:root {
    --panel-text: #e8e8ea;
    --accent-blue: #2b5cff;
    --accent-blue-hover: #244de0;
    --icon-btn-bg: #9aa0a6;
    --side-btn-bg: #ffffff;
    --side-btn-color: #111827;
}

body {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-x: visible;
    background: none;
}

/* ── Maps ── */
#circles,
#basemap {
    width: 100%;
    height: 100vh;
}
#basemap canvas {
    opacity: 0.6;
}

/* ── Loading overlay ── */
#loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 10050;
    background: rgba(24, 24, 28, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}
#loading-overlay[hidden] { display: none; }

#loading-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
#loading-text {
    color: #fff;
    font: 500 1rem/1.4 inherit;
    letter-spacing: 0.01em;
}

/* ── Utility ── */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ── Address search (Photon; panel closed until user opens it) ── */
.address-search-trigger {
    pointer-events: auto;
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 7px 14px;
    border: none;
    border-radius: 8px;
    background: var(--panel-bg);
    color: #fff;
    font: 600 clamp(0.75rem, 2.8vw, 0.88rem) system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    backdrop-filter: saturate(1.2) blur(6px);
    max-width: calc(100vw - 24px);
    transition: background 0.15s ease, transform 0.02s ease;
}
.address-search-trigger:hover {
    background: rgba(36, 38, 44, 0.98);
}
.address-search-trigger:active {
    transform: translateY(1px);
}
.address-search-trigger:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}
.address-search-trigger[aria-expanded="true"] {
    box-shadow: 0 0 0 2px var(--accent-blue), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.address-search-shell {
    position: fixed;
    inset: 0;
    z-index: 12;
    pointer-events: none;
}

.address-search-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 1;
    background: rgba(18, 20, 24, 0.45);
    backdrop-filter: blur(2px);
    pointer-events: none;
}
.address-search-backdrop:not([hidden]) {
    display: block;
    pointer-events: auto;
}

.address-search-panel {
    position: fixed;
    z-index: 2;
    background: var(--panel-bg);
    color: var(--panel-text);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    backdrop-filter: saturate(1.2) blur(6px);
    overflow: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.22s ease;
}

@media (min-width: 641px) {
    .address-search-backdrop {
        display: none !important;
    }

    .address-search-panel {
        top: 148px;
        left: 50%;
        width: min(420px, calc(100vw - 24px));
        margin-left: calc(-0.5 * min(420px, calc(100vw - 24px)));
        opacity: 0;
        visibility: hidden;
        transform: translateY(-12px);
    }
    .address-search-panel.address-search-panel--open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: translateY(0);
    }
}

@media (max-width: 640px) {
    .address-search-backdrop:not([hidden]) {
        display: block;
    }

    .address-search-panel {
        left: 0;
        right: 0;
        top: 0;
        width: 100%;
        margin-left: 0;
        padding-top: max(6px, env(safe-area-inset-top));
        border-radius: 0 0 10px 10px;
        opacity: 1;
        visibility: visible;
        transform: translateY(-100%);
    }
    .address-search-panel.address-search-panel--open {
        pointer-events: auto;
        transform: translateY(0);
    }

    /* Search UI above the logo so the bar covers it; when closed, :has() no longer applies */
    body:has(#address-search-panel.address-search-panel--open) .address-search-shell {
        z-index: 1012;
    }
    body:has(#address-search-panel.address-search-panel--open) .logo-fixed {
        z-index: 100;
    }
}

.address-search-inner {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px 6px;
}

#addressSearchInput {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(0, 0, 0, 0.2);
    color: var(--panel-text);
    /* ≥16px prevents iOS Safari from zooming the page when the field is focused */
    font-family: inherit;
    font-size: 16px;
    line-height: 1.35;
}
#addressSearchInput::placeholder {
    color: rgba(232, 232, 234, 0.55);
}
#addressSearchInput:focus {
    outline: 2px solid var(--accent-blue);
    outline-offset: 1px;
}

.address-search-results {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: min(40vh, 280px);
    overflow-y: auto;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.15);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.32) rgba(0, 0, 0, 0.2);
}

.address-search-results::-webkit-scrollbar,
.category-edit-dialog__body::-webkit-scrollbar {
    width: 8px;
}

.address-search-results::-webkit-scrollbar-track,
.category-edit-dialog__body::-webkit-scrollbar-track {
    margin: 4px 0;
    background: rgba(0, 0, 0, 0.22);
    border-radius: 8px;
}

