/* ============================================================
   个人记账本 · 设计系统
   方向：精密账册（Precision Ledger）
   - 纸感留白 + 极细分隔线，替代"万物皆卡片"
   - 金额一律等宽数字，纵向对齐便于扫读
   - 单一品牌色（青绿）作"印泥"；状态另有文字/符号兜底，不靠颜色单独表意
   ============================================================ */

:root {
  /* ---------- 品牌色阶（青绿） ---------- */
  --brand-50:  #eaf6f5;
  --brand-100: #cfe9e7;
  --brand-200: #a5d8d5;
  --brand-300: #6fc2be;
  --brand-400: #35b0aa;
  --brand-500: #0e9e99;   /* 主色：填充/图标 */
  --brand-600: #0a7c78;   /* 文本安全色（白底 4.6:1） */
  --brand-700: #08615e;
  --brand-900: #04302f;

  /* ---------- 语义色（文本色均满足 AA 4.5:1） ---------- */
  --success-fill: #16a34a;
  --success-text: #0f7a3d;
  --warning-fill: #d97706;
  --warning-text: #98520a;
  --danger-fill:  #dc2626;
  --danger-text:  #b91c1c;

  /* ---------- 中性色（向品牌色偏移，避免死灰） ---------- */
  --ink-1: #0e1a1c;
  --ink-2: #3f5155;
  --ink-3: #6b7c81;
  --ink-4: #9aa9ad;

  --paper:   #f5f7f7;
  --surface: #ffffff;
  --surface-2: #f8fafa;
  --line:    #e3e9e9;
  --line-strong: #d3dcdc;

  /* ---------- 间距阶（4px 基准） ---------- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

  /* ---------- 圆角 ---------- */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;

  /* ---------- 阴影（少而克制） ---------- */
  --shadow-1: 0 1px 2px rgba(14, 26, 28, .05);
  --shadow-2: 0 2px 8px rgba(14, 26, 28, .07), 0 1px 2px rgba(14, 26, 28, .04);
  --shadow-3: 0 10px 24px -8px rgba(14, 26, 28, .22);

  /* ---------- 动效（指数缓出，避免回弹） ---------- */
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --dur-1: 120ms; --dur-2: 220ms; --dur-3: 380ms;

  /* ---------- 排版 ---------- */
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", sans-serif;

  --fs-12: 12px; --fs-13: 13px; --fs-15: 15px; --fs-17: 17px;
  --fs-20: 20px; --fs-26: 26px; --fs-32: 32px;

  --tabbar-h: 62px;
}

/* ---------------- 暗色模式 ---------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --brand-50:  #0d2b2a;
    --brand-100: #113f3d;
    --brand-200: #17524f;
    --brand-300: #1f6a66;
    --brand-400: #26a09a;
    --brand-500: #2bb3ad;
    --brand-600: #4cc9c3;
    --brand-700: #8adbd6;

    --success-text: #4ade80;
    --warning-text: #fbbf24;
    --danger-text:  #f87171;

    --ink-1: #eef4f4;
    --ink-2: #c3d0d2;
    --ink-3: #93a4a8;
    --ink-4: #6d7d81;

    --paper:   #0d1415;
    --surface: #141d1e;
    --surface-2: #192325;
    --line:    #223031;
    --line-strong: #2e3f40;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 2px 10px rgba(0, 0, 0, .45);
    --shadow-3: 0 12px 28px -10px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--paper); color: var(--ink-1);
  font-family: var(--font); font-size: var(--fs-15); line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-size-adjust: 100%;
  overflow-x: hidden;   /* 任何内容都不允许把整页撑宽 */
}

