/* High contrast for bright surroundings. One look per role:
   data      white tabular numbers
   label     light gray
   input     recessed: black, bright border
   button    raised: clearly lighter than the panel; the step's action is solid blue
   link      blue text
   choice    radio rows in one recessed box; each row says what it gives you */
:root {
  --viewer: #08080a;
  --panel: #232429;
  --inset: #000;
  --inset-border: #5f636c;
  --row-line: #2e3036;
  --row-hover: #16171a;
  --row-on: #173063;
  --raised: #565a64;
  --raised-hover: #666b76;
  --divider: #42454c;
  --text: #fff;
  --label: #d3d6dc;
  --accent: #3b7cff;
  --accent-hover: #5c93ff;
  --link: #8cb6ff;
  --warn: #ffb547;
  --error: #ff7a70;
  --ok: #4fd465;
  --r: 6px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body { background: var(--viewer); color: var(--text); font: 12px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
p { margin: 0; }
.label { color: var(--label); }
.data { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.data.big { font-size: 15px; }
.warn { color: var(--warn); }
.error { color: var(--error); }
.spacer { flex: 1; }
button, select, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 1px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 32px; padding: 0 14px; border: 0; border-radius: var(--r);
  background: var(--raised); color: var(--text); font-weight: 600; white-space: nowrap; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 1px 3px rgba(0,0,0,.6);
}
.btn:hover:not(:disabled) { background: var(--raised-hover); }
.btn.primary { background: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.on { background: var(--text); color: #000; }
.btn.wide { width: 100%; height: 36px; justify-content: space-between; font-size: 13px; }
.btn.wide:not(:has(.price)) { justify-content: center; }
.btn.grow { flex: 1; }
.price { font-weight: 500; font-variant-numeric: tabular-nums; }
.buttons { display: flex; gap: 8px; }
.buttons .btn { flex: 1; }
.icon { width: 28px; height: 28px; flex: none; border: 0; border-radius: var(--r); background: none; color: var(--label); font-size: 13px; cursor: pointer; }
.icon:hover:not(:disabled) { background: var(--raised); color: var(--text); }
.link { align-self: flex-start; padding: 0; border: 0; background: none; color: var(--link); font-weight: 600; cursor: pointer; }
.link:hover:not(:disabled) { text-decoration: underline; }
.link[role=button] { user-select: none; }
.link-row { display: flex; justify-content: space-between; align-items: baseline; }

/* inputs */
select, input[type="text"], input[type="password"], textarea {
  width: 100%; border: 1px solid var(--inset-border); border-radius: var(--r); background: var(--inset); color: var(--text);
}
select, input[type="text"], input[type="password"] { height: 32px; padding: 0 8px; }
textarea { padding: 8px 10px; line-height: 1.5; resize: vertical; }
select:hover:not(:disabled), input:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: #8a8e97; }
::placeholder { color: #9a9ea7; }
input[type="range"] { width: 100%; margin: 4px 0; accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { width: 15px; height: 15px; margin: 0; flex: none; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check > .data { margin-left: auto; }

/* choices */
.options { display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--inset-border); border-radius: var(--r); background: var(--inset); }
.option { display: grid; grid-template-columns: 15px auto 1fr auto; align-items: center; column-gap: 12px; min-height: 36px; padding: 6px 12px; cursor: pointer; }
.option:has(.option-text) { grid-template-columns: 15px 1fr; align-items: start; padding: 10px 12px; }
.option:has(.option-text) input { margin-top: 1px; }
.option-text { display: flex; flex-direction: column; gap: 3px; }
.option-desc { color: var(--label); line-height: 1.45; }
.option + .option { border-top: 1px solid var(--row-line); }
.option:hover:not(.off):not(.on):not(:has(input:disabled)) { background: var(--row-hover); }
.option.on { background: var(--row-on); }
.option.off { cursor: default; color: #8d9199; }
.option.off .option-detail, .option.off .option-value, .option.off .option-hint { color: #8d9199; }
.option-hint { color: var(--label); text-align: right; }
.option-name { font-weight: 600; min-width: 56px; }
.options.wide .option-name { min-width: 104px; }
.option-detail { color: var(--label); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.option-value { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }

.spinner { display: inline-block; width: 13px; height: 13px; flex: none; vertical-align: -2px; border: 2px solid var(--raised); border-top-color: var(--accent-hover); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* layout */
.app { display: flex; height: 100%; }
.side { width: 380px; flex: none; display: flex; flex-direction: column; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--divider); }
.stage { flex: 1; display: flex; min-width: 0; position: relative; }
.side-head { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; height: 64px; padding: 0 6px; background: var(--panel); border-bottom: 1px solid var(--divider); }
/* sidebar header: a <fieldset> (locked during runs), which cannot center its flex content vertically, so the 52px menu
   button gets 6px of padding on every side instead */
.side > .side-head { height: auto; padding: 6px; }
.spent { margin-left: auto; color: var(--label); font-variant-numeric: tabular-nums; }

/* steps */
.step { position: relative; border-bottom: 1px solid var(--divider); }
/* export: pinned to the bottom of the sidebar */
.export { position: sticky; bottom: 0; z-index: 4; margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding: 16px 22px 18px; background: var(--panel); border-top: 1px solid var(--divider); box-shadow: 0 -6px 16px rgba(0,0,0,.35); }
.export-row { display: flex; gap: 8px; }
.export .format { width: 88px; flex: none; height: 36px; }
.step-head { padding-bottom: 8px; }
.step.sel::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.step-head { position: relative; width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 18px 22px 14px; border: 0; background: none; color: var(--text); text-align: left; cursor: pointer; }
.step-head:disabled { cursor: default; }
.step.off .step-head, .step.off .step-body { opacity: .45; }
.export.off .step-title { opacity: .45; } /* like a disabled step while there is nothing to download */
.step-title { display: inline-flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; }
.step-n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--raised); font-size: 12px; font-weight: 700; }
.step.sel .step-n { background: var(--accent); }
.step-desc { color: var(--label); line-height: 1.45; }
.step-summary { color: var(--label); font-variant-numeric: tabular-nums; }
.step-chev { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); font-size: 22px; line-height: 1; color: var(--label); }
.step-head:hover:not(:disabled) .step-chev { color: var(--text); }
.step-head:hover:not(:disabled) { background: rgba(255,255,255,.03); }
.step-head:disabled:not(.step.off *) { cursor: default; }
.step-body { display: flex; flex-direction: column; gap: 20px; padding: 4px 22px 24px; }
.step-head.source { flex-direction: row; align-items: center; gap: 12px; }
.source-text { display: flex; flex-direction: column; gap: 2px; }
.thumb { width: 44px; height: 44px; flex: none; object-fit: cover; border-radius: 4px; background: #000; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field.slider { gap: 2px; }
.field-note { color: var(--label); line-height: 1.45; }
.field-label { display: flex; align-items: baseline; justify-content: space-between; color: var(--label); font-weight: 600; }

.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.prompt-preview { display: block; width: 100%; padding: 8px 10px; border: 1px solid var(--inset-border); border-radius: var(--r); background: var(--inset); color: var(--text); text-align: left; line-height: 1.45; cursor: text; }
.prompt-preview:hover:not(:disabled) { border-color: #8a8e97; }

.versions { display: flex; flex-wrap: wrap; gap: 8px; }
.version { position: relative; }
.version-pick { display: block; padding: 0; border: 2px solid transparent; border-radius: 6px; background: none; cursor: pointer; }
.version.on .version-pick { border-color: var(--accent-hover); }
.version-img { display: block; width: 60px; height: 40px; object-fit: cover; border-radius: 4px; background: #000; }
.version-del { position: absolute; top: -7px; right: -7px; display: none; width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--raised-hover); color: var(--text); font-size: 11px; cursor: pointer; }
.version:hover .version-del { display: block; }
/* tile versions: square; selection is the blue ring, a version that may have drifted has an orange border */
.tile-version .version-img { width: 56px; height: 56px; }
.tile-version.on .version-pick { border-color: transparent; outline: 2px solid var(--accent-hover); outline-offset: 1px; }
.tile-version.drift .version-pick { border-color: var(--warn); }

.tile-summary { display: flex; flex-wrap: wrap; column-gap: 8px; row-gap: 4px; }

/* running action: progress fills the button */
.btn.running { position: relative; overflow: hidden; background: #1d3f86; }
.btn.running:hover:not(:disabled) { background: #22488f; }
.btn.running[aria-busy] { cursor: progress; }
.btn.running[aria-busy]:hover { background: #1d3f86; }
.btn.running > span:not(.fill) { position: relative; }
.fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); transition: width .4s; }
.fill.indeterminate { width: 35%; animation: sweep 1.4s ease-in-out infinite; }
@keyframes sweep { from { left: -35%; } to { left: 100%; } }

/* Disabled: one look for every control, the same whether a control is off by itself or because the sidebar is
   locked (a run in progress, or no image yet: a disabled <fieldset> disables everything inside it). */
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.side-body { flex: 1; display: flex; flex-direction: column; }
:is(.btn, .link, .icon, .menu-button, .prompt-preview, .version-pick, select, textarea, input):disabled { opacity: .45; cursor: default; }
.check:has(input:disabled) { opacity: .45; cursor: default; }
.options:not(:has(input:enabled)) { opacity: .45; }
.option:has(input:disabled) { cursor: default; }
.version-del:disabled { display: none !important; }
.side-body:disabled .step:not(.sel) .step-head { opacity: .45; }

.result { display: flex; align-items: baseline; justify-content: space-between; }
.format { width: 90px; flex: none; }

/* confirmation popover (popover.js): opens from the control that asked, arrow pointing at it */
.popover { position: fixed; z-index: 60; width: max-content; max-width: 300px; display: flex; flex-direction: column; gap: 14px;
  padding: 14px; background: #34363d; border: 1px solid var(--divider); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.8);
  animation: pop .12s ease-out; }
.popover.from-top { transform-origin: var(--arrow-x) 0; }
.popover.from-bottom { transform-origin: var(--arrow-x) 100%; }
@keyframes pop { from { opacity: 0; transform: scale(.94); } }
/* a wide dark falloff behind it, so the rest of the UI recedes (owner's request; an exception to "no gradients") */
.popover-shade { position: fixed; z-index: 59; width: 1600px; height: 1600px; transform: translate(-50%, -50%); pointer-events: none;
  background: radial-gradient(closest-side, rgba(0,0,0,.8), rgba(0,0,0,.55) 40%, transparent); animation: shade .15s ease-out; }
@keyframes shade { from { opacity: 0; } }
.popover p { font-size: 13px; font-weight: 600; line-height: 1.45; }
.popover .buttons .btn { min-width: 96px; }
.popover-arrow { position: absolute; left: calc(var(--arrow-x) - 7px); width: 14px; height: 14px; background: #34363d; border: 1px solid var(--divider); transform: rotate(45deg); }
.from-top .popover-arrow { top: -8px; border-right: 0; border-bottom: 0; }
.from-bottom .popover-arrow { bottom: -8px; border-left: 0; border-top: 0; }
/* a destructive confirmation (delete, discard): red, so it never reads as the blue next step */
.btn.danger { background: #d4382e; }
.btn.danger:hover:not(:disabled) { background: #e5483e; }

/* dialog */
.overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.65); }
.dialog { width: min(680px, 100%); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--divider); border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.7); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 22px; border-bottom: 1px solid var(--divider); }
.dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 12px 20px; }
.dialog-body textarea { font-size: 13px; }
.dialog-row { display: grid; grid-template-columns: 1fr 200px; gap: 12px; }
.dialog { width: min(760px, 100%); }
.dialog-body { gap: 0; padding: 0; }
.editor-part { display: flex; flex-direction: column; gap: 10px; padding: 18px 22px; }
.editor-part + .editor-part { border-top: 1px solid var(--divider); }
.editor-part:first-child { background: rgba(0,0,0,.18); }
.editor-row { display: flex; gap: 8px; }
.editor-row select { width: 200px; flex: none; }
.editor-row .btn { flex: 1; }
.prompt-text { font-size: 13px; }
.dialog-foot { display: flex; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--divider); }

/* project menu */
.menu { position: relative; min-width: 0; flex: 1; }
.menu-button { display: flex; align-items: center; gap: 10px; width: 100%; height: 52px; padding: 0 12px 0 4px; /* 44px thumb: 4px to the button edge on every side */ text-align: left; border: 0; border-radius: var(--r); background: none; color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.menu-button:hover:not(:disabled) { background: var(--raised); }
.menu-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { margin-left: auto; color: var(--label); }
.menu-button .menu-text { flex: 1; }
.menu-pop { position: absolute; left: 0; top: 38px; z-index: 20; width: 340px; max-height: 70vh; overflow-y: auto; padding: 6px; background: #34363d; border: 1px solid var(--divider); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.8); }
.menu-item { display: flex; align-items: center; width: 100%; height: 32px; padding: 0 10px; border: 0; border-radius: var(--r); background: none; color: var(--text); text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--raised); }
.menu-item.strong { font-weight: 600; }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--divider); }
.menu-row { display: flex; align-items: center; gap: 4px; padding-right: 4px; border-radius: var(--r); }
.menu-row.on { background: var(--raised); }
.menu-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 6px 10px 4px; }
.menu-open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 5px; border: 0; border-radius: var(--r); background: none; color: var(--text); text-align: left; cursor: pointer; }
.menu-open:hover { background: var(--raised-hover); }
.menu-open .thumb { width: 36px; height: 36px; }
.menu-text { display: flex; flex-direction: column; min-width: 0; }
.menu-text span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* viewer */
.viewer { flex: 1; position: relative; overflow: hidden; background: var(--viewer); }
.viewer canvas { display: block; touch-action: none; }
.viewer-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--label); }
.floaty { position: absolute; z-index: 6; display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 12px; background: var(--panel); border: 1px solid var(--divider); border-radius: var(--r); }
.floaty.top-right { top: 12px; right: 12px; }
.account { gap: 0; padding-left: 0; }
.account .stat { display: flex; align-items: baseline; gap: 6px; padding: 0 14px; border-right: 1px solid var(--divider); }
.account .stat.low .data { color: var(--warn); }
.account button { margin-left: 4px; }
.floaty button { height: 26px; padding: 0 10px; border: 0; border-radius: 4px; background: var(--raised); color: var(--text); font-weight: 600; cursor: pointer; }
.floaty button:hover { background: var(--raised-hover); }
.zoom { position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; background: var(--panel); border: 1px solid var(--divider); border-radius: var(--r); }
.zoom .check { padding-right: 8px; }
.zoom button { height: 26px; padding: 0 10px; border: 0; border-radius: 4px; background: var(--raised); color: var(--text); font-weight: 600; cursor: pointer; }
.zoom button:hover { background: var(--raised-hover); }
.zoom span { min-width: 48px; text-align: center; color: var(--label); font-variant-numeric: tabular-nums; }

.inspector { position: absolute; top: 60px; right: 12px; bottom: 58px; z-index: 7; width: 340px; overflow-y: auto; background: var(--panel); border: 1px solid var(--divider); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.inspector .side-head { position: sticky; top: 0; border-radius: 8px 8px 0 0; }
.zoomable { cursor: zoom-in; }
.inspector .side-head { padding: 0 8px 0 16px; }
.inspector .side-head .icon { margin-left: auto; }
.inspector-body { display: flex; flex-direction: column; gap: 14px; padding: 16px 20px 20px; }
.inspector figure { margin: 0; }
.inspector canvas { display: block; width: 100%; height: auto; border-radius: 4px; background: #000; }
.inspector figcaption { display: flex; justify-content: space-between; margin-top: 4px; color: var(--label); font-weight: 600; }
.status { font-weight: 600; }
.status.done { color: var(--ok); }
.status.flagged { color: var(--warn); }
.status.error { color: var(--error); }
.status.running { color: var(--link); }
.status.pending, .status.blending, .status.queued { color: var(--label); }

.activity { position: absolute; left: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; max-width: 60%; }
.activity-row { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 4px 4px 4px 12px; background: var(--panel); border: 1px solid var(--divider); border-radius: var(--r); }
.activity-row.error { color: var(--error); border-color: var(--error); }
.toast { position: fixed; top: 16px; left: 50%; z-index: 30; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 6px 6px 6px 16px; background: var(--panel); border: 1px solid var(--divider); border-radius: var(--r); box-shadow: 0 6px 24px rgba(0,0,0,.8); }
.toast.error span { color: var(--error); }

/* empty, login */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; cursor: pointer; }
.empty-title { font-size: 21px; font-weight: 700; }
.login { height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 280px; display: flex; flex-direction: column; gap: 8px; }
.login label { color: var(--label); font-weight: 600; }
.login input { height: 36px; }
.login button { height: 36px; margin-top: 4px; border: 0; border-radius: var(--r); background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.login button:disabled { opacity: .5; }

@media (max-width: 900px) {
  .app { flex-direction: column-reverse; }
  .side { width: 100%; max-height: 55vh; border-right: 0; }
  .stage { min-height: 45vh; }
  .inspector { position: absolute; inset: 0 0 0 auto; z-index: 10; width: min(340px, 92%); }
  .dialog-row { grid-template-columns: 1fr; }
}

.crash { max-width: 520px; display: flex; flex-direction: column; gap: 12px; }

