/* Pipeline studio: the pipeline is the centre of the workspace (left), the step library and results sit beside it (right).
   Loaded last; colours follow the light design, the dark theme is generated from this file by scripts/design.css tokens. */

/* ------------------------------------------------------------ signed-in visitors: no marketing banner, straight to the pipeline */
html.is-member #workspace-intro { display: none; }
.studio-hidden { display: none !important; }

/* landing headline: the second sentence always starts a new line, so "Run on" never dangles */
.intro h1 > span { display: block; }

/* ------------------------------------------------------------ pipeline bar */
.pbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; padding: 18px 0 12px; }
.pbar-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; flex: 1 1 320px; }
.pbar-title { position: relative; display: inline-flex; align-items: center; max-width: 100%; }
body .pbar-title input.pbar-name:not([type=file]) {
  width: min(100%, 440px); field-sizing: content; min-width: 300px; max-width: 100%; min-height: 0; box-shadow: none;
  padding: 12px 48px 12px 16px; border: 1px solid transparent; border-radius: var(--radius-lg); background: transparent;
  font-size: 20px;   line-height: 24px; color: var(--text-primary); text-overflow: ellipsis;
}
.pbar-name::placeholder { color: var(--text-secondary); opacity: 1; }
body .pbar-title input.pbar-name:not([type=file]):hover { border-color: var(--border-default); }
body .pbar-title input.pbar-name:not([type=file]):focus { outline: none; border-color: var(--brand-accent); background: var(--bg-surface); box-shadow: var(--shadow-card); }
.pbar-pencil { position: absolute; right: 16px; top: 13px; width: 20px; height: 24px; display: grid; place-items: center; color: var(--text-muted); pointer-events: none; }
.pbar-pencil svg { width: 20px; height: 20px; }
.pbar-name:focus + .pbar-pencil { opacity: .35; }
.pbar-badge {
  display: inline-flex; align-items: center; gap: 7px; min-height: 30px; padding: 3px 12px; border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--bg-page); color: var(--text-secondary); font: 600 12.5px/1 var(--font-mono); 
}
.pbar-badge:hover { background: var(--brand-tint); }
.pbar-badge-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-accent); }
.pbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pbar-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-surface); color: var(--text-primary); font-size: 13px; font-weight: 500; white-space: nowrap;
}
.pbar-btn:hover:not(:disabled) { background: var(--bg-page); border-color: var(--brand-accent); }
.pbar-btn:disabled { opacity: .5; }
.pbar-btn svg { flex: none; }
.pbar-tip { display: inline-flex; }
.pbar-tip[title] .pbar-btn:disabled { cursor: not-allowed; }
.pbar-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--brand-tint); color: var(--brand-tint-fg); font-size: 11.5px; font-weight: 600; line-height: 1; }

.pquick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 16px; }
.pquick[hidden] { display: none; }
.pquick-label { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-secondary); }
.pquick-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pquick-chip { min-height: 36px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg-surface); color: var(--text-primary); font-size: 13px; font-weight: 600; }
.pquick-chip:hover { background: var(--bg-page); border-color: var(--brand-accent); }
.pquick-chip.is-mine { border-color: var(--brand-accent); background: var(--bg-page); }

/* ------------------------------------------------------------ layout: pipeline left (wide), library + results right */
@media (min-width: 951px) {
  body .workspace-grid, body.ai-mode .workspace-grid { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; gap: 20px; grid-template-rows: max-content 1fr; }
  /* results sit under the pipeline that produced them; the library keeps the whole right column, so the two columns stay level */
  .workspace-card, body.ai-mode .workspace-card { grid-column: 2; grid-row: 1 / span 2; }
  /* Recent results are a tab of the right panel (studio.js), so both columns are one row and end level. */
  body .workspace-grid { align-items: stretch; }
}
@media (max-width: 950px) {
  .pipeline-side { order: 1; }
  .workspace-card { order: 2; }
  #history { order: 3; }
}
body .pipeline-side {
  position: static; max-height: none; overflow: visible; display: block;
  border: 1px solid var(--border-default);  background: var(--bg-surface); 
}
#history { position: static; max-height: none; padding: 20px 22px; }
body #history .results-heading { display: block; }
body #history .result-filters[hidden] { display: none; }
/* nothing processed yet: a compact note instead of a tall empty card */
body #history .empty:not(.filter-empty) { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 14px; margin: 10px 0 0; padding: 12px 4px 6px; text-align: left; padding-left: 0; padding-right: 0; }
body #history .empty:not(.filter-empty) .empty-symbol { grid-row: 1 / span 2; width: 40px; height: 40px; margin: 0; font-size: 18px; margin-left: 0; }
#history .empty:not(.filter-empty) strong, #history .empty:not(.filter-empty) p { margin: 0; }

