/* =========================================================
   GALLERY.CSS – Premium responsive gallery + lightbox
   ========================================================= */
/* =========================================================
   GALLERY SECTION
   ========================================================= */
.gallery-section {
    margin-top: clamp(2.5rem, 5vw, 4rem);
    text-align: center;
}
.gallery-title {
    margin: 0 0 0.5rem;
    color: #2c3e50;
    font-size: clamp(1.7rem, 3vw, 2.2rem);
    line-height: 1.2;
    letter-spacing: -0.02em;
}
.gallery-subtitle {
    margin: 0 auto clamp(1.5rem, 4vw, 2.5rem);
    max-width: 700px;
    color: #7f8c8d;
    font-style: italic;
    line-height: 1.6;
}
/* =========================================================
   GALLERY GRID
   ========================================================= */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(0.9rem, 2vw, 1.5rem);
    padding: 0 1rem;
}
/* =========================================================
   GALLERY ITEM
   ========================================================= */
.gallery-item {
    position: relative;
    aspect-ratio: 4 / 3;
    margin: 0;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 14px;
    background: #fff;
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.08),
        0 1px 3px rgba(0, 0, 0, 0.04);
    cursor: pointer;
    transform: translateZ(0);
    transition:
        transform 0.45s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.45s cubic-bezier(0.22, 1, 0.36, 1),
        border-color 0.3s ease;
    isolation: isolate;
}
/* Immagine */
.gallery-item img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    transform: scale(1.001);
    transform-origin: center center;
    transition:
        transform 0.7s cubic-bezier(0.22, 1, 0.36, 1),
        filter 0.5s ease;
    will-change: transform;
}
/* Overlay cinematografico */
.gallery-item::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    background:
        linear-gradient(
            180deg,
            rgba(0, 0, 0, 0) 45%,
            rgba(0, 0, 0, 0.08) 65%,
            rgba(0, 0, 0, 0.72) 100%
        );
    opacity: 0.8;
    pointer-events: none;
    transition:
        opacity 0.45s ease;
}
/* Highlight leggero */
.gallery-item::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 2;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: inherit;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.35s ease;
}
/* =========================================================
   HOVER DESKTOP
   ========================================================= */
@media (hover: hover) and (pointer: fine) {
    .gallery-item:hover {
        transform: translateY(-6px);
        border-color: rgba(0, 0, 0, 0.1);
        box-shadow:
            0 18px 35px rgba(0, 0, 0, 0.14),
            0 5px 12px rgba(0, 0, 0, 0.08);
    }
    .gallery-item:hover img {
        transform: scale(1.065);
        filter: saturate(1.04) contrast(1.02);
    }
    .gallery-item:hover::before {
        opacity: 1;
    }
    .gallery-item:hover::after {
        opacity: 1;
    }
}
/* =========================================================
   ACCESSIBILITY / KEYBOARD FOCUS
   ========================================================= */
.gallery-item:focus {
    outline: none;
}
.gallery-item:focus-visible {
    outline: 3px solid rgba(44, 62, 80, 0.65);
    outline-offset: 4px;
}
/* =========================================================
   CAPTION
   ========================================================= */
.gallery-item figcaption {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 3;
    padding: 2.5rem 1rem 0.9rem;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.02em;
    text-align: left;
    text-shadow:
        0 1px 2px rgba(0, 0, 0, 0.35),
        0 2px 8px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    transform: translateY(2px);
    transition:
        transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
        opacity 0.35s ease;
}
@media (hover: hover) and (pointer: fine) {
    .gallery-item:hover figcaption {
        transform: translateY(0);
    }
}
/* =========================================================
   LIGHTBOX
   ========================================================= */
/*.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 3vw, 2rem);
    box-sizing: border-box;
    overscroll-behavior: contain;
}*/
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 3vw, 2rem);
    box-sizing: border-box;
    overscroll-behavior: contain;

    opacity: 1;
    visibility: visible;
    transition:
        opacity 0.22s ease,
        visibility 0s linear 0s;
}

/*
.lightbox[hidden] {
    display: none;
}*/
.lightbox[hidden] {
    display: flex;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 0.22s ease,
        visibility 0s linear 0.22s;
}
/* =========================================================
   LIGHTBOX OVERLAY
   ========================================================= */