/* 所有数字：等宽，保证纵向对齐 */
.num, .amount, .sheet-total, .kpi-v, .rank-top .val, .rank-top .cnt,
.chart-value, .sheet-grid .v, .ledger-row .m, .record .amt, .pay-row .amt,
.total-line b, .savebar .info .v, .search-bar input {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.hidden { display: none !important; }
.muted { color: var(--ink-3); }
.error { color: var(--danger-text); font-size: var(--fs-13); min-height: 18px; margin: var(--sp-2) 0 0; }
.ok { color: var(--success-text); }
.warn { color: var(--warning-text); }
.card-title .ok, .card-sub .ok, .card-sub .warn { font-weight: 600; }

:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; border-radius: var(--r-sm); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.screen { height: 100%; }
.site-registration { padding: 6px 12px; text-align: center; font-size: 12px; background: var(--paper); }
.site-registration a { color: var(--ink-3); text-decoration: none; }
.site-registration a:hover { text-decoration: underline; }

/* ============================ 登录 ============================ */
#login-screen { display: flex; align-items: center; justify-content: center; padding: var(--sp-6); }
.login-box {
  width: 100%; max-width: 330px; text-align: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: var(--sp-8) var(--sp-5) var(--sp-6);
  box-shadow: var(--shadow-2);
}
.login-logo {
  width: 62px; height: 62px; margin: 0 auto var(--sp-4);
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, var(--brand-400), var(--brand-600));
  color: #fff; border-radius: 20px; font-size: var(--fs-26); font-weight: 700;
  box-shadow: var(--shadow-3);
}
.login-box h1 { font-size: var(--fs-20); margin: 0 0 var(--sp-1); letter-spacing: -.01em; }
.login-box p { margin: 0 0 var(--sp-4); font-size: var(--fs-13); }

/* ============================ 表单元素 ============================ */
input, select, textarea {
  width: 100%; padding: 12px 14px; font-size: 16px; font-family: inherit;
  color: var(--ink-1); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  outline: none; min-height: 46px;
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
input::placeholder, textarea::placeholder { color: var(--ink-4); }
input:focus, select:focus, textarea:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 18%, transparent);
}
select { appearance: none; background-image: none; padding-right: 34px; }
.readonly, input[readonly] { background: var(--surface-2); color: var(--ink-2); }
input[type="date"], input[type="month"], input[type="datetime-local"] { font-variant-numeric: tabular-nums; }

/* ============================ 按钮 ============================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  width: 100%; min-height: 46px; padding: 12px 16px; margin-top: var(--sp-3);
  font-size: var(--fs-15); font-weight: 600; font-family: inherit;
  color: #fff; background: var(--brand-500); border: none; border-radius: var(--r-md);
  cursor: pointer;
  transition: transform var(--dur-1) var(--ease-out), background var(--dur-1), box-shadow var(--dur-1);
}
.btn:hover { background: var(--brand-600); }
.btn:active { transform: scale(.985); }
.btn.ghost { background: var(--surface); color: var(--ink-1); border: 1px solid var(--line-strong); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--brand-300); }
.btn.danger { background: transparent; color: var(--danger-text); border: 1px solid color-mix(in srgb, var(--danger-fill) 42%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger-fill) 8%, transparent); }
.btn.small { width: auto; min-height: 38px; padding: 8px 14px; font-size: var(--fs-13); margin: 0; border-radius: var(--r-sm); }

/* ============================ 主框架 ============================ */
#app-screen { display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: var(--sp-1);
  height: 54px; padding: 0 var(--sp-2) 0 var(--sp-1);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  flex: 1; font-size: var(--fs-17); font-weight: 600; margin: 0;
  letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px; flex: none; display: flex; align-items: center; justify-content: center;
  font-size: 19px; color: var(--ink-3); background: none; border: none; border-radius: var(--r-full);
  cursor: pointer; transition: background var(--dur-1), color var(--dur-1);
}
.icon-btn svg {
  width: 20px; height: 20px; display: block;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn:hover { color: var(--ink-1); background: var(--surface-2); }
.icon-btn:active { background: var(--brand-50); }

main {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: var(--sp-4) var(--sp-4) calc(var(--tabbar-h) + 72px);
}

/* ============================ 底部导航 ============================ */
.tabbar {
  position: sticky; bottom: 0; z-index: 6;
  display: flex; align-items: stretch;
  padding: 0 var(--sp-2) env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative; flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  min-height: var(--tabbar-h); padding-top: 6px;
  font-size: 11.5px; font-family: inherit; color: var(--ink-3);
  background: none; border: none; cursor: pointer;
  transition: color var(--dur-1);
}
.tab svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--brand-600); font-weight: 600; }
.tab.active::before {
  content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 26px; height: 2.5px; border-radius: var(--r-full); background: var(--brand-500);
}
.tab:active { color: var(--brand-500); }

.fab {
  position: fixed; right: var(--sp-4); z-index: 7;
  bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1; color: #fff; font-family: inherit;
  background: linear-gradient(150deg, var(--brand-400), var(--brand-600));
  border: none; border-radius: var(--r-full); box-shadow: var(--shadow-3);
  cursor: pointer;
  transition: transform var(--dur-2) var(--ease-out), box-shadow var(--dur-2);
}
.fab:hover { transform: translateY(-1px); }
.fab:active { transform: scale(.94); }

