/* ================================================================
   RA CHATBOT – FRONTEND WIDGET
   Brand System v2.0  |  Clean Minimalism  |  Inter
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── CSS Variables ─────────────────────────────────────────────── */
:root {
  --bg-primary:   #FFFFFF;
  --bg-secondary: #f4f4f4;
  --text-primary: #111111;
  --accent:       #3489ee;
  --dark:         #354049;

  /* Derived */
  --accent-hover:   #354049;
  --accent-soft:    rgba(52,137,238,0.08);
  --accent-softer:  rgba(52,137,238,0.05);
  --border:         rgba(53,64,73,0.10);
  --shadow-sm:      0 2px 8px rgba(53,64,73,0.08);
  --shadow-md:      0 8px 32px rgba(53,64,73,0.12);
  --shadow-lg:      0 20px 60px rgba(53,64,73,0.16);
  --radius:         12px;
  --radius-sm:      8px;
  --radius-full:    9999px;
  --font:           'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition:     0.2s ease;
}

/* ── Toggle Button ─────────────────────────────────────────────── */
#ra-chat-toggle {
  position: fixed;
  bottom: 28px;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(52,137,238,0.35), var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99998;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  font-size: 22px;
  line-height: 1;
  outline: none;
}

#ra-chat-toggle:hover {
  background: var(--accent-hover);
  transform: scale(1.06) translateY(-2px);
  box-shadow: 0 8px 28px rgba(52,137,238,0.28), var(--shadow-lg);
}

#ra-chat-toggle:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

#ra-chat-toggle.ra-open {
  background: var(--dark);
  box-shadow: var(--shadow-md);
}

.ra-icon-open,
.ra-icon-close {
  position: absolute;
  transition: opacity var(--transition), transform var(--transition);
}

.ra-icon-close {
  opacity: 0;
  font-size: 18px;
  transform: rotate(-45deg);
}

#ra-chat-toggle.ra-open .ra-icon-open  { opacity: 0; transform: rotate(45deg); }
#ra-chat-toggle.ra-open .ra-icon-close { opacity: 1; transform: rotate(0deg); }

/* Badge */
#ra-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: #e83535;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-primary);
  padding: 0 3px;
  animation: ra-badge-pop 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes ra-badge-pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* ── Position ──────────────────────────────────────────────────── */
.ra-pos-right #ra-chat-toggle,
.ra-pos-right #ra-chat-window { right: 28px; }

.ra-pos-left #ra-chat-toggle,
.ra-pos-left #ra-chat-window { left: 28px; }

/* ── Chat Window ───────────────────────────────────────────────── */
#ra-chat-window {
  position: fixed;
  bottom: 98px;
  width: 384px;
  max-width: calc(100vw - 32px);
  max-height: min(620px, calc(100vh - 116px));
  background: var(--bg-primary);
  border-radius: 16px;
  box-shadow: var(--shadow-lg),
              0 0 0 1px var(--border);
  display: flex;
  flex-direction: column;
  z-index: 99999;
  overflow: hidden;
  font-family: var(--font);
  font-size: 15px;

  /* Animation */
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.34,1.2,0.64,1),
              opacity 0.22s ease;
}

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

/* ── Header ────────────────────────────────────────────────────── */
#ra-chat-header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.ra-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  border: 1.5px solid rgba(52,137,238,0.15);
}

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

.ra-header-info strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.ra-header-status {
  font-size: 12px;
  color: var(--dark);
  opacity: 0.6;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.ra-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  animation: ra-pulse 2.5s ease infinite;
}

@keyframes ra-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}

#ra-chat-close {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: none;
  color: var(--dark);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
  line-height: 1;
}

#ra-chat-close:hover {
  background: var(--accent);
  color: var(--bg-primary);
}

/* ── Messages ──────────────────────────────────────────────────── */
#ra-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  background: var(--bg-primary);
}

#ra-chat-messages::-webkit-scrollbar { width: 3px; }
#ra-chat-messages::-webkit-scrollbar-track { background: transparent; }
#ra-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

/* Bubbles */
.ra-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: ra-msg-in 0.2s ease;
}

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

.ra-msg--bot  { justify-content: flex-start; }
.ra-msg--user { justify-content: flex-end; }

