/* ────────────────────────────────────────────────────────────────────
   Mobile scanner page — touch-first, dark theme by default so the
   camera viewfinder reads cleanly under bright store lighting and the
   page stays readable in low-light back-of-shop scanning sessions.
   Tap targets stay >=48px so a gloved/sweaty thumb never misfires.
   Brand colors flow from CSS variables so a white-label deploy only
   needs to swap the values on :root.
   ──────────────────────────────────────────────────────────────────── */
:root {
  --brand-accent: #19d2e6;
  --brand-accent-strong: #00b6cc;
  --brand-ink: #0a1726;
  --bg: #0a1421;
  --bg-elev: #131f33;
  --bg-elev-2: #1b2942;
  --text: #f0f4fa;
  --text-dim: #9fb1c8;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);
  --danger: #ef4444;
  --success: #22c55e;
  --warn: #fbbf24;
  --shadow-card: 0 6px 18px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}
body.scan-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: calc(var(--safe-top) + 4px) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.hidden { display: none !important; }

/* ─── Top bar ─────────────────────────────────────────────────────── */
.scan-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand-link {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  min-height: var(--tap);
}
.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--brand-ink);
  object-fit: contain;
}
.brand-name {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 15px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
}
.user-label { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  border-radius: 8px;
}
.icon-btn:active { background: var(--bg-elev-2); }

/* ─── Mode tabs ───────────────────────────────────────────────────── */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg);
}
.mode-tabs-5 { grid-template-columns: repeat(5, 1fr); }
/* 6th mode (Inventory) — admin/management only; layout collapses to
   3 columns on narrow phones so each tab keeps enough tap area. */
.mode-tabs-6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 480px) {
  .mode-tabs-6 { grid-template-columns: repeat(3, 1fr); }
}
/* When inventory mode is hidden (non-privileged role) the grid still
   has 5 cells — pull the 6-col rule back to 5 so spacing stays even. */
.mode-tabs-6:has(.mode-tab-inv.hidden) { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 480px) {
  .mode-tabs-6:has(.mode-tab-inv.hidden) { grid-template-columns: repeat(3, 1fr); }
}
/* 7th mode (List) — scan a batch into a list, then print a price sheet of just
   those. Inventory may still be hidden for non-privileged roles, so the visible
   count is 7 (or 6 when inventory is hidden). On narrow phones the grid wraps. */
.mode-tabs-7 { grid-template-columns: repeat(7, 1fr); }
.mode-tabs-7:has(.mode-tab-inv.hidden) { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 480px) {
  .mode-tabs-7 { grid-template-columns: repeat(4, 1fr); }
}

/* ── Build List panel (List mode only) ──────────────────────────────── */
body:not([data-mode="list"]) #listPanel { display: none; }
body[data-mode="list"] #resultCard { display: none !important; }
body[data-mode="list"] .recent-section { display: none; }
.list-panel { margin: 10px 12px 24px; }
.list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.list-title { font-size: 15px; margin: 0; color: var(--text); }
.list-count { display: inline-block; min-width: 22px; text-align: center; background: var(--brand-accent); color: var(--brand-ink); border-radius: 11px; padding: 1px 7px; font-size: 13px; font-weight: 700; margin-left: 6px; }
.list-clear { padding: 6px 12px; font-size: 13px; }
.list-items { list-style: none; margin: 0 0 12px; padding: 0; }
.list-empty { color: var(--text-dim); text-align: center; padding: 18px; }
.list-items li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 6px; background: var(--bg-elev); }
.li-main { flex: 1; min-width: 0; }
.li-name { font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-pid { font-size: 11px; color: var(--text-dim); }
.li-qty-btn, .li-rm { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--bg-elev-2); color: var(--text); font-size: 18px; line-height: 1; }
.li-rm { color: var(--danger); font-size: 16px; }
.li-qty { min-width: 22px; text-align: center; font-size: 14px; color: var(--text); }
.list-unknown { margin-bottom: 12px; }
.list-unknown-title { font-size: 12px; color: var(--warn); margin-bottom: 4px; }
.list-unknown-items { list-style: none; margin: 0; padding: 0; }
.list-unknown-items li { font-size: 12px; color: var(--text-dim); padding: 4px 6px; border: 1px dashed var(--line-strong); border-radius: 8px; margin-bottom: 4px; }
.list-print { width: 100%; margin-top: 4px; }
.list-print:disabled { opacity: 0.5; }
.mode-tab-inv .mode-icon { filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.55)); }
.mode-tab-ai .mode-icon { filter: drop-shadow(0 0 6px rgba(25, 210, 230, 0.6)); }
.mode-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  padding: 8px 4px;
  background: var(--bg-elev);
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.mode-tab .mode-icon { font-size: 22px; line-height: 1; }
.mode-tab[aria-selected="true"] {
  background: var(--bg-elev-2);
  border-color: var(--brand-accent);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--brand-accent);
}

