/* === Thumbnail Studio (#view-thumbnails) — Pit Wall design system ===========
   Spec: Rooms/Work/spec/thumbnail-studio-spec.md §3. Design reference:
   studio-mockup-v5.png (same dir).

   TOKENS: every --ts-* below is an ALIAS onto a live token — no forks, no new
   values. The mockup's literals were already the fleet palette (#ff6b6b =
   --accent-red, #feca57 = --accent-yellow, #2ed573 = --fleet-working, #bbb =
   --text-muted, #ccc = --text-secondary), so the reskin resolves to the same
   pixels the Fleet board and Scoreboard paint. Comms owns the token source; a
   genuinely new value would be proposed there, not minted here.

   SCOPE: every selector is prefixed #view-thumbnails. The .ts-* names are new
   and unique, but a bare rule would still be a global that a later surface can
   collide with — the container prefix keeps this section unable to leak.        */
#view-thumbnails { overflow: hidden; }

#view-thumbnails .ts-wrap {
  --ts-panel: var(--fleet-panel-2);
  --ts-accent: var(--accent-red);
  --ts-accent-2: var(--accent-yellow);
  --ts-ok: var(--fleet-working);
  --ts-dim: var(--text-muted);
  --ts-sec: var(--text-secondary);
  display: flex;
  flex: 1;
  min-height: 0;
  font-family: var(--fleet-text);
}

/* ---- left panel ---------------------------------------------------------- */
#view-thumbnails .ts-left {
  width: 330px;
  flex-shrink: 0;
  border-right: 1px solid var(--glass-border);
  background: var(--ts-panel);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}
#view-thumbnails .ts-lbl {
  font-family: var(--fleet-ink);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--ts-dim);
}
#view-thumbnails .ts-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
}

/* model dropdown — the per-click price lives here and ONLY here (spec §1) */
#view-thumbnails .ts-dropdown-wrap { position: relative; }
#view-thumbnails .ts-dropdown {
  width: 100%;
  margin-top: 7px;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
#view-thumbnails .ts-dropdown:hover { background: var(--glass-hover); }
#view-thumbnails .ts-dropdown:focus-visible,
#view-thumbnails .ts-generate:focus-visible,
#view-thumbnails .ts-ref-add:focus-visible,
#view-thumbnails .ts-prompt:focus-visible,
#view-thumbnails .ts-btn:focus-visible,
#view-thumbnails .ts-model-opt:focus-visible,
#view-thumbnails .ts-at-opt:focus-visible,
#view-thumbnails .ts-ref-del:focus-visible {
  outline: 2px solid var(--ts-accent-2);
  outline-offset: 2px;
}
#view-thumbnails .ts-dropdown-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#view-thumbnails .ts-dropdown-name { font-weight: 600; font-size: 13px; }
#view-thumbnails .ts-dropdown-price {
  font-family: var(--fleet-mono);
  font-size: 10.5px;
  color: var(--ts-ok);
}
#view-thumbnails .ts-chev { color: var(--ts-dim); font-size: 11px; flex-shrink: 0; }
#view-thumbnails .ts-model-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  background: #241414;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
#view-thumbnails .ts-model-opt {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
}
#view-thumbnails .ts-model-opt:hover { background: var(--glass-bg); }
#view-thumbnails .ts-model-opt-on { background: rgba(255, 107, 107, 0.12); }

/* reference grid — 6 slots (spec §3). Every ref renders as a thumbnail so no
   unviewed file enters a call (§9.1): a UI fact, not an approval gate. */
#view-thumbnails .ts-refgrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 7px;
  border-radius: 10px;
}
#view-thumbnails .ts-ref {
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
}
#view-thumbnails .ts-ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
#view-thumbnails .ts-ref-tag {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.75);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--fleet-mono);
  font-size: 9.5px;
  color: var(--ts-accent-2);
}
#view-thumbnails .ts-ref-del {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.7);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
#view-thumbnails .ts-ref:hover .ts-ref-del,
#view-thumbnails .ts-ref-del:focus-visible { opacity: 1; }
#view-thumbnails .ts-ref-empty {
  border-style: dashed;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.25);
  font-size: 20px;
  font-weight: 300;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
#view-thumbnails .ts-ref-empty:hover { color: var(--ts-accent-2); border-color: var(--ts-accent-2); }
#view-thumbnails .ts-img-missing { display: flex; align-items: center; justify-content: center; }
#view-thumbnails .ts-img-missing::after {
  content: 'unavailable';
  font-family: var(--fleet-mono);
  font-size: 9px;
  color: var(--ts-dim);
}
#view-thumbnails .ts-hidden-input { display: none; }

