:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --card: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --accent-soft: #cde2fb;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --warning-soft: #fff3d6;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-soft: #fde4e4;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --card: #1a1a19;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --line: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --hover: rgba(255, 255, 255, 0.05);
    --accent: #3987e5; --accent-soft: #1c3b63;
    --good-text: #0ca30c; --warning-soft: #3a2d0c; --critical-soft: #3d1717;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --card: #1a1a19;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --line: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --hover: rgba(255, 255, 255, 0.05);
  --accent: #3987e5; --accent-soft: #1c3b63;
  --good-text: #0ca30c; --warning-soft: #3a2d0c; --critical-soft: #3d1717;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 17px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a { color: var(--ink-2); padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.nav a:hover { background: var(--hover); text-decoration: none; }
.nav a.active { color: var(--ink); background: var(--hover); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on .dot { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.live.pulse .dot { animation: pulse .8s ease-out; }
@keyframes pulse { from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); } to { box-shadow: 0 0 0 10px transparent; } }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--hover); }
.me { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13px; }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); cursor: pointer; }

/* ---------- layout */
.app { padding: 24px 20px 64px; max-width: 1480px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); max-width: 760px; }
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; overflow-y: hidden; }
.tabs a { padding: 8px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card + .card { margin-top: 14px; }
.grid .card + .card, .tiles .card + .card, .charts .card + .card { margin-top: 0; }
.section { margin-bottom: 28px; }
.section > h2 { margin-bottom: 10px; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.error-box { padding: 16px; border-radius: var(--radius); background: var(--critical-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent); }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- chips & badges */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; line-height: 20px;
  border: 1px solid var(--line); color: var(--ink-2); background: var(--surface); white-space: nowrap; }
.chip .sw { width: 8px; height: 8px; border-radius: 50%; }
.status-backlog .sw { background: var(--axis); }
.status-todo .sw { background: var(--muted); }
.status-in_progress .sw { background: var(--s1); }
.status-in_review .sw { background: var(--s7); }
.status-blocked .sw { background: var(--critical); }
.status-done .sw { background: var(--good); }
.status-cancelled .sw { background: var(--line); }
.prio { font-weight: 650; font-size: 11px; padding: 0 6px; border-radius: 5px; line-height: 18px; border: 1px solid var(--line); color: var(--ink-2); }
.prio-0 { background: var(--critical); border-color: var(--critical); color: #fff; }
.prio-1 { color: var(--ink); border-color: var(--axis); }
.label { font-size: 11px; color: var(--ink-2); background: var(--hover); padding: 0 6px; border-radius: 5px; line-height: 18px; }
.flag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 6px; line-height: 20px; }
.flag-question { background: var(--warning-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warning) 60%, transparent); }
.flag-attention { background: var(--critical-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--critical) 50%, transparent); }
.count { font-size: 11px; color: var(--muted); font-weight: 500; }

/* ---------- avatars */
.av { --c: var(--s1); display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--c); color: #fff; font-size: 10px; font-weight: 700; flex: none; letter-spacing: -.02em; }
.av.dark-text { color: #0b0b0b; }
.av.three { font-size: 8px; letter-spacing: -.04em; }
.av.lg { width: 40px; height: 40px; font-size: 15px; }
.av.lg.three { font-size: 12px; }
.av.human { background: var(--surface); color: var(--ink-2); border: 1px solid var(--axis); }
.who { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-weight: 550; }

/* ---------- board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(180px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 10px; font-weight: 600; font-size: 13px; }
.col-body { display: flex; flex-direction: column; gap: 8px; }
.tcard { display: block; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px; color: var(--ink); box-shadow: var(--shadow); }
.tcard:hover { border-color: var(--accent); text-decoration: none; }
.tcard .tid { font-family: var(--mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.tcard > .spread { flex-wrap: wrap; row-gap: 4px; }
.tcard .ttl { margin: 4px 0 8px; font-weight: 550; line-height: 1.35; overflow-wrap: anywhere; }
.tcard .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.tcard .working { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-2); display: flex; gap: 6px; align-items: flex-start; }
.tcard .working .txt { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lease { font-variant-numeric: tabular-nums; }
.lease.low { color: var(--critical); font-weight: 600; }
.toggle { display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2); font-size: 13px; cursor: pointer; user-select: none; }

/* ---------- ticket */
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.ticket-title { font-size: 22px; font-weight: 650; overflow-wrap: anywhere; }
.callout { display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; align-items: flex-start; }
.callout.question { background: var(--warning-soft); border: 1px solid color-mix(in srgb, var(--warning) 60%, transparent); }
.callout.attention { background: var(--critical-soft); border: 1px solid color-mix(in srgb, var(--critical) 50%, transparent); }
.callout.archived { background: color-mix(in srgb, var(--line) 35%, transparent); border: 1px solid var(--line); }
.tcard.archived { opacity: .8; }
.callout .ic { font-size: 18px; line-height: 1.2; }
.prose { overflow-wrap: anywhere; }
.prose p { margin: 0 0 8px; }
.prose p:last-child { margin-bottom: 0; }
.prose pre { background: var(--page); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; white-space: pre-wrap; }
.prose code { background: var(--hover); padding: 1px 4px; border-radius: 4px; }
.prose pre code { background: none; padding: 0; }
.prose ul { margin: 0 0 8px; padding-left: 20px; }
.prose h4 { margin: 10px 0 4px; font-size: 14px; }
.checklist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; }
.check { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--axis); flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; margin-top: 1px; }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.side dl { margin: 0; display: grid; grid-template-columns: 96px 1fr; gap: 8px 10px; font-size: 13px; }
.side dt { color: var(--muted); }
.side dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.list-plain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.list-plain li { min-width: 0; overflow-wrap: anywhere; }
.usage { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.usage .v { font-size: 16px; font-weight: 650; }
.usage .k { font-size: 11px; color: var(--muted); }

/* ---------- timeline */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filters button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 10px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.filters button[aria-pressed="true"] { background: var(--ink); color: var(--page); border-color: var(--ink); }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 10px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl { position: relative; padding: 0 0 14px 34px; }
.tl .node { position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); border: 2px solid var(--axis); display: flex; align-items: center; justify-content: center; font-size: 9px; }
.tl .head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.tl .head time { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
.tl .body { margin-top: 4px; overflow-wrap: anywhere; }
.tl .detail { margin-top: 6px; }
.tl .detail summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.tl .detail pre { margin: 6px 0 0; white-space: pre-wrap; background: var(--page); border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 360px; overflow: auto; }
.tl .use { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl.comment .bubble { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-top: 4px; }
.tl.comment.human .bubble { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--accent-soft) 35%, var(--card)); }
.atype { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; padding: 0 6px; border-radius: 5px; line-height: 18px; border: 1px solid var(--line); color: var(--ink-2); display: inline-flex; gap: 4px; align-items: center; }
.atype .sw { width: 7px; height: 7px; border-radius: 50%; }
.at-thought .sw { background: var(--s7); }
.at-action .sw { background: var(--s1); }
.at-result .sw { background: var(--s3); }
.at-question .sw { background: var(--warning); }
.at-error .sw { background: var(--critical); }
.at-note .sw { background: var(--muted); }
.tl.at-question .node { border-color: var(--warning); }
.tl.at-error .node { border-color: var(--critical); }
.tl.status .node { border-color: var(--accent); }

