:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #ff6b00;
  --accent-hover: #ff8533;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 10px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); margin-top: 0.5rem; }

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}
.login-card h1 { margin-bottom: 0.25rem; }
.login-card form { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.login-card input {
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: var(--danger); color: #1a0000; }
.btn.danger:hover { background: #fca5a5; }
.btn:disabled { opacity: 0.45; cursor: default; }
a.btn { display: inline-block; text-decoration: none; }
.download-link { margin-left: 0.5rem; margin-top: 0.5rem; }

.gen-status {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.gen-status.on { color: var(--ok); border-color: var(--ok); }
.gen-status.off { color: var(--muted); }
.gen-status.warn { color: #f59e0b; border-color: #f59e0b; }
.gen-status.on::before,
.gen-status.off::before,
.gen-status.warn::before { content: "● "; }
.gen-status.on::before { color: var(--ok); }
.gen-status.off::before { color: var(--danger); }
.gen-status.warn::before { color: #f59e0b; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--accent); }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.layout { display: flex; min-height: calc(100vh - 52px); }
.layout-stages { flex-direction: row; }

.stage-nav {
  width: 200px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: var(--surface);
  overflow-y: auto;
}
.stage-nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.stage-nav-btn:hover { background: var(--surface2); }
.stage-nav-btn.active {
  background: var(--surface2);
  border-color: var(--accent);
}
.stage-nav-label { font-size: 0.82rem; line-height: 1.2; }
.stage-nav-count {
  font-size: 0.72rem;
  min-width: 1.4rem;
  text-align: center;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
}
.stage-nav-btn.active .stage-nav-count { color: var(--accent); }

.stage-sidebar { width: 240px; }
.stage-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 1120px;
}
.stage-panel-head { margin-bottom: 1rem; }
.stage-panel-head h2 { margin-bottom: 0.25rem; }
.state-summary {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  padding: 0.75rem;
  margin: 1rem 0 0;
}
.state-summary.has-errors {
  border-color: var(--danger);
}
.state-summary-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.state-chip {
  font-size: 0.8rem;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.18rem 0.5rem;
  background: var(--surface);
}
.state-next,
.state-actions {
  font-size: 0.82rem;
  color: var(--muted);
}
.state-diagnostics {
  margin: 0.55rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.82rem;
}
.state-diagnostics .error {
  color: var(--danger);
}
.stage-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}
.flow-panel {
  max-width: 1220px;
}
.flow-track {
  display: grid;
  gap: 1.15rem;
}
.flow-step {
  position: relative;
  padding: 1.05rem 0 0.2rem 2.65rem;
  border-top: 1px solid var(--border);
}
.flow-step:first-child {
  border-top: 0;
  padding-top: 0.2rem;
}
.flow-step-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.flow-step-head h3 {
  margin: 0 0 0.18rem;
  font-size: 1rem;
}
.flow-step-num {
  position: absolute;
  left: 0;
  top: 1.05rem;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.82rem;
}
.flow-step:first-child .flow-step-num {
  top: 0.2rem;
}
.flow-step.active .flow-step-num {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.flow-step.done .flow-step-num {
  border-color: var(--ok);
  background: var(--ok);
  color: #08210f;
}
.flow-step.done:not(.active) .flow-step-head h3 {
  color: var(--ok);
}
.flow-actions {
  margin-top: 0.85rem;
}
.flow-step .queue-panel {
  margin: 0.7rem 0;
}
.flow-step .diagnostics-panel:empty {
  display: none;
}
.provider-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}
.top-provider-toggle {
  padding: 0.32rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.queue-panel { margin: 1rem 0; }
.queue-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.queue-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.queue-activity {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  white-space: nowrap;
  font-weight: 800;
}
.queue-activity.running {
  color: #126b45;
}
.queue-spinner {
  display: inline-block;
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  box-sizing: border-box;
  border: 2px solid rgba(20, 125, 63, 0.22);
  border-top-color: #126b45;
  border-radius: 999px;
  animation: queue-spin 0.72s linear infinite;
}
.photo-queue-row {
  min-height: 4.85rem;
}
.photo-queue-row .queue-name {
  flex: 0 1 auto;
  min-width: 4.8rem;
  max-width: 14rem;
}
.queue-photo-preview {
  flex: 0 0 48px;
  width: 48px;
  height: 66px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fffdf8;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.68rem;
  line-height: 1.1;
  overflow: hidden;
}
.queue-photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.queue-photo-preview:hover,
.queue-photo-preview:focus-visible {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(23, 107, 91, 0.14);
}
.queue-photo-preview.pending {
  cursor: default;
  background: repeating-linear-gradient(
    135deg,
    #eef3f5,
    #eef3f5 7px,
    #fffdf8 7px,
    #fffdf8 14px
  );
}
.queue-photo-preview.is-generating {
  cursor: progress;
  background: radial-gradient(circle at center, #ffffff 0 31%, #ecfdf3 32% 100%);
}
.queue-photo-preview.is-generating .queue-spinner {
  width: 1.15rem;
  height: 1.15rem;
}
.queue-photo-preview.missing {
  cursor: default;
  text-align: center;
  padding: 0.25rem;
}
.queue-photo-preview.is-busy {
  cursor: progress;
  opacity: 0.62;
}
.queue-cancel {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid rgba(185, 28, 28, 0.2);
  background: #fffdf8;
  color: #b42318;
  cursor: pointer;
  font-size: 1.18rem;
  font-weight: 800;
  line-height: 1;
}
.queue-cancel:hover,
.queue-cancel:focus-visible {
  background: #b42318;
  color: #fff;
  outline: none;
}
.queue-cancel:disabled {
  cursor: progress;
  opacity: 0.6;
}
@keyframes queue-spin {
  to {
    transform: rotate(360deg);
  }
}
.photo-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.6rem;
}
.photo-grid.compact .photo-card img {
  aspect-ratio: 3 / 4;
}
.photo-card.selectable {
  cursor: pointer;
  border: 2px solid transparent;
  background: none;
  padding: 0;
  font: inherit;
  text-align: left;
  width: 100%;
}
.photo-card.selectable.selected { border-color: var(--accent); }
.photo-card.selectable:hover { border-color: var(--accent-hover); }
.photo-card.source-photo { position: relative; }
.source-photo-count,
#photo-select-count {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}
.source-photo-count { margin: -0.15rem 0 0.45rem; }
.link-btn.inline-reset {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0;
}
.link-btn.inline-reset:hover,
.link-btn.inline-reset:focus-visible {
  color: var(--accent-hover);
  outline: none;
  text-decoration: underline;
}
.preview-video { width: 100%; max-height: 360px; margin: 1rem 0; background: #000; border-radius: 8px; }
.scene-grid.compact { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.category-board {
  margin-bottom: 1rem;
}
.category-board-head,
.category-focus {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.category-board h3,
.category-focus h3 {
  margin-bottom: 0.2rem;
  font-size: 1rem;
}
.category-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 0.65rem;
}
.category-card {
  min-height: 104px;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.45rem;
}
.category-card:hover,
.category-card:focus-visible {
  border-color: var(--accent);
  background: var(--surface2);
  outline: none;
}
.category-card strong {
  line-height: 1.2;
}
.category-card span:last-child {
  color: var(--muted);
  font-size: 0.82rem;
}
.category-card-kind,
.master-label {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}
.category-focus {
  padding: 0.85rem 1rem;
  border: 1px solid rgba(255, 107, 0, 0.45);
  border-radius: 8px;
  background: rgba(255, 107, 0, 0.08);
}
.master-panel {
  margin-bottom: 1rem;
}
.master-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.master-thumb {
  width: 72px;
  height: 96px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: #fff;
}
.master-thumb.empty { background: var(--surface2); }
.master-main {
  min-width: 0;
}
.master-main h3 {
  margin: 0.15rem 0;
  font-size: 1.1rem;
}
.master-main p {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.3;
  max-width: 58rem;
}
.master-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
}
.master-empty {
  padding: 0.85rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(15, 20, 25, 0.55);
}
.master-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 0.35rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-size: 0.62rem;
  font-weight: 700;
  vertical-align: 0.08rem;
}
.articula-list li.master-item {
  border-color: rgba(255, 107, 0, 0.55);
  background: rgba(255, 107, 0, 0.08);
}
.montage-tools { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; align-items: end; }
.montage-tools label { font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.25rem; }
.beat-markers { margin: 0.5rem 0 1rem; font-size: 0.8rem; }
.footage-panel { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.footage-chip { border: 1px solid var(--border); border-radius: 8px; padding: 0.35rem 0.6rem; background: var(--surface2); cursor: pointer; font-size: 0.8rem; }
.footage-chip:hover { border-color: var(--accent); }
.badge.pending { color: #fbbf24; }
.badge.running { color: var(--ok); }
.badge.done { color: var(--accent); }
.sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}
.sidebar h2 { font-size: 0.85rem; text-transform: uppercase; color: var(--muted); margin-bottom: 0.75rem; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.75rem; }
.sidebar-head h2 { margin-bottom: 0; }
.archive-toggle { font-size: 0.75rem; color: var(--muted); display: flex; align-items: center; gap: 0.3rem; }
.category-scope {
  margin-bottom: 0.75rem;
}
.category-scope label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
}
.category-scope select {
  width: 100%;
  max-width: 100%;
}
.category-scope .muted {
  min-height: 1rem;
  margin-top: 0.3rem;
  font-size: 0.72rem;
  line-height: 1.25;
}
.article-search { margin-bottom: 0.75rem; }
.article-search input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.article-search .muted { margin-top: 0.3rem; font-size: 0.72rem; line-height: 1.25; }
.workspace { flex: 1; padding: 1.25rem; overflow-y: auto; }
.placeholder { color: var(--muted); padding: 2rem; text-align: center; }

.articula-list { list-style: none; }
.articula-list li {
  position: relative;
  padding: 0.55rem 1.85rem 0.55rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 0.25rem;
  border: 1px solid transparent;
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
}
.articula-list li:hover { background: var(--surface2); }
.articula-list li.active { background: var(--surface2); border-color: var(--accent); }
.articula-list li.archived { opacity: 0.62; }
.articula-list li.generating { border-color: rgba(74, 222, 128, 0.35); }
.articula-list li.generated { border-color: rgba(255, 107, 0, 0.35); }
.articula-list .meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.articula-main { min-width: 0; }
.articula-remove {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  width: 1.25rem;
  height: 1.25rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.78;
}
.articula-remove:hover,
.articula-remove:focus-visible {
  background: rgba(255, 107, 0, 0.18);
  color: var(--danger);
  outline: none;
  opacity: 1;
}
.articula-remove:disabled {
  cursor: progress;
  opacity: 0.6;
}
.articula-code { font-weight: 600; }
.articula-name {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.25;
  margin-top: 0.1rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.articula-thumb {
  width: 38px;
  height: 56px;
  flex: 0 0 38px;
  border-radius: 5px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: #fff;
}
.articula-thumb.empty { background: var(--surface2); }

.photo-flow-articulas-board {
  margin: 0 0 1rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fffdf8;
}

.photo-flow-articulas-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.photo-flow-articulas-head h3 {
  margin: 0 0 0.15rem;
  font-size: 0.95rem;
}

.photo-flow-articulas-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.55rem;
}

.photo-flow-articula {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  min-width: 0;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.photo-flow-articula:hover,
.photo-flow-articula:focus-visible {
  border-color: rgba(23, 107, 91, 0.45);
  background: #f2f7f6;
  outline: none;
}

.photo-flow-articula.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.photo-flow-articula-thumb {
  width: 34px;
  height: 50px;
  flex: 0 0 34px;
  border: 1px solid var(--border);
  border-radius: 5px;
  object-fit: cover;
  background: #fff;
}

.photo-flow-articula-thumb.empty {
  background: var(--surface2);
}

.photo-flow-articula-main {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.photo-flow-articula-main strong,
.photo-flow-articula-main span,
.photo-flow-articula-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-flow-articula-main span,
.photo-flow-articula-main small,
.photo-flow-articulas-empty {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.25;
}

.editor-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.editor-title-row { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.editor-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--muted);
}
.badge.generated { color: var(--ok); }
.badge.edited { color: var(--accent); }
.badge.archived { color: var(--muted); }

.tabs {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.tab-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
  min-width: 220px;
  transition: border-color 0.15s, background 0.15s;
}
.tab-btn:hover { border-color: var(--accent-hover); }
.tab-btn.active {
  border-color: var(--accent);
  background: var(--surface2);
  box-shadow: 0 0 0 1px var(--accent);
}
.tab-icon { font-size: 1.4rem; }
.tab-text { display: flex; flex-direction: column; gap: 0.1rem; }
.tab-title { font-weight: 600; }
.tab-sub { font-size: 0.74rem; color: var(--muted); }
.tab-btn.active .tab-sub { color: var(--accent); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.workflow-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.workflow-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) 1.15fr;
  gap: 1rem;
  align-items: start;
}
.field-label,
.prompt-card span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  font: inherit;
}
textarea { resize: vertical; }
.field-control { margin-bottom: 0.45rem; }
.compact-control { width: min(280px, 100%); }
.inline-field {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 0.3rem 0 0.9rem;
}
.inline-field .field-label { margin-bottom: 0; }
.small { font-size: 0.78rem; }
.inline-error { color: #dc2626; font-size: 0.78rem; }
.compact { margin-bottom: 0.4rem; }
.compact h4 { font-size: 0.9rem; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.55rem;
}
.photo-card {
  display: block;
  position: relative;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}
button.photo-card {
  width: 100%;
  padding: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.regen-photo-card {
  position: relative;
}
.regen-photo-card.is-busy {
  opacity: 0.55;
  pointer-events: none;
}
.photo-remove {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  z-index: 2;
  width: 1.85rem;
  height: 1.85rem;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid rgba(185, 28, 28, 0.18);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 5px 14px rgba(15, 23, 42, 0.18);
  color: #b42318;
  cursor: pointer;
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.photo-remove:hover,
.photo-remove:focus-visible {
  background: #b42318;
  color: #fff;
  outline: none;
  transform: translateY(-1px);
}
.photo-restore {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  z-index: 2;
  width: 1.85rem;
  height: 1.85rem;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid rgba(22, 101, 52, 0.22);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 5px 14px rgba(15, 23, 42, 0.16);
  color: #166534;
  cursor: pointer;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.photo-restore:hover,
.photo-restore:focus-visible {
  background: #166534;
  color: #fff;
  outline: none;
  transform: translateY(-1px);
}
.scene-card .video-remove {
  top: 0.5rem;
  right: 0.5rem;
  z-index: 4;
  background: rgba(255, 255, 255, 0.96);
}
.scene-card.is-busy {
  opacity: 0.58;
  pointer-events: none;
}
.photo-card.disabled-select {
  opacity: 0.62;
}
.photo-card.is-excluded {
  opacity: 0.54;
  border-style: dashed;
  filter: grayscale(0.2);
}
.photo-card.is-excluded:hover {
  opacity: 0.78;
}
.photo-card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  display: block;
  background: #fff;
}
.photo-card span {
  display: block;
  padding: 0.3rem;
  font-size: 0.7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.zoom-open { overflow: hidden; }
.photo-zoom {
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow-y: auto;
  scrollbar-gutter: stable;
  background: rgba(4, 8, 13, 0.92);
}
.photo-zoom-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 13, 0.82);
}
.photo-zoom-panel {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  margin: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: #05070a;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}
.photo-zoom-close {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  z-index: 3;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(15, 20, 25, 0.78);
  color: #fff;
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
}
.photo-zoom-close:hover { border-color: var(--accent); color: #fff; }
.photo-zoom-media {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0;
  background: #05070a;
  overflow: auto;
  scrollbar-gutter: stable;
  position: relative;
  user-select: none;
  touch-action: none;
  cursor: zoom-in;
}
.photo-zoom-media.is-zoomed { cursor: grab; }
.photo-zoom-media.is-dragging { cursor: grabbing; }
.photo-zoom-media img {
  position: absolute;
  inset: 0.75rem;
  width: calc(100% - 1.5rem);
  height: calc(100% - 1.5rem);
  max-width: none;
  max-height: none;
  object-fit: contain;
  background: transparent;
  transform: translate3d(0, 0, 0) scale(1);
  transform-origin: center center;
  transition: transform 120ms ease;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  cursor: inherit;
}
.photo-zoom-media.is-dragging img { transition: none; }
.photo-zoom-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
}
.photo-zoom-title {
  font-weight: 600;
  line-height: 1.25;
}
.photo-zoom-subtitle {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.82rem;
}
.prompt-tools {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.9rem 0;
  flex-wrap: wrap;
}
.prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
}
.prompt-card {
  display: block;
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
}

.scene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  isolation: isolate;
}
.video-select-save-row {
  justify-content: flex-start;
  margin-top: 0;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}
.video-select-save-row .btn {
  min-width: 210px;
}
.video-auto-save-toggle {
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.video-save-status {
  flex: 1 1 220px;
  min-width: 180px;
}
.candidates-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.scene-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: default;
  color: var(--text);
  text-align: left;
  display: block;
  width: 100%;
  padding: 0;
  font: inherit;
  transition: z-index 0s linear 0.16s;
}
.scene-card video { width: 100%; display: block; background: #000; pointer-events: none; }
.lazy-video-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 9 / 12;
  overflow: hidden;
  background: linear-gradient(145deg, #141823, #07090d);
  cursor: zoom-in;
  transform-origin: center top;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-radius 0.16s ease;
  z-index: 1;
}
.lazy-video-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.lazy-video-icon {
  position: absolute;
  inset: auto;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  font-style: normal;
  font-size: 0.9rem;
  line-height: 1;
  padding-left: 0.1rem;
  pointer-events: none;
}
.lazy-video-frame.loaded .lazy-video-icon {
  opacity: 0;
}
.scene-card.is-preview-expanded {
  z-index: 40;
  overflow: visible;
  transition-delay: 0s;
}
.scene-card.is-preview-expanded .lazy-video-frame {
  transform: scale(2);
  cursor: zoom-out;
  border-radius: 8px;
  box-shadow: 0 22px 54px rgba(17, 20, 30, 0.36);
}
.scene-card.is-preview-expanded .lazy-video-frame video {
  object-fit: contain;
}
.scene-card span { display: block; padding: 0.4rem 0.6rem; font-size: 0.78rem; color: var(--muted); line-height: 1.35; }
.scene-card-body {
  display: grid;
  gap: 0.45rem;
  padding: 0.55rem;
  background: #fff;
}
.scene-card-body span {
  padding: 0;
}
.scene-card-body .btn {
  width: 100%;
  justify-content: center;
  min-height: 2.15rem;
  padding: 0.45rem 0.55rem;
  font-size: 0.78rem;
}
.scene-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 82, 20, 0.24), 0 10px 24px rgba(255, 82, 20, 0.16); }
.scene-pick-badge {
  position: absolute;
  top: 0.45rem;
  left: 0.45rem;
  z-index: 2;
  min-width: 1.7rem;
  height: 1.7rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: none;
  place-items: center;
  font-weight: 800;
  font-size: 0.86rem;
  box-shadow: 0 8px 18px rgba(255, 82, 20, 0.28);
}
.scene-card.selected .scene-pick-badge {
  display: grid;
}

.segments-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.segments-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }

.segment-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 0.6fr auto;
  gap: 0.75rem;
  align-items: end;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.segment-row:last-child { border-bottom: none; }
.segment-row label { font-size: 0.75rem; color: var(--muted); display: block; margin-bottom: 0.25rem; }
.range-val { font-size: 0.8rem; text-align: center; }
.segment-row .btn-remove { color: var(--danger); background: none; border: none; cursor: pointer; padding: 0.5rem; }

.preview-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.preview-panel video { width: 100%; max-height: 400px; background: #000; border-radius: 6px; }
.export-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 1rem; flex-wrap: wrap; gap: 0.75rem; }

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 200px; }
  .workflow-grid { grid-template-columns: 1fr; }
  .segment-row { grid-template-columns: 1fr; }
  .photo-zoom-panel {
    width: 100vw;
    height: 100vh;
    margin: 0;
    border-radius: 0;
  }
  .photo-zoom-footer {
    align-items: stretch;
    flex-direction: column;
  }
  .photo-zoom-footer .btn { width: 100%; }
  .photo-queue-row {
    flex-wrap: wrap;
    min-height: 4.3rem;
  }
  .queue-photo-preview {
    flex-basis: 42px;
    width: 42px;
    height: 58px;
  }
  .queue-activity-label {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .queue-spinner {
    animation: none;
  }
}

/* Dashboard refresh */
:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface2: #e8eef1;
  --border: #cbd5dc;
  --text: #172027;
  --muted: #60717d;
  --accent: #176b5b;
  --accent-hover: #0f8a71;
  --danger: #c2413b;
  --ok: #168456;
  --warning: #b76e00;
  --shadow-sm: 0 8px 24px rgba(21, 32, 39, 0.07);
  --shadow-md: 0 18px 48px rgba(21, 32, 39, 0.11);
  --radius: 8px;
}

html {
  background: var(--bg);
}

body {
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

.muted {
  color: var(--muted);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  padding: 0.9rem 1.45rem;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid rgba(203, 213, 220, 0.92);
  box-shadow: 0 10px 34px rgba(21, 32, 39, 0.06);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--text);
  font-size: 1.08rem;
  font-weight: 800;
}

.brand::before {
  content: "";
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 6px;
  background: linear-gradient(135deg, #176b5b, #2f7d95);
  box-shadow: 0 8px 18px rgba(23, 107, 91, 0.24);
}

.topbar-actions {
  gap: 0.65rem;
}

.btn {
  min-height: 2.35rem;
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  border: 1px solid transparent;
  font-weight: 700;
  line-height: 1.15;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  box-shadow: 0 10px 22px rgba(23, 107, 91, 0.2);
}

.btn.primary:hover {
  background: linear-gradient(135deg, #11584b, #0f7d67);
}

.btn.secondary,
.btn.ghost {
  background: #fff;
  color: #28333a;
  border-color: var(--border);
  box-shadow: 0 4px 14px rgba(21, 32, 39, 0.04);
}

.btn.secondary:hover,
.btn.ghost:hover {
  border-color: rgba(23, 107, 91, 0.35);
  background: #f2f7f6;
}

.btn.danger {
  background: #fff5f5;
  color: #b91c1c;
  border-color: #fecaca;
}

.btn.danger:hover {
  background: #fee2e2;
}

.gen-status {
  background: #fff;
  border-color: var(--border);
  color: var(--muted);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
}

.gen-status.on {
  color: #126b45;
  border-color: #bbf7d0;
  background: #e9f7ef;
}

.gen-status.off {
  color: #9a3412;
  border-color: #fed7aa;
  background: #fff7ed;
}

.layout {
  min-height: calc(100vh - 72px);
  height: calc(100vh - 72px);
  overflow: hidden;
}

.stage-nav {
  width: 188px;
  padding: 0.65rem 0.45rem;
  background: #fff;
  border-right: 1px solid var(--border);
  box-shadow: 10px 0 30px rgba(21, 32, 39, 0.035);
}

.stage-nav-btn {
  min-height: 2.35rem;
  padding: 0.48rem 0.52rem;
  border-radius: 7px;
  color: #34424a;
}

.stage-nav-btn:hover {
  background: #f6f1ff;
}

.stage-nav-btn.active {
  background: #f0e7ff;
  border-color: transparent;
  color: #8729b3;
  box-shadow: inset 3px 0 0 var(--accent);
}

.stage-nav-label {
  font-size: 0.76rem;
  font-weight: 700;
}

.stage-nav-count {
  min-width: 1.35rem;
  padding: 0.1rem 0.32rem;
  background: #f0f2f7;
  color: #6b7280;
  font-weight: 800;
  font-size: 0.66rem;
}

.stage-nav-btn.active .stage-nav-count {
  background: #fff;
  color: var(--accent);
}

.sidebar {
  width: 228px;
  padding: 0.65rem;
  background: #fbfcff;
  border-right: 1px solid var(--border);
}

.stage-sidebar {
  width: 228px;
  transition: width 160ms ease, padding 160ms ease, opacity 120ms ease;
}

.article-sidebar-toggle {
  align-self: flex-start;
  position: sticky;
  top: 0.65rem;
  z-index: 5;
  margin: 0.65rem 0.28rem 0 0.28rem;
  padding: 0.48rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fffdf8;
  color: #6b4d35;
  box-shadow: 0 8px 20px rgba(30, 34, 46, 0.08);
  cursor: pointer;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.article-sidebar-toggle:hover,
.article-sidebar-toggle:focus-visible {
  border-color: var(--accent);
  color: #9a3d00;
  outline: none;
}

body.article-sidebar-collapsed .stage-sidebar {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.sidebar-head {
  padding: 0.05rem 0 0.55rem;
  border-bottom: 1px solid var(--border);
}

.sidebar h2 {
  color: var(--text);
  font-size: 0.88rem;
  text-transform: none;
  font-weight: 800;
}

.archive-toggle {
  padding: 0.22rem 0.36rem;
  border-radius: 7px;
  background: #fff;
  border: 1px solid var(--border);
  color: #4b5563;
  font-size: 0.68rem;
}

.category-scope {
  margin: 0.62rem 0 0.55rem;
  padding: 0.56rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 5px 18px rgba(30, 34, 46, 0.035);
}

.category-scope label,
.field-label,
.prompt-card span,
.segment-row label,
.montage-tools label {
  color: #687084;
  font-weight: 700;
}

.article-search {
  position: sticky;
  top: 0;
  z-index: 2;
  padding-bottom: 0.52rem;
  background: #fbfcff;
}

.article-search input,
textarea,
select,
.login-card input {
  min-height: 2.1rem;
  border-radius: 7px;
  border-color: #dfe3ee;
  background: #fff;
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(30, 34, 46, 0.03);
}

.article-search input:focus,
textarea:focus,
select:focus,
.login-card input:focus {
  border-color: rgba(23, 107, 91, 0.65);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.12);
  outline: none;
}

.articula-list {
  padding-right: 0.15rem;
}

.articula-list li {
  margin-bottom: 0.36rem;
  padding: 0.48rem 1.55rem 0.48rem 0.46rem;
  border-radius: 7px;
  background: #fff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(30, 34, 46, 0.035);
  gap: 0.42rem;
}

.articula-list li:hover {
  background: #f2f7f6;
  border-color: rgba(23, 107, 91, 0.18);
}

.articula-list li.active {
  background: #f4ecff;
  border-color: rgba(23, 107, 91, 0.35);
  box-shadow: 0 8px 22px rgba(23, 107, 91, 0.12);
}

.articula-list li.master-item {
  border-color: rgba(23, 107, 91, 0.35);
  background: #f2f7f6;
}

.articula-code {
  color: #1f2433;
  font-weight: 800;
  font-size: 0.9rem;
}

.articula-name,
.articula-list .meta {
  color: #687084;
  font-size: 0.68rem;
  line-height: 1.18;
}

.articula-thumb {
  width: 32px;
  height: 48px;
  flex-basis: 32px;
  border-radius: 6px;
  border-color: #e7e9f1;
  box-shadow: inset 0 0 0 1px #fff;
}

.workspace {
  padding: 1.25rem 1.35rem 2rem;
  background: linear-gradient(180deg, #f7f9fa, #eef3f5);
}

.placeholder {
  margin: 0 auto;
  max-width: 560px;
  padding: 2rem;
  border: 1px dashed #d8dce8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.75);
}

.stage-panel,
.workflow-panel,
.candidates-panel,
.segments-panel,
.preview-panel,
.login-card {
  background: #fff;
  border-color: var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.stage-panel {
  max-width: 1280px;
  padding: 1.35rem;
}

.stage-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.stage-panel-head h2 {
  color: #111827;
  font-size: 1.35rem;
  line-height: 1.2;
}

.stage-panel-head .muted {
  max-width: 56rem;
  margin-top: 0.25rem;
}

.workflow-grid {
  grid-template-columns: minmax(280px, 0.82fr) minmax(360px, 1.18fr);
  gap: 1.15rem;
}

.workflow-grid > div,
.prompt-card,
.queue-panel,
.montage-tools,
.footage-panel,
.segments-box {
  border-radius: 8px;
}

.workflow-grid > div:first-child {
  padding: 1rem;
  border: 1px solid var(--border);
  background: #fbfcff;
}

textarea {
  line-height: 1.45;
}

#valuable-info {
  min-height: 132px;
}

.category-board {
  margin-top: 1rem;
}

.category-board-head,
.category-focus {
  align-items: flex-start;
}

.category-card-grid {
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.75rem;
}

.category-card {
  min-height: 118px;
  padding: 0.95rem;
  background: #fff;
  border-color: var(--border);
  box-shadow: 0 7px 20px rgba(30, 34, 46, 0.045);
}

.category-card:hover,
.category-card:focus-visible {
  background: #f2f7f6;
  border-color: rgba(23, 107, 91, 0.38);
  box-shadow: 0 12px 28px rgba(23, 107, 91, 0.12);
  transform: translateY(-1px);
}

.category-card strong {
  color: #1f2433;
  font-size: 0.96rem;
}

.category-card-kind,
.master-label {
  color: var(--accent);
}

.category-focus {
  padding: 0.95rem 1rem;
  border-color: rgba(23, 107, 91, 0.24);
  background: #f2f7f6;
}

.master-panel {
  margin: 1rem 0;
}

.master-card {
  grid-template-columns: 86px minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
  background: #fff;
  border-color: rgba(23, 107, 91, 0.18);
  box-shadow: var(--shadow-sm);
}

.master-thumb {
  width: 86px;
  height: 116px;
  border-radius: 8px;
  border-color: #e7e9f1;
}

.master-thumb.empty,
.articula-thumb.empty {
  background: #f0f2f7;
}

.master-main h3 {
  color: #111827;
  font-size: 1.22rem;
}

.master-badge {
  background: var(--accent);
  box-shadow: 0 5px 14px rgba(23, 107, 91, 0.2);
}

.master-empty {
  border-color: #d8dce8;
  background: #fff;
}

.photo-grid {
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 0.75rem;
}

.photo-card,
.scene-card {
  position: relative;
  background: #fff;
  border-color: var(--border);
  border-radius: 8px;
  box-shadow: 0 5px 16px rgba(30, 34, 46, 0.045);
}

.photo-card:hover,
.scene-card:hover {
  border-color: rgba(23, 107, 91, 0.38);
}

.photo-card.selectable.selected,
.scene-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(23, 107, 91, 0.12), 0 10px 24px rgba(23, 107, 91, 0.14);
}

.photo-card span,
.scene-card span {
  color: #687084;
  background: #fff;
}

.scene-card .scene-pick-badge {
  color: #fff;
  background: var(--accent);
  padding: 0;
  display: none;
}

.scene-card.selected .scene-pick-badge {
  display: grid;
}

.photo-card.source-photo.selected::after {
  display: none;
}

.prompt-grid {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.9rem;
}

.prompt-card {
  padding: 0.85rem;
  background: #fbfcff;
  border-color: var(--border);
  box-shadow: 0 5px 16px rgba(30, 34, 46, 0.035);
}

.prompt-card textarea {
  min-height: 112px;
  background: #fff;
}

.prompts-panel {
  width: 100%;
  max-width: none;
}

.prompt-usp-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0.85rem 0 1rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcff;
}

.prompt-usp-card span {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.prompt-usp-card textarea {
  min-height: 72px;
  resize: vertical;
  background: #fff;
}

.prompts-panel .prompt-grid {
  align-items: start;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.prompts-panel .prompt-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.prompts-panel .prompt-card textarea {
  min-height: 132px;
  overflow-y: hidden;
  resize: vertical;
  line-height: 1.4;
}

@media (max-width: 980px) {
  .prompts-panel .prompt-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1200px) {
  body[data-stage="prompts"] .stage-nav {
    width: 188px;
  }

  body[data-stage="prompts"] .stage-sidebar {
    width: 210px;
  }

  body[data-stage="prompts"] .workspace {
    padding: 1rem 1rem 1.5rem;
  }

  body[data-stage="prompts"] .prompts-panel {
    padding: 0.85rem;
  }

  body[data-stage="prompts"] .prompts-panel .stage-panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.45rem;
  }

  body[data-stage="prompts"] .prompts-panel .stage-panel-head h2 {
    margin-bottom: 0;
  }

  body[data-stage="prompts"] .prompts-panel .stage-panel-head .muted {
    max-width: 420px;
    margin-top: 0.15rem;
    text-align: right;
  }

  body[data-stage="prompts"] #prompts-meta {
    margin: 0.25rem 0 0.45rem;
    font-size: 0.84rem;
  }

  body[data-stage="prompts"] .inline-field {
    margin-bottom: 0.55rem;
  }

  body[data-stage="prompts"] .prompts-panel .prompt-grid {
    gap: 0.65rem;
  }

  body[data-stage="prompts"] .prompts-panel .prompt-card {
    padding: 0.55rem;
  }

  body[data-stage="prompts"] .prompts-panel .prompt-card span {
    margin-bottom: 0.25rem;
    font-size: 0.72rem;
  }

  body[data-stage="prompts"] .prompts-panel .prompt-card textarea {
    min-height: 128px;
    padding: 0.55rem;
    font-size: 0.86rem;
    line-height: 1.38;
  }

  body[data-stage="prompts"] .prompts-panel .stage-actions {
    margin-top: 0.65rem;
  }

  body[data-stage="prompts"] .category-scope .muted,
  body[data-stage="prompts"] .articula-thumb {
    display: none;
  }

  body[data-stage="prompts"] .articula-list li {
    padding: 0.58rem 0.65rem;
  }
}

.queue-panel {
  padding: 0.45rem 0.85rem;
  background: #fbfcff;
  border: 1px solid var(--border);
}

.queue-row {
  padding: 0.65rem 0;
  border-bottom-color: #edf0f6;
}

.badge {
  background: #f0f2f7;
  color: #596173;
  font-weight: 800;
}

.badge.pending {
  color: #92400e;
  background: #fff7ed;
}

.badge.running {
  color: #126b45;
  background: #e9f7ef;
}

.badge.done,
.badge.generated {
  color: #6f22a0;
  background: #f4ecff;
}

.badge.edited {
  color: #0f766e;
  background: #ecfeff;
}

.badge.archived {
  color: #6b7280;
  background: #f3f4f6;
}

.montage-tools,
.footage-panel {
  padding: 0.85rem;
  background: #fbfcff;
  border: 1px solid var(--border);
}

.footage-chip {
  background: #fff;
  border-color: var(--border);
  color: #34424a;
}

.footage-chip:hover {
  border-color: rgba(23, 107, 91, 0.45);
  background: #f2f7f6;
}

.preview-video,
.scene-card video,
.preview-panel video {
  border-radius: 8px;
  background: #0b0d12;
}

.segment-row {
  border-bottom-color: #edf0f6;
}

.segment-row .btn-remove,
.articula-remove:hover,
.articula-remove:focus-visible {
  color: #b91c1c;
}

.articula-remove {
  color: #98a1b3;
}

.photo-zoom-panel {
  background: #05070a;
  border-color: transparent;
}

.photo-zoom-footer {
  background: #fffdf8;
}

.photo-zoom-title {
  color: var(--text);
}

@media (max-width: 1120px) {
  .stage-nav {
    width: 190px;
  }

  .stage-sidebar {
    width: 280px;
  }

  .workspace {
    padding: 1rem;
  }
}

@media (max-width: 860px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .layout {
    height: auto;
    overflow: visible;
  }

  .layout-stages {
    flex-direction: column;
  }

  .stage-nav {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    overflow-x: auto;
  }

  .stage-nav-btn {
    min-width: 160px;
  }

  .sidebar,
  .stage-sidebar {
    width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .article-sidebar-toggle {
    display: none;
  }

  body.article-sidebar-collapsed .stage-sidebar {
    width: 100%;
    padding: 0.65rem;
    border-bottom: 1px solid var(--border);
    opacity: 1;
    overflow: visible;
    pointer-events: auto;
  }

  .article-search {
    position: static;
  }

  .workspace {
    overflow: visible;
  }

  .stage-panel-head,
  .master-card {
    display: block;
  }

  .master-thumb {
    margin-bottom: 0.75rem;
  }

  .master-actions {
    justify-content: flex-start;
    margin-top: 0.75rem;
  }

  .workflow-grid {
    grid-template-columns: 1fr;
  }
}

/* Operator neutral tuning */
:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface2: #e8eef1;
  --border: #cbd5dc;
}

html,
body {
  background: var(--bg);
}

.topbar {
  background: rgba(255, 255, 255, 0.94);
  border-bottom-color: rgba(203, 213, 220, 0.96);
}

.stage-nav {
  background: #ffffff;
  border-right-color: var(--border);
}

.sidebar,
.stage-sidebar,
.article-search {
  background: #f4f7f8;
}

.workspace {
  background: linear-gradient(180deg, #eef2f4, #e4eaee);
}

.stage-panel,
.workflow-panel,
.candidates-panel,
.segments-panel,
.preview-panel,
.login-card,
.category-scope,
.articula-list li,
.category-card,
.master-card,
.photo-card,
.scene-card,
.prompt-card,
.queue-panel,
.montage-tools,
.footage-panel {
  background-color: #ffffff;
  border-color: var(--border);
}

.workflow-grid > div:first-child,
.placeholder {
  background: rgba(255, 255, 255, 0.78);
  border-color: var(--border);
}

.article-search input,
textarea,
select,
.login-card input,
.btn.secondary,
.btn.ghost,
.photo-card span,
.scene-card span {
  background: #fffdf8;
}

.articula-list li:hover,
.category-card:hover,
.category-card:focus-visible,
.footage-chip:hover,
.btn.secondary:hover,
.btn.ghost:hover {
  background: #fff6ee;
}

.stage-nav-btn:hover,
.stage-nav-btn.active,
.category-focus,
.articula-list li.active,
.articula-list li.master-item {
  background: #f7edff;
}

.montage-board {
  display: grid;
  gap: 1rem;
}

.montage-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.montage-section-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.montage-section-head h3 {
  color: #111827;
  font-size: 1rem;
  line-height: 1.25;
}

.montage-section-head .muted {
  margin-top: 0.18rem;
}

.montage-step,
.slot-number {
  min-width: 1.8rem;
  height: 1.8rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(255, 107, 0, 0.2);
}

.montage-summary {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.montage-summary strong,
.montage-summary span {
  display: block;
}

.montage-active-slot {
  white-space: nowrap;
  border: 1px solid rgba(255, 107, 0, 0.28);
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  background: #fff4e8;
  color: #9a3d00;
  font-weight: 700;
  font-size: 0.82rem;
}

.montage-timeline {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.montage-slot {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fffdf8;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.montage-slot:hover,
.montage-slot:focus-visible {
  border-color: rgba(255, 107, 0, 0.42);
  outline: none;
}

.montage-slot.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 107, 0, 0.18), 0 12px 26px rgba(255, 107, 0, 0.12);
}

.slot-head {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.7rem;
}

.slot-head strong,
.slot-head span {
  display: block;
}

.slot-head strong {
  color: #171923;
  font-size: 0.86rem;
  line-height: 1.25;
  word-break: break-word;
}

.slot-head span:not(.slot-number) {
  color: #687084;
  font-size: 0.75rem;
  margin-top: 0.15rem;
}

.slot-media {
  aspect-ratio: 9 / 12;
  background: #0b0d12;
}

.slot-media video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #0b0d12;
}

.slot-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: #9aa2b5;
  background: repeating-linear-gradient(
    135deg,
    #fff7ef,
    #fff7ef 12px,
    #fffdf8 12px,
    #fffdf8 24px
  );
  font-weight: 700;
}

.slot-controls {
  display: grid;
  gap: 0.45rem;
  padding: 0.65rem;
}

.slot-controls label {
  display: grid;
  gap: 0.2rem;
  color: #687084;
  font-size: 0.72rem;
}

.slot-controls input[type="range"] {
  width: 100%;
}

.slot-controls select {
  width: 100%;
}

.slot-controls .slot-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.slot-controls .slot-check input {
  width: auto;
}

.slot-controls .btn-remove {
  justify-self: start;
  border: 1px solid #ffd0d0;
  border-radius: 6px;
  background: #fff6f6;
  color: #b91c1c;
  padding: 0.35rem 0.55rem;
}

.montage-candidates {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.candidate-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.candidate-head h3 {
  color: #111827;
  font-size: 0.96rem;
}

body[data-stage="montage"] .scene-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(122px, 1fr));
}

body[data-stage="montage"] .scene-card {
  min-height: 0;
}

body[data-stage="montage"] .scene-card video {
  aspect-ratio: 9 / 12;
  object-fit: cover;
}

.preview-caption {
  margin-bottom: 0.55rem;
}

body[data-stage="montage"] .preview-video {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  max-height: 620px;
  background: #0b0d12;
}

body[data-stage="montage"] .workspace {
  padding: 0.85rem 1rem 1.2rem;
}

body[data-stage="montage"] .stage-panel {
  width: 100%;
  max-width: none;
  min-height: calc(100vh - 92px);
}

@media (min-width: 1500px) {
  body[data-stage="montage"] .montage-board {
    grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
    align-items: start;
  }

  body[data-stage="montage"] .montage-section:first-child {
    grid-column: 1 / -1;
  }

  body[data-stage="montage"] .montage-section:nth-child(2) {
    grid-column: 1;
    min-width: 0;
  }

  body[data-stage="montage"] .montage-section:nth-child(3) {
    grid-column: 2;
    position: sticky;
    top: 0.85rem;
  }

  body[data-stage="montage"] .montage-timeline {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  body[data-stage="montage"] .scene-grid.compact {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  }

  body[data-stage="montage"] .preview-video {
    max-width: none;
    max-height: min(66vh, 720px);
  }
}

@media (max-width: 1180px) {
  .montage-timeline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .montage-summary,
  .candidate-head {
    display: block;
  }

  .montage-active-slot {
    display: inline-block;
    margin-top: 0.55rem;
  }

  .montage-timeline {
    grid-template-columns: 1fr;
  }
}

.diagnostics-panel {
  margin: 0.75rem 0 1rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
}

.diagnostics-panel:empty {
  display: none;
}

.diagnostics-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.diagnostics-head strong {
  display: block;
  color: #151923;
}

.diagnostics-head .muted {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.82rem;
}

.diagnostics-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.diagnostics-stats {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.diagnostics-stats span {
  padding: 0.22rem 0.48rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: #4b5565;
  background: #fff;
  font-size: 0.78rem;
}

.diagnostics-note {
  color: #687084;
  font-size: 0.84rem;
  margin-bottom: 0.65rem;
}

.diagnostics-jobs {
  display: grid;
  gap: 0.4rem;
}

.diagnostics-job {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto auto minmax(92px, auto);
  align-items: center;
  gap: 0.55rem;
  padding: 0.48rem 0;
  border-top: 1px solid rgba(217, 222, 232, 0.8);
  font-size: 0.84rem;
}

.diagnostics-job:first-child {
  border-top: 0;
}

.diagnostics-job.stale {
  color: #9a3412;
}

.diagnostics-job small {
  grid-column: 1 / -1;
  color: #b91c1c;
}

.chain-list {
  display: grid;
  gap: 0.5rem;
}

.chain-row {
  border-top: 1px solid rgba(217, 222, 232, 0.8);
  padding-top: 0.55rem;
}

.chain-row.problem summary {
  color: #9a3412;
}

.chain-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.chain-row summary {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto minmax(120px, auto);
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.chain-prompts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 0.65rem 0 0.1rem;
}

.chain-prompts p {
  margin: 0.25rem 0 0;
  color: #4b5565;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chain-error {
  grid-column: 1 / -1;
  color: #b91c1c !important;
}

.export-result-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.export-note {
  color: #687084;
  font-size: 0.84rem;
}

@media (max-width: 760px) {
  .diagnostics-head,
  .diagnostics-job,
  .chain-row summary,
  .chain-prompts {
    display: block;
  }

  .diagnostics-actions {
    justify-content: flex-start;
    margin-top: 0.55rem;
  }

  .diagnostics-job > * {
    margin-top: 0.25rem;
  }
}

body[data-stage="montage"] .stage-panel.montage-editor {
  max-width: none;
  width: 100%;
  padding: 0.9rem;
  min-height: calc(100vh - 84px);
}

.montage-editor-head {
  align-items: center;
  gap: 1rem;
}

.montage-editor-head h2 {
  flex: 0 0 auto;
}

.montage-actionbar {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
  width: 100%;
}

.montage-actionbar label {
  display: grid;
  gap: 0.22rem;
  min-width: 130px;
  color: #687084;
  font-size: 0.75rem;
}

.montage-actionbar .btn {
  min-height: 38px;
}

.montage-silent {
  min-width: auto !important;
  display: flex !important;
  align-items: center;
  gap: 0.4rem !important;
  height: 38px;
  padding: 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fffdf8;
}

.montage-editor-grid {
  display: grid;
  grid-template-columns: minmax(150px, 180px) minmax(420px, 1fr) minmax(220px, 260px);
  gap: 0.85rem;
  align-items: stretch;
  min-height: min(62vh, 720px);
}

.montage-bin,
.montage-preview-stage,
.montage-inspector,
.montage-timeline-shell {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
}

.montage-bin,
.montage-inspector {
  padding: 0.8rem;
  min-width: 0;
}

.montage-bin-head,
.inspector-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.65rem;
  margin-bottom: 0.7rem;
}

.montage-bin h3,
.montage-inspector h3 {
  margin: 0;
  font-size: 0.96rem;
  color: #111827;
}

.montage-bin-grid {
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)) !important;
  max-height: 42vh;
  overflow: auto;
  padding-right: 0.2rem;
  margin-bottom: 0.75rem;
}

.montage-bin-grid .scene-card span {
  font-size: 0.7rem;
  padding: 0.32rem 0.4rem;
}

.montage-preview-stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto auto;
  gap: 0.55rem;
  padding: 0.8rem;
  min-width: 0;
}

