/* ============================================================
   BORSUP — Document Paper (A4) — screen + print
   ============================================================ */
.doc-scroll { display: flex; justify-content: center; background: var(--paper-2); margin: 0 -24px -22px; padding: 22px 24px 24px; border-radius: 0 0 var(--r-lg) var(--r-lg); overflow-x: auto; }
#doc-print-area { display: flex; flex-direction: column; align-items: center; gap: 28px; }

/* Doc toolbar (copy type + signature + sign date) — not printed */
.doc-toolbar { display: flex; align-items: center; justify-content: center; gap: 22px; padding-bottom: 16px; flex-wrap: wrap; }
.doc-tool-group { display: flex; align-items: center; gap: 9px; }
.doc-copy-label { font-size: 13px; font-weight: 600; color: var(--text-600); white-space: nowrap; }
.doc-sig-upload { display: inline-flex; align-items: center; gap: 6px; padding: 8px 13px; border: 1px dashed var(--gold-400); border-radius: var(--r-sm); background: var(--gold-tint); color: var(--gold-600); font-size: 13px; font-weight: 600; transition: all .15s; }
.doc-sig-upload:hover { background: var(--gold-100); border-color: var(--gold-500); }
.doc-sig-chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 8px 5px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
.doc-sig-thumb { height: 26px; max-width: 90px; object-fit: contain; }
.doc-sig-x { width: 22px; height: 22px; border-radius: 6px; border: none; background: var(--paper-2); color: var(--text-500); display: grid; place-items: center; }
.doc-sig-x:hover { background: var(--red-100); color: var(--red-600); }
.doc-sign-date-input { width: auto; padding: 8px 11px; font-size: 13.5px; }

.doc-paper-a4 {
  width: 794px; min-height: 1123px; flex-shrink: 0;
  background: #fff; color: #1c1c1c;
  padding: 46px 44px 40px; box-sizing: border-box;
  box-shadow: 0 10px 40px rgba(20,24,29,.18);
  font-family: var(--font-body); font-size: 13.5px; line-height: 1.55;
  position: relative;
}

