* { box-sizing: border-box; }

/* Design tokens. Colours, type sizes, spacing and radii are defined once here;
   the rules below refer to them. Text colours keep at least 4.5:1 contrast on
   every light surface they sit on, form-field borders at least 3:1. */
:root {
  /* Surfaces */
  --bg: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #f1f5f9;
  --bg-hover: #e2e8f0;
  --canvas-bg: #fafbfc;
  --canvas-dot: #dde1e7;

  /* Text */
  --text: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #5b6474;
  --text-disabled: #9ca3af;

  /* Borders */
  --border-subtle: #e5e7eb;
  --border: #d1d5db;
  --border-input: #868e9a;
  --border-strong: #6b7280;

  /* Accent and links */
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --accent-softer: #eff6ff;
  --accent-ring: rgba(37, 99, 235, 0.25);
  --focus-on-dark: #93c5fd;
  --link: #1d4ed8;
  --link-hover: #1e3a8a;

  /* Status */
  --danger: #b91c1c;
  --danger-strong: #dc2626;
  --danger-dark: #991b1b;
  --danger-soft: #fef2f2;
  --danger-tint: #fee2e2;
  --danger-border: #fecaca;
  --danger-border-strong: #f87171;
  --warning: #92400e;
  --warning-strong: #b45309;
  --warning-soft: #fffbeb;
  --warning-tint: #fef3c7;
  --warning-border: #fcd34d;
  --success: #166534;
  --success-strong: #15803d;
  --success-soft: #f0fdf4;
  --success-tint: #d1fae5;
  --success-border: #6ee7b7;
  --waiting: #6d28d9;
  --waiting-strong: #9333ea;
  --waiting-soft: #f5f3ff;
  --waiting-border: #a78bfa;
  --running-strong: #a16207;
  --badge-bg: #e0e7ff;
  --badge-text: #3730a3;

  /* Dark toolbar and toast */
  --chrome-bg: #1f2937;
  --chrome-edge: #111827;
  --chrome-btn: #374151;
  --chrome-btn-hover: #4b5563;
  --chrome-border: #4b5563;
  --chrome-text: #f9fafb;
  --chrome-text-dim: #d1d5db;

  /* Canvas: node headers by type, connections */
  --node-border: #cbd5e1;
  --node-default: #eef2f7;
  --node-start: #d1fae5;
  --node-stop: #fecaca;
  --node-agent: #ddd6fe;
  --node-if: #fde68a;
  --node-case: #fef3c7;
  --node-loop: #fed7aa;
  --node-json: #bae6fd;
  --node-save: #fce7f3;
  /* Stronger shade of each header colour, for the palette's stripes. */
  --node-default-accent: #94a3b8;
  --node-start-accent: #34d399;
  --node-stop-accent: #f87171;
  --node-agent-accent: #a78bfa;
  --node-if-accent: #fbbf24;
  --node-case-accent: #fcd34d;
  --node-loop-accent: #fb923c;
  --node-json-accent: #38bdf8;
  --node-save-accent: #f472b6;
  --node-frame-accent: #818cf8;
  --template-bg: #f5f3ff;
  --template-bg-hover: #ede9fe;
  --template-border: #c4b5fd;
  --edge: #6b7280;
  --edge-back: #b45309;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: 10px;
  --fs-sm: 11px;
  --fs-base: 12px;
  --fs-md: 13px;
  --fs-lg: 15px;
  --fs-xl: 20px;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;

  /* Radii and elevation */
  --radius: 4px;
  --radius-lg: 6px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 2px 8px rgba(15, 23, 42, 0.14);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.24);
}

/* Explicit light background: without it the views show whatever the host
   window paints behind the page (dark in some embedded browsers). */
html, body { height: 100%; margin: 0; font-family: var(--font-sans); font-size: var(--fs-md); color: var(--text); background: var(--bg); color-scheme: light; }
#app { display: flex; flex-direction: column; height: 100vh; }
code, pre, kbd, samp { font-family: var(--font-mono); }
code { font-size: 0.92em; }
h2 { font-size: var(--fs-xl); }

