/*
  The generation workspace: workflow picker, parameter form, activity panel.
  Uses only tokens.css values.
*/

.create {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 340px;
  height: 100%;
  overflow: hidden;
}

.create-col {
  min-width: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.create-col + .create-col {
  border-left: 1px solid var(--border);
}

.col-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.col-body {
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* The phone tab bar over the columns. Absent on a wide screen, where all three
   columns are on screen at once and a tab bar would be a control for nothing. */
.col-tabs {
  display: none;
}

/* Shown on a wide screen; on a phone the paragraph it belongs to is folded
   away and this is what unfolds it. */
.info-btn {
  display: none;
}

/* ------------------------------------------------------- workflow picker */

.wf-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--sp-2);
}

.wf-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: var(--sp-3);
  padding: 7px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}

.wf-item:hover {
  background: var(--s2);
}

.wf-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.wf-thumb {
  width: 42px;
  height: 42px;
  flex: none;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--s3);
}

/* Named "blank" rather than "empty" on purpose: `.empty` is the page-level
   empty state, whose padding turned a 42px thumbnail into a 96px one. */
.wf-thumb.blank {
  display: grid;
  place-items: center;
  color: var(--fg-3);
}

.wf-thumb.blank svg {
  width: 18px;
  height: 18px;
}

.wf-name {
  font-weight: 550;
  font-size: 13px;
}

.wf-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

/* A heading inside the picker list, when recipes and workflows share it. */
.list-label {
  padding: var(--sp-3) 7px 4px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--fg-3);
}

/* Shown above the form while it is feeding a chain rather than one workflow,
   because otherwise nothing on screen says the inputs go somewhere else. */
.chain {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-md);
  background: var(--accent-soft);
}

/* ------------------------------------------------------------ parameters */

/* A labelled group of inputs. A fieldset rather than a div so the legend is
   announced with the fields it introduces. */
.group {
  margin: 0;
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--s1);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.group > legend {
  padding: 0 8px;
  margin-left: -4px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--fg-3);
}

.param {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.param-label {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  font-size: 12.5px;
  font-weight: 550;
  color: var(--fg-2);
}

/* The graph key, shown quietly so a mislabelled input can still be identified
   without opening the studio. */
.param-label .key {
  color: var(--fg-3);
  font-size: 11px;
  opacity: .75;
}

.param-label .val {
  margin-left: auto;
  color: var(--accent-2);
  font-size: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--s2);
  color: var(--fg-2);
  font-size: 12.5px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast),
    border-color var(--t-fast);
}

.chip:hover {
  background: var(--s3);
  color: var(--fg);
}

.chip.on {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--fg);
}

.slider-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: var(--sp-2);
  align-items: center;
}

.seed-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: var(--sp-2);
  align-items: center;
}

.seed-row select {
  width: auto;
}

input[type=range] {
  width: 100%;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

input[type=range]:focus {
  box-shadow: none;
}

/* ---------------------------------------------------------- image inputs */

/*
  Clip input. The player is the control: trim is set by watching, so it gets
  the room a picture preview does not need.
*/
.clip-input {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--s1);
}

.clip-player {
  width: 100%;
  max-height: 340px;
  border-radius: var(--r-sm);
  background: #000;
}

.clip-player[hidden] {
  display: none;
}

.clip-trim {
  gap: var(--sp-2);
}

/*
  A job's picture slot. Narrower than a workflow's image input because there is
  nothing to drag into it and no mask to paint: the answer is a file that is
  already in the library, so all it has to show is which one.
*/
.slot-pic {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--s1);
}

.slot-pic img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--s3);
}

.img-input {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3);
  border: 1px dashed var(--border-2);
  border-radius: var(--r-md);
  background: var(--s1);
  transition: border-color var(--t-fast), background var(--t-fast);
}

.img-input.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.img-input.filled {
  border-style: solid;
}

.img-preview {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: var(--r-sm);
}

.img-placeholder {
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  border-radius: var(--r-sm);
  background: var(--s2);
  color: var(--fg-3);
  font-size: 11.5px;
  text-align: center;
}

.img-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* ------------------------------------------------- trigger autocomplete */

.ac-pop {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: 100%;
  margin: 4px 0 0;
  padding: 4px;
  max-height: 230px;
  overflow-y: auto;
  list-style: none;
  background: var(--s3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
}

.ac-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 6px 9px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
}

.ac-item.on,
.ac-item:hover {
  background: var(--accent-soft);
}

