/* ===== Vanilla Carousel Component ===== */
/* Modern carousel component matching the design system */

/* Main carousel container */
.carousel-container {
    position: relative;
    overflow: hidden;
    background: var(--gray-100);
    box-shadow: var(--shadow-lg);
}

/* Track that holds all slides */
.carousel-track {
    display: flex;
    transition: transform var(--transition-slow) cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

/* Individual slide */
.carousel-slide {
    min-width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.carousel-slide img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

/* Main image display area */
.carousel-main {
    position: relative;
    aspect-ratio: 16/9;
    overflow: hidden;
    background: var(--gray-900);
}

/* Thumbnails container */
.carousel-thumbnails {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-3);
    padding: var(--space-2) 0;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-400) var(--gray-100);
}

/* Webkit scrollbar styling */
.carousel-thumbnails::-webkit-scrollbar {
    height: 6px;
}

.carousel-thumbnails::-webkit-scrollbar-track {
    background: var(--gray-100);
    border-radius: var(--radius-full);
}

.carousel-thumbnails::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: var(--radius-full);
}

.carousel-thumbnails::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}

/* Individual thumbnail */
.carousel-thumb {
    flex-shrink: 0;
    width: 100px;
    height: 75px;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all var(--transition-fast);
    opacity: 0.7;
    background: var(--gray-200);
}

.carousel-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.carousel-thumb:hover {
    border-color: var(--primary-blue-light);
    transform: scale(1.05);
    opacity: 1;
}

.carousel-thumb.active {
    border-color: var(--primary-blue);
    box-shadow: var(--shadow-md);
    opacity: 1;
    transform: scale(1.08);
}

/* Navigation arrows */
.carousel-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-md);
    z-index: 2;
    color: var(--gray-700);
}

.carousel-nav:hover {
    background: white;
    transform: translateY(-50%) scale(1.1);
    box-shadow: var(--shadow-xl);
    color: var(--primary-blue);
}

.carousel-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.carousel-nav.prev { 
    left: var(--space-3); 
}

.carousel-nav.next { 
    right: var(--space-3); 
}

.carousel-nav i {
    font-size: 18px;
}

/* Dots indicator */
.carousel-dots {
    position: absolute;
    bottom: var(--space-3);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-full);
}

.carousel-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.5);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
}

.carousel-dot:hover {
    background: rgba(255, 255, 255, 0.8);
    transform: scale(1.2);
}

.carousel-dot.active {
    width: 24px;
    background: white;
}

/* Loading state */
.carousel-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--gray-500);
    font-size: var(--text-lg);
}

/* Counter indicator */
.carousel-counter {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    color: white;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: 500;
}

/* Full screen mode */
.carousel-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    /* Use dynamic viewport height with fallback */
    height: 100vh;
    height: 100dvh;
    z-index: var(--z-modal);
    background: rgba(0, 0, 0, 0.95);
    border-radius: 0;
    /* Add safe area padding */
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
    display: flex;
    flex-direction: column;
}

.carousel-fullscreen .carousel-main {
    aspect-ratio: unset;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    /* Prevent overflow on small screens */
    overflow: hidden;
    position: relative;
}

.carousel-fullscreen .carousel-track {
    display: flex;
    align-items: center;
    height: 100%;
}

.carousel-fullscreen .carousel-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.carousel-fullscreen .carousel-track img {
    object-fit: contain;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

.carousel-fullscreen .carousel-thumbnails {
    position: relative;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.8);
    margin: 0;
    padding: var(--space-2);
    justify-content: center;
    max-height: 100px;
    overflow-x: auto;
    overflow-y: hidden;
}

/* Close button for fullscreen */
.carousel-close {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: white;
    font-size: 24px;
    z-index: 3;
}

.carousel-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .carousel-nav {
        width: 40px;
        height: 40px;
        background: rgba(255, 255, 255, 0.8);
    }
    
    .carousel-nav.prev { 
        left: var(--space-2); 
    }
    
    .carousel-nav.next { 
        right: var(--space-2); 
    }
    
    .carousel-nav i {
        font-size: 16px;
    }
    
    .carousel-thumb {
        width: 80px;
        height: 60px;
    }
    
    .carousel-dots {
        bottom: var(--space-2);
        padding: var(--space-1) var(--space-2);
    }
    
    .carousel-dot {
        width: 6px;
        height: 6px;
    }
    
    .carousel-dot.active {
        width: 18px;
    }
    
    /* Fullscreen mobile adjustments */
    .carousel-fullscreen {
        /* Ensure it doesn't exceed viewport */
        max-height: 100vh;
        max-height: 100dvh;
    }
    
    .carousel-fullscreen .carousel-thumbnails {
        max-height: 80px;
        padding: var(--space-1);
    }
    
    .carousel-fullscreen .carousel-thumb {
        width: 60px;
        height: 45px;
    }
    
    .carousel-fullscreen .carousel-close {
        width: 40px;
        height: 40px;
        font-size: 20px;
        top: var(--space-2);
        right: var(--space-2);
        /* Ensure it's always visible */
        position: fixed;
        z-index: var(--z-tooltip);
    }
    
    .carousel-fullscreen .carousel-nav {
        /* Make nav buttons more visible on mobile */
        opacity: 0.9;
        width: 36px;
        height: 36px;
    }
    
    .carousel-fullscreen .carousel-counter {
        font-size: var(--text-xs);
        padding: 2px var(--space-2);
        top: var(--space-2);
        left: var(--space-2);
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .carousel-nav {
        opacity: 0.8;
    }
    
    .carousel-container:hover .carousel-nav {
        opacity: 1;
    }
}

/* Smooth transitions for all states */
.carousel-container * {
    -webkit-tap-highlight-color: transparent;
}

/* Accessibility */
.carousel-container:focus-within .carousel-nav,
.carousel-nav:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

/* Loading skeleton for thumbnails */
.carousel-thumb.skeleton {
    background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-300) 50%, var(--gray-200) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

/* Fade in animation */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.carousel-slide img {
    animation: fadeIn 0.3s ease-in-out;
}

/* Prevent image dragging */
.carousel-container img {
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

/* Make main carousel area clickable for fullscreen */
.carousel-main {
    pointer-events: all;
    cursor: pointer;
}

/* Make thumbnails clickable */
.carousel-thumb {
    pointer-events: all;
}