/* ============================================================
   styles.css — Estilos de la aplicación Trenísimo
   ============================================================ */

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #1a2035;
  --bg-card-hover: #1e2a45;
  --text-primary: #e8eaf0;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #06b6d4;
  --border: #1f2937;
  --border-light: #374151;
  --shadow: rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-user-drag: none; }

img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  draggable: false;
}

html, body {
  height: 100%;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ---- LAYOUT ---- */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: 360px;
  min-width: 360px;
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform var(--transition), width var(--transition);
  overflow: hidden;
}

/* Scrollable area below the header */
.sidebar-scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.sidebar-scroll-area::-webkit-scrollbar { width: 5px; }
.sidebar-scroll-area::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll-area::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--bg-primary), var(--bg-secondary));
}

.sidebar-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.sidebar-close-btn {
  display: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.sidebar-close-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.4);
}

.app-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-logo-img {
  height: 50px;
  width: auto;
  max-width: 250px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.8)) drop-shadow(0 0 10px rgba(255, 255, 255, 0.45));
}

/* Mobile logo toggle: full logo on desktop, favicon on mobile */
.app-logo-mobile {
  display: none;
}

.app-logo-full {
  display: block;
}

/* Map brand icon (favicon on map bar) — hidden on desktop, shown on mobile */
.map-brand-icon {
  display: none;
  height: 36px;
  width: 36px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.8)) drop-shadow(0 0 10px rgba(255, 255, 255, 0.45));
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.live-dot {
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.datetime-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.current-date {
  font-size: 13px;
  color: var(--text-secondary);
}

.current-time {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

/* ---- STATS BAR ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.stat-card:hover {
  background: var(--bg-card-hover);
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-value.text-success { color: var(--success); }
.stat-value.text-danger { color: var(--danger); }
.stat-value.text-warning { color: var(--warning); }
.stat-value.text-info { color: var(--info); }
.stat-value.text-accent { color: var(--accent-light); }

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
  line-height: 1.3;
}

/* ---- FILTERS ---- */
.filters-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.filters-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  font-weight: 600;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border-light);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.filter-chip:hover {
  border-color: var(--accent);
  color: var(--accent-light);
}

.filter-chip.active {
  border-color: var(--chip-color, var(--accent));
  background: rgba(59, 130, 246, 0.12);
  color: var(--text-primary);
}

.filter-chip .chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chip-color, var(--accent));
}

.filter-chip .chip-count {
  font-size: 10px;
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 5px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}

/* ---- SEARCH ---- */
.search-box {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.search-input-wrapper {
  position: relative;
}

.search-input-wrapper input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}

.search-input-wrapper input:focus {
  border-color: var(--accent);
}

.search-input-wrapper input::placeholder {
  color: var(--text-muted);
}

.search-input-wrapper .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}

/* ---- TABS SEGMENTED CAPSULE SELECTOR ---- */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 5px;
  background: rgba(13, 20, 36, 0.85);
  backdrop-filter: blur(12px);
  border-radius: 12px;
  margin: 10px 14px 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: visible;
}

.tab {
  position: relative;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  outline: none;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}

.tab:hover {
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.06);
}

.tab.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(30, 58, 138, 0.35));
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #38bdf8;
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.25), inset 0 1px 1px rgba(255, 255, 255, 0.15);
}

