/* Search styling — ElasticPress Autosuggest (offcanvas quick search) + Facets (results sidebar) */
#search-autocomplete-offcanvas {
    width: 75%;
    max-width: 1000px;
}

@media(max-width: 992px) {
    #search-autocomplete-offcanvas {
        width: 100%;
    }
}

/* Search bar in the offcanvas needs breathing room below it before results */
#search-autocomplete-offcanvas .search-form,
#search-autocomplete-offcanvas .search-field {
    margin-bottom: 1rem;
}

/* Autosuggest dropdown, injected by ElasticPress after the .search-field input */
#search-autocomplete-offcanvas .ep-autosuggest-container {
    padding-top: 10px;
}

#search-autocomplete-offcanvas .ep-autosuggest {
    position: relative;
    background: #fff;
}

/* Unscoped (not offcanvas-only) - the results-page revise-search dropdown
   uses the same .autosuggest-list/.autosuggest-item/.ai-ep-show-all markup,
   including its own "Show all results" link (the listHTML filter that
   appends it isn't scoped to any one input). */
.autosuggest-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.autosuggest-item {
    padding: 0;
}

/* "Show all results" footer link appended to the suggestion list */
.autosuggest-item.ai-ep-show-all {
    border-top: 2px solid var(--color-border);
    margin-top: 0.5rem;
}

.ai-ep-show-all .autosuggest-link {
    display: block;
    padding: 0.9rem 0.4rem;
    text-align: center;
    font-family: var(--font-heading);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.85rem;
    color: var(--color-action);
}

.ai-ep-show-all .autosuggest-link:hover,
.ai-ep-show-all.selected .autosuggest-link {
    background: var(--color-bg-tint);
}

/* The autosuggest item reuses the theme's .archive-snippet markup/classes so
   the dropdown matches the /?s= results page exactly. The whole item is a
   single anchor, so strip link decoration and let the inner post-part classes
   (.article-category, h3, .byline, .post-excerpt) carry the styling. */
/* Not scoped to the offcanvas only - the results-page revise-search dropdown
   uses this same .autosuggest-item markup (via the itemHTML filter) and needs
   the same reset, or its links render fully underlined (title, date, and
   excerpt all inherit text-decoration from the single wrapping <a>). */
.autosuggest-item .autosuggest-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.autosuggest-item h3 {
    font-family: var(--font-heading);
    font-weight: 800;
    line-height: 1.2;
    color: var(--color-text-base);
    transition: color 0.3s ease;
}

.autosuggest-item .autosuggest-link:hover h3,
.autosuggest-item.selected h3 {
    color: var(--color-action);
}

/* Not scoped to the offcanvas only - the results-page revise-search dropdown
   uses the same highlight() markup and needs the same reset. Bootstrap's
   reboot styles the bare `mark` element globally (`mark, .mark { padding:
   0.1875em; background-color: var(--bs-highlight-bg) }`); without resetting
   `padding` here too, that box model survives even though color/background
   are overridden below, and reads as stray spaces around the matched word. */
.autosuggest-item mark,
.autosuggest-item .ep-highlight,
.archive-snippet mark,
.archive-snippet .ep-highlight {
    padding: 0;
    background: transparent;
    color: var(--color-action);
    font-weight: 700;
}

/* Loading indicator - ElasticPress adds .is-loading to the search <form> while
   an autosuggest request is in flight. Deliberately prominent: a full-width
   accent progress bar under the input plus a larger spinner. */
#search-autocomplete-offcanvas form.is-loading {
    position: relative;
}

#search-autocomplete-offcanvas form.is-loading::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -2px;
    height: 3px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--color-action) 50%,
        transparent 100%);
    background-size: 40% 100%;
    background-repeat: no-repeat;
    animation: ai-ep-progress 1s ease-in-out infinite;
    pointer-events: none;
}

#search-autocomplete-offcanvas form.is-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 14px;
    width: 24px;
    height: 24px;
    margin-top: -12px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-action);
    border-radius: 50%;
    animation: ai-ep-spin 0.6s linear infinite;
    pointer-events: none;
}

