:root {
  --brand: #2b6cb0;
  --brand-light: #ebf4ff;
  --danger: #c53030;
  --warning: #c05621;
  --success: #276749;
  --gray-50: #f0f4f8;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-bg: #1a202c;
  --sidebar-hover: #2d3748;
  --sidebar-text: #a0aec0;
  --sidebar-w: 220px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;
}

body {
  background: var(--gray-50);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--gray-900);
  -webkit-font-smoothing: antialiased;
}

body.auth-pending #sidebar,
body.auth-pending #main {
  visibility: hidden;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #f8fafc;
}

body.auth-pending .auth-gate {
  display: flex;
}

.auth-gate-panel {
  width: min(100%, 360px);
  padding: 28px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  background: white;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.12);
  text-align: center;
}

.auth-gate-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  background: var(--brand-light);
  color: var(--brand);
  font-size: 22px;
}

.auth-gate-panel h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}

.auth-gate-panel p {
  margin: 0 0 20px;
  color: var(--gray-600);
  font-size: 14px;
}

.invite-form {
  text-align: left;
}

.invite-form .form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
}

.req { color: var(--danger); font-weight: 600; margin-left: 2px; }

.flat-file-field-panel {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  background: #fff;
  overflow: hidden;
}

.flat-file-field-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 10px;
}

.flat-file-field-panel-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
}

.flat-file-field-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
}

.flat-file-field-item:last-child { border-bottom: none; }

.flat-file-field-item.priority-row {
  background: var(--brand-light);
}

.flat-file-field-item label {
  flex: 1;
  margin: 0;
  cursor: pointer;
}

.flat-file-field-item .field-meta {
  display: block;
  color: var(--gray-500);
  font-size: 11px;
  margin-top: 2px;
}

.flat-file-field-item code {
  font-size: 11px;
  color: var(--gray-600);
}

#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

#sidebar .brand {
  padding: 20px 16px 16px;
  color: white;
  font-size: 15px;
  font-weight: 700;
  background: var(--brand);
  border-bottom: 1px solid var(--gray-800);
}

#sidebar .brand small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  opacity: 0.7;
  margin-top: 2px;
}

.sidebar-section {
  padding: 12px 20px 4px;
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-600);
}

#sidebar .nav-link {
  color: var(--sidebar-text);
  padding: 11px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: 0.15s;
  text-decoration: none;
}

#sidebar .nav-link:hover {
  color: white;
  background: var(--sidebar-hover);
}

#sidebar .nav-link.active {
  color: white;
  border-left-color: var(--brand);
  background: var(--sidebar-hover);
}

#sidebar .nav-link i {
  font-size: 16px;
}

#main {
  margin-left: var(--sidebar-w);
  padding: 0;
  min-height: 100vh;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

/* 单 SKU 流程：步骤条（对齐原项目） */
.step-indicator {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  overflow: hidden;
}

.step-item {
  flex: 1;
  padding: 12px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--sidebar-text);
  border-right: 1px solid var(--gray-200);
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.step-item:last-child {
  border-right: none;
}

.step-item.active {
  background: var(--brand);
  color: white;
  font-weight: 600;
}

.step-item.completed {
  background: #f0fff4;
  color: var(--success);
}

.step-item .step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--gray-200);
  color: var(--gray-500);
}

.step-item.active .step-num {
  background: rgba(255, 255, 255, 0.3);
  color: white;
}

.step-item.completed .step-num {
  background: var(--success);
  color: white;
}

.workflow-step-panel {
  display: none;
}

.workflow-step-panel.active {
  display: block;
}

@media (max-width: 768px) {
  .step-indicator {
    flex-wrap: wrap;
  }

  .step-item {
    flex: 1 1 50%;
    border-bottom: 1px solid var(--gray-200);
  }

  .step-item:nth-last-child(-n + 2) {
    border-bottom: none;
  }
}

.topbar {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 12px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 99;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
}

.topbar h4 { margin: 0; font-size: 17px; font-weight: 600; color: var(--gray-800); }

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.auth-user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-user-email {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--gray-600);
  font-size: 13px;
}

.content-area {
  padding: 32px;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 768px) {
  :root {
    --sidebar-w: 200px;
  }
  #sidebar {
    width: 100%;
    height: auto;
    position: static;
  }
  #main {
    margin-left: 0;
  }
  .topbar {
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
  }
  .topbar-actions {
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
  }
  .auth-user-email {
    max-width: 180px;
  }
}

.config-section {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid var(--gray-200);
}

