/* ---------- Design tokens ---------- */
:root {
  --teal-50:#f0fdfa; --teal-100:#ccfbf1; --teal-500:#14b8a6; --teal-600:#0d9488; --teal-700:#0f766e; --teal-800:#115e59;
  --bg:#f4f6f8; --surface:#ffffff; --surface-2:#f9fafb; --border:#e5e8ec;
  --text:#131a22; --muted:#66727f; --primary:#0f766e; --primary-ink:#ffffff;
  --green:#16a34a; --red:#dc2626; --amber:#d97706; --blue:#2563eb;
  --shadow:0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --radius:14px; --radius-sm:10px;
  --nav-w:236px;
  font-synthesis:none;
}
:root[data-theme="dark"] {
  --bg:#0c1116; --surface:#131a22; --surface-2:#171f28; --border:#242f3b;
  --text:#e7edf3; --muted:#8a97a5; --primary:#2dd4bf; --primary-ink:#04201c;
  --shadow:0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0c1116; --surface:#131a22; --surface-2:#171f28; --border:#242f3b;
    --text:#e7edf3; --muted:#8a97a5; --primary:#2dd4bf; --primary-ink:#04201c;
    --shadow:0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
  }
}

* { box-sizing:border-box; }
/* The hidden attribute must always win over class display rules
   (.gate/.shell set display:grid, which otherwise overrides it). */
[hidden] { display:none !important; }
html,body { height:100%; }
body {
  margin:0; background:var(--bg); color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  font-size:14px; line-height:1.5; -webkit-font-smoothing:antialiased;
}
h1,h2,h3 { margin:0; font-weight:650; letter-spacing:-.01em; }
.muted { color:var(--muted); }
button { font-family:inherit; }
a { color:var(--primary); }

/* ---------- Gate ---------- */
.gate { position:fixed; inset:0; display:grid; place-items:center; background:linear-gradient(135deg,var(--teal-700),var(--teal-800)); padding:20px; z-index:50; }
.gate-card { background:var(--surface); border-radius:20px; padding:34px 30px; width:100%; max-width:340px; text-align:center; box-shadow:0 20px 60px rgba(0,0,0,.3); }
.gate-card h1 { font-size:26px; margin-top:14px; }
.gate-card p { margin:4px 0 20px; }
.gate-card input { width:100%; text-align:center; font-size:22px; letter-spacing:6px; padding:12px; margin-bottom:14px; border:1px solid var(--border); border-radius:var(--radius-sm); background:var(--surface-2); color:var(--text); }
.gate-card label { display:block; text-align:left; font-size:12px; color:var(--muted); margin-bottom:6px; }
.gate-msg { color:var(--red); font-size:13px; min-height:18px; margin:10px 0 0; }

