/* Botón flotante de WhatsApp con chat de preguntas frecuentes (scripts/chat.js). */
.rwc {
  --rwc-naranja: #fd5c00;
  --rwc-naranja-osc: #b03d00;
  --rwc-tinta: #0f0f11;
  --rwc-gris: #52525b;
  --rwc-linea: #e5e7eb;
  --rwc-crema: #f6f2ea;
  --rwc-wa: #25d366;
  --rwc-borde: max(18px, env(safe-area-inset-right, 0px));
  --rwc-abajo: max(18px, env(safe-area-inset-bottom, 0px));
  font-family: "Inter", system-ui, sans-serif;
  color: var(--rwc-tinta);
  -webkit-font-smoothing: antialiased;
}

.rwc *,
.rwc *::before,
.rwc *::after {
  box-sizing: border-box;
}

.rwc [hidden] {
  display: none !important;
}

.rwc :focus-visible {
  outline: 2.5px solid var(--rwc-naranja);
  outline-offset: 3px;
}

.rwc button,
.rwc input {
  font: inherit;
  color: inherit;
}

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

/* ---------- Botón y saludo ---------- */
.rwc-dock {
  position: fixed;
  right: var(--rwc-borde);
  bottom: var(--rwc-abajo);
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.rwc-lanzador {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 0 22px 0 7px;
  border: 0;
  border-radius: 999px;
  background: var(--rwc-tinta);
  color: #ffffff !important;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 14px 30px -10px rgba(15, 15, 17, 0.55);
  transition: transform 0.15s;
}

.rwc-lanzador:hover {
  transform: translateY(-2px);
}

.rwc-lanzador-wa {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--rwc-wa);
  color: #ffffff;
}

.rwc-lanzador-wa svg {
  width: 24px;
  height: 24px;
}

.rwc-saludo {
  position: relative;
  max-width: 270px;
  border-radius: 18px 18px 4px 18px;
  background: #ffffff;
  box-shadow: 0 18px 36px -14px rgba(20, 15, 10, 0.4), 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.rwc-saludo-abrir {
  display: block;
  width: 100%;
  padding: 12px 40px 12px 14px;
  border: 0;
  border-radius: inherit;
  background: none;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.rwc-saludo-abrir small {
  display: block;
  margin-top: 2px;
  color: var(--rwc-gris);
  font-size: 13px;
  font-weight: 500;
}

.rwc-saludo-x {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--rwc-gris);
  cursor: pointer;
}

.rwc-saludo-x:hover {
  background: #f4f4f5;
}

.rwc-saludo-x svg,
.rwc-cerrar svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
}

@media (prefers-reduced-motion: no-preference) {
  .rwc-saludo:not([hidden]) {
    animation: rwc-asoma 0.45s cubic-bezier(0.2, 1.3, 0.4, 1) both;
  }
}

@keyframes rwc-asoma {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.9);
  }
}

/* ---------- Ventana ----------
   El alto nunca pasa de la pantalla: la ventana se limita al espacio libre arriba del botón
   y el hilo es lo único que se encoge. */
