/* ============================================================
   PRODOTTI PAGE — MOBILE OPTIMIZATIONS
   Target: .page--prodotti
   Breakpoints: 767px (mobile), 991px (tablet)
   Design Direction: Industrial Utilitarian · precision e chiarezza
   ============================================================ */

/* ── 0. OVERFLOW FIX GLOBALE ────────────────────────────────── */
/* Elimina il bleeding orizzontale che forza la pagina a 460px */
.page--prodotti .catalogue-body,
.page--prodotti .container,
.page--prodotti .catalogue-layout {
    max-width: 100%;
    overflow-x: hidden;
}

/* ── 1. CATALOGUE LAYOUT: sidebar sopra + main sotto ── */
@media (max-width: 991px) {
    .catalogue-layout {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    .catalogue-main {
        width: 100%;
        min-width: 0; /* evita overflow in flex */
    }
}

/* ── 2. SIDEBAR MOBILE: collassabile con toggle ── */
@media (max-width: 991px) {
    /* Container: piena larghezza a tutti i livelli */
    #tech-sidebar-main,
    #tech-sidebar-main .tech-sidebar,
    .catalogue-layout > #tech-sidebar-main {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box;
        flex-shrink: 0;
    }

    .tech-sidebar {
        width: 100% !important;
        max-width: 100% !important;
        border-right: none;
        border-bottom: 2px solid #f0f0f0;
        padding: 0;
        position: relative;
        box-sizing: border-box;
    }

    /* Tutte le sezioni interne: larghezza piena */
    .tech-sb-section,
    .tech-sb-section > *,
    .tech-category-tree,
    .tech-form-group,
    .tech-search-wrap,
    .tech-slider-wrap,
    .tech-select-wrap,
    .tech-cat-root,
    .tech-cat-main-toggle,
    .tech-btn-submit,
    .tech-btn-clear,
    .tech-text-input,
    .tech-select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    /* Header sticky del filtro con pulsante toggle */
    .tech-sidebar::before {
        display: none;
    }
}

/* ── 2b. SIDEBAR: bordi angolari rimossi su mobile (stile flat / industrial) ── */
@media (max-width: 991px) {
    /* Tutti i box, card e bottoni dentro la sidebar: angoli piatti */
    #tech-sidebar-main .tech-sidebar,
    #tech-sidebar-main .tech-sb-section,
    #tech-sidebar-main .tech-cat-root,
    #tech-sidebar-main .tech-cat-main-toggle,
    #tech-sidebar-main .tech-node-content,
    #tech-sidebar-main .tech-text-input,
    #tech-sidebar-main .tech-select,
    #tech-sidebar-main .tech-select-wrap,
    #tech-sidebar-main .tech-search-wrap,
    #tech-sidebar-main .tech-btn-submit,
    #tech-sidebar-main .tech-btn-clear,
    #tech-sidebar-main .tech-cat-no-results,
    #tech-sidebar-main .tech-cat-search-clear,
    /* Vehicle selector card inside sidebar */
    #tech-sidebar-main [class*="vehicle"],
    #tech-sidebar-main [class*="card"],
    #tech-sidebar-main button,
    #tech-sidebar-main input,
    #tech-sidebar-main select,
    #tech-sidebar-main a[class*="tech"] {
        border-radius: 0 !important;
    }

    /* Separatori sezione: linee nette invece di spazi arrotondati */
    #tech-sidebar-main .tech-sb-section {
        border-bottom: 1px solid #e5e7eb;
    }

    /* Il toggle bar in cima rimane con angoli 0 anche lui */
    .sidebar-mobile-toggle {
        border-radius: 0;
    }
}

/* Wrapper toggle mobile per la sidebar */
.sidebar-mobile-toggle {
    display: none;
}

