/* ====== Flow page (agent pipeline builder) ====== */

.page--flow {
    padding: 0;
}

.flow-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-3) var(--s-2);
    flex-shrink: 0;
}

.flow-save-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--accent);
    border-color: var(--accent);
}
.flow-save-btn:disabled { opacity: 0.55; cursor: default; }

.flow-save-status {
    font-size: var(--fs-xs);
    color: var(--text-muted);
}
.flow-save-status[data-kind="ok"]    { color: var(--success); }
.flow-save-status[data-kind="error"] { color: var(--error); }

/* Agent dropdown (custom — options show name + responsibilities) */
.flow-agent-dd {
    position: relative;
    z-index: 30;
    flex-shrink: 0;
}
.flow-agent-dd__btn {
    background: var(--bg-elevated);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--r-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-family: inherit;
    padding: 6px 14px;
    cursor: pointer;
}
.flow-agent-dd__btn svg { display: block; }
.flow-agent-dd__btn.open,
.flow-agent-dd__btn:active { border-color: var(--accent-active); background: var(--surface); }

.flow-agent-dd__panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: min(320px, 80vw);
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
    padding: var(--s-1);
}
.flow-agent-dd__panel[hidden] { display: none; }

.flow-agent-dd__item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    font-family: inherit;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    cursor: pointer;
}
.flow-agent-dd__item:active { background: var(--surface); }
.flow-agent-dd__item + .flow-agent-dd__item { border-top: 1px solid var(--border); }

.flow-agent-dd__name {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.flow-agent-dd__detail {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.flow-agent-dd__empty {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    padding: var(--s-2) var(--s-3);
}

.flow-clear-btn { margin-left: auto; }

.flow-canvas {
    position: relative;
    flex: 1 1 auto;
    overflow: hidden;
    touch-action: none;
    /* darker than the workspace — visible outside its edges */
    background: #142219;
    border-top: 1px solid var(--border);
}

.flow-canvas__inner {
    position: absolute;
    top: 0;
    left: 0;
    width: 4000px;
    height: 4000px;
    transform-origin: 0 0;
    will-change: transform;
    /* dot grid lives on the workspace itself so it pans/zooms with the content */
    background-color: var(--bg);
    background-image: radial-gradient(rgba(232, 230, 220, 0.07) 1px, transparent 1.5px);
    background-size: 24px 24px;
    border: 2px solid rgba(212, 160, 74, 0.28);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.flow-edges {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}
.flow-edge {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    opacity: 0.85;
}
.flow-edge--temp {
    stroke-dasharray: 6 5;
    opacity: 0.6;
}
.flow-edge--selected {
    stroke: var(--error);
    stroke-width: 3;
    opacity: 1;
}
.flow-edge-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 22;
    pointer-events: stroke;
    cursor: pointer;
}

.flow-nodes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.flow-node {
    position: absolute;
    width: 200px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-2);
    pointer-events: auto;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    user-select: none;
    -webkit-user-select: none;
}
.flow-node--dragging {
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
    border-color: var(--accent);
    z-index: 5;
}
.flow-node--connecting { border-color: var(--accent); }
.flow-node--drop-target {
    border-color: var(--success);
    box-shadow: 0 0 0 2px rgba(136, 176, 106, 0.45);
}
.flow-node--input { border-left: 3px solid var(--success); }
.flow-node--note  { border-left: 3px solid var(--text-dim); }
.flow-node--agent { border-left: 3px solid var(--accent); }
.flow-node--run   { border-left: 3px solid var(--accent); border-color: rgba(212, 160, 74, 0.45); }
.flow-node--run .flow-node__avatar { background: var(--accent); color: var(--bg); }

.flow-node__runbtn {
    width: 100%;
    margin-top: var(--s-2);
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-family: inherit;
    padding: 8px 0;
    cursor: pointer;
}
.flow-node__runbtn svg { display: block; }
.flow-node__runbtn:active { background: var(--accent-active); }

.flow-node__head {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    cursor: grab;
}
.flow-node__avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: var(--r-full);
    background: var(--surface);
    color: var(--accent);
    font-size: var(--fs-xs);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.flow-node__meta { min-width: 0; flex: 1 1 auto; }
.flow-node__name {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.flow-node__role {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.flow-node__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 3px;
}
.flow-node__action {
    font-size: 9px;
    line-height: 1;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    padding: 3px 7px;
    text-transform: lowercase;
}
.flow-node__del {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-dim);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
    cursor: pointer;
    border-radius: var(--r-sm);
}
.flow-node__del:active { color: var(--error); background: var(--surface); }
.flow-node__del svg { display: block; }

.flow-node__text {
    width: 100%;
    margin-top: var(--s-2);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    font-size: var(--fs-xs);
    font-family: inherit;
    line-height: 1.4;
    padding: 6px 8px;
    resize: vertical;
    min-height: 38px;
    touch-action: auto;
}
.flow-node__text:focus { outline: none; border-color: var(--accent); }

.flow-port {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    border-radius: var(--r-full);
    background: var(--surface);
    border: 2px solid var(--accent);
    z-index: 2;
}
.flow-port--in  { left:  -9px; border-color: var(--text-muted); }
.flow-port--out {
    right: -9px;
    cursor: crosshair;
}
.flow-port--out::after {
    /* enlarged invisible touch target */
    content: "";
    position: absolute;
    inset: -12px;
}

.flow-hint {
    position: absolute;
    left: var(--s-4);
    right: var(--s-4);
    bottom: var(--s-4);
    text-align: center;
    font-size: var(--fs-xs);
    color: var(--text-muted);
    line-height: 1.6;
    pointer-events: none;
}
.flow-hint[hidden] { display: none; }

/* Flow run status — chip in the node's top-right corner driven by
   data-run-status (queued | running | done | failed). */
.flow-node[data-run-status]::after {
    content: attr(data-run-status);
    position: absolute;
    top: -9px;
    right: 10px;
    padding: 1px 8px;
    border-radius: var(--r-full);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: var(--bg-elevated);
    border: 1px solid var(--text-muted);
    color: var(--text-dim);
    pointer-events: none;
}
.flow-node[data-run-status="queued"]::after {
    border-color: var(--accent);
    color: var(--accent);
}
.flow-node[data-run-status="running"]::after {
    border-color: var(--accent);
    background: var(--accent);
    color: #1a2e1f;
    animation: flow-run-pulse 1.1s ease-in-out infinite;
}
.flow-node[data-run-status="running"] {
    box-shadow: 0 0 0 2px rgba(212, 160, 74, 0.45), 0 4px 14px rgba(0, 0, 0, 0.35);
}
.flow-node[data-run-status="done"]::after {
    border-color: var(--success);
    color: var(--success);
}
.flow-node[data-run-status="skipped"]::after {
    color: var(--text-dim);
    border-color: var(--border);
}
.flow-node[data-run-status="failed"]::after {
    border-color: var(--error);
    background: rgba(217, 119, 87, 0.15);
    color: var(--error);
}
@keyframes flow-run-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.45; }
}