.tab-icon {
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.tab-text {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1;
}

/* ---- TRAIN LIST ---- */
.train-list-container {
  max-height: min(420px, 45vh);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.train-list-container::-webkit-scrollbar { width: 6px; }
.train-list-container::-webkit-scrollbar-track { background: transparent; }
.train-list-container::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

.train-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.train-item:hover {
  background: var(--bg-card);
}

.train-item.selected {
  background: rgba(59, 130, 246, 0.1);
  border-left: 3px solid var(--accent);
}

.train-badge {
  min-width: 42px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.train-info {
  flex: 1;
  min-width: 0;
}

.train-number {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.train-route {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.train-meta {
  text-align: right;
}

.train-speed {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.train-status {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-on-time { color: var(--success); background: rgba(16, 185, 129, 0.1); }
.status-delayed { color: var(--warning); background: rgba(245, 158, 11, 0.1); }
.status-stopped { color: var(--danger); background: rgba(239, 68, 68, 0.1); }
.status-cancelled { color: var(--text-muted); background: rgba(107, 114, 128, 0.1); text-decoration: line-through; }

/* ---- INCIDENTS PANEL ---- */
.incident-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: all var(--transition);
  cursor: pointer;
}

.incident-item:hover {
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
}

.incident-item.selected {
  background: rgba(56, 189, 248, 0.12);
  border-left: 3px solid var(--accent);
}

.incident-map-marker {
  width: 32px;
  height: 32px;
  background: rgba(239, 68, 68, 0.95);
  border: 2px solid #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.8), 0 0 30px rgba(239, 68, 68, 0.5);
  animation: incident-pulse 1.5s infinite;
  cursor: pointer;
}

@keyframes incident-pulse {
  0% { transform: scale(1); box-shadow: 0 0 10px rgba(239, 68, 68, 0.8); }
  50% { transform: scale(1.18); box-shadow: 0 0 22px rgba(239, 68, 68, 1); }
  100% { transform: scale(1); box-shadow: 0 0 10px rgba(239, 68, 68, 0.8); }
}

.incident-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.incident-icon {
  font-size: 16px;
}

.incident-type {
  font-size: 13px;
  font-weight: 600;
}

.incident-time {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.incident-description {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 4px;
}

.incident-affected {
  font-size: 11px;
  color: var(--text-muted);
}

.incident-affected span {
  color: var(--warning);
  font-weight: 600;
}

.severity-badge {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 4px;
}

.severity-danger { background: var(--danger); }
.severity-warning { background: var(--warning); }
.severity-info { background: var(--info); }

.incident-resolved {
  opacity: 0.5;
}

.incident-resolved .incident-type::after {
  content: ' ✓ Resuelta';
  font-size: 10px;
  color: var(--success);
  font-weight: 600;
}

/* ---- MAP ---- */
.map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
  background: #090d16 !important;
}

/* Leaflet container & tile stabilization (evita cuadrados vacíos o con bordes por tiles rotos) */
.leaflet-container {
  background: #090d16 !important;
  outline: none !important;
}

.leaflet-tile {
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  -webkit-user-drag: none !important;
  user-select: none !important;
}

.leaflet-tile-container img {
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
}

img.leaflet-tile:not([src]),
img.leaflet-tile[src=""] {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Leaflet custom styling */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: 0 2px 10px var(--shadow) !important;
  margin-bottom: 140px !important;
  margin-right: 12px !important;
}

.leaflet-control-zoom a {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-card-hover) !important;
}

/* Train markers — sin parpadeos ni animaciones agresivas */
.train-marker {
  position: relative;
  cursor: pointer;
  user-select: none;
}

.train-marker:hover {
  transform: scale(1.25);
  z-index: 10000 !important;
}

/* Zona de pulsación invisible más grande que el punto de 16 px */
.train-marker::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 36px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

@media (pointer: coarse) {
  .train-marker::before {
    width: 44px;
    height: 44px;
  }
}

.marker-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.7), 0 0 12px var(--marker-glow, rgba(59, 130, 246, 0.5));
  position: relative;
}

.marker-dot.running {
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.7), 0 0 12px var(--marker-glow, rgba(59, 130, 246, 0.6));
}

.marker-dot.stopped {
  border-color: var(--danger) !important;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.7), 0 0 12px rgba(239, 68, 68, 0.8);
}

.marker-label {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.75);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.train-marker:hover .marker-label {
  opacity: 1;
}

/* Speed overlay on marker — tamaño estable para evitar saltos */
.marker-speed {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(10, 14, 26, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  min-width: 48px;
  text-align: center;
  box-sizing: border-box;
}

/* Direction arrow — centrado con el punto y orientado a lo largo de la vía */
.marker-arrow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  margin-top: -16px;
  margin-left: -16px;
  pointer-events: none;
  z-index: 5;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.85));
}

/* Route line on map */
.route-line {
  stroke-dasharray: 8 4;
}

/* ---- POPUPS (CARD) — Sin parpadeos ni animaciones de opacidad ---- */
.leaflet-popup {
  transition: none !important;
  animation: none !important;
}

.leaflet-fade-anim .leaflet-popup {
  opacity: 1 !important;
  transition: none !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 8px 30px var(--shadow) !important;
  border: 1px solid var(--border) !important;
  padding: 0 !important;
  width: 280px !important;
  box-sizing: border-box !important;
  transition: none !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  width: 280px !important;
  min-width: 280px !important;
  max-width: 280px !important;
  box-sizing: border-box !important;
  transition: none !important;
}

.leaflet-popup-tip {
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border) !important;
}

.popup-content {
  padding: 16px;
  width: 100%;
  box-sizing: border-box;
}

