/* ═══════════════════════════════════════════════════════════════════════════
   TUSBus — Identidad marítima
   Mar al anochecer (azul profundo) · coral cálido · niebla del norte
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Paleta */
  --night:       #0a1929;   /* mar al anochecer, fondo base */
  --night-2:     #0f2236;   /* superficie elevada */
  --night-3:     #16314a;   /* superficie 2 / hover */
  --hull:        #1d3b58;   /* bordes, líneas */
  --fog:         #8ba3b8;   /* texto secundario, niebla */
  --foam:        #e8f0f5;   /* texto principal, espuma */
  --sea:         #2d6a8f;   /* azul mar medio */
  --sea-bright:  #4db8d4;   /* azul cian, faros */
  --coral:       #ff6b5d;   /* coral cálido, acento principal */
  --coral-deep:  #e8503f;   /* coral oscuro */
  --amber:       #ffb84d;   /* ámbar, avisos / tiempo cercano */
  --kelp:        #3fb98a;   /* verde alga, ok / tiempo lejano */

  --font-display: 'Archivo', system-ui, sans-serif;
  --font-mono:    'Spline Sans Mono', monospace;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;

  --panel-w: 380px;
  --nav-h: 60px;
  --shadow: 0 8px 32px rgba(0,0,0,.45);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--night);
  color: var(--foam);
  font-family: var(--font-display);
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ── SPLASH ─────────────────────────────────────────────────────────────────── */
#splash {
  position: fixed; inset: 0; z-index: 9999;
  background: radial-gradient(circle at 50% 40%, var(--night-2), var(--night));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
}
.splash-mark { animation: float 2.4s ease-in-out infinite; }
#splash-bus { animation: ride 2.6s ease-in-out infinite; }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }
@keyframes ride {
  0%   { cx: 14; cy: 52; }
  45%  { cx: 44; cy: 38; }
  70%  { cx: 54; cy: 33; }
  100% { cx: 66; cy: 28; }
}
#splash h1 { font-size: 28px; font-weight: 800; letter-spacing: -1px; }
#splash h1 span { color: var(--coral); }
#splash p { color: var(--fog); font-family: var(--font-mono); font-size: 13px; }

/* ── APP SHELL ──────────────────────────────────────────────────────────────── */
#app { height: 100%; display: flex; flex-direction: column; }

#main {
  flex: 1; position: relative; display: flex; overflow: hidden;
}

#map { position: absolute; inset: 0; background: var(--night); z-index: 1; }

/* ── NAV ────────────────────────────────────────────────────────────────────── */
#nav {
  height: var(--nav-h); flex-shrink: 0;
  background: var(--night-2);
  border-bottom: 1px solid var(--hull);
  display: flex; align-items: center;
  padding: 0 18px; gap: 24px;
  z-index: 1000;
}
.nav-brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 17px; font-weight: 700; letter-spacing: -0.4px;
  white-space: nowrap;
}
.nav-brand strong { color: var(--coral); font-weight: 800; }
.brand-icon { flex-shrink: 0; }

.nav-tabs { display: flex; gap: 4px; flex: 1; }
.nav-tab {
  display: flex; align-items: center; gap: 7px;
  background: none; border: none; cursor: pointer;
  color: var(--fog); font-family: var(--font-display);
  font-size: 13px; font-weight: 600;
  padding: 8px 14px; border-radius: var(--r-sm);
  transition: all .18s; white-space: nowrap;
}
.nav-tab svg { opacity: .7; transition: opacity .18s; }
.nav-tab:hover { background: var(--night-3); color: var(--foam); }
.nav-tab.active { background: var(--coral); color: #fff; }
.nav-tab.active svg { opacity: 1; }

.nav-status {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 12px; color: var(--fog);
  white-space: nowrap;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--fog); transition: all .4s;
}
.status-dot.live  { background: var(--kelp); box-shadow: 0 0 8px var(--kelp); }
.status-dot.error { background: var(--coral); box-shadow: 0 0 8px var(--coral); }
.status-dot.loading { background: var(--amber); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── PANEL LATERAL ──────────────────────────────────────────────────────────── */
#panel {
  position: relative; z-index: 500;
  width: var(--panel-w); flex-shrink: 0;
  background: var(--night-2);
  border-right: 1px solid var(--hull);
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.view { display: none; flex-direction: column; height: 100%; overflow: hidden; }
.view.active { display: flex; }

.panel-head { padding: 20px 22px 14px; border-bottom: 1px solid var(--hull); flex-shrink: 0; }
.panel-head h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.6px; }
.panel-sub { color: var(--fog); font-size: 13px; margin-top: 3px; }
.panel-sub strong { color: var(--coral); }

