/* ==========================================
   LOADING STATES SYSTEM - Factulite
   Sistema modular para estados de carga
   ========================================== */

/* ==========================================
   1. SPINNERS
   ========================================== */

/* Spinner genérico */
.loading-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

.loading-spinner-sm {
    width: 0.875rem;
    height: 0.875rem;
    border-width: 1.5px;
}

.loading-spinner-lg {
    width: 2rem;
    height: 2rem;
    border-width: 3px;
}

/* ==========================================
   2. BOTONES CON LOADING
   ========================================== */

/* Botón en estado loading */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.65;
}

.btn-loading .btn-text {
    visibility: hidden;
}

.btn-loading .btn-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ==========================================
   3. FORMULARIOS CON LOADING
   ========================================== */

/* Overlay para formularios completos */
.form-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: inherit;
}

.form-loading-overlay .spinner-border {
    width: 3rem;
    height: 3rem;
}

.form-loading-overlay .loading-message {
    margin-top: 1rem;
    font-weight: 600;
    color: var(--color-primary, #003459);
}

/* ==========================================
   4. SECCIONES Y CARDS CON LOADING
   ========================================== */

/* Loading en cards/sections */
.section-loading {
    position: relative;
    min-height: 100px;
}

.section-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(2px);
    z-index: 10;
}

.section-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--color-primary, #003459);
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
    z-index: 11;
}

/* ==========================================
   5. SKELETON LOADERS
   ========================================== */

/* Skeleton loaders para listas */
.skeleton {
    animation: skeleton-loading 1s linear infinite alternate;
}

@keyframes skeleton-loading {
    0% {
        background-color: hsl(200, 20%, 80%);
    }
    100% {
        background-color: hsl(200, 20%, 95%);
    }
}

.skeleton-text {
    width: 100%;
    height: 0.7rem;
    margin-bottom: 0.5rem;
    border-radius: 0.25rem;
}

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

.skeleton-title {
    width: 40%;
    height: 1.5rem;
    margin-bottom: 1rem;
    border-radius: 0.25rem;
}

.skeleton-avatar {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
}

/* ==========================================
   6. TABLAS CON LOADING
   ========================================== */

/* Loading en tablas */
.table-loading {
    position: relative;
}

.table-loading tbody {
    opacity: 0.5;
    pointer-events: none;
}

.table-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--color-primary, #003459);
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
    z-index: 10;
}

/* ==========================================
   7. CURSORES Y ESTADOS GLOBALES
   ========================================== */

/* Cursor de espera global */
.cursor-wait,
.cursor-wait * {
    cursor: wait !important;
}

/* Deshabilitado con feedback visual */
.loading-disabled {
    opacity: 0.6;
    pointer-events: none;
    user-select: none;
}

/* ==========================================
   8. TOASTS Y NOTIFICACIONES
   ========================================== */

/* Estilos para toasts de loading */
.loading-toast {
    min-width: 250px;
}

.loading-toast .toast-body {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ==========================================
   9. ANIMACIONES
   ========================================== */

/* Fade in para overlays */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.form-loading-overlay {
    animation: fadeIn 0.2s ease-in;
}

/* Pulse para indicadores de loading */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.loading-pulse {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ==========================================
   10. UTILIDADES
   ========================================== */

/* Ocultar elementos durante loading */
.hide-on-loading {
    transition: opacity 0.2s;
}

.hide-on-loading.loading {
    opacity: 0;
    pointer-events: none;
}

/* Texto de loading */
.loading-text {
    color: var(--color-primary, #003459);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Dot animation para "Loading..." */
.loading-dots::after {
    content: '';
    animation: loading-dots 1.5s infinite;
}

@keyframes loading-dots {
    0%, 20% {
        content: '.';
    }
    40% {
        content: '..';
    }
    60%, 100% {
        content: '...';
    }
}

/* ==========================================
   11. RESPONSIVE
   ========================================== */

@media (max-width: 576px) {
    .form-loading-overlay .spinner-border {
        width: 2rem;
        height: 2rem;
    }
    
    .form-loading-overlay .loading-message {
        font-size: 0.875rem;
    }
}

/* ==========================================
   12. DARK MODE SUPPORT (opcional)
   ========================================== */

@media (prefers-color-scheme: dark) {
    .form-loading-overlay {
        background: rgba(0, 0, 0, 0.8);
    }
    
    .section-loading::after {
        background: rgba(0, 0, 0, 0.8);
    }
    
    .skeleton {
        animation: skeleton-loading-dark 1s linear infinite alternate;
    }
    
    @keyframes skeleton-loading-dark {
        0% {
            background-color: hsl(200, 20%, 20%);
        }
        100% {
            background-color: hsl(200, 20%, 30%);
        }
    }
}
