/* =========================================================================
   ANPR shared UI — v3 (multi-page admin chassis)
   Includes: design tokens (OKLCH-friendly), sidebar nav, page-header,
   command palette, toast, ГОСТ plate visual + mini-plate, sparkline,
   kbd chip, view-transitions, reduced-motion / reduced-transparency.
   Backward-compatible with v2 classes (.topbar, .panel, .btn, .icon-btn).
   ========================================================================= */

/* Saved frames use the shared page header, controls and color tokens. */
.capture-archive { min-width: 0; }
[hidden] { display: none !important; }
.range-readout { justify-self: end; min-width: 3ch; color: var(--text); font-size: 12px; font-weight: 700; }
.archive-check { display: inline-flex !important; align-items: center; gap: 8px; }
.scan-log-table { overflow-x: auto; }
.scan-log-table table { width: 100%; border-collapse: collapse; }
.scan-log-table th, .scan-log-table td { text-align: left; vertical-align: top; padding: 12px; border-bottom: 1px solid var(--line); }
.scan-log-table img { width: 120px; height: 68px; object-fit: contain; }
.scan-log-table td small { display: block; color: var(--muted); }
.archive-toolbar, .archive-summary, .archive-pagination, .archive-preview-actions {
  display: flex; align-items: center; flex-wrap: wrap; gap: 12px;
}
.archive-toolbar { align-items: end; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.archive-toolbar label { display: grid; gap: 6px; min-width: 0; font-size: 13px; }
.archive-toolbar select { max-width: 100%; width: 290px; }
.archive-summary { justify-content: space-between; margin: 18px 0; font-size: 13px; }
.archive-pagination label { display: flex; align-items: center; gap: 8px; }
.archive-pagination input { width: 72px; }
.archive-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 16px; }
.archive-grid[aria-busy="true"] { opacity: .6; pointer-events: none; }
.archive-card { display: grid; grid-template-rows: auto auto auto; gap: 6px; min-width: 0;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; padding: 0 0 12px;
  background: var(--surface); color: var(--text); text-align: left; cursor: pointer; }
