@import url("./tokens.css");

/* ==========================================================================
   0. 基础重置
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--ff-ui);
  font-size: var(--fs-14);
  line-height: 1.55;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--t-base), color var(--t-base);
}
h1,h2,h3,h4,p,figure { margin: 0; }
ul,ol { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
::selection { background: var(--c-primary-soft2); }

:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--c-n-200); border-radius: var(--r-full);
  border: 3px solid transparent; background-clip: content-box;
}
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #39435280; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--c-n-300); background-clip: content-box; }

/* ==========================================================================
   1. 排版工具类
   ========================================================================== */
.num {
  font-family: var(--ff-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: -.01em;
}
/* 契约①：所有余额数值中性墨色 */
.val   { color: var(--c-text); font-weight: 600; }
/* 契约③：净资产是唯一被品牌色强调的数值 */
.net   { color: var(--c-primary); font-weight: 700; }
/* 契约②：仅变动量可着涨跌色 */
.up    { color: var(--c-up); }
.down  { color: var(--c-down); }
.muted { color: var(--c-text-soft); }
.faint { color: var(--c-text-mute); }
.tiny  { font-size: var(--fs-12); }
.mono-lg { font-size: var(--fs-30); font-weight: 700; }
.ta-r  { text-align: right; }
.ta-c  { text-align: center; }
.nowrap{ white-space: nowrap; }
.hide  { display: none !important; }

.label {
  font-size: var(--fs-12);
  color: var(--c-text-mute);
  letter-spacing: .04em;
}
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3);
  font-size: var(--fs-15); font-weight: 650; color: var(--c-text);
  margin-bottom: var(--sp-3);
}
.section-title .sub { font-size: var(--fs-12); font-weight: 400; color: var(--c-text-mute); }

/* 分类圆点：分类色的唯一合法文本级出口 */
.cat-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  flex: none; background: var(--c-cat-other);
}
.cat-dot[data-cat="cash"]  { background: var(--c-cat-cash); }
.cat-dot[data-cat="fixed"] { background: var(--c-cat-fixed); }
.cat-dot[data-cat="equity"]{ background: var(--c-cat-equity); }
.cat-dot[data-cat="estate"]{ background: var(--c-cat-estate); }
.cat-dot[data-cat="other"] { background: var(--c-cat-other); }
.cat-dot[data-cat="debt"]  { background: var(--c-cat-debt); }
.cat-dot[data-cat="loan"]  { background: var(--c-cat-loan); }

.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.flex-c { display: flex; align-items: center; gap: var(--sp-2); }
.grow { flex: 1; min-width: 0; }

/* ==========================================================================
   2. 应用骨架：桌面侧边栏 / 移动底部 Tab
   ========================================================================== */
.app { min-height: 100vh; display: flex; }

.sidebar {
  width: var(--nav-w); flex: none;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 30;
}
.brand {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(145deg, var(--c-primary), var(--c-primary-press));
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 3px 8px rgba(43,76,126,.28);
}
[data-theme="dark"] .brand-mark { box-shadow: none; }
.brand-name { font-size: var(--fs-15); font-weight: 700; letter-spacing: -.01em; }
.brand-sub  { font-size: var(--fs-11); color: var(--c-text-mute); }

.nav { padding: var(--sp-2) var(--sp-3); flex: 1; overflow-y: auto; }
.nav-group-label {
  font-size: var(--fs-11); color: var(--c-text-faint);
  padding: var(--sp-4) var(--sp-3) var(--sp-2); letter-spacing: .08em;
}
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px var(--sp-3); border-radius: var(--r-md);
  color: var(--c-text-soft); font-size: var(--fs-14); font-weight: 500;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.nav-item:hover { background: var(--c-n-50); color: var(--c-text); }
[data-theme="dark"] .nav-item:hover { background: var(--c-surface-2); }
.nav-item.is-active {
  background: var(--c-primary-soft); color: var(--c-primary); font-weight: 650;
}
.nav-item.is-active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--c-primary);
}
.nav-item svg { flex: none; opacity: .9; }
.nav-badge {
  margin-left: auto; font-size: var(--fs-11); font-weight: 600;
  background: var(--c-n-100); color: var(--c-text-soft);
  padding: 1px 7px; border-radius: var(--r-full);
}
[data-theme="dark"] .nav-badge { background: var(--c-surface-2); }

.sidebar-foot { padding: var(--sp-3); border-top: 1px solid var(--c-border); }

