:root {
  color-scheme: light;
  --app-bg: #f5f7f8;
  --surface: #ffffff;
  --surface-subtle: #f8fafb;
  --surface-strong: #eef2f4;
  --line: #dce2e6;
  --line-strong: #c9d1d7;
  --text: #17212b;
  --muted: #677480;
  --faint: #8e99a3;
  --accent: #168565;
  --accent-hover: #116c52;
  --accent-soft: #e8f4ef;
  --accent-line: #b9ddcf;
  --danger: #c43d4b;
  --danger-soft: #fbecee;
  --warning: #9a6820;
  --warning-soft: #fff4df;
  --info: #356c9b;
  --info-soft: #eaf2f8;
  font-family: Inter, "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  min-width: 980px;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--app-bg);
  font-size: 14px;
}

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

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(22, 133, 101, 0.16);
  outline-offset: 1px;
}

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

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon,
.upload-icon,
.empty-icon {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon {
  width: 18px;
  height: 18px;
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: flex;
  width: 100%;
  height: 100vh;
  min-height: 620px;
  flex-direction: column;
}

.app-header {
  display: flex;
  height: 56px;
  flex: 0 0 56px;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.is-embedded .app-header {
  padding-right: 162px;
}

.brand-lockup,
.header-actions,
.connection-button,
.task-heading,
.task-toolbar,
.expiry-note,
.task-card-head,
.task-title-wrap,
.task-actions,
.dialog-actions {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  color: var(--accent);
  background: var(--accent-soft);
}

.brand-mark .icon {
  width: 17px;
  height: 17px;
}

.brand-copy {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.brand-copy h1 {
  margin-bottom: 0;
  font-size: 16px;
  font-weight: 700;
}

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

.header-actions {
  gap: 8px;
}

.connection-button {
  height: 34px;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
}

.connection-button:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--danger);
}

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

.icon-button,
.key-toggle,
.preview-remove {
  display: inline-grid;
  place-items: center;
  border: 0;
  color: var(--muted);
  background: transparent;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 5px;
}

.icon-button:hover,
.key-toggle:hover,
.preview-remove:hover {
  color: var(--text);
  background: var(--surface-strong);
}

.workspace {
  display: grid;
  min-height: 0;
  flex: 1 1 auto;
  grid-template-columns: 390px minmax(0, 1fr);
}

.composer-pane {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
}

.mode-tab {
  height: 36px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-weight: 600;
}

.mode-tab:hover {
  color: var(--text);
}

.mode-tab.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(23, 33, 43, 0.08);
}

.image-field {
  margin-top: 20px;
}

.prompt-field {
  display: flex;
  min-height: 260px;
  flex: 1 0 260px;
  flex-direction: column;
  margin-top: 20px;
}

.prompt-field textarea {
  min-height: 224px;
  flex: 1 1 auto;
}

.field-heading,
.size-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field-heading > span {
  color: var(--faint);
  font-size: 11px;
}

.field-label {
  display: block;
  margin: 0 0 8px;
  color: #35414c;
  font-size: 12px;
  font-weight: 700;
}

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

textarea {
  min-height: 224px;
  padding: 12px 13px;
  resize: vertical;
  line-height: 1.65;
}

textarea::placeholder,
input::placeholder {
  color: #a0a9b1;
}

textarea:focus,
input:focus {
  border-color: var(--accent);
}

input {
  height: 42px;
  padding: 0 12px;
}

.upload-zone {
  display: flex;
  min-height: 112px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-subtle);
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-icon {
  width: 22px;
  height: 22px;
  margin-bottom: 2px;
  color: var(--accent);
}

.upload-zone strong {
  color: var(--text);
  font-size: 13px;
}

.upload-zone span {
  color: var(--faint);
  font-size: 11px;
}

.source-preview-frame {
  position: relative;
  height: 150px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
}

.source-preview {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.preview-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(201, 209, 215, 0.85);
  border-radius: 5px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
}

.field-hint {
  min-height: 17px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.composer-footer {
  padding-top: 18px;
}

.size-row .field-label {
  margin-bottom: 0;
}

.size-switch {
  display: grid;
  width: 204px;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
}

.size-option {
  height: 34px;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
}

.size-option:last-child {
  border-right: 0;
}

.size-option:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

.size-option.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.primary-button,
.secondary-button,
.download-button {
  display: inline-flex;
  height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 700;
  text-decoration: none;
}

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

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

.primary-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.secondary-button {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface);
}

.secondary-button:hover {
  background: var(--surface-strong);
}

.submit-button {
  width: 100%;
  height: 44px;
  margin-top: 16px;
}

.task-pane {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--app-bg);
}

