:root {
    --primary-color: #0067ae;
    --white: #fff;
}

/* SearchBar */
.pac-container {
    z-index: 999999 !important;
}

.csn-location-search {
    background-color: var(--primary-color);
    padding: 1rem;

    label {
        color: var(--white);
        font-size: 1.2rem;
        font-weight: bold;
        margin-left: 2px;
    }

    input {
        background-color: var(--white);
        margin-top: 0.5rem;
        border-radius: 5px;
        padding-right: 7rem;
        height: 3rem;
        box-shadow: 0px 4px 4px 0px #00000040;
        font-size: 0.7rem;
    }

    input,
    input:hover,
    input:focus,
    input:active {
        border: 1px solid var(--input-border) !important;
        outline: none;
        box-shadow: none;
    }

    input:focus-visible {
        outline: 2px solid var(--input-border);
        outline-offset: 2px;
    }

    .csn-location-search__btn {
        position: absolute;
        right: 0.15rem;
        top: 57%;
        transform: translateY(-50%);
        height: calc(3rem - 0.3rem);
        padding: 0 1rem;

        background-color: var(--primary-color);
        border-radius: 5px;
        color: var(--white);
        font-size: 1.2rem;
        font-weight: bold;
        border: 0;
        cursor: pointer;
        z-index: 1000001;
    }

    .csn-location-search__field {
        position: relative;
        z-index: 1000000;
    }
}

.csn-location-search[data-ajax="0"] {
    /* ajax=0 means only search bar, not results page */
    background-color: unset;
    padding: 0;

    label {
        color: #434343;
    }

    input {
        margin-top: 0;
    }

    .csn-location-search__btn {
        top: 50%;
    }
}

/* ---------- Original LocationResults (merged) ---------- */

/* Note: mobile-first responsive rules follow below */
.csn-find-location-wrapper {
    /* default mobile-first values overwritten for desktop in media query */
    display: flex;
    flex-direction: column;
    height: auto; /* let content size on small screens */
    padding: 1rem 0;

    > * {
        min-height: 0;
        min-width: 0;
    }

    .csn-find-location-search-results-wrapper {
        width: 100%;
        margin: 0 0 1rem 0;

        #csn-location-results {
            max-height: calc(
                var(--csn-result-item-height, 88px) * 3 + 1.5rem
            ); /* fallback; overridden by responsive block below */
            overflow-y: auto;
            overflow-x: hidden;
            -webkit-overflow-scrolling: touch;

            ul {
                list-style: none;
                padding-left: 0;

                li {
                    /* original item styles are preserved; sizing reset later to allow natural height */
                    border: 1px solid #aaaaaa20;
                    box-shadow: 0px 4px 4px 0px #00000040;
                    padding: 1rem;
                    margin-bottom: 0.75rem;

                    .csn-result-title {
                        display: flex;

                        small {
                            margin-left: auto;
                        }

                        a {
                            font-weight: bold;
                        }

                        a:link,
                        a:visited,
                        a:hover,
                        a:active {
                            color: var(--primary-color);
                        }
                    }

                    .csn-loc-street,
                    .csn-loc-cityline {
                        font-size: 0.75rem;
                        color: #666;
                    }

                    .csn-loc-cityline {
                        line-height: 1;
                    }

                    .csn-result-links {
                        margin-top: 1.5rem;
                        display: flex;
                        font-size: 0.8rem;
                        justify-content: space-between;

                        a:link,
                        a:visited,
                        a:hover,
                        a:active {
                            color: #000;
                            text-decoration: underline solid #000 1px;
                        }
                    }
                } /* end li */
            } /* end ul */
        } /* end #csn-location-results */
    } /* end .csn-find-location-search-results-wrapper */

    #csn-location-map {
        /* mobile default; desktop overwritten in media query */
        width: 100%;
        min-height: 300px; /* adjust as desired for mobile */
        height: 300px;
        margin-bottom: 1rem;
        position: relative; /* required for overlay */
        overflow: hidden;
    }
} /* end .csn-find-location-wrapper */

