@font-face { font-family: 'Bricolage Grotesque'; src: url(fonts/bricolage-grotesque.woff2) format('woff2'); font-weight: 200 800; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; src: url(fonts/atkinson-hyperlegible-latin-400-normal.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; src: url(fonts/atkinson-hyperlegible-latin-700-normal.woff2) format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --frost: #E9EEF0;
  --paper: #FBFCFC;
  --ink: #18232E;
  --ink-2: #4A5863;
  --line: #CBD5DA;
  --fjord: #2D5B78;
  --fjord-soft: #D5E2EA;
  --saffran: #D9A21B;
  --saffran-soft: #F3DFA6;
  --lingon: #A8243A;
  --gran: #2E6A4F;
  --r-lg: 18px;
  --r-sm: 8px;
  --display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --body: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--frost); color: var(--ink);
  font: 16px/1.5 var(--body);
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--saffran); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; background: var(--paper); padding: 8px 12px; z-index: 50; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- header + tabs */
.top { display: flex; align-items: center; gap: 12px; padding: 16px 20px 6px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.mark { width: 30px; height: 30px; }
.name { font-family: var(--display); font-weight: 800; font-size: 1.3rem; letter-spacing: -0.02em; }
.week-label { color: var(--ink-2); margin-left: auto; }
.mode-pill { background: var(--saffran-soft); color: var(--ink); border-radius: 999px; padding: 2px 10px; font-size: .85rem; }

.tabs { display: flex; gap: 4px; padding: 6px 16px 0; overflow-x: auto; scrollbar-width: none; }
.tab {
  border: 0; background: none; padding: 10px 12px; border-radius: 10px 10px 0 0;
  color: var(--ink-2); cursor: pointer; white-space: nowrap; border-bottom: 3px solid transparent;
}
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--fjord); font-weight: 700; }
.tab:hover { color: var(--ink); }

main { padding: 12px 16px 24px; outline: none; }
.view { display: grid; gap: 16px; max-width: 760px; }
.panel { background: var(--paper); border-radius: var(--r-lg); padding: 20px; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }

/* ---------------------------------------------------------------- this week */
.hero { display: grid; gap: 6px; }
.hero .left { font-family: var(--display); font-weight: 800; font-size: clamp(2.6rem, 9vw, 4rem); line-height: 1; letter-spacing: -0.03em; }
.hero .left.over { color: var(--lingon); }
.hero .sub { color: var(--ink-2); max-width: 52ch; }
.meter { height: 10px; background: var(--fjord-soft); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.meter > span { display: block; height: 100%; background: var(--fjord); border-radius: 999px; }
.meter.over > span { background: var(--lingon); }

.strip { display: grid; gap: 2px; margin-top: 4px; }
.strip-row { display: grid; grid-template-columns: minmax(96px, 28%) 1fr auto; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--frost); }
.strip-row:first-child { border-top: 0; }
.strip-name { font-weight: 700; line-height: 1.2; }
.strip-name small { display: block; font-weight: 400; color: var(--ink-2); font-size: .8rem; }
.strip-fig { text-align: right; min-width: 7.5ch; line-height: 1.2; }
.strip-fig b { font-family: var(--display); font-weight: 600; font-size: 1.05rem; }
.strip-fig small { display: block; color: var(--ink-2); font-size: .8rem; }
.strip-fig .over { color: var(--lingon); }
.strip svg { width: 100%; height: 34px; display: block; overflow: visible; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--ink-2); margin-top: 14px; }
.legend i { display: inline-block; vertical-align: -2px; margin-right: 6px; }
.lg-band { width: 22px; height: 12px; border-radius: 6px; background: var(--saffran-soft); border: 1.5px solid var(--saffran); }
.lg-spent { width: 22px; height: 8px; border-radius: 4px; background: var(--fjord); }
.lg-budget { width: 3px; height: 16px; background: var(--ink); border-radius: 2px; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.fact b { display: block; font-family: var(--display); font-size: 1.4rem; font-weight: 600; }
.fact span { color: var(--ink-2); font-size: .9rem; }
.note { border-left: 4px solid var(--saffran); padding: 4px 0 4px 14px; }
.note.warn { border-left-color: var(--lingon); }

/* ---------------------------------------------------------------- forecast */
.cat-card { display: grid; gap: 10px; }
.cat-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.chart svg { width: 100%; height: 150px; display: block; overflow: visible; }
.chart .axis { font-size: 11px; fill: var(--ink-2); font-family: var(--body); }
.chart-legend { display: flex; gap: 16px; font-size: .85rem; color: var(--ink-2); }
.chart-legend i { display: inline-block; margin-right: 6px; vertical-align: 1px; }
.lg-bar { width: 12px; height: 10px; background: var(--fjord); border-radius: 2px; }
.lg-line { width: 18px; height: 3px; background: var(--saffran); border-radius: 2px; }
details summary { cursor: pointer; color: var(--fjord); font-weight: 700; }
details[open] summary { margin-bottom: 10px; }

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--frost); }
table.data td.num, table.data th.num { text-align: right; }