/* 主区 */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-6);
  background: color-mix(in srgb, var(--c-surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--c-border);
  position: sticky; top: 0; z-index: 25;
}
.topbar h1 { font-size: var(--fs-16); font-weight: 650; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }

.page { padding: var(--sp-6); max-width: 1320px; width: 100%; margin: 0 auto; }
.page-head { margin-bottom: var(--sp-5); }
.page-title { font-size: var(--fs-20); font-weight: 700; letter-spacing: -.02em; }
.page-sub { font-size: var(--fs-13); color: var(--c-text-mute); margin-top: 2px; }

/* 移动端底部 Tab */
.tabbar { display: none; }

/* ==========================================================================
   3. 视角切换（本系统最核心的一次交互）
   ========================================================================== */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--c-n-100); border-radius: var(--r-full);
  position: relative;
}
[data-theme="dark"] .segmented { background: var(--c-surface-2); }
.segmented button {
  padding: 5px 14px; border-radius: var(--r-full);
  font-size: var(--fs-13); font-weight: 600; color: var(--c-text-soft);
  display: flex; align-items: center; gap: 6px;
  transition: all var(--t-fast); white-space: nowrap;
}
.segmented button:hover { color: var(--c-text); }
.segmented button.is-active {
  background: var(--c-surface); color: var(--c-primary);
  box-shadow: var(--sh-1);
}

/* 成员头像 */
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: var(--fs-12); font-weight: 700; color: #fff;
  background: var(--c-n-400); letter-spacing: 0;
}
.avatar[data-m="husband"] { background: var(--c-m-husband); }
.avatar[data-m="wife"]    { background: var(--c-m-wife); }
.avatar[data-m="child"]   { background: var(--c-m-child); }
.avatar.sm { width: 20px; height: 20px; font-size: var(--fs-11); }
.avatar.lg { width: 40px; height: 40px; font-size: var(--fs-15); }
.avatar-stack { display: flex; }
.avatar-stack .avatar + .avatar { margin-left: -8px; box-shadow: 0 0 0 2px var(--c-surface); }

/* ==========================================================================
   4. 卡片
   ========================================================================== */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card-pad { padding: var(--sp-5); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--c-border);
}
.card-head h3 { font-size: var(--fs-15); font-weight: 650; }
.card-body { padding: var(--sp-5); }
.card-foot {
  padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--c-border);
  background: var(--c-surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg);
  font-size: var(--fs-12); color: var(--c-text-mute);
}

/* Hero：净资产主卡（随手记式顶部大数字） */
.hero {
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  background:
    radial-gradient(120% 140% at 92% 0%, rgba(200,137,43,.22) 0%, rgba(200,137,43,0) 46%),
    linear-gradient(140deg, #2f5387 0%, #24406b 48%, #1a3055 100%);
  color: #fff; position: relative; overflow: hidden;
  box-shadow: 0 12px 30px rgba(26,48,85,.26);
}
[data-theme="dark"] .hero {
  background:
    radial-gradient(120% 140% at 92% 0%, rgba(224,170,78,.16) 0%, rgba(224,170,78,0) 46%),
    linear-gradient(140deg, #23344f 0%, #1a2537 100%);
  box-shadow: none; border: 1px solid var(--c-border);
}
.hero::after {
  content: ""; position: absolute; right: -60px; bottom: -90px;
  width: 260px; height: 260px; border-radius: 50%;
  background: rgba(255,255,255,.05);
}
.hero-label {
  font-size: var(--fs-12); color: rgba(255,255,255,.72);
  display: flex; align-items: center; gap: 6px;
}
.hero-value {
  font-family: var(--ff-num); font-variant-numeric: tabular-nums;
  font-size: var(--fs-38); font-weight: 700; letter-spacing: -.025em;
  line-height: 1.15; margin-top: 2px;
}
.hero-value .cur { font-size: var(--fs-20); font-weight: 600; opacity: .7; margin-right: 4px; }
.hero-delta {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-12); font-weight: 600;
  padding: 3px 9px; border-radius: var(--r-full);
  background: rgba(255,255,255,.14); color: #fff; margin-top: var(--sp-3);
}
.hero-split {
  display: grid; grid-template-columns: 1fr 1px 1fr; gap: var(--sp-4);
  margin-top: var(--sp-5); padding-top: var(--sp-5);
  border-top: 1px solid rgba(255,255,255,.14);
  position: relative; z-index: 1;
}
.hero-split .divider { background: rgba(255,255,255,.14); }
.hero-item-label { font-size: var(--fs-12); color: rgba(255,255,255,.7); }
.hero-item-value {
  font-family: var(--ff-num); font-variant-numeric: tabular-nums;
  font-size: var(--fs-20); font-weight: 650; margin-top: 1px;
}

/* KPI 小卡 */
.kpi-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.kpi {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-lg); padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--sh-1);
  transition: box-shadow var(--t-fast), transform var(--t-fast);
}
.kpi:hover { box-shadow: var(--sh-2); transform: translateY(-1px); }
.kpi-label { font-size: var(--fs-12); color: var(--c-text-mute); display: flex; align-items: center; gap: 6px; }
.kpi-value {
  font-family: var(--ff-num); font-variant-numeric: tabular-nums;
  font-size: var(--fs-24); font-weight: 700; letter-spacing: -.02em;
  margin-top: 4px; color: var(--c-text);
}
.kpi-value.is-net { color: var(--c-primary); }
.kpi-foot { font-size: var(--fs-12); margin-top: 6px; display: flex; align-items: center; gap: 5px; }

