/* ============================================================
   生活费智控 AllowanceWise - 全局样式（零依赖、移动优先）
   ============================================================ */

:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --ink: #1f2430;
  --ink-2: #424957;
  --muted: #7a8194;
  --line: #e7e9f0;
  --line-strong: #d6dae5;

  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-weak: #eef0ff;
  --primary-ink: #3730a3;

  --safe: #15a34a;
  --safe-weak: #e8f7ef;
  --warn: #c77a08;
  --warn-weak: #fdf2dd;
  --danger: #dc2626;
  --danger-weak: #fdecec;
  --info: #0369a1;
  --info-weak: #e6f3fb;

  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(31, 36, 48, 0.06);
  --shadow-sm: 0 2px 10px rgba(31, 36, 48, 0.05);

  --tabbar-h: 70px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; color: var(--ink); }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }

/* ---------------- 布局骨架 ---------------- */

.app-shell { min-height: 100vh; }

.main-col { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 12px;
  background: rgba(244, 245, 248, 0.92);
  backdrop-filter: blur(8px);
}
.topbar-title { font-size: 17px; font-weight: 700; }

.view {
  padding: 4px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
  max-width: 980px;
  margin: 0 auto;
}

.sidebar { display: none; }
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: flex;
}
.tab-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.2;
  text-decoration: none;
  min-height: 44px;
  padding-bottom: 4px;
}
.tab-item svg { width: 22px; height: 22px; }
.tab-item.active { color: var(--primary); font-weight: 600; }

@media (min-width: 880px) {
  .app-shell { display: grid; grid-template-columns: 224px 1fr; }
  .tabbar { display: none; }
  .sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 22px 14px;
  }
  .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
  .brand-mark {
    width: 38px; height: 38px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-weak); color: var(--primary);
  }
  .brand-name { font-weight: 750; font-size: 16px; }
  .side-nav { display: flex; flex-direction: column; gap: 4px; }
  .side-nav .tab-item {
    flex: none; flex-direction: row; justify-content: flex-start;
    gap: 12px; font-size: 14.5px; padding: 11px 12px; border-radius: 12px;
  }
  .side-nav .tab-item:hover { background: var(--surface-2); }
  .side-nav .tab-item.active { background: var(--primary-weak); }
  .side-foot { margin-top: auto; padding: 12px; font-size: 12px; color: var(--muted); }
  .topbar { padding: 22px 30px 14px; background: transparent; backdrop-filter: none; position: static; }
  .topbar-title { font-size: 20px; }
  .view { padding: 4px 30px 40px; max-width: none; }
}

/* ---------------- 通用组件 ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 14px;
}
.card.flat { box-shadow: none; }
.card-title {
  font-size: 15px; font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 12px;
}
.card-title .sub { font-size: 12.5px; font-weight: 400; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; }
.gap-6 { gap: 6px; } .gap-10 { gap: 10px; } .gap-14 { gap: 14px; }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 520px) { .grid-3 { grid-template-columns: 1fr 1fr; } }

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 14.5px;
  font-weight: 600;
  min-height: 44px;
  cursor: pointer;
  transition: transform .04s ease, background .15s ease, box-shadow .15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); border-color: #f3c2c2; background: var(--danger-weak); }
.btn.safe { background: var(--safe); border-color: var(--safe); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

.input, select.input, textarea.input {
  width: 100%;
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 15.5px;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  min-height: 44px;
}
textarea.input { min-height: 72px; resize: vertical; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.13); }
.input.invalid { border-color: var(--danger); background: #fff8f8; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
.field .err { color: var(--danger); font-size: 12.5px; margin-top: 5px; min-height: 0; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 5px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge.safe { background: var(--safe-weak); color: var(--safe); border-color: #bfe6cf; }
.badge.warn { background: var(--warn-weak); color: var(--warn); border-color: #f0d9ac; }
.badge.danger { background: var(--danger-weak); color: var(--danger); border-color: #f3c2c2; }
.badge.info { background: var(--info-weak); color: var(--info); border-color: #b8dcf0; }
.badge.primary { background: var(--primary-weak); color: var(--primary-ink); border-color: #d4d8fb; }

/* 语义色数字 */
.num { font-variant-numeric: tabular-nums; font-weight: 700; }
.num.safe { color: var(--safe); }
.num.warn { color: var(--warn); }
.num.danger { color: var(--danger); }
.num.big { font-size: 30px; letter-spacing: -0.5px; }
.num.mid { font-size: 20px; }

