/*
 * Menu mobile ottimizzato con scrolling e altezza dinamica
 */

/* === HAMBURGER ICON === */
.mobile-menu-toggle {
    display: none;
    position: relative;
    width: 32px;
    height: 28px;
    cursor: pointer;
    z-index: 1100;
    border: none;
    background: transparent;
    padding: 0;
    margin-left: auto;
}

.mobile-menu-toggle span {
    display: block;
    position: absolute;
    height: 3px;
    width: 100%;
    background: #8b0000;
    border-radius: 3px;
    opacity: 1;
    left: 0;
    transform: rotate(0deg);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-menu-toggle span:nth-child(1) { top: 0px; }
.mobile-menu-toggle span:nth-child(2),
.mobile-menu-toggle span:nth-child(3) { top: 12px; }
.mobile-menu-toggle span:nth-child(4) { top: 24px; }

/* Animazione X quando aperto */
.mobile-menu-open .mobile-menu-toggle span:nth-child(1),
.mobile-menu-open .mobile-menu-toggle span:nth-child(4) {
    top: 12px;
    width: 0%;
    left: 50%;
}

.mobile-menu-open .mobile-menu-toggle span:nth-child(2) {
    transform: rotate(45deg);
}

.mobile-menu-open .mobile-menu-toggle span:nth-child(3) {
    transform: rotate(-45deg);
}

/* === MENU MOBILE RESPONSIVE === */
@media screen and (max-width: 768px) {
    .mobile-menu-toggle {
        display: block;
    }

    header .container {
        position: relative;
    }

    /* ✅ MENU CON ALTEZZA OTTIMIZZATA E SCROLLING */
    header nav {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh; /* Altezza piena dello schermo */
        background: linear-gradient(135deg, rgba(139, 0, 0, 0.98), rgba(220, 20, 60, 0.98));
        backdrop-filter: blur(20px);
        z-index: 1000;

        /* ✅ FLEX CON COLONNA E SCROLLING */
        flex-direction: column;
        overflow-y: auto; /* Permette lo scrolling verticale */
        -webkit-overflow-scrolling: touch; /* Scrolling fluido su iOS */
    }

    .mobile-menu-open header nav {
        display: flex;
    }

    /* ✅ CONTAINER INTERNO SCROLLABILE */
    header nav {
        padding: 80px 0 40px 0 !important; /* Padding ridotto */
        gap: 0 !important; /* Rimuovi gap per controllare manualmente la spaziatura */
        justify-content: flex-start;
        align-items: center;
    }

    /* ✅ LINK CON SPAZIATURA OTTIMIZZATA */
    header nav .nav-link {
        display: flex;
        color: white !important;
        font-size: 1.1rem !important; /* Dimensione ridotta */
        font-weight: 500;
        padding: 0.8rem 2rem !important; /* Padding ridotto */
        margin: 0.4rem 1rem !important; /* Margine controllato */
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(10px);
        border: 2px solid rgba(255, 215, 0, 0.3);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        text-align: center;
        min-width: 260px !important; /* Larghezza ridotta */
        max-width: calc(100% - 2rem) !important; /* Massima larghezza responsiva */
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);

        /* ✅ PREVIENI IL WRAP DEL TESTO */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    header nav .nav-link:hover,
    header nav .nav-link.active {
        background: rgba(255, 215, 0, 0.2);
        border-color: rgba(255, 215, 0, 0.7);
        transform: scale(1.02); /* Effetto più sottile */
        box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
    }

    /* ✅ ANIMAZIONI PIÙ VELOCI */
    header nav .nav-link {
        opacity: 0;
        transform: translateY(20px);
        animation: slideInUp 0.3s ease forwards;
    }

    header nav .nav-link:nth-child(1) { animation-delay: 0.05s; }
    header nav .nav-link:nth-child(2) { animation-delay: 0.1s; }
    header nav .nav-link:nth-child(3) { animation-delay: 0.15s; }
    header nav .nav-link:nth-child(4) { animation-delay: 0.2s; }
    header nav .nav-link:nth-child(5) { animation-delay: 0.25s; }
    header nav .nav-link:nth-child(6) { animation-delay: 0.3s; }
    header nav .nav-link:nth-child(7) { animation-delay: 0.35s; }
    header nav .nav-link:nth-child(8) { animation-delay: 0.4s; }
    header nav .nav-link:nth-child(9) { animation-delay: 0.45s; }

    /* ✅ BLOCCA LO SCROLL DEL BODY */
    .mobile-menu-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100vh;
    }
}

/* === MOBILE PICCOLO - OTTIMIZZAZIONI ULTERIORI === */
@media screen and (max-width: 480px) {
    header nav {
        padding: 70px 0 30px 0;
    }

    header nav .nav-link {
        font-size: 1rem;
        padding: 0.7rem 1.5rem;
        margin: 0.3rem 0.8rem;
        min-width: 240px;
    }

    header h1 {
        font-size: 1.7rem;
    }
}

/* === MOBILE MOLTO PICCOLO === */
@media screen and (max-width: 360px) {
    header nav .nav-link {
        font-size: 0.95rem;
        padding: 0.6rem 1.2rem;
        margin: 0.25rem 0.5rem;
        min-width: 220px;
    }
}

/* === SCROLLBAR PERSONALIZZATA PER IL MENU === */
@media screen and (max-width: 768px) {
    header nav::-webkit-scrollbar {
        width: 4px;
    }

    header nav::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 2px;
    }

    header nav::-webkit-scrollbar-thumb {
        background: rgba(255, 215, 0, 0.5);
        border-radius: 2px;
    }

    header nav::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 215, 0, 0.7);
    }
}

/* === ANIMAZIONI === */
@keyframes slideInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === ACCESSIBILITÀ === */
.mobile-menu-toggle:focus {
    outline: 2px solid rgba(255, 215, 0, 0.7);
    outline-offset: 2px;
}

/* Riduce le animazioni se l'utente le ha disabilitate */
@media (prefers-reduced-motion: reduce) {
    .mobile-menu-toggle span,
    .nav-link,
    header nav {
        transition: none;
        animation: none;
    }
}

/* === INDICATORE DI SCROLL (OPZIONALE) === */
@media screen and (max-width: 768px) {
    header nav::after {
        content: '';
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        height: 20px;
        background: linear-gradient(to top, rgba(139, 0, 0, 0.98), transparent);
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    /* Mostra l'indicatore quando c'è contenuto scrollabile */
    header nav.has-scroll::after {
        opacity: 1;
    }
}