/* ==========================================================================
   Lumina AI — design system
   Colour tokens are the validated data-viz reference palette, so chart series
   and UI accents come from one coherent, CVD-checked set. Dark mode is a
   selected set of steps for the dark surface, not an inverted light theme.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Surfaces & ink */
  --surface:        #fcfcfb;
  --page:           #f9f9f7;
  --surface-sunk:   #f3f3f0;
  --ink:            #0b0b0b;
  --ink-2:          #52514e;
  --ink-muted:      #898781;
  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --hairline:       rgba(11, 11, 11, 0.10);
  --hairline-soft:  rgba(11, 11, 11, 0.06);

  /* Categorical series (fixed order — never cycled) */
  --series-1: #2a78d6;   /* blue   */
  --series-2: #eb6834;   /* orange */
  --series-3: #1baf7a;   /* aqua   */

  /* Sequential ramp (blue) */
  --seq-150: #b7d3f6;
  --seq-250: #86b6ef;
  --seq-350: #5598e7;
  --seq-450: #2a78d6;
  --seq-550: #1c5cab;

  /* Status — reserved, always shipped with an icon + label */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;

  /* Product accent (shares the series-1 hue) */
  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --accent-soft: #eaf2fd;
  --accent-ring: rgba(42, 120, 214, 0.28);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgba(11, 11, 11, 0.05), 0 1px 3px rgba(11, 11, 11, 0.04);
  --shadow-2: 0 4px 12px rgba(11, 11, 11, 0.07), 0 2px 4px rgba(11, 11, 11, 0.04);
  --shadow-3: 0 18px 44px rgba(11, 11, 11, 0.16);

  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Cascadia Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface:       #1a1a19;
    --page:          #0d0d0d;
    --surface-sunk:  #141413;
    --ink:           #ffffff;
    --ink-2:         #c3c2b7;
    --ink-muted:     #898781;
    --grid:          #2c2c2a;
    --baseline:      #383835;
    --hairline:      rgba(255, 255, 255, 0.10);
    --hairline-soft: rgba(255, 255, 255, 0.06);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;

    --seq-150: #184f95;
    --seq-250: #1c5cab;
    --seq-350: #256abf;
    --seq-450: #3987e5;
    --seq-550: #6da7ec;

    --good-text: #0ca30c;
    --accent:      #3987e5;
    --accent-ink:  #0b0b0b;
    --accent-soft: #16283d;
    --accent-ring: rgba(57, 135, 229, 0.34);
    --shadow-3: 0 18px 44px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface:       #1a1a19;
  --page:          #0d0d0d;
  --surface-sunk:  #141413;
  --ink:           #ffffff;
  --ink-2:         #c3c2b7;
  --ink-muted:     #898781;
  --grid:          #2c2c2a;
  --baseline:      #383835;
  --hairline:      rgba(255, 255, 255, 0.10);
  --hairline-soft: rgba(255, 255, 255, 0.06);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --seq-150: #184f95;
  --seq-250: #1c5cab;
  --seq-350: #256abf;
  --seq-450: #3987e5;
  --seq-550: #6da7ec;
  --good-text: #0ca30c;
  --accent:      #3987e5;
  --accent-ink:  #0b0b0b;
  --accent-soft: #16283d;
  --accent-ring: rgba(57, 135, 229, 0.34);
  --shadow-3: 0 18px 44px rgba(0, 0, 0, 0.55);
}

/* --------------------------------------------------------------- reset -- */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* The UA rule for [hidden] is display:none at zero specificity, so any class
   that sets display (.callout, .field, .grid …) silently defeats it. Without
   this, an empty error box shows on page load. */
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* -------------------------------------------------------------- layout -- */

/* dvh tracks the viewport as mobile browser chrome collapses; vh does not,
   which is what leaves a dead strip under the fold on iOS Safari. */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; align-self: flex-start;
  display: flex; flex-direction: column; gap: 26px;
  width: 232px; height: 100vh; height: 100dvh; padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 0; }