.address-search-results::-webkit-scrollbar-thumb,
.category-edit-dialog__body::-webkit-scrollbar-thumb {
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
    background-color: rgba(255, 255, 255, 0.28);
}

.address-search-results::-webkit-scrollbar-thumb:hover,
.category-edit-dialog__body::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.4);
    background-clip: padding-box;
}
.address-search-results[hidden] {
    display: none !important;
}
.address-search-results li {
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.88rem;
    line-height: 1.35;
}
.address-search-results li:last-child {
    border-bottom: 0;
}
.address-search-results li:hover,
.address-search-results li:focus {
    background: rgba(43, 92, 255, 0.25);
    outline: none;
}

.address-search-status {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.35;
    color: rgba(232, 232, 234, 0.85);
}
.address-search-status[hidden] {
    display: none !important;
}
.address-search-status--error {
    color: #f5a3a3;
}

.address-search-attribution {
    margin: 0;
    font-size: 0.68rem;
    line-height: 1.3;
    color: rgba(232, 232, 234, 0.45);
}
.address-search-attribution a {
    color: rgba(232, 232, 234, 0.65);
}

/* ── Map title header ── */
.title-wrapper {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 11;
    text-align: center;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.city-selector-link {
    text-decoration: none;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.2s ease;
    cursor: pointer;
}
.city-selector-link:hover { transform: scale(1.02); }

.map-title {
    background: var(--panel-bg);
    color: white;
    border-radius: 8px 8px 0 0;
    backdrop-filter: saturate(1.2) blur(6px);
    padding: 8px 14px 8px 18px;
    font: 600 clamp(20px, 2.8vw, 28px)/1.2 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    max-width: 90vw;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.map-title svg {
    opacity: 0.7;
    transition: opacity 0.2s;
    padding-top: 5px;
}
.city-selector-link:hover .map-title svg { opacity: 1; }

.subheader {
    display: inline-block;
    background: var(--panel-bg);
    padding: 6px 12px;
    border-radius: 8px;
    color: white;
    font: 500 clamp(12px, 1.6vw, 16px)/1.2 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    backdrop-filter: saturate(1.2) blur(6px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 35vw;
}

/* ── Logo ── */
.logo-fixed {
    position: fixed;
    top: max(0px, env(safe-area-inset-top));
    z-index: 1000;
    display: inline-block;
    height: 130px;
    width: 110px;
    margin: 10px;
}

/* ── Side buttons ── */
.side-button {
    position: fixed;
    z-index: 1000;
    width: 35px;
    height: 35px;
    padding: 0;
    display: grid;
    place-items: center;
    background: var(--side-btn-bg);
    color: var(--side-btn-color);
    border: none;
    border-radius: 8px;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    cursor: pointer;
}
.general-info {
    top: max(170px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
}
.general-info svg { width: 22px; height: 22px; }

/* ── Panels (nav-panel + legend share base styles) ── */
.nav-panel,
.legend {
    background: var(--panel-bg);
    color: var(--panel-text);
    position: absolute;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    backdrop-filter: saturate(1.2) blur(6px);
    max-width: min(86vw, 360px);
    overflow: hidden;
    bottom: 10px;
}
.nav-panel { z-index: 11; min-width: 360px; right: 10px; }
.legend    { z-index: 10; min-width: 260px; left: 10px; }

#legend.legend--dev-on {
    min-width: min(92vw, 320px);
    max-width: min(96vw, 440px);
}

/* ── Panel + popover headers ── */
aside header,
.pop-inner > header {
    background: var(--panel-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    font-weight: 600;
    border-bottom: 1px solid white;
}
.pop-inner > header {
    margin: -10px -12px 0;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

/* ── Time form (Day & departure) ── */
#timeForm {
    --tf-field-bg: rgba(255, 255, 255, 0.07);
    --tf-field-bg-hover: rgba(255, 255, 255, 0.1);
    --tf-field-border: rgba(255, 255, 255, 0.14);
    --tf-field-border-hover: rgba(255, 255, 255, 0.22);
    --tf-field-h: 2.5rem;
    --tf-radius: 10px;
    --tf-focus: 0 0 0 2px rgba(43, 92, 255, 0.45);

    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px 12px 14px;
    min-width: 0;
}

/* Hidden fields must not consume grid rows if UA gives them a box */
#timeForm > input[type="hidden"] {
    display: none !important;
}

/* Flex row: iOS WebKit often ignores width inside CSS grid for type="time" */
#timeForm .time-form-row {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 8px;
    min-width: 0;
    width: 100%;
}

#timeForm .time-form-row > label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 0%;
    min-width: 0;
    max-width: 100%;
    margin: 0;
}

#timeForm label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    min-width: 0;
}

