:root {
  color-scheme: light;
  --page: #f6f7f9; --surface-1: #ffffff; --surface-2: #f1f3f6; --hover: #eef2f7;
  --text-primary: #191919; --text-secondary: #666666; --text-tertiary: #8a8a8a;
  --border: rgba(11, 11, 11, .10); --grid: #e7e7e7; --axis: #c2c2c2;
  --accent: #257de0; --accent-ink: #1b64be; --accent-wash: #e8f1fc;
  --good-ink: #006c10; --critical: #dc3c3d; --critical-ink: #b42a2b; --warning: #fbb315;
  --series-1: #257de0; --series-2: #f47230; --series-3: #00b894;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --nav-h: 62px; --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b; --surface-1: #191919; --surface-2: #222222; --hover: #262a30;
    --text-primary: #efefef; --text-secondary: #9c9c9c; --text-tertiary: #7a7a7a;
    --border: rgba(255, 255, 255, .10); --grid: #303030; --axis: #474747;
    --accent: #338ced; --accent-ink: #6aabf1; --accent-wash: #16263a;
    --good-ink: #53c556; --critical: #dc3c3d; --critical-ink: #eb6263;
    --series-1: #338ced; --series-2: #e76624; --series-3: #00a888;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); color: var(--text-primary); -webkit-text-size-adjust: 100%; }
body { font-size: 15px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.ic { width: 20px; height: 20px; flex: none; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-secondary); }
.small { font-size: 13px; }
.hidden { display: none !important; }
a { color: var(--accent-ink); }

/* ---------- shell ---------- */
#app { min-height: 100%; }
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.side { display: none; }
.main { min-width: 0; padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(12px); }
.topbar h1 { font-size: 19px; margin: 0; font-weight: 650; flex: 1; white-space: nowrap; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 11px; background: transparent; color: var(--text-secondary); }
.icon-btn:hover { background: var(--hover); color: var(--text-primary); }
.sync { position: relative; }
.sync .dot { position: absolute; right: 6px; top: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 10px; line-height: 16px; text-align: center; }
.sync.spin .ic { animation: spin 1s linear infinite; }
.sync.bad { color: var(--critical-ink); }
@keyframes spin { to { transform: rotate(360deg); } }
.content { padding: 4px 14px 16px; max-width: 1180px; margin: 0 auto; }

.bottomnav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface-1); border-top: 1px solid var(--border); }
.bottomnav a, .side a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--text-secondary); font-size: 11px; }
.bottomnav a.on, .side a.on { color: var(--accent-ink); }
.fab { position: fixed; z-index: 31; right: 18px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 20px rgba(37,125,224,.35); }
.fab .ic { width: 26px; height: 26px; }

@media (min-width: 960px) {
  .shell { grid-template-columns: 216px 1fr; }
  .side { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; padding: 18px 12px; border-right: 1px solid var(--border); background: var(--surface-1); }
  .side .brand { font-weight: 700; font-size: 18px; padding: 4px 10px 18px; display: flex; align-items: center; gap: 8px; }
  .side a { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px; border-radius: 10px; font-size: 15px; }
  .side a:hover { background: var(--hover); }
  .side a.on { background: var(--accent-wash); }
  .side .spacer { flex: 1; }
  .side .side-add { margin: 0 0 14px; justify-content: center; background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px; display: flex; gap: 8px; align-items: center; font-weight: 600; }
  .bottomnav, .fab { display: none; }
  .main { padding-bottom: 32px; }
  .topbar { padding: 16px 28px; }
  .content { padding: 4px 28px 28px; }
}

