/* ============================================================
   装修费用管家 — 设计系统
   Light theme · 数据密集型 · 移动端优先
   ============================================================ */

:root {
  /* 中性色 */
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-2: #FAFAFB;
  --surface-3: #F1F3F5;
  --border: #E4E7EC;
  --border-strong: #D0D5DD;
  --text: #1A1D21;
  --text-2: #5A6270;
  /* WCAG AA：正文级辅助文字对白底需 ≥4.5:1 */
  --text-3: #6B717B;
  --text-inv: #FFFFFF;

  /* 品牌 */
  --brand: #A96522;
  --brand-hover: #8E551C;
  --brand-soft: #FDF4E8;
  --brand-border: #F0D9BC;
  /* 图表/图形用的浅品牌色（不承载文字，无需满足对比度） */
  --brand-chart: #C8792B;

  /* 语义色（中文财经习惯：涨=红，跌=绿） */
  --danger: #D93025;
  --danger-soft: #FEF0EF;
  --danger-border: #F7CFCB;
  --success: #04875E;
  --success-soft: #ECFDF5;
  --success-border: #B7E8D3;
  --warn: #B16104;
  --warn-soft: #FFFBEB;
  --warn-border: #FCE7B2;
  --info: #2563EB;
  --info-soft: #EFF4FF;
  --info-border: #C7D8FE;

  /* 尺寸 */
  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 2px 8px rgba(16, 24, 40, 0.07);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);
  --header-h: 56px;
  --tabbar-h: 60px;
  --sidebar-w: 208px;
  /* iOS 独立窗口（添加到主屏后）顶部刘海/灵动岛安全区高度 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
          'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  --font-num: 'SF Mono', ui-monospace, 'Menlo', 'Consolas', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body { overflow-x: hidden; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
p { margin: 0; }
button { font-family: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ── 顶栏 ─────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 50;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex; align-items: center; gap: 12px;
  padding-left: 16px; padding-right: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* 注意：限定在 .app-header 内，避免与 .stat.brand（指标卡配色态）命名冲突 */
.app-header .brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; flex: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand) 0%, #E0A45C 100%);
  display: grid; place-items: center;
  color: #fff; font-size: 15px; font-weight: 700;
}
.brand-text { min-width: 0; }
.brand-title { font-size: 14px; font-weight: 650; line-height: 1.2; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--text-3); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* 顶栏「已支出」摘要：整体单行不折行，超窄屏时只保留金额 */
.header-chip {
  display: flex; align-items: baseline; gap: 6px; margin-right: 4px;
  white-space: nowrap; min-width: 0; overflow: hidden;
}
.header-chip .card-sub { flex: none; }
.header-chip .num { flex: none; }

/* ── 布局 ─────────────────────────────────────────────────── */
.app-body { display: flex; min-height: calc(100vh - var(--header-h) - var(--safe-top)); }

