:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #e5e5ea;
  --accent: #0a84ff;
  --accent-text: #ffffff;
  --good: #1f9d55;
  --bad: #d93025;
  --warn: #b26a00;
  --warn-bg: #fff4e0;
  --bad-bg: #fde8e6;
  --good-bg: #e6f6ec;
  --tab-h: 64px;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1b2b;
    --card: #14283b;
    --text: #f2f2f7;
    --muted: #9aa5b1;
    --line: #23384d;
    --accent: #4da3ff;
    --good: #4cd964;
    --bad: #ff6b60;
    --warn: #ffb74d;
    --warn-bg: #3a2c12;
    --bad-bg: #3d1f1d;
    --good-bg: #17352a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; word-break: break-all; }
small { color: var(--muted); font-size: 0.8em; display: block; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.3px; }
h2 { font-size: 17px; margin: 0 0 10px; display: flex; align-items: center; justify-content: space-between; }
p { margin: 0 0 10px; }

.app { padding: calc(var(--safe-top) + 8px) 14px calc(var(--safe-bottom) + 16px); max-width: 640px; margin: 0 auto; }
.view { display: block; padding-bottom: 8px; }
body:has(.tabbar) .view { padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 12px); }

.center { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 40vh; gap: 12px; color: var(--muted); }
.center.small { min-height: 80px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
.spinner.small { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.card.total { text-align: center; }
.card .big { font-size: 40px; font-weight: 700; letter-spacing: -1px; margin: 4px 0; }
.card .big small { display: inline; font-size: 16px; color: var(--muted); font-weight: 500; }
.card .sub { color: var(--muted); font-size: 14px; }
.stats { display: flex; justify-content: center; gap: 24px; margin-top: 14px; }
.stats > div { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--muted); }
.stats strong { color: var(--text); font-size: 16px; }

.hero { text-align: center; padding: 24px 8px 6px; }
.hero .logo { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 20px; background: var(--accent); color: white; display: flex; align-items: center; justify-content: center; }
.hero .logo .ico svg { width: 36px; height: 36px; }
.hero p { color: var(--muted); font-size: 15px; }

.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.steps li { flex: 1; display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px; background: var(--card); }
.steps li span { width: 20px; height: 20px; border-radius: 50%; background: var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }
.steps li.active { color: var(--text); font-weight: 600; }
.steps li.active span, .steps li.done span { background: var(--accent); color: white; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form.inline { flex-direction: row; flex-wrap: wrap; }
.form.inline input { flex: 1 1 120px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); }
input, select, textarea {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); font-size: 16px;
}
input[type="checkbox"] { width: 20px; height: 20px; padding: 0; accent-color: var(--accent); }
textarea { resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--bad); font-size: 14px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.notice { padding: 10px 12px; border-radius: 12px; background: var(--bg); font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.error { background: var(--bad-bg); color: var(--bad); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-weight: 600; font-size: 15px; min-height: 44px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.link { border: none; background: transparent; color: var(--accent); padding: 8px; min-height: 36px; }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 14px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.iconbtn { border: none; background: transparent; padding: 8px; border-radius: 10px; color: var(--accent); display: inline-flex; min-width: 44px; min-height: 44px; align-items: center; justify-content: center; }
.iconbtn:disabled { color: var(--muted); opacity: 0.5; }
.iconbtn.spin .ico svg { animation: spin 1s linear infinite; }
.ico { display: inline-flex; }
.ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.segmented { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.segmented button { flex: 1; border: none; background: transparent; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.1); }

.page-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 4px; }
.head-right { display: flex; gap: 4px; }

.strip { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-radius: 12px; font-size: 14px; margin: 8px 0; background: var(--good-bg); color: var(--good); }
.strip.warn { background: var(--warn-bg); color: var(--warn); }
.strip.bad { background: var(--bad-bg); color: var(--bad); }
.strip .btn { flex-shrink: 0; }

.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 6px 0; }
.monthnav strong { font-size: 17px; text-transform: capitalize; }

