/* =====================================================================
   Finance — "private ledger" design system
   Navy ledger ink on porcelain, brass for plan targets only.
   Bucket colours are information: they mean the same thing everywhere.
   ===================================================================== */
@font-face { font-family: Plex; src: url(fonts/ibm-plex-sans-latin-400-normal.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: Plex; src: url(fonts/ibm-plex-sans-latin-500-normal.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: Plex; src: url(fonts/ibm-plex-sans-latin-600-normal.woff2) format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: Plex; src: url(fonts/ibm-plex-sans-latin-ext-500-normal.woff2) format('woff2'); font-weight: 400 600; unicode-range: U+20A6; }
@font-face { font-family: PlexSerif; src: url(fonts/ibm-plex-serif-latin-500-normal.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: PlexSerif; src: url(fonts/ibm-plex-serif-latin-600-normal.woff2) format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: PlexSerif; src: url(fonts/ibm-plex-serif-latin-ext-500-normal.woff2) format('woff2'); font-weight: 500 600; unicode-range: U+20A6; }

:root {
  --navy: #0F2340; --navy-2: #1A3357; --porcelain: #EEF1F5; --paper: #FFFFFF;
  --rule: #DCE1E8; --rule-2: #E9EDF2; --ink: #14233A; --slate: #5B6779; --mist: #8C96A6;
  --brass: #A8823A; --brass-soft: #E9DFC8;
  --in: #1E6E55; --in-soft: #E3F0EA; --over: #9B2C2C; --over-soft: #F6E4E2;
  --b-giving: #A8823A; --b-saving: #2E7487; --b-investing: #1F3A68; --b-expenditure: #8A94A6;
  --serif: PlexSerif, "Iowan Old Style", Georgia, serif;
  --sans: Plex, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --r-panel: 14px; --r-ctl: 10px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--porcelain); color: var(--ink); font: 400 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
body { min-height: 100dvh; }
#app { min-height: 100dvh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num, .fig { font-variant-numeric: tabular-nums lining-nums; }
.fig { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; }
.muted { color: var(--slate); }
.neg { color: var(--over) !important; }
.pos { color: var(--in) !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top band ---------- */
.band { background: var(--navy); color: #fff; padding-top: env(safe-area-inset-top); position: sticky; top: 0; z-index: 6; }
.band .wrap { display: flex; align-items: center; gap: 12px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; font-weight: 600; letter-spacing: .01em; }
.brand svg { width: 26px; height: 26px; }
.books { display: inline-flex; border: 1px solid #ffffff33; border-radius: 999px; padding: 2px; }
.books button { padding: 5px 13px; border-radius: 999px; font-size: 13px; font-weight: 500; color: #C9D3E3; }
.books button[aria-selected=true] { background: #fff; color: var(--navy); }
.band .icon { color: #C9D3E3; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; }
.band .icon:hover { background: #ffffff14; }
.sync { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid #ffffff40; color: #E6ECF5; }
.sync.off { border-color: #E3B34199; color: #F3D48B; }

/* ---------- page heading ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 22px 0 14px; }
.head h1 { margin: 0; font: 600 24px/1.2 var(--serif); letter-spacing: -.01em; }
.head p { margin: 2px 0 0; color: var(--slate); font-size: 13.5px; }
.monthnav { display: flex; align-items: center; gap: 2px; }
.monthnav button { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: var(--slate); }
.monthnav button:hover:not(:disabled) { background: var(--paper); color: var(--ink); }

/* ---------- panels & ledger rows ---------- */
.panel { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-panel); margin-bottom: 14px; }
.panel > h2 { margin: 0; padding: 14px 16px 10px; font: 600 15px/1.3 var(--serif); color: var(--navy); display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.panel > h2 small { font: 400 12.5px var(--sans); color: var(--slate); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--rule-2); }
.row:first-of-type { border-top: 0; }
.panel > h2 + .row, .panel > h2 + * .row:first-child { border-top: 1px solid var(--rule-2); }
.row .grow { flex: 1; min-width: 0; }
.row .t { display: block; font-weight: 500; }
.row .s { display: block; font-size: 12.5px; color: var(--slate); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; text-align: right; }
.row .amt small { display: block; font-weight: 400; font-size: 12px; color: var(--slate); }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.sw-giving { background: var(--b-giving); } .sw-saving { background: var(--b-saving); }
.sw-investing { background: var(--b-investing); } .sw-expenditure { background: var(--b-expenditure); }
.pick { width: 100%; text-align: left; }
.pick:hover { background: #F7F9FB; }
.pick .chev { color: var(--mist); }
.pick.warn .s { color: var(--over); }

/* bars: fill = actual, brass tick = plan */
.meter { position: relative; height: 6px; background: var(--rule-2); border-radius: 3px; margin-top: 8px; }
.meter i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; width: 0; }
.meter b { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--brass); border-radius: 1px; }
.meter i.giving { background: var(--b-giving); } .meter i.saving { background: var(--b-saving); }
.meter i.investing { background: var(--b-investing); } .meter i.expenditure { background: var(--b-expenditure); }
.meter i.over { background: var(--over); }
.line-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--slate); margin-top: 6px; }

/* ---------- record ---------- */
.flow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.tile { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-panel); padding: 18px 16px 16px; text-align: left; display: grid; gap: 22px; position: relative; overflow: hidden; }
.tile::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; }
.tile.in::before { background: var(--in); } .tile.out::before { background: var(--over); }
.tile .glyph { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; }
.tile.in .glyph { background: var(--in-soft); color: var(--in); } .tile.out .glyph { background: var(--over-soft); color: var(--over); }
.tile strong { display: block; font: 600 21px/1.1 var(--serif); }
.tile span { font-size: 13px; color: var(--slate); }
.tile:active { transform: translateY(1px); }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--slate); font-size: 14px; padding: 18px 0 0; }
.back svg { width: 16px; height: 16px; }
.step-title { margin: 6px 0 14px; font: 600 22px/1.25 var(--serif); }
.flowtag { display: inline-block; font: 500 12px var(--sans); padding: 2px 8px; border-radius: 6px; margin-right: 8px; vertical-align: 3px; }
.flowtag.in { background: var(--in-soft); color: var(--in); } .flowtag.out { background: var(--over-soft); color: var(--over); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 16px; }
.chip { padding: 8px 13px; border-radius: 999px; border: 1px solid var(--rule); background: #F7F9FB; font-weight: 500; font-size: 14px; }
.chip:hover { border-color: var(--navy); }

/* form */
.form { padding: 16px; display: grid; gap: 16px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--slate); font-weight: 500; }
input[type=text], input:not([type]), input[type=email], input[type=password], input[type=date] {
  width: 100%; background: #fff; border: 1px solid var(--rule); border-radius: var(--r-ctl); padding: 12px 13px; color: var(--ink); outline: none; font-weight: 400; }
input:focus { border-color: var(--navy); box-shadow: 0 0 0 3px #0F234014; }
.amount-wrap { display: flex; align-items: baseline; gap: 8px; border-bottom: 2px solid var(--navy); padding-bottom: 4px; }
.amount-wrap span { font: 500 28px var(--serif); color: var(--slate); }
input.amount { border: 0 !important; box-shadow: none !important; padding: 0 !important; font: 500 38px/1.15 var(--serif) !important; font-variant-numeric: tabular-nums; background: transparent; }
.echo { font-size: 13px; color: var(--slate); min-height: 1.2em; }
label.check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); font-weight: 400; font-size: 14px; }
label.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--navy); }
.split { border: 1px solid var(--rule); border-radius: var(--r-ctl); background: #F8FAFC; }
.split h3 { margin: 0; padding: 12px 14px 4px; font: 600 14px var(--serif); color: var(--navy); }
.split .row { padding: 8px 14px; }
details summary { cursor: pointer; padding: 10px 14px; font-size: 13px; color: var(--slate); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 18px; border-radius: var(--r-ctl); font-weight: 600; border: 1px solid var(--rule); background: #fff; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: var(--over); border-color: #E0B9B5; background: var(--over-soft); }
.btn.quiet { border-color: transparent; color: var(--slate); }
.btn svg { width: 18px; height: 18px; }
.inline-form { display: flex; gap: 8px; padding: 0 16px 16px; }
.inline-form input { flex: 1; }
.note { margin: 0 16px 16px; padding: 10px 12px; border-radius: var(--r-ctl); font-size: 13.5px; }
.form .note { margin: 0; }
.hint { font-size: 12.5px; color: var(--slate); }
.scroll-x { overflow-x: auto; }
.note.warn { background: #FBF3E3; color: #6E4F12; border: 1px solid #EBD9B1; }
.note.bad { background: var(--over-soft); color: var(--over); border: 1px solid #E8C4C0; }
.banner { margin: 12px 0 0; }
.banner .note { margin: 0; }

/* ---------- month: hero with plan ring ---------- */
.hero { display: grid; grid-template-columns: 148px 1fr; gap: 16px; align-items: center; padding: 16px; }
.ring { width: 148px; height: 148px; }
.ring text { font-family: var(--sans); }
.legend { display: grid; gap: 8px; }
.legend .lg { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; font-size: 13.5px; }
.legend .lg b { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend .lg em { font-style: normal; font-weight: 400; color: var(--mist); font-size: 12px; margin-left: 3px; }
.legend .lg-key { font-size: 11.5px; color: var(--mist); text-align: right; }
.legend-note { font-size: 12px; color: var(--slate); padding: 0 16px 14px; }
.tick { display: inline-block; width: 2px; height: 12px; background: var(--brass); vertical-align: -2px; margin-right: 6px; border-radius: 1px; }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--rule-2); }
.totals div { padding: 12px 16px; border-left: 1px solid var(--rule-2); min-width: 0; }
.totals div:first-child { border-left: 0; }
.totals span { display: block; font-size: 12px; color: var(--slate); }
.totals b { display: block; font: 500 16px/1.3 var(--serif); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bucket-row { padding: 13px 16px; border-top: 1px solid var(--rule-2); }
.bucket-row .top { display: flex; align-items: baseline; gap: 10px; }
.bucket-row .top .t { flex: 1; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.bucket-row .top .t em { font-style: normal; color: var(--mist); font-size: 12.5px; font-weight: 400; }
.bucket-row .top .v { font-variant-numeric: tabular-nums; font-weight: 500; }
.tips { list-style: none; margin: 0; padding: 0; }
.tips li { padding: 11px 16px 11px 34px; border-top: 1px solid var(--rule-2); position: relative; font-size: 14px; }
.tips li::before { content: ""; position: absolute; left: 16px; top: 18px; width: 8px; height: 8px; border-radius: 50%; background: var(--mist); }
.tips li.good::before { background: var(--in); } .tips li.bad::before { background: var(--over); } .tips li.plan::before { background: var(--brass); }
.downloads { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }

/* ---------- overview ---------- */
.period { display: grid; grid-template-columns: repeat(3, 1fr); background: #fff; border: 1px solid var(--rule); border-radius: 999px; padding: 3px; margin: -4px 0 14px; }
.period button { padding: 7px 6px; border-radius: 999px; font-size: 13px; color: var(--slate); font-weight: 500; white-space: nowrap; }
.period button[aria-pressed=true] { background: var(--navy); color: #fff; }
.lead { padding: 18px 16px 6px; }
.lead .big { font: 500 34px/1.1 var(--serif); font-variant-numeric: tabular-nums; letter-spacing: -.015em; }
.lead p { margin: 6px 0 0; color: var(--slate); font-size: 13.5px; }
.chart { padding: 6px 8px 4px; }
.chart svg { width: 100%; max-width: 460px; height: auto; display: block; margin: 0 auto; }
.chart text { font-family: var(--sans); font-size: 11px; fill: var(--slate); }
.keys { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 4px 16px 14px; font-size: 12px; color: var(--slate); }
.keys span { display: inline-flex; align-items: center; gap: 6px; }
.keys i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.keys i.inc { background: none; border: 1.5px solid var(--navy); }
.grid-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.grid-table th, .grid-table td { padding: 9px 4px; text-align: right; border-top: 1px solid var(--rule-2); white-space: nowrap; }
.grid-table th:first-child, .grid-table td:first-child { text-align: left; padding-left: 14px; }
.grid-table th:last-child, .grid-table td:last-child { padding-right: 14px; }
.grid-table thead th { font-weight: 500; color: var(--slate); font-size: 12px; border-top: 0; vertical-align: bottom; }
.grid-table thead th small { display: block; color: var(--brass); font-weight: 500; }
.grid-table td.meet { color: var(--in); font-weight: 500; }
.grid-table td.miss { color: var(--slate); }
.grid-table td.over { color: var(--over); font-weight: 500; }
.grid-table tr.partial td:first-child::after { content: "*"; color: var(--brass); }
.table-note { padding: 8px 14px 12px; font-size: 12px; color: var(--slate); border-top: 1px solid var(--rule-2); }
.grid-table tfoot td { font-weight: 600; border-top: 1px solid var(--rule); }
.spark { display: inline-flex; align-items: flex-end; gap: 3px; height: 24px; padding-bottom: 1px; border-bottom: 1px solid var(--rule); }
.spark i { width: 6px; background: var(--b-expenditure); border-radius: 1px 1px 0 0; display: block; }
.spark i.z { background: transparent; }
.empty { text-align: center; color: var(--slate); padding: 40px 16px; }
.empty b { display: block; font: 600 18px var(--serif); color: var(--ink); margin-bottom: 4px; }

/* ---------- history ---------- */
.day { padding: 16px 4px 6px; font-size: 12.5px; color: var(--slate); font-weight: 500; }
.entry { width: 100%; text-align: left; }
.entry .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.in { background: var(--in); } .dot.out { background: var(--over); }
.entry .amt.in { color: var(--in); }
.entry.void .t, .entry.void .amt { text-decoration: line-through; color: var(--mist); }

/* ---------- tabs ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: #fff; border-top: 1px solid var(--rule); padding-bottom: env(safe-area-inset-bottom); }
.tabs .wrap { display: grid; grid-template-columns: repeat(4, 1fr); }
.tabs button { position: relative; display: grid; justify-items: center; gap: 3px; padding: 10px 4px 9px; color: var(--mist); font-size: 11.5px; font-weight: 500; }
.tabs button[aria-current=true] { color: var(--navy); }
.tabs button[aria-current=true]::before { content: ""; position: absolute; top: -1px; left: 28%; right: 28%; height: 2px; background: var(--brass); }

/* ---------- sheet, toast, auth ---------- */
.scrim { position: fixed; inset: 0; background: #0F234066; z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-width: 640px; margin: 0 auto; background: #fff; border-radius: 18px 18px 0 0; padding: 8px 0 calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px #0F234033; }
.sheet h3 { margin: 0; padding: 12px 16px 6px; font: 600 19px var(--serif); }
.sheet .btn.quiet { width: calc(100% - 32px); margin: 4px 16px 0; }
.sheet .form { padding-top: 8px; }
#toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px); opacity: 0; pointer-events: none; z-index: 20;
  background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px); transition: opacity .2s, transform .2s; box-shadow: 0 8px 28px #0F234040; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--over); } #toast.good { background: var(--in); }
.auth { min-height: 100dvh; background: var(--navy); display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; padding: 28px 22px 22px; }
.auth .mark { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth .mark svg { width: 34px; height: 34px; }
.auth .mark b { font: 600 20px var(--serif); color: var(--navy); }
.auth h1 { margin: 0 0 4px; font: 600 22px var(--serif); }
.auth p { margin: 0 0 18px; color: var(--slate); font-size: 14px; }
.auth .form { padding: 0; }
.qr { display: block; width: 196px; height: 196px; margin: 0 auto 10px; border: 1px solid var(--rule); border-radius: 12px; padding: 8px; }
.secret { display: block; word-break: break-all; background: var(--porcelain); padding: 10px; border-radius: 8px; margin-top: 6px; font-size: 13px; }
input.code { text-align: center; font: 500 26px var(--serif) !important; letter-spacing: .35em; }
.link { color: var(--navy); text-decoration: underline; font-size: 14px; margin-top: 12px; }
.boot { min-height: 100dvh; display: grid; place-items: center; background: var(--navy); }
.boot svg { width: 56px; height: 56px; animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { height: 2px; margin: 24px 0; background: linear-gradient(90deg, transparent, var(--brass), transparent) no-repeat; background-size: 40% 100%; animation: load 1.1s linear infinite; }
@keyframes load { from { background-position: -40% 0; } to { background-position: 140% 0; } }
@media (min-width: 720px) { .flow .tile { padding: 24px 20px 20px; } .hero { grid-template-columns: 168px 1fr; } .ring { width: 168px; height: 168px; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }
