@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400..700&display=swap");
:root {
  color-scheme: light;
  --page: #f3f1f8; --surface: #ffffff; --ink: #1d1b26; --ink-2: #5b5869; --muted: #8e8a9e;
  --grid: #ece9f3; --axis: #d6d2e0; --border: rgba(48, 32, 96, 0.08);
  --series-1: #6e56cf; --track: #e9e4fb;
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b; --good-text: #006300;
  --button: #6e56cf; --on-button: #fff;
  --shadow: 0 1px 2px rgba(30, 20, 60, 0.04), 0 6px 20px rgba(30, 20, 60, 0.06);
  --hover: rgba(48, 32, 96, 0.05);
  /* Motion: strong ease-out for anything entering, leaving or pressed (Emil Kowalski's curve) */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #131219; --surface: #1c1b23; --ink: #ecebf3; --ink-2: #b9b5c8; --muted: #858197;
    --grid: #2a2834; --axis: #363341; --border: rgba(255, 255, 255, 0.07);
    --series-1: #9584f2; --track: #2e2754; --good-text: #0ca30c;
    --button: #7c66dc;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    --hover: rgba(255, 255, 255, 0.05);
  }
}


* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14.5px/1.5 Inter, system-ui, "Segoe UI Variable Text", "Segoe UI", sans-serif; font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; }
header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
header h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
nav { display: flex; gap: 4px; }
nav a { padding: 6px 12px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
nav a[aria-current="page"] { background: var(--track); color: var(--series-1); font-weight: 600; }
.spacer { flex: 1; }
main { max-width: 1440px; margin: 0 auto; padding: 24px 16px 64px; display: grid; gap: 20px; align-content: start; }
section { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px 24px; min-width: 0; box-shadow: var(--shadow); }
h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.sub { color: var(--ink-2); font-size: 13px; margin: -8px 0 12px; }
.muted { color: var(--muted); }
main:has(> .tabs) { position: relative; }
/* A hidden tab stays laid out (content-visibility) and sits out of the grid, so showing it again is instant. */
section.off { content-visibility: hidden; visibility: hidden; position: absolute; top: 0; left: 16px; right: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--axis); }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 6px 6px 0 0; background: transparent; color: var(--ink-2); padding: 8px 16px; }
.tabs button:hover { background: var(--track); color: var(--ink); }
.tabs button[aria-selected="true"] { border-bottom-color: var(--series-1); color: var(--ink); font-weight: 600; }

