/* ===== Satélites en Vivo — dark mode espacial =====
   v3: brief UI/UX de Mateo (2026-08-23) — tipografía dual self-hosted,
       controles Leaflet al tema, paleta categórica afinada, ficha animada,
       accesibilidad (focus-visible / reduced-motion), modo cine. */

/* ----- Fuentes self-hosted (CSP: font-src 'self') — variable fonts latin ----- */
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('fonts/SpaceGrotesk.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url('fonts/JetBrainsMono.woff2') format('woff2');
}

:root {
  --bg: #05070f;
  --bg-panel: rgba(10, 14, 28, 0.88);
  --bg-panel-solid: #0a0e1c;
  --border: rgba(120, 150, 220, 0.18);
  --text: #dfe6ff;
  --text-dim: #8b96b8;
  --accent: #4cc9f0;
  --iss: #00f5ff;
  --starlink: #9db4ff;   /* brief #3: más luminancia (antes #7b8cde, ~3.5:1) */
  --station: #ffe066;    /* brief #3: dorado puro, separado de Clima */
  --gps: #80ed99;
  --weather: #ff7a59;    /* brief #3: coral, separado de Estaciones */
  --visual: #f4f1de;
  --font-display: 'Space Grotesk', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body, #app {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 14.5px;
}

/* ---------- Mapa ---------- */
#map {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 1;
}
.leaflet-container { background: var(--bg); }
/* oscurecer los tiles y levantar contraste: los puntos estallan sobre el fondo */
.leaflet-tile-pane { filter: brightness(0.82) contrast(1.05) saturate(0.9); }

/* ---------- Controles Leaflet al tema oscuro (brief #1) ---------- */
.leaflet-bar {
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 24px rgba(0,0,0,.45) !important;
  overflow: hidden;
}
.leaflet-bar a {
  background: var(--bg-panel) !important;
  border-bottom: 1px solid var(--border) !important;
  color: var(--text) !important;
  backdrop-filter: blur(8px);
  transition: background .15s, color .15s;
}
.leaflet-bar a:last-child { border-bottom: none !important; }
.leaflet-bar a:hover { background: rgba(76,201,240,.14) !important; color: var(--accent) !important; }
.leaflet-bar a.leaflet-disabled { background: rgba(10,14,28,.5) !important; color: rgba(139,150,184,.45) !important; }
.leaflet-control-attribution {
  background: rgba(5,7,15,.7) !important;
  color: var(--text-dim) !important;
  font-size: 10px !important;
  padding: 2px 8px !important;
  border-radius: 6px 0 0 0;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; text-decoration: underline; }

/* ---------- Barra superior ---------- */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(5,7,15,0.92), rgba(5,7,15,0.55) 75%, transparent);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { font-size: 26px; filter: drop-shadow(0 0 8px rgba(76,201,240,.7)); }
.brand-text h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: linear-gradient(90deg, #fff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}
.tagline { font-size: 11px; color: var(--text-dim); letter-spacing: 0.04em; white-space: nowrap; }

/* ---------- Buscador ---------- */
.search-wrap { position: relative; flex: 1; max-width: 460px; margin: 0 auto; }
#search {
  width: 100%;
  padding: 9px 14px 9px 36px;   /* hueco para la lupa (brief #7) */
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%238b96b8' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='16.5' y1='16.5' x2='21' y2='21'/%3E%3C/svg%3E") no-repeat 11px center;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 13px;
  outline: none;
  backdrop-filter: blur(8px);
  transition: border-color .2s, box-shadow .2s;
}
#search::placeholder { color: var(--text-dim); }
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76,201,240,.18); }

#search-results {
  position: absolute;
  top: calc(100% + 6px); left: 0; right: 0;
  max-height: 320px;
  overflow-y: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel-solid);
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
}
#search-results.hidden { display: none; }
.sr-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 9px 13px;
  cursor: pointer;
  border-bottom: 1px solid rgba(120,150,220,.08);
}
.sr-item:last-child { border-bottom: none; }
.sr-item:hover, .sr-item.active { background: rgba(76,201,240,.12); }
.sr-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-name mark { background: transparent; color: var(--accent); font-weight: 700; }
.sr-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-dim); white-space: nowrap; }
.sr-empty { padding: 12px 13px; color: var(--text-dim); font-size: 12.5px; cursor: default; }

