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

:root {
  --sidebar-w: 320px;
  --header-h: 56px;
  --filter-h: 44px;
  --bg: #f8f8f8;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #666;
  --accent: #003DA5;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,.12);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

body.dark {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2e3f;
  --text: #e4e6f0;
  --text-muted: #8a8fa8;
  --accent: #4d82f5;
  --shadow: 0 2px 12px rgba(0,0,0,.45);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── HEADER ── */
#header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  z-index: 1000;
}

#mode-switcher {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 2px;
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 8px;
  padding: 4px 10px 4px 6px;
  cursor: pointer;
  transition: background 150ms ease-out, color 150ms ease-out, transform 100ms ease-out;
  white-space: nowrap;
}
.mode-option:active:not(.active) { transform: scale(0.95); }

.mode-option svg { width: 26px; height: 26px; flex-shrink: 0; }

.mode-option:hover {
  background: var(--bg);
  color: var(--text);
}

.mode-option.active {
  background: var(--bg);
  color: var(--text);
}

.search-wrap {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  overflow: hidden;
  flex: 1;
  max-width: 520px;
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
}
.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 61, 165, 0.1);
}
body.dark .search-wrap:focus-within {
  box-shadow: 0 0 0 3px rgba(77, 130, 245, 0.18);
}

.search-field {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 0 12px;
  gap: 6px;
  min-width: 0;
}

.search-field label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .6px;
  flex-shrink: 0;
}

.search-field input {
  border: none;
  background: transparent;
  font-size: 14px;
  color: var(--text);
  outline: none;
  width: 100%;
  min-width: 0;
}

.search-field input::placeholder { color: #999; }

.search-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

.swap-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 150ms ease-out, transform 100ms ease-out;
}
.swap-btn:hover { color: var(--accent); }
.swap-btn:active { transform: scale(0.85); }
.swap-btn svg { transition: transform 380ms var(--ease-out); }
.swap-btn.is-swapping svg { transform: rotate(180deg); }

#header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: border-color .15s, background .15s;
}
.badge-btn:hover { border-color: var(--accent); background: #f0f4ff; }

/* ── FILTER BAR ── */
#filter-bar {
  height: var(--filter-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 52px), transparent 100%);
  mask-image: linear-gradient(to right, black calc(100% - 52px), transparent 100%);
}
#filter-bar::-webkit-scrollbar { display: none; }

.filter-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  background: var(--surface);
  color: var(--text);
  transition: background 150ms ease-out, border-color 150ms ease-out, color 150ms ease-out, transform 100ms ease-out;
  flex-shrink: 0;
}
.filter-chip:hover { border-color: var(--accent); background: #f0f4ff; }
.filter-chip:active { transform: scale(0.93); }
.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  animation: chipPop 280ms var(--ease-out);
}
@keyframes chipPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.filter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* ── MAIN LAYOUT ── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  z-index: 100;
  position: relative;
}
#sidebar::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: linear-gradient(to bottom, transparent, var(--surface));
  pointer-events: none;
  z-index: 10;
}
body.dark #sidebar::after {
  background: linear-gradient(to bottom, transparent, var(--surface));
}

#sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

#sidebar-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}
#sidebar-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

#sidebar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.meta-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  background: #f0f4ff;
  color: var(--accent);
  animation: metaTagIn 320ms var(--ease-out) both;
}
@keyframes metaTagIn {
  from { opacity: 0; transform: scale(0.82) translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.meta-tag:nth-child(2) { animation-delay: 60ms; }

#tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
#tab-bar::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: var(--ind-left, 0px);
  width: var(--ind-width, 0px);
  height: 2px;
  background: var(--accent);
  transition: left 240ms var(--ease-out), width 200ms var(--ease-out);
  border-radius: 1px;
}

.tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 150ms ease-out, transform 100ms ease-out;
}
.tab:active { transform: scale(0.96); }
.tab.active { color: var(--accent); }