.csn-location-list li.is-hovered,
.csn-location-list li.is-selected {
    background-color: var(--primary-color);
    color: var(--white);

    .csn-result-title {
        a:link,
        a:visited,
        a:hover,
        a:active {
            color: var(--white) !important;
        }
    }

    .csn-loc-street,
    .csn-loc-cityline {
        color: var(--white) !important;
    }

    .csn-gstars__fg use {
        fill: var(--white);
    }

    .csn-result-links {
        a:link,
        a:visited,
        a:hover,
        a:active {
            color: var(--white) !important;
            text-decoration-color: var(--white) !important;
        }
    }
}

/* Map loading overlay (kept from original) */
#csn-location-map.is-loading::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.6);
    z-index: 2;
}

#csn-location-map.is-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    border: 4px solid rgba(0, 0, 0, 0.15);
    border-top-color: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    animation: csnSpin 0.8s linear infinite;
    z-index: 3;
}

@keyframes csnSpin {
    to {
        transform: rotate(360deg);
    }
}

/* ---------- Responsive fixes (mobile-first) ---------- */

/* Autocomplete z-index reinforcement */
.pac-container {
    z-index: 999999 !important;
}

/* Keep search field stacking and button z-order stable */
.csn-location-search__field {
    position: relative;
    z-index: 10;
}
.csn-location-search__btn {
    z-index: 11;
    position: absolute;
}

/* Ensure list items size to content and nested elements don't overflow */
.csn-location-list {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.csn-location-list li {
    box-sizing: border-box;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    display: block;
    border: 1px solid #aaaaaa20;
    box-shadow: 0px 4px 4px 0px #00000040;
    padding: 1rem;
    margin: 0 0 0.75rem 0;
}

/* Apply consistent box-sizing to children */
.csn-location-list li *,
.csn-location-list * {
    box-sizing: border-box;
}

/* Results: scrollable area showing approximately 3 items on mobile */
#csn-location-results {
    order: 1;
    max-height: calc((var(--csn-result-item-min, 96px) * 3) + 1.5rem);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Ensure map flows after the results on small screens (search wrapper contains search+results) */
#csn-location-map {
    order: 2;
    width: 100%;
    height: 320px;
    min-height: 320px;
    margin: 0 0 1rem 0;
    position: relative;
    overflow: hidden;
}

/* Keep inner result layout */
.csn-result-title {
    display: flex;
    align-items: center;
}
.csn-result-title small {
    margin-left: auto;
}
.csn-loc-street,
.csn-loc-cityline {
    font-size: 0.75rem;
    color: #666;
    line-height: 1;
}
.csn-result-links {
    margin-top: 1.5rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
}

/* ---------- Desktop / large screens ---------- */
@media (min-width: 900px) {
    /* ensure wrapper is a flex row and has an explicit height */
    .csn-find-location-wrapper {
        display: flex;
        flex-direction: row;
        height: 600px; /* or use 70vh if you prefer */
        align-items: stretch; /* force children to fill height */
    }

    /* left column: search + results */
    .csn-find-location-search-results-wrapper {
        width: 40% !important;
        min-width: 320px;
        margin-right: 1rem !important;
        display: flex;
        flex-direction: column;
        height: 100%; /* fill wrapper height */
    }

    /* keep search at natural height */
    .csn-location-search {
        flex: 0 0 auto;

        input {
            font-size: 1rem;
        }
    }

    /* results area grows and may scroll; allow it to shrink with min-height:0 */
    #csn-location-results {
        flex: 1 1 auto;
        min-height: 482px; /* critical: allows flex child to shrink and enable scrolling */
        overflow-y: auto;
    }

    /* ensure list itself doesn't force extra height */
    .csn-location-list {
        margin: 0;
        padding: 0;
    }

    /* list items size naturally */
    .csn-location-list li {
        height: auto;
        min-height: 0;
        max-height: none;
    }

    /* right column: map - use flex so it fills remaining width and full height */
    #csn-location-map {
        flex: 1 1 60%;
        min-width: 0; /* critical for flex item to allow shrinking horizontally */
        height: 600px !important;
        min-height: 0;
        position: relative;
        overflow: hidden;
    }
}

/* Keep pac-container z-index intact if other rules loaded later */
.pac-container {
    z-index: 999999 !important;
}
