/**
 * Asistente de tienda — estilos.
 *
 * Adaptado del widget de covalinstalaciones.es. Dos cambios respecto al original,
 * y los dos vienen del sitio donde va a vivir:
 *
 * 1. TODO CUELGA DE #mlchat-root y todas las clases van prefijadas. El theme de
 *    esta tienda tiene un custom.css de 440 KB acumulado desde 2020: cualquier
 *    nombre generico como .chat-btn o .card tiene numeros de que ya exista.
 * 2. LOS COLORES SON VARIABLES PROPIAS, no las del theme. Asi el widget se ve
 *    igual aunque el theme cambie, y para vestirlo de la marca basta con
 *    redefinir estas cuatro lineas.
 */

#mlchat-root {
  --mlchat-primary: #1b2a4a;
  --mlchat-primary-suave: #2f4676;
  --mlchat-acento: #f5a623;
  --mlchat-fondo: #f4f6fa;
  --mlchat-borde: #dfe4ee;
  --mlchat-texto: #1f2430;
  --mlchat-gris: #6b7280;
}

#mlchat-root *,
#mlchat-root *::before,
#mlchat-root *::after {
  box-sizing: border-box;
}

/* ── Boton flotante ───────────────────────────────────────────────────────── */

#mlchat-root .mlchat-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--mlchat-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  z-index: 2147483000;
  transition: transform 0.18s ease;
}

#mlchat-root .mlchat-btn:hover { transform: scale(1.08); }
#mlchat-root .mlchat-btn svg { width: 26px; height: 26px; }

#mlchat-root .mlchat-btn .mlchat-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--mlchat-acento);
  border: 2px solid #fff;
}

/* Abierto, el punto de aviso no pinta nada: ya está mirando. */
#mlchat-root .mlchat-btn.abierto .mlchat-dot { display: none; }

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

#mlchat-root .mlchat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 372px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 130px);
  background: #fff;
  color: var(--mlchat-texto);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(16, 24, 40, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483001;
  font-size: 14px;
  line-height: 1.5;
  animation: mlchatIn 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes mlchatIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

#mlchat-root .mlchat-head {
  background: var(--mlchat-primary);
  color: #fff;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#mlchat-root .mlchat-head h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}

#mlchat-root .mlchat-head p {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.82;
  color: #fff;
}

#mlchat-root .mlchat-head-btns {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

#mlchat-root .mlchat-close,
#mlchat-root .mlchat-min {
  background: none;
  border: none;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  /*
   * 28x28: son dos dianas juntas y una de ellas termina la conversacion. Con el
   * padding de antes (0 2px) quedaban a tres pixeles de distancia en un movil,
   * que es como se pulsa la que no era.
   */
  width: 28px;
  height: 28px;
  padding: 0;
  cursor: pointer;
  opacity: 0.85;
  border-radius: 6px;
}

#mlchat-root .mlchat-min { font-size: 22px; }

#mlchat-root .mlchat-close:hover,
#mlchat-root .mlchat-min:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.16);
}

/* ── El diálogo de confirmación ───────────────────────────────────────────── */

/*
 * Cubre SOLO el panel del chat, no la página. Es nuestra ventana la que
 * pregunta; el resto del sitio sigue siendo del cliente y debe poder seguir
 * usándolo.
 */
#mlchat-root .mlchat-confirm {
  position: absolute;
  /* Los cuatro lados sueltos ademas de `inset`: Safari no entendio `inset`
     hasta 2021 y ahi el dialogo saldria pegado a una esquina sin cubrir nada. */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.45);
  border-radius: inherit;
}

#mlchat-root .mlchat-confirm[hidden] { display: none; }

#mlchat-root .mlchat-confirm-card {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  max-width: 300px;
}

#mlchat-root .mlchat-confirm-t {
  display: block;
  font-size: 15px;
  color: #111827;
  margin-bottom: 6px;
}

#mlchat-root .mlchat-confirm-p {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.45;
  color: #4b5563;
}

#mlchat-root .mlchat-confirm-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/*
 * El botón que destruye va en rojo y NO es el que tiene el foco al abrir: lo
 * tiene «Seguir aquí». Quien pulsa Enter por inercia no cuelga la conversación.
 */
#mlchat-root .mlchat-opt.danger {
  background: #b42318;
  border-color: #b42318;
  color: #fff;
}

#mlchat-root .mlchat-opt.danger:hover { background: #912018; }

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

#mlchat-root .mlchat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--mlchat-fondo);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#mlchat-root .mlchat-msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 14px;
  /* pre-line: el modelo separa en parrafos con saltos, y se respetan. */
  white-space: pre-line;
  overflow-wrap: anywhere;
}

#mlchat-root .mlchat-msg.bot {
  background: #fff;
  align-self: flex-start;
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
}

#mlchat-root .mlchat-msg.user {
  background: var(--mlchat-primary);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}

/*
 * El cursor del tecleo. Un bloque fino que parpadea al final de lo escrito, para
 * que se vea que la frase sigue viniendo y no que se ha quedado a medias.
 */
#mlchat-root .mlchat-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--mlchat-gris);
  animation: mlchatCursor 0.9s steps(2, start) infinite;
}