/* ============================ 结算单 ============================ */
.sheet {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-2);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  margin-bottom: var(--sp-3);
}
.sheet::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--brand-500), var(--brand-300));
}
.sheet-label { font-size: var(--fs-12); letter-spacing: .06em; color: var(--ink-3); font-weight: 600; }
.sheet-total { font-size: var(--fs-32); font-weight: 700; letter-spacing: -.02em; line-height: 1.15; margin: 2px 0 var(--sp-1); }
.sheet-sub { font-size: var(--fs-13); color: var(--ink-3); overflow-wrap: anywhere; }
.sheet-rule { border: 0; border-top: 1px dashed var(--line-strong); margin: var(--sp-3) 0; }
.sheet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.sheet-grid .k { display: block; font-size: var(--fs-12); color: var(--ink-3); margin-bottom: 1px; }
.sheet-grid .v { font-size: var(--fs-17); font-weight: 650; }

.progress { margin-top: var(--sp-3); }
.progress-head { display: flex; justify-content: space-between; font-size: var(--fs-12); color: var(--ink-3); margin-bottom: 5px; }
.progress-track { height: 7px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.progress-fill { height: 100%; border-radius: var(--r-full); background: linear-gradient(90deg, var(--brand-500), var(--brand-300)); transition: width var(--dur-3) var(--ease-out); }
.insight {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-top: var(--sp-3); padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-13); color: var(--ink-2);
  background: var(--brand-50); border-radius: var(--r-md);
}
.insight .dot { width: 7px; height: 7px; border-radius: var(--r-full); background: var(--brand-500); flex: none; }

/* ============================ 动作条 ============================ */
.actions { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.actions .btn { width: auto; flex: 1 1 auto; min-width: 92px; margin: 0; }

/* ============================ 分区与账册行 ============================ */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: var(--sp-5) 2px var(--sp-2); }
.section-head h2 { font-size: var(--fs-15); font-weight: 650; margin: 0; }
.section-head span { font-size: var(--fs-12); color: var(--ink-3); font-variant-numeric: tabular-nums; }

.year-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: var(--sp-5) 2px var(--sp-1); padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.year-head b { font-size: var(--fs-13); letter-spacing: .04em; color: var(--ink-2); }
.year-head span { font-size: var(--fs-12); color: var(--ink-3); font-variant-numeric: tabular-nums; }

.ledger-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 2px; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--line);
  font-family: inherit; color: inherit; cursor: pointer;
  transition: background var(--dur-1);
}
.ledger-row:active { background: var(--brand-50); }
.ledger-row .m {
  flex: none; width: 48px; font-size: var(--fs-20); font-weight: 700;
  letter-spacing: -.02em; color: var(--ink-1); font-variant-numeric: tabular-nums;
}
.ledger-row .m i { font-style: normal; font-size: 11px; font-weight: 500; color: var(--ink-4); margin-left: 1px; }
.ledger-row .body { flex: 1; min-width: 0; }
.ledger-row .line1 { font-size: var(--fs-13); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ledger-row .line2 { display: flex; align-items: center; gap: 6px; margin-top: 5px; }
.ledger-row .amt { flex: none; text-align: right; }
.ledger-row .amt b { display: block; font-size: var(--fs-15); font-variant-numeric: tabular-nums; }

.bar { flex: 1; height: 4px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-500), var(--brand-300)); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; font-size: 11.5px; font-weight: 600; border-radius: var(--r-full);
  border: 1px solid transparent; white-space: nowrap;
}
.badge.settled { color: var(--success-text); background: color-mix(in srgb, var(--success-fill) 12%, transparent); }
.badge.due { color: var(--warning-text); background: color-mix(in srgb, var(--warning-fill) 14%, transparent); }
.badge.neutral { color: var(--ink-2); background: var(--surface-2); border-color: var(--line); }

