:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef3ef;
  --ink: #18201d;
  --muted: #5f6b65;
  --line: #ccd6cf;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --amber: #b7791f;
  --danger: #b42318;
  --blue: #315d8f;
  --shadow: 0 18px 50px rgba(22, 35, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

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

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 0 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

h3 {
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.connection-bar {
  display: grid;
  grid-template-columns: 120px minmax(240px, 340px) minmax(180px, 260px);
  gap: 12px;
  align-items: end;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
  gap: 18px;
  align-items: start;
}

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

.form-panel,
.status-panel,
.json-panel {
  padding: 18px;
}

.json-panel {
  margin-top: 18px;
}

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

.title-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

fieldset {
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

fieldset:last-of-type {
  margin-bottom: 0;
}

legend {
  padding: 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

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

textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.45;
}

input[type="file"] {
  padding: 8px;
}

.file-field {
  margin-top: 12px;
}

.photo-options {
  margin-top: 12px;
}

.field-hint {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
}

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

.grid {
  display: grid;
  gap: 12px;
}

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

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

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

.segmented label,
.toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--ink);
}

.segmented input,
.toggles input {
  width: auto;
  min-height: auto;
}

.toggles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.ai-mode {
  margin-top: 12px;
}

.creative-options {
  margin-top: 12px;
}

.ai-off .creative-options,
.ai-off .toggles label:has(input[name="aiStoryboard"]),
.ai-off .toggles label:has(input[name="aiImages"]) {
  opacity: 0.52;
}

.actions,
.status-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.actions {
  grid-template-columns: minmax(160px, 1fr) minmax(140px, 0.6fr);
}

.status-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: #e6edf1;
  color: var(--blue);
}

.secondary-button:hover {
  background: #d8e4eb;
}

.ghost-button {
  min-width: 96px;
  background: var(--surface-soft);
  color: var(--accent-dark);
}

.warning-button {
  background: #fff0e2;
  color: var(--amber);
}

.warning-button:hover {
  background: #ffe3c2;
}

.status-readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.status-readout div {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.status-readout span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-readout strong {
  display: block;
  overflow-wrap: anywhere;
}

.progress-shell {
  width: 100%;
  height: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #e8ebe7;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.progress-label,
.muted {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.job-activity {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf7;
}

.activity-main {
  display: flex;
  gap: 10px;
  align-items: center;
}

.activity-dot {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.job-activity.active .activity-dot {
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.45);
  animation: activity-pulse 1.4s ease-out infinite;
}

.job-activity.done .activity-dot {
  background: var(--accent);
}

.job-activity.slow .activity-dot {
  background: var(--amber);
}

.job-activity.stale .activity-dot,
.job-activity.error .activity-dot {
  background: var(--danger);
}

.job-activity p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

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

.activity-meta span {
  min-width: 0;
  padding: 7px 8px;
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

@keyframes activity-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.45);
  }
  100% {
    box-shadow: 0 0 0 12px rgba(15, 118, 110, 0);
  }
}

.step-list {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.step-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #a8b3ad;
}

.step-item.done .step-dot {
  background: var(--accent);
}

.step-item.active .step-dot {
  background: var(--amber);
}

.step-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.step-state {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.outputs {
  margin-top: 18px;
}

.output-link,
.empty-state {
  display: block;
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}

.output-link {
  color: var(--accent-dark);
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #e7f2ef;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
}

pre {
  max-height: 440px;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111816;
  color: #d8eee8;
  padding: 14px;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .connection-bar,
  .grid.two,
  .grid.three,
  .toggles,
  .actions,
  .status-actions,
  .activity-meta {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 14px;
  }

  h1 {
    font-size: 1.55rem;
  }

  .form-panel,
  .status-panel,
  .json-panel {
    padding: 14px;
  }

  fieldset {
    padding: 12px;
  }

  .title-actions {
    width: 100%;
    justify-content: stretch;
  }

  .title-actions button {
    flex: 1;
    min-width: 0;
  }
}