/* ------------------------------------------------------------ input node */
.pipeline-input-slot { padding: 6px 6px 0; }
.pipeline-input-slot .files-section.pipe-input-node { padding: 14px 16px 6px; border: 0; background: transparent; box-shadow: none; }
.pipe-input-node .section-heading { margin-bottom: 10px; }
.pipe-input-node .section-heading h2 { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.pipe-node-tag { display: inline-block; padding: 3px 9px; border-radius: var(--radius-sm); background: var(--bg-muted); color: var(--text-secondary); font-size: 10.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; }
.pipe-input-node .step { display: none; }
.pipe-input-node .dropzone { min-height: 0; }
.input-samples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 10px 0 2px; font-size: 12.5px; color: var(--text-secondary); }
.input-samples[hidden] { display: none; }
.sample-chip { min-height: 32px; padding: 0 12px; border: 1px dashed var(--brand-accent); border-radius: var(--radius-sm); background: var(--bg-subtle); color: var(--text-secondary); font-size: 12.5px; font-weight: 600; }
.sample-chip:hover { background: var(--bg-page); }
body .dropzone.has-files ~ .input-samples { display: none; }

/* ------------------------------------------------------------ the chain */
.pipe-chain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.pipe-link { position: relative; display: flex; align-items: center; min-height: 38px; padding-left: 28px; }
.pipe-line { position: absolute;  top: 0; bottom: 0;   }
.pipe-link::after { content: ""; position: absolute;     box-sizing: border-box;   transform: rotate(45deg); }
.pipe-type { position: relative;        }
.pipe-step { border: 1px solid var(--border-default);  background: var(--bg-surface); box-shadow: var(--shadow-card); }
.pipe-step-head { display: grid;  align-items: center; gap: 12px; padding: 11px 10px 11px 14px; }
.pipe-number { display: grid; place-items: center;        }
.pipe-number.is-running { background: var(--bg-muted); color: transparent; }
.pipe-number.is-running::after { content: ""; width: 13px; height: 13px; border: 2px solid var(--border-strong);  border-radius: 50%; animation: pipe-spin .8s linear infinite; }
@keyframes pipe-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .pipe-number.is-running::after { animation: none; } }
.pipe-step-title { display: grid; gap: 2px; min-width: 0; padding: 2px 0; border: 0; background: none; text-align: left; cursor: pointer; }
.pipe-step-title b {   color: var(--text-primary); overflow-wrap: anywhere; }
.pipe-step-title small { font-size: 12px; line-height: 1.4; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pipe-step-title small.pipe-missing { color: var(--warning); font-weight: 600; }
.pipe-step-tools { display: flex; align-items: center; gap: 2px; }
.pipe-icon { width: 30px; height: 30px; border: 0; border-radius: var(--radius-md); background: none; color: var(--text-secondary); font-size: 15px; line-height: 1; }
.pipe-icon:hover:not(:disabled) { background: var(--bg-page); color: var(--text-secondary); }
.pipe-icon:disabled { opacity: .25; cursor: default; }
.pipe-remove:hover:not(:disabled) { background: var(--bg-muted); color: var(--danger); }
.pipe-step-body { padding: 4px 16px 16px 54px; }
.pipe-step-body .pipeline-fields { margin-top: 4px; }
.pipe-step-body .pipeline-format-scope { margin-top: 14px; }
.pipe-note { margin: 0; font-size: 12.5px; color: var(--text-secondary); }
.pipe-add-row { padding-left: 0; }
.pipe-add-row .pipeline-add { width: 100%; min-height: 46px; margin: 0;     font-size: 13.5px;  }
.pipe-link.has-hint { min-height: 76px; padding-bottom: 10px; }
.pipe-empty { flex: 1; margin: 8px 0 8px 24px; padding: 12px 16px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--bg-subtle); font-size: 13px; line-height: 1.55; color: var(--text-secondary); }
.pipe-empty-narrow { display: none; }
@media (min-width: 951px) { .pipe-empty-wide::after { content: " →"; font-weight: 600; color: var(--brand-tint-fg); } .pipe-add-row.is-empty { display: none; } }
@media (max-width: 950px) { .pipe-empty-wide { display: none; } .pipe-empty-narrow { display: inline; } }
.pipe-end { position: relative; display: grid; gap: 2px; margin-top: 0; padding: 12px 16px 12px 54px; border: 1px solid var(--border-default);   }
.pipe-end::before { content: ""; position: absolute; left: 14px; top: 50%; width: 26px; height: 26px; margin-top: -13px; border-radius: 50%;  }
.pipe-end::after { content: ""; position: absolute; left: 22px; top: 50%; width: 10px; height: 5px; margin-top: -4px; border-left: 2px solid var(--bg-surface); border-bottom: 2px solid var(--bg-surface); transform: rotate(-45deg); }
.pipe-end.is-empty { border-style: dashed; border-color: var(--border-strong); background: transparent; }
.pipe-end.is-empty::before { background: transparent; border: 2px dashed var(--border-strong); box-sizing: border-box; }
.pipe-end.is-empty::after { display: none; }
.pipe-end.is-empty b { font-weight: 500; color: var(--text-secondary); }
/* The tick means "the result is ready": until then a neutral ring, and a spinner while the job runs. */
body .pipe-end.has-steps:not(.is-done)::before { background: transparent; border: 2px solid var(--border-strong); box-sizing: border-box; }
body .pipe-end.has-steps:not(.is-done)::after { display: none; }
body .pipe-end.is-running::before { border-color: var(--border-strong); border-top-color: var(--brand-accent); animation: pipe-spin .8s linear infinite; }
@keyframes pipe-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { body .pipe-end.is-running::before { animation: none; border-color: var(--brand-accent); } }
.pipe-end-label { font-size: 10.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--brand-tint-fg); }
.pipe-end b { font-size: 15px; color: var(--text-primary); }
.pipe-end small { font-size: 12px; color: var(--text-secondary); }
.pipeline-order { margin: 12px 0 0; }

