:root {
  --bg: #0a0a0c;
  --sidebar: #0c0c0f;
  --surface: #141418;
  --surface-2: #1a1a20;
  --line: #232329;
  --line-2: #2c2c34;
  --text: #f2f2f4;
  --dim: #8b8b95;
  --dim-2: #63636d;
  --accent: #f59e0b;
  --blue: #5b8cff;
  --ok: #34d399;
  --err: #f87171;
}
* { box-sizing: border-box; }
/* `[hidden]` only sets `display: none` from the UA stylesheet, so ANY author
   `display` rule silently beats it. That has produced two bugs in one day — a
   Sign out button shown to people who were not signed in, and an invisible
   scrim eating every click on the page. The attribute wins from here on. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#app { display: grid; grid-template-columns: 248px 1fr 0; height: 100vh; transition: grid-template-columns .2s; }
#app.drawer-open { grid-template-columns: 248px 1fr 320px; }

/* ---------- Sidebar ---------- */
#sidebar { background: var(--sidebar); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; gap: 18px; }
.side-top { display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; padding: 6px 8px 12px; }
.brand .mark { width: 16px; height: 16px; border-radius: 5px; background: conic-gradient(from 200deg, var(--accent), var(--blue), var(--accent)); box-shadow: 0 0 16px -2px var(--accent); }
.side-group { display: flex; flex-direction: column; gap: 2px; }
.side-label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim-2); padding: 6px 10px; }
.side-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent; border: none; color: var(--dim); padding: 8px 10px; border-radius: 9px; font: inherit; font-size: 14px; cursor: pointer; transition: .12s; }
.side-item:hover { background: var(--surface); color: var(--text); }
.side-item.strong { color: var(--text); }
/* Which view you're in. Without this the sidebar gives no clue where you are,
   which is half of why getting back to the conversation felt like a dead end. */
.side-item.active { background: var(--surface); color: var(--text); }
.side-item.soon { opacity: .5; cursor: default; }
.side-item.soon:hover { background: transparent; color: var(--dim); }
.side-item .badge { margin-left: auto; font-size: 11px; color: var(--dim-2); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }
.side-item .soon-badge { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.side-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.sandbox { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--dim); padding: 6px 10px; border: 1px solid var(--line); border-radius: 9px; width: fit-content; }
.sandbox .s-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dim-2); }
.sandbox.on { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, var(--line)); }
.sandbox.on .s-dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

