/* 107 Live - dunkles Grunddesign nach Spec 22 */

:root {
    --bg: #111111;
    --panel: #1a1a1a;
    --panel-line: #2a2a2a;
    --text: #ffffff;
    --muted: #aaaaaa;
    --dim: #777777;

    --rail: #3a3a3a;
    --stop: #cfcfcf;

    --red: #e2453c;
    --green: #35b45c;
    --amber: #e8a33d;

    --focus: #ffd34d;

    --row: 46px;

    /* Der Linienplan hat drei feste Spuren nebeneinander:
       Gegenrichtung (gruen) | Schiene | Richtung Essen (rot) | Haltestellenname.
       Die Namen beginnen deshalb erst hinter der roten Spur, sonst ueberdecken
       die Fahrzeug-Badges sie. */
    --rail-x: 96px;
    --veh-w: 66px;
    --label-x: calc(var(--rail-x) + 14px + var(--veh-w) + 10px);
}

@media (max-width: 600px) {
    :root {
        --rail-x: 68px;
        --veh-w: 58px;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-text-size-adjust: 100%;
}

.wrap {
    max-width: 1180px;
    margin: 0 auto;
    padding: 16px;
}

/* --- Kopfbereich ------------------------------------------------------- */

header {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--panel-line);
}

.line-badge {
    flex: 0 0 auto;
    background: var(--red);
    color: #fff;
    font-weight: 700;
    font-size: 20px;
    letter-spacing: .5px;
    padding: 8px 12px;
    border-radius: 8px;
}

.titles { flex: 1 1 auto; min-width: 0; }
.titles h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.titles p  { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.status { flex: 0 0 auto; text-align: right; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 14px;
    font-weight: 600;
    padding: 6px 11px;
    border-radius: 999px;
    background: #202020;
    border: 1px solid var(--panel-line);
    white-space: nowrap;
}

.chip::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--dim);
}

.chip.is-live::before     { background: var(--green); }
.chip.is-schedule::before { background: var(--amber); }
.chip.is-stale::before    { background: var(--red); }
.chip.is-live     { color: var(--green); }
.chip.is-schedule { color: var(--amber); }
.chip.is-stale    { color: var(--red); }

.updated {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: var(--dim);
    font-variant-numeric: tabular-nums;
}

.notice {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #241d10;
    border: 1px solid #4a3a14;
    color: #f0cf90;
    font-size: 14px;
}

/* --- Aufteilung -------------------------------------------------------- */

/* minmax(0, 1fr) statt 1fr: eine Rasterspalte schrumpft sonst nicht unter die
   Breite ihres Inhalts und erzeugt einen waagerechten Bildlauf der ganzen Seite. */
main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin-top: 16px;
}

@media (min-width: 900px) {
    main { grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); }
}

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 12px;
    padding: 14px 16px 18px;
}

.panel h2 {
    margin: 0 0 12px;
    font-size: 13px;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}

/* --- Linienplan -------------------------------------------------------- */

.plan {
    position: relative;
    padding: 4px 0;
}

.plan::before {
    content: "";
    position: absolute;
    left: var(--rail-x);
    top: 12px;
    bottom: 12px;
    width: 4px;
    margin-left: -2px;
    background: var(--rail);
    border-radius: 2px;
}

.stop {
    position: relative;
    height: var(--row);
    display: flex;
    align-items: center;
}

.stop .dot {
    position: absolute;
    left: var(--rail-x);
    width: 11px;
    height: 11px;
    margin-left: -5.5px;
    border-radius: 50%;
    background: var(--stop);
    border: 2px solid var(--bg);
}

/* min-width:0 ist hier entscheidend: ohne das kann ein Flex-Element nicht unter
   seine Inhaltsbreite schrumpfen, der Plan wird breiter als das Smartphone, und die
   ganze Seite bekommt einen waagerechten Bildlauf - inklusive der Abfahrtsspalte,
   die dann rechts aus dem Bild rutscht. */
.stop .label {
    margin-left: var(--label-x);
    flex: 1 1 auto;
    min-width: 0;
    font-size: 15px;
    color: var(--stop);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 600px) {
    .stop .label { font-size: 14px; }
}

.stop.is-focus .dot {
    width: 17px;
    height: 17px;
    margin-left: -8.5px;
    background: var(--focus);
    box-shadow: 0 0 0 4px rgba(255, 211, 77, .18);
}

