:root {
  --bg: #171b20;
  --panel: #21262d;
  --inset: #1a1f25;
  --side: #262c34;
  --side-active: #1e2329;
  --border: #2f363e;
  --text: #e3e7eb;
  --muted: #95a0ab;
  --dim: #5f6973;
  --green: #3bb54a;
  --yellow: #e8d52a;
  --red: #ec3a55;
  --blue: #5aa0e8;
  --grey: #5f6973;
  --ink: #111418;
  --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Geist', ui-sans-serif, system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.45 var(--sans); }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.dim { color: var(--dim); }
.muted { color: var(--muted); }
.warn { color: var(--yellow); }
.err { color: var(--red); }
.ok { color: var(--green); }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.sidebar { background: var(--side); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 8px; padding: 22px 18px; font-size: 15px; font-weight: 500; }
.brand-mark { width: 20px; height: 20px; border-radius: 3px; background: var(--yellow); }
.sidebar nav { display: flex; flex-direction: column; }
.sidebar nav a { padding: 11px 18px; color: var(--muted); }
.sidebar nav a:hover { color: var(--text); }
.sidebar nav a.active { background: var(--side-active); color: var(--text); }
.sidebar-foot { margin-top: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 8px; background: var(--dim); }
.dot.on { background: var(--green); }
.dot.off { background: var(--red); }
main { overflow: auto; padding: 18px; min-width: 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 4px 4px 14px; }
.page-head h1 { margin: 0; font-size: 28px; font-weight: 300; }

/* ---------- panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 3px; display: flex; flex-direction: column; min-width: 0; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; color: var(--muted); font-size: 14px; font-weight: 300; }
.panel-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }

/* ---------- controls ---------- */
.btn { border: 1px solid var(--border); background: var(--side); border-radius: 3px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #0f1418; font-weight: 500; padding: 9px 18px; }
.btn.primary:disabled { background: var(--side); border-color: var(--border); color: var(--dim); cursor: not-allowed; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.ghost { background: none; }
.link { background: none; border: none; padding: 0; color: var(--blue); cursor: pointer; font-family: var(--mono); font-size: 12px; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--red); }
.btn.danger { color: var(--red); }
.input, .select, .textarea { background: var(--inset); border: 1px solid var(--border); border-radius: 3px; padding: 7px 10px; outline: none; min-width: 0; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--blue); }
.textarea { resize: vertical; width: 100%; min-height: 64px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; }
.field > label .mono { font-size: 11px; color: var(--dim); }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 3px; background: var(--side); font-size: 12px; cursor: pointer; border: 1px solid transparent; }
.chip.active { border-color: var(--blue); }
.chip .x { color: var(--dim); }
.chip .x:hover { color: var(--red); }
.chip.add { background: none; border: 1px dashed var(--border); color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 3px; overflow: hidden; }
.seg button { border: none; background: none; padding: 5px 12px; color: var(--muted); cursor: pointer; font-family: var(--mono); font-size: 12px; }
.seg button.on { background: var(--side); color: var(--text); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--side); border: 1px solid var(--border); padding: 9px 14px; border-radius: 3px; z-index: 100; max-width: 80vw; }
.toast.error { border-color: var(--red); color: #ffb3c0; }

/* ---------- run view ---------- */
.run-grid { display: grid; grid-template-columns: minmax(0, 1fr) 560px; gap: 14px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.shared-row { display: flex; flex-wrap: wrap; gap: 10px; }
.shared-row .field { flex: 1 1 120px; }
.shared-row .field.wide { flex: 2 1 220px; }
.media-input { display: flex; gap: 6px; align-items: center; }
.media-input .input { flex: 1; }
.thumb { width: 36px; height: 24px; border-radius: 2px; object-fit: cover; background: var(--side); flex: none; }
.models-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.models-row > .lbl { color: var(--dim); font-size: 12px; margin-right: 2px; }
.empty { color: var(--dim); padding: 24px 14px; text-align: center; }

.popover { position: absolute; z-index: 50; width: 520px; max-height: 460px; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 3px; box-shadow: 0 16px 40px rgba(0,0,0,.45); }
.popover-head { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--border); }
.popover-head .input { flex: 1; }
.popover-list { overflow: auto; }
.result { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 8px 10px; cursor: pointer; align-items: center; }
.result:hover { background: var(--inset); }
.result img, .result .noimg { width: 40px; height: 40px; border-radius: 3px; object-fit: cover; background: var(--side); }
.result .r-name { font-weight: 500; }
.result .r-sub { font-family: var(--mono); font-size: 11px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .r-prov { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.popover-section { padding: 8px 10px 4px; font-size: 11px; color: var(--dim); font-family: var(--mono); text-transform: uppercase; }

/* options (CLI) */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 0 14px 10px; }
.tabs:empty { display: none; }
.tabs button { border: none; background: none; padding: 3px 8px; border-radius: 3px; color: var(--dim); font-family: var(--mono); font-size: 11px; cursor: pointer; }
.tabs button.on { background: var(--side); color: var(--text); }
.endpoint { font-family: var(--mono); font-size: 12px; color: var(--dim); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.endpoint select { font-size: 12px; padding: 2px 6px; }
.cli { display: flex; flex-direction: column; font-family: var(--mono); font-size: 12px; }
.cli-row { display: grid; grid-template-columns: 172px 172px minmax(0, 1fr); align-items: center; padding: 5px 8px; gap: 8px; min-height: 32px; }
.cli-row:nth-child(even) { background: var(--inset); }
.cli-row.head { color: var(--dim); font-size: 10px; border-bottom: 1px solid var(--border); background: none !important; min-height: 0; }
.cli-name { display: flex; align-items: center; gap: 6px; color: var(--blue); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cli-name::before { content: ''; flex: none; width: 5px; height: 5px; border-radius: 50%; }
.cli-name.changed::before { background: var(--yellow); }
.cli-name.req { color: #8cc4ff; }
.cli-meta { color: var(--dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cli-val { min-width: 0; display: flex; align-items: center; gap: 4px; }
.cli-val .input, .cli-val .select { width: 100%; padding: 3px 6px; font-family: var(--mono); font-size: 12px; }
.cli-val .input.unset, .cli-val .select.unset { color: var(--dim); }
.cli-val .shared { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.cli-val .shared:hover { color: var(--muted); }
.cli-row.missing .cli-name { color: var(--red); }
.cli-json { grid-column: 1 / -1; }
.cli-json .textarea { font-family: var(--mono); font-size: 12px; min-height: 90px; }
.cli-foot { display: flex; gap: 16px; padding: 10px 8px 0; color: var(--dim); font-size: 11px; flex-wrap: wrap; }
.notices { display: flex; flex-direction: column; gap: 4px; font-family: var(--mono); font-size: 11px; padding: 6px 8px 0; }

.runbar { flex-direction: row; align-items: center; justify-content: space-between; padding: 12px 14px; gap: 14px; }
.runbar .total { font-family: var(--mono); font-size: 20px; font-weight: 500; }
.runbar .breakdown { font-family: var(--mono); font-size: 11px; color: var(--dim); }

/* results */
.result-card { border: 1px solid; border-radius: 3px; overflow: hidden; }
.result-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; color: var(--ink); font-weight: 500; }
.result-head .rh-status { font-family: var(--mono); font-size: 12px; }
.result-body { display: flex; gap: 14px; padding: 12px; }
.preview { width: 240px; height: 135px; flex: none; border: 1px solid var(--border); border-radius: 2px; background: #12161a; display: flex; align-items: center; justify-content: center; color: var(--muted); overflow: hidden; }
.preview video, .preview img { width: 100%; height: 100%; object-fit: contain; background: #000; }
.preview audio { width: 92%; }
.metrics { display: flex; flex-direction: column; gap: 3px; font-family: var(--mono); font-size: 12px; min-width: 0; flex: 1; }
.metric { display: grid; grid-template-columns: 86px minmax(0, 1fr); gap: 8px; }
.metric .k { color: var(--dim); }
.metric .v { overflow-wrap: anywhere; }
.metric .v small { color: var(--dim); font-size: 11px; }
.actions { display: flex; gap: 14px; margin-top: auto; padding-top: 6px; flex-wrap: wrap; }
.st-succeeded { --c: var(--green); }
.st-queued, .st-running, .st-pending, .st-finalizing { --c: var(--yellow); }
.st-failed { --c: var(--red); }
.st-canceled { --c: var(--grey); }
.result-card { border-color: color-mix(in srgb, var(--c) 55%, transparent); }
.result-card .result-head { background: var(--c); }
.result-card .result-body { background: color-mix(in srgb, var(--c) 5%, transparent); }
.raw { margin: 0 12px 12px; padding: 10px; background: var(--inset); border: 1px solid var(--border); border-radius: 3px; font-family: var(--mono); font-size: 11px; white-space: pre-wrap; word-break: break-all; max-height: 260px; overflow: auto; }

/* ---------- log ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 3px; }
table.log { width: 100%; border-collapse: collapse; font-size: 12px; }
table.log th { text-align: left; font-family: var(--mono); font-weight: 400; font-size: 10px; color: var(--dim); background: var(--side); padding: 8px 10px; position: sticky; top: 0; white-space: nowrap; }
table.log td { padding: 9px 10px; border-top: 1px solid var(--border); white-space: nowrap; }
table.log td.num { font-family: var(--mono); text-align: right; }
table.log th.num { text-align: right; }
table.log tr.row { cursor: pointer; }
table.log tr.row:hover td { background: var(--inset); }
table.log tr.sel td { background: color-mix(in srgb, var(--blue) 10%, transparent); }
table.log td.status::before { content: '●'; margin-right: 6px; color: var(--c); }
table.log tr.detail td { white-space: normal; background: var(--inset); }
.detail-grid { display: grid; grid-template-columns: 260px 1fr; gap: 16px; padding: 4px 0; }
.detail-grid pre { margin: 0; font-family: var(--mono); font-size: 11px; white-space: pre-wrap; word-break: break-all; max-height: 240px; overflow: auto; }
.log-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 2px; color: var(--muted); }

/* ---------- models ---------- */
.models-grid { display: flex; flex-direction: column; gap: 14px; }
.model-card .mc-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; }
.mc-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mc-title b { font-weight: 500; font-size: 14px; }
.mc-title span { font-family: var(--mono); font-size: 11px; color: var(--dim); }
table.prices { width: 100%; border-collapse: collapse; font-size: 12px; font-family: var(--mono); }
table.prices th { text-align: left; font-weight: 400; color: var(--dim); font-size: 10px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.prices td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.prices tr.future td { color: var(--dim); }
table.prices tr.expired td { color: var(--dim); text-decoration: line-through; }
.price-form { display: grid; grid-template-columns: 110px 100px 120px 90px 120px 120px 1fr auto; gap: 6px; align-items: center; }
.price-form .input, .price-form .select { padding: 4px 6px; font-family: var(--mono); font-size: 12px; width: 100%; }
.keys { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.login { max-width: 360px; margin: 18vh auto; }

@media (max-width: 1180px) {
  .run-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; }
  .sidebar nav { flex-direction: row; }
  .sidebar-foot { display: none; }
  .result-body { flex-direction: column; }
  .preview { width: 100%; height: auto; aspect-ratio: 16 / 9; }
  .cli-row { grid-template-columns: 130px 1fr; }
  .cli-meta { grid-column: 1 / -1; }
  .price-form { grid-template-columns: 1fr 1fr; }
}

/* ======================================================= templates additions */
.brand-mark.t { background: var(--blue); }
.head-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tmpl-grid { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 14px; align-items: start; }
.st-done { --c: var(--green); }
.st-stale { --c: #7a6f3a; }
.st-none { --c: var(--border); }
.st-partial, .st-draft { --c: var(--grey); }

/* inputs */
.drop { border: 1px dashed var(--border); border-radius: 3px; padding: 14px; text-align: center; color: var(--dim); cursor: pointer; font-size: 12px; }
.drop.over { border-color: var(--blue); color: var(--text); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.tthumb { position: relative; width: 72px; }
.tthumb img { width: 72px; height: 72px; object-fit: cover; border-radius: 3px; border: 1px solid var(--border); background: var(--inset); display: block; }
.tthumb span { display: block; font-family: var(--mono); font-size: 10px; color: var(--dim); text-align: center; margin-top: 2px; }
.tthumb button { position: absolute; top: 2px; right: 2px; border: none; background: rgba(0,0,0,.6); color: #fff; border-radius: 2px; width: 18px; height: 18px; cursor: pointer; line-height: 1; }
.presets-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.pp { border: 1px solid var(--border); border-radius: 3px; padding: 0; background: var(--inset); cursor: pointer; text-align: left; overflow: hidden; }
.pp img, .pp .noimg { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--side); }
.pp span { display: block; padding: 4px 6px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pp.on { border-color: var(--blue); }
.pp.on span { color: var(--text); }
.stars { display: flex; gap: 2px; }
.stars button { background: none; border: none; color: var(--dim); font-size: 18px; cursor: pointer; padding: 0 2px; line-height: 1; }
.stars button.on { color: var(--yellow); }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 8px; font-family: var(--mono); font-size: 12px; }
.kv .k { color: var(--dim); }

/* pipeline */
.pipeline { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.step { border: 1px solid color-mix(in srgb, var(--c) 60%, transparent); border-radius: 3px; overflow: hidden; background: var(--panel); }
.step.st-none, .step.st-stale { border-style: dashed; }
.step-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: color-mix(in srgb, var(--c) 22%, var(--panel)); }
.step.st-done .step-head, .step.st-running .step-head, .step.st-failed .step-head { background: var(--c); color: var(--ink); }
.step.st-done .step-head .dim, .step.st-running .step-head .dim, .step.st-failed .step-head .dim { color: rgba(17,20,24,.65); }
.step-title { display: flex; align-items: baseline; gap: 10px; font-weight: 500; min-width: 0; }
.step-title .mono { font-size: 11px; font-weight: 400; }
.step-actions { display: flex; gap: 6px; align-items: center; flex: none; }
.step-actions .btn { padding: 4px 10px; font-size: 12px; background: rgba(0,0,0,.15); border-color: rgba(0,0,0,.2); color: inherit; }
.step.st-none .step-actions .btn, .step.st-stale .step-actions .btn { background: var(--side); border-color: var(--border); }
.step-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.step-meta { display: flex; gap: 14px; flex-wrap: wrap; font-family: var(--mono); font-size: 11px; color: var(--dim); align-items: center; }
.step-meta b { color: var(--muted); font-weight: 400; }
.subtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.subtabs button { border: none; background: none; padding: 6px 10px; color: var(--dim); cursor: pointer; font-size: 12px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subtabs button.on { color: var(--text); border-bottom-color: var(--blue); }
.subtabs .spacer { flex: 1; }
pre.out { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 12px; line-height: 1.55; background: var(--inset); border: 1px solid var(--border); border-radius: 3px; padding: 12px; max-height: 560px; overflow: auto; }
textarea.out-edit { font-family: var(--mono); font-size: 12px; line-height: 1.55; min-height: 420px; }
.o-character { background: color-mix(in srgb, #b07cf0 22%, transparent); }
.o-product { background: color-mix(in srgb, #e8a33a 20%, transparent); }
.o-shots { background: color-mix(in srgb, var(--blue) 16%, transparent); }
.o-dialogue { background: color-mix(in srgb, var(--green) 22%, transparent); }
.o-frame { }
.o-closing { background: color-mix(in srgb, var(--grey) 30%, transparent); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--dim); align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-family: var(--mono); font-size: 12px; }
.checks li::before { content: '✓ '; color: var(--green); }
.checks li.bad { color: var(--red); }
.checks li.bad::before { content: '✗ '; color: var(--red); }
.lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lines li { display: grid; grid-template-columns: 96px 1fr auto; gap: 10px; font-size: 12px; align-items: baseline; }
.lines .when { font-family: var(--mono); color: var(--dim); }
.lines .fit { font-family: var(--mono); color: var(--dim); font-size: 11px; }
.lines .fit.over { color: var(--red); }
.model-row { display: flex; gap: 14px; }
.stale-note { font-size: 12px; color: #c9b85a; }
.runall { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* editor */
.tabsbar { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabsbar button { border: none; background: none; padding: 8px 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabsbar button.on { color: var(--text); border-bottom-color: var(--blue); }
.block { display: flex; flex-direction: column; gap: 8px; }
.block-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.block-head b { font-weight: 500; }
.block textarea { font-family: var(--mono); font-size: 12px; line-height: 1.55; min-height: 280px; }
.block textarea.tall { min-height: 560px; }
pre.diff { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 12px; line-height: 1.55; background: var(--inset); border: 1px solid var(--border); border-radius: 3px; padding: 12px; max-height: 620px; overflow: auto; }
pre.diff .same { color: var(--dim); }
pre.diff ins { background: color-mix(in srgb, var(--green) 25%, transparent); text-decoration: none; }
pre.diff del { background: color-mix(in srgb, var(--red) 25%, transparent); }
.dirty-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); margin-left: 6px; }
.json-edit { font-family: var(--mono); font-size: 12px; min-height: 220px; }
.step-edit { border: 1px solid var(--border); border-radius: 3px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--inset); }
.step-edit-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.step-edit-head .input { flex: 1; min-width: 140px; }
.list-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 14px; align-items: center; padding: 10px 12px; border-top: 1px solid var(--border); }
.list-row:first-child { border-top: none; }

/* runs */
.runs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.run-card { background: var(--panel); border: 1px solid var(--border); border-radius: 3px; overflow: hidden; display: flex; flex-direction: column; }
.run-card:hover { border-color: var(--muted); }
.run-card .media { aspect-ratio: 9 / 12; background: #000 center / cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--dim); overflow: hidden; position: relative; }
.run-card .media video, .run-card .media img { width: 100%; height: 100%; object-fit: cover; }
.run-card .media .badge { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.65); padding: 2px 6px; border-radius: 2px; font-family: var(--mono); font-size: 10px; color: var(--muted); }
.run-card .media, .run-card .info { cursor: pointer; }
.run-card .info { padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.run-card .info .row { display: flex; justify-content: space-between; gap: 8px; }
.run-card .info .mono { font-size: 11px; color: var(--dim); }
.preset-card { display: grid; grid-template-columns: 140px 1fr; gap: 14px; padding: 14px; }
.preset-card .imgs { display: flex; flex-direction: column; gap: 8px; }
.preset-card .imgs img, .preset-card .imgs .noimg { width: 140px; aspect-ratio: 1; object-fit: cover; border-radius: 3px; border: 1px solid var(--border); background: var(--inset); }
.row-fields { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row-fields .field { flex: 1 1 140px; }

@media (max-width: 1100px) { .tmpl-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .preset-card { grid-template-columns: 1fr; } .lines li { grid-template-columns: 1fr; } }

/* step editor */
.scards { display: flex; flex-direction: column; gap: 0; }
.scard { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; }
.scard-rail { display: flex; flex-direction: column; align-items: center; position: relative; }
.scard-rail::after { content: ''; position: absolute; top: 34px; bottom: -2px; width: 1px; background: var(--border); }
.scard:last-of-type .scard-rail::after { display: none; }
.scard-n { margin-top: 12px; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 11px; color: var(--muted); background: var(--panel); }
.scard-main { background: var(--panel); border: 1px solid var(--border); border-radius: 3px; margin-bottom: 12px; min-width: 0; }
.scard-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.scard-title { flex: 1; min-width: 120px; background: none; border-color: transparent; font-weight: 500; }
.scard-title:hover { border-color: var(--border); }
.scard-id { flex: 0 1 120px; font-size: 11px; color: var(--muted); }
.kind-badge { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 2px 6px; border-radius: 2px; background: var(--side); color: var(--muted); white-space: nowrap; }
.scard-head .btn.on { border-color: var(--blue); color: var(--blue); }
.scard-issues { padding: 6px 12px 0; font-size: 11px; }
.sf-form { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.sf-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.sf { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sf-row .sf { flex: 1 1 180px; }
.sf-l { font-size: 11px; color: var(--muted); }
.ref-text { display: flex; flex-direction: column; gap: 4px; }
.ref-text .textarea { font-family: var(--mono); font-size: 12px; min-height: 0; }
.ref-tools { display: flex; justify-content: flex-end; }
.ref-select { font-size: 11px; padding: 3px 6px; max-width: 240px; }
.cli.map .cli-row { grid-template-columns: 180px minmax(0, 1fr) minmax(0, 220px); }
.cli.map .cli-row.set .cli-name::before { background: var(--yellow); }
.cli.map .cli-val { flex-wrap: wrap; }
.cli.map .cli-val .input, .cli.map .cli-val .select { flex: 1 1 140px; min-width: 0; font-size: 11px; padding: 3px 6px; }
.list-ctl { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.list-item { display: flex; gap: 4px; }
.scard-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-left: 44px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 3px; }

.run-card .in-thumbs { display: flex; gap: 4px; }
.run-card .in-thumbs img { width: 28px; height: 28px; object-fit: cover; border-radius: 2px; background: var(--side); }
.run-card .one-line { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-card .qa { color: var(--muted); }
.run-card .info .row.mono { font-family: var(--mono); font-size: 11px; color: var(--muted); }

.sprompts { display: flex; flex-direction: column; gap: 6px; padding: 0 12px 12px; }
.sblock { border: 1px solid var(--border); border-radius: 3px; background: var(--inset); }
.sblock-head { display: flex; align-items: center; gap: 10px; padding: 6px 10px; flex-wrap: wrap; }
.sblock-head .mono.dim { font-size: 11px; margin-left: auto; }
.sblock-peek { padding: 0 10px 8px; font-size: 11px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sblock-text { border: none; border-top: 1px solid var(--border); border-radius: 0; min-height: 260px; max-height: 60vh; font-family: var(--mono); font-size: 12px; background: var(--panel); }
.seg.small button { padding: 2px 8px; font-size: 11px; }

.sf-line { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.kv { display: inline-flex; align-items: center; gap: 6px; }
.kv-l { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.compact { max-width: 420px; padding: 3px 8px !important; font-size: 12px !important; }
select.compact { width: auto !important; }
.wiring { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 11px; }
.wiring .sf-line { width: 100%; }