.popup-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.popup-operator-badge {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.popup-train-number {
  font-size: 16px;
  font-weight: 700;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 13px;
}

.popup-row .label {
  color: var(--text-muted);
}

.popup-row .value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.popup-speed {
  font-size: 24px;
  font-weight: 800;
  text-align: center;
  padding: 10px 0;
  color: var(--accent-light);
  font-variant-numeric: tabular-nums;
}

.popup-speed-val {
  font-variant-numeric: tabular-nums;
  display: inline-block;
}

.popup-speed small {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.popup-progress {
  margin-top: 10px;
}

.progress-bar {
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 3px;
  transition: width 1s ease;
}

.popup-route-endpoints {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================
   ESPACIOS MEMORIALES EN VÍA (URDA Y ADAMUZ)
   Homenaje con el máximo respeto en la LAV Madrid — Andalucía
   ============================================================ */
.memorial-map-pin {
  position: relative;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.memorial-pin-glow {
  display: none !important;
}

@keyframes memorialAura {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.3); opacity: 0.85; }
}

.memorial-pin-inner {
  position: relative;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #090d16;
  border: 1.5px solid #fbbf24;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.8), 0 0 6px rgba(251, 191, 36, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.memorial-map-pin:hover .memorial-pin-inner {
  transform: scale(1.15);
  box-shadow: 0 3px 12px rgba(251, 191, 36, 0.6);
  border-color: #fef08a;
}

.memorial-pin-ribbon {
  width: 12px;
  height: 12px;
  object-fit: contain;
  /* Resplandor blanco estático nítido en los bordes del lazo negro sobre fondo oscuro, sin animación */
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.95)) drop-shadow(0 0 5px rgba(255, 255, 255, 0.75)) drop-shadow(0 0 8px rgba(255, 255, 255, 0.4));
}

.memorial-pin-label {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 8px;
  font-weight: 800;
  color: #fbbf24;
  background: rgba(10, 14, 26, 0.92);
  border: 1px solid rgba(251, 191, 36, 0.5);
  padding: 1px 4px;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.8);
  pointer-events: none;
}
  pointer-events: none;
  letter-spacing: 0.3px;
}

/* Card del popup del Memorial */
.memorial-popup-card {
  font-family: 'Inter', sans-serif;
  padding: 6px 4px;
  color: #f8fafc;
}

.memorial-popup-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(251, 191, 36, 0.25);
}

.memorial-popup-ribbon {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.95)) drop-shadow(0 0 5px rgba(255, 255, 255, 0.75)) drop-shadow(0 0 10px rgba(255, 255, 255, 0.4));
}

.memorial-popup-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.memorial-popup-title {
  font-size: 14px;
  font-weight: 800;
  color: #ffffff;
  margin: 0;
  line-height: 1.25;
}

.memorial-popup-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 8px 10px;
}

.memorial-popup-meta-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  gap: 8px;
}

.memorial-popup-meta-item .meta-label {
  color: #94a3b8;
  font-weight: 500;
  flex-shrink: 0;
}

.memorial-popup-meta-item .meta-val {
  color: #f1f5f9;
  font-weight: 700;
  text-align: right;
}

.memorial-popup-desc {
  font-size: 11px;
  line-height: 1.55;
  color: #cbd5e1;
  margin: 0 0 14px 0;
  font-style: italic;
  padding: 0 2px;
}

.memorial-popup-btn {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.2), rgba(251, 191, 36, 0.08));
  border: 1px solid rgba(251, 191, 36, 0.5);
  color: #fbbf24;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.memorial-popup-btn:hover {
  background: rgba(251, 191, 36, 0.25);
  border-color: #fbbf24;
  color: #ffffff;
  transform: translateY(-1px);
}

/* ---- MAP OVERLAY CONTROLS ---- */
.map-overlay-top {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.map-overlay-bottom {
  position: absolute;
  bottom: 60px; /* Elevado para dejar libre el cuadrante inferior derecho (píldora de Netlify) */
  left: 14px;
  right: 14px;
  z-index: 1000;
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
  pointer-events: none;
}

.map-overlay-bottom > * {
  pointer-events: auto;
}

/* Elevar atribución de Leaflet para que no colisione con la píldora de Netlify */
.leaflet-bottom.leaflet-right {
  margin-bottom: 60px !important;
  margin-right: 14px !important;
}

/* Leyenda de Operadores (Ubicada arriba a la derecha en el mapa) */
.map-legend {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 8px 14px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

.legend-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  font-weight: 600;
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-secondary);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #fff;
  flex-shrink: 0;
}

.map-speed-display {
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 12px 16px;
  border: 1px solid var(--border);
  text-align: center;
}

.speed-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.speed-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent-light);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.speed-unit {
  font-size: 11px;
  color: var(--text-muted);
}

/* ---- TOGGLE SIDEBAR BUTTON ---- */
.sidebar-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.sidebar-toggle:hover {
  background: var(--bg-card-hover);
}

