/* Diagrams: the agent run (flow.js) and the phone line (callflow.js). Colours come from app.css tokens. */

/* ---------------------------------------------------------------- panel, tabs, controls */
.flow-card, .cf-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.cf-card .flow-caption { padding-top: 10px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.present-title { display: none; font-family: var(--display); font-weight: 600; font-size: 18px; letter-spacing: -0.01em; }
.present-title span { color: var(--muted); font-weight: 500; }
.tabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: 8px; }
.tab { font: inherit; font-size: 14px; font-weight: 500; color: var(--muted); background: transparent; cursor: pointer; border: 0; border-radius: 6px; min-height: 38px; padding: 0 14px; transition: color 140ms var(--ease-out), background-color 140ms var(--ease-out); }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.flow-ctrls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.flow-ctrls[hidden] { display: none; }
.ctl { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; font-weight: 500; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: var(--r-ctl); min-height: 36px; min-width: 38px; padding: 0 10px; cursor: pointer; justify-content: center; }
.ctl svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ctl:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }
.ctl:disabled { opacity: 0.45; cursor: not-allowed; }
.seg { display: inline-flex; }
.seg .ctl { border-radius: 0; margin-inline-start: -1px; font-family: var(--mono); font-size: 12px; }
.seg .ctl:first-child { border-radius: var(--r-ctl) 0 0 var(--r-ctl); margin-inline-start: 0; }
.seg .ctl:last-child { border-radius: 0 var(--r-ctl) var(--r-ctl) 0; }
.seg .ctl[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); position: relative; }
.pane-steps { padding: 8px 18px 18px; }
.pane-flow, .pane-call { display: flex; flex-direction: column; min-height: 0; }
.pane-call[hidden], .pane-flow[hidden], .pane-steps[hidden] { display: none; }

/* caption: one sentence about what is happening now */
.flow-caption { display: flex; align-items: baseline; gap: 10px; margin: 0; padding: 12px 18px 4px; min-height: 2.8em; font-size: 15px; color: var(--text); overflow: hidden; }
.flow-caption .cap-k { flex: none; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); }
.flow-caption .cap-t { min-width: 0; overflow: hidden; unicode-bidi: plaintext; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; line-clamp: 1; }
.flow-caption[data-tone="risk"] .cap-k { color: var(--warn); background: var(--warn-soft); }
.flow-caption[data-tone="ok"] .cap-k { color: var(--ok); background: var(--ok-soft); }
.flow-caption[data-tone="err"] .cap-k { color: var(--bad); background: var(--bad-soft); }

.flow-stage, .cf-stage { padding: 4px 12px 12px; min-height: 0; }
.flow-svg, .cf-svg { display: block; width: 100%; height: auto; }
.flow-dock { display: none; }

/* ---------------------------------------------------------------- presentation mode (full screen) */
body.flow-presenting { overflow: hidden; }
.flow-card.presenting { position: fixed; inset: 0; z-index: 50; border: 0; border-radius: 0; background: var(--bg); box-shadow: none; }
.presenting .panel-head { padding: 14px 28px; }
.presenting .present-title { display: block; }
.presenting .panel-foot, .presenting .head-title { display: none; }
.presenting .pane-flow { flex: 1; display: flex; }
.presenting .flow-caption { justify-content: center; font-size: 19px; padding: 14px 28px 0; }
.presenting .flow-stage { flex: 1; display: flex; padding: 6px 28px 10px; }
.presenting .flow-svg { height: 100%; max-height: 100%; }
.presenting .flow-dock { display: flex; flex-direction: column; gap: 4px; padding: 12px 28px 16px; border-top: 1px solid var(--border); background: var(--surface); }
.presenting .flow-dock .composer { max-width: 980px; width: 100%; margin: 0 auto; }
.presenting .flow-dock .status { max-width: 980px; width: 100%; margin: 0 auto; min-height: 0; }
.presenting .flow-dock .status:empty { display: none; }

