:root {
  --fondo: #f5f5f7;
  --superficie: rgba(255, 255, 255, 0.94);
  --texto: #1d1d1f;
  --texto-2: #6e6e73;
  --borde: #d2d2d7;
  --acento: #0071e3;
  --aviso: #b25000;
  --aviso-fondo: #fff4e5;
  --congelado: #9ca3af;
  --sombra: 0 4px 24px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #000;
    --superficie: rgba(28, 28, 30, 0.94);
    --texto: #f5f5f7;
    --texto-2: #98989d;
    --borde: #38383a;
    --acento: #0a84ff;
    --aviso: #ff9f0a;
    --aviso-fondo: #2c1d05;
    --congelado: #636366;
    --sombra: 0 4px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fondo);
  color: var(--texto);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
#mapa { position: fixed; inset: 0; }

.chips {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--borde); background: var(--superficie); color: var(--texto);
  border-radius: 999px; padding: 6px 12px; font: 600 13px/1 inherit; box-shadow: var(--sombra); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--acento); border-color: var(--acento); color: #fff; }
.chip-l { --color: #6b7280; }
.chip-l[aria-pressed="true"] { background: var(--color); border-color: var(--color); }

.banner {
  position: fixed; z-index: 2; left: 16px; right: 16px;
  top: calc(env(safe-area-inset-top) + 52px);
  background: var(--aviso-fondo); color: var(--aviso); border-radius: 12px;
  padding: 8px 12px; font-weight: 600; font-size: 13px; box-shadow: var(--sombra);
}
.vacio {
  position: fixed; z-index: 2; left: 50%; top: 45%; transform: translate(-50%, -50%);
  background: var(--superficie); color: var(--texto-2); border-radius: 12px; padding: 10px 14px;
  box-shadow: var(--sombra); max-width: calc(100% - 32px); text-align: center;
}
.estado {
  position: fixed; z-index: 2; left: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px);
  display: flex; align-items: center; gap: 6px;
  background: var(--superficie); color: var(--texto-2); border-radius: 999px;
  padding: 6px 10px; font-size: 12px; box-shadow: var(--sombra);
}
/* El verde sólo con tiempo real confirmado por el vigía. */
.estado .punto { width: 8px; height: 8px; border-radius: 50%; background: #8e8e93; }
.estado[data-fuente="vivo"] .punto { background: #34c759; }
.estado[data-fuente="horario"] .punto { background: #ff9f0a; }
.estado.error .punto { background: var(--aviso); }
.acciones { position: fixed; z-index: 2; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 96px); }
.acciones button {
  border: 0; background: var(--superficie); color: var(--acento); border-radius: 999px;
  padding: 8px 12px; font: 600 13px/1 inherit; box-shadow: var(--sombra); cursor: pointer;
}
.maplibregl-ctrl-bottom-right { margin-bottom: calc(env(safe-area-inset-bottom) + 40px); }

.hoja {
  position: fixed; z-index: 3; left: 0; right: 0; bottom: 0;
  max-height: 60dvh; overflow-y: auto;
  background: var(--superficie); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 16px 16px 0 0; box-shadow: var(--sombra);
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
  transform: translateY(100%); transition: transform 0.25s ease;
}
.hoja.abierta { transform: translateY(0); }
.hoja .asa { width: 36px; height: 5px; border-radius: 3px; background: var(--borde); margin: 0 auto 8px; }
.hoja-cerrar {
  position: absolute; top: 10px; right: 12px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: var(--borde); color: var(--texto); cursor: pointer;
}
.hoja h2 { margin: 4px 40px 4px 0; font-size: 18px; }
.hoja p { margin: 4px 0; }
.secundario { color: var(--texto-2); font-size: 13px; }
.aviso { color: var(--aviso); font-weight: 600; }
.cabecera { display: flex; align-items: center; gap: 8px; }
.cabecera h2 { margin: 4px 40px 4px 0; }

.chip-linea {
  --color: #6b7280; display: inline-block; min-width: 38px; text-align: center;
  background: var(--color); color: #fff; border-radius: 6px; padding: 3px 6px; font: 700 12px/1.2 inherit;
}
.llegadas { list-style: none; margin: 8px 0 0; padding: 0; }
.llegadas li {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 10px 0; border-top: 1px solid var(--borde);
}
.llegadas .destino { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.llegadas .tiempo { font-weight: 700; font-variant-numeric: tabular-nums; }

.bus {
  --color: #6b7280; position: relative; min-width: 32px; height: 32px; padding: 0 6px;
  border-radius: 16px; border: 2px solid #fff; background: var(--color); color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); font: 700 11px/1 -apple-system, system-ui, sans-serif;
  display: grid; place-items: center; cursor: pointer;
}
.bus .num { position: relative; z-index: 1; }
.bus .flecha { position: absolute; inset: -9px; pointer-events: none; }
.bus .flecha::before {
  content: ""; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 7px solid var(--color);
}
.bus.congelado { background: var(--congelado); opacity: 0.8; }
.bus .edad {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 3px;
  background: var(--superficie); color: var(--texto-2); border-radius: 6px; padding: 1px 4px;
  font: 600 10px/1.2 -apple-system, system-ui, sans-serif; white-space: nowrap;
}

.etiqueta-fuente { display: inline-block; margin: 4px 0 8px; padding: 2px 8px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.etiqueta-fuente.horario { background: color-mix(in srgb, #ff9f0a 18%, transparent); color: #b36b00; }
.etiqueta-fuente.vivo { background: color-mix(in srgb, #34c759 18%, transparent); color: #1f7a35; }
.llegadas .destino { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; white-space: normal; }
.llegadas .origen { font-size: 12px; font-weight: 600; padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, currentColor 10%, transparent); }
.llegadas .origen-gtfs { color: #0a6fb8; }
.llegadas .origen-tabla_oficial { color: #7a4d00; }
.llegadas .nota { flex-basis: 100%; font-size: 12px; opacity: .75; }
.sin-hora { font-size: 14px; margin: 10px 0 0; opacity: .85; }
@media (prefers-color-scheme: dark) {
  .etiqueta-fuente.horario { color: #ffb340; }
  .etiqueta-fuente.vivo { color: #5fd97a; }
  .llegadas .origen-gtfs { color: #64b5f6; }
  .llegadas .origen-tabla_oficial { color: #ffb340; }
}
