:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --accent: #1d4ed8;
    --late: #dc2626;
    --early: #059669;
    --shadow: 0 4px 18px rgba(15, 23, 42, .14);
    --radius: 12px;
    color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220;
        --surface: #111a2c;
        --surface-2: #1c2740;
        --text: #e2e8f0;
        --muted: #94a3b8;
        --border: #26334d;
        --accent: #60a5fa;
        --late: #f87171;
        --early: #34d399;
        --shadow: 0 4px 18px rgba(0, 0, 0, .5);
    }
    .leaflet-tile-pane { filter: brightness(.75) contrast(1.1) saturate(.8); }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
}
button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1001;
    display: flex; align-items: center; gap: 10px;
    height: 56px; padding: 0 12px;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 6px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 18px; }
.brand-mark { background: var(--accent); color: #fff; border-radius: 8px; padding: 2px 7px; font-size: 15px; }
.search { flex: 1; max-width: 460px; }
.search input {
    width: 100%; height: 38px; padding: 0 14px;
    border: 1px solid var(--border); border-radius: 19px;
    background: var(--surface-2); color: var(--text); font: inherit; outline: none;
}
.search input:focus { border-color: var(--accent); }
.icon-btn {
    display: grid; place-items: center; flex: none;
    width: 38px; height: 38px; border: 0; border-radius: 50%;
    background: var(--surface-2); cursor: pointer; font-size: 22px; line-height: 1;
}
.icon-btn:hover { background: var(--border); }

#map { position: fixed; top: 56px; left: 0; right: 0; bottom: 0; }

/* ---------- panel ---------- */
.panel {
    position: fixed; z-index: 1000; top: 68px; left: 12px; bottom: 12px; width: 380px;
    display: flex; flex-direction: column;
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.panel-title { flex: 1; display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 17px; min-width: 0; }
.panel-title > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-body { overflow-y: auto; padding: 4px 0 12px; }

.section { margin: 14px 16px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.list, .timeline { list-style: none; margin: 0; padding: 0; }
.row {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 9px 16px; border: 0; background: none; text-align: left; cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dest { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 13px; }
.when { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { margin: 16px; color: var(--muted); }
.error { color: var(--late); }
.foot { margin: 12px 16px 0; }
.live { color: var(--early); font-weight: 600; }
.cancelled .dest, .cancelled .when { text-decoration: line-through; color: var(--late); }
.notice { margin: 10px 16px; padding: 8px 10px; border-radius: 8px; background: #fef3c7; color: #78350f; font-size: 13px; }
.meta { padding: 10px 16px 6px; display: grid; gap: 4px; }
.next-stop {
    margin: 6px 16px 10px; padding: 10px 12px; border-radius: 10px;
    background: var(--surface-2); border-left: 4px solid var(--accent); display: grid; gap: 2px;
}
.next-name { font-weight: 650; font-size: 16px; }
.btn {
    justify-self: start; margin-top: 6px; padding: 6px 12px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); cursor: pointer;
}
.btn:hover { border-color: var(--accent); }

.badge {
    display: inline-grid; place-items: center; flex: none;
    min-width: 34px; height: 24px; padding: 0 6px; border-radius: 6px;
    font-weight: 700; font-size: 13px; white-space: nowrap;
}
.delay { font-weight: 650; font-size: 13px; font-variant-numeric: tabular-nums; }
.delay.late { color: var(--late); }
.delay.early { color: var(--early); }
.stop-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; border: 3px solid #334155; background: #fff; }

/* journey timeline */
.timeline li { position: relative; }
.timeline li::before {
    content: ""; position: absolute; left: 66px; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: .35;
}
.timeline li:first-child::before { top: 50%; }
.timeline li:last-child::before { bottom: 50%; }
.timeline .row { padding-left: 16px; }
.timeline .row::after {
    content: ""; position: absolute; left: 61px; top: 50%; margin-top: -6px;
    width: 13px; height: 13px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent); box-sizing: border-box;
}
.timeline .time { width: 40px; font-variant-numeric: tabular-nums; color: var(--muted); }
.timeline .grow { padding-left: 22px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline .passed { opacity: .5; }
.timeline .passed .row::after { background: var(--accent); }
.timeline .next .grow { font-weight: 650; }
.timeline .next .row::after { width: 17px; height: 17px; left: 59px; margin-top: -8px; box-shadow: 0 0 0 4px rgba(29, 78, 216, .2); }

/* ---------- bottom controls ---------- */
.controls {
    position: fixed; z-index: 999; left: 12px; bottom: 12px;
    display: flex; flex-direction: column; align-items: flex-start; gap: 6px; max-width: calc(100% - 80px);
}
body.panel-open .controls { left: 404px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; cursor: pointer; user-select: none; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
    display: block; padding: 5px 12px; border-radius: 16px; font-size: 13px; font-weight: 600;
    background: var(--surface); color: var(--muted); box-shadow: var(--shadow); border: 1px solid var(--border);
}
.chip input:checked + span { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.line-filter, .status {
    padding: 4px 10px; border-radius: 8px; font-size: 12px;
    background: var(--surface); box-shadow: var(--shadow); color: var(--muted);
}
.line-filter { color: var(--text); font-size: 13px; }
.line-filter button { border: 0; background: none; cursor: pointer; font-size: 16px; padding: 0 0 0 4px; color: var(--muted); }
.status.error { color: var(--late); }

/* ---------- vehicles ---------- */
.veh-icon { background: none; border: 0; }
.veh {
    position: relative; transform: translate(-50%, -50%);
    display: flex; align-items: center; justify-content: center; gap: 5px; min-width: 26px; height: 20px; padding: 0 5px;
    border-radius: 6px; border: 2px solid #fff; background: var(--vc); color: var(--vt);
    font: 700 11px/1 system-ui, sans-serif; white-space: nowrap; cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.veh b { position: relative; z-index: 1; }
.veh b.dest { max-width: 110px; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.op-logo {
    display: inline-grid; place-items: center; flex: none; min-width: 16px; height: 16px; padding: 0 3px;
    border-radius: 4px; font: 800 9px/1 system-ui, sans-serif; letter-spacing: -.02em; vertical-align: middle;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .85);
}
.op-logo.img { background: #fff; padding: 1px 2px; width: 34px; min-width: 34px; height: 16px; box-shadow: 0 0 0 1px rgba(15, 23, 42, .18); }
/* explicit size + !important: Leaflet sets max-width/height: none !important on images inside marker panes */
.op-logo img, .leaflet-container .op-logo img {
    display: block; width: 100%; height: 100%; max-width: 100% !important; max-height: 100% !important; object-fit: contain;
}
.veh .op-logo { position: relative; z-index: 1; margin-left: -2px; }
.type-icon { flex: none; width: 14px; height: 14px; }
.veh .type-icon { position: relative; z-index: 1; width: 13px; height: 13px; }
.panel-title .type-icon { width: 22px; height: 22px; color: var(--muted); }
.op-line { display: flex; align-items: center; gap: 6px; }
.veh.late { border-color: #fca5a5; }
.veh.selected { transform: translate(-50%, -50%) scale(1.35); box-shadow: 0 0 0 4px rgba(29, 78, 216, .45), 0 1px 4px rgba(0, 0, 0, .35); }
.veh .dir { position: absolute; left: 50%; top: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px; pointer-events: none; }
.veh .dir::before {
    content: ""; position: absolute; left: 50%; top: 0; margin-left: -5px;
    border: 5px solid transparent; border-top: 0; border-bottom: 6px solid var(--vc);
}
/* linear, as long as the tick: vehicles glide on instead of hopping every second */
.animate .leaflet-marker-icon.veh-icon { transition: transform 1s linear; }
.veh em {
    position: relative; z-index: 1; font-style: normal; font-weight: 600;
    max-width: 140px; overflow: hidden; text-overflow: ellipsis;
}

/* navigation view of the selected journey */
.arrow-icon, .dest-icon { background: none; border: 0; }
.route-arrow {
    position: absolute; left: -6px; top: -6px; width: 12px; height: 12px; pointer-events: none;
}
.route-arrow::before {
    content: ""; position: absolute; left: 1px; top: 0;
    border: 5px solid transparent; border-top: 0; border-bottom: 8px solid #fff;
}
.route-arrow::after {
    content: ""; position: absolute; left: 3px; top: 3px;
    border: 3px solid transparent; border-top: 0; border-bottom: 5px solid var(--vc);
}
.dest-pin {
    position: absolute; left: 0; bottom: 0; transform: translate(-50%, 0);
    display: flex; flex-direction: column; align-items: center; pointer-events: none;
}
.dest-pin span {
    padding: 4px 9px; border-radius: 8px; background: var(--vc); color: #fff;
    font: 700 12px/1.2 system-ui, sans-serif; white-space: nowrap; box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
    border: 2px solid #fff;
}
.dest-pin::after { content: ""; width: 3px; height: 14px; background: var(--vc); }


/* ---------- mobile ---------- */
@media (max-width: 700px) {
    .brand-name { display: none; }
    .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 58vh; border-radius: 16px 16px 0 0; }
    .controls { left: 8px; right: 8px; bottom: auto; top: 64px; max-width: none; }
    body.panel-open .controls { left: 8px; }
    .filters { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; padding-bottom: 4px; }
    .leaflet-bottom.leaflet-right { margin-bottom: 0; }
    body.panel-open .leaflet-bottom { display: none; }
}
