/* ── Paleta IA (púrpura) ────────────────────────────────────────────────── */
.ia-text-accent { color: #7c3aed !important; }

/* Botón de apertura del cajón IA */
.ia-open-drawer-btn {
    background: linear-gradient(135deg, #7c3aed, #5b21b6) !important;
    border-color: #5b21b6 !important;
    color: #fff !important;
    transition: background .20s, box-shadow .20s;
}
.ia-open-drawer-btn:hover,
.ia-open-drawer-btn:focus {
    background: linear-gradient(135deg, #5b21b6, #3b0f8c) !important;
    border-color: #3b0f8c !important;
    color: #fff !important;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.45);
}

/* ── Widget raíz ────────────────────────────────────────────────────────── */
#ia-chat-widget {
    position: fixed;
    bottom: 18px;
    right: 64px;
    z-index: 9990;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}

/* ── Botón flotante (FAB) ───────────────────────────────────────────────── */
.ia-chat-fab {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #5b21b6);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.50);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    transition: transform .20s, box-shadow .20s;
    position: relative;
    outline: none;
}
.ia-chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.65);
}
.ia-chat-fab:active { transform: scale(0.94); }

/* Insignia de mensajes nuevos */
.ia-chat-badge {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 14px;
    height: 14px;
    background: #e53935;
    border-radius: 50%;
    border: 2px solid #fff;
}

/* ── Panel ──────────────────────────────────────────────────────────────── */
.ia-chat-panel {
    position: absolute;
    bottom: 68px;
    right: 0;
    width: 380px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity .22s, transform .22s;
    transform-origin: bottom right;
}
.ia-hidden {
    opacity: 0;
    transform: scale(0.85) translateY(8px);
    pointer-events: none;
}

/* ── Cabecera ───────────────────────────────────────────────────────────── */
.ia-chat-header {
    background: linear-gradient(135deg, #7c3aed, #5b21b6);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.ia-chat-header-info {
    display: flex;
    align-items: center;
    gap: 8px;
}
.ia-chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #69f0ae;
    box-shadow: 0 0 6px #69f0ae;
    flex-shrink: 0;
}
.ia-chat-title {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 230px;
}
.ia-chat-header-actions { display: flex; gap: 2px; }

.ia-btn-icon {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, .80);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 13px;
    transition: background .15s, color .15s;
    outline: none;
}
.ia-btn-icon:hover {
    background: rgba(255, 255, 255, .20);
    color: #fff;
}

/* ── Área de mensajes ───────────────────────────────────────────────────── */
.ia-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8f9fa;
}
.ia-chat-messages::-webkit-scrollbar { width: 4px; }
.ia-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ia-chat-messages::-webkit-scrollbar-thumb { background: #c8cdd3; border-radius: 4px; }

/* Bienvenida */
.ia-chat-welcome {
    text-align: center;
    color: #6c757d;
    padding: 28px 16px;
}
.ia-welcome-icon {
    font-size: 38px;
    color: #7c3aed;
    margin-bottom: 10px;
}
.ia-chat-welcome p { margin: 0; font-size: 13px; }

/* Burbujas */
.ia-msg {
    display: flex;
    flex-direction: column;
    max-width: 86%;
    gap: 3px;
}
.ia-msg-user { align-self: flex-end; align-items: flex-end; }
.ia-msg-bot  { align-self: flex-start; align-items: flex-start; }

.ia-bubble {
    padding: 9px 13px;
    border-radius: 16px;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
}
.ia-msg-user .ia-bubble {
    background: #7c3aed;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ia-msg-bot .ia-bubble {
    background: #fff;
    color: #212529;
    border-bottom-left-radius: 4px;
    border: 1px solid #e2e6ea;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .07);
}
.ia-bubble-error {
    background: #fff3f3 !important;
    color: #c62828 !important;
    border-color: #ffcdd2 !important;
}

.ia-msg-label {
    font-size: 11px;
    color: #adb5bd;
    padding: 0 4px;
}

/* Fuentes */
.ia-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
}
.ia-source-chip {
    background: #ede9fe;
    color: #7c3aed;
    border: 1px solid #c4b5fd;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 11px;
    /* max-width: 200px; */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: default;
}

/* Indicador de escritura */
.ia-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 13px;
    background: #fff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    border: 1px solid #e2e6ea;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .07);
    width: fit-content;
}
.ia-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #adb5bd;
    animation: ia-bounce 1.2s infinite;
}
.ia-dot:nth-child(2) { animation-delay: .2s; }
.ia-dot:nth-child(3) { animation-delay: .4s; }
@keyframes ia-bounce {
    0%, 80%, 100% { transform: scale(.8); opacity: .5; }
    40%           { transform: scale(1.1); opacity: 1; }
}

