/* ===================== Traffic Vision — Stark HUD theme ===================== */
:root {
  --bg: #070b16;
  --bg-2: #0b1120;
  --panel: rgba(18, 27, 48, 0.72);
  --panel-solid: #0e1729;
  --border: rgba(56, 189, 248, 0.18);
  --border-strong: rgba(56, 189, 248, 0.45);
  --text: #dbeafe;
  --text-dim: #7c8bb0;
  --cyan: #22d3ee;
  --blue: #38bdf8;
  --gold: #fbbf24;
  --red: #f87171;
  --green: #34d399;
  --glow: 0 0 22px rgba(34, 211, 238, 0.35);
  --grid-line: rgba(56, 189, 248, 0.06);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}
[data-theme="light"] {
  --bg: #eef3fb;
  --bg-2: #e3ebf7;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --border: rgba(14, 116, 144, 0.18);
  --border-strong: rgba(14, 116, 144, 0.4);
  --text: #0f2038;
  --text-dim: #5a6b86;
  --cyan: #0891b2;
  --blue: #0284c7;
  --gold: #c2870a;
  --grid-line: rgba(8, 145, 178, 0.07);
  --glow: 0 0 18px rgba(8, 145, 178, 0.22);
  --shadow: 0 16px 40px rgba(30, 64, 120, 0.16);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Rajdhani", system-ui, sans-serif;
  background: radial-gradient(1200px 700px at 80% -10%, var(--bg-2), var(--bg)) fixed;
  color: var(--text);
  overflow: hidden;
}
.grid-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
                    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 30%, #000 30%, transparent 85%);
}
.brand { font-family: "Orbitron", sans-serif; font-weight: 900; letter-spacing: 2px; }
.brand span { color: var(--cyan); }

/* ---- arc reactor ---- */
.reactor {
  width: 72px; height: 72px; border-radius: 50%; position: relative; margin: 0 auto;
  background: radial-gradient(circle, rgba(34,211,238,0.25), transparent 70%);
  border: 2px solid var(--border-strong); box-shadow: var(--glow), inset 0 0 18px rgba(34,211,238,0.3);
  animation: spin 14s linear infinite;
}
.reactor.sm { width: 38px; height: 38px; margin: 0; }
.reactor-core {
  position: absolute; inset: 22%; border-radius: 50%;
  background: radial-gradient(circle, #e0fbff, var(--cyan) 55%, transparent 75%);
  box-shadow: 0 0 18px var(--cyan); animation: pulse 2.6s ease-in-out infinite;
}
.reactor.sm .reactor-core { inset: 24%; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: .75; transform: scale(.92);} 50% { opacity: 1; transform: scale(1.05);} }

/* ============================= LOGIN ============================= */
.login-wrap { position: relative; z-index: 1; height: 100vh; display: grid; place-items: center; }
.login-card {
  width: 380px; padding: 38px 34px; text-align: center;
  background: var(--panel); backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  position: relative;
}
.login-card::before, .login-card::after {
  content: ""; position: absolute; width: 22px; height: 22px; border: 2px solid var(--cyan); opacity: .7;
}
.login-card::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.login-card::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }
.login-card .brand { font-size: 26px; margin: 18px 0 2px; }
.brand-sub { font-size: 11px; letter-spacing: 4px; color: var(--text-dim); margin: 0 0 22px; }
#login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; letter-spacing: 1px; color: var(--text-dim); text-transform: uppercase; }
input, select {
  background: rgba(0,0,0,0.25); border: 1px solid var(--border); color: var(--text);
  padding: 11px 13px; border-radius: 9px; font-family: "Rajdhani", sans-serif; font-size: 15px; font-weight: 600;
}
[data-theme="light"] input, [data-theme="light"] select { background: rgba(255,255,255,0.7); }
input:focus, select:focus { outline: none; border-color: var(--cyan); box-shadow: var(--glow); }
.login-error { color: var(--red); font-size: 13px; min-height: 16px; font-weight: 600; }
.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #04121c; border: 0;
  padding: 12px; border-radius: 9px; font-family: "Orbitron", sans-serif; font-weight: 700;
  letter-spacing: 1.5px; cursor: pointer; box-shadow: var(--glow); transition: transform .12s, filter .12s;
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.1); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

/* ============================== APP ============================== */
.app { position: relative; z-index: 1; display: grid; grid-template-columns: 244px 1fr; height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--panel-solid), transparent); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; backdrop-filter: blur(8px);
}
.logo { display: flex; align-items: center; gap: 12px; padding: 6px 6px 18px; }
.logo .brand { font-size: 17px; line-height: 1; }
#nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
#nav a {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 9px;
  color: var(--text-dim); cursor: pointer; font-weight: 600; font-size: 15px; letter-spacing: .4px;
  border: 1px solid transparent; transition: all .14s;
}
#nav a .ico { color: var(--cyan); font-size: 14px; width: 16px; text-align: center; }
#nav a:hover { background: rgba(34,211,238,0.07); color: var(--text); }
#nav a.active { background: rgba(34,211,238,0.12); border-color: var(--border-strong); color: #fff; box-shadow: inset 3px 0 0 var(--cyan); }
[data-theme="light"] #nav a.active { color: var(--blue); }
.side-foot { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #04121c; font-weight: 800; font-family: "Orbitron";
}
.uname { font-weight: 700; font-size: 14px; }
.urole { font-size: 11px; color: var(--cyan); letter-spacing: 1px; text-transform: uppercase; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-family: "Rajdhani"; font-weight: 600; font-size: 13px; transition: all .14s;
}
.btn-ghost:hover { border-color: var(--cyan); color: var(--text); }

