* { box-sizing: border-box; }
:root {
  --ink: #23201d;
  --muted: #746b62;
  --line: #e4dbd0;
  --paper: #fffaf3;
  --panel: #ffffff;
  --brand: #8b1a1a;
  --gold: #b58a44;
  --green: #1b7a4b;
  --red: #b42323;
  --blue: #2f6f8f;
}
body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #f5f1ea;
}
button, input, select, textarea { font: inherit; }
button { border: 0; border-radius: 8px; min-height: 38px; padding: 0 14px; background: var(--brand); color: white; font-weight: 800; cursor: pointer; }
button:hover { filter: brightness(.98); transform: translateY(-1px); }
button.secondary { background: #fff; color: var(--brand); border: 1px solid #d8cbbb; }
button.danger { background: #3f2b2b; }
.hidden { display: none !important; }
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, rgba(139,26,26,.12), rgba(181,138,68,.12)), #f6f0e6;
}
.login-panel {
  width: min(440px, 100%);
  background: rgba(255,255,255,.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 60px rgba(54, 37, 21, .12);
}
.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  border-radius: 8px;
  font-weight: 950;
  letter-spacing: 0;
}
.brand-mark.small { width: 38px; height: 38px; }
.login-panel h1 { margin: 18px 0 8px; font-size: 26px; }
.login-panel p { margin: 0 0 22px; color: var(--muted); line-height: 1.6; }
.login-form, .record-form { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: #5c5149; font-size: 13px; font-weight: 800; }
input, select, textarea {
  width: 100%;
  border: 1px solid #d8cbbb;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  min-height: 40px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139,26,26,.1); }
.app-view { min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  background: #fbf7f0;
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
nav { display: grid; align-content: start; gap: 8px; }
.nav {
  background: transparent;
  color: #443a33;
  border: 1px solid transparent;
  text-align: left;
  justify-content: start;
}
.nav.active { background: #fff; color: var(--brand); border-color: var(--line); box-shadow: 0 8px 22px rgba(54,37,21,.07); }

/* 系统切换菜单 */
.system-switch {
  position: relative;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.system-switch-btn {
  width: 100%;
  min-height: 34px;
  border: 1px solid rgba(139,26,26,0.25);
  border-radius: 7px;
  background: rgba(139,26,26,0.08);
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.system-switch-btn:hover { background: rgba(139,26,26,0.15); }
.system-switch-menu {
  display: none;
  position: absolute;
  left: 0; right: 0;
  bottom: 40px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.12);
  overflow: hidden;
}
.system-switch-menu.show { display: block; }
.system-switch-menu a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  color: #443a33;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}
.system-switch-menu a:hover,
.system-switch-menu a.active { background: rgba(139,26,26,0.08); color: var(--brand); }
.system-switch-menu a.pending { color: #999; }
.system-switch-menu em {
  font-style: normal;
  color: #999;
  font-size: 11px;
  font-weight: 600;
}

.logout { background: #fff; color: #6c5d50; border: 1px solid var(--line); }
.workspace { min-width: 0; padding: 20px; }
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.toolbar h2 { margin: 0; font-size: 24px; }
.toolbar p { margin: 5px 0 0; color: var(--muted); }
.toolbar-actions { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.month-field { width: 164px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.metric { padding: 15px; min-height: 126px; display: grid; align-content: space-between; gap: 12px; }
.metric span { color: var(--muted); font-weight: 800; font-size: 12px; }
.metric strong { display: block; font-size: 26px; line-height: 1.05; overflow-wrap: anywhere; }
.metric em { font-style: normal; color: var(--muted); font-size: 12px; font-weight: 750; }
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid.two { grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.panel { overflow: hidden; }
.panel header {
  min-height: 52px;
  padding: 13px 15px;
  border-bottom: 1px solid #eee5da;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel h3 { margin: 0; font-size: 15px; }
.panel header span { color: var(--muted); font-size: 12px; font-weight: 750; }
.chart, .mini-chart { height: 280px; padding: 14px; }
.mini-chart { height: 230px; }
.bars, .quick-list, .delta-list { padding: 14px; display: grid; gap: 12px; }
.bar-row { display: grid; gap: 7px; }
.bar-top { display: flex; justify-content: space-between; gap: 10px; color: #4b4038; font-size: 13px; }
.bar-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-top span { color: var(--brand); font-weight: 900; white-space: nowrap; }
.bar-track { height: 9px; background: #eee6db; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), var(--gold)); min-width: 3px; }
.quick-item, .delta-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px; background: #fbf8f2; border: 1px solid #eee5da; border-radius: 8px; }
.quick-item span, .delta-item span { color: var(--muted); font-size: 12px; font-weight: 800; }
.quick-item strong, .delta-item strong { font-size: 18px; overflow-wrap: anywhere; text-align: right; }
.delta-item strong.up { color: var(--green); }
.delta-item strong.down { color: var(--red); }
.table-wrap { overflow: auto; padding: 14px; }
table { width: 100%; min-width: 620px; border-collapse: collapse; }
th, td { padding: 10px 9px; border-bottom: 1px solid #efe7dd; text-align: left; white-space: nowrap; font-size: 13px; }
th { color: #685a4e; background: #fbf8f2; font-size: 12px; }
td.money { color: var(--brand); font-weight: 900; }
.row-action { padding: 0 8px; min-height: 30px; background: transparent; color: var(--red); border: 1px solid #efd0d0; }
.empty { color: var(--muted); text-align: center; padding: 22px; }
svg { width: 100%; height: 100%; display: block; }
.axis { stroke: #eadfd2; stroke-width: 1; }
.line-income { fill: none; stroke: var(--brand); stroke-width: 3; }
.line-expense { fill: none; stroke: var(--blue); stroke-width: 3; }
.line-profit { fill: none; stroke: var(--green); stroke-width: 3; }
.chart-label { fill: #756a60; font-size: 11px; }
dialog { width: min(620px, calc(100vw - 28px)); border: 1px solid var(--line); border-radius: 8px; padding: 0; box-shadow: 0 24px 70px rgba(0,0,0,.24); }
dialog::backdrop { background: rgba(32,25,19,.28); }
.record-form { padding: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.record-form header, .record-form footer, .record-form .full { grid-column: 1 / -1; }
.record-form header, .record-form footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.record-form h3 { margin: 0; }
.icon-btn { width: 34px; min-height: 34px; padding: 0; background: #f5eee5; color: #4a3d34; font-size: 22px; }
.toast { position: fixed; right: 20px; bottom: 20px; padding: 12px 15px; background: #26211c; color: #fff; border-radius: 8px; box-shadow: 0 16px 42px rgba(0,0,0,.18); z-index: 50; }
@media (max-width: 1120px) {
  .app-view { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; grid-template-columns: 1fr; }
  nav { grid-template-columns: repeat(4, 1fr); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .workspace, .sidebar { padding: 12px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-actions { justify-content: stretch; }
  .toolbar-actions > * { flex: 1; }
  .metrics, nav, .record-form { grid-template-columns: 1fr; }
  .metric strong { font-size: 22px; }
  table { min-width: 560px; }
}