/* prompt */
#view-thumbnails .ts-prompt-block { display: flex; flex-direction: column; }
#view-thumbnails .ts-prompt-wrap { position: relative; }
#view-thumbnails .ts-prompt {
  width: 100%;
  margin-top: 7px;
  padding: 12px 14px;
  font-family: var(--fleet-text);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ts-sec);
  min-height: 118px;
  resize: vertical;
}
#view-thumbnails .ts-prompt::placeholder { color: var(--ts-dim); opacity: 0.7; }
#view-thumbnails .ts-at-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  z-index: 20;
  background: #241414;
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 4px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 100%;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
#view-thumbnails .ts-at-opt {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border-radius: 7px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--ts-accent-2);
  font-family: var(--fleet-mono);
  font-size: 10.5px;
  cursor: pointer;
}
#view-thumbnails .ts-at-opt:hover { background: var(--glass-hover); }
#view-thumbnails .ts-at-thumb { width: 22px; height: 16px; object-fit: cover; border-radius: 3px; }

#view-thumbnails .ts-rowopts { display: flex; gap: 8px; }
#view-thumbnails .ts-chip {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 7px 12px;
  font-family: var(--fleet-mono);
  font-size: 11px;
  color: var(--ts-sec);
}
#view-thumbnails .ts-chip b { color: var(--text-primary); font-weight: 500; }

#view-thumbnails .ts-iterating,
#view-thumbnails .ts-note {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ts-dim);
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
}
#view-thumbnails .ts-note-err { color: var(--ts-accent); border-color: rgba(255, 107, 107, 0.4); }
#view-thumbnails .ts-linkbtn {
  background: none;
  border: none;
  color: var(--ts-accent-2);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

/* '+ New Thumbnail' — a secondary top-of-panel action; deliberately quieter than
   the Generate gradient (Generate stays the primary CTA). Ghost button on the
   ts- glass tokens, accent-2 on hover. */
#view-thumbnails .ts-newthumb {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 9px;
  text-align: center;
  font-family: var(--fleet-ink);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.1s;
}
#view-thumbnails .ts-newthumb:hover {
  border-color: var(--ts-accent-2);
  color: var(--ts-accent-2);
  background: var(--glass-hover);
}
#view-thumbnails .ts-newthumb:active { transform: scale(0.98); }
#view-thumbnails .ts-newthumb:focus-visible { outline: 2px solid var(--ts-accent-2); outline-offset: 2px; }

/* Generate — carries NO price (Jase locked, spec §1); the price is above, in
   the model dropdown line. */
#view-thumbnails .ts-generate {
  margin-top: auto;
  background: linear-gradient(45deg, var(--ts-accent), var(--ts-accent-2));
  color: #1a1010;
  border: none;
  border-radius: 12px;
  padding: 13px;
  text-align: center;
  font-family: var(--fleet-ink);
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
#view-thumbnails .ts-generate:hover { filter: brightness(1.08); }
#view-thumbnails .ts-generate:active { transform: scale(0.99); }
#view-thumbnails .ts-generate-busy,
#view-thumbnails .ts-generate[disabled] { opacity: 0.6; cursor: default; }
#view-thumbnails .ts-generate-busy { animation: ts-pulse 1.1s ease-in-out infinite; }
@keyframes ts-pulse { 50% { opacity: 0.75; } }

/* ---- gallery ------------------------------------------------------------- */
#view-thumbnails .ts-mid { flex: 1; min-width: 0; padding: 16px 20px; overflow-y: auto; }
#view-thumbnails .ts-empty {
  color: var(--ts-dim);
  font-size: 13px;
  padding: 40px 0;
  text-align: center;
}
#view-thumbnails .ts-group { margin-bottom: 22px; }
/* History recedes: the newest group is the hero 2-up, everything older renders
   as a compact dimmed strip that comes back to full on hover — the
   studio-mockup-v5.png reference ("Earlier — wide room look test" row). */
#view-thumbnails .ts-group-old { opacity: 0.4; transition: opacity 0.2s; }
#view-thumbnails .ts-group-old:hover { opacity: 1; }
#view-thumbnails .ts-group-old .ts-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
#view-thumbnails .ts-group-old .ts-out { width: 200px; }
#view-thumbnails .ts-group-old .ts-ghead-p { font-family: var(--fleet-ink); font-weight: 500; }
#view-thumbnails .ts-ghead { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
#view-thumbnails .ts-ghead-p {
  font-size: 12.5px;
  color: var(--ts-sec);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