/* Scrollbars */
.view ::-webkit-scrollbar, .scrollable::-webkit-scrollbar { width: 5px; }
.view ::-webkit-scrollbar-thumb, .scrollable::-webkit-scrollbar-thumb { background: var(--hull); border-radius: 3px; }
.view ::-webkit-scrollbar-track { background: transparent; }

/* ── SEARCH ─────────────────────────────────────────────────────────────────── */
.search-wrap { padding: 14px 18px 8px; flex-shrink: 0; position: relative; }
.search-wrap input, .search-wrap select {
  width: 100%; background: var(--night);
  border: 1px solid var(--hull); border-radius: var(--r-sm);
  color: var(--foam); font-family: var(--font-mono); font-size: 13px;
  padding: 10px 12px; transition: border-color .18s;
}
.search-wrap input:focus, .search-wrap select:focus {
  outline: none; border-color: var(--sea-bright);
}
.search-wrap input::placeholder { color: var(--fog); opacity: .7; }
.search-wrap select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%238ba3b8' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}

.search-results {
  position: absolute; left: 18px; right: 18px; top: 100%;
  background: var(--night-3); border: 1px solid var(--hull);
  border-radius: var(--r-sm); max-height: 260px; overflow-y: auto;
  z-index: 100; box-shadow: var(--shadow);
}
.search-results:empty { display: none; }
.sr-item {
  padding: 10px 13px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--hull); transition: background .12s;
}
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--sea); }
.sr-item .sr-id { font-family: var(--font-mono); font-size: 10px; color: var(--fog); }

/* ── LINE CHIPS (en vivo) ───────────────────────────────────────────────────── */
.line-chips {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 14px 18px; overflow-y: auto; max-height: 200px;
  border-bottom: 1px solid var(--hull); flex-shrink: 0;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 20px;
  border: 1.5px solid var(--hull); background: var(--night);
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  color: var(--fog); cursor: pointer; transition: all .15s;
  user-select: none;
}
.chip:hover { border-color: var(--fog); }
.chip .chip-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.chip.active { color: #fff; border-color: transparent; }

/* ── LIVE INFO ──────────────────────────────────────────────────────────────── */
.live-info { flex: 1; overflow-y: auto; padding: 8px 0; }
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 50px 30px; text-align: center; color: var(--fog);
}
.empty-state p { font-size: 14px; line-height: 1.5; }

.live-line-block { border-bottom: 1px solid var(--hull); padding: 12px 18px; }
.llb-head {
  display: flex; align-items: center; gap: 9px; margin-bottom: 8px;
}
.llb-badge {
  font-family: var(--font-mono); font-weight: 700; font-size: 13px;
  padding: 3px 9px; border-radius: var(--r-sm); color: #fff;
}
.llb-name { font-size: 13px; font-weight: 600; color: var(--foam); }
.llb-count { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--fog); }
.bus-pill {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; margin: 4px 0; border-radius: var(--r-sm);
  background: var(--night); font-size: 12px;
}
.bus-pill .bp-dest { color: var(--fog); }
.bus-pill .bp-eta { font-family: var(--font-mono); font-weight: 700; color: var(--kelp); }
.bus-pill .bp-eta.soon { color: var(--coral); }

