/* ============================================================
   Template Dokumen Fisik SPJ — Gaya Korporat Premium
   (1) Kwitansi Resmi  (2) Faktur Penjualan PPN 12%  (3) BAST
   Dua tingkat: kaya di layar, tetap tajam saat dicetak.
   ============================================================ */

#printArea {
  --paper-w: 215mm;
  --paper-h: 330mm;
  --doc-pad-x: 15mm;
  --doc-pad-y: 13mm;
  --ink: #0f172a;
  --ink-2: #1e293b;
  --ink-soft: #475569;
  --line: #94a3b8;
  --line-soft: #cbd5e1;
  --brand: #2563EB;
  --brand-dark: #1e3a8a;
  --brand-50: #eff6ff;
  --accent: #1e40af;
  --tint: #eef3fa;
}

/* ---------------- KERTAS ---------------- */
.doc-sheet {
  width: var(--paper-w);
  min-height: var(--paper-h);
  background: #fff;
  color: var(--ink);
  padding: var(--doc-pad-y) var(--doc-pad-x);
  position: relative;
  display: flex;
  flex-direction: column;
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  font-size: 10.5pt;
  line-height: 1.5;
  box-shadow: 0 24px 64px rgba(2, 6, 23, .6);
  border-radius: 4px;
  overflow: hidden;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.doc-sheet > *:not(.doc-watermark):not(.doc-accent) { position: relative; z-index: 1; }

/* strip aksen atas (full bleed) */
.doc-accent {
  position: absolute; top: 0; left: 0; right: 0; height: 7px; z-index: 2;
  background: linear-gradient(90deg, var(--ink) 0 52%, var(--brand) 52% 80%, var(--accent) 80% 100%);
}

/* watermark logo */
.doc-watermark { position: absolute; inset: 0; display: grid; place-items: center; z-index: 0; pointer-events: none; }
.doc-watermark img { width: 70%; max-width: 148mm; opacity: .035; filter: grayscale(1); }

/* pemilihan dokumen (checkbox) — lembar yang tidak dicentang disembunyikan */
.doc-sheet.doc-off { display: none !important; }
.doc-sheet.last-visible { page-break-after: auto !important; break-after: auto !important; }

/* mode tangkap PDF (html2canvas): bersihkan hiasan layar agar hasil rapi */
#printArea.is-capturing .doc-sheet { box-shadow: none !important; border-radius: 0 !important; }

/* (kompatibilitas) tab filtering */
#printArea[data-tab="kwitansi"] .doc-sheet:not([data-doc="kwitansi"]),
#printArea[data-tab="faktur"]   .doc-sheet:not([data-doc="faktur"]),
#printArea[data-tab="bast"]     .doc-sheet:not([data-doc="bast"]) { display: none; }

/* ---------------- KOP SURAT ---------------- */
.doc-kop {
  display: flex; align-items: center; gap: 16px;
  padding: 6px 0 12px; border-bottom: 3px solid var(--ink); position: relative; margin-top: 4px;
}
.doc-kop::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}
.kop-line { height: 0; border-top: 1px solid var(--line-soft); margin: 18px 0 0; }
.doc-kop-logo {
  width: 74px; height: 74px; object-fit: contain; flex-shrink: 0; padding: 6px;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .1);
}
.doc-kop-center { flex: 1; text-align: center; }
.doc-kop-center .cv-name {
  font-size: 18.5pt; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  color: var(--ink); line-height: 1.08;
}
.doc-kop-center .cv-tag {
  font-size: 8.4pt; color: var(--brand); letter-spacing: .24em; text-transform: uppercase;
  font-weight: 700; margin-top: 4px;
}
.doc-kop-center .cv-addr { font-size: 8.4pt; color: var(--ink-soft); margin-top: 5px; }
.doc-kop-right {
  width: 78px; text-align: right; font-size: 7.4pt; color: var(--ink-soft); flex-shrink: 0;
  border-left: 1px solid var(--line-soft); padding-left: 10px;
}
.doc-kop-right .npwp { font-weight: 700; color: var(--brand-dark); letter-spacing: .06em; display: block; }

