/* Mateen Money. All visual values are tokens on :root; components never use raw colours. */

:root {
  --paper: #F3F6FC;
  --surface: #FFFFFF;
  --ink: #1B2638;
  --ink-2: #526079;
  --line: #D6E0F0;
  --accent: #2B63D9;
  --accent-press: #2353BA;
  --on-accent: #FFFFFF;
  --accent-soft: #E1EAFC;
  --warn: #8F5E0E;
  --warn-soft: #FDF0D9;
  --danger: #A3261B;
  --danger-soft: #FBE3DF;
  --backdrop: rgb(15 20 29 / 0.45);
  /* Behind a segmented control: the chosen segment is the surface colour on it. */
  --track: var(--line);
  /* Chart series, checked for colour blindness and contrast against --surface in each mode. */
  --series-1: #2B63D9;   /* spending */
  --series-2: #EB6834;   /* income */
  --series-muted: #A6B4CA;
  /* Money out is the spending blue, money in the income orange, everywhere: the exact series colours for fills,
     a -text shade of each that meets 4.5:1 for amounts, the ink that meets 4.5:1 on each fill, and a ~15% wash. */
  --spend: var(--series-1);
  --income: var(--series-2);
  --spend-text: #2B63D9;
  --income-text: #B9461A;
  --on-spend: #FFFFFF;
  --on-income: #1B2638;
  --spend-soft: color-mix(in srgb, var(--spend) 15%, transparent);
  --income-soft: color-mix(in srgb, var(--income) 15%, transparent);
  /* Behind the iOS status bar if it ever overlaps the page (with "black" it sits above it, and the strip is 0 high). */
  --status-bar: #1B2638;
  /* The headline is the one raised surface on Log: it holds the answer. Neutral, never tinted. */
  --shadow-raised: 0 1px 2px rgb(27 38 56 / 0.06), 0 6px 16px -6px rgb(27 38 56 / 0.16);
  --shadow-float: 0 2px 6px rgb(27 38 56 / 0.08), 0 20px 48px -12px rgb(27 38 56 / 0.32);

  --font-text: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Rounded on Apple devices; elsewhere the system sans. */
  --font-num: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Five text styles: screen title (--t-xl), section heading (--t-l), body (--t-m), small print (--t-s)
     and the number style (--font-num, tabular, 800; --t-xxl only for the amount being typed). */
  --t-s: 0.9375rem;   /* 15: small print */
  --t-m: 1.0625rem;   /* 17: body; stops iOS zooming on focus */
  --t-l: 1.375rem;    /* 22: section heading */
  --t-xl: 2.125rem;   /* 34: screen title and the answer's figure */
  --t-xxl: 3.5rem;    /* 56: the amount being typed */

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r-control: 12px;
  --r-panel: 22px;
  --touch: 48px;
  --tabbar: 64px;
  /* Below the tab bar: the home indicator's safe area less 14px. The full 34pt left a gap under
     the labels; 20pt still keeps them clear of the indicator. 0 on phones without one. */
  --tabbar-inset: max(calc(env(safe-area-inset-bottom) - 14px), 0px);
  /* Motion only explains a change of state, with no overshoot. */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0F141D;
    --surface: #172030;
    --ink: #E9EFF9;
    --ink-2: #A6B4CA;
    --line: #253247;
    --accent: #8AB4FF;
    --accent-press: #71A0F5;
    --on-accent: #0A1A33;
    --accent-soft: #1F3050;
    --warn: #EDBA62;
    --warn-soft: #3A2A14;
    --danger: #FF8F80;
    --danger-soft: #45201B;
    --track: var(--paper);
    --series-1: #3987E5;
    --series-2: #D95926;
    --series-muted: #526079;
    --spend-text: #6AA6F2;
    --income-text: #EE7D4A;
    --on-spend: #0F141D;
    --on-income: #0F141D;
    --status-bar: var(--paper);
    --shadow-raised: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 16px -6px rgb(0 0 0 / 0.5);
    --shadow-float: 0 2px 6px rgb(0 0 0 / 0.4), 0 20px 48px -12px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

/* Base. Hover styles sit in @media (hover: hover), so on a phone a tapped control never stays highlighted. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink);
  font: var(--t-m)/1.5 var(--font-text);
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
/* A quick second tap is a tap, never a zoom, anywhere on the page. The viewport's
   user-scalable=no is the sure stop on iOS; this keeps taps quick there too.
   On every element, not just html: a scrolling screen starts a new touch-action chain. */
* { touch-action: manipulation; }
/* With a see-through status bar over the page this strip kept its white text readable and
   content from showing through it. Zero high outside a home screen app. */
body::before {
  content: ''; position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: env(safe-area-inset-top); background: var(--status-bar); pointer-events: none;
}
/* Pull to refresh: a pill under the status bar that follows the finger. Words, not a spinner (no
   looping motion); the arrow turns once when letting go would refresh. */
.pull {
  position: fixed; z-index: 45; top: calc(env(safe-area-inset-top) + var(--s2)); left: 50%;
  display: inline-flex; align-items: center; gap: var(--s2); min-height: 40px; padding: 0 var(--s4);
  border-radius: 999px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-float);
  font-size: var(--t-s); font-weight: 600; white-space: nowrap; pointer-events: none;
  transform: translate(-50%, 0); opacity: 0;
}
.pull.leaving { transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out); }
.pull-arrow { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.15s var(--ease-out); }
.pull.ready .pull-arrow { transform: rotate(180deg); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Shell */

.top {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + var(--s4)) var(--s4) var(--s3);
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3);
}
.top h1 { font: 700 var(--t-xl)/1.1 var(--font-num); letter-spacing: -0.02em; }
/* Back to the screen this one was opened from (Accounts → Net Worth). */
.back-link {
  display: inline-flex; align-items: center; gap: var(--s1); min-height: 40px; margin: calc(-1 * var(--s2)) 0 0 calc(-1 * var(--s2)); padding: 0 var(--s3) 0 var(--s1);
  border-radius: 10px; color: var(--accent); font-weight: 700; text-decoration: none;
}
.back-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.back-link:active { background: var(--accent-soft); color: var(--accent-press); }
@media (hover: hover) { .back-link:hover { background: var(--accent-soft); color: var(--accent-press); } }
.synced { font-size: var(--t-s); color: var(--ink-2); margin-top: var(--s1); }
.scroller { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
main {
  max-width: 560px; margin: 0 auto;
  padding: 0 var(--s4) var(--s6);
}
.screen { display: grid; gap: var(--s5); }

.tabs {
  flex: none; position: relative; z-index: 10;
  /* Five tabs: each as wide as its label, the spare space shared between them so no two labels touch. */
  display: grid; grid-template-columns: repeat(5, auto); justify-content: space-evenly;
  padding-bottom: var(--tabbar-inset);
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.tabs a {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabbar); color: var(--ink-2); text-decoration: none;
  font-size: var(--t-s); font-weight: 600; line-height: 1.2; white-space: nowrap;
}
.tabs svg { width: 56px; height: 28px; padding: 2px 16px; border-radius: 999px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) { .tabs a:hover { color: var(--ink); } }
.tabs a:active { color: var(--accent-press); background: var(--accent-soft); }
.tabs a[aria-current] { color: var(--accent); }
/* The tab you're on (or under, for Accounts and IBKR): a pill behind its icon as well as the colour. */
.tabs a[aria-current] svg { background: var(--accent-soft); }
.tabs a:focus-visible { outline-offset: -3px; }
/* The narrowest phones: a slimmer pill so five labels still fit. */
/* The one exception to a single small-print size: labels 1px smaller, so five fit (the user's choice over shortening one). */
@media (max-width: 359px) { .tabs svg { width: 40px; padding: 2px 8px; } .tabs a { letter-spacing: -0.02em; font-size: calc(var(--t-s) - 1px); } }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent);
  font: 700 var(--t-s)/20px var(--font-num); text-align: center;
}

