:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #dfe5ee;
  --line-strong: #c5cfdc;
  --text: #111827;
  --muted: #687386;
  --muted-strong: #4b5565;
  --accent: #e53935;
  --accent-dark: #b91f1c;
  --blue: #1757d7;
  --blue-soft: #edf4ff;
  --shadow: 0 18px 44px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #fbfcfe 0, var(--bg) 280px),
    var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1480px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 24px 0 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 -10px 18px;
  padding: 14px 10px 16px;
  background: rgba(251, 252, 254, 0.9);
  border-bottom: 1px solid rgba(223, 229, 238, 0.85);
  backdrop-filter: blur(18px);
}

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

h1,
h2,
p,
figure {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 3.5vw, 44px);
  line-height: 1;
  letter-spacing: 0;
}

.topbar-subtitle {
  max-width: 620px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.process-mode-note {
  max-width: 310px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.process-mode {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  min-height: 44px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.06);
}

.process-mode label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  border-radius: 6px;
  cursor: pointer;
}

.process-mode input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.process-mode span {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 34px;
  border-radius: 6px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.process-mode input:checked + span {
  background: var(--blue-soft);
  color: var(--blue);
  box-shadow: inset 0 0 0 1px rgba(23, 87, 215, 0.12);
}

.process-mode input:focus-visible + span {
  outline: 2px solid rgba(23, 87, 215, 0.35);
  outline-offset: 2px;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 420px) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.upload-panel,
.settings-panel {
  grid-column: 1;
}

.result-panel {
  position: sticky;
  top: 116px;
  grid-column: 2;
  grid-row: 1 / span 2;
  min-height: calc(100vh - 144px);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head-with-action {
  align-items: flex-start;
}

.panel-head-with-action > div {
  min-width: 0;
  flex: 1;
}

.panel-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.result-head {
  align-items: flex-start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.result-head > div {
  min-width: 0;
  flex: 1;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 900;
  font-size: 14px;
  flex: 0 0 auto;
}

.primary-button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 0 18px;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
  white-space: nowrap;
}

.primary-button::before {
  content: ">";
  margin-right: 8px;
  font-weight: 900;
}

.download-button::before {
  content: "v";
  margin-right: 8px;
  font-weight: 900;
}

.primary-button:hover,
.download-button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

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

.secondary-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted-strong);
  padding: 0 12px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.secondary-button:hover {
  border-color: var(--accent);
  background: #fff5f5;
  color: var(--accent);
}

.clear-products-button {
  flex: 0 0 auto;
}

.dropzone {
  display: grid;
  place-items: center;
  min-height: 190px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.72), rgba(248,250,252,0.9)),
    var(--surface-soft);
  cursor: pointer;
  text-align: center;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--blue);
  background: #f4f8ff;
  transform: translateY(-1px);
}

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

.dropzone-title {
  display: block;
  color: var(--text);
  font-size: 18px;
  font-weight: 900;
}

.dropzone-subtitle {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.file-list {
  display: grid;
  gap: 8px;
  max-height: 250px;
  overflow: auto;
  margin-top: 14px;
  padding-right: 4px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-soft);
}

.product-file-item img {
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  flex: 0 0 auto;
  object-fit: contain;
}

.file-meta {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.file-item strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field span {
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 900;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 87, 215, 0.12);
}

.color-field input[type="color"] {
  height: 42px;
  padding: 4px;
  cursor: pointer;
}

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

.template-preview-wrap {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  max-height: 280px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #eef2f7 25%, transparent 25%),
    linear-gradient(-45deg, #eef2f7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef2f7 75%),
    linear-gradient(-45deg, transparent 75%, #eef2f7 75%);
  background-color: #fff;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
  overflow: hidden;
}

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

.progress-panel {
  display: grid;
  gap: 10px;
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.progress-panel[hidden] {
  display: none;
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted-strong);
  font-size: 13px;
}

.vip-hint {
  flex: 1;
  color: var(--accent);
  font-weight: 800;
  text-align: right;
}

.progress-copy strong {
  color: var(--text);
  white-space: nowrap;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7edf5;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--accent));
  transition: width 220ms ease;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  min-height: calc(100vh - 246px);
  align-content: start;
  padding-top: 2px;
}

.preview-grid.empty {
  place-items: center;
  grid-template-columns: 1fr;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.78), rgba(248,250,252,0.92)),
    var(--surface-soft);
}

.preview-item {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.preview-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.filename-input {
  width: 100%;
  min-height: 36px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--text);
  outline: none;
}

.filename-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 87, 215, 0.12);
}

.download-button {
  flex: 0 0 auto;
}

.download-button.disabled {
  pointer-events: none;
  opacity: 0.45;
}

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

  .upload-panel,
  .settings-panel,
  .result-panel {
    grid-column: 1;
  }

  .result-panel {
    position: static;
    grid-row: auto;
    min-height: 520px;
  }

  .preview-grid {
    min-height: 360px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 1480px);
    padding: 14px 0 20px;
  }

  .topbar,
  .topbar-actions,
  .grid-2,
  .result-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    margin-bottom: 12px;
  }

  .process-mode {
    width: 100%;
  }

  .process-mode-note {
    max-width: none;
  }

  .panel {
    padding: 14px;
  }

  .primary-button,
  .download-button {
    width: 100%;
  }

  .preview-grid {
    grid-template-columns: 1fr;
  }

  .progress-copy {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .vip-hint {
    flex-basis: 100%;
    order: 3;
    text-align: left;
  }
}
