/* ACDC v6 · components
 * Every class here has a matching helper in js/ui/components.js.
 * Screens compose these; screen CSS should only add layout.
 */

/* ---------- Icon ---------- */
.icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon[data-size='sm'] { width: 14px; height: 14px; }
.icon[data-size='lg'] { width: 20px; height: 20px; }

/* ---------- Status: glyph + word ---------- */
.status { display: inline-flex; align-items: center; gap: 7px; min-width: 0; color: var(--ink); white-space: nowrap; }
.status .glyph { width: 10px; height: 10px; color: var(--t-mark); fill: currentColor; stroke: none; overflow: visible; }
.status[data-tone='done'], .status[data-tone='idle'] { color: var(--ink-2); }
.status[data-tone='unknown'] { color: var(--ink-2); }
.status-note { color: var(--ink-3); font-weight: 400; }
.glyph-pulse { transform-origin: 50% 50%; transform-box: fill-box; animation: pulse 1.8s var(--ease) infinite; }
@keyframes pulse { 0% { opacity: 0.55; transform: scale(1); } 70%, 100% { opacity: 0; transform: scale(2.4); } }

/* ---------- Tag ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px;
  font-size: var(--text-xs); font-weight: 500; line-height: 1; white-space: nowrap;
  color: var(--t-ink, var(--ink-2)); background: var(--t-bg, var(--idle-bg));
  border: 1px solid var(--t-line, var(--idle-line)); border-radius: var(--r-sm);
}
.tag .icon { width: 12px; height: 12px; }
.tag[data-plain] { background: transparent; }

/* ---------- Record reference ---------- */
.ref {
  font-family: var(--font-mono); font-size: 0.92em; font-weight: 500; white-space: nowrap;
  color: var(--ref); border-radius: 3px; text-decoration: none;
}
.ref:hover { color: var(--ref-hover); text-decoration: underline; text-underline-offset: 3px; }
.ref-rev { font-weight: 400; }
/* A reference in a list of references is a target of its own: give it room */
.row-wrap > .ref { display: inline-flex; align-items: center; gap: 0.35em; min-width: 24px; min-height: 24px; }
.ref[data-plain] { color: inherit; }
.ref[data-historical] { color: var(--ink-3); }

/* ---------- People and agents ----------
 * Humans are round. Agents are square with a notch. The shape difference
 * survives greyscale, tiny sizes and colour-blind viewing.
 */
.actor { display: inline-flex; align-items: center; gap: 7px; min-width: 0; white-space: nowrap; }
.avatar {
  flex: none; display: inline-grid; place-items: center; width: 22px; height: 22px;
  font-size: 10.5px; font-weight: 600; line-height: 1; letter-spacing: 0;
  color: var(--ink-2); background: var(--sunken); border: 1px solid var(--line-2); border-radius: 50%;
}
.avatar[data-kind='agent'] {
  border-radius: 5px; font-family: var(--font-mono); font-size: 9px; font-weight: 600;
  color: var(--surface); background: var(--ink-2); border-color: transparent;
  clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 0 100%);
}
.avatar[data-size='sm'] { width: 18px; height: 18px; font-size: 9.5px; }
.avatar[data-size='lg'] { width: 28px; height: 28px; font-size: 12px; }
.avatar[data-self] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--accent-mark); }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { margin-left: -6px; box-shadow: 0 0 0 2px var(--surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }
.actor-note { color: var(--ink-3); }

/* ---------- Button ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: var(--control); padding: 0 12px; flex: none;
  font-size: var(--text-sm); font-weight: 500; line-height: 1; white-space: nowrap;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r-md);
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-4); text-decoration: none; color: var(--ink); }
.btn:active { transform: translateY(0.5px); }
.btn[data-variant='primary'] { color: var(--on-accent); background: var(--accent); border-color: transparent; font-weight: 600; }
.btn[data-variant='primary']:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn[data-variant='solid'] { color: var(--bg); background: var(--ink); border-color: transparent; }
.btn[data-variant='solid']:hover { background: var(--ink-2); color: var(--bg); }
.btn[data-variant='ghost'] { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn[data-variant='ghost']:hover { background: var(--sunken); color: var(--ink); }
.btn[data-variant='danger'] { color: var(--accent-ink); border-color: var(--accent-line); }
.btn[data-variant='danger']:hover { background: var(--accent-bg); }
.btn[data-size='sm'] { height: 26px; padding: 0 9px; font-size: var(--text-xs); }
.btn[data-size='lg'] { height: 38px; padding: 0 16px; font-size: var(--text-md); }
.btn[data-icon-only] { width: var(--control); padding: 0; }
.btn[data-icon-only][data-size='sm'] { width: 26px; }
.btn[aria-pressed='true']:not([data-variant='solid']) { background: var(--sunken); border-color: var(--line-2); color: var(--ink); }
.btn[aria-disabled='true'], .btn:disabled {
  cursor: not-allowed; color: var(--ink-3); background: var(--sunken); border-color: var(--line); border-style: dashed; box-shadow: none; transform: none;
}
.btn[data-variant='primary'][aria-disabled='true'] { background: var(--sunken); color: var(--ink-3); }
.btn kbd { margin-left: 2px; margin-right: -4px; }
.btn[data-variant='primary'] kbd, .btn[data-variant='solid'] kbd { color: inherit; background: rgba(255, 255, 255, 0.16); border-color: transparent; }
.btn-note { font-size: var(--text-xs); color: var(--ink-3); line-height: 1.35; }

.link-btn { color: var(--ref); font-weight: 500; font-size: inherit; display: inline-flex; align-items: center; gap: 4px; border-radius: 3px; }
.link-btn:hover { color: var(--ref-hover); text-decoration: underline; text-underline-offset: 2px; }
.link-btn .icon { width: 14px; height: 14px; }

/* ---------- Page scaffold ---------- */
.page { display: flex; flex-direction: column; min-height: 100%; }
.page-head { padding: var(--s6) var(--s8) 0; border-bottom: 1px solid var(--line); background: var(--bg); }
.page-head[data-flush] { padding-bottom: var(--s5); }
.page-title-row { display: flex; align-items: flex-start; gap: var(--s4); }
.page-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; min-width: 0; flex: 1 1 auto; }
.page-title h1 { font-size: var(--text-2xl); line-height: 1.2; letter-spacing: -0.02em; font-weight: 650; }
.page-id { font-family: var(--font-mono); font-size: var(--text-lg); font-weight: 500; color: var(--ink-3); letter-spacing: -0.01em; }
.page-actions { display: flex; align-items: center; gap: var(--s2); flex: none; }
.page-sub { margin-top: 4px; font-size: var(--text-lg); color: var(--ink-2); max-width: 76ch; }
.page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px var(--s5); margin-top: var(--s3); font-size: var(--text-sm); color: var(--ink-3); }
.page-meta > span { display: inline-flex; align-items: center; gap: 6px; }
.page-meta b { font-weight: 500; color: var(--ink); }
.page-head .tabs { margin-top: var(--s4); }
.page-head:not(:has(.tabs)) { padding-bottom: var(--s5); }

