/* Indented off the results column it sits beside. */
#searchFiltersSidebar {
    padding-left: 60px;
    margin-left: 50px;
}

/* Follows the results down the page. The aside it sits in is a flex item stretched to the row's
   height, which is set by the taller results column, so there is room inside it to travel.
   Only from lg up: below that the sidebar is a band above the results, with nothing to track. */
@media (min-width: 992px) {
    #searchFiltersSidebar {
        position: sticky;
        /*  The search bar pins itself to the top of the viewport as the page scrolls and publishes
            its height on the root - stickySearchBar.js - so the filters come to rest below it
            rather than behind it. 0px while the bar is in the flow, where the page starts. */
        top: calc(var(--stuckSearchBarHeight, 0px) + 16px);
        /* The filters run taller than a short viewport, and sticky pins the top edge: without a
           height of its own everything past the fold stays there for the whole of the stuck phase,
           surfacing only once the row's bottom is reached and the panel stops sticking.
           This is what makes the filters' scroll area a clipping parent, which is why the categories picker is
           taken off Popper - see the note on its toggle.

           filtersSidebarHeight.js measures the room actually left below the rail and publishes it
           here, so the cap is right on the way down as well as once the rail has pinned, and the
           rail grows into the space the header gives up. The fallback is the pinned figure, which
           is where the measured one settles. */
        max-height: var(--filtersRailMaxHeight, calc(100vh - var(--stuckSearchBarHeight, 0px) - 32px));
        /* The rail itself never scrolls: the header keeps its height and the filters below take
           whatever is left, scrolling inside it, so the count and Clear All stay in view. */
        display: flex;
        flex-direction: column;
    }

    #searchFiltersSidebar .filtersSidebarHeader {
        flex-shrink: 0;
    }

    #searchFiltersScrollArea {
        /* min-height: 0 lets the flex item shrink below its content, which is what gives it
           something to overflow. */
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        scrollbar-gutter: stable;
        /* Keeps the labels off the scrollbar that appears once the filters outgrow the cap. */
        padding-right: 8px;
        /* So the last filter clears the clipping edge rather than ending flush against it. */
        padding-bottom: 16px;
    }

    /* The scrollbar is a hint, not part of the panel: it fades in on hover and stays out of the
       way otherwise. Only the thumb's colour changes, never the track's width, so revealing it
       cannot reflow the filters. Firefox takes the two-value form; WebKit needs the pseudos. */
    #searchFiltersScrollArea {
        scrollbar-width: thin;
        scrollbar-color: transparent transparent;
    }

    /* focus-within so the cue is there for anyone tabbing through the filters rather than hovering. */
    #searchFiltersScrollArea:hover,
    #searchFiltersScrollArea:focus-within {
        scrollbar-color: rgba(0, 0, 0, .18) transparent;
    }

    #searchFiltersScrollArea::-webkit-scrollbar {
        width: 6px;
    }

    #searchFiltersScrollArea::-webkit-scrollbar-track {
        background: transparent;
    }

    #searchFiltersScrollArea::-webkit-scrollbar-thumb {
        background-color: transparent;
        border-radius: 3px;
        transition: background-color .2s ease;
    }

    #searchFiltersScrollArea:hover::-webkit-scrollbar-thumb,
    #searchFiltersScrollArea:focus-within::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, .18);
    }
}

/* Below lg the sidebar is a full width band above the results, where the desktop indent would
   push it off centre. */
@media (max-width: 991px) {
    #searchFiltersSidebar {
        padding-left: 0;
        margin-left: auto;
        margin-right: auto;
        max-width: 500px;
    }
}

/* The fieldset is only there to carry the disabled state, so it drops the chrome a fieldset comes
   with. min-inline-size would otherwise stop the sections narrowing with the sidebar. */
#searchFiltersSidebar .filterSections {
    margin: 0;
    padding: 0;
    border: 0;
    min-inline-size: 0;
}

.filterSection {
    padding: 8px 8px;
}

/* The sections get room either side of their rules; the Filters heading row above them keeps the base padding. */
.filterSection + .filterSection {
    padding-top: 30px;
    padding-bottom: 30px;
}

.filterSection h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.filterSection h2 {
    font-size: 20px;
    font-weight: 600;
}

#clearAllFilters {
    color: #d34545;
    font-size: 12px;
    font-weight: 600;
}

#clearAllFilters span {
    text-decoration: underline;
}

.filterSection a,
.filterSection a:hover {
    color: inherit;
}

.filterSection .filterOptions {
    margin-top: 8px;
}

/* The section heading is the collapse toggle, so the button is styled back down to a plain header row. */
.filterSection .filterSectionToggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    text-align: left;
}

.filterSection .filterSectionToggle i {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--theme-text-grey);
    transition: transform .2s ease-in-out;
}

/* Bootstrap puts .collapsed on the toggle whenever its panel is closed. */
.filterSection .filterSectionToggle.collapsed i {
    transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
    .filterSection .filterSectionToggle i {
        transition: none;
    }
}

/* The map is sized by the sidebar column, and capped so it can't crowd out the filters below. */
#opportunityMapContainer {
    display: flex;
    justify-content: center;
}

#opportunityMap {
    width: 100%;
    height: auto;
    max-height: clamp(185px, 21vh, 380px);
}

/* Regions with a checkbox behind them toggle it when clicked; the rest are just map. */
#opportunityMap .mapRegion.selectable {
    cursor: pointer;
}

/* Dim rather than recolour, so the cue reads the same over a selected region and an unselected
   one. ".hover" is the proxy set from the matching checkbox row. */
