/* ============================================================
   Workflows — List, detail, run views, and create modal
   ============================================================ */

.workflows-view {
    padding: 20px 24px;
    overflow-y: auto;
    height: 100%;
}

/* ── Header ───────────────────────────────────────────────── */

.wf-header {
    display: flex;
    flex-wrap: wrap; /* #4344: at large text the title and its buttons wrap instead of the buttons running off the right edge */
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.wf-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wf-header h2 {
    margin: 0;
    font-size: var(--type-page-size);
}

.wf-count-badge {
    font-size: 0.6875rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: var(--radius-ml);
}

.wf-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ── Empty state ──────────────────────────────────────────── */

.wf-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.wf-empty-icon {
    font-size: 3rem;
    opacity: 0.3;
    margin-bottom: 12px;
}

.wf-empty p {
    margin: 8px 0 4px;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.wf-empty-hint {
    font-size: 0.8125rem;
}

/* ── Workflow list ────────────────────────────────────────── */

.wf-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wf-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.wf-card:hover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
}

.wf-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.wf-card-name {
    font-weight: 600;
    font-size: var(--fs-lg);
    color: var(--text-primary);
}

.wf-card-badges {
    display: flex;
    gap: 6px;
    align-items: center;
}

.wf-badge {
    font-size: 0.6875rem;
    padding: 2px 8px;
    border-radius: var(--radius-ml);
    font-weight: 500;
}

.wf-badge-enabled {
    background: rgba(var(--fx-green-deep-rgb), 0.15);
    color: var(--success);
}

.wf-badge-disabled {
    background: rgba(var(--fx-slate-rgb), 0.15);
    color: var(--text-secondary);
}

.wf-badge-steps {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.wf-card-desc {
    font-size: var(--fs-lg);
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.wf-card-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.wf-last-run-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.wf-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.wf-status-dot.completed { background: var(--success); }
.wf-status-dot.running { background: var(--accent); animation: wf-pulse 1.5s infinite; }
.wf-status-dot.failed { background: var(--error); }
.wf-status-dot.killed { background: var(--warning); }
.wf-status-dot.pending { background: var(--text-secondary); }

@keyframes wf-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Workflow detail ──────────────────────────────────────── */

.wf-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: var(--space-lg);
}

.wf-detail-header > div:first-child { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }

.wf-detail-title {
    font-size: var(--fs-xl);
    font-weight: 600;
    margin: 0;
}

.wf-detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
}

.wf-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: var(--fs-base);
    color: var(--text-secondary);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.wf-detail-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.wf-detail-meta .material-icons {
    font-size: var(--icon-inline-size);
    color: var(--text-muted);
}

/* ── Steps list ───────────────────────────────────────────── */

.wf-steps-section {
    margin-bottom: 20px;
}

.wf-steps-section h3 {
    font-size: var(--fs-xl);
    margin: 0 0 8px;
    color: var(--text-secondary);
}

.wf-step-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wf-step-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
}

.wf-step-index {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.wf-step-name {
    font-weight: 500;
    color: var(--text-primary);
}

.wf-step-type {
    font-size: 0.6875rem;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-muted);
    margin-left: auto;
}

/* ── Runs table ───────────────────────────────────────────── */

.wf-runs-section h3 {
    font-size: var(--fs-xl);
    margin: 0 0 8px;
    color: var(--text-secondary);
}

.wf-runs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.wf-runs-table th,
.wf-runs-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.wf-runs-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.wf-runs-table tr {
    cursor: pointer;
}

.wf-runs-table tr:hover td {
    background: var(--bg-tertiary);
}

/* ── Progress bar ─────────────────────────────────────────── */

.wf-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.wf-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-xs);
    overflow: hidden;
}

.wf-progress-fill {
    height: 100%;
    border-radius: var(--radius-xs);
    transition: width 0.4s ease;
}

.wf-progress-fill.completed { background: var(--success); }
.wf-progress-fill.running { background: var(--accent); }
.wf-progress-fill.failed { background: var(--error); }
.wf-progress-fill.killed { background: var(--warning); }
.wf-progress-fill.pending { background: var(--text-secondary); }

.wf-progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Run detail ───────────────────────────────────────────── */

.wf-run-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.wf-run-title {
    font-size: var(--fs-lg);
    font-weight: 600;
    margin: 0;
}

.wf-run-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: var(--fs-base);
    color: var(--text-secondary);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.wf-run-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.wf-run-meta .material-icons {
    font-size: var(--icon-inline-size);
    color: var(--text-muted);
}

.wf-run-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ── Timeline layout ──────────────────────────────────────── */

.wf-timeline {
    position: relative;
    padding-left: 16px;
    gap: 0 !important;
}

.wf-timeline .wf-run-step {
    display: flex;
    gap: 12px;
    border: none;
    background: none;
    padding: 0 0 16px 0;
    border-radius: 0;
    position: relative;
}

.wf-timeline-node {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
    z-index: 1;
    border: 2px solid var(--border);
    background: var(--bg-primary);
}

.wf-timeline-node.completed { border-color: var(--success); background: var(--success); }
.wf-timeline-node.running { border-color: var(--accent); background: var(--accent); animation: wf-pulse 1.5s infinite; }
.wf-timeline-node.failed { border-color: var(--error); background: var(--error); }
.wf-timeline-node.killed { border-color: var(--warning); background: var(--warning); }
.wf-timeline-node.skipped { border-color: var(--text-secondary); background: transparent; }
.wf-timeline-node.pending { border-color: var(--text-secondary); background: transparent; }

.wf-run-step-connected::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 18px;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.wf-run-step-content {
    flex: 1;
    min-width: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 10px 14px;
}