/* ------------------------------------------------------------ run bar */
.pipe-run { position: sticky; bottom: 0; z-index: 5; display: grid; gap: 10px; margin: 18px -20px -20px; padding: 14px 20px 16px; border-top: 1px solid var(--border-default); border-radius: 0 0 var(--radius-lg) var(--radius-lg); background: color-mix(in srgb, var(--bg-surface) 95%, transparent); backdrop-filter: blur(6px); }
.pipe-run-note { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--text-secondary); }
.pipe-run-note.is-blocked { color: var(--warning); font-weight: 600; }
.pipe-run-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.pipe-run-actions .pipeline-run { flex: 1 1 220px; width: auto; margin: 0; min-height: 48px; }
.pipe-run-actions .pipe-test { flex: 0 1 auto; min-height: 48px; padding: 0 18px; font-weight: 500; }
.pipe-run .pipe-sample { justify-self: start; font-size: 12.5px; color: var(--brand-tint-fg); }
.pipe-run .pipeline-note, .pipe-run .pipeline-shortage, .pipe-run .pipeline-cost { margin: 0; }
/* While running: one status strip instead of the buttons */
.pipe-status { display: grid; gap: 10px; }
.pipe-status-head { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.pipe-status-spinner { flex: none; width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--brand-accent); border-radius: 50%; animation: pipe-spin .8s linear infinite; }
.pipe-status-text { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 500; color: var(--text-primary); overflow-wrap: anywhere; }
body .pipe-status-cancel { flex: none; min-height: 36px; padding: 0 14px; font-size: 13px; }
.pipe-status-bar { position: relative; height: 4px; border-radius: 999px; background: var(--bg-muted); overflow: hidden; }
.pipe-status-bar i { display: block; height: 100%; border-radius: inherit; background: var(--brand-accent); transition: width .4s ease; }
.pipe-status-bar.is-indeterminate i { width: 30%; animation: pipe-slide 1.2s ease-in-out infinite; }
@keyframes pipe-slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .pipe-status-spinner, .pipe-status-bar.is-indeterminate i { animation: none; } }
/* After the run: a short result card */
.pipe-result { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 14px; padding: 10px 12px; border: 1px solid var(--brand-tint-border); border-radius: var(--radius-md); background: var(--brand-tint); }
.pipe-result.is-failed, .pipe-result.is-cancelled { border-color: var(--warning-border); background: var(--warning-tint); }
.pipe-result-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; flex: 1 1 260px; min-width: 0; margin: 0; font-size: 13.5px; line-height: 1.45; }
.pipe-result-mark { flex: none; font-weight: 700; color: var(--brand-tint-fg); }
.pipe-result:not(.is-completed) .pipe-result-mark { color: var(--warning); }
.pipe-result-line b { color: var(--text-primary); }
.pipe-result-meta { min-width: 0; color: var(--text-secondary); overflow-wrap: anywhere; }
.pipe-result-expiry { flex-basis: 100%; font-size: 12px; color: var(--text-muted); }
.pipe-result-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
body .pipe-result-actions :is(.primary, .secondary) { min-height: 38px; padding: 0 14px; font-size: 13px; margin: 0; }
.pipe-result-save { padding: 0 4px; font-size: 13px; color: var(--text-secondary); }
/* Focus on the running chain: the library on the right steps back until the run ends. */
/* While a job runs the canvas shows only the run: no adding, moving or removing steps or files. */
body.pipeline-running :is(.pipe-add-row, #dropzone, .batch-sort-bar) { display: none; }
body.pipeline-running :is(.pipe-step-tools, .file-toolbar-actions) { visibility: hidden; }

/* The Results tab of the right panel: the former side card, without its own card chrome. */
.lib-tab-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--bg-surface); color: var(--text-secondary); font-size: 11px; font-weight: 600; line-height: 18px; }
.lib-tab.is-active .lib-tab-count { background: var(--bg-muted); }
.lib-tab-results.has-running .lib-tab-count { background: var(--brand-tint); color: var(--brand-tint-fg); }
body #history.studio-results { position: static; top: auto; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
body #history.studio-results[hidden] { display: none; }
body #history.studio-results .results-heading { display: none; }
/* The job form and its panels step aside while the Results tab is open. */
.action-section.shows-results > #job-form { display: none; }
.pipe-result-size { font-weight: 500; }
.pipe-next { margin: 12px 0 0; font-size: 13px; line-height: 1.5; color: var(--text-secondary); }
body .pipeline-state { margin-top: 16px; }

