:root {
  --bg: #fff;
  --ink: #242424;
  --muted: #6f6f78;
  --soft: #f5f5f6;
  --line: #e8e8ea;
  --line-strong: #d7d7dc;
  --green: #22c55e;
  --red: #e5252a;
  --shadow: 0 18px 34px rgba(0, 0, 0, .06);
  --radius: 26px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

body.dark {
  --bg: #111113;
  --ink: #f4f4f5;
  --muted: #b8b8c0;
  --soft: #1f1f23;
  --line: #2a2a2e;
  --line-strong: #3a3a40;
  --shadow: 0 18px 34px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  font-weight: 400;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; border: 0; color: inherit; background: transparent; }
input, textarea, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}
textarea { min-height: 92px; resize: vertical; }
label { display: grid; gap: 7px; color: #777780; font-size: 13px; font-weight: 560; }
body.dark label { color: #b8b8c0; }
h1, h2, h3, p { margin: 0; letter-spacing: 0; }
h1 { font-size: 27px; line-height: 1.1; font-weight: 650; }
h2 { font-size: 26px; font-weight: 650; }
h3 { font-size: 18px; font-weight: 620; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
th { color: var(--muted); font-weight: 580; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.page { width: min(1640px, calc(100vw - 160px)); margin: 0 auto; padding: 34px 0 64px; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 30px;
}

.login-card {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 30px;
  padding: 34px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 20px;
}

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

.apply-box {
  border-top: 1px solid var(--line);
  padding-top: 18px;
  display: grid;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  width: auto;
  height: 54px;
  display: block;
  opacity: .9;
}

.brand-row p { color: var(--muted); font-weight: 460; margin-top: 6px; }

.user-block {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.user-block span {
  color: var(--muted);
  font-weight: 520;
}

.tabs {
  display: flex;
  gap: 28px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 58px;
  overflow-x: auto;
}

.tabs button {
  padding: 0 0 13px;
  color: #8b8b95;
  font-size: 17px;
  font-weight: 480;
  white-space: nowrap;
  position: relative;
}

.tabs button.active { color: var(--ink); }
.tabs button.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 99px;
  background: var(--ink);
}

.section { display: none; }
.section.active { display: block; }
.section-head { margin-bottom: 26px; }
.section-head p { margin-top: 8px; color: var(--muted); font-size: 17px; }

.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}

.card-title {
  display: block;
  color: #9b9ba3;
  font-size: 16px;
  font-weight: 560;
  margin-bottom: 12px;
}

.big {
  display: block;
  font-size: 38px;
  font-weight: 640;
  line-height: 1;
  margin-bottom: 20px;
}

.progress {
  height: 14px;
  border-radius: 99px;
  background: var(--soft);
  overflow: hidden;
  margin-bottom: 14px;
}

.progress i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--green);
}

.quota-grid, .two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  margin-bottom: 22px;
}

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

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

.product-card {
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.product-card h3 {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.product-card.is-collapsed .collapsible-body {
  display: none;
}

.collapse-toggle {
  border: 0;
}

.fields {
  display: grid;
  gap: 11px;
}

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

.main-fields label:has(textarea),
.skc-fields label:has(textarea) {
  grid-column: 1 / -1;
}

.product-card textarea {
  min-height: 68px;
}

.reference-rule {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--soft);
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}

.reference-rule strong {
  font-size: 13px;
  font-weight: 620;
}

.reference-rule p,
.field-note {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

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

.drop-zone {
  min-height: 66px;
  border: 1px dashed #d1d1d6;
  border-radius: 16px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 10px;
  background: #fbfbfc;
  color: #85858f;
  cursor: pointer;
}

body.dark .drop-zone {
  background: #17171a;
  border-color: var(--line-strong);
}

.drop-zone input {
  display: none;
}

.drop-zone span {
  display: grid;
  gap: 4px;
}

.drop-zone small {
  color: #aaaab2;
  font-size: 11px;
  font-weight: 420;
}

.drop-zone.is-dragover {
  border-color: var(--ink);
  background: var(--soft);
  color: var(--ink);
}

.drop-zone.is-filled {
  border-style: solid;
  border-color: #c8c8ce;
  background:
    linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,.84)),
    linear-gradient(135deg, #eaf8ef, #f4f4f5);
  color: var(--ink);
}

body.dark .drop-zone.is-filled {
  background: #202024;
}

.reference-zone {
  min-height: 74px;
}

.logo-zone {
  min-height: 60px;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 99px;
  padding: 5px 9px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
}

.black-btn, .ghost-btn, .icon-btn {
  min-height: 40px;
  border-radius: 99px;
  padding: 9px 16px;
  font-weight: 560;
}

.black-btn {
  color: #fff;
  background: #0b0b0c;
}

body.dark .black-btn {
  color: #111113;
  background: #f4f4f5;
}

.ghost-btn, .icon-btn {
  border: 1px solid var(--line-strong);
  background: var(--bg);
}

.icon-btn {
  width: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.material-panel {
  display: grid;
  gap: 16px;
  max-height: 980px;
}

.mini-upload {
  display: grid;
  gap: 10px;
}

.material-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-content: start;
  overflow: auto;
  max-height: 720px;
}

.material-item, .image-tile, .result-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bg);
  padding: 10px;
  text-align: left;
  display: grid;
  gap: 8px;
}

.material-item:hover, .image-tile:hover {
  border-color: var(--line-strong);
  background: var(--soft);
}

.thumb {
  aspect-ratio: 1.05;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #55555c;
  font-weight: 640;
  background:
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.9)),
    linear-gradient(135deg, #e8f7ef, #eff2ff 58%, #fff5db);
}

body.dark .thumb {
  background: linear-gradient(135deg, #27372d, #222638 58%, #393323);
  color: #d4d4d8;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.image-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.image-tile.selected {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.image-tile {
  cursor: pointer;
}

.image-tile strong, .material-item strong {
  font-size: 13px;
}

.image-tile p, .material-item p, .result-card p {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

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

.stars {
  display: inline-flex;
  gap: 1px;
}

.star-btn {
  padding: 0;
  min-width: 16px;
  color: #c7c7ce;
  font-size: 15px;
  line-height: 1;
}

.star-btn.active {
  color: #111113;
}

body.dark .star-btn.active {
  color: #f4f4f5;
}

.mark-btn {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 520;
}

.mark-btn.active {
  border-color: var(--ink);
  color: var(--ink);
}

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

.table-wrap { overflow: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  border-radius: 99px;
  background: #111113;
  color: #fff;
  padding: 12px 18px;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  box-shadow: var(--shadow);
}

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

.modal-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--bg);
  box-shadow: var(--shadow);
  padding: 24px;
}

.filter-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.filter-row select, .filter-row input {
  min-width: 140px;
  max-width: 220px;
}

.prompt-audit {
  background: var(--soft);
  padding: 10px;
  border-radius: 12px;
  margin: 8px 0;
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid var(--line);
}

.prompt-audit small {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.prompt-audit p {
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink);
  white-space: pre-wrap;
}

.admin-stats-grid .big {
  color: var(--ink);
}

.admin-stats-grid article:nth-child(2) .big {
  color: var(--green);
}

@media (max-width: 1100px) {
  .page { width: min(100% - 32px, 980px); }
  .topbar, .generate-layout, .quota-grid, .two-col { grid-template-columns: 1fr; }
  .topbar { display: grid; }
  .product-grid, .image-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .login-grid, .product-grid, .material-grid, .image-grid, .image-grid.compact { grid-template-columns: 1fr; }
  .page { width: min(100% - 24px, 560px); padding-top: 20px; }
}
