/* Advanced Image Optimization CSS */
/* Best practices for responsive images, lazy loading, and performance */

/* Base image container */
.optimized-image-container {
    position: relative;
    overflow: hidden;
    background: var(--gray-100, #f3f4f6);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

/* Main image styles */
.optimized-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: all 0.3s ease;
    will-change: transform, opacity;
    opacity: 1;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* Hover effects */
.optimized-image.hover-effect:hover {
    transform: scale(1.05);
}

.optimized-image.hover-effect:active {
    transform: scale(0.98);
}

/* Placeholder styles */
.image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, 
        var(--gray-200, #e5e7eb) 0%, 
        var(--gray-300, #d1d5db) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    animation: placeholder-pulse 2s ease-in-out infinite;
}

.image-placeholder.no-image {
    position: relative;
}

.placeholder-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--gray-500, #6b7280);
    text-align: center;
    padding: 1rem;
}

.placeholder-content i {
    font-size: 2rem;
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.placeholder-content:hover i {
    opacity: 1;
}

.placeholder-text {
    font-size: 0.75rem;
    font-weight: 500;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

/* Lazy loading images */
.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease;
    filter: blur(5px);
}

.lazy-image.loaded {
    opacity: 1;
    filter: blur(0);
}

/* Responsive image sizes */
.responsive-image {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Hero images */
.hero-image {
    width: 100%;
    height: auto;
    max-height: 80vh;
    object-fit: cover;
    object-position: center;
}

/* Thumbnail images */
.thumbnail-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: inherit;
}

/* Avatar images */
.avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: 50%;
    border: 2px solid var(--gray-200, #e5e7eb);
}

.avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Card images */
.card-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    object-position: center;
    border-radius: 8px 8px 0 0;
}

/* Gallery images */
.gallery-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.gallery-image:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* Background images */
.bg-image {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

.bg-image.parallax {
    background-attachment: fixed;
}

/* Image overlays */
.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        rgba(0, 0, 0, 0.3) 50%,
        rgba(0, 0, 0, 0.7) 100%
    );
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: flex-end;
    padding: 1rem;
    color: white;
}

.image-container:hover .image-overlay {
    opacity: 1;
}

/* Loading states */
.image-loading {
    position: relative;
    overflow: hidden;
}

.image-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    animation: loading-shimmer 1.5s infinite;
}

/* Skeleton loading */
.skeleton-image {
    background: linear-gradient(
        90deg,
        var(--gray-200, #e5e7eb) 25%,
        var(--gray-300, #d1d5db) 50%,
        var(--gray-200, #e5e7eb) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

/* Image grid */
.image-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.image-grid-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    aspect-ratio: 1;
}

/* Masonry layout */
.masonry-grid {
    columns: 4;
    column-gap: 1rem;
}

.masonry-item {
    break-inside: avoid;
    margin-bottom: 1rem;
    border-radius: 8px;
    overflow: hidden;
}

/* Responsive breakpoints */
@media (max-width: 1200px) {
    .masonry-grid {
        columns: 3;
    }
}

@media (max-width: 768px) {
    .masonry-grid {
        columns: 2;
    }
    
    .placeholder-content i {
        font-size: 1.5rem;
    }
    
    .placeholder-text {
        font-size: 0.625rem;
    }
    
    .bg-image.parallax {
        background-attachment: scroll;
    }
}

@media (max-width: 480px) {
    .masonry-grid {
        columns: 1;
    }
    
    .image-grid {
        grid-template-columns: 1fr;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .optimized-image {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Print styles */
@media print {
    .optimized-image {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .image-placeholder,
    .image-overlay {
        display: none !important;
    }
}

/* Focus styles for accessibility */
.optimized-image-container:focus-within {
    outline: 2px solid var(--primary, #4b5563);
    outline-offset: 2px;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .optimized-image,
    .optimized-image.hover-effect:hover,
    .gallery-image:hover {
        transition: none;
        transform: none;
    }
    
    .image-loading::before,
    .skeleton-image {
        animation: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .image-placeholder {
        background: linear-gradient(135deg, 
            var(--gray-700, #374151) 0%, 
            var(--gray-800, #1f2937) 100%);
        color: var(--gray-300, #d1d5db);
    }
    
    .placeholder-content {
        color: var(--gray-300, #d1d5db);
    }
}

/* Animations */
@keyframes placeholder-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

@keyframes loading-shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Performance optimizations */
.optimized-image-container {
    contain: layout style paint;
}

.optimized-image {
    contain: layout style paint;
}

/* CSS containment for better performance */
.image-grid,
.masonry-grid {
    contain: layout style;
}

/* Smooth scrolling for anchor links */
html {
    scroll-behavior: smooth;
}

/* Image aspect ratio utilities */
.aspect-square {
    aspect-ratio: 1;
}

.aspect-video {
    aspect-ratio: 16 / 9;
}

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

.aspect-banner {
    aspect-ratio: 21 / 9;
}

/* Image filter effects */
.image-filter-grayscale {
    filter: grayscale(100%);
    transition: filter 0.3s ease;
}

.image-filter-grayscale:hover {
    filter: grayscale(0%);
}

.image-filter-blur {
    filter: blur(2px);
    transition: filter 0.3s ease;
}

.image-filter-blur:hover {
    filter: blur(0);
}

.image-filter-brightness {
    filter: brightness(0.8);
    transition: filter 0.3s ease;
}

.image-filter-brightness:hover {
    filter: brightness(1.1);
}

/* Image zoom on hover */
.image-zoom-container {
    overflow: hidden;
    cursor: zoom-in;
}

.image-zoom-container img {
    transition: transform 0.3s ease;
}

.image-zoom-container:hover img {
    transform: scale(1.5);
}

/* Image comparison slider */
.image-comparison {
    position: relative;
    overflow: hidden;
}

.image-comparison .before,
.image-comparison .after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.image-comparison .after {
    clip-path: polygon(0 0, 50% 0, 50% 100%, 0 100%);
}

/* Image lazy loading with intersection observer fallback */
.lazy-image-fallback {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lazy-image-fallback.loaded {
    opacity: 1;
}

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

.progressive-image .low-quality {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    filter: blur(10px);
    transform: scale(1.1);
}

.progressive-image .high-quality {
    position: relative;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.progressive-image .high-quality.loaded {
    opacity: 1;
}

/* Image error handling */
.image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--red-50, #fef2f2);
    border: 1px solid var(--red-200, #fecaca);
    border-radius: 8px;
    color: var(--red-600, #dc2626);
    font-size: 0.875rem;
}

.image-error i {
    margin-right: 0.5rem;
    font-size: 1rem;
}
