:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #deded9;
  --accent: #1f5fa8;
  --warn: #b3261e;
  --note: #8a5a00;
  --ok: #2e7d32;
  --row-hover: #eef3fa;
  --live-bg: #e3f3e6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --panel: #1f1f1d;
    --text: #ebebe6;
    --muted: #9a9a93;
    --line: #34342f;
    --accent: #7fb0ec;
    --warn: #ff8a80;
    --note: #e0b450;
    --ok: #81c784;
    --row-hover: #26303d;
    --live-bg: #16301c;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header {
  flex: none;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px 0;
}
h1 { font-size: 16px; margin: 0 8px 0 0; }
h2 { font-size: 14px; margin: 16px 0 6px; }
.controls { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
select, input, button {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px;
}
button { cursor: pointer; }
nav { display: flex; gap: 2px; margin-top: 6px; overflow-x: auto; }
nav button {
  border: none; border-bottom: 2px solid transparent; border-radius: 0;
  background: none; padding: 6px 10px; white-space: nowrap;
}
nav button.active { border-bottom-color: var(--accent); color: var(--accent); }
main { flex: 1; min-height: 0; overflow: auto; padding: 8px 16px 16px; }
.tab { display: none; }
.tab.active { display: block; }
/* Single-table tabs: the table scrolls, header row stays visible. */
.tab.fill.active { display: flex; flex-direction: column; height: 100%; }
.tab.fill .scroll { flex: 1; min-height: 0; overflow: auto; }
.hint { color: var(--muted); max-width: 90ch; margin: 4px 0 8px; font-size: 12px; }
.scroll { overflow-x: auto; }
table {
  border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); min-width: 100%;
}
th, td {
  padding: 3px 6px; border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: top; white-space: nowrap;
}
td.wrap { white-space: normal; min-width: 22ch; max-width: 48ch; }
th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel); font-weight: 600;
  box-shadow: inset 0 -1px var(--line);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--row-hover); }
