/* MuninTech Chatbot */
:root {
  --mtchat-color: #1a1a2e;
}

#mtchat-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99990;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.mtchat-hidden { display: none !important; }

/* Burbuja flotante */
#mtchat-bubble {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--mtchat-color);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#mtchat-bubble:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.34);
}
#mtchat-bubble-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2ecc71;
  border: 2px solid #fff;
}

/* Ventana */
#mtchat-window {
  position: fixed;
  bottom: 92px;
  right: 20px;
  width: 370px;
  max-width: calc(100vw - 24px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.24);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: mtchat-in 0.18s ease;
}
@keyframes mtchat-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Encabezado */
#mtchat-header {
  background: var(--mtchat-color);
  color: #fff;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#mtchat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
#mtchat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}
#mtchat-title {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}
#mtchat-status {
  font-size: 11.5px;
  opacity: 0.85;
}
#mtchat-status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2ecc71;
  margin-right: 5px;
}
#mtchat-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  opacity: 0.85;
}
#mtchat-close:hover { opacity: 1; }

/* Mensajes */
#mtchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  background: #f4f5f7;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mtchat-msg { display: flex; }
.mtchat-msg-user { justify-content: flex-end; }
.mtchat-msg-assistant { justify-content: flex-start; }
.mtchat-msg-bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.mtchat-msg-user .mtchat-msg-bubble {
  background: var(--mtchat-color);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.mtchat-msg-assistant .mtchat-msg-bubble {
  background: #fff;
  color: #222;
  border: 1px solid #e4e6ea;
  border-bottom-left-radius: 4px;
}
.mtchat-link {
  color: var(--mtchat-color);
  font-weight: 600;
  text-decoration: underline;
}
.mtchat-msg-user .mtchat-msg-bubble .mtchat-link { color: #fff; }

/* Indicador escribiendo */
.mtchat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 14px !important;
}
.mtchat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b6bac2;
  animation: mtchat-blink 1.2s infinite both;
}
.mtchat-typing span:nth-child(2) { animation-delay: 0.2s; }
.mtchat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes mtchat-blink {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

/* Fila WhatsApp */
#mtchat-wa-row {
  padding: 8px 12px 0;
  background: #f4f5f7;
  flex-shrink: 0;
}
#mtchat-wa-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #25d366;
  color: #fff !important;
  font-weight: 600;
  font-size: 14px;
  padding: 9px;
  border-radius: 10px;
  text-decoration: none;
}
#mtchat-wa-link:hover { background: #1fb958; color: #fff; }

/* Input */
#mtchat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e8eaee;
  flex-shrink: 0;
}
#mtchat-input {
  flex: 1;
  border: 1px solid #d6d9df;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
}
#mtchat-input:focus { border-color: var(--mtchat-color); }
#mtchat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--mtchat-color);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#mtchat-send:disabled { opacity: 0.5; cursor: default; }

#mtchat-footer {
  text-align: center;
  font-size: 10.5px;
  color: #9aa0aa;
  padding: 4px 0 7px;
  background: #fff;
  flex-shrink: 0;
}

/* ---------- Mascota ---------- */
.mtchat-mascot-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: 50% 100%;
  will-change: transform;
}
#mtchat-avatar.mtchat-has-mascot {
  background: #fff;
  padding: 3px;
  overflow: hidden;
}
#mtchat-bubble.mtchat-has-mascot {
  background: #f4f5f7;
  border: 3px solid var(--mtchat-color);
  padding: 5px;
}
.mtchat-mascot-bubble {
  width: 46px;
  height: 46px;
}

/* Reposo: flotación suave con ligero balanceo */
.mtchat-idle {
  animation: mtchat-float 3.2s ease-in-out infinite;
}
@keyframes mtchat-float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30% { transform: translateY(-3px) rotate(-2deg); }
  60% { transform: translateY(-1px) rotate(2deg); }
}

/* Escribiendo: rebote rápido, "está pensando" */
.mtchat-talking {
  animation: mtchat-talk 0.55s ease-in-out infinite;
}
@keyframes mtchat-talk {
  0%, 100% { transform: translateY(0) rotate(-3deg) scaleY(1); }
  25% { transform: translateY(-4px) rotate(0deg) scaleY(1.04); }
  50% { transform: translateY(0) rotate(3deg) scaleY(0.96); }
  75% { transform: translateY(-2px) rotate(0deg) scaleY(1.02); }
}