.ac-src {
  color: var(--fg-3);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------- model warning */

.model-warn {
  padding: var(--sp-3);
  border: 1px solid rgba(251, 191, 36, .32);
  border-radius: var(--r-md);
  background: rgba(251, 191, 36, .08);
  font-size: 13px;
}

.model-warn ul {
  margin: 8px 0;
  padding-left: 20px;
}

/* The GPU notice sits above the fields rather than among them, so it needs its
   own margins; the model warning inherits the field list's spacing. */
.gpu-bar {
  margin: var(--sp-3) var(--sp-3) 0;
}

/* ------------------------------------------------------------- generate bar */

/* Pinned to the bottom of the form column: the primary action should never be
   somewhere you have to scroll to find. */
.go-bar {
  position: sticky;
  bottom: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: auto;
  padding: var(--sp-3);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}

.go-bar .field {
  flex: none;
  width: 88px;
}

.go-bar .field.grow {
  flex: 1;
  width: auto;
}

/* --------------------------------------------------------------- activity */

.job {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.job.error {
  border-color: rgba(248, 113, 113, .4);
}

.job.done {
  border-color: rgba(52, 211, 153, .25);
}

.job-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.job-title {
  flex: 1;
  min-width: 0;
  font-weight: 550;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar {
  position: relative;
  height: 5px;
  overflow: hidden;
  background: var(--s4);
  border-radius: var(--r-pill);
}

.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: inherit;
  transition: width var(--t-med);
}

/* No total step count yet, so show motion without implying progress. */
.bar.indeterminate > i {
  width: 35%;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(320%);
  }
}

.job-preview,
.job-media img,
.job-media video {
  width: 100%;
  border-radius: var(--r-sm);
  background: var(--s3);
}

.job-media {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 6px;
}

.job-media img,
.job-media video {
  aspect-ratio: 1;
  object-fit: cover;
  cursor: pointer;
}

.job-note {
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: var(--s3);
  color: var(--fg-2);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

/* What a job asks for, listed in the recipe editor. Plain rows: it is a
   summary of something set elsewhere, not a control. */
.slot-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}

/*
  Where a step's inputs come from, in the recipe editor.

  Set in from the step's own controls and marked with a line down the side,
  because these rows are about the step's wiring rather than about the step —
  without the offset a dropdown saying "the plate" reads as another setting of
  the workflow above it.
*/
.bind-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
}

.bind-row {
  gap: 6px;
  align-items: center;
}

/* A label beside its field rather than above it, for the short ones: a name
   or a number reads as part of the sentence around it. */
.field.inline {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  margin: 0;
}

/* A server error, wherever it is reported: a failed job, a rejected submit, a
   step that cannot take the previous output. */
.job-note.err {
  background: var(--danger-soft);
  color: var(--danger);
}

.run-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.run-step {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 5px 8px;
  border-radius: var(--r-sm);
  background: var(--s1);
  font-size: 12.5px;
}

.run-step.running {
  background: var(--accent-soft);
}

.run-step.done {
  color: var(--fg-3);
}

.run-step.error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* The live-connection indicator in the activity header. */
.dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--fg-3);
}

.dot.live {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, .18);
}

.dot.down {
  background: var(--warn);
}

/* ------------------------------------------------------------------ mask */

.mask-panel {
  width: min(1000px, 96vw);
  max-height: 94vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--s2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
}

.mask-stage {
  display: grid;
  place-items: center;
  padding: var(--sp-3);
  background: var(--bg);
  border-radius: var(--r-md);
}

/* Zoomed in, the frame is larger than the stage, so the stage becomes the
   window onto it. Left-aligned, or a scrolled view snaps back to centre. */
.mask-stage.zoomed {
  place-items: start;
  overflow: auto;
}

/* The image and the canvas both fill this box, which is what keeps a stroke
   exactly under the pointer. */
.mask-frame {
  position: relative;
  line-height: 0;
  transform-origin: top left;
}

.mask-frame img,
.mask-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.mask-frame img {
  position: relative;
  border-radius: var(--r-sm);
}

.mask-frame canvas {
  opacity: .55;
  cursor: crosshair;
  touch-action: none;
  border-radius: var(--r-sm);
}

.mask-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
}

.mask-tools .field {
  width: 150px;
}

/* Naming a thing instead of drawing round it. */
.mask-find {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.mask-find input[type="text"] {
  flex: 1 1 160px;
  min-width: 130px;
  max-width: 260px;
}

.btn.on {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--fg);
}

/* ------------------------------------------------------- prompt rewriting */

/* Sits on the prompt's label row, pushed right past the graph key. Tinted,
   because it is the one control in the form that spends money. */
.enhance-btn {
  margin-left: auto;
  padding: 2px 8px;
  color: var(--accent-2);
}

.enhance-btn .icon {
  width: 14px;
  height: 14px;
}

.enhance-card {
  max-width: 640px;
}

.enhance-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* The prompt as typed, shown for comparison rather than for editing — the
   editing happens on the suggestion below it. */
.enhance-original {
  max-height: 120px;
  overflow-y: auto;
  padding: 9px 12px;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--fg-2);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------- node editor */

/*
  The node editor is a pane of the workflows view, but it is the only one that
  takes the whole workspace at every width. A graph is not a column: read
  through a third of the screen it is a maze, and ComfyUI's own toolbars assume
  they have room. So while it is showing, the columns beside it are not.
*/
.create > .pane-graph {
  display: none;
  overflow: hidden;
}

.create.show-graph {
  grid-template-columns: minmax(0, 1fr);
}

.create.show-graph > .create-col:not(.pane-graph) {
  display: none;
}

.create.show-graph > .pane-graph {
  display: flex;
  grid-column: 1 / -1;
  border-left: 0;
  border-top: 0;
  max-height: none;
}

