:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1f2430; --muted: #6b7280; --line: #e5e7eb;
  --accent: #3b6fd8; --plus: #1a7f4b; --minus: #c2410c;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14161b; --panel: #1d2027; --text: #e7e9ee; --muted: #9aa1ad; --line: #2c313b;
          --accent: #6d95ea; --plus: #4cc38a; --minus: #f08a5d; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; font-size: 15px; }
a { color: var(--accent); text-decoration: none; }
.top { display: flex; align-items: center; gap: 16px; padding: 12px 16px; background: var(--panel);
       border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 28px 0 10px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.back { margin: 6px 0 0; font-size: 13px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.card .label { font-size: 12px; color: var(--muted); }
.card .value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.chart { position: relative; height: 280px; background: var(--panel); border: 1px solid var(--line);
         border-radius: 10px; padding: 10px; }
.chart.tall { height: 360px; }
.table-wrap { overflow-x: auto; margin-top: 10px; background: var(--panel); border: 1px solid var(--line);
              border-radius: 10px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.compact td, table.compact th { padding: 6px 8px; font-size: 13px; }
tr.excluded td { opacity: 0.5; }
.bars { list-style: none; padding: 0; margin: 0; background: var(--panel); border: 1px solid var(--line);
        border-radius: 10px; }
.bars li { display: grid; grid-template-columns: 8em 1fr 7em; align-items: center; gap: 10px; padding: 8px 12px;
           border-bottom: 1px solid var(--line); }
.bars li:last-child { border-bottom: none; }
.bars .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.bars .bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bars .bar span { display: block; height: 100%; background: var(--accent); }
.bars .num { text-align: right; font-variant-numeric: tabular-nums; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters select, .filters input, .filters button { font: inherit; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.filters input { flex: 1; min-width: 12em; }
@media (max-width: 600px) {
  .cards { grid-template-columns: 1fr; }
  .card .value { font-size: 18px; }
  .bars li { grid-template-columns: 6em 1fr 6em; }
}
.top nav { display: flex; gap: 4px; overflow-x: auto; }
.top nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.top nav a.active { background: var(--bg); color: var(--text); font-weight: 600; }
.top .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #fde68a; color: #713f12; white-space: nowrap; }
button.link { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.mock-note { background: #fff7d6; color: #6b4e00; border-bottom: 1px solid #f1e2a8; padding: 8px 16px; font-size: 13px;
             text-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.group { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; }
.group-head, .group-row { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; }
.group-head { font-weight: 700; border-bottom: 1px solid var(--line); }
.group-row + .group-row { border-top: 1px solid var(--line); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress span { display: block; height: 100%; background: var(--plus); }
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.controls label { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
                  font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.controls output { font-size: 20px; font-weight: 700; color: var(--text); }
.controls input { width: 100%; }
#expenses input { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px;
                  background: var(--panel); color: var(--text); }
button.add, #expenses button { margin-top: 8px; font: inherit; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
body.bare { display: grid; place-items: center; min-height: 100vh; }
.login { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px 28px;
         width: min(360px, calc(100vw - 32px)); text-align: center; }
.brand.big { font-size: 26px; font-weight: 800; }
.login .error { color: var(--minus); font-size: 13px; }
button.google { width: 100%; margin: 16px 0 8px; padding: 12px; font: inherit; font-weight: 600; border-radius: 10px;
                border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
button.google:hover { background: var(--bg); }
@media (max-width: 760px) {
  .grid2, .controls { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; }
  .top nav { order: 3; width: 100%; }
}
.card .compare { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.bars.compare-bars li { grid-template-columns: 8em 1fr 7em 5em 6em; }
.bars.compare-bars li.head { font-size: 12px; color: var(--muted); padding-top: 6px; padding-bottom: 6px; }
@media (max-width: 600px) {
  .bars.compare-bars li { grid-template-columns: 5.5em 1fr 5.5em 3.8em 3.8em; gap: 6px; }
  .bars.compare-bars li.head span:nth-child(5) { font-size: 10px; }
}
.bars.yoy-bars li { grid-template-columns: 8em 1fr 7em 7em 5em; }
.bars.yoy-bars li.head { font-size: 12px; color: var(--muted); padding-top: 6px; padding-bottom: 6px; }
.bars .pair { display: flex; flex-direction: column; gap: 3px; }
.bars .bar.last span { background: #c9ced6; }
@media (max-width: 600px) {
  .bars.yoy-bars li { grid-template-columns: 5.5em 1fr 5em 5em 3.8em; gap: 6px; font-size: 13px; }
}
h2.first { margin-top: 4px; }
h3 { font-size: 14px; margin: 16px 0 8px; padding-left: 8px; border-left: 3px solid var(--accent); }
.kv { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.kv > div { display: flex; justify-content: space-between; padding: 10px 14px; }
.kv > div + div { border-top: 1px solid var(--line); }
.more { text-align: right; margin: 8px 0 0; font-size: 13px; }
.total { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; background: var(--panel);
         border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.total .amount { font-size: 24px; font-weight: 800; }
.table-wrap table th { color: var(--text); font-size: 13px; font-weight: 600; }
.controls.one { grid-template-columns: minmax(0, 360px); }
#accounts input { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; text-align: right;
                  background: var(--panel); color: var(--text); }
#accounts tfoot th { color: var(--text); }
table.sticky thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
table.sticky td:first-child, table.sticky th:first-child { position: sticky; left: 0; background: var(--panel); }
tr.past td { background: var(--bg); }
details.recat summary { cursor: pointer; list-style: none; }
details.recat summary::-webkit-details-marker { display: none; }
details.recat summary::after { content: " ✎"; color: var(--muted); font-size: 12px; }
details.recat form { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
details.recat select, details.recat button:not(.link) { font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.edited { font-size: 11px; margin-left: 6px; padding: 1px 6px; border-radius: 99px; background: #dbe7ff; color: #1e4fb5; }
.small-multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.mini { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.mini-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.mini-chart { position: relative; height: 150px; }
.progress.inline { display: inline-block; width: 60px; height: 6px; margin: 0 6px 0 0; vertical-align: middle; }
code { font-size: 12px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.chart-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 28px 0 10px; }
.chart-head h2 { margin: 0; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.segmented button { font: inherit; font-size: 13px; padding: 5px 10px; border: none; background: none; color: var(--muted);
                    cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.active { background: var(--accent); color: #fff; }
.toggle { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.subnav { display: flex; gap: 4px; overflow-x: auto; padding: 6px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.subnav a { padding: 5px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; font-size: 14px; }
.subnav a.active { color: var(--accent); font-weight: 600; background: var(--panel); }
tr.active-row td { background: #eef3ff; }
.ai-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 16px; }
.ai-bar button.add { margin-top: 0; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 99px; margin-left: 4px; }
.tag.orange { background: #ffe4d1; color: #9a3412; }
.tag.gray { background: var(--line); color: var(--muted); }
.recat label { display: inline-flex; align-items: center; gap: 4px; }
form.inline-edit { display: inline-flex; gap: 4px; align-items: center; }
form.inline-edit input { width: 5.5em; font: inherit; font-size: 13px; padding: 3px 6px; text-align: right;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); }
form.inline-edit button { font: inherit; font-size: 12px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--accent); cursor: pointer; }
.add-target { margin-top: 12px; }
table.sortable th { cursor: pointer; user-select: none; }
table.sortable th .sort { color: var(--line); font-size: 11px; }
table.sortable th[data-dir] .sort { color: var(--accent); }
.inst-filter { font: inherit; font-size: 13px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); }
.error-box { background: #fde8e1; color: #9a3412; border: 1px solid #f5c2b0; border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-top: 12px; }
