:root {
  --bg: #f6f7f5; --panel: #ffffff; --ink: #1d2421; --muted: #5d6762; --line: #e1e5e2; --soft: #eef2ef;
  --brand: #1f6f5c; --brand-ink: #ffffff; --brand-soft: #e2f0eb;
  --in: #1d7a4f; --out: #b2412f; --warn: #9a6400; --warn-soft: #fff4dc; --bad-soft: #fde9e5;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614; --panel: #1a201d; --ink: #e6ebe8; --muted: #9aa59f; --line: #2c3430; --soft: #222a26;
    --brand: #4fb393; --brand-ink: #0d1411; --brand-soft: #1e332b;
    --in: #5cc98f; --out: #f08a76; --warn: #f0b54a; --warn-soft: #33290f; --bad-soft: #3a1f1a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121614; --panel: #1a201d; --ink: #e6ebe8; --muted: #9aa59f; --line: #2c3430; --soft: #222a26;
  --brand: #4fb393; --brand-ink: #0d1411; --brand-soft: #1e332b;
  --in: #5cc98f; --out: #f08a76; --warn: #f0b54a; --warn-soft: #33290f; --bad-soft: #3a1f1a; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; overflow-x: hidden; }
a { color: var(--brand); }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
p { margin: .3rem 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.loading { padding: 2rem; color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.in { color: var(--in); } .out { color: var(--out); }

/* top bar */
.top { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-row { display: flex; align-items: center; gap: .75rem; padding: .55rem 1rem; flex-wrap: wrap; max-width: 1240px; margin: 0 auto; }
.brand { font-weight: 700; display: flex; align-items: center; gap: .5rem; text-decoration: none; color: var(--ink); }
.brand img { width: 26px; height: 26px; }
.who { margin-left: auto; display: flex; gap: .6rem; align-items: center; font-size: .86rem; color: var(--muted); }
.switch { display: flex; gap: .4rem; align-items: center; min-width: 0; }
.switch select { max-width: 260px; }
nav.tabs { display: flex; gap: .2rem; padding: 0 1rem; max-width: 1240px; margin: 0 auto; flex-wrap: wrap; }
nav.tabs a { padding: .55rem .75rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
nav.tabs a.on { color: var(--ink); border-color: var(--brand); }
nav.tabs .count { background: var(--out); color: #fff; border-radius: 999px; padding: 0 .4rem; font-size: .75rem; margin-left: .25rem; }
.banner { background: var(--warn-soft); color: var(--ink); padding: .45rem 1rem; text-align: center; font-size: .88rem; }

main { max-width: 1240px; margin: 0 auto; padding: 1.2rem 1rem 4rem; }
.head { display: flex; gap: 1rem; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }

/* panels and tiles */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
.grid2 > * { min-width: 0; }
.grid2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.tile .label { color: var(--muted); font-size: .85rem; }
.tile .value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: .82rem; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: .75rem; padding: .45rem 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.ok { color: var(--in); } .warn { color: var(--warn); } .bad { color: var(--out); }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--soft); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--brand-soft); color: var(--brand); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--out); }

/* forms */
label { display: block; font-size: .84rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.row > div { flex: 1 1 160px; min-width: 0; }
.row > .narrow { flex: 0 1 130px; }
.check { display: flex; gap: .4rem; align-items: center; color: var(--ink); font-size: .9rem; }
.check input { width: auto; }
.btn { display: inline-flex; align-items: center; gap: .3rem; padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: .2rem .55rem; font-size: .84rem; }
.btn.danger { color: var(--out); }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg a, .seg button { padding: .4rem .8rem; text-decoration: none; color: var(--muted); border: 0; background: var(--panel); cursor: pointer; }
.seg .on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.err { color: var(--out); font-size: .9rem; min-height: 1.2em; }

/* tables */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .45rem .55rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
tr.section td { font-weight: 650; background: var(--soft); }
tr.subtotal td { font-weight: 600; border-top: 1px solid var(--muted); }
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 3px double var(--ink); }
td.indent1 { padding-left: 1.4rem; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--soft); }
.report h2 { margin: 0; }
.report .rhead { text-align: center; margin-bottom: .8rem; }

/* bank review */
.bank-line { display: grid; grid-template-columns: 26px minmax(0, 1fr) 110px minmax(170px, 230px) minmax(120px, 160px) auto; gap: .5rem; align-items: center; padding: .55rem .4rem; border-top: 1px solid var(--line); }
.bank-line.headrow { font-size: .8rem; color: var(--muted); font-weight: 600; border-top: 0; }
.bank-line .desc { min-width: 0; overflow-wrap: anywhere; }
.bank-line .hint { font-size: .78rem; color: var(--muted); }
.bank-line input[type=checkbox] { width: auto; }

/* chart */
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 1rem; font-size: .84rem; color: var(--muted); }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; }
.key.inc { background: var(--brand); } .key.exp { background: var(--out); }
.bar-inc { fill: var(--brand); } .bar-exp { fill: var(--out); opacity: .85; }
.axis { fill: var(--muted); font-size: 11px; }
.gridline { stroke: var(--line); }

