/* ==========================================================================
   AstroChungungo IA - Asistente Flotante Cósmico
   Mascota: Chungungo Astronauta 🦦🚀
   ========================================================================== */

/* Capa del Avatar Flotante (Por detrás de los elementos: z-index: 1) */
.chungungo-avatar-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 76px;
  height: 76px;
  z-index: 1; /* Por detrás de las secciones (.section tiene z-index: 2) */
  pointer-events: auto;
  user-select: none;
  touch-action: none;
  will-change: transform;
  cursor: grab;
  transition: filter 0.3s ease;
}

/* Cuando se coloca al frente opcionalmente */
.chungungo-avatar-layer.in-front {
  z-index: 9999;
}

/* Estado de Arrastre por el Usuario */
.chungungo-avatar-layer.dragging {
  cursor: grabbing !important;
  filter: drop-shadow(0 0 25px rgba(56, 189, 248, 0.8)) !important;
  transition: none !important;
}

/* Botón Circular del Chungungo */
.chungungo-btn {
  position: relative;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: grab;
  padding: 0;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.chungungo-avatar-layer.dragging .chungungo-btn {
  cursor: grabbing !important;
}

/* Halo orbital giratorio */
.chungungo-halo {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #38bdf8, #a855f7, #10b981, #f59e0b, #38bdf8);
  animation: halo-spin 5s linear infinite;
  filter: blur(2px);
  opacity: 0.9;
  z-index: 1;
}

/* Pulso Cósmico de Gravedad Cero */
.chungungo-pulse {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid rgba(56, 189, 248, 0.6);
  animation: chungungo-pulse-wave 2.2s ease-out infinite;
  z-index: 0;
  pointer-events: none;
}

/* Estela Cósmica de Navegación */
.chungungo-thruster-glow {
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.85) 0%, rgba(168, 85, 247, 0.4) 60%, transparent 100%);
  bottom: -6px;
  left: 24px;
  filter: blur(4px);
  z-index: 1;
  animation: thruster-flare 1.2s ease-in-out infinite alternate;
  pointer-events: none;
}

/* Imagen del Chungungo Astronauta */
.chungungo-avatar-img {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  object-fit: cover;
  border: 2.5px solid #0f172a;
  z-index: 2;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.65);
  background: #0f172a;
  pointer-events: none;
}

/* Badge de estado en línea */
.chungungo-status-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: #10b981;
  border: 2.5px solid #0f172a;
  border-radius: 50%;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.chungungo-status-badge::after {
  content: '';
  width: 6px;
  height: 6px;
  background: #ffffff;
  border-radius: 50%;
  animation: status-blink 2s ease-in-out infinite;
}

/* Tooltip / Indicador de que se puede arrastrar */
.chungungo-drag-hint {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 9999px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 4;
}

.chungungo-avatar-layer:hover .chungungo-drag-hint {
  opacity: 1;
}

/* Burbuja Flotante de Bienvenida / Tooltip */
.chungungo-speech-bubble {
  position: fixed;
  z-index: 9998;
  max-width: 290px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(139, 92, 246, 0.5);
  border-radius: 18px;
  padding: 12px 16px;
  box-shadow: 0 15px 35px -8px rgba(0, 0, 0, 0.75),
              0 0 25px rgba(139, 92, 246, 0.3);
  color: #f8fafc;
  font-size: 0.88rem;
  line-height: 1.45;
  cursor: pointer;
  transition: opacity 0.3s ease, transform 0.3s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  pointer-events: auto;
}

.chungungo-speech-bubble:hover {
  transform: translateY(-3px) scale(1.02);
  border-color: rgba(56, 189, 248, 0.7);
  box-shadow: 0 18px 40px -6px rgba(0, 0, 0, 0.8),
              0 0 30px rgba(56, 189, 248, 0.4);
}

.chungungo-speech-bubble.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.95);
  visibility: hidden;
}

.chungungo-speech-text strong {
  color: #38bdf8;
  display: block;
  font-size: 0.92rem;
  margin-bottom: 2px;
}

.chungungo-speech-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.2s;
}

.chungungo-speech-close:hover {
  color: #f43f5e;
}

/* Ventana de Chat Expandible (Siempre al frente: z-index: 99999) */
.chungungo-chat-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 80px);
  background: rgba(11, 19, 38, 0.96);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid rgba(139, 92, 246, 0.45);
  border-radius: 24px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.9),
              0 0 40px rgba(124, 58, 237, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.94);
  transform-origin: bottom right;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 99999;
}

