:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #101828;
  --muted: #6b7a8d;
  --faint: #94a3b8;
  --brand: #0d4f43;
  --brand-2: #17795f;
  --brand-soft: #e6f2ee;
  --line: #e8ecf1;
  --warn: #d97706;
  --warn-soft: #fdf3e3;
  --danger: #d92d20;
  --danger-soft: #fdeceb;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  max-width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#app {
  max-width: 620px;
  width: 100%;
  margin: 0 auto;
  min-height: 100vh;
  overflow-x: hidden;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  background: rgba(242, 244, 247, .88);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
}

.topbar h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .2px;
}

.subline {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

.topbar-right { display: flex; gap: 6px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--brand);
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
  transition: transform .15s ease, background .15s ease;
}
.icon-btn:active { transform: scale(.94); background: var(--brand-soft); }
.icon-btn.spin svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 错误提示 */
.banner {
  margin: 0 18px 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: #8a1c14;
  font-size: 13px;
  line-height: 1.5;
}
.banner.hidden { display: none; }

.view { padding: 0 18px 24px; }

/* 概览主卡 */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  padding: 22px 22px 20px;
  color: #eafaf4;
  background: linear-gradient(140deg, #0b3f36 0%, #10614f 52%, #1a8a6c 100%);
  box-shadow: 0 12px 28px rgba(13, 79, 67, .28);
}
.hero::after {
  content: "";
  position: absolute;
  right: -60px; top: -70px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .16), transparent 62%);
}
.hero-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: rgba(234, 250, 244, .78);
  letter-spacing: .4px;
}
.hero-amount {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 8px 0 2px;
  font-weight: 750;
  letter-spacing: -.5px;
  font-variant-numeric: tabular-nums;
}
.hero-amount .num { font-size: 40px; line-height: 1.05; }
.hero-amount .unit { font-size: 17px; font-weight: 600; opacity: .9; }
.hero-exact {
  font-size: 12px;
  color: rgba(234, 250, 244, .66);
  font-variant-numeric: tabular-nums;
}
.hero-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, .14);
}
.hero-grid div { min-width: 0; }
.hero-grid div span { display: block; font-size: 11px; color: rgba(234, 250, 244, .68); }
.hero-grid div b {
  font-size: 16px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* 卡片 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px;
  margin-top: 14px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title {
  font-size: 14.5px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 7px;
}
.card-title .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand-2);
}
.card-sub { font-size: 12px; color: var(--muted); }

/* 指标网格 */
.kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.kpi {
  min-width: 0;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 15px;
  box-shadow: var(--shadow);
}
.kpi .label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.kpi .val {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.3px;
  font-variant-numeric: tabular-nums;
}
.kpi .val small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.kpi .hint { margin-top: 3px; font-size: 11.5px; color: var(--faint); }
.kpi.warn .val { color: var(--warn); }
.kpi.danger .val { color: var(--danger); }

