/* Optimized Gallery CSS - Maintains Horizontal Layout with Performance Improvements */

/* Gallery Container - Horizontal Scrolling Layout (preserved from original) */
.gallery-container {
    width: 100%;
    margin: 0;
    padding: 0;
    height: 40vh;
    min-height: 300px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    white-space: nowrap;
    font-size: 0;
    line-height: 0;
    letter-spacing: 0;
    position: relative;
    /* Performance improvements */
    will-change: scroll-position;
    contain: layout style paint;
}

/* Hide scrollbar for Chrome, Safari and Opera */
.gallery-container::-webkit-scrollbar { 
    display: none; 
}

/* Gallery spacing (preserved from original) */
.gallery-second { margin-top: 1rem; }
.gallery-third { margin-top: 1rem; }
.gallery-fourth { margin-top: 1rem; }
.gallery-container:first-of-type { margin-top: 0 !important; }
.gallery-third + .gallery-container { margin-top: 1rem; }

/* Gallery Items Wrapper - Horizontal Flex Layout */
.gallery-container .gallery-items-wrapper {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    height: 100%;
    margin: 0;
    padding: 0;
    white-space: nowrap;
    font-size: 0;
    line-height: 0;
    /* Performance optimizations */
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Gallery Items - Horizontal Layout (preserved from original) */
.gallery-item {
    display: flex;
    flex: 0 0 auto;
    width: auto;
    height: 100%;
    margin: 0;
    margin-right: -1px; /* overlap by 1px to kill hairline gaps */
    padding: 0;
    line-height: 0;
    font-size: 0;
    vertical-align: top;
    transition: transform 180ms ease, opacity 180ms ease, filter 180ms ease, box-shadow 180ms ease;
    /* Performance improvements */
    will-change: transform;
    backface-visibility: hidden;
}

.gallery-item:last-child { 
    margin-right: 0; 
}

/* Image Frame (preserved from original) */
.image-frame {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    display: block;
    overflow: hidden;
    line-height: 0;
    font-size: 0;
    cursor: grab;
    position: relative;
    background: #fff;
}

.image-frame:active {
    cursor: grabbing;
}

.image-frame:hover { 
    transform: none; 
    box-shadow: none; 
    border-color: transparent; 
}

/* Images - Optimized Loading */
.image-frame img {
    height: 100%;
    width: auto;
    display: block;
    margin: 0;
    padding: 0;
    border: 0;
    line-height: 0;
    font-size: 0;
    object-fit: cover;
    position: relative;
    backface-visibility: hidden;
    transform: translateZ(0);
    /* Performance improvements */
    will-change: opacity;
    transition: opacity 0.3s ease;
}

/* Loading placeholder improvements */
.image-frame img[src*="data:image/svg+xml"] {
    background: linear-gradient(90deg, #f5f5f5 25%, #e5e5e5 37%, #f5f5f5 63%);
    background-size: 400% 100%;
    animation: loading-shimmer 1.5s ease-in-out infinite;
}

@keyframes loading-shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Improved content-visibility for performance */
.gallery-container,
.gallery-container .gallery-item {
    content-visibility: auto;
    contain-intrinsic-size: 300px 200px;
}

/* Prefers-reduced-motion support */
@media (prefers-reduced-motion: reduce) {
    .gallery-item,
    .image-frame img {
        transition: none;
    }
    
    .image-frame img[src*="data:image/svg+xml"] {
        animation: none;
        background: #f5f5f5;
    }
    
    .gallery-container {
        scroll-behavior: auto;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .gallery-container {
        height: 35vh;
        min-height: 250px;
    }
    
    .gallery-item {
        /* Reduce complexity on mobile */
        transform: translateZ(0);
    }
}