:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #7c8798;
  --line: #e8eaf0;
  --brand: #4f46e5;
  --brand-soft: #eef0ff;
  --up: #0f9d58;
  --down: #e2504a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }

/* ---------------- 登录 ---------------- */
.login-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #e8eaff 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, #e6f6ff 0%, transparent 55%),
              #f7f8fc;
  z-index: 50;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 22px;
  padding: 30px 26px 22px;
  box-shadow: 0 24px 60px -24px rgba(24, 32, 58, .28);
  border: 1px solid #eef0f6;
}
.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 26px; }
.login-brand h1 { font-size: 19px; margin: 0 0 4px; letter-spacing: .2px; }
.login-brand p { margin: 0; font-size: 12.5px; color: var(--muted); }
.logo {
  width: 46px; height: 46px; border-radius: 14px; flex: none;
  background: linear-gradient(135deg, #5b54ef, #7c6cff 60%, #22c1e8);
  color: #fff; font-weight: 700; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 18px -8px rgba(79, 70, 229, .7);
}
.logo.sm { width: 38px; height: 38px; border-radius: 11px; font-size: 16px; }
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 7px; font-weight: 500; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 11px;
  border: 1px solid var(--line); background: #fbfcfe; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: #b9b8f5; box-shadow: 0 0 0 3px rgba(79, 70, 229, .1); background: #fff; }
.btn-primary {
  width: 100%; padding: 12px; border-radius: 11px; color: #fff; font-weight: 600;
  background: linear-gradient(135deg, #4f46e5, #6366f1 60%, #4f46e5);
  box-shadow: 0 10px 22px -12px rgba(79, 70, 229, .9);
  transition: transform .12s, opacity .15s;
}
.btn-primary:active { transform: scale(.99); }
.btn-primary[disabled] { opacity: .6; cursor: default; }
.login-error { color: var(--down); font-size: 12.5px; min-height: 18px; margin: 10px 0 0; }
.login-tip { font-size: 11.5px; color: #9aa3b2; margin: 14px 0 0; line-height: 1.6; }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; flex: none; background: #fff; border-right: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 26px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14.5px; }
.brand-text span { font-size: 11.5px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 11px;
  color: var(--ink-2); font-size: 13.5px; transition: background .15s, color .15s; text-align: left;
}
.nav-item svg { width: 18px; height: 18px; fill: currentColor; opacity: .75; }
.nav-item:hover { background: #f6f7fb; }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.sync-box {
  display: flex; gap: 9px; align-items: flex-start; padding: 11px 12px;
  background: #f7f8fc; border-radius: 12px; font-size: 11.5px; line-height: 1.5;
}
.sync-box strong { display: block; font-size: 12px; font-weight: 600; }
.sync-box span { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; margin-top: 5px; flex: none; }
.dot.warn { background: #f59e0b; }
.dot.err { background: var(--down); }

.main { flex: 1; min-width: 0; padding: 22px 26px 40px; max-width: 1500px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.topbar-title h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: -.2px; }
.topbar-title p { margin: 0; font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2); font-size: 13px;
  transition: background .15s, border-color .15s, transform .12s;
}
.btn:hover { background: #f8f9fc; border-color: #dcdfe8; }
.btn:active { transform: scale(.985); }
.btn.ghost { background: #fff; }
.btn.sm { padding: 7px 11px; font-size: 12.5px; }
.btn .ico { width: 15px; height: 15px; fill: currentColor; opacity: .8; }
.btn.spin .ico { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-toggle {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 13px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; font-size: 12.5px; color: var(--muted);
}
.icon-toggle svg { width: 16px; height: 16px; fill: currentColor; opacity: .7; }
.icon-toggle.on { background: var(--brand-soft); border-color: #c9c8fb; color: var(--brand); }
.icon-toggle.on svg { opacity: 1; }
.badge-virtual {
  display: inline-block; margin-left: 8px; vertical-align: 2px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  color: var(--brand); background: var(--brand-soft); letter-spacing: 0;
}

/* ---------------- 卡片 / KPI ---------------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 16px 17px;
  border: 1px solid #eef0f5; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi .label { font-size: 12.5px; color: var(--muted); margin-bottom: 9px; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 25px; font-weight: 650; letter-spacing: -.6px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 12.5px; font-weight: 500; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.kpi .sub { margin-top: 8px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.delta-up { color: var(--up); font-weight: 600; }
.delta-down { color: var(--down); font-weight: 600; }
.kpi .accent { position: absolute; right: -20px; top: -20px; width: 74px; height: 74px; border-radius: 50%; background: var(--brand-soft); opacity: .7; }

.grid.two { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; margin-bottom: 16px; }
.card {
  background: var(--card); border-radius: var(--radius); border: 1px solid #eef0f5;
  box-shadow: var(--shadow); padding: 16px 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 600; letter-spacing: -.1px; }
.link { font-size: 12.5px; color: var(--brand); cursor: pointer; }
.muted { color: var(--muted); font-size: 12px; }

.seg { display: flex; background: #f3f4f9; border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { padding: 5px 10px; border-radius: 7px; font-size: 12px; color: var(--muted); }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(16,24,40,.08); font-weight: 600; }

.chart { height: 190px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }

.cat-list { display: flex; flex-direction: column; gap: 10px; max-height: 238px; overflow-y: auto; padding-right: 4px; }
.cat-row { font-size: 12.5px; }
.cat-row .top { display: flex; justify-content: space-between; margin-bottom: 4px; gap: 8px; }
.cat-row .name { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-row .num { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.bar { height: 6px; border-radius: 4px; background: #f0f1f6; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, #6366f1, #8b8bf7); }

/* ---------------- 变化列表 ---------------- */
.change-list { display: flex; flex-direction: column; }
.change-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid #f2f3f7;
}
.change-item:last-child { border-bottom: none; }
.chg-icon {
  width: 32px; height: 32px; border-radius: 9px; flex: none; display: flex;
  align-items: center; justify-content: center; font-size: 16px; font-weight: 700; line-height: 1;
}
.chg-icon.up { background: #e9f8ef; color: var(--up); }
.chg-icon.down { background: #fdecec; color: var(--down); }
.chg-icon.new { background: var(--brand-soft); color: var(--brand); }
.chg-icon.price { background: #fff5e6; color: #d97706; }
.chg-main { flex: 1; min-width: 0; }
.chg-name { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chg-meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.chg-val { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; flex: none; }
.chg-val small { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.pill { display: inline-block; padding: 1px 7px; border-radius: 999px; background: #f2f3f8; color: var(--muted); font-size: 11px; }

/* ---------------- 筛选 ---------------- */
.filters { margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.input {
  padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: #fbfcfe;
  outline: none; min-width: 120px; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: #c3c2f7; box-shadow: 0 0 0 3px rgba(79,70,229,.08); background: #fff; }
.input.sm { padding: 8px 10px; font-size: 12.5px; }
#f-q, #c-q { flex: 1; min-width: 180px; }
.range { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.range .input { width: 84px; min-width: 0; }
.range em { font-style: normal; }
.result-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 12.5px; color: var(--ink-2); }

/* ---------------- 商品 ---------------- */
.product-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 12px;
}
.product {
  background: #fff; border-radius: 14px; border: 1px solid #eef0f5; overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s;
}
.product:hover { transform: translateY(-2px); box-shadow: 0 14px 30px -18px rgba(16,24,40,.3); }
.thumb { position: relative; padding-top: 78%; background: #f5f6fa; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .ph {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 700; color: #c3c8d6; letter-spacing: 1px;
  background: linear-gradient(135deg, #f3f4f9, #eceef7);
}
.product.no-img .thumb { padding-top: 0; height: 0; display: none; }
.badge {
  position: absolute; left: 8px; top: 8px; padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; color: #fff; backdrop-filter: blur(6px);
  background: rgba(15, 23, 42, .55);
}
.badge.out { background: rgba(226, 80, 74, .92); }
.badge.low { background: rgba(217, 119, 6, .92); }
.p-body { padding: 11px 12px 13px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.p-name {
  font-size: 13px; line-height: 1.45; font-weight: 550; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 37px;
}
.p-tag { font-size: 11px; color: var(--muted); }
.p-prices { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.price-sale { font-size: 16px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.price-cost { font-size: 11.5px; color: var(--muted); text-decoration: line-through; }
.p-profit { font-size: 11.5px; color: var(--up); background: #edf9f2; padding: 2px 7px; border-radius: 6px; }
.p-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 6px; border-top: 1px dashed #eef0f5; }
.stock { font-size: 12.5px; color: var(--ink-2); }
.stock b { font-size: 15px; font-variant-numeric: tabular-nums; }
.stock.zero b { color: var(--down); }
.stock.low b { color: #d97706; }
.updated { font-size: 11px; color: #a2aab8; }

.pager { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.pager button {
  min-width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; font-size: 12.5px; color: var(--ink-2); padding: 0 9px;
}
.pager button.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pager button[disabled] { opacity: .45; cursor: default; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; font-size: 13px; }

.chg-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.chg-summary .kpi { padding: 13px 15px; }
.chg-summary .kpi .val { font-size: 20px; }

/* ---------------- 周报 ---------------- */
.weekly-list { display: flex; flex-direction: column; gap: 14px; }
.week-card { background: #fff; border-radius: var(--radius); border: 1px solid #eef0f5; box-shadow: var(--shadow); overflow: hidden; }
.week-head {
  display: flex; align-items: center; justify-content: space-between; padding: 15px 18px;
  cursor: pointer; gap: 12px;
}
.week-head h3 { margin: 0; font-size: 15px; }
.week-head .wnum { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.week-body { padding: 0 18px 18px; border-top: 1px solid #f3f4f8; display: none; }
.week-card.open .week-body { display: block; }
.week-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 14px 0; }
.wk { background: #f9fafc; border-radius: 11px; padding: 11px 13px; }
.wk span { font-size: 11.5px; color: var(--muted); display: block; margin-bottom: 5px; }
.wk b { font-size: 17px; font-variant-numeric: tabular-nums; }
.week-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.week-cols h4 { margin: 0 0 8px; font-size: 12.5px; color: var(--ink-2); }
.mini-row { display: flex; justify-content: space-between; font-size: 12px; padding: 5px 0; border-bottom: 1px dashed #eef0f5; gap: 8px; }
.mini-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row span:last-child { flex: none; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* ---------------- 底部导航（移动端） ---------------- */
.tabbar { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 14px);
  background: rgba(17, 24, 39, .93); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 12.5px; opacity: 0; pointer-events: none; transition: .25s; z-index: 100;
  box-shadow: 0 12px 26px -14px rgba(0,0,0,.7); max-width: 84vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid.two { grid-template-columns: 1fr; }
  .chg-summary { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar { display: none; }
  .main { padding: 14px 14px calc(78px + env(safe-area-inset-bottom)); }
  .topbar { margin-bottom: 14px; align-items: center; }
  .topbar-title h2 { font-size: 18px; }
  .topbar-title p { font-size: 11.5px; }
  .topbar-actions .btn.ghost span { display: none; }
  .topbar-actions .btn { padding: 9px 11px; }
  #sync-btn { font-size: 0; padding: 9px 10px; }
  #sync-btn .ico { width: 17px; height: 17px; margin: 0; }
  .icon-toggle { padding: 9px 10px; }
  .icon-toggle span { display: none; }
  .topbar-title h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
  .badge-virtual { margin-left: 0; font-size: 10px; padding: 1px 6px; vertical-align: 0; }
  .kpis { gap: 10px; }
  .kpi { padding: 13px 14px; border-radius: 14px; }
  .kpi .val { font-size: 21px; }
  .card { padding: 14px; border-radius: 14px; }
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .product { border-radius: 12px; }
  .thumb { padding-top: 64%; }
  .p-body { padding: 9px 10px 11px; gap: 6px; }
  .p-name { font-size: 12px; line-height: 1.4; min-height: 34px; }
  .p-tag { font-size: 10.5px; }
  .price-sale { font-size: 14.5px; }
  .price-cost { font-size: 10.5px; }
  .p-prices { gap: 5px; }
  .p-profit { font-size: 10.5px; padding: 1px 5px; }
  .stock { font-size: 11.5px; }
  .stock b { font-size: 13.5px; }
  .updated { display: none; }
  .badge { font-size: 10px; padding: 2px 6px; left: 6px; top: 6px; }
  .filters { padding: 12px; }
  .filter-row { gap: 8px; }
  .input { flex: 1 1 auto; min-width: 0; }
  #f-q, #c-q { flex-basis: 100%; }
  .filters .input.sm { font-size: 12px; padding: 7px 9px; }
  .range { flex: 1 1 100%; gap: 5px; min-width: 0; }
  .range .input { width: 0; flex: 1 1 0; min-width: 0; }
  .range > span { width: 52px; flex: none; }
  #f-stock { flex: 1 1 auto; }
  #f-reset { flex: 0 0 auto; }
  .cat-list { max-height: none; overflow: visible; }
  .week-kpis { grid-template-columns: repeat(2, 1fr); }
  .week-cols { grid-template-columns: 1fr; }
  .chg-val { font-size: 12.5px; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: rgba(255,255,255,.96); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tab {
    flex: 1; padding: 8px 0; font-size: 11.5px; color: var(--muted); border-radius: 10px;
  }
  .tab.active { color: var(--brand); font-weight: 600; }
}

@media (max-width: 359px) {
  .product-grid { grid-template-columns: 1fr; }
}