/* 仓库占比 */
.wh-item { padding: 9px 0; }
.wh-item + .wh-item { border-top: 1px solid var(--line); }
.wh-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 13.5px;
}
.wh-top b { font-variant-numeric: tabular-nums; font-weight: 650; }
.wh-top .pct { color: var(--muted); font-size: 11.5px; margin-left: 4px; font-weight: 500; }
.bar {
  height: 7px;
  margin-top: 7px;
  border-radius: 99px;
  background: #eef1f5;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #17795f, #38b28a);
}
.bar.amber > i { background: linear-gradient(90deg, #d97706, #f5b445); }

/* 商品列表 */
.rows { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  cursor: pointer;
  transition: background .15s;
}
.row + .row { border-top: 1px solid var(--line); }
.row:active { background: #f7f9fb; }
.rank {
  flex: 0 0 22px;
  font-size: 12px;
  font-weight: 700;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.row-main { min-width: 0; flex: 1; }
.row-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-meta {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-right { text-align: right; flex: 0 0 auto; }
.row-amount {
  font-size: 14.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.row-qty {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.p-label {
  font-size: 10px;
  color: var(--faint);
  letter-spacing: .5px;
  margin-bottom: 1px;
}
/* 客户历史成交价（点商品展开） */
.hist-tip { color: var(--brand); font-weight: 600; }
.stock-link {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 9px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font: inherit;
  font-size: 11.5px;
  font-weight: 650;
  cursor: pointer;
}
.stock-link:active { opacity: .75; }
.sale-sum {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f5f8f7;
}
.sale-sum div { min-width: 0; }
.sale-sum span { display: block; font-size: 11px; color: var(--muted); }
.sale-sum b { font-size: 14px; font-variant-numeric: tabular-nums; }
.hist-btn {
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.hist-box {
  border-top: 1px dashed var(--line);
  padding: 6px 0 8px 0;
  margin: 0 0 4px;
}
.hist-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.hist-line .hd { flex: 0 0 74px; color: var(--faint); font-size: 11.5px; }
.hist-line .hp { font-weight: 700; color: var(--ink); }
.hist-line .hu { color: var(--faint); font-size: 11px; }
.hist-line .hq { margin-left: auto; text-align: right; }

.tunnel-row { display: flex; gap: 8px; align-items: center; }.tunnel-row input { flex: 1 1 auto; min-width: 0; font-size: 12.5px; }
.btn-mini {
  flex: 0 0 auto; height: 38px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--brand); background: #fff; color: var(--brand);
  font-size: 13px; font-weight: 600;
}
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
.field label.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); margin: 0 0 2px; }
.switch input { width: 18px; height: 18px; accent-color: var(--brand); flex: 0 0 auto; margin: 0; }
.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 600;
  vertical-align: 1px;
  background: var(--brand-soft);
  color: var(--brand);
}
.tag.gray { background: #f1f3f6; color: var(--muted); }
.tag.type {
  background: #eef4ff;
  color: #1d4ed8;
  max-width: 8em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  vertical-align: 1px;
}
.tag.amber { background: var(--warn-soft); color: var(--warn); }
.tag.red { background: var(--danger-soft); color: var(--danger); }

/* 搜索与筛选 */
.searchbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 14px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
}
.searchbar svg { flex: 0 0 auto; color: var(--faint); }
.searchbar input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  font: inherit;
  font-size: 15px;
  background: transparent;
  color: var(--ink);
}
.searchbar input::placeholder { color: var(--faint); }
.searchbar .clear { color: var(--faint); font-size: 12px; padding: 2px 4px; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 2px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 99px;
  background: #fff;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
  transition: .15s;
}
.chip.on {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 4px 12px rgba(13, 79, 67, .24);
}
.chip.warn-on { background: var(--warn); box-shadow: 0 4px 12px rgba(217, 119, 6, .24); }

.sortrow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 2px 2px;
  font-size: 12px;
  color: var(--muted);
}
.sortrow .sorts { display: flex; gap: 10px; }
.sortrow button { font-size: 12px; color: var(--muted); padding: 2px 0; font-weight: 600; }
.sortrow button.on { color: var(--brand); }
.sortrow button.on::after { content: " ↑"; font-size: 10px; }

.loadmore {
  margin: 14px auto 0;
  display: block;
  padding: 11px 26px;
  border-radius: 99px;
  background: #fff;
  color: var(--brand);
  font-size: 13.5px;
  font-weight: 650;
  box-shadow: var(--shadow);
}

/* 预警条目 */
.warn-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
}
.warn-item + .warn-item { border-top: 1px solid var(--line); }
.warn-flag {
  flex: 0 0 4px;
  align-self: stretch;
  border-radius: 99px;
  background: linear-gradient(180deg, #f0a028, #d97706);
}

/* 空状态 / 骨架 */
.empty {
  padding: 46px 0;
  text-align: center;
  color: var(--faint);
  font-size: 13.5px;
}
.empty .big { font-size: 30px; margin-bottom: 6px; }
.skeleton { padding: 22px; }
.sk-line {
  height: 12px;
  border-radius: 8px;
  background: linear-gradient(90deg, #eceff3 25%, #f5f7f9 37%, #eceff3 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s infinite;
  margin-bottom: 10px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* 底部导航 */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: space-around;
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .93);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(16, 24, 40, .06);
  max-width: 620px;
  margin: 0 auto;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0 4px;
  border-radius: 12px;
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 600;
  transition: color .15s;
}
.tab svg { width: 21px; height: 21px; }
.tab.active { color: var(--brand); }
.tab.active svg { filter: drop-shadow(0 2px 6px rgba(13, 79, 67, .22)); }

/* 底部弹层 */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; }
.sheet.hidden { display: none; }
.sheet-mask {
  position: absolute; inset: 0;
  background: rgba(16, 24, 40, .42);
  backdrop-filter: blur(2px);
  animation: fade .2s ease;
}
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  max-height: 86vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 22px 22px 0 0;
  padding: 8px 20px calc(22px + env(safe-area-inset-bottom));
  animation: slideUp .26s cubic-bezier(.2, .9, .3, 1);
  box-shadow: 0 -10px 40px rgba(16, 24, 40, .18);
  overscroll-behavior: contain;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-grip {
  width: 38px; height: 4px;
  border-radius: 99px;
  background: #dde2e8;
  margin: 4px auto 12px;
}
.sheet h3 { margin: 4px 0 2px; font-size: 18px; font-weight: 700; }
.sheet .sheet-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; }

