/* ===== Botón flotante robot (encima del de WhatsApp) ===== */
.chatbot-float {
  position: fixed;
  right: 60px;
  bottom: 145px; /* WhatsApp: 60 + 70 alto + 15 gap */
  width: 70px;
  height: 70px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #0f52be 0%, #003893 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  z-index: 100;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  animation: chatbot-pulse 2.5s infinite;
}

.chatbot-float:hover {
  transform: scale(1.06);
}

.chatbot-float i {
  font-size: 38px;
  position: absolute;
  transition: opacity 0.2s ease, transform 0.25s ease;
}

/* Ilustración a color: va sin filtros para no perder los tonos del arte */
.chatbot-float img.chatbot-icon-open {
  position: absolute;
  width: 88%;
  height: 88%;
  object-fit: contain;
  transition: opacity 0.2s ease, transform 0.25s ease;
}

.chatbot-icon-close { opacity: 0; transform: rotate(-90deg) scale(0.5); }
.chatbot-icon-open  { opacity: 1; transform: rotate(0) scale(1); }

/* Estado abierto: el botón muestra la X */
#chatbot-container.is-open .chatbot-icon-open  { opacity: 0; transform: rotate(90deg) scale(0.5); }
#chatbot-container.is-open .chatbot-icon-close { opacity: 1; transform: rotate(0) scale(1); }
#chatbot-container.is-open .chatbot-float { animation: none; }

@keyframes chatbot-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(15, 82, 190, 0.7); }
  70%  { box-shadow: 0 0 0 18px rgba(15, 82, 190, 0); }
  100% { box-shadow: 0 0 0 0 rgba(15, 82, 190, 0); }
}

/* ===== Ventana del chat ===== */
.chatbot-window {
  position: fixed;
  right: 60px;
  bottom: 230px; /* encima del botón robot */
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 480px;
  max-height: calc(100vh - 260px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 101;
  transform-origin: bottom right;
  animation: chatbot-pop 0.25s ease;
}

.chatbot-window[hidden] { display: none; }

@keyframes chatbot-pop {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  color: #fff;
  position: relative;
  overflow: hidden;
  /* gradiente animado que se desplaza suavemente */
  background: linear-gradient(120deg, #003893 0%, #0f52be 35%, #1f6fe0 50%, #0f52be 65%, #003893 100%);
  background-size: 250% 100%;
  animation: chatbot-header-flow 7s ease infinite;
}

/* brillo que cruza el header cada cierto tiempo */
.chatbot-header::after {
  content: "";
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  transform: skewX(-20deg);
  animation: chatbot-header-shine 6s ease-in-out infinite;
}

@keyframes chatbot-header-flow {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@keyframes chatbot-header-shine {
  0%, 65% { left: -60%; }
  100%    { left: 130%; }
}

.chatbot-header-info { display: flex; align-items: center; gap: 10px; position: relative; z-index: 1; }
.chatbot-close { position: relative; z-index: 1; }

.chatbot-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  animation: chatbot-avatar-bob 3s ease-in-out infinite;
}
/* el avatar "respira" y saluda ligeramente */
.chatbot-avatar i,
.chatbot-avatar img { animation: chatbot-avatar-wave 4s ease-in-out infinite; transform-origin: 50% 80%; }
.chatbot-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
@keyframes chatbot-avatar-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}
@keyframes chatbot-avatar-wave {
  0%, 88%, 100% { transform: rotate(0); }
  92%  { transform: rotate(-12deg); }
  96%  { transform: rotate(12deg); }
}

.chatbot-title { margin: 0; font-weight: 700; font-size: 0.95rem; }
.chatbot-status {
  margin: 0;
  font-size: 0.72rem;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chatbot-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
  animation: chatbot-pulse-dot 1.6s infinite;
}
@keyframes chatbot-pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7); }
  70%  { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

/* Fuera de horario: punto gris apagado, sin animación */
.chatbot-status.is-offline .chatbot-dot {
  background: #94a3b8;
  box-shadow: none;
  animation: none;
}

.chatbot-hours {
  margin: 1px 0 0;
  font-size: 0.66rem;
  opacity: 0.75;
}

.chatbot-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
  display: flex;
  opacity: 0.85;
}
.chatbot-close:hover { opacity: 1; }

/* ===== Formulario inicial (gate) ===== */
.chatbot-gate {
  padding: 18px 16px;
  background: #f3f5f9;
  display: flex;
  flex-direction: column;
  gap: 11px;
  overflow-y: auto;
  animation: chatbot-msg-in 0.3s ease;
}
.chatbot-gate[hidden] { display: none; }

