/* Chat Workspace */
.workspace {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
    width: 100%;
}
.workspace-header {
    padding: 0 16px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    height: 52px;
    min-height: 52px;
    max-height: 52px;
    gap: 10px;
    flex-wrap: nowrap;
    overflow: hidden;
    box-sizing: border-box;
    width: 100%;
    z-index: 100;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}
.btn-sidebar-toggle {
    display: none;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}
.btn-sidebar-toggle:hover {
    background: rgba(16, 185, 129, 0.12);
    border-color: var(--emerald-400);
    color: var(--emerald-400);
}
.header-title {
    font-size: 13.5px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: -0.2px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}
.scope-dropdown-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 220px;
    flex-shrink: 1;
}
.scope-dropdown {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: rgba(255, 255, 255, 0.04);
    color: var(--emerald-400);
    border: 1px solid var(--border-active);
    font-weight: 600;
    font-size: 11.5px;
    padding: 6px 26px 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    outline: none;
    width: 100%;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2310b981' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: all 0.2s ease;
}
.scope-dropdown:hover, .scope-dropdown:focus {
    border-color: var(--emerald-400);
    background-color: rgba(16, 185, 129, 0.08);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.2);
}
.scope-dropdown option {
    background: var(--bg-surface);
    color: var(--text-primary);
    padding: 8px;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.btn-header-action {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 6px 11px;
    font-size: 11.5px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
    user-select: none;
}
.btn-header-action:hover {
    background: rgba(16, 185, 129, 0.12);
    border-color: var(--emerald-400);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.18);
}
.btn-header-action:active {
    transform: translateY(0);
}
.header-action-icon {
    flex-shrink: 0;
    stroke-width: 2;
    transition: transform 0.2s ease;
}
.btn-header-action:hover .header-action-icon {
    transform: scale(1.08);
}
.header-action-icon.icon-emerald {
    color: var(--emerald-400);
}
.header-action-icon.icon-cyan {
    color: #38bdf8;
}
.status-pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--emerald-400);
    box-shadow: 0 0 8px var(--emerald-400);
    animation: pulseGlow 1.8s infinite;
    flex-shrink: 0;
    margin-right: -1px;
}
.btn-header-text {
    font-weight: 600;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}
.message {
    max-width: 860px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    transition: max-width 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}
.app-layout.telemetry-collapsed .message,
.app-layout.sidebar-collapsed .message {
    max-width: 1060px;
}
.app-layout.sidebar-collapsed.telemetry-collapsed .message {
    max-width: 1240px;
}
.message.user {
    align-self: flex-end;
    align-items: flex-end;
}
.message.assistant {
    align-self: flex-start;
    align-items: flex-start;
}
.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 13.5px;
    line-height: 1.6;
    word-break: break-word;
    box-shadow: var(--shadow-soft);
    transition: background-color 0.25s ease, border-color 0.25s ease, color 0.2s ease;
}
.message.user .message-bubble {
    background: var(--bg-user-bubble);
    border: 1px solid var(--border-user-bubble);
    color: var(--text-primary);
    border-bottom-right-radius: 4px;
}
.message.assistant .message-bubble {
    background: var(--bg-assistant-bubble);
    border: 1px solid var(--border-assistant-bubble);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    width: 100%;
}

/* Citations & Sources Pills */
.sources-pill-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.source-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.24);
    color: var(--text-primary);
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 11px;
    font-family: var(--font-mono);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: default;
    transition: all 0.15s ease;
}
.source-pill:hover {
    background: rgba(16, 185, 129, 0.18);
    border-color: var(--emerald-400);
}
.source-pill-refs {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.source-pill-ref-badge {
    background: rgba(16, 185, 129, 0.22);
    border: 1px solid rgba(16, 185, 129, 0.4);
    color: var(--emerald-400);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 10px;
    font-weight: 700;
}
.source-pill-title {
    color: var(--text-primary);
    font-weight: 500;
}
.source-pill-score {
    color: var(--emerald-400);
    font-size: 10px;
    opacity: 0.85;
}

/* Input Bar Moderno / Floating */
.input-bar-container {
    padding: 10px 18px max(14px, env(safe-area-inset-bottom));
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
    z-index: 100;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}
.input-box {
    width: 100%;
    max-width: 860px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: 8px 12px 8px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: max-width 0.32s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.25s ease, border-radius 0.2s ease;
    box-shadow: var(--shadow-soft);
    position: relative;
    box-sizing: border-box;
}
.app-layout.telemetry-collapsed .input-box,
.app-layout.sidebar-collapsed .input-box {
    max-width: 1060px;
}
.app-layout.sidebar-collapsed.telemetry-collapsed .input-box {
    max-width: 1240px;
}
.input-box:focus-within {
    border-color: var(--border-active);
    box-shadow: 0 0 20px var(--emerald-glow);
}
.input-box.is-expanded {
    border-radius: 18px !important;
    padding: 12px 14px !important;
    box-shadow: 0 14px 34px -4px rgba(0, 0, 0, 0.5), 0 0 20px var(--emerald-glow) !important;
}

.input-textarea-row {
    width: 100%;
    display: flex;
    align-items: flex-start;
}

.input-box textarea {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.45;
    resize: none;
    min-height: 38px;
    height: 38px;
    max-height: 180px;
    padding: 4px 2px;
    box-sizing: border-box;
    overflow-y: auto;
}
.input-box.is-expanded textarea {
    height: 200px !important;
    max-height: 360px !important;
    font-size: 14.5px !important;
    line-height: 1.55 !important;
}
.input-box textarea::placeholder {
    color: var(--text-muted);
}

.input-actions-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

[data-theme="light"] .input-actions-row {
    border-top-color: rgba(22, 34, 56, 0.06);
}

.input-tools-left,
.input-tools-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-box .btn-send {
    border-radius: 16px;
    padding: 6px 16px;
    font-size: 12.5px;
    letter-spacing: 0.2px;
    background: var(--accent-hero);
    color: #ffffff;
    border: none;
    cursor: pointer;
    font-weight: 700;
    transition: background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    flex-shrink: 0;
}
.input-box .btn-send:hover {
    background: var(--accent-hero-hover);
    color: #ffffff;
    transform: scale(1.02);
    box-shadow: 0 0 16px var(--emerald-glow);
}
.input-box .btn-send:active {
    transform: scale(0.98);
}

/* --- Botones de Herramientas en el Input Bar (ADR-029) --- */
.btn-input-tool {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    padding: 0;
    margin-bottom: 3px;
}

.btn-input-tool:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    transform: scale(1.1);
}

