/* popup card: rounded, soft drop shadow, tail kept from Leaflet's .leaflet-popup-tip */
.leaflet-popup {
    font-family: 'Manrope', system-ui, sans-serif;
    color: #17201C;
    filter: drop-shadow(0 10px 28px rgba(23, 32, 28, 0.22));
}

.leaflet-popup-content-wrapper {
    overflow: hidden !important;
    padding: 0;
    border-radius: 22px;
    background: #FFFFFF !important;
    box-shadow: none;
}

.leaflet-popup-content {
    margin: 0;
    width: 300px !important;
    /* the card scrolls instead of growing past the screen, so the parcel under its tip stays in view
       (popup autoPan keeps 90px above it for the top bar) */
    max-height: min(70vh, calc(100vh - 200px));
    max-height: min(70dvh, calc(100dvh - 200px));
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: none;
    background: white;
    font-size: 14px;
    line-height: 1.4;
}

@media only screen and (min-width: 640px) {
    .leaflet-popup-content {
        width: 360px !important;
    }
}

.leaflet-popup-tip {
    box-shadow: none;
}

.leaflet-popup-close-button {
    top: 10px !important;
    right: 10px !important;
    z-index: 2;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 30px !important;
    height: 30px !important;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.94) !important;
    color: #17201C !important;
    font: 400 22px/1 'Manrope', system-ui, sans-serif !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* image note (i) button: same look as the close button, mirrored to the photo's top-left corner */
.popup-info-button {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.94);
    color: #17201C;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

/* inline 360 viewer in the popup photo area: its own stacking context, so the viewer's internal z-indexes
   stay below the full-screen button that sits in the (i) spot (.popup-info-button) */
#popupImage .popup-panorama-viewer {
    position: relative;
    isolation: isolate;
}

.leaflet-popup-close-button span {
    margin-top: -2px;
}

/* photo carousel: arrows at the image edges, pill-shaped active dot (beats the global glider rules in input.css) */
#popupImage .glider-prev {
    left: 10px !important;
}

#popupImage .glider-next {
    right: 10px !important;
}

#popupImage .glider-dot {
    width: 6px !important;
    height: 6px !important;
    margin: 0 2.5px;
    background: rgba(255, 255, 255, 0.6) !important;
}

#popupImage .glider-dot.active {
    width: 18px !important;
    border-radius: 3px;
    background: #FFFFFF !important;
}

#map {
    z-index: 0;
    will-change: transform !important;
}

.leaflet-zoom-animated {
    will-change: transform !important;
}

.leaflet-pane {
    will-change: transform !important;
}

.pointer-events-none {
    pointer-events: none !important;
}

/* --marker-scale is set per zoom by updateMarkersSize (util.js), the transition matches Leaflet's zoom animation */
.marker-icon-div {
    transform: scale(var(--marker-scale, 1));
}

.leaflet-zoom-anim .marker-icon-div {
    transition: transform 0.25s cubic-bezier(0, 0, 0.25, 1);
}

/* toggled by updateLabelsVisibilityForZoom (util.js) */
.labels-hidden .parcel-labels {
    display: none;
}

@media (prefers-color-scheme: dark) {
    body {
        color: white;
        background: white;
    }

    .leaflet-popup-content {
        background: white;
    }
}

.leaflet-control-notifications {
    display: none;
}
/* toggle switches in the map filter sheet */
.map-filter-switch {
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    flex-shrink: 0;
    width: 44px;
    height: 24px;
    border: 0;
    border-radius: 9999px;
    padding: 0;
    background: #d1d5db;
    cursor: pointer;
    transition: background-color 0.15s;
}

.map-filter-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 9999px;
    background: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s;
}

.map-filter-switch:checked,
.map-filter-switch:checked:hover,
.map-filter-switch:checked:focus {
    background: var(--accent);
}

.map-filter-switch:checked::after {
    transform: translateX(20px);
}

.map-filter-switch:focus {
    outline: none;
    box-shadow: none;
}

.map-filter-switch:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* the map filter sheet hides the native scrollbar and draws its own (mapFilterSheet.js), since iOS only shows
   overlay scrollbars while scrolling */
.map-filter-scroll {
    scrollbar-width: none;
    overscroll-behavior: contain;
}

.map-filter-scroll::-webkit-scrollbar {
    display: none;
}

.map-filter-scrollbar {
    position: absolute;
    top: 4px;
    bottom: 8px;
    right: 4px;
    width: 6px;
    border-radius: 9999px;
    background: #f3f4f6;
}