.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 10px 24px;
  position: sticky; top: calc(var(--header-h) + var(--safe-top));
  height: calc(100vh - var(--header-h) - var(--safe-top));
  overflow-y: auto;
}
.nav-group-label {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  padding: 12px 10px 5px; letter-spacing: .04em;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; margin-bottom: 1px;
  border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px; font-weight: 500;
  cursor: pointer; user-select: none;
  border: none; background: none; width: 100%; text-align: left;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-icon { width: 17px; text-align: center; font-size: 15px; flex: none; opacity: .85; }
.nav-badge {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: var(--danger); color: #fff;
  padding: 1px 6px; border-radius: 9px; min-width: 18px; text-align: center;
}
.nav-badge.muted { background: var(--surface-3); color: var(--text-2); }

.main {
  flex: 1; min-width: 0;
  padding: 18px 20px 40px;
  max-width: 1400px;
}

.view-head {
  display: flex; align-items: flex-start; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.view-title { font-size: 19px; font-weight: 650; }
.view-desc { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.view-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ── 按钮 ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px; font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-3); border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent;
  color: var(--text-2); font-size: 15px; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ── 卡片 ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-title { font-size: 14px; font-weight: 620; }
.card-sub { font-size: 12px; color: var(--text-3); }
.card-head-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.card-body { padding: 16px; }
.card-body.tight { padding: 10px 16px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

/* ── 指标卡 ───────────────────────────────────────────────── */
/* display:block 显式声明，避免被其它同名 class（如 .brand）的布局规则污染 */
.stat {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.stat-label {
  font-size: 12px; color: var(--text-2);
  display: flex; align-items: center; gap: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-value {
  display: block;
  font-size: 23px; font-weight: 680; margin-top: 5px;
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  letter-spacing: -.02em; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-value.sm { font-size: 19px; }
.stat-meta { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }
.stat-meta .nowrap { white-space: nowrap; }
.stat-accent { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.stat.danger .stat-value { color: var(--danger); }
.stat.success .stat-value { color: var(--success); }
.stat.warn .stat-value { color: var(--warn); }
.stat.accent-brand .stat-value { color: var(--brand); }

/* ── 进度条 ───────────────────────────────────────────────── */
.bar {
  height: 7px; border-radius: 4px;
  background: var(--surface-3); overflow: hidden;
  position: relative;
}
.bar-fill { height: 100%; border-radius: 4px; transition: width .4s cubic-bezier(.4,0,.2,1); }
.bar-fill.ok { background: var(--success); }
.bar-fill.near { background: var(--warn); }
.bar-fill.over { background: var(--danger); }
.bar-fill.unplanned { background: var(--text-3); }
.bar-fill.empty { background: var(--border-strong); }
.bar-fill.brand { background: var(--brand); }
.bar.thin { height: 5px; }
.bar.thick { height: 10px; }

.bar-legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--text-2); margin-top: 9px;
}
.bar-legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }

/* ── 表格 ─────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  /* 纯 CSS 横向滚动阴影提示：右缘有内容溢出时显示渐隐 + 箭头 */
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)) left center / 24px 100% no-repeat,
    linear-gradient(to left, var(--surface) 30%, rgba(255,255,255,0)) right center / 24px 100% no-repeat,
    radial-gradient(farthest-side at 0 50%, rgba(16,24,40,.13), rgba(0,0,0,0)) left center / 12px 100% no-repeat,
    radial-gradient(farthest-side at 100% 50%, rgba(16,24,40,.13), rgba(0,0,0,0)) right center / 12px 100% no-repeat;
  background-attachment: local, local, scroll, scroll;
}
table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data th {
  text-align: left; font-weight: 600; font-size: 12px;
  color: var(--text-2); padding: 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
table.data td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tfoot td {
  padding: 10px 12px; font-weight: 650;
  background: var(--surface-2);
  border-top: 1.5px solid var(--border-strong);
}
td.num, th.num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
td.center, th.center { text-align: center; }
.nowrap { white-space: nowrap; }
.cell-strong { font-weight: 600; }
.cell-muted { color: var(--text-3); }
.cell-sm { font-size: 12px; }

.row-edit { cursor: pointer; }
.row-edit:hover { background: var(--brand-soft) !important; }

/* ── 标签 ─────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 7px;
  border-radius: 5px;
  font-size: 11.5px; font-weight: 550;
  background: var(--surface-3); color: var(--text-2);
  white-space: nowrap;
}
.tag-dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.tag-ok { background: var(--success-soft); color: var(--success); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.tag-info { background: var(--info-soft); color: var(--info); }
.tag-brand { background: var(--brand-soft); color: var(--brand); }
.tag-outline { background: transparent; border: 1px solid var(--border-strong); }

/* ── 表单 ─────────────────────────────────────────────────── */
.field { margin-bottom: 13px; }
.field-label {
  display: block; font-size: 12.5px; font-weight: 550;
  color: var(--text-2); margin-bottom: 5px;
}
.field-label .req { color: var(--danger); margin-left: 2px; }
.field-hint { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }

input[type='text'], input[type='number'], input[type='date'],
input[type='search'], input[type='month'], select, textarea {
  width: 100%; height: 36px; padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px; font-family: inherit;
  transition: border-color .12s, box-shadow .12s;
  -webkit-appearance: none; appearance: none;
}
textarea { height: auto; min-height: 68px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238B93A1' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 28px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input[readonly] { background: var(--surface-3); color: var(--text-2); }
input[type='number'] { font-family: var(--font-num); }

.checkbox { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.checkbox input { width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer; margin: 0; flex: none; }

.search-box { position: relative; }
.search-box input { padding-left: 31px; }
.search-box::before {
  content: '🔍'; position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); font-size: 12px; opacity: .5; pointer-events: none;
}

/* ── 模态框 ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(16, 24, 40, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  animation: fadeIn .16s ease;
  backdrop-filter: blur(2px);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 620px;
  max-height: 90vh; display: flex; flex-direction: column;
  animation: slideUp .2s cubic-bezier(.16,1,.3,1);
}
.modal.modal-sm { max-width: 400px; }
.modal.modal-lg { max-width: 900px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15px; font-weight: 620; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; gap: 9px; justify-content: flex-end;
  padding: 13px 18px; border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.modal-foot .spacer { margin-right: auto; }
.confirm-text { font-size: 13.5px; color: var(--text-2); line-height: 1.6; }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 26px; left: 50%;
  transform: translateX(-50%) translateY(14px);
  background: #1A1D21; color: #fff;
  padding: 9px 18px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 300; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { background: var(--danger); }
.toast-warn { background: var(--warn); }

/* ── 空状态 ───────────────────────────────────────────────── */
.empty {
  padding: 44px 20px; text-align: center; color: var(--text-3);
}
.empty-icon { font-size: 34px; opacity: .35; margin-bottom: 10px; }
.empty-title { font-size: 14px; font-weight: 550; color: var(--text-2); margin-bottom: 4px; }
.empty-desc { font-size: 12.5px; }
.empty .btn { margin-top: 14px; }

/* ── 图表 ─────────────────────────────────────────────────── */
.chart-box { width: 100%; }
.chart-box svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  font-size: 12px; color: var(--text-2); margin-top: 10px;
}
.chart-legend-item { display: inline-flex; align-items: center; gap: 5px; cursor: default; }

/* 甜甜圈图例 */
.donut-legend { display: flex; flex-direction: column; gap: 8px; }
.donut-legend-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; cursor: pointer; padding: 2px 0;
}
.donut-legend-row:hover { opacity: .75; }
.donut-legend-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend-row .val { font-family: var(--font-num); font-weight: 600; }
.donut-legend-row .pct { color: var(--text-3); font-size: 11.5px; width: 42px; text-align: right; font-family: var(--font-num); }

/* ── 分组小标题 ───────────────────────────────────────────── */
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 620; color: var(--text);
  margin: 20px 0 9px;
}
.section-title:first-child { margin-top: 0; }
.section-title .line { flex: 1; height: 1px; background: var(--border); }
.section-title .count { font-size: 11.5px; color: var(--text-3); font-weight: 500; }

