/* ========================================
   IMPORTACIONES Y VARIABLES CSS
   ======================================== */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100;400;900&display=swap');

:root {
  --primary-color: #007bff;
  --primary-dark: #0056b3;
  --primary-light: rgba(0, 123, 255, 0.1);
  --secondary-color: #6c757d;
  --success-color: #28a745;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --light-color: #f8f9fa;
  --dark-color: #343a40;
  --navbar-bg: #353535;
  --chat-border-radius: 15px;
  --message-border-radius: 15px;
  --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  --transition: all 0.3s ease;
  --font-family: 'Roboto', Arial, Helvetica, sans-serif;
}

/* ========================================
   ESTILOS BASE
   ======================================== */
body {
  background-color: var(--light-color);
  font-family: var(--font-family);
  overflow: hidden;
}

/* ========================================
   NAVEGACIÓN
   ======================================== */
.navbar {
  background: var(--navbar-bg);
}

/* ========================================
   CONTENEDOR DE CHAT
   ======================================== */
#chat-container {
  box-shadow: var(--box-shadow);
  border-radius: var(--chat-border-radius);
  overflow: hidden;
}

.chat-body {
  height: 65vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 123, 255, 0.3) transparent;
  padding: 1.5rem;
  scroll-behavior: auto;
}

/* Webkit scrollbar personalizado */
.chat-body::-webkit-scrollbar {
  width: 6px;
}

.chat-body::-webkit-scrollbar-track {
  background: transparent;
}

.chat-body::-webkit-scrollbar-thumb {
  background: rgba(0, 123, 255, 0.3);
  border-radius: 3px;
  transition: background 0.2s ease;
}

.chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 123, 255, 0.5);
}

/* ========================================
   AVATARES
   ======================================== */
.user-avatar,
.assistant-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========================================
   MENSAJES
   ======================================== */
.message-container {
  max-width: 80%;
  animation: slide-in 0.3s ease-out;
  will-change: transform;
}

.user-message {
  background-color: var(--primary-color);
  color: white;
  border-radius: var(--message-border-radius) var(--message-border-radius) 0 var(--message-border-radius);
  padding: 10px 15px;
  transition: var(--transition);
}

.assistant-message {
  background-color: #e9ecef;
  color: #212529;
  border-radius: var(--message-border-radius) var(--message-border-radius) var(--message-border-radius) 0;
  padding: 10px 15px;
  transition: var(--transition);
}

/* ========================================
   STREAMING Y ANIMACIONES
   ======================================== */
.streaming-message {
  border-left: 3px solid var(--primary-color);
  background: linear-gradient(90deg, rgba(0, 123, 255, 0.03) 0%, rgba(0, 123, 255, 0.01) 100%);
  position: relative;
  transition: var(--transition);
  min-height: 20px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.streaming-message::before {
  content: '';
  position: absolute;
  top: 0;
  left: -3px;
  width: 3px;
  height: 100%;
  background: linear-gradient(180deg, var(--primary-color) 0%, rgba(0, 123, 255, 0.3) 50%, transparent 100%);
  animation: gentle-pulse 2s infinite ease-in-out;
  will-change: transform, opacity;
}

.streaming-cursor {
  animation: smooth-blink 1.5s infinite ease-in-out;
  color: var(--primary-color);
  font-weight: bold;
  display: inline-block;
  margin-left: 2px;
  will-change: opacity, transform;
}

.message-completed {
  animation: message-completion 0.5s ease-out;
}

.streaming-message code {
  background-color: rgba(0, 123, 255, 0.08);
  padding: 1px 3px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  transition: background-color 0.2s ease;
}

.streaming-message pre {
  background-color: rgba(0, 123, 255, 0.03);
  border: 1px solid rgba(0, 123, 255, 0.15);
  border-radius: 5px;
  padding: 8px;
  margin: 3px 0;
  white-space: pre-wrap;
  overflow-x: auto;
  transition: var(--transition);
}

/* ========================================
   CONTROLES DE ENTRADA
   ======================================== */
textarea.form-control {
  resize: none;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  max-height: 100px;
  min-height: 38px;
}

textarea.form-control:disabled {
  background-color: var(--light-color);
  border-color: #e9ecef;
  color: var(--secondary-color);
  cursor: not-allowed;
}

#send-button {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ========================================
   INDICADORES Y ELEMENTOS ESPECIALES
   ======================================== */
.typing-indicator {
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: opacity 0.3s ease-in-out;
}

.file-reference {
  background-color: var(--primary-light);
  border-radius: 3px;
  padding: 1px 3px;
}

.btn.view-file-btn {
  gap: 1px;
  color: var(--primary-color);
  padding: 0;
  word-break: break-all;
}

.btn.view-file-btn:hover {
  color: var(--danger-color);
}

.error-message {
  background-color: #f8d7da !important;
  border-left: 3px solid var(--danger-color) !important;
  color: #721c24 !important;
}

/* ========================================
   VISORES DE ARCHIVOS
   ======================================== */
.pdf-container {
  min-height: 75vh;
  background-color: var(--light-color);
  border: 1px solid #ddd;
}

#pdfViewerFrame {
  width: 100%;
  height: 100%;
  border: none;
}

