:root {
  --bg-primary: #111116;
  --bg-secondary: #1a1a21;
  --bg-tertiary: #24242e;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --text-primary: #e4e4e9;
  --text-secondary: #9d9db0;
  --text-muted: #5c5c6e;
  --border: #2a2a35;
  --success: #2ecc71;
  --error: #e74c3c;
  --info: #3498db;
  --warning: #f39c12;
  --sidebar-width: 260px;
  --radius: 8px;
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg-primary: #f5f6f8;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e9ebf0;
  --accent: #2563eb;
  --accent-light: #3b82f6;
  --text-primary: #1a1a2e;
  --text-secondary: #4a4a60;
  --text-muted: #8a8aa0;
  --border: #d4d6de;
  --success: #16a34a;
  --error: #dc2626;
  --info: #2563eb;
  --warning: #d97706;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
}

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ── Layout ─────────────────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform var(--transition);
  z-index: 100;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-header .logo {
  width: 40px;
  height: 40px;
  border-radius: 7px;
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.3;
}


.theme-toggle {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.sidebar-version {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  line-height: 1.2;
}

.sidebar-nav {
  flex-shrink: 0;
  padding: 8px 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  font-size: 14px;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: rgba(59, 130, 246, 0.3);
  color: var(--text-primary);
  border-right: 3px solid var(--accent);
}

.sidebar-nav a .icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

.mobile-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  font-size: 20px;
  align-items: center;
  justify-content: center;
}

#main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1;
  padding: 32px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 24px;
  font-weight: 600;
}

.page-header p {
  color: var(--text-secondary);
  margin-top: 4px;
  font-size: 14px;
}

/* ── Buttons ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), border-color var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-light); }

.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}
.btn-secondary:hover { background: rgba(255,255,255,0.05); }

.btn-danger {
  background: transparent;
  border-color: var(--error);
  color: var(--error);
}
.btn-danger:hover { background: rgba(231,76,60,0.15); }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Forms ──────────────────────────────────────────────── */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  transition: border-color var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%239d9db0' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

[data-theme="light"] select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%234a4a60' stroke-width='2'/%3E%3C/svg%3E");
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-group input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.slider-group .slider-value {
  min-width: 48px;
  text-align: right;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* ── Toggle Switch ──────────────────────────────────────── */

.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: background var(--transition);
  cursor: pointer;
}

.toggle .slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle input:checked + .slider {
  background: var(--accent);
}

.toggle input:checked + .slider::before {
  transform: translateX(20px);
}

/* ── Cards ──────────────────────────────────────────────── */

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card + .card {
  margin-top: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

/* ── Badges ─────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-success { background: rgba(46,204,113,0.15); color: var(--success); }
.badge-error { background: rgba(231,76,60,0.15); color: var(--error); }
.badge-warning { background: rgba(243,156,18,0.15); color: var(--warning); }
.badge-info { background: rgba(52,152,219,0.15); color: var(--info); }

.doc-progress-text {
  display: block;
  font-size: 10px;
  color: var(--warning);
  margin-top: 2px;
  text-transform: none;
  font-weight: 400;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Chat Page ──────────────────────────────────────────── */

/* Override .page max-width for chat — needs full width for side panel */
.page:has(.chat-container) {
  max-width: none;
  padding: 0;
  overflow: hidden;
}

.chat-container {
  display: flex;
  height: 100%;
  min-height: 0;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 0 16px 12px;
}

/* ── Sidebar Chat History ──────────────────────────── */

.sidebar-chats {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.sidebar-new-chat {
  margin: 0 12px 8px;
  width: calc(100% - 24px);
  justify-content: center;
}

.sidebar-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-chat-item {
  position: relative;
  padding: 8px 28px 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition);
}

.sidebar-chat-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-chat-item.active {
  background: rgba(59, 130, 246, 0.25);
}

.sidebar-chat-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-chat-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-chat-delete {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition);
}

.sidebar-chat-item:hover .sidebar-chat-delete {
  opacity: 1;
}

.sidebar-chat-delete:hover {
  color: var(--error);
  background: rgba(231, 76, 60, 0.1);
}

.sidebar-chat-empty {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 16px 0;
}