.page-body { display: grid; grid-template-columns: minmax(0, 1fr); flex: 1 1 auto; min-height: 0; }
.page-body[data-layout='with-inspector'] { grid-template-columns: minmax(0, 1fr) var(--inspector); }
.page-main { padding: var(--s6) var(--s8) var(--s10); display: flex; flex-direction: column; gap: var(--s8); min-width: 0; }
.page-main[data-narrow] { max-width: 920px; }
.inspector {
  padding: var(--s6) var(--s6) var(--s10); background: var(--surface); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; gap: var(--s6); min-width: 0;
}
.inspector .section-head h2 { font-size: var(--text-md); }
.inspector > * + * { padding-top: var(--s6); border-top: 1px solid var(--line); }

@media (max-width: 1180px) {
  .page-body[data-layout='with-inspector'] { grid-template-columns: minmax(0, 1fr); }
  .inspector { border-left: 0; border-top: 1px solid var(--line); padding: var(--s6) var(--s8) var(--s10); }
}
@media (max-width: 760px) {
  .page-head { padding: var(--s4) var(--s4) 0; }
  .page-main, .inspector { padding: var(--s5) var(--s4) var(--s8); gap: var(--s6); }
  .page-title h1 { font-size: 20px; }
  .page-title-row { flex-wrap: wrap; }
  .page-sub { font-size: var(--text-md); }
}

/* ---------- Section ---------- */
.section { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.section-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px var(--s3); min-height: 24px; }
.section-head h2 { font-size: var(--text-lg); line-height: 1.3; }
.section-head h3 { font-size: var(--text-md); line-height: 1.3; }
.section-count { font-size: var(--text-sm); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.section-note { font-size: var(--text-sm); color: var(--ink-3); }
.section-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s2); align-self: center; }
.section-foot { font-size: var(--text-sm); color: var(--ink-3); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--s5); overflow-x: auto; scrollbar-width: none; margin-bottom: -1px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 8px 1px 10px;
  font-size: var(--text-md); font-weight: 500; color: var(--ink-3); white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab:focus-visible, .path-node:focus-visible, .table tbody tr:focus-visible { outline-offset: -2px; }