.preview-frame {
  min-height: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #080b10;
  overflow: hidden;
}

body[data-stage="montage"] .preview-video {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: min(58vh, 700px);
  margin: 0;
  border-radius: 8px;
  aspect-ratio: 3 / 4;
  object-fit: contain;
}

.preview-caption {
  min-height: 1.3em;
  margin: 0;
}

.active-clip-controls {
  min-height: 180px;
}

.inspector-title strong,
.inspector-title span {
  display: block;
}

.inspector-title span {
  color: #687084;
  font-size: 0.82rem;
}

.inspector-controls {
  display: grid;
  gap: 0.7rem;
}

.inspector-controls label {
  display: grid;
  gap: 0.28rem;
  color: #687084;
  font-size: 0.76rem;
}

.inspector-controls input[type="range"],
.inspector-controls select {
  width: 100%;
}

.inspector-controls .slot-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.inspector-controls .btn-remove,
.slot-remove {
  border: 1px solid #ffd0d0;
  border-radius: 7px;
  background: #fff6f6;
  color: #b91c1c;
}

.inspector-controls .btn-remove {
  justify-self: start;
  padding: 0.45rem 0.65rem;
}

.montage-timeline-shell {
  margin-top: 0.85rem;
  padding: 0.75rem;
}

.timeline-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

