:root{
  --ink:#1a2b4a;--ink-soft:#4a5a72;--line:#d8dee9;--paper:#fbfcfe;--bg:#eef1f6;
  --accent:#2563a8;--accent-dark:#1b4d84;--ok:#127a45;--ok-bg:#e3f4ea;--warn:#a13b2b;
  --nota:#f7d5db;--nota-ink:#1c3f8f;--radius:10px;
}
*{box-sizing:border-box}
body{margin:0;font-family:"Segoe UI",system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--ink);font-size:14px;line-height:1.5}

/* LOGIN */
.login-screen{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}
.login-box{background:var(--paper);border:1px solid var(--line);border-radius:14px;padding:32px;width:100%;max-width:380px}
.login-box h1{margin:0 0 4px;font-size:20px;color:var(--accent-dark)}
.login-box .sub{color:var(--ink-soft);font-size:13px;margin:0 0 18px}
.login-box label{margin-top:12px}

/* HEADER */
header.app{background:linear-gradient(135deg,var(--accent-dark),var(--accent));color:#fff;padding:16px 22px;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:12px}
header.app h1{margin:0;font-size:19px;font-weight:700}
header.app .sub{font-size:12px;opacity:.85}
nav.tabs{display:flex;gap:4px;flex-wrap:wrap;align-items:center}
nav.tabs button{background:rgba(255,255,255,.12);color:#fff;border:none;padding:9px 16px;border-radius:8px;cursor:pointer;font-size:13px;font-weight:600}
nav.tabs button.active{background:#fff;color:var(--accent-dark)}
nav.tabs button.logout{background:rgba(0,0,0,.15)}

main{max-width:1120px;margin:22px auto;padding:0 18px 60px}
.panel{display:none}
.panel.active{display:block}
.card{background:var(--paper);border:1px solid var(--line);border-radius:var(--radius);padding:20px;margin-bottom:18px}
.card h2{margin:0 0 14px;font-size:15px;color:var(--accent-dark);border-bottom:2px solid var(--line);padding-bottom:8px}

label{display:block;font-size:12px;font-weight:600;color:var(--ink-soft);margin-bottom:4px}
input,select,textarea{width:100%;padding:8px 10px;border:1px solid var(--line);border-radius:7px;font-size:13px;font-family:inherit;background:#fff;color:var(--ink)}
input:focus,select:focus,textarea:focus{outline:2px solid var(--accent);border-color:var(--accent)}
.grid{display:grid;gap:12px}
.g2{grid-template-columns:1fr 1fr}.g3{grid-template-columns:1fr 1fr 1fr}.g4{grid-template-columns:repeat(4,1fr)}
@media(max-width:680px){.g2,.g3,.g4{grid-template-columns:1fr}}
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:flex-end}

button.btn{background:var(--accent);color:#fff;border:none;padding:9px 16px;border-radius:7px;cursor:pointer;font-size:13px;font-weight:600}
button.btn:hover{background:var(--accent-dark)}
button.btn.full{width:100%;margin-top:18px;padding:11px}
button.btn.ghost{background:#fff;color:var(--accent);border:1px solid var(--accent)}
button.btn.danger{background:#fff;color:var(--warn);border:1px solid var(--warn)}
button.btn.sm{padding:5px 10px;font-size:12px}

table{width:100%;border-collapse:collapse;font-size:13px}
th,td{padding:8px 9px;text-align:left;border-bottom:1px solid var(--line)}
th{background:#f0f4fa;color:var(--ink-soft);font-size:11px;text-transform:uppercase;letter-spacing:.4px}
td.num,th.num{text-align:right}
.muted{color:var(--ink-soft);font-size:12px}
.pill{display:inline-block;background:var(--ok-bg);color:var(--ok);padding:2px 9px;border-radius:20px;font-size:11px;font-weight:700}
.empty{text-align:center;padding:26px;color:var(--ink-soft)}
.totbar{display:flex;justify-content:flex-end;gap:26px;padding:14px 6px;font-weight:700;font-size:15px;border-top:2px solid var(--line)}

.stat{background:#f0f4fa;border:1px solid var(--line);border-radius:10px;padding:18px}
.stat-label{font-size:12px;color:var(--ink-soft);font-weight:600}
.stat-num{font-size:24px;font-weight:800;color:var(--accent-dark);margin-top:6px}

.alert{padding:10px 12px;border-radius:7px;font-size:13px;margin-bottom:12px}
.alert.err{background:#fdecea;color:var(--warn);border:1px solid #f0c4bd}
.toast{position:fixed;bottom:22px;left:50%;transform:translateX(-50%);background:var(--ink);color:#fff;padding:11px 20px;border-radius:8px;font-size:13px;opacity:0;pointer-events:none;transition:opacity .25s;z-index:99}
.toast.show{opacity:1}

/* ====== NOTA ====== */
.nota-wrap{background:var(--nota);padding:34px 40px;border:1px solid #e2b8c1;color:var(--nota-ink);font-family:"Segoe UI",sans-serif}
.nota-head{display:flex;justify-content:space-between;gap:20px;align-items:flex-start}
.nota-head .col{font-size:13px;line-height:1.55;overflow-wrap:break-word;word-break:break-word}
.nota-head .nota-comp{flex:0 0 40%;max-width:40%}   /* kolom kiri: nama usaha + alamat, alamat panjang turun ke bawah */
.nota-head .col-yth{flex:0 0 30%;max-width:30%}
.nota-head .nota-meta{flex:0 0 28%;max-width:28%}
.nota-comp b{font-size:16px}
.nota-meta table{width:auto}
.nota-meta td:last-child{white-space:nowrap}
.nota-title{font-weight:700;text-align:left;padding-left:6px;margin-bottom:4px}
.nota-meta td{border:none;padding:1px 6px;font-size:13px;background:none;text-transform:none;letter-spacing:0;color:inherit}
.nota-wrap hr{border:none;border-top:1px dashed #9aa9d0;margin:16px 0}
table.nota-items{width:100%;font-size:12.5px;table-layout:fixed}
table.nota-items th,table.nota-items td{border:none;padding:3px 6px;color:inherit;vertical-align:top}
table.nota-items thead th{border-bottom:1px dashed #9aa9d0;text-transform:none;background:none;color:inherit;font-weight:700;letter-spacing:0}
/* Lebar kolom tetap; kolom No (1) & Nama Produk (2) diatur, sisanya rata.
   Nama produk panjang otomatis turun ke baris berikutnya. */
table.nota-items col.c-no{width:5%}
table.nota-items col.c-name{width:42%}
table.nota-items col.c-qty{width:11%}
table.nota-items col.c-price{width:15%}
table.nota-items col.c-disc{width:11%}
table.nota-items col.c-sub{width:16%}
table.nota-items td.it-name{overflow-wrap:break-word;word-break:break-word;white-space:normal}
table.nota-items td.it-sn{overflow-wrap:break-word;word-break:break-word;white-space:normal}
.nota-sn{font-size:11px;padding-left:6px}
.nota-foot{display:flex;justify-content:space-between;gap:20px;margin-top:14px;align-items:flex-start}
.nota-sign-group{display:flex;gap:20px;flex:0 0 62%;max-width:62%}
.sign{text-align:center;font-size:12px;flex:1 1 0;min-width:0}
.sign .box{height:60px;position:relative;overflow:visible}
.stamp-lunas{
  position:absolute;left:0;top:50%;
  transform:translateY(calc(-50% + var(--dy,0px))) translateX(var(--dx,0px)) rotate(var(--rot,-8deg));
  transform-origin:left center;
  opacity:var(--op,.85);
  mix-blend-mode:multiply;
  pointer-events:none;z-index:5;line-height:0;
  -webkit-print-color-adjust:exact;print-color-adjust:exact;
}
/* Stempel LUNAS — HTML/CSS murni (bukan SVG), lihat stampLunasSVG() di
   app.js utk alasannya (SVG-sebagai-gambar rapuh saat dipotret html2canvas
   di Safari/iOS). box-sizing:border-box supaya border ikut terhitung dlm
   width/height yang sudah ditentukan (border tidak menambah ukuran total). */
.stamp-box{position:relative;display:block;box-sizing:border-box;background:none}
.stamp-box-in{box-sizing:border-box}
/* Warna dipaksa !important, BUKAN cuma mengandalkan spesifisitas selector:
   aturan ".nota-pdf *{color:#000}" (utk gaya dot matrix hitam-putih di
   PDF/print) di browser ASLI sudah kalah spesifisitas lawan selector 2-kelas
   di bawah — tapi html2canvas (dipakai utk Save PDF & Print) meng-clone
   halaman lewat mesin CSS-nya SENDIRI yang TERBUKTI salah menghitung
   urutan/spesifisitas aturan ini (stempel jadi hitam di hasil clone-nya,
   padahal computed style di DOM asli sudah benar merah/putih). !important
   tidak bergantung pada resolusi spesifisitas itu sama sekali, jadi aman
   dari bug tersebut di mesin/browser manapun.  */
.stamp-lunas .stamp-word{
  display:flex;justify-content:center;line-height:1;
  font-family:"Arial Black",Arial,sans-serif;font-weight:900;font-style:italic;
  color:#d21e1e!important;white-space:nowrap;transform-origin:center;
}
.stamp-lunas .stamp-word span{color:#d21e1e!important}
.stamp-lunas .stamp-banner{
  display:flex;align-items:center;justify-content:center;box-sizing:border-box;
  font-family:Arial,sans-serif;font-weight:700;color:#fff!important;
  letter-spacing:.3mm;white-space:nowrap;
}
.sign .sign-role{white-space:nowrap}
.sign .sign-name{display:flex;justify-content:center;align-items:baseline;gap:2px;font-weight:700;max-width:100%}
.sign .sign-name .par{flex:0 0 auto}
.sign .sign-name .fill{flex:1 1 auto;min-width:80px;text-align:center;overflow-wrap:break-word;word-break:break-word}
.nota-tot{flex:0 0 34%;max-width:34%}
.nota-tot table{width:100%;margin-left:auto}
.nota-tot td{border:none;padding:2px 8px;font-size:13px;background:none;text-transform:none;letter-spacing:0;color:inherit}
.nota-tot td.num{text-align:right;font-weight:600}
.nota-note{font-style:italic;text-align:right;font-size:11px;margin-top:4px}
.nota-bank{margin-top:18px;font-size:12px}

/* ============================================================
   RESPONSIF — tablet & smartphone
   ============================================================ */
/* Header & tab menu bisa di-scroll horizontal di layar kecil */
@media(max-width:900px){
  header.app{padding:12px 14px}
  header.app h1{font-size:17px}
  main{margin:16px auto;padding:0 12px 80px}
  .card{padding:16px}
  nav.tabs{width:100%;overflow-x:auto;flex-wrap:nowrap;-webkit-overflow-scrolling:touch;padding-bottom:4px}
  nav.tabs button{white-space:nowrap;flex:0 0 auto}
}

/* Tablet: grid 4 kolom jadi 2 kolom */
@media(max-width:820px){
  .g3{grid-template-columns:1fr 1fr}
  .g4{grid-template-columns:1fr 1fr}
}

/* Smartphone */
@media(max-width:600px){
  header.app{flex-direction:column;align-items:stretch;gap:8px}
  header.app .sub{font-size:11px}
  .g2,.g3,.g4{grid-template-columns:1fr}
  .row{flex-direction:column;align-items:stretch}
  .row>div{width:100%}
  .row button.btn{width:100%}
  /* Input lebih besar agar nyaman disentuh & tidak zoom di iOS */
  input,select,textarea{font-size:16px;padding:10px 12px}
  button.btn{padding:11px 16px}
  .card h2{font-size:14px}

  /* Tabel lebar -> bisa digeser horizontal tanpa merusak layout */
  .table-wrap{width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
  table{min-width:560px}

  /* Nota di layar: perkecil & bisa digeser */
  .nota-wrap{padding:18px 16px;font-size:12px}
  .nota-head{flex-direction:column;gap:10px}
  .nota-head .nota-comp,.nota-head .col-yth,.nota-head .nota-meta{flex:1 1 100%;max-width:100%}
  .nota-meta table{width:100%}
}

/* Area aman untuk perangkat dengan notch (iPhone) saat mode PWA */
@supports(padding:max(0px)){
  header.app{padding-left:max(14px,env(safe-area-inset-left));padding-right:max(14px,env(safe-area-inset-right))}
  main{padding-bottom:max(80px,env(safe-area-inset-bottom))}
}

#printArea{display:none}

/* Gaya dot-matrix kompak — dipakai tombol Print (window.print() lewat
   printNotaHTML() di app.js). "Save PDF" TIDAK lewat sini lagi: PDF-nya
   sekarang digambar langsung pakai jsPDF (lihat saveNotaPdfNative() di
   app.js), tidak lagi merender HTML/CSS sama sekali.
   Class ".nota-pdf" ditempel LANGSUNG di elemen .nota-wrap (lihat
   notaHTML() di app.js) supaya gaya ini selalu aktif tanpa syarat & tidak
   bergantung pada ancestor manapun — pengukuran tinggi sebelum
   window.print() jadi akurat. */
.nota-wrap.nota-pdf{
  background:#fff;color:#000;border:none;padding:2mm 4mm;max-width:none;
  font-family:"Courier New",Courier,"Consolas",monospace;font-size:11px;
  line-height:1.3;font-weight:600;margin:0;
}
.nota-pdf *{color:#000}
.nota-pdf .nota-comp b{font-size:12px}
.nota-pdf .nota-head .col{font-size:11px;line-height:1.25}
.nota-pdf .nota-meta td,.nota-pdf .nota-tot td{font-size:11px;padding:0 6px}
.nota-pdf table.nota-items{font-size:11px}
.nota-pdf table.nota-items th,.nota-pdf table.nota-items td{padding:1px 6px}
.nota-pdf .nota-foot{margin-top:6px}
.nota-pdf .sign .box{height:30px;position:relative}
.nota-pdf .nota-bank{margin-top:6px;font-size:11px}
.nota-pdf .nota-sign-group{gap:12px}
.nota-pdf .sign{min-width:0;font-size:11px}
.nota-pdf hr{border:none;border-top:1px dashed #000;margin:6px 0}
/* stempel LUNAS tetap merah di PDF */
.nota-pdf .stamp-svg text,.nota-pdf .stamp-svg rect{}
/* ============================================================
   CETAK GAYA DOT MATRIX
   - Hitam di atas putih, font monospace (khas printer dot matrix)
   - Layout sama untuk kertas roll maupun A4 di printer lain
   - Lebar konten dibatasi agar konsisten (tidak melebar mengikuti A4)
   ============================================================ */
@page{
  /* Ukuran diatur DINAMIS via JS (fungsi printWithTitle) setinggi isi nota,
     sehingga hasil PDF terpotong pas seperti kertas roll. Nilai di bawah
     hanya fallback bila JS tidak berjalan. */
  size:210mm auto;
  margin:6mm;
}
@media print{
  html,body{height:auto!important;min-height:0!important;background:#fff!important;margin:0;padding:0}
  #app,.toast{display:none!important}
  #printArea{display:block!important;height:auto!important;min-height:0!important}

  /* Reset ke tampilan dot matrix */
  .nota-wrap{
    background:#fff!important;
    color:#000!important;
    border:none;
    padding:2mm 0;
    /* Lebar konten tetap agar hasil sama di roll & A4. */
    max-width:190mm;
    font-family:"Courier New",Courier,"Consolas",monospace;
    font-size:11px;
    line-height:1.3;
    font-weight:600;              /* dot matrix cenderung tebal */
    break-inside:avoid;page-break-inside:avoid;
    margin:0 0 4mm;
    border-bottom:1px dashed #000;/* pemisah antar nota (garis gunting) */
  }
  .nota-wrap:last-child{border-bottom:none;margin-bottom:0}

  /* Semua teks & garis jadi hitam */
  .nota-wrap *{color:#000!important;font-family:inherit!important}
  .nota-wrap .stamp-lunas{opacity:.85}
  .nota-wrap hr{border:none;border-top:1px dashed #000;margin:6px 0}
  .nota-comp b{font-size:12px}
  .nota-head .col{font-size:11px;line-height:1.25}
  .nota-meta td,.nota-tot td{font-size:11px;padding:0 6px}
  table.nota-items{font-size:11px}
  table.nota-items th,table.nota-items td{padding:1px 6px}
  table.nota-items thead th{border-bottom:1px dashed #000}
  .nota-foot{margin-top:6px}
  .sign .box{height:30px}
  .nota-bank{margin-top:6px;font-size:11px}
  .nota-sign-group{gap:12px}
  .sign{min-width:0;font-size:11px}
  .nota-note{font-style:italic}
}
