:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #5d6b7c;
  --line: #dde3ea;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --red: #c62828;
  --red-bg: #fde8e8;
  --amber: #a15c00;
  --amber-bg: #fff4de;
  --green: #1b7a3d;
  --blue: #1a5fb4;
  --row-dep: #dff3e3;
  --row-groc: #dcecfb;
  --row-gas: #ebe2f7;
  --row-rent: #ecdfd0;
  --row-late: #ffd9a8;
  --orange: #b45309;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --card: #1a222b;
    --ink: #e8edf2;
    --muted: #9aa8b8;
    --line: #2b3643;
    --accent: #2ab3a6;
    --accent-ink: #06201d;
    --red: #ff7b7b;
    --red-bg: #3a1c1f;
    --amber: #f0b256;
    --amber-bg: #34290f;
    --green: #5fd18a;
    --blue: #6cb2ff;
    --row-dep: #1d3a27;
    --row-groc: #1b3248;
    --row-gas: #2f2644;
    --row-rent: #3d2f22;
    --row-late: #4d3410;
    --orange: #ffb25b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.4; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: min(360px, 100%); display: grid; gap: 12px; }
.msg-err { color: var(--red); min-height: 1.2em; margin: 0; font-size: .9rem; }

/* layout */
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.sticky-stack { position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 1.1rem; margin: 0; white-space: nowrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 8px 12px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.tab[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.menu-btn { display: none; }
/* On a phone the tabs fold into a menu, so nothing has to be scrolled sideways. */
@media (max-width: 820px) {
  .top { position: relative; z-index: 6; }
  .menu-btn { display: inline-flex; align-items: center; gap: 8px; margin-right: auto; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: inherit; font: inherit; font-weight: 600; cursor: pointer; }
  .tabs { display: none; }
  .top.menu-open .tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; position: absolute; top: 100%; left: 0; right: 0; padding: 8px 16px 12px; background: var(--card); border-bottom: 1px solid var(--line); max-height: calc(100vh - 70px); overflow-y: auto; }
  .top.menu-open .tab { min-height: 44px; text-align: left; }
}
main { max-width: 980px; margin: 0 auto; padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
main > *, .grid > * { min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 12px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: .85rem; }
.stat.bad .value { color: var(--red); }
.stat.good .value { color: var(--green); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }

/* forms */
label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
input, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: .95rem; }
.check input { width: auto; }
.btn { font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 8px; font-size: .85rem; }

/* tables */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; }
td input.amt { width: 7.5em; text-align: right; padding: 4px 6px; }
td input.gross { width: 6.5em; padding: 2px 6px; font-size: .8rem; margin-left: 4px; }
.sub-name { color: var(--muted); font-size: .8rem; }
tr.lowest td.bal, tr.lowest td.bal strong { color: var(--red); font-weight: 400; }
tr.monthlow td.bal { color: var(--amber); font-weight: 700; }
tr.neg td.bal { color: var(--red); }
tr.derived td:nth-child(2) { color: var(--muted); }
tr.past td:first-child { color: var(--red); }
.tag { display: inline-block; font-size: .7rem; padding: 1px 6px; border-radius: 999px; background: var(--amber-bg); color: var(--amber); margin-left: 6px; vertical-align: middle; }
.sync { color: var(--muted); font-size: .8rem; margin-left: auto; margin-right: 8px; }
.sync.bad { color: var(--red); font-weight: 600; }
.cloud-card { min-width: min(92vw, 420px); }
.tag.debit { background: var(--blue-bg, var(--amber-bg)); color: var(--blue, var(--amber)); }
.tag.red { background: var(--red-bg); color: var(--red); }
.dep { color: var(--green); }
.big { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.pill-ok { color: var(--green); font-weight: 700; }
.pill-bad { color: var(--red); font-weight: 700; }
.notice { background: var(--amber-bg); color: var(--amber); border-radius: 8px; padding: 10px 12px; font-size: .9rem; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); width: min(560px, calc(100vw - 24px)); padding: 16px; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; }

