/* MeshFlows studio layer.
   Calm cards, air, and a Logic Apps-like branch structure.
   Colors come from the existing theme tokens. */

:root {
  --mf-radius: 16px;
  --mf-radius-sm: 12px;
  --mf-line: color-mix(in srgb, var(--text-muted) 72%, var(--border));
  --mf-shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 18px 40px rgba(0, 0, 0, 0.28);
  --mf-shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.18);
  --mf-lane-gap: 22px;
}

[data-theme="light"] {
  --mf-line: color-mix(in srgb, var(--text-muted) 55%, var(--border));
  --mf-shadow: 0 1px 0 rgba(255, 255, 255, 0.8), 0 18px 40px rgba(21, 34, 56, 0.08);
  --mf-shadow-soft: 0 10px 28px rgba(21, 34, 56, 0.06);
}

/* ----- Chrome ----- */
body {
  letter-spacing: -0.011em;
}

.content {
  padding: 28px 36px 48px;
  background:
    radial-gradient(900px 420px at 0% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    radial-gradient(700px 380px at 100% 0%, color-mix(in srgb, var(--purple) 10%, transparent), transparent 55%),
    var(--bg);
}

.topbar {
  height: 56px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
}

.topbar-brand {
  border-radius: 12px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.topbar-status,
.topbar-status-probe,
#buildInfo {
  border-radius: 999px;
  padding: 3px 8px;
  background: color-mix(in srgb, var(--surface-raised) 80%, transparent);
  border: 1px solid var(--border);
}

.sidebar {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, var(--canvas)), var(--surface));
  border-right: 1px solid var(--border);
  padding: 16px 0 24px;
}

.sidebar-section-toggle,
.sidebar-section h3 {
  letter-spacing: 0.08em;
  font-size: 10px;
}

.sidebar-action-btn {
  width: 26px;
  height: 26px;
  border-radius: 8px;
}

.group-header,
.wf-item,
.ops-wf-item,
.nav-item {
  border-radius: 10px;
}

.wf-item,
.ops-wf-item,
.nav-item {
  padding: 7px 10px;
}

.wf-item.active,
.ops-wf-item.active,
.nav-item.active {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}

.workflow-search-row {
  border-radius: 12px;
  background: var(--bg);
  margin-bottom: 8px;
}

.group-count,
.badge {
  border-radius: 999px;
}

/* ----- Type, tabs, tables, forms ----- */
.wf-detail-info h2,
.runs-header h3,
.detail-header h3 {
  letter-spacing: -0.03em;
}

.stat-card,
.settings-tree-pane,
.settings-selected-row,
.rabbit-card,
.design-trigger,
.trace-layout-side {
  border-radius: var(--mf-radius);
  box-shadow: var(--mf-shadow-soft);
}

.stat-card .stat-value {
  letter-spacing: -0.04em;
}

.workflow-list-tabs,
.design-step-tabs,
.detail-tabs,
.span-tabs {
  gap: 6px;
}

.workflow-list-tab,
.design-step-tab,
.tab,
.span-tab {
  border-radius: 999px;
}

.workflow-list-tab.active,
.design-step-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.run-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--mf-radius);
  box-shadow: var(--mf-shadow-soft);
}

.run-table th {
  background: var(--surface);
  letter-spacing: 0.08em;
  font-size: 10px;
}

.run-table td {
  border-bottom-color: color-mix(in srgb, var(--border) 70%, transparent);
  padding: 12px 14px;
}

