:root {
  --bg: #e9ecee;
  --bg-sidebar: #e3e8ea;
  --bg-elevated: #f7f8f9;
  --bg-card: #f4f6f7;
  --bg-hover: color-mix(in srgb, var(--text) 5%, var(--bg-card));
  --bg-feed: #1c2226;
  --border: rgba(31, 37, 43, 0.07);
  --border-strong: rgba(31, 37, 43, 0.12);
  --text: #1f252b;
  --muted: #4a545c;
  --faint: #5c666e;
  --steel: #4a545c;
  --idle: #5c666e;
  --brand: #0f5c68;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, transparent);
  --brand-hover: color-mix(in srgb, var(--brand) 82%, #000);
  --on-brand: #f4f8f8;
  --live: #1f7a4a;
  --live-soft: color-mix(in srgb, var(--live) 14%, transparent);
  --rec: var(--live);
  --rec-dim: var(--live-soft);
  --rec-ring: color-mix(in srgb, var(--live) 28%, transparent);
  --ok: #1f7a4a;
  --ok-dim: color-mix(in srgb, var(--ok) 12%, transparent);
  --ok-hover: color-mix(in srgb, var(--ok) 82%, #000);
  --on-ok: #f4f8f8;
  --warn: #7a5c14;
  --warn-soft: color-mix(in srgb, var(--warn) 14%, transparent);
  --danger: #b03a3a;
  --danger-dim: color-mix(in srgb, var(--danger) 12%, transparent);
  --info: #4a545c;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 8px 20px rgba(31, 37, 43, 0.06);
  --shadow-hover: 0 12px 24px rgba(31, 37, 43, 0.1);
  --shadow-inset: inset 0 0 0 1px rgba(0, 0, 0, 0.18), inset 0 18px 36px rgba(0, 0, 0, 0.22);
  --ease: 180ms ease;
  --touch: 40px;
  --sidebar-w: 240px;
  --header-h: 64px;
  --nav-offset: 0px;
  --font: Inter, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --scroll-track: transparent;
  --scroll-thumb: color-mix(in srgb, var(--muted) 35%, transparent);
  --scroll-thumb-hover: color-mix(in srgb, var(--muted) 50%, transparent);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color-scheme: light;
}

html {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
  overflow-x: hidden;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background-color: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: var(--scroll-thumb-hover);
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: none;
  box-shadow: 8px 0 24px rgba(31, 37, 43, 0.05);
  padding: 18px 0 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 18px 16px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--on-brand);
}

.brand h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: none;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 10px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--touch);
  padding: 8px 12px 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}

.nav a:hover:not(.active) {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 4%, transparent);
}

.nav a.active:hover {
  background: var(--brand-soft);
}

.nav a.active {
  background: var(--brand-soft);
  color: var(--brand);
  border-left-color: var(--brand);
  font-weight: 600;
}

.nav-ic,
.empty-ic {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav .ch {
  display: none;
}

.nav .badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  display: inline-grid;
  place-items: center;
}

.nav .badge:empty,
.nav .badge[data-count="0"] {
  display: none;
}

.sidebar-foot {
  flex-shrink: 0;
  margin: 0;
  padding: 14px 18px 18px;
  background: color-mix(in srgb, var(--bg) 55%, var(--bg-sidebar));
  box-shadow: 0 -12px 20px rgba(31, 37, 43, 0.04);
  font-size: 12px;
  color: var(--muted);
}

.sidebar-foot strong {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 4px;
}

.sidebar-foot-copy {
  display: block;
  color: var(--muted);
  line-height: 1.4;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--idle);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--idle) 18%, transparent);
}

.sidebar-foot.is-online .status-dot {
  background: var(--live);
  box-shadow: 0 0 0 3px var(--live-soft);
}

.sidebar-foot.is-offline .status-dot {
  background: var(--idle);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--idle) 18%, transparent);
}

.sidebar-foot.is-online strong {
  color: var(--live);
}

.sidebar-foot.is-offline strong {
  color: var(--muted);
}

