/*
 * style.css — Space Debris Orbit Visualizer
 *
 * Aesthetic: aerospace ground-station terminal. Dense, functional,
 * typographically driven. Space Mono for all technical readouts;
 * system-ui for prose labels. Amber as the primary accent — the
 * color of a star seen through atmosphere. No rounded bubbles,
 * no glassmorphism gradients, no generic dark-dashboard clichés.
 */

@import url('https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400&display=swap');

/* ── Design tokens ──────────────────────────────────────────────────── */
:root {
  --void:        #010306;        /* near-black space background */
  --surface:     #05090f;        /* panel surface */
  --surface2:    #0a1018;        /* slightly lighter surface */
  --border:      rgba(255,175,30,0.13);   /* amber border — subtle */
  --border2:     rgba(255,255,255,0.06);  /* for table dividers */
  --text:        #b8c8d8;
  --text-dim:    #3d5060;
  --text-bright: #e8f0f8;
  --amber:       #ffaa00;        /* primary accent */
  --amber-dim:   rgba(255,170,0,0.12);
  --cyan:        #00d4ff;        /* live data highlight */
  --critical:    #ff2040;
  --critical-bg: rgba(255,32,64,0.08);
  --critical-bd: rgba(255,32,64,0.35);
  --warning:     #ff7700;
  --warning-bg:  rgba(255,119,0,0.07);
  --warning-bd:  rgba(255,119,0,0.30);
  --safe:        #00cc66;

  --mono:   'Space Mono', 'Courier New', monospace;
  --sans:   system-ui, -apple-system, 'Segoe UI', sans-serif;

  --panel-w:   340px;
  --topbar-h:  44px;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--void);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

/* ── Canvas ──────────────────────────────────────────────────────────── */
#canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

/* ── Loading screen ──────────────────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--void);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.6s ease;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loader-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.loader-logo {
  font-family: var(--mono);
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.25em;
  line-height: 1;
}
.loader-sub {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  margin-bottom: 1.5rem;
}
.spinner {
  width: 28px; height: 28px;
  border: 2px solid rgba(255,170,0,0.15);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-msg {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
}

/* ── Top bar ─────────────────────────────────────────────────────────── */
#top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: rgba(1,3,6,0.96);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  z-index: 500;
  gap: 1.25rem;
}

/* Brand */
.bar-brand {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  flex-shrink: 0;
}
.brand-mark {
  color: var(--amber);
  font-size: 1rem;
}
.brand-title {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.15em;
}
.brand-sep {
  font-family: var(--mono);
  color: var(--text-dim);
  font-size: 0.8rem;
}
.brand-sub {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.12em;
}

/* Stat boxes */
.bar-stats {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  overflow: hidden;
}
.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.18rem 0.7rem;
  border: 1px solid var(--border);
  background: rgba(255,170,0,0.03);
  min-width: 56px;
}
.stat-box--alert { border-color: var(--critical-bd); background: var(--critical-bg); }
.stat-box--warn  { border-color: var(--warning-bd);  background: var(--warning-bg);  }
.stat-label {
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  line-height: 1;
}
.stat-val {
  font-family: var(--mono);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--cyan);
  line-height: 1.3;
}
.stat-box--alert .stat-val { color: var(--critical); }
.stat-box--warn  .stat-val { color: var(--warning);  }

/* Right side */
.bar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}
.live-dot {
  width: 6px; height: 6px;
  background: var(--safe);
  border-radius: 50%;
  animation: pulse-dot 2s ease infinite;
  box-shadow: 0 0 6px var(--safe);
}
@keyframes pulse-dot {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.3; }
}
.live-label {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--safe);
  letter-spacing: 0.12em;
}
.bar-time {
  font-family: var(--mono);
  font-size: 0.58rem;
  color: var(--text-dim);
  display: none;   /* shown on ≥900px */
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
button {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--amber);
  background: rgba(255,170,0,0.07);
  border: 1px solid var(--border);
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  min-height: 30px;
  touch-action: manipulation;
}
button:hover  { background: rgba(255,170,0,0.14); border-color: rgba(255,170,0,0.4); }
button:active { background: rgba(255,170,0,0.22); }

