/* R77 可视化家庭收支系统 H5 · 清新账本绿 */
:root {
  --color-primary: #2EAD6F;
  --color-primary-light: #6BCF9A;
  --color-primary-dark: #1F8A55;
  --color-accent: #FFB347;
  --color-bg: #F7FAF8;
  --color-surface: #FFFFFF;
  --color-text: #1A2E24;
  --color-text-light: #5A7268;
  --color-border: #D4E8DC;
  --color-expense: #E85D4A;
  --color-income: #2EAD6F;
  --radius: 14px;
  --shadow: 0 2px 14px rgba(26, 46, 36, 0.08);
  --font: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --contact-h: 68px;
  --fab-size: 56px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  padding-bottom: calc(var(--contact-h) + var(--fab-size) + 24px + var(--safe-bottom));
}
body.sheet-open { overflow: hidden; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }

.top-bar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
}
.top-bar__brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.top-bar__logo { border-radius: 10px; object-fit: cover; }
.top-bar__actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(46, 173, 111, 0.08); font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}

.theme-panel {
  position: sticky; top: 56px; z-index: 49;
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 16px; background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.theme-chip {
  padding: 6px 12px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--color-border); background: var(--color-surface);
}

.hero {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 55%, var(--color-primary-light) 100%);
  color: #fff;
  padding: 28px 20px 24px;
}
.hero__eyebrow { margin: 0 0 8px; font-size: 13px; opacity: .92; }
.hero h1 { margin: 0 0 8px; font-size: 22px; line-height: 1.3; }
.hero__subtitle { margin: 0; font-size: 14px; opacity: .9; }

.dashboard { padding: 16px; margin-top: -12px; }
.month-bar {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin-bottom: 12px; position: relative;
}
.month-bar__btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--color-surface); box-shadow: var(--shadow);
  font-size: 22px; line-height: 1; color: var(--color-text);
}
.month-bar__picker { position: relative; flex: 0 1 auto; }
.month-bar__label {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  margin: 0; padding: 8px 14px; min-width: 132px;
  font-size: 18px; font-weight: 600; text-align: center;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 999px; box-shadow: var(--shadow); color: var(--color-text);
  cursor: pointer;
}
.month-bar__label.is-open {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(46, 173, 111, 0.15);
}
.month-bar__caret { font-size: 12px; color: var(--color-text-light); transition: transform .2s; }
.month-bar__label.is-open .month-bar__caret { transform: rotate(180deg); }

.month-picker {
  position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  z-index: 60; width: min(280px, 86vw);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.12);
  padding: 12px;
}
.month-picker__year {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--color-border);
}
.month-picker__year strong { font-size: 17px; }
.month-picker__nav {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--color-bg); font-size: 18px; line-height: 1;
}
.month-picker__grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.month-picker__item {
  padding: 10px 0; border-radius: 10px; font-size: 14px; font-weight: 600;
  background: var(--color-bg); border: 1px solid transparent;
}
.month-picker__item.is-active {
  background: var(--color-primary); color: #fff; border-color: var(--color-primary);
}
.month-picker__item:active { transform: scale(0.96); }