/* ------------------------------------------------------------ library (right column) */
.workspace-card { overflow: visible; }
body .action-section {  border-top: 0; padding: 20px 22px 22px; }
body .action-section .section-heading h2 { font-size: 16px; }
body .action-section .section-heading .step { display: none; }
.lib-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 0 0 14px; padding: 4px; border-radius: var(--radius-lg); background: var(--bg-muted); }
.lib-tab { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 4px 5px; line-height: 1.2; text-align: center; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text-secondary); font-size: 13px; font-weight: 500; }
.lib-tab.is-active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-card); }
.lib-ai-hint { margin: 0 0 12px; font-size: 12.5px; line-height: 1.55; color: var(--text-secondary); }
.lib[hidden] { display: none; }
body .lib-search input:not([type=file]) { width: 100%; min-height: 42px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-surface); font-size: 13.5px; }
body .lib-search input:not([type=file]):focus { outline: none; border-color: var(--brand-accent); box-shadow: var(--shadow-card); }
.lib-cats { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0 2px; }
.lib-cat { min-height: 29px; padding: 0 9px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--text-secondary); font-size: 12px; font-weight: 600; }
.lib-context { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 12px 0 8px; font-size: 12.5px; line-height: 1.5; color: var(--text-secondary); }
.lib-toggle { font-size: 12.5px; color: var(--brand-tint-fg); }
.lib-flow-types { color: var(--text-primary); font: 600 12px var(--font-mono); overflow-wrap: anywhere; }
.lib-assumed { color: var(--text-muted); font-size: 11px; }
.lib-list, .lib-scroll { max-height: clamp(240px, 53dvh, 560px); margin: 0 -6px; padding: 0 6px 2px; overflow: auto; overscroll-behavior-y: contain; scrollbar-gutter: stable; }
@supports not selector(::-webkit-scrollbar) { .pipe-chain, .lib-list, .api-sheet, .api-sheet-code { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; } }
.pipe-chain::-webkit-scrollbar, .lib-list::-webkit-scrollbar, .lib-scroll::-webkit-scrollbar, .api-sheet::-webkit-scrollbar, .api-sheet-code::-webkit-scrollbar { width: 6px; height: 6px; }
.pipe-chain::-webkit-scrollbar-track, .lib-list::-webkit-scrollbar-track, .tpl-list::-webkit-scrollbar-track, .api-sheet::-webkit-scrollbar-track, .api-sheet-code::-webkit-scrollbar-track { background: transparent; }
.pipe-chain::-webkit-scrollbar-thumb, .lib-list::-webkit-scrollbar-thumb, .tpl-list::-webkit-scrollbar-thumb, .api-sheet::-webkit-scrollbar-thumb, .api-sheet-code::-webkit-scrollbar-thumb { border-radius: 3px; background: var(--border-strong); }
.pipe-chain::-webkit-scrollbar-thumb:hover, .lib-list::-webkit-scrollbar-thumb:hover, .tpl-list::-webkit-scrollbar-thumb:hover, .api-sheet::-webkit-scrollbar-thumb:hover, .api-sheet-code::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.lib-group { margin: 0 0 6px; }
.lib-group-title { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px 2px 6px; background: var(--bg-surface); font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--text-secondary); }
.lib-group-title svg { width: 15px; height: 15px; }
.lib-row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 6px 8px; border: 1px solid transparent; border-radius: var(--radius-lg); background: none; text-align: left; }
.lib-row:hover:not(:disabled) { border-color: var(--border-default); background: var(--bg-subtle); }
.lib-row:disabled { cursor: default; }
.lib-row.is-muted { opacity: .55; }
.lib-text { display: grid; gap: 1px; flex: 1; min-width: 0; }
.lib-text b { font-size: 13.5px; font-weight: 500; color: var(--text-primary); }
.lib-text small { font-size: 12px; line-height: 1.4; color: var(--text-secondary); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lib-add { display: inline-grid; place-items: center; flex: none; min-width: 28px; min-height: 28px; padding: 0 7px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-page); color: var(--text-secondary); font-size: 12px; font-weight: 600; white-space: nowrap; }
.lib-row:hover:not(:disabled) .lib-add { background: var(--brand-primary); border-color: var(--brand-primary); color: var(--fg-inverse); }
.lib-row.is-muted .lib-add { border-color: var(--border-default); background: var(--bg-page); color: var(--text-muted); font-weight: 600; }
.lib-tiles { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 6px; }
.lib-tile { min-height: 34px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-page); color: var(--text-secondary); font-size: 12.5px; font-weight: 600; }
.lib-tile:hover:not(:disabled) { background: var(--brand-primary); border-color: var(--brand-primary); color: var(--fg-inverse); }
.lib-tile-more { border-style: dashed; background: transparent; }
.lib-empty { margin: 10px 0; font-size: 13px; color: var(--text-secondary); }
.lib.is-called { animation: lib-call .9s ease-out; border-radius: var(--radius-lg); }
@keyframes lib-call { 0% { box-shadow: var(--shadow-card); } 100% { box-shadow: var(--shadow-card); } }
@media (prefers-reduced-motion: reduce) { .lib.is-called { animation: none; } }

