:root {
  color-scheme: dark;
  --bg: #090b0e;
  --panel: #12161b;
  --panel-soft: #171d23;
  --panel-raised: #1d242b;
  --text: #f3f5f2;
  --muted: #96a2ad;
  --border: #29323a;
  --border-soft: rgba(255, 255, 255, 0.07);
  --accent: #34d399;
  --accent-strong: #7dd3fc;
  --accent-soft: rgba(52, 211, 153, 0.13);
  --amber: #f0bd62;
  --danger: #fb806c;
  --warning: #f0bd62;
  --success: #6ee7a8;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  width: min(1680px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 4px 0 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(23px, 2.4vw, 32px);
  line-height: 1.05;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.3;
}

.topbar-actions,
.panel-header,
.action-row,
.upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.44fr) minmax(680px, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03), var(--shadow);
}

.generator-panel,
.status-panel,
.plan-panel {
  padding: 16px;
}

.generator-panel {
  position: sticky;
  top: 14px;
}

.plan-panel {
  margin-top: 16px;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-header p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.generator-form {
  display: grid;
  gap: 12px;
}

.generator-form .action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.advanced-panel {
  display: grid;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.advanced-panel summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 850;
}

.advanced-panel[open] summary {
  margin-bottom: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.compact-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
}

.field-wide {
  grid-column: 1 / -1;
}

.field span,
.reference-meta label {
  color: #d7dde1;
  font-size: 12px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0d1115;
  color: var(--text);
  outline: none;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    background 0.16s ease;
}

input::placeholder,
textarea::placeholder {
  color: #6d7780;
}

input,
select {
  min-height: 40px;
  padding: 0 12px;
}

textarea {
  min-height: 80px;
  padding: 11px 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(125, 211, 252, 0.8);
  background: #10161b;
  box-shadow: 0 0 0 3px rgba(125, 211, 252, 0.12);
}

.upload-row {
  align-items: stretch;
}

.upload-card {
  position: relative;
  display: grid;
  gap: 6px;
  flex: 1;
  min-height: 78px;
  padding: 13px;
  border: 1px dashed #40505b;
  border-radius: 8px;
  background: var(--panel-soft);
  transition:
    border-color 0.16s ease,
    background 0.16s ease;
}

.upload-card input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.upload-card:hover {
  border-color: rgba(125, 211, 252, 0.64);
  background: #1a2229;
}

.upload-title {
  font-size: 14px;
  font-weight: 800;
}

.upload-caption {
  color: var(--muted);
  font-size: 12px;
}

.reference-list {
  display: grid;
  gap: 10px;
}

.reference-item {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #151b21;
}

.reference-thumb {
  width: 72px;
  height: 72px;
  border-radius: 7px;
  object-fit: cover;
  background: var(--panel-soft);
}

.reference-meta {
  display: grid;
  gap: 8px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  background: #f3f5f2;
  color: #0c1115;
}

.primary-button:hover {
  background: #ffffff;
}

.secondary-button {
  background: var(--accent);
  color: #061813;
}

.secondary-button:hover {
  background: #6ee7b7;
}

.ghost-button {
  background: #10151a;
  border-color: var(--border);
  color: var(--text);
}

.ghost-button:hover {
  border-color: rgba(45, 212, 191, 0.66);
  background: #1b2227;
}

.danger-button {
  min-width: 40px;
  padding: 0 11px;
  background: rgba(251, 138, 103, 0.12);
  border-color: rgba(251, 138, 103, 0.34);
  color: var(--danger);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.status-idle {
  background: #252b31;
  color: #c0c8cf;
}

.status-ok,
.status-succeeded {
  background: rgba(110, 231, 168, 0.14);
  color: var(--success);
}

.status-processing,
.status-queued {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-failed {
  background: rgba(251, 138, 103, 0.14);
  color: var(--danger);
}

.status-warning {
  background: rgba(245, 198, 107, 0.14);
  color: var(--warning);
}

.status-skipped,
.status-dry_run,
.status-prompt_preview,
.status-plan_only {
  background: rgba(170, 178, 186, 0.14);
  color: #d7dde1;
}

.active-job {
  display: grid;
  gap: 10px;
  min-height: 106px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #10151a;
}

.job-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.job-title-row strong {
  overflow-wrap: anywhere;
}

.job-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}

.metric {
  padding: 9px;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.025);
}

.metric span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric b {
  font-size: 14px;
}

.progress-shell {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #2d353d;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.2s ease;
}

.production-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.82fr) minmax(330px, 1fr);
  gap: 14px;
  align-items: start;
}