[data-theme="light"] .btn-input-tool:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* Botón Varita Mágica ✨ */
.btn-magic-wand {
    color: #f59e0b;
}

.btn-magic-wand:hover {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}

.btn-magic-wand .wand-icon {
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-magic-wand:hover .wand-icon {
    transform: rotate(15deg) scale(1.15);
}

.btn-magic-wand.is-optimizing .wand-icon {
    animation: wandSpin 1s infinite linear;
    color: #f59e0b;
}

@keyframes wandSpin {
    0% { transform: rotate(0deg) scale(1.1); }
    100% { transform: rotate(360deg) scale(1.1); }
}

/* Botón Expandir / Contraer Input ⤢ / ⤡ */
.btn-expand-input {
    color: var(--text-muted);
    position: relative;
    overflow: hidden;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-expand-input .icon-expand {
    display: block;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.btn-expand-input .icon-collapse {
    display: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.btn-expand-input:hover {
    color: var(--emerald-400);
    background: rgba(16, 185, 129, 0.14);
    transform: scale(1.06);
}

/* Modo Expandido: Ocultar flechas afuera y mostrar flechas hacia adentro con animación fluida */
.input-box.is-expanded .btn-expand-input {
    color: var(--emerald-400);
    background: rgba(16, 185, 129, 0.2);
    box-shadow: 0 0 10px var(--emerald-glow);
}

.input-box.is-expanded .btn-expand-input .icon-expand {
    display: none;
}

.input-box.is-expanded .btn-expand-input .icon-collapse {
    display: block;
    animation: iconCollapsePop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] .input-box.is-expanded .btn-expand-input {
    color: #059669;
    background: rgba(5, 150, 105, 0.15);
    box-shadow: 0 0 10px rgba(5, 150, 105, 0.2);
}

@keyframes iconCollapsePop {
    0% {
        transform: scale(0.6) rotate(-45deg);
        opacity: 0;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* Botón Micrófono 🎙️ & Grabación Activa */
.btn-voice-mic {
    color: var(--sky-400);
}

.btn-voice-mic:hover {
    background: rgba(56, 189, 248, 0.15);
    color: var(--sky-400);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

.btn-voice-mic.is-recording {
    background: rgba(239, 68, 68, 0.2) !important;
    color: #ef4444 !important;
    border: 1px solid rgba(239, 68, 68, 0.4);
    animation: micPulseRing 1.5s infinite;
}

@keyframes micPulseRing {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
        transform: scale(1.08);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
        transform: scale(1);
    }
}

/* Indicador Visual de Optimización Mágica en Proceso */
.magic-loading-indicator {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(245, 158, 11, 0.45);
    border-radius: 20px;
    padding: 6px 16px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.5), 0 0 16px rgba(245, 158, 11, 0.25);
    z-index: 150;
    animation: indicatorPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] .magic-loading-indicator {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(245, 158, 11, 0.55);
    box-shadow: 0 8px 24px -4px rgba(22, 34, 56, 0.15), 0 0 16px rgba(245, 158, 11, 0.2);
}

@keyframes indicatorPop {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

.magic-loading-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(245, 158, 11, 0.3);
    border-top-color: #f59e0b;
    border-radius: 50%;
    animation: spinMagic 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes spinMagic {
    to { transform: rotate(360deg); }
}

.magic-loading-text {
    font-size: 12px;
    font-weight: 600;
    color: #fbbf24;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

[data-theme="light"] .magic-loading-text {
    color: #d97706;
}

/* --- Popover Flotante del Optimizador Mágico ✨ --- */
.magic-prompt-popover {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 20px;
    width: 340px;
    max-width: calc(100vw - 40px);
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: var(--radius-md, 14px);
    box-shadow: 0 16px 36px -4px rgba(0, 0, 0, 0.6), 0 0 20px rgba(245, 158, 11, 0.15);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
    animation: popoverFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] .magic-prompt-popover {
    background: rgba(255, 255, 255, 0.96);
    border-color: rgba(245, 158, 11, 0.45);
    box-shadow: 0 16px 36px -4px rgba(22, 34, 56, 0.18), 0 0 20px rgba(245, 158, 11, 0.12);
}

@keyframes popoverFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.magic-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-subtle);
}

.magic-popover-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
}

.magic-sparkle-icon {
    font-size: 14px;
}

.magic-popover-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.magic-popover-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.magic-popover-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.magic-mode-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm, 8px);
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    color: inherit;
    font-family: inherit;
}

[data-theme="light"] .magic-mode-card {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.06);
}

.magic-mode-card:hover {
    background: rgba(245, 158, 11, 0.08);
    border-color: rgba(245, 158, 11, 0.35);
    transform: translateX(3px);
}

.magic-mode-icon {
    font-size: 16px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.magic-mode-icon.emerald {
    background: rgba(16, 185, 129, 0.18);
    border: 1px solid rgba(16, 185, 129, 0.35);
}

.magic-mode-icon.sky {
    background: rgba(56, 189, 248, 0.18);
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.magic-mode-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.magic-mode-text strong {
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 700;
}

.magic-mode-text span {
    font-size: 10.5px;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* Efecto Shimmer en el Textarea durante la Optimización */
.input-box.optimizing-shimmer {
    border-color: #f59e0b !important;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.4) !important;
    animation: inputGlow 1.2s infinite alternate;
}

@keyframes inputGlow {
    from {
        box-shadow: 0 0 10px rgba(245, 158, 11, 0.2);
    }
    to {
        box-shadow: 0 0 25px rgba(245, 158, 11, 0.5);
    }
}

/* Document Viewer Container */
.document-viewer-container {
    display: none;
    flex-direction: column;
    height: calc(100vh - 52px);
    height: calc(100dvh - 52px);
    width: 100%;
    background: var(--bg-base);
    overflow: hidden;
}
.viewer-toolbar {
    padding: 6px 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
    min-height: 42px;
    box-sizing: border-box;
}

/* Document Viewer Tabs Bar (ADR-021 / ADR-025) */
.viewer-tabs-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    min-height: 32px;
    box-sizing: border-box;
}
.viewer-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}
.viewer-tab-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-active);
}
.viewer-tab-btn.active {
    background: rgba(16, 185, 129, 0.16) !important;
    border-color: var(--emerald-500) !important;
    color: var(--emerald-400) !important;
    box-shadow: 0 0 10px var(--emerald-glow);
}

