/* stage: 3D Stage module (gallery, viewport panes, inspector pieces). Classes are prefixed stg-. */

/* ---------------------------------------------------------------- editor layout */

.stg-editor {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}
.stg-viewport {
  flex: 1 1 auto;
  min-height: 0;
  user-select: none;
  -webkit-user-select: none;
}
.stg-viewport.is-picking .stg-pane { cursor: crosshair; }

.stg-gl {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}
.stg-panes {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 4px;
  padding: 0;
}
.stg-panes[data-layout="single"] { grid-template: 1fr / 1fr; }
.stg-panes[data-layout="side"] { grid-template: 1fr / minmax(0, 1.55fr) minmax(0, 1fr); }
.stg-panes[data-layout="quad"] { grid-template: repeat(2, minmax(0, 1fr)) / repeat(2, minmax(0, 1fr)); }

.stg-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  outline: 1px solid var(--border);
  outline-offset: -1px;
  touch-action: none;
}
.stg-pane:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.stg-ov {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.stg-pane-head {
  position: absolute;
  top: 8px;
  right: 8px;
  left: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
}
/* panes in the left column sit under the tool rail */
.stg-pane:first-child .stg-pane-head,
.stg-panes[data-layout="quad"] .stg-pane:nth-child(3) .stg-pane-head { left: 56px; }
.stg-pane-head > * { pointer-events: auto; }
.stg-pane-chip,
.stg-pane-btn,
.stg-pane-select {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  font: 700 11.5px/1 var(--font-ui);
  color: var(--text);
  background: var(--surface);
  border: var(--bw-thin) solid var(--line);
  border-radius: var(--r-pill);
  box-shadow: 1px 1px 0 0 var(--shadow-color);
}
.stg-pane-chip { margin-right: auto; pointer-events: none !important; }
.stg-pane-chip[data-kind="camera"] { color: var(--on-candy); background: var(--red); }
.stg-pane-btn { cursor: pointer; }
.stg-pane-btn:hover { background: var(--hover); }
.stg-pane-select { cursor: pointer; padding-right: 4px; }
.stg-banner .stg-pane-btn { height: 22px; margin-left: 4px; }

.stg-operate-hint {
  position: absolute;
  top: 40px;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  max-width: calc(100% - 16px);
  padding: 4px 10px;
  font-size: var(--fs-xs);
  color: var(--tooltip-fg);
  background: var(--tooltip-bg);
  border-radius: var(--r-pill);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0.9;
}

.stg-rail {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 6;
  background: var(--surface);
  border: var(--bw) solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.stg-rail-gap { width: 60%; height: 1px; margin: 2px 0; background: var(--border); }

.stg-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 7;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 120px);
  padding: 6px 8px 6px 12px;
  font-weight: 700;
  font-size: var(--fs-sm);
  color: var(--text);
  background: var(--cyan-soft);
  border: var(--bw-thin) solid var(--line);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-sm);
}
.stg-banner.is-warn { background: var(--amber-soft); }

/* ---------------------------------------------------------------- toolbar */

.stg-title {
  min-width: 80px;
  max-width: 280px;
  font-weight: 800;
}

/* ---------------------------------------------------------------- library */

.stg-library {
  top: 8px;
  left: 62px;
  bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 300px;
  max-width: calc(100% - 80px);
  overflow: hidden;
}
.stg-library-head { display: flex; align-items: center; gap: 8px; }
.stg-library-head .muted { flex: 1 1 auto; }
.stg-cats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}
.stg-cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
  padding: 6px 2px;
  font: 700 10.5px/1.1 var(--font-ui);
  color: var(--text-2);
  background: transparent;
  border: var(--bw-thin) solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.stg-cat span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stg-cat:hover { background: var(--hover); }