@media (max-width: 640px) {
  .top h1 { display: none; }
  main { padding: 10px; }
  th, td { padding: 6px 4px; }
  td input.amt { width: 6.2em; }
}
.flyout > td { background: var(--bg); padding: 8px 12px 12px; }
.weeks th, .weeks td { font-size: .9rem; }
/* Amounts to Consider: tight columns so the whole table fits without sliding sideways */
.amounts th, .amounts td { padding: 6px 4px; font-size: .85rem; }
.amounts td .btn.small { padding: 2px 6px; font-size: .8rem; }
.amounts .tag { margin-left: 0; }
/* Same column widths for months and weeks, so the numbers line up. Below the minimum width the table scrolls sideways. */
.amounts { table-layout: fixed; min-width: 800px; }
.amounts.hy { min-width: 940px; }
.amounts > tbody > .flyout > td { padding: 8px 0 12px; }
.amounts > tbody > .flyout p { padding: 0 4px; }
.flyout > td { padding-left: 4px; padding-right: 4px; }
/* the long sentences under a month must wrap instead of stretching the whole table */
#view tr.splitrow > td:first-child, #view tr.flyout > td:first-child { white-space: normal; }
#log-jump, #cleared-log { scroll-margin-top: 110px; }
tr.is-dep:not(.neg) td, tr.is-dep.lowest td { background: var(--row-dep); }
tr.is-groc:not(.neg) td, tr.is-groc.lowest td { background: var(--row-groc); }
tr.is-gas:not(.neg) td, tr.is-gas.lowest td { background: var(--row-gas); }
tr.is-rent:not(.neg) td, tr.is-rent.lowest td { background: var(--row-rent); }
tr.is-dep td.dep { color: var(--ink); }
tr.neg:not(.lowest) td { background: var(--red-bg); }
.negbar { background: var(--red-bg); color: var(--red); border-bottom: 2px solid var(--red); padding: 8px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 600; }
.negbar[hidden] { display: none; }
#neg-first { scroll-margin-top: 170px; }
tr.pastdue:not(.neg) td { background: var(--row-late); }
.tag.orange { background: var(--row-late); color: var(--orange); font-weight: 600; }
.duebar { background: var(--row-late); color: var(--orange); border-bottom: 2px solid var(--orange); padding: 8px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 600; }
.duebar[hidden] { display: none; }
.newbar { background: var(--row-groc); color: var(--blue); border-bottom: 2px solid var(--blue); padding: 8px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 600; }
.newbar[hidden] { display: none; }
.hypobar { background: var(--amber-bg); color: var(--amber); border-bottom: 2px solid var(--amber); padding: 8px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 600; }
.hypobar[hidden] { display: none; }
#due-first { scroll-margin-top: 190px; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); min-width: 760px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal-head { padding: 6px 8px; font-weight: 600; font-size: .85rem; color: var(--muted); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cal-day { min-height: 104px; padding: 4px 6px 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; }
.cal-day.outside { background: var(--bg-soft, rgba(128,128,128,.08)); }
.cal-day.today { outline: 2px solid var(--blue); outline-offset: -2px; }
.cal-num { font-size: .8rem; color: var(--muted); }
.chip { font-size: .75rem; line-height: 1.25; padding: 2px 5px; border-radius: 5px; background: var(--row-late-off, rgba(128,128,128,.12)); display: flex; justify-content: space-between; gap: 4px; }
.chip .cn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip b { white-space: nowrap; font-weight: 600; }
.chip i { font-style: normal; font-size: .65rem; color: var(--muted); }
.chip.is-dep { background: var(--row-dep); }
.chip.is-groc { background: var(--row-groc); }
.chip.is-gas { background: var(--row-gas); }
.chip.is-rent { background: var(--row-rent); }
.chip.pastdue { background: var(--row-late); }
.chip.tithe { opacity: .65; }
.cal-bal { margin-top: auto; font-size: .78rem; font-weight: 600; text-align: right; }
.cal-bal.neg { color: var(--red); }
.cal-bal.low { color: var(--orange); }