/* Buttons: one base look, plus .primary-btn for the main action of a view and
   .danger-btn for actions that delete or remove something. The dark toolbar,
   the canvas HUD and link-style buttons keep their own rules below. */
button {
  font-family: inherit; font-size: var(--fs-base); line-height: 1.35;
  padding: 4px 10px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border-input); border-radius: var(--radius); cursor: pointer;
}
button:hover { background: var(--bg-muted); }
button:active { background: var(--bg-hover); }
button:disabled { color: var(--text-disabled); background: var(--bg-subtle); border-color: var(--border); cursor: default; }
.primary-btn, #modal-ok { color: #fff; background: var(--accent); border-color: var(--accent-hover); font-weight: 600; }
.primary-btn:hover, #modal-ok:hover { background: var(--accent-hover); }
.danger-btn { color: var(--danger); border-color: var(--danger-border-strong); }
.danger-btn:hover { color: #fff; background: var(--danger-strong); border-color: var(--danger-strong); }
.danger-btn:active { background: var(--danger); }

/* Keyboard focus: one clear ring on every control (a mouse click on a button
   shows none); a light ring on the dark toolbar. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }
#toolbar button:focus-visible { outline-color: var(--focus-on-dark); }

#toolbar {
  display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; row-gap: var(--sp-1);
  padding: 6px 10px; background: var(--chrome-bg); color: var(--chrome-text);
  border-bottom: 1px solid var(--chrome-edge);
}
#toolbar .brand { font-weight: 700; margin-right: var(--sp-2); letter-spacing: 0.5px; }
#toolbar button { background: var(--chrome-btn); color: var(--chrome-text); border: 1px solid var(--chrome-border); padding: 4px 10px; border-radius: var(--radius); cursor: pointer; font-size: var(--fs-base); white-space: nowrap; }
#toolbar button:hover { background: var(--chrome-btn-hover); }
#toolbar button:disabled { opacity: 0.45; cursor: default; }
#toolbar button:disabled:hover { background: var(--chrome-btn); }
#toolbar button.active { background: var(--accent); border-color: var(--accent-hover); }
#toolbar .sep { width: 1px; height: 22px; background: var(--chrome-border); margin: 0 var(--sp-1); }
#toolbar .pill { margin-left: auto; padding: 3px 10px; border-radius: var(--radius-pill); background: var(--chrome-btn); font-size: var(--fs-sm); }
/* Status colours are dark enough for white text (at least 4.5:1). */
#toolbar .pill.running { background: var(--running-strong); }
#toolbar .pill.waiting_for_user { background: var(--waiting-strong); }
#toolbar .pill.done { background: var(--success-strong); }
#toolbar .pill.failed { background: var(--danger-strong); }
/* View switcher: the view buttons read as tabs, the rest as action buttons. */
#toolbar .view-btn { background: transparent; border-color: transparent; color: var(--chrome-text-dim); padding: 4px 8px; }
#toolbar .view-btn:hover { background: var(--chrome-btn); color: var(--chrome-text); }
#toolbar .view-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
/* Too narrow for one row: the tabs move together onto a second row instead of
   splitting across both. */
@media (max-width: 1419px) {
  #toolbar .sep:has(+ .view-btn) { flex-basis: 100%; height: 0; margin: 0; background: none; }
}

#main { display: flex; flex: 1; min-height: 0; }
#palette { width: 180px; background: var(--bg-muted); border-right: 1px solid var(--border); overflow: auto; padding: var(--sp-2); }
#palette h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-base); text-transform: uppercase; color: var(--text-secondary); }
#palette .palette-hint { margin: -4px 0 var(--sp-2); font-size: var(--fs-xs); line-height: 1.35; color: var(--text-muted); }
.palette-section-label { margin: 10px 0 5px; font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
.palette-section-label:first-child { margin-top: 0; }
.palette-item { padding: 6px 8px; margin-bottom: var(--sp-1); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); cursor: grab; font-size: var(--fs-base); user-select: none; }
.palette-item:hover { background: var(--bg-hover); }
.palette-item.template-item { border-color: var(--template-border); background: var(--template-bg); }
.palette-item.template-item:hover { background: var(--template-bg-hover); }
/* Each node item carries the colour of its node's header on the canvas. */
.palette-item[data-type] { border-left: 4px solid var(--node-default-accent); padding-left: 7px; }
.palette-item[data-type="start"] { border-left-color: var(--node-start-accent); }
.palette-item[data-type="stop"] { border-left-color: var(--node-stop-accent); }
.palette-item[data-type="agent"] { border-left-color: var(--node-agent-accent); }
.palette-item[data-type="if"] { border-left-color: var(--node-if-accent); }
.palette-item[data-type="case"] { border-left-color: var(--node-case-accent); }
.palette-item[data-type="max_iterations"] { border-left-color: var(--node-loop-accent); }
.palette-item[data-type="duplicate_json"], .palette-item[data-type="merge_json"] { border-left-color: var(--node-json-accent); }
.palette-item[data-type="save_json"] { border-left-color: var(--node-save-accent); }
.palette-item[data-type="frame"] { border-left-color: var(--node-frame-accent); }

#side-panel { width: 320px; background: var(--bg-subtle); border-left: 1px solid var(--border); overflow: auto; padding: var(--sp-3); }
#side-panel h3 { margin: 0 0 10px; font-size: var(--fs-base); text-transform: uppercase; color: var(--text-secondary); }
#side-panel label { display: block; margin: var(--sp-2) 0 3px; font-weight: 600; font-size: var(--fs-sm); color: var(--text-secondary); }
#side-panel input[type="text"], #side-panel input[type="number"], #side-panel select, #side-panel textarea { width: 100%; padding: 4px 6px; border: 1px solid var(--border-input); border-radius: var(--radius); font-size: var(--fs-base); font-family: inherit; background: var(--bg); color: var(--text); }
#side-panel textarea { min-height: 60px; resize: vertical; }
/* Read-only fields (the connection's ends) must not look editable. */
#side-panel input[readonly] { background: var(--bg-muted); border-color: var(--border); color: var(--text-secondary); }
#side-panel button { padding: 4px 10px; margin-top: 6px; cursor: pointer; }
#side-panel .row { display: flex; gap: 6px; align-items: center; }
#side-panel .muted { color: var(--text-muted); }
/* Section headings and separators split the panel into clear groups. */
#side-panel h4 { padding-top: var(--sp-2); border-top: 1px solid var(--border-subtle); }
#side-panel hr { border: 0; border-top: 1px solid var(--border-subtle); }

.view { flex: 1; min-width: 0; overflow: auto; display: none; position: relative; }
.view.active { display: block; }

#canvas-wrap.active { display: block; }
#canvas { position: relative; width: 100%; height: 100%; background: var(--canvas-bg); background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px); background-size: 16px 16px; overflow: hidden; }
#edges-svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
#edges-svg .edge { fill: none; stroke: var(--edge); stroke-width: 2; }
#edges-svg .edge.back { stroke-dasharray: 6 4; stroke: var(--edge-back); }
#edges-svg .edge:hover { stroke: var(--accent); }
#edges-svg .edge-hit { fill: none; stroke: rgba(0,0,0,0.001); stroke-width: 14; pointer-events: stroke; cursor: pointer; }
#edges-svg .edge-temp { stroke: var(--accent); stroke-dasharray: 4 4; }

#world-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#nodes-layer { position: absolute; left: 0; top: 0; pointer-events: none; }
/* Node geometry is shared with canvas.js (HEADER_H 24, NODE_BORDER_W 1,
   PORT_R 6): keep the header height, border width and port size as they are,
   or connections stop meeting their ports. */
.node {
  position: absolute; min-width: 140px; background: var(--bg); border: 1px solid var(--node-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); cursor: move; user-select: none;
  pointer-events: auto;
}
.node:not(.node-frame):not(.selected):hover { box-shadow: var(--shadow-md); }
.node.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.node .header { height: 24px; padding: 4px 8px; background: var(--node-default); font-weight: 600; font-size: var(--fs-base); border-bottom: 1px solid var(--border-subtle); border-radius: 5px 5px 0 0; }
.node .body { padding: 6px 8px; font-size: var(--fs-sm); color: var(--text-secondary); }
.node .ports { position: relative; height: 0; }
.port {
  position: absolute; width: 12px; height: 12px; background: var(--bg); border: 2px solid var(--edge); border-radius: 50%;
  cursor: crosshair;
}
.port:hover { border-color: var(--accent); background: var(--accent-soft); }
.port.in { left: -7px; }
.port.out { right: -7px; }
.port-label { position: absolute; font-size: var(--fs-xs); color: var(--text-secondary); pointer-events: none; }

.node[data-type="start"] .header { background: var(--node-start); }
.node[data-type="stop"] .header { background: var(--node-stop); }
.node[data-type="agent"] .header { background: var(--node-agent); }
.node[data-type="if"] .header { background: var(--node-if); }
.node[data-type="case"] .header { background: var(--node-case); }
.node[data-type="case"] .port-label { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node[data-type="max_iterations"] .header { background: var(--node-loop); }
.node[data-type="duplicate_json"] .header, .node[data-type="merge_json"] .header { background: var(--node-json); }
.node[data-type="save_json"] .header { background: var(--node-save); }

.registry-view { padding: var(--sp-4); }
.registry-view h2 { margin: 0 0 var(--sp-3); }
.registry-view table { width: 100%; border-collapse: collapse; background: var(--bg); }
.registry-view th, .registry-view td { padding: 6px 7px; border: 1px solid var(--border-subtle); text-align: left; vertical-align: top; }
.registry-view th { background: var(--bg-muted); font-size: var(--fs-sm); text-transform: uppercase; color: var(--text-secondary); }
.registry-view .system-badge { display: inline-block; padding: 1px 6px; background: var(--badge-bg); color: var(--badge-text); border-radius: var(--radius); font-size: var(--fs-xs); margin-left: var(--sp-1); }
.registry-view tr.agent-global-row td { background: var(--agent-global-bg); }
.registry-view tr.agent-global-row td:first-child { box-shadow: inset 4px 0 0 var(--agent-global-accent); }
.registry-view tr.agent-global-row .system-badge { background: var(--agent-global-badge-bg); color: var(--agent-global-badge-text); }
.registry-view .row-actions button { margin-right: var(--sp-1); }
.registry-view input[type="text"], .registry-view input[type="number"], .registry-view select, .registry-view textarea { width: 100%; padding: 3px 6px; border: 1px solid var(--border-input); border-radius: var(--radius); font-size: var(--fs-base); font-family: inherit; background: var(--bg); color: var(--text); }
.registry-view input[type="number"] { width: 120px; }
.registry-view textarea { min-height: 50px; }
.registry-view input:disabled, .registry-view select:disabled, .registry-view textarea:disabled { background: var(--bg-muted); border-color: var(--border); color: var(--text-muted); }
.registry-view .toolbar { margin-bottom: var(--sp-2); }
/* Boxed sections (Prompts, Connectors) look like the Run view's sections. */
.registry-view .run-section { margin-top: 14px; padding: var(--sp-3); background: var(--bg); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); }
.registry-view .run-section h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-md); }
.registry-view > .errors-list { margin-bottom: var(--sp-1); }
.registry-view .create-id-control { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.registry-view .create-id-control label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); }
.registry-view .create-id-control input[type="text"] { width: 180px; }
/* Narrow windows: controls keep a readable minimum width and long IDs wrap
   instead of squeezing the inputs; a table that still does not fit scrolls
   sideways with its view. The header row stays visible on long tables. */