.summary-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.summary-card__balance { text-align: center; margin-bottom: 14px; }
.summary-card__balance span { display: block; font-size: 13px; color: var(--color-text-light); margin-bottom: 4px; }
.summary-card__balance strong {
  font-size: 32px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.summary-card__balance strong.is-negative { color: var(--color-expense); }
.summary-card__row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary-stat {
  padding: 12px; border-radius: 12px; text-align: center;
  background: rgba(46, 173, 111, 0.06);
}
.summary-stat--expense { background: rgba(232, 93, 74, 0.08); }
.summary-stat em { display: block; font-style: normal; font-size: 12px; color: var(--color-text-light); }
.summary-stat strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.summary-stat--income strong { color: var(--color-income); }
.summary-stat--expense strong { color: var(--color-expense); }
.summary-card__top {
  margin: 12px 0 0; padding-top: 12px; border-top: 1px dashed var(--color-border);
  font-size: 13px; color: var(--color-text-light); text-align: center;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 18px; border-radius: 999px; font-size: 15px; font-weight: 600;
}
.btn--primary { background: var(--color-primary); color: #fff; }
.btn--full { width: 100%; }
.btn--lg { padding: 14px 20px; font-size: 16px; }

.section-block { padding: 8px 16px 20px; }
.section-title { margin: 0; font-size: 17px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.section-meta { font-size: 13px; color: var(--color-text-light); }

.member-filter {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.member-filter::-webkit-scrollbar { display: none; }
.member-chip {
  flex-shrink: 0; padding: 8px 14px; border-radius: 999px;
  font-size: 14px; border: 1px solid var(--color-border);
  background: var(--color-surface);
}
.member-chip.is-active {
  background: var(--color-primary); color: #fff; border-color: var(--color-primary);
}

.chart-tabs { display: flex; gap: 6px; }
.chart-tab {
  padding: 6px 10px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--color-border); background: var(--color-surface);
}
.chart-tab.is-active {
  background: var(--color-primary); color: #fff; border-color: var(--color-primary);
}
.chart-wrap {
  background: var(--color-surface); border-radius: var(--radius);
  padding: 8px; box-shadow: var(--shadow);
}
#chart-canvas { width: 100%; height: 220px; display: block; }

.tx-list { display: flex; flex-direction: column; gap: 16px; }
.tx-empty { text-align: center; color: var(--color-text-light); padding: 24px 12px; font-size: 14px; }
.tx-group__date {
  margin: 0 0 8px; font-size: 14px; color: var(--color-text-light);
  display: flex; align-items: baseline; gap: 8px;
}
.tx-group__date span { font-size: 12px; opacity: .75; }
.tx-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; background: var(--color-surface);
  border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 8px;
}
.tx-item__icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.tx-item__body { flex: 1; min-width: 0; }
.tx-item__body strong { display: block; font-size: 15px; margin-bottom: 2px; }
.tx-item__body span { font-size: 12px; color: var(--color-text-light); }
.tx-item__amount {
  font-style: normal; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.tx-item--income .tx-item__amount { color: var(--color-income); }
.tx-item--expense .tx-item__amount { color: var(--color-expense); }

.category-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.category-col {
  background: var(--color-surface); border-radius: var(--radius);
  padding: 14px 12px; box-shadow: var(--shadow);
}
.category-col h3 { margin: 0 0 10px; font-size: 14px; color: var(--color-text-light); }
.category-list { list-style: none; margin: 0; padding: 0; }
.category-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; font-size: 13px;
}
.category-list li span {
  width: 28px; height: 28px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 14px;
}

.site-footer {
  text-align: center; padding: 24px 16px 8px; color: var(--color-text-light); font-size: 13px;
}
.site-footer img { margin: 0 auto 10px; border-radius: 8px; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--contact-h) + 12px + var(--safe-bottom));
  width: var(--fab-size); height: var(--fab-size); border-radius: 50%;
  background: var(--color-primary); color: #fff;
  font-size: 28px; line-height: 1; box-shadow: 0 4px 16px rgba(46, 173, 111, 0.45);
  z-index: 70;
}

.add-sheet { position: fixed; inset: 0; z-index: 100; }
.add-sheet__backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.45);
  opacity: 0; transition: opacity .25s ease;
}
.add-sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88vh; overflow: auto;
  background: var(--color-surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  transform: translateY(100%); transition: transform .28s ease;
}
.add-sheet.is-open .add-sheet__backdrop { opacity: 1; }
.add-sheet.is-open .add-sheet__panel { transform: translateY(0); }
.add-sheet__close {
  position: absolute; top: 12px; right: 12px;
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,.06); font-size: 22px;
}
.add-sheet__body h3 { margin: 0 0 16px; font-size: 18px; }

.type-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px;
}
.type-toggle__btn {
  padding: 10px; border-radius: 10px; font-weight: 600;
  border: 1px solid var(--color-border); background: var(--color-bg);
}
.type-toggle__btn.is-active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.add-form label {
  display: block; margin-bottom: 12px; font-size: 13px; color: var(--color-text-light);
}
.add-form input, .add-form select {
  display: block; width: 100%; margin-top: 6px; padding: 12px;
  border: 1px solid var(--color-border); border-radius: 10px;
  font-size: 15px; background: var(--color-bg); color: var(--color-text);
}

