/* ============ APOGEE v3.1 — CLEAN MISSION CONTROL ============ */
:root {
  --bg: #05070f;
  --panel: rgba(11, 15, 28, 0.88);
  --panel-solid: #0b0f1c;
  --raised: rgba(255, 255, 255, 0.04);
  --raised-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.18);
  --accent: #4cc9f0;
  --accent-soft: rgba(76, 201, 240, 0.12);
  --accent-2: #8b7cff;
  --live: #3ddc97;
  --danger: #ff5d8f;
  --text: #e8eefb;
  --text-muted: #8391ab;
  --font-ui: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --font-display: 'Orbitron', sans-serif;
  --hud-h: 56px;
  --status-h: 32px;
  --sidebar-w: 320px;
  --gap: 16px;
  --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
button { font-family: inherit; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.4;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Background ---------- */
#starfield {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 0%, #0a1030 0%, #05070f 60%, #000 100%);
}
.nebula {
  position: fixed; border-radius: 50%; pointer-events: none;
  filter: blur(90px); z-index: 1; mix-blend-mode: screen; opacity: 0.35;
}
.nebula-1 { width: 560px; height: 560px; top: -200px; left: -200px;
  background: radial-gradient(circle, rgba(76, 201, 240, 0.3), transparent 70%); }
.nebula-2 { width: 640px; height: 640px; bottom: -300px; right: -200px;
  background: radial-gradient(circle, rgba(139, 124, 255, 0.3), transparent 70%); }
.vignette {
  position: fixed; inset: 0; z-index: 9997; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.45) 100%);
}