/* Pin controls to the bottom of each column so Day + Time line up when label heights differ */
#timeForm select#daySelect,
#timeForm .time-input-shell {
    margin-top: auto;
}

/* Flex host: WebKit time inputs shrink correctly as flex items, not as nested grid blocks */
#timeForm .time-input-shell {
    display: flex;
    flex-direction: row;
    align-items: center;
    box-sizing: border-box;
    height: var(--tf-field-h);
    min-height: var(--tf-field-h);
    max-height: var(--tf-field-h);
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

/* Native time inputs keep a large intrinsic min-width in WebKit */
#timeForm .time-field {
    min-width: 0;
}

#timeForm .lbl {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: rgba(232, 232, 234, 0.68);
}

#timeForm .time-input-shell input[type="time"] {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: 100%;
}

#timeForm select,
#timeForm input[type="time"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    background-color: var(--tf-field-bg);
    color: var(--panel-text);
    box-sizing: border-box;
    height: var(--tf-field-h);
    min-height: var(--tf-field-h);
    max-height: var(--tf-field-h);
    padding: 0 2.35rem 0 0.75rem;
    border-radius: var(--tf-radius);
    border: 1px solid var(--tf-field-border);
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.2;
    color-scheme: dark;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 1px 2px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    transition:
        background-color 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease;
}

#timeForm select:hover,
#timeForm input[type="time"]:hover {
    background-color: var(--tf-field-bg-hover);
    border-color: var(--tf-field-border-hover);
}

#timeForm select:focus,
#timeForm input[type="time"]:focus {
    outline: none;
    border-color: rgba(43, 92, 255, 0.55);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.22),
        var(--tf-focus);
}

#timeForm select#daySelect {
    display: flex;
    align-items: center;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 14px 14px;
}

#timeForm input[type="time"] {
    position: relative;
    overflow: hidden;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l4 2'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 1.0625rem 1.0625rem;
}

#timeForm input[type="time"]::-webkit-calendar-picker-indicator {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2.25rem;
    height: auto;
    margin: 0;
    padding: 0;
    opacity: 0;
    cursor: pointer;
}

#timeForm input[type="time"]::-webkit-datetime-edit,
#timeForm input[type="time"]::-webkit-datetime-edit-fields-wrapper,
#timeForm input[type="time"]::-webkit-datetime-edit-hour-field,
#timeForm input[type="time"]::-webkit-datetime-edit-minute-field,
#timeForm input[type="time"]::-webkit-datetime-edit-ampm-field,
#timeForm input[type="time"]::-webkit-datetime-edit-text {
    font-family: inherit !important;
    font-variant-numeric: proportional-nums;
    font-feature-settings: normal;
}

#timeForm input[type="time"]::-webkit-datetime-edit-fields-wrapper {
    padding: 0;
    max-width: 100%;
    min-width: 0;
}

#timeForm input[type="time"]::-webkit-datetime-edit {
    max-width: 100%;
    overflow: hidden;
}
#timeForm input[type="time"]::-webkit-datetime-edit-text {
    padding: 0 0.12em;
}
#timeForm input[type="time"]::-webkit-datetime-edit-hour-field,
#timeForm input[type="time"]::-webkit-datetime-edit-minute-field,
#timeForm input[type="time"]::-webkit-datetime-edit-ampm-field {
    padding: 0;
}

#timeForm select#daySelect option {
    background-color: #1e2128;
    color: var(--panel-text);
}