.stg-cat.is-active { color: var(--text); background: var(--c-soft); border-color: var(--line); }
.stg-lib-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 2px;
}
.stg-lib-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 8px 4px 6px;
  color: var(--text);
  background: var(--surface-2);
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--r-sm);
  cursor: grab;
}
.stg-lib-item:hover { background: var(--c-soft); border-color: var(--line); }
.stg-lib-item:active { cursor: grabbing; }
.stg-lib-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--on-candy);
  background: var(--c);
  border: var(--bw-thin) solid var(--line);
  border-radius: var(--r-sm);
}
.stg-lib-name {
  max-width: 100%;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
}
.stg-cast { display: flex; flex-direction: column; gap: 4px; padding-top: 6px; border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- timeline */

.stg-timeline {
  right: 12px;
  bottom: 12px;
  left: 62px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
}
.stg-timeline-main { display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; min-width: 0; }
.stg-timeline-title { font-size: var(--fs-sm); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.stg-scrub { width: 100%; accent-color: var(--cyan); }
.stg-timecode { font: 700 12px/1 var(--font-mono); color: var(--text-2); white-space: nowrap; }

/* ---------------------------------------------------------------- inspector */

.stg-inspector { min-height: 100%; }
.stg-tabs {
  position: sticky;
  top: calc(-1 * var(--s-4)); /* the aside's padding: stick to its very top edge */
  z-index: 2;
  padding: 8px var(--s-3) 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.stg-tabs .tabs { overflow-x: auto; scrollbar-width: none; }
.stg-tabs .tab { padding-left: 8px; padding-right: 8px; }
.stg-inspector-body { display: flex; flex-direction: column; min-width: 0; }
.stg-title-actions { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 600; }

.stg-help { margin: 0; font-size: 12px; line-height: 1.4; color: var(--text-muted); }
.stg-help.is-warn { color: var(--warn-text); }
.stg-name { font-size: var(--fs-md); font-weight: 800; min-width: 0; }

.stg-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.stg-row-stack { grid-template-columns: minmax(0, 1fr); gap: 5px; }
.stg-row-label { font-size: 12px; font-weight: 700; color: var(--text-2); }
.stg-row-control { min-width: 0; }
.stg-row-control > .select-wrap,
.stg-row-control > .input-wrap,
.stg-row-control > .number { width: 100%; }
.stg-row-hint { grid-column: 2; font-size: 11px; color: var(--text-muted); }

.stg-vec3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}
.stg-axis { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stg-axis .number { width: 100%; min-width: 0; }
.stg-axis-tag { font: 800 10px/1 var(--font-ui); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.stg-axis-tag[data-axis="X"] { color: var(--red); }
.stg-axis-tag[data-axis="Y"] { color: var(--green); }
.stg-axis-tag[data-axis="Z"] { color: var(--blue); }

.stg-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.stg-chip-row { display: flex; flex-wrap: wrap; gap: 5px; min-width: 0; }
.stg-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); }
.stg-stats strong { color: var(--text); font-size: var(--fs-md); }

.stg-keys { display: grid; gap: 4px; margin: 0; }
.stg-keys > div { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.stg-keys dt { font: 700 11px/1.4 var(--font-mono); color: var(--text); }
.stg-keys dd { margin: 0; color: var(--text-muted); text-align: right; }

.stg-swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.stg-swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: var(--bw-thin) solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}
.stg-swatch:hover { transform: scale(1.08); }
.stg-swatch.is-active { outline: 2px solid var(--focus); outline-offset: 2px; }
.stg-swatch-none {
  background: var(--surface) linear-gradient(135deg, transparent 45%, var(--danger) 45%, var(--danger) 55%, transparent 55%);
}

.stg-label-input { width: 64px; text-align: center; font-weight: 800; text-transform: uppercase; }
.stg-light-dot {
  display: inline-block;
  flex: none;
  width: 14px;
  height: 14px;
  border: var(--bw-thin) solid var(--line);
  border-radius: 50%;
}
.stg-dot { display: inline-block; flex: none; width: 12px; height: 12px; border: var(--bw-thin) solid var(--line); border-radius: 50%; }

.stg-pose-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.stg-pose,
.stg-lens,
.stg-kelvin,
.stg-ground,
.stg-env {
  min-width: 0;
  padding: 5px 6px;
  font: 700 11.5px/1.15 var(--font-ui);
  color: var(--text-2);
  background: var(--surface-2);
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.stg-pose:hover, .stg-lens:hover, .stg-kelvin:hover, .stg-ground:hover, .stg-env:hover { background: var(--hover); color: var(--text); }
.stg-pose.is-active,
.stg-lens.is-active,
.stg-env.is-active { color: var(--on-candy); background: var(--cyan); border-color: var(--line); }
.stg-kelvin.is-active,
.stg-ground.is-active { color: var(--text); background: var(--yellow-soft); border-color: var(--line); }
.stg-lenses { gap: 4px; }
.stg-lens { min-width: 36px; font-family: var(--font-mono); text-align: center; }
.stg-kelvin, .stg-ground { display: inline-flex; align-items: center; gap: 5px; }
.stg-kelvin span, .stg-ground span { width: 11px; height: 11px; border: var(--bw-thin) solid var(--line); border-radius: 50%; }
.stg-ground span { border-radius: 3px; }
.stg-env-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.stg-env { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 7px 2px; text-align: center; }

.stg-joints { display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--surface-2); border-radius: var(--r-sm); }
.stg-joint .slider { width: 100%; }

.stg-readout { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--text-muted); }
.stg-readout strong { color: var(--text); font-family: var(--font-mono); font-weight: 700; }

.stg-dof { display: flex; flex-direction: column; gap: 6px; }
.stg-dof-bar {
  position: relative;
  height: 10px;
  background: var(--surface-sunken);
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.stg-dof-bar span { position: absolute; top: 0; bottom: 0; background: var(--cyan); }

.stg-move {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--surface-2);
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--r-sm);
}

