/* ============================================================
   3 SEASONS FRUIT — Document System
   document.css — ระบบดีไซน์เอกสาร A4 (ธีมเขียวอมฟ้า + ทองจากโลโก้)
   ใช้ร่วมกันทั้ง 4 เอกสาร แต่โครง/ลำดับข้อมูลต่างกันตามหน้าที่ (docs.js)
   ระยะแนวดิ่งถูกบีบให้เอกสารปกติพอดี 1 หน้า A4
   ============================================================ */

:root {
  --deep:   #0E4C46; --teal:   #157A6E; --teal-2: #2E9C8D;
  --mint:   #E8F3F0; --mint-2: #F3FAF8;
  --gold:   #C89B2C;
  --ink:    #232B2F; --muted:  #6B7780; --line:   #CBDDE0; --line-2: #E4EEEC;
  --paper:  #FFFFFF;
  --doc-font: "Leelawadee UI", "Tahoma", "Sarabun", "Noto Sans Thai", "Segoe UI", sans-serif;
}

@page { size: A4 portrait; margin: 0; }

.sheet {
  width: 210mm; min-height: 297mm; box-sizing: border-box;
  padding: 11mm 12mm 9mm; margin: 0 auto; background: var(--paper); color: var(--ink);
  font-family: var(--doc-font); font-size: 10pt; line-height: 1.32; position: relative;
}
@media screen { .sheet { box-shadow: 0 2px 18px rgba(14,76,70,.14); border: 1px solid #e9efee; } }

/* ---------- หัวเอกสาร ---------- */
.doc-head { display: flex; align-items: flex-start; gap: 5mm; }
.brand-logo { width: 18mm; height: auto; flex: 0 0 auto; object-fit: contain; }
.brand-co { flex: 1 1 auto; }
.co-name-th { font-size: 13pt; font-weight: 700; color: var(--deep); }
.co-name-en { font-size: 8pt; font-weight: 600; color: var(--teal); letter-spacing: .3px; }
.co-meta { font-size: 7.6pt; color: var(--muted); margin-top: 1mm; line-height: 1.35; }
.co-meta .taxid { color: var(--deep); font-weight: 700; }
.doc-head-rule { height: 2px; background: linear-gradient(90deg, var(--deep) 0 72%, var(--gold) 72% 100%); border: 0; margin: 2.4mm 0 0; }

/* ---------- ชื่อเอกสาร ---------- */
.doc-title { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 3.5mm; gap: 6mm; }
.title-th { font-size: 20pt; font-weight: 800; color: var(--deep); line-height: 1.05; }
.title-en { font-size: 9.5pt; font-weight: 700; color: var(--teal); letter-spacing: 2px; text-transform: uppercase; margin-top: .5mm; }
.doc-mark { text-align: right; font-size: 8pt; color: var(--muted); }
.doc-mark .orig { display: inline-block; border: 1.3px solid var(--teal); color: var(--deep); font-weight: 700; padding: 1.2mm 3mm; border-radius: 2mm; margin-bottom: 1mm; }
.doc-mark .legal { display: block; font-size: 7.2pt; color: var(--muted); }
.badge-temp { display: inline-block; background: var(--gold); color: #3a2c00; font-weight: 800; font-size: 8.5pt; letter-spacing: 1px; padding: 1mm 3.2mm; border-radius: 1.5mm; margin-bottom: 1mm; }

/* ---------- meta grid ---------- */
.meta-grid { margin-top: 3mm; border: 1px solid var(--line); border-radius: 1.4mm; overflow: hidden; display: grid; grid-template-columns: repeat(4, 1fr); }
.meta-grid.c2 { grid-template-columns: repeat(2, 1fr); }
.meta-grid.c3 { grid-template-columns: repeat(3, 1fr); }
.meta-cell { padding: 1.5mm 2.6mm; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); }
.meta-cell:nth-child(4n) { border-right: 0; }
.meta-cell .k { font-size: 7.2pt; color: var(--muted); }
.meta-cell .v { font-size: 10pt; font-weight: 700; color: var(--ink); }
.meta-cell .v.empty { color: #b7c3c6; font-weight: 400; }

/* ---------- คู่สัญญา ---------- */
.parties { display: flex; gap: 4mm; margin-top: 3mm; }
.party { flex: 1 1 0; min-width: 0; border: 1px solid var(--line); border-radius: 1.4mm; overflow: hidden; }
.party.wide { flex: 1.15 1 0; } .party.narrow { flex: .85 1 0; }
.party h4 { margin: 0; font-size: 8.6pt; font-weight: 700; color: #fff; background: var(--teal); padding: 1.2mm 2.6mm; }
.party h4 .en { font-weight: 500; opacity: .85; font-size: 7pt; }
.party .body { display: block; padding: 1.8mm 2.6mm; }
.kv { display: grid; grid-template-columns: 32mm minmax(0, 1fr); gap: .6mm 3mm; align-items: baseline; }
.kv .k { font-size: 7.6pt; color: var(--muted); white-space: nowrap; }
.kv .v { font-size: 9pt; color: var(--ink); font-weight: 600; word-break: break-word; line-height: 1.4; }
.kv .v .nowrap { white-space: nowrap; }
.kv .v.empty { color: #b7c3c6; font-weight: 400; }
.kv.stack { grid-template-columns: 1fr; }

/* ---------- ตารางรายการ ---------- */
.tbl { width: 100%; border-collapse: collapse; margin-top: 3mm; font-size: 8.6pt; }
.tbl thead { display: table-header-group; }
.tbl th { background: var(--deep); color: #fff; font-weight: 700; font-size: 8pt; padding: 1.5mm 2mm; border: 1px solid var(--deep); text-align: center; vertical-align: middle; }
.tbl th .en { display: block; font-weight: 500; font-size: 6.4pt; opacity: .8; }
.tbl td { border: 1px solid var(--line); padding: 1.3mm 2mm; vertical-align: top; }
.tbl tbody tr:nth-child(even) td { background: var(--mint-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .ctr { text-align: center; }
.tbl .idx { text-align: center; color: var(--muted); width: 8mm; }
.tbl .desc { min-width: 38mm; }
.tbl .money-col { width: 23mm; } .tbl .qty-col { width: 15mm; } .tbl .date-col { width: 26mm; }

/* ---------- สรุปยอด ---------- */
.totals-wrap { display: flex; justify-content: space-between; align-items: flex-start; gap: 6mm; margin-top: 3mm; break-inside: avoid; }
.totals-note { flex: 1 1 auto; font-size: 7.8pt; color: var(--muted); }
.totals { flex: 0 0 80mm; border: 1px solid var(--line); border-radius: 1.4mm; overflow: hidden; }
.trow { display: flex; justify-content: space-between; padding: 1.4mm 3mm; font-size: 9pt; border-bottom: 1px solid var(--line-2); }
.trow:last-child { border-bottom: 0; }
.trow .lab { color: var(--muted); } .trow .lab .en { font-size: 7pt; }
.trow .amt { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.trow.grand { background: var(--deep); }
.trow.grand .lab, .trow.grand .amt { color: #fff; font-weight: 800; }
.trow.grand .lab { font-size: 10pt; } .trow.grand .amt { font-size: 12pt; }

/* ---------- ตัวอักษร ---------- */
.inwords { margin-top: 2.5mm; border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: 1.4mm; padding: 1.8mm 3mm; display: flex; gap: 3mm; align-items: baseline; break-inside: avoid; }
.inwords .k { font-size: 7.6pt; color: var(--muted); white-space: nowrap; }
.inwords .v { font-size: 10.5pt; font-weight: 700; color: var(--deep); }

/* ---------- ลายเซ็น ---------- */
.signs { display: flex; gap: 5mm; margin-top: 5mm; break-inside: avoid; }
.sign { flex: 1 1 0; text-align: center; }
.sign .box { height: 15mm; }
.sign .line { border-top: 1px dotted var(--muted); margin: 0 4mm; padding-top: 1.2mm; }
.sign .role { font-size: 8pt; color: var(--ink); font-weight: 600; }
.sign .role .en { display: block; font-size: 6.8pt; color: var(--muted); font-weight: 400; }
.sign .sub { font-size: 7pt; color: var(--muted); margin-top: .4mm; }

/* ---------- หมายเหตุ/กล่อง ---------- */
.notes { margin-top: 3mm; border-top: 1px solid var(--line-2); padding-top: 2mm; font-size: 7.6pt; color: var(--muted); break-inside: avoid; }
.notes b { color: var(--deep); }
.callout { margin-top: 3mm; background: var(--mint); border: 1px solid var(--teal-2); border-radius: 1.4mm; padding: 1.8mm 2.6mm; font-size: 8.2pt; color: var(--deep); break-inside: avoid; }
.callout.warn { background: #FBF3DA; border-color: var(--gold); color: #6b4e00; }

/* ---------- ท้ายเอกสาร ---------- */
.doc-foot { margin-top: 4mm; border-top: 1px solid var(--line); padding-top: 1.6mm; display: flex; justify-content: space-between; align-items: baseline; gap: 4mm; font-size: 7pt; color: var(--muted); }
.doc-foot .pageno { flex: 0 0 auto; white-space: nowrap; }
.blank { color: #b7c3c6; }

/* กลุ่มรับรองรับสินค้า + ลายเซ็น (ข้อความรับรอง: เล็กลง จัดกึ่งกลางเหนือช่อง "ผู้รับสินค้า") */
.recv-block { margin-top: 2.5mm; border: 1px solid var(--line); border-radius: 1.4mm; overflow: hidden; break-inside: avoid; }
.recv-note { padding: 2.4mm 3mm 1mm; width: 33.33%; box-sizing: border-box; text-align: center; font-size: 8.5pt; font-weight: 700; color: var(--deep); }
.recv-block .signs { margin-top: 0; padding: 1mm 3mm 2.5mm; }
.recv-note.full { width: 100%; text-align: center; padding: 2.4mm 4mm 1mm; }
/* บล็อก "ชำระโดยโอนเข้าบัญชี" (A และ B) — ข้อมูล COMPANY ว่าง = จุดให้เติม */
.bank-block { margin-top: 2.5mm; border: 1px solid var(--line); border-left: 3px solid var(--teal); border-radius: 1.4mm; padding: 1.8mm 3mm; background: #fbfdfc; break-inside: avoid; }
.bank-block .bk-title { font-size: 8pt; font-weight: 800; color: var(--deep); margin-bottom: 1.2mm; letter-spacing: .2px; }
.bank-block .bk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8mm 8mm; }
.bank-block .bk-kv { display: flex; gap: 2mm; align-items: baseline; font-size: 8.5pt; }
.bank-block .bk-k { color: var(--muted); min-width: 34mm; }
.bank-block .bk-v { color: var(--ink); font-weight: 600; }
.bank-block .bk-v .blank { color: var(--muted); font-weight: 400; }
/* แถบติ๊กวิธีชำระเงิน (Doc A) */
.pay-boxes { margin-top: 2.5mm; display: flex; flex-wrap: wrap; gap: 1.6mm 6mm; align-items: center; font-size: 9pt; color: var(--ink); }
.pay-boxes .pb-lab { font-weight: 700; color: var(--deep); }
.pay-boxes .pb { display: inline-flex; align-items: center; gap: 1.2mm; }
/* Doc C — เส้นบรรจุภัณฑ์/เอกสารแนบ + กล่องติ๊ก */
.pack-note { margin-top: 1.6mm; font-size: 7.6pt; color: var(--muted); }
.pack-note b { color: var(--deep); }
.cb { display: inline-block; width: 2.8mm; height: 2.8mm; border: 1px solid var(--muted); border-radius: .5mm; vertical-align: -.3mm; margin-right: 1mm; }
.cb.on { background: var(--deep); border-color: var(--deep); }

/* Doc I/J/K (เสนอราคา / สั่งขาย / ส่งของ) — บีบระยะให้ลง 1 หน้า A4 (ไม่กระทบ A/B/C/D) */
.sheet-i, .sheet-j, .sheet-k { padding-bottom: 4mm; }
.sheet-e .meta-grid, .sheet-j .meta-grid, .sheet-k .meta-grid { margin-top: 1.6mm; }
.sheet-e .meta-cell, .sheet-j .meta-cell, .sheet-k .meta-cell { padding: 1mm 2.4mm; }
.sheet-e .parties, .sheet-j .parties, .sheet-k .parties { margin-top: 2mm; }
.sheet-e .pack-note, .sheet-j .pack-note { margin-top: 1.4mm; font-size: 7.2pt; }
.sheet-e .tbl, .sheet-j .tbl, .sheet-k .tbl { margin-top: 1.5mm; }
.sheet-e .tbl td, .sheet-j .tbl td, .sheet-k .tbl td { padding: 0.8mm 2mm; }
.sheet-e .totals-wrap, .sheet-j .totals-wrap { margin-top: 1.6mm; }
.sheet-e .inwords, .sheet-j .inwords { margin-top: 1.4mm; }
.sheet-e .bank-block, .sheet-j .bank-block { margin-top: 1.5mm; padding: 1.2mm 3mm; }
.sheet-e .notes, .sheet-j .notes, .sheet-k .notes { margin-top: 1.4mm; font-size: 7pt; line-height: 1.4; }
.sheet-e .signs, .sheet-j .signs { margin-top: 2.5mm; }
.sheet-k .sum-grid { margin-top: 1.6mm; }
.sheet-k .sum-grid .meta-cell .k { font-size: 6.8pt; }
.sheet-k .sum-grid .meta-cell .v { font-size: 9pt; }
.sheet-k .recv-block { margin-top: 1.5mm; }
.sheet-k .recv-block .signs { margin-top: 0; padding: 0.5mm 3mm 1.5mm; }
.sheet-k .meta-cell { padding: 0.8mm 2.2mm; }
.sheet-k .meta-cell .v { font-size: 9.4pt; }
.sheet-k .pack-note { margin-top: 1.2mm; font-size: 7pt; }


/* ---------- พิมพ์จริง ---------- */
@media print {
  html, body { background: #fff !important; }
  .sheet { box-shadow: none !important; border: 0 !important; margin: 0 !important; width: 210mm; }
  .sheet.ex-sheet { height: 297mm; overflow: hidden; break-after: page; page-break-after: always; }
  .sheet.ex-sheet:last-child { break-after: auto; page-break-after: auto; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* ============================================================
   EXPORT — PACKING LIST / COMMERCIAL INVOICE (แบบ PL & INV.pdf)
   ============================================================ */
.ex-sheet { margin-bottom: 8mm; }
.ex-sheet:last-child { margin-bottom: 0; }
.ex-co { font-size: 14pt; font-weight: 800; color: var(--teal); letter-spacing: 2.5px; text-align: center; }
.ex-sub { font-size: 7.6pt; color: var(--ink); text-align: center; margin-top: .6mm; letter-spacing: .3px; }
.ex-head-mini { align-items: center; }
.ex-ref { flex: 0 0 42mm; text-align: right; font-size: 8.6pt; font-weight: 700; color: var(--ink); }
.ex-ref .kv2 { margin: .8mm 0; white-space: nowrap; }
.ex-ref .kv2 span { display: inline-block; min-width: 17mm; text-align: right; font-weight: 800; }
.ex-rule { border: 0; border-top: 1.6px dashed var(--ink); margin: 2.6mm 0 0; height: 0; }
.ex-title { text-align: center; font-size: 16pt; font-weight: 800; color: var(--deep); letter-spacing: 3px; text-transform: uppercase; margin: 3.5mm 0 1mm; }

/* บล็อกข้อมูลป้ายยาว–colon–ค่า แบบ PDF เดิม */
.ex-info { margin-top: 2mm; }
.ex-info-title { text-align: center; font-weight: 800; font-size: 11pt; letter-spacing: 1px; margin-bottom: 1.5mm; }
.ex-irow { display: flex; align-items: flex-start; gap: 1.6mm; font-size: 8.6pt; margin: .9mm 0; }
.ex-irow .k { flex: 0 0 44mm; text-align: right; font-weight: 700; letter-spacing: .4px; }
.ex-irow .c { flex: 0 0 3mm; font-weight: 700; }
.ex-irow .v { flex: 1 1 auto; font-weight: 600; line-height: 1.4; }

/* ตารางสองชั้น */
.ex-tbl { font-size: 8pt; margin-top: 2.5mm; }
.ex-tbl th { background: #fff; color: var(--ink); border: 1.2px solid var(--ink); font-size: 7.4pt; font-weight: 800; padding: 1.1mm 1.4mm; }
.ex-tbl th .en { display: none; }
.ex-tbl td { border: 1px solid var(--ink); padding: 1.2mm 1.6mm; }
.ex-tbl tbody tr:nth-child(even) td { background: #fff; }
.ex-c-idx { width: 13mm; } .ex-c-desc { width: 56mm; }
.pl-desc .d1 { font-weight: 700; }
.pl-desc .d2 { font-size: 7.4pt; color: var(--ink); margin-top: .4mm; }
.ex-tbl .num { text-align: right; }
.ex-tbl .ctr { text-align: center; }
.ex-total-tbl td { border-top: 1.6px solid var(--ink); }
.ex-tot-lab { text-align: center; font-weight: 800; font-size: 8pt; }
.ex-total-tbl tr.ex-grand td { background: var(--mint); font-weight: 800; }
.ex-total-tbl tr.ex-grand .num { font-size: 9.5pt; }

/* ตัวอักษร (USD) */
.ex-inwords { margin-top: 2mm; font-size: 8pt; font-weight: 700; text-align: center; line-height: 1.4; }

/* ข้อความรับรอง (Declaration) */
.ex-decl { margin-top: 3mm; padding: 2mm 3mm; border: 1px solid var(--line); border-left: 3px solid var(--teal); border-radius: 1.4mm; font-size: 7.8pt; font-style: italic; color: #33474d; line-height: 1.45; break-inside: avoid; }
.ex-decl .ex-decl-t { font-style: normal; font-weight: 800; font-size: 7.4pt; letter-spacing: .5px; color: var(--deep); margin-bottom: .6mm; }

/* หน้าต่อเนื่อง (สไตล์ 2): แถบ CONTINUED + แถว SUBTOTAL */
.ex-continued { margin-top: 2mm; padding: 1.4mm 3mm; background: var(--mint); border: 1px solid var(--teal-2); border-radius: 1.4mm; font-size: 8pt; font-weight: 700; color: var(--deep); letter-spacing: .3px; text-align: center; break-inside: avoid; }
.ex-sub-row td { background: #eef5f4 !important; border-top: 1.2px solid var(--teal-2); }
.ex-sub-row .ex-tot-lab { text-align: right; }

/* ลายเซ็น + ตรา */
.ex-signwrap { display: flex; justify-content: flex-end; align-items: flex-end; gap: 8mm; margin-top: 6mm; break-inside: avoid; }
.ex-seal { flex: 0 0 auto; width: 30mm; height: 30mm; border: 1.4px solid var(--teal-2); border-radius: 50%; color: var(--teal); font-size: 5.6pt; font-weight: 700; display: flex; align-items: center; justify-content: center; text-align: center; padding: 3mm; line-height: 1.25; }
.ex-seal span { display: block; border-top: 1px solid var(--teal-2); margin-top: 1mm; padding-top: .6mm; }
.ex-sign { flex: 0 0 62mm; text-align: center; }
.ex-sign .sigline { border-bottom: 1px solid var(--ink); height: 13mm; margin: 0 6mm; }
.ex-sign .signame { font-weight: 800; font-size: 9pt; margin-top: 1.2mm; }
.ex-sign .sigco { font-size: 7.6pt; color: var(--muted); margin-top: .4mm; }
