/* ==========================================================================
 * MatchBeast — Single Product Single-Owner Frame Architecture
 *
 * Loaded at wp_enqueue_scripts priority 120 (only on is_product(),
 * strictly AFTER matchbeast-grid-frame & flatsome-style).
 * ========================================================================== */

.single-product {
    --mb-single-product-image-inset: 16px;
    --mb-single-product-shell-width: calc(100% - (var(--mb-product-grid-edge-gap) * 2));
    --mb-single-product-shell-max-width: calc(1080px - (var(--mb-product-grid-edge-gap) * 2));
}

@media (max-width: 549px) {
    .single-product {
        --mb-single-product-image-inset: 10px;
    }
}

@media (min-width: 850px) {
    .single-product {
        --mb-single-product-shell-width: 100%;
        --mb-single-product-shell-max-width: 1080px;
    }
}

/* Strip inner gallery Flatsome grid borders */
.single-product .product-gallery .row[class*="-columns-"]::before {
    display: none !important;
}

.single-product .product-gallery .col {
    border: none !important;
}

.single-product .product-image-slider {
    margin-bottom: 0 !important;
}

/* Release footer container padding so every shell calculates width identically */
.single-product .product-main {
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
}

.single-product .product-footer {
    border: none !important;
    padding: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 40px !important;
}

@media (min-width: 850px) {
    .single-product .product-footer {
        margin-bottom: 60px !important;
    }
}

.single-product .product-footer > .container {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* --- 1. Unified Shell Width for All Stacked Modules --- */
.single-product .product-main .row.content-row,
.single-product .mb-fbt--desktop,
.single-product .matchbeast-upsells-wrapper,
.single-product .woocommerce-tabs.wc-tabs-wrapper,
.single-product .matchbeast-faqs-wrapper,
.single-product .related-products-wrapper {
    width: var(--mb-single-product-shell-width) !important;
    max-width: var(--mb-single-product-shell-max-width) !important;
    margin-left: auto !important;
    margin-right: auto !important;
    box-sizing: border-box !important;
}

/* --- 2. Hero Box (.product-main .row.content-row) --- */
.single-product .product-main .row.content-row {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 0 !important;
    padding: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    border: var(--mb-product-border-line) !important;
    background-color: #fff;
}

.single-product .product-main .row.content-row::before,
.single-product .product-main .row.content-row::after {
    display: none !important;
    content: none !important;
}

.single-product .product-gallery,
.single-product .product-info {
    width: auto !important;
    max-width: none !important;
    flex: none !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    min-width: 0;
}

.single-product .product-gallery {
    padding: var(--mb-single-product-image-inset) !important;
    background-color: #ffffff;
    border: 0 !important;
    border-bottom: var(--mb-product-border-line) !important;
}

.single-product .product-info {
    border: 0 !important;
}

.single-product .product-thumbnails {
    padding: 10px 15px 8px 15px !important;
    margin-bottom: 0 !important;
}

@media (min-width: 850px) {
    .single-product .product-main .row.content-row {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    }

    .single-product .product-gallery {
        display: flex;
        flex-direction: column;
        justify-content: center;
        border-bottom: 0 !important;
        border-right: var(--mb-product-border-line) !important;
    }

    .single-product .product-info {
        padding: 35px;
    }

    .single-product .product-thumbnails {
        margin-top: 15px !important;
        padding: 0 15px 8px 15px !important;
    }

    .single-product .product-thumbnails .col {
        border: 1px solid transparent;
        opacity: 0.6;
    }

    .single-product .product-thumbnails .col.is-nav-selected {
        opacity: 1 !important;
        border: var(--mb-product-border-line);
    }
}

/* Touch Tablets Only: stacked centered gallery without hijacking desktop resize */
@media (min-width: 768px) and (max-width: 1180px) and (hover: none) and (pointer: coarse),
       (min-width: 850px) and (max-width: 1366px) and (hover: none) and (pointer: coarse) {
    .single-product .product-main .row.content-row {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .single-product .product-gallery {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        background-color: #f0f0f0 !important;
        border-right: 0 !important;
        border-bottom: var(--mb-product-border-line) !important;
    }

    .single-product .product-gallery .product-images,
    .single-product .product-gallery .woocommerce-product-gallery,
    .single-product .product-thumbnails {
        width: 100% !important;
        max-width: 860px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        margin-bottom: 0 !important;
    }

    .single-product .product-thumbnails {
        background-color: #f0f0f0 !important;
    }

    .single-product .product-gallery .product-gallery-slider,
    .single-product .product-gallery .woocommerce-product-gallery__wrapper,
    .single-product .product-gallery .flickity-viewport,
    .single-product .product-gallery .woocommerce-product-gallery__image,
    .single-product .product-gallery .woocommerce-product-gallery__image a {
        width: 100% !important;
    }

    .single-product .product-gallery .woocommerce-product-gallery__image,
    .single-product .product-gallery .woocommerce-product-gallery__image a {
        display: flex !important;
        justify-content: center !important;
    }
}

/* --- 3. Stacked Full-Width Sections Below Hero (Single-Owner Bottom Seams) --- */
.single-product .matchbeast-upsells-wrapper {
    position: relative;
    z-index: 5;
    padding: 30px;
    background: #fff;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    border: var(--mb-product-border-line) !important;
    border-top: 0 !important;
    box-shadow: none !important;
}

.single-product .woocommerce-tabs.wc-tabs-wrapper {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding: 15px !important;
    background: #fff;
    border: var(--mb-product-border-line) !important;
    border-top: 0 !important;
    box-shadow: none !important;
}

@media (min-width: 850px) {
    .single-product .woocommerce-tabs.wc-tabs-wrapper {
        padding: 15px 10px 35px 10px !important;
    }
}

.single-product .matchbeast-faqs-wrapper {
    position: relative;
    z-index: 5;
    background: #fff;
    padding: 20px 15px !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    border: var(--mb-product-border-line) !important;
    border-top: 0 !important;
    box-shadow: none !important;
}

@media (min-width: 850px) {
    .single-product .matchbeast-faqs-wrapper {
        padding: 25px 20px !important;
    }
}

/* --- 4. Related Products Grid Seam (Top Edge Owned by Module Above) --- */
.single-product .related-products-wrapper {
    margin-top: 0 !important;
    margin-bottom: 30px !important;
    padding: 0 !important;
    border: 0 !important;
}

body.single-product .related-products-wrapper .row:not(.slider):not(.row-slider):not(.flickity-enabled):not(.ux-slider):not(.row-masonry) > .product-small.col:nth-child(n) {
    border-top: 0 !important;
}

@media (max-width: 849px) {
    .single-product .related-products-wrapper .product-small .title-wrapper .name {
        height: auto;
        min-height: 3.2em;
    }
}

/* --- 5. FBT Module Alignment (Unified 850px Breakpoint, Single-Owner Seam) --- */
@media (min-width: 850px) {
    .single-product .mb-fbt--mobile {
        display: none !important;
    }

    .single-product .mb-fbt--desktop {
        display: block !important;
        clear: both;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        padding: 28px 30px 30px !important;
        border: var(--mb-product-border-line) !important;
        border-top: 0 !important;
        box-shadow: none !important;
    }
}

@media (max-width: 849px) {
    .single-product .mb-fbt--desktop {
        display: none !important;
    }

    .single-product .mb-fbt--mobile {
        display: block !important;
        margin: 18px 0 !important;
        padding: 16px 0 !important;
        border: none !important;
        border-top: 1px solid #eaeaea !important;
        border-bottom: 1px solid #eaeaea !important;
        background: transparent !important;
        box-shadow: none !important;
    }
}