/* The headline: the one raised surface on Log */

.headline {
  padding: var(--s4);
  background: var(--surface);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-raised);
  display: grid; gap: var(--s2);
}
.headline-figure { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 var(--s2); }
.headline-figure .num { font: 800 var(--t-xl)/1 var(--font-num); letter-spacing: -0.03em; }
.headline-figure .unit { font-size: var(--t-m); font-weight: 600; color: var(--ink-2); }
.headline.negative .num { color: var(--danger); }
.headline-safe, .headline-change { font-weight: 600; }
.headline-safe.over { color: var(--danger); }
.budget-status { font-size: var(--t-s); }
.budget-status.over { color: var(--danger); }
.budget-status.heading { color: var(--warn); }
.list-row.budget-row { display: grid; gap: var(--s1); align-items: stretch; justify-content: stretch; }
.list-row.static { cursor: default; }
@media (hover: hover) { .list-row.static:hover { background: transparent; } }
.list-row.static:active { background: transparent; }
.budget-top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.budget-row .meter { margin-top: var(--s1); }
.reason { font-size: var(--t-s); color: var(--ink-2); }
/* Not connected yet: one slim line in place of the headline. */
.connect-banner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s1) var(--s1) var(--s1) var(--s3); border-radius: var(--r-control);
  background: var(--accent-soft); font-size: var(--t-s); font-weight: 600;
}
.connect-banner > span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.connect-banner .text-button { margin: 0; flex: none; }