/* Spending tab */
.spend-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.spend-month { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 104px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); font: inherit; cursor: pointer; font-variant-numeric: tabular-nums; }
.spend-month b { font-size: 1.05rem; }
.spend-month[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.spend-cats { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); align-items: start; }
.spend-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; padding: 0; border: 0; background: none; color: var(--ink); font: inherit; font-size: 1.05rem; cursor: pointer; text-align: left; }
.spend-head b { font-variant-numeric: tabular-nums; }
.spend-bar { height: 8px; margin: 8px 0 6px; border-radius: 4px; background: var(--line); overflow: hidden; }
.spend-bar i { display: block; height: 100%; background: var(--accent); }
.spend-cat select { max-width: 11em; }
.spend-cell { background: linear-gradient(to right, rgba(15, 118, 110, .22) var(--w), transparent var(--w)); }
.spend-h { margin: 16px 0 8px; font-size: 1.1rem; }
tr.spend-sum td { border-top: 2px solid var(--line); }
.linkbtn { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.linkbtn:hover { text-decoration: underline; }
/* The flyout stays as wide as the card shows, even when the table under it scrolls sideways (phone, 12 months). */
.sd { position: sticky; left: 0; width: calc(min(100vw, 980px) - 100px); white-space: normal; }
.sd h3 { margin: 12px 0 6px; font-size: 1rem; }
.sd-top { max-width: 560px; }
.sd-month { padding: 6px 0; border-top: 1px solid var(--line); }
.sd-month .spend-head { font-size: 1rem; }
.sd-month .spend-head:disabled { cursor: default; opacity: .7; }

/* Places still in "Other" (or "Other money in") are shaded light red so they stand out. */
tr.is-other td { background: var(--red-bg); }
.sort-desc { font-size: .78rem; word-break: break-word; max-width: 34ch; }
.sort-bar { position: sticky; top: 56px; z-index: 4; }
.sort-bar .grow { flex: 1; }
.rec-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.rec-list li { display: block; }

/* Settings: the update steps */
.steps { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 12px; }
.step { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; padding: 12px; border: 1px solid var(--line, #ccc); border-radius: 8px; }
.step-main { flex: 1 1 260px; min-width: 0; }
.step-btn { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }

/* a button that looks like a link (How To page) */
.linklike { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: var(--accent, #2563eb); text-decoration: underline; cursor: pointer; }
.linklike:hover { text-decoration: none; }
#view table th, #view table td { vertical-align: top; }

/* Forecast register: keep the buttons on one line, smaller */
td.acts { white-space: nowrap; }
td.acts .btn.small { padding: 2px 7px; font-size: .75rem; }
#view td:first-child { white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: .8rem; color: var(--muted); margin: 6px 0; }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line); margin-right: 4px; vertical-align: -2px; }
.legend .sw.is-dep { background: var(--row-dep); }
.legend .sw.is-groc { background: var(--row-groc); }
.legend .sw.is-gas { background: var(--row-gas); }
.legend .sw.is-rent { background: var(--row-rent); }
.legend .sw.is-late { background: var(--row-late); }
.legend .sw.is-neg { background: var(--red-bg); }
.legend-btn { display: inline-flex; align-items: center; background: none; border: 1px solid transparent; border-radius: 999px; padding: 2px 10px 2px 6px; color: var(--muted); font: inherit; cursor: pointer; }
.legend-btn:hover { border-color: var(--line); }
.legend-btn.on { border-color: var(--accent); color: var(--ink); font-weight: 600; background: color-mix(in srgb, var(--accent) 10%, transparent); }
.arrow { font-size: .8em; margin-right: 4px; }
.arrow.up { color: var(--green); }
.arrow.down { color: var(--red); }

/* a toggle switch */
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .15s; margin: 0; padding: 0; border: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 21px; }
label.check.sub { margin-left: 24px; }
.plain { list-style: none; padding: 0; margin: 8px 0; }
.plain li { margin: 8px 0; }

.switch.off { opacity: .45; cursor: not-allowed; }
.sats .sat-month { display: flex; align-items: center; gap: 10px 18px; flex-wrap: wrap; margin: 10px 0; }
.sats .sat-name { width: 84px; font-weight: 600; }
.sats .row { gap: 10px 18px; }
.sats .switch { white-space: nowrap; }
@media (min-width: 821px) {
  /* One grid for all months, so the switches line up in columns from month to month. */
  .sats { display: grid; grid-template-columns: repeat(6, max-content); gap: 10px 28px; align-items: center; margin: 10px 0; }
  .sats .sat-month, .sats .sat-days { display: contents; }
  .sats .sat-name { grid-column: 1; }
  .sats .sat-days .switch { grid-column: calc(var(--nth) + 1); }
}
.sats .switch input { background: #f4b9b6; } /* off: light red */
.sats .switch input:checked { background: #a9e0b8; } /* on: light green */
.sats .switch.off input { background: var(--line); } /* closed: grey */
.amounts td.hypo { background: color-mix(in srgb, var(--accent, #2f6fed) 8%, transparent); }
