/* ═══════════════════════════════════════════════════════════════ */
/* 🧠 KNOWLEDGE PANEL — Fases 3 & 4                               */
/* ═══════════════════════════════════════════════════════════════ */
/*  Fase 3 (Desktop): Panel dockado a la derecha, glassmórfico.   */
/*  Fase 4 (Mobile):  Bottom Sheet ergonómico con swipe-to-close. */
/*  Fuentes: Outfit (títulos), Inter (cuerpo)                      */
/*  Iconos: SVG lineales únicamente. PROHIBIDO uso de emojis.      */
/* ═══════════════════════════════════════════════════════════════ */

/* ─── VARIABLES DEL PANEL ─────────────────────────────────────── */
:root {
    --kp-width: 360px;
    --kp-accent: #4263eb;           /* Sobreescrito dinámicamente por JS */
    --kp-accent-alpha: #4263eb22;   /* Sobreescrito dinámicamente */
    --kp-bg: rgba(255, 255, 255, 0.82);
    --kp-border: rgba(255, 255, 255, 0.6);
    --kp-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    --kp-text: #1a1a2e;
    --kp-text-secondary: #4a5568;
    --kp-text-muted: #718096;
    --kp-section-label: #a0aec0;
    --kp-insight-bg: rgba(255, 248, 220, 0.65);
    --kp-insight-border: rgba(245, 158, 11, 0.25);
    --kp-notes-bg: rgba(248, 249, 255, 0.8);
    --kp-notes-border: rgba(66, 99, 235, 0.2);
    --kp-radius: 16px;
    --kp-transition: 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
    --kp-transition-close: 0.22s ease-in;
}

/* 🧬 CARGA PROGRESIVA & ENRIQUECIMIENTO */
.kp-loading-text {
    font-style: italic;
    color: var(--kp-text-muted);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    margin-top: 5px;
}

.kp-shimmer {
    display: inline-block;
    animation: kp-pulse 1.5s infinite ease-in-out;
}

@keyframes kp-pulse {
    0% { opacity: 0.3; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.15); }
    100% { opacity: 0.3; transform: scale(0.9); }
}

/* ═══════════════════════════════════════════════════════════════ */
/* FASE 3 — PANEL DESKTOP                                         */
/* ═══════════════════════════════════════════════════════════════ */

.knowledge-panel {
    position: fixed;
    top: 70px;                  /* Debajo de la toolbar */
    right: 0;
    bottom: 0;
    width: var(--kp-width);
    max-width: 92vw;
    z-index: 900;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Glassmorphism */
    background: var(--kp-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-left: 1px solid var(--kp-border);
    box-shadow: var(--kp-shadow);

    /* Borde izquierdo con acento de color dinámico */
    border-top-left-radius: var(--kp-radius);
    border-bottom-left-radius: var(--kp-radius);
}

/* Estado ABIERTO */
.knowledge-panel--open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
    animation: kpSlideIn var(--kp-transition) forwards;
}

/* Estado CERRADO */
.knowledge-panel--closed {
    transform: translateX(calc(var(--kp-width) + 20px));
    opacity: 0;
    pointer-events: none;
    animation: kpSlideOut var(--kp-transition-close) forwards;
}

@keyframes kpSlideIn {
    from {
        transform: translateX(calc(var(--kp-width) + 20px));
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes kpSlideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(calc(var(--kp-width) + 20px));
        opacity: 0;
    }
}

/* ─── CANVAS FOCUS MODE ────────────────────────────────────────── */
/* Cuando el panel está abierto, el canvas se atenúa levemente */
.canvas-focus-mode {
    transition: opacity 0.3s ease;
    opacity: 0.88;
}

/* ─── HEADER ───────────────────────────────────────────────────── */
.knowledge-panel__header {
    flex-shrink: 0;
    padding: 16px 18px 14px;
    background: linear-gradient(135deg, var(--kp-accent-alpha), transparent 70%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.4);

    /* Barra de acento dinámica en el tope */
    position: relative;
}

