:root {
  --bg: #0b0d12;
  --bg-soft: #11141b;
  --panel: #141823;
  --panel-2: #1a1f2c;
  --border: #232a39;
  --border-soft: #1c2230;
  --text: #e6e9ef;
  --muted: #8b93a4;
  --muted-2: #636b7d;
  --accent: #00e5a0;
  --accent-2: #34f0b6;
  --accent-soft: rgba(0, 229, 160, 0.13);
  --ok: #34d399;
  --warn: #fbbf24;
  --code-bg: #0e1118;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#app { display: grid; grid-template-columns: 290px 1fr; height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 20px 18px;
  display: flex; flex-direction: column; gap: 22px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 11px; }
.logo {
  height: 34px; width: auto; display: block; flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; letter-spacing: -0.01em; }
.brand-text .tag { font-size: 11px; color: var(--muted); }

.btn-ghost {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 12px; font-size: 13px; cursor: pointer; text-align: left;
  transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--panel-2); border-color: #2c3445; }

.side-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted-2); margin: 0 0 8px;
}
.muted { color: var(--muted); font-size: 12.5px; line-height: 1.55; }
.steps { margin: 0; padding-left: 18px; }
.steps li { margin-bottom: 6px; }
.side-foot { margin-top: auto; font-size: 11.5px; border-top: 1px solid var(--border-soft); padding-top: 14px; }
.side-foot code, code { font-family: var(--mono); color: var(--accent-2); }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.topbar {
  height: 52px; flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; background: rgba(11,13,18,.7); backdrop-filter: blur(8px);
}
.topbar .title { font-size: 14px; font-weight: 600; color: var(--text); }
.status-pill {
  font-size: 12px; font-family: var(--mono); color: var(--accent-2);
  background: var(--accent-soft); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 20px; display: inline-flex; align-items: center;
}
.status-pill[hidden] { display: none; }

.thread { flex: 1 1 auto; overflow-y: auto; padding: 26px 0 40px; }
.thread-inner, .msg, .welcome { max-width: 820px; margin: 0 auto; padding: 0 24px; }

/* welcome */
.welcome { padding-top: 7vh; }
.welcome h1 { font-size: 28px; letter-spacing: -0.02em; margin: 0 0 10px; }
.examples-label {
  margin-top: 26px; margin-bottom: 10px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted-2);
}
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chip {
  text-align: left; background: var(--panel); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 12px 14px; font-size: 13px;
  cursor: pointer; transition: border-color .15s, background .15s; line-height: 1.4;
}
.chip:hover { border-color: var(--accent); background: var(--panel-2); }

/* messages */
.msg { margin-bottom: 26px; }
.msg .role {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted-2); margin-bottom: 7px; display: flex; align-items: center; gap: 8px;
}
.msg.user .bubble {
  background: var(--accent-soft); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; white-space: pre-wrap;
}
.msg.assistant .answer { font-size: 15px; }
.answer p:first-child { margin-top: 0; }
.answer p:last-child { margin-bottom: 0; }
.answer pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; overflow-x: auto; font-size: 13px;
}
.answer code { font-family: var(--mono); font-size: 13px; }
.answer :not(pre) > code { background: var(--panel-2); padding: 1.5px 5px; border-radius: 5px; }
.answer table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13.5px; }
.answer th, .answer td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.answer th { background: var(--panel-2); }
.answer a { color: var(--accent-2); }
.cursor { display: inline-block; width: 8px; height: 16px; background: var(--accent-2);
  margin-left: 1px; vertical-align: -2px; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* inline citation pills */
.cite {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  color: var(--accent-2); background: var(--accent-soft);
  border: 1px solid var(--border); border-radius: 5px;
  padding: 0 5px; margin: 0 1px; cursor: pointer; text-decoration: none;
  vertical-align: 1px;
}
.cite:hover { background: var(--accent); color: #fff; }

/* no-match banner */
.nomatch {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  background: var(--panel); border-radius: 10px;
  padding: 13px 16px; font-size: 14px; color: var(--text); margin-bottom: 14px;
  line-height: 1.55;
}
.nomatch strong { color: var(--text); font-weight: 600; }

/* sources */
.sources { margin-top: 18px; }
.sources h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted-2); margin: 0 0 10px;
}
.source-card {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); margin-bottom: 9px; overflow: hidden;
}
.source-head {
  display: flex; gap: 10px; align-items: baseline; cursor: pointer;
  padding: 11px 14px; user-select: none;
}
.source-head:hover { background: var(--panel-2); }
.source-n {
  font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--accent-2);
  background: var(--accent-soft); border-radius: 5px; padding: 1px 6px; flex: 0 0 auto;
}
.source-meta { min-width: 0; flex: 1 1 auto; }
.source-title { font-size: 13.5px; font-weight: 600; line-height: 1.35; }
.source-cite { font-family: var(--mono); font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.source-toggle { color: var(--muted-2); font-size: 12px; flex: 0 0 auto; }
.source-body {
  display: none; padding: 0 14px 13px 14px; font-family: var(--mono);
  font-size: 12px; color: var(--muted); white-space: pre-wrap; line-height: 1.5;
  border-top: 1px solid var(--border-soft); margin-top: 0; padding-top: 11px;
}
.source-card.open .source-body { display: block; }
.source-card.flash { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.msg-meta { margin-top: 10px; font-size: 11.5px; color: var(--muted-2); font-family: var(--mono); }
.err { color: #f87171; font-size: 13.5px; }

/* ---------- composer ---------- */
.composer { flex: 0 0 auto; border-top: 1px solid var(--border); padding: 14px 0 16px; background: var(--bg); }
.composer-inner {
  max-width: 820px; margin: 0 auto; padding: 0 24px;
  display: flex; gap: 10px; align-items: flex-end;
}
#input {
  flex: 1 1 auto; resize: none; max-height: 200px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-family: var(--sans); font-size: 15px; line-height: 1.5;
  outline: none; transition: border-color .15s;
}
#input:focus { border-color: var(--accent); }
#send {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 11px;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  display: grid; place-items: center; transition: background .15s, opacity .15s;
}
#send:hover:not(:disabled) { background: var(--accent-2); }
#send:disabled { opacity: .4; cursor: not-allowed; }
.composer-foot {
  max-width: 820px; margin: 8px auto 0; padding: 0 24px;
  display: flex; justify-content: space-between; font-size: 11.5px;
}

@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .examples { grid-template-columns: 1fr; }
}