/* ── LÍNEAS GRID ────────────────────────────────────────────────────────────── */
.lines-grid { flex: 1; overflow-y: auto; padding: 8px; }
.line-card {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px; border-radius: var(--r-md); cursor: pointer;
  transition: background .12s; margin-bottom: 3px;
}
.line-card:hover { background: var(--night-3); }
.line-badge-lg {
  display: flex; align-items: center; justify-content: center;
  min-width: 44px; height: 36px; padding: 0 8px; border-radius: var(--r-sm);
  font-family: var(--font-mono); font-weight: 700; font-size: 15px;
  color: #fff; flex-shrink: 0;
}
.line-card-info { flex: 1; min-width: 0; }
.line-card-name { font-size: 13px; font-weight: 600; }
.line-card-meta { font-size: 11px; color: var(--fog); font-family: var(--font-mono); margin-top: 2px; }
.line-card-arrow { color: var(--fog); opacity: .5; }

/* ── RUTAS DETAIL ───────────────────────────────────────────────────────────── */
#routes-detail, #schedule-detail, #journey-results, #planner-departures {
  flex: 1; overflow-y: auto; padding: 0 0 20px;
}
.dir-toggle {
  display: flex; gap: 6px; padding: 12px 18px 4px;
}
.dir-btn {
  flex: 1; padding: 8px; border-radius: var(--r-sm); cursor: pointer;
  background: var(--night); border: 1px solid var(--hull);
  color: var(--fog); font-family: var(--font-display); font-size: 12px; font-weight: 600;
  transition: all .15s;
}
.dir-btn.active { background: var(--sea); color: #fff; border-color: var(--sea); }

.stop-sequence { padding: 8px 18px; }
.seq-stop {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0; cursor: pointer; position: relative;
}
.seq-stop:hover .seq-name { color: var(--sea-bright); }
.seq-marker {
  width: 13px; height: 13px; border-radius: 50%;
  border: 3px solid var(--coral); background: var(--night-2);
  flex-shrink: 0; z-index: 2;
}
.seq-stop:not(:last-child)::before {
  content: ''; position: absolute; left: 6px; top: 18px; bottom: -8px;
  width: 2px; background: var(--hull); z-index: 1;
}
.seq-name { font-size: 13px; transition: color .15s; }
.seq-id { font-family: var(--font-mono); font-size: 10px; color: var(--fog); margin-left: auto; }

/* ── HORARIOS ───────────────────────────────────────────────────────────────── */
.sched-controls { padding: 8px 18px; flex-shrink: 0; }
.sched-controls input[type=date] {
  width: 100%; background: var(--night); border: 1px solid var(--hull);
  border-radius: var(--r-sm); color: var(--foam); font-family: var(--font-mono);
  font-size: 13px; padding: 9px 12px; color-scheme: dark;
}
.sched-line-group { border-bottom: 1px solid var(--hull); padding: 12px 18px; }
.slg-head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.times-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
}
.time-chip {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  text-align: center; padding: 6px 4px; border-radius: 6px;
  background: var(--night); color: var(--foam); transition: all .12s;
}
.time-chip.next { background: var(--coral); color: #fff; font-weight: 700; }
.time-chip.past { opacity: .35; }
.time-dest-label {
  font-size: 11px; color: var(--fog); font-family: var(--font-mono);
  margin: 8px 0 4px;
}

/* ── CÓMO LLEGAR ────────────────────────────────────────────────────────────── */
.journey-points { padding: 16px 18px; }
.jp-row { display: flex; align-items: center; gap: 11px; }
.jp-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.jp-dot.origin { background: var(--sea-bright); }
.jp-dot.dest { background: var(--coral); }
.jp-line { width: 2px; height: 18px; background: var(--hull); margin-left: 6px; }
.jp-label { flex: 1; font-size: 13px; color: var(--fog); }
.jp-label.set { color: var(--foam); }
.jp-clear {
  background: none; border: none; color: var(--fog); cursor: pointer;
  font-size: 20px; line-height: 1; padding: 0 4px; opacity: .5;
}
.jp-clear:hover { opacity: 1; color: var(--coral); }

.btn-primary {
  margin: 8px 18px 14px; padding: 12px;
  background: var(--coral); color: #fff; border: none;
  border-radius: var(--r-md); font-family: var(--font-display);
  font-size: 14px; font-weight: 700; cursor: pointer;
  transition: all .15s;
}
.btn-primary:hover:not(:disabled) { background: var(--coral-deep); }
.btn-primary:disabled { background: var(--hull); color: var(--fog); cursor: not-allowed; }

.journey-option {
  margin: 0 18px 12px; padding: 14px;
  background: var(--night); border: 1px solid var(--hull);
  border-radius: var(--r-md); cursor: pointer; transition: all .15s;
}
.journey-option:hover { border-color: var(--sea-bright); }
.jo-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.jo-badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  font-family: var(--font-mono);
}
.jo-badge.direct { background: var(--kelp); color: var(--night); }
.jo-badge.transfer { background: var(--amber); color: var(--night); }
.jo-walk { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--fog); }
.jo-legs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.jo-leg-line {
  font-family: var(--font-mono); font-weight: 700; font-size: 13px;
  padding: 4px 10px; border-radius: var(--r-sm); color: #fff;
}
.jo-arrow { color: var(--fog); }
.jo-detail { font-size: 11px; color: var(--fog); margin-top: 8px; line-height: 1.5; }

