/* Mi parada — el poste de la EMT, en el móvil.
   El sistema completo (tokens, papeles tipográficos, componentes) está en DESIGN.md. */

:root {
  /* Color: azul y gris de emtmadrid.es; el rojo solo avisa */
  --emt: #2c7abf;        /* azul EMT: SOLO placas y chips de línea (información de la EMT) */
  --brand: #1f2328;      /* marca propia (grafito): cabecera, botones, enlaces, foco. No es de la EMT */
  --mist: #eef4fa;       /* superficies secundarias, esqueletos */
  --line: #d3dfeb;       /* separadores */
  --grey: #414042;       /* texto secundario */
  --ink: #000;           /* texto principal */
  --paper: #fff;
  --now: #d0262f;        /* "Llegando" y errores */
  --night: #1d2a39;      /* líneas nocturnas (búhos) */
  --warn: #7a4b00;       /* avisos de la EMT: texto e icono */
  --warn-bg: #fff3d6;    /* avisos de la EMT: fondo */

  /* Tipo: escala sobre el tamaño de texto del móvil (17 px por defecto) */
  --t-meta: .9rem;       /* 15: número de parada, distancia, dirección, "y otro en" */
  --t-body: 1rem;        /* 17: texto */
  --t-label: 1.1rem;     /* 19: destinos, nombres en listas, botones */
  --t-title: 1.2rem;     /* 20: nombres de parada, títulos de sección */
  --t-display: 1.75rem;  /* 30: cabecera */
  --t-figure: 2.35rem;   /* 40: los minutos */

  /* Espacio: múltiplos de 4 */
  --gutter: 20px;
  --radius: 12px;
  --tap: 48px;           /* área mínima de toque */

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);

  color-scheme: light;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 106.25%; -webkit-text-size-adjust: 100%; }
