/* MoneyMana 记账 — 移动优先样式 */
:root {
  --primary: #00A870;
  --primary-dark: #00875A;
  --income: #06AE56;
  --expense: #FA5151;
  --bg: #F4F6F8;
  --card: #FFFFFF;
  --text: #1B1F27;
  --muted: #8A919F;
  --line: #ECEEF2;
  --radius: 16px;
  --tabbar-h: 56px;
  --syncbar-h: 36px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 560px; margin: 0 auto; min-height: 100%; }
#view { padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); }

/* ---------- 通用 ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(20, 30, 50, 0.05);
}
.page-title { font-size: 22px; font-weight: 700; margin: 4px 0 14px; }
.muted { color: var(--muted); font-size: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 12px; background: var(--primary); color: #fff;
  font-size: 16px; font-weight: 600; padding: 12px 20px; cursor: pointer;
}
.btn:active { background: var(--primary-dark); }
.btn.ghost { background: #F0F2F5; color: var(--text); }
.btn.danger { background: #FFECEC; color: var(--expense); }
.btn.block { width: 100%; }

/* ---------- 底部导航 ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); z-index: 50;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10px; color: var(--muted); cursor: pointer; border: none; background: none;
}
.tab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--primary); font-weight: 600; }

/* ---------- 记一笔 ---------- */
.seg {
  display: flex; background: #EFF1F4; border-radius: 12px; padding: 3px; margin-bottom: 14px;
}
.seg button {
  flex: 1; border: none; background: none; padding: 8px 0; border-radius: 10px;
  font-size: 15px; color: var(--muted); font-weight: 600; cursor: pointer; transition: all .15s;
}
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.seg button.active.t-expense { color: var(--expense); }
.seg button.active.t-income { color: var(--income); }

