:root {
  --bg: #0b1220;
  --bg-2: #0f1729;
  --panel: #131c30;
  --panel-2: #18233b;
  --line: #243149;
  --text: #e6edf6;
  --muted: #8aa0bd;
  --teal: #0f766e;
  --teal-2: #14b8a6;
  --green: #22c55e;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}
#app { height: 100%; }

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
  overflow-x: hidden;
}
.auth-app { justify-content: center; }

.auth-screen {
  min-height: 100%;
  display: flex; flex-direction: column; justify-content: center;
  padding: calc(24px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
}
.auth-brand {
  font-size: 30px; font-weight: 800; letter-spacing: 0; line-height: 1.08;
  margin: 0 0 4px;
}
.auth-brand::before { content: "▦ "; color: var(--teal-2); }
.auth-sub { color: var(--muted); margin-bottom: 18px; font-size: 14px; }
.auth-panel {
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); padding: 12px;
}
.auth-seg { grid-template-columns: repeat(4, 1fr); }
.auth-msg { margin-top: 10px; font-size: 13px; }
.auth-msg.ok { color: var(--green); }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { flex: 1; min-width: 0; font-weight: 700; letter-spacing: 0; font-size: 16px; line-height: 1.15; }
.brand::before { content: "▦ "; color: var(--teal-2); }
.who {
  flex: 0 0 auto; max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px;
}

