/* pics — control-room aesthetic: cool graphite instrument, render-heat accent.
   The colourful outputs are the only saturated thing on screen; the UI stays
   quiet so they carry the colour. Technical values are set in monospace so they
   read like instrument readouts. */

:root {
  --bg: #0a0d12;
  --surface: #11161e;
  --surface-2: #161d27;
  --surface-3: #1d2530;
  --line: #262f3b;
  --line-strong: #384453;
  --text: #e9eef5;
  --muted: #8c98a8;
  --faint: #7b8696;   /* ≥4.5:1 on --surface for small technical labels (WCAG AA) */

  --glow: #ff8a3d;        /* render heat — the one signature accent */
  --glow-2: #ffb068;
  --hot: #ff4d6d;         /* over budget */
  --cool: #46e0bf;        /* active / success — latent mint */

  --r: 12px;
  --r-sm: 9px;
  --r-lg: 18px;
  --display: 'Space Grotesk', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', monospace;
  --shadow: 0 18px 50px -24px rgba(0,0,0,.8);
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--glow);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* faint instrument grid, barely visible */
  background-image:
    radial-gradient(1200px 600px at 80% -10%, rgba(255,138,61,.05), transparent 60%),
    linear-gradient(rgba(255,255,255,.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.012) 1px, transparent 1px);
  background-size: auto, 44px 44px, 44px 44px;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
::selection { background: rgba(255,138,61,.32); }

.eyebrow {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--faint);
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: .62em 1.05em;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .06s;
}
.btn:hover { border-color: var(--glow); }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--line); }
.btn-primary {
  border: none; color: #1a0f06; font-weight: 600;
  background: linear-gradient(180deg, var(--glow-2), var(--glow));
  box-shadow: 0 8px 24px -10px rgba(255,138,61,.7);
}
.btn-primary:hover { filter: brightness(1.06); border: none; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }

/* ── login ────────────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 500px at 50% 0%, rgba(255,138,61,.08), transparent 55%), var(--bg);
}
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 34px 30px;
  box-shadow: var(--shadow);
  display: grid; gap: 16px;
}
.login-brand, .wordmark {
  font-family: var(--display); font-weight: 700; font-size: 26px;
  letter-spacing: -.01em; display: flex; align-items: center; gap: 11px;
}
.login-sub { margin: -6px 0 6px; color: var(--muted); font-size: 14px; }
.login-error { color: var(--hot); font-size: 13px; min-height: 1em; margin: 0; }

.logo-ring {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--glow); position: relative; flex: none;
}
.logo-ring::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 5px; height: 5px; border-radius: 50%; background: var(--cool);
}

.field { display: grid; gap: 7px; }
.field-label { font-size: 13px; color: var(--muted); }
.field input, .prompt, .seed-wrap input, select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: .66em .8em; color: var(--text);
  transition: border-color .15s;
}
.field input:focus, .prompt:focus, select:focus, .seed-wrap input:focus { border-color: var(--glow); outline: none; box-shadow: none; }

/* ── app shell ────────────────────────────────────────────────── */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(10,13,18,.82); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 20;
}
.wordmark { font-size: 21px; }
.topbar .rig { margin-left: auto; }

.rig {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 8px 6px 13px; background: var(--surface);
}
.rig-label { font-family: var(--display); font-size: 11px; letter-spacing: .16em; color: var(--faint); }
.rig-readout { font-family: var(--mono); font-size: 13px; }
.rig .unit { color: var(--muted); font-size: 11px; }
.rig-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--cool); box-shadow: 0 0 10px var(--cool); }
.rig-dot.warn { background: var(--glow); box-shadow: 0 0 10px var(--glow); }
.rig-dot.down { background: var(--hot); box-shadow: 0 0 10px var(--hot); }

/* ── workspace ────────────────────────────────────────────────── */
.workspace {
  flex: 1; display: grid; grid-template-columns: minmax(340px, 400px) 1fr;
  gap: 0; align-items: start;
}
.console {
  position: sticky; top: 57px; align-self: start;
  max-height: calc(100vh - 57px); overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 18px; display: grid; gap: 14px;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
#gen-form { display: grid; gap: 14px; }

.module {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  display: grid; gap: 12px;
}
.module-head { display: flex; align-items: center; justify-content: space-between; }
.module-adv > summary, .neg > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px;
}
.module-adv > summary::after, .neg > summary::after {
  content: "+"; margin-left: auto; color: var(--faint); font-family: var(--mono);
}
.module-adv[open] > summary::after, .neg[open] > summary::after { content: "−"; }
.module-adv > summary::-webkit-details-marker, .neg > summary::-webkit-details-marker { display: none; }
.module-adv { display: grid; gap: 12px; }
.module-adv[open] { gap: 13px; }

.prompt {
  resize: vertical; min-height: 76px; line-height: 1.45;
  font-family: var(--body); font-size: 14.5px;
}
.prompt-sm { min-height: 48px; font-size: 13.5px; }
.neg { margin-top: 2px; }
.neg summary { font-size: 13px; color: var(--muted); padding: 2px 0; }
.neg[open] { display: grid; gap: 8px; }