.map-filter-scrollbar-thumb {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    border-radius: 9999px;
    background: #9ca3af;
    cursor: grab;
    touch-action: none;
}

/* wider invisible hit area so the thumb is easy to grab */
.map-filter-scrollbar-thumb::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -8px;
    right: -4px;
}

/* Layers | Pitches tabs in the map filter sheet */
.map-filter-tab {
    flex: 1;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
}

.map-filter-tab[aria-selected="true"] {
    background: white;
    color: #111827;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}


/* ---------------------------------------------------------------------------------------------------------------
   Map page chrome (components/map_sidebar.html + map_controls.html, wired in mapChrome.js).
   Base rules = mobile: only the sidebar's top bar shows, floating over the map. From lg (1024px) the sidebar is a
   320px panel that always holds the filters.
   --------------------------------------------------------------------------------------------------------------- */
.map-layout {
    position: relative;
    display: flex;
    height: 100%;
}

.map-layout [hidden] {
    display: none !important;
}

.map-area {
    position: relative;
    flex: 1;
    min-width: 0;
    height: 100%;
}

.map-sidebar {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 1000;
    pointer-events: none;
}

.map-sidebar-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.map-sidebar-title,
.map-sidebar-filter,
.map-sidebar-toggle {
    display: none;
}

.map-round-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    flex: none;
    border-radius: 9999px;
    background: #FFFFFF;
    color: #17201C;
    box-shadow: 0 4px 16px rgba(23, 32, 28, 0.14);
}

.map-round-button.is-active {
    background: var(--accent);
    color: #FFFFFF;
}

.map-flag {
    border-radius: 9999px;
    object-fit: cover;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
}

.map-menu {
    position: absolute;
    top: 60px;
    left: 0;
    z-index: 10;
    width: 232px;
    padding: 6px;
    border-radius: 20px;
    background: #FFFFFF;
    box-shadow: 0 10px 30px rgba(23, 32, 28, 0.18);
}

.map-search-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    height: 52px;
    padding: 0 8px 0 18px;
    border-radius: 26px;
    background: #FFFFFF;
    box-shadow: 0 4px 16px rgba(23, 32, 28, 0.14);
}

.map-search-pill input::placeholder {
    font-size: 14px;
    font-weight: 500;
    color: #7A847E;
}

/* the native clear button would duplicate ours */
.map-search-pill input::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

.map-search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: 9999px;
    background: #E4E7DF;
    color: #17201C;
}

.map-search-results {
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    max-height: 60vh;
    overflow-y: auto;
    padding: 8px;
    border-radius: 20px;
    background: #FFFFFF;
    box-shadow: 0 8px 28px rgba(23, 32, 28, 0.16);
    pointer-events: auto;
}

.map-search-result {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 56px;
    padding: 6px 12px;
    border-radius: 14px;
    text-align: left;
}

.map-search-result:hover,
.map-search-result:focus-visible {
    background: #F1F3EC;
    outline: none;
}

.map-search-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex: none;
    border-radius: 12px;
    color: #FFFFFF;
    font-size: 12px;
    font-weight: 800;
    overflow: hidden;
}

