/* =========================================================================
   Floss Inventory — styles
   Mobile-first. Light and dark themes are both driven by custom properties;
   floss swatches use their literal hex value in either theme so the colour a
   user sees never shifts with the UI theme.
   ========================================================================= */

/* ---------- tokens ---------- */

:root {
  color-scheme: light dark;

  --bg: #f6f5f2;
  --bg-elevated: #ffffff;
  --bg-sunken: #eeece7;
  --bg-chip: #ffffff;
  --text: #1c1b19;
  --text-muted: #6b675f;
  --text-inverse: #ffffff;
  --border: #e0ddd6;
  --border-strong: #c9c5bb;
  --accent: #3f6f52;
  --accent-strong: #2f5540;
  --accent-soft: #e6efe8;
  --danger: #a32b26;
  --danger-soft: #fbeae9;
  --warn: #8a5a12;
  --warn-soft: #fbf1de;
  --success: #2f6b46;
  --success-soft: #e4f1e8;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(28, 27, 25, 0.06), 0 4px 14px rgba(28, 27, 25, 0.05);

  --tap: 44px;
  --gutter: 16px;
  --tabbar-height: 62px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --bg-elevated: #1d2026;
    --bg-sunken: #101216;
    --bg-chip: #23272e;
    --text: #ececea;
    --text-muted: #a2a49f;
    --text-inverse: #14161a;
    --border: #2c3037;
    --border-strong: #414751;
    --accent: #7fb894;
    --accent-strong: #a2cfb2;
    --accent-soft: #1e2b23;
    --danger: #f28b85;
    --danger-soft: #33201f;
    --warn: #e0b46a;
    --warn-soft: #2e2617;
    --success: #7fc79b;
    --success-soft: #1a2a20;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 6px 18px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --bg-elevated: #1d2026;
  --bg-sunken: #101216;
  --bg-chip: #23272e;
  --text: #ececea;
  --text-muted: #a2a49f;
  --text-inverse: #14161a;
  --border: #2c3037;
  --border-strong: #414751;
  --accent: #7fb894;
  --accent-strong: #a2cfb2;
  --accent-soft: #1e2b23;
  --danger: #f28b85;
  --danger-soft: #33201f;
  --warn: #e0b46a;
  --warn-soft: #2e2617;
  --success: #7fc79b;
  --success-soft: #1a2a20;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 6px 18px rgba(0, 0, 0, 0.35);
}

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

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  /* Stops iOS rubber-banding the whole page behind the fixed tab bar. */
  overscroll-behavior-y: none;
}

body.is-modal-open { overflow: hidden; }

h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
img, video { max-width: 100%; display: block; }

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--bg-elevated);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius);
}
.skip-link:focus { left: 8px; top: 8px; }

/* ---------- app shell ---------- */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  padding: calc(env(safe-area-inset-top) + 12px) var(--gutter)
           calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 24px);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  outline: none;
}

.boot { padding: 40px 0; text-align: center; color: var(--text-muted); }
body.is-booting .tabbar { opacity: 0; pointer-events: none; }

/* ---------- bottom navigation ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: stretch;
  gap: 2px;
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  /* The inset keeps the tabs above the iPhone home indicator. */
  padding-bottom: env(safe-area-inset-bottom);
  transition: opacity 0.2s ease;
}

