/* =========================================================================
   Workflows (features/workflows), admin only: Speed to lead, and Replies and call-backs.
     wf-list / wf-row   Leads Settings → Workflows: one bordered box, a row per workflow (on/off, Open)
     wf / wf-bar        the canvas over the whole app (as Clips is): Back, the name and its On/Off, Saving… / Saved
     wf-rail            the slim bar down its left: the on/off switch, History
     wf-stage / world   the dotted canvas, moved and scaled as one (JS writes the transform and the grid's offset)
     wf-node / tile     a step: a square tile (a line icon, or the mark of who does it: Twilio, Magnet) with a numbered
                        two-line label under it; .is-off dashed and quiet; a Twilio step's corner badge is the connection
     wf-conn            Twilio's connection: the mark, Connected / what's wrong, the number, Check again (the bar, the tab)
     wf-stopped         the notice when Magnet turned the workflows off (Twilio refused for the account): danger tone
     wf-wire / pill     the wires between them (SVG), and the words on a branch
     wf-sec / field     a step's sheet (the shared drawer) and History's list of runs
   ========================================================================= */

/* ---- Leads Settings → Workflows ---- */
.wf-list { border: 1px solid var(--border); border-radius: var(--radius-lg); }
.wf-row { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto auto; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); }
.wf-row + .wf-row { border-top: 1px solid var(--border-faint); }
.wf-row-ico { display: inline-flex; color: var(--text-soft); }
.wf-row-ico svg { width: 16px; height: 16px; }
.wf-row-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wf-row-name { font-size: var(--text-md); font-weight: var(--fw-medium); color: var(--text-strong); }
.wf-row-desc { font-size: var(--text-sm); line-height: var(--leading-snug); color: var(--text-soft); }
.wf-skel-ico { width: 16px; height: 16px; }
.wf-skel-line { width: 55%; height: 12px; }
.wf-skel-line.is-short { width: 85%; }
.wf-list-host { display: flex; flex-direction: column; gap: var(--space-3); }

/* ---- Twilio's connection (the canvas bar and the Workflows tab) ---- */
.wf-conn { display: flex; align-items: center; gap: var(--space-2); min-width: 0; font-size: var(--text-sm); color: var(--text-muted); }
.wf-conn-logo { flex: none; width: 16px; height: 16px; }
.wf-conn-name { font-weight: var(--fw-medium); color: var(--text-strong); }
.wf-conn-num { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-soft); }
.wf-conn .tone-pill { flex: none; }
.wf-conn-check.is-busy svg { animation: wf-spin 0.8s linear infinite; }
@keyframes wf-spin { to { transform: rotate(360deg); } }

/* ---- the full-screen layer: over the whole app; drawers, dialogs and toasts above it ---- */
body.wf-open { overflow: hidden; }
body.wf-open .drawer-scrim { z-index: calc(var(--z-overlay) + 1); }
body.wf-open .drawer { z-index: calc(var(--z-overlay) + 2); }
body.wf-open .modal-scrim, body.wf-open .modal-shell { z-index: var(--z-scrim); }
body.wf-open .status-toast-stack, body.wf-open .app-toast { z-index: calc(var(--z-scrim) + 4); }
.wf { position: fixed; inset: 0; z-index: var(--z-overlay); display: flex; flex-direction: column; background: var(--surface); }
.wf.is-entering { animation: wf-in 260ms var(--ease-ios) both; }
.wf.is-leaving { animation: wf-out 180ms var(--ease) both; pointer-events: none; }
@keyframes wf-in { from { opacity: 0; transform: scale(0.98); } }
@keyframes wf-out { to { opacity: 0; transform: scale(0.99); } }

