:root {
  --bg: #f4f1ea; --surface: #fbfaf6; --raised: #ffffff; --text: #1b211d; --muted: #6a736c; --faint: #e7e3d8;
  --good: #1f7a4d; --bad: #b5432c; --warn: #96690c; --accent: #1f7a4d; --on-accent: #ffffff;
  --r: 18px; --gap: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1412; --surface: #161c19; --raised: #1c2420; --text: #e8ece6; --muted: #8d968f; --faint: #242d28;
    --good: #7fd1a3; --bad: #f0876f; --warn: #e6b85c; --accent: #7fd1a3; --on-accent: #0f1412; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
main { max-width: 760px; margin: 0 auto; display: grid; gap: 22px; }
[data-module], .page { display: grid; gap: 22px; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; white-space: nowrap; }
.muted { color: var(--muted); } .good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.small { font-size: 13px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.top h1 { font-size: 15px; font-weight: 600; letter-spacing: .02em; color: var(--muted); text-transform: uppercase; }
button { font: inherit; color: inherit; border: 0; border-radius: 999px; padding: 10px 16px; min-height: 44px; background: var(--raised); cursor: pointer; }
button.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
button:disabled { opacity: .6; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hero { background: var(--surface); border-radius: var(--r); padding: 22px 20px; display: grid; gap: 18px; }
.hero .label { font-size: 13px; color: var(--muted); }
.hero .net { font-size: clamp(38px, 11vw, 56px); font-weight: 650; line-height: 1.05; letter-spacing: -.02em; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--raised); border-radius: 14px; padding: 12px; min-width: 0; }
.stat .v { font-size: clamp(15px, 4.4vw, 20px); font-weight: 600; }

.notice { background: var(--surface); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 4px; }
.notice strong { font-weight: 600; }

section { display: grid; gap: 10px; }
section > header { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px; }
section h2 { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.list { display: grid; gap: var(--gap); }
.row { background: var(--surface); border-radius: var(--r); padding: 16px; display: grid; gap: 10px; }
.row .line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.row .name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.row .amt { font-size: 20px; font-weight: 650; }
.row.stale .amt { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--raised); color: var(--muted); }
.chip.bad { color: var(--bad); } .chip.warn { color: var(--warn); }
.bar { height: 6px; border-radius: 999px; background: var(--faint); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--muted); }
.bar.hot > i { background: var(--bad); } .bar.mid > i { background: var(--warn); }

.sources { background: var(--surface); border-radius: var(--r); padding: 6px 16px; }
.src { display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); }
.dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); } .dot.none { background: var(--faint); }
.src button { padding: 6px 12px; min-height: 36px; font-size: 13px; }
.src .err { grid-column: 2 / -1; margin-top: -6px; }

.pair { min-height: 70vh; display: grid; place-content: center; gap: 16px; text-align: center; }
.pair input { font: inherit; font-size: 28px; letter-spacing: .3em; text-align: center; width: min(280px, 80vw); padding: 14px; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--text); }
.spin { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; vertical-align: -2px; margin-right: 6px; animation: s .8s linear infinite; }
@keyframes s { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
@media (min-width: 620px) { .list.two { grid-template-columns: 1fr 1fr; } }

/* --- shell: sidebar on wide screens, drawer on phones --- */
body.shell { padding: 0; }
body.shell main { max-width: none; margin: 0; display: block; }
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) 16px 10px; }
.bar-title { font-weight: 600; }
.menu { padding: 8px 14px; min-height: 40px; background: var(--surface); }
#nav { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(290px, 84vw); background: var(--surface); overflow-y: auto;
  padding: calc(20px + env(safe-area-inset-top)) 14px 28px; transform: translateX(-102%); transition: transform .18s ease; }