@media (max-width: 991px) {
    .sidebar-mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 0.85rem 1.25rem;
        background: #fff;
        border: none;
        border-bottom: 1px solid #e5e7eb;
        cursor: pointer;
        font-weight: 700;
        font-size: 0.9rem;
        color: #111;
        gap: 0.75rem;
        position: sticky;
        top: 0;
        z-index: 30;
        box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    }

    .sidebar-mobile-toggle__left {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .sidebar-mobile-toggle__badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 20px;
        height: 20px;
        padding: 0 5px;
        background: #dc2626;
        color: #fff;
        font-size: 0.65rem;
        font-weight: 800;
        border-radius: 99px;
        line-height: 1;
    }

    .sidebar-mobile-toggle__chevron {
        transition: transform 0.25s ease;
        color: #6b7280;
        font-size: 0.75rem;
    }

    .sidebar-mobile-toggle--open .sidebar-mobile-toggle__chevron {
        transform: rotate(180deg);
    }

    /* Pannello filtri: collassato per default su mobile */
    .tech-sidebar .sidebar-content {
        overflow: hidden;
        max-height: 0;
        transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .tech-sidebar.sidebar--open .sidebar-content {
        max-height: 9999px;
    }

    /* Sezioni interne sidebar: padding compatto */
    .tech-sb-section {
        padding: 1rem 1.25rem;
        border-bottom: 1px solid #f3f4f6;
    }

    /* Campi di input: larghezza piena su mobile */
    .tech-text-input,
    .tech-select,
    .tech-slider-wrap,
    .tech-form-group {
        width: 100%;
        box-sizing: border-box;
    }

    /* Griglia form filtri: singola colonna */
    .tech-form-group {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
}

/* ── 3. BLOCK PRODUCTS TABS: scroll orizzontale ── */
@media (max-width: 767px) {
    .block-products-tabs {
        margin: 0 -1.25rem; /* bleeding edge-to-edge */
        border-radius: 0;
    }

    .block-products-tabs__header {
        padding: 0 1.25rem;
        flex-direction: column;
        gap: 0.5rem;
        overflow: hidden;
    }

    /* Tab list: scroll orizzontale nativo, no wrap */
    .block-products-tabs__list {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0;
        border-bottom: 2px solid #f0f0f0;
        padding: 0;
        margin: 0;
        list-style: none;
        width: 100%;
    }

    .block-products-tabs__list::-webkit-scrollbar {
        display: none;
    }

    .block-products-tabs__item {
        flex-shrink: 0;
    }

    .block-products-tabs__btn {
        white-space: nowrap;
        padding: 0.75rem 1.1rem;
        font-size: 0.75rem;
        font-weight: 700;
        letter-spacing: 0.06em;
    }

    /* Right area: product count + nav frecce su riga compatta */
    .block-products-tabs__right {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.5rem 0;
        width: 100%;
    }

    /* Conteggio prodotti */
    .block-products-tabs__right .search-count {
        font-size: 0.8rem !important;
    }

    /* Tab content: padding ridotto */
    .block-products-tabs__content {
        padding: 1rem 1.25rem;
    }

    /* Griglia tab prodotti: sempre 2 colonne */
    .block-products-tabs__content .products-grid,
    .block-products-tabs__content .related-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }
}

/* ── 4. LAYOUT SELECTOR TOOLBAR — 2 righe su mobile ── */
@media (max-width: 767px) {
    /* Wrapper: diventa una colonna a 2 righe */
    .layout-selector-wrapper {
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 0.5rem 0 !important;
        padding: 0.6rem 0 !important;
        margin-bottom: 0.75rem !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }

    /* ROW 1: bottoni layout + count — occupa tutta la larghezza */
    .layout-selector-wrapper > div:first-child {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        flex: 1 1 100%;
        width: 100%;
        padding-bottom: 0.4rem;
        border-bottom: 1px solid #f0f0f0;
    }

    /* Nascondi bottoni inutili su mobile */
    .layout-btn[title="Griglia 4 colonne"],
    .layout-btn[title="Griglia 3 colonne"],
    .layout-btn[title="Vista tabella"] {
        display: none !important;
    }

    .layout-btn {
        width: 32px;
        height: 32px;
        border-radius: 6px;
    }

    .layout-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Count prodotti: a destra nella row 1 */
    #products-summary-container {
        margin-left: auto;
        font-size: 0.72rem;
        color: #6b7280;
        white-space: nowrap;
        line-height: 1.2;
    }

    #products-summary-container strong {
        font-size: 0.85rem;
        color: #111;
    }

    /* ROW 2: sort + mostra — occupa tutta la larghezza, affiancati */
    .layout-selector-wrapper .ms-auto {
        flex: 1 1 100% !important;
        width: 100% !important;
        margin-left: 0 !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 0.5rem !important;
        align-items: center;
        padding-top: 0.4rem;
    }

    /* Ogni coppia label+select occupa metà riga */
    .layout-selector-wrapper .ms-auto > div {
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        gap: 0.35rem;
        flex: 1 1 50%;
        min-width: 0;
    }

    /* Label: compatto */
    .layout-selector-wrapper .text-dark.fw-bold {
        font-size: 0.68rem !important;
        white-space: nowrap;
        color: #9ca3af !important;
        font-weight: 700 !important;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        flex-shrink: 0;
    }

    /* Select: stile premium, larghezza fluida */
    .layout-selector-wrapper .tech-select,
    .layout-selector-wrapper select {
        appearance: none;
        -webkit-appearance: none;
        flex: 1;
        min-width: 0;
        font-size: 0.8rem;
        font-weight: 600;
        padding: 0.35rem 1.75rem 0.35rem 0.6rem;
        border: 1.5px solid #e5e7eb;
        border-radius: 6px;
        background: #fff;
        color: #111;
        cursor: pointer;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.5rem center;
        transition: border-color 0.15s;
    }

    .layout-selector-wrapper .tech-select:focus,
    .layout-selector-wrapper select:focus {
        outline: none;
        border-color: #dc2626;
    }

    /* Nasconde la freccia originale del wrapper (già nel background-image) */
    .layout-selector-wrapper .tech-select-wrap > i {
        display: none !important;
    }

    .layout-selector-wrapper .tech-select-wrap {
        flex: 1;
        min-width: 0;
        position: relative;
    }
}

