/* ===========================================================
   家庭记账 · 卡通可爱风格样式
   主色 #FF6B5A（暖橙），圆角卡片，柔和阴影
   =========================================================== */

:root {
  --primary: #ff6b5a;
  --primary-2: #ffa26b;
  --primary-soft: #fff1ed;
  --green: #35c58b;
  --green-soft: #e8faf2;
  --blue: #5b8def;
  --purple: #9b7bff;
  --yellow: #ffc94d;
  --bg: #fff6f2;
  --bg-2: #ffece5;
  --card: #ffffff;
  --text: #2f2a29;
  --text-2: #8b8280;
  --line: #f2e8e4;
  --shadow: 0 6px 20px rgba(255, 107, 90, 0.10);
  --shadow-lg: 0 12px 32px rgba(255, 107, 90, 0.18);
  --radius: 20px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

[data-theme='dark'] {
  --primary: #ff8272;
  --primary-2: #ffb07c;
  --primary-soft: #3a2a27;
  --green: #46d69a;
  --green-soft: #1f3a30;
  --blue: #7aa5ff;
  --purple: #ab90ff;
  --yellow: #ffd166;
  --bg: #17151a;
  --bg-2: #1f1c22;
  --card: #221f26;
  --text: #f3eeec;
  --text-2: #9d9591;
  --line: #322d33;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-2);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { overscroll-behavior-y: none; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 15px; color: inherit; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px);
  overflow-x: hidden;
}

/* ---------------- 顶部栏 ---------------- */
.topbar {
  position: relative;
  padding: 16px 18px 70px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  border-bottom-left-radius: 28px;
  border-bottom-right-radius: 28px;
  color: #fff;
}
.topbar.slim { padding-bottom: 18px; border-radius: 0 0 22px 22px; }
.topbar-row { display: flex; align-items: center; gap: 10px; }
.topbar .hello { font-size: 13px; opacity: 0.9; }
.topbar .who { font-size: 18px; font-weight: 700; }
.topbar .spacer { flex: 1; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; border: 2px solid rgba(255, 255, 255, 0.6);
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.2); font-size: 17px;
}

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 12px 14px;
}
.card.tight { padding: 12px 14px; }
.card-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 15px; font-weight: 700; margin: 0 0 12px;
}
.card-title .sub { font-size: 12px; color: var(--text-2); font-weight: 400; margin-left: auto; }
.card-link { font-size: 12px; color: var(--primary); margin-left: auto; font-weight: 600; }

/* 首页大卡（叠在顶部栏上） */
.hero {
  margin: -58px 14px 12px;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.hero .label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; margin: 2px 0 0; }
.hero .big small { font-size: 17px; font-weight: 600; margin-right: 2px; }
.hero .meta { display: flex; gap: 18px; margin-top: 12px; }
.hero .meta .m { font-size: 12px; color: var(--text-2); }
.hero .meta .m b { display: block; font-size: 16px; color: var(--text); margin-top: 2px; }
.hero .meta .m.income b { color: var(--green); }
.hero .meta .m.expense b { color: var(--primary); }
.hero-cat { position: absolute; right: 12px; bottom: 8px; width: 92px; opacity: 0.98; }

/* 快捷操作 */
.quick { display: flex; gap: 10px; margin: 12px 14px; }
.quick button {
  flex: 1; background: var(--card); border-radius: 18px; padding: 12px 6px;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  align-items: center; gap: 6px; font-size: 12px; color: var(--text-2);
  transition: transform 0.15s;
}
.quick button:active { transform: scale(0.95); }
.quick .qi {
  width: 38px; height: 38px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; font-size: 19px;
  background: var(--primary-soft);
}

