/* Agency components — plain CSS on the tokens. Class prefix: ag- */
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&display=swap");

.ag, .ag * { box-sizing: border-box; }
.ag { font-family: var(--font-sans); font-size: 14px; line-height: 21px; color: var(--ink); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
.ag button { font-family: inherit; }
.ag :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.ag-muted { color: var(--muted); }
.ag-faint { color: var(--faint); }
.ag-mono { font-family: var(--font-mono); font-size: 12px; line-height: 16px; font-weight: 500; }
.ag-ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ag-icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.ag-sep { color: var(--faint); padding: 0 2px; }

/* ── State glyph: shape + colour + word ─────────────────────── */
.ag-state { display: inline-flex; align-items: center; gap: var(--space-1); white-space: nowrap; }
.ag-glyph { width: 8px; height: 8px; flex: none; display: inline-block; }
.ag-glyph--working { border-radius: 50%; background: var(--working); }
.ag-glyph--needs { background: var(--needs); transform: rotate(45deg) scale(.92); border-radius: 1px; }
.ag-glyph--idle { border-radius: 50%; border: 1.5px solid var(--idle); }
.ag-glyph--ended { height: 2px; border-radius: 1px; background: var(--ended); }
.ag-state--working { color: var(--working); }
.ag-state--needs { color: var(--needs); }
.ag-state--idle { color: var(--idle); }
.ag-state--ended { color: var(--faint); }

/* ── Agent pip: role letter, filled by state ─────────────────── */
.ag-pips { display: inline-flex; gap: var(--space-1); align-items: center; }
.ag-pip { width: 18px; height: 18px; border-radius: var(--radius-xs); display: inline-flex; align-items: center; justify-content: center; font: 600 10px/1 var(--font-mono); flex: none; }
.ag-pip--working { background: var(--working); color: var(--on-working); }
.ag-pip--needs { background: var(--needs); color: var(--on-needs); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--needs); margin: 0 2px; }
.ag-pip--idle { border: 1.5px solid var(--idle); color: var(--idle); }
.ag-pip--ended { border: 1.5px dashed var(--ended); color: var(--faint); }
.ag-on-sidebar .ag-pip--needs { box-shadow: 0 0 0 2px var(--sidebar), 0 0 0 3.5px var(--needs); }
.ag-on-ground .ag-pip--needs { box-shadow: 0 0 0 2px var(--ground), 0 0 0 3.5px var(--needs); }
.ag-pips--sm .ag-pip { width: 10px; height: 10px; font-size: 0; }
.ag-pips--sm .ag-pip--needs { box-shadow: none; margin: 0; }
.ag-pips--sm .ag-pip--needs { transform: rotate(45deg) scale(.85); }

/* ── Badges ──────────────────────────────────────────────────── */
.ag-count { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-full); font: 600 11px/1 var(--font-mono); background: var(--needs); color: var(--on-needs); }
.ag-kind { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: var(--radius-xs); font-size: 12px; line-height: 16px; font-weight: 500; color: var(--needs); background: var(--needs-tint); }
.ag-kbd { font: 500 11px/1 var(--font-mono); color: var(--faint); border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 3px 5px; }

/* ── Buttons ─────────────────────────────────────────────────── */
.ag-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-control); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background-color 160ms ease-out; }
.ag-btn:hover { background: var(--hover); }
.ag-btn--primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.ag-btn--primary:hover { background: var(--ink); opacity: .9; }
.ag-btn--danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.ag-btn--quiet { border-color: transparent; background: transparent; color: var(--muted); }
.ag-btn--quiet:hover { background: var(--hover); color: var(--ink); }
.ag-btn--sm { height: 28px; padding: 0 10px; font-size: 13px; }
.ag-btn--icon { width: 28px; height: 28px; padding: 0; border-color: transparent; background: transparent; color: var(--muted); }
.ag-btn--icon:hover { background: var(--hover); color: var(--ink); }
.ag-btn[disabled] { opacity: .4; cursor: default; }
.ag-seg { display: inline-flex; padding: 2px; border-radius: var(--radius-sm); background: var(--hover); gap: 2px; }
.ag-seg button { height: 28px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer; }
.ag-seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }

/* ── Panels and lists ───────────────────────────────────────── */
.ag-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); }
.ag-section-head { display: flex; align-items: baseline; gap: var(--space-2); margin: 0 0 var(--space-2); }
.ag-section-head h2 { margin: 0; font-size: 15px; line-height: 22px; font-weight: 600; }
.ag-section-head .ag-faint { font-size: 13px; }

