:root {
  --bg: #f5f6f8; --card: #fff; --line: #e6e8eb; --ink: #1f2328; --muted: #6b7280;
  --brand: #b0824d; --brand-d: #8a6338; --bulk: #c0392b; --drop: #2f6f4f;
  --shadow: 0 2px 10px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
b { font-weight: 700; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 18px; background: #fff; border-bottom: 1px solid var(--line); box-shadow: var(--shadow); }
.brand { display: flex; flex-direction: column; line-height: 1.1; }
.brand .logo { font-size: 19px; font-weight: 800; color: var(--brand-d); letter-spacing: 1px; }
.brand .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.search { flex: 1; }
.search input { width: 100%; max-width: 520px; padding: 9px 14px; font-size: 14px; border: 1px solid var(--line); border-radius: 22px; outline: none; background: var(--bg); }
.search input:focus { border-color: var(--brand); background: #fff; }
.cart-btn { position: relative; padding: 9px 16px; font-size: 14px; font-weight: 600; color: #fff; background: var(--brand); border: none; border-radius: 22px; cursor: pointer; white-space: nowrap; }
.cart-btn:hover { background: var(--brand-d); }
.logout { padding: 8px 12px; font-size: 12px; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 18px; cursor: pointer; white-space: nowrap; }
.logout:hover { color: var(--ink); border-color: var(--muted); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; font-size: 12px; text-align: center; background: #fff; color: var(--brand-d); border-radius: 10px; }

.cats { position: sticky; top: 55px; z-index: 15; display: flex; gap: 8px; padding: 10px 18px; background: var(--bg); overflow-x: auto; border-bottom: 1px solid var(--line); }
.cats button { padding: 6px 14px; font-size: 13px; white-space: nowrap; cursor: pointer; background: #fff; border: 1px solid var(--line); border-radius: 16px; color: var(--muted); }
.cats button.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.filterbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 18px; background: var(--bg); border-bottom: 1px solid var(--line); }
.fl-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets button { padding: 4px 12px; font-size: 12px; cursor: pointer; background: #fff; border: 1px solid var(--line); border-radius: 14px; color: var(--muted); }
.presets button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.custom { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.custom input { width: 62px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 12px; }
.custom button { padding: 5px 10px; font-size: 12px; border: 1px solid var(--brand); background: var(--brand); color: #fff; border-radius: 8px; cursor: pointer; }
.custom button.reset { background: #fff; color: var(--muted); border-color: var(--line); }

main { padding: 14px 18px 60px; }
.stat { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.card.in-cart { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(176,130,77,.25); }
.thumb { aspect-ratio: 1/1; background: #eef0f2; cursor: pointer; overflow: hidden; display: flex; align-items: center; justify-content: center; position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .vcount { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.cat-badge { align-self: flex-start; font-size: 11px; color: var(--brand-d); background: #f3ebe0; padding: 2px 8px; border-radius: 10px; }
.name { font-size: 13.5px; font-weight: 600; margin: 0; line-height: 1.35; cursor: pointer; min-height: 36px; }
.name:hover { color: var(--brand-d); }
.prices { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.p-bulk .v { color: var(--bulk); font-size: 18px; }
.p-bulk .v::before, .p-drop .v::before { content: "¥"; font-size: 12px; margin-right: 1px; }
.p-drop .v { color: var(--drop); font-size: 14px; }
.p-bulk .lbl, .p-drop .lbl { font-size: 11px; color: var(--muted); margin-left: 3px; }
.swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.swatches .sw { font-size: 10.5px; color: var(--muted); background: #f3f4f6; border: 1px solid var(--line); border-radius: 10px; padding: 1px 8px; }
.buy { display: flex; gap: 8px; margin-top: auto; align-items: center; }
.qty { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.qty button { width: 28px; height: 30px; border: none; background: #f3f4f6; cursor: pointer; font-size: 16px; color: var(--ink); }
.qty button:hover { background: #e7e9ec; }
.qty .q { width: 44px; height: 30px; border: none; text-align: center; font-size: 14px; outline: none; -moz-appearance: textfield; }
.qty .q::-webkit-outer-spin-button, .qty .q::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.add { flex: 1; height: 32px; border: none; border-radius: 8px; background: var(--brand); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; }
.add:hover { background: var(--brand-d); }

.mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
.drawer, .cart { position: fixed; top: 0; right: 0; height: 100%; width: 430px; max-width: 92vw; background: #fff; z-index: 31; box-shadow: -4px 0 20px rgba(0,0,0,.15); display: flex; flex-direction: column; animation: slideIn .18s ease; }
@keyframes slideIn { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer[hidden], .cart[hidden], .mask[hidden] { display: none !important; }
.dh { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dh h2 { margin: 0; font-size: 16px; }
.close { border: none; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.dbody { padding: 16px 18px; overflow-y: auto; flex: 1; }

.detail-img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 10px; background: #eef0f2; margin-bottom: 14px; }
.detail h3 { margin: 0 0 10px; font-size: 16px; }
.detail .pr { display: flex; gap: 16px; margin-bottom: 8px; align-items: baseline; }
.detail .pr .b { color: var(--bulk); font-size: 22px; font-weight: 700; }
.detail .pr .d { color: var(--drop); font-size: 16px; font-weight: 700; }
.detail .moqline { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.vsel { margin-bottom: 12px; }
.vsel .t { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.vsel .opts { display: flex; gap: 8px; flex-wrap: wrap; }
.vsel .opt { padding: 6px 14px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: #fff; }
.vsel .opt.on { border-color: var(--brand); background: #f3ebe0; color: var(--brand-d); font-weight: 600; }
.vsel .opt.disabled { opacity: .35; cursor: not-allowed; }
/* 图片色卡 */
.opts.colors { gap: 10px; }
.sw-opt { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 76px; padding: 4px; border: 2px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.sw-opt img, .sw-opt .noimg { width: 66px; height: 66px; object-fit: cover; border-radius: 6px; background: #eef0f2; display: block; }
.sw-opt .cap { font-size: 10.5px; line-height: 1.2; color: var(--muted); text-align: center; max-width: 68px; }
.sw-opt.on { border-color: var(--brand); }
.sw-opt.on .cap { color: var(--brand-d); font-weight: 600; }
.sw-opt.disabled { opacity: .4; cursor: not-allowed; }
.spec-tbl { width: 100%; border-collapse: collapse; font-size: 13px; margin: 12px 0; }
.spec-tbl th, .spec-tbl td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.spec-tbl th { color: var(--muted); font-weight: 500; width: 92px; white-space: nowrap; }
.sp { font-size: 13px; color: #444; line-height: 1.7; white-space: pre-wrap; }
.jd { display: inline-block; margin-top: 10px; color: var(--brand-d); }

.cart-items { flex: 1; overflow-y: auto; padding: 8px 14px; }
.ci { display: flex; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.ci img { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; background: #eef0f2; }
.ci .info { flex: 1; min-width: 0; }
.ci .nm { font-size: 13px; font-weight: 600; line-height: 1.3; }
.ci .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.ci .ci-mkt { font-size: 11px; color: #9aa0a6; margin-top: 2px; }
.ci .ci-mkt s { color: #b0b4b9; }
.ci .tier { font-size: 11px; margin-top: 3px; }
.ci .tier.bulk { color: var(--drop); }
.ci .tier.drop { color: var(--muted); }
.ci .hint { color: #d08a2c; }
.ci .row2 { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.ci .sub { font-weight: 700; color: var(--ink); }
.ci .del { border: none; background: none; color: #c0392b; cursor: pointer; font-size: 12px; }
.cart-foot { border-top: 1px solid var(--line); padding: 14px 18px; }
.cart-foot .sum { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 4px; }
.cart-foot .sum b { font-size: 20px; color: var(--bulk); }
.cart-foot .note { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.cart-foot .acts { display: flex; gap: 10px; }
.cart-foot .acts button { flex: 1; height: 40px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid var(--line); }
.cart-foot .export { background: var(--brand); color: #fff; border-color: var(--brand); }
.cart-foot .export:hover { background: var(--brand-d); }
.cart-foot .clear { background: #fff; color: var(--muted); }
.cart-empty { text-align: center; color: var(--muted); padding: 60px 20px; }

@media (max-width: 560px) {
  .brand .sub { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}

/* 滚动锁定：详情/采购单打开时锁背景 */
body.no-scroll { overflow: hidden; }

/* 市场价划线锚点 */
.market-anchor { font-size: 12px; color: #9aa0a6; }
.market-anchor s { color: #b0b4b9; }
.market-anchor.lg { font-size: 14px; margin-bottom: 4px; }

/* 详情次级入口：查看采购单 */
.view-cart { width: 100%; margin-top: 10px; height: 40px; border: 1px solid var(--brand); background: #fff; color: var(--brand-d); border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }
.view-cart:hover { background: #f3ebe0; }

/* 购物车项可点开详情 */
.ci .open-detail { cursor: pointer; }
.ci .nm.open-detail:hover { color: var(--brand-d); }

/* 底部采购单常驻栏 */
.cart-dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 18px; background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(0,0,0,.1); animation: dockUp .25s ease; }
.cart-dock[hidden] { display: none; }
@keyframes dockUp { from { transform: translateY(100%); } to { transform: none; } }
.cart-dock.pulse { animation: pulse .4s; }
@keyframes pulse { 0%,100% { transform: none; } 50% { transform: scale(1.012); } }
.cd-info { display: flex; align-items: baseline; gap: 12px; }
.cd-sum { font-size: 13px; color: var(--muted); }
.cd-total { font-size: 21px; font-weight: 800; color: var(--bulk); }
.cd-btn { padding: 11px 26px; border: none; border-radius: 10px; background: var(--brand); color: #fff; font-size: 15px; font-weight: 700; cursor: pointer; }
.cd-btn:hover { background: var(--brand-d); }
main { padding-bottom: 84px; }

/* Toast */
.toast { position: fixed; top: 76px; left: 50%; transform: translate(-50%, -14px); z-index: 40; padding: 10px 22px; background: rgba(31,35,40,.92); color: #fff; font-size: 14px; border-radius: 22px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
