/* avatar.css - Estilos para el Avatar Virtual Interactivo */

:root {
  --avatar-primary: #007bff; /* Puede ajustarse a los colores de Luz de Vida */
  --avatar-bg-chat: rgba(255, 255, 255, 0.85);
  --avatar-border: rgba(200, 200, 200, 0.3);
  --avatar-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

/* Contenedor principal - No bloquea clics detrás, salvo sus hijos directos si lo necesitan */
#avatar-container {
  position: fixed;
  bottom: 20px;
  left: 20px; /* Separado del borde izquierdo */
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-start; /* Alinear de lado izquierdo */
  pointer-events: none; /* Deja pasar clics a lo que haya detrás */
  transition: bottom 1s ease, left 1s ease, transform 1s ease;
}

/* Efecto de antigravedad para la imagen del avatar */
#avatar-image-wrapper {
  position: relative;
  height: 180px; /* Limit height to prevent huge sizes */
  width: auto;
  cursor: pointer;
  pointer-events: auto; /* El avatar sí es clickeable */
  animation: float 4s ease-in-out infinite;
  display: flex;
  justify-content: center;
  align-items: flex-end; /* Alinear abajo para que no flote extrañamente */
}

#avatar-image-wrapper img {
  height: 100%;
  width: auto;
  object-fit: contain;
  transition: transform 0.3s ease, filter 0.3s ease;
  filter: drop-shadow(0px 10px 15px rgba(0,0,0,0.2));
}

#avatar-image-wrapper:hover img {
  transform: scale(1.05);
}

#avatar-img.talking {
  animation: talk-bob 1s infinite ease-in-out;
}
#avatar-img.thinking {
  animation: think-tilt 2s infinite ease-in-out;
  filter: brightness(1.1) drop-shadow(0px 10px 15px rgba(0,0,0,0.2));
}

@keyframes talk-bob {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04) translateY(-2px); }
}

@keyframes think-tilt {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-4deg) translateY(-2px); }
}

@keyframes float {
  0% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-15px) rotate(1deg); }
  100% { transform: translateY(0px) rotate(0deg); }
}

/* Globo de texto (Tooltip/Bubble) */
#avatar-bubble {
  position: absolute;
  bottom: 100%; /* Arriba de la enfermera */
  left: 50%;
  transform: translateX(-20%) translateY(10px);
  background-color: #fff;
  border-radius: 12px 12px 12px 0; /* Estilo cómic */
  padding: 12px 16px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: #333;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, transform 0.5s ease, visibility 0.5s;
  max-width: 250px;
  text-align: center;
  border: 1px solid #eee;
  z-index: 10;
}

#avatar-bubble::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 20px;
  border-width: 10px 10px 0 0;
  border-style: solid;
  border-color: #fff transparent transparent transparent;
}

#avatar-bubble.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-20%) translateY(-10px);
}

/* Ventana de Chat Flotante */
#avatar-chat-window {
  width: 320px;
  height: 400px;
  max-height: 55vh; /* Asegurar que no exceda el alto de pantalla */
  background: var(--avatar-bg-chat);
  backdrop-filter: blur(10px); /* Glassmorphism */
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--avatar-border);
  box-shadow: var(--avatar-shadow);
  border-radius: 16px;
  margin-bottom: 15px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  opacity: 0;
  transform: scale(0.9) translateY(20px);
  transform-origin: bottom left;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  visibility: hidden;
}

#avatar-chat-window.open {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
}

.chat-header {
  background: linear-gradient(135deg, #1b8bd4, #125c8f); /* Azul médico */
  color: white;
  padding: 15px;
  font-family: system-ui, sans-serif;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header span {
  font-size: 16px;
}

.close-chat {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

.chat-body {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-family: system-ui, sans-serif;
  font-size: 14.5px;
}

/* Scrollbar styling */
.chat-body::-webkit-scrollbar {
  width: 6px;
}
.chat-body::-webkit-scrollbar-track {
  background: transparent;
}
.chat-body::-webkit-scrollbar-thumb {
  background-color: rgba(0,0,0,0.2);
  border-radius: 10px;
}

.chat-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-message.bot {
  background-color: #f1f3f5;
  color: #333;
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

.chat-message.user {
  background-color: #1b8bd4;
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.chat-footer {
  padding: 10px 15px;
  border-top: 1px solid rgba(0,0,0,0.05);
  display: flex;
  gap: 8px;
  background-color: #fff;
}

.chat-input {
  flex: 1;
  padding: 10px 15px;
  border: 1px solid #ddd;
  border-radius: 20px;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: #1b8bd4;
}

.chat-send {
  background-color: #1b8bd4;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 0.2s;
}

.chat-send:hover {
  background-color: #125c8f;
}

.chat-send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  margin-left: 2px;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background-color: #f1f3f5;
  border-radius: 12px;
  align-self: flex-start;
  border-bottom-left-radius: 2px;
  display: none; /* Oculto por defecto */
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background-color: #888;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

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

/* Responsividad para móviles */
@media (max-width: 768px) {
  #avatar-image-wrapper {
    height: 120px; /* Avatar más pequeño en móviles */
  }
  
  #avatar-chat-window {
    width: calc(100vw - 40px);
    height: 350px;
    margin-bottom: 10px;
  }

  #avatar-bubble {
    max-width: 200px;
    font-size: 12px;
    transform: translateX(10%) translateY(10px);
  }
  #avatar-bubble.visible {
    transform: translateX(10%) translateY(-10px);
  }
}

/* Posiciones dinámicas (solo en desktop) */
@media (min-width: 769px) {
  #avatar-container.pos-center {
    transform: translateY(-30vh);
  }
  #avatar-container.pos-top {
    transform: translateY(-55vh);
  }
}

/* Botón de Acción WhatsApp */
.wa-action-btn {
  display: inline-flex;
  align-items: center;
  background-color: #25D366;
  color: #fff !important;
  padding: 10px 14px;
  border-radius: 8px;
  text-decoration: none !important;
  font-weight: 600;
  margin-top: 5px;
  font-size: 14px;
  transition: background-color 0.2s, transform 0.1s;
  box-shadow: 0 4px 6px rgba(37, 211, 102, 0.3);
}

.wa-action-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  margin-right: 8px;
}

.wa-action-btn:hover {
  background-color: #1ebe57;
  transform: translateY(-1px);
}
