/* =====================================================
   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;
}

/* =====================================================
   FIX BOTTOM SPACING - Single Product Page
   Eliminates the large empty space between the
   related products section and the footer.
   Scoped to body.single-product only.
   ===================================================== */

/* --- Page & Container Level --- */
body.single-product .single-product-page {
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
    min-height: auto !important;
}

body.single-product .single-product-page .container {
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
}

/* Override the global .woocommerce min-height: 60vh */
body.single-product .woocommerce {
    min-height: auto !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

/* --- Related Products Section --- */
body.single-product .related-products {
    margin-bottom: 0 !important;
    padding-bottom: 30px !important;
}

body.single-product .related-products-swiper {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

body.single-product .related-products-swiper .swiper-wrapper {
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
}

body.single-product .related-products .swiper-slide {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
    height: auto !important;
}

/* --- Product Cards inside Related Products ---
   Override global styles that stretch cards vertically */
body.single-product .related-products .product-card {
    height: auto !important;
    margin-bottom: 0 !important;
}

body.single-product .related-products .product-info {
    flex: 0 1 auto !important;
    padding: 8px 5px !important;
    padding-bottom: 4px !important;
}

body.single-product .related-products .product-price {
    margin-top: 4px !important;
    margin-bottom: 0 !important;
}

body.single-product .related-products .product-actions {
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
}

body.single-product .related-products .product-card-content {
    flex: 0 1 auto !important;
    padding-top: 8px !important;
    padding-bottom: 0 !important;
}

body.single-product .related-products .product-title {
    min-height: unset !important;
    -webkit-line-clamp: 2;
    margin-bottom: 2px !important;
}

body.single-product .related-products .swiper-slide {
    height: auto !important;
    align-self: flex-start !important;
}

body.single-product .related-products-swiper .swiper-wrapper {
    align-items: flex-start !important;
    height: auto !important;
}

/* --- Prevent any site-main wrapper from adding space --- */
body.single-product .site-main {
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
    min-height: auto !important;
}

/* =====================================================
   RELATED PRODUCTS SLIDER STYLES
   ===================================================== */

/* Section Layout */
body.single-product .related-products {
    position: relative;
    width: 100%;
    margin-top: 30px;
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
}

body.single-product .related-products-swiper {
    padding-bottom: 10px !important;
    /* Minimal for shadow/overflow if needed */
    margin-bottom: 0 !important;
}

body.single-product .related-products .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 5px;
}

body.single-product .related-products .section-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    color: #333;
}

/* Navigation Buttons */
body.single-product .slider-nav-buttons {
    display: flex;
    gap: 10px;
}

body.single-product .slider-nav-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

body.single-product .slider-nav-btn:hover {
    background: var(--navy-primary, #002147);
    border-color: var(--navy-primary, #002147);
    color: #fff;
}

body.single-product .slider-nav-btn.swiper-button-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f5f5f5;
    color: #ccc;
    border-color: #eee;
}

/* Slider Layout */
body.single-product .related-products-swiper {
    width: 100%;
    overflow: hidden;
    padding: 5px;
    /* Prevent shadow clipping */
}

/* Product Card Improvements */
body.single-product .related-products .product-card {
    display: flex;
    flex-direction: column;
    height: auto;
    background: transparent;
    border: none;
    box-shadow: none;
}

/* Image Container */
body.single-product .related-products .product-image {
    position: relative;
    aspect-ratio: 4/5 !important;
    /* Force portrait ratio */
    overflow: hidden;
    border-radius: 12px;
    background: #f8f8f8;
    width: 100%;
    margin-bottom: 0;
}

body.single-product .related-products .product-image img {
    width: 100%;
    height: 100% !important;
    object-fit: cover !important;
    /* Ensure image covers area */
    display: block;
    transition: transform 0.3s ease;
}

body.single-product .related-products .product-card:hover .product-image img {
    transform: scale(1.05);
}

/* Content Layout */
body.single-product .related-products .product-card-content {
    padding: 0 5px;
    text-align: right;
    /* RTL support */
}

body.single-product .related-products .product-title {
    font-size: 15px;
    margin: 0 0 2px;
    line-height: 1.4;
    font-weight: 600;
    min-height: unset;
}

body.single-product .related-products .product-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--navy-primary, #002147);
    margin-top: 4px;
}

/* Mobile Specific Adjustments */
@media (max-width: 767px) {
    body.single-product .related-products {
        margin-top: 30px;
    }

    body.single-product .related-products .section-title {
        font-size: 20px;
    }

    body.single-product .slider-nav-btn {
        width: 36px;
        height: 36px;
    }

    /* Ensure 2 columns fit nicely */
    body.single-product .related-products .swiper-slide {
        width: calc(50% - 5px);
        /* Fallback */
    }

    body.single-product .related-products .product-image {
        border-radius: 8px;
    }

    body.single-product .related-products .product-title {
        font-size: 14px;
    }

    body.single-product .related-products .product-price {
        font-size: 15px;
    }
}