.knowledge-panel__header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--kp-accent);
    border-radius: var(--kp-radius) var(--kp-radius) 0 0;
    opacity: 0.9;
}

.knowledge-panel__title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.knowledge-panel__icon {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--kp-accent-alpha);
    border: 1px solid var(--kp-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--kp-accent);
}

.knowledge-panel__node-title {
    flex: 1;
    min-width: 0;
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--kp-text);
    margin: 0;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.knowledge-panel__close-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.6);
    color: var(--kp-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s ease;
    padding: 0;
}

.knowledge-panel__close-btn:hover {
    background: rgba(220, 53, 69, 0.1);
    border-color: rgba(220, 53, 69, 0.3);
    color: #dc3545;
    transform: scale(1.08);
}

/* ─── CUERPO DESPLAZABLE ───────────────────────────────────────── */
.knowledge-panel__body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 18px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;

    /* Scrollbar premium */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
}

.knowledge-panel__body::-webkit-scrollbar {
    width: 4px;
}

.knowledge-panel__body::-webkit-scrollbar-track {
    background: transparent;
}

.knowledge-panel__body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 100px;
}

/* ─── SECCIONES ────────────────────────────────────────────────── */
.knowledge-panel__section {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.knowledge-panel__section-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--kp-section-label);
}

.knowledge-panel__desc {
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    line-height: 1.65;
    color: var(--kp-text-secondary);
    margin: 0;
    hyphens: auto;
}

.knowledge-panel__desc.is-empty-placeholder {
    color: var(--kp-text-muted, #888);
    font-style: italic;
    font-size: 0.82rem;
    opacity: 0.8;
}

/* ─── BLOQUE DE INSIGHT (Flashcard) ───────────────────────────── */
.knowledge-panel__insight-block {
    background: var(--kp-insight-bg);
    border: 1px solid var(--kp-insight-border);
    border-left: 3px solid rgba(245, 158, 11, 0.7);
    border-radius: 10px;
    padding: 10px 13px;
}

.knowledge-panel__insight {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    line-height: 1.6;
    color: #92400e;
    margin: 0;
    font-style: italic;
}

/* ─── SECTION HEADER (Label + Botón editar/descartar) ──────────── */
.knowledge-panel__section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.knowledge-panel__section-header .knowledge-panel__section-label {
    margin-bottom: 0;
}

/* Acciones en el header (Historial + Editar) */
.knowledge-panel__section-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Controles de Historial (Undo/Redo) */
.kp-history-controls {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 7px;
    padding: 2px;
}

.kp-history-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--kp-text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.kp-history-btn:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.05);
    color: var(--kp-text);
}

.kp-history-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Botón lápiz (Editar) */
.kp-edit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.04);
    color: var(--kp-text-muted);
    cursor: pointer;
    transition: all 0.18s ease;
    flex-shrink: 0;
}

.kp-edit-btn:hover {
    background: rgba(66, 99, 235, 0.1);
    color: var(--kp-accent, #4263eb);
    transform: scale(1.1);
}

.kp-edit-btn:active {
    transform: scale(0.95);
}

/* Botón descartar (X del insight) */
.kp-dismiss-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--kp-text-muted);
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.18s ease;
    flex-shrink: 0;
}

.kp-dismiss-btn:hover {
    opacity: 1;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* ─── TEXTAREA EDITABLE (Desc) ─────────────────────────────────── */
.knowledge-panel__editable-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px 12px;
    border: 1px solid var(--kp-accent, #4263eb);
    border-radius: 10px;
    background: var(--kp-notes-bg);
    font-family: 'Inter', sans-serif;
    font-size: 0.855rem;
    line-height: 1.6;
    color: var(--kp-text);
    resize: vertical;
    box-sizing: border-box;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
    outline: none;
    box-shadow: 0 0 0 3px var(--kp-accent-alpha, rgba(66, 99, 235, 0.1));
}

.knowledge-panel__editable-textarea:focus {
    border-color: var(--kp-accent);
    box-shadow: 0 0 0 3px var(--kp-accent-alpha);
}

.knowledge-panel__edit-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 2px 0;
}