/* ---------- Header ---------- */
.hud {
  position: fixed; top: 0; left: 0; right: 0; height: var(--hud-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; z-index: 1000;
  background: rgba(5, 7, 15, 0.85);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-mark { width: 34px; height: 34px; }
.logo-text { display: flex; flex-direction: column; gap: 2px; }
.wordmark {
  font-family: var(--font-display); font-weight: 900; font-size: 17px;
  letter-spacing: 0.28em; line-height: 1;
  background: linear-gradient(135deg, #4cc9f0, #8b7cff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { font-size: 11px; color: var(--text-muted); }

.hud-center { display: flex; align-items: baseline; gap: 10px; }
.clock-label { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.clock {
  font-family: var(--font-mono); font-weight: 500; font-size: 20px;
  color: var(--text); letter-spacing: 0.06em; min-width: 100px;
  font-variant-numeric: tabular-nums;
}

.hud-right { display: flex; align-items: center; gap: 8px; }
.status-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  background: var(--raised); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted); font-weight: 500;
}
.status-pill b { color: var(--text); font-family: var(--font-mono); font-weight: 700; }
.status-pill.live { color: var(--live); }
.pulse-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--live); animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Map ---------- */
.map-wrap {
  position: fixed; top: var(--hud-h); bottom: var(--status-h);
  left: 0; right: 0; z-index: 2;
}
#map { width: 100%; height: 100%; background: #05070f; }
.leaflet-tile-pane { filter: brightness(0.95) contrast(1.1) saturate(1.1) hue-rotate(190deg); }
.leaflet-container { background: #05070f !important; font-family: var(--font-ui) !important; }

/* zoom sits just left of the sidebar so nothing overlaps */
.leaflet-bottom.leaflet-right {
  right: calc(var(--sidebar-w) + var(--gap) * 2);
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
body.sidebar-collapsed .leaflet-bottom.leaflet-right { right: 0; }
.leaflet-bottom.leaflet-right .leaflet-control { margin: 0 0 var(--gap) 0; }
.leaflet-control-zoom {
  border: 1px solid var(--border) !important; border-radius: 8px !important;
  overflow: hidden; box-shadow: none !important;
}
.leaflet-control-zoom a {
  background: var(--panel-solid) !important; color: var(--text) !important;
  border-bottom: 1px solid var(--border) !important; width: 32px !important; height: 32px !important; line-height: 32px !important;
}
.leaflet-control-zoom a:last-child { border-bottom: 0 !important; }
.leaflet-control-zoom a:hover { background: #151b30 !important; color: var(--accent) !important; }

/* ---------- Shared panel look ---------- */
.sidebar, .detail-panel, .pass-widget, .ground-toggle {
  background: var(--panel);
  backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

/* ---------- Left column ---------- */
.left-stack {
  position: absolute; top: var(--gap); left: var(--gap);
  width: 292px; max-height: calc(100% - var(--gap) * 2);
  display: flex; flex-direction: column; gap: 12px;
  z-index: 520; pointer-events: none;
}
.left-stack > * { pointer-events: auto; }

.detail-panel { position: relative; padding: 16px; animation: panelIn 0.25s ease-out; }
.detail-panel[hidden] { display: none; }
@keyframes panelIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.close-btn {
  position: absolute; top: 12px; right: 12px; width: 26px; height: 26px;
  background: transparent; border: 0; border-radius: 6px;
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: 0.15s;
}
.close-btn:hover { background: var(--raised-hover); color: var(--text); }
.close-btn svg { width: 14px; height: 14px; }

.detail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; padding-right: 28px; }
.detail-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--accent); }
.detail-titles { min-width: 0; }
.detail-header h2 {
  font-size: 15px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.detail-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.detail-sub .sep { margin: 0 6px; opacity: 0.5; }
#detailNorad { font-family: var(--font-mono); }

.data-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.data-cell {
  padding: 10px 12px; background: var(--raised);
  border: 1px solid var(--border); border-radius: 8px;
}
.detail-label { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.detail-value {
  font-family: var(--font-mono); font-size: 14px; font-weight: 500; color: var(--text);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.detail-value.accent { color: var(--accent); }
.detail-value small { font-size: 10px; color: var(--text-muted); margin-left: 4px; font-weight: 400; }

.detail-actions { display: flex; gap: 8px; margin-top: 12px; }
.action-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--raised); color: var(--text);
  font-size: 12px; font-weight: 500; cursor: pointer; transition: 0.15s; white-space: nowrap;
}
.action-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.action-btn:hover { background: var(--raised-hover); border-color: var(--border-hover); }
.action-btn.primary { background: var(--accent-soft); border-color: rgba(76, 201, 240, 0.35); color: var(--accent); }
.action-btn.primary:hover { background: rgba(76, 201, 240, 0.2); }
.action-btn.primary.on { background: var(--accent); color: #04121a; border-color: var(--accent); }
.action-btn.small { flex: none; width: 100%; }

.pass-widget { padding: 14px 16px; flex-shrink: 0; }
.widget-header {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 10px;
}
.widget-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--danger); animation: pulse 2s ease-in-out infinite; }
.widget-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; line-height: 1.5; }
.pass-countdown {
  font-family: var(--font-mono); font-size: 26px; font-weight: 500; color: var(--accent);
  letter-spacing: 0.04em; margin-bottom: 8px; font-variant-numeric: tabular-nums;
}
.pass-detail { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.pass-detail span:last-child { color: var(--text); font-family: var(--font-mono); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: absolute; top: var(--gap); right: var(--gap); bottom: var(--gap);
  width: var(--sidebar-w);
  display: flex; flex-direction: column; z-index: 500;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar.collapsed { transform: translateX(calc(100% + var(--gap))); }

.sidebar-toggle {
  position: absolute; top: 0; left: -44px; width: 34px; height: 34px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: 0.15s;
}
.sidebar-toggle:hover { color: var(--accent); border-color: var(--border-hover); }
.sidebar-toggle svg { width: 16px; height: 16px; }

.sidebar-header {
  padding: 14px 14px 12px; display: flex; flex-direction: column; gap: 12px;
  flex-shrink: 0; border-bottom: 1px solid var(--border);
}
.sidebar-title { display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 600; }
.badge {
  background: var(--raised); border: 1px solid var(--border); padding: 2px 9px; border-radius: 999px;
  font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); font-weight: 500;
}

/* Search */
.search-box { position: relative; }
.search-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-muted); pointer-events: none;
}
#searchInput {
  width: 100%; padding: 10px 34px 10px 34px;
  background: var(--raised); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-family: var(--font-ui); font-size: 13px; outline: none; transition: 0.15s;
}
#searchInput::placeholder { color: var(--text-muted); }
#searchInput:focus { border-color: rgba(76, 201, 240, 0.5); background: rgba(76, 201, 240, 0.05); }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border: 0; background: transparent; border-radius: 6px;
  color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.search-clear[hidden] { display: none; }
.search-clear:hover { background: var(--raised-hover); color: var(--text); }
.search-clear svg { width: 13px; height: 13px; }

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
  max-height: 340px; overflow-y: auto; padding: 6px;
  background: var(--panel-solid); border: 1px solid var(--border-hover);
  border-radius: 10px; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}
