/*
 * WooCommerce Single Product Styles
 */

.single-product-layout {
    padding: 2rem 0;
}

.product-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    margin: 2rem 0;
    align-items: start;
}

.product-images {
    position: relative;
    width: 100%;
}

.product-summary {
    position: static;
    height: auto;
}

/* Hide WooCommerce's default gallery completely */
.woocommerce-product-gallery {
    display: none ;
}

/* Custom Product Gallery Styles */
.custom-product-gallery {
    display: block ;
    visibility: visible ;
    opacity: 1 ;
    width: 100%;
}

.main-product-image {
    width: 100%;
    max-width: 500px;
    height: 500px;
    margin: 0 auto 20px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
}

.main-product-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    transition: transform 0.3s ease;
}

.product-thumbnails-container {
    margin-top: 15px;
}

.product-thumbnails {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
    overflow-x: auto;
}

.thumbnail-item {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    transition: all 0.2s ease;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s ease;
}

.thumbnail-item.active {
    border-color: var(--cloudly-color-accent);
    box-shadow: 0 0 0 3px rgb(var(--cloudly-color-accent-rgb) / 0.3);
}

.thumbnail-item.active img {
    transform: scale(1.05);
}

.thumbnail-item:hover {
    border-color: var(--cloudly-color-accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.thumbnail-item:hover img {
    transform: scale(1.1);
}

/* Main product image container */
.woocommerce-product-gallery__image {
    width: 100% ;
    max-width: 600px ;
    margin: 0 auto 20px ;
    overflow: hidden ;
    border-radius: 8px ;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1) ;
    display: block ;
    visibility: visible ;
    opacity: 1 ;
}

/* Main product image */
.woocommerce-product-gallery__image img {
    width: 100% ;
    height: auto ;
    display: block ;
    transition: transform 0.3s ease ;
}

/* Thumbnail container */
.woocommerce-product-gallery__thumbnails {
    display: flex ;
    gap: 10px ;
    justify-content: center ;
    flex-wrap: wrap ;
    padding: 10px ;
    background: #f9f9f9 ;
    border-radius: 8px ;
    margin-bottom: 20px ;
    overflow-x: auto ;
    min-height: 100px ;
    display: block ;
    visibility: visible ;
    opacity: 1 ;
}

/* Individual thumbnail */
.woocommerce-product-gallery__thumbnail {
    width: 80px ;
    height: 80px ;
    flex-shrink: 0 ;
    cursor: pointer ;
    border: 2px solid transparent ;
    border-radius: 6px ;
    overflow: hidden ;
    position: relative ;
    transition: all 0.2s ease ;
    background: white ;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1) ;
    display: block ;
    visibility: visible ;
    opacity: 1 ;
}

/* Thumbnail image */
.woocommerce-product-gallery__thumbnail img {
    width: 100% ;
    height: 100% ;
    object-fit: cover ;
    display: block ;
    transition: transform 0.2s ease ;
}

/* Active thumbnail highlighting */
.woocommerce-product-gallery__thumbnail.active {
    border-color: var(--cloudly-color-accent) ;
    box-shadow: 0 0 0 3px rgb(var(--cloudly-color-accent-rgb) / 0.3) ;
}

.woocommerce-product-gallery__thumbnail.active img {
    transform: scale(1.05) ;
}

/* Hover effects */
.woocommerce-product-gallery__thumbnail:hover {
    border-color: var(--cloudly-color-accent) ;
    transform: translateY(-2px) ;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15) ;
}

.woocommerce-product-gallery__thumbnail:hover img {
    transform: scale(1.1) ;
}

/* Hide WooCommerce's default zoom functionality */
.woocommerce-product-gallery__image .zoom {
    display: none ;
}

/* Hide WooCommerce's default lightbox */
.woocommerce-product-gallery .woocommerce-product-gallery__trigger {
    display: none ;
}

/* Hide WooCommerce's default flexslider controls */
.woocommerce-product-gallery .flex-control-thumbs {
    display: none ;
}

.woocommerce-product-gallery .flex-direction-nav {
    display: none ;
}

/* Force thumbnail visibility with  */
.woocommerce-product-gallery__thumbnail,
.woocommerce-product-gallery__thumbnails,
.woocommerce-product-gallery__image {
    display: block ;
    visibility: visible ;
    opacity: 1 ;
    position: relative ;
    z-index: 9999 ;
}

/* Force image visibility */
.woocommerce-product-gallery__image img,
.woocommerce-product-gallery__thumbnail img {
    display: block ;
    visibility: visible ;
    opacity: 1 ;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .product-main {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    /* Make the main product image a responsive square on mobile */
    .main-product-image {
        max-width: none;
        height: auto;
        aspect-ratio: 1 / 1; /* height tracks width to form a square */
        display: block; /* override flex to avoid aspect-ratio interference */
        position: relative;
    }

    .main-product-image img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .woocommerce-product-gallery__image {
        max-width: 100%;
        margin-bottom: 15px;
    }
    
    .woocommerce-product-gallery__thumbnail {
        width: 60px ;
        height: 60px ;
    }
}

@media (max-width: 480px) {
    .woocommerce-product-gallery__thumbnail {
        width: 50px ;
        height: 50px ;
    }
    
    .woocommerce-product-gallery__thumbnails {
        gap: 5px ;
        padding: 5px ;
    }
}

/* Fallback for browsers without aspect-ratio support */
@supports not (aspect-ratio: 1 / 1) {
    @media (max-width: 768px) {
        .main-product-image {
            position: relative;
        }

        .main-product-image::before {
            content: "";
            display: block;
            padding-top: 100%; /* square based on width */
        }

        .main-product-image img {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
    }
}

/* Debugging - ensure thumbnails are visible */
.woocommerce-product-gallery__thumbnail::before {
    content: attr(data-thumbnail-num) ;
    position: absolute ;
    top: 2px ;
    left: 2px ;
    background: rgba(0,0,0,0.7) ;
    color: white ;
    font-size: 10px ;
    padding: 2px 4px ;
    border-radius: 2px ;
    z-index: 10 ;
}
