/* lit-stock: phone-first, high contrast, big targets (>= 48px), primary actions at the bottom. */
:root {
  --bg: #ffffff;
  --surface: #f3f5f7;
  --text: #111418;
  --muted: #4a5360;        /* 7.6:1 on white */
  --line: #6b7480;         /* 4.8:1, for borders that carry meaning */
  --primary: #0b4f8a;      /* 8.6:1 with white text */
  --primary-ink: #ffffff;
  --danger: #a1121f;
  --ok: #1d6b2f;
  --warn-bg: #fff4d6;
  --warn-ink: #5c3d00;
  --focus: #b35c00;
  --dev: #6b1d8a;
  --radius: 10px;
  --tap: 48px;
  --bar-h: 64px;
  font-size: 100%;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1216; --surface: #1b2027; --text: #f2f4f7; --muted: #b9c1cc; --line: #8a94a1;
    --primary: #5aa9f0; --primary-ink: #06121f; --danger: #ff8a93; --ok: #7fd48f;
    --warn-bg: #3a2c05; --warn-ink: #ffe3a1; --focus: #ffb35c; --dev: #d9a3f0;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 1.0625rem/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: .25rem 0 .75rem; }
h2 { font-size: 1.2rem; margin: 1.25rem 0 .5rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus, h1[tabindex='-1']:focus { outline: none; }
.skip { position: absolute; left: -999px; top: 0; background: var(--bg); padding: .75rem; z-index: 10; }
.skip:focus { left: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem; border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 5; }
.topbar .brand { font-weight: 800; font-size: 1.1rem; margin-right: auto; }
.who { font-size: .9rem; color: var(--muted); text-align: right; }
.devbar { background: var(--dev); color: #fff; padding: .5rem 1rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; font-size: .95rem; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .devbar { color: #1b0626; } }
.devbar select { min-height: 44px; font-size: 1rem; flex: 1; width: auto; min-width: 0; }
.devbar .devlabel { margin: 0; font-weight: 600; }
.devbar { flex-wrap: nowrap; }

main { padding: 1rem; max-width: 720px; margin: 0 auto; }

/* Buttons and fields */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: var(--tap); min-width: var(--tap); padding: .5rem 1rem;
  font: inherit; font-weight: 650; border-radius: var(--radius); cursor: pointer;
  border: 2px solid var(--primary); background: var(--bg); color: var(--primary); text-decoration: none;
}
button.primary, .btn.primary { background: var(--primary); color: var(--primary-ink); }
button.danger { border-color: var(--danger); color: var(--danger); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.block, .btn.block { width: 100%; }
label { font-weight: 600; display: block; margin: .75rem 0 .25rem; }
input, select, textarea {
  font: inherit; width: 100%; min-height: var(--tap); padding: .5rem .75rem;
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--bg); color: var(--text);
}
textarea { min-height: 6rem; }
.hint { color: var(--muted); font-size: .95rem; margin: .25rem 0; }
.error { color: var(--danger); font-weight: 600; }
.row { display: flex; gap: .5rem; align-items: center; }
.row > * { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* Home tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.tile { display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; min-height: 112px; padding: 1rem; border-radius: 14px; border: 2px solid var(--primary); color: var(--primary); text-decoration: none; font-weight: 750; font-size: 1.15rem; background: var(--bg); }
.tile.main { background: var(--primary); color: var(--primary-ink); grid-column: span 2; min-height: 128px; font-size: 1.35rem; }
.tile small { font-weight: 500; font-size: .95rem; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.list li { border-bottom: 1px solid var(--line); }
.list .pick { width: 100%; justify-content: space-between; text-align: left; border: 0; border-radius: 0; min-height: 56px; color: var(--text); background: transparent; font-weight: 600; padding: .5rem .25rem; }
.list .pick small { color: var(--muted); font-weight: 500; }
.itemrow { display: flex; gap: .75rem; align-items: center; padding: .5rem 0; }
.itemrow img { width: 44px; height: 62px; border-radius: 4px; flex: none; }
.itemrow .meta { flex: 1; min-width: 0; }
.itemrow .meta b { display: block; overflow-wrap: anywhere; }
li.basketrow { padding: .5rem 0 .75rem; }
.num.big { font-size: 1.3rem; }
.num { font-variant-numeric: tabular-nums; font-weight: 700; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .85rem; font-weight: 700; border: 1.5px solid currentColor; }
.badge.low { color: var(--danger); }
.badge.ok { color: var(--ok); }
.badge.dev { color: var(--dev); }
.notice { background: var(--warn-bg); color: var(--warn-ink); padding: .75rem 1rem; border-radius: var(--radius); margin: .75rem 0; }

/* Bottom action bar (one-handed: primary actions within thumb reach) */
.actionbar { position: fixed; left: 0; right: 0; bottom: calc(var(--bar-h) + env(safe-area-inset-bottom)); padding: .5rem 1rem; background: var(--bg); border-top: 1px solid var(--line); display: flex; gap: .5rem; z-index: 4; }
.actionbar > * { flex: 1; }
.has-actionbar { padding-bottom: 5rem; }

/* Bottom navigation */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--bar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--surface); border-top: 1px solid var(--line); z-index: 6; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--text); font-size: .85rem; font-weight: 650; min-height: var(--tap); }
.tabbar a[aria-current='page'] { color: var(--primary); box-shadow: inset 0 4px 0 var(--primary); }
.tabbar svg { width: 24px; height: 24px; }

/* Scanner */
.scanner { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 3 / 4; max-height: 52vh; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 18% 14%; border: 4px solid #fff; border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); pointer-events: none; }
.scanner .msg { position: absolute; left: 0; right: 0; bottom: 0; padding: .75rem; color: #fff; background: rgba(0,0,0,.65); text-align: center; font-weight: 600; }
.stepbar { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.stepbar b { font-size: 1.05rem; }

/* Quantity stepper */
.stepper { display: grid; grid-template-columns: 72px 1fr 72px; gap: .5rem; align-items: stretch; margin: .5rem 0; }
.stepper button { min-height: 64px; font-size: 2rem; line-height: 1; padding: 0; }
.stepper input { text-align: center; font-size: 1.75rem; font-weight: 800; min-height: 64px; }

/* Bottom sheet dialogs */
dialog.sheet { margin: auto 0 0; width: 100%; max-width: 100%; max-height: 92dvh; border: 0; border-radius: 18px 18px 0 0; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); background: var(--bg); color: var(--text); }
dialog.sheet::backdrop { background: rgba(0,0,0,.55); }
@media (min-width: 760px) { dialog.sheet { max-width: 560px; margin: auto; border-radius: 18px; } }
.sheet .cover-lg { width: 120px; height: 168px; border-radius: 6px; }
.match { display: flex; gap: 1rem; align-items: flex-start; }
.alts { display: grid; gap: .5rem; margin-top: .75rem; }
.alts button { justify-content: flex-start; text-align: left; color: var(--text); border-color: var(--line); }
.alts img { width: 36px; height: 50px; border-radius: 3px; }
.sheet-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.sheet-actions > * { flex: 1; }

/* Tables (reports) collapse to cards on phones */
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface); }
@media (max-width: 600px) {
  table.cards thead { position: absolute; left: -9999px; }
  table.cards tr { display: block; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .5rem; padding: .25rem .5rem; }
  table.cards td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem 0; }
  table.cards td::before { content: attr(data-label); font-weight: 700; color: var(--muted); }
}
pre.json { white-space: pre-wrap; word-break: break-word; font-size: .8rem; margin: 0; }