.wf-bar { display: flex; flex: none; align-items: center; justify-content: space-between; gap: var(--space-3); height: var(--shell-header-height); padding: 0 var(--space-4); border-bottom: 1px solid var(--border-faint); background: var(--surface); }
.wf-bar-l, .wf-bar-r { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.wf-bar-l { flex: 1; }
.wf-bar-sep { flex: none; width: 1px; height: 20px; margin: 0 var(--space-1); background: var(--border); }
.wf-bar-ico { display: inline-flex; flex: none; color: var(--text-soft); }
.wf-bar-ico svg { width: 16px; height: 16px; }
.wf-bar-title { overflow: hidden; min-width: 0; margin: 0; white-space: nowrap; text-overflow: ellipsis; font-size: var(--text-md); font-weight: var(--fw-semibold); color: var(--text-strong); }
.wf-bar .tone-pill { flex: none; }
.wf-saved { font-size: var(--text-sm); color: var(--text-soft); opacity: 0; transition: opacity var(--dur) var(--ease); }
.wf-saved.is-on { opacity: 1; }
.wf-bar-r { gap: var(--space-4); }

.wf-main { display: flex; flex: 1; min-height: 0; }
.wf-rail { display: flex; flex: none; flex-direction: column; align-items: center; gap: var(--space-3); width: 56px; padding: var(--space-4) 0; border-right: 1px solid var(--border-faint); background: var(--surface); }
.wf-rail-sep { width: 20px; height: 1px; background: var(--border); }
.wf-rail-btn[aria-pressed="true"] { background: var(--gray-150); color: var(--text-strong); box-shadow: var(--press-inset-ghost); }

/* the canvas: dotted, moved by dragging (or two fingers), zoomed with a pinch or the buttons */
.wf-stage {
  position: relative; flex: 1; min-width: 0; overflow: hidden;
  background-color: var(--surface-sunk);
  background-image: radial-gradient(var(--border) 1px, transparent 1px);
  background-size: var(--wf-grid, 18px) var(--wf-grid, 18px);
  background-position: var(--wf-gx, 0) var(--wf-gy, 0);
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.wf-stage.is-panning { cursor: grabbing; }
.wf-world { position: absolute; top: 0; left: 0; width: 0; height: 0; transform-origin: 0 0; }
.wf-world.is-smooth { transition: transform var(--dur-slow) var(--ease); }
.wf-wires { position: absolute; left: var(--x); top: var(--y); width: var(--w); height: var(--h); overflow: visible; pointer-events: none; }
.wf-wire, .wf-wire-arrow { fill: none; stroke: var(--gray-400); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.wf-wire.is-off { stroke: var(--border-strong); stroke-dasharray: 4 5; }

/* a step: the node is a point at its centre; the tile and the label hang off it */
.wf-node { position: absolute; left: var(--x); top: var(--y); width: 0; height: 0; padding: 0; border: 0; background: none; font: inherit; color: inherit; text-align: center; }
button.wf-node { cursor: pointer; }
.wf-node:focus-visible { outline: none; }
.wf-tile {
  position: absolute; left: -28px; top: -28px; display: grid; place-items: center; width: 56px; height: 56px;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text-strong);
  box-shadow: var(--shadow-sm); transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.wf-tile svg { width: 22px; height: 22px; }
.wf-node:focus-visible .wf-tile { outline: var(--focus-outline); outline-offset: var(--focus-offset); }
.wf-brand { width: 26px; height: 26px; }
.wf-node.is-off .wf-brand { opacity: 0.45; filter: grayscale(1); }
/* the connection, on a Twilio step's corner: ticked when connected, a warning when not */
.wf-tile-badge {
  position: absolute; top: -6px; right: -6px; display: grid; place-items: center; width: 18px; height: 18px;
  border: 2px solid var(--surface-sunk); border-radius: var(--radius-full);
}
.wf-tile-badge svg { width: 10px; height: 10px; stroke-width: 3; }
.wf-tile-badge.is-ok { background: var(--success-bg); color: var(--success-600); }
.wf-tile-badge.is-warn { background: var(--warning-bg); color: var(--warning-600); }
.wf-node.is-sel .wf-tile { border-color: var(--text-strong); box-shadow: 0 0 0 0.5px var(--text-strong), var(--shadow-sm); }
.wf-node.is-end .wf-tile { left: -20px; top: -20px; width: 40px; height: 40px; border-radius: var(--radius-full); box-shadow: none; color: var(--text-soft); }
.wf-node.is-end .wf-tile svg { width: 16px; height: 16px; }
.wf-node.is-end .wf-label { top: 28px; }
.wf-node.is-off .wf-tile { border-style: dashed; border-color: var(--border-strong); background: var(--surface-sunk); box-shadow: none; color: var(--text-soft); }
.wf-node.is-off .wf-label-t { color: var(--text-soft); }
.wf-label { position: absolute; left: -75px; top: 36px; display: flex; flex-direction: column; gap: 1px; width: 150px; pointer-events: none; }
.wf-label-t, .wf-label-s { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.wf-label-t { font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--text-strong); }
.wf-label-s { font-size: var(--text-2xs); color: var(--text-soft); }
.wf-join { position: absolute; left: var(--x); top: var(--y); width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: var(--radius-full); background: var(--gray-400); }
.wf-pill {
  position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -50%);
  padding: 2px var(--space-2-5); border: 1px solid var(--border); border-radius: var(--radius-full); background: var(--surface);
  font-size: var(--text-2xs); font-weight: var(--fw-medium); white-space: nowrap; color: var(--text-muted); box-shadow: var(--shadow-xs); pointer-events: none;
}
.wf-pill.is-off { border-style: dashed; color: var(--text-soft); box-shadow: none; }
@media (hover: hover) and (pointer: fine) {
  button.wf-node:hover .wf-tile { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
  button.wf-node.is-sel:hover .wf-tile { border-color: var(--text-strong); }
}

/* the zoom buttons (top left), and why nothing may go out yet (bottom centre) */
.wf-zoom { position: absolute; top: var(--space-4); left: var(--space-4); display: flex; flex-direction: column; gap: 2px; padding: var(--space-1); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); cursor: default; }
.wf-zoom .icon-ghost { border-radius: var(--radius-sm); }
.wf-note {
  position: absolute; bottom: var(--space-4); left: 50%; transform: translateX(-50%); display: flex; align-items: flex-start; gap: var(--space-2);
  width: max-content; max-width: min(560px, calc(100% - var(--space-8))); padding: var(--space-2-5) var(--space-3-5);
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm);
  font-size: var(--text-sm); line-height: var(--leading-snug); color: var(--text-muted); cursor: default;
}
.wf-note[hidden] { display: none; }
.wf-note svg { width: 16px; height: 16px; flex: none; margin-top: 1px; color: var(--text-soft); }
.ls-empty-note.wf-stopped, .wf-note.wf-stopped { border-color: color-mix(in srgb, var(--danger-600) 30%, var(--border)); background: color-mix(in srgb, var(--danger-600) 8%, var(--surface)); color: var(--danger-700); }
.ls-empty-note.wf-stopped svg, .wf-note.wf-stopped svg { color: var(--danger-600); }
.wf-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-soft); cursor: default; }

