/**
 * Success Stories Widget
 * Each image is a child of its own list item. Below the desktop breakpoint it
 * sits inline under its link; above it, it is absolutely positioned into the
 * media column and revealed on hover. One markup, no JavaScript.
 */

.dmn-ss {
    --dmn-ss-media-width: 50%;
    --dmn-ss-min-height: 420px;
    --dmn-ss-ratio: 4 / 3;
    --dmn-ss-duration: 350ms;
    --dmn-ss-pad-top: 70px;
    --dmn-ss-pad-right: 70px;
    --dmn-ss-pad-bottom: 70px;
    --dmn-ss-pad-left: 70px;
    /* Same idiom as --hero-shape-gutter in style.css: the distance from the
       viewport edge to the site container. Collapses to 0 on narrow screens. */
    --dmn-ss-container: 1650px;
    --dmn-ss-gutter: calc((100vw - min(100vw, var(--dmn-ss-container))) / 2);
    position: relative;
}

.dmn-ss__panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding:
        var(--dmn-ss-pad-top) var(--dmn-ss-pad-right)
        var(--dmn-ss-pad-bottom) var(--dmn-ss-pad-left);
}

/* Background bleeds to the section edge, text lines up with the site
   container.

   The offset lives on __inner rather than on the panel's padding on purpose:
   Elementor generates padding rules for .elementor-element-xxx .dmn-ss__panel
   and loads them after this file, so anything we set there is a cascade fight.
   No generated CSS ever targets __inner, so this always wins.

   The panel padding stays the floor: we only add the difference between it and
   the gutter, and never a negative value, so narrow screens are untouched. */
.dmn-ss__inner {
    min-width: 0;
}

.dmn-ss--align-container .dmn-ss__inner {
    margin-left: max(0px, calc(var(--dmn-ss-gutter) - var(--dmn-ss-pad-left)));
}

.dmn-ss--align-container.dmn-ss--media-left .dmn-ss__inner {
    margin-left: 0;
    margin-right: max(0px, calc(var(--dmn-ss-gutter) - var(--dmn-ss-pad-right)));
}

.dmn-ss__title {
    margin-top: 0;
}

.dmn-ss__list {
    display: flex;
    flex-direction: column;
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Items stay full width so the stacked image fills the panel. The hover
   target is still just the text, because the link itself is inline-flex. */
.dmn-ss__item {
    align-self: stretch;
    margin: 0;
    list-style: none;
}

.dmn-ss__link {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    transition: color var(--dmn-ss-duration) ease;
}

.dmn-ss__arrow {
    flex: none;
    width: 0.8em;
    height: 0.8em;
}

.dmn-ss__media {
    margin: 0;
    overflow: hidden;
}

.dmn-ss__media img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Tablet and down: the image belongs to its link. */
@media (max-width: 1024px) {
    .dmn-ss__media {
        width: 100%;
        margin: 12px 0 28px;
        aspect-ratio: var(--dmn-ss-ratio);
    }

    .dmn-ss__item:last-child .dmn-ss__media {
        margin-bottom: 0;
    }

    .dmn-ss--stacked-first .dmn-ss__item:not(:first-child) .dmn-ss__media {
        display: none;
    }
}

/* Desktop: two columns, image swaps on hover. */
@media (min-width: 1025px) {
    .dmn-ss {
        display: grid;
        grid-template-columns: calc(100% - var(--dmn-ss-media-width)) var(--dmn-ss-media-width);
        min-height: var(--dmn-ss-min-height);
    }

    .dmn-ss__panel {
        grid-column: 1;
    }

    .dmn-ss__media {
        position: absolute;
        inset: 0 0 0 calc(100% - var(--dmn-ss-media-width));
        opacity: 0;
        transition: opacity var(--dmn-ss-duration) ease;
    }

    .dmn-ss--media-left {
        grid-template-columns: var(--dmn-ss-media-width) calc(100% - var(--dmn-ss-media-width));
    }

    .dmn-ss--media-left .dmn-ss__panel {
        grid-column: 2;
    }

    .dmn-ss--media-left .dmn-ss__media {
        inset: 0 calc(100% - var(--dmn-ss-media-width)) 0 0;
    }

    /* Source order below matters: each rule overrides the one before it.
       :where() keeps the first two at a specificity the active rule can beat. */

    /* 1. Resting state: the first item's image. */
    :where(.dmn-ss__item:first-child) .dmn-ss__media {
        opacity: 1;
    }

    /* 2. Something is being hovered or focused, so drop the resting image. */
    :where(.dmn-ss__list:has(.dmn-ss__link:hover, .dmn-ss__link:focus-visible)) .dmn-ss__media {
        opacity: 0;
    }

    /* 3. Show the active one. */
    .dmn-ss__link:hover ~ .dmn-ss__media,
    .dmn-ss__link:focus-visible ~ .dmn-ss__media {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {

    .dmn-ss__media,
    .dmn-ss__link {
        transition: none;
    }
}
