/* ============================================================
   SpectraRAG — design system
   Developer-tool aesthetic · dark-first · IBM Plex · blue accent
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Serif:wght@400;500;600&display=swap');

/* ---------- tokens ---------- */
:root,
[data-theme="dark"] {
  --bg:        #0a0c10;
  --bg-grid:   rgba(255,255,255,0.022);
  --panel:     #0f1217;
  --panel-2:   #14181f;
  --panel-3:   #191e27;
  --raise:     #1b212b;
  --border:    #232a35;
  --border-soft:#1a202a;
  --text:      #e7ebf2;
  --text-dim:  #9aa4b2;
  --text-faint:#646e7d;
  --accent:    #4d8dff;
  --accent-2:  #6fa3ff;
  --accent-soft: rgba(77,141,255,0.13);
  --accent-line: rgba(77,141,255,0.35);
  --good:      #41c97a;
  --good-soft: rgba(65,201,122,0.13);
  --warn:      #e0a531;
  --warn-soft: rgba(224,165,49,0.13);
  --visual:    #c084fc;
  --visual-soft: rgba(192,132,252,0.14);
  --shadow:    0 1px 2px rgba(0,0,0,0.4), 0 8px 30px rgba(0,0,0,0.35);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg:        #f4f5f7;
  --bg-grid:   rgba(0,0,0,0.018);
  --panel:     #ffffff;
  --panel-2:   #fbfbfd;
  --panel-3:   #f3f4f7;
  --raise:     #ffffff;
  --border:    #e3e6eb;
  --border-soft:#edeff3;
  --text:      #14171c;
  --text-dim:  #5b6573;
  --text-faint:#929aa7;
  --accent:    #2563eb;
  --accent-2:  #1d4ed8;
  --accent-soft: rgba(37,99,235,0.08);
  --accent-line: rgba(37,99,235,0.28);
  --good:      #1a9d54;
  --good-soft: rgba(26,157,84,0.10);
  --warn:      #b9770e;
  --warn-soft: rgba(185,119,14,0.10);
  --visual:    #8b3fd6;
  --visual-soft: rgba(139,63,214,0.09);
  --shadow:    0 1px 2px rgba(16,24,40,0.06), 0 12px 28px rgba(16,24,40,0.07);
  --shadow-sm: 0 1px 2px rgba(16,24,40,0.07);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .25s ease, color .25s ease;
}
#root { height: 100%; }

::selection { background: var(--accent-soft); }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-feature-settings: "tnum" 1; }
.serif { font-family: "IBM Plex Serif", Georgia, serif; }

/* ---------- app shell ---------- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100%;
  background:
    linear-gradient(var(--bg-grid) 1px, transparent 1px) 0 0 / 100% 26px,
    var(--bg);
}

/* ---------- sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--panel);
  min-height: 0;
}
.brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 26px; height: 26px; flex: none;
  border-radius: 7px;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  position: relative;
  box-shadow: 0 0 0 1px var(--accent-line), 0 4px 12px var(--accent-soft);
}
.brand-mark::before,
.brand-mark::after {
  content: ""; position: absolute; left: 5px; right: 5px;
  height: 2px; border-radius: 2px; background: rgba(255,255,255,0.9);
}
.brand-mark::before { top: 8px; opacity: .95; }
.brand-mark::after  { top: 13px; left: 8px; right: 8px; opacity: .6; box-shadow: 0 4px 0 rgba(255,255,255,0.35); }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-tag {
  margin: 10px 0 0; font-size: 11.5px; line-height: 1.5;
  color: var(--text-dim);
}

.nav { padding: 10px 10px 4px; display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-faint); padding: 12px 8px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--text-dim); cursor: pointer;
  font-size: 13.5px; font-weight: 500;
  border: 1px solid transparent;
  transition: background .12s, color .12s;
  text-align: left; width: 100%; background: none;
  font-family: inherit;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft); color: var(--text);
  border-color: var(--accent-line);
}
.nav-item.active .ico { color: var(--accent); }
.nav-item .ico { color: var(--text-faint); flex: none; }
.nav-item .count {
  margin-left: auto; font-size: 11px; color: var(--text-faint);
  font-family: "IBM Plex Mono", monospace;
}

.sidebar-spacer { flex: 1 1 auto; min-height: 12px; }

.corpus-card {
  margin: 0 12px 10px; padding: 12px;
  border: 1px solid var(--border-soft); border-radius: 10px;
  background: var(--panel-2);
}
.corpus-card h4 {
  margin: 0 0 9px; font-size: 10px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--text-faint); font-weight: 600;
}
.stat-row { display: flex; justify-content: space-between; align-items: baseline; padding: 2.5px 0; }
.stat-row .k { font-size: 11.5px; color: var(--text-dim); }
.stat-row .v { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--text); font-weight: 500; }
.stat-row .v.idx { font-size: 11px; color: var(--accent); }

.sidebar-foot {
  border-top: 1px solid var(--border-soft);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 8px;
}
.foot-links { display: flex; gap: 12px; margin-left: 4px; }
.foot-links a { color: var(--text-faint); font-size: 12px; text-decoration: none; }
.foot-links a:hover { color: var(--accent); }

/* theme toggle */
.theme-toggle {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 0;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--panel-2); padding: 2px;
}
.theme-toggle button {
  width: 28px; height: 24px; border: 0; background: none; cursor: pointer;
  display: grid; place-items: center; border-radius: 999px;
  color: var(--text-faint);
}
.theme-toggle button.on { background: var(--raise); color: var(--accent); box-shadow: var(--shadow-sm); }

/* ---------- main + topbar ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px; height: 56px; flex: none;
  position: relative; z-index: 30;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  backdrop-filter: blur(8px);
}
.topbar .crumb { font-size: 13px; color: var(--text-dim); }
.topbar .crumb b { color: var(--text); font-weight: 600; }
.topbar-sub { font-size: 11.5px; color: var(--text-faint); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.view { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; }

/* desktop: no mobile chrome */
.nav-burger { display: none; }
.nav-scrim { display: none; }

/* ---------- mobile: sidebar collapses to an off-canvas drawer ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(86vw, 320px); z-index: 200;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 150;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
  }
  .nav-burger {
    display: inline-grid; place-items: center; flex: none;
    width: 36px; height: 36px; margin-left: -4px;
    border: 1px solid var(--border); border-radius: 9px;
    background: var(--panel-2); color: var(--text-dim); cursor: pointer;
  }
  .nav-burger:hover { color: var(--text); }
  .topbar { padding: 0 14px; gap: 11px; }
  .topbar-sub { display: none; }
  .topbar .tag { display: none; }
  /* Single-column chat: a two-pane split is unusable at phone width, so hide
     the retrieval side-panel and its toggle and let the conversation fill. */
  .topbar .segmented { display: none; }
  .endpoint-model { white-space: nowrap; }
  .endpoint-keylabel { display: none; }
  .chat-wrap .retr-panel { display: none; }
  .chat-wrap .chat-col { flex: 1 1 100%; }
}

