/* Richway Chat Widget — v2.0.0 */

/* ── Theme isolation: neutralise inherited font/text from theme ─────────
   NOTE: Do NOT put "all: unset !important" here — .rw-chat button has
   specificity (0,1,1) which would beat individual class rules (0,1,0)
   and wipe their styles. Each component resets itself in its own rule.  */
.rw-chat, .rw-chat * {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif !important;
  letter-spacing: normal !important;
  text-transform: none !important;
  -webkit-font-smoothing: antialiased !important;
}
/* Baseline button/input appearance reset — low-level only, no all:unset */
.rw-chat button {
  -webkit-appearance: none !important;
  appearance: none !important;
}
.rw-chat input[type="text"],
.rw-chat input[type="email"] {
  -webkit-appearance: none !important;
  appearance: none !important;
}

/* ── Panel ───────────────────────────────────────────────────── */
.rw-chat {
  position: fixed;
  right: max(var(--rw-right, 22px), env(safe-area-inset-right));
  bottom: calc(max(var(--rw-bottom, 22px), env(safe-area-inset-bottom)) + var(--orb-size, 72px) + 14px);
  z-index: 2147483020;

  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: 560px;

  background: #fff;
  border-radius: 20px;
  box-shadow:
    0 24px 64px rgba(0,0,0,.18),
    0 4px 16px rgba(0,0,0,.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;

  opacity: 0;
  transform: translateY(16px) scale(.97);
  pointer-events: none;
  transition: transform .28s cubic-bezier(.22,.68,0,1.2), opacity .22s ease;
}
.rw-chat.--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────────── */
.rw-chat-header {
  background: linear-gradient(160deg, var(--rw-green-top, #73A813) 0%, var(--rw-green-bot, #3E6B09) 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.rw-chat-header-info {
  display: flex;
  align-items: center;
  gap: 11px;
}
.rw-chat-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.45);
  flex-shrink: 0;
}
.rw-chat-avatar-fallback {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  border: 2px solid rgba(255,255,255,.35);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.rw-chat-avatar-fallback svg { width: 22px; height: 22px; color: #fff; }
.rw-chat-name {
  font: 700 15px/1.2 system-ui,-apple-system,"Segoe UI",sans-serif;
  color: #fff;
}
.rw-chat-status {
  display: flex; align-items: center; gap: 5px;
  margin-top: 3px;
  font: 500 12px/1 system-ui,-apple-system,"Segoe UI",sans-serif;
  color: rgba(255,255,255,.85);
}
.rw-chat-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #aaff5c;
  flex-shrink: 0;
  animation: rw-chat-pulse 2s ease infinite;
}
@keyframes rw-chat-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(170,255,92,.55); }
  70%  { box-shadow: 0 0 0 6px rgba(170,255,92,0); }
  100% { box-shadow: 0 0 0 0 rgba(170,255,92,0); }
}
.rw-chat-close-btn {
  all: unset !important;
  width: 32px !important; height: 32px !important;
  border-radius: 50% !important;
  background: rgba(255,255,255,.14) !important;
  cursor: pointer !important;
  display: flex !important; align-items: center !important; justify-content: center !important;
  flex-shrink: 0 !important;
  transition: background .18s !important;
}
.rw-chat-close-btn:hover { background: rgba(255,255,255,.28) !important; }
.rw-chat-close-btn svg { width: 14px !important; height: 14px !important; }

