:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --info: #475569;
  --info-bg: #e2e8f0;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --line: #1f2937;
    --primary: #3b82f6;
    --ok: #4ade80;
    --ok-bg: #052e16;
    --warn: #fbbf24;
    --warn-bg: #3a2a05;
    --bad: #f87171;
    --bad-bg: #3b0b0b;
    --info: #cbd5e1;
    --info-bg: #1e293b;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.wrap { max-width: 720px; margin: 0 auto; padding: 12px 16px 40px; display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
h1, h2 { margin: 0 0 12px; }
h2 { font-size: 18px; }
.muted { color: var(--muted); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 16px; background: #0f172a; color: #fff;
}
.brand { font-weight: 700; }
.tag { background: #f59e0b; color: #000; font-size: 12px; padding: 2px 8px; border-radius: 99px; margin-left: 6px; }
.top-actions { display: flex; gap: 6px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 12px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--bad); border-color: currentColor; background: transparent; }
.btn.ok { color: var(--ok); border-color: currentColor; background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 14px; }
.top .btn.ghost { background: transparent; color: #fff; border-color: #334155; }
.btn.ghost { background: transparent; }

input, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-width: 0;
}
label { display: grid; gap: 6px; margin-bottom: 12px; font-weight: 600; }
.login { min-height: 80vh; align-content: center; }
.login .card { display: grid; }
.err { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }

.scanner { display: grid; gap: 12px; }
/* низкое окно камеры: видео обрезается по высоте, распознаётся весь кадр */
.reader {
  position: relative; width: 100%; height: clamp(140px, 24vh, 200px);
  border-radius: 10px; overflow: hidden; background: #000;
}
.reader video {
  width: 100% !important; height: 100% !important; object-fit: cover; display: block;
}
.reader::after {  /* прицел */
  content: ''; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px;
  background: rgba(239, 68, 68, .85); box-shadow: 0 0 6px rgba(239, 68, 68, .9); pointer-events: none;
}
.reader[hidden] { display: none; }
#torchBtn.on { background: #facc15; border-color: #facc15; color: #000; }
.scan-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.scan-controls .btn { flex: 1 1 auto; }
.scan-controls select { flex: 1 1 160px; }
.manual { display: flex; gap: 8px; }
.manual input { flex: 1; font-family: ui-monospace, Consolas, monospace; letter-spacing: .03em; }

.result:empty { display: none; }
.res { border-radius: var(--radius); padding: 16px; border: 2px solid; animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.97); opacity: .4; } to { transform: none; opacity: 1; } }
.res.marked   { background: var(--ok-bg);   border-color: var(--ok); }
.res.already  { background: var(--warn-bg); border-color: var(--warn); }
.res.not_found, .res.error { background: var(--bad-bg); border-color: var(--bad); }
.res.multiple { background: var(--warn-bg); border-color: var(--warn); }
.res.unmarked { background: var(--info-bg); border-color: var(--info); }
.res-title { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.res.marked .res-title { color: var(--ok); }
.res.already .res-title, .res.multiple .res-title { color: var(--warn); }
.res.not_found .res-title, .res.error .res-title { color: var(--bad); }
.res-code { font-family: ui-monospace, Consolas, monospace; word-break: break-all; margin-bottom: 8px; }
.match { background: var(--card); border-radius: 10px; padding: 12px; margin-top: 10px; display: grid; gap: 10px; }
.fields { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; font-weight: 600; word-break: break-word; }
.fields dd.owner { font-size: 20px; }
.fields dd.mono { font-family: ui-monospace, Consolas, monospace; }
.match-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.history-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.stats { display: flex; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.pill { padding: 2px 8px; border-radius: 99px; font-weight: 700; }
.pill.marked { background: var(--ok-bg); color: var(--ok); }
.pill.already, .pill.multiple { background: var(--warn-bg); color: var(--warn); }
.pill.not_found, .pill.error { background: var(--bad-bg); color: var(--bad); }
.pill.unmarked { background: var(--info-bg); color: var(--info); }
.history-tools { display: flex; gap: 8px; margin-bottom: 8px; }
.history-tools input { flex: 1; padding: 8px 10px; }
.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.h-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.h-main { min-width: 0; }
.h-code { font-family: ui-monospace, Consolas, monospace; font-size: 14px; word-break: break-all; }
.h-sub { color: var(--muted); font-size: 13px; }
.h-actions { display: flex; gap: 4px; }

@media (max-width: 480px) {
  .top .brand { font-size: 15px; }
  .history-list li { grid-template-columns: 1fr auto; }
  .h-time { grid-column: 1 / -1; }
}
