:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e3e8f0;
  --line-strong: #cfd8e6;
  --text: #1c2536;
  --text-2: #5a677d;
  --text-3: #8b97ab;
  --primary: #2563eb;
  --primary-soft: #eaf1ff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warn: #d97706;
  --warn-soft: #fdf3e3;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

h1, h2, h3 { margin: 0; font-weight: 650; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 28px; line-height: 1; }
.brand h1 { font-size: 16px; letter-spacing: .2px; }
.brand p { margin: 0; font-size: 12px; color: var(--text-3); }

.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px;
  background: var(--line); color: var(--text-2);
  border-radius: 10px; font-size: 12px; font-weight: 600;
}

.topmeta { margin-left: auto; }
.store-chip {
  font-size: 12px; color: var(--text-2);
  background: #f1f4f9; padding: 5px 12px; border-radius: 20px;
}
.store-chip.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- 布局 ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 24px 28px 80px; }
.view { display: block; }

/* 图库直接堆叠在破损检测下方，用一条分隔线和标题区隔，
   售后人员进入后不用切 tab 就能看到图库 */
.lib-section { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--line); }
.section-title {
  display: flex; align-items: center;
  font-size: 17px; font-weight: 700; color: var(--text);
  margin: 0 0 16px;
}
.section-title .badge { background: var(--primary-soft); color: var(--primary); }

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

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 14px; flex-wrap: wrap;
}
.panel-head h2 { font-size: 15px; }
.muted { color: var(--text-3); font-weight: 400; font-size: 13px; }
.actions { display: flex; gap: 8px; }

/* ---------- 拖拽区 ---------- */
.dropzone {
  border: 2px dashed var(--line-strong);
  border-radius: 16px;
  background: #fff;
  padding: 48px 24px;
  text-align: center;
  transition: .18s;
  cursor: pointer;
  margin-bottom: 20px;
}
.dropzone:hover { border-color: var(--primary); background: #fbfdff; }
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: scale(1.005);
}
.dz-icon { font-size: 40px; line-height: 1; margin-bottom: 10px; }
.dz-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.dz-sub { color: var(--text-3); font-size: 13px; }
.link-btn {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--primary); font-family: inherit; font-size: 13px; text-decoration: underline;
}

