/* ========================================================= */
/* 1. STILI BASE & MAPPA */
/* ========================================================= */
body, html {
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, sans-serif;
    height: 100%;
    overflow: hidden;
    background-color: #f4f4f4;
    color: #333;
}

#map {
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

/* ========================================================= */
/* 2. STILI FILTRI (Menu Principale) */
/* ========================================================= */
#filters-container {
    position: fixed;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    gap: 10px;
    padding: 12px 18px;
    background-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 16px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
    max-width: 95%;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

#filters-container::-webkit-scrollbar {
    display: none;
}

.filter-button {
    padding: 10px 18px;
    margin: 0;
    border: none;
    background-color: #e9ecef;
    color: #343a40;
    cursor: pointer;
    border-radius: 20px;
    white-space: nowrap;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.filter-button:hover {
    background-color: #dee2e6;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.filter-button:active {
    transform: scale(0.98);
    box-shadow: none;
}

.filter-button.active {
    background-color: #006994;
    color: white;
    box-shadow: 0 3px 8px rgba(0, 105, 148, 0.4);
}

/* ========================================================= */
/* 3. STILI PULSANTE CENTRA MAPPA */
/* ========================================================= */
#centerMapButton {
    position: fixed;
    top: 100px;
    right: 20px;
    z-index: 100;
    width: 52px;
    height: 52px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    color: #333;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: all 0.25s ease-out;
}

#centerMapButton:hover {
    background-color: #f8f8f8;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
    transform: scale(1.05);
}

/* ========================================================= */
/* 4. STILI MODALE & DETTAGLI */
/* ========================================================= */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    /* Previene il bounce su iOS quando si swipea */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.modal.visible {
    display: flex;
    opacity: 1;
}

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

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-content {
    background: #fff;
    border-radius: 20px;
    max-width: 750px;
    width: 90%;
    padding: 30px;
    position: relative;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    max-height: 90vh;
    animation: fadeIn 0.4s ease-out forwards;
    /* Per lo swipe-down su mobile */
    overscroll-behavior: contain;
    touch-action: pan-y;
}

/* --- X DI CHIUSURA: grande, visibile, con cerchio scuro --- */
.close-button {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    font-size: 24px;
    cursor: pointer;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    line-height: 40px;
    text-align: center;
    z-index: 10;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.close-button:hover,
.close-button:active {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.6);
}

/* Indicatore visivo "tira giu per chiudere" (solo mobile) */
.modal-swipe-hint {
    display: none;
    width: 40px;
    height: 5px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    margin: 0 auto 15px auto;
}

.modal-content h2 {
    margin-top: 0;
    font-size: 2rem;
    color: #006994;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
    margin-bottom: 20px;
    padding-right: 50px; /* Spazio per la X */
}

#modalImage {
    width: 100%;
    max-height: 300px;
    border-radius: 16px;
    margin-bottom: 20px;
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.modal-details p {
    margin: 8px 0;
    font-size: 1rem;
    line-height: 1.5;
    color: #444;
}

.directions-button {
    display: block;
    text-align: center;
    padding: 12px;
    margin: 25px 0 15px 0;
    background-color: #006994;
    color: white;
    border-radius: 10px;
    font-weight: 600;
    text-decoration: none;
    transition: background-color 0.2s, box-shadow 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.directions-button:hover {
    background-color: #005a7f;
    box-shadow: 0 4px 8px rgba(0, 105, 148, 0.4);
}

/* --- PULSANTE "CHIUDI SCHEDA" IN BASSO --- */
.modal-close-footer {
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid #eee;
    text-align: center;
}

.modal-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 32px;
    background: #e74c3c;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    width: 100%;
    max-width: 300px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
    -webkit-tap-highlight-color: transparent;
}

.modal-close-btn::before {
    content: "✕";
    font-size: 14px;
}

.modal-close-btn:hover,
.modal-close-btn:active {
    background: #c0392b;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(231, 76, 60, 0.4);
}

.modal-close-btn:active {
    transform: translateY(0);
}

/* ========================================================= */
/* 5. STILI AUDIO PLAYER */
/* ========================================================= */
.audio-player {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 12px;
    padding: 12px 20px;
    background-color: #343a40;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.player-button {
    font-size: 1.4rem;
    cursor: pointer;
    background: #006994;
    border: none;
    color: #fff;
    transition: all 0.2s ease;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    flex-shrink: 0;
}

