/* =====================================================
   SINGLE PRODUCT PAGE - FINAL LAYOUT FIX
   Scoped to body.single-product only
   
   DESKTOP: Image RIGHT, Content LEFT, natural ratio, no crop
   MOBILE: Image first (full width), natural ratio, no crop
   ===================================================== */

/* =====================================================
   DESKTOP LAYOUT (≥ 768px)
   - Image column on RIGHT (smaller: 42%)
   - Content column on LEFT (larger: 58%)
   - Natural image dimensions (800x600 = 4:3)
   - object-fit: contain (no cropping)
   - RTL-safe flex ordering
   ===================================================== */
@media (min-width: 768px) {

    /* Main two-column layout */
    body.single-product .product-gallery-wrapper {
        display: flex !important;
        flex-direction: row-reverse !important;
        gap: 20px !important;
        align-items: flex-start;
        max-width: 1300px;
        margin: 0 auto;
        padding: 0 15px;
    }

    /* Product gallery column (RIGHT side = 42%) */
    body.single-product .product-gallery {
        flex: 0 0 42%;
        max-width: 42%;
        position: sticky;
        top: 20px;
    }

    /* Product details column (LEFT side = 58%) */
    body.single-product .product-details {
        flex: 0 0 58%;
        max-width: 58%;
        padding: 0;
    }

    /* Main image wrapper - full width of column */
    body.single-product .product-main-image-wrapper {
        max-width: 100% !important;
        width: 100%;
        margin: 0;
        background: transparent;
    }

    /* Main image container - auto height for natural ratio */
    body.single-product .product-main-image {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        aspect-ratio: unset !important;
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        border-radius: 12px;
        overflow: hidden;
        display: block;
    }

    /* Image - contain to show full image */
    body.single-product .product-main-image img,
    body.single-product .product-main-image img.main-product-img {
        width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
        object-position: center !important;
        display: block;
        border-radius: 12px;
    }

    /* WooCommerce default gallery */
    body.single-product .woocommerce-product-gallery {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0;
    }

    body.single-product .woocommerce-product-gallery__wrapper {
        width: 100% !important;
        height: auto !important;
        transform: none !important;
    }

    body.single-product .woocommerce-product-gallery__image {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: unset !important;
        padding-top: 0 !important;
        overflow: hidden;
        border-radius: 12px;
        background: transparent !important;
    }

    body.single-product .woocommerce-product-gallery__image img,
    body.single-product .woocommerce-product-gallery .wp-post-image,
    body.single-product .woocommerce-product-gallery__image .wp-post-image {
        width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
        object-position: center !important;
        border-radius: 12px;
    }

    /* Flexslider - auto height */
    body.single-product .flex-viewport {
        height: auto !important;
        aspect-ratio: unset !important;
        overflow: hidden !important;
        background: transparent !important;
        border-radius: 12px;
    }

    body.single-product .flexslider .slides>li {
        width: 100% !important;
        height: auto !important;
    }

    body.single-product .flexslider .slides img {
        width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
        object-position: center !important;
    }

    /* Thumbnails */
    body.single-product .product-thumbnails {
        display: flex;
        gap: 8px;
        margin-top: 12px;
        justify-content: flex-start;
    }

    body.single-product .product-thumbnail {
        width: 75px;
        height: auto;
        aspect-ratio: 1 / 1;
        border-radius: 6px;
        overflow: hidden;
        border: 2px solid transparent;
        cursor: pointer;
        flex-shrink: 0;
        background: #f5f5f5;
    }

    body.single-product .product-thumbnail.active,
    body.single-product .product-thumbnail:hover {
        border-color: var(--navy-primary, #002147);
    }

    body.single-product .product-thumbnail img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    /* WooCommerce thumbnail navigation */
    body.single-product .flex-control-thumbs {
        display: flex !important;
        gap: 8px;
        margin-top: 12px;
    }

    body.single-product .flex-control-thumbs li {
        width: 75px !important;
        height: 75px !important;
        border-radius: 6px;
        overflow: hidden;
        background: #f5f5f5;
    }

    body.single-product .flex-control-thumbs li img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }
}

/* Larger desktop screens - adjust proportions */
@media (min-width: 1200px) {
    body.single-product .product-gallery-wrapper {
        gap: 25px !important;
        max-width: 1400px;
    }

    body.single-product .product-gallery {
        flex: 0 0 40%;
        max-width: 40%;
    }

    body.single-product .product-details {
        flex: 0 0 60%;
        max-width: 60%;
    }

    body.single-product .product-thumbnail,
    body.single-product .flex-control-thumbs li {
        width: 80px !important;
        height: 80px !important;
    }
}

/* =====================================================
   MOBILE LAYOUT (< 768px)
   - Full width image
   - Natural ratio (no forced aspect)
   - object-fit: contain (no cropping)
   - Image FIRST, content BELOW
   ===================================================== */
