/* Stock Scan, bot mode (Telegram Mini App). One small sheet; no inline styles (CSP style-src 'self'). */

:root {
  --bg: #f2f4f7; --surface: #ffffff; --text: #0b1220; --muted: #4f5b6a; --line: #d6dce4;
  --accent: #0a5bd8; --accent-press: #0848ab; --accent-ink: #ffffff;
  --ok-solid: #16a34a; --warn-solid: #f59e0b; --bad: #b42318; --bad-solid: #dc2626;
  --r-sm: 12px; --r-md: 16px; --r-lg: 20px; --tap: 48px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1); --dur: 280ms;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Roboto Mono", monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14; --surface: #141a22; --text: #eef2f6; --muted: #a3afbd; --line: #283241;
    --accent: #4c9bff; --accent-press: #2f86f6; --accent-ink: #04101f; --bad: #ff8a80;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font: 16px/1.4 var(--font);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
h1, h2 { margin: 0; }

.gate { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 24px 20px; text-align: center; }
.gate h1 { font-size: 1.25rem; }
.gate p { margin: 0; font-size: 1.0625rem; }
#gate-text { font-weight: 700; }

.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.bar { padding: 12px 16px 8px; padding-top: max(12px, env(safe-area-inset-top)); }
.title { font-size: 1.25rem; font-weight: 800; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.875rem; }

