:root {
  /* カテゴリ色（固定の割り当て。順位でなくカテゴリに付く）。検証済みパレット */
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100;
  --c5: #e87ba4; --c6: #008300; --c7: #4a3aa7; --c8: #e34948; --c0: #b9b6ae;
  --bg: #f7f6f3;
  --fg: #1b1b1a;
  --muted: #76746e;
  --rule: #dddad3;
  --bar: #2f4f46;
  --bar-in: #a3672a;
  --accent: #2f4f46;
  --danger: #b03a2e;
  --surface: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151515;
    --fg: #ecebe7;
    --muted: #9a978f;
    --rule: #2d2c2a;
    --bar: #8fb8a8;
    --bar-in: #d9a066;
    --accent: #8fb8a8;
    --danger: #e0786c;
    --surface: #1e1e1d;
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
    --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767; --c0: #5c5a55;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151515; --fg: #ecebe7; --muted: #9a978f; --rule: #2d2c2a;
  --bar: #8fb8a8; --bar-in: #d9a066; --accent: #8fb8a8; --danger: #e0786c; --surface: #1e1e1d;
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
  --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767; --c0: #5c5a55;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-feature-settings: "palt";
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 32px);
  max-width: 720px;
  margin-inline: auto;
}
button, input, select { font: inherit; color: inherit; }
.num, dd, .amt { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ログイン */
.login { min-height: 80vh; display: grid; place-content: center; gap: 24px; }
.login h1 { font-size: 22px; font-weight: 600; letter-spacing: .1em; margin: 0; }
.login form { display: grid; gap: 8px; width: min(280px, 80vw); }
.login label { font-size: 13px; color: var(--muted); }

input, select {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 8px 10px;
  width: 100%;
}
button {
  background: none; border: 1px solid var(--rule); border-radius: 4px;
  padding: 8px 14px; cursor: pointer;
}
button.primary, .login button, #csv-form button { background: var(--accent); border-color: var(--accent); color: var(--bg); }
button.danger { color: var(--danger); border-color: transparent; padding-inline: 0; }
.error { color: var(--danger); font-size: 13px; min-height: 1.4em; margin: 0; }

/* ヘッダ */
.top { display: flex; align-items: center; justify-content: space-between; padding: 20px 0 8px; }
.top h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: .04em; }
.nav { border: none; font-size: 24px; line-height: 1; padding: 4px 12px; color: var(--muted); }

.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--rule); margin-bottom: 24px; }
.tabs button { border: none; border-radius: 0; padding: 10px 0; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--fg); }

h2 { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .08em; margin: 40px 0 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

/* 合計 */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; border-block: 1px solid var(--rule); }
.totals div { padding: 16px 0; }
.totals div + div { border-left: 1px solid var(--rule); padding-left: 16px; }
.totals dt { font-size: 12px; color: var(--muted); }
.totals dd { margin: 2px 0 0; font-size: clamp(17px, 5vw, 24px); font-weight: 600; letter-spacing: -.01em; }
.neg { color: var(--danger); }

/* カテゴリ */
.cats { list-style: none; margin: 0; padding: 0; }
.cats li { border-bottom: 1px solid var(--rule); }
.cats button {
  width: 100%; border: none; border-radius: 0; padding: 10px 0 8px; text-align: left;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
}
.cats .bar { grid-column: 1 / -1; height: 3px; background: var(--rule); position: relative; }
.cats .bar i { position: absolute; inset: 0 auto 0 0; background: var(--bar); }
.cats.income .bar i { background: var(--bar-in); }
.cats .n { color: var(--muted); font-size: 12px; margin-left: 6px; }
.cats.plain li { display: flex; justify-content: space-between; padding: 10px 0; }
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }

/* 推移 */
.trend { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; align-items: end; height: 140px; border-bottom: 1px solid var(--rule); }
.trend .col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 2px; }
.trend .bars { display: flex; gap: 2px; align-items: flex-end; height: 100px; }
.trend .bars i { width: 10px; background: var(--bar); display: block; }
.trend .bars i.in { background: var(--bar-in); }
.trend .lab { font-size: 11px; color: var(--muted); }
.trend .col.cur .lab { color: var(--fg); font-weight: 600; }
.legend { font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 8px; height: 8px; margin: 0 4px 0 10px; background: var(--bar); }
.legend i.in { background: var(--bar-in); }

