/* ==========================================================================
   AVIS - ASISTENTE VIRTUAL PERSONAL DEL STAUAEM
   Manual de Identidad Visual y Paleta de Colores Oficial
   ========================================================================== */

:root {
  /* Paleta Oficial STAUAEM */
  --avis-red-primary: #E31B23;       /* Rojo Insignia STAUAEM */
  --avis-red-ruby: #EF233C;          /* Rojo Rubí Brillante (Glow & Hover) */
  --avis-red-crimson: #B9131A;       /* Rojo Carmesí Oscuro */
  --avis-red-garnet: #8F0E17;        /* Rojo Granate Intenso */
  --avis-red-wine: #66070E;          /* Vino Tinto / Granate */
  --avis-red-burgundy: #4A060C;      /* Borgoña Profundo (Header Chat) */
  --avis-red-deep: #2E0407;          /* Vino Profundo Base */
  --avis-red-coral: #F87171;         /* Rojo Coral / Acento */
  --avis-red-salmon: #FCA5A5;        /* Salmón Suave */
  --avis-red-light: #FEE2E2;         /* Rosa / Acento Claro (Badges & Iconos) */
  --avis-red-border: #FECACA;        /* Borde Rosa Suave */
  --avis-bg-ivory: #FFF5F5;          /* Marfil Rosado (Fondo Chat) */
  
  /* Colores Neutros y Contraste */
  --avis-black-pure: #09090B;        /* Negro Puro */
  --avis-black-carbon: #0F172A;      /* Negro Carbón (Tipografía) */
  --avis-gray-graphite: #1E293B;     /* Gris Grafito */
  --avis-gray-muted: #64748B;        /* Gris Atenuado */
  --avis-white: #FFFFFF;             /* Blanco Puro */

  /* Variables Semánticas del Chat */
  --avis-primary: var(--avis-red-primary);
  --avis-primary-hover: var(--avis-red-ruby);
  --avis-accent: var(--avis-red-crimson);
  --avis-accent-light: var(--avis-red-light);
  --avis-bg-chat: var(--avis-bg-ivory);
  --avis-border: #E2E8F0;
  --avis-border-accent: var(--avis-red-border);
  --avis-shadow: 0 12px 35px -5px rgba(185, 19, 26, 0.28), 0 0 1px 1px rgba(143, 14, 23, 0.08);
  --avis-radius: 20px;

  /* Aliases para compatibilidad */
  --avi-primary: var(--avis-primary);
  --avi-primary-hover: var(--avis-primary-hover);
  --avi-accent: var(--avis-accent);
  --avi-accent-light: var(--avis-accent-light);
  --avi-bg-chat: var(--avis-bg-chat);
  --avi-border: var(--avis-border);
  --avi-shadow: var(--avis-shadow);
  --avi-radius: var(--avis-radius);
}

/* ==========================================================================
   1. LAUNCHER FLOTANTE (BOTÓN FLOTANTE INFERIOR DERECHO)
   ========================================================================== */
.avi-launcher,
.avis-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.avi-launcher:hover,
.avis-launcher:hover {
  transform: scale(1.05);
}

.avi-launcher-btn,
.avis-launcher-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--avis-red-primary) 0%, var(--avis-red-crimson) 100%);
  color: var(--avis-white);
  border: 2.5px solid var(--avis-white);
  box-shadow: 0 8px 24px rgba(227, 27, 35, 0.45), 0 0 0 1px rgba(239, 35, 60, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.55rem;
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.avi-launcher-btn:hover,
.avis-launcher-btn:hover {
  background: linear-gradient(135deg, var(--avis-red-ruby) 0%, var(--avis-red-primary) 100%);
  box-shadow: 0 12px 30px rgba(239, 35, 60, 0.55), 0 0 18px rgba(239, 35, 60, 0.6);
}

.avi-launcher-btn .avi-badge-online,
.avis-launcher-btn .avis-badge-online {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background-color: #22C55E;
  border: 2.5px solid var(--avis-white);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}

.avi-launcher-btn .avi-pulse,
.avis-launcher-btn .avis-pulse {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--avis-red-ruby);
  animation: avisPulse 2.5s infinite;
  pointer-events: none;
  opacity: 0.65;
}

@keyframes avisPulse {
  0% { transform: scale(1); opacity: 0.85; }
  70% { transform: scale(1.45); opacity: 0; }
  100% { transform: scale(1.45); opacity: 0; }
}

/* Tooltip Emergente del Launcher */
.avi-launcher-tooltip,
.avis-launcher-tooltip {
  background: var(--avis-white);
  color: var(--avis-black-carbon);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(74, 6, 12, 0.14);
  border: 1px solid var(--avis-red-border);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: avisBounce 3.2s ease-in-out infinite;
  white-space: nowrap;
}