/* ── 列表项 ───────────────────────────────────────────────── */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-2); }
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 13.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: 11.5px; color: var(--text-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-amount { font-family: var(--font-num); font-weight: 620; font-size: 14px; white-space: nowrap; }

/* ── 详情行 ───────────────────────────────────────────────── */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-3); font-size: 12.5px; }
.kv dd { margin: 0; font-weight: 550; }

/* ── 预算行内编辑 ─────────────────────────────────────────── */
.budget-row-name { font-weight: 550; }
.budget-row-note { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.mini-input {
  height: 26px; padding: 0 7px; font-size: 12.5px;
  border: 1px solid transparent; background: transparent;
  border-radius: 5px; width: 100%;
}
.mini-input:hover { border-color: var(--border-strong); background: var(--surface); }
.mini-input:focus { border-color: var(--brand); background: var(--surface); }
.mini-input.num { text-align: right; font-family: var(--font-num); }

/* ── 提示条 ───────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 10px 13px; border-radius: var(--radius-sm);
  font-size: 12.5px; line-height: 1.55;
  border: 1px solid;
}
.alert-icon { flex: none; font-size: 14px; line-height: 1.4; }
.alert-danger { background: var(--danger-soft); border-color: var(--danger-border); color: #8A1C15; }
.alert-warn { background: var(--warn-soft); border-color: var(--warn-border); color: #8A5407; }
.alert-info { background: var(--info-soft); border-color: var(--info-border); color: #1E40AF; }
.alert-success { background: var(--success-soft); border-color: var(--success-border); color: #065F46; }
.alert-neutral { background: var(--surface-2); border-color: var(--border); color: var(--text-2); }
.alert + .alert { margin-top: 8px; }

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

/* ── 响应式 ───────────────────────────────────────────────── */
@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 14px 13px calc(var(--tabbar-h) + var(--safe-bottom) + 26px); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid-4.keep-2, .grid-3.keep-2 { grid-template-columns: repeat(2, 1fr); }
  .view-title { font-size: 17px; }
  .view-actions { width: 100%; margin-left: 0; }
  .view-actions .btn { flex: 1; }

  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 60;
    box-shadow: 0 -2px 10px rgba(16,24,40,.06);
  }
  .tabbar-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px;
    border: none; background: none; cursor: pointer;
    color: var(--text-3); font-size: 10.5px; padding: 6px 2px;
  }
  .tabbar-item .ico { font-size: 19px; line-height: 1; }
  .tabbar-item.active { color: var(--brand); font-weight: 600; }

  .modal { max-width: 100%; max-height: 92vh; }
  .modal-foot .btn { flex: 1; }
  .field-row { flex-direction: column; gap: 0; }
  table.data { font-size: 12.5px; }
  table.data th, table.data td { padding: 8px 9px; }
  .brand-sub { display: none; }
  /* 窄屏顶栏空间有限：摘要只留金额，去掉「已支出」标签与「/ 预算」分母 */
  .header-chip .card-sub, .header-chip .num-sub { display: none; }
  .header-chip { gap: 0; }
  .brand-title { font-size: 13px; }
}