/* content + screens */
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 12px; }
.screen { padding: 14px 14px 0; }
.screen-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.screen-head h2 { font-size: 18px; margin: 0; }
h2, h3, h4 { font-weight: 650; }
h4 { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .6px; margin: 18px 0 6px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.pad { padding: 16px; }
.err { color: var(--red); }

/* grid map */
.legend { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.grid { display: flex; flex-direction: column; gap: 7px; }
.grid-row { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 7px; }
.cell {
  position: relative; aspect-ratio: 1 / 1;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 11px; cursor: pointer; padding: 0; transition: transform .05s;
}
.cell:active { transform: scale(.95); }
.cell-code { opacity: .7; font-size: 10px; }
.cell-qty { font-size: 14px; font-weight: 700; color: var(--text); margin-top: 2px; }
.cell.empty { background: var(--bg-2); }
.cell.low { background: rgba(34,197,94,.16); border-color: rgba(34,197,94,.35); }
.cell.mid { background: rgba(20,184,166,.20); border-color: rgba(20,184,166,.45); }
.cell.high { background: rgba(20,184,166,.40); border-color: var(--teal-2); }
.cell.full { background: rgba(251,191,36,.22); border-color: rgba(251,191,36,.55); }
.cell-exp { position: absolute; top: 5px; right: 6px; color: var(--amber); font-size: 9px; }

/* expiry alerts */
.expiry-panel {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); padding: 10px; margin-top: 18px; margin-bottom: 10px;
}
.expiry-panel.calm { color: var(--muted); font-size: 13px; padding: 10px 12px; }
.expiry-title { color: var(--text); font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.expiry-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.expiry-count {
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 8px;
  font-size: 18px; font-weight: 750; line-height: 1;
}
.expiry-count small { display: block; color: var(--muted); font-size: 10px; font-weight: 650; margin-top: 4px; }
.expiry-count.expired { color: #fecaca; border-color: rgba(248,113,113,.55); }
.expiry-count.today { color: #fed7aa; border-color: rgba(251,146,60,.55); }
.expiry-count.soon { color: #fde68a; border-color: rgba(251,191,36,.45); }
.expiry-list { list-style: none; margin: 0; padding: 0; }
.expiry-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border-left: 3px solid var(--amber); padding: 8px 8px 8px 10px;
  background: rgba(255,255,255,.02); border-radius: 8px; margin-top: 6px; cursor: pointer;
}
.expiry-row.expired { border-left-color: var(--red); }
.expiry-row.today { border-left-color: #fb923c; }
.expiry-row.soon { border-left-color: var(--amber); }
.expiry-right { text-align: right; white-space: nowrap; }
.expiry-right b { display: block; font-size: 12px; color: var(--text); }
.expiry-right span { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* lists + rows */
.list { list-style: none; margin: 0; padding: 0; }
.list.small .row { padding: 8px 12px; font-size: 13px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); margin-bottom: 8px; cursor: pointer;
}
.row-title { font-weight: 600; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.qty { font-weight: 700; white-space: nowrap; }
.qty .unit { font-weight: 400; color: var(--muted); font-size: 12px; }
.qty.low { color: var(--amber); }
.exp-tag { color: var(--amber); font-weight: 500; font-size: 11px; }

/* search */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search {
  flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px;
}
.search:focus { outline: none; border-color: var(--teal-2); }
.search-status { margin: -2px 2px 10px; }
.scan-btn {
  border: 1px solid var(--teal-2); background: rgba(20,184,166,.15); color: var(--teal-2);
  border-radius: 12px; padding: 0 16px; font-weight: 650; font-size: 14px; cursor: pointer;
}

/* tab bar */
.tabbar {
  display: grid; grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line); background: var(--bg-2);
  padding-bottom: var(--safe-bottom);
}
.tab {
  background: none; border: none; color: var(--muted);
  padding: 11px 0 13px; font-size: 12px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab::before { font-size: 19px; line-height: 1; }
.tab[data-i="map"]::before { content: "▦"; }
.tab[data-i="find"]::before { content: "⌕"; }
.tab[data-i="move"]::before { content: "⇄"; }
.tab[data-i="ledger"]::before { content: "▤"; }
.tab[data-i="more"]::before { content: "≡"; }
.tab.active { color: var(--teal-2); }

/* buttons + inputs */
.btn {
  width: auto; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 12px; padding: 13px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn.full { width: 100%; display: block; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #f0fdfa; }
.btn.primary:active { background: var(--teal-2); }
.btn:disabled { opacity: .5; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-row.three { grid-template-columns: 1fr 1fr 1fr; }
.btn-row .btn { width: 100%; }
.input, select.input {
  width: 100%; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; margin-bottom: 10px;
}
.input:focus { outline: none; border-color: var(--teal-2); }
.field-label { font-size: 12px; color: var(--muted); margin: 4px 2px; }

/* segmented control */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; margin: 4px 0 12px; }
.seg button {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 10px; padding: 11px 0; font-weight: 650; font-size: 13px; cursor: pointer;
}
.seg button.on { background: var(--teal); border-color: var(--teal); color: #f0fdfa; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 10px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 6px 11px; font-size: 12px; cursor: pointer;
}
.chip.on { border-color: var(--teal-2); color: var(--teal-2); }
.chip.warn { border-color: rgba(251,191,36,.65); color: var(--amber); }
.chip:disabled { opacity: .45; cursor: default; }

/* scrim / sheet / modal */
.scrim {
  position: fixed; inset: 0; background: rgba(3,7,18,.6); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px);
}
.scrim.center { align-items: center; }
.sheet {
  width: 100%; max-width: 560px; background: var(--bg-2);
  border-top-left-radius: 20px; border-top-right-radius: 20px;
  border: 1px solid var(--line); padding: 8px 16px calc(20px + var(--safe-bottom));
  max-height: 80%; overflow-y: auto;
}
.sheet-handle { width: 38px; height: 4px; background: var(--line); border-radius: 4px; margin: 6px auto 12px; }
.sheet-title { margin: 0 0 12px; }
.modal {
  width: calc(100% - 36px); max-width: 420px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 18px; padding: 20px;
}
.modal-title { margin: 0 0 14px; }
.item-meta { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

/* scanner */
.scanbox {
  width: calc(100% - 36px); max-width: 440px; background: #000;
  border: 1px solid var(--line); border-radius: 18px; padding: 14px; position: relative;
}
.scan-video { width: 100%; border-radius: 12px; background: #000; display: block; aspect-ratio: 3/4; object-fit: cover; }
.scan-frame {
  position: absolute; left: 14%; right: 14%; top: 32%; height: 22%;
  border: 2px solid var(--teal-2); border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0,0,0,.18);
  pointer-events: none;
}
.scanbox .btn { margin-top: 12px; }
.scan-reader { width: 100%; border-radius: 12px; overflow: hidden; background: #000; min-height: 240px; }
.scan-reader video { width: 100% !important; border-radius: 12px; display: block; }
.scan-reader img { display: none; }  /* hide library's default camera icon */
.scan-hint { text-align: center; color: var(--muted); font-size: 13px; margin: 10px 0 2px; }

/* toasts */
.toast-host {
  position: fixed; left: 0; right: 0; bottom: calc(78px + var(--safe-bottom)); z-index: 40;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 90%;
}
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); color: #fecaca; }

.stat-row { display: flex; gap: 10px; margin-bottom: 12px; }
.stat { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .n { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.warn .n { color: var(--amber); }

/* scan-first move controls */
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.action-tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 4px; border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); border-radius: 14px; font-size: 12px; font-weight: 650; cursor: pointer;
}
.action-tile .action-ico { font-size: 22px; line-height: 1; }
.action-tile.on { background: var(--teal); border-color: var(--teal); color: #f0fdfa; }
.action-tile:disabled { opacity: .45; cursor: default; }
.role-note { margin: -8px 2px 12px; }

.bigscan {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 20px; margin-bottom: 10px; border-radius: 16px;
  border: 2px dashed var(--teal-2); background: rgba(20,184,166,.12); color: var(--teal-2);
  font-size: 17px; font-weight: 700; cursor: pointer;
}
.bigscan-ico { font-size: 26px; }

.picked {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px; border: 1px solid var(--teal); border-radius: 14px;
  background: rgba(15,118,110,.18); margin-bottom: 6px;
}

.loc-row { display: flex; gap: 8px; align-items: stretch; margin-bottom: 4px; }
.loc-row .input { flex: 1; }
.loc-row .scan-btn { padding: 0 16px; }

.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 8px; margin-bottom: 4px; }
.stepper button {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 12px; font-size: 26px; font-weight: 700; cursor: pointer;
  min-width: 0;
}
.stepper input {
  width: 100%; min-width: 0;
  text-align: center; font-size: 24px; font-weight: 700;
  background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 12px;
}
.stepper input:focus { outline: none; border-color: var(--teal-2); }

.count-info { color: var(--muted); font-size: 13px; margin: 6px 2px; }
.variance { font-size: 13px; font-weight: 650; margin: 8px 2px; }
.variance.pos { color: var(--teal-2); }
.variance.neg { color: var(--amber); }

.btn.big { padding: 18px; font-size: 17px; margin-top: 14px; }

/* reports */
.report-panel {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); padding: 12px; margin-bottom: 8px;
}
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.toggle-row small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--teal-2); }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.report-panel label span { display: block; color: var(--muted); font-size: 12px; margin: 0 2px 4px; }
.report-panel .input { margin-bottom: 8px; }

.user-row { align-items: flex-start; cursor: default; }
.user-row.inactive { opacity: .7; }
.user-actions {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px;
  max-width: 260px;
}
.role-select {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.role-select:disabled { opacity: .45; cursor: default; }
.status-pill {
  display: inline-block; margin-left: 6px; padding: 2px 6px;
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
}
.status-pill.off { color: var(--amber); border-color: rgba(251,191,36,.5); }
.auth-event { padding-top: 9px; padding-bottom: 9px; }

/* responsive tightening for the awkward tablet / laptop middle widths */
@media (min-width: 700px) {
  .app { max-width: 720px; }
  .screen { padding: 18px 18px 0; }
  .grid-row { gap: 8px; }
  .cell { font-size: 12px; }
  .cell-code { font-size: 11px; }
  .cell-qty { font-size: 15px; }
}

@media (max-width: 380px) {
  .actions { gap: 6px; }
  .action-tile { padding: 12px 2px; font-size: 11px; }
  .stepper { grid-template-columns: 56px 1fr 56px; }
  .search-bar { gap: 6px; }
  .scan-btn { padding: 0 12px; }
}

/* receipt */
.receipt { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 14px; }
.rcpt-row { display: flex; justify-content: space-between; gap: 14px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.rcpt-row:last-child { border-bottom: none; }
.rcpt-k { color: var(--muted); font-size: 13px; }
.rcpt-v { font-weight: 600; text-align: right; word-break: break-word; }

[38;5;231m/* FEFO dispatch guidance (Chain 6) ---------------------------------------- */[0m
[38;5;231m.fefo-chip { display: inline-flex; align-items: center; gap: 4px; }[0m
[38;5;231m.fefo-chip .fefo-star { color: var(--teal-2); font-size: 11px; }[0m
[38;5;231m.fefo-chip .chip-exp { font-size: 10px; opacity: .8; margin-left: 2px; }[0m
[38;5;231m.fefo-chip.rec { border-color: var(--teal-2); }[0m
[38;5;231m.fefo-chip.soon { border-color: rgba(251,191,36,.65); color: var(--amber); }[0m
[38;5;231m.fefo-chip.today { border-color: rgba(251,191,36,.85); color: var(--amber); }[0m
[38;5;231m.fefo-chip.expired { border-color: rgba(248,113,113,.8); color: var(--red); }[0m
[38;5;231m.fefo-chip.on { border-color: var(--teal-2); color: var(--teal-2); }[0m
[38;5;231m.fefo-warn {[0m
[38;5;231m  font-size: 12px; color: var(--amber); margin: 2px 2px 10px;[0m
[38;5;231m  border-left: 3px solid var(--amber); padding: 6px 8px 6px 10px;[0m
[38;5;231m  background: var(--panel); border-radius: 0 6px 6px 0;[0m
[38;5;231m}[0m
[38;5;231m.fefo-warn.expired { color: var(--red); border-left-color: var(--red); }[0m
[38;5;231m.pick-first {[0m
[38;5;231m  font-size: 10px; font-weight: 700; color: var(--teal-2);[0m
[38;5;231m  border: 1px solid var(--teal-2); border-radius: 999px; padding: 1px 6px; margin-right: 2px;[0m
[38;5;231m}[0m
[38;5;231m.exp-tag.expired { color: var(--red); }[0m
[38;5;231m.exp-tag.today { color: var(--amber); }[0m