/* The figure changed (after a save or a sync): it eases into its new value. */
.headline-figure .num.changed { animation: changed 0.3s var(--ease-out); }
@keyframes changed { from { opacity: 0.3; transform: translateY(4px); } to { opacity: 1; transform: none; } }
/* A sheet opening comes up from the bottom, where it closes to. */
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Sections */

.section { display: grid; gap: var(--s3); }
.subhead { display: flex; align-items: center; gap: var(--s2); font: 700 var(--t-l)/1.1 var(--font-num); letter-spacing: -0.02em; }

/* Lists */

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 16px; overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  width: 100%; min-height: 60px; padding: var(--s3) var(--s4);
  border: 0; background: transparent; text-align: left; cursor: pointer;
}
@media (hover: hover) { .list-row:hover { background: color-mix(in srgb, var(--surface) 90%, var(--accent-soft)); } }
.list-row:active { background: var(--accent-soft); }
.list-row:focus-visible { outline-offset: -3px; }
.list-main { display: grid; min-width: 0; }
.list-title { font-weight: 600; overflow-wrap: anywhere; }
.list-sub { font-size: var(--t-s); color: var(--ink-2); }
.list-amount { font-family: var(--font-num); font-weight: 700; flex: none; }
/* Money out in blue, money in in orange. The label or the +/− beside it always says which too. */
.list-amount.spend, .cat-table td.spend { color: var(--spend-text); }
.list-amount.income { color: var(--income-text); }
/* Said instead of an amount ("No price yet"): small print. */
.list-amount.muted { font: 600 var(--t-s) var(--font-text); color: var(--ink-2); }
/* A category icon (or what the row is) at the start of a row: neutral, so the amount keeps the colour. */
.row-icon {
  display: inline-grid; place-items: center; flex: none; align-self: center;
  width: 36px; height: 36px; border-radius: 50%; background: var(--paper); color: var(--ink-2);
}
.row-icon + .list-main { margin-right: auto; }
a.list-row { color: inherit; text-decoration: none; }
/* A row that opens another screen ends in a chevron. */
.row-end-icon { display: inline-grid; flex: none; color: var(--ink-2); }
.row-end-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cat-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sort-item { padding-bottom: var(--s3); }
/* Every choice in view: the row wraps instead of scrolling sideways. */
.sort-item .chips { padding: 0 var(--s4); }

/* Weekly review: a flat card (the headline stays the one raised surface). */

.review { display: grid; gap: var(--s3); padding: var(--s4); background: var(--surface); border-radius: 16px; }
.review-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.review-figure { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 var(--s2); }
.review-figure .num { font: 800 var(--t-xl)/1 var(--font-num); letter-spacing: -0.03em; }
.review-figure .unit { color: var(--ink-2); font-weight: 600; }
.review-sub { font: 600 var(--t-m)/1.5 var(--font-text); margin-top: var(--s2); }
.review-list { display: grid; gap: var(--s2); }
.review-actions { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; margin-top: var(--s1); }
.review-actions .button { flex: none; }
.review-actions .text-button { margin-left: 0; }
.review .cat-table, .review .list { background: var(--paper); }

/* Overview */

