:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --border: #e2e1dc;
  --text: #1c1c1a;
  --muted: #6b6b63;
  /* Logo-Rot als Leitfarbe */
  --accent: #e20029;
  --accent-soft: #fdebee;
  /* Fläche der Verbindungssuche: abgesetzt von Hintergrund und Feldern. */
  --panel: #e6e5df;
  --accent-hover: #c20023;
  --d2: #a8860a;
  --d5: #d2620c;
  --d10: #e20029;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14140f;
    --surface: #1d1d18;
    --border: #32322b;
    --text: #f2f1ea;
    --muted: #a3a294;
    --accent: #e20029;
    --accent-soft: #2a0810;
    --panel: #2c2c26;
    --accent-hover: #ff1a45;
    --d2: #e0bc4a;
    --d5: hsl(24 100% 54% / 1);
    --d10: #e20029;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

main { max-width: 1000px; margin: 0 auto; padding: 32px 16px 64px; }

.topbar {display: flex;align-items: center;justify-content: space-between;gap: 16px;margin-bottom: 64px;}

/* Logo als Datei (public/logo.svg, 464 × 38). Höhe so, dass "ÖSTERREICH"
   gleich gross bleibt wie vorher (22 px für 35,6 von 38 Einheiten). */
.logo { display: flex; text-decoration: none; }
.logo-img { height: 23.5px; width: auto; display: block; }

.topbar-actions {
  display: flex; align-items: center; justify-content: flex-end;
  flex-wrap: wrap; gap: 8px 12px;
}
.updated { color: var(--muted); font-size: 13px; white-space: nowrap; }

.langbar { display: flex; gap: 6px; }
.langbar button {
  font: inherit; font-size: 13px; padding: 5px 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--muted);
}
.langbar button:hover { color: var(--text); }
.langbar button.active {
  color: var(--accent); border-color: var(--accent);
  background: var(--accent-soft); font-weight: 600;
}
.langbar button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.hero { margin-bottom: 28px; }
.headline { margin: 0; font-size: clamp(34px, 8vw, 64px); font-weight: 700; line-height: 1.05; }
#delayed-count { color: var(--accent); }
.sub { margin: 8px 0 0; color: var(--muted); font-size: 18px; }

.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.hidden { display: none; }

.counters {display: grid;grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));gap: 10px;margin-bottom: 54px;}
.counter { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; text-align: center; }
.counter b { display: block; font-size: 24px; }
.counter span { color: var(--muted); font-size: 13px; }

