/* ---------- 工作流画布 ---------- */
.wf-canvas { position: absolute; inset: 0; overflow: hidden; user-select: none; }
.wf-viewport {
  position: absolute; inset: 0; cursor: grab; touch-action: none;
  background-image: radial-gradient(circle, rgba(255, 255, 255, .085) 1px, transparent 1.4px);
  background-size: 22px 22px;
}
.wf-viewport.panning { cursor: grabbing; }
.wf-world { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.wf-svg { position: absolute; top: 0; overflow: visible; pointer-events: none; }

/* 连线 */
.wf-edge-path { fill: none; stroke: #2e3a4f; stroke-width: 2; transition: stroke .3s, opacity .3s; }
.wf-edge.branch-no .wf-edge-path { stroke: #3e3342; }
.wf-edge.flowing .wf-edge-path {
  stroke: var(--brand); stroke-dasharray: 7 7;
  animation: wf-dash .45s linear infinite;
  filter: drop-shadow(0 0 4px rgba(240, 185, 11, .7));
}
.wf-edge.taken .wf-edge-path { stroke: rgba(240, 185, 11, .7); filter: drop-shadow(0 0 3px rgba(240, 185, 11, .35)); }
.wf-edge.skipped .wf-edge-path { stroke-dasharray: 4 6; opacity: .35; }
.wf-edge.wf-hidden { opacity: 0; }
@keyframes wf-dash { to { stroke-dashoffset: -28; } }
.wf-pulse { fill: url(#wf-pulse-g); filter: drop-shadow(0 0 8px rgba(240, 185, 11, .9)); }
.wf-trail { fill: #f0b90b; }

/* 节点 */
.wf-nodes { position: absolute; top: 0; left: 0; }
.wf-node {
  --cat: #5b8dff;
  position: absolute; top: 0; left: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; border-radius: 12px;
  background: linear-gradient(180deg, #1a1f27, #151920);
  border: 1px solid color-mix(in srgb, var(--cat) 42%, #262d39);
  box-shadow: 0 0 14px color-mix(in srgb, var(--cat) 16%, transparent), 0 8px 20px rgba(0, 0, 0, .35);
  cursor: pointer;
  transition: opacity .3s, border-color .25s, box-shadow .25s, filter .3s, scale .2s;
}
.wf-node:hover { border-color: color-mix(in srgb, var(--cat) 75%, #262d39); }
.cat-trigger { --cat: #2ebd85; --cat-bg: rgba(46, 189, 133, .14); }
.cat-data { --cat: #5b8dff; --cat-bg: rgba(91, 141, 255, .14); }
.cat-analysis { --cat: #9b7bff; --cat-bg: rgba(155, 123, 255, .14); }
.cat-security { --cat: #22c3d6; --cat-bg: rgba(34, 195, 214, .14); }
.cat-condition { --cat: #f0b90b; --cat-bg: rgba(240, 185, 11, .14); }
.cat-execution { --cat: #ff8a3d; --cat-bg: rgba(255, 138, 61, .14); }
.cat-notify { --cat: #8b9bb4; --cat-bg: rgba(139, 155, 180, .14); }
.wf-node-icon {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 9px;
  background: color-mix(in srgb, var(--cat) 15%, transparent); color: var(--cat);
}
.wf-node-icon .icon { width: 18px; height: 18px; }
.wf-node-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.wf-node-title { font-size: 13px; font-weight: 600; color: #e8ecf2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-node-sub { font-size: 11.5px; color: #7c8899; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: color .2s; }
.wf-node-sub.result { color: #c6cfdb; }
.wf-node-status { position: absolute; top: 8px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: transparent; transition: background .2s; }
.wf-node-hint { position: absolute; top: -9px; right: -9px; display: none; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--yellow); color: #181a20; }
.wf-node-ver {
  position: absolute; top: -9px; left: 12px; padding: 0 6px; border-radius: 6px;
  background: var(--yellow); color: #181a20; font-size: 10.5px; font-weight: 700; line-height: 17px;
  animation: wf-ver-in .4s cubic-bezier(.3, 1.6, .5, 1);
}
@keyframes wf-ver-in { from { opacity: 0; scale: .5; } }

.wf-node.wf-hidden { opacity: 0; pointer-events: none; }
.wf-node.wf-pop { animation: wf-pop .5s cubic-bezier(.2, 1.3, .4, 1) both; }
@keyframes wf-pop {
  0% { opacity: 0; scale: .82; filter: blur(3px); box-shadow: 0 0 0 0 color-mix(in srgb, var(--cat) 60%, transparent); }
  55% { opacity: 1; scale: 1.04; filter: blur(0); box-shadow: 0 0 0 8px color-mix(in srgb, var(--cat) 0%, transparent), 0 0 28px color-mix(in srgb, var(--cat) 45%, transparent); }
  100% { scale: 1; }
}
.wf-node.wf-leave { opacity: 0; scale: .85; transition: opacity .3s, scale .3s; }
.wf-node.wf-flash { animation: wf-flash 1.6s ease-out; }
@keyframes wf-flash {
  0%, 40% { border-color: var(--yellow); box-shadow: 0 0 0 4px rgba(252, 213, 53, .25), 0 0 34px rgba(252, 213, 53, .45); background: #2a2614; }
  100% { box-shadow: 0 0 14px color-mix(in srgb, var(--cat) 16%, transparent); }
}
.wf-node.is-selected { box-shadow: 0 0 0 2px rgba(240, 185, 11, .75), 0 0 22px rgba(240, 185, 11, .25); }
.wf-node.is-editing { border-color: var(--yellow); }
.wf-node.is-editing::after, .wf-node.is-running::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(100deg, transparent 20%, rgba(252, 213, 53, .14) 45%, transparent 70%) 0 0 / 250% 100%;
  animation: wf-sweep 1.1s linear infinite;
}
@keyframes wf-sweep { from { background-position: 150% 0; } to { background-position: -100% 0; } }

/* 运行状态 */
.wf-node.is-pending { opacity: .5; }
.wf-node.is-running {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(240, 185, 11, .18), 0 0 30px rgba(240, 185, 11, .4);
  scale: 1.03;
}
.wf-node.is-running .wf-node-status { background: var(--brand); animation: wf-blink .8s ease-in-out infinite; }
.wf-node.is-success { border-color: rgba(46, 189, 133, .75); animation: wf-ok .6s ease-out; }
.wf-node.is-success .wf-node-status { background: var(--green); }
.wf-node.is-warn { border-color: rgba(240, 185, 11, .7); }
.wf-node.is-warn .wf-node-status { background: var(--brand); }
.wf-node.is-error { border-color: rgba(246, 70, 93, .8); box-shadow: 0 0 22px rgba(246, 70, 93, .35); animation: wf-shake .4s; }
.wf-node.is-error .wf-node-status { background: var(--red); }
.wf-node.is-error .wf-node-sub { color: #ff9aa9; }
.wf-node.is-skipped { opacity: .34; filter: grayscale(.7); }
@keyframes wf-blink { 50% { opacity: .3; } }
@keyframes wf-ok { 0% { box-shadow: 0 0 0 0 rgba(46, 189, 133, .6), 0 0 30px rgba(46, 189, 133, .5); } 100% { box-shadow: 0 0 0 10px rgba(46, 189, 133, 0), 0 0 14px color-mix(in srgb, var(--cat) 16%, transparent); } }
@keyframes wf-shake { 25% { translate: -3px 0; } 75% { translate: 3px 0; } }

/* 批注模式 */
.annotating .wf-viewport { cursor: default; }
.annotating .wf-node { cursor: crosshair; }
.annotating .wf-node:hover { border-style: dashed; border-color: var(--yellow); }
.annotating .wf-node:hover .wf-node-hint { display: grid; }
.annotating .wf-plus { opacity: 0; pointer-events: none; }

/* 标签与加号 */
.wf-overlay { position: absolute; top: 0; left: 0; transition: opacity .3s; }
.wf-overlay.wf-hidden { opacity: 0; pointer-events: none; }
.wf-overlay.wf-fade { animation: wf-fade .45s ease-out; }
@keyframes wf-fade { from { opacity: 0; } }
.wf-label {
  position: absolute; top: 0; left: 0; translate: -50% -50%;
  padding: 2px 8px; border-radius: 10px; white-space: nowrap;
  font-size: 11px; line-height: 16px;
  background: #151b25; border: 1px solid #2c3546; color: #93a6c2;
}
.wf-label.yes { color: #7fd8b1; border-color: rgba(46, 189, 133, .35); }
.wf-label.no { color: #f0a0ac; border-color: rgba(246, 70, 93, .3); }
.wf-plus {
  position: absolute; top: 0; left: 0; translate: -50% -50%;
  display: grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: #12161c; border: 1px solid #364156; color: #6f7d92;
  opacity: .7; transition: opacity .15s, background .15s, color .15s, scale .15s;
}
.wf-plus .icon { width: 12px; height: 12px; stroke-width: 2.4; }
.wf-plus:hover { opacity: 1; scale: 1.25; background: var(--yellow); border-color: var(--yellow); color: #181a20; }
.running .wf-plus, .building .wf-plus { opacity: 0; pointer-events: none; }

/* 顶部工具与缩放 */
.wf-topbar { position: absolute; top: 12px; right: 12px; z-index: 6; display: flex; align-items: center; gap: 8px; }
.wf-badge { padding: 5px 10px; border-radius: 8px; background: rgba(29, 33, 39, .9); border: 1px solid var(--line); font-size: 12px; color: var(--text-3); white-space: nowrap; }
.building .wf-badge { color: var(--brand); border-color: rgba(240, 185, 11, .4); }
.wf-annotate {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 8px;
  background: rgba(29, 33, 39, .9); border: 1px solid var(--line); font-size: 13px; color: var(--text-2);
}
.wf-annotate:hover { color: var(--text); border-color: #4a505a; }
.annotating .wf-annotate { border-color: rgba(240, 185, 11, .6); background: rgba(240, 185, 11, .1); color: var(--brand); }
.wf-zoom {
  position: absolute; right: 12px; bottom: 12px; z-index: 6;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px; border-radius: 10px; background: rgba(29, 33, 39, .92); border: 1px solid var(--line);
}
.wf-zoom button { display: grid; place-items: center; width: 30px; height: 28px; border-radius: 6px; color: var(--text-2); }
.wf-zoom button:hover { background: rgba(255, 255, 255, .07); color: var(--text); }
.wf-zoom span { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.wf-zoom i { width: 20px; height: 1px; margin: 3px 0; background: var(--line-strong); }
.wf-runbar {
  position: absolute; left: 12px; bottom: 12px; z-index: 6;
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 90px);
  padding: 6px 12px; border-radius: 9px; background: rgba(29, 33, 39, .92); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--text-2); animation: msg-in .25s ease-out;
}
.wf-runbar span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-runbar .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--text-4); }
.wf-runbar.live { border-color: rgba(240, 185, 11, .45); }
.wf-runbar.live .dot { background: var(--brand); animation: wf-blink .8s infinite; }
.wf-runbar.done .dot { background: var(--green); }
.wf-runbar.error .dot { background: var(--red); }

/* 生成中的骨架 */
.wf-ghost { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; background: rgba(15, 17, 21, .55); }
.ghost-flow { display: flex; flex-direction: column; align-items: center; }
.ghost-node {
  width: 220px; height: 44px; border-radius: 11px;
  border: 1px solid #262d39;
  background: linear-gradient(100deg, #161a21 30%, #222936 50%, #161a21 70%) 0 0 / 250% 100%;
  animation: wf-sweep 1.4s linear infinite, ghost-in .5s ease-out both;
}
.ghost-link { width: 2px; height: 18px; background: linear-gradient(#2e3a4f, transparent); }
@keyframes ghost-in { from { opacity: 0; transform: translateY(6px); } }
.ghost-caption { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 10px; background: rgba(29, 33, 39, .95); border: 1px solid rgba(240, 185, 11, .35); font-size: 13px; color: var(--brand); }
.ghost-caption b { font-weight: 500; color: var(--text-3); font-variant-numeric: tabular-nums; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(240, 185, 11, .25); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 浮层 */
.wf-pop {
  position: absolute; z-index: 20;
  padding: 12px; border-radius: 12px;
  background: #1d2128; border: 1px solid var(--line-strong);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .55);
  animation: pop .14s ease-out; user-select: text;
}
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pop-head b { font-size: 14px; }
.pop-x { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; color: var(--text-3); }
.pop-x:hover { background: rgba(255, 255, 255, .07); color: var(--text); }
.pop-node { display: flex; align-items: center; gap: 6px; margin: 8px 0; padding: 6px 8px; border-radius: 8px; background: rgba(240, 185, 11, .08); font-size: 12.5px; color: var(--brand); }
.pop-input {
  width: 100%; padding: 10px; border-radius: 9px; resize: none;
  border: 1px solid var(--line-strong); background: #15181d; color: var(--text);
  font: inherit; font-size: 13.5px; line-height: 1.55; outline: 0;
}
.pop-input:focus { border-color: #4a505a; }
.pop-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.pop-tip { font-size: 11.5px; color: var(--text-4); }
.pop-send { height: 30px; padding: 0 16px; border-radius: 7px; background: var(--yellow); color: #181a20; font-weight: 600; font-size: 13px; }
.pop-send:disabled { opacity: .45; }
.pop-meta { margin-top: 4px; font-size: 12px; color: var(--text-3); }
.pop-desc { margin: 8px 0; font-size: 12.5px; line-height: 1.6; color: var(--text-2); }
.pop-params { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.pop-params li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.pop-params span { color: var(--text-3); }
.pop-result { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: #23272e; font-size: 12.5px; line-height: 1.6; }
.pop-result small { display: block; color: var(--text-3); }
.pop-result.is-success b { color: var(--green); }
.pop-result.is-error b { color: var(--red); }
.pop-result.is-warn b { color: var(--brand); }
.pop-actions { display: flex; gap: 8px; margin-top: 12px; }
.pop-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 7px; background: #2b3139; font-size: 12.5px; }
.pop-btn:hover { background: #353b45; }
.pop-btn.danger { color: #ff9aa9; }

/* 空画布时隐藏工具栏 */
.wf-canvas:not(.has-flow) .wf-zoom, .wf-canvas:not(.has-flow) .wf-topbar { display: none; }
/* 条件节点补「否」分支 */
.wf-plus.branch-add { width: auto; height: 20px; padding: 0 7px 0 4px; gap: 2px; display: inline-flex; align-items: center; border-radius: 10px; border-style: dashed; border-color: rgba(246, 70, 93, .45); color: #f0a0ac; font-size: 11px; translate: 0 -50%; }
.wf-plus.branch-add:hover { scale: 1.08; }
/* 节点详情：可编辑参数 */
.pop-params.editable li { align-items: center; }
.pop-field { display: inline-flex; align-items: center; gap: 4px; }
.pop-field input[type="number"], .pop-field input[type="text"], .pop-field select {
  width: 110px; height: 26px; padding: 0 6px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: #15181d; color: var(--text); font: inherit; font-size: 12.5px; text-align: right; outline: 0;
}
.pop-field select { text-align: left; }
.pop-field input:focus, .pop-field select:focus { border-color: var(--brand); }
.pop-field input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); }
.pop-field em { font-style: normal; font-size: 11.5px; color: var(--text-4); min-width: 26px; }
.pop-btn.primary { background: var(--yellow); color: #181a20; font-weight: 600; }
.pop-btn.primary:hover:not(:disabled) { background: var(--yellow-hover); }
.pop-btn:disabled { opacity: .45; }
/* K 线迷你走势 */
.wf-node.has-spark .wf-node-sub { padding-right: 52px; }
.wf-spark { position: absolute; right: 10px; bottom: 9px; overflow: visible; }
.wf-spark path, .pop-spark path { fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: wf-spark-draw .9s ease-out forwards; }
.wf-spark.ok path, .pop-charts .ok path { stroke: var(--green); }
.wf-spark.bad path, .pop-charts .bad path { stroke: #6b7686; }
@keyframes wf-spark-draw { to { stroke-dashoffset: 0; } }
.pop-charts { margin: 8px 0 0; padding: 0; list-style: none; }
.pop-charts li { display: grid; grid-template-columns: 64px 72px 1fr; align-items: center; gap: 8px; padding: 4px 0; border-top: 1px dashed var(--line); }
.pop-charts b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--text); }
.pop-charts .bad b { color: var(--text-3); }
.pop-charts small { display: block; font-size: 11px; line-height: 1.4; color: var(--text-3); }
.pop-charts .ok small { color: #8fd6b6; }
/* 节点详情：长文本参数（自选关键词） */
.pop-params.editable li.stack { flex-direction: column; align-items: stretch; gap: 6px; }
.pop-params li.stack .pop-input { padding: 6px 8px; font-size: 12.5px; }
[data-pop] { max-height: calc(100% - 24px); overflow-y: auto; }
/* 触屏手势提示 */
.wf-hint {
  position: absolute; left: 50%; bottom: 64px; z-index: 15; translate: -50% 0;
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 16px;
  background: rgba(24, 26, 32, .92); border: 1px solid var(--line-strong); font-size: 12.5px; color: var(--text-2);
  pointer-events: none; animation: pop .2s ease-out;
}
/* 窄屏：工具条放到「工作流 / 策略代码 / 运行记录」标签下方，避免重叠 */
@media (max-width: 768px) {
  .wf-topbar { top: 56px; left: 12px; justify-content: space-between; }
}
/* 运行条与节点详情里的代币标签 */
.wf-runbar .rb-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-runbar .tk-row { flex: none; flex-wrap: nowrap; margin-left: 2px; overflow: visible; }
.pop-result .tk-row { display: flex; margin: 4px 0 0; }
.pop-tk-tip { margin-top: 6px; font-size: 11px; }
.pop-charts li .tk { height: 20px; padding: 0 5px; font-size: 11.5px; }
.pop-charts li .tk span { max-width: 4.2em; }
.pop-charts li { grid-template-columns: minmax(0, 84px) 72px 1fr; }
.pop-charts li .tk { max-width: 84px; }
