/* =========================================================================
   Remote Revenue - CONCEPTO "Editorial Luxe" - Chat widget
   Burbuja flotante + panel estilo WhatsApp, en la paleta editorial
   (papel crema + espresso + oliva). Reutiliza los tokens :root de concept.css.
   Esmeralda solo para la señal de "en linea". Lanzador 120, panel 130.
   ========================================================================= */

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

/* ---------- Lanzador (burbuja) ---------- */
.rrchat__bubble {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, #25d366, #1da851);
  color: #fff;
  box-shadow: 0 10px 26px rgba(37, 211, 102, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  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: 27px; height: 27px; }
.rrchat__bubble .rrchat__ico--close { display: none; }

/* Punto de aviso (mensaje de bienvenida sin leer) */
.rrchat__dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--terra);
  border: 2px solid var(--paper);
}

/* ---------- Panel ---------- */
.rrchat__panel {
  position: fixed;
  right: 22px;
  bottom: 94px;
  z-index: 130;
  width: 384px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100dvh - 122px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-soft);
  box-shadow: var(--shadow-lift);
  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);
}

/* 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(--paper-2), var(--card));
  border-bottom: 1px solid var(--line);
}
.rrchat__avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(88, 106, 43, 0.14);
  box-shadow: inset 0 0 0 1px rgba(88, 106, 43, 0.3);
  color: var(--olive-deep);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  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.98rem;
  color: var(--ink);
}
.rrchat__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--ink-mute);
}
.rrchat__status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 7px rgba(22, 163, 90, 0.6);
}
.rrchat__close {
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  color: var(--ink-mute);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.rrchat__close:hover { background: rgba(36, 27, 18, 0.06); color: var(--ink); }
.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(232, 161, 76, 0.07), transparent 60%),
    var(--paper);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.rrchat__log::-webkit-scrollbar { width: 8px; }
.rrchat__log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

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

/* Indicador "escribiendo..." */
.rrchat__typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px 14px 14px 4px;
}
.rrchat__typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-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(--paper);
}
.rrchat__chip {
  font-size: 0.8rem;
  color: var(--ink-soft);
  padding: 7px 13px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--card);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.rrchat__chip:hover {
  border-color: rgba(88, 106, 43, 0.5);
  color: var(--olive-deep);
  background: rgba(88, 106, 43, 0.08);
}

/* ---------- Pie: WhatsApp + input ---------- */
.rrchat__foot {
  border-top: 1px solid var(--line);
  background: var(--card);
}
.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(--ink-soft);
  border-bottom: 1px solid var(--line);
  transition: color 0.2s, background 0.2s;
}
.rrchat__wa:hover { color: var(--emerald-deep); background: rgba(22, 163, 90, 0.07); }
.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(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-soft);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.rrchat__input::placeholder { color: var(--ink-mute); }
.rrchat__input:focus {
  outline: none;
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(88, 106, 43, 0.15);
}
.rrchat__send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--paper);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-amb);
  transition: transform 0.2s var(--ease), opacity 0.2s;
}
.rrchat__send:hover { transform: translateY(-1px); }
.rrchat__send:disabled { opacity: 0.4; 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(--ink-mute);
  text-align: center;
}

/* ---------- Responsive (pantalla completa en movil) ---------- */
@media (max-width: 480px) {
  .rrchat { right: 16px; bottom: 16px; }
  .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;
  }
  .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; }
}

/* ---------- Elevar la burbuja/panel por encima del aviso de cookies ----------
   assets/js/chat.js mide la altura del banner y la expone en --rr-cookie-h. */
.rrchat.is-raised{bottom:calc(32px + var(--rr-cookie-h,0px));}
.rrchat.is-raised .rrchat__panel{bottom:calc(104px + var(--rr-cookie-h,0px));}
@media (max-width:480px){
  .rrchat.is-raised{bottom:calc(16px + 16px + var(--rr-cookie-h,0px));}
  .rrchat.is-raised .rrchat__panel{bottom:0;}
}