.run-table tr.active-row td {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.btn {
  border-radius: 999px;
  padding: 7px 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 18px color-mix(in srgb, var(--accent) 32%, transparent);
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 86%, #fff);
  color: #fff;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.45;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-sm,
.btn-small {
  border-radius: 999px;
}

.content input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.content textarea,
.content select,
.design-modal input:not([type="checkbox"]):not([type="radio"]),
.design-modal textarea,
.design-modal select,
.auth-card input,
.design-step-edit-json {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.workflow-search-row input,
.topbar-theme-select {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.code-block {
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg) 82%, var(--surface));
  border: 1px solid var(--border);
}

.placeholder,
.settings-empty-state,
.iam-empty-state {
  gap: 10px;
  color: var(--text-muted);
}

.placeholder::before {
  content: "";
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background:
    radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--mf-shadow-soft);
}

.design-overlay,
.rabbit-message-overlay,
.trigger-recent-detail-overlay {
  background: color-mix(in srgb, var(--bg) 42%, transparent);
  backdrop-filter: blur(8px);
}

.design-modal {
  border-radius: 22px;
  box-shadow: var(--mf-shadow);
  border: 1px solid var(--border);
  background: var(--surface);
}

.design-modal-header,
.detail-header {
  border-bottom-color: var(--border);
}

.design-step-detail,
.detail-panel {
  border-radius: var(--mf-radius);
  box-shadow: var(--mf-shadow-soft);
}

.auth-card {
  border-radius: 24px;
  box-shadow: var(--mf-shadow);
}

/* ----- Canvas ----- */
.design-flow,
.graph-container {
  border-radius: 20px;
  border: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
  background-color: var(--canvas);
  background-image:
    radial-gradient(circle, color-mix(in srgb, var(--text-muted) 35%, transparent) 1px, transparent 1px);
  background-size: 22px 22px;
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 6%, transparent);
}

.design-flow.design-tab-flow,
.graph-container {
  padding: 28px 24px 56px;
}

.design-flow::after {
  opacity: 0.55;
  letter-spacing: 0.04em;
}

.pipeline {
  align-items: center;
  width: max-content;
  min-width: 100%;
  padding: 8px 12px 18px;
  gap: 0;
}

.pipeline > .pipe-insert-zone,
.if-lane .pipe-insert-zone,
.pipe-scope .pipe-insert-zone,
.pipe-loop .pipe-insert-zone {
  margin-left: 0;
  align-self: center;
  justify-content: center;
  width: min(420px, 100%);
}

/* ----- Step cards ----- */
.pipe-node {
  margin-left: 0;
  width: 360px;
  max-width: 420px;
  min-width: 220px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--mf-shadow-soft);
}

.pipe-node:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: var(--mf-shadow);
  transform: translateY(-1px);
}

.pipe-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent), var(--mf-shadow-soft);
}

.pipe-node .node-header,
.if-split-header,
.loop-header {
  gap: 10px;
}

.pipe-node .node-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.pipe-node .node-main .node-id {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipe-node .node-main .node-type {
  display: inline-block;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
}

.has-run-after {
  position: relative;
  overflow: visible;
}

.node-run-after {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 3;
  display: flex;
  gap: 5px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.node-run-after-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--canvas);
}

.node-run-after-dot.succeeded { border-color: var(--green); }
.node-run-after-dot.failed { border-color: var(--red); }
.node-run-after-dot.skipped { border-color: var(--text-muted); }
.node-run-after-dot.timedout { border-color: var(--orange); }

.node-run-after-dot.succeeded.active { background: var(--green); }
.node-run-after-dot.failed.active { background: var(--red); }
.node-run-after-dot.skipped.active { background: var(--text-muted); }
.node-run-after-dot.timedout.active { background: var(--orange); }

.node-run-after-exit {
  top: auto;
  bottom: 0;
  transform: translate(-50%, 50%);
}

.pipe-run-after-graph {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  align-self: center;
  width: max-content;
  max-width: 100%;
}

.pipe-run-after-graph > .has-run-after-exit {
  position: relative;
  z-index: 3;
}

.pipe-run-after-wires {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.pipe-run-after-wire,
.pipe-run-after-wire-hit {
  pointer-events: stroke;
  cursor: pointer;
}

.pipe-run-after-wire.is-selected {
  stroke: var(--accent);
  stroke-width: 3px;
}

.pipe-wire-delete {
  position: absolute;
  z-index: 6;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--red);
  background: var(--surface);
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px var(--canvas);
}

.pipe-run-after-joins {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 40px;
  position: relative;
  z-index: 3;
  width: 100%;
}

.design-flow.edit-mode .node-run-after-exit .node-run-after-dot {
  pointer-events: auto;
  cursor: crosshair;
}

.pipe-run-after-drop {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pipe-run-after-draft {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 80;
  overflow: visible;
}

.pipe-run-after-draft-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 5 4;
}

.pipe-run-after-graph > .pipe-run-after-split {
  margin: 52px 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  width: max-content;
  min-width: 0;
}

.pipe-run-after-graph .pipe-run-after-split-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.pipe-run-after-graph .pipe-run-after-lanes {
  gap: 28px;
  justify-content: center;
}

