/* ============================================================
   MB-FLOW · "State-of-the-art custom agentic workflows" demo
   Temporal/n8n-style run view on a FIXED 520×325 design stage.
   The page scales the root; no scale logic in here ;  all px are
   design px. Consumes tokens.css + base.css primitives only.
   Every selector prefixed wf-.
   Semantics: green --act = deterministic rails / completed steps,
   cyan --see = the single agent judgment step, amber --warm = the
   rare escalate → human-review branch.
   ============================================================ */

.wf-app {
  position: absolute; left: 0; top: 0;
  width: 520px; height: 325px;
  overflow: hidden;
  background: var(--bg-1);
  font-family: var(--font-mono);
  user-select: none;
  display: flex; flex-direction: column;
}

/* ---------- titlebar ---------- */
.wf-titlebar {
  flex: none; height: 24px;
  display: flex; align-items: center; gap: 9px;
  padding: 0 11px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--line);
}
.wf-dots { display: inline-flex; gap: 4.5px; flex: none; }
.wf-dot { width: 6px; height: 6px; border-radius: 50%; display: block; opacity: 0.9; }
.wf-dot--r { background: var(--danger); }
.wf-dot--y { background: var(--warm); }
.wf-dot--g { background: var(--act); }
.wf-title {
  font-size: 9.5px; letter-spacing: 0.02em; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wf-title-dim { color: var(--fg-dim); }
.wf-run {
  margin-left: auto; flex: none;
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 9.5px; color: var(--fg-muted);
}
.wf-run-dot {
  width: 5px; height: 5px; border-radius: 50%; flex: none;
  background: var(--act);
  box-shadow: 0 0 6px var(--act-glow);
  animation: wf-dot-pulse 2.4s var(--ease-out) infinite;
}
.wf-run.is-tick { animation: wf-tickline 0.3s var(--ease-out); }

/* ---------- canvas (dot-grid DAG surface) ---------- */
.wf-canvas {
  position: relative; flex: 1 1 auto; min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle, var(--line) 1px, transparent 1.3px),
    radial-gradient(110% 80% at 6% 0%, var(--act-soft), transparent 52%),
    radial-gradient(110% 100% at 100% 100%, var(--see-soft), transparent 55%),
    var(--bg-1);
  background-size: 20px 20px, auto, auto, auto;
}

/* ---------- edges ---------- */
.wf-edges { position: absolute; inset: 0; width: 100%; height: 100%; }
.wf-e { fill: none; stroke: var(--line-2); stroke-width: 1.5; }
.wf-e--lane { stroke-dasharray: 3 4; }
.wf-el {
  fill: none; stroke-width: 2; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 100;
  transition: stroke-dashoffset 0.32s var(--ease);
}
.wf-el--act { stroke: var(--act); }
.wf-el--warm { stroke: var(--warm); }
.wf-el.is-on { stroke-dashoffset: 0; }

