/* Floating chat widget */
.rag-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Toggle button */
.rag-chat-widget__toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #1a73e8, #4285f4);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(26, 115, 232, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
  position: absolute;
  bottom: 0;
  right: 0;
}

.rag-chat-widget__toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(26, 115, 232, 0.5);
}

/* Chat window */
.rag-chat-widget__window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  top: 80px;
  width: 380px;
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  animation: ragWidgetSlideUp 0.25s ease-out;
}

@keyframes ragWidgetSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header */
.rag-chat-widget__header {
  padding: 16px 20px;
  background: linear-gradient(135deg, #1a73e8, #4285f4);
  color: #fff;
}

.rag-chat-widget__header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
}

.rag-chat-widget__header p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  opacity: 0.85;
}

/* Messages area */
.rag-chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f9fa;
}

/* Reuse message styles from the full page */
.rag-chat-widget .rag-chat-message {
  display: flex;
  gap: 8px;
  max-width: 90%;
  animation: ragFadeIn 0.3s ease-in;
}

@keyframes ragFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.rag-chat-widget .rag-chat-message--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.rag-chat-widget .rag-chat-message--assistant {
  align-self: flex-start;
}

.rag-chat-widget .rag-chat-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
}

.rag-chat-widget .rag-chat-message--assistant .rag-chat-avatar {
  background: #1a73e8;
  color: #fff;
}

.rag-chat-widget .rag-chat-message--user .rag-chat-avatar {
  background: #5f6368;
  color: #fff;
}

.rag-chat-widget .rag-chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.45;
  font-size: 0.88rem;
  word-wrap: break-word;
}

.rag-chat-widget .rag-chat-message--assistant .rag-chat-bubble {
  background: #fff;
  color: #202124;
  border: 1px solid #e0e0e0;
  border-bottom-left-radius: 4px;
}

.rag-chat-widget .rag-chat-message--user .rag-chat-bubble {
  background: #1a73e8;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Sources in widget */
.rag-chat-widget .rag-chat-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e8eaed;
  font-size: 0.78rem;
}

.rag-chat-widget .rag-chat-sources-title {
  font-weight: 600;
  color: #5f6368;
  margin-bottom: 3px;
}

.rag-chat-widget .rag-chat-source-item {
  padding: 2px 0;
}

.rag-chat-widget .rag-chat-sources a {
  color: #1a73e8;
  text-decoration: none;
}

.rag-chat-widget .rag-chat-sources a:hover {
  text-decoration: underline;
}

/* Input area */
.rag-chat-widget__input-area {
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
}

.rag-chat-widget__input-area .rag-chat-form {
  margin: 0;
}

.rag-chat-widget__input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: #f1f3f4;
  border-radius: 20px;
  padding: 6px 6px 6px 14px;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}

.rag-chat-widget__input-wrapper:focus-within {
  border-color: #1a73e8;
  background: #fff;
}

.rag-chat-widget .rag-chat-input,
.rag-chat-widget textarea.rag-chat-input {
  flex: 1;
  border: none !important;
  outline: none !important;
  resize: none;
  font-size: 0.88rem;
  line-height: 1.4;
  background: transparent !important;
  max-height: 80px;
  height: auto !important;
  min-height: 24px;
  padding: 4px 0 !important;
  margin: 0 !important;
  box-shadow: none !important;
  font-family: inherit;
  width: 100%;
  overflow-y: auto;
}

.rag-chat-widget .rag-chat-submit {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #1a73e8;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.rag-chat-widget .rag-chat-submit:hover {
  background: #1557b0;
}

.rag-chat-widget .rag-chat-submit:disabled {
  background: #c4c7cc;
  cursor: not-allowed;
}

.rag-chat-widget .rag-chat-send-icon {
  font-size: 0.95rem;
}

/* Typing indicator */
.rag-chat-widget .rag-chat-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.rag-chat-widget .rag-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa0a6;
  animation: ragTyping 1.4s infinite both;
}

.rag-chat-widget .rag-chat-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.rag-chat-widget .rag-chat-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes ragTyping {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Responsive - on mobile, make widget full width */
@media (max-width: 480px) {
  .rag-chat-widget__window {
    width: calc(100vw - 16px);
    right: 8px;
    height: 70vh;
    border-radius: 16px 16px 0 0;
    bottom: 100px;
  }
}
