/* ==========================================================================
   Carosello Galleria - CSS con Design Tokens
   ========================================================================== */

/* Import design tokens from main styles */
:root {
    --accent: #e79e3a;
    --accent-2: #c33323;
    --ink: #000000;
    --white: #ffffff;
}

/* Reset e base */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: #111;
    color: #fff;
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
}

/* Container principale carosello */
#carousel {
    min-height: 100vh;
    width: 100vw;
    display: grid;
    place-items: center;
    background: #111;
    position: relative;
}

/* Media elementi (immagini e video) */
.carousel__media {
    max-width: 92vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    /* Performance optimizations */
    will-change: transform;
    backface-visibility: hidden;
}

/* ==========================================================================
   Bottoni Navigazione Principali
   ========================================================================== */
/* Bottoni Freccia Eleganti */
#prev, #next {
    position: fixed !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    background: rgba(231, 158, 58, 0.85) !important; /* var(--accent) translucent */
    border: 1px solid rgba(255, 255, 255, 0.4) !important;
    padding: 0 !important;
    cursor: pointer !important;
    color: white !important;
    font-size: 24px !important;
    font-weight: bold !important;
    border-radius: 50% !important;
    min-width: 52px !important;
    min-height: 52px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 999 !important;
    backdrop-filter: blur(8px) !important;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3) !important;
    transition: all 0.2s ease !important;
}

#prev {
    left: 16px;
}

#next {
    right: 16px;
}

/* Hover e focus states eleganti */
#prev:hover, #next:hover,
#prev:focus, #next:focus {
    background: rgba(231, 158, 58, 1) !important; /* Solid accent on hover */
    outline: 2px solid white !important;
    outline-offset: 2px !important;
    transform: translateY(-50%) scale(1.1) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
}

#prev:active, #next:active {
    transform: translateY(-50%) scale(0.95) !important;
    background: rgba(231, 158, 58, 1) !important;
}

/* ==========================================================================
   Pulsante Chiudi (Mobile)
   ========================================================================== */
#close {
    position: fixed;
    top: 16px;
    right: 16px;
    background: rgba(195, 51, 35, 0.9); /* var(--accent-2) with transparency */
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--white);
    font-size: 24px;
    font-weight: normal;
    border-radius: 50%;
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
    min-width: 40px;
    min-height: 40px;
    display: flex !important; /* Force visible for testing */
    align-items: center;
    justify-content: center;
    user-select: none;
    z-index: 9999;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    /* Debug border */
    border: 1px solid rgba(255, 255, 255, 0.5);
}

#close:hover, #close:focus {
    background: var(--accent-2); /* Solid accent-2 on hover */
    outline: 2px solid var(--white);
    outline-offset: 2px;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

#close:active {
    transform: scale(0.95);
}

/* ==========================================================================
   Edge Zones - Sottili fasce laterali per navigazione
   ========================================================================== */
.nav-edge {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 20px; /* Sottile edge zone */
    height: 200px; /* Altezza limitata, non full screen */
    z-index: 5;
    display: none; /* Hidden by default, shown on mobile */
    cursor: pointer;
    user-select: none;
    pointer-events: auto;
    /* Semi-transparent for debugging */
    background: rgba(231, 158, 58, 0.1);
    border-radius: 0 8px 8px 0;
}

.nav-edge--prev {
    left: 0;
    border-radius: 0 8px 8px 0;
}

.nav-edge--next {
    right: 0;
    border-radius: 8px 0 0 8px;
}

.nav-edge:active {
    background: rgba(231, 158, 58, 0.3);
}

/* ==========================================================================
   No-Touch Belt - Area libera per controlli video
   ========================================================================== */
.no-touch-belt {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px; /* Fascia di 80px libera dai controlli */
    pointer-events: none; /* Trasparente agli eventi */
    z-index: 1;
}

/* Edge zones non devono interferire con la belt */
.nav-edge {
    bottom: 80px; /* Lascia spazio ai controlli video */
}

/* Sezione rimossa - stili unificati sopra */

/* Desktop: hitbox più grandi */
@media (min-width: 1025px) {
    #prev, #next {
        min-width: 56px;
        min-height: 56px;
        font-size: 28px;
    }
}

/* Mobile: hitbox ottimali per touch */
@media (max-width: 640px) {
    #prev, #next {
        min-width: 52px;
        min-height: 52px;
        font-size: 24px;
    }
}

