/* POS Toko Material — tema mengikuti demo: krem #F6F2EC, oranye #C2410C/#EA580C.
   Font Plus Jakarta Sans + JetBrains Mono di-bundle lokal (assets/fonts/)
   supaya aplikasi jalan offline tanpa Google Fonts. */
@font-face { font-family: 'Plus Jakarta Sans'; src: url('assets/fonts/plus-jakarta-sans-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Plus Jakarta Sans'; src: url('assets/fonts/plus-jakarta-sans-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Plus Jakarta Sans'; src: url('assets/fonts/plus-jakarta-sans-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Plus Jakarta Sans'; src: url('assets/fonts/plus-jakarta-sans-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Plus Jakarta Sans'; src: url('assets/fonts/plus-jakarta-sans-latin-800-normal.woff2') format('woff2'); font-weight: 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('assets/fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('assets/fonts/jetbrains-mono-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('assets/fonts/jetbrains-mono-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }

/* Elemen dengan atribut hidden harus selalu tersembunyi — tanpa ini,
   display:flex di .struk-wrap/.modal-wrap/#aiPanel mengalahkan hidden
   sehingga overlay/modal tidak bisa ditutup (bug: tombol Tutup tidak jalan). */
[hidden] { display: none !important; }

:root {
  --bg: #F6F2EC; --surface: #FFFFFF; --surface2: #FFF7ED;
  --ink: #1C1917; --muted: #78716C; --line: #E7E5E4;
  --orange: #EA580C; --orange-dark: #C2410C; --orange-soft: #FFEDD5;
  --green: #15803D; --green-soft: #DCFCE7; --red: #B91C1C; --red-soft: #FEE2E2;
  --amber: #B45309; --amber-soft: #FEF3C7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.05);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Plus Jakarta Sans', system-ui, sans-serif; font-size: 15px; }
h1 { font-size: 22px; margin: 0; letter-spacing: .2px; }
h2 { font-size: 19px; margin: 0 0 10px; }
h3 { font-size: 16px; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.mono, .card-value, .nota-no, .struk { font-family: 'JetBrains Mono', ui-monospace, monospace; }

/* Kredit kecil di pojok kanan bawah layar — tidak ikut tercetak di struk
   (lihat @media print di bawah). */
#watermark {
  position: fixed; right: 14px; bottom: 8px; z-index: 1; pointer-events: none;
  font-size: 9px; color: var(--muted); opacity: .45;
}
@media print { #watermark { display: none; } }

/* Header */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 22px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-logo { width: 44px; height: 44px; border-radius: 10px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-right { display: flex; gap: 10px; align-items: center; }
.badge-local { background: var(--green-soft); color: var(--green); font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 999px; }

/* Menu */
.menu { display: flex; gap: 8px; padding: 12px 22px 0; flex-wrap: wrap; }
.menu-btn { border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer; }
.menu-btn:hover { border-color: var(--orange); }
.menu-btn.active { background: var(--orange); border-color: var(--orange); color: #fff; }
.pill { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 2px 7px; margin-left: 4px; }

main { padding: 16px 22px 90px; }
.view { display: none; }
.view.active { display: block; }

/* Kartu ringkasan (diperkecil) */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.card.warn { background: var(--amber-soft); border-color: #FDE68A; }
.card-label { margin: 0 0 3px; color: var(--muted); font-size: 12px; }
.card-value { margin: 0; font-size: 19px; font-weight: 700; }
.card-sub { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

/* Kasir */
.kasir-grid { display: grid; grid-template-columns: 1fr 360px; gap: 18px; align-items: start; }
/* Pencarian + tombol X untuk mengosongkan */
.search-row { display: flex; gap: 10px; margin-bottom: 12px; }
.search-wrap { position: relative; flex: 1; display: flex; }
.search-wrap input { padding-right: 36px; }
.search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: none; background: transparent; font-size: 17px; line-height: 1; color: var(--muted); cursor: pointer; padding: 6px 9px; border-radius: 50%; }
.search-clear:hover { color: var(--ink); background: var(--line); }
input[type=text], input[type=date], select, textarea { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); width: 100%; }
input:focus, select:focus { outline: 2px solid var(--orange); outline-offset: 0; border-color: var(--orange); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 7px 13px; border-radius: 999px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip.active { background: var(--orange-dark); border-color: var(--orange-dark); color: #fff; }
.produk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.produk-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px; cursor: pointer; box-shadow: var(--shadow); }
.produk-card:hover { border-color: var(--orange); }
.produk-card.disabled { opacity: .55; cursor: not-allowed; }
.produk-card h4 { margin: 0 0 4px; font-size: 15px; }
.produk-card .harga { font-family: 'JetBrains Mono', monospace; font-weight: 700; color: var(--orange-dark); }
.produk-card .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stok-tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-top: 8px; }
.stok-tag.aman { background: var(--green-soft); color: var(--green); }
.stok-tag.menipis { background: var(--amber-soft); color: var(--amber); }
.stok-tag.habis { background: var(--red-soft); color: var(--red); }
.empty-note { color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; }

/* Nota */
.nota { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); position: sticky; top: 76px; }
.nota h2 { margin-bottom: 2px; }
.nota-no { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.nota label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.nota label input { margin-top: 4px; font-weight: 400; }
#keranjang { margin: 6px 0; }
.cart-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.cart-item .nm { flex: 1; }
.cart-item .nm small { display: block; color: var(--muted); font-size: 12px; }
.qty-btn { width: 26px; height: 26px; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; cursor: pointer; font: inherit; font-weight: 700; }
.qty-btn:hover { border-color: var(--orange); }
.cart-item .hrg { font-family: 'JetBrains Mono', monospace; font-size: 13px; min-width: 86px; text-align: right; }
.cart-item .del { border: none; background: none; cursor: pointer; color: var(--red); font-size: 15px; }
.empty-cart { color: var(--muted); font-size: 13px; }
.nota-rows { margin-top: 12px; }
.nota-rows .row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; }
.nota-rows .row.total { font-weight: 800; font-size: 18px; border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; }
.nota-rows .row.total span:last-child { font-family: 'JetBrains Mono', monospace; color: var(--orange-dark); }
.money-input { width: 130px !important; text-align: right; font-family: 'JetBrains Mono', monospace; }
.metode { display: flex; gap: 8px; margin: 14px 0; }
.metode-btn { flex: 1; border: 1px solid var(--line); background: var(--bg); padding: 10px 4px; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; }
.metode-btn.active { background: var(--orange); border-color: var(--orange); color: #fff; }

/* Tombol */
.btn { font: inherit; font-weight: 700; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.btn:hover { border-color: var(--orange); }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); }
.btn-ghost { background: var(--surface); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #991B1B; }
.btn-block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Tabel */
.tabel { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.tabel th, .tabel td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
.tabel th { background: var(--surface2); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.tabel tr:last-child td { border-bottom: none; }
.tabel .angka { font-family: 'JetBrains Mono', monospace; text-align: right; }
.status-pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.status-pill.aman { background: var(--green-soft); color: var(--green); }
.status-pill.menipis { background: var(--amber-soft); color: var(--amber); }
.status-pill.habis { background: var(--red-soft); color: var(--red); }
.status-pill.lunas { background: var(--green-soft); color: var(--green); }
.status-pill.bon { background: var(--red-soft); color: var(--red); }
.overdue { color: var(--red); font-weight: 700; }
.view-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.view-head h2 { margin: 0; }

/* Form */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); max-width: 860px; }
.form-grid label { display: block; font-size: 13px; font-weight: 600; }
.form-grid label input, .form-grid label select { margin-top: 5px; font-weight: 400; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 10px; }
.form-msg { margin-top: 12px; font-weight: 600; }
.form-msg.ok { color: var(--green); }
.form-msg.err { color: var(--red); }

/* Piutang */
.piutang-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.piutang-card.overdue { border-color: var(--red); }
.piutang-card .head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.piutang-card .jumlah { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 18px; color: var(--red); }
.piutang-card .actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* Laporan */
.chart-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.chart-box canvas { width: 100%; height: 260px; }
.top-item { display: flex; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; margin-bottom: 8px; }
.top-item b { font-family: 'JetBrains Mono', monospace; }

/* Pengaturan */
.settings-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); max-width: 720px; }
.settings-box.danger { border-color: #FCA5A5; background: #FFFBFB; }
.settings-box h3 { margin-top: 0; }

/* FAB AI */
#aiFab { position: fixed; left: 22px; bottom: 22px; z-index: 40; background: var(--orange); color: #fff; border: none; border-radius: 999px; padding: 13px 20px; font: inherit; font-weight: 700; cursor: pointer; box-shadow: 0 6px 20px rgba(234,88,12,.4); }
#aiPanel { position: fixed; left: 22px; bottom: 86px; z-index: 40; width: 380px; max-width: calc(100vw - 44px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0,0,0,.18); display: flex; flex-direction: column; overflow: hidden; }
.ai-head { display: flex; justify-content: space-between; gap: 8px; padding: 12px 14px; background: var(--surface2); border-bottom: 1px solid var(--line); font-size: 13px; }
.ai-chat { height: 300px; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-msg { padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.ai-msg.user { background: var(--orange-soft); align-self: flex-end; max-width: 85%; }
.ai-msg.bot { background: var(--bg); align-self: flex-start; max-width: 92%; }
.ai-saran { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px 10px; }
.ai-saran button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 10px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.ai-input-row { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }

/* Modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 60; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 22px; width: 480px; max-width: calc(100vw - 40px); max-height: 86vh; overflow-y: auto; }
.modal h3 { margin-top: 0; }
.modal label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.modal label input, .modal label select, .modal label textarea { margin-top: 5px; font-weight: 400; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.modal .danger-text { color: var(--red); font-weight: 700; }

/* Struk */
.struk-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 70; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 20px; }
.struk { background: #fff; width: 320px; max-height: 70vh; overflow-y: auto; padding: 18px 16px; font-size: 12.5px; line-height: 1.5; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.struk h4, .struk p { margin: 0; }
.struk .center { text-align: center; }
.struk hr { border: none; border-top: 1px dashed #999; margin: 8px 0; }
.struk .row { display: flex; justify-content: space-between; }
.struk-actions { display: flex; gap: 10px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px; font-weight: 600; z-index: 90; box-shadow: 0 6px 24px rgba(0,0,0,.3); max-width: 90vw; }

/* Cetak: hanya struk yang keluar */
@media print {
  body * { visibility: hidden; }
  #strukWrap, #strukWrap * { visibility: visible; }
  #strukWrap { position: absolute; inset: 0; background: #fff; }
  .struk-actions { display: none !important; }
  .struk { box-shadow: none; width: 100%; max-height: none; }
}

@media (max-width: 900px) {
  .kasir-grid { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .nota { position: static; }
}
