:root {
  --bg: #05070a;
  --surface: #0d1219;
  --surface-2: #131b25;
  --border: #1d2531;
  --border-gold: rgba(224,168,61,.22);
  --ink: #e8eef6;
  --ink-2: #8b98a8;
  --muted: #5f6b7a;
  --gold: #e0a83d;
  --gold-dim: #b8862c;
  --good: #3fb950;
  --bad: #f0603a;
  --accent: #4a9eff;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0,0,0,.55);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --panel: linear-gradient(180deg, rgba(19,25,34,.92), rgba(10,14,20,.94));
}
:root[data-theme="light"] {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d8dee6;
  --border-gold: rgba(198,138,30,.28);
  --ink: #1a2029;
  --ink-2: #48525e;
  --muted: #8a94a0;
  --gold: #c68a1e;
  --gold-dim: #a06f14;
  --shadow: 0 8px 26px rgba(20,30,50,.10);
  --panel: #ffffff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  position: relative;
  min-height: 100vh;
}
/* layered backdrop: surveillance grid + gold bloom (dark theme only) */
body::before, body::after { content: ""; position: fixed; pointer-events: none; z-index: 0; }
body::before {
  inset: -2px;
  background-image: linear-gradient(rgba(224,168,61,.13) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(224,168,61,.13) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: radial-gradient(ellipse 80% 65% at 50% 22%, #000 25%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 80% 65% at 50% 22%, #000 25%, transparent 78%);
}
body::after {
  left: 50%; top: -280px; width: 1000px; height: 1000px; transform: translateX(-50%);
  background: radial-gradient(circle, rgba(224,168,61,.10), rgba(224,168,61,.03) 42%, transparent 68%);
}
:root[data-theme="light"] body::before, :root[data-theme="light"] body::after { display: none; }
body > * { position: relative; z-index: 1; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; }

.brand { font-weight: 700; font-size: 16px; letter-spacing: 3px; display: flex; align-items: center; gap: 9px; text-transform: uppercase; font-family: var(--mono); }
.brand-mark { color: var(--gold); }
.brand-mark-img { height: 26px; width: auto; display: block; }
.brand-logo { display: block; width: 150px; max-width: 60%; height: auto; margin: 0 auto 4px; }

/* ---------- Auth screens (login / paywall / set-password) ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; position: relative; }
.login::before {
  content: ""; position: fixed; left: 50%; top: 40%; width: 1100px; height: 1100px;
  transform: translate(-50%,-50%); z-index: -1; pointer-events: none;
  background: conic-gradient(from 0deg, transparent 0deg, rgba(224,168,61,.10) 22deg, transparent 46deg);
  animation: sweep 9s linear infinite;
  mask-image: radial-gradient(circle, #000 12%, transparent 62%);
  -webkit-mask-image: radial-gradient(circle, #000 12%, transparent 62%);
}
:root[data-theme="light"] .login::before { display: none; }
@keyframes sweep { to { transform: translate(-50%,-50%) rotate(360deg); } }

/* Radar contacts: the networks we crawl, revealed as the sweep passes over them.
   Each blip's negative animation-delay is tuned to its angle so it ignites in
   sync with the beam, then decays like phosphor. */
.radar-blips { position: fixed; left: 50%; top: 40%; width: 0; height: 0; z-index: 0; pointer-events: none; }
.radar-blips span {
  position: absolute; left: 0; top: 0; opacity: .045;
  transform: rotate(var(--a)) translateX(var(--r)) rotate(calc(-1 * var(--a)));
  animation: blip 9s linear infinite; animation-delay: var(--d);
}
.radar-blips b {
  display: block; transform: translate(-50%,-50%);
  font: 700 11px/1 var(--mono); letter-spacing: 2.4px; text-transform: uppercase;
  color: var(--gold); white-space: nowrap; text-shadow: 0 0 16px rgba(224,168,61,.6);
}
.radar-blips b::before {
  content: ""; display: block; width: 5px; height: 5px; margin: 0 auto 7px;
  background: var(--gold); transform: rotate(45deg); box-shadow: 0 0 10px var(--gold);
}
@keyframes blip {
  0%   { opacity: .62; }
  6%   { opacity: .30; }
  30%  { opacity: .07; }
  100% { opacity: .045; }
}
:root[data-theme="light"] .radar-blips { display: none; }
/* below this width the card fills the screen — no room beside it for contacts */
@media (max-width: 900px) { .radar-blips { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .login::before, .radar-blips span { animation: none; }
  .radar-blips span { opacity: .14; }
}

.login-card {
  position: relative; background: var(--panel);
  border: 1px solid var(--border-gold); border-radius: 18px;
  padding: 34px 30px; width: 348px; max-width: 100%;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.04);
}
.login-card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent); opacity: .75;
}
.login-card .brand { font-size: 20px; justify-content: center; }
.login-card .muted { text-align: center; font-family: var(--mono); font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase; }
.login-card input, .login-card button { padding: 12px 13px; border-radius: 10px; font-size: 14px; }
.login-card input { background: #070a0e; border: 1px solid rgba(255,255,255,.12); color: var(--ink); outline: none; transition: border-color .18s, box-shadow .18s; }
:root[data-theme="light"] .login-card input { background: var(--surface-2); border-color: var(--border); }
.login-card input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(224,168,61,.14); }
.login-card button { background: var(--gold); color: #1a1200; border: 0; font-weight: 700; cursor: pointer; transition: filter .18s; }
.login-card button:hover { filter: brightness(1.09); }
.login-card button.ghost { background: none; border: 1px solid var(--border-gold); color: var(--gold); font-weight: 600; }
.login-card button.ghost:hover { background: rgba(224,168,61,.1); filter: none; }

/* ---------- App shell: sidebar + main ---------- */
#app:not(.hidden) { display: flex; min-height: 100vh; align-items: stretch; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.sidenav {
  flex: none; width: 208px; position: sticky; top: 0; height: 100vh; z-index: 12;
  background: rgba(9,13,19,.9); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-right: 1px solid var(--border); padding: 18px 12px; display: flex; flex-direction: column; gap: 22px;
}
:root[data-theme="light"] .sidenav { background: rgba(255,255,255,.92); }
.sidenav::after {
  content: ""; position: absolute; top: 0; bottom: 0; right: -1px; width: 1px;
  background: linear-gradient(180deg, transparent, var(--border-gold), transparent);
}
.sidenav .brand { font-size: 15px; padding: 6px 8px 0; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: none; border: 0; color: var(--ink-2); padding: 11px 12px; border-radius: 10px;
  cursor: pointer; font-size: 14px; font-weight: 500; font-family: inherit; transition: .15s; position: relative;
}
.nav-item svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; }
.nav-item svg .fill { fill: currentColor; stroke: none; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: rgba(224,168,61,.12); color: var(--gold); }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--gold); box-shadow: 0 0 10px var(--gold);
}

