/* Map page */
html, body {
    height: 100%;
    overflow: hidden;
}

#map {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
}

#loading {
    display: none;
    position: fixed;
    top: calc(var(--header-height) + 16px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--navy);
    background: var(--surface);
    border-radius: 999px;
    box-shadow: var(--shadow);
}

#loading.is-visible {
    display: inline-flex;
}

.search-area-button {
    position: fixed;
    top: calc(var(--header-height) + 16px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 600;
    color: var(--navy);
    background: var(--surface);
    border: none;
    border-radius: 999px;
    box-shadow: var(--shadow);
    cursor: pointer;
}

.search-area-button[hidden] {
    display: none;
}

.search-area-button:hover:not(:disabled) {
    background: var(--surface-alt);
}

#loading.is-visible ~ .search-area-button {
    display: none;
}

/* ---------- Active filter chips ---------- */
.filter-chips {
    position: fixed;
    top: calc(var(--header-height) + 10px);
    left: 10px;
    right: 60px;
    z-index: 5;
    display: flex;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-x: auto;
    scrollbar-width: none;
    pointer-events: none;
}

.filter-chips:empty {
    display: none;
}

.filter-chips:not(:empty) ~ #loading,
.filter-chips:not(:empty) ~ .search-area-button {
    top: calc(var(--header-height) + 56px);
}

.filter-chip {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 6px 0 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--navy);
    background: var(--surface);
    border-radius: 999px;
    box-shadow: 0 2px 6px rgba(0, 36, 63, 0.15);
    pointer-events: auto;
}

.filter-chip button {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    padding: 0;
    color: var(--muted);
    background: none;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.filter-chip button:hover {
    color: var(--navy);
    background: var(--surface-alt);
}

/* ---------- Legend ---------- */
.map-legend {
    position: fixed;
    left: 10px;
    bottom: 30px;
    z-index: 5;
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 6px rgba(0, 36, 63, 0.15);
}

.legend-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--navy);
    background: none;
    border: none;
    cursor: pointer;
}

.legend-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 10px 12px;
    list-style: none;
}

