/* ========================================
   GALERIE ET VISIONNEUSE — components/galerie_photos.html, partagé par la fiche logement
   et la fiche conciergerie (chargé par ces deux pages), piloté par static/js/visionneuse.js.
   ----------------------------------------
   - Galerie 1 grande + 4 petites : modificateurs --n0 à --n4 (nombre de vignettes), pour
     que la grille se remplisse sans trou quand il y a moins de 5 photos ;
   - --carousel : défilement horizontal plein cadre sur mobile, avec compteur « 1 / 5 » ;
   - .detail-lightbox : visionneuse plein écran.
   ======================================== */

/* Galerie : 1 grande + 4 petites en grille, coins arrondis 16px */
.gallery-wrap {
    position: relative;
    margin-bottom: 48px;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 8px;
    border-radius: var(--radius-xl);
    overflow: hidden;
    margin-bottom: 40px;
    height: clamp(300px, 36vw, 500px);
    position: relative;
}

.gallery-wrap .gallery {
    margin-bottom: 0;
}

.gallery__main,
.gallery__thumb {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: var(--color-surface);
    overflow: hidden;
    cursor: pointer;
}

.gallery__main {
    grid-column: 1 / 3;
    grid-row: 1 / 3;
}

.gallery__main img,
.gallery__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: filter 0.2s var(--ease);
}

.gallery__main:hover img,
.gallery__thumb:hover img {
    filter: brightness(0.86);
}

.gallery__main:focus-visible,
.gallery__thumb:focus-visible {
    outline: 3px solid var(--color-text);
    outline-offset: -3px;
}

.gallery__placeholder {
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    color: var(--color-border-strong);
    background: linear-gradient(135deg, var(--color-surface) 0%, var(--color-primary-light) 100%);
}

/* Moins de 5 photos : la grille s'adapte au lieu de laisser des trous */
.gallery--n0 .gallery__main {
    grid-column: 1 / -1;
}

.gallery--n1 .gallery__thumb,
.gallery--n2 .gallery__thumb {
    grid-column: 3 / 5;
}

.gallery--n1 .gallery__thumb {
    grid-row: 1 / 3;
}

.gallery--n3 .gallery__thumb:nth-child(2) {
    grid-column: 3 / 5;
}

/* Bouton « Afficher toutes les photos » */
.gallery__show-all {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 8px 16px;
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-text);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s var(--ease), transform 0.1s var(--ease);
    z-index: 2;
}

.gallery__show-all:hover {
    background: var(--color-surface);
}

.gallery__show-all:active {
    transform: scale(0.97);
}

/* Compteur « 1 / 5 » : seulement sur le carrousel mobile */
.gallery__counter {
    display: none;
}

/* Mobile : galerie en carrousel plein cadre */
@media (max-width: 767px) {
    .gallery.gallery--carousel {
        display: flex;
        height: auto;
        gap: 0;
        border-radius: 0;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
    }

    .gallery.gallery--carousel::-webkit-scrollbar {
        display: none;
    }

    .gallery.gallery--carousel .gallery__main,
    .gallery.gallery--carousel .gallery__thumb {
        display: block;
        flex: 0 0 100%;
        height: auto;
        aspect-ratio: 4 / 3;
        scroll-snap-align: start;
    }

    .gallery.gallery--carousel .gallery__placeholder {
        aspect-ratio: 4 / 3;
    }

    .gallery-wrap .gallery__counter {
        display: block;
        position: absolute;
        right: 16px;
        bottom: 16px;
        padding: 4px 12px;
        border-radius: var(--radius-pill);
        background: var(--color-scrim);
        color: var(--color-on-dark);
        font-size: 12px;
        font-weight: 700;
        pointer-events: none;
    }

    .gallery-wrap .gallery__show-all {
        right: auto;
        left: 16px;
        bottom: 12px;
        min-height: 36px;
        padding: 6px 12px;
        border-color: transparent;
        font-size: 13px;
        box-shadow: var(--shadow-sm);
    }
}

/* Visionneuse plein écran */
.detail-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-modale);
    align-items: center;
    justify-content: center;
}

.detail-lightbox--open {
    display: flex;
    animation: lightboxFadeIn 0.3s ease-out;
}

@keyframes lightboxFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.detail-lightbox--open .detail-lightbox__image-wrapper {
    animation: lightboxZoomIn 0.3s var(--ease);
}

@keyframes lightboxZoomIn {
    from {
        opacity: 0;
        transform: scale(0.92);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.detail-lightbox__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
}

/* Bouton ✕ : .btn-fermer--sombre (components.css), ici son placement seul */
.detail-lightbox__close {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 2;
}

.detail-lightbox__counter {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--color-on-dark);
    font-size: var(--font-size-sm);
    font-weight: 600;
    z-index: 2;
}

.detail-lightbox__arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: var(--color-on-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    transition: background-color 0.2s;
}

.detail-lightbox__arrow:hover {
    background: rgba(255, 255, 255, 0.3);
}

.detail-lightbox__arrow:disabled {
    opacity: 0.3;
    cursor: default;
}

.detail-lightbox__arrow--left {
    left: 24px;
}

.detail-lightbox__arrow--right {
    right: 24px;
}

.detail-lightbox__image-wrapper {
    position: relative;
    z-index: 1;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.detail-lightbox__image {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    transition: opacity 0.2s;
}

@media (max-width: 767px) {
    .detail-lightbox__arrow--left {
        left: 8px;
    }
    .detail-lightbox__arrow--right {
        right: 8px;
    }
    .detail-lightbox__arrow {
        width: 44px;
        height: 44px;
    }
}
