/* ============================
   RAG Chat - Floating Button + Side Drawer
   ============================ */

:root {
  --rag-bg: #0f0e0d;
  --rag-bg2: #161513;
  --rag-bg3: #1e1c1a;
  --rag-border: #2a2825;
  --rag-border2: #3a3733;
  --rag-text: #e8e4de;
  --rag-text2: #a09890;
  --rag-text3: #6a6360;
  --rag-accent: #c9a96e;
  --rag-accent2: #e8c98a;
  --rag-accent-dim: rgba(201,169,110,0.12);
  --rag-green: #7aaa8a;
  --rag-tag-bg: #201e1c;
}

[data-theme="light"] {
  --rag-bg: #faf9f7;
  --rag-bg2: #f0eeeb;
  --rag-bg3: #e8e5e1;
  --rag-border: #ddd9d3;
  --rag-border2: #ccc7bf;
  --rag-text: #2c2a27;
  --rag-text2: #5a5650;
  --rag-text3: #8a857d;
  --rag-accent: #a0824a;
  --rag-accent2: #8a6e3a;
  --rag-accent-dim: rgba(160,130,74,0.1);
  --rag-green: #5a8a6a;
  --rag-tag-bg: #f0eeeb;
}

/* --- Floating Button (inside #rightside) --- */
#rag-fab:hover {
  background-color: var(--btn-hover-color);
}

/* --- Overlay --- */
#rag-overlay {
  position: fixed;
  inset: 0;
  z-index: 1020;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

#rag-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* --- Drawer --- */
#rag-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1030;
  width: 420px;
  height: 100vh;
  background: var(--rag-bg);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  font-family: 'Noto Serif SC', serif;
  color: var(--rag-text);
}

#rag-drawer.open {
  transform: translateX(0);
}

/* Drawer header */
.rag-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--rag-border);
  flex-shrink: 0;
}

.rag-drawer-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rag-drawer-title .rag-dot {
  width: 6px;
  height: 6px;
  background: var(--rag-accent);
  border-radius: 50%;
}

.rag-drawer-title span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--rag-accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.rag-drawer-close {
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid var(--rag-border2);
  color: var(--rag-text3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transition: color 0.2s, border-color 0.2s;
}

.rag-drawer-close:hover {
  color: var(--rag-text);
  border-color: var(--rag-text3);
}

/* Drawer chat area */
.rag-drawer-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--rag-border2) transparent;
}

.rag-drawer-messages::-webkit-scrollbar { width: 4px; }
.rag-drawer-messages::-webkit-scrollbar-track { background: transparent; }
.rag-drawer-messages::-webkit-scrollbar-thumb { background: var(--rag-border2); }

/* Drawer empty state */
.rag-drawer-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 0 20px;
}

.rag-drawer-empty-title {
  font-size: 18px;
  font-weight: 300;
  color: var(--rag-text);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}

.rag-drawer-empty-desc {
  font-size: 13px;
  color: var(--rag-text3);
  font-style: italic;
  margin-bottom: 24px;
}

.rag-drawer-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.rag-drawer-suggestions button {
  font-family: 'Noto Serif SC', serif;
  font-size: 12px;
  color: var(--rag-text3);
  border: 1px solid var(--rag-border);
  background: transparent;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}

.rag-drawer-suggestions button:hover {
  color: var(--rag-accent);
  border-color: rgba(201,169,110,0.4);
  background: var(--rag-accent-dim);
}

/* Drawer input */
.rag-drawer-input {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--rag-border);
  flex-shrink: 0;
}

.rag-drawer-input-wrapper {
  position: relative;
  border: 1px solid var(--rag-border2);
  background: var(--rag-bg2);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.rag-drawer-input-wrapper:focus-within {
  border-color: var(--rag-accent);
  box-shadow: 0 0 0 3px rgba(201,169,110,0.08);
}

.rag-drawer-input-wrapper textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--rag-text);
  font-family: 'Noto Serif SC', serif;
  font-size: 14px;
  line-height: 1.6;
  padding: 12px 44px 12px 14px;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  overflow-y: auto;
}