/* ---------- Botones top ---------- */
.top-actions { display: flex; gap: 8px; }
.btn-iss, .btn-filters {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .05em;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all .2s;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn-iss { color: var(--iss); border-color: rgba(0,245,255,.35); }
.btn-iss:hover { box-shadow: 0 0 14px rgba(0,245,255,.35); }
.btn-filters:hover { border-color: var(--accent); }
.btn-filters { position: relative; }
.fbadge {
  display: inline-block; min-width: 16px; margin-left: 6px;
  font-family: var(--font-mono); font-size: 10px; line-height: 16px;
  text-align: center; border-radius: 9px;
  background: rgba(120,150,220,.16); color: var(--text-dim);
}
.fbadge.warn { background: var(--accent); color: #04121a; font-weight: 700; }

/* ---------- Panel de filtros ---------- */
#filter-panel {
  position: absolute;
  top: 64px; right: 16px;
  z-index: 1000;
  width: 210px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.filter-title { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--text-dim); margin-bottom: 9px; }
/* piezas del bottom sheet (móvil): en desktop el panel lateral queda como está */
.sheet-handle, #btn-iss-sheet, #sheet-scrim { display: none; }
#filter-chips { display: flex; flex-direction: column; gap: 6px; }
.chip {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(120,150,220,.06);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  user-select: none;
  transition: all .15s;
  touch-action: manipulation;
}
.chip:hover { background: rgba(120,150,220,.13); }
.chip.off { opacity: .38; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 6px currentColor; }
.chip .n { margin-left: auto; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-dim); }
/* subfiltros por país (grupo latam): anidados, más compactos que los chips de grupo */
#latam-subchips { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 0 6px 16px; }
#latam-subchips.hidden { display: none; }
#latam-subchips .chip.sub {
  width: auto; padding: 4px 8px; gap: 5px;
  font-size: 11px; border-radius: 7px;
  background: rgba(232,121,249,.07);   /* fuchsia del grupo latam */
}
#latam-subchips .chip.sub:hover { background: rgba(232,121,249,.16); }
#latam-subchips .chip.sub .n { margin-left: 0; font-size: 9.5px; }
.filter-foot { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-dim); }
#sat-count { font-family: var(--font-mono); color: var(--text); font-weight: 700; }

/* ---------- Ficha de satélite ---------- */
#info-card {
  position: absolute;
  left: 16px; bottom: 52px;
  z-index: 1000;
  width: 320px;
  max-width: calc(100vw - 32px);
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 50px rgba(0,0,0,.6);
  /* brief #4: entrada/salida animada (la técnica .hidden cambia abajo) */
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
#info-card.hidden {
  display: block;              /* override de la técnica display:none */
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  pointer-events: none;
}
#info-close {
  position: absolute; top: 10px; right: 10px;
  background: none; border: none; color: var(--text-dim);
  font-size: 15px; cursor: pointer; padding: 4px;
  touch-action: manipulation;
}
#info-close:hover { color: var(--text); }
.info-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 13px; padding-right: 22px; }
.info-head h2 { font-size: 19px; font-weight: 700; letter-spacing: .02em; }
/* brief #4: pill "EN VIVO" — los datos de la ficha se actualizan en tiempo real */
#info-name::after {
  content: '● EN VIVO';
  display: inline-block;
  margin-left: 9px;
  vertical-align: 2px;
  font-family: var(--font-mono);
  font-size: 8.5px; font-weight: 700; letter-spacing: .12em;
  color: #7dffb2;
  animation: livepulse 1.8s ease-in-out infinite;
}
@keyframes livepulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.badge {
  font-size: 10px; font-weight: 800; letter-spacing: .1em;
  padding: 3px 8px; border-radius: 20px;
  color: #041018; background: var(--iss);
  box-shadow: 0 0 12px rgba(0,245,255,.5);
}
.badge.hidden { display: none; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.field label { display: block; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-dim); margin-bottom: 2px; }
.field span { font-family: var(--font-mono); font-size: 13px; font-weight: 600; }
.field span small { display: block; font-size: 10px; font-weight: 400; color: var(--text-dim); margin-top: 1px; }
.info-note { margin-top: 13px; font-size: 11px; color: var(--text-dim); line-height: 1.45; }
.info-micro { margin-top: 11px; font-size: 11.5px; line-height: 1.45; color: var(--accent); opacity: .85; }
.info-actions { display: flex; gap: 8px; margin-top: 12px; }
.copy-btn {
  flex: 1; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: rgba(120,150,220,.07);
  color: var(--text); font: 700 12px var(--font-display);
  letter-spacing: .04em; cursor: pointer; transition: all .18s;
  touch-action: manipulation;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn.ok { border-color: #7dffb2; color: #7dffb2; }

/* ---------- Barra de estado ---------- */
#statusbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 1000;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  font-size: 11px;
  color: var(--text-dim);
  background: linear-gradient(0deg, rgba(5,7,15,0.92), rgba(5,7,15,0.5) 75%, transparent);
  pointer-events: none;
}
#status-tle { font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status-clock, #viewport-count { font-family: var(--font-mono); font-size: 10.5px; white-space: nowrap; }
.sep { opacity: .4; }
.credits { margin-left: auto; opacity: .75; white-space: nowrap; }
/* anchos intermedios: créditos fuera para que el resto no colisione (QA 780px) */
@media (max-width: 1000px) { .credits { display: none; } }
/* ventanas bajas: los hints de la columna de vista chocan con el panel de filtros */
@media (max-height: 640px) { .tt-hint, .proj-hint { display: none; } }

/* ---------- Splash ---------- */
#splash {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #0b1026 0%, #05070f 70%);
  transition: opacity .6s;
}
#splash.done { opacity: 0; pointer-events: none; }
.splash-inner { text-align: center; }
.splash-sat { font-size: 54px; animation: float 2.4s ease-in-out infinite; filter: drop-shadow(0 0 18px rgba(76,201,240,.8)); }
@keyframes float { 0%,100% { transform: translateY(0) rotate(-8deg); } 50% { transform: translateY(-14px) rotate(8deg); } }
.splash-msg { margin: 18px 0 12px; color: var(--text-dim); letter-spacing: .06em; font-size: 13px; }
.splash-bar { width: 220px; height: 3px; margin: 0 auto; border-radius: 3px; background: rgba(120,150,220,.15); overflow: hidden; }
#splash-progress { height: 100%; width: 0%; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--iss)); transition: width .3s; box-shadow: 0 0 10px var(--accent); }

