@keyframes skeleton-loading {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.skeleton {
    background: linear-gradient(90deg,
            #f0f0f0 0%,
            #e0e0e0 20%,
            #f0f0f0 40%,
            #f0f0f0 100%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.skeleton.dark {
    background: linear-gradient(90deg,
            #2a2a2a 0%,
            #3a3a3a 20%,
            #2a2a2a 40%,
            #2a2a2a 100%);
}

.skeleton::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, 0.3),
            transparent);
    animation: skeleton-loading 2s ease-in-out infinite;
}

.lazy-image-container {
    position: relative;
    overflow: hidden;
    background-color: #f5f5f5;
    display: inline-block;
    width: 100%;
}

.lazy-image-container.loading {
    background: linear-gradient(90deg,
            #f0f0f0 0%,
            #e0e0e0 20%,
            #f0f0f0 40%,
            #f0f0f0 100%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

.lazy-image {
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
}

.lazy-image.loaded {
    opacity: 1;
}

.lazy-image.error {
    opacity: 0.5;
}

.lazy-image.blur-up {
    filter: blur(10px);
    transition: filter 0.5s ease-in-out, opacity 0.5s ease-in-out;
}

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

.skeleton-card {
    background-color: #fff;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

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

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

.skeleton-text.medium {
    width: 80%;
}

.skeleton-text.long {
    width: 100%;
}

/* Product Card Skeleton */
.skeleton-product-card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.skeleton-product-card .skeleton-image {
    height: 250px;
    border-radius: 0;
    margin-bottom: 0;
}

.skeleton-product-card .skeleton-content {
    padding: 16px;
}

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

.skeleton-product-card .skeleton-price {
    height: 24px;
    width: 40%;
    background: linear-gradient(90deg,
            #f0f0f0 0%,
            #e0e0e0 20%,
            #f0f0f0 40%,
            #f0f0f0 100%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

/* Loading Spinner Overlay */
.lazy-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    z-index: 1;
    transition: opacity 0.3s ease-in-out;
}

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

/* Spinner */
.lazy-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);
    }
}

/* Fade-in animation for loaded images */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.lazy-image.fade-in {
    animation: fadeIn 0.6s ease-out;
}

/* Responsive Skeleton Sizes */
@media (max-width: 768px) {
    .skeleton-image {
        height: 150px;
    }

    .skeleton-product-card .skeleton-image {
        height: 180px;
    }
}

/* Grid Skeleton Layout */
.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    padding: 20px;
}

@media (max-width: 768px) {
    .skeleton-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
        padding: 12px;
    }
}

/* Lazy Background Image */
.lazy-bg {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
}

.lazy-bg::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg,
            #f0f0f0 0%,
            #e0e0e0 20%,
            #f0f0f0 40%,
            #f0f0f0 100%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    transition: opacity 0.5s ease-in-out;
}

.lazy-bg.loaded::before {
    opacity: 0;
}

/* Performance optimization */
.lazy-image-container,
.lazy-image,
.skeleton {
    will-change: opacity;
}

/* Accessibility */
.lazy-image[aria-busy="true"] {
    cursor: wait;
}

/* Error state */
.lazy-image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5;
    color: #999;
    font-size: 14px;
    min-height: 150px;
}

.lazy-image-error::before {
    content: '⚠️ Không thể tải ảnh';
}