.brand__mark {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(145deg, var(--series-1), var(--series-3));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: var(--shadow-1);
}
.brand__name { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.brand__tag { font-size: 11px; color: var(--ink-muted); letter-spacing: 0.02em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__label {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-muted); padding: 0 10px 6px;
}
.nav__item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500; text-decoration: none;
}
.nav__item:hover { background: var(--surface-sunk); color: var(--ink); text-decoration: none; }
.nav__item[aria-current="page"] {
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.nav__item svg { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar__foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px; background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.topbar h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.015em; }
.topbar__sub { font-size: 12.5px; color: var(--ink-muted); }
.topbar__spacer { flex: 1; }

.content { padding: 24px 28px 64px; max-width: 1360px; width: 100%; }

.section { margin-bottom: 28px; }
.section__head {
  display: flex; align-items: baseline; gap: 12px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.section__head h2 { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.section__head p { font-size: 12.5px; color: var(--ink-muted); }

/* --------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.card__head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--hairline-soft);
}
.card__head h3 { font-size: 13.5px; font-weight: 650; }
.card__head p { font-size: 12px; color: var(--ink-muted); }
.card__body { padding: 18px; }
.card__foot {
  padding: 12px 18px; border-top: 1px solid var(--hairline-soft);
  display: flex; gap: 8px; align-items: center;
}

.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--hairline); background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .13s ease, border-color .13s ease, transform .06s ease;
}
.btn:hover { background: var(--surface-sunk); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.btn--primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.btn--primary:hover { background: var(--seq-550); border-color: var(--seq-550); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-sunk); color: var(--ink); }
.btn--danger { color: var(--critical); border-color: var(--hairline); }
.btn--danger:hover { background: color-mix(in srgb, var(--critical) 10%, transparent); }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--block { width: 100%; }

/* --------------------------------------------------------------- chips -- */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 550; line-height: 1.5;
  border: 1px solid var(--hairline); background: var(--surface-sunk); color: var(--ink-2);
  white-space: nowrap;
}
.chip__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.chip--accent { background: var(--accent-soft); border-color: var(--accent-ring); color: var(--accent); }
.chip--good     { color: var(--good-text);  border-color: color-mix(in srgb, var(--good) 40%, transparent); background: color-mix(in srgb, var(--good) 10%, transparent); }
.chip--warning  { color: var(--ink);        border-color: color-mix(in srgb, var(--warning) 55%, transparent); background: color-mix(in srgb, var(--warning) 16%, transparent); }
.chip--serious  { color: var(--ink);        border-color: color-mix(in srgb, var(--serious) 55%, transparent); background: color-mix(in srgb, var(--serious) 16%, transparent); }
.chip--critical { color: var(--critical);   border-color: color-mix(in srgb, var(--critical) 42%, transparent); background: color-mix(in srgb, var(--critical) 10%, transparent); }
.chip--allergen { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, transparent); background: color-mix(in srgb, var(--critical) 9%, transparent); }
.chip--trace    { color: var(--ink-2); border-style: dashed; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.retailer-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 550; }
.retailer-chip__swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }

/* ---------------------------------------------------------- stat tiles -- */

