:root {
  color-scheme: light dark;
  --bg: #f6f6f3;
  --panel: #ffffff;
  --panel-2: #fafaf8;
  --text: #1c1c1e;
  --muted: #6b6b72;
  --faint: #9c9ca3;
  --line: #e5e4df;
  --line-strong: #d3d2cc;
  --accent: #3b5bdb;
  --accent-soft: #e8ecfd;

  --working: #2f6fed;
  --input: #c26a00;
  --input-soft: #fff4e2;
  --idle: #8a8a91;
  --completed: #1f9d55;
  --failed: #d93025;
  --canceled: #a3a3aa;

  --cat-lifecycle: #6b6b72;
  --cat-agent: #7c4dff;
  --cat-task: #1f9d55;
  --cat-attention: #e08600;
  --cat-status: #b6bcc6;
  --cat-wait: #2f6fed;
  --cat-message: #0f9aa8;
  --cat-other: #c4c4c9;

  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131315;
    --panel: #1b1b1e;
    --panel-2: #202024;
    --text: #ececef;
    --muted: #a0a0a8;
    --faint: #75757d;
    --line: #2b2b30;
    --line-strong: #3a3a41;
    --accent: #7b93ff;
    --accent-soft: #232a45;
    --working: #6b9bff;
    --input: #f0a33a;
    --input-soft: #33260f;
    --idle: #8d8d96;
    --completed: #45c47c;
    --failed: #ff6b5e;
    --canceled: #6f6f78;
    --cat-lifecycle: #a0a0a8;
    --cat-agent: #a58bff;
    --cat-task: #45c47c;
    --cat-attention: #f0a33a;
    --cat-status: #4a4f5a;
    --cat-wait: #6b9bff;
    --cat-message: #3cc3d0;
    --cat-other: #4a4a52;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
/* The whole viewer: top bar, three columns, timeline. */
.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  /* Never wider than the window: text cut short to fit (a node's id, the
     step's label) mustn't widen the page to its full length, which a phone
     would show zoomed in. */
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.mono { font-family: var(--mono); font-size: 12px; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; color: inherit; text-decoration: none; }
.brand img { width: 24px; height: 24px; }
.mode { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.mode .pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 12px;
}
.mode .pill.live { background: color-mix(in srgb, var(--completed) 14%, transparent); color: var(--completed); }
.mode .pill.past { background: var(--accent-soft); color: var(--accent); }
.mode .pill.offline { background: color-mix(in srgb, var(--failed) 12%, transparent); color: var(--failed); }
.mode .pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.mode .pill.live::before { animation: pulse 1.8s ease-in-out infinite; }

/* Three columns */
.layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 360px;
  min-height: 0;
  /* Model-written text with nowhere to break (a path, a URL, a hash) wraps
     anywhere rather than widening the card or panel it's in. */
  overflow-wrap: anywhere;
}
.layout > * { min-height: 0; overflow: auto; }

.sessions { border-right: 1px solid var(--line); background: var(--panel-2); }
.panel-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px 10px; background: var(--panel-2);
}
.panel-head h2 { white-space: nowrap; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.toggle { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 12px; color: var(--muted); cursor: pointer; }
.session-list { list-style: none; margin: 0; padding: 0 8px 16px; }
/* A folder's heading, which folds its sessions away, and its sessions. */
.folder + .folder { margin-top: 6px; }
.folder-head {
  width: 100%; display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; margin-top: 4px; border: none; border-radius: 6px; background: none;
  font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); text-align: left; cursor: pointer;
}
.folder-head:hover { color: var(--text); background: var(--panel); }
.folder-head svg {
  width: 12px; height: 12px; flex: none; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; transition: transform 0.15s;
}
.folder-head[aria-expanded="true"] svg { transform: rotate(90deg); }
.folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-attention { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--input); }
.folder-count { font-weight: 500; font-variant-numeric: tabular-nums; }
.folder-sessions { list-style: none; margin: 0; padding: 0; }
@media (prefers-reduced-motion: reduce) { .folder-head svg { transition: none; } }
.session {
  width: 100%; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 10px; row-gap: 2px;
  padding: 10px 10px; margin: 2px 0;
  background: none; border: 1px solid transparent; border-radius: var(--radius);
}
.session:hover { background: var(--panel); border-color: var(--line); }
.session.selected { background: var(--panel); border-color: var(--line-strong); box-shadow: 0 1px 2px rgb(0 0 0 / 0.04); }
.session.needs-you { box-shadow: inset 3px 0 0 var(--input); }
.session.spotlight { animation: spotlight 1.6s ease-out; }

