/*
  The AI Director, as it appears in the Studio.

  Two places: a small strip in the editor's right-hand column that says what is
  being made and lets you pause it, and a sheet over the top for everything else.
  The strip is the important one — it is what makes a timeline that is quietly
  gaining shots explicable — so it is built to sit under the inspector without
  competing with it.

  Nothing here invents a colour. A run's state is carried by the badge and the
  phase strip, which are the two things anybody glances at.
*/

/* ----------------------------------------------------------------- strip */

.studio-director {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--s1);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-lg);
}

.studio-director .bar { margin: 2px 0; }

.studio-director-acts {
  gap: var(--sp-2);
  align-items: center;
}

.studio-director-bad {
  color: var(--danger);
  background: var(--danger-soft);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
}

/* ----------------------------------------------------------------- sheet */

/* How wide it gets is stated in app.css, beside the library picker's, because a
   variant cannot widen .modal-card from here. */

.studio-director-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}

.studio-director-body h3 { margin: 0; }
.studio-director-body p { margin: 0; }

/* ----------------------------------------------------------------- modes */

/*
  The three ways in, as cards rather than a dropdown. Which one applies depends
  on the timeline underneath — a cut with no holes cannot have its holes filled —
  so each one has to be able to say why it is unavailable, which a disabled
  <option> cannot.
*/
.studio-director-modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-2);
}

.studio-director-mode {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: var(--sp-3);
  text-align: left;
  color: var(--fg);
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}

.studio-director-mode:hover:not(:disabled) { background: var(--s2); }

.studio-director-mode.on {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.studio-director-mode.off {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ form */

.studio-director-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.studio-director-form textarea { resize: vertical; }

/*
  Two columns once there is room for them. Fifteen fields in one column is a
  dialog you scroll to read, and the answers at the bottom — how long a shot may
  be, whether to render at the end — are the ones people change most.

  Items that carry a sentence rather than a value opt out and take the full
  width; everything else pairs up in source order.
*/
@media (min-width: 720px) {
  .studio-director-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-3) var(--sp-4);
    align-items: start;
  }

  .studio-director-form > .wide { grid-column: 1 / -1; }
}

.studio-director-pick {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* ---------------------------------------------------------------- phases */

/*
  Where it has got to, as a row of stations rather than a percentage. A film is
  not a linear amount of work — planning is one call and filming is hours — so a
  single bar would sit at 4% for most of the night and read as broken.
*/
.studio-director-phases {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
}

.studio-director-phase {
  padding: 3px 10px;
  font-size: 12px;
  color: var(--fg-3);
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
}

.studio-director-phase.past {
  color: var(--fg-2);
  border-color: var(--border-2);
}

.studio-director-phase.now {
  color: var(--fg);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

/* ------------------------------------------------------------------ gate */

.studio-director-gate {
  padding: var(--sp-3);
  background: var(--s2);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-md);
}

/* The script, as it will be read: wide, tall, and in a reading face rather
   than a code one, because it is prose someone is proofing. */
.studio-director-script {
  width: 100%;
  min-height: 220px;
  margin: var(--sp-3) 0 var(--sp-1);
  font: inherit;
  line-height: 1.55;
  resize: vertical;
}

.studio-director-voice .row {
  gap: var(--sp-2);
  align-items: center;
}

.studio-director-voice select {
  flex: 1 1 auto;
  min-width: 0;
}

/* The cast gate: each portrait large enough to judge a face or a design by. */
.studio-director-castgate {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}

.studio-director-castcard {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-width: 0;
}

.studio-director-castcard img,
.studio-director-castwait {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--s3);
}

.studio-director-castwait {
  display: grid;
  place-items: center;
}

/* A picture being drawn again: the old one stays, dimmed, with its state on top. */
.studio-director-pic {
  position: relative;
  min-width: 0;
}

.studio-director-pic > img {
  display: block;
}

.studio-director-pic:has(.studio-director-picstate:not(.failed)) > img {
  opacity: 0.55;
}

.studio-director-picstate {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 8px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--s1) 88%, transparent);
  font-size: 0.8rem;
}

