/* ============================================================================
 * 无限画布 (Infinite Canvas) — node-graph 编排画布
 * 自包含模块,只被 index.html 通过一个 <link> 引入。沿用全局 CSS 变量
 * (--accent / --panel / --border / --bg / --accent2)。不依赖任何第三方库。
 * ========================================================================== */

/* 画布 TAB pane:占满 topnav 以下的整屏,内部 flex 纵向(工具条 + 画布区) */
#tab-canvas.page.active { display: flex; }
#tab-canvas {
  flex-direction: column;
  height: calc(100vh - 52px);
  padding: 0;
  overflow: hidden;
}

/* ── 顶部工具条 ───────────────────────────────────────────── */
.vfc-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(24, 24, 31, .9);
  border-bottom: 1px solid var(--border, #2a2a35);
  z-index: 5;
}
.vfc-toolbar .vfc-title { font-size: .9rem; font-weight: 600; color: var(--accent2, #c4b5fd); }
.vfc-toolbar .vfc-hint { font-size: .78rem; color: #888; margin-left: 4px; }
.vfc-toolbar .vfc-spacer { margin-left: auto; }
.vfc-btn {
  background: rgba(124, 58, 237, .14);
  color: #ddd;
  border: 1px solid var(--border, #2a2a35);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: .82rem;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.vfc-btn:hover { background: rgba(124, 58, 237, .28); color: #fff; }
.vfc-btn.vfc-ghost { background: transparent; }
/* 顶栏统一画面比例选择器:与 .vfc-btn 同色系,label 内联紧凑 */
.vfc-ratio { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.vfc-ratio-lbl { font-size: .78rem; color: #888; }
.vfc-ratio-sel {
  background: rgba(124, 58, 237, .14);
  color: #ddd;
  border: 1px solid var(--border, #2a2a35);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: .82rem;
  cursor: pointer;
}
.vfc-ratio-sel:hover { background: rgba(124, 58, 237, .28); color: #fff; }

/* 访达文件拖入高亮:素材区 / 参考图槽 dragover 时 */
.vfc-drop-over {
  outline: 2px dashed var(--accent, #7c3aed);
  outline-offset: 2px;
  background: rgba(124, 58, 237, .1);
}

/* 添加节点下拉菜单 */
.vfc-menu-wrap { position: relative; }
.vfc-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 168px;
  max-height: min(66vh, 520px);
  overflow-y: auto;
  background: var(--panel, #18181f);
  border: 1px solid var(--border, #2a2a35);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .55);
  padding: 6px;
  z-index: 30;
  display: none;
}
.vfc-menu.open { display: block; }
.vfc-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: .82rem;
  color: #ccc;
  cursor: pointer;
}
.vfc-menu-item:hover { background: rgba(124, 58, 237, .2); color: #fff; }
.vfc-menu-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.vfc-menu-group {
  padding: 6px 10px 2px;
  font-size: .68rem;
  letter-spacing: .08em;
  color: #6b7280;
  text-transform: uppercase;
  user-select: none;
}
.vfc-menu-new { color: #a78bfa; font-weight: 600; }
.vfc-menu-new:hover { background: rgba(124, 58, 237, .3); color: #c4b5fd; }
.vfc-menu-sep { height: 1px; background: rgba(255,255,255,.08); margin: 4px 6px; }
.vfc-menu-hint { color: #4b5563; cursor: default; font-style: italic; }
.vfc-menu-hint:hover { background: none; color: #4b5563; }

/* ── 画布视口 + 世界层 ─────────────────────────────────────── */
.vfc-viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background-color: var(--bg, #0f0f13);
  /* 网格点背景,跟随平移由 JS 设 background-position/size */
  background-image: radial-gradient(rgba(255, 255, 255, .06) 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: grab;
  user-select: none;
}
.vfc-viewport.vfc-panning { cursor: grabbing; }

/* 框选矩形(Shift+左键拖):覆盖在世界层之上,不拦截指针 */
.vfc-marquee {
  position: absolute;
  display: none;
  border: 1px solid var(--accent2, #c4b5fd);
  background: rgba(124, 58, 237, .12);
  pointer-events: none;
  z-index: 3;
}

.vfc-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  width: 0;
  height: 0;
}
/* 连线 SVG:1px 占位 + overflow visible,路径用世界坐标延伸到框外 */
.vfc-edges {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}
.vfc-edges path.vfc-edge { fill: none; stroke: #7c6aa8; stroke-width: 2; pointer-events: stroke; cursor: pointer; }
.vfc-edges path.vfc-edge:hover { stroke: #ef5db0; stroke-width: 3; }
.vfc-edges path.vfc-edge-temp { fill: none; stroke: var(--accent2, #c4b5fd); stroke-width: 2; stroke-dasharray: 5 4; pointer-events: none; }

.vfc-nodelayer { position: absolute; left: 0; top: 0; }

/* ── 节点 ─────────────────────────────────────────────────── */
.vfc-node {
  position: absolute;
  width: 232px;
  background: var(--panel, #18181f);
  border: 1px solid var(--border, #2a2a35);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .5);
  font-size: .8rem;
  color: #ddd;
}
.vfc-node.vfc-selected { border-color: var(--accent2, #c4b5fd); box-shadow: 0 0 0 1px var(--accent2, #c4b5fd), 0 4px 18px rgba(0, 0, 0, .55); }

.vfc-node-hd {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px 10px 0 0;
  border-bottom: 1px solid var(--border, #2a2a35);
  cursor: move;
  font-weight: 600;
  font-size: .82rem;
}
.vfc-node-hd .vfc-node-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.vfc-node-hd .vfc-node-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vfc-node-hd .vfc-node-del { color: #888; cursor: pointer; font-size: .9rem; padding: 0 2px; }
.vfc-node-hd .vfc-node-del:hover { color: #ef5db0; }

.vfc-node-body { padding: 9px 10px; display: flex; flex-direction: column; gap: 7px; }
.vfc-node-body textarea,
.vfc-node-body input[type="text"],
.vfc-node-body select {
  width: 100%;
  box-sizing: border-box;
  background: #101015;
  border: 1px solid var(--border, #2a2a35);
  border-radius: 6px;
  color: #eee;
  padding: 6px 8px;
  font-size: .78rem;
  font-family: inherit;
  resize: vertical;
}
.vfc-node-body textarea:focus,
.vfc-node-body input:focus,
.vfc-node-body select:focus { outline: none; border-color: var(--accent, #7c3aed); }
.vfc-field-select { display: flex; align-items: center; gap: 8px; color: #aaa; font-size: .74rem; }
.vfc-field-select span { flex: 1; }
.vfc-field-select select { width: auto; min-width: 76px; resize: none; }

.vfc-run-btn {
  background: var(--accent, #7c3aed);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: .78rem;
  cursor: pointer;
  transition: background .15s;
}
.vfc-run-btn:hover { background: var(--accent-hover, #6d28d9); }
.vfc-run-btn:disabled { opacity: .55; cursor: default; }

.vfc-node-status {
  font-size: .72rem;
  color: #999;
  min-height: 1em;
  word-break: break-word;
}
.vfc-node-status.vfc-ok { color: #5fd08a; }
.vfc-node-status.vfc-err { color: #ef6d6d; }
.vfc-node-status.vfc-run { color: var(--accent2, #c4b5fd); }
.vfc-node-status.vfc-stale { color: #d97706; }
.vfc-node-result {
  font-size: .72rem;
  color: #bbb;
  max-height: 132px;
  overflow: auto;
  background: #101015;
  border: 1px solid var(--border, #2a2a35);
  border-radius: 6px;
  padding: 6px 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
.vfc-node-result:empty { display: none; }
/* 结果缩略图:图像/视频占满结果区宽、自然比例;加载失败降级占位 */
.vfc-thumb {
  display: block;
  width: 100%;
  height: auto;
  max-height: 132px;
  object-fit: contain;
  border-radius: 4px;
  background: #000;
}
.vfc-thumb-audio {
  display: block;
  width: 100%;
  height: 32px;
}
.vfc-thumb-err {
  color: #ef6d6d;
  font-size: .72rem;
  padding: 10px 8px;
  text-align: center;
}
/* 角色/场景图预览:结果区里按 2 列网格排立绘/场景图缩略图(节点宽仍 232,靠网格控制大小) */
.vfc-node-result.vfc-has-grid { max-height: 300px; }
.vfc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.vfc-grid-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.vfc-grid-item img {
  display: block;
  width: 100%;
  height: 66px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
}
.vfc-grid-cap {
  font-size: .66rem;
  line-height: 1.25;
  color: #9aa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vfc-grid-lock {
  min-height: 22px;
  border: 1px solid rgba(139, 92, 246, .55);
  border-radius: 4px;
  background: rgba(124, 58, 237, .18);
  color: #ddd6fe;
  font-size: .64rem;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
}
.vfc-grid-lock:hover { background: rgba(124, 58, 237, .32); }
.vfc-grid-lock:disabled, .vfc-grid-lock[aria-disabled="true"] { opacity: .6; cursor: default; }
.vfc-grid-lock.is-locked {
  border-color: rgba(34, 197, 94, .35);
  background: rgba(34, 197, 94, .12);
  color: #86efac;
}

/* ── 端口 ─────────────────────────────────────────────────── */
/* 行高 20 + gap 8 = 相邻端口中心间距 28px,大于命中盘直径 26px(::before inset -7),命中区不重叠 */
.vfc-ports { display: flex; flex-direction: column; gap: 8px; padding: 2px 0 8px; }
.vfc-port-row { position: relative; display: flex; align-items: center; height: 20px; font-size: .7rem; color: #aaa; }
.vfc-port-row.vfc-in { padding-left: 14px; justify-content: flex-start; }
.vfc-port-row.vfc-out { padding-right: 14px; justify-content: flex-end; }
.vfc-port {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2a2a35;
  border: 2px solid #7c6aa8;
  cursor: crosshair;
  top: 50%;
  transform: translateY(-50%);
  transition: background .12s, border-color .12s;
}
/* 透明命中盘:视觉圆点仍 12px,实际可点击/拖拽半径扩到 ~13px(inset -7 → 26px 直径),解决连接感应区太小 */
.vfc-port::before {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
}
.vfc-port-row.vfc-in .vfc-port { left: -6px; }
.vfc-port-row.vfc-out .vfc-port { right: -6px; }
.vfc-port:hover { background: var(--accent2, #c4b5fd); border-color: var(--accent2, #c4b5fd); }

/* 提示 toast */
.vfc-toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, .82);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: .8rem;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.vfc-toast.show { opacity: 1; }

/* 空项目提示 */
.vfc-empty-hint {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  background: rgba(124, 58, 237, .14);
  border: 1px solid var(--border, #2a2a35);
  color: #cbb8f0;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: .78rem;
  z-index: 4;
}

/* ── 上下文菜单(右键加节点 / 右键节点动作 / 连线拖到空白弹兼容节点) ── */
.vfc-ctx {
  position: absolute;
  min-width: 172px;
  max-height: 300px;
  overflow: auto;
  background: var(--panel, #18181f);
  border: 1px solid var(--border, #2a2a35);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .55);
  padding: 6px;
  z-index: 35;
}
.vfc-ctx-search {
  width: 100%;
  box-sizing: border-box;
  background: #101015;
  border: 1px solid var(--border, #2a2a35);
  border-radius: 6px;
  color: #eee;
  padding: 5px 8px;
  font-size: .78rem;
  margin-bottom: 6px;
}
.vfc-ctx-search:focus { outline: none; border-color: var(--accent, #7c3aed); }
.vfc-ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: .82rem;
  color: #ccc;
  cursor: pointer;
}
.vfc-ctx-item:hover { background: rgba(124, 58, 237, .2); color: #fff; }
.vfc-ctx-empty { padding: 7px 10px; font-size: .78rem; color: #777; }
.vfc-ctx-group {
  padding: 6px 10px 2px;
  font-size: .68rem;
  letter-spacing: .08em;
  color: #6b7280;
  text-transform: uppercase;
  user-select: none;
}

/* ── 缩略图 wrapper + 放大按钮(结果/参考图/素材共用) ───────── */
.vfc-media { position: relative; }
.vfc-media .vfc-thumb { display: block; }
.vfc-enlarge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: .78rem;
  line-height: 22px;
  cursor: zoom-in;
  opacity: 0;
  transition: opacity .12s;
}
.vfc-media:hover .vfc-enlarge { opacity: 1; }
.vfc-enlarge:hover { background: rgba(0, 0, 0, .8); }
/* 结果媒体下载按钮:图/视频 hover 显现(⛶ 左侧);音频常显(播放条右侧,不遮控件) */
.vfc-dl {
  position: absolute;
  top: 4px;
  right: 30px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: .78rem;
  line-height: 22px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s;
}
.vfc-media:hover .vfc-dl { opacity: 1; }
.vfc-dl:hover { background: rgba(0, 0, 0, .8); }
.vfc-media-audio { display: flex; align-items: center; gap: 4px; }
.vfc-media-audio .vfc-thumb-audio { flex: 1; }
.vfc-media-audio .vfc-dl { position: static; opacity: 1; flex: 0 0 auto; }
/* 结果区图/视频:固定画面比例框(跟随顶栏「比例」--vfc-ar),产物 contain 居中留边,
   节点高度不随产物真实比例跳动。仅作用于结果区(vfc-has-media),不碰参考图槽/素材区的
   .vfc-media,也不碰结果区音频(播放条)/文本(仍走 132px 限高+滚动)。 */
.vfc-node-result.vfc-has-media {
  max-height: none;
  overflow: visible;
  padding: 0;
  background: transparent;
  border: none;
}
.vfc-node-result.vfc-has-media .vfc-media {
  width: 100%;
  aspect-ratio: var(--vfc-ar, 16 / 9);
  background: #000;
  border-radius: 4px;
  overflow: hidden;
}
.vfc-node-result.vfc-has-media .vfc-thumb {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
}

/* ── 参考图槽 / 素材上传区 ───────────────────────────────── */
.vfc-ref { margin: 4px 0; }
.vfc-ref-hd { font-size: .68rem; color: #9a90c0; margin-bottom: 3px; }
.vfc-ref-slot { display: flex; flex-direction: column; gap: 4px; }
.vfc-asset { margin-bottom: 6px; display: flex; flex-direction: column; gap: 4px; }
.vfc-ref-btn {
  width: 100%;
  box-sizing: border-box;
  background: #1a1a22;
  border: 1px dashed #3a3a48;
  border-radius: 6px;
  color: #b7a9e0;
  padding: 6px 8px;
  font-size: .74rem;
  cursor: pointer;
}
.vfc-ref-btn:hover { border-color: var(--accent, #7c3aed); color: #fff; }

/* ── 全屏放大 lightbox ───────────────────────────────────── */
.vfc-lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .85);
  cursor: zoom-out;
}
.vfc-lightbox img,
.vfc-lightbox video {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 6px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .6);
}
.vfc-lightbox-close {
  position: absolute;
  top: 18px;
  right: 24px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 1.4rem;
  line-height: 40px;
  cursor: pointer;
}
.vfc-lightbox-close:hover { background: rgba(255, 255, 255, .25); }
.vfc-lightbox-dl {
  position: absolute;
  top: 22px;
  right: 76px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  font-size: .82rem;
  cursor: pointer;
}
.vfc-lightbox-dl:hover { background: rgba(255, 255, 255, .28); }
