:root {
  color-scheme: light;
  --bg: #EEF1EC;
  --surface: #FFFFFF;
  --ink: #1D2B2A;
  --muted: #5E6B68;
  --line: #D5DCD6;
  --field: #F7F9F6;
  --green: #0F5C52;
  --green-ink: #FFFFFF;
  --marigold: #E39B0B;
  --pos: #2E7A4B;
  --neg: #B23A2E;
  --e-need: #0F5C52;
  --e-life: #6E8FB8;
  --e-imp: #E39B0B;
  --e-none: #B9C2BC;
  --radius-lg: 18px;
  --radius: 10px;
  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", sans-serif;
  --body: "Public Sans", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121816;
    --surface: #1A2220;
    --ink: #E6ECE8;
    --muted: #9AA8A3;
    --line: #2C3833;
    --field: #141B19;
    --green: #4FB3A3;
    --green-ink: #0B1513;
    --marigold: #F2B33D;
    --pos: #5BC187;
    --neg: #E8786B;
    --e-need: #4FB3A3;
    --e-life: #8FA9CF;
    --e-imp: #F2B33D;
    --e-none: #4A5651;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--body);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
small { font-size: .8rem; color: var(--muted); }
h1, h2 { font-family: var(--display); letter-spacing: -.01em; margin: 0; }
h1 { font-size: clamp(1.7rem, 3.4vw, 2.4rem); font-weight: 800; line-height: 1.1; }
h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: .9rem; }
:focus-visible { outline: 3px solid var(--marigold); outline-offset: 2px; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: 600 .92rem var(--body); color: var(--ink); text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: .55rem 1.1rem; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--green); color: var(--green-ink); border-color: var(--green); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); border-color: var(--line); }
.btn.small { padding: .3rem .7rem; font-size: .82rem; }
.btn.danger { color: var(--neg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon {
  width: 2.2rem; height: 2.2rem; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 1.2rem; line-height: 1; cursor: pointer;
}
.icon:hover { border-color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; width: 100%; min-width: 0;
}
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--green); }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
label.chk { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; color: var(--ink); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { background: var(--surface); padding: 2.4rem 2rem; border-radius: var(--radius-lg); width: min(24rem, 100%); display: grid; gap: .6rem; }
.login-card .wordmark { font-size: 2rem; }
.login-card p { margin: 0 0 .6rem; color: var(--muted); }
.pw2 { display: grid; gap: .6rem; }
.err { color: var(--neg); min-height: 1.2em; margin: 0; font-size: .9rem; }

/* Layout */
.app { display: grid; grid-template-columns: 15rem 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 1.6rem 1rem;
  display: flex; flex-direction: column; gap: 1.6rem; border-right: 1px solid var(--line);
}
.wordmark { font-family: var(--display); font-weight: 800; font-size: 1.45rem; letter-spacing: -.02em; color: var(--green); padding: 0 .6rem; }
.nav { display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.nav button {
  text-align: left; font: 600 .95rem var(--body); color: var(--muted); background: none;
  border: 0; border-radius: var(--radius); padding: .6rem .75rem; cursor: pointer;
}
.nav button:hover { color: var(--ink); background: var(--surface); }
.nav button[aria-current=page] { color: var(--ink); background: var(--surface); box-shadow: inset 3px 0 0 var(--marigold); }
main { padding: 2rem clamp(1rem, 3vw, 2.6rem) 4rem; max-width: 76rem; width: 100%; outline: none; }

.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.period { display: flex; align-items: center; gap: .8rem; }
.period h1 { min-width: 12ch; text-align: center; }
.yearnav { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.lead { font-size: 1.02rem; max-width: 70ch; }
.hint { color: var(--muted); font-size: .88rem; margin: -.4rem 0 1.4rem; max-width: 75ch; }
.notice { padding: .8rem 1rem; border-radius: var(--radius); margin-bottom: 1.2rem; font-weight: 500; }
.notice.warn { background: color-mix(in srgb, var(--marigold) 22%, var(--surface)); }
.row { display: flex; gap: .6rem; flex-wrap: wrap; }

/* Month ribbon: the signature element */
.ribbon-wrap { margin-bottom: 1.6rem; }
.ribbon-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .7rem; }
.ribbon-head h2 { margin: 0; font-size: 1rem; color: var(--muted); font-weight: 600; font-family: var(--body); }
.ribbon { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; }
.tile {
  --tone: var(--pos);
  border: 0; cursor: pointer; padding: .7rem .2rem .6rem; border-radius: 6px;
  background: color-mix(in srgb, var(--tone) calc(var(--k) * 100%), var(--surface));
  color: var(--ink); display: flex; flex-direction: column; align-items: center; gap: .15rem;
  font-family: var(--body); min-height: 4.4rem; justify-content: center;
  transition: transform .15s ease;
}
.tile:first-child { border-radius: var(--radius) 6px 6px var(--radius); }
.tile:last-child { border-radius: 6px var(--radius) var(--radius) 6px; }
.tile.down { --tone: var(--marigold); }
.tile.empty { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.tile .tm { font-size: .78rem; font-weight: 600; }
.tile .tv { font: 700 .95rem var(--display); font-variant-numeric: tabular-nums; }
.tile.sel { outline: 2.5px solid var(--ink); outline-offset: 2px; transform: translateY(-2px); }
.tile:hover:not(.sel) { transform: translateY(-1px); }

/* Figures */
.figs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 1.6rem; }
.figs.three { grid-template-columns: repeat(3, 1fr); }
.figs > div { background: var(--surface); padding: 1.1rem 1.3rem; display: flex; flex-direction: column; gap: .2rem; }
.figs .lbl { font-size: .85rem; color: var(--muted); font-weight: 600; }
.figs strong { font: 700 1.5rem var(--display); text-align: left; }
.figs .pos strong { color: var(--pos); }
.figs .neg strong { color: var(--neg); }

.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.2rem; align-items: start; }
.stack { display: grid; gap: 1.2rem; }
.panel { background: var(--surface); border-radius: var(--radius-lg); padding: 1.3rem 1.4rem; margin-bottom: 1.2rem; }
.cols .panel, .stack .panel { margin-bottom: 0; }

/* Budget bars */
.budget { list-style: none; margin: 0; padding: 0; display: grid; gap: .95rem; }
.bl { display: flex; justify-content: space-between; gap: 1rem; font-weight: 600; }
.bl small { font-weight: 400; }
.bar { height: 8px; background: color-mix(in srgb, var(--ink) 9%, transparent); border-radius: 99px; margin: .35rem 0 .15rem; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: inherit; }
.budget .over .bar i { background: var(--neg); }
.budget .over .bn { color: var(--neg); font-weight: 600; }
.budget .nob .bar i { background: var(--e-none); }
.goal { margin-bottom: 1.1rem; }
.goal:last-child { margin-bottom: 0; }
.goalbar { height: 12px; }
.goalbar i { background: var(--marigold); }
.goalbar.short i { background: var(--e-life); }

.emobar { display: flex; height: 18px; border-radius: 99px; overflow: hidden; gap: 2px; margin-bottom: .9rem; }
.legend { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.legend li { display: flex; align-items: center; gap: .5rem; }
.legend .num { margin-left: auto; }
.sw { width: .8rem; height: .8rem; border-radius: 3px; display: inline-block; }
.e-need { background: var(--e-need); }
.e-lifestyle-quality { background: var(--e-life); }
.e-impulse { background: var(--e-imp); }
.e-unlabeled { background: var(--e-none); }

.fx { display: grid; grid-template-columns: 1fr auto; gap: .45rem 1rem; margin: 0 0 .6rem; }
.fx dt { color: var(--muted); }
.fx dd { margin: 0; font-weight: 700; }

.empty-state { background: var(--surface); border-radius: var(--radius-lg); padding: 3rem 2rem; text-align: center; display: grid; gap: .8rem; justify-items: center; }
.empty-state h2 { font-size: 1.5rem; margin: 0; }
.empty-state p { color: var(--muted); max-width: 46ch; margin: 0 0 .6rem; }

/* Import */
.drop {
  display: grid; place-items: center; text-align: center; gap: .3rem; color: var(--ink);
  border: 2px dashed color-mix(in srgb, var(--green) 45%, var(--line)); border-radius: var(--radius-lg);
  background: var(--surface); padding: 2.6rem 1.5rem; cursor: pointer; font-weight: 400;
}
.drop strong { font: 700 1.25rem var(--display); }
.drop span { color: var(--muted); font-size: .92rem; }
.drop.over { border-color: var(--marigold); background: color-mix(in srgb, var(--marigold) 10%, var(--surface)); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:focus-within { outline: 3px solid var(--marigold); outline-offset: 2px; }
.tips { margin: 1rem 0 1.4rem; max-width: 75ch; }
.tips summary { cursor: pointer; font-weight: 600; color: var(--green); }
.tips p { color: var(--muted); }
.fcards { display: grid; gap: 1rem; }
.fcard { background: var(--surface); border-radius: var(--radius-lg); padding: 1.1rem 1.3rem; border-left: 4px solid var(--green); }
.fcard header { display: flex; justify-content: space-between; gap: 1rem; align-items: start; margin-bottom: .9rem; }
.fcard header div { display: grid; gap: .1rem; }
.tag { color: var(--green); font-weight: 600; }
.mapgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: .8rem 1rem; }
.mapgrid .wide { grid-column: 1 / -1; }
.mapgrid .chk { align-self: end; padding-bottom: .5rem; }
.mini { width: 100%; margin-top: .9rem; font-size: .85rem; border-collapse: collapse; color: var(--muted); }
.mini td { padding: .3rem .4rem; border-top: 1px solid var(--line); }
.actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }
.actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: .8rem 0 calc(.8rem + env(safe-area-inset-bottom, 0px)); }
.formend { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; grid-column: 1 / -1; }