.content { display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 20px 28px; border-bottom: 1px solid var(--border); }
.topbar h2 { font-family: "Orbitron"; font-weight: 700; margin: 0; font-size: 20px; letter-spacing: 1px; }
.page-sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.top-actions { display: flex; gap: 10px; }
.view-root { padding: 24px 28px; overflow-y: auto; }

/* ---- KPI cards ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 13px; padding: 18px;
  backdrop-filter: blur(10px); position: relative; overflow: hidden;
}
.card::after { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 2px; background: linear-gradient(90deg, var(--cyan), transparent); }
.kpi-label { font-size: 12px; color: var(--text-dim); letter-spacing: 1.5px; text-transform: uppercase; }
.kpi-value { font-family: "Orbitron"; font-weight: 900; font-size: 32px; margin-top: 8px; color: #fff; }
[data-theme="light"] .kpi-value { color: var(--blue); }
.kpi-value small { font-size: 14px; color: var(--text-dim); font-family: "Rajdhani"; font-weight: 600; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 13px; padding: 20px; backdrop-filter: blur(10px); margin-bottom: 20px; }
.panel h3 { margin: 0 0 14px; font-family: "Orbitron"; font-weight: 700; font-size: 15px; letter-spacing: 1px; color: var(--cyan); }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--text-dim); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 11px 12px; border-bottom: 1px solid rgba(255,255,255,0.04); }
tr.clickable { cursor: pointer; transition: background .12s; }
tr.clickable:hover { background: rgba(34,211,238,0.07); }
.mono { font-family: "JetBrains Mono", monospace; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; letter-spacing: .5px; }
.tag.cyan { background: rgba(34,211,238,0.16); color: var(--cyan); }
.tag.gold { background: rgba(251,191,36,0.16); color: var(--gold); }
.tag.green { background: rgba(52,211,153,0.16); color: var(--green); }
.tag.red { background: rgba(248,113,113,0.16); color: var(--red); }

.line-block { border: 1px solid var(--border); border-radius: 11px; padding: 14px 16px; margin-bottom: 12px; }
.line-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.dot { width: 12px; height: 12px; border-radius: 3px; box-shadow: 0 0 8px currentColor; }
.line-name { font-family: "Orbitron"; font-weight: 700; font-size: 14px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.sense-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.sense-flow { font-family: "JetBrains Mono"; color: var(--cyan); font-weight: 600; }
.sense-classes { padding: 4px 0 8px 14px; display: flex; flex-wrap: wrap; gap: 6px; }

.frame-ref { position: relative; margin: 12px 0 14px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; max-width: 560px; cursor: zoom-in; }
.frame-ref img { width: 100%; display: block; }
.frame-ref:hover { border-color: var(--cyan); box-shadow: var(--glow); }
.frame-hint { position: absolute; bottom: 8px; right: 10px; background: rgba(0,0,0,0.6); color: #fff; font-size: 11px; padding: 3px 9px; border-radius: 5px; letter-spacing: .5px; }
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(2,4,10,0.9); display: grid; place-items: center; cursor: zoom-out; backdrop-filter: blur(4px); }
.lightbox img { max-width: 94vw; max-height: 90vh; border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--glow); }
.lb-close { position: fixed; top: 18px; right: 26px; color: #fff; font-size: 30px; cursor: pointer; line-height: 1; }

#map { height: 68vh; width: 100%; background: var(--bg-2); }
.map-note { padding: 10px 16px; font-size: 13px; color: var(--text-dim); border-top: 1px solid var(--border); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-solid); color: var(--text); }
.leaflet-popup-content { font-family: "Rajdhani", sans-serif; font-size: 14px; }
.leaflet-container { font-family: "Rajdhani", sans-serif; }

.form-inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.up-progress { height: 8px; background: var(--panel-2); border-radius: 4px; margin-top: 12px; overflow: hidden; }
#up-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--blue)); transition: width .2s; }
input[type=file] { padding: 8px; }

.rev-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; cursor: pointer; transition: all .12s; }
.rev-item:hover { border-color: var(--cyan); background: rgba(34,211,238,0.06); }
.rev-item .meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-top: 4px; }
#rev-canvas { width: 100%; border: 1px solid var(--border); border-radius: 8px; background: #000; }
.rev-controls { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.active-btn { border-color: var(--cyan); color: var(--cyan); }
.empty-state { text-align: center; color: var(--text-dim); padding: 40px; }
.toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 50; background: var(--panel-solid);
  border: 1px solid var(--border-strong); border-left: 3px solid var(--cyan); padding: 13px 18px;
  border-radius: 9px; font-weight: 600; box-shadow: var(--shadow); max-width: 380px;
}
.toast.err { border-left-color: var(--red); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