/* ── Side panel ──────────────────────────────────────────────────────── */
#side-panel {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  background: rgba(2,5,10,0.97);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 400;
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  /* Subtle grid pattern on panel */
  background-image:
    linear-gradient(rgba(255,170,0,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,170,0,0.02) 1px, transparent 1px);
  background-size: 24px 24px;
}
#side-panel.collapsed {
  transform: translateX(calc(var(--panel-w) + 1px));
}

/* Mobile handle (hidden desktop) */
.panel-handle {
  display: none;
  width: 32px; height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 2px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Mobile stat chips row */
#mobile-chips {
  display: none;
  gap: 0.4rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.75rem 0;
}

/* ── Panel sections ──────────────────────────────────────────────────── */
.panel-section {
  border-bottom: 1px solid var(--border2);
  padding: 0.8rem 0.85rem;
  flex-shrink: 0;
}

.section-head {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.12em;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.section-mark {
  color: var(--amber);
  font-size: 0.5rem;
  opacity: 0.6;
}
.section-count {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 0.58rem;
}
.panel-hint {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
  font-style: italic;
}
.panel-footer {
  margin-top: auto;
  padding: 0.7rem 0.85rem;
  font-size: 0.6rem;
  color: var(--text-dim);
  line-height: 1.8;
  border-top: 1px solid var(--border2);
}

/* ── Table ───────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.7rem;
}
.data-table th {
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--text-dim);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-align: left;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: rgba(255,170,0,0.03);
}
.data-table td {
  padding: 0.42rem 0.4rem;
  border-bottom: 1px solid var(--border2);
  vertical-align: middle;
  font-family: var(--mono);
  font-size: 0.68rem;
}
.data-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}
.data-table tbody tr:hover  { background: rgba(255,255,255,0.04); }
.data-table tbody tr:active { background: rgba(255,255,255,0.08); }
.data-table tbody tr.selected {
  background: rgba(255,170,0,0.07);
  border-left: 2px solid var(--amber);
}
.data-table tbody tr.row-critical {
  background: var(--critical-bg);
  border-left: 2px solid var(--critical);
  animation: row-pulse-critical 3s ease infinite;
}
.data-table tbody tr.row-warning {
  background: var(--warning-bg);
  border-left: 2px solid var(--warning);
}
@keyframes row-pulse-critical {
  0%,100% { background: var(--critical-bg); }
  50%      { background: rgba(255,32,64,0.14); }
}
.obj-pair {
  font-size: 0.65rem;
  line-height: 1.5;
  color: var(--text);
}
.obj-pair-sep { color: var(--text-dim); display: block; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.num-critical { color: var(--critical); }
.num-warning  { color: var(--warning);  }

/* Badges */
.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.12rem 0.35rem;
  white-space: nowrap;
}
.badge-critical { color: var(--critical); border: 1px solid var(--critical-bd); background: var(--critical-bg); }
.badge-warning  { color: var(--warning);  border: 1px solid var(--warning-bd);  background: var(--warning-bg); }
.badge-safe     { color: var(--safe);     border: 1px solid rgba(0,204,102,0.3); background: rgba(0,204,102,0.07); }
.prob {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--text-dim);
  display: block;
  margin-top: 1px;
}

/* ── ML readout ───────────────────────────────────────────────────────── */
.ml-readout {
  display: flex;
  gap: 0;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
}
.ml-readout-item {
  flex: 1;
  padding: 0.5rem 0.6rem;
  text-align: center;
  border-right: 1px solid var(--border);
}
.ml-readout-item:last-child { border-right: none; }
.ml-readout-divider { width: 1px; background: var(--border); }
.readout-num {
  display: block;
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--cyan);
  line-height: 1.1;
}
.readout-lbl {
  display: block;
  font-family: var(--mono);
  font-size: 0.52rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  margin-top: 2px;
}

.feat-bars { display: flex; flex-direction: column; gap: 0.3rem; }
.feat-row  { display: flex; align-items: center; gap: 0.5rem; }
.feat-name {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--text-dim);
  min-width: 96px;
}
.feat-bar-bg {
  flex: 1; height: 6px;
  background: rgba(255,255,255,0.05);
  overflow: hidden;
}
.feat-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--amber), rgba(255,170,0,0.4));
}
.feat-val {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--text-dim);
  min-width: 30px;
  text-align: right;
}