/* ---------------------------------------------------------------- shared diagram look */
.flow-svg text, .cf-svg text { font-family: var(--sans); fill: var(--text); }
.fl-dot { fill: var(--dot); }
.t-sky { --tc: var(--accent); }
.t-risk { --tc: var(--warn); }
.t-ok { --tc: var(--ok); }
.t-err { --tc: var(--bad); }

/* edges */
.fe-base { fill: none; stroke: var(--border-strong); stroke-width: 1.5; transition: stroke 400ms var(--ease-out), stroke-opacity 400ms var(--ease-out); }
.fe-flow { fill: none; stroke: transparent; stroke-width: 1.5; stroke-dasharray: 2 6; stroke-linecap: round; }
.fe.is-hot .fe-base { stroke: var(--tc); stroke-opacity: 0.35; }
.fe.is-hot .fe-flow { stroke: var(--tc); animation: fl-dash 0.6s linear infinite; }
.fe.is-seen .fe-base { stroke: var(--tc); stroke-opacity: 0.45; }

/* nodes */
.fn { transition: opacity 300ms var(--ease-out); }
.fn-box { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.2; transition: stroke 220ms var(--ease-out), fill 220ms var(--ease-out); }
.fn-tile { fill: var(--surface-2); }
.fn-icon { fill: none; stroke: var(--text); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.fn-risk .fn-tile { fill: var(--warn-soft); }
.fn-risk .fn-icon { stroke: var(--warn); }
.flow-svg .fn-title { font-weight: 600; }
.flow-svg .fn-title.fn-mono { font-family: var(--mono); font-weight: 500; }
.flow-svg .fn-tag { fill: var(--faint); font-family: var(--mono); }
.flow-svg .fn-line { fill: var(--muted); font-family: var(--mono); }
.flow-svg [data-node="employee"] .fn-line, .flow-svg [data-node="guards"] .fn-line, .flow-svg [data-node="human"] .fn-line { font-family: var(--sans); font-size: 12.5px; }
.flow-svg [data-node="employee"] .fn-line:not(.c-ok) { fill: var(--text); }
.flow-svg .fn-line.c-ok { fill: var(--ok); }
.flow-svg .fn-line.c-err { fill: var(--bad); }
.flow-svg .fn-line.c-risk { fill: var(--warn); }
.flow-svg .fn-line.c-sky { fill: var(--accent); }

.running .fn { opacity: 0.5; }
.running .fn.is-active, .running .fn.is-hold, .running .fn-loop { opacity: 1; }
.fn.is-active .fn-box { stroke: var(--accent); stroke-width: 1.8; fill: var(--accent-soft); }
.fn-risk.is-active .fn-box { stroke: var(--warn); fill: var(--warn-soft); }
.fn.tone-ok .fn-box { stroke: var(--ok); }
.fn.tone-risk .fn-box { stroke: var(--warn); }
.fn.tone-err .fn-box { stroke: var(--bad); fill: var(--bad-soft); }
.fn.is-hold .fn-box { stroke: var(--accent); stroke-width: 1.8; stroke-dasharray: 6 4; animation: fl-march 1s linear infinite; }
.fl-ping { fill: none; stroke-width: 2; transform-box: fill-box; transform-origin: center; pointer-events: none; }

/* the loop */
.fl-halo { fill: none; stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; }
.fl-core { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.2; }
.fl-seg { fill: none; stroke: var(--surface-2); stroke-width: 7; stroke-linecap: round; transition: stroke 300ms var(--ease-out); }
.fl-seg.is-lit { stroke: var(--accent); }
.fl-seg.is-now { stroke: var(--accent); stroke-width: 9; }
.fl-mark { fill: var(--accent); }
.flow-svg .fl-cap { fill: var(--muted); font-weight: 500; }
.flow-svg .fl-big { font-family: var(--display); font-weight: 600; font-variant-numeric: tabular-nums; }
.flow-svg .fl-big-of { fill: var(--muted); font-weight: 500; }
.flow-svg .fl-status { font-family: var(--mono); fill: var(--text); }
.flow-svg .fl-status.c-ok { fill: var(--ok); }
.flow-svg .fl-status.c-err { fill: var(--bad); }
.flow-svg .fl-status.c-risk { fill: var(--warn); }
.fn-loop.tone-err .fl-core { stroke: var(--bad); }
.fl-done { transition: opacity 300ms var(--ease-out); }
.fl-done rect { fill: var(--ok-soft); stroke: var(--ok); stroke-width: 1; }
.flow-svg .fl-done text { fill: var(--ok); font-family: var(--mono); }
.flow-svg .fl-done .fl-done-2 { fill: var(--text); }

/* service lights, badge, reply chip */
.fl-lamp { fill: var(--surface-2); stroke: var(--border-strong); stroke-width: 1; transition: fill 250ms var(--ease-out); }
.fl-light.is-up .fl-lamp { fill: var(--ok); stroke: none; }
.fl-light.is-down .fl-lamp { fill: var(--bad); stroke: none; }
.fl-light.is-checked .fl-lamp { stroke: var(--text); stroke-width: 1.6; }
.flow-svg .fl-lamp-t { fill: var(--muted); }
.fl-badge circle { fill: var(--surface-2); stroke: var(--border-strong); transition: fill 250ms var(--ease-out); }
.fl-badge.is-on circle { fill: var(--warn); stroke: none; }
.flow-svg .fl-badge text { font-family: var(--mono); font-weight: 600; }
.flow-svg .fl-badge.is-on text { fill: var(--surface); }
.fl-chip-lang rect { fill: var(--ok-soft); stroke: var(--ok); stroke-width: 1; }
.flow-svg .fl-chip-lang text { fill: var(--ok); font-family: var(--mono); }
.fl-chip-lang.is-risk rect { fill: var(--warn-soft); stroke: var(--warn); }
.flow-svg .fl-chip-lang.is-risk text { fill: var(--warn); }
.flow-svg .fl-legend text { fill: var(--muted); }

/* particles */
.fp-trail { fill: none; stroke: var(--tc); stroke-linecap: round; }
.fp-head { fill: var(--surface); stroke: var(--tc); stroke-width: 2.6; }
.fp-chip rect { fill: var(--surface); stroke: var(--tc); stroke-width: 1.2; }
.flow-svg .fp-chip text, .cf-svg .fp-chip text { fill: var(--tc); font-family: var(--mono); font-weight: 500; }

/* ---------------------------------------------------------------- the phone line (callflow.js) */
.cf-region { fill: none; stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 4; }
.cf-region.gw { fill: var(--surface-2); fill-opacity: 0.55; stroke-dasharray: none; stroke: var(--border); }
.cf-svg .cf-region-t { fill: var(--faint); font-size: 12px; font-weight: 500; }
.cf-svg .cf-region-t tspan.k { fill: var(--muted); font-weight: 600; }
.cf-node .fn-box { fill: var(--surface); }
.cf-svg .cf-title { font-weight: 600; font-size: 14.5px; }
.cf-svg .cf-sub { fill: var(--muted); font-size: 12px; }
.cf-svg .cf-live { fill: var(--faint); font-family: var(--mono); font-size: 11.5px; }
.cf-svg .cf-live.on { fill: var(--accent); }
.cf-svg .cf-live.ok { fill: var(--ok); }
.cf-svg .cf-live.warn { fill: var(--warn); }
.cf-node.ext .fn-box { fill: var(--bg); stroke-dasharray: 4 3; }
.cf-node.is-active .fn-box { stroke: var(--accent); stroke-width: 1.8; fill: var(--accent-soft); }
.cf-node.is-warn .fn-box { stroke: var(--warn); stroke-width: 1.8; fill: var(--warn-soft); }
.cf-node.is-ok .fn-box { stroke: var(--ok); stroke-width: 1.8; fill: var(--ok-soft); }
.cf-node.is-busy .fn-box { stroke: var(--accent); stroke-width: 1.8; stroke-dasharray: 6 4; animation: fl-march 1s linear infinite; }
.cf-svg .cf-clock { font-family: var(--display); font-weight: 600; font-size: 34px; fill: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.cf-tall .cf-clock { font-size: 22px; }
.cf-rec circle { fill: var(--bad); }
.cf-rec { fill: var(--bad); opacity: 0; transition: opacity 200ms; }
.cf-rec.on { opacity: 1; }
.cf-meter rect { fill: var(--accent); }
.cf-tools text { font-family: var(--mono); font-size: 11.5px; fill: var(--muted); }
.cf-svg .cf-tools text.on { fill: var(--accent); }
.cf-svg .cf-tools text.done { fill: var(--ok); }
.cf-under { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px 24px; padding: 14px 18px 18px; border-top: 1px solid var(--border); }
.cf-transcript { min-width: 0; }
.cf-line { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 10px; margin: 0; padding: 6px 0; font-size: 14.5px; }
.cf-line .who { font-size: 12.5px; font-weight: 600; color: var(--muted); padding-top: 2px; }
.cf-line .txt { unicode-bidi: plaintext; text-align: start; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.cf-line[data-who="agent"] .txt { color: var(--text); }
.cf-line[data-who="caller"] .txt { color: var(--muted); }
.cf-timing { min-width: 0; font-size: 12.5px; }
.cf-bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; background: var(--surface-2); margin: 6px 0 8px; }
.cf-bar span { display: flex; align-items: center; padding: 0 6px; white-space: nowrap; overflow: hidden; font-family: var(--mono); font-size: 11px; color: #fff; transition: flex-basis 500ms var(--ease-out); }
.cf-bar .s-vad { background: var(--faint); }
.cf-bar .s-stt { background: color-mix(in srgb, var(--accent) 65%, var(--surface)); }
.cf-bar .s-think { background: var(--accent); }
.cf-bar .s-tts { background: var(--ok); }
:root[data-theme="dark"] .cf-bar span { color: #121214; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cf-bar span { color: #121214; } }
.cf-timing-h { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); }
.cf-timing-h strong { color: var(--text); font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.cf-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); }
.cf-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-inline-end: 5px; vertical-align: 0; }
.cf-samples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cf-samples-t { font-size: 13px; color: var(--muted); margin-inline-end: 4px; }

@keyframes fl-dash { to { stroke-dashoffset: -8; } }
@keyframes fl-march { to { stroke-dashoffset: -10; } }

@media (max-width: 760px) {
  .panel-head { padding: 8px 10px; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 0 8px; }
  .ctl-t { display: none; }
  .flow-caption { font-size: 13.5px; padding: 10px 14px 2px; min-height: calc(2 * 1.5em + 12px); align-items: flex-start; }
  .flow-caption .cap-t { -webkit-line-clamp: 2; line-clamp: 2; }
  .flow-stage, .cf-stage { padding: 2px 4px 8px; }
  .cf-under { grid-template-columns: 1fr; padding: 12px 14px 14px; }
  .presenting .panel-head { padding: 10px 12px; }
  .presenting .flow-stage, .presenting .flow-dock { padding-left: 10px; padding-right: 10px; }
  .presenting .flow-stage { overflow-y: auto; display: block; }
  .presenting .flow-svg { height: auto; max-height: none; }
  .presenting .flow-caption { font-size: 14px; justify-content: flex-start; padding: 8px 12px 0; }
}
@media (prefers-reduced-motion: reduce) {
  .fe.is-hot .fe-flow { animation: none; stroke-dasharray: none; }
  .fn.is-hold .fn-box, .cf-node.is-busy .fn-box { animation: none; }
}