.archive-card:hover { border-color: var(--primary); }
.archive-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.archive-card img { display: block; width: 100%; aspect-ratio: 16/9; object-fit: contain; background: #080808; }
.archive-card strong, .archive-card span { padding: 0 12px; overflow-wrap: anywhere; font-size: 13px; letter-spacing: 0; }
.archive-card strong { margin-top: 5px; }
.archive-card span { color: var(--muted); }
.archive-dialog { width: min(1400px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }
.archive-dialog::backdrop { background: rgba(0,0,0,.8); }
.archive-preview-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }
.archive-preview-header strong { overflow-wrap: anywhere; font-size: 14px; }
.archive-preview-viewport { height: min(65dvh, 800px); overflow: auto; background: #080808; }
.archive-preview-viewport img { display: block; width: 100%; height: 100%; object-fit: contain; }
.archive-preview-viewport.original-size img { width: auto; height: auto; max-width: none; max-height: none; object-fit: initial; }
.archive-preview-actions { padding: 12px 16px; }
.archive-zoom { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.archive-filename { padding: 0 16px 14px; overflow-wrap: anywhere; color: var(--muted); font-size: 12px; }
#archiveImageError { padding: 0 16px; color: var(--danger); }
.video-session-grid { display: grid; gap: 12px; }
.archive-mode { display:flex; gap:4px; width:max-content; max-width:100%; border-bottom:1px solid var(--line); margin-bottom:18px; }
.video-archive-page .app-main { grid-template-columns: minmax(0, 1fr); }
.video-archive-page .archive-mode { width: 100%; flex-wrap: wrap; }
.archive-mode button { border:0; border-bottom:2px solid transparent; padding:10px 14px; background:none; color:var(--muted); cursor:pointer; font:inherit; }
.archive-mode button[aria-selected="true"] { border-bottom-color:var(--primary); color:var(--text); font-weight:700; }
.video-session-grid[aria-busy="true"] { opacity: .6; pointer-events: none; }
.video-session { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.video-session > header { padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.video-session > header div, .video-camera-row > div:first-child { display: grid; gap: 4px; }
.video-session span, .video-camera-row span { color: var(--muted); font-size: 12px; }
.video-camera-list { display: grid; }
.video-camera-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; }
.video-camera-row + .video-camera-row { border-top: 1px solid var(--line); }
.video-preview-viewport { height: min(70dvh, 820px); background: #080808; }
.video-preview-viewport video { display: block; width: 100%; height: 100%; object-fit: contain; }
.video-preroll { display: flex; align-items: start; gap: 8px; padding: 12px; overflow-x: auto; }
.video-preroll[hidden] { display: none; }
.video-preroll > strong { flex: 0 0 120px; font-size: 12px; }
.video-preroll a { display: grid; gap: 4px; flex: 0 0 120px; color: var(--muted); font-size: 11px; text-decoration: none; }
.video-preroll img { display: block; width: 120px; aspect-ratio: 16 / 9; object-fit: contain; background: #080808; }
.timeline-controls { display: flex; align-items: center; gap: 14px; margin-top: 20px; }
.timeline-controls input[type="range"] { flex: 1; min-width: 80px; }
.timeline-controls strong { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 15px; }
.timeline-camera-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.timeline-camera { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.timeline-camera header { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; font-size: 13px; }
.timeline-camera header span { color: var(--muted); text-align: right; }
.timeline-camera-view { position: relative; aspect-ratio: 16 / 9; background: #080808; }
.timeline-camera-view video { display: block; width: 100%; height: 100%; object-fit: contain; }
.timeline-camera-view .timeline-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.timeline-coverage { position: relative; height: 12px; margin: 12px; border: 1px solid var(--line); background: var(--surface-soft); cursor: crosshair; }
.timeline-coverage-block { position: absolute; top: 0; bottom: 0; background: var(--primary-2); opacity: .8; pointer-events: none; }
.timeline-coverage-marker { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text-strong); pointer-events: none; }
@media (max-width: 1024px) {
  .capture-archive-page .page-header { padding-left: 48px; }
  .video-archive-page .page-header { padding-left: 48px; }
}
@media (max-width: 600px) {
  .archive-toolbar label { width: 100%; }
  .archive-toolbar select { width: 100%; }
  .archive-preview-viewport { height: 52dvh; }
  .archive-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .video-camera-row { align-items: stretch; flex-direction: column; }
  .timeline-camera-grid { grid-template-columns: 1fr; }
  .timeline-controls { flex-wrap: wrap; }
  .timeline-controls input[type="range"] { flex-basis: 100%; order: 3; }
}

/* ---------- TOKENS ---------- */
:root {
  --r-card: 14px;
  --r-input: 10px;
  --r-pill: 999px;
  --grad-accent: linear-gradient(135deg, #5b8cff 0%, #22d3ee 100%);
  --grad-accent-soft: linear-gradient(135deg, rgba(91, 140, 255, 0.18), rgba(34, 211, 238, 0.18));
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur: 180ms;
  --nav-w: 248px;
  --nav-w-collapsed: 72px;
  --header-h: 76px;
  --hairline: 1px solid var(--line);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f17;
  --bg-glow: radial-gradient(900px 500px at 8% -10%, rgba(91, 140, 255, 0.12), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(34, 211, 238, 0.08), transparent 60%);
  --surface: #111826;
  --surface-2: #0f1623;
  --surface-soft: #0c121d;
  --line: #1f2937;
  --line-strong: #2a3a52;
  --text: #e5e9f0;
  --text-strong: #f5f7fb;
  --muted: #8a94a6;
  --muted-2: #5d6675;
  --primary: #5b8cff;
  --primary-2: #22d3ee;
  --primary-ink: #0b0f17;
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.14);
  --danger: #f43f5e;
  --danger-soft: rgba(244, 63, 94, 0.14);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.14);
  --topbar-bg: rgba(11, 15, 23, 0.72);
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 12px 32px rgba(0, 0, 0, 0.35);
  --ring: 0 0 0 2px rgba(34, 211, 238, 0.55);
  --plate-bg: #f5f6f7;
  --plate-ink: #0a0a0a;
  --plate-border: #111;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f9;
  --bg-glow: radial-gradient(900px 500px at 8% -10%, rgba(91, 140, 255, 0.18), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(34, 211, 238, 0.14), transparent 60%);
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --surface-soft: #f3f5f9;
  --line: #e3e8ef;
  --line-strong: #cbd3df;
  --text: #0f172a;
  --text-strong: #060b18;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --primary: #3a6bff;
  --primary-2: #06b6d4;
  --primary-ink: #ffffff;
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.12);
  --info: #0284c7;
  --info-soft: rgba(2, 132, 199, 0.12);
  --topbar-bg: rgba(255, 255, 255, 0.72);
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 8px 24px rgba(15, 23, 42, 0.06);
  --ring: 0 0 0 2px rgba(58, 107, 255, 0.45);
  --plate-bg: #fcfcfc;
  --plate-ink: #0a0a0a;
  --plate-border: #1f2937;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .app-nav, .topbar, .cmdk-modal, .toast, .hud-chip, .live-badge {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
}

/* ---------- BASE ---------- */
body {
  font-family: Inter, "Inter Variable", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif !important;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text) !important;
  background: var(--bg-glow), var(--bg) !important;
  background-attachment: fixed;
  font-feature-settings: "cv11", "ss01", "ss03";
}
body.no-scroll { overflow: hidden; }

.mono, .gost-plate, .gost-mini, .spark-num {
  font-family: "JetBrains Mono", "Geist Mono", ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
  font-variant-numeric: tabular-nums;
}

::selection { background: color-mix(in srgb, var(--primary-2) 35%, transparent); color: var(--text-strong); }

/* hide legacy in-page topbar once sidebar chassis is mounted */
body[data-chassis="v3"] .topbar,
body[data-chassis="v3"] header.topbar { display: none !important; }
/* ensure legacy app-shell doesn't fight the new chassis */
body[data-chassis="v3"] .app-shell {
  width: auto !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  display: contents;
}

/* ---------- SIDEBAR / APP CHASSIS ---------- */
.app-frame {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  min-height: 100vh;
}
body[data-nav-collapsed="1"] .app-frame { grid-template-columns: var(--nav-w-collapsed) minmax(0, 1fr); }

.app-nav {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 12px 12px;
  border-right: var(--hairline);
  background: var(--topbar-bg);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  z-index: 30;
}

.app-nav-brand {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 6px 6px 14px;
  border-bottom: var(--hairline);
  margin-bottom: 6px;
}
.app-nav-brand .brand-mark {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--grad-accent);
  color: #0b0f17;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -0.01em;
  box-shadow: 0 6px 18px rgba(91,140,255,0.28);
}
.app-nav-brand .brand-text {
  display: grid; gap: 1px; min-width: 0;
}
.app-nav-brand .brand-text strong {
  font-size: 13px; font-weight: 700; color: var(--text-strong);
  letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-nav-brand .brand-text small {
  font-size: 11px; color: var(--muted);
}

.app-nav-section {
  display: grid; gap: 1px;
  padding-top: 8px;
}
.app-nav-section + .app-nav-section { margin-top: 4px; padding-top: 8px; border-top: var(--hairline); }
.app-nav-section-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 4px 10px 6px;
}

.app-nav-link {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  position: relative;
}
.app-nav-link:hover { background: var(--surface-2); }
.app-nav-link svg { width: 18px; height: 18px; color: var(--muted); }
.app-nav-link[aria-current="page"] {
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  color: var(--text-strong);
  font-weight: 600;
}
.app-nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--grad-accent);
}
.app-nav-link[aria-current="page"] svg { color: var(--primary-2); }
.app-nav-link .nav-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: var(--hairline);
}

