/**
 * GR Advanced Search — Autocomplete Styles
 * BEM: gr-search__*
 */

/* v1.4.1 — Screen-reader only utility (visually hidden but announcable).
   Used for the ARIA live region "result count" announcement. */
.gr-search__sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
    white-space: nowrap;
}

/* v1.4.1 — Focus indicator visibile per keyboard navigation (a11y).
   Bootstrap focus a volte è rimosso/sovrascritto dai temi → forziamo. */
.gr-search__item:focus-visible,
.gr-search__item--active {
    outline: 2px solid #1565c0;
    outline-offset: -2px;
    background-color: #e3f2fd;
}

/* v1.4.1 — Respect prefers-reduced-motion: disabilita le transizioni
   non essenziali per utenti con sensibilità al movimento. */
@media (prefers-reduced-motion: reduce) {
    .gr-search__item,
    .gr-search__filters-panel,
    .gr-search__filters-toggle::after,
    .gr-search__view-all,
    .gr-search__facet-color {
        transition: none !important;
    }
    .gr-search__facet-color:hover {
        transform: none !important;
    }
}

/*
 * Suppress the native ps_searchbar dropdown when gradvancedsearch is enabled.
 * Both implementations bind to the same input; without this rule the user
 * sees two stacked dropdowns (one from the theme's ps_searchbar template,
 * one from our autocomplete.js). The native dropdown stays in the DOM and
 * reappears automatically if this module is later uninstalled (= the CSS
 * is no longer loaded).
 *
 * The JS in autocomplete.js also adds `.d-none` to these elements as a
 * belt-and-suspenders guard against late-mounting Bootstrap rules.
 */
.ps-searchbar__dropdown,
#ps_searchbar_dropdown {
    display: none !important;
}

/* -------------------------------------------------------------------------
 * Dropdown layout (v1.3.1 — mega-dropdown grid, Variante A)
 *
 * Width 820px allineato al bordo destro della searchbar (gr-hybrid posiziona
 * la searchbar a destra dell'header). Su tablet/mobile collassa a single
 * column / bottom-sheet rispettivamente.
 *
 * Quando il dropdown contiene facets/price-range (.--with-filters), layout
 * a 2 colonne grid: filtri 220px a sinistra, prodotti+categorie a destra.
 * Quando NON contiene filtri (query con 0 facets), dropdown stretto 480px
 * single column.
 * --------------------------------------------------------------------- */

.gr-search__dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 480px;
    max-width: calc(100vw - 2rem);
    z-index: 1050;
    background: #fff;
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 0.375rem 0.375rem;
    box-shadow: 0 0.5rem 1.5rem rgba(11, 18, 32, 0.12);
    max-height: 520px;
    overflow: hidden; /* contiene le 2 colonne scrollabili indipendenti */
    scrollbar-width: thin;
}

/* With filters: mega-dropdown 820px, grid 220px + 1fr */
.gr-search__dropdown--with-filters {
    width: 820px;
    display: grid;
    grid-template-columns: minmax(180px, 220px) 1fr;
}

/* Fallback senza filtri: scroll unico, single column */
.gr-search__dropdown:not(.gr-search__dropdown--with-filters) {
    overflow-y: auto;
}

/* Main panel (colonna destra in modalità with-filters) */
.gr-search__main-panel {
    max-height: 520px;
    overflow-y: auto;
    min-width: 0; /* permette text-overflow ellipsis nei child */
}

/* Mobile filter toggle button — visibile solo su mobile */
.gr-search__filters-toggle {
    display: none;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #1565c0;
    background: #fafafa;
    border: none;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
}
.gr-search__filters-toggle::after {
    content: '▾';
    transition: transform 0.2s ease;
}
.gr-search__filters-toggle[aria-expanded="true"]::after {
    transform: rotate(180deg);
}

/* Section */
.gr-search__section {
    padding: 0.25rem 0;
    border-bottom: 1px solid #f0f0f0;
}

.gr-search__section:last-child {
    border-bottom: none;
}

.gr-search__section-title {
    /* v1.4.3: tag promosso da <div> a <h3> per heading hierarchy WCAG.
       Reset default browser styles per non rompere il visual layout. */
    margin: 0;
    padding: 0.5rem 1rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
    line-height: 1.2;
}

/* Items */
.gr-search__item {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: #212529;
    transition: background-color 0.15s ease;
    cursor: pointer;
    gap: 0.75rem;
}

.gr-search__item:hover,
.gr-search__item--active {
    background-color: #f8f9fa;
    text-decoration: none;
    color: #212529;
}

/* Product item */
.gr-search__item--product {
    padding: 0.625rem 1rem;
}

.gr-search__item-image {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 0.25rem;
    overflow: hidden;
    background: #f8f9fa;
}

.gr-search__item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gr-search__item-placeholder {
    width: 100%;
    height: 100%;
    background: #e9ecef;
}

.gr-search__item-info {
    flex: 1;
    min-width: 0;
}