.chungungo-chat-window.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Cabecera del Chat */
.chungungo-chat-header {
  padding: 14px 18px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.98));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chungungo-header-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chungungo-header-avatar {
  position: relative;
  width: 44px;
  height: 44px;
}

.chungungo-header-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.chungungo-header-info h3 {
  margin: 0;
  font-family: var(--font-display, 'Outfit', sans-serif);
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chungungo-header-info p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chungungo-online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  display: inline-block;
}

.chungungo-header-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chungungo-btn-icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.chungungo-btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.25);
}

.chungungo-btn-icon.active {
  background: rgba(56, 189, 248, 0.25);
  color: #38bdf8;
  border-color: #38bdf8;
}

/* Área de Mensajes */
.chungungo-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.chungungo-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chungungo-chat-messages::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.5);
}

.chungungo-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.4);
  border-radius: 3px;
}

/* Estilos de Mensajes */
.chungungo-msg {
  display: flex;
  gap: 10px;
  max-width: 88%;
  animation: msg-appear 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.chungungo-msg.assistant {
  align-self: flex-start;
}

.chungungo-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chungungo-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  border: 1.5px solid rgba(56, 189, 248, 0.5);
}

.chungungo-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chungungo-msg-bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.48;
}

.chungungo-msg.assistant .chungungo-msg-bubble {
  background: rgba(30, 41, 59, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
  border-top-left-radius: 4px;
}

.chungungo-msg.user .chungungo-msg-bubble {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #ffffff;
  border-top-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

.chungungo-msg-bubble p {
  margin: 0 0 8px;
}

.chungungo-msg-bubble p:last-child {
  margin-bottom: 0;
}

.chungungo-msg-bubble ul {
  margin: 6px 0;
  padding-left: 18px;
}

.chungungo-msg-bubble li {
  margin-bottom: 4px;
}

.chungungo-msg-bubble strong {
  color: #38bdf8;
}

/* Botones de Acción dentro de Mensajes */
.chungungo-action-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chungungo-action-btn {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #38bdf8;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 9999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  transition: all 0.2s ease;
}

.chungungo-action-btn:hover {
  background: rgba(56, 189, 248, 0.25);
  color: #ffffff;
  border-color: #38bdf8;
  transform: translateY(-1px);
}

/* Indicador de Escritura */
.chungungo-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
}

.chungungo-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #38bdf8;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

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

/* Chips de Sugerencias Rápidas */
.chungungo-quick-chips {
  padding: 10px 16px;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(15, 23, 42, 0.4);
}

.chungungo-quick-chips::-webkit-scrollbar {
  height: 4px;
}

.chungungo-chip {
  flex-shrink: 0;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.3);
  color: #c4b5fd;
  font-size: 0.76rem;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.chungungo-chip:hover {
  background: rgba(139, 92, 246, 0.28);
  color: #ffffff;
  border-color: #a855f7;
  transform: translateY(-2px);
}

/* Formulario de Entrada */
.chungungo-chat-input-form {
  padding: 12px 14px;
  background: rgba(15, 23, 42, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chungungo-chat-input {
  flex: 1;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 10px 14px;
  color: #ffffff;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

.chungungo-chat-input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.25);
}

.chungungo-chat-input::placeholder {
  color: #64748b;
  font-size: 0.84rem;
}

.chungungo-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  border: none;
  color: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chungungo-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.5);
  color: #ffffff;
}

.chungungo-send-btn:active {
  transform: scale(0.95);
}

/* Keyframes */
@keyframes halo-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes chungungo-pulse-wave {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.15);
    opacity: 0;
  }
  100% {
    transform: scale(0.95);
    opacity: 0;
  }
}

@keyframes thruster-flare {
  0% {
    transform: scale(0.85);
    opacity: 0.6;
  }
  100% {
    transform: scale(1.25);
    opacity: 1;
  }
}

@keyframes status-blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

@keyframes msg-appear {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

/* Responsive para Móviles */
@media (max-width: 640px) {
  .chungungo-avatar-layer {
    width: 66px;
    height: 66px;
  }

  .chungungo-btn {
    width: 66px;
    height: 66px;
  }

  .chungungo-avatar-img {
    width: 60px;
    height: 60px;
  }

  .chungungo-speech-bubble {
    max-width: 250px;
    font-size: 0.82rem;
  }

  .chungungo-chat-window {
    bottom: 16px;
    right: 16px;
    width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 80px);
    border-radius: 20px;
  }
}