/* ─── UTILIDAD: Ocultar elementos ──────────────────────────────── */
.kp-hidden {
    display: none !important;
}

/* ─── BOTÓN REGENERAR ──────────────────────────────────────────── */
.knowledge-panel__regen-container {
    padding: 4px 0 8px;
}

.kp-regen-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    padding: 10px 16px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(66, 99, 235, 0.06), rgba(139, 92, 246, 0.06));
    color: var(--kp-accent, #4263eb);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.22s ease;
}

.kp-regen-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(66, 99, 235, 0.12), rgba(139, 92, 246, 0.12));
    border-color: var(--kp-accent, #4263eb);
    transform: translateY(-1px);
    box-shadow: 0 3px 12px rgba(66, 99, 235, 0.15);
}

.kp-regen-btn:active:not(:disabled) {
    transform: translateY(0);
}

.kp-regen-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.kp-regen-cost {
    font-size: 0.68rem;
    font-weight: 500;
    opacity: 0.6;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.04);
}

/* Loading state */
.kp-regen-btn--loading {
    pointer-events: none;
    opacity: 0.7;
}

.kp-regen-btn--loading svg {
    animation: kp-spin 0.8s linear infinite;
}

@keyframes kp-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ─── SHIMMER (Skeleton loading) ───────────────────────────────── */
.kp-shimmer {
    display: inline-block;
    color: transparent;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: kp-shimmer-move 1.5s ease-in-out infinite;
    border-radius: 4px;
    -webkit-background-clip: text;
    background-clip: text;
    font-style: italic;
}

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

/* ─── DIVISOR ──────────────────────────────────────────────────── */
.knowledge-panel__divider {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.07);
    margin: 2px 0;
}

/* ─── CONTADOR DE CARACTERES / ESTADO DE GUARDADO ─────────── */

.knowledge-panel__notes-char-count {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    color: var(--kp-text-muted);
}

.knowledge-panel__save-status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    color: var(--kp-text-muted);
    transition: color 0.2s ease;
}

.kp-save-icon--saved {
    color: #10b981; /* Verde guardado */
}

/* Estado "guardando..." */
.kp-save-status--unsaved {
    color: #f59e0b;
}

.kp-save-status--unsaved .kp-save-icon--saved {
    display: none;
}

/* ═══════════════════════════════════════════════════════════════ */
/* FASE 4 — MOBILE BOTTOM SHEET                                   */
/* ═══════════════════════════════════════════════════════════════ */


/* Bottom Sheet */
.knowledge-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    max-height: 82vh;
    min-height: 220px;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Glassmorphism */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);

    /* Bordes superiores redondeados */
    border-radius: 22px 22px 0 0;
    border-top: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);

    /* Barra de acento en la parte superior */
    border-top: 3px solid var(--kp-accent);
}

/* Estado CERRADO */
.knowledge-sheet--closed {
    transform: translateY(110%);
    opacity: 0;
    pointer-events: none;
    transition: transform var(--kp-transition-close), opacity var(--kp-transition-close);
}

/* Estado ABIERTO */
.knowledge-sheet--open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
    transition: transform var(--kp-transition), opacity 0.2s ease;
}

/* ─── DRAG HANDLE (Barra para deslizar) ─────────────────────────── */
.knowledge-sheet__drag-handle {
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0 6px;
    touch-action: none;
    cursor: grab;
}

.knowledge-sheet__handle-bar {
    width: 36px;
    height: 4px;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 100px;
}

/* ─── CONTENIDO INTERNO DEL SHEET (Reutiliza el panel) ─────────── */
.knowledge-sheet .knowledge-panel__inner {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;

    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.1) transparent;
}