.gr-search__item-name {
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* v1.4.1 — Highlight match: enfatizza la porzione del nome che matcha
   la query digitata. Background giallo soft, peso aumentato. Reset
   del default browser su <mark> per evitare conflitti con tema. */
.gr-search__highlight {
    background: #fff3bf;
    color: inherit;
    font-weight: 700;
    padding: 0 0.05em;
    border-radius: 1px;
}

.gr-search__item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.125rem;
    font-size: 0.75rem;
}

.gr-search__item-category {
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gr-search__item-price {
    font-weight: 600;
    color: #212529;
    white-space: nowrap;
    margin-left: 0.5rem;
}

/* -------------------------------------------------------------------------
 * Rating badge (v1.4.0)
 * Emesso nei product items quando product.rating != null && count > 0
 * --------------------------------------------------------------------- */
.gr-search__item-rating {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    font-size: 0.72rem;
    color: #6c757d;
    margin: 0 0.4rem;
    white-space: nowrap;
}

.gr-search__item-rating-star {
    color: #f6b100;
    font-size: 0.8rem;
    line-height: 1;
}

.gr-search__item-rating-value {
    font-weight: 600;
    color: #495057;
}

.gr-search__item-rating-count {
    color: #9aa1ab;
}

/* Category item */
.gr-search__item--category {
    padding: 0.375rem 1rem;
}

.gr-search__item-icon {
    font-family: 'Material Icons', sans-serif;
    font-size: 1.25rem;
    color: #6c757d;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

/* -------------------------------------------------------------------------
 * Recent + Trending sections (v1.4.0)
 * Emessi sul focus dell'input vuoto (prima che l'utente digiti).
 * Stesso markup .gr-search__item delle altre sezioni — qui solo stile
 * leggero di differenziazione tipografica.
 * --------------------------------------------------------------------- */

.gr-search__section--recent .gr-search__section-title,
.gr-search__section--trending .gr-search__section-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.gr-search__item--recent .gr-search__item-icon,
.gr-search__item--trending .gr-search__item-icon {
    color: #1565c0;
}

/* Mode "empty focus": il dropdown rende solo Recent+Trending, niente
   sidebar filtri. Layout sempre compact (480px). */
.gr-search__dropdown[data-empty-focus="1"] {
    overflow-y: auto;
}

/* Suggestion */
.gr-search__suggestion {
    padding: 0.625rem 1rem;
    font-size: 0.85rem;
    color: #6c757d;
    background: #fff8e1;
    border-bottom: 1px solid #f0f0f0;
}

.gr-search__suggestion-link {
    font-weight: 600;
    color: #1565c0;
    text-decoration: underline;
}

.gr-search__suggestion-link:hover {
    color: #0d47a1;
}

/* Empty state */
.gr-search__empty {
    padding: 1.5rem 1rem;
    text-align: center;
    font-size: 0.875rem;
    color: #6c757d;
}

/* View all */
.gr-search__view-all {
    display: block;
    padding: 0.75rem 1rem;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #1565c0;
    text-decoration: none;
    border-top: 1px solid #e9ecef;
    background: #fafafa;
    border-radius: 0 0 0.375rem 0.375rem;
    transition: background-color 0.15s ease;
}

.gr-search__view-all:hover,
.gr-search__view-all.gr-search__item--active {
    background: #e3f2fd;
    color: #0d47a1;
    text-decoration: none;
}

/* -------------------------------------------------------------------------
 * Facet filter panel (v1.3.0 base, v1.3.1 grid-aware)
 *
 * In modalità mega-dropdown (.--with-filters), questo è la prima colonna
 * della grid (sinistra). Border-right invece di border-bottom, overflow-y
 * indipendente dalla colonna principale.
 * --------------------------------------------------------------------- */

.gr-search__filters-panel {
    padding: 0.75rem 1rem;
    background: #fafafa;
    /* nel mega-dropdown grid, occupa la prima colonna */
    border-right: 1px solid #e9ecef;
    max-height: 520px;
    overflow-y: auto;
}

/* Fallback single-column (no filters present is impossibile qui; tenuto
   per retrocompatibilità se _ever_ il dropdown è renderizzato non-grid). */
.gr-search__dropdown:not(.gr-search__dropdown--with-filters) .gr-search__filters-panel {
    border-right: none;
    border-bottom: 1px solid #e9ecef;
    max-height: none;
}

.gr-search__facets-title,
.gr-search__price-range-title {
    /* v1.4.3: tag h3/h4 — reset default browser margins. */
    margin: 0 0 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
    line-height: 1.2;
}

.gr-search__facet-group {
    margin-bottom: 0.75rem;
}

.gr-search__facet-group:last-child {
    margin-bottom: 0;
}

.gr-search__facet-group-name {
    /* v1.4.3: tag h4 — reset default browser margins. */
    margin: 0 0 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #495057;
    line-height: 1.2;
}

/* Color circles */
.gr-search__facet-colors {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.gr-search__facet-color {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: transform 0.12s ease, border-color 0.12s ease;
    outline-offset: 2px;
}

.gr-search__facet-color:hover {
    transform: scale(1.15);
}

.gr-search__facet-color--active {
    border-color: #212529;
    transform: scale(1.15);
}

/* Select checkboxes */
.gr-search__facet-options {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.gr-search__facet-option {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    cursor: pointer;
    user-select: none;
    padding: 0.1rem 0;
}

.gr-search__facet-option:hover .gr-search__facet-option-name {
    color: #1565c0;
}

.gr-search__facet-checkbox {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.gr-search__facet-option-name {
    flex: 1;
    color: #212529;
}

.gr-search__facet-option-count {
    color: #9aa1ab;
    font-size: 0.75rem;
    white-space: nowrap;
}

/* -------------------------------------------------------------------------
 * Price range slider (v1.3.0)
 * --------------------------------------------------------------------- */

.gr-search__price-range {
    margin-bottom: 0.75rem;
}

.gr-search__price-sliders {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.gr-search__price-slider-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.gr-search__price-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: #dee2e6;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.gr-search__price-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #1565c0;
    cursor: pointer;
}

.gr-search__price-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #1565c0;
    border: none;
    cursor: pointer;
}

.gr-search__price-display {
    font-size: 0.8rem;
    color: #495057;
    text-align: center;
}

/* -------------------------------------------------------------------------
 * Responsive (mobile/tablet)
 * --------------------------------------------------------------------- */

/* Tablet: dropdown stretto se viewport tra 769-1024px */
@media (min-width: 769px) and (max-width: 1024px) {
    .gr-search__dropdown--with-filters {
        width: min(720px, calc(100vw - 2rem));
        grid-template-columns: 180px 1fr;
    }
    .gr-search__dropdown:not(.gr-search__dropdown--with-filters) {
        width: min(420px, calc(100vw - 2rem));
    }
}

/* v1.4.2 — Smart no-results fallback: trending alternatives wrapper.
 * Renders below the "Nessun risultato" empty state. Header riusa lo stile
 * sezione standard; gli item sono `gr-search__item--trending` esistenti.
 * Sottile separatore visivo + leggero padding-top per distinguerlo. */
.gr-search__no-results-fallback {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #eef0f3;
}
.gr-search__section--trending-fallback .gr-search__section-title {
    color: #6b7280;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* v1.4.2 — Clear button (X) per svuotare velocemente il search input.
 * Posizionato in absolute dentro `[data-gr-search-anchor]`, visibile solo
 * quando il dropdown è aperto o l'input ha contenuto. Click → reset input
 * + hide dropdown. CSS minimo: il modulo NON forza dimensioni dell'input
 * (lo decide il tema), solo posiziona il button sopra al border-right. */
.gr-search__clear {
    position: absolute;
    top: 50%;
    right: 2.5rem; /* lascia spazio al search icon nativo del tema */
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    z-index: 1;
    /* v1.4.3 — coerenza con HTML5 `hidden` attribute (settato/rimosso dal
       JS via updateClearButtonVisibility). UA stylesheet già fa display:none
       per [hidden]; data-visible="1" è ridondante ma kept as styling hook. */
}
.gr-search__clear[hidden] {
    display: none !important;
}
.gr-search__clear[data-visible="1"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.gr-search__clear:hover,
.gr-search__clear:focus-visible {
    color: #111;
    outline: 2px solid #1565c0;
    outline-offset: 1px;
    border-radius: 2px;
}

/* v1.4.3 — WCAG 1.4.10 Reflow: garantisce spazio sul testo input quando il
 * clear button è visibile, evita overlap su input ≤200px (mobile portrait).
 * Targetting il pattern wrapper standard del modulo. Il tema può override. */
[data-gr-search-anchor]:has(.gr-search__clear[data-visible="1"]) input[type="search"],
[data-gr-search-anchor]:has(.gr-search__clear[data-visible="1"]) input[type="text"] {
    padding-right: 4rem;
}

/* Mobile: bottom-sheet, single column, filtri collassati dietro toggle */
@media (max-width: 768px) {
    .gr-search__dropdown,
    .gr-search__dropdown--with-filters {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-width: none;
        max-height: 75vh;
        display: block; /* override grid */
        overflow-y: auto;
        border-radius: 0.75rem 0.75rem 0 0;
        border: none;
        box-shadow: 0 -0.5rem 2rem rgba(0, 0, 0, 0.2);
    }

    /* Mobile: toggle button visibile, filters panel collapsed by default */
    .gr-search__dropdown--with-filters .gr-search__filters-toggle {
        display: flex;
    }
    .gr-search__dropdown--with-filters .gr-search__filters-panel {
        max-height: 0;
        overflow: hidden;
        padding-top: 0;
        padding-bottom: 0;
        border-right: none;
        border-bottom: 1px solid #e9ecef;
        transition: max-height 0.2s ease, padding 0.2s ease;
    }
    .gr-search__dropdown--with-filters .gr-search__filters-panel--open {
        max-height: 360px;
        overflow-y: auto;
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    .gr-search__main-panel {
        max-height: none;
    }

    .gr-search__item-image {
        width: 40px;
        height: 40px;
    }
}