/* ── Message body ────────────────────────────────────────────── */
.rw-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 160px;
  scroll-behavior: smooth;
}
.rw-chat-body::-webkit-scrollbar { width: 4px; }
.rw-chat-body::-webkit-scrollbar-thumb { background: #cdd2d9; border-radius: 2px; }

/* Bot bubble */
.rw-chat-msg { max-width: 88%; align-self: flex-start; }
.rw-chat-msg-inner {
  background: #f3f5f8;
  color: #1c1f25;
  padding: 10px 14px;
  border-radius: 4px 18px 18px 18px;
  font: 500 14px/1.55 system-ui,-apple-system,"Segoe UI",sans-serif;
}

/* User bubble */
.rw-chat-user { max-width: 88%; align-self: flex-end; }
.rw-chat-user-inner {
  background: linear-gradient(135deg, var(--rw-green-top, #73A813) 0%, var(--rw-green-bot, #3E6B09) 100%);
  color: #fff;
  padding: 10px 14px;
  border-radius: 18px 18px 4px 18px;
  font: 600 14px/1.55 system-ui,-apple-system,"Segoe UI",sans-serif;
}

/* Typing indicator */
.rw-chat-typing { align-self: flex-start; }
.rw-chat-typing-inner {
  background: #f3f5f8;
  padding: 13px 16px;
  border-radius: 4px 18px 18px 18px;
  display: flex; gap: 5px; align-items: center;
}
.rw-chat-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #8a95a3;
  animation: rw-type .9s ease infinite;
}
.rw-chat-dot:nth-child(2) { animation-delay: .16s; }
.rw-chat-dot:nth-child(3) { animation-delay: .32s; }
@keyframes rw-type {
  0%, 80%, 100% { transform: scale(1); opacity: .45; }
  40%           { transform: scale(1.3); opacity: 1; }
}

/* ── Options strip ───────────────────────────────────────────── */
.rw-chat-opts {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  border-top: 1px solid #eff1f5;
  background: #fff;
}
.rw-chat-opt-btn {
  all: unset !important;
  box-sizing: border-box !important;
  display: block !important;
  width: 100% !important;
  text-align: center !important;
  padding: 10px 16px !important;
  border-radius: 999px !important;
  border: 1.5px solid var(--rw-green-border, #7FBC11) !important;
  color: #2d5c00 !important;
  background: transparent !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  line-height: 1.35 !important;
  cursor: pointer !important;
  transition: background .15s ease, color .15s ease !important;
  margin: 0 !important;
}
.rw-chat-opt-btn:hover,
.rw-chat-opt-btn:focus-visible {
  background: var(--rw-green-top, #73A813) !important;
  color: #fff !important;
}

/* ── "of" separator ─────────────────────────────────────────── */
.rw-chat-or {
  text-align: center !important;
  color: #9aa3ae !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  margin: 2px 0 !important;
  padding: 0 !important;
  position: relative !important;
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
}
.rw-chat-or::before,
.rw-chat-or::after {
  content: '' !important;
  flex: 1 !important;
  height: 1px !important;
  background: #e8eaed !important;
}

/* ── Lead form ───────────────────────────────────────────────── */
.rw-chat-form {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.rw-chat-form input {
  all: unset !important;
  box-sizing: border-box !important;
  display: block !important;
  width: 100% !important;
  padding: 10px 14px !important;
  border-radius: 10px !important;
  border: 1.5px solid #d5dae2 !important;
  font-size: 16px !important;
  font-weight: 500 !important;
  line-height: 1.3 !important;
  color: #1c1f25 !important;
  background: #fafbfc !important;
  transition: border-color .15s !important;
  margin: 0 !important;
  -webkit-appearance: none !important;
  appearance: none !important;
}
.rw-chat-form input:focus { border-color: var(--rw-green-border, #7FBC11) !important; outline: none !important; }
.rw-chat-form input.--err  { border-color: #e74c3c !important; }
.rw-chat-form-submit {
  all: unset !important;
  box-sizing: border-box !important;
  display: block !important;
  width: 100% !important;
  text-align: center !important;
  padding: 11px 20px !important;
  border-radius: 999px !important;
  background: linear-gradient(135deg, var(--rw-green-top, #73A813) 0%, var(--rw-green-bot, #3E6B09) 100%) !important;
  color: #fff !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  line-height: 1.3 !important;
  cursor: pointer !important;
  transition: opacity .15s !important;
  margin-top: 2px !important;
}
.rw-chat-form-submit:hover { opacity: .88 !important; }

/* ── WhatsApp CTA button ─────────────────────────────────────── */
.rw-chat-wa-cta {
  all: unset !important;
  box-sizing: border-box !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 9px !important;
  width: 100% !important;
  padding: 12px 20px !important;
  border-radius: 999px !important;
  background: linear-gradient(135deg, #25D366 0%, #128C7E 100%) !important;
  color: #fff !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  line-height: 1.3 !important;
  cursor: pointer !important;
  text-decoration: none !important;
  text-align: center !important;
  transition: opacity .15s !important;
}
.rw-chat-wa-cta:hover { opacity: .9 !important; }
.rw-chat-wa-cta svg { width: 17px !important; height: 17px !important; flex-shrink: 0 !important; }

/* ── Online badge on orb ─────────────────────────────────────── */
/* Badge is a child of .wa-orb (overflow:hidden removed from orb).
   position:absolute keeps it inside the transform flow so it moves
   with the orb on hover — no visual disconnect. */
.rw-orb-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #aaff5c;
  border: 2.5px solid #fff;
  z-index: 3;
  pointer-events: none;
  animation: rw-chat-pulse 2s ease infinite;
}

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .rw-chat {
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    border-radius: 20px 20px 0 0;
    max-height: 72vh;
  }
}
@media (prefers-reduced-motion: reduce) {
  .rw-chat { transition: none !important; }
  .rw-chat-status-dot, .rw-orb-badge { animation: none !important; }
}
