:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --bg: #ffffff;
  --fg: #1d2330;
  --muted: #5d6677;
  --line: #d9dde5;
  --accent: #0b5cad;
  --soft: #f6f8fb;
  --hover: #e9eef6;
  --hl: #fff6d6;
  --shadow: 0 2px 10px rgba(0, 0, 0, .18);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1b2230;
  --fg: #e6ebf5;
  --muted: #9aa6bd;
  --line: #333d52;
  --accent: #7fb2ff;
  --soft: #252e40;
  --hover: #2f3a50;
  --hl: #4a4220;
  --shadow: 0 2px 10px rgba(0, 0, 0, .55);
  color-scheme: dark;
}
:root[data-theme="dark"] .base-tiles { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
:root[data-theme="dark"] #map { background: #1d232c; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--fg); }
#map { position: fixed; inset: 0; background: #e8ecef; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#top {
  position: fixed; top: 10px; left: 10px; right: 10px; z-index: 1000; display: flex; gap: 10px; align-items: flex-start; pointer-events: none;
}
#top > * { pointer-events: auto; }
#top h1 { margin: 0; padding: 7px 12px; font-size: 15px; letter-spacing: .08em; background: var(--bg); border-radius: 8px; box-shadow: var(--shadow); }
#searchbox { position: relative; flex: 0 1 340px; min-width: 0; }
#search { width: 100%; padding: 8px 12px; font: inherit; border: 0; border-radius: 8px; box-shadow: var(--shadow); background: var(--bg); color: var(--fg); }
#results { list-style: none; margin: 4px 0 0; padding: 4px 0; background: var(--bg); border-radius: 8px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto; }
#results li { padding: 8px 12px; cursor: pointer; }
#results li:hover, #results li[aria-selected="true"] { background: var(--hover); }

#bar {
  position: fixed; left: 10px; bottom: 10px; z-index: 1000; max-width: calc(100vw - 20px);
  background: var(--bg); border-radius: 10px; box-shadow: var(--shadow); padding: 8px 10px;
}
#bar .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#bar .filters { margin-top: 6px; gap: 10px; }
#bar .sep { width: 1px; height: 16px; background: var(--line); }
#bar button, #bar select, #bar input[type="datetime-local"] { font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); color: var(--fg); }
#bar button { cursor: pointer; }
#bar button:hover { background: var(--hover); }
#clock { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 5.5em; }
#count { color: var(--muted); }
#note { margin: 6px 0 0; font-size: 11.5px; color: var(--muted); max-width: 520px; }
label { white-space: nowrap; }

#panel {
  position: fixed; z-index: 1001; top: 60px; right: 10px; bottom: auto; width: 340px; max-height: calc(100vh - 220px);
  overflow: auto; background: var(--bg); border-radius: 10px; box-shadow: var(--shadow); padding: 12px 14px;
}
#panel-close { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
#panel h2 { margin: 0 24px 2px 0; font-size: 16px; }
#panel .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
#panel table { width: 100%; border-collapse: collapse; }
#panel td { padding: 4px 4px; border-top: 1px solid var(--line); vertical-align: baseline; }
#panel td.t { white-space: nowrap; font-variant-numeric: tabular-nums; width: 3.4em; }
#panel td.ist { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 12.5px; font-weight: 600; padding-right: 6px; }
#panel td.ist.late { color: #d32f2f; }
#panel td.ist.early { color: #1976d2; }
#panel td.ist.ok { color: #2e7d32; }
:root[data-theme="dark"] #panel td.ist.late { color: #ff7b72; }
:root[data-theme="dark"] #panel td.ist.early { color: #8fd3ff; }
:root[data-theme="dark"] #panel td.ist.ok { color: #7ddc84; }
#panel tr.passed td.ist { opacity: 1; }
#panel td.ist.est { font-weight: 400; opacity: .75; }
#panel td.r { text-align: right; white-space: nowrap; color: var(--muted); font-size: 12.5px; }
#panel tr.passed { color: var(--muted); opacity: .6; }
#panel tr.current { background: var(--hl); font-weight: 600; }
#panel a.stop { color: var(--accent); cursor: pointer; text-decoration: none; }
#panel a.stop:hover { text-decoration: underline; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { border: 1px solid var(--line); background: var(--soft); color: var(--fg); border-radius: 999px; padding: 2px 10px; cursor: pointer; font: inherit; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.pill { display: inline-block; min-width: 2.2em; padding: 1px 7px; border-radius: 5px; text-align: center; font-weight: 700; font-size: 12.5px; }
.empty { color: var(--muted); padding: 10px 0; }

