:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665e;
  --line: #e4e0d8;
  --accent: #c2410c;
  --accent-soft: #fdebe1;
  --income: #15803d;
  --expense: #b91c1c;
  --bar: #f0b48f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --panel: #212026;
    --text: #ece9e4;
    --muted: #a39e96;
    --line: #34323a;
    --accent: #fb923c;
    --accent-soft: #3a2a20;
    --income: #4ade80;
    --expense: #f87171;
    --bar: #9a5a37;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.top nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.top nav a.active { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
main { max-width: 1080px; margin: 0 auto; padding: 20px 16px 80px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-top: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin: 14px 0; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-soft); }
.table-wrap { overflow-x: auto; }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 7em 1fr 6.5em; gap: 8px; align-items: center; font-size: 13px; }
.bar-row .track { display: block; height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.bar-row .fill { display: block; height: 100%; background: var(--bar); }
.bar-row .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; padding: 0 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; margin: 1px 2px; }
.tag.grey { background: var(--line); color: var(--muted); }
button, .btn {
  font: inherit; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--expense); }
input, select, textarea {
  font: inherit; width: 100%; padding: 7px 9px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
textarea { min-height: 70px; }
.filters { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 12px 0; }
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
#modal-form { padding: 18px; display: grid; gap: 10px; max-height: 85vh; overflow-y: auto; }
.fields { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.fields .full { grid-column: 1 / -1; }
label { display: grid; gap: 3px; font-size: 13px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--accent); color: #fff; }
.links { display: grid; gap: 6px; }
.links .link-row { display: grid; grid-template-columns: 1fr 5em 2.5em; gap: 6px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
#toast.show { opacity: 0.95; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
@media (max-width: 600px) {
  .fields { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .stat .value { font-size: 20px; }
}
