/* ============ 基础 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --primary: #4f6ef7;
  --primary-dark: #3d5ae0;
  --primary-light: #eef1fe;
  --danger: #e5484d;
  --success: #30a46c;
  --warning: #f59e0b;
  --text: #1c2333;
  --text-2: #5b6472;
  --text-3: #9aa3b2;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e6e9f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(28, 35, 51, 0.06), 0 4px 16px rgba(28, 35, 51, 0.05);
  --bottom-nav-h: 58px;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; }
a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }

/* ============ 登录页 ============ */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #e8edff 0%, #f4f6fb 45%, #eef9f3 100%);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(28, 35, 51, 0.12);
  padding: 36px 32px;
  text-align: center;
}
.auth-logo { font-size: 52px; line-height: 1; margin-bottom: 8px; }
.auth-title { font-size: 26px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-2); margin-bottom: 24px; font-size: 13px; }

.auth-tabs {
  display: flex; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 24px;
}
.auth-tab {
  flex: 1; padding: 8px 0; border: none; background: transparent;
  border-radius: 8px; color: var(--text-2); font-size: 14px; font-weight: 500;
  transition: all 0.15s;
}
.auth-tab.active { background: var(--card); color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }

.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
  background: #fafbfd;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.12);
}
.auth-msg { margin-top: 14px; min-height: 20px; font-size: 13px; color: var(--danger); }
.auth-msg.ok { color: var(--success); }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 500; transition: all 0.15s;
  background: #eef0f5; color: var(--text);
  min-height: 36px;
}
.btn:active { filter: brightness(0.95); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { background: #fdecec; color: var(--danger); }
.btn-danger:active { background: #fbdcdc; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; min-height: 30px; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:active { background: var(--bg); }
.icon-btn { width: 34px; height: 34px; padding: 0; border-radius: 7px; font-size: 15px; background: transparent; color: var(--text-3); }
.icon-btn:active { background: var(--bg); color: var(--text); }

/* ============ 主应用布局 ============ */
.app { display: flex; min-height: 100vh; flex-direction: row; }

/* 顶部栏（移动端，桌面隐藏） */
.topbar { display: none; }

.sidebar {
  width: 216px; flex-shrink: 0; background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 20px 14px;
}
.side-logo { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; padding: 0 8px 18px; }
.side-logo .logo-ico { font-size: 24px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 9px; border: none;
  background: transparent; color: var(--text-2); font-size: 14px; font-weight: 500;
  text-align: left; transition: all 0.15s;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-item .ico { font-size: 17px; width: 22px; text-align: center; }

.side-user {
  border-top: 1px solid var(--border); padding-top: 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.side-user .u-name { font-weight: 600; font-size: 13px; }
.side-user .u-sub { font-size: 12px; color: var(--text-3); }

.main { flex: 1; padding: 24px 28px; max-width: 1200px; width: 100%; min-width: 0; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 22px; font-weight: 700; }
.page-title .sub { font-size: 13px; color: var(--text-3); font-weight: 400; margin-left: 8px; }

/* ============ 卡片 & 表格 ============ */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: 20px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat-card { padding: 16px 18px; }
.stat-label { font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-value.income { color: var(--success); }
.stat-value.expense { color: var(--danger); }
.stat-value.blue { color: var(--primary); }

/* ============ 日历 ============ */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 8px; }
.cal-title { font-size: 18px; font-weight: 700; }
.cal-nav { display: flex; gap: 6px; align-items: center; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.cal-week span { text-align: center; font-size: 12px; color: var(--text-3); font-weight: 600; padding: 4px 0; }
.cal-day {
  min-height: 76px; background: #fafbfd; border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 6px; cursor: pointer; position: relative;
  transition: all 0.12s; overflow: hidden;
}
.cal-day:active { border-color: var(--primary); background: var(--primary-light); }
.cal-day.other { opacity: 0.38; }
.cal-day.today { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79, 110, 247, 0.18); }
.cal-day .d-num { font-size: 13px; font-weight: 600; color: var(--text-2); }
.cal-day.today .d-num { color: var(--primary); }
.cal-day .d-events { margin-top: 3px; display: flex; flex-direction: column; gap: 2px; }
.cal-chip {
  font-size: 10px; padding: 1px 4px; border-radius: 4px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; line-height: 1.5;
  background: var(--primary-light); color: var(--primary);
}
.cal-chip.todo { background: #fef3e2; color: #b45309; }
.cal-chip.done { background: #e6f6ee; color: var(--success); text-decoration: line-through; }
.cal-day .d-more { font-size: 10px; color: var(--text-3); }

/* ============ 待办 ============ */
.todo-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.todo-toolbar .btn-group { display: flex; gap: 6px; }
.filter-btn { padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--card); color: var(--text-2); font-size: 13px; }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.todo-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); margin-bottom: 10px; transition: all 0.15s;
}
.todo-item:active { box-shadow: var(--shadow); }
.todo-item.done .t-title { text-decoration: line-through; color: var(--text-3); }
.todo-check {
  width: 22px; height: 22px; flex-shrink: 0; border-radius: 50%;
  border: 2px solid var(--border); background: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; font-size: 12px; color: #fff;
}
.todo-check:active { border-color: var(--success); }
.todo-item.done .todo-check { background: var(--success); border-color: var(--success); }
.todo-main { flex: 1; min-width: 0; }
.t-title { font-weight: 500; font-size: 14px; word-break: break-all; }
.t-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.t-meta .due { color: var(--text-2); }
.t-meta .due.overdue { color: var(--danger); font-weight: 600; }
.t-meta .due.today-due { color: var(--warning); font-weight: 600; }

.prio { font-size: 11px; padding: 1px 8px; border-radius: 10px; font-weight: 600; }
.prio.high { background: #fdecec; color: var(--danger); }
.prio.medium { background: #fef3e2; color: #b45309; }
.prio.low { background: #e6f6ee; color: var(--success); }

/* ============ 记账 ============ */
.ledger-bar {
  display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.ledger-tab {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--card); color: var(--text-2); font-size: 14px; font-weight: 500;
  white-space: nowrap;
}
.ledger-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.ledger-tab .l-count { font-size: 11px; opacity: 0.75; }

.exp-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.exp-row:last-child { border-bottom: none; }
.exp-cat { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.exp-info { flex: 1; min-width: 0; }
.exp-title { font-size: 14px; font-weight: 500; word-break: break-all; }
.exp-sub { font-size: 12px; color: var(--text-3); }
.exp-amt { font-weight: 700; font-size: 15px; white-space: nowrap; }
.exp-amt.expense { color: var(--danger); }
.exp-amt.income { color: var(--success); }

/* 账本卡片 */
.ledger-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.ledger-ico { width: 44px; height: 44px; border-radius: 12px; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.ledger-info { flex: 1; min-width: 0; }
.ledger-name { font-size: 16px; font-weight: 600; }
.ledger-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.ledger-members { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.member-chip { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--bg); color: var(--text-2); }
.member-chip.owner { background: #fff6e0; color: #b45309; }
.chip-del { border: none; background: transparent; color: var(--text-3); cursor: pointer; padding: 0 2px; font-size: 11px; }
.chip-del:active { color: var(--danger); }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 26, 40, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 16px;
}
.modal {
  width: 100%; max-width: 440px; background: var(--card);
  border-radius: 16px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  max-height: 90vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title { font-size: 17px; font-weight: 700; }
.modal .field { margin-bottom: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ============ Toast ============ */
#toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; width: max-content; max-width: 90vw; }
.toast-item {
  background: #1c2333; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; margin-bottom: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  animation: toastIn 0.2s ease;
}
.toast-item.err { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ============ 空状态 ============ */
.empty { text-align: center; padding: 40px 20px; color: var(--text-3); }
.empty .empty-ico { font-size: 40px; margin-bottom: 8px; }

/* ============ 其他 ============ */
.list-scroll { max-height: 420px; overflow-y: auto; }
.section-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.mt-12 { margin-top: 12px; }
.mb-12 { margin-bottom: 12px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }

/* 费用分类颜色 */
.cat-餐饮 { background: #fef3e2; }
.cat-交通 { background: #e6f0fe; }
.cat-购物 { background: #fde8ef; }
.cat-居住 { background: #e6f6ee; }
.cat-娱乐 { background: #efe9fd; }
.cat-医疗 { background: #feecec; }
.cat-教育 { background: #e8f6fa; }
.cat-人情 { background: #fff6e0; }
.cat-其他 { background: #eef0f5; }

/* 环形图 */
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.legend { flex: 1; min-width: 160px; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-item .l-name { flex: 1; color: var(--text-2); }
.legend-item .l-val { font-weight: 600; }

/* ============ 移动端适配（手机优先） ============ */
.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--border);
  z-index: 90; justify-content: space-around; align-items: stretch;
}
.bnav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border: none; background: transparent;
  color: var(--text-3); font-size: 10px; padding: 6px 0;
}
.bnav-item .ico { font-size: 20px; line-height: 1; }
.bnav-item.active { color: var(--primary); font-weight: 600; }

@media (max-width: 768px) {
  body { padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom)); }

  /* 顶部栏显示 */
  .topbar {
    display: block; position: sticky; top: 0; z-index: 95;
    background: var(--card); border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
  }
  .topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; }
  .topbar-logo { font-size: 16px; font-weight: 700; }
  .topbar-user { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }

  /* 侧边栏隐藏，主内容全宽 */
  .sidebar { display: none; }
  .app { flex-direction: column; }
  .main { padding: 16px 14px; max-width: 100%; }

  .page-head { margin-bottom: 14px; }
  .page-title { font-size: 19px; }
  .page-title .sub { display: block; margin-left: 0; margin-top: 2px; }

  /* 卡片内边距收紧 */
  .card { padding: 14px; }

  /* 统计卡 2 列 */
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .stat-card { padding: 12px 14px; }
  .stat-value { font-size: 20px; }

  /* 日历更紧凑 */
  .cal-day { min-height: 58px; padding: 3px 4px; }
  .cal-day .d-events { display: none; }
  .cal-day.has-events .d-num::after { content: ''; display: block; width: 5px; height: 5px; border-radius: 50%; background: var(--primary); margin-top: 2px; }
  .cal-nav .btn { padding: 5px 8px; font-size: 12px; }

  /* 底部导航显示 */
  .bottom-nav { display: flex; }

  /* 记账明细行 */
  .exp-amt { font-size: 14px; }
  .exp-row { gap: 10px; }

  /* 环形图 */
  .donut-wrap { justify-content: center; }

  /* 弹窗接近全屏，从底部弹出 */
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%; width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  }
}

/* 桌面端小窗口 */
@media (max-width: 900px) and (min-width: 769px) {
  .sidebar { width: 64px; }
  .nav-item span.lbl, .side-user .u-info { display: none; }
  .side-logo .logo-text { display: none; }
}
/* 消息未读红点 */
.nav-item, .bnav-item { position: relative; }
.badge {
  position: absolute;
  top: 2px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #e5484d;
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  font-weight: 600;
}
@media (max-width: 768px) {
  .badge { top: 2px; right: 50%; transform: translateX(14px); }
}

/* 顶部栏图标按钮徽标定位 */
.topbar .icon-btn { position: relative; }
