/* Grapim hub. The tokens are ui/tokens.css (loaded first, as
   /hub/static/tokens.css), the same file the review desk uses, and the app
   shell is the desk's, so the two read as one product. 4 px grid. */

:root {
  /* Report charts (docs/provenance.md section 7). Agent kinds keep one colour
     each, in a fixed order, checked for colour-blind separation; unknown is a
     neutral, never a hue. Review states reuse the status colours. Everything
     else (colour, type, radius, shadow, focus, motion) is in tokens.css,
     shared with the review desk. */
  --k1: #2a78d6; --k2: #eb6834; --k3: #1baf7a; --k4: #eda100; --k5: #e87ba4; --k6: #6250d6;
  --k-unknown: #d9d9d3;
  --k-pending: #d99a1e; --k-rejected: #d03b3b; --k-approved: #b9d9c2;
  --chart-grid: #ecece8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --k1: #3987e5; --k2: #d95926; --k3: #199e70; --k4: #c98500; --k5: #d55181; --k6: #9085e9;
    --k-unknown: #3a3a40;
    --k-pending: #c98500; --k-rejected: #e66767; --k-approved: #2c4a36;
    --chart-grid: #232327;
  }
}

/* ---------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 16px; }
body {
  margin: 0; min-height: 100vh;
  background: var(--bg); color: var(--text);
  font: 400 var(--fs-13)/20px var(--font);
  font-feature-settings: var(--font-features);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, p, ol, ul, dl, dd, pre { margin: 0; }
ol, ul { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
p a, .fine a, .muted a, .link { color: var(--accent-text); text-underline-offset: 2px; }
p a:hover, .fine a:hover, .link:hover { text-decoration: underline; }
.link-quiet:hover { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
code, pre, kbd, .mono { font-family: var(--mono); font-size: var(--fs-12); font-variant-ligatures: none; }
p code, .fine code, .card-sub code, li code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; color: var(--text); overflow-wrap: anywhere; }
time, .num { font-variant-numeric: tabular-nums; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
* { scrollbar-color: var(--border-strong) transparent; scrollbar-width: thin; }

kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 4px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px;
  background: var(--surface); color: var(--text-2); font: 500 var(--fs-11)/1 var(--font);
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -48px; z-index: 50; padding: 8px 12px; background: var(--surface); border-radius: var(--radius); }
.skip:focus { top: 8px; box-shadow: var(--shadow-pop); }
.muted { color: var(--text-3); }
.small { font-size: var(--fs-12); }
.strong { font-weight: 600; }
.truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad { padding: 12px 16px; }
.icon { width: 16px; height: 16px; flex: none; display: inline-block; vertical-align: -3px; }

/* ---------------------------------------------------------------- app shell (team pages) */

.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }

.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px 12px; border-right: 1px solid var(--border); background: var(--bg);
}
.brand { display: inline-flex; align-items: center; gap: 8px; height: 28px; padding: 0 8px; font-weight: 600; font-size: var(--fs-14); letter-spacing: -0.01em; flex: none; border-radius: var(--radius); }
.logo { width: 18px; height: 18px; color: var(--text); flex: none; }

.switcher { position: relative; }
.switch {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; cursor: pointer; list-style: none;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.switch::-webkit-details-marker { display: none; }
.switch:hover { border-color: var(--border-strong); }
.switcher[open] > .switch { border-color: var(--border-strong); background: var(--surface-2); }
.switch-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.switch-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switch-sub { color: var(--text-3); font-size: var(--fs-12); line-height: 16px; text-transform: capitalize; }
.switch-chev { color: var(--text-3); }
.team-mark { width: 24px; height: 24px; border-radius: var(--radius); background: var(--text); color: var(--bg); display: inline-grid; place-items: center; font: 600 var(--fs-12)/1 var(--font); flex: none; }

.menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; width: max(100%, 264px);
  padding: 4px; max-height: min(480px, 70vh); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
}
.menu-label { padding: 6px 8px 4px; color: var(--text-3); font-size: var(--fs-12); font-weight: 500; }
.menu-item { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px 8px; border-radius: var(--radius); color: var(--text); }
.menu-item:hover { background: var(--surface-2); }
.menu-item[aria-current="true"] { background: var(--surface-2); }
.menu-item .icon { color: var(--text-3); }
.menu-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.menu-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.menu-sub { color: var(--text-3); font-size: var(--fs-12); line-height: 16px; }
.menu-item .menu-check { color: var(--accent-text); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

.search-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 32px; padding: 0 8px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text-3);
}
.search-btn:hover { border-color: var(--border-strong); color: var(--text-2); }
.search-btn span { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-btn kbd { height: 16px; min-width: 16px; font-size: var(--fs-11); border-bottom-width: 1px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px; border-radius: var(--radius); color: var(--text-2); font-weight: 500; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--surface-3); color: var(--text); }
.nav-item .icon { color: var(--text-3); }
.nav-item[aria-current="page"] .icon { color: var(--text); }
.nav-item .count { margin-left: auto; color: var(--accent-text); font-size: var(--fs-12); font-weight: 600; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px 4px 0; border-top: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me .login { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: var(--radius); color: var(--text-2); background: none; border: 0; cursor: pointer; list-style: none; }
.icon-btn::-webkit-details-marker { display: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Plain top bar: sign in, the team list, invites, errors. */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 48px; padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.top .crumbs { margin: 0; font-size: var(--fs-13); }
.top .brand { padding: 0; }
.top .me { flex: none; }
.who { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); }
.avatar { width: 20px; height: 20px; border-radius: 50%; flex: none; background: var(--surface-3); object-fit: cover; }
.row .avatar { width: 24px; height: 24px; }
.avatar-blank { display: inline-grid; place-items: center; font: 600 var(--fs-11)/1 var(--font); color: var(--text-2); }

.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--text-3); font-size: var(--fs-12); margin-bottom: 12px; }
.slash { color: var(--border-strong); }
.crumb { color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.top .crumb { color: var(--text-2); font-weight: 500; }
a.crumb:hover { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.crumb.current { color: var(--text-2); }

/* Content width: data and diffs wide, settings and tabbed pages middle, forms readable. */
.wrap { width: 100%; max-width: 824px; margin: 0 auto; padding: 24px 32px 80px; }
.wrap-mid { max-width: 1064px; }
.wrap-wide { max-width: 1264px; }
main:focus { outline: none; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head-main { min-width: 0; flex: 1 1 320px; }
.page-head h1 { font-size: var(--fs-20); line-height: 28px; font-weight: 600; letter-spacing: -0.015em; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; overflow-wrap: anywhere; text-wrap: balance; }
.page-sub { color: var(--text-2); margin-top: 4px; max-width: 72ch; }
.page-sub .sep { color: var(--border-strong); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sha { color: var(--text-3); font-weight: 400; font-size: var(--fs-12); }
.lede { color: var(--text-2); font-size: var(--fs-14); line-height: 22px; max-width: 64ch; }
.fine { color: var(--text-3); font-size: var(--fs-12); line-height: 18px; margin-top: 12px; max-width: 80ch; }
.section-title { font-size: var(--fs-13); font-weight: 600; margin: 32px 0 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sub-title { font-size: var(--fs-13); font-weight: 600; margin: 16px 0 8px; }

.tabs { display: flex; gap: 4px; margin: -8px 0 24px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab { position: relative; flex: none; padding: 8px 8px 10px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--text); }
.tab[aria-current="page"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--text); border-radius: 2px; }
.tab:focus-visible { outline-offset: -2px; }

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 500; white-space: nowrap; cursor: pointer; box-shadow: var(--shadow-1);
  transition: background-color 80ms ease, border-color 80ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(0.5px); }
.btn .icon { width: 14px; height: 14px; vertical-align: -2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border-strong)); }
.btn-sm { height: 24px; padding: 0 8px; font-size: var(--fs-12); }
.btn-block { width: 100%; height: 40px; font-size: var(--fs-14); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.gh { width: 16px; height: 16px; }

input[type="text"], input[type="number"], input[type="password"], select {
  height: 32px; padding: 0 10px; min-width: 0;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
.input-narrow { width: 80px; }
textarea {
  width: 100%; padding: 8px 10px; font-family: var(--mono); font-size: var(--fs-13);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); resize: vertical;
}
label { color: var(--text-2); }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form input[type="text"] { flex: 1 1 220px; }
form { margin: 0; }
.toggle { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--radius); color: var(--text-2); font-size: var(--fs-12); cursor: pointer; user-select: none; }
.toggle:hover { color: var(--text); }
.toggle:has(input:checked) { background: var(--surface-3); color: var(--text); }
.toggle:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------------------------------------------------------------- surfaces */

.card, .panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1); min-width: 0;
}
.card { padding: 16px; margin-bottom: 16px; scroll-margin-top: 24px; }
.card-narrow { max-width: 760px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 28px; flex-wrap: wrap; }
.card-title { font-size: var(--fs-14); font-weight: 600; }
.card > .card-title { margin-bottom: 8px; }
.card-sub { color: var(--text-2); margin: 4px 0 12px; max-width: 80ch; }
.card-danger { border-color: color-mix(in srgb, var(--danger) 28%, var(--border)); }
.card-danger .card-sub { margin-bottom: 0; }
.card .list-flush { margin: 12px -16px -16px; border-top: 1px solid var(--border); }
.card .inline-form + .list-flush { margin-top: 16px; }