.tab {
  min-height: var(--tap);
  padding: 8px 2px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tab__icon { font-size: 20px; line-height: 1; }
.tab__label { font-size: 11px; font-weight: 500; letter-spacing: 0.01em; }
.tab--active { color: var(--accent-strong); }

/* The Scan tab is the primary action and reads as a button, not a label. */
.tab--primary {
  color: var(--text-inverse);
  position: relative;
}
.tab--primary::before {
  content: "";
  position: absolute;
  inset: 4px 6px;
  border-radius: var(--radius);
  background: var(--accent);
  z-index: -1;
}
.tab--primary .tab__icon { font-size: 22px; font-weight: 700; }
.tab--primary.tab--active { color: var(--text-inverse); }
.tab--primary.tab--active::before { background: var(--accent-strong); }

/* ---------- headings & metrics ---------- */

.screen__head { margin-bottom: 14px; }
.screen__head--tight { margin-bottom: 8px; }

.screen__title {
  font-size: 26px;
  line-height: 1.15;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.metrics--wide { grid-template-columns: repeat(2, 1fr); }

.metric {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}
.metric__value { font-size: 21px; font-weight: 650; letter-spacing: -0.02em; }
.metric__label { font-size: 12px; color: var(--text-muted); }

.progress-wrap { margin-bottom: 14px; }
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* ---------- tools: search, chips, controls ---------- */

.screen__tools { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  /* 16px minimum stops iOS Safari zooming the page on focus. */
  font-size: 16px;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  -webkit-appearance: none;
  appearance: none;
}
.input--textarea { min-height: 96px; resize: vertical; }
.input--number { text-align: center; font-size: 22px; font-weight: 600; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-chip);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip--active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 600;
}
.chip__count { font-size: 12px; opacity: 0.8; font-variant-numeric: tabular-nums; }

.controls { display: flex; gap: 10px; flex-wrap: wrap; }
.control { display: flex; align-items: center; gap: 6px; }
.control__label { font-size: 13px; color: var(--text-muted); }

.select {
  min-height: var(--tap);
  padding: 8px 30px 8px 12px;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  -webkit-appearance: none;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.result-count { font-size: 13px; color: var(--text-muted); }

/* ---------- swatches ---------- */

.swatch {
  display: block;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  /* An inner hairline keeps White/B5200 visible against a white card. */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
}
.swatch--sm { width: 22px; height: 22px; border-radius: 5px; }
.swatch--md { width: 34px; height: 34px; }
.swatch--lg { width: 52px; height: 52px; }
.swatch--block { width: 100%; height: 72px; border-radius: var(--radius); }

/* ---------- lists ---------- */

.list { display: flex; flex-direction: column; gap: 8px; }

.list--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
}

.card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.rowlink {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: 0;
  padding: 2px 0;
  text-align: left;
  cursor: pointer;
}

.card__text { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.card__code { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.card__name {
  font-size: 14px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card__meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 3px; }
.card__qty { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.card__flag {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-sunken);
  border-radius: 999px;
  padding: 1px 8px;
}
.card__actions { flex: 0 0 auto; }
.card__actions--stack { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.card--shopping { align-items: flex-start; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.badge--owned { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.badge--low { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.badge--out { background: var(--bg-sunken); color: var(--text-muted); border-color: var(--border-strong); }
.badge--warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.badge--plain { background: var(--bg-sunken); color: var(--text-muted); border-color: var(--border-strong); }

/* compact rows */
.crow {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
}
.list--compact { gap: 4px; }
.crow__code {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 14px;
  min-width: 46px;
}
.crow__name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crow__status { font-size: 11px; color: var(--text-muted); flex: 0 0 auto; }
.crow__actions { flex: 0 0 auto; }

/* grid tiles */
.tile { display: block; }
.tile__btn {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  text-align: left;
  position: relative;
}
.tile__code { font-weight: 650; font-size: 14px; }
.tile__name {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile__state { font-size: 11px; font-weight: 600; }
.tile__state--out { color: var(--text-muted); }
.tile__state--low { color: var(--warn); }
.tile__state--owned { color: var(--success); }
.tile__fav { position: absolute; top: 10px; right: 12px; color: var(--danger); font-size: 14px; }

.list-more { text-align: center; font-size: 13px; color: var(--text-muted); padding: 12px 0; }
.sentinel { height: 1px; }

/* ---------- stepper ---------- */

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elevated);
}
.stepper__btn {
  width: var(--tap);
  height: var(--tap);
  border: 0;
  background: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.stepper__btn:disabled { opacity: 0.35; cursor: default; }
.stepper__btn:active:not(:disabled) { background: var(--bg-sunken); }
.stepper__value {
  min-width: 46px;
  height: var(--tap);
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: none;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
/* "Compact" narrows the readout, never the buttons: touch targets stay at the
   44px minimum even in the dense list and shopping views. */
.stepper--compact .stepper__btn { width: var(--tap); height: var(--tap); font-size: 19px; }
.stepper--compact .stepper__value { min-width: 34px; height: var(--tap); font-size: 14px; }

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

.btn {
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn--wide { width: 100%; }
.btn--primary { background: var(--accent); color: var(--text-inverse); }
.btn--secondary { background: var(--bg-elevated); border-color: var(--border-strong); color: var(--text); }
.btn--ghost { background: none; color: var(--accent-strong); }
.btn--danger { background: var(--danger); color: #fff; }
.btn__desc { font-size: 12px; font-weight: 400; opacity: 0.85; }

.fav {
  min-height: var(--tap);
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  cursor: pointer;
  font-size: 15px;
}
.fav--on { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

/* ---------- empty states ---------- */

.empty {
  text-align: center;
  padding: 44px 16px;
  color: var(--text-muted);
}
.empty__icon { font-size: 40px; margin-bottom: 10px; }
.empty__title { font-size: 19px; color: var(--text); margin-bottom: 6px; font-weight: 600; }
.empty__body { font-size: 14px; max-width: 44ch; margin: 0 auto; }
.empty__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

/* ---------- scan screen ---------- */

.scan__modes { margin-bottom: 10px; }
.scan__modehint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.scan__stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 46vh;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scan__video { width: 100%; height: 100%; object-fit: cover; }

.scan__reticle {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scan__reticle-box {
  width: 86%;
  height: 42%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
}

.scan__status { font-size: 13px; color: var(--text-muted); margin: 8px 0; min-height: 1.4em; }

.scan__controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.switch { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); font-size: 14px; }
.switch input { width: 22px; height: 22px; }

.scan__last {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.scan__lastlabel { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.scan__lastrow { display: flex; gap: 12px; align-items: center; }
.scan__lasttext { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.scan__lastcode {
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
  color: var(--text);
}
.scan__lastqty { font-size: 13px; color: var(--text-muted); }
.scan__placeholder { font-size: 14px; color: var(--text-muted); }

.scan__totals { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.scan__totalgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.scan__total {
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}
.scan__totalvalue { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.scan__totallabel { font-size: 11px; color: var(--text-muted); }
.scan__totalactions { display: flex; gap: 8px; }
.scan__totalactions .btn { flex: 1; }

.scan__historytitle { font-size: 14px; color: var(--text-muted); margin-bottom: 6px; }
.scan__historylist { display: flex; flex-direction: column; gap: 2px; }
.scan__historyitem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: 13px;
}
.scan__historylabel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan__historydelta { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- detail screen ---------- */

.detail__bar { margin-bottom: 6px; }
.detail { display: flex; flex-direction: column; gap: 14px; }
.detail__hero .swatch--block { height: 120px; }
.detail__code { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.detail__name { font-size: 17px; color: var(--text-muted); }
.detail__badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.section__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.section__title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 650; }
.section__body { display: flex; flex-direction: column; gap: 10px; }

.detail__row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail__fact { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.detail__label { font-size: 14px; color: var(--text-muted); }
.detail__value { font-variant-numeric: tabular-nums; }
.detail__note { font-size: 12px; color: var(--text-muted); }
.detail__notes { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.detail__notetext { font-size: 14px; white-space: pre-wrap; }
.detail__notetext--empty { color: var(--text-muted); }
.detail__updated { font-size: 12px; color: var(--text-muted); text-align: center; }

.barcodes { display: flex; flex-direction: column; gap: 8px; }
.barcode { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.barcode__value { font-family: var(--font-mono); font-size: 15px; }
.barcode__meta { font-size: 12px; color: var(--text-muted); flex: 1; min-width: 0; }
.barcode__remove {
  min-height: 36px;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: none;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
}

/* ---------- settings ---------- */

.settings { display: flex; flex-direction: column; gap: 14px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.setting__text { min-width: 0; flex: 1; }
.setting__label { font-size: 15px; font-weight: 550; display: block; }
.setting__desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.setting__control { flex: 0 0 auto; }
.setting__pair { display: inline-flex; align-items: center; gap: 8px; }
.setting__links { display: flex; gap: 8px; flex-wrap: wrap; }

/* The switch is drawn 52x32, but the hit area is the full 44px row height. */
.toggle { display: inline-block; position: relative; width: 52px; height: var(--tap); }
.toggle__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.toggle__track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 32px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 0.15s ease;
}
.toggle__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.toggle__input:checked + .toggle__track { background: var(--accent); }
.toggle__input:checked + .toggle__track .toggle__thumb { transform: translateX(20px); }
.toggle__input:focus-visible + .toggle__track { outline: 3px solid var(--accent); outline-offset: 2px; }

.about__line { font-size: 13px; color: var(--text-muted); }
.about__head { font-size: 14px; margin-top: 6px; }

/* ---------- stats ---------- */

.stats { display: flex; flex-direction: column; gap: 14px; }
.stats__list { display: flex; flex-direction: column; gap: 6px; }
.stats__listitem { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.stats__listlabel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats__listvalue { font-variant-numeric: tabular-nums; font-weight: 600; }
.stats__families { display: flex; flex-direction: column; gap: 12px; }
.stats__familyhead { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.stats__familycount { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- diagnostics ---------- */

.diag { margin-bottom: 14px; }
.diag__list { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 4px 12px; font-size: 13px; }
.diag__key { color: var(--text-muted); }
.diag__value { margin: 0; overflow-wrap: anywhere; font-family: var(--font-mono); font-size: 12px; }
.diag__errors { display: flex; flex-direction: column; gap: 10px; }
.diag__errorsbody { display: flex; flex-direction: column; gap: 10px; }
.diag__errorlist { display: flex; flex-direction: column; gap: 8px; }
.diag__error {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.diag__errorhead { font-size: 11px; color: var(--text-muted); }
.diag__errormsg { font-size: 13px; }
.diag__errordetail {
  font-size: 11px;
  color: var(--text-muted);
  white-space: pre-wrap;
  overflow-x: auto;
  margin: 0;
}
.diag__copybox { width: 100%; font-family: var(--font-mono); font-size: 12px; }

/* ---------- modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.modal__panel {
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal__title { font-size: 19px; font-weight: 650; }
.modal__body { display: flex; flex-direction: column; gap: 10px; }
.modal__text { font-size: 14px; color: var(--text-muted); }
.modal__text--lead { font-size: 16px; color: var(--text); }
.modal__text--strong { color: var(--text); font-weight: 600; }
.modal__text--mono { font-family: var(--font-mono); font-size: 17px; color: var(--text); }
.modal__actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal__actions .btn { flex: 1; }
.modal__choices { display: flex; flex-direction: column; gap: 8px; }
.modal__form { display: flex; flex-direction: column; gap: 10px; }

.onboard__list { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-muted); }
.onboard__list li { padding-left: 18px; position: relative; }
.onboard__list li::before { content: "•"; position: absolute; left: 4px; color: var(--accent); }

.assign-results { display: flex; flex-direction: column; gap: 4px; max-height: 34vh; overflow-y: auto; }
.assign-result {
  width: 100%;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  cursor: pointer;
  text-align: left;
}
.assign-result--active { border-color: var(--accent); background: var(--accent-soft); }
.assign-result__code { font-weight: 650; font-size: 14px; }
.assign-result__name { font-size: 13px; color: var(--text-muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assign-empty { font-size: 14px; color: var(--text-muted); padding: 8px; }

.manual__preview { display: flex; flex-direction: column; gap: 6px; }
.manual__match { display: flex; gap: 12px; align-items: center; }
.manual__code { font-weight: 650; }
.manual__qty { font-size: 13px; color: var(--text-muted); }

.count-list { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow-y: auto; }
.count-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.count-row__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count-row__nums { font-variant-numeric: tabular-nums; color: var(--text-muted); }

.import-summary { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.import-summary li { padding-left: 16px; position: relative; }
.import-summary li::before { content: "•"; position: absolute; left: 3px; color: var(--accent); }
.import-warn { color: var(--warn); }

/* ---------- toasts ---------- */

.toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 10px);
  z-index: 50;
  display: flex;
  justify-content: center;
  padding: 0 12px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  width: 100%;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast--in { opacity: 1; transform: translateY(0); }
.toast--success { border-color: var(--success); background: var(--success-soft); }
.toast--error { border-color: var(--danger); background: var(--danger-soft); }
.toast--warn { border-color: var(--warn); background: var(--warn-soft); }
.toast__swatch { width: 26px; height: 26px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18); flex: 0 0 auto; }
.toast__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toast__message { font-size: 14px; font-weight: 600; }
.toast__detail { font-size: 12px; color: var(--text-muted); }
.toast__action {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex: 0 0 auto;
}

/* ---------- responsive: large phones, tablets, desktop ---------- */

@media (min-width: 600px) {
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .metrics--wide { grid-template-columns: repeat(4, 1fr); }
  .list--grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  .screen__title { font-size: 30px; }
}

@media (min-width: 900px) {
  .view { padding-bottom: calc(var(--tabbar-height) + 40px); }
  .list--compact { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .detail { display: grid; grid-template-columns: 260px 1fr; grid-template-areas:
    "hero identity"
    "hero sections"; align-items: start; column-gap: 20px; }
  .detail__hero { grid-area: hero; position: sticky; top: 12px; }
  .detail__hero .swatch--block { height: 200px; }
  .detail__identity { grid-area: identity; }
  .detail .section, .detail .detail__updated { grid-column: 2; }
  .scan__stage { max-height: 52vh; }
}

/* Landscape phones: keep the camera and the last-scan panel side by side so
   the preview does not shrink to a letterbox. */
@media (orientation: landscape) and (max-height: 560px) {
  .scan__stage { aspect-ratio: auto; height: 58vh; max-height: none; }
  .screen__head--tight { display: none; }
  .scan__totalgrid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) and (orientation: landscape) {
  .scan__stage { max-height: 60vh; }
}

/* ---------- motion & contrast preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

@media (prefers-contrast: more) {
  :root { --border: var(--border-strong); --text-muted: var(--text); }
}
