/* ===== KIOS Kasir — Style ===== */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-d: #4338ca;
  --success: #16a34a;
  --success-d: #15803d;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 6px 20px rgba(0,0,0,.04);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
input, select, textarea { font-family: inherit; -webkit-user-select: text; user-select: text; }
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* Boot */
.boot { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.boot-logo { font-size: 56px; }
.boot-title { font-size: 22px; font-weight: 700; color: var(--primary); }
.spinner { width: 30px; height: 30px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); white-space: pre-line; }

/* Buttons */
.btn { border: 0; border-radius: 10px; padding: 11px 16px; font-size: 15px; font-weight: 600; cursor: pointer; background: var(--surface-2); color: var(--text); transition: .15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-d); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--surface-2); border: 1px solid var(--border); }
.btn-block { width: 100%; }
.btn-lg { padding: 15px; font-size: 17px; }
.link-danger { background: none; border: 0; color: var(--danger); font-size: 13px; cursor: pointer; }
.icon-btn { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; width: 42px; height: 42px; font-size: 18px; cursor: pointer; }
.mini-btn { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; font-size: 13px; cursor: pointer; margin-left: 4px; }
.mini-btn.danger { color: var(--danger); border-color: #fecaca; }

/* Inputs */
.inp { width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 15px; background: var(--surface); color: var(--text); }
.inp:focus { outline: none; border-color: var(--primary); }
.inp-lg { font-size: 22px; font-weight: 700; text-align: right; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ===== Login ===== */
.login-screen { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); }
.login-card { background: var(--surface); border-radius: 20px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-logo { font-size: 48px; text-align: center; }
.login-title { text-align: center; margin: 4px 0 0; font-size: 24px; }
.login-sub { text-align: center; color: var(--muted); margin: 2px 0 18px; }
.login-hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.key { padding: 16px; font-size: 20px; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; cursor: pointer; }
.key:active { background: var(--border); }

/* ===== POS ===== */
.pos { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.pos-topbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; white-space: nowrap; }
.brand-ico { font-size: 22px; }
.pos-search { flex: 1; max-width: 480px; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 15px; }
.pos-search:focus { outline: none; border-color: var(--primary); }
.pos-menu { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.user-chip { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; font-size: 13px; font-weight: 600; }
.user-chip .logout { background: none; border: 0; cursor: pointer; font-size: 16px; color: var(--danger); }

.sync-badge { display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 20px; font-size: 13px; font-weight: 600; cursor: pointer; background: var(--surface-2); border: 1px solid var(--border); }
.sync-badge.is-on { color: var(--success); }
.sync-badge.is-off { color: var(--danger); }
.sync-badge .dot { width: 9px; height: 9px; border-radius: 50%; }
.sync-badge .dot.on { background: var(--success); }
.sync-badge .dot.off { background: var(--danger); }
.sync-badge .pend { background: var(--warn); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; }

.pos-main { flex: 1; display: flex; overflow: hidden; position: relative; }
.pos-left { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.cat-bar { display: flex; gap: 8px; padding: 12px 14px; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--border); }
.cat-chip { white-space: nowrap; padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface-2); font-size: 14px; font-weight: 600; cursor: pointer; }
.cat-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.product-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; padding: 14px; align-content: start; }
.product-card { display: flex; flex-direction: column; gap: 6px; padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); cursor: pointer; text-align: left; min-height: 92px; }
.product-card:active { transform: scale(.97); border-color: var(--primary); }
.product-card.habis { opacity: .55; }
.pc-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.pc-price { color: var(--primary); font-weight: 700; font-size: 15px; margin-top: auto; }
.pc-stock { font-size: 11px; color: var(--muted); }

/* Cart */
.cart-panel { width: 360px; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; }
.cart-head { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--border); font-size: 16px; }
.cart-items { flex: 1; overflow-y: auto; padding: 8px; }
.cart-empty { padding: 40px 20px; text-align: center; color: var(--muted); white-space: pre-line; }
.cart-item { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 10px; }
.cart-item:nth-child(odd) { background: var(--surface-2); }
.ci-info { flex: 1; min-width: 0; }
.ci-name { font-weight: 600; font-size: 14px; }
.ci-price { font-size: 12px; color: var(--muted); }
.ci-qty { display: flex; align-items: center; gap: 4px; }
.qbtn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-size: 18px; cursor: pointer; }
.qinp { width: 44px; text-align: center; border: 1px solid var(--border); border-radius: 8px; padding: 6px 2px; font-size: 14px; }
.cart-foot { padding: 14px; border-top: 1px solid var(--border); background: var(--surface-2); padding-bottom: calc(14px + var(--safe-b)); }
.cart-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.cart-total { display: flex; justify-content: space-between; font-size: 22px; font-weight: 800; margin: 8px 0 12px; }
.cart-fab { display: none; }