.pipe-run-after-graph .if-lane,
.pipe-run-after-graph .if-lane-title {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.pipe-run-after-graph .if-lane-title {
  display: none;
}

.pipe-run-after-graph .pipe-node {
  position: relative;
  z-index: 3;
}

.pipe-run-after-graph .pipe-connector,
.pipe-run-after-graph .pipe-insert-zone {
  margin-left: 0;
  align-self: center;
}

.pipe-node .node-icon,
.mf-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-raised));
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  font-size: 15px;
}

.pipe-node .node-id,
.mf-title {
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 13px;
}

.pipe-node .node-type,
.if-split-header .node-type,
.loop-header .node-type {
  border-radius: 999px;
  padding: 2px 8px;
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.node-status,
.mf-status {
  border-radius: 999px;
  padding: 2px 8px;
  background: color-mix(in srgb, currentColor 14%, transparent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pipe-connector:not(.pipe-connector-run-after):not(.pipe-connector-join) {
  margin-left: 0;
  align-self: center;
  width: 2px;
  height: 22px;
  border-radius: 2px;
  background: var(--mf-line);
  position: relative;
}

.pipe-connector:not(.pipe-connector-run-after):not(.pipe-connector-join)::after {
  content: none;
}

/* ----- Conditions: true | false, including nested and sequential ----- */
.mf-branch {
  margin: 4px 0;
  padding: 0;
  border: 0;
  background: none;
  width: max-content;
  min-width: min(100%, 560px);
  max-width: none;
  align-self: center;
  overflow: visible;
}

.mf-branch > .if-split-header,
.mf-try > .if-split-header,
.mf-parallel > .if-split-header,
.mf-scope > .loop-header,
.mf-loop > .loop-header {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--mf-shadow-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.mf-branch > .if-split-header {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.mf-branch.selected > .if-split-header,
.mf-try.selected > .if-split-header,
.mf-parallel.selected > .if-split-header,
.if-split-header.selected,
.pipe-loop.selected > .loop-header,
.loop-header.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent), var(--mf-shadow-soft);
  background: var(--surface);
}

.mf-card-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.mf-kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.mf-condition {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.mf-branch-note {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
}

.mf-branch > .mf-fork,
.mf-branch > .mf-join {
  width: 2px;
  height: 16px;
  margin: 0 auto;
  background: var(--mf-line);
  position: relative;
}

.mf-branch > .if-split-lanes,
.if-lane > .mf-branch > .if-split-lanes,
.if-split-nested.mf-branch > .if-split-lanes {
  display: grid;
  grid-template-columns: max-content max-content;
  grid-auto-flow: column;
  gap: var(--mf-lane-gap);
  width: max-content;
  min-width: 100%;
  align-items: stretch;
  position: relative;
  padding: 14px 0 16px;
  margin: 0;
}

.mf-branch > .if-split-lanes > .if-lane {
  position: relative;
  min-width: 250px;
  min-height: 112px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, var(--canvas));
  box-shadow: var(--mf-shadow-soft);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.mf-branch > .if-split-lanes > .if-lane-true {
  border-color: color-mix(in srgb, var(--green) 42%, var(--border));
  background: color-mix(in srgb, var(--green) 8%, var(--surface));
}

.mf-branch > .if-split-lanes > .if-lane-false {
  border-color: color-mix(in srgb, var(--orange) 42%, var(--border));
  background: color-mix(in srgb, var(--orange) 8%, var(--surface));
}

.mf-lane-rails {
  position: absolute;
  left: 0;
  right: 0;
  top: -14px;
  height: 14px;
  pointer-events: none;
}

.mf-branch > .if-split-lanes > .if-lane-true .mf-lane-rails::before,
.mf-branch > .if-split-lanes > .if-lane-false .mf-lane-rails::before,
.mf-branch > .if-split-lanes > .if-lane::after {
  content: "";
  position: absolute;
  width: 2px;
  background: var(--mf-line);
  left: 50%;
  transform: translateX(-50%);
}

.mf-branch > .if-split-lanes > .if-lane .mf-lane-rails::before {
  top: 0;
  height: 14px;
}

.mf-branch > .if-split-lanes > .if-lane-true .mf-lane-rails::after,
.mf-branch > .if-split-lanes > .if-lane-false .mf-lane-rails::after {
  content: "";
  position: absolute;
  top: 0;
  height: 2px;
  width: calc(50% + (var(--mf-lane-gap) / 2));
  background: var(--mf-line);
}

.mf-branch > .if-split-lanes > .if-lane-true .mf-lane-rails::after {
  left: 50%;
}

.mf-branch > .if-split-lanes > .if-lane-false .mf-lane-rails::after {
  right: 50%;
}

.mf-branch > .if-split-lanes > .if-lane::after {
  bottom: -16px;
  height: 16px;
}

.mf-branch > .if-split-lanes > .if-lane-true::before,
.mf-branch > .if-split-lanes > .if-lane-false::before {
  content: "";
  position: absolute;
  bottom: -16px;
  height: 2px;
  width: calc(50% + (var(--mf-lane-gap) / 2));
  background: var(--mf-line);
}

.mf-branch > .if-split-lanes > .if-lane-true::before {
  left: 50%;
}

.mf-branch > .if-split-lanes > .if-lane-false::before {
  right: 50%;
}

.mf-branch .if-lane-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
}

.mf-lane-name {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.if-lane-true > .if-lane-title .mf-lane-name { color: var(--green); }
.if-lane-false > .if-lane-title .mf-lane-name { color: var(--orange); }
.if-lane-true > .if-lane-title .mf-lane-sub,
.if-lane-false > .if-lane-title .mf-lane-sub { color: var(--text-muted); }

.mf-lane-sub {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.mf-branch .if-lane .pipe-node,
.mf-branch .if-lane .pipe-scope,
.mf-branch .if-lane .pipe-loop,
.mf-branch .if-lane .mf-branch,
.mf-scope .pipe-node,
.mf-scope .mf-branch,
.mf-loop .pipe-node {
  margin-left: 0;
  max-width: none;
}

.mf-branch .if-lane .pipe-node {
  width: auto;
  align-self: stretch;
  min-width: 0;
  max-width: none;
}

.mf-branch .if-lane .pipe-connector,
.mf-scope .pipe-connector,
.mf-loop .pipe-connector {
  margin-left: 0;
  align-self: center;
}

.mf-branch > .if-split-lanes > .if-lane > .if-lane-empty {
  flex: 1;
  border: none;
  background: transparent;
  min-height: 88px;
}

.mf-branch .if-lane-empty,
.mf-empty,
.loop-body-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed color-mix(in srgb, var(--text-muted) 45%, var(--border));
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  color: var(--text-muted);
  font-size: 12px;
  font-style: normal;
  letter-spacing: 0;
  text-align: center;
}

.if-lane-add-btn,
.pipe-add-on-connector {
  justify-content: center;
  align-self: center;
  width: 22px;
  min-width: 0;
  min-height: 0;
  height: 28px;
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  opacity: 1;
  position: relative;
}

.pipe-add-on-connector::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--mf-line);
  transform: translateX(-50%);
  pointer-events: none;
}

.pipe-add-on-connector .pipe-insert-btn {
  position: relative;
  z-index: 1;
  width: 22px;
  height: 22px;
  border: 2px solid var(--accent);
  color: var(--accent);
  background: var(--surface);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 0 0 3px var(--canvas);
}

.pipe-add-on-connector:hover .pipe-insert-btn {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  transform: scale(1.08);
}

.pipeline > .pipe-insert-zone.pipe-add-on-connector,
.if-lane .pipe-insert-zone.pipe-add-on-connector,
.pipe-scope .pipe-insert-zone.pipe-add-on-connector,
.pipe-loop .pipe-insert-zone.pipe-add-on-connector,
.design-flow > .pipe-insert-zone.pipe-add-on-connector {
  width: 22px;
  max-width: 22px;
  height: 28px;
  min-height: 0;
  margin: 0;
  opacity: 1;
  align-self: center;
}

.pipe-add-on-connector:has(+ .pipe-connector) {
  height: 0;
  margin: 0;
  overflow: visible;
  z-index: 2;
}

.pipe-add-on-connector:has(+ .pipe-connector)::before {
  display: none;
}

.pipe-add-on-connector:has(+ .pipe-connector) .pipe-insert-btn {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, 0);
}

.pipe-add-on-connector:has(+ .pipe-connector):hover .pipe-insert-btn {
  transform: translate(-50%, 0) scale(1.08);
}

.mf-branch > .if-split-lanes > .if-lane:has(> .pipe-add-on-connector:only-child),
.mf-try .if-lane:has(> .pipe-add-on-connector:only-child) {
  min-height: 0;
  padding-top: 6px;
  padding-bottom: 6px;
}

/* ----- Scopes stay distinct containers ----- */
.mf-scope,
.mf-loop {
  margin: 6px 0;
  padding: 0;
  width: max-content;
  min-width: min(100%, 320px);
  border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  background: var(--surface);
  box-shadow: var(--mf-shadow-soft);
  overflow: visible;
}

.mf-scope[data-depth="1"] {
  border-color: color-mix(in srgb, var(--purple) 50%, var(--border));
  background: color-mix(in srgb, var(--purple) 5%, var(--surface));
}

.mf-scope[data-depth="2"] {
  border-color: color-mix(in srgb, var(--orange) 48%, var(--border));
  background: color-mix(in srgb, var(--orange) 6%, var(--surface));
}

.mf-scope[data-depth="3"],
.mf-scope[data-depth="4"],
.mf-scope[data-depth="5"] {
  border-color: color-mix(in srgb, var(--green) 42%, var(--border));
  background: color-mix(in srgb, var(--green) 5%, var(--surface));
}

.mf-scope > .loop-header,
.mf-loop > .loop-header {
  width: 100%;
  margin: 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  box-shadow: none;
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

.mf-scope[data-depth="1"] > .loop-header {
  background: color-mix(in srgb, var(--purple) 10%, var(--surface));
}

.mf-scope[data-depth="1"] .mf-kicker { color: var(--purple); }

.mf-scope[data-depth="2"] > .loop-header {
  background: color-mix(in srgb, var(--orange) 10%, var(--surface));
}

.mf-scope[data-depth="2"] .mf-kicker { color: var(--orange); }

.mf-scope > .loop-body,
.mf-loop > .loop-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 16px 16px 18px;
}

.mf-scope-count {
  font-size: 11px;
  font-weight: 650;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 2px 8px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
}

.mf-loop {
  border-color: color-mix(in srgb, var(--purple) 45%, var(--border));
}

.mf-loop > .loop-header {
  background: color-mix(in srgb, var(--purple) 8%, var(--surface));
}

.mf-loop .mf-kicker { color: var(--purple); }

.mf-scope .mf-scope,
.mf-scope .mf-loop,
.mf-loop .mf-scope,
.if-lane .mf-scope,
.if-lane .mf-loop,
.if-lane .pipe-loop {
  margin-left: 0;
  width: max-content;
  min-width: 100%;
}

/* Parallel scopes are columns, not a collapsed stack. */
.mf-parallel {
  margin-left: 0;
  padding: 0;
  border: 0;
  background: none;
  width: max-content;
  min-width: min(100%, 520px);
  overflow: visible;
}

.mf-parallel > .if-split-header {
  width: min(440px, 100%);
}

.mf-parallel > .if-split-lanes {
  display: grid;
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: minmax(250px, max-content);
  gap: 16px;
  width: max-content;
  align-items: stretch;
  padding-top: 14px;
}

.mf-parallel > .if-split-lanes > .if-lane {
  min-width: 250px;
  min-height: 120px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--purple) 35%, var(--border));
  background: color-mix(in srgb, var(--purple) 6%, var(--surface));
  box-shadow: var(--mf-shadow-soft);
}