.app-nav-bottom {
  margin-top: auto;
  display: grid; gap: 4px;
  padding-top: 8px;
  border-top: var(--hairline);
}
.app-nav-bottom .app-nav-link {
  font-size: 12.5px;
  color: var(--muted);
}

body[data-nav-collapsed="1"] .app-nav-brand { grid-template-columns: 36px; }
body[data-nav-collapsed="1"] .app-nav-brand .brand-text,
body[data-nav-collapsed="1"] .app-nav-section-title,
body[data-nav-collapsed="1"] .app-nav-link span,
body[data-nav-collapsed="1"] .app-nav-link .nav-badge { display: none; }
body[data-nav-collapsed="1"] .app-nav-link {
  grid-template-columns: 18px;
  justify-content: center;
  padding: 9px 0;
}

.app-nav-toggle {
  background: transparent;
  border: var(--hairline);
  color: var(--muted);
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.app-nav-toggle:hover { background: var(--surface-2); color: var(--text); }
.app-nav-toggle svg { width: 14px; height: 14px; }
body[data-nav-collapsed="1"] .app-nav-toggle span { display: none; }

/* mobile: off-canvas */
.app-nav-mobile-trigger {
  display: none;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: var(--hairline);
  background: var(--surface-2);
  color: var(--text);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.app-nav-mobile-trigger svg { width: 20px; height: 20px; }

@media (max-width: 1024px) {
  .app-frame { grid-template-columns: minmax(0, 1fr); }
  body[data-nav-collapsed="1"] .app-frame { grid-template-columns: minmax(0, 1fr); }
  .app-nav {
    position: fixed; top: 0; left: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease);
    box-shadow: 0 24px 60px rgba(0,0,0,0.4);
  }
  body[data-nav-open="1"] .app-nav { transform: translateX(0); }
  body[data-nav-open="1"]::after {
    content: "";
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(2px);
    z-index: 25;
  }
  .app-nav-mobile-trigger { display: inline-flex; }
}

/* ---------- APP MAIN AREA ---------- */
.app-main {
  display: grid;
  gap: 20px;
  align-content: start;
  align-items: start;
  padding: 20px clamp(16px, 2.4vw, 32px) 40px;
  min-width: 0;
}
.app-main > * {
  align-self: start;
  min-width: 0;
}

/* page header */
.page-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 14px;
  padding: 16px 18px;
  border: var(--hairline);
  border-radius: var(--r-card);
  background: var(--topbar-bg);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow-card);
  position: sticky;
  top: 8px;
  z-index: 20;
  min-height: 0;
  height: auto;
  margin: 0;
}
.page-header .page-title {
  display: grid; gap: 4px; min-width: 0;
}
.page-header .eyebrow {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.page-header h1 {
  margin: 0;
  font-size: clamp(18px, 2vw, 22px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text-strong);
  text-wrap: balance;
}
.page-header .page-sub {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  text-wrap: pretty;
}
.page-header .page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 720px) {
  .page-header { grid-template-columns: 1fr; align-items: stretch; padding: 12px 14px; }
  .page-header .page-actions { justify-content: flex-start; }
}