.meter { margin-top: .5rem; } .meter svg { width: 100%; height: 6px; display: block; }
.meter-bg { fill: var(--soft); } .meter-fill { fill: var(--brand); }
details summary { cursor: pointer; color: var(--brand); margin: .6rem 0; }

/* dialog and toast */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 1.2rem; background: var(--panel); color: var(--ink); width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(0,0,0,.35); }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .55rem 1rem; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100vw - 32px); z-index: 20; }
#toast.show { opacity: 1; }

/* sign in */
body.signin, .signin-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.narrow { max-width: 420px; width: 100%; }
.pick { display: block; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 10px; margin: .6rem 0; text-decoration: none; color: var(--ink); }
.pick:hover { border-color: var(--brand); background: var(--brand-soft); }
.pick strong { display: block; } .pick span { color: var(--muted); font-size: .9rem; }

.entry-line { display: grid; grid-template-columns: minmax(160px, 2fr) 110px 110px minmax(120px, 1fr) minmax(120px, 1.2fr) 32px; gap: .4rem; margin-bottom: .4rem; }
.entry-line.headrow { font-size: .8rem; color: var(--muted); font-weight: 600; }
.totals { display: flex; justify-content: flex-end; gap: 1.5rem; padding: .4rem 0; font-weight: 600; }

@media print {
  .top, .banner, .actions, .seg, form#rf, nav { display: none !important; }
  body, .card { background: #fff; color: #000; box-shadow: none; border: 0; }
}

@media (max-width: 760px) {
  main { padding: 1rem 16px 4rem; }
  .top-row { padding: .5rem 16px; }
  nav.tabs { padding: 0 8px; overflow-x: auto; flex-wrap: nowrap; }
  nav.tabs a { padding: .5rem .55rem; flex: 0 0 auto; }
  .who .name { display: none; }
  .switch { width: 100%; order: 3; }
  .switch select { max-width: none; flex: 1; }
  .bank-line { grid-template-columns: 26px 1fr auto; grid-template-areas: "c d a" "c cat cat" "c loc loc" "c act act"; }
  .bank-line > .c { grid-area: c; } .bank-line > .d { grid-area: d; } .bank-line > .a { grid-area: a; }
  .bank-line > .cat { grid-area: cat; } .bank-line > .loc { grid-area: loc; } .bank-line > .act { grid-area: act; }
  .bank-line.headrow { display: none; }
  .entry-line { grid-template-columns: 1fr 1fr; }
  .entry-line > .acct, .entry-line > .memo { grid-column: 1 / -1; }
  .entry-line.headrow { display: none; }
  .hide-phone { display: none; }
}
/* QuickBooks screen */
.note { background: var(--brand-soft); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.actions.wrap { flex-wrap: wrap; }
.qbout ul { margin: 4px 0 8px 18px; padding: 0; }
