:root {
    color-scheme: light;
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    background: #eef2f7;
    color: #172033;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: linear-gradient(180deg, #f8fafc 0, #eef2f7 100%); }
button { font: inherit; }

.passenger-app {
    width: 100%;
    min-height: 100vh;
    margin: 0 auto;
    padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.app-header, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.app-header h1 { margin: 2px 0 0; font-size: clamp(1.45rem, 6vw, 2rem); letter-spacing: -.04em; }
.app-kicker { margin: 0; color: #64748b; font-size: .75rem; font-weight: 700; letter-spacing: .18em; }
.live-indicator { display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto; color: #166534; font-size: .78rem; font-weight: 700; }
.live-indicator span { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 4px rgb(34 197 94 / 15%); }

.stale-banner, .error-banner { margin-top: 12px; padding: 10px 12px; border-radius: 12px; font-size: .84rem; font-weight: 700; }
.stale-banner { color: #92400e; background: #fef3c7; border: 1px solid #fde68a; }
.error-banner { color: #991b1b; background: #fee2e2; border: 1px solid #fecaca; }
.error-banner button { margin-left: 8px; padding: 5px 9px; border: 1px solid #fca5a5; border-radius: 8px; color: inherit; background: #fff; font-weight: 700; cursor: pointer; }

.direction-filter {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin: 16px 0 12px;
    padding: 4px;
    border: 1px solid #dbe3ee;
    border-radius: 14px;
    background: rgb(255 255 255 / 78%);
}
.direction-filter button { min-height: 38px; padding: 7px 5px; border: 0; border-radius: 10px; color: #64748b; background: transparent; font-size: .75rem; font-weight: 750; cursor: pointer; }
.direction-filter button.is-active { color: #0f172a; background: #fff; box-shadow: 0 3px 12px rgb(15 23 42 / 10%); }

.map-panel { position: relative; overflow: hidden; border: 1px solid #dbe3ee; border-radius: 20px; background: #dce8ec; box-shadow: 0 12px 30px rgb(30 41 59 / 12%); }
#passenger-map { width: 100%; height: clamp(520px, 68vh, 760px); height: clamp(520px, 68dvh, 760px); }
.map-legend { position: absolute; z-index: 500; right: 10px; bottom: 10px; display: flex; gap: 10px; padding: 7px 9px; border: 1px solid rgb(203 213 225 / 80%); border-radius: 10px; background: rgb(255 255 255 / 92%); color: #475569; font-size: .7rem; box-shadow: 0 4px 15px rgb(15 23 42 / 10%); }
.map-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-line { width: 20px; height: 0; border-top: 3px solid; }
.legend-line.forward { border-color: #2563eb; }
.legend-line.reverse { border-color: #f97316; border-top-style: dashed; }

.app-header, .direction-filter,
.stop-strip, .location-section, .vehicle-section {
    width: min(100%, 1120px);
    margin-inline: auto;
}

.stop-strip { display: flex; gap: 8px; overflow-x: auto; margin: 12px auto 0; padding: 2px 1px 7px; scrollbar-width: thin; }
.stop-pill { flex: 0 0 auto; padding: 7px 10px; border: 1px solid #dbe3ee; border-radius: 999px; background: #fff; color: #475569; font-size: .75rem; font-weight: 650; }
.stop-pill.endpoint { color: #0f172a; border-color: #bac8da; }

.location-section { margin-top: 14px; padding: 13px; border: 1px solid #dbe3ee; border-radius: 16px; background: rgb(255 255 255 / 84%); }
.location-heading > div { min-width: 0; }
.location-heading h2 { margin: 0; font-size: 1rem; }
.location-heading p { margin: 3px 0 0; color: #64748b; font-size: .7rem; }
.location-heading button { flex: 0 0 auto; min-height: 38px; padding: 7px 11px; border: 0; border-radius: 11px; color: #fff; background: #0f766e; font-size: .78rem; font-weight: 750; cursor: pointer; }
.location-heading button:disabled { cursor: wait; opacity: .6; }
.location-status { margin: 10px 0 0; color: #475569; font-size: .78rem; }
.location-results { display: grid; gap: 8px; margin-top: 10px; }
.location-direction { padding: 10px; border: 1px solid #dbe3ee; border-radius: 12px; background: #fff; }
.location-direction h3 { margin: 0; font-size: .86rem; }
.location-direction p { margin: 5px 0 0; }
.location-target, .location-empty { color: #64748b; font-size: .72rem; }
.location-vehicle { color: #172033; font-size: .78rem; font-weight: 700; }

.vehicle-section { margin-top: 14px; }
.section-heading h2 { margin: 0; font-size: 1rem; }
.section-heading span { color: #64748b; font-size: .78rem; }
.vehicle-list { display: grid; gap: 10px; margin-top: 9px; }
.vehicle-card { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 12px; border: 1px solid #dbe3ee; border-radius: 16px; background: #fff; box-shadow: 0 5px 18px rgb(30 41 59 / 7%); }
.vehicle-card[hidden] { display: none; }
.vehicle-card.offline { opacity: .62; }
.vehicle-card.delayed { border-color: #fcd34d; }
.vehicle-card.base-station { border-color: #f97316; border-style: dashed; }
.direction-badge { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: #fff; font-size: 1.25rem; font-weight: 900; }
.direction-badge.forward, .bus-marker.forward { background: #2563eb; }
.direction-badge.reverse, .bus-marker.reverse { background: #f97316; }
.direction-badge.unknown, .bus-marker.unknown { background: #64748b; }
.vehicle-main strong, .vehicle-main span, .vehicle-eta strong, .vehicle-eta span { display: block; }
.vehicle-main strong { font-size: .92rem; }
.vehicle-main .plate { margin-top: 2px; color: #64748b; font-size: .72rem; }
.vehicle-main .connection-state { margin-top: 4px; color: #475569; font-size: .72rem; font-weight: 700; }
.vehicle-main .next-stop { margin-top: 6px; color: #334155; font-size: .77rem; }
.base-station-notice { margin-top: 6px !important; color: #9a3412 !important; font-size: .77rem; font-weight: 800; }
.vehicle-eta { text-align: right; }
.vehicle-eta strong { color: #0f172a; font-size: .84rem; }
.vehicle-eta span { margin-top: 4px; color: #64748b; font-size: .66rem; }

.vehicle-marker-shell { position: relative; border: 0; background: transparent; }
.bus-marker { display: grid; place-items: center; width: 34px; height: 34px; border: 3px solid #fff; border-radius: 50% 50% 50% 12px; color: #fff; font-size: 18px; font-weight: 900; box-shadow: 0 4px 12px rgb(15 23 42 / 35%); transform: rotate(-45deg); }
.bus-marker span { transform: rotate(45deg); }
.vehicle-marker--base-station::before { content: ""; position: absolute; inset: -6px; border: 2px dashed #9a3412; border-radius: 50%; pointer-events: none; }
.vehicle-marker--base-station .bus-marker { background: #f97316; }
.vehicle-marker--base-station .base-station-marker-badge { position: absolute; right: -13px; bottom: -8px; min-width: 28px; padding: 2px 4px; border: 1px solid #9a3412; border-radius: 999px; background: #fff7ed; color: #9a3412; font-size: 9px; line-height: 1; text-align: center; transform: rotate(45deg); }
.route-forward, .route-reverse, .route-neutral { stroke-linecap: round; stroke-linejoin: round; }
.leaflet-popup-content { margin: 12px 14px; line-height: 1.45; }
.vehicle-popup strong, .vehicle-popup span { display: block; }
.vehicle-popup span { margin-top: 3px; color: #475569; font-size: .78rem; }

@media (max-width: 639px) {
    .passenger-app { padding-inline: 10px; }
    #passenger-map { height: clamp(620px, calc(100vh - 164px), 720px); height: clamp(620px, calc(100svh - 164px), 720px); }
}
@media (min-width: 640px) {
    .passenger-app { padding-inline: 22px; }
    .vehicle-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1100px) {
    .vehicle-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