.legend-list li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-available { background: #16a34a; }
.legend-fast { background: #f59e0b; }
.legend-offline { background: #94a3b8; }
.legend-you {
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

@media (max-width: 640px) {
    .legend-toggle {
        display: inline-flex;
    }

    .legend-list {
        display: none;
        padding-top: 0;
    }

    .map-legend.is-open .legend-list {
        display: flex;
    }
}

/* ---------- Map controls ---------- */
.mapboxgl-ctrl-top-right {
    top: 8px;
    right: 8px;
}

.mapboxgl-ctrl-group {
    border-radius: var(--radius-sm) !important;
    box-shadow: 0 2px 6px rgba(0, 36, 63, 0.15) !important;
}

.mapboxgl-ctrl-group button {
    width: 40px !important;
    height: 40px !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-ctrl-button {
    position: relative;
    color: var(--navy);
    background: var(--surface) !important;
}

.map-ctrl-button svg {
    display: block;
}

.map-ctrl-button:hover {
    background: var(--surface-alt) !important;
}

.filter-count {
    position: absolute;
    top: 3px;
    right: 3px;
    min-width: 15px;
    height: 15px;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 700;
    line-height: 15px;
    color: var(--navy);
    background: var(--yellow);
    border-radius: 999px;
}

.filter-count[hidden] {
    display: none;
}

/* ---------- Map markers ---------- */
.current-location-dot {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.2);
}

.walking-time-marker {
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--navy);
    white-space: nowrap;
    background: var(--yellow);
    border: 2px solid #fff;
    border-radius: 999px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

/* ---------- Filter panel ---------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    background: rgba(0, 20, 40, 0.45);
}

.modal.is-open {
    display: flex;
}

.filter-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(460px, calc(100vw - 32px));
    max-height: min(640px, calc(100vh - 48px));
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.filter-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.filter-panel-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--navy);
}

.filter-panel-header h2 i {
    color: var(--yellow);
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    font-size: 18px;
    color: var(--muted);
    background: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.icon-button:hover {
    color: var(--navy);
    background: var(--surface-alt);
}

.filter-sections {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
}

.filter-section {
    border-bottom: 1px solid var(--border);
}

.filter-section:last-child {
    border-bottom: none;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 14px 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--navy);
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
}

.section-header > i:first-child {
    width: 18px;
    color: var(--muted);
    text-align: center;
}

.section-count {
    margin-left: auto;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--navy);
    background: var(--yellow-soft);
    border-radius: 999px;
}

.section-count:empty {
    display: none;
}

.section-header .chevron {
    margin-left: auto;
    font-size: 12px;
    color: var(--muted);
    transition: transform 0.2s;
}

.section-count:not(:empty) + .chevron {
    margin-left: 8px;
}

.filter-section.collapsed .chevron {
    transform: rotate(-90deg);
}

.filter-section.collapsed .section-content {
    display: none;
}

.section-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 0 14px 28px;
}

.section-content label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 8px;
    font-size: 14px;
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
}

.section-content label:hover {
    background: var(--surface-alt);
}

.section-content label.select-all {
    font-weight: 600;
    color: var(--navy);
}

.section-content input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--navy);
}

.filter-panel-footer {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.filter-panel-footer .btn {
    flex: 1;
    height: 44px;
}

@media (max-width: 640px) {
    .modal {
        align-items: flex-end;
    }

    .filter-panel {
        width: 100%;
        max-height: 85vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        animation: sheet-up 0.25s ease-out;
    }
}

@keyframes sheet-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ---------- Charger details panel ---------- */
.custom-popup-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1;
}

.charger-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    font-size: 14px;
    color: var(--text);
}

.charger-card-header {
    padding-right: 36px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.charger-card-header h3 {
    margin: 0 0 4px;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--navy);
}

.charger-operator {
    margin: 0;
    color: var(--muted);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
}

.status-pill::before {
    content: '';
    width: 7px;
    height: 7px;
    background: currentColor;
    border-radius: 50%;
}

.status-pill.is-up {
    color: var(--success);
    background: #dcfce7;
}

.status-pill.is-down {
    color: var(--danger);
    background: #fee2e2;
}

.status-pill.is-unknown {
    color: var(--muted);
    background: var(--surface-alt);
}

.charger-field {
    margin: 0;
}

.charger-field dt {
    margin-bottom: 2px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.charger-field dd {
    margin: 0 0 12px;
}

.charger-field dd:last-child {
    margin-bottom: 0;
}

.charger-connectors h4 {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.connector {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    margin-bottom: 6px;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
}

.connector-name {
    font-weight: 600;
    color: var(--navy);
}

.connector-meta {
    color: var(--muted);
    font-size: 13px;
    text-align: right;
    white-space: nowrap;
}

.freshness {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: -4px 0 0;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.4;
    color: var(--success);
    background: #f0fdf4;
    border-radius: var(--radius-sm);
}

.freshness i {
    margin-top: 2px;
}

.freshness.is-stale {
    color: #92400e;
    background: #fffbeb;
}

.preserve-lines {
    white-space: pre-line;
}

.report-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: -4px;
    font-size: 13px;
    color: var(--muted);
    text-decoration: none;
}

.report-link:hover {
    color: var(--navy);
    text-decoration: underline;
}

.mapboxgl-marker.is-stale svg {
    opacity: 0.45;
}

.cluster-marker {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: var(--navy);
    color: #fff;
    font: 700 13px/1 var(--font);
    box-shadow: var(--shadow);
    cursor: pointer;
}

.cluster-marker.is-large {
    width: 46px;
    height: 46px;
    font-size: 15px;
}

.cluster-marker:hover {
    background: var(--accent);
}

.legend-stale {
    background: #16a34a;
    opacity: 0.45;
}

.legend-cluster {
    display: grid;
    place-items: center;
    width: 16px;
    height: 16px;
    margin: -2px;
    background: var(--navy);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
}

.charger-updated {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
}

.charger-actions {
    display: flex;
    gap: 10px;
}

.charger-actions .btn {
    flex: 1;
    height: 44px;
}