/* Filterzeile im Tabellenkopf, direkt unter den Spaltentiteln. */
.filters td { padding: 0 12px 10px; vertical-align: top; }
.filters td:first-child { display: flex; flex-direction: column; gap: 6px; }
.filters input, .filters select {
  font: inherit; font-size: 13px; width: 100%; min-width: 0; padding: 6px 8px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.filters input:focus-visible, .filters select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* Auf mittleren Breiten darf die Tabelle seitlich scrollen statt die Seite. */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

/* Feste Breiten: die Spalten bleiben stehen, egal was gefiltert wird. */
table.trains { table-layout: fixed; min-width: 900px; }
.col-wide { width: 18%; }
.col-time { width: 8%; }
.col-delay { width: 12%; }

table.trains { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.filters td { border-bottom: 1px solid var(--border); }
thead th { border-bottom: none; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
.num, td.num { text-align: right; }
.train-name { font-weight: 600; }
.train-cat { color: var(--muted); font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

.delay { font-weight: 700; white-space: nowrap; }
.delay.minor { color: var(--muted); font-weight: 600; }
.delay.d2 { color: var(--d2); }
.delay.d5 { color: var(--d5); }
.delay.d10 { color: var(--d10); }
.delay.cancelled { color: var(--d10); }

footer { margin-top: 28px; color: var(--muted); font-size: 13px; }

th .short { display: none; }

@media (max-width: 640px) {
  /* Logo und Sprachwahl nebeneinander wären auf dem Telefon breiter als der
     Bildschirm: Sprachwahl nach oben, Logo darunter. */
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-actions { order: -1; margin-left: auto; }
  .logo-img { height: 21.4px; }

  /* Alle Spalten bleiben; die Tabelle scrollt seitlich, die Verspätung
     klebt rechts fest. */
  table.trains { font-size: 14px; min-width: 760px; }
  .filters td { padding: 0 8px 8px; }
  th, td { padding: 8px 8px; }
  /* Nur lange Stationsnamen dürfen hart umbrechen, sonst zerreisst es
     Wörter wie "RegionalExpress". */
  table.trains > tbody > tr > td:nth-child(4) { overflow-wrap: anywhere; }
  th .long { display: none; }
  th .short { display: inline; }

  /* Letzte Spalte bleibt beim Querscrollen stehen. */
  table.trains > thead > tr > th:last-child,
  .filters td:last-child,
  table.trains > tbody > tr > td:last-child {
    position: sticky; right: 0; z-index: 1;
    background: var(--surface);
    box-shadow: inset 1px 0 0 var(--border);
  }
}

/* Aufklappbarer Zuglauf. Der Zugname ist der Knopf dafür. */
.train-row { cursor: pointer; }
.train-row:hover td { background: var(--accent-soft); }
.train-row.open td { border-bottom: none; }
.toggle { display: inline-block; font-weight: 600; cursor: pointer; }
/* Der Pfeil gehört nicht zum markierbaren Text. */
.toggle::before { content: "▸ "; color: var(--muted); user-select: none; }
.toggle[aria-expanded="true"]::before { content: "▾ "; }
.toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.notice-chip { color: var(--d5); font-size: 12px; font-weight: 600; margin-top: 2px; }

.detail > td { padding: 0 12px 16px; }
/* Beim Querscrollen der Haupttabelle bleibt der Zuglauf im Blick. */
.detail-inner {
  position: sticky; left: 12px;
  width: min(100%, calc(100vw - 58px));
}
.detail-hint { margin: 4px 0 10px; color: var(--muted); font-size: 13px; }
.notice {
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  padding: 8px 12px; margin: 4px 0 10px; border-radius: 0 8px 8px 0; font-size: 14px;
}
.notice p { margin: 4px 0 0; white-space: pre-line; }

.stops-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table.stops { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 14px; }
table.stops th, table.stops td { padding: 6px 10px; }
table.stops th { background: var(--bg); }
table.stops th.group { text-align: center; border-bottom: 1px solid var(--border); }
table.stops tbody tr:last-child td { border-bottom: none; }
.stop-time { white-space: nowrap; }
.stop-name { min-width: 180px; }
.struck { text-decoration: line-through; color: var(--muted); }
.delay.early { color: var(--muted); }
table.stops tr.passed td { color: var(--muted); }
table.stops tr.next td { background: var(--accent-soft); }
table.stops tr.next td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

@media (max-width: 640px) {
  /* Die Detailzeile ist die letzte Zelle ihrer Zeile – nicht festkleben. */
  table.trains > tbody > tr.detail > td:last-child { position: static; box-shadow: none; background: none; }
  .detail > td { padding: 0 8px 12px; }
  .detail-inner { left: 8px; width: calc(100vw - 50px); }
}

/* Fortschrittsbalken bis zum nächsten Abruf, direkt über der Liste. */
.refresh-bar {
  position: relative;
  height: 8px;
  /* margin-bottom: 0px; */
  background: var(--border);
  /* border-radius: 999px; */
  overflow: hidden;
  border: 1px solid var(--border);
}
.refresh-fill {
  position: absolute; inset: 0;
  background: var(--accent); border-radius: inherit;
  transform: scaleX(0); transform-origin: left center;
  transition: transform 1s linear;
}
.refresh-fill.instant { transition: none; }
/* Während des Ladens: ein Stück Balken läuft durch. */
.refresh-bar.loading .refresh-fill {
  transform: none; width: 30%; right: auto;
  animation: refresh-loading 1s ease-in-out infinite;
}
@keyframes refresh-loading {
  from { left: -30%; }
  to { left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .refresh-fill { transition: none; }
  .refresh-bar.loading .refresh-fill { animation: none; left: 0; width: 100%; opacity: 0.5; }
}

/* Sortierbare Spaltenköpfe: sehen aus wie Text, der Pfeil zeigt die Richtung. */
.sort {
  font: inherit; color: inherit; background: none; border: 0; padding: 0;
  cursor: pointer; text-align: inherit; display: inline-flex; align-items: center; gap: 4px;
}
.sort:hover, th[aria-sort] .sort { color: var(--text); }
.sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sort::after { content: "↕"; opacity: 0.35; font-size: 11px; }
th[aria-sort="ascending"] .sort::after { content: "▲"; opacity: 1; color: var(--accent); }
th[aria-sort="descending"] .sort::after { content: "▼"; opacity: 1; color: var(--accent); }

/* Nur für Screenreader sichtbar. */
.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;
}

/*
 * Verbindungssuche ganz oben: graue Fläche so breit wie der Inhalt darunter,
 * die Felder schmal in der Mitte. Links Von und Nach untereinander, rechts
 * Datum/Uhrzeit und darunter Suchen (rot). Auf dem Telefon alles untereinander.
 */
.trip-search {margin: 0 0 80px;}
.trip-form {
  display: grid;
  gap: 10px;
  padding: 40px 18px;
  grid-template-columns: minmax(0, 340px) minmax(0, 220px);
  justify-content: center;
  grid-template-areas:
    "from when"
    "to   submit";
  background: hsl(207 46% 18% / 1);
  border-radius: 16px;
}
.trip-more { display: contents; }
.trip-field { position: relative; min-width: 0; }
.trip-field.from { grid-area: from; }
.trip-field.to { grid-area: to; }
.trip-field.when { grid-area: when; }
.trip-submit { grid-area: submit; }
/* Feste Höhe: Datumsfelder zeichnet der Browser sonst etwas höher. */
.trip-form input, .trip-submit { height: 44px; }
.trip-form input {
  font: inherit; font-size: 15px; width: 100%; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.trip-form input:focus-visible, .trip-submit:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.trip-submit {
  font: inherit; font-weight: 600; padding: 10px 20px; cursor: pointer;
  border: 0; border-radius: 10px; background: var(--accent); color: #fff;
}
.trip-submit:hover { background: var(--accent-hover); }
.suggestions {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}
.suggestions li { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.suggestions li:hover, .suggestions li.active { background: var(--accent-soft); }

.trip-message { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.trip-results { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.trip {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.trip.is-cancelled { opacity: 0.75; }
.trip-summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
  padding: 10px 14px; cursor: pointer;
}
.trip-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 12px; }
.trip-times { display: flex; align-items: baseline; gap: 8px; font-weight: 700; font-size: 17px; }
.trip-arrow { color: var(--muted); font-weight: 400; }
.trip-date { font-size: 12px; font-weight: 600; color: var(--muted); }
.trip-time .planned { color: var(--muted); font-weight: 400; }
.trip-time .delay { font-size: inherit; }
.trip-time .day { font-size: 10px; color: var(--muted); margin-left: 1px; }
.trip-facts { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 13px; }
.trip-products { color: var(--text); }
.trip-flag { margin-left: auto; font-size: 13px; }

.trip-legs {
  list-style: none; margin: 0; padding: 4px 14px 12px;
  border-top: 1px solid var(--border); display: grid; gap: 8px;
}
.trip-leg { padding-top: 8px; }
.trip-leg.cancelled .trip-leg-head b { text-decoration: line-through; }
.trip-leg-line {
  display: grid; grid-template-columns: 28px minmax(110px, auto) 1fr auto;
  gap: 8px; align-items: baseline; font-size: 14px; margin-top: 2px;
}
.trip-leg-kind { color: var(--muted); font-size: 12px; }
.trip-leg-line .trip-time { font-weight: 600; }
.trip-transfer { color: var(--muted); font-size: 13px; padding-left: 36px; }
.trip-transfer.tight { color: var(--d5); }
.trip-transfer.missed { color: var(--d10); font-weight: 600; }

@media (max-width: 640px) {
  .trip-form {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "from" "to" "when" "submit";
    padding: 28px 16px;
  }
  .trip-leg-line { grid-template-columns: 24px auto 1fr; }
  .trip-leg-line > .train-cat { grid-column: 3; }
}
.trip-results.stale { opacity: 0.4; pointer-events: none; transition: opacity 0.2s; }
.trip-submit:disabled { opacity: 0.6; cursor: progress; }

/* Ladesymbol: Stationsvorschläge, Verbindungssuche, Zuglauf. */
.spinner {
  display: inline-block; width: 0.9em; height: 0.9em; vertical-align: -0.1em;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}
.suggestions li.status { cursor: default; color: var(--muted); }
.suggestions li.status:hover { background: none; }
