:root {
  --primary: #2b7a62;
  --primary-dark: #1f5c4a;
  --danger: #e24c4c;
  --income: #2e7d32;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #22302b;
  --muted: #7a8a84;
  --line: #e4e9e7;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: 76px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  box-shadow: 0 1px 6px rgba(0,0,0,.15);
}
.brand { font-size: 18px; font-weight: 700; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.user-chip {
  background: rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 12px 24px;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 4px 2px 12px;
}
.page-head h2 { margin: 0; font-size: 20px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card h3 { margin: 0 0 10px; font-size: 16px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

label {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
  color: #41504b;
}
label.check { display: flex; align-items: center; gap: 6px; margin-top: 6px; }

input, select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
}
input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
}
input[type="date"], input[type="month"], input[type="time"] {
  min-height: 44px;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  background: var(--line);
  color: var(--text);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: #eef2f0; color: var(--text); }
.btn-mini { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { display: block; width: 100%; margin-top: 6px; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  max-width: 560px;
  margin: 0 auto;
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tabbar a {
  flex: 1;
  text-align: center;
  padding: 11px 0 13px;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
}
.tabbar a.active { color: var(--primary); font-weight: 700; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  flex: 1;
  border: none;
  background: #eef2f0;
  color: var(--text);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  cursor: pointer;
}
.tab.active { background: var(--primary); color: #fff; font-weight: 700; }
.tab-panel { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.hidden { display: none; }

.flash {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 14px;
}
.flash.error { background: #fdecec; color: #a33333; }
.flash.ok { background: #e8f5ec; color: #1f5c4a; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.danger { color: var(--danger); }
.income { color: var(--income); }

.stat { text-align: center; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat.income { border-top: 3px solid var(--income); }
.stat.expense { border-top: 3px solid var(--danger); }
.stat.balance { border-top: 3px solid var(--primary); }

.reminder-list { list-style: none; margin: 0; padding: 0; }
.reminder-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.reminder-list li:last-child { border-bottom: none; }
.reminder-list .amount { margin-left: auto; font-weight: 700; }
.tag {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 6px;
  font-size: 12px;
  color: #fff;
}
.tag-income { background: var(--income); }
.tag-expense { background: var(--danger); }

.budget-row { margin-bottom: 10px; }
.budget-head {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 4px;
}
.progress {
  height: 10px;
  background: #edf1ef;
  border-radius: 999px;
  overflow: hidden;
}
.bar { height: 100%; background: var(--primary); border-radius: 999px; }
.bar.over { background: var(--danger); }
.bar.cat { background: #5b9d8b; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.table th { color: var(--muted); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.quick-links { display: flex; flex-wrap: wrap; gap: 8px; }
.quick-links .btn { flex: 1 1 40%; }

.add-title { font-weight: 700; cursor: pointer; padding: 4px 0; }
details.card { padding: 14px; }
details.card > form { margin-top: 10px; }

.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.tx-item:last-child { border-bottom: none; }
.tx-main { display: flex; justify-content: space-between; gap: 8px; }
.tx-merchant { font-weight: 600; font-size: 15px; }
.tx-amount { font-weight: 800; font-size: 16px; white-space: nowrap; }
.tx-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.tx-actions form { margin: 0; }

.filters label { margin-bottom: 8px; }

.scan-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.scan-item:last-child { border-bottom: none; }
.scan-item span { display: flex; flex-direction: column; gap: 2px; }

.login-wrap { max-width: 400px; margin: 8vh auto 0; padding: 0 4px; }
.login-title { text-align: center; font-size: 26px; margin: 0 0 18px; color: var(--primary); }

.warn { background: #fff7e6; border: 1px solid #ffe1a8; }

@media (min-width: 600px) {
  .container { padding: 16px 20px 32px; }
}
