/* CSS Variables for customizable colors */
:root {
    --bsearch-dropdown-bg: #fefefe;
    --bsearch-dropdown-border: #ccc;
    --bsearch-dropdown-shadow: rgba(0, 0, 0, 0.1);
    --bsearch-item-border: #eee;
    --bsearch-item-hover-bg: #f0f0f0;
    --bsearch-item-focus-outline: #2271b1;
    --bsearch-link-color: #333;
    --bsearch-link-focus-bg: #e8f0fe;
    --bsearch-scrollbar-track: #f0f0f0;
    --bsearch-scrollbar-thumb: #2271b1;
}

/* Only apply positioning to forms that have Better Search autocomplete - exclude Max Mega Menu */
.search-form:has(.bsearch-autocomplete-results),
form[role="search"]:has(.bsearch-autocomplete-results),
.search-form.bsearch-enabled,
form[role="search"].bsearch-enabled {
    position: relative;
}

/* Visually hidden element for screen readers */
.bsearch-visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

div.bsearch-autocomplete-results {
    display: none;
    position: absolute;
    z-index: 1000;
    background: var(--bsearch-dropdown-bg);
    border: 1px solid var(--bsearch-dropdown-border);
    border-radius: 4px;
    box-shadow: 0 4px 6px var(--bsearch-dropdown-shadow);
    max-height: 200px;
    overflow-y: auto;
    width: 100%;
    top: 100%;
    left: 0;
    margin-top: 4px;
}

div.bsearch-autocomplete-results ul,
div.bsearch-autocomplete-results > ul,
div.bsearch-autocomplete-results ul.bsearch-results-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    position: static !important;
    width: 100% !important;
}

div.bsearch-autocomplete-results ul li,
div.bsearch-autocomplete-results > ul > li,
div.bsearch-autocomplete-results ul.bsearch-results-list li {
    display: flex;
    margin: 0 !important;
    align-items: center;
    padding: 0;
    border-bottom: 1px solid var(--bsearch-item-border);
    cursor: pointer;
    position: static !important;
    width: 100% !important;
}

div.bsearch-autocomplete-results ul li:last-child,
div.bsearch-autocomplete-results > ul > li:last-child,
div.bsearch-autocomplete-results ul.bsearch-results-list li:last-child {
    border-bottom: none;
}

div.bsearch-autocomplete-results ul li.selected,
div.bsearch-autocomplete-results ul li:hover,
div.bsearch-autocomplete-results ul li.bsearch-selected,
div.bsearch-autocomplete-results > ul > li:hover,
div.bsearch-autocomplete-results ul.bsearch-results-list li:hover {
    background-color: var(--bsearch-item-hover-bg);
}

div.bsearch-autocomplete-results ul li:focus-within,
div.bsearch-autocomplete-results ul li.bsearch-selected,
div.bsearch-autocomplete-results > ul > li:focus-within,
div.bsearch-autocomplete-results ul.bsearch-results-list li:focus-within {
    outline: 2px solid var(--bsearch-item-focus-outline);
    outline-offset: -2px;
}

html body div.bsearch-autocomplete-results ul li a,
html body div.bsearch-autocomplete-results > ul > li > a,
div.bsearch-autocomplete-results ul.bsearch-results-list li a,
div.bsearch-autocomplete-results ul li.bsearch-result a,
div.bsearch-autocomplete-results ul li a.bsearch-result-link {
    display: block;
    width: 100%;
    padding: 5px 10px;
    text-align: left;
    text-decoration: none;
    color: var(--bsearch-link-color);
    line-height: 1.4;
    transition: all 0.2s ease;
    position: static;
}

/* Focus styles for input */
.search-form input[type="search"]:focus,
form[role="search"] input[type="search"]:focus {
    outline: none;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #2271b1;
    border-color: #2271b1;
}

/* Focus styles for submit button */
.search-form input[type="submit"]:focus,
.search-form button[type="submit"]:focus,
form[role="search"] input[type="submit"]:focus,
form[role="search"] button[type="submit"]:focus {
    outline: none;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #2271b1;
    border-color: #2271b1;
}

/* Focus styles for result links */
html body div.bsearch-autocomplete-results ul li a:focus,
html body div.bsearch-autocomplete-results > ul > li > a:focus,
html body div.bsearch-autocomplete-results ul.bsearch-results-list li a:focus {
    outline: none;
    background-color: var(--bsearch-link-focus-bg);
    box-shadow: inset 0 0 0 2px var(--bsearch-item-focus-outline);
    color: var(--bsearch-link-color);
}

/* Selected state combined with focus */
html body div.bsearch-autocomplete-results ul li.selected a:focus,
html body div.bsearch-autocomplete-results > ul > li.selected > a:focus,
html body div.bsearch-autocomplete-results ul.bsearch-results-list li.selected a:focus {
    background-color: var(--bsearch-link-focus-bg);
    box-shadow: inset 0 0 0 2px var(--bsearch-item-focus-outline);
}

/* High contrast mode support */
@media (forced-colors: active) {

    div.bsearch-autocomplete-results ul li.selected,
    div.bsearch-autocomplete-results ul li a:focus,
    div.bsearch-autocomplete-results > ul > li > a:focus,
    div.bsearch-autocomplete-results ul.bsearch-results-list li a:focus {
        outline: 2px solid CanvasText;
        outline-offset: -2px;
    }
}

/* Ensure scrollbar is visible and styled */
div.bsearch-autocomplete-results {
    scrollbar-width: thin;
    scrollbar-color: #2271b1 #f0f0f0;
}

div.bsearch-autocomplete-results::-webkit-scrollbar {
    width: 8px;
}

div.bsearch-autocomplete-results::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 4px;
}

div.bsearch-autocomplete-results::-webkit-scrollbar-thumb {
    background-color: #2271b1;
    border-radius: 4px;
    border: 2px solid #f0f0f0;
}

@media (max-width: 600px) {
    div.bsearch-autocomplete-results {
        width: 100%;
        max-height: 150px;
        margin-top: 2px;
    }

    html body div.bsearch-autocomplete-results ul li a,
    html body div.bsearch-autocomplete-results > ul > li > a,
    html body div.bsearch-autocomplete-results ul.bsearch-results-list li a {
        padding: 10px 12px;
    }
}