:root {
  --bg: #070b14;
  --bg-2: #0b1120;
  --panel: rgba(17, 25, 44, 0.82);
  --panel-line: rgba(94, 118, 169, 0.22);
  --text: #e6ecf8;
  --muted: #8b98b4;
  --accent: #22d3ee;
  --people: #f59e0b;
  --vehicles: #10b981;
  --plates: #ec4899;
  --faces: #8b5cf6;
  --objects: #22d3ee;
  --scene: #94a3b8;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 500px at 15% -5%, rgba(34, 211, 238, 0.08), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(139, 92, 246, 0.09), transparent 55%),
    var(--bg);
}

h1, h2 { font-weight: 650; letter-spacing: 0.01em; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--panel-line);
  background: rgba(7, 11, 20, 0.75); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 4px;
  background: conic-gradient(from 40deg, var(--accent), var(--faces), var(--plates), var(--accent));
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.55);
}
.brand h1 { margin: 0; font-size: 1.15rem; text-transform: uppercase; letter-spacing: 0.14em; }
.brand h1 em { font-style: normal; color: var(--accent); }
.topbar-status { display: flex; gap: 10px; }

.pill {
  padding: 5px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  border: 1px solid var(--panel-line); background: var(--bg-2); color: var(--muted);
}
.pill[data-state="ready"] { color: var(--ok); border-color: rgba(52, 211, 153, 0.4); }
.pill[data-state="loading"] { color: var(--warn); }
.pill[data-state="degraded"], .pill[data-state="error"] { color: var(--err); border-color: rgba(248, 113, 113, 0.4); }
.pill[data-state="stopped"] { color: var(--muted); }

/* ---------- banners & alerts ---------- */
.banner {
  margin: 10px 22px 0; padding: 10px 14px; border-radius: 10px; font-size: 0.86rem;
  background: rgba(251, 191, 36, 0.1); border: 1px solid rgba(251, 191, 36, 0.35); color: var(--warn);
}
.alerts { margin: 10px 22px 0; display: grid; gap: 8px; }
.diagnostic-alert {
  padding: 10px 14px; border-radius: 10px; font-size: 0.86rem;
  background: rgba(248, 113, 113, 0.09); border: 1px solid rgba(248, 113, 113, 0.35); color: #fca5a5;
}

/* ---------- layout ---------- */
.console {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px;
  padding: 18px 22px; align-items: start;
}
@media (max-width: 1080px) { .console { grid-template-columns: 1fr; } }

/* ---------- stage ---------- */
.stage-panel {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
.detect-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.detect-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  font-size: 0.82rem; font-weight: 600; color: var(--muted);
  background: var(--bg-2); border: 1px solid var(--panel-line);
  transition: all 0.15s ease;
}
.detect-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: 0.45; }
.dot-people { color: var(--people); } .dot-vehicles { color: var(--vehicles); }
.dot-plates { color: var(--plates); } .dot-faces { color: var(--faces); }
.dot-objects { color: var(--objects); } .dot-scene { color: var(--scene); }
.detect-chip[data-on="true"] { color: var(--text); border-color: rgba(34, 211, 238, 0.5); background: rgba(34, 211, 238, 0.08); }
.detect-chip[data-on="true"] .dot { opacity: 1; box-shadow: 0 0 8px currentColor; }
.detect-chip:hover { border-color: rgba(34, 211, 238, 0.6); }

.stage { position: relative; border-radius: 12px; overflow: hidden; background: #000; min-height: 320px; }
.stage video, .stage canvas { display: block; width: 100%; height: auto; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage-hud {
  position: absolute; left: 10px; bottom: 10px; display: flex; align-items: baseline; gap: 6px;
  padding: 6px 12px; border-radius: 10px; background: rgba(7, 11, 20, 0.72); backdrop-filter: blur(4px);
  font-family: ui-monospace, monospace; font-size: 0.8rem;
}
.hud-fps { color: var(--accent); font-size: 1.05rem; font-weight: 700; }
.hud-fps-label { color: var(--muted); }
.hud-ocr { margin-left: 12px; color: var(--plates); }

.stage-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.camera-controls { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.camera-controls select {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--panel-line);
  border-radius: 9px; padding: 8px 10px; font-size: 0.84rem; max-width: 230px;
}

.btn {
  padding: 9px 18px; border-radius: 10px; border: 1px solid var(--panel-line);
  font-size: 0.88rem; font-weight: 650; cursor: pointer; color: var(--text); background: var(--bg-2);
  transition: all 0.15s ease;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #22d3ee); color: #04121a; border: none;
  box-shadow: 0 4px 18px rgba(34, 211, 238, 0.35);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); }
.btn-warn { background: rgba(251, 191, 36, 0.12); border-color: rgba(251, 191, 36, 0.4); color: var(--warn); }

.status-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px;
}
.status-item {
  background: var(--bg-2); border: 1px solid var(--panel-line); border-radius: 10px;
  padding: 8px 12px; display: flex; flex-direction: column; gap: 2px;
}
.status-name { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.status-value { font-size: 0.84rem; font-weight: 600; }
.status-value[data-state="ready"] { color: var(--ok); }
.status-value[data-state="loading"] { color: var(--warn); }
.status-value[data-state="error"] { color: var(--err); }

/* ---------- rail ---------- */
.rail { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius);
  padding: 14px 16px;
}
.card h2 { margin: 0 0 10px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.hint {
  display: inline-flex; width: 15px; height: 15px; align-items: center; justify-content: center;
  border-radius: 50%; border: 1px solid var(--panel-line); font-size: 0.65rem; cursor: help; color: var(--muted);
}

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  background: var(--bg-2); border: 1px solid var(--panel-line); border-radius: 10px;
  padding: 8px 10px; text-align: center;
}
.stat span { display: block; font-family: ui-monospace, monospace; font-size: 1.2rem; font-weight: 700; }
.stat label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.stat-people span { color: var(--people); } .stat-vehicles span { color: var(--vehicles); }
.stat-plates span { color: var(--plates); } .stat-faces span { color: var(--faces); }
.stat-objects span { color: var(--objects); }
.scene-labels { margin: 10px 0 0; font-size: 0.78rem; color: var(--muted); line-height: 1.5; }