body[data-stage="montage"] .montage-timeline {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.1rem 0.1rem 0.55rem;
  margin: 0;
  scroll-snap-type: x proximity;
}

body[data-stage="montage"] .montage-slot {
  position: relative;
  flex: 0 0 156px;
  scroll-snap-align: start;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 244px;
}

body[data-stage="montage"] .montage-slot.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(23, 107, 91, 0.18), 0 10px 24px rgba(23, 107, 91, 0.12);
}

body[data-stage="montage"] .montage-slot.dragging {
  opacity: 0.55;
}

body[data-stage="montage"] .montage-slot.drop-target {
  border-color: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

body[data-stage="montage"] .slot-head {
  min-height: 58px;
  padding: 0.55rem;
  gap: 0.45rem;
}

body[data-stage="montage"] .slot-head strong {
  font-size: 0.76rem;
  line-height: 1.15;
  word-break: break-word;
}

body[data-stage="montage"] .slot-head span:not(.slot-number) {
  font-size: 0.7rem;
}

body[data-stage="montage"] .slot-number {
  min-width: 1.65rem;
  height: 1.65rem;
}

body[data-stage="montage"] .slot-media {
  aspect-ratio: 9 / 12;
  min-height: 0;
}

.slot-remove {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  z-index: 3;
  width: 1.6rem;
  height: 1.6rem;
  display: grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
}

body[data-stage="montage"] .footage-panel {
  margin-top: 0.6rem;
  max-height: 18vh;
  overflow: auto;
}

body[data-stage="montage"] .footage-chip {
  width: 100%;
  justify-content: flex-start;
  margin-bottom: 0.35rem;
}

@media (min-width: 1500px) {
  .montage-editor-grid {
    grid-template-columns: minmax(180px, 220px) minmax(620px, 1fr) minmax(240px, 300px);
  }

  body[data-stage="montage"] .montage-slot {
    flex-basis: 170px;
  }
}

@media (max-width: 1180px) {
  .montage-editor-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .montage-bin,
  .montage-inspector {
    order: 2;
  }

  .montage-preview-stage {
    order: 1;
  }

  .montage-bin-grid {
    max-height: none;
  }
}

/* Montage workbench v2 */
body[data-stage="montage"] .workspace {
  padding: 0.75rem 0.9rem 1rem;
}

body[data-stage="montage"] .stage-panel.montage-editor {
  padding: 0.9rem;
  min-height: calc(100vh - 86px);
}

.montage-workbench-head {
  display: grid;
  grid-template-columns: minmax(160px, 260px) minmax(0, 1fr);
  gap: 0.9rem;
  align-items: stretch;
  margin-bottom: 0.85rem;
}

.montage-title-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
  min-width: 0;
}