/* ─── Main scan area ──────────────────────────────────────────────── */
.scan-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  padding-bottom: calc(var(--safe-bottom) + 16px);
}
.scan-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-scan {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 80px;
  background: linear-gradient(135deg, var(--brand-accent), var(--brand-accent-strong));
  color: var(--brand-ink);
  border: none;
  border-radius: var(--radius);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  -webkit-tap-highlight-color: transparent;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn-scan:active { transform: scale(0.985); filter: brightness(0.95); }
.btn-scan-icon { display: inline-flex; }

.manual-row {
  display: flex;
  gap: 8px;
}
.manual-input {
  flex: 1;
  min-height: var(--tap);
  padding: 10px 14px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 16px; /* >=16px stops iOS auto-zoom on focus */
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  letter-spacing: 0.04em;
}
.manual-input:focus {
  outline: 2px solid var(--brand-accent);
  outline-offset: 1px;
  border-color: transparent;
}
.btn-primary,
.btn-secondary {
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--brand-accent);
  color: var(--brand-ink);
  border-color: var(--brand-accent-strong);
}
.btn-primary:active { filter: brightness(0.93); }
.btn-secondary {
  background: var(--bg-elev-2);
  color: var(--text);
  border-color: var(--line-strong);
}
.btn-secondary:active { background: var(--bg-elev); }

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