/* ---------- COMMAND PALETTE ---------- */
.cmdk-overlay {
  position: fixed; inset: 0;
  z-index: 60;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  align-items: start;
  justify-items: center;
  padding-top: clamp(40px, 12vh, 120px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms var(--ease);
}
.cmdk-overlay[data-open="1"] {
  opacity: 1;
  pointer-events: auto;
}
.cmdk-modal {
  width: min(640px, calc(100% - 32px));
  background: var(--surface);
  border: var(--hairline);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.45);
  overflow: hidden;
  transform: translateY(8px);
  transition: transform 200ms var(--ease);
}
.cmdk-overlay[data-open="1"] .cmdk-modal { transform: translateY(0); }
.cmdk-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: var(--hairline);
}
.cmdk-input-wrap svg { width: 18px; height: 18px; color: var(--muted); }
.cmdk-input {
  flex: 1;
  appearance: none;
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 15px;
  color: var(--text-strong);
  padding: 4px 0;
}
.cmdk-input::placeholder { color: var(--muted); }
.cmdk-list {
  max-height: min(60vh, 480px);
  overflow: auto;
  padding: 6px;
  display: grid;
  gap: 1px;
}
.cmdk-group-title {
  padding: 8px 10px 4px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.cmdk-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
}
.cmdk-item svg { width: 16px; height: 16px; color: var(--muted); }
.cmdk-item.is-active, .cmdk-item:hover {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  color: var(--text-strong);
}
.cmdk-item.is-active svg, .cmdk-item:hover svg { color: var(--primary-2); }
.cmdk-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.cmdk-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: var(--hairline);
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--muted);
}
.cmdk-foot .kbd-row { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- KBD chips ---------- */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 1px 6px;
  border: var(--hairline);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}

