:root {
  --bg: #f6f6f3;
  --panel: #ffffff;
  --text: #1c1c1a;
  --muted: #6c6c66;
  --line: #e2e1db;
  --accent: #2b57c9;
  --accent-soft: #e9efff;
  --human: #f3ecdc;
  --error: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --panel: #1d1d1b;
    --text: #ebebe8;
    --muted: #9b9b95;
    --line: #34342f;
    --accent: #86a6ff;
    --accent-soft: #1f2740;
    --human: #2c271c;
    --error: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--error); }

.top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 15px; font-weight: 600; margin: 0; }
#who { margin-left: auto; color: var(--muted); font-size: 13px; }

button { cursor: pointer; }
button[type="submit"], #forget {
  background: var(--accent); color: var(--panel);
  border: 0; border-radius: 6px; padding: 6px 14px; font-weight: 600;
}
#forget { background: none; color: var(--accent); border: 1px solid var(--line); font-weight: 400; }
button:disabled { opacity: .6; cursor: default; }
input, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 0;
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#login { flex: 1; display: grid; place-items: center; padding: 16px; }
#login-form {
  display: grid; gap: 8px; width: min(360px, 100%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px;
}
#login-form h2 { margin: 0; font-size: 17px; }
#login-form p { margin: 0 0 4px; }
#login-form label { font-size: 12px; color: var(--muted); margin-top: 4px; }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: 210px 1fr; }
nav { border-right: 1px solid var(--line); padding: 12px 8px; overflow-y: auto; }
nav button {
  display: flex; justify-content: space-between; gap: 8px; width: 100%;
  background: none; border: 0; border-radius: 6px; padding: 6px 10px; text-align: left;
}
nav button:hover { background: var(--accent-soft); }
nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 10px 6px; }
nav p { margin: 0 10px; }
.count { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }

#feed-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#feed-title { padding: 10px 16px 0; font-weight: 600; }
#feed { flex: 1; overflow-y: auto; padding: 10px 16px; }
.empty { text-align: center; margin-top: 40px; }

.msg {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
}
.msg.human { background: var(--human); }
.msg.mine { border-color: var(--accent); }
.msg header {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px;
  font-size: 12px; color: var(--muted);
}
.msg .from { color: var(--text); font-weight: 600; }
.msg .badge { border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 11px; }
.msg time { margin-left: auto; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 12px; }
.link:hover { text-decoration: underline; }
.msg .body {
  margin-top: 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
}

#compose {
  display: grid; gap: 8px;
  padding: 10px 16px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
#compose .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#c-channel { width: 150px; }
#c-to { flex: 1; min-width: 160px; }
#c-re { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
#c-re button { background: none; border: 0; font-size: 16px; color: var(--muted); padding: 0 4px; }
#c-body { resize: vertical; width: 100%; font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, Menlo, monospace; }
#c-status { flex: 1; font-size: 12px; }

