/* Layout */
header#header { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding: 12px 20px; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { line-height: 1.1; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); position: relative; }
.logo::before { content: ""; position: absolute; left: 7px; top: 15px; width: 20px; height: 3px; border-radius: 3px; background: #fff; transform: rotate(-42deg); }
.logo::after { content: ""; position: absolute; left: 6px; bottom: 5px; width: 8px; height: 8px; border-radius: 50%; background: #fff; }
.health { display: flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 99px; font-weight: 700; }
.health.good { background: color-mix(in srgb, var(--good) 14%, var(--surface)); color: var(--good-ink); }
.health.bad { background: color-mix(in srgb, var(--bad) 16%, var(--surface)); color: var(--bad-ink); }
.stats { display: flex; gap: 18px; }
.stat { display: grid; line-height: 1.15; }
.stat strong { font-size: 18px; }
.stat span { font-size: 11px; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.btn.github i { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--good); }
.conn { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.conn.bad i { background: var(--bad); }
.banner { flex-basis: 100%; padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 24%, var(--surface)); color: var(--warn-ink); font-weight: 600; }

main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--gap); padding: var(--gap) 20px 40px; align-items: start; }
.column { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); min-width: 0; }
#needs:empty { display: none; }

/* Composer */
#compose { display: grid; gap: 8px; padding: 12px; }
#compose label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.compose-row { display: flex; gap: 8px; align-items: stretch; }
.compose-row textarea { min-height: 40px; resize: none; field-sizing: content; max-height: 160px; }
#plans:empty { display: none; }
#plans { display: grid; gap: 4px; }
.plan { display: flex; gap: 8px; align-items: center; min-width: 0; }
.plan .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spinner { width: 12px; height: 12px; flex: none; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
.plan.done .spinner, .plan.failed .spinner { animation: none; border-color: var(--good); }
.plan.failed .spinner { border-color: var(--bad); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Needs you */
.needs { display: grid; gap: 8px; }
.needs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--gap); }
.question { display: grid; gap: 8px; align-content: start; border: 2px solid var(--warn); }
.question.blocking { border-color: var(--serious); }
.question p { color: var(--ink-2); overflow-wrap: anywhere; }
.options { display: flex; flex-wrap: wrap; gap: 8px; }
.options .btn { white-space: normal; }