.btn-primary {
    background: var(--accent-blue);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 3px;
    font: inherit;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.02s ease;
}
.btn-primary:hover { background: var(--accent-blue-hover); }
#timeForm .btn-primary {
    grid-column: 1 / -1;
    margin-top: 4px;
    border-radius: 10px;
    padding: 0.55rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    letter-spacing: 0.02em;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: linear-gradient(180deg, #4a74ff 0%, var(--accent-blue) 55%, #2a4fd4 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.22),
        0 2px 10px rgba(43, 92, 255, 0.35);
    transition:
        background 0.18s ease,
        transform 0.02s ease,
        box-shadow 0.18s ease,
        border-color 0.18s ease,
        filter 0.18s ease;
}
#timeForm .btn-primary:not(:disabled):hover {
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.28),
        0 4px 18px rgba(43, 92, 255, 0.45);
    filter: brightness(1.04);
    border-color: rgba(255, 255, 255, 0.28);
}
#timeForm .btn-primary:not(:disabled):active { transform: translateY(1px); }
#timeForm .btn-primary:disabled {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(200, 204, 214, 0.65);
    cursor: not-allowed;
    opacity: 1;
    box-shadow: none;
    pointer-events: none;
    filter: none;
}

/* ── Collapsible panel bodies ── */
#navigation-body,
#legend-body {
    overflow: hidden;
    min-width: 0;
    height: auto;
    transition: height 0.5s ease;
}
#navigation-body[hidden],
#legend-body[hidden] { display: none; }

#legend-body {
    padding: 12px 12px 14px;
}

.nav-panel:has(.legend__toggle[aria-expanded="false"]) #navigation-body { height: 0; padding: 0; }
.nav-panel:has(.legend__toggle[aria-expanded="false"]) .navigation__header { border: 0; }
.legend:has(.legend__toggle[aria-expanded="false"]) #legend-body { height: 0; padding: 0; }
.legend:has(.legend__toggle[aria-expanded="false"]) .legend__header { border: 0; }

/* ── Legend (Categories) — glass rows aligned with #timeForm ── */
.legend__title {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.legend__body-inner {
    margin: 0;
}

.legend table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

.legend tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px 12px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 1px 2px rgba(0, 0, 0, 0.22);
    transition:
        background-color 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease;
}

.legend tbody tr:last-child {
    margin-bottom: 0;
}

.legend tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.22);
}

.legend__category-cell {
    min-width: 0;
    display: inline-flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
}

.legend__name {
    font-weight: 500;
}

.legend__range-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-start;
    gap: 0.2rem;
    text-align: right;
    min-width: 0;
}

.legend__range {
    font-variant-numeric: tabular-nums;
    color: rgba(232, 232, 234, 0.9);
    white-space: nowrap;
}

#legend .legend__area-col {
    display: none;
}

#legend.legend--dev-on .legend__area-col {
    display: block;
    font-variant-numeric: tabular-nums;
    font-size: 0.8125rem;
    font-weight: 500;
    color: rgba(186, 192, 206, 0.82);
    white-space: nowrap;
    line-height: 1.25;
}

#legend.legend--dev-on .legend__area-col::before {
    content: "[";
    color: rgba(255, 255, 255, 0.35);
    font-weight: 500;
}

#legend.legend--dev-on .legend__area-col::after {
    content: "]";
    color: rgba(255, 255, 255, 0.35);
    font-weight: 500;
}

.legend td {
    padding: 0;
    border: none;
    vertical-align: middle;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.2;
}

.legend td:last-child {
    /* Time range column */
    min-width: 0;
}

.legend th {
    padding: 0;
    border: none;
}

.swatch {
    width: 13px;
    height: 13px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    display: inline-block;
    margin-right: 8px;
    vertical-align: -2px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* ── Icon buttons ── */
.icon-btn {
    width: 20px;
    height: 20px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 0;
    cursor: pointer;
    border-radius: 50%;
    background: var(--icon-btn-bg);
    color: #111827;
    position: relative;
    transition: background 0.15s ease;
}
.icon-btn:hover { background: white; }
.icon-btn:focus-visible { outline: none; }
.icon-btn::before {
    content: "";
    position: absolute;
    inset: -5px;
}

/* ── Info popover layout ── */
.info-popover {
    position: relative;
    display: flex;
    gap: 10px;
    margin-left: auto;
    line-height: 0;
}

/* ── Map dock panels: header icon controls (Day & Time + Categories) ── */
#info-btn.icon-btn,
#navigation-toggle.legend__toggle.icon-btn,
#legend-toggle.legend__toggle.icon-btn,
#legend-edit-categories-btn.legend__edit-btn.map-dev-category-edit--visible {
    place-items: center;
    width: 2.125rem;
    height: 1.875rem;
    min-width: 2.125rem;
    padding: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: rgba(248, 250, 252, 0.94);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.18);
    transition:
        background 0.18s ease,
        border-color 0.18s ease,
        color 0.18s ease,
        box-shadow 0.18s ease,
        transform 0.12s ease;
}