/* Respuesta lista: brinco con squash & stretch */
.mtchat-hop {
  animation: mtchat-hop 0.7s cubic-bezier(0.28, 0.84, 0.42, 1) 1;
}
@keyframes mtchat-hop {
  0% { transform: scaleY(0.85) scaleX(1.1); }
  30% { transform: translateY(-9px) scaleY(1.1) scaleX(0.95) rotate(-4deg); }
  55% { transform: translateY(0) scaleY(0.92) scaleX(1.06); }
  75% { transform: translateY(-3px) scaleY(1.02); }
  100% { transform: translateY(0) scaleY(1) scaleX(1); }
}

/* Accesibilidad: respetar usuarios que desactivan animaciones */
@media (prefers-reduced-motion: reduce) {
  .mtchat-idle, .mtchat-talking, .mtchat-hop {
    animation: none;
  }
}

/* Móvil */
@media (max-width: 480px) {
  #mtchat-window {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 84px;
    height: 70vh;
  }
  #mtchat-root { bottom: 14px; right: 14px; }
}

/* Botones del header */
#mtchat-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
#mtchat-mute {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px 6px;
  opacity: 0.85;
  display: flex;
  align-items: center;
}
#mtchat-mute:hover { opacity: 1; }

/* ---------- Teaser (burbuja de diálogo) ---------- */
#mtchat-teaser {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 260px;
  max-width: calc(100vw - 40px);
  background: #ffffff;
  color: #23233a;
  border: 3px solid var(--mtchat-color);
  border-radius: 18px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding: 13px 15px;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.45;
  cursor: pointer;
  animation: mtchat-teaser-in 0.28s cubic-bezier(0.34, 1.4, 0.64, 1);
  transform-origin: 100% 100%;
}
/* Colita apuntando al cuervo, con el mismo contorno */
#mtchat-teaser::after {
  content: "";
  position: absolute;
  bottom: -11px;
  right: 24px;
  width: 16px;
  height: 16px;
  background: #ffffff;
  border-right: 3px solid var(--mtchat-color);
  border-bottom: 3px solid var(--mtchat-color);
  transform: rotate(45deg) translateY(-4px);
}
#mtchat-teaser:hover {
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.24);
}
#mtchat-teaser-text {
  padding-right: 14px;
}
#mtchat-teaser-close {
  position: absolute;
  top: 4px;
  right: 6px;
  background: none;
  border: none;
  color: #9aa0aa;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}
#mtchat-teaser-close:hover { color: #23233a; }

@keyframes mtchat-teaser-in {
  from { opacity: 0; transform: scale(0.7) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.mtchat-teaser-out {
  opacity: 0 !important;
  transform: scale(0.85) translateY(6px) !important;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  #mtchat-teaser { animation: none; }
}

/* ---------- Botón píldora ---------- */
#mtchat-bubble.mtchat-pill {
  width: auto;
  height: 58px;
  border-radius: 32px;
  padding: 0 22px 0 16px;
  gap: 10px;
}
#mtchat-bubble-label {
  color: #fff;
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
/* Con mascota: fondo de marca y cuervo en círculo claro para contraste */
#mtchat-bubble.mtchat-pill.mtchat-has-mascot {
  background: var(--mtchat-color);
  border: none;
  padding: 0 22px 0 8px;
}
#mtchat-bubble.mtchat-pill .mtchat-mascot-bubble {
  width: 44px;
  height: 44px;
  background: #f4f5f7;
  border-radius: 50%;
  padding: 3px;
  box-sizing: border-box;
}

/* ---------- Estilo "contacto" v1.4.2 ---------- */
/* Degradado del header y de la píldora */
#mtchat-header,
#mtchat-bubble.mtchat-pill.mtchat-has-mascot,
#mtchat-bubble {
  background: var(--mtchat-color);
  background: linear-gradient(135deg, var(--mtchat-color), color-mix(in srgb, var(--mtchat-color) 55%, #6c5bd4));
}

/* Avatar del header más grande con badge verde encima */
#mtchat-avatar {
  position: relative;
  width: 42px;
  height: 42px;
  overflow: visible;
}
#mtchat-avatar.mtchat-has-mascot {
  background: #fff;
}
#mtchat-avatar .mtchat-mascot-img {
  border-radius: 50%;
}
#mtchat-avatar-badge {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2ecc71;
  border: 2px solid #fff;
}
/* El punto del texto "En línea" ya no hace falta: el badge vive en el avatar */
#mtchat-status::before { display: none; }

