:root {
  --ink: #11184F; --text: #1d1d1f; --muted: #6b6470; --line: #E6E2E4; --bg: #FAFAFB;
  --red: #D93A2B; --red-bg: #FDECEA; --blue: #294E95; --sel: #2F6BFF;
  --runtime-bg: #EAEEF5; --runtime: #294E95;
  --model-bg: #F1E1ED; --model: #7A126B;
  --context-bg: #FBF1E2; --context: #8A6327;
  --tools-bg: #E8F1EC; --tools: #3F6B55;
  --skills-bg: #E5F2F3; --skills: #2F6B73;
  --plugins-bg: #FAECEB; --plugins: #871C23;
  --subagent-bg: #EEEBF7; --subagent: #5A4E9A;
  --neutral-bg: #F3F2F4; --neutral: #4E444E;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: Arial, "Microsoft YaHei", "PingFang SC", sans-serif; color: var(--text); background: #fff; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.red { color: var(--red); font-weight: 700; }
.kicker { font-size: 12px; font-weight: 700; color: var(--blue); letter-spacing: .3px; }

.btn { border: 0; border-radius: 8px; padding: 9px 16px; font-size: 14px; cursor: pointer; font-family: inherit; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #1f2a7a; }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: #fff; border: 1px solid var(--line); color: var(--text); }
.btn.ghost:hover { background: var(--bg); }
.btn.link { background: none; color: var(--muted); padding: 6px 8px; }
.btn.wide { width: 100%; padding: 11px; font-size: 15px; }

/* ---------- 登录 ---------- */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #fff 0%, #f4f6fb 100%); padding: 24px; }
.login-card { display: flex; width: 960px; max-width: 100%; background: #fff; border-radius: 16px; box-shadow: 0 10px 40px rgba(17,24,79,.08); overflow: hidden; }
.login-left { flex: 1; padding: 56px 56px 40px; }
.login-left h1 { font-size: 44px; line-height: 1.15; margin: 14px 0 12px; }
.login-right { width: 380px; background: #f6f8fc; display: flex; align-items: center; justify-content: center; }
.login-right img { width: 300px; }
.form { display: flex; flex-direction: column; gap: 10px; margin-top: 28px; max-width: 360px; }
.form label { font-size: 13px; font-weight: 700; }
.form input { padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; font-size: 16px; font-family: inherit; }
.form input:focus { outline: 2px solid #C9D0F0; border-color: var(--blue); }
.msg { margin-top: 12px; font-size: 13px; color: var(--red); min-height: 18px; }
.dev-note { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: #FBF1E2; color: #8A6327; font-size: 13px; max-width: 360px; }

/* ---------- 顶栏 ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { height: 60px; display: flex; align-items: center; gap: 20px; padding: 0 20px; border-bottom: 1px solid var(--line); background: #fff; flex: none; }
.title { display: flex; flex-direction: column; line-height: 1.25; }
.title strong { font-size: 17px; }
.status { flex: 1; font-size: 13px; color: var(--muted); }
.status .pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-weight: 700; font-size: 12px; margin-right: 8px; }
.pill.ok { background: #E8F1EC; color: #3F6B55; }
.pill.todo { background: var(--neutral-bg); color: var(--neutral); }
.actions { display: flex; align-items: center; gap: 8px; }
.user { font-size: 13px; color: var(--muted); margin-left: 8px; }

/* ---------- 工作区 ---------- */
.workspace { flex: 1; display: flex; min-height: 0; }
.library { width: 280px; flex: none; border-right: 1px solid var(--line); background: var(--bg); overflow-y: auto; padding: 14px; }
.library.drop-target { background: #eef0f6; box-shadow: inset 0 0 0 2px #ABA8B1; }
.lib-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.lib-title { font-weight: 700; }
.lib-head input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; }
.lib-section { margin-top: 14px; }
.lib-label { font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.lib-items { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-foot { margin-top: 18px; line-height: 1.6; }

.chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px 7px 8px; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; font-size: 13px; cursor: grab; user-select: none; line-height: 1.2; }
.chip:hover { border-color: #ABA8B1; box-shadow: 0 2px 6px rgba(17,24,79,.08); }
.chip img { width: 18px; height: 18px; flex: none; object-fit: contain; }
.chip.lib-container { font-weight: 700; background: var(--g-bg); border-color: transparent; }
.chip.lib-container.g-harness { background: #EEEDF3; }
.chip.used { display: none; }

/* ---------- 画布 ---------- */
.stage { flex: 1; position: relative; min-width: 0; }
.canvas-wrap { position: absolute; inset: 0; overflow: auto; background: radial-gradient(circle, #dcdbe0 1px, transparent 1px) 0 0 / 22px 22px, #fff; }
.canvas-sizer { position: relative; }
.canvas { position: absolute; left: 0; top: 0; width: 2400px; height: 1600px; transform-origin: 0 0; user-select: none; }
.canvas-empty { position: absolute; left: 60px; top: 50px; font-size: 18px; color: #ABA8B1; pointer-events: none; }
.zoombar { position: absolute; right: 18px; bottom: 18px; display: flex; align-items: center; gap: 2px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 4px; box-shadow: 0 2px 10px rgba(17,24,79,.08); z-index: 20; }
.zoombar button { border: 0; background: none; font-size: 15px; min-width: 30px; height: 28px; border-radius: 6px; cursor: pointer; font-family: inherit; color: var(--text); }
.zoombar button:hover { background: var(--bg); }
.zoombar span { font-size: 12px; color: var(--muted); min-width: 44px; text-align: center; }

/* ---------- 画布上的节点（frame） ---------- */
.node { position: absolute; cursor: grab; }

/* 组件卡片 */
.card { display: flex; align-items: center; gap: 6px; padding: 0 10px; background: #fff; border: 1px solid #E2DFE5; border-radius: 9px;
  box-shadow: 0 1px 2px rgba(17,24,79,.06); font-size: 13px; font-weight: 600; color: var(--text); }
.card img { width: 20px; height: 20px; flex: none; object-fit: contain; }
.card .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 模块框 */
.box { border-radius: 12px; background: var(--g-bg); }
.box > .box-head { position: absolute; left: 0; top: 0; right: 0; height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 14px; pointer-events: none; overflow: hidden; }
.box > .box-head img { width: 20px; height: 20px; object-fit: contain; flex: none; }
.box > .box-head .name { font-weight: 700; font-size: 15px; color: var(--g); white-space: nowrap; }
.box > .box-head .sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box.g-harness { background: #fff; box-shadow: inset 0 0 0 2px var(--ink); }
.box.g-harness > .box-head { height: 52px; }
.box.g-harness > .box-head .name { font-size: 19px; }
.box.g-neutral { box-shadow: inset 0 0 0 1px #DAD7DD; }
.box.drop-target { outline: 2px dashed var(--sel); outline-offset: 3px; }

.g-runtime { --g: var(--runtime); --g-bg: var(--runtime-bg); }
.g-model { --g: var(--model); --g-bg: var(--model-bg); }
.g-context { --g: var(--context); --g-bg: var(--context-bg); }
.g-tools { --g: var(--tools); --g-bg: var(--tools-bg); }
.g-skills { --g: var(--skills); --g-bg: var(--skills-bg); }
.g-plugins { --g: var(--plugins); --g-bg: var(--plugins-bg); }
.g-subagent { --g: var(--subagent); --g-bg: var(--subagent-bg); }
.g-neutral { --g: var(--neutral); --g-bg: var(--neutral-bg); }
.g-harness { --g: var(--ink); --g-bg: #fff; }

/* 选中：Figma 式 8 个手柄 */
.node.selected { outline: 1.5px solid var(--sel); outline-offset: 1px; z-index: 5; }
.hdl { position: absolute; width: 10px; height: 10px; background: #fff; border: 1.5px solid var(--sel); border-radius: 2px; z-index: 60; }
.hdl-nw { left: -6px; top: -6px; cursor: nwse-resize; }
.hdl-ne { right: -6px; top: -6px; cursor: nesw-resize; }
.hdl-sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.hdl-se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.hdl-n { left: calc(50% - 5px); top: -6px; cursor: ns-resize; }
.hdl-s { left: calc(50% - 5px); bottom: -6px; cursor: ns-resize; }
.hdl-w { top: calc(50% - 5px); left: -6px; cursor: ew-resize; }
.hdl-e { top: calc(50% - 5px); right: -6px; cursor: ew-resize; }
.rm { position: absolute; top: -12px; right: -30px; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line); background: #fff;
  color: var(--muted); font-size: 13px; line-height: 17px; padding: 0; cursor: pointer; z-index: 61; }
.rm:hover { color: var(--red); border-color: var(--red); }

/* 提交后的错误标注（点「重试」清除） */
.node.err { outline: 2.5px solid var(--red); outline-offset: 2px; }
.badge { position: absolute; top: -10px; left: -10px; width: 20px; height: 20px; border-radius: 50%; background: var(--red); color: #fff;
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; z-index: 40; }
.box.err-zone { background-image: repeating-linear-gradient(45deg, rgba(217,58,43,.07) 0 8px, transparent 8px 16px); }
.node.flash { animation: flash 1s ease 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 10px rgba(217,58,43,.25); } }

/* 拖拽 */
.drag-ghost { position: fixed; z-index: 1000; pointer-events: none; opacity: .85; transform-origin: 0 0; box-shadow: 0 10px 30px rgba(17,24,79,.18); border-radius: 10px; }
.drop-tip { position: fixed; z-index: 1001; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 4px 9px; border-radius: 6px; white-space: nowrap; }
.drop-tip.out { background: #6b6470; }
.dragging { visibility: hidden; }
.drag-ghost.box.g-harness { box-shadow: 0 10px 30px rgba(17,24,79,.18); background: #F7F7FA; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }

/* ---------- 结果面板 ---------- */
.result { width: 330px; flex: none; border-left: 1px solid var(--line); background: #fff; overflow-y: auto; padding: 18px; }
.result-head strong { font-size: 17px; color: var(--red); }
.errors { padding-left: 20px; margin: 14px 0 18px; }
.errors li { font-size: 13px; line-height: 1.55; margin-bottom: 10px; cursor: pointer; }
.errors li:hover { color: var(--red); }
.errors li .tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--red-bg); color: var(--red); margin-right: 4px; }
.retry-note { margin-top: 8px; text-align: center; }

/* ---------- 弹窗 / 提示 ---------- */
.modal { position: fixed; inset: 0; background: rgba(17,24,79,.25); display: flex; align-items: center; justify-content: center; z-index: 2000; }
.modal-card { background: #fff; border-radius: 14px; padding: 28px 32px; width: 580px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-card h2 { margin-top: 0; }
.modal-card li { margin-bottom: 8px; line-height: 1.6; }
.modal-actions { text-align: right; margin-top: 16px; }
.modal-card.pass { text-align: center; }
.pass-badge { width: 64px; height: 64px; border-radius: 50%; background: #E8F1EC; color: #3F6B55; font-size: 36px; line-height: 64px; margin: 0 auto 12px; }
.modal-card.pass .modal-actions { text-align: center; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 3000; }
