/* 画布层：三层 canvas + DOM 节点卡片 + 端口 + HUD + 小地图 */

.canvas-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--bg); }
.canvas-host { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: default; outline: none; }
.canvas-host:focus-visible { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.canvas-host .layer { position: absolute; inset: 0; }
.canvas-host canvas.layer { pointer-events: none; }
.canvas-host .layer.nodes { pointer-events: none; transform-origin: 0 0; will-change: transform; }
.canvas-host.edge-hot { cursor: pointer; }
.canvas-host.mode-pan, .canvas-host.pan-ready { cursor: grab; }
.canvas-host.mode-pan:active, .canvas-host.pan-ready:active { cursor: grabbing; }
.canvas-host.mode-drag { cursor: grabbing; }
.canvas-host.mode-link { cursor: crosshair; }
.canvas-host.mode-marquee { cursor: crosshair; }
.canvas-host.mode-edge-hold { cursor: pointer; }
.canvas-host.mode-rewire { cursor: crosshair; }
.canvas-host.drop-files::after {
  content: '松开即可把图片放到画布上'; position: absolute; inset: 12px; z-index: 40;
  display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: var(--radius);
  background: rgba(91, 140, 255, .08); color: var(--text); font-size: 15px; pointer-events: none;
}

/* 小地图 */
.canvas-host .minimap {
  position: absolute; right: 14px; bottom: 14px; width: 200px; height: 128px; z-index: 22;
  border: 1px solid var(--line); border-radius: 10px; background: rgba(12, 15, 21, .72);
  backdrop-filter: blur(6px); box-shadow: var(--shadow); overflow: hidden; cursor: crosshair;
}
.canvas-host .minimap canvas { width: 100%; height: 100%; display: block; }
.canvas-host .minimap:hover { border-color: var(--accent); }

/* HUD：视图读数与浮层提示 */
.canvas-hud { position: absolute; left: 14px; bottom: 14px; z-index: 21; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.canvas-hud .hud-item {
  padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); background: rgba(12, 15, 21, .74);
  color: var(--muted); font: 500 11.5px/1.4 var(--mono, ui-monospace); backdrop-filter: blur(6px);
}
.canvas-hud .hud-item b { color: var(--text); font-weight: 600; }
.canvas-hud .hud-item.warn { color: var(--warn); border-color: rgba(210, 153, 34, .5); }
.canvas-hud .hud-item.ok { color: var(--ok); }

/* ------------------------------------------------------------ 节点卡片 */
.node {
  position: absolute; pointer-events: auto; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .32); color: var(--text);
  --node-color: var(--accent); overflow: visible; contain: layout style;
}
.node:hover { border-color: color-mix(in srgb, var(--node-color) 55%, var(--line)); }
.node.selected { border-color: var(--node-color); box-shadow: 0 0 0 2px color-mix(in srgb, var(--node-color) 40%, transparent), 0 10px 28px rgba(0, 0, 0, .42); }
.node.locked { border-style: dashed; }
.node.hidden-node { opacity: .18; }
.node.in-scope { background: color-mix(in srgb, var(--panel) 88%, var(--node-color) 12%); }
.node.dropping { outline: 2px dashed var(--accent); outline-offset: 4px; }
.node.is-busy .node-head { animation: nodePulse 1.4s ease-in-out infinite; }
@keyframes nodePulse { 50% { background: color-mix(in srgb, var(--node-color) 22%, var(--panel-2)); } }

.node-head {
  display: flex; align-items: center; gap: 7px; padding: 7px 10px; cursor: grab;
  border-bottom: 1px solid var(--line); border-radius: 11px 11px 0 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--node-color) 16%, var(--panel-2)), var(--panel-2));
  user-select: none; flex: none;
}
.node-head:active { cursor: grabbing; }
.node-glyph { font-size: 13px; line-height: 1; filter: saturate(.9); }
.node-title {
  flex: 1; min-width: 0; font-size: 12.5px; font-weight: 600; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; outline: none; padding: 1px 3px; border-radius: 4px;
}
.node-title:focus { background: var(--bg); box-shadow: inset 0 0 0 1px var(--accent); white-space: normal; }
.node-flag { font-size: 11px; opacity: .8; }
.node-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--node-color); box-shadow: 0 0 8px var(--node-color); flex: none; }
.node-body { flex: 1; min-height: 0; display: flex; padding: 8px 10px 10px; overflow: hidden; }
.nb { display: flex; flex-direction: column; gap: 6px; width: 100%; min-height: 0; }
.nb-far { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; padding: 2px 0; }

