:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --paper: #ffffff;
  --paper-soft: #f7f8f5;
  --paper-warm: #fbfbf8;
  --line: #dfe4dc;
  --line-strong: #cbd4c9;
  --text: #202825;
  --muted: #727b75;
  --faint: #9aa29c;
  --green: #2f7b67;
  --green-strong: #1f604f;
  --green-soft: #e8f2ec;
  --red: #c6473f;
  --orange: #a26722;
  --shadow: 0 10px 28px rgba(38, 50, 44, 0.08);
  --radius: 8px;
  --font: "Microsoft YaHei", "Noto Sans SC", "PingFang SC", "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171d18;
  --paper: #20271f;
  --paper-soft: #252d24;
  --paper-warm: #222a21;
  --line: #343d34;
  --line-strong: #4b554b;
  --text: #eef3ec;
  --muted: #aab3aa;
  --faint: #7f897f;
  --green: #7ed7bd;
  --green-strong: #8ee8ce;
  --green-soft: #263b34;
  --red: #ff8279;
  --orange: #d3a45f;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

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

button,
.ghost-btn {
  min-height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--paper);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: 140ms ease;
}

button:hover:not(:disabled),
.ghost-btn:hover {
  border-color: var(--green);
  color: var(--green-strong);
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--text);
  outline: none;
}

input,
select {
  height: 34px;
  padding: 0 10px;
}

textarea {
  min-height: 92px;
  resize: vertical;
  padding: 10px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 123, 103, 0.12);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  height: 40px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  object-fit: contain;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(18, 105, 82, 0.08);
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-mini {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  font-weight: 800;
  padding: 0 12px;
}

.primary-mini:hover:not(:disabled) {
  background: var(--green-strong);
  color: #fff;
}

.ghost-btn,
.import-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  background: var(--paper);
  color: var(--text);
}

.compact-action {
  color: var(--muted);
}

.utility-hidden {
  display: none !important;
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 430px;
  gap: 8px;
  height: calc(100vh - 40px);
  padding: 8px;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--paper) 96%, transparent);
  box-shadow: var(--shadow);
}

.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
}

.panel-heading,
.section-title-row,
.stage-header,
.button-row,
.stage-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-heading {
  padding: 12px 12px 8px;
}

.panel-heading h2,
.section h2,
.stage-header h2 {
  margin: 0;
  font-size: 15px;
}

.panel-heading p,
.setting-subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status-dot.ok {
  color: var(--green-strong);
  font-weight: 800;
}

.task-toolbar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px 10px;
  flex-wrap: wrap;
}

.task-toolbar span {
  color: var(--muted);
  font-size: 12px;
}

.secondary-btn,
.danger-btn,
.danger-soft {
  background: #fff;
  color: var(--green-strong);
}

.danger-btn,
.danger-soft {
  border-color: #efc9c5;
  color: var(--red);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.muted {
  background: var(--paper-soft);
  color: var(--muted);
}

.status-pill.ok {
  background: var(--green-soft);
  color: var(--green-strong);
}

.status-pill.error {
  background: #fde9e7;
  color: var(--red);
}

.task-filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin: 0 12px 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
}

.task-filters button,
.segmented button {
  min-height: 32px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.task-filters button.active,
.segmented button.active {
  background: var(--paper);
  color: var(--green-strong);
  font-weight: 800;
}

.task-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding: 0 12px 12px;
}

.task-item {
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 90px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--text);
  padding: 10px;
  text-align: left;
}

.task-item.active {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 123, 103, 0.11);
}

.task-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.task-kind,
.task-status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--paper-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.task-status.succeeded {
  background: var(--green-soft);
  color: var(--green-strong);
}

.task-status.failed {
  background: #fde9e7;
  color: var(--red);
}

.task-status.running,
.task-status.queued {
  background: #fff2dd;
  color: var(--orange);
}

.task-prompt {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.task-subline {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-panel {
  display: flex;
  flex-direction: column;
  padding: 12px;
}

.stage-header {
  margin-bottom: 10px;
}

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

.empty-preview {
  position: relative;
  display: grid;
  flex: 1;
  min-height: 520px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}

.empty-preview::before {
  content: "";
  position: absolute;
  inset: 44px 24px auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line), transparent);
}

.empty-copy {
  display: grid;
  gap: 48px;
  place-items: center;
  color: var(--faint);
  text-align: center;
}

