/* =============================================================
   IKAL.CSS — Widget del agente virtual Ikal
   Take The Leap · taketheleap.com.mx
   ============================================================= */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --ikal-purple:      #4a3060;
  --ikal-purple-mid:  #6b4899;
  --ikal-purple-light:#f8f4ff;
  --ikal-purple-border:#d4b8ff;
  --ikal-text:        #333;
  --ikal-text-light:  #666;
  --ikal-bg:          #fff;
  --ikal-shadow:      0 8px 32px rgba(74, 48, 96, 0.18);
  --ikal-radius:      16px;
  --ikal-btn-size:    56px;
  --ikal-panel-w:     340px;
  --ikal-panel-h:     500px;
  --ikal-z:           99990;   /* Debajo del z-index de WhatsApp (99999) */
}

/* ── Contenedor raíz ────────────────────────────────────────── */
#ikal-widget {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: var(--ikal-z);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-family: Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Botón flotante ─────────────────────────────────────────── */
#ikal-btn {
  width: var(--ikal-btn-size);
  height: var(--ikal-btn-size);
  border-radius: 50%;
  background: var(--ikal-purple);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--ikal-shadow);
  transition: transform 0.2s ease, background 0.2s ease;
  position: relative;
  order: 2; /* Botón debajo del panel */
}

#ikal-btn:hover {
  background: var(--ikal-purple-mid);
  transform: scale(1.08);
}

#ikal-btn svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  display: block;
}

/* Contador de mensajes no leídos */
#ikal-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #e53e3e;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* ── Panel de chat ──────────────────────────────────────────── */
#ikal-panel {
  width: var(--ikal-panel-w);
  height: var(--ikal-panel-h);
  background: var(--ikal-bg);
  border-radius: var(--ikal-radius);
  box-shadow: var(--ikal-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 10px;
  order: 1;
  transform-origin: bottom left;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

#ikal-panel.ikal-cerrado {
  opacity: 0;
  transform: scale(0.92) translateY(10px);
  pointer-events: none;
}

/* ── Header del panel ───────────────────────────────────────── */
#ikal-header {
  background: var(--ikal-purple);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ikal-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ikal-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ikal-header-info strong {
  display: block;
  color: #fff;
  font-size: 15px;
  line-height: 1.2;
}

.ikal-header-info span {
  display: block;
  color: rgba(255,255,255,0.7);
  font-size: 12px;
}

#ikal-cerrar {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}

#ikal-cerrar:hover {
  color: #fff;
  background: rgba(255,255,255,0.15);
}

/* ── Área de mensajes ───────────────────────────────────────── */
#ikal-mensajes {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

#ikal-mensajes::-webkit-scrollbar {
  width: 4px;
}
#ikal-mensajes::-webkit-scrollbar-thumb {
  background: var(--ikal-purple-border);
  border-radius: 2px;
}

