:root {
  --bg: #f4f6f5; --card: #ffffff; --text: #17201d; --muted: #5f6b67; --line: #dfe5e2;
  --brand: #0f5c4d; --brand-ink: #ffffff; --in: #11734b; --out: #b3261e; --warn-bg: #fff4d6; --warn: #6d4c00;
  --err-bg: #fde8e6; --ok-bg: #e3f4ea; --info-bg: #e7eef9; --focus: #2a7fff;
  --radius: 14px; --tabbar-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --card: #18211e; --text: #e6ece9; --muted: #9aa8a3; --line: #2a3632;
    --brand: #3fb594; --brand-ink: #062019; --in: #5bd39a; --out: #ff8a80; --warn-bg: #3a2f10; --warn: #ffd98a;
    --err-bg: #3d1b19; --ok-bg: #143022; --info-bg: #1a2638;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px); }
a { color: var(--brand); }
h1 { font-size: 1.4rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
.card h2:first-child { margin-top: 0; }
.wrap { max-width: 860px; margin: 0 auto; padding: 12px max(16px, env(safe-area-inset-left, 0px)) 0 max(16px, env(safe-area-inset-right, 0px)); }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.in { color: var(--in); } .out { color: var(--out); }
.top { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: var(--brand); color: var(--brand-ink); }
.top a { color: inherit; text-decoration: none; }
.brand { font-weight: 700; letter-spacing: .02em; }
.top-bal { font-variant-numeric: tabular-nums; font-weight: 600; }
.top-bal.neg { background: var(--out); color: #fff; padding: 2px 8px; border-radius: 8px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; height: var(--tabbar-h);
  font-size: .72rem; color: var(--muted); text-decoration: none; }
.tabbar .ic { font-size: 1.35rem; line-height: 1.2; }
.tabbar a[aria-current="page"] { color: var(--brand); font-weight: 600; }
.tabbar .tab-add .ic { background: var(--brand); color: var(--brand-ink); border-radius: 50%; width: 34px; height: 34px; display: grid; place-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
.hint { background: var(--info-bg); }
.hero { background: var(--brand); color: var(--brand-ink); border-radius: var(--radius); padding: 20px 18px; margin-bottom: 14px; text-align: center; }
.hero.neg { background: var(--out); color: #fff; }
.hero-label { opacity: .85; font-size: .9rem; text-transform: uppercase; letter-spacing: .08em; }
.hero-amount { font-size: clamp(2rem, 9vw, 3rem); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.hero-amount span { font-size: .45em; font-weight: 600; }
.hero-warn { margin-top: 4px; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 16px; align-items: center; }
.actions form { margin: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { background: var(--out); border-color: var(--out); color: #fff; }
.btn.in { background: var(--in); border-color: var(--in); color: #fff; }
.btn.out { background: var(--out); border-color: var(--out); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.in, .btn.out, .btn.danger { color: #10100f; } }
.btn.big { flex: 1; min-height: 56px; font-size: 1.05rem; }
.btn.block { width: 100%; }
.flash { padding: 10px 14px; border-radius: 10px; margin: 0 0 14px; background: var(--ok-bg); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.err { background: var(--err-bg); }
.flash.info { background: var(--info-bg); }
.form label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; font-weight: 600; font-size: .95rem; }
.form label em, label em { font-weight: 400; font-style: normal; color: var(--muted); }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  min-height: 44px; padding: 8px 12px; width: 100%; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); }
input[type=file] { padding: 8px; }
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; } .row > label { min-width: 0; } .grow { flex: 1 1 140px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.inline.form label { margin: 0; }
.form.inline { align-items: flex-end; }
.error { color: var(--out); font-weight: 600; font-size: .9rem; }
.help { color: var(--muted); font-weight: 400; font-size: .88rem; }
.preview { font-size: 1.15rem; font-weight: 700; min-height: 1.6em; margin: -4px 0 12px; color: var(--brand); font-variant-numeric: tabular-nums; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line);
  color: var(--text); text-decoration: none; }
.item:last-child { border-bottom: 0; }
a.item:active { background: var(--bg); }
.item-main { display: flex; flex-direction: column; min-width: 0; }
.item-title { font-weight: 600; }
.item-sub { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-amt { display: flex; flex-direction: column; align-items: flex-end; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item.deleted { opacity: .55; } .item.deleted .item-title { text-decoration: line-through; }
.item.cat { flex-wrap: wrap; } .item.cat input { width: auto; flex: 1 1 140px; } .item.inactive { opacity: .6; }
.item.month { flex-wrap: wrap; }
.menu .item { min-height: 54px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.big-amt { font-size: 1.8rem; font-weight: 700; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.receipt img, .receipt-current img { max-width: 100%; max-height: 420px; border-radius: 10px; border: 1px solid var(--line); display: block; margin: 8px 0; }
.receipt-current img { max-height: 160px; }
.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.monthnav h1 { margin: .4rem 0; text-align: center; font-size: 1.25rem; }
.filters { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 8px 0 12px; }
.filters select { width: auto; }
.badge { font-size: .9em; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px 8px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.data th, .data td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: .92rem; }
.data thead th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.data tfoot td { font-weight: 600; } .data tr.total td, .summary tr.total th, .summary tr.total td { font-weight: 700; border-top: 2px solid var(--text); }
.data.wide { font-size: .85rem; }
.num { text-align: right !important; white-space: nowrap; } .nowrap { white-space: nowrap; }
.summary { max-width: 420px; } .summary th { text-align: left; font-weight: 500; padding: 6px 0; } .summary td { padding: 6px 0; }
.audit { list-style: none; margin: 0; padding: 0; }
.audit li { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.changes { margin-top: 6px; font-size: .9rem; } .changes th { text-align: left; color: var(--muted); font-weight: 500; padding: 2px 10px 2px 0; width: 1%; white-space: nowrap; vertical-align: top; }
.changes td { overflow-wrap: anywhere; } del { color: var(--out); } ins { color: var(--in); text-decoration: none; }
.login { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login img { border-radius: 18px; } .login h1 { margin-bottom: 1.2rem; } .login form { text-align: left; }
.danger-zone { border-color: var(--out); }
[hidden] { display: none !important; }
@media (min-width: 700px) { .tabbar { justify-content: center; } .tabbar a { flex: 0 0 120px; } }