/* ── PLANIFICADOR ───────────────────────────────────────────────────────────── */
.planner-tabs { display: flex; padding: 12px 18px 0; gap: 6px; }
.pl-tab {
  flex: 1; padding: 9px; background: var(--night); border: 1px solid var(--hull);
  border-radius: var(--r-sm); color: var(--fog); cursor: pointer;
  font-family: var(--font-display); font-size: 12px; font-weight: 600; transition: all .15s;
}
.pl-tab.active { background: var(--sea); color: #fff; border-color: var(--sea); }
.pl-panel { display: none; flex-direction: column; }
.pl-panel.active { display: flex; }
.planner-row { display: flex; gap: 8px; padding: 4px 18px 8px; }
.planner-row input {
  flex: 1; background: var(--night); border: 1px solid var(--hull);
  border-radius: var(--r-sm); color: var(--foam); font-family: var(--font-mono);
  font-size: 13px; padding: 9px 10px; color-scheme: dark;
}
.sim-note { padding: 12px 18px; font-size: 12px; color: var(--fog); font-family: var(--font-mono); line-height: 1.5; }

.dep-row {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 18px; border-bottom: 1px solid var(--hull);
}
.dep-time { font-family: var(--font-mono); font-weight: 700; font-size: 15px; min-width: 52px; }
.dep-badge { font-family: var(--font-mono); font-weight: 700; font-size: 12px; padding: 3px 8px; border-radius: 6px; color: #fff; }
.dep-dest { font-size: 12px; color: var(--fog); flex: 1; }

/* ── MAPA: marcadores ───────────────────────────────────────────────────────── */
.leaflet-container { background: var(--night) !important; font-family: var(--font-display) !important; }
.leaflet-tile { filter: brightness(.6) saturate(.55) hue-rotate(185deg) contrast(1.05); }

.bus-icon-wrap {
  position: relative; width: 44px; height: 28px;
}
.minibus-rot {
  transition: transform .6s ease;
  transform-origin: center;
}
.minibus { display: block; }
/* Número de línea, siempre horizontal y centrado sobre el bus */
.bus-num {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono); font-weight: 700; font-size: 11px;
  padding: 0 5px; min-width: 16px; text-align: center; border-radius: 6px;
  pointer-events: none; line-height: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.95);
  box-shadow: 0 1px 5px rgba(0,0,0,.6); z-index: 4;
}
/* Flecha de dirección, por encima del bus */
.bus-arrow {
  position: absolute; top: -14px; left: 50%;
  margin-left: -6.5px; transform-origin: center;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5));
}
.bus-eta {
  position: absolute; top: -32px; left: 50%; transform: translateX(-50%);
  background: var(--night-2); border: 1px solid var(--hull);
  color: var(--foam); font-family: var(--font-mono); font-weight: 700;
  font-size: 10px; padding: 2px 6px; border-radius: 10px; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.5); z-index: 3;
}
.bus-eta.soon { background: var(--coral); border-color: var(--coral); color: #fff; }

.stop-dot {
  border-radius: 50%; border: 2px solid rgba(255,255,255,.92);
  box-shadow: 0 1px 5px rgba(0,0,0,.6); cursor: pointer;
  box-sizing: border-box; transition: width .15s, height .15s;
}
.stop-dot.big { width: 16px !important; height: 16px !important; }

.jp-marker {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg); border: 3px solid #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
}
.jp-marker.origin { background: var(--sea-bright); }
.jp-marker.dest { background: var(--coral); }
.jp-marker svg { transform: rotate(45deg); }