/* ---------------- JUDUL (BAND) ---------------- */
.doc-title { margin: 20px 0 16px; text-align: center; }
.doc-band {
  background: linear-gradient(135deg, var(--ink), var(--ink-2)); color: #fff;
  border-radius: 9px; padding: 11px 20px; box-shadow: 0 10px 22px -10px rgba(15, 23, 42, .6);
}
.doc-band h3 {
  font-size: 13.5pt; text-transform: uppercase; letter-spacing: .18em; font-weight: 700; color: #fff;
}
.doc-title .no {
  display: inline-block; margin-top: 10px; font-size: 9.6pt; letter-spacing: .05em;
  border: 1px solid var(--line-soft); background: #f8fafc; color: var(--brand-dark);
  border-radius: 20px; padding: 4px 18px; font-weight: 700;
}
.doc-title .no::before { content: "Nomor: "; color: var(--ink-soft); font-weight: 400; }
.doc-title .sub { font-size: 10pt; margin-top: 4px; color: var(--ink-soft); }

/* ---------------- INFO BOX ---------------- */
.doc-meta-box, .doc-party {
  border: 1px solid var(--line-soft); border-left: 3px solid var(--brand);
  border-radius: 6px; padding: 10px 14px; margin-bottom: 14px; background: #f8fafc;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .05);
}
.doc-meta-box { display: flex; justify-content: space-between; gap: 22px; }
.doc-meta-box table, .doc-party table { border-collapse: collapse; font-size: 10.5pt; }
.doc-meta-box td, .doc-party td { padding: 2px 0; vertical-align: top; }
.doc-meta-box .lbl, .doc-party .lbl { color: var(--ink-soft); padding-right: 10px; white-space: nowrap; }
.doc-meta-box .val, .doc-party .val { font-weight: 700; }
.doc-meta-box .sep, .doc-party .sep { padding: 0 4px; }

.doc-parties { display: flex; gap: 14px; margin: 10px 0 12px; }
.doc-parties .doc-party { flex: 1; margin-bottom: 0; }
.doc-party-head { font-size: 8.4pt; text-transform: uppercase; letter-spacing: .1em; color: var(--brand-dark); font-weight: 700; }
.doc-party-name { font-weight: 700; margin-top: 3px; }
.doc-party-sub { font-size: 9pt; color: var(--ink-soft); }

