:root {
  --bg: #0c0c0f;
  --surface: #13131a;
  --surface2: #1a1a24;
  --border: #2a2a3a;
  --accent: #7c6af7;
  --accent2: #f7c26a;
  --deep: #f26a8d;
  --text: #e8e8f0;
  --muted: #6b6b80;
  --success: #4ade80;
  --radius: 10px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 56px 1fr;
  overflow: hidden;
}

/* ── Topbar ── */
header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.logo { font-size: 18px; font-weight: 800; letter-spacing: -0.5px; color: var(--text); }
.logo span { color: var(--accent); }
.version-tag {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--muted);
  margin-left: auto;
}

/* ── Sidebar ── */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section h3 {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

/* Add source buttons */
.add-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.add-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s;
}
.add-btn-wide { grid-column: 1 / -1; justify-content: center; }
.add-btn:hover { border-color: var(--accent); background: #1e1e2e; }

/* Input forms */
.input-form {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.input-form.visible { display: flex; animation: fadeIn 0.15s ease; }
.input-form input,
.input-form textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}
.input-form input:focus,
.input-form textarea:focus { border-color: var(--accent); }
.input-form textarea { resize: vertical; min-height: 80px; }
.submit-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 12px;
  padding: 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.submit-btn:hover { opacity: 0.85; }
.submit-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Sources list */
.sources-header {
  padding: 10px 16px 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sources-header span { font-size: 11px; font-family: 'JetBrains Mono', monospace; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.sources-header .count { color: var(--accent); }
.hint { font-size: 10px; color: var(--muted); font-family: 'JetBrains Mono', monospace; padding: 4px 16px 6px; border-bottom: 1px solid var(--border); }

.sources-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 7px; }
.sources-list::-webkit-scrollbar { width: 3px; }
.sources-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.source-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s;
}
.source-item:hover { border-color: var(--muted); }
.source-item.selected { border-color: var(--accent); }
.s-type { font-size: 9px; font-family: 'JetBrains Mono', monospace; color: var(--accent2); text-transform: uppercase; letter-spacing: 0.5px; }
.s-title { font-size: 13px; font-weight: 700; margin: 3px 0 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 20px; }
.s-summary { font-size: 11px; color: var(--muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.s-del { position: absolute; top: 8px; right: 8px; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 4px; border-radius: 4px; line-height: 1; }
.s-del:hover { color: var(--deep); background: rgba(242,106,141,0.1); }
.empty-sources { text-align: center; color: var(--muted); font-size: 12px; font-family: 'JetBrains Mono', monospace; padding: 24px 0; }

/* ── Chat panel ── */
.chat-panel { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.toolbar-label { font-size: 12px; color: var(--muted); font-family: 'JetBrains Mono', monospace; }
.depth-toggle { display: flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.depth-btn { background: none; border: none; color: var(--muted); font-family: 'Syne', sans-serif; font-size: 12px; font-weight: 600; padding: 6px 14px; cursor: pointer; transition: background 0.15s, color 0.15s; }
.depth-btn.active { background: var(--accent); color: #fff; }
.depth-btn.active.is-deep { background: var(--deep); }
.scope-note { margin-left: auto; font-size: 11px; font-family: 'JetBrains Mono', monospace; color: var(--muted); }
.scope-note em { color: var(--accent2); font-style: normal; }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 16px; }
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; gap: 10px; padding: 40px; }
.welcome .icon { font-size: 40px; }
.welcome h2 { font-size: 20px; font-weight: 700; color: var(--text); }
.welcome p { font-size: 13px; font-family: 'JetBrains Mono', monospace; max-width: 340px; line-height: 1.7; }

.message { display: flex; gap: 12px; animation: fadeUp 0.2s ease; }
.message.user { flex-direction: row-reverse; }
.avatar { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.message.user .avatar { background: var(--accent); color: #fff; }
.message.ai .avatar { background: var(--surface2); border: 1px solid var(--border); }

.bubble { max-width: 72%; padding: 12px 16px; border-radius: 12px; font-size: 14px; line-height: 1.65; }
.message.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.message.ai .bubble { background: var(--surface2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.message.ai.is-deep .bubble { border-color: rgba(242,106,141,0.4); background: rgba(242,106,141,0.05); }

.msg-meta { font-size: 10px; font-family: 'JetBrains Mono', monospace; color: var(--muted); margin-top: 6px; }
.depth-tag { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-right: 6px; }
.depth-tag.surface { background: rgba(124,106,247,0.2); color: var(--accent); }
.depth-tag.deep { background: rgba(242,106,141,0.2); color: var(--deep); }

.go-deeper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  background: var(--surface2);
  border: 1px dashed var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  margin-top: 8px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.go-deeper:hover { border-color: var(--deep); color: var(--deep); }

/* Typing indicator */
.typing { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing span { width: 6px; height: 6px; background: var(--muted); border-radius: 50%; animation: bounce 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

/* Input area */
.chat-input-area { padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface); display: flex; gap: 10px; align-items: flex-end; }
.chat-input-area textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  font-size: 14px;
  padding: 11px 14px;
  border-radius: 10px;
  outline: none;
  resize: none;
  min-height: 46px;
  max-height: 120px;
  transition: border-color 0.15s;
  line-height: 1.5;
}
.chat-input-area textarea:focus { border-color: var(--accent); }
.chat-input-area textarea::placeholder { color: var(--muted); }
.send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 46px; height: 46px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.send-btn:hover { opacity: 0.85; transform: scale(1.04); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 999;
  animation: fadeUp 0.2s ease;
  max-width: 280px;
}
.toast.error { border-color: var(--deep); color: var(--deep); }
.toast.success { border-color: var(--success); color: var(--success); }

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }
