:root {
  --bg: #0d1117;
  --bg-panel: #141a24;
  --bg-card: #1a2230;
  --border: #2a3040;
  --text: #d5dbe5;
  --muted: #8b93a3;
  --accent: #4f9cf9;
  --accent2: #7c5cff;
  --ok: #3fb96b;
  --warn: #e0a93e;
  --fail: #e05e5e;
  --mono: "Cascadia Code", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 "Segoe UI", system-ui, sans-serif;
}

/* ---------- sidebar (fixed: stays put while content scrolls) ---------- */
#sidebar {
  width: 240px; height: 100vh;
  position: fixed; top: 0; left: 0; z-index: 10;
  overflow-y: auto;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.brand { padding: 18px 18px 12px; border-bottom: 1px solid var(--border); }
.brand-title { font-weight: 700; letter-spacing: 1px; color: var(--accent); }
.brand-sub { font-size: 12px; color: var(--muted); }
.menu { list-style: none; margin: 8px 0; padding: 0; flex: 1; overflow-y: auto; }
.menu a {
  display: block; padding: 9px 18px; color: var(--text);
  text-decoration: none; border-left: 3px solid transparent;
}
.menu a:hover { background: #1d2635; }
.menu a.active {
  border-left-color: var(--accent);
  background: #1d2635; color: #fff; font-weight: 600;
}
.sidebar-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--fail); margin-right: 7px;
}
.dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.badge {
  background: var(--accent2); color: #fff; border-radius: 10px;
  font-size: 11px; padding: 1px 7px; margin-left: 6px;
}
.tbl td.date { white-space: nowrap; }
.tbl td.id { white-space: nowrap; }

/* conversation session summary (structured) */
.sumv-head { font-weight: 600; margin: 0 0 8px; }
.sumv-grid {
  display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px;
  margin: 0; font-size: 13px;
}
.sumv-grid dt { color: var(--muted); font-weight: 600; }
.sumv-grid dd { margin: 0; }

/* ---------- content ---------- */
#nav-toggle {
  display: none; background: none; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 2px 10px; margin-right: 10px; font-size: 17px; line-height: 1.4;
}
#nav-backdrop { display: none; }
#content { margin-left: 240px; padding: 0 34px 60px; max-width: 1180px; }
#topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg); border-bottom: 1px solid var(--border);
  padding: 10px 0; margin-bottom: 20px;
  font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 10px;
}
#topbar-task {
  color: var(--text);
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.top-search { display: flex; gap: 6px; flex-shrink: 0; }
.top-search input {
  width: 210px; background: #10151f; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 10px; font-size: 13px;
}
.top-search button { padding: 5px 12px; font-size: 13px; }
.topbar-label { font-weight: 600; margin-right: 6px; }

/* content links (class-less anchors in cards/body text) */
#content a:not([class]) { color: #8fbfff; text-decoration: none; }
#content a:not([class]):hover { color: #c4dcff; text-decoration: underline; }