/* AI generator: just the composer; the plan appears as steps on the canvas */
#ai-panel { margin-top: 0; }

/* ------------------------------------------------------------ templates tab */
.tpl-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0 12px; }
.tpl-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.tpl-title h3 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.1px; }
.tpl-count { font: 500 12px/1 var(--font-mono); color: var(--text-muted); }
.tpl-count.is-full { color: var(--danger); }
.tpl-new { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--text-primary); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.tpl-new:hover:not(:disabled) { border-color: var(--brand-accent); background: var(--bg-page); }
.tpl-new:disabled { opacity: .5; }
.tpl-new svg { width: 14px; height: 14px; }
.tpl-search { margin: 0 0 12px; }
body .tpl-search input:not([type=file]) { width: 100%; min-height: 40px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-surface); font-size: 13.5px; }
body .tpl-search input:not([type=file]):focus { outline: none; border-color: var(--brand-accent); box-shadow: var(--shadow-card); }
.tpl-list { display: grid; gap: 10px; padding: 2px 0 4px; }
.tpl-card { display: grid; gap: 10px; padding: 14px 14px 12px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); transition: border-color .15s, box-shadow .15s; }
.tpl-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-card); }
.tpl-card.is-active { border-color: var(--brand-accent); background: color-mix(in srgb, var(--brand-tint) 45%, var(--bg-surface)); }
.tpl-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 24px; }
.tpl-name { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; font-weight: 600; letter-spacing: -.1px; color: var(--text-primary); }
.tpl-now { flex: none; padding: 3px 9px; border-radius: 999px; background: var(--brand-tint); color: var(--brand-tint-fg); font-size: 11px; font-weight: 600; letter-spacing: .02em; }
body input.tpl-rename:not([type=file]) { width: 100%; min-height: 32px; margin: -4px 0; padding: 0 10px; border: 1px solid var(--brand-accent); border-radius: var(--radius-sm); background: var(--bg-page); color: var(--text-primary); font: 600 14.5px/1 inherit; font-family: inherit; box-shadow: var(--shadow-card); }
body input.tpl-rename:not([type=file]):focus { outline: none; }
.tpl-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 4px; }
.tpl-pill { padding: 4px 9px; border-radius: var(--radius-sm); background: var(--bg-muted); color: var(--text-primary); font-size: 12px; font-weight: 500; line-height: 1.2; }
.tpl-arrow { color: var(--text-muted); font-size: 12px; }
.tpl-more { padding: 3px 8px; border: 1px dashed var(--border-strong); border-radius: 999px; color: var(--text-secondary); font-size: 11.5px; font-weight: 600; }
.tpl-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0; font-size: 12px; color: var(--text-secondary); }
.tpl-id { padding: 2px 8px; border: 1px solid var(--border-default); border-radius: 999px; background: var(--bg-page); color: var(--text-secondary); font: 500 11.5px/1.4 var(--font-mono); }
.tpl-id:hover { border-color: var(--brand-accent); color: var(--text-primary); }
.tpl-local { padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--warning, #b45309) 16%, transparent); color: var(--warning, #b45309); font-size: 11px; font-weight: 600; }
.tpl-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding-top: 10px; border-top: 1px solid var(--border-default); }
.tpl-open { flex: 1; min-height: 36px; margin-right: 6px; padding: 0 14px; border: 1px solid var(--brand-primary); border-radius: var(--radius-md); background: var(--brand-primary); color: var(--fg-inverse); font-size: 13px; font-weight: 600; }
.tpl-open:hover { filter: brightness(1.08); }
.tpl-card.is-active .tpl-open { border-color: var(--border-strong); background: var(--bg-surface); color: var(--text-primary); }
.tpl-icon { display: inline-grid; place-items: center; flex: none; width: 32px; height: 34px; border: 0; border-radius: var(--radius-md); background: none; color: var(--text-secondary); }
.tpl-icon:hover { background: var(--bg-muted); color: var(--text-primary); }
.tpl-icon.is-danger:hover { color: var(--danger); }
.tpl-icon svg { width: 17px; height: 17px; }
.tpl-empty { display: grid; justify-items: center; gap: 8px; padding: 26px 18px 22px; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); text-align: center; }
.tpl-empty-art { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 16px; background: var(--brand-tint); color: var(--brand-tint-fg); }
.tpl-empty b { font-size: 14.5px; font-weight: 600; color: var(--text-primary); }
.tpl-empty p { margin: 0; max-width: 34ch; font-size: 12.5px; line-height: 1.55; color: var(--text-secondary); }
.tpl-presets { margin-top: 14px; }
.tpl-presets > summary { padding: 8px 2px; cursor: pointer; color: var(--text-secondary); font-size: 12px; font-weight: 600; }
.tpl-presets[open] > summary { margin-bottom: 3px; }
.tpl-foot { display: flex; justify-content: flex-start; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-default); }
.tpl-foot[hidden] { display: none; }
.tpl-foot .text-button { font-size: 12.5px; color: var(--brand-tint-fg); }
.pbar-count.is-bump { animation: tpl-bump .5s ease-out; }
@keyframes tpl-bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .pbar-count.is-bump,
.tpl-card { animation: none; transition: none; } }

