:root {
  --ink: #1c1d20;
  --muted: #6e7178;
  --line: #dfe5d8;
  --panel: #ffffff;
  --page: #f7f8ef;
  --accent: #f4d70a;
  --accent-dark: #18361b;
  --accent-soft: #fff6a6;
  --leaf: #123415;
  --orange: #ffab08;
  --warn: #b56a00;
  --bad: #bd2d2d;
  --good: #247447;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button,
.button-link {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.button-link:hover {
  border-color: #9da6b5;
}

button:disabled,
.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.primary {
  background: var(--accent);
  border-color: #e5c900;
  color: #18220f;
  font-weight: 700;
}

.primary:hover {
  background: #ffe733;
}

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  color: #fff;
  background: var(--leaf);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 8px;
  background: #fffbe1;
  padding: 4px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #f6eaa0;
  margin-top: 3px;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a {
  color: #ecf1dc;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
}

.nav a:hover,
.nav a.active {
  background: rgba(244, 215, 10, 0.16);
  color: #fff7a6;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #b8c1cc;
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
}

.dot.online {
  background: var(--accent);
}

.main {
  min-width: 0;
  padding: 24px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.top-actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.api-button {
  background: var(--accent);
  border-color: #e2c602;
  color: #17220e;
  font-weight: 800;
}

.api-button:hover {
  background: #ffe94a;
  border-color: var(--orange);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.25;
}

h2 {
  font-size: 17px;
}

.topbar p,
.panel-head span,
small {
  color: var(--muted);
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 22px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: grid;
  gap: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-head.tight {
  margin-top: 2px;
}

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

.asset-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
  max-height: 430px;
  overflow: auto;
  padding-right: 2px;
}

.asset-list.single {
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}

.asset-card {
  position: relative;
  display: grid;
  gap: 8px;
  height: auto;
  min-height: 0;
  padding: 8px;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
}

.asset-card.selected {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(244, 215, 10, 0.35);
  background: #fffdf0;
}

.asset-card::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 2px solid #ced6c2;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.16);
}

.asset-card.selected::after {
  content: "✓";
  display: grid;
  place-items: center;
  border-color: var(--leaf);
  background: var(--accent);
  color: var(--leaf);
  font-weight: 900;
  font-size: 16px;
}

.asset-card[data-asset-kind="product"]::after {
  display: none;
}

.asset-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: #eef1f4;
}

.asset-card span {
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.upload-box {
  position: relative;
  min-height: 220px;
  border: 1px dashed #aab3c2;
  border-radius: var(--radius);
  background: #fbfcfd;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  overflow: hidden;
  cursor: pointer;
}

.upload-box input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #e6f3f4;
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 28px;
}

.upload-box img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbs {
  position: absolute;
  inset: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  pointer-events: none;
}

.thumbs img {
  position: static;
  border-radius: 6px;
  border: 1px solid #fff;
}

.character-cards {
  display: grid;
  gap: 14px;
}

.empty-state {
  border: 1px dashed #aab3c2;
  border-radius: var(--radius);
  color: var(--muted);
  background: #fbfcfd;
  padding: 18px;
}

.character-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 14px;
}

.character-head {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.character-head img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f1f3f6;
}

.character-head strong,
.character-head span,
.character-head small {
  display: block;
  overflow-wrap: anywhere;
}

.character-head span {
  color: var(--muted);
  margin: 3px 0;
}

.ok {
  color: var(--good);
}

.bad,
.error-text {
  color: var(--bad);
}

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

.prompt-grid.large textarea {
  min-height: 300px;
}

.prompt-panel {
  gap: 18px;
}

.prompt-grid.nested {
  align-items: start;
}

.prompt-grid label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  line-height: 1.55;
  color: var(--ink);
}

textarea:focus {
  outline: 2px solid rgba(244, 215, 10, 0.28);
  border-color: var(--orange);
}

.prompt-tools,
.actions,
.metric-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.action-bar {
  justify-content: flex-start;
}

.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  padding: 10px 12px;
  line-height: 1.45;
  white-space: pre-line;
}

.notice.error {
  border-color: #efb8b8;
  background: #fff5f5;
  color: var(--bad);
}

.notice.success {
  border-color: #b8ddc8;
  background: #f2fbf5;
  color: var(--good);
}

.prompt-tools {
  justify-content: space-between;
  color: var(--muted);
}

.status-panel {
  align-content: start;
}

.progress-wrap {
  display: grid;
  gap: 10px;
}

.progress-bar {
  height: 12px;
  border-radius: 999px;
  background: #e8ebf0;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--orange));
  transition: width 180ms ease;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.metric-row div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.metric-row span {
  display: block;
  font-size: 24px;
  font-weight: 800;
}

.compact {
  align-items: stretch;
}

.jobs-list {
  display: grid;
  gap: 16px;
}

.job-group {
  display: grid;
  gap: 8px;
}

.job-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}

.job-group-title h3 {
  margin: 0;
  font-size: 15px;
}

.job-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.job-row {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) 100px 90px 90px 120px;
  gap: 12px;
  align-items: center;
  text-align: left;
  cursor: pointer;
}

.job-row:last-child {
  border-bottom: 0;
}

.job-row:hover,
.job-row.active {
  background: #fffbea;
}

.job-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.job-main strong,
.job-main small {
  overflow-wrap: anywhere;
}

.job-row .outputs {
  justify-content: flex-end;
}

.job-row:focus-visible {
  outline: 2px solid rgba(244, 215, 10, 0.55);
  outline-offset: -2px;
}

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

.badge {
  border-radius: 999px;
  padding: 4px 10px;
  background: #edf1f5;
  color: #404650;
  font-size: 12px;
  font-weight: 700;
}

.badge.done {
  background: #e7f5ed;
  color: var(--good);
}

.badge.failed {
  background: #fdeaea;
  color: var(--bad);
}

.badge.running {
  background: #fff6c9;
  color: #8a6100;
}

.step-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.step {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
  min-width: 0;
}

.step strong,
.step p {
  overflow-wrap: anywhere;
}

.outputs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.outputs a {
  color: var(--leaf);
  font-weight: 700;
}

.log-stream {
  height: 260px;
  overflow: auto;
  background: #101418;
  color: #d7e0e8;
  border-radius: var(--radius);
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.log-line {
  padding: 3px 0;
  overflow-wrap: anywhere;
}

.log-line.error {
  color: #ff9d9d;
}

.log-line.warn {
  color: #ffd280;
}

.small {
  min-height: 32px;
  font-size: 13px;
}

.dialog {
  width: min(980px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
  color: var(--ink);
}

.dialog::backdrop {
  background: rgba(20, 24, 28, 0.48);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  max-height: 72vh;
  overflow: auto;
}

.preview-item {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fbfcfd;
}

.preview-item img,
.preview-item video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  background: #111;
}

.preview-item figcaption {
  padding: 8px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.settings-dialog {
  width: min(560px, calc(100vw - 32px));
}

.settings-dialog form {
  display: grid;
  gap: 14px;
}

.settings-dialog label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

.settings-dialog input[type="url"],
.settings-dialog input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 40px;
  padding: 8px 10px;
}

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  font-weight: 400;
}

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

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }

  .nav {
    grid-auto-flow: column;
    overflow-x: auto;
  }

  .sidebar-foot {
    margin-left: auto;
    margin-top: 0;
  }

  .workspace,
  .upload-grid,
  .prompt-grid {
    grid-template-columns: 1fr;
  }

  .character-head {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .character-head .remove-character {
    grid-column: 1 / -1;
    justify-self: start;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 22px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .upload-box {
    min-height: 180px;
  }
}
