/* ============================================
   FILTRO AVANZATO AJAX - STILI COMPLETI
   ============================================ */

/* ------------------------------------------
   1. BASE STYLES (Desktop First)
   ------------------------------------------ */

.faa-filter {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 100%;
    margin: 20px 0;
}

.faa-form {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 5px;
    margin-bottom: 20px;
}

.faa-field {
    margin-bottom: 15px;
}

.faa-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: #333;
}

.faa-field input,
.faa-field select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 14px;
    box-sizing: border-box;
}

.faa-checkboxes {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #ddd;
    padding: 10px;
    background: white;
    border-radius: 3px;
}

.faa-checkboxes label {
    display: block;
    font-weight: normal;
    margin: 5px 0;
    cursor: pointer;
    font-size: 13px;
}

.faa-checkboxes input {
    width: auto;
    margin-right: 8px;
}

/* ------------------------------------------
   2. PRICE SLIDER
   ------------------------------------------ */

.faa-price-slider {
    margin: 15px 5px;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    position: relative;
}

.faa-price-slider .ui-slider-range {
    background: #2271b1;
    height: 100%;
    border-radius: 3px;
    position: absolute;
}

.faa-price-slider .ui-slider-handle {
    width: 18px;
    height: 18px;
    background: #2271b1;
    border-radius: 50%;
    position: absolute;
    top: -6px;
    margin-left: -9px;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.faa-price-labels {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-top: 8px;
    font-weight: 600;
}

/* ------------------------------------------
   3. DATE SLIDER
   ------------------------------------------ */

.faa-date-slider-container {
    padding: 10px 0;
}

.faa-date-slider {
    margin: 15px 5px;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    position: relative;
}

.faa-date-slider .ui-slider-range {
    background: #2271b1;
    height: 100%;
    border-radius: 3px;
    position: absolute;
}

.faa-date-slider .ui-slider-handle {
    width: 18px;
    height: 18px;
    background: #2271b1;
    border-radius: 50%;
    position: absolute;
    top: -6px;
    margin-left: -9px;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.faa-date-labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    margin-top: 10px;
    font-weight: 600;
}

.faa-date-from-display,
.faa-date-to-display {
    background: #f0f6fc;
    padding: 5px 10px;
    border-radius: 3px;
    border: 1px solid #c5d9ed;
}

/* ------------------------------------------
   4. RANGE INPUTS
   ------------------------------------------ */

.faa-range-inputs,
.faa-date-inputs {
    display: flex;
    gap: 10px;
}

.faa-range-inputs input,
.faa-date-inputs input {
    flex: 1;
}

/* ------------------------------------------
   5. BUTTONS
   ------------------------------------------ */

.faa-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.faa-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
}

.faa-btn-primary {
    background: #0073aa;
    color: white;
    flex: 2;
}

.faa-btn-reset {
    background: #f0f0f0;
    color: #555;
    flex: 1;
}

/* ------------------------------------------
   6. RESULTS
   ------------------------------------------ */

.faa-results {
    margin-top: 30px;
}

.faa-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #eee;
}

.faa-count {
    font-weight: 600;
    color: #555;
    font-size: 14px;
}

.faa-sort {
    padding: 8px 15px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: white;
    font-size: 13px;
}

/* ------------------------------------------
   7. GRID & CARDS
   ------------------------------------------ */

.faa-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

.faa-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.faa-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
}

.faa-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.faa-card-content {
    padding: 20px;
}

.faa-card h3 {
    margin: 0 0 10px;
    font-size: 16px;
    line-height: 1.4;
}

.faa-card h3 a {
    color: #333;
    text-decoration: none;
}

.faa-card h3 a:hover {
    color: #0073aa;
}

.faa-card-meta {
    font-size: 12px;
    color: #888;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.faa-card-price {
    color: #0073aa;
    font-weight: 700;
    font-size: 16px;
}

.faa-card-excerpt {
    font-size: 13px;
    color: #666;
    line-height: 1.5;
}

