/* Agent pipeline — vertical node flow (js/agent-pipeline.js).
 * A make.com-style rendering of the content worker's real pipeline: one node
 * card per stage on a connector spine. All colors are house tokens
 * (css/main.css :root + css/theme.css) — see /design-system/. */

.apl {
  display: flex;
  flex-direction: column;
}

.apl-node {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
}

/* The spine: icon dot + connector line down to the next node. */
.apl-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.apl-dot {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 0 var(--edge-hi);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.apl-dot svg { width: 16px; height: 16px; }
.apl-line {
  width: 2px;
  flex: 1 1 auto;
  min-height: 14px;
  background: var(--line);
  margin: 4px 0;
}

.apl-card {
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-control, 13px);
  box-shadow: inset 0 1px 0 0 var(--edge-hi);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.apl-node:last-child .apl-card { margin-bottom: 0; }

/* Off nodes read as "a slot you could fill", not an error. */
.apl-node.is-off .apl-card { background: transparent; border-style: dashed; box-shadow: none; }
.apl-node.is-off .apl-dot { opacity: 0.55; }
.apl-node.is-off .apl-title { color: var(--muted); }

.apl-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.apl-title {
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  flex: 1 1 auto;
  min-width: 0;
}
.apl-pill {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted-2);
  flex: 0 0 auto;
}
.apl-pill.auto { border-color: transparent; background: var(--surface-3); }

.apl-gear {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid transparent;
  background: none;
  color: var(--muted-2);
  cursor: pointer;
  transition: color 150ms cubic-bezier(0.4, 0, 0.2, 1), border-color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.apl-gear svg { width: 15px; height: 15px; }
.apl-gear:hover { color: var(--text); border-color: var(--line-strong); }
.apl-gear:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-faint); }

.apl-value {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.apl-value strong { color: var(--text); font-weight: 600; }
.apl-value a { color: var(--accent-text); text-decoration: none; }
.apl-value a:hover { text-decoration: underline; }
.apl-note, .apl-subnote {
  margin-top: 6px;
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.45;
}
.apl-quote {
  margin-top: 6px;
  padding: 6px 10px;
  border-left: 2px solid var(--line-strong);
  color: var(--muted);
  font-size: 12.5px;
  font-style: italic;
}
.apl-run-note {
  margin-top: 6px;
  color: var(--accent-text);
  font-size: 12px;
}

/* Working-list target chips */
.apl-targets {
  margin-top: 8px;
  color: var(--muted-2);
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.apl-target-chip {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-chip, 12px);
  padding: 3px 9px;
  color: var(--muted);
  font-size: 11.5px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* "+ Add a step" affordance on off nodes */
.apl-add {
  margin-top: 6px;
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.apl-add:hover { text-decoration: underline; }
.apl-add:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-faint); border-radius: 6px; }

/* ── Inline editor ─────────────────────────────────────────────────── */
.apl-editor {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.apl-ed-row { display: flex; flex-direction: column; gap: 5px; }
.apl-ed-row > label {
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.apl-select, .apl-textarea, .apl-num {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-input, 13px);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
}
.apl-select:focus, .apl-textarea:focus, .apl-num:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px var(--accent-faint);
}
.apl-textarea { resize: vertical; min-height: 60px; }
.apl-num { width: 74px; text-align: center; font-variant-numeric: tabular-nums; }
.apl-ed-count { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.apl-ed-hint { color: var(--muted-2); font-size: 12.5px; }
.apl-radio {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.apl-radio input { accent-color: var(--accent); }
.apl-radio input:checked + span { color: var(--text); }
.apl-radio.is-disabled { opacity: 0.6; cursor: default; }
.apl-pub { padding: 4px 0; }
.apl-link { color: var(--accent-text); text-decoration: none; margin-left: 6px; font-size: 12.5px; }
.apl-link:hover { text-decoration: underline; }

/* Consent rows: the one place spend/rewrite can be switched on. Deliberately
 * loud relative to the quiet editor around it. */
.apl-consent {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-input, 13px);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  cursor: pointer;
}
.apl-consent input { margin-top: 2px; accent-color: var(--accent); flex: 0 0 auto; }
.apl-consent strong { color: var(--text); }

.apl-ed-err {
  color: var(--danger);
  font-size: 12.5px;
}
.apl-ed-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.apl-ed-note { color: var(--muted-2); font-size: 12px; }

/* ── Run overlay ───────────────────────────────────────────────────── */
.apl-node.run-done .apl-dot { color: var(--accent-text); border-color: rgba(var(--accent-rgb), 0.35); }
.apl-node.run-running .apl-dot { border-color: rgba(var(--accent-rgb), 0.35); }
.apl-node.run-skip .apl-dot { color: var(--muted-3); }
.apl-node.run-fail .apl-dot { color: var(--danger); border-color: var(--danger); }
.apl-node.run-fail .apl-run-note { color: var(--danger); }

.apl-spin {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid rgba(var(--accent-rgb), 0.25);
  border-top-color: var(--accent-text);
  animation: apl-spin 0.8s linear infinite;
}
@keyframes apl-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .apl-spin { animation: none; }
}

@media (max-width: 560px) {
  .apl-node { grid-template-columns: 28px 1fr; gap: 9px; }
  .apl-dot { width: 28px; height: 28px; flex-basis: 28px; }
  .apl-dot svg { width: 14px; height: 14px; }
}

/* ── Create face (mode:'create') — name, goal cards, estimate, launch ─ */
.apl-name-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 0 0 14px;
}
.apl-name-row > span {
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.apl-name {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-input, 13px);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  padding: 9px 11px;
  width: 100%;
}
.apl-name:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px var(--accent-faint);
}
.apl-goal-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
}
.apl-goal-card {
  text-align: left;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-control, 13px);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.apl-goal-card:hover { border-color: var(--line-strong); }