.registry-view td > input[type="text"] { min-width: 96px; }
.registry-view td > select { min-width: 96px; }
.registry-view td > textarea { min-width: 160px; }
.registry-view td > code { display: inline-block; min-width: 11ch; overflow-wrap: anywhere; }
#agents-view td > input[type="text"] { min-width: 160px; }
#agents-view td > code { overflow-wrap: normal; }
/* top: minus the view's padding, so the header sticks to the view's top edge. */
.registry-view thead th { position: sticky; top: calc(-1 * var(--sp-4)); z-index: 1; box-shadow: inset 0 -1px 0 var(--border); }
.settings-guide {
  margin: 10px 0 var(--sp-4);
  padding: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.settings-guide-header {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}
.settings-guide-header h3 {
  margin: 0;
  font-size: var(--fs-md);
  color: var(--text);
}
.settings-guide-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.settings-guide-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--sp-2);
  margin: 0;
  padding: 0;
  list-style: none;
}
.settings-guide-step {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: var(--sp-2);
  padding: var(--sp-2);
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  min-width: 0;
}
.settings-guide-number {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 700;
}
.settings-guide-step-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 2px var(--sp-2);
  margin-bottom: var(--sp-1);
}
.settings-guide-step h4 {
  margin: 0;
  font-size: var(--fs-base);
  color: var(--text);
}
.settings-guide-status {
  color: var(--text-secondary);
  font-size: var(--fs-xs);
}
.settings-guide-step p {
  margin: 0 0 6px;
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  line-height: 1.35;
}
.settings-guide-fields {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin-bottom: 6px;
}
.settings-guide-fields code {
  background: var(--badge-bg);
  color: var(--badge-text);
  padding: 1px 4px;
  border-radius: var(--radius);
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
}
.settings-guide-where {
  color: var(--text-muted);
  font-size: var(--fs-xs);
}