.ra-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  border: 1.5px solid rgba(52,137,238,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.ra-msg__bubble {
  max-width: 78%;
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  font-family: var(--font);
}

.ra-msg--bot .ra-msg__bubble {
  background: var(--bg-secondary);
  border-bottom-left-radius: 4px;
}

.ra-msg--user .ra-msg__bubble {
  background: var(--accent);
  color: var(--bg-primary);
  border-bottom-right-radius: 4px;
}

.ra-msg__bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ra-msg--bot .ra-msg__bubble strong { color: var(--accent); }

.ra-msg--bot .ra-msg__bubble ol,
.ra-msg--bot .ra-msg__bubble ul {
  margin: 6px 0;
  padding-left: 16px;
}

.ra-msg--bot .ra-msg__bubble li { margin-bottom: 3px; }

/* Typing */
.ra-typing .ra-msg__bubble {
  background: var(--bg-secondary);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ra-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dark);
  opacity: 0.35;
  animation: ra-bounce 1.2s ease infinite;
}

.ra-typing-dot:nth-child(2) { animation-delay: 0.18s; }
.ra-typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes ra-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%            { transform: translateY(-5px); opacity: 0.8; }
}

/* AI Disclaimer */
.ra-msg-disclaimer {
  margin-top: 8px;
  padding: 8px 11px;
  background: rgba(52,137,238,0.05);
  border: 1px solid rgba(52,137,238,0.12);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--dark);
  opacity: 0.85;
}

.ra-msg-disclaimer a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Quick Replies ─────────────────────────────────────────────── */
#ra-quick-replies {
  padding: 0 16px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ra-quick-btn {
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  color: var(--accent);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 12.5px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), transform var(--transition);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.ra-quick-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-primary);
  transform: translateY(-1px);
}

/* ── Input Row ─────────────────────────────────────────────────── */
#ra-chat-input-row {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  background: var(--bg-primary);
}

#ra-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-secondary);
  outline: none;
  transition: border-color var(--transition), background var(--transition),
              box-shadow var(--transition);
  line-height: 1.4;
}

#ra-chat-input:focus {
  border-color: var(--accent);
  background: var(--bg-primary);
  box-shadow: 0 0 0 3px rgba(52,137,238,0.10);
}

#ra-chat-input::placeholder { color: var(--dark); opacity: 0.4; }

#ra-chat-send {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background var(--transition), transform var(--transition);
}

#ra-chat-send:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.06);
}

#ra-chat-send:disabled {
  background: var(--bg-secondary);
  color: var(--dark);
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Legal Notice ──────────────────────────────────────────────── */
#ra-chat-legal {
  padding: 7px 16px 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--dark);
  opacity: 0.55;
  line-height: 1.45;
  text-align: center;
  font-family: var(--font);
  flex-shrink: 0;
  background: var(--bg-primary);
}

#ra-chat-legal a { color: var(--accent); text-decoration: none; }
#ra-chat-legal a:hover { text-decoration: underline; }
#ra-chat-legal strong { color: var(--dark); opacity: 1; }

/* ── Powered-by Footer ─────────────────────────────────────────── */
#ra-chat-footer {
  text-align: center;
  padding: 5px 0 9px;
  font-size: 10.5px;
  color: var(--dark);
  opacity: 0.3;
  font-family: var(--font);
  letter-spacing: 0.02em;
}

#ra-chat-footer a { color: inherit; text-decoration: none; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 440px) {
  #ra-chat-window {
    width: calc(100vw - 16px);
    border-radius: 14px;
  }
  .ra-pos-right #ra-chat-window,
  .ra-pos-left  #ra-chat-window { right: 8px; left: 8px; }
  .ra-pos-right #ra-chat-toggle { right: 16px; bottom: 20px; }
  .ra-pos-left  #ra-chat-toggle { left: 16px; bottom: 20px; }
}

/* ── Avatar text label ─────────────────────────────────────────── */
.ra-msg__avatar {
  font-size: 9px !important;
  font-weight: 700 !important;
  color: var(--accent) !important;
  font-family: var(--font) !important;
  letter-spacing: -0.02em;
}

.ra-avatar {
  font-size: 10px !important;
  font-weight: 700 !important;
  color: var(--accent) !important;
  font-family: var(--font) !important;
  letter-spacing: -0.02em;
}

/* ── SVG button icons ──────────────────────────────────────────── */
#ra-chat-toggle svg,
#ra-chat-send svg,
#ra-chat-close svg {
  display: block;
  flex-shrink: 0;
}

/* Smooth SVG stroke transition in close button */
#ra-chat-close:hover svg { stroke: var(--bg-primary); }