/* ── 5. PRODUCT GRID: 2 colonne native su mobile ── */
@media (max-width: 767px) {
    /* Sovrascrive il default colonna-singola per tutti i layout griglia */
    #products-container.products-grid,
    #products-container.products-grid--4,
    #products-container.products-grid--3,
    #products-container.products-grid--2,
    .products-grid.related-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.65rem !important;
    }

    /* Lista: layout compatto a due zone */
    .products-list-view .product-list-item {
        grid-template-columns: 90px 1fr;
        grid-template-rows: auto auto;
        gap: 0.75rem;
        padding: 0.9rem;
    }

    .product-list-image {
        width: 90px;
        height: 90px;
        grid-row: 1 / 3;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .product-list-info {
        grid-column: 2;
    }

    .product-list-actions {
        grid-column: 1 / -1;
        border-left: none;
        border-top: 1px solid #f0f0f0;
        padding: 0.75rem 0 0;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.4rem;
        justify-content: stretch;
    }

    .product-list-actions .btn-add-cart {
        flex: 1;
        text-align: center;
        justify-content: center;
        font-size: 0.8rem;
        padding: 0.55rem 0.5rem;
    }

    .product-list-title {
        font-size: 0.9rem;
    }

    .product-list-price {
        font-size: 1.15rem;
    }
}