/* 进度条 */
.progress { height: 9px; border-radius: 999px; background: #eceef4; overflow: hidden; }
.progress > .fill { height: 100%; border-radius: 999px; background: var(--primary); transition: width .3s ease; }
.progress > .fill.safe { background: var(--safe); }
.progress > .fill.warn { background: var(--warn); }
.progress > .fill.danger { background: var(--danger); }
.progress.thin { height: 7px; }

/* 横向信息行 */
.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); font-size: 13.5px; }
.kv .v { font-weight: 600; text-align: right; }

/* 空状态 */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 14px;
}
.empty .empty-glyph {
  width: 64px; height: 64px; margin: 0 auto 12px;
  border-radius: 20px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; color: #aab1c2;
}

/* 横幅 */
.banner {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13.5px;
  display: flex; gap: 10px; align-items: flex-start;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.banner .banner-icon { flex: none; margin-top: 1px; }
.banner.info { background: var(--info-weak); color: #0c4f75; border-color: #b8dcf0; }
.banner.warn { background: var(--warn-weak); color: #8a5506; border-color: #f0d9ac; }
.banner.danger { background: var(--danger-weak); color: #991b1b; border-color: #f3c2c2; }
.banner.safe { background: var(--safe-weak); color: #166534; border-color: #bfe6cf; }
.banner.primary { background: var(--primary-weak); color: var(--primary-ink); border-color: #d4d8fb; }

/* 表格（桌面）/ 卡片（手机） */
.table-wrap { width: 100%; overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: right; font-weight: 600; color: var(--muted);
  padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
  font-size: 12.5px;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.data tr:last-child td { border-bottom: none; }
table.data tfoot td { font-weight: 700; border-top: 1px solid var(--line-strong); }

/* ---------------- Toast / Modal ---------------- */

.toast-root {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 12px); left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 100; pointer-events: none;
}
.toast {
  background: rgba(31, 36, 48, 0.94); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  animation: toast-in .18s ease;
  max-width: 88vw;
}
.toast.safe { background: #15803d; }
.toast.danger { background: #b91c1c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.modal-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(24, 27, 39, 0.46);
  display: flex; align-items: center; justify-content: center;
  padding: 22px;
  animation: fade-in .15s ease;
}
.modal {
  background: var(--surface);
  border-radius: 18px;
  width: 100%; max-width: 400px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: modal-in .18s ease;
}
.modal h3 { font-size: 17px; margin-bottom: 8px; }
.modal .modal-body { color: var(--ink-2); font-size: 14px; margin-bottom: 18px; }
.modal .modal-actions { display: flex; gap: 10px; }
.modal .modal-actions .btn { flex: 1; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------------- 看板 ---------------- */

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px;
  box-shadow: var(--shadow-sm);
}
.stat-card .label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.hero-card {
  background: linear-gradient(135deg, #4f46e5 0%, #6d63f0 60%, #8b7ff5 100%);
  color: #fff;
  border: none;
}
.hero-card .label, .hero-card .muted { color: rgba(255,255,255,.82); }
.hero-card .num { color: #fff; }
.hero-card .progress { background: rgba(255,255,255,.22); }
.hero-card .kv { border-color: rgba(255,255,255,.18); }
.hero-card .kv .k { color: rgba(255,255,255,.82); }
.hero-card .badge { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.25); }

.month-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 14px; }
.month-nav .nav-btn {
  width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--ink-2);
}
.month-nav .nav-btn:disabled { opacity: .35; cursor: default; }
.month-nav .month-label { font-size: 16px; font-weight: 700; min-width: 120px; text-align: center; }

.cat-line { padding: 11px 0; border-bottom: 1px solid var(--line); }
.cat-line:last-child { border-bottom: none; }
.cat-line .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 7px; }
.cat-line .name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.cat-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.cat-line .money { font-size: 13.5px; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.cat-line .money b { color: var(--ink); }

.txn-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}
.txn-item:last-child { border-bottom: none; }
.txn-icon {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  background: var(--primary-weak); color: var(--primary-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.txn-item .meta { flex: 1; min-width: 0; }
.txn-item .meta .t1 { font-weight: 600; font-size: 14px; display: flex; gap: 7px; align-items: center; }
.txn-item .meta .t2 { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-item .amt { font-weight: 700; font-variant-numeric: tabular-nums; }

.day-group .day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12.5px; color: var(--muted);
  padding: 14px 2px 6px;
}
.day-group .day-head b { color: var(--ink-2); font-size: 13.5px; }

/* 分类选择网格 */
.chip-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 380px) { .chip-grid { grid-template-columns: repeat(3, 1fr); } }
.chip {
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 4px;
  font-size: 13px;
  min-height: 44px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-2);
  text-align: center;
}
.chip .chip-dot { width: 8px; height: 8px; border-radius: 50%; }
.chip.active { border-color: var(--primary); background: var(--primary-weak); color: var(--primary-ink); font-weight: 650; }

/* 金额大输入 */
.amount-input-wrap {
  display: flex; align-items: center; gap: 6px;
  border: 2px solid var(--line-strong); border-radius: 16px;
  padding: 8px 14px; background: var(--surface);
}
.amount-input-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.amount-input-wrap .cny { font-size: 26px; font-weight: 700; color: var(--muted); }
.amount-input-wrap input {
  flex: 1; border: none; outline: none; font-size: 30px; font-weight: 700;
  width: 100%; min-width: 0; background: transparent; color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* 报告 */
.score-ring { position: relative; width: 118px; height: 118px; flex: none; }
.score-ring .num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 30px; }
.score-part { margin-bottom: 10px; }
.score-part .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.finding-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 13px; margin-bottom: 10px; background: var(--surface-2); }
.finding-card .head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.finding-card .reason { font-size: 13.5px; color: var(--ink-2); }
.suggestion-card { border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px; border: 1px solid var(--line); background: var(--surface); }
.suggestion-card .head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.suggestion-card .actions { font-size: 13.5px; color: var(--ink-2); }
.suggestion-card .actions li { margin: 3px 0; }
.followup-ok { color: var(--safe); font-weight: 700; }
.followup-no { color: var(--danger); font-weight: 700; }

.section-stack > section { margin-bottom: 16px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

.svg-chart { width: 100%; height: auto; display: block; }

/* 设置页 */
.setting-group-title { font-size: 12.5px; color: var(--muted); font-weight: 600; margin: 18px 4px 8px; }

/* 引导页 */
.bootstrap-wrap { max-width: 520px; margin: 0 auto; padding: 24px 4px 60px; }
.bootstrap-hero { text-align: center; padding: 18px 0 22px; }
.bootstrap-hero .logo {
  width: 72px; height: 72px; border-radius: 22px; margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--primary), #8b7ff5);
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 14px 34px rgba(79,70,229,.35);
}
.bootstrap-hero h1 { font-size: 23px; margin-bottom: 8px; }
.bootstrap-hero p { color: var(--muted); font-size: 14px; }
.steps { display: flex; gap: 6px; margin-bottom: 20px; }
.steps .step { flex: 1; height: 5px; border-radius: 99px; background: var(--line-strong); }
.steps .step.on { background: var(--primary); }

.budget-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.budget-row:last-child { border-bottom: none; }
.budget-row .cat-name { flex: 1; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.budget-row input { width: 108px; text-align: right; }
.budget-row .unit { color: var(--muted); font-size: 13px; }

.cat-manage-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cat-manage-row:last-child { border-bottom: none; }

@media (min-width: 880px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .bootstrap-wrap { padding-top: 40px; }
}

/* ============================================================
   启动欢迎动画 / 加载遮罩
   ============================================================ */
.splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 45%, #10b981 100%);
  color: #fff;
  font-family: var(--font);
  transition: opacity 0.45s ease;
}
.splash.hide {
  opacity: 0;
  pointer-events: none;
}
.splash-inner {
  text-align: center;
  animation: splash-fade-in 0.5s ease both;
}
.splash-logo {
  width: 104px;
  height: 104px;
  margin: 0 auto 26px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
  animation: splash-pop 1s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.splash-title {
  margin: 0 0 10px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 4px;
}
.splash-tag {
  margin: 0 0 34px;
  font-size: 13px;
  opacity: 0.88;
  letter-spacing: 5px;
}
.splash-dots {
  display: flex;
  gap: 9px;
  justify-content: center;
}
.splash-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  animation: splash-dot 1.2s infinite ease-in-out;
}
.splash-dots span:nth-child(2) { animation-delay: 0.18s; }
.splash-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes splash-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes splash-pop {
  0%   { opacity: 0; transform: scale(0.6); }
  60%  { transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes splash-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1; }
}