/* ------------------------------------------
   8. PAGINATION
   ------------------------------------------ */

.faa-pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 30px;
    flex-wrap: wrap;
}

.faa-pagination a,
.faa-pagination span {
    padding: 10px 15px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    font-size: 14px;
}

.faa-pagination a {
    background: #f5f5f5;
    color: #555;
}

.faa-pagination a:hover {
    background: #0073aa;
    color: white;
}

.faa-pagination .current {
    background: #0073aa;
    color: white;
}

/* ------------------------------------------
   9. LOADING & MESSAGES
   ------------------------------------------ */

.faa-loading {
    text-align: center;
    padding: 60px;
    color: #666;
    font-size: 16px;
}

.faa-no-results {
    text-align: center;
    padding: 60px;
    color: #666;
    font-size: 16px;
    grid-column: 1/-1;
    background: #f9f9f9;
    border-radius: 5px;
}

/* ------------------------------------------
   10. LAYOUT HORIZONTAL
   ------------------------------------------ */

.faa-horizontal .faa-form {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.faa-horizontal .faa-field {
    flex: 1;
    min-width: 200px;
    margin-bottom: 0;
}

/* ------------------------------------------
   11. LAYOUT SIDEBAR - DESKTOP
   ------------------------------------------ */

.faa-sidebar-layout {
    width: 100%;
}

.faa-sidebar-wrapper {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

/* Toggle nascosto su desktop */
.faa-sidebar-toggle {
    display: none;
}

/* NASCONDI X SU DESKTOP */
.faa-sidebar-close {
    display: none !important;
}

/* Colonna sinistra: filtri */
.faa-sidebar-filters {
    flex: 0 0 280px;
    min-width: 280px;
    max-width: 280px;
}

.faa-sidebar-filters .faa-form {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    position: sticky;
    top: 20px;
}

.faa-sidebar-filters .faa-field {
    margin-bottom: 20px;
}

.faa-sidebar-filters .faa-field label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    display: block;
}

.faa-sidebar-filters .faa-checkboxes {
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
}

.faa-sidebar-filters .faa-checkboxes label {
    font-size: 13px;
    padding: 3px 0;
    cursor: pointer;
}

.faa-sidebar-filters .faa-price-slider {
    margin: 15px 0;
}

.faa-sidebar-filters .faa-buttons {
    margin-top: 25px;
}

.faa-sidebar-filters .faa-btn {
    padding: 12px;
    font-size: 14px;
}

/* Header sidebar desktop (senza X) */
.faa-sidebar-header {
    display: none; /* Nascondi completamente su desktop */
}

.faa-sidebar-footer {
    display: none; /* Nascondi completamente su desktop */
}

/* Colonna destra: risultati */
.faa-sidebar-results {
    flex: 1;
    min-width: 0;
}

.faa-sidebar-results .faa-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #eee;
}