#run-view { padding: var(--sp-4); }
#run-view h2 { margin: 0 0 var(--sp-2); }
/* A wide log table scrolls inside its section instead of running past it. */
#run-view .run-section { margin-top: 14px; padding: var(--sp-3); background: var(--bg); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); overflow-x: auto; }
#run-view .run-section h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-md); }
#run-view .log-table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
#run-view .log-table th, #run-view .log-table td { padding: 4px 6px; border: 1px solid var(--border-subtle); }
#run-view .log-table th { background: var(--bg-muted); }
#run-view .log-table tr.completed { background: var(--success-soft); }
#run-view .log-table tr.failed { background: var(--danger-soft); }
#run-view .log-table tr.cancelled { background: var(--warning-soft); color: var(--warning); }
#run-view .log-table tr.running { background: var(--accent-softer); font-style: italic; }
#run-view .log-table tr.waiting { background: var(--bg-muted); color: var(--text-muted); }
#run-view .log-table tr.selected { background: var(--accent-soft) !important; }
#run-view .log-table tr { cursor: pointer; }
#run-view select { padding: 2px 4px; border: 1px solid var(--border-input); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: var(--fs-base); }
#run-view .sim-panel { font-size: var(--fs-base); }
#run-view .sim-panel input[type="number"] { padding: 2px 4px; border: 1px solid var(--border-input); border-radius: var(--radius); }
#run-view .sim-panel select { padding: 2px 4px; border: 1px solid var(--border-input); border-radius: var(--radius); }
#run-view .cancelled-banner { background: var(--warning-tint); color: var(--warning); border: 1px solid var(--warning-border); padding: 6px 10px; border-radius: var(--radius); margin: 4px 0; }
#run-view .waiting-banner { background: var(--waiting-soft); color: var(--waiting); border: 1px solid var(--waiting-border); padding: 6px 10px; border-radius: var(--radius); margin: 4px 0; }
#toolbar .pill.cancelled { background: var(--warning); }
#toolbar .pill.idle { background: var(--chrome-btn); }
/* minmax(0, 1fr): long JSON lines must not widen the columns past the view. */
#run-view .inspector { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-2); margin-top: var(--sp-2); }
#run-view .inspector > div { min-width: 0; }
#run-view .inspector pre { white-space: pre-wrap; overflow-wrap: anywhere; }
#run-view pre { background: var(--bg-subtle); padding: 6px 8px; max-height: 220px; overflow: auto; border: 1px solid var(--border-subtle); border-radius: var(--radius); font-size: var(--fs-sm); }
#run-view .user-inputs-form input { width: 100%; padding: 3px 6px; border: 1px solid var(--border-input); border-radius: var(--radius); font-size: var(--fs-base); }
#run-view .user-inputs-form summary { cursor: pointer; font-weight: 600; font-size: var(--fs-md); }
#run-view .run-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
#run-view .run-mode-toggle { display: flex; gap: var(--sp-3); align-items: center; margin-left: var(--sp-3); font-size: var(--fs-base); }
#run-view #btn-run-now { padding: 4px 14px; font-weight: 600; background: var(--accent); color: #fff; border: 1px solid var(--accent-hover); border-radius: var(--radius); cursor: pointer; }
#run-view #btn-run-now:hover { background: var(--accent-hover); }
#run-view #btn-run-now.real { background: var(--warning-strong); border-color: var(--warning); }
#run-view #btn-run-now.real:hover { background: var(--warning); }
#run-view #btn-run-now:disabled { opacity: 0.5; cursor: default; }
#run-view #btn-run-now:disabled:hover { background: var(--accent); }
#run-view #btn-run-now.real:disabled:hover { background: var(--warning-strong); }
#run-view .run-summary { margin-top: var(--sp-2); font-size: var(--fs-base); color: var(--text-secondary); }
#run-view .run-summary.done { color: var(--success); }
#run-view .run-summary.failed { color: var(--danger); }
#run-view .run-summary.cancelled { color: var(--warning); }
#run-view .run-summary.waiting_for_user { color: var(--waiting); }
#run-view .real-mode-warning { margin-top: var(--sp-2); background: var(--warning-soft); border: 1px solid var(--warning-border); color: var(--warning); padding: 6px 10px; border-radius: var(--radius); font-size: var(--fs-base); }

