/* ========= PDP Image Layout - 2x2 Grid (.JS in Assets Folder) ======= */

:root {
    --pdp-image-radius: 5px;              /* corner radius for all PDP gallery images/tiles */
    --pdp-border-color: #c2c2c261;        /* border around images/tiles */
    --pdp-bg: #fff;                       /* gallery/tile background */
    --pdp-play-btn-bg: rgb(0 0 0 / 36%);  /* YouTube play button */
    --pdp-play-btn-border: #fff;
    --pdp-play-btn-hover: #FF0000;
}

/* --- DESKTOP VIEW --- */
@media screen and (min-width: 1024px) {

    /* 1. LAYOUT COLUMNS */
    div#prodInfoLeft {
        margin-block: 1rem;
        width: 60%;
        min-height: 100vh;
    }

    div#prodInfoRight {
        width: 40%;
    }

    /* 2. OVERFLOW FIXES */
    .grid.fixed.productPageTop,
    .container,
    .maxInner,
    .zflex-w,
    #prodInfoRight {
        overflow: visible !important;
    }

    .productPageTop .zflex-w {
        align-items: stretch !important;
    }

    div#webdes_pdp .productPageTop .maxInner {
        max-width: 100%;
        padding-inline: 1rem;
    }

    /* 3. 2x2 IMAGE GRID
       Main image top-left, first extra image top-right,
       remaining images flow 2-per-row down the page. */
    div#prodInfoLeft {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        align-content: start;
    }

    /* Thumbnail wrapper dissolves so its links join the grid */
    div#detailMivThumb {
        display: contents;
    }

    /* 4. MAIN IMAGE */
    #detailMiv {
        border: 1px solid var(--pdp-border-color);
        border-radius: var(--pdp-image-radius);
        aspect-ratio: 1/1;
        max-height: 80vh; /* keep the whole image on screen on laptops */
    }

    div#detailMiv img {
        border-radius: var(--pdp-image-radius);
        width: 100%;
        height: 100%;
        object-fit: contain;
        display: block;
    }

    /* Single-image products: main image spans the full width and sticky-scrolls
       alongside the product details. The lone grid row must stretch to the full
       column height, or sticky has no room to travel.
       (the hidden #ModularShortDescription link doesn't count as a thumbnail) */
    #prodInfoLeft:not(:has(a.col-thumbnail:not([href="#ModularShortDescription"]))) {
        align-content: stretch;
    }

    #prodInfoLeft:not(:has(a.col-thumbnail:not([href="#ModularShortDescription"]))) #detailMiv {
        grid-column: 1 / -1;
        align-self: start;
        position: -webkit-sticky;
        position: sticky;
        top: 90px;
    }

    /* Multi-image products: pin the whole image column while the details scroll.
       align-self:flex-start lets the column keep its natural height inside the
       stretched flex row, giving sticky room to travel. */
    #prodInfoLeft:has(a.col-thumbnail:not([href="#ModularShortDescription"])) {
        position: -webkit-sticky;
        position: sticky;
        top: 90px;
        align-self: flex-start;
        min-height: 0;
    }

    .MIVicon {
        border-radius: var(--pdp-image-radius);
        margin: .5rem;
    }

    /* 5. THUMBNAILS (!important beats the base theme's small thumb sizing) */
    div#detailMivThumb a,
    div#detailMivThumb #youTubeLink {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        max-height: none !important;
        flex: none !important;
        aspect-ratio: 1/1;
        border: 1px solid var(--pdp-border-color);
        border-radius: var(--pdp-image-radius);
        overflow: hidden;
        filter: grayscale(0) !important;
    }

    div#detailMivThumb a img {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: none !important;
        object-fit: cover;
        border-radius: var(--pdp-image-radius);
        display: block;
    }

    div#detailMivThumb #youTubeLink .bgStandard {
        display: none !important;
        padding: 0 !important;
    }

    /* Logo filler tile (added by JS when image count is odd) */
    #pdpLogoTile {
        aspect-ratio: 1/1;
        border: 1px solid var(--pdp-border-color);
        border-radius: var(--pdp-image-radius);
        background: var(--pdp-bg);
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100% !important;
    }

    #pdpLogoTile img {
        max-width: 60%;
        max-height: 60%;
        object-fit: contain;
    }

    /* Show more button spans both grid columns */
    #pdpShowMoreBtn {
        grid-column: 1 / -1;
    }

    /* 6. STICKY */
    #firstdetails {
        position: -webkit-sticky !important;
        position: sticky !important;
        top: 90px;
        align-self: flex-start;
        height: fit-content !important;
        z-index: 50;
        margin-bottom: 0 !important;
        overflow: scroll !important;
        padding-top: 1rem !important;
    }
}