.tab[aria-selected='true'], .tab[aria-current='page'] { color: var(--ink); border-bottom-color: var(--accent-mark); }
.tab-count { font-size: var(--text-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; font-weight: 400; }

/* ---------- Panel: the one bordered surface ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); min-width: 0; }
.panel-pad { padding: var(--s4); }
.panel-head { display: flex; align-items: center; gap: var(--s3); padding: 10px var(--s4); border-bottom: 1px solid var(--line); font-size: var(--text-sm); color: var(--ink-2); }
.panel-foot { padding: 10px var(--s4); border-top: 1px solid var(--line); font-size: var(--text-sm); color: var(--ink-3); }

/* ---------- Table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow-x: auto; min-width: 0; }
.table { font-size: var(--text-md); }
.table th {
  height: 32px; padding: 0 var(--s3); font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.02em; color: var(--ink-3);
  background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.table td { height: var(--row); padding: 6px var(--s3); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th:first-child, .table td:first-child { padding-left: var(--s4); }
.table th:last-child, .table td:last-child { padding-right: var(--s4); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.shrink, .table th.shrink { width: 1%; white-space: nowrap; }
.table td.wrap { white-space: normal; }
.table .cell-sub { display: block; font-size: var(--text-sm); color: var(--ink-3); line-height: 1.35; }
.table .cell-title { font-weight: 500; color: var(--ink); }
.table tbody tr { transition: background var(--fast) var(--ease); }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr[data-href]:hover, .table tbody tr:focus-within { background: var(--surface-2); }
.table tbody tr[data-href]:focus-visible { outline-offset: -2px; }
.table tbody tr[data-flag] { background: var(--t-bg); box-shadow: inset 3px 0 0 var(--t-mark); }
.table tbody tr[data-flag][data-href]:hover { background: color-mix(in srgb, var(--t-bg) 80%, var(--t-mark) 8%); }
/* Selection is neutral. Vermilion is reserved for "needs a person". */
.table tbody tr[aria-selected='true'] { background: var(--sunken); box-shadow: inset 3px 0 0 var(--ink-2); }
.table tbody tr[data-muted] td { color: var(--ink-3); }
.table[data-dense] td { height: 32px; padding-top: 4px; padding-bottom: 4px; }
.table caption { text-align: left; padding: 10px var(--s4); font-size: var(--text-sm); color: var(--ink-3); border-bottom: 1px solid var(--line); caption-side: top; }
.table-note { padding: 10px var(--s4); font-size: var(--text-sm); color: var(--ink-3); border-top: 1px solid var(--line); background: var(--surface); }

/* On a phone a register becomes one block per record, each fact under its label.
 * A matrix (stack: false) keeps its shape and scrolls sideways inside its frame. */
@media (max-width: 760px) {
  .table-wrap:not([data-stack]) .table { min-width: 600px; }
  .table-wrap:not([data-stack]) .table[data-dense] { min-width: 0; }
  .table-wrap[data-stack] { overflow: visible; }
  .table-wrap[data-stack] .table, .table-wrap[data-stack] tbody { display: block; min-width: 0; }
  .table-wrap[data-stack] caption { display: block; }
  .table-wrap[data-stack] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-wrap[data-stack] tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2) var(--s4); align-items: start; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
  .table-wrap[data-stack] tbody tr:last-child { border-bottom: 0; }
  .table-wrap[data-stack] tbody td, .table-wrap[data-stack] tbody td:first-child, .table-wrap[data-stack] tbody td:last-child { display: block; width: auto; min-width: 0; height: auto; padding: 0; border: 0; white-space: normal; text-align: left; }
  .table-wrap[data-stack] td::before { content: attr(data-label); display: block; font-size: var(--text-xs); color: var(--ink-3); line-height: 1.5; }
  .table-wrap[data-stack] td[data-label='']::before,
  .table-wrap[data-stack] td[data-stack-role='id']::before,
  .table-wrap[data-stack] td[data-stack-role='title']::before { display: none; }
  .table-wrap[data-stack] td[data-stack-role='id'],
  .table-wrap[data-stack] td[data-stack-role='title'],
  .table-wrap[data-stack] td[data-stack-role='full'] { grid-column: 1 / -1; }
  .table-wrap[data-stack] td[data-stack-role='id'] { margin-bottom: -4px; }
  .table-wrap[data-stack] tbody tr td[data-stack-role='hide'] { display: none; }
  .table-wrap[data-stack] td .status { white-space: normal; }
}