.montage-title-block h2 {
  margin: 0;
}

.montage-top-panels {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 320px);
  gap: 0.75rem;
  min-width: 0;
}

.montage-settings-panel,
.montage-export-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 0.7rem;
  box-shadow: 0 6px 18px rgba(30, 34, 46, 0.04);
}

.montage-panel-title {
  margin-bottom: 0.48rem;
  color: #4b5563;
  font-size: 0.72rem;
  font-weight: 800;
}

.montage-actionbar {
  justify-content: flex-start;
  gap: 0.5rem;
}

.montage-actionbar label {
  min-width: 128px;
}

.montage-actionbar label:has(#music-select),
.montage-actionbar label:has(#footage-select) {
  flex: 1 1 170px;
}

.montage-voice,
.montage-silent {
  min-width: auto !important;
  height: 38px;
  display: flex !important;
  align-items: center;
  gap: 0.4rem !important;
  padding: 0 0.62rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcff;
}

.montage-export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.montage-export-actions .btn.primary {
  grid-column: 1 / -1;
}

.montage-export-result {
  margin-top: 0.55rem;
  min-height: 1.25rem;
  font-size: 0.82rem;
}

body[data-stage="montage"] .montage-editor-grid {
  grid-template-columns: minmax(190px, 250px) minmax(440px, 1fr) minmax(260px, 320px);
  gap: 0.85rem;
  align-items: stretch;
  min-height: min(62vh, 740px);
}

body[data-stage="montage"] .montage-bin,
body[data-stage="montage"] .montage-preview-stage,
body[data-stage="montage"] .montage-inspector,
body[data-stage="montage"] .montage-timeline-shell {
  background: #fff;
  border-color: #e2e5ee;
  box-shadow: 0 8px 24px rgba(30, 34, 46, 0.04);
}

body[data-stage="montage"] .montage-bin,
body[data-stage="montage"] .montage-inspector {
  padding: 0.85rem;
}

body[data-stage="montage"] .montage-bin-head,
body[data-stage="montage"] .inspector-title {
  align-items: flex-start;
  padding-bottom: 0.62rem;
  border-bottom: 1px solid var(--border);
}

body[data-stage="montage"] .beat-markers {
  max-width: 8.4rem;
  margin: 0;
  text-align: right;
  line-height: 1.35;
}

body[data-stage="montage"] .montage-bin-grid {
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)) !important;
  max-height: 54vh;
  gap: 0.65rem;
  padding-right: 0.1rem;
}

