:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #111827;
  --muted: #64748b;
  --line: #d7dee8;
  --blue: #2563eb;
  --blue-strong: #1d4ed8;
  --teal: #0f766e;
  --amber: #b45309;
  --red: #b91c1c;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.10);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

body {
  overflow-y: auto;
  min-height: 100vh;
}

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

.app-shell {
  width: min(1880px, calc(100vw - 36px));
  margin: 0 auto;
  padding: 18px 0 30px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
  padding: 8px 0 14px;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

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

.top-actions,
.action-row,
.status-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(620px, 1.08fr) minmax(520px, 0.92fr) minmax(300px, 0.44fr);
  gap: 18px;
  align-items: start;
}

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

.composer,
.status-panel,
.history-panel {
  padding: 20px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title.compact {
  margin-top: 22px;
}

.section-title h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.section-title span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

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

.field-grid.two {
  grid-template-columns: minmax(240px, 1fr) minmax(190px, 0.58fr);
}

.field-grid.four {
  grid-template-columns: repeat(4, minmax(120px, 1fr));
}

.settings-grid {
  grid-template-columns: repeat(4, minmax(128px, 1fr));
}

.field.wide {
  grid-column: span 2;
}

.field {
  display: grid;
  gap: 7px;
}

.field > span {
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

textarea {
  min-height: 178px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

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

.icon-button,
.ghost-button,
.secondary-button,
.primary-button {
  border-radius: 6px;
  border: 1px solid var(--line);
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.icon-button {
  padding: 0;
  background: var(--panel-2);
  color: var(--muted);
}

.ghost-button,
.secondary-button {
  background: #fff;
  color: #334155;
}

.primary-button {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--blue-strong);
  border-color: var(--blue-strong);
}

.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

button:disabled,
.disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.source-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.72fr) minmax(360px, 1fr);
  gap: 12px;
}

.privacy-note,
.source-help {
  border: 1px solid #c7d2fe;
  background: #eef6ff;
  border-radius: 8px;
  padding: 11px 12px;
  color: #1e3a8a;
}

.privacy-note {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.5;
}

.privacy-note strong,
.source-help strong {
  color: #0f172a;
}

.source-help {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
  background: #f8fbff;
}

.source-help div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.source-help span {
  color: #475569;
  font-size: 12px;
  line-height: 1.45;
}

.upload-box {
  min-height: 252px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  background: #f8fafc;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  padding: 18px;
  cursor: pointer;
}

.upload-box:hover,
.upload-box.dragging {
  border-color: var(--blue);
  background: #eff6ff;
}

.upload-box input {
  display: none;
}

.upload-box strong {
  font-size: 18px;
}

.upload-box span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.text-source {
  min-width: 0;
}

.action-row {
  margin-top: 18px;
  justify-content: flex-end;
}

#submitJob {
  min-width: 148px;
}

#formError {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
  max-width: 360px;
}

.progress-block {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #334155;
  font-size: 14px;
}

.progress-track {
  height: 10px;
  margin-top: 12px;
  background: #dbe4ef;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--teal), var(--blue), var(--amber));
  transition: width 180ms ease;
}

.error-box {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: var(--red);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.status-actions {
  margin: 14px 0;
}

.download-button {
  min-width: 112px;
}

.preview-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  height: clamp(300px, 42vh, 470px);
  overflow: auto;
  padding-right: 4px;
  align-content: start;
  scrollbar-gutter: stable;
}

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

.preview-card.pending {
  background: #f8fafc;
}

.preview-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #e2e8f0;
}

.preview-pending {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, #eef2f7, #e2e8f0);
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
}

.preview-card span {
  display: block;
  padding: 7px 9px;
  color: var(--muted);
  font-size: 12px;
}

.log-box {
  margin-top: 14px;
  min-height: 160px;
  max-height: 270px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  padding: 10px;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.log-line {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
}

.log-time {
  color: #93c5fd;
}

.empty-state {
  color: #94a3b8;
  font-family: "Microsoft YaHei", Arial, sans-serif;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 180px);
  overflow: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-2);
  display: grid;
  gap: 8px;
  cursor: pointer;
}

.history-item:hover,
.history-item.active {
  border-color: var(--blue);
  background: #eff6ff;
}

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

.history-id {
  color: #334155;
  font-weight: 800;
  font-size: 13px;
}

.status-pill {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  background: #e2e8f0;
  color: #334155;
}

.status-pill.completed {
  background: #dcfce7;
  color: #166534;
}

.status-pill.failed,
.status-pill.cancelled {
  background: #fee2e2;
  color: #991b1b;
}

.status-pill.planning,
.status-pill.generating,
.status-pill.exporting,
.status-pill.converting,
.status-pill.checking,
.status-pill.preparing,
.status-pill.queued {
  background: #dbeafe;
  color: #1d4ed8;
}

.history-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 1fr 0.82fr;
  }

  .history-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100vw - 18px, 720px);
    padding-top: 10px;
  }

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

  .section-title span {
    text-align: left;
  }

  .workspace,
  .field-grid.two,
  .field-grid.four,
  .settings-grid,
  .source-grid {
    grid-template-columns: 1fr;
  }

  .source-help,
  .privacy-note {
    grid-template-columns: 1fr;
  }

  .field.wide {
    grid-column: auto;
  }

  .preview-strip {
    grid-template-columns: 1fr;
    height: clamp(280px, 48vh, 520px);
  }
}
