/* ── Bot Beniautos · panel del chat con IA ─────────────────────────────────
   Prefijo de ids y clases: bab-

   El BOTÓN flotante no se estila aquí: vive en botones.css, compartido con los
   otros dos, para que los tres midan exactamente lo mismo.

   La paleta es rosa magenta a propósito, fuera del rojo de la web: los bots se
   leen como herramientas y no como un elemento más del catálogo. Los
   degradados van de oscuro a vivo porque el texto blanco sobre rosa vivo no
   llega al contraste mínimo; cayendo sobre la parte oscura, sí.

   El widget vive al margen del tema: todo lleva su propio prefijo y las
   propiedades que el tema suele pisar (line-height, box-sizing, font) se
   declaran de forma explícita.                                             */

#bab-chat-panel,
#bab-chat-panel * {
  box-sizing: border-box;
}

:root {
  --bab-acento: #ff0d86;
  --bab-acento-osc: #c1005f;
  --bab-acento-suave: #fff0f7;
  --bab-tinta: #14171c;
  --bab-fuente: 'Muli', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

/* ── Panel ──────────────────────────────────────────────────────────────── */

#bab-chat-panel {
  position: fixed;
  bottom: 24px;
  width: 372px;
  max-width: calc(100vw - 32px);
  max-height: min(580px, calc(100vh - 64px));
  background: #fff;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99101;
  box-shadow:
    0 22px 60px rgba(193, 0, 95, .22),
    0 4px 12px rgba(20, 23, 28, .16),
    0 0 0 2px rgba(255, 255, 255, .9);
  opacity: 0;
  transform: translateY(12px) scale(.97);
  pointer-events: none;
  transition: opacity .16s ease, transform .2s cubic-bezier(.34, 1.4, .64, 1);
}

#bab-chat-panel.bab-izq { left: 24px; transform-origin: bottom left; }
#bab-chat-panel.bab-der { right: 24px; transform-origin: bottom right; }

#bab-chat-panel.bab-abierto {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Cabecera ───────────────────────────────────────────────────────────── */

#bab-chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  background: linear-gradient(120deg, #8f0046 0%, #c1005f 45%, #ff0d86 100%);
  flex-shrink: 0;
}

#bab-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .22);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#bab-chat-title {
  flex: 1;
  min-width: 0;
  font-family: var(--bab-fuente);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}

#bab-chat-title span {
  display: block;
  margin-top: 3px;
  font-size: 11.5px;
  font-weight: 500;
  color: rgba(255, 255, 255, .85);
  text-shadow: none;
}

#bab-chat-close {
  background: rgba(255, 255, 255, .16);
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  padding: 0;
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}

#bab-chat-close:hover { background: rgba(255, 255, 255, .32); }

/* ── Aviso de que es una IA ───────────────────────────────────────────────
   Obligación de transparencia del Reglamento (UE) 2024/1689 de inteligencia
   artificial, art. 50.1: hay que informar de que se está interactuando con un
   sistema de IA. Va fijo bajo la cabecera y NO dentro del hilo de mensajes: en
   el hilo se iría con el scroll y dejaría de verse.                       */

#bab-chat-ia {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  background: #ffe3f0;
  border-bottom: 1px solid rgba(193, 0, 95, .18);
  font-family: var(--bab-fuente);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.35;
  color: #8f0046;
  flex-shrink: 0;
}

#bab-chat-ia svg { flex-shrink: 0; }

/* ── Mensajes ───────────────────────────────────────────────────────────── */

#bab-chat-msgs {
  flex: 1 1 auto;
  min-height: 140px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: var(--bab-acento-suave);
}

#bab-chat-msgs::-webkit-scrollbar { width: 6px; }
#bab-chat-msgs::-webkit-scrollbar-track { background: transparent; }
#bab-chat-msgs::-webkit-scrollbar-thumb {
  background: rgba(193, 0, 95, .28);
  border-radius: 3px;
}

.bab-msg {
  max-width: 87%;
  padding: 11px 14px;
  border-radius: 16px;
  font-family: var(--bab-fuente);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.bab-msg.bab-bot {
  align-self: flex-start;
  background: #fff;
  color: var(--bab-tinta);
  border: 1px solid rgba(193, 0, 95, .16);
  border-bottom-left-radius: 5px;
  box-shadow: 0 2px 8px rgba(193, 0, 95, .07);
}

.bab-msg.bab-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #c1005f, #ff0d86);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 3px 10px rgba(193, 0, 95, .28);
}

.bab-msg strong { font-weight: 800; }

.bab-msg a.bab-link {
  color: var(--bab-acento-osc);
  text-decoration: underline;
  word-break: break-all;
}

