:root {
  --bg: #f4f6f9; --card: #ffffff; --ink: #14202b; --muted: #5d6b78; --line: #dfe5ec;
  --brand: #0f3d5e; --brand-2: #1d6fa5; --good: #15803d; --bad: #c0262d; --warn: #b45309;
  --warn-bg: #fff6e0; --chip: #eef2f6; --shadow: 0 1px 2px rgba(15, 30, 45, .06), 0 2px 8px rgba(15, 30, 45, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151b; --card: #17212b; --ink: #e5ecf2; --muted: #9aa8b5; --line: #2a3744;
    --brand: #8cc4ef; --brand-2: #6fb3e8; --good: #4ade80; --bad: #f87171; --warn: #fbbf24;
    --warn-bg: #3a2e12; --chip: #223040; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand-2); }
h1 { font-size: 1.35rem; margin: .4rem 0 .8rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 12px 16px 60px; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.good { color: var(--good); } .bad { color: var(--bad); }

/* header + nav */
.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: #0f3d5e; color: #fff; position: sticky; top: 0; z-index: 5; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.brand img { width: 26px; height: 26px; }
.top .add-btn { background: #fff; color: #0f3d5e; border: 0; font-weight: 700; }
.nav { display: flex; gap: 2px; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); padding: 0 8px; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 10px 12px; text-decoration: none; color: var(--muted); white-space: nowrap; border-bottom: 3px solid transparent; font-weight: 600; font-size: .92rem; }
.nav a.on { color: var(--brand); border-bottom-color: var(--brand-2); }

/* cards, stats */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card.narrow { max-width: 460px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit; min-width: 0; box-shadow: var(--shadow); }
.stat span { color: var(--muted); font-size: .82rem; }
.stat b { font-size: clamp(1.1rem, 4.6vw, 1.45rem); overflow-wrap: anywhere; }
.stat small { color: var(--muted); font-size: .78rem; }
.stat.big { background: #0f3d5e; color: #fff; border-color: #0f3d5e; }
.stat.big span { color: #cfe3f3; }
.stat.good b { color: var(--good); } .stat.bad b { color: var(--bad); }
.stat.warn { background: var(--warn-bg); border-color: var(--warn); } .stat.warn b { color: var(--warn); }
.books { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.bookcard { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--c, #2563eb); border-radius: 12px; padding: 12px 14px; color: inherit; text-decoration: none; box-shadow: var(--shadow); min-width: 0; }
.row { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.row span { color: var(--muted); } .row b { white-space: nowrap; }
.row.net { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }
.row.net.good b { color: var(--good); } .row.net.bad b { color: var(--bad); }
.meter { height: 6px; background: var(--chip); border-radius: 3px; margin: 8px 0 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--c, #9333ea); }
.note { background: var(--card); border-left: 4px solid var(--brand-2); padding: 10px 12px; border-radius: 6px; font-size: .9rem; }
.monthbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.monthbar h1 { margin: .3rem 0; flex: 1; text-align: center; }
.monthbar form { margin-left: auto; }

/* tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: .8rem; color: var(--muted); font-weight: 600; }
table.list tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
table.list tr.total.bad td.num { color: var(--bad); } table.list tr.total.good td.num { color: var(--good); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.review td { background: var(--warn-bg); }
.scroll-x { overflow-x: auto; }
table.grid td, table.grid th { font-size: .88rem; }

/* forms */
label { display: block; font-size: .85rem; color: var(--muted); margin: 6px 0; }
input, select, textarea { display: block; width: 100%; margin-top: 3px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font: inherit; font-size: 16px; min-width: 0; }
input[type=checkbox], input[type=radio] { display: inline; width: auto; margin: 0 6px 0 0; }
label.check { display: flex; align-items: center; color: var(--ink); }
.grid2, .grid3 { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: 1fr 1fr 1fr; } }
.btn { display: inline-block; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: #1d6fa5; border-color: #1d6fa5; color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.wide { width: 100%; margin-top: 8px; }
.actions { display: flex; gap: 10px; justify-content: space-between; margin-top: 10px; }
form.inline { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
form.inline label { flex: 1 1 160px; }
fieldset.rulebox { border: 1px dashed var(--line); border-radius: 8px; margin: 12px 0; padding: 8px 12px; }
fieldset.rulebox legend { font-size: .85rem; color: var(--muted); }
details summary { cursor: pointer; color: var(--brand-2); margin-top: 8px; font-size: .9rem; }
details[open] summary { margin-bottom: 6px; }
.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; margin-bottom: 12px; gap: 3px; }
.seg a, .seg label { flex: 1; text-align: center; padding: 8px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; margin: 0; display: flex; align-items: center; justify-content: center; font-size: .92rem; }
.seg a.on, .seg label:has(input:checked) { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.seg.dir label:has(input[value=out]:checked) { color: var(--bad); }
.seg.dir label:has(input[value=in]:checked) { color: var(--good); }
.filters { display: grid; grid-template-columns: 1fr; gap: 6px; }
@media (min-width: 760px) { .filters { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; align-items: center; } .filters input[type=search] { grid-column: 1 / -1; } }
.filters .dates { display: flex; gap: 4px; align-items: center; }
.filters select, .filters input { margin: 0; }
.sumline { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin: 6px 0 10px; font-weight: 600; font-size: .92rem; }
.sumline .btn { margin-left: auto; }

/* entries list */
.tx-list { display: flex; flex-direction: column; gap: 6px; }
.tx { display: flex; justify-content: space-between; gap: 10px; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--bad); border-radius: 10px; padding: 9px 12px; text-decoration: none; color: inherit; }
.tx.in { border-left-color: var(--good); }
.tx.review { background: var(--warn-bg); }
.tx-l { min-width: 0; }
.tx-who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { color: var(--muted); font-size: .8rem; }
.tx-tags { margin-top: 3px; display: flex; gap: 4px; flex-wrap: wrap; }
.tx-amt { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx.in .tx-amt { color: var(--good); }
.chip { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 10px; background: var(--chip); border-left: 3px solid var(--c, transparent); color: var(--ink); }
.chip.plain { border-left: 0; color: var(--muted); }
.chip.warn, .tag.warn { background: var(--warn-bg); color: var(--warn); border-left: 0; }
.tag { font-size: .7rem; background: var(--chip); color: var(--muted); padding: 1px 6px; border-radius: 8px; vertical-align: middle; }
.pager { display: flex; justify-content: center; gap: 12px; align-items: center; margin: 14px 0; }

.card.head { border-left: 5px solid var(--bad); }
.card.head.in { border-left-color: var(--good); }
.big-amt { font-size: 1.6rem; font-weight: 800; }
.bank-text { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; background: var(--chip); padding: 6px 8px; border-radius: 6px; margin: 6px 0; overflow-wrap: anywhere; }

.acct-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.acct-bal { font-size: 1.2rem; font-weight: 800; white-space: nowrap; }
.acct.inactive { opacity: .55; }

.flash { padding: 10px 12px; border-radius: 8px; margin-bottom: 10px; background: #e7f5ec; color: #14532d; border: 1px solid #b7e1c5; }
.flash.bad { background: #fdecec; color: #7f1d1d; border-color: #f3c2c2; }
@media (prefers-color-scheme: dark) { .flash { background: #12301f; color: #bbf7d0; border-color: #1f5135; } .flash.bad { background: #3a1616; color: #fecaca; border-color: #5c2323; } }

.login { max-width: 380px; margin: 9vh auto; text-align: center; }
.login .logo { width: 56px; height: 56px; }
.login form { text-align: left; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