.comment-form { margin-top: 8px; }
.comment-form textarea { width: 100%; min-height: 90px; resize: vertical; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); }
.comment-form .row { margin-top: 8px; justify-content: space-between; }
.btn { border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: none; color: var(--ink); border-color: var(--line); }

/* ---------- feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); align-items: start; }
.feed li.fresh { animation: fresh 2s ease-out; }
@keyframes fresh { from { background: color-mix(in srgb, var(--accent) 14%, transparent); } to { background: transparent; } }
.feed .what { font-size: 13px; overflow-wrap: anywhere; }
.feed .what .sub { color: var(--ink-2); }
.feed time { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- agents */
.agent-card .head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.agent-card .name { font-weight: 650; font-size: 15px; }
.state-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--axis); margin-right: 4px; }
.state-dot.working { background: var(--good); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* ---------- insights */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile .v { font-size: 26px; font-weight: 650; line-height: 1.1; }
.tile .k { color: var(--ink-2); font-size: 12px; margin-top: 4px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; margin-bottom: 18px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .val { fill: var(--ink-2); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .lbl { fill: var(--ink); font-size: 12px; }
.chart .bar { fill: var(--s1); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { opacity: .8; }
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--card); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, .12); max-width: 280px; }
.tooltip b { font-variant-numeric: tabular-nums; }

/* ---------- graph */
.graph-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.graph-wrap svg { display: block; }
.gnode rect.box { fill: var(--card); stroke: var(--border); stroke-width: 1; }
.gnode:hover rect.box { stroke: var(--accent); stroke-width: 2; }
.gnode .bar { stroke: none; }
.gnode text { fill: var(--ink); font-size: 12px; }
.gnode .gid { fill: var(--muted); font-family: var(--mono); font-size: 11px; }
.gnode .gst { fill: var(--ink-2); font-size: 11px; }
.gnode.cancelled { opacity: .45; }
.gedge { fill: none; stroke: var(--axis); stroke-width: 1.5; }
.gedge.open { stroke: var(--muted); stroke-dasharray: 4 3; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin: 10px 0; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- login */
.login { max-width: 460px; margin: 8vh auto 0; }
.login input { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-family: var(--mono); margin: 12px 0; }
.login ol { padding-left: 18px; color: var(--ink-2); }

@media (max-width: 960px) {
  .ticket-layout { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: 8px 16px; gap: 10px; flex-wrap: wrap; }
  .app { padding: 16px 16px 48px; }
  .live-label { display: none; }
  .grid, .charts { grid-template-columns: 1fr; }
  .board { grid-auto-columns: 82vw; }
  .side dl { grid-template-columns: 84px 1fr; }
}

/* ---------- iterations */
.iter-planning .sw { background: var(--muted); }
.iter-active .sw { background: var(--s1); }
.iter-review .sw { background: var(--warning); }
.iter-closed .sw { background: var(--good); }
