:root {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f4f5f7;
    --text: #15181d;
    --text-2: #5b6470;
    --text-3: #8a929c;
    --border: #e3e6ea;
    --accent: #1d6fd8;
    --live: #16a34a;
    --predicted: #d97706;
    --offline: #9aa1aa;
    --danger: #dc2626;
    --load-low: #16a34a;
    --load-mid: #d97706;
    --load-high: #dc2626;
    --shadow: 0 8px 28px rgba(16, 24, 40, 0.14), 0 2px 6px rgba(16, 24, 40, 0.08);
    --radius: 16px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.4 var(--font);
    -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

.app {
    display: grid;
    grid-template-rows: 1fr auto;
    height: 100dvh;
}

.map-area { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #eef0f2; }

/* Status pill */
.status {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    left: 12px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100% - 24px);
    padding: 8px 14px 8px 12px;
    background: var(--surface);
    border-radius: 999px;
    box-shadow: var(--shadow);
    font-size: 13px;
    font-weight: 600;
}
.status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--offline); }
.status[data-mode="live"] .status-dot { background: var(--live); animation: pulse 2s infinite; }
.status[data-mode="predicted"] .status-dot { background: var(--predicted); }
.status[data-mode="error"] .status-dot { background: var(--danger); }

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5); }
    70% { box-shadow: 0 0 0 7px rgba(22, 163, 74, 0); }
    100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

/* Detail sheet: bottom sheet on phones, side card on wide screens */
.sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    max-height: 58%;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: var(--shadow);
    animation: sheet-in 180ms ease-out;
}
.sheet[hidden] { display: none; }
.sheet::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 2px;
    background: var(--border);
    flex: none;
}
.sheet-body { overflow-y: auto; padding: 6px 16px 16px; overscroll-behavior: contain; }
.sheet-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--surface-2);
    cursor: pointer;
}
.sheet-close svg { width: 16px; height: 16px; stroke: var(--text-2); stroke-width: 2.2; stroke-linecap: round; }

@keyframes sheet-in { from { transform: translateY(16px); opacity: 0; } }

@media (min-width: 900px) {
    .sheet {
        top: 64px;
        left: 12px;
        right: auto;
        bottom: 12px;
        width: 380px;
        max-height: none;
        border-radius: var(--radius);
    }
    .sheet::before { display: none; }
    .sheet-body { padding-top: 16px; }
}

/* Sheet content */
.eyebrow {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 4px 40px 2px 0;
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--c); }
.title { margin: 0 40px 12px 0; font-size: 21px; font-weight: 700; line-height: 1.2; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px; }
.stat { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.stat-label { color: var(--text-2); font-size: 12px; font-weight: 600; }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 13px; font-weight: 600; color: var(--text-2); }

.section-title { margin: 4px 0 6px; color: var(--text-2); font-size: 12px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; }

.list { list-style: none; margin: 0; padding: 0; }
.row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 4px;
    border: 0;
    border-top: 1px solid var(--border);
    background: none;
    text-align: left;
    cursor: pointer;
}
.list li:first-child .row { border-top: 0; }
.row:hover { background: var(--surface-2); }
.row-badge {
    min-width: 40px;
    padding: 4px 6px;
    border-radius: 8px;
    background: var(--c);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}
.row-main { min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
.row-eta { text-align: right; font-variant-numeric: tabular-nums; }
.row-eta strong { display: block; font-size: 17px; }
.row-eta span { color: var(--text-3); font-size: 12px; }
.due { color: var(--live); }

.load { display: inline-flex; align-items: center; gap: 6px; }
.load-bar { width: 44px; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.load-bar > i { display: block; height: 100%; border-radius: inherit; background: var(--load); }
.load-big .load-bar { width: 100%; height: 8px; }
.load-big { display: block; margin-top: 6px; }

.empty { padding: 12px 0; color: var(--text-2); }
.note { margin: 12px 0 0; color: var(--text-3); font-size: 12px; }

/* Time control */
.timebar {
    z-index: 1001;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(16, 24, 40, 0.06);
}
.timebar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.now-button {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}
.now-button[aria-pressed="true"] { border-color: var(--live); color: var(--live); }
.readout { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 14px; }
.readout strong { color: var(--text); font-size: 16px; }

.slider {
    --fill: 0%;
    width: 100%;
    height: 28px;
    margin: 0;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right, var(--predicted) var(--fill), var(--border) var(--fill));
}
.slider::-moz-range-track { height: 6px; border-radius: 3px; background: var(--border); }
.slider::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--predicted); }
.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    margin-top: -9px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.slider:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.ticks { display: flex; justify-content: space-between; color: var(--text-3); font-size: 11px; padding: 0 2px; }

@media (min-width: 900px) {
    .timebar { padding-left: max(16px, calc(50% - 360px)); padding-right: max(16px, calc(50% - 360px)); }
}

/* Map markers */
.bus-icon { background: none; border: 0; }
.bus {
    position: relative;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--c);
    border: 3px solid #fff;
    box-shadow: 0 0 0 2px var(--load), 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 150ms;
}
.bus.selected { transform: scale(1.25); }
.bus-arrow { position: absolute; inset: 0; display: grid; place-items: center; }
.bus-label {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    padding: 1px 5px;
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    pointer-events: none;
}
.bus-arrow svg { width: 16px; height: 16px; fill: #fff; }

.leaflet-control-attribution { font-size: 10px; }
/* Mute the busy OSM style so routes and buses stand out */
.base-tiles { filter: saturate(0.35) brightness(1.04) contrast(0.92); }
.leaflet-container { font: inherit; }
@media (max-width: 899px) {
    .leaflet-control-zoom { display: none; }
}