.bab-msg.bab-user a.bab-link { color: #fff; }

/* Enlace a la ficha de un coche: la URL entera son 90 caracteres y ocupaba
   cuatro líneas en el panel, así que se muestra como pastilla. */
.bab-msg a.bab-ficha {
  display: inline-block;
  margin-top: 4px;
  padding: 4px 12px;
  border: 1.5px solid var(--bab-acento);
  border-radius: 999px;
  background: #fff;
  color: var(--bab-acento-osc);
  font-size: 12.5px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, color .15s;
}

.bab-msg a.bab-ficha::after { content: ' →'; font-weight: 400; }

.bab-msg a.bab-ficha:hover {
  background: var(--bab-acento);
  color: #fff;
}

/* ── Botones dentro de una respuesta ────────────────────────────────────── */

.bab-accion {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 10px 17px;
  border-radius: 999px;
  font-family: var(--bab-fuente);
  font-size: 13.5px;
  font-weight: 800;
  text-decoration: none !important;
  word-break: normal;
  transition: filter .15s, transform .1s;
}

.bab-accion:active { transform: scale(.98); }
.bab-accion:hover { filter: brightness(1.08); }
.bab-accion svg { flex-shrink: 0; }

.bab-accion-wa {
  background: linear-gradient(135deg, #128c3e, #25d366);
  color: #fff !important;
  box-shadow: 0 3px 12px rgba(37, 211, 102, .4);
}

.bab-accion-stock {
  background: linear-gradient(135deg, #8f0046, #ff0d86);
  color: #fff !important;
  box-shadow: 0 3px 12px rgba(193, 0, 95, .35);
}

.bab-accion-tel {
  background: #fff;
  color: var(--bab-acento-osc) !important;
  border: 1.5px solid var(--bab-acento);
}

/* ── «Escribiendo…» ────────────────────────────────────────────────────── */

.bab-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid rgba(193, 0, 95, .16);
  border-radius: 16px;
  border-bottom-left-radius: 5px;
}

.bab-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bab-acento);
  animation: bab-bote .9s infinite ease-in-out;
}

.bab-typing i:nth-child(2) { animation-delay: .15s; }
.bab-typing i:nth-child(3) { animation-delay: .3s; }

@keyframes bab-bote {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Sugerencias iniciales ──────────────────────────────────────────────── */

#bab-chat-sug {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 12px;
  background: var(--bab-acento-suave);
  flex-shrink: 0;
}

/* En cuanto se usa una sugerencia el bloque se vacía: sin esto dejaría una
   franja de relleno flotando sobre el campo de escribir. */
#bab-chat-sug:empty { display: none; padding: 0; }

#bab-chat-sug button {
  background: #fff;
  border: 1.5px solid rgba(193, 0, 95, .3);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: var(--bab-fuente);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--bab-acento-osc);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

#bab-chat-sug button:hover {
  background: var(--bab-acento);
  border-color: var(--bab-acento);
  color: #fff;
}

/* ── Formulario ─────────────────────────────────────────────────────────── */

#bab-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 11px 12px;
  background: #fff;
  border-top: 1px solid rgba(193, 0, 95, .14);
  flex-shrink: 0;
}

#bab-chat-input {
  flex: 1;
  min-width: 0;
  background: var(--bab-acento-suave);
  border: 1.5px solid rgba(193, 0, 95, .2);
  border-radius: 22px;
  padding: 10px 15px;
  font-family: var(--bab-fuente);
  font-size: 14px;
  line-height: 1.4;
  color: var(--bab-tinta);
  resize: none;
  max-height: 96px;
  overflow-y: auto;
  outline: none;
  box-shadow: none;
}

#bab-chat-input:focus {
  background: #fff;
  border-color: var(--bab-acento);
}

#bab-chat-input::placeholder { color: #a8809a; }

#bab-chat-send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #c1005f, #ff0d86);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 4px 12px rgba(193, 0, 95, .35);
  transition: filter .15s, transform .1s;
}

#bab-chat-send:hover:not(:disabled) { filter: brightness(1.08); }
#bab-chat-send:active:not(:disabled) { transform: scale(.96); }

#bab-chat-send:disabled {
  background: #d8ccd3;
  box-shadow: none;
  cursor: default;
}

#bab-chat-send svg { pointer-events: none; }

/* ── Aviso de privacidad ────────────────────────────────────────────────── */

#bab-chat-legal {
  padding: 8px 14px 11px;
  background: #fff;
  border-top: 1px solid rgba(193, 0, 95, .1);
  font-family: var(--bab-fuente);
  font-size: 10.5px;
  line-height: 1.5;
  color: #8a7f85;
  text-align: center;
  flex-shrink: 0;
}

#bab-chat-legal a { color: var(--bab-acento-osc); text-decoration: underline; }

/* ── Móvil ──────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  #bab-chat-panel {
    left: 12px !important;
    right: 12px !important;
    width: auto;
    bottom: 16px;
    max-height: calc(100vh - 40px);
  }
}

@media (prefers-reduced-motion: reduce) {
  #bab-chat-panel,
  .bab-accion,
  .bab-msg a.bab-ficha { transition: none; }
  .bab-typing i { animation: none; }
}
