:root {
  --primary: #0f766e;
  --primary-light: #14b8a6;
  --bg: #f6f7f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --expense: #dc2626;
  --income: #16a34a;
  --transfer: #6b7280;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  width: min(320px, 85vw);
  display: flex; flex-direction: column; gap: 12px;
  text-align: center;
}
.login-card h1 { color: var(--primary); margin-bottom: 8px; }

/* ---------- 布局 ---------- */
.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(76px + env(safe-area-inset-bottom));
}
.page h2 { margin-bottom: 12px; font-size: 20px; }
.page h3 { margin: 18px 0 8px; font-size: 16px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px;
  border: none; background: none;
  font-size: 11px; color: var(--muted);
  cursor: pointer;
}
.tabbar button span { font-size: 20px; }
.tabbar button.active { color: var(--primary); font-weight: 600; }

/* ---------- 表单 ---------- */
input, select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  background: var(--card);
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--primary-light); border-color: transparent; }

.form-row { display: flex; gap: 8px; margin-top: 10px; }
.form-row > * { flex: 1; }
#add-party, #add-note, #edit-party, #edit-note, #edit-amount, #edit-category { margin-top: 10px; }

.amount-input {
  font-size: 32px; font-weight: 700; text-align: center;
  padding: 16px; margin-bottom: 12px;
}

.type-switch {
  display: flex; gap: 6px; margin-bottom: 12px;
  background: #e9ecef; border-radius: var(--radius); padding: 4px;
}
.type-switch button {
  flex: 1; padding: 8px; border: none; border-radius: 9px;
  background: none; font-size: 15px; color: var(--muted); cursor: pointer;
}
.type-switch button.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.cat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin-bottom: 12px;
}
.cat-grid button {
  padding: 10px 4px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); font-size: 14px; cursor: pointer; color: var(--text);
}
.cat-grid button.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }

.btn {
  padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); font-size: 16px; cursor: pointer; color: var(--text);
}
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.btn.danger { background: #fee2e2; color: var(--expense); border-color: #fecaca; }
.btn.big { width: 100%; padding: 14px; margin-top: 4px; }
.btn:active { opacity: .85; }

.error { color: var(--expense); font-size: 14px; min-height: 1em; }
.hint { color: var(--muted); font-size: 13px; margin-bottom: 12px; line-height: 1.6; }

/* ---------- 明细 ---------- */
.month-bar {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  margin-bottom: 12px; font-size: 17px; font-weight: 600;
}
.month-nav {
  width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 50%;
  background: var(--card); font-size: 18px; cursor: pointer; color: var(--text);
}
.summary-bar {
  display: flex; justify-content: space-around;
  background: var(--card); border-radius: var(--radius);
  padding: 12px; margin-bottom: 12px; font-size: 14px;
}
.summary-bar b { display: block; font-size: 17px; margin-top: 2px; }

.day-group { margin-bottom: 14px; }
.day-head {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted); padding: 0 4px 6px;
}
.record {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--radius);
  padding: 12px; margin-bottom: 6px; cursor: pointer;
}
.record .cat-badge {
  flex-shrink: 0;
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: #e0f2f1; color: var(--primary); font-size: 13px; font-weight: 600;
}
.record .info { flex: 1; min-width: 0; }
.record .info .title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record .info .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.record .amt { font-weight: 700; font-size: 16px; flex-shrink: 0; }
.amt.expense { color: var(--expense); }
.amt.income { color: var(--income); }
.amt.transfer { color: var(--transfer); }

/* ---------- 识别/导入结果 ---------- */
.upload-box {
  display: block; text-align: center;
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 28px 16px; margin-bottom: 12px;
  background: var(--card); color: var(--muted); font-size: 16px; cursor: pointer;
}
.result-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 6px;
}
.result-item.dup { opacity: .5; }
.result-item input[type=checkbox] { width: 20px; height: 20px; flex-shrink: 0; }
.result-item .info { flex: 1; min-width: 0; font-size: 14px; }
.result-item .info .sub { font-size: 12px; color: var(--muted); }
.result-item select {
  width: auto; padding: 6px 8px; font-size: 13px; flex-shrink: 0;
}
.dup-tag { color: var(--expense); font-size: 11px; }

/* ---------- 统计 ---------- */
.totals {
  display: flex; gap: 10px; margin-bottom: 6px;
}
.totals .card {
  flex: 1; background: var(--card); border-radius: var(--radius);
  padding: 14px; text-align: center;
}
.totals .card .label { font-size: 13px; color: var(--muted); }
.totals .card .value { font-size: 20px; font-weight: 700; margin-top: 4px; }

.cat-row { margin-bottom: 10px; }
.cat-row .row-head {
  display: flex; justify-content: space-between;
  font-size: 14px; margin-bottom: 4px;
}
.cat-row .bar-bg {
  height: 8px; background: var(--border); border-radius: 4px; overflow: hidden;
}
.cat-row .bar {
  height: 100%; background: var(--primary-light); border-radius: 4px;
}

.daily-chart {
  display: flex; align-items: flex-end; gap: 2px;
  height: 120px; background: var(--card); border-radius: var(--radius);
  padding: 12px;
}
.daily-chart .day-col {
  flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
  height: 100%;
}
.daily-chart .day-col .bar {
  background: var(--primary-light); border-radius: 2px 2px 0 0; min-height: 2px;
}

/* ---------- 成员 ---------- */
.member-switch { margin-bottom: 10px; }
.member-filter {
  display: flex; gap: 6px; justify-content: center; margin-bottom: 12px;
}
.member-filter button {
  padding: 6px 16px; border: 1px solid var(--border); border-radius: 16px;
  background: var(--card); font-size: 13px; color: var(--muted); cursor: pointer;
}
.member-filter button.active {
  background: var(--mc, var(--primary)); border-color: var(--mc, var(--primary));
  color: #fff; font-weight: 600;
}
.member-badge {
  display: inline-block; padding: 1px 7px; border-radius: 9px;
  color: #fff; font-size: 11px; margin-right: 6px; vertical-align: middle;
}
#stats-members { margin-bottom: 6px; }
#stats-members b { margin-left: 4px; }

/* ---------- 弹窗 & Toast ---------- */
.modal {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  width: 100%; max-width: 560px;
  background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.modal-card h3 { margin-bottom: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%);
  background: rgba(31,41,55,.92); color: #fff;
  padding: 10px 18px; border-radius: 20px; font-size: 14px;
  z-index: 200; white-space: nowrap;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827; --card: #1f2937; --text: #f3f4f6;
    --muted: #9ca3af; --border: #374151;
  }
  .type-switch { background: #374151; }
  .record .cat-badge { background: #134e4a; color: #5eead4; }
}
