/* ============================================================
   Radius Wealth — AI Chat Widget
   Premium Intercom-style floating chat bubble
   ============================================================ */

/* ---------- Variables ---------- */
:root {
  --rw-navy: #1a365d;
  --rw-navy-light: #2c5282;
  --rw-blue: #3182ce;
  --rw-blue-light: #ebf8ff;
  --rw-gold: #d69e2e;
  --rw-gray-50: #f7fafc;
  --rw-gray-100: #edf2f7;
  --rw-gray-200: #e2e8f0;
  --rw-gray-400: #a0aec0;
  --rw-gray-600: #718096;
  --rw-gray-800: #2d3748;
  --rw-shadow: 0 10px 40px rgba(26,54,93,0.18);
  --rw-shadow-lg: 0 20px 60px rgba(26,54,93,0.25);
  --rw-radius: 16px;
  --rw-transition: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- Bubble ---------- */
#rw-chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99998;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--rw-navy) 0%, var(--rw-navy-light) 100%);
  box-shadow: var(--rw-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s var(--rw-transition), box-shadow 0.3s ease;
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

#rw-chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: var(--rw-shadow-lg);
}

#rw-chat-bubble:active {
  transform: scale(0.95);
}

#rw-chat-bubble svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: transform 0.3s ease;
}

#rw-chat-bubble.rw-open svg.rw-icon-chat {
  display: none;
}
#rw-chat-bubble.rw-open svg.rw-icon-close {
  display: block;
}
#rw-chat-bubble:not(.rw-open) svg.rw-icon-chat {
  display: block;
}
#rw-chat-bubble:not(.rw-open) svg.rw-icon-close {
  display: none;
}

/* Pulse animation */
#rw-chat-bubble::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--rw-navy);
  opacity: 0;
  animation: rw-pulse 3s ease-in-out infinite;
  pointer-events: none;
}

#rw-chat-bubble.rw-open::before {
  animation: none;
}

@keyframes rw-pulse {
  0%, 100% { transform: scale(1); opacity: 0; }
  50% { transform: scale(1.4); opacity: 0.15; }
}

/* Tooltip */
#rw-chat-bubble .rw-tooltip {
  position: absolute;
  right: 72px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--rw-gray-800);
  color: white;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#rw-chat-bubble .rw-tooltip::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: var(--rw-gray-800);
  border-right: none;
}

#rw-chat-bubble:hover .rw-tooltip {
  opacity: 1;
}

/* Unread badge */
#rw-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e53e3e;
  color: white;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  opacity: 0;
  transform: scale(0);
  transition: all 0.3s var(--rw-transition);
}

#rw-chat-badge.rw-show {
  opacity: 1;
  transform: scale(1);
}

/* ---------- Chat Window ---------- */
#rw-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 99999;
  width: 380px;
  max-height: 520px;
  background: white;
  border-radius: var(--rw-radius);
  box-shadow: var(--rw-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.35s var(--rw-transition);
}

#rw-chat-window.rw-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.rw-chat-header {
  background: linear-gradient(135deg, var(--rw-navy) 0%, var(--rw-navy-light) 100%);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.rw-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.rw-chat-header-info {
  flex: 1;
  min-width: 0;
}

.rw-chat-header-title {
  color: white;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.rw-chat-header-subtitle {
  color: rgba(255,255,255,0.7);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.rw-chat-header-subtitle::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #48bb78;
  flex-shrink: 0;
}

.rw-chat-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.rw-chat-close:hover {
  background: rgba(255,255,255,0.2);
}

/* Messages area */
.rw-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
  max-height: 340px;
  background: var(--rw-gray-50);
  scroll-behavior: smooth;
}

.rw-chat-messages::-webkit-scrollbar {
  width: 5px;
}
.rw-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.rw-chat-messages::-webkit-scrollbar-thumb {
  background: var(--rw-gray-200);
  border-radius: 3px;
}

/* Message bubbles */
.rw-msg {
  max-width: 85%;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: 14px;
  word-break: break-word;
  animation: rw-msg-in 0.3s var(--rw-transition);
}

@keyframes rw-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.rw-msg-assistant {
  background: white;
  color: var(--rw-gray-800);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.rw-msg-user {
  background: var(--rw-navy);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.rw-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: white;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.rw-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rw-gray-400);
  animation: rw-typing-bounce 1.4s ease-in-out infinite;
}

.rw-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.rw-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes rw-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.rw-chat-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--rw-gray-100);
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  flex-shrink: 0;
}

#rw-chat-input {
  flex: 1;
  border: 1px solid var(--rw-gray-200);
  border-radius: 22px;
  padding: 9px 16px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
  background: var(--rw-gray-50);
  color: var(--rw-gray-800);
}

#rw-chat-input::placeholder {
  color: var(--rw-gray-400);
}

#rw-chat-input:focus {
  border-color: var(--rw-blue);
  background: white;
}

#rw-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--rw-navy);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
}

#rw-chat-send:hover {
  background: var(--rw-navy-light);
}

#rw-chat-send:active {
  transform: scale(0.92);
}

#rw-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#rw-chat-send svg {
  width: 16px;
  height: 16px;
  fill: white;
}

/* Footer */
.rw-chat-footer {
  text-align: center;
  padding: 6px 0 8px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  color: var(--rw-gray-400);
  background: white;
  flex-shrink: 0;
  letter-spacing: 0.3px;
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  #rw-chat-window {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: 88px;
    max-height: calc(100vh - 120px);
    border-radius: 14px;
  }

  #rw-chat-bubble {
    bottom: 16px;
    right: 16px;
  }

  #rw-chat-bubble .rw-tooltip {
    display: none;
  }
}

/* ---------- Print: hide widget ---------- */
@media print {
  #rw-chat-bubble,
  #rw-chat-window {
    display: none !important;
  }
}