.errors-list { background: var(--danger-soft); border: 1px solid var(--danger-border); padding: var(--sp-2); border-radius: var(--radius); }
.errors-list ul { margin: 4px 0; padding-left: 20px; }
.errors-list li { font-size: var(--fs-base); }
.errors-list code { background: var(--danger-tint); padding: 1px 4px; border-radius: 2px; font-size: var(--fs-sm); }
.success-banner { background: var(--success-tint); border: 1px solid var(--success-border); padding: var(--sp-2); border-radius: var(--radius); }
.warnings-list { background: var(--warning-soft); border: 1px solid var(--warning-border); padding: var(--sp-2); border-radius: var(--radius); margin-top: var(--sp-2); }
.warnings-list ul { margin: 4px 0; padding-left: 20px; }
.warnings-list li { font-size: var(--fs-base); }
.warnings-list code { background: var(--warning-tint); padding: 1px 4px; border-radius: 2px; font-size: var(--fs-sm); }
.issue-item { margin: 4px 0 var(--sp-2); }
.issue-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; margin-top: 2px; font-size: var(--fs-sm); color: var(--text-muted); }
.issue-meta code { font-size: var(--fs-xs); }
.issue-link { background: none; border: none; padding: 0; margin: 0; color: var(--link); text-decoration: underline; cursor: pointer; font: inherit; }
.issue-link:hover, .issue-link:active { color: var(--link-hover); background: none; }
.issue-hint { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-secondary); }

#modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: center; justify-content: center; z-index: 1000; }
#modal-backdrop.hidden { display: none; }
/* Dialogs stay narrow enough to read (about 100 characters a line). */
#modal { background: var(--bg); padding: var(--sp-4) var(--sp-5) var(--sp-4); border-radius: 8px; min-width: 360px; max-width: min(720px, calc(100vw - 32px)); max-height: 85vh; overflow: auto; box-shadow: var(--shadow-lg); }
#modal h3 { margin: 0 0 var(--sp-3); font-size: var(--fs-lg); }
#modal-actions { margin-top: var(--sp-4); text-align: right; }
#modal-actions button { padding: 6px 18px; margin-left: 6px; cursor: pointer; }

.muted { color: var(--text-muted); }
.hidden { display: none !important; }

/* Short-lived status message (run opened, file downloaded, ...). */
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 1100;
  max-width: min(560px, 90vw); padding: var(--sp-2) 14px; border-radius: var(--radius-lg); line-height: 1.4;
  background: var(--chrome-bg); color: var(--chrome-text); font-size: var(--fs-base); box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.visible { opacity: 1; }

/* Side-panel additions: validation badge, dangling-edge warning. */
#side-title { display: flex; align-items: center; gap: 6px; }
#side-title .error-badge {
  display: inline-block; padding: 1px 6px; background: var(--danger-border); color: var(--danger-dark);
  border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 600; text-transform: none;
}
.dangling-warn {
  margin-top: var(--sp-2); padding: 6px 8px; background: var(--warning-soft); border: 1px solid var(--warning-border);
  border-radius: var(--radius); font-size: var(--fs-sm); color: var(--warning);
}
#side-panel .node-issues { margin: 0 0 var(--sp-2); padding: 6px 8px; border-radius: var(--radius); font-size: var(--fs-sm); }
#side-panel .node-issues.errors { background: var(--danger-soft); border: 1px solid var(--danger-border); color: var(--danger-dark); }
#side-panel .node-issues.warnings { background: var(--warning-soft); border: 1px solid var(--warning-border); color: var(--warning); }
#side-panel .node-issues ul { margin: 2px 0 0; padding-left: var(--sp-4); }
#side-panel .field-hint { color: var(--text-muted); font-size: var(--fs-xs); margin-top: 2px; }

