:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e3e8ef;
  --line-2: #cfd7e3;
  --text: #17212f;
  --text-2: #5b6778;
  --text-3: #8592a3;
  --brand: #0f2a4a;
  --accent: #1b64be;
  --accent-soft: #e8f1fc;
  --series-1: #257de0;
  --series-2: #f47230;
  --good: #0a7a32;
  --good-soft: #e6f5ec;
  --bad: #c0392b;
  --bad-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff6dc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f141b;
    --surface: #171e27;
    --surface-2: #1c2530;
    --line: #2a3441;
    --line-2: #384455;
    --text: #e8edf3;
    --text-2: #a5b1c0;
    --text-3: #7b8796;
    --brand: #0b1724;
    --accent: #5ea2f0;
    --accent-soft: #1b2b40;
    --series-1: #338ced;
    --series-2: #e76624;
    --good: #3ccf6e;
    --good-soft: #15301f;
    --bad: #ff7b6e;
    --bad-soft: #3a1c19;
    --warn: #f0c050;
    --warn-soft: #3a2f12;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.45; color: var(--text); background: var(--bg);
  -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, .n { font-variant-numeric: tabular-nums; }
.boot { padding: 40px; text-align: center; color: var(--text-2); }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 232px; flex: none; background: var(--brand); color: #dfe7f1; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 12px;
}
.side .logo { font-weight: 700; font-size: 18px; color: #fff; padding: 4px 10px 18px; letter-spacing: .2px; }
.side .logo small { display: block; font-weight: 400; font-size: 12px; color: #9fb2c8; margin-top: 2px; }
.side nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #cfdae7; margin-bottom: 2px; font-size: 14.5px;
}
.side nav a:hover { background: rgba(255, 255, 255, .07); }
.side nav a.on { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 600; }
.side nav .sep { height: 1px; background: rgba(255, 255, 255, .1); margin: 10px 6px; }
.side .who { margin-top: auto; font-size: 13px; color: #9fb2c8; padding: 10px; }
.side .who button { background: none; border: 1px solid rgba(255, 255, 255, .25); color: #dfe7f1; border-radius: 7px; padding: 4px 10px; margin-top: 6px; cursor: pointer; }
.ico { width: 18px; height: 18px; flex: none; }
.main { flex: 1; min-width: 0; }
.topbar { display: none; }
.content { padding: 24px 28px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -.2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.tabbar { display: none; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .hd { display: flex; align-items: center; gap: 10px; padding: 14px 16px 0; }
.card > .hd h2 { font-size: 15.5px; margin: 0; }
.card > .hd .sub { color: var(--text-2); font-size: 13px; }
.card > .hd .act { margin-left: auto; }
.card > .bd { padding: 14px 16px 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
select.inp.sm { padding-right: 28px; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpis.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { padding: 14px 16px; }
.kpi .k { font-size: 12.5px; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 550; font-size: 14px;
  min-height: 38px; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger.solid { background: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .ico { width: 16px; height: 16px; }
label.f { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.inp, select.inp, textarea.inp {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--surface); min-height: 40px;
  font-size: 15px; outline: none; -webkit-appearance: none; appearance: none;
}
select.inp { background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.inp.money { text-align: right; font-variant-numeric: tabular-nums; }
.inp.sm { min-height: 34px; padding: 6px 9px; font-size: 14px; }
textarea.inp { min-height: 70px; resize: vertical; }
.field { margin-bottom: 14px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.fields .full { grid-column: 1 / -1; }
.hint { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 14px; font-weight: 550; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.seg.types button.on[data-v="income"] { background: var(--good); color: #fff; }
.seg.types button.on[data-v="expense"] { background: var(--bad); color: #fff; }
.seg.types button.on[data-v="upad"] { background: #6a4ce2; color: #fff; }
.seg.types button.on[data-v="transfer"] { background: #546478; color: #fff; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13.5px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-2); font-weight: 650; padding: 9px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
.tbl th.sortable { cursor: pointer; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface-2); }
.tbl td.n, .tbl th.n { text-align: right; white-space: nowrap; }
.tbl td:first-child { white-space: nowrap; }
.tbl tr.tot td { font-weight: 700; border-top: 2px solid var(--line-2); background: var(--surface-2); }
.tbl .desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-income { background: var(--good-soft); color: var(--good); }
.b-expense { background: var(--bad-soft); color: var(--bad); }
.b-upad { background: #efeafd; color: #5a3fd0; }
.b-transfer { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { .b-upad { background: #2a2346; color: #b9a8ff; } }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border: 1px solid rgba(0, 0, 0, .12); }
.fx { font-size: 12px; color: var(--text-3); }

/* entries list (cards on mobile) */
.tx-cards { display: none; }
.bd > .tx-cards .txc { padding-left: 0; padding-right: 0; }
.txc { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: flex-start; background: var(--surface); }
.txc .l { flex: 1; min-width: 0; }
.txc .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txc .t2 { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txc .amt { font-weight: 700; text-align: right; white-space: nowrap; }
.txc .amt small { display: block; font-weight: 400; font-size: 12px; color: var(--text-3); }
.txc.sel, .tbl tr.sel td { background: var(--accent-soft) !important; }
.txc input[type=checkbox] { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }
.sumstrip { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.sumstrip b { font-variant-numeric: tabular-nums; }
.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.bulkbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--accent-soft); flex-wrap: wrap; }

/* ---------- bars & charts ---------- */
.hbars { display: grid; gap: 9px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 10px; align-items: center; font-size: 13.5px; cursor: default; }
.hbar .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { display: block; height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); }
.hbar .val { font-variant-numeric: tabular-nums; text-align: right; min-width: 90px; }
.hbar .pct { color: var(--text-3); font-size: 12px; margin-left: 6px; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--line-2); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: 7px 10px; border-radius: 8px; font-size: 12.5px; line-height: 1.5; white-space: nowrap; z-index: 5; transform: translate(-50%, -100%); margin-top: -8px; box-shadow: 0 4px 12px rgba(0, 0, 0, .2); }
.tip b { font-variant-numeric: tabular-nums; }

.bal-list .ba { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.bal-list .ba:last-child { border-bottom: 0; }
.bal-list .ba.tot { font-weight: 700; border-top: 2px solid var(--line-2); }
.biz-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.biz-card { padding: 14px 16px; border-left: 4px solid var(--series-1); }
.biz-card h3 { margin: 0 0 8px; font-size: 16px; }
.biz-card .l { display: flex; justify-content: space-between; font-size: 14px; padding: 2px 0; }
.biz-card .l.big { font-weight: 700; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 20, 35, .45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .12s ease; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 620px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.modal.sm { max-width: 420px; }
.modal .mh { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal .mh h2 { margin: 0; font-size: 17px; flex: 1; }
.modal .mb { padding: 16px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-bottom: calc(12px + var(--safe-b)); }
.modal .mf .left { margin-right: auto; }
.x { border: 0; background: transparent; font-size: 24px; line-height: 1; cursor: pointer; color: var(--text-2); padding: 4px 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.err { background: var(--bad-soft); color: var(--bad); padding: 9px 12px; border-radius: 9px; font-size: 14px; margin-bottom: 12px; }
.note { background: var(--warn-soft); color: var(--warn); padding: 9px 12px; border-radius: 9px; font-size: 14px; }
.okbox { background: var(--good-soft); color: var(--good); padding: 9px 12px; border-radius: 9px; font-size: 14px; }
.infobox { background: var(--accent-soft); padding: 10px 12px; border-radius: 9px; font-size: 14px; }

/* toast */
#toast-root { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); animation: up .15s ease; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- settings ---------- */
.set-sec { margin-bottom: 18px; scroll-margin-top: 16px; }
.set-sec.dirty { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.set-sec .hd .flag { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; }
.set-sec .ft { display: flex; justify-content: flex-end; gap: 8px; padding: 0 16px 16px; align-items: center; }
.set-sec .ft .msg { margin-right: auto; font-size: 13px; }
.set-nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.list-ed { width: 100%; border-collapse: collapse; }
.list-ed td { padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.list-ed th { font-size: 12px; text-align: left; color: var(--text-2); padding: 4px; font-weight: 600; }
.list-ed tr.del td { opacity: .45; text-decoration: line-through; }
.list-ed input[type=color] { width: 38px; height: 34px; border: 1px solid var(--line-2); border-radius: 8px; padding: 2px; background: var(--surface); }
.savebar {
  position: sticky; bottom: 0; z-index: 20; margin: 0 -28px -60px; padding: 12px 28px; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; box-shadow: 0 -4px 14px rgba(0, 0, 0, .07);
}
.savebar .msg { flex: 1; font-size: 14px; }
.savebar.clean .msg { color: var(--text-3); }
.savebar.dirty .msg { color: var(--accent); font-weight: 600; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #0f2a4a, #1b64be); }
.login .card { width: 100%; max-width: 380px; padding: 26px 24px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }

/* import */
.drop { display: block; border: 2px dashed var(--line-2); border-radius: 12px; padding: 28px; text-align: center; cursor: pointer; }
.drop.on { border-color: var(--accent); background: var(--accent-soft); }
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--text-2); }
.stat .v { font-weight: 700; font-size: 17px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  body { font-size: 15.5px; }
  .side { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; background: var(--brand); color: #fff;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px; min-height: 52px;
  }
  .topbar .t { font-weight: 650; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar button { background: rgba(255, 255, 255, .12); border: 0; color: #fff; border-radius: 8px; padding: 6px 10px; font-size: 14px; }
  .content { padding: 14px 12px calc(90px + var(--safe-b)); }
  .page-head h1 { display: none; }
  .page-head { margin-bottom: 12px; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .grid.g2, .grid.g3, .grid.g-main { grid-template-columns: minmax(0, 1fr); }
  .kpis, .kpis.k4, .kpis.k3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpis .kpi:first-child { grid-column: 1 / -1; }
  .kpi { padding: 11px 13px; }
  .kpi .v { font-size: 19px; }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 12px; }
  .tx-table { display: none; }
  .tx-cards { display: block; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + var(--safe-b)); justify-content: space-around; align-items: flex-end;
  }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text-2); background: none; border: 0; padding: 4px 0; cursor: pointer; }
  .tabbar .on { color: var(--accent); font-weight: 650; }
  .tabbar .ico { width: 23px; height: 23px; }
  .tabbar .fab { flex: none; width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: #fff; justify-content: center; margin: -22px 6px 0; box-shadow: 0 4px 14px rgba(27, 100, 190, .45); }
  .tabbar .fab .ico { width: 26px; height: 26px; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal, .modal.sm { max-width: none; border-radius: 16px 16px 0 0; max-height: calc(100vh - 30px); animation: up .18s ease; }
  .savebar { margin: 0 -12px; padding: 10px 12px; bottom: calc(68px + var(--safe-b)); border-radius: 12px 12px 0 0; }
  .savebar .msg { font-size: 13px; }
  .hide-m { display: none !important; }
  .hbar { grid-template-columns: minmax(70px, 110px) 1fr auto; }
  .hbar .val { min-width: 76px; }
  .inp, select.inp, textarea.inp { font-size: 16px; } /* stop iOS zoom */
  #toast-root { bottom: calc(140px + var(--safe-b)); }
  .tbl { font-size: 13.5px; }
  .tbl td, .tbl th { padding: 8px 7px; }
  .list-ed .hide-m { display: none; }
}
@media print {
  .side, .tabbar, .topbar, .page-head .actions, .savebar { display: none !important; }
  .content { padding: 0; }
}