@keyframes ai-ep-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes ai-ep-progress {
    0% {
        background-position: -40% 0;
    }
    100% {
        background-position: 140% 0;
    }
}

/* Facets sidebar on the search results page (native search.php / archive template) */
/* Brand placeholder image (imageless results). A logo shouldn't be cropped
   like a photo, so contain it on a neutral field instead of cover.

   The box must match the real .rectangle thumbnails (aspect-ratio 300/250).
   aspect-ratio is forced with !important because some snippets constrain their
   images to other ratios that would otherwise apply here. border-box keeps
   the inset padding from enlarging the box (content-box padding would make
   it taller than the photos). */
.archive-snippet img.is-placeholder,
#search-autocomplete-offcanvas .autosuggest-item img.is-placeholder {
    aspect-ratio: 300 / 250 !important;
    object-fit: contain !important;
    object-position: center !important;
    background: var(--color-bg-tint);
    width: 100% !important;
    height: auto !important;
    padding: 0 !important;
}

/* Search results heading */
.search-results-header {
    border-bottom: 2px solid var(--color-text-base);
    padding-bottom: 0.75rem;
}

/* Revise-search form in the results header. The input carries
   .ep-search-input so ElasticPress's autosuggest script skips attaching a
   dropdown to it entirely (see A() in autosuggest-script.js, which early-
   returns for any input with that class or .facet-search) - typing and
   submitting just does a normal full-page GET navigation to /?s=<term>,
   like any plain search form. */
.search-revise-form {
    max-width: 640px;
}

.search-revise-form .search-field {
    width: 100%;
}

.search-results-heading {
    font-family: var(--font-heading);
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 0.25rem;
}

.search-results-heading .search-results-term {
    color: var(--color-action);
}

.search-results-count {
    color: var(--color-text-muted);
    letter-spacing: 0.06em;
}

/* ==========================================================================
   Facets sidebar — modern, card-based, scannable
   ========================================================================== */
.search-facets-sidebar {
    flex: 0 0 300px;
    max-width: 300px;
    align-self: flex-start;
}

/* Mobile "Filters" toggle button (hidden on desktop via d-lg-none) */
.search-filters-toggle {
    width: 100%;
    font-family: var(--font-heading);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.search-filters-toggle::after {
    content: " ▾";
}

.search-filters-toggle[aria-expanded="true"]::after {
    content: " ▴";
}

@media (max-width: 991.98px) {
    .search-facets-sidebar {
        flex-basis: auto;
        max-width: none;
        width: 100%;
        margin-bottom: 2rem;
    }

    /* Mobile flex order: Filters button, then the (collapsed) facets directly
       below it, then results. Desktop keeps natural DOM order (results | facets)
       with no order rules, so the sidebar stays on the right. */
    .search-filters-toggle {
        order: 1;
    }

    .search-facets-sidebar {
        order: 2;
    }

    .search-results-main {
        order: 3;
    }

    /* Facets collapse below the Filters toggle on mobile; cap each card's term
       list shorter so the expanded filter block doesn't run too long. */
    .search-facets-sidebar .terms .inner {
        max-height: 14rem;
    }

    .search-facets-sidebar .widget {
        margin-bottom: 0.75rem;
    }
}

.search-facets-sidebar .widget {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 1rem 1.15rem;
    margin-bottom: 1rem;
}

.search-facets-sidebar .widget-title,
.search-facets-sidebar h3.facet-title,
.search-facets-sidebar .widgettitle,
.search-facets-sidebar h2.widgettitle {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-base);
}

/* Search-within-facet input */
.search-facets-sidebar .facet-search {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 0.6rem;
    padding: 0.4rem 0.65rem;
    font-size: 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg-tint);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-facets-sidebar .facet-search:focus {
    outline: none;
    border-color: var(--color-action);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-action) 20%, transparent);
}