/* ==========================================================================
   5. 列表（随手记式：左标识 · 中主副标题 · 右数值）
   ========================================================================== */
.list { }
.list-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 11px var(--sp-5);
  border-bottom: 1px solid var(--c-border);
  transition: background var(--t-fast);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--c-surface-2); }
.list-row .rt { font-size: var(--fs-14); font-weight: 550; }
.list-row .rs { font-size: var(--fs-12); color: var(--c-text-mute); display: flex; align-items: center; gap: 6px; margin-top: 1px; }
.list-row .rv {
  font-family: var(--ff-num); font-variant-numeric: tabular-nums;
  font-size: var(--fs-15); font-weight: 600; text-align: right; color: var(--c-text);
}
.list-row .rvs { font-size: var(--fs-12); text-align: right; margin-top: 1px; }

/* 可折叠分组头 */
.group-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 10px var(--sp-5); cursor: pointer;
  background: var(--c-surface-2); border-bottom: 1px solid var(--c-border);
  user-select: none;
}
.group-head:hover { background: var(--c-n-100); }
[data-theme="dark"] .group-head:hover { background: #232c39; }
.group-head .chev { transition: transform var(--t-fast); color: var(--c-text-mute); }
.group-head.is-open .chev { transform: rotate(90deg); }
.group-name { font-size: var(--fs-13); font-weight: 650; }
.group-meta { font-size: var(--fs-12); color: var(--c-text-mute); }

/* 占比迷你条 */
.minibar {
  height: 4px; border-radius: 2px; background: var(--c-n-100);
  overflow: hidden; width: 100%;
}
[data-theme="dark"] .minibar { background: var(--c-surface-2); }
.minibar > i { display: block; height: 100%; border-radius: 2px; background: var(--c-cat-other); }

/* ==========================================================================
   6. 标签 / 徽章（契约⑤：状态一律中性）
   ========================================================================== */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-11); font-weight: 600; line-height: 1.6;
  padding: 1px 8px; border-radius: var(--r-sm);
  background: var(--c-n-100); color: var(--c-text-soft);
  border: 1px solid transparent; white-space: nowrap;
}
[data-theme="dark"] .tag { background: var(--c-surface-2); }
.tag.is-outline { background: transparent; border-color: var(--c-border-strong); color: var(--c-text-mute); }
.tag.is-primary { background: var(--c-primary-soft); color: var(--c-primary); }
.tag.is-accent  { background: var(--c-accent-soft); color: var(--c-accent); }
.tag.is-warn    { background: var(--c-warn-soft); color: var(--c-warn); }

/* 状态点：已录入 / 沿用 / 自动 —— 全部灰阶 */
.dot-state { width: 6px; height: 6px; border-radius: 50%; background: var(--c-n-300); flex: none; }
.dot-state[data-s="entered"] { background: var(--c-n-500); }
.dot-state[data-s="carry"]   { background: var(--c-n-200); }
.dot-state[data-s="auto"]    { background: var(--c-n-400); }

