/* Demo viewer. Tokens follow the landing page (website/index.html).
   Always light, even when the OS is in dark mode: easier to read on a projector. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #2c313a;
  --muted: #6b7280;
  --rule: #ebedf0;
  --rule-strong: #c9ced6;
  --accent: #3a75b0;
  --code-bg: #f7f8fa;
  --panel: #fbfbfc;
  --node-bg: #ffffff;
  --thinking: #2a78d6;
  --exec: #b87800;
  --msg: #eb6834;
  --bad: #c43c3b;
  --s1: #2a78d6;
  --s2: #eb6834;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
button, select {
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  padding: .3rem .7rem;
  cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, .node:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; }

/* --- header ------------------------------------------------------------------- */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem 1.5rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--rule);
}
.crumbs { font-weight: 600; }
.crumbs a { color: var(--fg); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { color: var(--muted); margin: 0 .35rem; }
.pickers { display: flex; flex-wrap: wrap; gap: .8rem; }
.pickers label { color: var(--muted); font-size: .9rem; }
.pickers select { margin-left: .3rem; color: var(--fg); }
.detail { display: flex; align-items: center; gap: 0; margin-left: auto; }
.detail-label { color: var(--muted); font-size: .9rem; margin-right: .5rem; }
.detail button { border-radius: 0; margin-left: -1px; font-size: .9rem; }
.detail button:first-of-type { border-radius: 6px 0 0 6px; }
.detail button:last-of-type { border-radius: 0 6px 6px 0; }
.detail button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); position: relative; }

/* --- stage -------------------------------------------------------------------- */
.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(20rem, 30rem);
  grid-template-areas: "graph panel";
}
.stage[data-level="1"] { grid-template-columns: minmax(0, 1fr); grid-template-areas: "graph"; }
.stage[data-level="1"] .panel { display: none; }

.graph-wrap { grid-area: graph; position: relative; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: .8rem 1rem 0; }
.run-head h1 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.run-head p { margin: .1rem 0 0; font-size: .88rem; }
.run-head p a { color: var(--accent); text-decoration: none; }
.run-head p a:hover { text-decoration: underline; }
.status { position: absolute; inset: 40% 0 auto; text-align: center; color: var(--muted); }
#graph { flex: 1; min-height: max(12rem, 45%); width: 100%; }

.legend { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; margin: 0; padding: .3rem 0 .6rem; list-style: none; font-size: .8rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .35rem; }
.lg { display: inline-block; width: 14px; height: 10px; border-radius: 3px; border: 2px solid var(--rule-strong); }
.lg.thinking { border-color: var(--thinking); }
.lg.exec { border-color: var(--exec); }
.lg.dormant { border-style: dashed; opacity: .6; }
.lg.msg { background: var(--msg); border-color: var(--msg); }
.lg.transit, .lg.peer { border: 0; height: 2px; border-radius: 0; background: var(--muted); }
.lg.peer { height: 4px; background: none; border-top: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); }

/* graph */
.edge { stroke: var(--rule-strong); stroke-width: 2; }
.edge.peer { stroke-width: 2; stroke-dasharray: none; }
.edge.transit { stroke: var(--muted); stroke-width: 1.6; }
.edge.peer { stroke: var(--muted); stroke-width: 4.5; }
.edge.pseudo { stroke-dasharray: 3 5; }
.arrowhead { fill: var(--muted); }

.node { cursor: pointer; }
.node.pseudo { cursor: default; }
.node .box { fill: var(--node-bg); stroke: var(--rule-strong); stroke-width: 1.5; transition: stroke .2s, opacity .3s; }
.node .halo { fill: none; stroke: none; }
.node .label { text-anchor: middle; dominant-baseline: middle; font-weight: 600; font-size: 15px; fill: var(--fg); }
.node .status { text-anchor: middle; font-size: 11.5px; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }
.node.pseudo .box { stroke-dasharray: 4 3; }
.node.pseudo .label { font-weight: 500; font-size: 13px; fill: var(--muted); }
.node[data-state="thinking"] .box { stroke: var(--thinking); stroke-width: 2.5; }
.node[data-state="thinking"] .halo { stroke: var(--thinking); stroke-width: 2; animation: pulse 1.4s ease-in-out infinite; }
.node[data-state="exec"] .box { stroke: var(--exec); stroke-width: 2.5; }
.node[data-state="exec"] .status { fill: var(--exec); }
.node[data-state="thinking"] .status { fill: var(--thinking); }
.node .status.cmd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; fill: var(--exec); }
.node:not([data-state="exec"]) .status.cmd { fill: var(--muted); }
.node[data-state="dormant"] .box { stroke-dasharray: 5 4; opacity: .6; }
.node[data-state="dormant"] .label { opacity: .6; }
.node.selected .box { stroke-width: 3; }
.node.selected .label { text-decoration: underline; text-underline-offset: 3px; }
@keyframes pulse { 0%, 100% { opacity: .15; } 50% { opacity: .8; } }
@media (prefers-reduced-motion: reduce) { .node .halo { animation: none !important; opacity: .5; } }

