:root {
  --bg: #0a0e12;
  --panel: rgba(14, 19, 25, 0.78);
  --panel-border: rgba(200, 255, 0, 0.12);
  --text: #e8eef2;
  --text-mut: #8a96a3;
  --accent: #c8ff00;
  --accent-soft: rgba(200, 255, 0, 0.16);
  --beluga: #ff8a3d;
  --beluga-soft: rgba(255, 138, 61, 0.25);
  --me: #4ea1ff;
  --me-soft: rgba(78, 161, 255, 0.30);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-feature-settings: "tnum" 1, "ss01" 1;
  -webkit-font-smoothing: antialiased;
}

#map {
  position: absolute;
  inset: 0;
}

/* ---- panels ---- */
.panel {
  position: absolute;
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  padding: 10px 14px;
  z-index: 5;
  pointer-events: auto;
  user-select: none;
}

.panel--brand {
  top: 14px;
  left: 14px;
  padding: 10px 16px 11px;
}
.panel__title {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  line-height: 1;
}
.panel__title::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: 2px;
  box-shadow: 0 0 8px var(--accent);
}
.panel__sub {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-mut);
  margin-top: 4px;
}

.filters {
  position: absolute;
  top: 76px;
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 320px;
  z-index: 5;
  pointer-events: auto;
}
.filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--panel-border);
  color: var(--text-mut);
  border-radius: 100px;
  padding: 6px 11px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease, border-color 120ms ease;
  user-select: none;
}
.filter:hover:not([disabled]) { color: var(--text); border-color: rgba(200,255,0,0.3); }
.filter--active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0e12;
  font-weight: 700;
}
.filter--active svg { color: #0a0e12; }
.filter--beluga.filter--active {
  background: var(--beluga);
  border-color: var(--beluga);
  color: #0a0e12;
}
.filter[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}
.filter svg {
  width: 14px;
  height: 14px;
  color: currentColor;
  flex-shrink: 0;
}

.panel--sidebar {
  top: 14px;
  right: 14px;
  width: 290px;
  max-height: calc(100vh - 28px);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.sidebar__head {
  padding: 12px 14px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar__title {
  padding: 10px 14px 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-mut);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.sidebar__from {
  font-size: 10px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-mut);
  opacity: 0.7;
}
.stats__row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
}
.stats__row--mut {
  color: var(--text-mut);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 4px;
}
.stats__label {
  color: var(--text-mut);
  font-size: 12px;
}
#count {
  font-weight: 600;
  font-size: 16px;
  color: var(--accent);
  min-width: 22px;
  text-align: right;
}
.nearby {
  list-style: none;
  margin: 0;
  padding: 4px 6px 10px;
  overflow-y: auto;
  flex: 1;
}
.nearby__empty {
  color: var(--text-mut);
  font-size: 12px;
  padding: 12px 10px;
  text-align: center;
}
.nearby__item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 100ms ease;
}
.nearby__item:hover { background: rgba(255,255,255,0.05); }
.nearby__item--beluga {
  background: rgba(255, 138, 61, 0.08);
  border: 1px solid rgba(255, 138, 61, 0.4);
}
.nearby__item--beluga:hover { background: rgba(255, 138, 61, 0.14); }
.nearby__cs {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--text);
}
.nearby__item--beluga .nearby__cs { color: var(--beluga); }
.nearby__dist {
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  white-space: nowrap;
}
.nearby__item--beluga .nearby__dist { color: var(--beluga); }
.nearby__meta {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-mut);
  margin-top: 1px;
}
.nearby__meta b {
  font-weight: 600;
  color: var(--text);
}
.nearby__bullet {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: 1px;
  flex-shrink: 0;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-mut);
  flex-shrink: 0;
}
.dot--live {
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-soft);
  animation: pulse 2s infinite;
}
.dot--off {
  background: #ff5a5a !important;
  animation: none !important;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 var(--accent-soft); }
  70%  { box-shadow: 0 0 0 10px rgba(200,255,0,0); }
  100% { box-shadow: 0 0 0 0 rgba(200,255,0,0); }
}