/* One try/catch box: header says TRY once, try steps sit in the body, catch is the second lane. */
.mf-try {
  margin: 6px 0;
  padding: 0;
  width: max-content;
  min-width: min(100%, 420px);
  border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--green) 42%, var(--border));
  background: var(--surface);
  box-shadow: var(--mf-shadow-soft);
  overflow: visible;
}

.if-lane > .mf-try,
.mf-scope .mf-try,
.mf-loop .mf-try {
  margin-left: 0;
  padding: 0;
  width: max-content;
  min-width: 100%;
}

.mf-try > .if-split-header {
  width: auto;
  max-width: none;
  margin: 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  box-shadow: none;
  background: color-mix(in srgb, var(--green) 8%, var(--surface));
}

.mf-try .mf-kicker { color: var(--green); }

.mf-try.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent), var(--mf-shadow-soft);
}

.mf-try.selected > .if-split-header,
.mf-try > .if-split-header.selected {
  border-color: transparent;
  box-shadow: none;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.mf-try > .if-split-lanes {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 440px;
  max-width: 100%;
  margin: 0;
  padding: 14px 14px 16px;
  box-sizing: border-box;
}

.mf-try > .if-split-lanes > .if-lane-true {
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.mf-try > .if-split-lanes > .if-lane-false {
  min-width: 0;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--orange) 42%, var(--border));
  padding: 12px;
  background: color-mix(in srgb, var(--orange) 8%, var(--surface));
  box-shadow: none;
}

