:root {
  color-scheme: light;
  --bg: #eef3f6;
  --bg-2: #f7fafb;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --panel-alt: #f5f8fa;
  --text: #18242c;
  --muted: #64727d;
  --faint: #96a1aa;
  --line: #dbe4e9;
  --line-strong: #c3d0d8;
  --accent: #08756f;
  --accent-2: #3468d7;
  --accent-3: #c85544;
  --accent-soft: #e0f3f0;
  --danger: #c23a3a;
  --warning: #946313;
  --success: #157347;
  --shadow-sm: 0 8px 22px rgba(24, 36, 44, 0.06);
  --shadow: 0 18px 50px rgba(24, 36, 44, 0.10);
  --radius: 8px;
  --radius-sm: 6px;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 1180px;
  background:
    linear-gradient(135deg, rgba(8, 117, 111, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(200, 85, 68, 0.10), transparent 28%),
    var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

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

.hidden {
  display: none !important;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  border-bottom: 1px solid rgba(195, 208, 216, 0.72);
  background: rgba(247, 250, 251, 0.86);
  backdrop-filter: blur(18px);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

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

.topbar-actions,
.section-title-row,
.button-group,
.inline-options,
.reference-row,
.prompt-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 0.72fr) minmax(500px, 1.48fr) minmax(330px, 0.95fr);
  gap: 14px;
  padding: 16px;
  align-items: start;
}

.panel {
  overflow: hidden;
  border: 1px solid rgba(195, 208, 216, 0.78);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.config-panel,
.library-panel {
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 104px);
  overflow: auto;
}

.config-panel,
.generator-panel,
.library-panel {
  backdrop-filter: blur(10px);
}

.generator-panel {
  padding: 18px;
  box-shadow: var(--shadow);
}

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

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

h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
}

h3 {
  font-size: 13px;
  color: var(--muted);
}

