/* Workflows: sidebar list, template gallery, builder (canvas + config panel), preview dialog.
   Shared tones/icons (--auto-*, .auto-well) live in ui-automation.css. */

/* ---------- Sidebar ---------- */
.workflow-sidebar nav { display: grid; gap: 1px; }
.workflow-row { position: relative; display: flex; align-items: center; min-width: 0; }
.workflow-option {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  text-align: start;
  font-size: 14px;
}
.workflow-option strong { min-width: 0; overflow: hidden; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.workflow-option:hover { background: var(--hover); }
.workflow-option[aria-pressed="true"] { background: var(--selected); }
.workflow-option[aria-pressed="true"] strong { font-weight: 500; }
.workflow-dot { flex: none; width: 8px; height: 8px; margin-inline: 4px 1px; border-radius: 50%; background: var(--control-line); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--quiet) 40%, transparent); }
.workflow-dot[data-state="live"] { background: var(--success-ink); box-shadow: 0 0 0 3px var(--success-soft); }
.workflow-dot[data-state="paused"] { background: var(--warning-ink); box-shadow: none; }
/* Priority arrows appear on hover/focus, over the end of the row. */
.workflow-priority { position: absolute; inset-inline-end: 4px; display: inline-flex; gap: 2px; opacity: 0; pointer-events: none; transition: opacity 120ms ease; }
.workflow-row:is(:hover, :focus-within) .workflow-priority { opacity: 1; pointer-events: auto; }
.workflow-row:is(:hover, :focus-within) .workflow-option { padding-inline-end: 60px; }
#workflows-view .workflow-priority .button { width: 24px; min-height: 24px; padding: 0; border-color: transparent; background: var(--surface); color: var(--muted); font-size: 12px; box-shadow: var(--shadow-sm); }
#workflows-view .workflow-priority .button:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
#workflows-view .workflow-priority .button:disabled { opacity: .4; box-shadow: none; }
.workflow-list-empty { display: grid; gap: 10px; justify-items: start; padding: 4px 8px; }
.workflow-list-empty p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.workflow-list-new { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 500; }
.workflow-list-new .icon { width: 16px; height: 16px; }
.workflow-list-new:hover { color: var(--accent-hover, var(--accent)); text-decoration: underline; }

/* ---------- Template gallery ---------- */
.workflow-start { width: min(100%, 1040px); margin: 0 auto; padding-top: 4px; }
.workflow-start-header.desk-page-header { margin-bottom: 24px; }
.workflow-start .desk-page-description { max-width: 620px; }
.workflow-gallery-heading { margin: 28px 0 12px; color: var(--ink); font-size: 15px; font-weight: 600; }
.workflow-start-header + .workflow-gallery-heading { margin-top: 0; }
.workflow-templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.workflow-template {
  display: grid;
  grid-template-rows: auto auto 1fr;
  align-content: start;
  gap: 4px;
  padding: 8px 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  text-align: start;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}
