/* TIB statistics page, on the platform design system (theme.css tokens, light and dark). */
:root { --ok: #2e8b57; --late: #d4920b; --very-late: #c0392b; --early: #2b7a99; }
:root[data-theme="dark"] { --ok: #6ccb8f; --late: #e6b04f; --very-late: #f2857b; --early: #6fb7c2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ok: #6ccb8f; --late: #e6b04f; --very-late: #f2857b; --early: #6fb7c2; } }

.db-topbar .tib-nav { margin-left: 14px; }

.stats { padding: 28px 0 48px; }
.stats-intro { margin-bottom: 18px; }
.stats-intro p { max-width: 760px; }

/* key numbers: one ruled row, not four cards */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 26px; border-top: 2px solid var(--db-text); border-bottom: 1px solid var(--db-border); }
.kpi { padding: 14px 18px 16px; border-left: 1px solid var(--db-border); }
.kpi:first-child { border-left: 0; padding-left: 0; }
.kpi-label { font-size: 14px; color: var(--db-muted); font-weight: 700; }
.kpi-value { font: 800 34px/1.1 var(--db-display); letter-spacing: -.03em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12.5px; color: var(--db-muted); }

/* Month bar and calendars */
.month-bar { display: flex; align-items: center; gap: 12px; margin: 6px 0 12px; }
.month-bar h2 { margin: 0; min-width: 180px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.cal-grid .db-card + .db-card { margin-top: 0; }
.cal-grid .db-hint { margin: 4px 0 0; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-wd { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--db-faint); padding-bottom: 2px; }
.cal-day {
  position: relative; aspect-ratio: 1 / .82; border-radius: 4px; border: 1px solid var(--db-border); background: var(--db-surface-2);
  color: var(--db-text); padding: 5px 6px; text-align: left; font: inherit; cursor: pointer; display: flex; flex-direction: column;
  justify-content: space-between; min-width: 0; transition: border-color .15s;
}
.cal-day:hover { border-color: var(--db-text); }
.cal-day[disabled] { cursor: default; opacity: .45; border-color: var(--db-border); }
.cal-day.empty { visibility: hidden; }
.cal-day .n { font-size: 12px; font-weight: 700; }
.cal-day .v { font-size: 12.5px; font-weight: 750; font-variant-numeric: tabular-nums; align-self: flex-end; }
.cal-day.today { outline: 2px solid var(--db-accent); outline-offset: 1px; }
.cal-day[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--db-accent); }
.cal-day.dark-text { color: #1b1d21; }
.cal-day.light-text { color: #ffffff; }
.scale { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--db-muted); }
.scale i { flex: 1; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #c0392b, #d4920b 50%, #2e8b57); }

/* Day details */
.day .db-card-head { align-items: center; }
.line-filter .db-select { min-height: 38px; padding: 6px 10px; min-width: 190px; max-width: 100%; }
.day-kpis { display: grid; grid-template-columns: repeat(6, 1fr); margin-bottom: 18px; border-top: 1px solid var(--db-border); border-bottom: 1px solid var(--db-border); }
.day-kpis div { padding: 10px 12px; border-left: 1px solid var(--db-border); }
.day-kpis div:first-child { border-left: 0; padding-left: 0; }
.day-kpis b { display: block; font: 800 22px/1.2 var(--db-display); font-variant-numeric: tabular-nums; }
.day-kpis span { font-size: 12px; color: var(--db-muted); }
.day h3 { margin-top: 18px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar-ok { fill: var(--ok); }
.chart .bar-late { fill: var(--late); }
.chart .axis { fill: var(--db-muted); font: 10px var(--db-font); }
.chart .grid { stroke: var(--db-border); stroke-width: 1; }
.chart-legend { display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--db-muted); margin-top: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-ok { background: var(--ok); }
.sw-late { background: var(--late); }
.two-col { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 22px; }
.table-wrap { overflow-x: auto; max-height: 520px; overflow-y: auto; border: 1px solid var(--db-border); border-radius: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--db-border); white-space: nowrap; }
.tbl th { position: sticky; top: 0; background: var(--db-surface-2); font-size: 12px; color: var(--db-muted); font-weight: 700; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .route { white-space: normal; min-width: 180px; }
.badge-line { display: inline-block; min-width: 40px; padding: 2px 6px; border-radius: 6px; text-align: center; font-weight: 750; font-size: 12px; background: var(--db-surface-3); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-weight: 700; font-size: 12.5px; }
.chip-on_time { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.chip-early { background: color-mix(in srgb, var(--early) 18%, transparent); color: var(--early); }
.chip-late { background: color-mix(in srgb, var(--late) 22%, transparent); color: color-mix(in srgb, var(--late) 70%, var(--db-text)); }
.chip-very_late { background: color-mix(in srgb, var(--very-late) 18%, transparent); color: var(--very-late); }
.chip-no_data { background: var(--db-surface-2); color: var(--db-muted); }
.kind { font-size: 12px; color: var(--db-muted); }

/* Passengers */
.bars { display: grid; gap: 6px; }
.bars .row { display: grid; grid-template-columns: 70px 1fr 48px; align-items: center; gap: 10px; font-size: 13px; }
.bars .track { height: 12px; background: var(--db-surface-2); border-radius: 6px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--db-accent); border-radius: 6px; }
.load-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
/* a grid column may be narrower than its table: the table scrolls in its own box (.table-wrap), never the page */
.cal-grid > *, .two-col > *, .load-cols > *, .kpis > * { min-width: 0; }
/* the bottom of every page: the same two lines as the bottom of the map's panel (what the site is; the data credit, About, privacy, terms) */
.bus-footer { display: block; padding: 18px clamp(12px, 3vw, 24px) 24px; }
.bus-footer p { margin: 0; color: var(--db-muted); font-size: 13px; line-height: 1.55; }
.bus-footer .bus-footer-legal { margin-top: 3px; font-size: 12.5px; }
.bus-footer a { color: inherit; text-decoration: underline; text-decoration-color: var(--db-border-strong); text-underline-offset: 2px; }
.bus-footer a:hover { color: var(--db-text); }

@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .cal-grid, .two-col, .load-cols { grid-template-columns: 1fr; }
  .day-kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 560px) {
  .db-topbar .tib-nav { margin-left: 4px; }
  .day .db-card-head { flex-wrap: wrap; }
  .line-filter, .line-filter .db-select { width: 100%; min-width: 0; }
  .kpi-value { font-size: 24px; }
  .cal { gap: 3px; }
  .cal-day { padding: 3px 4px; border-radius: 7px; }
  .cal-day .v { font-size: 10.5px; }
  .day-kpis { grid-template-columns: repeat(2, 1fr); }
  .db-topbar .db-brand span { display: none; }
}

.unofficial { font-size: 13.5px; color: var(--db-muted); border-left: 3px solid var(--db-border-strong); padding: 2px 0 2px 10px; margin: 8px 0 0; }

/* The page of one stop (/tib/stop/) */
.stop-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; }
.stop-head h1 { margin: 0; }
/* the lines of a stop and of each departure, in the line's colours (assets/line-colors.css of the network: class lc-<line>) */
.stop-lines { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 0; }
.stop-lines[hidden] { display: none; }
.stop-line[class*="lc-"] { background: var(--line-color, var(--db-text)); color: var(--line-text, var(--db-bg)); }
.stop-departures { list-style: none; margin: 0; padding: 0; }
/* the overnight brief, task 9: no layout shift when the departures come (the list, the stop's name and lines have their room first; the
   notice of stale or paused data is under the list) */
.stop-head h1:empty::before { content: '\00a0'; }
.stop-departures { min-height: 70vh; } /* the same room before and after the departures come (often a few on EMT): nothing under it moves */
#stopCode:empty::before { content: '\00a0'; } /* the stop's code: its line is there from the start */
.stop-lines { min-height: 26px; }
.stop-departures li { display: flex; gap: 10px; align-items: center; padding: 10px 0; }
.stop-departures li + li { border-top: 1px solid var(--db-border); }
.stop-line { min-width: 44px; padding: 2px 6px; border-radius: 6px; background: var(--db-surface-3); font-weight: 700; text-align: center; }
.stop-to { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.stop-delay { font-size: .85rem; color: var(--db-muted); }
.stop-delay.status-on_time { color: var(--db-success); }
.stop-delay.status-late { color: var(--db-warning); }
.stop-delay.status-very_late { color: var(--db-danger); }
.stop-delay.status-early { color: var(--db-sea); }
.stop-when { display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; }

/* «Ver dónde está» under a departure (assets/where.js): a small map on tap, the bus, the road to this stop, minutes and distance */
.where-btn { align-self: flex-start; margin-top: 4px; padding: 6px 0; min-height: 32px; border: 0; background: none; color: var(--db-accent);
  font: 700 14px/1.2 var(--db-font); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.where-btn[aria-expanded="true"] { text-decoration: none; }
.where-btn:focus-visible { outline: 2px solid var(--db-accent); outline-offset: 2px; border-radius: 4px; }
.stop-departures li.where-panel { display: block; padding: 4px 0 14px; border-top: 0; }
.where-map { height: 230px; border-radius: 10px; border: 1px solid var(--db-border); background: var(--db-surface-2); overflow: hidden; position: relative; isolation: isolate; }
.where-words { margin: 8px 0 6px; font-size: 14.5px; }
.where-big { font-size: 14px; }
.where-bus-icon { background: none; border: 0; }
.where-bus { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 22px; padding: 0 5px; box-sizing: border-box;
  border-radius: 6px; background: #1b1d21; color: #fff; font: 800 12px/1 var(--db-font); box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0, 0, 0, .35); }
.where-bus.where-estimated, .where-bus.where-scheduled { background: #fff; color: #1b1d21; box-shadow: 0 0 0 2px #1b1d21, 0 2px 6px rgba(0, 0, 0, .3); }
:root[data-theme="dark"] .where-map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