.view.hidden { display: none; }
.netbar { padding: 16px 20px 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 60px;
  background: rgba(10,14,20,.82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
:root[data-theme="light"] .topbar { background: rgba(255,255,255,.88); }
.view-title { flex: 1; margin: 0; font-size: 16px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; font-family: var(--mono); color: var(--ink); }
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-gold), transparent);
}
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button {
  background: none; border: 0; color: var(--ink-2); padding: 8px 14px; border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 500; text-transform: capitalize; transition: .16s;
}
.tabs button:hover { background: var(--surface-2); color: var(--ink); }
.tabs button.active { background: rgba(224,168,61,.12); color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

button.primary { background: var(--gold); color: #1a1200; border: 0; padding: 9px 15px; border-radius: 9px; font-weight: 700; cursor: pointer; transition: filter .18s; }
button.primary:hover { filter: brightness(1.09); }
button.ghost { background: none; border: 1px solid var(--border); color: var(--ink-2); padding: 8px 13px; border-radius: 9px; cursor: pointer; transition: .16s; }
button.ghost:hover { color: var(--gold); border-color: var(--border-gold); }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--ink-2); width: 34px; height: 34px; border-radius: 9px; cursor: pointer; transition: .16s; }
.icon-btn:hover { color: var(--gold); border-color: var(--border-gold); }
.lang-sel { background: var(--surface); border: 1px solid var(--border); color: var(--ink-2); height: 34px; border-radius: 9px; padding: 0 8px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: var(--mono); }
.lang-sel:hover { color: var(--gold); }

