/* ==========================================================================
   KASTOR · WIDGET DE CHAT (asistente con IA)
   Estilos aislados con prefijo .kchat-* · reusa los tokens de tema del sitio.
   El launcher se apila ENCIMA del botón flotante de WhatsApp (.wa-float).
   ========================================================================== */

/* ---------- Launcher (burbuja flotante) ---------- */
.kchat-launcher {
  position: fixed;
  right: 1.1rem;
  bottom: calc(1.1rem + 56px + 14px); /* sobre el botón de WhatsApp */
  z-index: 46;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: var(--text-primary);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}
.kchat-launcher:hover { transform: scale(1.06); background: var(--accent-hover); }
.kchat-launcher svg { width: 28px; height: 28px; }
.kchat-launcher .kchat-ico-close { display: none; }
.kchat-launcher.kchat-open .kchat-ico-open { display: none; }
.kchat-launcher.kchat-open .kchat-ico-close { display: block; }

/* Puntito de aviso inicial */
.kchat-launcher::after {
  content: "";
  position: absolute;
  top: 2px; right: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #25D366;
  border: 2px solid var(--bg-primary);
  transition: opacity .2s ease;
}
.kchat-launcher.kchat-open::after,
.kchat-launcher.kchat-seen::after { opacity: 0; }

/* ---------- Panel ---------- */
.kchat-panel {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;              /* cubre los flotantes mientras chateás */
  z-index: 55;
  width: min(380px, calc(100vw - 2rem));
  height: min(600px, calc(100vh - 3rem));
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .55);
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(.98);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  font-family: var(--font-body);
}
.kchat-panel.kchat-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---------- Header ---------- */
.kchat-header {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .85rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.kchat-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: grid; place-items: center;
  color: var(--accent);
  flex-shrink: 0;
}
.kchat-avatar svg { width: 22px; height: 22px; }
/* Avatar con el KAS actualizado (idle.svg) */
.kchat-avatar-kas { background: transparent; overflow: visible; }
.kchat-avatar-kas img { height: 42px; width: auto; display: block; }
.kchat-title { font-family: var(--font-display); font-weight: 700; font-size: .98rem; color: var(--text-primary); line-height: 1.1; }
.kchat-subtitle { font-size: .74rem; color: var(--text-secondary); margin-top: 1px; }
.kchat-header .kchat-close {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); padding: 4px;
  border-radius: 8px; line-height: 0;
}
.kchat-header .kchat-close:hover { color: var(--text-primary); background: var(--bg-surface); }
.kchat-header .kchat-close svg { width: 20px; height: 20px; }

/* ---------- Zona de mensajes ---------- */
.kchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  scrollbar-width: thin;
}
.kchat-msg {
  max-width: 85%;
  padding: .6rem .8rem;
  border-radius: 14px;
  font-size: .9rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.kchat-msg-bot {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}
.kchat-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

/* Tarjetas de producto sugerido */
.kchat-products { align-self: flex-start; width: 100%; display: flex; flex-direction: column; gap: .5rem; }
.kchat-product {
  display: flex; align-items: center; gap: .6rem;
  text-decoration: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .55rem .7rem;
  transition: border-color .18s ease, transform .18s ease;
}
.kchat-product:hover { border-color: var(--accent); transform: translateY(-1px); }
.kchat-product-info { min-width: 0; flex: 1; }
.kchat-product-name { font-weight: 600; font-size: .86rem; color: var(--text-primary); line-height: 1.2; }
.kchat-product-price { font-size: .78rem; color: var(--accent); font-family: var(--font-mono); margin-top: 2px; }
.kchat-product-arrow { color: var(--text-secondary); flex-shrink: 0; }
.kchat-product-arrow svg { width: 18px; height: 18px; }

/* Botón WhatsApp dentro del chat */
.kchat-wa {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: .5rem;
  text-decoration: none;
  background: #25D366; color: #06351a;
  font-weight: 600; font-size: .86rem;
  padding: .55rem .9rem; border-radius: 999px;
}
.kchat-wa svg { width: 18px; height: 18px; }

/* Indicador "escribiendo…" */
.kchat-typing { display: inline-flex; gap: 4px; align-items: center; padding: .7rem .8rem; }
.kchat-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-secondary); opacity: .5;
  animation: kchat-bounce 1.2s infinite ease-in-out;
}
.kchat-typing span:nth-child(2) { animation-delay: .15s; }
.kchat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes kchat-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: .9; } }

/* Chips de sugerencias iniciales */
.kchat-suggestions { display: flex; flex-wrap: wrap; gap: .4rem; padding: 0 1rem .6rem; }
.kchat-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: .4rem .7rem;
  font-size: .78rem;
  cursor: pointer;
  transition: border-color .18s ease, color .18s ease;
}
.kchat-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Input ---------- */
.kchat-form {
  display: flex; gap: .5rem;
  padding: .7rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.kchat-input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .6rem .9rem;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: .9rem;
  outline: none;
  resize: none;
  max-height: 90px;
  line-height: 1.35;
}
.kchat-input:focus { border-color: var(--accent); }
.kchat-send {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--accent);
  color: var(--text-primary);
  display: grid; place-items: center;
  transition: background .18s ease;
}
.kchat-send:hover:not(:disabled) { background: var(--accent-hover); }
.kchat-send:disabled { opacity: .5; cursor: not-allowed; }
.kchat-send svg { width: 20px; height: 20px; }

.kchat-footer-note {
  text-align: center;
  font-size: .68rem;
  color: var(--text-muted);
  padding: 0 1rem .5rem;
}

@media (prefers-reduced-motion: reduce) {
  .kchat-panel, .kchat-launcher, .kchat-product { transition: none; }
  .kchat-typing span { animation: none; }
}
