/* LangGraph Agent Running, built on the AI viewers' stylesheet. Opened full
   screen or in an iframe, which cannot see the site's own light/dim switch,
   so it follows the reader's system preference, as the Kubernetes viewers do. */

:root {
  --bg: #ffffff;
  --card: #ffffff;
  --border: #dfe3e8;
  --text: #22272e;
  --dim: #5f6b78;
  --accent: #326ce5;
  --btn: #f4f5f7;
  --panel: #0d2436;
  --panel-text: #eaf1f6;
  --raw: #f7f8fa;
  --flash: rgba(255, 196, 0, 0.3);
  --r-user: #326ce5;
  --r-assistant: #7a4fd0;
  --r-tool: #c96a12;
  --r-sys: #5f6b78;
  --k-function: #2f7d9a;
  --code: #0f8a6a;
  --mdl: #7a4fd0;
  --cal: #b0417e;
  --code-bg: #f6f8fa;
  --js: #0a6b3d;
  --jk: #1b4f9c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1d2b;
    --card: #112b40;
    --border: #234862;
    --text: #eaf1f6;
    --dim: #9fb2c2;
    --accent: #6f9bff;
    --btn: #16374f;
    --panel: #081b29;
    --raw: #0d2233;
    --flash: rgba(255, 196, 0, 0.18);
    --r-user: #7ea6ff;
    --r-assistant: #b79bff;
    --r-tool: #f0a050;
    --r-sys: #9fb2c2;
    --k-function: #6cc4e0;
    --code: #4fd1a8;
    --mdl: #b79bff;
    --cal: #f08cbc;
    --code-bg: #0d2233;
    --js: #8fe3a8;
    --jk: #9cc2ff;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.dim { color: var(--dim); font-weight: 400; }
.kv-app { padding: 0.5rem 16px 1rem; max-width: 1700px; margin: 0 auto; }
.kv-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.9rem; margin: 0 0 0.45rem; }
.kv-head h1 { font-size: 1.3rem; margin: 0; letter-spacing: -0.01em; }
.kv-head p { margin: 0; color: var(--dim); font-size: 0.92rem; }
.in-viewer .kv-head { display: none; }

/* --- controls */
.kv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin-bottom: 0.6rem; }
.kv-bar .count { font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; color: var(--dim); }
.kv-btn { background: var(--btn); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.35rem 0.9rem; font-size: 0.88rem; cursor: pointer; font-family: inherit; }
.kv-btn:hover:not(:disabled) { border-color: var(--accent); }
.kv-btn:disabled { opacity: 0.45; cursor: default; }
.kv-btn.play { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; min-width: 6rem; }
.kv-btn.go { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.kv-btn.tiny { padding: 0.05rem 0.45rem; font-size: 0.74rem; border-radius: 5px; }
.kv-app select { background: var(--btn); color: var(--text); border: 1px solid var(--border); border-radius: 7px;
  padding: 0.3rem 0.4rem; font-size: 0.86rem; font-family: inherit; min-width: 0; max-width: 100%; }

/* --- the events */
.log { list-style: none; margin: 0; padding: 0; }
.log-intro { font-size: 0.84rem; line-height: 1.45; }
.log-intro p { margin: 0 0 0.4rem; }
.log-intro .main { font-weight: 600; }
.log li { border-bottom: 1px dashed var(--border); }
.log-head { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 1.6rem minmax(0, 1fr) auto; gap: 0.4rem; align-items: baseline; padding: 0.15rem 0.3rem; cursor: pointer; }
.log-head::after { content: '▸'; color: var(--dim); font-size: 0.7rem; }
.log li.open .log-head::after { content: '▾'; }
.log-head:focus-visible { outline: 2px solid var(--accent); }
.log li:hover .log-head { background: color-mix(in srgb, var(--flash) 40%, transparent); }
.log li.now .log-head { background: color-mix(in srgb, var(--flash) 75%, transparent); }
.log li.now.open .log-body { background: color-mix(in srgb, var(--flash) 30%, transparent); }
.log-body { padding: 0.2rem 0.5rem 0.5rem 2.1rem; font-size: 0.8rem; line-height: 1.42; }
.log-body p { margin: 0 0 0.3rem; }
.log-body .main { font-weight: 600; font-size: 0.9rem; }
/* Bold inside a step's main line: the fact the step turns on, in the accent colour */
.log-body .main b { color: var(--accent); font-weight: 800; }
.log .n { color: var(--dim); font-family: ui-monospace, Menlo, monospace; font-size: 0.72rem; }
.log .scene { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--dim); padding: 0.5rem 0.3rem 0.15rem; border-bottom: none; }
.log-body ul.steps, .log-intro ul.steps { margin: 0 0 0.35rem; padding-left: 1.05rem; list-style: disc; }
.log-body ul.steps li, .log-intro ul.steps li { border: 0; margin: 0 0 0.15rem; }
.log-body ul.steps ul.steps, .log-intro ul.steps ul.steps { margin: 0.1rem 0; list-style: circle; }
.log code, .log-intro code { font-size: 0.92em; background: var(--code-bg); padding: 0 0.2em; border-radius: 3px; }