/* ---- a step's sheet ---- */
.wf-sec { display: flex; flex-direction: column; gap: var(--space-3); }
.wf-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.wf-fields > .wf-field:only-child { grid-column: 1 / -1; }
.wf-field { display: flex; flex-direction: column; gap: var(--space-1-5); min-width: 0; }
.wf-field-k { font-size: var(--text-xs); font-weight: var(--fw-medium); color: var(--text-soft); }
.wf-sec > .field-msg { margin-top: calc(var(--space-1-5) - var(--space-3)); }
.wf-switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); cursor: pointer; }
.wf-switch-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wf-switch-t { font-size: var(--text-md); font-weight: var(--fw-medium); color: var(--text-strong); }
.wf-switch-h { font-size: var(--text-sm); color: var(--text-soft); }
.wf-how { display: flex; flex-direction: column; gap: var(--space-1-5); margin: 0; padding-left: var(--space-5); font-size: var(--text-sm); line-height: var(--leading-snug); color: var(--text-muted); }
.wf-hours { display: flex; align-items: center; gap: var(--space-2); }
.wf-hours .input { flex: 1; min-width: 0; }
.wf-hours-to { flex: none; font-size: var(--text-sm); color: var(--text-soft); }
.wf-inline { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-muted); }
.wf-num { flex: none; width: 72px; }
.wf-sec > .btn { align-self: flex-start; }

/* History: one bordered box, a run per row */
.wf-runs { border: 1px solid var(--border); border-radius: var(--radius-lg); }
.wf-run { display: flex; flex-direction: column; gap: var(--space-1-5); padding: var(--space-3) var(--space-4); }
.wf-run + .wf-run { border-top: 1px solid var(--border-faint); }
.wf-run-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.wf-run-name { overflow: hidden; min-width: 0; white-space: nowrap; text-overflow: ellipsis; font-size: var(--text-md); font-weight: var(--fw-medium); color: var(--text-strong); }
.wf-run-ago { flex: none; font-size: var(--text-xs); color: var(--text-soft); }
.wf-run-biz { margin-top: -4px; font-size: var(--text-sm); color: var(--text-soft); }
.wf-run-out { display: flex; flex-wrap: wrap; gap: var(--space-1-5); }

@media (max-width: 640px) {
  .wf-bar { padding: 0 var(--space-3); }
  .wf-bar-r { gap: var(--space-2); }
  .wf-bar .wf-conn-name, .wf-bar .wf-conn-num, .wf-bar .wf-conn-logo { display: none; }
  .wf-saved { display: none; }
  .wf-bar-sep, .wf-bar-ico { display: none; }
  .wf-rail { width: 48px; }
  .wf-zoom { top: var(--space-3); left: var(--space-3); }
  .wf-note { bottom: var(--space-3); }
  .wf-fields { grid-template-columns: minmax(0, 1fr); }
  .wf-row { grid-template-columns: 16px minmax(0, 1fr) auto; }
  .wf-row .btn { grid-column: 2 / -1; justify-self: start; }
}
@media (prefers-reduced-motion: reduce) {
  .wf.is-entering, .wf.is-leaving, .wf-conn-check.is-busy svg { animation: none; }
  .wf-world.is-smooth { transition: none; }
}
