:root {
  --bg: #0a0f1a; --panel: #0f1729; --panel2: #131d33; --border: #1e293b; --text: #94a3b8; --head: #e2e8f0;
  --accent: #34d399; --accent-dim: #065f46; --red: #f87171; --amber: #fbbf24; --blue: #60a5fa; --violet: #a78bfa;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.55 Inter, system-ui, sans-serif; display: flex; flex-direction: column; }
b, strong { color: var(--head); font-weight: 600; }
button { font: inherit; cursor: pointer; }
.mono { font-family: var(--mono); }
.muted { color: #64748b; }

.app { flex: 1; display: grid; grid-template-columns: 290px 1fr; min-height: 0; }

/* ---------- sidebar */
.side { background: var(--panel); border-right: 1px solid var(--border); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand b { display: block; font-size: 16px; }
.brand small { color: #64748b; font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: #052e22; color: var(--accent); font-size: 18px; border: 1px solid var(--accent-dim); }
.btn { border: 1px solid var(--border); background: var(--panel2); color: var(--head); padding: 9px 12px; border-radius: 9px; text-align: left; }
.btn:hover { border-color: #334155; }
.btn.new { font-weight: 600; }
.btn.ghost { background: none; color: var(--accent); padding: 6px 0; border: none; }
.panel { border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.panel h3 { margin: 0 0 10px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #64748b; }
.lbl { display: flex; justify-content: space-between; font-size: 12.5px; margin: 10px 0 4px; color: var(--head); }
.lbl:first-of-type { margin-top: 0; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.range-ends { display: flex; justify-content: space-between; font-size: 11px; color: #64748b; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: none; color: var(--text); padding: 6px; font-size: 12.5px; }
.seg button.on { background: #052e22; color: var(--accent); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat { background: var(--panel2); border-radius: 8px; padding: 6px 8px; }
.stat b { display: block; font-size: 16px; font-family: var(--mono); }
.stat span { font-size: 11px; color: #64748b; }
.how ol { margin: 0; padding-left: 18px; font-size: 12.5px; }
.how li { margin-bottom: 4px; }
.foot { font-size: 11.5px; margin: auto 0 0; }

/* ---------- main */
.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.top .title { color: var(--head); font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font: 500 11.5px var(--mono); padding: 3px 9px; border-radius: 99px; border: 1px solid var(--accent-dim); color: var(--accent); background: #052e22; white-space: nowrap; }
.pill.off { border-color: #7f1d1d; color: var(--red); background: #2a0f12; }
.icon { background: none; border: 1px solid var(--border); color: var(--head); width: 34px; height: 34px; border-radius: 8px; }
#menu { display: none; }

.scroll { flex: 1; overflow-y: auto; padding: 24px 18px 8px; }
.welcome, .msgs { max-width: 820px; margin: 0 auto; }
.welcome h1 { color: var(--head); font-size: 26px; margin: 4vh 0 6px; letter-spacing: -.01em; }
.welcome p { margin: 0 0 20px; max-width: 640px; }
.examples { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.ex { text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; color: var(--head); }
.ex:hover { border-color: var(--accent-dim); background: #0d1b2a; }
.ex small { display: block; margin-top: 6px; color: #64748b; font-size: 11.5px; }
.ex small i { font-style: normal; color: var(--accent); }

.msg { display: flex; gap: 12px; margin: 0 0 22px; }
.avatar { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.msg.user .avatar { background: #1e293b; color: var(--head); }
.msg.bot .avatar { background: #052e22; color: var(--accent); border: 1px solid var(--accent-dim); }
.body { min-width: 0; flex: 1; }
.msg.user .bubble { color: var(--head); background: var(--panel); border: 1px solid var(--border); padding: 10px 14px; border-radius: 12px; display: inline-block; max-width: 100%; white-space: pre-wrap; word-wrap: break-word; }
.answer { color: #cbd5e1; word-wrap: break-word; }
.answer p { margin: 0 0 10px; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 20px; }
.answer li { margin-bottom: 4px; }
.answer h4 { color: var(--head); margin: 12px 0 6px; font-size: 14.5px; }
.answer .tbl { overflow-x: auto; margin: 0 0 12px; border: 1px solid var(--border); border-radius: 10px; }
.answer table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.answer th { text-align: left; color: var(--head); font-weight: 600; background: var(--panel); white-space: nowrap; }
.answer th, .answer td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.answer tr:last-child td { border-bottom: 0; }
.nw { white-space: nowrap; }
.answer code { font-family: var(--mono); font-size: 12.5px; background: var(--panel2); padding: 1px 5px; border-radius: 5px; }
.cite { font: 600 10.5px var(--mono); color: var(--accent); background: #052e22; border: 1px solid var(--accent-dim); border-radius: 5px; padding: 0 4px; margin: 0 1px; cursor: pointer; vertical-align: 1px; }
.cite:hover { background: var(--accent); color: #052e22; }
.caret::after { content: '▍'; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.err { color: var(--red); background: #2a0f12; border: 1px solid #7f1d1d; padding: 8px 12px; border-radius: 9px; margin-top: 8px; font-size: 13px; }
.meta { font: 11.5px var(--mono); color: #475569; margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- retrieval trace */
.trace { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); margin-bottom: 12px; overflow: hidden; }
.trace > summary { list-style: none; cursor: pointer; padding: 9px 12px; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--head); }
.trace > summary::-webkit-details-marker { display: none; }
.trace > summary::before { content: '▸'; color: #64748b; transition: transform .15s; }
.trace[open] > summary::before { transform: rotate(90deg); }
.trace .sum-right { margin-left: auto; font: 11.5px var(--mono); color: #64748b; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps { padding: 2px 12px 10px; }
.step { border-left: 2px solid var(--border); margin-left: 6px; padding: 0 0 10px 14px; position: relative; animation: in .25s ease; }
@keyframes in { from { opacity: 0; transform: translateY(4px); } }
.step::before { content: ''; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--panel); }
.step.run::before { background: var(--amber); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.step-h { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; color: var(--head); font-weight: 500; }
.step-h .ms { margin-left: auto; font: 11px var(--mono); color: #64748b; }
.step-b { font-size: 12px; margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font: 11px var(--mono); padding: 1px 7px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--border); color: var(--text); }
.chip.g { color: var(--accent); border-color: var(--accent-dim); }
.chip.b { color: var(--blue); border-color: #1e3a5f; }
.chip.v { color: var(--violet); border-color: #3b2a63; }
.chip.a { color: var(--amber); border-color: #5b4513; }
.hits { width: 100%; border-collapse: collapse; font-size: 11.5px; margin-top: 4px; }
.hits td, .hits th { padding: 3px 6px; border-bottom: 1px solid #172033; text-align: left; vertical-align: top; }
.hits th { font-weight: 500; color: #64748b; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
.hits td.t { color: #cbd5e1; word-break: break-word; }
.hits td.n { font-family: var(--mono); white-space: nowrap; text-align: right; }
.bar { height: 4px; border-radius: 2px; background: var(--accent); min-width: 2px; }
.bar.kw { background: var(--blue); } .bar.vec { background: var(--violet); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.src-list { display: grid; gap: 6px; margin-top: 4px; }
.src { border: 1px solid var(--border); border-radius: 9px; padding: 7px 9px; background: var(--panel2); scroll-margin: 80px; transition: border-color .2s, background .2s; }
.src.flash { border-color: var(--accent); background: #0b2a22; }
.src-h { display: flex; gap: 6px; align-items: baseline; font-size: 12px; color: var(--head); }
.src-h .n { font: 600 11px var(--mono); color: var(--accent); }
.src p { margin: 4px 0 0; font-size: 11.5px; color: var(--text); }

/* ---------- composer */
.composer { max-width: 820px; width: calc(100% - 36px); margin: 8px auto 0; display: flex; gap: 8px; align-items: flex-end; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 8px 8px 8px 14px; }
.composer:focus-within { border-color: #334155; }
.composer textarea { flex: 1; resize: none; border: 0; outline: 0; background: none; color: var(--head); font: inherit; max-height: 160px; padding: 6px 0; }
.send { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--accent); color: #052e22; font-size: 15px; }
.send:disabled { background: #1e293b; color: #475569; cursor: not-allowed; }
.hint { text-align: center; font-size: 11.5px; margin: 6px 0 10px; padding: 0 16px; }

/* ---------- KB modal */
.modal { position: fixed; inset: 0; background: rgba(2, 6, 15, .7); z-index: 10000; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.sheet { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: min(920px, 100%); height: min(80vh, 760px); display: flex; flex-direction: column; overflow: hidden; }
.sheet-head { display: flex; gap: 8px; align-items: center; padding: 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sheet-head b { margin-right: auto; }
.sheet-head input, .sheet-head select { background: var(--panel2); border: 1px solid var(--border); color: var(--head); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 13px; }
.sheet-head input { flex: 1; min-width: 160px; }
.kb { overflow-y: auto; padding: 12px; display: grid; gap: 8px; align-content: start; }
.kb .src p { font-size: 12px; }
.tag { font: 10.5px var(--mono); padding: 0 6px; border-radius: 5px; border: 1px solid var(--border); color: #64748b; margin-left: auto; white-space: nowrap; }
.tag.od { color: var(--red); border-color: #7f1d1d; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 9000; top: 0; bottom: 0; left: 0; width: 290px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(2, 6, 15, .6); }
  #menu { display: inline-block; }
  .cols { grid-template-columns: 1fr; }
  .welcome h1 { font-size: 21px; margin-top: 1vh; }
  .scroll { padding: 16px 12px 8px; }
  .composer { width: calc(100% - 24px); }
  .msg { gap: 8px; }
  .avatar { width: 26px; height: 26px; }
}