/* ---------- Key / value list ---------- */
.kv { display: grid; grid-template-columns: minmax(0, 1fr); font-size: var(--text-md); }
.kv > div { display: grid; grid-template-columns: minmax(96px, 42%) minmax(0, 1fr); gap: var(--s3); align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line); }
.kv > div:last-child { border-bottom: 0; }
.kv > div:first-child { padding-top: 0; }
.kv dt { color: var(--ink-3); }
.kv dd { color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.kv dd .status { white-space: normal; }
.kv-source { display: block; font-size: var(--text-xs); color: var(--ink-3); }
.kv[data-cols='2'] { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--s8); }
@media (max-width: 760px) { .kv[data-cols='2'] { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Callout ---------- */
.callout {
  display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4);
  background: var(--t-bg, var(--surface)); border: 1px solid var(--t-line, var(--line));
  border-left: 3px solid var(--t-mark, var(--ink-4)); border-radius: var(--r-md);
}
.callout-icon { flex: none; color: var(--t-mark); margin-top: 2px; }
.callout { flex-wrap: wrap; }
.callout-body { flex: 1 1 22rem; min-width: 0; }
.callout-title { display: block; font-size: var(--text-lg); font-weight: 600; color: var(--ink); line-height: 1.35; }
.callout-text { color: var(--ink-2); margin-top: 1px; }
.callout-text + .callout-text { margin-top: 4px; }
.callout-actions { display: flex; align-items: center; gap: var(--s2); flex: 0 1 auto; align-self: center; flex-wrap: wrap; margin-left: auto; }
.callout[data-size='sm'] { padding: var(--s2) var(--s3); }
.callout[data-size='sm'] .callout-title { font-size: var(--text-md); }
@media (max-width: 760px) { .callout-body { flex: 1 1 0; } .callout-actions { width: 100%; margin-left: 0; } }

/* ---------- Gate rail ----------
 * The backbone of a decision: eight separate facts, in order.
 */
.gates { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); position: relative; }
.gate { position: relative; display: flex; flex-direction: column; gap: 2px; padding: 0 var(--s3) 0 0; min-width: 0; }
.gate::before {
  content: ''; position: absolute; top: 11px; left: 24px; right: 0; height: 2px; background: var(--line-2);
}
.gate:last-child::before { display: none; }
.gate[data-state='done']::before { background: var(--ok-mark); }
.gate-node {
  position: relative; z-index: 1; display: grid; place-items: center; width: 24px; height: 24px; margin-bottom: 6px;
  color: var(--idle-mark); background: var(--surface); border: 2px solid var(--line-2); border-radius: 50%;
}
.gate-node .icon { width: 13px; height: 13px; stroke-width: 2; }
.gate-label { font-size: var(--text-sm); font-weight: 600; color: var(--ink-2); line-height: 1.3; }
.gate-detail { font-size: var(--text-xs); color: var(--ink-3); line-height: 1.35; overflow-wrap: break-word; }
.gate-label-full { display: none; }
.gates[data-layout='vertical'] .gate-label-full { display: inline; }
.gates[data-layout='vertical'] .gate-label-short { display: none; }
.gate[data-state='done'] .gate-node { color: var(--surface); background: var(--ok-mark); border-color: var(--ok-mark); }
.gate[data-state='done'] .gate-label { color: var(--ink); }
.gate[data-state='current'] .gate-node { color: var(--on-accent); background: var(--accent-mark); border-color: var(--accent-mark); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-mark) 20%, transparent); }
.gate[data-state='current'] .gate-label { color: var(--accent-ink); }
.gate[data-state='current'] .gate-detail { color: var(--ink-2); }
.gate[data-state='active'] .gate-node { color: #fff; background: var(--run-mark); border-color: var(--run-mark); }
.gate[data-state='active'] .gate-label { color: var(--run-ink); }
.gate[data-state='active'] .gate-detail { color: var(--ink-2); }
.gate[data-state='blocked'] .gate-node { color: var(--accent-mark); border-color: var(--accent-mark); }
.gate[data-state='blocked'] .gate-label { color: var(--ink); }
.gate[data-state='failed'] .gate-node, .gate[data-state='unknown'] .gate-node { color: var(--warn-mark); border-color: var(--warn-mark); border-style: dashed; }
.gate[data-state='na'] .gate-node { border-style: dashed; background: transparent; }
.gate[data-state='na'] .gate-label, .gate[data-state='na'] .gate-detail { color: var(--ink-3); }
.gate[data-state='waiting'] .gate-label { color: var(--ink-3); }
.gate[data-live] .gate-node { animation: gate-in var(--med) var(--ease); }
@keyframes gate-in { from { transform: scale(0.6); } to { transform: none; } }

.gates[data-layout='vertical'] { grid-auto-flow: row; grid-auto-columns: auto; gap: 0; }
.gates[data-layout='vertical'] .gate { display: grid; grid-template-columns: 24px minmax(0, 1fr); column-gap: var(--s3); padding: 0 0 var(--s4); }
.gates[data-layout='vertical'] .gate:last-child { padding-bottom: 0; }
.gates[data-layout='vertical'] .gate-node { grid-row: 1 / span 2; margin: 0; }
.gates[data-layout='vertical'] .gate::before { top: 24px; bottom: 0; left: 11px; right: auto; width: 2px; height: auto; }
.gates[data-layout='vertical'] .gate-label { padding-top: 3px; }
/* The rail answers to the width of its own frame. Eight steps need about
 * 760px; below that it becomes two rows of four, and a list on a phone. */
.gates-frame { container-type: inline-size; }
@container (max-width: 760px) {
  .gates:not([data-layout='vertical']) { grid-auto-flow: row; grid-template-columns: repeat(4, minmax(0, 1fr)); row-gap: var(--s4); }
  .gates:not([data-layout='vertical']) .gate:nth-child(4n)::before { display: none; }
  .gates .gate-label-full { display: inline; }
  .gates .gate-label-short { display: none; }
}
@container (max-width: 460px) {
  .gates:not([data-layout='vertical']) { grid-template-columns: minmax(0, 1fr); row-gap: 0; }
  .gates:not([data-layout='vertical']) .gate { display: grid; grid-template-columns: 24px minmax(0, 1fr); column-gap: var(--s3); padding: 0 0 var(--s4); }
  .gates:not([data-layout='vertical']) .gate-node { grid-row: 1 / span 2; margin: 0; }
  .gates:not([data-layout='vertical']) .gate::before, .gates:not([data-layout='vertical']) .gate:nth-child(4n)::before { display: block; top: 24px; bottom: 0; left: 11px; right: auto; width: 2px; height: auto; }
  .gates:not([data-layout='vertical']) .gate:last-child::before { display: none; }
  .gates:not([data-layout='vertical']) .gate-label { padding-top: 3px; }
}

/* ---------- Dependency path ---------- */
.path { display: flex; align-items: stretch; gap: 0; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.path-node { position: relative; flex: 1 1 0; min-width: 150px; display: flex; flex-direction: column; gap: 2px; padding: var(--s3) var(--s6) var(--s3) var(--s4); color: inherit; border-right: 1px solid var(--line); }
.path-node:last-child { border-right: 0; }
a.path-node:hover { background: var(--surface-2); text-decoration: none; color: inherit; }
.path-node::after {
  content: ''; position: absolute; top: 50%; right: -6px; z-index: 1; width: 11px; height: 11px;
  background: var(--surface); border-top: 1px solid var(--line-2); border-right: 1px solid var(--line-2); transform: translateY(-50%) rotate(45deg);
}
.path-node:last-child::after { display: none; }
.path-node[data-current] { box-shadow: inset 0 -3px 0 var(--t-mark, var(--accent-mark)); }
.path-id { font-family: var(--font-mono); font-size: var(--text-md); font-weight: 600; color: var(--ink); }
a.path-node .path-id { color: var(--ref); }
.path-title { font-size: var(--text-sm); color: var(--ink-2); }
.path-node .status { font-size: var(--text-sm); margin-top: 2px; white-space: normal; align-items: flex-start; }
.path-node .status .glyph { margin-top: 4px; }
.path-gate { font-size: var(--text-xs); color: var(--ink-3); }

/* ---------- Timeline ---------- */
.timeline { display: flex; flex-direction: column; font-size: var(--text-sm); }
.tl-item { position: relative; display: grid; grid-template-columns: 12px minmax(64px, auto) minmax(0, 1fr); column-gap: var(--s3); padding: 0 0 var(--s3); align-items: baseline; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before { content: ''; position: absolute; left: 5px; top: 14px; bottom: -4px; width: 1px; background: var(--line-2); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 7px; height: 7px; margin-left: 2px; border-radius: 50%; background: var(--t-mark, var(--idle-mark)); align-self: center; transform: translateY(-1px); }
.tl-item[data-tone='muted'] .tl-dot { background: var(--ink-4); }
.tl-item[data-latest] .tl-dot { box-shadow: 0 0 0 3px color-mix(in srgb, var(--t-mark, var(--idle-mark)) 25%, transparent); }
.tl-time { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-3); white-space: nowrap; }
.tl-text { color: var(--ink); min-width: 0; }
.tl-item[data-tone='muted'] .tl-text { color: var(--ink-2); }
.tl-actor { color: var(--ink-3); }
.tl-item[data-new] { animation: tl-in 420ms var(--ease); }
@keyframes tl-in { from { opacity: 0; transform: translateY(-4px); background: var(--run-bg); } to { opacity: 1; transform: none; } }

/* ---------- Ballot ---------- */
.ballot { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.ballot-row { display: grid; grid-template-columns: minmax(180px, 1.1fr) minmax(0, 2fr) 72px; gap: var(--s4); align-items: center; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.ballot-row:last-of-type { border-bottom: 0; }
.ballot-row[data-leading] { box-shadow: inset 3px 0 0 var(--accent-mark); }
.ballot-opt { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; min-width: 0; font-weight: 500; }
.opt-key {
  flex: none; display: inline-grid; place-items: center; width: 22px; height: 22px; font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 600;
  color: var(--ink-2); background: var(--sunken); border-radius: var(--r-sm);
}
.ballot-row[data-leading] .opt-key { color: var(--on-accent); background: var(--accent-mark); }
.ballot-track { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 26px; }
.ballot-vote { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 9px 0 3px; font-size: var(--text-sm); background: var(--sunken); border-radius: 13px; animation: vote-in var(--med) var(--ease); }
.ballot-vote[data-kind='agent'] { border-radius: var(--r-sm); }
.ballot-vote[data-self] { background: var(--accent-bg); box-shadow: inset 0 0 0 1px var(--accent-line); }
@keyframes vote-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
.ballot-none { font-size: var(--text-sm); color: var(--ink-4); }
.ballot-count { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink-2); }
.ballot-count b { font-size: var(--text-lg); font-weight: 600; color: var(--ink); }
.ballot-foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); padding: var(--s3) var(--s4); border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-md) var(--r-md); font-size: var(--text-sm); color: var(--ink-3); }
@media (max-width: 760px) {
  .ballot-row { grid-template-columns: minmax(0, 1fr) auto; }
  .ballot-track { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- Meter ---------- */
.meter { display: flex; gap: 2px; height: 10px; border-radius: 5px; overflow: hidden; background: transparent; }
.meter-seg { min-width: 2px; border-radius: 2px; background: var(--ink-4); transition: flex-grow var(--med) var(--ease); }
.meter-seg[data-seg='used'] { background: var(--ink-2); }
.meter-seg[data-seg='reserved'] { background: var(--run-mark); }
.meter-seg[data-seg='unknown'] { background: repeating-linear-gradient(135deg, var(--warn-mark) 0 3px, transparent 3px 6px); }
.meter-seg[data-seg='available'] { background: var(--line-2); }
.meter-legend { display: flex; flex-wrap: wrap; gap: 4px var(--s5); margin-top: var(--s2); font-size: var(--text-sm); color: var(--ink-2); }
.meter-key { display: inline-flex; align-items: center; gap: 6px; }
.meter-key::before { content: ''; width: 9px; height: 9px; border-radius: 2px; background: var(--ink-4); }
.meter-key[data-seg='used']::before { background: var(--ink-2); }
.meter-key[data-seg='reserved']::before { background: var(--run-mark); }
.meter-key[data-seg='unknown']::before { background: repeating-linear-gradient(135deg, var(--warn-mark) 0 3px, transparent 3px 6px); }
.meter-key[data-seg='available']::before { background: var(--line-2); }
.meter-key b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Business-time strip ---------- */
.window-strip { display: flex; gap: 2px; height: 22px; font-size: 10.5px; }
.window-seg { display: grid; place-items: center; min-width: 0; padding: 0 6px; border-radius: 3px; white-space: nowrap; overflow: hidden; color: var(--ok-ink); background: var(--ok-bg); border: 1px solid var(--ok-line); }
.window-seg[data-kind='closed'] { color: var(--ink-3); background: repeating-linear-gradient(135deg, var(--sunken) 0 4px, transparent 4px 8px); border-color: var(--line); }
.window-seg[data-kind='remaining'] { color: var(--run-ink); background: var(--run-bg); border-color: var(--run-line); }
.window-ends { display: flex; justify-content: space-between; margin-top: 4px; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-3); }

/* ---------- Source excerpt ---------- */
.excerpt { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.excerpt-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2); padding: 9px var(--s4); background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: var(--text-sm); color: var(--ink-2); }
.excerpt-body { padding: var(--s2) 0; font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.7; overflow-x: auto; }
.excerpt-line { display: grid; grid-template-columns: 56px minmax(0, 1fr); padding: 0 var(--s4) 0 0; white-space: pre; }
.excerpt-line > span:first-child { text-align: right; padding-right: var(--s4); color: var(--ink-4); user-select: none; }
.excerpt-line[data-mark] { background: var(--accent-bg); box-shadow: inset 3px 0 0 var(--accent-mark); }
.excerpt-foot { padding: 9px var(--s4); border-top: 1px solid var(--line); font-size: var(--text-sm); color: var(--ink-3); }

