:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --text-2: #4b5563;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-soft: #e6fffb;
  --amber: #f59e0b;
  --amber-soft: #fff7ed;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --green: #10b981;
  --green-soft: #ecfdf5;
  --slate-soft: #f1f5f9;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

button,
input {
  font-family: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶部 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.logo {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.28);
}

.brand-text {
  min-width: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.brand-text p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-chip {
  flex: none;
  max-width: 42vw;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(13, 148, 136, 0.18);
}

.tabs {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px 10px;
  display: flex;
  gap: 8px;
}

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.tab:hover {
  color: var(--primary-dark);
}

.tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.25);
}

/* ---------- 主体 ---------- */
.main {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 16px 40px;
  flex: 1;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.section-head p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.head-actions {
  display: flex;
  gap: 8px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 8px;
}

.input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease;
  white-space: nowrap;
}

.btn:hover {
  background: #f9fafb;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(13, 148, 136, 0.22);
}

.btn.primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text-2);
}

.btn.ghost:hover {
  background: #f3f4f6;
}

.btn.danger-ghost {
  background: transparent;
  border-color: #fecaca;
  color: var(--red);
}

.btn.danger-ghost:hover {
  background: var(--red-soft);
}

.btn.sm {
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 8px;
}

.btn.lg {
  padding: 12px 22px;
  font-size: 15px;
}

.btn-plus {
  font-size: 17px;
  line-height: 1;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* ---------- 记录列表 ---------- */
.record-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.record-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.record-card:hover {
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.09);
  transform: translateY(-1px);
}

.record-thumb {
  width: 84px;
  height: 84px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--slate-soft);
  border: 1px solid var(--line);
  flex: none;
}

.record-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.record-main h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  word-break: break-all;
}

.record-meta {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.record-fields {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-all;
}

.record-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
  flex: none;
}

.record-actions .btn {
  min-width: 56px;
}