/* ---------- Main ---------- */
#main { display: flex; flex-direction: column; min-width: 0; position: relative; }
#topbar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; position: absolute; top: 0; left: 0; right: 0; z-index: 3; }
.spacer { flex: 1; }
.status { font-size: 11px; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line); text-transform: uppercase; letter-spacing: .07em; color: var(--dim); background: color-mix(in srgb, var(--bg) 70%, transparent); }
.status.running { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 45%, var(--line)); }
.status.running::before { content: "●"; margin-right: 6px; animation: pulse 1s infinite; }
.status.error { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
/* The stream dropped and we're resuming from the last event we saw. The work
   itself keeps running on the server, so this is a warning, not an error. */
/* Rendered markdown inside an agent message. */
.msg.agent > :first-child { margin-top: 0; }
.msg.agent > :last-child { margin-bottom: 0; }
.msg.agent p { margin: 0 0 10px; }
.msg.agent h3, .msg.agent h4, .msg.agent h5, .msg.agent h6 { margin: 16px 0 8px; line-height: 1.3; }
.msg.agent ul, .msg.agent ol { margin: 0 0 10px; padding-left: 22px; }
.msg.agent li { margin: 3px 0; }
.msg.agent code { font-size: .9em; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.msg.agent hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.msg.agent a { color: var(--blue); }
.md-code { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: 12.5px; margin: 0 0 10px; }
/* A wide table scrolls inside the message rather than stretching the column. */
.md-table { overflow-x: auto; margin: 0 0 12px; border: 1px solid var(--line); border-radius: 8px; }
.md-table table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md-table th, .md-table td { text-align: left; padding: 7px 11px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.md-table th { background: var(--surface); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); }
.md-table tr:last-child td { border-bottom: none; }
.md-table code { background: transparent; border: none; padding: 0; }

/* Approval card. The turn is blocked on this, so it's the loudest thing in the
   stream — a request that reads like just another tool call gets ignored until
   it times out, which silently turns "ask a human" into "deny by default". */
.approval { border: 1px solid color-mix(in srgb, var(--warn, #d19a29) 55%, var(--line)); border-radius: 10px; padding: 14px 16px; margin: 14px 0; background: color-mix(in srgb, var(--warn, #d19a29) 8%, transparent); }
.approval .ap-head { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--warn, #d19a29); margin-bottom: 8px; }
.approval .ap-intent { font-size: 15px; line-height: 1.45; }
.approval .ap-detail { margin-top: 10px; }
.approval .ap-detail summary { font-size: 12px; color: var(--dim); cursor: pointer; }
.approval .ap-detail pre { margin-top: 8px; font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; }
.approval .ap-actions { display: flex; gap: 10px; margin-top: 14px; }
.approval .ap-yes { background: var(--warn, #d19a29); color: #1a1206; border: none; border-radius: 7px; padding: 8px 18px; font-weight: 600; cursor: pointer; }
.approval .ap-yes:disabled, .approval .ap-no:disabled { opacity: .5; cursor: default; }
.approval .ap-note:not(:empty) { margin-top: 10px; font-size: 13px; color: var(--dim); }
.approval.approved { border-color: color-mix(in srgb, var(--ok, #3fa66a) 50%, var(--line)); background: transparent; }
.approval.rejected, .approval.expired { border-color: var(--line); background: transparent; opacity: .75; }

#model-select { background: transparent; border: none; color: inherit; font: inherit; font-size: 12px; cursor: pointer; outline: none; padding: 0 2px; }
#model-select option { background: var(--bg); color: var(--text); }

.status.reconnecting { color: var(--warn, #d19a29); border-color: color-mix(in srgb, var(--warn, #d19a29) 45%, var(--line)); }
.status.reconnecting::before { content: "◌"; margin-right: 6px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* Hero (empty) state */
#hero { flex: 1; display: grid; place-items: center; padding: 24px; }
.hero-inner { width: min(720px, 92%); text-align: center; }
.hero-inner h1 { font-size: clamp(34px, 5vw, 58px); font-weight: 640; letter-spacing: -.02em; margin: 0 0 28px; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; margin-top: 18px; }
.chip { background: var(--surface); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 9px 15px; font: inherit; font-size: 13.5px; cursor: pointer; transition: .12s; }
.chip:hover { border-color: var(--line-2); background: var(--surface-2); }
.chip.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }

#app.active #hero { display: none; }
#app:not(.active) #stream { display: none; }
#app:not(.active) #dock { display: none; }

/* Stream (active) state */
.stream { flex: 1; overflow-y: auto; padding: 64px 24px 20px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.msg { max-width: 760px; width: fit-content; }
.msg.user { align-self: flex-end; background: var(--surface-2); border: 1px solid var(--line-2); padding: 11px 15px; border-radius: 16px 16px 5px 16px; }
.msg.agent { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); padding: 13px 17px; border-radius: 16px 16px 16px 5px; white-space: pre-wrap; line-height: 1.6; }
.reasoning { align-self: flex-start; color: var(--dim); font-size: 13px; max-width: 760px; padding-left: 6px; border-left: 2px solid var(--line-2); }
.tool { align-self: flex-start; max-width: 760px; width: 100%; }
.tool details { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.tool summary { list-style: none; cursor: pointer; padding: 10px 13px; display: flex; align-items: center; gap: 9px; font-size: 13px; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: "▸"; color: var(--dim-2); transition: .15s; }
.tool details[open] summary::before { transform: rotate(90deg); }
.tool .tname { font-family: ui-monospace, "SF Mono", Menlo, monospace; color: var(--blue); }
.tool .tstatus { margin-left: auto; font-size: 11px; color: var(--dim); }
.tool .tstatus.err { color: var(--err); }
.tool pre { margin: 0; padding: 11px 13px; border-top: 1px solid var(--line); background: #0d0d11; font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: #c9c9d4; overflow-x: auto; max-height: 340px; }
.turnbar { align-self: center; font-size: 11px; color: var(--dim); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 13px; }
.failbar { align-self: center; color: var(--err); background: color-mix(in srgb, var(--err) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--err) 35%, var(--line)); border-radius: 11px; padding: 9px 15px; font-size: 13px; max-width: 760px; }

/* Composer (shared between hero slot and dock) */
.composer { background: var(--surface); border: 1px solid var(--line-2); border-radius: 18px; padding: 12px 14px 10px; box-shadow: 0 12px 40px -20px rgba(0,0,0,.8); }
#hero-composer-slot .composer { margin-top: 6px; }
#dock { padding: 14px 24px 20px; }
#dock .composer { max-width: 760px; margin: 0 auto; }
.composer textarea { width: 100%; resize: none; background: transparent; border: none; color: var(--text); font: inherit; font-size: 15px; max-height: 200px; padding: 2px 4px 6px; }
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--dim-2); }
.composer-bar { display: flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--dim); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; }
.pill .p-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); }
.send { width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--text); color: var(--bg); display: grid; place-items: center; cursor: pointer; transition: .12s; }
.send:hover { transform: translateY(-1px); }
.send svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* Right drawer */
.drawer { background: var(--sidebar); border-left: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column; }
#app:not(.drawer-open) .drawer { display: none; }
.drawer-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.drawer-head span { flex: 1; }
.drawer-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.k { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.k > span { color: var(--dim); font-size: 13px; flex: none; }
.k b { font-variant-numeric: tabular-nums; font-size: 12.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.k b.on { color: var(--ok); display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; }
.k b.on::before { content: "●"; }
.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-row .t { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; }
.muted { color: var(--dim); font-size: 13px; }

/* Memories view */
#memories-view { flex: 1; overflow-y: auto; padding: 60px 32px 32px; display: none; flex-direction: column; gap: 20px; }
#app.view-memories #hero, #app.view-memories #stream, #app.view-memories #dock { display: none !important; }
#app.view-memories #memories-view { display: flex; }
.mv-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.mv-head h2 { margin: 0 0 2px; font-size: 26px; letter-spacing: -.01em; }
.mv-actions { display: flex; align-items: center; gap: 12px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg-btn { background: transparent; border: none; color: var(--dim); padding: 6px 13px; border-radius: 7px; font: inherit; font-size: 13px; cursor: pointer; }
.seg-btn.active { background: var(--surface-2); color: var(--text); }
.mem-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.mem-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 15px 16px; display: flex; flex-direction: column; gap: 10px; }
.mem-card .mc-top { display: flex; align-items: center; gap: 8px; }
.mem-card .cat { font-size: 11px; color: var(--dim); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; }
.mem-card .src { font-size: 11px; color: var(--dim-2); }
.mem-card .src.agent { color: var(--blue); }
.mem-card .imp { margin-left: auto; display: inline-flex; gap: 3px; }
.mem-card .imp i { width: 6px; height: 6px; border-radius: 50%; background: var(--line-2); }
.mem-card .imp i.on { background: var(--accent); }
.mem-card .mc-title { font-size: 15px; font-weight: 600; line-height: 1.35; }
/* Bodies can be long — cap the card and let the note scroll inside it. */
.mem-card .mc-body { font-size: 13.5px; line-height: 1.5; color: var(--dim); white-space: pre-wrap; max-height: 160px; overflow-y: auto; }
.mem-card .mc-when { font-size: 12px; color: var(--dim); }
.mem-card .mc-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.mem-card .mc-tags span { font-size: 11px; color: var(--dim); background: var(--surface-2); border-radius: 999px; padding: 2px 8px; }
.mem-card .mc-actions { display: flex; gap: 8px; margin-top: 2px; }

/* Provenance — who wrote this note and how much to trust it */
.mem-card .mc-prov { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 11px; color: var(--dim-2); }
.trust { font-size: 11px; border-radius: 999px; padding: 2px 9px; border: 1px solid var(--line); white-space: nowrap; }
.trust.t-trusted { color: #4ade80; border-color: rgba(74, 222, 128, .35); background: rgba(74, 222, 128, .08); }
.trust.t-derived { color: var(--dim); }
.trust.t-untrusted { color: #fbbf24; border-color: rgba(251, 191, 36, .4); background: rgba(251, 191, 36, .1); }
.mem-card .rev { margin-left: auto; font-size: 11px; color: var(--dim-2); }

/* Stats strip — a sense of what the agent knows, at a glance */
.mem-stats { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; padding: 2px 2px 4px; }
.mem-stats .stat { display: flex; align-items: baseline; gap: 6px; }
.mem-stats .stat b { font-size: 19px; font-weight: 600; }
.mem-stats .stat span { font-size: 12px; color: var(--dim); }
.mem-stats .stat.warn b { color: #fbbf24; }
.mem-stats .stat-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.tag-chip { background: var(--surface); border: 1px solid var(--line); color: var(--dim); border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 11px; cursor: pointer; }
.tag-chip:hover { color: var(--text); border-color: var(--line-2); }
.tag-chip i { font-style: normal; color: var(--dim-2); }

/* Journal — the activity feed */
.journal-pane { display: none; flex-direction: column; gap: 22px; }
#app.journal-mode .journal-pane { display: flex; }
#app.journal-mode .mem-list, #app.journal-mode .mem-stats { display: none; }
.j-day h3 { font-size: 12px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 10px; }
.j-row { display: flex; gap: 12px; padding: 10px 12px; border-left: 2px solid var(--line); }
.j-row:hover { background: var(--surface); border-left-color: var(--line-2); }
.j-row.notable { border-left-color: #fbbf24; background: rgba(251, 191, 36, .05); }
.j-icon { width: 20px; text-align: center; color: var(--dim); flex: none; }
.j-main { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.j-line { font-size: 14px; }
.j-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--dim-2); }
.j-warn { font-size: 12px; color: #fbbf24; }
.j-link { background: none; border: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; }
.j-link:hover { text-decoration: underline; }
/* A journal row with a title but no note to open — a search, a spend record, a
   store write. Reads as part of the sentence rather than as a dead control. */
.j-plain { color: var(--text); }

/* Review — curation candidates */
.review-pane { display: none; flex-direction: column; gap: 28px; }
#app.review-mode .review-pane { display: flex; }
#app.review-mode .mem-list, #app.review-mode .mem-stats { display: none; }
.rv-section h3 { font-size: 13px; font-weight: 600; margin: 0 0 4px; }
.rv-section > .muted { font-size: 12px; margin: 0 0 12px; }
.rv-cluster { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface); }
.rv-sim { font-size: 11px; color: var(--accent); margin-bottom: 8px; }
.rv-note { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 4px 0; font-size: 13px; }
.rv-note .muted { font-size: 12px; }
.rv-meta { margin-left: auto; font-size: 11px; color: var(--dim-2); }
.rv-note.stale { flex-direction: column; align-items: stretch; gap: 7px; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; background: var(--surface); }
.rv-head { display: flex; align-items: center; gap: 10px; }
.rv-score { margin-left: auto; font-size: 11px; color: var(--dim-2); font-variant-numeric: tabular-nums; }
.rv-reasons { display: flex; flex-wrap: wrap; gap: 6px; }
.rv-reasons span { font-size: 11px; color: var(--dim); background: var(--surface-2); border-radius: 999px; padding: 2px 9px; }
.rv-actions { display: flex; gap: 8px; }

/* Search box in the memory header */
.mem-search { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font: inherit; font-size: 13px; padding: 7px 12px; min-width: 180px; }
.mem-search:focus { outline: none; border-color: var(--line-2); }

/* Soul editor — hidden unless the Soul segment is active */
.soul-pane { display: none; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }
/* Scoped to the id, not the class: #goals-pane also carries .soul-pane, so the
   class form matched both and rendered the Goals editor underneath the Soul
   editor whenever the Soul tab was selected. */
#app.soul-mode #soul-pane { display: flex; }
#app.soul-mode .mem-list { display: none; }
.soul-text {
  flex: 1; min-height: 320px; resize: vertical;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  color: var(--text); padding: 16px 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; line-height: 1.65;
}
.soul-text:focus { outline: none; border-color: var(--line-2); }
.soul-actions { display: flex; align-items: center; gap: 12px; }
.soul-actions .primary { margin-left: auto; }
.mem-empty { grid-column: 1 / -1; text-align: center; color: var(--dim); padding: 60px 0; }

/* Add Memory dialog */
.mem-form { padding: 22px; width: min(560px, 94vw); display: flex; flex-direction: column; gap: 14px; }
.mem-form-head { display: flex; align-items: center; }
.mem-form-head h2 { margin: 0; flex: 1; font-size: 20px; }
.mem-form .x { background: transparent; border: none; color: var(--dim); font-size: 16px; cursor: pointer; }
.mem-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text); font-weight: 500; }
.mem-form textarea, .mem-form input, .mem-form select { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; }
.mem-form textarea { resize: vertical; }
.mem-form textarea:focus, .mem-form input:focus, .mem-form select:focus { outline: none; border-color: var(--line-2); }
.mem-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mem-form .sub { font-size: 11.5px; color: var(--dim); font-weight: 400; }
.mem-form menu { display: flex; justify-content: flex-end; gap: 10px; margin: 4px 0 0; padding: 0; }

/* buttons */
button { font: inherit; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--dim); border-radius: 9px; padding: 6px 12px; cursor: pointer; transition: .12s; }
.ghost:hover { color: var(--text); border-color: var(--line-2); }
.ghost.small { padding: 4px 9px; font-size: 12px; }
.ghost:disabled { opacity: .4; cursor: not-allowed; }
.primary { background: var(--text); color: var(--bg); border: none; border-radius: 9px; padding: 8px 15px; font-weight: 600; cursor: pointer; }

/* settings dialog */
dialog { border: 1px solid var(--line-2); background: var(--surface); color: var(--text); border-radius: 16px; padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.settings-form { padding: 22px; width: min(430px, 92vw); display: flex; flex-direction: column; gap: 15px; }
.settings-form h2 { margin: 0; font-size: 19px; }
.settings-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--dim); }
.settings-form input { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 11px 13px; font: inherit; }
.settings-form input:focus { outline: none; border-color: var(--line-2); }
.settings-form .note { font-size: 12.5px; color: var(--dim); margin: 0; }
.settings-form menu { display: flex; justify-content: flex-end; gap: 10px; margin: 0; padding: 0; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }
[data-tip] { position: relative; }

/* The menu button only exists on a phone; on a wide screen the sidebar is
   always there and a button to reveal it would be a button that does nothing. */
#nav-toggle { display: none; }
#scrim { display: none; }

/* ---------- phones ----------
   The sidebar and the drawer used to be `display: none` here, and the sidebar
   is the only way to reach Skills, Memory, Files, Connections and Settings —
   so on a phone the whole right-hand half of the product was unreachable, and
   the Connections panel could not be opened at all. They become overlays
   instead: same markup, same JavaScript, laid over the conversation rather
   than beside it. */
@media (max-width: 820px) {
  #app, #app.drawer-open { grid-template-columns: 1fr; }

  #nav-toggle { display: inline-flex; align-items: center; }

  /* `visibility` as well as `transform`: an off-screen sidebar that is merely
     translated is still in the tab order and still read by a screen reader, so
     a phone user would tab into a menu they cannot see. */
  #sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px); z-index: 40;
    transform: translateX(-100%); visibility: hidden;
    transition: transform .2s ease, visibility .2s;
    overflow-y: auto;
  }
  #app.nav-open #sidebar { transform: translateX(0); visibility: visible; }

  /* Full width, because a 320px panel on a 390px screen is neither one thing
     nor the other — and the connection rows need the room. */
  .drawer {
    position: fixed; inset: 0; width: 100%; z-index: 40;
    border-left: none;
  }

  #scrim { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(0,0,0,.5); }

  /* Comfortable thumb targets, and room for a connector's buttons to sit on
     their own line without crowding. */
  .side-item { padding: 11px 10px; }
  .drawer-body { padding: 14px; gap: 12px; }
  .conn-buttons button, .conn-actions button { padding: 8px 14px; }
  /* The gap is larger here, so the pull-up has to be too. */
  .conn-buttons { margin-top: -6px; }
}

/* Skills panel — written guidance, distinct from raw tools */
.guide { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--surface); }
.guide b { font-size: 13px; }
.guide span { font-size: 12px; color: var(--dim); line-height: 1.45; }

/* ---------- Skills view ---------- */
#skills-view { flex: 1; overflow-y: auto; padding: 60px 32px 32px; display: none; flex-direction: column; gap: 16px; }
#app.view-skills #hero, #app.view-skills #stream, #app.view-skills #dock, #app.view-skills #memories-view { display: none !important; }
#app.view-skills #skills-view { display: flex; }

#goals-pane { display: none; }
#app.goals-mode #mem-list, #app.goals-mode #journal-pane, #app.goals-mode #review-pane,
#app.goals-mode #soul-pane { display: none; }
#app.goals-mode #goals-pane { display: block; }
.soul-tpl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; }

/* Files: the project folder. */
#files-view { display: none; flex-direction: column; gap: 14px; padding: 26px 30px; overflow-y: auto; }
#app.view-files #hero, #app.view-files #stream, #app.view-files #dock, #app.view-files #memories-view,
#app.view-files #skills-view, #app.view-files #threads-view { display: none !important; }
#app.view-files #files-view { display: flex; }
#file-list { display: flex; flex-direction: column; gap: 8px; }
.file-row { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 9px; padding: 10px 14px; background: var(--surface); }
.file-row .f-path { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .f-meta { font-size: 12px; color: var(--dim); white-space: nowrap; }
.file-preview { margin: 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; max-height: 60vh; overflow: auto; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }

/* Threads: the list that makes "New thread" non-destructive. */
#threads-view { display: none; flex-direction: column; gap: 14px; padding: 26px 30px; overflow-y: auto; }
#app.view-threads #hero, #app.view-threads #stream, #app.view-threads #dock,
#app.view-threads #memories-view, #app.view-threads #skills-view { display: none !important; }
#app.view-threads #threads-view { display: flex; }
#thread-list { display: flex; flex-direction: column; gap: 10px; }
.thread-card { border: 1px solid var(--line); border-radius: 10px; padding: 13px 15px; background: var(--surface); }
.thread-card.current { border-color: color-mix(in srgb, var(--blue) 50%, var(--line)); }
.thread-card .tc-top { display: flex; align-items: center; gap: 9px; }
.thread-card .tc-title { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-card .tc-live { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--blue); border: 1px solid color-mix(in srgb, var(--blue) 40%, var(--line)); border-radius: 999px; padding: 1px 7px; }
.thread-card .tc-meta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 5px; font-size: 12px; color: var(--dim); }
.skills-intro { font-size: 13px; max-width: 760px; margin: 0; }
.skill-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.skill-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 15px 16px; display: flex; flex-direction: column; gap: 9px; }
.sk-top { display: flex; align-items: center; gap: 9px; }
.sk-top b { font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.sk-src { font-size: 11px; border-radius: 999px; padding: 2px 9px; border: 1px solid var(--line); color: var(--dim); }
.sk-src.u { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.sk-size { margin-left: auto; font-size: 11px; color: var(--dim-2); }
.sk-desc { font-size: 13px; color: var(--dim); line-height: 1.5; }
.sk-loc { grid-column: 1 / -1; font-size: 12px; }
.sk-reader { display: flex; flex-direction: column; gap: 12px; max-width: 820px; }
.sk-reader h3 { margin: 0; font-size: 18px; }
.sk-body { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; white-space: pre-wrap; font-size: 13px; line-height: 1.6; color: var(--text); max-height: 60vh; overflow-y: auto; }
.skill-form { max-width: 680px; }
.sk-mode { align-self: flex-start; margin-bottom: 4px; }

/* --- context meter -----------------------------------------------------------
   Sits in the composer bar because that is where you decide whether to keep
   going in this thread or start a new one, which is the only decision the
   number informs. */
.composer-bar { position: relative; }
.ctx { cursor: pointer; font-variant-numeric: tabular-nums; }
.ctx:hover { color: var(--text); border-color: var(--line-2); }
.ctx-track { width: 46px; height: 5px; border-radius: 999px; background: var(--line-2); overflow: hidden; }
.ctx-fill { display: block; height: 100%; width: 0%; border-radius: 999px; background: var(--blue); transition: width .3s ease, background .3s ease; }
/* Amber, then red — the thread is worth splitting well before it is truncated. */
.ctx-fill.warn { background: var(--accent); }
.ctx-fill.hot { background: var(--err); }

.ctx-pop {
  position: absolute; bottom: calc(100% + 10px); left: 0; z-index: 40;
  width: 320px; max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 14px;
  padding: 12px 13px; box-shadow: 0 18px 50px -18px rgba(0,0,0,.9); font-size: 12.5px;
}
.ctx-pop h4 { margin: 0 0 2px; font-size: 12.5px; color: var(--text); }
.ctx-pop .ctx-sub { color: var(--dim-2); font-size: 11.5px; margin-bottom: 9px; }
.ctx-row { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; color: var(--dim); }
.ctx-row .n { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text); }
.ctx-row.sum { border-top: 1px solid var(--line); margin-top: 7px; padding-top: 7px; color: var(--text); }
.ctx-row.free { color: var(--dim-2); }
.ctx-note { margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--dim-2); font-size: 11.5px; line-height: 1.45; }


/* --- guided setup ------------------------------------------------------------
   A blank page in a settings tab is a task nobody does, and a default soul is a
   generic assistant. The banner is derived from the soul text on every load, so
   answering three questions and stopping brings it back naming the other three —
   a "setup done" flag would let a half-finished soul look finished forever. */
.setup-banner {
  display: flex; align-items: center; gap: 12px; margin: 10px 0 0;
  background: linear-gradient(90deg, rgba(245,158,11,.10), rgba(245,158,11,.03));
  border: 1px solid rgba(245,158,11,.35); border-radius: 12px; padding: 10px 12px; font-size: 13px;
}
.setup-banner .sb-text { flex: 1; color: var(--text); }
.setup-banner .sb-text small { display: block; color: var(--dim); font-size: 12px; margin-top: 2px; }
.setup-banner button { font: inherit; font-size: 12.5px; border-radius: 8px; padding: 6px 11px; cursor: pointer; }
.setup-banner .sb-go { background: var(--accent); border: none; color: #1a1200; font-weight: 600; }
.setup-banner .sb-later { background: transparent; border: 1px solid var(--line-2); color: var(--dim); }

#setup { border: none; background: transparent; padding: 0; max-width: 620px; width: 92vw; }
#setup::backdrop { background: rgba(0,0,0,.6); }
.setup-card { background: var(--surface); border: 1px solid var(--line-2); border-radius: 18px; padding: 22px 24px; }
.setup-step { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim-2); }
.setup-card h2 { margin: 6px 0 6px; font-size: 19px; }
.setup-help { color: var(--dim); font-size: 13px; line-height: 1.5; margin: 0 0 10px; }
.setup-example { color: var(--dim-2); font-size: 12.5px; line-height: 1.5; background: var(--bg); border-left: 2px solid var(--line-2); padding: 8px 10px; border-radius: 0 8px 8px 0; margin: 0 0 12px; }
.setup-card textarea {
  width: 100%; min-height: 96px; resize: vertical; background: var(--bg); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 14px;
}
.setup-card textarea:focus { outline: none; border-color: var(--accent); }
.setup-count { text-align: right; font-size: 11.5px; color: var(--dim-2); margin-top: 4px; font-variant-numeric: tabular-nums; }
.setup-count.over { color: var(--err); }
.setup-actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.setup-actions .spacer { flex: 1; }
.setup-actions button { font: inherit; font-size: 13px; border-radius: 9px; padding: 8px 14px; cursor: pointer; }
.setup-actions .primary { background: var(--accent); border: none; color: #1a1200; font-weight: 600; }
.setup-actions .ghost { background: transparent; border: 1px solid var(--line-2); color: var(--dim); }
.setup-done { font-size: 13.5px; line-height: 1.6; color: var(--text); }
.setup-done .missing { color: var(--accent); }

/* --- goals as a checklist -----------------------------------------------------
   GOALS.md stays plain markdown — it is injected into the prompt in full and is
   meant to be hand-editable — so this view round-trips the file rather than
   owning it. The markdown editor stays, one disclosure away. */
.goals-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.goal { display: flex; gap: 11px; align-items: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; }
.goal.done { opacity: .55; }
.goal.done .g-text { text-decoration: line-through; }
.goal.overdue { border-color: rgba(248,113,113,.45); }
.goal input[type="checkbox"] { margin-top: 2px; width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex: none; }
.goal .g-main { flex: 1; min-width: 0; }
.goal .g-text { font-size: 14px; color: var(--text); }
.goal .g-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; font-size: 12px; color: var(--dim); }
.goal .g-by { font-variant-numeric: tabular-nums; }
.goal .g-by.late { color: var(--err); }
.goal .g-by.soon { color: var(--accent); }
.goal .g-del { background: none; border: none; color: var(--dim-2); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 4px; }
.goal .g-del:hover { color: var(--err); }
.goals-add { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 8px; align-items: center; }
.goal-input, .goal-date {
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 9px; color: var(--text);
  font: inherit; font-size: 13px; padding: 8px 10px; min-width: 0;
}
.goal-input:focus, .goal-date:focus { outline: none; border-color: var(--accent); }
.goals-add .primary { font: inherit; font-size: 13px; border-radius: 9px; padding: 8px 14px; background: var(--accent); border: none; color: #1a1200; font-weight: 600; cursor: pointer; }
#goals-raw-wrap { margin-top: 16px; }
#goals-raw-wrap summary { cursor: pointer; font-size: 12.5px; padding: 4px 0; }
#goals-raw-wrap .soul-text { margin-top: 10px; }

/* Two nudges, two meanings, two colours. Amber is "you still owe me something";
   blue is "here's the next thing"; green is "that worked". Finishing the soul
   used to hand back an identical amber box, which read as failure. */
.setup-banner.info {
  background: linear-gradient(90deg, rgba(91,140,255,.10), rgba(91,140,255,.03));
  border-color: rgba(91,140,255,.35);
}
.setup-banner.info .sb-go { background: var(--blue); color: #05102b; }
.setup-banner.ok {
  background: linear-gradient(90deg, rgba(52,211,153,.10), rgba(52,211,153,.03));
  border-color: rgba(52,211,153,.35);
}

/* ---------- connections panel ---------- */
/* The panel became interactive when credentials went per tenant: connecting is
   something a user does for their own account, not something the operator does
   in the server's environment. */
/* The status text has to give way to the buttons, not the other way round: a
   truncated credit count is readable, a Disconnect button pushed off the edge
   of the drawer is unreachable. Found by driving the panel, not by reading it. */
/* Pulled up against the card it belongs to. `.drawer-body` is a flex column
   with a gap, so without the negative margin the buttons float midway between
   their own connector and the next one, and "Connect" reads as belonging to
   whichever card you happened to look at first. */
.conn-buttons { display: flex; gap: 6px; justify-content: flex-end; margin: -4px 0 2px; flex-wrap: wrap; }
.conn-form { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 8px 0; background: var(--surface); }
.conn-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.conn-field > span { color: var(--dim); font-size: 12px; }
.conn-field input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 13px; width: 100%;
}
.conn-field input:focus { outline: none; border-color: var(--line-2); }
.conn-actions { display: flex; gap: 8px; margin-top: 4px; }
.conn-msg { font-size: 12.5px; margin: 6px 0 12px; }
.conn-msg.ok { color: var(--ok); }
.conn-msg.bad { color: var(--err); }
.muted.small { font-size: 12px; }
.ghost.danger:hover { color: var(--err); border-color: var(--err); }

/* ---------- sign in ---------- */
.signin-sep { display: flex; align-items: center; gap: 10px; color: var(--dim-2); font-size: 12px; margin: 14px 0 10px; }
.signin-sep::before, .signin-sep::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.signin-btn { display: inline-flex; align-items: center; justify-content: center; gap: 9px; width: 100%; padding: 9px 12px; color: var(--text); font-size: 13.5px; }
.signin-btn svg { flex: none; }
#signed-in-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
#signed-in-row .note { margin: 0; }