/* Pestañas del Visor en Modo Claro (Alto Contraste & Editorial) */
[data-theme="light"] .viewer-tabs-bar {
    background: var(--bg-surface);
    border-bottom: 1px solid rgba(22, 34, 56, 0.08);
}
[data-theme="light"] .viewer-tab-btn {
    background: #FFFFFF;
    border-color: rgba(22, 34, 56, 0.15);
    color: var(--text-secondary);
}
[data-theme="light"] .viewer-tab-btn:hover {
    background: #F8FAF7;
    color: var(--text-primary);
    border-color: #059669;
}
[data-theme="light"] .viewer-tab-btn.active {
    background: #059669 !important;
    border-color: #047857 !important;
    color: #FFFFFF !important;
    font-weight: 700 !important;
    box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25) !important;
}
[data-theme="light"] .viewer-tab-btn.active span {
    color: #FFFFFF !important;
}

.viewer-title-group {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 0 1 auto;
    max-width: 240px;
    overflow: hidden;
}
.viewer-doc-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 130px;
    flex-shrink: 1;
}
.viewer-doc-badges {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.viewer-badge {
    font-size: 9.5px;
    padding: 1px 5px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
}
.viewer-badge.emerald {
    color: var(--emerald-400);
    border-color: rgba(16,185,129,0.3);
    background: rgba(16, 185, 129, 0.08);
}
.viewer-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
}
.btn-header-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.btn-header-action:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-active);
}
.btn-header-action.btn-close-viewer {
    color: var(--red-500);
    border-color: rgba(239, 68, 68, 0.25);
    background: rgba(239, 68, 68, 0.06);
}
.btn-header-action.btn-close-viewer:hover {
    background: rgba(239, 68, 68, 0.18);
    border-color: var(--red-500);
    color: #FFFFFF;
}
.viewer-body {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-base);
    padding: 20px 24px;
    margin: 0 auto;
    width: 100%;
    max-width: 900px;
    box-sizing: border-box;
}

/* ==========================================================================
   RESPONSIVE MÓVILES PANTALLA SIMPLE (< 600px)
   ========================================================================== */
@media (max-width: 599px) {
    .btn-sidebar-toggle {
        display: inline-flex;
    }
    .workspace-header {
        padding: 0 10px;
        gap: 8px;
    }
    .header-title {
        display: none;
    }
    .scope-dropdown-wrapper {
        max-width: 180px;
        min-width: 110px;
    }
    .btn-header-action {
        padding: 5px 8px;
        font-size: 11px;
        height: 30px;
        gap: 4px;
    }
    .chat-container {
        padding: 12px 10px;
        gap: 12px;
    }
    .message-bubble {
        font-size: 13px;
        padding: 10px 12px;
    }
    .input-bar-container {
        padding: 8px 10px max(10px, env(safe-area-inset-bottom));
    }
    .input-box {
        padding: 8px 10px 6px 10px;
        border-radius: 18px;
        gap: 4px;
    }
    .input-box textarea {
        font-size: 13.5px;
        min-height: 36px;
        height: 36px;
        line-height: 1.4;
        padding: 2px 2px;
    }
    .input-box .btn-send {
        padding: 5px 12px;
        font-size: 11.5px;
        border-radius: 14px;
    }
    .btn-input-tool {
        width: 28px;
        height: 28px;
        margin-bottom: 0;
    }
    .viewer-toolbar {
        padding: 6px 10px;
    }
    .viewer-body {
        padding: 10px;
    }
}

