:root {
  color-scheme: light;
  --page: #f5f3ee;
  --surface: #fcfcfb;
  --surface-2: #f0eee8;
  --ink: #1d1c19;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e7e5de;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, .08);
  --shadow: 0 1px 2px rgba(20, 18, 12, .04), 0 8px 24px -12px rgba(20, 18, 12, .10);
  --good: #006300;
  --bad: #b3261e;
  --wash: rgba(29, 28, 25, .05);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s-other: #a9a79f;
  --radius: 18px;
  --font: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Segoe UI", "Microsoft YaHei", sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, .08);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
  --good: #0ca30c;
  --bad: #e66767;
  --wash: rgba(255, 255, 255, .06);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s-other: #6b6a65;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; font-weight: 400; }
.accent-good { color: var(--good); }
:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; border-radius: 8px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .02em; font-size: 16px; }
.brand-mark { width: 28px; height: 28px; border-radius: 9px; background: var(--ink); display: flex; align-items: flex-end; justify-content: center; gap: 3px; padding: 6px; }
.brand-mark i { width: 4px; border-radius: 2px; background: var(--page); }
.brand-mark i:nth-child(1) { height: 45%; } .brand-mark i:nth-child(2) { height: 100%; } .brand-mark i:nth-child(3) { height: 30%; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 18px; gap: 6px; padding: 12px; margin: 0 auto 18px; }
.brand-mark.big i { width: 7px; border-radius: 4px; }

/* ---------- boot ---------- */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot .brand-mark { margin: 0; animation: breathe 1.2s ease-in-out infinite; }
.boot .brand-mark i { animation: bars 1.2s ease-in-out infinite; transform-origin: bottom; }
.boot .brand-mark i:nth-child(2) { animation-delay: .15s; } .boot .brand-mark i:nth-child(3) { animation-delay: .3s; }
@keyframes bars { 50% { transform: scaleY(.55); } }
@keyframes breathe { 50% { opacity: .75; } }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(360px, 100%); text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 40px 28px 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: .04em; }
.login-card p { margin: 0 0 24px; font-size: 13.5px; }
.field input { width: 100%; height: 48px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); padding: 0 16px; font-size: 16px; outline: none; transition: border-color .15s, background .15s; }
.field input:focus { border-color: var(--ink-2); background: var(--surface); }
.login-card .btn { margin-top: 14px; }
.login-err { min-height: 20px; color: var(--bad); font-size: 13px; margin: 12px 0 0 !important; }