#view-thumbnails .ts-ghead-meta {
  font-family: var(--fleet-mono);
  font-size: 10px;
  color: var(--ts-dim);
  white-space: nowrap;
  flex-shrink: 0;
}
#view-thumbnails .ts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 850px;
}
#view-thumbnails .ts-out {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  aspect-ratio: 16 / 9;
}
#view-thumbnails .ts-out img { width: 100%; height: 100%; object-fit: cover; display: block; }
#view-thumbnails .ts-out-actions {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 6px;
}
#view-thumbnails .ts-btn {
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  font-family: var(--fleet-text);
  font-size: 8px;
  font-weight: 600;
  padding: 4px 7px;
  border-radius: 5px;
  letter-spacing: 0.04em;
  opacity: 0.9;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
#view-thumbnails .ts-btn:hover { opacity: 1; }
#view-thumbnails .ts-btn:active { transform: scale(0.96); }
#view-thumbnails .ts-btn-y {
  background: linear-gradient(45deg, var(--ts-accent), var(--ts-accent-2));
  color: #1a1010;
  border: none;
}
#view-thumbnails .ts-btn.ts-busy { opacity: 0.55; cursor: default; }

/* a dead roll is an empty slot carrying its error — the group still ships (§4) */
#view-thumbnails .ts-out-failed {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  border-style: dashed;
  border-color: rgba(255, 107, 107, 0.4);
  background: rgba(255, 107, 107, 0.06);
  text-align: center;
}
#view-thumbnails .ts-failed-label {
  font-family: var(--fleet-ink);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--ts-accent);
}
#view-thumbnails .ts-failed-err {
  font-family: var(--fleet-mono);
  font-size: 9.5px;
  line-height: 1.4;
  color: var(--ts-dim);
  overflow-wrap: anywhere;
}

/* ---- v2: name, selectors, per-output actions (spec §7) ------------------- */
/* thumbnail name — required before refs/Generate (§1). A plain legible field:
   it is the first thing the studio touches every session. */
#view-thumbnails .ts-name {
  width: 100%;
  margin-top: 7px;
  padding: 11px 14px;
  font-family: var(--fleet-text);
  font-size: 13px;
  color: var(--text-primary);
}
#view-thumbnails .ts-name::placeholder { color: var(--ts-dim); opacity: 0.7; }
#view-thumbnails .ts-name:focus-visible { outline: 2px solid var(--ts-accent-2); outline-offset: 2px; }
#view-thumbnails .ts-name-hint {
  margin-top: 6px;
  font-family: var(--fleet-mono);
  font-size: 9.5px;
  letter-spacing: 0.02em;
  color: var(--ts-dim);
  transition: color 0.15s;
}
#view-thumbnails .ts-name-hint-warn { color: var(--ts-accent-2); }

/* aspect + resolution segmented selectors (§2). Two small radiogroups — arrow
   keys move within a group; the on state is the accent-tinted pill. */
#view-thumbnails .ts-selects { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
#view-thumbnails .ts-seg-group { display: flex; flex-direction: column; gap: 6px; }
#view-thumbnails .ts-seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 9px;
}
#view-thumbnails .ts-seg-opt {
  border: none;
  background: none;
  color: var(--ts-sec);
  font-family: var(--fleet-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
#view-thumbnails .ts-seg-opt:hover { color: var(--text-primary); }
#view-thumbnails .ts-seg-on {
  background: linear-gradient(45deg, var(--ts-accent), var(--ts-accent-2));
  color: #1a1010;
}
#view-thumbnails .ts-seg-opt:focus-visible { outline: 2px solid var(--ts-accent-2); outline-offset: 2px; }
#view-thumbnails .ts-seg-group-static .ts-chip { align-self: flex-start; }

/* refs locked until the thumbnail is named — dim the add tiles so it reads as
   not-yet, not broken. */
#view-thumbnails .ts-refs-locked .ts-ref-add { opacity: 0.45; }

/* gallery header name — a small accent pill at the head of the group meta. */
#view-thumbnails .ts-ghead-name {
  font-family: var(--fleet-ink);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ts-accent-2);
  background: rgba(254, 202, 87, 0.12);
  border: 1px solid rgba(254, 202, 87, 0.3);
  padding: 2px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  white-space: nowrap;
}