/* Leaflet popups */
.leaflet-popup-content-wrapper {
  background: var(--night-2) !important; color: var(--foam) !important;
  border: 1px solid var(--hull) !important; border-radius: var(--r-md) !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-popup-tip { background: var(--night-2) !important; border: 1px solid var(--hull) !important; }
.leaflet-popup-content { margin: 12px 14px !important; font-family: var(--font-display) !important; }
.popup-title { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.popup-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 12px; padding: 3px 0; border-top: 1px solid var(--hull);
}
.popup-badge { font-family: var(--font-mono); font-weight: 700; font-size: 11px; padding: 2px 7px; border-radius: 5px; color: #fff; }
.popup-eta { font-family: var(--font-mono); font-weight: 700; color: var(--kelp); }
.popup-eta.soon { color: var(--coral); }
.leaflet-control-zoom a {
  background: var(--night-2) !important; color: var(--foam) !important;
  border-color: var(--hull) !important;
}
.leaflet-control-zoom a:hover { background: var(--night-3) !important; }

/* ── TOAST ──────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--night-3); border: 1px solid var(--hull);
  color: var(--foam); padding: 10px 18px; border-radius: var(--r-md);
  font-family: var(--font-mono); font-size: 12px; z-index: 5000;
  transition: transform .3s cubic-bezier(.4,0,.2,1); box-shadow: var(--shadow);
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MÓVIL
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --nav-h: 64px; }

  #main { flex-direction: column; }

  /* Nav pasa abajo */
  #nav {
    order: 2; height: var(--nav-h);
    border-bottom: none; border-top: 1px solid var(--hull);
    padding: 0 4px; gap: 0;
  }
  .nav-brand { display: none; }
  .nav-status { display: none; }
  .nav-tabs {
    width: 100%; justify-content: space-around; gap: 0;
  }
  .nav-tab {
    flex-direction: column; gap: 3px; padding: 6px 4px;
    font-size: 9px; flex: 1; border-radius: var(--r-sm);
  }
  .nav-tab span { font-size: 9px; }
  .nav-tab.active { background: none; color: var(--coral); }
  .nav-tab.active svg { color: var(--coral); }
  .nav-tab svg { width: 22px; height: 22px; }

  /* Panel: hoja inferior de ALTURA AUTOMÁTICA (se ajusta al contenido) */
  #main { order: 1; }
  #map { inset: 0; }
  #panel {
    position: absolute; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%;
    height: auto;                 /* se ajusta al contenido */
    max-height: 62vh;             /* tope para no comerse el mapa */
    border-right: none; border-top: 1px solid var(--hull);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    z-index: 600;
    display: flex; flex-direction: column;
    box-shadow: 0 -6px 24px rgba(0,0,0,.4);
  }
  /* Colapsado: solo asoma la cabecera (la "agarradera" + título) */
  #panel.collapsed { transform: translateY(calc(100% - 66px)); }

  /* Agarradera para arrastrar */
  #panel::before {
    content: ''; position: absolute; top: 8px; left: 50%;
    transform: translateX(-50%); width: 40px; height: 5px;
    background: var(--fog); opacity: .4; border-radius: 3px; z-index: 10;
  }
  .panel-head {
    padding: 18px 18px 10px; cursor: pointer; flex-shrink: 0;
    touch-action: none;          /* permite el gesto de arrastre */
  }
  .panel-head h2 { font-size: 18px; }
  .panel-sub { font-size: 11.5px; }

  /* El cuerpo de cada vista hace scroll si se pasa del máximo.
     Solo la vista activa se muestra (como flex-column); las demás ocultas. */
  .view { height: auto; }
  .view.active { display: flex; flex-direction: column; min-height: 0; max-height: 62vh; overflow: hidden; }
  .line-chips, .lines-grid, .live-info, #routes-list,
  .journey-results, #schedule-detail, #planner-body {
    overflow-y: auto; -webkit-overflow-scrolling: touch;
  }

  #toast { bottom: calc(var(--nav-h) + 16px); }

  .times-grid { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); }

  /* En vivo: chips compactos */
  .line-chips { padding: 8px 14px; gap: 6px; max-height: 40vh; }
  .chip { padding: 5px 10px; font-size: 11.5px; gap: 5px; }
  .chip .chip-dot { width: 9px; height: 9px; }
  .live-info { padding: 2px 0; }
  .live-line-block { padding: 8px 14px; }
  .bus-pill { padding: 6px 9px; font-size: 11px; }
  .empty-hint { padding: 12px 16px 16px; font-size: 12px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, .bus-icon-wrap { transition: none !important; animation: none !important; }
}

