:root {
  color-scheme: light;
  --bg: #f7f8fc;
  --panel: #ffffff;
  --line: #e6e9f0;
  --line-strong: #d5dceb;
  --text: #1f2937;
  --heading: #101b3d;
  --muted: #6f7d99;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --purple: #8b5cf6;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 16px 36px rgba(31, 41, 55, 0.06);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--heading);
  font-size: 22px;
  font-weight: 800;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: block;
  object-fit: contain;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 22px;
  color: #425174;
  font-size: 14px;
}

.primary-link {
  color: var(--primary);
  font-weight: 700;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--heading);
  font-weight: 700;
}

.avatar {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #5ea2ff, #8b5cf6);
  color: #fff;
  font-size: 14px;
}

.inline-form {
  display: inline;
  margin: 0;
}

.link-button {
  border: 0;
  background: transparent;
  color: #425174;
  padding: 0;
}

.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  max-width: 1440px;
  min-height: calc(100vh - 64px);
  margin: 0 auto;
}

.sidebar {
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 12px 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.68);
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-nav a {
  position: relative;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-radius: 8px;
  color: #586783;
  font-size: 16px;
  font-weight: 600;
}

.side-nav a span {
  width: 20px;
  display: inline-grid;
  place-items: center;
  color: #7a8aad;
}

.side-nav a.active {
  background: #eef5ff;
  color: #0f62ff;
}

.side-nav a.active::before {
  content: "";
  position: absolute;
  left: -12px;
  width: 4px;
  height: 48px;
  border-radius: 0 4px 4px 0;
  background: #2d6bff;
}

.side-nav a.active span {
  color: #0f62ff;
}

.quota-card {
  margin: 0 16px;
  padding: 18px;
  border: 1px solid #dce7ff;
  border-radius: 12px;
  background: #f7fbff;
}

.quota-card p {
  margin: 0 0 12px;
  color: #60708f;
  font-size: 14px;
}

.quota-card strong {
  display: block;
  color: #1461ff;
  font-size: 24px;
}

.quota-card small {
  color: #60708f;
  font-size: 14px;
  font-weight: 600;
}

.quota-track,
.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebf5;
}

.quota-track {
  margin: 16px 0;
}

.quota-track span,
.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #4f8dfb);
  transition: width 0.25s ease;
}

.content {
  min-width: 0;
  padding: 24px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 880px) 320px;
  gap: 24px;
}

.main-column,
.right-column,
.gif-layout,
.config-list {
  display: grid;
  gap: 16px;
}

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

.panel-title {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-title h1,
.panel-title h2,
.page-title {
  margin: 0;
  color: var(--heading);
  font-size: 20px;
  line-height: 1.3;
}

.page-title {
  margin-bottom: 8px;
  font-size: 28px;
}

.page-subtitle {
  margin: 0 0 28px;
  color: var(--muted);
}

.compact-title {
  margin-bottom: 14px;
}

.step-index {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: #eef5ff;
  color: #0f62ff;
  font-size: 20px;
  font-weight: 800;
}

.step-index.purple {
  background: #f1ebff;
  color: var(--purple);
}

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

.generator-form,
.compact-form {
  display: grid;
  gap: 16px;
}

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

.inline-field label,
.field-label,
.compact-form label,
.three-fields label,
.two-fields label {
  color: #24314f;
  font-size: 14px;
  font-weight: 700;
}

.field-label span {
  margin-left: 8px;
  color: #7181a2;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #d4dceb;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #6d9cff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.inline-field input {
  width: 90px;
}

.prompt-box {
  position: relative;
}

.prompt-box textarea,
.compact-form textarea {
  min-height: 92px;
  resize: vertical;
  padding-right: 74px;
  line-height: 1.6;
}

.prompt-magic {
  position: absolute;
  right: 16px;
  top: 20px;
  width: 40px;
  height: 40px;
  border: 1px solid #dbe4f5;
  border-radius: 9px;
  background: #f4f8ff;
  color: #1263ff;
  font-size: 20px;
}

.prompt-counter {
  position: absolute;
  right: 16px;
  bottom: 12px;
  color: #7181a2;
  font-size: 13px;
}

.primary-button,
.outline-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 800;
}

