:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --green: #059669;
  --green-bg: #ecfdf5;
  --orange: #d97706;
  --orange-bg: #fff7ed;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --sidebar: #111827;
  --sidebar-soft: #172033;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c10;
  --panel: #14161c;
  --panel-2: #1b1f27;
  --line: #2b303b;
  --text: #f3f4f6;
  --muted: #a1a1aa;
  --blue: #60a5fa;
  --blue-bg: #10243d;
  --green: #34d399;
  --green-bg: #073525;
  --orange: #fbbf24;
  --orange-bg: #33270a;
  --red: #f87171;
  --red-bg: #35141a;
  --sidebar: #05070d;
  --sidebar-soft: #0d1322;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 1180px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Segoe UI", sans-serif;
  font-size: 14px;
}

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 26px 17px 22px;
  background: var(--sidebar);
  color: #f9fafb;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #2563eb;
  font-weight: 900;
}

.brand-title {
  font-size: 18px;
  font-weight: 900;
  line-height: 1.15;
}

.brand-subtitle {
  margin-top: 3px;
  color: #c7d2fe;
  font-size: 14px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 7px;
  color: #e5e7eb;
  font-size: 18px;
  font-weight: 900;
}

.nav-item.active {
  background: #1d4ed8;
  color: #ffffff;
}

.side-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #253149;
  border-radius: 8px;
  background: var(--sidebar-soft);
}

.side-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 22px;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 800;
}

.side-row b {
  white-space: nowrap;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #253149;
  border-radius: 8px;
  background: var(--sidebar-soft);
}

.theme-switch {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.theme-switch button {
  height: 32px;
  border: 1px solid #334155;
  border-radius: 7px;
  background: #f8fafc;
  color: #111827;
  font-weight: 900;
  cursor: pointer;
}

.theme-switch button:last-child {
  background: #020617;
  color: #f8fafc;
}

.theme-switch button.active {
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.22);
}

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

.main {
  margin-left: 248px;
  min-height: 100vh;
}

.topbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 21px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 10px;
  font-size: 16px;
  line-height: 1.15;
}

.topbar p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions,
.filter-bar,
.rail-tags,
.action-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

.button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.pill,
.chip,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 900;
}

.chip {
  background: var(--panel-2);
  color: var(--muted);
}

.chip.selected,
.pill.info {
  background: var(--blue-bg);
  color: var(--blue);
}

.pill.success {
  background: var(--green-bg);
  color: var(--green);
}

.pill.warning {
  background: var(--orange-bg);
  color: var(--orange);
}

.pill.muted {
  background: var(--panel-2);
  color: var(--muted);
}

.page-grid {
  display: grid;
  gap: 10px;
  padding: 10px 14px;
}

.queue-grid {
  grid-template-columns: minmax(0, 1fr) 280px;
}

.new-grid {
  grid-template-columns: minmax(410px, 1fr) minmax(360px, 400px) 230px;
}

.detail-grid {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.worker-grid,
.settings-grid {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.presets-grid {
  grid-template-columns: 320px minmax(0, 1fr);
}

.content-stack,
.right-rail {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 10px;
}

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

.panel.compact {
  padding: 12px;
}

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

.metrics-row,
.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

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

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

.metric-card {
  display: flex;
  min-height: 68px;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--panel);
}

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

.metric-card strong {
  font-size: 22px;
}

.job-table {
  margin-top: 10px;
  display: grid;
  gap: 7px;
}

.job-row {
  display: grid;
  grid-template-columns: 72px 112px 170px minmax(150px, 1fr) 110px;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--panel-2);
}

.job-head {
  min-height: 30px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  background: transparent;
}

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

.log-list div {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  min-height: 24px;
  align-items: center;
}

.log-list b {
  color: var(--blue);
}

.block-list {
  margin-top: 10px;
}

.grow-panel {
  min-height: 420px;
}

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

.preset-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--panel-2);
}

.preset-row.active {
  background: var(--blue-bg);
}

.preset-row em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
  font-weight: 900;
}

.muted-row {
  opacity: 0.72;
}

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

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

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

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

.theme-row button {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.theme-row button.active {
  border-color: var(--blue);
  background: var(--blue-bg);
  color: var(--blue);
}

.status-pending {
  background: var(--orange-bg);
  color: var(--orange);
}

.status-running,
.status-uploading {
  background: var(--blue-bg);
  color: var(--blue);
}

.status-succeeded {
  background: var(--green-bg);
  color: var(--green);
}

.status-failed {
  background: var(--red-bg);
  color: var(--red);
}

.status-canceled {
  background: var(--panel-2);
  color: var(--muted);
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

textarea {
  resize: vertical;
  min-height: 74px;
}

textarea[name="positive_prompt"] {
  min-height: 90px;
}

textarea[name="negative_prompt"] {
  min-height: 70px;
}

.create-panel {
  min-height: 0;
}

.reference-row,
.result-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: 10px;
  align-items: end;
}

.result-row {
  grid-template-columns: 132px minmax(0, 1fr);
  align-items: start;
}

.preview-box {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 82px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.preview-box img {
  width: 100%;
  height: 100%;
  min-height: 82px;
  object-fit: cover;
}

.preview-box.has-image {
  border-color: var(--blue);
  background: var(--panel);
}

.preview-box.large {
  min-height: 144px;
  border-color: var(--blue);
  background: var(--blue-bg);
  color: var(--blue);
}

.action-line {
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

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

.locked-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
}

.status-list,
.details {
  display: grid;
  grid-template-columns: minmax(118px, 42%) minmax(0, 1fr);
  gap: 8px 10px;
  margin: 0;
}

.status-list dt,
.details dt {
  min-width: 0;
  color: var(--muted);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.status-list dd,
.details dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.good {
  color: var(--green);
  font-weight: 900;
}

.warn {
  color: var(--orange);
  font-weight: 900;
}

.info-text {
  color: var(--blue);
  font-weight: 900;
}

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

.progress {
  overflow: hidden;
  height: 8px;
  margin: 10px 0;
  border-radius: 999px;
  background: var(--line);
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

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

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

.result-card img {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}

.empty {
  padding: 26px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.empty.small {
  padding: 18px;
}

.alert,
.error-text {
  margin: 12px 14px 0;
  border: 1px solid var(--red);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--red-bg);
  color: var(--red);
  font-weight: 900;
}

.error-text.inline {
  margin: 0;
}

.muted-text {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

pre {
  overflow: auto;
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-2);
  color: var(--text);
}

@media (max-width: 1280px) {
  .sidebar {
    width: 230px;
    padding-inline: 13px;
  }

  .main {
    margin-left: 230px;
  }

  .new-grid {
    grid-template-columns: minmax(390px, 1fr) minmax(340px, 380px) 220px;
  }

  .queue-grid {
    grid-template-columns: minmax(0, 1fr) 250px;
  }
}

@media (max-width: 1100px) {
  html {
    min-width: 0;
  }

  .sidebar {
    position: static;
    width: auto;
  }

  .main {
    margin-left: 0;
  }

  .topbar {
    min-height: 52px;
    align-items: flex-start;
    flex-direction: column;
  }

  .queue-grid,
  .new-grid,
  .detail-grid,
  .worker-grid,
  .presets-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .metrics-row,
  .metric-strip,
  .metrics-mini,
  .job-row,
  .reference-row,
  .result-row,
  .preset-editor,
  .compact-grid,
  .preset-row,
  .theme-row {
    grid-template-columns: 1fr;
  }
}