/* ---------- nodes ---------- */
.wf-node {
  position: absolute; width: 76px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.wf-node[data-wf-node="trigger"]  { left: 4px;   top: 80px; }
.wf-node[data-wf-node="fetch"]    { left: 76px;  top: 80px; }
.wf-node[data-wf-node="validate"] { left: 152px; top: 80px; }
.wf-node[data-wf-node="classify"] { left: 228px; top: 78px; }
.wf-node[data-wf-node="autofix"]  { left: 304px; top: 80px; }
.wf-node[data-wf-node="write"]    { left: 380px; top: 80px; }
.wf-node[data-wf-node="audit"]    { left: 452px; top: 80px; }
.wf-node[data-wf-node="escalate"] { left: 304px; top: 168px; }

.wf-body {
  position: relative; flex: none;
  width: 36px; height: 32px;
  border-radius: 7px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  display: grid; place-items: center;
  color: var(--fg-dim);
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease),
              color 0.25s var(--ease), background 0.25s var(--ease);
}
.wf-node--trigger .wf-body { border-radius: 12px; }
.wf-ic { width: 14px; height: 14px; }
.wf-ic path, .wf-ic circle, .wf-ic ellipse {
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* det step running: quick mechanical green flash */
.wf-node.is-run .wf-body {
  border-color: var(--act); color: var(--fg);
  box-shadow: 0 0 0 3px var(--act-soft), 0 2px 10px var(--act-glow);
}
/* completed: faint green edge + tick badge */
.wf-node.is-done .wf-body { border-color: var(--act-soft); color: var(--fg-muted); }

.wf-tick {
  position: absolute; top: -5px; right: -5px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--act); color: var(--act-ink);
  display: grid; place-items: center;
  box-shadow: 0 2px 6px var(--act-glow);
  transform: scale(0);
  transition: transform 0.22s var(--ease-out);
}
.wf-tick svg { width: 8px; height: 8px; display: block; }
.wf-tick svg path { fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.wf-node.is-done .wf-tick { transform: scale(1); }

.wf-name { font-size: 9.5px; line-height: 1; letter-spacing: 0.02em; color: var(--fg-muted); transition: color 0.25s var(--ease); }
.wf-node.is-done .wf-name, .wf-node.is-run .wf-name { color: var(--fg); }

.wf-tag {
  font-size: 7px; line-height: 1; font-weight: 500;
  letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--fg-dim);
  background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 3px;
  padding: 2px 4px; white-space: nowrap;
  transition: color 0.25s var(--ease), border-color 0.25s var(--ease), background 0.25s var(--ease);
}
/* deterministic chips turn green as their step completes ;  rails are green */
.wf-node.is-done .wf-tag--det { color: var(--act); border-color: var(--act-soft); }
.wf-tag--trig { text-transform: none; letter-spacing: 0.02em; }
.wf-node.is-done .wf-tag--trig { color: var(--fg-muted); }

/* ---------- the agent node (cyan, the ONE judgment step) ---------- */
.wf-node--agent .wf-body { width: 40px; height: 36px; }
.wf-tag--agent { color: var(--see); border-color: var(--see-soft); }
.wf-node--agent.is-run .wf-body {
  border-color: var(--see); color: var(--see);
  animation: wf-think 1.1s var(--ease) infinite;
}
.wf-node--agent.is-run .wf-tag--agent { background: var(--see-soft); }
.wf-node--agent.is-done .wf-body { border-color: var(--see-soft); color: var(--fg-muted); }
.wf-node--agent .wf-tick { background: var(--see); color: var(--see-ink); box-shadow: 0 2px 6px var(--see-glow); }
@keyframes wf-think {
  0%, 100% { box-shadow: 0 0 0 3px var(--see-soft), 0 2px 12px var(--see-glow); }
  50%      { box-shadow: 0 0 0 6px transparent,     0 2px 18px var(--see-glow); }
}

/* cyan detect brackets around the judgment step while it reasons */
.wf-detect {
  position: absolute; inset: -7px;
  --len: 7px; --thick: 1.5px; --inset: 0px;
  opacity: 0; transform: scale(1.08);
  transition: opacity 0.22s var(--ease-out), transform 0.22s var(--ease-out);
  pointer-events: none; z-index: 4;
}
.wf-detect.is-on { opacity: 1; transform: none; }