/* Expression editor / block builder UI. */
.expr-editor { display: flex; flex-direction: column; gap: 6px; padding: 6px; background: var(--bg-subtle); border: 1px solid var(--border-subtle); border-radius: var(--radius); margin: 4px 0 var(--sp-2); }
.expr-editor select.block-type-sel { font-size: var(--fs-sm); }
.expr-var-picker { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-1); align-items: center; }
.expr-var-picker label { grid-column: 1 / -1; margin: 0; }
.block-builder-host { padding: var(--sp-1); background: var(--bg); border: 1px dashed var(--border); border-radius: var(--radius); }
.block-node { display: flex; flex-direction: column; gap: var(--sp-1); padding: var(--sp-1); background: var(--bg); border: 1px solid var(--border-subtle); border-radius: var(--radius); margin-top: var(--sp-1); }
.block-node > select, .block-node > input { font-size: var(--fs-sm); }
.block-node .block-child { padding-left: 10px; border-left: 2px solid var(--border-subtle); margin-top: 2px; }
.block-node .block-child > label { font-size: var(--fs-xs); text-transform: uppercase; color: var(--text-muted); }
.block-node .var-ns-sel, .block-node .var-id-sel { font-size: var(--fs-sm); }

/* Dangling edge styling. */
#edges-svg .edge.dangling { stroke: var(--danger-strong); stroke-dasharray: 4 3; }
#edges-svg .edge.selected { stroke: var(--accent); stroke-width: 3; }
#edges-svg .edge-port-dot { fill: var(--edge); }

/* Canvas HUD: zoom, fit, reset (W1). */
.canvas-hud {
  position: absolute; right: 10px; bottom: 10px; z-index: 5;
  display: flex; gap: var(--sp-1); align-items: center; padding: 4px 6px;
  background: rgba(255,255,255,0.92); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); font-size: var(--fs-base);
}
.canvas-hud .hud-btn { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 2px 8px; border-radius: var(--radius); cursor: pointer; font-size: var(--fs-base); }
.canvas-hud .hud-btn:hover { background: var(--bg-muted); }
.canvas-hud .hud-zoom-label { padding: 0 4px; font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; color: var(--text-secondary); }