/* ------------------------------------------------------------ API sheet */
.api-sheet {  max-height: 88vh; padding: 24px 26px 22px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); color: var(--text-primary); overflow: auto; width: min(720px, calc(100vw - 32px)); }
.api-sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 8px; }
.api-sheet-head h2 { margin: 0 0 8px; font-size: 21px; letter-spacing: -.4px; }
.api-sheet-lead { margin: 0 0 14px; font-size: 13.5px; line-height: 1.55; color: var(--text-secondary); }
.api-sheet-tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.api-sheet-forms { margin-bottom: 8px; }
.api-sheet-tab { min-height: 34px; padding: 0 14px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--text-secondary); font-size: 12.5px; font-weight: 500; }
.api-sheet-code { margin: 0; padding: 14px 16px; max-height: 340px; overflow: auto; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-page); color: var(--text-primary); font: 12.5px/1.6 var(--font-mono); white-space: pre; tab-size: 2; }
.api-sheet-notes { margin: 14px 0 0; padding-left: 18px; font-size: 12.5px; line-height: 1.55; color: var(--text-secondary); }
.api-sheet-notes li + li { margin-top: 4px; }
.api-sheet-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-top: 16px; }
.api-sheet-link { font-size: 13px; font-weight: 500; color: var(--brand-tint-fg); }
.api-sheet-link:hover { text-decoration: underline; }

