/* =======================================================================
   BlackWhite — เอกสารพิมพ์ (@media print เท่านั้น)
   ใช้ได้ทั้ง A4 (ค่าเริ่มต้น) และ A5 (เลือกในหน้าต่างพิมพ์)
   ======================================================================= */

#printRoot { display: none; }

@media print {
  @page { size: A4; margin: 12mm 12mm 14mm; }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-family: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Sarabun', system-ui, sans-serif;
    font-size: 11pt;
  }
  body > *:not(#printRoot) { display: none !important; }
  #printRoot { display: block !important; }

  .sheet {
    break-after: page;
    padding: 0;
    margin: 0;
    color: #000;
  }
  .sheet:last-child { break-after: auto; }

  .sheet__head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10mm;
    border-bottom: 1.4pt solid #000;
    padding-bottom: 3mm;
  }
  .sheet__shop { display: flex; gap: 3mm; align-items: flex-start; }
  .sheet__mark {
    width: 11mm; height: 11mm; display: grid; place-items: center;
    background: #000; color: #fff; font-weight: 700; font-size: 11pt; border-radius: 1mm;
  }
  .sheet__shop strong { display: block; font-size: 13pt; letter-spacing: -.2pt; }
  .sheet__shop span { display: block; font-size: 8.5pt; color: #333; line-height: 1.45; }

  .sheet__title { text-align: right; }
  .sheet__title h1 { font-size: 14pt; margin: 0 0 1.5mm; }
  .sheet__title span { display: block; font-size: 8.5pt; color: #222; }
  .sheet__title b { font-size: 10pt; }
  .sheet__copy {
    display: inline-block; margin-top: 1.5mm; border: 0.6pt solid #000;
    padding: 0.6mm 2mm; font-size: 7.5pt; font-weight: 700;
  }

  .sheet__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5mm; margin-top: 4mm; }
  .sheet__grid h2, .sheet__block h2, .sheet__terms h2 {
    font-size: 8pt; text-transform: uppercase; letter-spacing: .06em;
    margin: 0 0 1mm; color: #444;
  }
  .sheet__grid p { margin: 0 0 0.6mm; font-size: 9.5pt; line-height: 1.45; }

  .sheet__block { margin-top: 4mm; }
  .sheet__block p { margin: 0; font-size: 9.5pt; line-height: 1.5; }
  .sheet__block--muted { background: #f4f4f4; padding: 2.5mm 3mm; border-radius: 1mm; }

  .sheet__items { width: 100%; border-collapse: collapse; margin-top: 4mm; font-size: 9.5pt; }
  .sheet__items th {
    text-align: left; font-size: 8pt; text-transform: uppercase; letter-spacing: .04em;
    border-bottom: 1pt solid #000; padding: 1.5mm 1.5mm; color: #333;
  }
  .sheet__items td { padding: 1.4mm 1.5mm; border-bottom: 0.4pt solid #ccc; vertical-align: top; }
  .sheet__items .c { width: 7mm; text-align: center; }
  .sheet__items .n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .sheet__items .sheet__kind { display: block; font-size: 7.5pt; color: #666; }
  .sheet__empty { text-align: center; color: #777; }

  .sheet__totals { width: 78mm; margin-left: auto; margin-top: 3mm; font-size: 9.5pt; }
  .sheet__totalrow { display: flex; justify-content: space-between; gap: 4mm; padding: 0.7mm 0; }
  .sheet__totalrow--grand {
    border-top: 1pt solid #000; margin-top: 1.5mm; padding-top: 1.8mm; font-weight: 700; font-size: 11pt;
  }
  .sheet__totalrow--due { font-weight: 700; }

  .sheet__terms { margin-top: 5mm; border-top: 0.4pt solid #bbb; padding-top: 2.5mm; }
  .sheet__terms ol { margin: 0 0 1.5mm; padding-left: 4.5mm; font-size: 8pt; line-height: 1.5; color: #222; }
  .sheet__terms p { margin: 0; font-size: 8pt; color: #333; }

  .sheet__signs { display: grid; grid-template-columns: 1fr 1fr; gap: 10mm; margin-top: 8mm; }
  .sheet__sign { text-align: center; font-size: 8pt; }
  .sheet__sign img { display: block; max-height: 18mm; max-width: 62mm; margin: 0 auto 1.5mm; }
  .sheet__sign .sheet__line { display: block; height: 18mm; border-bottom: 0.5pt solid #000; margin-bottom: 1.5mm; }
  .sheet__sign span { display: block; }
  .sheet__muted { color: #555; font-size: 7.5pt; }
  .sheet__note { font-size: 7.5pt; color: #555; }

  .sheet__foot {
    display: flex; justify-content: space-between; gap: 4mm;
    margin-top: 6mm; padding-top: 1.5mm; border-top: 0.4pt solid #bbb;
    font-size: 7pt; color: #666;
  }
}

/* สำหรับพิมพ์ใบเสร็จขนาด 80mm (ถ้าเลือกกระดาษนี้ในหน้าต่างพิมพ์) */
@media print and (max-width: 90mm) {
  @page { size: 80mm auto; margin: 4mm; }
  .sheet__head { flex-direction: column; gap: 2mm; }
  .sheet__title { text-align: left; }
  .sheet__grid { grid-template-columns: 1fr; gap: 2mm; }
  .sheet__signs { grid-template-columns: 1fr; gap: 6mm; }
}