/* Burbujas */
.ikal-burbuja {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.ikal-burbuja.bot {
  background: var(--ikal-purple-light);
  color: var(--ikal-text);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  max-width: 84%;
  line-height: 1.52;
}

/* Prosa compacta para respuestas Markdown del bot */
.ikal-burbuja.bot > *:first-child {
  margin-top: 0;
}

.ikal-burbuja.bot > *:last-child {
  margin-bottom: 0;
}

.ikal-burbuja.bot p {
  margin: 0 0 0.62em;
}

.ikal-burbuja.bot strong {
  font-weight: 700;
}

.ikal-burbuja.bot h1,
.ikal-burbuja.bot h2,
.ikal-burbuja.bot h3,
.ikal-burbuja.bot h4 {
  margin: 0.8em 0 0.34em;
  color: #262230;
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: 0;
}

.ikal-burbuja.bot h1 {
  font-size: 1.16em;
}

.ikal-burbuja.bot h2 {
  font-size: 1.08em;
}

.ikal-burbuja.bot h3,
.ikal-burbuja.bot h4 {
  font-size: 1em;
}

.ikal-burbuja.bot ul,
.ikal-burbuja.bot ol {
  margin: 0.48em 0 0.7em;
  padding-left: 1.12em;
}

.ikal-burbuja.bot li {
  margin: 0.14em 0;
}

.ikal-burbuja.bot li > p {
  margin: 0.16em 0;
}

.ikal-burbuja.bot a {
  color: #1f62e8;
  font-weight: 500;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.ikal-burbuja.bot blockquote {
  margin: 0.56em 0;
  padding-left: 0.75em;
  border-left: 3px solid var(--ikal-purple-border);
  color: #5b536a;
}

.ikal-burbuja.bot hr {
  margin: 0.8em 0;
  border: 0;
  border-top: 1px solid rgba(74, 48, 96, 0.12);
}

.ikal-burbuja.bot p + ul,
.ikal-burbuja.bot p + ol,
.ikal-burbuja.bot ul + p,
.ikal-burbuja.bot ol + p,
.ikal-burbuja.bot h1 + p,
.ikal-burbuja.bot h2 + p,
.ikal-burbuja.bot h3 + p,
.ikal-burbuja.bot h4 + p {
  margin-top: 0;
}

.ikal-burbuja.visitante {
  background: var(--ikal-purple);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

.ikal-msg-wrap.sistema {
  width: 100%;
  display: flex;
  justify-content: center;
}

.ikal-burbuja.sistema {
  background: #f3f0fb;
  color: #7a6a9a;
  border: 1px solid #ddd5f5;
  border-radius: 20px;
  font-size: 12px;
  font-style: italic;
  text-align: center;
  max-width: 88%;
  padding: 5px 14px;
}

/* Nombre del emisor encima de la burbuja */
.ikal-emisor {
  font-size: 11px;
  color: var(--ikal-text-light);
  margin-bottom: 2px;
  padding-left: 2px;
}

/* Burbuja del asesor humano (handoff) */
.ikal-burbuja.vendedor {
  background: #4a3060;
  color: #fff;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.ikal-vendedor-label {
  font-size: 11px;
  color: #7c5c9e;
  margin-bottom: 2px;
  padding-left: 2px;
  font-weight: 600;
}

/* Indicador de escritura */
.ikal-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 13px;
  background: var(--ikal-purple-light);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}

.ikal-typing span {
  width: 7px;
  height: 7px;
  background: var(--ikal-purple-mid);
  border-radius: 50%;
  animation: ikal-dot 1.2s infinite ease-in-out;
}

.ikal-typing span:nth-child(2) { animation-delay: 0.2s; }
.ikal-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ikal-dot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%            { transform: scale(1);   opacity: 1; }
}


/* ── Barra de nueva conversación (post-límite) ──────────────── */
#ikal-limite-bar {
  padding: 10px 12px;
  border-top: 1px solid var(--ikal-purple-border);
  background: #f8f6ff;
  flex-shrink: 0;
}

#ikal-nueva-conv-btn {
  width: 100%;
  padding: 9px 0;
  background: var(--ikal-purple);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

#ikal-nueva-conv-btn:hover {
  opacity: 0.88;
}

/* ── Área de input ──────────────────────────────────────────── */
#ikal-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #eee;
  flex-shrink: 0;
  background: #fff;
}

#ikal-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  font-family: inherit;
  color: var(--ikal-text);
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.15s ease;
}

#ikal-input:focus {
  outline: none;
  border-color: var(--ikal-purple-mid);
  box-shadow: 0 0 0 2px rgba(106,72,153,0.12);
}

#ikal-enviar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--ikal-purple);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}

#ikal-enviar:hover {
  background: var(--ikal-purple-mid);
  transform: scale(1.08);
}

#ikal-enviar:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

#ikal-enviar svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}


/* ── Responsivo ─────────────────────────────────────────────── */
@media (max-width: 400px) {
  :root {
    --ikal-panel-w: calc(100vw - 32px);
    --ikal-panel-h: 420px;
  }

  #ikal-widget {
    left: 12px;
    bottom: 12px;
  }
}
