/**
 * עיצוב טעינה עצלה
 */

/* תמונות בטעינה עצלה */
img.lazy-load {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    background: #f0f0f0;
}

/* תמונה בטעינה */
img.lazy-loading {
    opacity: 0.5;
    filter: blur(5px);
    transition: opacity 0.3s, filter 0.3s;
}

/* תמונה שנטענה */
img.lazy-loaded {
    opacity: 1 !important;
    filter: none !important;
}

/* תמונה עם שגיאה */
img.lazy-error {
    opacity: 1;
    position: relative;
    background: #f9f9f9;
    border: 1px solid #e5e5e5;
}

img.lazy-error::before {
    content: '⚠';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: #dc3232;
}

/* Placeholder animation */
@keyframes shimmer {
    0% {
        background-position: -468px 0;
    }
    100% {
        background-position: 468px 0;
    }
}

img.lazy-load:not([src]),
img.lazy-load[src^="data:"] {
    background: linear-gradient(
        to right,
        #f0f0f0 8%,
        #f8f8f8 18%,
        #f0f0f0 33%
    );
    background-size: 800px 100px;
    animation: shimmer 1.5s linear infinite;
}

/* שמירת יחס גובה-רוחב */
img.lazy-load[data-aspect-ratio] {
    width: 100%;
    height: auto;
}

/* מיכל תמונה עם טעינה עצלה */
.lazy-load-container {
    position: relative;
    overflow: hidden;
    background: #f0f0f0;
}

.lazy-load-container::before {
    content: '';
    display: block;
    padding-top: var(--aspect-ratio, 56.25%); /* Default 16:9 */
}

.lazy-load-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* אינדיקטור טעינה */
.lazy-load-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    display: none;
}

img.lazy-loading ~ .lazy-load-spinner {
    display: block;
}

.lazy-load-spinner::after {
    content: '';
    display: block;
    width: 30px;
    height: 30px;
    margin: 5px;
    border-radius: 50%;
    border: 3px solid #f3f3f3;
    border-top-color: #0073aa;
    animation: spin 1s linear infinite;
}

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

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

.progressive-image img {
    display: block;
    width: 100%;
    height: auto;
}

.progressive-image img.lazy-load {
    filter: blur(20px);
    transform: scale(1.1);
}

.progressive-image img.lazy-loaded {
    filter: blur(0);
    transform: scale(1);
    transition: filter 0.5s, transform 0.5s;
}

/* תמיכה בתמונות רספונסיביות */
picture img.lazy-load {
    width: 100%;
    height: auto;
}

/* Native lazy loading fallback */
img[loading="lazy"] {
    background: #f0f0f0;
}

/* Accessibility */
img.lazy-load[alt=""]:not(.lazy-loaded) {
    min-height: 1px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    img.lazy-load:not([src]),
    img.lazy-load[src^="data:"] {
        background: linear-gradient(
            to right,
            #2a2a2a 8%,
            #3a3a3a 18%,
            #2a2a2a 33%
        );
    }
    
    .lazy-load-container {
        background: #2a2a2a;
    }
    
    img.lazy-error {
        background: #2a2a2a;
        border-color: #3a3a3a;
    }
}

/* Print styles */
@media print {
    img.lazy-load {
        opacity: 1 !important;
        filter: none !important;
    }
    
    .lazy-load-spinner {
        display: none !important;
    }
}
