/**
 * Styles pour ACF Gallery
 */

.acf-gallery-taxonomy {
    margin: 20px 0;
}

/* Fallback sans JavaScript : ordre horizontal ACF, sans reordonner le DOM. */
.acf-gallery-taxonomy .acf-gallery-grid {
    display: grid;
    grid-template-columns: repeat(var(--acf-gallery-columns, 3), minmax(0, 1fr));
    gap: 20px;
    width: 100%;
    align-items: start;
    column-count: auto !important;
    -webkit-column-count: auto !important;
}

/* Masonry JS : première rangée de gauche à droite, puis placement dans la
   colonne la plus courte pour équilibrer les hauteurs, sans recadrage. */
.acf-gallery-taxonomy .acf-gallery-grid.acf-gallery-grid--masonry {
    display: block;
    position: relative;
}
.acf-gallery-taxonomy .acf-gallery-grid--masonry > .acf-gallery-item {
    position: absolute;
    display: block;
    margin: 0;
    min-width: 0;
    box-sizing: border-box;
}

.acf-gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    background: transparent !important;
    display: block;
    width: 100%;
    margin-bottom: 0;
    break-inside: avoid;
    page-break-inside: avoid;
}

.acf-gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.acf-gallery-link {
    display: block;
    text-decoration: none;
    position: relative;
    overflow: hidden;
    background: transparent !important;
    border-radius: 8px;
    width: 100%;
    line-height: 0;
}

.acf-gallery-image {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    transition: transform 0.3s ease;
    background: transparent !important;
    border: none;
    vertical-align: middle;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: high-quality;
}

.acf-gallery-item:hover .acf-gallery-image {
    transform: scale(1.05);
}

.acf-gallery-caption {
    margin: 10px 0 0 0;
    padding: 10px;
    font-size: 14px;
    color: #666;
    text-align: center;
    background: #f9f9f9;
    border-radius: 0 0 8px 8px;
}

/* Lightbox styles */
.acf-gallery-lightbox {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    overflow: auto;
    animation: fadeIn 0.3s;
}

.acf-gallery-lightbox.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.acf-gallery-lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    margin: auto;
    animation: zoomIn 0.3s;
}

.acf-gallery-lightbox-image {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}

.acf-gallery-lightbox-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
    z-index: 10000;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.acf-gallery-lightbox-close:hover,
.acf-gallery-lightbox-close:focus {
    color: #ccc;
    text-decoration: none;
}

.acf-gallery-lightbox-prev,
.acf-gallery-lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    font-size: 30px;
    font-weight: bold;
    padding: 20px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.3s ease;
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    min-width: 50px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    z-index: 10000;
}

.acf-gallery-lightbox-prev {
    left: 20px;
}

.acf-gallery-lightbox-next {
    right: 20px;
}

.acf-gallery-lightbox-prev:hover,
.acf-gallery-lightbox-next:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

.acf-gallery-lightbox-caption {
    color: #fff;
    text-align: center;
    padding: 20px;
    font-size: 18px;
}

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

@keyframes zoomIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Colonnes et espacements responsives, partagés avec le placement JS. */
@media (max-width: 768px) {
    .acf-gallery-taxonomy .acf-gallery-grid {
        grid-template-columns: repeat(var(--acf-gallery-columns-mobile, 1), minmax(0, 1fr));
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .acf-gallery-taxonomy .acf-gallery-grid {
        gap: 10px;
    }

    .acf-gallery-lightbox-prev,
    .acf-gallery-lightbox-next {
        font-size: 24px;
        padding: 15px;
        min-width: 60px;
        min-height: 60px;
        background-color: rgba(0, 0, 0, 0.7);
    }

    .acf-gallery-lightbox-prev { left: 10px; }
    .acf-gallery-lightbox-next { right: 10px; }

    .acf-gallery-lightbox-close {
        top: 10px;
        right: 10px;
        font-size: 36px;
        width: 60px;
        height: 60px;
        background-color: rgba(0, 0, 0, 0.7);
        border-radius: 50%;
    }
}