/* ---------- TOAST ---------- */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 70;
  display: grid;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
}
.toast {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 18px;
  align-items: start;
  gap: 12px;
  padding: 12px 14px;
  border: var(--hairline);
  border-left: 3px solid var(--muted);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 40px rgba(0,0,0,0.32);
  font-size: 13px;
  color: var(--text);
  animation: toast-in 220ms var(--ease) both;
  backdrop-filter: blur(10px);
}
.toast[data-leaving="1"] { animation: toast-out 180ms var(--ease) forwards; }
.toast .toast-msg { line-height: 1.45; word-break: break-word; }
.toast .toast-close {
  appearance: none; background: transparent; border: 0; color: var(--muted);
  cursor: pointer; padding: 0;
}
.toast svg { width: 18px; height: 18px; flex: 0 0 auto; }
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-success svg { color: var(--success); }
.toast.toast-error { border-left-color: var(--danger); }
.toast.toast-error svg { color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-warning svg { color: var(--warning); }
.toast.toast-info { border-left-color: var(--info); }
.toast.toast-info svg { color: var(--info); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(20px) scale(0.96); }
}

/* ---------- ГОСТ PLATE VISUAL ---------- */
.gost-plate {
  display: inline-grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: var(--plate-bg);
  color: var(--plate-ink);
  border: 2px solid var(--plate-border);
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0.04em;
  overflow: hidden;
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace;
  font-stretch: condensed;
  position: relative;
  min-width: 0;
}
.gost-plate .gp-main {
  padding: 8px 14px 6px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gost-plate .gp-region {
  display: grid;
  grid-template-rows: 1fr auto;
  border-left: 2px solid var(--plate-border);
  padding: 0 10px;
  min-width: 56px;
  background: var(--plate-bg);
}
.gost-plate .gp-region .gp-num {
  font-size: clamp(18px, 2.4vw, 26px);
  align-self: center;
  text-align: center;
  letter-spacing: 0.02em;
}
.gost-plate .gp-region .gp-flag {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  height: 6px;
  margin: 2px 0 4px;
}
.gost-plate .gp-region .gp-flag span:nth-child(1) { background: #ffffff; border-bottom: 1px solid #ccc; }
.gost-plate .gp-region .gp-flag span:nth-child(2) { background: #0033a0; }
.gost-plate .gp-region .gp-flag span:nth-child(3) { background: #d52b1e; }
.gost-plate .gp-region .gp-rus {
  font-size: 9px;
  font-weight: 700;
  text-align: center;
  color: #333;
  letter-spacing: 0.1em;
  margin-bottom: 2px;
}
.gost-plate.gost-empty {
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  color: var(--muted);
  border-color: var(--line-strong);
}
.gost-plate.gost-empty .gp-region { background: transparent; border-color: var(--line-strong); }
.gost-plate.gost-confirmed {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--success) 35%, transparent), 0 0 40px color-mix(in srgb, var(--success) 25%, transparent);
}
.gost-plate.gost-candidate {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--warning) 35%, transparent), 0 0 30px color-mix(in srgb, var(--warning) 20%, transparent);
}
.gost-plate.gost-scanning::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(91,140,255,0.18), transparent);
  background-size: 200% 100%;
  animation: gost-sweep 1.6s var(--ease) infinite;
  pointer-events: none;
}
@keyframes gost-sweep {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* mini-plate for log tables */
.gost-mini {
  display: inline-grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  background: var(--plate-bg);
  color: var(--plate-ink);
  border: 1.5px solid var(--plate-border);
  border-radius: 5px;
  font-weight: 800;
  font-size: 13px;
  line-height: 1;
  min-width: 0;
  vertical-align: middle;
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace;
  letter-spacing: 0.04em;
  overflow: hidden;
}
.gost-mini .gpm-main { padding: 4px 8px 3px; }
.gost-mini .gpm-region {
  border-left: 1.5px solid var(--plate-border);
  padding: 4px 6px 3px;
  min-width: 28px;
  text-align: center;
  font-size: 11px;
}

/* ---------- SPARKLINE ---------- */
.spark {
  display: inline-block;
  vertical-align: middle;
  width: 72px;
  height: 22px;
  overflow: hidden;
}
.spark svg { width: 100%; height: 100%; display: block; }
.spark-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.spark-card {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: var(--hairline);
  background: var(--surface-2);
}
.spark-card dt {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.spark-card dd {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-strong);
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

/* ---------- LEGACY (.topbar, .panel, .btn, .icon-btn) compat ---------- */
.app-shell {
  width: min(1480px, calc(100vw - 48px));
  margin: 24px auto;
  display: grid;
  gap: 24px;
}

.topbar, .panel {
  border: 1px solid var(--line);
  background: var(--topbar-bg);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.panel {
  background: var(--surface);
  border-radius: var(--r-card);
}

.topbar {
  min-height: 72px;
  border-radius: var(--r-card);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: nowrap;
}

.brand { display: grid; grid-template-columns: 42px minmax(260px, 520px); align-items: center; gap: 14px; min-width: 0; }
.brand-mark { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--grad-accent); color: #fff; font-weight: 800; box-shadow: 0 6px 18px rgba(91,140,255,0.25); }
.brand h1 { margin: 0; font-size: clamp(20px, 2vw, 26px); font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; color: var(--text-strong); }
.brand p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--r-input);
  padding: 9px 14px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  background: var(--grad-accent);
  color: var(--primary-ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(91,140,255,0.22);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn[disabled] { opacity: 0.55; cursor: progress; transform: none; box-shadow: none; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
  box-shadow: none;
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line-strong); }

.btn.active {
  background: var(--grad-accent);
  color: var(--primary-ink);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(91,140,255,0.25);
}

.icon-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  width: 40px; height: 40px;
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--r-input);
  cursor: pointer;
  padding: 0;
  box-shadow: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--line-strong); }