/* El header del sheet: más compacto */
.knowledge-sheet .knowledge-panel__header {
    padding: 8px 18px 12px;
}

.knowledge-sheet .knowledge-panel__header::before {
    display: none; /* El acento ya está en el border-top del sheet */
}

.knowledge-sheet .knowledge-panel__body {
    padding: 0 18px 32px; /* Extra bottom padding para gestos táctiles */
}

/* ─── OCULTACIÓN EN DESKTOP ─────────────────────────────────────── */
@media (min-width: 769px) {
    .knowledge-sheet {
        display: none !important;
    }
}

/* ─── OCULTACIÓN EN MOBILE ──────────────────────────────────────── */
@media (max-width: 768px) {
    .knowledge-panel {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════ */
/* 🚀 SMART HANDLE (Manija Inteligente) PARA PANEL DE IA          */
/* ═══════════════════════════════════════════════════════════════ */
/* 
   - Desktop: Píldora vertical al centro derecho.
   - Mobile: Píldora horizontal inferior al centro (Safe Area 24px).
   - Z-index persistente, Material glassmorphism premium.
*/

/* ─── DESKTOP (Edge Handle) ────────────────────────────────────── */
.smart-handle {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%) translateX(20px);
    width: 32px;
    height: 104px;
    
    /* Material: Glassmorphism absoluto */
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-right: none;
    border-radius: 20px 0 0 20px;
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.08); /* Luz incidente leve */
    
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: grab;
    z-index: 890 !important; /* Por encima de controles pero debajo de minimap (900+) */
    
    /* Estado Oculto */
    opacity: 0;
    pointer-events: none;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
                background 0.2s ease,
                border-color 0.2s ease,
                box-shadow 0.2s ease;
}

/* Animación sutil para Mobile (Smart Pill) */
@keyframes smartPillPulse {
    0% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); border-color: rgba(255, 255, 255, 0.4); }
    50% { box-shadow: 0 4px 20px rgba(13, 0, 158, 0.2); border-color: rgba(13, 0, 158, 0.4); }
    100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); border-color: rgba(255, 255, 255, 0.4); }
}

[data-theme="dark"] .smart-handle,
.dark-mode .smart-handle,
body.dark-theme .smart-handle {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.4);
}

/* Estado Visible */
.smart-handle.visible {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
    pointer-events: auto;
}

.smart-handle:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.7);
    transform: translateY(-50%) translateX(-6px); /* Asomo elástico */
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
}

body.dark-theme .smart-handle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.smart-handle:active {
    cursor: grabbing;
    transform: translateY(-50%) translateX(0);
}

.smart-handle__icon {
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--kp-text);
    /* Rotación para Desktop (el icon SVG se dibuja verticalemente para caber mejor) */
    transition: color 0.3s ease;
}

body.dark-theme .smart-handle__icon {
    color: #e2e8f0;
}

/* ─── MOBILE (Smart Pill) ──────────────────────────────────────── */
@media (max-width: 768px) {
    .smart-handle {
        top: auto;
        bottom: 26px; /* Sincronizado con .capincho-fab mobile (calc(26px + safe-area)) */
        bottom: calc(26px + env(safe-area-inset-bottom, 0px));
        left: 50%;
        right: auto;
        transform: translateX(-50%) translateY(20px);
        width: 110px; /* Reducción de ancho */
        height: 44px; /* Un poco más estilizado */
        
        border-right: 1px solid rgba(255, 255, 255, 0.4); /* Resetea el border-right none */
        border-radius: 100px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
        animation: smartPillPulse 4s ease-in-out infinite; /* Animación simple de presencia */
        background: rgba(255, 255, 255, 0.6); /* Un poco más de cuerpo para que se note */
        
        /* Flex row for mobile handle */
        flex-direction: row;
        gap: 8px;
        
        touch-action: pan-x pan-y; /* Permite arrastre y pan nativo */
    }

    .smart-handle.visible {
        transform: translateX(-50%) translateY(0);
    }
    
    .smart-handle:hover {
        transform: translateX(-50%) translateY(0); /* Disable asomo en mobile */
    }
    
    .smart-handle:active {
        transform: translateX(-50%) translateY(2px) scale(0.97);
    }
}

