:root {
  --bg: #eef1f0;
  --surface: #ffffff;
  --ink: #14211e;
  --muted: #58696a;
  --line: #d3dbd9;
  --accent: #1f3fbf;
  --accent-ink: #ffffff;
  --accent-soft: #e4e9fb;
  --warn: #9a5b00;
  --warn-soft: #fbf0d9;
  --bad: #a3271f;
  --bad-soft: #fbe6e3;
  --ok: #1d6b45;
  --ok-soft: #e0f1e8;
  --sans: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --serif: Charter, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1615; --surface: #172120; --ink: #e6efec; --muted: #94a6a3; --line: #2b3a38;
    --accent: #8ea2ff; --accent-ink: #0d1330; --accent-soft: #1d2647;
    --warn: #f0b95a; --warn-soft: #34290f; --bad: #ff8b80; --bad-soft: #3a1b18; --ok: #6fd6a0; --ok-soft: #12301f;
  }
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); line-height: 1.5; font-variant-numeric: tabular-nums; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.2rem; margin-top: 2rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .8rem; max-width: 70ch; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* shell */
.shell { display: grid; grid-template-columns: 13.5rem minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 1.25rem 1rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1rem; }
.brand { font-family: var(--serif); font-size: 1.15rem; font-weight: 700; text-decoration: none; color: var(--ink); }
.side nav { display: flex; flex-direction: column; gap: .15rem; }
.side nav a { padding: .45rem .6rem; border-radius: 6px; color: var(--ink); text-decoration: none; }
.side nav a:hover { background: var(--bg); }
.side nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side form { margin-top: auto; }
main { min-width: 0; padding: 1.75rem clamp(1rem, 3vw, 2.5rem) 4rem; max-width: 74rem; width: 100%; }
@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: .6rem .8rem; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .side form { margin: 0 0 0 auto; }
}

/* messages */
.flash { padding: .65rem .9rem; border-radius: 6px; margin-bottom: 1rem; background: var(--ok-soft); color: var(--ok); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.bad { background: var(--bad-soft); color: var(--bad); }

/* forms */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .5rem .6rem; width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox] { width: auto; }
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: .5rem 1rem; text-decoration: none; display: inline-block; }
button.quiet, .btn.quiet { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--bad); border-color: var(--line); }
button.small, .btn.small { padding: .2rem .55rem; font-size: .85rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }
.row > div { flex: 1 1 9rem; }
.row > .wide { flex: 3 1 14rem; }
.row > .mid { flex: 2 1 12rem; }
.row > .fit { flex: 0 0 auto; }

/* quick add: the one thing this app is for */
.quick { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 1rem 1.1rem; }
.quick summary { cursor: pointer; color: var(--muted); font-size: .9rem; margin-top: .8rem; }
.quick .more { margin-top: .6rem; }
.quick #amount { font-family: var(--serif); font-size: 1.25rem; }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; font-size: .85rem; color: var(--muted); background: color-mix(in srgb, var(--bg) 60%, var(--surface)); }
th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: color-mix(in srgb, var(--bg) 60%, var(--surface)); }
.scroll { overflow-x: auto; }
.actions { display: flex; gap: .4rem; align-items: center; }
.actions form { margin: 0; }

/* budget lines */
.budget { display: grid; gap: .7rem; }
.budget-row { display: grid; grid-template-columns: 11rem 1fr 10rem; gap: .8rem; align-items: center; }
.bar { height: .7rem; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.over > span { background: var(--bad); }
.bar.none > span { background: var(--muted); opacity: .55; }
@media (max-width: 640px) { .budget-row { grid-template-columns: 1fr; gap: .2rem; } }

.headline { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin: 1.5rem 0 1rem; }
.headline .big { font-family: var(--serif); font-size: 2.6rem; font-weight: 700; line-height: 1; }

/* badges */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--line); color: var(--ink); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
.login { max-width: 22rem; margin: 12vh auto; }
.login .panel { padding: 1.4rem; }
.login form > * + * { margin-top: .8rem; }
.only-print { display: none; }

@media print {
  body { background: #fff; color: #000; }
  .side, .no-print, .flash { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  table, .panel { border-color: #999; }
  .only-print { display: block; }
  a { color: #000; text-decoration: none; }
}
@media (prefers-reduced-motion: no-preference) { button, .btn, .bar > span { transition: background-color .15s, width .3s; } }

.draft { display: grid; grid-template-columns: 12rem minmax(0, 1fr); gap: 1.2rem; }
.draft .thumb img { width: 100%; max-height: 15rem; object-fit: contain; object-position: top left; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
@media (max-width: 700px) { .draft { grid-template-columns: 1fr; } .draft .thumb img { max-height: 11rem; } }

.setup { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.setup .qr svg { display: block; width: auto; height: auto; max-width: 100%; shape-rendering: crispEdges; }
.key { font-size: 1rem; letter-spacing: .05em; overflow-wrap: anywhere; }
.codes { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .6rem; }
.codes code { font-size: 1.15rem; }
@media (max-width: 700px) { .setup { grid-template-columns: 1fr; } }
