/* Widget del chat de Linvitia (LINVITIA-82). Sin librerias; compatible con la CSP del sitio. */

:root {
  --lnv-chat-fondo: #ffffff;
  --lnv-chat-texto: #1f2430;
  --lnv-chat-borde: #d8dbe3;
  --lnv-chat-acento: #8a2f5f;
  --lnv-chat-acento-texto: #ffffff;
  --lnv-chat-anelia: #f3eef1;
  --lnv-chat-cliente: #e6f0ea;
}

@media (prefers-color-scheme: dark) {
  :root {
    --lnv-chat-fondo: #1c1f27;
    --lnv-chat-texto: #eef0f5;
    --lnv-chat-borde: #3a3f4c;
    --lnv-chat-acento: #d98ab5;
    --lnv-chat-acento-texto: #1c1f27;
    --lnv-chat-anelia: #2a2d38;
    --lnv-chat-cliente: #243a2f;
  }
}

.lnv-chat-lanzador {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1000;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 24px;
  background: var(--lnv-chat-acento);
  color: var(--lnv-chat-acento-texto);
  font: 600 1rem/1 system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.lnv-chat-panel {
  position: fixed;
  right: 16px;
  bottom: 76px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 100px));
  border: 1px solid var(--lnv-chat-borde);
  border-radius: 12px;
  background: var(--lnv-chat-fondo);
  color: var(--lnv-chat-texto);
  font: 1rem/1.45 system-ui, sans-serif;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.lnv-chat-panel[hidden] {
  display: none;
}

.lnv-chat-cabecera {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--lnv-chat-borde);
}

.lnv-chat-titulo {
  margin: 0;
  font-size: 1.05rem;
}

.lnv-chat-cerrar {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.6rem;
  cursor: pointer;
}

.lnv-chat-registro {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

.lnv-chat-mensaje {
  max-width: 85%;
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.lnv-chat-anelia {
  background: var(--lnv-chat-anelia);
  border-bottom-left-radius: 2px;
}

.lnv-chat-cliente {
  margin-left: auto;
  background: var(--lnv-chat-cliente);
  border-bottom-right-radius: 2px;
}

.lnv-chat-mensaje a {
  color: var(--lnv-chat-acento);
}

.lnv-chat-estado {
  min-height: 1.4em;
  margin: 0;
  padding: 0 14px;
  font-size: 0.875rem;
  opacity: 0.85;
}

.lnv-chat-formulario {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--lnv-chat-borde);
}

.lnv-chat-etiqueta {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.lnv-chat-entrada {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--lnv-chat-borde);
  border-radius: 8px;
  background: var(--lnv-chat-fondo);
  color: inherit;
  font: inherit;
  resize: none;
}

.lnv-chat-enviar {
  min-width: 44px;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--lnv-chat-acento);
  color: var(--lnv-chat-acento-texto);
  font: 600 1rem system-ui, sans-serif;
  cursor: pointer;
}

.lnv-chat-lanzador:focus-visible,
.lnv-chat-cerrar:focus-visible,
.lnv-chat-enviar:focus-visible,
.lnv-chat-entrada:focus-visible,
.lnv-chat-mensaje a:focus-visible {
  outline: 3px solid var(--lnv-chat-acento);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  .lnv-chat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .lnv-chat-panel {
    animation: lnv-chat-entrada 0.18s ease-out;
  }
}

@keyframes lnv-chat-entrada {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* LINVITIA-83: respuestas rapidas, imagenes y reintento. */
.lnv-chat-opciones {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.lnv-chat-opcion,
.lnv-chat-reintentar {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--lnv-chat-acento);
  border-radius: 20px;
  background: transparent;
  color: var(--lnv-chat-acento);
  font: 600 0.95rem system-ui, sans-serif;
  cursor: pointer;
}

.lnv-chat-opcion:disabled {
  opacity: 0.5;
  cursor: default;
}

.lnv-chat-opcion:focus-visible,
.lnv-chat-reintentar:focus-visible {
  outline: 3px solid var(--lnv-chat-acento);
  outline-offset: 2px;
}

.lnv-chat-mensaje img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* LINVITIA-86: cabecera con WhatsApp, indicador de escritura, adjuntar foto y 360 px. */
.lnv-chat-cabecera {
  flex-wrap: wrap;
  gap: 4px 8px;
}

.lnv-chat-titulo {
  flex: 1 1 auto;
}

.lnv-chat-whatsapp {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--lnv-chat-acento);
  border-radius: 22px;
  background: transparent;
  color: var(--lnv-chat-acento);
  font: 600 0.9rem system-ui, sans-serif;
  cursor: pointer;
}

.lnv-chat-whatsapp:focus-visible,
.lnv-chat-adjuntar:focus-visible {
  outline: 3px solid var(--lnv-chat-acento);
  outline-offset: 2px;
}

.lnv-chat-formulario {
  grid-template-columns: auto 1fr auto;
  align-items: end;
}

.lnv-chat-adjuntar {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--lnv-chat-borde);
  border-radius: 8px;
  background: transparent;
  font-size: 1.25rem;
  cursor: pointer;
}

.lnv-chat-archivo[hidden] {
  display: none;
}

/* LINVITIA-208: boton de nota de voz (solo si el navegador sabe grabar). */
.lnv-chat-con-voz {
  grid-template-columns: auto auto 1fr auto;
}

.lnv-chat-grabar {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--lnv-chat-borde);
  border-radius: 8px;
  background: transparent;
  font-size: 1.25rem;
  cursor: pointer;
}

.lnv-chat-grabar[hidden] {
  display: none;
}

.lnv-chat-grabar[aria-pressed='true'] {
  border-color: #b3261e;
  background: #b3261e;
  color: #fff;
}

.lnv-chat-grabar:focus-visible {
  outline: 3px solid var(--lnv-chat-acento);
  outline-offset: 2px;
}

.lnv-chat-escribiendo {
  display: flex;
  gap: 4px;
  width: fit-content;
}

.lnv-chat-punto {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}

@media (prefers-reduced-motion: no-preference) {
  .lnv-chat-punto {
    animation: lnv-chat-punto 1.2s infinite ease-in-out;
  }

  .lnv-chat-punto:nth-child(2) {
    animation-delay: 0.2s;
  }

  .lnv-chat-punto:nth-child(3) {
    animation-delay: 0.4s;
  }
}

@keyframes lnv-chat-punto {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}

/* A 360 px el panel ocupa toda la pantalla y la cabecera pasa a dos filas sin desbordar. */
@media (max-width: 400px) {
  .lnv-chat-whatsapp {
    flex: 1 1 100%;
    order: 3;
  }

  .lnv-chat-mensaje {
    max-width: 92%;
  }
}

/* LINVITIA-89: avisos del sistema en el registro (cambio de canal). */
.lnv-chat-sistema {
  margin-right: auto;
  margin-left: auto;
  background: transparent;
  border: 1px dashed var(--lnv-chat-borde);
  font-size: 0.875rem;
  text-align: center;
}