.main {
  min-width: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: var(--header-h);
  height: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 14px 24px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar > div:first-child {
  min-width: 0;
  flex: 1 1 160px;
}

.topbar h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

.topbar .sub {
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  margin-top: 4px;
}

.clock {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex: 1 1 auto;
}

.control-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.control-split {
  width: 1px;
  height: 22px;
  margin: 0 6px;
  background: var(--border-strong);
  align-self: center;
}

.btn,
.ctrl-arm {
  appearance: none;
  min-height: var(--touch);
  min-width: var(--touch);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: none;
  transition: background var(--ease), border-color var(--ease), color var(--ease), box-shadow var(--ease), transform var(--ease);
}

.btn:hover,
.ctrl-arm:hover {
  background: var(--bg-hover);
  border-color: color-mix(in srgb, var(--text) 22%, transparent);
}

.btn:active,
.ctrl-arm:active {
  transform: translateY(1px);
}

.btn.primary,
.btn.ok {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
}

.btn.primary:hover,
.btn.ok:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--muted);
}

.btn.ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.btn.btn-text {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.btn.btn-text:hover {
  background: var(--bg-hover);
}

.btn.btn-text.danger,
.btn.danger {
  border-color: transparent;
  color: var(--danger);
  background: transparent;
}

.btn.danger {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

.btn.btn-text.danger:hover,
.btn.danger:hover {
  background: var(--danger-dim);
  color: var(--danger);
}

.btn.success {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--on-ok);
  font-weight: 600;
}

.btn.success:hover {
  background: var(--ok-hover);
  border-color: var(--ok-hover);
}

.ctrl-arm {
  font-family: var(--font);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
}

.ctrl-arm::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--on-brand) 70%, transparent);
}

.ctrl-arm:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: var(--on-brand);
}

.ctrl-arm.is-armed {
  background: var(--live);
  border-color: var(--live);
  color: var(--on-ok);
}

.ctrl-arm.is-armed::before {
  background: var(--on-ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--on-ok) 25%, transparent);
}

.ctrl-arm.is-armed:hover {
  background: var(--ok-hover);
  border-color: var(--ok-hover);
}

.ctrl-pause {
  background: transparent;
  font-weight: 500;
}

.content {
  padding: 8px 24px 40px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  padding-bottom: max(40px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-width: 0;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  border: none;
  background: transparent;
}

.readout-item {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
  background: var(--bg-card);
  box-shadow: var(--shadow);
  transition: box-shadow var(--ease), transform var(--ease);
}

.readout-item:hover {
  box-shadow: var(--shadow-hover);
}

.readout-item.warn {
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
  background: color-mix(in srgb, var(--warn-soft) 55%, var(--bg-card));
}

.readout-item.is-idle {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--warn) 40%, var(--border-strong));
  background: color-mix(in srgb, var(--bg) 40%, var(--bg-card));
  box-shadow: none;
}

.readout-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: -0.01em;
  text-transform: none;
  font-weight: 500;
}

.readout-value {
  display: block;
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}

.readout-idle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: none;
  font-family: var(--font);
  font-weight: 500;
  color: var(--warn);
}

.readout-idle .empty-ic {
  width: 14px;
  height: 14px;
}

.readout-item.is-idle .readout-value {
  color: var(--faint);
}

.readout-item.warn .readout-value {
  color: var(--warn);
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 24px;
}

