:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1d2f45;
  --muted: #68788d;
  --line: #dbe4f0;
  --accent: #0f6c86;
  --accent-soft: #e6f4f7;
  --gold: #b98a33;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 420px at 6% -8%, rgba(205, 241, 238, 0.95) 0%, transparent 58%),
    radial-gradient(840px 340px at 94% -4%, rgba(250, 236, 205, 0.88) 0%, transparent 55%),
    linear-gradient(180deg, #eef2f9 0%, var(--bg) 34%, #f9fbff 100%);
}

body.modal-open {
  overflow: hidden;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.app-header h1 {
  margin: 0;
  font-size: 28px;
}

.app-header p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.search-panel {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.search-hero {
  margin-top: 18px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(234, 247, 246, 0.98) 0%, rgba(251, 246, 235, 0.98) 52%, rgba(255, 255, 255, 0.98) 100%);
  border: 1px solid #d7e5eb;
  border-radius: 24px;
  padding: 18px;
  box-shadow:
    0 20px 46px rgba(27, 42, 65, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.search-hero::before {
  content: "";
  position: absolute;
  top: -42px;
  right: -36px;
  width: 180px;
  height: 180px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.6), transparent 68%);
  pointer-events: none;
}

.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.hero-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1;
}

.hero-title-wrap {
  flex: 1;
  min-width: 0;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.hero-logo-wrap {
  width: 88px;
  height: 88px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid #d8e3ea;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 12px 24px rgba(17, 79, 104, 0.08);
}

.hero-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.hero-logo-fallback {
  display: none;
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: linear-gradient(145deg, #70b2bb 0%, #b98a33 100%);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
}

.hero-title-wrap h2 {
  margin: 0;
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: 0.3px;
  color: #114f68;
}

.hero-title-wrap p {
  margin: 8px 0 0;
  color: #587285;
  font-size: 13px;
  line-height: 1.5;
  max-width: 540px;
}

.search-panel-strong {
  margin-top: 14px;
  border: 1px solid rgba(137, 188, 199, 0.7);
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(8px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.search-input-hero {
  border-width: 1px;
  border-color: #b9d5dc;
  min-height: 52px;
  font-size: 16px;
  padding-left: 16px;
  padding-right: 16px;
  background: rgba(255, 255, 255, 0.96);
}

.search-input-hero:focus {
  border-color: #0f8ca8;
  box-shadow: 0 0 0 4px rgba(15, 140, 168, 0.12);
}

.source-panel {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.source-panel h2 {
  margin: 0;
  font-size: 18px;
}

.source-tip {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.quick-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.advanced-panel {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.source-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.source-item {
  min-width: 0;
}

.file-input-hidden {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 140px;
}

.selected-file-name {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
}

.url-row {
  display: flex;
  gap: 8px;
}

.btn {
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  min-height: 42px;
  padding: 0 14px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 700;
  box-shadow: 0 10px 18px rgba(15, 108, 134, 0.12);
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

.btn:hover {
  opacity: 0.97;
  transform: translateY(-1px);
  box-shadow: 0 14px 22px rgba(15, 108, 134, 0.16);
}

.btn-light {
  background: #fff;
  color: var(--accent);
  border-color: #c9dbe4;
  box-shadow: 0 8px 16px rgba(28, 59, 82, 0.06);
}

.love-btn {
  background: linear-gradient(135deg, #ff4f87 0%, #ff7a59 100%);
  border: none;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  min-height: 48px;
  padding: 0 20px;
  box-shadow: 0 10px 24px rgba(255, 79, 135, 0.25);
}

.love-btn:hover {
  opacity: 1;
  transform: translateY(-1px);
}

.source-actions {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.source-status-wrap {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-status {
  display: inline-flex;
  align-items: center;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid #d8e4ee;
  background: rgba(255, 255, 255, 0.92);
  color: #476177;
  font-size: 12px;
  line-height: 1.2;
  box-shadow: 0 6px 12px rgba(20, 42, 63, 0.04);
}

#syncNgpStatus:empty {
  display: none;
}

.search-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 15px;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 102, 255, 0.12);
}

.feedback {
  margin-top: 16px;
  color: #63758a;
  font-size: 14px;
  padding-left: 4px;
}

.result-section {
  margin-top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 16px 36px rgba(20, 42, 63, 0.07);
}

.table-wrap {
  overflow-x: auto;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(250,252,255,0.96));
}

table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  white-space: normal;
  word-break: break-word;
  vertical-align: top;
}

th {
  background: #f3f6fb;
  font-weight: 600;
  color: #596d83;
  font-size: 12px;
  letter-spacing: 0.2px;
}

tr:hover td {
  background: #fbfdff;
}

/* 列宽：图片/产品名/规格/外包装/容量/价格/51码/箱规/库存/复制 */
th:nth-child(1), td:nth-child(1) { width: 15%; }
th:nth-child(2), td:nth-child(2) { width: 15%; }
th:nth-child(3), td:nth-child(3) { width: 16%; }
th:nth-child(4), td:nth-child(4) { width: 7%; }
th:nth-child(5), td:nth-child(5) { width: 7%; }
th:nth-child(6), td:nth-child(6) { width: 8%; }
th:nth-child(7), td:nth-child(7) { width: 11%; }
th:nth-child(8), td:nth-child(8) { width: 7%; text-align: center; }
th:nth-child(9), td:nth-child(9) { width: 9%; text-align: center; }
th:nth-child(10), td:nth-child(10) { width: 10%; text-align: center; }

.image-cell {
  vertical-align: middle;
  background: linear-gradient(180deg, #fcfdff 0%, #f8fbff 100%);
}

.image-card {
  display: grid;
  gap: 8px;
}

.thumb-link {
  display: block;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(180deg, #f8fafc 0%, #eef4ff 100%);
  border: 1px solid #dfe7f2;
  aspect-ratio: 1 / 1;
  box-shadow: 0 10px 20px rgba(24, 44, 66, 0.06);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.thumb-link:hover {
  border-color: #b8c9df;
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(24, 44, 66, 0.08);
}

.product-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  text-align: center;
  font-size: 12px;
  color: #64748b;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.1), rgba(255,255,255,0.4)),
    repeating-linear-gradient(-45deg, #edf3fb, #edf3fb 12px, #f6f9fd 12px, #f6f9fd 24px);
}

.thumb-link img + .thumb-fallback {
  display: none;
}

.thumb-link-missing {
  pointer-events: none;
}

.thumb-link-missing .thumb-fallback {
  display: flex;
}

.image-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.copy-cell {
  display: table-cell;
  vertical-align: middle;
  background: linear-gradient(180deg, #fcfdff 0%, #f6f9fd 100%);
}

.copy-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.copy-cell .btn-row-copy {
  display: block;
  width: 100%;
  margin-bottom: 0;
}

.copy-cell .btn-row-copy:last-child {
  margin-bottom: 0;
}

.btn-row-copy {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #5f6f83;
  font-size: 12px;
  padding: 7px 8px;
  cursor: pointer;
  white-space: nowrap;
  width: 100%;
  box-sizing: border-box;
  font-weight: 700;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.btn-image-action {
  padding: 6px 8px;
}

.btn-row-copy:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #fbfeff;
  transform: translateY(-1px);
}

.btn-row-copy.copied {
  color: #16a34a;
  border-color: #86efac;
  background: #f0fdf4;
}

.hidden {
  display: none;
}

.image-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.image-preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(2px);
}

.image-preview-dialog {
  position: relative;
  z-index: 1;
  width: min(92vw, 980px);
  max-height: 88vh;
  margin: 4vh auto;
  display: grid;
  grid-template-rows: auto 1fr;
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.38);
}

.image-preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid #e7edf5;
  background: linear-gradient(180deg, #fbfcff 0%, #f3f7fc 100%);
}

.image-preview-title {
  margin: 0;
  font-size: 18px;
  color: #17324d;
}

.image-preview-code {
  margin: 4px 0 0;
  font-size: 12px;
  color: #64748b;
}

.image-preview-close {
  border: 1px solid #d7e3ee;
  background: #fff;
  color: #4b5d73;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.image-preview-close:hover {
  border-color: #b8c9df;
  color: #163d63;
}

.image-preview-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  max-height: calc(88vh - 72px);
  padding: 16px;
  background:
    radial-gradient(500px 180px at 50% 0%, rgba(231, 240, 255, 0.8), transparent 70%),
    #f7f9fc;
}

.image-preview-img {
  max-width: 100%;
  max-height: calc(88vh - 104px);
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.16);
}

@media (max-width: 640px) {
  .app {
    padding: 18px 12px 24px;
  }

  .app-header h1 {
    font-size: 22px;
  }

  .search-panel {
    padding: 12px;
  }

  .search-hero {
    padding: 12px 12px 14px;
    border-radius: 20px;
  }

  .hero-top {
    display: block;
  }

  .hero-brand {
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
  }

  .hero-logo-wrap {
    width: 74px;
    height: 74px;
    border-radius: 14px;
  }

  .hero-title-wrap h2 {
    font-size: 28px;
    line-height: 1.08;
  }

  .hero-title-wrap p {
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.35;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .hero-actions .btn {
    width: 100%;
    min-height: 46px;
    font-size: 16px;
  }

  .image-preview-dialog {
    width: calc(100vw - 20px);
    margin: 10px auto;
    max-height: calc(100vh - 20px);
    border-radius: 16px;
  }

  .image-preview-header {
    padding: 12px 12px 10px;
  }

  .image-preview-title {
    font-size: 16px;
  }

  .image-preview-body {
    padding: 10px;
    max-height: calc(100vh - 92px);
  }

  .image-preview-img {
    max-height: calc(100vh - 112px);
  }

  .source-panel {
    padding: 12px;
  }

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

  .quick-actions {
    flex-direction: column;
  }

  .url-row {
    flex-direction: column;
  }

  .btn {
    min-height: 44px;
    width: 100%;
  }

  .file-picker-btn {
    width: 100%;
  }

  .love-btn {
    width: 100%;
    min-height: 50px;
  }

  table {
    min-width: 100%;
    table-layout: auto;
  }

  thead {
    display: none;
  }

  tbody tr {
    display: block;
    margin: 0 0 12px;
    border: 1px solid #dfe5ef;
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 10px 22px rgba(19, 32, 58, 0.07);
  }

  tbody td {
    width: 100% !important;
    display: grid;
    grid-template-columns: 78px 1fr;
    gap: 10px;
    align-items: center;
    border-bottom: 1px solid #eef2f8;
    padding: 11px 12px;
    text-align: left !important;
  }

  tbody td::before {
    content: attr(data-label);
    color: #627082;
    font-size: 11px;
    font-weight: 600;
  }

  tbody td.mobile-hide-empty {
    display: none !important;
  }

  tbody td.copy-cell {
    display: block;
  }

  tbody td.image-cell {
    display: block;
  }

  tbody td.image-cell::before {
    display: block;
    margin-bottom: 8px;
  }

  tbody td.image-cell .image-card {
    gap: 10px;
  }

  tbody td.image-cell .thumb-link {
    aspect-ratio: 4 / 3;
  }

  tbody td.image-cell .image-actions {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  tbody td.copy-cell::before {
    display: block;
    margin-bottom: 8px;
  }

  tbody td.copy-cell .copy-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  tbody tr td:last-child {
    border-bottom: none;
  }
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable:hover { color: var(--accent, #3b6fd4); }
th.sort-active { color: var(--accent, #3b6fd4); }
.sort-arrow { font-size: 11px; opacity: 0.6; margin-left: 2px; }
