/* ==================== BUTTON TRIGGER ==================== */
.btn-open-tabs {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
    color: var(--color-white);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    transition: all 0.3s ease;
    z-index: 50 !important;
}

.btn-open-tabs:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.6);
}

.btn-open-tabs:active {
    transform: scale(0.95);
}

/* Mostra pulsante SOLO su TABLET E MOBILE (fino a 1024px) */
@media (max-width: 1024px) {
    .btn-open-tabs.show {
        display: flex;
    }
}

/* Su DESKTOP il pulsante NON esiste */
@media (min-width: 1025px) {
    .btn-open-tabs {
        display: none !important;
    }
}

/* ==================== MODAL BACKDROP ==================== */
.tabs-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    z-index: 999;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.tabs-modal-backdrop.active {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* DESKTOP: backdrop posizionato come il side panel - SEMPRE VISIBILE */
@media (min-width: 1025px) {
    .tabs-modal-backdrop {
        display: block !important;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: auto;
        width: 320px;
        max-width: 40%;
        inset: unset;
        background: rgba(0, 0, 0, 0.3);
        z-index: 1199;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
}

/* DESKTOP 1400px: adatta larghezza come side panel */
@media (min-width: 1025px) and (max-width: 1400px) {
    .tabs-modal-backdrop {
        width: 300px;
        max-width: 35%;
    }
}

/* TABLET E MOBILE (fino a 1024px): backdrop nascosto di default */
@media (max-width: 1024px) {
    .tabs-modal-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 998 !important;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        background: rgba(0, 0, 0, 0);
        backdrop-filter: blur(0px);
    }
    
    .tabs-modal-backdrop.active {
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
}

/* ==================== MODAL CONTAINER ==================== */
.tabs-modal {
    background: var(--color-white);
    box-shadow: var(--shadow-lg);
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* DESKTOP: sidebar fissa SEMPRE APERTA (da 1025px in su) */
@media (min-width: 1025px) {
    .tabs-modal {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 320px;
        max-width: 40%;
        height: 100vh;
        border-radius: 0;
        max-height: 100vh;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
        border-left: 1px solid var(--border-color);
        z-index: 1199;
        /* SEMPRE VISIBILE SU DESKTOP */
        transform: none;
        visibility: visible;
        opacity: 1;
    }
}

@media (min-width: 1025px) and (max-width: 1400px) {
    .tabs-modal {
        width: 300px;
        max-width: 35%;
    }
}

/* TABLET E MOBILE (fino a 1024px): CHIUSO DI DEFAULT, si apre al click */
@media (max-width: 1024px) {
    .tabs-modal {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: none !important;
        border-radius: var(--border-radius) var(--border-radius) 0 0;
        max-height: 85vh;
        transform: translateY(100%);
        transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), 
                    visibility 0.4s ease,
                    opacity 0.4s ease;
        z-index: 999 !important;
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
    }

    /* Stato APERTO su tablet/mobile: rimuovi classe 'collapsed' */
    .tabs-modal:not(.collapsed) {
        transform: translateY(0);
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
    }

    /* Stato CHIUSO su tablet/mobile: con classe 'collapsed' */
    .tabs-modal.collapsed {
        transform: translateY(100%);
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
    }

    /* Nascondi contenuto quando collassato su tablet/mobile */
    .tabs-modal.collapsed .tabs-modal-header,
    .tabs-modal.collapsed .tabs-modal-nav,
    .tabs-modal.collapsed .tabs-modal-content {
        display: none;
    }
}

/* ==================== MODAL HEADER ==================== */
.tabs-modal-header {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    color: var(--color-white);
    flex-shrink: 0;
    gap: 8px;
    min-height: 48px;
}

.tabs-modal-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tabs-modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--color-white);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 18px;
}

.tabs-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Su DESKTOP nascondi il bottone X perché il modal è sempre aperto */
@media (min-width: 1025px) {
    .tabs-modal-close {
        display: none;
    }
}