.kv { display: flex; flex-direction: column; gap: 8px; font-size: 14px; margin-bottom: 10px; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.kv > div:last-child { border-bottom: none; }
.kv span { color: var(--muted); flex-shrink: 0; }
.kv strong { font-weight: 600; text-align: right; word-break: break-word; }
.kv.small { font-size: 13px; }

.txlist, .plain, .catlist, .legend { list-style: none; margin: 0; padding: 0; }
.tx { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.tx:last-child { border-bottom: none; }
.tx.excl { opacity: 0.5; }
.tx-main { flex: 1; min-width: 0; }
.tx-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-name.big { font-size: 18px; white-space: normal; }
.tx-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.tx-amt.big { font-size: 20px; }
.tx-amt.foreign { color: var(--muted); }
.tx-amt small { text-align: right; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; display: inline-block; }

.plain li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.plain li[data-action] { cursor: pointer; }
.plain li:last-child { border-bottom: none; }
.plain .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.plain .val { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.plain .val small { display: inline; }

.donut-wrap { display: flex; align-items: center; gap: 16px; }
.donut { flex-shrink: 0; }
.donut .center-top { font-size: 11px; font-weight: 700; text-anchor: middle; fill: var(--text); }
.donut .center-bottom { font-size: 7px; text-anchor: middle; fill: var(--muted); text-transform: capitalize; }
.legend { flex: 1; min-width: 0; font-size: 13px; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto auto; gap: 8px; align-items: center; padding: 4px 0; }
.legend .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .val { font-variant-numeric: tabular-nums; }
.legend .pct { color: var(--muted); width: 34px; text-align: right; }

.chart { width: 100%; display: block; overflow: visible; }
.chart.bars rect { fill: var(--line); }
.chart.bars .active rect { fill: var(--accent); }
.chart.bars text { fill: var(--muted); font-size: 4.2px; text-anchor: middle; }
.chart.bars .val { font-size: 3.6px; }
.chart.bars .active text { fill: var(--text); font-weight: 600; }

.catlist li { padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.catlist li:last-child { border-bottom: none; }
.catlist .row { display: flex; align-items: center; gap: 8px; }
.catlist .row .lbl { flex: 1; }
.catlist .row .val { font-weight: 600; font-variant-numeric: tabular-nums; }
.catlist .row.small { font-size: 12px; color: var(--muted); justify-content: space-between; padding-left: 20px; margin-top: 2px; }
.meter-wrap { margin-top: 16px; text-align: left; }
.meter-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.meter { height: 6px; background: var(--bg); border-radius: 3px; margin: 6px 0 0 20px; overflow: hidden; }
.meter-wrap .meter { margin-left: 0; height: 8px; }
.meter span { display: block; height: 100%; border-radius: 3px; }

.filters { display: flex; gap: 8px; margin: 6px 0; }
.filters .search { flex: 1; }
.filters select { flex: 0 0 46%; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: white; }
.list-summary { color: var(--muted); font-size: 13px; padding: 4px 2px 8px; }
.daygroup { background: var(--card); border-radius: var(--radius); padding: 6px 14px; margin-bottom: 10px; }
.dayhead { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 8px 0 2px; font-weight: 600; text-transform: capitalize; }
.empty { color: var(--muted); text-align: center; padding: 16px 8px; font-size: 14px; }

.insight { border-left: 4px solid var(--line); }
.insight.warn { border-left-color: var(--bad); }
.insight.tip { border-left-color: var(--accent); }
.insight.info { border-left-color: var(--muted); }
.insight h2 { display: block; }
.insight p { color: var(--muted); font-size: 14px; }
.saving { margin-top: 10px; font-size: 14px; color: var(--good); }
.plan { margin: 10px 0 0; padding-left: 22px; }
.plan li { margin: 0 0 12px; font-size: 15px; display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.plan em { font-style: normal; color: var(--good); font-weight: 600; white-space: nowrap; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 8px 0; }

.copyrow { display: flex; gap: 8px; }
.copyrow input { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tab-h) + var(--safe-bottom));
  padding: 6px 4px var(--safe-bottom); display: flex; justify-content: space-around; background: var(--card);
  border-top: 1px solid var(--line); z-index: 20;
}
.tab { flex: 1; border: none; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; padding: 4px 0; }
.tab.active { color: var(--accent); }
.tab .ico svg { width: 24px; height: 24px; }

.toast { position: fixed; top: calc(var(--safe-top) + 10px); left: 14px; right: 14px; z-index: 40; padding: 12px 14px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,0.2); animation: fade 0.2s ease-out; }
.toast.error { background: var(--bad); color: white; }
.toast.ok { background: var(--good); color: white; }
@keyframes fade { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: white; text-align: center; padding: 20px; }
.sync-banner { position: sticky; top: var(--safe-top); z-index: 15; display: flex; align-items: center; gap: 10px; background: var(--accent); color: white; padding: 10px 14px; border-radius: 12px; font-size: 14px; margin: 4px 0 8px; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 30; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--card); border-radius: 20px 20px 0 0; padding: 16px 16px calc(var(--safe-bottom) + 16px); z-index: 31; animation: up 0.25s ease-out; max-width: 640px; margin: 0 auto; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.about p { color: var(--muted); font-size: 13px; }