/* Animazione apparizione elementi mobile */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#close {
    animation: fadeInUp 0.3s ease 0.2s both;
}

.nav-area {
    animation: fadeInUp 0.3s ease 0.1s both;
}

/* ==========================================================================
   Responsive Design - Tablet
   ========================================================================== */
@media (max-width: 1024px) and (min-width: 641px) {
    .carousel__media {
        max-width: 90vw;
        max-height: 82vh;
    }
    
    #prev, #next {
        padding: 10px 14px;
        font-size: 22px;
        min-width: 48px;
        min-height: 48px;
        z-index: 1000;
    }
    
    #prev {
        left: 16px;
    }
    
    #next {
        right: 16px;
    }
}

/* ==========================================================================
   Responsive Design - Mobile
   ========================================================================== */
/* ==========================================================================
   Desktop: Auto-hide frecce
   ========================================================================== */
@media (min-width: 1025px) {
    #prev, #next {
        opacity: 1 !important; /* Force visible for testing */
        transition: opacity 0.3s ease;
    }
    
    #carousel:hover #prev,
    #carousel:hover #next {
        opacity: 1 !important;
    }
    
    /* No edge zones su desktop */
    .nav-edge {
        display: none;
    }
}

/* ==========================================================================
   Mobile: Edge zones attive, bottoni visibili
   ========================================================================== */
@media (max-width: 640px) {
    .carousel__media {
        max-width: 95vw;
        max-height: 80vh;
    }
    
    /* Mostra il pulsante chiudi su mobile */
    #close {
        display: flex !important;
        top: calc(16px + env(safe-area-inset-top, 0px));
        right: calc(16px + env(safe-area-inset-right, 0px));
    }
    
    /* Mostra edge zones su mobile */
    .nav-edge {
        display: block;
    }
    
    /* Frecce sempre visibili su mobile */
    #prev, #next {
        opacity: 1;
    }
    
    /* Ottimizza per orientamento portrait */
    @media (orientation: portrait) {
        .carousel__media {
            max-width: 98vw;
            max-height: 75vh;
        }
        
        #prev, #next {
            top: 45%;
        }
    }
    
    /* Ottimizza per orientamento landscape */
    @media (orientation: landscape) {
        .carousel__media {
            max-width: 92vw;
            max-height: 85vh;
        }
    }
}

/* Focus visibile per accessibilità */
*:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Cursore per swipe su touch */
#carousel {
    touch-action: pan-y pinch-zoom;
    cursor: grab;
}

#carousel:active {
    cursor: grabbing;
}

/* ==========================================================================
   Indicatori di Stato
   ========================================================================== */
.carousel__indicators {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 16px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    font-size: 14px;
    color: white;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 8px;
}

.carousel__counter {
    font-variant-numeric: tabular-nums;
    min-width: 45px;
    text-align: center;
}

.carousel__title {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.8;
}

/* ==========================================================================
   Feedback Visivi per Touch
   ========================================================================== */
.carousel__media {
    transition: transform 0.1s ease;
}

.carousel__media:active {
    transform: scale(0.98);
}

/* Ripple effect per bottoni */
#prev, #next {
    position: relative;
    overflow: hidden;
}

#prev::after, #next::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
}

#prev:active::after, #next:active::after {
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Responsive - Indicatori
   ========================================================================== */
@media (max-width: 640px) {
    .carousel__indicators {
        bottom: 16px;
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .carousel__title {
        max-width: 150px;
    }
    
    .carousel__counter {
        min-width: 40px;
    }
    
    /* Safe area per dispositivi con notch */
    .carousel__indicators {
        bottom: calc(16px + env(safe-area-inset-bottom));
    }
    
    #close {
        top: calc(16px + env(safe-area-inset-top));
        right: calc(16px + env(safe-area-inset-right));
    }
}

/* ==========================================================================
   Miglioramenti per dispositivi con notch
   ========================================================================== */
@supports (padding: max(0px)) {
    .carousel__indicators {
        bottom: max(24px, 24px + env(safe-area-inset-bottom));
    }
    
    @media (max-width: 640px) {
        .carousel__indicators {
            bottom: max(16px, 16px + env(safe-area-inset-bottom));
        }
        
        #close {
            top: max(16px, 16px + env(safe-area-inset-top));
            right: max(16px, 16px + env(safe-area-inset-right));
        }
    }
}
