/* ==========================================================================
   ID SEC GROUP — ASISTENTE VIRTUAL (chatbot)
   Usa los colores del tema (panel → 8. Estilos): --primary-color, --accent-purple,
   --primary-rgb, --text-dark, --bg-light. Contenido:
     1. Botón flotante y aviso      4. Botones, enlaces y valoración
     2. Ventana del chat            5. Formulario para un asesor
     3. Mensajes                    6. Celular, movimiento reducido
   ========================================================================== */

/* El botón «volver arriba» sube para no tapar el botón del chat */
.has-chatbot .back-to-top {
  bottom: 92px;
}

/* Espacio al final del pie para que el botón del chat no tape las redes sociales */
.has-chatbot .main-footer {
  padding-bottom: 96px;
}

/* …ni el botón «volver arriba» tape el último icono de redes */
@media (min-width: 769px) {
  .has-chatbot .footer-social-wrapper {
    padding-right: 64px;
  }
}

.chatbot {
  --chat-primary: var(--primary-color, #461840);
  --chat-accent: var(--accent-purple, #7b3f8c);
  --chat-rgb: var(--primary-rgb, 70 24 64);
  --chat-bg: var(--bg-light, #ffffff);
  --chat-text: var(--text-dark, #222222);
  font-family: var(--font-main, system-ui, sans-serif);
}

.chatbot-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ── 1. Botón flotante y aviso ────────────────────────────────────────── */
.chatbot-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1001;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-primary));
  color: #ffffff;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 8px 24px rgb(var(--chat-rgb) / 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-launcher:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 12px 28px rgb(var(--chat-rgb) / 0.45);
}

.chatbot-launcher:focus-visible,
.chatbot button:focus-visible,
.chatbot a:focus-visible {
  outline: 3px solid var(--chat-accent);
  outline-offset: 3px;
}

.chatbot-icon-close,
.chatbot.is-open .chatbot-icon-open {
  display: none;
}

.chatbot.is-open .chatbot-icon-close {
  display: inline;
}

.chatbot-teaser {
  position: fixed;
  right: 92px;
  bottom: 30px;
  z-index: 1001;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: min(260px, calc(100vw - 120px));
  padding: 6px 6px 6px 14px;
  background: var(--chat-bg);
  color: var(--chat-text);
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);
  animation: chatbot-pop 0.35s ease;
}

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

.chatbot-teaser-text {
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  padding: 4px 0;
}

.chatbot-teaser-close {
  border: none;
  background: none;
  color: #777777;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  width: 28px;
  height: 28px;
  flex: none;
}

/* ── 2. Ventana del chat ──────────────────────────────────────────────── */
.chatbot-panel {
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 1000;
  width: min(380px, calc(100vw - 40px));
  height: min(600px, calc(100vh - 120px));
  height: min(600px, calc(100dvh - 120px));
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  color: var(--chat-text);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgb(0 0 0 / 0.22);
  overflow: hidden;
  animation: chatbot-pop 0.25s ease;
}

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

.chatbot-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px 14px 16px;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-accent));
  color: #ffffff;
}

.chatbot-avatar {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.chatbot-heading {
  flex: 1;
  min-width: 0;
}

.chatbot-heading h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
  font-family: inherit;
  letter-spacing: 0;
}

.chatbot-status {
  margin: 2px 0 0;
  font-size: 0.78rem;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chatbot-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 0.3);
}

.chatbot-restart,
.chatbot-close {
  border: none;
  background: transparent;
  color: #ffffff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  flex: none;
}

.chatbot-restart:hover,
.chatbot-close:hover {
  background: rgb(255 255 255 / 0.18);
}

/* ── 3. Mensajes ──────────────────────────────────────────────────────── */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  background: rgb(var(--chat-rgb) / 0.04);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.chatbot-row {
  display: flex;
  flex-direction: column;
  max-width: 88%;
}

.chatbot-row-bot {
  align-self: flex-start;
}

.chatbot-row-user {
  align-self: flex-end;
  align-items: flex-end;
}

.chatbot-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-line;          /* respeta los saltos de línea de la respuesta */
  overflow-wrap: anywhere;
}

.chatbot-row-bot .chatbot-bubble {
  background: var(--chat-bg);
  color: var(--chat-text);
  border: 1px solid rgb(var(--chat-rgb) / 0.12);
  border-bottom-left-radius: 4px;
}

