* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: sans-serif; 
}

body { 
    display: flex; 
    height: 100vh; 
    background: #1a1a1a; 
    color: white; 
    overflow: hidden; 
}

.hidden {
    display: none !important;
}

/* Interruttore Menu Bar */
.menu-toggle-btn {
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 2000;
    background: #007bff;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

/* Schermata di Login */
#loginOverlay { 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: #111; 
    z-index: 9999; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
}

.login-box { text-align: center; }

#loginOverlay input { 
    padding: 12px; 
    font-size: 1rem; 
    border: none; 
    border-radius: 5px; 
    margin-bottom: 15px; 
    width: 280px; 
    text-align: center; 
    background: #333; 
    color: white; 
}

#loginOverlay button { 
    padding: 12px 25px; 
    font-size: 1rem; 
    background: #007bff; 
    color: white; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer; 
    font-weight: bold; 
}

#errorMsg { 
    color: #ff4d4d; 
    margin-top: 15px; 
    display: none; 
}

/* Layout Principale */
#mainContent { 
    width: 100%; 
    height: 100%; 
}

.app-layout { 
    display: flex; 
    height: 100vh; 
    width: 100%; 
}

/* Sidebar e Stati di Chiusura */
.sidebar { 
    width: 320px; 
    background: #232323; 
    border-right: 1px solid #3a3a3a; 
    overflow-y: auto; 
    padding-top: 60px; /* Spazio per non coprire il bottone menu */
    transition: width 0.3s ease, min-width 0.3s ease;
    min-width: 320px;
}

.sidebar.collapsed {
    width: 0px !important;
    min-width: 0px !important;
    overflow: hidden;
    border-right: none;
}

.sidebar h2 { 
    padding: 0 20px 20px 20px; 
    font-size: 1.4rem; 
    border-bottom: 1px solid #3a3a3a; 
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #ffffff;
}

.video-group { margin-bottom: 20px; }

.group-title {
    background: #1a1a1a; 
    padding: 12px 20px;
    font-size: 0.85rem;
    font-weight: bold;
    color: #3b9eff; 
    text-transform: uppercase;
    letter-spacing: 1px;
    border-left: 4px solid #007bff; 
    border-bottom: 1px solid #2a2a2a;
}

.sidebar ul { list-style: none; }

.sidebar li { 
    padding: 12px 20px 12px 35px; 
    cursor: pointer; 
    border-bottom: 1px solid #2e2e2e; 
    font-size: 0.95rem; 
    color: #b3b3b3; 
    transition: all 0.2s ease; 
}

.sidebar li:hover { 
    background: #2d2d2d; 
    color: #ffffff;
    padding-left: 40px; 
}

.sidebar li.active { 
    background: #007bff; 
    color: #ffffff;
    font-weight: bold; 
    padding-left: 40px; 
}

/* Area Contenitore Media */
.video-container { 
    flex: 1; 
    padding: 30px; 
    background: #111111; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: all 0.3s ease;
}

.placeholder-text {
    color: #666;
    font-size: 1.2rem;
    text-align: center;
}

#mediaViewer iframe { 
    width: 100%; 
    height: 100%; 
    max-width: 1100px; 
    max-height: 700px; 
    border: none; 
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7); 
    background: #000; 
}

/* Fix per forzare la proporzione 16:9 perfetta per i video 640x360 */
#mediaViewer iframe.video-iframe {
    aspect-ratio: 16 / 9;
    max-height: 618px; 
}

/* Carosello Slide Quadrato (Ottimizzato per PC) */
.carousel-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: calc(100vh - 120px); 
    max-height: calc(100vh - 120px); 
    aspect-ratio: 1 / 1; 
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    overflow: hidden;
}

.carousel-slide {
    width: 100%;
    height: 100%;
    object-fit: contain; 
    background: #000;
}

/* Pulsanti freccia */
.carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    width: 55px;  
    height: 55px; 
    cursor: pointer;
    font-size: 1.3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.1s ease;
    user-select: none;
    z-index: 10;
}

.carousel-btn:hover {
    background: #007bff; 
    transform: translateY(-50%) scale(1.05); 
}

.carousel-btn.prev { left: 20px; }
.carousel-btn.next { right: 20px; }

/* Badge del contatore */
.carousel-counter-badge {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    padding: 6px 14px;
    font-size: 0.85rem;
    font-weight: bold;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    letter-spacing: 0.5px;
    z-index: 15;
    pointer-events: none; 
}

/* ==========================================================================
   MEDIA QUERIES: OTTIMIZZAZIONI AGGRESSIVE PER SMARTPHONE (Schermi <= 768px)
   ========================================================================== */
@media (max-width: 768px) {
    
    /* Riduce lo spazio di bordo attorno al video/slide per dare massima area visiva */
    .video-container {
        padding: 10px;
        padding-top: 60px; /* Lascia lo spazio per il pulsante del menu in alto */
    }

    /* La sidebar diventa un pannello a schermo intero sovrapposto */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1500;
        box-shadow: 5px 0 25px rgba(0,0,0,0.8);
        width: 85% !important; /* Copre quasi tutto lo schermo quando aperta */
        min-width: 85% !important;
    }
    
    .sidebar.collapsed {
        width: 0px !important;
        min-width: 0px !important;
        transform: translateX(-100%); /* Sposta il menu fuori a sinistra */
    }

    /* Ottimizzazione Video 16:9 su smartphone */
    #mediaViewer iframe.video-iframe {
        width: 100% !important;
        height: auto !important;
        max-height: none !important;
        aspect-ratio: 16 / 9; /* Garantisce che i video 640x360 si vedano enormi senza barre deformate */
    }

    /* Ottimizzazione Slide 1080x1080 su smartphone */
    .carousel-container {
        width: 95vw !important; /* Prende quasi tutta la larghezza dello schermo del telefono */
        height: 95vw !important; /* Resta un quadrato perfetto occupando il massimo spazio */
        max-width: none !important;
        max-height: none !important;
    }

    /* Ingrandisce i pulsanti del carosello così da poterli premere bene con le dita */
    .carousel-btn {
        width: 48px;
        height: 48px;
        font-size: 1.1rem;
        background: rgba(0, 0, 0, 0.75); /* Più scuro per risaltare */
    }
    
    .carousel-btn.prev { left: 8px; }
    .carousel-btn.next { right: 8px; }

    /* Rimpicciolisce il badge per non rubare spazio visivo alla slide */
    .carousel-counter-badge {
        top: 10px;
        right: 10px;
        font-size: 0.75rem;
        padding: 4px 10px;
    }
}