/* 明細 */
.filter { display: flex; justify-content: space-between; align-items: center; padding: 8px 0 16px; }
.day { margin-top: 20px; }
.day h3 { font-size: 12px; color: var(--muted); font-weight: 500; margin: 0; padding-bottom: 4px; border-bottom: 1px solid var(--fg); display: flex; justify-content: space-between; }
.tx { width: 100%; border: none; border-bottom: 1px solid var(--rule); border-radius: 0; padding: 10px 0; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 0 12px; }
.tx .m { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .s { font-size: 12px; color: var(--muted); grid-column: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 500; }
.tx.in .amt { color: var(--bar-in); }
.tx.transfer { opacity: .5; }
.tx .uncat { color: var(--danger); }
.add { margin-top: 24px; width: 100%; border-style: dashed; color: var(--muted); }

/* 取り込み */
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.result { font-size: 13px; white-space: pre-wrap; }
.inbox { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.inbox li { border-bottom: 1px solid var(--rule); padding: 8px 0; display: grid; grid-template-columns: 1fr auto; gap: 0 8px; }
.inbox .st { font-size: 11px; color: var(--muted); }
.inbox .st.error { color: var(--danger); }
.inbox .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox .note { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }

/* ダイアログ */
dialog {
  border: none; border-radius: 8px; padding: 20px; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--fg);
}
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
dialog label.check { display: flex; gap: 8px; align-items: center; }
dialog label.check input { width: auto; }
.ed-merchant { font-size: 17px; font-weight: 600; margin: 0; }
.ed-meta, .ed-detail { color: var(--muted); font-size: 13px; margin: 0; }
.actions { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; margin-top: 8px; }

/* 取り込み失敗の通知 */
.alert { margin: 0 0 16px; }
.alert button { width: 100%; text-align: left; border: none; border-left: 3px solid var(--danger); border-radius: 0; background: none; color: var(--danger); padding: 8px 12px; font-size: 13px; }
.inbox .st.received { color: var(--danger); }

/* 読み込み中は前の月の数字だと分かるように薄くする */
body.loading .view { opacity: .4; transition: opacity .15s; }

/* 資産 */
.totals.one { grid-template-columns: 1fr; }
.totals.one dd { font-size: clamp(26px, 8vw, 34px); }
.accounts { list-style: none; margin: 0; padding: 0; }
.accounts li { border-bottom: 1px solid var(--rule); }
.accounts button { width: 100%; border: none; border-radius: 0; padding: 10px 0; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 0 12px; }
.accounts .s { font-size: 12px; color: var(--muted); }
.accounts .amt { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 500; }
.accounts .neg, .cats .neg { color: var(--danger); }
.trend.asset { grid-template-columns: repeat(12, 1fr); gap: 4px; }
.trend.asset .bars i { width: 100%; min-width: 6px; }
.trend.asset .bars { width: 100%; justify-content: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.holdings { list-style: none; padding: 0; margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.holdings li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }

/* 前月比 */
.diff { display: block; font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 2px; letter-spacing: 0; }
.cats .diff { display: inline; margin: 0 0 0 8px; }

/* 概要の資産合計 */
.asset-line { width: 100%; border: none; border-bottom: 1px solid var(--rule); border-radius: 0; padding: 14px 0; display: flex; justify-content: space-between; align-items: baseline; text-align: left; }
.asset-line .lab { font-size: 12px; color: var(--muted); }
.asset-line .val { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

/* カテゴリ構成バー：区切りは2pxの地色ギャップ */
.stack { display: flex; gap: 2px; height: 14px; margin: 4px 0 12px; }
.stack i { display: block; height: 100%; min-width: 2px; }
.stack i:first-child { border-radius: 4px 0 0 4px; }
.stack i:last-child { border-radius: 0 4px 4px 0; }
.stack i:only-child { border-radius: 4px; }
.cats .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 8px; vertical-align: 1px; }
.cats .bar i { border-radius: 0 2px 2px 0; }

/* 取り込み状況 */
.sources { list-style: none; margin: 0; padding: 0; }
.sources li { border-bottom: 1px solid var(--rule); padding: 10px 0; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.sources .nm { font-weight: 500; }
.sources .md { font-size: 12px; color: var(--muted); text-align: right; }
.sources .st { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.sources .st.due { color: var(--danger); }
.sources .how { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.sources li.auto .how { display: none; }
.sources li.auto.note .how { display: block; }