@media (hover: hover) {
    #opportunityMap .mapRegion.selectable:hover,
    #opportunityMap .mapRegion.selectable.hover {
        fill-opacity: 0.6;
    }
}

/* Remove any outline when clicking on the map element */
#opportunityMap:focus:not(:focus-visible),
#opportunityMap *:focus:not(:focus-visible) {
    outline: none;
}

/* The other half of the cross-highlight: the row lights up when its region is hovered. */
#regionFilter .form-check.hover .form-check-label {
    color: #EB0E8C;
}

#opportunityTypeFilter,
#regionFilter {
    container-type: inline-size;
}

/* opportunity types are a 2x2 grid filling top to bottom then across; regions read across. */
#regionFilter .filterOptions, #opportunityTypeFilter .filterOptions {
    display: grid;
    row-gap: 8px;
}

#regionFilter .filterOptions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 12px;
}

/* One column by default, so narrow sidebars don't wrap the longer labels mid-row. */
#opportunityTypeFilter .filterOptions {
    grid-template-columns: 1fr;
}

@container (min-width: 300px) {
    #opportunityTypeFilter .filterOptions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 12px;
        grid-template-rows: repeat(2, auto);
        grid-auto-flow: column;
    }
}

#opportunityTypeFilter .filterOptions .form-check,
#regionFilter .filterOptions .form-check {
    margin-bottom: 0;
}

/* Sit the label directly beside the checkbox instead of Bootstrap's indented block layout. */
.filterSection .form-check {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    padding-left: 0;
}

.filterSection .form-check-label {
    font-size: 14px;
    cursor: pointer;
}

.filterSection .form-check-input {
    margin-left: 0;
    margin-top: 0;
    flex-shrink: 0;
    border-color: #19ACEE;
    border-radius: .15em;
    cursor: pointer;
}

.filterSection .form-check-input:checked {
    background-color: #19ACEE;
    border-color: #19ACEE;
}

/* Status filter: the state radios, then the date range that applies to the chosen state. */
#statusFilter .form-check-input[type="radio"] {
    border-radius: 50%;
}

#statusFilter .dateRangeLabel {
    margin: 10px 0 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--theme-text-grey);
}

#statusFilter .dateChips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#statusFilter .dateChip {
    padding: 7px 14px;
    border: 1px solid #19ACEE;
    border-radius: 999px;
    background-color: transparent;
    font-size: 13px;
    line-height: 1.2;
}

#statusFilter .dateChip.active {
    background-color: #CCEEFB;
}

/* The custom range: a "From" row above a "To" row, the labels sharing a column so the fields line up. */
#statusFilter .dateRangeInputs {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px 10px;
    margin-top: 12px;
}

#statusFilter .dateRangeFieldLabel {
    font-size: 13px;
    font-weight: 600;
    color: var(--theme-text-grey);
}

#statusFilter .dateRangeControl {
    position: relative;
    min-width: 0;
}

/* style.css sizes every bare text input (16px, line-height 2.3, grey focus fill), so each of those is reset here. */
#statusFilter .dateRangeControl .form-control {
    width: 100%;
    height: auto;
    padding: 8px 34px 8px 12px;
    border: 1px solid #CED4DA;
    border-radius: 8px;
    background-color: #fff;
    color: #414042;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.4;
}

#statusFilter .dateRangeControl .form-control:focus {
    border-color: #19ACEE;
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(25, 172, 238, .2);
}

#statusFilter .dateRangeControl .form-control::placeholder {
    color: #ADB5BD;
}

/* Decoration only: clicks fall through to the input, which is what opens the picker. */
#statusFilter .dateRangeControl i {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    color: #19ACEE;
    font-size: 13px;
    pointer-events: none;
}

/* The date panels toggle on the hidden attribute, which the display rules above would otherwise win against. */
#statusFilter [hidden] {
    display: none !important;
}

/* Categories: a select-styled picker, with whatever it holds listed as pills underneath. */
#categoriesFilter .categorySelect {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    margin-top: 10px;
    padding: 9px 14px;
    border: 1px solid #CED4DA;
    border-radius: 8px;
    background-color: #fff;
    color: var(--theme-text-grey);
    font-size: 14px;
    line-height: 1.4;
    text-align: left;
}

#categoriesFilter .categorySelect i {
    flex-shrink: 0;
    font-size: 12px;
}

#categoriesFilter #classificationDropdownList {
    width: 100%;
}

/* The search bar's copy of this panel is capped by tenderSearchBarV3.css, which is scoped to
   #tenderSearchBar. The sidebar's copy needs its own cap or the tree runs off the page. */
#categoriesFilter #classificationDropdownList #hierarchy {
    max-height: min(400px, 50vh);
    overflow-y: auto;
}

#categoriesFilter .categoryPills {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 10px 0 0;
    padding: 0;
    list-style: none;
}

#categoriesFilter .categoryPill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 14px;
    border: 1px solid #19ACEE;
    border-radius: 999px;
    background-color: #CCEEFB;
    font-size: 13px;
}

/* Category names run long, so a pill keeps to one line and the full name goes in the tooltip. */
#categoriesFilter .categoryPillLabel {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#categoriesFilter .categoryPillRemove {
    flex-shrink: 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    line-height: 1;
}

/* The panel already starts level with the results column, so no lead-in padding above the count. */
.filterTenderCountDisplay {
    font-size: 20px;
    margin-bottom: 0;
    padding: 0 0 0 8px;
    font-weight: 500;
}