/* square (1:1) outputs get a square tile so cover-crop doesn't chop them. */
#view-thumbnails .ts-out-1x1 { aspect-ratio: 1 / 1; }

/* per-output actions reveal on hover / keyboard focus — four controls would
   crowd the tile if always on. focus-within keeps them reachable without a mouse
   (a11y baseline); touch devices, which have no hover, keep them visible. */
#view-thumbnails .ts-out-actions {
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.15s, transform 0.15s;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: calc(100% - 16px);
}
#view-thumbnails .ts-out:hover .ts-out-actions,
#view-thumbnails .ts-out:focus-within .ts-out-actions { opacity: 1; transform: none; }
@media (hover: none) {
  #view-thumbnails .ts-out-actions { opacity: 1; transform: none; }
}
#view-thumbnails .ts-btn-dl {
  background: linear-gradient(45deg, var(--ts-accent), var(--ts-accent-2));
  color: #1a1010;
  border: none;
  font-weight: 700;
}
#view-thumbnails .ts-btn-discard:hover { border-color: rgba(255, 107, 107, 0.6); color: var(--ts-accent); }
#view-thumbnails .ts-btn-armed,
#view-thumbnails .ts-btn-armed:hover {
  background: var(--ts-accent);
  color: #1a1010;
  border-color: var(--ts-accent);
  opacity: 1;
}
#view-thumbnails .ts-exp-wrap { position: relative; }
#view-thumbnails .ts-exp-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  right: 0;
  z-index: 15;
  background: #241414;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55);
  min-width: 150px;
}
#view-thumbnails .ts-exp-opt {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--fleet-text);
  font-size: 10.5px;
  padding: 8px 12px;
  cursor: pointer;
}
#view-thumbnails .ts-exp-opt:hover { background: var(--glass-bg); }
#view-thumbnails .ts-exp-opt:focus-visible { outline: 2px solid var(--ts-accent-2); outline-offset: -2px; }

/* per-box drag-over highlight — mirrors the visual weight of the old whole-grid
   .ts-drop-active (2px dashed accent-2), scoped to the ONE box under the cursor.
   inset outline-offset keeps the ring inside the box's rounded corners. */
#view-thumbnails .ts-ref-drop-active {
  outline: 2px dashed var(--ts-accent-2);
  outline-offset: -2px;
  border-color: var(--ts-accent-2);
  background: rgba(254, 202, 87, 0.10);
}

/* ---- preview lightbox -----------------------------------------------------
   Appended to <body> (NOT #view-thumbnails) so it layers above every stacking
   context, so it is scoped by class alone. Dark full-viewport backdrop; image
   centered, object-fit contain, capped 90vw/90vh (never blown up past that cap).
   View-only — no controls beyond close. */
.ts-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.85);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.ts-lightbox.hidden { display: none; }
.ts-lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}
.ts-lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.ts-lightbox-close:hover { background: rgba(0, 0, 0, 0.85); }
.ts-lightbox-close:active { transform: scale(0.94); }
.ts-lightbox-close:focus-visible { outline: 2px solid var(--ts-accent-2, #feca57); outline-offset: 2px; }
/* generated tiles are click-to-preview — hint it on the cursor */
#view-thumbnails .ts-out img { cursor: zoom-in; }
/* lock body scroll behind the open overlay */
body.ts-lightbox-lock { overflow: hidden; }

/* ---- narrow / mobile ------------------------------------------------------
   The two panes stack: controls, then the gallery. Phone users are reviewing
   and exporting far more than they are generating, so the gallery stays a
   single column at full width rather than a squeezed 2-up. */
@media (max-width: 900px) {
  #view-thumbnails .ts-wrap { flex-direction: column; overflow-y: auto; }
  #view-thumbnails .ts-left {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--glass-border);
    overflow: visible;
  }
  #view-thumbnails .ts-mid { overflow: visible; }
  #view-thumbnails .ts-generate { margin-top: 4px; }
}
@media (max-width: 480px) {
  #view-thumbnails .ts-grid { grid-template-columns: 1fr; }
  #view-thumbnails .ts-mid { padding: 12px; }
  #view-thumbnails .ts-ghead { flex-direction: column; align-items: flex-start; gap: 2px; }
  #view-thumbnails .ts-ghead-p { white-space: normal; }
  /* 44px touch targets on the overlay chips — 8px text is a desktop affordance */
  #view-thumbnails .ts-btn { font-size: 10px; padding: 8px 10px; }
}