.filters { display: grid; gap: var(--s3); }
.period-nav { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--s2); }
.period-label { text-align: center; font: 700 var(--t-l)/1.1 var(--font-num); letter-spacing: -0.02em; }
.period-label-small { font-size: var(--t-m); }
.total-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 60px; padding: var(--s3) var(--s4); }
.trip-row { align-items: flex-start; }
.list-amount.danger, .list-sub.danger { color: var(--danger); }
/* Net Worth: an amount with its own currency under it, and a balance that needs updating. */
.list-end { display: grid; justify-items: end; flex: none; text-align: right; }
.list-sub.stale { color: var(--warn); font-weight: 600; }
.subhead-amount { margin-left: auto; font-size: var(--t-m); font-weight: 700; letter-spacing: 0; }
.stale-warning { display: grid; gap: var(--s1); justify-items: start; }
/* Left over: the figure the period comes down to, so it's the one row with a fill. */
.total-row.standout { min-height: 72px; background: var(--accent-soft); }
/* Red when more was spent than came in ("Overspent" says so too). The budget's state lives in its own section. Solid tints only. */
.total-row.standout.state-over { background: var(--danger-soft); }
.total-row.standout .list-title { font-weight: 700; }
.total-row.standout .list-amount { font-size: var(--t-xl); font-weight: 800; letter-spacing: -0.03em; line-height: 1; }

.cat-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 16px; overflow: hidden; }
.cat-table tr + tr { border-top: 1px solid var(--line); }
.cat-table th, .cat-table td { padding: var(--s3) var(--s4); text-align: left; vertical-align: top; }
/* One gap between the meter and its amount (the amount's), so long names and amounts fit at 375px. */
.cat-table th { font-weight: 600; width: 100%; padding-right: 0; }
.cat-table td { text-align: right; white-space: nowrap; font-family: var(--font-num); font-weight: 700; }
.cat-table td + td { padding-left: 0; }
.cat-table .share { color: var(--ink-2); font-weight: 600; min-width: 3.5em; }
/* The narrowest phones: a one-word name, its amount and its share don't fit side by side, so the
   share goes under the amount. */
@media (max-width: 359px) {
  .cat-table, .cat-table tbody { display: block; }
  .cat-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .cat-table th { grid-row: 1 / span 2; }
  .cat-table td, .cat-table td + td { padding-left: var(--s3); }
  .cat-table td + td { padding-top: 0; }
  .cat-table .share { min-width: 0; }
}
.cat-name { display: block; }
.all-categories { display: grid; gap: var(--s2); }
.meter { display: block; height: 8px; margin-top: var(--s2); border-radius: 4px; background: var(--line); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 4px; }
.fill-1 { background: var(--series-1); }
.fill-muted { background: var(--series-muted); }
/* Net worth's meters and line are ink: blue means money out. */
/* Net worth's meters: accent blue, by the user's choice (an exception to blue meaning money out). */
.fill-accent { background: var(--accent); }
.fill-warn { background: var(--warn); }
.fill-danger { background: var(--danger); }

.mark-1 { fill: var(--series-1); }
.mark-2 { fill: var(--series-2); }
.mark-accent { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.mark-accent-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.crosshair { stroke: var(--ink-2); stroke-width: 1; }
/* Dragging across the line moves the crosshair; scrolling up and down still scrolls. */
.worth-chart { cursor: crosshair; touch-action: pan-y; }
.worth-chart:focus-visible { outline-offset: 4px; border-radius: 4px; }

.chart-figure { margin: 0; padding: var(--s4); background: var(--surface); border-radius: 16px; display: grid; gap: var(--s3); }
.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .baseline { stroke: var(--ink-2); stroke-width: 1; }
.chart .axis { fill: var(--ink-2); font: 600 var(--t-s) var(--font-num); font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; }
.chart .month { cursor: pointer; outline: none; }
.chart .month.on .hit, .chart .month:focus-visible .hit { fill: var(--accent-soft); }
.chart .month:focus-visible .hit { stroke: var(--accent); stroke-width: 2; }
.legend { display: flex; gap: var(--s4); font-size: var(--t-s); color: var(--ink-2); font-weight: 600; }
.legend > span { display: inline-flex; align-items: center; gap: var(--s2); }
.swatch { width: 12px; height: 12px; border-radius: 3px; }
.swatch-1, .key-1 { background: var(--series-1); }
.swatch-2, .key-2 { background: var(--series-2); }
.chart-tip {
  position: absolute; top: 0; left: 0; width: max-content; max-width: 100%; pointer-events: none; white-space: nowrap;
  padding: var(--s2) var(--s3); border-radius: 10px; background: var(--ink); color: var(--paper);
  font-size: var(--t-s); box-shadow: var(--shadow-float);
}
.tip-title { font-weight: 600; }
.tip-row { display: flex; align-items: center; gap: var(--s1); }
.tip-row strong { font: 700 var(--t-s) var(--font-num); font-variant-numeric: tabular-nums; }
.line-key { display: inline-block; flex: none; width: 12px; height: 3px; border-radius: 2px; margin-right: var(--s1); }
.table-view summary {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--s3); margin-left: calc(-1 * var(--s3));
  border-radius: 10px; color: var(--accent); font-weight: 700; cursor: pointer; list-style: none;
}
.table-view summary::-webkit-details-marker { display: none; }
.table-view summary:active { background: var(--accent-soft); color: var(--accent-press); }
@media (hover: hover) { .table-view summary:hover { background: var(--accent-soft); color: var(--accent-press); } }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--t-s); }
.data-table th, .data-table td { padding: var(--s2) 0; border-top: 1px solid var(--line); text-align: left; }
.data-table thead th { border-top: 0; color: var(--ink-2); font-weight: 600; }
.data-table td, .data-table thead th + th { text-align: right; }
/* Amounts never wrap and keep a gap from the column before, so neighbouring figures can't run together. */
.data-table td, .data-table thead th + th { padding-left: var(--s3); white-space: nowrap; }