/* Modo Compacto: Móviles 1 Pantalla y Pantalla Cover de Plegables (< 640px) */
@media (max-width: 640px) {
    .workspace-header {
        padding: 0 6px;
        gap: 4px;
        height: 48px;
        min-height: 48px;
        max-height: 48px;
    }
    .header-left {
        gap: 4px;
        flex: 1;
        min-width: 0;
    }
    .btn-sidebar-toggle {
        width: 29px;
        height: 29px;
        padding: 0;
    }
    .scope-dropdown-wrapper {
        flex: 1;
        max-width: 100%;
        min-width: 0;
    }
    .scope-dropdown {
        font-size: 10.5px;
        padding: 4px 18px 4px 6px;
        background-position: right 4px center;
    }
    .header-actions {
        gap: 3px;
    }
    .btn-header-action {
        width: auto;
        height: 29px;
        padding: 3px 6px;
        font-size: 10px;
        gap: 3px;
        border-radius: var(--radius-sm);
    }
    .btn-header-text {
        display: inline !important;
        font-size: 10px;
        font-weight: 600;
    }
    .header-action-icon {
        width: 12.5px;
        height: 12.5px;
    }
    .status-pulse-dot {
        display: inline-block !important;
        width: 5px;
        height: 5px;
        margin-right: -1px;
    }
}

/* Modo Ultra Compacto (< 360px) */
@media (max-width: 360px) {
    .workspace-header {
        padding: 0 4px;
        gap: 3px;
    }
    .btn-sidebar-toggle {
        width: 27px;
        height: 27px;
    }
    .btn-header-action {
        height: 27px;
        padding: 2px 4px;
        font-size: 9.5px;
        gap: 2px;
    }
    .btn-header-text {
        font-size: 9.5px;
    }
    .scope-dropdown {
        font-size: 10px;
        padding: 3px 15px 3px 5px;
    }
}


/* --- Chunk Inspector & Editor Styles (ADR-021) --- */
.chunk-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chunk-card.editing {
    border-color: var(--border-active);
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.15);
}
.chunk-card-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.chunk-badge-id {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--emerald-400);
    background: rgba(16, 185, 129, 0.12);
    padding: 3px 9px;
    border-radius: 4px;
    border: 1px solid rgba(16, 185, 129, 0.25);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.chunk-meta-text {
    font-size: 11px;
    color: var(--text-muted);
}
.chunk-vector-badges {
    display: flex;
    align-items: center;
    gap: 6px;
}
.chunk-badge-vec {
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 3px;
}
.chunk-badge-vec.dense {
    color: var(--emerald-400);
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.chunk-badge-vec.sparse {
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.2);
}
.chunk-text-content {
    font-size: 12.5px;
    color: var(--text-primary);
    line-height: 1.6;
    white-space: pre-wrap;
    font-family: 'JetBrains Mono', monospace;
    background: rgba(0, 0, 0, 0.25);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.04);
    max-height: 240px;
    overflow-y: auto;
}
.chunk-card-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.btn-chunk-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 11.5px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    min-height: 30px;
    box-sizing: border-box;
}
.btn-chunk-action:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-active);
}
.btn-chunk-action.enrich {
    color: var(--emerald-400);
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.06);
}
.btn-chunk-action.enrich:hover {
    background: rgba(16, 185, 129, 0.15);
    border-color: var(--emerald-400);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}
.btn-chunk-action.delete {
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}
.btn-chunk-action.delete:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: #ef4444;
}

/* PDF Canvas Container */
.pdf-pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #1e222b;
    border-radius: var(--radius-sm);
    width: 100%;
    box-sizing: border-box;
}
.pdf-page-wrapper {
    background: #ffffff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    overflow: hidden;
    max-width: 100%;
    position: relative;
}
.pdf-page-wrapper canvas {
    display: block;
    max-width: 100%;
    height: auto !important;
}

@media (max-width: 600px) {
    .chunk-card-footer {
        justify-content: stretch;
        gap: 6px;
    }
    .btn-chunk-action {
        flex: 1 1 calc(33.33% - 6px);
        min-width: 75px;
        padding: 6px 4px;
        font-size: 10.5px;
        gap: 3px;
        text-align: center;
    }
}


.btn-text-full { display: inline; }
.btn-text-mobile { display: none; }