.search-results[hidden] { display: none; }
.result-heading { padding: 8px 8px 4px; font-size: 11px; color: var(--text-muted); font-weight: 500; }
.result {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px;
  background: transparent; border: 0; border-radius: 7px; color: var(--text);
  text-align: left; cursor: pointer; transition: background 0.12s;
}
.result:hover, .result.hl { background: var(--raised-hover); }
.result-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.result-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-sub { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-action {
  font-size: 11px; font-weight: 500; color: var(--accent);
  padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); flex-shrink: 0;
}
.result-action.muted { color: var(--text-muted); background: var(--raised); }
.search-note { padding: 8px; font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.spinner {
  display: inline-block; width: 10px; height: 10px; margin-right: 8px; vertical-align: -1px;
  border: 1.5px solid var(--border-hover); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* List */
.sat-list { overflow-y: auto; flex: 1; padding: 6px; min-height: 120px; }
.sat-list::-webkit-scrollbar, .search-results::-webkit-scrollbar { width: 6px; }
.sat-list::-webkit-scrollbar-thumb, .search-results::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14); border-radius: 3px;
}
.sat-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px;
  border-radius: 8px; cursor: pointer; transition: background 0.12s;
}
.sat-item:hover { background: var(--raised); }
.sat-item.active { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.sat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: currentColor; }
.sat-info { flex: 1; min-width: 0; }
.sat-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sat-meta { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.sat-alt { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* Constellations */
.constellations { border-top: 1px solid var(--border); flex-shrink: 0; }
.constellations summary {
  list-style: none; cursor: pointer; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 500; color: var(--text-muted); transition: color 0.15s;
}
.constellations summary::-webkit-details-marker { display: none; }
.constellations summary:hover { color: var(--text); }
.chev { width: 16px; height: 16px; transition: transform 0.2s; }
.constellations[open] .chev { transform: rotate(180deg); }
.chip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 12px 12px; }
.chip {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; background: var(--raised); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 12px; cursor: pointer; transition: 0.15s;
  min-width: 0;
}
.chip-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.chip-count { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); flex-shrink: 0; }
.chip:hover:not(:disabled) { background: var(--raised-hover); border-color: var(--border-hover); }
.chip:disabled { cursor: wait; opacity: 0.7; }
.chip.loaded { border-color: rgba(61, 220, 151, 0.35); background: rgba(61, 220, 151, 0.07); cursor: default; }
.chip.loaded .chip-count { color: var(--live); }
.chip.failed .chip-count { color: var(--danger); }

/* ---------- Ground track toggle ---------- */
.ground-toggle {
  position: absolute; bottom: var(--gap); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 9px 16px;
  color: var(--text-muted); font-size: 12px; font-weight: 500; cursor: pointer;
  z-index: 500; transition: 0.15s;
}
.ground-toggle:hover { color: var(--text); border-color: var(--border-hover); }
.ground-toggle.active { color: var(--accent); border-color: rgba(76, 201, 240, 0.4); }
.toggle-indicator { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--text-muted); transition: 0.15s; }
.ground-toggle.active .toggle-indicator { background: var(--accent); border-color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: absolute; top: var(--gap); left: 50%; transform: translate(-50%, -12px);
  padding: 9px 16px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--panel-solid); border: 1px solid var(--border-hover);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none; transition: 0.25s; z-index: 700; max-width: 90%;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 93, 143, 0.5); color: #ffb3c8; }

/* ---------- Status bar ---------- */
.statusbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--status-h);
  background: rgba(5, 7, 15, 0.92); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; font-size: 11px; color: var(--text-muted); z-index: 1000;
}
.status-left, .status-center, .status-right { display: flex; align-items: center; gap: 14px; }
.status-chip {
  padding: 2px 9px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--accent); font-weight: 600; font-size: 10px;
}
.status-value { color: var(--text); font-family: var(--font-mono); }

/* ---------- Markers ---------- */
.sat-marker { position: relative; }
.sat-marker-inner {
  width: 9px; height: 9px; border-radius: 50%; background: currentColor;
  box-shadow: 0 0 8px currentColor; border: 1.5px solid rgba(255, 255, 255, 0.85);
}
.sat-marker-inner.iss { width: 13px; height: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  :root { --sidebar-w: 290px; }
  .left-stack { width: 270px; }
}
@media (max-width: 800px) {
  .tagline { display: none; }
  .status-left .status-muted, .status-center { display: none; }
}
@media (max-width: 680px) {
  .hud-center { display: none; }
  .hud-right .status-pill:nth-child(2) { display: none; }
  .sidebar { width: calc(100% - var(--gap) * 2); top: auto; height: 55%; }
  .sidebar.collapsed { transform: translateY(calc(100% + var(--gap))); }
  .sidebar-toggle { top: -44px; left: 0; }
  .left-stack { width: calc(100% - var(--gap) * 2); }
  .pass-widget { display: none; }
  .leaflet-bottom.leaflet-right, body.sidebar-collapsed .leaflet-bottom.leaflet-right { display: none; }
  .ground-toggle { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
