/* 兜兜记账 — 移动优先 */
:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --ink: #24312b;
  --ink-2: #5b6b62;
  --ink-3: #93a29a;
  --line: #e6ebe7;
  --primary: #0f9d76;
  --primary-weak: #e2f4ec;
  --accent: #e8663c;
  --danger: #d9534f;
  --warn: #c77c11;
  --warn-weak: #fdf3e0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(36, 49, 43, .06), 0 4px 14px rgba(36, 49, 43, .05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.5;
}
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--ink); }

/* ---------- 顶栏 / 底栏 ---------- */
.topbar { position: sticky; top: 0; z-index: 50; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; }
.brand { font-weight: 700; font-size: 17px; display: flex; gap: 6px; align-items: center; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-user { color: var(--ink-2); font-size: 13px; }
.icon-btn { border: 0; background: transparent; font-size: 18px; padding: 4px; border-radius: 8px; text-decoration: none; }
.icon-btn:active { background: var(--line); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; background: rgba(255,255,255,.95); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; text-align: center; padding: 6px 0 7px; color: var(--ink-3); font-size: 11px; }
.tabbar a .tab-icon { display: block; font-size: 20px; line-height: 1.3; }
.tabbar a.active { color: var(--primary); font-weight: 600; }

/* ---------- 布局 ---------- */
.app { max-width: 760px; margin: 0 auto; padding: 14px 14px calc(76px + env(safe-area-inset-bottom)); }
@media (min-width: 761px) { .app { padding-top: 22px; } }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h3 { font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--ink-3); font-size: 13px; }
.muted-2 { color: var(--ink-2); font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; background: #fbfcfb; outline: none;
}
.input:focus { border-color: var(--primary); background: #fff; }
textarea.input { resize: vertical; min-height: 56px; }
.amount-input { font-size: 30px; font-weight: 700; text-align: center; letter-spacing: .5px; }
.amount-prefix { text-align: center; color: var(--ink-3); font-size: 14px; margin-bottom: -4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; font-size: 15px;
  background: var(--primary); color: #fff;
}
.btn:active { opacity: .85; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; padding: 13px; font-size: 16px; }
.btn.ghost { background: var(--primary-weak); color: var(--primary); }
.btn.plain { background: #eef1ee; color: var(--ink-2); }
.btn.danger { background: #fbe9e8; color: var(--danger); }
.btn.warn { background: var(--warn-weak); color: var(--warn); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

.seg { display: flex; background: #eef1ee; border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; border-radius: 8px; padding: 8px 0; background: transparent; color: var(--ink-2); font-weight: 600; }
.seg button.on { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button.on.family { color: var(--primary); }
.seg button.on.personal { color: var(--accent); }

.chip-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (min-width: 480px) { .chip-grid { grid-template-columns: repeat(6, 1fr); } }
.chip {
  border: 1px solid var(--line); background: #fbfcfb; border-radius: 10px;
  padding: 7px 2px; text-align: center; font-size: 12px; color: var(--ink-2);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.chip .ci { display: block; font-size: 19px; line-height: 1.35; }
.chip.on { border-color: var(--primary); background: var(--primary-weak); color: var(--primary); font-weight: 600; }

/* ---------- 汇总卡 ---------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary .s-item { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 10px; text-align: center; }
.summary .s-label { font-size: 12px; color: var(--ink-3); }
.summary .s-value { font-size: 19px; font-weight: 700; margin-top: 2px; }
.summary .s-value.accent { color: var(--primary); }
.summary .s-value.personal { color: var(--accent); }

/* ---------- 记录列表 ---------- */
.day-head { display: flex; justify-content: space-between; padding: 10px 6px 4px; color: var(--ink-3); font-size: 12.5px; }
.txn {
  display: flex; align-items: center; gap: 11px;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 11px 13px; margin-bottom: 8px;
}
.txn .t-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--primary-weak); display: flex; align-items: center; justify-content: center; font-size: 19px; flex: none; }
.txn .t-main { flex: 1; min-width: 0; }
.txn .t-title { font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.txn .t-sub { color: var(--ink-3); font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.txn .t-amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.txn .t-amt.personal { color: var(--accent); }
.tag { display: inline-block; font-size: 11px; border-radius: 5px; padding: 0 5px; line-height: 17px; vertical-align: 1px; }
.tag.family { background: var(--primary-weak); color: var(--primary); }
.tag.personal { background: #fdeee7; color: var(--accent); }
.tag.ok { background: var(--primary-weak); color: var(--primary); }
.tag.question { background: var(--warn-weak); color: var(--warn); }
.t-actions { display: flex; flex-direction: column; gap: 4px; }
.t-actions button { border: 0; background: transparent; color: var(--ink-3); font-size: 12px; padding: 2px 4px; }

/* ---------- 状态 / 徽标 ---------- */
.status-pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 12px; font-size: 13px; font-weight: 600; }
.status-open { background: var(--primary-weak); color: var(--primary); }
.status-closed { background: var(--warn-weak); color: var(--warn); }
.status-finalized { background: #e8ecf6; color: #3d5bb5; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.member-line { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.member-line:last-child { border-bottom: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-weak); color: var(--primary); font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }

/* ---------- 对比条 ---------- */
.bar-row { display: flex; align-items: center; gap: 8px; margin: 7px 0; }
.bar-row .bar-label { width: 74px; font-size: 13px; color: var(--ink-2); text-align: right; flex: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bar-row .bar-track { flex: 1; height: 14px; background: #edf0ed; border-radius: 7px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 7px; background: var(--primary); }
.bar-row .bar-fill.alt { background: var(--accent); }
.bar-row .bar-val { width: 86px; font-size: 12.5px; font-variant-numeric: tabular-nums; flex: none; }

/* ---------- 账单 ---------- */
.bill-hero { text-align: center; padding: 26px 16px 20px; background: linear-gradient(160deg, #10795c, #0f9d76); color: #fff; border-radius: var(--radius); margin-bottom: 14px; }
.bill-hero .bh-period { font-size: 14px; opacity: .85; letter-spacing: 2px; }
.bill-hero .bh-total { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 6px 0 2px; }
.bill-hero .bh-sub { font-size: 12.5px; opacity: .8; }
.bill-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.bill-table th, .bill-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.bill-table th { color: var(--ink-3); font-weight: 500; font-size: 12.5px; }
.bill-table td.num, .bill-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .bill-table .col-pm { display: none; } }
.transfer-line { background: var(--warn-weak); border-radius: 10px; padding: 10px 12px; margin-top: 8px; font-size: 14px; }

/* ---------- Toast / Modal ---------- */
.toast-wrap { position: fixed; top: 14px; left: 0; right: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: rgba(36,49,43,.92); color: #fff; border-radius: 999px; padding: 9px 20px; font-size: 14px; max-width: 86%; animation: fadein .18s; }
.toast.err { background: rgba(190,60,50,.95); }
@keyframes fadein { from { opacity: 0; transform: translateY(-6px); } }

.modal-mask { position: fixed; inset: 0; background: rgba(20,28,24,.45); z-index: 100; display: flex; align-items: flex-end; justify-content: center; animation: fadein .15s; }
@media (min-width: 560px) { .modal-mask { align-items: center; } }
.modal { background: var(--card); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto; }
@media (min-width: 560px) { .modal { border-radius: 18px; padding-bottom: 18px; } }
.modal h3 { margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

/* ---------- 登录 ---------- */
.auth-wrap { min-height: 92vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.auth-logo { text-align: center; font-size: 46px; margin-bottom: 6px; }
.auth-title { text-align: center; font-size: 21px; font-weight: 800; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--ink-3); font-size: 13px; margin-bottom: 22px; }

.empty { text-align: center; color: var(--ink-3); padding: 34px 0; font-size: 14px; }
.empty .e-icon { font-size: 38px; display: block; margin-bottom: 8px; opacity: .75; }

/* 月度切换 */
.month-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 12px; }
.month-nav button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 5px 13px; font-size: 15px; color: var(--ink-2); }
.month-nav .mn-label { font-weight: 700; min-width: 108px; text-align: center; }
.month-nav .mn-future { opacity: .35; pointer-events: none; }

.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 260px; }

/* ---------- 小票识别 ---------- */
.ai-draft { background: var(--primary-weak); border: 1px solid #bfe3d6; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.ai-draft details { margin-top: 8px; }
.ai-draft summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }
.ai-item { padding: 4px 0; font-size: 13.5px; border-bottom: 1px dashed rgba(0,0,0,.06); }
.ai-item:last-child { border-bottom: 0; }
.ai-warn { background: var(--warn-weak); color: var(--warn); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; margin-top: 8px; }
.ai-error { background: #fbe9e8; color: #9c3a30; border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 13.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-error .btn { margin-left: auto; }
.ai-split { margin-top: 10px; font-size: 13.5px; color: var(--ink-2); gap: 6px; }
.ai-cat { border: 0; background: rgba(15,157,118,.1); color: var(--primary); border-radius: 999px; padding: 2px 8px; font-size: 11px; white-space: nowrap; flex: none; }
.ai-cat.unset { background: #eef1ee; color: var(--ink-3); }
.ai-cat-clear { border: 0; background: transparent; color: var(--ink-3); font-size: 12.5px; padding: 4px 0; margin-top: 2px; }
.ai-cat-clear.on { color: var(--accent); }
.rlink { text-decoration: none; margin-left: 4px; }

.ai-checklist { margin-top: 10px; }
.ai-check-head { padding: 2px 2px 6px; border-bottom: 1px solid rgba(0,0,0,.08); }
.ai-check-head b.all-done { color: var(--primary); }
.ai-checklist .ai-item { padding: 7px 2px; border-bottom: 1px dashed rgba(0,0,0,.07); font-size: 14px; }
.ai-checklist .ai-item.ok { opacity: .55; }
.ai-checklist .ai-item.ok .grow span { text-decoration: line-through; }
.ai-checklist input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--primary); flex: none; }
.ai-edit { border: 0; background: transparent; color: var(--ink-3); font-size: 15px; padding: 4px 6px; }
.ai-edit:active { color: var(--primary); }
.img-overlay { position: fixed; inset: 0; z-index: 150; background: rgba(10,14,12,.93); display: flex; flex-direction: column; align-items: center; padding: 14px; overflow: auto; }
.img-overlay img { max-width: 100%; border-radius: 8px; }
.img-tip { color: rgba(255,255,255,.65); font-size: 12.5px; padding: 10px 0; }

/* ---------- 打印 ---------- */
@media print {
  .topbar, .tabbar, .no-print { display: none !important; }
  body { background: #fff; }
  .app { padding: 0; max-width: 100%; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .bill-hero { background: #10795c !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