/* ---------- Accesibilidad (brief #9) ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
#search:focus-visible { outline: none; }   /* ya tiene su propio tratamiento de foco */
@media (prefers-reduced-motion: reduce) {
  .splash-sat { animation: none; }
  #info-name::after { animation: none; }
  #info-card { transition: none; }
  #splash { transition: none; }
}

/* ---------- Modo cine (brief #11, tecla H) ---------- */
body.cinema #topbar, body.cinema #statusbar,
body.cinema #filter-panel, body.cinema #info-card,
body.cinema .tt-control, body.cinema .tt-hint {
  opacity: 0;
  pointer-events: none;
}
#topbar, #statusbar, #filter-panel, #info-card { transition: opacity .25s ease; }
#info-card { transition: opacity .2s ease, transform .2s ease, visibility .2s; }

/* ---------- Responsive ---------- */
/* punteros táctiles: el control de zoom sobra (pinch y doble-tap lo cubren, spec §1.6) */
@media (pointer: coarse) {
  .leaflet-control-zoom { display: none; }
}

/* Sistema de zonas móvil (spec Mateo §1): cada componente tiene su zona y en
   la zona 4 (inferior) solo existe UNA cosa a la vez — ficha, chip o sheet */
@media (max-width: 760px) {
  /* zona 1 — topbar en una sola fila: marca + búsqueda siempre visible + filtros */
  .brand-text .tagline { display: none; }
  .brand-text h1 { font-size: 13px; }
  #topbar { flex-wrap: nowrap; gap: 8px; padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px; }
  .search-wrap { order: 0; flex: 1 1 auto; min-width: 0; max-width: none; margin: 0; }
  #btn-iss { display: none; }   /* pasa a la cabecera del sheet de filtros (spec §1.3) */

  /* zona 4 — filtros como bottom sheet (spec §1.4) */
  #filter-panel {
    top: auto; left: 0; right: 0; bottom: calc(30px + env(safe-area-inset-bottom, 0px));
    width: auto; max-height: 55vh; overflow-y: auto;
    padding: 8px 14px 10px;
    border-radius: 16px 16px 0 0;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  #filter-panel.collapsed { display: none; }
  .sheet-handle { display: block; width: 32px; height: 4px; border-radius: 2px;
    background: rgba(139,150,184,.45); margin: 0 auto 8px; }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
  .sheet-head .filter-title { margin-bottom: 0; }
  #btn-iss-sheet { display: block; padding: 7px 12px; font-size: 11.5px; }
  #filter-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  #sheet-scrim { display: block; position: absolute; inset: 0; z-index: 999;
    background: rgba(2,4,12,.5); }
  #sheet-scrim[hidden] { display: none; }
  /* con el sheet abierto, la zona 4 es del sheet: la ficha/chip se retira */
  body.sheet-open #info-card { visibility: hidden; }

  /* ficha acotada: nunca más de la mitad de la pantalla, con scroll propio */
  #info-card { left: 10px; right: 10px; bottom: 48px; width: auto; padding: 12px;
    max-height: 52dvh; overflow-y: auto; }
  #info-card.as-chip { max-height: none; overflow: visible; }
  .info-grid { gap: 7px 10px; }
  .credits { display: none; }
  /* aire a la derecha: la atribución de Leaflet vive en la esquina inferior derecha */
  #statusbar { padding-right: 150px; }
  #viewport-count { display: none; }
}
/* pantallas muy angostas: solo el glifo de marca (spec §1.3) */
@media (max-width: 360px) { .brand-text { display: none; } }

/* notch / barra de gestos: respeta las zonas seguras (viewport-fit=cover) */
#statusbar { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
@media (max-width: 760px) {
  #info-card { bottom: calc(48px + env(safe-area-inset-bottom, 0px)); }
}