/* ---------------- TABEL BARANG ---------------- */
.doc-table {
  width: 100%; border-collapse: collapse; font-size: 9.3pt;
  border: 1.4px solid var(--ink); border-radius: 6px; overflow: hidden;
}
.doc-table th, .doc-table td { border-right: 1px solid var(--line-soft); padding: 7px 10px; }
.doc-table th:last-child, .doc-table td:last-child { border-right: 0; }
.doc-table thead th {
  background: linear-gradient(180deg, var(--ink-2), var(--ink)); color: #fff;
  text-transform: uppercase; font-size: 7.9pt; letter-spacing: .05em; text-align: center;
  font-weight: 700; border-bottom: 1.5px solid var(--ink);
}
.doc-table tbody td { border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.doc-table tbody tr:last-child td { border-bottom: 0; }
.doc-table tbody tr:nth-child(even) { background: #f7fafd; }
.doc-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-table .ctr { text-align: center; }
.doc-table .item-name { font-weight: 600; }
.doc-table tbody tr:hover { background: var(--brand-50); }

/* ---------------- TOTAL ---------------- */
.doc-totals { display: flex; justify-content: flex-end; margin-top: 12px; }
.doc-totals table { border-collapse: collapse; font-size: 10pt; min-width: 350px; border: 1.4px solid var(--ink); border-radius: 6px; overflow: hidden; }
.doc-totals td { padding: 5px 13px; border-bottom: 1px solid var(--line-soft); }
.doc-totals tr:last-child td { border-bottom: 0; }
.doc-totals .lbl { text-align: right; color: var(--ink-soft); }
.doc-totals .val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; border-left: 1px solid var(--line-soft); }
.doc-totals tr.grand .lbl,
.doc-totals tr.grand .val { background: linear-gradient(135deg, var(--ink), var(--ink-2)); color: #fff; font-size: 11.5pt; font-weight: 800; }

/* ---------------- TERBILANG & CATATAN ---------------- */
.qty-note { margin-top: 10px; font-size: 10pt; }
.terbilang-line { margin-top: 10px; font-size: 10.5pt; }
.terbilang-line .box {
  border: 1px dashed var(--brand); background: var(--brand-50); color: var(--brand-dark);
  padding: 8px 14px; display: inline-block; font-style: italic; font-weight: 700; border-radius: 6px;
}
.bank-note {
  margin-top: 10px; font-size: 9.6pt; background: #f1f5f9; border-left: 3px solid var(--brand);
  border-radius: 0 6px 6px 0; padding: 8px 12px;
}
.bank-note strong { display: block; margin-bottom: 2px; color: var(--brand-dark); }

/* ---------------- TANDA TANGAN ---------------- */
.doc-end { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 22px; gap: 16px; }
.doc-end .place { font-size: 10.5pt; }
.doc-end .place .date { margin-top: 2px; }

.doc-sign { display: flex; justify-content: space-between; gap: 14px; margin-top: 12px; text-align: center; }
.doc-sign.cols-2 .col { flex: 1; max-width: 46%; }
.doc-sign.cols-4 .col { flex: 1; }
.doc-sign .col { font-size: 10pt; position: relative; }
.doc-sign .col .place { font-size: 10.5pt; margin-bottom: 6px; white-space: nowrap; }
.doc-sign .col .role { white-space: pre-line; font-weight: 600; }
.doc-sign .col .subtitle { font-size: 9pt; color: var(--ink-soft); }
.doc-sign .col .sign-area { position: relative; height: 76px; }
.doc-sign .col .sign-area::after {
  content: ""; position: absolute; left: 16%; right: 16%; bottom: 6px; border-bottom: 1px dotted var(--line);
}
.doc-sign .col .name { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.doc-sign .col .nip { font-size: 9pt; color: var(--ink-soft); }

/* kotak tanda tangan BAST */
.doc-sign.cols-4 .col .box {
  border: 1px solid var(--line-soft); border-top: 3px solid var(--brand); border-radius: 7px;
  padding: 9px 9px 12px; min-height: 150px; display: flex; flex-direction: column; background: #fff;
  box-shadow: 0 3px 10px rgba(15, 23, 42, .06);
}
.doc-sign.cols-4 .col .box .role { font-weight: 700; }
.doc-sign.cols-4 .col .box .sign-area { flex: 1; min-height: 64px; }
.doc-sign.cols-4 .col .box .sign-area::after { left: 10%; right: 10%; }
.doc-sign.cols-4 .col .box .name { font-size: 9.5pt; }
.doc-sign.cols-4 .stamp { width: 76px; height: 76px; left: 0; bottom: 4px; }
.doc-sign.cols-4 .stamp::before { inset: 6px; }
.doc-sign.cols-4 .stamp img { width: 28px; height: 28px; }
.doc-sign.cols-4 .stamp .stamp-top { top: 11px; font-size: 4.9pt; }
.doc-sign.cols-4 .stamp .stamp-bottom { bottom: 11px; font-size: 4.9pt; }
.doc-sign.cols-4 .dig-sign { width: 86px; height: 38px; left: 2px; bottom: 8px; }

/* ---------------- STEMPEL & TTD DIGITAL ---------------- */
.stamp-element { pointer-events: none; }
.stamp {
  position: absolute; width: 114px; height: 114px; border: 2.6px solid var(--brand);
  border-radius: 50%; color: var(--brand-dark); display: grid; place-items: center;
  transform: rotate(-13deg); opacity: .9; z-index: 3; left: 2px; bottom: 6px;
  box-shadow: inset 0 0 0 2px rgba(15, 23, 42, .06);
}
.stamp::before { content: ""; position: absolute; inset: 8px; border: 1.3px solid var(--brand); opacity: .55; border-radius: 50%; }
.stamp img { width: 42px; height: 42px; object-fit: contain; filter: grayscale(1); opacity: .45; }
.stamp .stamp-top { position: absolute; top: 15px; font-size: 6.4pt; font-weight: 700; letter-spacing: .05em; text-align: center; width: 82%; }
.stamp .stamp-bottom { position: absolute; bottom: 15px; font-size: 6.4pt; font-weight: 700; letter-spacing: .04em; text-align: center; width: 82%; }
.stamp.custom img { width: 60px; height: 60px; filter: none; opacity: .95; }
.dig-sign { width: 124px; height: 54px; position: absolute; left: 8px; bottom: 18px; z-index: 2; object-fit: contain; }
.dig-sign path { fill: none; stroke: #1e3a8a; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
#printArea[data-stamp="off"] .stamp-element,
#printArea[data-stamp="off"] .dig-sign { display: none !important; }

/* ---------------- KWITANSI ---------------- */
.kwitansi-frame {
  border: 1.6px solid var(--ink); border-radius: 8px; padding: 5px; margin-top: 2px;
  background: #fff; box-shadow: 0 12px 26px -14px rgba(15, 23, 42, .4);
}
.kwitansi-inner { border: 1px solid var(--line-soft); border-radius: 5px; padding: 20px 22px; position: relative; overflow: hidden; }
.kwitansi-inner::before {
  content: "KWITANSI"; position: absolute; top: 6px; right: 18px; font-size: 38pt; font-weight: 800;
  letter-spacing: .1em; color: rgba(15, 23, 42, .045); pointer-events: none;
}
.kwitansi-row { display: flex; align-items: flex-end; gap: 12px; padding: 12px 0; border-bottom: 1px dotted var(--line); position: relative; z-index: 1; }
.kwitansi-row .k-lbl { width: 156px; color: var(--ink-soft); flex-shrink: 0; text-transform: uppercase; font-size: 8.6pt; letter-spacing: .06em; font-weight: 700; padding-bottom: 2px; }
.kwitansi-row .k-val { flex: 1; font-weight: 700; }
.kwitansi-row .k-val.italic { font-style: italic; color: var(--brand-dark); }
.kwitansi-amount { display: flex; justify-content: flex-end; margin: 18px 0 6px; }
.amount-box {
  border: 2px solid var(--ink); border-radius: 8px; padding: 10px 20px; display: inline-block;
  min-width: 240px; text-align: right; background: linear-gradient(180deg, #fff, #f1f5f9);
  box-shadow: 0 0 0 5px #fff, 0 5px 0 rgba(15, 23, 42, .14);
}
.amount-box .rp { font-size: 18.5pt; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .01em; color: var(--ink); }
.amount-box .lbl { font-size: 8pt; text-transform: uppercase; letter-spacing: .16em; color: var(--brand-dark); display: block; text-align: right; font-weight: 700; margin-bottom: 3px; }

/* ---------------- FOOTER DOKUMEN ---------------- */
.doc-foot {
  margin-top: auto; padding-top: 9px; border-top: 1px solid var(--line-soft);
  display: flex; justify-content: space-between; gap: 12px; font-size: 7.6pt; color: #94a3b8; letter-spacing: .02em;
}
.doc-foot strong { color: var(--ink-soft); font-weight: 700; }

/* penanda lembar (layar) */
.sheet-tag {
  position: absolute; top: 4.5mm; right: 5mm; z-index: 2;
  font-family: var(--font); font-size: 8pt; color: #94a3b8;
  letter-spacing: .05em; text-transform: uppercase; font-weight: 700;
}

/* ============================================================
   @MEDIA PRINT — tepat 3 halaman + pengaman tanpa background
   ============================================================ */
@media print {
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  body > *:not(#previewModal) { display: none !important; }

  #previewModal {
    position: static !important; inset: auto !important; display: block !important;
    background: #fff !important; backdrop-filter: none !important;
  }
  .modal-chrome, .modal-footer { display: none !important; }
  .paper-viewport { display: block !important; overflow: visible !important; padding: 0 !important; background: #fff !important; }
  .paper-stage { transform: none !important; }
  #printArea { display: block !important; }

  .doc-sheet {
    display: block !important; box-shadow: none !important; border-radius: 0 !important; overflow: visible !important;
    width: 100% !important; min-height: 0 !important; margin: 0 !important;
    page-break-after: always; break-after: page;
  }
  .doc-foot { margin-top: 12px !important; }
  .doc-sheet:last-child { page-break-after: auto; break-after: auto; }
  .doc-table thead { display: table-header-group; }
  .doc-table tr, .doc-sign, .doc-totals, .kwitansi-frame, .doc-meta-box, .doc-party { page-break-inside: avoid; break-inside: avoid; }
  .sheet-tag { display: none !important; }

  /* pengaman bila background tidak dicetak: teks tetap gelap & terbaca */
  .doc-band { background: #fff !important; border: 1.5px solid var(--ink) !important; box-shadow: none !important; }
  .doc-band h3 { color: var(--ink) !important; }
  .doc-table thead th { background: var(--tint) !important; color: var(--ink) !important; }
  .doc-totals tr.grand .lbl, .doc-totals tr.grand .val { background: var(--tint) !important; color: var(--ink) !important; }
  .amount-box { background: #fff !important; box-shadow: none !important; }
  .doc-kop-logo, .doc-sign.cols-4 .col .box, .kwitansi-frame, .doc-meta-box, .doc-party { box-shadow: none !important; }
}