/* ── Parada resaltada al pinchar ──────────────────────────────────────────── */
.stop-highlight {
  width: 40px; height: 40px; position: relative;
  display: flex; align-items: center; justify-content: center;
}
.stop-highlight::before {
  content: ''; position: absolute; inset: 0;
  border-radius: 50%; background: var(--hl); opacity: .35;
  animation: stoppulse 1.6s ease-out infinite;
}
.stop-highlight-core {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--hl); border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.6); z-index: 2;
}
@keyframes stoppulse {
  0%   { transform: scale(.4); opacity: .55; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ── Opción de viaje seleccionada ─────────────────────────────────────────── */
.journey-option.sel {
  border-color: var(--coral);
  background: var(--night-3);
  box-shadow: inset 3px 0 0 var(--coral);
}

/* ── Próximas llegadas en popup de parada ─────────────────────────────────── */
.popup-arrivals { margin: 4px 0; }
.pa-loading, .pa-empty { font-size: 12px; color: var(--fog); padding: 4px 0; }
.pa-src {
  display: inline-block; font-family: var(--font-mono); font-size: 9px;
  padding: 2px 7px; border-radius: 10px; margin-bottom: 6px; font-weight: 600;
}
.pa-src.live  { background: rgba(63,185,138,.18); color: var(--kelp); }
.pa-src.sched { background: rgba(255,184,77,.18); color: var(--amber); }
.pa-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; border-top: 1px solid var(--hull);
}
.pa-badge {
  font-family: var(--font-mono); font-weight: 700; font-size: 11px;
  padding: 2px 7px; border-radius: 5px; flex-shrink: 0; min-width: 26px; text-align: center;
}
.pa-dest { font-size: 11px; color: var(--fog); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pa-times { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.pa-eta { font-family: var(--font-mono); font-weight: 700; font-size: 12px; color: var(--foam); }
.pa-eta.soon { color: var(--coral); }
.pa-sep { color: var(--hull); }

/* ── Minibús ──────────────────────────────────────────────────────────────── */
.minibus { filter: drop-shadow(0 3px 6px rgba(0,0,0,.6)); }

/* ── Botón geolocalización ────────────────────────────────────────────────── */
#geo-btn {
  position: absolute; right: 12px; bottom: 28px; z-index: 600;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--night-2); border: 1px solid var(--hull);
  color: var(--sea-bright); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); transition: all .15s;
}
#geo-btn:hover { background: var(--night-3); color: #fff; }
#geo-btn:active { transform: scale(.92); }