/* How many sessions need you, and arrows to step through them: under the
   panel's title, so it stays in view as the list scrolls. */
.panel-head { flex-wrap: wrap; }
.attention-nav {
  flex-basis: 100%; display: flex; align-items: center; gap: 6px;
  padding: 4px 4px 4px 10px; border-radius: 8px;
  background: var(--input-soft); border: 1px solid color-mix(in srgb, var(--input) 35%, transparent);
  color: var(--input); font-size: 12.5px; font-weight: 600;
}
.attention-nav[hidden] { display: none; }
.attention-count { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-nav .icon-btn { width: 26px; height: 26px; background: var(--panel); color: var(--text); }
.session .dot { grid-row: 1 / span 3; margin-top: 6px; }
.s-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The app a session ran in, before its name. */
.app-icon { width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px; border-radius: 3px; flex: none; }

/* The Apps dropdown: a checkbox per app, over the list. */
.app-filter { position: relative; }
.app-filter[hidden] { display: none; }
.app-filter > summary { list-style: none; user-select: none; }
.app-filter > summary::-webkit-details-marker { display: none; }
.app-filter > summary::after { content: "▾"; font-size: 10px; }
.app-filter[open] > summary { color: var(--text); }
/* Placed on the page (`placeAppMenu`), so the scrolling list can't clip it. */
.app-menu {
  position: fixed; left: 0; top: 0; z-index: 40;
  min-width: 190px; max-width: calc(100vw - 32px); padding: 6px; display: grid; gap: 1px;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
}
.app-menu label { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; font-size: 13px; color: var(--text); cursor: pointer; white-space: nowrap; }
.app-menu label:hover { background: var(--panel-2); }
.app-menu .app-icon { margin-right: 0; }
.app-menu .count { margin-left: auto; padding-left: 12px; color: var(--faint); font-size: 12px; }
.app-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.s-when { color: var(--faint); font-size: 12px; white-space: nowrap; }
.s-sub, .s-meta { grid-column: 2 / span 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.s-sub { color: var(--muted); }
.s-sub.attention { color: var(--input); font-weight: 600; }
.s-sub.problem { color: var(--failed); font-weight: 600; }
.s-meta { color: var(--faint); font-size: 12px; }
.sessions .empty-note { padding: 8px 16px; }

/* Main view */
main { padding: 22px 28px 40px; }
.banner {
  margin-bottom: 16px; padding: 10px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--failed) 10%, var(--panel)); color: var(--failed);
  border: 1px solid color-mix(in srgb, var(--failed) 30%, transparent);
}
.view-head { margin-bottom: 18px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
.btn {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--text);
  font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.view-head h1 { font-size: 22px; letter-spacing: -0.02em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.view-head .meta { margin-top: 4px; color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.past-note {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 12px;
  padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 600;
}

.tree .children {
  margin-left: 17px;
  padding-left: 18px;
  border-left: 1.5px solid var(--line);
}
.node {
  position: relative;
  width: 100%; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: start;
  margin: 8px 0; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.children > .branch > .node::before {
  content: ""; position: absolute; left: -19px; top: 22px; width: 18px; border-top: 1.5px solid var(--line);
}
.node:hover { border-color: var(--line-strong); }
.node.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.node.current { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); border-color: var(--accent); }
.node.flash { animation: flash 1.6s ease-out; }
.node.attention { animation: needs-you 0.65s ease-in-out 4; }
.node.input_required { border-color: color-mix(in srgb, var(--input) 55%, var(--line)); }
.node.completed, .node.canceled { background: var(--panel-2); }
.node.completed .node-name, .node.canceled .node-name { color: var(--muted); }
.node-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.node-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; }
.node-name { font-weight: 620; }
.node-purpose { color: var(--text); }
.node-headline { color: var(--muted); }
.node-attention {
  color: var(--input); font-weight: 600;
  background: var(--input-soft); border-radius: 6px; padding: 3px 8px; align-self: flex-start;
}
.node-blocked { color: var(--working); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.node-blocked::before { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-radius: 50%; border-top-color: transparent; animation: spin 1.2s linear infinite; }

.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: var(--idle); flex: none; }
.dot.working { background: var(--working); animation: pulse 1.8s ease-in-out infinite; }
.dot.input_required { background: var(--input); animation: pulse 1s ease-in-out infinite; }
.dot.idle { background: var(--idle); }
.dot.completed { background: var(--completed); }
.dot.failed { background: var(--failed); }
.dot.canceled { background: var(--canceled); }

.state {
  font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--idle) 14%, transparent); color: var(--idle);
}
.state.working { background: color-mix(in srgb, var(--working) 13%, transparent); color: var(--working); }
.state.input_required { background: color-mix(in srgb, var(--input) 15%, transparent); color: var(--input); }
.state.completed { background: color-mix(in srgb, var(--completed) 13%, transparent); color: var(--completed); }
.state.failed { background: color-mix(in srgb, var(--failed) 13%, transparent); color: var(--failed); }
.chip {
  font-size: 11.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px;
}
.chip.warn { color: var(--input); border-color: color-mix(in srgb, var(--input) 40%, transparent); }