.empty-state {
  grid-column: 1 / -1;
  background: var(--card);
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state svg {
  color: #94a3b8;
  margin-bottom: 8px;
}

.empty-state h3 {
  margin: 6px 0;
  font-size: 17px;
  color: var(--text);
}

.empty-state p {
  margin: 0 0 16px;
  font-size: 13px;
}

/* ---------- 上传 ---------- */
.upload-zone {
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  padding: 26px 16px;
  text-align: center;
  background: #fbfcfd;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.upload-zone:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.upload-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 10px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
}

.upload-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.upload-tip {
  margin: 6px auto 16px;
  max-width: 420px;
  font-size: 13px;
  color: var(--muted);
}

.upload-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.paste-zone {
  margin-top: 14px;
  min-height: 38px;
  padding: 9px 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  outline: none;
  cursor: text;
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
  user-select: text;
}

.paste-zone:empty::before {
  content: attr(data-hint);
}

.paste-zone:focus {
  border-color: var(--primary);
  background: #f0fdfa;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}

.paste-zone:focus:empty::before {
  color: var(--primary-dark);
}

/* ---------- 识别结果 ---------- */
.result-head {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.preview-wrap {
  display: block;
  flex: none;
}

.preview {
  display: block;
  max-width: 280px;
  max-height: 280px;
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--slate-soft);
  object-fit: contain;
}

.result-meta {
  flex: 1;
  min-width: 180px;
}

.meta-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-time {
  font-size: 12px;
  color: var(--muted);
}

.meta-time b {
  color: var(--text-2);
}

.hint {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}

.editor-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 10px;
}

.editor-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.editor {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.editor-empty {
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.field-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1.35fr) 30px;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.field-row:last-child {
  border-bottom: none;
}

.field-row:nth-child(even) {
  background: #fcfcfd;
}

.field-row .idx {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.field-row .input {
  padding: 7px 9px;
  font-size: 13px;
  border-radius: 8px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #9ca3af;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  color: var(--red);
  background: var(--red-soft);
  border-color: #fecaca;
}

.editor-actions {
  margin-top: 10px;
}

.save-bar {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
}

.save-bar .btn {
  width: 100%;
}

/* ---------- 详情 ---------- */
.detail-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.detail-preview {
  max-width: 100%;
  max-height: 420px;
  margin: 0 auto;
}

.kv-table {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(90px, 34%) minmax(0, 66%);
  border-bottom: 1px solid var(--line);
}

.kv-row:last-child {
  border-bottom: none;
}

.kv-row > span {
  padding: 9px 12px;
  font-size: 13px;
  word-break: break-word;
}

.kv-row .k {
  background: #f8fafc;
  color: var(--text-2);
  font-weight: 600;
  border-right: 1px solid var(--line);
}

.kv-row .v {
  color: var(--text);
}

.kv-row .v.empty {
  color: #9ca3af;
}

.kv-table.compact .kv-row > span {
  padding: 7px 10px;
  font-size: 12px;
}

.sticky-actions {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-top: 6px;
}

.sticky-actions .btn.lg {
  flex: 1;
}

/* ---------- 比对 ---------- */
.standard-summary {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.preview-wrap.small .preview {
  width: 76px;
  height: 76px;
  max-width: 76px;
  max-height: 76px;
  object-fit: cover;
}

.standard-summary-main {
  flex: 1;
  min-width: 0;
}

.standard-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.standard-name-row h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  word-break: break-all;
}

.tag {
  flex: none;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.std-fields {
  margin-top: 8px;
}

.std-fields summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--primary-dark);
  font-weight: 600;
  list-style: none;
}

.std-fields summary::-webkit-details-marker {
  display: none;
}

.std-fields summary::before {
  content: "▸ ";
}

.std-fields[open] summary::before {
  content: "▾ ";
}

.std-fields .kv-table {
  margin-top: 8px;
}

.compare-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.compare-new-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.preview.compare-new-img {
  width: 72px;
  height: 72px;
  max-width: 72px;
  max-height: 72px;
  object-fit: cover;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.sum-item {
  border-radius: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sum-item b {
  font-size: 24px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.sum-item span {
  font-size: 12px;
  color: var(--muted);
}

.sum-item.total {
  background: #f8fafc;
}

.sum-item.same {
  background: var(--green-soft);
  border-color: #d1fae5;
}

.sum-item.same b {
  color: #047857;
}

.sum-item.different {
  background: var(--amber-soft);
  border-color: #fed7aa;
}

.sum-item.different b {
  color: #b45309;
}

.sum-item.missing {
  background: var(--slate-soft);
  border-color: #e2e8f0;
}

.sum-item.missing b {
  color: #475569;
}

.sum-item.extra {
  background: var(--primary-soft);
  border-color: #99f6e4;
}

.sum-item.extra b {
  color: var(--primary-dark);
}

.sum-item:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.compare-tip {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-2);
}

.compare-tip.has-diff {
  background: var(--amber-soft);
  border-color: #fed7aa;
  color: #92400e;
}

.compare-tip.no-diff {
  background: var(--green-soft);
  border-color: #d1fae5;
  color: #047857;
}

.compare-tip b {
  font-size: 15px;
}

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

.legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot.different {
  background: var(--amber);
}

.dot.missing {
  background: #94a3b8;
}

.dot.extra {
  background: var(--green);
}

.dot.same {
  background: #d1d5db;
}

.diff-table {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}

.diff-head {
  display: none;
}

.diff-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
}

.diff-row:last-child {
  border-bottom: none;
}

.diff-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  word-break: break-word;
}

.badge {
  flex: none;
  font-style: normal;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
}

.diff-cell {
  border-radius: 8px;
  padding: 8px 10px;
  background: #f8fafc;
  font-size: 13px;
  word-break: break-word;
  white-space: pre-wrap;
}

.diff-cell::before {
  content: attr(data-label);
  display: block;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 2px;
}

.diff-cell .empty {
  color: #9ca3af;
}

.diff-row.status-different {
  background: var(--amber-soft);
  border-left-color: var(--amber);
}

.diff-row.status-different .badge {
  background: #fde68a;
  color: #92400e;
}

.diff-row.status-different .diff-cell {
  background: #fff;
}

.diff-row.status-missing {
  background: var(--slate-soft);
  border-left-color: #94a3b8;
}

.diff-row.status-missing .badge {
  background: #e2e8f0;
  color: #475569;
}

.diff-row.status-extra {
  background: var(--green-soft);
  border-left-color: var(--green);
}

.diff-row.status-extra .badge {
  background: #a7f3d0;
  color: #047857;
}

.diff-row.status-same {
  background: #fff;
}

.diff-row.status-same .badge {
  background: #f0fdf4;
  color: #15803d;
}

mark {
  background: #fde68a;
  color: #92400e;
  padding: 0 2px;
  border-radius: 3px;
  font-weight: 700;
}

.diff-empty {
  padding: 26px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- 底部 ---------- */
.footer {
  text-align: center;
  padding: 18px 16px 26px;
  font-size: 11px;
  color: #9ca3af;
}

/* ---------- 进度遮罩 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.overlay-card {
  width: min(360px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 24px 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}

.overlay-card h3 {
  margin: 6px 0 4px;
  font-size: 17px;
}

.spinner {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 4px;
}

.spinner span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--primary);
  animation: bounce 1s infinite ease-in-out;
}

.spinner span:nth-child(2) {
  animation-delay: 0.15s;
}

.spinner span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0.7);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.overlay-step {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #14b8a6, #0d9488);
  transition: width 0.3s ease;
}

.overlay-elapsed {
  margin: 10px 0 0;
  font-size: 12px;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  z-index: 70;
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  max-width: calc(100vw - 40px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: #b91c1c;
}

/* ---------- 响应式 ---------- */
@media (min-width: 640px) {
  .topbar-inner {
    padding: 14px 24px 10px;
  }

  .tabs {
    padding: 0 24px 12px;
  }

  .main {
    padding: 24px 24px 48px;
  }

  .record-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .sum-item:last-child:nth-child(odd) {
    grid-column: auto;
  }

  .save-bar .btn {
    width: auto;
    min-width: 220px;
  }

  .diff-head {
    display: grid;
    grid-template-columns: minmax(120px, 0.9fr) minmax(0, 1.5fr) minmax(0, 1.5fr);
    gap: 8px;
    padding: 10px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--line);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-2);
  }

  .diff-row {
    grid-template-columns: minmax(120px, 0.9fr) minmax(0, 1.5fr) minmax(0, 1.5fr);
    gap: 8px;
    align-items: start;
    padding: 10px 14px;
  }

  .diff-name {
    padding-top: 8px;
  }

  .diff-cell::before {
    display: none;
  }

  .detail-layout {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    align-items: start;
  }
}

@media (min-width: 900px) {
  .brand-text p {
    font-size: 12.5px;
  }

  .record-actions {
    flex-direction: row;
    align-items: center;
    align-self: center;
  }

  .model-chip {
    max-width: none;
  }
}
