/**
 * Merida Search — Autocomplete Dropdown
 *
 * BEM naming, CSS custom properties.
 * Layers on top of .merida-search-field from custom-header.css.
 */

/* ================================================================
   Custom Properties
   ================================================================ */
:root {
    --ms-dropdown-bg: var(--global-palette9, #fff);
    --ms-dropdown-border: var(--global-palette7, #d0d5dd);
    --ms-dropdown-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    --ms-dropdown-radius: 12px;
    --ms-dropdown-max-height: 696px;
    --ms-dropdown-z: 99999;

    --ms-item-hover-bg: var(--global-palette8, #f5f7fa);
    --ms-item-active-bg: var(--global-palette7, #e8ecf0);
    --ms-item-padding: 10px 16px;
    --ms-item-gap: 12px;

    --ms-title-color: var(--global-palette3, #1a1a2e);
    --ms-title-size: 14px;
    --ms-title-weight: 600;

    --ms-meta-color: var(--global-palette5, #666);
    --ms-meta-size: 12px;

    --ms-image-size: 48px;
    --ms-image-radius: 6px;
    --ms-image-bg: var(--global-palette8, #f5f7fa);

    --ms-see-all-color: var(--merida-brand-color, #183e86);
    --ms-see-all-size: 14px;
    --ms-see-all-weight: 600;

    --ms-section-header-color: var(--global-palette5, #666);
    --ms-section-header-size: 12px;
    --ms-section-header-weight: 500;
    --ms-section-border: var(--global-palette7, #e5e5e5);
}

/* ================================================================
   Search Wrapper — Positioning context for dropdown
   ================================================================ */
.merida-main-header__search,
.merida-header-search {
    position: relative;
    transition: min-width 0.25s ease, max-width 0.25s ease;
}

.merida-main-header__search.merida-search--expanded {
    min-width: 645px;
    max-width: 645px;
}

/* ================================================================
   Dropdown Container
   ================================================================ */
.merida-search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: var(--ms-dropdown-z);
    background: var(--ms-dropdown-bg);
    border: 1px solid var(--ms-dropdown-border);
    border-radius: var(--ms-dropdown-radius);
    box-shadow: var(--ms-dropdown-shadow);
    max-height: var(--ms-dropdown-max-height);
    min-width: 645px;
    overflow: hidden;
    display: none;
    /* Flex column: scroll area + sticky footer */
    flex-direction: column;
}

.merida-search-results--visible {
    display: flex;
}

/* Scrollable inner area (sections live here) */
.merida-search-results__scroll {
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
}

/* ================================================================
   Sections (Suggestions, Categories, Products)
   ================================================================ */
.merida-search-section {
    padding: 20px 16px;
    animation: ms-section-fade-in 0.2s ease forwards;
}

.merida-search-section+.merida-search-section {
    border-top: 1px solid var(--ms-section-border);
}

.merida-search-section__header {
    padding: 0 0 8px;
    font-size: var(--ms-section-header-size);
    font-weight: var(--ms-section-header-weight);
    color: var(--ms-section-header-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    user-select: none;
}

@keyframes ms-section-fade-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ================================================================
   Result Item (shared base for all types)
   ================================================================ */
.merida-search-result {
    display: flex;
    align-items: center;
    gap: var(--ms-item-gap);
    padding: 10px 0;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.15s;
}

.merida-search-result:hover,
.merida-search-result--active {
    background: var(--ms-item-hover-bg);
}

.merida-search-result:active {
    background: var(--ms-item-active-bg);
}

/* ================================================================
   Suggestion Item — search icon + text
   ================================================================ */
.merida-search-result--suggestion {
    gap: 10px;
    padding: 8px 0;
}

.merida-search-result__icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--ms-meta-color);
}

.merida-search-result--suggestion .merida-search-result__text {
    font-size: var(--ms-title-size);
    color: var(--ms-title-color);
}

/* ================================================================
   Category Item — bold text
   ================================================================ */
.merida-search-result--category {
    padding: 8px 0;
}

.merida-search-result--category .merida-search-result__text {
    font-size: var(--ms-title-size);
    font-weight: var(--ms-title-weight);
    color: var(--ms-title-color);
}

/* ================================================================
   Product Item — Image + Content
   ================================================================ */
.merida-search-result__image {
    width: var(--ms-image-size);
    height: var(--ms-image-size);
    object-fit: contain;
    border-radius: var(--ms-image-radius);
    background: var(--ms-image-bg);
    flex-shrink: 0;
}

.merida-search-result__content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.merida-search-result__title {
    font-size: var(--ms-title-size);
    font-weight: var(--ms-title-weight);
    color: var(--ms-title-color);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.merida-search-result__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--ms-meta-size);
    color: var(--ms-meta-color);
    line-height: 1.3;
}

.merida-search-result__sku {
    font-size: var(--ms-meta-size);
    color: var(--ms-meta-color);
}

.merida-search-result__subtitle {
    font-size: var(--ms-meta-size);
    color: var(--global-palette6, #888);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Pipe separator between meta items */
.merida-search-result__meta-sep {
    color: var(--global-palette6, #888);
}

/* ================================================================
   "See All Results" Link — Sticky footer
   ================================================================ */
.merida-search-results__all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    font-size: var(--ms-see-all-size);
    font-weight: var(--ms-see-all-weight);
    color: var(--ms-see-all-color);
    text-decoration: none;
    border-top: 1px solid var(--ms-dropdown-border);
    background: var(--ms-dropdown-bg);
    flex-shrink: 0;
    transition: background-color 0.15s;
    cursor: pointer;
}

.merida-search-results__all:hover {
    background: var(--ms-item-hover-bg);
}

/* ================================================================
   Loading State
   ================================================================ */
.merida-search-results__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    color: var(--ms-meta-color);
    font-size: var(--ms-meta-size);
}

/* ================================================================
   No Results
   ================================================================ */
.merida-search-results__empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    color: var(--ms-meta-color);
    font-size: var(--ms-title-size);
}

/* ================================================================
   Overlay — Click-to-close backdrop
   ================================================================ */
.merida-search-results__overlay {
    position: fixed;
    inset: 0;
    z-index: calc(var(--ms-dropdown-z) - 1);
    display: none;
    pointer-events: auto;
}

.merida-search-results__overlay--visible {
    display: block;
}

/* ================================================================
   Mobile — Full-width dropdown, capped height
   ================================================================ */
@media (max-width: 1024px) {
    .merida-search-results {
        min-width: 0;
        max-height: 70vh;
        border-radius: var(--ms-dropdown-radius) var(--ms-dropdown-radius);
    }

    /* Disable wrapper expansion on mobile. */
    .merida-main-header__search.merida-search--expanded {
        min-width: 0;
        max-width: none;
    }
}

/* ================================================================
   Reduced Motion
   ================================================================ */
@media (prefers-reduced-motion: reduce) {

    .merida-search-result,
    .merida-search-results__all {
        transition: none;
    }

    .merida-search-section {
        animation: none;
    }
}
/* ================================================================
   Faceted Filters — Pill Dropdowns
   ================================================================ */
#merida-search-filters.merida-search-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 0;
    padding: 0;
}

/* Merge filters row with top-row into one flex line */
.kwt-products-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
}

.kwt-products-wrap > #merida-search-filters {
    flex: 1 1 auto;
}

.kwt-products-wrap > .woocommerce-notices-wrapper {
    width: 100%;
    order: -1;
}

.kwt-products-wrap > .kadence-shop-top-row {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 20px auto;
    padding: 0;
    width: auto;
}

.kwt-products-wrap > ul.products {
    width: 100%;
}

.kwt-products-wrap .kadence-shop-top-item.kadence-woo-results-count {
    margin: 0;
}

.kwt-products-wrap .kadence-shop-top-item.kadence-woo-ordering {
    margin: 0;
}

/* Ordering select styled as pill */
.kwt-products-wrap .woocommerce-ordering select.orderby {
    height: 40px;
    padding: 0 36px 0 18px;
    background-color: var(--global-palette8, #f5f7fa);
    border: 2px solid transparent;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    color: var(--global-palette3, #1a1a2e);
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%231a1a2e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 12px;
    transition: background-color 0.15s, border-color 0.15s;
    box-sizing: border-box;
    line-height: 1;
}

.kwt-products-wrap .woocommerce-ordering select.orderby:hover,
.kwt-products-wrap .woocommerce-ordering select.orderby:focus,
.kwt-products-wrap .woocommerce-ordering select.orderby:active {
    background-color: var(--global-palette8, #f5f7fa);
    border-color: var(--global-palette3, #1a1a2e);
    outline: none;
    box-shadow: none;
    color: var(--global-palette3, #1a1a2e);
}

/* Result count text styling */
.kwt-products-wrap .woocommerce-result-count {
    font-size: 14px;
    font-weight: 500;
    color: var(--global-palette5, #666);
    margin: 0;
    white-space: nowrap;
}

/* Single filter wrapper — positioned for dropdown */
#merida-search-filters .merida-filter {
    position: relative;
}

/* Pill button */
#merida-search-filters .merida-filter__pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 40px;
    padding: 0 18px;
    background: var(--global-palette8, #f5f7fa);
    border: 2px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--global-palette3, #1a1a2e);
    line-height: 1;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
    box-sizing: border-box;
}

#merida-search-filters .merida-filter__pill:hover,
#merida-search-filters .merida-filter__pill:active,
#merida-search-filters .merida-filter--open .merida-filter__pill {
    background: var(--global-palette8, #f5f7fa);
    border-color: var(--global-palette3, #1a1a2e);
    box-shadow: none;
    color: var(--global-palette3, #1a1a2e);
}

#merida-search-filters .merida-filter__pill-label {
    pointer-events: none;
    text-transform: capitalize;
}

#merida-search-filters .merida-filter__pill-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--global-palette3, #1a1a2e);
    color: var(--global-palette9, #fff);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

#merida-search-filters .merida-filter__chevron {
    flex-shrink: 0;
    transition: transform 0.2s;
    pointer-events: none;
}

#merida-search-filters .merida-filter--open .merida-filter__chevron {
    transform: rotate(180deg);
}

/* Dropdown panel */
#merida-search-filters .merida-filter__dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 100;
    min-width: 280px;
    max-width: 96vw;
    width: max-content;
    max-height: 320px;
    overflow-y: auto;
    background: var(--global-palette9, #fff);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 8px 0;
}

#merida-search-filters .merida-filter--open .merida-filter__dropdown {
    display: block;
}

/* Dropdown list */
#merida-search-filters .merida-filter__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

#merida-search-filters .merida-filter__item {
    margin: 0;
}

#merida-search-filters .merida-filter__item label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 15px;
    line-height: 1.4;
    padding: 8px 16px;
    transition: background 0.1s;
    color: var(--global-palette3, #1a1a2e);
    white-space: nowrap;
}

#merida-search-filters .merida-filter__item label:hover {
    background: var(--global-palette8, #f5f7fa);
    color: var(--global-palette3, #1a1a2e);
}

#merida-search-filters .merida-filter__checkbox {
    margin: 0;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    accent-color: var(--global-palette3, #1a1a2e);
}

#merida-search-filters .merida-filter__label {
    flex: 1;
    min-width: 0;
    text-transform: capitalize;
    font-size: 14px;
    font-weight: 500;
}

/* Clear filters button */
#merida-search-filters .merida-filters__clear {
    display: inline-flex;
    align-items: center;
    height: 40px;
    padding: 0 18px;
    background: var(--global-palette8, #f5f7fa);
    border: 2px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--global-palette3, #1a1a2e);
    line-height: 1;
    white-space: nowrap;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
    box-sizing: border-box;
}

#merida-search-filters .merida-filters__clear:hover,
#merida-search-filters .merida-filters__clear:active {
    background: var(--global-palette8, #f5f7fa);
    border-color: var(--global-palette3, #1a1a2e);
    box-shadow: none;
    color: var(--global-palette3, #1a1a2e);
}

/* Loading state — applied by JS during AJAX */
#merida-search-filters.merida-search-filters--loading {
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.2s;
}

/* Mobile: TODO — waiting for UX design */