body[data-stage="montage"] .montage-bin-grid .scene-card {
  border-radius: 8px;
}

body[data-stage="montage"] .montage-bin-grid .scene-card span {
  min-height: 2.8rem;
  white-space: normal;
}

body[data-stage="montage"] .montage-preview-stage {
  grid-template-rows: minmax(0, 1fr) auto auto;
  padding: 0.85rem;
}

body[data-stage="montage"] .preview-frame {
  min-height: 0;
  border-radius: 8px;
}

body[data-stage="montage"] .preview-video {
  width: min(100%, 560px);
  max-height: min(64vh, 740px);
}

body[data-stage="montage"] .preview-caption {
  padding: 0.28rem 0.1rem 0;
  line-height: 1.35;
}

body[data-stage="montage"] .montage-inspector {
  position: sticky;
  top: 0.8rem;
  align-self: start;
}

.inspector-controls {
  gap: 0.65rem;
}

.inspector-group {
  display: grid;
  gap: 0.55rem;
  padding: 0.68rem;
  border: 1px solid #e7eaf2;
  border-radius: 8px;
  background: #fbfcff;
}

.inspector-group h4 {
  margin: 0;
  color: #1f2937;
  font-size: 0.8rem;
}

.inspector-group label {
  margin: 0;
}

.control-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.control-row input[type="range"] {
  grid-column: 1 / -1;
}

.range-value {
  color: #374151;
  font-size: 0.74rem;
  font-weight: 800;
}

.inspector-danger {
  background: #fffafa;
}

.inspector-danger .btn-remove {
  width: 100%;
}

body[data-stage="montage"] .montage-timeline-shell {
  margin-top: 0.85rem;
  padding: 0.82rem;
}

body[data-stage="montage"] .timeline-topline {
  margin-bottom: 0.72rem;
}

.timeline-subtitle {
  display: block;
  margin-top: 0.12rem;
  color: var(--muted);
  font-size: 0.76rem;
}

body[data-stage="montage"] .montage-timeline {
  gap: 0.7rem;
  padding-bottom: 0.62rem;
}

body[data-stage="montage"] .montage-slot {
  flex-basis: 176px;
  min-height: 260px;
  background: #fff;
}

body[data-stage="montage"] .slot-head {
  min-height: 64px;
}

body[data-stage="montage"] .slot-media {
  aspect-ratio: 9 / 13;
}

@media (min-width: 1500px) {
  body[data-stage="montage"] .montage-editor-grid {
    grid-template-columns: minmax(230px, 300px) minmax(620px, 1fr) minmax(280px, 340px);
  }

  body[data-stage="montage"] .montage-slot {
    flex-basis: 190px;
  }
}