.chatbot-row-user .chatbot-bubble {
  background: var(--chat-primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

/* «Escribiendo…» */
.chatbot-typing .chatbot-bubble {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
}

.chatbot-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgb(var(--chat-rgb) / 0.55);
  animation: chatbot-blink 1.2s infinite ease-in-out;
}

.chatbot-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing-dot:nth-child(3) { animation-delay: 0.3s; }

/* ── 4. Botones, enlaces y valoración ─────────────────────────────────── */
.chatbot-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chatbot-choice {
  border: 1.5px solid var(--chat-primary);
  background: var(--chat-bg);
  color: var(--chat-primary);
  border-radius: 999px;
  padding: 7px 13px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  min-height: 36px;
  transition: background 0.15s ease, color 0.15s ease;
}

.chatbot-choice:hover {
  background: var(--chat-primary);
  color: #ffffff;
}

.chatbot-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chatbot-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 10px;
  background: rgb(var(--chat-rgb) / 0.1);
  color: var(--chat-primary);
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  min-height: 34px;
}

.chatbot-link:hover {
  background: rgb(var(--chat-rgb) / 0.18);
}

.chatbot-link-whatsapp {
  background: #25d366;
  color: #ffffff;
}

.chatbot-link-whatsapp:hover {
  background: #1ebe5a;
}

.chatbot-feedback {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: #666666;
  padding-left: 4px;
}

.chatbot-feedback-btn {
  border: none;
  background: transparent;
  color: #777777;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
}

.chatbot-feedback-btn:hover {
  background: rgb(var(--chat-rgb) / 0.1);
  color: var(--chat-primary);
}

/* ── 5. Formulario para un asesor ─────────────────────────────────────── */
.chatbot-lead {
  background: var(--chat-bg);
  border: 1px solid rgb(var(--chat-rgb) / 0.18);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chatbot-lead-title {
  margin: 0 0 2px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--chat-primary);
}

.chatbot-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.8rem;
  font-weight: 600;
}

.chatbot-field input,
.chatbot-field select,
.chatbot-field textarea {
  font: inherit;
  font-weight: 400;
  font-size: 0.9rem;
  padding: 8px 10px;
  border: 1px solid rgb(var(--chat-rgb) / 0.25);
  border-radius: 8px;
  background: var(--input-bg, #f4f4f6);
  color: var(--chat-text);
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
}

.chatbot-field input:focus,
.chatbot-field select:focus,
.chatbot-field textarea:focus {
  outline: 2px solid var(--chat-accent);
  outline-offset: 0;
}

.chatbot-field-error {
  color: #b42318;
  font-weight: 600;
  min-height: 0;
}

.chatbot-field-error:empty {
  display: none;
}

.chatbot-trap {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.chatbot-privacy {
  margin: 0;
  font-size: 0.74rem;
  color: #666666;
  line-height: 1.35;
}

.chatbot-lead-submit {
  border: none;
  border-radius: 10px;
  background: var(--chat-primary);
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  padding: 10px;
  cursor: pointer;
  min-height: 42px;
}

.chatbot-lead-submit:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Caja de texto */
.chatbot-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgb(var(--chat-rgb) / 0.1);
  background: var(--chat-bg);
}

.chatbot-input input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.95rem;
  padding: 10px 14px;
  border: 1px solid rgb(var(--chat-rgb) / 0.2);
  border-radius: 999px;
  background: var(--input-bg, #f4f4f6);
  color: var(--chat-text);
}

.chatbot-input input:focus {
  outline: 2px solid var(--chat-accent);
  outline-offset: 0;
}

.chatbot-input button {
  width: 44px;
  height: 44px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: var(--chat-primary);
  color: #ffffff;
  cursor: pointer;
}

.chatbot-input button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.chatbot-footnote {
  margin: 0;
  padding: 0 12px 8px;
  font-size: 0.7rem;
  color: #888888;
  text-align: center;
  background: var(--chat-bg);
}

/* ── Animaciones ──────────────────────────────────────────────────────── */
@keyframes chatbot-pop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes chatbot-blink {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ── 6. Celular y movimiento reducido ─────────────────────────────────── */
@media (max-width: 600px) {
  .chatbot-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    z-index: 1002;
  }

  .chatbot.is-open .chatbot-launcher {
    display: none;            /* en celular se cierra con la X del encabezado */
  }

  .chatbot-launcher {
    right: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
  }

  .chatbot-teaser {
    right: 82px;
    bottom: 24px;
  }

  .has-chatbot .back-to-top {
    bottom: 84px;
    right: 20px;
  }

  .chatbot-input input {
    font-size: 16px;          /* evita el zoom automático de iPhone al escribir */
  }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot-panel,
  .chatbot-teaser,
  .chatbot-typing-dot {
    animation: none;
  }

  .chatbot-messages {
    scroll-behavior: auto;
  }
}