.lightbox-overlay {
    position: absolute;
    inset: 0;
    background:
        rgba(7, 10, 14, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
}
/* =========================================================
   LIGHTBOX CONTENT
   ========================================================= */
.lightbox-content {
    position: relative;
    z-index: 1;
    width: min(1200px, 92vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: lightboxIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.lightbox:not([hidden]) .lightbox-content {
    transform: scale(1);
    opacity: 1;
}
@keyframes lightboxIn {
    from {
        opacity: 0;
        transform: scale(0.94) translateY(12px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}
/* =========================================================
   LIGHTBOX IMAGE
   ========================================================= */
.lightbox-image {
    display: block;
    width: auto;
    max-width: min(100%, 1200px);
    max-height: 78vh;
    height: auto;
    object-fit: contain;
    border-radius: 10px;
    box-shadow:
        0 25px 70px rgba(0, 0, 0, 0.55),
        0 5px 20px rgba(0, 0, 0, 0.3);
    user-select: none;
    -webkit-user-drag: none;
    opacity: 0;
    transition:
        opacity 0.2s ease,
        transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.lightbox-image.is-loaded {
    opacity: 1;
}
/* =========================================================
   CLOSE BUTTON
   ========================================================= */
.lightbox-close {
    position: absolute;
    top: -1.5rem;
    right: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition:
        background 0.25s ease,
        transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
        border-color 0.25s ease;
}
.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.35);
    transform: rotate(90deg);
}
.lightbox-close:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.65);
    outline-offset: 3px;
}
/* =========================================================
   PREV / NEXT
   ========================================================= */

.lightbox-prev,
.lightbox-next {
    position: fixed;
    top: 50%;
    z-index: 3;

    width: 52px;
    height: 52px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 50%;

    background: rgba(255, 255, 255, 0.1);

    color: #fff;

    font-size: 1.8rem;
    line-height: 1;

    cursor: pointer;

    transform: translateY(-50%);

    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    transition:
        background 0.25s ease,
        border-color 0.25s ease,
        transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);

    box-sizing: border-box;
}

.lightbox-prev {
    left: clamp(0.75rem, 2vw, 2rem);
}

.lightbox-next {
    right: clamp(0.75rem, 2vw, 2rem);
}

.lightbox-prev:hover,
.lightbox-next:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.35);
}

.lightbox-prev:hover {
    transform: translate(-3px, -50%);
}

.lightbox-next:hover {
    transform: translate(3px, -50%);
}

.lightbox-prev:focus-visible,
.lightbox-next:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.65);
    outline-offset: 3px;
}
/* =========================================================
   CAPTION + COUNTER
   ========================================================= */
.lightbox-caption {
    width: 100%;
    max-width: 900px;
    margin-top: 1rem;
    color: #fff;
    font-size: clamp(1rem, 2vw, 1.2rem);
    font-weight: 500;
    line-height: 1.45;
    text-align: center;
    text-shadow:
        0 2px 8px rgba(0, 0, 0, 0.6);
}
.lightbox-counter {
    margin-top: 0.4rem;
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
}
/* =========================================================
   TABLET
   ========================================================= */
@media (max-width: 900px) {
    .gallery-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .lightbox-content {
        width: min(94vw, 1000px);
    }
}
/* =========================================================
   MOBILE
   ========================================================= */
@media (max-width: 600px) {
    .gallery-section {
        margin-top: 2rem;
    }
    .gallery-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
        padding: 0 0.75rem;
    }
    .gallery-item {
        border-radius: 10px;
    }
    .gallery-item figcaption {
        padding: 2rem 0.7rem 0.65rem;
        font-size: 0.9rem;
    }
    .lightbox {
        padding: 0.75rem;
    }
    .lightbox-content {
        width: 100%;
        max-height: 94vh;
    }
    .lightbox-image {
        max-width: 100%;
        max-height: 76vh;
        border-radius: 8px;
    }
    .lightbox-close {
        top: -1.25rem;
        right: 0;
        width: 44px;
        height: 44px;
        font-size: 1.8rem;
    }
    .lightbox-prev,
    .lightbox-next {
        width: 44px;
        height: 44px;
        font-size: 1.4rem;
        background: rgba(255, 255, 255, 0.14);
    }
    .lightbox-caption {
        padding: 0 2.5rem;
        font-size: 0.95rem;
    }
    .lightbox-counter {
        font-size: 0.8rem;
    }
}
/* =========================================================
   VERY SMALL MOBILE
   ========================================================= */
@media (max-width: 380px) {
    .gallery-grid {
        gap: 0.6rem;
        padding: 0 0.6rem;
    }
    .gallery-item figcaption {
        font-size: 0.82rem;
    }
    .lightbox-prev,
    .lightbox-next {
        width: 40px;
        height: 40px;
    }
}
/* =========================================================
   REDUCED MOTION
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
    .gallery-item,
    .gallery-item img,
    .gallery-item::before,
    .gallery-item::after,
    .gallery-item figcaption,
    .lightbox-content,
    .lightbox-close,
    .lightbox-prev,
    .lightbox-next {
        transition: none;
        animation: none;
    }
    .gallery-item:hover {
        transform: none;
    }
    .gallery-item:hover img {
        transform: none;
    }
}