.studio-director-picstate > span:not(.spinner) {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.studio-director-picstate.failed {
  color: var(--danger, #e5484d);
}

.studio-director-pic.small .studio-director-picstate {
  left: 2px;
  right: 2px;
  bottom: 2px;
  padding: 0 2px 0 4px;
  font-size: 0.7rem;
}

.studio-director-pic.small .studio-director-picstate .btn {
  display: none;
}

.studio-director-gatepick {
  margin-bottom: var(--sp-2);
}

/* Sets are rooms, judged by their layout, so they get more width than a face —
   and each is two pictures, its two ends, side by side. */
.studio-director-setgate {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-2);
}

.studio-director-plates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}

.studio-director-platefig {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.studio-director-castcard img.studio-director-plate,
.studio-director-castcard .studio-director-plate {
  aspect-ratio: auto;
  min-height: 140px;
  max-height: 320px;
  object-fit: contain;
  background: #000;
}

.studio-director-style textarea {
  width: 100%;
  margin-top: var(--sp-2);
  font: inherit;
  resize: vertical;
}

.studio-director-style small {
  display: block;
  margin-top: var(--sp-1);
}

/* The redraw bar: a quieter cousin of the gate, since nothing is waiting on it. */
.studio-director-redraw {
  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);
}

.studio-director-engine select {
  width: 100%;
}

.studio-director-engine small {
  display: block;
  margin-top: var(--sp-1);
}

.studio-director-redraw .studio-director-engine {
  flex: 1 1 260px;
  min-width: 0;
}

/* One shot, large: the frames side by side at a size a face can be judged at. */
/* Planning a run again: a short form, so a little wider than a plain dialog. */
.studio-director-replan {
  max-width: min(560px, 96vw);
}

.studio-director-shotview {
  width: min(1100px, 96vw);
  /* The base card is a 440px dialog; this one is for looking at pictures. */
  max-width: min(1100px, 96vw);
  max-height: 94vh;
  overflow: auto;
}

.studio-director-shotview-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.studio-director-shotview-frames {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  justify-content: center;
}

.studio-director-shotview-frame {
  flex: 1 1 260px;
  max-width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
}

.studio-director-shotview-frame img,
.studio-director-shotview-frame video {
  max-width: 100%;
  max-height: 62vh;
  object-fit: contain;
  border-radius: var(--r-sm);
  background: #000;
}

.studio-director-shotview-frame .studio-director-castwait {
  width: 100%;
  min-height: 160px;
  aspect-ratio: auto;
}

.studio-director-says {
  margin: 0;
  font-size: 1.05em;
  line-height: 1.5;
}

.studio-director-shotview-acts {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.studio-director-contact {
  width: 100%;
  margin-top: var(--sp-3);
  border-radius: var(--r-sm);
  background: #000;
}

/* ------------------------------------------------------------ cast, shots */

.studio-director-more {
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}

.studio-director-more > summary {
  cursor: pointer;
  color: var(--fg-2);
}

.studio-director-more > summary:hover { color: var(--fg); }

.studio-director-cast {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}

.studio-director-role {
  display: flex;
  gap: var(--sp-3);
  min-width: 0;
}

.studio-director-role img {
  flex: none;
  width: 64px;
  height: 84px;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--s3);
}

.studio-director-shots {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-height: 420px;
  margin-top: var(--sp-3);
  overflow: auto;
}

.studio-director-shot {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: var(--sp-2);
  border-radius: var(--r-sm);
}

.studio-director-shot:hover { background: var(--s2); }

.studio-director-thumb {
  flex: none;
  width: 96px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--s3);
}

/* ------------------------------------------------------------------- log */

.studio-director-log {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 300px;
  margin-top: var(--sp-2);
  overflow: auto;
}

.studio-director-note {
  display: flex;
  gap: var(--sp-3);
  font-size: 13px;
  color: var(--fg-2);
}

.studio-director-note > span:first-child {
  flex: none;
  width: 90px;
  text-align: right;
}

.studio-director-note.bad { color: var(--danger); }
