.s-graph-editor {
  --graph-surface: var(--t-surface-bg, #f1f3f5);
  --graph-bg: var(--graph-surface);
  --graph-panel: var(--t-card-bg, white);
  --graph-ink: var(--t-text, #17202a);
  --graph-muted: color-mix(in srgb, var(--graph-ink) 65%, var(--graph-panel));
  --graph-line: var(--t-card-border-color, #d8dde3);
  --graph-accent: var(--t-primary, #5254bd);
  --graph-radius: min(14px, var(--t-card-radius, 12px));
  --graph-field-radius: min(8px, var(--t-input-radius, 6px));
  --graph-accent-bg: color-mix(in srgb, var(--graph-accent) 13%, var(--graph-panel));
  --graph-number: #398de0;
  --graph-boolean: #e9a146;
  --graph-text: #c770cb;
  --graph-flow: #8c99af;
  --graph-any: #8e82de;
  display: grid;
  grid-template-columns: minmax(132px, 176px) minmax(0, 1fr) minmax(154px, 218px);
  color: var(--graph-ink);
  background: var(--graph-panel);
  border: 1px solid var(--graph-line);
  border-radius: var(--graph-radius);
  overflow: hidden;
  min-width: 0;
  font: 400 0.84rem/1.4 var(--t-font, system-ui), sans-serif;
}

.s-graph-editor-brutalist, .s-graph-editor-pixel, .s-graph-editor-carbon, .s-graph-editor-metro {
  --graph-radius: 0px;
  --graph-field-radius: 0px;
}

.s-graph-editor-material3, .s-graph-editor-cartoon, .s-graph-editor-liquid-glass {
  --graph-radius: 20px;
  --graph-field-radius: 10px;
}

/* Liquid Glass uses light text in light mode, so give both graph modes a matching surface. */
html:not(.dark) .s-graph-editor-liquid-glass {
  --graph-ink: #f5f7ff;
  --graph-panel: #253352;
  --graph-surface: #192541;
  --graph-line: #596681;
  --graph-accent: color-mix(in srgb, var(--t-primary, #5254bd) 45%, white);
  background: rgb(37 51 82 / 91%);
  color-scheme: dark;
}

.s-graph-editor *, .s-graph-editor *::before, .s-graph-editor *::after { box-sizing: border-box; }
.s-graph-editor [data-tone="event"] { --node-tone: #41ad83; }
.s-graph-editor [data-tone="operation"] { --node-tone: #4e9bb8; }
.s-graph-editor [data-tone="condition"] { --node-tone: var(--graph-boolean); }
.s-graph-editor [data-tone="number"] { --node-tone: var(--graph-number); }
.s-graph-editor [data-tone="text"] { --node-tone: var(--graph-text); }
.s-graph-editor [data-tone="graph"] { --node-tone: var(--graph-any); }
.s-graph-editor [data-type="number"] { --port-color: var(--graph-number); }
.s-graph-editor [data-type="boolean"] { --port-color: var(--graph-boolean); }
.s-graph-editor [data-type="text"] { --port-color: var(--graph-text); }
.s-graph-editor [data-type="flow"] { --port-color: var(--graph-flow); }
.s-graph-editor button {
  border: 1px solid transparent;
  border-radius: var(--graph-field-radius);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.s-graph-editor button:disabled { cursor: default; opacity: 0.35; }
.s-graph-editor button:focus-visible, .s-graph-editor input:focus-visible,
.s-graph-editor select:focus-visible, .s-graph-edge-hit:focus-visible {
  outline: 2px solid var(--graph-accent);
  outline-offset: 2px;
}
.s-graph-editor input:not([type="checkbox"]), .s-graph-editor select {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 0.55rem 0.6rem;
  background: var(--graph-bg);
  border: 1px solid var(--graph-line);
  border-radius: var(--graph-field-radius);
  color: var(--graph-ink);
  font: inherit;
}
.s-graph-editor input::placeholder { color: var(--graph-muted); }
.s-graph-palette, .s-graph-inspector { min-width: 0; padding: 1rem 0.85rem; }
.s-graph-palette { display: flex; flex-direction: column; border-inline-end: 1px solid var(--graph-line); }
.s-graph-inspector { border-inline-start: 1px solid var(--graph-line); }
.s-graph-editor h2 { margin: 0 0 0.85rem; font-size: 0.95rem; font-weight: 680; }
.s-graph-editor h3 {
  margin: 0 0 0.4rem;
  color: var(--graph-muted);
  font-size: 0.69rem;
  font-weight: 650;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}
.s-graph-palette-list { margin-top: 1rem; }
.s-graph-palette-group + .s-graph-palette-group { margin-top: 0.8rem; }
.s-graph-editor .s-graph-palette-node {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 0.55rem;
  padding: 0.35rem 0.4rem;
  color: var(--graph-ink);
  text-align: start;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.s-graph-drag-preview {
  position: fixed;
  z-index: 2;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--graph-accent);
  border-radius: var(--graph-field-radius);
  background: var(--graph-panel);
  pointer-events: none;
}
.s-graph-palette-node span { width: 0.54rem; height: 0.54rem; border-radius: 2px; background: var(--node-tone, var(--graph-accent)); flex: none; }
.s-graph-palette-node b { margin-inline-start: auto; color: var(--graph-muted); font-weight: 400; }
.s-graph-palette-node:hover, .s-graph-toolbar button:not(:disabled):hover,
.s-graph-zoom button:hover, .s-graph-inspector button:hover { background: var(--graph-accent-bg); }
.s-graph-palette-help, .s-graph-hint { color: var(--graph-muted); font-size: 0.78rem; }
.s-graph-palette-help { margin: auto 0 0; padding-top: 1rem; }
.s-graph-hint { margin: 0.75rem 0; overflow-wrap: anywhere; }
.s-graph-workspace { display: flex; min-width: 0; min-height: 0; flex-direction: column; }
.s-graph-toolbar, .s-graph-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.8rem;
}
.s-graph-toolbar { min-height: 3rem; border-bottom: 1px solid var(--graph-line); }
.s-graph-toolbar nav { display: flex; align-items: center; gap: 0.35rem; min-width: 0; overflow-x: auto; white-space: nowrap; }
.s-graph-toolbar nav button { color: var(--graph-accent); font-size: inherit; padding: 0.18rem 0.3rem; }
.s-graph-toolbar nav span { color: var(--graph-muted); }
.s-graph-toolbar strong { font-weight: 650; }
.s-graph-toolbar-actions { display: flex; align-items: center; flex-shrink: 0; gap: 0.45rem; }
.s-flow-direction {
  display: flex;
  gap: 0.12rem;
  padding: 0.12rem;
  border: 1px solid var(--graph-line);
  border-radius: var(--graph-field-radius);
}
.s-flow-direction button { font-size: 0.72rem; padding: 0.3rem 0.4rem; }
.s-flow-direction button[aria-pressed="true"] {
  color: var(--graph-ink);
  font-weight: 650;
  background: var(--graph-accent-bg);
  border-color: var(--graph-accent);
}
.s-graph-history { display: flex; gap: 0.2rem; }
.s-graph-history button { width: 1.85rem; height: 1.85rem; font-size: 1.15rem; line-height: 1; }
.s-graph-status {
  min-height: 2.15rem;
  border-top: 1px solid var(--graph-line);
  color: var(--graph-muted);
  font-size: 0.73rem;
}
.s-graph-status span:first-child { flex-shrink: 0; }
.s-graph-status span:last-child { text-align: end; }
.s-graph-stage {
  position: relative;
  isolation: isolate;
  flex: 1;
  min-height: var(--graph-canvas-height, 520px);
  background: var(--graph-bg);
}
.s-graph-canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background-image: radial-gradient(circle, color-mix(in srgb, var(--graph-ink) 19%, transparent) 0.8px, transparent 1px);
  cursor: grab;
}
.s-graph-canvas:focus-visible { outline: 2px solid var(--graph-accent); outline-offset: -2px; }
.s-graph-canvas.panning { cursor: grabbing; }
.s-graph-plane {
  position: absolute;
  width: 1px;
  height: 1px;
  transform-origin: top left;
  pointer-events: none;
}
.s-graph-wires { position: absolute; width: 1px; height: 1px; overflow: visible; }
.s-graph-edge, .s-graph-draft {
  fill: none;
  stroke: var(--port-color, var(--graph-any));
  stroke-width: 2.2;
  pointer-events: none;
}
.s-graph-edge-hit { fill: none; stroke: transparent; stroke-width: 15; pointer-events: stroke; cursor: pointer; }
.s-graph-arrow { fill: var(--port-color, var(--graph-any)); pointer-events: none; }
.s-graph-wires g:hover .s-graph-edge, .s-graph-wires g.selected .s-graph-edge { stroke-width: 3.75; }
.s-graph-wires g.selected .s-graph-edge { stroke: var(--graph-accent); }
.s-graph-wires g.selected .s-graph-arrow { fill: var(--graph-accent); }
.s-graph-draft { stroke: var(--graph-accent); stroke-dasharray: 5 4; }
.s-graph-empty {
  position: absolute;
  top: 48%;
  width: 100%;
  margin: 0;
  text-align: center;
  color: var(--graph-muted);
  pointer-events: none;
}
.s-graph-node {
  position: absolute;
  pointer-events: auto;
  border-radius: var(--graph-radius);
  background: var(--graph-panel);
  box-shadow: inset 0 0 0 1px var(--graph-line), 0 4px 14px #11182726;
}
.s-graph-node.selected { z-index: 1; box-shadow: 0 0 0 2px var(--graph-accent), 0 4px 15px #11182735; }
.s-graph-node-bar {
  display: flex;
  align-items: center;
  height: var(--graph-header);
  border-bottom: 1px solid var(--graph-line);
  border-radius: var(--graph-radius) var(--graph-radius) 0 0;
  background: color-mix(in srgb, var(--node-tone, var(--graph-accent)) 14%, var(--graph-panel));
}
.s-graph-editor .s-graph-node-title {
  display: flex;
  min-width: 0;
  height: 100%;
  flex: 1;
  align-items: center;
  gap: 0.48rem;
  padding: 0 0.55rem;
  font-size: 0.79rem;
  font-weight: 700;
  text-align: start;
  cursor: grab;
}
.s-graph-node-title:active { cursor: grabbing; }
.s-graph-node-title span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-graph-node-symbol {
  display: grid;
  place-items: center;
  flex: 0 0 23px;
  height: 23px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--node-tone, var(--graph-accent)) 24%, var(--graph-panel));
  font-size: 0.74rem;
  font-weight: 750;
}
.s-graph-node-open { width: 1.55rem; height: 1.55rem; margin-inline-end: 0.4rem; }
.s-graph-node-open:hover { background: var(--graph-accent-bg); }
.s-graph-ports { position: relative; display: flex; justify-content: space-between; }
.s-graph-port-column { display: flex; min-width: 0; max-width: 50%; flex-direction: column; }
.s-graph-editor .s-graph-port {
  position: relative;
  border: 0;
  border-radius: 0;
  height: var(--graph-port);
  padding: 0 0.72rem;
  color: var(--graph-muted);
  font-size: 0.75rem;
  text-align: start;
}
.s-graph-editor .s-graph-port:focus-visible { outline-offset: -2px; }
.s-graph-port span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-graph-port::before {
  position: absolute;
  top: calc(50% - 4.5px);
  left: -4.5px;
  width: 9px;
  height: 9px;
  border: 1px solid var(--graph-panel);
  border-radius: 50%;
  background: var(--port-color, var(--graph-any));
  box-shadow: 0 0 0 1px var(--port-color, var(--graph-any));
  content: "";
}
.s-graph-port[data-type="flow"]::before { border-radius: 2px; }
.s-graph-port[data-port-side="output"] { text-align: end; }
.s-graph-port[data-port-side="output"]::before { right: -4.5px; left: auto; }
.s-graph-port:hover, .s-graph-port.pending { background: var(--graph-accent-bg); }
.s-graph-node-summary {
  position: absolute;
  top: 5px;
  left: 10px;
  max-width: 84px;
  padding: 1px 4px;
  overflow: hidden;
  color: var(--graph-muted);
  font: 11px/1.6 ui-monospace, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
.s-graph-node[data-tone="graph"] .s-graph-node-summary { display: none; }

.s-graph-editor[data-mode="flowchart"] {
  --graph-bg: color-mix(in srgb, var(--graph-surface) 46%, var(--graph-panel));
  --graph-flow: color-mix(in srgb, var(--graph-ink) 61%, var(--graph-panel));
}
.s-graph-editor[data-mode="flowchart"] .s-graph-canvas {
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--graph-ink) 9%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--graph-ink) 9%, transparent) 1px, transparent 1px);
}
.s-graph-palette-node span[data-shape] { width: 13px; height: 10px; }
.s-graph-palette-node span[data-shape="terminator"] { border-radius: 12px; }
.s-graph-palette-node span[data-shape="decision"] { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.s-graph-palette-node span[data-shape="io"] { clip-path: polygon(24% 0, 100% 0, 76% 100%, 0 100%); }
.s-graph-palette-node span[data-shape="message"] { clip-path: polygon(0 0, 72% 0, 100% 35%, 100% 100%, 0 100%); }
.s-graph-palette-node span[data-shape="subprocess"] { border-inline: 3px double var(--graph-panel); }
.s-graph-editor[data-mode="flowchart"] .s-graph-edge, .s-graph-editor[data-mode="flowchart"] .s-graph-draft {
  stroke-linecap: round;
  stroke-linejoin: round;
}
.s-flow-edge-label {
  fill: var(--graph-ink);
  stroke: var(--graph-bg);
  stroke-width: 4px;
  stroke-linejoin: round;
  paint-order: stroke;
  font-size: 11px;
  font-weight: 650;
  pointer-events: none;
}
.s-graph-node.s-flow-node, .s-graph-node.s-flow-node.selected { background: transparent; box-shadow: none; }
.s-flow-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: color-mix(in srgb, var(--node-tone, var(--graph-accent)) 12%, var(--graph-panel));
  stroke: color-mix(in srgb, var(--node-tone, var(--graph-accent)) 68%, var(--graph-ink));
  stroke-width: 1.75px;
  pointer-events: none;
}
.s-flow-outline-detail { fill: none; stroke-width: 1.25px; }
.s-flow-node.selected .s-flow-outline { stroke: var(--graph-accent); stroke-width: 3px; }
.s-graph-editor .s-flow-title {
  position: absolute;
  inset: 0 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 0;
  border: 0;
  color: var(--graph-ink);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  cursor: grab;
}
.s-graph-editor .s-flow-title:active { cursor: grabbing; }
.s-flow-node[data-shape="decision"] .s-flow-title { inset-inline: 21%; }
.s-flow-node[data-shape="subprocess"] .s-flow-title { inset-inline: 17px; }
.s-flow-title span, .s-flow-title small {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.s-flow-title small { color: var(--graph-muted); font-weight: 400; font-size: 0.68rem; }
.s-graph-editor .s-flow-open { position: absolute; right: 13px; top: 3px; padding: 0 0.15rem; line-height: 1.1; }
.s-flow-open:hover { background: var(--graph-accent-bg); }
.s-graph-editor .s-flow-port, .s-graph-editor .s-flow-resize {
  position: absolute;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  background: transparent;
  border: 0;
  padding: 0;
}
.s-graph-editor .s-flow-port { cursor: crosshair; }
.s-flow-port::before, .s-flow-resize::before {
  position: absolute;
  inset: 5px;
  content: "";
  border: 1.5px solid var(--port-color, var(--graph-accent));
  border-radius: 50%;
  background: var(--graph-panel);
}
.s-flow-port:hover::before, .s-flow-port.pending::before { background: var(--port-color, var(--graph-accent)); }
.s-graph-editor .s-flow-resize { top: 100%; left: 100%; cursor: nwse-resize; }
.s-flow-resize::before { border-color: var(--graph-accent); border-radius: 2px; }
.s-flow-resize:hover::before { background: var(--graph-accent); }
.s-flow-size { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

.s-graph-zoom, .s-graph-minimap {
  position: absolute;
  bottom: 0.7rem;
  border: 1px solid var(--graph-line);
  border-radius: var(--graph-field-radius);
  background: var(--graph-panel);
}
.s-graph-zoom { display: flex; align-items: center; inset-inline-start: 0.7rem; gap: 0.15rem; padding: 0.2rem; }
.s-graph-zoom button { min-width: 1.75rem; min-height: 1.65rem; padding: 0.1rem 0.32rem; }
.s-graph-zoom span { min-width: 3.1rem; text-align: center; font: 0.73rem ui-monospace, monospace; }
.s-graph-minimap { inset-inline-end: 0.7rem; width: 146px; height: 88px; overflow: hidden; pointer-events: none; }
.s-graph-minimap span, .s-graph-minimap div { position: absolute; }
.s-graph-minimap span { border-radius: 2px; background: color-mix(in srgb, var(--graph-accent) 45%, var(--graph-panel)); }
.s-graph-minimap span.active { background: var(--graph-accent); }
.s-graph-minimap div { border: 1px solid var(--graph-accent); background: color-mix(in srgb, var(--graph-accent) 8%, transparent); }
.s-graph-inspector label { display: grid; gap: 0.32rem; margin-bottom: 0.85rem; color: var(--graph-muted); font-size: 0.78rem; }
.s-graph-selected-type { margin: 0 0 0.85rem; font-weight: 650; color: var(--graph-accent); }
.s-graph-editor .s-graph-remove, .s-graph-editor .s-graph-inspector-open {
  width: 100%;
  padding: 0.4rem;
  border-color: var(--graph-line);
}
.s-graph-editor .s-graph-remove {
  margin-top: 0.55rem;
  color: color-mix(in srgb, var(--t-error, #bb354a) 72%, var(--graph-ink));
}

@media (max-width: 820px) {
  .s-graph-editor { grid-template-columns: 136px minmax(0, 1fr); }
  .s-graph-inspector { grid-column: 1 / -1; border-inline-start: 0; border-top: 1px solid var(--graph-line); }
}

@media (max-width: 520px) {
  .s-graph-editor[data-mode="flowchart"] .s-graph-toolbar { flex-wrap: wrap; }
  .s-graph-editor { grid-template-columns: minmax(0, 1fr); }
  .s-graph-palette { border-inline-end: 0; border-bottom: 1px solid var(--graph-line); }
  .s-graph-palette-list { display: flex; gap: 1rem; overflow-x: auto; }
  .s-graph-palette-group { flex: 0 0 125px; }
  .s-graph-palette-group + .s-graph-palette-group { margin-top: 0; }
  .s-graph-minimap { display: none; }
  .s-graph-stage { min-height: 430px; }
}
