/* 小账本 · 样式 */
:root {
  --bg: #F4F5F9;
  --card: #FFFFFF;
  --ink: #171A24;
  --ink2: #565D72;
  --muted: #9298AB;
  --line: #EFF1F6;
  --primary: #4F6EF7;
  --primary-soft: #EDF0FE;
  --green: #12B76A;
  --green-soft: #E8F8F0;
  --red: #F04438;
  --radius: 20px;
  --shadow: 0 6px 22px rgba(23, 26, 36, .06);
  --shadow-sm: 0 2px 10px rgba(23, 26, 36, .05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
    "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(150px + env(safe-area-inset-bottom));
  position: relative;
}

.view { animation: fade .22s ease both; padding: 0 16px; }
.view[hidden] { display: none; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------- 顶部 ---------------- */
.top {
  padding: calc(14px + env(safe-area-inset-top)) 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.month {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: .2px;
}

.month button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--muted);
  font-size: 18px;
}
.month button:active { background: #E9ECF5; }
.month .m-label { min-width: 96px; text-align: center; cursor: pointer; }

.round-btn {
  width: 38px;
  height: 38px;
  border-radius: 13px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  display: grid;
  place-items: center;
  color: var(--ink2);
}
.round-btn:active { transform: scale(.96); }

/* ---------------- 汇总卡 ---------------- */
.hero {
  margin-top: 10px;
  padding: 20px;
  border-radius: 26px;
  background: linear-gradient(135deg, #5B7CFA 0%, #7A5BF7 100%);
  color: #fff;
  box-shadow: 0 14px 34px rgba(91, 124, 250, .28);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  width: 180px; height: 180px;
  right: -60px; top: -90px;
  background: radial-gradient(circle, rgba(255,255,255,.28), rgba(255,255,255,0) 70%);
  border-radius: 50%;
}
.hero .label { font-size: 13px; opacity: .82; letter-spacing: .4px; }
.hero .amount {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -.6px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.hero .amount small { font-size: 18px; font-weight: 600; opacity: .9; margin-right: 2px; }
.hero .sub {
  display: flex;
  gap: 26px;
  margin-top: 14px;
  font-size: 13px;
  opacity: .92;
}
.hero .sub b { font-weight: 650; font-variant-numeric: tabular-nums; }
.hero .sub span { opacity: .75; margin-right: 6px; }

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card-title {
  font-size: 14px;
  font-weight: 650;
  color: var(--ink2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title .more { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---------------- 快捷识别 ---------------- */
.action-bar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(62px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px 16px 12px;
  background: var(--bg);
  z-index: 20;
}
.action-bar::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: -18px;
  height: 18px;
  background: linear-gradient(to top, #F4F5F9, rgba(244,245,249,0));
  pointer-events: none;
}
.action-bar .act {
  flex: 1 1 0;
  min-width: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid rgba(255,255,255,.9);
  box-shadow: 0 6px 18px rgba(31,41,71,.10);
  font-size: 13.5px;
  font-weight: 640;
  color: var(--text);
  transition: transform .12s ease, box-shadow .12s ease;
}
.action-bar .act svg { flex: none; color: var(--primary); }
.action-bar .act span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.action-bar .act:active { transform: scale(.97); box-shadow: 0 3px 10px rgba(31,41,71,.10); }
.action-bar .add {
  flex: none;
  width: 48px; height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, #5B7CFA, #7A5BF7);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  font-weight: 400;
  box-shadow: 0 8px 20px rgba(91,124,250,.36);
  transition: transform .12s ease;
}
.action-bar .add:active { transform: scale(.94); }
.action-bar[hidden] { display: none; }

/* ---------------- 列表 ---------------- */
.list { margin-top: 16px; }
.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 6px 6px;
  font-size: 12.5px;
  color: var(--muted);
}
.day-head b { font-weight: 600; color: #7A8095; font-variant-numeric: tabular-nums; }

.day-card { background: #fff; border-radius: 18px; box-shadow: var(--shadow-sm); overflow: hidden; }
.day-card + .day-card { margin-top: 10px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  position: relative;
}
.row + .row::before {
  content: "";
  position: absolute;
  left: 62px; right: 0; top: 0;
  height: 1px;
  background: var(--line);
}
.row:active { background: #FAFBFF; }

.emoji {
  width: 42px; height: 42px;
  border-radius: 14px;
  display: grid; place-items: center;
  font-size: 21px;
  background: #F3F5FB;
  flex: none;
}
.row .mid { flex: 1; min-width: 0; }
.row .mid .t { font-size: 15px; font-weight: 550; }
.row .mid .s {
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}
.row .amt {
  font-size: 16px; font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.2px;
}
.row .amt.income { color: var(--green); }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  padding: 44px 0 40px;
}
.empty .big { font-size: 40px; margin-bottom: 8px; opacity: .85; }

/* ---------------- 统计 ---------------- */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { position: relative; width: 132px; height: 132px; flex: none; }
.donut canvas { width: 132px; height: 132px; }
.donut .center {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center;
}
.donut .center .k { font-size: 11.5px; color: var(--muted); }
.donut .center .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

.legend { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.legend .item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; }
.legend .dot { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.legend .n { flex: 1; color: var(--ink2); }
.legend .p { color: var(--muted); font-variant-numeric: tabular-nums; }

.cat-bars { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .emoji { width: 32px; height: 32px; border-radius: 11px; font-size: 16px; }
.bar-row .body { flex: 1; }
.bar-row .l1 { display: flex; justify-content: space-between; margin-bottom: 5px; }
.bar-row .l1 span { color: var(--ink2); font-size: 13px; }
.bar-row .l1 b { font-variant-numeric: tabular-nums; font-weight: 600; }
.bar-track { height: 6px; background: #F1F3F9; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; transition: width .5s cubic-bezier(.22,.61,.36,1); }

.trend { display: flex; align-items: flex-end; gap: 10px; height: 116px; padding: 4px 2px 0; }
.trend .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.trend .bar {
  width: 100%;
  max-width: 26px;
  background: linear-gradient(180deg, #8FA4FF, #5B7CFA);
  border-radius: 7px;
  min-height: 3px;
  transition: height .5s cubic-bezier(.22,.61,.36,1);
}
.trend .bar.zero { background: #EDF0F7; }
.trend .lab { font-size: 10.5px; color: var(--muted); }

/* ---------------- 设置 ---------------- */
.set-group { margin-top: 14px; }
.set-group .g-title {
  font-size: 12.5px; color: var(--muted);
  padding: 0 6px 7px; letter-spacing: .3px;
}
.set-list { background: #fff; border-radius: 18px; box-shadow: var(--shadow-sm); overflow: hidden; }
.set-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px;
  position: relative;
}
.set-row + .set-row::before {
  content: ""; position: absolute; left: 14px; right: 0; top: 0; height: 1px; background: var(--line);
}
.set-row .k { font-size: 14.5px; }
.set-row .v { margin-left: auto; font-size: 13px; color: var(--muted); max-width: 55%; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set-row .chev { color: #C6CBD9; font-size: 17px; margin-left: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--muted); padding-left: 2px; }
.field input, .field select, .field textarea {
  background: #F5F6FA;
  border-radius: 13px;
  padding: 12px 14px;
  font-size: 14.5px;
  border: 1.5px solid transparent;
  transition: border-color .18s, background .18s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  background: #fff;
}
.field .hint { font-size: 11.5px; color: var(--muted); padding-left: 2px; line-height: 1.45; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 46px; padding: 0 18px;
  border-radius: 14px;
  font-size: 15px; font-weight: 600;
  background: var(--primary); color: #fff;
  transition: transform .12s, opacity .2s;
}
.btn:active { transform: scale(.98); opacity: .92; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--primary-soft); color: var(--primary); }
.btn.gray { background: #F1F3F9; color: var(--ink2); }
.btn.small { height: 36px; padding: 0 14px; font-size: 13.5px; border-radius: 11px; }
.btn[disabled] { opacity: .5; }

/* ---------------- 底部导航 ---------------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  height: calc(62px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.94);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid #EDEFF5;
  display: flex;
  z-index: 30;
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: #A5ABBC;
  font-size: 10.5px;
  font-weight: 550;
}
.tab.active { color: var(--primary); }
.tab svg { width: 22px; height: 22px; }

/* ---------------- 弹层 ---------------- */
.mask {
  position: fixed; inset: 0;
  background: rgba(14,17,28,.42);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 50;
}
.mask.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  max-height: 92dvh;
  background: #fff;
  border-radius: 26px 26px 0 0;
  transform: translateY(102%);
  transition: transform .32s cubic-bezier(.22,.61,.36,1);
  z-index: 60;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 40px rgba(20,24,40,.12);
}
.sheet.open { transform: translateY(0); }
.sheet-head {
  padding: 14px 20px 8px;
  display: flex; align-items: center; justify-content: space-between;
  flex: none;
}
.sheet-head h3 { margin: 0; font-size: 16.5px; font-weight: 650; }
.sheet-head .x {
  width: 30px; height: 30px; border-radius: 50%;
  background: #F2F4F9; color: #7C8296;
  display: grid; place-items: center;
  font-size: 16px;
}
.sheet-body {
  padding: 4px 20px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}
.sheet-foot {
  flex: none;
  padding: 10px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #fff;
}
.sheet-grip {
  width: 36px; height: 4px; border-radius: 3px; background: #E4E7EF;
  margin: 8px auto 0;
}

/* 记一笔 */
.kind-seg {
  display: flex; background: #F3F5FA; border-radius: 13px; padding: 4px; gap: 4px;
  margin-bottom: 16px;
}
.kind-seg button {
  flex: 1; height: 36px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted);
  transition: all .18s;
}
.kind-seg button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(23,26,36,.08); }

.amount-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 2px 14px;
  border-bottom: 1.5px solid var(--line);
  margin-bottom: 16px;
}
.amount-row .cur { font-size: 22px; font-weight: 600; color: var(--ink2); }
.amount-row input {
  flex: 1; font-size: 38px; font-weight: 700; letter-spacing: -.8px;
  padding: 0; font-variant-numeric: tabular-nums;
  min-width: 0;
}
.amount-row input::placeholder { color: #D3D8E4; font-weight: 600; }

.cat-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 10px 6px; margin-bottom: 18px;
}
.cat-item {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 6px 0;
  border-radius: 14px;
  font-size: 11.5px; color: var(--ink2);
  transition: background .15s;
}
.cat-item .emoji { width: 40px; height: 40px; font-size: 19px; border-radius: 13px; transition: all .18s; }
.cat-item.on { color: var(--primary); font-weight: 600; }
.cat-item.on .emoji { background: var(--primary); box-shadow: 0 6px 14px rgba(79,110,247,.32); }

.form-line { display: flex; gap: 10px; }
.form-line > * { flex: 1; }

.attach {
  display: flex; align-items: center; gap: 10px;
  background: #F5F6FA; border-radius: 13px; padding: 8px;
  margin-bottom: 16px;
}
.attach img { width: 46px; height: 46px; border-radius: 9px; object-fit: cover; }
.attach .info { flex: 1; font-size: 12.5px; color: var(--ink2); }
.attach .info small { display: block; color: var(--muted); font-size: 11px; }
.attach .del { color: var(--red); font-size: 12.5px; padding: 6px 8px; }

.ai-banner {
  background: linear-gradient(135deg, #EEF1FF, #F3EEFF);
  border-radius: 14px;
  padding: 11px 13px;
  font-size: 12.5px;
  color: #4A4FA8;
  margin-bottom: 14px;
  display: flex; gap: 8px; align-items: flex-start;
}
.ai-banner b { font-weight: 650; }

/* 识别弹层 */
.scan-options { display: flex; gap: 12px; padding: 6px 0 8px; }
.scan-option {
  flex: 1;
  background: #F7F8FC;
  border-radius: 18px;
  padding: 22px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 550;
}
.scan-option .ico {
  width: 52px; height: 52px; border-radius: 17px;
  background: #fff; box-shadow: var(--shadow-sm);
  display: grid; place-items: center;
  color: var(--primary);
}
.scan-option:active { transform: scale(.98); }

/* 扫描中 */
.scanning {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(10,12,20,.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; color: #fff;
}
.scanning[hidden] { display: none; }
.scan-frame {
  width: 220px; height: 280px;
  border-radius: 20px;
  position: relative;
  overflow: hidden;
  background: #1B1F2E;
  box-shadow: 0 0 0 1px rgba(255,255,255,.14);
}
.scan-frame img { width: 100%; height: 100%; object-fit: cover; opacity: .55; }
.scan-line {
  position: absolute; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, #7E9BFF, transparent);
  box-shadow: 0 0 18px 4px rgba(110,139,255,.65);
  animation: scanmove 1.8s ease-in-out infinite;
}
@keyframes scanmove {
  0% { top: 6%; opacity: .2; }
  50% { top: 92%; opacity: 1; }
  100% { top: 6%; opacity: .2; }
}
.scan-corner { position: absolute; width: 18px; height: 18px; border: 2.5px solid #8AA2FF; }
.scan-corner.tl { left: 10px; top: 10px; border-right: 0; border-bottom: 0; border-radius: 6px 0 0 0; }
.scan-corner.tr { right: 10px; top: 10px; border-left: 0; border-bottom: 0; border-radius: 0 6px 0 0; }
.scan-corner.bl { left: 10px; bottom: 10px; border-right: 0; border-top: 0; border-radius: 0 0 0 6px; }
.scan-corner.br { right: 10px; bottom: 10px; border-left: 0; border-top: 0; border-radius: 0 0 6px 0; }
.scanning .st { font-size: 15px; font-weight: 550; letter-spacing: .3px; }
.scanning .sd { font-size: 12.5px; opacity: .6; margin-top: -14px; }
.dots::after { content: ""; animation: dots 1.4s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: rgba(24,27,38,.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all .25s;
  z-index: 100;
  max-width: 84vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 分类管理 */
.cat-manage-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.cat-manage-row .name { flex: 1; font-size: 14.5px; }
.cat-manage-row .act { color: var(--muted); font-size: 13px; padding: 4px 8px; }
.cat-manage-row .act.danger { color: var(--red); }

/* 空状态按钮 */
.pill-row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.pill {
  padding: 8px 14px; border-radius: 999px;
  background: #fff; box-shadow: var(--shadow-sm);
  font-size: 12.5px; color: var(--ink2);
}
.pill.on { background: var(--primary); color: #fff; }

.tag {
  display: inline-block; padding: 2px 7px; border-radius: 6px;
  background: var(--green-soft); color: var(--green);
  font-size: 11px; font-weight: 600;
}
.tag.blue { background: var(--primary-soft); color: var(--primary); }
.tag.gray { background: #F1F3F8; color: #8B93A7; }
.tag.red { background: #FEECEC; color: #F04438; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* AI 用量 */
.usage-val { font-size: 12.5px; color: #5B6274; font-variant-numeric: tabular-nums; }
.live-dot {
  display: inline-block; width: 6px; height: 6px; margin-left: 6px; vertical-align: 1px;
  border-radius: 50%; background: #12B76A; box-shadow: 0 0 0 3px rgba(18,183,106,.14);
  animation: livepulse 2s ease-in-out infinite;
}
@keyframes livepulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none } }