/* Avatares junto a los mensajes del bot */
.mtchat-msg { align-items: flex-end; gap: 7px; }
.mtchat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #e4e6ea;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #23233a;
  overflow: hidden;
  margin-bottom: 16px;
}
.mtchat-msg-avatar img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}
.mtchat-msg-body {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}
.mtchat-msg-user .mtchat-msg-body { align-items: flex-end; }
.mtchat-msg-assistant .mtchat-msg-body { align-items: flex-start; }
.mtchat-msg-body .mtchat-msg-bubble { max-width: 100%; }

/* Hora bajo cada mensaje */
.mtchat-msg-time {
  font-size: 10.5px;
  color: #9aa0aa;
  margin-top: 3px;
  padding: 0 4px;
}

/* Burbujas del cliente con degradado */
.mtchat-msg-user .mtchat-msg-bubble {
  background: var(--mtchat-color);
  background: linear-gradient(135deg, var(--mtchat-color), color-mix(in srgb, var(--mtchat-color) 55%, #6c5bd4));
}

/* ---------- Posición y arrastre v1.6.1 ---------- */
/* En móvil, el botón nace ARRIBA de la barra de navegación inferior del tema */
@media (max-width: 768px) {
  #mtchat-root { bottom: 88px; right: 14px; }
  #mtchat-window { bottom: 150px; }
}

/* Mientras se arrastra */
#mtchat-root.mtchat-dragging #mtchat-bubble {
  cursor: grabbing;
  transform: scale(1.07);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  transition: none;
}
#mtchat-bubble { touch-action: none; cursor: grab; }

/* Si el botón vive en la mitad izquierda, el teaser se alinea a la izquierda */
#mtchat-root.mtchat-left #mtchat-teaser {
  right: auto;
  left: 0;
}
#mtchat-root.mtchat-left #mtchat-teaser::after {
  right: auto;
  left: 24px;
}

/* ---------- Modo pestaña lateral v1.7.0 ---------- */
#mtchat-root.mtchat-side {
  /* Sin transform: un padre con transform "captura" a los hijos position:fixed */
  top: calc(50% - 29px);
  bottom: auto !important;
  right: 0 !important;
}
/* La píldora se esconde dejando asomar solo a la mascota */
#mtchat-root.mtchat-side #mtchat-bubble.mtchat-pill {
  border-radius: 32px 0 0 32px;
  padding-right: 16px;
  transform: translateX(calc(100% - 62px));
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
#mtchat-root.mtchat-side:hover #mtchat-bubble.mtchat-pill,
#mtchat-root.mtchat-side #mtchat-bubble.mtchat-pill:focus-visible {
  transform: translateX(0);
  box-shadow: -4px 4px 18px rgba(0, 0, 0, 0.3);
}
/* Botón redondo (sin etiqueta) en modo lateral: media luna */
#mtchat-root.mtchat-side #mtchat-bubble:not(.mtchat-pill) {
  border-radius: 32px 0 0 32px;
}
/* Teaser: a la izquierda de la pestaña, centrado verticalmente */
#mtchat-root.mtchat-side #mtchat-teaser {
  bottom: auto;
  top: 50%;
  right: calc(100% + 14px);
  transform: translateY(-50%);
  width: 240px;
}
#mtchat-root.mtchat-side #mtchat-teaser::after {
  bottom: auto;
  right: -10px;
  top: 50%;
  transform: translateY(-50%) rotate(-45deg);
}
@keyframes mtchat-teaser-in-side {
  from { opacity: 0; transform: translateY(-50%) scale(0.85); }
  to { opacity: 1; transform: translateY(-50%) scale(1); }
}
#mtchat-root.mtchat-side #mtchat-teaser {
  animation: mtchat-teaser-in-side 0.28s cubic-bezier(0.34, 1.4, 0.64, 1);
  transform-origin: 100% 50%;
}
/* En móvil el modo lateral también funciona (tap = abrir chat directo) */
@media (max-width: 768px) {
  #mtchat-root.mtchat-side { bottom: auto !important; }
}

/* ---------- Ventana centrada en modo lateral v1.7.1 ---------- */
#mtchat-root.mtchat-side ~ #mtchat-window,
#mtchat-root.mtchat-side #mtchat-window {
  top: 50%;
  bottom: auto;
  right: 84px;
  transform: translateY(-50%);
  max-height: min(560px, calc(100vh - 40px));
  animation: mtchat-in-side 0.18s ease;
}
@keyframes mtchat-in-side {
  from { opacity: 0; transform: translateY(-50%) scale(0.97); }
  to { opacity: 1; transform: translateY(-50%) scale(1); }
}
@media (max-width: 768px) {
  #mtchat-root.mtchat-side #mtchat-window {
    left: 12px;
    right: 12px;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    height: 72vh;
  }
}
