:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #6b7785;
  --line: #e2e8f0;
  --accent: #0f766e;
  --accent-2: #c2410c;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #047857;
  --shadow: 0 10px 30px rgba(26, 35, 50, 0.08);
  --radius: 14px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9f3ef 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #ffe8d9 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  backdrop-filter: blur(10px);
  background: rgba(255,255,255,0.82);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 1.15rem;
  color: var(--accent);
}
.topbar nav { display: flex; gap: 8px; }
.topbar nav a {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
}
.topbar nav a.active,
.topbar nav a:hover {
  background: #e6f4f2;
  color: var(--accent);
}
.topbar nav a.nav-external {
  border: 1px solid #cce8e4;
  color: var(--accent);
}
.topbar nav a.nav-external:hover {
  background: #0f766e;
  color: #fff;
  border-color: #0f766e;
}
.topbar .nav-user {
  align-self: center;
  margin-left: 8px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 0.9rem;
}
.topbar nav a.nav-logout {
  color: var(--danger);
}
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 40px);
}
.login-card {
  width: min(420px, 100%);
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}
.form-error {
  color: var(--danger);
  background: #fee2e2;
  padding: 10px 12px;
  border-radius: 10px;
}

.container {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 60px;
}

.page-title {
  margin: 0 0 6px;
  font-size: 1.6rem;
}
.page-sub {
  margin: 0 0 20px;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 16px;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.86rem;
  color: var(--muted);
  font-weight: 600;
}
label.field input,
label.field select,
label.field textarea,
.input, .select, .textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
label.field textarea, .textarea { min-height: 84px; resize: vertical; }
label.field .req { color: var(--danger); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #edf2f7; color: var(--ink); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-warn { background: #ffedd5; color: var(--accent-2); }
.btn-sm { padding: 7px 10px; font-size: 0.85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.upload-zone {
  border: 1.5px dashed #9cc4bf;
  border-radius: 12px;
  padding: 22px;
  text-align: center;
  background: #f7fbfa;
  color: var(--muted);
  cursor: pointer;
}
.upload-zone.dragover { background: #e8f7f4; border-color: var(--accent); }

.image-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.image-list.ozon-edit {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.image-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdff;
  cursor: grab;
  position: relative;
  min-width: 0;
}
.image-card.dragging { opacity: 0.55; }
.image-card .handle {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.55);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.2;
  user-select: none;
}
.image-card .thumb-wrap {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #eee;
}
.image-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.image-card .meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.image-card .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}
.badge-size { color: #0369a1; }
.badge-detail { color: #7c3aed; }
.image-card textarea {
  width: 100%;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  resize: vertical;
}
.image-card .side {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.image-card .side .btn { flex: 1; min-width: 0; }
.check-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

/* 兼容旧类名（若有残留） */
.image-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdff;
}
.image-row img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  cursor: zoom-in;
}
.image-row .meta { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.image-row .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}
.image-row textarea {
  width: 100%;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
.image-row .side {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.image-row .handle { display: none; }

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.tab {
  padding: 8px 14px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font-weight: 700;
  border: none;
  cursor: pointer;
}
.tab.active {
  background: var(--accent);
  color: #fff;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.placeholder-tip {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: #f8fafc;
  border-radius: 12px;
  border: 1px dashed var(--line);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.result-grid .item {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  position: relative;
}
.result-grid .item .pick {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.92);
  font-size: 0.78rem;
  font-weight: 700;
}
.result-grid .item .gen-del {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  border: none;
  border-radius: 8px;
  padding: 4px 8px;
  background: rgba(254, 226, 226, 0.95);
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}
.result-grid .item.dragging {
  opacity: 0.5;
}
.result-grid .item .drag-hint {
  position: absolute;
  bottom: 36px;
  right: 8px;
  z-index: 2;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.55);
  color: #fff;
  font-size: 0.7rem;
}
.result-grid .item.picked {
  outline: 2px solid var(--accent);
}
.result-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}
/* 平台生成图：竖屏 3:4（宽:高） */
.result-grid.platform-generated {
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}
.result-grid.platform-generated img {
  aspect-ratio: 3 / 4;
  object-fit: cover;
}
.result-grid .cap {
  padding: 8px 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
}
table.data th, table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.92rem;
}
table.data th { color: var(--muted); font-weight: 700; }
table.data tr:hover td { background: #f8fafc; }
.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  background: #eee;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 50;
}
.toast.error { background: #7f1d1d; }
.toast.ok { background: #065f46; }
.toast.hidden { display: none; }
.hidden { display: none !important; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.78);
  cursor: zoom-out;
}
.lightbox.hidden { display: none !important; }
.lightbox img {
  max-width: min(96vw, 1400px);
  max-height: 92vh;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  background: #111;
  cursor: default;
}
.lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 999px;
  background: rgba(255,255,255,0.92);
  color: #0f172a;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  z-index: 101;
}
.result-grid img {
  cursor: zoom-in;
}

.muted { color: var(--muted); }
.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: #ecfdf5;
  color: var(--ok);
}
.loading-bar {
  height: 4px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}
.loading-bar > span {
  display: block;
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, var(--accent), #14b8a6);
  animation: slide 1.1s ease-in-out infinite;
}
.progress-box {
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid #99f6e4;
  background: #f0fdfa;
}
.progress-box .progress-title {
  font-weight: 700;
  color: var(--accent);
}
.image-row.retouching,
.image-card.retouching {
  outline: 2px solid var(--accent);
  background: #ecfdf5;
}
.btn.busy {
  opacity: 0.7;
  pointer-events: none;
}
@keyframes slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .image-list {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  }
  .image-list.ozon-edit {
    grid-template-columns: 1fr;
  }
}

.price-breakdown-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.86rem;
}
.price-breakdown-table th,
.price-breakdown-table td {
  border: 1px solid #e2e8ec;
  padding: 6px 10px;
  text-align: left;
}
.price-breakdown-table th {
  background: #f0f4f6;
  font-weight: 600;
}
.price-breakdown-table tr.row-total td {
  font-weight: 700;
  background: #fafcfd;
}
.price-breakdown-wrap {
  margin-top: 4px;
}
.margin-coeff-grid .field input[readonly] {
  background: #eef2f4;
}

.category-suggest-wrap {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed #d8e0e6;
}
.category-suggest-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.category-suggest-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: #334155;
}
.category-suggest-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.category-suggest-item {
  position: relative;
  padding: 10px 12px 12px;
  border: 2px solid #e2e8ec;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  min-height: 72px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.category-suggest-item:hover {
  border-color: #c4b5fd;
}
.category-suggest-item.selected {
  border-color: #7c3aed;
  box-shadow: 0 0 0 1px #7c3aed inset;
  background: #faf5ff;
}
.category-suggest-item .cat-path {
  font-size: 0.82rem;
  line-height: 1.45;
  color: #1e293b;
  word-break: break-word;
}
.category-suggest-item.selected .cat-path {
  color: #5b21b6;
  font-weight: 600;
}
.category-suggest-item .cat-reason {
  margin-top: 6px;
  font-size: 0.75rem;
  color: #64748b;
  line-height: 1.35;
}
.category-suggest-item .cat-check {
  position: absolute;
  right: 8px;
  bottom: 6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #7c3aed;
  color: #fff;
  font-size: 0.72rem;
  line-height: 18px;
  text-align: center;
  display: none;
}
.category-suggest-item.selected .cat-check {
  display: block;
}
.category-suggest-hint {
  margin: 8px 0 0 !important;
  font-size: 0.82rem;
}
@media (max-width: 900px) {
  .category-suggest-list {
    grid-template-columns: 1fr;
  }
}