.config-section h3,
.ai-card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand);
  margin-bottom: 16px;
  border-bottom: 1px solid var(--gray-200);
  padding-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 18px;
  border: 2px solid transparent;
  background-image: linear-gradient(white, white),
    linear-gradient(135deg, #667eea, #764ba2);
  background-origin: border-box;
  background-clip: padding-box, border-box;
}

.ai-card .ai-icon {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.ai-card-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.ai-model-select {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
  background: white;
  min-width: 280px;
}

.ai-cost-est {
  font-size: 11px;
  color: #805ad5;
  background: #faf5ff;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.img-dropzone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: 0.2s;
  background: var(--gray-50);
  margin-top: 8px;
}

.img-dropzone:hover,
.img-dropzone.dragover {
  border-color: var(--brand);
  background: var(--brand-light);
}

.img-dropzone i { font-size: 28px; color: var(--sidebar-text); }

.img-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.img-preview-item {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--gray-200);
  background: var(--gray-50);
}

.img-preview-item img { width: 100%; height: 100%; object-fit: cover; }

.img-preview-item .img-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
}

.cost-badge {
  background: linear-gradient(135deg, #2b6cb0, #2c5282);
  color: white;
  border-radius: var(--radius-full);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border: none;
}

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  pointer-events: auto;
}

.results-panel {
  display: block;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 20px;
}

.results-panel .field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  margin-top: 12px;
  margin-bottom: 4px;
}

.results-panel .field-value {
  font-size: 13px;
  color: var(--gray-800);
  white-space: pre-wrap;
  line-height: 1.5;
}

.info-tip { color: var(--gray-500); cursor: help; font-size: 14px; }

.instructions-hero h3 { margin-bottom: 8px; }

.instructions-steps {
  padding-left: 1.25rem;
  line-height: 1.6;
}

.instructions-steps li { margin-bottom: 14px; }

.instructions-steps li:last-child { margin-bottom: 0; }

.instructions-card {
  height: 100%;
  padding: 14px 16px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  background: #fff;
}

.instructions-card h6 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}

.instructions-card ul {
  padding-left: 1.1rem;
  line-height: 1.55;
}

.instructions-actions {
  margin-top: 8px;
  padding: 4px 0 12px;
}

/* ---------- Stepwise single-SKU flow (listing_steps.js) ---------- */
.steprail {
  display: flex;
  margin-bottom: 20px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.steprail .s {
  flex: 1;
  padding: 12px 14px;
  font-size: 12px;
  color: var(--sidebar-text);
  display: flex;
  align-items: center;
  gap: 8px;
  border-right: 1px solid var(--gray-200);
}
.steprail .s:last-child { border-right: none; }
.steprail .s .n {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-500);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.steprail .s.active { color: var(--brand); font-weight: 600; background: var(--brand-light); }
.steprail .s.active .n { background: var(--brand); color: #fff; }
.steprail .s.done { color: var(--success); }
.steprail .s.done .n { background: var(--success); color: #fff; }

.field-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--gray-100);
}
.field-row:last-child { border-bottom: none; }
.field-key {
  width: 140px;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--gray-500);
  padding-top: 6px;
}
.field-key .req { color: var(--danger); }
.field-body { flex: 1; }
.ai-hint { font-size: 11px; color: var(--sidebar-text); margin-top: 5px; }
.ai-hint .bi { color: var(--brand); }

