/* ════════════════════════════════════════════════════
   EstrenaWeb ChatBot v1 — Fase 1: UI + respuestas predefinidas
   Fase 2: solo hay que sustituir ResponseEngine en chat-bot.js
   ════════════════════════════════════════════════════ */

/* ── Variables locales ──────────────────────────── */
.ew-chatbot {
  --ew-coral:       #C4361B;
  --ew-coral-h:     #AC2F18;
  --ew-coral-texto: #C4361B;
  --ew-ink:    #1A1410;
  --ew-ink-2:  rgba(26,20,16,0.55);
  --ew-bg:     #FFF4E8;
  --ew-white:  #FFFFFF;
  --ew-border: rgba(26,20,16,0.10);
  --ew-r:      20px;
  --ew-shadow: 0 12px 50px rgba(26,20,16,0.16);
}

/* ── Animaciones de blob ───────────────────────── */
@keyframes ewBlobMorph {
  0%,100% { border-radius: 72% 28% 57% 43% / 43% 47% 53% 57%; }
  33%     { border-radius: 55% 45% 40% 60% / 60% 38% 62% 40%; }
  66%     { border-radius: 42% 58% 66% 34% / 50% 57% 43% 50%; }
}
@keyframes ewBlobFloat {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-6px); }
}
@keyframes ewMsgIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes ewDot {
  0%,80%,100% { transform: scale(0.8); opacity: 0.4; }
  40%         { transform: scale(1.2); opacity: 1; }
}
@keyframes ewFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Trigger: botón flotante ───────────────────── */
.ew-chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9995;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none; /* los hijos tienen pointer-events */
}

/* Bocadillo "¿Te ayudo?" */
.ew-chat-bubble {
  background: var(--ew-white);
  border: 1px solid var(--ew-border);
  border-radius: 14px 14px 4px 14px;
  padding: 9px 14px;
  font-size: 0.86rem;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--ew-ink);
  box-shadow: 0 4px 20px rgba(26,20,16,0.12);
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.ew-chat-bubble.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Wrapper de animación flotante (separa float de hover scale) */
.ew-blob-float-wrap {
  pointer-events: auto;
  animation: ewBlobFloat 4s ease-in-out infinite;
}

/* El botón blob */
.ew-chat-blob-btn {
  width: 62px;
  height: 62px;
  background: var(--ew-coral);
  border: none;
  cursor: pointer;
  position: relative;
  border-radius: 72% 28% 57% 43% / 43% 47% 53% 57%;
  box-shadow: 0 6px 24px rgba(196,54,27,0.45);
  animation: ewBlobMorph 6s ease-in-out infinite;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
}
.ew-chat-blob-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 30px rgba(196,54,27,0.55);
}
.ew-chat-blob-btn:focus-visible {
  outline: 3px solid var(--ew-coral);
  outline-offset: 4px;
}

/* SVG cara */
.ew-blob-face {
  width: 38px;
  height: 38px;
  position: absolute;
  inset: 0;
  margin: auto;
  pointer-events: none;
  transition: opacity 0.15s;
}

/* × cierre */
.ew-blob-close {
  color: #fff;
  font-size: 26px;
  font-weight: 300;
  line-height: 1;
  opacity: 0;
  position: absolute;
  transition: opacity 0.15s;
  pointer-events: none;
  user-select: none;
}
.ew-chat-blob-btn.open .ew-blob-face  { opacity: 0; }
.ew-chat-blob-btn.open .ew-blob-close { opacity: 1; }

/* ── Ventana de chat ───────────────────────────── */
.ew-chat-window {
  position: fixed;
  bottom: 102px;
  right: 24px;
  width: 370px;
  max-height: min(560px, calc(100vh - 130px));
  display: flex;
  flex-direction: column;
  background: var(--ew-bg);
  border-radius: var(--ew-r);
  box-shadow: var(--ew-shadow);
  border: 1px solid var(--ew-border);
  z-index: 9990;
  overflow: hidden;
  /* Estado cerrado */
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.ew-chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Cabecera */
.ew-chat-header {
  background: var(--ew-coral);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.ew-header-blob {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  position: relative;
  animation: ewBlobMorph 6s ease-in-out infinite;
  border-radius: 72% 28% 57% 43% / 43% 47% 53% 57%;
  background: rgba(255,255,255,0.22);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ew-header-blob svg {
  width: 28px;
  height: 28px;
}

.ew-header-info { flex: 1; min-width: 0; }
.ew-header-name {
  font-family: 'Clash Display', system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
}
.ew-header-sub {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.73rem;
  color: rgba(255,255,255,0.78);
  margin-top: 2px;
}

.ew-header-dot {
  width: 9px;
  height: 9px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.4);
  flex-shrink: 0;
}

.ew-reset-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.55);
  font-size: 1rem;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.ew-reset-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.15);
}

