Files
admin-edu-space/frontend/views/partials/ai_chat_widget.html
T

647 lines
20 KiB
HTML

{% set active_auth_user = impersonated_user if (is_impersonating and impersonated_user) else (auth_user if (auth_user and auth_user.is_authenticated) else (current_user if (current_user and current_user.is_authenticated) else user)) %}
{% set current_user_id = active_auth_user.id if active_auth_user and active_auth_user.id else '' %}
{% set current_user_email = active_auth_user.email if active_auth_user and active_auth_user.email else '' %}
{% set current_user_name = active_auth_user.first_name if (active_auth_user and active_auth_user.first_name) else (active_auth_user.name if active_auth_user else '') %}
{% set current_role_name = (active_auth_user.role if active_auth_user and active_auth_user.role else 'alumno') | lower %}
<!-- ===================================================== -->
<!-- WIDGET UdeCi: TUTOR VIRTUAL UNICABA (UX ESTILO MELI) -->
<!-- Bottom Sheet Nativo en Móvil + Input Dock Inteligente -->
<!-- ===================================================== -->
<!-- Backdrop de Bloqueo en Móvil -->
<div id="aiChatBackdrop" class="ai-chat-backdrop d-none" aria-hidden="true"></div>
<div id="aiChatContainer" class="ai-chat-container"
data-user-id="{{ current_user_id }}"
data-user-email="{{ current_user_email }}"
data-user-name="{{ current_user_name }}"
data-user-role="{{ current_role_name }}">
<!-- Botón Lanzador Flotante -->
<button id="aiChatLauncher" class="ai-chat-launcher btn shadow-lg" type="button" aria-label="Abrir tutor UdeCi" title="UdeCi - Tutor Virtual UniCABA">
<span class="ai-launcher-icon"><i class="bi bi-stars"></i></span>
<span class="ai-launcher-badge pulse-dot"></span>
</button>
<!-- Panel de Conversación (Bottom Sheet en Móvil / Ventana Flotante en Desktop) -->
<div id="aiChatPanel" class="ai-chat-panel card border-0 d-none" role="dialog" aria-modal="true" aria-labelledby="aiChatTitle">
<!-- Drag Handle Superior (Estilo Nativo Móvil) -->
<div class="ai-sheet-handle-bar" id="aiSheetHandleBar" title="Desliza para cerrar">
<span class="ai-sheet-handle"></span>
</div>
<!-- Cabecera de Navegación y Acciones -->
<div class="ai-chat-header d-flex align-items-center justify-content-between px-3 pt-1 pb-2">
<!-- Botón de Retroceso / Minimizar (Móvil & Desktop) -->
<button type="button" class="ai-btn-circle" id="aiChatBackBtn" title="Cerrar asistente" aria-label="Volver">
<i class="bi bi-chevron-left fs-6"></i>
</button>
<!-- Título Central con Ícono IA -->
<div class="d-flex align-items-center gap-2 text-center overflow-hidden">
<div class="ai-header-sparkle-badge">
<i class="bi bi-stars"></i>
</div>
<div class="lh-1 text-truncate">
<h6 class="mb-0 fw-bold ai-header-title text-truncate" id="aiChatTitle">UdeCi</h6>
<small class="ai-header-subtitle">Tutor Virtual UniCABA</small>
</div>
</div>
<!-- Botones de Acción Derecha: Nuevo Chat + Cerrar -->
<div class="d-flex align-items-center gap-1">
<button type="button" class="ai-btn-circle" id="aiChatClearBtn" title="Nueva conversación" aria-label="Nueva conversación">
<i class="bi bi-pencil-square fs-6"></i>
</button>
<button type="button" class="ai-btn-circle d-none d-md-inline-flex" id="aiChatCloseBtn" title="Cerrar ventana" aria-label="Cerrar">
<i class="bi bi-x-lg fs-6"></i>
</button>
</div>
</div>
<!-- Subtítulo / Disclaimer Institucional (Estilo Mercado Libre) -->
<div class="ai-chat-disclaimer px-3 py-1">
<small class="text-muted d-block text-center">UdeCi usa inteligencia artificial para responderte.</small>
</div>
<!-- Área de Conversación (Mensajes) -->
<div class="ai-chat-messages px-3 py-2" id="aiChatMessages" tabindex="0">
<!-- Conversación generada dinámicamente -->
</div>
<!-- Indicador de Respuesta en Progreso -->
<div id="aiChatTyping" class="ai-typing-indicator px-3 py-1 d-none">
<small class="text-muted d-flex align-items-center gap-2">
<span class="typing-dot"></span>
<span class="typing-dot"></span>
<span class="typing-dot"></span>
<span>UdeCi está respondiendo...</span>
</small>
</div>
<!-- Dock de Entrada (Input estilo Mercado Libre) -->
<div class="ai-chat-footer px-3 py-2" id="aiChatFooter">
<form id="aiChatForm" class="m-0" onsubmit="handleAiChatSubmit(event)">
<div class="ai-input-pill-container d-flex align-items-center gap-2">
<!-- Botón + para abrir atajos rápidos -->
<button type="button" class="ai-input-plus-btn" id="aiChatPlusBtn" title="Consultas rápidas" aria-label="Abrir temas">
<i class="bi bi-plus-lg"></i>
</button>
<!-- Campo de texto autorregulable -->
<textarea id="aiChatInput" class="form-control ai-chat-textarea border-0 shadow-none p-0"
rows="1"
placeholder="Pregúntame"
aria-label="Mensaje para UdeCi"></textarea>
<!-- Botón Enviar con ícono elevado -->
<button type="submit" class="ai-send-btn" id="aiChatSendBtn" title="Enviar consulta" aria-label="Enviar">
<i class="bi bi-arrow-up-circle-fill fs-4"></i>
</button>
</div>
</form>
</div>
</div>
</div>
<style>
/* ==============================================================
ESTILOS BASE: WIDGET UdeCi CON ESTÉTICA MERCADO LIBRE
============================================================== */
/* Backdrop para Móvil */
.ai-chat-backdrop {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(15, 23, 42, 0.55);
backdrop-filter: blur(3px);
-webkit-backdrop-filter: blur(3px);
z-index: 1065;
transition: opacity 0.25s ease;
}
/* Contenedor Flotante Principal */
.ai-chat-container {
position: fixed;
bottom: calc(24px + env(safe-area-inset-bottom, 0px));
right: calc(24px + env(safe-area-inset-right, 0px));
z-index: 1070;
font-family: inherit;
}
/* Botón Lanzador Flotante (Desktop y estado cerrado) */
.ai-chat-launcher {
width: 56px;
height: 56px;
border-radius: 50% !important;
background: linear-gradient(135deg, #B43E8E 0%, #2563eb 100%) !important;
color: #ffffff !important;
display: flex;
align-items: center;
justify-content: center;
border: 2px solid rgba(255, 255, 255, 0.45) !important;
position: relative;
cursor: pointer;
box-shadow: 0 8px 24px rgba(180, 62, 142, 0.35) !important;
transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
}
.ai-chat-launcher:hover {
transform: scale(1.08);
box-shadow: 0 12px 30px rgba(180, 62, 142, 0.5) !important;
}
.ai-launcher-icon {
font-size: 1.45rem;
line-height: 1;
}
.pulse-dot {
position: absolute;
top: 3px;
right: 3px;
width: 12px;
height: 12px;
background-color: #22c55e;
border-radius: 50%;
border: 2px solid #ffffff;
box-shadow: 0 0 8px #22c55e;
animation: aiPulse 2.2s infinite;
}
@keyframes aiPulse {
0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
/* ==============================================================
PANEL DE CONVERSACIÓN: DESKTOP
============================================================== */
.ai-chat-panel {
width: 400px;
max-width: calc(100vw - 32px);
height: 560px;
max-height: calc(100vh - 90px);
border-radius: 24px !important;
overflow: hidden;
display: flex;
flex-direction: column;
box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35) !important;
animation: aiSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
background: #ffffff;
border: 1px solid rgba(180, 62, 142, 0.2) !important;
z-index: 1075;
}
@keyframes aiSlideUp {
from { opacity: 0; transform: translateY(16px) scale(0.97); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
/* Ocultar handle bar en desktop */
.ai-sheet-handle-bar {
display: none;
width: 100%;
text-align: center;
padding: 8px 0 2px 0;
cursor: grab;
user-select: none;
}
.ai-sheet-handle {
display: inline-block;
width: 40px;
height: 4px;
background: rgba(100, 116, 139, 0.35);
border-radius: 4px;
}
/* Cabecera Estilo Mercado Libre */
.ai-chat-header {
background: #ffffff;
border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.ai-header-title {
color: #0F172A;
font-size: 0.98rem;
}
.ai-header-subtitle {
font-size: 0.72rem;
color: #64748B;
}
.ai-header-sparkle-badge {
width: 32px;
height: 32px;
border-radius: 50%;
background: linear-gradient(135deg, rgba(180, 62, 142, 0.15) 0%, rgba(37, 99, 235, 0.15) 100%);
color: #B43E8E;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.05rem;
}
/* Botones Circulares del Header */
.ai-btn-circle {
width: 36px;
height: 36px;
border-radius: 50%;
border: 1px solid transparent;
background: rgba(241, 245, 249, 0.85);
color: #334155;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.18s ease;
}
.ai-btn-circle:hover {
background: rgba(226, 232, 240, 1);
color: #0F172A;
transform: translateY(-1px);
}
/* Disclaimer Institucional */
.ai-chat-disclaimer {
background: rgba(248, 250, 252, 0.85);
border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}
.ai-chat-disclaimer small {
font-size: 0.73rem;
color: #64748B !important;
}
/* Área de Mensajes */
.ai-chat-messages {
flex: 1 1 auto;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 14px;
scroll-behavior: smooth;
background: #FFFFFF;
}
/* Mensajes Estilo Mercado Libre */
.ai-msg {
max-width: 88%;
word-break: break-word;
font-size: 0.92rem;
line-height: 1.48;
}
/* Mensaje del Usuario: Cápsula suave a la derecha con hora */
.ai-msg-user {
align-self: flex-end;
background: #F1F5F9;
color: #0F172A;
padding: 9px 14px 6px 14px;
border-radius: 20px 20px 4px 20px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.ai-msg-user .ai-msg-time {
font-size: 0.68rem;
color: #94A3B8;
text-align: right;
margin-top: 3px;
display: block;
}
/* Mensaje del Asistente (UdeCi): Lienzo limpio sin caja pesada */
.ai-msg-assistant {
align-self: flex-start;
color: #0F172A;
padding: 2px 4px;
background: transparent;
width: 100%;
}
.ai-msg-assistant p:last-child {
margin-bottom: 0;
}
/* Fila de Acciones debajo de la respuesta de UdeCi (Copiar, Audio, Feedback) */
.ai-msg-actions {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
padding-top: 4px;
}
.ai-action-icon-btn {
background: transparent;
border: none;
color: #94A3B8;
cursor: pointer;
padding: 3px 5px;
font-size: 0.9rem;
border-radius: 6px;
display: inline-flex;
align-items: center;
justify-content: center;
transition: all 0.15s ease;
}
.ai-action-icon-btn:hover {
color: #0F172A;
background: rgba(0, 0, 0, 0.05);
}
.ai-action-icon-btn.active {
color: #B43E8E;
}
/* Opciones / Chips sugeridos en la respuesta */
.ai-msg-options {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 10px;
}
.ai-option-btn {
font-size: 0.78rem;
padding: 5px 12px;
border-radius: 18px;
background-color: #FFFFFF;
border: 1px solid #CBD5E1;
color: #0F172A;
cursor: pointer;
transition: all 0.15s ease;
font-weight: 500;
}
.ai-option-btn:hover {
background-color: rgba(180, 62, 142, 0.1);
border-color: #B43E8E;
color: #8C256B;
transform: translateY(-1px);
}
/* Indicador de Escritura */
.ai-typing-indicator .typing-dot {
width: 6px;
height: 6px;
background-color: #94a3b8;
border-radius: 50%;
animation: typingBounce 1.4s infinite ease-in-out;
}
.ai-typing-indicator .typing-dot:nth-child(1) { animation-delay: 0s; }
.ai-typing-indicator .typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-indicator .typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
40% { transform: scale(1.1); opacity: 1; }
}
/* Dock de Entrada / Input Pill (Estilo Meli) */
.ai-chat-footer {
background: #ffffff;
border-top: 1px solid rgba(0, 0, 0, 0.06);
position: relative;
z-index: 2;
}
.ai-input-pill-container {
background: #FFFFFF;
border: 1px solid #CBD5E1;
border-radius: 28px;
padding: 6px 8px 6px 12px;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.ai-input-pill-container:focus-within {
border-color: #B43E8E;
box-shadow: 0 0 0 3px rgba(180, 62, 142, 0.15);
}
.ai-input-plus-btn {
width: 28px;
height: 28px;
border-radius: 50%;
border: none;
background: #F1F5F9;
color: #475569;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
font-size: 0.95rem;
flex-shrink: 0;
transition: all 0.15s ease;
}
.ai-input-plus-btn:hover {
background: #E2E8F0;
color: #0F172A;
}
.ai-chat-textarea {
background: transparent !important;
resize: none;
max-height: 80px;
font-size: 0.95rem;
color: #0F172A;
line-height: 1.4;
}
.ai-chat-textarea::placeholder {
color: #94A3B8;
font-size: 0.95rem;
}
.ai-send-btn {
background: transparent;
border: none;
color: #B43E8E;
cursor: pointer;
padding: 0;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
transition: transform 0.15s ease, color 0.15s ease;
}
.ai-send-btn:hover {
color: #8C256B;
transform: scale(1.08);
}
.ai-send-btn:disabled {
color: #CBD5E1;
cursor: not-allowed;
transform: none;
}
/* ==============================================================
TEMA OSCURO ([data-bs-theme="dark"])
============================================================== */
[data-bs-theme="dark"] .ai-chat-panel {
background: #0F172A;
border-color: #334155 !important;
box-shadow: 0 20px 48px rgba(0, 0, 0, 0.6) !important;
}
[data-bs-theme="dark"] .ai-chat-header {
background: #0F172A;
border-bottom-color: #1E293B;
}
[data-bs-theme="dark"] .ai-header-title {
color: #F8FAFC;
}
[data-bs-theme="dark"] .ai-header-subtitle {
color: #94A3B8;
}
[data-bs-theme="dark"] .ai-header-sparkle-badge {
background: rgba(255, 138, 182, 0.18);
color: #FF8AB6;
}
[data-bs-theme="dark"] .ai-btn-circle {
background: #1E293B;
color: #CBD5E1;
}
[data-bs-theme="dark"] .ai-btn-circle:hover {
background: #334155;
color: #F8FAFC;
}
[data-bs-theme="dark"] .ai-chat-disclaimer {
background: #131D31;
border-bottom-color: #1E293B;
}
[data-bs-theme="dark"] .ai-chat-disclaimer small {
color: #94A3B8 !important;
}
[data-bs-theme="dark"] .ai-chat-messages {
background: #0F172A;
}
[data-bs-theme="dark"] .ai-msg-user {
background: #1E293B;
color: #F8FAFC;
}
[data-bs-theme="dark"] .ai-msg-assistant {
color: #F8FAFC;
}
[data-bs-theme="dark"] .ai-action-icon-btn:hover {
color: #F8FAFC;
background: rgba(255, 255, 255, 0.08);
}
[data-bs-theme="dark"] .ai-option-btn {
background: #1E293B;
border-color: #334155;
color: #F8FAFC;
}
[data-bs-theme="dark"] .ai-option-btn:hover {
background: rgba(255, 138, 182, 0.2);
border-color: #FF8AB6;
color: #FF8AB6;
}
[data-bs-theme="dark"] .ai-chat-footer {
background: #0F172A;
border-top-color: #1E293B;
}
[data-bs-theme="dark"] .ai-input-pill-container {
background: #1E293B;
border-color: #334155;
}
[data-bs-theme="dark"] .ai-input-pill-container:focus-within {
border-color: #FF8AB6;
box-shadow: 0 0 0 3px rgba(255, 138, 182, 0.2);
}
[data-bs-theme="dark"] .ai-input-plus-btn {
background: #334155;
color: #CBD5E1;
}
[data-bs-theme="dark"] .ai-input-plus-btn:hover {
background: #475569;
color: #F8FAFC;
}
[data-bs-theme="dark"] .ai-chat-textarea {
color: #F8FAFC;
}
[data-bs-theme="dark"] .ai-send-btn {
color: #FF8AB6;
}
[data-bs-theme="dark"] .ai-send-btn:hover {
color: #FFA5C8;
}
[data-bs-theme="dark"] .ai-sheet-handle {
background: rgba(255, 255, 255, 0.3);
}
/* ==============================================================
UX MÓVIL EXACTA ESTILO MERCADO LIBRE (< 768px):
Bottom Sheet Nativo, Sólido, Sin Desbordes, Acoplado al Teclado
============================================================== */
@media (max-width: 768px) {
.ai-chat-container {
position: static !important;
}
.ai-chat-launcher {
position: fixed !important;
bottom: calc(32px + env(safe-area-inset-bottom, 0px)) !important;
right: calc(26px + env(safe-area-inset-right, 0px)) !important;
width: 56px !important;
height: 56px !important;
z-index: 1060 !important;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32), 0 0 0 2px rgba(255, 255, 255, 0.35) !important;
}
.ai-chat-launcher.chat-open {
display: none !important;
}
/* Bottom Sheet que ocupa casi toda la pantalla (92vh/92dvh) dejando ver el contexto */
.ai-chat-panel {
position: fixed !important;
left: 0 !important;
right: 0 !important;
bottom: 0 !important;
top: auto !important;
width: 100vw !important;
max-width: 100vw !important;
height: 92vh !important;
height: 92dvh !important;
max-height: 92dvh !important;
border-top-left-radius: 28px !important;
border-top-right-radius: 28px !important;
border-bottom-left-radius: 0 !important;
border-bottom-right-radius: 0 !important;
border: none !important;
box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4) !important;
z-index: 1080 !important;
animation: aiSheetSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
overscroll-behavior: contain;
}
@keyframes aiSheetSlideUp {
from { transform: translateY(100%); }
to { transform: translateY(0); }
}
/* Mostrar drag handle bar */
.ai-sheet-handle-bar {
display: block !important;
}
.ai-chat-header {
padding: 0.4rem 1rem 0.6rem !important;
}
.ai-chat-messages {
padding: 0.85rem 1rem !important;
-webkit-overflow-scrolling: touch;
}
.ai-msg {
max-width: 90% !important;
}
/* Dock Inferior móvil anclado */
.ai-chat-footer {
padding: 0.65rem 0.9rem !important;
padding-bottom: max(0.65rem, env(safe-area-inset-bottom, 10px)) !important;
box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
}
.ai-input-pill-container {
padding: 7px 10px 7px 12px !important;
}
.ai-chat-textarea {
font-size: 16px !important; /* Previene auto-zoom molesto en iOS */
}
.ai-send-btn i {
font-size: 1.85rem !important;
}
}
/* Bloqueo de scroll en fondo cuando el Bottom Sheet está abierto */
body.ai-chat-mobile-open {
overflow: hidden !important;
position: fixed;
width: 100%;
height: 100%;
}
</style>
<!-- Script Lógico de UdeCi -->
<script src="/js/ai-chat-widget.js"></script>