.stat {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius-lg); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow-1);
}
.stat__label {
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em;
  text-transform: uppercase; color: var(--ink-muted);
}
.stat__value { font-size: 30px; font-weight: 640; letter-spacing: -0.025em; line-height: 1.1; }
.stat__meta { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.stat--hero .stat__value { font-size: 48px; }

/* Meter — one ratio against a limit, same-ramp track */
.meter { display: flex; flex-direction: column; gap: 5px; }
.meter__top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.meter__name { font-size: 12.5px; color: var(--ink-2); }
.meter__value { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.meter__track { height: 8px; border-radius: 999px; background: var(--grid); overflow: hidden; }
.meter__fill { height: 100%; border-radius: 999px; background: var(--seq-450); }
.meter__fill[data-band="low"]  { background: var(--critical); }
.meter__fill[data-band="mid"]  { background: var(--serious); }
.meter__fill[data-band="high"] { background: var(--seq-450); }

/* -------------------------------------------------------------- charts -- */

.chart { width: 100%; }
.chart__rows { display: flex; flex-direction: column; gap: 11px; }
.chart-row { display: grid; grid-template-columns: 130px 1fr 52px; gap: 10px; align-items: center; }
.chart-row__name { font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-row__track { height: 14px; background: var(--surface-sunk); border-radius: 3px; overflow: hidden; }
.chart-row__bar {
  height: 100%; background: var(--seq-450);
  border-radius: 0 4px 4px 0;   /* rounded data-end, anchored to the baseline */
  min-width: 2px; transition: width .35s cubic-bezier(.2,.7,.3,1);
}
.chart-row__value { font-size: 12.5px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.chart-row:hover .chart-row__bar { filter: brightness(1.08); }

/* Part-to-whole: 2px surface gap between adjacent segments */
.stackbar { display: flex; height: 16px; border-radius: 4px; overflow: hidden; gap: 2px; background: var(--surface); }
.stackbar__seg { height: 100%; min-width: 3px; }
.stackbar__seg:first-child { border-radius: 4px 0 0 4px; }
.stackbar__seg:last-child { border-radius: 0 4px 4px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.legend__item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend__value { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

.chart-empty { font-size: 12.5px; color: var(--ink-muted); padding: 18px 0; text-align: center; }

/* ------------------------------------------------------------- capture -- */

.tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-sunk); border-radius: var(--radius);
  border: 1px solid var(--hairline-soft); width: fit-content; max-width: 100%;
  overflow-x: auto;
}
.tab {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: none; background: transparent; color: var(--ink-2);
  font-size: 13px; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-1); font-weight: 620;
}
.tab svg { width: 16px; height: 16px; }
.tab__badge {
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}

.tabpanel[hidden] { display: none; }

.dropzone {
  border: 1.5px dashed var(--baseline); border-radius: var(--radius-lg);
  background: var(--surface-sunk);
  padding: 40px 24px; text-align: center; cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.is-dragging { border-color: var(--accent); background: var(--accent-soft); border-style: solid; }
.dropzone__icon { width: 40px; height: 40px; margin: 0 auto 12px; color: var(--accent); }
.dropzone__title { font-size: 14.5px; font-weight: 600; margin-bottom: 4px; }
.dropzone__hint { font-size: 12.5px; color: var(--ink-muted); }

.queue { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.queue__item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--hairline);
  border-radius: var(--radius); background: var(--surface);
}
.queue__thumb {
  width: 42px; height: 42px; border-radius: var(--radius-sm); flex-shrink: 0;
  object-fit: cover; background: var(--surface-sunk);
  display: grid; place-items: center; color: var(--ink-muted);
}
.queue__body { flex: 1; min-width: 0; }
.queue__name {
  font-size: 13px; font-weight: 550; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.queue__meta { font-size: 11.5px; color: var(--ink-muted); }
.queue__bar { height: 3px; border-radius: 999px; background: var(--grid); margin-top: 6px; overflow: hidden; }
.queue__bar span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s ease; }

/* ---------------------------------------------------------- live scan -- */

.scanner {
  position: relative; border-radius: var(--radius-lg); overflow: hidden;
  background: #0b0b0b; aspect-ratio: 4 / 3; display: grid; place-items: center;
}
.scanner video, .scanner canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.scanner__overlay { position: absolute; inset: 0; pointer-events: none; }
.scanner__reticle {
  position: absolute; inset: 12% 10%; border-radius: 12px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .55), 0 0 0 9999px rgba(0, 0, 0, .32);
}
.scanner__hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(11, 11, 11, .74); color: #fff; padding: 6px 12px;
  border-radius: 999px; font-size: 12px; white-space: nowrap; backdrop-filter: blur(4px);
}
.scanner__idle { color: #c3c2b7; font-size: 13px; text-align: center; padding: 24px; z-index: 1; }
.scanner__measure { position: absolute; inset: 0; cursor: crosshair; }

.measure-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 12px; background: var(--surface-sunk);
  border: 1px solid var(--hairline); border-radius: var(--radius); margin-top: 12px;
}

/* ------------------------------------------------ live capture session -- */

.shot-tray {
  margin-top: 12px; padding: 12px;
  background: var(--surface-sunk); border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.shot-tray__head {
  display: flex; align-items: baseline; gap: 10px;
  flex-wrap: wrap; margin-bottom: 10px; font-size: 12.5px;
}
.shot-tray__strip {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
  -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}

.shot {
  position: relative; flex-shrink: 0; cursor: pointer;
  width: 74px; height: 74px; border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface);
  border: 2px solid transparent; box-shadow: var(--shadow-1);
}
.shot img { width: 100%; height: 100%; object-fit: cover; }
.shot:hover { border-color: var(--baseline); }
.shot.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

.shot__index {
  position: absolute; left: 4px; bottom: 4px;
  background: rgba(11, 11, 11, .74); color: #fff;
  font-size: 10.5px; font-weight: 700; line-height: 1;
  padding: 3px 6px; border-radius: 999px;
}
.shot__badge {
  position: absolute; left: 4px; top: 4px;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--good); color: #fff;
  display: grid; place-items: center;
}
.shot__badge svg { width: 11px; height: 11px; }
.shot__remove {
  position: absolute; right: 3px; top: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  border: none; cursor: pointer; line-height: 1; font-size: 14px;
  background: rgba(11, 11, 11, .72); color: #fff;
  display: grid; place-items: center; padding: 0;
}
.shot__remove:hover { background: var(--critical); }

