/* ================= LnBudget 样式 ================= */
:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --line: #e7ebf3;
  --text: #1d2433;
  --muted: #7a8494;
  --accent: #4f7cff;
  --accent-soft: #eef3ff;
  --green: #16a34a;
  --red: #e5484d;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(30, 41, 59, .06);
  --shadow-lg: 0 12px 32px rgba(30, 41, 59, .16);
  --sidebar-w: 236px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; }
input, select { font-family: inherit; }
svg.ic { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- 按钮 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer; transition: all .18s; background: #fff; color: var(--text); }
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, #5b8cff, #4f7cff); color: #fff; box-shadow: 0 4px 14px rgba(79, 124, 255, .35); }
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 6px 18px rgba(79, 124, 255, .45); }
.btn-ghost { background: #f4f6fb; color: #4a5568; }
.btn-ghost:hover { background: #e9edf5; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 13px 26px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: none; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; transition: .15s; font-size: 18px; }
.icon-btn:hover { background: #eef1f7; color: var(--text); }
.icon-btn.danger:hover { background: #fee2e2; color: var(--red); }

/* ---------- 登录页 ---------- */
.login-wrap { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; overflow: hidden; background: linear-gradient(135deg, #101b3c, #1e3a8a 55%, #4f7cff); }
.login-bg { position: absolute; inset: 0; overflow: hidden; }
.blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .5; animation: floaty 12s ease-in-out infinite; }
.blob.b1 { width: 420px; height: 420px; background: #22d3ee; left: -120px; top: -80px; }
.blob.b2 { width: 380px; height: 380px; background: #a78bfa; right: -100px; bottom: -60px; animation-delay: -4s; }
.blob.b3 { width: 260px; height: 260px; background: #34d399; right: 22%; top: 8%; animation-delay: -8s; }
@keyframes floaty { 0%, 100% { transform: translate(0, 0) scale(1); } 33% { transform: translate(40px, -30px) scale(1.08); } 66% { transform: translate(-30px, 24px) scale(.94); } }
.login-card { position: relative; z-index: 2; width: 100%; max-width: 400px; background: rgba(255, 255, 255, .93); backdrop-filter: blur(14px); border-radius: 20px; padding: 34px 32px 24px; box-shadow: 0 24px 60px rgba(2, 6, 23, .45); animation: popIn .5s cubic-bezier(.22, 1.2, .36, 1); }
@keyframes popIn { from { opacity: 0; transform: translateY(22px) scale(.96); } to { opacity: 1; transform: none; } }
.login-card.shake { animation: shake .45s; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 46px; height: 46px; border-radius: 13px; background: linear-gradient(135deg, #5b8cff, #8b5cf6); display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: 0 6px 16px rgba(79, 124, 255, .4); flex: none; }
.brand-logo svg { width: 26px; height: 26px; }
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
#loginForm { margin-top: 24px; display: flex; flex-direction: column; gap: 15px; }
.login-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; border-radius: 10px; padding: 9px 12px; font-size: 13px; }
.login-foot { margin: 18px 0 0; text-align: center; font-size: 12px; color: #94a3b8; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: #4a5568; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="date"], input[type="month"], input[type="datetime-local"], select {
  width: 100%; border: 1.5px solid var(--line); background: #fbfcfe; border-radius: 10px; padding: 9px 12px; font-size: 14px; color: var(--text); outline: none; transition: .15s; min-height: 40px;
}
input:focus, select:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(79, 124, 255, .15); }
input::placeholder { color: #b3bccb; }

/* ---------- 应用布局 ---------- */
.app { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: linear-gradient(180deg, #171f33, #1d2740); color: #dfe6f5; display: flex; flex-direction: column; padding: 22px 16px; z-index: 40; }
.brand-side { padding: 0 8px 20px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.brand-side h1 { color: #fff; font-size: 17px; }
.brand-side p { color: #8b98b8; }
.side-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; margin-top: 18px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; border: none; background: transparent; color: #a9b6d4; font-size: 14px; font-weight: 500; cursor: pointer; transition: .16s; text-align: left; width: 100%; }
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: linear-gradient(135deg, #4f7cff, #6a5cff); color: #fff; box-shadow: 0 4px 14px rgba(79, 124, 255, .35); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px 8px 2px; border-top: 1px solid rgba(255, 255, 255, .08); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, #34d399, #0ea5e9); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.side-user-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.side-user-info b { font-size: 13px; color: #fff; }
.side-user-info span { font-size: 11px; color: #7e8db0; }
.side-user .icon-btn { color: #8b98b8; }
.side-user .icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 28px; background: rgba(243, 245, 250, .85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h2 { margin: 0; font-size: 19px; }
.topbar p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
#content { padding: 22px 28px 44px; max-width: 1240px; width: 100%; margin: 0 auto; }
.page { display: none; animation: fadeUp .35s ease; }
.page.active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 15px; }
.link { color: var(--accent); text-decoration: none; font-size: 13px; cursor: pointer; font-weight: 600; }
.link:hover { text-decoration: underline; }
.page-hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

/* ---------- 月份选择条 ---------- */
.monthbar { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.monthbar input[type="month"] { width: 150px; }
.monthbar .spacer { flex: 1; }
.monthbar .icon-btn { background: #fff; border: 1px solid var(--line); width: 38px; height: 38px; font-weight: 700; }

/* ---------- 统计卡片 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.stat-card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); overflow: hidden; }
.stat-card::after { content: ""; position: absolute; right: -30px; top: -30px; width: 104px; height: 104px; border-radius: 50%; opacity: .12; }
.stat-card.income::after { background: var(--green); }
.stat-card.expense::after { background: var(--red); }
.stat-card.balance::after { background: var(--accent); }
.stat-card.count::after { background: #8b5cf6; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { margin-top: 6px; font-size: 24px; font-weight: 800; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.stat-card.income .stat-value { color: var(--green); }
.stat-card.expense .stat-value { color: var(--red); }
.stat-card.balance .stat-value { color: var(--accent); }

/* ---------- 双栏 ---------- */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

/* ---------- 图表 ---------- */
.chart-box { position: relative; display: flex; align-items: center; justify-content: center; }
.chart-tip { position: absolute; z-index: 10; pointer-events: none; background: rgba(17, 24, 39, .92); color: #fff; border-radius: 10px; padding: 8px 11px; font-size: 12px; line-height: 1.7; opacity: 0; transition: opacity .12s; white-space: nowrap; box-shadow: 0 8px 20px rgba(2, 6, 23, .3); }
.chart-tip.show { opacity: 1; }
.chart-tip b { display: block; margin-bottom: 2px; }
.chart-tip span { display: block; }
.chart-legend { margin-top: 12px; display: flex; flex-direction: column; gap: 7px; max-height: 180px; overflow: auto; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-item .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-name { color: #4a5568; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend-pct { color: var(--muted); font-size: 12px; min-width: 52px; text-align: right; }
.chart-legend.grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; max-height: none; }

/* ---------- 流水列表 ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type="month"] { width: 150px; }
.filters select { width: 130px; }
.search-box { position: relative; flex: 1; min-width: 180px; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search-box input { padding-left: 34px; }
.rec-head, .rec-row { display: grid; grid-template-columns: 150px 160px 1fr 130px 90px; align-items: center; gap: 10px; padding: 10px 8px; }
.rec-head { font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); padding-top: 0; }
.rec-head span:last-child { text-align: right; }
.rec-row { border-bottom: 1px solid #f1f4f9; font-size: 14px; transition: background .12s; }
.rec-row:hover { background: #f8fafd; }
.rec-row:last-child { border-bottom: none; }
.rec-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.rec-cat { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.cat-dot { width: 26px; height: 26px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; flex: none; }
.rec-note { color: #6b7484; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-amt { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.rec-amt.inc { color: var(--green); }
.rec-amt.exp { color: var(--red); }
.rec-ops { display: flex; justify-content: flex-end; gap: 2px; }
.rec-list .rec-row { padding: 12px 8px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; font-size: 13px; color: var(--muted); }

/* ---------- 分类 ---------- */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(235px, 1fr)); gap: 12px; }
.cat-card { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fbfcfe; transition: .15s; }
.cat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.cat-icon { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none; }
.cat-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cat-info b { font-size: 14px; }
.cat-info span { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cat-ops { display: flex; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #f1f4f9; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
.table td { white-space: nowrap; }
.log-detail { white-space: normal !important; min-width: 280px; }
.badge { background: #eef2ff; color: #4f46e5; border-radius: 6px; padding: 3px 8px; font-size: 12px; font-weight: 600; }

/* ---------- 导出页 ---------- */
.exp-card { max-width: 760px; }
.sec-title { font-size: 14px; color: #4a5568; margin: 18px 0 10px; }
.sec-title:first-child { margin-top: 0; }
.radio-row { display: flex; gap: 10px; flex-wrap: wrap; }
.radio-row label { display: flex; align-items: center; gap: 7px; border: 1.5px solid var(--line); background: #fbfcfe; border-radius: 10px; padding: 9px 14px; cursor: pointer; font-size: 14px; transition: .15s; }
.radio-row input, .fmt-card input { accent-color: var(--accent); margin: 0; }
.radio-row label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: #2f54d0; font-weight: 600; }
.custom-range { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.custom-range input { width: 170px; }
.format-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.fmt-card { display: flex; flex-direction: column; gap: 4px; border: 1.5px solid var(--line); border-radius: 12px; padding: 14px 16px; cursor: pointer; transition: .15s; background: #fbfcfe; }
.fmt-card b { font-size: 15px; }
.fmt-card span { font-size: 12px; color: var(--muted); }
.fmt-card input { align-self: flex-end; }
.fmt-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px rgba(79, 124, 255, .12); }
.exp-meta { margin: 14px 0 10px; color: var(--muted); font-size: 13px; }

/* ---------- 弹窗 ---------- */
.modal-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, .45); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 18px; opacity: 0; transition: opacity .2s; }
.modal-overlay.show { opacity: 1; }
.modal { width: 100%; max-width: 440px; max-height: 88vh; overflow: auto; background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); transform: translateY(14px) scale(.97); transition: transform .22s cubic-bezier(.22, 1.2, .36, 1); }
.modal-overlay.show .modal { transform: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 20px 20px; }
.confirm-text { margin: 4px 0 0; color: #4a5568; font-size: 14px; line-height: 1.6; word-break: break-all; }
.form-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; padding: 9px 12px; border-radius: 10px; font-size: 13px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: #eef1f7; padding: 4px; border-radius: 12px; }
.seg button { border: none; background: transparent; padding: 9px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; transition: .15s; }
.seg button.on { background: #fff; box-shadow: 0 1px 4px rgba(30, 41, 59, .12); }
.seg button.on.exp { color: var(--red); }
.seg button.on.inc { color: var(--green); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-bottom: 8px; }
.emoji-grid button { border: 1.5px solid var(--line); background: #fbfcfe; border-radius: 9px; font-size: 17px; padding: 6px 0; cursor: pointer; transition: .12s; }
.emoji-grid button:hover { background: var(--accent-soft); }
.emoji-grid button.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px rgba(79, 124, 255, .2); }
.color-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--line); background: var(--c, #ccc); cursor: pointer; padding: 0; transition: .12s; flex: none; }
.swatch.on { box-shadow: 0 0 0 2.5px var(--accent); }
.swatch-custom { display: flex; align-items: center; justify-content: center; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); overflow: hidden; }
.swatch-custom input { opacity: 0; width: 100%; height: 100%; cursor: pointer; padding: 0; border: none; min-height: 0; }

/* ---------- 提示气泡 ---------- */
#toastRoot { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; width: min(92vw, 440px); }
.toast { background: #1f2937; color: #fff; border-radius: 12px; padding: 11px 18px; font-size: 14px; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(-12px); transition: .25s; max-width: 100%; word-break: break-all; }
.toast.show { opacity: 1; transform: none; }
.toast-ok { background: linear-gradient(135deg, #059669, #10b981); }
.toast-err { background: linear-gradient(135deg, #dc2626, #ef4444); }

/* ---------- 空状态 ---------- */
.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 30px 10px; }
.empty::before { content: "🗒️"; display: block; font-size: 34px; margin-bottom: 8px; }

/* ---------- 底部导航（移动端） ---------- */
.bottomnav { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 980px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  #content { padding: 16px 14px 96px; }
  .topbar { padding: 12px 16px; }
  .bottomnav { display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: rgba(255, 255, 255, .95); backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottomnav .nav-item { flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 11px; color: var(--muted); border-radius: 10px; text-align: center; }
  .bottomnav .nav-item.active { background: transparent; color: var(--accent); box-shadow: none; }
  .bottomnav svg.ic { width: 20px; height: 20px; }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-value { font-size: 20px; }
  .topbar h2 { font-size: 16px; }
  #quickAddBtn span { display: none; }
  #quickAddBtn { padding: 9px 12px; }
  .filters select { width: 108px; }
  .chart-legend.grid { grid-template-columns: 1fr; }
  .rec-head { display: none; }
  .rec-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 12px 6px; }
  .rec-time { order: 3; flex-basis: 100%; font-size: 12px; }
  .rec-cat { order: 1; }
  .rec-note { order: 4; flex-basis: 100%; font-size: 13px; white-space: normal; }
  .rec-amt { order: 2; margin-left: auto; }
  .rec-ops { order: 5; margin-left: auto; }
  .emoji-grid { grid-template-columns: repeat(8, 1fr); gap: 5px; }
  .emoji-grid button { font-size: 15px; }
  .modal { max-width: 100%; }
  .radio-row label { flex: 1; justify-content: center; min-width: 90px; }
}