.task-header {
  display: grid;
  min-height: 64px;
  flex: 0 0 auto;
  align-items: center;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 24px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.task-heading {
  gap: 9px;
}

.task-heading h2 {
  margin-bottom: 0;
  font-size: 17px;
}

.task-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.task-filters {
  display: flex;
  height: 32px;
  align-items: stretch;
  gap: 3px;
}

.task-filter {
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.task-filter:hover {
  color: var(--text);
  background: var(--surface-strong);
}

.task-filter.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.task-toolbar {
  min-width: 0;
  justify-content: flex-end;
  gap: 12px;
}

.expiry-note {
  min-width: 0;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.expiry-note .icon {
  width: 15px;
  height: 15px;
}

.concurrency-label {
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.task-grid {
  display: grid;
  min-height: 0;
  flex: 1 1 auto;
  align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  grid-auto-rows: max-content;
  gap: 14px;
  overflow-y: auto;
  padding: 20px;
}

.empty-state {
  display: grid;
  min-height: 420px;
  place-content: center;
  grid-column: 1 / -1;
  justify-items: center;
  color: var(--faint);
}

.empty-icon {
  width: 32px;
  height: 32px;
  margin-bottom: 10px;
  stroke-width: 1.5;
}

.empty-state p {
  margin-bottom: 0;
  font-size: 13px;
}

.task-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  transition: border-color 120ms ease;
}

.task-card:hover {
  border-color: var(--line-strong);
}

.task-preview {
  position: relative;
  display: grid;
  aspect-ratio: 1 / 1;
  place-items: center;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.task-placeholder {
  display: grid;
  place-items: center;
  color: #a5afb7;
}

.task-placeholder .icon {
  width: 30px;
  height: 30px;
  stroke-width: 1.5;
}

.task-card.is-running .task-placeholder .icon {
  color: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

.task-card.is-failed .task-preview {
  color: var(--danger);
  background: var(--danger-soft);
}

.task-card.is-failed .task-placeholder {
  color: var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1); }
}

.task-image {
  position: absolute;
  inset: 0;
}

.task-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #f1f4f5;
}

.task-card-body {
  display: flex;
  min-height: 164px;
  flex-direction: column;
  padding: 13px;
}

.task-card-head {
  justify-content: space-between;
  gap: 10px;
}

.task-title-wrap {
  min-width: 0;
  gap: 7px;
}

.task-number {
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-size,
.task-mode {
  flex: 0 0 auto;
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
}

.task-size {
  color: var(--accent);
  background: var(--accent-soft);
}

.task-mode {
  color: var(--info);
  background: var(--info-soft);
}

.badge {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.badge::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  content: "";
}

.badge.waiting::before {
  background: var(--warning);
}

.badge.submitting::before,
.badge.processing::before {
  background: var(--info);
}

.badge.completed::before {
  background: var(--accent);
}

.badge.failed::before {
  background: var(--danger);
}

.task-prompt {
  display: -webkit-box;
  min-height: 39px;
  margin: 11px 0 0;
  overflow: hidden;
  color: #33404b;
  font-size: 12px;
  line-height: 1.6;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.task-message {
  min-height: 17px;
  margin: 8px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.task-card.is-failed .task-message {
  color: var(--danger);
}

.progress {
  height: 3px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 3px;
  background: #e5eaed;
}

.progress span {
  display: block;
  width: 38%;
  height: 100%;
  border-radius: inherit;
  background: var(--info);
  animation: progress 1.4s ease-in-out infinite;
}

@keyframes progress {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

.task-actions {
  min-height: 34px;
  margin-top: auto;
  padding-top: 11px;
  gap: 8px;
}

.download-button,
.task-actions .secondary-button {
  height: 32px;
  padding: 0 10px;
  font-size: 11px;
}

.download-button {
  color: #ffffff;
  background: var(--accent);
}

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

dialog {
  width: 440px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(23, 33, 43, 0.18);
}

dialog::backdrop {
  background: rgba(23, 33, 43, 0.42);
}

.settings-form {
  padding: 22px;
}

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

.dialog-header h2 {
  margin-bottom: 4px;
  font-size: 17px;
}

.dialog-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
}

.close-button {
  margin: -5px -5px 0 0;
}

.settings-form > .field-label {
  margin-top: 16px;
}

.fixed-input:disabled {
  cursor: not-allowed;
  color: var(--muted);
  border-color: var(--line);
  background: var(--surface-strong);
  opacity: 1;
}

.key-field {
  position: relative;
}

.key-field input {
  padding-right: 42px;
}

.key-toggle {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 34px;
  height: 34px;
  border-radius: 5px;
}

.form-message {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 12px;
}

.dialog-actions {
  justify-content: flex-end;
  gap: 9px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.dialog-actions .primary-button,
.dialog-actions .secondary-button {
  min-width: 78px;
}