/* ============================ 记录行 ============================ */
.record {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 2px; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--line);
  font-family: inherit; color: inherit; cursor: pointer;
}
.record:active { background: var(--brand-50); }
.record .date {
  flex: none; width: 78px; text-align: left;
  font-size: 11px; color: var(--ink-4); line-height: 1.35;
  font-variant-numeric: tabular-nums;
}
.record .date b {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-1);
  letter-spacing: -.01em; white-space: nowrap;
}
.record .date span { white-space: nowrap; }
.record .body { flex: 1; min-width: 0; }
.record .t1 { font-size: var(--fs-15); font-weight: 600; letter-spacing: -.005em; }
.record .t2 { font-size: var(--fs-13); color: var(--ink-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record .amt { flex: none; font-size: var(--fs-15); font-weight: 650; font-variant-numeric: tabular-nums; }

.pay-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 2px; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--line); font-family: inherit; color: inherit; cursor: pointer; }
.pay-row:active { background: var(--brand-50); }
.pay-row .body { flex: 1; min-width: 0; }
.pay-row .t1 { font-size: var(--fs-15); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay-row .t2 { font-size: var(--fs-12); color: var(--ink-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay-row .amt { font-size: var(--fs-15); font-weight: 650; color: var(--success-text); font-variant-numeric: tabular-nums; flex: none; }

/* FAB 向下滚动时收起，避免遮挡内容（必须定义在 .fab 之后才生效） */
.fab-hidden { opacity: 0; transform: scale(.85) translateY(10px); pointer-events: none; }

/* 月度柱状图：窄屏横向滑动，带可见滚动条 */
.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin: 0 calc(-1 * var(--sp-4));
  padding: 0 var(--sp-4) var(--sp-2);
  scrollbar-width: auto;
  scrollbar-color: var(--line-strong) var(--surface-2);
}
.chart-scroll::-webkit-scrollbar { height: 0; }   /* 手机端原生滚动条不占位，用自定义滑动条替代 */

/* 自定义滑动条：始终可见，可拖动（替代手机上会自动隐藏的原生滚动条） */
.scroll-track {
  position: relative; height: 6px; margin: 10px 2px 2px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-full); overflow: hidden; touch-action: none;
}
.scroll-thumb {
  position: absolute; top: 0; bottom: 0; min-width: 26px;
  background: var(--line-strong); border-radius: var(--r-full);
  transition: background var(--dur-1);
}
.scroll-thumb:hover, .scroll-thumb:active { background: var(--brand-300); }
.scroll-track.hidden { display: none; }
.scroll-hint {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: var(--fs-12); color: var(--ink-4); margin: 2px 0 0;
  transition: opacity var(--dur-2) var(--ease-out);
}
.scroll-hint.hidden { display: none; }
.scroll-hint.fade { opacity: 0; }

/* ============================ 搜索 ============================ */
.search-bar { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.search-bar input { flex: 1; }
.search-bar .btn { width: auto; flex: none; margin: 0; padding: 0 16px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 var(--sp-3); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; font-size: var(--fs-13); font-family: inherit;
  color: var(--ink-2); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-full); cursor: pointer; transition: all var(--dur-1);
}
.chip:hover, .chip.active { color: var(--brand-700); border-color: var(--brand-300); background: var(--brand-50); }
.person-chip {
  display: inline-block; padding: 1px 7px; margin-left: 3px;
  font-size: 11px; color: var(--ink-3); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-full); white-space: nowrap;
}
mark { background: color-mix(in srgb, var(--brand-400) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ============================ 卡片 / 明细 ============================ */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--sp-4); margin-bottom: var(--sp-3);
  box-shadow: var(--shadow-1);
}
.card-title { font-size: var(--fs-15); font-weight: 650; margin: 0 0 2px; letter-spacing: -.005em; }
.card-sub { font-size: var(--fs-13); color: var(--ink-3); margin: 0; }

.row-line { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 7px 0; font-size: var(--fs-13); border-bottom: 1px dashed var(--line); }
.row-line:last-child { border-bottom: none; }
.row-line .k { color: var(--ink-3); flex: none; min-width: 72px; }
.row-line .v { text-align: right; word-break: break-all; font-variant-numeric: tabular-nums; }

/* ============================ 表单 ============================ */
.field { margin-bottom: var(--sp-3); }
.field > label { display: block; font-size: var(--fs-13); color: var(--ink-2); margin-bottom: 5px; font-weight: 500; }
.field-row { display: flex; gap: var(--sp-2); }
.field-row > * { flex: 1; min-width: 0; }
.hint, .tip { font-size: var(--fs-12); color: var(--ink-4); margin: 5px 2px 0; line-height: 1.6; }

.items-head { display: flex; align-items: center; justify-content: space-between; margin: var(--sp-4) 2px var(--sp-2); }
.items-head h2 { font-size: var(--fs-15); font-weight: 650; margin: 0; }
.items-count { font-size: var(--fs-12); color: var(--ink-3); }