@media (max-width: 600px) {
    .btn-text-full { display: none !important; }
    .btn-text-mobile { display: inline !important; }
    .chunk-card-footer {
        display: grid !important;
        grid-template-columns: 1fr 1.35fr 1fr !important;
        gap: 6px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .btn-chunk-action {
        width: 100% !important;
        min-width: 0 !important;
        padding: 7px 4px !important;
        font-size: 11px !important;
        justify-content: center !important;
        gap: 4px !important;
        text-align: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    .btn-chunk-action span {
        font-size: 11.5px;
    }
}


/* --- Tipografía Markdown en Burbujas de Chat --- */
.message-bubble h1, .message-bubble h2, .message-bubble h3, .message-bubble h4 {
    margin: 10px 0 6px;
    font-weight: 700;
    color: #f8fafc;
    letter-spacing: -0.2px;
}
.message-bubble h3 {
    font-size: 14.5px;
    color: var(--emerald-400);
}
.message-bubble p {
    margin: 0 0 10px;
}
.message-bubble p:last-child {
    margin-bottom: 0;
}
.message-bubble ul, .message-bubble ol {
    margin: 6px 0 10px 20px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.message-bubble li {
    line-height: 1.55;
    color: var(--text-primary);
}
.message-bubble strong {
    color: #ffffff;
    font-weight: 700;
}
.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 12.5px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-subtle);
}
.message-bubble th, .message-bubble td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.message-bubble th {
    background: rgba(16, 185, 129, 0.12);
    color: var(--emerald-400);
    font-weight: 700;
    font-size: 12px;
}
.message-bubble tr:last-child td {
    border-bottom: none;
}
.message-bubble code {
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--emerald-400);
}
.message-bubble pre {
    background: rgba(11, 15, 25, 0.85);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    margin: 10px 0;
}


/* Badges Numéricos Sutiles de Citas en el Texto */
.inline-ref-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(16, 185, 129, 0.16);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: var(--emerald-400);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    padding: 0px 4px;
    border-radius: 3px;
    margin: 0 2px;
    vertical-align: 1px;
    letter-spacing: 0.2px;
    cursor: default;
    transition: all 0.15s ease;
}
.inline-ref-badge:hover {
    background: rgba(16, 185, 129, 0.3);
    border-color: var(--emerald-400);
    color: #ffffff;
}

/* ==========================================================================
   🧠 Dynamic RAG Reasoning & Pipeline Progress Card (Aceternity / Linear Style)
   ========================================================================== */

.rag-thinking-card {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(16, 185, 129, 0.28);
    border-radius: var(--radius-md);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35), 0 0 20px rgba(16, 185, 129, 0.08);
    animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.rag-thinking-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.rag-thinking-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.rag-thinking-pulsar {
    position: relative;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.rag-pulsar-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(16, 185, 129, 0.4);
    animation: ragPulsarRing 1.6s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}

.rag-pulsar-core {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--emerald-400);
    box-shadow: 0 0 8px var(--emerald-400);
}

@keyframes ragPulsarRing {
    0% { transform: scale(0.6); opacity: 1; }
    100% { transform: scale(2.2); opacity: 0; }
}

.rag-thinking-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-wrap: wrap;
}

.rag-thinking-status {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.1px;
}

.rag-thinking-scope-badge {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--emerald-400);
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    padding: 1px 7px;
    border-radius: 10px;
    white-space: nowrap;
}

.rag-thinking-timer {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--emerald-400);
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    padding: 3px 8px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.rag-stepper-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.rag-step-item {
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    min-width: 0;
}

.rag-step-item.active {
    border-color: rgba(56, 189, 248, 0.5);
    background: rgba(56, 189, 248, 0.08);
    box-shadow: 0 0 14px rgba(56, 189, 248, 0.12);
    transform: translateY(-1px);
}

.rag-step-item.completed {
    border-color: rgba(16, 185, 129, 0.35);
    background: rgba(16, 185, 129, 0.06);
}

.rag-step-icon-wrap {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
    border: 1.5px solid rgba(255, 255, 255, 0.18);
    background: rgba(0, 0, 0, 0.3);
    font-size: 10px;
    color: var(--text-muted);
}

.rag-step-item.active .rag-step-icon-wrap {
    border-color: transparent;
    border-top-color: #38bdf8;
    border-right-color: #38bdf8;
    animation: ragStepSpin 0.75s linear infinite;
    background: transparent;
}

.rag-step-item.completed .rag-step-icon-wrap {
    border: none;
    background: #10b981;
    color: #0b0f19;
    font-weight: 900;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.rag-step-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.rag-step-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.rag-step-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rag-step-item.active .rag-step-name {
    color: #38bdf8;
    font-weight: 700;
}

.rag-step-item.completed .rag-step-name {
    color: var(--emerald-400);
}

.rag-step-pct-badge {
    font-family: var(--font-mono);
    font-size: 9.5px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.rag-step-item.active .rag-step-pct-badge {
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.35);
    color: #38bdf8;
}

.rag-step-item.completed .rag-step-pct-badge {
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.35);
    color: var(--emerald-400);
}