.rag-drawer-input-wrapper textarea::placeholder {
  color: var(--rag-text3);
  font-style: italic;
}

.rag-drawer-input-wrapper .rag-send-btn {
  position: absolute;
  right: 10px;
  bottom: 8px;
  width: 28px;
  height: 28px;
  background: var(--rag-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
}

.rag-drawer-input-wrapper .rag-send-btn:hover { background: var(--rag-accent2); }
.rag-drawer-input-wrapper .rag-send-btn:active { transform: scale(0.95); }
.rag-drawer-input-wrapper .rag-send-btn svg { color: var(--rag-bg); }

/* --- Shared message styles (drawer + page) --- */
.rag-msg-user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
  animation: ragFadeUp 0.3s ease;
}

.rag-msg-user-bubble {
  max-width: 80%;
  background: var(--rag-bg3);
  border: 1px solid var(--rag-border2);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--rag-text2);
}

.rag-msg-ai {
  margin-bottom: 24px;
  animation: ragFadeUp 0.3s ease;
}

.rag-msg-ai-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.rag-msg-ai-label .rag-dot {
  width: 6px;
  height: 6px;
  background: var(--rag-accent);
  border-radius: 50%;
}

.rag-msg-ai-label .rag-ai-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--rag-accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.rag-msg-ai-content {
  font-size: 14px;
  line-height: 1.85;
  color: var(--rag-text);
  letter-spacing: 0.02em;
  margin-bottom: 16px;
}

.rag-msg-ai-content p { margin-bottom: 12px; }
.rag-msg-ai-content p:last-child { margin-bottom: 0; }

.rag-cite {
  display: inline-flex;
  align-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--rag-accent);
  background: var(--rag-accent-dim);
  border: 1px solid rgba(201,169,110,0.2);
  padding: 1px 5px;
  margin: 0 2px;
  vertical-align: middle;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
  top: -1px;
}

.rag-cite:hover { background: rgba(201,169,110,0.2); }

.rag-source-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rag-source-card {
  border: 1px solid var(--rag-border);
  background: var(--rag-bg2);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-decoration: none;
  color: inherit;
}

.rag-source-card:hover {
  border-color: rgba(201,169,110,0.35);
  background: var(--rag-bg3);
}

.rag-source-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--rag-accent);
  opacity: 0.7;
  margin-top: 2px;
  flex-shrink: 0;
  width: 16px;
}

.rag-source-info { flex: 1; min-width: 0; }

.rag-source-title {
  font-size: 13px;
  color: var(--rag-text);
  font-weight: 500;
  margin-bottom: 4px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rag-source-excerpt {
  font-size: 12px;
  color: var(--rag-text3);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.rag-source-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.rag-source-date {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--rag-text3);
}

.rag-source-tag {
  font-size: 10px;
  color: var(--rag-text3);
  background: var(--rag-tag-bg);
  border: 1px solid var(--rag-border);
  padding: 1px 6px;
}

.rag-msg-divider {
  border: none;
  border-top: 1px solid var(--rag-border);
  margin: 4px 0 20px;
}

/* Loading */
.rag-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--rag-text3);
  font-size: 13px;
  font-style: italic;
  padding: 8px 0;
  margin-bottom: 20px;
}

.rag-loading-dots {
  display: flex;
  gap: 4px;
}

.rag-loading-dots span {
  width: 4px;
  height: 4px;
  background: var(--rag-accent);
  border-radius: 50%;
  animation: ragBlink 1.2s infinite;
  opacity: 0.3;
}

.rag-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.rag-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ragBlink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

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

/* Error message */
.rag-error {
  color: #c4715a;
  font-size: 13px;
  padding: 8px 12px;
  border: 1px solid rgba(196,113,90,0.3);
  background: rgba(196,113,90,0.08);
  margin-bottom: 20px;
}

/* --- Mobile --- */
@media (max-width: 768px) {
  #rag-drawer {
    width: 100vw;
  }
}