/* ==========================================================================
   7. 按钮
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--r-md);
  font-size: var(--fs-13); font-weight: 600;
  background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border-strong);
  transition: all var(--t-fast); white-space: nowrap;
}
.btn:hover { background: var(--c-n-50); border-color: var(--c-n-300); }
[data-theme="dark"] .btn:hover { background: var(--c-surface-2); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.is-primary {
  background: var(--c-primary); color: #fff; border-color: transparent;
  box-shadow: 0 1px 2px rgba(43,76,126,.28);
}
.btn.is-primary:hover { background: var(--c-primary-hover); }
[data-theme="dark"] .btn.is-primary { color: #0f1620; }
.btn.is-ghost { background: transparent; border-color: transparent; color: var(--c-text-soft); }
.btn.is-ghost:hover { background: var(--c-n-100); color: var(--c-text); }
[data-theme="dark"] .btn.is-ghost:hover { background: var(--c-surface-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: var(--fs-12); }
.btn.lg { height: 44px; padding: 0 22px; font-size: var(--fs-15); border-radius: var(--r-md); }
.btn.block { width: 100%; }
.btn.icon { width: 34px; padding: 0; }
.btn.icon.sm { width: 28px; }

/* ==========================================================================
   8. 表单
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--fs-12); font-weight: 600; color: var(--c-text-soft); }
.input, .select {
  height: 36px; padding: 0 11px; width: 100%;
  background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border-strong); border-radius: var(--r-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  font-size: var(--fs-14);
}
.input.num-in { font-family: var(--ff-num); font-variant-numeric: tabular-nums; text-align: right; }
.input:hover, .select:hover { border-color: var(--c-n-400); }
.input:focus, .select:focus {
  outline: none; border-color: var(--c-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-primary) 16%, transparent);
}
.input::placeholder { color: var(--c-text-faint); }
.select {
  appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a95a4' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 9px center;
}
.hint { font-size: var(--fs-12); color: var(--c-text-mute); }
.form-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); }

/* 开关 */
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch i {
  position: absolute; inset: 0; border-radius: var(--r-full);
  background: var(--c-n-300); transition: background var(--t-fast); pointer-events: none;
}
.switch i::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform var(--t-fast);
}
.switch input:checked + i { background: var(--c-primary); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-primary) 22%, transparent); }

/* ==========================================================================
   9. 表格（历史台账核心）
   ========================================================================== */
.table-wrap {
  overflow: auto; border: 1px solid var(--c-border);
  border-radius: var(--r-lg); background: var(--c-surface);
  max-height: 62vh;
}
.tbl { font-size: var(--fs-13); min-width: 100%; }
.tbl th, .tbl td {
  padding: 0 12px; height: 38px; white-space: nowrap;
  border-bottom: 1px solid var(--c-border);
  text-align: right;
}
.tbl thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--c-surface-2); color: var(--c-text-soft);
  font-size: var(--fs-12); font-weight: 650; height: 34px;
  border-bottom: 1px solid var(--c-border-strong);
}
.tbl thead tr.grp th {
  top: 0; height: 30px; font-size: var(--fs-11); letter-spacing: .05em;
  color: var(--c-text-mute); font-weight: 600;
  border-bottom: 1px solid var(--c-border);
}
.tbl thead tr.cols th { top: 30px; }
.tbl th.stick-l, .tbl td.stick-l {
  position: sticky; left: 0; z-index: 2; text-align: left;
  background: var(--c-surface); border-right: 1px solid var(--c-border);
}
.tbl thead th.stick-l { z-index: 4; background: var(--c-surface-2); }
.tbl tbody tr:hover td { background: var(--c-primary-soft); }
.tbl tbody tr:hover td.stick-l { background: var(--c-primary-soft); }
.tbl td.n {
  font-family: var(--ff-num); font-variant-numeric: tabular-nums;
  color: var(--c-text);
}
/* 汇总列：仅净资产用品牌色，总资产/总负债保持中性 */
.tbl td.sum { background: var(--c-surface-2); font-weight: 600; }
.tbl tbody tr:hover td.sum { background: var(--c-primary-soft2); }
.tbl td.sum-net { color: var(--c-primary); font-weight: 700; }
.tbl .col-sep { border-left: 1px solid var(--c-border-strong); }
/* 沿用值：仅降低不透明度，不着色 */
.tbl td.carry { color: var(--c-text-mute); }
.tbl td.editable { cursor: cell; }
.tbl td.editable:hover { box-shadow: inset 0 0 0 2px var(--c-primary); border-radius: 3px; }
.tbl td .cell-in {
  width: 100%; height: 26px; text-align: right; border: 1px solid var(--c-primary);
  border-radius: var(--r-sm); background: var(--c-surface); color: var(--c-text);
  font-family: var(--ff-num); font-variant-numeric: tabular-nums; font-size: var(--fs-13);
  padding: 0 6px;
}
.tbl tr.is-today td { box-shadow: inset 0 1px 0 var(--c-accent), inset 0 -1px 0 var(--c-accent); }

/* ==========================================================================
   10. 图表容器
   ========================================================================== */
