/* =========================================================================
   Remote Revenue - Chat widget (assets/js/chat.js)
   Burbuja flotante + panel de chat estilo WhatsApp, con la paleta del sitio
   (dark + lime). Reutiliza los tokens :root de styles.css.
   Stacking: nav 50, grain 60, cookie banner 200. Lanzador 120, panel 130.
   ========================================================================= */

.rrchat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 120;
  font-family: var(--font-body);
}

/* Si el aviso de cookies está visible, subimos el widget por encima de él (lo activa
   el JS, que mide la altura real del banner en --rr-cookie-h para no taparse). */
.rrchat.is-raised { bottom: calc(var(--rr-cookie-h, 60px) + 32px); }

/* ---------- Lanzador (burbuja) ---------- */
.rrchat__bubble {
  width: 60px;
  height: 60px;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  color: var(--on-accent);
  box-shadow: var(--shadow-accent), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.rrchat__bubble:hover { transform: translateY(-2px) scale(1.03); }
.rrchat__bubble:active { transform: translateY(0) scale(0.97); }
.rrchat__bubble svg { width: 28px; height: 28px; }
.rrchat__bubble .rrchat__ico--close { display: none; }

/* Punto de aviso (nuevo mensaje de bienvenida) */
.rrchat__dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ff5d5d;
  border: 2px solid var(--bg);
}

/* ---------- Panel ---------- */
.rrchat__panel {
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 130;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100dvh - 120px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-card);
  box-shadow: var(--shadow), var(--hi);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.28s var(--ease), transform 0.28s var(--ease);
}
.rrchat.is-raised .rrchat__panel { bottom: calc(var(--rr-cookie-h, 60px) + 104px); }

/* Estado abierto */
.rrchat.is-open .rrchat__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.rrchat.is-open .rrchat__ico--chat { display: none; }
.rrchat.is-open .rrchat__bubble .rrchat__ico--close { display: block; }
.rrchat.is-open .rrchat__dot { display: none; }

/* ---------- Header ---------- */
.rrchat__head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border-bottom: 1px solid var(--line);
}
.rrchat__avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rrchat__titles { flex: 1 1 auto; min-width: 0; }
.rrchat__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}
.rrchat__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--text-mute);
}
.rrchat__status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 7px var(--accent);
}
.rrchat__close {
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  color: var(--text-mute);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.rrchat__close:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.rrchat__close svg { width: 18px; height: 18px; }

/* ---------- Log de mensajes ---------- */
.rrchat__log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(196, 240, 66, 0.035), transparent 60%),
    var(--bg-2);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.rrchat__log::-webkit-scrollbar { width: 8px; }
.rrchat__log::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; }

/* Burbujas tipo WhatsApp */
.rrchat__msg {
  max-width: 82%;
  padding: 9px 13px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  border: 1px solid var(--line);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.rrchat__msg--bot {
  align-self: flex-start;
  background: var(--surface-2);
  border-radius: 14px 14px 14px 4px;
}
.rrchat__msg--user {
  align-self: flex-end;
  background: var(--accent-dim);
  border-color: var(--accent-line);
  color: var(--text);
  border-radius: 14px 14px 4px 14px;
}

/* Indicador "escribiendo..." */
.rrchat__typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px 14px 14px 4px;
}
.rrchat__typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-mute);
  animation: rrchatDot 1.2s infinite ease-in-out both;
}
.rrchat__typing span:nth-child(2) { animation-delay: 0.18s; }
.rrchat__typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes rrchatDot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Chips de respuesta rápida ---------- */
.rrchat__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 14px 10px;
  background: var(--bg-2);
}
.rrchat__chip {
  font-size: 0.8rem;
  color: var(--text-soft);
  padding: 7px 13px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.025);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.rrchat__chip:hover {
  border-color: var(--accent-line);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ---------- Pie: WhatsApp + input ---------- */
.rrchat__foot {
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.rrchat__wa {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-soft);
  border-bottom: 1px solid var(--line);
  transition: color 0.2s, background 0.2s;
}
.rrchat__wa:hover { color: var(--accent); background: var(--accent-dim); }
.rrchat__wa svg { width: 17px; height: 17px; flex: 0 0 auto; }
.rrchat__wa[hidden] { display: none; }

.rrchat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
}
.rrchat__input {
  flex: 1 1 auto;
  resize: none;
  max-height: 96px;
  min-height: 40px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(10, 11, 13, 0.5);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-input);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.rrchat__input::placeholder { color: var(--text-mute); }
.rrchat__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.rrchat__send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  color: var(--on-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--hi);
  transition: transform 0.2s var(--ease), opacity 0.2s;
}
.rrchat__send:hover { transform: translateY(-1px); }
.rrchat__send:disabled { opacity: 0.45; cursor: default; transform: none; }
.rrchat__send svg { width: 18px; height: 18px; }

.rrchat__disclaimer {
  padding: 0 14px 10px;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--text-mute);
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .rrchat { right: 16px; bottom: 16px; }
  /* La burbuja se eleva sobre el banner (más alto en móvil por ir en columna).
     El fallback es generoso por si el JS aún no ha medido la altura real. */
  .rrchat.is-raised { bottom: calc(var(--rr-cookie-h, 190px) + 24px); }
  .rrchat__panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  /* A pantalla completa el panel ocupa todo, así que ignora el offset del banner. */
  .rrchat.is-raised .rrchat__panel { bottom: 0; }
  /* Abierto, el panel a pantalla completa debe quedar SOBRE el aviso de cookies
     (z 200) para que el banner no tape el campo de escritura. Hay que elevar el
     CONTENEDOR (no el panel): .rrchat crea su propio contexto de apilamiento, así
     que subir solo el panel no basta. */
  .rrchat.is-open { z-index: 210; }
}

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  .rrchat__bubble,
  .rrchat__panel,
  .rrchat__send { transition: none; }
  .rrchat__typing span { animation: none; }
  .rrchat.is-open .rrchat__panel { transform: none; }
}