.player-button:hover {
    background: #005a7f;
    transform: scale(1.05);
}

.progress-container {
    flex-grow: 1;
    background: #555;
    height: 8px;
    border-radius: 4px;
    position: relative;
    cursor: pointer;
}

.progress-bar {
    background: #006994;
    height: 100%;
    width: 0;
    border-radius: 4px;
    position: absolute;
    top: 0;
    left: 0;
    transition: width 0.1s linear;
}

.seek-slider {
    width: 100%;
    -webkit-appearance: none;
    background: transparent;
    cursor: pointer;
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    height: 8px;
}

.seek-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #fff;
    border: 2px solid #006994;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(0,0,0,0.4);
    margin-top: -4px;
}

.time-display {
    font-size: 0.95rem;
    color: #ffffff;
    white-space: nowrap;
    flex-shrink: 0;
}

.volume-container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    justify-content: flex-end;
    color: #fff;
}

.volume-slider {
    width: 90px;
    -webkit-appearance: none;
    height: 6px;
    background: #555;
    outline: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #006994;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 3px rgba(0,0,0,0.5);
}

/* ========================================================= */
/* 6. MEDIA QUERIES (Mobile First) */
/* ========================================================= */
@media (max-width: 650px) {
    #filters-container {
        top: auto;
        bottom: 10px;
        left: 20px;
        right: 20px;
        width: auto;
        max-width: none;
        transform: translateX(0);
        padding: 8px 10px;
    }
    
    #centerMapButton {
        top: 70px;
        right: 15px;
        width: 44px;
        height: 44px;
    }

    .modal-content {
        padding: 20px;
        width: 95%;
        max-height: 92vh;
        border-radius: 16px;
        /* Su mobile il modale parte dal basso come una sheet */
        animation: slideUp 0.35s ease-out forwards;
    }
    
    .modal-content h2 {
        font-size: 1.4rem;
        padding-right: 45px;
    }

    /* X più grande su mobile */
    .close-button {
        width: 40px;
        height: 40px;
        font-size: 20px;
        top: 10px;
        right: 10px;
    }

    /* Mostra l'indicatore di swipe su mobile */
    .modal-swipe-hint {
        display: block;
    }
    
    .audio-player {
        padding: 10px 15px;
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .volume-container {
        width: 100%;
        justify-content: flex-start;
        order: 3;
    }

    .volume-slider {
        width: 100%;
    }

    /* Pulsante chiudi più grande su mobile */
    .modal-close-btn {
        padding: 16px 32px;
        font-size: 17px;
        max-width: none;
    }

    .modal-close-footer {
        margin-top: 20px;
        padding-top: 12px;
    }

    #modalImage {
        max-height: 220px;
    }
}

/* ========================================================= */
/* 7. STILI CLUSTER MARKER (Leaflet.markercluster)          */
/* ========================================================= */

.custom-cluster-icon {
    background: transparent !important;
    border: none !important;
}

.cluster-inner {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #006994 0%, #004d6b 100%);
    color: white;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 105, 148, 0.5), inset 0 0 0 3px rgba(255,255,255,0.2);
    border: 3px solid white;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    font-family: 'Inter', system-ui, sans-serif;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.custom-cluster-icon:hover .cluster-inner {
    transform: scale(1.15);
    box-shadow: 0 6px 20px rgba(0, 105, 148, 0.7), inset 0 0 0 3px rgba(255,255,255,0.4);
}

.marker-cluster-small .cluster-inner {
    width: 40px;
    height: 40px;
    font-size: 14px;
}

.marker-cluster-medium .cluster-inner {
    width: 50px;
    height: 50px;
    font-size: 18px;
}

.marker-cluster-large .cluster-inner {
    width: 60px;
    height: 60px;
    font-size: 22px;
}

.leaflet-cluster-spider-leg {
    stroke: #006994;
    stroke-width: 2;
    stroke-opacity: 0.6;
}

.marker-cluster {
    background: transparent !important;
}

.marker-cluster div {
    background: transparent !important;
    border-radius: 0 !important;
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
}