.section-title-row {
  justify-content: space-between;
  margin-bottom: 12px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

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

.field.compact {
  min-width: 160px;
  margin-bottom: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  outline: none;
  padding: 9px 10px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

textarea {
  min-height: 230px;
  resize: vertical;
  line-height: 1.58;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.secret-row {
  display: grid;
  grid-template-columns: 1fr 40px;
  gap: 8px;
}

.inline-options {
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.inline-options input {
  width: auto;
}

.size-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.validation {
  min-height: 20px;
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.validation.invalid {
  color: var(--danger);
}

.validation.valid {
  color: var(--success);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 10px;
  border: 1px solid rgba(8, 117, 111, 0.20);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  white-space: nowrap;
}

.pill.muted {
  border-color: var(--line);
  background: var(--panel-alt);
  color: var(--muted);
}

.small-button,
.ghost-button,
.full-button,
.generate-button,
.icon-button,
.upload-button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  transition: transform 0.12s, border-color 0.12s, color 0.12s, background 0.12s, box-shadow 0.12s;
}

.small-button {
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.42);
}

.full-button,
.generate-button {
  width: 100%;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(8, 117, 111, 0.18);
}

.full-button.secondary {
  border-color: #1d2b34;
  background: #1d2b34;
}

.generate-button {
  margin-top: 16px;
  min-height: 52px;
  font-size: 16px;
}

.small-button:hover,
.ghost-button:hover,
.icon-button:hover,
.upload-button:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 8px 20px rgba(24, 36, 44, 0.07);
}

.full-button:hover,
.generate-button:hover,
.small-button.primary:hover {
  transform: translateY(-1px);
}

.small-button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.danger {
  color: var(--danger);
}

.prompt-tools {
  margin-top: 12px;
  align-items: end;
}

.subsection {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

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

.batch-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(245, 248, 250, 0.92), rgba(255, 255, 255, 0.72));
}

.batch-textarea {
  min-height: 120px;
}

.batch-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.batch-list {
  max-height: 220px;
  overflow: auto;
}

.batch-item {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.batch-item p {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.batch-item code {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.reference-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
}

.task-recovery {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.upload-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

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

.image-list,
.result-grid,
.list-stack {
  display: grid;
  gap: 10px;
}

.image-list {
  margin-top: 12px;
}

.reference-item,
.list-card,
.result-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.76);
  padding: 10px;
}

.reference-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.reference-item img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: #e7eef2;
}

.reference-item code,
.list-card code {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.payload-preview,
.log-box {
  min-height: 164px;
  max-height: 260px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  border: 1px solid #263943;
  border-radius: var(--radius);
  background: #122029;
  color: #d8e4ea;
  font-family: Consolas, "SF Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.log-box {
  min-height: 126px;
  color: #c7d2d9;
}

.progress-track {
  height: 8px;
  margin-bottom: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #d9e3e9;
}

.progress-track div {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s ease;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
}

.tab {
  min-height: 44px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.tab:last-child {
  border-right: 0;
}

.tab.active {
  background: #fff;
  color: var(--accent);
  font-weight: 700;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.tab-panel {
  display: none;
  padding: 14px;
}

.tab-panel.active {
  display: block;
}

.library-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 12px;
}

.list-card h4,
.result-card h4 {
  margin: 0 0 6px;
  font-size: 13px;
}

.list-card p,
.result-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.task-id-line {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  margin: 0 0 10px;
  font-size: 12px;
}

.task-id-line span {
  color: var(--muted);
}

.task-id-line code {
  min-width: 0;
}

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

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

.result-card {
  background: #fff;
  box-shadow: 0 8px 20px rgba(24, 36, 44, 0.05);
}

.result-card img {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background:
    linear-gradient(45deg, #eef3f6 25%, transparent 25%),
    linear-gradient(-45deg, #eef3f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef3f6 75%),
    linear-gradient(-45deg, transparent 75%, #eef3f6 75%),
    #f8fafb;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.empty-state {
  min-height: 120px;
  align-items: center;
  justify-content: center;
  place-items: center;
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(245, 248, 250, 0.72);
  color: var(--faint);
  font-size: 13px;
  text-align: center;
}

.history-tools {
  margin-bottom: 12px;
}

.dialog {
  width: min(720px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(12, 18, 24, 0.38);
}

.dialog form {
  padding: 18px;
}

.dialog h2 {
  margin: 0 0 14px;
}

.dialog textarea {
  min-height: 180px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-actions .full-button {
  width: auto;
  min-width: 110px;
}

.admin-section {
  display: grid;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.admin-section:first-of-type {
  border-top: 0;
}

.admin-user-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 110px 120px;
  gap: 10px;
}

.image-preview-dialog {
  width: min(1080px, calc(100vw - 28px));
}

.image-preview-shell {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.image-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.image-preview-header h2 {
  margin: 0;
}

.image-preview-canvas {
  display: grid;
  min-height: min(70vh, 720px);
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, #eef3f6 25%, transparent 25%),
    linear-gradient(-45deg, #eef3f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef3f6 75%),
    linear-gradient(-45deg, transparent 75%, #eef3f6 75%),
    #f8fafb;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.image-preview-canvas img {
  display: block;
  max-width: 100%;
  max-height: 76vh;
  object-fit: contain;
}

.login-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(238, 243, 246, 0.86);
  backdrop-filter: blur(16px);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}

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

.login-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

@media (max-width: 1180px) {
  body {
    min-width: 1024px;
  }

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

  .library-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }

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

@media (max-width: 1080px) {
  body {
    min-width: 0;
  }

  .topbar,
  .workspace {
    padding-left: 12px;
    padding-right: 12px;
  }

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

  .workspace {
    display: grid;
    grid-template-columns: 1fr;
  }

  .config-panel,
  .library-panel {
    position: static;
    max-height: none;
  }

  .subsection.split,
  .prompt-tools,
  .reference-row,
  .admin-user-grid {
    grid-template-columns: 1fr;
  }
}
