#product-popup-container {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 2147483647 !important;
    padding: 20px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    /* Start fully invisible */
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s linear 0.2s, opacity 0.2s ease-out;
    /* Prevent any layout shifts */
    contain: layout size;
    isolation: isolate;
}

#product-popup-container.open {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
}

#product-popup-container.product-popup-container--behind-overlay {
    z-index: 9990 !important;
}

#product-popup-container > .variable-select-popup,
#product-popup-container > .variable-select-popup.variable-select-popup--above-product-modal {
    z-index: 2147483650 !important;
}

.product-popup {
    position: relative;
    width: 100%;
    max-width: 1750px;
    margin: 0 auto;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    height: 80vh;
    overflow: hidden;
    z-index: 2147483648 !important;
    /* Prevent content from affecting size during load */
    contain: layout style;
    display: flex;
    flex-direction: column;
}

.product-popup.open {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 1;
}

.popup-header {
    position: relative;
    padding: 15px;
    border-bottom: 1px solid #eee;
}

.close-popup {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 5px 10px;
    color: #666;
    transition: color 0.15s ease;
    z-index: 100;
}

.close-popup:hover {
    color: #000;
}

.popup-content {
    position: relative;
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    opacity: 1;
    transition: opacity 0.2s ease-out;
    display: block;
    min-height: 0;
    height: 100%;
}

.product-popup .popup-loading {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
    margin: 0;
    padding: 0;
    font-family: "montserrat", sans-serif;
}

.product-popup .popup-loading-text {
    color: #666;
    font-size: 14px;
    margin: 8px 0 0;
    font-family: "montserrat", sans-serif;
    font-weight: 500;
}

.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 186, 0, 0.2);
    border-top: 3px solid #ffba00;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 10px;
}

.product-popup .mk-popup-skeleton {
    max-width: 100%;
    min-height: 60vh;
}

.product-popup .popup-content .mk-media-loader > img.mk-product-img {
    width: 100%;
    height: auto;
}

.product-popup .gallery-img-container .mk-media-loader > img.product-gallery-img {
    width: auto;
    height: auto;
    max-width: none;
    margin-right: 0;
    display: block;
}

.product-popup .gallery-img-container {
    padding: 0.5rem;
    align-items: center;
}

.product-popup .gallery-img-container .mk-media-loader {
    line-height: 0;
    height: fit-content;
    min-height: 0;
}

.product-popup .gallery-img-container > .product-gallery-img:not(:last-child) {
    margin-right: 2rem;
}

.product-popup .gallery-img-strip {
    margin-top: 0;
    line-height: 0;
}

.product-popup .product-column-1-wrapper > .mk-media-loader {
    position: relative;
    z-index: 1;
}

