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

399 lines
13 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 FLOTANTE: UdeCi - TUTOR VIRTUAL UNICABA -->
<!-- SDD-010: Arquitectura RAG y Asistencia Contextual -->
<!-- ===================================================== -->
<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 UdeCi" title="UdeCi - Tutor Virtual UniCABA">
<span class="ai-launcher-icon"><i class="bi bi-chat-heart-fill"></i></span>
<span class="ai-launcher-badge pulse-dot"></span>
</button>
<!-- Panel de Conversación -->
<div id="aiChatPanel" class="ai-chat-panel card shadow-lg border-0 d-none" role="dialog" aria-modal="true" aria-labelledby="aiChatTitle">
<!-- Cabecera Limpia e Institucional de UdeCi -->
<div class="card-header ai-chat-header d-flex align-items-center justify-content-between p-3 border-bottom">
<div class="d-flex align-items-center gap-2 overflow-hidden">
<div class="ai-avatar-circle">
<i class="bi bi-mortarboard-fill text-white"></i>
</div>
<div class="lh-sm text-truncate">
<div class="d-flex align-items-center gap-2">
<h6 class="mb-0 fw-bold text-white" id="aiChatTitle">UdeCi</h6>
<span class="badge bg-white text-primary fw-semibold rounded-pill px-2 py-0" style="font-size: 0.68rem;">Tutor Virtual</span>
</div>
<small class="text-white-50 d-flex align-items-center gap-1 mt-1" style="font-size: 0.73rem;">
<span class="status-indicator-dot"></span>
<span>UniCABA &bull; En línea</span>
</small>
</div>
</div>
<div class="d-flex align-items-center gap-1">
<button type="button" class="btn btn-sm btn-outline-light border-0 py-1 px-2" id="aiChatClearBtn" title="Reiniciar chat">
<i class="bi bi-arrow-clockwise"></i>
</button>
<button type="button" class="btn btn-sm btn-outline-light border-0 py-1 px-2" id="aiChatCloseBtn" title="Cerrar">
<i class="bi bi-x-lg"></i>
</button>
</div>
</div>
<!-- Área de Mensajes -->
<div class="card-body ai-chat-messages p-3" id="aiChatMessages" tabindex="0">
<!-- Mensaje de bienvenida inicial y conversación -->
</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>
<!-- Área de Entrada / Envío -->
<div class="card-footer ai-chat-footer p-2 border-top">
<form id="aiChatForm" class="d-flex align-items-center gap-2 m-0" onsubmit="handleAiChatSubmit(event)">
<textarea id="aiChatInput" class="form-control form-control-sm ai-chat-textarea"
rows="1"
placeholder="Escribe tu consulta aquí..."
aria-label="Mensaje para UdeCi"></textarea>
<button type="submit" class="btn btn-primary btn-sm rounded-circle ai-send-btn" id="aiChatSendBtn" title="Enviar consulta">
<i class="bi bi-send-fill"></i>
</button>
</form>
</div>
</div>
</div>
<style>
/* Contenedor Flotante */
.ai-chat-container {
position: fixed;
bottom: 24px;
right: 24px;
z-index: 1060;
font-family: inherit;
}
/* Botón Lanzador */
.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.55rem;
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 */
.ai-chat-panel {
width: 380px;
max-width: calc(100vw - 32px);
height: 520px;
max-height: calc(100vh - 90px);
border-radius: 18px !important;
overflow: hidden;
display: flex;
flex-direction: column;
animation: aiSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45) !important;
backdrop-filter: none !important;
-webkit-backdrop-filter: none !important;
opacity: 1 !important;
}
@keyframes aiSlideUp {
from { opacity: 0; transform: translateY(16px) scale(0.97); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
/* Modo Oscuro 100% Sólido y Opaco (Cero Transparencia) */
[data-bs-theme="dark"] .ai-chat-panel,
[data-bs-theme="dark"] #aiChatPanel {
background-color: #0f172a !important;
background: #0f172a !important;
border: 1px solid #334155 !important;
opacity: 1 !important;
}
[data-bs-theme="dark"] .ai-chat-header {
background-color: #1e293b !important;
background: #1e293b !important;
border-bottom: 1px solid #334155 !important;
}
[data-bs-theme="dark"] .ai-chat-messages,
[data-bs-theme="dark"] #aiChatMessages {
background-color: #0f172a !important;
background: #0f172a !important;
opacity: 1 !important;
}
[data-bs-theme="dark"] .ai-chat-footer {
background-color: #1e293b !important;
background: #1e293b !important;
border-top: 1px solid #334155 !important;
}
[data-bs-theme="dark"] .ai-chat-textarea {
background-color: #0f172a !important;
color: #f8fafc !important;
border: 1px solid #475569 !important;
}
/* Modo Claro 100% Sólido y Opaco */
[data-bs-theme="light"] .ai-chat-panel,
[data-bs-theme="light"] #aiChatPanel {
background-color: #ffffff !important;
background: #ffffff !important;
border: 1px solid rgba(180, 62, 142, 0.25) !important;
opacity: 1 !important;
}
[data-bs-theme="light"] .ai-chat-header {
background: linear-gradient(135deg, #B43E8E 0%, #8A256B 100%) !important;
border-bottom: 1px solid rgba(180, 62, 142, 0.2) !important;
}
[data-bs-theme="light"] .ai-chat-messages,
[data-bs-theme="light"] #aiChatMessages {
background-color: #FAF5F8 !important;
background: #FAF5F8 !important;
opacity: 1 !important;
}
[data-bs-theme="light"] .ai-chat-footer {
background-color: #ffffff !important;
background: #ffffff !important;
border-top: 1px solid rgba(180, 62, 142, 0.2) !important;
}
[data-bs-theme="light"] .ai-chat-textarea {
background-color: #ffffff !important;
color: #1e293b !important;
border: 1px solid #cbd5e1 !important;
}
.ai-avatar-circle {
width: 36px;
height: 36px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.25);
display: flex;
align-items: center;
justify-content: center;
font-size: 1.15rem;
}
.status-indicator-dot {
display: inline-block;
width: 7px;
height: 7px;
background-color: #22c55e;
border-radius: 50%;
}
/* Mensajes */
.ai-chat-messages {
flex: 1 1 auto;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 10px;
scroll-behavior: smooth;
}
.ai-msg {
max-width: 86%;
padding: 9px 13px;
border-radius: 14px;
font-size: 0.86rem;
line-height: 1.45;
word-break: break-word;
}
.ai-msg-user {
align-self: flex-end;
background-color: #0d6efd;
color: #ffffff;
border-bottom-right-radius: 3px;
}
.ai-msg-assistant {
align-self: flex-start;
border-bottom-left-radius: 3px;
}
[data-bs-theme="dark"] .ai-msg-assistant {
background-color: #1e293b;
color: #f8fafc;
border: 1px solid #334155;
}
[data-bs-theme="light"] .ai-msg-assistant {
background-color: #f8fafc;
color: #0f172a;
border: 1px solid #e2e8f0;
}
/* Botones de sugerencias debajo de la respuesta */
.ai-msg-options {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 8px;
}
.ai-option-btn {
font-size: 0.74rem;
padding: 3px 9px;
border-radius: 12px;
background-color: rgba(13, 110, 253, 0.08);
border: 1px solid rgba(13, 110, 253, 0.25);
color: #0d6efd;
cursor: pointer;
transition: all 0.15s ease;
}
[data-bs-theme="dark"] .ai-option-btn {
background-color: rgba(56, 189, 248, 0.1);
border-color: rgba(56, 189, 248, 0.3);
color: #38bdf8;
}
.ai-option-btn:hover {
background-color: #0d6efd;
color: #ffffff;
border-color: #0d6efd;
transform: translateY(-1px);
}
[data-bs-theme="dark"] .ai-option-btn:hover {
background-color: #38bdf8;
color: #0f172a;
border-color: #38bdf8;
}
/* 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; }
}
/* Textarea y Botón */
.ai-chat-textarea {
resize: none;
border-radius: 18px;
padding-left: 12px;
padding-right: 12px;
max-height: 75px;
}
.ai-send-btn {
width: 36px;
height: 36px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
@media (max-width: 768px) {
.ai-chat-container {
bottom: 16px;
right: 16px;
z-index: 1070;
}
.ai-chat-launcher {
width: 52px;
height: 52px;
}
.ai-chat-launcher.chat-open {
display: none !important;
}
.ai-chat-panel {
position: fixed !important;
top: 0 !important;
left: 0 !important;
right: 0 !important;
bottom: 0 !important;
width: 100vw !important;
max-width: 100vw !important;
height: 100dvh !important;
max-height: 100dvh !important;
border-radius: 0 !important;
z-index: 1080 !important;
box-shadow: none !important;
border: none !important;
}
.ai-chat-header {
border-radius: 0 !important;
padding: 0.75rem 1rem !important;
}
.ai-chat-messages {
padding: 0.85rem !important;
-webkit-overflow-scrolling: touch;
}
.ai-msg {
max-width: 90% !important;
font-size: 0.88rem !important;
}
.ai-option-btn {
font-size: 0.78rem !important;
padding: 6px 12px !important;
min-height: 32px;
}
.ai-chat-footer {
padding: 0.65rem 0.85rem !important;
padding-bottom: max(0.65rem, env(safe-area-inset-bottom, 0px)) !important;
}
.ai-chat-textarea {
font-size: 16px !important; /* Previene el auto-zoom involuntario en Safari iOS */
padding: 8px 12px !important;
}
}
body.ai-chat-mobile-open {
overflow: hidden !important;
touch-action: none;
}
</style>
<!-- Script Lógico de UdeCi -->
<script src="/js/ai-chat-widget.js"></script>