.inbox circle { fill: var(--msg); stroke: var(--bg); stroke-width: 2; }
.inbox text { text-anchor: middle; font-size: 11px; font-weight: 700; fill: #fff; }
.dot rect { fill: var(--msg); stroke: var(--bg); stroke-width: 2; }
.dot path { fill: none; stroke: #fff; stroke-width: 1.4; }
.dot.human rect { fill: var(--muted); }

/* chart */
.chart-wrap { position: relative; padding: 0 0 .6rem; max-width: 46rem; }
.chart-title { font-size: .85rem; font-weight: 600; }
.chart-legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); }
.chart-legend span, .tooltip div { display: flex; align-items: center; gap: .35rem; }
.sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; }
.sw.s1 { background: var(--s1); }
.sw.s2 { background: var(--s2); }
.chart { width: 100%; height: auto; display: block; }
.chart .grid line { stroke: var(--rule); stroke-width: 1; }
.chart .tick, .chart .end-label { font-size: 11px; fill: var(--muted); }
.chart .end-label { fill: var(--fg); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .line.s1, .chart .marker.s1 { stroke: var(--s1); }
.chart .line.s2, .chart .marker.s2 { stroke: var(--s2); }
.chart .marker { fill: var(--bg); stroke-width: 2; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.tooltip { position: absolute; pointer-events: none; background: var(--bg); border: 1px solid var(--rule-strong); border-radius: 6px; padding: .35rem .55rem; font-size: .8rem; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.tip-head { font-weight: 600; }

/* --- agent panel ---------------------------------------------------------------- */
.panel { grid-area: panel; display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--rule); background: var(--panel); }
.panel-top { display: flex; align-items: flex-start; gap: .5rem; padding: .8rem 1rem .6rem; border-bottom: 1px solid var(--rule); }
.panel-head { flex: 1; min-width: 0; }
.panel-title { font-size: 1.15rem; font-weight: 700; }
.panel-meta { display: flex; flex-wrap: wrap; gap: .3rem .7rem; align-items: center; font-size: .82rem; }
.follow { font-size: .8rem; padding: .2rem .55rem; display: none; }
.panel.pinned .follow { display: block; }
.chip { font-weight: 600; font-size: .78rem; padding: .05rem .5rem; border-radius: 999px; border: 1.5px solid var(--rule-strong); }
.chip.state-thinking { border-color: var(--thinking); color: var(--thinking); }
.chip.state-exec { border-color: var(--exec); color: var(--exec); }
.chip.state-dormant { border-style: dashed; color: var(--muted); }

.panel-list { list-style: none; margin: 0; padding: .4rem 1rem 1rem; overflow-y: auto; min-height: 0; flex: 1; }
.entry { padding: .55rem 0; border-bottom: 1px solid var(--rule); font-size: .88rem; overflow-wrap: anywhere; }
.entry .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .78rem; margin-right: .5rem; }
.entry .reason { color: var(--muted); font-style: italic; margin-bottom: .15rem; }
.entry.exec .cmd code { background: var(--code-bg); padding: .1rem .35rem; border-radius: 4px; border-left: 3px solid var(--exec); }
.entry pre { background: var(--code-bg); padding: .5rem .6rem; border-radius: 5px; overflow-x: auto; max-height: 18rem; white-space: pre-wrap; margin: .3rem 0 0; }
.entry .output summary, .entry.prompt summary { cursor: pointer; color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.exit-bad { color: var(--bad); font-weight: 600; }
.entry.message .msg-head, .entry.delivered .msg-head { font-weight: 600; color: var(--msg); }
.entry.delivered .msg-head { color: var(--fg); }
.msg-text, .prose { white-space: pre-wrap; margin-top: .15rem; }
.entry.message .msg-text, .entry.delivered .msg-text { padding-left: .6rem; border-left: 3px solid var(--msg); }
.entry.delivered .msg-text { border-left-color: var(--rule-strong); }
.entry.state, .entry.idle, .entry.turn, .entry.warning { color: var(--muted); font-size: .84rem; }
.entry.state { color: var(--fg); font-weight: 500; }
.entry.turn { text-align: center; padding: .25rem 0; border-bottom: 0; font-size: .75rem; letter-spacing: .04em; }
.entry.warning { color: var(--bad); }
.empty { color: var(--muted); padding: 1rem 0; font-size: .9rem; }

/* --- message spotlight ---------------------------------------------------------------- */
/* A fixed share of the left column, so the graph never resizes as messages come and go. */
.spotlight {
  flex: 0 0 38%;
  min-height: 9rem;
  display: flex;
  flex-direction: column;
  margin: 0 0 .8rem;
  padding: .8rem 1.2rem .9rem;
  border: 1px solid var(--rule-strong);
  border-left: 6px solid var(--msg);
  border-radius: 10px;
  background: var(--bg);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .06);
}
.spotlight.idle { border-left-color: var(--rule-strong); box-shadow: none; }
.spotlight.idle .spot-text { color: var(--muted); font-size: 1rem; }
.spot-top { display: flex; align-items: baseline; gap: 1rem; }
.spot-head { flex: 1; font-size: 1.35rem; font-weight: 700; }
.spot-head .from { color: var(--msg); }
.spot-count { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.spot-reason { margin: .2rem 0 0; color: var(--muted); font-style: italic; font-size: 1rem; }
.spot-text {
  flex: 1;
  min-height: 0;
  margin-top: .5rem;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: clamp(1.05rem, 1.25vw, 1.4rem);
  line-height: 1.5;
}
.spot-bar { height: 4px; margin-top: .6rem; background: var(--rule); border-radius: 2px; overflow: hidden; }
.spot-bar i { display: block; height: 100%; width: 0; background: var(--msg); }
.spotlight.idle .spot-bar { visibility: hidden; }

/* graph focus while a message is up */
#graph.focusing .node:not(.focus) { opacity: .35; }
#graph.focusing .edge:not(.focus) { opacity: .35; }
#graph.focusing .node .status { visibility: hidden; } /* the clock is held; keep the arrow clear */
.edge.focus { visibility: hidden; } /* replaced by the directional .focus-arrow */
.focus-arrow { stroke: var(--msg); stroke-width: 4; }
.msg-arrowhead { fill: var(--msg); }
.node.focus .box { stroke: var(--msg); stroke-width: 3; }

/* --- transport ---------------------------------------------------------------------- */
.transport { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .8rem; padding: .55rem 1rem; border-top: 1px solid var(--rule); }
.transport .primary { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; min-width: 5rem; }
.transport .speed, .transport .check { color: var(--muted); font-size: .9rem; display: flex; align-items: center; gap: .3rem; }
.scrub { position: relative; flex: 1; min-width: 12rem; display: flex; align-items: center; }
.scrub input { width: 100%; position: relative; accent-color: var(--accent); }
.ticks { position: absolute; left: 8px; right: 8px; top: 50%; height: 14px; transform: translateY(-50%); pointer-events: none; }
.ticks i { position: absolute; width: 2px; height: 100%; background: var(--msg); opacity: .55; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }

/* --- reports dialog -------------------------------------------------------------------- */
dialog { width: min(52rem, calc(100vw - 2rem)); max-height: calc(100vh - 3rem); padding: 0; border: 1px solid var(--rule-strong); border-radius: 10px; background: var(--bg); color: var(--fg); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dialog-head { display: flex; gap: .5rem; align-items: center; padding: .6rem .8rem; border-bottom: 1px solid var(--rule); }
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; flex: 1; }
.tabs button { font-size: .85rem; padding: .2rem .6rem; }
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.report { padding: .5rem 1.4rem 1.4rem; overflow-y: auto; max-height: calc(100vh - 8rem); }
.report pre { background: var(--code-bg); padding: .6rem; border-radius: 6px; overflow-x: auto; }
.report table { border-collapse: collapse; }
.report td, .report th { border: 1px solid var(--rule); padding: .2rem .5rem; }

/* --- narrow screens ---------------------------------------------------------------------- */
@media (max-width: 900px) {
  body { height: auto; }
  .stage, .stage[data-level="1"] { display: flex; flex-direction: column; }
  #graph { min-height: 18rem; }
  .panel { border-left: 0; border-top: 1px solid var(--rule); max-height: 60vh; }
  .spotlight { flex-basis: auto; max-height: 60vh; }
  .detail { margin-left: 0; }
  .transport { position: sticky; bottom: 0; background: var(--bg); }
}