.faa-sidebar-results .faa-count {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.faa-sidebar-results .faa-sort {
    padding: 8px 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 14px;
}

.faa-sidebar-results .faa-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

/* ------------------------------------------
   12. COLONNE PERSONALIZZABILI - SIDEBAR
   ------------------------------------------ */

.faa-sidebar-layout.faa-columns-1 .faa-sidebar-results .faa-grid {
    grid-template-columns: 1fr;
}

.faa-sidebar-layout.faa-columns-2 .faa-sidebar-results .faa-grid {
    grid-template-columns: repeat(2, 1fr);
}

.faa-sidebar-layout.faa-columns-3 .faa-sidebar-results .faa-grid {
    grid-template-columns: repeat(3, 1fr);
}

.faa-sidebar-layout.faa-columns-4 .faa-sidebar-results .faa-grid {
    grid-template-columns: repeat(4, 1fr);
}

.faa-sidebar-layout.faa-columns-5 .faa-sidebar-results .faa-grid {
    grid-template-columns: repeat(5, 1fr);
}

.faa-sidebar-layout.faa-columns-6 .faa-sidebar-results .faa-grid {
    grid-template-columns: repeat(6, 1fr);
}

/* ------------------------------------------
   13. SOTTOCATEGORIE
   ------------------------------------------ */

.faa-subcategories-container {
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
}

.faa-subcategory-group {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px dashed #eee;
    animation: fadeIn 0.3s ease;
}

.faa-subcategory-group:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.faa-subcategory-group-title {
    font-size: 11px;
    font-weight: 700;
    color: #2271b1;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #e0e0e0;
}

.faa-subcategory-item {
    display: block;
    font-weight: normal;
    margin: 4px 0;
    cursor: pointer;
    font-size: 13px;
    padding: 3px 0;
}

.faa-subcategory-item:hover {
    background: #f0f6fc;
    border-radius: 3px;
    margin: 0 -5px;
    padding: 3px 5px;
}

.faa-subcategory-item small {
    color: #999;
    font-weight: normal;
    font-size: 11px;
}

.faa-subcategories-placeholder {
    font-style: italic;
    text-align: center;
    padding: 15px 10px;
    color: #666;
}

/* ------------------------------------------
   14. ACF CHECKBOXES
   ------------------------------------------ */

.faa-acf-checkboxes {
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
}

.faa-acf-checkboxes label {
    display: block;
    font-weight: normal;
    margin: 5px 0;
    cursor: pointer;
    font-size: 13px;
    padding: 3px 0;
}

.faa-acf-checkboxes label:hover {
    background: #f0f6fc;
    border-radius: 3px;
    margin: 0 -5px;
    padding: 3px 5px;
}

.faa-acf-checkboxes input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    cursor: pointer;
}

