/**
 * Gallery Image Optimization Styles
 * Lazy loading, loading states, and performance optimizations
 */

/* Lazy Loading States */
img[data-lazy-src] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    background: #f3f4f6;
    background-image: 
        linear-gradient(45deg, transparent 40%, rgba(255,255,255,0.5) 50%, transparent 60%),
        linear-gradient(90deg, #f3f4f6 0%, #e5e7eb 50%, #f3f4f6 100%);
    background-size: 200% 100%, 200% 100%;
    animation: shimmer 1.5s infinite;
}

img[data-lazy-src].loaded {
    opacity: 1;
    background: none;
    animation: none;
}

img[data-lazy-src].loading {
    opacity: 0.7;
}

img[data-lazy-src].error {
    opacity: 0.5;
    background: #fef2f2;
    border: 2px dashed #fca5a5;
}

/* Loading Spinner */
.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner-inner {
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top: 2px solid #60a5fa;
    border-radius: 50%;
    animation: spin 0.8s linear infinite reverse;
    margin: 6px auto;
}

/* Error Placeholder */
.error-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #6b7280;
    z-index: 10;
}

.error-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.error-text {
    font-size: 12px;
    font-weight: 500;
}

/* Shimmer Animation */
@keyframes shimmer {
    0% {
        background-position: -200% 0, -200% 0;
    }
    100% {
        background-position: 200% 0, 200% 0;
    }
}

/* Spin Animation */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Gallery Grid Optimizations */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    padding: 1rem;
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    background: #f9fafb;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.1);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* Thumbnail Optimizations */
.thumbnail {
    width: 100%;
    height: auto;
    max-width: 300px;
    max-height: 300px;
    object-fit: cover;
    border-radius: 4px;
}

.thumbnail-small {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 4px;
}

.thumbnail-medium {
    width: 200px;
    height: 200px;
    object-fit: cover;
    border-radius: 4px;
}

.thumbnail-large {
    width: 600px;
    height: 600px;
    object-fit: cover;
    border-radius: 8px;
}

/* Progressive Loading */
.progressive-image {
    position: relative;
    overflow: hidden;
}

.progressive-image .placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

.progressive-image .main-image {
    position: relative;
    z-index: 2;
    transition: opacity 0.3s ease-in-out;
}

/* Performance Optimizations */
.gallery-container {
    contain: layout style paint;
}

.gallery-item {
    contain: layout style paint;
    will-change: transform;
}

/* Responsive Images */
@media (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 1rem;
        padding: 0.5rem;
    }
    
    .gallery-item {
        min-height: 250px;
    }
}

@media (max-width: 480px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 0.75rem;
        padding: 0.25rem;
    }
    
    .gallery-item {
        min-height: 200px;
    }
}

/* Loading Animation */
@keyframes loading {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Fade In Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.gallery-item.loaded {
    animation: fadeIn 0.5s ease-out;
}

/* Focus States for Accessibility */
.gallery-item:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.gallery-item:focus img {
    outline: none;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .gallery-item {
        border: 2px solid #000;
    }
    
    .error-placeholder {
        color: #000;
        background: #fff;
        padding: 8px;
        border-radius: 4px;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    img[data-lazy-src],
    .gallery-item,
    .progressive-image .main-image {
        transition: none;
    }
    
    .spinner,
    .spinner-inner {
        animation: none;
    }
    
    .gallery-item.loaded {
        animation: none;
    }
}