.rag-step-sub {
    font-size: 9.5px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rag-thinking-overall-pct {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.25);
    padding: 3px 8px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.rag-thinking-progress-track {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.rag-thinking-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #10b981 0%, #06b6d4 50%, #8b5cf6 100%);
    background-size: 200% 100%;
    animation: ragShimmer 1.6s linear infinite;
    transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Metadata chip sobre respuesta completada */
.rag-meta-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 10.5px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    padding: 3px 8px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.rag-meta-chip strong {
    color: var(--emerald-400);
}

.rag-trace-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-subtle);
    font-size: 10px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.rag-trace-chip:hover {
    background: rgba(16, 185, 129, 0.12);
    border-color: var(--emerald-500);
    color: var(--emerald-400);
    transform: translateY(-1px);
}

.rag-trace-chip code {
    font-family: var(--font-mono);
    color: inherit;
    font-size: 9.5px;
}

.rag-trace-chip .copy-icon {
    font-size: 9px;
    opacity: 0.7;
}

.rag-trace-chip.copied {
    background: #059669 !important;
    color: #FFFFFF !important;
    border-color: #047857 !important;
}

[data-theme="light"] .rag-trace-chip {
    background: rgba(22, 34, 56, 0.05);
    border-color: rgba(22, 34, 56, 0.12);
    color: #475569;
}

[data-theme="light"] .rag-trace-chip:hover {
    background: #059669;
    color: #FFFFFF;
    border-color: #047857;
}

@keyframes ragStepSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes ragShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==========================================================================
   ESTILOS ESPECÍFICOS MODO CLARO RETRO-TECH (CHAT & HEADER)
   ========================================================================== */
[data-theme="light"] .scope-dropdown {
    background-color: #FFFFFF !important;
    color: #162238 !important;
    border-color: rgba(22, 34, 56, 0.15) !important;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23ea580c' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
}
[data-theme="light"] .scope-dropdown:hover,
[data-theme="light"] .scope-dropdown:focus {
    border-color: #FF6B4A !important;
    background-color: #FFEAE3 !important;
    box-shadow: 0 0 12px rgba(255, 107, 74, 0.2) !important;
}
[data-theme="light"] .scope-dropdown option {
    background-color: #FFFFFF !important;
    color: #162238 !important;
}
[data-theme="light"] .btn-header-action {
    background: #FFFFFF;
    border-color: rgba(22, 34, 56, 0.12);
    color: #162238;
}
[data-theme="light"] .btn-header-action:hover {
    background: #FFEAE3;
    border-color: #FF6B4A;
    color: #EA580C;
}
[data-theme="light"] .source-pill {
    background: #E8F8F2;
    border-color: #A7F3D0;
    color: #065F46;
}
[data-theme="light"] .source-pill:hover {
    background: #D1FAE5;
    border-color: #10B981;
}
[data-theme="light"] .source-pill-ref-badge {
    background: #FFEAE3;
    border-color: #FFB39F;
    color: #EA580C;
}
[data-theme="light"] .rag-meta-chip {
    background: #FFFFFF;
    border-color: rgba(22, 34, 56, 0.1);
    color: #475569;
}
[data-theme="light"] .rag-meta-chip strong {
    color: #EA580C;
}

/* RAG Reasoning Card & Stepper en Modo Claro */
[data-theme="light"] .rag-thinking-card {
    background: #FFFFFF !important;
    border: 1px solid rgba(22, 34, 56, 0.1) !important;
    box-shadow: 0 4px 20px rgba(22, 34, 56, 0.06), 0 0 20px rgba(255, 107, 74, 0.05) !important;
}
[data-theme="light"] .rag-thinking-status {
    color: #162238 !important;
}
[data-theme="light"] .rag-thinking-scope-badge {
    background: #FFEAE3 !important;
    border-color: #FFB39F !important;
    color: #EA580C !important;
}
[data-theme="light"] .rag-thinking-timer {
    background: #FAF7F2 !important;
    border-color: rgba(22, 34, 56, 0.12) !important;
    color: #162238 !important;
}
[data-theme="light"] .rag-step-item {
    background: #FAF7F2 !important;
    border: 1px solid rgba(22, 34, 56, 0.08) !important;
}
[data-theme="light"] .rag-step-name {
    color: #162238 !important;
}
[data-theme="light"] .rag-step-desc {
    color: #64748B !important;
}
[data-theme="light"] .rag-step-item.completed {
    background: #E8F8F2 !important;
    border-color: #A7F3D0 !important;
}
[data-theme="light"] .rag-step-item.completed .rag-step-name {
    color: #065F46 !important;
}
[data-theme="light"] .rag-step-item.completed .rag-step-icon-wrap {
    background: #10B981 !important;
    color: #FFFFFF !important;
}
[data-theme="light"] .rag-step-item.active {
    background: #FFEAE3 !important;
    border-color: #FF6B4A !important;
}
[data-theme="light"] .rag-step-item.active .rag-step-name {
    color: #EA580C !important;
}
[data-theme="light"] .rag-step-badge {
    background: #FFFFFF !important;
    border-color: rgba(22, 34, 56, 0.1) !important;
    color: #162238 !important;
}
[data-theme="light"] .rag-step-badge.completed {
    background: #A7F3D0 !important;
    color: #065F46 !important;
}
[data-theme="light"] .rag-step-badge.active {
    background: #FFB39F !important;
    color: #9A3412 !important;
}
[data-theme="light"] .rag-thinking-progress-track {
    background: rgba(22, 34, 56, 0.08) !important;
}

/* Tablas Markdown & Bloques de Código en Modo Claro */
[data-theme="light"] .message-bubble strong {
    color: #162238;
}
[data-theme="light"] .message-bubble table {
    background: #FFFFFF;
    border: 1px solid rgba(22, 34, 56, 0.1);
}
[data-theme="light"] .message-bubble th {
    background: #FAF7F2;
    color: #162238;
    border-bottom: 1px solid rgba(22, 34, 56, 0.1);
}
[data-theme="light"] .message-bubble td {
    color: #162238;
    border-bottom: 1px solid rgba(22, 34, 56, 0.06);
}
[data-theme="light"] .message-bubble tr:nth-child(even) td {
    background: #FAF7F2;
}
[data-theme="light"] .message-bubble tr:hover td {
    background: #FFEAE3;
}
[data-theme="light"] .message-bubble code {
    background: #FFEAE3;
    color: #EA580C;
}
[data-theme="light"] .message-bubble pre {
    background: #FAF7F2;
    border: 1px solid rgba(22, 34, 56, 0.1);
    color: #162238;
}
[data-theme="light"] .message-bubble h1,
[data-theme="light"] .message-bubble h2,
[data-theme="light"] .message-bubble h4,
[data-theme="light"] .message-bubble h5,
[data-theme="light"] .message-bubble h6 {
    color: #162238 !important;
}
[data-theme="light"] .message-bubble h3 {
    color: #059669 !important;
}
[data-theme="light"] .message-bubble strong {
    color: #162238 !important;
}
[data-theme="light"] .message-bubble li,
[data-theme="light"] .message-bubble p {
    color: #162238 !important;
}

@media (max-width: 900px) {
    .rag-stepper-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 540px) {
    .rag-stepper-container {
        grid-template-columns: 1fr;
    }
    .rag-step-sub {
        display: none;
    }
}

/* ==========================================================================
   MILESTONE 14: WORKSPACE SPLIT-VIEW, SPLITTER GRIP, BUSCADOR & RESALTADO GOLD
   ========================================================================== */

/* 1. Layout Maestro Split-View */
.workspace.split-view-active {
    display: flex !important;
    flex-direction: row !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    position: relative !important;
}

/* Columna de Chat Maestro (100% por defecto, 50% en Split-View) */
.split-chat-section {
    flex: 1 1 100%;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.workspace.split-view-active .split-chat-section {
    flex: 0 0 var(--split-chat-width, 50%);
    width: var(--split-chat-width, 50%);
    min-width: 28%;
    max-width: 72%;
    transition: flex-basis 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

body.is-resizing-split .split-chat-section,
body.is-resizing-split .document-viewer-container {
    transition: none !important;
    user-select: none !important;
}

/* 2. Píldora Central Splitter Grip (Drag & Drop 60fps) */
.split-grip-resizer {
    position: relative;
    width: 14px;
    height: 100%;
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    user-select: none;
    touch-action: none;
    background: transparent;
    transition: background 0.2s ease;
}

.split-grip-resizer::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    background: var(--border-subtle);
    transform: translateX(-50%);
    transition: background 0.2s, width 0.2s;
}

.split-grip-resizer:hover::before,
body.is-resizing-split .split-grip-resizer::before {
    background: var(--emerald-500);
    width: 2px;
    box-shadow: 0 0 8px var(--emerald-glow);
}

.split-grip-pill {
    position: relative;
    width: 24px;
    height: 52px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(16, 185, 129, 0.45);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 8px rgba(16, 185, 129, 0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    z-index: 45;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s, border-color 0.2s;
}

.icon-split-arrows {
    width: 13px;
    height: 13px;
    stroke: var(--emerald-400);
}

.split-grip-dots {
    display: flex;
    flex-direction: column;
    gap: 2.5px;
}

.split-grip-dots span {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--emerald-400);
    opacity: 0.8;
}

.split-grip-resizer:hover .split-grip-pill,
body.is-resizing-split .split-grip-pill {
    transform: scale(1.12);
    border-color: var(--emerald-400);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), 0 0 16px var(--emerald-glow);
}

/* 3. Panel de Visor en Modo Split */
.workspace.split-view-active .document-viewer-container {
    flex: 1 1 auto !important;
    min-width: 28% !important;
    max-width: 72% !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    background: var(--bg-surface) !important;
    border-left: 1px solid var(--border-subtle) !important;
    animation: splitViewerSmoothIn 0.38s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    position: relative !important;
    z-index: 30;
    will-change: transform, opacity;
}

@keyframes splitViewerSmoothIn {
    0% {
        opacity: 0;
        transform: translate3d(24px, 0, 0);
    }
    100% {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

/* Modo Maximizado en Pantalla Completa */
.document-viewer-container.is-maximized {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    z-index: 100 !important;
}

/* 4. Barra de Búsqueda In-Document con Lupa (M14) */
.viewer-search-toolbar {
    display: flex !important;
    align-items: center !important;
    flex: 1 1 220px !important;
    min-width: 170px !important;
    max-width: 280px !important;
    margin: 0 6px !important;
}

.search-input-wrapper {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    width: 100% !important;
    min-width: 170px !important;
    height: 30px !important;
    background: var(--bg-card) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-sm) !important;
    padding: 0 8px !important;
    gap: 4px !important;
    box-sizing: border-box !important;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.search-input-wrapper:focus-within {
    border-color: var(--emerald-500) !important;
    box-shadow: 0 0 10px var(--emerald-glow) !important;
    background: var(--bg-surface) !important;
}

.search-glass-icon {
    width: 14px !important;
    height: 14px !important;
    min-width: 14px !important;
    min-height: 14px !important;
    max-width: 14px !important;
    max-height: 14px !important;
    stroke: var(--text-muted) !important;
    flex-shrink: 0 !important;
    display: block !important;
}

#viewerSearchInput {
    border: none !important;
    background: transparent !important;
    color: var(--text-primary) !important;
    font-size: 11px !important;
    font-family: var(--font-sans) !important;
    outline: none !important;
    flex: 1 1 auto !important;
    min-width: 50px !important;
    width: 100% !important;
    height: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

#viewerSearchInput::placeholder {
    color: var(--text-muted) !important;
    font-size: 11px !important;
}

.search-counter {
    font-size: 10px !important;
    font-weight: 700 !important;
    font-family: var(--font-mono) !important;
    color: #F59E0B !important;
    background: rgba(245, 158, 11, 0.15) !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
}

.search-nav-btn,
.search-clear-btn {
    border: none !important;
    background: transparent !important;
    color: var(--text-secondary) !important;
    font-size: 11px !important;
    cursor: pointer !important;
    padding: 2px 4px !important;
    border-radius: 3px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.15s !important;
    flex-shrink: 0 !important;
}

.search-nav-btn:hover,
.search-clear-btn:hover {
    color: var(--text-primary) !important;
    background: rgba(255, 255, 255, 0.1) !important;
}

/* 5. Resaltado Dorado Inteligente y Animación de Pulso (DOM / Texto) */
.rag-highlight-gold {
    background: rgba(251, 191, 36, 0.28) !important;
    border-left: 4px solid #F59E0B !important;
    border-radius: 0 6px 6px 0 !important;
    padding: 2px 6px !important;
    display: inline-block !important;
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.3) !important;
    color: inherit !important;
    transition: background 0.3s ease, box-shadow 0.3s ease !important;
}

.rag-highlight-gold.pulse {
    animation: goldHighlightPulse 3s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
}

@keyframes goldHighlightPulse {
    0% {
        background: rgba(245, 158, 11, 0.55);
        box-shadow: 0 0 24px rgba(245, 158, 11, 0.85);
    }
    40% {
        background: rgba(245, 158, 11, 0.35);
        box-shadow: 0 0 16px rgba(245, 158, 11, 0.5);
    }
    100% {
        background: rgba(251, 191, 36, 0.22);
        box-shadow: 0 0 8px rgba(245, 158, 11, 0.2);
    }
}

/* 6. Coincidencias de Búsqueda In-Document (DOM) */
.rag-search-match {
    background: rgba(253, 224, 71, 0.35) !important;
    color: inherit !important;
    border-radius: 2px !important;
    padding: 1px 2px !important;
}

.rag-search-match-active {
    background: #F59E0B !important;
    color: #000000 !important;
    font-weight: 700 !important;
    border-radius: 3px !important;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.8) !important;
    outline: 2px solid #D97706 !important;
}