/* ------------------------------------------------------------ phones */
@media (max-width: 700px) {
  body .pbar-title input.pbar-name:not([type=file]) { font-size: 20px; min-width: 0; width: 100%; }
  .pbar-title { width: 100%; }
  .pbar-actions { width: 100%; }
  .pbar-actions .pbar-btn { flex: 1 1 auto; justify-content: center; }
  body .pipeline-editor { padding: 4px 14px 16px; }
  .pipe-run { margin: 16px -14px -16px; padding: 12px 14px 14px; }
  .pipe-step-body { padding: 2px 12px 14px 12px; }
  .lib-tab { font-size: 12px; }
}

/* ------------------------------------------------------------ API sheet: PipeID first, calmer chrome */
.api-sheet:focus { outline: none; }
.api-sheet .dialog-close:focus:not(:focus-visible) { outline: none; box-shadow: none; border-color: transparent; }
.api-sheet::backdrop { background: rgba(9, 9, 11, .55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
html[data-dark="1"] .api-sheet::backdrop { background: rgba(0, 0, 0, .75); }
.api-sheet-save { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 0 0 12px; padding: 12px 14px; border: 1px dashed var(--brand-accent); border-radius: var(--radius-lg); background: var(--brand-tint); }
.api-sheet-save[hidden] { display: none; }
.api-sheet-save p { flex: 1 1 260px; margin: 0; font-size: 13px; line-height: 1.5; color: var(--text-primary); }
.api-sheet-codebox { position: relative; }
.api-sheet-codebox .api-sheet-code { padding-right: 52px; }
.api-sheet-copy { position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--text-secondary); }
.api-sheet-copy:hover { color: var(--text-primary); border-color: var(--border-strong); }

/* ------------------------------------------------------------ polish: tab track, disabled save, prompt examples, footnote */
.landing-section[hidden] { display: none; }
/* disabled "Save as template": a quiet outline like the API button; it turns teal once the chain has a step */
body .pbar-btn.pbar-save:disabled { background: transparent; border-color: var(--border-strong); color: var(--text-secondary); box-shadow: none; opacity: .6; }
body .pbar-btn.pbar-save:disabled * { color: inherit; }
/* the dark theme: a deep track, the active tab lifted above it */
html[data-dark="1"] .lib-tabs { background: #09090B; border: 1px solid var(--border-default); }
html[data-dark="1"] .lib-tab.is-active { background: #27272A; color: #FAFAFA; box-shadow: 0 1px 2px rgba(0, 0, 0, .5); outline: 1px solid rgba(255, 255, 255, .1); outline-offset: -1px; }
html[data-dark="1"] .lib-tab:not(.is-active):hover { color: var(--text-primary); }
/* example prompts under the AI field */
.lib-ai-examples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0 0; }
.lib-ai-examples > span { flex: 0 0 100%; font-size: 12px; color: var(--text-secondary); }
.lib-ai-chip { min-height: 34px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--text-primary); font-size: 12.5px; font-weight: 500; text-align: left; }
.lib-ai-chip:hover:not(:disabled) { border-color: var(--brand-accent); background: var(--brand-tint); }

/* one inner inset for the three cards: input node, "Add steps" and recent results (22px sides, 20px top) */

/* the tall right column must not stretch the left rows apart: results stay pinned right under the pipeline */
@media (min-width: 951px) {
}

/* File contract of a template (accepted formats, file count, strict) */
.tpl-icon.is-set { color: var(--brand-tint-fg); }
.tpl-contract-chip { display: inline-flex; align-items: center; padding: 1px 8px; border: 1px solid var(--brand-tint-border); border-radius: var(--radius-sm); background: var(--brand-tint); color: var(--brand-tint-fg); font-size: 11px; line-height: 1.5; }
.tpl-contract { display: grid; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-default); }
.tpl-contract-hint { margin: 0; font-size: 12px; line-height: 1.5; color: var(--text-secondary); }
.tpl-contract-formats { min-width: 0; margin: 0; padding: 0; border: 0; }
.tpl-contract-formats legend { padding: 0 0 6px; font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.tpl-contract-counts { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.tpl-contract-counts label { display: grid; gap: 4px; font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.tpl-contract-counts input { width: 110px; min-height: 34px; font-size: 13px; }
.tpl-contract-strict { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; line-height: 1.45; cursor: pointer; }
.tpl-contract-strict input { flex: none; width: 17px; height: 17px; margin-top: 1px; accent-color: var(--brand-accent); }
.tpl-contract-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }

/* Input formats picked without files (to design a template) */
.input-kinds { display: grid; gap: 8px; margin: 12px 0 2px; font-size: 12.5px; color: var(--text-secondary); }
.input-kinds[hidden] { display: none; }
.input-kinds-chips { align-items: center; }
.input-kinds-note { font-size: 11.5px; line-height: 1.5; color: var(--text-secondary); }
body .dropzone.has-files ~ .input-kinds { display: none; }

/* Saved templates open from the toolbar; the panel has its own way back to the steps */
.pbar-btn.is-active { border-color: var(--brand-accent); background: var(--brand-tint); color: var(--brand-tint-fg); }
.tpl-head .tpl-title { flex: 1; }

/* [ Files | Pick formats ] in the input header */
.input-tabs { display: inline-flex; gap: 2px; margin: 8px 0 10px; padding: 3px; border-radius: var(--radius-md); background: var(--bg-muted); }
.input-tabs[hidden] { display: none; }
.input-tab { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 12px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-secondary); font-size: 12.5px; font-weight: 500; }
.input-tab.is-active { background: var(--bg-surface); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border-default); }
.input-tab:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }
.input-tab-count { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--brand-tint); color: var(--brand-tint-fg); font-size: 11px; line-height: 18px; text-align: center; }
.input-tab-count[hidden] { display: none; }
.input-collapsed { display: none !important; }