.workflow-template:hover { border-color: var(--control-line-hover, var(--control-line)); box-shadow: var(--shadow-pop); transform: translateY(-1px); }
.workflow-template:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.workflow-template > strong { margin-top: 10px; padding-inline: 8px; font-size: 14px; font-weight: 600; }
.workflow-template > span:last-child { padding-inline: 8px; color: var(--muted); font-size: 13px; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) { .workflow-template { transition: none; } .workflow-template:hover { transform: none; } }
.workflow-template-illustration {
  position: relative;
  display: block;
  height: 132px;
  border-radius: var(--radius-md);
  background: radial-gradient(circle, var(--auto-grid-dot) 1px, transparent 1.2px) center / 14px 14px, var(--inset);
  overflow: hidden;
}
.workflow-template-illustration i { position: absolute; z-index: 1; display: block; width: 44px; height: 22px; border: 1px solid var(--control-line); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow-sm); }
.workflow-template-illustration i:first-child { left: calc(50% - 22px); top: 26px; border-color: color-mix(in srgb, var(--auto-entry-ink) 45%, transparent); background: var(--auto-entry-fill); }
.workflow-template-illustration i:first-child::before { content: ''; position: absolute; left: 6px; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--auto-entry-ink); }
.workflow-template-illustration i:not(:first-child)::before { content: ''; position: absolute; left: 7px; right: 12px; top: 9px; height: 3px; border-radius: 2px; background: var(--line); }
.workflow-template-illustration::after { content: ''; position: absolute; left: calc(50% - .75px); top: 48px; width: 1.5px; height: 30px; background: var(--auto-edge); }
.workflow-template-illustration :is(i:nth-child(2), i:nth-child(3)) { top: 78px; }
.workflow-template-illustration.is-blank i:nth-child(2) { left: calc(50% - 22px); border-style: dashed; box-shadow: none; }
.workflow-template-illustration.is-triage i:nth-child(2) { left: calc(50% - 64px); }
.workflow-template-illustration.is-triage i:nth-child(3) { left: calc(50% + 20px); }
.workflow-template-illustration.is-triage::after { height: 14px; }
.workflow-template-illustration.is-triage::before { content: ''; position: absolute; left: calc(50% - 42px); top: 62px; width: 84px; height: 16px; border: 1.5px solid var(--auto-edge); border-bottom: 0; border-radius: 6px 6px 0 0; }
.workflow-template-illustration.is-chain i:first-child { top: 14px; }
.workflow-template-illustration.is-chain i:nth-child(2) { left: calc(50% - 22px); top: 54px; }
.workflow-template-illustration.is-chain i:nth-child(3) { left: calc(50% - 22px); top: 94px; }
.workflow-template-illustration.is-chain::after { top: 36px; height: 58px; }
.workflow-template-illustration.is-choice::after { display: none; }
.workflow-template-illustration.is-choice i:first-child { left: calc(50% - 56px); top: 22px; width: 112px; height: 40px; border-color: var(--line); border-radius: 12px 12px 12px 4px; background: var(--surface); }
.workflow-template-illustration.is-choice i:first-child::before { left: 10px; right: 26px; top: 11px; height: 4px; border-radius: 2px; background: var(--control-line); box-shadow: 0 9px 0 -0.5px var(--line); }
.workflow-template-illustration.is-choice :is(i:nth-child(2), i:nth-child(3)) { top: 74px; width: 52px; height: 22px; border-color: color-mix(in srgb, var(--auto-message-ink) 45%, transparent); border-radius: 999px; background: var(--auto-message-fill); box-shadow: none; }
.workflow-template-illustration.is-choice :is(i:nth-child(2), i:nth-child(3))::before { left: 12px; right: 12px; background: color-mix(in srgb, var(--auto-message-ink) 55%, transparent); }
.workflow-template-illustration.is-choice i:nth-child(2) { left: calc(50% - 56px); }
.workflow-template-illustration.is-choice i:nth-child(3) { left: calc(50% + 4px); }
.workflow-template-illustration.is-choice.is-input i:nth-child(2) { width: 112px; border-color: var(--control-line); border-radius: 8px; background: var(--surface); }
.workflow-template-illustration.is-choice.is-input i:nth-child(2)::before { right: 52px; background: var(--line); }
.workflow-template-illustration.is-choice.is-input i:nth-child(3) { display: none; }
.workflow-viewer-empty { margin-top: 48px; }

