:root {
  --bg: #f1f1f1;
  --surface: #ffffff;
  --sidebar: #ebebeb;
  --text: #303030;
  --muted: #616161;
  --subtle: #8a8a8a;
  --border: #e3e3e3;
  --border-strong: #c9c9c9;
  --primary: #303030;
  --primary-hover: #1a1a1a;
  --accent: #005bd3;
  --success: #29845a;
  --success-bg: #cdfee1;
  --warning-bg: #fff1c2;
  --warning: #8a6116;
  --critical: #c70a24;
  --critical-bg: #fee9e8;
  --info-bg: #eaf4ff;
  --radius: 12px;
  --shadow: 0 1px 0 rgba(26, 26, 26, 0.07), 0 1px 2px rgba(26, 26, 26, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 13px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 650; margin: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h2 { font-size: 14px; font-weight: 650; margin: 0; }
code { background: #f3f3f3; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.pre { white-space: pre-wrap; }
.neg { color: var(--critical); }
.pad { padding: 16px; }
.pad-x { padding: 0 16px; }
.req { color: var(--critical); font-style: normal; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--sidebar); padding: 12px 8px 24px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; color: var(--text); text-decoration: none !important; }
.brand-logo { width: 32px; height: 32px; border-radius: 8px; background: #1a1a1a; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 16px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px; color: var(--text); font-weight: 550; text-decoration: none; }
.nav a:hover { background: rgba(0, 0, 0, 0.05); }
.nav a.active { background: #fafafa; box-shadow: var(--shadow); }
.nav-group { margin: 14px 10px 4px; font-size: 11px; font-weight: 600; color: var(--subtle); }
.nav-badge { margin-left: auto; background: #ffd79d; color: #5e4200; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 600; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; color: #4a4a4a; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 20px; background: var(--bg); position: sticky; top: 0; z-index: 20; border-bottom: 1px solid transparent; }
.topbar-title { font-weight: 600; display: none; }
.topbar-user { margin-left: auto; }
.menu-btn { display: none; }
.content { padding: 8px 24px 48px; max-width: 1400px; width: 100%; margin: 0 auto; }

.dropdown { position: relative; }
.dropdown summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.dropdown summary::-webkit-details-marker { display: none; }
.dropdown summary:hover { background: rgba(0, 0, 0, 0.05); }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border-radius: 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); padding: 6px; min-width: 150px; z-index: 30; }
.dropdown-menu a, .dropdown-menu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: #f1f1f1; text-decoration: none; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #c4b5fd; color: #2e1065; display: grid; place-items: center; font-weight: 600; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta small { color: var(--muted); font-size: 11px; }

/* ---------- 页面头部 ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 8px 0 16px; flex-wrap: wrap; }
.page-header p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.back-link { display: inline-block; color: var(--muted); margin-bottom: 4px; font-size: 12px; }

/* ---------- 卡片 ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.card.pad { padding: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px; }
.card-header form { margin: 0; }
.card-title { margin-bottom: 12px; }
.card-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.card-title-row .card-title { margin: 0; }
.sticky { position: sticky; top: 64px; }
.narrow { max-width: 420px; }
.empty-state { padding: 40px; text-align: center; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stats .card { margin: 0; }
.stat { padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 550; }
.stat-value { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value-sm { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-foot { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stats-sm .stat-value { font-size: 17px; }
.stat .stat-value + .stat-value { margin-top: 0; font-size: 18px; }
.cur { font-size: 0.7em; font-weight: 600; color: var(--muted); margin-right: 2px; }
.amt-line { white-space: nowrap; }
.amt-line + .amt-line { margin-top: 2px; }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 20px 0 10px; }
.section-title h2 { font-size: 16px; }
.chart-cur { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 16px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-weight: 550; color: var(--muted); background: #f7f7f7; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; font-size: 12px; }
.table td { padding: 9px 12px; border-bottom: 1px solid #ebebeb; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 650; background: #fafafa; border-top: 1px solid var(--border); }
.table .num { text-align: right; white-space: nowrap; }
.table-hover tbody tr[data-href] { cursor: pointer; }
.table-hover tbody tr:hover td { background: #f7f7f7; }
.table-compact td, .table-compact th { padding: 5px 10px; }
.table .empty { text-align: center; color: var(--muted); padding: 28px; }
.row-void td { color: var(--subtle); text-decoration: line-through; }
.row-void td .badge, .row-void td a { text-decoration: none; }
.row-muted td { color: var(--muted); }
.ellipsis { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-check { width: 36px; }
.w-ratio { width: 110px; }
.w-sort { width: 80px; }
.w-cur { width: 90px; }
.table-toolbar { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.table-toolbar form { margin: 0; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px; border-top: 1px solid var(--border); }
.old { color: var(--critical); }
.new { color: var(--success); }

/* ---------- 徽章 ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 8px; font-size: 11px; font-weight: 550; background: #e3e3e3; color: #4a4a4a; white-space: nowrap; vertical-align: middle; }
.badge-pending, .badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-confirmed { background: var(--success-bg); color: #0c5132; }
.badge-void { background: var(--critical-bg); color: #8e0b21; }
.dir { display: inline-block; font-size: 11px; padding: 0 5px; border-radius: 4px; }
.dir-income { background: #e0f0ff; color: #00527c; }
.dir-expense { background: #fdeee6; color: #8a3c00; }

/* ---------- 横幅 ---------- */
.banner { border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; background: var(--info-bg); border: 1px solid #b6d9ff; }
.banner ul { margin: 6px 0 0; padding-left: 20px; }
.banner-success { background: #effdf4; border-color: #a6eac0; }
.banner-error { background: var(--critical-bg); border-color: #fcc5c2; }
.banner-warning { background: #fff8e3; border-color: #f5d68a; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > span { font-weight: 550; font-size: 12px; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.field.inline > span { white-space: nowrap; }
.hint { color: var(--muted); font-size: 11px; min-height: 0; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], input[type=file], select, textarea {
  font: inherit; color: var(--text); background: #fdfdfd; border: 1px solid #8a8a8a; border-radius: 8px; padding: 6px 10px; width: 100%; min-height: 32px;
  border-color: var(--border-strong);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
.check, .switch { display: flex; align-items: center; gap: 6px; font-weight: 550; cursor: pointer; margin-bottom: 8px; }
.readonly-value { padding: 6px 10px; min-height: 32px; background: #f7f7f7; border-radius: 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-footer { display: flex; justify-content: flex-end; align-items: center; gap: 16px; padding: 12px 16px; border-top: 1px solid var(--border); }
.form-footer .check { margin: 0; }
.filters { padding: 14px 16px 6px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0 12px; }
.filter-grid .grow { grid-column: span 2; }
.filter-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.period-filter { display: flex; gap: 6px; align-items: center; margin: 0; flex-wrap: wrap; }
.period-filter select, .period-filter input { width: auto; }
.custom-range { display: inline-flex; gap: 4px; align-items: center; }
.alloc-table td { padding: 6px 8px; }
.alloc-table input, .alloc-table select { min-width: 0; }
.amount-input { max-width: 160px; }
.daily-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.daily-table td { padding: 6px 10px; }
.daily-table input[type=text] { display: inline-block; width: 140px; }
.locked-cell { color: var(--muted); }
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.dl .big { font-size: 20px; font-weight: 650; }
.dl-side { grid-template-columns: 70px 1fr; }
.steps { padding-left: 20px; margin: 0 0 16px; }
.steps li { margin-bottom: 6px; }

/* ---------- 按钮 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 6px 12px; min-height: 32px; border-radius: 8px; border: 0; cursor: pointer;
  background: #fff; color: var(--text); box-shadow: inset 0 -1px 0 #b5b5b5, inset 0 0 0 1px rgba(0,0,0,.1); text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: #f7f7f7; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: inset 0 -1px 0 #000, 0 1px 0 rgba(0,0,0,.2); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--critical); color: #fff; box-shadow: none; }
.btn-danger:hover { background: #a30a1f; }
.btn-danger-plain { background: transparent; color: var(--critical); box-shadow: none; }
.btn-plain { background: transparent; box-shadow: none; color: var(--accent); }
.btn-sm { padding: 3px 10px; min-height: 28px; font-size: 12px; }
.btn-block { width: 100%; margin-bottom: 8px; }
.btn.disabled { opacity: .45; pointer-events: none; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: #ececec; }

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs a { padding: 5px 12px; border-radius: 8px; color: var(--text); font-weight: 550; }
.tabs a.active { background: #fff; box-shadow: var(--shadow); }
.tabs a:hover { text-decoration: none; background: rgba(0,0,0,.04); }

/* ---------- 图表 ---------- */
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot.inc, .bar.inc { background: #4f8ff7; }
.dot.exp, .bar.exp { background: #f6a46b; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding: 8px 16px 12px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.bar-pair { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.bar { width: 40%; max-width: 16px; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar-label { font-size: 11px; color: var(--muted); margin-top: 4px; }
.progress { height: 8px; background: #ececec; border-radius: 4px; overflow: hidden; margin: 12px 0 4px; }
.progress-bar { height: 100%; background: var(--success); }
.progress-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

/* ---------- 历史 ---------- */
.history-item { padding: 10px 16px; border-top: 1px solid #ebebeb; }
.history-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.history-reason { margin: 4px 0; color: var(--warning); }
.history-item .table { margin-top: 6px; border: 1px solid #ebebeb; }
details.changes summary { cursor: pointer; color: var(--accent); font-size: 12px; }

/* ---------- 登录 ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(160deg, #e9e9e9, #f6f6f6); padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.08); padding: 28px; }
.auth-brand { padding: 0 0 20px; }
.auth-wrap { width: 100%; max-width: 480px; }

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  body.nav-open .sidebar { transform: none; }
  .sidebar-mask { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 40; }
  body.nav-open .sidebar-mask { display: block; }
  .menu-btn { display: inline-block; }
  .topbar-title { display: block; }
  .content { padding: 4px 12px 40px; }
  .grid-2, .form-layout { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .user-meta { display: none; }
}
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2, .filter-grid .grow { grid-column: auto; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 17px; }
  .page-header { align-items: flex-start; }
}
