/* Chat de las webs (plantilla/chat, ver LEEME.md). Cada web le da su aspecto con estas variables,
   puestas en su propio CSS sobre .chat (o :root). Los valores de aquí son solo un respaldo neutro:
   una web nunca debería salir con ellos. */
:where(.chat) {
  --chat-fondo: #fff;              /* fondo del panel */
  --chat-tinta: #1d1d1d;           /* texto */
  --chat-tinta-2: #555;            /* texto secundario (nota, «escribiendo») */
  --chat-suave: #eee;              /* burbuja de las respuestas */
  --chat-linea: rgba(0, 0, 0, .14);
  --chat-marca: #222;              /* botón flotante y burbuja de la persona */
  --chat-marca-2: #000;            /* botón flotante al pasar el ratón */
  --chat-sobre-marca: #fff;
  --chat-icono: currentColor;      /* icono del botón flotante */
  --chat-acento: #222;             /* botón Enviar, bordes de las sugerencias */
  --chat-acento-2: #000;
  --chat-sobre-acento: #fff;
  --chat-contorno: #fff;           /* aro del botón flotante, para que se vea sobre fondos de su color */
  --chat-radio: 6px;
  --chat-display: system-ui, sans-serif;
  --chat-texto: system-ui, sans-serif;
  --chat-curva: cubic-bezier(.22, 1, .36, 1);
  --chat-abajo: 16px;              /* distancia del botón al borde de abajo (súbela si hay barra fija) */
}

.chat[hidden], .chat__panel[hidden], .chat__sugerencias[hidden] { display: none; }
.chat__oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.chat__abrir {
  position: fixed; right: 16px; bottom: calc(var(--chat-abajo) + env(safe-area-inset-bottom)); z-index: 45;
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border: 0; border-radius: var(--chat-radio); background: var(--chat-marca); color: var(--chat-sobre-marca); cursor: pointer;
  font: 600 15px/1 var(--chat-texto); box-shadow: 0 0 0 2px var(--chat-contorno);
  transition: background-color .25s, transform .45s var(--chat-curva), bottom .45s var(--chat-curva);
}
.chat__abrir svg { color: var(--chat-icono); flex: none; }
.chat__abrir:hover { background: var(--chat-marca-2); }
.chat__abrir:active { transform: scale(.98); }
.chat.abierto .chat__abrir { transform: translateX(calc(100% + 24px)); }

.chat__panel {
  position: fixed; z-index: 50; right: 8px; left: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; max-height: min(78svh, 640px);
  background: var(--chat-fondo); color: var(--chat-tinta); border-radius: var(--chat-radio);
  box-shadow: 0 0 0 1px var(--chat-linea), 0 18px 48px rgba(0, 0, 0, .22);
  font-family: var(--chat-texto);
  opacity: 0; transform: translateX(32px);
  transition: opacity .35s ease-out, transform .5s var(--chat-curva);
}
@media (min-width: 600px) { .chat__panel { left: auto; right: 16px; bottom: 16px; width: 380px; } }
.chat.abierto .chat__panel { opacity: 1; transform: none; }

.chat__cabecera { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 18px; border-bottom: 1px solid var(--chat-linea); }
.chat__titulo { margin: 0; font: 500 20px/1.2 var(--chat-display); letter-spacing: -.01em; }
.chat__cerrar { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: inherit; border-radius: var(--chat-radio); cursor: pointer; }
.chat__cerrar:hover { background: var(--chat-suave); }

.chat__mensajes { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px 18px 8px; display: flex; flex-direction: column; gap: 10px; font-size: 16px; line-height: 1.45; }
.chat__msg { margin: 0; max-width: 88%; padding: 10px 14px; border-radius: var(--chat-radio); animation: chat-entra .45s var(--chat-curva) both; }
.chat__msg--asistente { align-self: flex-start; background: var(--chat-suave); }
.chat__msg--usuario { align-self: flex-end; background: var(--chat-marca); color: var(--chat-sobre-marca); --desde: 14px; }
.chat__msg--espera { color: var(--chat-tinta-2); }
@keyframes chat-entra { from { opacity: 0; transform: translateX(var(--desde, -14px)); } }

.chat__sugerencias { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 18px 12px; }
.chat__sugerencias button {
  min-height: 44px; padding: 8px 14px; border: 0; border-radius: var(--chat-radio); cursor: pointer; text-align: left;
  background: transparent; color: var(--chat-tinta); box-shadow: inset 0 0 0 1.5px var(--chat-acento); font: 500 15px/1.3 var(--chat-texto);
  transition: background-color .2s, color .2s;
}
.chat__sugerencias button:hover { background: var(--chat-acento); color: var(--chat-sobre-acento); }
.chat__sugerencias button:active { transform: scale(.98); }

.chat__form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--chat-linea); }
.chat__form input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 14px; border: 0; border-radius: var(--chat-radio);
  background: #fff; color: #1d1d1d; box-shadow: inset 0 0 0 1.5px var(--chat-linea); font: 400 16px/1 var(--chat-texto);
}
.chat__form input:focus-visible { outline: 2px solid var(--chat-acento); outline-offset: 0; }
.chat__enviar {
  min-height: 48px; padding: 0 16px; border: 0; border-radius: var(--chat-radio); cursor: pointer;
  background: var(--chat-acento); color: var(--chat-sobre-acento); font: 600 16px/1 var(--chat-texto);
  transition: background-color .2s, transform .12s;
}
.chat__enviar:hover { background: var(--chat-acento-2); }
.chat__enviar:active { transform: scale(.98); }
.chat__enviar:disabled { opacity: .6; cursor: wait; }

.chat__pie { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding: 0 18px 12px; font-size: 13px; color: var(--chat-tinta-2); }
.chat__nota { margin: 0; }
.chat__contacto { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; color: var(--chat-tinta); text-decoration: underline; text-decoration-color: var(--chat-acento); text-underline-offset: 4px; }