/* Per-capture quality dot — assessed at the shutter, shown before extraction. */
.shot__quality {
  position: absolute; right: 4px; bottom: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .9);
}
.shot__quality[data-verdict="good"] { background: var(--good); }
.shot__quality[data-verdict="fair"] { background: var(--warning); }
.shot__quality[data-verdict="bad"]  { background: var(--critical); }

/* Live capture-quality badge over the viewfinder. */
.quality-badge {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  max-width: calc(100% - 28px);
  padding: 7px 13px; border-radius: 999px;
  background: rgba(11, 11, 11, .78); backdrop-filter: blur(6px);
  color: #fff; font-size: 12.5px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .2s ease;
}
.quality-badge__dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .18);
}
.quality-badge[data-verdict="good"] .quality-badge__dot { background: var(--good); }
.quality-badge[data-verdict="fair"] .quality-badge__dot { background: var(--warning); }
.quality-badge[data-verdict="bad"]  .quality-badge__dot { background: var(--critical); }
.quality-badge[data-verdict="good"] { background: rgba(12, 163, 12, .82); }
.quality-badge[data-verdict="bad"]  { background: rgba(208, 59, 59, .82); }

/* The reticle turns green once the frame is worth capturing. */
.scanner__reticle { transition: box-shadow .25s ease; }
.quality-badge[data-verdict="good"] ~ .scanner__reticle,
.scanner__overlay:has(.quality-badge[data-verdict="good"]) .scanner__reticle {
  box-shadow: 0 0 0 2px var(--good), 0 0 0 9999px rgba(0, 0, 0, .32);
}

#torch-btn.is-on { background: var(--warning); border-color: var(--warning); color: #0b0b0b; }

.derived-tag {
  font-size: 9.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 1px 4px; border-radius: 3px; vertical-align: middle;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-ring);
}

.frame-quality { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.frame-quality__item {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--hairline); color: var(--ink-2);
}
.frame-quality__item[data-weak="true"] {
  border-color: color-mix(in srgb, var(--critical) 45%, transparent);
  color: var(--critical);
}

.result-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.result-picker__item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px 6px 6px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--hairline); background: var(--surface);
  font-size: 12.5px; font-weight: 550; color: var(--ink);
  max-width: 100%; overflow: hidden;
}
.result-picker__item img {
  width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
}
.result-picker__item > span:nth-of-type(1) {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px;
}
.result-picker__item:hover { background: var(--surface-sunk); }
.result-picker__item.is-active { border-color: var(--accent); background: var(--accent-soft); }

@media (max-width: 640px) {
  .shot { width: 64px; height: 64px; }
  .shot__remove { width: 24px; height: 24px; }   /* fat-finger friendly */
  .result-picker__item > span:nth-of-type(1) { max-width: 130px; }
}
.measure-toolbar__step { font-size: 12.5px; color: var(--ink-2); flex: 1; min-width: 200px; }
.measure-readout {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px;
}
.measure-readout div {
  background: var(--surface-sunk); border: 1px solid var(--hairline-soft);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.measure-readout dt { font-size: 11px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .04em; }
.measure-readout dd { font-size: 15px; font-weight: 620; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- forms -- */

.field { display: flex; flex-direction: column; gap: 5px; }
.field__label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field__hint { font-size: 11.5px; color: var(--ink-muted); }

.input, .select, .textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-size: 13px;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--baseline); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
.textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
.select { appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23898781' stroke-width='1.6'><path d='M4 6.5 8 10.5 12 6.5'/></svg>");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 15px;
}

.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--hairline); border-radius: var(--radius-lg);
  margin-bottom: 16px; box-shadow: var(--shadow-1);
}
.filter-bar .field { min-width: 140px; }
.filter-bar .field--grow { flex: 1; min-width: 220px; }