.graph-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

/* Its own scrolling, its own gestures, its own everything: the frame is a whole
   application and the page must not try to lay out its insides. */
.graph-frame {
  flex: 1;
  min-width: 0;
  border: 0;
  background: var(--bg);
}

/* Something to say over the editor without taking it down — the frame behind
   this cost seconds to start and is wanted for the next workflow. */
.graph-notice {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}

.graph-notice .empty {
  max-width: 60ch;
}

/* The save dialog's list of consequences: what moved, what is about to be
   dropped. Scrolls, because a big edit can touch a lot of inputs. */
.graph-diff {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  max-height: 50vh;
  overflow-y: auto;
}

.graph-diff ul.plain {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.graph-diff .row.between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.adopt-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 320px;
  overflow-y: auto;
  margin-top: var(--sp-2);
}

.adopt-row {
  gap: var(--sp-2);
  padding: 3px 4px;
  border-radius: var(--r-sm);
}

.adopt-row:hover {
  background: var(--s1);
}

/* ------------------------------------------------------------ graph advice */

.advice {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  max-height: 60vh;
  overflow-y: auto;
}

.advice-summary {
  margin: 0;
  line-height: 1.5;
}

.advice-problems {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.advice-problem {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-start;
  padding: var(--sp-2);
  border-radius: var(--r-sm);
  border-left: 3px solid var(--muted);
  background: var(--s1);
  font-size: 13px;
}

.advice-problem .icon {
  flex: none;
  margin-top: 2px;
}

/* Severity reads as colour, since the same words carry very different weight:
   a missing model file stops the workflow, an odd step count does not. */
.advice-problem.blocking {
  border-left-color: var(--danger);
}

.advice-problem.warning {
  border-left-color: var(--warn);
}

.advice-opts {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.advice-opt {
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}

.advice-opt input {
  margin-top: 3px;
}

.advice-detail summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}

.advice-digest {
  margin: var(--sp-2) 0 0;
  padding: var(--sp-2);
  max-height: 280px;
  overflow: auto;
  background: var(--s1);
  border-radius: var(--r-sm);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --------------------------------------------------------------- narrow */

@media (max-width: 1200px) {
  .create {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  /* The activity panel moves under the form rather than being cut off. */
  .create > .create-col:last-child {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--border);
    max-height: 45vh;
  }
}

/*
  A phone gets one column at a time, chosen by the tab bar. Stacking them
  instead meant a 200px-tall scrolling list of workflows sitting on top of the
  form, with the activity panel a page and a half below — three cramped things
  rather than one whole one.
*/
@media (max-width: 860px) {
  .create {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  .col-tabs {
    display: flex;
    grid-row: 1;
    gap: 2px;
    padding: var(--sp-2) var(--sp-2) 0;
    border-bottom: 1px solid var(--border);
    background: var(--s1);
  }

  .col-tab {
    position: relative;
    flex: 1;
    min-width: 0;
    padding: 10px 4px 11px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--fg-3);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
  }

  .col-tab.active {
    color: var(--fg);
    border-bottom-color: var(--accent);
  }

  /* Something finished while you were on another tab. */
  .col-tab-dot {
    position: absolute;
    top: 7px;
    right: 12px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-2);
  }

  .create > .create-col {
    grid-row: 2;
    grid-column: 1;
    display: none;
    overflow-y: auto;
    border-left: 0;
    max-height: none;
  }

  .create.show-picker > .pane-picker,
  .create.show-form > .pane-form,
  .create.show-activity > .pane-activity,
  .create.show-editor > .pane-editor,
  .create.show-graph > .pane-graph,
  .create.show-side > .pane-side {
    display: flex;
  }

  /* The editor head carries six actions. On its own row the title is a title;
     sharing one with the actions, it became a word per line. */
  .edit-head {
    flex-wrap: wrap;
  }

  .edit-head > .grow {
    flex: 1 1 100%;
  }

  /* The head is the title, the badges, and the fold-out description — a row
     that has to survive a workflow called "Flux2 Klein Image Edit Single". */
  .wf-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .wf-head h2 {
    font-size: 16px;
  }

  .wf-head .wf-desc {
    display: none;
    flex-basis: 100%;
    margin-top: var(--sp-2);
  }

  .wf-head.info-open .wf-desc {
    display: block;
  }

  .info-btn {
    display: inline-flex;
  }

  /* Room for a thumb on either side of the value. */
  .slider-row {
    grid-template-columns: minmax(0, 1fr) 78px;
  }

  /* Batch and folder on one row, the actions on the next: at 390px all four
     on one line left "(no folde" and a Generate button too narrow to read. */
  .go-bar {
    flex-wrap: wrap;
    padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom) / 2);
  }

  .go-bar .field {
    width: 82px;
  }

  .go-bar .field.grow {
    flex: 1 1 120px;
  }

  .go-bar > .btn {
    flex: 1 1 auto;
    height: 40px;
  }

  .img-input {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .img-preview,
  .img-placeholder {
    width: 72px;
    height: 72px;
  }

  .mask-panel {
    width: 100%;
    max-width: none;
    max-height: 92vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
}