.hidden {
  display: none !important;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.chat-toolbar select {
  max-width: 240px;
}

.chat-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-messages:empty::after {
  content: "Send a message to start a conversation.";
  color: var(--text-muted);
  text-align: center;
  margin-top: 40%;
  font-size: 15px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.message-user {
  align-self: flex-end;
}

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

.message-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-user .message-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-assistant .message-bubble {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.markdown-content { white-space: normal; }
.markdown-content h1, .markdown-content h2, .markdown-content h3 { margin: 12px 0 6px; font-size: 15px; font-weight: 600; }
.markdown-content h1 { font-size: 17px; }
.markdown-content h2 { font-size: 16px; }
.markdown-content p { margin: 6px 0; }
.markdown-content ul, .markdown-content ol { margin: 6px 0; padding-left: 20px; }
.markdown-content li { margin: 2px 0; }
.markdown-content code { background: var(--bg-primary); padding: 1px 4px; border-radius: 3px; font-size: 13px; }
.markdown-content pre { background: var(--bg-primary); padding: 10px; border-radius: var(--radius); overflow-x: auto; margin: 8px 0; }
.markdown-content pre code { padding: 0; background: none; }
.markdown-content hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.markdown-content blockquote { border-left: 3px solid var(--accent); margin: 8px 0; padding: 4px 12px; color: var(--text-secondary); }

.message-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  padding: 0 4px;
}

.message-user .message-label { text-align: right; }

/* Answer images (below assistant message text) */
.answer-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding: 0 4px;
}

.answer-img {
  max-height: 220px;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
  background: var(--bg-primary);
}

.answer-img:hover {
  border-color: var(--accent);
  transform: scale(1.02);
}

.chat-learn-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  align-self: flex-start;
}

.btn-teach, .btn-correct {
  background: rgba(52, 152, 219, 0.1);
  border: 1px solid rgba(52, 152, 219, 0.3);
  color: var(--accent-light);
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-teach:hover, .btn-correct:hover {
  background: rgba(52, 152, 219, 0.2);
  border-color: var(--accent);
}

/* ── Term Corrections Table ────────────────────── */

.tc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
}
.tc-table th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--bg-tertiary);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.85em;
}
.tc-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.tc-table td:last-child {
  width: 36px;
  text-align: center;
}
.tc-del {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}
.tc-del:hover {
  background: rgba(231, 76, 60, 0.15);
  border-color: var(--danger);
}

/* ── Tool Activity Indicator ────────────────────── */

.tool-activity {
  border-left: 3px solid var(--info);
  background: rgba(52, 152, 219, 0.08);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 12px;
}

.tool-activity-label {
  font-weight: 600;
  color: var(--info);
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tool-call-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool-call-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11px;
  font-weight: 500;
}

.tool-call-icon {
  font-size: 10px;
  font-weight: 700;
}

.tool-ok {
  background: rgba(46, 204, 113, 0.15);
  color: var(--success);
}

.tool-error {
  background: rgba(231, 76, 60, 0.15);
  color: var(--error);
}

.tool-pending {
  background: rgba(243, 156, 18, 0.15);
  color: var(--warning);
}

/* Streaming cursor */
.streaming .message-bubble::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--text-primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ── Sources Side Panel ─────────────────────────── */

.sources-panel-container {
  width: 340px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sources-panel-container.collapsed {
  display: none;
}

.sources-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

.sources-panel-header h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.sources-panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}

.sources-panel-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.sources-panel-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sources-panel-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 40px 16px;
}

.sources-panel-mcp-note {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-left: 3px solid var(--primary);
  padding: 8px 12px;
  margin: 0 12px 12px;
  border-radius: 4px;
}

/* Sources toggle button in toolbar */
.sources-toggle {
  margin-left: auto;
}

.sources-toggle.active {
  background: rgba(59, 130, 246, 0.3);
  border-color: var(--accent);
  color: var(--text-primary);
}

/* Source count badge on messages */
.message-source-count {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  background: rgba(59, 130, 246, 0.25);
  border: 1px solid var(--accent);
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent-light);
  cursor: pointer;
  margin-left: 6px;
  transition: background var(--transition);
}