button, .button { font: inherit; font-weight: 500; padding: 7px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); cursor: pointer; box-shadow: 0 1px 2px rgba(30, 20, 60, 0.05); }
.tabs button, button.icon { box-shadow: none; }
a.button { color: var(--ink); text-decoration: none; display: inline-block; }
button.primary { background: var(--button); color: var(--on-button); border-color: transparent; font-weight: 600; }
button:disabled { opacity: 0.5; cursor: default; }
/* Press feedback; tabs and drag grips stay still. */
button { transition: transform 160ms var(--ease-out); }
button.primary:not(:disabled):hover { filter: brightness(1.08); }
:not(.tabs) > button:active:not(:disabled, .grip) { transform: scale(0.97); }
button.icon { padding: 6px 8px; line-height: 0; border-color: transparent; background: transparent; color: var(--ink-2); }
button.icon:hover { background: var(--track); color: var(--ink); }
td.actions { text-align: right; white-space: nowrap; width: 1%; }
td.actions button + button { margin-left: 6px; }
tr.editing td { background: var(--page); }
td.grip-cell { width: 1%; padding-right: 0; }
button.grip { cursor: grab; font-size: 16px; line-height: 1; padding: 4px 6px; touch-action: none; }
tr.dragging td { opacity: 0.45; background: var(--track); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
button.danger { background: var(--critical); color: #fff; border-color: transparent; font-weight: 600; }
dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--ink); padding: 20px 22px; max-width: min(440px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
/* Dialogs fade and grow in from the centre (200ms) and leave a little faster (150ms). */
dialog, dialog::backdrop { transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out), overlay 200ms allow-discrete, display 200ms allow-discrete; }
dialog:not([open]), dialog:not([open])::backdrop { opacity: 0; transform: scale(0.96); transition-duration: 150ms; }
dialog:not([open])::backdrop { transform: none; }
@starting-style {
  dialog[open] { opacity: 0; transform: scale(0.96); }
  dialog[open]::backdrop { opacity: 0; }
}
dialog p { margin: 0 0 18px; color: var(--ink-2); }
input, select { font: inherit; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--axis); background: var(--surface); color: var(--ink); min-width: 0; }
input:focus-visible, select:focus-visible { outline: none; border-color: var(--series-1); box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-1) 25%, transparent); }
input[type="number"] { width: 110px; }
a { color: var(--series-1); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 13px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.scroll { overflow-x: auto; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px 20px; box-shadow: var(--shadow); }
.tile .label { color: var(--ink-2); font-size: 13px; font-weight: 500; }
.tile .value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile .note { color: var(--ink-2); font-size: 13px; }
a.tile { color: inherit; text-decoration: none; }
a.tile:hover { border-color: var(--series-1); }

.warnings { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.warnings li { display: flex; gap: 10px; align-items: baseline; padding: 8px 12px; border-radius: 8px; background: var(--page); border-left: 4px solid var(--muted); }
.warnings li.critical { border-color: var(--critical); }
.warnings li.warning { border-color: var(--warning); }
.warnings li.good { border-color: var(--good); }
.tag { font-weight: 600; font-size: 13px; white-space: nowrap; }

/* Meter: severity in the fill, same-ramp track, a tick where spending "should" be today */
.meter { position: relative; height: 10px; background: var(--track); border-radius: 5px; min-width: 120px; }
.meter > span { position: absolute; inset: 0 auto 0 0; border-radius: 5px; background: var(--series-1); max-width: 100%; }
.meter.over > span { background: var(--critical); }
.meter.ahead > span { background: var(--warning); }
.meter > i { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 6px; background: var(--key); }
#tip { position: fixed; pointer-events: none; background: var(--ink); color: var(--surface); padding: 6px 10px; border-radius: 6px; font-size: 13px; display: none; z-index: 10; }

.columns { display: flex; align-items: flex-end; gap: 8px; height: 170px; }
.columns > div { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-2); }
.columns b { width: 100%; max-width: 24px; background: var(--series-1); border-radius: 4px 4px 0 0; }
.columns .current b { background: var(--ink-2); }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
/* Confirmation toast: floats over the page so it never pushes content down */
.flash { position: fixed; left: 50%; bottom: 24px; z-index: 30; margin: 0; width: max-content; max-width: min(560px, calc(100vw - 32px));
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 6px 10px 14px; border-radius: 14px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-left: 4px solid var(--good);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18); transform: translateX(-50%); animation: toast-in 200ms var(--ease-out); }
.flash.error { border-left-color: var(--critical); }
.flash .mark { flex: none; line-height: 0; margin-top: 2px; color: var(--good); }
.flash.error .mark { color: var(--critical); }
.flash .text { flex: 1; padding-top: 1px; }
.flash button.icon { margin-top: -2px; }
.flash:empty { display: none; }
.flash.leaving { animation: toast-out 150ms var(--ease-out) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
/* Reduced motion: keep the fades, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  .flash { animation-name: fade-in; }
  .flash.leaving { animation-name: fade-out; }
  button:active, dialog, dialog:not([open]) { transform: none !important; }
  @starting-style { dialog[open] { transform: none; } }
}
.goal { display: grid; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--grid); }
.goal .meter { height: 12px; }

/* IOUs: one collapsible row per month; Review's Vendors by type: one per type */
:is(details.month, details.group) { border-bottom: 1px solid var(--grid); }
:is(details.month, details.group) > summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 24px; padding: 12px 4px; cursor: pointer; list-style: none; }
:is(details.month, details.group) > summary::-webkit-details-marker { display: none; }
:is(details.month, details.group) > summary::before { content: "▸"; color: var(--muted); transition: transform 0.15s; }
:is(details.month, details.group)[open] > summary::before { transform: rotate(90deg); }
:is(details.month, details.group) .month-name { flex: 1; min-width: 140px; font-weight: 600; }
:is(details.month, details.group) .month-owed { min-width: 130px; text-align: right; font-weight: 600; }
:is(details.month, details.group) > .scroll { padding: 0 0 12px 22px; }
details.month table { table-layout: fixed; }
details.month th:nth-child(1) { width: 12%; }
details.month th:nth-child(n+3) { width: 16%; }
details.group table { table-layout: fixed; } /* same columns in every type section */
details.group th:nth-child(1) { width: 30%; }
details.group th:nth-child(2) { width: 10%; }
details.group th:nth-child(n+3):nth-child(-n+4) { width: 12%; }
details.group th:nth-child(5) { width: 16%; }
details.month .month-note { flex-basis: 100%; padding-left: 22px; font-size: 13px; }