.detail-hero {
  border-radius: 16px;
  padding: 16px 18px;
  background: linear-gradient(140deg, #0b3f36, #17795f);
  color: #eafaf4;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}
.detail-hero .l span { font-size: 11.5px; opacity: .75; display: block; }
.detail-hero .l b { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.detail-hero .r { text-align: right; font-size: 11.5px; opacity: .85; line-height: 1.6; }

.kv {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 10px;
  margin-top: 16px;
}
.kv div span { display: block; font-size: 11.5px; color: var(--muted); }
.kv div b { font-size: 14.5px; font-weight: 650; font-variant-numeric: tabular-nums; }

.section-label {
  margin: 18px 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .4px;
}

/* 设置表单 */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input, .field select {
  width: 100%;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 12px;
  padding: 12px 13px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  outline: 0;
}
.field input:focus { border-color: var(--brand-2); background: #fff; }
.field .tip { margin-top: 5px; font-size: 11px; color: var(--faint); }
.btn-primary {
  width: 100%;
  margin-top: 6px;
  padding: 14px;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(13, 79, 67, .22);
}
.btn-primary:active { transform: scale(.99); opacity: .92; }
.btn-ghost {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border-radius: 14px;
  background: #f1f4f7;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.note {
  margin-top: 14px;
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.6;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  z-index: 60;
  padding: 10px 18px;
  border-radius: 99px;
  background: rgba(16, 24, 40, .9);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  transition: .2s ease;
  pointer-events: none;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (min-width: 480px) {
  .hero-amount .num { font-size: 46px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

/* 开关行（覆盖 .field 的通用样式） */
.field label.switch {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; color: var(--ink); margin: 0 0 2px;
}
.field label.switch input[type="checkbox"] {
  width: 18px; height: 18px; padding: 0; flex: 0 0 auto;
  accent-color: var(--brand); border-radius: 4px;
}

/* 单位切换 */
.unit-chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px;
  -webkit-overflow-scrolling: touch;
}
.unit-chip {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 8px 12px; font-size: 13.5px; color: var(--ink); font-weight: 600;
  font-family: inherit;
}
.unit-chip em { font-style: normal; font-size: 10.5px; font-weight: 400; color: var(--faint); }
.unit-chip.on {
  border-color: var(--brand); background: #edf7f2; color: var(--brand);
  box-shadow: 0 0 0 2px rgba(11,81,55,.08);
}
.unit-chip.on em { color: var(--brand-2); }

/* 货品页 */
.list-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 4px 8px; font-size: 12px; color: var(--faint);
}
.tag.green { background: #e9f6ef; color: #0b7a54; }
