/* The sale ticket, zoom trigger and image travel together inside the frame. */
body .pem-product .jl-detail-panel .pem-product__gallery {
    --jl-photo-gap: clamp(16px, 2.2vh, 28px);
    position: relative;
    top: auto;
    justify-self: center;
    align-self: start;
}

.jl-detail-panel .woocommerce-product-gallery__image > a,
.jl-detail-panel .woocommerce-product-gallery__image > a > img,
.jl-detail-panel .woocommerce-product-gallery__image--placeholder > img {
    display: block;
}

.jl-detail-panel .woocommerce-product-gallery .woocommerce-product-gallery__image > a > img,
.jl-detail-panel .woocommerce-product-gallery .woocommerce-product-gallery__image--placeholder > img {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    max-height: none;
    object-fit: contain;
}

@media (min-width: 850px) {
    .jl-detail-panel .woocommerce-product-gallery .flex-control-thumbs {
        flex-wrap: nowrap;
        overscroll-behavior-y: contain;
    }
}

@media screen and (min-width: 1000px) and (min-height: 600px) {
    /* When measurements are unavailable the photo stays in normal document flow. */
    body .pem-product .jl-detail-panel .pem-product__gallery[data-jl-gallery-fit] {
        --jl-photo-space: calc(100dvh - var(--jl-masthead-end) - 2 * var(--jl-photo-gap));
        --jl-gallery-rail: 0px;
        --jl-gallery-caption: 0px;
        max-width: max(0px, calc(var(--jl-photo-space) + var(--jl-gallery-rail) - var(--jl-gallery-caption)));
        position: sticky;
        /* A narrower column leaves equal space above and below the photo too. */
        top: max(calc(var(--jl-masthead-end) + var(--jl-photo-gap)),
                 calc((100dvh + var(--jl-masthead-end) - var(--jl-gallery-height)) / 2));
    }

    body .pem-product .jl-detail-panel .pem-product__gallery[data-jl-gallery-fit]:has(.jl-plate-caption) {
        --jl-gallery-caption: 2rem;
    }
    body .pem-product .jl-detail-panel .pem-product__gallery[data-jl-gallery-fit]:has(.flex-control-thumbs) {
        --jl-gallery-rail: calc(clamp(58px, 5.6vw, 90px) + 10px);
    }
}

@media (max-width: 849px) {
    body .pem-product .jl-detail-panel .pem-product__gallery {
        max-width: min(100%, max(18rem, 62svh));
        margin-block: var(--jl-photo-gap);
    }
}
