* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f5f6f8; color: #222; font-size: 14px;
}
header {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: #fff; border-bottom: 1px solid #e5e6ea;
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 20px; }
nav { display: flex; gap: 8px; }
.tab {
  border: none; background: none; padding: 6px 16px; font-size: 15px;
  cursor: pointer; border-radius: 6px; color: #666;
}
.tab.active { background: #2563eb; color: #fff; }
.ai-badge { margin-left: auto; font-size: 12px; color: #888; }

.view { padding: 16px 24px; }
.hidden { display: none !important; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.spacer { flex: 1; }
.btn {
  display: inline-block; border: 1px solid #d0d3d9; background: #fff;
  padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: #f0f2f5; }
.btn.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn.on { background: #2563eb; color: #fff; border-color: #2563eb; }
select, input[type=text], input[type=number] {
  padding: 6px 10px; border: 1px solid #d0d3d9; border-radius: 6px;
  font-size: 14px; background: #fff;
}
.hint { color: #888; font-size: 13px; }
.saved-hint { color: #16a34a; margin-left: 10px; font-size: 13px; }
.section-title { margin: 20px 0 10px; }

/* ---- 记账页布局 ---- */
.ledger-main { display: flex; gap: 16px; align-items: flex-start; }
.tx-list { flex: 1.4; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cat-side { flex: 1; position: sticky; top: 76px; display: flex; flex-direction: column; gap: 12px; }

.tx-card {
  background: #fff; border: 1px solid #e5e6ea; border-radius: 10px;
  padding: 10px 14px;
}
.tx-card.dim { opacity: .62; }
.tx-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tx-who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-desc { color: #777; font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amt { font-size: 16px; font-weight: 700; white-space: nowrap; }
.tx-amt.in { color: #16a34a; }
.tx-meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 12px; color: #999; }
.badge {
  font-size: 11px; padding: 1px 8px; border-radius: 999px;
  background: #eef0f3; color: #555;
}
.badge.income { background: #dcfce7; color: #15803d; }
.badge.neutral { background: #f1f5f9; color: #64748b; }
.badge.src { background: #e0e7ff; color: #4338ca; }
.chip {
  display: inline-block; background: #ecfdf5; border: 1px solid #a7f3d0;
  color: #065f46; border-radius: 999px; padding: 2px 10px; font-size: 12px;
}

.tx-classify { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tx-classify .sep { color: #ccc; }
.tx-actions { margin-left: auto; display: flex; gap: 6px; }
.link-btn { border: none; background: none; color: #2563eb; cursor: pointer; font-size: 12px; padding: 2px 4px; }
.link-btn.danger { color: #dc2626; }
.sug-mark { font-size: 11px; color: #d97706; }

/* ---- 右侧五个花销框 ---- */
.cat-boxes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.cat-box {
  background: #fff; border: 2px solid #e5e6ea; border-radius: 10px;
  padding: 10px 8px; text-align: center; cursor: pointer;
}
.cat-box:hover { border-color: #b6c4e2; }
.cat-box.active { border-color: #2563eb; background: #eff6ff; }
.cat-box .name { font-size: 13px; color: #555; }
.cat-box .total { font-size: 17px; font-weight: 700; margin-top: 4px; }
.cat-box .count { font-size: 11px; color: #999; margin-top: 2px; }

.cat-detail {
  background: #fff; border: 1px solid #e5e6ea; border-radius: 10px;
  padding: 14px; min-height: 120px;
}
.cat-detail h3 { margin-bottom: 10px; font-size: 15px; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-table th, .detail-table td {
  text-align: left; padding: 5px 6px; border-bottom: 1px solid #f0f1f4;
}
.detail-table th { color: #888; font-weight: 500; }
.detail-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sub-line { color: #777; font-size: 12px; padding-left: 12px; }

/* ---- 预算页 ---- */
.budget-cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.budget-card {
  background: #fff; border: 1px solid #e5e6ea; border-radius: 10px; padding: 14px;
}
.budget-card { cursor: pointer; }
.budget-card:hover { border-color: #b6c4e2; }
.budget-card h4 { font-size: 14px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.budget-card .row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; color: #555; gap: 8px; }
.budget-card .row.grp { color: #999; font-size: 12px; border-top: 1px dashed #eee; margin-top: 6px; padding-top: 8px; }
.budget-card .row .ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.budget-card .balance { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.budget-card .balance.neg { color: #dc2626; }
.budget-card .balance.pos { color: #16a34a; }
.detail-link { font-size: 12px; color: #2563eb; font-weight: 400; }
.range-hint { font-size: 11px; color: #aaa; margin-left: 4px; }
.modal-body.wide { width: min(680px, 94vw); max-height: 80vh; overflow-y: auto; }
.modal-body.wide h3 { margin-bottom: 12px; }

.budget-config {
  background: #fff; border: 1px solid #e5e6ea; border-radius: 10px; padding: 14px;
}
.budget-config-inputs { display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0; }
.budget-config-inputs label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #555; }
.budget-config-inputs input { width: 110px; }

#budget-table { overflow-x: auto; }

/* ---- 弹窗 & toast ---- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-body {
  background: #fff; border-radius: 12px; padding: 20px; width: min(560px, 92vw);
}
.modal-body textarea { width: 100%; margin: 10px 0; padding: 8px; font-size: 13px; border: 1px solid #d0d3d9; border-radius: 6px; }
.modal-actions { display: flex; gap: 10px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #222; color: #fff; padding: 8px 18px; border-radius: 8px;
  font-size: 13px; z-index: 200; max-width: 80vw;
}

/* ---- 登录 ---- */
#user-area { margin-left: 12px; display: flex; align-items: center; gap: 8px; font-size: 13px; color: #666; }
.auth-screen {
  position: fixed; inset: 0; background: #f5f6f8; z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.auth-card {
  background: #fff; border: 1px solid #e5e6ea; border-radius: 12px;
  padding: 32px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px;
}
.auth-card h2 { text-align: center; margin-bottom: 8px; }
.auth-card input { padding: 10px 12px; border: 1px solid #d0d3d9; border-radius: 8px; font-size: 14px; }
.auth-toggle { text-align: center; font-size: 13px; }
.auth-toggle a { color: #2563eb; text-decoration: none; }
.auth-err { color: #dc2626; font-size: 13px; text-align: center; min-height: 18px; }