/* --- MOBILE VIEW (unchanged) --- */
@media screen and (max-width: 1024px) {
    div#prodInfoLeft {
        display: flex;
        flex-flow: row;
        overflow-x: scroll;
        padding: .5rem;
        background: var(--pdp-bg);
    }

    #detailMiv::before {
       content: 'More Images >';
       font-size: 0.7rem;
       position: absolute;
       bottom: 1rem;
       right: 2rem;
       letter-spacing: 0.05rem;
       z-index: 1;
       background: var(--color4);
       padding: .5rem;
       border-radius: var(--pdp-image-radius);
    }

    div#detailMivThumb {
        display: flex;
        flex-flow: row;
        overflow: visible;
        gap: 1rem;
        margin-block: 0;
    }

    #detailMivThumb > a img,
    .cssItemImg > a img {
        min-width: 85vw !important;
        width: 85vw !important;
        height: 100% !important;
        aspect-ratio: 1/1 !important;
        border-radius: var(--pdp-image-radius);
        object-fit: cover;
        border: 1px solid var(--pdp-border-color);
    }

    .cssItemImg > a img {
        margin-right: 1rem;
    }

    /* Hiding logic for single images */
    #prodInfoLeft:has(#detailMivThumb .col-thumbnail:only-child) {
        overflow: hidden;
    }

    #prodInfoLeft:has(#detailMivThumb .col-thumbnail:only-child) .cssItemImg > a img {
        width: 100% !important;
        padding: .5rem !important;
    }

    #detailMivThumb:has(> .col-thumbnail:only-child) {
        display: none;
    }

    #prodInfoLeft:has(#detailMivThumb .col-thumbnail:only-child) #detailMiv::before {
       display: none;
    }

    #detailMivThumb .col-thumbnail {
        flex: 0 !important;
        min-width: 85vw;
        border-radius: var(--pdp-image-radius);
    }

    #youTubeLink .bgStandard {
        background: transparent;
        border-radius: var(--pdp-image-radius);
    }

    #brand-logo-area > a {
        padding-right: 1rem !important;
        padding-top: 0;
    }

    #brand-logo-area > a img {
        border-radius: var(--pdp-image-radius) !important;
    }

    .MIViconZoom {
        display: none;
    }

    /* Desktop-only logo filler tile */
    #pdpLogoTile {
        display: none;
    }
}

/* Hide short desc */
a[href="#ModularShortDescription"] {
    display: none !important;
}

/* --- YOUTUBE PLAY BUTTON STYLING --- */
#youTubeLink {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
}

#youTubeLink::after {
    content: '';
    position: absolute;
    width: 60px;
    height: 60px;
    background-color: var(--pdp-play-btn-bg);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='white' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 30px;
    border-radius: 50%;
    border: 2px solid var(--pdp-play-btn-border);
    transition: all 0.3s ease;
    z-index: 2;
    pointer-events: none;
}

#youTubeLink:hover::after {
    background-color: var(--pdp-play-btn-hover);
    transform: scale(1.1);
    border-color: var(--pdp-play-btn-hover);
}

/* --- SHOW MORE (text link style) --- */
#pdpShowMoreBtn {
    width: 100%;
    padding: 12px 0;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--color1);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-decoration: underline;
    text-underline-offset: 4px;
    line-height: normal;
    margin-bottom: 1rem;
}

#pdpShowMoreBtn:hover {
    text-decoration-thickness: 2px;
}
