/* Hord Pantry v3 — tokens first, then layout, then components. */
:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --surface-3: #efeadf;
  --line: #e4ddcf;
  --text: #1f2421;
  --text-2: #5c625d;
  --text-3: #8a8f89;
  --brand: #2f5d45;
  --brand-ink: #ffffff;
  --brand-soft: #e3ede6;
  --accent: #b8862b;
  --good: #0aac23; --good-ink: #006c10; --good-soft: #e3f4e5;
  --warn: #fbb315; --warn-ink: #8a5a00; --warn-soft: #fdf1d6;
  --serious: #f18a59; --serious-ink: #9a3f12; --serious-soft: #fde6da;
  --crit: #dc3c3d; --crit-ink: #a3201f; --crit-soft: #fbe2e2;
  --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600; --s5: #ee7fac; --s6: #008a17; --s7: #6a4ce2; --s8: #ec4647;
  --seq: #257de0; --grid: #ece7dc;
  --shadow: 0 1px 2px rgba(31, 36, 33, .06), 0 4px 16px rgba(31, 36, 33, .06);
  --radius: 16px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: Fraunces, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141513; --surface: #1c1e1b; --surface-2: #222521; --surface-3: #2b2e2a; --line: #333731;
    --text: #eceee9; --text-2: #b3b8b1; --text-3: #8a9088;
    --brand: #7fbf98; --brand-ink: #0f1a13; --brand-soft: #22332a; --accent: #e0b25c;
    --good-ink: #6fd17e; --good-soft: #1d2f20; --warn-ink: #fbc34a; --warn-soft: #33290f;
    --serious-ink: #f5a47e; --serious-soft: #3a2419; --crit-ink: #f08283; --crit-soft: #3a1d1d;
    --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
    --seq: #338ced; --grid: #2c2f2b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141513; --surface: #1c1e1b; --surface-2: #222521; --surface-3: #2b2e2a; --line: #333731;
  --text: #eceee9; --text-2: #b3b8b1; --text-3: #8a9088;
  --brand: #7fbf98; --brand-ink: #0f1a13; --brand-soft: #22332a; --accent: #e0b25c;
  --good-ink: #6fd17e; --good-soft: #1d2f20; --warn-ink: #fbc34a; --warn-soft: #33290f;
  --serious-ink: #f5a47e; --serious-soft: #3a2419; --crit-ink: #f08283; --crit-soft: #3a1d1d;
  --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
  --seq: #338ced; --grid: #2c2f2b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font: 700 26px/1.15 var(--display); letter-spacing: -.01em; }
h2 { font: 650 19px/1.25 var(--display); }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--text-2); }
.tiny { font-size: 12.5px; color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }
.boot { display: grid; place-items: center; height: 80vh; color: var(--text-2); }

/* ---------- shell */
.shell { max-width: 1180px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  margin: 0 -16px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid transparent; }
.topbar.scrolled { border-bottom-color: var(--line); }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand img { width: 32px; height: 32px; }
.brand .t { font: 700 18px/1.1 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .s { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.pill .pl { display: inline; }
@media (max-width: 480px) { .pill .pl { display: none; } .pill { padding: 8px 10px; } }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 12.5px; font-weight: 550; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.crit { background: var(--crit); }
.iconbtn { width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; cursor: pointer; flex: none; }
.iconbtn svg { width: 18px; height: 18px; }

.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); display: flex; justify-content: center; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
.nav-inner { display: flex; gap: 2px; width: 100%; max-width: 640px; }
.nav button { flex: 1; border: 0; background: none; padding: 6px 2px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; font-weight: 600; color: var(--text-3); cursor: pointer; position: relative; }
.nav button svg { width: 22px; height: 22px; }
.nav button.on { color: var(--brand); background: var(--brand-soft); }
.nav .badge { position: absolute; top: 0; left: calc(50% + 6px); transform: scale(.9); transform-origin: left top; }
@media (min-width: 900px) {
  .nav { top: 0; bottom: 0; right: auto; width: 92px; flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--line); padding-top: 76px; }
  .nav-inner { flex-direction: column; gap: 6px; }
  .nav button { flex: none; padding: 10px 4px; }
  .shell { padding-left: 108px; padding-bottom: 48px; max-width: 1280px; }
  .topbar { margin-left: -108px; padding-left: 124px; }
}
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--crit); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.badge.soft { background: var(--surface-3); color: var(--text-2); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 18px 0 14px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); max-width: 62ch; }

