/* Transit Cádiz — app del urbano. Paleta sobria, clara/oscura. */
:root {
  color-scheme: light dark;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #162033;
  --muted: #53627a;
  --accent: #006f9e;
  --accent-text: #ffffff;
  --border: #d9e2ee;
  --ok: #1a7f4b;
  --warn: #8a5300;
  --danger: #b3261e;
  --shadow: 0 2px 12px rgba(20, 33, 51, .12);
  --topbar-h: 3.25rem;
  --tabbar-h: 3.75rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --surface: #151d2c;
    --surface-2: #1e293b;
    --text: #eef4ff;
    --muted: #a9b7cd;
    --accent: #4bb8e6;
    --accent-text: #06222e;
    --border: #2b3648;
    --ok: #4ecb86;
    --warn: #f2bd6b;
    --danger: #ff8a80;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #151d2c;
  --surface-2: #1e293b;
  --text: #eef4ff;
  --muted: #a9b7cd;
  --accent: #4bb8e6;
  --accent-text: #06222e;
  --border: #2b3648;
  --ok: #4ecb86;
  --warn: #f2bd6b;
  --danger: #ff8a80;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }

/* --- Estructura ------------------------------------------------------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 60rem;
  margin: 0 auto;
  background: var(--bg);
}
.topbar {
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; text-decoration: none; color: var(--text); }
.brand-mark { color: var(--accent); font-size: 1.2rem; }
.brand-text { font-size: 1.05rem; }
.topbar .pill { margin-left: auto; }

.view { flex: 1 1 auto; position: relative; overflow: hidden; }

.tabbar {
  flex: 0 0 var(--tabbar-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1rem;
  text-decoration: none;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
}
.tab-ico { font-size: 1.15rem; line-height: 1; }
.tab.is-active { color: var(--accent); }

/* --- Píldoras / estado --------------------------------------------------- */
.pill {
  font-size: .78rem;
  font-weight: 600;
  padding: .2rem .55rem;
  border-radius: 999px;
  white-space: nowrap;
}
.pill-ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill-warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.pill-danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.pill-muted { background: var(--surface-2); color: var(--muted); }

/* --- Insignia de línea -------------------------------------------------- */
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 .35rem;
  border-radius: .45rem;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

/* --- Botones --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem .9rem;
  border: 1px solid var(--border);
  border-radius: .6rem;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-sm { padding: .35rem .6rem; font-size: .85rem; }

/* --- Páginas (stubs) ------------------------------------------------- */
.page { padding: 1.25rem 1rem 2rem; height: 100%; overflow-y: auto; }
.page-title { margin: .25rem 0 1rem; font-size: 1.5rem; }
.section-h { margin: 1.5rem 0 .5rem; font-size: 1rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.linelist { list-style: none; margin: .5rem 0; padding: 0; display: grid; gap: .5rem; }
.linelist-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .6rem;
  text-decoration: none;
  color: var(--text);
}
.segrow { display: flex; gap: .5rem; flex-wrap: wrap; }
.seg {
  padding: .5rem .9rem;
  border: 1px solid var(--border);
  border-radius: .6rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.seg.is-on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* --- Ficha de parada --------------------------------------------------- */
.page-back {
  display: inline-block; font-size: .9rem; text-decoration: none;
  /* Área táctil ≥ 40 px sin desplazar el texto (padding + margen negativo). */
  padding: .45rem .5rem; margin: -.25rem -.5rem .25rem;
}
.stop-head { display: flex; align-items: flex-start; gap: .75rem; }
.stop-head .page-title { margin: 0; }
.stop-head > div:first-child { flex: 1 1 auto; min-width: 0; }
.stop-side { display: flex; flex-direction: column; align-items: flex-end; gap: .45rem; flex: 0 0 auto; }
.stop-lines { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .35rem; }
.stop-lines a { text-decoration: none; }

.star {
  flex: 0 0 auto;
  width: 2.4rem; height: 2.4rem;
  border: 1px solid var(--border);
  border-radius: .6rem;
  background: var(--surface);
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.star.is-on { color: #f5a623; border-color: #f5a623; }

.arrivals-widget { margin-top: 1rem; }
.arrivals-meta { margin: 0 0 .5rem; font-size: .82rem; }
.arrivals-meta.is-warn { color: var(--warn); }
.arrivals { list-style: none; margin: 0; padding: 0; display: grid; gap: .1rem; }
.arrivals-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem .25rem;
  border-bottom: 1px solid var(--border);
}
.arrivals-row:last-child { border-bottom: 0; }
.arrivals-dest { font-size: .95rem; }
.grow { flex: 1 1 auto; }
.eta { font-variant-numeric: tabular-nums; white-space: nowrap; display: inline-flex; align-items: baseline; gap: .4rem; }
.eta-kind {
  font-size: .6rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: .12rem .32rem; border-radius: .3rem; line-height: 1; align-self: center;
}
.eta.is-rt .eta-kind { color: #fff; background: var(--ok); }
.eta.is-sched .eta-kind { color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); }
.eta.is-rt .eta-time { font-weight: 800; color: var(--text); }
.eta.is-sched .eta-time { color: var(--muted); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* --- Salidas desde cabecera (parada) + "última salida" ------------------ */
.tt-lastbus { margin: 0 0 .5rem; font-size: .82rem; color: var(--warn); font-weight: 600; }
.headway {
  margin-top: .9rem; padding: .7rem .8rem;
  border: 1px solid var(--border); border-radius: .6rem;
  background: var(--surface-2); font-size: .86rem;
}
.headway-head { display: flex; align-items: center; gap: .35rem; font-weight: 700; margin-bottom: .4rem; }
.headway-row { display: flex; align-items: center; gap: .5rem; padding: .2rem 0; }
.headway-last { color: var(--warn); font-weight: 600; }

/* --- Aviso "🔔 Avísame" ------------------------------------------------- */
.arrivals-metarow { display: flex; align-items: center; gap: .35rem; margin: 0 0 .5rem; }
.arrivals-metarow .arrivals-meta { margin: 0; }
.arrivals-maplink { display: inline-block; margin-top: .55rem; }
.remind { margin-top: .6rem; }
.remind-head { display: flex; align-items: center; gap: .3rem; }
.remind-toggle { font-weight: 600; }
.remind-setup { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .5rem; }
.remind-setup[hidden], .remind-status[hidden], .remind-head[hidden] { display: none; }
.remind-sel {
  padding: .4rem .5rem; border: 1px solid var(--border); border-radius: .5rem;
  background: var(--surface); color: var(--text); font: inherit;
}
.remind-status {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  margin-top: .4rem; padding: .5rem .7rem;
  background: color-mix(in srgb, var(--ok) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--ok) 35%, var(--border));
  border-radius: .6rem; font-size: .88rem;
}
.link-with-info { display: inline-flex; align-items: center; gap: .2rem; }

/* --- Modo "en la parada" (letra grande) ------------------------------- */
.stop-simple-title { font-size: clamp(1.6rem, 6vw, 2.4rem); margin: .5rem 0 .25rem; }
.arrivals-big .arrivals-row { padding: .9rem .3rem; gap: .8rem; }
.arrivals-big .arrivals-dest { font-size: 1.1rem; }
.arrivals-big .eta-time { font-size: 1.6rem; }
.arrivals-big .eta-kind { font-size: .66rem; }
.arrivals-big .badge { min-width: 2rem; height: 2rem; font-size: 1rem; }

/* --- Burbuja de ayuda "ⓘ" --------------------------------------------- */
.info-wrap { position: relative; display: inline-flex; }
.info-dot {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: .95rem; line-height: 1; padding: .1rem; border-radius: 50%;
}
.info-dot:hover, .info-dot:focus-visible { color: var(--accent); }
.info-pop {
  /* z-index por encima de los paneles y controles de Leaflet (hasta 1000),
     que si no se comen la burbuja cuando el dot está cerca de un mapa. */
  position: absolute; top: calc(100% + .3rem); left: 0; z-index: 1200;
  width: min(17rem, 72vw); padding: .5rem .6rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: .5rem;
  box-shadow: var(--shadow); font-size: .8rem; font-weight: 400; line-height: 1.4;
}

.ministop-map {
  margin-top: 1rem;
  height: 12rem;
  border: 1px solid var(--border);
  border-radius: .75rem;
  overflow: hidden;
  background: var(--surface-2);
}

/* --- Bottom sheet ---------------------------------------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(10, 15, 25, 0);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: background .2s ease;
}
.sheet-backdrop.is-open { background: rgba(10, 15, 25, .45); }
.sheet {
  width: min(100%, 34rem);
  max-height: 78dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 1rem 1rem 0 0;
  padding: .5rem 1.15rem calc(1.15rem + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(10, 15, 25, .25);
  transform: translateY(100%);
  transition: transform .22s ease;
}
.sheet-backdrop.is-open .sheet { transform: translateY(0); }
.sheet-grip { width: 2.5rem; height: .3rem; border-radius: 999px; background: var(--border); margin: .35rem auto .6rem; }
.sheet-head { display: flex; align-items: center; gap: .75rem; }
.sheet-title { flex: 1 1 auto; font-size: 1.05rem; }
.sheet-close {
  flex: 0 0 auto;
  width: 2rem; height: 2rem;
  border: 0; border-radius: .5rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}
.sheet-full { margin-top: .75rem; }

/* --- Mapa ----------------------------------------------------------- */
.map { position: absolute; inset: 0; background: var(--surface-2); }
/* Modo oscuro del mapa: no hay un segundo servidor de teselas sin coste, así
   que se oscurecen las mismas teselas de OSM con un filtro. Solo afecta al
   panel de teselas (aplicado vía applyDarkTiles en ui.js), no a rutas ni
   marcadores, que van en otros paneles de Leaflet. */
.map-dark-tiles { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
.map-loading,
.map-hint { position: absolute; z-index: 500; }
.map-loading {
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.map-hint {
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--muted);
  font-size: .8rem;
  padding: .3rem .7rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.map-hint:empty { display: none; }

.loading { display: flex; align-items: center; gap: .6rem; color: var(--muted); }
.spin {
  width: 1.1rem; height: 1.1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.errbox {
  margin: 2rem auto;
  max-width: 22rem;
  text-align: center;
  color: var(--muted);
  display: grid;
  gap: .75rem;
  justify-items: center;
}

/* Filtro de líneas sobre el mapa (contraíble) */
.map-filter {
  background: var(--surface);
  border: 1px solid var(--border) !important;
  border-radius: .6rem !important;
  padding: .25rem;
  max-width: 12.5rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.map-filter-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .3rem .4rem;
  border: 0;
  border-radius: .4rem;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.map-filter-head:hover { background: var(--surface-2); }
.map-filter-title { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; flex: 1 1 auto; text-align: left; }
.map-filter-caret {
  font-size: .95rem;
  line-height: 1;
  transition: transform .15s ease;
  transform: rotate(90deg); /* expandido: apunta hacia abajo */
}
.map-filter.is-collapsed .map-filter-caret { transform: rotate(0); }
.map-filter-body { margin-top: .15rem; }
.map-filter.is-collapsed .map-filter-body { display: none; }

.lchip {
  display: flex;
  align-items: center;
  gap: .4rem;
  width: 100%;
  padding: .25rem .35rem;
  border: 0;
  border-radius: .4rem;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: .74rem;
  text-align: left;
  cursor: pointer;
  opacity: .4;
}
.lchip:hover { background: var(--surface-2); }
.lchip.is-on { opacity: 1; }
.lchip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lchip-rc { margin-top: .15rem; border-top: 1px solid var(--border); padding-top: .35rem; }
.lchip-dot { width: 1.15rem; text-align: center; font-size: .9rem; }

.map-locate {
  display: grid !important;
  place-items: center;
  width: 34px; height: 34px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  text-decoration: none;
}

/* Autobuses en vivo: triángulo SVG que apunta al rumbo (ver vehicleDivIcon).
   position:absolute es OBLIGATORIO: Leaflet posiciona el icono con translate3d()
   desde el origen del panel; con position:relative/static cada icono queda además
   en el flujo normal y el N-ésimo baja ~17 px de más (los buses "se caían" hacia
   abajo, peor cuanto más alejado el zoom). */
.veh-icon { background: none !important; border: 0 !important; position: absolute; }
.veh-icon svg { display: block; filter: drop-shadow(0 1px 1.5px rgba(10, 15, 25, .45)); }
.veh-icon.is-stale { opacity: .45; }
/* Flechas de sentido a lo largo de los trazados. */
.dir-arrow { background: none !important; border: 0 !important; position: absolute; }
.dir-arrow svg { display: block; filter: drop-shadow(0 0 1px rgba(10, 15, 25, .35)); }
.map-notice {
  position: absolute;
  z-index: 600;
  bottom: 2.75rem;      /* abajo, para no chocar con el filtro de la esquina */
  left: 50%;
  transform: translateX(-50%);
  max-width: 80%;
  text-align: center;
  background: var(--warn);
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  padding: .3rem .7rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.popup-linelink { font-size: .8rem; align-self: center; }

/* Popups de Leaflet con nuestros tokens */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-popup-content { margin: .7rem .9rem; }
.popup { display: grid; gap: .45rem; min-width: 11rem; }
.popup-sub { font-size: .8rem; color: var(--muted); }
.popup-lines { display: flex; flex-wrap: wrap; gap: .3rem; }
.popup-veh-head { align-items: center; }
.popup-veh-dest { font-weight: 700; font-size: .9rem; }
.leaflet-container { font: inherit; background: var(--surface-2); }
:root[data-theme="dark"] .leaflet-tile { filter: brightness(.8) contrast(1.05); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile { filter: brightness(.8) contrast(1.05); }
}

/* --- Ficha de línea ------------------------------------------------- */
.line-title { display: flex; align-items: center; gap: .6rem; }
.line-title .page-title { margin: 0; font-size: 1.3rem; }
.line-sub { margin: .4rem 0 0; font-size: .85rem; }

.line-senses { margin-top: 1rem; }
.line-senses .seg { font-size: .85rem; padding: .45rem .7rem; }
.line-senses .seg-extra { border-style: dashed; }
.line-morebtn {
  margin-top: .5rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.line-morebtn[hidden] { display: none; }

.line-map-wrap {
  position: relative;
  margin-top: 1rem;
  height: clamp(18rem, 55vh, 30rem);
  border: 1px solid var(--border);
  border-radius: .75rem;
  overflow: hidden;
  background: var(--surface-2);
}
.line-map { position: absolute; inset: 0; }
.line-map-wrap .map-notice { bottom: .5rem; }

.line-stops-toggle {
  display: flex; align-items: center; gap: .4rem;
  width: 100%; border: 0; background: none; padding: 0;
  font-family: inherit; cursor: pointer; text-align: left;
}
.line-stops-toggle .toggle-caret { transition: transform .15s ease; }
.line-stops-toggle[aria-expanded="false"] .toggle-caret { transform: rotate(-90deg); }
.line-stops { list-style: none; margin: .25rem 0 0; padding: 0; }
.line-stop {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem .35rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
}
.line-stops li:last-child .line-stop { border-bottom: 0; }
.line-stop-seq {
  flex: 0 0 auto;
  width: 1.6rem; height: 1.6rem;
  display: grid; place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--lc, var(--accent)) 20%, transparent);
  color: var(--text);
  font-size: .78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.line-stop-name { flex: 1 1 auto; font-size: .95rem; }
.line-stop-id { flex: 0 0 auto; font-size: .8rem; font-variant-numeric: tabular-nums; }

.tt-tabs { margin-top: .5rem; }
.tt-tabs .seg-sm { font-size: .82rem; padding: .4rem .75rem; }
.line-tt-body { margin-top: .75rem; }
.tt-summary { margin: 0 0 .5rem; }
.tt-times { display: flex; flex-wrap: wrap; gap: .35rem; }
.tt-time {
  padding: .25rem .5rem;
  border: 1px solid var(--border);
  border-radius: .4rem;
  background: var(--surface);
  color: var(--muted);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}
.tt-time.is-next {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 700;
}

/* --- Portada (Paso 5) --------------------------------------------- */
.home .page-title { margin-bottom: .75rem; }

.search-box {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .7rem;
}
.search-box:focus-within { border-color: var(--accent); }
.search-ico { color: var(--muted); font-size: .95rem; }
.search-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: .7rem 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
}
.search-input:focus { outline: none; }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-results { margin-top: .75rem; }
.sr-empty { padding: .5rem .25rem; }

.sr-list { display: grid; gap: .4rem; margin-top: .5rem; }
.sr-row {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem .7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .6rem;
  text-decoration: none;
  color: var(--text);
}
.sr-num {
  flex: 0 0 auto;
  min-width: 2.6rem;
  padding: .2rem .3rem;
  text-align: center;
  border-radius: .4rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.sr-body { flex: 1 1 auto; min-width: 0; display: grid; }
.sr-name { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-sub { font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-lines { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: .25rem; justify-content: flex-end; max-width: 8rem; }
.sr-lines .badge { min-width: 1.4rem; height: 1.4rem; font-size: .74rem; }

.home-dynamic[hidden] { display: none; }
.near-box { margin: 1.1rem 0 .25rem; display: grid; gap: .6rem; }
.near-btn { justify-content: center; width: 100%; }
.link-btn {
  justify-self: start;
  /* Área táctil más cómoda sin mover el texto (padding compensado con margen). */
  padding: .45rem .3rem;
  margin: -.45rem -.3rem;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.fav-lines { display: flex; flex-wrap: wrap; gap: .35rem; margin: .25rem 0 .6rem; }
.fav-lines a { text-decoration: none; }

/* --- Favoritos (Paso 6) ------------------------------------------- */
.fav-header { display: flex; align-items: baseline; gap: .75rem; }
.fav-header .page-title { margin: .25rem 0 1rem; flex: 1 1 auto; }
.fav-editbtn { flex: 0 0 auto; }

.fav-list { display: grid; gap: .6rem; margin-top: .5rem; }
.fav-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .7rem;
  padding: .7rem .8rem;
}
.fav-item.fav-stop { display: block; }

.fav-line {
  display: flex;
  align-items: center;
  gap: .7rem;
  text-decoration: none;
  color: var(--text);
}
.fav-line-body { flex: 1 1 auto; min-width: 0; display: grid; gap: .1rem; }
.fav-line-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav-line-count { font-size: .78rem; }
.fav-line-count.is-live { color: var(--ok); font-weight: 600; }
.fav-chev { flex: 0 0 auto; color: var(--muted); font-size: 1.4rem; line-height: 1; }

.fav-item:has(.fav-edit) { display: flex; align-items: center; gap: .6rem; }
.fav-item:has(.fav-edit) .fav-line,
.fav-item:has(.fav-edit) .fav-stop-title { flex: 1 1 auto; min-width: 0; }
.fav-edit { flex: 0 0 auto; display: flex; align-items: center; gap: .3rem; }
.fav-ord, .fav-rm {
  width: 2rem; height: 2rem;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: .5rem;
  background: var(--surface);
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
}
.fav-ord:disabled { opacity: .35; cursor: default; }
.fav-rm { color: #c62828; border-color: color-mix(in srgb, #c62828 35%, var(--border)); }

.fav-stop-head { display: flex; align-items: flex-start; gap: .7rem; }
.fav-stop-title { flex: 1 1 auto; min-width: 0; display: grid; gap: .1rem; text-decoration: none; color: var(--text); }
.fav-stop-name { font-weight: 600; }
.fav-stop-sub { font-size: .78rem; }
.fav-stop-lines { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: .25rem; justify-content: flex-end; max-width: 8rem; }
.fav-stop-lines .badge { min-width: 1.4rem; height: 1.4rem; font-size: .74rem; }
.fav-stop .arrivals-widget { margin-top: .6rem; border-top: 1px solid var(--border); padding-top: .5rem; }

.fav-empty { margin-top: 1.5rem; display: grid; gap: .6rem; }
.fav-empty-cta { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.btn-ghost { background: var(--surface); color: var(--text); }

/* --- Modal (popups de campaña) --------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(0, 0, 0, .5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-box {
  position: relative;
  width: 100%; max-width: 26rem;
  background: var(--surface); color: var(--text);
  border-radius: 1rem 1rem 0 0;
  padding: 1.5rem 1.25rem 1.25rem;
  box-shadow: var(--shadow);
}
.modal-x {
  position: absolute; top: .6rem; right: .6rem;
  border: 0; background: transparent; color: var(--muted);
  font-size: 1.1rem; line-height: 1; cursor: pointer; padding: .5rem;
}
.modal-title { margin: 0 0 .6rem; font-size: 1.2rem; padding-right: 1.5rem; }
.modal-body { margin: 0; color: var(--text); }
.modal-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.25rem; }
.modal-actions .btn { flex: 1 1 auto; justify-content: center; }

@media (min-width: 30rem) {
  .modal-backdrop { align-items: center; padding: 1rem; }
  .modal-box { border-radius: 1rem; }
}

/* --- Toast --------------------------------------------------------- */
.toast-host { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 1rem); transform: translateX(-50%); z-index: 9999; display: grid; gap: .5rem; }
.toast { background: var(--text); color: var(--bg); padding: .5rem .9rem; border-radius: .6rem; font-size: .85rem; box-shadow: var(--shadow); transition: opacity .3s, transform .3s; }
.toast.out { opacity: 0; transform: translateY(.5rem); }

@media (min-width: 48rem) {
  .app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* ===================================================================
   Fase 8 — pulido, "Más" (tarifas / recarga / servicio) y planificador
   =================================================================== */

/* Foco programático en el título al navegar: sin recuadro visible. */
.page-title:focus, .line-page :focus-visible.page-title { outline: none; }

/* Píldora "en circulación" como enlace */
.topbar a.pill { text-decoration: none; }

/* --- Banda de sin conexión + avisos -------------------------------- */
.offline-bar {
  flex: 0 0 auto;
  background: var(--warn); color: #fff;
  font-size: .8rem; font-weight: 600; text-align: center;
  padding: .35rem .75rem;
}
.alert-host { flex: 0 0 auto; display: grid; }
.alert {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .55rem .85rem;
  font-size: .85rem;
  border-bottom: 1px solid var(--border);
}
.alert-info { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.alert-warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); }
.alert-body { flex: 1 1 auto; }
.alert-x {
  flex: 0 0 auto; border: 0; background: transparent; color: var(--muted);
  font-size: .95rem; cursor: pointer; padding: .1rem .2rem;
}

/* --- Cajas de aviso dentro de una vista --------------------------- */
.notice {
  border: 1px solid var(--border);
  border-radius: .6rem;
  padding: .65rem .8rem;
  font-size: .85rem;
  margin-bottom: 1rem;
  background: var(--surface);
}
.notice-warn {
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--warn) 35%, var(--border));
}
.notice-info {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
}
.svc-alerts { margin-bottom: .5rem; }

/* --- Menú "Más" y enlaces ---------------------------------------- */
.menu { display: grid; gap: .5rem; margin-top: .5rem; }
.menu-row {
  display: flex; align-items: center; gap: .8rem;
  padding: .8rem .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .7rem;
  text-decoration: none; color: var(--text);
}
.menu-ico { flex: 0 0 auto; font-size: 1.2rem; width: 1.6rem; text-align: center; }
.menu-body { flex: 1 1 auto; min-width: 0; display: grid; }
.menu-label { font-weight: 600; }
.menu-sub { font-size: .8rem; }
.menu-chev { flex: 0 0 auto; color: var(--muted); font-size: 1.3rem; }
.links-block { margin-top: 1.25rem; }

/* --- Tarifas --------------------------------------------------- */
.fare-group { margin-top: .5rem; }
.fare-list {
  border: 1px solid var(--border); border-radius: .7rem;
  overflow: hidden; background: var(--surface);
}
.fare-item {
  display: flex; align-items: flex-start; gap: .8rem;
  padding: .65rem .85rem;
  border-bottom: 1px solid var(--border);
}
.fare-item:last-child { border-bottom: 0; }
.fare-main { flex: 1 1 auto; min-width: 0; display: grid; gap: .1rem; }
.fare-name { font-weight: 600; font-size: .92rem; }
.fare-price {
  flex: 0 0 auto; font-weight: 800; white-space: nowrap;
  color: var(--accent); font-variant-numeric: tabular-nums;
}

/* --- Dónde recargar ---------------------------------------------- */
.rc-list { display: grid; gap: .5rem; margin-top: .5rem; }
.rc-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: .7rem; padding: .7rem .85rem;
  display: grid; gap: .25rem;
}
.rc-head { display: flex; align-items: baseline; gap: .5rem; }
.rc-name { font-weight: 600; flex: 1 1 auto; }
.rc-kind {
  flex: 0 0 auto; font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.recharge-map { height: 14rem; margin-bottom: .5rem; }

/* --- Tarjeta de info / contacto -------------------------------- */
.info-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: .8rem; padding: 1rem; margin-bottom: 1rem;
}
.card-title { margin: 0 0 .35rem; font-size: 1.05rem; }
.contact-row {
  display: flex; align-items: center; gap: .7rem;
  padding: .5rem 0; border-top: 1px solid var(--border);
  text-decoration: none; color: var(--text);
}
.contact-row:first-of-type { border-top: 0; }
.contact-ico { flex: 0 0 auto; width: 1.5rem; text-align: center; }
.contact-val { display: block; font-weight: 600; }

/* --- Portada: acciones rápidas y cabecera con acción ---------- */
.home-quick { display: flex; gap: .5rem; margin: .9rem 0 .25rem; }
.home-quick .btn { flex: 1 1 0; justify-content: center; }
.section-h-row { display: flex; align-items: baseline; justify-content: space-between; }
.section-h-row .section-h { margin-bottom: .25rem; }

/* --- Invitación a dejar feedback (portada) ------------------------- */
.fb-invite {
  display: flex; align-items: center; gap: .4rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: .8rem; padding: .65rem .7rem; margin: .9rem 0 .25rem;
}
.fb-invite-body {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; gap: .6rem;
  text-decoration: none; color: var(--text);
}
.fb-invite-ico { flex: 0 0 auto; font-size: 1.4rem; }
.fb-invite-title { display: block; font-weight: 600; }
.fb-invite-x {
  flex: 0 0 auto; border: 0; background: transparent; color: var(--muted);
  font-size: .95rem; cursor: pointer; padding: .4rem;
}

/* --- Página de comentarios (feedback) ------------------------------ */
.rating { display: flex; gap: .4rem; margin-top: .4rem; }
.fb-field { margin-bottom: 1.1rem; }
.fb-label { display: block; font-weight: 600; margin-bottom: .4rem; }
.fb-comment {
  width: 100%; padding: .6rem .75rem;
  border: 1px solid var(--border); border-radius: .6rem;
  background: var(--surface); color: var(--text); font: inherit; resize: vertical;
}
.fb-status { margin-top: .5rem; min-height: 1.2rem; }
.fb-privacy { margin-top: 1.25rem; }

/* --- Ficha de parada: acciones y enlaces ---------------------- */
.stop-actions { display: flex; gap: .4rem; flex: 0 0 auto; }
.stop-links { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: .9rem; }

/* --- Planificador "Cómo llegar" ------------------------------- */
/* min-height estable: al pasar de buscador a "elegido" no salta el campo de abajo. */
.picker { margin-top: 1rem; min-height: 4.6rem; scroll-margin-top: 4rem; }
.picker-label { display: block; margin-bottom: .3rem; }
.picker-me {
  margin-top: .4rem; width: 100%;
  border: 1px dashed var(--border); border-radius: .6rem;
  background: var(--surface); color: var(--accent);
  padding: .5rem; font: inherit; cursor: pointer;
}
.picker-list {
  margin-top: .35rem; display: grid; gap: .15rem;
  border: 1px solid var(--border); border-radius: .6rem; overflow: hidden;
}
.picker-list[hidden], .picker-chosen[hidden], .search-box[hidden] { display: none; }
.picker-opt {
  display: flex; justify-content: space-between; gap: .5rem;
  padding: .5rem .7rem; border: 0; background: var(--surface);
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.picker-opt:hover { background: var(--surface-2); }
.picker-chosen {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem .75rem; margin-top: .1rem;
  background: var(--surface-2); border-radius: .6rem;
}
.itin-results { display: grid; gap: .75rem; margin-top: 1.25rem; }
.itin-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: .8rem; padding: .85rem;
}
.itin-head {
  font-size: .72rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); margin-bottom: .5rem;
}
.itin-step {
  display: flex; align-items: center; gap: .6rem;
  padding: .3rem 0; font-size: .9rem;
}
.itin-step a { text-decoration: none; }
.itin-walk, .itin-transfer { color: var(--muted); font-size: .85rem; padding-left: .1rem; }
.itin-transfer { font-weight: 600; color: var(--text); }
.itin-dot { color: var(--muted); width: 1.4rem; text-align: center; }

/* --- Correcciones de prueba (alias, buscador, estado, favoritos) ---- */
.search-clear {
  flex: 0 0 auto;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: .35rem;
  cursor: pointer;
}
.search-clear:hover { color: var(--text); }

.alias-tag {
  display: inline-block;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  border-radius: .4rem;
  padding: 0 .35rem;
  font-size: .82em;
  font-weight: 700;
  vertical-align: baseline;
}

.arrivals-more { padding: .3rem 0; font-size: .85rem; }

.linelist-net {
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: .4rem;
  padding: 0 .35rem;
}

.fav-stop-tools { margin: .1rem 0 .35rem; }
.fav-alias-btn {
  font-size: .8rem;
  padding: .2rem .5rem;
  border: 1px dashed var(--border);
  border-radius: .5rem;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.fav-alias-btn.is-on { color: var(--accent); border-style: solid; border-color: var(--accent); }

.popup-go { color: var(--accent-text) !important; white-space: nowrap; }
.popup-go span { color: inherit; }

.status-row { display: flex; align-items: center; gap: .55rem; font-size: .95rem; }
.status-dot {
  width: .75rem; height: .75rem; border-radius: 50%;
  background: var(--muted); flex: 0 0 auto;
}
.status-row.is-ok .status-dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.status-row.is-down .status-dot { background: #d3453b; box-shadow: 0 0 0 3px color-mix(in srgb, #d3453b 25%, transparent); }
.status-row.is-ok .status-text { color: var(--ok); }
.status-row.is-down .status-text { color: #d3453b; }

/* --- Movimiento reducido ------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
