:root {
  --bg: #071015;
  --panel: #0e1b21;
  --panel-2: #13242b;
  --line: #223840;
  --text: #f2f7f5;
  --muted: #8da1a6;
  --accent: #42e8b4;
  --accent-dark: #123e34;
  --danger: #ff7369;
  --danger-dark: #42201f;
  --warning: #ffc966;
  --shadow: 0 18px 45px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 10%, rgba(54, 211, 153, 0.12), transparent 36rem),
    #0a1118;
}
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(100%, 430px);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(15, 25, 35, 0.96);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.35);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 36px; }
.login-brand div { display: grid; gap: 2px; }
.login-brand div span { color: var(--muted); font-size: 13px; }
.login-copy h1 { margin: 8px 0 10px; font-size: 30px; }
.login-copy p { margin: 0 0 26px; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 10px; }
.login-form label { margin-top: 8px; color: var(--muted); font-size: 13px; font-weight: 700; }
.login-form input {
  width: 100%;
  box-sizing: border-box;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0b151e;
  color: var(--text);
  font: inherit;
}
.login-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-message { min-height: 20px; margin: 8px 0 0; color: var(--danger); }
.login-submit { width: 100%; margin-top: 4px; padding: 13px; }
.admin-account { display: flex; align-items: center; gap: 10px; }
.admin-account-name { color: var(--muted); font-size: 13px; }

button, input { font: inherit; }
select { font: inherit; }

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1500px) / 2));
  border-bottom: 1px solid var(--line);
  background: #09151a;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand, .system-state, .metric-row, .decision-line, .input-row {
  display: flex;
  align-items: center;
}

.camera-switcher {
  display: grid;
  gap: 4px;
  min-width: 250px;
}
.camera-switcher span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.camera-switcher select {
  width: 100%;
  min-height: 36px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  outline: none;
  background: #0e1b21;
  color: var(--text);
  cursor: pointer;
}
.camera-switcher select:focus { border-color: var(--accent); }

.brand { gap: 12px; }

.brand-logo {
  width: 52px;
  height: 40px;
  flex: 0 0 auto;
  object-fit: contain;
}
.login-brand .brand-logo { width: 58px; height: 44px; }

.brand div, .system-state div { display: grid; gap: 2px; }
.brand strong { font-size: 16px; letter-spacing: -.02em; }
.brand span:last-child, .system-state span { color: var(--muted); font-size: 12px; }

.system-state { gap: 10px; text-align: right; }
.system-state strong { font-size: 13px; }

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(255, 115, 105, .12);
}
.status-dot.ok { background: var(--accent); box-shadow: 0 0 0 4px rgba(66, 232, 180, .12); }
.status-dot.pending { background: var(--warning); box-shadow: 0 0 0 4px rgba(255, 201, 102, .12); }

.shell {
  width: min(1500px, calc(100% - 48px));
  margin: 28px auto 48px;
}