#txtContent {
  font-family: 'Courier New', monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

#visorPDF pre {
  height: 100%;
  white-space: pre-wrap;
  overflow-y: auto;
  margin: 0;
  padding: 1rem;
  background-color: var(--light-color);
  font-family: Consolas, monospace;
  font-size: 0.9rem;
}

/* ========================================
   GESTIÓN DOCUMENTAL
   ======================================== */
.document-item {
  cursor: pointer;
  transition: background-color 0.2s;
  padding: 12px 8px;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.document-item:hover {
  background-color: var(--primary-light);
}

.document-name {
  cursor: pointer;
  color: var(--primary-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
}

.document-name:hover {
  text-decoration: underline;
}

/* ========================================
   ESTADO INICIAL
   ======================================== */
#initial-state {
  min-height: 55vh;
  animation: fadeIn 0.5s ease-in-out;
}

#initial-state .fa-robot {
  color: var(--primary-color);
  text-shadow: 0 2px 4px rgba(0, 123, 255, 0.2);
}

.btn-module {
  min-width: 120px;
  height: 60px;
  border: 2px solid var(--primary-color);
  border-radius: 10px;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 5px;
}

.btn-module:hover {
  background-color: var(--primary-color);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.btn-module:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 123, 255, 0.3);
}

.btn-module:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  box-shadow: 0 0 0 0.25rem rgba(0, 123, 255, 0.25);
}

.btn-module i {
  font-size: 1.2rem;
}

.btn-module:nth-child(odd) {
  animation: gentle-bounce 2s ease-in-out 3s infinite;
}

.btn-module:nth-child(even) {
  animation: gentle-bounce 2s ease-in-out 3.5s infinite;
}

.btn-module:hover {
  animation-play-state: paused;
}

/* ========================================
   HEADERS Y TRANSICIONES
   ======================================== */
.header-no-assistant {
  background: linear-gradient(135deg, var(--secondary-color) 0%, #495057 100%);
}

.header-with-assistant {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  transition: background 0.5s ease;
}

.assistant-activation {
  animation: activateAssistant 0.6s ease-out;
}

/* ========================================
   ANIMACIONES
   ======================================== */
@keyframes fadeIn {
  0% { 
    opacity: 0; 
    transform: translateY(20px); 
  }
  100% { 
    opacity: 1; 
    transform: translateY(0); 
  }
}

@keyframes slide-in {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes gentle-pulse {
  0%, 100% { 
    opacity: 0.6;
    transform: scaleY(1);
  }
  50% { 
    opacity: 1;
    transform: scaleY(1.02);
  }
}

@keyframes smooth-blink {
  0%, 45% { opacity: 1; transform: scale(1); }
  50%, 95% { opacity: 0.3; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes message-completion {
  0% {
    transform: translateY(2px);
    opacity: 0.9;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes gentle-bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-5px);
  }
  60% {
    transform: translateY(-3px);
  }
}

@keyframes activateAssistant {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(0.95);
  }
  100% {
    opacity: 0;
    transform: scale(0.9);
  }
}

@keyframes simple-blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.3; }
}

