:root {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #141414;
  --border: #242424;
  --muted: #737373;
  --text: #e8e8e8;
  --accent: #ff5f1f;
  --accent-dim: #b3400f;
  --green: #3ddc84;
  --blue: #4ea1ff;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: 16px; }

/* ---- Login ---- */
.login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #140a05, #000 70%);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px 28px; width: 320px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.login-glyph { margin-bottom: 6px; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; letter-spacing: .5px; }
.login-card .muted { margin: 2px 0 18px; }
.login-card input {
  width: 100%; padding: 11px 13px; margin-bottom: 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-err { color: #ff5b5b; font-size: 12px; min-height: 16px; margin-top: 6px; }

/* ---- App layout ---- */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 18px; padding: 0 16px; height: 54px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .4px; }
.tabs { display: flex; gap: 2px; }
.tab {
  background: none; border: none; color: var(--muted); padding: 8px 14px; cursor: pointer;
  border-radius: 8px; font-size: 13px; font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); background: var(--surface-2); }
.global-search { margin-left: auto; display: flex; gap: 6px; }
.global-search input {
  width: 240px; padding: 8px 11px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 13px;
}
.global-search input:focus { outline: none; border-color: var(--accent); }
.logout { margin-left: 6px; }

button { font-family: var(--sans); }
.btn-primary {
  background: var(--accent); color: #fff; border: none; padding: 11px 16px; border-radius: 8px;
  font-weight: 700; cursor: pointer; font-size: 14px; width: 100%;
}
.btn-primary:hover { background: var(--accent-dim); }
.btn-ghost {
  background: none; border: 1px solid var(--border); color: var(--muted); padding: 7px 12px;
  border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

main { flex: 1; overflow: hidden; }
.panel { height: 100%; display: none; }
.panel.active { display: flex; }

/* ---- Vault ---- */
#panel-vault { flex-direction: row; }
.tree {
  width: 320px; min-width: 220px; border-right: 1px solid var(--border);
  overflow: auto; padding: 8px; background: var(--surface);
}
.tree-dir { user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px;
  cursor: pointer; font-size: 13px; color: var(--text); white-space: nowrap;
}
.tree-row:hover { background: var(--surface-2); }
.tree-row .chev { color: var(--muted); width: 12px; display: inline-block; text-align: center; }
.tree-row .ico { opacity: .8; }
.tree-children { margin-left: 14px; border-left: 1px solid var(--border); padding-left: 4px; }
.tree-file .name { color: var(--muted); }
.tree-file:hover .name { color: var(--text); }

.reader { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.reader-bar {
  padding: 9px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  display: flex; justify-content: space-between; gap: 10px;
}
.reader-body { flex: 1; overflow: auto; padding: 20px 24px; }
.reader-body pre {
  font-family: var(--mono); font-size: 13px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word;
}
.binary-note { color: var(--muted); font-style: italic; }

/* ---- Memory ---- */
#panel-memory { flex-direction: column; overflow: hidden; }
.mem-toolbar { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.mem-toolbar input { flex: 1; padding: 8px 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.mem-toolbar input:focus { outline: none; border-color: var(--accent); }
.mem-toolbar select { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px; }
.mem-stats { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.stat-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: 12px; color: var(--muted); }
.stat-chip b { color: var(--accent); }
.mem-list { flex: 1; overflow: auto; padding: 12px 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(360px,1fr)); gap: 12px; align-content: start; }
.mem-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  font-size: 13px; line-height: 1.5;
}
.mem-card.pinned { border-color: var(--accent-dim); }
.mem-card .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; font-size: 11px; }
.badge { border-radius: 5px; padding: 1px 7px; font-weight: 600; }
.badge-veracity-STATED { background: #1a2a3a; color: var(--blue); }
.badge-veracity-inferred { background: #2a241a; color: #e0b34a; }
.badge-veracity-tool { background: #1a2a1f; color: var(--green); }
.badge-scope { background: var(--surface-2); color: var(--muted); }
.badge-pin { background: var(--accent-dim); color: #fff; }
.badge-type { background: var(--surface-2); color: var(--muted); }
.mem-card .content { color: var(--text); white-space: pre-wrap; word-break: break-word; }
.mem-card .content mark { background: var(--accent); color: #000; border-radius: 2px; padding: 0 1px; }
.mem-card .ts { color: var(--muted); font-size: 11px; margin-top: 6px; }

/* ---- KG ---- */
.kg-layout { flex: 1; display: flex; overflow: hidden; }
.kg-canvas-wrap { flex: 1; overflow: hidden; position: relative; background:
  radial-gradient(circle at 50% 40%, #0d0d0d, #000 70%); }
.kg-svg { width: 100%; height: 100%; }
.kg-side { width: 280px; border-left: 1px solid var(--border); overflow: auto; padding: 14px; background: var(--surface); }
.kg-side h3 { margin: 0 0 8px; font-size: 13px; color: var(--accent); }
.kg-node circle { cursor: pointer; }
.kg-node text { font-size: 10px; fill: var(--muted); pointer-events: none; }
.kg-edge { stroke: #333; stroke-width: 1; }
.kg-edge-label { fill: #555; font-size: 9px; }
.legend { position: absolute; bottom: 12px; left: 12px; font-size: 11px; color: var(--muted); }
.legend span { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

/* ---- Gists ---- */
#panel-gists { overflow: auto; }
.gist-list { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; max-width: 900px; }
.gist-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.gist-card .meta { display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.gist-card .text { font-size: 13px; line-height: 1.55; white-space: pre-wrap; }

/* ---- Global results ---- */
#panel-global { flex-direction: column; overflow: auto; padding: 16px; gap: 18px; }
.res-section h2 { font-size: 14px; color: var(--accent); margin: 0 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.res-item { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--surface); }
.res-item .rl { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-bottom: 3px; cursor: pointer; }
.res-item .rl:hover { color: var(--accent); }
.res-item .tx { font-size: 13px; line-height: 1.5; }
.res-item .tx mark { background: var(--accent); color: #000; border-radius: 2px; padding: 0 1px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