.avi-launcher-tooltip span.avi-highlight,
.avis-launcher-tooltip span.avis-highlight,
.avi-launcher-tooltip strong.avi-highlight,
.avis-launcher-tooltip strong.avis-highlight {
  color: var(--avis-red-primary);
  font-weight: 700;
}

@keyframes avisBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* ==========================================================================
   2. CONTENEDOR PRINCIPAL DEL CHAT
   ========================================================================== */
.avi-chat-container,
.avis-chat-container {
  position: fixed;
  bottom: 98px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 610px;
  max-height: calc(100vh - 120px);
  background: var(--avis-white);
  border-radius: var(--avis-radius);
  box-shadow: var(--avis-shadow);
  border: 1px solid var(--avis-red-border);
  display: flex;
  flex-direction: column;
  z-index: 10000;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(24px) scale(0.96);
  transition: all 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

.avi-chat-container.active,
.avis-chat-container.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0) scale(1);
}

/* ==========================================================================
   3. HEADER INSTITUCIONAL DEL ASISTENTE
   ========================================================================== */
.avi-chat-header,
.avis-chat-header {
  background: linear-gradient(135deg, var(--avis-red-burgundy) 0%, var(--avis-red-garnet) 45%, var(--avis-red-crimson) 100%);
  color: var(--avis-white);
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2.5px solid var(--avis-red-ruby);
  box-shadow: 0 4px 12px rgba(46, 4, 7, 0.2);
}

.avi-header-left,
.avis-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avi-avatar,
.avis-avatar {
  width: 44px;
  height: 44px;
  background: var(--avis-white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--avis-red-primary);
  font-size: 1.35rem;
  font-weight: 800;
  border: 2px solid var(--avis-red-ruby);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

.avi-header-info h4,
.avis-header-info h4 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--avis-white);
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Montserrat', system-ui, -apple-system, sans-serif;
}

.avi-header-info p,
.avis-header-info p {
  margin: 2px 0 0 0;
  font-size: 0.74rem;
  color: var(--avis-red-salmon);
  display: flex;
  align-items: center;
  gap: 5px;
}

.avi-status-dot,
.avis-status-dot {
  width: 7px;
  height: 7px;
  background: #22C55E;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 5px rgba(34, 197, 94, 0.8);
}

.avi-header-actions,
.avis-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.avi-btn-icon,
.avis-btn-icon {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--avis-white);
  opacity: 0.9;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 7px;
  border-radius: 8px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avi-btn-icon:hover,
.avis-btn-icon:hover {
  opacity: 1;
  background: var(--avis-red-ruby);
  border-color: var(--avis-red-ruby);
  transform: translateY(-1px);
}

/* ==========================================================================
   4. ÁREA DE MENSAJES Y CONVERSACIÓN
   ========================================================================== */