/* ---------------------------------------------------------------- ledger */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="search"] { flex: 1 1 220px; }
.day { margin-top: 6px; }
.day h3 { font-size: .9rem; color: var(--ink-2); font-family: var(--body); font-weight: 700; padding: 10px 4px 4px; }
.tx { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; text-align: left; background: var(--paper); border: 0; border-radius: var(--r-sm); padding: 10px 12px; margin-top: 4px; cursor: pointer; }
.tx:hover { background: #fff; box-shadow: inset 0 0 0 1.5px var(--line); }
.tx .d { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .a { text-align: right; font-family: var(--display); font-weight: 600; }
.tx .a.in { color: var(--gran); }
.tx .m { font-size: .82rem; color: var(--ink-2); grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-block; border-radius: 999px; padding: 0 8px; font-size: .78rem; line-height: 1.6; background: var(--frost); color: var(--ink); }
.chip.guess { background: var(--saffran-soft); }
.chip.off { background: none; box-shadow: inset 0 0 0 1px var(--line); color: var(--ink-2); }

/* ---------------------------------------------------------------- forms */
label { display: block; font-weight: 700; font-size: .9rem; margin: 14px 0 6px; }
input, select, textarea { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; }
textarea { font: inherit; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { border-color: var(--fjord); }
input[type="checkbox"] { width: 18px; height: 18px; padding: 0; accent-color: var(--fjord); flex: none; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: .82rem; color: var(--ink-2); min-height: 1.3em; margin-top: 4px; }
.amount-wrap { display: flex; align-items: baseline; gap: 8px; border-bottom: 2px solid var(--ink); }
.amount-wrap input { border: 0; padding: 4px 0; font-family: var(--display); font-weight: 800; font-size: 2.6rem; background: none; border-radius: 0; letter-spacing: -0.02em; }
.amount-wrap input:focus { outline: none; }
.amount-wrap:focus-within { border-bottom-color: var(--saffran); }
.amount-wrap span { font-family: var(--display); font-size: 1.4rem; color: var(--ink-2); }
.seg { display: inline-flex; background: var(--frost); border-radius: 999px; padding: 3px; margin-top: 10px; }
.seg label { margin: 0; font-weight: 400; padding: 4px 12px; border-radius: 999px; cursor: pointer; font-size: .88rem; }
.seg input { position: absolute; opacity: 0; width: 1px; }
.seg label:has(input:checked) { background: var(--paper); font-weight: 700; }
.seg label:has(input:focus-visible) { outline: 3px solid var(--saffran); }
button.primary, button.secondary, button.danger, button.link {
  border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer; font-weight: 700;
}
button.primary { background: var(--fjord); color: #fff; width: 100%; margin-top: 18px; }
button.primary:hover { background: #244b63; }
button.primary:disabled { opacity: .6; cursor: progress; }
button.secondary { background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--line); }
.panel button.secondary, dialog button.secondary { background: var(--frost); box-shadow: none; }
button.secondary:hover { background: var(--fjord-soft); }
button.danger { background: none; color: var(--lingon); box-shadow: inset 0 0 0 1.5px currentColor; }
button.link { background: none; padding: 4px 0; color: var(--fjord); text-decoration: underline; text-underline-offset: 3px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.form-msg { margin-top: 10px; font-size: .9rem; min-height: 1.4em; }
.form-msg.err { color: var(--lingon); }

/* add panel: bottom sheet on phones, sticky column on desktop */
.add-panel {
  position: fixed; inset: auto 0 0 0; background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom)); box-shadow: 0 -12px 40px rgba(24, 35, 46, .18);
  transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); z-index: 20; max-height: 92vh; overflow-y: auto;
}
.add-panel.open { transform: none; visibility: visible; }
.add-panel:not(.open) { visibility: hidden; transition: transform .28s cubic-bezier(.2, .8, .2, 1), visibility 0s .28s; }
.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 21;
  background: var(--ink); color: #fff; border: 0; border-radius: 999px; padding: 15px 22px 15px 18px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(24, 35, 46, .3); cursor: pointer;
}
.fab::before { content: "+"; font-family: var(--display); font-size: 1.4rem; line-height: 0; margin-right: 8px; vertical-align: -2px; }
.fab[aria-expanded="true"]::before { content: "×"; }

@media (max-width: 560px) {
  .strip-row { grid-template-columns: 1fr auto; grid-template-areas: "name fig" "bar bar"; row-gap: 4px; }
  .strip-name { grid-area: name; }
  .strip-fig { grid-area: fig; }
  .strip svg { grid-area: bar; }
}

@media (min-width: 1020px) {
  body[data-view="app"] { display: grid; grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: auto auto 1fr; column-gap: 28px; padding: 0 28px 40px; max-width: 1240px; margin: 0 auto; }
  body[data-view="app"] .top, body[data-view="app"] .tabs, body[data-view="app"] main { grid-column: 1; padding-left: 0; padding-right: 0; }
  body[data-view="app"] .top { padding-top: 24px; }
  body:not([data-view="app"]) { max-width: 980px; margin: 0 auto; }
  .add-panel, .add-panel:not(.open) { visibility: visible; position: sticky; top: 24px; grid-column: 2; grid-row: 1 / span 3; align-self: start; transform: none; border-radius: var(--r-lg); box-shadow: none; max-height: none; margin-top: 24px; transition: none; }
  .fab { display: none; }
}

/* ---------------------------------------------------------------- dialog, toast, tip */
dialog { border: 0; border-radius: var(--r-lg); padding: 22px; width: min(460px, calc(100vw - 24px)); background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgba(24, 35, 46, .45); }
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; transition: .2s; pointer-events: none; z-index: 40; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--lingon); }
.tip { position: fixed; z-index: 45; background: var(--ink); color: #fff; padding: 6px 10px; border-radius: 8px; font-size: .82rem; pointer-events: none; max-width: 240px; line-height: 1.35; }

.empty { text-align: left; display: grid; gap: 10px; }
.loading { color: var(--ink-2); padding: 30px 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------------------------------------------------------------- screens without a sheet open */
body:not([data-view="app"]) .tabs, body:not([data-view="app"]) .add-panel, body:not([data-view="app"]) .fab { display: none; }
body:not([data-view="app"]) { padding-bottom: 40px; }
.welcome { display: grid; gap: 18px; max-width: 880px; padding: 18px 4px 8px; }
.w-title { font-family: var(--display); font-weight: 800; font-size: clamp(2.1rem, 6vw, 3.4rem); line-height: 1.02; letter-spacing: -0.03em; max-width: 17ch; }
.w-lead { font-size: 1.12rem; color: var(--ink-2); max-width: 58ch; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-top: 6px; }
.choice { background: var(--paper); border-radius: var(--r-lg); padding: 22px; display: grid; gap: 10px; align-content: start; }
.choice p { color: var(--ink-2); }
.choice .primary { margin-top: 6px; }
.choice.open { box-shadow: inset 0 0 0 2px var(--saffran); }
.create-form label:first-child { margin-top: 0; }
.w-demo { margin-top: -4px; }
.w-privacy { max-width: 62ch; }
.setup { display: grid; gap: 16px; max-width: 880px; }
.setup .w-title { font-size: clamp(1.8rem, 5vw, 2.6rem); max-width: none; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.cols { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.cat-row { display: grid; grid-template-columns: 1fr minmax(150px, 210px); gap: 12px; align-items: center; padding: 8px 0; border-top: 1px solid var(--frost); }
.cat-row:first-of-type { border-top: 0; }
.cat-name { font-weight: 700; line-height: 1.25; }
.cat-name small { display: block; font-weight: 400; color: var(--ink-2); font-size: .82rem; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 10px 0 0; cursor: pointer; }
label.check input { margin-top: 2px; }
fieldset.checks { border: 0; padding: 0; margin: 14px 0 0; }
fieldset.checks legend { font-weight: 700; font-size: .9rem; padding: 0; }
.cat-table { display: grid; gap: 6px; margin-top: 8px; }
.cat-th, .cat-tr { display: grid; grid-template-columns: minmax(120px, 1.2fr) minmax(130px, 1fr) minmax(140px, 1.6fr) 70px; gap: 8px; align-items: center; }
.cat-th { font-size: .8rem; color: var(--ink-2); font-weight: 700; }
.cat-tr input, .cat-tr select { padding: 8px 10px; }
button:disabled { opacity: .55; cursor: not-allowed; }
.loading { font-family: var(--display); font-size: 1.2rem; }

@media (max-width: 720px) {
  .row3 { grid-template-columns: 1fr 1fr; }
  .cols { grid-template-columns: 1fr 1fr; }
  .cat-th { display: none; }
  .cat-tr { grid-template-columns: 1fr 1fr; padding: 10px 0; border-top: 1px solid var(--frost); }
  .cat-tr input[data-f="keywords"] { grid-column: 1 / -1; }
}

/* ---------------------------------------------------------------- privacy page */
.doc { max-width: 720px; margin: 8px auto 40px; }
.doc h1 { font-size: 2rem; margin-bottom: 8px; }
.doc h2 { font-size: 1.15rem; margin-top: 22px; }
.doc p, .doc ul { margin-top: 8px; max-width: 68ch; }
.doc li { margin-top: 6px; }
.doc code { font-size: .9em; background: var(--frost); padding: 1px 5px; border-radius: 4px; }