#sort-bar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#sort-bar span { font-size: 12px; color: var(--text-muted); }
.sort-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  color: var(--text);
  transition: background 150ms ease-out, border-color 150ms ease-out, color 150ms ease-out, transform 100ms ease-out;
}
.sort-btn:active { transform: scale(0.93); }
.sort-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

#route-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #ddd transparent;
}

#route-list::-webkit-scrollbar { width: 4px; }
#route-list::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

.route-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background 120ms ease-out, translate 140ms var(--ease-out);
  gap: 10px;
  animation: routeSlideIn 220ms var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 28ms);
}
.route-item:hover, .route-item.hover { background: #f8f9ff; translate: 2px 0; }
.route-item.selected { background: #eef2ff; }
.route-item.isolated:hover, .route-item.isolated.hover { translate: 0; }

@keyframes routeSlideIn {
  from { opacity: 0; transform: translateX(-7px); }
  to   { opacity: 1; transform: none; }
}

.route-code {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  padding: 3px 7px;
  border-radius: 5px;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
  letter-spacing: .4px;
}

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

.route-city {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.route-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.route-duration {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

.op-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  color: #fff;
}

.via-tag {
  font-size: 10px;
  color: #999;
  font-style: italic;
}

#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-muted);
  padding: 32px 24px;
  text-align: center;
}

#empty-state svg {
  opacity: .35;
  animation: floatIcon 3.2s ease-in-out infinite;
}
@keyframes floatIcon {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-7px); }
}
#empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); }
#empty-state p { font-size: 13px; line-height: 1.5; }

/* ── MAP ── */
#map {
  flex: 1;
  position: relative;
}

/* Modo oscuro: el tile ya ES dark (MapTiler streets-v2-dark o Carto dark_all
   como fallback). No aplicamos filter — antes el hue-rotate sobre un tile
   ya oscuro lo enrarecía y oscurecía más de lo necesario. Mantenemos el
   background del contenedor para que cuando los tiles aún no cargan se vea
   un color coherente con la UI dark (#1a1d27). */
body.dark #map {
  background: #1a1d27;
}

/* ── MAP CONTROLS ── */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-control-zoom a {
  border-radius: 6px !important;
  border: none !important;
  margin-bottom: 4px !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  font-size: 18px !important;
}

/* ── STATION POPUP ── */
.station-popup {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.station-popup h4 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}
.station-popup p {
  font-size: 12px;
  color: #666;
}
.station-popup .pop-stats {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* ── VIEW MODE TOGGLE ── */
#view-toggle {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 500;
  display: flex;
  background: var(--surface);
  border-radius: 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.view-group {
  display: flex;
}
.view-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  border: none;
  background: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .15s, color .15s, opacity .15s;
  white-space: nowrap;
  font-family: inherit;
}
.view-btn:hover:not(.active):not(:disabled) { background: #f0f4ff; color: var(--accent); }
.view-btn:active:not(.active):not(:disabled) { transform: scale(0.92); }
.view-btn.active { background: var(--accent); color: #fff; }
.view-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.view-group .view-btn + .view-btn { border-left: 1px solid var(--border); }

/* ── RESET BUTTON (integrado en view-toggle) ── */
.view-divider {
  width: 1px;
  background: var(--border);
  margin: 6px 4px;
}
#reset-btn {
  background: transparent;
  color: #E30613;
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: none;
  align-items: center;
  gap: 6px;
  border-radius: 8px;
  transition: background .15s;
  font-family: inherit;
}
#reset-btn:hover { background: rgba(227,6,19,.08); }
#reset-btn.visible { display: flex; }

/* ── RECENTER BUTTON (al lado de Reset, accent azul) ── */
#recenter-btn {
  background: transparent;
  color: var(--accent);
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 8px;
  transition: background .15s, color .15s, opacity .15s, transform .15s;
  font-family: inherit;
}
#recenter-btn:hover:not(:disabled) {
  background: rgba(0, 61, 165, .08);
}
#recenter-btn:active:not(:disabled) {
  transform: scale(0.96);
}
#recenter-btn:disabled {
  color: var(--text-muted);
  opacity: 0.45;
  cursor: not-allowed;
}
body.dark #recenter-btn { color: #6d9bff; }
body.dark #recenter-btn:hover:not(:disabled) { background: rgba(109, 155, 255, .12); }
body.dark #recenter-btn:disabled { color: var(--text-muted); }