@media (max-width: 1320px) {
  .montage-workbench-head,
  .montage-top-panels,
  body[data-stage="montage"] .montage-editor-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-stage="montage"] .montage-inspector {
    position: static;
  }

  body[data-stage="montage"] .montage-bin-grid {
    max-height: none;
    grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)) !important;
  }
}

@media (max-width: 720px) {
  .montage-export-actions {
    grid-template-columns: 1fr;
  }

  body[data-stage="montage"] .montage-slot {
    flex-basis: 150px;
  }
}

/* Montage compact layout v3 */
body[data-stage="montage"] .workspace {
  padding: 0.72rem 0.85rem 1rem;
}

body[data-stage="montage"] .stage-panel.montage-editor {
  width: min(100%, 1120px);
  max-width: 1120px;
  min-height: auto;
  margin: 0 auto;
  padding: 0.78rem;
}

body[data-stage="montage"] .montage-workbench-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.72rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

body[data-stage="montage"] .montage-title-block {
  flex: 0 0 auto;
  min-width: 108px;
}

body[data-stage="montage"] .montage-title-block h2 {
  font-size: 1.18rem;
}

body[data-stage="montage"] .montage-top-panels {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  min-width: 0;
}

body[data-stage="montage"] .montage-settings-panel,
body[data-stage="montage"] .montage-export-panel {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

body[data-stage="montage"] .montage-settings-panel {
  flex: 1 1 auto;
  min-width: 0;
}

body[data-stage="montage"] .montage-export-panel {
  flex: 0 0 auto;
  min-width: 0;
}

body[data-stage="montage"] .montage-panel-title {
  display: none;
}

body[data-stage="montage"] .montage-actionbar,
body[data-stage="montage"] .montage-export-actions {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  flex-wrap: wrap;
}

body[data-stage="montage"] .montage-actionbar {
  justify-content: flex-start;
}

body[data-stage="montage"] .montage-actionbar label {
  min-width: 0;
}

body[data-stage="montage"] .montage-actionbar label:has(#music-select),
body[data-stage="montage"] .montage-actionbar label:has(#footage-select) {
  flex: 0 1 158px;
}

body[data-stage="montage"] .montage-actionbar select {
  min-height: 2rem;
  padding: 0.42rem 0.55rem;
}

body[data-stage="montage"] .montage-voice,
body[data-stage="montage"] .montage-silent {
  height: 34px;
  padding: 0 0.5rem;
  background: #fff;
}

body[data-stage="montage"] .montage-actionbar .btn,
body[data-stage="montage"] .montage-export-actions .btn {
  min-height: 2rem;
  padding: 0.42rem 0.7rem;
}

body[data-stage="montage"] .montage-export-actions {
  display: flex;
  justify-content: flex-end;
}

body[data-stage="montage"] .montage-export-actions .btn.primary {
  grid-column: auto;
  min-width: 128px;
}

body[data-stage="montage"] #btn-next-articula.hidden {
  display: none;
}

body[data-stage="montage"] .montage-export-result {
  flex-basis: 100%;
  margin: 0.18rem 0 0;
  min-height: 0;
  text-align: right;
  font-size: 0.78rem;
}

body[data-stage="montage"] .montage-editor-grid {
  display: grid;
  grid-template-columns: 184px minmax(360px, 500px) 252px;
  justify-content: center;
  align-items: start;
  gap: 0.72rem;
  min-height: auto;
}

body[data-stage="montage"] .montage-bin,
body[data-stage="montage"] .montage-preview-stage,
body[data-stage="montage"] .montage-inspector,
body[data-stage="montage"] .montage-timeline-shell {
  border-radius: 8px;
  background: #fff;
}

body[data-stage="montage"] .montage-bin,
body[data-stage="montage"] .montage-inspector {
  padding: 0.68rem;
}

body[data-stage="montage"] .montage-bin h3,
body[data-stage="montage"] .montage-inspector h3 {
  font-size: 0.9rem;
}

body[data-stage="montage"] .montage-bin-head,
body[data-stage="montage"] .inspector-title {
  margin-bottom: 0.55rem;
  padding-bottom: 0.48rem;
}

body[data-stage="montage"] .beat-markers {
  display: none;
}

body[data-stage="montage"] .montage-bin-grid {
  grid-template-columns: 1fr !important;
  max-height: 430px;
  gap: 0.52rem;
  margin-bottom: 0.52rem;
}

body[data-stage="montage"] .montage-bin-grid .lazy-video-frame {
  aspect-ratio: 9 / 8.8;
}

body[data-stage="montage"] .montage-bin-grid .scene-card span {
  min-height: auto;
  padding: 0.28rem 0.42rem;
  font-size: 0.68rem;
  line-height: 1.2;
}

body[data-stage="montage"] .footage-panel {
  max-height: 112px;
}

body[data-stage="montage"] .montage-preview-stage {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 0.45rem;
  padding: 0.65rem;
}

body[data-stage="montage"] .preview-frame {
  width: 100%;
  min-height: 0;
  padding: 0;
}

body[data-stage="montage"] .preview-video {
  width: min(100%, 430px);
  max-height: min(56vh, 570px);
  aspect-ratio: 3 / 4;
}

body[data-stage="montage"] .preview-caption {
  font-size: 0.78rem;
}

body[data-stage="montage"] .montage-inspector {
  position: sticky;
  top: 0.7rem;
}

body[data-stage="montage"] .active-clip-controls {
  min-height: 0;
}

body[data-stage="montage"] .inspector-title strong {
  font-size: 0.86rem;
  line-height: 1.25;
}

body[data-stage="montage"] .inspector-title span {
  font-size: 0.76rem;
}

body[data-stage="montage"] .inspector-controls {
  gap: 0.48rem;
}

body[data-stage="montage"] .inspector-group {
  gap: 0.42rem;
  padding: 0.55rem;
}

body[data-stage="montage"] .inspector-group h4 {
  font-size: 0.74rem;
}

body[data-stage="montage"] .inspector-group label {
  font-size: 0.72rem;
}

body[data-stage="montage"] .montage-timeline-shell {
  margin-top: 0.72rem;
  padding: 0.65rem;
}

body[data-stage="montage"] .timeline-topline {
  margin-bottom: 0.55rem;
}

body[data-stage="montage"] .montage-timeline {
  gap: 0.5rem;
  padding-bottom: 0.45rem;
}

body[data-stage="montage"] .montage-slot {
  flex-basis: 136px;
  min-height: 198px;
}

body[data-stage="montage"] .slot-head {
  min-height: 50px;
  padding: 0.45rem;
}

body[data-stage="montage"] .slot-head strong {
  font-size: 0.68rem;
}

body[data-stage="montage"] .slot-head span:not(.slot-number) {
  font-size: 0.64rem;
}

body[data-stage="montage"] .slot-number {
  min-width: 1.38rem;
  height: 1.38rem;
  font-size: 0.72rem;
}

body[data-stage="montage"] .slot-media {
  aspect-ratio: 9 / 10.5;
}

body[data-stage="montage"] .slot-remove {
  width: 1.42rem;
  height: 1.42rem;
}

@media (min-width: 1500px) {
  body[data-stage="montage"] .stage-panel.montage-editor {
    max-width: 1160px;
  }

  body[data-stage="montage"] .montage-editor-grid {
    grid-template-columns: 196px minmax(390px, 520px) 264px;
  }

  body[data-stage="montage"] .preview-video {
    width: min(100%, 450px);
  }
}

@media (max-width: 1180px) {
  body[data-stage="montage"] .montage-workbench-head,
  body[data-stage="montage"] .montage-top-panels {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-stage="montage"] .montage-editor-grid {
    grid-template-columns: minmax(160px, 210px) minmax(340px, 1fr);
  }

  body[data-stage="montage"] .montage-inspector {
    grid-column: 1 / -1;
    position: static;
  }
}

@media (max-width: 820px) {
  body[data-stage="montage"] .montage-editor-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-stage="montage"] .montage-bin-grid {
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)) !important;
  }

  body[data-stage="montage"] .montage-export-actions {
    justify-content: flex-start;
  }
}

/* Montage storyboard layout v4 */
body[data-stage="montage"] .stage-panel.montage-editor {
  width: min(100%, 980px);
  max-width: 980px;
  padding: 0.78rem;
}

body[data-stage="montage"] .montage-workbench-head {
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

body[data-stage="montage"] .montage-title-block {
  min-width: 92px;
}

body[data-stage="montage"] .montage-top-panels {
  gap: 0.5rem;
}

body[data-stage="montage"] .montage-actionbar label:has(#music-select),
body[data-stage="montage"] .montage-actionbar label:has(#footage-select) {
  flex-basis: 146px;
}

body[data-stage="montage"] .montage-editor-grid {
  grid-template-columns: minmax(360px, 1fr) 272px;
  justify-content: center;
  gap: 0.72rem;
}

body[data-stage="montage"] .montage-preview-stage {
  min-width: 0;
}

body[data-stage="montage"] .preview-video {
  width: min(100%, 420px);
  max-height: min(54vh, 560px);
}

body[data-stage="montage"] .montage-inspector {
  align-self: stretch;
}

body[data-stage="montage"] .montage-timeline-shell {
  margin-top: 0.72rem;
  border-color: rgba(23, 107, 91, 0.22);
  background: #f2f7f6;
}

body[data-stage="montage"] .timeline-topline strong {
  font-size: 0.92rem;
}

body[data-stage="montage"] .montage-timeline {
  padding: 0.05rem 0.05rem 0.48rem;
}

body[data-stage="montage"] .montage-slot {
  flex-basis: 126px;
  min-height: 172px;
  border-color: #e7e0f3;
}

body[data-stage="montage"] .montage-slot.active {
  box-shadow: 0 0 0 2px rgba(23, 107, 91, 0.2), 0 8px 18px rgba(23, 107, 91, 0.12);
}

body[data-stage="montage"] .slot-head {
  min-height: 44px;
  padding: 0.38rem;
}

body[data-stage="montage"] .slot-media {
  aspect-ratio: 9 / 9.6;
}

body[data-stage="montage"] .slot-head strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

body[data-stage="montage"] .montage-bin {
  margin-top: 0.72rem;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(30, 34, 46, 0.04);
}

body[data-stage="montage"] .montage-bin-head {
  margin-bottom: 0.55rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}

body[data-stage="montage"] .montage-bin h3 {
  font-size: 0.88rem;
}

body[data-stage="montage"] .montage-bin-grid {
  display: flex !important;
  grid-template-columns: none !important;
  gap: 0.5rem;
  max-height: none;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.02rem 0.02rem 0.45rem;
  margin: 0;
}

body[data-stage="montage"] .montage-bin-grid .scene-card {
  flex: 0 0 118px;
}

body[data-stage="montage"] .montage-bin-grid .lazy-video-frame {
  aspect-ratio: 9 / 9;
}

body[data-stage="montage"] .montage-bin-grid .scene-card span {
  min-height: 2.1rem;
  font-size: 0.64rem;
}

body[data-stage="montage"] .footage-panel {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.45rem;
  max-height: none;
  overflow-x: auto;
  margin: 0.5rem 0 0;
}

body[data-stage="montage"] .footage-chip {
  width: auto;
  white-space: nowrap;
  margin-bottom: 0;
}

@media (min-width: 1500px) {
  body[data-stage="montage"] .stage-panel.montage-editor {
    max-width: 1020px;
  }

  body[data-stage="montage"] .montage-editor-grid {
    grid-template-columns: minmax(390px, 1fr) 286px;
  }
}

@media (max-width: 1080px) {
  body[data-stage="montage"] .stage-panel.montage-editor {
    max-width: 100%;
  }

  body[data-stage="montage"] .montage-editor-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-stage="montage"] .montage-inspector {
    position: static;
  }
}

/* Montage selected clip panel v5 */
body[data-stage="montage"] .stage-panel.montage-editor {
  width: min(100%, 920px);
  max-width: 920px;
}

body[data-stage="montage"] .montage-editor-grid {
  grid-template-columns: minmax(0, 1fr);
  gap: 0.58rem;
  width: min(100%, 580px);
  margin: 0 auto;
}

body[data-stage="montage"] .montage-preview-stage {
  width: 100%;
}

body[data-stage="montage"] .preview-video {
  width: min(100%, 460px);
  max-height: min(54vh, 560px);
}

body[data-stage="montage"] .montage-inspector {
  position: static;
  align-self: auto;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

body[data-stage="montage"] .montage-inspector > h3 {
  display: none;
}

body[data-stage="montage"] .active-clip-controls {
  width: 100%;
}

body[data-stage="montage"] .clip-control-card {
  display: grid;
  gap: 0.62rem;
  padding: 0.68rem;
  border: 1px solid #dfe6f0;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(20, 28, 42, 0.06);
}

body[data-stage="montage"] .clip-control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.72rem;
  padding-bottom: 0.56rem;
  border-bottom: 1px solid #edf1f7;
}

body[data-stage="montage"] .clip-control-main {
  display: grid;
  gap: 0.12rem;
  min-width: 0;
}

body[data-stage="montage"] .clip-control-main strong {
  font-size: 1rem;
  color: #111827;
}

body[data-stage="montage"] .clip-control-main span {
  color: #5d6b82;
  font-size: 0.76rem;
}

body[data-stage="montage"] .clip-kicker {
  color: #1f7a5a !important;
  font-size: 0.68rem !important;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

body[data-stage="montage"] .clip-source-name {
  overflow: hidden;
  max-width: 100%;
  color: #7b8495 !important;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-stage="montage"] .clip-nav {
  display: flex;
  flex: 0 0 auto;
  gap: 0.36rem;
}

body[data-stage="montage"] .clip-nav .btn {
  min-height: 2rem;
  padding: 0.38rem 0.58rem;
  white-space: nowrap;
}

body[data-stage="montage"] .clip-control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.85fr);
  gap: 0.5rem;
}

