/* index.html — the map page. Shared rules live in app.css. */

/* Full-height flex layout: the map fills whatever the controls leave. */
html, body { height: 100%; overflow: hidden; }
body { display: flex; flex-direction: column; }
.topbar { flex-shrink: 0; }
.container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    overflow: hidden;
    padding-bottom: 1rem;
}
.stats, .filters, .controls { flex-shrink: 0; }

/* Filters: one panel, one row per group. On a phone the same panel is a
   bottom sheet opened from the Filters button (see the media query). */
.filters-panel { display: grid; gap: 0.45rem; padding: 0.55rem 0.75rem; }
body:not(.filters-open) .filters-panel { display: none; }
.filter-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}
.filter-label {
    flex: none;
    width: 4.5rem;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
}
.filter-row .switch + .switch { margin-left: 0.5rem; }
#transitStyleContainer { display: none; align-items: center; gap: 0.5rem; flex-wrap: wrap; width: 100%; padding-left: 5.1rem; }
#transitStyleContainer .filter-label-inline { width: auto; }
#transitStyleContainer .transit-note { color: var(--text-3); font-size: 12px; }
.sheet-head, .sheet-foot, .sheet-backdrop, .controls .break { display: none; }

/* The Filters button: sits in the control bar, collapses the panel on a
   desktop and opens the sheet on a phone. */
.filters-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: var(--control-h);
    padding: 0 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
}
.filters-toggle:hover { background: var(--surface-2); }
.filters-toggle .chevron { transition: transform 0.15s; }
.filters-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.filters-toggle .count {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
}

@media (max-width: 720px) {
    .filter-label { width: 100%; }
    #transitStyleContainer { padding-left: 0; }
    #transitStyleContainer .transit-note, .filter-row .hint { display: none; }

    /* Stats: one strip that scrolls sideways instead of a 3+2 grid. */
    .stats {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
        scrollbar-width: none;
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    .stats::-webkit-scrollbar { display: none; }
    .stats .stat-card { flex: 0 0 auto; min-width: 7.4rem; padding: 0.45rem 0.7rem; gap: 0.1rem; }
    .stats .stat-card h3 { font-size: 10px; white-space: nowrap; }
    .stats .stat-card .value { font-size: 18px; }

    /* Controls: search + Filters on the first line, view + sort on the second. */
    .controls { padding: 0.5rem 0.6rem; gap: 0.5rem; }
    .controls .search-field { flex: 1 1 10rem; }
    .controls .break { display: block; flex-basis: 100%; height: 0; }
    .controls #sortSelect { flex: 1 1 auto; }
    .controls .fullscreen-btn, .controls .export-btn { display: none; }
    .filters-toggle .chevron { display: none; }

    /* The filters panel becomes a bottom sheet. */
    .filters-panel,
    body:not(.filters-open) .filters-panel {
        display: grid;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1200;
        max-height: 85vh;
        overflow-y: auto;
        padding: 0 1rem calc(0.75rem + env(safe-area-inset-bottom));
        border-radius: 14px 14px 0 0;
        border-bottom: 0;
        box-shadow: var(--shadow-float);
        transform: translateY(105%);
        transition: transform 0.22s ease;
    }
    body.filters-open .filters-panel { transform: none; }
    .sheet-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        margin: 0 -1rem 0.25rem;
        padding: 0.6rem 1rem 0.5rem;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
    }
    .sheet-head::before {
        content: "";
        position: absolute;
        top: 6px;
        left: 50%;
        width: 36px;
        height: 4px;
        margin-left: -18px;
        border-radius: 2px;
        background: var(--border-strong);
    }
    .sheet-title { font-weight: 600; font-size: 15px; padding-top: 0.35rem; }
    .sheet-done { padding-top: 0.35rem; font-weight: 600; color: var(--accent-text); }
    .sheet-foot {
        display: flex;
        justify-content: space-between;
        gap: 0.5rem;
        margin-top: 0.4rem;
        padding-top: 0.6rem;
        border-top: 1px solid var(--border);
    }
    .sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 1100; background: rgba(10, 12, 16, 0.45); }
    .sheet-backdrop[hidden] { display: none; }
}