/* 列表底部的"新增货物"：上一条填完才出现 */
.add-zone { margin: 2px 0 var(--sp-3); }
.add-zone .btn { width: 100%; margin: 0; border-style: dashed; }
.add-zone .btn:hover { border-style: solid; background: var(--brand-50); color: var(--brand-700); }
.add-hint {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 14px; font-size: var(--fs-13); color: var(--ink-4);
  background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--r-lg);
}

.item-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-3); margin-bottom: var(--sp-3); }
.item-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-2); }
.item-head b { font-size: var(--fs-13); color: var(--ink-2); letter-spacing: .03em; }
.remove-btn {
  padding: 6px 11px; font-size: var(--fs-12); font-family: inherit; font-weight: 600;
  color: var(--danger-text); background: color-mix(in srgb, var(--danger-fill) 10%, transparent);
  border: none; border-radius: var(--r-sm); cursor: pointer;
}

/* 底部常驻保存栏 */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.savebar .info { flex: 1; min-width: 0; }
.savebar .info .k { font-size: var(--fs-12); color: var(--ink-3); }
.savebar .info .v { font-size: var(--fs-20); font-weight: 700; letter-spacing: -.015em; }
.savebar .btn { width: auto; margin: 0; padding: 12px 22px; flex: none; }
main.has-savebar { padding-bottom: calc(var(--tabbar-h) + 104px); }

/* ============================ 统计页（对齐用户设计稿） ============================ */

/* ============================ 桌面端适配（≥900px） ============================
   手机：单栏 + 底部导航；桌面：左侧边栏 + 宽屏内容（参考随手记/飞书的网页版形态） */
.sidenav { display: none; }

@media (min-width: 900px) {
  #app-screen {
    display: grid; grid-template-columns: 224px 1fr;
    grid-template-rows: 54px 1fr;
  }
  .sidenav {
    grid-row: 1 / 3; display: flex; flex-direction: column; gap: 2px;
    padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--line);
  }
  .sidenav-brand {
    font-size: var(--fs-17); font-weight: 700; letter-spacing: -.01em;
    padding: 4px 12px 14px;
  }
  .sidenav .tab {
    flex: none; width: 100%; min-height: 44px; flex-direction: row;
    justify-content: flex-start; gap: 12px; padding: 10px 14px;
    border-radius: 10px; font-size: 14.5px; font-weight: 500;
  }
  .sidenav .tab svg { width: 20px; height: 20px; }
  .sidenav .tab.active::before { display: none; }
  .sidenav .tab.active { background: var(--brand-50); }
  .sidenav .tab:hover { color: var(--brand-600); }

  .tabbar { display: none; }
  .topbar { grid-column: 2; }
  main {
    grid-column: 2; overflow-y: auto;
    padding: 26px 40px 56px;
    width: 100%; max-width: 1240px; margin: 0 auto;
    scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
  }
  main::-webkit-scrollbar { width: 8px; }
  main::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
  main::-webkit-scrollbar-track { background: transparent; }
  main.has-savebar { padding-bottom: 132px; }
  #fab { bottom: 36px; right: 44px; }
  .savebar { left: 224px; }

  /* 宽屏多列 */
  .ledger-list { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  .chart-scroll { overflow-x: visible; }
  .sp .chart { width: 100%; }
  .sp .bar-col { flex: 1 1 0; min-width: 0; }
}
.savebar .error { margin: 0; min-height: 0; }

.total-line { display: flex; justify-content: space-between; align-items: center; padding: var(--sp-3) 2px 0; font-size: var(--fs-15); }
.total-line b { font-size: var(--fs-20); color: var(--brand-600); font-variant-numeric: tabular-nums; }