/* ---------- 设置 ---------- */
.set-row { display: flex; align-items: center; gap: 14px; }
.set-row label { font-weight: 600; min-width: 96px; }
.set-row input[type=range] { flex: 1; max-width: 420px; accent-color: var(--primary); }
.set-row output {
  font-variant-numeric: tabular-nums; font-weight: 700; color: var(--primary);
  min-width: 48px; text-align: right;
}
.hint { color: var(--text-2); font-size: 12.5px; margin: 10px 0 12px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.switch input { accent-color: var(--primary); width: 15px; height: 15px; }

/* ---------- 结果队列 ---------- */
.queue { display: flex; flex-direction: column; gap: 14px; }

.item {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
}
.item.dup { border-color: #f5c6c6; background: #fffbfb; }
.item.susp { border-color: #f0dcb4; background: #fffdf7; }
.item.new { border-color: #bfe5cd; background: #fbfffc; }

.item-thumb {
  width: 132px; height: 132px; border-radius: 8px; overflow: hidden;
  background: #f1f4f9; cursor: zoom-in; display: flex; align-items: center; justify-content: center;
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-thumb .spinner { color: var(--text-3); font-size: 12px; }

.item-body { min-width: 0; }
.item-top { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.item-meta { color: var(--text-3); font-size: 12px; }

/* 检测结果里的图片名称：未入库时可编辑，已入库后显示文字 */
.name-input {
  width: 100%; margin: 6px 0 2px;
  border: 1px solid var(--line-strong); border-radius: 7px; padding: 7px 10px;
  font-size: 13.5px; font-weight: 600; font-family: inherit; color: var(--text);
}
.name-input:focus { outline: none; border-color: var(--primary); }
.item-name-text {
  font-weight: 600; font-size: 14px; word-break: break-all;
  margin: 6px 0 2px; color: var(--text);
}

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.tag.dup { background: var(--danger-soft); color: var(--danger); }
.tag.susp { background: var(--warn-soft); color: var(--warn); }
.tag.new { background: var(--ok-soft); color: var(--ok); }
.tag.pending { background: #eef1f6; color: var(--text-2); }

.verdict { margin: 8px 0 10px; font-size: 13.5px; }
.verdict strong { font-weight: 650; }
.verdict .why { color: var(--text-2); }

.simbar {
  height: 6px; border-radius: 4px; background: #eef1f6; overflow: hidden; margin: 6px 0 10px;
}
.simbar > i { display: block; height: 100%; border-radius: 4px; transition: width .3s; }

.matches { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.match {
  display: flex; gap: 10px; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px 6px 6px;
  background: #fff;
}
.match img { width: 46px; height: 46px; border-radius: 6px; object-fit: cover; cursor: zoom-in; }
.match-meta { font-size: 12px; line-height: 1.45; }
.match-meta b { color: var(--danger); font-variant-numeric: tabular-nums; }
.match-meta span { display: block; color: var(--text-3); }

.item-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.note-input {
  border: 1px solid var(--line-strong); border-radius: 7px; padding: 6px 10px;
  font-size: 13px; font-family: inherit; width: 190px; color: var(--text);
}
.note-input:focus { outline: none; border-color: var(--primary); }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-family: inherit; transition: .15s;
}
.btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #1d4fd7; color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn.ok:hover:not(:disabled) { background: #128740; color: #fff; }
.btn.ghost { background: #fff; }
.btn.danger-ghost { color: var(--danger); border-color: #f0c8c8; }
.btn.danger-ghost:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 12px; }

/* ---------- 图库 ---------- */
.lib-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.lib-toolbar input[type=search] {
  flex: 1; min-width: 220px; max-width: 380px;
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 12px;
  font-size: 13px; font-family: inherit; color: var(--text);
}
.lib-toolbar select {
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--text);
}
.lib-toolbar input:focus, .lib-toolbar select:focus { outline: none; border-color: var(--primary); }
.grow { flex: 1; }

.lib-stats { margin-top: 12px; font-size: 12.5px; color: var(--text-2); }
.lib-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.lib-note {
  margin: 10px 0 0; padding-top: 10px; font-size: 12px; color: var(--text-3);
  border-top: 1px dashed var(--line);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.card-img {
  height: 160px; background: #f1f4f9; cursor: zoom-in; position: relative;
}
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { padding: 10px 12px 12px; }
.card-name {
  font-size: 13px; font-weight: 600; margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; user-select: none; -webkit-user-select: none;
}
.card-name:hover { color: var(--primary); text-decoration: underline dotted; }
.card-name-edit {
  width: 100%; box-sizing: border-box;
  font-size: 13px; font-weight: 600; font-family: inherit;
  color: var(--text); background: #fff;
  padding: 2px 5px; margin: -2px -5px 2px;
  border: 1.5px solid var(--primary); border-radius: 4px; outline: none;
  user-select: text; -webkit-user-select: text;
}
.card-sub { font-size: 11.5px; color: var(--text-3); line-height: 1.5; }
.card-note {
  margin-top: 6px; font-size: 12px; color: var(--text-2);
  background: #f6f8fb; border-radius: 6px; padding: 3px 7px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-fp {
  margin-top: 6px; font-family: ui-monospace, Consolas, Menlo, monospace;
  font-size: 11px; color: var(--text-3); letter-spacing: .3px;
}
.card-actions { display: flex; gap: 6px; padding: 0 12px 12px; }

/* 选中态：只有选中后卡片才露出操作按钮，避免手滑误删 */
.card { transition: box-shadow .15s, border-color .15s; }
.card-img { position: relative; }
.card.selectable .card-img { cursor: pointer; }
.card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14), var(--shadow);
}
.card-hint {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(28, 37, 54, .62); color: #fff;
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  opacity: 0; transition: .15s; pointer-events: none;
}
.card:hover .card-hint { opacity: 1; }
.card.selected .card-hint { opacity: 0; }
.card-locked { padding: 0 12px 12px; font-size: 11.5px; color: var(--text-3); }

/* 赔付状态 */
.payout {
  display: inline-flex; align-items: center;
  padding: 1px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; user-select: none;
}
.payout.pending { background: #f1f4f9; color: var(--text-2); border-color: var(--line); }
.payout.paid { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cd; }
.payout.unpaid { background: var(--danger-soft); color: var(--danger); border-color: #f3cccc; }
.payout:hover { filter: brightness(.96); }

.payout-pick { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.payout-pick button {
  border: 0; background: #fff; padding: 6px 11px; cursor: pointer;
  font-size: 12.5px; font-family: inherit; color: var(--text-2);
  border-right: 1px solid var(--line); transition: .12s;
}
.payout-pick button:last-child { border-right: 0; }
.payout-pick button:hover { background: #f4f7fb; }
.payout-pick button.on { color: #fff; font-weight: 600; }
.payout-pick button.on[data-v="pending"] { background: #798593; }
.payout-pick button.on[data-v="paid"] { background: var(--ok); }
.payout-pick button.on[data-v="unpaid"] { background: var(--danger); }

/* 压缩提示 */
.compressed-tip {
  margin-top: 6px; font-size: 12px; color: var(--warn);
  background: var(--warn-soft); border-radius: 6px; padding: 3px 8px;
  display: inline-block;
}

.empty-hint {
  text-align: center; color: var(--text-3); font-size: 13.5px;
  padding: 36px 20px; border: 1px dashed var(--line-strong); border-radius: var(--radius);
  background: #fff;
}
.empty-hint strong { color: var(--text-2); }

/* ---------- 预览 ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(16, 22, 34, .82);
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  padding: 40px;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 92vw; max-height: 82vh; border-radius: 8px; background: #fff; }
.lb-info { color: #d7dee9; font-size: 13px; margin-top: 14px; text-align: center; }
.lb-close {
  position: absolute; top: 20px; right: 24px;
  width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.14); color: #fff; font-size: 17px; cursor: pointer;
}
.lb-close:hover { background: rgba(255,255,255,.26); }

/* ---------- 接入码门禁 ---------- */
.gate {
  position: fixed; inset: 0; z-index: 500;
  background: linear-gradient(160deg, #eef3fb 0%, #f7f9fc 100%);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.gate[hidden] { display: none; }
.gate-box {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 12px 40px rgba(16, 24, 40, .1);
  padding: 36px 34px 28px; width: 100%; max-width: 380px; text-align: center;
}
.gate-logo { font-size: 40px; line-height: 1; margin-bottom: 12px; }
.gate-box h2 { font-size: 18px; margin-bottom: 6px; }
.gate-sub { color: var(--text-3); font-size: 13px; margin: 0 0 20px; }
#gateForm { display: flex; gap: 8px; }
#gateCode {
  flex: 1; border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; font-family: inherit;
  color: var(--text); letter-spacing: 2px;
}
#gateCode:focus { outline: none; border-color: var(--primary); }
.gate-err { color: var(--danger); font-size: 13px; margin: 12px 0 0; }
.gate-tip { color: var(--text-3); font-size: 12px; margin: 14px 0 0; }
.gate-box.shake { animation: gateShake .32s; }
@keyframes gateShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(4px); }
}

/* ---------- 提示 ---------- */
.toast-wrap {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: #1c2536; color: #fff; padding: 9px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 6px 20px rgba(16,24,40,.2);
  animation: toastIn .22s ease;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .topmeta { margin-left: 0; }
  main { padding: 16px; }
  .item { grid-template-columns: 1fr; }
  .item-thumb { width: 100%; height: 190px; }
  .note-input { width: 100%; }
}
