/* Brain — zach.oligarchie.dev. Warm paper by day, graphite by night. No navy, no glow. */
:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #f9f6ef;
  --line: #e4ded2;
  --line-strong: #d2cbbd;
  --ink: #1f1d1a;
  --ink-2: #57524a;
  --muted: #6f695f;
  --accent: #d0531f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3d8;
  --ok: #2f7d4a;
  --warn: #a86a12;
  --bad: #b3361f;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px rgba(40, 30, 10, .06);
  --lobe-fill: .08;
  --lobe-stroke: .35;

  --a-leo: #2c7a72;
  --a-health: #3d8a46;
  --a-relationships: #c04e74;
  --a-personal-growth: #b07d18;
  --a-finances: #3f6aa6;
  --a-kyra: #7f55b8;
  --a-misc: #7b7366;
  --a-system: var(--accent);

  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 10px;
  --panel-w: 440px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413;
    --surface: #1c1b19;
    --surface-2: #222120;
    --line: #2e2c29;
    --line-strong: #3d3a36;
    --ink: #eeebe4;
    --ink-2: #bdb8ae;
    --muted: #9b958a;
    --accent: #ef7a45;
    --accent-ink: #1a0f08;
    --accent-soft: #3a2519;
    --ok: #6cc08a;
    --warn: #e0a84a;
    --bad: #f07c66;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .25);
    --lobe-fill: .11;
    --lobe-stroke: .45;
    --a-leo: #4fb3a8;
    --a-health: #6fbf6f;
    --a-relationships: #e27a9c;
    --a-personal-growth: #d9a53e;
    --a-finances: #6f98d6;
    --a-kyra: #a985de;
    --a-misc: #a69e90;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413;
  --surface: #1c1b19;
  --surface-2: #222120;
  --line: #2e2c29;
  --line-strong: #3d3a36;
  --ink: #eeebe4;
  --ink-2: #bdb8ae;
  --muted: #9b958a;
  --accent: #ef7a45;
  --accent-ink: #1a0f08;
  --accent-soft: #3a2519;
  --ok: #6cc08a;
  --warn: #e0a84a;
  --bad: #f07c66;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .25);
  --lobe-fill: .11;
  --lobe-stroke: .45;
  --a-leo: #4fb3a8;
  --a-health: #6fbf6f;
  --a-relationships: #e27a9c;
  --a-personal-growth: #d9a53e;
  --a-finances: #6f98d6;
  --a-kyra: #a985de;
  --a-misc: #a69e90;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ layout */
.app { display: grid; grid-template-rows: auto 1fr; height: 100dvh; }
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--bg);
  min-width: 0;
}
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand h1 { font: 400 26px/1 var(--serif); margin: 0; letter-spacing: -.01em; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); display: inline-block; transform: translateY(-2px); }
.brand small { color: var(--muted); font-size: 12px; }
.filters { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 5px 11px 5px 9px; font-size: 13px;
}
.chip[aria-pressed="false"] { background: transparent; color: var(--muted); border-color: var(--line); }
.chip[aria-pressed="false"] svg { opacity: .35; }
.chip b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="false"] b { color: var(--muted); }
.spacer { flex: 1; }
.search {
  width: 220px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; outline: none;
}
.search:focus { border-color: var(--line-strong); }
.iconbtn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  height: 34px; min-width: 34px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--ink-2);
}
.iconbtn:hover { border-color: var(--line-strong); color: var(--ink); }
.iconbtn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.iconbtn .badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 11px; padding: 0 6px; font-weight: 600; }

.main { display: grid; grid-template-columns: 1fr var(--panel-w); min-height: 0; }
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.panel {
  border-left: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}