/* History, Plan, Settings */

.filter-row { display: flex; flex-wrap: wrap; gap: var(--s2); }
/* Each filter keeps its whole label; it wraps to a new row when there's no room and fills the row it's on. */
.select.select-small { flex: 1 1 auto; width: auto; max-width: 100%; min-height: 40px; border-radius: 999px; font-size: var(--t-s); font-weight: 600; }
/* The category filter shows the picked category's icon inside its pill (a native select can't draw one per option). */
.select-icon { position: relative; display: flex; flex: 1 1 auto; max-width: 100%; }
.select-icon .select.select-small { padding-left: 40px; }
.select-icon .cat-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; }
.day { gap: var(--s2); }
.day-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); font: 600 var(--t-m)/1.5 var(--font-text); }
.day-total { font: 600 var(--t-s) var(--font-text); color: var(--ink-2); }
.list-title .tag { margin-left: var(--s2); }
.list-note { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tag.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag.tag-quiet { background: var(--paper); color: var(--ink-2); }
.reorder-row { display: flex; align-items: center; padding-right: var(--s1); }
.reorder-row .list-row { flex: 1; min-width: 0; }
.add-row { display: grid; grid-template-columns: 1fr auto; gap: var(--s2); }
.add-row .button { width: auto; min-height: var(--touch); padding: 0 var(--s4); }
/* Term dates sit on one card, a line between terms, so the three read as one group and each term as its own row. */
.terms { background: var(--surface); border-radius: 16px; overflow: hidden; }
.term { display: grid; gap: var(--s2); margin: 0; padding: var(--s4); border: 0; min-width: 0; }
.term + .term { border-top: 1px solid var(--line); }
.term legend { float: left; width: 100%; padding: 0; font-weight: 600; }
.terms .input { background: var(--paper); }
.button-stack { display: grid; gap: var(--s2); }
.plan-summary { display: grid; gap: var(--s2); }
/* Sections sit further apart than the lines inside them, so each reads as one group. */
.settings, .sections { gap: var(--s6); }
/* Settings is one long screen of like-looking groups: a rule above each heading marks where the next one starts. */
.settings { gap: var(--s5); }
.settings > .section + .section { padding-top: var(--s5); border-top: 1px solid var(--line); }
.text-button.inline { margin-left: 0; }

/* Chips */

.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  min-height: 40px; padding: 0 var(--s4);
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: var(--t-s); font-weight: 600; cursor: pointer;
}
.chip:has(.cat-icon) { display: inline-flex; align-items: center; gap: 6px; padding-left: var(--s3); }
.chip .cat-icon { width: 18px; height: 18px; color: var(--ink-2); }
.chip[aria-checked="true"] .cat-icon, .chip[aria-pressed="true"] .cat-icon { color: currentColor; }
@media (hover: hover) { .chip:hover { border-color: var(--ink-2); } }
.chip:active { border-color: var(--accent); background: var(--accent-soft); }
.chip[aria-checked="true"], .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip:disabled { background: var(--paper); color: var(--ink-2); border-style: dashed; cursor: default; }