/* ---------- Builder ---------- */
.workflow-header { flex: none; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; min-height: 56px; padding: 8px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.workflow-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 260px; }
.workflow-title-field { display: flex; min-width: 0; flex: 0 1 420px; }
#workflows-view #workflow-title {
  width: 100%;
  min-width: 120px;
  min-height: 32px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.01em;
  text-overflow: ellipsis;
}
#workflows-view #workflow-title:not(:disabled):hover { border-color: var(--control-line); background: var(--surface); }
#workflows-view #workflow-title:focus-visible { border-color: var(--focus); box-shadow: 0 0 0 3px var(--auto-ring); }
#workflows-view #workflow-title:disabled { background: transparent; color: var(--ink); }
@supports (field-sizing: content) {
  #workflows-view #workflow-title { field-sizing: content; width: auto; max-width: 100%; }
  .workflow-title-field { flex: 0 1 auto; }
}
.workflow-status.badge { flex: none; }
.workflow-status[data-state="live"] { background: var(--success-soft); color: var(--success-ink); }
.workflow-status[data-state="paused"] { background: var(--warning-soft); color: var(--warning-ink); }
#workflow-dirty { flex: none; color: var(--quiet); font-size: 12px; white-space: nowrap; }
#workflow-dirty:not(:empty)::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-inline-end: 6px; border-radius: 50%; background: var(--warning-ink); vertical-align: 1px; }
.workflow-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.workflow-board {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 28vw, 380px);
  grid-template-rows: auto minmax(420px, 1fr);
  min-height: max(520px, calc(100dvh - 48px - 57px));
  overflow: hidden;
}
.workflow-board-menu { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; padding: 8px 12px 8px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.workflow-board-menu h3 { margin: 0; color: var(--ink); font-size: 14px; font-weight: 600; }
.workflow-board-menu h3 span { margin-inline-start: 8px; color: var(--quiet); font-size: 13px; font-weight: 400; font-variant-numeric: tabular-nums; }
.workflow-board-menu label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.workflow-board-menu select { width: auto; min-width: 180px; }
.workflow-map {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
  overflow: auto;
  background: radial-gradient(circle, var(--auto-grid-dot) 1px, transparent 1.2px) 0 0 / 20px 20px, var(--auto-canvas);
}
.workflow-map-body { position: relative; min-height: 100%; width: max-content; min-width: 100%; padding: 40px 32px 64px; }
.workflow-layer { display: flex; gap: 24px; justify-content: center; width: 100%; }
.workflow-layer + .workflow-layer { margin-top: 48px; }
.workflow-card {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
  row-gap: 8px;
  width: 248px;
  min-height: 64px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  text-align: start;
  box-shadow: var(--auto-node-shadow);
  overflow-wrap: anywhere;
  cursor: pointer;
}
.workflow-card:hover { border-color: var(--control-line-hover, var(--control-line)); }
.workflow-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--auto-ring), var(--auto-node-shadow); }
.workflow-card[data-type="trigger"] { border-top: 3px solid var(--auto-entry-ink); padding-top: 10px; }
.workflow-card[data-type="trigger"][aria-pressed="true"] { border-top-color: var(--auto-entry-ink); }
.workflow-card .workflow-well { width: 32px; height: 32px; }
.workflow-card-copy { display: grid; gap: 2px; min-width: 0; }
.workflow-card-copy small { color: var(--muted); font-size: 12px; font-weight: 500; }
.workflow-card-copy strong { font-size: 14px; font-weight: 600; line-height: 1.35; }
.workflow-card-meta { grid-column: 2; justify-self: start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.workflow-wires { position: absolute; inset: 0; pointer-events: none; }
.workflow-wires svg { position: absolute; inset: 0; overflow: visible; }
.workflow-wires path { fill: none; stroke: var(--auto-edge); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.workflow-disconnected { margin-top: 40px; padding-top: 16px; border-top: 1px dashed var(--control-line); }
.workflow-disconnected p { margin: 0 0 12px; color: var(--muted); font-size: 12px; font-weight: 500; text-align: center; }

/* Config panel */
.workflow-inspector { grid-column: 2; grid-row: 2; display: grid; align-content: start; gap: 16px; min-width: 0; padding: 0 20px 24px; overflow: auto; border-left: 1px solid var(--line); background: var(--surface); }
.workflow-board .workflow-board-menu { grid-column: 1 / -1; }
.workflow-inspector-title { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; margin: 0 -20px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 15px; font-weight: 600; }
.workflow-inspector-title .workflow-well { width: 32px; height: 32px; }
.workflow-inspector label, .workflow-preview-form label { display: grid; gap: 6px; color: var(--ink); font-size: 13px; font-weight: 500; }
.workflow-inspector :is(select, textarea, input:not([type="checkbox"], [type="radio"])),
.workflow-preview-form :is(select, textarea, input:not([type="checkbox"], [type="radio"])) { width: 100%; }
.workflow-channels, .workflow-experiment { min-width: 0; display: grid; gap: 10px; margin: 0; padding: 10px 12px 12px; border: 1px solid var(--line); border-radius: var(--radius-md); }
.workflow-channels { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.workflow-channels legend, .workflow-experiment legend { padding-inline: 4px; color: var(--ink); font-size: 13px; font-weight: 500; }
.workflow-inspector .workflow-channels label { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
.workflow-inspector .workflow-toggle { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; line-height: 1.45; }
.workflow-field-help { margin: -8px 0 0; color: var(--quiet); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.workflow-rule-list, .workflow-effects, .workflow-effect { display: grid; gap: 10px; }
.workflow-rule { position: relative; display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--inset); }
.workflow-rule-buttons { position: absolute; top: 6px; inset-inline-end: 6px; z-index: 1; display: flex; gap: 2px; }
.workflow-rule > .workflow-rule-buttons + label { margin-top: 2px; }
.workflow-inline { display: flex; align-items: center; gap: 6px; }
.workflow-inline select { flex: 1; }
.workflow-inline button { flex: none; }
#workflows-view :is(.workflow-rule-buttons, .workflow-inline) .button { width: 28px; min-height: 28px; padding: 0; border-color: transparent; background: transparent; color: var(--muted); font-size: 14px; }
#workflows-view :is(.workflow-rule-buttons, .workflow-inline) .button:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
#workflows-view .workflow-inspector :is(.workflow-effects, .workflow-rule-list) > .button { justify-self: start; min-height: 28px; padding-inline: 10px; font-size: 12px; }
#workflows-view .workflow-inspector > .button[data-workflow="remove-step"] { justify-self: start; margin-top: 4px; color: var(--danger-ink); }
#workflows-view .workflow-inspector > .button[data-workflow="remove-step"]:hover { background: var(--danger-soft); }

/* Path analysis */
.workflow-analysis { margin: 20px 20px 32px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); font-size: 13px; overflow: hidden; }
.workflow-analysis summary { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 20px; color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer; }
.workflow-analysis[open] summary { border-bottom: 1px solid var(--line); }
.workflow-analysis > :not(summary) { margin-inline: 20px; }
.workflow-analysis > .button { margin-top: 16px; }
.workflow-analysis h3 { margin: 20px 20px 8px; font-size: 14px; font-weight: 600; }
.workflow-analysis dl { margin-top: 12px; }
.workflow-analysis dl > div { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--soft-line); }
.workflow-analysis dt { color: var(--ink); font-weight: 500; }
.workflow-analysis dd { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.workflow-analysis meter { width: 120px; height: 8px; accent-color: var(--accent); }
.workflow-analysis ol { margin-bottom: 20px; padding-inline-start: 18px; }
.workflow-analysis li { margin: 8px 0; }
.workflow-analysis li span { display: block; margin-top: 2px; color: var(--muted); overflow-wrap: anywhere; }
.workflow-analysis > p { margin-block: 12px 20px; color: var(--muted); }
.workflow-callback { margin: 6px 0 10px; padding: 8px 10px; border-radius: var(--radius-md); background: var(--inset); }
.workflow-callback p { margin-top: 6px; color: var(--muted); overflow-wrap: anywhere; }
.workflow-cohorts { width: calc(100% - 40px); margin-bottom: 16px; border-collapse: collapse; font-size: 13px; }
.workflow-cohorts :is(th, td) { padding: 8px 10px; border-bottom: 1px solid var(--soft-line); text-align: start; }
.workflow-cohorts thead th { color: var(--muted); font-size: 12px; font-weight: 500; background: var(--inset); }

/* ---------- Preview dialog ---------- */
#workflow-preview { width: min(560px, calc(100vw - 32px)); color: var(--ink); }
.workflow-preview-form { display: grid; gap: 16px; }
.workflow-preview-intro { margin: -4px 0 0; color: var(--muted); font-size: 13px; }
.workflow-preview-form > .button.primary { justify-self: end; }
.workflow-preview-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
#workflow-preview-result { color: var(--muted); font-size: 13px; }
#workflow-preview-result:not(:empty) { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--inset); }
#workflow-preview-result p { margin: 0; }
.workflow-preview-trace { display: grid; gap: 10px; margin: 0; padding-inline-start: 20px; color: var(--ink); overflow-wrap: anywhere; }
.workflow-preview-trace strong { font-weight: 600; }
.workflow-preview-trace ul { margin-top: 4px; padding-inline-start: 18px; color: var(--muted); }
.workflow-preview-trace ul strong { color: var(--ink); font-weight: 500; }

@media (max-width: 1100px) {
  .workflow-board { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 1000px) {
  .workflow-board { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(320px, auto) auto; min-height: 0; }
  .workflow-map { grid-row: 2; }
  .workflow-inspector { grid-column: 1; grid-row: 3; border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 600px) {
  #workflows-view { display: flex; flex-direction: column; }
  .workflow-sidebar { flex: none; max-height: 160px; overflow: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .workflow-start { padding-top: 0; }
  .workflow-templates { grid-template-columns: minmax(0, 1fr); }
  .workflow-preview-options { grid-template-columns: minmax(0, 1fr); }
  .workflow-header { padding-inline: 12px; }
}