.avi-messages-area,
.avis-messages-area {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background-color: var(--avis-bg-ivory);
  background-image: radial-gradient(var(--avis-red-border) 0.65px, transparent 0.65px);
  background-size: 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Burbujas de Mensaje */
.avi-message,
.avis-message {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: avisFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes avisFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.avi-message.bot,
.avis-message.bot {
  align-self: flex-start;
}

.avi-message.user,
.avis-message.user {
  align-self: flex-end;
}

.avi-bubble,
.avis-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 0.91rem;
  line-height: 1.55;
  word-break: break-word;
}

/* Mensaje del Asistente (Bot) */
.avi-message.bot .avi-bubble,
.avis-message.bot .avis-bubble {
  background: var(--avis-white);
  color: var(--avis-black-carbon);
  border-top-left-radius: 4px;
  box-shadow: 0 3px 10px rgba(74, 6, 12, 0.06);
  border: 1px solid var(--avis-red-border);
}

/* Mensaje del Usuario */
.avi-message.user .avi-bubble,
.avis-message.user .avis-bubble {
  background: linear-gradient(135deg, var(--avis-red-primary) 0%, var(--avis-red-crimson) 100%);
  color: var(--avis-white);
  border-top-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(185, 19, 26, 0.28);
}

.avi-message-time,
.avis-message-time {
  font-size: 0.68rem;
  color: var(--avis-gray-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.avi-message.user .avi-message-time,
.avis-message.user .avis-message-time {
  align-self: flex-end;
  color: var(--avis-red-crimson);
}

/* ==========================================================================
   5. FORMATEO DE CONTENIDO MARKDOWN
   ========================================================================== */
.avi-bubble p,
.avis-bubble p {
  margin: 0 0 8px 0;
}
.avi-bubble p:last-child,
.avis-bubble p:last-child {
  margin-bottom: 0;
}

.avi-bubble ul, .avi-bubble ol,
.avis-bubble ul, .avis-bubble ol {
  margin: 6px 0 8px 18px;
  padding: 0;
}

.avi-bubble li,
.avis-bubble li {
  margin-bottom: 4px;
}

.avi-message.bot .avi-bubble strong,
.avis-message.bot .avis-bubble strong {
  color: var(--avis-red-garnet);
  font-weight: 700;
}

.avi-message.user .avi-bubble strong,
.avis-message.user .avis-bubble strong {
  color: #FFF275;
}

/* Citas y Fuentes Estatutarias */
.avi-sources-tag,
.avis-sources-tag {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--avis-red-border);
  font-size: 0.76rem;
  color: var(--avis-gray-graphite);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.avi-source-badge,
.avis-source-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--avis-red-light);
  color: var(--avis-red-garnet);
  padding: 3px 9px;
  border-radius: 6px;
  font-weight: 600;
  border: 1px solid var(--avis-red-border);
  width: fit-content;
}

/* ==========================================================================
   6. CHIPS DE SUGERENCIAS RÁPIDAS
   ========================================================================== */
.avi-chips-wrapper,
.avis-chips-wrapper {
  padding: 8px 14px 10px;
  display: flex;
  justify-content: center;
  gap: 10px;
  background: var(--avis-bg-ivory);
  border-top: 1px solid var(--avis-red-border);
}

.avi-chip,
.avis-chip {
  flex: 1;
  max-width: 180px;
  background: var(--avis-white);
  border: 1px solid var(--avis-red-border);
  color: var(--avis-red-crimson);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 2px 5px rgba(74, 6, 12, 0.04);
}

.avi-chip i,
.avis-chip i {
  color: var(--avis-red-primary);
  transition: color 0.2s ease;
}

.avi-chip:hover,
.avis-chip:hover {
  background: linear-gradient(135deg, var(--avis-red-primary) 0%, var(--avis-red-crimson) 100%);
  color: var(--avis-white);
  border-color: var(--avis-red-primary);
  box-shadow: 0 4px 10px rgba(227, 27, 35, 0.25);
  transform: translateY(-1px);
}

.avi-chip:hover i,
.avis-chip:hover i {
  color: var(--avis-white);
}

/* ==========================================================================
   7. INDICADOR DE ESTADO "ESCRIBIENDO..."
   ========================================================================== */
.avi-typing,
.avis-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  background: var(--avis-white);
  border-radius: 14px;
  width: fit-content;
  border: 1px solid var(--avis-red-border);
  margin-bottom: 6px;
  box-shadow: 0 2px 6px rgba(74, 6, 12, 0.05);
}

.avi-typing-dot,
.avis-typing-dot {
  width: 6px;
  height: 6px;
  background-color: var(--avis-red-primary);
  border-radius: 50%;
  animation: avisTyping 1.4s infinite ease-in-out both;
}

.avi-typing-dot:nth-child(1),
.avis-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.avi-typing-dot:nth-child(2),
.avis-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes avisTyping {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   8. BARRA DE ENTRADA / FORMULARIO DE TEXTO
   ========================================================================== */
.avi-input-area,
.avis-input-area {
  padding: 12px 14px;
  background: var(--avis-white);
  border-top: 1px solid var(--avis-red-border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.avi-textarea,
.avis-textarea {
  flex: 1;
  border: 1.5px solid var(--avis-red-border);
  border-radius: 14px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  max-height: 90px;
  min-height: 42px;
  resize: none;
  outline: none;
  transition: all 0.2s ease;
  background: var(--avis-bg-ivory);
  color: var(--avis-black-carbon);
}

.avi-textarea:focus,
.avis-textarea:focus {
  border-color: var(--avis-red-primary);
  background: var(--avis-white);
  box-shadow: 0 0 0 3px rgba(227, 27, 35, 0.12);
}

.avi-send-btn,
.avis-send-btn {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--avis-red-primary) 0%, var(--avis-red-crimson) 100%);
  color: var(--avis-white);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(227, 27, 35, 0.25);
}

.avi-send-btn:hover:not(:disabled),
.avis-send-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--avis-red-ruby) 0%, var(--avis-red-primary) 100%);
  box-shadow: 0 6px 14px rgba(239, 35, 60, 0.4);
  transform: translateY(-1px);
}

.avi-send-btn:disabled,
.avis-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.avi-footer-disclaimer,
.avis-footer-disclaimer {
  font-size: 0.67rem;
  text-align: center;
  color: var(--avis-gray-muted);
  padding: 4px 10px 8px;
  background: var(--avis-white);
  border-top: 1px solid rgba(254, 202, 202, 0.3);
}

/* ==========================================================================
   9. RESPONSIVIDAD PARA DISPOSITIVOS MÓVILES
   ========================================================================== */
@media (max-width: 480px) {
  .avi-launcher,
  .avis-launcher {
    bottom: 16px;
    right: 16px;
  }
  .avi-launcher-tooltip,
  .avis-launcher-tooltip {
    display: none;
  }
  .avi-chat-container,
  .avis-chat-container {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
}