/* ---------- cards & grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card.flat { box-shadow: none; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { flex: 1 1 auto; min-width: 12ch; }
.card-head .tiny { flex: 0 1 auto; }
.grid { display: grid; gap: 14px; }
.grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .grid.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.grid.widgets { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .grid.widgets { grid-template-columns: repeat(2, minmax(0, 1fr)); } .w-wide { grid-column: 1 / -1; } }
.kpi { padding: 14px 16px; }
.kpi .v { font: 700 28px/1.1 var(--display); font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12.5px; color: var(--text-2); font-weight: 550; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.chart { width: 100%; height: 260px; }
.chart.tall { height: 320px; }

/* ---------- controls */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 12px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; justify-content: center; min-height: 40px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; border-radius: 10px; }
.btn.danger { color: var(--crit-ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; min-height: 42px; }
.input:focus, .btn:focus-visible, .chip:focus-visible, .nav button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
textarea.input { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.spacer { flex: 1; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 13px; white-space: nowrap; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.chip .badge { background: var(--surface-3); color: var(--text-2); }
.chip.on .badge { background: color-mix(in srgb, var(--brand-ink) 25%, transparent); color: var(--brand-ink); }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stepper button { width: 38px; height: 38px; border: 0; background: none; font-size: 18px; cursor: pointer; }
.stepper input { width: 64px; text-align: center; border: 0; background: none; height: 38px; font-weight: 650; }

/* ---------- status tags (always icon + label) */
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 650; padding: 3px 8px; border-radius: 8px; white-space: nowrap; }
.tag svg { width: 13px; height: 13px; }
.tag.good { background: var(--good-soft); color: var(--good-ink); }
.tag.warn { background: var(--warn-soft); color: var(--warn-ink); }
.tag.serious { background: var(--serious-soft); color: var(--serious-ink); }
.tag.crit { background: var(--crit-soft); color: var(--crit-ink); }
.tag.info { background: var(--surface-3); color: var(--text-2); }
.tag.store { background: var(--surface-3); color: var(--text); }
.tag.store::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--store, var(--text-3)); }

/* ---------- product cards */
.products { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.product { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; padding: 12px; cursor: pointer; text-align: left; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); width: 100%; }
.product:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.thumb { width: 64px; height: 64px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; flex: none; }
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumb .ph { font: 700 20px var(--display); color: var(--text-3); }
.thumb.sm { width: 44px; height: 44px; border-radius: 10px; }
.thumb.lg { width: 96px; height: 96px; border-radius: 16px; }
.product .name { font-weight: 650; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.product .meta { font-size: 12.5px; color: var(--text-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product .foot { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.qty { font: 700 15px var(--font); font-variant-numeric: tabular-nums; }

/* ---------- lists */
.list { display: flex; flex-direction: column; }
.li { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.li:first-child { border-top: 0; }
.li .main { flex: 1; min-width: 0; }
.li.wrap { flex-wrap: wrap; }
.li.wrap > select { flex: 1 1 180px; max-width: none !important; }
@media (max-width: 560px) { .li.wrap > .main { flex-basis: calc(100% - 60px); } .li.wrap > select { flex-basis: 100%; } }
.li .title { font-weight: 650; }
.li .sub { font-size: 13px; color: var(--text-2); }
.clickable { cursor: pointer; }
.empty { padding: 28px 12px; text-align: center; color: var(--text-2); }

/* ---------- meters */
.meter { height: 10px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 6px; background: var(--seq); }
.meter.good > i { background: var(--good); }
.meter.over > i { background: var(--brand); }

/* ---------- shopping */
.shop-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.shop-row:first-child { border-top: 0; }
.shop-row .title { font-weight: 650; }
.shop-row .sub { font-size: 13px; color: var(--text-2); }
.shop-row .side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.store-head { display: flex; align-items: center; gap: 10px; }
.store-head .sw { width: 12px; height: 12px; border-radius: 4px; background: var(--store); }

/* ---------- bottom sheet / modal */
.scrim { position: fixed; inset: 0; background: rgba(10, 12, 10, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); animation: up .2s ease; }
@media (min-width: 760px) { .scrim { align-items: center; } .sheet { border-radius: 22px; max-height: 88vh; } }
.sheet-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.sheet-head .main { flex: 1; min-width: 0; }
.sheet section { margin-top: 14px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.kv > div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.kv .k { font-size: 12px; color: var(--text-3); font-weight: 550; }
.kv .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.loc-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.loc-row:first-child { border-top: 0; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- toast */
#toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; transition: all .2s ease; z-index: 70;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; max-width: calc(100vw - 32px); pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--crit); color: #fff; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 24px; }
.login img { width: 56px; height: 56px; margin-bottom: 14px; }

/* ---------- scan */
.scan-box { display: grid; gap: 12px; }
#reader { width: 100%; border-radius: 16px; overflow: hidden; background: #000; }
#reader video { border-radius: 16px; }
.tally .li { align-items: center; }
.pending { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- widgets customization */
.wedit { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.wedit:first-child { border-top: 0; }
.wedit label { flex: 1; display: flex; gap: 10px; align-items: center; font-weight: 600; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--text-3); font-weight: 600; font-size: 12px; border-top: 0; }
.table td.r, .table th.r { text-align: right; }
.scroll-x { overflow-x: auto; }
.callout { background: var(--brand-soft); border-radius: 14px; padding: 12px 14px; color: var(--text); }
.callout.warn { background: var(--warn-soft); }
details > summary { cursor: pointer; font-weight: 600; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