.card-db .db-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 0.86rem; }
.card-db label { color: var(--muted); }
.db-kind { font-weight: 700; color: var(--ok); text-transform: capitalize; }

.setting { margin-bottom: 14px; }
.setting > label { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 6px; color: var(--text); }
.setting > label span { color: var(--accent); font-family: ui-monospace, monospace; }
.setting input[type="range"] { width: 100%; accent-color: var(--accent); }
.setting input[type="number"] {
  width: 100%; background: var(--bg-2); border: 1px solid var(--panel-line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 0.86rem;
}
.setting-note { margin: 5px 0 0; font-size: 0.72rem; color: var(--muted); }
.toggles { display: grid; gap: 8px; }
.switch { display: flex; align-items: center; gap: 9px; font-size: 0.84rem; cursor: pointer; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

.card-privacy .privacy-list { margin: 0; padding-left: 18px; font-size: 0.78rem; color: var(--muted); line-height: 1.55; }
.card-privacy strong { color: var(--text); }

.card-diag summary { cursor: pointer; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.diag-grid { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.diag-grid div { background: var(--bg-2); border-radius: 8px; padding: 7px 10px; }
.diag-grid label { display: block; font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.diag-grid span { font-size: 0.76rem; font-family: ui-monospace, monospace; word-break: break-word; }

/* ---------- records ---------- */
.records { margin: 6px 22px 20px; background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius); padding: 16px 18px; }
.records-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.records-head h2 { margin: 0; font-size: 1rem; }
.tabs { display: flex; gap: 8px; }
.tab-btn {
  padding: 7px 16px; border-radius: 9px; border: 1px solid var(--panel-line);
  background: var(--bg-2); color: var(--muted); font-weight: 650; font-size: 0.84rem; cursor: pointer;
}
.tab-btn.active { color: var(--text); border-color: rgba(34, 211, 238, 0.55); background: rgba(34, 211, 238, 0.09); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
th {
  text-align: left; padding: 8px 10px; color: var(--muted); font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.09em; border-bottom: 1px solid var(--panel-line);
}
td { padding: 8px 10px; border-bottom: 1px solid rgba(94, 118, 169, 0.12); vertical-align: middle; }
.plate-badge {
  font-family: ui-monospace, monospace; font-weight: 700; letter-spacing: 0.08em;
  background: rgba(236, 72, 153, 0.12); color: var(--plates); border: 1px solid rgba(236, 72, 153, 0.35);
  border-radius: 7px; padding: 3px 9px; display: inline-block;
}
.thumb {
  width: 52px; height: 36px; object-fit: cover; border-radius: 6px; border: 1px solid var(--panel-line);
  cursor: zoom-in; background: var(--bg-2); display: inline-block; margin-right: 4px;
}
.thumb-face { width: 36px; height: 36px; border-radius: 8px; }
.no-photo { color: var(--muted); font-size: 0.72rem; }
.cell-sub { display: block; color: var(--muted); font-size: 0.72rem; }
.empty { text-align: center; color: var(--muted); padding: 18px 0; font-size: 0.86rem; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; }
.pager span { font-size: 0.8rem; color: var(--muted); }

/* ---------- photo modal ---------- */
.photo-modal {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 7, 14, 0.86); backdrop-filter: blur(4px);
}
.photo-modal img { max-width: 92vw; max-height: 86vh; border-radius: 12px; border: 1px solid var(--panel-line); }
.photo-modal button {
  position: absolute; top: 18px; right: 24px; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--panel-line); background: var(--bg-2); color: var(--text); font-size: 1.3rem; cursor: pointer;
}

/* ---------- misc ---------- */
.loading-overlay {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 7, 14, 0.82); backdrop-filter: blur(4px);
}
.loading-card { text-align: center; color: var(--muted); }
.spinner {
  width: 44px; height: 44px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid rgba(34, 211, 238, 0.2); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.foot { text-align: center; color: var(--muted); font-size: 0.74rem; padding: 0 22px 26px; }
.hidden { display: none !important; }
