/* ── Workflow builder + run pages — shared structural CSS ──────── */

/* Page wrappers */
.workflows-page,
.wf-run-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-5);
}
/* Builder is a split-pane (chat + form) so it needs a lot more horizontal
   room — 1200px squeezes both columns. Allowed to fill the viewport with
   generous gutters; on huge monitors a 1700px cap stops lines from
   stretching uncomfortably wide. */
.wf-builder {
    max-width: 1700px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-5);
}

/* Page headers */
.workflows-header,
.wf-builder-header,
.wf-run-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}

.wf-run-header-actions {
    display: flex;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* Stop run — danger-tinted so it reads as destructive next to Refresh. */
.wf-stop-btn {
    color: #b91c1c;
    border-color: #fca5a5;
}

.wf-stop-btn:hover:not(:disabled) {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

/* Verify-step verdict shown under the step name in run detail. */
.verify-verdict {
    margin-top: 4px;
    font-size: 0.82rem;
    font-weight: 600;
}
.verify-verdict.verdict-pass { color: #0f766e; }
.verify-verdict.verdict-fail { color: #b91c1c; }
.verify-detail {
    margin-top: 4px;
    font-size: 0.8rem;
}
.verify-detail summary {
    cursor: pointer;
    color: #b91c1c;
}
.verify-detail ul {
    margin: 4px 0 0 0;
    padding-left: 18px;
    color: var(--text-secondary);
}

/* AI Analysis step editor — suggested-question chips. */
.ai-suggest-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: 6px;
}
.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.ai-chip {
    border: 1px solid #99f6e4;
    background: #f0fdfa;
    color: #0f766e;
    border-radius: 14px;
    padding: 4px 10px;
    font-size: 0.82rem;
    cursor: pointer;
    text-align: left;
}
.ai-chip:hover {
    background: #0f766e;
    border-color: #0f766e;
    color: #fff;
}

.workflows-header .header-content h1,
.wf-builder-header h1,
.wf-run-header h1 {
    margin: 0 0 6px 0;
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-primary);
}

.workflows-header .subtitle,
.wf-run-header .run-id {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.back-link {
    display: inline-block;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    margin-bottom: 6px;
}
.back-link:hover { color: var(--text-primary); }

.wf-builder-actions { display: flex; gap: var(--space-3); }

/* Buttons (page-scoped variants) */
.workflows-page .btn-primary,
.wf-builder .btn-primary,
.wf-run-page .btn-primary {
    background: var(--qwri-accent, var(--accent-primary, #6d28d9));
    color: #fff;
    padding: 9px 16px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 120ms ease-out;
}
.workflows-page .btn-primary:hover,
.wf-builder .btn-primary:hover,
.wf-run-page .btn-primary:hover { background: var(--qwri-accent-ink, var(--accent-hover, #5b21b6)); }
.workflows-page .btn-primary:disabled,
.wf-builder .btn-primary:disabled,
.wf-run-page .btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.workflows-page .btn-secondary,
.wf-builder .btn-secondary,
.wf-run-page .btn-secondary {
    background: var(--bg-secondary, transparent);
    color: var(--text-primary);
    padding: 9px 14px;
    border-radius: 6px;
    border: 1px solid var(--border-default, #d4d4d8);
    font-weight: 500;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 120ms ease-out;
}
.workflows-page .btn-secondary:hover,
.wf-builder .btn-secondary:hover,
.wf-run-page .btn-secondary:hover { background: var(--bg-tertiary, rgba(0,0,0,0.04)); }
.workflows-page .btn-secondary.small,
.wf-builder .btn-secondary.small,
.wf-run-page .btn-secondary.small { padding: 5px 10px; font-size: 0.82rem; }
.workflows-page .btn-secondary:disabled,
.wf-builder .btn-secondary:disabled,
.wf-run-page .btn-secondary:disabled { opacity: 0.6; cursor: not-allowed; }

/* Banners / loading / empty */
.workflows-page .error-banner,
.wf-builder .error-banner,
.wf-run-page .error-banner {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 12px 16px;
    margin-bottom: var(--space-4);
    background: var(--bg-danger, rgba(239, 68, 68, 0.08));
    color: var(--text-danger, #ef4444);
    border: 1px solid var(--text-danger, #ef4444);
    border-radius: 6px;
    font-size: 0.9rem;
}
.workflows-page .error-banner.muted-banner,
.wf-run-page .error-banner.muted-banner {
    background: var(--bg-tertiary, rgba(0,0,0,0.04));
    color: var(--text-secondary);
    border-color: var(--border-default, #d4d4d8);
}
.workflows-page .close-btn {
    margin-left: auto;
    background: none; border: none;
    color: inherit; cursor: pointer;
    font-size: 1.2rem; line-height: 1;
}

.workflows-page .loading-container,
.wf-builder .loading-container,
.wf-run-page .loading-container {
    display: flex; flex-direction: column; align-items: center;
    padding: var(--space-8) 0; gap: var(--space-3);
    color: var(--text-tertiary, #71717a);
}
.workflows-page .loading-spinner-large,
.wf-builder .loading-spinner-large,
.wf-run-page .loading-spinner-large {
    width: 32px; height: 32px;
    border: 3px solid var(--border-light, #e4e4e7);
    border-top-color: var(--qwri-accent, var(--accent-primary, #6d28d9));
    border-radius: 50%;
    animation: wfSpin 0.8s linear infinite;
}
@keyframes wfSpin { to { transform: rotate(360deg); } }

.workflows-page .empty-state,
.wf-run-page .empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-5);
    color: var(--text-secondary);
}
.workflows-page .empty-state h2,
.wf-run-page .empty-state h2 {
    margin: 0 0 8px 0;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.2rem;
}

/* Tables (list + run-detail step states) */
.workflows-table-wrap,
.wf-run-page .step-states-table { width: 100%; }
.workflows-table,
.step-states-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.workflows-table thead,
.step-states-table thead {
    background: var(--bg-tertiary, rgba(0,0,0,0.04));
    text-align: left;
}
.workflows-table th,
.workflows-table td,
.step-states-table th,
.step-states-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light, #e4e4e7);
    vertical-align: top;
}
.workflows-table .wf-name { font-weight: 600; color: var(--text-primary); }
.workflows-table .wf-desc { font-size: 0.82rem; color: var(--text-tertiary); margin-top: 2px; }
.workflows-table .wf-schedule { font-size: 0.78rem; color: var(--accent-primary, #7c3aed); margin-top: 3px; }
/* Advisory notes: warning-severity lint findings — collapsed by default and
   visually calm, because the workflow runs fine as built. */
.wf-builder .advisory-notes-banner {
    margin: 0 0 14px; padding: 8px 14px; border-radius: 10px;
    background: var(--bg-subtle, #fafafa); border: 1px solid var(--border-color, #e4e4e7);
    font-size: 0.88rem; color: var(--text-secondary, #52525b);
}
.wf-builder .advisory-notes-banner summary { cursor: pointer; font-weight: 600; }
.wf-builder .advisory-notes-banner ul { margin: 8px 0 2px; }
/* Systematic-failure banner: reassures the user a repeat failure is the
   platform's fault, not their prompt, and carries the Report-to-qwri button. */
.systematic-failure-banner {
    margin-top: 10px; padding: 12px 14px; border-radius: 10px;
    background: #fffbeb; border: 1px solid #fde68a;
    color: #713f12; font-size: 0.9rem; line-height: 1.5;
}
.systematic-failure-banner .btn-primary.small {
    display: inline-block; margin-left: 8px; padding: 4px 12px; font-size: 0.8rem;
}
.systematic-failure-banner .systematic-reported {
    display: inline-block; margin-left: 8px; font-weight: 600; color: #15803d;
}
/* Sample-run modal: the orchestrator's live "what's happening now" line under
   the spinner while the sample runs. */
.wf-builder .sample-live-activity {
    max-width: 480px; margin: 6px auto 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* One-click test-drive: live activity line under the status badge while the
   Shadow sample runs (auto-activates on success). Clamped so a long
   orchestrator narration can't stretch the row. */
.workflows-table .wf-testdrive {
    font-size: 0.72rem; color: var(--accent-primary, #7c3aed);
    margin-top: 4px; max-width: 220px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.workflows-table .wf-owner { font-size: 0.75rem; color: var(--text-tertiary, #71717a); margin-top: 2px; }
.workflows-table .shared-chip {
    display: inline-flex; align-items: center;
    margin-left: 8px; padding: 1px 8px;
    font-size: 0.7rem; font-weight: 600;
    color: var(--accent-primary, #7c3aed);
    background: rgba(124, 58, 237, 0.10);
    border-radius: 999px; vertical-align: middle;
}
.workflows-table .muted,
.wf-run-page .muted { color: var(--text-tertiary, #71717a); }
.workflows-table .col-actions,
.wf-run-page .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.workflows-table .col-actions button,
.wf-run-page .action-btn {
    margin-left: 4px;
    background: transparent;
    border: 1px solid var(--border-default, #d4d4d8);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}
.workflows-table .action-btn:hover { background: var(--bg-tertiary); }
.workflows-table .action-btn.delete:hover { color: var(--text-danger); border-color: var(--text-danger); }
.workflows-table .action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Status badges + step states */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.status-draft    { background: rgba(113,113,122,0.15); color: #71717a; }
.status-active   { background: rgba(34,197,94,0.15);  color: #16a34a; }
.status-disabled { background: rgba(239,68,68,0.15);  color: #ef4444; }

.run-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}
.run-status.status-pending           { background: rgba(113,113,122,0.15); color: #52525b; }
.run-status.status-running           { background: rgba(99,102,241,0.15);  color: #4f46e5; }
.run-status.status-completed         { background: rgba(34,197,94,0.15);   color: #16a34a; }
.run-status.status-failed            { background: rgba(239,68,68,0.15);   color: #ef4444; }
.run-status.status-cancelled         { background: rgba(113,113,122,0.15); color: #52525b; }
.run-status.status-awaitingapproval  { background: rgba(245,158,11,0.18);  color: #d97706; }

.step-state {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
}
.state-pending           { background: rgba(113,113,122,0.15); color: #52525b; }
.state-running           { background: rgba(99,102,241,0.15);  color: #4f46e5; }
.state-completed,
.state-approved          { background: rgba(34,197,94,0.15);   color: #16a34a; }
.state-failed,
.state-rejected          { background: rgba(239,68,68,0.15);   color: #ef4444; }
.state-skipped           { background: rgba(113,113,122,0.15); color: #71717a; }
.state-awaitingapproval  { background: rgba(245,158,11,0.18);  color: #d97706; }

/* Combo B — a step's run gate (condition). Shown on the builder card so the
   user can see "this only fires when the analysis flags action" and clear it. */
.step-gate {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0 2px;
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.10);
    border: 1px solid rgba(245, 158, 11, 0.25);
    font-size: 0.82rem;
    color: #92400e;
}
.step-gate-icon  { font-size: 0.9rem; opacity: 0.8; }
.step-gate-text  { flex: 1; }
.step-gate-text strong { font-weight: 600; }
.step-gate-clear {
    background: none;
    border: 1px solid rgba(146, 64, 14, 0.35);
    color: #92400e;
    border-radius: 6px;
    padding: 1px 8px;
    font-size: 0.72rem;
    cursor: pointer;
}
.step-gate-clear:hover { background: rgba(146, 64, 14, 0.08); }

/* "Add gate" affordance + inline gate editor */
.step-gate-add { margin: 6px 0 2px; }
.gate-editor {
    margin: 6px 0 2px;
    padding: 10px;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.06);
    border: 1px solid rgba(245, 158, 11, 0.25);
}
.gate-editor-title { font-size: 0.8rem; font-weight: 600; color: #92400e; margin-bottom: 6px; }
.gate-editor-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.gate-field {
    padding: 4px 8px;
    border: 1px solid var(--border-primary, #d1d5db);
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: inherit;
    background: var(--bg-primary, #fff);
    color: var(--text-primary);
}
.gate-path { width: 170px; }
.gate-value { width: 110px; }
.gate-editor-actions {
    display: flex; align-items: center; gap: 8px;
    margin-top: 8px;
}
.gate-editor-hint { flex: 1; font-size: 0.74rem; color: var(--text-secondary); }

/* Gate dry-run outcome ("Test against last run") */
.gate-test-result {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    line-height: 1.45;
}
.gate-test-result.pass { background: rgba(16, 185, 129, 0.08); border: 1px solid rgba(16, 185, 129, 0.3); color: #065f46; }
.gate-test-result.skip { background: rgba(107, 114, 128, 0.08); border: 1px solid rgba(107, 114, 128, 0.3); color: #374151; }
.gate-test-result.warn { background: rgba(239, 68, 68, 0.07); border: 1px solid rgba(239, 68, 68, 0.3); color: #991b1b; }

/* Phase A — live activity line under the currently-running step. The row
   itself gets a subtle indigo tint so users can locate it instantly while
   scrolling a long step list. */
.step-row-running        { background: rgba(99, 102, 241, 0.05); }

.step-activity {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-size: 0.83rem;
    color: var(--text-secondary, #52525b);
    font-style: italic;
}

.step-activity-spinner {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid rgba(99, 102, 241, 0.25);
    border-top-color: #4f46e5;
    animation: step-activity-spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes step-activity-spin {
    to { transform: rotate(360deg); }
}

/* Phase C — Running-now indicator on the workflows list + runs page. */
.running-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 1px 8px;
    margin-left: 8px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #4f46e5;
    background: rgba(99, 102, 241, 0.12);
    border-radius: 999px;
    vertical-align: middle;
}
.running-chip-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4f46e5;
    animation: running-pulse 1.4s ease-in-out infinite;
}
@keyframes running-pulse {
    0%, 100% { opacity: 0.45; }
    50%      { opacity: 1; }
}

.active-runs-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin-bottom: 12px;
    background: rgba(99, 102, 241, 0.08);
    border-left: 3px solid #6366f1;
    border-radius: 4px;
    font-size: 0.88rem;
    color: var(--text-primary, #18181b);
}
.active-runs-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6366f1;
    animation: running-pulse 1.4s ease-in-out infinite;
}

/* Builder structure */
.wf-builder-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.card {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-light, #e4e4e7);
    border-radius: 8px;
    padding: var(--space-4) var(--space-5);
}
.card h2 {
    margin: 0 0 var(--space-3) 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}
.card .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
}
.card .section-header h2 { margin: 0; }
.card p.muted { color: var(--text-tertiary, #71717a); font-size: 0.85rem; margin: 0 0 var(--space-3) 0; }
.card p.muted.small { font-size: 0.8rem; margin-top: 4px; }

/* Form fields */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--space-3); }
.field.grow { flex: 1; }
.field-row {
    display: flex;
    gap: var(--space-3);
    /* flex-start, not flex-end: sibling fields carry hint text of different
       heights (sometimes conditionally), and bottom-aligning them shoves the
       shorter field's label/control below its neighbour's baseline. */
    align-items: flex-start;
    flex-wrap: wrap;
    margin-bottom: var(--space-3);
}
@media (max-width: 640px) {
    .field-row { flex-direction: column; align-items: stretch; }
    .field-row .field { width: 100%; }
}
.field label {
    font-size: 0.82rem;
    color: var(--text-secondary, #52525b);
    font-weight: 500;
}
.field-hint {
    font-size: 0.78rem;
    color: var(--text-tertiary, #71717a);
    margin-top: 2px;
}
/* Endpoint description under the picker — clamped when it's a long schema dump. */
.endpoint-desc {
    font-size: 0.78rem;
    color: var(--text-tertiary, #71717a);
    margin-top: 2px;
}
.endpoint-desc.clamped {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea,
.input-row input,
.input-row select,
.kv-row input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border-default, #d4d4d8);
    border-radius: 4px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #18181b);
    font-size: 0.9rem;
    font-family: inherit;
}
.field textarea.code-area {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.83rem;
    line-height: 1.45;
    white-space: pre;
}
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    padding: 7px 0;
}
.checkbox-row input { width: auto; margin: 0; }

/* Intent-contract results on the run-detail page */
.contract-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    vertical-align: middle;
}
.contract-badge.pass { background: rgba(16, 185, 129, 0.12); color: #065f46; }
.contract-badge.fail { background: rgba(239, 68, 68, 0.12); color: #991b1b; }
.contract-outcome.pass { color: #059669; font-weight: 600; }
.contract-outcome.fail { color: #b91c1c; font-weight: 600; }
.contract-outcome.inconclusive { color: var(--text-secondary, #71717a); }
.contract-detail { font-size: 0.8rem; color: var(--text-secondary, #52525b); }

/* Run-trigger modal: checkbox list for a multi-select input */
.multiselect-options {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border-color, #d0d5dd);
    border-radius: 8px;
    padding: 4px 10px;
}
.multiselect-options .checkbox-row { padding: 5px 0; }

/* Dynamic (optionsSource) input — live checkbox table in the trigger modal */
.dynamic-options-table-wrap {
    max-height: 300px;
    overflow: auto;
    border: 1px solid var(--border-color, #d0d5dd);
    border-radius: 8px;
}
.dynamic-options-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.dynamic-options-table th,
.dynamic-options-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-color, #e4e7ec);
    white-space: nowrap;
}
.dynamic-options-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface-color, #f9fafb);
    z-index: 1;
}
.dynamic-options-table tbody tr { cursor: pointer; }
.dynamic-options-table tbody tr:hover { background: var(--hover-color, #f2f4f7); }
.dynamic-options-table tbody tr.selected { background: var(--selected-color, #ecfdf3); }
.dynamic-options-table .dyn-check-col { width: 32px; }
.btn-inline { margin-left: 8px; padding: 2px 10px; font-size: 0.8rem; }

/* Inputs editor rows */
.input-row {
    display: grid;
    grid-template-columns: 1fr 1.4fr 0.8fr 1fr auto auto;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

/* select-input dropdown choices sub-editor */
.input-options {
    margin: -2px 0 12px 24px;
    padding: 8px 10px;
    border-left: 2px solid var(--border-default, #d4d4d8);
    background: var(--bg-secondary, #fafafa);
    border-radius: 4px;
}
.input-options-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.option-row {
    display: grid;
    grid-template-columns: 1fr 1.6fr auto;
    gap: 8px;
    margin-bottom: 6px;
    align-items: center;
}
.option-row input {
    width: 100%;
    padding: 6px 9px;
    border: 1px solid var(--border-default, #d4d4d8);
    border-radius: 4px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #18181b);
    font-size: 0.88rem;
    font-family: inherit;
}

/* Step cards */
.steps-card { display: flex; flex-direction: column; gap: var(--space-3); }
.add-step-cluster { display: flex; gap: 6px; flex-wrap: wrap; }

.step-card {
    border: 1px solid var(--border-default, #d4d4d8);
    border-radius: 6px;
    background: var(--bg-secondary, rgba(0,0,0,0.02));
}
.step-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary, rgba(0,0,0,0.04));
    border-bottom: 1px solid var(--border-light, #e4e4e7);
    border-radius: 6px 6px 0 0;
}
.step-index { font-weight: 600; color: var(--text-tertiary); font-family: ui-monospace, monospace; font-size: 0.85rem; }
.step-id { width: 110px !important; padding: 4px 8px !important; font-size: 0.82rem !important; font-family: ui-monospace, monospace; }
.step-name { flex: 1; padding: 4px 8px !important; font-size: 0.85rem !important; }
.step-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    background: rgba(99,102,241,0.15);
    color: #4f46e5;
}
/* Sophia proposed-change review marks (per-step accept/undo). */
.step-card--proposed {
    border-left: 3px solid var(--qwri-accent, #0F766E);
    background: rgba(15, 118, 110, 0.045);
}
.step-proposed-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    background: rgba(15, 118, 110, 0.14);
    color: var(--qwri-accent, #0F766E);
    white-space: nowrap;
}
.step-proposed-btn {
    padding: 2px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-primary, #e5e5eb);
    background: var(--bg-primary, #fff);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.step-proposed-btn.keep { color: var(--qwri-accent, #0F766E); }
.step-proposed-btn.undo { color: #b45309; }
.step-proposed-btn:hover { background: var(--bg-tertiary, rgba(0,0,0,0.05)); }
.step-removed-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding: 8px 14px;
    border: 1px dashed var(--border-primary, #d4d4d8);
    border-radius: var(--radius-lg, 8px);
    color: var(--text-secondary, #52525b);
    font-size: 0.85rem;
}
.step-removed-name { font-style: italic; }

/* One collapsible convention (run detail's <details> elements). */
.wf-details > summary {
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary, #52525b);
    user-select: none;
}
.wf-details > summary:hover { color: var(--text-primary, #1a1a2e); }
.wf-details[open] > summary { margin-bottom: 6px; }

/* Debug-a-failed-run banner in the builder (?debugRun deep link). */
.wf-debug-banner {
    margin: 0 0 14px;
    padding: 10px 16px;
    border: 1px solid rgba(220, 38, 38, 0.35);
    border-left: 4px solid #dc2626;
    border-radius: var(--radius-lg, 8px);
    background: rgba(220, 38, 38, 0.06);
    color: var(--text-primary, #1a1a2e);
    font-size: 0.875rem;
    line-height: 1.55;
}
.wf-debug-banner a { color: #dc2626; font-weight: 600; margin-left: 6px; }

/* "If this step fails" controls on the step card. */
.wf-retry-wait { width: 64px; padding: 2px 6px; margin: 0 4px; }

/* Conditional-step chip on the collapsed summary row — gates were previously
   invisible until the card AND the gate editor were both expanded. */
.step-gate-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(245, 158, 11, 0.14);
    color: #b45309;
    white-space: nowrap;
}
/* ── Step-card sections: What it does / If something goes wrong / Sophia handles ── */
.step-section {
    border: 1px solid var(--border-subtle, #e4e4e7);
    border-radius: 8px;
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
    background: var(--bg-primary, #fff);
}
.step-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary, #71717a);
    margin-bottom: var(--space-3);
}
.step-section-sophia {
    background: rgba(15, 118, 110, 0.04);
    border-color: rgba(15, 118, 110, 0.18);
}
.sophia-facts {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary, #52525b);
}
.sophia-facts li::before {
    content: "•";
    color: var(--qwri-accent, #0F766E);
    margin-right: 8px;
}
.sophia-facts code {
    font-size: 0.8rem;
    background: rgba(15, 118, 110, 0.08);
    padding: 1px 5px;
    border-radius: 4px;
}
/* Full-width consequence sentence under the failure-policy row. */
.step-consequence {
    margin-top: 4px;
    font-style: italic;
}
.step-more-options { margin-top: var(--space-2); }

/* Collapsed-row chip for a non-default failure policy — the one business
   decision worth seeing without opening the card. Default (stop, no retries)
   shows nothing. */
.step-fail-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(99, 102, 241, 0.12);
    color: #4338ca;
    white-space: nowrap;
}

/* Builder header status chip (Draft / Active / Disabled). */
.wf-builder-header h1 { display: flex; align-items: center; gap: 10px; }
.wf-status-chip {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    vertical-align: middle;
}
.wf-status-chip.wf-status-draft    { background: rgba(245,158,11,0.16); color: #b45309; }
.wf-status-chip.wf-status-active   { background: rgba(34,197,94,0.16);  color: #15803d; }
.wf-status-chip.wf-status-disabled { background: rgba(113,113,122,0.16); color: #52525b; }

/* Per-item results (fan-out children) on run detail */
.child-runs-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-color, #e4e7ec);
    border-radius: 8px;
}
.child-runs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.child-runs-table th,
.child-runs-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color, #e4e7ec);
    vertical-align: top;
}
.child-runs-table .child-item { font-weight: 600; white-space: nowrap; }
.child-runs-table .child-error { max-width: 420px; }
.child-runs-table .btn-small { padding: 3px 10px; font-size: 0.8rem; }
.child-runs-table .child-actions { white-space: nowrap; display: flex; gap: 6px; }

/* Per-item steps, expanded in place: a multi-item run has to read as ONE
   screen, so the operator never has to leave the parent to see what an
   item did. */
.child-steps-row > td { background: var(--bg-tertiary, rgba(0,0,0,0.03)); }
.child-steps {
    margin: 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.child-step { font-size: 0.83rem; }
.child-step code { margin-left: 8px; }

.status-chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}
.status-chip.ok        { background: rgba(34,197,94,0.16);  color: #15803d; }
.status-chip.skipped   { background: rgba(113,113,122,0.16); color: #52525b; }
.status-chip.shadow    { background: rgba(99,102,241,0.14); color: #4338ca; }
.status-chip.warn      { background: rgba(245,158,11,0.16); color: #b45309; }
.status-chip.failed    { background: rgba(239,68,68,0.16);  color: #b91c1c; }
.status-chip.cancelled { background: rgba(113,113,122,0.16); color: #52525b; }
.status-chip.awaiting  { background: rgba(59,130,246,0.14); color: #1d4ed8; }
.status-chip.running   { background: rgba(59,130,246,0.14); color: #1d4ed8; }

.step-type-badge.step-type-write_action { background: rgba(245,158,11,0.18); color: #d97706; }
.step-type-badge.step-type-bulk_export  { background: rgba(34,197,94,0.15);  color: #16a34a; }
.step-type-badge.step-type-transform    { background: rgba(168,85,247,0.18); color: #9333ea; }

.step-actions { display: flex; gap: 4px; margin-left: auto; }
.icon-btn {
    background: transparent;
    border: 1px solid var(--border-default, #d4d4d8);
    color: var(--text-primary);
    width: 28px; height: 26px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
}
.icon-btn:hover { background: var(--bg-tertiary); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn.delete:hover { color: var(--text-danger); border-color: var(--text-danger); }

.step-card-body { padding: 12px 14px; }
.step-editor { display: flex; flex-direction: column; gap: var(--space-3); }

.recipe-reset-row {
    margin-top: var(--space-3);
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.recipe-reset-text { flex: 1; font-size: 0.85rem; line-height: 1.4; }
.recipe-reset-text strong { display: block; margin-bottom: 2px; }
/* Auto-cleared-on-edit variant: amber accent to signal a pending re-capture. */
.recipe-recapture-note {
    background: var(--warning-bg, rgba(245, 158, 11, 0.10));
    border-color: var(--warning-border, rgba(245, 158, 11, 0.45));
}
.kv-row {
    display: grid;
    grid-template-columns: 1fr 2fr auto;
    gap: 6px;
    margin-bottom: 6px;
}

/* Run detail */
.run-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: var(--space-4);
}
.run-summary-block .label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.approval-card { border: 1px solid #f59e0b; }
.approval-block {
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 12px 14px;
    margin-top: var(--space-3);
}
/* Which item this approval is for. On a fan-out parent several cards carry
   near-identical payloads, so the item is the only thing telling them apart. */
.approval-item-badge {
    display: inline-block;
    padding: 2px 10px;
    margin-bottom: 8px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    background: #fef3c7;
    color: #92400e;
}
.approval-meta { font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 8px; }
.approval-meta .muted { color: var(--text-tertiary); margin: 0 4px 0 12px; }
.approval-actions { display: flex; gap: 8px; margin-top: 8px; }
.payload-pre {
    background: var(--bg-tertiary, rgba(0,0,0,0.04));
    padding: 10px 12px;
    border-radius: 4px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82rem;
    white-space: pre-wrap;
    max-height: 320px;
    overflow: auto;
}
.step-error { color: var(--text-danger, #ef4444); font-size: 0.82rem; }
.muted.small, .small { font-size: 0.78rem; }

/* Modal — scoped to all three workflow roots. The builder page root is
   .wf-builder; omitting it here left the modal card unstyled so Bootstrap's
   global .modal-backdrop covered the screen in black with no visible card. */
.workflows-page .modal-backdrop,
.wf-run-page .modal-backdrop,
.wf-builder .modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 100;
}
.workflows-page .modal-card,
.wf-run-page .modal-card,
.wf-builder .modal-card {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: min(560px, 92vw);
    background: var(--bg-primary, #fff);
    border-radius: 8px;
    z-index: 101;
    display: flex; flex-direction: column;
    max-height: 88vh;
}
/* Wider variant for the sample-run modal, which renders a step-states table. */
.workflows-page .modal-card.modal-card-wide,
.wf-run-page .modal-card.modal-card-wide,
.wf-builder .modal-card.modal-card-wide {
    width: min(820px, 94vw);
}
/* Content-sized variant (the run-trigger dialog). A dynamic input renders a
   live option table whose width depends on the tenant's detailColumns, so no
   fixed width is right: too narrow clips the last column behind an inner
   scrollbar, too wide leaves a mostly-empty dialog for a two-column table.
   fit-content grows the dialog to the table and stops there, floored at the
   old 560px so simple dialogs are unchanged and capped so a wide table
   scrolls inside rather than running off the viewport.
   The prose caps below are load-bearing, not cosmetic: a paragraph's
   max-content width is its ENTIRE text on one line, so without them the
   readiness checklist alone would push every trigger dialog to the cap. */
.workflows-page .modal-card.modal-card--fit,
.wf-run-page .modal-card.modal-card--fit,
.wf-builder .modal-card.modal-card--fit {
    /* Centred with auto margins rather than the shell's left:50% + translateX.
       That is not a style preference: for a fixed element, shrink-to-fit space
       is the containing block MINUS the left offset, so left:50% would cap
       fit-content at 50vw and the dialog could never grow past it. Anchoring
       left:0/right:0 gives it the full viewport to size against, and auto
       margins do the centring the translate used to. */
    left: 0;
    right: 0;
    margin-inline: auto;
    transform: translateY(-50%);
    width: fit-content;
    min-width: min(560px, 92vw);
    max-width: min(1180px, 94vw);
}
.modal-card--fit .readiness-headline,
.modal-card--fit .readiness-list,
.modal-card--fit .error-banner,
.modal-card--fit .modal-body > p,
.modal-card--fit .modal-body .field-hint,
.modal-card--fit .modal-body .muted {
    max-width: 64ch;
}
/* The option table is what may legitimately exceed the floor width — it must
   not inherit any measure cap, and its wrapper stretches to the dialog. */
.modal-card--fit .dynamic-options-table-wrap {
    max-width: none;
    width: 100%;
}
.workflows-page .modal-header,
.wf-run-page .modal-header,
.wf-builder .modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-light);
}
.workflows-page .modal-header h2,
.wf-run-page .modal-header h2,
.wf-builder .modal-header h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.workflows-page .modal-close,
.wf-run-page .modal-close,
.wf-builder .modal-close {
    background: none; border: none;
    font-size: 1.4rem; line-height: 1;
    cursor: pointer; color: var(--text-tertiary);
}
.workflows-page .modal-body,
.wf-run-page .modal-body,
.wf-builder .modal-body { padding: 16px 18px; overflow: auto; }
.workflows-page .modal-footer,
.wf-run-page .modal-footer,
.wf-builder .modal-footer {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--border-light);
}

code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.85em; }

/* ── Builder validation banner ────────────────────────────────── */
.warning-banner {
    background: rgba(245, 158, 11, 0.10);
    border: 1px solid #f59e0b;
    color: var(--text-primary, #18181b);
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: var(--space-4);
    font-size: 0.9rem;
}
.warning-banner-header {
    margin-bottom: 8px;
    color: #b45309;
}
.warning-banner-header strong { color: #92400e; }
.warning-banner-list {
    margin: 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.warning-banner-list code {
    background: rgba(245, 158, 11, 0.15);
    color: #92400e;
    padding: 0 4px;
    border-radius: 3px;
}
.link-btn {
    background: none;
    border: none;
    color: var(--qwri-accent, #6d28d9);
    text-decoration: underline;
    cursor: pointer;
    padding: 0 4px;
    font: inherit;
}
.link-btn:hover { color: var(--qwri-accent-ink, #5b21b6); }

/* ── Per-step editor extras: key-pills + advanced details ─────── */
.key-pill-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}
.key-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border-default, #d4d4d8);
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #18181b);
    cursor: pointer;
    font-size: 0.82rem;
    transition: background 100ms ease, border-color 100ms ease;
}
.key-pill:hover {
    background: var(--bg-tertiary, rgba(0,0,0,0.04));
}
.key-pill.selected {
    background: rgba(99,102,241,0.12);
    border-color: #6366f1;
    color: #4338ca;
}
.key-pill .check { font-weight: 700; }
.key-pill code { background: transparent; padding: 0; font-size: 0.82rem; }

.advanced-block {
    margin-top: var(--space-2, 8px);
    border: 1px dashed var(--border-default, #d4d4d8);
    border-radius: 6px;
    padding: 6px 10px;
}
.advanced-block summary {
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary);
    user-select: none;
    padding: 4px 0;
}
.advanced-block[open] summary {
    margin-bottom: var(--space-2, 8px);
    color: var(--text-primary);
    font-weight: 500;
}

/* ── Phase 10a — split-pane builder + revealable step cards ─────────── */

/* Two-column layout: chat on the left, form on the right. Collapses to a
   stacked layout on narrow viewports (tablets / small laptops). */
.wf-split {
    display: grid;
    /* Roughly equal split — chat pane is a primary surface, not a side
       panel. minmax floors keep both columns usable on narrower
       monitors. align-items: start keeps the chat-pane card anchored
       to the TOP of its column instead of stretching to match the
       right column's height (stretching pushes the input box far away
       from the intent textarea when there are many steps on the right). */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--space-5, 20px);
    align-items: start;
}
@media (max-width: 1200px) {
    .wf-split {
        grid-template-columns: 1fr;
    }
}

.wf-chat-pane {
    /* Sticky so as the user scrolls the right-column step list the
       chat stays visible at the top of the viewport. */
    position: sticky;
    top: var(--space-5, 20px);
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
}

.chat-pane-card {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-default, #e4e4e7);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* Content-sized — the card no longer stretches to match the right
       column's height. The intent textarea + clarification + actions
       sit as a tight visual cluster regardless of how many steps are
       on the right. Sticky positioning (on .wf-chat-pane) keeps the
       card visible as the user scrolls the step list. */
    overflow: hidden;
}
.chat-pane-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-light, #f1f1f3);
}
.chat-pane-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary, #18181b);
}
/* ── v2 intent-doc shape ─────────────────────────────────────── */
.chat-pane-intent {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.intent-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary, #52525b);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.intent-textarea {
    width: 100%;
    min-height: 260px;
    padding: 12px 14px;
    font-size: 0.95rem;
    line-height: 1.55;
    border: 1px solid var(--border-default, #d4d4d8);
    border-radius: 6px;
    resize: vertical;
    font-family: inherit;
    color: var(--text-primary, #18181b);
    background: var(--bg-primary, #fff);
}
.intent-textarea:focus {
    outline: none;
    border-color: var(--qwri-accent, #6366f1);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}
.intent-textarea:disabled {
    background: var(--bg-tertiary, rgba(0,0,0,0.03));
    color: var(--text-tertiary, #71717a);
    cursor: not-allowed;
}
.intent-hint {
    font-size: 0.78rem;
    color: var(--text-tertiary, #71717a);
}

.intent-autosave {
    font-size: 0.78rem;
    color: var(--text-tertiary, #71717a);
    font-style: italic;
}

.intent-autosave-err {
    font-size: 0.78rem;
    color: var(--qwri-danger, #dc2626);
}

.chat-pane-updated {
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--text-tertiary, #71717a);
    margin-left: 6px;
}

.bld-pickup-banner {
    padding: 8px 12px;
    background: rgba(99, 102, 241, 0.08);
    border-left: 3px solid var(--qwri-accent, #6366f1);
    border-radius: 4px;
    font-size: 0.82rem;
    color: var(--text-secondary, #52525b);
    font-style: italic;
}

.bld-note {
    padding: 10px 12px;
    background: var(--bg-tertiary, rgba(0,0,0,0.03));
    border-left: 3px solid var(--qwri-accent, #6366f1);
    border-radius: 4px;
    font-size: 0.9rem;
    color: var(--text-primary, #18181b);
    line-height: 1.5;
}

/* "What changed": the server's own account of the turn, beside Sophia's note */
.bld-applied {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.82rem;
    color: var(--text-primary, #18181b);
    background: rgba(13, 148, 136, 0.08);
    border-left: 3px solid #0d9488;
}
.bld-applied-none {
    background: var(--bg-tertiary, rgba(0,0,0,0.03));
    border-left-color: var(--border-color, #d4d4d8);
    color: var(--text-secondary, #52525b);
}
.bld-applied-label {
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary, #71717a);
    white-space: nowrap;
}
.bld-applied-skipped {
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.82rem;
    background: rgba(217, 119, 6, 0.08);
    border-left: 3px solid #d97706;
    color: var(--text-primary, #18181b);
}
.bld-applied-skipped ul { margin: 4px 0 0 18px; padding: 0; }

/* Sophia rewrote the user's intent: shown, diffable, undoable */
.bld-intent-change {
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.82rem;
    background: rgba(99, 102, 241, 0.08);
    border-left: 3px solid var(--qwri-accent, #6366f1);
}
.bld-intent-change-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.bld-intent-change-actions { display: inline-flex; align-items: center; gap: 6px; }
.bld-intent-diff {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 4px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e4e4e7);
    line-height: 1.6;
    font-size: 0.85rem;
}
.bld-intent-diff .diff-added { background: rgba(22, 163, 74, 0.18); border-radius: 2px; padding: 0 2px; }
.bld-intent-diff .diff-removed { background: rgba(220, 38, 38, 0.14); text-decoration: line-through; border-radius: 2px; padding: 0 2px; }

/* Intent-coverage panel: requirement ↔ step provenance from the last turn */
.bld-coverage {
    border: 1px solid var(--border-color, #e4e4e7);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.8rem;
}
.bld-coverage-title {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary, #71717a);
    margin-bottom: 4px;
}
.bld-coverage-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 3px 0;
    line-height: 1.4;
}
.bld-coverage-row .cov-icon  { width: 14px; flex-shrink: 0; text-align: center; }
.bld-coverage-row .cov-text  { flex: 1; }
.bld-coverage-row .cov-steps { font-family: monospace; font-size: 0.72rem; color: var(--text-secondary, #71717a); }
.bld-coverage-row.covered   .cov-icon { color: #059669; }
.bld-coverage-row.partial   .cov-icon { color: #d97706; }
.bld-coverage-row.uncovered { color: #b91c1c; }
.bld-coverage-row.uncovered .cov-icon { color: #b91c1c; }

.bld-clarification {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    background: rgba(99, 102, 241, 0.05);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 8px;
}
.bld-clar-q {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary, #18181b);
    line-height: 1.45;
}
.bld-clar-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.bld-chip {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-default, #d4d4d8);
    color: var(--text-primary, #18181b);
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 100ms ease, border-color 100ms ease;
}
.bld-chip:hover:not(:disabled) {
    background: rgba(99, 102, 241, 0.12);
    border-color: var(--qwri-accent, #6366f1);
}
.bld-chip:disabled { opacity: 0.5; cursor: not-allowed; }
.bld-clar-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.9rem;
    line-height: 1.5;
    border: 1px solid var(--border-default, #d4d4d8);
    border-radius: 6px;
    resize: vertical;
    font-family: inherit;
    background: var(--bg-primary, #fff);
}
.bld-clar-input:focus {
    outline: none;
    border-color: var(--qwri-accent, #6366f1);
}
.bld-clar-actions {
    display: flex;
    justify-content: flex-end;
}

.chat-pane-actions {
    display: flex;
    justify-content: flex-end;
}

/* Compact summary row (always visible) for each step. */
.step-card-summary {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
}
.step-card-summary .step-index {
    font-size: 0.82rem;
    color: var(--text-tertiary, #71717a);
    font-weight: 600;
    padding-top: 8px;
    min-width: 24px;
}
.step-summary-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.step-name-input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 0.98rem;
    font-weight: 500;
    color: var(--text-primary, #18181b);
    padding: 6px 0;
    outline: none;
}
.step-name-input::placeholder {
    color: var(--text-tertiary, #a1a1aa);
    font-weight: 400;
    font-style: italic;
}
.step-name-input:focus {
    border-bottom: 1px solid var(--qwri-accent, #6366f1);
}
.step-summary-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-tertiary, #71717a);
}
.step-id-label {
    background: var(--bg-tertiary, rgba(0,0,0,0.04));
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    color: var(--text-secondary, #52525b);
}
.step-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.reveal-toggle {
    background: transparent;
    border: 1px solid var(--border-default, #d4d4d8);
    color: var(--text-secondary, #52525b);
    font-size: 0.78rem;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 120ms ease;
}
.reveal-toggle:hover {
    background: var(--bg-tertiary, rgba(0,0,0,0.04));
    color: var(--text-primary, #18181b);
}

/* ── Output files (run artifacts) ─────────────────────────── */
.wf-run-page .artifact-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.wf-run-page .artifact-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px;
    border: 1px solid var(--border-light, #e4e4e7);
    border-radius: 8px;
    background: var(--bg-secondary, rgba(0,0,0,0.015));
}
.wf-run-page .artifact-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.wf-run-page .artifact-icon { font-size: 1.4rem; line-height: 1; }
.wf-run-page .artifact-name { font-weight: 600; color: var(--text-primary, #18181b); }

/* Inline download affordance on a step's output key. */
.wf-run-page .link-button {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    color: var(--qwri-accent, var(--accent, #6d28d9));
    font: inherit;
}
.wf-run-page .link-button:hover { text-decoration: underline; }
.wf-run-page .link-button code { color: inherit; }


/* ── Write kill switch (builder Basics panel) ─────────────────────── */
.wf-kill-switch {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}
.wf-kill-switch input[type="checkbox"] { cursor: pointer; }

/* ── Approval summary card (human sentence first, JSON collapsed) ──── */
.approval-summary { margin: 8px 0 4px; }
.approval-headline { font-weight: 600; font-size: 1.02rem; margin-bottom: 4px; }
.approval-reason {
    background: #fef3c7;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.88rem;
    margin: 6px 0;
}
.approval-facts { border-collapse: collapse; width: 100%; max-width: 480px; font-size: 0.9rem; margin: 6px 0; }
.approval-facts td { padding: 4px 8px; border-bottom: 1px solid var(--border, #eee); }
.approval-facts td:first-child { color: var(--muted, #6b7280); }

/* ── Write receipts + trust banner ─────────────────────────────────── */
.write-receipt-state { font-weight: 600; font-size: 0.88rem; }
.write-receipt-state.succeeded { color: #15803d; }
.write-receipt-state.failed { color: #b91c1c; }
.write-receipt-state.sent { color: #b45309; }
.write-receipt-state.pending { color: #6b7280; }
.write-receipt-error { color: #b91c1c; font-size: 0.85rem; }
.wf-trust-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #ecfdf5;
    border: 1px solid #6ee7b7;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 8px 0;
    font-size: 0.9rem;
}

/* ── Starter intent chips (blank-page empty state) ─────────────────── */
.intent-starters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}
.intent-starters-label { color: var(--muted, #6b7280); font-size: 0.82rem; }
.intent-starter-chip {
    background: var(--chip-bg, #f3f0ff);
    border: 1px solid var(--chip-border, #d8ccf4);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    text-align: left;
}
.intent-starter-chip:hover { filter: brightness(0.97); }

/* ── Mobile: data-dense run-detail tables scroll instead of squishing ── */
@media (max-width: 900px) {
    .wf-run-page .step-states-table,
    .wf-run-page .approval-facts {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
}
.artifact-retention-hint { margin-top: 8px; }

/* ── Fleet health strip + failing chip (workflows list) ────────────── */
.fleet-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    padding: 10px 16px;
    margin-bottom: 14px;
    font-size: 0.9rem;
}
.fleet-strip.has-failures { border-color: #fca5a5; }
.fleet-stat { font-weight: 600; }
.fleet-stat.ok { color: #15803d; }
.fleet-stat.bad { color: #b91c1c; }
.fleet-stat.warn { color: #b45309; }
.fleet-stat.muted { color: var(--muted, #6b7280); font-weight: 400; }
.failing-chip {
    display: inline-block;
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-left: 6px;
}

/* Steady-state "last run" chip on the workflows list — the failing-chip
   above wins when the workflow is on a failure streak, so these colors are
   deliberately calmer (amber, not red) than that alarm state. */
.last-run-chip {
    display: inline-block;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    margin-left: 6px;
    vertical-align: middle;
}
.last-run-chip.ok      { background: rgba(34,197,94,0.15);   color: #16a34a; }
.last-run-chip.warn    { background: rgba(245,158,11,0.18);  color: #b45309; }
.last-run-chip.neutral { background: rgba(113,113,122,0.15); color: #71717a; }

/* ── Reliability badges (success ratio + time saved) on each row ────────
   Deliberately muted/compact — trust furniture, not an alarm. The red
   failing-chip above stays the only loud element on a row. */
.wf-reliability {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}
.reliability-chip {
    display: inline-block;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(113,113,122,0.12);
    color: var(--muted, #6b7280);
    white-space: nowrap;
}
.reliability-chip.saved {
    background: rgba(34,197,94,0.12);
    color: #15803d;
}

/* Muted "Ran on vN (current is vM)" line in the run-detail header. */
.run-version-line {
    margin-top: 2px;
    font-size: 0.8rem;
    color: var(--muted, #6b7280);
}
.run-version-line a { color: inherit; text-decoration: underline; }

/* ── Artifact preview modal + inline table ─────────────────────────── */
.modal-card.modal-wide { max-width: 900px; width: 92vw; }
.artifact-preview-body { max-height: 65vh; overflow: auto; }
.artifact-actions { display: flex; gap: 8px; }
.preview-table-wrap { overflow-x: auto; }
.preview-table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.preview-table th, .preview-table td {
    border: 1px solid var(--border, #e5e7eb);
    padding: 4px 8px;
    text-align: left;
    white-space: nowrap;
}
.preview-table th { background: var(--chip-bg, #f3f0ff); position: sticky; top: 0; }
.preview-frame { width: 100%; height: 55vh; border: 1px solid var(--border, #e5e7eb); border-radius: 6px; background: #fff; }
.preview-pre { white-space: pre-wrap; word-break: break-word; font-size: 0.82rem; }

/* ── Sophia suggestions panel (tenant-specific templates) ──────────── */
.suggest-panel {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 16px;
}
.suggest-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.suggest-head h2 { margin: 0 0 2px; font-size: 1.1rem; }
.suggest-sparse {
    background: #fef3c7;
    border-radius: 8px;
    padding: 10px 14px;
    margin-top: 10px;
    font-size: 0.9rem;
}
.suggest-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-top: 12px;
}
.suggest-card {
    text-align: left;
    background: var(--chip-bg, #faf9ff);
    border: 1px solid var(--chip-border, #e5e0f5);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: box-shadow .12s, transform .12s;
}
.suggest-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.08); transform: translateY(-1px); }
.suggest-cat {
    align-self: flex-start;
    background: #ede9fe;
    color: #6d28d9;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .02em;
}
.suggest-title { font-weight: 600; }
.suggest-desc { color: var(--muted, #6b7280); font-size: 0.85rem; }
.suggest-cta { color: var(--qwri-accent, #6d28d9); font-size: 0.82rem; font-weight: 600; margin-top: 2px; }

/* ── Webhook trigger URLs ──────────────────────────────────────────── */
.wh-trigger { display: flex; flex-direction: column; gap: 10px; }
.wh-url-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wh-url {
    flex: 1 1 320px; min-width: 0; overflow-x: auto; white-space: nowrap;
    background: var(--qwri-surface-2, #f3f4f6); border: 1px solid var(--qwri-border, #e5e7eb);
    border-radius: 6px; padding: 6px 9px; font-size: 0.8rem;
}

/* ── Version history + recipe transparency ─────────────────────────── */
.version-current {
    background: #dcfce7; color: #15803d; border-radius: 999px;
    padding: 0 7px; font-size: 0.7rem; font-weight: 700; margin-left: 6px;
}
.version-origin {
    background: #fef3c7; color: #92400e; border-radius: 999px;
    padding: 0 7px; font-size: 0.7rem; font-weight: 600; margin-left: 6px;
}
.recipe-view { margin-top: 6px; font-size: 0.85rem; }
.recipe-view summary { cursor: pointer; color: var(--muted, #6b7280); }
.recipe-view-pre {
    white-space: pre-wrap; word-break: break-word;
    background: #f6f6f8; border-radius: 6px; padding: 10px;
    font-size: 0.8rem; margin-top: 6px; max-height: 320px; overflow: auto;
}

/* ── Compound-gate editor (AND/OR combinator between condition rows) ── */
.gate-combinator { margin: 4px 0; }
.gate-combinator select { font-size: 0.8rem; font-weight: 600; padding: 2px 6px; }

/* ── Phase 4: per-write shadow/live + tenant autonomy consent ── */
.wf-writemode { margin: 6px 0 10px; padding: 8px 10px; border-radius: 6px; border: 1px solid #e2e8f0; background: #f8fafc; }
.wf-writemode.live { border-color: #f59e0b; background: #fffbeb; }
.wf-writemode.shadow { border-color: #cbd5e1; }
.wf-writemode-badge { font-weight: 600; font-size: 0.82rem; margin-right: 8px; }
.wf-writemode.live .wf-writemode-badge { color: #b45309; }
.wf-writemode.shadow .wf-writemode-badge { color: #475569; }
.wf-writemode-hint { font-size: 0.78rem; color: #64748b; margin-top: 4px; }
.wf-autonomy { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #e2e8f0; }
.wf-ai-warning { font-size: 0.78rem; color: #92400e; background: #fffbeb; border: 1px solid #fde68a; border-radius: 6px; padding: 8px 10px; margin-top: 6px; line-height: 1.4; }

/* ── Phase 5: data pinning (builder-only fixtures) ── */
.wf-pin-row { margin: 6px 0 10px; padding: 8px 10px; border-radius: 6px; border: 1px dashed #cbd5e1; background: #f8fafc; }
.wf-pin-badge { font-weight: 600; font-size: 0.82rem; color: #475569; margin-right: 8px; }
.wf-pin-hint { font-size: 0.78rem; color: #64748b; margin-top: 4px; line-height: 1.4; }
.wf-pin-error { font-size: 0.78rem; color: #b45309; margin-top: 4px; }

/* ── Threshold trigger config ── */
.th-trigger { margin-top: 8px; padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 6px; background: #f8fafc; }
.th-compare-row { display: flex; gap: 8px; align-items: center; }
.th-compare-row select { flex: 0 0 auto; }
.th-compare-row input { flex: 1 1 auto; }

/* ── Auto-repair run-detail card (also reused for the "Run warnings" card —
   same amber "the engine flagged something, run still finished" register) ── */
.wf-repair-card { border-left: 4px solid #f59e0b; }
.wf-repair-list { margin: 6px 0 0; padding-left: 18px; font-size: 0.88rem; }
.wf-repair-list li { margin: 3px 0; }

/* ── "Fix this step" affordance under a failed step's error ── */
.wf-fix-step-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.wf-fix-step-note { margin: 0; }

/* ── Trust/attention dashboard ── */

/* Workflow header action bar — icon-led buttons.
   Scoped to this cluster so the shared .btn-secondary/.btn-primary used by the
   builder + run pages stay untouched. Three ghost nav buttons read as one calm
   cluster; the primary CTA is the only filled/coloured element so the eye lands
   on "New workflow" first. */
.workflows-header-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.workflows-header-actions .wf-head-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: var(--radius-lg, 8px);
    border: 1px solid var(--border-primary, #e5e5eb);
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #1a1a2e);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: border-color 140ms ease, background 140ms ease,
                color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.workflows-header-actions .wf-head-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-secondary, #4a4a5e);
    transition: color 140ms ease, transform 140ms ease;
}

.workflows-header-actions .wf-head-btn:hover {
    /* --accent-primary is theme-aware (dark teal in light mode, bright teal in
       dark) so the hover text/border stay legible in both themes. */
    border-color: var(--accent-primary, #0F766E);
    background: var(--accent-subtle, rgba(15, 118, 110, 0.08));
    color: var(--accent-primary, #0F766E);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm, 0 2px 4px rgba(0, 0, 0, 0.08));
}

.workflows-header-actions .wf-head-btn:hover svg {
    color: var(--accent-primary, #0F766E);
}

.workflows-header-actions .wf-head-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.workflows-header-actions .wf-head-btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus, 0 0 0 3px rgba(15, 118, 110, 0.15));
    border-color: var(--accent-primary, #0F766E);
}

/* Primary CTA — the only filled element. Solid brand teal, its own icon in
   white, a gentle lift on hover. */
/* Count badge on the "Needs attention" pill — failing + awaiting approval. */
.workflows-header-actions .wf-head-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #dc2626;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

/* Row overflow (kebab) menu — Run stays a dedicated button, the rest live here. */
.action-menu-wrap { position: relative; display: inline-block; }
.action-menu-backdrop { position: fixed; inset: 0; z-index: 40; }
.action-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 41;
    min-width: 160px;
    padding: 4px;
    border: 1px solid var(--border-primary, #e5e5eb);
    border-radius: var(--radius-lg, 8px);
    background: var(--bg-primary, #fff);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
}
.action-menu-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-primary, #1a1a2e);
    font-family: inherit;
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
}
.action-menu-item:hover { background: var(--bg-tertiary, rgba(0,0,0,0.05)); }
.action-menu-item.danger { color: #dc2626; }
.action-menu-item.danger:hover { background: rgba(220, 38, 38, 0.08); }

/* In-app confirm dialog + danger button (shared modal-card shell). */
.workflows-page .modal-card--confirm,
.wf-run-page .modal-card--confirm,
.wf-builder .modal-card--confirm { max-width: 440px; }
.workflows-page .btn-danger,
.wf-run-page .btn-danger,
.wf-builder .btn-danger {
    background: #dc2626;
    border: 1px solid #dc2626;
    color: #fff;
    border-radius: var(--radius-lg, 8px);
    padding: 8px 16px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}
.workflows-page .btn-danger:hover:not(:disabled),
.wf-run-page .btn-danger:hover:not(:disabled),
.wf-builder .btn-danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; }
.workflows-page .btn-danger:disabled,
.wf-run-page .btn-danger:disabled,
.wf-builder .btn-danger:disabled { opacity: 0.6; cursor: not-allowed; }

.workflows-header-actions .wf-head-btn--primary {
    border-color: transparent;
    background: var(--qwri-accent, #0F766E);
    color: var(--qwri-on-accent, #fff);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 118, 110, 0.28);
}

.workflows-header-actions .wf-head-btn--primary svg {
    color: currentColor;
}

.workflows-header-actions .wf-head-btn--primary:hover {
    border-color: transparent;
    background: var(--qwri-accent-ink, #115E59);
    color: var(--qwri-on-accent, #fff);
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.32);
    transform: translateY(-1px);
}

.workflows-header-actions .wf-head-btn--primary:hover svg {
    color: currentColor;
    transform: rotate(90deg);
}

@media (prefers-reduced-motion: reduce) {
    .workflows-header-actions .wf-head-btn,
    .workflows-header-actions .wf-head-btn svg {
        transition: none;
    }
    .workflows-header-actions .wf-head-btn:hover { transform: none; }
    .workflows-header-actions .wf-head-btn--primary:hover svg { transform: none; }
}
.wf-attention-page { max-width: 900px; margin: 0 auto; }
.wf-attn-list { list-style: none; margin: 8px 0 0; padding: 0; }
.wf-attn-list li { padding: 7px 0; border-bottom: 1px solid #f1f5f9; font-size: 0.9rem; }
.wf-attn-list li:last-child { border-bottom: none; }
.wf-attn-reason { color: #475569; margin-left: 4px; }
.wf-attn-when { color: #94a3b8; font-size: 0.8rem; margin-left: 8px; }
.wf-count { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 10px; background: #e2e8f0; color: #334155; font-size: 0.8rem; font-weight: 600; margin-left: 6px; }
.wf-allclear h2 { color: #16a34a; }

/* ── Multi-workflow planner ── */
.wf-plan-page { max-width: 820px; margin: 0 auto; }
.wf-plan-page textarea { width: 100%; }
.wf-plan-actions { margin-top: 8px; }
.wf-plan-head { display: flex; justify-content: space-between; align-items: center; }
.wf-plan-outcome { color: #334155; font-weight: 500; }
.wf-plan-blocked { color: #b45309; font-size: 0.85rem; }
.wf-plan-steps { list-style: decimal; padding-left: 22px; margin: 10px 0 0; }
.wf-plan-steps li { padding: 8px 0; border-bottom: 1px solid #f1f5f9; }
.wf-plan-steps li.running { background: #fffbeb; }
.wf-plan-steps li.done .wf-plan-step-title strong { color: #16a34a; }
.wf-plan-step-title { display: flex; gap: 8px; align-items: center; }
.wf-plan-write { font-size: 0.72rem; font-weight: 600; color: #b45309; background: #fef3c7; border-radius: 4px; padding: 1px 6px; }
.wf-plan-tag { font-size: 0.78rem; color: #64748b; }
.wf-plan-tag.ok { color: #16a34a; }
.wf-plan-reason { font-size: 0.85rem; color: #475569; margin-top: 2px; }
.wf-plan-inputs { font-size: 0.78rem; color: #94a3b8; margin-top: 2px; }
.wf-plan-error { color: #dc2626; font-size: 0.85rem; margin-top: 3px; }

/* ── Datasets page (client-maintained sheets feeding file_input steps) ── */
.datasets-page .register-panel {
    border: 1px solid var(--border-default, #d4d4d8);
    border-radius: 8px;
    padding: 16px 18px;
    margin-bottom: var(--space-5);
    background: var(--bg-secondary, #fafafa);
}
.datasets-page .register-panel h2 { margin: 0 0 4px; font-size: 1.05rem; }
.datasets-page .register-form { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; align-items: flex-end; }
.datasets-page .register-form label {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 0.82rem; font-weight: 600; color: var(--text-secondary);
    min-width: 220px; flex: 1;
}
.datasets-page .register-form input {
    padding: 8px 10px; border: 1px solid var(--border-default, #d4d4d8);
    border-radius: 6px; font-size: 0.9rem; font-weight: 400;
}
.datasets-page .register-actions { display: flex; gap: 8px; }

.dataset-list { display: flex; flex-direction: column; gap: 12px; }
.dataset-card {
    border: 1px solid var(--border-default, #e4e4e7);
    border-radius: 8px;
    padding: 14px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
    justify-content: space-between;
    background: var(--bg-primary, #fff);
}
.dataset-card-main { flex: 1 1 380px; min-width: 0; }
.dataset-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dataset-name { font-weight: 600; color: var(--text-primary); }
.dataset-slug {
    font-size: 0.78rem; background: var(--bg-tertiary, #f4f4f5);
    border-radius: 4px; padding: 2px 6px; color: var(--text-secondary);
}
.dataset-desc { margin: 4px 0 0; color: var(--text-secondary); font-size: 0.88rem; }
.dataset-meta {
    display: flex; flex-wrap: wrap; gap: 4px 14px;
    margin-top: 6px; font-size: 0.82rem; color: var(--text-tertiary, #71717a);
}
.dataset-sophia-row {
    display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center;
    margin-top: 8px; font-size: 0.85rem;
}
.dataset-sophia-row .sophia-toggle {
    display: inline-flex; gap: 6px; align-items: center; cursor: pointer;
    color: var(--text-secondary, #4a4a5e); font-weight: 500;
}
.dataset-sophia-row input[type="date"] {
    padding: 5px 8px; font-size: 0.82rem;
    border: 1px solid var(--border-primary, #d4d4d8); border-radius: 6px;
    background: var(--bg-primary, #fff); color: var(--text-primary, #1a1a2e);
}
.dataset-overlap-warning {
    margin: 6px 0 0; font-size: 0.82rem;
    color: var(--warning-text, #92400e);
    background: var(--warning-bg, #fef3c7);
    border: 1px solid var(--warning-border, #fcd34d);
    border-radius: 6px; padding: 6px 10px;
}
.dataset-card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dataset-card-actions .sheet-input {
    width: 120px; padding: 7px 9px; font-size: 0.82rem;
    border: 1px solid var(--border-default, #d4d4d8); border-radius: 6px;
}
.dataset-card-actions .upload-btn { position: relative; overflow: hidden; display: inline-block; }
.dataset-card-actions .upload-btn input[type="file"] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%;
}
.dataset-card-actions .upload-btn.disabled { opacity: 0.6; pointer-events: none; }
.datasets-page .btn-danger {
    background: none; border: 1px solid #fca5a5; color: #b91c1c;
    padding: 8px 12px; border-radius: 6px; font-size: 0.85rem; cursor: pointer;
}
.datasets-page .btn-danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.datasets-page .btn-danger:disabled { opacity: 0.6; cursor: not-allowed; }

.datasets-page .badge {
    font-size: 0.74rem; font-weight: 600; border-radius: 10px; padding: 2px 8px;
}
.datasets-page .badge-fresh { background: #dcfce7; color: #166534; }
.datasets-page .badge-stale { background: #fef3c7; color: #92400e; }
.datasets-page .badge-missing { background: #fee2e2; color: #b91c1c; }

.dataset-preview { flex-basis: 100%; border-top: 1px solid var(--border-light, #f1f5f9); padding-top: 10px; }
.dataset-preview .preview-scroll { overflow-x: auto; }
.dataset-preview table { border-collapse: collapse; font-size: 0.82rem; min-width: 100%; }
.dataset-preview th, .dataset-preview td {
    border: 1px solid var(--border-light, #e4e4e7);
    padding: 4px 8px; text-align: left; white-space: nowrap;
}
.dataset-preview th { background: var(--bg-tertiary, #f4f4f5); font-weight: 600; }
.datasets-page .muted { color: var(--text-tertiary, #94a3b8); }
.datasets-page .small { font-size: 0.84rem; }

/* ── Dataset chips on the workflows list (file_input staleness at a glance) ── */
.wf-dataset-chip {
    display: inline-block; margin-top: 4px; margin-right: 6px;
    font-size: 0.76rem; font-weight: 600; border-radius: 10px; padding: 2px 8px;
    text-decoration: none;
}
.wf-dataset-chip.ok { background: #dcfce7; color: #166534; }
.wf-dataset-chip.warn { background: #fef3c7; color: #92400e; }
.wf-dataset-chip.bad { background: #fee2e2; color: #b91c1c; }

/* file_input step-type badge colour in the builder step list */
.step-type-badge.step-type-file_input { background: #ecfeff; color: #0e7490; }

/* ── Dataset column-mapping dialog ── */
.datasets-page .mapping-panel {
    border: 1px solid #fbbf24; border-radius: 8px; background: #fffbeb;
    padding: 16px 18px; margin-bottom: var(--space-5);
}
.datasets-page .mapping-panel h2 { margin: 0 0 4px; font-size: 1.05rem; }
.mapping-table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 0.88rem; }
.mapping-table th, .mapping-table td {
    border: 1px solid #fde68a; padding: 6px 10px; text-align: left; vertical-align: top;
}
.mapping-table th { background: #fef3c7; }
.mapping-choices { display: flex; flex-wrap: wrap; gap: 6px; }
.mapping-choice {
    display: inline-flex; align-items: center; gap: 5px;
    border: 1px solid var(--border-default, #d4d4d8); border-radius: 12px;
    padding: 3px 9px; font-size: 0.8rem; cursor: pointer; background: #fff;
}
.mapping-choice.picked { border-color: #0e7490; background: #ecfeff; color: #0e7490; font-weight: 600; }
.mapping-choice input { margin: 0; }
.mapping-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Flow diagram (WorkflowFlowDiagram component) ─────────────────────────
   HTML nodes absolutely positioned over an SVG edge layer. Fixed node
   geometry (200x76) keeps layout computable in C# without measurement —
   the CSS width MUST stay in sync with WorkflowFlowDiagram.NodeW. */
.wf-diagram-shell { outline: none; }
.wf-diagram-shell.wf-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--bg-primary, #fff);
    padding: 16px;
    display: flex;
    flex-direction: column;
}
.wf-diagram-shell.wf-fullscreen .wf-diagram-wrap { flex: 1; }

.wf-diagram-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
}
.wf-diagram-toolbar button {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-default, #d4d4d8);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 0.78rem;
    cursor: pointer;
    color: var(--text-secondary, #52525b);
    line-height: 1.4;
}
.wf-diagram-toolbar button:hover { border-color: #6366f1; color: #4f46e5; }
.wf-diagram-toolbar .wf-zoom-label { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
.wf-diagram-toolbar .wf-toolbar-gap { flex: 1; }

.wf-diagram-wrap { overflow: auto; border-radius: 12px; }
.wf-diagram-scale { margin: 0 auto; }
.wf-diagram-canvas {
    position: relative;
    /* The workbench surface: nodes sit ON something, not on the page. */
    background-color: var(--bg-secondary, #fafafa);
    background-image: radial-gradient(circle,
        color-mix(in srgb, var(--border-default, #d4d4d8) 55%, transparent) 1px,
        transparent 1px);
    background-size: 20px 20px;
    border-radius: 12px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}
.wf-diagram-edges { position: absolute; inset: 0; pointer-events: none; }

/* Empty builder canvas: preview the shape of what's about to exist. */
.wf-empty-canvas {
    background-color: var(--bg-secondary, #fafafa);
    background-image: radial-gradient(circle,
        color-mix(in srgb, var(--border-default, #d4d4d8) 55%, transparent) 1px,
        transparent 1px);
    background-size: 20px 20px;
    border-radius: 12px;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.wf-empty-node {
    width: 200px;
    height: 76px;
    box-sizing: border-box;
    border: 2px dashed var(--border-default, #d4d4d8);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary, #a1a1aa);
    font-size: 0.85rem;
    font-weight: 600;
}
.wf-empty-hint { margin: 0; font-size: 0.8rem; color: var(--text-tertiary, #a1a1aa); text-align: center; }

/* Edges: each is a <g> holding a port dot at the source, the line, and a
   filled arrowhead at the target — all taking --wf-edge-color. Data edges
   inherit their SOURCE step's accent (wf-src-*), so you can follow what kind
   of output a line carries; gates stay semantic amber-dashed. */
.wf-edge-g { --wf-edge-color: var(--text-tertiary, #a1a1aa); }
.wf-edge-line {
    fill: none;
    stroke: var(--wf-edge-color);
    stroke-width: 2;
    stroke-linecap: round;
    opacity: 0.8;
    filter: drop-shadow(0 0 2px color-mix(in srgb, var(--wf-edge-color) 40%, transparent));
}
.wf-edge-head { fill: var(--wf-edge-color); stroke: none; opacity: 0.95; }
.wf-edge-port { fill: var(--wf-edge-color); opacity: 0.95; }

/* Live run: data visibly flows along edges feeding the running step. Dashes
   march in the path's draw direction (source → target); the class is derived
   from real run state every render, never a fire-once trigger. */
.wf-edge-g.wf-edge-active .wf-edge-line {
    stroke-dasharray: 6 6;
    stroke-width: 2.5;
    opacity: 1;
    animation: wf-edge-flow 0.6s linear infinite;
}
@keyframes wf-edge-flow { to { stroke-dashoffset: -12; } }

/* Arrival snap when the fed step completes: the wire flashes once. */
.wf-edge-g.wf-edge-arrived .wf-edge-line { animation: wf-edge-arrive 0.5s ease-out 1; }
@keyframes wf-edge-arrive {
    0%   { stroke-width: 4; filter: drop-shadow(0 0 5px var(--wf-edge-color)); }
    100% { stroke-width: 2; }
}

/* Source-accent hues for data edges (mirror the .wf-type-* accents). */
.wf-src-api_call      { --wf-edge-color: #4f46e5; }
.wf-src-transform     { --wf-edge-color: #9333ea; }
.wf-src-bulk_export   { --wf-edge-color: #16a34a; }
.wf-src-write_action  { --wf-edge-color: #d97706; }
.wf-src-email         { --wf-edge-color: #0284c7; }
.wf-src-verify        { --wf-edge-color: #0d9488; }
.wf-src-ai_analysis   { --wf-edge-color: #c026d3; }
.wf-src-loop          { --wf-edge-color: #ea580c; }
.wf-src-sub_workflow  { --wf-edge-color: #475569; }
.wf-src-file_input    { --wf-edge-color: #0e7490; }
.wf-src-write_dataset { --wf-edge-color: #65a30d; }

/* Kind overrides (two-class specificity beats the wf-src-* accent). */
.wf-edge-g.wf-edge-gate { --wf-edge-color: #d97706; }
.wf-edge-g.wf-edge-gate .wf-edge-line { stroke-dasharray: 6 5; }
.wf-edge-g.wf-edge-input { --wf-edge-color: #94a3b8; }

/* The fan-out boundary. Drawn heavier than a data edge and in its own colour
   because it is a different KIND of relationship: not "this data feeds that
   step" but "everything below here runs once per item, in its own child run".
   Without it the per-item half has no incoming edge at all and reads as a
   second, unrelated workflow. */
.wf-edge-g.wf-edge-fanout { --wf-edge-color: #7c3aed; }
.wf-edge-g.wf-edge-fanout .wf-edge-line {
    stroke-width: 3;
    stroke-dasharray: 2 6;
    stroke-linecap: round;
}

.wf-peritem-band {
    position: absolute;
    width: 200px;
    box-sizing: border-box;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #7c3aed;
    pointer-events: none;
}
/* A left rail down the per-item nodes, so the phase reads as a group rather
   than as one flagged step. */
.wf-node.wf-per-item { border-left: 3px solid #7c3aed; }


.wf-node {
    position: absolute;
    width: 200px;
    height: 76px;
    box-sizing: border-box;
    background: var(--bg-primary, #fff);
    background: color-mix(in srgb, var(--wf-accent, #6366f1) 4%, var(--bg-primary, #fff));
    border: 1.5px solid var(--border-default, #d4d4d8);
    border-color: color-mix(in srgb, var(--wf-accent, #6366f1) 40%, var(--border-default, #d4d4d8));
    border-top: 3px solid var(--wf-accent, var(--border-default, #d4d4d8));
    border-radius: 10px;
    padding: 7px 10px 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 3px;
    /* Ambient depth at rest — hover only intensifies it. */
    box-shadow: 0 1px 2px rgba(0,0,0,0.06), 0 1px 1px rgba(0,0,0,0.04);
    transition: box-shadow 0.12s ease, transform 0.12s ease, opacity 0.15s ease;
}
.wf-node:hover {
    box-shadow: 0 6px 16px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08);
    transform: translateY(-2px);
    z-index: 30;
}
.wf-node:focus-visible { outline: 2px solid var(--wf-accent, #6366f1); outline-offset: 2px; }
.wf-node.selected {
    outline: none;
    box-shadow: 0 0 0 2px var(--wf-accent, #6366f1), 0 8px 20px rgba(0,0,0,0.14);
    transform: translateY(-2px);
    z-index: 20;
}

/* Full-bleed tinted band behind the type header — this is what makes each
   step type read at a glance. */
.wf-node-head {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    margin: -7px -10px 0;
    padding: 4px 10px 3px;
    background: rgba(99,102,241,0.12);
    background: color-mix(in srgb, var(--wf-accent, #6366f1) 15%, transparent);
    border-radius: 8px 8px 0 0;
}
.wf-node-icon-chip {
    width: 20px;
    height: 20px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: color-mix(in srgb, var(--wf-accent, #6366f1) 20%, transparent);
}
.wf-node-icon { width: 13px; height: 13px; flex: none; color: var(--wf-accent, #6366f1); }
.wf-node-type {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--wf-accent, #6366f1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wf-node-dot {
    width: 7px; height: 7px; flex: none; margin-left: auto;
    border-radius: 50%; background: #4f46e5;
    animation: wf-dot-blink 1s ease-in-out infinite;
}
@keyframes wf-dot-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.wf-node-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary, #18181b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wf-node-foot { display: flex; align-items: center; gap: 5px; min-width: 0; }
.wf-node-outkey {
    font-size: 0.68rem;
    color: var(--text-secondary, #52525b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.wf-node-badge {
    flex: none;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 0 5px;
    border-radius: 999px;
    line-height: 1.5;
}
.wf-node-badge.badge-gate     { background: rgba(245,158,11,0.18); color: #d97706; }
.wf-node-badge.badge-approval { background: rgba(113,113,122,0.15); color: var(--text-secondary, #52525b); }
.wf-node-badge.badge-awaiting {
    background: rgba(245,158,11,0.18); color: #d97706;
    text-transform: uppercase;
    animation: wf-dot-blink 1.4s ease-in-out infinite;
}
.wf-node-time { flex: none; margin-left: auto; font-size: 0.64rem; color: var(--text-tertiary, #a1a1aa); }

/* Inputs pseudo-node: run-time inputs feeding the first consuming steps. */
.wf-node.wf-node-inputs {
    border: 1.5px dashed var(--border-default, #d4d4d8);
    border-radius: 999px;
    cursor: default;
    align-items: center;
    justify-content: center;
    text-align: center;
}
.wf-node.wf-node-inputs:hover { box-shadow: none; transform: none; }
.wf-node.wf-node-inputs .wf-node-outkey { max-width: 180px; }

/* Per-type accents — the CSS half of the WorkflowStepVisuals registry.
   Hues match the existing .step-type-badge colors where those exist. */
.wf-type-api_call      { --wf-accent: #4f46e5; }
.wf-type-transform     { --wf-accent: #9333ea; }
.wf-type-bulk_export   { --wf-accent: #16a34a; }
.wf-type-write_action  { --wf-accent: #d97706; }
.wf-type-email         { --wf-accent: #0284c7; }
.wf-type-whatsapp      { --wf-accent: #25d366; }
.wf-type-verify        { --wf-accent: #0d9488; }
.wf-type-ai_analysis   { --wf-accent: #c026d3; }
.wf-type-loop          { --wf-accent: #ea580c; }
.wf-type-sub_workflow  { --wf-accent: #475569; }
.wf-type-file_input    { --wf-accent: #0e7490; }
.wf-type-write_dataset { --wf-accent: #65a30d; }
.wf-type-unknown       { --wf-accent: var(--text-tertiary, #a1a1aa); }

/* Run-mode status. The type accent keeps the top edge + header band; status
   colors the remaining border + fill so both read at once. */
.wf-status-pending   { opacity: 0.55; filter: saturate(0.4); }
.wf-status-running   { border-color: #4f46e5; background: rgba(99,102,241,0.08); animation: wf-pulse 1.6s ease-in-out infinite; }
.wf-status-completed { border-color: rgba(34,197,94,0.7); background: rgba(34,197,94,0.10); }
.wf-status-failed    { border-color: #ef4444; background: rgba(239,68,68,0.10); }
.wf-status-skipped   { opacity: 0.55; border-style: dashed; }

/* Running glow biased toward the bottom edge — primes the eye for where the
   output is about to hand off downstream. */
@keyframes wf-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,0.35), 0 2px 2px -2px rgba(99,102,241,0); }
    50%      { box-shadow: 0 0 0 6px rgba(99,102,241,0), 0 8px 12px -2px rgba(99,102,241,0.4); }
}

/* One-shot completion/failure choreography. The wf-just-finished class is
   derived from a ~1.5s server-state diff window (run page), so these fire
   exactly once per transition and can never desync from real state. */
.wf-status-completed.wf-just-finished { animation: wf-land 0.6s ease-out 1; }
@keyframes wf-land {
    0%   { box-shadow: 0 0 0 10px rgba(34,197,94,0.35); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
.wf-status-failed.wf-just-finished { animation: wf-shake 0.3s ease-in-out 1; }
@keyframes wf-shake {
    0%, 100% { transform: none; }
    25%      { transform: translateX(-3px); }
    75%      { transform: translateX(3px); }
}
.wf-node-check {
    position: absolute;
    top: 4px;
    right: 8px;
    width: 15px;
    height: 15px;
    fill: none;
    stroke: #16a34a;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.wf-node-check path {
    stroke-dasharray: 26;
    stroke-dashoffset: 26;
    animation: wf-check-draw 0.35s ease-out 0.1s forwards;
}
@keyframes wf-check-draw { to { stroke-dashoffset: 0; } }

/* Steps header: three children (title, view toggle, add-step cluster) must
   wrap instead of squeezing into each other on narrow cards. */
.steps-card .section-header { flex-wrap: wrap; gap: 8px 14px; }
.steps-card .section-header h2 { flex: none; }
.steps-card .add-step-cluster { margin-left: auto; justify-content: flex-end; }

/* List <-> Diagram segmented toggle (builder Steps header). */
.wf-view-toggle { display: inline-flex; border: 1px solid var(--border-default, #d4d4d8); border-radius: 6px; overflow: hidden; }
.wf-view-toggle button {
    background: transparent;
    border: none;
    padding: 4px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--text-secondary, #52525b);
}
.wf-view-toggle button + button { border-left: 1px solid var(--border-default, #d4d4d8); }
.wf-view-toggle button.active {
    background: rgba(99,102,241,0.12);
    color: #4f46e5;
    font-weight: 600;
}

/* Per-step detail panel under the run-detail diagram — reads as a callout
   connected to the clicked node via its accent (house pattern: accent left
   border + tint, same as .bld-pickup-banner / .bld-note). */
.wf-step-detail-panel {
    margin-top: 14px;
    border-top: 1px solid var(--border-default, #e4e4e7);
    border-left: 3px solid var(--wf-accent, var(--border-default, #e4e4e7));
    padding: 12px 0 0 12px;
}
.wf-step-detail-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wf-step-detail-header .wf-node-icon { width: 16px; height: 16px; position: static; }
.wf-step-detail-header h3 { margin: 0; font-size: 0.95rem; }
.wf-step-detail-close {
    margin-left: auto;
    background: transparent;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text-tertiary, #a1a1aa);
}
.wf-step-detail-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 28px;
    margin-top: 10px;
}
.wf-step-detail-grid .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-tertiary, #a1a1aa);
    margin-bottom: 2px;
}
.wf-step-skip-reason {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary, #52525b);
}
.wf-diagram-hint { margin-top: 8px; font-size: 0.78rem; color: var(--text-tertiary, #a1a1aa); }

/* Builder: focus target for diagram click-to-edit scroll. */
.step-card:focus { outline: none; }

/* Builder diagram — node data-preview ("peek") panel. Reuses the
   .wf-step-detail-panel shell from run-detail for visual consistency; only
   the body/footer below are peek-specific. */
.wf-peek-body { margin-top: 10px; max-height: 340px; overflow: auto; }
.wf-peek-body .preview-table-wrap { max-height: 300px; }
.wf-peek-foot {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-default, #e4e4e7);
}
.wf-peek-foot .muted.small { margin-right: auto; }

/* Builder diagram — sticky notes strip. Documentation only, zero engine
   impact: no x/y, the diagram is auto-layout so notes render in a strip
   rather than pinned to canvas coordinates. */
.wf-notes-strip { margin-bottom: 10px; }
.wf-notes-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.wf-notes-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-tertiary, #a1a1aa);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.wf-notes-list { display: flex; flex-wrap: wrap; gap: 8px; }
.wf-note-chip {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    width: 220px;
    background: var(--warning-bg, rgba(245, 158, 11, 0.10));
    border: 1px solid var(--warning-border, rgba(245, 158, 11, 0.45));
    border-radius: 8px;
    padding: 8px;
}
.wf-note-text {
    flex: 1;
    resize: vertical;
    border: none;
    background: transparent;
    font-size: 0.82rem;
    color: var(--warning-text, #92400e);
    font-family: inherit;
    padding: 0;
}
.wf-note-text:focus { outline: none; }
.wf-note-delete { flex: none; width: 22px; height: 22px; border: none; color: var(--warning-text, #92400e); }

/* Missing list-badge colors, aligned with the diagram accents. */
.step-type-badge.step-type-email         { background: rgba(2,132,199,0.14);  color: #0284c7; }
.step-type-badge.step-type-whatsapp      { background: rgba(37,211,102,0.16); color: #16a34a; }
.step-type-badge.step-type-verify        { background: rgba(13,148,136,0.14); color: #0d9488; }
.step-type-badge.step-type-ai_analysis   { background: rgba(192,38,211,0.14); color: #c026d3; }
.step-type-badge.step-type-loop          { background: rgba(234,88,12,0.14);  color: #ea580c; }
.step-type-badge.step-type-sub_workflow  { background: rgba(100,116,139,0.16); color: #64748b; }
.step-type-badge.step-type-write_dataset { background: rgba(101,163,13,0.15); color: #65a30d; }

/* Hover focus: dim everything not on the hovered node's upstream/downstream
   path. Placed after the status rules so dimming wins on the same element. */
.wf-node.wf-dim { opacity: 0.22; }
.wf-edge-g.wf-dim { opacity: 0.12; }
.wf-edge-g { transition: opacity 0.15s ease; }

/* Rich hover popover (replaces the sluggish native title tooltip). */
.wf-node-popover {
    position: absolute;
    left: 50%;
    top: calc(100% + 8px);
    transform: translateX(-50%);
    width: max-content;
    max-width: 260px;
    max-height: 320px;
    overflow-y: auto;
    background: #23283a;
    color: #f1f3f9;
    border-radius: 8px;
    padding: 8px 11px;
    font-size: 0.74rem;
    line-height: 1.45;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.12s ease 0.15s;
    /* Hover-only tooltip by default (never steal clicks from whatever it
       overlaps) — .wf-pop-detail below re-enables it locally so the
       expandable "Details" affordance is actually clickable. */
    pointer-events: none;
    z-index: 40;
    text-align: left;
}
.wf-node-popover.above { top: auto; bottom: calc(100% + 8px); }
.wf-node:hover .wf-node-popover { opacity: 1; visibility: visible; }
.wf-pop-title { font-weight: 700; font-size: 0.78rem; margin-bottom: 2px; }
.wf-pop-row { color: #c3c9da; }
.wf-pop-row code { color: #f1f3f9; background: rgba(255,255,255,0.12); border-radius: 3px; padding: 0 3px; font-size: 0.7rem; }
.wf-pop-error { color: #fca5a5; }

/* Expandable full error inside the popover — the headline above stays
   truncated; this reveals the raw error a retail owner would never need,
   but support might. Always dark (the popover itself isn't theme-aware),
   so no separate dark-mode rule is needed. */
.wf-pop-detail { margin-top: 4px; pointer-events: auto; }
.wf-pop-detail summary { cursor: pointer; color: #9aa3b8; font-size: 0.72rem; }
.wf-pop-detail summary:hover { color: #c3c9da; }
.wf-pop-detail-pre {
    margin: 4px 0 0;
    padding: 6px 8px;
    background: rgba(0,0,0,0.25);
    border-radius: 4px;
    font-size: 0.7rem;
    line-height: 1.4;
    color: #e4e6ef;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 160px;
    overflow-y: auto;
}

/* Dark theme: light-mode 600-weight accents go muddy on a dark canvas —
   bump each one step lighter for both nodes and edges. */
[data-theme="dark"] .wf-type-api_call,      [data-theme="dark"] .wf-src-api_call      { --wf-accent: #6366f1; --wf-edge-color: #6366f1; }
[data-theme="dark"] .wf-type-transform,     [data-theme="dark"] .wf-src-transform     { --wf-accent: #a855f7; --wf-edge-color: #a855f7; }
[data-theme="dark"] .wf-type-bulk_export,   [data-theme="dark"] .wf-src-bulk_export   { --wf-accent: #22c55e; --wf-edge-color: #22c55e; }
[data-theme="dark"] .wf-type-write_action,  [data-theme="dark"] .wf-src-write_action  { --wf-accent: #f59e0b; --wf-edge-color: #f59e0b; }
[data-theme="dark"] .wf-type-email,         [data-theme="dark"] .wf-src-email         { --wf-accent: #0ea5e9; --wf-edge-color: #0ea5e9; }
[data-theme="dark"] .wf-type-whatsapp,      [data-theme="dark"] .wf-src-whatsapp      { --wf-accent: #34d399; --wf-edge-color: #34d399; }
[data-theme="dark"] .wf-type-verify,        [data-theme="dark"] .wf-src-verify        { --wf-accent: #14b8a6; --wf-edge-color: #14b8a6; }
[data-theme="dark"] .wf-type-ai_analysis,   [data-theme="dark"] .wf-src-ai_analysis   { --wf-accent: #d946ef; --wf-edge-color: #d946ef; }
[data-theme="dark"] .wf-type-loop,          [data-theme="dark"] .wf-src-loop          { --wf-accent: #f97316; --wf-edge-color: #f97316; }
[data-theme="dark"] .wf-type-sub_workflow,  [data-theme="dark"] .wf-src-sub_workflow  { --wf-accent: #94a3b8; --wf-edge-color: #94a3b8; }
[data-theme="dark"] .wf-type-file_input,    [data-theme="dark"] .wf-src-file_input    { --wf-accent: #06b6d4; --wf-edge-color: #06b6d4; }
[data-theme="dark"] .wf-type-write_dataset, [data-theme="dark"] .wf-src-write_dataset { --wf-accent: #84cc16; --wf-edge-color: #84cc16; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .wf-type-api_call,      :root:not([data-theme]) .wf-src-api_call      { --wf-accent: #6366f1; --wf-edge-color: #6366f1; }
    :root:not([data-theme]) .wf-type-transform,     :root:not([data-theme]) .wf-src-transform     { --wf-accent: #a855f7; --wf-edge-color: #a855f7; }
    :root:not([data-theme]) .wf-type-bulk_export,   :root:not([data-theme]) .wf-src-bulk_export   { --wf-accent: #22c55e; --wf-edge-color: #22c55e; }
    :root:not([data-theme]) .wf-type-write_action,  :root:not([data-theme]) .wf-src-write_action  { --wf-accent: #f59e0b; --wf-edge-color: #f59e0b; }
    :root:not([data-theme]) .wf-type-email,         :root:not([data-theme]) .wf-src-email         { --wf-accent: #0ea5e9; --wf-edge-color: #0ea5e9; }
    :root:not([data-theme]) .wf-type-whatsapp,      :root:not([data-theme]) .wf-src-whatsapp      { --wf-accent: #34d399; --wf-edge-color: #34d399; }
    :root:not([data-theme]) .wf-type-verify,        :root:not([data-theme]) .wf-src-verify        { --wf-accent: #14b8a6; --wf-edge-color: #14b8a6; }
    :root:not([data-theme]) .wf-type-ai_analysis,   :root:not([data-theme]) .wf-src-ai_analysis   { --wf-accent: #d946ef; --wf-edge-color: #d946ef; }
    :root:not([data-theme]) .wf-type-loop,          :root:not([data-theme]) .wf-src-loop          { --wf-accent: #f97316; --wf-edge-color: #f97316; }
    :root:not([data-theme]) .wf-type-sub_workflow,  :root:not([data-theme]) .wf-src-sub_workflow  { --wf-accent: #94a3b8; --wf-edge-color: #94a3b8; }
    :root:not([data-theme]) .wf-type-file_input,    :root:not([data-theme]) .wf-src-file_input    { --wf-accent: #06b6d4; --wf-edge-color: #06b6d4; }
    :root:not([data-theme]) .wf-type-write_dataset, :root:not([data-theme]) .wf-src-write_dataset { --wf-accent: #84cc16; --wf-edge-color: #84cc16; }
}

/* Detail panel opens like a callout, not a page reflow. */
.wf-step-detail-panel { animation: wf-panel-in 0.15s ease-out; }
@keyframes wf-panel-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}

/* Print / save-as-PDF: just the diagram, unclipped and unscaled chrome. */
@media print {
    .wf-diagram-toolbar, .wf-view-toggle, .add-step-cluster { display: none !important; }
    .wf-diagram-wrap { overflow: visible !important; }
    .wf-node-popover { display: none !important; }
}

/* ── Pre-flight readiness panel (trigger modal) ─────────────────────────
   Green headline = confidence moment; red = the failure that DIDN'T happen
   mid-demo. Warns stay amber and never block Run. */
.readiness-panel {
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 14px;
    font-size: 0.85rem;
    border: 1px solid var(--border-color, #d5d9e2);
}
.readiness-panel.ready { border-color: rgba(34,197,94,0.45); background: rgba(34,197,94,0.07); }
.readiness-panel.not-ready { border-color: rgba(239,68,68,0.5); background: rgba(239,68,68,0.07); }
.readiness-headline { font-weight: 600; margin-bottom: 6px; }
.readiness-panel.ready .readiness-headline { color: #16a34a; }
.readiness-panel.not-ready .readiness-headline { color: #dc2626; }
.readiness-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.readiness-item { display: flex; align-items: baseline; gap: 6px; }
.readiness-icon { width: 1em; text-align: center; }
.readiness-item.ok .readiness-icon { color: #16a34a; }
.readiness-item.warn .readiness-icon { color: #d97706; }
.readiness-item.fail .readiness-icon { color: #dc2626; }
.readiness-item.fail .readiness-label { font-weight: 600; }
.readiness-detail { color: var(--muted-color, #6b7280); font-size: 0.8rem; }
[data-theme="dark"] .readiness-panel.ready { background: rgba(34,197,94,0.12); }
[data-theme="dark"] .readiness-panel.not-ready { background: rgba(239,68,68,0.12); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .readiness-panel.ready { background: rgba(34,197,94,0.12); }
    :root:not([data-theme]) .readiness-panel.not-ready { background: rgba(239,68,68,0.12); }
}

/* Editable-before-approve payload box */
.approval-edit { margin: 8px 0; }
.approval-edit summary { cursor: pointer; font-size: 0.85rem; color: var(--muted-color, #6b7280); }
.approval-edit-box {
    width: 100%;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.78rem;
    line-height: 1.45;
    border: 1px solid var(--border-color, #d5d9e2);
    border-radius: 6px;
    padding: 8px;
    margin-top: 6px;
    background: var(--input-bg, transparent);
    color: inherit;
    resize: vertical;
}

/* ── "vs baseline" verdict in the sample-run modal ──────────────────────
   Green when the run reproduces the approved output, amber when it
   doesn't. Amber, not red: a difference is something to look at, not a
   failure — the run itself succeeded. */
.baseline-verdict {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.45;
}
.baseline-verdict .muted { color: inherit; opacity: 0.8; font-size: 0.8rem; }
.baseline-verdict.match {
    background: rgba(34, 197, 94, 0.10);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #15803d;
}
.baseline-verdict.mismatch {
    background: rgba(245, 158, 11, 0.10);
    border: 1px solid rgba(245, 158, 11, 0.45);
    color: #92400e;
}
.baseline-diff-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--text-primary);
}
.baseline-diff-table th,
.baseline-diff-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border-light, #e4e4e7);
    vertical-align: top;
}
.baseline-diff-table thead th { font-weight: 600; opacity: 0.75; }
.baseline-diff-table tbody tr:last-child td { border-bottom: none; }

/* ── Print documents panel (run detail) ───────────────────────── */
.print-doc-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 10px 0 14px;
}
.print-doc-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border: 1px solid var(--border-color, #d0d5dd);
    border-radius: 999px;
    background: var(--surface-color, #f9fafb);
    font-size: 0.8rem;
}
.print-doc-chip::before { content: "📄"; }
.print-actions { display: flex; justify-content: flex-start; }
.print-result { margin-top: 10px; }

/* Deferred push-notification offer on the run page */
.push-offer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin: var(--space-3) 0;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.push-offer-actions {
    display: flex;
    gap: var(--space-2);
}

/* ── Recipient pickers (email + WhatsApp step editors) ──────────────────
   These classes were used by both editors but never had any styling, so
   every person ran into the next one as unstyled inline spans — a wall of
   names and addresses with no row a cursor could land on. Each recipient is
   now a real row: a scrollable box, one person per line, a visible hit area,
   and the name given priority over the address it used to compete with. */

.recipient-checklist {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 260px;
    overflow-y: auto;
    padding: var(--space-1, 4px);
    background: var(--bg-subtle, #fafafa);
    border: 1px solid var(--border-light, #e4e4e7);
    border-radius: var(--radius-md, 8px);
}

.recipient-check {
    display: flex;
    align-items: baseline;
    gap: var(--space-2, 8px);
    padding: 7px 10px;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    line-height: 1.35;
}

.recipient-check:hover {
    background: var(--bg-primary, #fff);
}

.recipient-check input[type="checkbox"] {
    flex: 0 0 auto;
    margin: 0;
    cursor: pointer;
}

.recipient-check-name {
    flex: 0 1 auto;
    font-weight: 500;
    color: var(--text-primary, #18181b);
}

/* The address is context, not the thing being chosen: it sits to the right,
   smaller and quieter, and truncates rather than wrapping a row onto two
   lines. Absent entirely on the WhatsApp picker, where it only ever invited
   choosing someone for the wrong channel. */
.recipient-check-email {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
    font-size: var(--text-xs, 0.78rem);
    color: var(--text-muted, #71717a);
}

.recipient-checklist-note {
    margin-top: var(--space-2, 8px);
}

/* Sample-run dialog: the produced report, and what activating will do */
.sample-output-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
}
.sample-output-head h3 { margin: 0; }
.sample-output-picker { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.sample-output-picker .bld-chip.active { border-color: var(--qwri-accent, #6366f1); font-weight: 600; }
.sample-output-text { max-height: 46vh; overflow: auto; }
.activate-summary {
    margin-top: 14px;
    padding: 10px 14px;
    border-radius: 6px;
    border: 1px solid var(--border-color, #e4e4e7);
    background: var(--bg-tertiary, rgba(0,0,0,0.03));
    font-size: 0.88rem;
}
.activate-summary-title { font-weight: 600; margin-bottom: 4px; }
.activate-summary ul { margin: 0 0 0 18px; padding: 0; }
.activate-summary li { margin: 2px 0; }

.last-run-link { color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
.last-run-link:hover { color: var(--qwri-accent, #6366f1); text-decoration-style: solid; }

/* Chat box under the conversation: a message TO Sophia, separate from the request document */
.bld-composer { display: flex; flex-direction: column; gap: 6px; }
.bld-composer-input {
    width: 100%;
    resize: vertical;
    min-height: 56px;
    padding: 8px 10px;
    border: 1px solid var(--border-color, #d4d4d8);
    border-radius: 8px;
    font: inherit;
    font-size: 0.9rem;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #18181b);
}
.bld-composer-input:focus { outline: 2px solid var(--qwri-accent, #0f766e); outline-offset: 1px; }
.bld-composer-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.bld-composer-hint { font-size: 0.78rem; color: var(--text-secondary, #71717a); margin-right: auto; }

/* Pick-several questions */
.bld-clar-picks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 4px 12px;
    margin: 8px 0 4px;
}
.bld-clar-pick { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; cursor: pointer; padding: 3px 0; }
.bld-clar-pick input { width: 16px; height: 16px; accent-color: var(--qwri-accent, #0f766e); }
.bld-clar-pick-tools { display: flex; gap: 12px; margin-bottom: 6px; }