.amount-box {
  display: flex; align-items: baseline; gap: 6px; padding: 18px 16px 6px;
  position: sticky; top: var(--syncbar-h); z-index: 20; background: var(--card);
  border-bottom: 1px solid var(--line);
}
.amount-box .cur { font-size: 24px; font-weight: 700; }
.amount-display {
  flex: 1; font-size: 40px; font-weight: 700; min-height: 48px; line-height: 48px;
  overflow: hidden; white-space: nowrap; text-align: right;
}
.amount-display.empty { color: #C6CBD4; font-size: 28px; }
.caret { display: inline-block; width: 2px; height: 34px; background: var(--primary); animation: blink 1s step-end infinite; vertical-align: middle; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }

.meta-row { display: flex; gap: 10px; padding: 10px 16px 14px; }
.meta-row input {
  flex: 1; border: none; background: #F4F6F8; border-radius: 10px;
  padding: 10px 12px; font-size: 14px; color: var(--text); outline: none; min-width: 0;
}
.meta-row input[type=date], .meta-row input[type=time] { flex: 0 0 auto; }

.cat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 0;
  padding: 6px 6px 2px;
}
.cat-item {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 8px 2px; border-radius: 12px; cursor: pointer; border: 2px solid transparent;
}
.cat-item .icon {
  width: 46px; height: 46px; border-radius: 50%; background: #F2F4F7;
  display: flex; align-items: center; justify-content: center; font-size: 23px;
}
.cat-item .name { font-size: 12px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item.selected { border-color: var(--primary); background: #E9F8F2; }
.cat-item.selected .name { color: var(--primary); font-weight: 600; }

/* 键盘 */
.keypad {
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 54px);
  gap: 6px; margin-top: 14px;
}
.key {
  border: none; border-radius: 12px; background: #fff; font-size: 22px; font-weight: 600;
  color: var(--text); cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.05);
  display: flex; align-items: center; justify-content: center; user-select: none;
}
.key:active { background: #E8EBEF; }
.key.fn { background: #EDF0F3; font-size: 17px; }
.key.save { grid-column: 4; grid-row: 3 / span 2; background: var(--primary); color: #fff; font-size: 17px; flex-direction: column; gap: 4px; }
.key.save:active { background: var(--primary-dark); }
.key.save:disabled { background: #BFE6D6; }
.key.zero { grid-column: 2 / span 2; }
.key svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.edit-banner {
  display: flex; align-items: center; justify-content: space-between;
  background: #FFF7E8; color: #B26A00; border-radius: 10px; padding: 9px 12px;
  font-size: 13px; margin-bottom: 12px;
}
.edit-banner button { border: none; background: none; color: var(--expense); font-size: 13px; cursor: pointer; font-weight: 600; }

/* ---------- 明细 ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav .label { font-size: 18px; font-weight: 700; }
.month-nav button {
  border: none; background: #fff; width: 34px; height: 34px; border-radius: 10px;
  font-size: 17px; color: var(--text); cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.month-nav button:disabled { opacity: .3; }

.sum-row { display: flex; gap: 10px; margin-bottom: 14px; }
.sum-item { flex: 1; background: #fff; border-radius: 14px; padding: 12px; text-align: center; box-shadow: 0 1px 3px rgba(20,30,50,.05); }
.sum-item .v { font-size: 16px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.sum-item .l { font-size: 11px; color: var(--muted); }
.sum-item .v.in { color: var(--income); }
.sum-item .v.out { color: var(--expense); }

.day-group { margin-bottom: 6px; }
.day-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 8px 6px 6px; }
.tx-list { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(20,30,50,.05); }
.tx-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; }
.tx-row:active { background: #F7F9FA; }
.tx-row + .tx-row { border-top: 1px solid var(--line); }
.tx-row .icon { width: 38px; height: 38px; border-radius: 50%; background: #F2F4F7; display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0; }
.tx-row .mid { flex: 1; min-width: 0; }
.tx-row .cat { font-size: 15px; font-weight: 500; }
.tx-row .tx-time { display: inline-block; font-size: 11px; color: var(--muted); background: #F2F4F7; border-radius: 6px; padding: 1px 6px; margin-right: 6px; vertical-align: 1px; font-variant-numeric: tabular-nums; }
.tx-row .note { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.tx-row .amt { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-row .amt.in { color: var(--income); }
.tx-row .amt.out { color: var(--text); }

.empty { text-align: center; padding: 48px 0; color: var(--muted); }
.empty .big { font-size: 44px; margin-bottom: 10px; }

/* ---------- 报表 ---------- */
.rank-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.rank-row .icon { width: 34px; height: 34px; border-radius: 50%; background: #F2F4F7; display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0; }
.rank-row .info { flex: 1; min-width: 0; }
.rank-row .top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px; }
.rank-row .top .money { font-weight: 600; font-variant-numeric: tabular-nums; }
.rank-row .pct { font-size: 12px; color: var(--muted); margin-left: 6px; font-weight: 400; }
.rank-bar { height: 8px; border-radius: 4px; background: #F0F2F5; overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: 4px; }
.seg-mini { display: flex; background: #EFF1F4; border-radius: 9px; padding: 2px; }
.seg-mini button { border: none; background: none; padding: 5px 14px; border-radius: 7px; font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; }
.seg-mini button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.chart-wrap { width: 100%; overflow: hidden; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 16px; justify-content: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.section-title { font-size: 15px; font-weight: 700; margin: 4px 0 10px; display: flex; justify-content: space-between; align-items: center; }

/* ---------- 设置 ---------- */
.set-group-title { font-size: 13px; color: var(--muted); margin: 18px 4px 8px; }
.set-list { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(20,30,50,.05); }
.set-item { display: flex; align-items: center; gap: 12px; padding: 13px 14px; cursor: pointer; }
.set-item:active { background: #F7F9FA; }
.set-item + .set-item { border-top: 1px solid var(--line); }
.set-item .icon { width: 34px; height: 34px; border-radius: 10px; background: #F2F4F7; display: flex; align-items: center; justify-content: center; font-size: 17px; }
.set-item .label { flex: 1; font-size: 15px; }
.set-item .arrow { color: #C6CBD4; font-size: 18px; }
.set-item .sub { font-size: 12px; color: var(--muted); margin-left: auto; margin-right: 4px; }

/* ---------- 弹窗 / Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 30px);
  transform: translateX(-50%) translateY(20px); background: rgba(27, 31, 39, 0.88); color: #fff;
  padding: 10px 22px; border-radius: 22px; font-size: 14px; opacity: 0;
  pointer-events: none; transition: all .25s; z-index: 200; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#modal-root { position: fixed; inset: 0; z-index: 100; display: none; }
#modal-root.show { display: block; }
.modal-mask { position: absolute; inset: 0; background: rgba(15, 20, 30, 0.45); }
.modal {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(88vw, 340px); background: #fff; border-radius: 18px; padding: 22px 18px 16px;
}
.modal h3 { font-size: 17px; margin-bottom: 8px; text-align: center; }
.modal p { font-size: 14px; color: var(--muted); text-align: center; line-height: 1.6; margin-bottom: 16px; }
.modal .actions { display: flex; gap: 10px; }
.modal .actions .btn { flex: 1; padding: 11px 0; }
.form-item { margin-bottom: 12px; }
.form-item label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.form-item input, .form-item select {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; outline: none; background: #fff;
}
.form-item input:focus { border-color: var(--primary); }
.emoji-palette { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-palette button {
  width: 38px; height: 38px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 19px; cursor: pointer;
}
.emoji-palette button.sel { border-color: var(--primary); background: #E9F8F2; }

.info-code {
  background: #F4F6F8; border-radius: 10px; padding: 10px 12px; font-size: 13px;
  line-height: 1.8; word-break: break-all; font-family: ui-monospace, monospace;
}

/* ---------- 同步状态条 / 离线 ---------- */
#syncbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 9px 16px; font-size: 13px;
  height: var(--syncbar-h); box-sizing: border-box;
}
#syncbar:empty { display: none; }
#syncbar.pending { background: #FFF7E8; color: #B26A00; }
#syncbar.off { background: #EDF0F3; color: #5F6368; }
#syncbar.ok { background: #E9F8F2; color: #0A7A4F; }
#syncbar .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 6px; vertical-align: 1px;
}
#syncbar .dot.on { background: #06AE56; box-shadow: 0 0 0 3px rgba(6,174,86,.15); }
#syncbar .dot.off { background: #B0B8C0; }
#syncbar button {
  border: none; border-radius: 8px; padding: 5px 14px; font-size: 13px;
  font-weight: 600; cursor: pointer; flex-shrink: 0;
}
#syncbar.pending button { background: #B26A00; color: #fff; }
#syncbar.off button { background: #fff; color: #5F6368; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
#syncbar button:disabled { opacity: .6; }

.offline-note {
  background: #FFF7E8; color: #B26A00; border-radius: 10px;
  padding: 9px 12px; font-size: 13px; margin-bottom: 12px;
}
.pending-badge {
  display: inline-block; background: #FFF3E0; color: #B26A00;
  font-size: 10px; padding: 1px 6px; border-radius: 6px;
  margin-left: 6px; vertical-align: 2px; font-weight: 500;
}