/* Segmented control: switches what the screen shows (never a value being picked). */

.segmented {
  display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; gap: 2px;
  padding: 3px; border-radius: var(--r-control); background: var(--track); box-shadow: inset 0 0 0 1px var(--line);
}
.segment {
  min-height: 40px; padding: 0 var(--s2); border: 0; border-radius: 9px;
  background: transparent; color: var(--ink-2); font-size: var(--t-s); font-weight: 600; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}
@media (hover: hover) { .segment:hover { background: color-mix(in srgb, var(--track) 50%, var(--surface)); color: var(--ink); } }
.segment:active { background: var(--surface); color: var(--ink); }
/* The chosen segment: a solid accent fill; the others stay muted. */
.segment[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
/* Spent / Received and Cost / Income: the fill says money out (blue) or money in (orange). */
.kind-switch .segment[data-value="spend"][aria-checked="true"] { background: var(--spend); color: var(--on-spend); }
.kind-switch .segment[data-value="income"][aria-checked="true"] { background: var(--income); color: var(--on-income); }
@media (hover: hover) {
  .kind-switch .segment[data-value="spend"]:not([aria-checked="true"]):hover { background: var(--spend-soft); }
  .kind-switch .segment[data-value="income"]:not([aria-checked="true"]):hover { background: var(--income-soft); }
}
.kind-switch .segment[data-value="spend"]:not([aria-checked="true"]):active { background: var(--spend-soft); }
.kind-switch .segment[data-value="income"]:not([aria-checked="true"]):active { background: var(--income-soft); }
.segment:focus-visible { outline-offset: -2px; }

/* The Split block (Log, the edit sheet, Sort Payment): its rows sit apart like the form's fields. */
.split-block { display: grid; gap: var(--s4); }
.split-off { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: var(--touch); }
.split-off .text-button { margin: 0 calc(-1 * var(--s3)) 0 0; }
.split-add { display: flex; gap: var(--s2); }
.split-add .input { flex: 1; min-width: 0; }
.split-add .button { width: auto; flex: none; margin: 0; }
/* Split With: a select-like box naming who's ticked, folding out a list of tick boxes under it. */
.multi-select summary { display: flex; align-items: center; list-style: none; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.multi-select summary::-webkit-details-marker { display: none; }
.multi-select[open] summary { border-color: var(--accent); }
.multi-empty { color: var(--ink-2); }
.multi-options { display: grid; margin-top: var(--s2); padding: var(--s1) var(--s3); border: 1px solid var(--line); border-radius: var(--r-control); background: var(--surface); }
.multi-options .text-button { justify-self: start; margin-left: calc(-1 * var(--s3)); }

/* The entry form */

.entry { display: grid; gap: var(--s3); }
.pad-display {
  display: flex; align-items: baseline; justify-content: center; gap: var(--s2);
  padding: var(--s3) 0 var(--s1); font-family: var(--font-num);
}
.pad-display .currency {
  min-height: 40px; padding: 0 var(--s2); border: 0; border-radius: 10px; background: transparent;
  font: 700 var(--t-l) var(--font-num); color: var(--ink-2); cursor: pointer;
}
.pad-display .currency:active { background: var(--accent-soft); color: var(--ink); }
@media (hover: hover) { .pad-display .currency:hover { background: var(--accent-soft); color: var(--ink); } }
.pad-display .num { font-size: var(--t-xxl); font-weight: 800; letter-spacing: -0.03em; line-height: 1; transition: color 0.15s; }
.entry[data-kind="spend"] .pad-display .num:not(.placeholder) { color: var(--spend-text); }
.entry[data-kind="income"] .pad-display .num:not(.placeholder) { color: var(--income-text); }
.pad-display .num.placeholder { color: var(--ink-2); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.key {
  min-height: 56px; border: 0; border-radius: 16px; background: var(--surface);
  font: 700 var(--t-l) var(--font-num); cursor: pointer;
}
@media (hover: hover) { .key:hover { background: color-mix(in srgb, var(--surface) 90%, var(--accent-soft)); } }
.key:active { background: var(--accent-soft); color: var(--accent-press); }
.summary { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); font-size: var(--t-s); color: var(--ink-2); }

/* Fields */

.field { display: grid; gap: var(--s1); }
.field-label { font-size: var(--t-s); font-weight: 600; color: var(--ink-2); }
.field-hint { font-size: var(--t-s); color: var(--ink-2); }
.input, .select {
  width: 100%; min-height: var(--touch); padding: 0 var(--s3);
  border: 1px solid var(--line); border-radius: var(--r-control);
  background: var(--surface); font-size: var(--t-m);
}
@media (hover: hover) { .input:hover, .select:hover { border-color: var(--ink-2); } }
.input:focus-visible, .select:focus-visible { outline-offset: 0; border-color: var(--accent); }
/* A field that can't change here (a settled bill's amount): the page colour, muted, with the reason said above it. */
.input[readonly], .select:disabled { background: var(--paper); color: var(--ink-2); }
.select {
  appearance: none; padding-right: var(--s6);
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat;
}
.row-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s3); }
/* iOS gives date and time inputs a fixed minimum width and centres the text; make them fit like the rest. */
.input[type="date"], .input[type="time"] { min-width: 0; -webkit-appearance: none; appearance: none; text-align: left; }
.input::-webkit-date-and-time-value { text-align: left; }
.toggle { display: flex; align-items: center; gap: var(--s3); min-height: var(--touch); font-weight: 600; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.details { display: grid; gap: var(--s4); padding-top: var(--s2); scroll-margin-top: var(--s4); }

/* Buttons: one primary (filled) and one secondary (text) style. Danger is the secondary style in red. */

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  width: 100%; border-radius: 14px; font-weight: 700; cursor: pointer;
}
a.button { text-decoration: none; }
.button.primary { min-height: 52px; border: 0; background: var(--accent); color: var(--on-accent); font-size: var(--t-m); }
.button.primary:active { background: var(--accent-press); }
@media (hover: hover) { .button.primary:hover { background: var(--accent-press); } }
.button.primary:disabled { background: var(--line); color: var(--ink-2); cursor: default; }
.button.secondary, .button.danger {
  width: fit-content; max-width: 100%; justify-self: start; justify-content: flex-start;
  min-height: 40px; padding: 0 var(--s3); margin-left: calc(-1 * var(--s3));
  border: 0; border-radius: 10px; background: transparent; color: var(--accent); text-align: left;
}
.button.secondary:active { background: var(--accent-soft); color: var(--accent-press); }
@media (hover: hover) { .button.secondary:hover { background: var(--accent-soft); color: var(--accent-press); } }
.button.secondary:disabled { color: var(--ink-2); background: transparent; cursor: default; }
.button.danger { color: var(--danger); }
/* Secondary buttons side by side (Update balances, Move money); they wrap on a narrow screen. */
.button-row { display: flex; flex-wrap: wrap; column-gap: var(--s5); }
.button.danger:active { background: var(--danger-soft); }
@media (hover: hover) { .button.danger:hover { background: var(--danger-soft); } }
.text-button {
  min-height: 40px; padding: 0 var(--s3); margin-left: calc(-1 * var(--s3));
  border: 0; border-radius: 10px; background: transparent; color: var(--accent); font-weight: 700; cursor: pointer;
}
.text-button:active { background: var(--accent-soft); color: var(--accent-press); }
@media (hover: hover) { .text-button:hover { background: var(--accent-soft); color: var(--accent-press); } }
.link-row { display: flex; flex-wrap: wrap; column-gap: var(--s5); }
.link-row .text-button { margin-left: calc(-1 * var(--s3)); }
.summary .text-button { margin: 0 calc(-1 * var(--s3)) 0 0; flex: none; }
.icon-button {
  display: inline-grid; place-items: center; flex: none;
  width: var(--touch); height: var(--touch); border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.icon-button:active { background: var(--accent-soft); color: var(--ink); }
@media (hover: hover) { .icon-button:hover { background: var(--accent-soft); color: var(--ink); } }
.icon-button:disabled { opacity: 0.35; cursor: default; background: transparent; }
/* The Settings gear: a quiet filled circle, accent-tinted while Settings is open; never an outline ring. */
#settings { background: var(--surface); }
#settings[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
#settings:focus:not(:focus-visible) { outline: none; }
#settings:active { background: var(--accent-soft); color: var(--ink); }
@media (hover: hover) { #settings:hover { background: var(--accent-soft); color: var(--ink); } }
.icon-button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Hints, warnings, tags */

.hint, .warning { font-size: var(--t-s); padding: var(--s2) var(--s3); border-radius: 10px; }
.hint { background: var(--accent-soft); }
/* A warning sits on the surface it's in, marked by an amber rule at its start: a filled amber box looked muddy on the dark card. */
.warning { background: none; border-left: 3px solid var(--warn); border-radius: 0; color: var(--ink); }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft);
  color: var(--ink); font: 600 var(--t-s)/1.4 var(--font-text); letter-spacing: 0;
}
.empty-line { color: var(--ink-2); padding: var(--s3) 0; }
.empty { padding: 0 0 var(--s6); display: grid; gap: var(--s3); }
.empty h2, .empty p { max-width: 34ch; }
.empty h2 { font: 700 var(--t-l)/1.1 var(--font-num); letter-spacing: -0.02em; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s4); margin: 0; font-size: var(--t-s); }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 600; }