.panel { margin-bottom: 16px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; min-height: 44px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.panel-title { font-size: var(--fs-13); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-title .num { font-weight: 500; }
.panel-body { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.panel-empty { padding: 16px; color: var(--text-3); }
.panel-foot { padding: 8px 16px; border-top: 1px solid var(--border); color: var(--text-3); }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); margin-bottom: 24px; overflow: hidden; }
.list-flush { border: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg); box-shadow: none; margin: 0; }
.row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 16px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row-link:hover { background: var(--surface-2); }
.row-main { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: var(--text-3); font-size: var(--fs-12); white-space: nowrap; }
.row-meta.truncate { flex: 0 1 280px; }
.row-sub { color: var(--text-3); font-size: var(--fs-12); line-height: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-action-spacer { width: 60px; flex: none; }
.team-text { display: flex; flex-direction: column; min-width: 0; }
.team-list .row { min-height: 56px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px; border-radius: 4px;
  font-size: var(--fs-12); font-weight: 500; white-space: nowrap; background: var(--surface-3); color: var(--text-2);
}
.badge-plan { background: var(--accent-bg); color: var(--accent-text); text-transform: capitalize; }
.badge-role { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }
.badge-pending { background: var(--accent-bg); color: var(--accent-text); }
.badge-ok { background: var(--ok-bg); color: var(--ok-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); }
.badge-outline.badge-ok { color: var(--ok-text); }
.badge-outline.badge-warn { color: var(--warn-text); box-shadow: inset 0 0 0 1px var(--warn-border); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--add-text); flex: none; }
.count-pill { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent-bg); color: var(--accent-text); font-size: var(--fs-12); font-weight: 600; }
.plan { text-transform: capitalize; }

.live { position: relative; display: inline-block; width: 8px; height: 8px; flex: none; }
.live::before { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--add-text); }
.live::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 1px solid var(--add-text); opacity: 0; animation: ping 2.4s ease-out infinite; }
@keyframes ping { 0% { transform: scale(0.6); opacity: 0.6; } 80%, 100% { transform: scale(1.4); opacity: 0; } }

.agent { display: inline-flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; }
.agent-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; flex: none; }

.notice { padding: 10px 12px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 16px; color: var(--text-2); }
.notice-error { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); color: var(--text); }

.reveal { margin: 0 0 16px; padding: 12px; border-radius: var(--radius); border: 1px solid var(--warn-border); background: var(--warn-bg); }
.reveal-title { font-weight: 600; margin-bottom: 8px; }
.reveal-row { display: flex; gap: 8px; }
.reveal-value { flex: 1; min-width: 0; font-family: var(--mono); font-size: var(--fs-12); }
.reveal .fine { margin-top: 8px; color: var(--text-2); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 12px 0 16px; }
.stats div { padding: 8px 12px; border-radius: var(--radius); background: var(--surface-2); min-width: 0; }
.stats dt { color: var(--text-3); font-size: var(--fs-12); }
.stats dd { font-weight: 600; font-variant-numeric: tabular-nums; }
.billing-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.facts { display: grid; grid-template-columns: 140px minmax(0, 1fr); margin-top: 8px; }
.facts > div { display: contents; }
.facts dt, .facts dd { padding: 8px 0; border-top: 1px solid var(--border); }
.facts > div:first-child dt, .facts > div:first-child dd { border-top: 0; }
.facts dt { color: var(--text-3); }
.facts dd { min-width: 0; overflow-wrap: anywhere; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.empty { padding: 40px 24px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); margin-bottom: 24px; }
.empty-title { font-size: var(--fs-14); font-weight: 600; margin-bottom: 4px; }
.empty .muted { max-width: 60ch; margin: 0 auto; }
.empty .code-wrap, .empty > .code { text-align: left; margin: 16px auto 0; max-width: 560px; }
.empty-actions { margin-top: 16px; }

.code code { background: none; padding: 0; border-radius: 0; color: inherit; }
.code { padding: 12px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); overflow-x: auto; line-height: 20px; white-space: pre; }
.code-wrap { position: relative; margin-top: 8px; }
.code-wrap .code { padding-right: 72px; }
.code-copy { position: absolute; top: 8px; right: 8px; }
.howto { margin-top: 12px; }
.howto summary { cursor: pointer; color: var(--text-2); font-weight: 500; width: fit-content; border-radius: 4px; }
.howto summary:hover { color: var(--text); }
.howto .code, .howto .code-wrap { margin-top: 8px; }

/* Segmented control that switches panels: radio buttons and :has, no script. */
.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--radius); background: var(--surface-3); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg-item { padding: 0 10px; height: 28px; display: inline-flex; align-items: center; gap: 6px; border-radius: 4px; color: var(--text-2); font-weight: 500; white-space: nowrap; cursor: pointer; }
.seg-item:hover { color: var(--text); }
.seg-item[aria-current], .seg-item:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.seg-item:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }
.seg-quiet { background: transparent; border: 1px solid var(--border); }
.seg-quiet .seg-item { height: 24px; padding: 0 8px; font-size: var(--fs-12); }
.seg-quiet .seg-item[aria-current] { background: var(--surface-3); box-shadow: none; }
nav.seg { margin-bottom: 16px; }

.switch-panels { margin-top: 12px; }
.segpanels > .switch-panels > .switch-panel { display: none; }
.segpanels:has(> .seg > .seg-item:nth-child(1) > input:checked) > .switch-panels > .switch-panel:nth-child(1),
.segpanels:has(> .seg > .seg-item:nth-child(2) > input:checked) > .switch-panels > .switch-panel:nth-child(2),
.segpanels:has(> .seg > .seg-item:nth-child(3) > input:checked) > .switch-panels > .switch-panel:nth-child(3),
.segpanels:has(> .seg > .seg-item:nth-child(4) > input:checked) > .switch-panels > .switch-panel:nth-child(4),
.segpanels:has(> .seg > .seg-item:nth-child(5) > input:checked) > .switch-panels > .switch-panel:nth-child(5) { display: block; }
@supports not selector(:has(*)) {
  .segpanels > .switch-panels > .switch-panel { display: block; margin-bottom: 16px; }
}
.segpanels .segpanels { margin-top: 16px; }