/* ==================== TAB NAVIGATION ==================== */
.tabs-modal-nav {
    display: flex;
    background-color: #e9ecef;
    border-bottom: 1px solid var(--color-gray-200);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
}

.tabs-modal-nav::-webkit-scrollbar {
    height: 4px;
}

.tabs-modal-nav::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.tabs-modal-nav::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 2px;
}

.tab-button {
    flex: 1;
    padding: 14px 12px;
    text-align: center;
    cursor: pointer;
    background-color: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--color-gray-700);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-family: inherit;
    white-space: nowrap;
    transition: all 0.3s ease;
    min-width: 100px;
}

.tab-button:hover {
    background-color: #dee2e6;
}

.tab-button.active {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
    border-bottom-color: var(--color-accent);
    color: var(--color-white);
}

/* ==================== TAB CONTENT ==================== */
.tabs-modal-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 10px 20px 10px;
    -webkit-overflow-scrolling: touch;
}

.tabs-modal-content::-webkit-scrollbar {
    width: 6px;
}

.tabs-modal-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.tabs-modal-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-pane.active {
    display: block;
}

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

.tab-pane h2 {
    margin-bottom: 15px;
    color: var(--color-gray-800);
    font-size: 18px;
}

.tab-pane p {
    line-height: 1.6;
    color: var(--color-gray-700);
    margin-bottom: 15px;
    font-size: 11px;
}

.tab-pane h3 {
    margin: 20px 0 10px 0;
    color: var(--color-gray-800);
    font-size: 16px;
}

.tab-pane ul {
    margin: 10px 0 15px 20px;
    color: var(--color-gray-700);
}

.tab-pane li {
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 1.5;
}

/* ==================== DEMO CONTENT ==================== */
.demo-container {
    max-width: 1200px;
    margin: 40px auto;
    padding: 20px;
    background: var(--color-white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
}

.demo-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-gray-800);
    margin-bottom: 20px;
}

.demo-description {
    color: var(--color-gray-700);
    line-height: 1.8;
    margin-bottom: 20px;
}

/* ==================== CORREZIONE Z-INDEX MOBILE E TABLET ==================== */
@media (max-width: 1024px) {
    /* Backdrop dietro il modal ma sopra la mappa */
    .tabs-modal-backdrop {
        z-index: 998 !important;
    }

    /* Modal sopra il backdrop */
    .tabs-modal {
        z-index: 999 !important;
    }

    /* Abbassa gli elementi della mappa */
    .map-container {
        z-index: 1 !important;
        position: relative !important;
    }

    .map-area {
        z-index: 1 !important;
        position: relative !important;
    }

    /* Abbassa i controlli mappa */
    .map-controls {
        z-index: 10 !important;
    }

    /* Abbassa l'attribution di Leaflet */
    .leaflet-control-attribution {
        z-index: 10 !important;
    }

    /* Abbassa i popup della mappa */
    .leaflet-popup-pane {
        z-index: 5 !important;
    }

    .leaflet-marker-pane {
        z-index: 5 !important;
    }

    /* Assicura che i controlli Leaflet rimangono visibili ma sotto il modal */
    .leaflet-control {
        z-index: 10 !important;
    }

    /* Pulsante FAB (apri tabs) sopra tutto quando modal è chiuso */
    .btn-open-tabs {
        z-index: 50 !important;
    }

    /* Quando il modal è aperto, il FAB potrebbe essere nascosto dal backdrop */
    .tabs-modal-backdrop.active {
        z-index: 998 !important;
    }
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 480px) {
    .btn-open-tabs {
        width: 50px;
        height: 50px;
        font-size: 20px;
        bottom: 380px;
        right: 20px;
    }

    .tabs-modal-nav {
        gap: 0;
    }

    .tab-button {
        min-width: 80px;
        font-size: 10px;
        padding: 12px 8px;
    }

    .tabs-modal-header {
        padding: 12px 16px;
    }

    .tabs-modal-title {
        font-size: 16px;
    }

    .tabs-modal-close {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .tabs-modal-content {
        padding: 16px;
    }
}