/**
 * WS Booster - Widget Stack Sections
 *
 * Sections empilees avec sticky + scale-behind.
 *
 * Architecture CSS :
 * 1. position: sticky pose le pin sans JS (fallback fonctionne en GSAP absent)
 * 2. z-index croissant (pose inline par PHP) = section suivante recouvre l'ancienne
 * 3. transform-origin: top center pour que le scale-behind retrecit vers le haut
 * 4. transition: transform fluide quand le JS GSAP modifie scale
 * 5. @media reduced-motion = pas de scale (CSS sticky suffit pour le pin)
 * 6. .ws-stack-sections--editor = builder Elementor : pas de sticky (sinon le
 *    contenu disparait derriere le panneau), pas de transform.
 */

.ws-stack-sections {
    --ws-stack-offset: 80px;
    --ws-stack-gap: 12px;
    position: relative;
    width: 100%;
}

/* Section individuelle : sticky par defaut, transitions douces sur transform */
.ws-stack-section {
    position: sticky;
    /* top est pose par Elementor via selectors sur sticky_offset (responsive).
       Fallback si jamais pas de selector : --ws-stack-offset. */
    top: var(--ws-stack-offset, 80px);
    /* La section suivante recouvre la precedente : besoin d'un fond opaque */
    background-color: #0f172a;
    color: var(--ws-stack-text, #ffffff);
    overflow: hidden;
    transform-origin: top center;
    will-change: transform;
    transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Decalage cumule sticky : chaque section colle un peu plus bas que la
   precedente. Calcule via data-attr --ws-stack-index (pose en inline style
   par PHP), evite d'ecrire .ws-stack-section:nth-child(N) repete. */
.ws-stack-section[data-index] {
    top: calc(var(--ws-stack-offset, 80px) + var(--ws-stack-index, 0) * var(--ws-stack-gap, 0px));
}

/* Inner = flex container (text + image). Direction reglable par viewport */
.ws-stack-section__inner {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 48px;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    height: 100%;
}

/* === BLOC TEXTE === */
.ws-stack-section__text {
    flex: 1 1 auto;
    min-width: 0;
}

.ws-stack-section__subtitle {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    opacity: 0.7;
    margin: 0 0 16px;
    color: inherit;
}

.ws-stack-section__title {
    font-size: clamp(28px, 4.2vw, 56px);
    line-height: 1.1;
    font-weight: 700;
    margin: 0 0 20px;
    color: inherit;
}

.ws-stack-section__body {
    font-size: 17px;
    line-height: 1.6;
    margin: 0 0 28px;
    color: inherit;
    opacity: 0.9;
}

.ws-stack-section__body p:last-child { margin-bottom: 0; }
.ws-stack-section__body p:first-child { margin-top: 0; }

/* === CTA === */
.ws-stack-section__cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 28px;
    background: #ffffff;
    color: #0f172a;
    text-decoration: none;
    border-radius: 999px;
    font-weight: 600;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    border: none;
    box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.35);
}

.ws-stack-section__cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px -10px rgba(0, 0, 0, 0.45);
}

/* === BLOC IMAGE === */
.ws-stack-section__media {
    flex: 0 1 500px;
    max-width: 500px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* !important pour battre l'override du theme img { max-width:100%; height:auto }
   qui sinon empeche les controles Largeur max / Rayon de l'image de fonctionner.
   Bible regle 9.13 + memoire "Conflit img theme - !important". */
.ws-stack-section__image {
    display: block;
    width: 100% !important;
    height: auto !important;
    max-width: 500px !important;
    border-radius: 16px;
    object-fit: cover;
}

/* === PROGRESS BAR (optionnelle) === */
.ws-stack-progress {
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(15, 23, 42, 0.12);
    z-index: 100;
    overflow: hidden;
}

.ws-stack-progress__bar {
    width: 100%;
    height: 100%;
    background: #3b82f6;
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 0.1s linear;
    will-change: transform;
}

/* === COUNTER (optionnel) === */
.ws-stack-counter {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: rgba(15, 23, 42, 0.85);
    color: #ffffff;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.05em;
    z-index: 90;
    pointer-events: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* === EMPTY STATE === */
.ws-stack-sections__empty {
    padding: 60px 40px;
    text-align: center;
    color: #94a3b8;
    background: rgba(15, 23, 42, 0.04);
    border: 2px dashed rgba(15, 23, 42, 0.15);
    border-radius: 12px;
}

/* === EDITEUR ELEMENTOR ===
   Demande user : "j'aimerais qu'on ait tout comme dans la page en mode reel".
   On laisse donc le sticky CSS + GSAP scale-behind tourner dans le builder
   exactement comme en front, pour que l'utilisateur voie l'effet en live
   pendant qu'il configure les controles.
   La classe .ws-stack-sections--editor reste posee server-side (anti-flash
   §9.40) mais n'override plus position/transform — l'effet visuel est
   identique a la page reelle. */

/* === RESPONSIVE === */
@media (max-width: 1024px) {
    .ws-stack-section__inner {
        gap: 32px;
    }
    .ws-stack-section__media {
        flex: 0 1 380px;
        max-width: 380px;
    }
}

@media (max-width: 768px) {
    .ws-stack-section__inner {
        flex-direction: column !important;
        align-items: flex-start;
        gap: 28px;
    }
    .ws-stack-section__media {
        flex: 0 1 auto;
        max-width: 100%;
        width: 100%;
    }
    .ws-stack-section__image {
        max-width: 100% !important;
    }
    .ws-stack-section__title {
        font-size: clamp(24px, 6vw, 38px);
    }
    .ws-stack-section__body {
        font-size: 15px;
    }
    .ws-stack-counter {
        bottom: 16px;
        right: 16px;
        padding: 8px 12px;
        font-size: 11px;
    }
}

/* === REDUCED MOTION ===
   Utilisateurs avec preference reduced-motion : on garde le sticky (utile pour
   l'organisation visuelle) mais on coupe les transitions / scale anim. */
@media (prefers-reduced-motion: reduce) {
    .ws-stack-section {
        transition: none !important;
        transform: none !important;
    }
    .ws-stack-progress__bar {
        transition: none !important;
    }
}