.contact-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  padding: 6px 12px calc(6px + var(--safe-bottom));
  background: rgba(255,255,255,.96); border-top: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
  backdrop-filter: blur(8px);
}
.contact-footer__btns {
  display: flex; gap: 6px; justify-content: center; align-items: center;
}
.contact-footer__cta, .contact-footer__btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  text-decoration: none; white-space: nowrap;
}
.contact-footer__cta { background: var(--color-primary); color: #fff; }
.contact-footer__btn {
  background: #fff; color: var(--color-text); border: 1px solid rgba(0,0,0,.1);
}
.contact-footer__brand { margin: 4px 0 0; text-align: center; font-size: 10px; color: #999; }

.app-toast {
  position: fixed; left: 50%; bottom: calc(var(--contact-h) + 80px);
  transform: translateX(-50%) translateY(12px);
  padding: 10px 18px; border-radius: 999px;
  background: rgba(26, 46, 36, .88); color: #fff; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200;
}
.app-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }

body[data-theme="nightLedger"] .contact-footer,
body[data-theme="nightLedger"] .top-bar,
body[data-theme="nightLedger"] .add-sheet__panel {
  background: var(--color-surface);
}
body[data-theme="nightLedger"] .contact-footer__btn { background: var(--color-bg); }

@media (min-width: 768px) {
  #app { max-width: 480px; margin: 0 auto; }
  .add-sheet__panel {
    left: 50%; right: auto; width: min(480px, 92vw);
    transform: translate(-50%, 100%);
  }
  .add-sheet.is-open .add-sheet__panel { transform: translate(-50%, 0); }
}

/* ── P1 模块 ── */
.member-cards {
  display: flex; gap: 12px; overflow-x: auto; padding: 4px 0 8px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.member-cards::-webkit-scrollbar { display: none; }
.member-card {
  flex-shrink: 0; width: 108px; padding: 12px 10px;
  background: var(--color-surface); border-radius: var(--radius);
  box-shadow: var(--shadow); text-align: center; cursor: pointer;
  border: 2px solid transparent;
}
.member-card:hover { border-color: var(--color-primary-light); }
.member-card__avatar {
  position: relative; width: 48px; height: 48px; margin: 0 auto 8px;
  border-radius: 50%; background: rgba(46,173,111,.12);
  display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.member-card__role {
  position: absolute; right: -6px; bottom: -4px; font-size: 9px;
  background: var(--color-surface); border-radius: 999px; padding: 1px 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
.member-card strong { display: block; font-size: 13px; margin-bottom: 4px; }
.member-card p { margin: 0; font-size: 11px; color: var(--color-text-light); line-height: 1.35; }
.member-card--add {
  border: 2px dashed var(--color-border); background: transparent; box-shadow: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.member-card--add span { font-size: 28px; color: var(--color-primary); }

.notify-panel { margin-top: 12px; }
.notify-title { margin: 0 0 8px; font-size: 14px; }
.notify-empty { margin: 0; font-size: 13px; color: var(--color-text-light); }
.notify-list { margin: 0; padding: 0 0 0 18px; font-size: 13px; color: var(--color-text-light); }
.notify-list li { margin-bottom: 6px; }

.export-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 400px) { .export-grid { grid-template-columns: repeat(3, 1fr); } }
.export-btn {
  padding: 12px 10px; border-radius: 12px; font-size: 13px; font-weight: 600;
  background: var(--color-surface); border: 1px solid var(--color-border);
  box-shadow: var(--shadow); text-align: center;
}

.story-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary));
  color: #fff; text-decoration: none;
}
.story-banner strong { display: block; font-size: 16px; margin-bottom: 4px; }
.story-banner span { font-size: 12px; opacity: .9; }
.story-banner em { font-style: normal; font-size: 14px; flex-shrink: 0; }

.theme-follow {
  display: flex; align-items: center; gap: 8px; width: 100%;
  margin-bottom: 10px; font-size: 13px; cursor: pointer;
}
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; width: 100%; }
.theme-card {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 10px; border: 1px solid var(--color-border);
  background: var(--color-surface); font-size: 12px; text-align: left;
}
.theme-card.is-active { border-color: var(--color-primary); box-shadow: 0 0 0 2px rgba(46,173,111,.2); }
.theme-card__swatch { width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; }

