/* ============================================
   LOADING STATES & SKELETON SCREENS
   ============================================ */

/* Loading Spinners */
.spinner-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.spinner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    border-radius: inherit;
}

.spinner-overlay.dark {
    background-color: rgba(0, 0, 0, 0.6);
}

/* Using CSS variables for spinner colors */
.spinner-custom {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner-custom.small {
    width: 24px;
    height: 24px;
    border-width: 3px;
}

.spinner-custom.large {
    width: 60px;
    height: 60px;
    border-width: 6px;
}

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

/* Skeleton Screens - using CSS variables that automatically adapt to theme 
   Note: neutral colors are redefined in dark mode via base.css theme definitions,
   so skeleton appearance automatically adjusts for light/dark themes */
.skeleton {
    background: linear-gradient(90deg, 
        var(--color-neutral-200) 25%, 
        var(--color-neutral-300) 50%, 
        var(--color-neutral-200) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

/* Single animation works for all themes since colors adapt via CSS variables */
@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Skeleton Variants */
.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
    width: 100%;
}

.skeleton-text.title {
    height: 1.5rem;
    width: 70%;
    margin-bottom: 1rem;
}

.skeleton-text.subtitle {
    height: 1.25rem;
    width: 50%;
    margin-bottom: 0.75rem;
}

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

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

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

.skeleton-avatar.large {
    width: 60px;
    height: 60px;
}

.skeleton-button {
    height: 38px;
    width: 100px;
    border-radius: 6px;
}

.skeleton-card {
    height: 200px;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.skeleton-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: center;
}

.skeleton-row .skeleton-avatar {
    flex-shrink: 0;
}

.skeleton-row .skeleton-text {
    flex: 1;
}

.skeleton-table {
    width: 100%;
}

.skeleton-table-row {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color-light);
}

.skeleton-table-cell {
    flex: 1;
    height: 1rem;
}

.skeleton-metric {
    text-align: center;
    padding: 1.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
}

.skeleton-metric-value {
    height: 2rem;
    width: 80px;
    margin: 0 auto 0.5rem;
}

.skeleton-metric-label {
    height: 1rem;
    width: 120px;
    margin: 0 auto;
}

/* Loading States for Components */
.loading-state {
    position: relative;
    min-height: 100px;
}

.loading-state.loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Loading spinner - using CSS variables for theme consistency */
.loading-state.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 2;
}

/* Progress Loading - using CSS variables */
.progress-loading {
    height: 4px;
    background-color: var(--color-neutral-200);
    border-radius: 2px;
    overflow: hidden;
    margin: 1rem 0;
}

.progress-loading-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--primary-soft));
    background-size: 200% 100%;
    animation: progress-loading 2s ease-in-out infinite;
    border-radius: 2px;
}

@keyframes progress-loading {
    0% { 
        width: 0%;
        background-position: 200% 0;
    }
    50% { 
        width: 70%;
        background-position: -200% 0;
    }
    100% { 
        width: 100%;
        background-position: 200% 0;
    }
}

/* Pulse Loading */
.pulse-loading {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #007bff;
    animation: pulse 1.5s ease-in-out infinite;
}

.pulse-loading:nth-child(2) {
    animation-delay: 0.2s;
    margin-left: 4px;
}

.pulse-loading:nth-child(3) {
    animation-delay: 0.4s;
    margin-left: 4px;
}

@keyframes pulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    40% {
        opacity: 1;
        transform: scale(1.2);
    }
}

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

/* Loading dots - using CSS variable for theme consistency */
.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--primary-color);
    animation: loading-dots 1.5s ease-in-out infinite;
}

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

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

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

/* Dark Mode Support - skeleton styles defined above */

/* Dark mode skeleton borders - using CSS variables */
[data-theme-mode="dark"] .skeleton-table-row {
    border-bottom-color: var(--border-color);
}

[data-theme-mode="dark"] .skeleton-metric {
    border-color: var(--border-color);
}

[data-theme-mode="dark"] .spinner-overlay {
    background-color: rgba(0, 0, 0, 0.8);
}

/* Loading State Utilities */
.loading-hide {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.loading-show {
    opacity: 1;
    transition: opacity 0.3s ease;
}

.disabled-while-loading {
    pointer-events: none;
    opacity: 0.6;
}

/* Button Loading States */
.btn.loading {
    color: transparent;
    pointer-events: none;
    position: relative;
}

.btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.btn.btn-primary.loading::after {
    border-top-color: #fff;
}

.btn.btn-outline-primary.loading::after {
    border-top-color: #007bff;
}

/* Form Loading States */
.form-loading .form-control,
.form-loading .form-select {
    background-color: #f8f9fa;
    pointer-events: none;
}

.form-loading .form-control::placeholder {
    color: transparent;
}

/* Table Loading States */
.table-loading {
    position: relative;
}

.table-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 1;
}

/* Table loading spinner - using CSS variables for theme consistency */
.table-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 2;
}

/* Responsive Loading States */
@media (max-width: 768px) {
    .spinner-custom {
        width: 32px;
        height: 32px;
        border-width: 3px;
    }
    
    .spinner-custom.small {
        width: 20px;
        height: 20px;
        border-width: 2px;
    }
    
    .skeleton-button {
        height: 44px;
        width: 120px;
    }
    
    .skeleton-text {
        height: 0.875rem;
    }
    
    .skeleton-text.title {
        height: 1.25rem;
    }
}