/* ---------- Tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; padding: 20px; }
.tile {
  position: relative; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px; overflow: hidden; transition: border-color .18s, transform .18s;
}
.tile::before {
  content: ""; position: absolute; left: 14px; right: 14px; top: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-gold), transparent);
}
.tile:hover { border-color: var(--border-gold); transform: translateY(-2px); }
.tile .label { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.4px; font-family: var(--mono); }
.tile-metric { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; }
.tile .val { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.tile .val-unit { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.tile .sub { color: var(--ink-2); font-size: 12px; margin-top: 4px; }
.tile .sub b { color: var(--gold); font-weight: 700; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; padding: 0 20px 14px; flex-wrap: wrap; }
.toolbar input {
  flex: 1; max-width: 340px; padding: 10px 13px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); color: var(--ink); outline: none; transition: .18s;
}
.toolbar input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(224,168,61,.12); }
.last-updated { margin-left: auto; font-family: var(--mono); font-size: 11px; letter-spacing: .6px; }

/* ---------- Table ---------- */
.table-wrap { padding: 0 20px 24px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
thead th {
  text-align: left; padding: 11px 12px; font-size: 10.5px; color: var(--ink-2);
  background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
  cursor: pointer; user-select: none; text-transform: uppercase; letter-spacing: 1.1px;
  font-family: var(--mono); transition: color .16s;
}
thead th:hover { color: var(--gold); }
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13px; white-space: nowrap; }
tbody tr { cursor: pointer; transition: background .14s; }
tbody tr:hover { background: rgba(224,168,61,.06); }
tbody tr:last-child td { border-bottom: 0; }
.score { font-weight: 700; color: var(--gold); font-family: var(--mono); }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.title-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.empty { padding: 52px; text-align: center; color: var(--muted); font-family: var(--mono); letter-spacing: .8px; }

/* ---------- Videos ---------- */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; padding: 20px; }
.video-card {
  position: relative; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: border-color .18s, transform .18s;
}
.video-card:hover { border-color: var(--border-gold); transform: translateY(-2px); }
.video-thumb {
  position: relative; aspect-ratio: 16/9; background: var(--surface-2);
  background-size: cover; background-position: center; display: grid; place-items: center;
}
.video-thumb::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 55%, rgba(0,0,0,.5));
}
.video-play {
  position: relative; z-index: 1; width: 52px; height: 52px; border-radius: 50%;
  background: rgba(224,168,61,.92); display: grid; place-items: center; transition: transform .18s;
}
.video-card:hover .video-play { transform: scale(1.1); }
.video-play svg { width: 20px; height: 20px; fill: #1a1200; margin-left: 3px; }
.video-dur {
  position: absolute; right: 8px; bottom: 8px; z-index: 2; background: rgba(0,0,0,.72);
  color: #fff; font: 700 11px/1 var(--mono); padding: 3px 6px; border-radius: 5px;
}
.video-meta { padding: 13px 15px 15px; }
.video-meta .vtitle { font-size: 14px; font-weight: 600; color: var(--ink); line-height: 1.35; }
.video-meta .vtag {
  display: inline-block; margin-top: 8px; font: 700 10px/1 var(--mono); letter-spacing: 1px;
  text-transform: uppercase; color: var(--gold); background: rgba(224,168,61,.1);
  border: 1px solid var(--border-gold); padding: 4px 8px; border-radius: 20px;
}
.video-modal-frame { position: relative; aspect-ratio: 16/9; width: 100%; border-radius: 12px; overflow: hidden; background: #000; }
.video-modal-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- Jobs panel ---------- */
.jobs {
  position: fixed; bottom: 0; right: 0; width: 340px; max-height: 40vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border-gold); border-radius: var(--radius) 0 0 0;
  box-shadow: var(--shadow); font-size: 12px; z-index: 20;
}
.jobs:empty { display: none; }
.job-row { display: flex; justify-content: space-between; gap: 8px; padding: 9px 13px; border-bottom: 1px solid var(--border); }
.badge { padding: 2px 8px; border-radius: 20px; font-size: 10.5px; font-weight: 700; font-family: var(--mono); text-transform: uppercase; letter-spacing: .5px; }
.badge.queued { background: var(--surface-2); color: var(--ink-2); }
.badge.running { background: rgba(74,158,255,.16); color: var(--accent); }
.badge.done { background: rgba(63,185,80,.15); color: var(--good); }
.badge.error { background: rgba(240,96,58,.15); color: var(--bad); }

/* ---------- Favorites ---------- */
.star-cell { width: 46px; text-align: center; padding: 4px 6px !important; }
.star {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px;
  color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; user-select: none;
  transition: color .12s, background .12s, transform .08s;
}
.star:hover { color: var(--gold); background: rgba(224,168,61,.12); transform: scale(1.08); }
.star.on { color: var(--gold); text-shadow: 0 0 12px rgba(224,168,61,.5); }
.star.on:hover { color: var(--gold-dim); }
/* Chart / detail button (right end of each row) */
.chart-cell { width: 52px; text-align: center; padding: 4px 6px !important; }
.chart-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px; cursor: pointer;
  color: var(--ink-2); border: 1px solid var(--border); background: var(--surface-2);
  transition: color .14s, border-color .14s, background .14s, transform .08s;
}
.chart-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-btn:hover { color: var(--gold); border-color: var(--border-gold); background: rgba(224,168,61,.12); transform: scale(1.08); }
tbody tr:hover .chart-btn { border-color: var(--border-gold); color: var(--gold); }

