/* ============================================================
   SISTEMA DE LOADING / CARGA
   Inventario TX
   ============================================================
   Overlays, spinners, skeleton loaders y estados de carga.
   ============================================================ */

/* ── OVERLAY DE CARGA (full page) ─────────────────────── */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(241, 245, 249, 0.85);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    display: grid;
    grid-size: 3;
    gap: 4px;
}

.loading-spinner::before,
.loading-spinner::after {
    content: '';
    background: var(--color-primary);
    border-radius: var(--radius-full);
    animation: spinner-girar 1.2s ease-in-out infinite;
}

.loading-spinner::after {
    background: var(--color-esmeralda);
    animation-delay: -0.6s;
}

/* Spinner de tres puntos */
.spinner-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}

.spinner-dots span {
    width: 10px;
    height: 10px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    animation: spinner-girar 1.2s ease-in-out infinite;
}

.spinner-dots span:nth-child(1) { animation-delay: -0.32s; }
.spinner-dots span:nth-child(2) { animation-delay: -0.16s; }
.spinner-dots span:nth-child(3) { animation-delay: 0s; }

.spinner-dots.spinner-esmeralda span { background: var(--color-esmeralda); }
.spinner-dots.spinner-rubi span { background: var(--color-rubi); }

/* Spinner circular con borde */
.spinner-circulo {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: var(--radius-full);
    animation: girar 0.8s linear infinite;
}

.spinner-circulo.spinner-sm {
    width: 24px;
    height: 24px;
    border-width: 2px;
}

.spinner-circulo.spinner-lg {
    width: 56px;
    height: 56px;
    border-width: 4px;
}

/* Spinner de linea */
.spinner-linea {
    width: 100%;
    height: 3px;
    background: var(--color-border);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
}

.spinner-linea::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 40%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    animation: spinner-linea 1.2s ease-in-out infinite;
}

.loading-text {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-muted);
    animation: pulso 1.5s ease-in-out infinite;
}

/* ── SKELETON LOADER ───────────────────────────────────────
   Placeholder de contenido mientras carga */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--color-bg) 25%,
        var(--color-border) 50%,
        var(--color-bg) 75%
    );
    background-size: 200% 100%;
    animation: skeleton 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
}

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

.skeleton-title {
    height: 1.5rem;
    width: 60%;
    margin-bottom: 0.75rem;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
}

.skeleton-button {
    height: 44px;
    width: 120px;
    border-radius: var(--radius-md);
}

.skeleton-card {
    height: 120px;
    border-radius: var(--radius-lg);
}

/* Skeleton para listas */
.skeleton-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.skeleton-list-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.skeleton-list-item .skeleton-avatar {
    flex-shrink: 0;
}

.skeleton-list-item .skeleton-content {
    flex: 1;
}

.skeleton-list-item .skeleton-content .skeleton-title {
    margin-bottom: 0.5rem;
}

.skeleton-list-item .skeleton-content .skeleton-text {
    width: 90%;
}

/* Skeleton para tablas */
.skeleton-table {
    width: 100%;
}

.skeleton-table th {
    padding: 0.75rem;
    text-align: left;
}

.skeleton-table td {
    padding: 0.75rem;
    vertical-align: middle;
}

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

.skeleton-table-row > * {
    flex: 1;
}

/* ── STEPS LOADER (indicador de pasos) ─────────────────── */
.steps-loader {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.step-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.step-item .step-dot {
    width: 10px;
    height: 10px;
    border-radius: var(--radius-full);
    background: var(--color-border);
    transition: all var(--transition-normal);
}

.step-item.active .step-dot {
    background: var(--color-primary);
    transform: scale(1.3);
    animation: pulso 1s ease-in-out infinite;
}

.step-item.completed .step-dot {
    background: var(--color-esmeralda);
}

.step-item.completed .step-dot::after {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    background: white;
    border-radius: var(--radius-full);
}

.step-connector {
    width: 40px;
    height: 2px;
    background: var(--color-border);
    transition: background var(--transition-normal);
}

.step-item.completed + .step-connector {
    background: var(--color-esmeralda);
}

/* ── PROGRESS BAR ──────────────────────────────────────── */
.progress-bar-wrapper {
    width: 100%;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.375rem;
    font-size: var(--font-size-xs);
    color: var(--color-muted);
}

.progress-bar {
    height: 8px;
    background: var(--color-bg);
    border-radius: var(--radius-full);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.progress-bar-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.progress-bar-fill.success {
    background: var(--gradient-confirmar);
}

.progress-bar-fill.warning {
    background: var(--gradient-warning);
}

.progress-bar-fill.danger {
    background: var(--gradient-cancelar);
}

/* Progress bar con porcentaje animado */
.progress-bar-fill::after {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.3) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

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

/* ── LAZY LOAD IMAGE ──────────────────────────────────── */
.lazy-image {
    background: var(--color-bg);
    position: relative;
    overflow: hidden;
}

.lazy-image::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        var(--color-bg) 25%,
        var(--color-border) 50%,
        var(--color-bg) 75%
    );
    background-size: 200% 100%;
    animation: skeleton 1.5s ease-in-out infinite;
}

.lazy-image.loaded::before {
    display: none;
}

.lazy-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

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

/* ── STAGGERED LIST LOADING ───────────────────────────────
   Para cargar items de lista con delay escalonado */
.stagger-load {
    opacity: 0;
    animation: escalar-entrada 0.4s ease forwards;
}

.stagger-load:nth-child(1) { animation-delay: 0.05s; }
.stagger-load:nth-child(2) { animation-delay: 0.10s; }
.stagger-load:nth-child(3) { animation-delay: 0.15s; }
.stagger-load:nth-child(4) { animation-delay: 0.20s; }
.stagger-load:nth-child(5) { animation-delay: 0.25s; }
.stagger-load:nth-child(6) { animation-delay: 0.30s; }
.stagger-load:nth-child(7) { animation-delay: 0.35s; }
.stagger-load:nth-child(8) { animation-delay: 0.40s; }
.stagger-load:nth-child(9) { animation-delay: 0.45s; }
.stagger-load:nth-child(10) { animation-delay: 0.50s; }

/* ── RESPONSIVE ────────────────────────────────────────── */
@media (max-width: 576px) {
    .loading-overlay {
        backdrop-filter: blur(2px);
    }

    .loading-spinner {
        width: 36px;
        height: 36px;
    }
}