:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --text: #e7e9ee;
  --muted: #8b93a1;
  --accent: #5B4CD6;
  --accent-tint: #2a2456;
  --user: #2d3345;
  --assistant: #1e222b;
  --err: #e5484d;
  --ok: #48b26b;
  --border: #262a34;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { font-weight: 600; letter-spacing: 0.02em; }
.who { color: var(--muted); font-size: 13px; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

section#auth { padding: 40px; max-width: 400px; margin: 0 auto; }
section#auth label { display: block; margin: 12px 0; }
section#auth input { display: block; width: 100%; padding: 8px; margin-top: 4px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 4px; }

section#app { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.tabs button {
  background: none; border: none; color: var(--muted);
  padding: 8px 16px; cursor: pointer; border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.tab { flex: 1; display: flex; min-height: 0; padding: 0; }
.tab[hidden] { display: none; }

/* ---------- Chat layout ---------- */

.chat-layout { display: flex; flex-direction: row; }

.threads {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.threads-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em;
}
.threads-head button {
  background: var(--accent); color: white; border: none;
  width: 24px; height: 24px; border-radius: 4px; cursor: pointer; font-size: 16px; line-height: 1;
}
#thread-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; flex: 1; }
#thread-list li {
  padding: 8px 12px; cursor: pointer; border-radius: 4px; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#thread-list li:hover { background: var(--panel-2); }
#thread-list li.active { background: var(--accent-tint); color: white; }

.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.thread-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--panel);
}
#thread-title { font-weight: 500; }
.thread-head .controls { display: flex; gap: 8px; align-items: center; }
.thread-head select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 4px 8px; border-radius: 4px; font-size: 13px;
}

.transcript {
  flex: 1; overflow-y: auto; padding: 20px 20px 12px;
  display: flex; flex-direction: column; gap: 12px;
}

.turn { display: flex; }
.turn-user { justify-content: flex-end; }
.turn-assistant { justify-content: flex-start; flex-direction: column; align-items: flex-start; }
.turn-user .bubble, .turn-assistant .bubble {
  max-width: 720px; padding: 10px 14px; border-radius: 12px;
  white-space: pre-wrap; word-wrap: break-word; line-height: 1.45;
}
.turn-user .bubble { background: var(--user); border-bottom-right-radius: 4px; }
.turn-assistant .bubble { background: var(--assistant); border-bottom-left-radius: 4px; }

.citations { color: var(--muted); font-size: 12px; margin-top: 6px; padding-left: 4px; }

/* Distil pill */
.distil-pill {
  margin-top: 10px; padding: 12px 14px; max-width: 720px;
  background: var(--accent-tint); border-left: 3px solid var(--accent); border-radius: 6px;
}
.distil-bullet { font-weight: 500; }
.distil-reason { font-size: 13px; color: var(--muted); margin-top: 4px; font-style: italic; }
.distil-actions { display: flex; gap: 6px; margin-top: 10px; }
.distil-actions button {
  padding: 4px 12px; border: 1px solid var(--border); background: transparent;
  color: var(--text); border-radius: 4px; cursor: pointer; font-size: 13px;
}
.distil-actions button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.distil-actions button.secondary { color: var(--muted); }
.distil-done { color: var(--ok); font-size: 13px; }

/* Compose */
.compose {
  display: flex; gap: 8px; padding: 12px 20px 20px;
  border-top: 1px solid var(--border); background: var(--panel);
}
.compose textarea {
  flex: 1; padding: 10px 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; resize: none;
  font-family: inherit; font-size: 15px; line-height: 1.4;
}
.compose textarea:focus { outline: none; border-color: var(--accent); }
.compose button {
  padding: 0 20px; background: var(--accent); color: white; border: none;
  border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.compose button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 6px 12px; border-radius: 4px; cursor: pointer; }

/* Ingest tab (unchanged) */
#tab-ingest { padding: 20px; display: block; }
.muted { color: var(--muted); }
.counts { display: flex; gap: 12px; margin: 16px 0; }
.counts .cell { background: var(--panel-2); padding: 12px 16px; border-radius: 6px; min-width: 100px; }
.counts .k { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.counts .v { font-size: 24px; font-weight: 500; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 500; }

.err { color: var(--err); margin-top: 8px; }
