/* =================================================
   Image Loading Optimization Styles
   Progressive loading with blur-up effect
   ================================================= */

/* Base image loading states */
img {
    transition: opacity 0.3s ease, filter 0.3s ease;
}

img.loading {
    opacity: 0.3;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

img.loaded {
    opacity: 1;
    filter: none;
}

img.error {
    opacity: 0.5;
    filter: grayscale(100%);
}

/* Blur-up effect for progressive image loading */
img.blur-up {
    filter: blur(10px);
    transform: scale(1.05);
}

img.blur-up-loaded {
    filter: blur(5px);
}

/* Shimmer animation for loading skeleton */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Image placeholder skeleton */
.image-placeholder {
    position: relative;
    overflow: hidden;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.image-placeholder::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 0.5;
        transform: translate(-50%, -50%) scale(1.2);
    }
}

/* Property gallery specific optimizations */
.property-hero-gallery .main-image {
    position: relative;
    background: #f5f5f5;
}

.property-hero-gallery .main-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.property-hero-gallery .main-image img.loading {
    min-height: 500px;
}

/* Thumbnail gallery optimization */
.thumbnail-gallery {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.thumbnail {
    flex-shrink: 0;
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    position: relative;
}

.thumbnail:hover {
    border-color: var(--primary-color, #C8A55B);
    transform: translateY(-2px);
}

.thumbnail.active {
    border-color: var(--primary-color, #C8A55B);
    box-shadow: 0 4px 12px rgba(200, 165, 91, 0.3);
}

.thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail img.loading {
    min-height: 100px;
}

/* Property card image optimization */
.property-card-image,
.property-image {
    position: relative;
    background: #f5f5f5;
    overflow: hidden;
}

.property-card-image img,
.property-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Loading spinner overlay */
.image-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(200, 165, 91, 0.2);
    border-top-color: var(--primary-color, #C8A55B);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 10;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Lazy load fade-in */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.4s ease-in;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Responsive image optimization */
@media (max-width: 768px) {
    .thumbnail {
        width: 80px;
        height: 80px;
    }
    
    .property-hero-gallery .main-image img.loading {
        min-height: 300px;
    }
}

/* Performance: Disable animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    img,
    .image-placeholder,
    .thumbnail {
        animation: none !important;
        transition: none !important;
    }
}

/* Image error state styling */
.image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    color: #999;
    font-size: 14px;
    text-align: center;
    padding: 20px;
}

.image-error::before {
    content: '🖼️';
    display: block;
    font-size: 40px;
    margin-bottom: 10px;
}

/* Progressive JPEG support */
img[data-progressive="true"] {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* WebP support detection fallback */
.no-webp img[data-webp] {
    content: url(attr(data-fallback));
}