/* 7. PDF.js Page Wrapper & TextLayer (Cero Duplicación de Texto, 100% Transparente) */
.pdf-page-wrapper {
    position: relative !important;
    margin: 0 auto 24px auto !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35) !important;
    border-radius: 4px !important;
    overflow: hidden !important;
    background: #FFFFFF !important;
    display: block !important;
}

.pdf-page-wrapper canvas {
    display: block !important;
    width: 100% !important;
    height: auto !important;
}

.pdf-page-wrapper .textLayer {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    overflow: hidden !important;
    opacity: 1 !important;
    line-height: 1.0 !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    z-index: 2 !important;
}

.pdf-page-wrapper .textLayer span {
    color: transparent !important;
    -webkit-text-fill-color: transparent !important;
    position: absolute !important;
    white-space: pre !important;
    cursor: text !important;
    transform-origin: 0% 0% !important;
}

.pdf-page-wrapper .textLayer ::selection {
    background: rgba(16, 185, 129, 0.35) !important;
    color: transparent !important;
    -webkit-text-fill-color: transparent !important;
}

/* Resaltado en PDF: Solo Fondo Ámbar/Oro, Texto 100% Transparente para que no se duplique */
.pdf-page-wrapper .textLayer span.rag-search-match {
    background: rgba(253, 224, 71, 0.45) !important;
    color: transparent !important;
    -webkit-text-fill-color: transparent !important;
    border-radius: 2px !important;
    box-shadow: 0 0 6px rgba(253, 224, 71, 0.6) !important;
}

