/* =========================================================================
   1. RESET GLOBALE E PREVENZIONE OVERFLOW
   ========================================================================= */
html, body {
    max-width: 100vw !important;
    overflow-x: hidden !important;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* =========================================================================
   2. LAYOUT DESKTOP PAGINA RISULTATI RICERCA
   ========================================================================= */
body.search-results .site-main,
body.search .site-main {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 30px;
    align-items: start;
}

body.search-results .woocommerce-no-products-found,
body.search-results .no-results {
    grid-column: 2;
    width: 100%;
}

/* =========================================================================
   3. FORM DI RICERCA ENHANCED (DESKTOP)
   ========================================================================= */
.catalog-search-enhanced-wrap {
    width: 100%;
    max-width: 100%;
    margin: 0 auto 1.5rem auto;
    position: relative;
    z-index: 99;
}

.catalog-search-form,
.core-search-enhanced-form {
    display: flex;
    flex-direction: row;
    gap: 10px;
    width: 100%;
    align-items: center;
    position: relative;
}

.search-field-main {
    flex: 1;
    min-width: 0;
    position: relative;
}

.catalog-input-text {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 15px;
    background-color: #ffffff;
}

.search-field-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    position: relative;
    z-index: 101;
}

.catalog-select-cat {
    padding: 12px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background-color: #ffffff;
    font-size: 14px;
    max-width: 240px;
    height: 46px;
}

.catalog-submit-btn,
.core-search-enhanced-form button[type="submit"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 20px;
    height: 46px;
    background-color: #0f172a;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.button-label-mobile {
    display: none;
    height: 46px;
    width: 46px;
}

/* =========================================================================
   4. FIX TENDINA SUGGERIMENTI LIVE SEARCH / AJAX (SOLO Z-INDEX)
   Lasciamo che il JS calcoli posizioni e dimensioni senza blocchi CSS
   ========================================================================= */
.searchwp-live-search-results,
.autocomplete-suggestions,
.catalog-search-ajax-results {
    z-index: 99999 !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2) !important;
}

/* =========================================================================
   5. STRUCTURE MOBILE (< 768px) - LAYOUT VERTICALE PURO
   ========================================================================= */
@media screen and (max-width: 768px) {

    /* --- Form di Ricerca Mobile --- */
    .catalog-search-form,
    .core-search-enhanced-form {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .search-field-main {
        width: 100%;
    }

    .search-field-controls {
        width: 100%;
        display: flex;
        flex-direction: row;
        gap: 8px;
        align-items: center;
    }

    .catalog-select-cat {
        flex: 1;
        max-width: none;
        width: 100%;
        min-width: 0;
    }

    .catalog-submit-btn {
        padding: 0 16px;
    }

    .button-label-mobile {
        /* display: inline; */
        display: none;
        font-size: 14px;
    }

    /* --- Struttura Pagina Risultati: Trasparente e Verticale --- */
    body.search-results .site-main,
    body.search-results main,
    body.search .site-main,
    body.search main {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 0 12px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    /* Testi e Intestazioni */
    .search-results .page-title,
    .search-results .woocommerce-products-header__title {
        margin: 15px 0 !important;
        font-size: 1.25rem !important;
    }

    .search-results .woocommerce-ordering,
    .search-results .woocommerce-result-count {
        float: none !important;
        width: 100% !important;
        margin-bottom: 10px !important;
        text-align: left !important;
    }

    .search-results .woocommerce-ordering select {
        width: 100% !important;
        padding: 8px;
        border-radius: 6px;
        border: 1px solid #cbd5e1;
    }

    /* --- Sidebar / Toggle Categorie Mobile --- */
    body.search-results .custom-shop-sidebar,
    body.search .custom-shop-sidebar,
    body.search-results sidebar,
    body.search-results aside {
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        margin: 0 0 15px 0 !important;
        box-sizing: border-box !important;
    }

    /* --- Griglia Prodotti a 2 Colonne Perfetta e Contenuta --- */
    body.search-results ul.products,
    body.search ul.products {
        display: flex !important;
        flex-wrap: wrap !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        gap: 10px !important;
        box-sizing: border-box !important;
    }

    body.search-results ul.products li.product,
    body.search ul.products li.product {
        width: calc(50% - 5px) !important; /* Esattamente la metà del contenitore meno il gap */
        max-width: calc(50% - 5px) !important;
        float: none !important;
        margin: 0 0 10px 0 !important;
        box-sizing: border-box !important;
        background: #ffffff;
        border-radius: 8px;
        border: 1px solid #e2e8f0;
        padding: 8px;
    }

    body.search-results ul.products li.product img,
    body.search ul.products li.product img {
        width: 100% !important;
        height: auto !important;
        border-radius: 4px;
        object-fit: cover;
    }

    /* Box Nessun Risultato */
    body.search-results .woocommerce-no-products-found,
    body.search-results .no-results {
        width: 100% !important;
        box-sizing: border-box !important;
        margin-bottom: 20px !important;
    }
}