/* Tables */
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem 1.2rem; align-items: center; margin-bottom: .9rem; }
.toolbar input[type=search] { max-width: 18rem; }
.toolbar select { width: auto; }
.tablewrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius-lg); }
.panel .tablewrap { border-radius: 0; }
table.grid { width: 100%; border-collapse: collapse; font-size: .9rem; }
.grid th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: .7rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid th.num { text-align: right; }
.grid td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; padding: .7rem .6rem; }
.grid td small { display: block; }
.grid .concept { min-width: 14rem; }
.grid .nowrap, .nowrap { white-space: nowrap; }
.grid .pad { padding: 1.4rem; text-align: center; }
.grid tr.uncat td:first-child { box-shadow: inset 3px 0 0 var(--marigold); }
.grid tr.off { opacity: .45; }
.grid tr.k-transfer { color: var(--muted); }
.grid.edit input, .grid.edit select { background: transparent; border-color: transparent; padding: .35rem .45rem; }
.grid.edit input:hover, .grid.edit select:hover, .grid.edit input:focus, .grid.edit select:focus { border-color: var(--line); background: var(--field); }
.grid.edit input[type=date] { min-width: 9.5rem; }
.grid .amt { min-width: 7rem; }
.grid .acct { min-width: 8rem; }
.grid select { min-width: 9rem; }
.bulk { display: flex; align-items: center; gap: .8rem; background: var(--surface); padding: .6rem 1rem; border-radius: var(--radius); margin-bottom: .8rem; border: 1px solid var(--marigold); }
.bulk select { width: auto; }
.addbox { margin-bottom: 1.2rem; }
.addbox summary { list-style: none; }
.addbox summary::-webkit-details-marker { display: none; }
.addbox[open] summary { margin-bottom: 1rem; }
.addbox form { background: var(--surface); padding: 1.2rem; border-radius: var(--radius-lg); }