/* segmented controls */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 4px; }
.seg-btn {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  border-radius: 6px; padding: 8px 6px; cursor: pointer; display: grid; gap: 1px;
  transition: background .14s, color .14s, border-color .14s;
}
.seg-btn .seg-title { font-weight: 600; font-size: 14px; }
.seg-btn .seg-meta { font-family: var(--mono); font-size: 10px; color: var(--faint); letter-spacing: .02em; }
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-checked="true"] {
  background: var(--surface-3); color: var(--text); border-color: var(--line-strong);
  box-shadow: inset 0 0 0 1px rgba(255,138,61,.25);
}
.seg-btn[aria-checked="true"] .seg-meta { color: var(--glow-2); }
.seg-sm .seg-btn { padding: 7px 4px; text-align: center; font-family: var(--mono); }

/* aspect ratio chips */
.ratios { display: grid; grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); gap: 6px; }
.ratio {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px;
  padding: 8px 2px 6px; cursor: pointer; display: grid; gap: 5px; place-items: center;
  transition: border-color .14s, background .14s;
}
.ratio:hover { border-color: var(--line-strong); }
.ratio-box { width: 18px; height: 18px; display: grid; place-items: center; }
.ratio-box i { display: block; background: var(--faint); border-radius: 1.5px; transition: background .14s; }
.ratio-label { font-family: var(--mono); font-size: 9.5px; color: var(--faint); }
.ratio[aria-checked="true"] { border-color: var(--glow); background: var(--surface-3); }
.ratio[aria-checked="true"] i { background: var(--glow); }
.ratio[aria-checked="true"] .ratio-label { color: var(--glow-2); }

/* sliders */
.slider-row { display: grid; grid-template-columns: 64px 1fr 46px; align-items: center; gap: 10px; }
.slider-row label { font-size: 13px; color: var(--muted); }
.slider-row output { text-align: right; font-size: 13px; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px;
  background: var(--surface-3); cursor: pointer; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--glow); box-shadow: 0 2px 6px rgba(0,0,0,.5); }
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--text); border: 3px solid var(--glow); }

.dual { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seed-field label, .batch-field label, .select-field { font-size: 13px; color: var(--muted); display: grid; gap: 7px; }
.seed-wrap { position: relative; display: flex; }
.seed-wrap input { padding-right: 38px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  border-radius: 7px; width: 30px; height: 30px; cursor: pointer; display: grid; place-items: center;
}
.seed-wrap .icon-btn { position: absolute; right: 4px; top: 4px; border: none; background: transparent; }
.icon-btn:hover { color: var(--glow); }
.select-field select { margin-top: 0; font-size: 13px; }

/* toggle */
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; color: var(--muted); }
.toggle input { position: absolute; opacity: 0; }
.toggle-track { width: 38px; height: 22px; border-radius: 999px; background: var(--surface-3);
  border: 1px solid var(--line); position: relative; transition: background .16s, border-color .16s; flex: none; }
.toggle-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--faint); transition: transform .16s, background .16s; }
.toggle input:checked + .toggle-track { background: rgba(255,138,61,.25); border-color: var(--glow); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); background: var(--glow); }
.toggle input:focus-visible + .toggle-track { box-shadow: var(--ring); }

/* img2img dropzone */
.opt-tag { font-family: var(--mono); font-size: 10px; color: var(--faint); letter-spacing: .04em; }
.dropzone { border: 1.5px dashed var(--line-strong); border-radius: var(--r-sm); padding: 14px; text-align: center; transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--glow); background: rgba(255,138,61,.06); }
.dz-empty { color: var(--muted); font-size: 13px; display: grid; gap: 3px; }
.dz-hint { color: var(--faint); font-size: 11px; }
.linklike { background: none; border: none; color: var(--glow); cursor: pointer; padding: 0; font: inherit; }
.linklike:hover { text-decoration: underline; }
.dz-preview { position: relative; display: inline-block; }
.dz-preview img { max-height: 130px; max-width: 100%; border-radius: 8px; display: block; }
.dz-remove { position: absolute; top: 6px; right: 6px; background: rgba(10,13,18,.75); border-color: transparent; }

