/* Advanced Image Loading Effects CSS */
/* Styles for progressive loading, blur-up effects, and loading states */

/* ========================================= */
/* PROGRESSIVE IMAGE LOADING STYLES */
/* ========================================= */

/* Base styles for progressive loading images */
.progressive-image {
    position: relative;
    overflow: hidden;
    background-color: transparent;
    display: block;
}

/* Low quality placeholder (blurred) */
.progressive-image .img-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(10px);
    transform: scale(1.1); /* Slightly larger to hide blur edges */
    transition: opacity 0.5s ease;
    z-index: 1;
}

/* Full quality image */
.progressive-image .img-full {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.5s ease;
    z-index: 2;
}

/* When full image is loaded */
.progressive-image.loaded .img-placeholder {
    opacity: 0;
}

.progressive-image.loaded .img-full {
    opacity: 1;
}

/* Pixelated loading effect alternative */
.progressive-image.pixelated .img-placeholder {
    filter: blur(0px);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    transform: scale(1.05);
}

/* Base styles for images with data-src (lazy loading) */
img[data-src] {
    background-color: transparent;
    background-image: none;
    animation: none;
}

/* Loading shimmer animation */
@keyframes loading-shimmer {
    0% {
        background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    }
    100% {
        background-position: 20px 20px, 20px 30px, 30px 10px, 10px 20px;
    }
}

/* Enhanced blur-up effect for progressive loading */
.blur-up {
    filter: blur(8px);
    transform: scale(1.02);
    transition: filter 0.6s ease, opacity 0.6s ease, transform 0.6s ease;
    will-change: filter, opacity, transform;
}

.blur-up.loaded {
    filter: blur(0px);
    transform: scale(1);
    opacity: 1;
}

/* ========================================= */
/* IMAGE LOADING STATES */
/* ========================================= */

/* Loading state */
.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-sweep 1.5s infinite;
    z-index: 1;
}

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

/* Loaded state with enhanced animation */
.image-loaded {
    animation: fade-in-scale 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fade-in-scale {
    from {
        opacity: 0;
        transform: scale(1.05);
        filter: blur(2px);
    }
    to {
        opacity: 1;
        transform: scale(1);
        filter: blur(0px);
    }
}

/* Enhanced blur-to-sharp transition for hero images */
.hero-image {
    transition: filter 0.8s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.8s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Gallery images with staggered loading effect */
.gallery-image {
    transition: filter 0.5s ease, 
                transform 0.5s ease,
                opacity 0.5s ease;
}

.gallery-image.loaded {
    animation: slide-in-fade 0.6s ease forwards;
}

@keyframes slide-in-fade {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
        filter: blur(3px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0px);
    }
}

/* Error state */
.image-error {
    background-color: #f8f8f8;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23ccc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpolyline points='21,15 16,10 5,21'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 48px 48px;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 14px;
}

/* ========================================= */
/* PRIORITY-BASED LOADING STYLES */
/* ========================================= */

/* High priority images (hero, logo) */
.priority-high {
    will-change: transform, opacity;
    transform: translateZ(0); /* Force hardware acceleration */
}

/* Medium priority images (menu, features) */
.priority-medium {
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Low priority images (gallery, background) */
.priority-low {
    transition: opacity 0.6s ease, transform 0.6s ease;
}

/* ========================================= */
/* PERFORMANCE OPTIMIZATIONS */
/* ========================================= */

/* GPU acceleration for smooth transitions */
.progressive-image,
.blur-up,
.hero-image,
.gallery-image {
    will-change: filter, opacity, transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .progressive-image,
    .blur-up,
    .hero-image,
    .gallery-image,
    .image-loaded {
        transition: opacity 0.2s ease;
        animation: none;
    }
    
    .progressive-image .img-placeholder {
        filter: none;
        transform: none;
    }
    
    .blur-up {
        filter: none;
        transform: none;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .progressive-image .img-placeholder {
        filter: blur(8px); /* Slightly less blur on mobile */
    }
    
    .blur-up {
        filter: blur(6px);
        transition-duration: 0.4s; /* Faster on mobile */
    }
    
    .hero-image,
    .gallery-image {
        transition-duration: 0.5s;
    }
}

/* Responsive image containers */
.responsive-image-container {
    position: relative;
    overflow: hidden;
    background-color: #f5f5f5;
}

.responsive-image-container img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
}

/* Aspect ratio containers for consistent loading */
.aspect-ratio-16-9 {
    aspect-ratio: 16 / 9;
}

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

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

/* ========================================= */
/* INTERSECTION OBSERVER LOADING STATES */
/* ========================================= */

/* Images entering viewport */
.entering-viewport {
    animation: slide-in-up 0.6s ease-out;
}

@keyframes slide-in-up {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Images in viewport */
.in-viewport {
    opacity: 1;
    transform: translateY(0);
}

/* Images leaving viewport */
.leaving-viewport {
    transition: opacity 0.3s ease;
}

/* ========================================= */
/* SPRITE OPTIMIZATION STYLES */
/* ========================================= */

/* Icon sprite containers */
.icon-sprite {
    display: inline-block;
    background-repeat: no-repeat;
    vertical-align: middle;
    transition: transform 0.2s ease;
}

.icon-sprite:hover {
    transform: scale(1.1);
}

/* Small icons */
.icon-small {
    width: 24px;
    height: 24px;
}

/* Medium icons */
.icon-medium {
    width: 32px;
    height: 32px;
}

/* Large icons */
.icon-large {
    width: 48px;
    height: 48px;
}

/* ========================================= */
/* PERFORMANCE OPTIMIZATION STYLES */
/* ========================================= */

/* Hardware acceleration for animated images */
.hw-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Optimized transforms */
.optimized-transform {
    will-change: transform;
    transform: translate3d(0, 0, 0);
}

/* Reduce paint operations */
.reduce-paint {
    contain: layout style paint;
}

/* ========================================= */
/* GALLERY SPECIFIC LOADING STYLES */
/* ========================================= */

/* Gallery grid loading */
.gallery-grid.loading .gallery-item {
    opacity: 0;
    transform: translateY(20px);
    animation: gallery-item-load 0.5s ease-out forwards;
}

.gallery-grid.loading .gallery-item:nth-child(1) { animation-delay: 0.1s; }
.gallery-grid.loading .gallery-item:nth-child(2) { animation-delay: 0.2s; }
.gallery-grid.loading .gallery-item:nth-child(3) { animation-delay: 0.3s; }
.gallery-grid.loading .gallery-item:nth-child(4) { animation-delay: 0.4s; }
.gallery-grid.loading .gallery-item:nth-child(5) { animation-delay: 0.5s; }
.gallery-grid.loading .gallery-item:nth-child(6) { animation-delay: 0.6s; }

@keyframes gallery-item-load {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Gallery image hover effects */
.gallery-item img {
    transition: transform 0.3s ease, filter 0.3s ease;
}

.gallery-item:hover img {
    transform: scale(1.05);
    filter: brightness(1.1);
}

/* ========================================= */
/* HERO IMAGE LOADING STYLES */
/* ========================================= */

/* Hero background loading */
.hero-bg-img.loading,
.hero-background.loading {
    background-color: #1a472a;
    background-image: linear-gradient(135deg, #1a472a 0%, #2d5a3d 100%);
    animation: hero-bg-pulse 2s ease-in-out infinite alternate;
}

@keyframes hero-bg-pulse {
    from {
        opacity: 0.8;
    }
    to {
        opacity: 1;
    }
}

.hero-bg-img.loaded,
.hero-background.loaded {
    animation: hero-bg-fade-in 1s ease-out;
}

@keyframes hero-bg-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ========================================= */
/* MENU IMAGE LOADING STYLES */
/* ========================================= */

/* Menu item image containers */
.menu-item-image {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background-color: #f8f8f8;
}

.menu-item-image.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(255, 255, 255, 0.5) 50%,
        transparent 70%
    );
    animation: menu-shimmer 1.5s infinite;
}

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

/* ========================================= */
/* MOBILE OPTIMIZATION STYLES */
/* ========================================= */

/* Mobile-specific loading optimizations */
@media (max-width: 768px) {
    /* Reduce animations on mobile for better performance */
    .reduce-motion img[data-src] {
        animation: none;
    }
    
    .reduce-motion .blur-up {
        transition: filter 0.2s ease, opacity 0.2s ease;
    }
    
    /* Simpler loading states for mobile */
    .mobile-simple-loading {
        background: #f5f5f5;
        transition: opacity 0.3s ease;
    }
    
    /* Optimize touch interactions */
    .touch-optimized {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* ========================================= */
/* ACCESSIBILITY LOADING STYLES */
/* ========================================= */

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
    img[data-src],
    .blur-up,
    .image-loading::before,
    .entering-viewport {
        animation: none;
        transition: opacity 0.2s ease;
    }
    
    .gallery-grid.loading .gallery-item {
        animation: none;
        opacity: 1;
        transform: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    img[data-src] {
        background-color: transparent;
        background-image: none;
    }
    
    .image-error {
        background-color: #fff;
        border: 2px solid #000;
        color: #000;
    }
}

/* ========================================= */
/* PRINT STYLES */
/* ========================================= */

@media print {
    /* Ensure images are visible in print */
    img[data-src] {
        background: none;
        animation: none;
    }
    
    .blur-up {
        filter: none;
    }
    
    .image-loading::before {
        display: none;
    }
}

/* ========================================= */
/* UTILITY CLASSES */
/* ========================================= */

/* Force immediate loading */
.load-immediately {
    animation: none !important;
    filter: none !important;
    opacity: 1 !important;
    transform: none !important;
}

/* Hide until loaded */
.hide-until-loaded {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.hide-until-loaded.loaded {
    opacity: 1;
}

/* Fade in when loaded */
.fade-in-loaded {
    opacity: 0;
    transition: opacity 0.5s ease;
}

.fade-in-loaded.loaded {
    opacity: 1;
}

/* Scale in when loaded */
.scale-in-loaded {
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.scale-in-loaded.loaded {
    opacity: 1;
    transform: scale(1);
}