.grid-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.feed-col {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.grid-split .feed-col > .card-live {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.grid-split .card-live .card-head {
  min-height: 44px;
  padding-left: 0;
  padding-right: 0;
  box-sizing: border-box;
}

.grid-split .camera {
  width: 100%;
  max-width: none;
  margin-inline: 0;
  align-self: stretch;
}

/* Keep both feed titles flush with the video frame edge */
.grid-split .feed-col > .card-live > .camera {
  margin-left: 0;
  margin-right: 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
  transition: box-shadow var(--ease);
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

.card-live {
  background: transparent;
  border: none;
  box-shadow: none;
  overflow: visible;
}

.card-live:hover {
  box-shadow: none;
}

.card-live .card-head,
.card-live .cam-actions {
  background: transparent;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 12px;
  border-bottom: none;
  background: transparent;
}

.section-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.015em;
  text-transform: none;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
  text-transform: none;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-live .card-head h3 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}

.card-head-title {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
  overflow: visible;
  text-overflow: unset;
  white-space: normal;
}

.cam-title-label {
  flex-shrink: 0;
}

.card-head-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn.cam-log {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  padding: 8px 12px;
  min-height: var(--touch);
  white-space: nowrap;
  background: transparent;
  color: var(--muted);
  border-color: var(--border-strong);
}

.btn.cam-fs {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 6;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  padding: 8px 12px;
  min-height: 36px;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius-sm);
  background: rgba(12, 16, 20, 0.62);
  color: #f4f6f7;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
}

.btn.cam-fs:hover {
  background: rgba(12, 16, 20, 0.82);
  border-color: rgba(255, 255, 255, 0.45);
  color: #fff;
}

.btn.cam-fs:active {
  transform: scale(0.98);
}

.cam-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 4px 0;
  border-top: none;
  background: transparent;
}

.cam-actions-hint {
  margin-right: auto;
  font-size: 12px;
  color: var(--muted);
}

.cam-actions .btn {
  padding: 8px 12px;
}

.status-alert {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--warn);
}

.status-alert::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
}

.data-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
}

.dashboard-vehicle-feed {
  position: relative;
}

.dashboard-vehicle-feed .camera-lane {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.38s ease, visibility 0.38s ease;
}

.dashboard-vehicle-feed .camera-lane .plate-readout {
  z-index: 7;
}

.dashboard-vehicle-feed .camera-lane.is-active {
  visibility: visible;
  opacity: 1;
  z-index: 1;
}

.dashboard-vehicle-feed .camera-lane.is-hidden {
  visibility: hidden;
  opacity: 0;
  z-index: 0;
}

.cam-lane-toggle {
  position: relative;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  isolation: isolate;
  flex-shrink: 0;
}

.cam-lane-toggle.is-switching {
  animation: cam-lane-pop 0.38s cubic-bezier(0.34, 1.3, 0.64, 1);
}

.cam-lane-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border-radius: 999px;
  background: var(--bg-card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(255, 255, 255, 0.06);
  transition: transform 0.32s cubic-bezier(0.34, 1.2, 0.64, 1);
  z-index: 0;
}

.cam-lane-toggle[data-lane="out"] .cam-lane-thumb {
  transform: translateX(100%);
}

.cam-lane-opt {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  padding: 5px 14px;
  min-width: 52px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.24s ease, transform 0.24s ease;
}

.cam-lane-opt:hover {
  color: var(--text-soft, var(--text));
}

.cam-lane-opt.is-active {
  color: var(--text);
}

.cam-lane-opt.is-active:active {
  transform: scale(0.96);
}

@keyframes cam-lane-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.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;
}

.vehicle-lanes .feed-col {
  gap: 16px;
}

.camera {
  position: relative;
  background: var(--bg-feed);
  aspect-ratio: 16 / 9;
  width: min(100%, calc(var(--cam-max, 70vh) * 16 / 9));
  max-height: var(--cam-max, calc(100dvh - 22rem));
  margin-inline: auto;
  overflow: hidden;
  border-radius: var(--radius);
  box-shadow: var(--shadow), var(--shadow-inset);
}

.camera video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  background: var(--bg-feed);
  filter: contrast(1.02) saturate(0.94);
}

.camera.large {
  aspect-ratio: 16 / 9;
}

.cam-vignette {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 1;
  background: radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.28) 100%);
}

.cam-scrim {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 4;
  background:
    linear-gradient(180deg, rgba(8, 12, 14, 0.62) 0%, rgba(8, 12, 14, 0.18) 28%, transparent 42%),
    linear-gradient(0deg, rgba(8, 12, 14, 0.5) 0%, transparent 26%);
}

.cam-reticle {
  pointer-events: none;
  position: absolute;
  inset: 10px;
  z-index: 3;
}

.cam-reticle i {
  position: absolute;
  width: 16px;
  height: 16px;
  border-color: rgba(255, 255, 255, 0.45);
  border-style: solid;
  border-radius: 1px;
}