/* ------------------------------------------------------------ map */
svg.map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; }
svg.map.dragging { cursor: grabbing; }
.map .spoke { fill: none; stroke: var(--line-strong); stroke-width: 1.2; }
.map .lobe { transition: transform .5s cubic-bezier(.2,.7,.2,1); }
.map .lobe-bg { stroke-width: 1.2; }
.map .lobe-label { font: 400 21px var(--serif); fill: var(--ink); pointer-events: none; }
.map .lobe-sub { font: 500 10.5px var(--sans); fill: var(--muted); letter-spacing: .06em; text-transform: uppercase; pointer-events: none; }
.map .node { transition: transform .5s cubic-bezier(.2,.7,.2,1), opacity .25s; cursor: pointer; }
.map .node .hit { fill: transparent; }
.map .node:hover .shape, .map .node.sel .shape { stroke: var(--ink); stroke-width: 2; }
.map .node.dim, .map .lobe.dim .lobe-bg { opacity: .18; }
.map .node.off { opacity: 0; pointer-events: none; }
.map .nlabel { font: 500 11px var(--sans); fill: var(--ink-2); pointer-events: none; paint-order: stroke; stroke: var(--bg); stroke-width: 3.5px; opacity: 0; transition: opacity .2s; }
.map.zoomed .node.big .nlabel, .map .node:hover .nlabel, .map .node.sel .nlabel, .map .node.hit-search .nlabel { opacity: 1; }
.map .core-c { fill: var(--accent); }
.map .core-ring { fill: none; stroke: var(--accent); stroke-opacity: .35; stroke-dasharray: 2 5; }
.map .core-t { font: 400 24px var(--serif); fill: var(--accent-ink); pointer-events: none; }
.map .core { cursor: pointer; }
.map .pulse { animation: pulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 50% { opacity: .35; } }

.legend {
  position: absolute; left: 16px; bottom: 16px; display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); background: color-mix(in srgb, var(--bg) 85%, transparent);
  padding: 6px 10px; border-radius: 8px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.zoomctl { position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--bg);
  font-size: 12.5px; padding: 6px 9px; border-radius: 6px; max-width: 280px; z-index: 5;
  transform: translate(-50%, calc(-100% - 12px)); opacity: 0; transition: opacity .12s;
}
.tip.on { opacity: 1; }
.tip small { display: block; opacity: .7; font-size: 11px; }

/* ------------------------------------------------------------ panel */
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: none; padding: 8px 10px 10px; color: var(--muted); border-bottom: 2px solid transparent;
  font-weight: 500; display: inline-flex; gap: 6px; align-items: center;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tab .badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 10.5px; padding: 0 6px; font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; min-height: 0; }
.panel-close { display: none; }
.pad { padding: 18px 20px 28px; }

