:root {
    --sail-store-locator-heading-font: 'Belwe Lt BT Light', serif;
    --sail-store-locator-body-font: 'Open Sans', sans-serif;
    --sail-store-locator-text-color: #000;
    --sail-store-locator-select-color: var(--text-color);
    --sail-store-locator-select-background: #F5DB97;
    --sail-store-locator-option-outline: #F1ECDF;
    --sail-store-locator-store-box-background: #EBF4FB;
    --sail-store-locator-store-box-hover-background: #F1ECDF;
    --sail-store-locator-store-name-color: #484848;
    --sail-store-locator-cta-color: #323232;
    --sail-store-locator-cta-background: #C8E7FF;
    --sail-store-locator-cta-hover-background: #F5DB97;
}
section.store-locator {
    margin-top: 2rem;
    margin-bottom: 2rem;
    font-family: var(--sail-store-locator-heading-font);

    * {
        font-family: inherit;
    }

    .store-locator-wrapper {
        header {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            align-items: center;
            gap: 1rem;
            margin-top: 2rem;
            margin-bottom: 1rem;

            > * {
                margin: 0;
            }

            .store-list-heading {
                font-size: 1.5rem;
                font-weight: 700;
            }

            .last-updated {
                font-size: 1.125rem;
                font-weight: 400;
            }
        }

        form {
            .form-inputs {
                display: grid;
                grid-template-columns: 1fr;
                gap: 1rem;

                @media screen and (min-width: 1300px) {
                    grid-template-columns: repeat(2, 1fr);
                }
            }

            .custom-select input,
            .custom-select .input,
            .product-select select,
            input[type="search"] {
                width: 100%;
                padding: 1rem;
                font-size: 1.125rem;
                font-weight: 700;
                border: 1px solid #000 !important;
                border-radius: 0;
                box-sizing: border-box;
                margin: 0;
                background: #fff;
            }

            .product-select select {
                background-image: url(../images/chevron.svg);
                background-repeat: no-repeat;
                background-position: right 1rem center;
                background-size: 1rem;
                padding-right: 3.5rem;
            }

            .product-selected {
                img {
                    aspect-ratio: 1 / 1;
                    object-fit: contain;
                    max-height: min(525px, 50svh);

                    @media screen and (min-width: 1300px) {
                        max-height: min(225px, 50svh);
                    }
                }
            }

            .search-wrapper {
                position: relative;
                height: max-content;

                input[type="search"] {
                    padding-right: 3.8em; /* Space for icons */
                }

                svg {
                    height: 1.25rem; /* 20px */
                    width: 1.25rem; /* 20px */
                    position: absolute;
                    top: 50%;
                    translate: 0 -50%;
                    cursor: pointer;
                    transition: background-color 0.2s, color 0.2s;
                    border-radius: 0.25rem;

                    &.geo-icon {
                        height: 1.25rem; /* 20px */
                        width: 1.25rem; /* 20px */
                        right: 2.5rem; /* 40px from the right */
                        color: #4a5568; /* Default icon color */
                    }

                    &.search-icon {
                        right: 1rem; /* 16px from the right */
                        color: #718096; /* Search icon color */
                    }

                    &.active {
                        background-color: #38a169; /* Green background */
                        color: white; /* White icon */
                    }
                }
            }

            .custom-select {
                position: relative;
                user-select: none;
                cursor: default;
                position: relative;
                height: max-content;

                input,
                .input {
                    user-select: none;
                    cursor: pointer;
                    line-height: initial;
                }

                &::after {
                    content: '';
                    position: absolute;
                    top: 50%;
                    translate: 0 -50%;
                    right: 1rem;
                    width: 1rem;
                    height: 1rem;
                    pointer-events: none;
                    background-image: url(../images/chevron.svg);
                    background-repeat: no-repeat;
                    background-position: center;
                    background-size: 1rem;
                    transition: rotate 0.2s;
                }

                &.open {
                    &::after {
                        rotate: 180deg;
                    }
                }

                .custom-select-overlay {
                    position: absolute;
                    top: 100%;
                    top: calc(100% - 1px); /* To cover bottom border of input */
                    left: 0;
                    width: 100%;
                    max-height: 300px;
                    max-height: clamp(200px, 80svh, 600px);
                    overflow-y: auto;
                    background: #fff;
                    border: 1px solid #000;
                    border-top: none;
                    z-index: 3000;
                    display: none;
                    scrollbar-width: thin;
                    scrollbar-color: var(--sail-store-locator-select-background) #F1ECDF;
                    scrollbar-gutter: stable;

                    &::-webkit-scrollbar {
                        width: 8px;
                    }

                    &::-webkit-scrollbar-track {
                        background: #F1ECDF;
                    }

                    &::-webkit-scrollbar-thumb {
                        background-color: var(--sail-store-locator-select-background);
                        border-radius: 4px;
                    }

                    &.open {
                        display: block;
                    }

                    ul {
                        &::before {
                            content: '';
                            display: block;
                            height: 1px;
                            width: 100%;
                            background: #000;
                            margin-top: -1rem;
                        }

                        display: flex;
                        flex-direction: column;
                        padding: 1rem !important;
                        list-style: none;
                        gap: 0.25rem;

                        li {
                            font-size: 1rem;
                            line-height: normal;
                            padding: 0.5rem;
                            cursor: pointer;

                            &:hover {
                                background-color: var(--sail-store-locator-store-box-background);
                            }
                        }
                    }
                }
            }

            &.has-products {
                @media screen and (min-width: 1300px) {
                    display: grid;
                    grid-template-columns: repeat(4, 1fr);
                    gap: 2rem;

                    .form-inputs {
                        grid-column: span 4;
                    }

                    .store-filter {
                        grid-column: span 3;
                        justify-content: center;

                        header {
                            margin-top: 0;
                        }
                    }
                }
            }
        }
    }

    h2 {
        font-size: 3.125rem;
        margin-bottom: 1.5rem;
    }

    select[data-store-products] {
        width: 100%;
        min-width: max-content;
        max-width: max-content;
        padding: 0.5rem;
        font-size: 1rem;
        border: 1px solid #ccc;
        border-radius: 4px;
        box-sizing: border-box;
        margin-bottom: 1rem;
        background: #fff;
        padding-right: 2.5em; /* Space for dropdown arrow */
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='gray'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.75rem center;
        background-size: 1rem;
    }

    #store-locator {
        &.loading {
            opacity: 0.75;
            pointer-events: none;
            cursor: wait;
        }
    }

    form {
        display: flex;
        flex-direction: column;
        flex: 1 1 0%;
        gap: 1rem;
        background-color: #daeaf6;
        padding: 1rem;
        border-radius: 0.5rem;
        color: #000;

        .store-filter {
            display: flex;
            flex-direction: column;

            h4 {
                margin: 0;
                font-size: 1.5rem;
                font-weight: 700;
            }

            p {
                margin: 0;
                font-size: 0.875rem;
                color: #4a5568;
            }
        }

        input:checked + label {
            background-color: var(--sail-store-locator-select-background);
            border-color: var(--sail-store-locator-select-background);
        }

        ul {
            list-style: none;
            padding: 0 !important;
            margin: 0 !important;
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            gap: 0.5rem;

            li {
                display: flex;
                flex-direction: row;
                align-items: center;

                label {
                    margin: 0;
                    font-size: 1rem;
                    line-height: 1.4;
                    cursor: pointer;
                    color: var(--sail-store-locator-select-color, #000);
                    background: var(--sail-store-locator-option-background, #fff);
                    padding: 0.5rem;
                    border: 1px solid var(--sail-store-locator-option-outline, #ccc);
                }
            }
        }
    }

    .store-results {
        ul {
            padding: 0.5rem !important;
            border: 1px solid #000;
            margin: 0 !important;
            max-height: clamp(200px, 80svh, 600px);
            overflow-y: auto;
            scrollbar-width: thin;
            scrollbar-color: var(--sail-store-locator-select-background) #F1ECDF;
            scrollbar-gutter: stable;

            &::-webkit-scrollbar {
                width: 8px;
            }

            &::-webkit-scrollbar-track {
                background: #F1ECDF;
            }

            &::-webkit-scrollbar-thumb {
                background-color: var(--sail-store-locator-select-background);
                border-radius: 4px;
            }
        }

        li {
            list-style: none;
            padding: 0.75rem 0;
            margin: 0;
            display: flex;
            flex-direction: row;
            gap: 0.5rem;
            justify-content: space-between;
            align-items: start;
            border-bottom: 1px solid rgba(255, 255, 255, 0.05);
            /* word-break: break-all; */
            max-width: 100%;
            overflow-wrap: break-word;

            .item-info {
                flex: 1;
                display: flex;
                flex-direction: column;
                gap: 0.25rem;
            }

            h3 {
                margin: 0;
                font-size: 1.25rem;
                font-weight: 500;
                color: #2d3748;
                text-transform: capitalize;
            }

            .address {
                font-family: var(--sail-store-locator-body-font);
                font-size: 0.8125rem;
                line-height: 1.4;
            }

            .map-link {
                font-family: var(--sail-store-locator-body-font);
                font-size: 0.8125rem;
                line-height: 1.4;
            }

            p {
                margin: 0;
                font-size: 1rem;
                color: #4a5568;
                line-height: 1.4;
                text-transform: capitalize;
            }
        }
    }
    
    .hidden {
        display: none;
    }
    

    &.list {
        .store-locator-wrapper {
            padding: 1rem;
            border-radius: 0.5rem;
            background-color: #ebf5fc;

            .last-updated {
                margin: 0;
                font-size: 0.875rem;
                color: #616d82;
                text-align: right;
            }

            #store-locator {
                gap: 1rem;
                display: grid;

                @media screen and (min-width: 1080px) {
                    grid-template-columns: repeat(2, 1fr);
                }
            }

            form {
                &.has-products {
                    display: flex;
                    flex-direction: column;
                }

                .form-inputs {
                    @media screen and (min-width: 1300px) {
                        grid-template-columns: 1fr;
                    }
                }
            }
            

            .store-results {
                li.store-card {
                    a {
                        font-size: 0.85rem;
                        color: #3182ce;
                        text-decoration: none;
                        font-weight: 500;

                        &:hover {
                            text-decoration: underline;
                        }
                    }
                }
            }
        }
    }

    &.grid {
        .store-locator-wrapper {
            header {
                display: flex;
                flex-wrap: wrap;
                justify-content: space-between;
                align-items: center;
                gap: 1rem;
                margin-bottom: 1rem;

                > * {
                    margin: 0;
                }
            }

            form {
                background-color: unset;
                padding: 0;
            }

            .store-results {
                ul {
                    display: grid;
                    gap: 1rem;
                    grid-template-columns: 1fr;

                    @media screen and (min-width: 640px) {
                        grid-template-columns: repeat(2, 1fr);
                    }

                    @media screen and (min-width: 1080px) {
                        grid-template-columns: repeat(3, 1fr);
                    }

                    @media screen and (min-width: 1440px) {
                        grid-template-columns: repeat(4, 1fr);
                    }
                }

                li.store-card {
                    padding: 1rem;
                    background-color: var(--sail-store-locator-store-box-background);
                    color: #323232;
                    font-weight: 400;
                    line-height: 1.4;
                    display: flex;
                    flex-direction: column;
                    overflow-wrap: anywhere;

                    .store-name {
                        color: var(--sail-store-locator-store-name-color);
                        font-weight: 700;
                        font-size: 1.125rem;
                    }

                    .address {
                        color: var(--sail-store-locator-cta-color);
                    }

                    .map-link {
                        font-size: 0.8125rem;
                        margin-top: 1rem;
                        padding: 0.5rem 0.75rem;
                        background-color: var(--sail-store-locator-cta-background);
                        color: var(--sail-store-locator-cta-color);
                        display: flex;
                        flex-direction: row;
                        gap: 0.5rem;
                        align-items: center;

                        &::after {
                            content: '';
                            display: inline-flex;
                            height: 1.125rem;
                            width: 1.125rem;
                            background-image: url(../images/external-link.svg);
                        }

                        &:focus,
                        &:active,
                        &:hover {
                            background-color: var(--sail-store-locator-cta-hover-background);
                        }
                    }

                    &:hover {
                        background-color: var(--sail-store-locator-store-box-hover-background);
                    }
                }
            }
        }
    }

    form,
    .store-results {
        position: relative;

        .loading-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.7);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 100;
            cursor: wait;

            .spinner {
                border: 0.25rem solid rgba(0, 0, 0, 0.1);
                border-left-color: #000;
                border-radius: 50%;
                width: 2.7rem;
                height: 2.7rem;
                animation: spin 1.7s linear infinite;
            }
        }
    }
}