.empty-copy span {
  color: var(--muted);
  font-size: 14px;
}

.cache-warning {
  position: absolute;
  bottom: 18px;
  left: 20px;
  right: 20px;
  margin: 0;
  color: rgba(120, 125, 121, 0.38);
  font-size: clamp(18px, 1.5vw, 28px);
  font-weight: 900;
  text-align: center;
}

:root[data-theme="dark"] .cache-warning {
  color: rgba(170, 179, 170, 0.28);
}

.active-preview {
  display: grid;
  gap: 12px;
  overflow: auto;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.media-tile {
  position: relative;
  overflow: hidden;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(45deg, #edf0eb 25%, transparent 25%),
    linear-gradient(-45deg, #edf0eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf0eb 75%),
    linear-gradient(-45deg, transparent 75%, #edf0eb 75%);
  background-color: var(--paper);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.media-tile img,
.media-tile video {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 260px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.72);
}

.media-toolbar {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.media-toolbar a,
.media-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 7px;
  background: rgba(32, 40, 37, 0.84);
  color: #fff;
  padding: 0 10px;
  text-decoration: none;
  backdrop-filter: blur(8px);
}

.media-empty {
  display: grid;
  min-height: 260px;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

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

.task-meta div,
.prompt-card,
.request-info,
.raw-response {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 10px;
}

.task-meta span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.task-meta strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-card p {
  margin: 0;
  line-height: 1.65;
  white-space: pre-wrap;
}

.request-info {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.raw-response {
  padding: 0;
}

.raw-response summary {
  padding: 10px;
  color: var(--green-strong);
  font-weight: 800;
  cursor: pointer;
}

.raw-response pre {
  overflow: auto;
  max-height: 360px;
  margin: 0;
  border-top: 1px solid var(--line);
  padding: 10px;
  font-size: 12px;
  line-height: 1.55;
}

.right-panel {
  overflow: auto;
}

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

.connection-card {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
}

.connection-card .compact-field,
.connection-card .mini-actions,
.connection-card #configMessage {
  display: none;
}

.connection-card .section-title-row {
  align-items: start;
}

.connection-card h2 {
  font-size: 20px;
}

.generator-card {
  padding: 16px;
}

.section:last-child {
  border-bottom: 0;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.compact-field {
  margin-bottom: 8px;
}

.slim-field textarea {
  min-height: 58px;
}

.hint {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.hint.error {
  color: var(--red);
}

.hint.success {
  color: var(--green-strong);
}

.input-with-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 7px;
}

.icon-btn {
  min-width: 34px;
  padding: 0;
}

.mini-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.mini-actions button {
  flex: 1;
}

.reference-uploader {
  display: grid;
  gap: 9px;
}

.reference-title {
  margin-bottom: 12px;
}

.reference-title h2 {
  font-size: 18px;
}

.clear-reference {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  color: var(--text);
  font-size: 20px;
  font-weight: 500;
}

.reference-wide {
  margin-bottom: 14px;
}

.upload-box {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  min-height: 178px;
  padding: 18px 12px;
  border: 1px dashed #bdb5a8;
  border-radius: 12px;
  background: var(--paper-warm);
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--green);
  font-size: 23px;
}

.upload-box strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid rgba(47, 123, 103, 0.28);
  border-radius: 9px;
  background: #eaf5f1;
  color: var(--green-strong);
  padding: 0 16px;
  font-size: 16px;
}

.upload-box small {
  max-width: 360px;
  margin-top: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.35;
}

.reference-preview {
  min-height: 112px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf1eb;
}

.reference-preview img {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: contain;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  overflow: hidden;
  min-width: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
}

.big-mode {
  display: grid;
  min-height: 56px;
  margin-bottom: 14px;
  border-radius: 12px;
}

.big-mode button {
  font-size: 22px;
}

.big-mode button.active,
.option-grid button.active {
  background: #fff;
  color: var(--green-strong);
  box-shadow: 0 5px 14px rgba(28, 40, 35, 0.12);
  font-weight: 900;
}

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

.visual-controls {
  gap: 12px;
}

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

.option-field {
  margin-bottom: 0;
}

.hidden-native {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.option-grid {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-soft);
}

.option-grid button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  font-size: 16px;
}

.ratio-grid {
  grid-template-columns: repeat(5, 1fr);
  padding: 6px;
}

.resolution-grid {
  grid-template-columns: repeat(2, 1fr);
  padding: 6px;
}

.resolution-grid button {
  font-weight: 700;
}

.pill-grid {
  grid-template-columns: repeat(4, 1fr);
  padding: 4px;
}

[data-control="background"].pill-grid {
  grid-template-columns: repeat(3, 1fr);
}

.count-field {
  max-width: 300px;
}

.count-grid {
  grid-template-columns: repeat(4, 1fr);
  padding: 4px;
}

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

.apply-template {
  min-height: 46px;
  border-radius: 10px;
  color: var(--text);
  font-size: 20px;
}

.source-switch label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.source-switch input {
  position: absolute;
  opacity: 0;
}

.source-switch label:has(input:checked) {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green-strong);
}

.control-stack {
  display: grid;
  gap: 0;
}

.split-controls {
  display: grid;
  grid-template-columns: 1fr 0.76fr;
  gap: 8px;
}

.advanced-box {
  margin: 6px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-warm);
}

.advanced-box summary {
  padding: 10px;
  color: var(--green-strong);
  font-weight: 800;
  cursor: pointer;
}

.advanced-box[open] {
  padding: 0 10px 10px;
}

.advanced-box[open] summary {
  margin: 0 -10px 10px;
  border-bottom: 1px solid var(--line);
}

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

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--text);
  padding: 0 9px;
}

