:root {
  --bg: #101217;
  --panel: #171b23;
  --panel-2: #1f2530;
  --line: #2d3441;
  --text: #eef2f9;
  --muted: #97a2b8;
  --accent: #86a7ff;
  --danger: #ff7171;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
body { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button, input, textarea, select {
  border-radius: 10px;
  border: 1px solid var(--line);
}
button {
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.danger:hover { border-color: var(--danger); }
input, textarea, select {
  width: 100%;
  background: #11151c;
  color: var(--text);
  padding: 10px 12px;
  margin-top: 6px;
}
label { display: block; color: var(--muted); font-size: 14px; }
textarea { resize: vertical; }
ul { padding-left: 18px; margin: 10px 0 0; color: var(--muted); }
.app-shell { display: grid; grid-template-columns: 320px 1fr; height: 100vh; }
.sidebar {
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #11151c;
  overflow-y: auto;
}
.sidebar h1 { margin: 0; font-size: 24px; }
.subtitle { margin: 6px 0 0; color: var(--muted); }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin-top: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 16px; }
.row-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.form-block { display: grid; gap: 12px; }
.hidden { display: none; }
.muted { color: var(--muted); }
.main-area { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: #0d1015;
}
.pill {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
}
.canvas {
  position: relative;
  flex: 1;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 28px 28px;
}
.edges-layer, .nodes-layer { position: absolute; inset: 0; }
.edges-layer {
  width: 100%;
  height: 100%;
  overflow: visible;
  z-index: 1;
}
.nodes-layer { z-index: 2; }
.edge-line, .edge-preview {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  marker-end: url(#arrowhead);
}
.edge-preview { stroke-dasharray: 8 6; }
.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 18;
  pointer-events: stroke;
  cursor: pointer;
}
.edges-layer text {
  fill: var(--text);
  font-size: 13px;
  pointer-events: none;
}
.edge-label-bg {
  fill: rgba(15, 18, 23, 0.95);
  stroke: var(--line);
}
.edges-layer marker path { fill: var(--accent); }
.edge-line.selected {
  stroke-width: 4;
  filter: drop-shadow(0 0 6px rgba(134, 167, 255, 0.75));
}
.edge-label-bg.selected { stroke: var(--accent); }
.edge-label-hit {
  fill: transparent;
  pointer-events: all;
  cursor: pointer;
}
.node {
  position: absolute;
  min-width: 180px;
  min-height: 100px;
  padding: 14px 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, #1f2530, #171c24);
  border: 1px solid var(--line);
  box-shadow: 0 12px 24px rgba(0,0,0,0.25);
  user-select: none;
}
.node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(134, 167, 255, 0.25), 0 12px 24px rgba(0,0,0,0.25);
}
.node-title {
  font-weight: 700;
  margin-bottom: 10px;
  outline: none;
  white-space: pre-wrap;
}
.node-text {
  color: var(--muted);
  white-space: pre-wrap;
  line-height: 1.4;
  padding-right: 16px;
  outline: none;
}
.node-title[contenteditable="true"],
.node-text[contenteditable="true"] {
  user-select: text;
  cursor: text;
}
.node-port {
  position: absolute;
  right: -8px;
  top: 10px;
  width: 20px;
  height: calc(100% - 20px);
  border-radius: 12px;
  background: transparent;
  border: none;
  cursor: crosshair;
}
.node-resizer-hit {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 24px;
  height: 24px;
  cursor: nwse-resize;
  background: transparent;
}
.edge-inline-editor {
  position: absolute;
  z-index: 5;
  width: 180px;
  margin: 0;
  background: #0f131a;
  border: 1px solid var(--accent);
  box-shadow: 0 8px 18px rgba(0,0,0,0.35);
}

.edge-label-text { pointer-events: none; }

.edge-line { cursor: pointer; }