#info-btn.icon-btn:hover,
#navigation-toggle.legend__toggle.icon-btn:hover,
#legend-toggle.legend__toggle.icon-btn:hover,
#legend-edit-categories-btn.legend__edit-btn.map-dev-category-edit--visible:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.38);
    color: #fff;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.22);
    transform: translateY(-1px);
}

#info-btn.icon-btn:active,
#navigation-toggle.legend__toggle.icon-btn:active,
#legend-toggle.legend__toggle.icon-btn:active,
#legend-edit-categories-btn.legend__edit-btn.map-dev-category-edit--visible:active {
    transform: translateY(0);
}

#info-btn.icon-btn:focus-visible,
#navigation-toggle.legend__toggle.icon-btn:focus-visible,
#legend-toggle.legend__toggle.icon-btn:focus-visible,
#legend-edit-categories-btn.legend__edit-btn.map-dev-category-edit--visible:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 2px rgba(43, 92, 255, 0.55),
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.18);
}

/* ── Toggle chevron ── */
.legend__toggle .chev {
    width: 20px;
    height: 20px;
    color: currentColor;
    transition: transform 0.5s ease;
    transform-origin: 50% 50%;
    transform: rotate(180deg);
}
.legend__toggle[aria-expanded="true"] .chev { transform: rotate(0deg); }

/* ── Popover panel ── */
.pop {
    position: absolute;
    z-index: 1000;
    min-inline-size: 220px;
    max-inline-size: min(86vw, 360px);
    color: var(--panel-text);
    background: var(--panel-bg);
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
    backdrop-filter: saturate(1.2) blur(6px);
    padding: 10px 12px;
    transform: translateY(-8px);
}
.pop[hidden] { display: none !important; }
.pop[data-placement="bottom"] {
    inset: 100% auto auto 0;
    transform: translateY(8px);
}
.pop-inner { display: grid; gap: 6px; }
.pop-inner p { margin: 0; line-height: 1.5; color: var(--panel-text); }

.pop-close {
    padding: 2px;
    border: 0;
    background: transparent;
    cursor: pointer;
    color: var(--icon-btn-bg);
    font-size: 14px;
    border-radius: 4px;
}
.pop-close:hover { color: var(--panel-text); }
.pop-close:focus-visible { outline: none; }

/* ── Popover arrow ── */
.pop-arrow {
    position: absolute;
    inline-size: 10px;
    block-size: 10px;
    background: #1d1f24;
    transform: rotate(45deg);
}
.pop:not([data-placement="bottom"]) .pop-arrow { bottom: -6px; left: 12px; }
.pop[data-placement="bottom"] .pop-arrow { top: -5px; left: 12px; }
.pop[data-align="end"] .pop-arrow { left: auto; right: 12px; }

/* ── Map hints ── */
#map-hint,
#map-hint-action {
    position: fixed;
    left: 50%;
    top: 38%;
    transform: translateX(-50%);
    z-index: 12;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 0.9rem;
    pointer-events: none;
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
    max-width: calc(100vw - 24px);
}
#map-hint svg,
#map-hint-action svg { flex-shrink: 0; }
#map-hint[hidden],
#map-hint-action[hidden] { display: none; }

#map-hint {
    background: var(--panel-bg);
    color: white;
    transition: opacity 0.3s ease;
}
#map-hint.map-hint--hidden { opacity: 0; }
#map-hint-action { background: var(--accent-blue); color: #fff; }

@keyframes btn-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(43, 92, 255, 0.7); }
    60%  { box-shadow: 0 0 0 8px rgba(43, 92, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(43, 92, 255, 0); }
}
.btn--pulse { animation: btn-pulse 0.7s ease-out 2; }

/* ── MapLibre controls ── */
.maplibregl-ctrl-group { border-radius: 8px; }
.maplibregl-ctrl-group button { width: 35px; height: 35px; }
.maplibregl-ctrl-group .maplibregl-ctrl-icon { background-size: 80% 80%; }

