:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-2: #115e59;
  --brand-soft: #ccfbf1;
  --good: #15803d;
  --good-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --panel: #111a2c; --panel-2: #0f172a; --text: #e2e8f0; --muted: #94a3b8;
    --line: #1e293b; --brand: #14b8a6; --brand-2: #0d9488; --brand-soft: #134e4a;
    --good: #4ade80; --good-soft: #14532d; --bad: #f87171; --bad-soft: #450a0a;
    --warn: #fbbf24; --warn-soft: #451a03; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --panel: #111a2c; --panel-2: #0f172a; --text: #e2e8f0; --muted: #94a3b8;
  --line: #1e293b; --brand: #14b8a6; --brand-2: #0d9488; --brand-soft: #134e4a;
  --good: #4ade80; --good-soft: #14532d; --bad: #f87171; --bad-soft: #450a0a;
  --warn: #fbbf24; --warn-soft: #451a03; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
h2 { margin: 0 0 12px; font-size: 20px; }
h3 { margin: 16px 0 8px; font-size: 16px; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 15px; }
label.check input { width: auto; }
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 600;
  background: var(--brand); color: #fff; display: inline-flex; gap: 6px; align-items: center; justify-content: center;
}
.btn:hover { background: var(--brand-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { background: var(--bad); }
.btn.warn { background: #d97706; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.big { padding: 16px; font-size: 18px; width: 100%; }
.pill {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 10px;
  font-size: 12px; white-space: nowrap; cursor: default;
}
button.pill { cursor: pointer; }
.pill.on { color: var(--good); }
.pill.off { color: var(--bad); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag.low { background: var(--warn-soft); color: var(--warn); }
.tag.out { background: var(--bad-soft); color: var(--bad); }
.tag.ok { background: var(--good-soft); color: var(--good); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.row > .btn, .row > .auto { flex: 0 0 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 12px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav button {
  border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted);
  font-weight: 600; white-space: nowrap; display: flex; gap: 6px; align-items: center;
}
.nav button.active { background: var(--brand-soft); color: var(--brand); }
.nav .ico { display: inline-flex; }
.icon { flex: 0 0 auto; vertical-align: -3px; }
.btn-ico { display: inline-flex; }
.btn-ico:empty { display: none; }
/* WhatsApp-green buttons */
.btn.wa { background: #1fa855; color: #fff; text-decoration: none; }
.btn.wa:hover { background: #178a45; }
a.btn { text-decoration: none; }
.support { display: flex; flex-direction: column; gap: 10px; }
.support-head { display: flex; gap: 12px; align-items: center; }
.support-head img { border-radius: 12px; }
.support-row { display: flex; gap: 8px; flex-wrap: wrap; }
.support-row .btn { flex: 1 1 140px; }
.login-help { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.login-help a { color: var(--brand); font-weight: 600; text-decoration: none; display: inline-flex; gap: 4px; align-items: center; }
.settings-tabs { position: sticky; top: 64px; z-index: 5; background: var(--bg); padding: 6px 0; }
details > p { margin: 4px 0 10px 16px; }
.quick-btn { white-space: nowrap; }
.top-right { display: flex; align-items: center; gap: 8px; }
main { padding: 16px; max-width: 1500px; margin: 0 auto; }

/* Laptop widths: not enough room for name + menu + status in one line, so the menu gets its own row */
@media (min-width: 861px) and (max-width: 1500px) {
  .topbar { flex-wrap: wrap; row-gap: 4px; }
  .top-right { margin-left: auto; }
  .nav { order: 3; flex: 1 1 100%; flex-wrap: wrap; overflow: visible; }
  .cart { top: 118px; max-height: calc(100vh - 136px); }
}

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
  .brand span { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
  .top-right { margin-left: auto; }
  #userName { display: none; }
  .hide-sm { display: none; }
  .quick-btn span { display: none; }
  .settings-tabs { top: 0; overflow-x: auto; flex-wrap: nowrap; }
  .settings-tabs .btn { white-space: nowrap; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--panel);
    border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); justify-content: space-around;
  }
  .nav button { flex-direction: column; gap: 0; font-size: 11px; padding: 6px 8px; }
  .nav .ico { font-size: 20px; }
  main { padding: 12px 12px 90px; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand), var(--brand-2)); }
.login .card { width: 100%; max-width: 360px; text-align: center; }
.login img { width: 64px; height: 64px; border-radius: 16px; }
.pin-dots { font-size: 28px; letter-spacing: 10px; height: 40px; margin: 8px 0; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.keypad button { padding: 16px; font-size: 22px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; }
.keypad button:active { background: var(--brand-soft); }

/* ---------- sell screen ---------- */
.sell { display: grid; grid-template-columns: minmax(0, 1fr) clamp(320px, 32vw, 420px); gap: 16px; align-items: start; }
.scanbar { display: flex; gap: 8px; }
.scanbar input { font-size: 18px; padding: 14px; min-width: 0; flex: 1; }
.cats { display: flex; gap: 6px; overflow-x: auto; margin: 12px 0; padding-bottom: 4px; }
.cats button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 14px; cursor: pointer; white-space: nowrap; }
.cats button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer;
  text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 92px;
}
.tile:hover { border-color: var(--brand); }
.tile .name { font-weight: 600; line-height: 1.2; }
.tile .price { font-weight: 700; color: var(--brand); margin-top: auto; }
.tile.out { opacity: .55; }
.results { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; max-height: 300px; overflow: auto; }
.results button { display: flex; width: 100%; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; text-align: left; }
.results button:hover { background: var(--panel-2); }

.cart { position: sticky; top: 70px; display: flex; flex-direction: column; max-height: calc(100vh - 90px); }
.cart-lines { overflow: auto; flex: 1; min-height: 120px; margin: 8px -16px; padding: 0 16px; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.cart-line .nm { font-weight: 600; }
.cart-line .meta { font-size: 12px; color: var(--muted); }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-size: 16px; }
.qty input { width: 56px; text-align: center; padding: 4px; }
.totals { border-top: 1px solid var(--line); padding-top: 8px; }
.totals .line { display: flex; justify-content: space-between; padding: 2px 0; }
.totals .grand { font-size: 26px; font-weight: 800; }
.cart-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

@media (max-width: 1000px) {
  .sell { grid-template-columns: minmax(0, 1fr); }
  .cart { position: static; max-height: none; }
}

/* ---------- payment ---------- */
.methods { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.methods button {
  padding: 12px 8px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel-2); cursor: pointer; font-weight: 600;
}
.methods button.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.due-box { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.due-box div { background: var(--panel-2); border-radius: 10px; padding: 10px; text-align: center; }
.due-box b { display: block; font-size: 22px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pay-list { margin: 10px 0; }
.pay-list .p { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.change { font-size: 28px; font-weight: 800; text-align: center; padding: 12px; border-radius: 12px; background: var(--good-soft); color: var(--good); }

/* ---------- tables, kpis ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; flex: 1; min-width: 160px; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--panel-2); position: sticky; top: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
tr.loss td { background: var(--bad-soft); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 22px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.hero { border-width: 2px; }
.kpi.hero.good { border-color: var(--good); background: var(--good-soft); }
.kpi.hero.bad { border-color: var(--bad); background: var(--bad-soft); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding: 8px 0; overflow-x: auto; }
.bar { flex: 1; min-width: 14px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bar i { display: block; width: 100%; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar i.neg { background: var(--bad); }
.bar small { font-size: 10px; color: var(--muted); margin-top: 4px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }

/* ---------- modal & toast ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 100; display: grid; place-items: center; padding: 16px;
  animation: fade .12s ease;
}
.modal {
  background: var(--panel); border-radius: 16px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px);
  overflow: auto; box-shadow: 0 20px 60px rgb(0 0 0 / .3);
}
.modal.wide { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }
.x { border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; top: 70px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); animation: fade .15s ease; max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good); color: #fff; }
.toast.warn { background: #d97706; color: #fff; }

.receipt-preview {
  font-family: "Courier New", ui-monospace, monospace; font-size: 12px; background: #fff; color: #000;
  padding: 12px; border-radius: 8px; border: 1px solid var(--line); margin: 0 auto; white-space: pre-wrap;
}
.receipt-preview.w58 { width: 32ch; box-sizing: content-box; }
.receipt-preview.w80 { width: 48ch; box-sizing: content-box; }
video.scanner { width: 100%; border-radius: 12px; background: #000; max-height: 60vh; }

/* ---------- subscription banner, details, labels ---------- */
.lic-banner { padding: 10px 16px; font-weight: 600; text-align: center; }
.lic-banner.warn { background: var(--warn-soft); color: var(--warn); }
.lic-banner.bad { background: var(--bad-soft); color: var(--bad); }
details > summary { cursor: pointer; padding: 6px 0; }
.label { background: #fff; color: #000; border: 1px dashed #bbb; border-radius: 6px; padding: 6px; text-align: center; font-family: system-ui, sans-serif; }
.label-shop { font-size: 9px; color: #444; }
.label-name { font-size: 13px; font-weight: 700; line-height: 1.15; }
.label-price { font-size: 15px; font-weight: 800; margin: 2px 0; }
.label-bar svg { display: block; max-height: 60px; }

/* ---------- printing ---------- */
#printArea { display: none; }
@media print {
  @page { margin: 0; }
  body.printing > *:not(#printArea) { display: none !important; }
  body.printing { background: #fff; }
  body.printing #printArea { display: block; }
  .receipt-paper { font-family: "Courier New", monospace; color: #000; white-space: pre-wrap; padding: 2mm 0; }
  .receipt-paper.w58 { width: 48mm; font-size: 9px; }
  .receipt-paper.w80 { width: 72mm; font-size: 9px; }
  /* A4 sticker sheet: 3 columns × 8 rows (common 63.5 × 33.9 mm labels) */
  body.printing #printArea.label-sheet { display: grid; grid-template-columns: repeat(3, 63.5mm); grid-auto-rows: 33.9mm; gap: 0 2.5mm; padding: 13mm 7mm; }
  .label-sheet .label { border: 0; overflow: hidden; padding: 2mm; break-inside: avoid; }
}
