:root {
  --bg: #f4f5f2; --card: #ffffff; --ink: #1d2a26; --muted: #6a7570; --line: #dfe3dd;
  --accent: #1f6f5c; --accent-ink: #ffffff; --accent-soft: #e3f1ed;
  --danger: #b3382c; --warn-bg: #fff4d6; --warn-ink: #7a5600; --err-bg: #fde7e4; --ok-bg: #e3f1ed;
  --ess: #1f6f5c; --nec: #c58a1b; --dis: #8a6fb0;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191a; --card: #1d2424; --ink: #e8eeea; --muted: #94a09a; --line: #2f3a38;
    --accent: #4fb89d; --accent-ink: #0c1512; --accent-soft: #20322e;
    --danger: #ef7d70; --warn-bg: #3a3014; --warn-ink: #f1d38a; --err-bg: #3a1f1c; --ok-bg: #1f3530;
  }
}
* { box-sizing: border-box; }
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(--accent); }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
h3 { margin: 0; font-size: 1rem; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .warn { color: var(--warn-ink); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1.2rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand .mark { display: grid; place-items: center; width: 28px; height: 28px; background: var(--accent); color: var(--accent-ink); border-radius: 7px; font-size: .95rem; }
nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; padding: .2rem 0; border-bottom: 2px solid transparent; }
nav a.on, nav a:hover { color: var(--ink); border-bottom-color: var(--accent); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 1.2rem 1rem 5rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.narrow { max-width: 460px; margin: 2rem auto; } .card.narrow-l { max-width: 460px; }
.head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.head-row h1 { margin-bottom: .2rem; }
.client-line { margin: 0; color: var(--muted); }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }

label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
input, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: .45rem .6rem; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.inline-form { display: flex; gap: .8rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { flex: 1 1 180px; }
form.inline { display: inline-flex; gap: .3rem; align-items: center; margin: 0; }
.search { display: flex; gap: .4rem; }

.btn, button.link { font: inherit; cursor: pointer; }
.btn { display: inline-block; background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); border-radius: 8px; padding: .5rem 1rem; text-decoration: none; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); filter: none; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: .25rem .6rem; font-size: .82rem; }
button.link { background: none; border: 0; color: var(--muted); padding: 0; }
button.link:hover { color: var(--ink); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--ok-bg); }
.flash.err { background: var(--err-bg); color: var(--danger); } .flash.warn { background: var(--warn-bg); color: var(--warn-ink); }

table { border-collapse: collapse; width: 100%; }
table.list th, table.list td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); }
table.list th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.list tfoot td { font-weight: 600; border-bottom: 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
td.actions, th.actions { text-align: right; white-space: nowrap; }
.mini { width: 120px; padding: .25rem .5rem; font-size: .82rem; }

/* Budget editor */
.client-card { display: flex; gap: .8rem; flex-wrap: wrap; } .client-card label { flex: 0 1 220px; } .client-card .grow { flex: 1 1 260px; }
.summary { display: grid; grid-template-columns: repeat(5, 1fr); gap: .6rem; position: sticky; top: 54px; z-index: 10; margin-bottom: .8rem; background: var(--bg); padding: .5rem 0; }
.summary div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem .8rem; box-shadow: 0 2px 6px rgba(0,0,0,.04); }
.summary span { display: block; font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.summary strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; } .summary small { font-weight: 400; color: var(--muted); font-size: .72rem; display: block; }
.hint { color: var(--muted); font-size: .88rem; max-width: 80ch; }
.cat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; padding: .8rem 1rem 1rem; }
.cat > header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .4rem; }
.cat-total { color: var(--muted); font-variant-numeric: tabular-nums; } .cat-total b { color: var(--ink); }
.scroll { overflow-x: auto; }
table.grid { min-width: 760px; margin-bottom: .5rem; }
table.grid th { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; text-align: left; padding: .2rem .3rem; font-weight: 600; }
table.grid td { padding: .2rem .3rem; }
table.grid input, table.grid select { width: 100%; padding: .35rem .45rem; }
.c-name { width: 30%; } .c-amt { width: 14%; } .c-cls { width: 15%; } .c-f { width: 8%; } .c-cap { width: 13%; } .c-x { width: 34px; }
.c-f input { text-align: center; padding-left: .2rem !important; padding-right: .2rem !important; }
.c-amt input, .c-cap input { text-align: right; }
button.x { background: none; border: 0; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; border-radius: 6px; width: 28px; height: 28px; }
button.x:hover { color: var(--danger); background: var(--err-bg); }
.savebar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: .6rem 1rem; display: flex; justify-content: flex-end; align-items: center; gap: .6rem; z-index: 15; }

/* Results */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; } .grid-2 .card { margin-bottom: 0; }
.result > header { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .5rem; }
.result .big { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; } .result .big small { font-size: .75rem; color: var(--muted); font-weight: 400; }
.result.current { border-color: var(--accent); }
.bars { display: grid; gap: .55rem; }
.bar-row { display: grid; grid-template-columns: 220px 1fr 240px; align-items: center; gap: .8rem; }
.bar-track { background: var(--bg); border-radius: 99px; height: 14px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; } .bar-val small { color: var(--muted); }

@media (max-width: 800px) {
  .summary { grid-template-columns: repeat(2, 1fr); position: static; }
  .grid-2 { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr; gap: .2rem; } .bar-val { text-align: left; }
}

@media print {
  body { background: #fff; color: #000; font-size: 12px; }
  .no-print { display: none !important; }
  .card { border: 1px solid #bbb; break-inside: avoid; }
  .wrap { padding: 0; max-width: none; }
  .bar-fill { background: #333 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