/* Sheets */

.sheet {
  width: 100%; max-width: 560px; max-height: min(92dvh, calc(100dvh - env(safe-area-inset-top) - var(--s2))); margin: auto auto 0;
  padding: 0 var(--s4) calc(env(safe-area-inset-bottom) + var(--s4));
  border: 0; border-radius: var(--r-panel) var(--r-panel) 0 0;
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow-float); overflow-y: auto;
}
.sheet[open] { animation: rise 0.25s var(--ease-out); }
.sheet::backdrop { background: var(--backdrop); }
.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s4) 0 var(--s2); background: var(--paper);
}
.sheet-head h2 { font: 700 var(--t-l)/1.1 var(--font-num); letter-spacing: -0.02em; }
.sheet-form { display: grid; gap: var(--s4); }
.sheet-actions { display: grid; gap: var(--s2); margin-top: var(--s5); }

/* Toast and update pill */

#toast {
  position: fixed; left: var(--s4); right: var(--s4); z-index: 20;
  bottom: calc(var(--tabbar) + var(--tabbar-inset) + var(--s3));
  max-width: 528px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) var(--s4); border-radius: 14px;
  background: var(--ink); color: var(--paper); font-size: var(--t-s); box-shadow: var(--shadow-float);
  opacity: 0; transform: translateY(12px); pointer-events: none;
  transition: opacity 0.2s, transform 0.2s var(--ease-out);
}
#toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast-action {
  flex: none; min-height: 40px; padding: 0 var(--s3); border: 0; border-radius: 10px;
  background: transparent; color: var(--accent-soft); font-weight: 700; cursor: pointer;
}
.toast-action:active { background: color-mix(in srgb, var(--ink) 80%, var(--paper)); }
@media (hover: hover) { .toast-action:hover { background: color-mix(in srgb, var(--ink) 80%, var(--paper)); } }
.update {
  position: fixed; top: calc(env(safe-area-inset-top) + var(--s2)); left: 50%; z-index: 30;
  min-height: 40px; padding: 0 var(--s4); border: 0; border-radius: 999px;
  background: var(--accent); color: var(--on-accent); font: 600 var(--t-s) var(--font-text);
  box-shadow: var(--shadow-float); cursor: pointer; transform: translateX(-50%);
}
.update:active { background: var(--accent-press); }
@media (hover: hover) { .update:hover { background: var(--accent-press); } }

/* Figures always line up. */
.num, .list-amount, .key, .pad-display, .badge, .headline, .facts dd, .cat-table td, .data-table td, .day-total {
  font-variant-numeric: lining-nums tabular-nums;
  font-feature-settings: "lnum" 1, "tnum" 1;
}

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

/* People: what's owed, in the colour of the way the money will move (the words say which too). */
.subhead.income { color: var(--income-text); }
.subhead.spend { color: var(--spend-text); }
/* Four labels in one switch (History): each segment as wide as its label, the spare space shared, so
   "Merchants" fits beside "People" at 375px. */
.segmented.fit { display: flex; }
.segmented.fit .segment { flex: 1 1 auto; min-width: 0; padding: 0 4px; }
/* Under 360px, as the tab labels: 1px smaller and a little tighter, so the words still fit. */
@media (max-width: 359px) { .segmented.fit .segment { padding: 0 2px; letter-spacing: -0.02em; font-size: calc(var(--t-s) - 1px); } }