/* Income */
.seg { display: inline-flex; background: var(--field); border: 1px solid var(--line); border-radius: 99px; padding: 3px; margin-bottom: 1rem; }
.seg label { flex-direction: row; align-items: center; gap: .4rem; padding: .4rem .9rem; border-radius: 99px; cursor: pointer; color: var(--ink); font-weight: 600; }
.seg label:has(input:checked) { background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
.seg input { position: absolute; opacity: 0; }
.inline { display: flex; gap: .4rem; }
.calc { min-height: 1.5em; margin: .9rem 0 0; font-weight: 500; color: var(--green); }
.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
[hidden] { display: none !important; }

.toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 150%);
  background: var(--ink); color: var(--bg); padding: .7rem 1.2rem; border-radius: 99px; font-weight: 600;
  max-width: calc(100% - 2rem); transition: transform .25s ease; z-index: 50;
}
.toast.show { transform: translate(-50%, 0); }
.toast.bad { background: var(--neg); color: #fff; }
.fatal { padding: 2rem; font-size: 1.1rem; }

/* Mobile */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: sticky; top: 0; z-index: 20; height: auto; padding: .7rem .8rem;
    flex-direction: row; align-items: center; gap: .6rem; border-right: 0; border-bottom: 1px solid var(--line);
    background: var(--bg); padding-top: calc(.7rem + env(safe-area-inset-top, 0px)); margin-top: calc(-1 * env(safe-area-inset-top, 0px));
  }
  .side .wordmark { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: .2rem; }
  .nav button { white-space: nowrap; padding: .45rem .7rem; font-size: .88rem; }
  .nav button[aria-current=page] { box-shadow: inset 0 -3px 0 var(--marigold); }
  main { padding-top: 1.3rem; }
  .cols { grid-template-columns: 1fr; }
  .figs, .figs.three { grid-template-columns: 1fr 1fr; }
  .ribbon { grid-template-columns: repeat(6, 1fr); }
  .tile:first-child, .tile:last-child { border-radius: 6px; }
  .period h1 { min-width: 0; font-size: 1.5rem; }
}
@media (max-width: 420px) {
  .figs strong { font-size: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* Goals */
h3 { font: 700 1rem var(--display); margin: 0 0 .8rem; }
p.small, .small { font-size: .85rem; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--green); font-weight: 600; text-decoration: underline; cursor: pointer; }
.gcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: 1.2rem; align-items: start; }
.gcard { background: var(--surface); border-radius: var(--radius-lg); padding: 1.3rem 1.4rem; display: grid; gap: .55rem; border-top: 4px solid var(--marigold); }
.gcard.newgoal { margin-bottom: 1.2rem; border-top-color: var(--green); }
.gcard header { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.gcard h2 { margin: 0; font-size: 1.15rem; }
.gbal { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.gbal strong { font: 800 1.75rem var(--display); text-align: left; }
.gbal span { color: var(--muted); }
.gcard .goalbar { margin: 0; }
.pace { margin: 0; font-weight: 600; color: var(--green); font-size: .92rem; }
.pace.done { color: var(--pos); }
.pace.muted { color: var(--muted); font-weight: 500; }
.gstats { display: grid; grid-template-columns: 1fr auto; gap: .3rem 1rem; margin: .3rem 0 .4rem; font-size: .9rem; }
.gstats dt { color: var(--muted); }
.gstats dd { margin: 0; font-weight: 600; }
.gstats dd small { margin-left: .3rem; font-weight: 400; }
.gform { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: .4rem; }
.gform .mapgrid { grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }
.gform p { margin: .8rem 0 0; }
.gentries summary { cursor: pointer; font-weight: 600; color: var(--green); font-size: .9rem; }
.gentries ul { list-style: none; margin: .6rem 0 0; padding: 0; display: grid; gap: .2rem; font-size: .88rem; }
.gentries li { display: grid; grid-template-columns: 5.5rem 1fr auto 1.6rem; gap: .5rem; align-items: center; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.gentries li span:first-child { color: var(--muted); }
.gentries li.out .num { color: var(--neg); }
.gentries li.growth .num { color: var(--pos); }
.icon.x { width: 1.5rem; height: 1.5rem; font-size: .95rem; border-color: transparent; color: var(--muted); }
.icon.x:hover { color: var(--neg); border-color: var(--line); }
