/* Product Details Slick Slider Styles */

/* Main Slider Container */
.main-image-slider {
    position: relative;
    margin-bottom: 1rem;
    min-height: 400px;
    /* Ensure minimum height */
}

.main-slider {
    position: relative;
    width: 100%;
    min-height: 400px;
    /* Ensure minimum height */
}

.main-slider .slide-item {
    position: relative;
    outline: none;
    display: block !important;
    /* Force display when visible */
}

.main-slider .slide-item img {
    width: 100%;
    height: auto;
    display: block;
    /* border-radius: 8px; */
    max-width: 100%;
}

/* Force visibility for filtered slides */
.main-slider .slide-item:not([style*="display: none"]) {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Slider Navigation Buttons */
.slider-nav {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    z-index: 15;
    pointer-events: none;
    height: 0;
}

.main_prev_btn,
.main_next_btn {
    position: absolute;
    top: 0;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #e5e5e5;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    pointer-events: auto;
    z-index: 16;
}

.main_prev_btn {
    left: 10px;
}

.main_next_btn {
    right: 10px;
}

.main_prev_btn:hover,
.main_next_btn:hover {
    background: rgba(255, 255, 255, 1);
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.main_prev_btn i,
.main_next_btn i {
    font-size: 14px;
    color: #333;
}

/* Thumbnail Container */
.thumbnail-container {
    margin-top: 0.5rem;
}

.thumbnail-slider {
    position: relative;
}

.thumbnail-slider .px-1 {
    padding: 0 4px;
}

.product-thumbnail {
    width: 100%;
    height: auto;
    /* border-radius: 6px; */
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

/* Slick Slider Overrides */
.slick-slide {
    outline: none;
}

.slick-dots {
    bottom: -45px;
}

/* Mobile Horizontal Layout - Force Apply */
@media screen and (max-width: 768px) {

    html,
    body {
        overflow-x: hidden !important;
    }

    /* Force mobile layout container */
    .tf-product-media-wrap.thumbs-bottom .product-gallery,
    .product-gallery {
        display: flex !important;
        gap: 10px !important;
        align-items: flex-start !important;
        flex-direction: row !important;
        width: 100% !important;
    }
}

/* Force Mobile Layout Class - Highest Priority */
body.mobile-layout .product-gallery {
    display: flex !important;
    gap: 10px !important;
    align-items: flex-start !important;
    flex-direction: row !important;
    width: 100% !important;
}

body.mobile-layout .main-image-slider {
    flex: 0 0 75% !important;
    width: 75% !important;
    max-width: 75% !important;
    margin-bottom: 0 !important;
}

body.mobile-layout .thumbnail-container {
    flex: 0 0 25% !important;
    width: 25% !important;
    max-width: 25% !important;
    margin-top: 0 !important;
    overflow: hidden !important;
}

body.mobile-layout .thumbnail-slider {
    height: 100% !important;
}

/* Mobile Horizontal Layout - Media Query Based */
@media screen and (max-width: 768px) {

    /* Force main image slider to left side */
    .tf-product-media-wrap.thumbs-bottom .main-image-slider,
    .main-image-slider {
        flex: 0 0 75% !important;
        /* 75% width for main image */
        width: 75% !important;
        max-width: 75% !important;
    }

    .tf-product-media-wrap.thumbs-bottom .main-slider,
    .main-slider {
        min-height: auto !important;
        width: 100% !important;
    }

    /* Force thumbnail container to right side */
    .tf-product-media-wrap.thumbs-bottom .thumbnail-container,
    .thumbnail-container {
        flex: 0 0 25% !important;
        /* 25% width for thumbnails */
        margin-top: 0 !important;
        margin-left: 0 !important;
        overflow: hidden !important;
        width: 25% !important;
        max-width: 25% !important;
    }

    /* Vertical thumbnail layout */
    .thumbnail-slider {
        height: 100% !important;
    }

    .thumbnail-slider.slick-vertical .slick-slide {
        display: block !important;
        height: auto !important;
        border: none !important;
    }

    .thumbnail-slider .px-1 {
        padding: 2px 0 !important;
        /* Vertical spacing */
        margin-bottom: 4px !important;
        width: 100% !important;
    }

    .product-thumbnail {
        aspect-ratio: 3/4 !important;
        object-fit: cover !important;
        border-radius: 6px !important;
        width: 100% !important;
        height: auto !important;
    }

    /* Vertical slider specific styles */
    .thumbnail-slider.slick-vertical .slick-track {
        height: auto !important;
        width: 100% !important;
    }

    .thumbnail-slider.slick-vertical .slick-list {
        height: 100% !important;
        width: 100% !important;
    }

    /* Force mobile vertical layout class */
    .thumbnail-slider.mobile-vertical-layout {
        height: 100% !important;
    }

    .thumbnail-slider.mobile-vertical-layout .slick-track {
        height: auto !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .thumbnail-slider.mobile-vertical-layout .slick-slide {
        display: block !important;
        height: auto !important;
        width: 100% !important;
        margin-bottom: 4px !important;
    }

    /* Navigation buttons adjustment */
    .main_prev_btn,
    .main_next_btn {
        width: 32px !important;
        height: 32px !important;
    }

    .main_prev_btn {
        left: 5px !important;
    }

    .main_next_btn {
        right: 5px !important;
    }

    .main_prev_btn i,
    .main_next_btn i {
        font-size: 11px !important;
    }
}

/* Extra small devices */
@media (max-width: 576px) {
    .product-gallery {
        gap: 8px !important;
    }

    .main-image-slider {
        flex: 0 0 63% !important;
        /* Slightly smaller on very small screens */
    }

    .thumbnail-container {
        flex: 0 0 34% !important;
        /* Slightly larger for thumbnails */
    }

    .thumbnail-slider .px-1 {
        margin-bottom: 3px !important;
    }

    .main_prev_btn,
    .main_next_btn {
        width: 28px !important;
        height: 28px !important;
    }

    .main_prev_btn i,
    .main_next_btn i {
        font-size: 10px !important;
    }
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

/* Slick Track Alignment */
.slick-track {
    display: flex !important;
    align-items: flex-start;
}

.slick-slide {
    height: auto;
    float: none !important;
}

/* Conditional Left Alignment for Thumbnails - chỉ áp dụng khi cần thiết */
/* CSS này sẽ được override bởi JavaScript khi cần */
.thumbnail-slider .slick-list {
    overflow: hidden;
    touch-action: pan-y !important;
    pointer-events: auto !important;
}

/* Base styling cho thumbnail slider */
.thumbnail-slider {
    position: relative;
}

/* Specific class cho khi force left alignment (≤4 images) */
.thumbnail-slider.force-left-align .slick-track {
    margin-left: 0 !important;
    margin-right: auto !important;
    transform: translate3d(0px, 0px, 0px) !important;
}

.thumbnail-slider.force-left-align {
    text-align: left !important;
}

.thumbnail-slider.force-left-align.slick-slider {
    margin-left: 0 !important;
    margin-right: auto !important;
}

.slick-slide>div {
    height: 100%;
}

/* Thumbnail Active State */
.thumbnail-slider .slick-current .product-thumbnail {
    border: 2px solid #e43131;
}

/* Loading States */
.main-slider.loading {
    opacity: 0.7;
    pointer-events: none;
}

.main-slider.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 20;
}

@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Transition Effects */
.main-slider,
.thumbnail-slider {
    transition: opacity 0.3s ease;
}

.main-slider.transitioning,
.thumbnail-slider.transitioning {
    opacity: 0.5;
}

/* Highest priority: remove margin between thumbnails for mobile layout */
body.mobile-layout .thumbnail-slider .px-1,
body.mobile-layout .thumbnail-slider.mobile-vertical-layout .slick-slide {
    margin-bottom: 0 !important;
    padding: 0 !important;
}

body.mobile-layout .thumbnail-slider .px-1:last-child,
body.mobile-layout .thumbnail-slider.mobile-vertical-layout .slick-slide:last-child {
    margin-bottom: 0 !important;
}

/* Use aspect-ratio on mobile layout to equalize heights */
body.mobile-layout .main-image-slider {
    /* width: 75% by JS/CSS earlier */
    aspect-ratio: 3 / 4 !important;
    /* height = width * 4/3 */
    height: auto !important;
}

body.mobile-layout .thumbnail-container {
    /* width: 25% by JS/CSS earlier */
    aspect-ratio: 1 / 4 !important;
    /* height = width * 4 */
    height: auto !important;
}

/* Shrink thumbnails and add spacing on mobile */
body.mobile-layout .thumbnail-slider.mobile-vertical-layout .slick-slide {
    transform: scale(0.95) !important;
    transform-origin: top center !important;
    margin-bottom: 2px !important;
}

body.mobile-layout .thumbnail-slider.mobile-vertical-layout .slick-slide:last-child {
    margin-bottom: 0 !important;
}

/* Override slider wrapper margin on mobile */
@media only screen and (max-width: 768px) {

    /* Remove thumbnail border-radius on mobile */
    .product-thumbnail,
    .thumbnail-slider .px-1,
    .thumbnail-slider .slick-slide,
    .thumbnail-slider,
    .thumbnail-container {
        border-radius: 0 !important;
    }

    .tf-product-media-wrap {
        margin-bottom: 0 !important;
    }

    .product-gallery {
        margin-top: 15px;
    }

    .variant-picker-item {
        margin-bottom: 0px !important;
    }
}