/* Map + list */
.content {
    overflow: hidden;
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#mapView { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#map { flex: 1; width: 100%; min-height: 200px; background: var(--surface-2); }

.map-container.fullscreen {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border-radius: 0;
    border: 0;
}
.map-container.fullscreen #map { height: 100vh !important; }
.fullscreen-exit-btn {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 10000;
    height: var(--control-h);
    padding: 0 0.9rem;
    background: var(--inverse);
    color: var(--inverse-text);
    border: 0;
    border-radius: var(--radius-sm);
    font-weight: 500;
    box-shadow: var(--shadow-float);
}
.fullscreen-esc-overlay {
    position: fixed;
    bottom: 48px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    padding: 0.6rem 1rem;
    background: rgba(16, 19, 26, 0.85);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 13px;
    transition: opacity 0.5s;
    pointer-events: none;
}
.fullscreen-esc-overlay.fade-out { opacity: 0; }

/* Map pins (Leaflet divIcons; markup built in js/pages/index.js) */
.custom-marker { background: transparent !important; border: none !important; }
.pin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--unknown);
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    box-sizing: border-box;
}
.pin-bar { background: var(--bar); }
.pin-store { background: var(--store); }
.pin-removed { background: var(--removed); }
.pin-unknown { background: var(--unknown); }
.pin-new { box-shadow: 0 0 0 3px var(--new), 0 1px 3px rgba(0, 0, 0, 0.35); }
.pin-highlight { width: 18px; height: 18px; box-shadow: 0 0 0 3px var(--transit), 0 0 12px var(--transit); }
.pin-dim { opacity: 0.3; }

/* Leaflet popups take the theme */
.leaflet-popup-content-wrapper {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-float);
    font-family: var(--font-sans);
}
.leaflet-popup-tip { background: var(--surface); box-shadow: none; border: 1px solid var(--border); }
.leaflet-popup-content { margin: 0.75rem 0.9rem; font-size: 13px; line-height: 1.45; min-width: 220px; }
.leaflet-popup-close-button { color: var(--text-3) !important; }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--text) !important; }
.popup-title { font-weight: 600; font-size: 14px; margin-bottom: 0.35rem; }
.popup-badges { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.45rem; }
.popup-line { color: var(--text-2); }
.popup-links { margin-top: 0.45rem; display: flex; gap: 0.75rem; }
.popup-meta { margin-top: 0.45rem; color: var(--text-3); font-size: 11.5px; }
.popup-meta .removed { color: var(--removed-text); }
.dark-theme .leaflet-bar a { background: var(--surface); color: var(--text); border-bottom-color: var(--border); }
.dark-theme .leaflet-bar a:hover { background: var(--surface-2); }
.dark-theme .leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--text-3); }
.dark-theme .leaflet-control-attribution a { color: var(--text-2); }

/* Legend */
.map-legend {
    position: absolute;
    bottom: 24px;
    left: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-float);
    z-index: 1000;
    min-width: 180px;
    overflow: hidden;
}
.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0.5rem 0.45rem 0.85rem;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
    border-bottom: 1px solid var(--border);
}
.legend-header button {
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-2);
    font-size: 15px;
    line-height: 1;
}
.legend-header button:hover { background: var(--surface-2); color: var(--text); }
.legend-content { padding: 0.5rem 0.85rem 0.6rem; display: grid; gap: 0.3rem; }
.legend-content.collapsed { display: none; }
.legend-item { display: flex; align-items: center; gap: 0.55rem; font-size: 13px; color: var(--text); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-dot.blue { background: var(--bar); }
.legend-dot.green { background: var(--store); }
.legend-dot.red { background: var(--removed); }
.legend-dot.gray { background: var(--unknown); }
.legend-dot.gold { background: var(--new); }

/* List view */
.locations-list { height: 100%; overflow-y: auto; }
.empty-state { padding: 2.5rem 1rem; text-align: center; color: var(--text-2); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent-text); font-weight: 500; text-decoration: underline; }
.location-card {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    display: grid;
    gap: 0.35rem;
}
.location-card:hover { background: var(--surface-2); }
.location-card:last-child { border-bottom: 0; }
.location-card h3 { font-size: 14px; font-weight: 600; }
.location-card .badges { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.location-card p { color: var(--text-2); }
.location-card .links { display: flex; gap: 1rem; font-size: 13px; }
.location-card .meta {
    margin-top: 0.15rem;
    color: var(--text-3);
    font-size: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
}
.location-card .meta .removed { color: var(--removed-text); }

.skeleton-card { padding: 1rem; border-bottom: 1px solid var(--border); }
.skeleton-line {
    height: 0.9rem;
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}
.skeleton-line.title { width: 60%; height: 1.1rem; }
.skeleton-line.short { width: 40%; }
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