.brand-mark { width:56px; height:56px; border-radius:16px; background:var(--teal-700); color:#fff; display:grid; place-items:center; font-weight:800; font-size:30px; margin:0 auto; box-shadow:var(--shadow); }
.brand-mark.sm { width:38px; height:38px; font-size:20px; border-radius:11px; margin:0; }
/* uploaded business logo replaces the letter tile */
.brand-mark.has-logo { background:#fff; padding:5px; }
.brand-mark.has-logo img { max-width:100%; max-height:100%; object-fit:contain; border-radius:8px; display:block; }

/* ---------- Shell ---------- */
.shell { display:grid; grid-template-columns:var(--nav-w) 1fr; height:100vh; }
.sidebar { background:var(--surface); border-right:1px solid var(--border); display:flex; flex-direction:column; padding:16px 12px; gap:6px; }
.sidebar-head { display:flex; align-items:center; gap:10px; padding:6px 8px 14px; }
.brand-text { display:flex; flex-direction:column; line-height:1.2; overflow:hidden; }
.brand-text strong { font-size:15px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.brand-text span { font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.nav { display:flex; flex-direction:column; gap:2px; flex:1; overflow-y:auto; }
.nav-item { display:flex; align-items:center; gap:11px; padding:9px 11px; border-radius:10px; color:var(--muted); cursor:pointer; border:none; background:none; text-align:left; font-size:13.5px; width:100%; font-weight:500; }
.nav-item:hover { background:var(--surface-2); color:var(--text); }
.nav-item.active { background:var(--teal-700); color:#fff; }
.nav-item .ico { width:20px; text-align:center; font-size:15px; }
.nav-sep { font-size:10.5px; text-transform:uppercase; letter-spacing:.08em; color:var(--muted); padding:12px 11px 4px; font-weight:700; }
.sidebar-foot { display:flex; gap:6px; padding-top:10px; border-top:1px solid var(--border); }

.main { display:flex; flex-direction:column; overflow:hidden; }
.topbar { display:flex; align-items:center; gap:12px; padding:14px 22px; border-bottom:1px solid var(--border); background:var(--surface); }
.topbar h2 { font-size:18px; flex:1; }
.topbar-actions { display:flex; gap:8px; flex-wrap:wrap; }
.menu-btn { display:none; font-size:18px; }
.view { padding:22px; overflow-y:auto; flex:1; }

/* ---------- Buttons ---------- */
.btn { border:1px solid var(--border); background:var(--surface); color:var(--text); padding:8px 14px; border-radius:10px; cursor:pointer; font-size:13.5px; font-weight:550; display:inline-flex; align-items:center; gap:7px; transition:.12s; white-space:nowrap; }
.btn:hover { border-color:var(--muted); }
.btn:active { transform:translateY(1px); }
.btn-primary { background:var(--primary); border-color:var(--primary); color:var(--primary-ink); }
.btn-primary:hover { filter:brightness(1.05); }
.btn-ghost { border-color:transparent; background:transparent; color:var(--muted); }
.btn-ghost:hover { background:var(--surface-2); color:var(--text); }
.btn-danger { color:var(--red); border-color:transparent; background:transparent; }
.btn-danger:hover { background:color-mix(in srgb, var(--red) 12%, transparent); }
.btn-sm { padding:6px 10px; font-size:12.5px; }
.btn-block { width:100%; justify-content:center; }
.btn:disabled { opacity:.5; cursor:not-allowed; }

/* ---------- Cards / grid ---------- */
.grid { display:grid; gap:16px; }
.cards { display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:14px; }
.card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:18px; box-shadow:var(--shadow); }
.card-h { display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
.card-h h3 { font-size:15px; }
.stat { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:16px 18px; box-shadow:var(--shadow); }
.stat .label { font-size:12px; color:var(--muted); font-weight:600; text-transform:uppercase; letter-spacing:.04em; }
.stat .value { font-size:26px; font-weight:700; margin-top:6px; letter-spacing:-.02em; }
.stat .delta { font-size:12.5px; margin-top:4px; }
.pos-plus { color:var(--green); } .neg { color:var(--red); } .pos { color:var(--green); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x:auto; border:1px solid var(--border); border-radius:var(--radius); background:var(--surface); }
table.tbl { width:100%; border-collapse:collapse; font-size:13px; min-width:520px; }
.tbl th { text-align:left; padding:11px 14px; color:var(--muted); font-weight:650; font-size:11.5px; text-transform:uppercase; letter-spacing:.04em; border-bottom:1px solid var(--border); background:var(--surface-2); position:sticky; top:0; }
.tbl td { padding:10px 14px; border-bottom:1px solid var(--border); }
.tbl tr:last-child td { border-bottom:none; }
.tbl tbody tr:hover { background:var(--surface-2); }
.tbl .num { text-align:right; font-variant-numeric:tabular-nums; }
.tbl .row-actions { text-align:right; white-space:nowrap; }
.empty { text-align:center; padding:40px 20px; color:var(--muted); }
.empty .big { font-size:34px; margin-bottom:8px; }

/* ---------- Forms ---------- */
.field { display:flex; flex-direction:column; gap:5px; margin-bottom:12px; }
.field label { font-size:12.5px; color:var(--muted); font-weight:600; }
.field input, .field select, .field textarea {
  padding:9px 11px; border:1px solid var(--border); border-radius:var(--radius-sm); background:var(--surface-2); color:var(--text); font-size:14px; font-family:inherit; width:100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline:2px solid color-mix(in srgb,var(--primary) 40%,transparent); border-color:var(--primary); }
.form-row { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.form-row-3 { display:grid; grid-template-columns:1fr 1fr 1fr; gap:12px; }

/* ---------- Modal ---------- */
.modal-back { position:fixed; inset:0; background:rgba(8,12,16,.5); display:grid; place-items:center; z-index:40; padding:16px; }
.modal { background:var(--surface); border-radius:var(--radius); box-shadow:0 20px 60px rgba(0,0,0,.3); width:100%; max-width:520px; max-height:90vh; overflow:auto; }
.modal-h { display:flex; align-items:center; justify-content:space-between; padding:16px 20px; border-bottom:1px solid var(--border); position:sticky; top:0; background:var(--surface); }
.modal-h h3 { font-size:16px; }
.modal-b { padding:20px; }
.modal-f { display:flex; gap:10px; justify-content:flex-end; padding:14px 20px; border-top:1px solid var(--border); position:sticky; bottom:0; background:var(--surface); }

/* ---------- Badges / pills ---------- */
.badge { display:inline-flex; align-items:center; gap:5px; font-size:11.5px; font-weight:650; padding:3px 9px; border-radius:999px; }
.badge.in { background:color-mix(in srgb,var(--green) 15%,transparent); color:var(--green); }
.badge.out { background:color-mix(in srgb,var(--red) 15%,transparent); color:var(--red); }
.badge.grey { background:var(--surface-2); color:var(--muted); }
.badge.amber { background:color-mix(in srgb,var(--amber) 16%,transparent); color:var(--amber); }
.badge.blue { background:color-mix(in srgb,var(--blue) 15%,transparent); color:var(--blue); }

/* ---------- Toast ---------- */
.toast { position:fixed; bottom:22px; left:50%; transform:translateX(-50%); background:var(--text); color:var(--bg); padding:11px 18px; border-radius:10px; font-size:13.5px; font-weight:550; z-index:60; box-shadow:0 8px 30px rgba(0,0,0,.3); }

/* ---------- POS ---------- */
.pos-wrap { display:grid; grid-template-columns:1fr 360px; gap:16px; height:calc(100vh - 120px); }
.pos-catalog { overflow-y:auto; padding-right:4px; }
.pos-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(130px,1fr)); gap:11px; }
.prod-tile { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-sm); padding:13px; cursor:pointer; text-align:left; transition:.1s; box-shadow:var(--shadow); }
.prod-tile:hover { border-color:var(--primary); transform:translateY(-2px); }
.prod-tile:active { transform:translateY(0); }
.prod-tile .pt-name { font-weight:600; font-size:13px; line-height:1.3; margin-bottom:8px; min-height:34px; }
.prod-tile .pt-price { font-weight:700; color:var(--primary); }
.prod-tile .pt-stock { font-size:11px; color:var(--muted); margin-top:3px; }
.prod-tile.oos { opacity:.5; }
.cart { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); display:flex; flex-direction:column; box-shadow:var(--shadow); overflow:hidden; }
.cart-h { padding:14px 16px; border-bottom:1px solid var(--border); font-weight:650; display:flex; justify-content:space-between; align-items:center; }
.cart-items { flex:1; overflow-y:auto; padding:6px; }
.cart-line { display:flex; align-items:center; gap:8px; padding:8px; border-radius:8px; }
.cart-line:hover { background:var(--surface-2); }
.cart-line .cl-name { flex:1; font-size:13px; }
.cart-line .cl-name small { display:block; color:var(--muted); }
.qty { display:flex; align-items:center; gap:6px; }
.qty button { width:26px; height:26px; border-radius:7px; border:1px solid var(--border); background:var(--surface); cursor:pointer; font-size:15px; line-height:1; color:var(--text); }
.qty span { min-width:20px; text-align:center; font-variant-numeric:tabular-nums; }
.cart-foot { border-top:1px solid var(--border); padding:14px 16px; }
.cart-total-row { display:flex; justify-content:space-between; margin-bottom:6px; font-size:13.5px; }
.cart-total-row.grand { font-size:19px; font-weight:750; margin:8px 0 12px; }
.pay-methods { display:grid; grid-template-columns:repeat(3,1fr); gap:6px; margin-bottom:10px; }
.pay-methods button { padding:8px; border:1px solid var(--border); border-radius:8px; background:var(--surface); cursor:pointer; font-size:12px; color:var(--text); }
.pay-methods button.sel { background:var(--primary); color:var(--primary-ink); border-color:var(--primary); }

/* receipt */
.receipt { font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:12.5px; }
.receipt .r-line { display:flex; justify-content:space-between; }
.receipt hr { border:none; border-top:1px dashed var(--border); margin:8px 0; }

/* chart */
.bars { display:flex; align-items:flex-end; gap:10px; height:150px; padding-top:10px; }
.bar-col { flex:1; display:flex; flex-direction:column; align-items:center; gap:6px; height:100%; justify-content:flex-end; }
.bar { width:100%; max-width:38px; border-radius:6px 6px 0 0; background:var(--primary); min-height:2px; transition:.3s; }
.bar.neg-bar { background:var(--red); }
.bar-label { font-size:11px; color:var(--muted); }

.two-col { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.sec-title { font-size:12px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); font-weight:700; margin:2px 0 10px; }
.report-line { display:flex; justify-content:space-between; padding:7px 0; border-bottom:1px solid var(--border); }
.report-line.total { font-weight:750; border-bottom:2px solid var(--text); border-top:1px solid var(--border); margin-top:4px; }
.report-line .lbl.indent { padding-left:16px; color:var(--muted); }
.pill-row { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:16px; }

/* ---------- Responsive ---------- */
@media (max-width:900px) {
  .pos-wrap { grid-template-columns:1fr; height:auto; }
  .two-col { grid-template-columns:1fr; }
  .form-row, .form-row-3 { grid-template-columns:1fr; }
}
@media (max-width:760px) {
  .shell { grid-template-columns:1fr; }
  .sidebar { position:fixed; inset:0 auto 0 0; width:var(--nav-w); z-index:30; transform:translateX(-100%); transition:.2s; box-shadow:var(--shadow); }
  .sidebar.open { transform:translateX(0); }
  .menu-btn { display:inline-flex; }
  .sidebar-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.4); z-index:29; }
}
@media print {
  .sidebar,.topbar { display:none !important; }
  .shell { grid-template-columns:1fr; }
  .view { padding:0; overflow:visible; }
  body { background:#fff; }
}
