/* ═══════════════════════════════════════════════════════════
   doc-print.css — Boonsook POS V5
   สไตล์เอกสาร A4 สำหรับ QT / INV / RE
   ใช้ร่วมกันทุก module — พิมพ์/PDF คมชัด ไม่ใช้ html2canvas
   ═══════════════════════════════════════════════════════════ */

/* ── Preview wrapper (หน้าจอ) ─────────────────────────────── */
.doc-preview {
  padding: 16px 0;
  background: #e5e7eb;
}

.doc-page {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto 16px;
  padding: 18mm 16mm 14mm;
  box-sizing: border-box;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
  position: relative;
  display: flex;
  flex-direction: column;
  font-family: "Sarabun", "Noto Sans Thai", "THSarabunNew", system-ui, sans-serif;
  font-size: 13px;
  color: #111;
  line-height: 1.6;
}

/* ── Accent bar top ─────────────────────────────────────────── */
.doc-accent {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
}
.doc-accent.qt  { background: #f97316; }
.doc-accent.inv { background: #0284c7; }
.doc-accent.re  { background: #10b981; }

/* ── Page number badge ──────────────────────────────────────── */
.doc-page-badge {
  position: absolute;
  top: 0; right: 0;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 900; color: #fff;
}
.doc-page-badge.qt  { background: #f97316; }
.doc-page-badge.inv { background: #0284c7; }
.doc-page-badge.re  { background: #10b981; }

.doc-copy-label {
  font-size: 11px; color: #888; text-align: center;
  margin-top: 2px; font-weight: 600;
}

/* ── Inner flex column ──────────────────────────────────────── */
.doc-page-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────── */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1.5px solid #d1d5db;
  margin-bottom: 14px;
}

.doc-header-left {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 55%;
}

.doc-logo {
  width: 60px; height: 60px;
  border-radius: 8px;
  object-fit: contain;
  flex-shrink: 0;
}

.doc-company-name {
  font-size: 16px;
  font-weight: 900;
  margin-bottom: 3px;
}

.doc-company-detail {
  font-size: 11.5px;
  color: #555;
  line-height: 1.65;
}

/* ── Title (right side) ─────────────────────────────────────── */
.doc-header-right { text-align: right; }

.doc-title {
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
}
.doc-title.qt  { color: #f97316; }
.doc-title.inv { color: #0284c7; }
.doc-title.re  { color: #10b981; }

.doc-title-sub {
  font-size: 11px;
  font-weight: 600;
  margin-top: 2px;
  color: #888;
}

/* ── Detail table (เลขที่, วันที่, ผู้ขาย) ──────────────────── */
.doc-detail-table {
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 8px;
}
.doc-detail-table td {
  padding: 3px 10px;
  border: 1px solid #d1d5db;
}
.doc-detail-table td:first-child {
  font-weight: 700;
  color: #555;
  background: #f9fafb;
  white-space: nowrap;
}

/* ── Customer section ───────────────────────────────────────── */
.doc-customer-section {
  margin: 10px 0 14px;
}
.doc-customer-label {
  font-weight: 800;
  font-size: 11px;
  text-decoration: underline;
  margin-bottom: 3px;
}
.doc-customer-label.qt  { color: #f97316; }
.doc-customer-label.inv { color: #0284c7; }
.doc-customer-label.re  { color: #10b981; }

.doc-customer-name {
  font-weight: 700;
  font-size: 14px;
}
.doc-customer-detail {
  font-size: 12px;
  color: #333;
  line-height: 1.65;
}

/* ── Items table ────────────────────────────────────────────── */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 6px;
  font-size: 12.5px;
}
.doc-table th {
  padding: 7px 8px;
  font-weight: 700;
  border: 1px solid #d1d5db;
  background: #f3f4f6;
  color: #333;
  text-align: center;
  font-size: 11.5px;
}
.doc-table td {
  padding: 7px 8px;
  border: 1px solid #d1d5db;
  vertical-align: top;
}
.doc-table tbody tr:nth-child(even) td {
  background: #fafafa;
}

/* ── Baht text ──────────────────────────────────────────────── */
.doc-baht-text {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  margin: 6px 0 2px;
}

/* ── Totals ─────────────────────────────────────────────────── */
.doc-totals {
  margin-left: auto;
  width: 270px;
  margin-top: 4px;
}
.doc-total-row {
  display: flex;
  justify-content: space-between;
  padding: 3.5px 0;
  font-size: 12.5px;
  color: #333;
}
.doc-total-row.grand {
  font-size: 14px;
  font-weight: 900;
  padding-top: 7px;
  margin-top: 3px;
}
.doc-total-row.grand.qt  { color: #f97316; border-top: 2px solid #f97316; }
.doc-total-row.grand.inv { color: #0284c7; border-top: 2px solid #0284c7; }
.doc-total-row.grand.re  { color: #10b981; border-top: 2px solid #10b981; }

/* ── Note section ───────────────────────────────────────────── */
.doc-note-section {
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.7;
}
.doc-note-title {
  font-weight: 800;
  text-decoration: underline;
  margin-bottom: 2px;
}
.doc-note-title.qt  { color: #f97316; }
.doc-note-title.inv { color: #0284c7; }
.doc-note-title.re  { color: #10b981; }

/* ── Payment info (ใบเสร็จ) ─────────────────────────────────── */
.doc-payment-info {
  margin-top: 14px;
  font-size: 11.5px;
  color: #444;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 8px 10px;
}
.doc-payment-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 4px 12px;
  margin-top: 6px;
  font-size: 11.5px;
  border: 1px solid #d1d5db;
  padding: 6px 8px;
  border-radius: 4px;
}
.doc-payment-grid span:nth-child(odd) {
  font-weight: 700;
  white-space: nowrap;
}
.doc-payment-grid-line {
  border-bottom: 1px solid #e2e8f0;
  width: 100%;
}

/* ── Signatures ─────────────────────────────────────────────── */
.doc-signatures {
  display: flex;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 24px;
  font-size: 12.5px;
}
.doc-sig-col {
  text-align: center;
  width: 44%;
}
.doc-sig-behalf {
  font-weight: 600;
  margin-bottom: 28px;
  font-size: 12px;
}
.doc-sig-line {
  width: 200px;
  border-bottom: 1px solid #333;
  margin: 0 auto 5px;
  height: 36px;
}
.doc-sig-label-row {
  display: flex;
  justify-content: center;
  gap: 44px;
  font-size: 11.5px;
}

/* ═══════════════════════════════════════════════════════════
   @media mobile — ปรับเอกสารให้พอดีจอมือถือ
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .doc-preview {
    padding: 8px;
    background: #f1f5f9;
  }

  .doc-page {
    width: auto !important;
    min-height: auto !important;
    padding: 14px 12px 16px;
    margin: 0 auto 12px;
    font-size: 12px;
    border-radius: 8px;
  }

  .doc-page-inner {
    padding: 0;
  }

  /* Header: stack vertically */
  .doc-header {
    flex-direction: column;
    gap: 10px;
    padding-bottom: 10px;
  }

  .doc-header-left {
    max-width: 100%;
    gap: 10px;
  }

  .doc-header-right {
    text-align: left;
  }

  .doc-logo {
    width: 48px;
    height: 48px;
  }

  .doc-company-name {
    font-size: 14px;
  }

  .doc-company-detail {
    font-size: 11px;
  }

  .doc-title {
    font-size: 20px;
  }

  .doc-title-sub {
    font-size: 10px;
  }

  /* Detail table */
  .doc-detail-table {
    margin-left: 0;
    font-size: 11.5px;
  }

  .doc-detail-table td {
    padding: 3px 8px;
  }

  .doc-detail-table td:last-child {
    min-width: 0;
  }

  /* Customer */
  .doc-customer-name {
    font-size: 13px;
  }

  .doc-customer-detail {
    font-size: 11.5px;
  }

  /* Items table: allow wrapping & scroll */
  .doc-table {
    font-size: 11px;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .doc-table th {
    padding: 6px 5px;
    font-size: 10.5px;
    white-space: nowrap;
  }

  .doc-table td {
    padding: 6px 5px;
    font-size: 11px;
  }

  /* Totals: full width */
  .doc-totals {
    width: 100%;
    margin-left: 0;
  }

  .doc-total-row {
    font-size: 12px;
  }

  .doc-total-row.grand {
    font-size: 13px;
  }

  /* Note */
  .doc-note-section {
    font-size: 11.5px;
  }

  /* Payment info */
  .doc-payment-grid {
    grid-template-columns: auto 1fr;
    font-size: 11px;
  }

  /* Signatures: stack vertically */
  .doc-signatures {
    flex-direction: column;
    gap: 20px;
    align-items: center;
    padding-top: 16px;
  }

  .doc-sig-col {
    width: 85%;
  }

  .doc-sig-line {
    width: 160px;
  }

  .doc-sig-behalf {
    margin-bottom: 20px;
    font-size: 11.5px;
  }

  .doc-sig-label-row {
    font-size: 11px;
  }

  /* Page badge */
  .doc-page-badge {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }
}

/* ═══════════════════════════════════════════════════════════
   @media print — A4 คมชัด ไม่มีพื้นหลัง
   ═══════════════════════════════════════════════════════════ */
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    margin: 0;
    padding: 0;
    background: #fff !important;
  }

  .doc-preview {
    background: #fff !important;
    padding: 0;
  }

  .doc-page {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    box-shadow: none !important;
    page-break-after: always;
    background: #fff !important;
  }

  .doc-page:last-child {
    page-break-after: avoid;
  }

  /* แสดงสีและ border ตอนพิมพ์ */
  .doc-accent.qt  { background: #f97316 !important; }
  .doc-accent.inv { background: #0284c7 !important; }
  .doc-accent.re  { background: #10b981 !important; }

  .doc-page-badge.qt  { background: #f97316 !important; color: #fff !important; }
  .doc-page-badge.inv { background: #0284c7 !important; color: #fff !important; }
  .doc-page-badge.re  { background: #10b981 !important; color: #fff !important; }

  .doc-table th { background: #f3f4f6 !important; }
  .doc-table tbody tr:nth-child(even) td { background: #fafafa !important; }
  .doc-detail-table td:first-child { background: #f9fafb !important; }
}