.progress { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.bar { width: 76px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--completed); border-radius: 3px; }

.empty {
  max-width: 560px; margin: 8vh auto; padding: 28px 30px; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.empty h2 { font-size: 18px; margin-bottom: 8px; }
.empty p { color: var(--muted); margin: 8px 0; }
.empty code, .detail code, .modal-box code {
  font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 6px;
}
.empty pre { margin: 12px 0; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.empty-note { color: var(--muted); }

/* Detail panel */
.detail { border-left: 1px solid var(--line); background: var(--panel); padding: 20px 20px 40px; }
.detail .placeholder, .modal-box .placeholder { color: var(--faint); margin-top: 30px; text-align: center; }
.detail-head h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.idline { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--faint); min-width: 0; }
.idline .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy {
  flex: none; border: 1px solid var(--line); background: var(--panel-2); border-radius: 6px;
  font-size: 11px; padding: 1px 7px; cursor: pointer; color: var(--muted);
}
.open-box { margin-top: 14px; }
.open-box .btn:disabled { opacity: 0.6; cursor: progress; }
.open-note { font-size: 12.5px; margin-top: 8px; }
.open-ok { color: var(--muted); }
.open-error { color: var(--failed); display: block; }
.open-command { color: var(--muted); display: block; margin-top: 6px; }
.detail section, .modal-box section { margin-top: 20px; }
.detail h3, .modal-box h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; }
.detail .lead, .modal-box .lead { margin-top: 12px; }
.detail .attention-box, .modal-box .attention-box {
  margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--input-soft); color: var(--input); font-weight: 600;
}
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 7px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
.list > li:first-child { border-top: none; }
.list .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list .sub { display: block; color: var(--muted); font-size: 12.5px; }
.list .time { color: var(--faint); font-size: 12px; white-space: nowrap; }
.task-icon { width: 14px; flex: none; text-align: center; font-size: 12px; }
.task.completed .grow { color: var(--faint); text-decoration: line-through; }
.task.completed .task-icon { color: var(--completed); }
.task.in_progress .grow { font-weight: 600; }
.task.in_progress .task-icon { color: var(--working); }
.task.pending .task-icon { color: var(--faint); }
.linkish {
  border: none; background: none; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; text-align: left;
}
.linkish:hover { text-decoration: underline; }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px 14px; margin: 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.body-text { white-space: pre-wrap; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin-top: 4px; font-size: 12.5px; }

