/* Instagram-style Lazy Loading CSS */

/* Placeholder styles */
img.lazy-placeholder {
    background: linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
                linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    animation: shimmer 1.5s infinite ease-in-out;
    transition: filter 0.3s ease, opacity 0.3s ease;
}

/* Shimmer effect while loading */
@keyframes shimmer {
    0% {
        background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    }
    50% {
        background-position: 10px 0, 10px 10px, 20px -10px, 0px 0px;
    }
    100% {
        background-position: 20px 0, 20px 10px, 30px -10px, 10px 0px;
    }
}

/* Loaded state */
img.lazy-loaded {
    background: none;
    animation: none;
}

/* Error state */
img.lazy-error {
    background: #ffebee;
    color: #d32f2f;
}

/* Progressive loading effects */
img[style*="blur"] {
    will-change: filter;
}

/* Smooth transitions for carousel images */
.carousel-img.lazy-placeholder {
    background-color: #f5f5f5;
}

.carousel-img.lazy-loaded {
    transition: opacity 0.3s ease;
}

/* Profile image placeholder */
.post-image img.lazy-placeholder {
    border-radius: 50%;
    background: radial-gradient(circle, #e0e0e0 30%, #f5f5f5 70%);
}

/* Video container improvements */
.video-container {
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}

.post-video {
    background: #000;
    object-fit: cover;
    transition: opacity 0.3s ease;
}

/* Instagram-style Infinite Scroll Indicators */

/* Loading indicator */
.infinite-scroll-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    margin: 20px 0;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

.loading-spinner {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #00c4b4;
    font-weight: 500;
}

.loading-spinner i {
    font-size: 18px;
    color: #00c4b4;
}

/* End of content message */
.infinite-scroll-end {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 30px 20px;
    margin: 20px 0;
    text-align: center;
}

.end-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #666;
    font-weight: 500;
}

.end-message i {
    font-size: 24px;
    color: #00c4b4;
}

/* Error message */
.infinite-scroll-error {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    margin: 20px 0;
    background: #ffebee;
    border-radius: 12px;
    border-left: 4px solid #f44336;
}

.error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    color: #d32f2f;
    text-align: center;
}

.error-message i {
    font-size: 20px;
    color: #f44336;
}

.retry-btn {
    background: #f44336;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.3s ease;
}

.retry-btn:hover {
    background: #d32f2f;
}

/* Loading states for different connection speeds */
@media (max-width: 768px) {
    /* Mobile optimizations */
    img.lazy-placeholder {
        background-size: 15px 15px;
        animation-duration: 2s;
    }
    
    .infinite-scroll-loading,
    .infinite-scroll-end,
    .infinite-scroll-error {
        margin: 15px 10px;
        padding: 15px;
        border-radius: 8px;
    }
    
    .loading-spinner,
    .end-message,
    .error-message {
        font-size: 14px;
    }
}

/* High DPI displays */
@media (min-resolution: 2dppx) {
    img.lazy-placeholder {
        background-size: 10px 10px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    img.lazy-placeholder {
        background: linear-gradient(45deg, #2a2a2a 25%, transparent 25%), 
                    linear-gradient(-45deg, #2a2a2a 25%, transparent 25%), 
                    linear-gradient(45deg, transparent 75%, #2a2a2a 75%), 
                    linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
    }
    
    .post-image img.lazy-placeholder {
        background: radial-gradient(circle, #404040 30%, #2a2a2a 70%);
    }
    
    .infinite-scroll-loading {
        background: rgba(42, 42, 42, 0.9);
        color: #fff;
    }
    
    .end-message {
        color: #ccc;
    }
    
    .infinite-scroll-error {
        background: rgba(244, 67, 54, 0.1);
        border-left-color: #f44336;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    img.lazy-placeholder {
        animation: none;
        background: #f0f0f0;
    }
    
    img[style*="blur"] {
        transition: none;
    }
    
    .loading-spinner i {
        animation: none;
    }
}

/* Instagram-style smooth animations */
.infinite-scroll-loading,
.infinite-scroll-end,
.infinite-scroll-error {
    animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================ */
/* Instagram-style Background Prefetching */
/* ============================================ */

/* Background Prefetch Indicators */
.prefetch-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 196, 180, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    z-index: 1000;
    display: none;
    align-items: center;
    gap: 6px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideInFromRight 0.3s ease-out;
}

.prefetch-indicator.active {
    display: flex;
}

.prefetch-indicator i {
    animation: pulse 1.5s ease-in-out infinite;
}

.prefetch-stats {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 11px;
    z-index: 999;
    display: none;
    backdrop-filter: blur(10px);
    max-width: 200px;
}

.prefetch-stats.show {
    display: block;
    animation: fadeInUp 0.3s ease-out;
}

.prefetch-stats .stat-line {
    margin: 2px 0;
    display: flex;
    justify-content: space-between;
}

.prefetch-stats .stat-line .label {
    opacity: 0.8;
}

.prefetch-stats .stat-line .value {
    font-weight: bold;
    color: #00c4b4;
}

/* Animations for Background Prefetching */
@keyframes slideInFromRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Instagram-style smooth content appearance */
.business-card.prefetched {
    animation: fadeInUpSmooth 0.4s ease-out;
}

@keyframes fadeInUpSmooth {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Performance optimizations for background prefetch */
.prefetch-hidden {
    position: absolute;
    left: -9999px;
    top: -9999px;
    visibility: hidden;
    pointer-events: none;
}

/* Dark mode adjustments for prefetch indicators */
.dark-mode .prefetch-indicator {
    background: rgba(0, 196, 180, 0.8);
}

.dark-mode .prefetch-stats {
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Mobile optimizations for prefetch indicators */
@media (max-width: 768px) {
    .prefetch-indicator {
        top: 10px;
        right: 10px;
        padding: 6px 10px;
        font-size: 11px;
    }
    
    .prefetch-stats {
        bottom: 70px;
        right: 10px;
        padding: 8px 12px;
        font-size: 10px;
        max-width: 180px;
    }
}

/* Reduced motion support for prefetch animations */
@media (prefers-reduced-motion: reduce) {
    .prefetch-indicator {
        animation: none;
    }
    
    .prefetch-indicator i {
        animation: none;
    }
    
    .business-card.prefetched {
        animation: none;
    }
}
