:root {
  --brand: #6A47E8; --brand-2: #5FD6BA;
  --bg: #f7f6fc; --panel: #ffffff; --ink: #1d1a2e; --muted: #6b6784; --line: #e3e0f0; --soft: #efecfb;
  --accent: #6A47E8; --ok: #1d8a4e; --bad: #c23a3a; --warn: #b7791f;
  --add: #e6f6ec; --del: #fbeaea; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121020; --panel: #1b1830; --ink: #ecebf5; --muted: #a29fbd; --line: #2e2a48; --soft: #252040;
    --accent: #9a82ff; --ok: #4cc38a; --bad: #ff7b7b; --warn: #e3b341; --add: #16301f; --del: #3a1c1c; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, Segoe UI, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--accent); }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button.ghost { background: none; color: var(--ink); border: 1px solid var(--line); }
button.bad { background: var(--bad); } button.ok { background: var(--ok); }
button.link { background: none; color: var(--accent); padding: 0; }
button.icon { padding: 4px 8px; position: relative; }
#bell-n { position: absolute; top: -4px; right: -4px; background: var(--bad); color: #fff; border-radius: 999px; font-size: 10px; padding: 0 5px; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
header { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 8px 16px; background: var(--panel);
  border-top: 3px solid var(--brand); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 3; }
.spacer { flex: 1; }
#search { flex: 1 1 260px; max-width: 460px; } #search input { width: 100%; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand img { height: 28px; width: auto; display: block; }
.brand .product { display: flex; flex-direction: column; line-height: 1.1; border-left: 2px solid var(--brand-2); padding-left: 10px; }
.brand .product b { color: var(--accent); font-size: 16px; letter-spacing: .02em; }
.brand .product small { color: var(--muted); font-size: 11px; }
@media (prefers-color-scheme: dark) { .brand img, .login-brand img { background: #fff; border-radius: 6px; padding: 3px 6px; } }
.layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); min-height: calc(100vh - 52px); }
.layout:has(> #nav:empty) { grid-template-columns: minmax(0, 1fr); }
nav#nav:empty { display: none; }
#shell > header > * { min-width: 0; max-width: 100%; }
#shell .brand { flex-shrink: 0; }
#project { max-width: 20rem; }
.account-menu { display: flex; align-items: center; gap: 12px; margin-left: auto; flex-shrink: 0; }
.account-menu #me { max-width: 20ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu button { flex-shrink: 0; white-space: nowrap; }
@media (max-width: 1100px) {
  #orgnav { order: 3; flex: 1 0 100%; }
  #search { order: 4; flex: 1 0 100%; max-width: none; }
  #project { flex: 1 1 160px; }
}
@media (max-width: 480px) {
  #shell > header { gap: 8px; padding: 8px 12px; }
  #shell .brand img { height: 24px; }
  #shell .brand .product { padding-left: 6px; }
  .account-menu { gap: 8px; }
  .account-menu #me { max-width: 12ch; }
  #project { order: 2; flex-basis: 100%; max-width: none; }
}
nav#nav { border-right: 1px solid var(--line); background: var(--panel); padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
nav#nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
nav#nav a.active { background: var(--soft); color: var(--accent); font-weight: 600; }
nav#nav a.locked { color: var(--muted); }
nav#nav .sep { height: 1px; background: var(--line); margin: 6px 4px; }
main { padding: 16px; min-width: 0; }
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  nav#nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  nav#nav .sep { display: none; }
  .brand .product small { display: none; }
}
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: min(420px, 100%); }
.login-card form:not(.inline) { display: grid; gap: 10px; margin-top: 12px; }
.login-card label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.login-brand { text-align: center; }
.login-brand img { height: 48px; width: auto; }
.login-brand h1 { margin: 10px 0 0; font-size: 20px; color: var(--accent); }
.login-brand h1 span { color: var(--muted); font-weight: 400; }
h2 { margin: 0 0 12px; font-size: 18px; }
h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.tile .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 12px; }
.tile.alert .n { color: var(--bad); }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.split { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .cols, .split { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; cursor: pointer; }
.list li.sel { border-color: var(--accent); }
.feed { list-style: none; margin: 0; padding: 0; max-height: 65vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.feed li { padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 13px; word-break: break-word; }
.feed .t { color: var(--muted); margin-right: 8px; font-family: var(--mono); font-size: 12px; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; display: block; overflow-x: auto; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.wrap { white-space: normal; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.pill.passed, .pill.low, .pill.deployed, .pill.done, .pill.applied, .pill.validated, .pill.active, .pill.accepted, .pill.verified { color: var(--ok); border-color: var(--ok); }
.pill.failed, .pill.error, .pill.high, .pill.critical, .pill.rejected, .pill.expired, .pill.broken { color: var(--bad); border-color: var(--bad); }
.pill.medium, .pill.pending, .pill.claimed, .pill.proposed, .pill.changes_requested, .pill.queued, .pill.review, .pill.expiring, .pill.grace { color: var(--warn); border-color: var(--warn); }
.pill.collision { color: var(--warn); border-color: var(--warn); font-weight: 600; }
.notice { border-left: 3px solid var(--warn); padding: 4px 10px; margin: 8px 0; white-space: normal; }
.muted { color: var(--muted); } .err { color: var(--bad); }
.inline { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
pre.diff, pre.code { font-family: var(--mono); font-size: 12px; margin: 0; overflow-x: auto; background: var(--bg); border-radius: 6px; padding: 8px; }
pre.diff .a { background: var(--add); display: block; } pre.diff .d { background: var(--del); display: block; } pre.diff .h { color: var(--accent); display: block; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; } dl.kv dt { color: var(--muted); }
code { font-family: var(--mono); font-size: 12px; }
.locked-view { max-width: 560px; margin: 40px auto; text-align: center; background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 24px; }
.locked-view .lock { font-size: 28px; }
.chat { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; height: calc(100vh - 110px); }
@media (max-width: 760px) { .chat { grid-template-columns: 1fr; height: auto; } }
.chat .rooms { overflow: auto; }
.chat .rooms a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.chat .rooms a.sel { background: var(--soft); color: var(--accent); font-weight: 600; }
.chat .pane { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.chat .msgs { flex: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 240px; }
.msg { max-width: 820px; }
.msg .who { font-weight: 600; } .msg .who .kind { font-weight: 400; color: var(--muted); font-size: 11px; margin-left: 4px; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg.system { color: var(--muted); font-size: 13px; border-left: 3px solid var(--brand-2); padding-left: 8px; }
.msg .mact { font-size: 12px; }
.chat form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat form textarea { min-height: 40px; }
.board { display: grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); gap: 10px; overflow-x: auto; }
.board .col { background: var(--soft); border-radius: 8px; padding: 8px; min-height: 200px; }
.board .col h3 { margin: 4px 4px 8px; }
.board .cardt { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 6px; }
.board .cardt .mv { display: flex; justify-content: space-between; margin-top: 6px; }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
#notes { position: fixed; right: 12px; top: 60px; width: min(380px, 94vw); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; z-index: 5; box-shadow: 0 8px 30px rgba(0,0,0,.15); }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 6px; max-width: 90vw; z-index: 9; }
.hits .hit { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.hits .hit .snip { color: var(--muted); font-size: 13px; word-break: break-word; margin-top: 2px; }
.hits .hit.code .snip { font-family: var(--mono); font-size: 12px; }
.hits mark { background: var(--soft); color: var(--accent); border-radius: 3px; padding: 0 1px; }
.meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.meter .bar { margin-top: 6px; }
.bar.full > span { background: var(--bad); }
/* Organization-level navigation and views (Home, People & Agents, Projects) */
#orgnav { display: flex; flex-wrap: wrap; gap: 2px; }
#orgnav a { padding: 5px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
#orgnav a.active { background: var(--soft); color: var(--accent); font-weight: 600; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.home-grid .list li { cursor: default; }
.home-grid .list li .muted { font-size: 13px; word-break: break-word; }
.home-grid .locked-view { margin: 0; padding: 16px; }
.home-grid .locked-view h2 { font-size: 15px; }
.pill.mention { color: var(--accent); border-color: var(--accent); font-weight: 600; }
tr.tier th { text-align: left; background: var(--soft); }
/* Code map (project source graph) */
.pill.subview { font-size: 12px; font-weight: 600; text-decoration: none; vertical-align: middle; margin-left: 6px; }
.pmap-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
@media (max-width: 900px) { .pmap-wrap { grid-template-columns: 1fr; } }
.pmap { position: relative; max-height: 72vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.pmap-rows { position: relative; margin-right: 200px; }
.pmap-row { position: absolute; left: 0; right: 0; height: 26px; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden;
  cursor: pointer; border-left: 3px solid transparent; font-size: 13px; }
.pmap-row:hover, .pmap-row.sel { background: var(--soft); }
.pmap-row.rel { background: color-mix(in srgb, var(--brand-2) 18%, transparent); }
.pmap-row.busy .nm { font-weight: 600; }
.pmap-row.col { border-left-color: var(--warn); }
.pmap-row .tw { width: 10px; color: var(--muted); flex: none; }
.pmap-row.file .nm { font-family: var(--mono); font-size: 12px; }
.pmap-row.file .nm:hover { text-decoration: underline; color: var(--accent); }
.pmap-row .inf { font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.pmap-row .pill { font-size: 11px; padding: 0 6px; flex: none; }
.pill.agent { color: var(--accent); border-color: var(--accent); }
.pmap-edges { position: absolute; top: 0; right: 0; pointer-events: none; overflow: visible; }
.pmap-edges path { fill: none; stroke: currentColor; opacity: .75; pointer-events: stroke; }
.pmap-edges path.out { color: var(--accent); } .pmap-edges path.in { color: var(--ok); } .pmap-edges path.all { color: var(--muted); opacity: .45; }
.pmap-side { align-self: start; font-size: 13px; word-break: break-word; }
.pmap-side h3 { margin-top: 12px; }
.pmap-edges marker path { fill: var(--muted); }

/* First-run identity setup keeps labels and one-time credentials readable. */
.identity-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px; margin-top: 12px; }
.identity-form label { display: flex; flex-direction: column; gap: 5px; }
.identity-form small { color: var(--muted); }
.identity-form button { align-self: end; justify-self: start; }
.identity-token { display: block; overflow-wrap: anywhere; margin-bottom: 12px; }
@media (max-width: 480px) { .home-grid { grid-template-columns: minmax(0, 1fr); } }