.map-search-tile img {
    width: 20px;
    height: 20px;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

/* left-middle control stack; the 1px gap over the grey background draws the dividers */
.map-controls {
    position: absolute;
    top: 50%;
    left: 16px;
    z-index: 900;
    display: flex;
    flex-direction: column;
    gap: 1px;
    width: 48px;
    transform: translateY(-50%);
    border-radius: 24px;
    background: #E5E8E0;
    box-shadow: 0 4px 16px rgba(23, 32, 28, 0.14);
    overflow: hidden;
}

.map-ctl {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: #FFFFFF;
    color: #17201C;
}

.map-ctl:hover {
    background: #F1F3EC;
}

.map-ctl[aria-pressed="true"] {
    color: #2F6FDB;
}

.map-ctl-layers.map-filter-active {
    color: var(--accent);
    background: var(--accent-soft);
}

.map-ctl-zoom {
    display: none;
}

/* count of hidden filter items; tapping it shows everything again */
.map-filter-badge {
    position: absolute;
    top: 4px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9999px;
    background: var(--accent);
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

/* navigation mode (navigation.js) hides the chrome, only the route summary stays; the 360 view (panorama.js) hides it too */
.map-layout.is-navigating .map-sidebar,
.map-layout.is-navigating .map-controls,
.map-layout.is-panorama .map-sidebar,
.map-layout.is-panorama .map-controls {
    display: none !important;
}

@media (max-width: 1023px) {
    .map-controls {
        transition: opacity 0.15s ease-out;
    }

    .map-layout.has-popup .map-controls {
        opacity: 0;
        pointer-events: none;
    }
}

/* the locate plugin is only used for its logic, our #map-ctl-locate drives it */
.leaflet-control-locate {
    display: none !important;
}

@media (min-width: 1024px) {
    .map-ctl-zoom {
        display: flex;
    }

    .map-layout .map-sidebar {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        display: flex;
        flex-direction: column;
        width: 320px;
        flex: none;
        height: 100%;
        background: #FFFFFF;
        box-shadow: 4px 0 24px rgba(23, 32, 28, 0.10);
        pointer-events: auto;
        transition: margin-left 0.2s ease-out, box-shadow 0.2s ease-out;
    }

    /* the panel slides out by its own width, so .map-area (flex: 1) takes the space; mapChrome.js calls
       map.invalidateSize() on transitionend. Its content goes invisible once the slide ends, so it can't be tabbed to. */
    .map-layout .map-sidebar > * {
        transition: visibility 0s;
    }

    .map-layout.is-sidebar-hidden .map-sidebar {
        margin-left: -320px;
        box-shadow: none;
    }

    .map-layout.is-sidebar-hidden .map-sidebar > :not(.map-sidebar-toggle) {
        visibility: hidden;
        transition: visibility 0s 0.2s;
    }

    /* hangs off the panel's right edge, so it rides along and ends up at the map's left edge when hidden */
    .map-layout .map-sidebar-toggle {
        position: absolute;
        top: 50%;
        left: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 24px;
        height: 56px;
        transform: translateY(-50%);
        border: 1px solid #E3E6DE;
        border-left: 0;
        border-radius: 0 12px 12px 0;
        background: #FFFFFF;
        color: #17201C;
        box-shadow: 4px 0 12px rgba(23, 32, 28, 0.10);
    }

    .map-layout .map-sidebar-toggle:hover {
        background: #F1F3EC;
    }

    .map-layout .map-sidebar-toggle svg {
        transition: transform 0.2s ease-out;
    }

    .map-layout.is-sidebar-hidden .map-sidebar-toggle svg {
        transform: rotate(180deg);
    }

    /* clear of the sidebar tab, which sits at the map's left edge at the same height */
    .map-layout .map-controls {
        left: 40px;
    }

    .map-layout .map-sidebar-bar {
        padding: 20px 20px 16px;
    }

    .map-layout .map-round-button {
        width: 48px;
        height: 48px;
        border: 1px solid #E3E6DE;
        box-shadow: none;
    }

    .map-layout .map-round-button.is-active {
        border-color: var(--accent);
    }

    .map-layout .map-search-pill {
        height: 48px;
        background: #F3F4EF;
        box-shadow: none;
    }

    .map-layout .map-sidebar-title {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 0 20px 16px;
        border-bottom: 1px solid #EEF0EA;
    }

    .map-layout .map-sidebar-filter {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
    }

    .map-layout .map-search-results {
        top: 84px;
        bottom: 0;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
        padding: 4px 12px;
    }

    /* filters live inline in the panel, so the layers button is mobile only */
    .map-layout .map-ctl-layers {
        display: none;
    }
}

/* map_filter_sheet.html's sheet while it is moved into the panel */
#map-filter-sheet.is-inline {
    flex: 1;
    min-height: 0;
    max-width: none;
    max-height: none !important;
    border-radius: 0;
    box-shadow: none;
}

#map-filter-sheet.is-inline .map-filter-handle,
#map-filter-sheet.is-inline #map-filter-close {
    display: none;
}

#map-filter-sheet.is-inline .map-filter-scroll {
    flex: 1;
}

#map-filter-sheet.is-inline .map-filter-body {
    flex: 1;
}

/* parcel border width, set per zoom by updateParcelStrokeForZoom (util.js); overrides the inline weight */
.leaflet-overlay-pane path.parcel {
    stroke-width: var(--parcel-stroke-width, 1.5);
}

/* parcel whose popup is open (polygon.js), scaled around its own center */
.leaflet-overlay-pane path.background {
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 0.15s ease-out;
}

.leaflet-overlay-pane path.parcel-selected {
    transform: scale(1.12);
}
