/**
 * WS Booster - Galerie Justifiee
 *
 * v2.9.2 :
 * - 3 modes de mise en page : Justifiee (flex+JS), Grille (CSS Grid), Maconnerie (CSS columns)
 * - Mode Perspective 3D : algo Framion Wall intact
 * - Fade-mask passe en CSS vars (--ws-jg-fade-top/--ws-jg-fade-bot)
 *   pour permettre render_type:none cote PHP
 * - Variable --ws-jgallery-zoom pour intensite hover configurable
 */

/* ============================================================
   BASE COMMUNE
   ============================================================ */
.ws-jgallery {
    --ws-jgallery-zoom: 1.05;
    width: 100%;
    list-style: none;
    padding: 0;
    margin: 0;
    gap: 8px;
}

.ws-jgallery__item {
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    background: #f3f4f6;
    line-height: 0;
    text-decoration: none;
    display: block;
}

.ws-jgallery__item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                filter 0.4s ease;
}

/* Zoom au hover (intensite via --ws-jgallery-zoom) */
.ws-jgallery--zoom .ws-jgallery__item:hover img {
    transform: scale(var(--ws-jgallery-zoom, 1.05));
}

/* Overlay couleur au hover (variable --ws-jgallery-overlay) */
.ws-jgallery__item::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--ws-jgallery-overlay, transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

.ws-jgallery__item:hover::after {
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    .ws-jgallery__item img {
        transition: none;
    }
}

/* ============================================================
   MODE JUSTIFIED (style Unsplash, lignes egalisees via JS)
   Active par default + classe ws-jgallery--layout-justified
   ============================================================ */
.ws-jgallery--layout-justified .ws-jgallery {
    display: flex;
    flex-wrap: wrap;
}

.ws-jgallery--layout-justified .ws-jgallery__item {
    flex-grow: 1;
    flex-basis: auto;
}

/* Derniere ligne : ne pas etirer les items isoles */
.ws-jgallery--layout-justified .ws-jgallery::after {
    content: "";
    flex-grow: 9999999;
}

/* ============================================================
   MODE GRID (CSS Grid, colonnes egales, ratio image preserve)
   ============================================================ */
.ws-jgallery--layout-grid .ws-jgallery {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
}

.ws-jgallery--layout-grid .ws-jgallery__item {
    aspect-ratio: 4 / 3;
}

/* ============================================================
   MODE MASONRY (CSS columns, hauteurs naturelles - style Pinterest)
   ============================================================ */
.ws-jgallery--layout-masonry .ws-jgallery {
    display: block;
    column-count: 3;
    column-gap: 8px;
}

.ws-jgallery--layout-masonry .ws-jgallery__item {
    display: inline-block;
    width: 100%;
    margin-bottom: 8px;
    break-inside: avoid;
    page-break-inside: avoid;
}

.ws-jgallery--layout-masonry .ws-jgallery__item img {
    height: auto;
    aspect-ratio: auto;
}

/* ============================================================
   MODE PERSPECTIVE 3D ("Framion Wall") - INTACT
   ============================================================ */
.ws-jgallery__viewport {
    --ws-jg-rx: 30deg;
    --ws-jg-ry: 0deg;
    --ws-jg-rz: 0deg;
    --ws-jg-fade-top: 0px;
    --ws-jg-fade-bot: 0px;
    position: relative;
    width: 100%;
    height: 80vh;
    overflow: hidden;
    perspective: 1500px;
    transform-style: preserve-3d;

    /* Fade mask consomme les CSS vars posees par les controls fade_top/fade_bottom */
    -webkit-mask-image: linear-gradient(
        to bottom,
        transparent 0,
        black var(--ws-jg-fade-top, 0px),
        black calc(100% - var(--ws-jg-fade-bot, 0px)),
        transparent 100%
    );
    mask-image: linear-gradient(
        to bottom,
        transparent 0,
        black var(--ws-jg-fade-top, 0px),
        black calc(100% - var(--ws-jg-fade-bot, 0px)),
        transparent 100%
    );
}

.ws-jgallery__stage {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotateX(var(--ws-jg-rx)) rotateY(var(--ws-jg-ry)) rotateZ(var(--ws-jg-rz));
    transform-origin: 50% 50%;
    transform-style: preserve-3d;
    will-change: transform;
}

.ws-jgallery-persp-yes .ws-jgallery {
    flex-wrap: wrap;
    width: 100%;
    will-change: transform;
}

/* Quand marquee actif, le JS structure les items en rangees scrollantes */
.ws-jgallery__row {
    display: flex;
    gap: 8px;
    width: max-content;
    overflow: visible;
    will-change: transform;
}

.ws-jgallery__row--left {
    animation: ws-jgallery-marq-left linear infinite;
}
.ws-jgallery__row--right {
    animation: ws-jgallery-marq-right linear infinite;
}

@keyframes ws-jgallery-marq-left {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
}
@keyframes ws-jgallery-marq-right {
    from { transform: translateX(-50%); }
    to   { transform: translateX(0); }
}

.ws-jgallery__rows-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

/* Ombres legeres sur les cards en mode hero */
.ws-jgallery-persp-yes .ws-jgallery__item {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
}

.ws-jgallery-persp-yes .ws-jgallery__item img {
    transition: filter 0.4s ease, transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@media (prefers-reduced-motion: reduce) {
    .ws-jgallery__row--left,
    .ws-jgallery__row--right {
        animation: none !important;
    }
}

/* === Mode VERTICAL : colonnes qui defilent haut/bas === */
.ws-jgallery__rows-wrap--vertical {
    flex-direction: row;
    height: 100%;
    align-items: stretch;
}

.ws-jgallery__row--vertical {
    display: flex;
    flex-direction: column;
    width: auto;
    flex: 1;
    height: max-content;
    overflow: visible;
}

.ws-jgallery__row--up {
    animation: ws-jgallery-marq-up linear infinite;
}
.ws-jgallery__row--down {
    animation: ws-jgallery-marq-down linear infinite;
}

@keyframes ws-jgallery-marq-up {
    from { transform: translateY(0); }
    to   { transform: translateY(-50%); }
}
@keyframes ws-jgallery-marq-down {
    from { transform: translateY(-50%); }
    to   { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .ws-jgallery__row--up,
    .ws-jgallery__row--down {
        animation: none !important;
    }
}