.hero-grid, .content-grid { display: grid; gap: 20px; }
.hero-grid { grid-template-columns: minmax(0, 2.2fr) minmax(320px, .8fr); }
.content-grid { grid-template-columns: minmax(0, 2fr) minmax(340px, .75fr); margin-top: 20px; align-items: start; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.panel-head {
  min-height: 82px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head.compact { min-height: 76px; }

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; letter-spacing: -.03em; }
h1 { font-size: clamp(20px, 2vw, 28px); }
h2 { font-size: 20px; }

.metric-row { gap: 20px; color: var(--muted); font-size: 12px; }
.metric-row b { color: var(--text); font-variant-numeric: tabular-nums; }

.video-stage {
  position: relative;
  min-height: 360px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #03080a;
}

.video-stage img { width: 100%; height: 100%; display: block; object-fit: contain; }
.video-overlay {
  position: absolute;
  inset: 18px 18px auto 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #dbe7e4;
  font: 600 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-shadow: 0 1px 5px #000;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  background: rgba(7, 16, 21, .78);
  border: 1px solid rgba(255, 255, 255, .16);
  font-size: 10px;
  letter-spacing: .1em;
}
.live-badge i { width: 6px; height: 6px; background: var(--danger); border-radius: 50%; }

.latest-panel { padding: 22px; min-height: 100%; }
.empty-state { min-height: 390px; display: grid; place-content: center; justify-items: center; text-align: center; }
.empty-state p { max-width: 230px; margin: 8px 0 0; color: var(--muted); font-size: 13px; }

.scan-frame {
  width: 112px;
  height: 46px;
  margin-bottom: 30px;
  border: 2px solid var(--line);
  position: relative;
}
.scan-frame::before {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  height: 1px;
  background: var(--accent);
  box-shadow: 0 0 15px var(--accent);
}

.latest-event { padding-top: 24px; }
.hidden { display: none !important; }
.decision-line { justify-content: space-between; color: var(--muted); font-size: 12px; }

.decision {
  padding: 6px 9px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  border: 1px solid currentColor;
}
.decision.open { color: var(--accent); background: var(--accent-dark); }
.decision.deny { color: var(--danger); background: var(--danger-dark); }

.plate-number {
  margin: 28px 0 24px;
  padding: 14px 10px;
  background: #f5f5ef;
  border: 4px solid #111;
  color: #101212;
  text-align: center;
  font: 800 clamp(28px, 4vw, 45px)/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .07em;
  box-shadow: inset 0 0 0 2px #c8c8c0;
}

.latest-stats { margin: 0; display: grid; gap: 0; border-top: 1px solid var(--line); }
.latest-stats div { display: flex; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.latest-stats dt { color: var(--muted); font-size: 12px; }
.latest-stats dd { margin: 0; text-align: right; font-size: 12px; font-weight: 700; }
.latest-snapshot-button {
  width: 100%;
  margin-top: 18px;
  padding: 0;
  border: 1px solid var(--line);
  background: transparent;
  cursor: zoom-in;
}
.latest-snapshot { width: 100%; display: block; }
.latest-snapshot-button:hover, .latest-snapshot-button:focus-visible { border-color: var(--accent); }

.button {
  min-height: 38px;
  border: 1px solid transparent;
  padding: 0 15px;
  color: var(--text);
  cursor: pointer;
  font-weight: 750;
  font-size: 12px;
  transition: background .15s ease, border-color .15s ease;
}
.button.primary { background: var(--accent); color: #06221b; }
.button.primary:hover { background: #71f0c8; }
.button.secondary { background: transparent; border-color: var(--line); }
.button.secondary:hover { border-color: #3e5a63; background: var(--panel-2); }

.event-header, .event-row {
  display: grid;
  grid-template-columns: 84px minmax(120px, 1.2fr) minmax(100px, .8fr) 120px minmax(130px, 1fr);
  align-items: center;
  gap: 14px;
}
.event-header { padding: 11px 20px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; border-bottom: 1px solid var(--line); }
.event-row { min-height: 80px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.event-row:last-child { border-bottom: 0; }
.event-thumb-button {
  width: 72px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: zoom-in;
  overflow: hidden;
}
.event-thumb-button:hover, .event-thumb-button:focus-visible { border-color: var(--accent); }
.event-thumb-button:disabled { cursor: default; }
.event-thumb { width: 100%; height: 100%; display: block; object-fit: cover; }
.event-plate { font: 800 16px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .05em; }
.event-meta { display: block; margin-top: 4px; color: var(--muted); font: 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }
.event-confidence, .event-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.list-empty { padding: 46px 20px; text-align: center; color: var(--muted); font-size: 13px; }

.image-viewer {
  width: min(96vw, 1600px);
  height: min(94vh, 1100px);
  max-width: none;
  max-height: none;
  padding: 0;
  border: 1px solid #3d555e;
  background: #050b0e;
  color: var(--text);
  box-shadow: 0 30px 100px rgba(0, 0, 0, .72);
}
.image-viewer::backdrop { background: rgba(0, 0, 0, .82); backdrop-filter: blur(4px); }
.image-viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.image-viewer-head {
  min-height: 68px;
  padding: 12px 16px 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: #09151a;
}
.image-viewer-head > div:first-child { min-width: 0; display: grid; gap: 4px; }
.image-viewer-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-viewer-head span { color: var(--muted); font-size: 12px; }
.image-viewer-actions { display: flex; align-items: center; gap: 8px; }
.image-viewer-actions .button.selected { border-color: var(--accent); color: var(--accent); }
.frame-counter { min-width: 92px; text-align: center; font-variant-numeric: tabular-nums; }
.panel-actions { display: flex; align-items: center; gap: 8px; }
.event-filters {
  display: grid;
  grid-template-columns: 150px 120px 120px minmax(150px, 1fr) 150px auto;
  align-items: end;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 22, 27, .52);
}
.event-filters label { display: grid; gap: 6px; }
.event-filters label > span { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.event-filters input, .event-filters select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  outline: none;
  background: #09161b;
  color: var(--text);
}
.event-filters input:focus, .event-filters select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(66, 232, 180, .1); }
.event-filter-count { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }
.image-viewer-close {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
}
.image-viewer-close:hover, .image-viewer-close:focus-visible { border-color: var(--danger); color: var(--danger); }
.image-viewer-stage { min-height: 0; display: grid; place-items: center; overflow: auto; padding: 18px; }
.image-viewer-image { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; cursor: zoom-in; }
.image-viewer-image.actual-size { max-width: none; max-height: none; cursor: zoom-out; }
.image-viewer-label {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(180px, 280px) auto auto auto;
  align-items: end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #09151a;
}
.image-viewer-label > div { display: grid; gap: 3px; }
.image-viewer-label label { color: var(--text); font-size: 12px; font-weight: 800; }
.image-viewer-label span { color: var(--muted); font-size: 10px; }
.image-viewer-label .form-message { grid-column: 1 / -1; min-height: 0; margin: 0; }

.allowlist-panel { position: sticky; top: 96px; }
.count { min-width: 30px; text-align: center; color: var(--accent); font: 800 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.allowlist-form { padding: 18px; border-bottom: 1px solid var(--line); }
.allowlist-form label { display: block; margin: 0 0 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.allowlist-form label:not(:first-child) { margin-top: 13px; }
.input-row { gap: 8px; }
input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  outline: none;
  background: #09161b;
  color: var(--text);
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(66, 232, 180, .1); }
.form-message { min-height: 16px; margin: 10px 0 0; color: var(--danger); font-size: 11px; }
.form-message.success { color: var(--accent); }
.allowlist-items { max-height: 410px; overflow: auto; }
.allowlist-item { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.allowlist-item:last-child { border-bottom: 0; }
.allowlist-item strong { font: 800 14px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .05em; }
.allowlist-item span { grid-column: 1; color: var(--muted); font-size: 11px; }
.remove-button { grid-row: 1 / span 2; grid-column: 2; align-self: center; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; }
.remove-button:hover { color: var(--danger); }

@media (max-width: 1050px) {
  .hero-grid, .content-grid { grid-template-columns: 1fr; }
  .latest-panel { min-height: auto; }
  .empty-state { min-height: 250px; }
  .allowlist-panel { position: static; }
  .event-filters { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
}

@media (max-width: 720px) {
  .topbar { padding: 0 16px; }
  .system-state div { display: none; }
  .camera-switcher { min-width: 0; width: 46%; }
  .camera-switcher span { display: none; }
  .shell { width: min(100% - 24px, 1500px); margin-top: 12px; }
  .panel-head { align-items: flex-start; }
  .metric-row { display: none; }
  .video-stage { min-height: 220px; }
  .event-header { display: none; }
  .event-filters { grid-template-columns: 1fr 1fr; padding: 14px 12px; }
  .event-filter-plate { grid-column: 1 / -1; }
  .event-row { grid-template-columns: 72px 1fr auto; gap: 10px 12px; }
  .event-row > :nth-child(4), .event-row > :nth-child(5) { grid-column: 2; }
  .event-row > :nth-child(3) { grid-column: 3; grid-row: 1; }
  .event-row > :nth-child(4) { display: none; }
  .event-row > :nth-child(5) { grid-row: 2; }
  .image-viewer { width: 100vw; height: 100dvh; border: 0; }
  .image-viewer-head { padding: 10px 12px; }
  .image-viewer-actions .button { display: none; }
  .image-viewer-actions .frame-nav { display: inline-flex; }
  .frame-counter { min-width: 72px; }
  .image-viewer-label { grid-template-columns: 1fr auto auto auto; }
  .image-viewer-label > div { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