/* ─── Status bar ──────────────────────────────────────────────────── */
.status-bar {
  min-height: 22px;
  font-size: 13px;
  color: var(--text-dim);
  padding: 0 2px;
}
.status-bar.error { color: #fca5a5; }
.status-bar.success { color: #86efac; }

/* ─── Result card ─────────────────────────────────────────────────── */
.result-card {
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.result-card.kind-product { border-left: 4px solid var(--brand-accent); }
.result-card.kind-slab    { border-left: 4px solid #fbbf24; }
.result-card.kind-unknown { border-left: 4px solid var(--danger); }
.result-card.kind-multi   { border-left: 4px solid var(--warn); }

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.result-kind {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.result-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: var(--text-dim);
}
.result-name {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  word-break: break-word;
}
.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.result-meta strong { color: var(--text); font-weight: 600; }
.price-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.price-tile {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.price-tile .label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.price-tile .value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.price-tile.empty .value { color: var(--text-dim); font-weight: 500; }

/* Price-mode mega tiles: when current mode is "price", make tiles HUGE
   so the operator can read across the table at arm's length. */
body[data-mode="price"] .price-grid {
  grid-template-columns: 1fr;
}
body[data-mode="price"] .price-tile .value {
  font-size: 32px;
}

.stock-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.stock-now {
  font-size: 14px;
  color: var(--text-dim);
}
.stock-now strong { color: var(--text); font-size: 17px; font-weight: 700; }
.qty-input {
  width: 80px;
  min-height: var(--tap);
  padding: 4px 8px;
  font-size: 18px;
  text-align: center;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}
.btn-stack {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-stack > button {
  flex: 1 1 auto;
  min-width: 110px;
}

.multi-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.multi-list li {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  min-height: var(--tap);
}
.multi-list li:active { background: var(--bg-elev); }

/* ─── Recent scans ────────────────────────────────────────────────── */
.recent-section { margin-top: 4px; }
.recent-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 4px 2px 6px;
}
.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.recent-list li {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  min-height: 44px;
}
.recent-list li.recent-empty { color: var(--text-dim); cursor: default; justify-content: center; }
.recent-list .recent-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-dim);
  font-size: 11px;
}
.recent-list .recent-name { color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Camera viewfinder ───────────────────────────────────────────── */
.camera-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#cameraVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-viewfinder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.camera-viewfinder::before {
  content: "";
  width: min(78vw, 78vh, 360px);
  aspect-ratio: 1.4 / 1;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
}
.vf-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 4px solid var(--brand-accent);
  border-radius: 4px;
}
.vf-corner.vf-tl { top: calc(50% - min(39vw, 39vh, 180px) / 1.4); left: calc(50% - min(39vw, 39vh, 180px)); border-right: none; border-bottom: none; }
.vf-corner.vf-tr { top: calc(50% - min(39vw, 39vh, 180px) / 1.4); right: calc(50% - min(39vw, 39vh, 180px)); border-left: none; border-bottom: none; }
.vf-corner.vf-bl { bottom: calc(50% - min(39vw, 39vh, 180px) / 1.4); left: calc(50% - min(39vw, 39vh, 180px)); border-right: none; border-top: none; }
.vf-corner.vf-br { bottom: calc(50% - min(39vw, 39vh, 180px) / 1.4); right: calc(50% - min(39vw, 39vh, 180px)); border-left: none; border-top: none; }
.vf-laser {
  position: absolute;
  left: calc(50% - min(35vw, 35vh, 160px));
  right: calc(50% - min(35vw, 35vh, 160px));
  height: 2px;
  background: var(--brand-accent);
  box-shadow: 0 0 12px var(--brand-accent);
  animation: laser 1.6s ease-in-out infinite alternate;
}
@keyframes laser {
  0%   { transform: translateY(-90px); opacity: 0.95; }
  100% { transform: translateY(90px); opacity: 0.95; }
}

.camera-controls {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  z-index: 2;
}
.btn-icon-lg {
  min-width: 52px;
  min-height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon-lg:active { background: rgba(255, 255, 255, 0.15); }
/* Capture button — only shown in AI card mode. Big round bottom-center
   shutter, ring inside ring, scales on press. */
.btn-capture {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 32px);
  transform: translateX(-50%);
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  -webkit-tap-highlight-color: transparent;
}
.btn-capture-ring {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.08s ease, background 0.12s ease;
}
.btn-capture:active .btn-capture-ring { transform: scale(0.86); background: var(--brand-accent); }
.btn-capture:disabled { opacity: 0.55; pointer-events: none; }
.btn-capture.busy .btn-capture-ring {
  background: var(--brand-accent);
  animation: capturePulse 0.9s ease-in-out infinite;
}
@keyframes capturePulse {
  0%, 100% { transform: scale(0.85); }
  50% { transform: scale(1); }
}

/* Card-mode viewfinder uses a vertical aspect ratio (cards are tall).
   We dim the rest of the screen and box the card-sized region with
   brand-accent corners. */
.camera-overlay.mode-card .camera-viewfinder::before {
  width: min(72vw, 50vh, 320px);
  aspect-ratio: 0.71 / 1;
  border-radius: 10px;
}
.camera-overlay.mode-card .vf-corner.vf-tl { top: calc(50% - min(36vw, 25vh, 160px)); left: calc(50% - min(26vw, 18vh, 114px)); }
.camera-overlay.mode-card .vf-corner.vf-tr { top: calc(50% - min(36vw, 25vh, 160px)); right: calc(50% - min(26vw, 18vh, 114px)); }
.camera-overlay.mode-card .vf-corner.vf-bl { bottom: calc(50% - min(36vw, 25vh, 160px)); left: calc(50% - min(26vw, 18vh, 114px)); }
.camera-overlay.mode-card .vf-corner.vf-br { bottom: calc(50% - min(36vw, 25vh, 160px)); right: calc(50% - min(26vw, 18vh, 114px)); }
.camera-overlay.mode-card .vf-laser { display: none; }

.camera-hint {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 28px);
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  padding: 0 16px;
}
.camera-hint.error { color: #fca5a5; }
.camera-overlay.mode-card .camera-hint {
  bottom: calc(var(--safe-bottom) + 130px);
}
.kind-card { border-left: 4px solid var(--brand-accent); }
.kind-card .result-meta strong { color: var(--text); }
.card-resolved-image {
  display: block;
  margin: 6px auto 0;
  max-width: 60%;
  max-height: 320px;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.id-low {
  color: var(--warn);
  font-size: 12px;
  margin-top: 4px;
}

/* ─── Product image block ───────────────────────────────────────── */
/* Shown for every product/slab scan. Sized down to ~200px on
   non-inventory modes (keeps the result card compact for quick
   look-ups) and blown up to ~46vh on inventory mode so the operator
   can confirm the right product at a glance while holding the phone.
   Falls back to a name-only card when no image is available. */
.result-image-wrap {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-height: 140px;
  max-height: 200px;
}
.result-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.result-image-fallback {
  display: none;
  padding: 18px;
  text-align: center;
  font-weight: 700;
  color: var(--text);
  font-size: 14px;
}
.result-image-fallback small { color: var(--text-dim); font-weight: 400; font-size: 11px; display: block; margin-top: 4px; }
.result-image-wrap.img-failed .result-image { display: none; }
.result-image-wrap.img-failed .result-image-fallback { display: block; }

/* Inventory mode is FAST-TRACK ONLY. Three things on screen:
   product photo, product name, the qty input + save. Everything else
   (price tiles, slab meta, kind/id chip, "open in dashboard" links,
   "scan another" button, recent scans list) is hidden so the
   operator's eyes go straight to the three things that matter while
   walking the shop floor with a Bluetooth scanner.
   Reported: "show 3 things the item name and qty that i can update
   so they need too be large to only see those things". */
body[data-mode="inventory"] .result-image-wrap {
  min-height: 240px;
  max-height: 48vh;
  background: #fff;
}
body[data-mode="inventory"] .result-name {
  font-size: 28px;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  letter-spacing: -0.005em;
  padding: 0 8px;
}
/* The result card itself stretches to fill the viewport in inventory
   mode so there's no awkward white space below the qty input — the
   focus is on the three blocks, not on the chrome around them. */
body[data-mode="inventory"] .result-card {
  padding: 12px;
  gap: 12px;
}
/* Hide everything that isn't the image / name / qty controls. */
body[data-mode="inventory"] .result-head,
body[data-mode="inventory"] .result-meta,
body[data-mode="inventory"] .price-grid,
body[data-mode="inventory"] .recent-section,
body[data-mode="inventory"] .result-card .btn-stack {
  display: none !important;
}
/* Compact the scan trigger above the result so screen real estate
   goes to the picture + name + qty. We still want it tappable since
   the operator's flow is scan→edit→scan→edit, but it doesn't need
   to be the visual centerpiece. */
body[data-mode="inventory"] .btn-scan {
  min-height: 52px;
  font-size: 15px;
}
body[data-mode="inventory"] .btn-scan-icon svg { width: 22px; height: 22px; }
body[data-mode="inventory"] .scan-actions { gap: 6px; }
body[data-mode="inventory"] .manual-input { min-height: 44px; font-size: 14px; }
body[data-mode="inventory"] .scan-main { gap: 8px; padding: 8px; }
body[data-mode="inventory"] .status-bar { min-height: 16px; font-size: 12px; }

/* ─── Inventory mode: huge "Set total stock to: ____" tile ──────── */
.inv-set-row {
  margin-top: 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.inv-set-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.inv-set-current {
  font-size: 13px;
  color: var(--text-dim);
}
.inv-set-current strong { color: var(--text); font-size: 17px; }
.inv-set-current.zero strong { color: #fca5a5; }
.inv-set-input {
  font-size: 76px;
  font-weight: 900;
  text-align: center;
  background: var(--bg);
  color: var(--text);
  border: 3px solid var(--brand-accent);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-variant-numeric: tabular-nums;
  width: 100%;
  -moz-appearance: textfield;
  line-height: 1;
}
.inv-set-input::-webkit-outer-spin-button,
.inv-set-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.inv-set-input:focus {
  outline: 2px solid var(--brand-accent-strong);
  outline-offset: 1px;
}
.inv-set-save {
  width: 100%;
  min-height: 72px;
  font-size: 22px;
  font-weight: 900;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  letter-spacing: 0.02em;
}
.inv-set-save:active { filter: brightness(0.92); }
.inv-set-save:disabled { opacity: 0.5; cursor: not-allowed; }

/* Current-stock readout — shown above the input so the operator
   confirms "what's in here right now" before they type the new total.
   Big number, dim label. Turns red when 0 to flag empties. */
.inv-current-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.inv-current-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.inv-current-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.inv-current-line.zero .inv-current-value { color: #fca5a5; }
.inv-help { font-size: 12px; color: var(--text-dim); }

/* Input flanked by −/+ buttons. Big tap targets for thumbs; clamps
   the input to a centered text field so the number stays huge. */
.inv-input-wrap {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  gap: 8px;
  align-items: stretch;
}
.inv-adjust {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 40px;
  font-weight: 900;
  cursor: pointer;
  min-height: 112px;
  line-height: 1;
}
.inv-adjust:active { background: var(--bg); transform: scale(0.97); }
.inv-input-wrap .inv-set-input { min-height: 112px; }
.inv-input-wrap { grid-template-columns: 78px 1fr 78px; }

/* Quick-add row: +1 / +5 / +10 / +25 / 0 buttons under the input. */
.inv-quick-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.inv-quick {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  min-height: 52px;
}
.inv-quick:active { background: var(--bg); }
.inv-quick.inv-quick-zero {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.4);
}
.inv-quick.inv-quick-zero:active { background: rgba(239, 68, 68, 0.22); }
.inv-unlink-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  padding: 14px;
  background: var(--bg-elev-2);
  border-left: 4px solid var(--warn);
  border-radius: var(--radius);
}
.inv-unlink-row .inv-set-label { color: var(--warn); }
.inv-unlink-row .btn-primary { background: var(--warn); color: var(--bg); border-color: var(--warn); }

/* ─── Login overlay ───────────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 22px 20px;
  box-shadow: var(--shadow-card);
}
.login-logo {
  width: 64px;
  height: 64px;
  align-self: center;
  border-radius: 14px;
  background: var(--brand-ink);
  object-fit: contain;
}
.login-title {
  text-align: center;
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
}
.login-sub {
  text-align: center;
  color: var(--text-dim);
  margin: 0 0 6px;
  font-size: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field > span {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.field input,
.field select {
  min-height: var(--tap);
  padding: 10px 12px;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 16px;
}
.field input:focus,
.field select:focus {
  outline: 2px solid var(--brand-accent);
  outline-offset: 1px;
  border-color: transparent;
}
.field-row {
  display: flex;
  gap: 8px;
}
.field-row .field { flex: 1; }
.field.field-narrow { flex: 0 1 90px; }

.login-error {
  min-height: 18px;
  font-size: 13px;
  color: #fca5a5;
  text-align: center;
}
.auto-status {
  min-height: 18px;
  font-size: 12px;
  color: var(--text-dim);
}
.auto-status.ok { color: #86efac; }
.auto-status.err { color: #fca5a5; }

/* ─── Slab modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(5, 10, 18, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 17px; }
.slab-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px calc(16px + var(--safe-bottom));
  overflow-y: auto;
}

/* ─── Larger screens: cap content width so the layout doesn't sprawl
   when used on tablets / desktop. Otherwise the same mobile UI works. */
@media (min-width: 720px) {
  .scan-topbar, .mode-tabs, .scan-main { max-width: 720px; width: 100%; margin: 0 auto; }
  .modal-overlay { align-items: center; padding: 24px; }
  .modal-card { border-radius: var(--radius); }
}

/* Camera-enable banner. Only shown when the page loaded over HTTP on a
   non-localhost origin (i.e., the cellphone). Big tap target, accent
   color so operators don't miss it. Tap = go to the HTTPS variant of
   the same page, accept self-signed cert once, camera APIs unlock. */
.camera-enable-banner {
  display: block;
  margin: 12px 16px;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.18), rgba(34, 197, 94, 0.12));
  border: 1.5px solid rgba(74, 222, 128, 0.55);
  border-radius: 10px;
  color: #bbf7d0;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.4;
  text-align: center;
}
.camera-enable-banner:hover {
  filter: brightness(1.1);
}
