:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --muted: #646b78;
  --border: #dde1e7;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #d6f1ee;
  --danger: #c2271d;
  --danger-soft: #fde4e1;
  --warn: #a15c00;
  --warn-soft: #fff0d6;
  --ok: #157a3a;
  --ok-soft: #dcf5e4;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #181b21; --surface-2: #22262e; --text: #eceef2; --muted: #9aa1ad;
    --border: #2c313a; --brand: #2bb3a3; --brand-ink: #04201d; --brand-soft: #123a36;
    --danger: #ff6b5e; --danger-soft: #3a1714; --warn: #ffb547; --warn-soft: #3a2a0f;
    --ok: #4ed27e; --ok-soft: #12321e; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #181b21; --surface-2: #22262e; --text: #eceef2; --muted: #9aa1ad;
  --border: #2c313a; --brand: #2bb3a3; --brand-ink: #04201d; --brand-soft: #123a36;
  --danger: #ff6b5e; --danger-soft: #3a1714; --warn: #ffb547; --warn-soft: #3a2a0f;
  --ok: #4ed27e; --ok-soft: #12321e; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
body.no-tabs { padding-bottom: 24px; }
a { color: var(--brand); text-decoration: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* ---- top bar & tab bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px; background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { flex: 1; font-size: 18px; margin: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: inherit; padding: 8px; border-radius: 10px; display: inline-flex; cursor: pointer; }
.icon-btn:active { background: rgba(255,255,255,.18); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; color: var(--muted); font-size: 11px; }
.tabbar a.active { color: var(--brand); font-weight: 600; }
.badge { position: absolute; top: 3px; left: calc(50% + 6px); background: var(--danger); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; display: grid; place-items: center; }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px; }

/* ---- cards & lists */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; text-align: left; cursor: pointer; color: var(--text); font: inherit; }
.stat b { display: block; font-size: 22px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.crit b { color: var(--danger); }
.stat.on { outline: 2px solid var(--brand); }
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.row:last-child { border-bottom: 0; }
a.row:active, button.row:active { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; display: grid; place-items: center; color: var(--muted); }
.qty { text-align: right; flex: none; }
.qty b { font-size: 20px; display: block; line-height: 1.1; }
.qty span { font-size: 11px; color: var(--muted); }
.qty.crit b { color: var(--danger); }
.qty.zero b { color: var(--danger); text-decoration: line-through; }

.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.pill.crit { background: var(--danger-soft); color: var(--danger); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); flex: none; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 6px 12px; border-radius: 99px; font: inherit; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* ---- forms */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.search { margin-bottom: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.btn svg { width: 18px; height: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.actions .btn { flex: 1; }

.stepper { display: flex; align-items: stretch; gap: 8px; }
.stepper button { width: 56px; font-size: 24px; }
.stepper input { text-align: center; font-size: 22px; font-weight: 700; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font: inherit; color: var(--muted); font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 15; width: 56px; height: 56px; border-radius: 18px;
  background: var(--brand); color: var(--brand-ink); border: 0; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.fab svg { width: 28px; height: 28px; }

/* ---- photos */
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-pick { border: 1.5px dashed var(--border); border-radius: 12px; padding: 8px; background: var(--surface); }
.photo-pick.req { border-color: var(--warn); }
.photo-pick.has { border-style: solid; border-color: var(--brand); }
.photo-pick .lbl { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.photo-pick .prev { aspect-ratio: 4/3; border-radius: 8px; background: var(--surface-2) center/cover no-repeat; margin-bottom: 6px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.photo-pick .btns { display: flex; gap: 6px; }
.photo-pick .btns .btn { flex: 1; min-height: 36px; padding: 6px; font-size: 12px; }
.hero { width: 100%; max-height: 300px; object-fit: cover; border-radius: var(--radius); background: var(--surface-2); display: block; }
.adj-photos { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.adj-photos img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; cursor: zoom-in; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.big-stock { font-size: 40px; font-weight: 800; line-height: 1; }
.big-stock.crit { color: var(--danger); }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress i { display: block; height: 100%; background: var(--brand); }
.count-in { width: 84px; text-align: center; font-weight: 700; min-height: 40px; padding: 6px; }
.row.mismatch { background: var(--warn-soft); }
.row.matched .title::after { content: " ✓"; color: var(--ok); }

.banner { border-radius: 12px; padding: 12px; margin-bottom: 12px; background: var(--brand-soft); color: var(--text); display: flex; gap: 10px; align-items: center; }
.banner.crit { background: var(--danger-soft); }
.banner .grow { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }

/* ---- login */
.login { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login .logo { width: 72px; height: 72px; border-radius: 20px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 16px 0; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--brand); border-color: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 300px; margin: 0 auto; }
.keypad button { height: 58px; font-size: 22px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; }
.keypad button:active { background: var(--surface-2); }
.who { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 16px; }
.who button { padding: 14px 8px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; }

/* ---- toast & modal */
#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s; z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: calc(100% - 32px); font-size: 14px; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); color: #fff; }
#modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden] { display: none; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet h3 { font-size: 17px; margin-bottom: 14px; }
.viewer { background: #000; align-items: center !important; }
.viewer img { max-width: 100%; max-height: 100vh; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 10px; }
.section-title h2 { margin: 0; }

/* ---- reports */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.kpi span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi b { display: block; font-size: 22px; line-height: 1.2; margin: 2px 0; }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi.hero { grid-column: 1 / -1; }
.kpi.hero b { font-size: 32px; }
.hbars { display: grid; gap: 12px; }
.hbar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.hbar-top span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 8px; background: var(--surface-2); border-radius: 4px; margin-top: 4px; }
.hbar-track i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.cols { display: flex; align-items: flex-end; gap: 2px; height: 120px; border-bottom: 1px solid var(--border); }
.col { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.col i { display: block; width: 100%; background: var(--brand); border-radius: 4px 4px 0 0; }
.col:hover i { opacity: .75; }
.cols-axis { display: flex; justify-content: space-between; margin-top: 6px; }
.col { max-width: 36px; }
