/* Panel cívico: papel claro, tinta oscura y los colores de las señales solo para el estado. */
:root {
  color-scheme: light;
  --bg: #F4F3EF; --surface: #FFFFFF; --ink: #16181D; --muted: #4F5560; --faint: #646A75; --line: #E1DFD8; --line-strong: #8A8F98;
  --ok: #2F9E62; --warn: #D98E04; --bad: #D9363E; --accent: #1F4FBF;
  --warn-ink: #8A5A00; --bad-ink: #B0232B;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --top: 60px;
}
/* Tema oscuro: solo si se elige (o si «Automático» y el sistema está en oscuro). Lo resuelve el script de la cabecera. */
:root[data-theme="dark"] { --bg: #111317; --surface: #1A1D23; --ink: #ECEDEF; --muted: #B3B8C1; --faint: #969CA6; --line: #2A2E36; --line-strong: #6B717C; --accent: #8FAEFF; --warn-ink: #F0B54A; --bad-ink: #FF8A8F; }
* { box-sizing: border-box; }
html, body { margin: 0; }
html { scroll-padding-top: calc(var(--top) + 12px); -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--ink); font: 400 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; accent-color: var(--accent); scrollbar-color: var(--line-strong) transparent; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
[hidden] { display: none !important; }
b, strong { font-weight: 600; }
a { color: var(--accent); text-underline-offset: .18em; }
a:hover { text-decoration-thickness: 2px; }
button, a, summary, select, input, label { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[tabindex="-1"]:focus { outline: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 3000; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-weight: 600; text-decoration: none; }
.skip:focus { top: 8px; }
.noscript { padding-block: 24px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }

.top { position: sticky; top: 0; z-index: 2000; padding-top: env(safe-area-inset-top); background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 20px; height: var(--top); }
.brand { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); text-decoration: none; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; padding: 4px 2px; }
nav a { display: inline-flex; align-items: center; min-height: 44px; color: var(--muted); text-decoration: none; font-size: 15px; padding: 0 10px; border-radius: 8px; white-space: nowrap; }
nav a:hover { color: var(--ink); background: color-mix(in srgb, var(--surface) 70%, transparent); }
nav a[aria-current="page"] { color: var(--ink); background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
nav a:focus-visible { outline-offset: -3px; }

/* La pestaña visible la decide el atributo data-view de <html> (sin parpadeo al cargar). */
.view { display: none; padding-block: 28px 64px; }
html[data-view="ahora"] #ahora, html[data-view="riesgo"] #riesgo, html[data-view="incidencias"] #incidencias, html[data-view="avisos"] #avisos,
html[data-view="puntualidad"] #puntualidad, html[data-view="puntos"] #puntos, html[data-view="metodo"] #metodo, html[data-view="estacion"] #estacion,
html[data-view="linea"] #linea, html[data-view="informe"] #informe, html:not([data-view]) #ahora { display: block; }
#ahora.view { padding: 0; }
main:focus { outline: none; }
h1 { font-size: clamp(26px, 3.4vw, 36px); font-weight: 600; line-height: 1.12; letter-spacing: -.02em; margin: 0 0 10px; text-wrap: balance; }
h2 { font-size: 15px; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); margin: 28px 0 10px; font-weight: 600; text-wrap: balance; }
.prose h2 { text-transform: none; font-size: 21px; color: var(--ink); letter-spacing: -.01em; margin-top: 36px; }
.lede { color: var(--muted); max-width: 70ch; margin: 0 0 22px; font-size: 17px; text-wrap: pretty; }
.prose p, .prose li { max-width: 72ch; }
.note { color: var(--faint); font-size: 14px; }
code { font-family: var(--mono); font-size: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; overflow-wrap: anywhere; }

/* Estado en directo */
.status { margin: 0 0 4px; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; min-height: 22px; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--faint); display: inline-block; }
.dot[data-state="ok"] { background: var(--ok); animation: pulse 2s ease-out infinite; }
.dot[data-state="warn"] { background: var(--warn); }
.dot[data-state="bad"] { background: var(--bad); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(47 158 98 / .5); } 100% { box-shadow: 0 0 0 10px rgb(47 158 98 / 0); } }
.notice, .state { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 12px 0; background: var(--surface); font-size: 15px; }
.notice p, .state p { margin: 0 0 8px; }
.notice p:last-child, .state p:last-child { margin: 0; }
.notice.bad, .state.error { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); background: color-mix(in srgb, var(--bad) 7%, var(--surface)); }
.notice.warn { border-color: color-mix(in srgb, var(--warn) 60%, var(--line)); background: color-mix(in srgb, var(--warn) 8%, var(--surface)); }
.state.loading { color: var(--muted); border-style: dashed; background: transparent; }

