:root {
  --bg:        #F5F2EC;
  --surface:   #FFFFFF;
  --surface-2: #FBF9F5;
  --ink:       #2E2E2C;
  --muted:     #7C7871;
  --line:      #E4DFD5;
  --line-soft: #EFEBE3;
  --income:    #5F8F73;
  --income-bg: #E8F0EA;
  --expense:   #B5726C;
  --expense-bg:#F6E9E8;
  --goal:      #9A7B4B;
  --goal-bg:   #F4EDE1;
  --accent:    #4F6F7E;
  --warn:      #B8863B;
  --scenario:  #8A7CA8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(46,46,44,.05), 0 4px 16px rgba(46,46,44,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #1B1A19;
    --surface:   #242322;
    --surface-2: #2B2A28;
    --ink:       #EDEAE4;
    --muted:     #9C978E;
    --line:      #3A3835;
    --line-soft: #322F2C;
    --income:    #86BE9C;
    --income-bg: #22302A;
    --expense:   #DB9A94;
    --expense-bg:#332524;
    --goal:      #D6B27A;
    --goal-bg:   #322B1F;
    --accent:    #8FB4C4;
    --warn:      #DCAE63;
    --scenario:  #B4A6D2;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
               "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: 76px; }

a { color: var(--accent); }

/* ── ヘッダ ─────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.appbar h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: .02em; }
.appbar .sub { color: var(--muted); font-size: 12px; margin-left: auto; }
.appbar .sub a { color: var(--muted); text-decoration: none; }

.wrap { max-width: 940px; margin: 0 auto; padding: 14px; }

/* ── ナビ ───────────────────────────────── */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 7px;
  font-size: 10px; text-decoration: none; color: var(--muted);
  border-top: 2px solid transparent;
}
.nav a .ico { font-size: 17px; line-height: 1; }
.nav a.on { color: var(--accent); border-top-color: var(--accent); }

/* ── カード ─────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card > h2 {
  margin: 0 0 10px;
  font-size: 13px; font-weight: 650; letter-spacing: .04em;
  color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.card > h2 .right { margin-left: auto; font-weight: 500; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .grid3 { grid-template-columns: 1fr 1fr; } }

/* ── 数字 ───────────────────────────────── */
.num  { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.big  { font-size: 30px; font-weight: 640; letter-spacing: -.02em; line-height: 1.15; }
.mid  { font-size: 20px; font-weight: 620; }
.yen::after { content: "円"; font-size: .62em; font-weight: 500; margin-left: 2px; opacity: .7; }
.income  { color: var(--income); }
.expense { color: var(--expense); }
.muted   { color: var(--muted); }
.small   { font-size: 12px; }
.tiny    { font-size: 11px; }

/* ── ゴールゲージ ───────────────────────── */
.goalbox { background: var(--goal-bg); border-color: color-mix(in srgb, var(--goal) 30%, transparent); }
.gauge { height: 12px; border-radius: 99px; background: var(--line-soft); overflow: hidden; margin: 10px 0 6px; position: relative; }
.gauge > i { display: block; height: 100%; border-radius: 99px; background: var(--goal); transition: width .4s ease; }
.gauge > i.ok { background: var(--income); }
.gauge > i.ng { background: var(--expense); }

/* ── バッジ ─────────────────────────────── */
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 99px;
  font-size: 11px; font-weight: 600; line-height: 1.7;
  background: var(--line-soft); color: var(--muted);
  white-space: nowrap;
}
.badge.inc { background: var(--income-bg);  color: var(--income); }
.badge.exp { background: var(--expense-bg); color: var(--expense); }
.badge.sc  { background: color-mix(in srgb, var(--scenario) 18%, transparent); color: var(--scenario); }
.badge.act { background: var(--goal-bg); color: var(--goal); }

/* ── テーブル ───────────────────────────── */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 9px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th { font-size: 11px; font-weight: 620; color: var(--muted); letter-spacing: .03em; background: var(--surface-2); position: sticky; top: 0; }
td.r, th.r { text-align: right; }
tr.past td { color: var(--muted); }
tr.cur td { background: color-mix(in srgb, var(--accent) 7%, transparent); font-weight: 600; }
tr.goalrow td { background: var(--goal-bg); font-weight: 650; }
tbody tr:hover td { background: var(--surface-2); }

/* ── フォーム ───────────────────────────── */
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 3px; font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=month],
input[type=password], input[type=file], select, textarea {
  width: 100%; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface-2); color: var(--ink);
  font-size: 15px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
textarea { min-height: 60px; resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 130px; min-width: 0; }
.chk { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink); margin: 10px 0 0; font-weight: 500; }
.chk input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink);
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--line-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger  { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 40%, transparent); background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; align-items: center; }

/* ── フラッシュ ─────────────────────────── */
.flash {
  padding: 10px 13px; border-radius: 10px; margin-bottom: 12px; font-size: 13px; font-weight: 550;
  background: var(--income-bg); color: var(--income);
  border: 1px solid color-mix(in srgb, var(--income) 25%, transparent);
}
.flash.err { background: var(--expense-bg); color: var(--expense); border-color: color-mix(in srgb, var(--expense) 25%, transparent); }
.flash.warn{ background: var(--goal-bg);    color: var(--warn);    border-color: color-mix(in srgb, var(--warn) 25%, transparent); }

/* ── 明細行 ─────────────────────────────── */
.list { list-style: none; margin: 0; padding: 0; }
.list > li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line-soft);
}
.list > li:last-child { border-bottom: 0; }
.list .name { flex: 1; min-width: 0; }
.list .name b { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 620; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

details.item { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--surface); }
details.item > summary {
  padding: 10px 12px; cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 9px;
}
details.item > summary::-webkit-details-marker { display: none; }
details.item > .body { padding: 0 12px 12px; border-top: 1px solid var(--line-soft); }

.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 2.5px; border-radius: 2px; display: inline-block; }

.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 13px; }
hr.sep { border: 0; border-top: 1px solid var(--line-soft); margin: 14px 0; }
.pill-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.pill-tabs a {
  padding: 5px 13px; border-radius: 99px; font-size: 13px; text-decoration: none;
  border: 1px solid var(--line); color: var(--muted); background: var(--surface); white-space: nowrap;
}
.pill-tabs a.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