.mf-try .if-lane .pipe-node {
  width: auto;
  max-width: none;
  align-self: stretch;
}

.design-flow > .scoped-context-header {
  width: 100%;
  max-width: none;
  min-width: 0;
  margin: 0 0 12px;
  padding: 8px 14px;
  box-sizing: border-box;
  position: sticky;
  left: 0;
  z-index: 2;
  border-radius: 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
  box-shadow: none;
}

.design-flow > .scoped-context-header:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--border);
}

.design-flow > .scoped-context-header .node-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 12px;
}

.design-flow > .scoped-context-header.scoped-context-empty {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.design-flow > .scoped-context-header.scoped-context-empty .scoped-context-provider {
  margin: 0;
}

.design-flow > .pipe-workflow-handlers {
  width: 100%;
  max-width: none;
  min-width: 0;
  margin: 22px 0 8px;
  padding: 8px 12px 12px;
  box-sizing: border-box;
  position: sticky;
  left: 0;
  z-index: 2;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--orange) 42%, var(--border));
  background: color-mix(in srgb, var(--orange) 10%, var(--canvas));
  box-shadow: none;
}

.pipe-workflow-handlers > .if-split-header {
  width: 100%;
  max-width: none;
  margin: 0 0 10px;
  padding: 4px 2px 8px;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--orange) 35%, var(--border));
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 11px;
}

