/* Savycart Product Gallery Styles */

/* Base Gallery Styles */
.savycart-gallery {
    position: relative;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

/* Main Image Container - REMOVED ALL PADDING/MARGINS */
.gallery-main-container {
    position: relative;
    width: 100%;
    height: 500px;
    overflow: hidden;
    background: #f8f8f8;
    margin-bottom: 15px;
    border-radius: 8px;
    padding: 0 !important; /* Force remove padding */
}

.gallery-main-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin: 0 !important;
    padding: 0 !important;
}

.gallery-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 !important;
    padding: 0 !important;
}

.gallery-slide.active {
    opacity: 1;
    position: relative;
    z-index: 1;
    transform: translateX(0);
}

.gallery-slide.leaving {
    opacity: 0;
}

/* Touch active state */
.gallery-main-wrapper.touch-active {
    cursor: grabbing;
}

/* Slide animations */
.gallery-slide.slide-in-right {
    animation: slideInRight 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.gallery-slide.slide-out-left {
    animation: slideOutLeft 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.gallery-slide.slide-in-left {
    animation: slideInLeft 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.gallery-slide.slide-out-right {
    animation: slideOutRight 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(-100%);
        opacity: 0;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Image should fill entire container with no margins */
.gallery-main-image {
    width: 100% !important;
    height: 100% !important;
    cursor: pointer;
    transition: opacity 0.3s ease;
    position: relative;
    z-index: 1;
    display: block;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
}

/* Lightbox Trigger Button */
.lightbox-trigger-btn {
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000 !important; /* Very high z-index */
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    touch-action: manipulation; /* Better touch handling */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

.lightbox-trigger-btn:hover {
    background: white;
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.lightbox-trigger-btn:active {
    transform: scale(0.95);
}

.lightbox-trigger-btn svg {
    width: 20px;
    height: 20px;
    color: #333;
}

/* Zoom Functionality */
.zoom-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    opacity: 0;
    z-index: 2;
    transition: opacity 0.2s ease;
    pointer-events: none;
    will-change: opacity, transform;
}

.zoom-container.active {
    opacity: 1;
}

.zoom-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 0.25s cubic-bezier(0.2, 0, 0.2, 1), opacity 0.2s ease;
    will-change: transform;
    opacity: 0;
    pointer-events: none;
    backface-visibility: hidden;
    transform: scale(1.1) translate(0%, 0%); /* Start slightly zoomed for smoother effect */
}

/* Navigation Arrows */
.gallery-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 20;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.gallery-arrow:hover {
    background: white;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.gallery-arrow-prev {
    left: 20px;
}

.gallery-arrow-next {
    right: 20px;
}

.gallery-arrow svg {
    width: 24px;
    height: 24px;
    color: #333;
}

/* Thumbnails Container - REMOVED PADDING */
.gallery-thumbnails-container {
    position: relative;
    display: flex;
    align-items: center;
    max-width: 100%;
    margin: 0 auto;
    padding: 0 !important; /* Remove padding */
}

.gallery-thumbnails-wrapper {
    flex: 1;
    display: flex;
    overflow-x: auto;
    scroll-behavior: smooth;
    gap: 10px;
    padding: 10px 0 !important; /* Only top/bottom padding */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.gallery-thumbnails-wrapper::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.gallery-thumbnail {
    flex: 0 0 auto;
    width: 80px;
    height: 80px;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0.7;
    margin: 0 !important;
}

.gallery-thumbnail:hover {
    opacity: 1;
    border-color: #ddd;
}

.gallery-thumbnail.active {
    opacity: 1;
    border-color: #2196F3;
    box-shadow: 0 0 0 1px #2196F3;
}

.thumbnail-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.gallery-thumbnail:hover .thumbnail-image {
    transform: scale(1.05);
}

/* Thumbnail Arrows */
.thumb-arrow {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0 5px;
}

.thumb-arrow:hover {
    background: #f8f8f8;
    border-color: #999;
}

.thumb-arrow svg {
    width: 16px;
    height: 16px;
    color: #666;
}

/* Lightbox Styles */
.savycart-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.savycart-lightbox.open {
    display: flex;
    opacity: 1;
    align-items: center;
    justify-content: center;
}

.lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.lightbox-container {
    position: relative;
    width: 90%;
    height: 90%;
    max-width: 1400px;
    max-height: 90vh;
    background: white;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: 10;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.lightbox-header {
    padding: 20px;
    display: flex;
    justify-content: flex-end;
    border-bottom: 3px solid #eee;
    background: white;
    flex-shrink: 0;
}

.lightbox-close {
    background-color: #d4e3db;
    border: none;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
    color: #333;
    border-radius: 50%;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.lightbox-close:hover {
    background: #f8f8f8;
}

.lightbox-close svg {
    width: 24px;
    height: 24px;
    stroke: #333;
}

.lightbox-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    height: calc(100% - 81px); /* Subtract header height */
    min-height: 0;
}

.lightbox-main-image-container {
    flex: 0 0 70%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #f8f8f8;
    border-right: 1px solid #eee;
    overflow: hidden;
    min-height: 0;
}

.lightbox-main-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.lightbox-sidebar {
    flex: 0 0 30%;
    padding: 20px;
    overflow-y: auto;
    background: white;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.lightbox-thumbnails {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 4 per row for smaller thumbnails */
    gap: 8px; /* Smaller gap */
    flex-shrink: 0;
    max-height: 100%;
    overflow-y: auto;
}

.lightbox-thumbnail {
    position: relative;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    aspect-ratio: 1/1;
    background: #f8f8f8;
    flex-shrink: 0;
}

.lightbox-thumbnail:hover {
    border-color: #ddd;
}

.lightbox-thumbnail.active {
    border-color: #2196F3;
    box-shadow: 0 0 0 1px #2196F3;
}

.lightbox-thumb-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.lightbox-thumbnail:hover .lightbox-thumb-image {
    transform: scale(1.05);
}

/* Responsive Styles */
@media (max-width: 1024px) {
    .gallery-main-container {
        height: 450px;
    }
    
    .lightbox-container {
        width: 95%;
        height: 95%;
        max-height: 95vh;
    }
    
    .lightbox-content {
        flex-direction: column;
    }
    
    .lightbox-main-image-container {
        flex: 0 0 60%;
        border-right: none;
        border-bottom: 1px solid #eee;
        padding: 15px;
        min-height: 300px;
        max-height: 60vh;
    }
    
    .lightbox-sidebar {
        flex: 0 0 40%;
        max-height: 40vh;
        padding: 15px;
    }
    
    .lightbox-thumbnails {
        grid-template-columns: repeat(5, 1fr); /* 5 per row on tablet */
        gap: 6px;
        max-height: calc(100% - 20px);
    }
}

@media (max-width: 768px) {
    .gallery-main-container {
        height: 400px;
    }
    
    /* Hide arrows on mobile */
    .gallery-arrow {
        display: none !important;
    }
    
    .thumb-arrow {
        display: none !important;
    }
    
    .gallery-thumbnail {
        width: 70px;
        height: 70px;
    }
    
    /* Zoom disabled on mobile */
    .zoom-container {
        display: none !important;
    }
    
    .gallery-main-image {
        opacity: 1 !important;
        cursor: pointer; /* Keep pointer for lightbox on mobile */
    }
    
    /* Lightbox trigger button for mobile */
    .lightbox-trigger-btn {
        width: 44px !important;
        height: 44px !important;
        bottom: 15px !important;
        right: 15px !important;
        z-index: 1001 !important; /* Even higher for mobile */
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2);
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.3);
    }
    
    .lightbox-trigger-btn:active {
        transform: scale(0.9);
        background: white;
    }
    
    .lightbox-trigger-btn svg {
        width: 20px;
        height: 20px;
    }
    
    /* Lightbox adjustments - Full screen */
    .lightbox-container {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    
    .lightbox-content {
        flex-direction: column;
        height: calc(100% - 60px);
    }
    
    .lightbox-header {
        padding: 8px;
    }
    
    .lightbox-main-image-container {
        flex: 0 0 71%;
        padding: 10px !important; /* Reduced padding */
        min-height: 250px;
        max-height: 70vh;
        border-right: none;
        border-bottom: 4px solid #eee;
    }
    
    .lightbox-sidebar {
        flex: 0 0 20%;
        padding: 15px;
        max-height: 30vh;
        overflow-y: auto;
    }
    
    .lightbox-thumbnails {
        grid-template-columns: repeat(5, 1fr); /* 4 per row on mobile */
        gap: 6px;
        max-height: none;
    }
    
    .lightbox-main-image {
        max-height: 100%;
        width: auto;
        height: auto;
    }
}

@media (max-width: 480px) {
    .gallery-main-container {
        height: 350px;
    }
    
    .gallery-thumbnail {
        width: 60px;
        height: 60px;
    }
    
    .lightbox-container {
        width: 100% !important;
        height: 100% !important;
    }
    
    .lightbox-main-image-container {
        flex: 0 0 75%;
        padding: 0px !important; /* Minimal padding */
        min-height: 200px;
        max-height: 50vh;
    }
    
    .lightbox-sidebar {
        flex: 0 0 25%;
        padding: 10px;
        max-height: 25vh;
    }
    
    .lightbox-thumbnails {
        grid-template-columns: repeat(5, 1fr); /* 3 per row on small mobile */
        gap: 5px;
    }
    
    .lightbox-trigger-btn {
        width: 40px !important;
        height: 40px !important;
        bottom: 10px !important;
        right: 10px !important;
    }
    
    .lightbox-trigger-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* Body scroll lock when lightbox is open */
body.lightbox-open {
    overflow: hidden !important;
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .gallery-main-image {
        cursor: pointer;
    }
    
    .gallery-arrow {
        display: none;
    }
    
    .thumb-arrow {
        display: none;
    }
    
    .zoom-container {
        display: none !important;
    }
    
    .lightbox-trigger-btn {
        width: 48px !important;
        height: 48px !important;
        z-index: 1002 !important;
    }
}

/* Loading animation for slides */
@keyframes slideLoading {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.gallery-slide:not(.active) .gallery-main-image {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: slideLoading 1.5s infinite;
}

/* Ensure lightbox container doesn't shift */
.lightbox-main-image-container {
    contain: layout paint;
}

/* Force remove any inherited margins/padding */
.savycart-gallery * {
    box-sizing: border-box;
}

.savycart-gallery .gallery-main-container,
.savycart-gallery .gallery-main-wrapper,
.savycart-gallery .gallery-slide,
.savycart-gallery .gallery-main-image {
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    outline: none !important;
}