/* ── Pie (input) ────────────────────────────────────────────────────────── */
.ia-chat-footer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e9ecef;
    background: #fff;
    flex-shrink: 0;
}
.ia-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    max-height: 100px;
    background: #f8f9fa;
    transition: border-color .20s, background .20s;
    line-height: 1.4;
}
.ia-chat-input:focus {
    border-color: #7c3aed;
    background: #fff;
}
.ia-btn-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #7c3aed;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    outline: none;
    transition: background .18s, transform .14s;
}
.ia-btn-send:hover   { background: #5b21b6; }
.ia-btn-send:active  { transform: scale(.93); }
.ia-btn-send:disabled { background: #adb5bd; cursor: not-allowed; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #ia-chat-widget { bottom: 14px; right: 14px; }
    .ia-chat-panel {
        width: calc(100vw - 28px);
        height: 72vh;
        right: -7px;
    }
}

/* ── Modo embebido (panel inline, sin FAB) ──────────────────────────────── */
#ia-chat-widget.ia-embebido {
    position: relative;
    /* bottom: auto; */
    right: auto;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    z-index: auto;
}

#ia-chat-widget.ia-embebido .ia-chat-panel {
    position: relative;
    bottom: auto;
    right: auto;
    width: 100%;
    height: 100%;
    border-radius: 0;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
}

/* El área de mensajes ocupa todo el espacio disponible */
#ia-chat-widget.ia-embebido .ia-chat-messages {
    flex: 1;
    overflow-y: auto;
}

@media (max-width: 768px) {
    #ia-chat-widget.ia-embebido {
        height: 100%;
        min-height: 400px;
    }
}

/* ── Barra flotante de consulta sobre el visor de archivo ──────────────── */
#ia-modal-ask-bar {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid #c4b5fd;
    border-radius: 30px;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.28);
    display: flex;
    align-items: center;
    padding: 8px 8px 8px 14px;
    gap: 8px;
    min-width: 300px;
    max-width: 520px;
    width: max-content;
    backdrop-filter: blur(4px);
    transition: box-shadow .2s, border-color .2s;
}
#ia-modal-ask-bar:focus-within {
    box-shadow: 0 4px 28px rgba(124, 58, 237, 0.42);
    border-color: #7c3aed;
}
.ia-ask-bar-icon {
    color: #7c3aed;
    font-size: 15px;
    flex-shrink: 0;
}
#ia-modal-ask-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: transparent;
    color: #212529;
    min-width: 220px;
}
#ia-modal-ask-input::placeholder { color: #adb5bd; }
#ia-modal-ask-send {
    background: #7c3aed;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    outline: none;
    transition: background .18s, transform .14s;
}
#ia-modal-ask-send:hover  { background: #5b21b6; }
#ia-modal-ask-send:active { transform: scale(.92); }

/* ── Cajón IA Global (sidebar drawer) ──────────────────────────────────── */
#ia-drawer-root {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    z-index: 1040;
    display: flex;
    flex-direction: row;
    align-items: center;
    pointer-events: none;
}

#ia-drawer-toggle {
    pointer-events: all;
    flex-shrink: 0;
    width: 28px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    background: linear-gradient(180deg, #7c3aed, #5b21b6);
    color: #fff;
    border: none;
    cursor: pointer;
    padding: 18px 6px;
    border-radius: 8px 0 0 8px;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 600;
    letter-spacing: 1px;
    box-shadow: -3px 0 10px rgba(124, 58, 237, 0.40);
    transition: background .20s, box-shadow .20s;
    display: flex;
    align-items: center;
    gap: 6px;
    outline: none;
    align-self: center;
}
#ia-drawer-toggle:hover {
    background: linear-gradient(180deg, #5b21b6, #3b0f8c);
    box-shadow: -4px 0 14px rgba(124, 58, 237, 0.55);
}
#ia-drawer-toggle .ia-drawer-tab-icon {
    transform: rotate(0deg);
    transition: transform .25s;
    font-size: 14px;
}
#ia-drawer-root.ia-drawer-open #ia-drawer-toggle .ia-drawer-tab-icon {
    transform: rotate(180deg);
}

#ia-drawer-panel {
    pointer-events: all;
    width: 25vw;
    min-width: 320px;
    height: 100vh;
    padding-top: 60px;   /* compensa la navbar fija de la aplicación */
    background: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width .30s ease, min-width .30s ease, opacity .25s ease;
    opacity: 1;
}
#ia-drawer-panel.ia-drawer-hidden {
    width: 0;
    min-width: 0;
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 768px) {
    #ia-drawer-panel {
        width: 85vw;
        min-width: 0;
    }
}