.search-facets-sidebar .terms {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Cap the term list to roughly the top 10 and scroll the rest; the built-in
   facet search filters the full list. */
.search-facets-sidebar .terms .inner {
    max-height: 20rem;
    overflow-y: auto;
    padding-right: 4px;
}

.search-facets-sidebar .terms .inner::-webkit-scrollbar {
    width: 6px;
}

.search-facets-sidebar .terms .inner::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.search-facets-sidebar .terms .term {
    display: block;
    margin: 0;
}

/* The facet-search JS toggles a .hide class on non-matching terms. EP's own
   `.term.hide{display:none}` is lower specificity than our `.term{display:block}`
   above, so it loses - re-assert the hide at higher specificity or search
   appears to do nothing. */
.search-facets-sidebar .terms .term.hide {
    display: none;
}

.search-facets-sidebar .terms .term a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-base);
    text-decoration: none;
    font-size: 0.9rem;
    line-height: 1.3;
    padding: 0.3rem 0.4rem;
    border-radius: 6px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.search-facets-sidebar .terms .term a:hover {
    background: var(--color-bg-tint);
    color: var(--color-action);
}

/* Custom checkbox affordance (EP outputs an empty .ep-checkbox div) */
.search-facets-sidebar .ep-checkbox {
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--color-border);
    border-radius: 4px;
    position: relative;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.search-facets-sidebar .term.selected > a {
    color: var(--color-action);
    font-weight: 700;
}

.search-facets-sidebar .term.selected .ep-checkbox {
    background: var(--color-action);
    border-color: var(--color-action);
}

.search-facets-sidebar .term.selected .ep-checkbox::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 1px;
    width: 4px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Date facet options */
.search-facets-sidebar .ep-facet-date-form {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.search-facets-sidebar .ep-facet-date-option {
    margin: 0;
}

.search-facets-sidebar .ep-facet-date-option label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-base);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.3rem 0.4rem;
    border-radius: 6px;
    cursor: pointer;
}

.search-facets-sidebar .ep-facet-date-option label:hover {
    background: var(--color-bg-tint);
}

/* Radio inputs (date presets). The native control renders as a faint gray
   ring that accent-color can't darken (accent-color only tints the checked
   state), so draw a fully custom radio with a clearly-visible dark border and
   a filled primary-color dot when selected. */
.search-facets-sidebar input.ep-radio {
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    width: 18px !important;
    height: 18px !important;
    min-width: 18px;
    aspect-ratio: 1 / 1 !important;
    margin: 0 !important;
    flex: 0 0 18px;
    border: 2px solid var(--color-text-base) !important;
    border-radius: 50% !important;
    background: #fff !important;
    box-sizing: border-box;
    position: relative;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.search-facets-sidebar input.ep-radio:hover {
    border-color: var(--color-action) !important;
}

.search-facets-sidebar input.ep-radio:checked {
    border-color: var(--color-action) !important;
}

.search-facets-sidebar input.ep-radio:checked::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--color-action);
    transform: translate(-50%, -50%);
    /* EP ships `.ep-radio:checked:after{opacity:0}`; that property isn't set in
       our rule above, so re-assert it here or the dot stays invisible. */
    opacity: 1 !important;
}

.search-facets-sidebar input.ep-radio:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--color-action) 40%, transparent);
    outline-offset: 1px;
}

/* Custom date range picker - stack From/To full-width so they don't overflow */
.search-facets-sidebar .ep-date-range-picker {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0.5rem 0 0.25rem;
    padding-left: 0.4rem;
}

.search-facets-sidebar .ep-date-range-picker.is-hidden {
    display: none;
}

.search-facets-sidebar .ep-date-range-picker__from,
.search-facets-sidebar .ep-date-range-picker__to {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.search-facets-sidebar .ep-date-range-picker label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.search-facets-sidebar .ep-facet-date-form input[type="date"] {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
}

.search-facets-sidebar .ep-facet-date-form__action {
    margin-top: 0.6rem;
}

.search-facets-sidebar .ep-facet-date-form__action-submit {
    padding: 0.4rem 0.8rem;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #fff;
    background: var(--color-action);
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.search-facets-sidebar .ep-facet-date-form__action-submit:hover {
    background: var(--color-action-dark);
}

@media(max-width: 991px) {
    .search-facets-sidebar {
        position: static;
        max-width: none;
    }
}