.panel--controls {
  bottom: 22px;
  left: 14px;
  padding: 6px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms ease;
}
.btn:hover { background: rgba(255,255,255,0.06); }
.btn:active { background: rgba(255,255,255,0.10); }
.btn svg { color: var(--accent); }

.attribution {
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-size: 10px;
  color: var(--text-mut);
  background: rgba(10,14,18,0.55);
  padding: 3px 8px;
  border-radius: 4px;
  z-index: 4;
  pointer-events: none;
}

/* ---- popup ---- */
.maplibregl-popup-content {
  background: var(--panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--panel-border);
  border-radius: 10px !important;
  box-shadow: var(--shadow);
  font-family: inherit;
  padding: 10px 12px !important;
  min-width: 180px;
}
.maplibregl-popup-tip { display: none !important; }
.maplibregl-popup-close-button {
  color: var(--text-mut) !important;
  font-size: 16px;
  padding: 4px 8px !important;
}

.popup-title {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--accent);
}
.popup-title--beluga { color: var(--beluga); }
.popup-sub {
  color: var(--text-mut);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.popup-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.popup-grid dt {
  color: var(--text-mut);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.popup-grid dd { margin: 0; color: var(--text); }

/* ---- ruta origen → destino ---- */
.popup-route {
  margin: 2px 0 8px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  font-size: 13px;
}
.route { color: var(--text); letter-spacing: 0.02em; }
.route b { font-weight: 700; color: var(--accent); }
.route__arrow { color: var(--text-mut); margin: 0 3px; }
.route--loading, .route--none { color: var(--text-mut); font-size: 12px; font-style: italic; }

/* ---- modelo exacto + foto en el popup ---- */
.popup-photo {
  margin: -4px -4px 8px;
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}
.popup-photo[hidden] { display: none; }
.popup-photo img {
  width: 100%;
  height: auto;
  max-height: 130px;
  object-fit: cover;
  display: block;
}
.popup-model {
  font-size: 12px;
  color: var(--text-mut);
  margin: -2px 0 7px;
}
.popup-model:empty { display: none; }
.popup-model__name { color: var(--text); font-weight: 600; }
.nearby__route {
  grid-column: 1 / -1;
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-mut);
}
.nearby__route .route b { font-size: 11px; color: var(--text); }
.nearby__item--beluga .nearby__route .route b { color: var(--beluga); }

/* ---- legend ---- */
.legend-toggle {
  bottom: 22px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  z-index: 6;
}
.legend-toggle:hover { background: rgba(20,28,36,0.85); }
.legend-toggle svg { color: var(--accent); }

.panel--legend {
  bottom: 70px;
  right: 14px;
  width: 280px;
  max-width: calc(100vw - 28px);
  padding: 14px 16px 12px;
  z-index: 6;
}
.panel--legend[hidden] { display: none; }
.legend__title {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-mut);
  margin-bottom: 10px;
}
.legend__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.legend__item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: center;
}
.legend__icon {
  width: 28px;
  height: 22px;
  display: inline-block;
  position: relative;
}
.legend__icon--plane {
  background: linear-gradient(135deg, #ff6b35 0%, #ffd633 25%, #c8ff00 50%, #4ea1ff 75%, #bf94ff 100%);
  clip-path: polygon(50% 0, 56% 28%, 100% 40%, 100% 50%, 56% 50%, 54% 78%, 70% 92%, 70% 96%, 50% 88%, 30% 96%, 30% 92%, 46% 78%, 44% 50%, 0 50%, 0 40%, 44% 28%);
}
.alt-chip {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  vertical-align: 0;
  margin-right: 2px;
}
.legend__icon--beluga {
  background: var(--beluga);
  clip-path: polygon(50% 0, 56% 28%, 100% 40%, 100% 50%, 56% 50%, 54% 78%, 70% 92%, 70% 96%, 50% 88%, 30% 96%, 30% 92%, 46% 78%, 44% 50%, 0 50%, 0 40%, 44% 28%);
  box-shadow: 0 0 10px var(--beluga-soft);
}
.legend__icon--me {
  width: 16px;
  height: 16px;
  margin: 3px 0 0 6px;
  background: var(--me);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--me-soft);
}
.legend__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}
.legend__desc {
  font-size: 11px;
  color: var(--text-mut);
  margin-top: 2px;
  line-height: 1.35;
}

