/**
 * NidusLab Lazy Loading CSS
 * Enhanced styles for smooth image loading transitions
 * Production-ready with performance optimizations
 */

/* Base lazy image styles */
.lazy-image,
[data-lazy] {
    transition: opacity 0.3s ease-in-out, filter 0.3s ease-in-out;
    will-change: opacity;
}

/* Loading state */
.lazy-loading {
    opacity: 0.7;
    filter: blur(1px);
}

/* Loaded state */
.lazy-loaded {
    opacity: 1;
    filter: none;
}

/* Error state */
.lazy-error {
    opacity: 0.6;
    filter: grayscale(100%) brightness(0.8);
    position: relative;
}

.lazy-error::after {
    content: "⚠️";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    z-index: 1;
}

/* Wrapper for shimmer animation */
.lazy-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    background-color: #f8f9fa;
}

/* Shimmer loading animation */
.lazy-shimmer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    animation: shimmer 1.5s infinite;
    pointer-events: none;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Pulse animation for loading states */
.lazy-pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0.6;
    }
}

/* Fade-in animation for loaded images */
.lazy-fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive image utilities */
.lazy-responsive {
    max-width: 100%;
    height: auto;
}

/* Aspect ratio containers */
.lazy-aspect-16-9 {
    aspect-ratio: 16 / 9;
}

.lazy-aspect-4-3 {
    aspect-ratio: 4 / 3;
}

.lazy-aspect-1-1 {
    aspect-ratio: 1 / 1;
}

.lazy-aspect-3-2 {
    aspect-ratio: 3 / 2;
}

/* Background image specific styles */
.lazy-bg {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.lazy-bg-contain {
    background-size: contain;
}

.lazy-bg-center {
    background-position: center;
}

.lazy-bg-top {
    background-position: top;
}

.lazy-bg-bottom {
    background-position: bottom;
}

/* Placeholder patterns */
.lazy-placeholder-dots {
    background-image: radial-gradient(circle, #ddd 1px, transparent 1px);
    background-size: 20px 20px;
}

.lazy-placeholder-lines {
    background-image: linear-gradient(45deg, #ddd 25%, transparent 25%),
                      linear-gradient(-45deg, #ddd 25%, transparent 25%),
                      linear-gradient(45deg, transparent 75%, #ddd 75%),
                      linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

/* Performance optimizations */
.lazy-image {
    content-visibility: auto;
    contain-intrinsic-size: 200px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .lazy-loading {
        filter: none;
        opacity: 0.8;
    }
    
    .lazy-error {
        filter: none;
        border: 2px solid #dc3545;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .lazy-image,
    [data-lazy],
    .lazy-shimmer,
    .lazy-pulse,
    .lazy-fade-in {
        animation: none;
        transition: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .lazy-wrapper {
        background-color: #2d3748;
    }
    
    .lazy-shimmer {
        background: linear-gradient(
            90deg,
            transparent,
            rgba(255, 255, 255, 0.1),
            transparent
        );
    }
    
    .lazy-placeholder-dots {
        background-image: radial-gradient(circle, #4a5568 1px, transparent 1px);
    }
    
    .lazy-placeholder-lines {
        background-image: linear-gradient(45deg, #4a5568 25%, transparent 25%),
                          linear-gradient(-45deg, #4a5568 25%, transparent 25%),
                          linear-gradient(45deg, transparent 75%, #4a5568 75%),
                          linear-gradient(-45deg, transparent 75%, #4a5568 75%);
    }
}

/* Print styles */
@media print {
    .lazy-image,
    [data-lazy] {
        opacity: 1 !important;
        filter: none !important;
    }
    
    .lazy-shimmer {
        display: none !important;
    }
}

/* Focus styles for accessibility */
.lazy-image:focus,
[data-lazy]:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Loading spinner alternative */
.lazy-spinner {
    position: relative;
}

.lazy-spinner::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1;
}

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

/* Remove spinner when loaded */
.lazy-loaded.lazy-spinner::before {
    display: none;
}