/* ---------------- 列表 ---------------- */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row .ric {
  width: 40px; height: 40px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; background: var(--primary-soft); flex: none;
}
.row .rmain { flex: 1; min-width: 0; }
.row .rmain .t1 {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row .rmain .t2 { font-size: 11.5px; color: var(--text-2); margin-top: 2px; }
.row .ramt { font-size: 15px; font-weight: 700; white-space: nowrap; }
.amt-expense { color: var(--text); }
.amt-income { color: var(--green); }
.amt-transfer { color: var(--blue); }

.empty {
  text-align: center; color: var(--text-2); font-size: 13px;
  padding: 26px 10px;
}
.empty .e-emoji { font-size: 34px; display: block; margin-bottom: 6px; opacity: 0.7; }
.loading { text-align: center; color: var(--text-2); font-size: 13px; padding: 22px; }

/* ---------------- 进度条 ---------------- */
.bar { height: 9px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width 0.5s; }
.bar.ok > i { background: linear-gradient(90deg, var(--green), #7ee0b3); }
.bar.warn > i { background: linear-gradient(90deg, var(--yellow), var(--primary-2)); }
.bar.over > i { background: linear-gradient(90deg, #ff5252, #ff8080); }

.budget-item { margin-bottom: 14px; }
.budget-item:last-child { margin-bottom: 2px; }
.budget-head { display: flex; align-items: baseline; gap: 8px; font-size: 13.5px; margin-bottom: 7px; }
.budget-head .bn { font-weight: 600; }
.budget-head .bv { margin-left: auto; font-size: 12px; color: var(--text-2); }
.budget-head .bv b { color: var(--text); font-size: 13.5px; }
.budget-head .level { font-size: 11px; padding: 1px 7px; border-radius: 8px; }
.level.alert { background: #fff6e0; color: #c98a00; }
.level.over { background: #ffecec; color: #e33; }
[data-theme='dark'] .level.alert { background: #40361d; }
[data-theme='dark'] .level.over { background: #402222; }

/* ---------------- 分类速览（九宫格） ---------------- */
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 6px; }
.gcat { text-align: center; font-size: 11.5px; color: var(--text-2); }
.gcat .gi {
  width: 44px; height: 44px; margin: 0 auto 5px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; background: var(--primary-soft);
}
.gcat .gv { color: var(--text); font-weight: 600; font-size: 11.5px; }

/* ---------------- 图表 ---------------- */
.chart-wrap { display: flex; align-items: center; gap: 14px; }
.chart-wrap svg { flex: none; }
.legend { flex: 1; min-width: 0; }
.legend .lg { display: flex; align-items: center; gap: 7px; font-size: 12.5px; padding: 4px 0; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend .ln { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .lv { color: var(--text-2); font-size: 12px; }

/* ---------------- 底部导航 ---------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-width: 480px; margin: 0 auto;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; align-items: center;
}
.tabbar .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; color: var(--text-2); padding-top: 6px;
}
.tabbar .tab .ti { font-size: 20px; line-height: 1; filter: grayscale(0.6) opacity(0.7); transition: 0.2s; }
.tabbar .tab.on { color: var(--primary); font-weight: 700; }
.tabbar .tab.on .ti { filter: none; transform: translateY(-1px); }
.tabbar .tab.fab-slot { position: relative; }

.fab {
  position: fixed; right: max(18px, calc(50% - 240px + 18px)); bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 58px; height: 58px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-size: 28px; font-weight: 300;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px rgba(255, 107, 90, 0.45); z-index: 45;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }

/* ---------------- 弹层 ---------------- */
.mask {
  position: fixed; inset: 0; background: rgba(24, 16, 14, 0.45);
  z-index: 60; opacity: 0; pointer-events: none; transition: opacity 0.22s;
}
.mask.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-width: 480px; margin: 0 auto;
  background: var(--card); border-radius: 24px 24px 0 0;
  padding: 8px 16px calc(18px + var(--safe-b));
  transform: translateY(102%); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
  max-height: 90vh; overflow-y: auto;
}
.sheet.on { transform: translateY(0); }
.sheet .handle { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 6px auto 12px; }
.sheet h3 { margin: 0 0 14px; font-size: 17px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---------------- 表单 ---------------- */
.field { margin-bottom: 13px; }
.field > label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 13px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--bg);
  outline: none; transition: border-color 0.18s;
}
.input:focus { border-color: var(--primary); background: var(--card); }
textarea.input { min-height: 62px; resize: vertical; }

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 10px 0; border-radius: 14px; font-size: 13.5px;
  background: var(--bg); color: var(--text-2); border: 1.5px solid transparent; font-weight: 600;
}
.seg button.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
[data-theme='dark'] .seg button.on { background: var(--primary-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 13px; border-radius: 14px; font-size: 13px;
  background: var(--bg); color: var(--text-2); border: 1.5px solid transparent;
}
.chip.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); font-weight: 600; }

.cat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px 4px; }
.cat-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 10.5px; color: var(--text-2); padding: 6px 0; border-radius: 14px;
  border: 1.5px solid transparent;
}
.cat-grid button .ci {
  width: 40px; height: 40px; border-radius: 14px; background: var(--bg);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.cat-grid button.on { color: var(--primary); font-weight: 700; }
.cat-grid button.on .ci { background: var(--primary-soft); box-shadow: 0 0 0 2px var(--primary) inset; }

.btn {
  padding: 13px 18px; border-radius: 16px; font-size: 15px; font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  box-shadow: 0 6px 16px rgba(255, 107, 90, 0.32);
}
.btn:active { transform: scale(0.98); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--bg); color: var(--text-2); box-shadow: none; font-weight: 600; }
.btn.danger { background: #ffe9e7; color: #e5432f; box-shadow: none; }
[data-theme='dark'] .btn.danger { background: #3a2220; }

.amount-input {
  display: flex; align-items: baseline; gap: 6px;
  padding: 4px 0 14px; border-bottom: 2px solid var(--line);
}
.amount-input span { font-size: 24px; font-weight: 700; color: var(--text-2); }
.amount-input input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 38px; font-weight: 800; letter-spacing: -0.5px; padding: 0;
  width: 100%;
}

/* ---------------- Toast / 弹窗 ---------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 34px); transform: translate(-50%, 12px);
  background: rgba(38, 30, 28, 0.94); color: #fff; font-size: 13.5px;
  padding: 10px 18px; border-radius: 14px; z-index: 90;
  opacity: 0; pointer-events: none; transition: 0.22s; max-width: 80vw; text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 月度切换 */
.month-switch { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; }
.month-switch button {
  width: 30px; height: 30px; border-radius: 10px; background: rgba(255, 255, 255, 0.22);
  color: #fff; font-size: 15px; display: flex; align-items: center; justify-content: center;
}
.topbar.slim .month-switch button { background: var(--bg); color: var(--text); }

/* 筛选行 */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters select, .filters input {
  border: none; background: var(--card); border-radius: 12px; padding: 8px 11px;
  font-size: 12.5px; color: var(--text-2); box-shadow: var(--shadow); outline: none; flex: none;
}
.filters input { min-width: 130px; }

.stat-strip { display: flex; margin: 0 14px; gap: 10px; }
.stat-strip .s {
  flex: 1; background: var(--card); border-radius: 18px; padding: 12px;
  box-shadow: var(--shadow);
}
.stat-strip .s .l { font-size: 11.5px; color: var(--text-2); }
.stat-strip .s .v { font-size: 17px; font-weight: 800; margin-top: 3px; }
.stat-strip .s.inc .v { color: var(--green); }
.stat-strip .s.exp .v { color: var(--primary); }

.list-group { margin: 12px 14px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-group .row { padding: 13px 16px; }
.list-group .row .ric { background: var(--primary-soft); }
.chev { color: var(--text-2); font-size: 15px; flex: none; }

.section-title { font-size: 12.5px; color: var(--text-2); margin: 18px 18px 6px; font-weight: 600; }

/* 记账日历 */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px 3px; }
.cal .cw { text-align: center; font-size: 10.5px; color: var(--text-2); }
.cal .cd {
  aspect-ratio: 1; border-radius: 11px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 11.5px;
  background: var(--bg); color: var(--text-2); position: relative;
}
.cal .cd.has { background: var(--primary-soft); color: var(--text); font-weight: 600; }
.cal .cd.today { outline: 2px solid var(--primary); }
.cal .cd .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--primary); margin-top: 2px; }
.cal .cd.empty-cell { background: transparent; }

.deleted-tip { font-size: 11.5px; color: var(--text-2); }

@media (min-width: 481px) {
  body { background: var(--bg-2); }
  .app { box-shadow: 0 0 40px rgba(0, 0, 0, 0.08); }
}

/* ---------------- 登录页 ---------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 28px 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 24px; padding: 30px 26px; box-shadow: var(--shadow-lg); }
.login-tabs { display: flex; gap: 6px; background: var(--bg); border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.login-tabs button { flex: 1; padding: 9px 4px; border-radius: 11px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.login-tabs button.on { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }
.login-msg { color: #e5432f; font-size: 13px; text-align: center; margin: 0 0 12px; line-height: 1.6; }
.login-tip { color: var(--text-2); font-size: 11.5px; margin: 10px 0 0; line-height: 1.65; }

/* 身份徽章 */
.role-badge { display: inline-block; font-size: 10.5px; padding: 1px 8px; border-radius: 8px; font-weight: 600; vertical-align: 1.5px; }
.role-badge.owner { background: #fff1e8; color: #e06a00; }
.role-badge.admin { background: #eaf1ff; color: #3a6fd8; }
.role-badge.member { background: var(--bg); color: var(--text-2); }
.role-badge.me { background: var(--primary-soft); color: var(--primary); }
[data-theme='dark'] .role-badge.owner { background: #402c1d; color: #ffab5e; }
[data-theme='dark'] .role-badge.admin { background: #1e2a44; color: #8fb3ff; }

/* ---------------- 电脑端布局（≥900px） ---------------- */
@media (min-width: 900px) {
  body { background: var(--bg-2); }
  .app { max-width: 920px; padding-top: 58px; }

  /* 底部导航改为顶部吸顶横向导航 */
  .tabbar {
    top: 0; bottom: auto;
    max-width: 920px;
    height: 58px; padding-bottom: 0;
    border-top: none; border-bottom: 1px solid var(--line);
    border-radius: 0 0 20px 20px;
  }
  .tabbar .tab { flex-direction: row; gap: 7px; font-size: 13px; padding-top: 0; }
  .tabbar .tab .ti { font-size: 17px; }
  .tabbar .tab.fab-slot { display: none; }

  .fab {
    bottom: 28px;
    right: max(24px, calc(50% - 460px + 24px));
  }

  .topbar { padding: 16px 26px 70px; }
  .topbar.slim { padding: 16px 26px 18px; }

  .card { margin: 12px 24px; padding: 18px; }
  .list-group { margin: 12px 24px; }
  .section-title { margin: 20px 26px 8px; }

  /* 首页大卡横排 */
  .hero {
    margin: -52px 24px 14px;
    display: flex; align-items: center; gap: 18px;
    padding: 22px;
  }
  .hero .big { font-size: 40px; }
  .hero .meta { margin-top: 6px; gap: 28px; }
  .hero .meta .m b { font-size: 18px; }
  .hero-cat { position: static; width: 110px; margin-left: auto; flex: none; }

  .quick { margin: 12px 24px; gap: 14px; }
  .quick button { padding: 14px 6px; font-size: 12.5px; }
  .quick .qi { width: 42px; height: 42px; font-size: 21px; }

  .stat-strip { margin: 0 24px; gap: 12px; }
  .stat-strip .s { padding: 14px; }
  .stat-strip .s .v { font-size: 20px; }

  .filters { padding: 12px 24px 2px; flex-wrap: wrap; overflow-x: visible; }

  /* 报表双列网格 */
  .rep-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; align-items: start; }
  .rep-grid .stat-strip { grid-column: 1 / -1; margin: 0; }

  /* 弹层 → 居中弹窗 */
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%;
    max-width: 560px; width: calc(100% - 40px);
    border-radius: 24px;
    transform: translate(-50%, -46%) scale(0.96);
    max-height: 86vh;
  }
  .sheet.on { transform: translate(-50%, -50%) scale(1); }

  .toast { top: 76px; bottom: auto; transform: translate(-50%, -8px); }
  .toast.on { transform: translate(-50%, 0); }

  .cal .cd { border-radius: 12px; }
  .chart-wrap { gap: 20px; }
}
