/* ============================================================
   我的账本 · 清新薄荷设计系统
   纸感底色 + 薄荷绿点缀 + 衬线数字，安静清爽的手账气质
   ============================================================ */

:root {
  --accent: #10b981;
  --accent-strong: #0d9d70;
  --accent-soft: #e3f6ee;
  --accent-fade: #d5efe4;
  --ink: #26332c;
  --ink-2: #5b6b62;
  --ink-3: #93a49b;
  --paper: #f6f8f4;
  --card: #ffffff;
  --line: #e4ebe5;
  --danger: #d96a4f;
  --danger-soft: #fbeae4;
  --warn: #d9a44f;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(38, 51, 44, .05), 0 6px 24px -12px rgba(38, 51, 44, .12);
  --shadow-lg: 0 12px 40px -12px rgba(38, 51, 44, .25);
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-display: Georgia, "Times New Roman", "STZhongsong", serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* 纸感颗粒 + 顶部薄荷晕染 */
.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 340px at 18% -6%, rgba(16, 185, 129, .10), transparent 64%),
    radial-gradient(700px 300px at 92% -4%, rgba(14, 165, 233, .05), transparent 60%),
    var(--paper);
}
.page-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .04 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--accent-fade); }

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
  background: rgba(246, 248, 244, .82);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 28px;
}
.brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--ink);
  letter-spacing: .5px;
}
.brand:hover { text-decoration: none; }
.main-nav { display: flex; gap: 4px; flex: 1; }
.main-nav a {
  color: var(--ink-2);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14.5px;
  transition: all .18s;
}
.main-nav a:hover { color: var(--ink); text-decoration: none; background: var(--accent-soft); }
.main-nav a.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-weight: 600;
}
.topbar-user { display: flex; align-items: center; gap: 12px; }
.username { color: var(--ink-3); font-size: 13.5px; }