/* ---- toast ---- */
.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translate(-50%, -10px);
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--beluga);
  border-radius: var(--radius);
  box-shadow: 0 12px 36px rgba(0,0,0,0.5), 0 0 28px var(--beluga-soft);
  color: var(--text);
  padding: 11px 16px;
  font-size: 13px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transition: opacity 240ms ease, transform 240ms ease;
  pointer-events: auto;
}
.toast[hidden] { display: none; }
.toast--show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast__icon {
  width: 16px;
  height: 16px;
  background: var(--beluga);
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 12px var(--beluga);
}
.toast__title {
  font-weight: 700;
  color: var(--beluga);
}
.toast__close {
  background: transparent;
  border: 0;
  color: var(--text-mut);
  font-size: 18px;
  cursor: pointer;
  padding: 0 2px;
  margin-left: 4px;
}

/* ---- formulario de avisos por email ---- */
.panel--watch {
  bottom: 22px;
  left: 14px;
  width: 300px;
  max-width: calc(100vw - 28px);
  padding: 14px 16px 16px;
  z-index: 12;
}
.panel--watch[hidden] { display: none; }
.watch__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.watch__title { font-weight: 700; font-size: 14px; }
.watch__close {
  background: transparent;
  border: 0;
  color: var(--text-mut);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.watch__close:hover { color: var(--text); }
.watch__hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text-mut);
  line-height: 1.4;
}
.watch__hint b { color: var(--text); }
.watch__label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mut);
  margin: 10px 0 4px;
}
.watch__mut { text-transform: none; letter-spacing: 0; opacity: 0.8; }
.watch__input {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
}
.watch__input:focus {
  outline: none;
  border-color: var(--accent);
}
.watch__zone {
  margin: 12px 0 4px;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 6px 9px;
  line-height: 1.35;
}
.watch__save {
  width: 100%;
  margin-top: 12px;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  color: #0a0e12;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 10px;
  cursor: pointer;
  transition: opacity 120ms ease;
}
.watch__save:hover { opacity: 0.9; }
.watch__save:disabled { opacity: 0.6; cursor: default; }
.watch__msg {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: 6px;
}
.watch__msg--ok { background: var(--accent-soft); color: var(--accent); }
.watch__msg--err { background: rgba(255, 90, 90, 0.15); color: #ff8a8a; }

/* ---- mobile ---- */
@media (max-width: 640px) {
  .panel--brand { padding: 8px 12px 9px; }
  .panel__title { font-size: 15px; }
  .panel__sub { display: none; }
  .panel--legend { width: calc(100vw - 28px); }

  /* Filtros en una sola fila deslizable, sin amontonarse sobre el mapa */
  .filters {
    top: 86px;
    max-width: calc(100vw - 28px);
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .filters::-webkit-scrollbar { display: none; }
  .filter { flex-shrink: 0; }

  /* Panel de aviones plegable: colapsado solo muestra la cabecera */
  .panel--sidebar {
    width: calc(100vw - 28px);
    max-height: 58vh;
  }
  .panel--sidebar .sidebar__head {
    position: relative;
    cursor: pointer;
    padding-right: 30px;
  }
  .panel--sidebar .sidebar__head::after {
    content: "▾";
    position: absolute;
    right: 12px;
    top: 11px;
    color: var(--text-mut);
    font-size: 13px;
    transition: transform 200ms ease;
  }
  .panel--sidebar:not(.is-collapsed) .sidebar__head::after {
    transform: rotate(180deg);
  }
  .panel--sidebar.is-collapsed {
    width: auto;
    max-height: none;
  }
  .panel--sidebar.is-collapsed .sidebar__title,
  .panel--sidebar.is-collapsed .nearby {
    display: none;
  }
  /* Colapsado: cabecera de una sola línea para no chocar con los filtros */
  .panel--sidebar.is-collapsed .stats__row--mut {
    display: none;
  }
  .panel--sidebar.is-collapsed .sidebar__head {
    padding: 9px 30px 9px 14px;
    border-bottom: 0;
  }

  /* Formulario de avisos centrado en móvil, sin tapar los controles */
  .panel--watch {
    left: 14px;
    right: 14px;
    width: auto;
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
  }
}
