/* ========================================
   LAZY LOADING & PERFORMANCE CSS
   ======================================== */

/* Image Lazy Loading - Fade In Effect */
img[data-src], img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    background: #f0f0f0;
}

img.lazy-loaded {
    opacity: 1;
}

/* Blur-up effect (optional) */
img.blur-up {
    filter: blur(10px);
    transition: filter 0.3s ease-in-out, opacity 0.3s ease-in-out;
}

img.lazy-loaded.blur-up {
    filter: blur(0);
}

/* ========================================
   SKELETON LOADERS (Facebook-style)
   ======================================== */

@keyframes skeleton-loading {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.skeleton-loading {
    background: linear-gradient(90deg, #f0f0f0 0px, #e0e0e0 40px, #f0f0f0 80px);
    background-size: 200px 100%;
    animation: skeleton-loading 1.4s ease-in-out infinite;
}

.loading-skeleton {
    padding: 20px 0;
}

.skeleton-card {
    background: #fff;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.skeleton-image {
    width: 100%;
    height: 200px;
    background: linear-gradient(90deg, #f0f0f0 0px, #e0e0e0 40px, #f0f0f0 80px);
    background-size: 200px 100%;
    animation: skeleton-loading 1.4s ease-in-out infinite;
    border-radius: 4px;
    margin-bottom: 12px;
}

.skeleton-text {
    width: 100%;
    height: 16px;
    background: linear-gradient(90deg, #f0f0f0 0px, #e0e0e0 40px, #f0f0f0 80px);
    background-size: 200px 100%;
    animation: skeleton-loading 1.4s ease-in-out infinite;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-text.title {
    height: 24px;
    width: 80%;
    margin-bottom: 12px;
}

/* ========================================
   SECTION LAZY LOADING
   ======================================== */

.lazy-section {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.lazy-section.section-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================
   FADE-IN ANIMATION
   ======================================== */

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

.fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Stagger animation for multiple items */
.post-card:nth-child(1) { animation-delay: 0s; }
.post-card:nth-child(2) { animation-delay: 0.1s; }
.post-card:nth-child(3) { animation-delay: 0.2s; }
.post-card:nth-child(4) { animation-delay: 0.3s; }
.post-card:nth-child(5) { animation-delay: 0.4s; }

/* ========================================
   INFINITE SCROLL INDICATOR
   ======================================== */

.scroll-sentinel {
    height: 10px;
    width: 100%;
    visibility: hidden;
}

.loading-more {
    text-align: center;
    padding: 30px;
}

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

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

/* ========================================
   POST CARD (for infinite scroll)
   ======================================== */

.post-card {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.post-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.post-card .post-image {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    overflow: hidden;
    background: #f0f0f0;
}

.post-card .post-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.post-card .post-content {
    padding: 15px;
}

.post-card h3 {
    margin: 0 0 10px 0;
    font-size: 18px;
    line-height: 1.4;
}

.post-card h3 a {
    color: #333;
    text-decoration: none;
    transition: color 0.2s ease;
}

.post-card h3 a:hover {
    color: #2980b9;
}

.post-card p {
    color: #666;
    font-size: 14px;
    line-height: 1.6;
    margin: 0;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .skeleton-card {
        padding: 10px;
    }
    
    .skeleton-image {
        height: 150px;
    }
    
    .post-card .post-content {
        padding: 12px;
    }
}

/* ========================================
   PERFORMANCE HINTS
   ======================================== */

/* Will-change for smoother animations */
.lazy-section,
.post-card {
    will-change: transform, opacity;
}

/* Contain layout for better performance */
.post-card {
    contain: layout;
}

/* ========================================
   LOADING STATE
   ======================================== */

.is-loading {
    pointer-events: none;
    opacity: 0.6;
    position: relative;
}

.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ========================================
   CACHE INDICATOR (Optional - for debugging)
   ======================================== */

.from-cache {
    position: relative;
}

.from-cache::before {
    content: '📦';
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 20px;
    opacity: 0.7;
    z-index: 10;
}

/* ========================================
   PROGRESSIVE SECTION LAZY LOADING
   ======================================== */

/* Section placeholder with skeleton */
.lazy-section-placeholder {
    min-height: 200px;
    margin: 20px 0;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.lazy-section-placeholder.loading {
    opacity: 0.6;
}

/* Skeleton loader for sections */
.lazy-section-placeholder .skeleton-loader {
    padding: 20px;
    background: #fff;
    border-radius: 8px;
}

.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.skeleton-grid::before,
.skeleton-grid::after {
    content: '';
    display: block;
    height: 150px;
    background: linear-gradient(90deg, #f0f0f0 0px, #e0e0e0 40px, #f0f0f0 80px);
    background-size: 200px 100%;
    animation: skeleton-loading 1.4s ease-in-out infinite;
    border-radius: 4px;
}

/* Loaded section animation */
.lazy-section-loaded {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.lazy-section-loaded.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Error state */
.section-load-error {
    padding: 40px;
    text-align: center;
    color: #999;
    background: #f8f8f8;
    border-radius: 8px;
    font-size: 14px;
}

/* Advertisement placeholders (no skeleton needed) */
.lazy-section-placeholder[data-section^="advertisement"] {
    min-height: 0;
    margin: 10px 0;
}

/* Performance optimization for section loading */
#lazy-sections-container {
    contain: layout style;
}

/* Responsive skeleton for mobile */
@media (max-width: 768px) {
    .lazy-section-placeholder {
        min-height: 150px;
        margin: 15px 0;
    }
    
    .skeleton-grid {
        grid-template-columns: 1fr;
    }
}