/* ---------- buttons ---------- */
.btn { height: 44px; padding: 0 18px; border-radius: 13px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .1s, background .15s, opacity .15s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--ink); color: var(--page); }
.btn.ghost { background: var(--wash); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { height: 38px; min-width: 38px; padding: 0 10px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--ink-2); font-size: 13.5px; transition: background .15s; }
.icon-btn:hover { background: var(--wash); color: var(--ink); }
.icon-btn.busy svg { animation: spin 1.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- top bar ---------- */
.topbar { max-width: 1280px; margin: 0 auto; padding: 18px 24px 8px; display: flex; align-items: center; justify-content: space-between; padding-top: max(18px, env(safe-area-inset-top)); }
.top-actions { display: flex; gap: 2px; }

/* ---------- filter bar ---------- */
.filterbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--page) 86%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid transparent; transition: border-color .2s; }
.filterbar.stuck { border-bottom-color: var(--border); }
.filter-inner { max-width: 1280px; margin: 0 auto; padding: 10px 24px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--wash); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { height: 32px; padding: 0 14px; border-radius: 9px; font-size: 14px; color: var(--ink-2); white-space: nowrap; transition: background .15s, color .15s; }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--border); }
.seg button:disabled { opacity: .35; cursor: default; }
.seg.small button { height: 28px; padding: 0 10px; font-size: 13px; }
.stepper { display: inline-flex; align-items: center; gap: 2px; }
.stepper .step { width: 32px; height: 32px; border-radius: 10px; font-size: 20px; line-height: 1; color: var(--ink-2); }
.stepper .step:hover { background: var(--wash); }
.stepper .step:disabled { opacity: .3; cursor: default; background: none; }
.period-label { font-weight: 650; font-size: 15px; padding: 0 6px; min-width: 104px; text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
.custom-range { display: inline-flex; align-items: center; gap: 6px; }
.custom-range input { height: 34px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); padding: 0 8px; font-size: 14px; }
.filter-pills { display: flex; gap: 8px; margin-left: auto; }
.pill { height: 34px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; max-width: 220px; }
.pill span { color: var(--muted); }
.pill b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.active { border-color: var(--ink); }
.active-chips { max-width: 1280px; margin: 0 auto; padding: 0 24px; display: flex; flex-wrap: wrap; gap: 6px; }
.active-chips:not(:empty) { padding-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 6px 0 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; }
.chip .x { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.chip .x:hover { background: var(--wash); color: var(--ink); }
.chip.clear { background: none; border-style: dashed; padding-right: 10px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ---------- grid ---------- */
.grid { max-width: 1280px; margin: 0 auto; padding: 12px 24px 24px; display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .01em; }
.head-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kpi-hero { grid-column: span 5; display: flex; flex-direction: column; justify-content: center; padding: 24px 26px; background: var(--ink); color: var(--page); border: 0; position: relative; overflow: hidden; }
.kpi-hero::after { content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.10), transparent 70%); }
:root[data-theme="dark"] .kpi-hero { background: #f0efec; color: #121211; }
.kpi-hero .kpi-label { color: inherit; opacity: .62; }
.hero-num { font-size: clamp(36px, 5vw, 52px); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin: 6px 0 10px; }
.hero-num .yen { font-size: .55em; font-weight: 600; margin-right: 2px; opacity: .7; }
.delta { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; align-self: flex-start; background: rgba(127,127,127,.18); }
.delta:empty { display: none; }
.hero-sub { font-size: 13px; opacity: .62; margin-top: 10px; }
.kpis { grid-column: span 7; display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.kpi { padding: 18px 20px; display: flex; flex-direction: column; justify-content: center; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-num { font-size: 26px; font-weight: 680; letter-spacing: -.01em; margin-top: 2px; }
.kpi-num small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.trend { grid-column: span 8; }
.pie { grid-column: span 4; }
.list-card { grid-column: span 4; }
.tx-card { grid-column: span 12; }
.chart { width: 100%; height: 300px; }
.pie .chart { height: 330px; }
.hint { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- rank lists ---------- */
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rank li { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; padding: 8px 8px; margin: 0 -8px; border-radius: 12px; cursor: pointer; transition: background .12s, opacity .15s; }
.rank li:hover { background: var(--wash); }
.rank li.dim { opacity: .42; }
.rank li.sel { background: var(--wash); }
.rank .ico { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; font-size: 16px; background: var(--surface-2); position: relative; }
.rank .ico .dot { position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border: 2px solid var(--surface); border-radius: 50%; }
.rank .name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .bar { height: 4px; border-radius: 2px; background: var(--grid); margin-top: 5px; overflow: hidden; }
.rank .bar i { display: block; height: 100%; border-radius: 2px; }
.rank .val { text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 600; }
.rank .val .pct { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.rank .card-ico { font-size: 10px; font-weight: 700; letter-spacing: .02em; color: var(--ink-2); }
.rank-empty { color: var(--muted); font-size: 13.5px; padding: 18px 0; text-align: center; }

/* ---------- transactions ---------- */
.search { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border-radius: 11px; background: var(--wash); }
.search svg { width: 16px; height: 16px; color: var(--muted); }
.search input { border: 0; background: none; outline: none; width: 150px; font-size: 14px; }
.tx-list { display: flex; flex-direction: column; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 4px 6px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--grid); position: sticky; top: var(--fb-h, 56px); background: var(--surface); z-index: 1; }
.day-head b { color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.tx { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--grid); cursor: pointer; }
.tx:hover { background: var(--wash); }
.tx:last-child { border-bottom: 0; }
.tx .ico { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-size: 17px; }
.tx .t1 { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .t2 { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; font-size: 15px; }
.tx .amt.neg { color: var(--good); }
.tx .amt small { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 6px; background: var(--wash); color: var(--ink-2); margin-left: 6px; vertical-align: 1px; }
#moreBtn { margin-top: 12px; }
.foot { max-width: 1280px; margin: 0 auto; padding: 0 24px 40px; text-align: center; }

/* ---------- sheet / dialog ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 10, 8, .38); z-index: 40; animation: fade .18s ease; }
:root[data-theme="dark"] .scrim { background: rgba(0, 0, 0, .62); }
:root[data-theme="dark"] .sheet { border: 1px solid var(--border); }
.sheet { position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100vw - 32px)); max-height: min(82vh, 760px); overflow: auto; background: var(--surface); border-radius: 22px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.4); animation: pop .2s cubic-bezier(.2,.9,.3,1.2); }
.sheet-grip { display: none; }
.sheet-body { padding: 24px; }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.sheet .sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.sheet-section { margin-top: 18px; }
.sheet-section h4 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 500; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.opt { display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border); font-size: 14px; text-align: left; transition: background .12s, border-color .12s; }
.opt:hover { background: var(--wash); }
.opt.on { border-color: var(--ink); background: var(--wash); font-weight: 600; }
.opt .em { font-size: 16px; }
.opt .cnt { margin-left: auto; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.opt-list { display: flex; flex-direction: column; gap: 6px; }
.opt-list .opt { height: auto; min-height: 48px; padding: 8px 12px; }
.opt-list .opt .l2 { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.sheet-actions { display: flex; gap: 10px; margin-top: 22px; }
.sheet-actions .btn { flex: 1; }
.kv { display: grid; grid-template-columns: 84px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.big-amt { font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 14px; }
.drop { border: 1.5px dashed var(--axis); border-radius: 16px; padding: 30px 16px; text-align: center; transition: background .15s, border-color .15s; cursor: pointer; }
.drop.over { background: var(--wash); border-color: var(--ink); }
.drop svg { width: 34px; height: 34px; color: var(--muted); }
.drop p { margin: 8px 0 0; color: var(--ink-2); font-size: 14px; }
.drop .muted { font-size: 12.5px; margin-top: 4px; }
.result-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--grid); font-size: 13.5px; }
.result-row .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-row b { color: var(--good); }
.progress { height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; margin-top: 8px; }
.progress i { display: block; height: 100%; background: var(--ink); border-radius: 3px; transition: width .3s; }
.src-badge { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--wash); color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--page); padding: 10px 18px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%) scale(.97); } }
@keyframes up { from { transform: translateY(100%); } }

/* ---------- view switch ---------- */
.view-seg { margin-left: 14px; }
.view-seg button { height: 30px; padding: 0 14px; font-size: 14px; }

/* ---------- income ---------- */
.span12 { grid-column: span 12; }
.inc-filter { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 2px 0; }
.inc-filter .period-label { min-width: 0; }
.inc-count { margin-left: auto; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi-label .dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 2px; vertical-align: 1px; }
.flow-stats { display: flex; gap: 22px; flex-wrap: wrap; }
.flow-stats div { display: flex; flex-direction: column; }
.flow-stats span { font-size: 12px; color: var(--muted); }
.flow-stats b { font-size: 16px; font-weight: 680; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.ytable { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; min-width: 760px; }
.ytable th, .ytable td { padding: 11px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.ytable thead th { font-size: 12px; font-weight: 500; color: var(--muted); }
.ytable th:first-child { text-align: left; font-weight: 650; }
.ytable tbody tr { cursor: pointer; transition: background .12s; }
.ytable tbody tr:hover, .ytable tbody tr.sel { background: var(--wash); }
.ytable sup { color: var(--muted); margin-left: 1px; }
.ytable tbody tr:last-child th, .ytable tbody tr:last-child td { border-bottom: 0; }
.slip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.slip { text-align: left; padding: 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); transition: background .12s, transform .1s; }
.slip:hover { background: var(--wash); }
.slip:active { transform: scale(.98); }
.slip.bonus { border-color: color-mix(in srgb, var(--s2) 45%, transparent); }
.slip-top { display: flex; justify-content: space-between; align-items: center; }
.slip-m { font-weight: 650; font-size: 15px; }
.slip .tag { margin: 0; }
.slip.bonus .tag { background: color-mix(in srgb, var(--s2) 16%, transparent); }
.slip-net { font-size: 19px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.slip-sub { font-size: 12px; color: var(--muted); }
.slip .bar { height: 4px; border-radius: 2px; background: var(--grid); margin-top: 10px; overflow: hidden; }
.slip .bar i { display: block; height: 100%; border-radius: 2px; }
.slip-split { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: var(--wash); border-radius: 14px; padding: 12px 14px; }
.slip-split span { display: block; font-size: 12px; color: var(--muted); }
.slip-split b { font-variant-numeric: tabular-nums; }
.brow { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.brow em { font-style: normal; color: var(--muted); font-size: 12px; margin-left: 8px; }
.brow b { font-weight: 600; font-variant-numeric: tabular-nums; }
.brow.subtotal { color: var(--muted); font-size: 13px; padding-left: 12px; }
.brow.subtotal b { font-weight: 500; }
.brow.total { border-bottom: 0; font-weight: 650; }
.brow.total b { font-weight: 700; }
.empty-state { text-align: center; padding: 56px 20px; }
.empty-state h2 { margin: 0 0 6px; font-size: 18px; }
.empty-state p { margin: 0 0 18px; }

/* ---------- ledger ---------- */
.entry-card { grid-column: span 6; }
.rent-card { grid-column: span 6; }
.amt-field { display: flex; align-items: baseline; gap: 6px; border-bottom: 2px solid var(--grid); padding: 4px 2px 8px; margin-bottom: 16px; transition: border-color .15s; }
.amt-field:focus-within { border-color: var(--ink); }
.amt-field span { font-size: 26px; font-weight: 600; color: var(--muted); }
.amt-field input { border: 0; outline: none; background: none; font-size: 40px; font-weight: 700; letter-spacing: -.02em; width: 100%; min-width: 0; font-variant-numeric: tabular-nums; }
.amt-field.income input { color: var(--good); }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.lf { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.lf.grow { flex: 1; min-width: 140px; }
.lf > span { padding-left: 2px; }
.lf input { height: 40px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface-2); padding: 0 12px; font-size: 15px; color: var(--ink); outline: none; }
.lf input:focus { border-color: var(--ink-2); background: var(--surface); }
.lf input:disabled { opacity: .5; }
.chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; margin-top: 6px; }
.chip-grid .opt { height: 38px; font-size: 13.5px; padding: 0 10px; }
.method-seg { margin-top: 6px; }
.form-err { color: var(--bad); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 11px; }
.btn.danger { color: var(--bad); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.rent-form { background: var(--wash); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.rent-list { display: flex; flex-direction: column; gap: 8px; }
.rent-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px; border: 1px solid var(--border); border-radius: 14px; }
.rent-row.live { border-color: var(--ink-2); }
.rent-name { font-weight: 650; }
.rent-period { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.rent-amt { font-size: 20px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.rent-amt small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 2px; }
.rent-ops { grid-column: 1 / -1; display: flex; gap: 4px; justify-content: flex-end; margin-top: 2px; }
.rent-ops .icon-btn { height: 30px; font-size: 13px; }
.tx.editing { background: var(--wash); }
.lf select { height: 40px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface-2); padding: 0 10px; font-size: 15px; color: var(--ink); }
.lf textarea { border-radius: 11px; border: 1px solid var(--border); background: var(--surface-2); padding: 10px 12px; font: inherit; font-size: 14px; color: var(--ink); resize: vertical; outline: none; }
.lf textarea:focus { border-color: var(--ink-2); background: var(--surface); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.cat-tile { display: grid; grid-template-columns: 34px 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; text-align: left; padding: 10px 12px; border-radius: 13px; border: 1px solid var(--border); transition: background .12s; }
.cat-tile:hover { background: var(--wash); }
.cat-tile .em { grid-row: 1 / 3; width: 34px; height: 34px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 17px; }
.cat-tile .cat-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-tile .cat-name .tag { margin-left: 2px; }
.cat-tile .cat-meta { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-tile.add { border-style: dashed; color: var(--ink-2); }
.cat-edit-top { display: flex; gap: 12px; align-items: flex-end; }
.icon-input { width: 64px; height: 64px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface-2); text-align: center; font-size: 30px; outline: none; flex: none; }
.emoji-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 4px; margin-top: 12px; }
.emoji-pick button { height: 36px; border-radius: 9px; font-size: 18px; }
.emoji-pick button:hover { background: var(--wash); }

/* ---------- tablet ---------- */
@media (max-width: 1080px) {
  .kpi-hero, .kpis { grid-column: span 12; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .trend, .pie { grid-column: span 12; }
  .list-card { grid-column: span 6; }
  .list-card.merch-wide { grid-column: span 12; }
  .entry-card, .rent-card { grid-column: span 12; }
}

/* ---------- phone ---------- */
@media (max-width: 680px) {
  body { font-size: 14.5px; }
  .topbar { padding: 14px 16px 4px; padding-top: max(14px, env(safe-area-inset-top)); }
  .icon-btn .lbl { display: none; }
  .brand-name { display: none; }
  .view-seg { margin-left: 8px; }
  .view-seg button { padding: 0 11px; }
  .amt-field input { font-size: 34px; }
  .chip-grid { grid-template-columns: repeat(3, 1fr); }
  .cat-grid { grid-template-columns: repeat(2, 1fr); }
  .inc-count { margin-left: 0; width: 100%; }
  .flow-stats { gap: 14px; width: 100%; justify-content: space-between; }
  .flow-stats b { font-size: 14px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .slip-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-inner { padding: 8px 16px; gap: 8px; }
  .seg button { padding: 0 11px; }
  .filterbar .seg { flex: 1; }
  .filterbar .seg button { flex: 1; }
  .filterbar .seg { flex-basis: 100%; }
  .stepper { flex: 1; justify-content: space-between; min-width: 0; }
  .period-label { min-width: 0; font-size: 14.5px; }
  .custom-range { flex: 1 1 100%; }
  .custom-range input { flex: 1; min-width: 0; }
  .filter-pills { margin-left: 0; gap: 6px; }
  .custom-range:not([hidden]) ~ .filter-pills { width: 100%; }
  .custom-range:not([hidden]) ~ .filter-pills .pill { flex: 1; max-width: none; }
  .pill { padding: 0 10px; gap: 5px; max-width: 108px; }
  .active-chips { padding: 0 16px; }
  .grid { padding: 8px 12px 20px; gap: 12px; }
  .card { padding: 16px; border-radius: 16px; }
  .kpi-hero { padding: 20px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi { padding: 14px 16px; }
  .kpi-num { font-size: 21px; }
  .list-card { grid-column: span 12; }
  .chart { height: 260px; }
  .pie .chart { height: 280px; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .tx-card .head-tools { width: 100%; }
  .sheet { left: 0; right: 0; top: auto; bottom: 0; transform: none; width: 100%; max-height: 88vh; border-radius: 22px 22px 0 0; animation: up .25s cubic-bezier(.2,.9,.3,1); padding-bottom: env(safe-area-inset-bottom); }
  .sheet-grip { display: block; width: 38px; height: 5px; border-radius: 3px; background: var(--axis); margin: 10px auto 0; }
  .sheet-body { padding: 16px 18px 22px; }
  .opt-grid { grid-template-columns: repeat(2, 1fr); }
}

/* =========================================================
   导航外壳：电脑侧栏 / 手机底栏
   ========================================================= */
a { color: inherit; }
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100dvh; }
.sidenav { position: sticky; top: 0; height: 100dvh; padding: 20px 12px 16px; border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; }
.sidenav .brand { text-decoration: none; padding: 0 10px 14px; }
.sidenav nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: 11.5px; color: var(--muted); padding: 16px 12px 6px; letter-spacing: .1em; }
.sidenav nav a, .nav-btn { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: 11px; color: var(--ink-2); font-size: 14.5px; text-decoration: none; transition: background .12s, color .12s; width: 100%; text-align: left; }
.sidenav nav a:hover, .nav-btn:hover { background: var(--wash); color: var(--ink); }
.sidenav nav a.on { background: var(--surface); color: var(--ink); font-weight: 650; box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 0 0 1px var(--border); }
.sidenav nav a.on svg { stroke-width: 2.1; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; padding-top: 16px; }
.nav-btn { font-size: 13.5px; color: var(--muted); }
.main-col { min-width: 0; padding-bottom: 32px; }
.page-head { max-width: 1280px; margin: 0 auto; padding: 26px 24px 10px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: .01em; }
.seg a { height: 32px; padding: 0 16px; border-radius: 9px; font-size: 14px; color: var(--ink-2); white-space: nowrap; display: inline-flex; align-items: center; text-decoration: none; transition: background .15s, color .15s; }
.seg a.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--border); }
.page:not(.grid):not(#pg-expense) { max-width: 1280px; margin: 0 auto; padding: 8px 24px 24px; display: flex; flex-direction: column; gap: 16px; }
.card.narrow { width: 100%; max-width: 640px; margin: 0 auto; }
.tabbar { display: none; }

/* 页面里的小部件 */
.back-link, .link { font-size: 13.5px; color: var(--ink-2); text-decoration: none; }
.back-link { display: inline-block; margin-bottom: 12px; }
.link:hover, .back-link:hover { color: var(--ink); }
.kind-seg { display: flex; width: 100%; margin-bottom: 18px; }
.kind-seg button { flex: 1; height: 36px; font-size: 15px; }
a.tx { text-decoration: none; color: inherit; }
.hint-list { margin: 14px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 13.5px; line-height: 1.8; }
.rent-hero { text-align: center; padding: 28px 20px 22px; }
.rent-now { font-size: 40px; font-weight: 750; letter-spacing: -.02em; margin: 4px 0 4px; }
.rent-now small { font-size: 15px; color: var(--muted); font-weight: 500; }
.rent-hero .sheet-actions { justify-content: center; }
.rent-hero .sheet-actions .btn { flex: 0 1 280px; }
button.rent-row { width: 100%; text-align: left; transition: background .12s; }
button.rent-row:hover { background: var(--wash); }
.rent-amt .chev { color: var(--muted); margin-left: 8px; font-weight: 400; }
.chev { color: var(--muted); font-size: 18px; }
.ai-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.ai-card h2 { margin: 0 0 4px; font-size: 15px; }
.ai-card p { margin: 0; max-width: 560px; }
.ai-side { display: flex; align-items: center; gap: 16px; }
.ai-num { font-size: 26px; font-weight: 700; }
.ai-num small { font-size: 13px; color: var(--muted); font-weight: 500; }
.menu-list { display: flex; flex-direction: column; background: var(--wash); border-radius: 16px; overflow: hidden; }
.menu-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; text-decoration: none; text-align: left; width: 100%; border-bottom: 1px solid var(--grid); font-size: 15px; }
.menu-item:last-child { border-bottom: 0; }
.menu-item > span:nth-child(2) { flex: 1; }
.menu-item small { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.menu-item.on { font-weight: 650; }
.mi-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface); font-size: 17px; }

@media (max-width: 900px) {
  .shell { display: block; }
  .sidenav { display: none; }
  .main-col { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px); border-top: 1px solid var(--border); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; border-radius: 12px; font-size: 11px; color: var(--muted); text-decoration: none; }
  .tabbar svg { width: 23px; height: 23px; }
  .tabbar .on { color: var(--ink); font-weight: 650; }
  .tabbar .on svg { stroke-width: 2.2; }
  .page-head { padding: max(18px, env(safe-area-inset-top)) 16px 8px; gap: 10px; }
  .page-head h1 { font-size: 22px; }
  .page-head .sub-tabs { width: 100%; display: flex; }
  .page-head .sub-tabs a { flex: 1; justify-content: center; }
  .page:not(.grid):not(#pg-expense) { padding: 4px 12px 16px; gap: 12px; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
}
.opt.more-cats { justify-content: center; color: var(--ink-2); border-style: dashed; }

/* =========================================================
   问 AI
   ========================================================= */
#pg-ask.page { padding-bottom: 0 !important; }
.chat-wrap { width: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; min-height: calc(100dvh - 120px); }
.chat { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 4px 0 18px; }
.chat-empty { text-align: center; padding: 40px 8px 20px; }
.ask-mark { width: 56px; height: 56px; border-radius: 18px; margin: 0 auto 14px; display: grid; place-items: center; font-size: 26px; background: var(--ink); color: var(--page); }
.chat-empty h2 { margin: 0 0 6px; font-size: 20px; }
.chat-empty p { margin: 0 0 18px; font-size: 14px; }
.suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.sug { padding: 10px 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); font-size: 14px; text-align: left; transition: background .12s; }
.sug:hover { background: var(--wash); }
.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg.ai { align-items: flex-start; }
.bubble { max-width: min(88%, 640px); padding: 11px 15px; border-radius: 18px; font-size: 15px; line-height: 1.65; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--ink); color: var(--page); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.ai .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.bubble.err { color: var(--bad); }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble .md-h { font-weight: 700; margin-top: 4px; }
.bubble ul, .bubble ol { margin: 0 0 8px; padding-left: 20px; }
.bubble li { margin: 2px 0; }
.bubble code { font-size: 13px; background: var(--wash); padding: 1px 5px; border-radius: 5px; }
.md-table { overflow-x: auto; margin: 4px 0 10px; }
.md-table table { border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; min-width: 100%; }
.md-table th, .md-table td { padding: 6px 10px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; }
.md-table td:nth-child(2), .md-table th:nth-child(2) { white-space: nowrap; }
.md-table th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.msg-meta { font-size: 11.5px; color: var(--muted); margin: 4px 6px 0; }
.typing { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
.typing span { margin-left: 6px; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
.composer { position: sticky; bottom: 0; display: flex; align-items: flex-end; gap: 8px; padding: 10px 0 16px; background: linear-gradient(to bottom, transparent, var(--page) 30%); }
.composer textarea { flex: 1; resize: none; border-radius: 18px; border: 1px solid var(--border); background: var(--surface); padding: 12px 16px; font: inherit; font-size: 15px; color: var(--ink); outline: none; line-height: 1.45; box-shadow: var(--shadow); max-height: 140px; }
.composer textarea:focus { border-color: var(--ink-2); }
.composer .send { width: 46px; height: 46px; flex: none; border-radius: 50%; background: var(--ink); color: var(--page); display: grid; place-items: center; }
.composer .send:disabled { opacity: .35; }
.composer .clear-chat { height: 46px; flex: none; }
@media (max-width: 900px) {
  .chat-wrap { min-height: calc(100dvh - 170px); }
  .composer { bottom: calc(70px + env(safe-area-inset-bottom)); padding-bottom: 10px; }
  .bubble { max-width: 92%; font-size: 14.5px; }
}