.checkbox-line input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.primary-action {
  width: 100%;
  min-height: 36px;
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  font-weight: 900;
}

.primary-action:hover:not(:disabled) {
  background: var(--green-strong);
  color: #fff;
}

.safety-copy {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

.connection-card {
  padding: 10px 12px;
}

.connection-card #saveConfigBtn {
  display: none;
}

.connection-card h2,
.reference-title h2 {
  font-size: 15px;
}

.generator-card {
  padding: 12px;
}

.right-panel .field {
  gap: 5px;
  margin-bottom: 8px;
  font-size: 11px;
}

.right-panel input,
.right-panel select {
  height: 31px;
  padding: 0 9px;
  font-size: 12px;
}

.right-panel textarea {
  min-height: 78px;
  padding: 8px;
  font-size: 12px;
  line-height: 1.45;
}

.reference-title {
  margin-bottom: 8px;
}

.clear-reference {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 12px;
}

.reference-wide {
  margin-bottom: 10px;
}

.upload-box {
  grid-template-columns: 96px minmax(0, 1fr);
  min-height: 124px;
  padding: 12px 10px;
  border-radius: 10px;
}

.upload-box strong {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 7px;
  font-size: 13px;
}

.upload-box small {
  max-width: 260px;
  font-size: 12px;
  line-height: 1.4;
}

.big-mode {
  min-height: 40px;
  margin-bottom: 10px;
  border-radius: 9px;
}

.big-mode button {
  min-height: 38px;
  font-size: 14px;
}

.ratio-size-grid {
  gap: 8px;
}

.visual-controls {
  gap: 8px;
}

.option-grid {
  border-radius: 8px;
}

.option-grid button {
  min-height: 29px;
  border-radius: 6px;
  font-size: 12px;
}

.ratio-grid,
.resolution-grid {
  padding: 4px;
}

.resolution-grid button {
  font-size: 11px;
  font-weight: 700;
}

.pill-grid,
.count-grid {
  padding: 3px;
}

.template-row {
  grid-template-columns: minmax(0, 1fr) 56px;
  gap: 8px;
}

.apply-template {
  min-height: 31px;
  border-radius: 7px;
  font-size: 12px;
}

.advanced-box {
  margin: 4px 0 10px;
}

.advanced-box summary {
  padding: 8px;
  font-size: 12px;
}

.primary-action {
  min-height: 34px;
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(18, 24, 21, 0.42);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 20px 58px rgba(22, 34, 29, 0.24);
  padding: 18px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.modal-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.modal-close {
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

@media (max-width: 1320px) {
  .workspace {
    grid-template-columns: 280px minmax(0, 1fr) 380px;
  }
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .left-panel,
  .stage-panel,
  .right-panel {
    min-height: auto;
  }

  .task-list {
    max-height: 320px;
  }
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 10px;
  }

  .workspace {
    padding: 6px;
  }

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

  .topbar-actions,
  .stage-header,
  .section-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .task-meta,
  .advanced-grid,
  .split-controls {
    grid-template-columns: 1fr;
  }

  .cache-warning {
    font-size: 16px;
  }
}
