/* =========================================
   WEBCHAT AVAIA
   Todo con prefijo .avaia-wc- para no afectar
   el resto de la web ni el chat demostrativo.
========================================= */

.avaia-wc {
  --wc-green: #13b866;
  --wc-green-dark: #0a7f47;
  --wc-green-soft: #e9f8f0;
  --wc-ink: #101512;
  --wc-text: #26302a;
  --wc-muted: #66706a;
  --wc-line: #e4ebe6;
  --wc-bubble: #f2f5f3;
  --wc-shadow: 0 24px 70px rgba(10, 30, 18, .22), 0 4px 16px rgba(10, 30, 18, .08);

  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10000;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--wc-text);
  -webkit-font-smoothing: antialiased;
}

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

.avaia-wc [hidden] {
  display: none !important;
}

/* ---------- Botón flotante (siempre visible con el chat cerrado) ---------- */

.avaia-wc-launcher {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  padding: 0 20px 0 8px;
  height: 52px;
  border: 0;
  border-radius: 999px;
  background: #ffffff;
  color: var(--wc-ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--wc-shadow);
  cursor: pointer;
  transition: transform .2s ease;
}

.avaia-wc-launcher:hover {
  transform: translateY(-2px);
}

.avaia-wc-launcher .avaia-wc-avatar {
  width: 38px;
  height: 38px;
  font-size: 13px;
}

/* ---------- Panel ---------- */

.avaia-wc-panel {
  width: 380px;
  height: min(620px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--wc-line);
  border-radius: 22px;
  box-shadow: var(--wc-shadow);
  transform-origin: bottom right;
  animation: avaia-wc-in .22s ease-out;
}

@keyframes avaia-wc-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(.98);
  }
}

/* Header */

.avaia-wc-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 16px 18px;
  border-bottom: 1px solid var(--wc-line);
  background: #ffffff;
}

.avaia-wc-avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--wc-ink);
  color: #20ef7d;
  font-weight: 900;
  font-size: 14px;
  letter-spacing: .02em;
}

.avaia-wc-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.avaia-wc-title strong {
  color: var(--wc-ink);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .01em;
}

.avaia-wc-title span {
  color: var(--wc-muted);
  font-size: 12.5px;
}

.avaia-wc-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--wc-green-soft);
  color: var(--wc-green-dark);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.avaia-wc-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wc-green);
  box-shadow: 0 0 0 3px rgba(19, 184, 102, .18);
}

.avaia-wc-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--wc-muted);
  cursor: pointer;
}

.avaia-wc-close:hover {
  background: var(--wc-bubble);
  color: var(--wc-ink);
}

.avaia-wc-close svg {
  width: 18px;
  height: 18px;
}

/* Mensajes */

.avaia-wc-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 16px 8px;
  background: #ffffff;
}

.avaia-wc-msg {
  display: flex;
  margin: 0 0 10px;
}

.avaia-wc-msg.is-user {
  justify-content: flex-end;
}

.avaia-wc-bubble {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.avaia-wc-msg.is-assistant .avaia-wc-bubble {
  background: var(--wc-bubble);
  color: var(--wc-text);
  border-bottom-left-radius: 5px;
}

.avaia-wc-msg.is-user .avaia-wc-bubble {
  background: var(--wc-green-dark);
  color: #ffffff;
  border-bottom-right-radius: 5px;
}

.avaia-wc-bubble a {
  color: var(--wc-green-dark);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.avaia-wc-msg.is-user .avaia-wc-bubble a {
  color: #ffffff;
}

/* Escribiendo */

.avaia-wc-typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 9px 13px;
  border-radius: 16px;
  border-bottom-left-radius: 5px;
  background: var(--wc-bubble);
  color: var(--wc-muted);
  font-size: 12.5px;
}

.avaia-wc-dots {
  display: inline-flex;
  gap: 3px;
}

.avaia-wc-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--wc-green);
  animation: avaia-wc-bounce 1s infinite;
}

.avaia-wc-dots i:nth-child(2) {
  animation-delay: .15s;
}

.avaia-wc-dots i:nth-child(3) {
  animation-delay: .3s;
}

@keyframes avaia-wc-bounce {
  50% {
    opacity: .3;
    transform: translateY(-2px);
  }
}

/* Avisos (límites, errores) */

.avaia-wc-notice {
  margin: 4px 8px 12px;
  padding: 9px 12px;
  border-radius: 12px;
  background: #fff6e6;
  color: #7a4b00;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

/* Conversación finalizada */

.avaia-wc-end {
  margin: 6px 4px 12px;
  padding: 14px;
  border: 1px solid var(--wc-line);
  border-radius: 16px;
  background: var(--wc-green-soft);
  text-align: center;
}

.avaia-wc-end p {
  margin: 0 0 12px;
  color: var(--wc-text);
  font-size: 14px;
  line-height: 1.45;
}

.avaia-wc-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--wc-green);
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .03em;
  text-decoration: none;
  transition: background .15s ease;
}

.avaia-wc-cta:hover {
  background: var(--wc-green-dark);
}

.avaia-wc.is-ended .avaia-wc-inputbox {
  background: var(--wc-bubble);
  opacity: .7;
}

.avaia-wc.is-ended .avaia-wc-input {
  cursor: not-allowed;
}

.avaia-wc.is-ended .avaia-wc-hint {
  color: var(--wc-muted);
  font-weight: 600;
}

/* Input */

.avaia-wc-form {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--wc-line);
  background: #ffffff;
}

.avaia-wc-inputbox {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--wc-line);
  border-radius: 18px;
  background: #fbfcfb;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.avaia-wc-inputbox:focus-within {
  border-color: var(--wc-green);
  box-shadow: 0 0 0 3px rgba(19, 184, 102, .14);
}

.avaia-wc-input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 120px;
  padding: 8px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--wc-ink);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.4;
}

.avaia-wc-input::placeholder {
  color: #8b958f;
}

.avaia-wc-send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--wc-green);
  color: #ffffff;
  cursor: pointer;
  transition: background .15s ease, opacity .15s ease;
}

.avaia-wc-send:hover {
  background: var(--wc-green-dark);
}

.avaia-wc-send:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.avaia-wc-send svg {
  width: 17px;
  height: 17px;
}

.avaia-wc-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  padding: 0 4px;
  color: #8b958f;
  font-size: 11px;
}

.avaia-wc-count.is-warn {
  color: #b35c00;
}

.avaia-wc-turnstile:empty {
  display: none;
}

.avaia-wc-turnstile {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.avaia-wc :focus-visible {
  outline: 2px solid var(--wc-green);
  outline-offset: 2px;
}

.avaia-wc-input:focus-visible {
  outline: 0;
}

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

/* ---------- Mobile: pantalla completa ---------- */

@media (max-width: 560px) {

  .avaia-wc {
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  .avaia-wc.is-open {
    inset: 0;
  }

  /* Launcher compacto: solo el círculo "AV" (el texto queda en aria-label). */
  .avaia-wc-launcher {
    width: 56px;
    height: 56px;
    padding: 0;
    gap: 0;
    justify-content: center;
    font-size: 0;
  }

  /* Aro blanco de 3px: se distingue sobre fondos claros y oscuros. */
  .avaia-wc-launcher .avaia-wc-avatar {
    width: 50px;
    height: 50px;
    font-size: 16px;
  }

  .avaia-wc-panel {
    width: 100%;
    height: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .avaia-wc-input {
    font-size: 16px; /* evita el zoom automático de iOS */
  }

  .avaia-wc-header {
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .avaia-wc-form {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

html.avaia-wc-lock,
html.avaia-wc-lock body {
  overflow: hidden;
}
