:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #17202b;
  --muted: #5d6b7a;
  --line: #d9dee5;
  --primary: #1f5fae;
  --primary-text: #ffffff;
  --ok: #1e7d46;
  --ok-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fff2d9;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --top: #1f3a5f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --card: #1a212b; --text: #e8edf3; --muted: #9aa7b5; --line: #2c3643;
    --primary: #4a8fe0; --ok: #5fcb8b; --ok-bg: #14301f; --warn: #f0b24e; --warn-bg: #33270f;
    --bad: #f28b82; --bad-bg: #3a1c1a; --top: #0c1520;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); }
[hidden] { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--top); color: #fff; }
.brand { font-weight: 700; }
.status { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #999; display: inline-block; }
.dot.on { background: #4cd07d; } .dot.off { background: #e05a4f; }

.screen { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
h1 { font-size: 22px; margin: 0 0 12px; } h2 { font-size: 17px; margin: 0 0 10px; }
label { display: block; margin: 10px 0; font-weight: 600; font-size: 14px; }
input, textarea { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font-size: 17px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); }
textarea { font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 13px; font-weight: 400; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.row.between { justify-content: space-between; } .row.center { justify-content: center; }
.grow { flex: 1; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 11px 14px;
  border-radius: 10px; font-size: 16px; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.link { border: 0; background: none; color: var(--primary); padding: 4px; min-height: 0; }
.btn.small { padding: 6px 10px; font-size: 14px; min-height: 36px; }
.btn.big { width: 100%; padding: 14px; font-size: 18px; margin-top: 8px; }
.btn.huge { width: 100%; padding: 22px; font-size: 22px; margin-bottom: 12px; border-radius: 14px; }
.btn.wide { width: 100%; margin-top: 6px; }
.msg { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }

.records { list-style: none; padding: 0; margin: 0; }
.records li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0;
  border-top: 1px solid var(--line); cursor: pointer; }
.records .code { font-variant-numeric: tabular-nums; font-weight: 600; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.chip.match { background: var(--ok-bg); color: var(--ok); }
.chip.mismatch { background: var(--warn-bg); color: var(--warn); }
.chip.no_photo, .chip.void { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.chip.pending { background: var(--bad-bg); color: var(--bad); }

/* camera */
.camera-screen { padding: 0; max-width: none; }
.camera-wrap { position: relative; background: #000; height: 58vh; overflow: hidden; }
#video { width: 100%; height: 100%; object-fit: cover; }
.aim { position: absolute; left: 10%; right: 10%; top: 32%; bottom: 32%; border: 3px solid rgba(255,255,255,.85);
  border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.25); }
.flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .25s; }
.flash.good { background: rgba(40, 200, 110, .45); opacity: 1; }
.flash.bad { background: rgba(230, 70, 60, .35); opacity: 1; }
.scan-panel { padding: 12px 16px 20px; max-width: 640px; margin: 0 auto; }
.scan-title { font-size: 18px; font-weight: 700; }
.hint { min-height: 1.4em; margin-top: 6px; font-weight: 600; }
.hint.retake { background: var(--warn-bg); color: var(--warn); padding: 8px 10px; border-radius: 8px; }
.hint.good { color: var(--ok); }
.each-counter { text-align: center; margin: 8px 0; }
.big-number { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.type-box { margin-top: 10px; }
.type-box input { margin-bottom: 8px; }

.item-card .upc, .upc { font-size: 24px; font-weight: 800; letter-spacing: .5px; font-variant-numeric: tabular-nums; }
.stepper { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.stepper input { text-align: center; margin: 0; font-size: 22px; font-weight: 700; }
.btn.step { min-width: 56px; font-size: 24px; }
.total-line { margin-top: 12px; font-size: 18px; }
details { margin-top: 12px; } summary { font-weight: 600; cursor: pointer; padding: 6px 0; }

.photo-wrap { margin-top: 10px; border-radius: 8px; overflow: hidden; background: #000; }
#photo-canvas { width: 100%; display: block; touch-action: manipulation; }
.counts-line { font-size: 17px; }
.check { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.check input { width: auto; margin: 0; }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: center; }
.verdict { padding: 12px; border-radius: 10px; font-weight: 700; margin-bottom: 12px; text-align: center; }
.verdict.match { background: var(--ok-bg); color: var(--ok); }
.verdict.mismatch { background: var(--warn-bg); color: var(--warn); }
.verdict.no_photo { background: var(--card); color: var(--muted); border: 1px solid var(--line); }
.radio { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 16px; }
.radio input[type=radio] { width: auto; margin: 0; }
.inline-num { width: 110px; display: inline-block; margin: 0; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
  width: min(92vw, 560px); }
.rd-body { white-space: pre-wrap; font-size: 13px; background: var(--bg); padding: 10px; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 90vw; }