/* Agent row: fixed height, same columns everywhere */
.ag-agent { display: grid; grid-template-columns: 16px minmax(120px, max-content) minmax(0, 1fr) auto 92px; align-items: center; column-gap: var(--space-3); height: var(--row-h); padding: 0 var(--space-2) 0 var(--space-3); border-radius: var(--radius-sm); }
.ag-agent:hover, .ag-agent:focus-within { background: var(--hover); }
.ag-agent__who { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.ag-agent__name { font-weight: 500; white-space: nowrap; }
.ag-agent__role { font-size: 13px; color: var(--muted); white-space: nowrap; }
.ag-agent__doing { font-size: 13px; color: var(--muted); }
.ag-agent__doing.is-needs { color: var(--needs); font-weight: 500; }
.ag-agent__time { font: 500 12px/16px var(--font-mono); color: var(--faint); text-align: right; }
.ag-agent__time.is-needs { color: var(--needs); }
.ag-agent__actions { display: flex; justify-content: flex-end; gap: 2px; opacity: 0; transition: opacity 120ms ease-out; }
.ag-agent:hover .ag-agent__actions, .ag-agent:focus-within .ag-agent__actions, .ag-agent.show-actions .ag-agent__actions { opacity: 1; }

/* Needs-you item */
.ag-needs-list { overflow: hidden; }
.ag-need { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto auto 28px; align-items: center; column-gap: var(--space-3); padding: 12px var(--space-3) 12px var(--space-4); }
.ag-need + .ag-need { border-top: 1px solid var(--line); }
.ag-need:hover { background: var(--needs-tint); }
.ag-need__q { font-size: 15px; line-height: 22px; font-weight: 500; }
.ag-need__meta { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 18px; color: var(--muted); margin-top: 2px; }
.ag-need__meta b { color: var(--ink); font-weight: 500; }
.ag-need__wait { font: 500 12px/16px var(--font-mono); color: var(--needs); text-align: right; min-width: 52px; }

/* Project row */
.ag-projects { padding: 0 4px; }
.ag-project + .ag-project { border-top: 1px solid var(--line); }
.ag-project__head { margin: 4px 0; display: grid; grid-template-columns: 16px 16px minmax(96px, 150px) max-content minmax(0, 1fr) auto 28px; align-items: center; column-gap: var(--space-3); height: 48px; padding: 0 var(--space-2) 0 var(--space-1); border-radius: var(--radius-sm); cursor: pointer; }
.ag-project__head:hover { background: var(--hover); }
.ag-project__grip, .ag-project__chev { color: var(--faint); display: flex; }
.ag-project__grip { opacity: 0; cursor: grab; }
.ag-project__head:hover .ag-project__grip { opacity: 1; }
.ag-project__name { font-size: 15px; font-weight: 500; }
.ag-project__status { font-size: 13px; color: var(--muted); }
.ag-project__right { display: flex; align-items: center; gap: var(--space-2); }
.ag-project.is-quiet .ag-project__name { color: var(--muted); }
.ag-project__body { padding: 0 0 var(--space-3) 36px; margin-top: -4px; }
.ag-team { margin-top: var(--space-1); }
.ag-team__head { display: flex; align-items: baseline; gap: var(--space-2); padding: 8px var(--space-3) 2px; font-size: 13px; }
.ag-team__head b { font-weight: 600; }

/* ── Inputs ─────────────────────────────────────────────────── */
.ag-composer { display: flex; align-items: flex-end; gap: var(--space-2); min-height: 44px; padding: 6px 6px 6px 6px; background: var(--surface); border: 1px solid var(--line-control); border-radius: var(--radius-sm); }
.ag-composer:focus-within { border-color: var(--ink); }
.ag-composer__to { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 8px; border-radius: 6px; border: 0; background: var(--hover); color: var(--ink); font-size: 13px; font-weight: 500; cursor: pointer; flex: none; white-space: nowrap; }
.ag-composer__to .ag-muted { font-weight: 400; }
.ag-composer textarea { flex: 1; min-width: 0; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink); font: 14px/21px var(--font-sans); padding: 5px 4px; height: 31px; max-height: 168px; }
.ag-composer textarea::placeholder { color: var(--faint); }
.ag-composer__send { width: 30px; height: 30px; border-radius: 6px; border: 0; background: var(--ink); color: var(--on-ink); display: inline-flex; align-items: center; justify-content: center; flex: none; cursor: pointer; }
.ag-composer__send[disabled] { background: var(--hover); color: var(--faint); cursor: default; }
.ag-composer-hint { display: flex; gap: var(--space-3); padding: 6px 2px 0; font-size: 12px; color: var(--faint); }

