:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --ink: #14161a;
  --ink-2: #6b7280;
  --ink-3: #9aa1ab;
  --line: #edeef1;
  --line-strong: #e2e4e8;
  --accent: #e4573d;
  --accent-soft: #fdeeea;
  --j: #3f7fbf;
  --l: #e08a3c;
  --green: #2f9e6b;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 6px 18px rgba(17, 24, 39, .04);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: 16px; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
input { border: 0; outline: none; background: transparent; }
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px calc(28px + var(--safe-b));
  background:
    radial-gradient(120% 70% at 15% 0%, #fff3ef 0%, rgba(255, 243, 239, 0) 55%),
    radial-gradient(90% 60% at 95% 8%, #eef4ff 0%, rgba(238, 244, 255, 0) 60%),
    var(--bg);
}
.gate-inner { width: 100%; max-width: 400px; }
.brand { text-align: center; margin-bottom: 26px; }
.brand-logo { width: 72px; height: 72px; border-radius: 20px; box-shadow: 0 10px 24px rgba(228, 87, 61, .22); }
.brand h1 { font-size: 26px; letter-spacing: 2px; margin: 16px 0 6px; font-weight: 700; }
.brand p { margin: 0; color: var(--ink-2); font-size: 14px; }
.gate-card {
  background: var(--card);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.gate-lead { margin: 0; color: var(--ink-2); font-size: 13.5px; }
.gate-tip { margin: 2px 0 0; text-align: center; font-size: 13px; color: var(--ink-3); }
.gate-tip a { color: var(--accent); text-decoration: none; }
.gate-error { color: #d93a2b; text-align: center; font-size: 13px; min-height: 18px; margin: 10px 0 0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--ink-2); padding-left: 2px; }
.field input, .text-input, .date-chip {
  background: #f6f7f8;
  border-radius: 12px;
  padding: 13px 14px;
  width: 100%;
  border: 1px solid transparent;
  transition: border-color .15s, background .15s;
}
.field input:focus, .text-input:focus { border-color: #cfd4dc; background: #fff; }

/* ---------- 按钮 ---------- */
.btn {
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  transition: transform .12s, opacity .15s;
}
.btn:active { transform: scale(.985); opacity: .9; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 8px 20px rgba(228, 87, 61, .24); }
.btn.ghost { background: #f4f5f7; color: var(--ink); }
.btn.danger { color: #d93a2b; }
.link-btn { color: var(--accent); font-size: 13.5px; padding: 4px 2px; }
.link-btn.danger { color: #d93a2b; }

/* ---------- 主体框架 ---------- */
.app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  padding-bottom: calc(84px + var(--safe-b));
  position: relative;
}
@media (min-width: 700px) {
  body { background: #e9eaee; }
  .app { box-shadow: 0 0 0 1px rgba(0,0,0,.04), 0 20px 50px rgba(0,0,0,.08); }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-t)) 18px 10px;
  background: rgba(242, 243, 245, .88);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
}
.topbar h2 { margin: 0; font-size: 22px; letter-spacing: .3px; }
.page-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-2); }
.icon-btn { color: var(--ink-2); padding: 8px; border-radius: 10px; }
.icon-btn:active { background: #e8eaed; }

.view { padding: 6px 14px 10px; }
.page { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.card-note { font-size: 12px; color: var(--ink-3); }

/* ---------- 记账 ---------- */
.entry { padding: 16px 16px 18px; }
.entry-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.date-chip {
  width: auto;
  font-size: 13.5px;
  color: var(--ink-2);
  padding: 8px 12px;
  border-radius: 10px;
  background: #f4f5f7;
  -webkit-appearance: none;
  appearance: none;
  min-height: 34px;
}
.seg { display: flex; background: #f2f3f5; border-radius: 11px; padding: 3px; }
.seg-item {
  padding: 7px 16px;
  border-radius: 9px;
  font-size: 14px;
  color: var(--ink-2);
  font-weight: 600;
  transition: all .16s;
  white-space: nowrap;
}
.seg-item.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-item[data-payer="J"].active { color: var(--j); }
.seg-item[data-payer="L"].active { color: var(--l); }

.amount-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 14px 2px 6px;
  border-bottom: 1.5px solid var(--line);
  margin-bottom: 4px;
}
.amount-wrap:focus-within { border-color: var(--accent); }
.yen { font-size: 26px; font-weight: 600; color: var(--ink-3); }
.amount-input {
  flex: 1;
  min-width: 0;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1.1;
  padding: 0;
  font-variant-numeric: tabular-nums;
}
.amount-input::placeholder { color: #ccd0d6; font-weight: 600; }

.section-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-2);
  margin: 15px 2px 8px;
}
.section-label em { font-style: normal; color: var(--ink-3); font-size: 11.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chips.purpose-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.chips.purpose-grid .chip { padding: 9px 4px; font-size: 13.5px; gap: 3px; }
.chips.purpose-grid .chip .code { padding: 0 3px; font-size: 9.5px; }
.chips.scroll-x { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 3px; }
.chips.scroll-x::-webkit-scrollbar { display: none; }
.chips.scroll-x .chip { flex: 0 0 auto; }
.chip {
  position: relative;
  padding: 9px 12px;
  border-radius: 12px;
  background: #f5f6f8;
  color: var(--ink);
  font-size: 14px;
  border: 1px solid transparent;
  transition: all .14s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  justify-content: center;
  white-space: nowrap;
}
.chip .code {
  font-size: 10.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  background: #fff;
  border-radius: 5px;
  padding: 0 4px;
  line-height: 15px;
}
.chip.active { background: var(--accent-soft); border-color: rgba(228, 87, 61, .35); color: #b93e28; font-weight: 600; }
.chip.active .code { color: #b93e28; background: #fff; }
.chip.quick { background: #fff; border-color: var(--line-strong); padding: 6px 11px; font-size: 13px; color: var(--ink-2); }
.chips.quick { margin-top: 8px; }
.chips.filter { gap: 7px; margin: 0 2px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips.filter::-webkit-scrollbar { display: none; }
.chips.filter .chip { flex: 0 0 auto; }

.text-input { margin-top: 0; }
.text-input.small { font-size: 14px; padding: 11px 13px; }
.extra { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.more-toggle { font-size: 12.5px; color: var(--ink-2); padding: 10px 2px 0; display: inline-flex; align-items: center; gap: 4px; }
.save-btn { width: 100%; margin-top: 16px; padding: 15px; font-size: 16.5px; }

.topbar-right { display: flex; align-items: center; gap: 2px; }
.top-save { font-size: 15px; font-weight: 650; color: var(--ink-3); padding: 6px 6px; border-radius: 8px; }
.top-save.ready { color: var(--accent); }

/* ---------- 流水列表 ---------- */
.tx-list { display: flex; flex-direction: column; }
.tx-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  width: 100%;
}
.tx-row:last-child { border-bottom: 0; }
.tx-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.tx-dot.J { background: var(--j); }
.tx-dot.L { background: var(--l); }
.tx-main { flex: 1; min-width: 0; }
.tx-title { display: flex; align-items: center; gap: 6px; font-size: 14.5px; }
.tx-title b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.tag-pill { background: #f4f5f7; color: var(--ink-2); border-radius: 5px; padding: 0 5px; font-size: 10.5px; line-height: 16px; }
.tx-amount { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amount.neg { color: var(--green); }

.groups { display: flex; flex-direction: column; gap: 10px; }
.group { background: var(--card); border-radius: var(--radius); padding: 12px 16px 4px; box-shadow: var(--shadow); }
.group-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 2px 0 8px; border-bottom: 1px solid var(--line);
}
.group-head span { font-size: 12.5px; color: var(--ink-2); }
.group-head b { font-size: 12.5px; color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- 月份条 ---------- */
.monthbar {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  background: var(--card); border-radius: 14px; padding: 8px; box-shadow: var(--shadow);
}
.monthbar button { color: var(--ink-2); padding: 6px 12px; border-radius: 9px; font-size: 18px; line-height: 1; }
.monthbar button:active { background: #f2f3f5; }
.monthbar .m-label { font-size: 15px; font-weight: 650; min-width: 128px; text-align: center; }
.monthbar .m-label small { display: block; font-size: 11px; color: var(--ink-3); font-weight: 400; }

.summary-strip { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; }
.summary-strip .s-main .s-label { font-size: 11.5px; color: var(--ink-3); }
.summary-strip .s-main .s-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.summary-strip .s-side { text-align: right; font-size: 12px; color: var(--ink-2); line-height: 1.7; }
.summary-strip .s-side i { font-style: normal; font-variant-numeric: tabular-nums; font-weight: 600; }
.load-more { display: flex; justify-content: center; margin-top: 4px; }
.empty { text-align: center; color: var(--ink-3); font-size: 13px; padding: 26px 0; }

/* ---------- 看板 ---------- */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--card); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.kpi .k-label { font-size: 11.5px; color: var(--ink-3); display: flex; justify-content: space-between; }
.kpi .k-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; letter-spacing: -.4px; }
.kpi .k-value small { font-size: 13px; font-weight: 500; color: var(--ink-3); }
.kpi .k-foot { font-size: 11.5px; color: var(--ink-2); margin-top: 2px; }
.up { color: var(--accent); }
.down { color: var(--green); }

.table-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
.table-scroll::-webkit-scrollbar { display: none; }
table.cross { border-collapse: collapse; font-size: 12.5px; min-width: 100%; }
table.cross th, table.cross td { padding: 8px 9px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.cross th { color: var(--ink-3); font-weight: 500; font-size: 11.5px; }
table.cross td:first-child, table.cross th:first-child {
  text-align: left; position: sticky; left: 0; background: var(--card); z-index: 1; padding-left: 0;
}
table.cross tbody tr:nth-child(even) td { background: #fafbfc; }
table.cross tbody tr:nth-child(even) td:first-child { background: #fafbfc; }
table.cross tr.total td { font-weight: 700; border-top: 1px solid var(--line-strong); }
table.cross td.zero { color: #d5d8dd; }

.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 46px 1fr 74px; align-items: center; gap: 9px; font-size: 12.5px; }
.bar-track { height: 8px; background: #f2f3f5; border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, #f0846c, #e4573d); }
.bar-amount { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }

.split { display: flex; gap: 6px; height: 34px; border-radius: 10px; overflow: hidden; margin: 4px 0 12px; }
.split div { display: flex; align-items: center; justify-content: center; font-size: 11.5px; color: #fff; font-weight: 600; }
.split .j { background: var(--j); }
.split .l { background: var(--l); }
.split .none { background: #e5e7eb; color: var(--ink-3); }
.pay-rows { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.pay-rows > div { display: flex; justify-content: space-between; }
.pay-rows b { font-variant-numeric: tabular-nums; }
.settle { margin-top: 12px; background: #f7f8f9; border-radius: 12px; padding: 11px 12px; font-size: 12.5px; color: var(--ink-2); line-height: 1.6; }
.settle b { color: var(--ink); }

.rank { display: flex; flex-direction: column; gap: 10px; }
.rank-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: 13.5px; }
.rank-bar { grid-column: 1 / -1; height: 6px; background: #f2f3f5; border-radius: 4px; overflow: hidden; }
.rank-bar i { display: block; height: 100%; background: #cfd4dc; border-radius: 4px; }
.rank-row.top .rank-bar i { background: var(--accent); }

.trend { display: flex; align-items: flex-end; gap: 5px; height: 120px; padding-top: 8px; }
.trend .t-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; height: 100%; }
.trend .t-bar { width: 100%; background: #dfe3e8; border-radius: 4px 4px 2px 2px; min-height: 3px; }
.trend .t-col.cur .t-bar { background: var(--accent); }
.trend .t-lab { font-size: 9.5px; color: var(--ink-3); white-space: nowrap; }

.tag-list { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.tag-list > div { display: flex; justify-content: space-between; }

.kv-list { display: flex; flex-direction: column; }
.kv-list > div { display: flex; justify-content: space-between; padding: 8px 0; font-size: 13.5px; border-bottom: 1px solid var(--line); }
.kv-list > div:last-child { border-bottom: 0; }
.kv-list b { font-variant-numeric: tabular-nums; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.foot { text-align: center; font-size: 11.5px; color: var(--ink-3); margin: 6px 0 0; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 460px;
  display: flex;
  padding: 6px 8px calc(6px + var(--safe-b));
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid rgba(0, 0, 0, .06);
  z-index: 30;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0 4px;
  color: var(--ink-3);
  font-size: 10.5px;
}
.tab svg { width: 23px; height: 23px; }
.tab.active { color: var(--accent); }

/* ---------- 弹层 ---------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(17, 20, 25, .38);
  z-index: 60; display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.sheet {
  width: 100%; max-width: 460px; background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 8px 0 calc(14px + var(--safe-b));
  max-height: 92dvh; overflow-y: auto;
  animation: slideUp .22s cubic-bezier(.32, .72, 0, 1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 6px; }
.sheet-head h3 { margin: 0; font-size: 15px; }
.sheet-body { padding: 6px 14px 0; display: flex; flex-direction: column; gap: 12px; }
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translate(-50%, 12px);
  background: rgba(20, 22, 26, .92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 80;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