.apl-goal-card:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-faint); }
.apl-goal-card.is-selected { border-color: rgba(var(--accent-rgb), 0.5); }
.apl-goal-card strong { color: var(--text); font-size: 13px; font-weight: 600; }
.apl-goal-card span { color: var(--muted-2); font-size: 12px; line-height: 1.45; }
.apl-goal-card.is-selected span { color: var(--muted); }

/* The read-only built-in prompt quote */
.apl-prompt {
  border: 1px solid var(--line);
  border-radius: var(--r-input, 13px);
  background: var(--panel);
  overflow: hidden;
}
.apl-prompt > summary {
  padding: 8px 11px;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  list-style: none;
}
.apl-prompt > summary::before { content: '› '; color: var(--muted-3); }
.apl-prompt[open] > summary::before { content: '⌄ '; }
.apl-prompt-body {
  padding: 0 11px 10px;
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}
.apl-steer strong { color: var(--accent-text); }

/* The full-prompt editor (the stage's actual, editable prompt) */
.apl-sp-text {
  min-height: 150px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.55;
}
.apl-sp-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted-2);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: 1px;
}
.apl-sp-badge.is-custom {
  color: var(--accent-text);
  border-color: rgba(var(--accent-rgb), 0.4);
  background: var(--accent-faint);
}
.apl-sp-reset { align-self: flex-start; margin-top: 6px; }

/* The AI "Proposed changes" Apply card (js/agent-detail-apply.js) — rides on
   the .aplm modal shell; these are just the before→after rows. */
.ada-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.ada-row:last-child { border-bottom: 0; }
.ada-field {
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.ada-change { color: var(--muted); font-size: 13px; line-height: 1.5; }
.ada-before { color: var(--muted-2); text-decoration: line-through; }
.ada-arrow { color: var(--muted-3); margin: 0 8px; }
.ada-after { color: var(--text); font-weight: 600; }
.ada-status { color: var(--muted); font-size: 12.5px; }
.ada-status.is-danger { color: var(--danger, #ff8f8f); }
.apl-amber { color: var(--gold, #e6c47a); }
.apl-amber a { color: inherit; }

.apl-estimate {
  margin-top: 14px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-input, 13px);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}
.apl-estimate strong { color: var(--text); font-variant-numeric: tabular-nums; }
.apl-est-warn { color: var(--gold, #e6c47a); margin-top: 4px; }
.apl-launch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.apl-launch-status { font-size: 12.5px; color: var(--muted); }
.apl-launch-status.is-danger { color: var(--danger); }

/* ── Preview modal (js/agent-pipeline-modal.js) ─────────────────────
 * Self-contained on purpose: pills appear on chat/report pages that don't
 * load css/agents.css, so this can't lean on the .af-modal classes. Uses
 * only main.css/theme.css tokens. */
.aplm {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 24px;
  animation: aplmIn 0.18s ease-out;
}
@keyframes aplmIn { from { opacity: 0; } to { opacity: 1; } }
.aplm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 4, 8, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.aplm-card {
  position: relative;
  width: min(600px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px 26px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card, 20px);
  box-shadow: inset 0 1px 0 0 var(--edge-hi), 0 30px 60px -16px rgba(0, 0, 0, 0.7);
  animation: aplmCardIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes aplmCardIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
/* Compact variant for single-field dialogs (rename, small confirms). */
.aplm-card--sm { width: min(440px, 100%); }
@media (prefers-reduced-motion: reduce) {
  .aplm, .aplm-card { animation: none; }
}
.aplm-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--muted-2);
  cursor: pointer;
}
.aplm-close:hover { background: var(--surface-3); color: var(--text); }
.aplm-title {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  padding-right: 28px;
}
.aplm-sub {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}
.aplm-warn {
  margin: 0 0 10px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--gold, #e6c47a);
  border-radius: var(--r-input, 13px);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}
.aplm-name-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 0 0 14px;
}
.aplm-name-row > span {
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.aplm-name, .aplm-paste {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-input, 13px);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  padding: 9px 11px;
  width: 100%;
}
.aplm-name:focus, .aplm-paste:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px var(--accent-faint);
}
.aplm-paste {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  resize: vertical;
  min-height: 160px;
}
.aplm-loading { color: var(--muted-2); font-size: 13px; padding: 18px 0; }
.aplm-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.aplm-spacer { flex: 1 1 auto; }
.aplm-status {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.aplm-status.is-danger { color: var(--danger); }