.tag {
  display: inline-block; padding: 0 6px; margin: 1px 2px 1px 0;
  border-radius: 4px; font-size: 12px; border: 1px solid currentColor;
}
.tag.Ausfall, .tag.Verschwunden { color: var(--warn); }
.tag.Ersatz { color: var(--accent); }
tr.flagged td { background: color-mix(in srgb, var(--note) 14%, transparent); }
.tag.Extrazug, .tag.Zielwechsel, .tag.Gleisabweichung,
.tag.Gleiswechsel, .tag.Verspätung, .tag.Baureihentausch { color: var(--note); }
.bad { color: var(--warn); }
.good { color: var(--ok); }
.muted { color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.inline { display: inline-flex; gap: 6px; align-items: center; }
.flagline { display: block; }
.flagline + .flagline { margin-top: 2px; }
#delay-min { width: 5em; }
input[type=search] { width: min(100%, 360px); margin-bottom: 6px; }
.t { font-variant-numeric: tabular-nums; margin-right: 4px; }
.differs { color: var(--note); }
dialog {
  width: min(1100px, 96vw); max-height: 92vh; padding: 16px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog .close {
  float: right; font-size: 20px; line-height: 1; border: none; background: none;
}
dl.meta {
  display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px;
}
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; }
details { margin-top: 12px; }
pre {
  background: var(--bg); padding: 8px; border-radius: 6px;
  overflow: auto; max-height: 50vh; font-size: 12px;
}
.strip { display: inline-flex; gap: 1px; vertical-align: middle; }
.strip i {
  width: 5px; height: 12px; background: var(--line); border-radius: 1px;
}
.strip i.on { background: var(--accent); }
.strip i.sel { outline: 1px solid var(--text); outline-offset: 1px; }
#fleet-absent { width: 4em; }
tr.sel td { background: var(--row-hover); }
.scroll.limit { max-height: 75vh; overflow: auto; }
.totals {
  display: grid; grid-template-columns: auto auto auto auto minmax(80px, 1fr);
  gap: 2px 12px; align-items: center; max-width: 900px; margin-bottom: 6px;
}
.trow { display: contents; }
.totals .n { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar {
  height: 6px; background: var(--line); border-radius: 3px;
  overflow: hidden; display: flex;
}
.bar i { display: block; height: 100%; }
.series { display: grid; gap: 3px; margin: 8px 0 10px; }
.serie { display: grid; grid-template-columns: 8.5em 1fr; gap: 6px; }
.serie .name { font-weight: 600; padding-top: 2px; }
.serie .name small { margin-left: 4px; font-weight: 400; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 3px; }
.chip {
  font: 12px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums; width: 3.2em; text-align: center;
  padding: 4px 0; border-radius: 4px; border: 1px solid transparent;
  background: none; color: inherit;
}
button.chip { cursor: pointer; }
.chip.live { background: var(--live-bg); color: var(--ok); border-color: var(--ok); font-weight: 600; }
.chip.day { background: var(--accent); color: var(--panel); }
.chip.seen { background: var(--row-hover); }
.chip.missing { color: var(--muted); border: 1px dashed var(--muted); }
.chip.retired { color: var(--muted); text-decoration: line-through; }
.chip.key { width: auto; padding: 4px 8px; font-family: inherit; }
#fleet-legend.filtering .chip.key[aria-pressed="false"] { opacity: .4; }
.chip.key[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 1px; }
.chip { display: inline-block; height: 22px; line-height: 12px; }
@media (max-width: 600px) {
  .serie { grid-template-columns: 1fr; gap: 2px; }
  .totals { display: block; font-size: 12px; }
  .trow { display: flex; flex-wrap: wrap; gap: 0 10px; margin-bottom: 4px; }
  .trow .bar { flex-basis: 100%; }
}
#map {
  flex: 1; min-height: 320px; border: 1px solid var(--line); border-radius: 6px;
}
.maplibregl-popup-content { color: #1d1d1b; font: 13px/1.4 system-ui, sans-serif; }
.maplibregl-popup-content button { margin: 2px; }
/* Train markers: line icon, destination right, wagon numbers below.
   Anchor top-left = the wrapper origin is the coordinate. */
.tm { cursor: pointer; }
.tm-icon { position: absolute; transform: translate(-50%, -50%); }
.tm-fallback { font: bold 12px/1 Arial, sans-serif; color: #000; }
.tm-waiting .tm-icon { opacity: 0.55; }
.tm-label, .tm-units {
  position: absolute; white-space: nowrap; pointer-events: none;
  color: #000; text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff, 0 0 4px #fff;
}
.tm-label { top: 0; transform: translateY(-50%); font-size: 10px; line-height: 1.1; }
.tm-units {
  display: none; left: 0; transform: translateX(-50%);
  font-size: 9px; line-height: 1.1; font-variant-numeric: tabular-nums;
}
.tm-units-on .tm-units { display: block; }
.tm-delay { color: #d32f2f; }
/* Separate badge, so it does not read as part of the destination */
.tm-tag {
  font-style: normal; font-size: 8px; font-weight: 600; text-transform: uppercase;
  border: 1px solid currentColor; border-radius: 3px; padding: 0 2px;
  margin-left: 2px; background: #fff; text-shadow: none;
}
.tm-extra { color: #8a5a00; }
.tm-cancelled { color: #b3261e; }
.tm-collided .tm-tag { display: none; }
/* DT5 livery as in HVVMap: blood-orange ends, steel grey middle */
.tm-dt5 .tm-dest {
  background: linear-gradient(90deg, #ffab91, #e0e0e0 20%, #e0e0e0 80%, #ffab91);
  padding: 0 3px; border-radius: 2px; text-shadow: none;
}
/* A hidden label keeps its delay, as in HVVMap. */
.tm-collided .tm-dest, .tm-collided .tm-units { display: none; }
.tm-hit .tm-icon { outline: 3px solid #1d1d1b; outline-offset: 2px; border-radius: 3px; }
details.info { position: relative; }
details.info summary {
  list-style: none; cursor: pointer; font-size: 16px; line-height: 1;
  color: var(--accent); padding: 2px 4px;
}
details.info summary::-webkit-details-marker { display: none; }
details.info > div {
  position: absolute; z-index: 5; right: 0; top: 24px; width: min(340px, 85vw);
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 10px; box-shadow: 0 4px 12px rgb(0 0 0 / .15);
  font-size: 12px; color: var(--text);
}
details.info p { margin: 6px 0; }
.maplibregl-popup-content { max-height: 50vh; overflow: auto; }
.station-hover .maplibregl-popup-content { white-space: nowrap; }
