/* ========================================
   CONTAINER PRINCIPALE
   ======================================== */
.wp-block-saba-modern-gallery {
    position: relative;
    margin: 40px 0;
    max-width: 100%;
    overflow: hidden;
}

/* ========================================
   CAROUSEL LAYOUT
   ======================================== */
.saba-gallery--carousel {
    display: flex;
    gap: var(--gap, 20px);
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding: 10px 0;
    scroll-snap-type: x mandatory;
}

.saba-gallery--carousel::-webkit-scrollbar {
    display: none;
}

.saba-gallery--carousel .saba-gallery__item {
    flex: 0 0 calc((100% - (var(--gap, 20px) * 2)) / 3);
    scroll-snap-align: start;
}

/* ========================================
   GRID LAYOUT
   ======================================== */
.saba-gallery--grid {
    display: grid;
    gap: var(--gap, 20px);
    grid-template-columns: repeat(var(--cols-desktop, 3), 1fr);
}

/* ========================================
   MASONRY LAYOUT
   ======================================== */
.saba-gallery--masonry {
    column-count: var(--cols-desktop, 3);
    column-gap: var(--gap, 20px);
}

.saba-gallery--masonry .saba-gallery__item {
    break-inside: avoid;
    margin-bottom: var(--gap, 20px);
    display: inline-block;
    width: 100%;
}

/* ========================================
   ITEM SINGOLO (CON VARIABILI CSS)
   ======================================== */
.saba-gallery__item {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #f0f0f0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.saba-gallery__item:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.2);
}

/* ========================================
   IMMAGINI E VIDEO (USA VARIABILI)
   ======================================== */
.saba-gallery__item img,
.saba-gallery__item video {
    width: 100%;
    height: var(--thumb-height, 300px);
    object-fit: cover;
    object-position: var(--image-position, center);
    display: block;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Migliora rendering immagini */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    
    /* GPU acceleration */
    transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Zoom più delicato per immagini ad alta risoluzione */
.saba-gallery__item:hover img {
    transform: scale(1.05) translateZ(0);
}

/* ========================================
   CAPTION OVERLAY
   ======================================== */
.saba-gallery__caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.9), rgba(0,0,0,0.6), transparent);
    color: white;
    padding: 20px 15px 15px;
    font-size: 14px;
    line-height: 1.4;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.saba-gallery__item:hover .saba-gallery__caption {
    transform: translateY(0);
}

/* ========================================
   CLICK INDICATOR (LENTE)
   ======================================== */
.saba-gallery__item::after {
    content: '🔍';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 60px;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.saba-gallery__item:hover::after {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* ========================================
   FRECCE CAROUSEL
   ======================================== */
.saba-gallery__arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(10px);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.2);
    width: 55px;
    height: 55px;
    border-radius: 50%;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.saba-gallery__arrow:hover {
    background: rgba(0, 0, 0, 0.95);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-50%) scale(1.15);
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.saba-gallery__arrow:active {
    transform: translateY(-50%) scale(1);
}

.saba-gallery__arrow--prev {
    left: 15px;
}

.saba-gallery__arrow--next {
    right: 15px;
}

/* ========================================
   LIGHTBOX
   ======================================== */
.saba-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.96);
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.saba-lightbox.active {
    display: flex;
}

@keyframes fadeIn {
    from { 
        opacity: 0;
        backdrop-filter: blur(0px);
    }
    to { 
        opacity: 1;
        backdrop-filter: blur(20px);
    }
}

/* ========================================
   LIGHTBOX CONTENT
   ======================================== */