.icon-btn svg { width: 18px; height: 18px; }

.panel-header { padding: 16px 18px; border-bottom: var(--hairline); }
.panel-body { padding: 18px; }

/* ---------- FORMS / CONTROLS ----------
   Keep control primitives here so page-specific input rules do not distort
   checkboxes, switches, or compact boolean settings.
*/
input[type="checkbox"] {
  appearance: auto;
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
  max-width: 18px !important;
  max-height: 18px !important;
  flex: 0 0 18px;
  padding: 0 !important;
  margin: 0;
  border-radius: 4px;
  accent-color: var(--primary-2);
  box-shadow: none;
}

.switch,
.check-row {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 28px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: 0;
}

.switch input[type="checkbox"],
.check-row input[type="checkbox"] {
  align-self: center;
}

table { color: var(--text); border-collapse: collapse; width: 100%; }
th, td { border-bottom: var(--hairline); padding: 10px 12px; text-align: left; }
th { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border: var(--hairline);
  border-radius: var(--r-pill);
  padding: 3px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}
.chip.ok, .status.ok { color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); background: var(--success-soft); }
.chip.bad, .status.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: var(--danger-soft); }
.chip.warn, .status.warn { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 35%, transparent); background: var(--warning-soft); }

.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); flex: 0 0 auto; display: inline-block; margin-right: 6px; vertical-align: middle; }
.status.ok::before { background: var(--success); animation: pulse-dot 1.8s ease-in-out infinite; }
.status.bad::before { background: var(--danger); }
.status.warn::before { background: var(--warning); }
@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.8); opacity: 0.6; }
}