@media (max-width: 420px) {
  .stat-value { font-size: 20px; }
  .grid-4.keep-2 { grid-template-columns: repeat(2, 1fr); }
  /* 极窄屏：品牌名可收缩，按钮只留图标文字 */
  .app-header { padding: 0 11px; gap: 8px; }
  .brand-text { overflow: hidden; }
  .brand-title { font-size: 12.5px; }
  .header-actions { gap: 6px; }
  .header-chip .num { font-size: 12px; }
  #btn-add-expense { padding: 0 9px; }
}

/* ── 打印 ─────────────────────────────────────────────────── */
@media print {
  .sidebar, .tabbar, .app-header, .view-actions, .btn { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .main { padding: 0; max-width: none; }
}

/* ── 滚动条 ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ── PWA 安装引导条 ─────────────────────────────────────────── */
.install-banner {
  position: fixed; z-index: 70;
  left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: flex-start; gap: 11px;
  padding: 12px 38px 12px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  transform: translateY(16px); opacity: 0;
  transition: transform .24s ease, opacity .24s ease;
}
.install-banner.show { transform: translateY(0); opacity: 1; }

.install-icon { flex: none; }
.install-icon img {
  width: 38px; height: 38px; border-radius: 10px; display: block;
  box-shadow: 0 2px 6px rgba(16,24,40,.14);
}
.install-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.install-text strong { font-size: 13.5px; font-weight: 650; }
.install-text span { font-size: 11.5px; color: var(--text-3); line-height: 1.45; }
.install-actions { flex: none; display: flex; gap: 6px; align-items: center; }
/* 关闭按钮绝对定位，避免挤占正文空间 */
.install-close {
  position: absolute; top: 7px; right: 7px;
  width: 24px; height: 24px; padding: 0;
  border: none; background: none; cursor: pointer;
  color: var(--text-3); font-size: 19px; line-height: 1;
  border-radius: 50%;
}
.install-close:hover { background: var(--surface-3); color: var(--text); }

@media (max-width: 860px) {
  .install-banner {
    left: 10px; right: 10px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 10px);
    padding: 11px 34px 11px 11px; gap: 9px;
  }
  .install-text span { font-size: 11px; }
  .install-icon img { width: 34px; height: 34px; }
}

/* 窄屏：说明文字与按钮上下排列，按钮占满整行但保持紧凑 */
@media (max-width: 420px) {
  .install-banner { flex-wrap: wrap; align-items: flex-start; }
  .install-text { flex: 1 1 100%; }
  .install-actions { flex: 1 1 100%; }
  .install-actions .btn { flex: 1; }
}