.pipe-workflow-handlers > .if-split-lanes {
  width: 100%;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.pipe-workflow-handlers .if-lane {
  min-width: 0;
  border-radius: 12px;
  padding: 10px;
  background: color-mix(in srgb, var(--orange) 8%, var(--bg));
  border-color: color-mix(in srgb, var(--orange) 30%, var(--border));
  box-shadow: none;
}

.pipe-workflow-handlers .if-lane .pipe-node {
  width: 100%;
  max-width: none;
  background: color-mix(in srgb, var(--orange) 14%, var(--surface));
  box-shadow: none;
}

/* Run status stays readable on cards and containers. */
.run-step-view .pipe-node.status-ok,
.run-step-view .pipe-node.status-success,
.run-step-view .pipe-node.status-succeeded,
.run-step-view .mf-branch.status-ok > .if-split-header,
.run-step-view .mf-branch.status-succeeded > .if-split-header,
.run-step-view .mf-branch.status-success > .if-split-header,
.run-step-view .mf-scope.status-succeeded > .loop-header,
.run-step-view .mf-scope.status-ok > .loop-header,
.run-step-view .mf-loop.status-succeeded > .loop-header,
.run-step-view .mf-try.status-succeeded,
.run-step-view .mf-try.status-ok,
.run-step-view .mf-try.status-success,
.run-step-view .mf-parallel.status-succeeded > .if-split-header {
  border-color: var(--green);
}

.run-step-view .pipe-node.status-failed,
.run-step-view .pipe-node.status-error,
.run-step-view .mf-branch.status-failed > .if-split-header,
.run-step-view .mf-branch.status-error > .if-split-header,
.run-step-view .mf-scope.status-failed > .loop-header,
.run-step-view .mf-try.status-failed,
.run-step-view .mf-try.status-error {
  border-color: var(--red);
}

.run-step-view .pipe-node.status-skipped,
.run-step-view .pipe-node.status-not-reached,
.run-step-view .status-skipped > .if-split-header,
.run-step-view .status-not-reached > .if-split-header,
.run-step-view .status-skipped > .loop-header,
.run-step-view .status-not-reached > .loop-header,
.run-step-view .pipe-node.status-skipped,
.run-step-view .mf-branch.status-not-reached,
.run-step-view .mf-scope.status-not-reached,
.run-step-view .mf-loop.status-not-reached,
.run-step-view .mf-try.status-not-reached,
.run-step-view .mf-try.status-skipped {
  opacity: 0.72;
}

.pipe-rename-btn,
.pipe-delete-btn {
  border-radius: 999px;
  padding: 2px 8px;
  line-height: 1.4;
}

.pipe-run-after-split {
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  padding: 10px;
}

.pipe-insert-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--mf-shadow-soft);
}