/* ── Onboarding / tutorial ── */
.skip-btn {
    background: transparent;
    border: none;
    color: #d0d0d0;
    font-size: 14px;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s;
}
.skip-btn:hover { color: #ffffff; }

.tutorial-buttons {
    display: none;
    justify-content: space-between;
    align-items: center;
}
.tutorial-buttons button {
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    font: inherit;
    cursor: pointer;
    background: var(--accent-blue);
    color: white;
}
.tutorial-buttons .skip-btn {
    background: transparent;
    color: #d0d0d0;
    padding: 0;
}
.tutorial-progress { margin: 0 8px; }

.floating-clone {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    margin: 0;
    transform: translate3d(0, 0, 0);
}
#info-btn-onboarding { display: none; }

/* ── Responsive ── */
@media (prefers-reduced-motion: reduce) {
    .legend__toggle .chev,
    #legend-body,
    #navigation-body { transition: none; }
    .address-search-panel { transition: none; }
    #info-btn.icon-btn,
    #navigation-toggle.legend__toggle.icon-btn,
    #legend-toggle.legend__toggle.icon-btn,
    #legend-edit-categories-btn.legend__edit-btn.map-dev-category-edit--visible {
        transition: none;
    }
}

@media (max-width: 640px) {
    .map-title { font-size: 1.5rem; line-height: 1.0; }
    .subheader { font-size: 0.8rem; }

    .address-search-trigger__text {
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .bottom-dock {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
        display: grid;
        gap: 12px;
        z-index: 11;
        pointer-events: none;
    }
    .bottom-dock > .legend,
    .bottom-dock > .nav-panel {
        pointer-events: auto;
        position: static !important;
        max-width: none !important;
        /* Desktop uses min-width: 360px — allow panels to shrink to the viewport */
        min-width: 0 !important;
        width: 100%;
        box-sizing: border-box;
    }

    /* Categories header: keep title + edit + collapse on narrow widths */
    .legend__header {
        flex-wrap: wrap;
        row-gap: 8px;
        column-gap: 10px;
        align-items: center;
    }

    .legend__header .legend__title {
        flex: 1 1 0;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .legend__header .info-popover {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        gap: 8px;
        margin-left: auto;
    }

    /* WebKit time UI — mobile: favor Day width, match control heights, nudge time text start */
    #timeForm {
        gap: 10px;
        padding: 12px 12px 14px;
    }

    #timeForm .time-form-row {
        gap: 6px;
    }

    /* Equal column widths (share row 50/50 minus gap) */
    #timeForm .time-form-row > .day-field,
    #timeForm .time-form-row > .time-field {
        flex: 1 1 0%;
        min-width: 0;
    }

    #timeForm select#daySelect {
        font-size: 0.8125rem;
        padding-right: 2rem;
    }

    #timeForm #departureTimeInput {
        direction: ltr;
        text-align: left !important;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l4 2'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.5rem center;
        background-size: 1rem 1rem;
        padding: 0 1.9rem 0 0.75rem;
        font-size: 0.8125rem;
        overflow: hidden;
    }

    #timeForm input[type="time"]::-webkit-calendar-picker-indicator {
        width: 1.9rem;
    }

    #timeForm input[type="time"]::-webkit-datetime-edit-fields-wrapper {
        display: flex !important;
        justify-content: flex-start !important;
        align-items: center;
        width: 100% !important;
        box-sizing: border-box;
        padding-inline-start: 2px;
    }

    #timeForm input[type="time"]::-webkit-datetime-edit {
        overflow: hidden;
        max-width: 100%;
        margin-inline: 0 !important;
        text-align: start !important;
        direction: ltr !important;
        width: auto !important;
        flex: 0 0 auto !important;
    }

    #timeForm input[type="time"]::-webkit-datetime-edit-hour-field,
    #timeForm input[type="time"]::-webkit-datetime-edit-minute-field,
    #timeForm input[type="time"]::-webkit-datetime-edit-ampm-field {
        text-align: start !important;
    }

    .logo-fixed { height: 80px; width: 68px; }

    #map-hint,
    #map-hint-action {
        font-size: clamp(0.7rem, 3.5vw, 0.9rem);
        padding: 8px 12px;
        gap: 6px;
        overflow: hidden;
        max-width: calc(100vw - 32px);
    }
    #map-hint svg,
    #map-hint-action svg { width: 13px; height: 13px; }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .bottom-dock { display: flex; }
    .logo-fixed { height: 80px; width: 68px; }
}

/* Map page — edit travel-time categories (modal) */
html.category-edit-open {
    overflow: hidden;
}

.category-edit-backdrop {
    box-sizing: border-box;
    position: fixed;
    inset: 0;
    z-index: 10010;
    margin: 0;
    padding: 0;
    border: none;
    background: rgba(6, 8, 12, 0.58);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    cursor: pointer;
}