h1 { font-size: 26px; margin: 10px 0 14px; }
h2 { font-size: 19px; margin: 6px 0 12px; color: #eaf0f8; }
h3 { font-size: 15px; margin: 16px 0 8px; color: #c8d2e0; }
code { font-family: var(--mono); font-size: 13px; color: #9ecbff; }
.muted { color: var(--muted); }
.wrap { word-break: break-word; }

.hero { padding: 26px 0 6px; }
.hero h1 { font-size: 38px; margin-bottom: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-sub { font-size: 17px; color: var(--muted); max-width: 760px; }
.credits { display: flex; gap: 26px; flex-wrap: wrap; margin: 14px 0 4px; }
.credits div { display: flex; gap: 7px; align-items: baseline; }
.credits dt { color: var(--muted); font-size: 13px; }
.credits dd { margin: 0; font-weight: 600; color: #eaf0f8; font-size: 14px; }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px 22px; margin: 16px 0;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- mobile sidebar (off-canvas ≤ 900px) ---------- */
@media (max-width: 900px) {
  #sidebar {
    transform: translateX(-105%);
    transition: transform .2s ease-in-out;
    z-index: 20;
  }
  body.nav-open #sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.6); }
  #nav-toggle { display: inline-block; }
  #nav-backdrop {
    position: fixed; inset: 0; z-index: 15;
    background: rgba(0,0,0,.5);
  }
  body.nav-open #nav-backdrop { display: block; }
  #content { margin-left: 0; padding: 0 16px 60px; }
  .top-search input { width: 120px; }
  .topbar-label { display: none; }
}

.track-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.track { background: #151d2b; border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
.track h3 { margin-top: 0; color: var(--accent); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 10px 0; }
.stat { background: #151d2b; border: 1px solid var(--border); border-radius: 8px; padding: 12px; text-align: center; }
.stat-num { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--muted); }

.state-box {
  background: #10151f; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono); font-size: 12.5px; color: #b9c4d4;
  max-height: 420px; overflow-y: auto;
}
.state-box.small { max-height: 90px; }
.log-tail { height: 380px; max-height: 380px; }
.live-chip {
  font-size: 11px; color: var(--ok); border: 1px solid var(--ok);
  border-radius: 10px; padding: 0 8px; vertical-align: middle;
}
.live-chip::before { content: "● "; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.tbl a { color: var(--accent); text-decoration: none; }
.tbl a:hover { text-decoration: underline; }
.table-scroll { overflow-x: auto; }
.table-scroll .tbl td { font-family: var(--mono); font-size: 12px; white-space: nowrap; }

.tag {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  border-radius: 10px; padding: 1px 9px; white-space: nowrap;
}
.tag-ok   { background: #14301f; color: var(--ok); border: 1px solid var(--ok); }
.tag-cond { background: #2e2a12; color: var(--warn); border: 1px solid var(--warn); }
.tag-num  { background: #152438; color: var(--accent); border: 1px solid var(--accent); }
.tag-run  { background: #241a38; color: var(--accent2); border: 1px solid var(--accent2); }
.tag-open { background: #1a1f29; color: var(--muted); border: 1px solid var(--muted); }
.tag-fail { background: #331818; color: var(--fail); border: 1px solid var(--fail); }
.tag-cat  { background: #152438; color: #9ecbff; border: 1px solid var(--border); }

.check { display: inline-block; width: 20px; height: 20px; line-height: 20px;
  text-align: center; border-radius: 50%; font-size: 12px; margin-right: 3px; }
.check-pass { background: #14301f; color: var(--ok); }
.check-fail { background: #331818; color: var(--fail); }

.commit-list { list-style: none; padding: 0; margin: 0; }
.commit-list li { padding: 5px 0; border-bottom: 1px solid var(--border); }
.commit-list code { color: var(--text); }

.ladder li { margin: 6px 0; }

.md { font-size: 15px; }
.md table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 12px 0; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; vertical-align: top; }
.md th { background: #151d2b; }
.md h1, .md h2, .md h3 { color: #eaf0f8; }
.md pre { background: #10151f; border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; }
.md code { font-size: 12.5px; }
.md blockquote { border-left: 3px solid var(--accent2); margin: 10px 0; padding: 2px 14px; color: var(--muted); }
.math-line { overflow-x: auto; }

.fb-form label, .fb-search { display: block; margin: 10px 0; font-size: 13.5px; }
.fb-form input, .fb-form select, .fb-form textarea,
.fb-search input, .fb-search select {
  display: block; width: 100%; margin-top: 4px;
  background: #10151f; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
  font: inherit;
}
.fb-search { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: end; }
button {
  background: var(--accent); color: #06121f; border: 0; border-radius: 6px;
  padding: 9px 18px; font-weight: 700; cursor: pointer; font-size: 14px;
}
button:hover { filter: brightness(1.1); }
.fb-item { border-top: 1px solid var(--border); padding: 12px 0; }

/* global search */
.search-form { display: flex; gap: 8px; margin: 14px 0 20px; max-width: 720px; }
.search-form input[type="text"] {
  flex: 1; background: #10151f; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
  font: inherit;
}
.search-hit { margin-bottom: 12px; }
.search-hit-head { margin-bottom: 4px; font-size: 14px; }
.search-hit-head a { color: var(--accent); text-decoration: none; font-weight: 600; }
.search-hit-head a:hover { text-decoration: underline; }
.snippet {
  background: #10151f; border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 10px; margin: 6px 0; font-family: var(--mono);
  font-size: 12.5px; white-space: pre-wrap; word-break: break-word;
  color: var(--muted);
}
.snippet-ln { color: var(--accent2); margin-right: 8px; user-select: none; }
.snippet mark { background: #4a3d10; color: #ffe08a; border-radius: 2px; padding: 0 1px; }

/* spreadsheet data tables (scripts & data) */
.pager { display: flex; gap: 14px; align-items: center; margin: 4px 0 8px; font-size: 13px; }
.pager a { color: var(--accent); text-decoration: none; font-weight: 600; }
.pager a:hover { text-decoration: underline; }
.sheet {
  overflow: auto; max-height: 72vh;
  border: 1px solid var(--border); border-radius: 6px;
}
.sheet table { border-collapse: separate; border-spacing: 0; font-family: var(--mono); font-size: 12.5px; }
.sheet th, .sheet td { padding: 3px 14px; white-space: nowrap; }
.sheet thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-panel); color: var(--accent);
  border-bottom: 2px solid var(--border); text-align: left;
}
.sheet td { border-bottom: 1px solid #1c2431; }
.sheet td.num { text-align: right; }
.sheet .rn {
  position: sticky; left: 0; z-index: 1;
  background: var(--bg-panel); color: var(--muted);
  text-align: right; border-right: 1px solid var(--border);
  user-select: none;
}
.sheet thead .rn { z-index: 3; }
.sheet tbody tr:hover td { background: #1d2635; }
.sheet tbody tr:hover .rn { background: #232f44; }
.json-box {
  background: #10151f; border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 14px; max-height: 480px; overflow: auto;
  font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap;
  word-break: break-word;
}
details summary { cursor: pointer; color: var(--accent); }
.code-box { white-space: pre; word-break: normal; }
details.perim { margin: 8px 0; }
details.perim > summary { line-height: 1.5; }
.fb-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.fb-notes { color: var(--muted); font-size: 13.5px; }

.messages { margin: 10px 0; }
.msg { padding: 10px 14px; border-radius: 8px; margin: 6px 0; }
.msg.success { background: #14301f; border: 1px solid var(--ok); }
.msg.error { background: #331818; border: 1px solid var(--fail); }

.log-row:hover { background: #1d2635; }
.freshness { font-size: 12.5px; }

/* ---------- conversations ---------- */
.msgcard {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 18px; margin: 12px 0;
}
.msg-user { border-left: 4px solid var(--accent2); }
.msg-assistant { border-left: 4px solid var(--accent); }
.msg-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin-bottom: 8px; font-size: 13px; }
.msg-id { font-family: var(--mono); color: var(--muted); }
.role-badge { font-size: 11.5px; font-weight: 700; border-radius: 10px; padding: 1px 9px; }
.role-user { background: #241a38; color: var(--accent2); border: 1px solid var(--accent2); }
.role-assistant { background: #152438; color: var(--accent); border: 1px solid var(--accent); }
.msg-open { margin-left: auto; color: var(--accent); text-decoration: none; font-size: 12.5px; }
.msg-open:hover { text-decoration: underline; }

.msgtext { white-space: pre-wrap; word-break: break-word; margin: 8px 0; }

details.think, details.tool, details.rawjson {
  border: 1px solid var(--border); border-radius: 8px;
  margin: 8px 0; background: #121824;
}
details.think summary, details.tool summary, details.rawjson summary {
  cursor: pointer; padding: 8px 12px; font-size: 13px; color: var(--muted);
  user-select: none;
}
details.think summary:hover, details.tool summary:hover { color: var(--text); }
.think-body {
  padding: 4px 14px 12px; white-space: pre-wrap; word-break: break-word;
  color: #b8a7e8; font-style: italic; font-size: 13.5px;
  border-top: 1px dashed var(--border);
}
.tool-body { padding: 4px 14px 12px; border-top: 1px dashed var(--border); }
.tool-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); margin: 10px 0 4px; }
.tool-body pre, .rawjson pre {
  background: #0c1119; border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; margin: 0; font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; word-break: break-all; max-height: 480px; overflow-y: auto;
}
.rawjson { margin-top: 10px; }
.rawjson pre { margin: 0 14px 12px; }

.msgnav {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 18px; margin: 14px 0;
  position: sticky; top: 44px; z-index: 4;
}
.navbtn {
  background: #152438; border: 1px solid var(--accent); color: var(--accent);
  border-radius: 6px; padding: 6px 14px; text-decoration: none; font-weight: 600;
  font-family: var(--mono); font-size: 13px;
}
.navbtn:hover { background: #1b2f4a; }
.navbtn.disabled { border-color: var(--border); color: var(--muted); background: none; }
.itemnav { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.msgpos { font-size: 13.5px; }
.jumpbox { margin-left: auto; display: flex; gap: 8px; }
.jumpbox input {
  width: 90px; background: #10151f; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
}
.jumpbox button { padding: 6px 12px; font-size: 13px; }

.conv-filter { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.conv-filter input[type="text"] {
  flex: 1; min-width: 220px; background: #10151f; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; font: inherit;
}
.conv-filter select {
  background: #10151f; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; font: inherit;
}
.count-note { font-size: 12.5px; }
