/* =====================================================================================
   cetak.css : tampilan NOTA, STRUK THERMAL, LAPORAN TIM + aturan @media print
   -------------------------------------------------------------------------------------
   BAGIAN 1  Area cetak & @media print   (menyembunyikan seluruh UI/dashboard saat dicetak)
   BAGIAN 2  Pratinjau di layar          (modal "Cetak Nota / Struk")
   BAGIAN 3  Nota (A4 / A5 / Letter / F4)  gaya bersih & minimalis
   BAGIAN 4  Struk thermal 58 / 80 mm
   BAGIAN 5  Laporan Rekapitulasi Tim & Mitra
   Warna divisi dipakai lewat variabel --div (diisi dari DIVISIONS[nama].hex).
   ===================================================================================== */

/* ============================== BAGIAN 1. AREA CETAK & @MEDIA PRINT ============================== */
#print-root { display: none; }

@media print {
    /* Sembunyikan SEMUA elemen halaman (sidebar, dashboard, modal, toast, backdrop) kecuali area cetak */
    body > *:not(#print-root) { display: none !important; }
    html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; height: auto !important; overflow: visible !important; }
    #print-root { display: block !important; position: static !important; }
    .dok { box-shadow: none !important; margin: 0 !important; border-radius: 0 !important; zoom: 1 !important; }
    .dok-nota, .dok-laporan { page-break-after: always; break-after: page; }
    .dok:last-child { page-break-after: auto; break-after: auto; }
    .dok-struk { page-break-after: always; break-after: page; }
    .dk-tabel tr, .dk-total, .dk-ttd, .lp-k { page-break-inside: avoid; break-inside: avoid; }
    .dk-tabel thead { display: table-header-group; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ============================== BAGIAN 2. PRATINJAU DI LAYAR ============================== */
.cetak-bar { display: flex; flex-wrap: wrap; gap: .75rem; padding: .6rem 1rem; border-bottom: 1px solid rgba(100,116,139,.25); background: rgba(248,250,252,.8); }
.cetak-bar label { display: flex; flex-direction: column; font-size: .72rem; font-weight: 600; color: #475569; gap: .15rem; min-width: 130px; }
.cetak-pratinjau { background: #cbd5e1; padding: 1rem; display: flex; justify-content: center; align-items: flex-start; }
.cetak-kertas { display: flex; flex-direction: column; gap: 1rem; align-items: center; }
.cetak-kertas .dok { box-shadow: 0 6px 24px rgba(15,23,42,.25); }

/* ============================== BAGIAN 3. NOTA ============================== */
.dok { background: #fff; color: #0f172a; font-family: 'Segoe UI', Roboto, Arial, sans-serif; font-size: 11px; line-height: 1.45; box-sizing: border-box; position: relative; }
.dok *, .dok *::before, .dok *::after { box-sizing: border-box; }
.dok .r { text-align: right; } .dok .c { text-align: center; }
.dok small { display: block; font-size: .85em; color: #64748b; font-weight: 400; }

.dok-nota { width: 210mm; min-height: 150mm; padding: 12mm 14mm; }
.dok-a5 { width: 148mm; padding: 9mm 10mm; font-size: 10px; }
.dok-letter { width: 216mm; } .dok-f4 { width: 215mm; }

.dk-kop { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding-bottom: 8px; border-bottom: 1.5px solid #0f172a; }
.dk-merk { display: flex; align-items: center; gap: 10px; }
.dk-usaha { font-size: 1.55em; font-weight: 800; letter-spacing: -.01em; }
.dk-info { font-size: .85em; color: #475569; }
.dk-div { display: flex; align-items: center; gap: 8px; text-align: right; flex-direction: row-reverse; }
.dk-div-ikon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; border: 1.5px solid var(--div, #0f172a); color: var(--div, #0f172a); font-size: 18px; }
.dk-div-teks b { display: block; font-size: 1.05em; letter-spacing: .03em; }
.dk-div-teks small { color: #64748b; }
.dk-judul { text-align: center; font-size: 1.5em; letter-spacing: .12em; margin: 10px 0 8px; font-weight: 800; position: relative; }
.dk-judul::after { content: ''; display: block; width: 60px; height: 3px; background: var(--div, #0f172a); margin: 5px auto 0; border-radius: 2px; }
.dk-meta { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.dk-meta div { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; padding: 5px 8px; }
.dk-meta span { display: block; font-size: .8em; color: #64748b; text-transform: uppercase; letter-spacing: .04em; }
.dk-meta b { font-size: 1.05em; word-break: break-word; }
.dok-a5 .dk-meta { grid-template-columns: repeat(2, 1fr); }

.dk-tabel { width: 100%; border-collapse: collapse; margin: 4px 0; }
.dk-tabel th { background: #0f172a; color: #fff; padding: 5px 7px; font-size: .88em; text-align: left; font-weight: 600; }
.dk-tabel th.r { text-align: right; } .dk-tabel th.c { text-align: center; }
.dk-tabel td { padding: 5px 7px; border-bottom: 1px solid #e2e8f0; vertical-align: top; }
.dk-tabel tbody tr:nth-child(even) td { background: #f8fafc; }

.dk-bawah { display: flex; justify-content: space-between; gap: 14px; margin-top: 8px; align-items: flex-start; }
.dk-kiri { flex: 1; font-size: .92em; }
.dk-kiri > div { margin-bottom: 6px; }
.dk-terbilang span, .dk-catatan span { display: block; font-size: .8em; color: #64748b; text-transform: uppercase; letter-spacing: .04em; }
.dk-terbilang i { text-transform: capitalize; }
.dk-qr { width: 80px; height: 80px; object-fit: contain; }
.dk-total { width: 46%; border-collapse: collapse; }
.dk-total td { padding: 3px 7px; } .dk-total td:last-child { text-align: right; }
.dk-grand td { background: #0f172a; color: #fff; font-weight: 800; font-size: 1.15em; padding: 6px 8px; }
.dk-syarat { margin-top: 8px; font-size: .85em; color: #475569; white-space: pre-wrap; }
.dk-ttd { display: flex; justify-content: flex-end; margin-top: 14px; }
.dk-ttd-box { width: 150px; text-align: center; position: relative; min-height: 80px; }
.dk-garis { height: 52px; border-bottom: 1px solid #0f172a; margin-bottom: 4px; }
.dk-tanda { height: 52px; max-width: 140px; object-fit: contain; display: block; margin: 0 auto 4px; }
.dk-stempel { position: absolute; left: -48px; top: -6px; height: 64px; opacity: .85; }
.dk-app { display: flex; justify-content: space-between; margin-top: 12px; padding-top: 6px; border-top: 1px dashed #94a3b8; font-size: .8em; color: #64748b; font-weight: 600; letter-spacing: .05em; }
.dk-app span { font-weight: 400; letter-spacing: 0; }

/* ============================== BAGIAN 4. STRUK THERMAL ============================== */
.dok-struk { font-family: 'Courier New', ui-monospace, monospace; padding: 3mm 2mm 4mm; color: #000; }
.dok-s80 { width: 80mm; font-size: 11px; }
.dok-s58 { width: 58mm; font-size: 9px; }
.dok-struk small, .dok-struk .sk-sub { color: #000; }
.sk-kop { text-align: center; margin-bottom: 4px; }
.sk-ikon { font-size: 2.4em; line-height: 1; }
.sk-usaha { font-weight: 800; font-size: 1.25em; letter-spacing: .02em; }
.sk-sub { font-size: .82em; }
.sk-judul { text-align: center; font-weight: 800; margin: 4px 0; letter-spacing: .1em; }
.sk-garis { border-top: 1px dashed #000; margin: 4px 0; }
.sk-baris { display: flex; justify-content: space-between; gap: 6px; }
.sk-baris span:last-child { text-align: right; word-break: break-word; }
.sk-tebal { font-weight: 800; }
.sk-total { font-weight: 800; font-size: 1.2em; margin-top: 2px; }
.sk-item { margin: 3px 0; }
.sk-nama { font-weight: 700; word-break: break-word; }
.sk-hit { display: flex; justify-content: space-between; gap: 6px; }
.sk-tengah { text-align: center; margin-top: 5px; }
.sk-kecil { font-size: .8em; margin-top: 2px; }
.dk-barcode { display: block; width: 92%; margin: 6px auto 0; }

/* ============================== BAGIAN 5. LAPORAN TIM & MITRA ============================== */
.dok-laporan { width: 210mm; padding: 12mm 14mm; }
.lp-kop { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; align-items: center; padding-bottom: 8px; border-bottom: 1.5px solid #0f172a; }
.lp-judul { text-align: center; } .lp-judul h1 { font-size: 1.45em; margin: 0 0 2px; font-weight: 800; line-height: 1.2; }
.lp-cetak { text-align: right; font-size: .9em; color: #475569; }
.lp-h { font-size: 1.15em; font-weight: 800; margin: 14px 0 6px; }
.lp-kartu { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.lp-k { border: 1px solid #e2e8f0; border-radius: 10px; padding: 8px 10px; background: #f8fafc; }
.lp-k h3 { font-size: 1em; font-weight: 700; margin: 0 0 6px; }
.lp-donut-wrap { display: flex; align-items: center; gap: 8px; }
.lp-donut { width: 72px; height: 72px; border-radius: 50%; display: grid; place-content: center; text-align: center; position: relative; flex: none; }
.lp-donut::before { content: ''; position: absolute; inset: 14px; background: #f8fafc; border-radius: 50%; }
.lp-donut b, .lp-donut small { position: relative; line-height: 1.1; }
.lp-donut b { font-size: 1.5em; }
.lp-leg { list-style: none; padding: 0; margin: 0; font-size: .88em; }
.lp-leg i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.lp-sub { font-size: .85em; color: #475569; margin-top: 6px; }
.lp-angka { font-size: 3em; font-weight: 800; text-align: center; line-height: 1.1; margin-top: 8px; }
.lp-k .lp-angka + .lp-sub { text-align: center; }
.lp-bar { display: grid; grid-template-columns: 70px 1fr 22px; gap: 5px; align-items: center; font-size: .85em; margin-bottom: 4px; }
.lp-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lp-bar div { background: #e2e8f0; height: 9px; border-radius: 5px; overflow: hidden; } .lp-bar i { display: block; height: 100%; }
.lp-bar b { text-align: right; }
.lp-st { font-weight: 800; font-size: .85em; } .lp-st.on { color: #15803d; } .lp-st.off { color: #b91c1c; }

/* ============================== BAGIAN 6. VARIAN TEMPLATE ==============================
   Setiap template di assets/template/templates.json punya "kelas" (mis. tpl-nota-klasik) yang dipasang pada dokumen.
   Mau membuat template baru? Tulis kelas baru di sini (atau di file .css di folder assets/template lalu isi "css" di templates.json). */
.tpl-ada-latar { background-image: var(--tpl-latar); background-size: cover; background-position: center top; background-repeat: no-repeat; }
.tpl-kop { display: block; width: calc(100% + 28mm); margin: -12mm -14mm 8px; max-width: none; height: auto; }
.dok-a5 .tpl-kop { width: calc(100% + 20mm); margin: -9mm -10mm 8px; }
.tpl-wm { position: absolute; inset: 0; background-size: 70% auto; background-position: center; background-repeat: no-repeat; opacity: .5; pointer-events: none; }
.dok > *:not(.tpl-wm) { position: relative; }

/* --- Nota Klasik Bergaris --- */
.tpl-nota-klasik .dk-kop { border-bottom: 3px double #0f172a; }
.tpl-nota-klasik .dk-judul::after { display: none; }
.tpl-nota-klasik .dk-meta div { background: none; border-radius: 0; border: 1px solid #94a3b8; }
.tpl-nota-klasik .dk-tabel { border: 1px solid #0f172a; }
.tpl-nota-klasik .dk-tabel th { background: #e2e8f0; color: #0f172a; border: 1px solid #0f172a; }
.tpl-nota-klasik .dk-tabel td { border: 1px solid #94a3b8; }
.tpl-nota-klasik .dk-tabel tbody tr:nth-child(even) td { background: none; }
.tpl-nota-klasik .dk-grand td { background: #e2e8f0; color: #0f172a; border: 1px solid #0f172a; }

/* --- Struk Ringkas --- */
.tpl-struk-ringkas .dk-barcode, .tpl-struk-ringkas .sk-ikon, .tpl-struk-ringkas .sk-kop .sk-sub, .tpl-struk-ringkas .sk-item .sk-sub { display: none; }
.tpl-struk-ringkas { padding-top: 1mm; }

/* --- Laporan Tabel Sederhana --- */
.tpl-laporan-tabel .lp-kartu { display: none; }
.tpl-laporan-tabel .lp-teks { display: block; }
.tpl-laporan-tabel .dk-tabel th { background: #e2e8f0; color: #0f172a; }

/* ============================== BAGIAN 7. LAPORAN (lanjutan) ============================== */
.dok-laporan { display: flex; flex-direction: column; min-height: 297mm; }
.dok-laporan .lp-kaki { margin-top: auto; }
.lp-teks { display: none; font-size: 1.05em; margin: 6px 0 10px; padding: 8px 10px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; }
.lp-k h3 i { margin-right: 4px; color: #2f6db5; }
.lp-sisi { flex: 1; min-width: 0; }
.lp-gauge-box { position: relative; width: 100%; max-width: 92px; margin: 0 auto; }
.lp-gauge { width: 100%; display: block; }
.lp-gauge-box.lp-besar { max-width: 140px; margin-top: 6px; }
.lp-gauge-isi { position: absolute; left: 0; right: 0; bottom: 2px; text-align: center; line-height: 1; }
.lp-gauge-isi b { font-size: 2.2em; display: block; } .lp-gauge-isi small { font-size: .9em; color: #475569; }
.lp-tengah { text-align: center; }
.lp-donut small { font-size: .62em; max-width: 44px; line-height: 1.1; }
.lp-batang { width: 100%; height: auto; display: block; margin-top: 4px; }
.lp-tabel th { background: #dfe6f0; color: #0f172a; }
.lp-tabel td { font-size: .95em; }
.lp-kosong { padding: 14px !important; font-weight: 800; letter-spacing: .02em; }
.lp-kaki { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 10px; align-items: center; padding-top: 8px; margin-top: 14px; border-top: 1px solid #0f172a; }
.lp-merk-kaki { display: flex; align-items: center; gap: 8px; }
.lp-qr { display: flex; align-items: center; gap: 8px; justify-content: center; font-size: .85em; }
.lp-qr img, .lp-qr svg { width: 62px; height: 62px; object-fit: contain; }
.lp-kontak { text-align: right; font-size: .85em; }

@media print {
    .dok-nota, .dok-laporan { padding: 0 !important; min-height: 0 !important; }
    .tpl-kop { width: 100% !important; margin: 0 0 8px !important; }
}
