/* Performance and Lazy Loading Styles */

/* Lazy loading fade-in effect - Only apply to specifically marked elements */
.lazyload:not([src]) {
    opacity: 0;
}

.lazyload[src] {
    opacity: 1;
}

.lazyloaded {
    opacity: 1 !important;
    transition: opacity 300ms ease-in-out;
}

/* Ensure critical images are always visible */
.header img, 
.logo img, 
.cart-icon img,
.nav img,
#header img {
    opacity: 1 !important;
}

/* Placeholder for lazy loaded images */
.lazy-placeholder {
    background: linear-gradient(90deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(#f0f0f0 50%, transparent 50%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    animation: loading 1.5s infinite linear;
}

@keyframes loading {
    0% { background-position: 0 0, 10px 10px; }
    100% { background-position: 20px 20px, 30px 30px; }
}

/* Critical CSS for above-the-fold content */
.hero-section {
    min-height: 60vh;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Optimize button and form performance */
.btn {
    transition: all 0.15s ease-in-out;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .lazyloaded {
        transition: none;
    }
}

/* Performance optimizations for large lists */
.large-list {
    contain: layout style paint;
}

.large-list-item {
    contain: layout style;
}

/* Cookie banner performance optimization */
#cookieConsent {
    will-change: transform;
    contain: layout style paint;
}

/* Optimize animations */
.animate__animated {
    animation-fill-mode: both;
}

/* Reduce repaints for modals */
.modal {
    contain: layout style paint;
}

/* Optimize carousel performance */
.owl-carousel {
    will-change: transform;
}

/* Image optimization classes */
.img-optimized {
    max-width: 100%;
    height: auto;
    object-fit: cover;
}

.img-responsive {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Loading skeleton for better perceived performance */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
    border-radius: 4px;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.skeleton-image {
    width: 100%;
    height: 200px;
    border-radius: 8px;
}

/* CSS Loading State Management */
.css-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease-out;
}

.css-loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.css-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Prevent FOUC for specific elements */
.anti-fouc {
    visibility: hidden;
}

.css-loaded .anti-fouc {
    visibility: visible;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Fast loading states for critical UI elements */
.header-loading .navbar-brand {
    background: #f0f0f0;
    border-radius: 4px;
    width: 120px;
    height: 40px;
}

.header-loading .nav-link {
    background: #f0f0f0;
    border-radius: 4px;
    width: 80px;
    height: 20px;
    margin: 0 10px;
}