/* 数据故事页 */
body.story-page {
  padding-bottom: 0; background: var(--color-bg); overflow: hidden;
}
.story-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: rgba(255,255,255,.9);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--color-border);
}
.story-top__back { text-decoration: none; color: var(--color-primary); font-size: 14px; }
.story-scroll {
  height: 100vh; overflow-y: auto; scroll-snap-type: y mandatory;
  scroll-behavior: smooth; padding-top: 52px;
}
.story-slide {
  min-height: calc(100vh - 52px); scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 24px; text-align: center;
  opacity: 0; transform: translateY(24px); transition: opacity .5s, transform .5s;
}
.story-slide.is-visible { opacity: 1; transform: translateY(0); }
.story-slide--1 { background: linear-gradient(160deg, var(--color-primary-dark), var(--color-primary)); color: #fff; }
.story-slide--2 { background: var(--color-surface); }
.story-slide--3 { background: linear-gradient(160deg, #FFB347, var(--color-accent)); color: #422006; }
.story-slide--4 { background: var(--color-bg); }
.story-slide--5 { background: linear-gradient(160deg, var(--color-primary-light), var(--color-bg)); }
.story-slide--6 { background: var(--color-surface); gap: 12px; }
.story-eyebrow { font-size: 14px; opacity: .85; margin: 0 0 12px; }
.story-slide h1 { margin: 0 0 12px; font-size: 28px; line-height: 1.3; }
.story-slide h2 { margin: 8px 0; font-size: 36px; font-variant-numeric: tabular-nums; }
.story-slide p { margin: 8px 0; font-size: 15px; }
.story-sub { opacity: .85; }
.story-slide .is-negative { color: var(--color-expense); }
.story-back {
  margin-top: 8px; padding: 12px; border-radius: 999px;
  border: 1px solid var(--color-border); text-decoration: none; color: var(--color-text);
}
.story-slide img { border-radius: 8px; margin: 8px 0; }

/* ── P2 模块 ── */
.budget-overview { margin-top: 14px; }
.budget-overview__title { margin: 0 0 10px; font-size: 14px; color: var(--color-text-light); }
.budget-overview__scroll {
  display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.budget-overview__scroll::-webkit-scrollbar { display: none; }
.budget-mini {
  flex-shrink: 0; width: 140px; padding: 10px;
  background: var(--color-surface); border-radius: 12px; box-shadow: var(--shadow);
}
.budget-mini span { display: block; font-size: 13px; margin-bottom: 8px; }
.budget-mini em { font-style: normal; font-size: 11px; color: var(--color-text-light); }

.budget-bar { height: 6px; background: rgba(0,0,0,.06); border-radius: 999px; overflow: hidden; margin: 6px 0; }
.budget-bar--lg { height: 10px; }
.budget-bar__fill { height: 100%; border-radius: 999px; transition: width .4s ease; }

.budget-card {
  background: var(--color-surface); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
  border-left: 4px solid var(--color-primary);
}
.budget-card__head { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 15px; }
.budget-card p { margin: 8px 0; font-size: 12px; color: var(--color-text-light); }
.budget-card__actions { display: flex; gap: 8px; margin-top: 8px; }
.budget-edit-btn, .budget-del-btn {
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--color-border); background: var(--color-bg);
}
.budget-warn { border-left-color: #FF9800; }
.budget-overrun {
  border-left-color: #D32F2F;
  animation: budgetPulse 1.5s ease-in-out infinite;
}
@keyframes budgetPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(244, 67, 54, 0); }
}

.goal-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--color-surface); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.goal-card--done { border: 2px solid var(--color-accent); }
.goal-card__icon { font-size: 32px; line-height: 1; }
.goal-card__body { flex: 1; min-width: 0; }
.goal-card__body strong { display: block; margin-bottom: 4px; }
.goal-card__body p { margin: 0 0 8px; font-size: 13px; color: var(--color-text-light); }
.jar-svg { width: 72px; height: 120px; display: block; margin: 0 auto 8px; }
.goal-card__actions { display: flex; align-items: center; gap: 10px; }
.goal-deposit-btn {
  padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--color-primary); color: #fff;
}
.goal-done-tag { font-size: 13px; color: var(--color-accent); }

.tx-search {
  width: 100%; padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--color-border); border-radius: 12px;
  font-size: 15px; background: var(--color-surface);
}

.adv-card {
  background: var(--color-surface); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.adv-card h3 { margin: 0 0 8px; font-size: 15px; }
.adv-big { margin: 0; font-size: 28px; font-weight: 700; color: var(--color-primary); }
.adv-meta { margin: 4px 0 0; font-size: 13px; color: var(--color-text-light); }
.adv-card--settings label { display: block; margin-bottom: 10px; font-size: 13px; }
.reminder-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.adv-card--settings input[type="time"] {
  width: 100%; margin-top: 6px; padding: 10px; border-radius: 10px;
  border: 1px solid var(--color-border); background: var(--color-bg);
}

.confetti-burst {
  position: fixed; inset: 0; z-index: 300; pointer-events: none;
  background: radial-gradient(circle, rgba(255,215,0,.35) 0%, transparent 70%);
  animation: confettiFade 2s ease forwards;
}
@keyframes confettiFade {
  from { opacity: 1; } to { opacity: 0; }
}
