:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --border: #2d3a4d;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #5b9fd4;
  --danger: #e05c5c;
  --entry: #6bcb77;
  --router: #ffd166;
  --condition: #9b5de5;
  --action: #00bbf9;
  --merge: #888;
  --exit: #f15bb5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar h1 { margin: 0 0 4px; font-size: 1.25rem; }
.sub { margin: 0 0 10px; color: var(--muted); font-size: 0.9rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.node-search-bar {
  padding-bottom: 10px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--border);
}

.node-search {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.node-search-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.node-search-field select,
.node-search-field input[type="text"] {
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.node-search-field select {
  min-width: 7.5rem;
}

.node-search-id-field input[type="text"] {
  width: min(320px, 42vw);
}

.node-search-next:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.toolbar label { font-size: 0.85rem; color: var(--muted); }
.toolbar input[type="password"] {
  margin-left: 6px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
}

button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button:hover { filter: brightness(1.08); }

.status { font-size: 0.85rem; color: var(--muted); margin-left: 8px; }
.status.ok { color: var(--entry); }
.status.err { color: var(--danger); }

.layout {
  display: grid;
  grid-template-columns: 220px 1fr 300px;
  flex: 1;
  min-height: 0;
}

.layout > * {
  min-height: 0;
}

.palette, .inspector {
  padding: 12px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--panel);
}

.inspector { border-right: none; border-left: 1px solid var(--border); }

.palette h2, .inspector h2 {
  margin: 12px 0 8px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.hint { font-size: 0.8rem; color: var(--muted); }

.canvas-hint {
  padding: 8px;
  border-radius: 6px;
  background: rgba(91, 159, 212, 0.08);
  border: 1px solid rgba(91, 159, 212, 0.25);
  line-height: 1.45;
}

.canvas-hint strong { color: var(--text); }

.drawflow .parent-drawflow {
  cursor: grab;
}

.drawflow .parent-drawflow:active {
  cursor: grabbing;
}

.drawflow .drawflow-node {
  cursor: grab;
}

.drawflow .drawflow-node:active {
  cursor: grabbing;
}

.canvas-hint kbd {
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.75rem;
}

/* 连线：路径可点击选中（便于 Delete 删除）；SVG 容器本身不挡平移 */
.drawflow svg.connection {
  pointer-events: none;
}

.drawflow .connection .main-path {
  pointer-events: stroke;
  stroke-width: 6px;
  cursor: pointer;
}

.drawflow .connection .main-path:hover {
  stroke-width: 8px;
  filter: brightness(1.2);
}

.drawflow .connection .main-path.selected {
  stroke: var(--accent) !important;
  stroke-width: 8px;
}

/* 选中节点时：入边绿、出边红 */
.drawflow .connection.conn-highlight-in .main-path {
  stroke: var(--conn-in, #6bcb77) !important;
  stroke-width: 8px;
  filter: drop-shadow(0 0 4px rgba(107, 203, 119, 0.55));
}

.drawflow .connection.conn-highlight-out .main-path {
  stroke: var(--conn-out, #e05c5c) !important;
  stroke-width: 8px;
  filter: drop-shadow(0 0 4px rgba(224, 92, 92, 0.55));
}

.drawflow .connection.conn-highlight-in .point,
.drawflow .connection.conn-highlight-out .point {
  stroke-width: 3px;
}

.drawflow .connection.conn-highlight-in .point {
  stroke: var(--conn-in, #6bcb77);
  fill: #3d8f47;
}

.drawflow .connection.conn-highlight-out .point {
  stroke: var(--conn-out, #e05c5c);
  fill: #a83232;
}

.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
  cursor: crosshair;
}

.palette-item {
  padding: 8px 10px;
  margin-bottom: 6px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  cursor: grab;
  font-size: 0.85rem;
}

.palette-item[data-kind="entry"] { border-color: var(--entry); }
.palette-item[data-kind="router"] { border-color: var(--router); }
.palette-item[data-kind="condition"] { border-color: var(--condition); }
.palette-item[data-kind="action"] { border-color: var(--action); }
.palette-item[data-kind="exit"] { border-color: var(--exit); }

.canvas {
  position: relative;
  background: #121820;
  background-image: radial-gradient(circle, #1e2a3a 1px, transparent 1px);
  background-size: 20px 20px;
  overflow: hidden;
  min-width: 0;
}

#drawflow,
#drawflow.parent-drawflow {
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* 连线 SVG 容器不挡鼠标；具体路径见 .main-path 规则 */
.drawflow svg.connection {
  pointer-events: none;
}

.drawflow svg.connection .point {
  pointer-events: all;
}

#drawflow.panning,
#drawflow.panning .drawflow-node {
  cursor: grabbing !important;
}

#drawflow.pan-ready:not(.panning) {
  cursor: grab;
}

.drawflow .drawflow-node {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 8px;
  min-width: 200px;
  max-width: 260px;
  color: var(--text);
  position: absolute;
  font-size: 0.8rem;
  line-height: 1.35;
  padding: 6px 8px 8px;
}

.drawflow .drawflow-node .node-id {
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.drawflow .drawflow-node .node-kind {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  opacity: 0.85;
}

.drawflow .drawflow-node .node-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 4px;
}

.drawflow .drawflow-node .badge-branch,
.drawflow .drawflow-node .badge-effect,
.drawflow .drawflow-node .badge-feige,
.drawflow .drawflow-node .badge-exit {
  display: inline-block;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
  margin: 2px 4px 2px 0;
  font-weight: 600;
}

.drawflow .drawflow-node .badge-branch {
  background: rgba(155, 93, 229, 0.25);
  color: #d4b5ff;
}

.drawflow .drawflow-node .badge-effect {
  background: rgba(0, 187, 249, 0.2);
  color: #7dd3fc;
}

.drawflow .drawflow-node .badge-feige {
  background: rgba(255, 209, 102, 0.2);
  color: #ffe08a;
}

.drawflow .drawflow-node .badge-exit {
  background: rgba(241, 91, 181, 0.2);
  color: #f9a8d4;
}

.drawflow .drawflow-node .line-tool {
  color: #7ee787;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
  word-break: break-all;
}

.drawflow .drawflow-node .line-handler {
  color: #79c0ff;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
}

.drawflow .drawflow-node .line-muted {
  color: var(--muted);
  font-size: 0.68rem;
  word-break: break-all;
}

.glossary-box {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 12px;
}

.glossary-box p {
  margin: 0 0 6px;
}

.field-hints {
  margin: 8px 0 0;
  padding: 8px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.4;
}

.inspector .hidden,
.field-router.hidden,
.field-action.hidden {
  display: none !important;
}

.drawflow .drawflow-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91, 159, 212, 0.45), 0 8px 24px rgba(0, 0, 0, 0.35);
}
.drawflow .drawflow-node.kind-entry { border-color: var(--entry); }
.drawflow .drawflow-node.kind-router { border-color: var(--router); }
.drawflow .drawflow-node.kind-condition { border-color: var(--condition); }
.drawflow .drawflow-node.kind-action { border-color: var(--action); }
.drawflow .drawflow-node.kind-exit { border-color: var(--exit); }

.drawflow .drawflow_content_node {
  padding: 8px 10px;
  font-size: 0.82rem;
}

.drawflow .drawflow_content_node .node-id { font-weight: 600; }
.drawflow .drawflow_content_node .node-kind {
  display: inline-block;
  font-size: 0.7rem;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--border);
  margin-left: 4px;
}

.meta-box {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
}

#dryRunContext, .inspector textarea, .inspector input, .inspector select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
}

.inspector label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.82rem;
}

.inspector label small { color: var(--muted); }

.hidden { display: none !important; }

.dry-run {
  margin-top: 12px;
  padding: 8px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.75rem;
  overflow-x: auto;
  max-height: 280px;
}