/* ========================================
   RESPONSIVE DESIGN - TABLETS
   ======================================== */
@media (max-width: 992px) {
  .chat-body {
    padding: 1rem;
  }
  
  .message-container {
    max-width: 85%;
  }
  
  .btn-module {
    min-width: 100px;
    height: 55px;
    font-size: 0.9rem;
  }
  
  .btn-module i {
    font-size: 1.1rem;
  }
}

@media (max-width: 768px) {
  /* Ocultar opciones de menú en móviles */
  #manage-documents-btn,
  #new-scorm {
    display: none !important;
  }
  
  #chat-container {
    border-radius: 10px;
  }
  
  .chat-body {
    height: 70vh;
    padding: 0.8rem;
  }
  
  .user-avatar, .assistant-avatar {
    width: 35px;
    height: 35px;
    font-size: 0.9rem;
  }
  
  .message-container {
    max-width: 90%;
  }
  
  .user-message, .assistant-message {
    padding: 8px 12px;
    font-size: 0.95rem;
  }
  
  .document-name {
    font-size: 0.85rem;
  }
  
  .pdf-container {
    min-height: 70vh;
  }
  
  #initial-state {
    min-height: 70vh;
    padding: 1rem;
  }
  
  .btn-module {
    min-width: 90px;
    height: 50px;
    font-size: 0.85rem;
    gap: 2px;
  }
  
  .btn-module i {
    font-size: 1rem;
  }
  
  #initial-state .fa-robot {
    font-size: 3rem !important;
  }
  
  #initial-state h4 {
    font-size: 1.3rem;
  }
  
  #initial-state p {
    font-size: 0.9rem;
  }
}

/* ========================================
   RESPONSIVE DESIGN - MÓVILES
   ======================================== */
@media (max-width: 576px) {
  body {
    font-size: 14px;
  }
  
  #chat-container {
    border-radius: 8px;
    margin: 0.5rem;
  }
  
  .chat-body {
    height: 75vh;
    padding: 0.5rem;
  }
  
  .user-avatar, .assistant-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.8rem;
  }
  
  .message-container {
    max-width: 95%;
  }
  
  .user-message {
    padding: 6px 10px;
    font-size: 0.9rem;
    border-radius: 12px 12px 2px 12px;
  }
  
  .assistant-message {
    padding: 6px 10px;
    font-size: 0.9rem;
    border-radius: 12px 12px 12px 2px;
  }
  
  textarea.form-control {
    min-height: 44px;
    font-size: 16px;
    padding: 10px 12px;
  }
  
  #send-button {
    min-height: 44px;
    padding: 0 15px;
  }
  
  .btn.view-file-btn {
    font-size: 0.8rem;
    padding: 2px 4px;
  }
  
  .document-name {
    font-size: 0.8rem;
  }
  
  .typing-indicator {
    padding: 8px;
    gap: 3px;
  }
  
  .pdf-container {
    min-height: 65vh;
  }
  
  #visorPDF pre {
    padding: 0.5rem;
    font-size: 0.8rem;
  }
  
  .streaming-message::before {
    width: 2px;
    left: -2px;
  }
  
  .streaming-message {
    border-left-width: 2px;
  }
  
  .streaming-cursor {
    font-size: 0.8rem;
  }
  
  #initial-state {
    min-height: 75vh;
    padding: 0.5rem;
  }
  
  .btn-module {
    min-width: 80px;
    height: 45px;
    font-size: 0.75rem;
    margin: 2px;
    border-radius: 8px;
  }
  
  .btn-module i {
    font-size: 0.9rem;
  }
  
  #initial-state .fa-robot {
    font-size: 2.5rem !important;
    margin-bottom: 1rem !important;
  }
  
  #initial-state h4 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
  }
  
  #initial-state p {
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
  }
  
  #initial-state .row {
    justify-content: center;
  }
  
  #initial-state .col-auto {
    flex: 0 0 auto;
    margin: 2px;
  }
}