/* --- the stage: the users, the chat server, LangGraph and the services on
   top; the checkpointer and the events under them. Every card has a fixed
   size and scrolls. */
:root { --ta: #326ce5; --tb: #c96a12; --int: #c96a12; }
@media (prefers-color-scheme: dark) { :root { --ta: #7ea6ff; --tb: #f0a050; --int: #f0a050; } }
.al-stage { position: relative; display: grid; gap: 12px;
  grid-template-columns: minmax(0, 250px) minmax(0, 270px) minmax(0, 1fr) minmax(0, 230px);
  grid-template-rows: minmax(0, 60fr) minmax(0, 40fr);
  grid-template-areas: "user app run out" "bottom bottom bottom bottom";
  height: max(780px, calc(100vh - 6.2rem)); }
@media (min-width: 1101px) { .in-viewer .al-stage { height: max(780px, calc(100vh - 4.1rem)); } }
.al-user { grid-area: user; } .al-app { grid-area: app; } .al-run { grid-area: run; } .al-out { grid-area: out; }
.al-store { grid-area: store; } .al-log { grid-area: log; }
.al-bottom { grid-area: bottom; display: flex; min-width: 0; min-height: 0; }
.al-bottom .al-store { flex: 1 1 0; }
.al-bottom .al-log { flex: none; width: var(--log-w, 390px); }
.al-split { flex: none; width: 12px; cursor: col-resize; touch-action: none; position: relative; }
.al-split::after { content: ''; position: absolute; top: 50%; left: 4px; height: 44px; width: 4px; margin-top: -22px;
  border-radius: 2px; background: var(--border); }
.al-split:hover::after, .al-split:focus-visible::after, .al-split.drag::after { background: var(--accent); }
.al-split:focus-visible { outline: none; }
@media (max-width: 1100px) {
  .al-bottom { display: contents; }
  .al-bottom .al-log { width: auto; }
  .al-split { display: none; }
  .al-stage { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: auto;
    grid-template-rows: 560px 420px 400px 440px;
    grid-template-areas: "run run" "user app" "store store" "out log"; }
  .kv-bar { position: sticky; top: 0; z-index: 40; background: var(--bg); margin: 0 -16px 0.6rem; padding: 0.4rem 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
}
@media (max-width: 640px) {
  .kv-bar { gap: 0.35rem 0.5rem; }
  .kv-bar .kv-btn { padding: 0.3rem 0.7rem; }
  .kv-bar select { flex: 1 1 10rem; }
  .al-stage { grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 380px 380px 420px auto 440px;
    grid-template-areas: "run" "user" "app" "store" "out" "log"; }
  .al-stage .run-body { grid-template-columns: minmax(0, 1fr); overflow: visible; }
  .al-stage .loop { height: 280px; flex: none; }
  .al-stage .store-body { grid-template-columns: minmax(0, 1fr); }
}

.kv-card { display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden;
  border: 1px solid var(--border); border-radius: 12px; background: var(--card); font-size: 0.84rem;
  transition: box-shadow 0.25s, border-color 0.25s; }
.kv-card.here { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.kv-card > header { flex: none; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.45rem 0.7rem 0.4rem; border-bottom: 1px solid var(--border); }
.kv-card > header h2 { font-size: 0.92rem; margin: 0; flex: 1 1 10rem; min-width: 0; }
.kv-card > header h2 code { font-size: 0.72rem; color: var(--dim); font-weight: 400; margin-left: 0.3rem; }
.kv-card > header .turn { font-size: 0.8rem; padding: 0.2rem 0.6rem; animation: al-due 1.4s ease-in-out infinite; }
@keyframes al-due { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); } }
.kv-body { flex: 1; min-height: 0; overflow: auto; padding: 0.5rem 0.7rem; }
h3 { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--dim); margin: 0 0 0.35rem; }
.free, .empty, .idle { color: var(--dim); font-style: italic; font-size: 0.78rem; }
/* Each thread has a colour: its chat, its calls, its run, its versions, and what flies for it */
.ta { --tc: var(--ta); } .tb { --tc: var(--tb); }

/* --- the users: one chat per user, its thread above it */
.users { display: flex; flex-direction: column; gap: 0.6rem; }
.person { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; border-left: 4px solid var(--tc); padding-left: 0.45rem; }
.person .who { margin: 0 0 0.35rem; display: flex; align-items: center; gap: 0.45rem; }
.person .who b { font-size: 0.95rem; color: var(--tc); }
.person .who .dim { font-size: 0.72rem; }
.face { flex: none; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--tc); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 0.9rem; }
.chat { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 0.4rem; }
.bubble { max-width: 92%; padding: 0.4rem 0.6rem; border-radius: 12px; line-height: 1.38; font-size: 0.8rem; }
.bubble.user { align-self: flex-end; background: var(--tc); color: #fff; border-bottom-right-radius: 3px; }
.bubble.ai, .bubble.app { align-self: flex-start; background: var(--raw); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.bubble .by { display: block; font-style: normal; font-size: 0.64rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.15rem; color: var(--int); }
.bubble.ask { border-left: 4px solid var(--int); }
.choice { display: flex; gap: 0.35rem; margin-top: 0.3rem; }
.choice b { color: var(--code); }
.fake { border: 1px solid var(--int); color: var(--int); border-radius: 6px; padding: 0 0.45rem; font-size: 0.74rem; font-weight: 700; }
.fake.off { border-color: var(--border); color: var(--dim); }
.tools-row { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.2rem; font-size: 0.68rem; color: var(--dim); }
.regen.on { color: var(--accent); font-weight: 800; }

/* --- the chat server: what it does, and its calls to the graph */
.app-body { display: flex; flex-direction: column; gap: 0.6rem; }
.handler { flex: none; border: 1px solid var(--border); border-radius: 7px; padding: 0.35rem 0.5rem; background: var(--raw); }
.handler ul { margin: 0; padding-left: 1.05rem; font-size: 0.76rem; line-height: 1.35; }
.handler li { margin-bottom: 0.1rem; }
.handler li b { font-weight: 600; }
.calls ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.call { position: relative; border: 1px solid var(--border); border-left: 6px solid var(--tc); border-radius: 6px; padding: 0.25rem 0.5rem; }
.call p { margin: 0; font-size: 0.76rem; }
.call .chead code { font-size: 0.74rem; }
.call .args { margin: 0.1rem 0; display: grid; grid-template-columns: 6.6rem minmax(0, 1fr); gap: 0 0.4rem; font-size: 0.74rem; }
.call .args dt { font-family: ui-monospace, Menlo, monospace; color: var(--dim); }
.call .args dd { margin: 0; }
.call.open { border-left-style: solid; background: color-mix(in srgb, var(--tc) 9%, var(--card)); }
.call.open::before { content: ''; position: absolute; left: -6px; top: 0; bottom: 0; width: 6px;
  background: repeating-linear-gradient(180deg, var(--tc) 0 6px, transparent 6px 10px); animation: al-run 0.8s linear infinite; }
@keyframes al-run { to { background-position: 0 10px; } }
.call:not(.open) { opacity: 0.8; }
.cstat b { color: var(--tc); }
.ret { font-weight: 600; }
.ret b { border-radius: 5px; padding: 0 0.4rem; color: #fff; }
.ret.r-end b { background: var(--code); } .ret.r-int b { background: var(--int); }

/* --- LangGraph: the graph beside the state of each running call */
.run-body { display: grid; grid-template-columns: minmax(200px, 300px) minmax(0, 1fr); gap: 0.8rem; overflow: hidden; }
.graph, .runs { min-height: 0; display: flex; flex-direction: column; }
.runs { gap: 0.5rem; overflow: auto; }
.loop { width: 100%; height: 100%; min-height: 0; flex: 1; }
.loop .ge { fill: none; stroke: var(--dim); stroke-width: 1.6; opacity: 0.7; }
.loop marker path { fill: var(--dim); }
.loop .gl { font: 600 11px ui-monospace, Menlo, monospace; fill: var(--dim); text-anchor: middle; }
.loop .gn rect, .loop .gn circle { fill: var(--raw); stroke: var(--border); stroke-width: 1.5; transition: fill 0.3s; }
.loop .gn text { font: 700 16px -apple-system, 'Segoe UI', Roboto, sans-serif; fill: var(--text); text-anchor: middle; }
.loop .gn text.tag { font: 500 11px ui-monospace, Menlo, monospace; fill: var(--dim); }
.loop .gn text.side { font-size: 12px; text-anchor: start; font-weight: 600; fill: var(--dim); }
.loop .gn text.side.mid { text-anchor: middle; }
.loop .gn.term circle { fill: var(--dim); stroke: none; }
.loop .gn.at rect, .loop .gn.at circle { fill: var(--tc); stroke: var(--tc); }
.loop .gn.at text:not(.side) { fill: #fff; }
.loop .tok rect { fill: var(--tc); }
.loop .tok text { font: 700 10px ui-monospace, Menlo, monospace; fill: #fff; text-anchor: middle; }
.run { border: 1px solid var(--border); border-top: 4px solid var(--tc); border-radius: 7px; padding: 0.3rem 0.45rem; background: var(--raw);
  display: flex; flex-direction: column; min-height: 0; flex: 1 1 0; }
.run h3 { color: var(--tc); }
.next { margin: 0.3rem 0 0; font: 0.78rem ui-monospace, Menlo, monospace; }
.next b { color: var(--tc); }

.chips { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; min-height: 0; position: relative;
  display: flex; flex-direction: column; gap: 0.2rem; }
.chip { display: grid; grid-template-columns: 2.9rem minmax(0, 1fr); gap: 0.35rem; align-items: baseline;
  padding: 0.18rem 0.45rem; border-radius: 6px; border-left: 4px solid; background: var(--card); font-size: 0.76rem; }
.chip b { font: 700 0.7rem ui-monospace, Menlo, monospace; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.r-human { border-color: var(--r-user); } .chip.r-human b { color: var(--r-user); }
.chip.r-ai { border-color: var(--r-assistant); } .chip.r-ai b { color: var(--r-assistant); }
.chip.r-call { border-color: var(--r-assistant); } .chip.r-call b { color: var(--r-assistant); } .chip.r-call span { font-family: ui-monospace, Menlo, monospace; font-size: 0.72rem; }
.chip.r-tool { border-color: var(--code); } .chip.r-tool b { color: var(--code); }
.chip.lit { background: color-mix(in srgb, var(--flash) 90%, var(--card)); outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); }

/* --- outside our process */
.out-body { display: flex; flex-direction: column; gap: 0.5rem; }
.svc { border: 1px solid var(--border); border-left: 4px solid var(--k-function); border-radius: 7px; padding: 0.3rem 0.5rem; background: var(--raw); }
.svc.mdl { border-left-color: var(--mdl); }
.svc p { margin: 0; font-size: 0.76rem; color: var(--dim); }
.svc.busy { border-left-color: var(--int); }
.svc.busy p { color: var(--int); font-weight: 700; }
.svc .ev { color: var(--text); padding: 0.1rem 0.35rem; border-left: 3px solid var(--code); background: var(--card); border-radius: 3px; margin-top: 0.15rem; }
.svc.act, .handler.act, .insp.act { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }

/* --- the checkpointer: a row of versions per thread, and one version opened */
.store-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 330px); gap: 0.8rem; overflow: hidden; }
.rows { min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 0.3rem; }
.vthread h3 { color: var(--tc); margin: 0; }
.vscroll { overflow-x: auto; overflow-y: hidden; }
.vrow { display: block; }
.vrow .link { stroke: var(--tc); stroke-width: 2; fill: none; opacity: 0.6; }
.vrow .dot { cursor: pointer; }
.vrow .dot circle { fill: color-mix(in srgb, var(--tc) 14%, var(--card)); stroke: var(--tc); stroke-width: 2; }
.vrow .dot text { font: 700 11px ui-monospace, Menlo, monospace; fill: var(--text); text-anchor: middle; pointer-events: none; }
.vrow .dot text.nx { font-size: 9.5px; font-weight: 500; fill: var(--dim); }
.vrow .dot.side { opacity: 0.55; }
.vrow .dot.head circle { fill: var(--tc); stroke-width: 3; }
.vrow .dot.head text:not(.nx) { fill: #fff; }
.vrow .dot.waiting circle { stroke: var(--int); stroke-width: 3; stroke-dasharray: 4 3; }
.vrow .dot.sel circle { stroke: var(--text); stroke-width: 3; }
.vrow .dot:hover circle { stroke-width: 3.5; }
.insp { min-height: 0; overflow: auto; border: 1px solid var(--border); border-radius: 7px; padding: 0.35rem 0.5rem; background: var(--raw); display: flex; flex-direction: column; }
.insp .latest { background: var(--accent); color: #fff; border-radius: 5px; padding: 0 0.3rem; letter-spacing: 0; text-transform: none; }
.insp .meta { margin: 0 0 0.35rem; display: grid; grid-template-columns: 5.2rem minmax(0, 1fr); gap: 0 0.4rem; font-size: 0.76rem; }
.insp .meta dt { color: var(--dim); }
.insp .meta dd { margin: 0; font-family: ui-monospace, Menlo, monospace; }
.insp .wait { color: var(--int); font-family: -apple-system, 'Segoe UI', sans-serif; font-weight: 700; }
.insp .chips { overflow: visible; flex: none; }

/* --- a tour step's spotlight: what it names is outlined, the rest dims */
.al-stage.spotlight .kv-card:not(.here) { opacity: 0.35; transition: opacity 0.4s; }
.al-stage.spotlight .kv-card.al-log { opacity: 1; }
.al-stage.spotlight .act { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 8px; }
/* The graph needs no frame: in its step, it is the only thing lit on its card */
.al-stage.spotlight .graph.act { outline: none; }
.al-stage.spotlight .vrow .act, .al-stage.spotlight .loop .act { outline: none; }
.al-stage.spotlight .vrow .act circle { stroke: var(--accent); stroke-width: 4; }
.call.act { box-shadow: 0 0 0 3px color-mix(in srgb, var(--tc) 40%, transparent); }
.bubble.act { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.loop .gn.act rect, .loop .gn.act circle { stroke-width: 3; }

/* --- what is in the air: a message flying along its arrow, in its thread's colour */
#al-fly { position: absolute; left: 0; top: 0; width: 0; height: 0; overflow: visible; pointer-events: none; z-index: 50; }
#al-fly .trail { position: absolute; left: 0; top: 0; overflow: visible; }
#al-fly .trail polyline { fill: none; stroke: var(--tc, var(--accent)); stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 3 7; }
#al-fly .trail path { fill: var(--tc, var(--accent)); }
#al-fly .msg { position: absolute; transform: translate(-50%, -50%); background: var(--tc, var(--panel)); color: #fff;
  border-radius: 6px; padding: 0.12rem 0.5rem; font-size: 0.74rem; font-weight: 600; white-space: nowrap;
  font-family: ui-monospace, Menlo, Consolas, monospace; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3); }
.log a, .log-intro a { color: var(--accent); font-weight: 600; }
/* A full thread_id: a UUID, in the monospace font, wrapped anywhere rather than cut */
.uuid { font-family: ui-monospace, Menlo, monospace; text-transform: none; letter-spacing: 0; overflow-wrap: anywhere; }
.call .args dd.uuid { grid-column: 1 / -1; font-size: 0.66rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run h3 { display: flex; align-items: center; gap: 0.35rem; }
/* The running state's version, drawn as the latest version's dot is */
.vbadge { flex: none; }
.vbadge circle { fill: var(--tc); stroke: var(--tc); stroke-width: 2; }
.vbadge text { font: 700 11px ui-monospace, Menlo, monospace; fill: #fff; text-anchor: middle; letter-spacing: 0; }