.search-input { position: relative; }
.search-input svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--ink-muted); pointer-events: none;
}
.search-input .input { padding-left: 32px; }

/* -------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--hairline); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 900px; }
table.data th {
  text-align: left; font-size: 11px; font-weight: 650; letter-spacing: .05em;
  text-transform: uppercase; color: var(--ink-muted);
  padding: 11px 14px; border-bottom: 1px solid var(--hairline);
  background: var(--surface); position: sticky; top: 0; z-index: 1;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--hairline-soft); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-sunk); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

.cell-product { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.cell-product img, .cell-product .placeholder {
  width: 38px; height: 38px; border-radius: var(--radius-sm); object-fit: cover;
  background: var(--surface-sunk); flex-shrink: 0; display: grid; place-items: center;
  color: var(--ink-muted);
}
.cell-product__name { font-weight: 550; }
.cell-product__sub { font-size: 11.5px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- pagination -- */

.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.pager__info { font-size: 12.5px; color: var(--ink-muted); margin-right: auto; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- misc --- */

.empty {
  text-align: center; padding: 56px 24px; color: var(--ink-muted);
  border: 1px dashed var(--baseline); border-radius: var(--radius-lg); background: var(--surface);
}
.empty h3 { font-size: 15px; color: var(--ink); margin-bottom: 6px; font-weight: 620; }
.empty p { font-size: 13px; max-width: 460px; margin: 0 auto; }
.empty svg { width: 38px; height: 38px; margin: 0 auto 14px; color: var(--baseline); }

.callout {
  display: flex; gap: 10px; padding: 11px 14px; border-radius: var(--radius);
  border: 1px solid var(--hairline); background: var(--surface-sunk); font-size: 12.5px;
}
.callout svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.callout--warning { border-color: color-mix(in srgb, var(--warning) 50%, transparent); background: color-mix(in srgb, var(--warning) 12%, transparent); }
.callout--info { border-color: var(--accent-ring); background: var(--accent-soft); }
.callout--critical { border-color: color-mix(in srgb, var(--critical) 40%, transparent); background: color-mix(in srgb, var(--critical) 9%, transparent); }
.callout ul { margin: 4px 0 0; padding-left: 18px; }

.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--ink-muted); }
.kv dd { font-weight: 550; overflow-wrap: anywhere; }

.raw-text {
  font-family: var(--mono); font-size: 12px; line-height: 1.65;
  white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--surface-sunk); border: 1px solid var(--hairline-soft);
  border-radius: var(--radius); padding: 14px; max-height: 340px; overflow-y: auto;
}

.toast-stack {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 40px));
}
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--hairline);
  box-shadow: var(--shadow-2); font-size: 13px;
  animation: toast-in .22s cubic-bezier(.2,.8,.3,1);
}
.toast svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.toast--good svg { color: var(--good); }
.toast--critical svg { color: var(--critical); }
.toast--warning svg { color: var(--warning); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.tooltip {
  position: fixed; z-index: 200; pointer-events: none;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-2);
  padding: 7px 10px; font-size: 12px; white-space: nowrap;
}
.tooltip__value { font-weight: 650; font-variant-numeric: tabular-nums; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-sunk) 25%, var(--grid) 37%, var(--surface-sunk) 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.spinner {
  width: 15px; height: 15px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--hairline); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  background: rgba(11, 11, 11, .45); padding: 20px; backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3); width: min(520px, 100%);
  border: 1px solid var(--hairline); overflow: hidden;
}

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.nutrition-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 300px; }
.nutrition-table th, .nutrition-table td { padding: 8px 10px; border-bottom: 1px solid var(--hairline-soft); }
.nutrition-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); font-weight: 650; }
.nutrition-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.nutrition-table tbody tr:last-child td { border-bottom: none; }
.nutrition-table tr[data-indent="1"] td:first-child { padding-left: 26px; color: var(--ink-2); }

.badge-conf { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.badge-conf svg { width: 13px; height: 13px; }

/* ---------------------------------------------------------------- auth -- */

.auth-body {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(1000px 520px at 12% -10%, var(--accent-soft), transparent 62%),
    radial-gradient(760px 420px at 96% 108%, color-mix(in srgb, var(--series-3) 16%, transparent), transparent 60%),
    var(--page);
}

.auth-card {
  width: min(408px, 100%); padding: 32px;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
}
.auth-card__brand { display: flex; align-items: center; gap: 11px; margin-bottom: 26px; }
.auth-card__title { font-size: 21px; font-weight: 660; letter-spacing: -0.02em; margin-bottom: 5px; }
.auth-card__sub { font-size: 13px; color: var(--ink-muted); margin-bottom: 22px; }
.auth-card__foot {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--hairline-soft);
  font-size: 12px; color: var(--ink-muted); text-align: center;
}