.ag-field { display: flex; flex-direction: column; gap: 6px; }
.ag-field label { font-size: 13px; font-weight: 500; }
.ag-input { height: 36px; padding: 0 10px; border: 1px solid var(--line-control); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font: 14px var(--font-sans); }
.ag-help { font-size: 13px; color: var(--muted); }

/* ── Question card ──────────────────────────────────────────── */
.ag-question { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.ag-question__head { display: flex; align-items: center; gap: var(--space-2); padding: 10px var(--space-4); background: var(--needs-tint); font-size: 13px; }
.ag-question__head b { font-weight: 600; }
.ag-question__head .ag-mono { margin-left: auto; color: var(--needs); }
.ag-question__body { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.ag-question__title { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; }
.ag-option { display: grid; grid-template-columns: 18px 1fr; column-gap: var(--space-3); align-items: start; padding: 10px var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.ag-option:hover { background: var(--hover); }
.ag-option__radio { width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; border: 1.5px solid var(--line-control); }
.ag-option.is-picked { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.ag-option.is-picked .ag-option__radio { border: 5px solid var(--ink); }
.ag-option b { display: block; font-weight: 500; }
.ag-option span { font-size: 13px; color: var(--muted); }
.ag-question__foot { display: flex; align-items: center; gap: var(--space-2); padding-top: var(--space-1); }
.ag-question__foot .ag-push { margin-left: auto; }
.ag-question__error { display: flex; gap: var(--space-2); align-items: flex-start; padding: 10px var(--space-3); border-radius: var(--radius-sm); border: 1px solid var(--danger); color: var(--danger); font-size: 13px; line-height: 19px; }
.ag-question__error b { font-weight: 600; }
.ag-question__error span { color: var(--ink); }

/* ── Menu, dialog, toast ───────────────────────────────────── */
.ag-menu { width: 248px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); }
.ag-menu__item { display: flex; align-items: center; gap: 10px; min-height: 32px; padding: 6px 10px; border-radius: 6px; font-size: 14px; cursor: pointer; }
.ag-menu__item:hover, .ag-menu__item.is-active { background: var(--hover); }
.ag-menu__item .ag-icon { color: var(--muted); }
.ag-menu__item .ag-kbd { margin-left: auto; }
.ag-menu__item.is-danger { color: var(--danger); }
.ag-menu__item.is-danger .ag-icon { color: var(--danger); }
.ag-menu__item.is-disabled { color: var(--faint); cursor: default; align-items: flex-start; }
.ag-menu__item.is-disabled:hover { background: transparent; }
.ag-menu__item small { display: block; font-size: 12px; line-height: 16px; }
.ag-menu__sep { height: 1px; background: var(--line); margin: 4px 6px; }
.ag-menu__label { padding: 8px 10px 4px; font-size: 12px; color: var(--faint); font-weight: 500; }

.ag-dialog { width: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); }
.ag-dialog__body { padding: var(--space-6) var(--space-6) var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.ag-dialog__title { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; }
.ag-dialog__list { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px; }
.ag-dialog__list .ag-agent { grid-template-columns: 16px max-content minmax(0, 1fr); height: 36px; }
.ag-dialog__foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-6) var(--space-6); }

.ag-toast { display: inline-flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: 6px 6px 6px var(--space-4); background: var(--ink); color: var(--on-ink); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); font-size: 14px; }
.ag-toast button { height: 32px; padding: 0 12px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--on-ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ── Notice: empty, error, offline ─────────────────────────── */
.ag-notice { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-2); padding: var(--space-8) var(--space-6); max-width: 380px; margin: 0 auto; padding-inline: var(--space-4); }
.ag-notice__icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--hover); color: var(--muted); margin-bottom: var(--space-1); }
.ag-notice__icon.is-danger { color: var(--danger); }
.ag-notice h3 { margin: 0; font-size: 15px; line-height: 22px; font-weight: 600; }
.ag-notice p { margin: 0 0 var(--space-2); font-size: 14px; color: var(--muted); }