.nav-open #nav { transform: none; }
.scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .45); display: none; }
.nav-open .scrim { display: block; }
.nav-title { font-size: 19px; font-weight: 650; padding: 4px 12px 10px; }
.nav-sub { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 16px 12px 6px; }
#nav a { display: flex; align-items: center; min-height: 44px; padding: 8px 12px; border-radius: 12px; color: var(--text); text-decoration: none; }
#nav a:hover { background: var(--raised); }
#nav a.active { background: var(--raised); font-weight: 600; color: var(--accent); }
#nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav-group a { padding-left: 20px; }
#view { padding: 6px 16px calc(40px + env(safe-area-inset-bottom)); max-width: 820px; margin: 0 auto; }
@media (prefers-reduced-motion: reduce) { #nav { transition: none; } }
@media (min-width: 900px) {
  .bar, .scrim { display: none !important; }
  #nav { transform: none; width: 250px; }
  #view { margin-left: 250px; padding: 28px 28px 48px; max-width: 1080px; }
}

/* --- money views --- */
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.pagehead h1 { font-size: 22px; font-weight: 650; }
.cards3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border-radius: var(--r); padding: 14px 16px; min-width: 0; }
.tile .label { font-size: 13px; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 650; }
.group { background: var(--surface); border-radius: var(--r); padding: 4px 16px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 13px 0; align-items: baseline; }
.item + .item { box-shadow: 0 -1px 0 var(--faint); }
.item .t { font-weight: 600; overflow-wrap: anywhere; }
.item .a { font-weight: 650; text-align: right; }
.item .s { grid-column: 1 / -1; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--raised); color: var(--muted); }
.tag.bad { color: var(--bad); } .tag.warn { color: var(--warn); } .tag.good { color: var(--good); }
.empty { color: var(--muted); padding: 14px 0; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { padding: 6px 14px; min-height: 38px; font-size: 14px; background: var(--surface); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.bars { display: grid; gap: 10px; padding: 12px 0; }
.bars .b { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bars .b .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .track { height: 8px; border-radius: 999px; background: var(--faint); overflow: hidden; }
.bars .track i { display: block; height: 100%; border-radius: 999px; background: var(--accent); }

.cal-head, .cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-head span { font-size: 12px; color: var(--muted); text-align: center; padding: 2px 0; }
.day { background: var(--surface); border: 0; border-radius: 12px; min-height: 62px; padding: 6px 5px; text-align: left; display: grid; align-content: start; gap: 2px;
  color: inherit; font: inherit; cursor: pointer; min-width: 0; }
.day.blank { background: none; cursor: default; }
.day .d { font-size: 12px; color: var(--muted); }
.day.today .d { color: var(--accent); font-weight: 700; }
.day.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.day .amt { font-size: 11px; font-weight: 650; overflow: hidden; text-overflow: clip; white-space: nowrap; }
.day .dots { display: flex; gap: 3px; flex-wrap: wrap; }
.day .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.dots i.loan { background: var(--bad); } .dots i.card { background: var(--warn); } .dots i.payroll { background: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.legend i.loan { background: var(--bad); } .legend i.card { background: var(--warn); } .legend i.payroll { background: var(--accent); }
@media (min-width: 620px) { .day { min-height: 78px; padding: 8px; } .day .amt { font-size: 13px; } }

/* --- tables --- */
.tablewrap { container-type: inline-size; overflow-x: auto; max-width: 100%; padding: 4px 0; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 10px 8px; text-align: left; vertical-align: top; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
th { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .03em; padding-top: 6px; padding-bottom: 8px; vertical-align: bottom; }
th.r, td.r { text-align: right; }
td.num, .nw { white-space: nowrap; }
td { overflow-wrap: break-word; hyphens: none; }
td:not(.r) { min-width: 5.5em; }
/* the name column stays put when a wide table scrolls sideways */
th:first-child, td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
td:first-child { font-weight: 600; min-width: 9.5em; }
tbody tr + tr td { border-top: 1px solid var(--faint); }
tfoot td { font-weight: 650; border-top: 1px solid var(--muted); }
details > summary.small { cursor: pointer; padding: 8px 0; color: var(--muted); }

/* When the space for a table is narrow (a phone, or a tight column next to
   the sidebar), each row becomes a card of "label   value" lines. */
@container (max-width: 600px) {
  table, thead, tbody, tfoot, tr, td { display: block; width: auto; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr { padding: 12px 0; }
  tbody tr + tr, tfoot tr { border-top: 1px solid var(--faint); }
  tfoot tr { border-top-color: var(--muted); }
  tbody tr + tr td, tfoot td { border-top: 0; }
  td, td.r { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 3px 0; min-width: 0; text-align: right; position: static; }
  td::before { content: attr(data-label); flex: none; max-width: 55%; text-align: left; white-space: normal; color: var(--muted); font-size: 13px; font-weight: 400; }
  td:first-child { display: block; text-align: left; font-size: 16px; min-width: 0; padding-bottom: 5px; position: static; }
  td:first-child::before { content: none; }
  td.empty { display: none; }
  td:not(.r) { min-width: 0; }
}
details.row > summary { list-style: none; cursor: pointer; display: grid; gap: 8px; }
details.row > summary::-webkit-details-marker { display: none; }
details.row > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 8px; }
details.row[open] > summary { margin-bottom: 4px; }
/* wide tables scroll inside their card, never the page */
#view, [data-module], .page, .page > *, section, .list, .group, .row, details.row > * { min-width: 0; }
.page, .list, section { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 620px) { .list.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* --- sign-in and setup --- */
.auth { max-width: 360px; margin: 8vh auto 0; display: grid; gap: 14px; padding: 0 16px; }
.auth h1 { font-size: 24px; font-weight: 650; margin-bottom: 4px; }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.field input { font: inherit; font-size: 17px; padding: 12px 14px; border: 0; border-radius: 12px; background: var(--surface); color: var(--text); width: 100%; }
.auth button { width: 100%; }
.qr { justify-self: center; border-radius: 12px; background: #fff; }
.key { display: block; font-size: 15px; letter-spacing: .06em; word-break: break-all; padding: 8px 0; color: var(--text); }
.signout { margin: 22px 12px 0; padding: 8px 14px; min-height: 40px; font-size: 14px; background: var(--raised); color: var(--muted); }