/* ── signature: thermal budget gauge ──────────────────────────── */
.thermal {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line); border-radius: var(--r); padding: 13px 14px; display: grid; gap: 9px;
}
.thermal-top { display: flex; align-items: center; justify-content: space-between; }
.thermal-val { font-size: 12.5px; color: var(--muted); }
.thermal-val #therm-est { color: var(--text); }
.thermal-bar { position: relative; height: 9px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.thermal-fill { position: absolute; inset: 0 auto 0 0; width: 0;
  background: linear-gradient(90deg, #5a6575, var(--glow-2) 70%, var(--glow));
  border-radius: 6px; transition: width .3s ease, background .3s; }
.thermal-ceil-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .5; }
.thermal-note { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.thermal.over .thermal-fill { background: linear-gradient(90deg, var(--glow), var(--hot)); animation: pulse 1.4s ease-in-out infinite; }
.thermal.over .thermal-note { color: var(--hot); }
@keyframes pulse { 50% { opacity: .62; } }

.btn-generate { width: 100%; padding: .9em; font-size: 15.5px; flex-direction: column; gap: 1px; }
.btn-generate .gen-dim { font-size: 11px; opacity: .8; font-weight: 500; }
.btn-generate:disabled { opacity: .55; cursor: not-allowed; filter: grayscale(.3); }

/* ── stage ────────────────────────────────────────────────────── */
.stage { padding: 20px 22px 60px; display: grid; gap: 18px; align-content: start; min-width: 0; }
.active { display: grid; gap: 12px; }
.active:empty { display: none; }
.job-card {
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  padding: 13px 14px; display: grid; gap: 10px;
}
.job-card.run { border-color: rgba(255,138,61,.4); }
.job-card.fail { border-color: rgba(255,77,109,.45); }
.job-row { display: flex; align-items: center; gap: 10px; }
.job-state { font-family: var(--display); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; }
.job-state.run { color: var(--glow); background: rgba(255,138,61,.12); }
.job-state.done { color: var(--cool); background: rgba(70,224,191,.12); }
.job-state.fail { color: var(--hot); background: rgba(255,77,109,.12); }
.job-prompt { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.job-err { color: var(--hot); font-size: 12.5px; font-family: var(--mono); }
.job-imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.job-imgs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.spinner { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--surface-3); border-top-color: var(--glow); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.gallery-head { display: flex; align-items: baseline; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.gallery-count { color: var(--faint); font-size: 12px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery-empty { color: var(--faint); padding: 30px 0; text-align: center; }
.shot { position: relative; border-radius: 10px; overflow: hidden; cursor: pointer; background: var(--surface);
  border: 1px solid var(--line); aspect-ratio: 1; }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .35s ease; }
.shot:hover img { transform: scale(1.05); }
.shot::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 -40px 30px -30px rgba(0,0,0,.7); }
.shot-tag { position: absolute; left: 7px; bottom: 6px; z-index: 1; font-family: var(--mono); font-size: 10px;
  color: var(--glow-2); background: rgba(10,13,18,.6); padding: 1px 6px; border-radius: 5px; }

/* ── lightbox ─────────────────────────────────────────────────── */
.lightbox { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 4vmin;
  background: rgba(6,8,11,.86); backdrop-filter: blur(8px); }
.lb-figure { margin: 0; max-width: min(1100px, 96vw); max-height: 92vh; display: grid; gap: 14px;
  grid-template-rows: 1fr auto; }
.lb-figure img { max-width: 100%; max-height: 74vh; object-fit: contain; border-radius: 10px;
  justify-self: center; box-shadow: var(--shadow); }
.lb-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; color: var(--muted); font-size: 13px; }
.lb-meta .m-prompt { flex-basis: 100%; color: var(--text); font-size: 14px; }
.lb-meta .chip { font-family: var(--mono); font-size: 11.5px; color: var(--muted); border: 1px solid var(--line);
  padding: 2px 8px; border-radius: 6px; background: var(--surface); }
.lb-meta .chip b { color: var(--glow-2); font-weight: 500; }
.lb-actions { display: flex; gap: 8px; margin-left: auto; }
.lb-close { position: fixed; top: 18px; right: 20px; width: 38px; height: 38px; font-size: 16px; border-radius: 10px; }

/* ── toast ────────────────────────────────────────────────────── */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--line-strong); color: var(--text);
  padding: 11px 18px; border-radius: 10px; font-size: 14px; z-index: 60; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { border-color: var(--hot); color: #ffd7dd; }

/* ── modal (change password) ──────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 24px;
  background: rgba(6,8,11,.8); backdrop-filter: blur(8px); }
.modal-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 26px; display: grid; gap: 13px; box-shadow: var(--shadow); }
.modal-title { font-family: var(--display); font-weight: 600; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* boot overlay (shown until presets load; error+retry on failure) */
.boot { position: fixed; inset: 57px 0 0 0; z-index: 16; display: grid; place-items: center;
  background: var(--bg); }
.boot-inner { display: grid; gap: 14px; justify-items: center; color: var(--muted); text-align: center; padding: 24px; }
.boot-err-title { font-family: var(--display); font-size: 19px; color: var(--text); }
.boot-err-msg { font-size: 13px; max-width: 360px; }
.spinner-lg { width: 30px; height: 30px; border-width: 3px; }

.gallery-more { justify-self: center; margin-top: 4px; }
.job-dim { color: var(--faint); font-size: 12px; }

/* disabled segment group (img2img locks batch to 1) */
.seg.disabled { opacity: .45; }
.seg .seg-btn[aria-disabled="true"] { cursor: not-allowed; }

/* ── responsive ───────────────────────────────────────────────── */
@media (max-width: 880px) {
  .workspace { grid-template-columns: 1fr; }
  .console { position: static; max-height: none; border-right: none; border-bottom: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