.saba-lightbox__content {
    position: relative;
    max-width: 95vw;
    max-height: 90vh;
    animation: zoomIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes zoomIn {
    from { 
        transform: scale(0.7) translateY(30px);
        opacity: 0;
    }
    to { 
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.saba-lightbox__content img,
.saba-lightbox__content video {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    display: block;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

/* ========================================
   CONTROLLI LIGHTBOX
   ======================================== */
.saba-lightbox__close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 36px;
    font-weight: 300;
    width: 65px;
    height: 65px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    z-index: 10;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.saba-lightbox__close:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
    transform: rotate(90deg) scale(1.1);
}

.saba-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 40px;
    font-weight: bold;
    width: 65px;
    height: 65px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.saba-lightbox__nav:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-50%) scale(1.15);
}

.saba-lightbox__nav:active {
    transform: translateY(-50%) scale(0.95);
}

.saba-lightbox__nav--prev {
    left: 25px;
}

.saba-lightbox__nav--next {
    right: 25px;
}

/* ========================================
   LIGHTBOX COUNTER E CAPTION
   ======================================== */
.saba-lightbox__counter {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 1px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.saba-lightbox__caption {
    position: absolute;
    bottom: 85px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 15px 30px;
    border-radius: 12px;
    max-width: 80%;
    text-align: center;
    font-size: 15px;
    line-height: 1.6;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* ========================================
   RESPONSIVE - TABLET
   ======================================== */
@media (max-width: 1024px) {
    .saba-gallery--grid {
        grid-template-columns: repeat(var(--cols-tablet, 2), 1fr);
    }
    
    .saba-gallery--masonry {
        column-count: var(--cols-tablet, 2);
    }
    
    .saba-gallery--carousel .saba-gallery__item {
        flex: 0 0 calc((100% - var(--gap, 20px)) / 2);
    }
    
    .saba-gallery__arrow {
        width: 50px;
        height: 50px;
        font-size: 28px;
    }
}

/* ========================================
   RESPONSIVE - MOBILE
   ======================================== */
@media (max-width: 768px) {
    .saba-gallery--grid {
        grid-template-columns: repeat(var(--cols-mobile, 1), 1fr);
    }
    
    .saba-gallery--masonry {
        column-count: var(--cols-mobile, 1);
    }
    
    .saba-gallery--carousel .saba-gallery__item {
        flex: 0 0 85%;
    }
    
    .saba-gallery__arrow {
        width: 45px;
        height: 45px;
        font-size: 24px;
    }
    
    .saba-gallery__arrow--prev {
        left: 10px;
    }
    
    .saba-gallery__arrow--next {
        right: 10px;
    }
    
    .saba-lightbox__nav,
    .saba-lightbox__close {
        width: 55px;
        height: 55px;
        font-size: 28px;
    }
    
    .saba-lightbox__nav--prev {
        left: 15px;
    }
    
    .saba-lightbox__nav--next {
        right: 15px;
    }
    
    .saba-lightbox__close {
        top: 15px;
        right: 15px;
    }
    
    .saba-lightbox__counter {
        font-size: 14px;
        padding: 10px 20px;
        bottom: 20px;
    }
    
    .saba-lightbox__caption {
        font-size: 13px;
        padding: 12px 20px;
        bottom: 70px;
        max-width: 90%;
    }
    
    /* Riduci altezza immagini su mobile se non specificato */
    .saba-gallery__item img:not([style*="height"]),
    .saba-gallery__item video:not([style*="height"]) {
        height: 250px;
    }
}

@media (max-width: 480px) {
    .wp-block-saba-modern-gallery {
        margin: 20px 0;
    }
    
    .saba-gallery--carousel {
        padding: 5px 0;
    }
    
    .saba-gallery__item::after {
        font-size: 40px;
    }
    
    .saba-lightbox__content {
        max-width: 100vw;
        max-height: 85vh;
    }
}

/* ========================================
   ACCESSIBILITÀ
   ======================================== */
.saba-gallery__arrow:focus,
.saba-lightbox__nav:focus,
.saba-lightbox__close:focus {
    outline: 3px solid rgba(255, 255, 255, 0.6);
    outline-offset: 3px;
}

/* Reduce motion per utenti con preferenze */
@media (prefers-reduced-motion: reduce) {
    .saba-gallery__item,
    .saba-gallery__item img,
    .saba-gallery__arrow,
    .saba-lightbox,
    .saba-lightbox__content {
        animation: none;
        transition: none;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .saba-gallery__arrow,
    .saba-lightbox {
        display: none !important;
    }
    
    .saba-gallery--carousel {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }
}