/* Header */
.dp-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 16px; border-bottom: 2.5px solid var(--ink-900); }
.dp-shop { display: flex; gap: 13px; align-items: flex-start; }
.dp-logo { width: 50px; height: 50px; border-radius: 11px; background: linear-gradient(145deg, var(--gold-400), var(--gold-600)); color: var(--ink-900); display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; font-size: 26px; flex-shrink: 0; }
.dp-shop-name { font-family: var(--font-head); font-weight: 700; font-size: 18px; color: var(--ink-900); }
.dp-shop-line { font-size: 12px; color: #555; line-height: 1.5; max-width: 320px; }
.dp-title-wrap { text-align: right; flex-shrink: 0; }
.dp-title-th { font-family: var(--font-head); font-size: 25px; font-weight: 700; color: var(--ink-900); line-height: 1.1; white-space: nowrap; }
.dp-title-en { font-size: 11px; letter-spacing: .22em; color: var(--gold-600); font-weight: 600; margin-top: 2px; }
.dp-stamp { display: inline-block; margin-top: 8px; font-size: 10.5px; font-weight: 600; border-radius: 5px; padding: 3px 10px; letter-spacing: .04em; }
.dp-stamp-original { color: var(--gold-600); border: 1px solid var(--gold-300); background: var(--gold-tint); }
.dp-stamp-copy { color: var(--wine-600); border: 1px solid var(--wine-100); background: var(--wine-100); }

/* Mid: customer + meta */
.dp-mid { display: flex; justify-content: space-between; gap: 28px; margin-top: 18px; }
.dp-customer { flex: 1; min-width: 0; }
.dp-block-label { font-size: 11px; color: #999; margin-bottom: 4px; white-space: nowrap; }
.dp-cust-name { font-weight: 700; font-size: 15px; color: var(--ink-900); }
.dp-cust-line { font-size: 12.5px; color: #555; line-height: 1.55; max-width: 380px; }
.dp-meta { width: 300px; flex-shrink: 0; }
.dp-meta-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 12.5px; }
.dp-meta-label { color: #888; flex-shrink: 0; white-space: nowrap; }
.dp-meta-value { color: var(--ink-900); font-weight: 600; text-align: right; white-space: nowrap; }

/* Project */
.dp-project { margin-top: 16px; background: var(--gold-tint); border: 1px solid var(--gold-100); border-radius: 8px; padding: 9px 14px; display: flex; gap: 10px; align-items: baseline; }
.dp-project-label { font-size: 11.5px; color: var(--gold-600); font-weight: 700; flex-shrink: 0; white-space: nowrap; }
.dp-project-val { font-size: 13px; color: var(--ink-900); font-weight: 500; }

/* Items table */
.dp-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.dp-table thead th { background: var(--ink-900); color: #fff; font-weight: 600; font-size: 12px; padding: 9px 11px; text-align: left; }
.dp-table thead th.c-no { width: 34px; text-align: center; border-radius: 6px 0 0 0; }
.dp-table thead th.c-qty { width: 78px; text-align: right; }
.dp-table thead th.c-price { width: 96px; text-align: right; }
.dp-table thead th.c-disc { width: 80px; text-align: right; }
.dp-table thead th.c-amt { width: 104px; text-align: right; border-radius: 0 6px 0 0; }
.dp-table tbody td { padding: 10px 11px; border-bottom: 1px solid #eee; vertical-align: top; font-size: 12.5px; }
.dp-table tbody td.c-no { text-align: center; color: #999; }
.dp-table tbody td.c-qty, .dp-table tbody td.c-price, .dp-table tbody td.c-disc, .dp-table tbody td.c-amt { text-align: right; }
.dp-table tbody td.c-amt { font-weight: 600; color: var(--ink-900); }
.dp-item-name { font-weight: 600; color: var(--ink-900); }
.dp-item-desc { font-size: 11.5px; color: #888; margin-top: 2px; }

/* Delivery note table */
.dp-table-delivery thead th.c-status { width: 130px; text-align: right; border-radius: 0 6px 0 0; }
.dp-table-delivery thead th.c-qty { text-align: right; }
.dp-table-delivery thead th.c-amt { border-radius: 0; }
.dp-table-delivery tbody td.c-status { text-align: right; }
.dp-status-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--green-600); background: var(--green-100); padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
.dp-delivery-note-spacer { height: 30px; }

/* Summary */
.dp-summary-wrap { display: flex; justify-content: space-between; gap: 24px; margin-top: 14px; align-items: flex-start; }
.dp-bahttext { flex: 1; padding-top: 8px; }
.dp-bahttext-paren { font-size: 12.5px; color: #555; font-style: italic; }
.dp-summary { width: 320px; flex-shrink: 0; }
.dp-sum-row { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; font-size: 13px; color: #444; }
.dp-sum-label { color: #666; white-space: nowrap; }
.dp-sum-value { font-weight: 600; color: var(--ink-900); }
.dp-baht { color: #999; font-weight: 400; font-size: 11.5px; }
.dp-sum-strong { border-top: 1px solid #ddd; padding-top: 8px; margin-top: 2px; }
.dp-sum-strong .dp-sum-label, .dp-sum-strong .dp-sum-value { font-weight: 700; color: var(--ink-900); font-size: 13.5px; }
.dp-sum-pay { background: var(--ink-900); color: #fff; border-radius: 8px; padding: 9px 14px; margin-top: 6px; }
.dp-sum-pay .dp-sum-label { color: #d8dde3; font-weight: 600; }
.dp-sum-pay .dp-sum-value { color: var(--gold-300); font-weight: 700; font-size: 16px; }
.dp-sum-pay .dp-baht { color: #9aa3ad; }

/* Notes */
.dp-notes { margin-top: 20px; border: 1px solid var(--line); border-left: 3px solid var(--gold-500); border-radius: 6px; padding: 11px 14px; background: #fbfaf7; }
.dp-notes-label { font-size: 11.5px; color: var(--gold-600); font-weight: 700; margin-bottom: 3px; }
.dp-notes-body { font-size: 12.5px; color: #555; line-height: 1.6; }

/* Receipt payment block */
.dp-payment { margin-top: 18px; border: 1px dashed var(--line); border-radius: 8px; padding: 12px 14px; background: #fbfaf7; }
.dp-payment-line { font-size: 12px; color: #666; }
.dp-payment-methods { display: flex; gap: 18px; margin: 9px 0; flex-wrap: wrap; }
.dp-paychip { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: #555; }
.dp-paychip.on { color: var(--ink-900); font-weight: 700; }
.dp-paybox { width: 15px; height: 15px; border: 1.5px solid #999; border-radius: 3px; display: grid; place-items: center; font-size: 11px; color: var(--green-600); }
.dp-paychip.on .dp-paybox { border-color: var(--green-600); background: var(--green-100); }
.dp-payment-bank { font-size: 12.5px; color: var(--ink-900); font-weight: 500; margin-top: 4px; }

/* Signatures */
.dp-signs { display: flex; justify-content: space-between; gap: 60px; margin-top: 40px; }
.dp-sign-col { flex: 1; text-align: center; }
.dp-sign-inname { font-size: 12px; color: #555; margin-bottom: 6px; }
.dp-sign-space { height: 50px; display: flex; align-items: flex-end; justify-content: center; }
.dp-sign-img { max-height: 50px; max-width: 160px; object-fit: contain; }
.dp-sign-line { border-bottom: 1px dotted #999; margin: 0 10px 7px; }
.dp-sign-role { font-size: 11.5px; color: #888; }
.dp-sign-date { font-size: 11.5px; color: #888; margin-top: 4px; }

/* Modal doc size */
.modal-doc { max-width: 880px; }

/* Payment history (in preview modal) */
.payment-history-section { margin-top: 18px; }
.ph-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: var(--text-900); margin-bottom: 10px; }
.ph-title svg { color: var(--gold-600); }
.ph-card { border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; background: var(--surface); display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.ph-rows { display: grid; grid-template-columns: repeat(2, minmax(160px, 1fr)); gap: 8px 24px; flex: 1; }
.ph-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.ph-label { color: var(--text-500); }
.ph-value { font-weight: 600; color: var(--text-900); }
.ph-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (max-width: 600px) { .ph-rows { grid-template-columns: 1fr; } .ph-card { flex-direction: column; align-items: stretch; } }

/* ===== Payment attachment page ===== */
.payment-attachment { margin-top: 24px; }
.pa-section-title { font-family: var(--font-head); font-weight: 700; font-size: 16px; color: var(--ink-900); margin: 24px 0 12px; padding-bottom: 6px; border-bottom: 1.5px solid var(--gold-400, #bf9b49); }
.pa-empty { color: #888; font-size: 13.5px; padding: 8px 0; }
.pa-banks { display: flex; flex-direction: column; gap: 14px; }
.pa-bank { display: flex; justify-content: space-between; align-items: center; gap: 18px; border: 1px solid #e2ddd2; border-radius: 10px; padding: 14px 18px; }
.pa-bank-name { font-weight: 700; font-size: 15px; color: var(--ink-900); margin-bottom: 4px; }
.pa-bank-line { font-size: 13.5px; color: #333; line-height: 1.6; }
.pa-qr { width: 120px; height: 120px; object-fit: contain; border: 1px solid #e2ddd2; border-radius: 8px; flex-shrink: 0; background: #fff; }
.pa-cheques { display: flex; flex-direction: column; gap: 6px; }
.pa-cheque-line { font-size: 14px; color: #333; }
.pa-note { margin-top: 26px; padding: 14px 18px; background: #faf6ec; border: 1px solid var(--gold-200, rgba(191,155,73,.35)); border-radius: 10px; font-size: 13px; color: #5a4a22; line-height: 1.7; }

/* ===== Print ===== */
@media print {
  html, body { height: auto !important; background: #fff !important; }
  body.printing-doc #root { display: none !important; }
  /* Hide every portaled modal except the one holding the document */
  body.printing-doc .modal-overlay { display: none !important; }
  body.printing-doc .modal-overlay:has(#doc-print-area) {
    display: block !important;
    position: static !important; inset: auto !important;
    padding: 0 !important; margin: 0 !important; background: #fff !important;
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important; overflow: visible !important;
  }
  body.printing-doc .modal-overlay:has(#doc-print-area) .modal {
    position: static !important; max-width: none !important; width: auto !important;
    max-height: none !important; box-shadow: none !important; border-radius: 0 !important;
    margin: 0 !important; animation: none !important; display: block !important;
  }
  body.printing-doc .modal-head, body.printing-doc .modal-foot, body.printing-doc .doc-toolbar { display: none !important; }
  body.printing-doc .modal-body { padding: 0 !important; overflow: visible !important; max-height: none !important; }
  body.printing-doc .doc-scroll { margin: 0 !important; padding: 0 !important; background: #fff !important; display: block !important; overflow: visible !important; }
  body.printing-doc #doc-print-area { display: block !important; gap: 0 !important; }
  body.printing-doc #doc-print-area .doc-paper-a4 {
    width: 100% !important; min-height: auto !important; margin: 0 auto !important;
    box-shadow: none !important; padding: 0 !important;
    page-break-after: always; break-after: page;
  }
  body.printing-doc #doc-print-area .doc-paper-a4:last-child { page-break-after: auto; break-after: auto; }
  @page { size: A4; margin: 11mm; }
}

@media (max-width: 880px) {
  .doc-paper-a4 { transform-origin: top center; }
}