/* Timeline */
.timeline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "steppers track live" "caption caption caption";
  align-items: center;
  gap: 6px 14px;
  padding: 10px 18px 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.steppers { grid-area: steppers; display: flex; gap: 4px; }
/* The timeline drawer's controls, for a phone only (see the narrow styles). */
.timeline-hide, .timeline-open { display: none; }
.timeline-open { place-items: center; flex: none; width: 34px; height: 30px; padding: 0; }
.timeline-open svg { width: 22px; height: 22px; }
.timeline-open .track-line { stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; }
.timeline-open .track-thumb { fill: var(--accent); stroke: var(--panel); stroke-width: 2; }
.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
}
.icon-btn:hover:not(:disabled) { border-color: var(--line-strong); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.icon-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.track { grid-area: track; position: relative; height: 38px; }
.ticks { position: absolute; left: 9px; right: 9px; top: 3px; height: 14px; pointer-events: none; }
.tick {
  position: absolute; bottom: 0; width: 2px; height: 9px; margin-left: -1px; border-radius: 1px;
  background: var(--cat-other);
}
.tick.lifecycle { background: var(--cat-lifecycle); height: 14px; }
.tick.agent { background: var(--cat-agent); height: 12px; }
.tick.task { background: var(--cat-task); height: 10px; }
.tick.attention { background: var(--cat-attention); height: 14px; width: 3px; }
.tick.status { background: var(--cat-status); height: 6px; }
.tick.wait { background: var(--cat-wait); }
.tick.message { background: var(--cat-message); height: 11px; }
.tick.passed { opacity: 1; }
.tick.ahead { opacity: 0.35; }

#slider {
  --pct: 100%;
  position: absolute; left: 0; right: 0; bottom: 2px; width: 100%; height: 18px; margin: 0;
  -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer;
}
#slider:disabled { cursor: default; opacity: 0.5; }
#slider:focus-visible { outline: none; }
#slider::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--accent) 0 var(--pct), var(--line) var(--pct) 100%);
}
#slider::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
#slider::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
#slider::-webkit-slider-thumb {
  -webkit-appearance: none; box-sizing: border-box; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--accent), 0 1px 3px rgb(0 0 0 / 0.25);
}
#slider::-moz-range-thumb {
  box-sizing: border-box; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--accent), 0 1px 3px rgb(0 0 0 / 0.25);
}
#slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent); }
#slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent); }

.hover-tip {
  position: absolute; bottom: 40px; transform: translateX(-50%);
  /* At most 80% of the window: a long label's cut in the middle (see `showTip`). */
  max-width: 80vw; padding: 6px 10px; border-radius: 8px; pointer-events: none; z-index: 5;
  background: var(--text); color: var(--bg); font-size: 12px; white-space: nowrap; overflow: hidden;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.18);
}
.hover-tip .t { opacity: 0.7; margin-right: 6px; }

.live-btn {
  grid-area: live; justify-self: end; display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: 13px;
  background: var(--panel-2); border: 1px solid var(--line-strong); color: var(--muted);
}
.live-btn .live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.live-btn.on { background: color-mix(in srgb, var(--completed) 12%, var(--panel)); border-color: color-mix(in srgb, var(--completed) 45%, transparent); color: var(--completed); }
.live-btn.on .live-dot { background: var(--completed); animation: pulse 1.8s ease-in-out infinite; }
.live-btn:not(.on):hover { border-color: var(--accent); color: var(--accent); }

.caption-row { grid-area: caption; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; }
.caption { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 13px; }
.step-count { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.step-time { color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.step-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 7px; min-width: 0; }
.step-label .swatch { flex: none; }
.legend { flex: none; list-style: none; margin: 0; padding: 0; display: flex; gap: 12px; font-size: 12px; color: var(--faint); }
.legend li { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--cat-other); }
.swatch.lifecycle { background: var(--cat-lifecycle); }
.swatch.agent { background: var(--cat-agent); }
.swatch.task { background: var(--cat-task); }
.swatch.attention { background: var(--cat-attention); }
.swatch.status { background: var(--cat-status); }
.swatch.wait { background: var(--cat-wait); }
.swatch.message { background: var(--cat-message); }