/* Agents: headed by the work, with model and machine underneath */
#team { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.section-head .btn { margin-left: auto; align-self: center; }
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.job { display: flex; flex-direction: column; gap: 7px; padding: 12px 14px; border-top: 3px solid var(--accent); animation: arrive 0.35s ease-out; }
.job.chore { border-top-color: var(--line-2); }
.job-top { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.verb { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); }
.verb i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.chore .verb i { background: var(--muted); }
.headline { padding: 0; border: 0; background: none; text-align: left; font-size: 16px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
button.headline:hover { color: var(--accent); }
.doing { font-size: 13px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; min-height: 2.9em; }
.job-who { display: flex; align-items: center; gap: 9px; margin-top: auto; padding-top: 9px; border-top: 1px solid var(--line); min-width: 0; }
.who-text { display: grid; flex: 1; min-width: 0; line-height: 1.25; font-size: 13px; }
.who-text > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The machine and the profile may take a second line rather than lose a word. */
.who-text > span { white-space: normal; }
.quiet { padding: 14px 16px; border: 1px dashed var(--line-2); border-radius: var(--radius); color: var(--muted); }
.bench { display: flex; flex-wrap: wrap; gap: 6px; }
.benched { display: flex; align-items: center; gap: 7px; max-width: 100%; padding: 5px 11px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); font-size: 12px; font-weight: 600; }
.benched span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.benched .muted { flex: none; font-weight: 400; }
.benched i, .status i { width: 8px; height: 8px; flex: none; border-radius: 50%; border: 2px solid var(--muted); }
.benched.idle i, .status.idle i { border-color: var(--good); background: var(--good); }
.benched.resting i, .benched.failed i, .status.resting i { border-color: var(--warn); background: var(--warn); }
.status.working i { background: var(--accent); border-color: var(--accent); }
.benched.failed { border-color: var(--warn); }
.benched.offline, .benched.off { opacity: 0.65; }
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--ink-2); white-space: nowrap; }
.trouble { font-size: 12px; color: var(--warn-ink); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.switch { width: 36px; height: 21px; flex: none; padding: 2px; border: 0; border-radius: 99px; background: var(--line-2); }
.switch span { display: block; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch[aria-checked="true"] { background: var(--good); }
.switch[aria-checked="true"] span { transform: translateX(15px); }

/* Devices: machine, then subscription or key, then its agents */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: var(--gap); align-items: start; }
.device { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; padding: 0; }
.device > header { display: flex; align-items: center; gap: 11px; padding: 13px 16px; }
.device > header > div { display: grid; flex: 1; min-width: 0; }
.device > header h2 { overflow-wrap: anywhere; }
.device.offline > header { opacity: 0.65; }
.device-icon { position: relative; flex: none; width: 30px; height: 21px; margin-bottom: 4px; border: 2px solid var(--ink-2); border-radius: 4px; }
.device-icon::after { content: ""; position: absolute; left: -5px; right: -5px; bottom: -6px; height: 2px; border-radius: 2px; background: var(--ink-2); }
.subscription { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 13px 16px; border-top: 1px solid var(--line); }
.sub-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.sub-head h3 { font-size: 14px; overflow-wrap: anywhere; }
.windows { display: grid; gap: 7px; }
.window { display: grid; gap: 1px; }
.window .meter { grid-template-columns: 74px 1fr 62px; font-size: 12px; color: var(--ink-2); }
.window .meter.warn { color: var(--warn-ink); }
.window .meter.warn .meter-fill { background: var(--warn); }
.window small { padding-left: 82px; }
.window-text { display: grid; grid-template-columns: 74px 1fr; gap: 8px; font-size: 12px; color: var(--ink-2); }
.money-block { display: grid; gap: 7px; }
.totals { font-variant-numeric: tabular-nums; }
.agent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.agent { display: flex; align-items: flex-start; gap: 10px; padding: 9px 10px; border-radius: 10px; background: var(--surface-2); }
.agent.off > .avatar, .agent.offline > .avatar, .agent.off > .agent-main, .agent.offline > .agent-main { opacity: 0.6; }
.agent .avatar { width: 30px; height: 30px; font-size: 13px; }
.agent-main { display: grid; flex: 1; min-width: 0; justify-items: start; line-height: 1.3; }
.agent-main > * { max-width: 100%; overflow-wrap: anywhere; }
.agent-main .link, .on-it { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.on-it { font-size: 12px; }
.model-pick { padding: 0; border: 0; background: none; font-weight: 700; text-align: left; overflow-wrap: anywhere; }
.model-pick:hover { color: var(--accent); }
.agent-side { display: grid; justify-items: end; gap: 6px; flex: none; }
.agent-actions { display: flex; align-items: center; gap: 10px; }
.foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Brainstorm room */
.brainstorm { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.brainstorm h2 { overflow-wrap: anywhere; white-space: pre-wrap; }
.ideas { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.idea { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.idea.thinking { border-style: dashed; color: var(--ink-2); }
.idea.thinking .spinner { display: inline-block; vertical-align: -1px; }
.idea-text { overflow-wrap: anywhere; }
.idea .files { overflow-wrap: anywhere; }
.wrong-if { font-size: 12px; color: var(--ink-2); overflow-wrap: anywhere; }
/* A model's name is read whole: the button drops below it where a card is narrow. */
.idea .job-who { align-self: stretch; flex-wrap: wrap; }
.idea .who-text { flex-basis: 140px; }
.idea .job-who .btn { margin-left: auto; }

/* Tabs */
#tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); scroll-margin-top: 90px; overflow-x: auto; }
#tabs button { flex: none; border: 0; background: none; padding: 9px 14px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
#tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
#tabs .tab-team, #tabs .tab-feed { display: none; }
.view { display: none; min-width: 0; }
body[data-tab="flow"] .view-flow, body[data-tab="map"] .view-map, body[data-tab="talk"] .view-talk,
body[data-tab="devices"] .view-devices, body[data-tab="ideas"] .view-ideas,
body[data-tab="costs"] .view-costs, body[data-tab="skills"] .view-skills { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }

/* Flow */
.track { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; }
.track-now { display: flex; align-items: center; gap: 14px; min-width: 0; }
.rail { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cars { display: flex; gap: 3px; }
.car { padding: 5px 11px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.track.running .cars { animation: roll 1.4s ease-in-out infinite alternate; }
@keyframes roll { from { transform: translateX(0); } to { transform: translateX(9px); } }
.station { padding: 4px 10px; border: 2px solid var(--line-2); border-radius: 8px; font-weight: 700; }
.track-past { display: flex; flex-wrap: wrap; gap: 6px; }
.gate { flex-basis: 100%; display: grid; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; }
.gate summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
.gate-form { grid-template-columns: minmax(0, 420px) auto; justify-content: start; margin: 8px 0 4px; }
.run { padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.run.landed { background: color-mix(in srgb, var(--good) 14%, var(--surface)); color: var(--good-ink); }
.run.partial { background: color-mix(in srgb, var(--warn) 24%, var(--surface)); color: var(--warn-ink); }
.run.failed { background: color-mix(in srgb, var(--bad) 14%, var(--surface)); color: var(--bad-ink); }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 1fr); gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.lane { display: flex; flex-direction: column; gap: 8px; padding: 8px; border-radius: var(--radius); background: var(--surface-2); min-height: 150px; min-width: 0; }
.lane h3 { display: flex; justify-content: space-between; padding: 2px 4px; color: var(--ink-2); }
.count { font-variant-numeric: tabular-nums; color: var(--muted); }
.task { display: grid; gap: 6px; text-align: left; padding: 10px 11px; border: 1px solid var(--line); border-left: 4px solid var(--line-2); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); animation: arrive 0.35s ease-out; min-width: 0; }
@keyframes arrive { from { transform: translateY(-6px); } }
.task:hover { border-color: var(--accent); }
.task.s-building, .task.s-reviewing, .task.s-merging { border-left-color: var(--accent); }
.task.s-review_wait, .task.s-queued { border-left-color: color-mix(in srgb, var(--accent) 45%, var(--surface)); }
.task.s-approval_wait, .task.s-needs_human { border-left-color: var(--warn); }
.task.s-merged { border-left-color: var(--good); }
.task.s-reverted { border-left-color: var(--bad); }
.task-top { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.task-top .avatar { margin-left: auto; }
.id { font-size: 11px; font-weight: 700; color: var(--muted); }
.title { font-weight: 600; overflow-wrap: anywhere; }
.who { display: flex; align-items: center; gap: 9px; min-width: 0; padding: 2px 0 2px 3px; }
.who div { display: grid; min-width: 0; font-size: 12px; }
.who span:not(.avatar) { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.why { font-size: 12px; color: var(--muted); }
.why.back { color: var(--warn-ink); font-weight: 600; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 9px; align-items: center; font-size: 11px; color: var(--muted); }
.risk.high { color: var(--bad-ink); font-weight: 700; }

/* Map */
.scroll { overflow-x: auto; padding-top: 6px; }
.view-map .card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
svg text { fill: var(--ink); font-size: 12px; }
.trunk { stroke: var(--ink-2); stroke-width: 4; stroke-linecap: round; }
.trunk.red { stroke: var(--bad); }
.head { fill: var(--ink-2); }
.branch { fill: none; stroke: var(--line-2); stroke-width: 2.5; }
.branch.landed { stroke: var(--good); }
.branch-name { font-weight: 700; }
svg text.branch-note { fill: var(--muted); font-size: 11px; }
svg text.num { font-weight: 700; font-size: 11px; }
.node, .box { cursor: pointer; --sc: var(--muted); }
.node .hit { fill: transparent; }
.node .dot { fill: var(--surface); stroke: var(--sc); stroke-width: 3; }
.node .dot.filled { fill: var(--sc); }
.node .ring { fill: none; stroke: var(--sc); stroke-width: 2; animation: pulse 1.6s ease-out infinite; transform-box: fill-box; transform-origin: center; }
.node .badge { fill: var(--vc); stroke: var(--surface); stroke-width: 2; }
svg text.badge-letter { fill: #fff; font-size: 9px; font-weight: 700; }
.v-4 svg text.badge-letter, svg .v-4 text.badge-letter { fill: var(--v4-ink); }
.st-building, .st-reviewing, .st-merging, .st-review_wait, .st-queued { --sc: var(--accent); }
.st-merged { --sc: var(--good); }
.st-approval_wait, .st-needs_human { --sc: var(--warn); }
.st-reverted { --sc: var(--bad); }
.collision path { fill: none; stroke: var(--bad); stroke-width: 2; stroke-dasharray: 5 4; }
.collision text { fill: var(--bad-ink); font-weight: 800; font-size: 14px; }
.box rect { fill: var(--surface); stroke: var(--sc); stroke-width: 2; }
.box:hover rect { fill: var(--surface-2); }
.edge { fill: none; stroke: var(--line-2); stroke-width: 2; stroke-dasharray: 5 4; }
.edge.met { stroke: var(--good); stroke-dasharray: none; }
.tip { fill: var(--muted); }

.why.held { color: var(--good-ink); font-weight: 600; }
.next { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.next .chip { border: 0; cursor: pointer; }

/* Talk and feed */
.talk { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: var(--gap); }
.thread-list { display: flex; flex-direction: column; gap: 4px; max-height: 480px; overflow-y: auto; }
.thread-list button { display: grid; text-align: left; padding: 9px 11px; border: 1px solid transparent; border-radius: 10px; background: none; min-width: 0; flex: none; }
.thread-list button > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-list button span { font-size: 12px; color: var(--muted); }
.thread-list button.on { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
.messages { display: flex; flex-direction: column; gap: 14px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); height: 480px; overflow-y: auto; }
.msg { display: flex; gap: 10px; min-width: 0; }
.msg-body { min-width: 0; display: grid; gap: 2px; justify-items: start; }
.msg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.msg p { overflow-wrap: anywhere; }
.tag { padding: 0 7px; border-radius: 5px; border: 1px solid var(--line-2); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); }
.tag.t-warn, .tag.t-object { border-color: var(--serious); }
.tag.t-decide { border-color: var(--good); }
.tag.t-ask, .tag.t-handoff { border-color: var(--warn); }
.tag.t-announce, .tag.t-propose { border-color: var(--accent); }
.reply { display: flex; gap: 8px; margin-left: calc(250px + var(--gap)); }
#feed { position: sticky; top: 78px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 92px); min-width: 0; }
.feed-list { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.event { display: flex; gap: 10px; min-width: 0; animation: arrive 0.35s ease-out; }
.event p { overflow-wrap: anywhere; font-size: 13px; }
.mark { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); font-weight: 800; color: var(--ink-2); }
.event.good .mark { background: color-mix(in srgb, var(--good) 18%, var(--surface)); color: var(--good-ink); }
.event.warn .mark { background: color-mix(in srgb, var(--warn) 28%, var(--surface)); color: var(--warn-ink); }
.event.bad .mark { background: color-mix(in srgb, var(--bad) 18%, var(--surface)); color: var(--bad-ink); }
.empty { display: grid; gap: 10px; justify-items: center; text-align: center; padding: 34px 20px; }

/* Narrower screens: the feed moves below. */
@media (max-width: 1180px) {
  main { grid-template-columns: minmax(0, 1fr); }
  #feed { display: none; }
  #tabs .tab-feed { display: block; }
  body[data-tab="feed"] #feed { display: flex; position: static; max-height: none; grid-row: 2; }
}
/* Tabs that only small screens have: on a wide one they show the tasks. */
@media (min-width: 1181px) { body[data-tab="feed"] .view-flow { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); } }
@media (min-width: 761px) { body[data-tab="team"] .view-flow { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); } }

/* Phones: one section at a time, switched from a bar at the bottom. */
@media (max-width: 760px) {
  header#header { padding: 10px 14px; gap: 8px 12px; position: static; }
  .stats { display: none; }
  .health { margin-left: auto; padding: 4px 10px; font-size: 12px; }
  .header-actions { width: 100%; gap: 6px; }
  .header-actions .btn { padding-left: 11px; padding-right: 11px; }
  .btn.github .wide { display: none; }
  .conn { margin-left: auto; }
  main { padding: 12px 12px 90px; }
  .compose-row { flex-wrap: wrap; }
  .compose-row textarea { flex-basis: 100%; }
  .compose-row .btn { flex: 1; }
  /* New work is typed where work is shown; elsewhere the box only pushes the page down. */
  body:is([data-tab="devices"], [data-tab="talk"], [data-tab="costs"], [data-tab="map"], [data-tab="skills"]) #compose { display: none; }
  /* A bar that scrolls sideways: more sections than fit stay one swipe away. */
  #tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; gap: 0; background: var(--surface); border-top: 1px solid var(--line); border-bottom: 0; padding: 0 0 env(safe-area-inset-bottom); scrollbar-width: none; }
  #tabs button, #tabs .tab-team { display: block; flex: 1 0 auto; padding: 14px 11px; border-bottom: 0; border-top: 3px solid transparent; font-size: 12px; }
  #tabs .tab-feed { display: none; }
  #tabs button.on { border-top-color: var(--accent); }
  #team { display: none; }
  body[data-tab="team"] #team { display: grid; }
  body[data-tab="team"] #feed { display: flex; position: static; max-height: none; }
  .jobs, .devices { grid-template-columns: minmax(0, 1fr); }
  .board { grid-auto-flow: row; grid-auto-columns: auto; overflow: visible; }
  .lane { min-height: 0; }
  .lane.is-empty { display: none; }
  .talk { grid-template-columns: minmax(0, 1fr); }
  .thread-list { flex-direction: row; overflow-x: auto; max-height: none; }
  .thread-list button { max-width: 200px; }
  .messages { height: 50vh; }
  .reply { margin-left: 0; }
  .grid3 { grid-template-columns: 1fr; }
  .inline { grid-template-columns: 1fr; }
  #drawer { width: 100vw; max-width: 100vw; border-radius: 0; }
  #toast { bottom: 76px; }
}