.production-main {
  display: grid;
  gap: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
}

.video-preview {
  display: grid;
  place-items: center;
  min-height: 590px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #050708;
  color: rgba(255, 255, 255, 0.72);
}

.video-preview video {
  width: min(100%, 350px);
  max-height: 680px;
  aspect-ratio: 9 / 16;
  border-radius: 8px;
  background: #000;
}

.pipeline-flow {
  display: grid;
  gap: 10px;
  max-height: 720px;
  margin: 0;
  overflow: auto;
  padding-right: 2px;
}

.pipeline-step {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #10151a;
}

.pipeline-step > summary {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 52px;
  padding: 10px 11px;
  cursor: pointer;
}

.pipeline-number {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(125, 211, 252, 0.38);
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 900;
}

.pipeline-body {
  display: grid;
  gap: 11px;
  border-top: 1px solid var(--border);
  padding: 11px;
}

.pipeline-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

.pipeline-meta-item {
  padding: 9px;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.025);
}

.pipeline-meta-item span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.pipeline-meta-item b {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.pipeline-media-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 9px;
}

.pipeline-media-card {
  display: grid;
  gap: 7px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #151b21;
  padding: 8px;
  color: var(--text);
  text-decoration: none;
}

.pipeline-media-card img,
.pipeline-media-card video {
  width: 100%;
  aspect-ratio: 9 / 12;
  border-radius: 7px;
  background: #080a0c;
  object-fit: cover;
}

.pipeline-media-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.prompt-card-list {
  display: grid;
  gap: 8px;
}

.prompt-card,
.pipeline-json {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111519;
}

.prompt-card > summary {
  cursor: pointer;
  padding: 10px 11px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 850;
}

.prompt-card pre,
.pipeline-json {
  max-height: 360px;
  margin: 0;
  overflow: auto;
  border-top: 1px solid var(--border);
  padding: 11px;
  color: #dce6eb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.pipeline-json {
  border-top: 1px solid var(--border);
}

.split-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.drawer-panel {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.drawer-panel summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 850;
}

.drawer-panel[open] summary {
  margin-bottom: 10px;
}

.artifact-list,
.job-list {
  display: grid;
  gap: 8px;
}

.artifact-item,
.job-item,
.scene-item,
.retention-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #151b21;
}

.artifact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
}

.artifact-item a {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.job-item {
  display: grid;
  gap: 7px;
  padding: 10px;
  text-align: left;
}

.job-item button {
  display: grid;
  gap: 5px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.job-item small,
.artifact-item small,
.plan-muted {
  color: var(--muted);
  font-size: 12px;
}

.plan-output {
  display: grid;
  gap: 12px;
}

.generation-details {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
}

.detail-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #10151a;
}

.detail-block summary {
  cursor: pointer;
  padding: 11px 12px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 850;
}

.detail-block pre {
  max-height: 520px;
  margin: 0;
  overflow: auto;
  border-top: 1px solid var(--border);
  padding: 13px;
  color: #dce6eb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.plan-card {
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.plan-card span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.plan-card strong {
  overflow-wrap: anywhere;
}

.scene-list,
.retention-list {
  display: grid;
  gap: 9px;
}

.scene-item,
.retention-item {
  padding: 11px 12px;
}

.scene-head,
.retention-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  font-weight: 850;
}

.empty-state,
.empty-list {
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(420px, calc(100% - 36px));
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f4f0e8;
  color: #111519;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1280px) {
  .workspace,
  .production-grid,
  .split-row {
    grid-template-columns: 1fr;
  }

  .generator-panel {
    position: static;
  }

  .compact-grid,
  .plan-grid,
  .detail-grid,
  .pipeline-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 18px, 1540px);
    padding-top: 12px;
  }

  .topbar,
  .panel-header,
  .topbar-actions,
  .upload-row {
    align-items: stretch;
    flex-direction: column;
  }

  .generator-form .action-row {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .compact-grid,
  .reference-meta,
  .job-meta,
  .plan-grid,
  .detail-grid,
  .pipeline-meta {
    grid-template-columns: 1fr;
  }

  .reference-item {
    grid-template-columns: 56px 1fr;
  }

  .reference-thumb {
    width: 56px;
    height: 56px;
  }

  .reference-item .danger-button {
    grid-column: 1 / -1;
  }

  .video-preview {
    min-height: 420px;
  }
}