.cam-reticle .tl { top: 0; left: 0; border-width: 1px 0 0 1px; }
.cam-reticle .tr { top: 0; right: 0; border-width: 1px 1px 0 0; }
.cam-reticle .bl { bottom: 0; left: 0; border-width: 0 0 1px 1px; }
.cam-reticle .br { bottom: 0; right: 0; border-width: 0 1px 1px 0; }

.cam-osd {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
}

.osd-id {
  position: absolute;
  top: 12px;
  left: 16px;
  max-width: calc(50% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #f4f6f7;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.osd-right {
  position: absolute;
  top: 12px;
  right: 16px;
  max-width: calc(50% - 20px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  text-align: right;
  white-space: nowrap;
}

.cam-live-pill {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.38);
  color: #f4f6f7;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.cam-live-pill.is-on {
  display: inline-flex;
  color: #d8f3e4;
}

.cam-live-pill .rec-dot {
  background: var(--live);
}

.osd-rec {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #f4f6f7;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.osd-rec .rec-dot {
  background: var(--live);
}

.rec-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--live);
  animation: rec-pulse 1.4s ease-in-out infinite;
}

.cam-clock {
  color: #f4f6f7;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

@keyframes rec-pulse {
  50% { opacity: 0.35; }
}

.overlay-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.bbox {
  position: absolute;
  border: 1px solid var(--live);
  border-radius: 2px;
}

.bbox.pop {
  animation: pop 180ms ease-out;
}

.bbox.live {
  animation: none;
  will-change: left, top, width, height;
}

.bbox.unknown {
  border-color: var(--warn);
}

.bbox.plate {
  border-color: var(--live);
}

.bbox.plate span {
  background: var(--live);
  color: var(--on-ok);
}

.plate-readout {
  display: none;
  position: absolute;
  top: 86px;
  right: 16px;
  z-index: 6;
  pointer-events: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 6px 10px 5px;
  background: rgba(12, 16, 18, 0.72);
  border-radius: var(--radius-sm);
}

.plate-readout.is-on {
  display: flex;
}

.plate-readout-k {
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #d8f3e4;
  font-weight: 500;
  font-family: var(--mono);
}

.plate-readout-num {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  color: #f4f6f7;
  letter-spacing: 0.08em;
  line-height: 1.15;
}

.camera.large .plate-readout-num {
  font-size: 22px;
}

.bbox span {
  position: absolute;
  left: -1px;
  top: -20px;
  background: var(--live);
  color: var(--on-ok);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
  font-family: var(--mono);
}

.bbox.unknown span {
  background: var(--warn);
  color: #fff8e8;
}

.bbox.out span {
  background: var(--ok);
  color: var(--on-ok);
}

@keyframes pop {
  from { transform: scale(0.96); opacity: 0; }
}

/* Active table theme: PALETTE 2 (snapshot of palette 1 in css/table-palette-1.css) */
.table-wrap {
  overflow: auto;
  max-height: min(420px, 55dvh);
  background: #ffffff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid #e2e8f0;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: #ffffff;
}

th,
td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  border-left: none;
  border-right: none;
  border-top: none;
  white-space: nowrap;
}

tbody tr {
  background: #ffffff;
  transition: background 120ms ease;
}

tbody tr:nth-child(even) {
  background: #fafafa;
}

tbody tr:hover {
  background: #f1f5f9;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr.is-newest {
  animation: row-pulse 1.6s ease-out 1;
}

th {
  color: #475569;
  font-size: 13px;
  letter-spacing: -0.01em;
  text-transform: none;
  font-weight: 700;
  position: sticky;
  top: 0;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  z-index: 1;
}

td.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.plate-chip,
.mono-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #0f172a;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.3;
}

.plate-chip .dir-dot {
  margin-right: 0;
}

.col-gate {
  color: #94a3b8;
  font-size: 12px;
}

.lane-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lane-badge.in {
  color: #16a34a;
  background: #dcfce7;
}

.lane-badge.out {
  color: #d97706;
  background: #fef3c7;
}

.lane-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.dir-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  flex-shrink: 0;
}

