:root {
  --bg: #f3f4f6; --card: #fff; --ink: #111827; --sub: #6b7280; --line: #e5e7eb;
  --blue: #1d4ed8; --red: #dc2626; --green: #15803d; --amber: #b45309; --dark: #1f2937;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; }
button, input, a.btn { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#top { position: sticky; top: 0; z-index: 20; background: var(--dark); color: #fff; }
#tabs { display: flex; }
#tabs button { flex: 1; padding: 13px 0 11px; background: none; border: 0; color: #9ca3af; font-size: 17px; font-weight: 600; border-bottom: 3px solid transparent; }
#tabs button.on { color: #fff; border-bottom-color: #60a5fa; }
#stat { display: flex; gap: 10px; align-items: center; padding: 4px 12px 7px; font-size: 13px; color: #d1d5db; }
#statText { flex: 1; }
#qInfo { color: #fbbf24; }
button.link { background: none; border: 0; color: #93c5fd; padding: 0; font-size: 13px; }

main { padding-bottom: calc(88px + var(--safe-b)); }
.tab { display: none; }
.tab.on { display: block; }

/* 摄像头 */
#cam { position: relative; background: #000; height: 52vh; min-height: 280px; overflow: hidden; }
#cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
#frame { position: absolute; left: 50%; top: 46%; width: 62vmin; height: 62vmin; max-width: 330px; max-height: 330px; transform: translate(-50%, -50%);
  border: 3px solid rgba(255,255,255,.9); border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.28); pointer-events: none; }
#camMsg { position: absolute; left: 0; right: 0; top: 10px; text-align: center; color: #fff; font-size: 15px; text-shadow: 0 1px 3px #000; padding: 0 12px; }
#camMsg.err { color: #fecaca; }
#camBtns { position: absolute; left: 0; right: 0; bottom: 10px; display: flex; justify-content: center; gap: 10px; }
#camBtns button { background: rgba(17,24,39,.75); color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 22px; padding: 8px 16px; font-size: 15px; }
#cam .only-full { display: none; }
#wxBox { background: var(--card); padding: 22px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
#wxBox #btnWx { min-height: 76px; font-size: 24px; border-radius: 14px; }
#wxBox #btnType2 { min-height: 48px; }
#wxBox .hint { margin: 2px 0 0; }
#camFull { position: fixed; inset: 0; z-index: 60; background: #000; }
#camFull #cam { height: 100%; }
#camFull #cam .only-full { display: inline-block; }

/* 扫码结果 */
#result:empty { display: none; }
.rec { background: var(--card); margin: 8px 0; padding: 12px 12px 10px; }
.rec + .rec { border-top: 6px solid var(--bg); }
.code { font-size: 26px; font-weight: 800; letter-spacing: .3px; word-break: break-all; }
.meta { color: var(--sub); font-size: 14px; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 13px; font-weight: 600; background: #e5e7eb; color: #374151; white-space: nowrap; }
.c-ok { background: #dcfce7; color: var(--green); }
.c-bad { background: #fee2e2; color: var(--red); }
.c-redo { background: #fef3c7; color: var(--amber); }
.c-new { background: #dbeafe; color: var(--blue); }
.c-off { background: #f3f4f6; color: #9ca3af; text-decoration: line-through; }
.photos { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 10px -12px 0; padding: 0 12px 4px; }
.photos img { height: 56vh; max-height: 520px; min-width: 40vw; max-width: 86vw; object-fit: contain; background: #e5e7eb; border-radius: 8px; scroll-snap-align: start; flex: none; }
.photos.small img { height: 92px; min-width: 70px; }
.nopic { margin-top: 10px; height: 160px; border-radius: 8px; background: #fee2e2; color: var(--red); display: flex; align-items: center; justify-content: center; font-weight: 600; text-align: center; padding: 10px; }
.sub-title { margin: 12px 0 0; font-size: 13px; color: var(--sub); }
.big-msg { background: var(--card); padding: 18px 14px; margin: 8px 0; font-size: 16px; }
.big-msg b { font-size: 22px; }
.cands { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.cand { background: #f9fafb; border: 1px solid var(--line); border-radius: 10px; padding: 6px; text-align: left; }
.cand img { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; background: #e5e7eb; display: block; }
.cand b { display: block; margin-top: 4px; word-break: break-all; }
.mini-actions { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.mini-actions button { background: none; border: 0; padding: 4px 0; color: var(--sub); text-decoration: underline; font-size: 14px; }
.mini-actions button.warn { color: var(--red); }

/* 底部操作条 */
#bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; gap: 10px; padding: 10px 12px calc(10px + var(--safe-b)); background: rgba(255,255,255,.97); border-top: 1px solid var(--line); }
#bar button { flex: 1; min-height: 56px; border-radius: 12px; border: 0; font-size: 19px; font-weight: 700; }
.btn { display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 10px 14px; text-decoration: none; font-weight: 600; }
.btn.small { padding: 7px 12px; font-size: 14px; }
.primary, #bar .primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.danger, #bar .danger { background: var(--red); color: #fff; border-color: var(--red); }
.good, #bar .good { background: var(--green); color: #fff; border-color: var(--green); }
.ghost, #bar .ghost { background: #e5e7eb; color: var(--ink); }
#bar .grow2 { flex: 1.6; }

/* 最近扫的 */
#recent { padding: 10px 12px; }
#recent h4 { margin: 4px 0 8px; font-size: 14px; color: var(--sub); font-weight: 600; }
.rrow { display: flex; align-items: center; gap: 8px; background: var(--card); padding: 9px 10px; border-radius: 10px; margin-bottom: 6px; }
.rrow b { flex: 1; word-break: break-all; }
.rrow small { color: var(--sub); }

/* 清单、插图 */
.tools { background: var(--card); padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 74px; z-index: 10; }
.tools .chips button { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 6px 11px; font-size: 14px; }
.tools .chips button.on { background: var(--dark); color: #fff; border-color: var(--dark); }
.row2 { display: flex; gap: 8px; margin-top: 8px; }
.row2:first-child { margin-top: 0; }
.row2 input { flex: 1; min-width: 0; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; font-size: 16px; }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--sub); }
.item { display: flex; align-items: center; gap: 10px; background: var(--card); padding: 8px 12px; border-bottom: 1px solid var(--line); }
.item img, .item .noimg { width: 58px; height: 58px; border-radius: 8px; object-fit: cover; background: #e5e7eb; flex: none; }
.item .noimg { display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--sub); }
.item .mid { flex: 1; min-width: 0; }
.item .mid b { display: block; word-break: break-all; }
.item .mid small { color: var(--sub); font-size: 13px; }
.item .btn { flex: none; }
.group-title { padding: 14px 12px 6px; font-size: 14px; color: var(--sub); font-weight: 600; }
.empty { padding: 40px 20px; text-align: center; color: var(--sub); }

/* 弹层 */
#sheet { position: fixed; inset: 0; z-index: 65; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
#sheet .panel { background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 0 0 calc(16px + var(--safe-b)); }
.ph { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; background: var(--card); position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--line); }
.ph h3 { margin: 0; flex: 1; font-size: 19px; word-break: break-all; }
.ph .x { background: none; border: 0; font-size: 26px; line-height: 1; color: var(--sub); padding: 0 4px; }
.pb { padding: 12px 14px; }
.names { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.names button { padding: 14px 6px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 16px; }
.names button.on { border-color: var(--blue); color: var(--blue); font-weight: 700; }
.pick-btns { display: flex; gap: 10px; }
.pick-btns .btn { flex: 1; min-height: 54px; font-size: 17px; }
.drop { margin-top: 10px; border: 2px dashed #cbd5e1; border-radius: 12px; padding: 12px; text-align: center; color: var(--sub); font-size: 14px; }
.drop.over { border-color: var(--blue); background: #eff6ff; }
.prev { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.prev div { position: relative; }
.prev img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; background: #e5e7eb; display: block; }
.prev span { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; border-radius: 8px; padding: 0 6px; }
.prev button { position: absolute; right: 4px; top: 4px; width: 28px; height: 28px; border-radius: 14px; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 16px; line-height: 28px; padding: 0; }
.prev .ok { position: absolute; right: 4px; bottom: 4px; left: auto; top: auto; background: var(--green); }
.upbtn { width: 100%; margin-top: 12px; min-height: 56px; font-size: 18px; }
.err { color: var(--red); }

/* 看大图 */
#viewer { position: fixed; inset: 0; z-index: 70; background: #000; display: flex; flex-direction: column; }
.vbox { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; }
.vbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.vbox.zoom { display: block; }
.vbox.zoom img { max-width: none; max-height: none; width: 260%; }
.vbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 12px calc(10px + var(--safe-b)); color: #fff; background: #111; }
.vbar button, .vbar a { background: #374151; color: #fff; border: 0; border-radius: 10px; padding: 10px 14px; font-size: 16px; text-decoration: none; }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 80; background: rgba(17,24,39,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; max-width: 90vw; text-align: center; }
#toast.bad { background: rgba(185,28,28,.95); }

@media (min-width: 760px) {
  main { max-width: 760px; margin: 0 auto; }
  #cam { height: 46vh; }
  .photos img { height: 60vh; }
}
