/* Storybook Dashboard — dark, warm-copper accent (matches the books' palette).
 *
 * Design rules this file follows, so that adding something later does not undo them:
 *   1. One primary (accent) action per context. Everything else is quiet.
 *   2. Controls are touchable: 36px tall, 14px text. There are no 11px inputs.
 *   3. Separation by space and surface, not by drawing another 1px line.
 *   4. Anything that is not needed to act is folded away, not shrunk.
 */
:root {
  --bg: #0e1116;
  --surface: #151a21;         /* cards, sidebar */
  --surface-2: #1a212a;       /* card heads, hovers */
  --elev: #222a35;            /* inputs, chips */
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .14);
  --text: #e8ecf1;
  --muted: #98a2b1;
  --faint: #6c7684;
  --accent: #e08a4a;          /* molten copper */
  --accent-hi: #f0a066;
  --accent-soft: rgba(224, 138, 74, .13);
  --accent-line: rgba(224, 138, 74, .42);
  --good: #4cc38a;
  --good-soft: rgba(76, 195, 138, .12);
  --warn: #e0b34a;
  --warn-soft: rgba(224, 179, 74, .12);
  --bad: #e0664a;
  --info: #5aa9e0;

  --r-lg: 14px;
  --r: 10px;
  --r-sm: 7px;
  --ctl: 36px;                /* the one control height */
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  /* content stops growing at ~1280px; past that the page grows margins, not rows */
  --gutter: max(28px, calc((100% - 1280px) / 2));

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
::selection { background: var(--accent); color: #1a1206; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: #2a323d; border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #3a4452; background-clip: content-box; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ------------------------------------------------------- */
.app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 54px; padding: 0 16px 0 18px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { font-weight: 650; font-size: 14px; letter-spacing: .2px; color: var(--muted); }
.brand span { color: var(--text); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.body { display: grid; grid-template-columns: 276px 1fr; min-height: 0; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.main { overflow-y: auto; min-width: 0; }

/* ---------- buttons ------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: var(--ctl); padding: 0 14px; border-radius: var(--r-sm);
  background: var(--elev); border: 1px solid var(--line); color: var(--text);
  font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: #2a333f; border-color: var(--line-strong); }
.btn:disabled { opacity: .38; cursor: default; }
.btn:disabled:hover { background: var(--elev); border-color: var(--line); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.quiet { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.quiet:hover { color: var(--text); border-color: var(--line-strong); background: var(--surface-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #1a1206; font-weight: 650; }
.btn.accent:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
.btn.accent:disabled:hover { background: var(--accent); }
.btn.big { height: 40px; padding: 0 18px; font-size: 14px; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: var(--ctl); padding: 0; }
.btn.icon.small { width: 30px; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: rgba(224, 102, 74, .12); border-color: var(--bad); color: var(--bad); }
.btn.save.is-dirty { border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); }
kbd {
  font-family: var(--mono); font-size: 11px; background: rgba(0, 0, 0, .3);
  border: 1px solid var(--line-strong); border-radius: 4px; padding: 1px 5px;
}

/* ---------- inputs ------------------------------------------------------- */
.inp {
  width: 100%; min-height: var(--ctl); padding: 8px 11px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--text); outline: none; font-size: 14px; line-height: 1.55;
  transition: border-color .12s, background .12s;
}
.inp:hover { border-color: var(--line-strong); }
.inp:focus { border-color: var(--accent-line); background: #10141a; }
.inp::placeholder { color: var(--faint); }
textarea.inp { overflow: hidden; min-height: 76px; resize: vertical; }
textarea.inp.mono, input.inp.mono { font-family: var(--mono); font-size: 13px; }
select.inp {
  height: var(--ctl); padding: 0 30px 0 11px; cursor: pointer;
  background-color: var(--elev);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2.5 4.5l3.5 3.5 3.5-3.5' fill='none' stroke='%2398a2b1' stroke-width='1.6' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
  -webkit-appearance: none; appearance: none;
  text-overflow: ellipsis;
}

/* a control with a button glued to its right (model + refresh) */
.with-btn { display: flex; gap: 6px; align-items: center; }
.with-btn .inp { min-width: 0; flex: 1; }

/* one label + control, stacked — the only field layout in this app */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field-hint { font-size: 12px; color: var(--faint); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- sidebar ------------------------------------------------------ */
.sidebar-head { position: sticky; top: 0; z-index: 2; background: var(--surface); padding: 12px; border-bottom: 1px solid var(--line); }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search .inp { padding-left: 34px; }
.gen-list { padding: 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.gen-item {
  display: block; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 11px; border-radius: var(--r); border: 1px solid transparent;
  background: transparent; color: inherit;
}
.gen-item:hover { background: var(--surface-2); }
.gen-item.active { background: var(--accent-soft); border-color: var(--accent-line); }
.gen-item .title {
  display: block; font-weight: 600; font-size: 13.5px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gen-item.active .title { color: var(--accent-hi); }
.gen-item .sub { display: flex; align-items: center; gap: 7px; margin-top: 5px; font-size: 12px; color: var(--faint); }
.gen-item .sub .dim { color: var(--faint); }
.minibar { flex: 1; height: 3px; border-radius: 3px; background: var(--elev); overflow: hidden; max-width: 72px; }
.minibar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.minibar.full span { background: var(--good); }
.livedot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.flag { color: var(--warn); font-size: 12px; }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--line); color: var(--faint); font-size: 12px; }

/* ---------- book header -------------------------------------------------- */
.gen-header {
  position: sticky; top: 0; z-index: 6; background: var(--bg);
  /* the rule runs the full width, the content lines up with the view below it */
  padding: 20px var(--gutter) 0; border-bottom: 1px solid var(--line);
}
.gen-title-row { display: flex; align-items: flex-start; gap: 14px; }
.gen-title { font-size: 23px; font-weight: 700; margin: 0; letter-spacing: -.2px; line-height: 1.25; }
.gen-sub { color: var(--faint); font-size: 12.5px; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gen-sub .slug { font-family: var(--mono); }
.gen-sub .sep { opacity: .5; }
.warnchip {
  color: var(--warn); background: var(--warn-soft); border: 1px solid rgba(224, 179, 74, .3);
  padding: 1px 9px; border-radius: 20px; font-size: 12px;
}
.tabs { display: flex; gap: 4px; margin-top: 16px; }
.tab {
  cursor: pointer; padding: 0 14px; height: 38px; border: none; background: transparent;
  color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; font-size: 13.5px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.view { padding: 24px var(--gutter) 140px; }
.spacer { flex: 1; }

/* ---------- popover menu (⋯) --------------------------------------------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 268px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: 0; border-radius: var(--r-sm); color: var(--text);
  padding: 8px 10px; font-size: 13.5px; cursor: pointer;
}
.menu-item:hover { background: var(--elev); }
.menu-item.is-active { color: var(--accent); }
.menu-item .tick { width: 14px; color: var(--accent); flex: none; }
.menu-item small { display: block; color: var(--faint); font-size: 12px; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); padding: 8px 10px 4px; }

/* ---------- empty state -------------------------------------------------- */
.empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: 40px; gap: 6px; }
.empty-emoji { font-size: 44px; opacity: .7; }
.empty h2 { margin: 0; color: var(--text); font-weight: 650; font-size: 19px; }
.empty p { max-width: 380px; margin: 0 0 10px; font-size: 13.5px; }

/* ---------- cards -------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 18px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.card-head .left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.card-head .num { font-weight: 650; font-size: 13px; color: var(--text); white-space: nowrap; }
.card-head .label {
  color: var(--faint); font-size: 12.5px; font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.card-head .actions { display: flex; gap: 8px; align-items: center; flex: none; }
.dirtydot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: none; flex: none; }
.dirtydot.on { display: inline-block; }
.card-body { padding: 16px; }

.page-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); }
.page-grid > div { padding: 18px; min-width: 0; }
.page-grid .story-col { border-right: 1px solid var(--line); background: rgba(0, 0, 0, .12); }
@media (max-width: 1180px) { .page-grid { grid-template-columns: 1fr; } .page-grid .story-col { border-right: none; border-bottom: 1px solid var(--line); } }
.col-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint);
  margin-bottom: 10px; display: flex; align-items: center; gap: 8px;
}
.col-label .basename { font-family: var(--mono); text-transform: none; letter-spacing: 0; }

/* references list */
.refs { display: flex; flex-direction: column; gap: 6px; }
.ref-row { display: flex; gap: 6px; align-items: center; }
.ref-row .inp { flex: 1; }
.ref-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 12px; background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--accent-line); padding: 1px 9px; border-radius: 20px; font-family: var(--mono);
}
.chip.tiny { font-size: 11px; padding: 0 7px; }
.chip.off { color: var(--faint); background: var(--elev); border-color: var(--line); }
.iconbtn {
  cursor: pointer; background: transparent; border: 1px solid var(--line); color: var(--faint);
  border-radius: var(--r-sm); width: var(--ctl); height: var(--ctl); display: grid; place-items: center; flex: none;
}
.iconbtn:hover { color: var(--bad); border-color: var(--bad); }

/* ---------- image slot --------------------------------------------------- */
.imgslot { margin-top: 0; }
.dropzone {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--r); padding: 22px;
  text-align: center; color: var(--muted); cursor: pointer; background: rgba(0, 0, 0, .18);
  font-size: 13.5px; transition: border-color .12s, background .12s, color .12s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.dropzone.slim { padding: 14px; font-size: 13px; }
.thumb-wrap { position: relative; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); }
.thumb-wrap img { width: 100%; display: block; max-height: 340px; object-fit: contain; background: #090b0e; }
.thumb-tools { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; opacity: 0; transition: opacity .12s; }
.thumb-wrap:hover .thumb-tools { opacity: 1; }
.thumb-tools .btn { background: rgba(10, 12, 16, .85); backdrop-filter: blur(4px); border-color: var(--line-strong); }

/* ---------- section headings / misc -------------------------------------- */
.section-title {
  font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: .07em; margin: 28px 0 14px; display: flex; align-items: center; gap: 10px;
}
.section-title:first-child { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 18px; }
.note { color: var(--faint); padding: 10px 0 18px; font-size: 13.5px; }
.tagline { font-family: var(--mono); color: var(--faint); font-size: 12px; }
.doc-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.doc-err { color: var(--bad); font-size: 13px; }

/* ---------- accordions (sources / templates) ----------------------------- */
.doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 8px; overflow: hidden; }
.doc-head { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; cursor: pointer; gap: 10px; }
.doc-head:hover { background: var(--surface-2); }
.doc-head .nm { font-weight: 600; font-size: 13.5px; }
.doc-head .nm small { color: var(--faint); font-weight: 400; margin-left: 8px; font-family: var(--mono); font-size: 12px; }
.chev { color: var(--faint); transition: transform .15s; flex: none; }
.doc.open .chev { transform: rotate(90deg); }
.doc-body { display: none; padding: 0 16px 16px; }
.doc.open .doc-body { display: block; }
.doc-body textarea { min-height: 340px; }

/* ---------- save bar ----------------------------------------------------- */
.savebar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 22px; z-index: 35;
  display: flex; align-items: center; gap: 14px; padding: 9px 9px 9px 18px;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 999px; box-shadow: var(--shadow);
}
.savebar.hidden { display: none; }
#savebar-count { font-size: 13.5px; color: var(--text); }

/* ---------- modal -------------------------------------------------------- */
.modal-bg { position: fixed; inset: 0; background: rgba(4, 6, 9, .72); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 40; padding: 32px; }
.modal { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-lg); width: min(880px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.modal.wide { width: min(1040px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.modal-head .sub { font-size: 12.5px; color: var(--faint); font-family: var(--mono); margin-top: 2px; }
.modal-body { padding: 20px; overflow: auto; }
.modal-body > textarea, .modal-body textarea.raw {
  width: 100%; min-height: 52vh; font-family: var(--mono); font-size: 13px; line-height: 1.6;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px;
  color: var(--text); outline: none; resize: vertical;
}
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal-err { color: var(--bad); font-size: 13px; }
.modal-note { font-size: 12.5px; color: var(--faint); }
.foot-actions { display: flex; gap: 8px; }

/* ---------- toasts ------------------------------------------------------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--surface-2); border: 1px solid var(--line-strong); border-left: 3px solid var(--good);
  border-radius: var(--r-sm); padding: 11px 16px; min-width: 210px; box-shadow: var(--shadow);
  animation: slidein .18s ease; font-size: 13.5px;
}
.toast.error { border-left-color: var(--bad); }
.toast.info { border-left-color: var(--info); }
@keyframes slidein { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
.hidden { display: none !important; }

/* ---------- run panel ---------------------------------------------------- */
.runwrap { padding: 18px var(--gutter) 0; }
.runpanel { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.runpanel.is-live { border-color: var(--accent-line); }
.run-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; font-size: 13.5px; }
.run-head .run-title { font-weight: 600; }
.runbadge { font-size: 12.5px; padding: 2px 10px; border-radius: 20px; border: 1px solid var(--line); color: var(--muted); }
.runbadge.running { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.runbadge.done { color: var(--good); border-color: rgba(76, 195, 138, .35); background: var(--good-soft); }
.runbadge.failed, .runbadge.aborted, .runbadge.stopped { color: var(--bad); border-color: rgba(224, 102, 74, .35); }
.run-note { color: var(--faint); font-size: 12.5px; }
.runlog {
  margin: 0; padding: 12px 14px; max-height: 260px; overflow: auto; background: #0a0d11;
  border-top: 1px solid var(--line); font-family: var(--mono); font-size: 12px; line-height: 1.65; white-space: pre-wrap;
}
.runline { padding: 1px 0; }
.runline.tool { color: var(--muted); }
.runline.meta { color: var(--faint); }
.runline.say { color: var(--text); }
.runline.good { color: var(--good); font-weight: 600; margin-top: 6px; }
.runline.bad { color: var(--bad); font-weight: 600; margin-top: 6px; }
.runsteps { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; padding: 0 14px 12px; }
.runstep { font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 5px; border: 1px solid var(--line); color: var(--faint); }
.runstep.done { color: var(--good); border-color: rgba(76, 195, 138, .3); }
.runstep.next { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.runstep-note { font-size: 12px; color: var(--muted); margin-left: 6px; }
.runpanel.log-hidden .runlog, .runpanel.steps-hidden .runsteps { display: none; }

/* ---------- Produktion --------------------------------------------------- */
.flow-head {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 18px 20px; margin-bottom: 26px;
}
.flow-head-top { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.flow-count { display: flex; align-items: baseline; gap: 8px; }
.flow-count strong { font-size: 24px; font-weight: 700; letter-spacing: -.3px; }
.flow-count span { color: var(--muted); font-size: 13.5px; }
.flow-bar { height: 5px; border-radius: 4px; background: var(--elev); overflow: hidden; }
.flow-bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s ease; }
.flow-bar.full span { background: var(--good); }

.flow-stage { margin-bottom: 28px; }
.flow-stage-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding-left: 2px; }
.flow-stage-title { font-weight: 650; font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.flow-stage-count { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.flow-stage-count.full { color: var(--good); }
.flow-stage-line { flex: 1; height: 1px; background: var(--line); }

.flow-item { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); margin-bottom: 6px; overflow: hidden; transition: border-color .12s; }
.flow-item:hover { border-color: var(--line-strong); }
.flow-item.is-done { background: transparent; }
/* a step whose references are not rendered yet is not work you can start */
.flow-item.is-blocked { opacity: .6; }
.flow-item.is-blocked:hover, .flow-item.is-blocked.is-open { opacity: 1; }
.flow-item.is-current { border-color: var(--accent-line); background: var(--surface); }
.flow-item.is-open { background: var(--surface); }
.flow-row { display: flex; align-items: center; gap: 14px; padding: 10px 14px; cursor: pointer; min-width: 0; }
.flow-row:hover { background: var(--surface-2); }
.flow-num { font-family: var(--mono); font-size: 12px; color: var(--faint); width: 24px; text-align: right; flex: none; }
.flow-thumb {
  width: 54px; height: 38px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line);
  display: grid; place-items: center; overflow: hidden; flex: none; color: var(--faint); font-size: 13px;
}
.flow-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.is-done .flow-thumb { border-color: rgba(76, 195, 138, .35); }
.flow-name { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.flow-name .nm { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow-name small { color: var(--faint); font-family: var(--mono); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow-tags { display: flex; gap: 4px; flex-wrap: nowrap; overflow: hidden; justify-content: flex-end; }
.flow-badge { font-size: 12px; padding: 2px 10px; border-radius: 20px; white-space: nowrap; flex: none; border: 1px solid transparent; }
.flow-badge.done { color: var(--good); background: var(--good-soft); border-color: rgba(76, 195, 138, .28); }
.flow-badge.ready { color: #1a1206; background: var(--accent); font-weight: 650; }
.flow-badge.open { color: var(--muted); background: var(--elev); }
.flow-badge.blocked { color: var(--faint); background: transparent; border-color: var(--line); font-size: 11.5px; }
.flow-item.is-open .chev { transform: rotate(90deg); }

.flow-body { border-top: 1px solid var(--line); padding: 20px; background: rgba(0, 0, 0, .16); }
.flow-step { margin-bottom: 20px; }
.flow-step:last-child { margin-bottom: 0; }
.flow-step-head {
  display: flex; align-items: center; gap: 9px; margin-bottom: 10px;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint);
}
.flow-step-n {
  width: 18px; height: 18px; border-radius: 50%; background: var(--elev); color: var(--muted);
  font-size: 11px; font-weight: 700; display: grid; place-items: center; flex: none; letter-spacing: 0;
}
.flow-refs { display: flex; gap: 10px; flex-wrap: wrap; }
.flow-ref { width: 118px; }
.flow-ref .flow-ref-img { height: 76px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); overflow: hidden; display: grid; place-items: center; color: var(--faint); font-size: 11.5px; cursor: zoom-in; }
.flow-ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
.flow-ref.missing .flow-ref-img { border-style: dashed; border-color: rgba(224, 179, 74, .5); color: var(--warn); cursor: default; }
.flow-ref-tag { font-family: var(--mono); font-size: 11.5px; color: var(--accent); margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow-ref.missing .flow-ref-tag { color: var(--warn); }
.flow-warn { color: var(--warn); font-size: 12.5px; margin-top: 10px; }
.flow-pagetext { color: var(--muted); font-size: 13.5px; line-height: 1.65; border-left: 2px solid var(--line-strong); padding: 2px 0 2px 14px; white-space: pre-wrap; }
.flow-details summary { cursor: pointer; color: var(--muted); font-size: 13px; list-style: none; display: inline-flex; align-items: center; gap: 6px; }
.flow-details summary::-webkit-details-marker { display: none; }
.flow-details summary::before { content: '▸'; color: var(--faint); }
.flow-details[open] summary::before { content: '▾'; }
.flow-details summary:hover { color: var(--text); }
.flow-prose { margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px 16px; font-size: 13.5px; line-height: 1.65; }
.flow-prose p { margin: 0 0 10px; }
.flow-prose p:last-child { margin-bottom: 0; }
.flow-prose .muted { color: var(--muted); font-size: 13px; }

/* ---------- render panel (collapsed settings + one primary button) ------- */
.rp { display: flex; flex-direction: column; gap: 10px; }
.rp-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.rp-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* what this step will actually send, read-only — edited under Presets */
.rp-line {
  font-family: var(--mono); font-size: 12.5px; color: var(--muted);
  background: rgba(0, 0, 0, .18); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 12px; overflow-x: auto; white-space: nowrap;
}
.rp-presetsel { width: auto; min-width: 190px; max-width: 280px; }
.rp-status { font-size: 12.5px; color: var(--muted); word-break: break-word; }
.rp-status:empty { display: none; }
.rp-status.ok { color: var(--good); }
.rp-status.warn { color: var(--warn); }
.rp-status.run { color: var(--accent); }

/* ---------- render versions ---------------------------------------------- */
.vstrip { display: flex; flex-direction: column; gap: 8px; }
.vstrip:empty { display: none; }
.vhead { display: flex; justify-content: space-between; align-items: baseline; font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); }
.vhead .vsize { text-transform: none; letter-spacing: 0; font-family: var(--mono); }
.vrow { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.vthumb {
  position: relative; flex: 0 0 auto; width: 96px; padding: 0; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden;
}
.vthumb:hover { border-color: var(--line-strong); }
.vthumb img { width: 100%; height: 60px; object-fit: cover; display: block; }
.vthumb.is-pinned { border-color: var(--accent); cursor: default; }
.vlabel { display: block; font-size: 11px; line-height: 1.9; color: var(--muted); text-align: center; }
.vthumb.is-pinned .vlabel { color: var(--accent); }
.vpin { position: absolute; top: 3px; left: 5px; font-size: 12px; color: var(--accent); text-shadow: 0 1px 3px #000; }
.vdel {
  position: absolute; top: 3px; right: 4px; width: 18px; height: 18px; border-radius: 4px;
  display: grid; place-items: center; font-size: 11px; background: rgba(10, 12, 16, .8);
  color: var(--text); opacity: 0; transition: opacity .12s;
}
.vthumb:hover .vdel { opacity: 1; }
.vdel:hover { background: var(--bad); }

/* ---------- banner ------------------------------------------------------- */
.banner {
  background: var(--warn-soft); border: 1px solid rgba(224, 179, 74, .3); color: #e8cf9a;
  border-radius: var(--r); padding: 12px 15px; margin-bottom: 18px; font-size: 13px;
}

/* display:flex on .field outranks the browser's own [hidden] rule, so a hidden
   field (a model with no quality tiers) needs saying twice. */
.field[hidden] { display: none !important; }

/* the picture half of a card: render controls, the image, its versions */
.imgblock { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.flow-body .imgblock { margin-top: 0; padding-top: 0; border-top: 0; }

/* preset row inside the render settings */
.checkline { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; margin-bottom: 16px; }
.checkline input { margin-top: 3px; flex: none; width: 15px; height: 15px; accent-color: var(--accent); }
.checkline strong { display: block; font-weight: 600; font-size: 13.5px; }
.checkline small { display: block; color: var(--faint); font-size: 12.5px; line-height: 1.5; margin-top: 2px; }
.preset-recap { font-family: var(--mono); font-size: 12.5px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 9px 12px; }

/* ---------- Ablauf: one row per pipeline step ---------------------------- */
.steprow {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) minmax(220px, 320px);
  gap: 14px; align-items: start; padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.steprow:last-of-type { border-bottom: 0; }
.steprow.is-off { opacity: .45; }
.steprow.is-off:hover { opacity: .8; }
.steprow-on { display: grid; place-items: center; padding-top: 3px; }
.steprow-on input { width: 16px; height: 16px; accent-color: var(--accent); }
.steprow-name .nm { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 9px; }
.steprow-name small { display: block; color: var(--faint); font-size: 12px; font-family: var(--mono); margin-top: 3px; }
.steprow-name small.hint { font-family: var(--sans); font-size: 12.5px; }
.stepn {
  min-width: 22px; height: 20px; padding: 0 6px; border-radius: 5px; background: var(--elev);
  color: var(--muted); font-family: var(--mono); font-size: 11.5px; display: grid; place-items: center; flex: none;
}
.steprow-ctl { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 720px) { .steprow { grid-template-columns: 24px 1fr; } .steprow-ctl { grid-column: 2; } }

/* ---------- per-book step list in the run panel -------------------------- */
.steplist { border-top: 1px solid var(--line); padding: 6px 14px 12px; }
.steplist-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.steplist-row:last-child { border-bottom: 0; }
.steplist-row.is-off { opacity: .45; }
.steplist-row.is-now { background: var(--accent-soft); border-radius: var(--r-sm); padding-left: 8px; padding-right: 8px; }
.steplist-nm { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.steplist-nm span { font-size: 13.5px; font-weight: 500; }
.steplist-nm small { color: var(--faint); font-size: 11.5px; font-family: var(--mono); }
.steplist-state { width: 52px; text-align: center; color: var(--faint); font-size: 12px; flex: none; }
.steplist-row.is-done .steplist-state { color: var(--good); }
.steplist-row.is-now .steplist-state { color: var(--accent); }
.runbadge.waiting { color: var(--warn); border-color: rgba(224, 179, 74, .4); background: var(--warn-soft); }
.steprow-ctl .field.is-muted { opacity: .4; }

/* ---------- preset editor ------------------------------------------------ */
.preset-cols { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 22px; }
@media (max-width: 760px) { .preset-cols { grid-template-columns: 1fr; } }
.preset-list { display: flex; flex-direction: column; gap: 2px; align-content: start; }
.preset-item {
  display: flex; align-items: center; gap: 8px; text-align: left; width: 100%;
  background: transparent; border: 1px solid transparent; border-radius: var(--r-sm);
  color: var(--text); padding: 9px 11px; font-size: 13.5px; cursor: pointer;
}
.preset-item:hover { background: var(--surface-2); }
.preset-item.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-hi); }
.preset-item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-item .star { color: var(--accent); }
.preset-item.new { color: var(--muted); border-style: dashed; border-color: var(--line); margin-top: 8px; }
.preset-edit .doc-actions { border-top: 1px solid var(--line); padding-top: 16px; }

/* ---------- Vorlagen: the style templates, field by field ---------------- */
.tpl-head { margin: 4px 0 18px; }
.tpl-body .field { margin-bottom: 20px; }
.tpl-key { font-family: var(--mono); font-size: 11px; color: var(--faint); font-weight: 400; margin-left: 8px; }
.tpl-sub {
  border-left: 2px solid var(--line-strong); padding-left: 14px; margin-top: 4px;
  display: flex; flex-direction: column;
}
.tpl-sub .field { margin-bottom: 14px; }
.tpl-sub .field:last-child { margin-bottom: 0; }
.tpl-note {
  background: rgba(0, 0, 0, .18); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 11px 13px; margin-bottom: 20px; color: var(--muted); font-size: 12.5px; line-height: 1.6;
}
.tpl-note .field-label { color: var(--faint); margin-bottom: 4px; }
.tpl-body .ref-row { align-items: flex-start; }
.tpl-body .ref-row .iconbtn { margin-top: 2px; }

/* ---------- Buchvorschau (scene as a printed spread) --------------------- */
.spread-bg { position: fixed; inset: 0; z-index: 40; background: rgba(4, 6, 9, .9); backdrop-filter: blur(3px); display: flex; flex-direction: column; }
.spread-bar { display: flex; align-items: center; gap: 8px; padding: 12px 20px; flex-wrap: wrap; }
.spread-bar .spacer { flex: 1; }
.spread-title { font-weight: 650; font-size: 15px; margin-left: 4px; }
.spread-count { color: var(--faint); font-family: var(--mono); font-size: 12.5px; margin-right: 4px; }
.spread-hint { color: var(--faint); font-size: 12.5px; margin-right: 4px; }
.spread-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px 24px 28px; }

.spread {
  position: relative; container-type: inline-size;
  aspect-ratio: 21 / 9; width: min(100%, calc((100vh - 110px) * 21 / 9));
  overflow: hidden; border-radius: 3px; background: #090b0e;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7);
}
.spread > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }

/* the dark fade: full at the outer edge, gone by the middle */
.spread-shade { position: absolute; inset: 0; pointer-events: none; }
.spread.text-left  .spread-shade { background: linear-gradient(to right, rgba(0, 0, 0, .88) 0%, rgba(0, 0, 0, .78) 20%, rgba(0, 0, 0, .5) 34%, rgba(0, 0, 0, .18) 44%, rgba(0, 0, 0, 0) 50%); }
.spread.text-right .spread-shade { background: linear-gradient(to left,  rgba(0, 0, 0, .88) 0%, rgba(0, 0, 0, .78) 20%, rgba(0, 0, 0, .5) 34%, rgba(0, 0, 0, .18) 44%, rgba(0, 0, 0, 0) 50%); }

/* the gutter: a soft crease with a hint of paper highlight either side */
.spread-fold {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to right, rgba(0, 0, 0, 0) 42%, rgba(0, 0, 0, .12) 46%, rgba(0, 0, 0, .38) 48.8%, rgba(0, 0, 0, .7) 50%,
      rgba(0, 0, 0, .38) 51.2%, rgba(0, 0, 0, .12) 54%, rgba(0, 0, 0, 0) 58%),
    linear-gradient(to right, rgba(255, 255, 255, 0) 47.4%, rgba(255, 255, 255, .1) 48.3%, rgba(255, 255, 255, 0) 49.2%,
      rgba(255, 255, 255, 0) 50.8%, rgba(255, 255, 255, .1) 51.7%, rgba(255, 255, 255, 0) 52.6%);
}
/* optional: the central 8% the templates keep faces out of */
.spread-gutterzone { position: absolute; top: 0; bottom: 0; left: 46%; width: 8%; pointer-events: none; display: none;
  border-left: 1px dashed rgba(224, 138, 74, .7); border-right: 1px dashed rgba(224, 138, 74, .7);
  background: repeating-linear-gradient(45deg, rgba(224, 138, 74, .12) 0 6px, rgba(224, 138, 74, 0) 6px 12px); }
.spread.show-gutter .spread-gutterzone { display: block; }

/* text sits in the middle of its page, scaled with the spread */
.spread-text {
  position: absolute; top: 0; bottom: 0; width: 50%; padding: 0 8cqw 0 7cqw;
  display: flex; flex-direction: column; justify-content: center;
  color: #fff; font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 1.45cqw; line-height: 1.5; text-shadow: 0 1px 0.3cqw rgba(0, 0, 0, .55);
}
.spread.text-left  .spread-text { left: 0; }
.spread.text-right .spread-text { right: 0; padding: 0 7cqw 0 8cqw; }
.spread-text p { margin: 0 0 .8em; }
.spread-text p:last-child { margin-bottom: 0; }
.spread-text p.empty { opacity: .5; font-style: italic; }

/* Batch-Schalter im Preset-Dialog */
.chk { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.chk input { width: 16px; height: 16px; margin: 0; }
.chk input:disabled + span { color: var(--faint); }
.preset-item .chip.tiny { margin-left: auto; }
.preset-pixels { margin: -4px 0 16px; }