.password-wrap { position: relative; display: block; }
.password-wrap .input { padding-right: 62px; }
.password-toggle {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; color: var(--accent);
  font-size: 12px; font-weight: 600; cursor: pointer;
  padding: 5px 8px; border-radius: var(--radius-sm);
}
.password-toggle:hover { background: var(--accent-soft); }

.user-card {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: var(--radius);
  border: 1px solid var(--hairline); background: var(--surface-sunk);
}
.user-card__avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 13px; font-weight: 650;
  background: var(--accent); color: var(--accent-ink);
}
.user-card__body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.user-card__name {
  font-size: 12.5px; font-weight: 600; color: var(--ink); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-card__name:hover { color: var(--accent); }
.user-card__role {
  font-size: 10.5px; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}

.select--inline { padding: 4px 26px 4px 8px; font-size: 12px; width: auto; min-width: 108px; }
.row-actions { white-space: nowrap; }
.row-actions .btn + .btn { margin-left: 4px; }
@media (max-width: 640px) {
  .row-actions { white-space: normal; display: flex; flex-wrap: wrap; gap: 6px; }
  .row-actions .btn { flex: 1 1 auto; margin-left: 0 !important; }
  .select--inline { width: 100%; font-size: 16px; padding: 9px 30px 9px 11px; }
}

/* ==========================================================================
   Responsive
   Two-column page layouts live here as classes, never as inline styles — an
   inline grid-template-columns outranks every media query below and is how a
   page silently stays two-up on a phone.
   ========================================================================== */

.split { display: grid; gap: 16px; align-items: start; }
.split--capture { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.split--rail    { grid-template-columns: minmax(0, 340px) minmax(0, 1fr); }
.split--aside   { grid-template-columns: minmax(0, 1fr) minmax(0, 380px); }

@media (max-width: 1080px) {
  .split--capture, .split--rail, .split--aside { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------------------------------------- tablet & below (900px) -- */

@media (max-width: 900px) {
  .shell { flex-direction: column; }

  .sidebar {
    position: sticky; top: 0; z-index: 30;
    flex-direction: row; align-items: center; flex-wrap: nowrap;
    width: 100%; height: auto; gap: 10px;
    padding: 8px max(12px, env(safe-area-inset-left)) 8px max(12px, env(safe-area-inset-right));
    border-right: none; border-bottom: 1px solid var(--hairline);
  }
  .brand { padding: 0; flex-shrink: 0; }
  .brand__tag, .brand__name { display: none; }
  .nav__label { display: none; }

  .nav {
    flex-direction: row; flex: 1; min-width: 0; gap: 2px;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav__item { padding: 8px 11px; white-space: nowrap; }

  /* The user card and sign-out must stay reachable — hiding the sidebar
     footer on mobile leaves no way to see who you are or to sign out. */
  .sidebar__foot {
    margin-top: 0; flex-direction: row; align-items: center;
    gap: 6px; flex-shrink: 0;
  }
  .sidebar__foot .callout { display: none; }          /* Vision badge: desktop only */
  .sidebar__foot [data-theme-toggle] span { display: none; }
  .user-card { padding: 4px; border: none; background: transparent; gap: 6px; }
  .user-card__body { display: none; }

  .topbar {
    flex-wrap: wrap; gap: 10px 12px;
    padding: 12px max(14px, env(safe-area-inset-left)) 12px max(14px, env(safe-area-inset-right));
  }
  .topbar__spacer { display: none; }
  .topbar > div:first-child { flex: 1 1 100%; }
  .topbar h1 { font-size: 16px; }

  .content {
    padding: 16px max(14px, env(safe-area-inset-left))
             max(48px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  }

  .chart-row { grid-template-columns: 92px 1fr 44px; }
  .grid--4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

/* ------------------------------------------------------ phones (640px) -- */

@media (max-width: 640px) {
  /* iOS zooms the whole page when a focused input is under 16px. Bump the
     form controls so tapping a field never rescales the layout. */
  .input, .select, .textarea { font-size: 16px; padding: 10px 12px; }
  .select { background-position: right 10px center; }

  /* Comfortable touch targets — 32px buttons are a miss-tap generator. */
  .btn { padding: 10px 14px; min-height: 42px; }
  .btn--sm { padding: 7px 11px; min-height: 36px; font-size: 12.5px; }
  .nav__item { min-height: 40px; }
  .password-toggle { min-height: 34px; padding: 6px 10px; }

  .stat { padding: 13px 14px; }
  .stat__value { font-size: 25px; }
  .stat--hero .stat__value { font-size: 36px; }
  .grid, .grid--2, .grid--3, .grid--4 { grid-template-columns: minmax(0, 1fr); }

  .section { margin-bottom: 22px; }
  .card__body, .card__head, .card__foot { padding-left: 14px; padding-right: 14px; }

  .filter-bar { padding: 12px; gap: 10px; }
  .filter-bar .field, .filter-bar .field--grow { min-width: 0; flex: 1 1 100%; }
  .filter-bar .btn { width: 100%; }

  .tabs { width: 100%; }
  .tab { flex: 1; justify-content: center; padding: 10px 8px; font-size: 12.5px; }
  .tab span.tab__badge { display: none; }

  .dropzone { padding: 26px 16px; }
  .dropzone__icon { width: 32px; height: 32px; }

  .measure-readout { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .measure-readout div { padding: 6px 8px; }
  .measure-readout dd { font-size: 13px; }
  .measure-toolbar { padding: 10px; }
  .measure-toolbar .btn { flex: 1 1 calc(50% - 4px); }
  .measure-toolbar__step { flex: 1 1 100%; min-width: 0; }

  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .kv dt { font-size: 11.5px; margin-top: 8px; }
  .kv dd { margin-bottom: 2px; }

  .modal { max-height: 88vh; overflow-y: auto; }
  .modal-backdrop { padding: 12px; align-items: flex-end; }
  .toast-stack { right: 10px; left: 10px; bottom: max(10px, env(safe-area-inset-bottom)); }

  .auth-card { padding: 24px 20px; box-shadow: var(--shadow-2); }

  .pager { flex-wrap: wrap; }
  .pager__info { flex: 1 1 100%; margin-bottom: 4px; text-align: center; }
  .pager .btn { flex: 1; }
}

/* ------------------------------------------- data tables become cards -- */

/* The catalogue table is 900px wide by design. Below that it would live
   permanently inside a horizontal scroller, which is readable in theory and
   miserable in practice — so each row becomes a self-labelling card instead.
   The breakpoint is 900px, not 640px: a portrait tablet has the same problem
   as a phone here. */
@media (max-width: 900px) {
  .table-wrap { border: none; background: transparent; overflow-x: visible; }
  table.data { min-width: 0; display: block; }
  table.data thead { display: none; }
  table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr {
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: var(--radius-lg); margin-bottom: 10px;
    padding: 12px 14px; box-shadow: var(--shadow-1);
  }
  table.data tbody tr:hover { background: var(--surface); }
  table.data td { border: none; padding: 4px 0; text-align: left !important; }
  table.data td[data-label]::before {
    content: attr(data-label);
    display: block; font-size: 10.5px; font-weight: 650;
    letter-spacing: 0.05em; text-transform: uppercase;
    color: var(--ink-muted); margin-bottom: 2px;
  }
  table.data td:first-child::before { display: none; }   /* the card's own title */
  table.data td:last-child { padding-top: 10px; }
  table.data td:last-child .btn { width: 100%; }
  table.data .num { text-align: left; }
}

/* --------------------------------------------------------- touch input -- */

/* The measuring overlay is a drag surface: a touch that starts on it must draw,
   never scroll. This is deliberately NOT inside a `hover: none` query — touch
   laptops and stylus Android devices report `hover: hover` and would still pan,
   and page-panning over this element is unwanted on every device anyway. */
.scanner__measure { touch-action: none; }
.scanner { touch-action: manipulation; }   /* also kills the double-tap zoom */

@media (hover: none) {
  .btn:active { transform: none; }
  .chart-row:hover .chart-row__bar { filter: none; }
}

* { -webkit-tap-highlight-color: rgba(42, 120, 214, 0.16); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important; scroll-behavior: auto !important;
  }
}

@media print {
  .sidebar, .topbar, .btn, .filter-bar { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; }
}