.dir-dot.in {
  background: #16a34a;
  box-shadow: 0 0 0 3px #dcfce7;
}

.dir-dot.out {
  background: #d97706;
  box-shadow: 0 0 0 3px #fef3c7;
}

@keyframes row-pulse {
  0% {
    background-color: color-mix(in srgb, #16a34a 16%, #ffffff);
    box-shadow: inset 3px 0 0 #16a34a;
  }
  100% {
    box-shadow: inset 3px 0 0 transparent;
  }
}

.dir {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.dir.in {
  background: #dcfce7;
  color: #16a34a;
}

.dir.out {
  background: #fef3c7;
  color: #d97706;
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

td:has(.empty-state),
td:has(.empty-idle) {
  padding: 0;
  border-bottom: none;
  background: transparent;
}

.empty-state,
.empty-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 168px;
  padding: 32px 20px;
  text-align: center;
}

.empty-state .empty-ic,
.empty-idle .empty-ic {
  width: 28px;
  height: 28px;
  color: var(--warn);
  margin-bottom: 4px;
}

.empty-state strong,
.empty-idle .empty-t {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.empty-state p,
.empty-idle .empty-k {
  margin: 0;
  max-width: 280px;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.activity {
  max-height: 420px;
  overflow: auto;
}

.activity-item {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  background: var(--muted);
}

.dot.vehicle { background: var(--brand); }
.dot.face { background: var(--ok); }
.dot.unknown { background: var(--warn); }
.dot.enroll { background: var(--steel); }

.activity-item time {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.face-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  padding: 0;
}

.face-grid:has(.empty-state),
.face-grid:has(.empty-idle) {
  display: block;
  padding: 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.face-grid .empty-state,
.face-grid .empty-idle {
  min-height: 280px;
  width: 100%;
}

.face-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow var(--ease), transform var(--ease);
}

.face-card:hover {
  box-shadow: var(--shadow-hover);
}

.face-thumb {
  height: 220px;
  background: var(--bg-card);
  position: relative;
  overflow: hidden;
}

.face-count {
  position: absolute;
  right: 10px;
  bottom: 10px;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(12, 16, 18, 0.72);
  color: #f4f6f7;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.face-thumb canvas,
.face-thumb img,
.face-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.thumb-missing {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}

.modal-face {
  width: 100%;
  height: 240px;
  object-fit: cover;
  object-position: center top;
  border-radius: var(--radius);
  margin-bottom: 14px;
  background: var(--bg-card);
}

.face-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.face-body h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.face-body p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.face-body .face-hits {
  color: var(--text);
  font-weight: 600;
}

.modal-back {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--text) 38%, transparent);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-back.open {
  display: flex;
}

.modal {
  width: min(420px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 40px rgba(31, 37, 43, 0.16);
  padding: 22px;
}

.modal h3 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-transform: none;
}

.modal p.hint {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: none;
  font-weight: 500;
  color: var(--muted);
}

.field input {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: var(--touch);
  color-scheme: light;
  font-family: var(--mono);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover);
  z-index: 60;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 180ms ease;
  font-size: 13px;
}

.toast.show {
  opacity: 1;
  transform: none;
}

.note {
  font-size: 13px;
  color: var(--muted);
  padding: 0 4px;
  margin: 0;
}

.card:fullscreen,
.card:-webkit-full-screen {
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
  border: none;
  background: var(--bg-feed);
  display: flex;
  flex-direction: column;
  box-shadow: none;
}

.card:fullscreen .card-head,
.card:-webkit-full-screen .card-head {
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg-feed) 88%, #fff);
}

.card:fullscreen .camera,
.card:-webkit-full-screen .camera,
.card:fullscreen .camera.large,
.card:-webkit-full-screen .camera.large {
  flex: 1;
  width: 100%;
  height: auto;
  aspect-ratio: auto;
  max-height: none;
  min-height: 0;
  border-radius: 0;
  box-shadow: none;
}

.card:fullscreen .cam-actions,
.card:-webkit-full-screen .cam-actions {
  flex-shrink: 0;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    padding: 10px 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    box-shadow: 0 8px 20px rgba(31, 37, 43, 0.06);
    overflow: visible;
  }

  .brand {
    padding: 0 8px 0 0;
    flex: 0 0 auto;
  }

  .nav {
    flex: 1 1 220px;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav a {
    flex: 1 0 auto;
    white-space: nowrap;
    justify-content: center;
    padding: 8px 12px;
    border-left: none;
    border-bottom: 3px solid transparent;
  }

  .nav a.active {
    box-shadow: none;
    border-left-color: transparent;
    border-bottom-color: var(--brand);
  }

  .sidebar-foot {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    max-width: 220px;
    box-shadow: none;
  }

  .sidebar-foot-copy {
    display: none;
  }

  .topbar {
    top: var(--nav-offset, 0px);
    flex-wrap: wrap;
    padding: 12px 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .topbar h2 {
    font-size: 22px;
  }

  .content {
    padding: 8px 16px 32px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    gap: 24px;
  }

  .grid-2,
  .grid-split {
    grid-template-columns: 1fr;
  }

  .grid-split .camera,
  .camera,
  .camera.large {
    width: min(100%, calc(min(var(--cam-max, 70vh), 52vh) * 16 / 9));
    max-height: min(var(--cam-max, 70vh), 52vh);
  }
}

@media (max-width: 720px) {
  .topbar h2 {
    font-size: 20px;
  }

  .topbar .sub {
    font-size: 13px;
  }

  .card-head h3,
  .section-head h3,
  .card-live .card-head h3 {
    font-size: 16px;
  }

  .controls {
    width: 100%;
    justify-content: flex-start;
  }

  .clock {
    width: 100%;
    order: -1;
  }

  .btn.btn-text.danger {
    margin-left: 4px;
  }

  .brand p {
    display: none;
  }

  .brand h1 {
    font-size: 12px;
  }

  .nav .ch {
    display: none;
  }

  .readout-value {
    font-size: 24px;
  }

  .cam-osd {
    font-size: 10px;
  }

  .osd-id {
    top: 8px;
    left: 10px;
    max-width: calc(48% - 8px);
  }

  .osd-right {
    top: 8px;
    right: 10px;
    max-width: calc(48% - 8px);
  }

  .plate-readout {
    top: 72px;
    right: 10px;
    padding: 4px 8px 4px;
  }

  .plate-readout-num,
  .camera.large .plate-readout-num {
    font-size: 14px;
  }

  .cam-reticle {
    inset: 6px;
  }

  .cam-reticle i {
    width: 12px;
    height: 12px;
  }

  .card-head {
    padding: 0 2px 10px;
    gap: 8px;
  }

  .cam-actions {
    padding: 8px 2px 0;
  }

  .table-wrap {
    max-height: min(360px, 50dvh);
  }

  .modal-back {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    padding: 16px;
  }

  .modal-actions .btn {
    min-height: 40px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 480px) {
  .sidebar {
    padding: 8px 8px 6px;
  }

  .brand {
    width: 100%;
    padding: 0 4px 4px;
  }

  .nav {
    flex: 1 1 100%;
  }

  .nav a {
    padding: 8px 8px;
    font-size: 12px;
  }

  .sidebar-foot {
    width: 100%;
    max-width: none;
  }

  .topbar {
    padding: 10px 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .content {
    padding: 8px 12px 28px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    gap: 20px;
  }

  .kpis {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .grid-split .camera,
  .camera,
  .camera.large {
    width: min(100%, calc(min(var(--cam-max, 70vh), 46vh) * 16 / 9));
    max-height: min(var(--cam-max, 70vh), 46vh);
  }

  .face-thumb {
    height: 180px;
  }
}

@media (pointer: coarse) {
  .btn,
  .ctrl-arm,
  .nav a {
    min-height: 40px;
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  .sidebar {
    position: relative;
  }

  .topbar {
    top: 0;
  }

  .grid-split .camera,
  .camera,
  .camera.large {
    max-height: 64vh;
    width: min(100%, calc(64vh * 16 / 9));
  }

  .table-wrap {
    max-height: 40vh;
  }
}