/* ---------- Diff ---------- */
.diff-del { color: var(--accent-ink); background: var(--accent-bg); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--accent-ink) 50%, transparent); padding: 0 3px; border-radius: 3px; }
.diff-ins { color: var(--ok-ink); background: var(--ok-bg); padding: 0 3px; border-radius: 3px; text-decoration: none; }
.diff-same { color: var(--ink-3); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: var(--text-sm); font-weight: 500; color: var(--ink-2); }
.field-help { font-size: var(--text-xs); color: var(--ink-3); }
.field-error { font-size: var(--text-xs); color: var(--accent-ink); }
.input, .select, .textarea {
  width: 100%; height: var(--control); padding: 0 10px; font-size: var(--text-md);
  color: var(--ink); background: var(--surface); border: 1px solid var(--field-line); border-radius: var(--r-md);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.textarea { height: auto; min-height: 72px; padding: 8px 10px; line-height: 1.45; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-2); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.input[readonly] { background: var(--surface-2); font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-2); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 28px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23808a87' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.input[data-size='sm'], .select[data-size='sm'] { height: 26px; font-size: var(--text-sm); padding-left: 8px; }

.segmented { display: inline-flex; padding: 2px; gap: 2px; background: var(--sunken); border-radius: var(--r-md); }
.segmented button, .segmented a { height: 26px; padding: 0 10px; display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); font-weight: 500; color: var(--ink-3); border-radius: 4px; white-space: nowrap; }
.segmented button:hover, .segmented a:hover { color: var(--ink); text-decoration: none; }
.segmented [aria-pressed='true'], .segmented [aria-checked='true'], .segmented [aria-current='true'] { color: var(--ink); background: var(--surface); box-shadow: 0 0 0 1px var(--line-2), 0 1px 2px rgba(0, 0, 0, 0.06); }