.fav-toggle { background: var(--surface); border: 1px solid var(--border); color: var(--ink-2); padding: 10px 13px; border-radius: 10px; cursor: pointer; font-size: 13px; white-space: nowrap; transition: .16s; }
.fav-toggle:hover { color: var(--gold); border-color: var(--border-gold); }
.fav-toggle.active { color: var(--gold); border-color: var(--gold); background: rgba(224,168,61,.1); }

/* ---------- Detail modal + chart ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.72); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal.hidden { display: none; }
.modal-card {
  position: relative; background: var(--panel); border: 1px solid var(--border-gold);
  border-radius: 18px; padding: 26px; width: 540px; max-width: 94vw; box-shadow: var(--shadow);
}
.modal-card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent); opacity: .75;
}
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: 0; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; }
.modal-close:hover { color: var(--gold); }
.modal-title { font-size: 16px; font-weight: 700; padding-right: 24px; }
.modal-link { display: inline-block; font-size: 12px; color: var(--accent); word-break: break-all; margin-top: 4px; }
.modal-chart-title { font-size: 10.5px; color: var(--muted); margin: 18px 0 6px; font-family: var(--mono); text-transform: uppercase; letter-spacing: 1.3px; }
.chart { width: 100%; height: auto; }
.chart-line { fill: none; stroke: var(--gold); stroke-width: 2; stroke-linejoin: round; }
.chart circle { fill: var(--gold); }
.axis { stroke: var(--border); stroke-width: 1; }
.axis-lbl { fill: var(--muted); font-size: 10px; }

@media (max-width: 760px) {
  #app:not(.hidden) { flex-direction: column; }
  .sidenav {
    width: 100%; height: auto; flex-direction: row; align-items: center; gap: 8px;
    padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .sidenav::after { display: none; }
  .sidenav .brand { padding: 0 6px 0 4px; }
  .nav { flex-direction: row; flex: 1; gap: 4px; }
  .nav-item { padding: 9px 12px; justify-content: center; }
  .nav-item.active::before { left: 9px; right: 9px; top: auto; bottom: 0; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
  .topbar { height: auto; flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .view-title { flex-basis: 100%; font-size: 14px; }
  .tiles, .toolbar, .netbar, .table-wrap, .video-grid { padding-left: 14px; padding-right: 14px; }
  .jobs { width: 100%; border-radius: 0; }
}