/* ===== Workflow chain cards (Task History) ===== */
.news-card--workflow { cursor: default; }

.wf-steps {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
}

.wf-step {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(0,0,0,0.12);
    overflow: hidden;
}

.wf-step__row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
}
.wf-step__row:hover { background: rgba(255,255,255,0.04); }

.wf-step__dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-dim);
}
.wf-step__dot--done      { background: var(--success); }
.wf-step__dot--failed    { background: var(--error); }
.wf-step__dot--running   { background: var(--warning); animation: flow-run-pulse 1.2s ease-in-out infinite; }
.wf-step__dot--cancelled { background: var(--text-dim); }

.wf-step__title {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wf-step__agent {
    font-size: 0.72rem;
    color: var(--text-dim);
    flex-shrink: 0;
}

.wf-step__status {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    flex-shrink: 0;
}
.wf-step--expanded .wf-step__status { color: var(--accent); }

.wf-step__details {
    padding: 4px 12px 10px;
    border-top: 1px solid var(--border);
}

.wf-io-label {
    margin-top: 8px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.wf-io-label--in  { color: #4a9eb0; }
.wf-io-label--out { color: var(--accent); }
.wf-io-label--verif { color: var(--text-dim); }

.wf-step__verif {
    flex-shrink: 0;
    padding: 1px 7px;
    font-size: 0.66rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-radius: 9px;
    border: 1px solid transparent;
}
.wf-step__verif--approved {
    color: var(--success);
    border-color: var(--success);
    background: rgba(80, 200, 120, 0.1);
}
.wf-step__verif--rejected {
    color: var(--error);
    border-color: var(--error);
    background: rgba(220, 80, 80, 0.1);
}
.wf-step__verif--skipped {
    color: var(--text-dim);
    border-color: var(--border);
}

.wf-io-text {
    margin: 4px 0 0;
    padding: 8px 10px;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text);
    background: rgba(0,0,0,0.2);
    border-radius: 6px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 240px;
    overflow: auto;
}

.wf-arrow {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
    line-height: 1;
    padding: 3px 0;
}

/* Per-step run policy controls (agent nodes) */
.flow-node__opts {
    display: flex;
    gap: 6px;
    padding: 0 10px 8px;
}
.flow-node__opt {
    flex: 1;
    min-width: 0;
    font-size: 0.68rem;
    padding: 2px 4px;
    color: var(--text-dim);
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.flow-node--agent[data-run-when="failure"] {
    border-color: rgba(220, 80, 80, 0.55);
}
.flow-node--agent[data-run-when="failure"] .flow-node__opt:first-child {
    color: var(--error);
    border-color: rgba(220, 80, 80, 0.55);
}
.flow-node--agent[data-run-when="always"] .flow-node__opt:first-child {
    color: var(--warning);
}
