/* bahn-explorer — one stylesheet, light + dark via color-scheme tokens */

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f0f1f4;
  --text: #1b1d21;
  --muted: #6b7280;
  --line: #d9dce2;
  --accent: #ec0016;
  --accent-soft: #fde8ea;
  --ok: #1a7f37;
  --warn: #b45309;
  --info: #1d4ed8;
  --class1: #f5c518;
  --class2: #4b8bd6;
  --classB: #8fb35c;
  --dining: #d9534f;
  --loco: #444a55;
  --shadow: 0 2px 10px rgba(0, 0, 0, .08);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1d2026;
    --panel-2: #262a32;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --line: #333844;
    --accent: #ff3b4a;
    --accent-soft: #3a1b1f;
    --ok: #4ade80;
    --warn: #fbbf24;
    --info: #60a5fa;
    --shadow: 0 2px 12px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: clip; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--info); }
button { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
[hidden] { display: none !important; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center;
  padding: .6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.brand-mark { background: var(--accent); color: #fff; border-radius: 6px; padding: .1rem .4rem; font-size: .85em; letter-spacing: .02em; }
.search { position: relative; flex: 1 1 320px; display: flex; gap: .4rem; min-width: 260px; }
.search input {
  flex: 1; padding: .55rem .8rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); color: var(--text); font: inherit; min-width: 0;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.suggest {
  position: absolute; top: 100%; left: 0; right: 0; margin: .3rem 0 0; padding: .3rem; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  max-height: 60vh; overflow: auto; z-index: 30;
}
.suggest li { padding: .45rem .6rem; border-radius: 6px; cursor: pointer; display: flex; gap: .6rem; align-items: baseline; }
.suggest li:hover, .suggest li.active { background: var(--panel-2); }
.suggest .sugg-type { font-size: .75em; color: var(--muted); min-width: 2.6em; }
.suggest .sugg-meta { margin-left: auto; color: var(--muted); font-size: .8em; }
.tabs { display: flex; gap: .2rem; margin-left: auto; }
.tabs a { text-decoration: none; color: var(--muted); padding: .4rem .7rem; border-radius: 8px; }
.tabs a.active, .tabs a:hover { color: var(--text); background: var(--panel-2); }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px;
  padding: .5rem .8rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: .25rem .55rem; font-size: .85em; }
.btn.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- layout ---------- */
main { flex: 1; width: 100%; max-width: 1240px; margin: 0 auto; padding: 1rem; }
.view > * + * { margin-top: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 .6rem; font-size: 1.15rem; }
.panel h3 { margin: 1rem 0 .4rem; font-size: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.grow { flex: 1; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  border: 1px solid var(--line); border-radius: 999px; padding: .15rem .6rem; font-size: .85em;
  background: var(--panel-2); cursor: pointer; user-select: none;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.badge { display: inline-block; border-radius: 6px; padding: .05rem .45rem; font-size: .8em; font-weight: 600; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.ICE, .badge.EC_IC, .badge.IR { background: var(--accent); color: #fff; border-color: var(--accent); }
.badge.REGIONAL { background: #4d4d4d; color: #fff; border-color: #4d4d4d; }
.badge.SBAHN { background: #1e8c3a; color: #fff; border-color: #1e8c3a; }
.badge.BUS { background: #a1006b; color: #fff; border-color: #a1006b; }
.badge.TRAM { background: #c8102e; color: #fff; border-color: #c8102e; }
.badge.UBAHN { background: #0b5ea8; color: #fff; border-color: #0b5ea8; }
.badge.SCHIFF { background: #0e7490; color: #fff; border-color: #0e7490; }
.badge.ANRUFPFLICHTIG { background: #7c3aed; color: #fff; border-color: #7c3aed; }
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.delay { font-weight: 600; }
.delay.late { color: var(--accent); }
.delay.ontime { color: var(--ok); }
.canceled { text-decoration: line-through; color: var(--muted); }
.msg { border-left: 3px solid var(--warn); padding: .3rem .6rem; margin: .3rem 0; background: var(--panel-2); border-radius: 0 6px 6px 0; }
.msg.HOCH { border-color: var(--accent); }
.msg.NIEDRIG { border-color: var(--muted); }
.notice { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 8px; padding: .6rem .8rem; }
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -.15em; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 2rem 0; }
.hero h1 { font-size: 1.9rem; margin: 0 0 .6rem; }
.hero p { max-width: 720px; margin: 0 auto 1.2rem; }
.hero-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .7rem; max-width: 900px; margin: 0 auto 1rem; }
.card.link {
  display: flex; flex-direction: column; gap: .2rem; text-align: left; text-decoration: none; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; cursor: pointer; box-shadow: var(--shadow);
}
.card.link:hover { border-color: var(--accent); }
.card.link span { color: var(--muted); font-size: .9em; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: .95em; }
table.grid th, table.grid td { text-align: left; padding: .45rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid th { color: var(--muted); font-weight: 600; font-size: .85em; white-space: nowrap; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover { background: var(--panel-2); }
table.grid td.time { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.grid .sub { color: var(--muted); font-size: .85em; }
table.grid .fahrzeug { margin-top: .15rem; min-height: 1.1em; color: var(--text); }
table.grid .fahrzeug:empty { display: none; }
table.grid .fahrzeug .badge { font-size: .95em; }
.rt { color: var(--muted); font-size: .85em; }
.rt.late { color: var(--accent); font-weight: 600; }
tr.stop-canceled td { opacity: .55; }
tr.detail-row td { background: var(--panel-2); }

/* ---------- JSON viewer ---------- */
details.json { margin-top: .6rem; }
details.json summary { cursor: pointer; color: var(--muted); }
pre.json {
  margin: .4rem 0 0; padding: .7rem; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line);
  font-family: var(--mono); font-size: .8em; line-height: 1.4; overflow: auto; max-height: 60vh; white-space: pre;
}
.j-k { color: var(--info); }
.j-s { color: var(--ok); }
.j-n { color: var(--warn); }
.j-b { color: var(--accent); }

/* ---------- route map ---------- */
.map { width: 100%; height: 360px; background: var(--panel-2); border-radius: 8px; border: 1px solid var(--line); display: block; }
.map .route { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.map .stop { fill: var(--panel); stroke: var(--text); stroke-width: 1.5; cursor: pointer; }
.map .stop.canceled { stroke: var(--muted); stroke-dasharray: 2 2; }
.map .stop:hover { fill: var(--accent); }
.map text { font-size: 11px; fill: var(--text); pointer-events: none; paint-order: stroke; stroke: var(--panel); stroke-width: 3px; }

/* ---------- coach sequence ---------- */
.platform { position: relative; margin: .8rem 0 .4rem; overflow-x: auto; padding-bottom: .4rem; }
.platform-inner { position: relative; height: 118px; min-width: 100%; }
.sector { position: absolute; top: 0; height: 100%; border-left: 1px dashed var(--line); }
.sector span { position: absolute; top: 2px; left: 4px; font-size: .75em; color: var(--muted); font-weight: 700; }
.sector.last { border-right: 1px dashed var(--line); }
.vehicle {
  position: absolute; top: 34px; height: 56px; border: 1.5px solid var(--text); border-radius: 6px;
  background: var(--panel); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .78em; line-height: 1.15; overflow: hidden; padding: 2px; box-shadow: var(--shadow);
}
.vehicle:hover, .vehicle.active { outline: 2px solid var(--accent); }
.vehicle .wnr { font-weight: 700; font-size: 1.15em; }
.vehicle.k1 { background: color-mix(in srgb, var(--class1) 35%, var(--panel)); }
.vehicle.k2 { background: color-mix(in srgb, var(--class2) 30%, var(--panel)); }
.vehicle.kB { background: linear-gradient(90deg, color-mix(in srgb, var(--class1) 35%, var(--panel)) 50%, color-mix(in srgb, var(--class2) 30%, var(--panel)) 50%); }
.vehicle.kR { background: color-mix(in srgb, var(--dining) 30%, var(--panel)); }
.vehicle.kL { background: var(--loco); color: #fff; border-color: var(--loco); }
.vehicle.closed { opacity: .45; border-style: dashed; }
.vehicle .uic { font-size: .72em; white-space: nowrap; opacity: .85; letter-spacing: -.02em; }
.uic b { font-weight: 800; color: var(--accent); }
.vehicle.kL .uic b { color: #ffd166; }
.vehicle .dir { position: absolute; top: 1px; font-size: .9em; color: var(--muted); }
.vehicle .dir.f { right: 4px; } .vehicle .dir.b { left: 4px; }
/* coach row derived from the seat plan: same boxes, no platform scale */
.pseudo-seq { display: flex; flex-wrap: wrap; gap: 4px; margin: .4rem 0 .6rem; }
.pseudo-seq .vehicle { position: static; width: 78px; height: 56px; }
.group-label { position: absolute; top: 96px; font-size: .75em; color: var(--muted); white-space: nowrap; border-top: 2px solid var(--muted); padding-top: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: .8rem; font-size: .85em; color: var(--muted); }
.legend i { display: inline-block; width: 1em; height: 1em; border-radius: 3px; border: 1px solid var(--text); vertical-align: -.15em; margin-right: .3em; }
.veh-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .6rem; }
.veh-card { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; background: var(--panel-2); font-size: .9em; }
.veh-card h4 { margin: 0 0 .3rem; font-size: 1em; }
.amen { display: flex; flex-wrap: wrap; gap: .25rem; }
.amen span { border: 1px solid var(--line); border-radius: 5px; padding: .05rem .4rem; font-size: .82em; background: var(--panel); }
.amen span.AVAILABLE { border-color: var(--ok); }
.amen span.NOT_AVAILABLE { text-decoration: line-through; color: var(--muted); }

/* ---------- occupancy ---------- */
.occ { display: inline-flex; gap: 2px; vertical-align: middle; }
.occ i { width: 6px; height: 12px; border-radius: 2px; background: var(--line); display: inline-block; }
.occ.s1 i:nth-child(-n+1), .occ.s2 i:nth-child(-n+2), .occ.s3 i:nth-child(-n+3), .occ.s4 i:nth-child(-n+4) { background: var(--ok); }
.occ.s3 i, .occ.s4 i { background: var(--warn); }
.occ.s4 i { background: var(--accent); }
.occ.s0 i { background: var(--line); }

/* ---------- connections ---------- */
.conn { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .9rem; background: var(--panel); }
.conn + .conn { margin-top: .6rem; }
.conn-head { display: flex; flex-wrap: wrap; gap: .6rem 1.2rem; align-items: baseline; }
.leg { display: grid; grid-template-columns: 5.5em 1fr; gap: .2rem .8rem; padding: .45rem 0; border-top: 1px dashed var(--line); font-size: .93em; }
.leg .t { font-variant-numeric: tabular-nums; white-space: nowrap; }
.leg.walk { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .6rem; }
.form-grid label { display: flex; flex-direction: column; gap: .2rem; font-size: .85em; color: var(--muted); }
.form-grid input, .form-grid select, .console input, .console select, .console textarea {
  padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); color: var(--text); font: inherit;
}
.form-grid input:focus, .console input:focus { outline: 2px solid var(--accent); }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(520px, 100%); z-index: 40;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -4px 0 20px rgba(0,0,0,.2);
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 1rem; overflow: auto; }

/* ---------- console & docs ---------- */
.console { display: grid; gap: .6rem; }
.console .params { display: grid; grid-template-columns: 1fr 2fr auto; gap: .4rem; align-items: center; }
.console .url { font-family: var(--mono); font-size: .85em; word-break: break-all; padding: .5rem; background: var(--panel-2); border-radius: 6px; }
.doc h2 { margin-top: 1.4rem; }
.doc h3 { margin-top: 1.2rem; }
.doc table { font-size: .9em; }
.doc code { background: var(--panel-2); padding: .05em .3em; border-radius: 4px; }
.doc pre { background: var(--panel-2); padding: .6rem; border-radius: 6px; overflow: auto; font-size: .85em; }

/* ---------- seat plans (gsd_v3 + wagentypen) ---------- */
/* one layout unit (the app's "em") is --u pixels; every size below is a
   multiple of it so that nothing depends on inherited font sizes */
.coach-scroll { overflow-x: auto; padding-bottom: .3rem; }
.coach {
  --u: 5.5px;
  position: relative; margin: .3rem 0 .4rem; border: 2px solid var(--text); border-radius: calc(var(--u) * 2.5);
  background: var(--panel); overflow: hidden; flex: none;
}
.coach .seat, .coach .einbau, .coach .symbol { position: absolute; box-sizing: border-box; }
.seat {
  --u: 5.5px;
  width: calc(var(--u) * 3.6); height: calc(var(--u) * 3.6); border: 1px solid var(--text); border-radius: calc(var(--u) * .5);
  padding: 0; margin: 0; font: 700 calc(var(--u) * 1.5) / 1 system-ui, sans-serif; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text); position: relative;
}
.coach .seat { --u: inherit; }
.seat .seat-dir { position: absolute; font-size: calc(var(--u) * 1.1); line-height: 1; opacity: .6; }
.seat.dir-OBEN .seat-dir { top: 1px; left: 50%; transform: translateX(-50%); }
.seat.dir-UNTEN .seat-dir { bottom: 1px; left: 50%; transform: translateX(-50%); }
.seat.dir-LINKS .seat-dir { left: 2px; top: 50%; transform: translateY(-50%); }
.seat.dir-RECHTS .seat-dir { right: 2px; top: 50%; transform: translateY(-50%); }
.seat.free { background: #c8f0d0; border-color: #1a7f37; }
.seat.taken { background: var(--panel-2); color: var(--muted); border-color: var(--line); }
.seat.proposed { background: #ffe08a; border-color: #b45309; }
.seat.unknown { background: var(--panel); border-style: dashed; }
.seat:hover { outline: 2px solid var(--accent); z-index: 2; }
.seat-swatch { display: inline-block; width: 1em; height: 1em; border-radius: 3px; border: 1px solid var(--text); vertical-align: -.15em; margin-right: .3em; }
.seat-swatch.free { background: #c8f0d0; } .seat-swatch.taken { background: var(--panel-2); } .seat-swatch.proposed { background: #ffe08a; }
.einbau {
  background: color-mix(in srgb, var(--muted) 35%, var(--panel)); border-radius: calc(var(--u) * .4);
  font-size: calc(var(--u) * 1.3); line-height: 1; color: var(--muted); padding: calc(var(--u) * .2); white-space: nowrap;
  width: calc(var(--u) * 3.5); height: calc(var(--u) * 2.5);
}
.einbau.TISCH_GROSS { height: calc(var(--u) * 5.5); }
.einbau.WAND_I_KLEIN, .einbau.WAND_I_GROSS, .einbau.WAND_L, .einbau.WAND_T { width: calc(var(--u) * .6); height: calc(var(--u) * 4); background: var(--text); border-radius: 0; padding: 0; }
.einbau.WAND_I_GROSS { height: calc(var(--u) * 8); }
.einbau.WAND_I_KLEIN.dir-LINKS, .einbau.WAND_I_KLEIN.dir-RECHTS, .einbau.WAND_I_GROSS.dir-LINKS, .einbau.WAND_I_GROSS.dir-RECHTS { width: calc(var(--u) * 4); height: calc(var(--u) * .6); }
.einbau.UEBERGANG_OBEN_NACH_UNTEN, .einbau.UEBERGANG_UNTEN_NACH_OBEN, .einbau.TREPPE { width: calc(var(--u) * 6); background: color-mix(in srgb, var(--info) 25%, var(--panel)); }
.symbol { font-size: calc(var(--u) * 2); line-height: 1; opacity: .85; pointer-events: none; }
.seat-grid { display: flex; flex-wrap: wrap; gap: .25rem; margin: .3rem 0 .6rem; }
.seat-grid .seat { position: static; }
@media (prefers-color-scheme: dark) {
  .seat.free { background: #1f4d2a; color: #e6e8ec; } .seat.proposed { background: #6b4a00; color: #fff; }
  .seat-swatch.free { background: #1f4d2a; } .seat-swatch.proposed { background: #6b4a00; }
}

/* ---------- day map ---------- */
.kmap-wrap { position: relative; margin-top: .4rem; }
.kmap { display: block; width: 100%; border: 1px solid var(--line); border-radius: 8px; cursor: crosshair; touch-action: none; }
.ktip { position: absolute; z-index: 5; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; font-size: .85em; box-shadow: var(--shadow); max-width: 320px; }
.kattr { position: absolute; right: 6px; bottom: 6px; font-size: .7em; color: #cfd3da; background: rgba(9,10,13,.7); padding: .15rem .45rem; border-radius: 4px; pointer-events: auto; }
.kattr a { color: #9ecbff; }
.kmap { background: #090a0d; }
.kbar { display: inline-block; width: 70px; height: 8px; border-radius: 4px; background: var(--line); vertical-align: middle; overflow: hidden; }
.kbar i { display: block; height: 100%; background: var(--ok); }
#kBr .chip .seat-swatch { margin-right: .3em; }

.footer { padding: .8rem 1rem; color: var(--muted); font-size: .85em; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; border-top: 1px solid var(--line); }

@media (max-width: 720px) {
  .tabs { margin-left: 0; width: 100%; justify-content: space-between; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: .3rem; }
  .map { height: 260px; }
}

/* ---------- account: footer, invitation dialog ---------- */
.footer-account { margin-left: auto; }
.footer-account a { color: inherit; }
.modal {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  padding: 1rem; background: rgba(0, 0, 0, .45);
}
.modal-dialog { position: relative; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; }
.modal-close { position: absolute; top: .7rem; right: .7rem; }
.invite-list { display: flex; flex-direction: column; gap: .5rem; margin: .6rem 0 .9rem; }
.invite-row {
  display: flex; align-items: center; gap: .6rem; padding: .5rem .7rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
}
.invite-row .inv-state { font-weight: 600; white-space: nowrap; font-size: .85em; }
.invite-row .inv-state.open { color: var(--ok); }
.invite-row .inv-state.used { color: var(--muted); }
.invite-row .inv-state.exp { color: var(--warn); }
.invite-row .inv-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.invite-row input {
  width: 100%; padding: .3rem .5rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--text); font: inherit; font-size: .85em; font-family: var(--mono);
}

/* ---------- settings: raw JSON is opt-in (body.show-raw) ---------- */
body:not(.show-raw) .raw { display: none !important; }
.pref-row { display: flex; gap: .7rem; align-items: flex-start; cursor: pointer; margin-top: .4rem; }
.pref-row input { margin-top: .3rem; accent-color: var(--accent); }

/* ---------- connections: cheap-detour results ---------- */
.alt-box { border: 1px dashed var(--line); border-radius: var(--radius); padding: .8rem .9rem; background: var(--panel-2); }
.alt-item { margin-top: .6rem; }
.alt-item .conn { margin-top: .25rem; }
.badge.save { background: var(--ok); color: #fff; border-color: var(--ok); }
