:root {
  --brand: #1f4dd8;
  --brand-dark: #16389e;
  --brand-soft: #eef3ff;
  --ok: #12a150;
  --warn: #d97706;
  --danger: #dc2626;
  --ink: #101828;
  --ink-2: #475467;
  --ink-3: #98a2b3;
  --line: #e6e9f0;
  --bg: #f5f7fb;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 20px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
[hidden] { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--ink-2); }
.tiny { font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: linear-gradient(120deg, #16389e, #1f4dd8 55%, #2f6bff);
  color: #fff; box-shadow: 0 2px 14px rgba(16, 24, 40, .18);
}
.topbar-in { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; letter-spacing: .3px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px; background: rgba(255, 255, 255, .18);
  display: grid; place-items: center; font-size: 16px;
}
.brand small { display: block; font-weight: 400; font-size: 11px; opacity: .82; letter-spacing: 0; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav button {
  background: transparent; border: 0; color: rgba(255, 255, 255, .85); font: inherit; font-size: 13.5px;
  padding: 7px 13px; border-radius: 9px; cursor: pointer; transition: .15s;
}
.nav button:hover { background: rgba(255, 255, 255, .13); color: #fff; }
.nav button.on { background: #fff; color: var(--brand-dark); font-weight: 600; }
.topbar .who { font-size: 12.5px; text-align: right; line-height: 1.35; }
.topbar .who b { font-size: 13.5px; }

/* --------------------------------------------------------------- layout */
.wrap { max-width: 1280px; margin: 0 auto; padding: 18px 16px 90px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-h { padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-h h3 { margin: 0; font-size: 15px; }
.card-b { padding: 16px; }
.card-b.tight { padding: 0; }

/* -------------------------------------------------------------- controls */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); padding: 8px 14px; transition: .15s; white-space: nowrap;
}
button:hover, .btn:hover { border-color: #cfd6e4; background: #fafbff; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn-ok:hover { filter: brightness(.94); }
.btn-danger { background: #fff; border-color: #f3c1c1; color: var(--danger); }
.btn-danger:hover { background: #fff5f5; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); padding: 6px 8px; }
.btn-ghost:hover { background: var(--brand-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { padding: 12px 22px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; justify-content: center; }

input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); width: 100%; transition: .15s;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 77, 216, .1); }
textarea { resize: vertical; min-height: 64px; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; font-weight: 500; }
label.f > span b { color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
.search { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; min-width: 220px; }
.search input { border: 0; box-shadow: none !important; padding-left: 0; }
.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 13px;
  font-size: 13px; cursor: pointer; white-space: nowrap; color: var(--ink-2);
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }

/* ---------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #fafbfe; color: var(--ink-2); font-weight: 600; font-size: 12.5px; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
tbody tr:hover { background: #fbfcff; }
.tbl-scroll { overflow: auto; max-height: 70vh; }
.empty { padding: 46px 16px; text-align: center; color: var(--ink-3); }
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }

/* --------------------------------------------------------------- badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.7; white-space: nowrap; }
.b-pending { background: #fff7e6; color: #b45309; }
.b-processing { background: #eaf2ff; color: #1d4ed8; }
.b-shipped { background: #e8f8ef; color: #0f7a3d; }
.b-cancelled { background: #f4f5f7; color: #667085; }
.b-ok { background: #e8f8ef; color: #0f7a3d; }
.b-off { background: #f4f5f7; color: #667085; }
.b-warn { background: #fef3c7; color: #92400e; }
.b-danger { background: #fee2e2; color: #b91c1c; }
.b-brand { background: var(--brand-soft); color: var(--brand-dark); }

/* ---------------------------------------------------------------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 23px; font-weight: 700; margin-top: 5px; letter-spacing: -.4px; }
.stat .s { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.stat.hl { background: linear-gradient(135deg, #1f4dd8, #2f6bff); border-color: transparent; color: #fff; }
.stat.hl .k, .stat.hl .s { color: rgba(255, 255, 255, .85); }

/* -------------------------------------------------------------- products */
.grid-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 14px; }
.p-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); transition: .18s; }
.p-card:hover { transform: translateY(-2px); box-shadow: 0 8px 26px rgba(16, 24, 40, .11); }
.p-img { height: 190px; display: grid; place-items: center; font-size: 46px; background: linear-gradient(140deg, #eef3ff, #f7f9ff); position: relative; overflow: hidden; }
.p-img .stock-tag { position: absolute; top: 8px; left: 8px; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .92); font-weight: 600; }
.p-body { padding: 11px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.p-name { font-weight: 600; font-size: 13.5px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 38px; }
.p-meta { font-size: 11.5px; color: var(--ink-3); display: flex; gap: 8px; flex-wrap: wrap; }
.p-price { display: flex; align-items: baseline; gap: 7px; margin-top: auto; }
.p-price .now { font-size: 19px; font-weight: 700; color: var(--brand-dark); }
.p-price .was { font-size: 12px; color: var(--ink-3); text-decoration: line-through; }
.p-actions { display: flex; gap: 7px; }
.p-actions button { flex: 1; }

/* ---------------------------------------------------------------- cart */
.cart-fab {
  position: fixed; right: 20px; bottom: 22px; z-index: 50; background: var(--brand); color: #fff;
  border: 0; border-radius: 999px; padding: 13px 20px; font-weight: 600; font-size: 14.5px;
  box-shadow: 0 10px 28px rgba(31, 77, 216, .38); display: flex; align-items: center; gap: 9px;
}
.cart-fab:hover { background: var(--brand-dark); }
.cart-fab .n { background: #fff; color: var(--brand-dark); border-radius: 999px; font-size: 12px; min-width: 20px; text-align: center; padding: 1px 5px; }
.drawer-mask { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 60; display: flex; justify-content: flex-end; }
.drawer { width: 100%; max-width: 430px; background: #fff; display: flex; flex-direction: column; animation: slideIn .22s ease; }
@keyframes slideIn { from { transform: translateX(24px); opacity: .4; } }
.modal-mask { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 620px; max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; }
.modal.wide { max-width: 900px; }
.modal-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-h h3 { margin: 0; font-size: 16px; }
.modal-b { padding: 18px; overflow: auto; }
.modal-f { padding: 13px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: #fcfcfe; }
.line-item { display: flex; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); align-items: center; }
.line-item .ic { position: relative; width: 42px; height: 42px; border-radius: 10px; background: var(--brand-soft); display: grid; place-items: center; font-size: 21px; flex: 0 0 auto; overflow: hidden; }
.line-item .ic img { position: absolute; inset: 0; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.qty { display: flex; align-items: center; gap: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.qty button { border: 0; border-radius: 0; padding: 4px 9px; background: #fafbfe; }
.qty input { width: 54px; text-align: center; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 0; padding: 5px 0; box-shadow: none !important; }
.sum-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; }
.sum-row.total { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 10px; font-size: 16px; font-weight: 700; }
.notice { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 10px; padding: 9px 12px; font-size: 13px; }
.notice.blue { background: var(--brand-soft); border-color: #cddcff; color: var(--brand-dark); }
.notice.red { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.notice.green { background: #ecfdf3; border-color: #bbf7d0; color: #0f7a3d; }

/* ---------------------------------------------------------------- misc */
.toast-wrap { position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #101828; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13.5px; box-shadow: 0 8px 24px rgba(16, 24, 40, .3); animation: fadeDown .2s; max-width: 88vw; }
.toast.ok { background: #0f7a3d; }
.toast.err { background: #b91c1c; }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-8px); } }
.auth-wrap { max-width: 940px; margin: 40px auto; display: grid; grid-template-columns: 1.05fr .95fr; gap: 22px; align-items: start; }
.hero { background: linear-gradient(150deg, #16389e, #2f6bff); color: #fff; border-radius: 18px; padding: 30px 28px; }
.hero h1 { margin: 0 0 10px; font-size: 25px; line-height: 1.35; }
.hero p { margin: 0 0 16px; opacity: .9; font-size: 14px; }
.hero ul { padding-left: 18px; margin: 0; opacity: .95; font-size: 13.5px; line-height: 1.9; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { border: 0; background: transparent; border-bottom: 2px solid transparent; border-radius: 0; padding: 9px 12px; color: var(--ink-2); font-weight: 600; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.pick-list { font-size: 12px; }
.pick-list td { padding: 6px 8px; }
/* ---------------------------------------------------------------- images */
/* 图片必须绝对定位铺满图片框：否则大图会撑开网格行、溢出并把下面的商品名/价格盖住
   同时写 top/left，兼容不支持 inset 的老版微信内置浏览器 */
.p-img img { position: absolute; inset: 0; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.p-img.clickable { cursor: pointer; }
.p-img .img-count {
  position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: rgba(16, 24, 40, .62); color: #fff; font-weight: 600;
}
.thumb { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); background: #fff; display: block; }
.thumb-sm { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; border: 1px solid var(--line); background: #fff; display: block; }
.thumb-ph {
  width: 38px; height: 38px; border-radius: 8px; border: 1px dashed var(--line); background: #fafbfe;
  display: grid; place-items: center; font-size: 17px;
}
.gal { display: flex; gap: 14px; flex-wrap: wrap; }
.gal-main {
  width: 290px; max-width: 100%; height: auto; object-fit: contain; background: #fff;
  border: 1px solid var(--line); border-radius: 12px; flex: 0 0 auto;
}
.gal-ph { width: 290px; max-width: 100%; aspect-ratio: 1 / 1; border-radius: 12px; border: 1px dashed var(--line); background: #fafbfe; display: grid; place-items: center; font-size: 74px; }
.gal-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.gal-thumbs img { width: 58px; height: 58px; object-fit: cover; border-radius: 9px; border: 2px solid transparent; cursor: pointer; background: #fff; }
.gal-thumbs img.on { border-color: var(--brand); }
.img-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.img-cell { position: relative; width: 86px; height: 86px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #fafbfe; }
.img-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-cell .del {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; padding: 0; border-radius: 999px;
  background: rgba(16, 24, 40, .66); color: #fff; border: 0; font-size: 12px; line-height: 1; cursor: pointer;
}
.img-cell .main-tag { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(16, 24, 40, .6); color: #fff; font-size: 10.5px; text-align: center; }
.img-cell .setmain {
  position: absolute; left: 3px; top: 3px; font-size: 10.5px; padding: 1px 6px; border-radius: 999px;
  background: rgba(255, 255, 255, .92); border: 1px solid var(--line); cursor: pointer;
}
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
}
@media (max-width: 860px) {
  .auth-wrap { grid-template-columns: 1fr; margin: 16px auto; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .wrap { padding: 14px 12px 96px; }
  .topbar-in { padding: 9px 12px; gap: 9px; }
  .brand span.t { display: none; }
  .nav button { padding: 6px 10px; font-size: 13px; }
  .topbar .who { display: none; }
  table { font-size: 12.5px; }
  th, td { padding: 8px 9px; }
  .grid-products { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 10px; }
  .p-img { height: 150px; font-size: 38px; }
  .cart-fab { right: 12px; bottom: 14px; padding: 12px 16px; }
}

/* 商品图展示框统一成正方形：图片导出时已补白边成 1:1，
   这里让框也是 1:1，object-fit:cover 就不会再裁掉任何内容（之前竖版图上下被切就是这个原因） */
@supports (aspect-ratio: 1 / 1) {
  .p-img { height: auto; aspect-ratio: 1 / 1; }
  .gal-main { aspect-ratio: 1 / 1; height: auto; }
  .gal-thumbs img { aspect-ratio: 1 / 1; }
}
