/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --debris:    #f57c00;
  --active:    #58a6ff;
  --starlink:  #8957e5;
  --risk:      #d32f2f;
  --graveyard: #8b949e;
  --bg:        #0d1117;
  --bg2:       #161b22;
  --bg3:       #21262d;
  --border:    #30363d;
  --text:      #e6edf3;
  --text2:     #8b949e;
  --accent:    #58a6ff;
  --header-h:  60px;
  --banner-h:  68px;
  --status-h:  28px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
}
.header-inner {
  width: 100%; max-width: 1900px; margin: 0 auto;
  padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.header-title { display: flex; align-items: center; gap: 12px; }
.header-icon  { font-size: 26px; line-height: 1; }
h1 { font-size: 16px; font-weight: 700; color: var(--text); letter-spacing: 0.01em; }
.subtitle { font-size: 10px; color: var(--text2); margin-top: 2px; letter-spacing: 0.02em; }
.header-nav { display: flex; gap: 4px; }
.nav-btn {
  padding: 5px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: transparent; color: var(--text2); cursor: pointer; font-size: 12px;
  transition: all 0.15s; white-space: nowrap;
}
.nav-btn:hover  { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Stat Banner ─────────────────────────────────────────────────────────────── */
.stat-banner {
  position: fixed; top: var(--header-h); left: 0; right: 0; z-index: 999;
  height: var(--banner-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 8px; overflow-x: auto;
}
.stat-card {
  flex: 1; min-width: 130px; text-align: center;
  padding: 6px 10px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  transition: border-color 0.2s;
}
.stat-card.debris    { border-color: var(--debris); }
.stat-card.active    { border-color: var(--active); }
.stat-card.starlink  { border-color: var(--starlink); }
.stat-card.risk      { border-color: var(--risk); }
.stat-card.graveyard { border-color: var(--graveyard); }
.stat-number {
  font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-card.debris    .stat-number { color: var(--debris); }
.stat-card.active    .stat-number { color: var(--active); }
.stat-card.starlink  .stat-number { color: var(--starlink); }
.stat-card.risk      .stat-number { color: var(--risk); }
.stat-card.graveyard .stat-number { color: var(--graveyard); }
.stat-label { font-size: 9px; color: var(--text2); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Main & Panels ───────────────────────────────────────────────────────────── */
main {
  position: fixed;
  top: calc(var(--header-h) + var(--banner-h));
  left: 0; right: 0;
  bottom: 0;
  overflow: hidden;
}
.panel { display: none; height: 100%; flex-direction: column; }
.panel.active { display: flex; }

/* ── Map Panel ───────────────────────────────────────────────────────────────── */
#panel-map { flex-direction: column; }

.map-layout {
  display: flex; flex: 1; overflow: hidden;
  height: calc(100% - var(--status-h));
}

/* Sidebar */
.map-sidebar {
  width: 240px; min-width: 240px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0;
}
.map-sidebar::-webkit-scrollbar { width: 4px; }
.map-sidebar::-webkit-scrollbar-track { background: var(--bg2); }
.map-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section h3 {
  font-size: 10px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 8px;
}

/* Load status */
.load-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text);
}
.load-detail {
  font-size: 10px; color: var(--text2); margin-top: 4px; line-height: 1.5;
}
.data-source-info {
  display: flex; align-items: center; gap: 6px; margin-top: 6px;
}
.ds-tag {
  font-size: 9px; padding: 2px 6px; border-radius: 3px;
  background: #1a3a5c; color: var(--active); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.ds-epoch { font-size: 10px; color: var(--text2); }

/* Legend */
.legend { display: flex; flex-direction: column; gap: 5px; }
.legend-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text); cursor: pointer;
  padding: 3px 0;
}
.legend-item input[type=checkbox] { cursor: pointer; accent-color: var(--accent); }
.legend-item .dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0; opacity: 0.9;
}
.legend-item small { color: var(--text2); font-size: 10px; margin-left: auto; }

/* Regime buttons */
.regime-btns {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  margin-bottom: 6px;
}
.regime-btn {
  padding: 4px 6px; border-radius: 5px; border: 1px solid var(--border);
  background: transparent; color: var(--text2); cursor: pointer; font-size: 10px;
  transition: all 0.15s; font-weight: 600;
}
.regime-btn:hover  { background: var(--bg3); color: var(--text); }
.regime-btn.active { background: #1a3a5c; color: var(--active); border-color: var(--active); }
.regime-info { font-size: 10px; color: var(--text2); }

/* Altitude filter */
.alt-filter { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.range-row {
  display: flex; align-items: center; gap: 6px;
}
.range-row label { width: 24px; font-size: 10px; color: var(--text2); flex-shrink: 0; }
.range-row input[type=range] {
  flex: 1; height: 4px; accent-color: var(--active);
  cursor: pointer;
}
.range-row span { width: 62px; font-size: 10px; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.alt-context { display: flex; gap: 4px; flex-wrap: wrap; }
.alt-badge {
  font-size: 9px; padding: 2px 5px; border-radius: 3px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.alt-badge.leo { background: rgba(88,166,255,0.15); color: var(--active); }
.alt-badge.meo { background: rgba(137,87,229,0.15); color: var(--starlink); }
.alt-badge.geo { background: rgba(139,148,158,0.15); color: var(--graveyard); }

/* Object inspector */
.object-info-empty {
  font-size: 11px; color: var(--text2); font-style: italic; padding: 4px 0;
}
.object-info-data { font-size: 11px; color: var(--text); }
.oi-row { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px solid var(--border); }
.oi-row:last-child { border-bottom: none; }
.oi-key { color: var(--text2); }
.oi-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.oi-name { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.oi-layer {
  display: inline-block; font-size: 9px; padding: 2px 6px; border-radius: 3px;
  font-weight: 600; margin-bottom: 6px; text-transform: uppercase;
}

/* Refresh */
.refresh-btn {
  width: 100%; padding: 7px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg3);
  color: var(--text); cursor: pointer; font-size: 12px;
  transition: all 0.15s; margin-bottom: 4px;
}
.refresh-btn:hover { background: #1a3a5c; border-color: var(--active); color: var(--active); }
.refresh-info { font-size: 10px; color: var(--text2); }

/* Map / Globe area */
.map-area {
  flex: 1; position: relative; overflow: hidden;
  background: #080c14;
}
#globe-container {
  width: 100%; height: 100%;
  cursor: grab;
}
#globe-container:active { cursor: grabbing; }

/* Tooltip */
.tooltip {
  position: absolute; z-index: 100;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px;
  font-size: 11px; pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  max-width: 220px;
}
.tooltip.hidden { display: none; }
.tt-name { font-weight: 700; font-size: 12px; color: var(--text); margin-bottom: 4px; }
.tt-row { display: flex; justify-content: space-between; gap: 16px; color: var(--text2); }
.tt-row span:last-child { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tt-layer {
  display: inline-block; font-size: 9px; padding: 1px 5px; border-radius: 3px;
  font-weight: 600; margin-top: 3px; text-transform: uppercase;
}

/* Hover coordinate pill */
.hover-coords {
  position: absolute; bottom: 36px; right: 10px;
  background: rgba(13,17,23,0.85); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 10px;
  font-size: 10px; color: var(--text2);
  font-family: 'Courier New', monospace;
  pointer-events: none;
  backdrop-filter: blur(4px);
  transition: opacity 0.2s;
}
.hover-coords.hidden { opacity: 0; }

/* Globe overlay controls (top-right) */
.globe-controls {
  position: absolute; top: 10px; right: 10px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 10;
}
.gc-btn {
  padding: 5px 10px; border-radius: 5px;
  border: 1px solid var(--border);
  background: rgba(13,17,23,0.85); color: var(--text2);
  cursor: pointer; font-size: 11px; backdrop-filter: blur(4px);
  transition: all 0.15s; white-space: nowrap;
}
.gc-btn:hover   { background: rgba(88,166,255,0.15); color: var(--active); border-color: var(--active); }
.gc-btn.toggled { background: rgba(88,166,255,0.2);  color: var(--active); border-color: var(--active); }

/* Globe legend (bottom-right) */
.globe-legend {
  position: absolute; bottom: 36px; left: 10px;
  background: rgba(13,17,23,0.85); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px;
  font-size: 10px; pointer-events: none; backdrop-filter: blur(4px);
  z-index: 10;
}
.gl-title { color: var(--text2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 5px; font-size: 9px; }
.gl-row   { display: flex; align-items: center; gap: 6px; color: var(--text2); margin-bottom: 3px; }
.gl-dot   { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Map loading overlay */
.map-loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(10,14,23,0.85); z-index: 50;
  gap: 16px;
}
.map-loading.hidden { display: none; }
#map-load-msg { font-size: 13px; color: var(--text2); }

/* Status bar */
.status-bar {
  height: var(--status-h);
  background: var(--bg2); border-top: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 14px; gap: 24px;
  font-size: 10px; color: var(--text2); font-family: 'Courier New', monospace;
  white-space: nowrap; overflow: hidden;
}
.status-bar span { flex-shrink: 0; }

/* Spinners */
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--border);
  border-top-color: var(--active); border-radius: 50%;
  animation: spin 0.8s linear infinite; flex-shrink: 0;
}
.spinner-large {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--active); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Analysis Panel ──────────────────────────────────────────────────────────── */
#panel-analysis { overflow-y: auto; }
.analysis-layout {
  padding: 20px; gap: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  align-content: start;
  min-height: 100%;
}
.analysis-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
}
.analysis-card.wide {
  grid-column: 1 / -1;
}
.card-header { margin-bottom: 12px; }
.card-header h3 { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.card-header .card-sub { font-size: 10px; color: var(--text2); }

.chart-container { position: relative; height: 200px; }
.chart-container.half { height: 160px; }
.chart-note { font-size: 10px; color: var(--text2); margin-top: 8px; line-height: 1.5; }

/* Kessler grid */
.kessler-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 14px;
}
.k-metric {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
.k-val {
  font-size: 18px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.k-val.danger  { color: var(--risk); }
.k-val.warning { color: #f57c00; }
.k-label { font-size: 10px; color: var(--text2); margin-top: 3px; }
.k-trend { font-size: 9px; margin-top: 2px; }
.k-trend.up     { color: var(--risk); }
.k-trend.neutral{ color: var(--text2); }

/* Risk gauge bar */
.risk-gauge-wrap {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px;
}
.risk-label { font-size: 11px; color: var(--text); font-weight: 600; margin-bottom: 8px; }
.risk-bar-bg {
  height: 12px; background: var(--bg); border-radius: 6px;
  overflow: hidden; margin-bottom: 4px;
}
.risk-bar-fill {
  height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, #388e3c 0%, #fbc02d 40%, #f57c00 65%, #d32f2f 85%);
  transition: width 0.5s ease;
}
.risk-bar-labels {
  display: flex; justify-content: space-between;
  font-size: 9px; color: var(--text2); margin-bottom: 4px;
}
.risk-value { font-size: 12px; font-weight: 700; color: var(--risk); text-align: center; }

/* CDM / Conjunction feed */
.cdm-note {
  background: rgba(88,166,255,0.08); border: 1px solid rgba(88,166,255,0.2);
  border-radius: 6px; padding: 8px 10px; font-size: 10px; color: var(--text2);
  margin-bottom: 10px; display: flex; gap: 8px; align-items: flex-start;
}
.cdm-badge {
  background: rgba(88,166,255,0.2); color: var(--active);
  font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 3px;
  white-space: nowrap; flex-shrink: 0;
}
.cdm-feed { display: flex; flex-direction: column; gap: 6px; }
.cdm-item {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px;
  border-left: 3px solid var(--border);
}
.cdm-item.risk-high     { border-left-color: var(--risk); }
.cdm-item.risk-elevated { border-left-color: #f57c00; }
.cdm-item.risk-moderate { border-left-color: #fbc02d; }
.cdm-objects { font-size: 11px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.cdm-meta {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  font-size: 10px; color: var(--text2);
}
.cdm-meta span strong { color: var(--text); }
.cdm-risk {
  display: inline-block; font-size: 9px; padding: 1px 5px; border-radius: 3px;
  font-weight: 700; text-transform: uppercase; float: right; margin-top: -20px;
}
.cdm-risk.high     { background: rgba(211,47,47,0.2); color: var(--risk); }
.cdm-risk.elevated { background: rgba(245,124,0,0.2); color: #f57c00; }
.cdm-risk.moderate { background: rgba(251,192,45,0.2); color: #fbc02d; }

/* Source table */
.source-table {
  width: 100%; border-collapse: collapse; margin-top: 10px;
  font-size: 11px;
}
.source-table th {
  text-align: left; padding: 5px 8px;
  background: var(--bg3); color: var(--text2);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.source-table td {
  padding: 5px 8px; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.source-table tr:last-child td { border-bottom: none; }
.source-table .total-row td { background: var(--bg3); font-size: 12px; }

/* ── About Panel ─────────────────────────────────────────────────────────────── */
#panel-about { overflow-y: auto; }
.about-layout { padding: 24px; display: flex; justify-content: center; }
.about-card {
  max-width: 860px; width: 100%;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 28px 32px;
}
.about-card h2 {
  font-size: 20px; font-weight: 700; margin-bottom: 4px;
}
.about-sub { font-size: 11px; color: var(--text2); margin-bottom: 24px; }
.about-card h3 {
  font-size: 13px; font-weight: 700; color: var(--active);
  margin: 20px 0 8px; text-transform: uppercase; letter-spacing: 0.06em;
}
.about-card p { font-size: 13px; color: var(--text2); line-height: 1.7; margin-bottom: 10px; }
.about-card strong { color: var(--text); }
.about-list { padding-left: 20px; }
.about-list li { font-size: 12px; color: var(--text2); line-height: 1.7; margin-bottom: 4px; }

/* CRS chain */
.crs-chain {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px;
  margin: 12px 0; flex-wrap: wrap;
}
.crs-step {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 12px; text-align: center;
  min-width: 80px;
}
.crs-step.active-crs { border-color: var(--active); background: rgba(88,166,255,0.08); }
.crs-name { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.crs-desc { font-size: 9px; color: var(--text2); line-height: 1.4; }
.crs-arrow { font-size: 16px; color: var(--text2); flex-shrink: 0; }