/* ---------- cards ---------- */
.card { background: var(--surface-1); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.card h2 .grow { flex: 1; }
.grid2 { display: grid; gap: 14px; }
@media (min-width: 960px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid2 > .card { margin-bottom: 0; } .grid2 { margin-bottom: 14px; } }

.monthbar { display: flex; align-items: center; gap: 4px; }
.monthbar strong { font-size: 15px; min-width: 92px; text-align: center; font-weight: 600; }

.hero-label { color: var(--text-secondary); font-size: 13px; }
.hero { font-size: 40px; font-weight: 650; letter-spacing: -.5px; margin: 2px 0 10px; }
@media (min-width: 960px) { .hero { font-size: 48px; } }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tiles.four { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 720px) { .tiles.four { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--text-secondary); }
.tile .v { font-size: clamp(14px, 4.2vw, 17px); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .d { font-size: 12px; color: var(--text-secondary); }
.pos { color: var(--good-ink); }
.neg { color: var(--text-primary); }

.meter { height: 6px; border-radius: 3px; background: var(--accent-wash); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter.warn span { background: var(--warning); }
.meter.over span { background: var(--critical); }
.budget-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.budget-row .amt { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.budget-row .amt b { color: var(--text-primary); font-weight: 600; }
.over-tag { color: var(--critical-ink); font-size: 12px; font-weight: 600; }

/* ---------- entry list ---------- */
.day { margin-top: 6px; }
.dayhead { display: flex; justify-content: space-between; padding: 10px 4px 6px; font-size: 13px; color: var(--text-secondary); }
.rows { background: var(--surface-1); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.row:first-child { border-top: 0; }
.row:hover { background: var(--hover); }
.cat { flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-size: 14px; font-weight: 600; background: var(--surface-2); color: var(--text-secondary); }
.cat.daily { background: var(--accent-wash); color: var(--accent-ink); }
.cat.income { background: color-mix(in srgb, var(--good-ink) 14%, transparent); color: var(--good-ink); }
.cat.fixed { background: color-mix(in srgb, var(--series-2) 16%, transparent); color: color-mix(in srgb, var(--series-2) 70%, var(--text-primary)); }
.cat.big { background: color-mix(in srgb, #6a4ce2 14%, transparent); color: color-mix(in srgb, #6a4ce2 70%, var(--text-primary)); }
.row .mid { flex: 1; min-width: 0; }
.row .t1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t2 { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .flag { color: var(--critical-ink); }
.row .amount { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--text-secondary); padding: 36px 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters input[type=search] { flex: 1 1 180px; }
.field, .filters input, .filters select, .sheet input, .sheet select, .sheet textarea, .form input, .form select { border: 1px solid var(--border); background: var(--surface-1); border-radius: 10px; padding: 9px 11px; min-height: 40px; }
.chip { border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.sug { border-color: var(--accent); color: var(--accent-ink); }
.chip.sug.on { color: #fff; }
.summary-line { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--text-secondary); margin: 0 4px 6px; }
.btn { border: 1px solid var(--border); background: var(--surface-1); border-radius: 10px; padding: 9px 14px; display: inline-flex; align-items: center; gap: 6px; font-weight: 550; justify-content: center; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--critical-ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- tables (desktop month view etc.) ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-1); }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--text-secondary); }
table.data td:first-child, table.data th:first-child { text-align: left; position: sticky; left: 0; background: var(--surface-1); }
table.data th:first-child { background: var(--surface-2); z-index: 1; }
table.data tr.budget td { color: var(--text-secondary); background: var(--surface-2); }
table.data td.sub { font-weight: 650; }
table.data td.over { color: var(--critical-ink); font-weight: 650; }
table.data tr:hover td { background: var(--hover); }

.month-card .mhead { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.month-card .mhead strong { flex: 1; font-size: 16px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); }
.badge.ok { background: color-mix(in srgb, var(--good-ink) 14%, transparent); color: var(--good-ink); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 14px; }
.kv .k { color: var(--text-secondary); }
.kv .v { text-align: right; font-variant-numeric: tabular-nums; }
.kv .strong { font-weight: 650; }

/* ---------- sheets / dialogs ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.36); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; background: var(--surface-1); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); animation: up .2s ease; }
.sheet.full { max-width: 1100px; height: 100vh; max-height: 100vh; border-radius: 0; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
@media (min-width: 720px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } .sheet.full { height: 92vh; max-height: 92vh; border-radius: 20px; } }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 17px; flex: 1; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 16px; border-radius: 8px; color: var(--text-secondary); font-weight: 550; }
.seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.amount-input { display: flex; align-items: baseline; gap: 6px; border-bottom: 2px solid var(--accent); margin: 10px 0 14px; padding-bottom: 4px; }
.amount-input span { font-size: 24px; color: var(--text-secondary); }
.amount-input input { border: 0 !important; background: transparent !important; font-size: 34px; font-weight: 650; width: 100%; padding: 0 !important; outline: none; font-variant-numeric: tabular-nums; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.form label > input, .form label > select { color: var(--text-primary); font-size: 15px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-label { font-size: 12px; color: var(--text-secondary); margin: 8px 0 4px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; padding: 12px; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 4px; }

.import-row { display: grid; grid-template-columns: 24px 88px 1fr 112px 92px; gap: 8px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); font-size: 14px; }
.import-row input[type=text], .import-row select { min-height: 34px; padding: 5px 8px; width: 100%; }
.import-row .amount { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.import-row .hint { grid-column: 3 / -1; font-size: 12px; color: var(--text-secondary); margin-top: -4px; }
.import-row .hint.warn { color: var(--critical-ink); }
.import-row.off { opacity: .55; }
@media (max-width: 719px) {
  .import-row { grid-template-columns: 24px 1fr 92px; }
  .import-row .date { grid-column: 2; font-size: 12px; color: var(--text-secondary); }
  .import-row .amount { grid-column: 3; grid-row: 1; }
  .import-row .detail { grid-column: 2 / 4; }
  .import-row .catsel { grid-column: 2 / 4; }
  .import-row .hint { grid-column: 2 / 4; }
}
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--text-secondary); }
.progress { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin: 10px 0; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width .2s; }

.settings-list .item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.settings-list .item:first-child { border-top: 0; }
.settings-list .item .grow { flex: 1; min-width: 0; }
.cat-group { margin-bottom: 12px; }
.cat-group h4 { margin: 8px 0 6px; font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.cat-item { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 3px 4px 3px 12px; margin: 0 6px 6px 0; font-size: 14px; }
.cat-item select { border: 0; background: var(--surface-2); border-radius: 999px; padding: 2px 6px; font-size: 12px; min-height: 0; }
.budget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.budget-grid label { display: grid; gap: 3px; font-size: 13px; color: var(--text-secondary); }
.budget-grid input { border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; background: var(--surface-1); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 24px; }
.login h1 { margin: 0 0 4px; font-size: 24px; }
.logo { width: 48px; height: 48px; border-radius: 14px; background: var(--accent); color: #fff; display: grid; place-items: center; margin-bottom: 14px; }
.logo .ic { width: 28px; height: 28px; }
.error { color: var(--critical-ink); font-size: 13px; min-height: 18px; }

/* ---------- charts ---------- */
.viz-root { color: var(--text-primary); }
.viz-plot { width: 100%; }
.viz-plot svg { display: block; overflow: visible; }
.viz-grid { stroke: var(--grid); stroke-width: 1; }
.viz-base { stroke: var(--axis); stroke-width: 1; }
.viz-cross { stroke: var(--axis); stroke-width: 1; }
.viz-tick { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-label { fill: var(--text-primary); font-size: 12px; }
.viz-value { fill: var(--text-secondary); font-size: 12px; font-variant-numeric: tabular-nums; }
.viz-hit { outline: none; cursor: default; }
.viz-hit:focus-visible { stroke: var(--accent); stroke-width: 1; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-secondary); margin: -4px 0 8px; }
.viz-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.viz-swatch { width: 10px; height: 10px; border-radius: 3px; }
.viz-swatch.line { height: 2px; width: 14px; border-radius: 1px; }
.viz-table { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.viz-table summary { cursor: pointer; }
.viz-table table { border-collapse: collapse; margin-top: 6px; width: 100%; font-variant-numeric: tabular-nums; }
.viz-table th, .viz-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); text-align: right; }
.viz-table th:first-child, .viz-table td:first-child { text-align: left; }
.viz-tip { position: fixed; z-index: 90; pointer-events: none; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.14); opacity: 0; transition: opacity .1s; min-width: 120px; }
.viz-tip.show { opacity: 1; }
.viz-tip-title { color: var(--text-secondary); margin-bottom: 4px; }
.viz-tip-row { display: flex; align-items: center; gap: 6px; }
.viz-tip-row strong { font-variant-numeric: tabular-nums; }
.viz-tip-name { color: var(--text-secondary); }
.viz-key { width: 12px; height: 2px; border-radius: 1px; }
.viz-mark:hover { filter: brightness(1.12); }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 84px); transform: translate(-50%, 10px); background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; transition: .2s; z-index: 100; max-width: 90vw; text-align: center; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--critical); }
@media (min-width: 960px) { #toast { bottom: 32px; } }