.design-workflow-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 8px;
}

.design-workflow-form.hidden {
  display: none;
}

.dwf-root,
.dwf-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.dwf-group {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--canvas) 55%, var(--surface));
}

.dwf-group > legend {
  padding: 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  color: var(--text-muted);
}

.dwf-field {
  display: grid;
  grid-template-columns: minmax(88px, 34%) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.dwf-label {
  font-size: 12px;
  font-weight: 650;
  color: var(--text);
  text-transform: lowercase;
}

.dwf-field input[type="text"],
.dwf-field input[type="number"],
.dwf-field select,
.dwf-json,
.dwf-row > input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: 12px/1.4 var(--mono, ui-monospace, monospace);
}

.dwf-field input:disabled,
.dwf-field select:disabled,
.dwf-json:disabled,
.dwf-row > input:disabled {
  opacity: 0.72;
}

.dwf-check {
  justify-self: start;
  width: 16px;
  height: 16px;
}

.dwf-json {
  min-height: 88px;
  resize: vertical;
}

.dwf-json.dwf-invalid {
  border-color: var(--red);
}

.dwf-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.dwf-row > .dwf-group {
  flex: 1;
}

.dwf-empty {
  font-size: 12px;
  color: var(--text-muted);
}

.dwf-add,
.dwf-remove {
  align-self: center;
}

@media (max-width: 900px) {
  .content { padding: 16px; }
  .topbar { height: auto; min-height: 56px; }
  .mf-condition { max-width: 160px; }
  .dwf-field { grid-template-columns: 1fr; }
}

/* Freeform designer: one entrance, status dots as exits, groups keep their children. */
.design-flow.pipe-freeform {
  overflow: auto;
}

.pipe-freeform-root {
  position: relative;
  min-height: 160px;
  overflow: visible;
}

.pipe-freeform .pipe-freeform-root > .pipe-node,
.pipe-freeform .pipe-freeform-root > .if-split,
.pipe-freeform .pipe-freeform-root > .pipe-loop,
.pipe-freeform .pipe-freeform-root > .pipe-scope,
.pipe-freeform .pipe-freeform-root > .mf-parallel {
  position: absolute;
  margin: 0;
  z-index: 2;
}

.pipe-freeform .pipe-freeform-root > .pipe-node {
  width: 240px;
  min-width: 220px;
  max-width: 240px;
}

.pipe-freeform .pipe-node:hover {
  transform: none;
}

.pipe-freeform .pipe-connector,
.pipe-freeform .pipe-insert-zone,
.pipe-freeform .mf-fork,
.pipe-freeform .mf-join,
.pipe-freeform .if-split-lanes > .if-lane {
  display: none;
}

.pipe-freeform .if-split,
.pipe-freeform .pipe-loop,
.pipe-freeform .pipe-scope {
  display: flex;
  flex-direction: column;
}

.pipe-freeform .loop-body,
.pipe-freeform .if-split-lanes {
  position: relative;
  flex: 1 1 auto;
  min-height: 80px;
}

.pipe-freeform-wires {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.pipe-freeform-wires .pipe-run-after-wire,
.pipe-freeform-wires .pipe-run-after-wire-hit {
  pointer-events: stroke;
}

.node-run-after-entry {
  position: absolute;
  z-index: 4;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--canvas);
  pointer-events: none;
}

.pipe-freeform.dir-td .node-run-after-entry,
.design-flow.dir-td .node-run-after-entry {
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
}

.pipe-freeform.dir-lr .node-run-after-exit,
.design-flow.dir-lr .node-run-after-exit {
  top: 50%;
  right: 0;
  bottom: auto;
  left: auto;
  flex-direction: column;
  transform: translate(50%, -50%);
}

.pipe-freeform.dir-lr .node-run-after-entry,
.design-flow.dir-lr .node-run-after-entry {
  left: 0;
  top: 50%;
  transform: translate(-50%, -50%);
}

#designTidyTdBtn.is-active,
#designTidyLrBtn.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
}