/* Settings: Storage, the fields of the chosen provider only. */
.storage-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; margin-top: 12px; }
.storage-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.storage-field input, .storage-field select { width: 100%; }
.storage-field .fine { margin-top: 0; }
.storage-provider { grid-column: 1 / -1; max-width: 320px; }
.storage-secrets { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; margin: 0; padding: 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); }
.storage-secrets legend { padding: 0 4px; color: var(--text-2); }
.storage-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.storage-actions .fine { margin-top: 0; }
.storage-move { margin-top: 12px; display: grid; gap: 8px; }
.storage-move progress { width: 100%; height: 8px; accent-color: var(--accent); }
.storage-form .no-has { display: none; }
.storage-form:has(#storage-provider option[value="s3"]:checked) [data-only]:not([data-only~="s3"]),
.storage-form:has(#storage-provider option[value="r2"]:checked) [data-only]:not([data-only~="r2"]),
.storage-form:has(#storage-provider option[value="gcs"]:checked) [data-only]:not([data-only~="gcs"]),
.storage-form:has(#storage-provider option[value="azure"]:checked) [data-only]:not([data-only~="azure"]) { display: none; }
@supports not selector(:has(*)) {
  .storage-form label > [data-only] { display: none; }
  .storage-form .no-has { display: inline; }
}

.token-form .howto .fine { margin-top: 8px; }
.connector-form { margin-top: 12px; }
.connector-form input[type="password"] { flex: 1 1 260px; }
.connector-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.scope-rows { display: grid; gap: 8px; margin-top: 8px; }
.scope-list { display: inline-flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.scope-list .badge { font-size: var(--fs-11); max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

.auth { max-width: 400px; margin: 64px auto 0; display: flex; flex-direction: column; gap: 16px; }
.auth h1 { font-size: var(--fs-20); line-height: 28px; font-weight: 600; letter-spacing: -0.015em; }
.empty-page { max-width: 480px; margin: 64px auto 0; display: flex; flex-direction: column; gap: 12px; }
.empty-page h1 { font-size: var(--fs-20); font-weight: 600; }

/* ---------------------------------------------------------------- overview */

.overview { display: grid; grid-template-columns: minmax(0, 1fr) 344px; gap: 16px 24px; align-items: start; }
.ov-main, .ov-side { min-width: 0; }

.items > li + li, .feed > li + li, .plain-list > li + li { border-top: 1px solid var(--border); }
.item-link { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-width: 0; }
a.item-link:hover { background: var(--surface-2); }
.item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.item-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; color: var(--text-3); font-size: var(--fs-12); min-width: 0; }
.item-meta .sep { color: var(--border-strong); }
.item-side { display: flex; align-items: center; gap: 8px; flex: none; color: var(--text-3); font-size: var(--fs-12); }

.feed-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 8px 16px; }
.feed-what { min-width: 0; overflow-wrap: anywhere; }
.feed-row > time { color: var(--text-3); font-size: var(--fs-12); white-space: nowrap; flex: none; }
.feed-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); overflow: hidden; }

.plain-row { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 16px; min-width: 0; }
.plain-row .icon { color: var(--text-3); }
.plain-row > time { color: var(--text-3); font-size: var(--fs-12); white-space: nowrap; flex: none; }
.plain-main { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plain-main > .agent { flex: none; max-width: 60%; }
.plain-main > .truncate { flex: 1; }
.step-dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--border-strong); flex: none; }

.share { color: var(--text-2); display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.share-num { font-size: var(--fs-24); line-height: 28px; font-weight: 600; letter-spacing: -0.02em; color: var(--text); }

/* The setup checklist. */
.steps-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.step { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 16px; padding: 20px; }
.step + .step { border-top: 1px solid var(--border); }
.step-mark { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); font: 600 var(--fs-12)/1 var(--font); font-variant-numeric: tabular-nums; }
.step.is-done .step-mark { background: var(--ok-bg); color: var(--ok-text); }
.step-mark .icon { width: 14px; height: 14px; }
.step-body { min-width: 0; }
.step-title { font-size: var(--fs-14); line-height: 24px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.step.is-done .step-title { color: var(--text-2); }
.step-text { color: var(--text-2); margin-top: 2px; max-width: 72ch; }
.step.is-done .step-text { color: var(--text-3); }
.step-action { margin-top: 12px; max-width: 640px; }
.step-action .code-wrap { margin-top: 0; }

/* ---------------------------------------------------------------- settings */

.settings { display: grid; grid-template-columns: 184px minmax(0, 1fr); gap: 32px; align-items: start; }
.subnav { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 2px; }
.subnav-item { display: flex; align-items: center; height: 32px; padding: 0 8px; border-radius: var(--radius); color: var(--text-2); font-weight: 500; white-space: nowrap; }
.subnav-item:hover { background: var(--surface-2); color: var(--text); }
.subnav-item[aria-current] { background: var(--surface-3); color: var(--text); }
.settings-body { min-width: 0; max-width: 760px; }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table thead th { text-align: left; font-weight: 500; color: var(--text-3); font-size: var(--fs-12); padding: 8px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody th { text-align: left; font-weight: 400; }
.table tbody th, .table td { padding: 10px 16px; border-top: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table tbody tr:first-child th, .table tbody tr:first-child td { border-top: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table a.strong:hover { text-decoration: underline; text-underline-offset: 2px; }
.table td.truncate { max-width: 320px; }
.table .num { text-align: right; }
.table th .sha { margin-left: 8px; }
.table .cell-action { text-align: right; width: 1%; }
.cell-run { max-width: 0; width: 50%; }
.run-link { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-intent { font-weight: 500; color: var(--text); }
.run-link:hover .run-intent { text-decoration: underline; text-underline-offset: 2px; }
.run-sub { display: flex; align-items: center; gap: 8px; margin-top: 2px; font-size: var(--fs-12); min-width: 0; }
.run-sub .agent-name { font-weight: 400; color: var(--text-2); }
.delta { font-family: var(--mono); font-size: var(--fs-12); white-space: nowrap; font-variant-numeric: tabular-nums; }
.plus { color: var(--add-text); }
.minus { color: var(--del-text); }

/* ---------------------------------------------------------------- run */

.run-bar {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap;
  margin: 0 -8px; padding: 12px 8px;
  background: var(--bg); border-bottom: 1px solid transparent;
}
.run-bar-main { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 320px; }
.run-title { font-size: var(--fs-20); line-height: 28px; font-weight: 600; letter-spacing: -0.015em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-bar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.run-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; color: var(--text-2); margin-top: 4px; }
.run-meta .live { margin-right: 2px; }
.review-panel { margin-top: 16px; }
.review-panel .panel-body > p { max-width: 80ch; }
.review-panel .fine { margin-top: 0; }
.pulls { display: flex; align-items: flex-start; gap: 8px; }
.pulls .icon { color: var(--text-3); margin-top: 2px; }
.review-form label { display: block; margin-bottom: 4px; color: var(--text-2); font-size: var(--fs-12); }
.review-form textarea { min-height: 56px; }

.turns { position: relative; padding: 4px 0; }
.turns li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 12px; padding: 8px 16px; align-items: start; position: relative; }
.turns li::before { content: ""; position: absolute; left: 27px; top: 0; bottom: 0; width: 1px; background: var(--border); }
.turns li:first-child::before { top: 16px; }
.turns li:last-child::before { bottom: calc(100% - 16px); }
.turns li:only-child::before { display: none; }
.turn-n { position: relative; z-index: 1; width: 24px; height: 20px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); font: 600 var(--fs-11)/1 var(--font); font-variant-numeric: tabular-nums; }
.turn-body { min-width: 0; }
.turn-intent { color: var(--text); overflow-wrap: anywhere; }
.turn-intent::before { content: "\201C"; color: var(--text-3); }
.turn-intent::after { content: "\201D"; color: var(--text-3); }
.turn-side { color: var(--text-3); font-size: var(--fs-12); white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: 4px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  font: var(--fs-12)/1 var(--mono); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
a.chip:hover { color: var(--text); border-color: var(--border-strong); }

.files-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin: 32px 0 8px; }
.files-head .section-title { margin: 0; }
.changes { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; }
.changes.single { grid-template-columns: minmax(0, 1fr); }
.ftree { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; padding: 4px; margin: 0; }
.ftree a { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 4px 8px; border-radius: var(--radius); color: var(--text-2); }
.ftree a:hover { background: var(--surface-2); color: var(--text); }
.ftree .icon { width: 14px; height: 14px; color: var(--text-3); }
.ftree .p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; font: var(--fs-12)/20px var(--mono); }
.ftree .p bdi { direction: ltr; }
.file-list { min-width: 0; }

.file { margin-bottom: 16px; scroll-margin-top: 72px; }
.file-head {
  display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px 0 8px; cursor: pointer; list-style: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.file-head::-webkit-details-marker { display: none; }
.file:not([open]) .file-head { border-bottom: 0; }
.file-head .chev { color: var(--text-3); transition: transform 120ms ease; }
.file:not([open]) .file-head .chev { transform: rotate(-90deg); }
.file-head:hover .file-path { text-decoration: underline; text-underline-offset: 2px; }
.file-path { font: 500 var(--fs-12)/20px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.file-meta { display: inline-flex; gap: 8px; align-items: center; flex: none; }
.file-note { padding: 8px 16px; font-size: var(--fs-12); color: var(--text-2); background: var(--surface-2); }

/* Diffs, as the desk draws them. */
.diff { overflow-x: auto; background: var(--surface); }
.diff table { border-collapse: collapse; width: 100%; font: var(--fs-12)/20px var(--mono); font-variant-ligatures: none; }
.diff td { padding: 0; vertical-align: top; }
.diff .ln {
  width: 1%; min-width: 44px; padding: 0 8px; text-align: right; color: var(--text-3); user-select: none; white-space: nowrap;
  position: sticky; left: 0; background: var(--surface); font-variant-numeric: tabular-nums;
}
.diff .ln + .ln { left: 44px; }
.diff .src { white-space: pre; padding-right: 16px; tab-size: 2; }
.diff .sign { display: inline-block; width: 24px; padding-left: 8px; user-select: none; color: var(--text-3); }
.diff tr.add td { background: var(--add-bg); }
.diff tr.add .ln { background: color-mix(in srgb, var(--add-strong) 60%, var(--surface)); color: var(--text-2); }
.diff tr.add .sign { color: var(--add-text); }
.diff tr.del td { background: var(--del-bg); }
.diff tr.del .ln { background: color-mix(in srgb, var(--del-strong) 60%, var(--surface)); color: var(--text-2); }
.diff tr.del .sign { color: var(--del-text); }
.diff tr.hunk td { background: var(--surface-2); color: var(--text-3); padding: 4px 8px; }
:root:has(#wrap-lines:checked) .diff .src { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- reports */

.k-claude-code { fill: var(--k1); background: var(--k1); }
.k-codex { fill: var(--k2); background: var(--k2); }
.k-cursor { fill: var(--k3); background: var(--k3); }
.k-mcp { fill: var(--k4); background: var(--k4); }
.k-http { fill: var(--k5); background: var(--k5); }
.k-other { fill: var(--k6); background: var(--k6); }
.k-ai { fill: var(--k1); background: var(--k1); }
.k-unknown, .k-human { fill: var(--k-unknown); background: var(--k-unknown); }
.k-pending, .k-blocks { fill: var(--k-pending); background: var(--k-pending); }
.k-rejected { fill: var(--k-rejected); background: var(--k-rejected); }
.k-conflicts { fill: var(--k6); background: var(--k6); }
.k-approved { fill: var(--k-approved); background: var(--k-approved); }

.rbar { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 12px; }
.rbar > nav.seg { margin-bottom: 0; }
.rbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.filters { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.filters label { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--text-3); }
.filters input[type="date"], .filters select { height: 28px; padding: 0 8px; font-size: var(--fs-12); border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); min-width: 0; }
.filters select { max-width: 200px; }
.filters input[type="date"]:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }

.coverage { display: flex; flex-wrap: wrap; gap: 4px 0; color: var(--text-3); font-size: var(--fs-12); margin-bottom: 16px; }
.coverage > span + span::before { content: "·"; margin: 0 8px; color: var(--border-strong); }
.coverage b { color: var(--text-2); font-weight: 500; }
.warn-text { color: var(--warn-text); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.kpi { padding: 12px 16px; min-width: 0; border-left: 1px solid var(--border); }
.kpi:first-child { border-left: 0; }
.kpi dt { color: var(--text-3); font-size: var(--fs-12); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi dd { display: flex; flex-direction: column; }
.kpi-v { font-size: var(--fs-24); line-height: 30px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-s { color: var(--text-3); font-size: var(--fs-12); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chart-card { padding-bottom: 8px; }
.chart-card.flush { padding: 0; overflow: hidden; }
.chart-card.flush .card-head { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chart { margin: 12px 0 0; }
.chart-grid { display: grid; grid-template-columns: 40px minmax(0, 1fr); }
.chart svg { display: block; overflow: visible; }
.chart text { font: var(--fs-11) var(--font); fill: var(--text-3); font-variant-numeric: tabular-nums; }
.chart line.grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart line.base { stroke: var(--border-strong); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .col:hover .hit { fill: var(--surface-2); }
.segbar .gap { fill: var(--surface); }
.segbar .track, .hbar .track { fill: var(--surface-3); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--text-2); font-size: var(--fs-12); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }

.table-scroll { overflow-x: auto; }
.table-dense tbody th, .table-dense td { padding-top: 6px; padding-bottom: 6px; }
.table td.wrap { white-space: normal; }
.table th.truncate { max-width: 380px; }
.bar-table { margin: 0; }
.bar-col { width: 28%; min-width: 120px; }
.hbar { display: block; }
.intent { display: block; font-size: var(--fs-12); max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.row-dim th, .row-dim td { color: var(--text-3); }

.caveats { margin-top: 8px; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); color: var(--text-2); }
.caveats summary { cursor: pointer; font-weight: 500; color: var(--text); }
.caveats ul { list-style: disc; padding-left: 18px; margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.empty-ok { border-style: solid; }

.teaser { padding: 20px; }
.teaser-big { font-size: var(--fs-14); line-height: 22px; color: var(--text-2); margin: 4px 0 8px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.teaser-num { font-size: var(--fs-display); line-height: 44px; font-weight: 600; letter-spacing: -0.03em; color: var(--text); font-variant-numeric: tabular-nums; }
.upgrade .price { color: var(--text-2); }
.upgrade .price b { color: var(--text); font-size: var(--fs-14); }
.checks { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 16px; }
.checks li { position: relative; padding-left: 20px; color: var(--text-2); }
.checks li::before { content: ""; position: absolute; left: 2px; top: 6px; width: 10px; height: 6px; border-left: 2px solid var(--ok-text); border-bottom: 2px solid var(--ok-text); transform: rotate(-45deg); }
.checks b { color: var(--text); font-weight: 500; }
.policy-sub { margin: 20px 0 8px; }
.steps { list-style: decimal; padding-left: 20px; margin: 6px 0 8px; }
.steps li { margin: 2px 0; }

.tip { position: fixed; z-index: 60; pointer-events: none; max-width: 280px; padding: 6px 8px; border-radius: var(--radius); background: var(--text); color: var(--bg); font-size: var(--fs-12); line-height: 16px; box-shadow: var(--shadow-1); }
.tip[hidden] { display: none; }

/* ---------------------------------------------------------------- dialogs: palette and shortcuts */

dialog {
  padding: 0; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-pop); width: min(560px, calc(100vw - 32px)); max-height: min(640px, calc(100vh - 64px));
}
dialog::backdrop { background: rgb(10 10 8 / 0.42); }
.dlg { display: flex; flex-direction: column; max-height: inherit; }
.dlg-head { padding: 20px 24px 12px; }
.dlg-title { font-size: var(--fs-16); line-height: 24px; font-weight: 600; }
.dlg-lead { color: var(--text-2); margin-top: 4px; }
.dlg-body { padding: 0 24px 16px; overflow-y: auto; min-height: 0; }
.dlg-foot { padding: 12px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; background: var(--surface-2); border-radius: 0 0 12px 12px; }

.palette { width: min(600px, calc(100vw - 24px)); margin-top: 12vh; }
.palette-input { display: flex; align-items: center; gap: 8px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.palette-input input { flex: 1; height: 48px; border: 0; background: transparent; font-size: var(--fs-16); outline: none; min-width: 0; padding: 0; }
.palette-input input:focus-visible { outline: none; }
.palette-list { max-height: min(420px, 60vh); overflow-y: auto; padding: 4px; }
.palette-group { padding: 8px 12px 4px; font-size: var(--fs-12); font-weight: 600; color: var(--text-3); }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 0 12px; min-height: 36px; border-radius: var(--radius); cursor: pointer; }
.palette-item .main-l { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .sub { color: var(--text-3); font-size: var(--fs-12); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }
.palette-item[aria-selected="true"] { background: var(--surface-3); }
.palette-empty { padding: 24px; text-align: center; color: var(--text-3); }
.palette-foot { display: flex; gap: 16px; padding: 8px 16px; border-top: 1px solid var(--border); color: var(--text-3); font-size: var(--fs-12); }
.palette-foot span, .keys-k { display: inline-flex; gap: 4px; align-items: center; flex: none; }

.keys { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.keys h3 { font-size: var(--fs-12); font-weight: 600; color: var(--text-3); margin-bottom: 8px; }
.keys li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1200px) {
  .changes { grid-template-columns: minmax(0, 1fr); }
  .ftree { position: static; max-height: 200px; }
}

@media (max-width: 1080px) {
  .overview { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 4px; position: sticky; top: 0; z-index: 20;
    height: 48px; padding: 0 8px 0 12px;
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
  }
  .topbar .brand { padding: 0 4px; }
  .topbar-team { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mnav[open] > summary { background: var(--surface-3); color: var(--text); }
  .menu-sheet { position: fixed; top: 52px; left: 8px; right: 8px; width: auto; max-height: calc(100vh - 64px); padding: 8px; }
  .menu-sheet .nav { gap: 2px; }
  .menu-sheet .me { padding: 4px 8px; }
  html { scroll-padding-top: 64px; }
  .run-bar { top: 48px; }
  .ftree { top: 120px; }
  .file { scroll-margin-top: 120px; }
  .card { scroll-margin-top: 112px; }
  .settings { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .subnav {
    top: 48px; z-index: 3; flex-direction: row; overflow-x: auto; scrollbar-width: none;
    margin: 0 -16px; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--border);
  }
  .subnav-item { height: 28px; flex: none; }
}

@media (max-width: 640px) {
  .top { padding: 0 16px; }
  .top .login { display: none; }
  /* The page heading says where you are: keep only the brand and the team. */
  .top .crumbs > .slash ~ .slash, .top .crumbs > .slash ~ .slash ~ * { display: none; }
  .wrap { padding: 16px 16px 64px; }
  .hide-sm { display: none; }
  .row { flex-wrap: wrap; gap: 4px 8px; }
  .row-main { flex: 1 1 0; }
  .row-meta, .row-meta.truncate { order: 3; flex: 1 1 100%; }
  .row-main > .muted { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .row-title { flex: 0 1 auto; min-width: 0; }
  .row-action-spacer { display: none; }
  .team-list .row { flex-wrap: nowrap; }
  .team-list .badge-plan { display: none; }
  .table tbody th, .table td, .table thead th { padding-left: 12px; padding-right: 12px; }
  .table td.truncate { max-width: 160px; }
  .cell-run { width: auto; max-width: 180px; }
  .auth, .empty-page { margin-top: 32px; }
  .reveal-row { flex-direction: column; }
  .file-head { flex-wrap: wrap; padding: 6px 12px 6px 8px; }
  .file-meta { margin-left: 24px; }
  .page-head h1, .run-title { font-size: var(--fs-20); line-height: 26px; }
  .run-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .run-bar-actions .btn { flex: 1; }
  .run-bar-actions { width: 100%; }
  .turns li { grid-template-columns: 24px minmax(0, 1fr); padding: 8px 12px; }
  .turns li::before { left: 23px; }
  .turn-side { grid-column: 2; }
  .facts { grid-template-columns: 104px minmax(0, 1fr); }
  .item-link { align-items: flex-start; }
  .item-side { flex-direction: column; align-items: flex-end; gap: 4px; }
  .step { gap: 12px; padding: 16px; }
  .code-wrap .code { padding-right: 12px; padding-top: 40px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(3) { border-left: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--border); }
  .kpi-v { font-size: var(--fs-20); line-height: 26px; }
  .rbar, .rbar-right { width: 100%; }
  .rbar > .seg { width: 100%; }
  .rbar > .seg .seg-item { flex: 1; justify-content: center; padding: 0 6px; }
  .rbar-right { justify-content: space-between; }
  .filters label { flex: 1 1 140px; }
  .filters input[type="date"], .filters select { flex: 1; max-width: none; }
  .bar-col { min-width: 0; }
  .table th.truncate, .intent { max-width: 150px; }
  .coverage { gap: 2px 12px; }
  .coverage > span + span::before { content: none; }
  .teaser-num { font-size: var(--fs-display-sm); line-height: 36px; }
  .keys { grid-template-columns: minmax(0, 1fr); }
  .diff .ln { min-width: 36px; padding: 0 6px; }
  .diff .ln + .ln { left: 36px; }
}

@media (hover: none) {
  .search-btn kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .live::after { display: none; }
}

/* ---------------------------------------------------------------- motion and waiting states
   Durations and easing from tokens.css. Transform and opacity only; under
   prefers-reduced-motion everything above collapses to an instant change. */

@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes nav-progress { from { transform: scaleX(0); } 60% { transform: scaleX(0.72); } to { transform: scaleX(0.92); } }

/* Menus and dialogs open with a short drop and fade. */
details[data-menu][open] > .menu { animation: pop-in var(--dur) var(--ease-out); transform-origin: top left; }
dialog[open] { animation: pop-in var(--dur) var(--ease-out); }
dialog[open]::backdrop { animation: fade-in var(--dur) var(--ease-out); }

/* Tab panels, segmented switches and opened diff files fade in. */
.segpanels > .switch-panels > .switch-panel { animation: fade-in var(--dur) var(--ease-out); }
.file[open] > .file-head ~ * { animation: fade-in var(--dur) var(--ease-out); }
.howto[open] > summary ~ * { animation: fade-in var(--dur) var(--ease-out); }
.file-head .chev { transition: transform var(--dur-fast) var(--ease-out); }

/* Notices, reveals and the duplicate-name hint arrive like the desk's toasts. */
.notice, .reveal, #team-name-dup:not([hidden]) { animation: rise-in var(--dur) var(--ease-out); }

/* The copy button confirms. */
.code-copy.is-done, [data-copy].is-done { color: var(--ok-text); border-color: color-mix(in srgb, var(--ok-text) 35%, var(--border-strong)); }
.code-copy, [data-copy] { transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out); }

/* Interactive surfaces share one quick transition. */
.nav-item, .subnav-item, .menu-item, .seg-item, .tab, .item-link, .row-link, .table tbody tr, .palette-item, .search-btn, .switch, .ftree a, .chip, .toggle {
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

/* A submitted form: its button says what is happening, shows a spinner and
   takes no second click (hub.js sets aria-busy). */
.btn[aria-busy="true"] { cursor: progress; pointer-events: none; opacity: 0.85; }
.btn[aria-busy="true"]::before {
  content: ""; width: 12px; height: 12px; flex: none; border-radius: 50%;
  border: 1.5px solid currentColor; border-right-color: transparent;
  animation: spin 700ms linear infinite;
}
.btn[aria-busy="true"] > .icon { display: none; }
form[aria-busy="true"] .btn:not([aria-busy="true"]) { opacity: 0.55; pointer-events: none; }

/* Navigation: a thin bar at the top while the next page loads (shown after
   a short delay, so fast pages never flash it). */
.nav-progress {
  position: fixed; z-index: 100; top: 0; left: 0; right: 0; height: 2px; pointer-events: none;
  background: var(--accent); transform-origin: left; transform: scaleX(0); opacity: 0;
}
.nav-progress.is-on { opacity: 1; animation: nav-progress 8s var(--ease-out) forwards; }
.nav-progress.is-done { opacity: 0; transform: scaleX(1); transition: transform var(--dur) var(--ease-out), opacity var(--dur-slow) var(--ease-out) var(--dur); }

/* The skeleton the desk uses, for anything the hub fills in later. */
.sk { display: block; height: 12px; border-radius: 4px; background: var(--surface-3); position: relative; overflow: hidden; }
.sk::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 60%, transparent), transparent); animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

@media (prefers-reduced-motion: reduce) {
  .nav-progress.is-on { animation: none; transform: scaleX(0.6); }
  .btn[aria-busy="true"]::before { animation: none; border-right-color: currentColor; opacity: 0.6; }
}

/* ---------------------------------------------------------------- profile menu (sidebar foot) */
.profile { position: relative; }
.profile > summary { list-style: none; }
.profile > summary::-webkit-details-marker { display: none; }
.profile-btn { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 4px 8px; border-radius: var(--radius); cursor: pointer; color: var(--text-2); }
.profile-btn:hover, .profile[open] .profile-btn { background: var(--surface-2); color: var(--text); }
.profile-btn .login { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.menu-up { top: auto; bottom: calc(100% + 4px); }
.profile-menu { width: 100%; min-width: 0; max-height: min(640px, 85vh); }
.profile-menu .menu-title { flex: 1; min-width: 0; }
.profile-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 36px 12px 16px; margin-bottom: 4px; border-radius: var(--radius); background: var(--surface-2); text-align: center; }
.profile-card .plan { position: absolute; top: 8px; left: 8px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); color: var(--accent-text); font-size: var(--fs-11); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.profile-card .avatar { width: 48px; height: 48px; margin-bottom: 6px; border-radius: 50%; }
.profile-card .avatar-blank { font-size: var(--fs-20); background: var(--surface-3); }
.profile-name { font-size: var(--fs-14); font-weight: 600; color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-sub { font-size: var(--fs-12); color: var(--text-3); }
.menu-item .menu-ext { margin-left: auto; width: 12px; height: 12px; }
.profile-foot { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 4px; }
.theme-seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: var(--radius); background: var(--surface-2); }
.theme-seg button { display: grid; place-items: center; width: 26px; height: 24px; border: 0; border-radius: calc(var(--radius) - 2px); background: none; color: var(--text-3); cursor: pointer; }
.theme-seg button:hover { color: var(--text); }
.theme-seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.signout { white-space: nowrap; flex: none; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px; border: 0; border-radius: var(--radius); background: none; color: var(--danger); font-weight: 500; cursor: pointer; }
.signout:hover { background: var(--surface-2); }

/* ---------------------------------------------------------------- Ask Grapim (src/hub/agent/, agent.js)
   A docked panel on the right, resizable like the sidebar; a full-screen
   sheet on phones. Motion: the motion tokens, transform and opacity (the
   steps list also eases its grid rows open), all off under reduced motion. */

:root { --agent-w: 400px; }

.ask-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 32px; padding: 0 8px; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius); background: none; color: var(--text-2); font-weight: 500;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.ask-btn:hover, .ask-btn[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.ask-btn .icon { color: var(--accent-text); }
.ask-btn span { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ask-btn kbd { height: 16px; min-width: 16px; font-size: var(--fs-11); border-bottom-width: 1px; color: var(--text-3); }
.ask-btn kbd + kbd { margin-left: -4px; }
.topbar .icon-btn[data-action="agent"] .icon { color: var(--accent-text); }

.ask-run .icon { color: var(--accent-text); }
.run-bar-review { display: inline-flex; gap: 8px; flex-wrap: wrap; }

/* The page makes room: a third grid column that eases open with the panel. */
.app:has(> .agent-panel) { grid-template-columns: var(--sidebar) minmax(0, 1fr) 0px; }
html[data-agent="open"] .app:has(> .agent-panel) { grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--agent-w); }
html[data-resizing] .app { transition: none; }

.agent-panel {
  grid-column: 3; grid-row: 1; position: sticky; top: 0; z-index: 10;
  width: var(--agent-w); height: 100vh; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--border);
}
.agent-panel[hidden] { display: none; }
.agent-panel:focus { outline: none; }
.agent-panel.is-in { animation: agent-in var(--dur-slow) var(--ease-out); }
.agent-panel.is-out { animation: agent-out var(--dur) var(--ease-out) forwards; pointer-events: none; }
@keyframes agent-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes agent-out { to { opacity: 0; transform: translateX(24px); } }

.agent-resize { position: absolute; top: 0; bottom: 0; left: -4px; width: 8px; z-index: 2; cursor: col-resize; touch-action: none; }
.agent-resize::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; background: var(--accent); opacity: 0; transition: opacity var(--dur-fast) var(--ease-out); }
.agent-resize:hover::after, html[data-resizing] .agent-resize::after { opacity: .6; transition-delay: 80ms; }
.agent-resize:focus-visible { outline: none; }
.agent-resize:focus-visible::after { opacity: 1; }

.agent-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 52px; padding: 0 8px 0 16px; border-bottom: 1px solid var(--border); flex: none; }
.agent-title { display: flex; align-items: center; gap: 8px; font-size: var(--fs-14); font-weight: 600; letter-spacing: -0.01em; }
.agent-mark { color: var(--accent-text); }
.agent-head-actions { display: flex; gap: 2px; }
.agent-icon-btn { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: var(--radius); background: none; color: var(--text-3); cursor: pointer; transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.agent-icon-btn:hover { background: var(--surface-2); color: var(--text); }
.agent-icon-btn:disabled { opacity: .4; cursor: default; background: none; }

.agent-body { position: relative; flex: 1; min-height: 0; display: flex; }
.agent-log { flex: 1; min-width: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.agent-log:focus-visible { outline-offset: -2px; }

.agent-jump {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text-2);
  font-size: var(--fs-12); font-weight: 500; box-shadow: var(--shadow-pop);
  animation: agent-jump-in var(--dur) var(--ease-out);
}
.agent-jump[hidden] { display: none; }
.agent-jump:hover { color: var(--text); }
.agent-jump .icon { width: 14px; height: 14px; }
@keyframes agent-jump-in { from { opacity: 0; transform: translate(-50%, 6px); } }

/* Empty, not set up, loading. */
.agent-empty { margin: auto 0; padding: 8px 4px 24px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.agent-empty-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-lg); background: var(--accent-bg); color: var(--accent-text); margin-bottom: 4px; }
.agent-empty-mark .icon { width: 18px; height: 18px; }
.agent-empty h3 { font-size: var(--fs-16); line-height: 24px; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
.agent-empty p { color: var(--text-2); max-width: 46ch; }
.agent-off .agent-empty-mark { background: var(--surface-2); color: var(--text-3); }
.agent-fine { font-size: var(--fs-12); line-height: 18px; color: var(--text-3); }
.agent-fine code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; color: var(--text); }
.agent-starters { display: flex; flex-direction: column; align-items: stretch; gap: 6px; width: 100%; margin-top: 12px; }
.agent-starter {
  --i: 0;
  text-align: left; min-height: 36px; padding: 8px 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow-1);
  animation: rise-in var(--dur-slow) var(--ease-out) both; animation-delay: calc(var(--i) * 35ms + 60ms);
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.agent-starter:hover { border-color: var(--border-strong); background: var(--surface-2); }
.agent-starter:active { transform: scale(0.985); }
.agent-loading { margin: auto 0; }

/* Messages. */
.ag-msg { min-width: 0; overflow-wrap: anywhere; }
.ag-msg.is-live { animation: rise-in var(--dur) var(--ease-out); }
.msg-user { align-self: flex-end; max-width: 88%; padding: 8px 12px; border-radius: 12px 12px 4px 12px; background: var(--surface-3); color: var(--text); white-space: pre-wrap; }
.msg-notice { display: flex; align-items: flex-start; gap: 8px; color: var(--text-3); font-size: var(--fs-12); line-height: 18px; }
.msg-notice .icon { width: 14px; height: 14px; margin-top: 2px; }
.msg-notice.notice-error, .msg-notice.notice-refusal { color: var(--danger); background: none; border: 0; padding: 0; margin: 0; }
.msg-notice.notice-limit { color: var(--warn-text); }
.msg-actions { display: flex; gap: 8px; }

/* Answers: compact prose. */
.agent-md { color: var(--text); line-height: 21px; }
.agent-md > * + *, .agent-md .md-done > * + *, .agent-md .md-done:not(:empty) + .md-open:not(:empty) { margin-top: 8px; }
.agent-md h3 { font-size: var(--fs-14); font-weight: 600; margin-top: 12px; }
.agent-md h4 { font-size: var(--fs-13); font-weight: 600; margin-top: 10px; }
.agent-md ul, .agent-md ol { padding-left: 20px; }
.agent-md ul { list-style: disc; }
.agent-md ol { list-style: decimal; }
.agent-md li + li { margin-top: 2px; }
.agent-md li::marker { color: var(--text-3); }
.agent-md code { font-size: var(--fs-12); background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.agent-md blockquote { padding-left: 12px; border-left: 1px solid var(--border-strong); color: var(--text-2); }
.agent-md a.link { color: var(--accent-text); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent-text) 35%, transparent); text-underline-offset: 2px; }
.agent-md a.link:hover { text-decoration-color: currentColor; }
.agent-table { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.agent-md table { border-collapse: collapse; width: 100%; font-size: var(--fs-12); font-variant-numeric: tabular-nums; }
.agent-md th, .agent-md td { text-align: left; padding: 6px 8px; border-top: 1px solid var(--border); vertical-align: top; }
.agent-md thead th { border-top: 0; color: var(--text-3); font-weight: 500; background: var(--surface-2); }
.agent-code-wrap { position: relative; }
.agent-code { margin: 0; padding: 10px 12px; padding-right: 64px; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: var(--fs-12); line-height: 18px; }
.agent-code code { background: none; padding: 0; white-space: pre; }
.agent-copy {
  position: absolute; top: 6px; right: 6px; height: 24px; padding: 0 8px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text-2); font-size: var(--fs-12); font-weight: 500;
  opacity: 0; transition: opacity var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.agent-code-wrap:hover .agent-copy, .agent-copy:focus-visible, .agent-copy.is-done { opacity: 1; }
.agent-copy.is-done { color: var(--ok-text); border-color: color-mix(in srgb, var(--ok-text) 35%, var(--border-strong)); }

/* Streaming: each new chunk fades in where it lands. */
.md-open { white-space: pre-wrap; }
.md-open:empty, .md-done:empty { display: none; }
.ag-tok { animation: fade-in var(--dur-slow) var(--ease-out); }

/* Before the first token: three soft dots and a shimmering label. */
.ag-thinking { display: flex; align-items: center; gap: 10px; height: 24px; color: var(--text-3); font-size: var(--fs-12); animation: fade-in var(--dur) var(--ease-out); }
.ag-dots { display: inline-flex; gap: 4px; }
.ag-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent-text); opacity: .25; animation: agent-dot 1.2s var(--ease-in-out) infinite; }
.ag-dots i:nth-child(2) { animation-delay: 160ms; }
.ag-dots i:nth-child(3) { animation-delay: 320ms; }
@keyframes agent-dot { 0%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
/* The shimmer is a soft band of the panel's background sweeping across the
   label (a transform, like the skeleton's), not coloured text. */
.ag-shimmer, .ag-step[data-status="running"] .ag-step-label { position: relative; overflow: hidden; color: var(--text-2); }
.ag-shimmer::after, .ag-step[data-status="running"] .ag-step-label::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--bg) 75%, transparent) 50%, transparent);
  transform: translateX(-100%); animation: agent-sweep 1.6s var(--ease-in-out) infinite;
}
@keyframes agent-sweep { to { transform: translateX(100%); } }

/* Tool steps: a row each while they run, then one line that opens. */
.ag-steps { display: flex; flex-direction: column; font-size: var(--fs-12); color: var(--text-2); }
.ag-steps.is-live { animation: fade-in var(--dur) var(--ease-out); }
.ag-steps-sum {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; max-width: 100%; height: 26px; padding: 0 8px 0 4px; margin-left: -4px;
  border: 0; border-radius: var(--radius); background: none; color: var(--text-3); cursor: pointer; font-weight: 500;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.ag-steps-sum:hover { background: var(--surface-2); color: var(--text); }
.ag-steps-sum-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-steps-chev { width: 12px; height: 12px; transition: transform var(--dur) var(--ease-out); }
.ag-steps.is-open .ag-steps-chev { transform: rotate(90deg); }
.ag-steps[data-state="running"] .ag-steps-sum { display: none; }
.ag-steps-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--dur-slow) var(--ease-out); }
.ag-steps.is-open .ag-steps-body { grid-template-rows: 1fr; }
.ag-steps-inner { min-height: 0; overflow: hidden; }
.ag-steps-list { display: flex; flex-direction: column; gap: 2px; padding: 2px 0; opacity: 0; transition: opacity var(--dur) var(--ease-out); }
.ag-steps.is-open .ag-steps-list { opacity: 1; }
.ag-steps[data-state="done"] .ag-steps-list { margin: 2px 0 0 5px; padding-left: 4px; border-left: 1px solid var(--border); }
.ag-step { display: flex; align-items: center; gap: 8px; min-height: 22px; padding-left: 4px; }
.ag-step.is-live { animation: rise-in var(--dur) var(--ease-out); }
.ag-step-mark { width: 14px; height: 14px; flex: none; display: grid; place-items: center; }
.ag-step-mark > * { grid-area: 1 / 1; transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out); }
.ag-step-mark .icon { width: 14px; height: 14px; opacity: 0; transform: scale(.6); }
.ag-step-check { color: var(--ok-text); }
.ag-step-x { color: var(--danger); }
.ag-spin { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid currentColor; border-right-color: transparent; opacity: .7; animation: spin 700ms linear infinite; }
.ag-step[data-status="done"] .ag-spin, .ag-step[data-status="error"] .ag-spin { opacity: 0; transform: scale(.6); }
.ag-step[data-status="done"] .ag-step-check, .ag-step[data-status="error"] .ag-step-x { opacity: 1; transform: none; }
.ag-step-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-step[data-status="error"] .ag-step-label { color: var(--danger); }

/* Action cards: what will happen, on what, as whom; Confirm or Cancel. */
.ag-act { padding: 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-1); transform-origin: 50% 0; transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out); }
.ag-act.is-live { animation: agent-card-in var(--dur-slow) var(--ease-out); }
@keyframes agent-card-in { from { opacity: 0; transform: translateY(4px) scale(.97); } }
.act-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.act-title { font-size: var(--fs-13); font-weight: 600; line-height: 20px; overflow-wrap: anywhere; }
.act-tag { flex: none; padding: 1px 6px; border-radius: 4px; background: var(--accent-bg); color: var(--accent-text); font-size: var(--fs-11); font-weight: 600; line-height: 16px; }
.act-effect { margin-top: 4px; color: var(--text-2); font-size: var(--fs-12); line-height: 18px; }
.act-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--border); font-size: var(--fs-12); line-height: 18px; }
.act-facts dt { color: var(--text-3); }
.act-facts dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.act-buttons { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.act-hint { color: var(--text-3); font-size: var(--fs-12); }
.act-ok .ag-spin { display: none; width: 10px; height: 10px; }
.act-ok[aria-busy="true"] { opacity: 1; }
.act-ok[aria-busy="true"] .ag-spin { display: block; }
.act-ok[aria-busy="true"]::before { content: none; }
.act-ok:disabled, .act-no:disabled { cursor: progress; }
.ag-act.is-pending { box-shadow: var(--shadow-1), 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-danger-solid:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.act-result { display: flex; align-items: flex-start; gap: 8px; margin-top: 12px; font-size: var(--fs-12); line-height: 18px; color: var(--text); }
.act-done-mark { width: 18px; height: 18px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--ok-bg); color: var(--ok-text); }
.act-done-mark .icon { width: 12px; height: 12px; }
.ag-act.is-confirmed .act-done-mark { animation: agent-check var(--dur-slow) var(--ease-out); }
.ag-act.is-confirmed .act-done-mark .icon { animation: agent-check-in var(--dur-slow) var(--ease-out) 60ms both; }
@keyframes agent-check { from { transform: scale(.4); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } }
@keyframes agent-check-in { from { transform: scale(.3) rotate(-20deg); opacity: 0; } }
.act-failed { color: var(--danger); }
.act-failed .icon { width: 14px; height: 14px; margin-top: 2px; }
.act-secret { display: flex; gap: 8px; margin-top: 10px; }
.act-secret .reveal-value { flex: 1; min-width: 0; height: 28px; font-size: var(--fs-12); }
.act-fine { margin-top: 6px; color: var(--text-3); font-size: var(--fs-12); line-height: 18px; }
.act-link { margin-top: 8px; font-size: var(--fs-12); }
.ag-act.is-leaving { opacity: 0; transform: scale(.98); }
.ag-act[data-status="cancelled"] { padding: 0; border-color: transparent; background: none; box-shadow: none; }
.ag-act.is-cancelled { animation: fade-in var(--dur) var(--ease-out); }
.act-line { display: flex; align-items: center; gap: 6px; color: var(--text-3); font-size: var(--fs-12); }
.act-line .icon { width: 12px; height: 12px; }

/* The composer. */
.agent-compose { flex: none; padding: 8px 12px 12px; background: var(--bg); }
.agent-field { border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-1); transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
.agent-field:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }
.agent-chip { display: inline-flex; align-items: center; gap: 6px; max-width: calc(100% - 16px); margin: 8px 8px 0; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: var(--fs-11); font-weight: 500; line-height: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-chip-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }
.agent-row { display: flex; align-items: flex-end; gap: 8px; padding: 4px 6px 6px 12px; }
.agent-input { flex: 1; min-width: 0; min-height: 32px; max-height: 160px; padding: 6px 0; border: 0; background: none; resize: none; font: 400 var(--fs-13)/20px var(--font); color: var(--text); }
.agent-input:focus-visible { outline: none; }
.agent-send {
  width: 32px; height: 32px; flex: none; display: grid; place-items: center; cursor: pointer;
  border: 0; border-radius: var(--radius); background: var(--accent); color: var(--on-accent);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.agent-send:hover { background: var(--accent-hover); }
.agent-send:active { transform: scale(.92); }
.agent-send-icons { display: grid; }
.agent-send-icons .icon { grid-area: 1 / 1; transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out); }
.agent-send .i-stop { opacity: 0; transform: scale(.5) rotate(-45deg); }
.agent-panel.is-busy .agent-send { background: var(--text); color: var(--bg); }
.agent-panel.is-busy .agent-send .i-send { opacity: 0; transform: translateY(-6px) scale(.6); }
.agent-panel.is-busy .agent-send .i-stop { opacity: 1; transform: none; }
.agent-foot { display: flex; flex-wrap: wrap; gap: 0 6px; margin-top: 6px; padding: 0 4px; color: var(--text-3); font-size: var(--fs-11); line-height: 16px; }
.agent-foot .sep { color: var(--border-strong); }