.chart { width: 100%; display: block; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--c-text-soft); }
.legend-item b { color: var(--c-text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* 配置诊断偏差条 */
.gap-row { display: grid; grid-template-columns: 92px 1fr 150px; gap: var(--sp-3); align-items: center; padding: 11px 0; border-bottom: 1px solid var(--c-border); }
.gap-row:last-child { border-bottom: 0; }
.gap-track {
  position: relative; height: 22px; border-radius: var(--r-sm);
  background: var(--c-n-100); overflow: hidden;
}
[data-theme="dark"] .gap-track { background: var(--c-surface-2); }
.gap-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: var(--r-sm); opacity: .82; }
.gap-target {
  position: absolute; top: -3px; bottom: -3px; width: 2px;
  background: var(--c-accent); border-radius: 1px;
}
.gap-target::after {
  content: ""; position: absolute; top: -3px; left: -3px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--c-accent);
}

/* ==========================================================================
   11. 抽屉 / 弹层
   ========================================================================== */
.overlay {
  position: fixed; inset: 0; background: rgba(16,22,30,.42);
  backdrop-filter: blur(2px); z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity var(--t-base);
}
.overlay.is-open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%);
  background: var(--c-surface); z-index: 61; box-shadow: var(--sh-3);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform var(--t-slow);
}
.drawer.is-open { transform: none; }
.drawer-head { padding: var(--sp-5); border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; }
.drawer-head h3 { font-size: var(--fs-16); font-weight: 650; }
.drawer-body { padding: var(--sp-5); overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: var(--sp-4); }
.drawer-foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--c-border); display: flex; gap: var(--sp-3); }

/* Toast */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--c-n-900); color: #fff; padding: 9px 16px; border-radius: var(--r-md);
  font-size: var(--fs-13); box-shadow: var(--sh-3);
  animation: toastIn .26s cubic-bezier(.16,1,.3,1);
}
[data-theme="dark"] .toast { background: var(--c-n-100); color: var(--c-n-900); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.97); } }

/* 空状态 */
.empty { padding: var(--sp-12) var(--sp-5); text-align: center; color: var(--c-text-mute); }
.empty svg { opacity: .35; margin-bottom: var(--sp-3); }
.empty p { font-size: var(--fs-13); }

/* 骨架屏 */
.skel { background: linear-gradient(90deg, var(--c-n-100) 25%, var(--c-n-50) 37%, var(--c-n-100) 63%); background-size: 400% 100%; animation: skel 1.3s ease infinite; border-radius: var(--r-sm); }
@keyframes skel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ==========================================================================
   12. 栅格
   ========================================================================== */
.grid { display: grid; gap: var(--sp-4); }
.g-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-1 { grid-template-columns: 1fr 1fr; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }

/* ==========================================================================
   13. 响应式
   ========================================================================== */
@media (max-width: 1080px) {
  .g-2-1, .g-1-1, .g-2 { grid-template-columns: 1fr; }
  .g-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .sidebar { display: none; }
  .page { padding: var(--sp-4) var(--sp-4) calc(var(--tabbar-h) + var(--sp-8)); }
  .topbar { padding: 0 var(--sp-4); gap: var(--sp-2); }
  .topbar h1 { font-size: var(--fs-15); }
  .g-3 { grid-template-columns: 1fr; }
  .hero-value { font-size: var(--fs-30); }
  .hero { padding: var(--sp-5); }
  .card-pad, .card-body { padding: var(--sp-4); }
  .list-row { padding: 11px var(--sp-4); }
  .group-head { padding: 10px var(--sp-4); }
  .gap-row { grid-template-columns: 76px 1fr; }
  .gap-row .gap-nums { grid-column: 1 / -1; }
  .hide-sm { display: none !important; }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--c-surface) 92%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--c-border);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; font-size: var(--fs-11); color: var(--c-text-mute); font-weight: 500;
  }
  .tabbar a.is-active { color: var(--c-primary); font-weight: 650; }
  .tabbar a.fab-slot { position: relative; }
  .tabbar .fab {
    width: 42px; height: 42px; border-radius: 50%; margin-top: -18px;
    background: var(--c-primary); color: #fff; display: grid; place-items: center;
    box-shadow: 0 4px 12px rgba(43,76,126,.4);
  }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi { padding: var(--sp-3) var(--sp-4); }
  .kpi-value { font-size: var(--fs-18); }
  .hero-split { grid-template-columns: 1fr 1px 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* 打印 */
@media print {
  .sidebar, .topbar, .tabbar, .btn { display: none !important; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
}