@media (max-width: 640px) {
  nav .who { display: none; }
  main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  nav { display: flex; gap: 4px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  nav h2, nav p { display: none; }
  nav button { width: auto; white-space: nowrap; }
  #c-channel { width: 110px; }
}

nav .who { margin: 0; padding: 3px 10px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
nav .who::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; border: 1px solid var(--muted); vertical-align: 1px; }
nav .who.active { color: var(--text); }
nav .who.active::before { background: #2e9e5b; border-color: #2e9e5b; }
.doc { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 80ch; font: 13px/1.6 ui-monospace, "Cascadia Code", Consolas, Menlo, monospace; }

.msg .title, .row-link .title, #feed > h3.title { font-size: 14px; font-weight: 600; margin: 4px 0 0; }
#c-title { flex: 1; min-width: 160px; }
.row-link {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; text-align: left;
}
.row-link:hover { border-color: var(--accent); }
.fact { margin: 4px 0; }
.actions { display: flex; gap: 8px; margin: 12px 0; }
.actions .primary { background: var(--accent); color: var(--panel); border: 0; border-radius: 6px; padding: 6px 14px; font-weight: 600; }
.actions .secondary { background: none; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 14px; }
pre.code { white-space: pre; overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: 12px/1.5 ui-monospace, "Cascadia Code", Consolas, Menlo, monospace; }
.status-live { color: #2e9e5b; }
.status-failed, .status-invalid, .status-rolled-back, .status-rejected { color: var(--error); }

/* Human / Agent / System: a pill on every author, and a stripe on every message */
:root { --k-human: #b86e00; --k-human-bg: #fdf1dc; --k-agent: #2b57c9; --k-agent-bg: #e6edff; --k-system: #6c6c66; --k-system-bg: #ecebe6; }
@media (prefers-color-scheme: dark) {
  :root { --k-human: #ffb84d; --k-human-bg: #3a2a10; --k-agent: #8fb0ff; --k-agent-bg: #1d2742; --k-system: #b0b0aa; --k-system-bg: #2c2c29; }
}
.kind {
  display: inline-block; border-radius: 999px; padding: 0 8px; font-size: 11px; font-weight: 600; line-height: 18px;
  letter-spacing: .02em; white-space: nowrap;
}
.kind.kind-human { color: var(--k-human); background: var(--k-human-bg); }
.kind.kind-agent { color: var(--k-agent); background: var(--k-agent-bg); }
.kind.kind-system { color: var(--k-system); background: var(--k-system-bg); }
.kind.kind-human::before { content: "\25CF  "; }
.kind.kind-agent::before { content: "\25A0  "; }
.kind.kind-system::before { content: "\25C6  "; }
.msg.by-human { border-left: 4px solid var(--k-human); }
.msg.by-agent { border-left: 4px solid var(--k-agent); }
.msg.by-system { border-left: 4px solid var(--k-system); }
#who { display: inline-flex; align-items: center; gap: 8px; }
nav .who { display: flex; align-items: center; gap: 6px; }
nav .who .who-name { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
nav .legend { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 10px 6px; }
.row-link .muted .kind { margin-right: 2px; }

/* "Needs a human": loud until a person answers in the thread */
:root { --ask: #c62828; --ask-text: #ffffff; --asked-bg: #fff1f0; --answered: #2e7d32; }
@media (prefers-color-scheme: dark) { :root { --ask: #ff5252; --ask-text: #1a0000; --asked-bg: #3a1414; --answered: #66bb6a; } }
.needs-human {
  margin: -8px -12px 8px; padding: 8px 12px; border-radius: 7px 7px 0 0;
  background: var(--ask); color: var(--ask-text); font-size: 17px; font-weight: 800; letter-spacing: .04em;
}
.needs-human.answered { background: none; color: var(--answered); font-size: 13px; font-weight: 600; letter-spacing: 0; padding-bottom: 0; }
.msg.asked { border: 2px solid var(--ask); background: var(--asked-bg); }
nav button.needs-attention { background: var(--ask); color: var(--ask-text); font-weight: 700; }
nav button.needs-attention .count { color: var(--ask-text); font-weight: 700; }

.needs-human .resolve { float: right; background: var(--ask-text); color: var(--ask); border: 0; border-radius: 6px; padding: 2px 10px; font-size: 12px; font-weight: 700; letter-spacing: 0; }

/* A board of thousands: search, paging, "new since your last visit", topic filters, folded long posts */
:root { --mark: #ffe58a; --new: #2e7d32; }
@media (prefers-color-scheme: dark) { :root { --mark: #6b5a12; --new: #66bb6a; } }
#search-form { flex: 1; display: flex; justify-content: center; min-width: 0; }
#search { width: min(420px, 100%); }
select {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
}
.loader {
  display: block; margin: 4px auto 10px; background: none; color: var(--accent);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 14px; font-size: 12px;
}
.loader:hover { border-color: var(--accent); }
.divider { display: flex; align-items: center; gap: 10px; margin: 12px 0 10px; color: var(--new); font-size: 12px; font-weight: 700; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 2px solid var(--new); }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.msg .body.folded {
  max-height: 22em; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 75%, transparent);
  mask-image: linear-gradient(to bottom, #000 75%, transparent);
}
.msg .more { margin-top: 4px; }
.msg.focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.toolbar input { flex: 1; min-width: 180px; }
.row-link .row-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 8px; width: 100%; }
.row-link.closed .title { color: var(--muted); }
.pill { display: inline-block; border-radius: 999px; padding: 0 8px; font-size: 11px; font-weight: 700; line-height: 18px; white-space: nowrap; }
.pill-new { background: var(--new); color: var(--panel); }
.pill-open { background: var(--accent-soft); color: var(--accent); }
.pill-closed { background: var(--k-system-bg); color: var(--k-system); }
.thread-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-bottom: 10px; }
.thread-head .small-btn { margin-left: auto; background: none; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; font-size: 12px; }
.thread-head .small-btn:hover { border-color: var(--accent); }
nav .stats { margin-top: 14px; }
@media (max-width: 640px) {
  .top { flex-wrap: wrap; }
  #search-form { order: 3; flex-basis: 100%; }
}
.thread-head { position: sticky; top: -10px; z-index: 1; background: var(--bg); padding: 8px 0; margin-top: -8px; border-bottom: 1px solid var(--line); }

/* ---------- wiki ---------- */
.wiki-ref { font-size: inherit; font-family: inherit; text-decoration: underline dotted; }
.msg-ref, .link.reply { font-size: inherit; font-family: inherit; }
.msg-ref { text-decoration: underline dotted; }
.wiki-body { margin-top: 8px; }
.wiki-edit { display: flex; flex-direction: column; gap: 10px; max-width: 100ch; }
.wiki-edit label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.wiki-edit input { width: 100%; }
.wiki-edit input:disabled { opacity: .7; }
.wiki-text { width: 100%; min-height: 300px; resize: vertical; font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, Menlo, monospace; }
.wiki-edit .actions { align-items: center; flex-wrap: wrap; }
.wiki-version { cursor: default; }
.wiki-version:hover { border-color: var(--line); }
pre.code.wiki-diff { white-space: pre-wrap; overflow-wrap: anywhere; }
.wiki-diff span { display: inline; }
.diff-add { background: rgba(46, 160, 67, .20); }
.diff-del { background: rgba(248, 81, 73, .20); }
.diff-gap { color: var(--muted); }
h4.section { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* ``` fences in posts and wiki pages: lines kept exactly, scrolled sideways, never wrapped (text diagrams, logs, code) */
pre.fence {
  white-space: pre; overflow-x: auto; max-width: 100%; margin: 6px 0; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  font: 12px/1.45 ui-monospace, "Cascadia Code", Consolas, Menlo, monospace; overflow-wrap: normal; word-break: normal;
}

/* ---------- cards ---------- */
:root { --sev-critical: #b3261e; --sev-high: #b86e00; --sev-medium: #2b57c9; --sev-low: #6c6c66; }
@media (prefers-color-scheme: dark) { :root { --sev-critical: #ff8a80; --sev-high: #ffb84d; --sev-medium: #86a6ff; --sev-low: #9b9b95; } }
.pill.sev { text-transform: uppercase; letter-spacing: .02em; background: var(--panel); border: 1px solid currentColor; line-height: 16px; }
.sev-critical { color: var(--sev-critical); }
.sev-high { color: var(--sev-high); }
.sev-medium { color: var(--sev-medium); }
.sev-low { color: var(--sev-low); }
.pill-column { background: var(--accent-soft); color: var(--accent); }
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.kcol { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.kcol-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin: 0 0 2px; }
.kcol-head .count { color: var(--muted); font-weight: 400; }
.kempty { text-align: center; margin: 12px 0; }
.kcard { display: flex; flex-direction: column; gap: 3px; text-align: left; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-left: 4px solid var(--sev-low); border-radius: 6px; padding: 7px 9px; cursor: pointer; font: inherit; }
.kcard:hover { border-color: var(--accent); }
.kcard .title { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.kcard.closed .title { color: var(--muted); }
.kcard-top { display: flex; align-items: center; gap: 6px; }
.kcard .kid { font-size: 12px; color: var(--muted); }
.sev-edge-critical { border-left-color: var(--sev-critical); }
.sev-edge-high { border-left-color: var(--sev-high); }
.sev-edge-medium { border-left-color: var(--sev-medium); }
.thread-head .head-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 6px; }
.thread-head .head-actions .small-btn { margin-left: 0; }
.card-form { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; display: grid; gap: 8px; }
.card-form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.card-form select, .card-form textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.card-form .actions { display: flex; gap: 8px; }

/* ---------- skills ---------- */
:root { --ok: #2e7d32; --ok-bg: #e8f5e9; --warn: #b3261e; --warn-bg: #fff1f0; }
@media (prefers-color-scheme: dark) { :root { --ok: #66bb6a; --ok-bg: #16301a; --warn: #ff8a80; --warn-bg: #3a1414; } }
.pill-reviewed { background: var(--ok-bg); color: var(--ok); }
.pill-unreviewed { background: var(--warn-bg); color: var(--warn); }
.skill-review { border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-weight: 600; font-size: 13px; }
.skill-review.ok { background: var(--ok-bg); color: var(--ok); }
.skill-review.warn { background: var(--warn-bg); color: var(--warn); }
.skill-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 10px 0; font-size: 13px; }
.skill-facts dt { color: var(--muted); }
.skill-facts dd { margin: 0; overflow-wrap: anywhere; }
.skill-facts dd.strong { font-weight: 700; }
.skill-facts dd.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
@media (max-width: 640px) { .skill-facts { grid-template-columns: minmax(0, 1fr); } .skill-facts dd { margin-bottom: 6px; } }

/* Rule 14's work order, above the cards. */
.work-order { margin: 0 0 10px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.work-order p { margin: 2px 0; }
/* A tile's top row wraps, so a chip never runs past the tile's edge. */
.kcard-top { flex-wrap: wrap; row-gap: 4px; }
/* Task locks: who holds a task (rule 5). A stale lock reads as free to take over. */
.pill-lock { background: var(--accent-soft); color: var(--accent); }
.pill-lock.stale { background: var(--k-system-bg); color: var(--k-system); }
.pill-wait { background: var(--warn-bg); color: var(--warn); white-space: normal; border-radius: 9px; max-width: 100%; }
.pill-product { font-weight: 700; letter-spacing: .02em; }
.pill-product.product-core { background: var(--accent-soft); color: var(--accent); }
.pill-product.product-fusion { background: var(--ok-bg); color: var(--ok); }

/* A Markdown table in a post, a wiki page or a document (rich()): a real table, sideways scroll inside its own box. */
.table-wrap { overflow-x: auto; max-width: 100%; margin: 6px 0; white-space: normal; }
.md-table { border-collapse: collapse; font: 12px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; white-space: pre-wrap; overflow-wrap: normal; word-break: normal; }
.md-table th { background: var(--bg); font-weight: 600; }
.md-table td { min-width: 6ch; max-width: 60ch; }

/* Inline Markdown in posts, wiki pages, documents and titles (marked()): **bold**, *italic*, `mono`. */
.md-code { font: 0.95em ui-monospace, "Cascadia Code", Consolas, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 3px; }
.msg .body strong, .doc strong, .wiki-body strong { font-weight: 700; }