/* ========================================
   RESPONSIVE DESIGN - MÓVILES PEQUEÑOS
   ======================================== */
@media (max-width: 375px) {
  #chat-container {
    margin: 0.25rem;
    border-radius: 6px;
  }
  
  .chat-body {
    padding: 0.25rem;
    height: 78vh;
  }
  
  .user-avatar, .assistant-avatar {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
  }
  
  .user-message, .assistant-message {
    padding: 5px 8px;
    font-size: 0.85rem;
  }
  
  .user-message {
    border-radius: 10px 10px 2px 10px;
  }
  
  .assistant-message {
    border-radius: 10px 10px 10px 2px;
  }
  
  .document-name {
    font-size: 0.75rem;
  }
  
  #visorPDF pre {
    font-size: 0.75rem;
    padding: 0.25rem;
  }
  
  #initial-state {
    padding: 0.25rem;
  }
  
  .btn-module {
    min-width: 70px;
    height: 40px;
    font-size: 0.7rem;
    border-radius: 6px;
  }
  
  .btn-module i {
    font-size: 0.8rem;
  }
  
  #initial-state .fa-robot {
    font-size: 2rem !important;
  }
  
  #initial-state h4 {
    font-size: 1rem;
  }
  
  #initial-state p {
    font-size: 0.8rem;
  }
  
  #initial-state small {
    font-size: 0.7rem;
  }
}

/* ========================================
   LANDSCAPE MODE
   ======================================== */
@media (max-height: 500px) and (orientation: landscape) {
  .chat-body {
    height: 60vh;
  }
  
  .pdf-container {
    min-height: 55vh;
  }
  
  .user-avatar, .assistant-avatar {
    width: 25px;
    height: 25px;
    font-size: 0.7rem;
  }
  
  .user-message, .assistant-message {
    padding: 4px 8px;
    font-size: 0.8rem;
  }
  
  #initial-state {
    min-height: 60vh;
    padding: 0.5rem;
  }
  
  #initial-state .fa-robot {
    font-size: 2rem !important;
    margin-bottom: 0.5rem !important;
  }
  
  #initial-state h4 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
  }
  
  #initial-state p {
    font-size: 0.8rem;
    margin-bottom: 1rem;
  }
  
  .btn-module {
    min-width: 70px;
    height: 35px;
    font-size: 0.7rem;
  }
}

/* ========================================
   ACCESIBILIDAD Y PREFERENCIAS
   ======================================== */
@media (hover: none) and (pointer: coarse) {
  .document-item:hover {
    background-color: transparent;
  }
  
  .document-item:active {
    background-color: var(--primary-light);
  }
  
  .btn.view-file-btn:hover {
    color: var(--primary-color);
  }
  
  .btn.view-file-btn:active {
    color: var(--danger-color);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .streaming-message::before,
  .streaming-cursor,
  .message-container {
    animation: none;
  }
  
  .assistant-message, .user-message,
  .streaming-message, #typing-indicator {
    transition: none;
  }
  
  #initial-state {
    animation: none;
  }
  
  .btn-module {
    transition: none;
  }
  
  .btn-module:hover {
    transform: none;
  }
  
  .streaming-cursor {
    animation: simple-blink 2s infinite;
  }
}

@media (prefers-contrast: high) {
  .streaming-message {
    border-left-color: var(--primary-dark);
    background: rgba(0, 86, 179, 0.1);
  }
  
  .streaming-cursor {
    color: var(--primary-dark);
  }
  
  .btn-module {
    border-width: 3px;
    border-color: var(--primary-dark);
  }
  
  .btn-module:hover {
    background-color: var(--primary-dark);
    border-color: #004085;
  }
  
  #initial-state .fa-robot {
    color: var(--primary-dark);
  }
}

@media (prefers-color-scheme: dark) {
  .streaming-message {
    background: linear-gradient(90deg, rgba(100, 200, 255, 0.05) 0%, rgba(100, 200, 255, 0.01) 100%);
    border-left-color: #64c8ff;
  }
  
  .streaming-cursor {
    color: #64c8ff;
  }
}