body[data-stage="montage"] .clip-control-grid .inspector-group {
  min-width: 0;
  padding: 0.55rem;
}

body[data-stage="montage"] .clip-trim-group {
  grid-row: span 2;
}

body[data-stage="montage"] .clip-control-grid .inspector-danger {
  grid-column: 1 / -1;
}

body[data-stage="montage"] .clip-control-grid .inspector-group h4 {
  font-size: 0.76rem;
}

body[data-stage="montage"] .clip-control-grid .inspector-group label {
  font-size: 0.72rem;
}

body[data-stage="montage"] .clip-control-grid select {
  min-height: 2.15rem;
}

body[data-stage="montage"] .clip-control-grid .btn-remove {
  width: 100%;
  white-space: normal;
}

@media (max-width: 720px) {
  body[data-stage="montage"] .montage-editor-grid {
    width: 100%;
  }

  body[data-stage="montage"] .clip-control-head {
    align-items: stretch;
    flex-direction: column;
  }

  body[data-stage="montage"] .clip-nav {
    width: 100%;
  }

  body[data-stage="montage"] .clip-nav .btn {
    flex: 1 1 0;
  }

  body[data-stage="montage"] .clip-control-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-stage="montage"] .clip-trim-group {
    grid-row: auto;
  }
}

/* Montage desk layout and reorder handle v6 */
body[data-stage="montage"] .stage-panel.montage-editor {
  width: min(100%, 1180px);
  max-width: 1180px;
  padding: 0.75rem;
}

body[data-stage="montage"] .montage-workbench-head {
  display: grid;
  gap: 0.58rem;
  margin: 0 0 0.75rem;
  padding-bottom: 0.72rem;
  border-bottom: 1px solid var(--border);
}

body[data-stage="montage"] .montage-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

body[data-stage="montage"] .montage-title-block {
  min-width: 0;
}

body[data-stage="montage"] .montage-title-block h2 {
  margin: 0;
  font-size: 1.22rem;
}

body[data-stage="montage"] #voice-status {
  display: block;
  margin-top: 0.25rem;
}

body[data-stage="montage"] .montage-export-panel {
  display: flex;
  flex: 0 1 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  min-width: 0;
}

body[data-stage="montage"] .montage-export-panel .btn {
  min-height: 2.2rem;
  padding: 0.48rem 0.78rem;
  white-space: nowrap;
}

body[data-stage="montage"] .montage-export-panel .btn.primary {
  min-width: 150px;
}

body[data-stage="montage"] .btn.secondary.subtle {
  color: #4b5563;
  background: #fffdf8;
}

body[data-stage="montage"] .montage-settings-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.48rem;
  min-width: 0;
  padding: 0.62rem;
  border: 1px solid #eadfce;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: none;
}

body[data-stage="montage"] .montage-settings-panel label {
  display: grid;
  gap: 0.22rem;
  min-width: 0;
  color: #687084;
  font-size: 0.76rem;
}

body[data-stage="montage"] .montage-settings-panel label:has(#music-select) {
  flex: 1 1 220px;
}

body[data-stage="montage"] .montage-settings-panel label:has(#footage-select) {
  flex: 1 1 170px;
}

body[data-stage="montage"] .montage-settings-panel select {
  min-height: 2.1rem;
}

body[data-stage="montage"] .montage-settings-panel .btn,
body[data-stage="montage"] .montage-settings-panel .montage-silent,
body[data-stage="montage"] .montage-settings-panel .montage-voice {
  flex: 0 0 auto;
  min-height: 2.1rem;
}

body[data-stage="montage"] .montage-settings-panel .montage-silent,
body[data-stage="montage"] .montage-settings-panel .montage-voice {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  white-space: nowrap;
}

body[data-stage="montage"] .montage-export-result {
  flex: 1 1 100%;
  align-self: center;
  min-height: 0;
  margin: 0;
  text-align: right;
}

body[data-stage="montage"] .montage-desk {
  display: grid;
  grid-template-columns: minmax(420px, 540px) minmax(360px, 1fr);
  gap: 0.85rem;
  align-items: start;
}

body[data-stage="montage"] .montage-left,
body[data-stage="montage"] .montage-right {
  display: grid;
  gap: 0.65rem;
  min-width: 0;
}

body[data-stage="montage"] .montage-preview-stage {
  width: 100%;
  padding: 0.68rem;
}

body[data-stage="montage"] .preview-video {
  width: min(100%, 430px);
  max-height: min(58vh, 580px);
}

body[data-stage="montage"] .montage-inspector {
  display: none;
}

body[data-stage="montage"] .montage-timeline-shell {
  margin: 0;
  padding: 0.62rem;
  border-color: rgba(23, 107, 91, 0.2);
  background: #f2f7f6;
}

body[data-stage="montage"] .timeline-topline {
  margin-bottom: 0.5rem;
}

body[data-stage="montage"] .montage-timeline {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.45rem;
  max-height: min(47vh, 520px);
  overflow: auto;
  padding: 0.05rem;
  margin: 0;
  scroll-snap-type: none;
}

body[data-stage="montage"] .montage-slot {
  position: relative;
  display: grid;
  grid-template-columns: 2rem 76px minmax(0, 1fr) 1.9rem;
  grid-template-areas: "handle media head remove";
  align-items: stretch;
  gap: 0.45rem;
  min-height: 86px;
  padding: 0.42rem;
  overflow: visible;
  cursor: pointer;
}

body[data-stage="montage"] .slot-drag-handle {
  grid-area: handle;
  display: grid;
  place-items: center;
  min-height: 100%;
  border: 1px dashed #c8b8df;
  border-radius: 7px;
  color: #7c3aed;
  background: #f2f7f6;
  cursor: grab;
  font-weight: 900;
  touch-action: none;
  user-select: none;
}

body[data-stage="montage"] .slot-drag-handle:focus-visible {
  outline: 2px solid rgba(23, 107, 91, 0.35);
  outline-offset: 2px;
}

body.montage-reordering,
body.montage-reordering * {
  cursor: grabbing !important;
}

body[data-stage="montage"] .montage-slot.dragging {
  opacity: 0.65;
  transform: scale(0.99);
}

body[data-stage="montage"] .montage-slot.drop-target {
  border-color: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.22);
}

body[data-stage="montage"] .slot-head {
  grid-area: head;
  display: flex;
  align-items: center;
  min-height: 0;
  padding: 0.1rem 0.15rem;
  gap: 0.5rem;
}

body[data-stage="montage"] .slot-head strong {
  max-width: 100%;
  font-size: 0.78rem;
  line-height: 1.18;
  word-break: normal;
}

body[data-stage="montage"] .slot-head span:not(.slot-number) {
  font-size: 0.7rem;
}

body[data-stage="montage"] .slot-number {
  flex: 0 0 auto;
  min-width: 1.55rem;
  height: 1.55rem;
}

body[data-stage="montage"] .slot-media {
  grid-area: media;
  align-self: center;
  width: 76px;
  aspect-ratio: 1 / 1;
  border-radius: 7px;
  overflow: hidden;
}

body[data-stage="montage"] .slot-remove {
  grid-area: remove;
  position: static;
  align-self: center;
  justify-self: center;
  width: 1.55rem;
  height: 1.55rem;
}

body[data-stage="montage"] .montage-bin {
  margin: 0;
  padding: 0.62rem;
}

body[data-stage="montage"] .montage-bin-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)) !important;
  gap: 0.45rem;
  max-height: min(35vh, 360px);
  overflow: auto;
  padding: 0.02rem;
}

body[data-stage="montage"] .montage-bin-grid .scene-card {
  flex: none;
  cursor: grab;
}

body[data-stage="montage"] .footage-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
  max-height: none;
  overflow: visible;
}

body[data-stage="montage"] .footage-chip {
  width: auto;
  margin: 0;
  white-space: nowrap;
}

