:root {
  --rag-primary: #4f46e5;
  --rag-primary-hover: #4338ca;
  --rag-bg: #ffffff;
  --rag-text: #1f2937;
  --rag-muted: #6b7280;
  --rag-border: #e5e7eb;
  --rag-bot-bg: #f3f4f6;
  --rag-user-bg: #4f46e5;
  --rag-user-text: #ffffff;
}

#rag-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#rag-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--rag-primary);
  color: white;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
  transition: background 0.2s, transform 0.2s;
}

#rag-chat-toggle:hover {
  background: var(--rag-primary-hover);
  transform: scale(1.05);
}

#rag-chat-panel {
  display: none;
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  background: var(--rag-bg);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--rag-border);
}

#rag-chat-panel.open {
  display: flex;
}

#rag-chat-header {
  padding: 16px;
  background: var(--rag-primary);
  color: white;
  font-weight: 600;
  font-size: 15px;
}

#rag-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rag-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.rag-message.bot {
  align-self: flex-start;
  background: var(--rag-bot-bg);
  color: var(--rag-text);
  border-bottom-left-radius: 4px;
}

.rag-message.user {
  align-self: flex-end;
  background: var(--rag-user-bg);
  color: var(--rag-user-text);
  border-bottom-right-radius: 4px;
}

.rag-message.loading {
  color: var(--rag-muted);
  font-style: italic;
}

.rag-sources {
  margin-top: 8px;
  font-size: 11px;
  color: var(--rag-muted);
  border-top: 1px solid var(--rag-border);
  padding-top: 6px;
}

#rag-chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--rag-border);
}

#rag-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--rag-border);
  border-radius: 24px;
  font-size: 14px;
  outline: none;
}

#rag-chat-input:focus {
  border-color: var(--rag-primary);
}

#rag-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--rag-primary);
  color: white;
  cursor: pointer;
  font-size: 16px;
}

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

@media (max-width: 480px) {
  #rag-chat-panel {
    width: calc(100vw - 32px);
    height: 70vh;
  }
}