/* --- camera panel ---------------------------------------------------------------- */
.cam { position: relative; height: 42vh; height: 42dvh; min-height: 220px; margin: 0 12px; border-radius: var(--r-lg); overflow: hidden; background: #000; color: #fff; }
.cam-media { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-media.mirror { transform: scaleX(-1); }
.cam-stage { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 12px; }
.cam:not(.on) .window, .cam:not(.on) .zoom-chips { visibility: hidden; }
.window {
  position: relative; width: 86%; aspect-ratio: 16 / 10; max-height: 62%;
  border-radius: var(--r-lg); box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.5);
}
.window::after { content: ""; position: absolute; inset: 0; border-radius: inherit; border: 3px solid transparent; transition: border-color 120ms var(--ease), background-color 120ms var(--ease); }
.corner { position: absolute; width: 30px; height: 30px; border: 4px solid #fff; }
.corner.tl { top: -2px; left: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: var(--r-lg); }
.corner.tr { top: -2px; right: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: var(--r-lg); }
.corner.bl { bottom: -2px; left: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: var(--r-lg); }
.corner.br { bottom: -2px; right: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: var(--r-lg); }
.scan-line { position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; border-radius: 2px; opacity: 0; background: linear-gradient(90deg, transparent, #4c9bff 20%, #9cc8ff 50%, #4c9bff 80%, transparent); box-shadow: 0 0 12px rgba(76, 155, 255, 0.9); }
.cam.searching .scan-line { opacity: 1; animation: sweep 1.6s var(--ease) infinite alternate; }
.window.hit::after { border-color: var(--ok-solid); background: rgba(34, 197, 94, 0.22); }
.window.hit .corner { border-color: #22c55e; }
.window.miss::after { border-color: var(--warn-solid); }
.cam.frozen .window { box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.25); }
@keyframes sweep { from { transform: translateY(-34px); } to { transform: translateY(34px); } }
@media (prefers-reduced-motion: reduce) { .cam.searching .scan-line { animation: none; } }

.cam-hint { position: relative; margin: 0; max-width: 34ch; text-align: center; font-weight: 600; font-size: 0.9375rem; padding: 6px 14px; border-radius: 999px; background: rgba(0, 0, 0, 0.6); }
.cam-hint.warn { color: #1a1000; background: var(--warn-solid); }
.zoom-chips { display: flex; gap: 6px; padding: 4px; border-radius: 999px; background: rgba(0, 0, 0, 0.5); }
.zoom-chip { min-width: 44px; height: 36px; border-radius: 999px; border: 0; background: transparent; color: #fff; font: 700 0.875rem var(--font); }
.zoom-chip[aria-pressed="true"] { background: #fff; color: #000; }

.start {
  position: absolute; inset: 0; margin: auto; width: max-content; height: 64px; padding: 0 28px;
  display: inline-flex; align-items: center; gap: 10px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font: 800 1.125rem var(--font);
}
.start svg { width: 26px; height: 26px; }
.cam-close { position: absolute; top: 10px; right: 10px; width: var(--tap); height: var(--tap); border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.2); background: rgba(0, 0, 0, 0.55); color: #fff; display: grid; place-items: center; }
.cam-close svg { width: 22px; height: 22px; }
.marks { position: absolute; inset: 0; width: 100%; height: 100%; }
.mark-box { fill: none; stroke: #fff; stroke-width: 3; }
.mark.likely .mark-box { stroke: #4c9bff; }
.mark circle { fill: #4c9bff; }
.mark text { fill: #fff; font: 700 15px var(--font); }

/* --- the list -------------------------------------------------------------------- */
.list-wrap { flex: 1; padding: 12px 16px 96px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.count { font-size: 1.125rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.room { margin-top: 8px; }
.room-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.room-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width var(--dur) var(--ease); }
.room-bar span[data-level="1"] { width: 10%; } .room-bar span[data-level="2"] { width: 20%; }
.room-bar span[data-level="3"] { width: 30%; } .room-bar span[data-level="4"] { width: 40%; }
.room-bar span[data-level="5"] { width: 50%; } .room-bar span[data-level="6"] { width: 60%; }
.room-bar span[data-level="7"] { width: 70%; } .room-bar span[data-level="8"] { width: 80%; background: var(--warn-solid); }
.room-bar span[data-level="9"] { width: 90%; background: var(--warn-solid); } .room-bar span[data-level="10"] { width: 100%; background: var(--bad-solid); }
.room-text { margin: 4px 0 0; font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.full { margin: 10px 0 0; padding: 10px 12px; border-radius: var(--r-sm); background: var(--bad-solid); color: #fff; font-weight: 700; }
.empty { color: var(--muted); margin: 16px 0 0; }
.list { list-style: none; margin: 10px 0 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 8px; padding: 10px 6px 10px 14px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  touch-action: pan-y; user-select: none; transition: transform 120ms var(--ease);
}
.item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-serial { font-size: 1.0625rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 0.8125rem; color: var(--muted); }
.item-x { width: var(--tap); height: var(--tap); border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: 1.125rem; }

/* --- buttons, footer, sheets ------------------------------------------------------- */
.btn { min-height: var(--tap); padding: 0 18px; border-radius: var(--r-md); border: 1px solid transparent; font: 700 1rem var(--font); display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: var(--text); background: var(--surface); }
.btn svg { width: 20px; height: 20px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { background: var(--accent-press); }
.btn-primary:disabled { opacity: 0.45; }
.btn-secondary { border-color: var(--line); }
.btn-quiet { background: transparent; color: var(--accent); padding: 0 8px; }
.btn-block { width: 100%; }
.foot { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.foot .btn { min-height: 56px; font-size: 1.125rem; }

.toast { position: fixed; left: 16px; right: 16px; bottom: 96px; z-index: 60; margin: 0; padding: 12px 14px; border-radius: var(--r-sm); background: #111827; color: #fff; font-weight: 600; text-align: center; }
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.45); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-height: 85vh; overflow: auto; padding: 20px 16px; padding-bottom: max(20px, env(safe-area-inset-bottom)); background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0; }
.sheet h2 { font-size: 1.1875rem; margin-bottom: 8px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
.serial-input { width: 100%; min-height: 56px; margin-top: 8px; padding: 0 14px; border: 2px solid var(--line); border-radius: var(--r-sm); background: var(--bg); color: var(--text); font: 700 1.25rem var(--mono); text-transform: uppercase; }
.serial-input:focus { outline: none; border-color: var(--accent); }
.choices { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.choice { width: 100%; justify-content: flex-start; border-color: var(--line); padding: 10px 12px; text-align: left; }
.choice.likely { border-color: var(--accent); }
.choice-num { width: 28px; height: 28px; border-radius: 999px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); flex: none; }
.choice-body { display: flex; flex-direction: column; min-width: 0; }
.choice-value { font-weight: 700; overflow-wrap: anywhere; }
.choice-meta { font-size: 0.8125rem; color: var(--muted); font-weight: 500; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