/* iPhone: seguir el tamaño de texto que la persona tenga en Ajustes (Dynamic Type) */
@supports (font: -apple-system-body) { html { font: -apple-system-body; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--t-body);
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
svg { flex: none; }
ul { list-style: none; margin: 0; padding: 0; }

main { max-width: 560px; margin: 0 auto; padding: 20px var(--gutter) calc(40px + env(safe-area-inset-bottom)); }

/* Papeles tipográficos: cada texto es uno de estos */
.meta { font-size: var(--t-meta); font-weight: 400; color: var(--grey); line-height: 1.3; }
.label { font-size: var(--t-label); font-weight: 700; line-height: 1.2; overflow-wrap: break-word; hyphens: auto; }
.title { font-size: var(--t-title); font-weight: 700; line-height: 1.15; overflow-wrap: break-word; hyphens: auto; }

/* ---------- Placa azul (cabecera) ---------- */

.plate {
  background: var(--paper);
  color: var(--ink);
  border-bottom: 2px solid var(--line);
  padding: max(env(safe-area-inset-top), 14px) var(--gutter) 18px;
}
.plate-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
/* Logo: el autobús del icono, en blanco, delante del nombre (solo en la portada) */
.brand-bus { width: auto; height: 1.15em; font-size: var(--t-display); }
.plate-title:has(.brand-bus:not([hidden])) { justify-content: flex-start; align-items: center; gap: 10px; }
.plate h1 {
  margin: 0;
  font-size: var(--t-display); font-weight: 800; line-height: 1.08; letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.plate-sub { margin: 6px 0 0; color: var(--grey); }
.plate-sub:empty { display: none; }

/* La plaquita blanca con el número, como en el poste (solo en la cabecera de una parada) */
.plate .stop-number {
  flex: none; margin-top: 4px; padding: 2px 9px;
  border: 2px solid var(--brand); border-radius: 6px; color: var(--brand);
  font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap;
}

.back {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: var(--tap); margin: -6px 0 10px -10px; padding: 0 14px 0 6px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink);
  font-weight: 700;
}
.back svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Botones ---------- */

.btn-primary {
  min-height: 56px; padding: 0 20px;
  border: 0; border-radius: var(--radius);
  background: var(--brand); color: #fff;
  font-size: var(--t-label); font-weight: 700;
}
.link {
  display: inline-flex; align-items: center; min-height: var(--tap);
  color: var(--brand); font-weight: 700;
  text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px;
}

/* La acción principal, fija abajo, donde llega el pulgar */
.thumb-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 70%, rgb(255 255 255 / 0));
}
.locate {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; max-width: 520px; min-height: 64px; margin: 0 auto; padding: 0 20px;
  border: 0; border-radius: 14px;
  background: var(--brand); color: #fff;
  font-size: var(--t-title); font-weight: 700;
  box-shadow: 0 6px 18px rgb(31 35 40 / .25);
}
.locate svg { width: 26px; height: 26px; fill: currentColor; }
/* Con el teclado abierto para escribir el número, el botón estorba */
body:has(#stop-number:focus) .thumb-bar { display: none; }

/* ---------- Inicio ---------- */

#home { padding-bottom: 104px; } /* que el botón fijo no tape lo último */

.by-number label { display: block; }
.hint { margin: 6px 0 0; color: var(--grey); }
.hint.invalid { color: var(--now); font-weight: 700; }

.number-row { display: flex; gap: 10px; margin-top: 16px; }
.number-plate {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  border: 3px solid var(--brand); border-radius: var(--radius); background: var(--paper);
}
.number-plate:focus-within { box-shadow: 0 0 0 3px var(--line); }
.number-plate span { color: var(--brand); font-weight: 800; font-size: var(--t-title); }
.number-plate input {
  flex: 1; min-width: 0; height: 60px; padding: 0;
  border: 0; background: transparent; outline: 0;
  font-size: var(--t-display); font-weight: 800; letter-spacing: .04em; font-variant-numeric: tabular-nums;
}
.number-row .btn-primary { min-width: 88px; }

.recent { margin-top: 40px; }
.recent h2 { margin: 0 0 4px; }
.recent li { display: flex; align-items: stretch; border-bottom: 2px solid var(--line); }
.recent .go {
  flex: 1; min-width: 0; min-height: 64px; padding: 12px 0;
  border: 0; background: none; text-align: left;
}
.recent .go .meta { display: block; margin-top: 2px; }
.recent .forget { width: 56px; border: 0; background: none; color: var(--grey); }
.recent .forget svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

/* ---------- Llegadas ---------- */

.status { min-height: 24px; }
#updated.stale { color: var(--now); }

.rows { margin-top: 10px; overflow-anchor: none; }
.rows li { border-bottom: 2px solid var(--line); }
.rows li:last-child { border-bottom: 0; }

/* Una fila: placa de línea, destino y minutos */
.row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center; column-gap: 14px;
  padding: 12px 0;
}
.line {
  display: grid; place-items: center;
  min-width: 62px; height: 46px; padding: 0 8px;
  border-radius: 7px; background: var(--emt); color: #fff;
  font-size: var(--t-title); font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.line.night { background: var(--night); }

/* Lo que se tiene que leer con el brazo estirado */
.eta { text-align: right; line-height: 1; white-space: nowrap; }
.eta b { font-size: var(--t-figure); font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.eta .unit { margin-left: 4px; font-weight: 700; color: var(--grey); }
.eta .next { display: block; margin-top: 4px; }
.eta.far b { font-size: var(--t-label); color: var(--grey); } /* +20 min: dato, sin gritar */
.eta.now b { display: inline-flex; align-items: center; gap: 7px; font-size: var(--t-title); color: var(--now); }
.eta.now b::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor;
  animation: beat 1.4s ease-in-out infinite;
}

/* Cerca de ti: cada parada, plegada, con sus líneas a la vista */
.rows > li.stop { border-bottom: 2px solid var(--line); }
.stop summary { display: block; list-style: none; cursor: pointer; padding: 16px 0; }
.stop summary::-webkit-details-marker { display: none; }
.stop-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stop .meta { display: block; margin-top: 3px; }
/* El sentido, justo bajo el nombre: es lo que distingue las paradas de un mismo cruce */
.stop .towards { display: block; margin-top: 3px; line-height: 1.3; }
/* La dirección lleva al mapa: azul y subrayada para que se vea que se toca */
.stop .address {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 44px; margin-top: 0;
  font-size: var(--t-meta); color: var(--brand); font-weight: 700;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px;
}
.stop .address svg { width: 16px; height: 16px; fill: currentColor; }
.stop .address:not([href]) { color: var(--grey); font-weight: 400; text-decoration: none; }
.chevron {
  width: 26px; height: 26px; margin-top: -1px;
  fill: none; stroke: var(--brand); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round;
  transition: transform 200ms var(--ease-out);
}
.stop details[open] .chevron { transform: rotate(180deg); }
/* Abierta, la parada va en un marco: se ve dónde empieza y dónde acaba */
.stop details[open] {
  margin: 10px -12px 14px; padding: 0 12px;
  border: 2px solid var(--line); border-radius: 14px;
}
.rows > li.stop:has(details[open]) { border-bottom-color: transparent; }
.rows > li.stop:has(+ li.stop details[open]) { border-bottom-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  min-width: 38px; padding: 3px 8px; border-radius: 6px; text-align: center;
  background: var(--emt); color: #fff; font-size: var(--t-meta); font-weight: 800; font-variant-numeric: tabular-nums;
}
.chip.night { background: var(--night); }
.stop details[open] .chips { display: none; } /* abierta, las líneas ya salen con sus minutos */
.stop-rows { border-top: 2px solid var(--line); }
.stop-rows .empty { padding: 16px 0; color: var(--grey); }
.stop-foot { padding: 4px 0 14px; }

/* ---------- Avisos de la EMT ---------- */

.notices:empty { display: none; }
.notices { display: grid; gap: 8px; margin: 12px 0 4px; }
.stop .notices { margin: 0 0 10px; }
.notice {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn);
}
.notice > svg { width: 22px; height: 22px; margin-top: 1px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.notice-title { display: block; color: var(--ink); line-height: 1.25; }
.notice-when { display: block; margin-top: 2px; font-size: var(--t-meta); }
.notice details summary { display: inline-flex; align-items: center; min-height: 40px; cursor: pointer; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.notice details summary::-webkit-details-marker { display: none; }
.notice-text { margin: 0 0 4px; color: var(--ink); font-size: var(--t-meta); line-height: 1.4; }
.notice .link { color: var(--warn); font-size: var(--t-meta); }
.notice-more { justify-self: start; padding: 0; border: 0; background: none; font-size: var(--t-meta); color: var(--warn); }

/* ---------- Estados: cargando, vacío, error ---------- */

.state { margin-top: 28px; }
.state h2 { margin: 0; }
.state p { margin: 8px 0 0; color: var(--grey); }
.state .btn-primary { margin-top: 18px; }

.loader {
  display: grid; justify-items: center; gap: 10px; padding: 56px 0 24px;
  border: 0 !important;
  animation: fade 200ms ease 180ms both; /* si la respuesta llega antes, ni se ve */
}
.loader-bus { width: 64px; height: auto; animation: bob 560ms ease-in-out infinite alternate; }
.loader.small { padding: 20px 0 16px; gap: 6px; border-bottom: 0; }
.loader.small .loader-bus { width: 36px; }
.loader.small .road { width: 72px; }
/* La carretera: discontinua y avanzando, para que el autobús parezca venir */
.road {
  width: 120px; height: 4px; border-radius: 2px;
  background: repeating-linear-gradient(90deg, var(--line) 0 14px, transparent 14px 24px);
  background-size: 24px 4px;
  animation: drive 480ms linear infinite;
}

/* ---------- Panel inferior (ubicación bloqueada) ---------- */

.sheet {
  width: 100%; max-width: 560px; margin: auto auto 0;
  padding: 24px var(--gutter) calc(20px + env(safe-area-inset-bottom));
  border: 0; border-radius: 20px 20px 0 0;
  background: var(--paper); color: var(--ink);
}
.sheet::backdrop { background: rgb(0 0 0 / .35); }
.sheet h2 { margin: 0; }
.sheet p { margin: 10px 0 0; color: var(--grey); }
.sheet-actions { display: grid; gap: 8px; margin-top: 20px; }
.sheet-secondary { min-height: 56px; border: 0; background: none; color: var(--brand); font-weight: 700; }

/* ---------- Movimiento: solo para responder o señalar un cambio ---------- */

.btn-primary, .locate, .back, .recent .go, .sheet-secondary { transition: transform 160ms var(--ease-out); }
.btn-primary:active, .locate:active, .back:active, .recent .go:active, .sheet-secondary:active { transform: scale(.97); }

/* Al abrir una vista, las filas llegan en cascada corta (no al refrescar) */
.rows.entering > li { animation: enter 280ms var(--ease-out) both; }
.rows.entering > li:nth-child(2) { animation-delay: 40ms; }
.rows.entering > li:nth-child(3) { animation-delay: 80ms; }
.rows.entering > li:nth-child(n+4) { animation-delay: 120ms; }

.sheet[open] { animation: sheet-in 280ms var(--ease-sheet); }
.sheet[open]::backdrop { animation: fade 200ms ease; }

@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes beat { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-4px); } }
@keyframes drive { from { background-position: 0 0; } to { background-position: -24px 0; } }

@media (prefers-reduced-motion: reduce) {
  .btn-primary, .locate, .back, .recent .go, .sheet-secondary, .chevron { transition: none; }
  .rows.entering > li, .sheet[open] { animation: fade 200ms ease both; }
  .eta.now b::before, .loader-bus, .road { animation: none; }
}

/* Solo para lectores de pantalla */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Al desplegar una parada, su contenido entra con un fundido corto (no al refrescar) */
.stop details.just-opened > :not(summary) { animation: fade 220ms var(--ease-out); }