.stop.is-focus .label {
    color: var(--focus);
    font-weight: 700;
    font-size: 16px;
}

/* --- Fahrzeuge --------------------------------------------------------- */

.vehicles {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.vehicle {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 5px;
    height: 24px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    pointer-events: auto;
    transform: translateY(-50%);
    transition: top 1.2s cubic-bezier(.4, 0, .2, 1);
    white-space: nowrap;
    overflow: hidden;
}

/* Grosse Spruenge werden gesetzt, nicht animiert - sonst gleitet ein Fahrzeug
   bei einer geaenderten Prognose sichtbar rueckwaerts. */
.vehicle.no-anim { transition: none; }

.vehicle.dir-H {
    left: calc(var(--rail-x) + 14px);
    width: var(--veh-w);
    background: var(--red);
}

.vehicle.dir-R {
    left: 0;
    width: calc(var(--rail-x) - 14px);
    justify-content: flex-end;
    background: var(--green);
}

/* Fahrzeuge ohne Echtzeit sind als solche erkennbar. */
.vehicle.is-scheduled {
    background: #2a2a2a;
    color: var(--muted);
    border: 1px dashed currentColor;
}
.vehicle.dir-H.is-scheduled { border-color: var(--red); color: #f0968f; }
.vehicle.dir-R.is-scheduled { border-color: var(--green); color: #8bd6a2; }

.vehicle .delay { font-weight: 600; opacity: .85; }

.plan.is-stale .vehicle { opacity: .4; transition: none; }

/* --- Randmarker -------------------------------------------------------- */

.edge {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12.5px;
    color: var(--muted);
    padding: 4px 0;
    min-height: 22px;
}

.edge:empty { display: none; }

.edge span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #202020;
    border: 1px solid var(--panel-line);
    border-radius: 999px;
    padding: 2px 9px;
}

.edge .pip { width: 8px; height: 8px; border-radius: 50%; }
.edge .pip.dir-H { background: var(--red); }
.edge .pip.dir-R { background: var(--green); }

/* --- Abfahrtsmonitor --------------------------------------------------- */

.dir + .dir { margin-top: 20px; }

.dir h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 700;
}

.dir h3::before {
    content: "";
    width: 11px;
    height: 11px;
    border-radius: 50%;
}

.dir.dir-towardsEssen h3::before      { background: var(--red); }
.dir.dir-oppositeDirection h3::before { background: var(--green); }

/* minmax(0, …) auch hier: eine Rasterspalte mit "1fr" bekommt als Mindestbreite die
   Inhaltsbreite. Zusammen mit white-space:nowrap am Ziel schiebt ein langer Name wie
   "Gelsenkirchen Hbf" die ganze Seite breiter als das Display - und die Zeitspalte
   rutscht rechts aus dem Bild. */
.dep {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: baseline;
    padding: 9px 0;
    border-top: 1px solid var(--panel-line);
}

.dep .line-no { font-weight: 700; font-size: 14px; color: var(--muted); }

.dep .dest {
    font-size: 15px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dep .when { text-align: right; font-variant-numeric: tabular-nums; }
.dep .when b { font-size: 16px; font-weight: 700; display: block; }
.dep .when small { color: var(--dim); font-size: 12px; }

.dep .when .late { color: var(--red); }
.dep .when .plan-only { color: var(--dim); }

.dep.is-cancelled .dest { text-decoration: line-through; color: var(--dim); }
.dep.is-cancelled .when b { color: var(--red); }

.empty { color: var(--dim); font-size: 14px; padding: 10px 0; }

/* --- Detailfenster ----------------------------------------------------- */

.detail {
    position: fixed;
    inset: auto 0 0 0;
    background: var(--panel);
    border-top: 1px solid var(--panel-line);
    padding: 16px 18px 20px;
    z-index: 20;
}

@media (min-width: 640px) {
    .detail {
        inset: auto auto 20px 20px;
        width: 330px;
        border: 1px solid var(--panel-line);
        border-radius: 12px;
    }
}

.detail h3 { margin: 0 0 10px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 14px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }

.detail .close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
}

footer {
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid var(--panel-line);
    color: var(--dim);
    font-size: 12px;
}

@media (prefers-reduced-motion: reduce) {
    .vehicle { transition: none; }
}