/* ============================ 状态：骨架 / 空 / 提示 ============================ */
.skeleton { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-4); margin-bottom: var(--sp-3); }
.sk-line {
  height: 11px; border-radius: var(--r-full); margin-bottom: 9px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease-in-out infinite;
}
.sk-line:last-child { margin-bottom: 0; }
.sk-line.w40 { width: 40%; } .sk-line.w60 { width: 60%; } .sk-line.w80 { width: 80%; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.empty {
  text-align: center; padding: var(--sp-8) var(--sp-5);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
}
.empty svg { width: 46px; height: 46px; stroke: var(--brand-300); stroke-width: 1.4; fill: none; margin-bottom: var(--sp-3); }
.empty b { display: block; font-size: var(--fs-15); margin-bottom: var(--sp-1); }
.empty p { font-size: var(--fs-13); color: var(--ink-3); margin: 0 0 var(--sp-2); }
.empty .btn { width: auto; padding: 10px 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 26px);
  transform: translateX(-50%) translateY(8px);
  display: flex; align-items: center; gap: var(--sp-2);
  max-width: 84%; padding: 11px 18px; font-size: var(--fs-13); font-weight: 500;
  color: #fff; background: color-mix(in srgb, var(--ink-1) 92%, transparent);
  border-radius: var(--r-full); box-shadow: var(--shadow-3);
  z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { width: 16px; height: 16px; stroke: var(--brand-300); stroke-width: 2; fill: none; flex: none; }

/* ============================ 平板 / 桌面 ============================ */
@media (min-width: 640px) and (max-width: 899px) {
  main { max-width: 680px; margin: 0 auto; width: 100%; padding-left: var(--sp-6); padding-right: var(--sp-6); }
  .topbar, .tabbar { padding-left: max(var(--sp-2), calc((100vw - 680px) / 2)); padding-right: max(var(--sp-2), calc((100vw - 680px) / 2)); }
  .savebar { padding-left: max(var(--sp-4), calc((100vw - 680px) / 2)); padding-right: max(var(--sp-4), calc((100vw - 680px) / 2)); }
  .fab { right: max(var(--sp-4), calc((100vw - 680px) / 2 + var(--sp-4))); }
  .sheet-total { font-size: 36px; }
}

/* ============================================================
   统计页（对齐用户设计稿「经营统计-重设计」）
   结构：大标题 Header（年份下拉 + 导出）→ KPI 三卡 → 月度柱状图 → 客户/货物双卡排行
   作用域：全部样式收在 .sp 容器内，不影响其他页面
   ============================================================ */
.sp {
  --bg: #F5F5F7;
  --card-c: #FFFFFF;
  --hairline: #E3E3E8;
  --ink-c: #1D1D1F;
  --muted-c: #7A7A7A;
  --accent: #0E9E99;        /* 品牌青绿（与账本/流水一致），用于图形与大面积填充 */
  --accent-ink: #0A7C78;    /* 文本安全青绿（白底 4.6:1），用于文字强调与小徽章底 */
  --accent-tint: #A5D8D5;   /* 淡青绿，用于非最高柱与货物细条 */
  --track: #EDEDF0;
  --divider: #F0F0F0;
  --orange-bg: #FFF3E3;
  --orange-text: #B25000;
  --font-num: "Inter Tight", -apple-system, "Segoe UI", system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  --chart-scale: 1;

  display: flex; flex-direction: column; gap: 24px;
}
.sp .num {
  font-family: var(--font-num);
  font-weight: 600;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}

/* ---------- Header ---------- */
.sp .header { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.sp .header h1 { margin: 0; font-size: 30px; font-weight: 600; letter-spacing: -.02em; color: var(--ink-c); }
.sp .header .subtitle { margin: 6px 0 0; font-size: 14px; color: var(--muted-c); }
.sp .header .actions { display: flex; align-items: center; gap: 10px; margin: 0; }
.sp .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: auto; min-height: 0; margin: 0; padding: 10px 20px;
  border: none; cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 500;
  border-radius: 999px; color: var(--ink-c);
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
.sp .btn:active { transform: scale(.95); }
.sp .btn-ghost { background: var(--card-c); color: var(--ink-c); border: 1px solid var(--hairline); }
.sp .btn-primary { background: var(--accent); color: #fff; }
.sp .btn-primary:hover { opacity: .92; }
.sp .year-wrap { position: relative; }
.sp .year-menu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 9;
  min-width: 136px; padding: 6px; display: flex; flex-direction: column;
  background: var(--card-c); border: 1px solid var(--hairline);
  border-radius: 14px; box-shadow: var(--shadow-2);
}
.sp .year-menu button {
  padding: 10px 14px; font-family: inherit; font-size: 14px; text-align: left;
  color: var(--ink-c); background: none; border: none; border-radius: 9px; cursor: pointer;
}
.sp .year-menu button:hover { background: var(--bg); }
.sp .year-menu button.active { color: var(--accent-ink); font-weight: 600; }

/* ---------- 卡片 ---------- */
.sp .card {
  background: var(--card-c); border: 1px solid var(--hairline);
  border-radius: 18px; padding: 22px; margin: 0; box-shadow: none;
}
.sp .card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sp .card-head h2 { margin: 0; font-size: 19px; font-weight: 600; color: var(--ink-c); }
.sp .card-scope { font-size: 13px; color: var(--muted-c); }
.sp .chip {
  font-size: 13px; color: var(--muted-c); background: var(--bg);
  border: none; border-radius: 999px; padding: 6px 14px; white-space: nowrap;
}

/* ---------- KPI 三卡 ---------- */
.sp .kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.sp .kpi {
  min-height: 178px; display: flex; flex-direction: column; gap: 10px;
  border-bottom: none; border-right: none;   /* 覆盖全局 .kpi 无残留 */
  padding: 22px; margin: 0;
}
.sp .kpi .label { font-size: 14px; color: var(--muted-c); }
.sp .kpi .amount { font-size: 30px; line-height: 1.15; color: var(--ink-c); overflow-wrap: anywhere; }
.sp .kpi .note { font-size: 13px; color: var(--muted-c); }
.sp .progress { margin: 0; height: 8px; background: var(--track); border: none; border-radius: 999px; overflow: hidden; }
.sp .progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.sp .progress-caption { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted-c); }
.sp .progress-caption b { color: var(--accent-ink); font-family: var(--font-num); font-weight: 600; }
.sp .chip-warn {
  align-self: flex-start; font-size: 12px; color: var(--orange-text);
  background: var(--orange-bg); border: none; border-radius: 999px; padding: 5px 12px;
}
.sp .chip-ok {
  align-self: flex-start; font-size: 12px; color: #0F7A3D;
  background: #E8F6EE; border: none; border-radius: 999px; padding: 5px 12px;
}

/* ---------- 月度柱状图 ---------- */
.sp .chart {
  height: calc(380px * var(--chart-scale));
  display: flex; align-items: flex-end; gap: clamp(12px, 2.4vw, 36px);
  margin-top: 20px; padding: 0; min-width: max-content;
}
.sp .bar-col {
  flex: 1 0 auto; min-width: 44px; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 10px;
  position: relative; cursor: pointer;
}
.sp .bar-col .val { font-size: 13px; color: var(--muted-c); white-space: nowrap; transition: color .15s ease; }
.sp .bar-col .vbar {
  flex: none; width: clamp(34px, 5.5vw, 110px);
  height: calc(var(--h, 0) * var(--chart-scale) * 1px);
  background: var(--accent-tint); border: none; border-radius: 10px;
  transition: background .15s ease, box-shadow .15s ease;
}
.sp .bar-col .mon { font-size: 13px; color: var(--muted-c); white-space: nowrap; transition: color .15s ease; }
.sp .bar-col.is-max .val,
.sp .bar-col.is-max .mon { color: var(--ink-c); font-weight: 600; }
.sp .bar-col.is-max .vbar { background: var(--accent); }

/* 悬停/选中：点亮柱子 */
.sp .bar-col:hover .vbar,
.sp .bar-col.tip-open .vbar {
  background: color-mix(in srgb, var(--accent) 55%, #fff);
  box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--accent) 45%, transparent);
}
.sp .bar-col.is-max:hover .vbar,
.sp .bar-col.is-max.tip-open .vbar {
  background: color-mix(in srgb, var(--accent) 82%, #fff);
}
.sp .bar-col:hover .val,
.sp .bar-col.tip-open .val { color: var(--ink-c); }

/* 悬浮提示：跟随柱顶，超出图顶时下压（不裁剪） */
.sp .bar-col .tip {
  position: absolute; left: 50%; z-index: 10;
  bottom: min(calc(var(--h, 0) * var(--chart-scale) * 1px + 44px), calc(100% - 112px));
  transform: translateX(-50%) translateY(4px);
  min-width: 152px; padding: 10px 13px;
  background: #1D1D1F; color: #fff;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 10px; box-shadow: 0 8px 22px -8px rgba(0, 0, 0, .4);
  font-size: 12.5px; line-height: 1.55; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.sp .bar-col:first-child .tip { transform: translateX(-14%) translateY(4px); }
.sp .bar-col:last-child .tip { transform: translateX(-86%) translateY(4px); }
.sp .bar-col:hover .tip,
.sp .bar-col.tip-open .tip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.sp .bar-col:first-child:hover .tip,
.sp .bar-col:first-child.tip-open .tip { transform: translateX(-14%) translateY(0); }
.sp .bar-col:last-child:hover .tip,
.sp .bar-col:last-child.tip-open .tip { transform: translateX(-86%) translateY(0); }
.sp .tip .tt { display: block; font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.sp .tip .row { display: flex; justify-content: space-between; gap: 16px; }
.sp .tip .row .k { color: rgba(255, 255, 255, .62); }
.sp .tip .row .v { font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums; }
.sp .tip .row .v.ok { color: #4ADE80; }
.sp .tip::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: #1D1D1F;
}
.sp .bar-col:first-child .tip::after { left: 14%; }
.sp .bar-col:last-child .tip::after { left: 86%; }

/* ---------- 排行双卡 ---------- */
.sp .rank-row { display: grid; grid-template-columns: minmax(0, 500px) 1fr; gap: 20px; align-items: stretch; margin: 0; }
.sp .rank-card { display: flex; flex-direction: column; gap: 16px; }
.sp .rank-card .card-head { flex: none; }
.sp .rank-empty { margin: 0; font-size: 13px; color: var(--muted-c); }

/* 客户排行：每人一块 */
.sp .cust-block { display: flex; flex-direction: column; gap: 10px; }
.sp .cust-block + .cust-block { padding-top: 14px; border-top: 1px solid var(--divider); }
.sp .cust-line { display: flex; align-items: center; gap: 12px; }
.sp .cust-line .badge {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border: none; border-radius: 999px;
  background: var(--accent-ink); color: #fff;
  font-family: var(--font-num); font-size: 13px; font-weight: 600;
}
.sp .cust-line .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; font-weight: 600; color: var(--ink-c); }
.sp .cust-line .count { flex: none; font-size: 13px; color: var(--muted-c); white-space: nowrap; }
.sp .cust-amount { font-size: 26px; color: var(--ink-c); }
.sp .cust-note { font-size: 13px; color: var(--muted-c); }
.sp .rank-foot {
  margin-top: auto; padding-top: 14px;
  border-top: 1px solid var(--divider); font-size: 12px; color: var(--muted-c);
}

/* 货物排行：徽标 + 名称 + 笔数 + 金额 + 细条 */
.sp .goods-list { display: flex; flex-direction: column; gap: 12px; margin: 0; }
.sp .goods-item { display: flex; flex-direction: column; gap: 6px; }
.sp .goods-line { display: flex; align-items: center; gap: 10px; }
.sp .goods-line .badge {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; padding: 0; border: none; border-radius: 999px;
  background: var(--track); color: var(--muted-c);
  font-family: var(--font-num); font-size: 12px; font-weight: 600;
}
.sp .goods-line .gname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; color: var(--ink-c); }
.sp .goods-line .gcount { flex: none; font-size: 12px; color: var(--muted-c); white-space: nowrap; }
.sp .goods-line .gamount { flex: none; font-size: 15px; color: var(--ink-c); white-space: nowrap; }
.sp .goods-bar { height: 4px; width: var(--w, 0%); border-radius: 999px; background: var(--accent-tint); }
.sp .goods-item.top .goods-bar { background: var(--accent); }
.sp .goods-item.top .badge { background: var(--accent-ink); color: #fff; }

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) {
  .sp .rank-row { grid-template-columns: 1fr; }
}
@media (max-width: 899px) {
  .sp { --chart-scale: .72; gap: 18px; }
  .sp .header h1 { font-size: 25px; }
  .sp .card { padding: 18px; border-radius: 16px; }
  .sp .kpi-row { grid-template-columns: 1fr; gap: 12px; }
  .sp .kpi { min-height: 0; padding: 18px; }
  .sp .kpi .amount { font-size: 27px; }
  .sp .chart { gap: 10px; margin-top: 16px; }
  .sp .bar-col { min-width: 38px; }
  .sp .bar-col .vbar { width: clamp(24px, 6.5vw, 56px); border-radius: 8px; }
  .sp .cust-amount { font-size: 23px; }
}

/* ---------- 暗色模式 ---------- */
@media (prefers-color-scheme: dark) {
  .sp {
    --bg: #1A2224;
    --card-c: var(--surface);
    --hairline: var(--line);
    --ink-c: var(--ink-1);
    --muted-c: var(--ink-3);
    --accent: #2BB3AD;
    --accent-ink: #4CC9C3;
    --accent-tint: #17524F;
    --track: #243033;
    --divider: #223031;
    --orange-bg: #3A2812;
    --orange-text: #F0A860;
  }
  .sp .chip-ok { color: #4ADE80; background: #14301F; }
  /* 暗色下柱子悬停往亮青绿提亮（混白会在暗底上发灰） */
  .sp .bar-col:hover .vbar,
  .sp .bar-col.tip-open .vbar {
    background: color-mix(in srgb, var(--accent) 62%, var(--accent-tint));
  }
  .sp .bar-col.is-max:hover .vbar,
  .sp .bar-col.is-max.tip-open .vbar {
    background: var(--accent-ink);
  }
}
