/* =========================================================
   Asistente / Chatbot JM Sitios
   Módulo autocontenido. No depende de variables del sitio
   ni modifica ningún estilo existente: todas sus variables
   están acotadas a los propios elementos del chat.
   ========================================================= */

/* Variables propias del chatbot (acotadas a sus elementos) */
.chat-launcher,
.chat-panel {
  --primary: #804EDD;
  --primary-700: #6a3fc4;
  --primary-300: #a684ea;
  --bg-dark: #181028;
  --border: rgba(207, 202, 251, 0.14);
  --border-strong: rgba(207, 202, 251, 0.28);
  --text-secondary: #CFCAFB;
  --shadow-purple: 0 14px 34px -12px rgba(128, 78, 221, 0.55);
}

/* Botón lanzador (apilado por encima del WhatsApp flotante del sitio) */
.chat-launcher {
  position: fixed;
  bottom: 22px; right: 22px;
  z-index: 1001;
  width: 58px; height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: grid; place-items: center;
  color: #fff;
  background: var(--primary);
  box-shadow: var(--shadow-purple);
  transition: transform .2s ease, background .2s ease;
}
.chat-launcher:hover { transform: translateY(-2px) scale(1.04); background: var(--primary-700); }
.chat-launcher:focus-visible { outline: 2px solid var(--primary-300); outline-offset: 3px; }
.chat-launcher__badge {
  position: absolute;
  top: -3px; right: -3px;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #25D366;
  color: #fff;
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--bg-dark);
}

/* Al abrir el chat se oculta el lanzador (el panel cubre el WhatsApp flotante) */
body.chat-open .chat-launcher { display: none; }

/* Panel */
.chat-panel {
  position: fixed;
  bottom: 22px; right: 22px;
  z-index: 1002;
  width: 374px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 44px);
  display: flex;
  flex-direction: column;
  background: #1b1330;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 24px 60px -18px rgba(0,0,0,0.75);
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform .3s ease, opacity .26s ease;
}
.chat-panel.is-open { transform: translateY(0); opacity: 1; pointer-events: auto; }

/* Header */
.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, #5b34a8 100%);
  color: #fff;
}
.chat-head__avatar {
  width: 42px; height: 42px;
  flex: none;
  border-radius: 12px;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.16);
  font-family: 'Manrope', sans-serif;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.02em;
}
.chat-head__info { flex: 1; min-width: 0; }
.chat-head__title { font-family: 'Manrope', sans-serif; font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.chat-head__status { font-size: 12.5px; color: rgba(255,255,255,0.82); display: flex; align-items: center; gap: 6px; }
.chat-head__dot { width: 8px; height: 8px; border-radius: 50%; background: #34e070; box-shadow: 0 0 0 3px rgba(52,224,112,0.25); }
.chat-head__close {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 9px;
  border: none; cursor: pointer;
  background: rgba(255,255,255,0.14);
  color: #fff;
  display: grid; place-items: center;
  font-size: 18px; line-height: 1;
  transition: background .2s ease;
}
.chat-head__close:hover { background: rgba(255,255,255,0.26); }

/* Mensajes */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(207,202,251,0.3) transparent;
}
.chat-body::-webkit-scrollbar { width: 7px; }
.chat-body::-webkit-scrollbar-thumb { background: rgba(207,202,251,0.25); border-radius: 4px; }

.msg { display: flex; max-width: 86%; }
.msg p { margin: 0; }
.msg--bot { align-self: flex-start; }
.msg--user { align-self: flex-end; }
.msg__bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.5;
  letter-spacing: -0.01em;
}
.msg--bot .msg__bubble {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  color: #ECE9FB;
  border-top-left-radius: 4px;
}
.msg--user .msg__bubble {
  background: var(--primary);
  color: #fff;
  border-top-right-radius: 4px;
}
.msg__bubble a { color: #fff; font-weight: 600; text-decoration: underline; }
.msg--bot .msg__bubble a { color: var(--primary-300); }
.msg__bubble strong { font-weight: 700; color:#CFCAFB }

/* Acción dentro de burbuja (ej. WhatsApp) */
.msg__action {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
  padding: 9px 14px;
  border-radius: 10px;
  background: #25D366;
  color: #fff !important;
  font-weight: 600 !important;
  font-size: 13.5px;
  text-decoration: none !important;
}
.msg__action:hover { filter: brightness(1.05); }

/* Indicador de escritura */
.typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary-300);
  animation: chat-typing 1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-typing { 0%,60%,100%{ transform: translateY(0); opacity:.5 } 30%{ transform: translateY(-5px); opacity:1 } }

/* Chips */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 4px 14px 12px;
}
.chat-chip {
  border: 1px solid var(--border-strong);
  background: rgba(128,78,221,0.10);
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s ease, color .2s ease, border-color .2s ease;
}
.chat-chip:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Input */
.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.18);
}
.chat-input textarea {
  flex: 1;
  resize: none;
  max-height: 96px;
  background: var(--bg-dark);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 14.5px;
  line-height: 1.4;
  padding: 11px 13px;
}
.chat-input textarea::placeholder { color: rgba(207,202,251,0.5); }
.chat-input textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(128,78,221,0.22); }
.chat-send {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: none; cursor: pointer;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  transition: background .2s ease, transform .15s ease;
}
.chat-send:hover { background: var(--primary-700); }
.chat-send:active { transform: scale(0.94); }
.chat-send:disabled { opacity: .5; cursor: default; }

.chat-foot {
  text-align: center;
  font-size: 11.5px;
  color: rgba(207,202,251,0.6);
  padding: 0 12px 12px;
  background: rgba(0,0,0,0.18);
}

@media (max-width: 480px) {
  .chat-panel {
    width: auto;
    left: 12px; right: 12px; bottom: 12px;
    height: auto; top: 12px;
    max-height: none;
    border-radius: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel { transition: opacity .01ms; }
  .typing span { animation: none; }
}