/* ---------- shared endpoint control (chat + inspection) ---------- */
.endpoint { position: relative; display: flex; gap: 7px; }
.endpoint-pill {
  display: inline-flex; align-items: center; gap: 9px;
  height: 32px; padding: 0 10px 0 11px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font-family: inherit; transition: border-color .12s, background .12s;
}
.endpoint-pill:hover { border-color: var(--text-faint); background: var(--panel-3); }
.endpoint-pill.open { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.endpoint-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: none; }
.endpoint-dot.on { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.endpoint-model { font-size: 12.5px; color: var(--text); font-weight: 500; }
.endpoint-sep { width: 1px; height: 16px; background: var(--border); }
.endpoint-caret { color: var(--text-faint); transition: transform .15s; }

.endpoint-pop {
  position: absolute; top: calc(100% + 9px); right: 0; width: 320px; z-index: 80;
  background: var(--panel); border: 1px solid var(--border); border-radius: 13px;
  box-shadow: var(--shadow); padding: 14px; transform-origin: top right;
}
.endpoint-pop-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.endpoint-pop-title { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.endpoint-pop-title .ico { color: var(--accent); }
.endpoint-pop-sub { font-size: 10.5px; color: var(--text-faint); }
.endpoint-field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.endpoint-field:last-child { margin-bottom: 0; }
.endpoint-keystat { display: inline-flex; align-items: center; gap: 7px; font-size: 10.5px; color: var(--text-faint); }
.endpoint-keystat.ok { color: var(--good); }

.model-list { display: flex; flex-direction: column; gap: 3px; max-height: 230px; overflow-y: auto; }
.model-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 9px; border-radius: 8px;
  border: 1px solid transparent; background: none; cursor: pointer; text-align: left; width: 100%; font-family: inherit;
}
.model-row:hover { background: var(--panel-2); }
.model-row.on { background: var(--accent-soft); border-color: var(--accent-line); }
.model-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.model-row-id { font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-row-note { font-size: 10.5px; color: var(--text-faint); font-family: "IBM Plex Mono", monospace; }
.model-row-check { color: var(--accent); flex: none; }
.model-group-label {
  font-size: 10px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint); font-family: "IBM Plex Mono", monospace;
  margin: 9px 2px 2px;
}
.model-list .model-group-label:first-child { margin-top: 2px; }
.model-row.locked { opacity: .55; }
.model-row.locked:hover { opacity: .8; background: var(--panel-2); }
.endpoint-cta { margin-top: 11px; width: 100%; justify-content: center; }
.endpoint-keystat a { color: var(--accent); }
.route-card a, .retr-empty a { color: var(--accent); }

/* settings row (now holds New chat) */
.adv-toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 4px 24px; border-bottom: 1px solid var(--border-soft);
}

/* ---------- generic controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel-3); border-color: var(--text-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: none; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-note { font-size: 10.5px; color: var(--text-faint); line-height: 1.45; }
.field > label {
  font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); font-weight: 600;
}
.input, .select {
  font-family: "IBM Plex Mono", monospace; font-size: 13px;
  padding: 8px 11px; border-radius: 8px; color: var(--text);
  border: 1px solid var(--border); background: var(--panel);
  outline: none; transition: border-color .12s, box-shadow .12s;
  width: 100%;
}
.input::placeholder { color: var(--text-faint); }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text-dim);
  cursor: pointer; transition: all .12s; font-family: inherit;
}
.chip:hover { border-color: var(--accent-line); color: var(--text); background: var(--accent-soft); }

.tag {
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px;
  padding: 2px 7px; border-radius: 5px; letter-spacing: .02em;
  background: var(--panel-3); color: var(--text-dim); border: 1px solid var(--border-soft);
  white-space: nowrap;
}
.pill {
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px; display: inline-flex; align-items: center; gap: 5px;
  white-space: nowrap;
}
.pill.text   { background: var(--accent-soft); color: var(--accent); }
.pill.visual { background: var(--visual-soft); color: var(--visual); }
.pill.mixed  { background: var(--good-soft); color: var(--good); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* figure placeholder */
.fig-ph {
  position: relative; border-radius: 8px; overflow: hidden;
  background:
    repeating-linear-gradient(135deg, var(--panel-3) 0 9px, var(--panel-2) 9px 18px);
  border: 1px solid var(--border-soft);
  display: grid; place-items: center; color: var(--text-faint);
}
.fig-ph .fig-kind {
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 5px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
}

/* score bar */
.scorebar { height: 5px; border-radius: 3px; background: var(--panel-3); overflow: hidden; }
.scorebar > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.scorebar.visual > i { background: var(--visual); }
.scorebar.dropped > i { background: var(--text-faint); opacity: .55; }

.divider { height: 1px; background: var(--border-soft); border: 0; margin: 0; }

.kbd {
  font-family: "IBM Plex Mono", monospace; font-size: 11px;
  padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text-dim);
}

