/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 240px;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --border: #e5e5e7;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --accent: #1a1a2e;
  --accent-fg: #ffffff;
  --accent-hover: #2d2d4e;
  --filter-active: #1a1a2e;
  --filter-active-fg: #ffffff;
  --model-active: #1a1a2e;
  --model-active-fg: #ffffff;
  --user-bubble: #1a1a2e;
  --user-fg: #ffffff;
  --assistant-bubble: #ffffff;
  --assistant-fg: #1a1a1a;
  --source-bg: #f3f4f6;
  --error: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Login overlay ────────────────────────────────────────────────────── */
.login-overlay {
  position: fixed; inset: 0;
  background: #0f0f1a;
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}

.login-logo {
  display: flex; align-items: center; justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.login-card h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 13px;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 12px;
}

.login-card input[type="password"]:focus {
  border-color: var(--accent);
}

.login-card button[type="submit"] {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.login-card button[type="submit"]:hover { background: var(--accent-hover); }
.login-card button[type="submit"]:disabled { opacity: 0.6; cursor: not-allowed; }

.login-error {
  color: var(--error);
  font-size: 13px;
  margin-top: 10px;
}

/* ── App layout ───────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s;
}

.filter-btn:hover { background: var(--bg); }
.filter-btn.active {
  background: var(--filter-active);
  color: var(--filter-active-fg);
  font-weight: 500;
}

/* Model toggle */
.model-toggle {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.model-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.model-btn:hover { border-color: var(--accent); }
.model-btn.active {
  background: var(--model-active);
  border-color: var(--model-active);
  color: var(--model-active-fg);
}

.model-name { font-size: 13px; font-weight: 500; }
.model-desc { font-size: 11px; opacity: 0.7; }
.model-btn.active .model-desc { opacity: 0.8; }

/* Sidebar footer */
.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.status-badge {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}

#status-chunks {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

#status-queue {
  font-size: 11px;
  color: var(--text-muted);
}

.logout-btn {
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

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

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

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.welcome-msg {
  margin: auto;
  max-width: 480px;
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
}

.welcome-msg h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.welcome-msg p { font-size: 14px; line-height: 1.6; }
.welcome-msg em { color: var(--accent); font-style: normal; }

/* Message bubbles */
.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 760px;
  width: 100%;
}

.msg-row.user { align-self: flex-end; align-items: flex-end; }
.msg-row.assistant { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.65;
  font-size: 14px;
}

.msg-row.user .msg-bubble {
  background: var(--user-bubble);
  color: var(--user-fg);
  border-bottom-right-radius: 4px;
  max-width: 520px;
}

.msg-row.assistant .msg-bubble {
  background: var(--assistant-bubble);
  color: var(--assistant-fg);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  max-width: 680px;
}

/* Markdown inside assistant bubble */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 12px 0 6px;
}
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin-bottom: 8px; }
.msg-bubble li { margin-bottom: 3px; }
.msg-bubble code {
  background: var(--source-bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}
.msg-bubble pre code {
  display: block;
  padding: 10px;
  overflow-x: auto;
  white-space: pre;
}
.msg-bubble strong { font-weight: 600; }

/* Meta row (model used, retrieval stats) */
.msg-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  padding: 0 4px;
}

/* Sources */
.sources-toggle {
  margin-top: 8px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

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

.sources-list {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 680px;
}

.source-item {
  background: var(--source-bg);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
}

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

.source-filename {
  font-weight: 500;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 460px;
}

.source-score {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.source-unc {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.source-unc-path {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.copy-path-btn {
  flex-shrink: 0;
  padding: 2px 8px;
  font-size: 11px;
  font-family: inherit;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
  white-space: nowrap;
}

.copy-path-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.source-excerpt {
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Thinking indicator */
.thinking-row {
  align-self: flex-start;
}

.thinking-bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.dot-flashing {
  display: flex; gap: 4px;
}

.dot-flashing span {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: dotFlash 1.2s infinite;
}

.dot-flashing span:nth-child(2) { animation-delay: 0.2s; }
.dot-flashing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotFlash {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.9); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── Input bar ────────────────────────────────────────────────────────── */
.input-bar {
  flex-shrink: 0;
  padding: 16px 32px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  transition: border-color 0.15s;
  box-shadow: var(--shadow);
}

.input-wrap:focus-within { border-color: var(--accent); }

#question-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  background: transparent;
  color: var(--text);
  max-height: 160px;
  overflow-y: auto;
}

#send-btn {
  flex-shrink: 0;
  width: 34px; height: 34px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}

#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#send-btn.stop-mode { background: #dc2626; }
#send-btn.stop-mode:hover { background: #b91c1c; }

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  padding: 0 4px;
}

#active-filter-label {
  color: var(--accent);
  font-weight: 500;
}

/* ── Utilities ────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .messages { padding: 16px; }
  .input-bar { padding: 12px 16px 16px; }
}