.chip {
  display: inline-block;
  padding: 4px 11px;
  border-radius: var(--radius-full);
  font-size: 12px;
  border: 1px solid var(--gray-300);
  background: #fff;
  cursor: pointer;
  margin: 0 5px 5px 0;
}
.chip.sel { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip.add { border-style: dashed; color: var(--gray-500); }

.badge-cat {
  background: var(--brand-light);
  color: var(--brand);
  border-radius: var(--radius-full);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
}
.badge-warn {
  background: #feebc8;
  color: var(--warning);
  border-radius: var(--radius-full);
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 700;
}

.ls-log { font-size: 12px; }
.ls-log .l { padding: 6px 0; display: flex; align-items: center; gap: 8px; color: var(--gray-500); }
.ls-log .l.ok { color: var(--success); }
.ls-log .l.run { color: var(--brand); font-weight: 600; }
.ls-log .l .bi { font-size: 14px; }

/* keyword coverage preview (copy review step) */
.ls-kw-coverage { border: 1px solid #e2e8f0; border-radius: 8px; background: #fbfdff; padding: 10px 14px; }
.ls-kw-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--gray-700, #334155); margin-bottom: 8px; }
.ls-kw-body { font-size: 13px; line-height: 1.7; color: #475569; }
.ls-kw-line { padding: 3px 0; }
.ls-kw-tag { display: inline-block; min-width: 44px; font-size: 11px; color: var(--gray-500); background: #eef2f7; border-radius: 4px; padding: 1px 6px; margin-right: 6px; }
.ls-kw-desc { display: inline-block; max-height: 120px; overflow: auto; vertical-align: top; }
.ls-kw-hit { color: #0b6; font-weight: 700; background: #e7f9f0; border-radius: 3px; padding: 0 2px; }
.ls-kw-unused { margin-top: 8px; padding-top: 8px; border-top: 1px dashed #e2e8f0; }
.ls-kw-chip { display: inline-block; font-size: 11px; color: var(--gray-500); background: #f1f5f9; border-radius: 10px; padding: 1px 8px; margin: 2px 3px 0 0; }

/* progressive copy preview during 'generating' status */
.ls-partial { margin: 8px 0 14px; padding: 12px 14px; background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; }
.ls-partial-block:not(:empty) { padding: 6px 0; border-bottom: 1px dashed #f0f4f8; }
.ls-partial-block:last-child { border-bottom: none; }
.ls-partial-label { font-size: 11px; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.ls-partial-val { font-size: 13px; color: var(--gray-700, #334155); }
.ls-partial-val.ls-desc { max-height: 180px; overflow: auto; }
.ls-partial-val ul, .ls-partial-val ol { margin: 0; padding-left: 18px; }

/* ---- flat-file preview grid (final step) ---- */
.ls-ff-grid { max-height: 460px; overflow: auto; border: 1px solid #e2e8f0; border-radius: 8px; background: #fff; }
.ls-ff-table { border-collapse: separate; border-spacing: 0; font-size: 12px; white-space: nowrap; }
.ls-ff-table th, .ls-ff-table td { border-bottom: 1px solid #f0f4f8; border-right: 1px solid #f0f4f8; padding: 2px 4px; }
.ls-ff-table thead th { position: sticky; top: 0; z-index: 2; background: #2d3748; color: #fff; font-weight: 600; padding: 6px 8px; }
.ls-ff-rowhdr { position: sticky; left: 0; z-index: 1; background: #f7fafc; font-weight: 600; color: #4a5568; }
.ls-ff-table thead th.ls-ff-rowhdr { z-index: 3; background: #1a202c; }
.ls-ff-req { color: #fc8181; }
.ls-ff-cell { border: 1px solid transparent; background: transparent; font-size: 12px; min-width: 120px; max-width: 240px; padding: 2px 4px; }
.ls-ff-cell:focus { border-color: var(--brand); outline: none; background: var(--brand-light); }
.ls-ff-select { min-width: 130px; }
.ls-ff-edited { background: #fefcbf; border-color: #ecc94b; }

/* clickable step-rail nodes (back navigation to a reached step) */
.steprail .s.ls-rail-clickable { cursor: pointer; }
.steprail .s.ls-rail-clickable:hover { background: var(--brand-light); }

/* flagged columns (product-specific, double-check needed) — make them stand out */
.ls-ff-table thead th.ls-ff-flagged-head { background: #c05621; }    /* darker amber on dark header */
.ls-ff-table tbody td.ls-ff-flagged-cell { background: #fff9e6; }    /* subtle amber wash on cells */
.ls-ff-table tbody td.ls-ff-flagged-cell .ls-ff-cell:focus { background: #fffbeb; }

/* ---- image-gen grid (step ⑤) ---- */
.ls-img-variant { background:#fff; border:1px solid #e2e8f0; border-radius:10px; padding:12px 14px; margin-bottom:14px; }
.ls-img-variant-head { font-size:13px; color:#2d3748; margin-bottom:8px; }
.ls-img-row { display:grid; grid-template-columns:repeat(auto-fill, minmax(160px, 1fr)); gap:10px; }
.ls-img-card { border:1px solid #e2e8f0; border-radius:8px; padding:8px; background:#fff; transition:.15s; }
.ls-img-card.ls-img-sel { border-color: var(--brand); background: var(--brand-light); }
.ls-img-thumb { width:100%; aspect-ratio:1/1; background:#f7fafc; border-radius:6px; overflow:hidden; display:flex; align-items:center; justify-content:center; }
.ls-img-thumb img { width:100%; height:100%; object-fit:contain; }
.ls-img-meta { font-size:12px; color:#4a5568; margin-top:6px; }
.ls-img-meta label { font-size:12px; cursor:pointer; }
.ls-img-reason { margin-top:2px; }
