:root {
  --bg: #f6f5f1; --card: #ffffff; --ink: #1d1d1b; --muted: #6b6a66; --line: #e4e2dc;
  --coles: #e01a22; --coles-soft: #fdecec; --ww: #178841; --ww-soft: #e8f5ec;
  --win: #0d7a3e; --win-soft: #e3f4ea; --warn: #b45309; --promo: #c2410c; --promo-soft: #fff1e6;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514; --card: #1f1f1d; --ink: #eeede9; --muted: #a09f9a; --line: #33322f;
    --coles-soft: #3a1c1d; --ww-soft: #1a3324; --win: #4ade80; --win-soft: #173323;
    --promo: #fb923c; --promo-soft: #3a2616; --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 16px 80px; }
header h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
header h1 .c { color: var(--coles); } header h1 .w { color: var(--ww); }
header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.add { display: flex; gap: 8px; margin: 20px 0 10px; }
.add input { flex: 1; min-width: 0; font: inherit; padding: 11px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); color: var(--ink); }
.add input:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 8px 14px; }
button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 4px 8px; }
button.ghost:hover { color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 999px; }
.chip:hover { border-color: var(--ink); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px;
  font-size: 13px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button { border: 0; border-radius: 0; padding: 6px 12px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--ink); color: var(--bg); }
.toolbar .spacer { flex: 1; }