.product-popup .single-product-attributes {
    z-index: 5;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.error-message {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    padding: 15px;
    border-radius: 4px;
    text-align: center;
}

/* Related products slider inside popup (match homepage slider) */
.product-popup .related-products .display-products {
    width: 100%;
    max-width: 100%;
}

.product-popup .related-products {
    overflow-x: visible;
}

.product-popup .mk-related-products-grid {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 14.5rem;
    gap: 1rem;
    justify-content: start;
    width: max-content;
    min-width: 100%;
    margin: 0;
    padding: 1rem 1.2rem;
    list-style: none;
    overflow: visible;
    background-color: #444444;
    box-sizing: border-box;
}

.product-popup .mk-related-products-grid .shop-product-list-item {
    display: flex;
    flex-direction: column;
    overflow: visible;
    width: 14.5rem;
    min-width: 14.5rem;
    max-width: 14.5rem;
    padding-bottom: 2.2rem;
    height: auto;
}

.product-popup .mk-related-products-grid .product-image-wrapper {
    position: relative;
    overflow: hidden;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    flex: 0 0 auto;
}

.product-popup .mk-related-products-grid .product-attributes {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0.35rem;
    min-height: 1.7rem;
    margin-top: 0;
    padding-bottom: 0;
}

.product-popup .related-products .display-products {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 10px;
    background-color: #444444;
    box-shadow: rgba(9, 30, 66, 0.25) 0px 4px 8px -2px, rgba(9, 30, 66, 0.08) 0px 0px 0px 1px;
    -webkit-overflow-scrolling: touch;
}

.product-popup .related-products .display-products::-webkit-scrollbar-track {
    background-color: #858585;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}

.product-popup .related-products .display-products::-webkit-scrollbar {
    height: 10px;
    background-color: #f5f5f5;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}

.product-popup .related-products .display-products::-webkit-scrollbar-thumb {
    background-color: #ffba00;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #product-popup-container {
        padding: 0;
        align-items: stretch;
        justify-content: flex-start;
    }
    
    .product-popup {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
        contain: none;
    }
    
    .popup-content {
        padding: 12px;
        padding-top: 3.25rem;
        -webkit-overflow-scrolling: touch;
    }

    .product-popup .close-popup {
        position: fixed;
        top: calc(env(safe-area-inset-top, 0px) + 10px);
        right: calc(env(safe-area-inset-right, 0px) + 10px);
        z-index: 2147483649;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 2.75rem;
        height: 2.75rem;
        padding: 0;
        border: 2px solid #fff;
        border-radius: 50%;
        background: rgba(0, 0, 0, 0.78);
        color: #fff;
        font-size: 1.75rem;
        line-height: 1;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    }

    .product-popup .close-popup:hover {
        background: #ffba00;
        color: #000;
        border-color: #fff;
    }

    .product-popup #product-content.single-product-main-content-grid {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "media"
            "details"
            "purchase"
            "related";
        gap: 0.75rem;
        width: 100%;
        max-width: 100%;
        margin: 0;
    }

    .product-popup .single-product-rows,
    .product-popup .single-product-grid {
        display: contents;
    }

    .product-popup .product-popup-media {
        grid-area: media;
        display: block;
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
        background-color: #ffffff;
        border-radius: 5px;
        overflow: hidden;
    }

    .product-popup .product-column-1-wrapper {
        position: relative;
        display: block;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
        box-sizing: border-box;
    }

    .product-popup .product-column-1-wrapper .mk-product-img,
    .product-popup .single-product-grid .mk-product-img {
        display: block;
        width: 100%;
        max-width: 100%;
        height: auto;
        margin: 0;
    }

    .product-popup .gallery-img-strip {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .product-popup .gallery-img-container {
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
        box-sizing: border-box;
    }

    .product-popup .single-product-attributes {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 3;
        height: auto;
        min-height: 2.5rem;
        padding: 0.4rem 0.5rem;
        box-sizing: border-box;
        overflow: visible;
    }

    .product-popup .single-product-attributes .product-attributes {
        position: static;
        display: flex;
        align-items: center;
        justify-content: space-evenly;
        flex-wrap: nowrap;
        width: 100%;
        gap: 0;
        margin: 0;
        padding: 0 0.35rem;
        box-sizing: border-box;
    }

    .product-popup .single-product-attributes .product-attributes .tooltip {
        flex: 1 1 0;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 0;
        max-width: none;
        margin: 0;
        position: relative;
        z-index: 5;
    }

    .product-popup .single-product-attributes .product-attributes .tooltip .top {
        z-index: 1005;
    }

    .product-popup .single-product-attributes .prod-attribute {
        position: static;
        display: block;
        max-width: 1.85rem;
        width: 1.85rem;
        height: 1.85rem;
        margin: 0;
    }

    .product-popup .product-column-1-wrapper .store-deal-badge {
        z-index: 4;
        max-width: calc(100% - 1rem);
    }

    .product-popup .single-product-grid > .product-text-content {
        grid-area: details;
        width: 100%;
        min-width: 0;
        max-height: none;
        overflow: visible;
        padding: 0.75rem;
        margin: 0;
        box-sizing: border-box;
        background-color: #ffffff;
        border-radius: 5px;
    }

    .product-popup .mk-product-description-wrap {
        margin-top: 0.75rem;
    }

    .product-popup .mk-product-description {
        font-family: "montserrat", sans-serif;
        font-size: 0.95rem;
        line-height: 1.5;
        color: #222;
        max-height: 7.5rem;
        overflow: hidden;
    }

    .product-popup .mk-product-description.is-expanded {
        max-height: none;
    }

    .product-popup .mk-product-description-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin-top: 0.65rem;
        font-size: 0.85rem;
    }

    .product-popup .mk-product-description-toggle[hidden] {
        display: none !important;
    }

    .product-popup .single-product-sidebar {
        grid-area: purchase;
        width: 100%;
        min-width: 0;
        margin: 0;
        box-sizing: border-box;
    }

    .product-popup .related-products {
        grid-area: related;
        width: 100%;
        min-width: 0;
        margin: 0;
        box-sizing: border-box;
    }

    .product-popup .mk-product-store-selector {
        flex-direction: column;
        align-items: stretch;
        gap: 0.65rem;
        width: 100%;
    }

    .product-popup .mk-product-store-selector .secondary-btn,
    .product-popup .mk-product-store-selector .current-selected-store-badge {
        width: 100%;
        box-sizing: border-box;
        justify-content: center;
    }
}

@media (min-width: 769px) {
    .product-popup .mk-product-description-toggle {
        display: none !important;
    }
}

@media (max-width: 480px) {
    #product-popup-container {
        padding: 0;
    }
    
    .product-popup {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
    }
    
    .popup-content {
        padding: 10px;
        padding-top: 3.15rem;
    }
    
    .product-popup .close-popup {
        top: calc(env(safe-area-inset-top, 0px) + 8px);
        right: calc(env(safe-area-inset-right, 0px) + 8px);
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.55rem;
    }
}

/* Scroll lock helper */
body.no-scroll {
    overflow: hidden;
    /* Prevent page shift when scrollbar disappears */
    padding-right: var(--scrollbar-width, 0px);
}