:root {
  color-scheme: light;
  --ink: #22211f;
  --muted: #706a63;
  --line: #ded8cf;
  --paper: #fbfaf7;
  --panel: #ffffff;
  --accent: #d44763;
  --accent-dark: #9e2941;
  --ok: #24705d;
  --warn: #a97628;
  --shadow: 0 18px 50px rgba(46, 38, 30, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  max-width: 1720px;
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.stage-header,
.section-title-row,
.source-bar,
.catalog-meta,
.action-row,
.top-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 16px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 6px;
  font-size: 24px;
}

h3 {
  margin-bottom: 12px;
  font-size: 18px;
}

.api-key-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.api-key-field span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.api-key-field input {
  width: min(360px, 34vw);
  min-height: 42px;
  border: 2px solid #ff5260;
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.save-key-button,
.primary-button,
.secondary-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 850;
}

.save-key-button,
.primary-button {
  background: var(--ink);
  color: #fff;
}

.save-key-button {
  min-height: 34px;
  background: var(--accent);
  padding: 0 12px;
  font-size: 13px;
}

.secondary-button,
.icon-button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 24px;
}

.step-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow: auto;
}

.step-tab {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 0 16px;
  font-weight: 850;
  white-space: nowrap;
}

.step-tab.is-active {
  border-color: var(--accent);
  background: #fff4f6;
  color: var(--accent-dark);
}

.stage {
  display: none;
  min-height: calc(100vh - 130px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.stage.is-active {
  display: block;
}

.stage-header {
  align-items: flex-start;
  margin-bottom: 18px;
}

.stage-header p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.selected-counter {
  min-width: 100px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  text-align: center;
  font-weight: 950;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field span,
.check-filter span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

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

.field input:focus,
.field select:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 71, 99, 0.18);
}

.source-url {
  flex: 1;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.catalog-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) minmax(180px, 0.7fr) auto auto minmax(220px, auto);
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.batch-image-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.batch-image-actions .secondary-button {
  white-space: nowrap;
}

.check-filter {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pager span,
#productCount,
#outfitSummary {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  padding-bottom: 78px;
}

.product-card,
.outfit-card,
.modal-item,
.result-card,
.style-option,
.background-option {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.product-card {
  position: relative;
  min-height: 300px;
  padding: 10px;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.product-card.is-selected {
  border-color: var(--accent);
  background: #fff4f6;
}

.select-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-weight: 950;
}

.product-card.is-selected .select-badge {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.product-image-wrap {
  position: relative;
}

.product-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  background: #f3f0eb;
  border: 1px solid var(--line);
  object-fit: cover;
}

.category-override {
  display: grid;
  gap: 4px;
  margin: 8px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.category-override select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0 10px;
  font: inherit;
  color: var(--ink);
}

.card-progress {
  position: absolute;
  inset: auto 8px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  padding: 8px;
  box-shadow: 0 8px 20px rgba(46, 38, 30, 0.12);
}

.card-progress .progress-track {
  height: 6px;
}

.card-progress p,
.product-error {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 850;
}

.product-error {
  color: var(--accent-dark);
  line-height: 1.4;
}

.product-title {
  margin: 10px 0 5px;
  font-weight: 950;
  line-height: 1.25;
}

.product-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.product-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.mini-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 850;
}

.sticky-action {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 0 0;
  background: linear-gradient(to top, var(--panel) 72%, rgba(255, 255, 255, 0));
}

.confirmed-strip {
  display: flex;
  gap: 8px;
  overflow: auto;
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.selected-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(212, 71, 99, 0.32);
  background: #fff4f6;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.selected-pill button {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.compose-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

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

.style-option {
  min-height: 74px;
  padding: 12px;
  text-align: left;
}

.style-option.is-active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.style-option strong {
  display: block;
  margin-bottom: 4px;
}

.style-option span {
  color: inherit;
  opacity: 0.72;
  font-size: 12px;
}

.settings-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.outfit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.outfit-card {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 10px;
  padding: 10px;
  min-width: 0;
}

.outfit-card img,
.modal-item img {
  width: 76px;
  height: 76px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #f3f0eb;
}

.outfit-card h4,
.modal-item h4 {
  margin: 0 0 5px;
  font-size: 14px;
}

.outfit-card p,
.modal-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.background-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.background-option {
  padding: 8px;
  text-align: left;
}

.background-option.is-active {
  border-color: var(--accent);
  background: #fff4f6;
}

.background-option img {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  object-fit: cover;
  background: #f3f0eb;
}

.background-option span {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 850;
}

.progress-panel {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffaf0;
}

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

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--warn));
  transition: width 0.3s ease;
}

.progress-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.result-card {
  padding: 10px;
}

.result-image {
  position: relative;
  aspect-ratio: 9 / 16;
  border-radius: 6px;
  overflow: hidden;
  background: #f3f0eb;
}

.result-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-badge,
.download-button {
  position: absolute;
  z-index: 2;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.result-badge {
  top: 10px;
  left: 10px;
  padding: 5px 8px;
}

.download-button {
  right: 10px;
  bottom: 10px;
  min-height: 34px;
  border: 1px solid var(--line);
  padding: 0 10px;
}

.result-card h3 {
  margin: 10px 0 6px;
  font-size: 15px;
}

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 18, 16, 0.45);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(760px, 100%);
  max-height: min(760px, 90vh);
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.modal-actions {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.modal-header h2 {
  margin: 0;
}

.modal-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding: 14px;
}

.modal-item {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
}

.preview-card {
  width: min(760px, 100%);
}

.preview-body {
  display: grid;
  grid-template-columns: minmax(260px, 480px) 1fr;
  gap: 16px;
  padding: 14px;
}

.preview-body img {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: min(62vh, 520px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f0eb;
  object-fit: contain;
}

.modal.is-result-preview .preview-card {
  width: min(760px, 100%);
}

.modal.is-result-preview .preview-body {
  grid-template-columns: minmax(240px, 420px) 1fr;
}

.modal.is-result-preview .preview-body img {
  aspect-ratio: 9 / 16;
  max-height: min(68vh, 620px);
}

.preview-body p {
  color: var(--muted);
  line-height: 1.55;
}

.inline-actions {
  padding: 0;
  border: 0;
  justify-content: flex-start;
}

.is-disabled {
  pointer-events: none;
  opacity: 0.55;
}

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .stage-header,
  .source-bar,
  .catalog-meta,
  .compose-layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .api-key-field {
    width: 100%;
  }

  .api-key-field input {
    width: 100%;
  }

  .catalog-toolbar {
    grid-template-columns: 1fr;
  }

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

  .product-card {
    min-height: 260px;
  }

  .style-picker {
    grid-template-columns: 1fr;
  }

  .action-row,
  .pager {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

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