/* ReID · веб-интерфейс оператора. Без внешних ресурсов: системные шрифты, офлайн. */
:root {
  --bg: #f4f3f8; --surface: #ffffff; --surface-2: #f7f6fb; --line: #e4e1ec; --line-2: #d6d2e2;
  --text: #1b1a22; --muted: #6c6780; --faint: #9a95ab;
  --accent: #e8004f; --accent-ink: #ffffff; --accent-soft: #ffe1eb;
  --violet: #5b2a91; --lilac: #8a83d1;
  --ok: #0e8a5f; --ok-soft: #dcf3ea; --mid: #b86e00; --mid-soft: #fbeed8; --bad: #c62f3e; --bad-soft: #fbe2e5;
  --stage: #0d0c12; --shadow: 0 1px 2px rgba(20, 16, 40, .06), 0 8px 24px rgba(20, 16, 40, .06);
  --r: 14px; --r-sm: 9px;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0e0c14; --surface: #16131f; --surface-2: #1c1827; --line: #2a2536; --line-2: #3a3349;
  --text: #ecebf3; --muted: #a39db5; --faint: #6f6983;
  --accent: #ff2e6d; --accent-ink: #ffffff; --accent-soft: #3b1426;
  --violet: #b99cff; --lilac: #8a83d1;
  --ok: #3ad29a; --ok-soft: #10302a; --mid: #ffb44d; --mid-soft: #33250f; --bad: #ff6674; --bad-soft: #3a1419;
  --stage: #07060b; --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- шапка ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
       padding: 12px 24px; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(12px);
       border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand .mark { width: 34px; height: 34px; }
.brand .mark rect { fill: var(--accent); }
.brand .mark path, .brand .mark circle { fill: #fff; }
.brand .mark circle { fill: var(--accent); }
.brand b { font: 700 18px/1.1 var(--display); letter-spacing: .2px; display: block; }
.brand span { color: var(--muted); font-size: 12.5px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); padding: 4px; border-radius: 12px; }
.tabs button { border: 0; background: none; padding: 7px 16px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface);
        border-radius: 999px; padding: 4px 11px; font-size: 12.5px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.chip.link:hover { color: var(--text); border-color: var(--line-2); }
.chip.warn { color: var(--mid); border-color: color-mix(in srgb, var(--mid) 40%, transparent); background: var(--mid-soft); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.chip.ok .dot { background: var(--ok); } .chip.bad .dot { background: var(--bad); }
.icon-btn { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; border: 1px solid var(--line);
            background: var(--surface); cursor: pointer; }
.icon-btn svg { width: 16px; height: 16px; fill: var(--muted); }

/* ---------- раскладка ---------- */
main { max-width: 1480px; margin: 0 auto; padding: 20px 24px 60px; }
.tab-page { display: grid; gap: 18px; }
#tab-search { grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr); align-items: start; }
.col-left, .col-right { display: grid; gap: 18px; min-width: 0; }
@media (max-width: 1080px) {
  #tab-search { grid-template-columns: 1fr; }
  .col-left > .controls { order: 1; }          /* на узком экране «Найти» — сразу под кадром, примеры ниже */
  .col-left > .card:has(#samples) { order: 2; }
}
@media (max-width: 640px) {
  main { padding: 14px 12px 40px; }
  .top { position: static; padding: 10px 12px; gap: 10px; }
  .brand span { display: none; }
  .brand { margin-right: 0; flex: 1; }
  .tabs { order: 3; width: 100%; }
  .tabs button { flex: 1; padding: 7px 6px; }
  .status { gap: 6px; }
  #stGallery, #stDevice { display: none; }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.eyebrow { font: 700 11px/1.2 var(--sans); letter-spacing: .09em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
h2 { font: 700 18px/1.25 var(--display); margin: 0; text-wrap: balance; }
.muted { color: var(--muted); font-size: 13.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- кнопки и контролы ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 10px; padding: 8px 14px;
       border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px;
       transition: background .15s, border-color .15s, transform .1s; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--faint); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); padding: 11px 22px; font-size: 15px; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn input[type=file] { display: none; }
.spinner { width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
           animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; align-items: start; }
.controls .switch, .controls .btn.primary { grid-column: 1 / -1; }
.ctrl { display: grid; gap: 6px; }
.ctrl label { display: flex; justify-content: space-between; align-items: baseline; font-size: 13.5px; color: var(--muted); }
.ctrl label b { color: var(--text); font-family: var(--mono); }
.ctrl small { color: var(--faint); font-size: 12px; line-height: 1.4; }
input[type=range] { width: 100%; margin: 0; accent-color: var(--accent); height: 22px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; color: var(--muted); user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; }
.switch span { width: 38px; height: 22px; border-radius: 999px; background: var(--line-2); position: relative; transition: background .2s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 640px) {
  .controls { grid-template-columns: 1fr; }
  .card-head .actions { width: 100%; }
  .card-head .actions .btn { flex: 1; padding: 8px 6px; font-size: 13px; }
  .btn.primary { padding: 14px 22px; }
}

/* ---------- сцена с кадром ---------- */
.stage { position: relative; background: var(--stage); border-radius: 12px; aspect-ratio: 16 / 9; overflow: hidden;
         display: grid; place-items: center; border: 1px dashed transparent; }
.stage.drag { border-color: var(--accent); }
.stage img, .stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage img { object-fit: contain; user-select: none; -webkit-user-drag: none; }
.stage svg { touch-action: pan-y pinch-zoom; cursor: crosshair; }
.stage.drawing svg { touch-action: none; }
.stage.drawing { outline: 2px solid var(--accent); outline-offset: 2px; }
#drawBtn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* найденные машины — кнопки-превью под кадром */
.dets { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 4px; scroll-snap-type: x proximity; }
.det-chip { flex: none; display: grid; gap: 5px; padding: 5px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2);
            cursor: pointer; scroll-snap-align: start; transition: border-color .15s, background .15s; }
.det-chip:hover { border-color: var(--line-2); }
.det-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.det-thumb { width: 104px; height: 78px; border-radius: 7px; background: var(--stage); display: grid; place-items: center; overflow: hidden; }
.det-thumb canvas { max-width: 100%; max-height: 100%; display: block; }
.det-cap { font-size: 11.5px; color: var(--muted); text-align: left; white-space: nowrap; }
.det-chip.active .det-cap { color: var(--accent); font-weight: 600; }
.stage-empty { color: #8f8aa1; text-align: center; padding: 20px; font-size: 14px; }
.stage-busy { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 8px; align-items: center; background: rgba(10, 9, 15, .78);
              color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 12.5px; }
.stage-info { margin-top: 10px; font-size: 13px; color: var(--muted); min-height: 20px; }
.stage-info b { color: var(--text); }

/* рамки на кадре (SVG, координаты — пиксели исходного кадра) */
.det { fill: transparent; stroke: rgba(255, 255, 255, .75); stroke-dasharray: 10 8; cursor: pointer; transition: stroke .15s; }
.det:hover { stroke: #fff; stroke-dasharray: none; }
.det-label { fill: rgba(10, 9, 15, .75); }
.det-text { fill: #fff; font: 600 22px var(--sans); pointer-events: none; }
.sel { fill: transparent; stroke: var(--accent); }
.sel-corner { fill: var(--accent); }
.dim { fill: rgba(5, 4, 8, .55); pointer-events: none; }

/* ---------- примеры: уменьшенный кадр + рамка машины ---------- */
.samples { display: grid; grid-auto-flow: column; grid-auto-columns: 168px; gap: 10px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
.sample { position: relative; border: 2px solid transparent; border-radius: 10px; overflow: hidden; cursor: pointer; padding: 0;
          background: var(--surface-2); aspect-ratio: 16 / 9; scroll-snap-align: start; transition: border-color .15s; }
.sample:not(.loaded) { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.sample img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; display: block; opacity: 0; transition: opacity .3s; }
.sample.loaded img { opacity: 1; }
.sample-box { position: absolute; border: 2px solid var(--accent); border-radius: 3px; box-shadow: 0 0 0 999px rgba(5, 4, 8, .28); pointer-events: none; }
.sample.active { border-color: var(--accent); }
.sample:hover { border-color: var(--line-2); }
.sample.active:hover { border-color: var(--accent); }
.sample.busy::after { content: ""; position: absolute; right: 6px; bottom: 6px; width: 14px; height: 14px; border-radius: 50%;
                      border: 2px solid #fff; border-right-color: transparent; animation: spin .7s linear infinite; }
@media (max-width: 640px) { .samples { grid-auto-columns: 140px; } }

/* ---------- вердикт ---------- */
.verdict-body { display: flex; gap: 20px; align-items: center; }
.ring { position: relative; width: 112px; height: 112px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring .track { stroke: var(--line); }
.ring .val { stroke: var(--faint); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .6s ease, stroke .3s; }
.ring b { position: absolute; inset: 0; display: grid; place-items: center; font: 700 24px var(--mono); }
.verdict h2 { font-size: 22px; }
.verdict p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.verdict.ok { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.verdict.ok .ring .val { stroke: var(--ok); } .verdict.ok h2 { color: var(--ok); }
.verdict.no { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.verdict.no .ring .val { stroke: var(--bad); } .verdict.no h2 { color: var(--bad); }
.verdict.err h2 { color: var(--bad); }
.route { display: flex; align-items: center; gap: 10px; margin-top: 12px; font: 600 13px var(--mono); }
.route span { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; }
.route i { flex: 1; max-width: 90px; height: 2px; background: linear-gradient(90deg, var(--lilac), var(--accent)); position: relative; }
.route i::after { content: ""; position: absolute; right: -2px; top: -4px; border: 5px solid transparent; border-left-color: var(--accent); }
@media (max-width: 520px) { .verdict-body { flex-direction: column; align-items: flex-start; } }

/* ---------- сравнение пары ---------- */
.pair { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 14px; align-items: center; }
.pair figure { margin: 0; display: grid; gap: 8px; }
.pair figcaption { font-size: 12.5px; color: var(--muted); text-align: center; }
.shot { position: relative; background: var(--stage); border-radius: 10px; overflow: hidden; height: 260px; display: grid; place-items: center; }
.shot img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.shot.explained { height: auto; }
.shot.explained img { width: 100%; height: 100%; max-height: none; object-fit: fill; }
.shot .heat { position: absolute; inset: 0; pointer-events: none; background-size: 100% 100%; opacity: 0; transition: opacity .25s; }
.pair-mid { display: grid; justify-items: center; gap: 4px; min-width: 88px; }
.pair-mid b { font: 700 26px var(--mono); }
.pair-mid small { color: var(--muted); font-size: 12px; }
.pill { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.hi { background: var(--ok-soft); color: var(--ok); } .pill.mid { background: var(--mid-soft); color: var(--mid); } .pill.lo { background: var(--bad-soft); color: var(--bad); }
.heat-bar { display: grid; grid-template-columns: auto 180px 1fr; gap: 12px; align-items: center; margin-top: 14px; font-size: 13px; color: var(--muted); }
.heat-bar small { color: var(--faint); }
@media (max-width: 640px) { .pair { grid-template-columns: 1fr; } .shot { height: 220px; } .heat-bar { grid-template-columns: 1fr; } }

/* ---------- кандидаты и галерея ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.legend .b { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: -8px; }
.b.hi { background: var(--ok); } .b.mid { background: var(--mid); } .b.lo { background: var(--bad); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.grid.gallery { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.cand { border: 1px solid var(--line); border-radius: 11px; overflow: hidden; background: var(--surface-2); cursor: pointer; padding: 0; text-align: left;
        transition: border-color .15s, transform .15s; animation: rise .35s ease both; }
.cand:hover { border-color: var(--line-2); transform: translateY(-2px); }
.cand.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cand .thumb { aspect-ratio: 4 / 3; background: var(--stage); display: grid; place-items: center; position: relative; }
.cand .thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.cand .rank { position: absolute; top: 6px; left: 6px; font: 700 11px var(--mono); background: rgba(10, 9, 15, .75); color: #fff; padding: 2px 6px; border-radius: 6px; }
.cand .meta { padding: 8px 9px 9px; display: grid; gap: 5px; }
.cand .row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.cand .row b { font: 700 13.5px var(--mono); color: var(--text); }
.cand .bar { height: 4px; border-radius: 3px; background: var(--line); overflow: hidden; }
.cand .bar i { display: block; height: 100%; background: var(--bad); }
.cand.hi .bar i { background: var(--ok); } .cand.mid .bar i { background: var(--mid); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.more { display: flex; justify-content: center; margin-top: 14px; }

/* ---------- о решении ---------- */
.about h2 { font-size: 24px; margin-bottom: 18px; }
.steps { list-style: none; padding: 0; margin: 0 0 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; counter-reset: s; }
.steps li { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 4px; counter-increment: s; }
.steps li::before { content: counter(s); font: 700 12px var(--mono); color: var(--accent); }
.steps b { font-family: var(--display); }
.steps span { color: var(--muted); font-size: 13.5px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpis div { border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.kpis b { font: 700 26px var(--mono); display: block; }
.kpis span { color: var(--muted); font-size: 13px; }

/* ---------- уведомления и окна ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--surface); border: 1px solid var(--line-2); border-left: 0; border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow);
         font-size: 13.5px; max-width: 360px; animation: rise .25s ease both; }
.toast.error { color: var(--bad); } .toast.ok { color: var(--ok); }
.modal { position: fixed; inset: 0; background: rgba(5, 4, 8, .55); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; max-width: 400px; width: 100%; }
.modal-box h3 { margin: 0 0 8px; font-family: var(--display); }
.modal-box p { color: var(--muted); margin: 0 0 16px; }
.modal-box .actions { justify-content: flex-end; }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: 11px; aspect-ratio: 4 / 4.2; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