/* ═══════════════════════════════════════════════════════════════ */
/* ⏳ GLOBAL ENRICHMENT LOADER                                     */
/* ═══════════════════════════════════════════════════════════════ */
.global-enrichment-loader {
    position: fixed;
    /* Debajo de context-toolbar (50px) + main-header (58px) + gap */
    top: 112px; 
    right: 28px;
    width: 44px; /* Un poco más grande */
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    
    /* Pulso azul llamativo (IA vibe) */
    box-shadow: 0 4px 16px rgba(13, 0, 158, 0.15), 0 0 10px rgba(66, 99, 235, 0.2);
    border: 1.5px solid rgba(13, 0, 158, 0.1);
    
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    
    transform: scale(0) rotate(-45deg);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.5s var(--capincho-easing-elastic, cubic-bezier(0.34, 1.56, 0.64, 1)),
                opacity 0.3s ease-out,
                background-color 0.4s ease,
                border-color 0.4s ease,
                box-shadow 0.4s ease;
}

/* Animación de pulso continuo (Llamativo pero bajo consumo) */
@keyframes enrichmentPulse {
    0% { box-shadow: 0 4px 16px rgba(13, 0, 158, 0.15), 0 0 8px rgba(66, 99, 235, 0.2); }
    50% { box-shadow: 0 4px 20px rgba(13, 0, 158, 0.25), 0 0 16px rgba(66, 99, 235, 0.4); }
    100% { box-shadow: 0 4px 16px rgba(13, 0, 158, 0.15), 0 0 8px rgba(66, 99, 235, 0.2); }
}

[data-theme="dark"] .global-enrichment-loader,
body.dark-theme .global-enrichment-loader {
    background: rgba(30, 30, 40, 0.9);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.global-enrichment-loader.visible {
    transform: scale(1) rotate(0);
    opacity: 1;
    animation: enrichmentPulse 3s ease-in-out infinite;
}

.global-enrichment-loader .loader-ring {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(66, 99, 235, 0.2);
    border-top-color: #4263eb;
    border-radius: 50%;
    animation: loader-spin 0.8s linear infinite;
    position: absolute;
    transition: opacity 0.3s ease;
}

.global-enrichment-loader .loader-check {
    position: absolute;
    color: white;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Estado de ÉXITO */
.global-enrichment-loader.done {
    background-color: #10b981; /* Verde esmeralda */
    border-color: transparent;
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.global-enrichment-loader.done .loader-ring {
    opacity: 0;
    animation: none;
}

.global-enrichment-loader.done .loader-check {
    opacity: 1;
    transform: scale(1);
}

/* Estado de ERROR / PAUSA (Clic para reintentar) */
.global-enrichment-loader.error {
    background-color: #ef4444 !important; /* Rojo vibrante */
    border-color: transparent !important;
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.5) !important;
    cursor: pointer !important;
    pointer-events: auto !important;
}

.global-enrichment-loader.error .loader-ring {
    opacity: 0 !important;
    animation: none !important;
}

.global-enrichment-loader.error .loader-retry {
    display: block !important;
    opacity: 1 !important;
    transform: scale(1);
}

.global-enrichment-loader.error .loader-check {
    display: none !important;
}

/* Ajustes mobile */
@media (max-width: 768px) {
    .global-enrichment-loader {
        /* En mobile context-toolbar (50px) + main-header (56px) = 106px */
        top: 110px;
        right: 16px;
    }
}

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

@media (max-width: 768px) {
    .global-enrichment-loader {
        top: auto;
        bottom: 90px;
        right: 16px; /* Sobre los FAB rights */
    }
}
