:root {
  color-scheme: light;
  --bg: #eef3f2;
  --bg-strong: #e1e8eb;
  --ink: #172026;
  --ink-soft: #30414a;
  --muted: #66737c;
  --line: #d6e0e3;
  --panel: #ffffff;
  --panel-soft: #f8faf9;
  --accent: #0f766e;
  --accent-dark: #0b4f4a;
  --accent-soft: #e3f6f2;
  --blue: #315f9f;
  --blue-soft: #e8f0fb;
  --gold: #b7791f;
  --gold-soft: #fff5dd;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --success: #16803c;
  --success-soft: #e7f7ec;
  --shadow: 0 18px 55px rgba(27, 39, 49, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:disabled,
input:disabled,
textarea:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.shell {
  width: min(1540px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar,
.panel-head,
.dialog-head,
.dialog-foot,
.output-head,
.output-actions,
.top-actions,
.form-actions,
.dialog-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar,
.panel-head,
.dialog-head,
.dialog-foot,
.output-head,
.dialog-toolbar {
  justify-content: space-between;
}

.topbar {
  margin-bottom: 22px;
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p,
figure {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 34px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.35;
}

.subhead {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.top-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(660px, 1fr) 430px;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.composer {
  min-height: 520px;
}

.jobs-panel {
  min-height: 520px;
}

.output {
  margin-top: 18px;
}

.output-head {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.output-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.form-grid,
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

label {
  display: grid;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fbfcfc;
  padding: 11px 12px;
  outline: none;
}

textarea {
  min-height: 136px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.primary,
.icon-button {
  border-radius: 6px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.primary {
  min-height: 42px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  padding: 11px 16px;
  font-weight: 900;
}

.primary:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.primary:active:not(:disabled),
.icon-button:active:not(:disabled) {
  transform: translateY(0);
}

.primary.ghost {
  background: #ffffff;
  color: var(--accent-dark);
  border-color: var(--line);
}

.primary.ghost:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.primary.small {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 13px;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent-dark);
  font-size: 22px;
  line-height: 1;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  max-width: 100%;
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.badge-soft {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.completed,
.badge.ready {
  background: var(--success-soft);
  color: var(--success);
}

.badge.failed,
.badge.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.working,
.badge.warning {
  background: var(--gold-soft);
  color: var(--gold);
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.compact {
  margin: 0;
}

.form-actions {
  justify-content: space-between;
  flex-wrap: wrap;
  padding-top: 4px;
}

.check-row {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-weight: 700;
}

.check-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.state-line {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
}

.state-line.error {
  border-color: rgba(180, 35, 24, 0.28);
  background: var(--danger-soft);
  color: var(--danger);
}

.job-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  max-height: 442px;
  overflow: auto;
  padding-right: 2px;
}

.job-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.job-item:hover {
  border-color: rgba(15, 118, 110, 0.55);
  background: #ffffff;
}

.job-item.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.job-item.failed {
  border-color: rgba(180, 35, 24, 0.34);
}

.job-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-weight: 900;
}

.job-topic {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.error-text {
  color: var(--danger);
  font-weight: 800;
}

.job-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.meta-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 11px 12px;
  min-width: 0;
}

.metric strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.2;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.empty {
  min-height: 190px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  margin-top: 16px;
  padding: 24px;
  text-align: center;
  line-height: 1.6;
}

.empty.error {
  border-color: rgba(180, 35, 24, 0.32);
  background: var(--danger-soft);
  color: var(--danger);
}

.loading-block {
  min-height: 190px;
  display: grid;
  place-items: center;
  gap: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  margin-top: 16px;
  padding: 24px;
  text-align: center;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #dce7e9;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.script-grid {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

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

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title .muted {
  text-align: right;
}

.note-block {
  border-left: 3px solid var(--accent);
  background: var(--panel-soft);
  border-radius: 6px;
  padding: 12px 14px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.65;
}

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

.character-card,
.shot {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
}

.character-card h3,
.shot h3 {
  overflow-wrap: anywhere;
}

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

.detail-list div,
.shot-meta div {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  padding: 9px 10px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
}

.detail-list strong,
.shot-meta strong,
.frame-copy strong {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 12px;
}

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

.asset-card {
  min-width: 0;
  overflow: hidden;
}

.asset-thumb {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #dfe8ea;
}

.asset-thumb img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

.asset-card figcaption,
.asset-caption {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.asset-placeholder {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-soft);
  padding: 12px;
  text-align: center;
  font-size: 12px;
  line-height: 1.35;
}

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

.shot-list {
  display: grid;
  gap: 14px;
}

.shot-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.shot-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.shot-copy {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.shot-copy p {
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
}

.frame-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.1fr;
  gap: 12px;
  margin-top: 12px;
}

.video-box {
  min-height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.55;
}

.video-box .badge {
  margin-bottom: 10px;
}

.prompt-box {
  max-height: 120px;
  overflow: auto;
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.admin-dialog {
  width: min(980px, calc(100vw - 48px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.admin-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.admin-shell {
  padding: 22px;
}

.dialog-head {
  margin-bottom: 18px;
}

.dialog-toolbar {
  margin-top: 14px;
}

.dialog-foot {
  margin-top: 18px;
  align-items: flex-end;
}

.setting-field small {
  color: var(--muted);
  font-weight: 600;
  line-height: 1.4;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: 430px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #172026;
  color: #ffffff;
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.45;
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 1180px) {
  body {
    min-width: 0;
  }

  .shell {
    width: min(100% - 28px, 980px);
    padding-top: 18px;
  }

  .topbar,
  .layout,
  .output-head,
  .dialog-foot {
    align-items: stretch;
  }

  .topbar,
  .layout,
  .output-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-actions,
  .output-actions {
    justify-content: flex-start;
  }

  .layout,
  .form-grid,
  .admin-grid,
  .meta-strip,
  .character-grid,
  .cards-grid,
  .storyboard-grid,
  .frame-row,
  .shot-meta,
  .detail-list {
    grid-template-columns: 1fr;
  }

  .jobs-panel,
  .composer {
    min-height: 0;
  }

  .job-list {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 640px);
  }

  .panel {
    padding: 16px;
  }

  h1 {
    font-size: 28px;
  }

  .form-actions,
  .dialog-toolbar,
  .dialog-foot {
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary,
  .primary.small {
    width: 100%;
  }
}