@media (max-width: 700px) {
  #top h1 { display: none; }
  #searchbox { flex: 1 1 auto; }
  #panel { top: auto; left: 10px; right: 10px; bottom: 150px; width: auto; max-height: 45vh; }
  #note { font-size: 10.5px; }
}

/* Werkzeuge */
#tools { display: flex; gap: 6px; pointer-events: auto; }
#tools button { font: inherit; padding: 7px 10px; border: 0; border-radius: 8px; background: var(--bg); color: var(--fg); box-shadow: var(--shadow); cursor: pointer; white-space: nowrap; }
#tools button span { margin-left: 5px; }
#tools button[hidden] { display: none; }
#tools button[aria-pressed="true"] { background: var(--accent); color: var(--bg); }
#search { background: var(--bg); color: var(--fg); }
#results li { color: var(--fg); }
#top h1 { color: var(--fg); }
#panel { color: var(--fg); }
#panel .block { border-top: 1px solid var(--line); padding: 8px 0 2px; }
#panel .block:first-of-type { border-top: 0; }
#panel .bh { font-weight: 600; margin-bottom: 2px; }
#panel .bh .sub { font-weight: 400; }
.star { border: 0; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: #e0a800; padding: 0 2px; }
.linegrid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.linebtn { border: 2px solid transparent; background: none; padding: 2px; border-radius: 8px; cursor: pointer; }
.linebtn[aria-pressed="false"] { opacity: .3; border-color: var(--line); }
#collapse { margin-left: auto; }
#bar.collapsed #options { display: none; }

@media (max-width: 700px) {
  #top { flex-wrap: wrap; }
  #searchbox { flex: 1 1 100%; order: 1; }
  #tools { order: 0; width: 100%; justify-content: space-between; }
  #tools button { flex: 1; padding: 8px 6px; }
  #tools button span { display: none; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh; border-radius: 14px 14px 0 0; padding-bottom: 18px; }
  body.panel-open #bar { display: none; }
  body.panel-open .leaflet-bottom { display: none; }
}

/* Statische Variante: kein Kartenhintergrund, keine Overlays */
body.static .ovl { display: none; }
#map { background: #eef1f4; }
:root[data-theme="dark"] #map { background: #1d232c; }

/* Linien, Route, Teilen */
.pillbtn { cursor: pointer; }
.pillbtn:hover { filter: brightness(1.1); }
.urlbox { width: 100%; font: inherit; font-size: 12px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); color: var(--fg); }
.sf { position: relative; margin-bottom: 8px; }
.sf input, .timebox { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); color: var(--fg); }
.timebox { width: auto; padding: 4px 8px; }
.sfl { position: absolute; z-index: 5; left: 0; right: 0; list-style: none; margin: 2px 0 0; padding: 4px 0; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 220px; overflow: auto; }
.sfl li { padding: 7px 10px; cursor: pointer; }
.sfl li:hover { background: var(--hover); }
.rowbtns { margin: 4px 0; color: var(--muted); }
.chip.go { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; }
.jcard { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 8px 0; cursor: pointer; }
.jcard[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.jh { font-weight: 700; margin-bottom: 4px; }
.leg { margin: 6px 0; padding-left: 4px; }
.leg.walk { color: var(--muted); }

/* Zeitleiste, Legende, Tafel */
#tl { flex: 1 1 100%; width: 100%; accent-color: var(--accent); }
#legend { position: fixed; z-index: 1000; top: 56px; left: 10px; max-width: calc(100vw - 20px); background: var(--bg); color: var(--fg); border-radius: 8px; box-shadow: var(--shadow); padding: 6px 10px; font-size: 12.5px; }
#legend .dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin: 0 3px 0 6px; vertical-align: -1px; border: 1px solid #fff; }
#legend .chip { margin-left: 8px; padding: 0 8px; }
#board { position: fixed; inset: 0; z-index: 3000; background: var(--bg); color: var(--fg); overflow: auto; padding: 16px 20px; }
body.board-open #bar, body.board-open #top, body.board-open #panel, body.board-open #legend { display: none; }
.bhead { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; border-bottom: 2px solid var(--line); padding-bottom: 10px; }
.bname { font-size: 28px; font-weight: 700; flex: 1 1 auto; }
.bclock { font-size: 28px; font-variant-numeric: tabular-nums; font-weight: 700; }
.bbtns { display: flex; gap: 8px; }
.brows { margin-top: 6px; }
.brow { display: grid; grid-template-columns: 4.2em auto 1fr auto 5.5em; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 22px; }
.brow .pill { font-size: 22px; min-width: 2.6em; padding: 3px 10px; }
.brow .bt { font-variant-numeric: tabular-nums; font-weight: 600; }
.brow .bp { color: var(--muted); font-size: 16px; }
.brow .bm { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.bnote { margin-top: 14px; }
@media (max-width: 700px) {
  .bname, .bclock { font-size: 22px; }
  .brow { grid-template-columns: 3.6em auto 1fr 4.2em; font-size: 18px; gap: 10px; }
  .brow .bp { display: none; }
  #legend { top: 112px; }
}

#notice { margin: 0 0 6px; padding: 5px 8px; border-radius: 6px; background: #fff3cd; color: #5b4300; font-size: 12.5px; max-width: 560px; }
:root[data-theme="dark"] #notice { background: #4a3d12; color: #ffe9a8; }

/* Adressen, Diagramm */
.sfl li.addr { color: var(--accent); }
.sfl li.note { color: var(--muted); cursor: default; }
.chart { margin: 8px 0; max-height: 240px; overflow: auto; }
.crow { display: grid; grid-template-columns: 3.2em 1fr 4em; gap: 6px; align-items: center; width: 100%; border: 0; background: none; color: var(--fg); font: inherit; font-size: 12px; padding: 1px 0; cursor: pointer; text-align: left; }
.crow:hover { background: var(--hover); }
.cw { display: block; height: 10px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.cb { display: block; height: 100%; border-radius: 3px; }
.cm { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* Optionen */
#options { margin-top: 6px; display: grid; gap: 8px 22px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); max-width: 820px; }
#options .group { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; align-content: flex-start; }
#options .gt { width: 100%; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#options .wide { grid-column: 1 / -1; margin: 0; }
#bar .chip { border: 1px solid var(--line); background: var(--soft); color: var(--fg); border-radius: 999px; padding: 2px 10px; }
@media (max-width: 700px) {
  #options { max-height: 42vh; overflow: auto; }
}

/* Mehrfach-Tafel, QR */
.bcols.multi { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 8px 28px; }
.bcols.multi .brow { font-size: 18px; grid-template-columns: 3.4em auto 1fr 4.6em; gap: 10px; }
.bcols.multi .brow .bp { display: none; }
.bcols.multi .brow .pill { font-size: 18px; }
.bsub { margin-top: 12px; font-size: 20px; font-weight: 700; color: var(--accent); }
.badd { margin: 10px 0; max-width: 420px; }
.bqr { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 12px 0; }
.qrbox { width: 260px; height: 260px; background: #fff; padding: 8px; border-radius: 8px; }
.urltext { word-break: break-all; max-width: 520px; text-align: center; }
@media (max-width: 700px) { .bcols.multi { grid-template-columns: 1fr; } }

/* Echtzeit */
.live { font-size: 12px; font-weight: 700; color: #2e7d32; white-space: nowrap; }
.live.stale { color: #b26a00; }
#options .group.wide #when { flex: 1 1 180px; min-width: 0; }
.dly { display: inline-block; border-radius: 4px; padding: 0 4px; font-size: 11px; font-weight: 700; line-height: 1.5; }
.canc { text-decoration: line-through; color: #d32f2f; }
tr:has(.canc) td, .brow:has(.canc) { color: var(--muted); }
.sub.warn { color: #d32f2f; }
.atext { white-space: pre-line; font-size: 13px; margin: 6px 0; }
#panel details summary { cursor: pointer; font-weight: 600; }
#panel tr.th td { font-weight: 700; color: var(--muted); font-size: 12px; }

/* Systemleisten (Statusleiste, Navigationsleiste, Notch) */
#top { top: calc(10px + var(--sat)); left: calc(10px + var(--sal)); right: calc(10px + var(--sar)); }
#bar { bottom: calc(10px + var(--sab)); left: calc(10px + var(--sal)); max-width: calc(100vw - 20px - var(--sal) - var(--sar)); }
.leaflet-top { top: var(--sat); }
.leaflet-bottom { bottom: var(--sab); }
/* Schmale Bildschirme: die Leiste unten reicht über die ganze Breite, Kartenhinweise darüber setzen */
@media (max-width: 700px) { .leaflet-bottom { bottom: calc(var(--sab) + var(--bar-h, 0px) + 14px); } }
.leaflet-left { left: var(--sal); }
.leaflet-right { right: var(--sar); }
body::before, body::after { content: ""; position: fixed; left: 0; right: 0; z-index: 1003; pointer-events: none; background: var(--bg); opacity: .92; }
body::before { top: 0; height: var(--sat); }
body::after { bottom: 0; height: var(--sab); }
@media (min-width: 701px) {
  #panel { top: calc(60px + var(--sat)); right: calc(10px + var(--sar)); max-height: calc(100vh - 220px - var(--sat) - var(--sab)); }
}
@media (max-width: 700px) {
  #panel { padding-bottom: calc(18px + var(--sab)); max-height: calc(55vh + var(--sab)); }
  /* Tastatur offen: Fenster direkt über die Tastatur setzen, damit Eingabefelder sichtbar bleiben */
  body.kb-open #panel { bottom: var(--kb, 0px); padding-bottom: 14px; max-height: calc(100vh - var(--kb, 0px) - var(--sat) - 130px); }
}

/* Standort-Knopf */
#btn-locate.on { color: #1a73e8; }
#btn-locate.follow { background: #1a73e8; color: #fff; }
#btn-locate.wait { opacity: .6; }
#toast { position: fixed; left: 50%; top: calc(70px + var(--sat)); transform: translateX(-50%); z-index: 1100; max-width: 90vw; padding: 8px 14px; border-radius: 8px; background: var(--fg); color: var(--bg); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }
.leaflet-control-attribution .owner { font-weight: 600; color: #012f57; }
:root[data-theme="dark"] .leaflet-control-attribution .owner { color: #f2c14e; }
:root[data-theme="dark"] .leaflet-control-attribution { background: rgba(16, 22, 29, .85); color: #c9d3dd; }
:root[data-theme="dark"] .leaflet-control-attribution a { color: #7cc0ff; }
a.chip { text-decoration: none; display: inline-block; }
#update { position: fixed; left: 50%; transform: translateX(-50%); top: calc(118px + var(--sat)); z-index: 1100; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; max-width: 92vw; padding: 8px 12px; border-radius: 10px; background: #012f57; color: #fff; box-shadow: var(--shadow); }
#update .chip { background: #f2c14e; color: #012f57; border-color: #f2c14e; font-weight: 600; }
.deptime { white-space: nowrap; }
.deptime .planned { text-decoration: line-through; opacity: .6; }
.deptime .real { font-variant-numeric: tabular-nums; }
.dly { font-variant-numeric: tabular-nums; }

/* Erinnerungen, Ziel, Anschluss, Pünktlichkeit */
.bell, .goal { border: 0; background: none; cursor: pointer; font-size: 15px; padding: 0 2px; line-height: 1; opacity: .45; vertical-align: middle; }
.bell.on, .goal:hover, .bell:hover { opacity: 1; }
tr.goalrow { background: var(--hl); font-weight: 600; }
tr.goalrow .goal { opacity: 1; }
.target { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; padding: 8px 10px; border-radius: 8px; background: #012f57; color: #fff; font-weight: 600; }
.target .bell { opacity: .7; }
.target .bell.on { opacity: 1; }
.xfer { margin: 4px 0; padding: 3px 8px; border-radius: 6px; font-size: 12.5px; font-weight: 600; }
.xfer.ok { background: #e3f2e5; color: #1b5e20; }
.xfer.tight { background: #fff3cd; color: #7a4f00; }
.xfer.bad { background: #fde2e2; color: #a01818; }
:root[data-theme="dark"] .xfer.ok { background: #1d3a24; color: #a6e3b0; }
:root[data-theme="dark"] .xfer.tight { background: #3d3214; color: #f2d58a; }
:root[data-theme="dark"] .xfer.bad { background: #44201f; color: #f5a3a3; }
.punct .prow { margin: 3px 0; font-size: 13px; }
.xfer.fc { font-size: 13.5px; margin: 6px 0 4px; }
.units { font-size: .8em; font-weight: 700; opacity: .75; white-space: nowrap; }
