:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1d2430;
  --ink-2: #3d4653;
  --muted: #78818f;
  --line: #edf0f4;
  --line-2: #e4e8ee;
  --accent: #0e8a6b;
  --accent-dark: #0b7258;
  --accent-soft: #e9f6f1;
  --warn: #b06a12;
  --warn-soft: #fdf3e3;
  --danger: #c4453d;
  --danger-soft: #fdeeec;
  --info: #3c6ea5;
  --info-soft: #ecf3fa;
  --purple: #6b5aa8;
  --purple-soft: #f1eefb;
  --side: #191f27;
  --side-2: #232b36;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 31, 43, 0.04), 0 8px 28px rgba(23, 31, 43, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: 14px; color: var(--ink); }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, p { margin: 0; }

/* ---------- 基础控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 38px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 9px;
  background: #eef1f5; color: var(--ink-2);
  font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
}
.btn:hover { background: #e6eaef; }
.btn:disabled, .btn.disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: #fff; border-color: var(--line-2); color: var(--ink-2); }
.btn-ghost:hover { border-color: #cfd7df; background: #fbfcfd; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b23a33; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

input[type="text"], input:not([type]), input[type="password"], input[type="number"], input[type="date"], input[type="month"], select, textarea {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 9px;
  background: #fff; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 9px 12px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 138, 107, .12);
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #8a93a0 50%), linear-gradient(135deg, #8a93a0 50%, transparent 50%); background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type="file"] { display: none; }

.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 13px; font-weight: 500; margin-left: 12px; }
.link:first-child { margin-left: 0; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }
.muted { color: var(--muted); }
.warn-text { color: var(--warn); }
.hint { color: var(--muted); font-size: 12.5px; }
.notice { margin: 12px 0; padding: 10px 12px; border-radius: 9px; background: var(--warn-soft); color: #7e5317; font-size: 13px; }
.form-error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }
.req { color: var(--danger); margin-left: 3px; }
.nowrap { white-space: nowrap; }
.ta-r { text-align: right; }
.grow { flex: 1 1 180px; }

.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.chip.ok { background: var(--accent-soft); color: #0b7059; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.purple { background: var(--purple-soft); color: var(--purple); }
.chip.neutral { background: #f0f2f5; color: var(--muted); }
.chip.locked { background: #eef0f3; color: #59616d; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 30;
  width: 232px; padding: 22px 14px 18px;
  background: var(--side); color: #cfd6df;
  display: flex; flex-direction: column;
  transition: transform .22s ease;
}
.side-brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 22px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, #16a37e, #0b7258);
  color: #fff; font-size: 20px; font-weight: 600;
  box-shadow: 0 6px 16px rgba(14, 138, 107, .28);
}
.brand-mark.small { width: 36px; height: 36px; border-radius: 10px; font-size: 17px; }
.side-brand strong { display: block; color: #fff; font-size: 15px; letter-spacing: .5px; }
.side-brand span { display: block; color: #8993a1; font-size: 11.5px; letter-spacing: .4px; }
.nav { flex: 1; overflow-y: auto; padding-right: 2px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.14) transparent; }
.nav::-webkit-scrollbar { width: 4px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 4px; }
.nav-group { margin-bottom: 18px; }
.nav-group-label { padding: 0 10px 6px; color: #67717e; font-size: 11px; letter-spacing: 1.2px; }
.nav-item {
  width: 100%; height: 38px; margin-bottom: 2px; padding: 0 10px;
  border: 0; border-radius: 9px; background: transparent;
  color: #b7c0cb; text-align: left; font-size: 13.5px;
  display: flex; align-items: center; gap: 10px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.nav-item.active { background: rgba(14, 138, 107, .18); color: #fff; font-weight: 500; }
.nav-dot { width: 5px; height: 5px; border-radius: 50%; background: #4a5563; }
.nav-item.active .nav-dot { background: #2fd0a3; box-shadow: 0 0 0 3px rgba(47, 208, 163, .14); }
.side-foot { padding: 14px 10px 0; color: #7b8593; font-size: 11.5px; display: flex; align-items: center; gap: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot-live { width: 6px; height: 6px; border-radius: 50%; background: #2fd0a3; flex: none; }

.main { flex: 1; margin-left: 232px; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: 64px; padding: 0 30px;
  display: flex; align-items: center; gap: 16px;
  background: rgba(244, 246, 248, .88);
  backdrop-filter: blur(10px);
}
.page-title { font-size: 15px; font-weight: 600; color: var(--ink); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13px; color: var(--ink-2); }
.nav-toggle { display: none; height: 32px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; }
.content { padding: 6px 30px 60px; max-width: 1360px; }

.boot-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; color: var(--muted); }

/* ---------- 页面 / 面板 ---------- */
.page { display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 8px 2px 0; }
.page-head h2 { font-size: 23px; font-weight: 600; letter-spacing: .2px; }
.page-sub { margin-top: 5px; max-width: 760px; color: var(--muted); font-size: 13px; }
.page-actions { display: flex; align-items: center; gap: 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; }
.panel-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.panel-title::before { content: ''; width: 3px; height: 13px; border-radius: 2px; background: var(--accent); }
.danger-panel { border-color: #f3ddda; }

.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin-bottom: 14px; }
.toolbar-spacer { flex: 1; }
.field-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.field-inline > span { white-space: nowrap; }
.field-inline input, .field-inline select { width: 158px; height: 34px; font-size: 13px; }
.field-inline.grow input { width: 200px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { padding: 10px 12px; text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; background: #fafbfc; }
.table th:first-child { border-radius: 8px 0 0 8px; }
.table th:last-child { border-radius: 0 8px 8px 0; }
.table td { padding: 12px; border-bottom: 1px solid #f2f4f7; vertical-align: middle; }
.table tbody tr:hover td { background: #fbfcfd; }
.table tbody tr:last-child td { border-bottom: 0; }
.table.compact td { padding: 9px 12px; }
.log-detail { max-width: 420px; color: var(--ink-2); }
.empty { padding: 34px 0; text-align: center; color: var(--muted); font-size: 13px; }
.empty.small { padding: 18px 0; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding-top: 14px; font-size: 13px; color: var(--muted); }

/* ---------- 汇总 ---------- */
.summary-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 2px 0 16px; }
.sum-item { flex: 1 1 150px; min-width: 140px; padding: 12px 14px; border-radius: 10px; background: #f8fafb; }
.sum-item span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.sum-item strong { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- 统计卡片 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.stat-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-card > span { display: block; color: var(--muted); font-size: 12.5px; }
.stat-card strong { display: block; margin: 5px 0 2px; font-size: 24px; font-weight: 600; letter-spacing: -.3px; font-variant-numeric: tabular-nums; }
.stat-card small { color: var(--muted); font-size: 12px; }
.stat-card.accent { background: linear-gradient(150deg, #0f9473, #0b6f56); border-color: transparent; color: #fff; }
.stat-card.accent > span, .stat-card.accent small { color: rgba(255,255,255,.78); }
.stat-card.warn { background: linear-gradient(150deg, #b9822b, #96651a); border-color: transparent; color: #fff; }
.stat-card.warn > span, .stat-card.warn small { color: rgba(255,255,255,.8); }

.two-col { display: grid; grid-template-columns: 1.02fr .98fr; gap: 16px; }
.balance-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.balance-row > div { background: #f8fafb; border-radius: 11px; padding: 14px 16px; }
.balance-row span { display: block; color: var(--muted); font-size: 12px; }
.balance-row strong { display: block; margin: 2px 0; font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
.balance-row small { color: var(--muted); font-size: 11.5px; }
.risk-box { margin-top: 14px; padding: 13px 15px; border-radius: 11px; background: var(--danger-soft); color: #7f2b26; }
.risk-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; color: var(--danger); }
.risk-box p { font-size: 12.5px; line-height: 1.65; }
.risk-box .link { margin: 8px 0 0; }
.ok-box { margin-top: 14px; padding: 12px 15px; border-radius: 11px; background: var(--accent-soft); color: #0b6f56; font-size: 13px; }

.todo-list { display: flex; flex-direction: column; }
.todo-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 10px; border-radius: 10px; cursor: pointer; transition: background .15s; }
.todo-item:hover { background: #f8fafb; }
.todo-item strong { display: block; font-size: 13px; font-weight: 500; }
.todo-item span:not(.chip) { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }

/* ---------- 趋势 ---------- */
.trend { display: flex; align-items: flex-end; gap: 26px; height: 168px; padding: 10px 6px 0; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.trend-bars { display: flex; align-items: flex-end; justify-content: center; gap: 5px; width: 100%; height: 128px; }
.bar { display: block; width: 9px; border-radius: 4px 4px 2px 2px; min-height: 0; transition: height .3s; }
.bar.income { background: #18a37f; }
.bar.expense { background: #4a6fa5; }
.bar.salary { background: #b9822b; opacity: .8; }
.trend-col > span { color: var(--muted); font-size: 11.5px; }
.legend { display: flex; gap: 18px; margin-top: 12px; padding-left: 4px; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.income { background: #18a37f; }
.dot.expense { background: #4a6fa5; }
.dot.salary { background: #b9822b; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px 18px; }
.form-item { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-item.full { grid-column: 1 / -1; }
.form-item > label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.form-section { grid-column: 1 / -1; margin: 4px 0 -2px; font-size: 12px; font-weight: 600; letter-spacing: .6px; color: var(--accent); }
.field-hint { color: var(--muted); font-size: 11.5px; }
.notice + .notice { margin-top: 8px; }

/* ---------- 弹窗 ---------- */
.modal-mask { position: fixed; inset: 0; z-index: 60; background: rgba(20, 26, 34, .42); backdrop-filter: blur(2px); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 18px 30px; overflow-y: auto; }
.modal { width: 100%; max-width: 640px; background: #fff; border-radius: 16px; box-shadow: 0 24px 70px rgba(16, 22, 30, .25); display: flex; flex-direction: column; max-height: 88vh; animation: modal-in .18s ease; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 22px 12px; }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.icon-btn { width: 30px; height: 30px; border: 0; border-radius: 8px; background: #f2f4f7; color: #68717d; font-size: 18px; line-height: 1; }
.icon-btn:hover { background: #e9edf1; }
.modal-body { padding: 6px 22px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 20px; }
.modal-confirm { max-width: 420px; }
.confirm-msg { color: var(--ink-2); font-size: 14px; line-height: 1.7; }

/* ---------- 提示 ---------- */
.toasts { position: fixed; top: 20px; right: 22px; z-index: 90; display: flex; flex-direction: column; gap: 9px; }
.toast { padding: 11px 16px; border-radius: 10px; background: #26303b; color: #fff; font-size: 13px; box-shadow: 0 10px 30px rgba(16, 22, 30, .2); animation: toast-in .18s ease; max-width: 420px; }
.toast.error { background: #a83b35; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- 登录 / 初始化 ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(1100px 600px at 15% 0%, #e8f4ef 0%, transparent 55%), radial-gradient(900px 500px at 95% 100%, #eef1f9 0%, transparent 60%), #f4f6f8; }
.auth-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 20px 60px rgba(23, 31, 43, .08); padding: 32px 30px 26px; }
.brand-block { display: flex; align-items: center; gap: 13px; margin-bottom: 26px; }
.brand-block h1 { font-size: 21px; font-weight: 600; letter-spacing: .4px; }
.brand-block p { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); }
.auth-form .btn { margin-top: 4px; height: 42px; }
.auth-foot { margin-top: 22px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.auth-foot .muted { margin-top: 5px; }
.setup-card { max-width: 520px; }
.setup-body { color: var(--ink-2); font-size: 13.5px; line-height: 1.75; margin-bottom: 18px; }
.setup-body p + p { margin-top: 8px; }
.setup-result { margin-top: 12px; padding: 10px 12px; border-radius: 9px; background: var(--accent-soft); color: #0b6f56; }

/* ---------- 附件 ---------- */
.att-box { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: #fbfcfd; }
.att-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.att-toolbar .hint { flex: 1; min-width: 200px; }
.att-list { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.att-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 10px; border-radius: 9px; background: #fff; border: 1px solid #f0f2f5; }
.att-main { min-width: 0; }
.att-name { display: block; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-meta { display: block; color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.att-actions { display: flex; align-items: center; flex: none; }

/* ---------- 借款还款 ---------- */
.repay-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.repay-summary > div { padding: 12px 14px; border-radius: 10px; background: #f8fafb; }
.repay-summary span { display: block; color: var(--muted); font-size: 12px; }
.repay-summary strong { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.repay-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; padding: 12px; border-radius: 10px; background: #f8fafb; margin-bottom: 14px; }
.repay-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 130px; }
.repay-form label.grow { flex: 1; }
.repay-form input { height: 34px; }
.repay-list { display: flex; flex-direction: column; gap: 6px; }
.repay-row-wrap { border-bottom: 1px solid #f2f4f7; }
.repay-row-wrap:last-child { border-bottom: 0; }
.repay-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 4px; }
.repay-row strong { margin-right: 10px; font-weight: 500; }
.repay-row .att-actions .link { margin-left: 12px; }
.repay-row-wrap .att-box { margin: 4px 0 12px; }

/* ---------- 导出 ---------- */
.export-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.export-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 16px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcfd; }
.export-card strong { font-size: 13.5px; font-weight: 600; }
.export-card p { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- 设置 ---------- */
.seg { display: inline-flex; padding: 3px; border-radius: 9px; background: #f0f3f6; }
.seg button { height: 28px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 12.5px; }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(23, 31, 43, .08); }
.settings .panel + .panel { margin-top: 16px; }
.page .panel + .panel { margin-top: 0; }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .main { margin-left: 0; }
  .nav-toggle { display: inline-flex; align-items: center; }
  .topbar { padding: 0 18px; }
  .content { padding: 4px 18px 50px; }
  .page-title { display: none; }
  .export-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .stat-grid, .stat-grid.two { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .balance-row { grid-template-columns: 1fr; }
  .summary-row { flex-direction: column; }
  .sum-item { flex: 1 1 auto; }
  .trend { gap: 10px; }
  .page-head h2 { font-size: 20px; }
  .panel { padding: 16px; }
  .modal-mask { padding: 3vh 10px 20px; }
  .modal-body { padding: 4px 16px 18px; }
  .modal-head, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .repay-form label { min-width: 100%; }
}