/* Checkout */
.checkout { min-width: 320px; }
.co-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.co-total { font-size: 28px; font-weight: 800; color: var(--primary); }
.pay-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.pay-tab { flex: 1; padding: 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--surface-2); font-weight: 600; cursor: pointer; font-size: 14px; }
.pay-tab.active { border-color: var(--primary); background: #eef2ff; color: var(--primary); }
.pay-section.hidden, .qris-box.hidden, .hidden { display: none !important; }
.quick-cash { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.co-kembali { font-size: 18px; font-weight: 700; color: var(--success); margin-top: 10px; text-align: right; }
.co-kembali.kurang { color: var(--danger); }
.qris-img { width: 100%; max-width: 280px; display: block; margin: 0 auto; border-radius: 12px; }
.qris-placeholder { padding: 40px; text-align: center; color: var(--muted); border: 2px dashed var(--border); border-radius: 12px; white-space: pre-line; }
.hint { font-size: 12px; color: var(--muted); }

/* Receipt options */
.receipt-opts { min-width: 300px; }
.ro-success { color: var(--success); font-weight: 700; text-align: center; font-size: 18px; margin-bottom: 12px; }
.rcpt-preview { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-size: 12px; max-height: 240px; overflow: auto; white-space: pre; font-family: 'Courier New', monospace; }
.ro-actions { display: flex; gap: 8px; margin: 12px 0; }
.ro-actions .btn { flex: 1; }
.ro-wa { display: flex; gap: 8px; }
.ro-wa .inp { flex: 1; }

/* ===== Toast ===== */
#toast-wrap { position: fixed; bottom: calc(16px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1e293b; color: #fff; padding: 11px 18px; border-radius: 24px; font-size: 14px; font-weight: 500; box-shadow: 0 6px 24px rgba(0,0,0,.3); opacity: 0; transform: translateY(12px); transition: .25s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warn { background: var(--warn); }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; transition: .2s; padding: 16px; }
.modal-overlay.show { opacity: 1; }
.modal-box { background: var(--surface); border-radius: 18px; width: 100%; max-width: 440px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); transform: scale(.96); transition: .2s; }
.modal-overlay.show .modal-box { transform: scale(1); }
.modal-box.wide { max-width: 620px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-x { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.modal-foot .btn-block { flex: 1; }

/* ===== Admin ===== */
.admin { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.adm-topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); }
.adm-tabs { display: flex; gap: 6px; padding: 10px 14px; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--border); }
.adm-tab { white-space: nowrap; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; font-size: 14px; cursor: pointer; }
.adm-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.adm-content { flex: 1; overflow-y: auto; padding: 16px; }
.adm-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.adm-bar .inp { flex: 1; min-width: 180px; }

.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; padding: 11px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); text-transform: uppercase; }
.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.data-table tr:last-child td { border-bottom: 0; }

.chip-list { display: flex; flex-direction: column; gap: 8px; }
.kat-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }

.import-box { max-width: 640px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.import-result { margin-top: 14px; }
.ok-box { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--success-d); padding: 12px; border-radius: 10px; margin-bottom: 12px; }

.settings-form { max-width: 520px; }
.qris-preview { max-width: 200px; margin-top: 10px; border-radius: 12px; display: block; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-val { font-size: 22px; font-weight: 800; color: var(--primary); }
.stat-lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h4 { margin: 0 0 10px; }
.card .row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.report-out .row:last-child { border-bottom: 0; }

.hist-sum { display: flex; justify-content: space-between; padding: 10px 4px; font-size: 16px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.hist-list { display: flex; flex-direction: column; gap: 6px; }
.hist-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; background: var(--surface-2); border-radius: 10px; cursor: pointer; }
.hist-item:active { background: var(--border); }
.hist-meta { color: var(--muted); font-size: 13px; }

/* Update banner */
.update-banner { position: fixed; top: 0; left: 0; right: 0; background: var(--primary); color: #fff; padding: 10px 16px; text-align: center; font-size: 14px; z-index: 9998; display: flex; align-items: center; justify-content: center; gap: 12px; }
.update-banner button { background: #fff; color: var(--primary); border: 0; border-radius: 8px; padding: 6px 14px; font-weight: 700; cursor: pointer; }

/* ===== Responsive (mobile) ===== */
@media (max-width: 820px) {
  .cart-panel { position: fixed; inset: 0; z-index: 900; width: 100%; transform: translateX(100%); transition: transform .25s; }
  body.cart-open .cart-panel { transform: translateX(0); }
  .cart-fab { display: flex; position: fixed; right: 16px; bottom: calc(16px + var(--safe-b)); z-index: 800; width: 60px; height: 60px; border-radius: 50%; background: var(--primary); color: #fff; border: 0; font-size: 26px; box-shadow: 0 8px 24px rgba(79,70,229,.5); cursor: pointer; align-items: center; justify-content: center; }
  .cart-fab::before { content: '🛒'; }
  .pos-search { max-width: none; }
  .brand strong { display: none; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .user-chip span { display: none; }
}