/* Evidenziazione campo attivo */
.faa-field-acf-select .faa-checkboxes input:checked + span,
.faa-field-acf-checkbox .faa-checkboxes input:checked + span {
    color: #2271b1;
    font-weight: 600;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------
   15. RESPONSIVE - TABLET
   ------------------------------------------ */

@media (max-width: 1400px) {
    .faa-sidebar-layout.faa-columns-5 .faa-sidebar-results .faa-grid,
    .faa-sidebar-layout.faa-columns-6 .faa-sidebar-results .faa-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1200px) {
    .faa-sidebar-layout[class*="faa-columns-"] .faa-sidebar-results .faa-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 992px) {
    .faa-sidebar-layout[class*="faa-columns-"] .faa-sidebar-results .faa-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ------------------------------------------
   16. RESPONSIVE - MOBILE (max-width: 768px)
   ------------------------------------------ */

@media (max-width: 768px) {
    
    /* Layout orizzontale diventa verticale */
    .faa-horizontal .faa-form {
        flex-direction: column;
    }
    
    .faa-horizontal .faa-field {
        min-width: 100%;
        margin-bottom: 15px;
    }
    
    /* Grid base diventa singola colonna */
    .faa-grid {
        grid-template-columns: 1fr;
    }
    
    /* Results header stackato */
    .faa-results-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    /* ========================================
       SIDEBAR MOBILE COLLASSABILE
       ======================================== */
    
    .faa-sidebar-layout .faa-sidebar-wrapper {
        flex-direction: column;
        gap: 0;
    }
    
    /* MOSTRA HEADER E FOOTER SU MOBILE */
    .faa-sidebar-header,
    .faa-sidebar-footer {
        display: flex !important;
    }
    
    /* Toggle button visibile sopra i risultati */
    .faa-sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 16px 20px;
        background-color: #2271b1; 
        color: white;
        border: none;
        border-radius: 8px;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        margin-bottom: 20px;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        transition: all 0.3s ease;
    }
    
    .faa-sidebar-toggle:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0,0,0,0.15);
        filter: brightness(1.1);
    }
    
    .faa-sidebar-toggle:active {
        transform: translateY(0);
    }
    
    .faa-sidebar-toggle-text {
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .faa-sidebar-toggle-icon {
        font-size: 20px;
        transition: transform 0.3s ease;
    }
    
    .faa-sidebar-toggle[aria-expanded="true"] .faa-sidebar-toggle-icon {
        transform: rotate(180deg);
    }
    
    /* Overlay scuro dietro il pannello */
    .faa-sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.6);
        z-index: 9998;
        backdrop-filter: blur(2px);
    }
    
    .faa-sidebar-overlay.faa-sidebar-open {
        display: block;
        animation: fadeIn 0.3s ease;
    }
    
    /* Pannello laterale fisso (slide da sinistra) */
    .faa-sidebar-filters {
        position: fixed;
        top: 0;
        left: 0;
        width: 82%;
        max-width: 340px;
        height: 100vh;
        height: 100dvh;
        background: #f5f5f5;
        z-index: 9999;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        margin: 0;
        padding: 0;
        max-height: none;
        opacity: 1;
        overflow: hidden;
        box-shadow: 2px 0 20px rgba(0,0,0,0.2);
    }
    
    .faa-sidebar-filters.faa-sidebar-open {
        transform: translateX(0);
        margin-bottom: 0;
    }
    
    /* Header con titolo e X - VISIBILE SU MOBILE */
    .faa-sidebar-header {
        flex-shrink: 0;
        padding: 18px 20px;
        background: white;
        border-bottom: 1px solid #e0e0e0;
        justify-content: space-between;
        align-items: center;
        position: relative;
        z-index: 2;
    }
    
    .faa-sidebar-header h3 {
        margin: 0;
        font-size: 20px;
        font-weight: 700;
        color: #333;
    }
    
    /* MOSTRA X SU MOBILE */
    .faa-sidebar-close {
        display: flex !important;
        background: #f0f0f0;
        border: none;
        font-size: 20px;
        line-height: 1;
        cursor: pointer;
        color: #555;
        width: 36px;
        height: 36px;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: all 0.2s;
    }
    
    .faa-sidebar-close:hover {
        background: #e0e0e0;
        color: #000;
        transform: rotate(90deg);
    }
    
    /* Area scrollabile con i filtri */
    .faa-sidebar-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 20px 40px 20px 20px;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }
    
    .faa-sidebar-content .faa-form {
        background: transparent;
        padding: 0;
        margin: 0;
        border-radius: 0;
    }
    
    .faa-sidebar-content .faa-field {
        margin-bottom: 20px;
    }
    
    .faa-sidebar-content .faa-checkboxes {
        background: white;
        max-height: 200px;
    }
    
    /* Footer con pulsante chiudi - VISIBILE SU MOBILE */
    .faa-sidebar-footer {
        flex-shrink: 0;
        padding: 16px 20px;
        background: white;
        border-top: 1px solid #e0e0e0;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
        position: relative;
        z-index: 2;
    }
    
    .faa-sidebar-close-btn {
        width: 100%;
        padding: 14px 20px;
        background: #2271b1;
        color: white;
        border: none;
        border-radius: 6px;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    .faa-sidebar-close-btn:hover {
        filter: brightness(1.15);
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    }
    
    .faa-sidebar-close-btn:active {
        transform: translateY(0);
    }
    
    /* Blocco scroll pagina quando aperto */
    body.faa-sidebar-opened {
        overflow: hidden;
        touch-action: none;
    }
    
    /* Risultati sempre sotto */
    .faa-sidebar-results {
        width: 100%;
    }
    
    .faa-sidebar-results .faa-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Colonne personalizzate reset su mobile */
    .faa-sidebar-layout[class*="faa-columns-"] .faa-sidebar-results .faa-grid {
        grid-template-columns: 1fr;
    }
    
    /* Sidebar filtri reset */
    .faa-sidebar-filters {
        flex: 1 1 auto;
        max-width: 100%;
        width: 100%;
    }
    
    /* ACF checkboxes */
    .faa-acf-checkboxes {
        max-height: 200px;
        overflow-y: auto;
    }
}