/* Marcador de ubicación del usuario */
.user-loc {
  width: 24px; height: 24px; position: relative;
  display: flex; align-items: center; justify-content: center;
}
.user-loc::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: var(--sea-bright); opacity: .3;
  animation: stoppulse 2s ease-out infinite;
}
.user-loc-core {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--sea-bright); border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.6); z-index: 2;
}

/* ── Banner instalar PWA ──────────────────────────────────────────────────── */
#install-banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 16px; z-index: 5000;
  display: flex; align-items: center; gap: 12px;
  background: var(--night-2); border: 1px solid var(--hull);
  border-radius: var(--r-lg); padding: 12px 14px;
  box-shadow: var(--shadow); max-width: 92vw; width: 380px;
}
.ib-icon { flex-shrink: 0; }
.ib-text { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ib-text strong { font-size: 14px; }
.ib-text span { font-size: 11px; color: var(--fog); }
#install-btn {
  flex-shrink: 0; background: var(--coral); color: #fff; border: none;
  border-radius: var(--r-md); padding: 9px 16px; font-weight: 700;
  font-family: var(--font-display); font-size: 13px; cursor: pointer;
}
#install-btn:hover { background: var(--coral-deep); }
#install-close {
  flex-shrink: 0; background: none; border: none; color: var(--fog);
  font-size: 22px; line-height: 1; cursor: pointer; padding: 0 2px; opacity: .6;
}
#install-close:hover { opacity: 1; }

@media (max-width: 768px) {
  /* En móvil el panel es de altura variable: el botón de ubicación va arriba
     a la derecha, bajo los controles de zoom, para no chocar con el panel. */
  #geo-btn { top: 96px; bottom: auto; right: 12px; }
  #install-banner { bottom: calc(var(--nav-h) + 12px); }
}