.pdf-page-wrapper .textLayer span.rag-search-match-active {
    background: rgba(245, 158, 11, 0.65) !important;
    color: transparent !important;
    -webkit-text-fill-color: transparent !important;
    border-radius: 3px !important;
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.95) !important;
    outline: 2px solid #D97706 !important;
}

.pdf-page-wrapper .textLayer span.rag-highlight-gold {
    background: rgba(251, 191, 36, 0.55) !important;
    color: transparent !important;
    -webkit-text-fill-color: transparent !important;
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.8) !important;
    border-radius: 3px !important;
}

.pdf-page-num-badge {
    position: absolute;
    bottom: 8px;
    right: 12px;
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-subtle);
    pointer-events: none;
    z-index: 10;
}

/* 8. Animación Mágica Estelar al abrir Split-View (2.5s) */
.magic-split-sparkle {
    position: absolute;
    color: #F59E0B;
    pointer-events: none;
    user-select: none;
    z-index: 60;
    filter: drop-shadow(0 0 10px rgba(245, 158, 11, 0.95));
    animation: magicSparkleFloat 2.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes magicSparkleFloat {
    0% {
        opacity: 0;
        transform: translateY(0) scale(0.3) rotate(0deg);
    }
    25% {
        opacity: 1;
        transform: translateY(-16px) scale(1.3) rotate(60deg);
    }
    70% {
        opacity: 0.85;
        transform: translateY(-38px) scale(1.0) rotate(140deg);
    }
    100% {
        opacity: 0;
        transform: translateY(-65px) scale(0.4) rotate(220deg);
    }
}