.category-edit-backdrop:not([hidden]) {
    display: block;
}

.category-edit-backdrop[hidden],
.category-edit-dialog[hidden] {
    display: none !important;
}

.category-edit-dialog:not([hidden]) {
    box-sizing: border-box;
    position: fixed;
    inset: 0;
    z-index: 10011;
    display: flex;
    align-items: center;
    justify-content: center;
    padding:
        max(12px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(12px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
    pointer-events: none;
}

.category-edit-dialog__surface {
    pointer-events: auto;
    width: min(100%, 420px);
    max-height: min(88vh, 640px);
    display: flex;
    flex-direction: column;
    border-radius: 14px;
    background: linear-gradient(165deg, rgba(34, 38, 48, 0.98) 0%, rgba(22, 24, 30, 0.99) 100%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow:
        0 24px 48px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(0, 0, 0, 0.2) inset;
    color: #e8eaef;
    overflow: hidden;
}

.category-edit-dialog__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.category-edit-dialog__title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
    letter-spacing: 0.02em;
    line-height: 1.25;
}

.category-edit-dialog__close {
    flex-shrink: 0;
    color: rgba(232, 234, 239, 0.85);
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}

.category-edit-dialog__close:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.category-edit-dialog__body {
    box-sizing: border-box;
    margin: 0;
    padding: 12px 16px 10px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.15);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.32) rgba(0, 0, 0, 0.2);
}

.category-edit-dialog__lede {
    margin: 0 0 16px;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: rgba(200, 204, 214, 0.92);
}

.category-edit-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.category-edit-field__label {
    font-size: 0.78rem;
    font-weight: 500;
    color: rgba(210, 214, 224, 0.88);
}

.category-edit-select,
.category-edit-input {
    font: inherit;
    font-size: 0.9rem;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(0, 0, 0, 0.28);
    color: #f4f5f8;
    width: 100%;
    box-sizing: border-box;
}

.category-edit-select:focus,
.category-edit-input:focus {
    outline: none;
    border-color: rgba(96, 165, 250, 0.55);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.22);
}

.category-edit-boundaries label[hidden] {
    display: none !important;
}

.category-edit-section-label {
    margin: 6px 0 10px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(168, 174, 188, 0.9);
}

.category-edit-rows {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 4px;
}

.category-edit-row {
    display: grid;
    grid-template-columns: 28px 1fr 44px;
    align-items: center;
    gap: 10px;
}

.category-edit-row[hidden] {
    display: none !important;
}

.category-edit-row__idx {
    font-size: 0.75rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.35);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.category-edit-name {
    min-width: 0;
    font: inherit;
    font-size: 0.9rem;
    padding: 9px 11px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(0, 0, 0, 0.28);
    color: #f4f5f8;
}

.category-edit-name:focus {
    outline: none;
    border-color: rgba(96, 165, 250, 0.55);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.22);
}

.category-edit-color {
    width: 44px;
    height: 40px;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
}

.category-edit-dialog__footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    padding: 12px 16px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.15);
}

.category-edit-footer-btn {
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: 10px;
    cursor: pointer;
    border: none;
    transition: background 0.15s ease, transform 0.1s ease;
}

.category-edit-footer-btn:active {
    transform: translateY(1px);
}

.category-edit-footer-btn--ghost {
    background: transparent;
    color: rgba(200, 204, 214, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

.category-edit-footer-btn--ghost:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.category-edit-footer-btn--primary {
    background: linear-gradient(180deg, #4b7cff 0%, #355dde 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(53, 93, 222, 0.35);
}

.category-edit-footer-btn--primary:hover {
    filter: brightness(1.06);
}

/* Legend — edit categories (shown only when JS adds .map-dev-category-edit--visible; localStorage.development === "true") */
#legend-edit-categories-btn.legend__edit-btn {
    display: none !important;
}

#legend-edit-categories-btn.legend__edit-btn.map-dev-category-edit--visible {
    display: inline-grid !important;
}

.legend__edit-icon {
    display: block;
    width: 15px;
    height: 15px;
}

@media (max-width: 640px) {
    .category-edit-dialog:not([hidden]) {
        align-items: flex-end;
    }

    .category-edit-dialog__surface {
        width: 100%;
        max-height: min(92dvh, 620px);
        border-radius: 14px 14px 0 0;
    }
}