.switch { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; font-size: var(--text-md); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { position: relative; width: 30px; height: 18px; flex: none; background: var(--line-2); border-radius: 9px; transition: background var(--fast) var(--ease); }
.switch-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform var(--fast) var(--ease); }
.switch input:checked + .switch-track { background: var(--ok-mark); }
.switch input:checked + .switch-track::after { transform: translateX(12px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }

.check { display: flex; align-items: flex-start; gap: var(--s2); cursor: pointer; line-height: 1.4; }
.check input { flex: none; width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); cursor: pointer; }

/* ---------- Evidence checklist (not a to-do list) ----------
 * Criteria are met by evidence, not by ticking a box.
 */
.criteria { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.criterion { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: var(--s3); align-items: baseline; padding: 9px var(--s4); border-bottom: 1px solid var(--line); }
.criterion:last-child { border-bottom: 0; }
.criterion-mark { width: 16px; height: 16px; align-self: center; display: grid; place-items: center; border-radius: 50%; border: 1.5px dashed var(--ink-4); color: transparent; }
.criterion[data-met] .criterion-mark { border: 0; background: var(--ok-mark); color: var(--surface); }
.criterion-mark .icon { width: 11px; height: 11px; stroke-width: 2.5; }
.criterion-need { font-size: var(--text-sm); color: var(--ink-3); text-align: right; }

/* ---------- Comments ---------- */
.thread { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.comment { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.comment-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px var(--s2); font-size: var(--text-sm); }
.comment-author { font-weight: 600; color: var(--ink); }
.comment-meta { color: var(--ink-3); }
.comment-text { color: var(--ink); overflow-wrap: anywhere; white-space: pre-wrap; }
.comment[data-new] { animation: tl-in 420ms var(--ease); }
.comment-form { display: flex; align-items: flex-end; gap: var(--s2); padding: var(--s3) var(--s4); }
.comment-form .textarea { min-height: var(--control); height: var(--control); padding: 5px 10px; resize: none; }
.comment-form .textarea:focus-visible { background: var(--surface); height: 72px; }
.comment-note { padding: 0 var(--s4) var(--s3); font-size: var(--text-xs); color: var(--ink-3); }

/* ---------- Empty state ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: var(--s8) var(--s4); text-align: center; color: var(--ink-3); background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--r-md); }
.empty .icon { width: 22px; height: 22px; color: var(--ink-4); margin-bottom: 4px; }
.empty strong { color: var(--ink); font-weight: 600; }
.empty p { max-width: 52ch; }
.empty .row { margin-top: var(--s3); justify-content: center; }

/* ---------- Copy field ---------- */
.copy-field { display: flex; align-items: stretch; gap: var(--s2); min-width: 0; }
.copy-field .input { flex: 1 1 auto; min-width: 0; }
.copy-block { position: relative; padding: var(--s3) var(--s4); font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }

/* ---------- Overlays ---------- */
.overlay-root { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.overlay-root > * { pointer-events: auto; }

dialog.dialog {
  width: min(560px, calc(100vw - 32px)); max-height: min(720px, calc(100dvh - 48px)); padding: 0; margin: auto;
  color: var(--ink); background: var(--overlay); border: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-dialog); overflow: hidden;
}
dialog.dialog[open] { display: flex; flex-direction: column; animation: dialog-in var(--med) var(--ease); }
dialog.dialog::backdrop { background: var(--scrim); animation: fade-in var(--med) var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.dialog-head { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s5) var(--s5) var(--s3); }
.dialog-head h2 { font-size: var(--text-xl); line-height: 1.3; }
.dialog-sub { color: var(--ink-3); font-size: var(--text-sm); margin-top: 2px; }
.dialog-body { padding: 0 var(--s5) var(--s5); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s4); }
.dialog-foot { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s5); border-top: 1px solid var(--line); background: var(--surface-2); }
.dialog-foot .spacer + .btn { margin-left: auto; }