/* ---------- 主容器 ---------- */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 96px;
}
.container > * { animation: rise .45s ease both; }
.container > *:nth-child(2) { animation-delay: .05s; }
.container > *:nth-child(3) { animation-delay: .1s; }
.container > *:nth-child(4) { animation-delay: .15s; }
.container > *:nth-child(5) { animation-delay: .2s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.card-title { font-weight: 700; font-size: 15.5px; }
.card-side { color: var(--ink-3); font-size: 13px; }
.card-side.link { color: var(--accent-strong); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.two-col .card { margin-bottom: 0; }
.two-col + .two-col { margin-top: 18px; }

/* ---------- 统计卡片 ---------- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
  opacity: .55;
  border-radius: 4px 0 0 4px;
}
.stat-label { color: var(--ink-3); font-size: 13px; }
.stat-num {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .5px;
  margin-top: 2px;
}
.stat-income { color: var(--accent-strong); }
.stat-balance { color: #2b7fbf; }
.stat-negative { color: var(--danger); }

/* ---------- 预算进度条 ---------- */
.progress {
  height: 12px;
  background: var(--accent-soft);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #6ee7b7, var(--accent));
  border-radius: 999px;
  transition: width .6s ease;
}
.progress-warn { background: linear-gradient(90deg, #f3d29b, var(--warn)); }
.progress-over { background: linear-gradient(90deg, #eda48c, var(--danger)); }
.budget-note { color: var(--ink-3); font-size: 13px; margin-top: 8px; }
.text-danger { color: var(--danger); }

/* ---------- 图表 ---------- */
.trend-svg { width: 100%; height: auto; display: block; }
.chart-legend { display: inline-flex; align-items: center; gap: 6px; }
.dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 4px;
}
.dot-income { background: var(--accent); opacity: .45; }
.dot-expense { background: var(--accent); }

.donut-wrap {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}
.donut-svg { width: 140px; height: 140px; flex-shrink: 0; }
.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 160px; }
.donut-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-size: 13.5px;
  color: var(--ink-2);
}
.donut-legend em {
  margin-left: auto;
  font-style: normal;
  color: var(--ink-3);
  font-family: var(--font-display);
}

/* ---------- 统计页 ---------- */
.cmp-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
.cmp-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  position: relative;
  overflow: hidden;
}
.cmp-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: 4px 0 0 4px;
}
.cmp-card:first-child::before { background: var(--danger); opacity: .55; }
.cmp-card:last-child::before { background: var(--accent); opacity: .55; }
.cmp-label { color: var(--ink-3); font-size: 13px; }
.cmp-num {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .5px;
  margin-top: 2px;
}
.cmp-deltas { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.delta {
  font-size: 12.5px;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.delta.good { color: var(--accent-strong); background: var(--accent-soft); }
.delta.bad { color: var(--danger); background: var(--danger-soft); }
.delta.flat { color: var(--ink-3); background: var(--paper); }

.month-labels {
  display: flex;
  margin-top: 6px;
}
.month-labels span {
  flex: 1;
  text-align: center;
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
}
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
}
.rank-item:last-child { border-bottom: none; }
.rank-icon {
  width: 32px; height: 32px;
  background: var(--accent-soft);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.rank-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.rank-name { font-size: 13.5px; color: var(--ink-2); }
.rank-bar { height: 5px; background: var(--accent-soft); border-radius: 999px; overflow: hidden; }
.rank-bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.rank-val {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}
.rank-val em { font-style: normal; color: var(--ink-3); font-size: 12px; margin-left: 6px; }

.pm-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.pm-cell {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pm-icon { font-size: 20px; }
.pm-name { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.pm-line { font-size: 12.5px; color: var(--ink-3); display: flex; justify-content: space-between; }
.pm-line b { font-family: var(--font-display); font-weight: 700; }
.pos { color: var(--accent-strong); }
.neg { color: var(--danger); }

.year-picker { margin: 0; }
.year-picker .input { width: auto; padding: 5px 10px; font-size: 13.5px; }
.table-scroll { overflow-x: auto; }
.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.report-table th, .report-table td {
  padding: 9px 12px;
  text-align: right;
  border-bottom: 1px solid var(--line);
}
.report-table th:first-child, .report-table td:first-child { text-align: left; }
.report-table thead th {
  color: var(--ink-3);
  font-weight: 600;
  font-size: 13px;
}
.report-table tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--line);
  border-bottom: none;
}
.report-actions { margin-top: 14px; }

/* ---------- 账目列表 ---------- */
.txn-list { list-style: none; margin: 0; padding: 0; }
.txn-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px dashed var(--line);
}
.txn-item:last-child { border-bottom: none; }
.txn-icon {
  width: 38px; height: 38px;
  background: var(--accent-soft);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.txn-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.txn-name {
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.txn-meta { color: var(--ink-3); font-size: 12.5px; }
.txn-amount {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}
.txn-amount.is-income { color: var(--accent-strong); }
.txn-ops { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.txn-ops form { margin: 0; }

.empty { color: var(--ink-3); text-align: center; padding: 26px 0; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 14.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all .18s;
  text-decoration: none;
  line-height: 1.5;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px -4px rgba(16, 185, 129, .5);
}
.btn-primary:hover { background: var(--accent-strong); transform: translateY(-1px); }
.btn-ghost {
  background: var(--card);
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-strong); }
.btn-block { width: 100%; margin-top: 6px; }
.btn-link {
  background: none;
  border: none;
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  padding: 2px 4px;
}
.btn-link:hover { text-decoration: underline; }
.btn-danger { color: var(--danger); }

/* ---------- 表单 ---------- */
.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  padding: 9px 12px;
  font-size: 14.5px;
  font-family: inherit;
  color: var(--ink);
  transition: border-color .18s, box-shadow .18s;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-label {
  display: block;
  color: var(--ink-2);
  font-size: 13px;
  margin: 10px 0 5px;
}
.field-row { display: flex; gap: 12px; }
.field-row .grow { flex: 1; }
.field-row .field-label { margin-top: 0; }
.field-group { margin-bottom: 6px; }

/* 表单内就地错误提示 */
.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f2d4c9;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 12px;
  animation: rise .25s ease both;
}
.form-error[hidden] { display: none; }

/* 收/支切换 */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 8px;
}
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item span {
  display: block;
  text-align: center;
  padding: 8px 0;
  border-radius: 9px;
  color: var(--ink-3);
  cursor: pointer;
  font-weight: 600;
  transition: all .18s;
}
.seg-item input:checked + span {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 10px -3px rgba(16, 185, 129, .55);
}
.seg-item input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 金额大输入框 */
.amount-field {
  display: flex;
  align-items: baseline;
  gap: 6px;
  border-bottom: 2px solid var(--line);
  padding: 2px 6px 8px;
  margin: 4px 0 12px;
  transition: border-color .18s;
}
.amount-field:focus-within { border-color: var(--accent); }
.amount-field .yen {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--ink-3);
}
.amount-field input {
  border: none;
  outline: none;
  background: none;
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  width: 100%;
  color: var(--ink);
  letter-spacing: .5px;
}
.amount-field input::placeholder { color: var(--line); }

/* 分类/支付方式 chip */
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block;
  padding: 7px 13px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13.5px;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .15s;
}
.chip span:hover { border-color: var(--accent); }
.chip input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 600;
}
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-disabled span { opacity: .45; cursor: not-allowed; }