/* Frame nodes (W2): translucent, dashed, lowest-Z. */
.node.node-frame {
  --frame-color: #6366f1;
  --frame-rgb: 99, 102, 241;
  background: rgba(var(--frame-rgb),0.06);
  border: 1.5px dashed var(--frame-color);
  box-shadow: none;
  cursor: default;
  min-width: 100px;
  min-height: 60px;
}
.node.node-frame.selected { border-color: var(--frame-color); box-shadow: 0 0 0 2px rgba(var(--frame-rgb),0.25); }
.node.node-frame .frame-header {
  position: absolute; left: 0; right: 0; top: 0;
  padding: 4px 8px; background: rgba(var(--frame-rgb),0.18);
  font-weight: 600; font-size: var(--fs-base); color: var(--frame-color);
  /* Darker than the frame colour so the title stays readable on its tint. */
  color: color-mix(in srgb, var(--frame-color) 70%, #000);
  border-bottom: 1px dashed var(--frame-color); border-radius: 5px 5px 0 0;
  cursor: move; pointer-events: auto; user-select: none;
}
.node.node-frame .frame-body {
  position: absolute; left: 0; right: 0; top: 24px; bottom: 0;
  pointer-events: auto;
}

/* Frame resize handles: four corners + E/S edges. Visible enough to grab,
   subtle when not hovered. */
.node.node-frame .frame-resize {
  position: absolute; pointer-events: auto; background: var(--frame-color);
  opacity: 0.35; z-index: 2;
}
.node.node-frame .frame-resize:hover { opacity: 0.85; }
.node.node-frame .frame-resize-nw {
  left: -5px; top: -5px; width: 12px; height: 12px;
  cursor: nwse-resize; border-radius: 2px;
}
.node.node-frame .frame-resize-ne {
  right: -5px; top: -5px; width: 12px; height: 12px;
  cursor: nesw-resize; border-radius: 2px;
}
.node.node-frame .frame-resize-sw {
  left: -5px; bottom: -5px; width: 12px; height: 12px;
  cursor: nesw-resize; border-radius: 2px;
}
.node.node-frame .frame-resize-se {
  right: -5px; bottom: -5px; width: 12px; height: 12px;
  cursor: nwse-resize; border-radius: 2px;
}
.node.node-frame .frame-resize-e {
  right: -3px; top: 28px; bottom: 14px; width: 6px;
  cursor: ew-resize; border-radius: 2px;
}
.node.node-frame .frame-resize-s {
  bottom: -3px; left: 14px; right: 14px; height: 6px;
  cursor: ns-resize; border-radius: 2px;
}

/* Foldable nodes (W3): chevron in header, slim folded layout. */
.node .header { display: flex; align-items: center; gap: 6px; }
.node .header .header-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .header .fold-toggle {
  cursor: pointer; padding: 0 5px; user-select: none; color: var(--text-secondary); font-size: var(--fs-sm);
  line-height: 18px; border-radius: var(--radius);
}
.node .header .fold-toggle:hover { color: var(--accent); background: rgba(255, 255, 255, 0.6); }
/* Validator badge: red for errors, amber for warnings; the title lists them. */
.node .header .issue-badge {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%; background: var(--danger-strong); color: #fff;
  font-size: var(--fs-xs); font-weight: 700; cursor: help;
}
.node .header .issue-badge.warning { background: var(--warning-strong); }
.node.has-errors:not(.selected) { border-color: var(--danger-border-strong); }
.node.folded:not(.selected) { box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.node.folded .body, .node.folded .port-label { display: none; }
.node.folded .port, .node .port.folded-port {
  display: block; visibility: visible; pointer-events: auto;
  width: 12px; height: 12px;
}

/* Run-history view (W4). */
#run-history-view { padding: var(--sp-4); }
#run-history-view .run-history-table { width: 100%; border-collapse: collapse; background: var(--bg); font-size: var(--fs-base); }
#run-history-view .run-history-table th, #run-history-view .run-history-table td { padding: 6px 8px; border: 1px solid var(--border-subtle); text-align: left; vertical-align: top; }
#run-history-view .run-history-table th { background: var(--bg-muted); font-size: var(--fs-sm); text-transform: uppercase; color: var(--text-secondary); }
#run-history-view .run-history-table .row-actions button { margin-right: var(--sp-1); }
#run-history-view .run-row.run-status-failed td { background: var(--danger-soft); }
#run-history-view .run-row.run-status-cancelled td { background: var(--warning-soft); }
#run-history-view .run-row.run-status-done td { background: var(--success-soft); }
