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

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; }
body { 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 { 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: 0;
    padding: 4px;
    border: 1px solid #dbe3ee;
    border-radius: 14px;
    background: rgb(255 255 255 / 78%);
}
.direction-filter button { min-height: 44px; 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; isolation: isolate; 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-controls { position: absolute; z-index: 700; top: 12px; left: 50%; width: min(calc(100% - 24px), 680px); transform: translateX(-50%); pointer-events: none; }
.map-controls > * { pointer-events: auto; }
.map-statuses { display: grid; gap: 6px; margin-top: 8px; justify-items: center; }
.location-control { position: absolute; z-index: 700; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 24px); pointer-events: none; }
.location-control > * { pointer-events: auto; }
.location-actions { display: flex; gap: 8px; }
.location-actions button { min-width: 44px; min-height: 44px; padding: 8px 12px; border: 0; border-radius: 12px; color: #fff; background: #0f766e; font-size: .78rem; font-weight: 750; cursor: pointer; box-shadow: 0 4px 15px rgb(15 23 42 / 18%); }
.location-actions button:disabled { cursor: wait; opacity: .6; }
.location-status { margin: 0; padding: 8px 10px; border-radius: 10px; color: #334155; background: rgb(255 255 255 / 94%); font-size: .76rem; box-shadow: 0 4px 15px rgb(15 23 42 / 14%); }
.location-control .location-status { pointer-events: none; }
.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, .stop-strip, .mobile-info-sheet {
    width: min(100%, 1120px);
    margin-inline: auto;
}

.mobile-sheet-heading { display: none; }
.mobile-sheet-content { display: contents; }

.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-privacy-disclosure { margin: 6px 0 0; color: #64748b; font-size: .7rem; line-height: 1.45; }
.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: 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%); cursor: pointer; }
.vehicle-card[hidden] { display: none; }
.vehicle-card.offline { opacity: .62; }
.vehicle-card.delayed { border-color: #fcd34d; }
.vehicle-card.waiting { border-color: #93c5fd; border-style: dashed; }
.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: .72rem; font-weight: 900; }
.direction-badge.forward { background: #2563eb; }
.direction-badge.reverse { background: #f97316; }
.direction-badge.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; }
.customer-eta { margin-top: 5px; color: #0f766e; font-size: .75rem; font-weight: 800; }
.base-station-notice { margin-top: 6px !important; color: #9a3412 !important; font-size: .77rem; font-weight: 800; }
.vehicle-card.waiting .connection-state { color: #1d4ed8; }
.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 { border: 0; background: transparent; }
.passenger-location-icon { border: 0; background: transparent; }
.passenger-location-marker { position: relative; width: 32px; height: 32px; }
.passenger-location-dot { position: absolute; z-index: 2; top: 50%; left: 50%; width: 16px; height: 16px; border: 3px solid #fff; border-radius: 50%; background: #1687f8; box-shadow: 0 2px 8px rgb(15 23 42 / 35%); transform: translate(-50%, -50%); }
.passenger-location-heading { position: absolute; z-index: 1; inset: 0; transform: rotate(var(--passenger-heading-rotation)); transition: transform 160ms linear; transform-origin: center; }
.passenger-location-heading::before { content: ""; position: absolute; top: 0; left: 50%; width: 0; height: 0; border-right: 6px solid transparent; border-bottom: 12px solid #1687f8; border-left: 6px solid transparent; filter: drop-shadow(0 1px 1px rgb(15 23 42 / 30%)); transform: translateX(-50%); }
.passenger-location-heading[hidden] { display: none; }
.bus-marker {
    position: relative;
    display: block;
    width: 34px;
    height: 42px;
    --vehicle-color: #64748b;
    --vehicle-tag-offset: 0px;
    pointer-events: none;
}
.bus-marker.forward { --vehicle-color: #2563eb; }
.bus-marker.reverse { --vehicle-color: #f97316; }
.bus-marker.unknown { --vehicle-color: #64748b; }
.vehicle-direction-arrow {
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 50%;
    width: 34px;
    height: 42px;
    background: #fff;
    clip-path: polygon(50% 0, 100% 40%, 100% 100%, 0 100%, 0 40%);
    filter: drop-shadow(0 3px 7px rgb(15 23 42 / 45%));
    transform: translate(-50%, -50%) rotate(var(--vehicle-heading, 0deg));
    pointer-events: none;
}
.vehicle-direction-arrow::after {
    content: "";
    position: absolute;
    inset: 3px;
    background: var(--vehicle-color);
    clip-path: polygon(50% 0, 100% 42%, 100% 100%, 0 100%, 0 42%);
}
.vehicle-plate-label {
    position: absolute;
    z-index: 3;
    top: 50%;
    left: 50%;
    display: block;
    max-width: 150px;
    padding: 3px 8px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: var(--vehicle-color);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 3px 10px rgb(15 23 42 / 35%);
    transform: translate(-50%, -50%) rotate(var(--vehicle-heading, 0deg)) translateY(var(--vehicle-tag-offset, 0px)) rotate(calc(-1 * var(--vehicle-heading, 0deg)));
}
.bus-marker.plate-marker--medium .vehicle-plate-label { font-size: 10px; }
.bus-marker.plate-marker--long .vehicle-plate-label { font-size: 9px; letter-spacing: -.15px; }
.vehicle-marker--base-station::before { content: ""; position: absolute; z-index: 1; top: 50%; left: 50%; width: 46px; height: 46px; border: 2px dashed #9a3412; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.vehicle-marker--base-station .base-station-marker-badge { position: absolute; z-index: 4; right: -14px; bottom: -10px; 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; }
.passenger-stop-label {
    padding: 5px 8px;
    border: 1px solid rgb(148 163 184 / 75%);
    border-radius: 8px;
    background: rgb(255 255 255 / 96%);
    color: #172033;
    font-size: .74rem;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgb(15 23 42 / 34%), 0 0 0 1px rgb(255 255 255 / 70%);
    cursor: pointer;
}
.passenger-stop-label:focus-visible { outline: 3px solid #38bdf8; outline-offset: 2px; }
.passenger-stop-marker:focus-visible { outline: 3px solid #38bdf8; outline-offset: 3px; }
.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; }
.leaflet-popup-content:has(.stop-arrival-details) { width: min(320px, calc(100vw - 76px)) !important; }
.stop-arrival-details h2 { margin: 0 0 10px; color: #0f172a; font-size: 1rem; }
.stop-arrival-direction + .stop-arrival-direction { margin-top: 11px; padding-top: 10px; border-top: 1px solid #e2e8f0; }
.stop-arrival-direction h3 { margin: 0; color: #334155; font-size: .8rem; }
.stop-arrival-message { margin: 6px 0 0; color: #64748b; font-size: .75rem; }
.stop-arrival-list { display: grid; gap: 7px; margin: 7px 0 0; padding: 0; list-style: none; }
.stop-arrival-vehicle { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 7px 8px; border-radius: 9px; background: #f8fafc; }
.stop-arrival-vehicle strong { min-width: 0; overflow-wrap: anywhere; color: #172033; font-size: .78rem; }
.stop-arrival-plate { color: #64748b; font-size: .68rem; }
.stop-arrival-eta { grid-column: 2; grid-row: 1; color: #0f766e; font-size: .74rem; font-weight: 800; }
.stop-arrival-state { grid-column: 2; grid-row: 2; justify-self: end; font-size: .68rem; font-weight: 750; }
.stop-arrival-vehicle.online .stop-arrival-state { color: #15803d; }
.stop-arrival-vehicle.delayed .stop-arrival-state { color: #b45309; }

@media (max-width: 639px) {
    html, body { width: 100%; height: 100%; overflow: hidden; }
    .passenger-app { position: relative; width: 100%; height: 100vh; height: 100dvh; min-height: 0; padding: 0; overflow: hidden; }
    .app-header, .stop-strip, .map-legend { display: none; }
    .map-panel { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; box-shadow: none; }
    #passenger-map { width: 100%; height: 100vh; height: 100dvh; }
    .map-controls { top: max(8px, env(safe-area-inset-top)); width: calc(100% - 16px); }
    .direction-filter { gap: 3px; padding: 3px; border-radius: 12px; background: rgb(255 255 255 / 90%); box-shadow: 0 5px 18px rgb(15 23 42 / 14%); }
    .direction-filter button { min-height: 44px; font-size: .7rem; }
    .map-statuses { margin-top: 5px; }
    .stale-banner, .error-banner { padding: 7px 9px; font-size: .72rem; }
    .error-banner button { min-height: 44px; }
    .location-control { top: calc(max(8px, env(safe-area-inset-top)) + 56px); right: 8px; bottom: auto; left: 8px; justify-content: flex-end; align-items: flex-start; }
    .location-status { max-width: min(62vw, 240px); }
    .location-actions { flex: 0 0 auto; }
    .location-actions button { width: 44px; height: 44px; overflow: hidden; padding: 0 5px; font-size: 0; white-space: nowrap; }
    .location-actions button::before { font-size: 1rem; }
    [data-use-location]::before { content: "◎"; }
    [data-recenter-location]::before { content: "⌖"; }

    .mobile-info-sheet { position: absolute; z-index: 1100; right: 8px; bottom: 0; left: 8px; width: auto; max-height: 56vh; max-height: 56dvh; margin: 0; padding: 0 10px calc(12px + env(safe-area-inset-bottom)); overflow: hidden; border: 1px solid rgb(203 213 225 / 88%); border-bottom: 0; border-radius: 20px 20px 0 0; background: rgb(248 250 252 / 96%); box-shadow: 0 -8px 30px rgb(15 23 42 / 18%); backdrop-filter: blur(12px); }
    .mobile-sheet-heading { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 10px; }
    .mobile-sheet-heading > div { display: flex; align-items: baseline; gap: 8px; }
    .mobile-sheet-heading strong { font-size: .95rem; }
    .mobile-sheet-heading span { color: #64748b; font-size: .74rem; }
    .mobile-sheet-heading button { min-width: 44px; min-height: 44px; padding: 6px 9px; border: 0; border-radius: 12px; color: #334155; background: #e2e8f0; font-size: .75rem; font-weight: 800; cursor: pointer; }
    .mobile-sheet-heading .sheet-chevron { display: inline-block; margin-left: 4px; color: currentColor; font-size: 1rem; transition: transform .16s ease; }
    .mobile-info-sheet:not(.is-expanded) .sheet-chevron { transform: rotate(180deg); }
    .mobile-info-sheet:not(.is-expanded) .mobile-sheet-content { display: none; }
    .mobile-sheet-content { display: flex; min-height: 0; max-height: calc(56vh - 70px - env(safe-area-inset-bottom)); max-height: calc(56dvh - 70px - env(safe-area-inset-bottom)); flex-direction: column; }
    .location-section { flex: 0 0 auto; margin: 0 0 8px; padding: 0; border: 0; background: transparent; }
    .location-section > .section-heading,
    .vehicle-section > .section-heading { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .location-privacy-disclosure { margin: 0 2px 7px; font-size: .64rem; }
    .location-results { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; margin-top: 0; }
    .location-direction { padding: 7px; border-radius: 10px; }
    .location-direction h3 { font-size: .75rem; }
    .location-direction p { margin-top: 3px; font-size: .68rem; }
    .vehicle-section { display: flex; min-height: 0; flex: 1 1 auto; flex-direction: column; margin: 0; }
    .vehicle-list { min-height: 0; flex: 1 1 auto; margin-top: 0; padding: 0 1px 2px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; touch-action: pan-y; }
    .vehicle-card { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 9px; border-radius: 13px; }
    .vehicle-main strong { font-size: .86rem; }
    .vehicle-main .plate, .vehicle-main .connection-state { font-size: .68rem; }
    .vehicle-main .next-stop, .customer-eta { font-size: .72rem; }
    .vehicle-eta strong { font-size: .76rem; }
    .vehicle-eta span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .mobile-sheet-heading .sheet-chevron { transition: none; }
    .passenger-location-heading { transition: none; }
}
@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)); }
}
