:root {
  --bg: #04070f;
  --bg-2: #060b18;
  --ink: #e8f1ff;
  --muted: #8ba3c7;
  --cyan: #38e1ff;
  --blue: #4f8cff;
  --glow: rgba(56, 225, 255, 0.55);
  --line: rgba(120, 170, 255, 0.16);
  --glass: rgba(10, 18, 34, 0.62);
  --glass-strong: rgba(10, 18, 34, 0.85);
  --danger: #ff5d6c;
  --ok: #46f3a3;
  --radius: 16px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#cesiumContainer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Hide default Cesium chrome we don't use, keep the canvas clean */
.cesium-widget-credits,
.cesium-viewer-bottom { display: none !important; }
.cesium-viewer-toolbar,
.cesium-viewer-animationContainer,
.cesium-viewer-timelineContainer { display: none !important; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hidden { display: none !important; }

/* ---------- Loading ---------- */
.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: radial-gradient(circle at 50% 40%, #0a1730, #04070f 70%);
  transition: opacity 600ms ease;
}
.loading.done { opacity: 0; pointer-events: none; }
.loading-orb {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #6fe9ff, #2b6cff 55%, #0a1730 100%);
  box-shadow: 0 0 60px var(--glow), inset 0 0 30px rgba(0, 0, 0, 0.4);
  animation: pulse 2.4s ease-in-out infinite;
}
.loading-title { margin: 6px 0 0; font-size: 1.6rem; font-weight: 800; letter-spacing: 0.18em; }
.loading-sub { margin: 0; color: var(--muted); font-size: 0.9rem; }

@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 50px var(--glow); }
  50% { transform: scale(1.06); box-shadow: 0 0 80px var(--glow); }
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 800;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 14px var(--glow);
}
.brand-name { font-size: 1.15rem; }
.brand-accent { color: var(--cyan); }

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 460px;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  width: 18px; height: 18px;
  color: var(--muted);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 10px 12px 10px 38px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(4, 9, 20, 0.7);
  color: var(--ink);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
#search:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(56, 225, 255, 0.16); }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  max-height: 320px;
  overflow-y: auto;
  border-radius: 12px;
  background: var(--glass-strong);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: none;
}
.search-results.open { display: block; }
.search-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgba(120, 170, 255, 0.08);
}
.search-item:hover, .search-item.active { background: rgba(56, 225, 255, 0.12); }
.search-item .si-name { font-weight: 600; }
.search-item .si-meta { color: var(--muted); font-size: 0.8rem; }

.topbar-stats { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }
.stat-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(4, 9, 20, 0.6);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}
.stat-pill strong { color: var(--ink); }
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 10px rgba(70, 243, 163, 0.8);
  animation: blink 2s infinite;
}
.live-dot.paused { background: var(--muted); box-shadow: none; animation: none; }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---------- Panels ---------- */
.panel { position: fixed; z-index: 18; border-radius: var(--radius); color: var(--ink); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.panel-head h2 { margin: 0; font-size: 0.95rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.panel-body { padding: 6px 16px 16px; }
.panel-sub { margin: 4px 0 10px; font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.filters { top: 84px; left: 14px; width: 268px; max-height: calc(100vh - 120px); overflow-y: auto; }
.filters.collapsed .panel-body { display: none; }

.filter-list { display: grid; gap: 4px; }
.filter-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 140ms ease;
  user-select: none;
}
.filter-row:hover { background: rgba(56, 225, 255, 0.08); }
.filter-row input { display: none; }
.filter-swatch { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 8px currentColor; }
.filter-name { flex: 1; font-size: 0.9rem; }
.filter-count { color: var(--muted); font-size: 0.78rem; }
.filter-row.off { opacity: 0.4; }
.filter-row.off .filter-swatch { box-shadow: none; }

.divider { height: 1px; background: var(--line); margin: 14px 0; }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1;
  padding: 8px 4px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(4, 9, 20, 0.5);
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 140ms ease;
}
.seg button:hover { color: var(--ink); }
.seg button.active { background: rgba(56, 225, 255, 0.18); color: var(--ink); border-color: var(--cyan); }

.switch-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0 2px;
  font-size: 0.9rem;
  cursor: pointer;
}
.switch-row span:first-child { flex: 1; }
.switch-row input { display: none; }
.switch {
  width: 40px; height: 22px; border-radius: 999px;
  background: rgba(120, 170, 255, 0.2);
  position: relative; transition: background 160ms ease;
  flex-shrink: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink); transition: transform 160ms ease;
}
.switch-row input:checked + .switch { background: var(--cyan); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }

.action-btn {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(4, 9, 20, 0.6);
  color: var(--ink);
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
  transition: all 160ms ease;
}
.action-btn svg { width: 18px; height: 18px; }
.action-btn:hover { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(56, 225, 255, 0.12); }
.action-btn.primary { background: linear-gradient(135deg, var(--blue), var(--cyan)); color: #021022; border: none; }
.action-btn.primary.active { box-shadow: 0 0 18px var(--glow); }

.ghost-btn {
  width: 28px; height: 28px; border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent; color: var(--muted);
  cursor: pointer; font-size: 1rem; line-height: 1;
}
.ghost-btn:hover { color: var(--ink); }

/* ---------- Detail ---------- */
.detail { top: 84px; right: 14px; width: 320px; padding: 18px; }
.close-btn {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: transparent;
  color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.close-btn:hover { color: var(--ink); }
.detail-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cat-chip {
  padding: 4px 10px; border-radius: 999px;
  font-size: 0.74rem; letter-spacing: 0.06em; text-transform: uppercase;
  background: rgba(56, 225, 255, 0.16); color: var(--cyan);
  border: 1px solid rgba(56, 225, 255, 0.3);
}
.badge {
  padding: 4px 10px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700;
  background: linear-gradient(135deg, var(--blue), var(--cyan)); color: #021022;
}
.detail h2 { margin: 2px 0 4px; font-size: 1.25rem; line-height: 1.2; padding-right: 28px; }
.detail-id { margin: 0 0 14px; color: var(--muted); font-size: 0.84rem; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric {
  padding: 10px;
  border-radius: 10px;
  background: rgba(4, 9, 20, 0.55);
  border: 1px solid var(--line);
}
.metric-label { display: block; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.metric-val { display: block; margin-top: 3px; font-size: 0.98rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.overhead-line { margin: 14px 0 12px; font-size: 0.85rem; color: var(--muted); }
.overhead-line.visible { color: var(--ok); }
.detail-actions { display: flex; gap: 8px; }
.detail-actions .action-btn { width: auto; flex: 1; }

/* ---------- Overhead ---------- */
.overhead { bottom: 56px; right: 14px; width: 320px; padding: 18px; max-height: 46vh; overflow-y: auto; }
.overhead h2 { margin: 0 0 4px; font-size: 1.1rem; padding-right: 28px; }
.overhead-sub { margin: 0 0 12px; color: var(--muted); font-size: 0.84rem; }
.overhead-list { display: grid; gap: 6px; }
.overhead-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  background: rgba(4, 9, 20, 0.5); border: 1px solid var(--line);
  cursor: pointer;
}
.overhead-item:hover { border-color: var(--cyan); }
.overhead-item .oi-name { flex: 1; font-size: 0.88rem; font-weight: 600; }
.overhead-item .oi-el { color: var(--cyan); font-size: 0.82rem; font-variant-numeric: tabular-nums; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 30;
  padding: 6px 10px; border-radius: 8px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  font-size: 0.82rem; pointer-events: none;
  transform: translate(-50%, -130%);
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.tooltip .tt-cat { color: var(--cyan); font-size: 0.72rem; }

/* ---------- Status bar ---------- */
.statusbar {
  position: fixed; bottom: 14px; left: 14px; z-index: 16;
  padding: 8px 14px; border-radius: 999px;
  font-size: 0.78rem; color: var(--muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px; }
  .search-wrap { order: 3; max-width: none; flex-basis: 100%; }
  .topbar-stats { margin-left: 0; }
  .source-pill { display: none; }
  .filters { top: auto; bottom: 56px; left: 10px; right: 10px; width: auto; max-height: 40vh; }
  .detail { top: auto; bottom: 56px; left: 10px; right: 10px; width: auto; max-height: 52vh; overflow-y: auto; }
  .overhead { bottom: 56px; left: 10px; right: 10px; width: auto; }
  .statusbar { display: none; }
}