/* Toast */
#toast { position: fixed; left: 1rem; right: 1rem; bottom: calc(var(--bar-h) + 4.5rem); z-index: 20; display: flex; justify-content: center; pointer-events: none; }
#toast p { margin: 0; background: var(--text); color: var(--bg); padding: .75rem 1rem; border-radius: var(--radius); font-weight: 600; max-width: 560px; }
#toast p.err { background: var(--danger); color: #fff; }

/* QR labels (printable) */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.label { border: 1px dashed var(--line); padding: .5rem; text-align: center; break-inside: avoid; }
.label svg { width: 100%; max-width: 140px; height: auto; }
.label b { display: block; font-family: ui-monospace, monospace; font-size: 1.1rem; }
.label span { display: block; font-size: .85rem; }

@media print {
  .topbar, .devbar, .tabbar, .actionbar, .noprint, #toast, .skip { display: none !important; }
  body { padding: 0; background: #fff; color: #000; }
  main { max-width: none; padding: 0; }
  .labels { grid-template-columns: repeat(3, 1fr); gap: 0; }
  .label { height: 38mm; border: 1px dotted #999; padding: 2mm; }
  .label svg { max-width: 24mm; }
  table.cards thead { position: static; }
  table.cards tr { display: table-row; border: 0; }
  table.cards td { display: table-cell; border-bottom: 1px solid #999; }
  table.cards td::before { content: none; }
}

/* Checkboxes: big but not stretched; grid cells may shrink (date inputs) */
input[type='checkbox'] { width: 28px; height: 28px; min-height: 0; flex: none; accent-color: var(--primary); }
label:has(> input[type='checkbox']) { display: flex; align-items: center; gap: .75rem; min-height: var(--tap); }
.grid2 > *, .row > * { min-width: 0; }
input[type='date'] { min-width: 0; }
a.itemrow { color: var(--text); text-decoration: none; }
a.itemrow .meta b { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