/* fade-in */
@keyframes riseIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.rise { animation: riseIn .4s cubic-bezier(.2,.7,.3,1) both; }
@keyframes blink { 50% { opacity: 0; } }
.caret { display: inline-block; width: 7px; height: 15px; background: var(--accent); vertical-align: -2px; margin-left: 2px; animation: blink 1s steps(1) infinite; border-radius: 1px; }

@media (prefers-reduced-motion: reduce) {
  .rise { animation: none; }
}

/* ---------- markdown / answers ---------- */
.md p { margin: 0 0 12px; }
.md p:last-child { margin-bottom: 0; }
.md ol { margin: 0 0 12px; padding-left: 0; list-style: none; counter-reset: li; }
.md ol li { position: relative; padding-left: 30px; margin-bottom: 8px; counter-increment: li; }
.md ol li::before {
  content: counter(li); position: absolute; left: 0; top: 1px;
  width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
  font-family: "IBM Plex Mono", monospace; font-size: 11px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line);
}
.md ul { margin: 0 0 12px; padding-left: 0; list-style: none; }
.md ul li { position: relative; padding-left: 30px; margin-bottom: 8px; }
.md ul li::before {
  content: ""; position: absolute; left: 7px; top: 8px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); opacity: .75;
}
.md strong { font-weight: 600; color: var(--text); }
.cite-ref {
  font-family: "IBM Plex Mono", monospace; font-size: 9.5px; font-weight: 600;
  cursor: pointer; vertical-align: super; line-height: 0; margin: 0 1px;
  color: var(--accent); padding: 1px 4px; border-radius: 4px;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  transition: background .12s;
}
.cite-ref:hover { background: var(--accent); color: #fff; }
.cite-ref.fig { color: var(--visual); background: var(--visual-soft); border-color: color-mix(in srgb, var(--visual) 40%, transparent); }
.cite-ref.fig:hover { background: var(--visual); color: #fff; }

/* ---------- segmented ---------- */
.segmented { display: inline-flex; padding: 2px; gap: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.seg {
  font-family: "IBM Plex Mono", monospace; font-size: 11.5px; font-weight: 500;
  padding: 4px 10px; border: 0; border-radius: 6px; background: none; color: var(--text-dim); cursor: pointer;
}
.seg.on { background: var(--raise); color: var(--accent); box-shadow: var(--shadow-sm); }
.seg.off { opacity: .4; cursor: not-allowed; }

/* ---------- figure thumb ---------- */
.figthumb { display: flex; flex-direction: column; gap: 5px; }
.figthumb-meta { font-size: 10.5px; color: var(--text-faint); }
.figthumb-meta .mono { color: var(--text-dim); }

/* tooltip */
.tt { position: relative; }
.tt::after {
  content: attr(data-tt); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--raise); color: var(--text); border: 1px solid var(--border);
  font-size: 11px; padding: 5px 8px; border-radius: 6px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .12s; box-shadow: var(--shadow); z-index: 50;
  font-family: "IBM Plex Sans", sans-serif; font-weight: 400;
}
.tt:hover::after { opacity: 1; }

/* ============================================================
   CHAT VIEW
   ============================================================ */
.chat-wrap { display: flex; flex: 1; min-width: 0; }
.chat-col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; min-height: 0; }

/* config strip */
.config-strip {
  display: flex; align-items: flex-end; gap: 12px; padding: 14px 24px;
  border-bottom: 1px solid var(--border-soft); flex: none; flex-wrap: wrap;
}
.config-strip .field { min-width: 0; }
.config-strip .field.key { flex: 1 1 280px; max-width: 380px; }
.config-strip .field.model { flex: 0 1 280px; }
.label-info { display: inline-flex; align-items: center; gap: 5px; }
.label-info .ico { color: var(--text-faint); }

.adv-toggle {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none;
  font-size: 12px; color: var(--text-dim); padding: 7px 0;
}
.adv-toggle .ico { transition: transform .15s; }
.adv-toggle.open .ico { transform: rotate(90deg); }
.adv-panel {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 22px;
  padding: 16px 24px; border-bottom: 1px solid var(--border-soft);
  background: var(--panel-2);
}
@media (max-width: 760px) { .adv-panel { grid-template-columns: 1fr; } }
.adv-panel .range-row { display: flex; align-items: center; gap: 10px; }
.adv-panel input[type=range] { flex: 1; accent-color: var(--accent); }
.adv-panel .range-val { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--accent); min-width: 24px; text-align: right; }

