/* =========================================================
   Central A4 print engine (งานสารบรรณ)
   - หน้าจอ: แสดงเป็นแผ่นกระดาษ A4 พร้อมระยะขอบเท่ากับตอนพิมพ์
   - ตอนพิมพ์: ระยะขอบมาจาก @page ของเอกสารแต่ละชนิด จึงถูกต้องทุกหน้า
     (หน้า 2 เป็นต้นไปมีขอบบนเท่าหน้าแรก)
   ระยะขอบตามแนวปฏิบัติ: บน 2.5 ซม. ซ้าย 3 ซม. ขวา 2 ซม. ล่าง 2 ซม.
   บันทึกข้อความ/คำสั่ง: ครุฑอยู่ห่างขอบบน 1.5 ซม.
   ========================================================= */
@font-face{font-family:'TH Sarabun New Embedded';src:url('fonts/THSarabunNew.ttf?v=1') format('truetype');font-style:normal;font-weight:400;font-display:block}
@font-face{font-family:'TH Sarabun New Embedded';src:url('fonts/THSarabunNew-Bold.ttf?v=1') format('truetype');font-style:normal;font-weight:700;font-display:block}
@font-face{font-family:'TH Sarabun New Embedded';src:url('fonts/THSarabunNew-Italic.ttf?v=1') format('truetype');font-style:italic;font-weight:400;font-display:block}
@font-face{font-family:'TH Sarabun New Embedded';src:url('fonts/THSarabunNew-BoldItalic.ttf?v=1') format('truetype');font-style:italic;font-weight:700;font-display:block}

:root{--doc-font:'TH Sarabun New Embedded','TH SarabunIT๙','TH Sarabun New','TH SarabunPSK',sans-serif}

/* ---------- แผ่นเอกสาร ---------- */
.official-page,.official-document,.requisition-sheet{
  --page-padding:25mm 20mm 20mm 30mm;
  box-sizing:border-box;width:210mm;min-height:297mm;margin:0 auto 24px;padding:var(--page-padding);
  background:#fff;color:#000;font-family:var(--doc-font);font-size:16pt;line-height:1.15;font-weight:400;font-style:normal;
  letter-spacing:0;word-spacing:0;font-kerning:normal;text-rendering:optimizeLegibility;
  box-shadow:0 1px 3px rgba(15,23,42,.08),0 12px 36px rgba(15,23,42,.12);border-radius:2px
}
.official-page--memo,.official-page--order{--page-padding:15mm 20mm 20mm 30mm}
.official-page--tor{--page-padding:25mm 20mm 20mm 30mm}
.official-page--request{--page-padding:20mm 20mm 15mm 30mm}
.official-page--form,.official-page--requisition,.official-page--receipt{--page-padding:15mm 15mm 15mm 20mm}
.official-page--ledger{--page-padding:15mm 15mm 12mm 20mm;width:297mm;min-height:210mm}