/* Zona de mensajes */
.ew-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.ew-chat-messages::-webkit-scrollbar { width: 4px; }
.ew-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ew-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(26,20,16,0.15);
  border-radius: 2px;
}

/* Burbujas */
.ew-msg {
  display: flex;
  flex-direction: column;
  max-width: 90%;
  animation: ewMsgIn 0.22s ease;
}
.ew-msg-bot  { align-self: flex-start; }
.ew-msg-user { align-self: flex-end; }

.ew-msg-bubble {
  padding: 10px 14px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.875rem;
  line-height: 1.58;
}
.ew-msg-bot .ew-msg-bubble {
  background: var(--ew-white);
  color: var(--ew-ink);
  border: 1px solid var(--ew-border);
  border-radius: 4px 16px 16px 16px;
}
.ew-msg-user .ew-msg-bubble {
  background: var(--ew-coral);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}
.ew-msg-bubble b,
.ew-msg-bubble strong { font-weight: 700; }

/* Lista Markdown renderizada dentro de burbuja de bot */
.ew-md-list {
  margin: 4px 0 2px 16px;
  padding: 0;
  list-style: disc;
}
.ew-md-list li { margin-bottom: 3px; }

/* Link inline dentro de mensaje */
.ew-chat-link {
  color: var(--ew-coral-texto);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ew-msg-user .ew-chat-link { color: #fff; }

/* Quick replies */
.ew-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 6px;
  animation: ewFadeIn 0.25s 0.1s ease both;
}
.ew-qr-btn {
  background: var(--ew-white);
  border: 1.5px solid var(--ew-coral-texto);
  color: var(--ew-coral-texto);
  border-radius: 999px;
  padding: 11px 14px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1.3;
}
.ew-qr-btn:hover { background: var(--ew-coral); color: #fff; }

/* Botón de inicio tras "Quiero empezar" */
.ew-start-btn {
  display: inline-block;
  background: var(--ew-coral);
  color: #fff;
  border-radius: 999px;
  padding: 10px 20px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.875rem;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.15s;
  margin-top: 6px;
  animation: ewFadeIn 0.25s 0.15s ease both;
}
.ew-start-btn:hover { background: var(--ew-coral-h); }

/* Indicador de escritura */
.ew-typing-wrap { animation: ewMsgIn 0.2s ease; }
.ew-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--ew-white);
  border: 1px solid var(--ew-border);
  border-radius: 4px 16px 16px 16px;
}
.ew-typing-dot {
  width: 7px;
  height: 7px;
  background: rgba(26,20,16,0.35);
  border-radius: 50%;
  animation: ewDot 1.2s ease-in-out infinite;
}
.ew-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ew-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Pie: CTA fija + campo de texto */
.ew-chat-footer {
  padding: 11px 14px;
  border-top: 1px solid var(--ew-border);
  background: var(--ew-white);
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex-shrink: 0;
}
.ew-footer-cta {
  display: block;
  background: var(--ew-coral);
  color: #fff;
  text-align: center;
  padding: 9px 16px;
  border-radius: 999px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.15s;
}
.ew-footer-cta:hover { background: var(--ew-coral-h); }

.ew-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.ew-chat-input {
  flex: 1;
  border: 1.5px solid var(--ew-border);
  border-radius: 999px;
  padding: 8px 15px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.875rem;
  color: var(--ew-ink);
  background: var(--ew-bg);
  outline: none;
  transition: border-color 0.15s;
}
.ew-chat-input:focus { border-color: var(--ew-coral); }
.ew-chat-input::placeholder { color: rgba(26,20,16,0.35); }

.ew-chat-send {
  width: 36px;
  height: 36px;
  background: var(--ew-coral);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.ew-chat-send:hover { background: var(--ew-coral-h); }
.ew-chat-send svg { width: 15px; height: 15px; }

/* ── Responsive móvil ─────────────────────────── */
@media (max-width: 480px) {
  .ew-chat-window {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 82vh;
    border-radius: 20px 20px 0 0;
    transform-origin: bottom center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .ew-chat-trigger {
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    right: 18px;
  }
}