/* scroll area + empty state */
.chat-scroll { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.chat-inner { max-width: 760px; margin: 0 auto; padding: 28px 24px 24px; }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 6px; min-height: 100%; padding: 40px 24px;
}
.empty-mark {
  width: 52px; height: 52px; border-radius: 14px; margin-bottom: 8px;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; box-shadow: 0 8px 30px var(--accent-soft), 0 0 0 1px var(--accent-line);
}
.empty h2 { margin: 4px 0 2px; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.empty p { margin: 0 0 18px; color: var(--text-dim); font-size: 13.5px; max-width: 420px; }
.suggest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 600px; }
.suggest {
  text-align: left; padding: 13px 14px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font-family: inherit; font-size: 13px; line-height: 1.45; transition: all .14s;
  display: flex; flex-direction: column; gap: 9px;
}
.suggest:hover { border-color: var(--accent-line); background: var(--accent-soft); transform: translateY(-1px); }
.suggest .q { font-weight: 500; }

/* messages */
.msg { margin-bottom: 26px; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  padding: 10px 14px; border-radius: 13px 13px 4px 13px; max-width: 80%;
  font-size: 14px; color: var(--text);
}
.msg-ai .ai-head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.ai-avatar {
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff;
}
.ai-name { font-size: 12px; font-weight: 600; }
.ai-meta { margin-left: auto; display: flex; align-items: center; gap: 8px; font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--text-faint); }
.ai-body { font-size: 14px; }
.ai-body .md p, .ai-body .md li { color: var(--text); }
.ai-body.err .md p, .ai-body.err .md li { color: #e0716f; }

/* inline figure cards inside answer */
.answer-figs { display: flex; gap: 10px; margin: 14px 0 2px; flex-wrap: wrap; }
.answer-fig {
  width: 168px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: var(--panel); cursor: pointer; transition: border-color .12s;
}
.answer-fig:hover { border-color: var(--accent-line); }
.answer-fig .cap { padding: 8px 10px; font-size: 11px; color: var(--text-dim); line-height: 1.4; }
.answer-fig .cap b { color: var(--visual); font-family: "IBM Plex Mono", monospace; font-size: 10px; }
.answer-fig-img { overflow: hidden; background: #fdfdfb; }
.answer-fig-img img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }

.ai-foot { display: flex; align-items: center; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.metric { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-faint); }
.metric b { font-family: "IBM Plex Mono", monospace; color: var(--text-dim); font-weight: 500; }
.ai-foot .acts { margin-left: auto; display: flex; gap: 4px; }

/* composer */
.composer-wrap { flex: none; padding: 14px 24px 18px; border-top: 1px solid var(--border); background: var(--panel); }
.composer { max-width: 760px; margin: 0 auto; }
.composer-box {
  display: flex; align-items: flex-end; gap: 10px; padding: 8px 8px 8px 14px;
  border: 1px solid var(--border); border-radius: 13px; background: var(--panel-2);
  transition: border-color .12s, box-shadow .12s;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer-box textarea {
  flex: 1; border: 0; background: none; resize: none; outline: none; color: var(--text);
  font-family: inherit; font-size: 14px; line-height: 1.5; max-height: 140px; padding: 6px 0;
}
.composer-box textarea::placeholder { color: var(--text-faint); }
.composer-hint { display: flex; align-items: center; gap: 10px; margin-top: 9px; justify-content: flex-end; }
.composer-hint .left { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-faint); }

/* ============================================================
   RETRIEVAL PANEL (chat right)
   ============================================================ */
.retr-panel {
  width: 384px; flex: none; border-left: 1px solid var(--border);
  background: var(--panel); display: flex; flex-direction: column; min-height: 0;
}
.retr-head { padding: 14px 16px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; gap: 8px; flex: none; }
.retr-head h3 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-dim); }
.retr-head .live { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-family: "IBM Plex Mono", monospace; font-size: 10.5px; color: var(--good); }
.retr-head .live .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.retr-body { flex: 1; overflow-y: auto; padding: 16px; min-height: 0; }
.retr-empty { color: var(--text-faint); font-size: 12.5px; text-align: center; padding: 40px 16px; line-height: 1.6; }