/* ── 6. PRODUCT CARD: ottimizzata per 2 colonne strette ── */
@media (max-width: 767px) {
    .product-card {
        border-radius: 10px;
        overflow: hidden;
    }

    /* Immagine prodotto: centrata orizzontalmente e verticalmente */
    .product-card .product-card__image {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 12px 12px 8px;
    }

    .product-card .image.image--type--product {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Override the global aspect-ratio with fixed compact height for 2-col mobile grid */
    .product-card .image__body {
        display: flex;
        align-items: center;
        justify-content: center;
        aspect-ratio: unset;
        height: 120px;
        width: 100%;
        overflow: hidden;
    }

    /* position:static ensures flex centering works (not absolute) */
    .product-card .image__tag,
    .product-card .img-immagineprodotto.image__tag {
        position: static;
        display: block;
        max-height: 110px;
        width: auto;
        max-width: 90%;
        height: auto;
        object-fit: contain;
        margin: 0 auto;
    }

    /* Area info: padding compatto */
    .product-card__info {
        padding: 0.5rem 0.6rem 0.35rem;
    }

    .product-card__meta {
        font-size: 0.65rem;
        margin-bottom: 0.2rem;
    }

    /* Nome prodotto: 2 righe max, poi ellipsis */
    .product-card__name h3 a {
        font-size: 0.78rem;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* Footer card: prezzo + bottone carrello su riga */
    .product-card__footer {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.45rem 0.6rem;
        gap: 0.3rem;
        border-top: 1px solid #f0f0f0;
    }

    /* Prezzo: più piccolo ma leggibile */
    .product-card__price.price-mono,
    .product-card__price--current,
    .product-card__price--new {
        font-size: 0.9rem !important;
    }

    .product-card__price--old {
        font-size: 0.7rem !important;
    }

    /* Bottone carrello: cerchio compatto touch-friendly */
    .product-card__addtocart-icon {
        width: 34px;
        height: 34px;
        flex-shrink: 0;
        font-size: 0.85rem;
        border-radius: 8px;
    }

    /* Azioni floating (wishlist/compare): più piccole */
    .product-card__actions-list {
        top: 6px;
        right: 6px;
        gap: 4px;
    }

    .product-card__action {
        width: 28px;
        height: 28px;
        font-size: 0.7rem;
    }
}

/* ── 7. ACTIVE FILTERS BAR ── */
@media (max-width: 767px) {
    .search-summary-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding: 0.5rem 0;
    }

    .active-filters-bar {
        flex-wrap: nowrap;
        display: inline-flex;
        gap: 0.4rem;
    }
}

/* ── 8. PAGINAZIONE + PER-PAGE ── */
@media (max-width: 767px) {
    /* Contenitore wrapper paginazione: colonna centrata */
    .catalogue-main > div[style*="space-between"] {
        flex-direction: column !important;
        align-items: center !important;
        gap: 1rem !important;
        margin-top: 1.5rem !important;
        padding: 1rem 0 0 !important;
        border-top: 1px solid #f0f0f0;
    }

    /* Nasconde le div laterali vuote */
    .catalogue-main > div[style*="space-between"] > div[style*="flex: 1;"]:first-child {
        display: none !important;
    }

    /* Paginazione Laravel: pill buttons compatti */
    .pagination {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.2rem;
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .pagination li > span,
    .pagination li > a {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 34px;
        height: 34px;
        padding: 0 0.5rem;
        border: 1.5px solid #e5e7eb;
        border-radius: 6px;
        font-size: 0.8rem;
        font-weight: 600;
        color: #374151;
        background: #fff;
        text-decoration: none;
        transition: all 0.15s;
        white-space: nowrap;
    }

    .pagination li > a:hover {
        border-color: #dc2626;
        color: #dc2626;
        background: #fff5f5;
    }

    /* Pagina attiva */
    .pagination li.active > span,
    .pagination li > span[aria-current] {
        background: #dc2626;
        border-color: #dc2626;
        color: #fff;
    }

    /* Disabled (prev/next alle estremità) */
    .pagination li > span.disabled,
    .pagination li.disabled > span {
        opacity: 0.35;
        pointer-events: none;
    }

    /* Per-page selector in fondo: stile coerente con la toolbar */
    .per-page-selector {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        background: #fff;
        border: 1px solid #f0f0f0;
        border-radius: 8px;
        padding: 0.45rem 0.85rem;
        box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    }

    .per-page-selector label {
        font-size: 0.7rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: #9ca3af;
        white-space: nowrap;
    }

    #per_page_bottom {
        appearance: none;
        -webkit-appearance: none;
        font-size: 0.8rem;
        font-weight: 700;
        padding: 0.3rem 1.75rem 0.3rem 0.55rem;
        border: 1.5px solid #e5e7eb;
        border-radius: 6px;
        background: #fff;
        color: #111;
        cursor: pointer;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.45rem center;
        outline: none;
    }

    #per_page_bottom:focus {
        border-color: #dc2626;
    }

    /* Messaggio "Hai visto tutti i prodotti" */
    .catalogue-main > div.text-center.py-4.text-muted {
        font-size: 0.8rem;
        color: #9ca3af;
        letter-spacing: 0.03em;
        padding: 1rem 0;
        text-align: center;
    }
}

/* ── 9. EMPTY STATE ── */
@media (max-width: 767px) {
    .empty-state {
        padding: 3rem 1.25rem !important;
        border-radius: 12px !important;
    }

    .empty-state h2 {
        font-size: 1.4rem !important;
    }
}

/* ── 10. TABLET: layout 2 colonne affiancate ── */
@media (min-width: 768px) and (max-width: 991px) {
    .catalogue-layout {
        display: flex;
        flex-direction: column;
    }

    .tech-sidebar {
        width: 100%;
    }

    /* Griglia: 3 colonne su tablet */
    #products-container.products-grid--4 {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    #products-container.products-grid--3 {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}