.message-source-count:hover {
  background: rgba(59, 130, 246, 0.45);
}

/* Correction suggestion banner */
.correction-suggestion {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 4px 0;
  background: rgba(52, 152, 219, 0.1);
  border: 1px solid var(--info);
  border-radius: var(--radius);
  font-size: 12px;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.correction-suggestion-text {
  flex: 1;
  color: var(--text-primary);
}

.correction-suggestion-save {
  flex-shrink: 0;
  font-size: 11px;
  padding: 2px 10px;
}

.correction-suggestion-dismiss {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}

.correction-suggestion-dismiss:hover {
  color: var(--text-primary);
}

.message-cached-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  background: rgba(52, 152, 219, 0.15);
  border: 1px solid var(--info);
  border-radius: 12px;
  font-size: 9px;
  font-weight: 600;
  color: var(--info);
  margin-left: 6px;
}

/* Source panel cards */
.sp-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  transition: border-color var(--transition);
}

.sp-card:hover {
  border-color: var(--accent);
}

.sp-card.highlighted {
  border-color: var(--info);
  background: rgba(52, 152, 219, 0.08);
  box-shadow: 0 0 0 1px var(--info);
  transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
}

.citation-link {
  color: var(--info);
  font-size: 0.85em;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  padding: 0 1px;
  border-radius: 2px;
  transition: background var(--transition), color var(--transition);
}

.citation-link:hover {
  background: rgba(52, 152, 219, 0.15);
  text-decoration: none;
}

.sp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.sp-doc {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
  text-decoration: none;
}
a.sp-doc:hover {
  color: var(--primary);
  text-decoration: underline;
}

.sp-score {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 10px;
  margin-left: 8px;
}

.sp-score.high {
  background: rgba(46, 204, 113, 0.15);
  color: var(--success);
}

.sp-score.mid {
  background: rgba(243, 156, 18, 0.15);
  color: var(--warning);
}

.sp-score.low {
  background: rgba(231, 76, 60, 0.15);
  color: var(--error);
}

.sp-page {
  font-size: 11px;
  color: var(--text-muted);
}

.sp-text {
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.4;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Tables in source panel cards */
.sp-text table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin: 6px 0;
}
.sp-text th,
.sp-text td {
  border: 1px solid var(--border);
  padding: 3px 6px;
  text-align: left;
}
.sp-text th {
  background: var(--bg-secondary);
  font-weight: 600;
}

.sp-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.sp-images img {
  max-height: 80px;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
}

.sp-images img:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

/* Source feedback voting */
.sp-feedback {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  align-items: center;
}

.sp-vote {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 10px;
  padding: 2px 8px;
  transition: all var(--transition);
  line-height: 1;
}

.sp-vote:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.sp-vote-up.active {
  background: rgba(46, 204, 113, 0.15);
  border-color: var(--success);
  color: var(--success);
}

.sp-vote-down.active {
  background: rgba(231, 76, 60, 0.15);
  border-color: var(--error);
  color: var(--error);
}

/* ── Image Lightbox ─────────────────────────────── */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  z-index: 1000;
}

.lightbox-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.6);
  flex-shrink: 0;
  z-index: 1;
}

.lightbox-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 16px;
  cursor: pointer;
  min-width: 36px;
  text-align: center;
  transition: background 0.15s;
}

.lightbox-btn:hover { background: rgba(255, 255, 255, 0.25); }

.lightbox-close { margin-left: 16px; color: var(--error); font-weight: 700; }

.lightbox-zoom-level {
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  min-width: 48px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.lightbox-viewport {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  transition: transform 0.15s ease;
  transform-origin: center center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  user-select: none;
}

/* Chat input */
.chat-input-area {
  flex-shrink: 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.chat-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input-wrapper textarea {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  resize: none;
  min-height: 44px;
  max-height: 160px;
  line-height: 1.5;
}

.chat-input-wrapper textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-input-wrapper .btn-send {
  padding: 10px 16px;
  height: 44px;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Documents Page ─────────────────────────────────────── */

.url-ingest-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  max-width: 600px;
}

.url-ingest-row .form-control {
  flex: 1;
}

.crawl-section {
  margin-bottom: 16px;
  max-width: 700px;
}

.crawl-toggle {
  cursor: pointer;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 0;
  user-select: none;
}

.crawl-toggle:hover {
  text-decoration: underline;
}

.crawl-form {
  margin-top: 8px;
}

.crawl-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.crawl-row .form-control:first-child {
  flex: 1;
}

.crawl-dryrun-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.crawl-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.crawl-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
  font-size: 14px;
}

.crawl-report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 8px;
}