.wf-run-step-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.wf-run-step-status {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.wf-run-step-status.completed { background: rgba(var(--fx-green-deep-rgb), 0.15); color: var(--success); }
.wf-run-step-status.running { background: rgba(var(--accent-rgb), 0.15); color: var(--accent); }
.wf-run-step-status.failed { background: rgba(var(--fx-red-rgb), 0.15); color: var(--error); }
.wf-run-step-status.killed { background: rgba(var(--fx-amber-rgb), 0.15); color: var(--warning); }
.wf-run-step-status.skipped { background: rgba(var(--fx-slate-rgb), 0.15); color: var(--text-secondary); }
.wf-run-step-status.pending { background: rgba(var(--fx-slate-rgb), 0.1); color: var(--text-secondary); }

.wf-run-step-name {
    font-weight: 500;
    font-size: 0.8125rem;
}

.wf-run-step-timing {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.wf-run-step-output-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--fs-md);
    color: var(--text-muted);
    cursor: pointer;
    margin-top: 6px;
    user-select: none;
    background: none;
    border: none;
    padding: 0;
    font-family: inherit;
}

.wf-run-step-output-toggle:hover {
    color: var(--text-secondary);
}

.wf-run-step-output {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 0;
    overflow: hidden;
    color: var(--text-secondary);
    margin-top: 4px;
    /* Collapsed shows nothing: without this the padding left a clipped strip of the first line. */
    padding-top: 0;
    padding-bottom: 0;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.wf-run-step-output.wf-expanded {
    max-height: 300px;
    overflow-y: auto;
    padding-top: 8px;
    padding-bottom: 8px;
}

.wf-run-step-error-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--fs-md);
    color: var(--error);
    margin-top: 6px;
}

.wf-run-step-output.wf-run-step-error {
    color: var(--text-primary);
    border-left: 2px solid var(--error);
}

.wf-toggle-arrow {
    transition: transform 0.2s;
}

.wf-expanded + .wf-toggle-arrow,
.wf-run-step-output.wf-expanded ~ .wf-toggle-arrow {
    transform: rotate(180deg);
}

.wf-timing-active {
    color: var(--accent);
}

.wf-step-agent-link {
    font-size: var(--fs-base);
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 2px;
}

.wf-step-agent-link:hover {
    text-decoration: underline;
}

/* ── Failed step highlight ────────────────────────────────── */

.wf-step-failed {
    border-color: rgba(var(--fx-red-rgb), 0.4);
}

/* ── Exit code badge ──────────────────────────────────────── */

.wf-exit-code {
    font-size: 0.6875rem;
    font-family: var(--font-mono);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.wf-exit-ok {
    background: rgba(var(--fx-green-deep-rgb), 0.12);
    color: var(--success);
}

.wf-exit-err {
    background: rgba(var(--fx-red-rgb), 0.12);
    color: var(--error);
}

/* ── Step file list ───────────────────────────────────────── */

.wf-step-files {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    font-size: 0.75rem;
}

.wf-step-file {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1px 6px;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--text-muted);
}

/* ── Sidebar workflow group ────────────────────────────────── */

.session-wf-card {
    border-left-color: var(--color-tool-agent) !important;
}

/* ── Create modal ─────────────────────────────────────────── */

.wf-modal-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wf-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 4px;
}

.wf-hint {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: var(--fs-base);
}

.wf-input {
    background: var(--bg-tertiary);
    border: 1px solid var(--control-border);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    font-size: var(--fs-md);
    color: var(--text-primary);
    width: 100%;
    min-height: var(--control-height);
    font-family: var(--font-sans);
}

.wf-input:focus {
    outline: none;
    border-color: var(--accent);
}

.wf-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Step editor ──────────────────────────────────────────── */

.wf-steps-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wf-step-editor-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
}

.wf-step-editor-top {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.wf-step-editor-top select,
.wf-step-editor-top input {
    background: var(--bg-secondary);
    border: 1px solid var(--control-border);
    border-radius: var(--radius-sm);
    padding: 4px 6px;
    font-size: var(--fs-md);
    color: var(--text-primary);
}

.wf-step-editor-top select { width: 80px; }
.wf-step-editor-top input { flex: 1; }

.wf-step-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    font-size: 1rem;
    line-height: 1;
}

.wf-step-remove-btn:hover {
    color: var(--error);
}

.wf-step-editor-body textarea {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--control-border);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    font-size: 0.75rem;
    color: var(--text-primary);
    resize: vertical;
    min-height: 36px;
    font-family: var(--font-mono);
}

.wf-add-step-btn {
    align-self: flex-start;
    margin-top: 4px;
}

.wf-modal-error {
    background: rgba(var(--fx-red-rgb), 0.1);
    border: 1px solid rgba(var(--fx-red-rgb), 0.3);
    color: var(--error);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    font-size: 0.8125rem;
    margin-top: 4px;
}

/* ── Status badge (reused) ────────────────────────────────── */

.wf-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: var(--radius-ml);
    font-weight: 500;
}

.wf-status-badge.completed { background: rgba(var(--fx-green-deep-rgb), 0.15); color: var(--success); }
.wf-status-badge.running { background: rgba(var(--accent-rgb), 0.15); color: var(--accent); }
.wf-status-badge.failed { background: rgba(var(--fx-red-rgb), 0.15); color: var(--error); }
.wf-status-badge.killed { background: rgba(var(--fx-amber-rgb), 0.15); color: var(--warning); }
.wf-status-badge.pending { background: rgba(var(--fx-slate-rgb), 0.15); color: var(--text-secondary); }