@media (max-width: 1120px) {
  body[data-stage="montage"] .montage-head-row {
    align-items: stretch;
    flex-direction: column;
  }

  body[data-stage="montage"] .montage-export-panel {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  body[data-stage="montage"] .montage-settings-panel {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  body[data-stage="montage"] .montage-export-result {
    grid-column: 1 / -1;
    text-align: left;
  }

  body[data-stage="montage"] .montage-desk {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-stage="montage"] .montage-timeline {
    max-height: none;
  }
}

@media (min-width: 901px) and (max-width: 1120px) {
  body[data-stage="montage"] .montage-head-row {
    align-items: flex-start;
    flex-direction: row;
  }

  body[data-stage="montage"] .montage-export-panel {
    justify-content: flex-end;
  }

  body[data-stage="montage"] .montage-desk {
    grid-template-columns: minmax(400px, 1.15fr) minmax(330px, 0.85fr);
  }

  body[data-stage="montage"] .montage-timeline {
    max-height: min(54vh, 560px);
  }
}

@media (max-width: 640px) {
  body[data-stage="montage"] .stage-panel.montage-editor {
    padding: 0.55rem;
  }

  body[data-stage="montage"] .montage-settings-panel,
  body[data-stage="montage"] .montage-export-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-stage="montage"] .montage-export-panel .btn,
  body[data-stage="montage"] .montage-settings-panel .btn {
    width: 100%;
  }

  body[data-stage="montage"] .montage-slot {
    grid-template-columns: 1.85rem 64px minmax(0, 1fr) 1.7rem;
  }

  body[data-stage="montage"] .slot-media {
    width: 64px;
  }
}


.operator-panel { max-width: 1440px; }
.operator-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.operator-head-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.operator-summary {
  display: flex; justify-content: space-between; gap: 1rem; align-items: center;
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: .85rem; margin-bottom: 1rem;
}
.operator-summary-title h3 { margin-top: .15rem; }
.operator-metrics { display: flex; flex-wrap: wrap; gap: .45rem; justify-content: flex-end; }
.operator-metrics span, .operator-product-footer span {
  border: 1px solid var(--border); background: var(--surface2); border-radius: 999px; padding: .22rem .55rem; font-size: .78rem; color: var(--muted);
}
.operator-product { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
.operator-product.master { border-color: var(--accent); }
.operator-product-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: .9rem; }
.operator-product-head h3 { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.operator-product-head h3 span { color: var(--muted); font-size: .9rem; font-weight: 500; }
.operator-product-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.operator-role { display: inline-flex; align-items: center; justify-content: center; min-width: 1.6rem; height: 1.35rem; padding: 0 .4rem; border-radius: 999px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; border: 1px solid var(--border); color: var(--muted); }
.operator-role.master { color: #111827; background: var(--accent); border-color: var(--accent); }
.operator-role.slave { color: var(--ok); border-color: color-mix(in srgb, var(--ok), transparent 35%); }
.operator-source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.operator-source-photo { min-height: 180px; }
.operator-product-footer { display: flex; gap: .45rem; flex-wrap: wrap; margin-top: .85rem; }
.operator-member-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .55rem; }
.operator-member { display: grid; grid-template-columns: auto 1fr; gap: .25rem .5rem; align-items: center; text-align: left; padding: .65rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; }
.operator-member:hover, .operator-member.active { border-color: var(--accent); background: var(--surface2); }
.operator-member span:not(.operator-role), .operator-member small { grid-column: 2; color: var(--muted); }
.operator-category-grid { margin-top: 1rem; }


/* Operator no-hidden responsive layout v1 */
html,
body {
  max-width: 100%;
}

.topbar {
  flex-wrap: wrap;
  min-width: 0;
}

.brand {
  flex: 0 1 auto;
  min-width: 0;
}

.topbar-actions {
  flex: 1 1 520px;
  min-width: 0;
  justify-content: flex-end;
}

.topbar-actions .btn,
.gen-status {
  flex: 0 1 auto;
  max-width: 100%;
  white-space: normal;
}

.layout,
.layout-stages,
.workspace,
.stage-panel {
  min-width: 0;
}

.workspace {
  overflow-x: visible;
}

.stage-panel {
  width: 100%;
}

body[data-stage="operator"] .workspace {
  padding-inline: clamp(0.65rem, 1.2vw, 1.25rem);
}

body[data-stage="operator"] .operator-panel {
  width: 100%;
  max-width: none;
  min-width: 0;
}

body[data-stage="operator"] .operator-head,
body[data-stage="operator"] .operator-product-head,
body[data-stage="operator"] .operator-summary {
  flex-wrap: wrap;
  min-width: 0;
}

body[data-stage="operator"] .operator-head > div:first-child,
body[data-stage="operator"] .operator-product-head > div:first-child,
body[data-stage="operator"] .operator-summary-title {
  flex: 1 1 320px;
  min-width: 0;
}

body[data-stage="operator"] .operator-head-actions,
body[data-stage="operator"] .operator-product-actions {
  flex: 1 1 300px;
  min-width: 0;
  justify-content: flex-end;
}

body[data-stage="operator"] .operator-head-actions .btn,
body[data-stage="operator"] .operator-product-actions .btn {
  flex: 0 1 auto;
  max-width: 100%;
  white-space: normal;
}

body[data-stage="operator"] .operator-metrics {
  flex: 1 1 420px;
  min-width: 0;
}

body[data-stage="operator"] .operator-source-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 170px));
  justify-content: start;
}

body[data-stage="operator"] .operator-member-list,
body[data-stage="operator"] .operator-category-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr));
  min-width: 0;
}

body[data-stage="operator"] .operator-member,
body[data-stage="operator"] .category-card,
body[data-stage="operator"] .operator-product {
  min-width: 0;
  max-width: 100%;
}

body[data-stage="operator"] .operator-member strong,
body[data-stage="operator"] .operator-member span,
body[data-stage="operator"] .operator-member small,
body[data-stage="operator"] .category-card strong,
body[data-stage="operator"] .operator-product-head h3,
body[data-stage="operator"] .operator-product-head h3 span {
  overflow-wrap: anywhere;
}

@media (max-width: 1280px) {
  .topbar-actions {
    justify-content: flex-start;
  }

  body[data-stage="operator"] .operator-head-actions,
  body[data-stage="operator"] .operator-product-actions,
  body[data-stage="operator"] .operator-metrics {
    justify-content: flex-start;
  }
}

@media (max-width: 1180px) {
  body[data-stage="operator"] .operator-head-actions .btn {
    flex: 1 1 220px;
  }

  body[data-stage="operator"] .operator-product-actions .btn {
    flex: 1 1 180px;
  }
}

@media (max-width: 980px) {
  body[data-stage="operator"] .operator-head,
  body[data-stage="operator"] .operator-product-head,
  body[data-stage="operator"] .operator-summary {
    display: flex;
    align-items: stretch;
    flex-direction: column;
  }

  body[data-stage="operator"] .operator-head-actions,
  body[data-stage="operator"] .operator-product-actions,
  body[data-stage="operator"] .operator-metrics {
    flex-basis: auto;
    width: 100%;
  }
}


/* Operator recommendation and visible progress v1 */
body[data-stage="operator"] .operator-recommendation,
body[data-stage="operator"] .operator-progress {
  margin-bottom: 0.85rem;
}

body[data-stage="operator"] .operator-guide,
body[data-stage="operator"] .operator-progress-board {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 1rem;
  min-width: 0;
  padding: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(21, 32, 39, 0.06);
}

body[data-stage="operator"] .operator-guide {
  border-left: 5px solid var(--accent);
}

body[data-stage="operator"] .operator-guide.start { border-left-color: #0f8a71; }
body[data-stage="operator"] .operator-guide.next { border-left-color: #2f7d95; }
body[data-stage="operator"] .operator-guide.run { border-left-color: #b76e00; }
body[data-stage="operator"] .operator-guide.done { border-left-color: var(--ok); }
body[data-stage="operator"] .operator-guide.wait { border-left-color: var(--muted); }

body[data-stage="operator"] .operator-guide-main,
body[data-stage="operator"] .operator-progress-head {
  min-width: 0;
}

body[data-stage="operator"] .operator-guide-main {
  flex: 1 1 420px;
}

body[data-stage="operator"] .operator-guide-kicker {
  display: inline-flex;
  margin-bottom: 0.25rem;
  color: #176b5b;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

body[data-stage="operator"] .operator-guide h3 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.22;
}

body[data-stage="operator"] .operator-guide p {
  max-width: 62rem;
  margin-top: 0.35rem;
  color: var(--muted);
  line-height: 1.42;
}

body[data-stage="operator"] .operator-guide-actions {
  display: flex;
  flex: 0 1 300px;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  min-width: 0;
  flex-wrap: wrap;
}

body[data-stage="operator"] .operator-guide-target {
  max-width: 100%;
  padding: 0.28rem 0.55rem;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 55%);
  border-radius: 999px;
  color: #176b5b;
  font-weight: 800;
  font-size: 0.78rem;
  background: #f2f7f6;
}

body[data-stage="operator"] .operator-progress-board {
  display: grid;
  gap: 0.75rem;
  background: #f7f9fa;
}

body[data-stage="operator"] .operator-progress-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

body[data-stage="operator"] .operator-progress-head strong {
  color: var(--text);
}

body[data-stage="operator"] .operator-step-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 0.5rem;
  min-width: 0;
}

body[data-stage="operator"] .operator-step,
body[data-stage="operator"] .operator-progress-step {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
  padding: 0.55rem 0.62rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.78rem;
}

body[data-stage="operator"] .operator-progress-step span,
body[data-stage="operator"] .operator-step span {
  font-weight: 800;
}

body[data-stage="operator"] .operator-progress-step strong {
  color: var(--text);
  font-size: 0.86rem;
}

body[data-stage="operator"] .operator-step.done,
body[data-stage="operator"] .operator-progress-step.done {
  border-color: rgba(22, 132, 86, 0.35);
  background: #e9f7ef;
  color: #126b45;
}

body[data-stage="operator"] .operator-step.current,
body[data-stage="operator"] .operator-progress-step.current {
  border-color: rgba(183, 110, 0, 0.45);
  background: #fff7e8;
  color: #8a5200;
  box-shadow: inset 0 0 0 1px rgba(183, 110, 0, 0.14);
}

body[data-stage="operator"] .operator-members-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.2rem 0 0.55rem;
  flex-wrap: wrap;
}

body[data-stage="operator"] .operator-member {
  grid-template-columns: auto minmax(0, 1fr);
  align-content: start;
  gap: 0.28rem 0.55rem;
}

body[data-stage="operator"] .operator-member.ready {
  border-color: rgba(22, 132, 86, 0.36);
}

body[data-stage="operator"] .operator-member-action {
  font-weight: 700;
}

body[data-stage="operator"] .operator-member small {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-stage="operator"] .operator-member-chips {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  gap: 0.28rem;
  margin-top: 0.28rem;
}

body[data-stage="operator"] .operator-done-chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.45rem;
  padding: 0.12rem 0.42rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
}

body[data-stage="operator"] .operator-done-chip.ok {
  color: #126b45;
  border-color: rgba(22, 132, 86, 0.35);
  background: #e9f7ef;
}

body[data-stage="operator"] .operator-done-chip.todo {
  color: #6b7280;
  background: #f4f7f8;
}

@media (max-width: 980px) {
  body[data-stage="operator"] .operator-guide {
    display: grid;
  }

  body[data-stage="operator"] .operator-guide-actions {
    justify-content: flex-start;
  }

  body[data-stage="operator"] .operator-guide-actions .btn {
    width: 100%;
  }
}