/* The Cards / Graph switch, in the view's heading */
.title-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
.view-switch { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.view-option {
  font: inherit; font-size: 12.5px; font-weight: 600; padding: 4px 12px; border: none; border-radius: 7px;
  background: none; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.view-option:hover { color: var(--text); }
.view-option.on { background: var(--accent-soft); color: var(--accent); }

/* The graph view: the tree as a network (app.js, "graph view"). Nodes are
   coloured by state as the cards' dots are, and outlined and shaped by
   kind in the legend's colours: a session square, an agent circle, a
   command diamond. */
.graph-host {
  position: relative; height: clamp(420px, calc(100vh - 330px), 1100px);
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden;
}
.graph { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; user-select: none; }
.graph:active { cursor: grabbing; }
.graph-note { padding: 24px; color: var(--muted); }
.gnode { cursor: pointer; outline: none; }
.gnode.leaving { pointer-events: none; }
.gnode .shape { fill: var(--idle); stroke: var(--cat-agent); stroke-width: 2.5; transition: fill 0.4s, stroke 0.4s; }
.gnode.k-session .shape { stroke: var(--cat-lifecycle); }
.gnode.k-command .shape { stroke: var(--cat-message); }
.gnode.working .shape { fill: var(--working); }
.gnode.input_required .shape { fill: var(--input); }
.gnode.idle .shape { fill: var(--idle); }
.gnode.completed .shape { fill: var(--completed); }
.gnode.failed .shape { fill: var(--failed); }
.gnode.canceled .shape { fill: var(--canceled); }
.gnode.stale .shape { stroke-dasharray: 3 2; }
.gnode.completed .grow, .gnode.canceled .grow { opacity: 0.6; transition: opacity 0.4s; }
.gnode.selected .shape { stroke: var(--accent); stroke-width: 3.5; }
.gnode:hover .shape { stroke-width: 3.5; }
.gnode .halo { fill: none; stroke: transparent; stroke-width: 3; transform-box: fill-box; transform-origin: center; }
.gnode.working .halo { stroke: var(--working); animation: halo 1.8s ease-out infinite; }
/* A session's working is its agents': it doesn't pulse itself. */
.gnode.k-session.working .halo { stroke: transparent; animation: none; }
.gnode.input_required .halo { stroke: var(--input); animation: halo 1s ease-out infinite; }
.gnode.current .halo { stroke: var(--accent); stroke-width: 4; opacity: 0.5; animation: none; }
.gnode.flash .halo { stroke: var(--completed); animation: halo 1.6s ease-out; }
/* What needs you, just brought into view (the attention counter's arrows): it pulses. */
.gnode.attention .halo { stroke: var(--input); stroke-width: 5; animation: halo 0.65s ease-out 4; }
.gnode.attention .shape { transform-box: fill-box; transform-origin: center; animation: bump 0.65s ease-in-out 4; }
.gnode:focus-visible .halo { stroke: var(--accent); stroke-dasharray: 3 3; opacity: 1; animation: none; }
.glabel {
  font-size: 11px; font-weight: 600; fill: var(--text); text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round;
}
.gnode.completed .glabel, .gnode.canceled .glabel { fill: var(--muted); font-weight: 500; }
.link { fill: none; stroke: var(--line-strong); stroke-width: 1.5; }
/* A node's tasks, as one pill beside it: how many are done, of how many. */
.pill { outline: none; }
.pill path { fill: var(--panel); stroke: var(--cat-task); stroke-width: 1.5; }
.pill text { font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums; fill: var(--cat-task); text-anchor: middle; pointer-events: none; }
.pill.all-done path { fill: color-mix(in srgb, var(--cat-task) 16%, var(--panel)); }
.pill image { pointer-events: none; }
/* The check mark is black: white in a dark theme. */
@media (prefers-color-scheme: dark) { .pill image { filter: invert(1); } }
.pill:hover path, .pill:focus-visible path { stroke-width: 2.5; }
.modal-box section.spot { animation: spot 1.4s ease-out; border-radius: 8px; }
.link.wait { stroke: var(--cat-wait); stroke-dasharray: 5 4; marker-end: url(#wait-arrow); opacity: 0.8; }
/* A parent waiting on its child (or a child on its parent): its line, dashed. */
.link.tree.waiting { stroke: var(--cat-wait); stroke-dasharray: 5 4; stroke-width: 2; animation: march 1s linear infinite; }
.wait-head { fill: var(--cat-wait); }
.graph-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.graph-tools .btn[hidden] { display: none; }
/* Another session needs you: the All button's orange, and pulses when one first does. */
.graph-tools .show-others.needs-you { border-color: var(--input); color: var(--input); }
.graph-tools .show-others.pulse { animation: needs-you 0.5s ease-in-out 4; }
.graph-tools .icon-fit { display: grid; place-items: center; padding: 4px 7px; }
.graph-tools .icon-fit img { display: block; width: 20px; height: 20px; }

/* The other sessions, round this one when zoomed out (app.js, "the other
   sessions, zoomed out"): coloured by how they're doing, as the list's
   dots are, and pulsing orange where they need you; still once they've
   flown in. */
.onode { cursor: pointer; outline: none; }
.onode.gone { pointer-events: none; }
.onode .hit { fill: transparent; stroke: transparent; transition: fill 0.15s, stroke 0.15s; }
.onode:hover .hit, .onode:focus-visible .hit { fill: color-mix(in srgb, var(--accent) 6%, transparent); stroke: color-mix(in srgb, var(--accent) 40%, transparent); }
.onode .shape { fill: var(--idle); stroke: var(--cat-lifecycle); stroke-width: 2.5; }
.onode.working .shape { fill: var(--working); }
.onode.completed .shape { fill: var(--completed); }
.onode.failed .shape { fill: var(--failed); }
.onode.canceled .shape { fill: var(--canceled); }
.onode.completed .obody, .onode.canceled .obody { opacity: 0.6; }
.onode.needs-you .shape { fill: var(--input); stroke: var(--input); }
.onode .halo { fill: none; stroke: transparent; stroke-width: 3; transform-box: fill-box; transform-origin: center; }
.onode.needs-you .halo { stroke: var(--input); stroke-width: 4; animation: halo 1s ease-out infinite; }
.onode .oname {
  font-size: 13px; font-weight: 650; fill: var(--text); text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round;
}
.onode .ostatus { font-size: 11.5px; fill: var(--muted); text-anchor: middle; pointer-events: none; }
.onode.needs-you .ostatus { fill: var(--input); font-weight: 650; }
/* A copy of the one chosen, over the page while its tree comes (see `showGhost`). */
.graph-ghost { position: fixed; z-index: 30; overflow: visible; pointer-events: none; transition: opacity 0.25s ease; }
.graph-ghost.gone { opacity: 0; }
.graph-ghost .hit { display: none; }
.graph-foot {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  display: flex; align-items: flex-end; gap: 8px; pointer-events: none;
}
.graph-foot > * { pointer-events: auto; }
.graph-legend {
  margin: 0; padding: 5px 10px; list-style: none; min-width: 0;
  display: flex; flex-wrap: wrap; gap: 4px 12px; pointer-events: none;
  font-size: 12px; color: var(--muted);
  background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--line); border-radius: 8px;
  transition: opacity 0.4s ease;
}
/* Its button, for a phone only (see the narrow styles). */
.legend-show { display: none; place-items: center; flex: none; width: 34px; height: 30px; padding: 0; }
.legend-show svg { width: 24px; height: 24px; fill: none; stroke-width: 2.2; }
.legend-show .k-session { stroke: var(--cat-lifecycle); }
.legend-show .k-agent { stroke: var(--cat-agent); }
.legend-show .k-command { stroke: var(--cat-message); stroke-linejoin: round; }
.legend-show .k-tasks { stroke: var(--cat-task); stroke-width: 1.8; }
/* Zoomed out to the other sessions, the legend fades away, and back. */
.graph-host.overview .graph-legend { opacity: 0; }
.glyph { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; border: 2px solid; background: var(--panel); }
.glyph.k-session { border-color: var(--cat-lifecycle); border-radius: 3px; }
.glyph.k-agent { border-color: var(--cat-agent); border-radius: 50%; }
.glyph.k-command { border-color: var(--cat-message); width: 9px; height: 9px; transform: rotate(45deg); }
.glyph.k-tasks { border-color: var(--cat-task); border-width: 1.5px; width: 16px; height: 9px; border-radius: 5px; }
.glyph.k-wait { width: 16px; height: 0; border: none; border-top: 2px dashed var(--cat-wait); background: none; vertical-align: middle; }
.graph-tip {
  position: absolute; z-index: 5; max-width: 300px; padding: 10px 12px; pointer-events: none;
  display: flex; flex-direction: column; gap: 4px; font-size: 12.5px;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.16);
}
.graph-tip[hidden] { display: none; }
.tip-head { display: flex; align-items: center; gap: 8px; }
.tip-head .dot { margin-top: 0; }
.tip-sub, .tip-muted { color: var(--muted); }
.tip-attention { color: var(--input); font-weight: 600; }
.tip-hint { color: var(--faint); font-size: 11.5px; margin-top: 2px; }

/* A node's details, in a dialog over the page (from the graph) */
.node-modal {
  width: min(640px, calc(100vw - 32px)); max-height: min(82vh, 900px); padding: 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
  box-shadow: 0 24px 64px rgb(0 0 0 / 0.3);
}
.node-modal::backdrop { background: rgb(0 0 0 / 0.42); }
.node-modal[open] { animation: modal-in 0.18s ease-out; }
.modal-box { position: relative; padding: 22px 24px 26px; }
.modal-box .detail-head h2 { padding-right: 36px; }
.modal-close {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border: none; border-radius: 8px;
  background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer;
}
.modal-close:hover { background: var(--panel-2); color: var(--text); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes halo { 0% { opacity: 0.9; transform: scale(0.85); } 100% { opacity: 0; transform: scale(1.5); } }
@keyframes march { to { stroke-dashoffset: -9; } }
@keyframes spot { 0% { background: color-mix(in srgb, var(--cat-task) 16%, transparent); } 100% { background: transparent; } }
@keyframes bump { 50% { transform: scale(1.3); } }
@keyframes needs-you {
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--input) 45%, transparent); border-color: var(--input); }
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes flash {
  0% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--completed) 45%, transparent); }
  100% { box-shadow: 0 0 0 4px transparent; }
}
@keyframes spotlight {
  0% { box-shadow: inset 3px 0 0 var(--input), 0 0 0 3px color-mix(in srgb, var(--input) 50%, transparent); }
  100% { box-shadow: inset 3px 0 0 var(--input), 0 0 0 3px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}

/* Narrower windows: the list and the view, and no details pane (a node's
   details open in the dialog instead: see `showDetails`). A phone has its
   own layout, below. */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 250px minmax(0, 1fr); }
}
@media (min-width: 721px) and (max-width: 1100px) {
  .layout > .detail { display: none; }
}
@media (max-width: 720px) {
  /* Content shorter than the window (a session's page, say) leaves the top
     bar and timeline their own height; the middle takes the rest. */
  .app { height: auto; min-height: 100%; overflow: visible; grid-template-rows: auto 1fr auto; }
  /* Stacked; the details, last, fill what's left above the timeline. */
  .layout { display: flex; flex-direction: column; }
  .layout > .detail { flex: 1 0 auto; max-height: none; }
  .layout > * { overflow: visible; }
  .sessions { border-right: none; border-bottom: 1px solid var(--line); }
  main { padding: 16px; }
  /* On a phone, the timeline's a drawer at the bottom of the screen:
     hidden at first, shown by the Timeline pill, hidden again by the
     arrow atop it (see `setTimelineOpen`). What's on the page leaves room
     for it (--timeline-room, set to its height while it's open). */
  .timeline {
    grid-template-areas: "steppers live" "track track" "caption caption"; grid-template-columns: auto 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding-top: 22px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgb(0 0 0 / 0.08);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  body.timeline-closed .timeline { transform: translateY(calc(100% + 12px)); }
  .timeline-hide {
    display: grid; place-items: center;
    position: absolute; top: 2px; left: 50%; transform: translateX(-50%);
    width: 44px; height: 20px; padding: 0; border: none; border-radius: 10px;
    background: none; color: var(--muted); cursor: pointer;
  }
  .timeline-hide svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .timeline-hide:hover { color: var(--text); background: var(--panel-2); }
  /* Shown while the timeline's hidden. */
  body.paged.timeline-closed .timeline-open { display: grid; }
  /* The page's own content clear of the drawer, while it's up. */
  body.paged .layout { padding-bottom: var(--timeline-room, 0px); }
  .legend { display: none; }
  /* The graph's legend, hidden at first behind its button (see
     `legendButton`); tapping it hides it again. */
  .graph-host .legend-show { display: grid; }
  .graph-host.legend-open .legend-show { display: none; }
  .graph-host:not(.legend-open) .graph-legend { display: none; }
  .graph-host.legend-open .graph-legend { pointer-events: auto; cursor: pointer; transform-origin: bottom left; animation: legend-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1); }
  .graph-host.overview .legend-show { opacity: 0; pointer-events: none; }
  /* The timeline's button, at the other end. */
  .graph-foot .timeline-open { margin-left: auto; }

  /* One page at a time: the list, or a session's page (its tree, details
     and timeline), with a way back. */
  body.paged .sessions, body.paged .brand { display: none; }
  /* A session's page is its tree; a node's details, tapped there, are a
     page of their own (see `nodePaged`), with Back to the session. */
  body.paged:not(.node-page) .detail { display: none; }
  body.node-page main { display: none; }
  body.node-page .layout > .detail { border-top: none; }
  body:not(.paged) main, body:not(.paged) .detail, body:not(.paged) .timeline { display: none; }
  body.paged .topbar { position: sticky; top: 0; z-index: 10; }

  /* Going between the list and a session's page (see `transition`): the
     page fades, the new one rising a little, while the session's name
     moves between the list and the heading. */
  ::view-transition-old(root) { animation: 160ms ease-out both page-out; }
  ::view-transition-new(root) { animation: 280ms 60ms cubic-bezier(0.2, 0.8, 0.2, 1) both page-in; }
  ::view-transition-group(session-name) { animation-duration: 340ms; animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1); }
  /* "Completed" moves between the list's head and the top bar. Only one of
     the two is ever shown, so they can share a name. */
  .done-toggle { view-transition-name: completed-toggle; }
  /* The status pill ("Live", "Reconnecting…") stays solid, gliding to where
     it is on the other page, rather than fading with it. */
  #mode { view-transition-name: mode-pill; }
  ::view-transition-group(completed-toggle), ::view-transition-group(mode-pill) {
    animation-duration: 340ms; animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  /* The name's two sizes, scaled between, rather than squashed. */
  ::view-transition-old(session-name), ::view-transition-new(session-name) { height: 100%; width: auto; object-fit: contain; }
}
@keyframes page-out { to { opacity: 0; } }
@keyframes page-in { from { opacity: 0; transform: translateY(10px); } }
.back-btn {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: -6px; padding: 6px 10px 6px 4px;
  background: none; border: none; border-radius: 8px;
  color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
}
.back-btn[hidden] { display: none; }
.topbar-end { display: flex; align-items: center; gap: 12px; }
#page-toggles[hidden] { display: none; }
.back-btn:hover { background: var(--accent-soft); }
.back-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@keyframes legend-in { from { opacity: 0; transform: translateY(6px) scale(0.96); } }