@keyframes mlchatCursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Quien pide menos movimiento no ve parpadear nada. */
@media (prefers-reduced-motion: reduce) {
  #mlchat-root .mlchat-cursor { animation: none; }
}

#mlchat-root .mlchat-pensando {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 15px;
}

#mlchat-root .mlchat-pensando span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mlchat-gris);
  animation: mlchatPunto 1s infinite ease-in-out;
}

#mlchat-root .mlchat-pensando span:nth-child(2) { animation-delay: 0.18s; }
#mlchat-root .mlchat-pensando span:nth-child(3) { animation-delay: 0.36s; }

@keyframes mlchatPunto {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ── Fichas de producto ───────────────────────────────────────────────────── */

#mlchat-root .mlchat-cards {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

#mlchat-root .mlchat-card {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--mlchat-borde);
  border-radius: 11px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

#mlchat-root .mlchat-card:hover {
  border-color: var(--mlchat-primary-suave);
  transform: translateY(-1px);
  text-decoration: none;
  color: inherit;
}

#mlchat-root .mlchat-card img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 7px;
  background: var(--mlchat-fondo);
}

#mlchat-root .mlchat-card-datos {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#mlchat-root .mlchat-card-datos strong {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  /* Dos lineas y corta: el nombre completo de una luminaria son ocho palabras. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#mlchat-root .mlchat-card-precio {
  display: flex;
  gap: 6px;
  align-items: baseline;
}

#mlchat-root .mlchat-card-precio b {
  font-size: 14px;
  color: var(--mlchat-primary);
}

#mlchat-root .mlchat-card-precio s {
  font-size: 12px;
  color: var(--mlchat-gris);
}

#mlchat-root .mlchat-card-stock {
  font-size: 11.5px;
  color: #148a4a;
}

#mlchat-root .mlchat-card-stock.agotado { color: #b4443a; }

/* ── Cuando atiende una persona ──────────────────────────────────────────── */

/*
 * El nombre encima de la burbuja. Pequeño y gris: identifica sin competir con lo
 * que dice, que es lo que hay que leer.
 */
#mlchat-root .mlchat-quien {
  align-self: flex-start;
  margin: 2px 0 -4px 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--mlchat-gris);
}

/*
 * Y la burbuja del agente va distinta de la del bot: una persona y un modelo no
 * pueden parecer lo mismo en pantalla.
 */
#mlchat-root .mlchat-msg.agente {
  background: #eef3ff;
  box-shadow: 0 1px 3px rgba(27, 42, 74, 0.1);
}

/* ── Acciones dentro del hilo ────────────────────────────────────────────── */

/*
 * Van pegadas al mensaje, dentro del contenedor con scroll. En columna y
 * alineadas a la izquierda, como la burbuja del bot: así se leen como la
 * continuación de lo que acaba de decir, no como una barra de herramientas.
 */
#mlchat-root .mlchat-acciones {
  align-self: flex-start;
  max-width: 86%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: -3px;
}

#mlchat-root .mlchat-acciones .mlchat-opt {
  font-size: 12.5px;
  padding: 7px 14px;
}

/* ── Sugerencias plegadas ────────────────────────────────────────────────── */

#mlchat-root .mlchat-sug {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* El botón de abrir/cerrar no es una opción del menú: va más discreto. */
#mlchat-root .mlchat-sug-toggle {
  align-self: flex-start;
  font-size: 12.5px;
  padding: 7px 13px;
}

#mlchat-root .mlchat-vermas {
  align-self: flex-start;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--mlchat-primary);
  text-decoration: none;
  padding: 3px 1px;
}

#mlchat-root .mlchat-vermas:hover {
  text-decoration: underline;
  color: var(--mlchat-primary-suave);
}

#mlchat-root .mlchat-aviso-panel {
  align-self: flex-start;
  margin: 0;
  font-size: 12px;
  color: var(--mlchat-gris);
}

/* ── Panel lateral de sugerencias ────────────────────────────────────────── */

/*
 * A LA IZQUIERDA DEL CHAT, no encima ni debajo: el chat vive pegado a la
 * esquina derecha, así que el único sitio donde cabe una lista sin tapar la
 * conversación es a su lado. Comparte el alto del panel para que los dos
 * bordes superiores coincidan.
 */
#mlchat-root .mlchat-side {
  position: fixed;
  bottom: 92px;
  right: 412px;
  width: 320px;
  max-height: calc(100vh - 130px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(16, 24, 40, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483001;
  font-size: 14px;
  animation: mlchatIn 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

#mlchat-root .mlchat-side[hidden] { display: none; }

#mlchat-root .mlchat-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: var(--mlchat-fondo);
  border-bottom: 1px solid var(--mlchat-borde);
  flex-shrink: 0;
}

#mlchat-root .mlchat-side-head strong {
  font-size: 13.5px;
  color: var(--mlchat-texto);
}

#mlchat-root .mlchat-side-head .mlchat-close {
  color: var(--mlchat-gris);
  font-size: 22px;
}