/* "reasoning…" chip floating above the agent node */
.wf-reason {
  position: absolute; bottom: 100%; left: 50%;
  transform: translate(-50%, 3px);
  margin-bottom: 10px;
  font-size: 8px; letter-spacing: 0.03em; white-space: nowrap;
  color: var(--see);
  background: var(--bg-2);
  border: 1px solid var(--see-soft); border-radius: 4px;
  padding: 2.5px 6px;
  opacity: 0;
  transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
  z-index: 5;
}
.wf-reason.is-on {
  opacity: 1; transform: translate(-50%, 0);
  animation: wf-shimmer 1.1s var(--ease) infinite;
}
@keyframes wf-shimmer {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* ---------- escalate node (amber, human review) ---------- */
.wf-tag--esc { text-transform: uppercase; }
.wf-node--esc.is-wait .wf-body {
  border-color: var(--warm-line); color: var(--warm);
  box-shadow: 0 0 0 3px var(--warm-soft), 0 2px 10px var(--warm-soft);
}
.wf-node--esc.is-wait .wf-name { color: var(--fg); }
.wf-node--esc.is-wait .wf-tag--esc { color: var(--warm); border-color: var(--warm-line); }
.wf-node--esc.is-wait .wf-body::after {
  content: ""; position: absolute; inset: -1px; border-radius: 7px;
  border: 1px solid var(--warm-line);
  animation: wf-wait 2s var(--ease-out) infinite;
}
@keyframes wf-wait {
  0%   { transform: scale(1);    opacity: 0.9; }
  100% { transform: scale(1.45); opacity: 0; }
}
.wf-badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 13px; height: 13px; border-radius: var(--r-pill);
  background: var(--warm); color: var(--bg);
  font-size: 8px; font-weight: 700; line-height: 13px; text-align: center;
  padding: 0 3px;
  transform: scale(0);
  transition: transform 0.25s var(--ease-out);
}
.wf-node--esc.is-wait .wf-badge { transform: scale(1); }

/* ---------- routing count pills, pinned on the branch edges ---------- */
.wf-count {
  position: absolute;
  font-size: 8px; font-weight: 700; line-height: 1;
  padding: 2.5px 5px; border-radius: var(--r-pill);
  background: var(--bg-1);
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.25s var(--ease-out);
  z-index: 5;
}
.wf-count.is-on { transform: translate(-50%, -50%) scale(1); }
.wf-count--act  { left: 305px; top: 96px;  color: var(--act);  border: 1px solid var(--act-soft); }
.wf-count--warm { left: 307px; top: 124px; color: var(--warm); border: 1px solid var(--warm-line); }

/* ---------- status strip ---------- */
.wf-status {
  flex: none; height: 22px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 11px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  font-size: 9px; letter-spacing: 0.01em;
}
.wf-s-dot {
  flex: none; width: 5px; height: 5px; border-radius: 50%;
  background: var(--act);
  box-shadow: 0 0 6px var(--act-glow);
  animation: wf-dot-pulse 2.4s var(--ease-out) infinite;
}
@keyframes wf-dot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.wf-s-line { display: inline-flex; align-items: baseline; gap: 5px; min-width: 0; }
.wf-s-line.is-tick { animation: wf-tickline 0.3s var(--ease-out); }
@keyframes wf-tickline { from { opacity: 0.15; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.wf-s-verb { font-weight: 700; flex: none; }
.wf-v--act  { color: var(--act); }
.wf-v--see  { color: var(--see); }
.wf-v--warm { color: var(--warm); }
.wf-v--dim  { color: var(--fg); }
.wf-s-sep { color: var(--fg-dim); flex: none; }
.wf-s-text { color: var(--fg-muted); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wf-s-ok { flex: none; color: var(--act); font-weight: 700; opacity: 0; transition: opacity 0.2s var(--ease); }
.wf-s-ok.is-on { opacity: 1; }
.wf-s-env { margin-left: auto; flex: none; font-size: 8px; color: var(--fg-dim); letter-spacing: 0.03em; }

/* ============================================================
   REDUCED MOTION · static end state (set by js/mb-flow.js)
   base.css zeroes durations; also stop ambient loops here.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .wf-run-dot, .wf-s-dot { animation: none; }
  .wf-node--agent.is-run .wf-body { animation: none; }
  .wf-node--esc.is-wait .wf-body::after { animation: none; opacity: 0; }
  .wf-reason.is-on { animation: none; }
}