/* ── Modal Info ───────────────────────────────────────────────────────────── */
#info-modal {
  position: fixed; inset: 0; z-index: 6000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.info-backdrop {
  position: absolute; inset: 0;
  background: rgba(5, 12, 20, .72); backdrop-filter: blur(3px);
}
.info-card {
  position: relative; z-index: 2;
  background: var(--night-2); border: 1px solid var(--hull);
  border-radius: var(--r-lg); padding: 28px 26px 24px;
  max-width: 420px; width: 100%; text-align: center;
  box-shadow: var(--shadow);
  animation: infoIn .25s cubic-bezier(.4,0,.2,1);
}
@keyframes infoIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
#info-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--fog);
  font-size: 26px; line-height: 1; cursor: pointer; opacity: .6;
}
#info-close:hover { opacity: 1; color: var(--coral); }
.info-mark { margin-bottom: 10px; }
.info-card h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.6px; margin-bottom: 14px; }
.info-card h2 strong { color: var(--coral); }
.info-lead { font-size: 15px; color: var(--foam); margin-bottom: 12px; }
.info-lead strong { color: var(--sea-bright); }
.info-card p { font-size: 13px; color: var(--fog); line-height: 1.6; margin-bottom: 12px; }
.info-note {
  font-size: 11.5px !important; color: var(--fog); opacity: .85;
  background: var(--night); border-radius: var(--r-sm);
  padding: 10px 12px; border: 1px solid var(--hull);
}
.info-links { display: flex; flex-direction: column; gap: 9px; margin-top: 18px; }
.info-link {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 11px; border-radius: var(--r-md); text-decoration: none;
  font-weight: 700; font-size: 13px; transition: all .15s;
  background: var(--night-3); color: var(--foam); border: 1px solid var(--hull);
}
.info-link:hover { background: var(--hull); }
.info-link.linkedin { background: #0a66c2; border-color: #0a66c2; color: #fff; }
.info-link.linkedin:hover { background: #0954a0; }

/* ── Botón volver (vista Rutas) ───────────────────────────────────────────── */
.back-btn {
  margin: 12px 18px 4px; padding: 8px 14px;
  background: var(--night); border: 1px solid var(--hull);
  border-radius: var(--r-sm); color: var(--sea-bright);
  font-family: var(--font-display); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.back-btn:hover { background: var(--night-3); color: #fff; }
#routes-list-wrap, #routes-detail-wrap { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#routes-list-wrap.hidden, #routes-detail-wrap.hidden { display: none; }

/* ── Modal Stats ──────────────────────────────────────────────────────────── */
#stats-modal {
  position: fixed; inset: 0; z-index: 6000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.stats-card { max-width: 520px; text-align: left; max-height: 88vh; overflow-y: auto; }
.stats-card h2 { text-align: center; font-size: 22px; font-weight: 800; margin-bottom: 16px; }
#stats-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--fog);
  font-size: 26px; line-height: 1; cursor: pointer; opacity: .6;
}
#stats-close:hover { opacity: 1; color: var(--coral); }

.stats-periods {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; justify-content: center;
}
.stats-periods button {
  background: var(--night); border: 1px solid var(--hull);
  color: var(--fog); border-radius: 20px; padding: 6px 14px;
  font-family: var(--font-display); font-size: 12px; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.stats-periods button:hover { border-color: var(--fog); color: var(--foam); }
.stats-periods button.active { background: var(--coral); border-color: var(--coral); color: #fff; }

.stats-kpis { display: flex; gap: 12px; margin-bottom: 22px; }
.kpi {
  flex: 1; background: var(--night); border: 1px solid var(--hull);
  border-radius: var(--r-md); padding: 16px; text-align: center;
}
.kpi-num { display: block; font-family: var(--font-mono); font-weight: 700; font-size: 30px; color: var(--sea-bright); }
.kpi-label { font-size: 11px; color: var(--fog); }

.stats-section { margin-bottom: 22px; }
.stats-section h3 { font-size: 13px; font-weight: 700; color: var(--foam); margin-bottom: 12px; }

/* Gráfico de horas */
.hours-chart {
  display: flex; align-items: flex-end; gap: 2px; height: 110px;
  padding: 8px 4px 0; background: var(--night); border: 1px solid var(--hull);
  border-radius: var(--r-md);
}
.hbar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.hbar {
  width: 100%; max-width: 12px; border-radius: 3px 3px 0 0;
  background: linear-gradient(to top, var(--sea), var(--sea-bright));
  min-height: 2px; transition: height .3s;
}
.hbar-lbl { font-family: var(--font-mono); font-size: 8px; color: var(--fog); margin-top: 3px; height: 10px; }

/* Ranking dispositivos */
.devices-rank { display: flex; flex-direction: column; gap: 9px; }
.dev-row { display: flex; align-items: center; gap: 10px; }
.dev-name { font-size: 12px; min-width: 110px; flex-shrink: 0; }
.dev-bar-wrap { flex: 1; height: 8px; background: var(--night); border-radius: 5px; overflow: hidden; }
.dev-bar { height: 100%; background: linear-gradient(to right, var(--coral-deep), var(--coral)); border-radius: 5px; transition: width .4s; }
.dev-count { font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: var(--foam); min-width: 36px; text-align: right; }
.dev-empty { font-size: 12px; color: var(--fog); padding: 8px 0; }

@media (max-width: 768px) {
  .dev-name { min-width: 88px; font-size: 11px; }
  .kpi-num { font-size: 24px; }
}

/* ── Mensaje "elige línea" compacto (vista En vivo) ───────────────────────── */
.empty-hint {
  padding: 14px 18px; font-size: 12.5px; color: var(--fog);
  text-align: center; line-height: 1.5;
}

/* En móvil, el panel es más bajo: el bloque de chips se hace scrollable
   para poder llegar a todas las líneas, y la zona de info también. */
@media (max-width: 768px) {
  .line-chips { max-height: 118px; overflow-y: auto; }
  .empty-hint { padding: 10px 16px; font-size: 12px; }
}

/* Etiqueta tiempo real en el panel En vivo */
.src-tag {
  display: inline-block; font-family: var(--font-mono); font-size: 9px;
  padding: 2px 8px; border-radius: 10px; margin: 0 14px 6px; font-weight: 600;
}
.src-tag.live { background: rgba(63,185,138,.18); color: var(--kelp); }