.retr-section { margin-bottom: 22px; }
.retr-section > h4 {
  margin: 0 0 11px; font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-faint); font-weight: 600; display: flex; align-items: center; gap: 7px;
}
.retr-section > h4 .n { margin-left: auto; font-family: "IBM Plex Mono", monospace; color: var(--text-dim); letter-spacing: 0; }

/* route summary */
.route-card { border: 1px solid var(--border-soft); border-radius: 10px; padding: 12px; background: var(--panel-2); }
.route-card .gate { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.route-bars { display: flex; flex-direction: column; gap: 9px; }
.route-bars .rb { display: grid; grid-template-columns: 54px 1fr 38px; align-items: center; gap: 9px; }
.route-bars .rb .lbl { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--text-dim); }
.route-bars .rb .pct { font-family: "IBM Plex Mono", monospace; font-size: 11px; text-align: right; color: var(--text); }

/* candidate / evidence rows */
.cand { padding: 11px; border: 1px solid var(--border-soft); border-radius: 10px; margin-bottom: 8px; background: var(--panel-2); transition: border-color .12s; }
.cand.hl { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cand.dropped { opacity: .62; }
.cand-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cand-num { font-family: "IBM Plex Mono", monospace; font-size: 10px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: 5px; padding: 1px 6px; }
.cand-num.visual { color: var(--visual); background: var(--visual-soft); border-color: color-mix(in srgb, var(--visual) 40%, transparent); }
.cand-src { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--text-dim); }
.cand-score { margin-left: auto; font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--text); font-weight: 500; }
.cand-quote { font-family: "IBM Plex Serif", serif; font-size: 12.5px; line-height: 1.55; color: var(--text-dim); margin: 6px 0 8px; padding-left: 9px; border-left: 2px solid var(--border); }
.cand-meta { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.pin-note { font-size: 10.5px; color: var(--text-faint); line-height: 1.45; white-space: normal; }
.cand-status { font-family: "IBM Plex Mono", monospace; font-size: 10px; letter-spacing: .04em; }
.cand-status.kept { color: var(--good); }
.cand-status.dropped { color: var(--text-faint); }

/* ---------- tweak-driven variants ---------- */
[data-density="compact"] body, body[data-density] { }
[data-density="compact"] .chat-inner { padding: 18px 24px 18px; }
[data-density="compact"] .msg { margin-bottom: 18px; }
[data-density="compact"] .ai-body, [data-density="compact"] .msg-user .bubble { font-size: 13px; }
[data-density="compact"] .content-pad { padding: 16px 24px 40px; }
[data-density="compact"] .paper-grid, [data-density="compact"] .figure-grid { gap: 11px; }

[data-density="comfy"] .chat-inner { padding: 40px 24px 28px; max-width: 800px; }
[data-density="comfy"] .msg { margin-bottom: 34px; }
[data-density="comfy"] .ai-body, [data-density="comfy"] .msg-user .bubble { font-size: 15px; }
[data-density="comfy"] .content-pad { padding: 32px 32px 56px; }
[data-density="comfy"] .paper-grid, [data-density="comfy"] .figure-grid { gap: 18px; }

[data-answerfont="serif"] .ai-body .md { font-family: "IBM Plex Serif", Georgia, serif; font-size: 14.5px; line-height: 1.62; }