/* ── Legend ───────────────────────────────────────────────────────────── */
.legend { display: flex; flex-direction: column; gap: 0.4rem; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.7rem;
  color: var(--text-dim);
}
.legend-dot  { width: 8px; height: 8px; flex-shrink: 0; }
.legend-sat  { background: #00BFFF; border-radius: 50%; }
.legend-deb  { background: #888; }
.legend-crit { background: var(--critical); border-radius: 50%; box-shadow: 0 0 5px var(--critical); }
.legend-warn { background: var(--warning);  border-radius: 50%; box-shadow: 0 0 5px var(--warning); }

/* ── Tooltip ─────────────────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  background: rgba(2,5,10,0.96);
  border: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
  font-size: 0.72rem;
  color: var(--text);
  pointer-events: none;
  z-index: 800;
  max-width: 190px;
  display: none;
  line-height: 1.6;
}
#tooltip.visible { display: block; }
#tooltip .tt-name {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--amber);
  letter-spacing: 0.05em;
}
#tooltip .tt-row {
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--text-dim);
}

/* ── Controls hint ───────────────────────────────────────────────────── */
#controls-hint {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(1,3,6,0.90);
  border: 1px solid var(--border2);
  padding: 0.3rem 1rem;
  font-family: var(--mono);
  font-size: 0.58rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  z-index: 400;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
}
#controls-hint button { pointer-events: all; }
#btn-reset-view { padding: 0.25rem 0.6rem; min-height: 24px; font-size: 0.58rem; }

/* ── Floating mobile panel button ────────────────────────────────────── */
#btn-open-panel {
  display: none;
  position: fixed;
  bottom: 3.6rem;
  right: 0.9rem;
  z-index: 450;
  background: var(--amber);
  color: #000;
  border: none;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 0.55rem 1rem;
  min-height: 40px;
  box-shadow: 0 2px 20px rgba(255,170,0,0.35);
}
#btn-open-panel:hover  { background: #ffc400; border: none; }
#btn-open-panel:active { opacity: 0.85; }

/* Show bar-time on wide screens */
@media (min-width: 900px) {
  .bar-time { display: block; }
}

/* ════════════════ TABLET ≤ 768px ═══════════════════════════════════ */
@media (max-width: 768px) {
  :root { --panel-w: 280px; }
  .bar-time { display: none; }
  .brand-sub { display: none; }
  .stat-box { min-width: 48px; padding: 0.15rem 0.5rem; }
}

/* ════════════════ MOBILE ≤ 600px  —  bottom sheet ══════════════════ */
@media (max-width: 600px) {
  :root { --topbar-h: 48px; }

  .bar-stats   { display: none; }
  .bar-time    { display: none; }
  .live-label  { display: none; }
  .brand-sub   { display: none; }
  .brand-sep   { display: none; }
  #top-bar { gap: 0; justify-content: space-between; padding: 0 0.75rem; }

  /* Bottom sheet */
  #side-panel {
    top: auto;
    left: 0; right: 0; bottom: 0;
    width: 100% !important;
    max-height: 74vh;
    border-left: none;
    border-top: 2px solid var(--amber);
    transform: translateY(100%);
    box-shadow: 0 -8px 40px rgba(0,0,0,0.7);
    background-image: none;
    background-color: rgba(2,4,9,0.98);
  }
  #side-panel:not(.collapsed) { transform: translateY(0); }
  #side-panel.collapsed        { transform: translateY(100%); }

  .panel-handle   { display: block; }
  #mobile-chips   { display: flex; }
  #btn-open-panel { display: flex; align-items: center; }

  #controls-hint { bottom: 4.4rem; font-size: 0.54rem; }

  .col-vel { display: none; }
  .data-table td { padding: 0.5rem 0.4rem; }
  button { min-height: 38px; }

  #tooltip { display: none !important; }
}

/* ════════════════ SMALL PHONE ≤ 400px ══════════════════════════════ */
@media (max-width: 400px) {
  .brand-title { font-size: 0.78rem; letter-spacing: 0.08em; }
  .live-dot, .live-label { display: none; }
  .feat-name { min-width: 72px; }
  .panel-section { padding: 0.65rem 0.7rem; }
}
