:root {
  --bg: #f6f4ef; --surface: #ffffff; --surface-2: #faf8f4; --ink: #1c2321; --muted: #6b7370; --line: #e3dfd6;
  --accent: #1f5c4a; --accent-ink: #ffffff; --accent-soft: #e4efe9;
  --ok: #1f7a4d; --warn: #9a6700; --bad: #b3261e; --bad-soft: #fbeae8; --warn-soft: #fbf3dc;
  --radius: 10px; --shadow: 0 1px 2px rgba(28, 35, 33, .06), 0 4px 14px rgba(28, 35, 33, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513; --surface: #191f1c; --surface-2: #1f2622; --ink: #e8ece9; --muted: #96a09b; --line: #2b332f;
    --accent: #6fc3a3; --accent-ink: #0d1512; --accent-soft: #1d2e27;
    --ok: #6fc3a3; --warn: #e0b24a; --bad: #f08a80; --bad-soft: #3a1f1c; --warn-soft: #352c14;
    --shadow: none;
  }
}
* { 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; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 13px; } .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.grow { flex: 1; } .right { text-align: right; } .boot { padding: 40px; text-align: center; color: var(--muted); }
.pos { color: var(--ok); } .neg { color: var(--ink); } .over { color: var(--bad); }

/* layout */
.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1180px; margin: 0 auto; padding: 10px 18px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.02em; color: var(--accent); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand i { width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-style: normal; font-size: 14px; }
nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
nav a { padding: 7px 11px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; white-space: nowrap; }
nav a:hover { color: var(--ink); background: var(--surface-2); }
nav a.on { color: var(--accent); background: var(--accent-soft); }
.month { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.month b { min-width: 128px; text-align: center; font-weight: 600; }
main { max-width: 1180px; margin: 0 auto; padding: 20px 18px 80px; }
.head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.head h1 { margin-right: auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card > h3 { margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card > h3 .grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* controls */
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.icon { padding: 5px 9px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; max-width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: 17px; height: 17px; accent-color: var(--accent); padding: 0; }
label.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi span { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.kpi b { display: block; font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); }

/* bars */
.brow { padding: 9px 0; border-top: 1px solid var(--line); }
.brow:first-of-type { border-top: 0; }
.brow-top { display: flex; gap: 10px; align-items: baseline; }
.brow-top .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.bar { height: 7px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.over i { background: var(--bad); }
.bar.near i { background: var(--warn); }

.trend { display: flex; gap: 10px; align-items: flex-end; height: 130px; }
.trend > div { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.trend .cols { flex: 1; display: flex; gap: 3px; align-items: flex-end; width: 100%; justify-content: center; }
.trend .cols i { width: 38%; max-width: 22px; border-radius: 3px 3px 0 0; min-height: 2px; }
.trend .in { background: var(--accent); } .trend .out { background: #c98b3f; }
.trend small { color: var(--muted); margin-top: 5px; font-size: 12px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

/* lists */
.list { display: flex; flex-direction: column; }
.li { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.li:first-child { border-top: 0; }
.li .main { flex: 1; min-width: 0; }
.li .main b { font-weight: 550; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .main small { color: var(--muted); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--accent-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); margin-right: 4px; font-weight: 600; }
.day { width: 34px; height: 34px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 650; font-variant-numeric: tabular-nums; flex: none; }

/* transactions */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input[type=search] { flex: 1; min-width: 170px; }
.txs { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tx { display: grid; grid-template-columns: 26px 88px minmax(0, 1fr) 130px 200px 118px 70px; gap: 10px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); }
.tx:first-child { border-top: 0; }
.tx.hd { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.tx.flagged { background: var(--warn-soft); }
.tx .desc { min-width: 0; cursor: pointer; }
.tx .desc b { font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .desc small { color: var(--muted); }
.tx .acct { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx select { width: 100%; padding: 5px 7px; font-size: 14px; }
.tx select.none { border-color: var(--warn); background: var(--warn-soft); }
.tx .amt { text-align: right; font-weight: 600; }
.tx .acts { display: flex; justify-content: flex-end; gap: 2px; }
.flagbtn { border: 0; background: none; cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 6px; color: var(--muted); opacity: .45; }
.flagbtn.on { opacity: 1; }
.flagbtn:hover { background: var(--surface-2); color: var(--muted); }
.flagbtn.on { color: var(--warn); }
.bulk { position: sticky; bottom: 12px; z-index: 15; margin-top: 12px; background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); }
.bulk select, .bulk input { padding: 5px 8px; }
.bulk .btn { padding: 5px 10px; }
@media (max-width: 860px) {
  .tx { grid-template-columns: 24px minmax(0, 1fr) auto; grid-template-areas: "c d a" "c s x"; row-gap: 6px; }
  .tx.hd { display: none; }
  .tx .chk { grid-area: c; } .tx .desc { grid-area: d; } .tx .amt { grid-area: a; } .tx .cat { grid-area: s; } .tx .acts { grid-area: x; }
  .tx .date, .tx .acct { display: none; }
  .tx .desc small .mdate { display: inline; }
  .month b { min-width: 104px; }
  .month { margin-left: 0; width: 100%; justify-content: space-between; order: 3; }
  nav { order: 4; width: 100%; }
}
@media (min-width: 861px) { .tx .desc small .mdate { display: none; } }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.right, th.right { text-align: right; }
.scroll { overflow-x: auto; }
.budget-in { width: 112px; text-align: right; }
tr.grp td { background: var(--surface-2); font-weight: 650; }

/* debts */
.debts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.debt .bal { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: 6px 0 2px; }
.debt dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 12px 0; }
.debt dt { font-size: 12px; color: var(--muted); } .debt dd { margin: 0; font-weight: 550; font-variant-numeric: tabular-nums; }
.debt .acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* dialogs */
dialog.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog.dlg::backdrop { background: rgba(15, 20, 18, .5); }
.dlg form, .dlg .body { padding: 20px; }
.dlg h2 { margin-bottom: 14px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; grid-column: span 2; }
.field.half { grid-column: span 1; }
.field > span { font-size: 13px; font-weight: 600; }
.field small { color: var(--muted); font-size: 12.5px; }
.field input:not([type=checkbox]), .field select, .field textarea { width: 100%; }
.field.checkf { flex-direction: row; align-items: center; gap: 8px; }
.dlg-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
.err { color: var(--bad); font-weight: 550; margin: 12px 0 0; }
@media (max-width: 520px) { .field.half { grid-column: span 2; } }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: min(400px, 100%); padding: 26px; }
.auth h1 { margin: 14px 0 6px; }
.auth form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

/* import */
.maps { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 12px 0; }
.note { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 9px 12px; margin: 10px 0; font-weight: 500; }
.okbox { background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; margin: 10px 0; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.steps li:first-child { border-top: 0; }
.steps li::before { content: counter(s); width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.steps li.done::before { content: "✓"; background: var(--accent); color: var(--accent-ink); }
.steps li div { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

#toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 24px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); display: flex; gap: 12px; align-items: center; }
.toast.bad { background: var(--bad); color: #fff; }
.toast button { font: inherit; font-weight: 700; background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