.primary-button {
  border: 0;
  background: linear-gradient(90deg, #1461ff, #0f62ff);
  color: #fff;
}

.purple-button {
  background: linear-gradient(90deg, #7e5df6, #9b5cf6);
}

.outline-button {
  border: 1px solid #d8e0ee;
  background: #fff;
  color: #315071;
}

.full-button {
  width: 100%;
}

.compact {
  min-height: 36px;
  padding: 8px 14px;
  font-size: 14px;
}

.upload-section {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.section-caption {
  flex: 0 0 100%;
  color: #1f2b49;
  font-size: 14px;
  font-weight: 800;
}

.section-caption span {
  color: var(--muted);
  font-weight: 500;
}

.reference-list,
.selected-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.reference-item,
.selected-item,
.upload-tile {
  width: 128px;
  height: 120px;
  overflow: hidden;
  border-radius: 8px;
}

.reference-item,
.selected-item {
  position: relative;
  background: #edf2fa;
}

.reference-item img,
.selected-item img,
.asset-thumb img,
.result-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.remove-file {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: rgba(16, 24, 40, 0.8);
  color: #fff;
  font-size: 18px;
  line-height: 1;
}

.upload-tile,
.wide-upload {
  display: grid;
  place-items: center;
  border: 1px dashed #cbd6eb;
  background: #fbfdff;
  color: #566888;
  text-align: center;
  cursor: pointer;
}

.upload-tile input,
.wide-upload input {
  display: none;
}

.upload-tile span {
  color: #526180;
  font-size: 30px;
  line-height: 1;
}

.upload-tile strong,
.wide-upload span {
  color: #263756;
  font-size: 14px;
}

.upload-tile small,
.wide-upload small {
  color: #7181a2;
  font-size: 12px;
}

.progress-card {
  display: grid;
  gap: 12px;
}

.progress-card[hidden] {
  display: none;
}

.progress-head,
.progress-status,
.result-actions,
.config-actions,
.detail-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-head {
  justify-content: space-between;
}

.progress-head h2 {
  margin: 0;
  color: #0f62ff;
  font-size: 16px;
}

.progress-head strong {
  color: #0f62ff;
}

.status-dot {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border: 2px solid var(--success);
  border-radius: 50%;
}

.status-dot::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 16px;
}

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

.preview-button {
  width: 100%;
  height: 148px;
  padding: 0;
  border: 0;
  background: #eef2f8;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-top: 1px solid var(--line);
}

.result-actions a,
.result-actions button {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: #526180;
}

.result-actions a:last-child,
.result-actions button:last-child {
  border-right: 0;
}

.result-actions .is-favorite {
  color: #e0527d;
}

.result-actions .login-required {
  background: #f8fafc;
  color: #7a8aad;
}

.login-history-hint {
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1px solid #dbe7ff;
  border-radius: 8px;
  background: #f7fbff;
  color: #526180;
  font-size: 13px;
  line-height: 1.6;
}

.empty-state {
  min-height: 132px;
  display: grid;
  place-items: center;
  border: 1px dashed #d5dceb;
  border-radius: 8px;
  background: #fbfdff;
  color: #8a97b3;
}

.gif-layout {
  grid-template-columns: minmax(360px, 400px) minmax(0, 1fr);
  align-items: start;
}

.wide-upload {
  min-height: 76px;
  border-radius: 8px;
  margin-top: 14px;
}

.asset-picker {
  margin-top: 16px;
}

.asset-thumb {
  width: 78px;
  height: 78px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: transparent;
}

.asset-thumb.active {
  border-color: var(--primary);
}

.two-fields,
.three-fields {
  display: grid;
  gap: 18px;
}

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

.three-fields {
  grid-template-columns: 220px minmax(260px, 1fr) 300px;
}

.two-fields input,
.three-fields input {
  margin-top: 8px;
}

.gif-preview-box {
  min-height: 500px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: #edf2f8;
}

.gif-preview-box img {
  width: 100%;
  height: 100%;
  max-height: 560px;
  object-fit: contain;
}

.config-list {
  gap: 28px;
}

.api-card {
  overflow: hidden;
  padding-left: 28px;
}

.api-card .three-fields {
  align-items: end;
}

.api-card input {
  min-height: 48px;
  font-size: 15px;
  font-weight: 600;
}

.card-accent {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
}

.card-accent.blue {
  background: var(--primary);
}

.card-accent.purple {
  background: var(--purple);
}

.api-card h2 {
  margin: 0 0 8px;
  color: var(--heading);
}

.config-actions {
  width: 100%;
  margin-top: 20px;
}

.config-actions [data-save-config] {
  margin-left: auto;
}

.connect-state {
  color: #8a97b3;
  font-weight: 700;
  white-space: nowrap;
}

.connect-state.success {
  color: #16a34a;
}

.connect-state.error {
  color: var(--danger);
}

.filter-bar {
  display: grid;
  grid-template-columns: 150px 150px minmax(220px, 1fr) auto auto;
  gap: 12px;
  margin-bottom: 18px;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
}

.task-table {
  display: grid;
  gap: 8px;
}

.task-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.task-row.selected {
  border-color: #b8d4ff;
  background: #f7fbff;
}

.task-row a {
  min-height: 72px;
  display: grid;
  grid-template-columns: 140px 100px minmax(180px, 1fr) 92px 160px;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.task-row strong {
  color: #0f62ff;
  font-size: 13px;
}

.task-row em {
  color: #425174;
  font-style: normal;
  line-height: 1.5;
}

.task-row time,
.task-row span {
  color: #526180;
  font-size: 13px;
}

.status-pill {
  justify-self: start;
  padding: 4px 9px;
  border-radius: 6px;
  background: #eef5ff;
  color: var(--primary);
  font-size: 12px;
  font-style: normal;
}

.status-pill.completed {
  background: #ecfdf3;
  color: #16a34a;
}

.status-pill.failed {
  background: #fff1f1;
  color: var(--danger);
}

.detail-panel {
  align-self: start;
  position: sticky;
  top: 88px;
}

.detail-cover {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 14px;
}

.detail-list {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  color: #4b5b78;
  font-size: 14px;
}

.detail-list dt {
  color: #7a8aad;
}

.detail-list dd {
  margin: 0;
  word-break: break-all;
}

.prompt-preview {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: #425174;
  line-height: 1.7;
}

.simple-page {
  max-width: 820px;
  line-height: 1.8;
}

.auth-card {
  max-width: 420px;
  margin: 64px auto 0;
}

.auth-card h1 {
  margin: 0 0 22px;
  color: var(--heading);
}

.auth-card form {
  display: grid;
  gap: 14px;
}

.auth-card input {
  margin-top: 8px;
}

.auth-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--danger);
  font-size: 13px;
}

.auth-required-panel {
  max-width: 680px;
}

.auth-required-panel h2 {
  margin: 0 0 10px;
  color: var(--heading);
}

.auth-required-panel p {
  margin: 0;
  color: #526180;
  line-height: 1.7;
}

.auth-required-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.field-help {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.message-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.toast {
  padding: 10px 12px;
  border-radius: 8px;
  background: #ecfdf3;
  color: #166534;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: rgba(15, 23, 42, 0.78);
}

.image-modal.show {
  display: flex;
}

.image-modal img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 8px;
  background:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-color: #fff;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.modal-close {
  position: fixed;
  top: 20px;
  right: 24px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #1f2937;
  font-size: 28px;
}

.processor-layout {
  display: grid;
  grid-template-columns: minmax(420px, 560px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.processor-form {
  display: grid;
  gap: 18px;
}

.processor-section {
  display: grid;
  gap: 12px;
}

.processor-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.processor-section-title span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef5ff;
  color: var(--primary);
  font-weight: 800;
}

.processor-section-title h2 {
  margin: 0;
  color: var(--heading);
  font-size: 18px;
}

.processor-upload {
  margin-top: 0;
}

.processor-file-list {
  display: grid;
  gap: 8px;
}

.processor-file-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.processor-file-item img {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  background: #edf2f8;
}

.processor-file-item strong,
.processor-file-item span {
  display: block;
}

.processor-file-item strong {
  color: var(--heading);
  word-break: break-all;
}

.processor-file-item span {
  margin-top: 4px;
  color: #7a8aad;
  font-size: 13px;
}

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

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

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

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

.processor-grid label,
.processor-check {
  color: #526180;
  font-weight: 700;
}

.processor-grid input,
.processor-grid select {
  margin-top: 8px;
}

.processor-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.processor-check input {
  width: 16px;
  height: 16px;
}

.processor-help {
  margin: 0;
}

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

.processor-segmented label {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #526180;
  font-weight: 700;
  font-size: 12px;
  min-width: 120px;
}

.processor-segmented label  input{
  min-height: unset;
}

.processor-results {
  position: sticky;
  top: 88px;
}

.processor-summary {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f7fbff;
  color: #526180;
  font-weight: 700;
}

.processor-result-grid {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

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

.processor-errors {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: #fff1f1;
  color: var(--danger);
}

.processor-errors p {
  margin: 0;
  word-break: break-all;
}

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

  .sidebar {
    padding-left: 8px;
    padding-right: 8px;
  }

  .side-nav a {
    justify-content: center;
    padding: 0;
  }

  .side-nav a span {
    width: auto;
  }

  .side-nav a:not(.active) {
    color: transparent;
  }

  .side-nav a span {
    color: #7a8aad;
  }

  .quota-card {
    display: none;
  }

  .workspace-grid,
  .gif-layout,
  .history-layout,
  .processor-layout {
    grid-template-columns: 1fr;
  }

  .right-column,
  .detail-panel,
  .processor-results {
    position: static;
  }

  .three-fields {
    grid-template-columns: 1fr;
  }

  .config-actions {
    flex-wrap: wrap;
  }

  .config-actions [data-save-config] {
    margin-left: 0;
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px;
  }

  .top-actions {
    flex-wrap: wrap;
    gap: 14px;
  }

  .shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .side-nav a,
  .side-nav a:not(.active) {
    color: #586783;
    font-size: 13px;
  }

  .side-nav a.active::before {
    display: none;
  }

  .content {
    padding: 16px;
  }

  .panel {
    padding: 18px;
  }

  .two-fields,
  .filter-bar,
  .task-row a,
  .processor-grid.two,
  .processor-grid.three,
  .processor-grid.four {
    grid-template-columns: 1fr;
  }

  .reference-item,
  .selected-item,
  .upload-tile {
    width: calc(50% - 6px);
  }
}