/* 提示词 / 便签 */
.node-text {
  width: 100%; min-height: 58px; resize: none; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: 400 12.5px/1.55 var(--font, system-ui); padding: 7px 9px;
}
.node-text:focus { border-color: var(--accent); outline: none; }
.node-text.plain { min-height: 90px; }
.nb-text .node-text { background: rgba(210, 153, 34, .07); border-color: rgba(210, 153, 34, .28); }
.nb-foot { font-size: 11px; }

/* 媒体 */
.media { position: relative; flex: 1; min-height: 90px; border-radius: 9px; overflow: hidden; background: var(--bg); display: grid; place-items: center; }
.media img, .media video { width: 100%; height: 100%; object-fit: contain; display: block; background: #05070b; }
.media.placeholder { border: 1px dashed var(--line); gap: 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 8px; }
.ph-glyph { font-size: 22px; opacity: .5; }
.ph-text { font-size: 11.5px; }
.ph-err { font-size: 11px; color: var(--err); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-err { position: absolute; left: 6px; bottom: 6px; max-width: calc(100% - 12px); padding: 2px 7px; border-radius: 999px; font-size: 10.5px; color: #ffe3e3; background: color-mix(in srgb, var(--err) 78%, transparent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media.busy { border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); gap: 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.media.busy .spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.busy-label { font-size: 12px; color: var(--text); }
.busy .cost { font-size: 11px; }
.media-badge { position: absolute; right: 6px; top: 6px; padding: 2px 6px; border-radius: 999px; font: 600 10.5px/1.5 var(--mono, ui-monospace); background: rgba(4, 6, 10, .68); color: #dfe6f1; }
.nb-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.nb-chips .chip { font-size: 10.5px; padding: 1px 7px; }
.nb-prompt { font-size: 11px; line-height: 1.45; max-height: 30px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* 输出汇聚 */
.nb-output { padding: 0; }
.out-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; flex: 1; min-height: 0; }
.out-cell { position: relative; border-radius: 6px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); cursor: zoom-in; }
.out-cell img, .out-cell video { width: 100%; height: 100%; object-fit: cover; display: block; }
.out-cell:hover { border-color: var(--accent); }
.out-empty { display: grid; place-items: center; height: 100%; font-size: 11.5px; text-align: center; padding: 6px; }

/* 分组 */
.node-group { background: color-mix(in srgb, var(--panel) 55%, transparent); border-style: dashed; border-color: #31506f; box-shadow: none; }
.node-group .node-body { padding: 6px 10px; }
.node-group > .node-head { border-bottom-style: dashed; }

/* 端口 */
.port {
  position: absolute; width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; border-radius: 50%;
  background: var(--panel-2); border: 2px solid var(--node-color); cursor: crosshair; pointer-events: auto;
  transition: transform .12s ease, box-shadow .12s ease;
  z-index: 4; /* 端口压在右侧缩放手柄之上，避免中点被手柄抢走点击 */
}
.port:hover, .port.hot { transform: scale(1.45); box-shadow: 0 0 0 5px color-mix(in srgb, var(--node-color) 28%, transparent); }
.port.in { left: 0; }
.port.out { left: 100%; }
.port .port-label {
  position: absolute; top: -17px; left: 50%; transform: translateX(-50%); font: 600 9.5px/1.3 var(--mono, ui-monospace);
  color: var(--muted); background: rgba(6, 9, 14, .82); padding: 1px 4px; border-radius: 4px; white-space: nowrap;
  opacity: 0; transition: opacity .12s ease; pointer-events: none;
}
.port:hover .port-label, .canvas-host[data-lod='near'] .node.selected .port .port-label { opacity: 1; }
.resize-handle { position: absolute; width: 12px; height: 12px; right: -3px; bottom: -3px; border-radius: 3px; background: var(--panel-2); border: 1px solid var(--node-color); cursor: nwse-resize; pointer-events: auto; z-index: 3; }
.resize-handle.w { right: -3px; bottom: auto; top: calc(50% + 16px); height: 22px; width: 8px; cursor: ew-resize; border-radius: 4px; }
.resize-handle.h { right: auto; left: 50%; bottom: -3px; width: 22px; height: 8px; cursor: ns-resize; border-radius: 4px; }
.node.locked .resize-handle, .node.is-group .resize-handle.w, .node.is-group .resize-handle.h { display: none; }

/* 缩放较远时收起细节 */
.canvas-host[data-lod='far'] .node-body, .canvas-host[data-lod='far'] .resize-handle, .canvas-host[data-lod='far'] .port { display: none; }
.canvas-host[data-lod='far'] .node { border-radius: 8px; }
.canvas-host[data-lod='far'] .node-head { border-bottom: 0; border-radius: 8px; padding: 5px 8px; }
.canvas-host[data-lod='mid'] .port { width: 10px; height: 10px; margin: -5px 0 0 -5px; }
.canvas-host[data-lod='mid'] .nb-prompt { display: none; }
