/* =========================================
   Shoppable images
========================================= */

.p2p-shoppable-images {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(100px, 3fr);
    align-items: center;
    gap: 2rem;

    width: min(100% - 32px, 1400px);
    margin: auto;
    margin-block: 5rem;
}

.p2p-shoppable-images-header {
    margin-bottom: 2rem;
}

.p2p-shoppable-images-title {
    margin: 0 0 1rem;
}

.p2p-shoppable-images-blurb {
    max-width: 70ch;
}

/* =========================================
   Shoppable image grid
========================================= */

.p2p-shoppable-images-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.5rem;
    align-items: start;
}

.p2p-shoppable-image {
    min-width: 0;
}

/* -----------------------------------------
   1 image: one full-width image
----------------------------------------- */

.p2p-shoppable-images:has(
    .p2p-shoppable-images-grid > .p2p-shoppable-image:only-child
) {
    grid-template-columns: minmax(180px, 1fr) 1fr;
}

.p2p-shoppable-images:has(
    .p2p-shoppable-images-grid > .p2p-shoppable-image:only-child
) .p2p-shoppable-images-grid {
    justify-self: end;

    .p2p-shoppable-image {
        width: 100%;
    }

    .p2p-shoppable-image-background {
        max-height: 80vh;
    }
}
.p2p-shoppable-images-grid:has(> .p2p-shoppable-image:only-child) {
    grid-template-columns: minmax(0, 1fr);
}

/* -----------------------------------------
   2 images: side by side
----------------------------------------- */

.p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(2):last-child) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* -----------------------------------------
   3 images: three side by side
----------------------------------------- */

.p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(3):last-child) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* -----------------------------------------
   4 images: 2 x 2
----------------------------------------- */

.p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(4):last-child) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* -----------------------------------------
   5 images:
   2 x 2 on the left + large image on right
----------------------------------------- */

.p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(5):last-child) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) 2fr;
    grid-template-rows: repeat(2, auto);
}

.p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(5):last-child)
.p2p-shoppable-image:last-child {
    grid-column: 3;
    grid-row: 1 / span 2;
}

.p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(5):last-child)
.p2p-shoppable-image:last-child
.p2p-shoppable-image-background {
    aspect-ratio: 3 / 4;
    width: 100%;
}

/* -----------------------------------------
   6 images: 2 columns x 3 rows
----------------------------------------- */

.p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(6):last-child) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* -----------------------------------------
   Image frame: always 3:4
----------------------------------------- */

.p2p-shoppable-image-background {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    isolation: isolate;
    background: #f5f5f5;
}

.p2p-shoppable-image-background > img {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    object-fit: cover;
    object-position: center;
}

.p2p-shoppable-image {
    min-width: 0;
}

/* Fixed 3:4 portrait frame */

.p2p-shoppable-image-background {
    position: relative;
    width: auto;
    max-height: 60vh;
    aspect-ratio: 3 / 4;
    /* overflow: hidden; */
    isolation: isolate;
    background: #f5f5f5;
}

.p2p-shoppable-image-background > img {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    object-fit: cover;
    object-position: center;
}

/* Each hotspot is positioned using its own X/Y values */

.p2p-shoppable-product {
    position: absolute;
    left: var(--p2p-hotspot-x, 50%);
    top: var(--p2p-hotspot-y, 50%);
    z-index: 2;
    transform: translate(-50%, -50%);

    &:hover {
        z-index: 10;
    }
}

/* Hotspot button */

.p2p-shoppable-product-dot {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 34px;
    height: 34px;

    border: 2px solid #ffffff;
    border-radius: 50%;

    background: rgba(0, 0, 0, 0.4);
    color: #fff;

    font-size: 1rem;
    line-height: 1;
    text-decoration: none;

    box-shadow: 0 2px 8px rgba( 0, 0, 0, 0.25 );

    cursor: pointer;
    transition:
        transform 0.2s ease,
        background-color 0.2s ease;
}

.p2p-shoppable-product-dot:hover,
.p2p-shoppable-product-dot:focus-visible {
    background: #000;
    color: #fff;
    transform: scale(1.1);
}

/* Product preview */

.p2p-shoppable-product-preview {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 12px);
    z-index: 5;

    /*
     * Opens to the right of the dot; hotspots in the right half of the
     * image use --left (below) and open to the left instead.
     */
    width: min(200px, calc(100vw - 2rem));
    padding: 0.75rem;

    background: #fff;
    color: #111;

    box-shadow: 0 4px 18px rgba( 0, 0, 0, 0.18 );

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transform: translate(-1rem, 6px);
    transition:
        opacity 0.2s ease,
        transform 0.2s ease,
        visibility 0s linear 0.2s;
}

.p2p-shoppable-product:hover .p2p-shoppable-product-preview,
.p2p-shoppable-product:focus-within .p2p-shoppable-product-preview {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translate(-1rem, 0);
}

.p2p-shoppable-product--left .p2p-shoppable-product-preview {
    left: auto;
    right: 50%;
    transform: translate(1rem, 6px);
}

.p2p-shoppable-product--left:hover .p2p-shoppable-product-preview,
.p2p-shoppable-product--left:focus-within .p2p-shoppable-product-preview {
    transform: translate(1rem, 0);
}

.p2p-shoppable-product-preview a {
    display: block;
    color: inherit;
    text-decoration: none;
}

.p2p-shoppable-product-preview img {
    display: block;
    width: 100%;
    height: auto;
    margin-bottom: 0.5rem;
}

.p2p-shoppable-product-preview-title {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
}

.p2p-shoppable-product-preview-price {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.9rem;
}

/* Invisible hover bridge between hotspot and preview */

.p2p-shoppable-product-preview::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -12px;
    height: 12px;
}

/* Small screens */

@media (max-width: 575.98px) {
    .p2p-shoppable-images-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .p2p-shoppable-product-dot {
        width: 30px;
        height: 30px;
    }

    .p2p-shoppable-product-preview {
        width: 160px;
    }
}

/* -----------------------------------------
   Responsive
----------------------------------------- */

/* Below lg: intro above the images. */
@media (max-width: 991.98px) {

    .p2p-shoppable-images,
    .p2p-shoppable-images:has(
        .p2p-shoppable-images-grid > .p2p-shoppable-image:only-child
    ) {
        grid-template-columns: minmax(0, 1fr);
        gap: 1.5rem;
        margin-block: 3rem;
    }

    .p2p-shoppable-images-header {
        margin-bottom: 0;
    }

    .p2p-shoppable-images:has(
        .p2p-shoppable-images-grid > .p2p-shoppable-image:only-child
    ) .p2p-shoppable-images-grid {
        justify-self: stretch;
    }
}

/* xs: two columns; with 3 or 5 images the last one fills a full row. */
@media (max-width: 575.98px) {

    .p2p-shoppable-images {
        margin-block: 2rem;
    }

    .p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(3):last-child),
    .p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(5):last-child) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: none;
    }

    .p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(3):last-child)
    .p2p-shoppable-image:last-child,
    .p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(5):last-child)
    .p2p-shoppable-image:last-child {
        grid-column: 1 / -1;
        grid-row: auto;
    }

    .p2p-shoppable-images-grid:has(> .p2p-shoppable-image:nth-child(5):last-child)
    .p2p-shoppable-image:last-child
    .p2p-shoppable-image-background {
        width: 100%;
    }
}