/* ── LEGEND ── */
#legend {
  position: absolute;
  bottom: 28px;
  left: 12px;
  z-index: 500;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 12px;
  min-width: 190px;
}

#legend h5 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(0,0,0,.12);
}
.legend-line {
  width: 24px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── TOOLTIP ── */
.station-tooltip {
  background: rgba(20,20,30,.85) !important;
  border: none !important;
  border-radius: 5px !important;
  color: #fff !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  padding: 4px 8px !important;
  box-shadow: none !important;
}
.station-tooltip::before { display: none !important; }

/* ── TRANSFER TOGGLE ── */
#transfer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
#transfer-toggle input[type=checkbox] { cursor: pointer; accent-color: var(--accent); }

/* ── LOADING OVERLAY ── */
#loading {
  position: fixed;
  inset: 0;
  background: rgba(248,248,250,.94);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(3px);
}

/* Simple spinner (reused for initial page load) */
.spinner {
  width: 34px; height: 34px;
  border: 3px solid #dde5ff;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .55s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes _pp { 0%,100% { transform: scale(1); } 50% { transform: scale(1.14); } }

/* Card (initial loading only) */
.lcard {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 8px 40px rgba(0,0,0,.14), 0 1px 4px rgba(0,0,0,.06);
  display: flex;
  flex-direction: column;
  gap: 0;
}
.lcard-init {
  flex-direction: row;
  align-items: center;
  gap: 14px;
  padding: 20px 28px;
}
.ltitle {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

/* ── ROUTE LIST SECTION HEADER (tab "Todos") ── */
.list-section-hd {
  padding: 6px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Isolated route (after sidebar click) */
.route-item.isolated {
  background: #eef2ff;
  border-left: 3px solid var(--accent);
}

/* ── LEAFLET MARKER / PATH TRANSITIONS ── */
.leaflet-overlay-pane path {
  transition: stroke-opacity 150ms ease-out, stroke-width 150ms ease-out;
}
.leaflet-overlay-pane circle {
  transition: r 120ms var(--ease-out), fill-opacity 120ms ease-out, stroke-width 120ms ease-out;
}

/* ── AUTOCOMPLETE ── */
.autocomplete-drop {
  position: fixed;
  z-index: 9000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: none;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-5px) scale(0.98);
  transform-origin: top center;
  transition: opacity 160ms ease-out, transform 160ms var(--ease-out);
}
.autocomplete-drop.ac-visible {
  opacity: 1;
  transform: none;
}

.ac-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 100ms ease-out;
  gap: 8px;
}
.ac-item:hover { background: #f0f4ff; }
.ac-item:active { background: #e0eaff; }
.ac-city { font-size: 14px; font-weight: 600; }
.ac-region { font-size: 11px; color: var(--text-muted); }
.ac-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  padding: 8px 14px 3px;
  pointer-events: none;
}

/* ── DARK MODE OVERRIDES ── */
body.dark .route-item:hover,
body.dark .route-item.hover          { background: #222640; }
body.dark .route-item.selected       { background: #1e2a50; }
body.dark .route-item.isolated       { background: #1e2a50; border-left-color: var(--accent); }
body.dark .route-item                { border-bottom-color: #232638; }
body.dark .meta-tag                  { background: #1e2a50; color: var(--accent); }
body.dark .list-section-hd           { background: #12141e; }
body.dark .ac-item:hover             { background: #222640; }
body.dark .filter-chip:hover         { background: #1e2a50; color: var(--accent); border-color: var(--accent); }
body.dark #loading                   { background: rgba(10,10,15,.94); }
body.dark .lcard                     { background: #1a1d27; color: var(--text); }
body.dark .spinner                   { border-color: #2a3060; border-top-color: var(--accent); }
body.dark .leaflet-control-zoom a    { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
body.dark .view-btn:hover:not(.active){ background: #1e2a50; color: var(--accent); }
body.dark #reset-btn:hover           { background: rgba(255,80,90,.1); }
body.dark .view-divider              { background: #2a2e3f; }
body.dark #reset-btn:hover           { background: #a0000f; }

/* ── DARK MODE TOGGLE BUTTON ── */
.dark-toggle {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 5px 10px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  color: var(--text);
  transition: border-color 150ms ease-out, background 150ms ease-out, transform 100ms ease-out;
  display: flex;
  align-items: center;
}
.dark-toggle:hover { border-color: var(--accent); background: #f0f4ff; }
.dark-toggle:active { transform: scale(0.88); }
@keyframes darkToggleSpin {
  0%   { transform: scale(1)    rotate(0deg); }
  40%  { transform: scale(0.78) rotate(-25deg); }
  100% { transform: scale(1)    rotate(360deg); }
}
.dark-toggle.is-spinning { animation: darkToggleSpin 420ms var(--ease-out) forwards; }
body.dark .dark-toggle:hover { background: #1e2a50; }


/* ── HELP BUTTON ── */
.help-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 5px 11px;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color 150ms ease-out, background 150ms ease-out, transform 100ms ease-out, color 150ms ease-out;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
}
.help-btn:hover { border-color: var(--accent); background: #f0f4ff; color: var(--accent); }
.help-btn:active { transform: scale(0.9); }
body.dark .help-btn:hover { background: #1e2a50; }

/* ── HELP MODAL ── */
#help-modal {
  position: fixed;
  inset: 0;
  z-index: 7000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease-out;
}
#help-modal.visible { opacity: 1; pointer-events: auto; }

.hm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.42);
  backdrop-filter: blur(2px);
}
.hm-card {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22), 0 0 0 1px var(--border);
  width: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.94) translateY(10px);
  transition: transform 250ms var(--ease-out);
}
#help-modal.visible .hm-card { transform: none; }

.hm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.hm-header h2 { font-size: 17px; font-weight: 700; }
.hm-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
  transition: background 120ms ease-out, color 120ms ease-out, transform 100ms ease-out;
}
.hm-close:hover { background: var(--bg); color: var(--text); }
.hm-close:active { transform: scale(0.88); }

.hm-body { overflow-y: auto; padding: 6px 0; flex: 1; }
.hm-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 11px 24px;
  transition: background 100ms ease-out;
  cursor: default;
}
.hm-item:hover { background: var(--bg); }
.hm-icon { font-size: 19px; flex-shrink: 0; width: 26px; text-align: center; margin-top: 1px; }
.hm-item div { font-size: 13px; line-height: 1.5; color: var(--text); }
.hm-item strong { font-weight: 600; display: block; margin-bottom: 1px; }

.kbd {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: monospace;
  font-weight: 700;
  color: var(--text-muted);
  margin: 2px 1px;
}
.hm-footer {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.hm-tutorial-btn {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: filter 150ms, transform 100ms ease-out;
}
.hm-tutorial-btn:hover { filter: brightness(1.1); }
.hm-tutorial-btn:active { transform: scale(0.98); }

/* ── TUTORIAL ── */
#tutorial-highlight {
  position: fixed;
  z-index: 8001;
  border-radius: 10px;
  box-shadow: 0 0 0 3px var(--accent), 0 0 0 9999px rgba(0,0,0,0.58);
  pointer-events: none;
  display: none;
  transition: top 270ms var(--ease-out), left 270ms var(--ease-out),
              width 270ms var(--ease-out), height 270ms var(--ease-out);
}
#tutorial-card {
  position: fixed;
  z-index: 8002;
  background: var(--surface);
  border-radius: 14px;
  padding: 20px;
  width: 300px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.28), 0 0 0 1px var(--border);
  display: none;
  font-family: inherit;
  transition: top 270ms var(--ease-out), left 270ms var(--ease-out);
  animation: tutCardIn 250ms var(--ease-out) both;
}
@keyframes tutCardIn {
  from { opacity: 0; transform: scale(0.94) translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.tc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.tc-step {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .5px;
  background: #f0f4ff;
  padding: 2px 8px;
  border-radius: 10px;
}
body.dark .tc-step { background: #1e2a50; }
.tc-skip {
  background: none;
  border: none;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  transition: background 120ms, color 120ms;
  font-family: inherit;
}
.tc-skip:hover { background: var(--bg); color: var(--text); }
.tc-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.tc-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.tc-body strong, .tc-body b { color: var(--text); font-weight: 600; }
.tc-actions { display: flex; gap: 8px; }
.tc-back, .tc-next {
  flex: 1;
  padding: 9px;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: filter 150ms, transform 100ms ease-out;
}
.tc-back:active, .tc-next:active { transform: scale(0.95); }
.tc-back {
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.tc-back:hover { color: var(--text); }
.tc-next { background: var(--accent); color: #fff; }
.tc-next:hover { filter: brightness(1.1); }

/* ── RESPONSIVE ── */
@media (max-width: 700px) {
  :root { --sidebar-w: 260px; }
  .mode-option span { display: none; }
  .mode-option { padding: 4px 5px; }
}

/* ── TOAST ── */
.tc-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(14px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  box-shadow: 0 8px 28px rgba(0,0,0,0.16);
  z-index: 9500;
  opacity: 0;
  transition: opacity 240ms ease-out, transform 240ms var(--ease-out);
  pointer-events: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tc-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.tc-toast--success { border-left: 3px solid #22c55e; }
.tc-toast--info    { border-left: 3px solid var(--accent); }
.tc-toast--warn    { border-left: 3px solid #f59e0b; }

/* ── MODE TRANSITION OVERLAY ── */
.mode-transition-overlay {
  position: absolute;
  inset: 0;
  z-index: 480;
  background: var(--bg);
  opacity: 0;
  transition: opacity 160ms ease-out;
  pointer-events: none;
}
.mode-transition-overlay.visible { opacity: 0.72; }

/* ── ROUTE TOOLTIP (estilo Google Maps) ── */
.leaflet-tooltip.route-tooltip {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  pointer-events: none;
}
.leaflet-tooltip.route-tooltip::before { display: none; }
.route-tooltip .tt-title { font-weight: 700; margin-bottom: 4px; }
.route-tooltip .tt-ops { display: flex; gap: 4px; margin: 4px 0; flex-wrap: wrap; }
.route-tooltip .tt-op {
  font-size: 10px; font-weight: 700; color: #fff;
  padding: 2px 6px; border-radius: 3px; letter-spacing: .3px;
}
.route-tooltip .tt-meta {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}
body.dark .leaflet-tooltip.route-tooltip {
  background: #1a1d27;
  border-color: #2a2e3f;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}

/* ── TRANSFER ICON ── */
.transfer-icon {
  display: inline-block;
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 4px;
  vertical-align: middle;
  font-weight: 400;
}

/* ── STATIONS PANEL ── */
#stations-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  transition: background .15s, transform .1s;
  font-family: inherit;
}
#stations-toggle:hover { background: #f0f4ff; transform: scale(1.02); }
#stations-toggle:active { transform: scale(0.96) !important; }
body.dark #stations-toggle:hover { background: #1e2a50; }

#stations-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 320px;
  z-index: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 380ms cubic-bezier(0.34, 1.56, 0.64, 1), opacity 220ms ease-out;
  transform-origin: top right;
}
#stations-panel.hidden {
  pointer-events: none;
  opacity: 0;
  transform: scale(.90) translateX(14px) translateY(-6px);
  transition: transform 220ms var(--ease-in-out), opacity 180ms ease-in;
}

#stations-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
#stations-panel-header .sp-title {
  font-size: 15px;
  font-weight: 700;
}
#stations-panel-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 6px;
  border-radius: 4px;
  transition: background .15s;
}
#stations-panel-close:hover { background: var(--bg); color: var(--text); }

#stations-search {
  margin: 12px 16px 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
#stations-search:focus { border-color: var(--accent); }

#stations-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
}
.sp-region {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: .5px;
  padding: 10px 8px 4px;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.sp-station {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 120ms ease-out, translate 140ms var(--ease-out);
}
.sp-station:hover { background: var(--bg); translate: 2px 0; }
.sp-station:active { translate: 0; opacity: 0.75; }
.sp-station-code {
  font-size: 10px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  padding: 3px 6px;
  border-radius: 4px;
  letter-spacing: .4px;
  min-width: 36px;
  text-align: center;
}
.sp-station-info { flex: 1; min-width: 0; }
.sp-station-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sp-station-meta {
  font-size: 11px;
  color: var(--text-muted);
}

body.dark .sp-region { background: #1a1d27; }

/* ════════════════════════════════════════════════════════════════
   3D VIEW (lazy-activated when user selects "3D" mode)
   z-index 450 sits above Leaflet's panes (max ~400) and below
   the floating UI controls (view-toggle/legend/etc. at 500+).
   ════════════════════════════════════════════════════════════════ */
#map-3d {
  position: absolute;
  inset: 0;
  z-index: 450;
  display: none;
  background: #0f1117;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}
#map-3d.active {
  display: block;
  opacity: 1;
  pointer-events: auto;
}
/* Fade suave de Leaflet al entrar/salir de 3D (estilo Google Maps).
   - Estado normal: visible, opacity 1.
   - mode-3d:       opacity 0 con transición, luego visibility hidden tras 0.4s
                    para deshabilitar clicks (marker-pane z=600 los capturaría).
   - Saliendo de mode-3d: visibility:visible inmediato (transition delay 0)
                    para que el fade-in sea visible. */
.leaflet-map-pane,
.leaflet-control-container {
  transition: opacity 0.4s ease, visibility 0s 0s;
}
body.mode-3d .leaflet-map-pane,
body.mode-3d .leaflet-control-container {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0s 0.4s;
}

.scene3d-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0f1117;
  color: #aaa;
  gap: 16px;
  font-family: inherit;
}
.scene3d-loading p {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.02em;
}

#train-hud {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 550;
  display: none;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 8px 12px 10px;
  font-family: inherit;
  min-width: 380px;
}
#train-hud.active { display: flex; }

.hud-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: 18px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, opacity .15s, transform .1s;
  font-family: inherit;
}
.hud-btn:hover:not(:disabled) { background: var(--accent); color: #fff; }
.hud-btn:active:not(:disabled) { transform: scale(.94); }
.hud-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.hud-btn-primary {
  width: 42px; height: 42px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(0, 61, 165, .35);
}
.hud-btn-primary:hover:not(:disabled) {
  background: var(--accent);
  filter: brightness(1.1);
}

/* Barra de progreso de la animación */
.hud-progress {
  width: 100%;
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}
.hud-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #5a8dff);
  border-radius: 2px;
  transition: width .12s linear;
}
body.dark .hud-progress-fill {
  background: linear-gradient(90deg, #6d9bff, #a5c1ff);
}

.hud-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 2px;
}

.hud-speed {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  color: var(--text-muted);
}
.hud-label {
  margin-right: 4px;
  font-weight: 500;
}
.hud-speed-btn {
  border: none;
  background: transparent;
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.hud-speed-btn.active { background: var(--accent); color: #fff; }
.hud-speed-btn:hover:not(.active) { background: var(--bg); color: var(--accent); }

/* Slider continuo de velocidad (0.25× a 8×) */
.hud-speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.hud-speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.hud-speed-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.hud-speed-slider:active::-webkit-slider-thumb { cursor: grabbing; }
.hud-speed-value {
  min-width: 44px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Toggle de modo de simulación: Tiempo real vs Libre */
.hud-modes {
  display: inline-flex;
  background: var(--bg);
  border-radius: 14px;
  padding: 2px;
  gap: 0;
}
.hud-mode-btn {
  border: none;
  background: transparent;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.hud-mode-btn.active { background: var(--accent); color: #fff; }
.hud-mode-btn:hover:not(.active) { color: var(--accent); }

/* Indicador de velocidad real (solo en modo Tiempo real con ruta cargada) */
.hud-kmh {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