.official-page *,.official-document *{box-sizing:border-box;letter-spacing:0;word-spacing:0}
.official-page table,.official-document table{width:100%;max-width:100%;min-width:0;border-collapse:collapse;table-layout:fixed;font-family:inherit}
.official-page th,.official-page td,.official-document th,.official-document td{overflow-wrap:anywhere;word-break:normal;color:#000;position:static}
.official-page tr,.official-document tr,.official-no-break,.signature-block{break-inside:avoid;page-break-inside:avoid}
.official-paragraph{margin:0 0 1.5mm;text-indent:25mm;text-align:left;line-height:1.15}
.signature-space{height:15mm}
.page-break{break-before:page;page-break-before:always}

/* ลายเซ็นมาตรฐาน: "ลงชื่อ ....... ตำแหน่ง" / (ชื่อ) จัดกึ่งกลางใต้เส้นจุด */
.doc-sign{display:grid;grid-template-columns:max-content 62mm max-content;column-gap:1.5mm;row-gap:0;align-items:end;line-height:1.15;break-inside:avoid;page-break-inside:avoid}
.doc-sign .sig-dots{border-bottom:1.2px dotted #000;height:.9em;margin-bottom:.22em}
.doc-sign .sig-name,.doc-sign .sig-extra{grid-column:2;justify-self:center;text-align:center;white-space:nowrap}
.doc-sign .sig-role{white-space:nowrap}

.official-print-note{max-width:210mm;margin:0 auto 14px;padding:10px 14px;border:1px solid #f2cf66;border-radius:10px;background:#fff8dc;color:#6b5200;font-family:'Sarabun',sans-serif;font-size:13px}
.official-print-note.is-landscape{max-width:297mm}

/* ---------- บัญชีวัสดุ (A4 แนวนอน) ---------- */
.doc-scroll{overflow-x:auto;padding:2px 2px 8px}
.ledger-sheet{font-family:var(--doc-font);font-size:16pt;line-height:1.15;color:#000}
.ledger-head{text-align:center;margin:0 0 3mm;line-height:1.15}
.ledger-head h1{font-size:20pt;font-weight:700;margin:0}
.ledger-info{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:1.5mm 6mm;margin:0 0 3mm}
.ledger-field{display:flex;gap:2mm;align-items:baseline;min-width:0}
.ledger-field.w-wide{grid-column:span 2}
.ledger-field b{white-space:nowrap;font-weight:700}
.ledger-field span{flex:1;min-width:0;border-bottom:1px dotted #000;min-height:1.15em;overflow-wrap:anywhere;padding:0 1mm}
.ledger-table{font-size:15pt;line-height:1.1}
.ledger-table th,.ledger-table td{border:1px solid #000;padding:.8mm 1.5mm;background:#fff;color:#000;vertical-align:middle;height:7.2mm}
.ledger-table th{font-weight:700;text-align:center;line-height:1.05}
.ledger-table td.c{text-align:center}.ledger-table td.n{text-align:right;white-space:nowrap}
.ledger-table .ledger-opening td{font-weight:700}
.ledger-table tbody tr:last-child td,.delivery-items tbody tr:last-child td,.tor-print-table tbody tr:last-child td{border-bottom:1px solid #000}
.ledger-picker-actions{display:flex;align-items:flex-end;justify-content:flex-end}

/* ---------- ใบรับเข้าคลัง ---------- */
.official-page--receipt .card{border:0;box-shadow:none;padding:0;margin:0;background:#fff;color:#000;border-radius:0}
.official-page--receipt h2{font-size:20pt;font-weight:700;margin:0 0 2mm}
.official-page--receipt table{font-size:16pt;line-height:1.1}
.official-page--receipt th,.official-page--receipt td{border:1px solid #000!important;padding:1mm 1.5mm;background:#fff!important;color:#000;position:static}
.official-page--receipt th{text-align:center;font-weight:700}
.official-page--receipt td:nth-child(2),.official-page--receipt td:nth-child(3){text-align:center}.official-page--receipt td:nth-child(4),.official-page--receipt td:nth-child(5){text-align:right}

/* ---------- ขนาดกระดาษและระยะขอบตอนพิมพ์ ---------- */
@page{size:A4 portrait;margin:15mm}
@page memo{size:A4 portrait;margin:15mm 20mm 20mm 30mm}
@page order{size:A4 portrait;margin:15mm 20mm 20mm 30mm}
@page tor{size:A4 portrait;margin:25mm 20mm 20mm 30mm;
  @top-center{content:"- " counter(page) " -";font-family:'TH Sarabun New Embedded','TH Sarabun New',sans-serif;font-size:16pt;vertical-align:middle}}
@page tor:first{@top-center{content:none}}
@page request{size:A4 portrait;margin:20mm 20mm 15mm 30mm}
@page form{size:A4 portrait;margin:15mm 15mm 15mm 20mm}
@page ledger{size:A4 landscape;margin:15mm 15mm 12mm 20mm;
  @top-right{content:"แผ่นที่ " counter(page);font-family:'TH Sarabun New Embedded','TH Sarabun New',sans-serif;font-size:14pt;vertical-align:bottom;padding-bottom:3mm}}

@media print{
  html,body{width:auto;margin:0!important;padding:0!important;background:#fff!important;color:#000!important;-webkit-print-color-adjust:exact;print-color-adjust:exact}
  .sidebar,.app-header,.content>.fiscal-bar,.no-print,.flash,.official-print-note,.theme-toggle{display:none!important}
  .layout,.main,.content{display:block!important;width:auto!important;max-width:none!important;margin:0!important;padding:0!important;transform:none!important}
  .official-page,.official-document,.requisition-sheet{
    width:auto!important;min-height:0!important;height:auto!important;max-width:none!important;max-height:none!important;
    margin:0!important;padding:0!important;background:#fff!important;color:#000!important;
    box-shadow:none!important;border:0!important;border-radius:0!important;transform:none!important;zoom:1!important;overflow:visible!important;
    page:form
  }
  .official-page--memo{page:memo}
  .official-page--order{page:order}
  .official-page--tor{page:tor}
  .official-page--request{page:request}
  .official-page--ledger{page:ledger}
  /* ให้ทั้งหน้าใช้ชนิดกระดาษเดียวกับเอกสาร เพื่อไม่ให้เกิดหน้าว่างก่อนเอกสาร */
  body:has(.official-page--form),body:has(.official-page--requisition),body:has(.official-page--receipt){page:form}
  body:has(.official-page--memo){page:memo}
  body:has(.official-page--order){page:order}
  body:has(.official-page--tor){page:tor}
  body:has(.official-page--request){page:request}
  body:has(.official-page--ledger){page:ledger}
  .content>br{display:none}
  .official-page table,.official-document table,.requisition-sheet table{width:100%!important;max-width:100%!important;min-width:0!important;table-layout:fixed!important;border-collapse:collapse!important}
  .official-page thead,.official-document thead,.requisition-sheet thead{display:table-header-group}
  .official-page tr,.official-document tr,.requisition-sheet tr{break-inside:avoid;page-break-inside:avoid}
  .official-page h1,.official-page h2,.official-page h3{break-after:avoid;page-break-after:avoid}
  .official-page p{orphans:2;widows:2}
}
@media screen and (max-width:900px){
  .official-page,.official-document,.requisition-sheet{width:100%;min-height:0;padding:20px 18px}
}
