/* Loading States and Skeleton Screens */

/* Spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: #222;
    animation: spin 0.8s linear infinite;
}

.spinner-large {
    width: 40px;
    height: 40px;
    border-width: 4px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.loading-content {
    text-align: center;
}

.loading-content .spinner-large {
    margin-bottom: 16px;
}

.loading-text {
    font-size: 16px;
    color: #666;
    font-weight: 500;
}

/* Skeleton screens */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #f8f8f8 50%,
        #f0f0f0 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Skeleton article card */
.skeleton-article-card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

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

.skeleton-meta {
    height: 16px;
    width: 40%;
    margin-bottom: 16px;
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
}

.skeleton-text:last-child {
    width: 60%;
}

.skeleton-tags {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.skeleton-tag {
    height: 24px;
    width: 80px;
    border-radius: 12px;
}

.skeleton-button {
    height: 36px;
    width: 120px;
    margin-top: 12px;
    border-radius: 6px;
}

/* Progress bar */
.progress-bar {
    width: 100%;
    height: 4px;
    background: #f0f0f0;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    background: #222;
    transition: width 0.3s ease;
    border-radius: 2px;
}

.progress-bar-indeterminate {
    width: 30%;
    animation: progress-indeterminate 1.5s infinite ease-in-out;
}

@keyframes progress-indeterminate {
    0% {
        left: -30%;
    }
    100% {
        left: 100%;
    }
}

/* Loading dots */
.loading-dots {
    display: inline-flex;
    gap: 4px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: #666;
    border-radius: 50%;
    animation: loading-dots 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loading-dots {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Button loading state */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Dark mode */
body.dark-mode .loading-overlay {
    background: rgba(0, 0, 0, 0.9);
}

body.dark-mode .skeleton {
    background: linear-gradient(
        90deg,
        #2d3748 0%,
        #374151 50%,
        #2d3748 100%
    );
    background-size: 200% 100%;
}

body.dark-mode .skeleton-article-card {
    background: #1f2937;
}

body.dark-mode .progress-bar {
    background: #374151;
}

body.dark-mode .loading-text {
    color: #d1d5db;
}

/* Fade in animation for loaded content */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

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

/* Infinite Scroll Loading Indicator */
#infinite-scroll-loading {
    padding: 2rem 0;
    text-align: center;
}

#infinite-scroll-loading .spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.3em;
}

#infinite-scroll-sentinel {
    min-height: 20px;
    visibility: hidden;
}

/* Lazy loading image placeholder */
img[loading="lazy"] {
    background: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #f8f8f8 50%,
        #f0f0f0 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

body.dark-mode img[loading="lazy"] {
    background: linear-gradient(
        90deg,
        #2d3748 0%,
        #374151 50%,
        #2d3748 100%
    );
    background-size: 200% 100%;
}