@media (max-width: 767px) {

    /* Single column layout */
    body.single-product .product-gallery-wrapper {
        display: flex !important;
        flex-direction: column !important;
        width: 100%;
        padding: 0;
        margin: 0;
        gap: 0;
    }

    /* Gallery full width, appears FIRST */
    body.single-product .product-gallery {
        order: 1;
        position: relative;
        top: 0;
        width: 100%;
        margin-bottom: 20px;
    }

    /* Product details appear BELOW */
    body.single-product .product-details {
        order: 2;
        padding: 0 15px;
        width: 100%;
    }

    /* Main image wrapper - full width */
    body.single-product .product-main-image-wrapper {
        max-width: 100% !important;
        width: 100%;
        margin: 0;
        padding: 0;
        background: transparent !important;
        border-radius: 0;
        overflow: hidden;
    }

    /* Main image container - auto height for natural ratio */
    body.single-product .product-main-image {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        aspect-ratio: unset !important;
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        border-radius: 0;
        overflow: hidden;
        display: block;
    }

    /* Image - contain to show full image */
    body.single-product .product-main-image img,
    body.single-product .product-main-image img.main-product-img {
        width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
        object-position: center !important;
        display: block !important;
        border-radius: 0;
        position: relative !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
    }

    /* WooCommerce Gallery - full width */
    body.single-product .woocommerce-product-gallery {
        width: 100% !important;
        max-width: 100% !important;
        background: transparent !important;
    }

    body.single-product .woocommerce-product-gallery__wrapper {
        width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        transform: none !important;
        background: transparent !important;
    }

    /* Natural ratio - no forced aspect */
    body.single-product .woocommerce-product-gallery__image {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: unset !important;
        padding-top: 0 !important;
        position: relative !important;
        overflow: hidden;
        background: transparent !important;
    }

    /* Image - contain to show full image */
    body.single-product .woocommerce-product-gallery__image img,
    body.single-product .woocommerce-product-gallery .wp-post-image,
    body.single-product .woocommerce-product-gallery__image .wp-post-image {
        width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
        object-position: center !important;
        position: relative !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
    }

    /* Flexslider - auto height */
    body.single-product .flex-viewport {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: unset !important;
        overflow: hidden !important;
        background: transparent !important;
    }

    body.single-product .flexslider .slides>li {
        width: 100% !important;
        height: auto !important;
    }

    body.single-product .flexslider .slides img {
        width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
        object-position: center !important;
    }

    /* Thumbnails - horizontal scroll */
    body.single-product .product-thumbnails {
        display: flex;
        gap: 8px;
        margin-top: 12px;
        padding: 4px 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }

    body.single-product .product-thumbnail {
        width: 65px;
        height: 65px;
        min-width: 65px;
        flex-shrink: 0;
        border-radius: 6px;
        overflow: hidden;
        border: 2px solid transparent;
        background: #f5f5f5;
    }

    body.single-product .product-thumbnail img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    /* WooCommerce thumbnail navigation */
    body.single-product .flex-control-thumbs {
        display: flex !important;
        gap: 8px;
        margin-top: 12px;
        padding: 4px 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    body.single-product .flex-control-thumbs li {
        width: 65px !important;
        min-width: 65px;
        height: 65px !important;
        border-radius: 6px;
        overflow: hidden;
        flex-shrink: 0;
        background: #f5f5f5;
    }

    body.single-product .flex-control-thumbs li img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }

    /* Container */
    body.single-product .single-product-page .container {
        padding: 0 10px;
        max-width: 100%;
    }
}

/* Extra small screens */
@media (max-width: 480px) {

    body.single-product .product-thumbnail,
    body.single-product .flex-control-thumbs li {
        width: 55px !important;
        min-width: 55px;
        height: 55px !important;
    }

    body.single-product .single-product-page .container {
        padding: 0 8px;
    }

    body.single-product .product-details {
        padding: 0 10px;
    }
}

/* =====================================================
   RTL SUPPORT
   Ensures proper RTL behavior without breaking layout
   ===================================================== */
@media (min-width: 768px) {

    body.single-product[dir="rtl"] .product-gallery-wrapper,
    body.rtl.single-product .product-gallery-wrapper {
        flex-direction: row !important;
    }

    body.single-product[dir="ltr"] .product-gallery-wrapper,
    body.ltr.single-product .product-gallery-wrapper {
        flex-direction: row-reverse !important;
    }
}

/* =====================================================
   NUCLEAR OVERRIDES - Remove forced aspect ratios
   ===================================================== */

/* Remove any forced aspect ratio on main images */
body.single-product .woocommerce-product-gallery__image,
body.single-product .product-main-image,
body.single-product .flex-viewport {
    aspect-ratio: unset !important;
}

/* Ensure contain, not cover */
body.single-product .woocommerce-product-gallery__image img,
body.single-product .product-main-image img,
body.single-product .flex-viewport img,
body.single-product .flexslider .slides img {
    object-fit: contain !important;
    width: 100% !important;
    height: auto !important;
}