/* Review, Recently sorted: transactions from the latest sync or the last 3 days glow softly */
tr.fresh td { background: color-mix(in srgb, var(--series-1) 10%, transparent); }
tr.fresh td:first-child { box-shadow: inset 3px 0 var(--series-1); }
.new { font-size: 12px; font-weight: 600; color: var(--series-1); }

/* Limits & goals: Expenses is the page's main section */
section.focus { border: 2px solid var(--series-1); }
section.focus > h2 { font-size: 20px; }
.summary { margin: 0 0 12px; font-size: 16px; }
/* IOUs: the bill on the left, a narrow "Paid toward" panel on the right; stacked on narrow screens. */
.side-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 320px); gap: 20px; align-items: start; }
@media (max-width: 800px) { .side-split { grid-template-columns: 1fr; } }
section.small h2 { font-size: 15px; }
.toward { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.toward li { padding: 8px 0; border-bottom: 1px solid var(--grid); display: grid; gap: 2px; }

/* Left sidebar on wide screens; the highlight slides between pages (cross-page view transition). */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation: none; }
::view-transition-group(nav-pill) { animation-duration: 220ms; animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1); }
@media (prefers-reduced-motion: reduce) { ::view-transition-group(*) { animation: none; } }
nav .pill { display: none; }
@media (min-width: 801px) {
  body { display: grid; grid-template-columns: 236px minmax(0, 1fr); }
  header { position: sticky; top: 0; height: 100vh; flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 20px; padding: 28px 16px 20px; background: var(--surface); border-bottom: 0; border-right: 1px solid var(--border); }
  header h1 { padding: 0 12px; }
  nav { flex-direction: column; position: relative; }
  nav a { position: relative; z-index: 1; height: 40px; display: flex; align-items: center; padding: 0 12px; border-radius: 10px; }
  nav a[aria-current="page"] { background: transparent; color: var(--series-1); }
  nav .pill { display: block; position: absolute; inset: 0 0 auto; height: 40px; border-radius: 10px; background: var(--track); view-transition-name: nav-pill; }
  nav:has(> a:nth-of-type(2)[aria-current]) .pill { translate: 0 44px; }
  nav:has(> a:nth-of-type(3)[aria-current]) .pill { translate: 0 88px; }
  nav:has(> a:nth-of-type(4)[aria-current]) .pill { translate: 0 132px; }
  nav:has(> a:nth-of-type(5)[aria-current]) .pill { translate: 0 176px; }
  nav:has(> a:nth-of-type(6)[aria-current]) .pill { translate: 0 220px; }
  header > .row { padding: 0 4px; flex-wrap: nowrap; }
  main { width: 100%; margin: 0; padding: 32px 32px 64px; }
}
@media (hover: hover) and (pointer: fine) {
  nav a, button, .tabs button { transition: background-color 150ms ease, color 150ms ease, transform 160ms cubic-bezier(0.23, 1, 0.32, 1); }
  nav a:not([aria-current]):hover { background: var(--hover); color: var(--ink); }
  :not(.tabs) > button:not(.primary, .danger, .icon):not(:disabled):hover { background: var(--page); }
}