.rwc-chat {
  position: fixed;
  right: var(--rwc-borde);
  bottom: calc(var(--rwc-abajo) + 72px);
  z-index: 71;
  display: flex;
  flex-direction: column;
  width: 380px;
  max-width: calc(100vw - 36px);
  height: 600px;
  max-height: calc(100vh - var(--rwc-abajo) - 96px);
  max-height: calc(100dvh - var(--rwc-abajo) - 96px);
  overflow: hidden;
  border-radius: 22px;
  background: #ffffff;
  box-shadow: 0 30px 60px -20px rgba(20, 15, 10, 0.45), 0 0 0 1px rgba(0, 0, 0, 0.06);
  transform-origin: bottom right;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.rwc-chat[data-cerrado] {
  visibility: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  pointer-events: none;
}

.rwc-barra {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px 12px 16px;
  background: var(--rwc-naranja);
  color: #ffffff;
}

.rwc-barra > span:nth-child(2) {
  flex: 1;
  min-width: 0;
}

.rwc-barra img {
  display: block;
  width: auto;
  height: 18px;
}

.rwc-barra small {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  opacity: 0.9;
}

.rwc-avatar {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  color: var(--rwc-naranja);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.rwc-avatar::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #3ddc84;
  box-shadow: 0 0 0 2px var(--rwc-naranja);
}

.rwc-cerrar {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
}

.rwc-cerrar:hover {
  background: rgba(255, 255, 255, 0.16);
}

.rwc-cerrar svg {
  width: 20px;
  height: 20px;
}

.rwc-hilo {
  flex: 1 1 auto;
  min-height: 120px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 14px;
  background: var(--rwc-crema);
  scroll-behavior: smooth;
}

.rwc-msg {
  align-self: flex-start;
  max-width: 86%;
  margin: 0;
  padding: 9px 12px;
  border-radius: 4px 16px 16px 16px;
  background: #ffffff;
  color: #1f1d1a;
  font-size: 15px;
  line-height: 1.45;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

.rwc-msg-yo {
  align-self: flex-end;
  border-radius: 16px 4px 16px 16px;
  background: var(--rwc-tinta);
  color: #ffffff;
}

.rwc-accion {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--rwc-naranja);
  color: #ffffff !important;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none !important;
}

.rwc-accion-wa {
  background: var(--rwc-wa);
  color: #ffffff !important;
}

.rwc-accion svg {
  width: 16px;
  height: 16px;
}

@media (prefers-reduced-motion: no-preference) {
  .rwc-msg.rwc-nueva {
    animation: rwc-llega 0.35s ease both;
  }
}

@keyframes rwc-llega {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

.rwc-escribiendo {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 4px 16px 16px 16px;
  background: #ffffff;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

.rwc-escribiendo span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b9b0a6;
  animation: rwc-punto 1s infinite ease-in-out;
}

.rwc-escribiendo span:nth-child(2) {
  animation-delay: 0.15s;
}

.rwc-escribiendo span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes rwc-punto {
  50% {
    opacity: 0.5;
    transform: translateY(-4px);
  }
}

.rwc-preguntas {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--rwc-linea);
}

.rwc-preguntas button {
  padding: 6px 10px;
  border: 1.5px solid var(--rwc-naranja);
  border-radius: 999px;
  background: #ffffff;
  color: var(--rwc-naranja-osc);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.rwc-preguntas button:hover {
  background: var(--rwc-naranja);
  color: #ffffff;
}

.rwc-preguntas button.rwc-usada {
  border-color: var(--rwc-linea);
  background: #f4f4f5;
  color: #8a8a93;
}

.rwc-preguntas button.rwc-propia {
  border-color: var(--rwc-tinta);
  background: #ffffff;
  color: var(--rwc-tinta);
}

.rwc-preguntas button.rwc-propia:hover {
  background: var(--rwc-tinta);
  color: #ffffff;
}

.rwc-redactor {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 14px;
}

.rwc-redactor input {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 10px 16px;
  border: 2px solid var(--rwc-linea);
  border-radius: 999px;
  background: #ffffff;
  font-size: 16px;
}

.rwc-redactor input:focus {
  border-color: var(--rwc-wa);
  outline: none;
}

.rwc-redactor button {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--rwc-wa);
  color: #ffffff;
  cursor: pointer;
}

.rwc-redactor button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Pantallas muy bajas: si no caben todas, las preguntas son lo único con scroll propio. */
@media (max-height: 520px) {
  .rwc-preguntas {
    max-height: 96px;
    overflow-y: auto;
  }
}

/* ---------- Celular: la ventana ocupa casi toda la pantalla y tapa el botón ---------- */
@media (max-width: 640px) {
  .rwc {
    --rwc-borde: max(14px, env(safe-area-inset-right, 0px));
    --rwc-abajo: max(14px, env(safe-area-inset-bottom, 0px));
  }

  .rwc-lanzador {
    min-height: 54px;
    padding-right: 18px;
    font-size: 15px;
  }

  .rwc-lanzador-wa {
    width: 40px;
    height: 40px;
  }

  .rwc-chat {
    left: max(8px, env(safe-area-inset-left, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: none;
    height: 640px;
    max-height: calc(100vh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    transform-origin: bottom center;
  }

  .rwc.rwc-abierto .rwc-dock {
    visibility: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rwc *,
  .rwc *::before,
  .rwc *::after {
    animation: none !important;
    transition: none !important;
  }
}
