:root {
  --primary: #0fa678;
  --primary-dark: #0c855f;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #8a9099;
  --expense: #e8553e;
  --income: #2ecc71;
  --border: #eceef1;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

#app { max-width: 480px; margin: 0 auto; min-height: 100vh; padding: 16px 16px 90px; }

/* 顶部标题栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 13px; }

/* 卡片 */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; color: var(--muted); font-weight: 600; }

/* 汇总大数字 */
.balance { text-align: center; padding: 8px 0 4px; }
.balance .label { color: var(--muted); font-size: 13px; }
.balance .amount { font-size: 34px; font-weight: 700; margin: 4px 0; }
.balance .amount.neg { color: var(--expense); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); text-align: center;
}
.stat .label { color: var(--muted); font-size: 12px; }
.stat .val { font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat .val.expense { color: var(--expense); }
.stat .val.income { color: var(--income); }

/* 成员行 */
.member-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.member-row:last-child { border-bottom: none; }
.member-row .name { font-weight: 600; }
.member-row .nums { text-align: right; font-size: 13px; }
.member-row .nums .e { color: var(--expense); }
.member-row .nums .i { color: var(--income); }

/* 明细列表 */
.tx {
  display: flex; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.tx:active { background: #fafafa; }
.tx .ico { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; margin-right: 12px; }
.tx .mid { flex: 1; min-width: 0; }
.tx .mid .cat { font-weight: 600; }
.tx .mid .meta { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 700; font-size: 16px; }
.tx .amt.expense { color: var(--expense); }
.tx .amt.income { color: var(--income); }

/* 表单 */
.field { margin-bottom: 14px; }
.field label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--text); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { resize: none; height: 70px; }

/* 类型切换 */
.segment { display: flex; background: #eef0f2; border-radius: 10px; padding: 4px; }
.segment button {
  flex: 1; border: none; background: transparent; padding: 10px; border-radius: 8px;
  font-size: 15px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.segment button.active.expense { background: var(--expense); color: #fff; }
.segment button.active.income { background: var(--income); color: #fff; }

/* 分类选择网格 */
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.cat-cell {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 4px; text-align: center;
  cursor: pointer; font-size: 13px;
}
.cat-cell .emoji { font-size: 22px; display: block; }
.cat-cell.active { border-color: var(--primary); background: #e9f8f2; color: var(--primary-dark); font-weight: 600; }

/* 按钮 */
.btn {
  display: block; width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn:active { background: var(--primary-dark); }
.btn.ghost { background: #eef0f2; color: var(--text); }
.btn.danger { background: #ffecea; color: var(--expense); }
.btn-row { display: flex; gap: 10px; }

/* 底部导航 */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 480px;
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border); padding: 6px 0 env(safe-area-inset-bottom);
  z-index: 50;
}
.tabbar a { text-decoration: none; color: var(--muted); font-size: 11px; text-align: center; flex: 1; }
.tabbar a span { display: block; }
.tabbar a.active { color: var(--primary); }
.tabbar .fab {
  flex: 0 0 auto; width: 52px; height: 52px; margin-top: -22px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 28px; line-height: 52px;
  box-shadow: 0 4px 14px rgba(15, 166, 120, 0.4); font-weight: 700;
}
.tabbar .fab span { display: none; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  background: #fff; width: 100%; max-width: 480px; border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto;
  animation: slideUp 0.22s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-card h3 { margin: 0 0 14px; font-size: 17px; }

/* Toast */
.toast {
  position: fixed; left: 50%; top: 40%; transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.82); color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; z-index: 200; max-width: 80%; text-align: center;
}

/* 杂项 */
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--muted); }
.right { text-align: right; }
.login-wrap { max-width: 360px; margin: 12vh auto 0; padding: 0 24px; }
.login-wrap h1 { text-align: center; color: var(--primary); font-size: 26px; }
.login-wrap .logo { font-size: 54px; text-align: center; }
.hint { font-size: 12px; color: var(--muted); text-align: center; margin-top: 10px; }
.chart-box { position: relative; height: 220px; }
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.filter-bar select { flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.pill { padding: 6px 12px; border-radius: 20px; background: #eef0f2; color: var(--muted); font-size: 13px; border: none; }
.pill.active { background: var(--primary); color: #fff; }