/* Long help text shows one line; click (or Enter) shows the rest. */
p.sub:not([id]) { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden; cursor: pointer; }
p.sub.open { display: block; cursor: auto; }
header > button.sync { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
@media (min-width: 801px) {
  header .spacer { display: none; }
  header > nav { margin-bottom: auto; } /* page buttons and Sync sit at the bottom of the sidebar */
}
/* Review's to-sort count in the nav */
nav a .badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--critical); color: #fff; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
@media (max-width: 800px) { nav a .badge { margin-left: 6px; } }
/* Account: <name> under Sync, and its menu (a popover in the top layer, placed by app.js) */
header > button.account-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu { position: fixed; inset: auto; margin: 0; min-width: 200px; max-width: calc(100vw - 32px); padding: 6px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--ink); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
  transform-origin: left bottom; opacity: 0; transform: translateX(-6px) scale(0.97);
  transition: opacity 160ms ease-out, transform 200ms cubic-bezier(0.23, 1, 0.32, 1), overlay 200ms allow-discrete, display 200ms allow-discrete; }
.account-menu.below { transform-origin: left top; transform: translateY(-6px) scale(0.97); }
.account-menu:popover-open { display: grid; opacity: 1; transform: none; }
@starting-style { .account-menu:popover-open { opacity: 0; transform: translateX(-6px) scale(0.97); } .account-menu.below:popover-open { transform: translateY(-6px) scale(0.97); } }
.account-menu > :is(a, button) { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; padding: 9px 12px;
  border: 0; border-radius: 9px; background: none; box-shadow: none; color: var(--ink); font: inherit; font-weight: 500; text-align: left; text-decoration: none; cursor: pointer; }
.account-menu > :is(a, button):is(:hover, :focus-visible) { background: var(--page); }
.account-menu > button { color: var(--critical); }
.account-menu .muted { font-weight: 400; font-size: 13px; }
@media (prefers-reduced-motion: reduce) { .account-menu, .account-menu.below, .account-menu:popover-open { transform: none; } @starting-style { .account-menu:popover-open, .account-menu.below:popover-open { transform: none; } } }
:is(button, a).link-button { border: 0; background: none; box-shadow: none; padding: 0; color: var(--series-1); font-size: 13px; text-decoration: underline; }

/* Sign-in and PIN pages */
body.gate { display: grid; grid-template-columns: 1fr; place-items: center; min-height: 100vh; padding: 16px; }
.gate-card { width: min(360px, 100%); display: grid; gap: 14px; }
.gate-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
.gate-card p { margin: 0; }
.gate-card label, form.stack label { display: grid; gap: 6px; font-weight: 500; font-size: 14px; }
.gate-card input { width: 100%; padding: 10px 12px; font-size: 16px; } /* 16px stops phones zooming in */
.gate-card button { padding: 10px 14px; }
.gate-card .link-button { justify-self: start; padding: 0; }
.gate-error { color: var(--critical); min-height: 1.4em; font-size: 14px; }
form.stack { display: grid; gap: 12px; max-width: 360px; }
form.stack input { width: 100%; }
nav:not(:has([aria-current])) .pill { display: none; } /* pages outside the nav, like Account */

/* PIN page: "Continue as <name>", four dots that fill as digits are typed (an invisible field takes the input) */
.pin-card { display: grid; justify-items: center; gap: 22px; text-align: center; width: min(360px, 100%); }
.pin-card h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.pin-card p { margin: 0; }
.dots-wrap { position: relative; display: block; padding: 10px; cursor: text; }
.dots { display: flex; gap: 20px; }
.dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink-2);
  transition: background-color 120ms ease-out, border-color 120ms ease-out, transform 160ms cubic-bezier(0.23, 1, 0.32, 1); }
.dots i.on { background: var(--series-1); border-color: var(--series-1); transform: scale(1.12); }
.dots.shake { animation: pin-shake 360ms cubic-bezier(0.36, 0.07, 0.19, 0.97); }
.dots.shake i { border-color: var(--critical); }
@keyframes pin-shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pin-capture { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; font-size: 16px; caret-color: transparent; }
@media (prefers-reduced-motion: reduce) { .dots.shake { animation: none; } .dots i, .dots i.on { transition: none; transform: none; } }
