/* =============================================================================
 * เอกสารฉบับพิมพ์ (A4) — ใช้ทั้งดูตัวอย่างบนจอ (#docview) และพิมพ์ (#printview)
 * ========================================================================== */

/* ---------- ตัวดูเอกสารบนจอ ---------- */
#docview { display: none; }
#docview.on { display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 40; background: #525659; }
body.noscroll { overflow: hidden; }
.dvbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; background: #0f2742; color: #fff; }
.dvbar .dvt { font-weight: 700; }
.dvbar .sp { flex: 1; }
.dvbar .btn { min-height: 42px; color: var(--ink); }
.dvbar .btn.pri { color: #fff; }
.dvpages { flex: 1; overflow: auto; padding: 12px; -webkit-overflow-scrolling: touch; }

/* ---------- หน้า A4 ---------- */
.page {
  position: relative; box-sizing: border-box; display: flex; flex-direction: column;
  width: 210mm; min-height: 297mm; padding: 8mm; margin: 0 auto 14px; background: #fff; color: #000;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
  font-family: 'Sarabun', 'TH Sarabun New', 'Leelawadee UI', 'Leelawadee', 'Tahoma', sans-serif; font-size: 10.5px; line-height: 1.3;
}
.page.land { width: 297mm; min-height: 210mm; font-size: 9.5px; }
.page b, .page strong { font-weight: 700; }

.wm { position: absolute; left: 0; right: 0; top: 42%; text-align: center; transform: rotate(-24deg); font-size: 64px; font-weight: 800; color: rgba(200, 0, 0, .12); pointer-events: none; z-index: 5; white-space: nowrap; }
.stamp { align-self: flex-start; border: 2px solid #c00; color: #c00; padding: 2px 12px; font-weight: 700; transform: rotate(-2deg); margin: 4px 0; }

/* หัวเอกสาร */
table.dh { width: 100%; border-collapse: collapse; margin-bottom: 2px; }
table.dh td { border: 1.5px solid #000; padding: 3px 6px; vertical-align: middle; }
.dl { width: 21%; text-align: center; } .dl img { height: 32px; display: inline-block; }
.dt { text-align: center; font-size: 15px; font-weight: 700; line-height: 1.25; }
.dts { font-size: 10px; font-weight: 400; }
.dr { width: 21%; font-size: 9.5px; }
.dno { font-weight: 700; }
.dm { display: flex; justify-content: space-between; font-size: 8.5px; color: #333; margin: 1px 0 3px; }

/* ตาราง */
table.g { width: 100%; border-collapse: collapse; margin: 0 0 3px; table-layout: auto; }
table.g th, table.g td { border: 1px solid #000; padding: 1.5px 4px; vertical-align: middle; }
table.g th { background: #e8ebef; font-weight: 700; text-align: center; }
table.g th.sh { text-align: left; background: #d6e0ef; }
table.g th.rh { text-align: left; width: 13%; }
table.g td.c, table.g th.c { text-align: center; }
table.g td.l { text-align: left; }
table.g td.na { text-align: center; color: #555; font-style: italic; }
table.g td.nt { font-size: 9px; height: 20px; vertical-align: top; }
table.g tr.bad td, table.g td.bad { background: #fde3e3; }
table.g tr.selrow td { background: #eaf2ff; }
table.g tr.part td { background: #f0f0f0; font-weight: 700; }
table.g tr.tall td { height: 26px; }
table.info td { border: 1px solid #000; }
table.info td.lb { white-space: nowrap; font-weight: 700; width: 1%; background: #f6f7f9; }
.w4 { width: 4%; } .w5 { width: 5%; } .w7 { width: 7%; } .w8 { width: 8%; } .w9 { width: 9%; } .w11 { width: 11%; }
.w14 { width: 14%; } .w16 { width: 16%; } .w20 { width: 20%; } .w25 { width: 25%; }
.xs { font-size: .86em; }

/* ช่องติ๊ก / ช่องเติม */
.cb { display: inline-block; width: 10px; height: 10px; border: 1px solid #000; line-height: 9px; font-size: 9px; text-align: center; font-weight: 800; vertical-align: -1px; background: #fff; }
.cb.on { color: #0b3d91; }
.dopt { white-space: nowrap; margin-right: 9px; }
.fill { display: inline-block; min-width: 80px; height: 1em; border-bottom: 1px dotted #000; vertical-align: bottom; }
.fill.short { min-width: 34px; }
.fv { font-weight: 700; color: #0b3d91; }
.fv.bad { color: #c00; }

/* บล็อกต่างๆ */
.band { background: #000; color: #fff; text-align: center; font-weight: 700; padding: 1px; margin: 3px 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-items: start; }
.cols.c13 { grid-template-columns: 1fr 1.25fr; }
.cols.c13b { grid-template-columns: 1fr 1fr; }
.osb { border: 1.5px solid #000; padding: 3px 6px; margin: 3px 0; }
.ibox { border: 1px solid #c00; padding: 2px 6px; margin: 3px 0; font-size: 9px; }
.nl { margin: 1px 0 1px 14px; padding: 0; font-size: 9px; }
.nl li.bad { color: #a00; }
.rem { font-size: 9px; margin: 3px 0; }
.tools { line-height: 1.9; font-size: 9.5px; }
.tool { display: inline-block; min-width: 32%; white-space: nowrap; }
.phbox { border: 1px solid #000; text-align: center; }
.phbox .bt { background: #d6e0ef; font-weight: 700; padding: 1px 4px; border-bottom: 1px solid #000; text-align: left; }
.phbox img { display: block; max-width: 100%; max-height: 48mm; margin: 2px auto; object-fit: contain; }
.phempty { padding: 30px 6px; color: #777; }
table.tt th, table.tt td { text-align: center; padding: 1px 1px; font-size: 8.5px; }
table.tt td { height: 13px; }
.page.land .sgi { height: 26px; } .page.land .sgi img { max-height: 26px; }
.page.land .phbox img { max-height: 42mm; }
table.fp12 td { height: 15px; }
table.amt { font-size: 8.8px; }
table.amt td.eq { font-weight: 700; vertical-align: top; background: #f4f5f7; }
table.amt thead { display: table-header-group; }
table.amt tr { break-inside: avoid; }
.amsum { margin: 3px 0; font-size: 10px; }

/* ลายเซ็น */
.sgrow { display: flex; gap: 8px; margin: 4px 0; break-inside: avoid; }
.sg { flex: 1; text-align: center; border: 1px solid #999; padding: 2px 4px; }
.sg.off { opacity: .45; }
.sgi { height: 32px; display: flex; align-items: center; justify-content: center; }
.sgi img { max-height: 32px; max-width: 100%; }
.sgn { font-size: 10px; } .sgl { font-weight: 700; } .sgs { font-size: 9px; } .sgd { font-size: 9px; }

/* ภาคผนวกรูป */
.pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pgrid figure { margin: 0; border: 1px solid #999; break-inside: avoid; }
.pgrid img { display: block; width: 100%; max-height: 90mm; object-fit: contain; background: #f4f4f4; }
.pgrid figcaption { font-size: 9px; padding: 2px 4px; }

/* ท้ายเอกสาร */
.dfoot { margin-top: auto; padding-top: 4px; }
.df { display: flex; justify-content: space-between; border-top: 1.5px solid #000; padding-top: 1px; font-size: 9.5px; font-weight: 700; }
.dmeta { font-size: 7.5px; color: #444; }

/* ---------- พิมพ์ / บันทึก PDF ---------- */
#printview { display: none; }
@page { size: A4 portrait; margin: 8mm; }
@page land { size: A4 landscape; margin: 8mm; }
@media print {
  body { background: #fff !important; }
  body > *:not(#printview) { display: none !important; }
  #printview { display: block !important; }
  .page { width: auto; min-height: 279mm; padding: 0; margin: 0; box-shadow: none; break-after: page; }
  .page.land { page: land; min-height: 192mm; }
  .page:last-child { break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
table.tt th.off, table.tt td.off { background: #d9d9d9; }