/* ---- EMPTY STATE ---- */
.empty-state {
  padding: 30px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.empty-state p {
  font-size: 13px;
}

/* ---- RADAR DISTANCIAS: EXPLICACIÓN DIDÁCTICA Y ESTADO NOMINAL ---- */
.radar-nominal-view {
  padding: 20px 16px 16px;
  text-align: center;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.radar-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.radar-status-badge .status-indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.radar-shield-icon {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 14px rgba(56, 189, 248, 0.45));
}

.radar-headline {
  font-size: 14.5px;
  font-weight: 700;
  color: #f8fafc;
  margin: 0 0 8px 0;
}

.radar-description {
  font-size: 11.5px;
  line-height: 1.55;
  color: #94a3b8;
  margin: 0 0 16px 0;
  text-align: center;
}

.radar-description strong {
  color: #38bdf8;
}

.radar-features-card {
  width: 100%;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  box-sizing: border-box;
}

.radar-feature-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.radar-feature-row .feature-icon {
  font-size: 16px;
  line-height: 1.2;
  flex-shrink: 0;
  margin-top: 1px;
}

.radar-feature-row strong {
  display: block;
  font-size: 11.5px;
  color: #f1f5f9;
  margin-bottom: 2px;
}

.radar-feature-row p {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.45;
  margin: 0;
}

/* ---- LOADING ---- */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--text-secondary);
  font-size: 14px;
}

/* ---- MOBILE RESPONSIVE ---- */

/* Mobile back button - only visible on mobile inside the sidebar */
.sidebar-back-btn {
  display: none;
  width: 100%;
  padding: 16px 20px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.15), rgba(56, 189, 248, 0.06));
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--accent-light);
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  align-items: center;
  gap: 10px;
  text-align: left;
  transition: background 0.2s;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.sidebar-back-btn span {
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(56, 189, 248, 0.15);
  border-radius: 8px;
  transition: background 0.2s;
}

.sidebar-back-btn:hover {
  background: rgba(56, 189, 248, 0.2);
}

.sidebar-back-btn:hover span {
  background: rgba(56, 189, 248, 0.3);
}

.sidebar-back-btn:active {
  background: rgba(56, 189, 248, 0.3);
}