/* ── App shell ──────────────────────────────────────────────── */
.ag-app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100%; background: var(--ground); overflow: hidden; }
.ag-side { background: var(--sidebar); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px 10px; gap: 2px; min-height: 0; }
.ag-side__brand { display: flex; align-items: center; gap: 8px; padding: 2px 8px 14px; font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.ag-side__brand svg { width: 20px; height: 20px; fill: var(--brand); }
.ag-nav { display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 8px; border-radius: var(--radius-sm); font-size: 14px; color: var(--ink); cursor: pointer; }
.ag-nav:hover { background: var(--hover); }
.ag-nav.is-current { background: var(--selected); font-weight: 500; }
.ag-nav .ag-icon { color: var(--muted); }
.ag-nav__end { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.ag-side__label { padding: 18px 8px 6px; font-size: 12px; font-weight: 500; color: var(--faint); }
.ag-sub { padding-left: 18px; }
.ag-sub .ag-nav { height: 30px; font-size: 13px; color: var(--muted); }
.ag-sub .ag-nav.is-current { color: var(--ink); }
.ag-side__foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 2px; }
.ag-side__status { display: flex; align-items: center; gap: 6px; padding: 6px 8px 0; font-size: 12px; color: var(--faint); }

.ag-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ag-scroll { flex: 1; overflow: hidden; padding: var(--space-8) var(--space-8) var(--space-6); }
.ag-col { max-width: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-6); }
.ag-pagehead { display: flex; align-items: flex-start; gap: var(--space-4); }
.ag-pagehead h1 { margin: 0; font-size: 22px; line-height: 28px; font-weight: 600; letter-spacing: -0.01em; }
.ag-pagehead__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.ag-pagehead__meta b { font-family: var(--font-mono); font-weight: 600; color: var(--ink); font-size: 12px; }
.ag-pagehead .ag-push { margin-left: auto; }
.ag-dock { padding: var(--space-3) var(--space-8) var(--space-6); border-top: 1px solid var(--line); background: var(--ground); }
.ag-dock__inner { max-width: 980px; margin: 0 auto; }
.ag-gd-line { display: flex; gap: var(--space-2); align-items: baseline; font-size: 13px; color: var(--muted); padding: 0 2px 8px; }
.ag-gd-line b { color: var(--ink); font-weight: 500; white-space: nowrap; }

/* Channel header + conversation */
.ag-chanhead { display: flex; align-items: center; gap: var(--space-3); height: 60px; padding: 0 var(--space-6); border-bottom: 1px solid var(--line); background: var(--ground); flex: none; }
.ag-chanhead h1 { margin: 0; font-size: 17px; line-height: 24px; font-weight: 600; }
.ag-chanhead .ag-push { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.ag-crumb { font-size: 13px; color: var(--muted); }
.ag-thread { flex: 1; overflow: hidden; padding: var(--space-6); }
.ag-thread__col { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-6); }
.ag-msg { display: flex; flex-direction: column; gap: 4px; }
.ag-msg__who { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.ag-msg__who b { font-size: 14px; font-weight: 600; }
.ag-msg__body { margin: 0; font-size: 14px; line-height: 22px; max-width: 68ch; }
.ag-msg--you .ag-msg__body { color: var(--ink); }
.ag-day { display: flex; align-items: center; gap: var(--space-3); font-size: 12px; color: var(--faint); }
.ag-day::before, .ag-day::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.ag-event { font-size: 13px; color: var(--faint); display: flex; align-items: center; gap: 6px; }

/* Terminal */
.ag-term { border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; background: var(--terminal-bg); display: flex; flex-direction: column; }
.ag-term__head { display: flex; align-items: center; gap: var(--space-2); height: 40px; padding: 0 6px 0 var(--space-3); background: var(--surface); border-bottom: 1px solid var(--line); font-size: 13px; }
.ag-term__head b { font-size: 14px; font-weight: 500; }
.ag-term__head .ag-push { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.ag-term__body { padding: 12px 14px; font: 400 13px/19px var(--font-mono); color: var(--terminal-ink); white-space: pre; overflow: hidden; flex: 1; }
.ag-term__body .d { color: var(--terminal-dim); }
.ag-term__body .n { color: var(--terminal-needs); }
.ag-term__wait { display: flex; align-items: center; gap: var(--space-2); padding: 8px var(--space-3); background: var(--needs-tint); color: var(--ink); font-size: 13px; border-bottom: 1px solid var(--line); }
.ag-term__wait .ag-mono { color: var(--needs); margin-left: auto; }