.crumb { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.crumb button { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.kind { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.d-title { font: 400 30px/1.1 var(--serif); margin: 4px 0 8px; letter-spacing: -.01em; }
.d-lead { color: var(--ink-2); margin: 0 0 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 6px; }
.btn {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 7px 12px;
  display: inline-flex; gap: 6px; align-items: center; font-weight: 500;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .5; cursor: default; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin: 14px 0; }
.stat { border: 1px solid var(--line); border-radius: var(--r); padding: 9px 11px; background: var(--surface-2); text-align: left; }
button.stat:hover { border-color: var(--line-strong); }
.stat b { display: block; font: 400 24px/1.1 var(--serif); }
.stat span { font-size: 11.5px; color: var(--muted); }
h3.sec { font-size: 11.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; display: flex; justify-content: space-between; align-items: baseline; }
h3.sec small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.list li { border-bottom: 1px solid var(--line); }
.row { display: flex; gap: 10px; align-items: flex-start; width: 100%; padding: 9px 2px; border: 0; background: none; text-align: left; }
button.row:hover { background: var(--surface-2); }
.row .ic { flex: none; margin-top: 3px; }
.row .tx { flex: 1; min-width: 0; }
.row .t { display: block; font-weight: 500; overflow-wrap: anywhere; }
.row .s { display: block; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row .r { flex: none; color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--ink-2); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: currentColor; }
.pill.warn { color: var(--warn); border-color: currentColor; }
.pill.bad { color: var(--bad); border-color: currentColor; }
.more { border: 0; background: none; color: var(--accent); padding: 8px 2px; font-weight: 500; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; margin: 10px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.kpis { display: grid; gap: 8px; }
.kpi { display: flex; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: var(--r); padding: 9px 12px; background: var(--surface-2); }
.kpi span { color: var(--ink-2); font-size: 13px; }
.kpi b { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.kpi.na b { color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); font-style: italic; padding: 8px 0; }

/* markdown */
.md { font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 1.3em 0 .5em; }
.md h1 { font: 400 26px/1.15 var(--serif); }
.md h2 { font-size: 16px; }
.md h3, .md h4 { font-size: 14px; }
.md p { margin: .6em 0; }
.md ul, .md ol { padding-left: 1.3em; margin: .5em 0; }
.md li { margin: .2em 0; }
.md pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: 12.5px; }
.md code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: .6em 0; padding: 2px 12px; border-left: 3px solid var(--line-strong); color: var(--ink-2); }
.md table { border-collapse: collapse; font-size: 12.5px; display: block; overflow-x: auto; margin: .6em 0; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md .fm { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-bottom: 10px; font-family: var(--mono); white-space: pre-wrap; }
.md > :first-child { margin-top: 0; }

/* ------------------------------------------------------------ chat */
.threads-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 8px; }
.threads-head h2 { font: 400 24px var(--serif); margin: 0; }
.thread-item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 12px 20px; }
.thread-item:hover { background: var(--surface-2); }
.thread-item .top-l { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.thread-item .tt { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-item .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.thread-item .lt { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; margin-top: 2px; }
.scope { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--ink-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.scope i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.thinking-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; animation: pulse 1.2s infinite; }

.chat { display: flex; flex-direction: column; height: 100%; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.chat-head .tx { flex: 1; min-width: 0; }
.chat-head .tt { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.msg { max-width: 92%; }
.msg.olivier { align-self: flex-end; background: var(--ink); color: var(--bg); border-radius: 14px 14px 4px 14px; padding: 9px 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.zach { align-self: flex-start; }
.msg.zach .who, .msg.error .who { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; display: flex; gap: 6px; align-items: center; }
.msg.zach .who i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.msg.zach .md { background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 9px 13px; }
.msg.error { align-self: stretch; color: var(--bad); font-size: 13px; border: 1px dashed currentColor; border-radius: 10px; padding: 8px 12px; }
.msg.pending { align-self: flex-start; color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.composer { border-top: 1px solid var(--line); padding: 10px 12px 12px; background: var(--surface); }
.composer .scope-pick { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 12.5px; color: var(--muted); }
.composer select { border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 4px 8px; max-width: 100%; flex: 1; min-width: 0; }
.composer .box { display: flex; gap: 8px; align-items: flex-end; border: 1px solid var(--line-strong); border-radius: 12px; padding: 6px 6px 6px 12px; background: var(--surface); }
.composer .box:focus-within { border-color: var(--ink-2); }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; background: none; max-height: 200px; padding: 6px 0; line-height: 1.45; }
.send { border: 0; background: var(--accent); color: var(--accent-ink); width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .4; cursor: default; }
.hint { font-size: 11.5px; color: var(--muted); margin: 6px 4px 0; }

/* ------------------------------------------------------------ login */
.login-page { display: grid; place-items: center; min-height: 100dvh; overflow: auto; }
.login { width: min(360px, calc(100vw - 32px)); }
.login h1 { font: 400 44px/1 var(--serif); margin: 0 0 6px; display: flex; align-items: center; gap: 10px; }
.login p { color: var(--muted); margin: 0 0 24px; }
.login label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 4px; }
.login input { width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 10px; padding: 10px 12px; outline: none; }
.login input:focus { border-color: var(--ink-2); }
.login button { margin-top: 18px; width: 100%; justify-content: center; padding: 10px; }
.login .msg-e { color: var(--bad); min-height: 1.5em; margin-top: 10px; font-size: 13px; }

/* ------------------------------------------------------------ narrow */
@media (max-width: 980px) {
  :root { --panel-w: 380px; }
  .search { width: 150px; }
  .brand small { display: none; }
}
@media (max-width: 760px) {
  .top { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .filters { order: 3; flex-basis: 100%; }
  .search { width: auto; flex: 1; min-width: 0; }
  .spacer { display: none; }
  .main { grid-template-columns: 1fr; }
  .panel {
    position: fixed; inset: 0; z-index: 20; border-left: 0;
    transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.7,.2,1);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: none; }
  .panel-close { display: inline-flex; margin-left: auto; align-self: center; }
  .legend { left: 10px; bottom: 10px; right: 64px; gap: 8px 12px; font-size: 11px; }
  .zoomctl { right: 10px; bottom: 10px; }
  .pad { padding: 16px 16px 28px; }
  .thread-item { padding: 12px 16px; }
  .threads-head { padding: 14px 16px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