@media (max-width: 768px) {
  .sidebar-back-btn {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    min-width: unset;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    z-index: 2000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .map-overlay-top {
    top: 10px;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 10px 12px;
  }

  .stat-card {
    padding: 8px 4px;
  }

  .stat-value {
    font-size: 16px;
  }

  .filter-chips {
    gap: 4px;
  }

  .filter-chip {
    padding: 5px 8px;
    font-size: 11px;
  }

  .map-legend {
    display: none;
  }

  .map-speed-display {
    padding: 8px 12px;
  }

  .speed-value {
    font-size: 22px;
  }

  /* Card responsive garantizada en móvil: tamaño óptimo y siempre visible en pantalla */
  .leaflet-popup {
    z-index: 1200 !important;
    pointer-events: auto !important;
    max-width: calc(100vw - 20px) !important;
  }

  .leaflet-popup-content-wrapper {
    width: min(300px, calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px) !important;
    border-radius: 16px !important;
    box-shadow: 0 16px 45px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.1) !important;
    background: #0f172a !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .leaflet-popup-content {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    max-height: min(400px, calc(100dvh - 160px)) !important;
    overflow-y: auto !important;
    margin: 0 !important;
    padding: 14px 16px 12px 16px !important;
    box-sizing: border-box !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .leaflet-popup-tip-container {
    display: block !important;
  }

  .leaflet-popup-close-button {
    top: 10px !important;
    right: 10px !important;
    width: 30px !important;
    height: 30px !important;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.12) !important;
    color: #f8fafc !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 18px !important;
    padding: 0 !important;
  }

  .popup-content {
    padding: 0;
  }

  .popup-speed {
    font-size: 22px;
    padding: 4px 0;
  }

  .popup-row {
    font-size: 12px;
  }

  /* Sidebar close button */
  .sidebar-close-btn {
    display: inline-flex;
  }

  /* Sidebar toggle button - better positioning */
  .sidebar-toggle {
    top: 10px;
    right: 10px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 20px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .tabs {
    margin: 8px 10px;
    padding: 3px;
    gap: 4px;
  }
  .tab {
    height: 36px;
    gap: 4px;
    padding: 0 4px;
  }
  .tab-icon {
    font-size: 13px;
  }
  .tab-text {
    font-size: 10px;
    letter-spacing: 0.2px;
  }
}

/* ---- MOBILE BOTTOM BAR ---- */
.mobile-bottom-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1500;
  background: rgba(10, 14, 26, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

@media (max-width: 768px) {
  .mobile-bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-around;
  }
}

.mobile-stat {
  text-align: center;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s;
  min-width: 60px;
}

.mobile-stat:active {
  background: rgba(56, 189, 248, 0.15);
}

.mobile-stat-value {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.mobile-stat-label {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 1px;
}

/* ---- OVERLAY BACKDROP ---- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1999;
}

.sidebar-backdrop.active {
  display: block;
}

/* ---- NOTIFICATION BADGES (TOTAL VISIBILITY, SAFE INSET) ---- */
.notification-badge {
  position: absolute;
  top: -5px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 1.5px solid #090e1a;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
  z-index: 10;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.notification-badge.badge-warning,
#proximity-tab-badge {
  background: linear-gradient(135deg, #fbbf24, #f59e0b) !important;
  color: #0f172a !important;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.6), 0 2px 6px rgba(0, 0, 0, 0.7) !important;
}

.notification-badge.badge-danger,
.tab[data-tab="incidents"] .notification-badge {
  background: linear-gradient(135deg, #ef4444, #dc2626) !important;
  color: #ffffff !important;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.6), 0 2px 6px rgba(0, 0, 0, 0.7) !important;
}

/* ---- OPERATOR FILTER COLORS ---- */
.chip-AVE { --chip-color: #8B1A2B; }
.chip-AVLO { --chip-color: #6B1FAF; }
.chip-OUIGO { --chip-color: #E4006E; }
.chip-IRYO { --chip-color: #C8102E; }
.chip-ALVIA { --chip-color: #0064A4; }
.chip-TALGO { --chip-color: #005A9C; }
.chip-EUROMED { --chip-color: #00838F; }
.chip-MD { --chip-color: #43A047; }
.chip-CERCANIAS { --chip-color: #FF8F00; }

/* ---- SCROLLBAR HIDE FOR MOBILE ---- */
@media (max-width: 768px) {
  .train-list-container {
    -webkit-overflow-scrolling: touch;
  }
}

/* ---- Leaflet attribution simplification ---- */
.leaflet-control-attribution {
  background: rgba(17, 24, 39, 0.7) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

/* ============================================================
   UPGRADE: MEMORIAL, PROXIMIDAD, RUTAS, CLUSTERING & LOGOS
   ============================================================ */

/* ---- MEMORIAL TICKER BUTTON ---- */
.memorial-ticker-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(90deg, #090c15, #182030);
  border: 1px solid #283548;
  border-left: 3px solid #111827;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  width: 100%;
  text-align: left;
  transition: all var(--transition);
}

.memorial-ticker-btn:hover {
  background: #1c263a;
  border-color: #38bdf8;
  transform: translateY(-1px);
}

.memorial-ticker-img {
  width: 16px;
  height: 24px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.7)) drop-shadow(0 0 8px rgba(255, 255, 255, 0.3));
}

.map-memorial-img {
  width: 16px;
  height: 24px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.7)) drop-shadow(0 0 8px rgba(255, 255, 255, 0.3));
}

.memorial-ticker-text {
  flex: 1;
  color: #cbd5e1;
}

.memorial-arrow {
  color: var(--accent-light);
  font-weight: 700;
}

/* ---- FLOATING MAP MEMORIAL BADGE ---- */
/* Oculto en PC (ya existe el botón en el sidebar). Solo visible en móvil. */
.map-memorial-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 999;
  background: rgba(10, 14, 26, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid #334155;
  border-radius: 20px;
  padding: 6px 14px;
  display: none;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  transition: all var(--transition);
}

.map-memorial-badge:hover {
  background: rgba(17, 24, 39, 0.95);
  border-color: #64748b;
  transform: scale(1.02);
}

.ribbon-symbol {
  font-size: 15px;
}

/* ---- MODAL OVERLAY ---- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 16px;
  max-width: 560px;
  width: 100%;
  padding: 28px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: #fff;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.modal-ribbon-img {
  width: 50px;
  height: 72px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.7)) drop-shadow(0 0 12px rgba(255, 255, 255, 0.3));
}

.modal-header h3 {
  font-size: 20px;
  font-weight: 800;
  color: #f8fafc;
  line-height: 1.3;
}

.modal-subtitle {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 4px;
}

.modal-body p {
  font-size: 14px;
  color: #cbd5e1;
  line-height: 1.6;
  margin-bottom: 12px;
}

.modal-fact {
  background: rgba(15, 23, 42, 0.8);
  border-left: 3px solid #38bdf8;
  padding: 10px 14px;
  border-radius: 6px;
  margin: 10px 0;
  font-size: 13px;
  color: #e2e8f0;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #1e293b;
}

.modal-legal-link {
  color: #38bdf8;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.modal-legal-link:hover {
  text-decoration: underline;
}

.modal-btn-primary {
  background: #38bdf8;
  color: #0f172a;
  border: none;
  padding: 9px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition);
}

.modal-btn-primary:hover {
  background: #7dd3fc;
}

/* ---- ROUTE SELECTOR ---- */
.route-filter-box {
  padding: 12px 16px 6px;
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.select-wrapper {
  position: relative;
}

.select-wrapper select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}

.select-wrapper select:focus {
  border-color: var(--accent);
}

/* ---- MAP FLOATING BUTTONS ---- */
.map-floating-btn {
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(8px);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px var(--shadow);
  transition: all var(--transition);
}

.map-floating-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  color: var(--accent-light);
}

.map-floating-btn.active {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent);
  color: #fff;
}

/* ---- ROUTE HIGHLIGHT POLYLINE ---- */
/* El resplandor se dibuja con una polilínea ancha translúcida (ver highlightRoutePath),
   no con CSS filter, que provoca líneas fantasma en los bordes de la capa SVG. */
.route-glow-path {
  stroke-linecap: round;
  stroke-linejoin: round;
}

.route-traversed-path {
  stroke-dasharray: 6 6;
  animation: traverse-flow 1.5s linear infinite;
}

@keyframes traverse-flow {
  to { stroke-dashoffset: -12; }
}

/* Station Waypoint Pin */
.station-waypoint-marker {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #38bdf8;
  border: 2px solid #ffffff;
  box-shadow: 0 0 6px rgba(0,0,0,0.6);
}

/* ---- PROXIMITY LINE (COLLISION RISK WARNING) ---- */
.proximity-warning-line {
  stroke-linecap: round;
  stroke-dasharray: 8 6;
  animation: proximity-dash 1s linear infinite;
}

@keyframes proximity-dash {
  to { stroke-dashoffset: -14; }
}

.proximity-warning-label {
  background: rgba(15, 23, 42, 0.95);
  border: 1.5px solid #eab308;
  border-radius: 8px;
  color: #fef08a;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 12px;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.7);
  pointer-events: auto;
  z-index: 10000 !important;
}

.proximity-warning-label::before {
  border-top-color: #eab308 !important;
}

/* ---- PROXIMITY RADAR PANEL ITEMS ---- */
.proximity-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.4);
  cursor: pointer;
  transition: background var(--transition);
}

.proximity-item:hover {
  background: var(--bg-card);
}

.proximity-item.critical {
  border-left: 3px solid var(--danger);
  background: rgba(239, 68, 68, 0.08);
}

.proximity-item.warning {
  border-left: 3px solid #f97316;
  background: rgba(249, 115, 22, 0.06);
}

.proximity-item.caution {
  border-left: 3px solid #eab308;
}

.proximity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.proximity-trains {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.proximity-vs {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
}

.proximity-dist-badge {
  font-size: 13px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

.badge-risk-critical { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.badge-risk-warning { background: rgba(249, 115, 22, 0.2); color: #fb923c; border: 1px solid rgba(249, 115, 22, 0.4); }
.badge-risk-caution { background: rgba(234, 179, 8, 0.2); color: #facc15; border: 1px solid rgba(234, 179, 8, 0.4); }
.badge-risk-nominal { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }

.proximity-corridor {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.risk-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.risk-bar-container {
  flex: 1;
  height: 6px;
  background: #1e293b;
  border-radius: 3px;
  overflow: hidden;
}

.risk-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.risk-val-text {
  font-weight: 700;
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---- SAFETY INDICATOR WIDGET ---- */
/* ---- PANEL CTC TELEMETRÍA & SEÑALIZACIÓN ---- */
.ctc-telemetry-panel {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ctc-signal-box {
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 9px 14px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* Semáforo ferroviario real de 3 aspectos (ERTMS / ASFA) */
.rail-signal-lamp {
  background: #090d16;
  border: 1.5px solid #334155;
  border-radius: 12px;
  padding: 4px 5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
}

.signal-lens {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #1e293b;
  opacity: 0.25;
  transition: all 0.3s ease;
}

.lens-green.active {
  background: #10b981;
  opacity: 1;
  box-shadow: 0 0 10px #10b981, 0 0 18px rgba(16, 185, 129, 0.6);
}

.lens-yellow.active {
  background: #f59e0b;
  opacity: 1;
  box-shadow: 0 0 10px #f59e0b, 0 0 18px rgba(245, 158, 11, 0.6);
  animation: pulse 1.2s infinite;
}

.lens-red.active {
  background: #ef4444;
  opacity: 1;
  box-shadow: 0 0 12px #ef4444, 0 0 20px rgba(239, 68, 68, 0.8);
  animation: pulse 0.6s infinite;
}

.ctc-signal-info {
  display: flex;
  flex-direction: column;
}

.ctc-sublabel {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.ctc-main-status {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
}

.ctc-main-status.status-nominal { color: #34d399; }
.ctc-main-status.status-caution { color: #fbbf24; }
.ctc-main-status.status-critical { color: #f87171; }

.ctc-speed-box {
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 9px 14px;
  border: 1px solid var(--border);
  text-align: center;
  min-width: 95px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.ctc-speed-readout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 3px;
}

.speed-number {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent-light);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* Leyenda cabecera y badges */

.legend-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.legend-badge-live {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  font-size: 8px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.legend-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---- LEAFLET MARKERCLUSTER CUSTOM DARK THEME ---- */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background-color: rgba(15, 23, 42, 0.75) !important;
  border: 2px solid var(--accent) !important;
  border-radius: 50% !important;
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.4) !important;
  backdrop-filter: blur(6px) !important;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background-color: rgba(30, 41, 59, 0.9) !important;
  color: #ffffff !important;
  font-family: 'Inter', sans-serif !important;
  font-weight: 800 !important;
  font-size: 12px !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* ---- LOGO SVG IN CARDS AND POPUPS ---- */
.operator-logo-wrap {
  width: 48px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.operator-logo-wrap svg,
.operator-logo-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.popup-logo-container {
  width: 72px;
  height: 26px;
  display: flex;
  align-items: center;
}

.popup-logo-container svg,
.popup-logo-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---- SIDEBAR LEGAL FOOTER ---- */
.sidebar-legal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  font-size: 11px;
}

.legal-links {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.legal-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}

.legal-links a:hover {
  color: var(--accent-light);
}

.legal-links span {
  color: var(--border-light);
}

.legal-disclaimer {
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.3;
}

.made-by {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.5px;
  opacity: 0.7;
}

/* ---- TOOLTIP INTERACTIVO DE RUTAS Y VÍAS ---- */
.route-interactive-tooltip {
  background: rgba(10, 14, 26, 0.94) !important;
  border: 1.5px solid #334155 !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6) !important;
  color: #e2e8f0 !important;
  backdrop-filter: blur(8px) !important;
  padding: 8px 12px !important;
}

.route-interactive-tooltip::before {
  border-top-color: #334155 !important;
}

/* Nodos Centrales Ferroviarios.
   Sin CSS filter: un filter sobre elementos del SVG de Leaflet hace que Chrome pinte
   los bordes de la capa SVG como líneas finas que persisten al mover el mapa. */
.hub-node-pulse {
  stroke-opacity: 1;
}

/* Botón de cierre visible y accesible en popups Leaflet */
.leaflet-popup-close-button {
  color: #cbd5e1 !important;
  font-size: 20px !important;
  width: 26px !important;
  height: 26px !important;
  top: 8px !important;
  right: 8px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 6px !important;
  background: rgba(255, 255, 255, 0.1) !important;
  transition: all 0.2s !important;
}

.leaflet-popup-close-button:hover {
  color: #ffffff !important;
  background: rgba(239, 68, 68, 0.8) !important;
}

/* ============================================================
   FINAL MOBILE OVERRIDES (BOTTOM BAR, CTC PANEL, MEMORIAL, CLOSE)
   ============================================================ */
@media (max-width: 768px) {

  /* ---- MAP TOP CONTROLS: Alinear botones con lazo y hamburguesa ---- */
  .map-overlay-top {
    top: 10px !important;
    left: 10px !important;
    right: auto !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    z-index: 1000 !important;
  }

  .map-floating-btn {
    font-size: 11px !important;
    padding: 8px 10px !important;
    height: 40px !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5) !important;
  }

  /* Memorial badge — same row, just left of hamburger */
  .map-memorial-badge {
    top: 10px !important;
    right: 62px !important;
    width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    border-radius: 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5) !important;
  }

  .map-memorial-badge .map-memorial-img {
    width: 20px !important;
    height: 28px !important;
  }

  .map-memorial-badge .ribbon-text {
    display: none !important;
  }

  /* Hamburger toggle — same height row */
  .sidebar-toggle {
    top: 10px !important;
    right: 10px !important;
    width: 44px !important;
    height: 44px !important;
    border-radius: 12px !important;
  }

  /* ---- HIDE CTC PANEL ON MOBILE (info already in bottom bar, avoids overlap & duplication) ---- */
  .map-overlay-bottom {
    display: none !important;
  }

  /* Leaflet attribution & zoom above bottom bar */
  .leaflet-bottom.leaflet-right {
    margin-bottom: 60px !important;
    margin-right: 8px !important;
  }

  .leaflet-control-zoom {
    margin-bottom: 80px !important;
  }

  /* ---- SIDEBAR SCROLLABLE FIX ---- */
  .sidebar {
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  /* The back button stays fixed at top */
  .sidebar-back-btn {
    display: flex !important;
    flex-shrink: 0 !important;
  }

  /* Header stays fixed */
  .sidebar-header {
    flex-shrink: 0 !important;
  }

  /* Stats stay fixed */
  .stats-grid {
    flex-shrink: 0 !important;
  }

  /* Everything below stats scrolls */
  .route-filter-box,
  .filters-section,
  .search-box {
    flex-shrink: 0 !important;
  }

  /* Tabs stay visible */
  .tabs {
    flex-shrink: 0 !important;
  }

  /* Train list capped with max-height to avoid infinite scroll to footer */
  .train-list-container {
    max-height: min(320px, 38vh) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 10px !important;
  }

  /* Legal footer stays at bottom */
  .sidebar-legal-footer {
    flex-shrink: 0 !important;
  }

  .sidebar-close-btn {
    display: inline-flex !important;
  }

  /* ---- MAP BRAND ICON (favicon) visible on mobile ---- */
  .map-brand-icon {
    display: block !important;
  }

  /* ---- MOBILE BOTTOM BAR: 2×2 grid to avoid Netlify overlap ---- */
  .mobile-bottom-bar {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0 !important;
    padding: 6px 12px !important;
    padding-bottom: max(6px, env(safe-area-inset-bottom)) !important;
    max-width: 52% !important;
    left: 0 !important;
    right: auto !important;
    border-radius: 0 12px 0 0 !important;
  }

  .mobile-stat {
    padding: 3px 4px !important;
    min-width: 0 !important;
  }

  .mobile-stat-value {
    font-size: 15px !important;
  }

  .mobile-stat-label {
    font-size: 8px !important;
  }
}

/* ---- PANEL CTC SIEMPRE ANCLADO A LA IZQUIERDA DEL MAPA ---- */
.map-overlay-bottom {
  right: auto;
}

/* ---- SELECTOR DE TIPO DE SERVICIO (MÓVIL) ---- */
.service-select {
  display: none;
  /* Sin position: el menú se ancla a .map-overlay-top y abre desde su borde izquierdo */
}

.service-select-btn {
  max-width: 100%;
}

.service-select-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.service-select-caret {
  font-size: 10px;
  opacity: 0.8;
  transition: transform var(--transition);
}

.service-select.open .service-select-caret {
  transform: rotate(180deg);
}

.service-select-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 260px;
  max-width: calc(100vw - 20px);
  background: rgba(15, 23, 42, 0.97);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  z-index: 1100;
}

.service-select.open .service-select-menu {
  display: block;
}

.service-option-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.service-option {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
}

.service-option.selected {
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(59, 130, 246, 0.45);
}

.service-option .chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chip-color);
  flex-shrink: 0;
}

.service-option-name {
  flex: 1;
}

.service-option-count {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.service-option-check {
  width: 38px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.service-option-check.checked {
  background: var(--chip-color);
  border-color: var(--chip-color);
  color: #fff;
}

.service-select-hint {
  font-size: 10px;
  color: var(--text-muted);
  padding: 6px 8px 2px;
  line-height: 1.4;
}

@media (max-width: 768px) {
  .service-select {
    display: block;
  }

  /* En móvil el selector de servicio sustituye al botón de agrupación */
  #btn-toggle-clusters {
    display: none !important;
  }
}

/* ============================================================
   FILA SUPERIOR DEL MAPA RESPONSIVE (logo + botones + lazo + menú)
   Los botones encogen y recortan su texto en lugar de solaparse.
   ============================================================ */
.map-overlay-top .map-floating-btn,
.service-select {
  flex: 0 1 auto;
  min-width: 0;
}

.map-brand-icon {
  flex-shrink: 0;
}

.btn-text,
.service-select-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Escritorio estrecho / tablet: la leyenda baja a una segunda fila si no cabe junto a los botones */
@media (min-width: 769px) and (max-width: 1060px) {
  .map-legend {
    top: 56px;
  }
}

@media (max-width: 768px) {
  /* La fila de botones termina antes del lazo memorial (right: 62px + 40px) y del menú */
  .map-overlay-top {
    right: 112px !important;
    align-items: center !important;
  }

  .service-select-btn {
    width: 100%;
  }
}

/* Pantallas muy estrechas: "Red de Vías" se queda solo con el icono */
@media (max-width: 360px) {
  #btn-toggle-all-routes .btn-text {
    display: none;
  }
}