.chatbot-offhours {
  margin: 0 0 2px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #7c2d12;
  background: #fff7ed;
  border: 1px solid #fdba74;
  padding: 10px 12px;
  border-radius: 12px;
}
.chatbot-offhours[hidden] { display: none; }
.chatbot-offhours a { color: #7c2d12; font-weight: 700; }

.chatbot-gate-intro {
  margin: 0 0 2px;
  font-size: 0.88rem;
  line-height: 1.45;
  color: #0f172a;
  background: #fff;
  padding: 12px 14px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.chatbot-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1.5px solid #d6dce6;
  border-radius: 12px;
  padding: 0 12px;
  transition: border-color 0.2s ease;
}
.chatbot-field:focus-within { border-color: #0f52be; }
.chatbot-field i { color: #94a3b8; font-size: 18px; flex-shrink: 0; }
.chatbot-field--area { align-items: flex-start; padding-top: 10px; }
.chatbot-field--area i { margin-top: 2px; }
.chatbot-field input,
.chatbot-field textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.88rem;
  padding: 11px 0;
  font-family: inherit;
  color: #0f172a;
  resize: none;
}

.chatbot-terms {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 0.78rem;
  color: #475569;
  line-height: 1.4;
  cursor: pointer;
  padding: 2px;
}
.chatbot-terms input {
  width: 17px;
  height: 17px;
  margin-top: 1px;
  accent-color: #0f52be;
  cursor: pointer;
  flex-shrink: 0;
}
.chatbot-terms a { color: #0f52be; font-weight: 600; }

.chatbot-gate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 4px;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #0f52be 0%, #003893 100%);
  color: #fff;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
}
.chatbot-gate-btn i { font-size: 20px; }
.chatbot-gate-btn:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.chatbot-gate-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Mensajes */
.chatbot-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: #f3f5f9;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chatbot-messages[hidden],
.chatbot-input[hidden] { display: none; }

.chatbot-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.4;
  word-wrap: break-word;
  animation: chatbot-msg-in 0.2s ease;
}
@keyframes chatbot-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chatbot-msg.bot {
  align-self: flex-start;
  background: #ffffff;
  color: #0f172a;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}
.chatbot-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #0f52be 0%, #003893 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Enlaces dentro de los mensajes */
.chatbot-msg a {
  color: #0f52be;
  font-weight: 600;
  text-decoration: underline;
  word-break: break-word;
}
.chatbot-msg.user a { color: #fff; }

/* Menú rápido de servicios (chips) */
.chatbot-quickreplies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
  animation: chatbot-msg-in 0.25s ease;
}
.chatbot-chip {
  background: #fff;
  border: 1.5px solid #0f52be;
  color: #0f52be;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.chatbot-chip:hover {
  background: linear-gradient(135deg, #0f52be 0%, #003893 100%);
  color: #fff;
  transform: translateY(-1px);
}

/* Indicador "escribiendo..." */
.chatbot-typing {
  align-self: flex-start;
  background: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}
.chatbot-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: chatbot-bounce 1.2s infinite;
}
.chatbot-typing span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatbot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Alerta única de resumen al correo (al cerrar el lead) */
.chatbot-summary-prompt {
  align-self: stretch;
  background: linear-gradient(135deg, #eef4ff 0%, #e3ecff 100%);
  border: 1.5px solid #b9cdf5;
  border-radius: 14px;
  padding: 14px 16px;
  animation: chatbot-msg-in 0.3s ease;
}
.chatbot-summary-prompt p {
  margin: 0 0 12px;
  font-size: 0.86rem;
  color: #1e3a6e;
  line-height: 1.45;
}
.chatbot-summary-prompt p i { color: #0f52be; }
.chatbot-summary-field { margin-bottom: 10px; }
.chatbot-summary-field input {
  width: 100%;
  border: 1.5px solid #b9cdf5;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.85rem;
  outline: none;
  background: #fff;
}
.chatbot-summary-field input:focus { border-color: #0f52be; }
.chatbot-summary-warn { margin: 0 0 10px; font-size: 0.76rem; color: #c0392b; }
.chatbot-summary-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chatbot-chip--solid {
  background: linear-gradient(135deg, #0f52be 0%, #003893 100%);
  color: #fff;
  border-color: transparent;
}
.chatbot-chip--solid:hover { filter: brightness(1.08); transform: translateY(-1px); }
.chatbot-sending { font-size: 0.85rem; color: #1e3a6e; font-style: italic; }

/* Input */
.chatbot-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e5e9f0;
}
.chatbot-input input {
  flex: 1;
  border: 1px solid #d6dce6;
  border-radius: 22px;
  padding: 10px 14px;
  font-size: 0.88rem;
  outline: none;
}
.chatbot-input input:focus { border-color: #0f52be; }
.chatbot-input button {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #0f52be 0%, #003893 100%);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chatbot-input button:disabled { opacity: 0.5; cursor: default; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .chatbot-float {
    right: 16px;
    bottom: calc(101px + env(safe-area-inset-bottom, 0px));
  } /* WhatsApp móvil: 16 + 70 + 15 */
  .chatbot-window {
    right: 16px;
    left: 16px;
    bottom: calc(186px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: none;
    height: 70vh;
    height: 70dvh;
    max-height: calc(100vh - 210px);
    max-height: calc(100dvh - 210px);
  }

  /* Evita el auto-zoom de iOS al enfocar campos con font-size < 16px */
  .chatbot-field input,
  .chatbot-field textarea,
  .chatbot-input input,
  .chatbot-summary-field input {
    font-size: 16px;
  }
}

@media (max-width: 400px) {
  .chatbot-float {
    width: 60px;
    height: 60px;
    right: 12px;
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  }
  .chatbot-window {
    right: 10px;
    left: 10px;
    bottom: calc(160px + env(safe-area-inset-bottom, 0px));
    border-radius: 14px;
  }
  .chatbot-avatar { width: 32px; height: 32px; font-size: 18px; }
  .chatbot-header { padding: 11px 12px; }
  .chatbot-title { font-size: 0.88rem; }
  .chatbot-hours { font-size: 0.62rem; }
  .chatbot-gate { padding: 14px 12px; }
  .chatbot-messages { padding: 12px; }
  .chatbot-msg { max-width: 88%; }
}

/* Móvil en horizontal / poca altura: el 70dvh se queda corto o se pasa */
@media (max-width: 768px) and (max-height: 500px) {
  .chatbot-window {
    height: calc(100dvh - 24px);
    max-height: calc(100dvh - 24px);
    bottom: 12px;
  }
  /* Con tan poca altura, el botón flotante encima de la ventana abierta estorba */
  #chatbot-container.is-open .chatbot-float { display: none; }
}