/* ---------- TABS ---------- */
.tab-bar {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--surface-2);
  border: var(--hairline);
  border-radius: 12px;
  overflow-x: auto;
  scrollbar-width: thin;
  flex-wrap: nowrap;
}
.tab-bar::-webkit-scrollbar { height: 4px; }
.tab-bar::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
.tab-btn {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all var(--dur) var(--ease);
  min-height: 32px;
}
.tab-btn svg { width: 14px; height: 14px; }
.tab-btn:hover { color: var(--text); }
.tab-btn[aria-selected="true"] {
  color: var(--primary-ink);
  background: var(--grad-accent);
  box-shadow: 0 4px 14px rgba(91,140,255,0.22);
}

/* ---------- VIEW TRANSITIONS (best-effort, MPA) ---------- */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) {
  animation-duration: 220ms;
  animation-timing-function: var(--ease);
}

/* ---------- A11Y / FOCUS ---------- */
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.app-nav-link:focus-visible, .cmdk-item:focus-visible, .tab-btn:focus-visible { box-shadow: var(--ring); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- PAGE HELP ---------- */
.page-help-button svg { width: 17px; height: 17px; }
body.help-open { overflow: hidden; }
.help-overlay {
  position: fixed; inset: 0; z-index: 120;
  display: grid; place-items: center;
  padding: 24px;
  background: color-mix(in srgb, #02050b 78%, transparent);
  backdrop-filter: blur(4px);
}
.help-overlay[hidden] { display: none; }
.help-dialog {
  width: min(1040px, 100%);
  max-height: min(900px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0,0,0,.42);
}
.help-header {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 20px 22px 16px;
  border-bottom: var(--hairline);
}
.help-header h2 { margin: 4px 0 0; font-size: 22px; letter-spacing: 0; }
.help-close svg { width: 18px; height: 18px; }
.help-search-wrap {
  display: grid; gap: 7px;
  padding: 14px 22px;
  border-bottom: var(--hairline);
  background: var(--surface-2);
}
.help-search-wrap label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0; }
.help-search-wrap input { width: 100%; }
.help-body { overflow: auto; padding: 20px 22px 28px; }
.help-intro { margin: 0 0 16px; color: var(--text); line-height: 1.65; }
.help-legend {
  display: grid; grid-template-columns: auto minmax(120px, 1fr) auto minmax(120px, 1fr) auto minmax(120px, 1fr);
  gap: 8px 10px; align-items: center;
  padding: 12px 0 18px;
  color: var(--muted); font-size: 12px;
}
.help-state {
  display: inline-flex; align-items: center; width: max-content;
  padding: 3px 8px; border-radius: var(--r-pill);
  border: 1px solid var(--line); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0;
}
.help-state.active { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.help-state.partial { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); }
.help-state.legacy { color: var(--muted); background: var(--surface-2); }
.help-section { padding: 20px 0 0; border-top: var(--hairline); }
.help-section + .help-section { margin-top: 22px; }
.help-section h3 { margin: 0 0 12px; font-size: 16px; letter-spacing: 0; }
.help-items { display: grid; }
.help-item { padding: 15px 0; border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent); }
.help-item:first-child { border-top: 0; }
.help-item-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.help-item h4 { margin: 0; font-size: 14px; letter-spacing: 0; }
.help-item p { margin: 7px 0 9px; color: var(--text); font-size: 13px; line-height: 1.55; }
.help-item dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.help-item dl > div { min-width: 0; }
.help-item dt { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0; }
.help-item dd { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.help-empty { padding: 36px 0; color: var(--muted); text-align: center; }
@media (max-width: 760px) {
  .help-overlay { padding: 0; }
  .help-dialog { width: 100%; max-height: 100vh; height: 100vh; border: 0; border-radius: 0; }
  .help-header, .help-search-wrap, .help-body { padding-left: 16px; padding-right: 16px; }
  .help-legend { grid-template-columns: auto 1fr; }
  .help-item dl { grid-template-columns: 1fr; }
}

/* ---------- LEGACY topbar override when chassis active ---------- */
@media (max-width: 1120px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { justify-content: flex-start; }
}
@media (max-width: 720px) {
  .app-shell { width: min(100% - 24px, 1480px); margin: 16px auto; }
  .brand { grid-template-columns: 42px minmax(0, 1fr); }
}