/* summary */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.tot { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.tot .lbl { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tot .amt { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tot .sub { font-size: 12px; color: var(--muted); }
.tot.best { border-color: var(--win); background: var(--win-soft); }
.tot.best .amt { color: var(--win); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.c { background: var(--coles); } .dot.w { background: var(--ww); }
.verdict { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px;
  margin-bottom: 18px; font-size: 15px; }
.verdict b { color: var(--win); }

/* rows */
.item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.item-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.item-head .name { font-weight: 600; }
.item-head .term { color: var(--muted); font-size: 12px; cursor: pointer; border-bottom: 1px dashed var(--muted); }
.item-head .spacer { flex: 1; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; }
.qty button { border: 0; padding: 2px 9px; background: transparent; }
.qty span { min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.pair { display: grid; grid-template-columns: 1fr 1fr; }
.side { padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; position: relative; min-height: 92px; }
.side + .side { border-left: 1px solid var(--line); }
.side.win { background: var(--win-soft); }
.side img { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
.side .info { min-width: 0; flex: 1; }
.store-tag { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.store-tag.c { color: var(--coles); } .store-tag.w { color: var(--ww); }
.pname { font-size: 13px; line-height: 1.35; margin: 1px 0 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pname a { color: inherit; text-decoration: none; } .pname a:hover { text-decoration: underline; }
.price { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.was { color: var(--muted); text-decoration: line-through; font-size: 12px; margin-left: 4px; }
.unit { font-size: 12px; color: var(--muted); }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--promo-soft); color: var(--promo); font-weight: 600; }
.badge.win { background: var(--win); color: #fff; }
.badge.na { background: var(--line); color: var(--muted); }
.swap { position: absolute; right: 8px; top: 8px; font-size: 12px; }
.msg { color: var(--muted); font-size: 13px; padding: 8px 0; }
.msg.err { color: var(--coles); }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; border: 1.5px dashed var(--line); border-radius: 14px; }

/* picker */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 32px)); max-height: 80vh;
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.pk-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; position: sticky; top: 0; background: var(--card); }
.pk-head .t { font-weight: 600; flex: 1; }
.pk-head input { font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); width: 180px; }
.pk-list { overflow-y: auto; max-height: calc(80vh - 60px); }
.pk-row { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pk-row:hover { background: var(--bg); }
.pk-row.sel { background: var(--win-soft); }
.pk-row img { width: 44px; height: 44px; object-fit: contain; background: #fff; border-radius: 6px; flex: none; }
.pk-row .info { flex: 1; min-width: 0; font-size: 13px; }
.pk-row .p { text-align: right; font-variant-numeric: tabular-nums; }
.pk-row .p b { font-size: 15px; }

footer { margin-top: 30px; font-size: 12px; color: var(--muted); }

@media (max-width: 640px) {
  .summary { grid-template-columns: 1fr 1fr; }
  .summary .tot:last-child { grid-column: span 2; }
  .tot .amt { font-size: 22px; }
  .side { flex-direction: column; gap: 6px; padding: 10px; }
  .side img { width: 44px; height: 44px; }
  .price { font-size: 17px; }
}

/* ---------- v2: 顶栏、标签页、必需品、特价 ---------- */
header { display: flex; align-items: flex-start; gap: 12px; }
header .titles { flex: 1; min-width: 0; }
.top-actions { display: flex; gap: 6px; align-items: center; flex: none; }
.code-chip { font-size: 12px; padding: 5px 10px; border-radius: 999px; font-variant-numeric: tabular-nums; letter-spacing: .05em; }
.lang .seg button { padding: 5px 10px; }

.tabs { display: flex; gap: 4px; margin: 18px 0 4px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-radius: 0; background: transparent; padding: 10px 14px; color: var(--muted);
  font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }
.tabs .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px;
  background: var(--promo); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.tabs .count:empty { display: none; }
[hidden] { display: none !important; }

.star { border: 0; background: transparent; padding: 0 2px; font-size: 18px; line-height: 1; color: var(--line); }
.star.on { color: #f59e0b; }
.star:hover { color: #f59e0b; }

.banner { display: flex; align-items: center; gap: 10px; background: var(--promo-soft); color: var(--promo);
  border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; font-weight: 500; }
.banner .spacer { flex: 1; }
.banner button { border-color: var(--promo); color: var(--promo); background: transparent; padding: 4px 12px; font-size: 13px; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 4px; font-size: 17px; }
.panel p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row input[type=email], .row input[type=text] { flex: 1; min-width: 180px; font: inherit; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
label.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.note.ok { color: var(--win); } .note.err { color: var(--coles); }

.sp-item { display: grid; grid-template-columns: 1fr 1fr; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; margin-bottom: 10px; overflow: hidden; box-shadow: var(--shadow); }
.sp-item .sp-name { grid-column: span 2; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600;
  display: flex; gap: 8px; align-items: center; }
.sp-item .sp-name .spacer { flex: 1; }
.sp-item.hot { border-color: var(--promo); }
.sp-side { padding: 10px 14px; font-size: 13px; }
.sp-side + .sp-side { border-left: 1px solid var(--line); }
.sp-side.deal { background: var(--promo-soft); }
.sp-side .price { font-size: 18px; }

dialog.small { width: min(420px, calc(100vw - 32px)); }
.dlg-body { padding: 16px; }
.dlg-body h3 { margin: 0 0 6px; font-size: 16px; }
.dlg-body p { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.big-code { font-size: 28px; font-weight: 700; letter-spacing: .12em; font-variant-numeric: tabular-nums; margin: 4px 0 12px; }

@media (max-width: 640px) {
  header { flex-direction: column; }
  .sp-item { grid-template-columns: 1fr; }
  .sp-item .sp-name { grid-column: auto; }
  .sp-side + .sp-side { border-left: 0; border-top: 1px solid var(--line); }
}

/* ---------- v3: 每件商品的选品按钮、门店选择 ---------- */
.seg.mini { border-radius: 8px; }
.seg.mini button { padding: 2px 8px; font-size: 12px; }
#storeBtn { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: 0; }
.store-list { max-height: 45vh; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.store-list:empty { display: none; }
.store-list .msg { padding: 12px 16px; }
.dlg-body .note { margin: 8px 0 0; }
.top-actions { flex-wrap: wrap; justify-content: flex-end; }

@media (max-width: 640px) {
  .item-head { flex-wrap: wrap; row-gap: 6px; }
  .top-actions { justify-content: flex-start; }
}

/* ---------- v4: 一键加购 ---------- */
.cart-btn { margin-top: 10px; width: 100%; font-size: 13px; padding: 6px 10px; }
.tot.best .cart-btn { border-color: var(--win); color: var(--win); background: transparent; }
#cartDlg { width: min(560px, calc(100vw - 32px)); max-height: 88vh; overflow-y: auto; }
.cart-part { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 12px 0; }
.cart-items { margin: 6px 0 0; padding-left: 20px; font-size: 13px; color: var(--muted); max-height: 160px; overflow-y: auto; }
a.btn { display: inline-block; text-decoration: none; border-radius: 10px; padding: 8px 14px; border: 1px solid var(--line); color: var(--ink); }
a.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }
.cart-how { background: var(--bg); border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-size: 13px; }
.cart-how ol { margin: 6px 0; padding-left: 20px; }
.cart-how li { margin: 6px 0; }
.bookmarklet { display: inline-block; margin-top: 6px; padding: 6px 12px; border-radius: 999px; background: #f59e0b; color: #1d1d1b;
  font-weight: 700; text-decoration: none; cursor: grab; }
.cart-check { margin: 10px 0 4px; padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.cart-check.ok { background: var(--win-soft); color: var(--win); }
.cart-check.err { background: var(--promo-soft); color: var(--promo); }
.note.warn { color: var(--promo); }
.cart-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.cart-table td { padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.cart-table td.pn { color: var(--muted); }
.cart-table td.q { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .cart-table td.pn { display: none; } }

.price-note { font-size: 12px; color: var(--muted); cursor: help; }