.stg-mini-list { display: flex; flex-direction: column; gap: 3px; margin: 0; padding: 0; list-style: none; font-size: 12.5px; }
.stg-mini-list li { display: flex; align-items: center; gap: 6px; }

.stg-tree-group { display: flex; flex-direction: column; gap: 1px; }
.stg-tree-head { display: flex; align-items: center; gap: 6px; padding: 6px 2px 3px; font-size: 11px; font-weight: 800; color: var(--text-2); }
.stg-tree-row,
.stg-light-row,
.stg-cam-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  border-radius: var(--r-sm);
}
.stg-tree-row:hover, .stg-light-row:hover, .stg-cam-row:hover { background: var(--hover); }
.stg-tree-row.is-active, .stg-light-row.is-active, .stg-cam-row.is-active { background: var(--cyan-soft); }
.stg-tree-row.is-dim .stg-tree-name, .stg-light-row.is-dim .stg-tree-name { opacity: 0.55; }
.stg-tree-name,
.stg-cam-main {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1 1 auto;
  min-width: 0;
  padding: 5px 6px;
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}
.stg-light-row { padding-right: 4px; }
.stg-cam-badge {
  display: grid;
  place-items: center;
  flex: none;
  min-width: 26px;
  height: 22px;
  padding: 0 4px;
  font: 800 12px/1 var(--font-ui);
  color: var(--on-candy);
  background: var(--red);
  border: var(--bw-thin) solid var(--line);
  border-radius: var(--r-xs);
}
.stg-cam-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stg-room { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.stg-room .number { width: 100%; min-width: 0; }
.stg-checklist {
  max-height: 200px;
  margin: 0;
  padding: 8px 10px;
  overflow: auto;
  font: 11.5px/1.45 var(--font-mono);
  color: var(--text-2);
  white-space: pre-wrap;
  background: var(--surface-sunken);
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--r-sm);
}

/* ---------------------------------------------------------------- gallery */

.stg-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: var(--s-4);
}
.stg-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: var(--bw) solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.stg-card:hover { box-shadow: var(--shadow-md); }
.stg-card-thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  padding: 0;
  overflow: hidden;
  background: var(--surface-sunken);
  border: 0;
  border-bottom: var(--bw-thin) solid var(--line);
  cursor: pointer;
}
.stg-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stg-card-empty { color: var(--text-muted); }
.stg-miniplan { width: 100%; height: 100%; }
.stg-mp-wall { stroke: var(--text-2); stroke-linecap: round; }
.stg-mp-obj { fill: var(--text-muted); opacity: 0.6; }
.stg-mp-person { stroke: var(--line); stroke-width: 0.03; }
.stg-mp-light { fill: var(--yellow); stroke: var(--line); stroke-width: 0.03; }
.stg-mp-cam { fill: var(--red); stroke: var(--line); stroke-width: 0.03; }
.stg-card-body { display: flex; flex-direction: column; gap: 6px; padding: 10px 10px 12px 12px; }
.stg-card-title { display: flex; align-items: center; gap: 4px; }
.stg-card-name {
  flex: 1 1 auto;
  padding: 0;
  font: 800 var(--fs-md)/1.2 var(--font-ui);
  color: var(--text);
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}
.stg-card-name:hover { text-decoration: underline; }
.stg-card-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }

.stg-templates { margin-top: var(--s-6); }
.stg-h2 { margin: 0 0 var(--s-3); font: 800 var(--fs-lg)/1.2 var(--font-display); }
.stg-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--s-3);
}
.stg-template {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: var(--bw-thin) solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
}
.stg-template:hover { background: var(--cyan-soft); }
.stg-template-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  color: var(--on-candy);
  background: var(--cyan);
  border: var(--bw-thin) solid var(--line);
  border-radius: var(--r-sm);
}
.stg-template-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* ---------------------------------------------------------------- dialogs */

.stg-dialog { display: flex; flex-direction: column; gap: var(--s-3); }
.stg-settype { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stg-settype-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: var(--bw-thin) solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
}
.stg-settype-btn:hover { background: var(--hover); }
.stg-settype-btn.is-active { background: var(--cyan-soft); border-color: var(--line); box-shadow: 1.5px 1.5px 0 0 var(--shadow-color); }
.stg-dialog-foot { margin-top: var(--s-2); }

@media (max-width: 860px) {
  .stg-panes[data-layout="side"] { grid-template: minmax(0, 1.4fr) minmax(0, 1fr) / 1fr; }
  .stg-library { width: auto; right: 8px; }
  /* the inspector drops below: give the viewport a fixed share of the screen */
  .stg-page .page-body { flex: 0 0 auto; height: 64vh; }
  .stg-panes[data-layout="side"] .stg-pane .stg-pane-head { left: 56px; }
}