#mlchat-root .mlchat-side-body {
  overflow-y: auto;
  padding: 12px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/*
 * Por debajo de 900px el panel no se pinta nunca (lo decide el JS), pero si una
 * ventana se encoge con el panel abierto, esto evita que se quede flotando en
 * medio de la pantalla hasta el siguiente repintado.
 */
@media (max-width: 899px) {
  #mlchat-root .mlchat-side { display: none; }
}

/* ── Opciones ─────────────────────────────────────────────────────────────── */

#mlchat-root .mlchat-opts {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 12px 16px 14px;
  background: var(--mlchat-fondo);
  flex-shrink: 0;
}

#mlchat-root .mlchat-opt {
  background: #fff;
  border: 1px solid var(--mlchat-borde);
  color: var(--mlchat-primary);
  border-radius: 100px;
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

#mlchat-root .mlchat-opt:hover {
  background: var(--mlchat-primary);
  border-color: var(--mlchat-primary);
  color: #fff;
}

#mlchat-root .mlchat-opt.ghost {
  border-style: dashed;
  font-weight: 500;
  color: var(--mlchat-gris);
}

#mlchat-root .mlchat-opt.ghost:hover {
  background: #e8ebf2;
  border-color: var(--mlchat-gris);
  color: var(--mlchat-texto);
}

/* ── Formulario del flujo de pedidos ─────────────────────────────────────── */

#mlchat-root .mlchat-form {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

#mlchat-root .mlchat-form input {
  border: 1px solid var(--mlchat-borde);
  border-radius: 9px;
  padding: 9px 13px;
  font-size: 13.5px;
  color: var(--mlchat-texto);
  background: #fff;
}

#mlchat-root .mlchat-form input:focus {
  outline: none;
  border-color: var(--mlchat-primary-suave);
}

#mlchat-root .mlchat-form-nota {
  margin: 1px 2px 3px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--mlchat-gris);
}

/* ── Entrada ──────────────────────────────────────────────────────────────── */

#mlchat-root .mlchat-input {
  display: flex;
  gap: 8px;
  padding: 11px 13px;
  border-top: 1px solid var(--mlchat-borde);
  background: #fff;
  flex-shrink: 0;
}

#mlchat-root .mlchat-input input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--mlchat-borde);
  border-radius: 100px;
  padding: 9px 14px;
  font-size: 14px;
  color: var(--mlchat-texto);
  background: #fff;
}

#mlchat-root .mlchat-input input:focus {
  outline: none;
  border-color: var(--mlchat-primary-suave);
}

#mlchat-root .mlchat-input button {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--mlchat-primary);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

#mlchat-root .mlchat-input button:hover:not(:disabled) { background: var(--mlchat-primary-suave); }
#mlchat-root .mlchat-input button:disabled { opacity: 0.4; cursor: default; }

/* ── Movil ────────────────────────────────────────────────────────────────── */

@media (max-width: 520px) {
  #mlchat-root .mlchat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 88vh;
    max-height: 88vh;
    border-radius: 14px 14px 0 0;
  }

  #mlchat-root .mlchat-btn {
    bottom: 16px;
    right: 16px;
  }
}

/* ── «Te han contestado»: el botón pide que lo miren ──────────────────────── */

/*
 * El brillo se queda hasta que se abre el chat; el temblor dura un segundo y
 * medio. Un icono vibrando sin parar en la esquina de una tienda es
 * insoportable, y lo primero que hace el visitante es irse de la página.
 */
#mlchat-root .mlchat-btn.avisa {
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.28),
    0 0 0 3px #ffdd00,
    0 0 18px 2px rgba(255, 221, 0, 0.75);
}

/* El punto ya estaba ahí: cambia de color, no aparece. */
#mlchat-root .mlchat-btn.avisa .mlchat-dot { background: #ffdd00; }

@keyframes mlchat-tiembla {
  0%, 100% { transform: translateX(0) rotate(0); }
  15%      { transform: translateX(-2px) rotate(-5deg); }
  30%      { transform: translateX(2px) rotate(5deg); }
  45%      { transform: translateX(-2px) rotate(-4deg); }
  60%      { transform: translateX(2px) rotate(4deg); }
  75%      { transform: translateX(-1px) rotate(-2deg); }
}

#mlchat-root .mlchat-btn.tiembla {
  animation: mlchat-tiembla 0.5s ease-in-out 2;
}

/*
 * Quien ha pedido que no se mueva nada se queda SIN TEMBLOR PERO CON BRILLO. El
 * aviso no desaparece: lo que molesta es el movimiento, no enterarse.
 */
@media (prefers-reduced-motion: reduce) {
  #mlchat-root .mlchat-btn.tiembla { animation: none; }
}

/* La cuenta de una alternativa a un producto agotado. */
#mlchat-root .mlchat-card-cuenta {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--mlchat-primary);
}

#mlchat-root .mlchat-card-cuenta b { font-weight: 600; }

/* 01/12/2026: mientras el asistente contesta, las opciones se ven inactivas (chat.js tampoco las atiende). */
#mlchat-root .mlchat-ocupado .mlchat-acciones .mlchat-opt { opacity: 0.45; cursor: default; pointer-events: none; }
