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

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600;700;800&display=swap');

: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: "Sarabun", "Leelawadee UI", "Noto Sans Thai", "Tahoma", "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: 12.5pt; font-weight: 700; color: var(--deep); }
.co-name-en { font-size: 7.8pt; font-weight: 600; color: var(--teal); letter-spacing: .3px; }
.co-meta { font-size: 8.4pt; color: #33474d; margin-top: 1mm; line-height: 1.5; }
.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; 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 { padding: 1.8mm 2.6mm; }
.kv { display: grid; grid-template-columns: 32mm 1fr; gap: .6mm 3mm; align-items: baseline; }
.kv .k { font-size: 7.6pt; color: var(--muted); }
.kv .v { font-size: 9pt; color: var(--ink); font-weight: 600; }
.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); }

/* บรรทัดรับรองรับสินค้า (ใต้จำนวนเงินตัวอักษร) */
.recv-note { margin: 3mm 0 0; padding: 1.6mm 3mm; border: 1px solid var(--line); border-left: 3px solid var(--teal); border-radius: 1.4mm; font-size: 10pt; font-weight: 700; color: var(--deep); break-inside: avoid; }

/* ---------- ลายเซ็น ---------- */
.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; }

/* ---------- พิมพ์จริง ---------- */
@media print {
  html, body { background: #fff !important; }
  .sheet { box-shadow: none !important; border: 0 !important; margin: 0 !important; width: 210mm; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