/* Ahora: mapa + panel */
.live { display: grid; grid-template-columns: minmax(0, 1fr) 390px; height: calc(100dvh - var(--top)); }
.map-wrap { position: relative; min-height: 420px; }
#map { position: absolute; inset: 0; background: #D9DCE0; }
.map-msg { position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 1000; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.panel { overflow-y: auto; overscroll-behavior: contain; padding: 22px 22px 40px; border-left: 1px solid var(--line); background: var(--bg); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi b { display: block; font: 500 26px/1.1 var(--mono); }
.kpi span { display: block; margin-top: 4px; font-size: 13px; line-height: 1.35; color: var(--muted); }
.kpis.head { grid-template-columns: repeat(3, 1fr); margin-top: 12px; }
.kpis.head .kpi b { font-size: 30px; }
.kpi.alert b { color: var(--bad-ink); }
.tools { display: grid; gap: 10px; margin-top: 18px; }
.field-label { font-size: 14px; color: var(--muted); margin-bottom: -4px; }
.tools input[type=search] { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
.tools input[type=search]::placeholder { color: var(--faint); opacity: 1; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 999px; padding: 0 14px; min-height: 44px; cursor: pointer; }
.seg.sub { margin-top: 8px; }
.seg.sub button { min-height: 40px; font-size: 13px; padding: 0 12px; }
.seg button small { font-family: var(--mono); opacity: .7; margin-left: 4px; }
.seg button:hover { border-color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.count { margin: 0; }
.count:empty { display: none; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; }
.legend { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend i.ring { background: transparent; box-shadow: 0 0 0 2px var(--ink); }
.explain { margin-top: 10px; font-size: 14px; color: var(--muted); }
.explain summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--ink); font-weight: 600; font-size: 14px; }
.explain summary:hover { color: var(--accent); }
.explain p { margin: 0 0 10px; }
.explain.all { margin-top: 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

/* Ficha de un tren */
.ficha { margin: 14px 0 4px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px; padding: 14px 16px; }
.ficha-head { display: flex; align-items: flex-start; gap: 10px; }
.ficha h2 { margin: 0; flex: 1; font-size: 20px; text-transform: none; letter-spacing: -.01em; color: var(--ink); overflow-wrap: anywhere; }
.ficha-sub { margin: 2px 0 10px; color: var(--muted); font-size: 14px; }
.facts { display: grid; gap: 6px; margin: 0; }
.facts div { display: grid; grid-template-columns: 9.5em minmax(0, 1fr); gap: 10px; font-size: 14px; padding-block: 4px; border-top: 1px solid var(--line); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.ficha .note { margin: 10px 0 0; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.icon-btn { flex: none; display: inline-grid; place-items: center; width: 44px; height: 44px; margin: -8px -8px 0 0; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.btn { display: inline-flex; align-items: center; gap: 8px; font: inherit; font-size: 14px; font-weight: 600; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 0 14px; min-height: 44px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink); background: color-mix(in srgb, var(--ink) 5%, var(--surface)); }
.btn:active { transform: translateY(1px); }
.btn.done { border-color: var(--ok); }
a.btn { text-decoration: none; }
#informe .filters .btn { margin-left: 0; }
#informe .filters #i-copy { margin-left: auto; }

/* Listas */
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.list > li { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; font-size: 14px; overflow-wrap: anywhere; }
.list > li:not(:has(> .row)) { padding: 10px 12px; }
.list li b { display: block; font-size: 15px; }
.list li small { color: var(--muted); font-size: 13px; }
.list li.empty { color: var(--muted); background: transparent; border-style: dashed; }
.list .row { all: unset; box-sizing: border-box; display: block; width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px; cursor: pointer; }
.list .row:hover { background: color-mix(in srgb, var(--ink) 4%, var(--surface)); }
.list .row:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.list .row[aria-current="true"] { box-shadow: inset 0 0 0 2px var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 14px; }
.chip b { font-family: var(--mono); font-weight: 500; }

/* Filtros y tablas */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filters .btn { margin-left: auto; }
.table-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 0 0 12px; }
.table-tools .note { margin: 0; flex: 1 1 280px; }
input[type=date] { font: inherit; color: var(--ink); background-color: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 10px; min-height: 44px; }
select { font: inherit; color: var(--ink); background-color: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 10px; min-height: 44px; cursor: pointer; }
.table-wrap { overflow: auto; max-height: min(72vh, 760px); border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overscroll-behavior: contain; }
.table-wrap:focus-visible { outline-offset: 2px; }
.explain.all .table-wrap { max-height: 60vh; margin-bottom: 14px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-weight: 600; font-size: 13px; padding: 0; box-shadow: 0 1px 0 var(--line-strong); white-space: nowrap; }
th.num, td.num { text-align: right; }
th button { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 4px; width: 100%; min-height: 44px; padding: 0 12px; cursor: pointer; }
th.num button { justify-content: flex-end; }
th button:hover { color: var(--ink); }
th button:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
th svg { flex: none; opacity: 0; transition: opacity .15s ease-out, transform .15s ease-out; }
th button:hover svg { opacity: .5; }
th[aria-sort] { color: var(--ink); }
th[aria-sort] svg { opacity: 1; }
th[aria-sort="ascending"] svg { transform: rotate(180deg); }
tr:last-child td { border-bottom: 0; }
td.num { font-family: var(--mono); font-weight: 500; white-space: nowrap; }
td small { color: var(--muted); }
td .row-link { all: unset; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: .18em; display: inline-flex; align-items: center; min-height: 32px; }
td .row-link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
td.empty { color: var(--muted); padding: 16px 12px; }
tbody tr:hover td { background: color-mix(in srgb, var(--ink) 3%, transparent); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s1 { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn-ink); }
.s2, .s3 { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad-ink); }
.cards { display: grid; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; content-visibility: auto; contain-intrinsic-size: auto 120px; }
.card p { margin: 6px 0 0; overflow-wrap: anywhere; }
.card small { color: var(--muted); }
.c-infraestructura, .c-seguridad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad-ink); }
.c-terceros, .c-meteorologia, .c-material { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn-ink); }
.c-obras, .c-huelga, .c-operativa, .c-accesibilidad, .c-otros { background: color-mix(in srgb, var(--faint) 16%, transparent); color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.minimap { height: 300px; border-radius: 14px; border: 1px solid var(--line); margin-bottom: 12px; background: #D9DCE0; }
.minimap.tall { height: 420px; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 150px; margin-bottom: 18px; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; }
.chart .col { flex: 1 0 12px; max-width: 56px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.chart .bar { width: 100%; background: var(--warn); border-radius: 3px 3px 0 0; min-height: 2px; }
.chart .col span { font-size: 11px; color: var(--faint); margin-top: 4px; }
.chart .col em { font: 500 11px/1.2 var(--mono); font-style: normal; color: var(--muted); margin-bottom: 3px; white-space: nowrap; }
.chart { justify-content: center; }
.chart .note { margin: auto; }
.rules { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.rules .card b { display: block; margin-bottom: 4px; }
.glossary { display: grid; gap: 0; margin: 0; max-width: 72ch; }
.glossary div { padding: 12px 0; border-top: 1px solid var(--line); }
.glossary dt { font-weight: 600; }
.glossary dd { margin: 2px 0 0; color: var(--muted); }
.api li { margin-bottom: 6px; }

/* Buscador de estaciones, enlaces a estaciones y líneas */
.search { display: grid; gap: 10px; max-width: 560px; margin-bottom: 20px; }
.search input[type=search], .tools input[type=search] { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
.search input[type=search]::placeholder { color: var(--faint); opacity: 1; }
.search .note { margin: 0; }
.search .note:empty, .search .list:empty { display: none; }
.suggest .note { margin: 0 0 6px; }
.list a.row b { color: var(--accent); }
.list .row .go { float: right; color: var(--muted); }
.line-link { font-weight: 600; }
.badge { display: inline-grid; place-items: center; min-width: 1.9em; padding: 0 .35em; margin-right: .3em; border-radius: 8px; font: 600 .8em/1.6 var(--mono); vertical-align: .12em; }
.kpis.wide { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin: 0 0 14px; }
.chips + .list { margin-top: 12px; }
pre.plain { white-space: pre-wrap; overflow-wrap: anywhere; font: 13.5px/1.55 var(--mono); color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 0 0 14px; max-height: 60vh; overflow: auto; }
#t-ciaf th { padding: 10px 12px; }
.legend i.seg-alto, .legend i.seg-medio, .legend i.seg-bajo { width: 22px; height: 0; border-radius: 0; border-top: 5px solid var(--bad); vertical-align: 3px; }
.legend i.seg-medio { border-top-color: var(--warn); }
.legend i.seg-bajo { border-top: 4px dashed var(--faint); }

/* Tramos a vigilar */
.risk > li { border-left: 4px solid var(--line); padding: 12px 14px; }
.risk > li.alto { border-left-color: var(--bad); }
.risk > li.medio { border-left-color: var(--warn); }
.risk > li.sel { box-shadow: 0 0 0 2px var(--accent); }
.risk h2 { margin: 2px 0 0; font-size: 17px; text-transform: none; letter-spacing: -.01em; color: var(--ink); }
.risk h2:focus { outline: none; }
.risk p { margin: 0; }
.risk ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.risk .actions { margin-top: 10px; }
.lvl { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.lvl.alto { color: var(--bad-ink); } .lvl.medio { color: var(--warn-ink); } .lvl.bajo { color: var(--muted); }

/* Leaflet con los colores de la web */
.leaflet-container { font-family: var(--sans); background: #D9DCE0; }
.leaflet-container:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.leaflet-popup-content { font: 14px/1.45 var(--sans); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip, .leaflet-tooltip { background: var(--surface); color: var(--ink); }
.leaflet-tooltip { border-color: var(--line); font: 13px/1.3 var(--sans); }
.leaflet-touch .leaflet-bar a { width: 44px; height: 44px; line-height: 44px; }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-bottom-color: var(--line); }
.leaflet-bar a:hover { background: var(--bg); }
.leaflet-control-attribution { font-size: 11px; }
.leaflet-control-attribution a { color: var(--accent); }
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.82) contrast(.92) saturate(.5); }
:root[data-theme="dark"] .leaflet-container, :root[data-theme="dark"] #map, :root[data-theme="dark"] .minimap { background: #23262c; }
:root[data-theme="dark"] .leaflet-control-attribution { background: rgb(26 29 35 / .85) !important; color: var(--muted); }
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
.theme { margin-left: 8px; flex: none; }
.theme select { min-height: 40px; padding: 4px 6px; font-size: 13px; width: auto; max-width: 104px; }

@media (max-width: 860px) {
  th button { padding: 0 10px; }
  td { padding: 10px; }
  .live { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 55vh; height: 55dvh; min-height: 300px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; padding: 18px 16px 40px; }
  .two { grid-template-columns: 1fr; }
  .bar { gap: 8px; }
  .wrap { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .brand span { display: none; }
  .minimap.tall { height: 320px; }
  .filters .btn { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