/* ---------- 筛选区 ---------- */
.filter-card { padding-bottom: 14px; }
.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0 14px;
}
.filter-grid .field-label { margin-top: 8px; }
.filter-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  align-items: center;
}

/* ---------- 分页 ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
}
.pager-info { color: var(--ink-3); font-size: 13.5px; }

/* ---------- 设置页 ---------- */
.setting-list { list-style: none; margin: 0 0 10px; padding: 0; }
.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 2px;
  border-bottom: 1px dashed var(--line);
  font-size: 14.5px;
}
.setting-item:last-child { border-bottom: none; }
.setting-item.is-archived { color: var(--ink-3); }
.setting-item .txn-ops form { margin: 0; }
.inline-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.inline-form .input { flex: 1; width: auto; min-width: 0; }
.inline-form .input-icon { flex: 0 0 72px; text-align: center; }
/* grid/flex 子项允许收缩到固有宽度以下，防止窄屏横向溢出 */
.two-col > *, .filter-grid > *, .stat-cards > * { min-width: 0; }
.stack-form .btn { margin-top: 12px; }
.hint { color: var(--ink-3); font-size: 12.5px; margin: 8px 0 0; }

/* ---------- 编辑表单卡片 ---------- */
.form-card { max-width: 560px; margin: 0 auto; }

/* ---------- 记一笔 FAB 与弹窗 ---------- */
.fab {
  position: fixed;
  right: 26px;
  bottom: 30px;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 28px -6px rgba(16, 185, 129, .6);
  transition: transform .18s, background .18s;
  z-index: 60;
}
.fab:hover { transform: scale(1.08) rotate(90deg); background: var(--accent-strong); }

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(38, 51, 44, .38);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal-mask[hidden] { display: none; }
.modal {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 460px;
  padding: 18px 22px 22px;
  animation: pop .25s ease;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 6px;
}
.modal-close {
  border: none;
  background: var(--paper);
  color: var(--ink-3);
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}
.modal-close:hover { color: var(--ink); }

/* ---------- 提示消息 ---------- */
.flash-stack { margin-bottom: 16px; }
.flash {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 8px;
  animation: rise .3s ease both;
}
.flash-success { background: var(--accent-soft); color: var(--accent-strong); border: 1px solid var(--accent-fade); }
.flash-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #f2d4c9; }

/* ---------- 登录/初始化页 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 44px 40px 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  animation: rise .5s ease both;
}
.auth-logo { font-size: 44px; }
.auth-title { font-size: 22px; margin: 10px 0 4px; letter-spacing: 1px; }
.auth-sub { color: var(--ink-3); font-size: 13.5px; margin: 0 0 18px; }
.auth-form { text-align: left; }
.auth-form .field-label { margin-top: 14px; }
.auth-form .btn { margin-top: 22px; }

/* ---------- 移动端底部导航 ---------- */
.mobile-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, .98);
  border-top: 1px solid var(--line);
  z-index: 80;
  padding: 4px 8px calc(6px + env(safe-area-inset-bottom));
  grid-template-columns: 1fr 1fr 64px 1fr 1fr;
}
.mobile-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--ink-3);
  font-size: 11.5px;
  padding: 4px 0;
  border-radius: 10px;
}
.mobile-nav a.active { color: var(--accent-strong); font-weight: 600; }
.mobile-nav a:hover { text-decoration: none; }
.m-icon { font-size: 20px; line-height: 1.3; }
.m-add {
  width: 52px; height: 52px;
  margin-top: -18px;
  border-radius: 50%;
  border: 4px solid var(--paper);
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 8px 20px -6px rgba(16, 185, 129, .6);
  justify-self: center;
}

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  .main-nav { display: none; }
  .topbar-inner { justify-content: space-between; height: 54px; }
  .container { padding: 16px 14px 110px; }
  .mobile-nav { display: grid; }
  .fab { display: none; }
  .stat-cards { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat-card { padding: 12px 12px; }
  .stat-num { font-size: 19px; }
  .two-col { grid-template-columns: 1fr; }
  .two-col .card { margin-bottom: 0; }
  .filter-grid { grid-template-columns: repeat(2, 1fr); }
  .pm-grid { grid-template-columns: repeat(2, 1fr); }
  .txn-ops { flex-direction: column; gap: 2px; align-items: flex-end; }
  .modal-mask { padding: 4vh 12px 12px; }
}
