:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #0b5cad;
  --board: #0d2a5c;
  --board-ink: #ffffff;
  --late: #d92d20;
  --ok: #12805c;
  --warn: #b54708;
  --flix: #73d700;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button, input, select { font: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
input, select { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
.muted { color: var(--muted); font-size: 13px; }

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--board); color: #fff;
}
.topbar h1 { font-size: 18px; margin: 0; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: transparent; color: #cdd6e6; border-color: transparent; }
.tabs button[aria-selected="true"] { background: #fff; color: var(--board); }

main { padding: 12px 16px; max-width: 1400px; margin: 0 auto; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; }
.toolbar label.grow { flex: 1 1 240px; }
.toolbar label input, .toolbar label select { color: var(--ink); font-size: 15px; }
.seg { display: flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.quick button { padding: 3px 9px; font-size: 13px; }
.station-results { list-style: none; padding: 0; margin: 0 0 10px; background: #fff; border: 1px solid var(--line); border-radius: 6px; max-height: 260px; overflow: auto; }
.station-results li button { width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; }
.msg { padding: 10px 12px; border-radius: 6px; margin: 8px 0; background: #fff4e5; border: 1px solid #f5c48a; color: #7a3e00; }
.msg.err { background: #fdecea; border-color: #f3b0a9; color: #8a1c12; }
.board-head { font-weight: 600; margin: 4px 0 8px; }

/* Bahnhofsanzeige */
.board { background: var(--board); color: var(--board-ink); border-radius: 8px; overflow: hidden; }
.row {
  display: grid; grid-template-columns: 64px 88px 1fr 72px 60px; gap: 8px; align-items: start;
  padding: 9px 12px; border-bottom: 1px solid rgba(255,255,255,.12);
}
.row:last-child { border-bottom: 0; }
.row .time { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.row .time .act { display: block; font-size: 13px; font-weight: 600; color: #ffd166; }
.row .train { font-weight: 700; }
.row .train small { display: block; font-weight: 400; color: #b9c4d8; font-size: 12px; }
.row .dest { font-size: 16px; font-weight: 600; }
.row .via { font-size: 12px; color: #b9c4d8; margin-top: 2px; }
.row .plat { text-align: center; font-weight: 700; }
.row .plat small { display: block; font-weight: 400; font-size: 11px; color: #b9c4d8; }
.row .plat.changed { background: #ffd166; color: #000; border-radius: 4px; }
.row .plat.changed small { color: #333; }
.row .delay { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.delay.d0 { color: #7ee2a8; }
.delay.d1 { color: #ffd166; }
.delay.d2 { color: #ff8a80; }
.row.cancelled .dest, .row.cancelled .time { text-decoration: line-through; opacity: .7; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 3px; margin-left: 6px; vertical-align: middle; }
.badge.cx { background: var(--late); color: #fff; }
.badge.add { background: var(--ok); color: #fff; }
.board .empty { padding: 16px; color: #b9c4d8; }

/* Flix */
.summary { flex: 1 1 auto; font-weight: 600; }
.flix-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr); gap: 12px; }
.map { height: 68vh; min-height: 420px; border-radius: 8px; border: 1px solid var(--line); }
.flix-side { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; max-height: 68vh; min-height: 420px; overflow: auto; }
.flix-side h2 { font-size: 14px; margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.flix-side h2:first-child { margin-top: 0; }
.vlist { list-style: none; margin: 0; padding: 0; }
.vlist li { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-bottom: 6px; cursor: pointer; }
.vlist li:hover { border-color: var(--accent); }
.vlist li.on-a72 { border-left: 5px solid var(--flix); }
.vlist .l1 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.vlist .line { font-weight: 800; background: var(--flix); color: #fff; padding: 1px 6px; border-radius: 4px; }
.vlist .route { font-weight: 600; }
.vlist .l2 { font-size: 13px; color: var(--muted); margin-top: 3px; }
.vlist .empty { cursor: default; color: var(--muted); border-style: dashed; }
.vlist .rm { float: right; padding: 0 6px; font-size: 12px; }
.st { display: inline-block; font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 3px; color: #fff; letter-spacing: .02em; }
.st-LIVE { background: var(--ok); }
.st-ALT { background: #8a6d3b; }
.st-KEIN_GPS { background: #6b7280; }
.st-GTFS_KANDIDAT { background: #4b5563; }
.st-FEHLER { background: var(--late); }
.st-A72 { background: var(--flix); color: #1b3a00; }
.watch-form { display: flex; gap: 6px; margin-bottom: 8px; }
.watch-form input { flex: 1; font-family: ui-monospace, monospace; font-size: 13px; }
.detail { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-top: 12px; }
.detail h3 { margin: 0 0 8px; }
.detail dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0 0 10px; font-size: 14px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.detail code { font-size: 12px; word-break: break-all; }
.detail table { border-collapse: collapse; font-size: 13px; width: 100%; }
.detail td, .detail th { border-bottom: 1px solid var(--line); padding: 3px 6px; text-align: left; }
.detail .close { float: right; }
.legend { font-size: 12px; color: var(--muted); margin-top: 10px; }
.foot { text-align: center; font-size: 12px; color: var(--muted); padding: 16px; }
.bus-icon { background: none; border: 0; }

@media (max-width: 900px) {
  .flix-layout { grid-template-columns: 1fr; }
  .map { height: 45vh; min-height: 280px; }
  .flix-side { max-height: none; min-height: 0; }
}

/* ---------- Smartphone ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; -webkit-tap-highlight-color: transparent; }
  /* iOS zoomt bei Eingabefeldern < 16px automatisch hinein */
  input, select, button { font-size: 16px; }
  .topbar { position: sticky; top: 0; z-index: 1100; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); flex-wrap: nowrap; }
  .topbar h1 { font-size: 15px; white-space: nowrap; }
  .tabs { margin-left: auto; }
  .tabs button { padding: 6px 10px; font-size: 14px; }
  main { padding: 10px 12px; }
  .toolbar { gap: 8px; }
  .toolbar label.grow { flex: 1 1 100%; order: -1; }
  .toolbar label { font-size: 11px; }
  #station-form label.grow { flex: 1 1 60%; }
  .quick { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .quick::-webkit-scrollbar { display: none; }
  .quick button { flex: 0 0 auto; padding: 6px 12px; font-size: 14px; }
  .board-head { font-size: 14px; }
  .board { border-radius: 6px; margin: 0 -4px; }

  /* Zugzeile: Zeit + Verspätung links, Zug/Ziel/Laufweg Mitte, Gleis rechts */
  .row {
    grid-template-columns: 54px minmax(0, 1fr) auto;
    grid-template-areas: "time train plat" "time main plat" "delay main plat";
    gap: 2px 10px; padding: 10px;
  }
  .row .time { grid-area: time; font-size: 16px; }
  .row .train { grid-area: train; font-size: 13px; display: flex; gap: 6px; align-items: baseline; }
  .row .train small { display: inline; }
  .row > div:nth-child(3) { grid-area: main; min-width: 0; }
  .row .plat { grid-area: plat; min-width: 40px; align-self: start; padding: 2px 4px; }
  .row .delay { grid-area: delay; text-align: left; font-size: 14px; }
  .row .dest { font-size: 16px; line-height: 1.25; }
  .row .via { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .row[aria-expanded="true"] .via { -webkit-line-clamp: unset; }


  /* FlixBus */
  .summary { flex: 1 1 100%; font-size: 14px; }
  .map { height: 42vh; min-height: 260px; border-radius: 6px; }
  .flix-side { padding: 8px 10px; }
  .vlist li { padding: 10px; }
  .watch-form input { font-size: 14px; min-width: 0; }
  .detail { padding: 10px; scroll-margin-top: 60px; }
  .detail dl { grid-template-columns: 1fr; gap: 0; }
  .detail dt { margin-top: 6px; font-size: 12px; }
  .detail .tbl { overflow-x: auto; }
  .legend { line-height: 1.8; }
}

/* Unterwegszeiten */
.row.clickable { cursor: pointer; }
.row.clickable:hover, .row.clickable:focus-visible { background: rgba(255,255,255,.06); outline: none; }
.row[aria-expanded="true"] { background: rgba(255,255,255,.08); }
.stops { background: #0a2149; padding: 8px 12px 10px 76px; border-bottom: 1px solid rgba(255,255,255,.12); }
.stops-head { font-size: 12px; color: #b9c4d8; margin-bottom: 6px; }
.stops ul { list-style: none; margin: 0; padding: 0; }
.stops li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; padding: 5px 0; border-top: 1px dashed rgba(255,255,255,.12); }
.stops li:first-child { border-top: 0; }
.stops .sname { flex: 1 1 200px; font-weight: 600; }
.stops .sres { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 14px; font-variant-numeric: tabular-nums; }
.stops .ask { padding: 2px 10px; font-size: 13px; background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.stops .ask:hover { border-color: #fff; }
.stops .muted { color: #b9c4d8; font-size: 12px; }
.stops .err { color: #ff8a80; font-size: 13px; }
.stops .pchg { background: #ffd166; color: #000; border-radius: 3px; padding: 0 4px; }
.stops b.d0 { color: #7ee2a8; } .stops b.d1 { color: #ffd166; } .stops b.d2 { color: #ff8a80; }

/* Smartphone-Regeln für die Halte-Liste (nach den Basisregeln, damit sie greifen) */
@media (max-width: 640px) {
  .stops { padding: 8px 10px 10px; }
  .stops li { gap: 4px 8px; padding: 7px 0; }
  .stops .sname { flex: 1 1 100%; }
  .stops li:has(.ask) .sname { flex: 1 1 0; min-width: 0; }
  .stops .ask { padding: 6px 12px; font-size: 14px; flex: 0 0 auto; }
  .detail h3 { font-size: 17px; }
}

/* Schichtliste */
.subnav { margin-bottom: 10px; }
.shift-summary .sh-head { font-weight: 600; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: #e5e7eb; color: #1f2937; }
.chip.ok { background: #d1fadf; color: #05603a; }
.chip.warn { background: #fef0c7; color: #93370d; }
.chip.bad { background: #fee4e2; color: #912018; }
.chip.idle { background: #eef0f3; color: #4b5563; }
.chip.a72 { background: var(--flix); color: #1b3a00; }
.shift-list { list-style: none; margin: 0; padding: 0; }
.shift-list li { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; background: var(--panel); border: 1px solid var(--line); border-left-width: 5px; border-radius: 6px; padding: 9px 10px; margin-bottom: 6px; }
.shift-list li[role="button"] { cursor: pointer; }
.shift-list li[role="button"]:hover { border-color: var(--accent); }
.shift-list li.chk-ok { border-left-color: var(--ok); }
.shift-list li.chk-warn { border-left-color: #f79009; }
.shift-list li.chk-bad { border-left-color: var(--late); background: #fff8f7; }
.shift-list li.chk-idle { border-left-color: #c5cad3; }
.shift-list li.empty { display: block; color: var(--muted); border-style: dashed; border-left-width: 1px; }
.sh-time { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.sh-time small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.sh-main .l1 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sh-main .line { font-weight: 800; background: var(--flix); color: #fff; padding: 1px 6px; border-radius: 4px; }
.sh-main .route { font-weight: 600; margin-top: 2px; }
.sh-main .l2 { font-size: 13px; color: var(--muted); margin-top: 2px; }
.sh-check { font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 3px; }
.sh-check.ok { background: #d1fadf; color: #05603a; }
.sh-check.warn { background: #fef0c7; color: #93370d; }
.sh-check.bad { background: var(--late); color: #fff; }
.sh-check.idle { background: #eef0f3; color: #4b5563; }
@media (max-width: 640px) {
  #shift-form label { flex: 1 1 40%; }
  #shift-form input, #shift-form select { width: 100%; }
  #shift-form button { flex: 1 1 40%; }
  .shift-list li { grid-template-columns: 54px minmax(0, 1fr); gap: 8px; }
}
.eta { font-size: 13px; font-weight: 600; margin-top: 3px; padding: 2px 6px; border-radius: 4px; display: inline-block; }
.eta-next { background: #e0eaff; color: #1d3f8c; }
.eta-now { background: var(--flix); color: #1b3a00; }
.eta-past { background: #eef0f3; color: #4b5563; font-weight: 400; }
.sh-actions { margin-top: 4px; font-size: 13px; }
.sh-actions .link { color: var(--accent); font-weight: 600; }
.focus-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: #e0eaff; border: 1px solid #b6c8f5; border-radius: 6px; padding: 6px 10px; margin-bottom: 8px; font-size: 14px; }
.focus-bar button { padding: 3px 10px; font-size: 13px; }
.pulse { animation: pulse 1.6s ease-out infinite; transform-origin: 22px 22px; }
@keyframes pulse { 0% { opacity: 1; transform: scale(.6); } 100% { opacity: 0; transform: scale(1.15); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
.detail .back-shift { margin-right: 6px; }
.focus-bar .err { color: var(--late); }

/* Sprungziele nicht unter der festen Kopfzeile verstecken */
#flix-focus, #map, .detail { scroll-margin-top: 64px; }

.print-row { margin: 0 0 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.print-btn { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.st-AREA { background: #b42318; color: #fff; }

/* hidden-Attribut immer respektieren (auch bei Elementen mit display-Regel) */
[hidden] { display: none !important; }

/* Schienenersatzverkehr */
.badge.sev { background: #f79009; color: #1f1300; }
.row.sev { background: rgba(247, 144, 9, .14); }
.row.sev .dest, .row.sev .time { opacity: .85; }
.sev-banner { padding: 10px 12px; border-radius: 6px; margin: 8px 0; background: #fff4e5; border: 2px solid #f79009; color: #5c2c00; }
.sev-banner .sev-stops { font-size: 13px; }
.sev-toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; margin: 0 0 8px; }
.notices { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; margin: 0 0 8px; font-size: 14px; }
.notices summary { cursor: pointer; font-weight: 600; }
.notices ul { margin: 6px 0 2px; padding-left: 18px; }
.notices li { margin-bottom: 4px; }
.badge.sevhint { background: #fef0c7; color: #7a4100; border: 1px solid #f79009; }
.sevhint-text { color: #ffd8a8 !important; }

/* iOS: kein automatisches Hineinzoomen beim Antippen von Eingabefeldern
   (braucht ≥ 16px – die spezifischere .toolbar-Regel muss mit überschrieben werden) */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (max-width: 640px) {
  .toolbar label input, .toolbar label select, #shift-form input, #shift-form select, .watch-form input { font-size: 16px; }
}

/* Vorschläge Bahnhofssuche */
.combo { position: relative; }
.combo .station-results { position: absolute; top: 100%; left: 0; right: 0; z-index: 1200; margin: 2px 0 0; max-height: min(55vh, 420px); box-shadow: 0 8px 24px rgba(0,0,0,.18); color: var(--ink); font-size: 15px; }
.station-results li button { padding: 9px 10px; background: #fff; }
.station-results li[aria-selected="true"] button, .station-results li button:hover { background: #e8f0fb; }
.station-results mark { background: none; color: inherit; font-weight: 700; }

.advanced { margin-top: 14px; font-size: 14px; }
.advanced summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.detail .tech { margin-top: 10px; font-size: 12px; color: var(--muted); }
.detail .tech summary { cursor: pointer; }