.effects { display: flex; flex-direction: column; gap: 2px; }
.effects-title { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px; }
.effect { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: var(--s2); align-items: baseline; padding: 3px 0; }
.effect .icon { width: 14px; height: 14px; align-self: center; stroke-width: 2.25; }
.effect[data-kind='will'] .icon { color: var(--ok-mark); }
.effect[data-kind='wont'] .icon { color: var(--ink-4); }
.effect[data-kind='wont'] { color: var(--ink-2); }
.effect[data-kind='keeps'] .icon { color: var(--warn-mark); }
.effect[data-kind='blocked'] .icon { color: var(--accent-mark); }

.toast-stack { position: fixed; right: var(--s5); bottom: var(--s5); z-index: 60; display: flex; flex-direction: column; gap: var(--s2); align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--s3); max-width: min(440px, calc(100vw - 32px)); padding: 10px 14px;
  font-size: var(--text-md); color: var(--bg); background: var(--ink); border-radius: var(--r-md); box-shadow: var(--shadow-pop);
  animation: toast-in var(--med) var(--ease);
}
.toast[data-tone='hold'] { background: var(--accent); color: #fff; }
.toast .icon { flex: none; }
.toast button { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.toast[data-leaving] { opacity: 0; transform: translateY(6px); transition: opacity var(--med) var(--ease), transform var(--med) var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.peek {
  position: fixed; z-index: 55; width: 320px; padding: var(--s3) var(--s4); font-size: var(--text-sm);
  color: var(--ink); background: var(--overlay); border-radius: var(--r-md); box-shadow: var(--shadow-pop);
  animation: fade-in var(--fast) var(--ease); pointer-events: none;
}
.peek-type { display: flex; align-items: center; gap: var(--s2); font-size: var(--text-xs); color: var(--ink-3); }
.peek-title { font-size: var(--text-md); font-weight: 600; margin-top: 2px; }
.peek-summary { color: var(--ink-2); margin-top: 4px; }
.peek .status { margin-top: var(--s2); }

.menu {
  position: fixed; z-index: 56; min-width: 220px; max-width: 360px; max-height: min(480px, calc(100dvh - 32px)); overflow-y: auto; padding: 5px;
  color: var(--ink); background: var(--overlay); border-radius: var(--r-md); box-shadow: var(--shadow-pop); animation: fade-in var(--fast) var(--ease);
}
.menu-label { padding: 6px 9px 4px; font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); }
.menu-item { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 32px; padding: 5px 9px; text-align: left; font-size: var(--text-md); color: var(--ink); border-radius: var(--r-sm); }
.menu-item:hover, .menu-item[data-active] { background: var(--sunken); text-decoration: none; color: var(--ink); }
.menu-item[aria-checked='true'] { font-weight: 600; }
.menu-item-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.menu-item-note { font-size: var(--text-xs); color: var(--ink-3); font-weight: 400; white-space: normal; line-height: 1.35; }
.menu-item .icon { color: var(--ink-3); }
.menu-sep { height: 1px; margin: 5px 0; background: var(--line); }

/* Tooltips are drawn by the shell in the overlay layer (.tip in base.css), so
 * a scrolling panel can never clip them. */
[data-tip] { position: relative; }
.term { text-decoration: underline dotted var(--ink-4); text-underline-offset: 3px; cursor: help; }
.term:focus-visible { outline: 2px solid var(--focus, var(--accent)); outline-offset: 2px; border-radius: 2px; }

/* ---------- Shared work ---------- */
.sha { font-family: var(--font-mono); font-size: 0.9em; padding: 1px 5px; color: var(--ink-2); background: var(--sunken); border-radius: 3px; white-space: nowrap; }
.files { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-width: 0; }
.file { font-family: var(--font-mono); font-size: 0.9em; padding: 1px 5px; color: var(--ink-2); background: var(--sunken); border-radius: 3px; overflow-wrap: anywhere; }
.file[data-mark] { color: var(--hold-ink); background: var(--hold-bg); box-shadow: inset 0 0 0 1px var(--hold-line); }
.avatar[data-kind='foreign'] { border-style: dashed; border-radius: 5px; color: var(--ink-3); background: transparent; }
.presence { display: inline-flex; align-items: center; gap: 7px; min-width: 0; font-size: var(--text-sm); color: var(--ink-3); }
.presence[data-compact] .presence-text { display: none; }
.accountable { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0 4px; }
.steps { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px; font-size: var(--text-xs); }
.steps li { display: flex; flex-direction: column; gap: 1px; padding: 6px 8px 0 0; border-top: 2px solid var(--line-2); color: var(--ink-3); }
.steps li[data-done='true'] { border-top-color: var(--ink-2); color: var(--ink-2); }
.steps li[data-next] { border-top-color: var(--warn-mark); }
.steps-what { font-weight: 600; color: var(--ink); }
.steps li:not([data-done='true']):not([data-next]) .steps-what { color: var(--ink-3); font-weight: 500; }
@media (max-width: 760px) { .steps { grid-auto-flow: row; } .steps li { border-top: 0; border-left: 2px solid var(--line-2); padding: 2px 0 6px 8px; } .steps li[data-done='true'] { border-left-color: var(--ink-2); } .steps li[data-next] { border-left-color: var(--warn-mark); } }

/* ---------- Gate dots: the gate rail, compressed for lists ---------- */
.gate-dots { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.gate-dots i { width: 7px; height: 7px; border-radius: 50%; background: transparent; border: 1.5px solid var(--line-2); }
.gate-dots i[data-state='done'] { background: var(--ok-mark); border-color: var(--ok-mark); }
.gate-dots i[data-state='current'] { background: var(--accent-mark); border-color: var(--accent-mark); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-mark) 22%, transparent); }
.gate-dots i[data-state='active'] { background: var(--run-mark); border-color: var(--run-mark); }
.gate-dots i[data-state='blocked'] { border-color: var(--accent-mark); }
.gate-dots i[data-state='failed'], .gate-dots i[data-state='unknown'] { border-color: var(--warn-mark); border-style: dashed; }
.gate-dots i[data-state='na'] { border-style: dotted; opacity: 0.6; }
.gate-dots-count { margin-left: 5px; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-3); }