.crawl-report-table th,
.crawl-report-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.crawl-report-table th {
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
}

.crawl-url {
  word-break: break-all;
  max-width: 350px;
}

.crawl-refs {
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
}

.crawl-ref {
  display: inline-block;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 24px;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

.dropzone .dropzone-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.dropzone .dropzone-text {
  color: var(--text-secondary);
  font-size: 14px;
}

.dropzone .dropzone-text strong {
  color: var(--text-primary);
}

.dropzone .dropzone-formats {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.dropzone input[type="file"] {
  display: none;
}

.upload-progress {
  margin-bottom: 16px;
}

.progress-bar-container {
  background: var(--bg-primary);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.progress-bar-indeterminate {
  width: 100% !important;
  background: linear-gradient(90deg, var(--accent) 0%, var(--bg-primary) 50%, var(--accent) 100%);
  background-size: 200% 100%;
  animation: progress-indeterminate 1.5s linear infinite;
}

@keyframes progress-indeterminate {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.progress-label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

/* Document toolbar: pills + search */
.doc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.doc-filter-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.doc-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}

.doc-pill:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.doc-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pill-count {
  font-size: 11px;
  opacity: 0.7;
}

.doc-search-wrapper {
  max-width: 260px;
  flex-shrink: 0;
}

.doc-search-wrapper .doc-search {
  font-size: 13px;
  padding: 6px 10px;
}

/* Compact document table */
.doc-table {
  width: 100%;
  border-collapse: collapse;
}

.doc-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.doc-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
}

.doc-table td {
  padding: 7px 8px;
  font-size: 13px;
  border-bottom: 1px solid rgba(42, 42, 74, 0.5);
  vertical-align: middle;
}

.doc-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.doc-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.doc-name-cell .doc-icon {
  flex-shrink: 0;
  width: 24px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.doc-name-cell .doc-icon svg {
  width: 24px;
  height: 28px;
}

.doc-name-cell .doc-filename {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-stats {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.doc-features {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 3px;
}

.feat-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.feat-strategy {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
}

.feat-on {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

.feat-embedder {
  background: rgba(251, 191, 36, 0.12);
  color: #fbbf24;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feat-meta {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
}

.stats-legend-icon {
  display: inline-block;
  width: 15px;
  height: 15px;
  line-height: 15px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  cursor: help;
  vertical-align: middle;
  margin-left: 2px;
}

.stats-legend-icon:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
}

/* Document inspect modal */
.inspect-modal {
  width: 90vw;
  max-width: 900px;
  height: 85vh;
  display: flex;
  flex-direction: column;
}

.inspect-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.inspect-header h3 {
  margin: 0;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 12px;
}

.inspect-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.inspect-tab {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.inspect-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.inspect-search {
  margin-bottom: 10px;
}

.inspect-search input {
  font-size: 13px;
  padding: 6px 10px;
}

#inspect-body {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px;
  background: var(--bg);
}

.inspect-summary {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

.inspect-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 0;
}

.inspect-chunk {
  margin-bottom: 12px;
  padding: 10px;
  background: var(--card-bg);
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.inspect-chunk-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.inspect-chunk-text {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
}

.inspect-parent {
  margin-top: 8px;
}

.inspect-parent summary {
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 4px;
}

.inspect-parent .inspect-chunk-text {
  font-size: 12px;
  color: var(--text-secondary);
  border-left: 2px solid var(--border-color);
  padding-left: 10px;
}

.inspect-caption {
  margin-bottom: 10px;
  padding: 10px;
  background: var(--card-bg);
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.inspect-caption-file {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.inspect-caption-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.inspect-thumb {
  width: 120px;
  max-height: 100px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.inspect-caption-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}

#inspect-body mark {
  background: rgba(251, 191, 36, 0.3);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

.doc-actions {
  white-space: nowrap;
}

.doc-actions .btn-inspect {
  margin-right: 4px;
}

.doc-collection-cell {
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

.doc-date-cell {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

/* Clickable document file link */
.doc-file-link {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--info);
  text-decoration: none;
  cursor: pointer;
}

.doc-file-link:hover {
  text-decoration: underline;
  color: var(--accent-light);
}

/* Collection pill delete button */
.pill-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  color: inherit;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
  cursor: pointer;
}

.doc-pill:hover .pill-delete {
  opacity: 0.7;
}

.pill-delete:hover {
  opacity: 1 !important;
  background: rgba(231, 76, 60, 0.3);
  color: var(--error);
}

/* Renameable collection name — double-click hint */
.pill-name[data-col-rename] {
  cursor: text;
  border-bottom: 1px dashed transparent;
  transition: border-color var(--transition);
}

.pill-name[data-col-rename]:hover {
  border-bottom-color: var(--text-muted);
}

/* Add collection pill button */
.doc-pill-add {
  border-style: dashed;
  font-size: 16px;
  font-weight: 400;
  padding: 5px 10px;
}

.doc-pill-add:hover {
  border-color: var(--accent);
  color: var(--accent-light);
}

/* Inline create collection form */
.create-collection-inline {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

/* Pagination controls */
.doc-pagination {
  margin-top: 12px;
}

.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
}

.pagination-size {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination-size label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.pagination-size-select {
  width: auto;
  min-width: 60px;
  padding: 3px 8px;
  font-size: 12px;
}

.pagination-info {
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.pagination-buttons {
  display: flex;
  gap: 4px;
}

.pagination-btn {
  min-width: 32px;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.doc-error-msg {
  color: var(--error);
  font-size: 11px;
  margin-top: 2px;
  line-height: 1.3;
  max-width: 400px;
  word-break: break-word;
  opacity: 0.85;
}

.doc-table .btn-delete {
  padding: 2px 8px;
  font-size: 11px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
}

/* ── Collections Page ───────────────────────────────────── */

.collections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.collection-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color var(--transition);
}

.collection-card:hover {
  border-color: var(--accent);
}

.collection-card .collection-name {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 4px;
}

.collection-card .collection-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.collection-card .collection-stats {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.collection-card .collection-actions {
  display: flex;
  gap: 8px;
}

.create-collection-form {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.create-collection-form h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.inline-form .form-group {
  margin-bottom: 0;
  flex: 1;
  min-width: 150px;
}

/* ── Manage Documents Modal ─────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h3 {
  margin-bottom: 16px;
}

.modal .modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.cleanup-result {
  text-align: center;
  padding: 12px 0;
}

.cleanup-table {
  margin: 12px auto 0;
  border-collapse: collapse;
  text-align: left;
}

.cleanup-table td {
  padding: 4px 16px 4px 0;
}

.cleanup-table td:last-child {
  text-align: right;
  padding-right: 0;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.checkbox-list input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* ── Settings Page ──────────────────────────────────────── */

.settings-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.settings-tab {
  padding: 10px 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}

.settings-tab:hover {
  color: var(--text-primary);
}

.settings-tab.active {
  color: var(--accent, #3b82f6);
  border-bottom-color: var(--accent, #3b82f6);
}

.settings-tab-panel {
  display: none;
}

.settings-tab-panel.active {
  display: block;
}

.settings-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.settings-section h3 {
  font-size: 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-section h3 .icon {
  font-size: 18px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.settings-row .form-group {
  flex: 1;
}

.test-btn-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.test-result {
  font-size: 13px;
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: var(--radius);
}

.test-result.success {
  background: rgba(46,204,113,0.1);
  color: var(--success);
}

.test-result.error {
  background: rgba(231,76,60,0.1);
  color: var(--error);
}

.settings-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

/* ── MCP Settings Tab ──────────────────────────────────── */

.mcp-server-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.mcp-server-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.mcp-server-header:hover {
  background: var(--bg-secondary);
}

.mcp-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mcp-status-dot.connected { background: var(--success, #2ecc71); }
.mcp-status-dot.error { background: var(--error, #e74c3c); }

.mcp-server-name {
  font-weight: 600;
  flex: 1;
}

.mcp-server-badge {
  font-size: 0.75em;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mcp-tool-count {
  font-size: 0.85em;
  color: var(--text-muted);
}

.mcp-chevron {
  font-size: 0.7em;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.mcp-server-card.expanded .mcp-chevron {
  transform: rotate(90deg);
}

.mcp-tool-list {
  display: none;
  border-top: 1px solid var(--border);
  max-height: 400px;
  overflow-y: auto;
}

.mcp-server-card.expanded .mcp-tool-list {
  display: block;
}

.mcp-tool-item {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: baseline;
}

.mcp-tool-item:last-child {
  border-bottom: none;
}

.mcp-tool-name {
  font-family: var(--font-mono, monospace);
  font-size: 0.85em;
  white-space: nowrap;
  color: var(--accent, #3498db);
}

.mcp-tool-desc {
  font-size: 0.82em;
  color: var(--text-muted);
}

/* ── Evaluation Tab ─────────────────────────────────────── */

.eval-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.eval-table th,
.eval-table td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.eval-table th {
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
}

.eval-table tbody tr:hover {
  background: rgba(59, 130, 246, 0.08);
}

.eval-metric {
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.eval-good { color: var(--success); }
.eval-mid { color: var(--warning); }
.eval-low { color: var(--error); }

.eval-status {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
}

.eval-status-ok {
  background: rgba(46, 204, 113, 0.15);
  color: var(--success);
}

.eval-status-running {
  background: rgba(52, 152, 219, 0.15);
  color: var(--info);
}

.eval-status-error {
  background: rgba(231, 76, 60, 0.15);
  color: var(--error);
}

.eval-metric-legend {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.7;
}

.eval-metric-legend strong {
  color: var(--text-primary);
}

.eval-summary {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.eval-question {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.eval-question.expanded {
  white-space: normal;
  max-width: none;
  overflow: visible;
}

.eval-detail-table td,
.eval-detail-table th {
  padding: 4px 6px;
}

.eval-row-question:hover {
  background: var(--bg-hover, rgba(255,255,255,0.03));
}

.eval-answer-cell {
  background: var(--bg-secondary, #1a1a21);
  padding: 10px 14px !important;
  border-left: 3px solid var(--accent, #3b82f6);
}

.eval-answer-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.eval-answer-text {
  font-size: 13px;
  color: var(--text-primary);
  white-space: pre-wrap;
  line-height: 1.5;
}

/* ── Toast Notifications ────────────────────────────────── */

#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 14px;
  pointer-events: auto;
  animation: toast-in 0.3s ease forwards;
  max-width: 360px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.toast.removing {
  animation: toast-out 0.3s ease forwards;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--error); }
.toast-info { border-left: 3px solid var(--info); }

.toast .toast-icon { font-size: 16px; flex-shrink: 0; }
.toast .toast-msg { flex: 1; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* ── Confirm Dialog ─────────────────────────────────────── */

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}

.confirm-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 90%;
}

.confirm-dialog p {
  margin-bottom: 16px;
  font-size: 14px;
}

.confirm-dialog .confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Responsive ─────────────────────────────────────────── */

/* Medium screens: overlay sources panel */
@media (max-width: 1200px) {
  .sources-panel-container:not(.collapsed) {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 150;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
  }
}

@media (max-width: 768px) {
  .mobile-toggle {
    display: flex;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }

  .sidebar-backdrop.open {
    display: block;
  }

  .page {
    padding: 16px;
    padding-top: 56px;
  }

  .message {
    max-width: 95%;
  }

  .collections-grid {
    grid-template-columns: 1fr;
  }

  .inline-form {
    flex-direction: column;
  }

  .settings-row {
    flex-direction: column;
    align-items: stretch;
  }

  .doc-table .col-stats,
  .doc-table .col-collection,
  .doc-table .col-date {
    display: none;
  }

  .doc-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .doc-search-wrapper {
    max-width: none;
  }

  /* Full-width overlay on mobile */
  .sources-panel-container:not(.collapsed) {
    width: 100%;
  }

  .auth-card {
    margin: 16px;
    width: auto;
  }
}

/* ── Auth Pages ──────────────────────────────────────────── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 380px;
  max-width: 100%;
}

.auth-header {
  text-align: center;
  margin-bottom: 24px;
}

.auth-logo {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  display: block;
  margin: 0 auto 8px;
}

.auth-header h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.auth-header p {
  font-size: 13px;
  color: var(--text-secondary);
}

.auth-tagline {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 0.02em;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: color var(--transition), border-color var(--transition);
}

.auth-tab:hover {
  color: var(--text-secondary);
}

.auth-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.auth-submit {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
  padding: 10px 16px;
}


/* ── User Management ─────────────────────────────────────── */

.users-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color var(--transition);
}

.user-card:hover {
  border-color: var(--accent);
}

.user-card.user-pending {
  border-left: 3px solid var(--warning);
}

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

.user-name {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-role-select,
.user-rate-select {
  width: auto;
  min-width: 100px;
  padding: 4px 8px;
  font-size: 12px;
}

/* ── User Collection Access ──────────────────────────────── */

.user-collections {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.user-colls-label {
  flex-shrink: 0;
}

.user-colls-list {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}

.user-colls-none {
  color: var(--danger);
  font-style: italic;
}

.user-colls-edit {
  flex-shrink: 0;
  font-size: 11px;
  padding: 2px 8px;
}

.modal-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.colls-checklist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
}

.colls-check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--transition);
}

.colls-check-item:hover {
  background: var(--bg-secondary);
}

.colls-check-item input[type="checkbox"] {
  accent-color: var(--accent);
}

/* ── Sidebar User Section ────────────────────────────────── */

.sidebar-user {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.sidebar-username {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link-btn {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 0;
  margin-bottom: 6px;
  cursor: pointer;
  text-align: left;
  transition: color var(--transition);
}

.sidebar-link-btn:hover {
  color: var(--accent-light);
}

.sidebar-logout {
  display: block;
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color var(--transition), border-color var(--transition);
}

.sidebar-logout:hover {
  color: var(--error);
  border-color: var(--error);
}

.sidebar-signin {
  display: block;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 4px;
}

.sidebar-signin:hover {
  color: var(--text-primary);
  text-decoration: none;
}

/* ── Log Viewer ──────────────────────────────────────────── */

.log-page {
  max-width: none !important;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.log-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.log-filters {
  display: flex;
  gap: 4px;
}

.log-filter-btn {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

.log-filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.log-actions {
  display: flex;
  gap: 6px;
}

#log-scroll-btn.active {
  background: rgba(243, 156, 18, 0.15);
  border-color: var(--warning);
  color: var(--warning);
}

.log-viewer {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  min-height: 0;
}

.log-entry {
  display: flex;
  gap: 8px;
  padding: 1px 4px;
  border-radius: 2px;
  white-space: nowrap;
}

.log-entry:hover {
  background: rgba(255, 255, 255, 0.03);
}

.log-ts {
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 170px;
}

.log-level {
  flex-shrink: 0;
  min-width: 64px;
  font-weight: 600;
  text-transform: uppercase;
}

.log-logger {
  color: var(--text-muted);
  flex-shrink: 0;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-msg {
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-all;
  min-width: 0;
}

/* Level colors */
.log-info .log-level  { color: var(--info); }
.log-warning .log-level { color: var(--warning); }
.log-error .log-level { color: var(--error); }
.log-error .log-msg   { color: var(--error); }
.log-debug .log-level { color: var(--text-muted); }
.log-debug .log-msg   { color: var(--text-secondary); }

/* ── Feedback Page ──────────────────────────────────────── */

.fb-create-form {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.fb-create-form h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.fb-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.fb-filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.fb-filter-label {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 64px;
  flex-shrink: 0;
}

.fb-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  transition: border-color var(--transition);
}

.fb-card:hover {
  border-color: var(--accent);
}

.fb-card.expanded {
  border-color: var(--accent);
}

.fb-card-header {
  padding: 12px 16px;
  cursor: pointer;
}

.fb-card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.fb-card-title {
  font-weight: 600;
  font-size: 14px;
  min-width: 0;
  word-break: break-word;
}

.fb-card-badges {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.fb-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.fb-card-detail {
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}

.fb-description {
  white-space: pre-wrap;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 12px 0;
  line-height: 1.5;
}

/* Admin controls inside expanded ticket */
.fb-admin-controls {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin: 8px 0 12px;
}

.fb-admin-controls label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
  display: block;
}

/* Comments */
.fb-comments-section {
  margin-top: 12px;
}

.fb-comments-section h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.fb-comments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.fb-comment {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.fb-comment-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.fb-comment-content {
  font-size: 13px;
  color: var(--text-primary);
  white-space: pre-wrap;
  line-height: 1.4;
}

.fb-no-comments {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.fb-add-comment textarea {
  min-height: 60px;
}

/* Category badge colors */
.fb-badge-cat-bug        { background: rgba(231,76,60,0.15);  color: var(--error); }
.fb-badge-cat-feature    { background: rgba(59,130,246,0.2);   color: var(--accent-light); }
.fb-badge-cat-improvement { background: rgba(52,152,219,0.15); color: var(--info); }
.fb-badge-cat-question   { background: rgba(243,156,18,0.15); color: var(--warning); }

/* Priority badge colors */
.fb-badge-pri-critical { background: rgba(231,76,60,0.15); color: var(--error); }
.fb-badge-pri-high     { background: rgba(243,156,18,0.15); color: var(--warning); }
.fb-badge-pri-medium   { background: rgba(52,152,219,0.15); color: var(--info); }
.fb-badge-pri-low      { background: rgba(108,108,128,0.15); color: var(--text-muted); }

/* Status badge colors */
.fb-badge-status-open        { background: rgba(52,152,219,0.15); color: var(--info); }
.fb-badge-status-in-progress { background: rgba(243,156,18,0.15); color: var(--warning); }
.fb-badge-status-resolved    { background: rgba(46,204,113,0.15); color: var(--success); }
.fb-badge-status-closed      { background: rgba(108,108,128,0.15); color: var(--text-muted); }

@media (max-width: 768px) {
  .fb-card-title-row { flex-direction: column; align-items: flex-start; }
  .fb-filter-group { flex-direction: column; align-items: flex-start; }
}

/* ── Help Page ──────────────────────────────────────────── */

.help-page {
  max-width: 820px;
}

.help-toc {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.help-toc h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.help-toc ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.help-toc a {
  font-size: 13px;
  color: var(--info);
  text-decoration: none;
}

.help-toc a:hover {
  text-decoration: underline;
}

.help-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.help-section h3 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.help-section p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.6;
}

.help-section ul {
  padding-left: 20px;
  margin-bottom: 8px;
}

.help-section li {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  line-height: 1.5;
}

.help-steps {
  counter-reset: step;
  list-style: none;
  padding-left: 0;
}

.help-steps li {
  counter-increment: step;
  position: relative;
  padding-left: 36px;
  margin-bottom: 12px;
}

.help-steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.help-mcp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}

.help-mcp-table th,
.help-mcp-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}

.help-mcp-table th {
  background: var(--bg-primary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.help-mcp-table td:first-child {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
  white-space: nowrap;
  color: var(--accent-light);
}

.help-mcp-table td:nth-child(2) {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11px;
  color: var(--text-muted);
}


.help-kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  .help-section { padding: 14px 16px; }
  .help-toc ul { flex-direction: column; }
  .help-mcp-table { font-size: 12px; }
  .help-mcp-table td:first-child { white-space: normal; }
}

/* ── Light theme refinements ─────────────────────────── */
[data-theme="light"] #sidebar {
  box-shadow: 1px 0 3px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .auth-card {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .modal {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .toast {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .btn-primary {
  color: #ffffff;
}

[data-theme="light"] .feat-strategy {
  background: rgba(99, 102, 241, 0.12);
  color: #4338ca;
}

[data-theme="light"] .feat-on {
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
}

[data-theme="light"] .feat-embedder {
  background: rgba(217, 119, 6, 0.12);
  color: #b45309;
}

[data-theme="light"] .feat-meta {
  background: rgba(14, 165, 233, 0.12);
  color: #0369a1;
}

[data-theme="light"] .doc-stats {
  color: #4a4a60;
}