/* Phones: a full-screen sheet that slides up over the page. */
@media (max-width: 860px) {
  .app:has(> .agent-panel), html[data-agent="open"] .app:has(> .agent-panel) { grid-template-columns: minmax(0, 1fr); }
  .agent-panel { position: fixed; inset: 0; z-index: 70; grid-column: auto; width: auto; height: 100dvh; border-left: 0; }
  .agent-panel.is-in { animation: agent-sheet-in var(--dur-slow) var(--ease-out); }
  .agent-panel.is-out { animation: agent-sheet-out var(--dur) var(--ease-out) forwards; }
  .agent-resize { display: none; }
  .agent-head { height: 48px; padding-left: 12px; }
  .agent-log { padding: 12px 12px 20px; }
  .agent-compose { padding: 8px 8px max(8px, env(safe-area-inset-bottom)); }
  .agent-input { font-size: var(--fs-16); }
  .msg-user { max-width: 92%; }
}
@keyframes agent-sheet-in { from { transform: translateY(100%); } }
@keyframes agent-sheet-out { to { transform: translateY(100%); } }

@media (hover: none) {
  .ask-btn kbd { display: none; }
  .agent-copy { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .ag-dots i, .ag-spin { animation: none !important; }
  .ag-shimmer::after, .ag-step[data-status="running"] .ag-step-label::after { display: none; }
  .ag-dots i { opacity: .6; }
  .ag-steps-body, .ag-steps-list { transition: none; }
  .agent-starter, .ag-act.is-confirmed .act-done-mark .icon { animation: none; }
}
