/* ForMyLife — Life Budgeting — on the Piper Design System (piper-tokens.css, loaded first; docs/THEMES.md).
   Three layouts: phone, tablet, desktop. */

/* ForMyLife's tokens are names for the design system's. System, Light and Dark are the Piper core plus
   ForMyLife's orange (<html data-piper-app="formylife">; data-color-scheme="light|dark" when Light or
   Dark is chosen), so they follow the device, the picker and Increase Contrast with no values
   here. A named theme (themes.css, data-theme) sets the colour tokens itself. */
:root {
  --font: var(--piper-font-text);
  --mono: var(--piper-font-mono);
  --radius: var(--piper-radius-lg);
  --radius-sm: var(--piper-radius-md);
  --page: var(--piper-background-grouped);
  --page-ink: var(--piper-label);
  --surface: var(--piper-surface);
  /* A quiet fill that shows on both the page and a card. */
  --surface-2: color-mix(in srgb, var(--piper-label) 6%, var(--piper-surface));
  --line: var(--piper-separator);
  --ink: var(--piper-label);
  --muted: var(--piper-label-secondary);
  /* Orange as text, filled buttons and focus is the accent ink (4.5:1 on every core background,
     white text on it in light and black in dark); --accent-2 is the brand orange for marks. */
  --accent: var(--piper-accent-ink);
  --accent-strong: var(--piper-accent-ink);
  --accent-2: var(--piper-accent);
  --on-accent: var(--piper-on-accent);
  --accent-soft: color-mix(in srgb, var(--piper-accent) 10%, var(--piper-surface));
  --mint: var(--piper-success-ink);
  --mint-soft: var(--piper-success-tint);
  --danger: var(--piper-critical-ink);
  --danger-soft: var(--piper-critical-tint);
  --sun: var(--piper-warning-ink);
  --avatar-ink: var(--accent);
  --usable-ink: var(--mint);
  --shadow: var(--piper-shadow-1);
  /* The Forest stage, ForMyLife's signature (Ready to Assign): one forest in light and dark, so what
     sits on it is decided once. Cream text 11.6:1, quiet text 7.8:1, the dark accent ink with
     black text for a button (4.15:1 on the stage), borders 4.5:1, a track darker than the stage
     so the bar reads against both. */
  --stage: #133A2E;
  --stage-ink: #FBF5EC;
  --stage-quiet: #BFD0C6;
  --stage-accent: #F16C34;
  --stage-on-accent: #000000;
  --stage-line: #7FA393;
  --stage-track: #0B2219;
  --stage-negative: #FF9E98;
  /* Over-assigned: the stage turns red, with the word. */
  --stage-over: #7D221D;
  --stage-over-quiet: #FFE1DA;
  --stage-over-track: #4B1411;
  --tabbar-height: 0px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* One keyboard focus ring everywhere: buttons, links, rows and fields. */
:focus-visible { outline: var(--piper-focus-width) solid var(--accent-strong); outline-offset: var(--piper-focus-offset); }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--piper-text-callout-size);
  background: var(--page);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link:focus { position: fixed; z-index: 100; top: 12px; left: 12px; }

/* ---------- Shell ---------- */

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--piper-space-4);
  padding: var(--piper-space-3) clamp(var(--piper-space-4), 3vw, var(--piper-space-8));
  padding-top: max(var(--piper-space-3), env(safe-area-inset-top));
  background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.brand {
  display: inline-flex; align-items: center; gap: var(--piper-space-3);
  text-decoration: none; font-weight: 700; letter-spacing: -.01em;
}
/* The mark: black on the brand orange (6.2:1), the same in every theme. */
.brand-name { font-size: var(--piper-text-callout-size); white-space: nowrap; }
.brand-domain { color: var(--muted); font-weight: 500; }

.topnav { display: none; gap: var(--piper-space-1); margin-left: var(--piper-space-3); }
.topnav a {
  text-decoration: none; padding: var(--piper-space-2) var(--piper-space-4); border-radius: var(--piper-radius-pill); font-weight: 550; font-size: var(--piper-text-subheadline-size);
  color: var(--muted);
}
.topnav a:hover, .topnav a:focus-visible { background: var(--surface-2); color: var(--ink); }
.topnav a[aria-current="page"] { background: var(--ink); color: var(--page); }

.topbar-status { margin-left: auto; display: flex; align-items: center; gap: var(--piper-space-3); font-size: var(--piper-text-footnote-size); color: var(--muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 4px color-mix(in srgb, var(--mint) 18%, transparent); }
.status-dot.dirty { background: var(--sun); box-shadow: 0 0 0 4px color-mix(in srgb, var(--sun) 20%, transparent); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 20%, transparent); }

.avatar-button {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; padding: 0;
}
.avatar-initial { font-weight: 700; color: var(--avatar-ink); background: var(--accent-soft); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: var(--piper-text-footnote-size); }

main { padding: var(--piper-space-6) clamp(var(--piper-space-4), 3vw, var(--piper-space-8)) 96px; width: min(1240px, 100%); margin: 0 auto; }
.view { display: contents; }

.tabbar { display: none; }

/* ---------- Type ---------- */

h1, h2, h3, h4 { margin: 0; letter-spacing: -.02em; line-height: 1.15; }
.eyebrow {
  font-size: var(--piper-text-caption1-size); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
/* Every figure lines up: tabular numerals wherever a dollar amount or count is shown. */
.money, .has-amount, .metric-value, .account-balance, .cat-available, .cat-budgeted, .cat-activity { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.positive { color: var(--mint); }
.negative { color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: var(--piper-text-footnote-size); }

/* ---------- Month header ---------- */

.month-head {
  display: grid;
  gap: var(--piper-space-4);
  margin-bottom: var(--piper-space-4);
}
.month-title-row { display: flex; align-items: center; gap: var(--piper-space-3); flex-wrap: wrap; }
.month-title-row h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
.month-arrows { display: inline-flex; gap: var(--piper-space-1); }
.icon-button {
  width: 36px; height: 36px; border-radius: var(--piper-radius-md); border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; font-size: var(--piper-text-callout-size); color: var(--ink);
}
.icon-button:hover { background: var(--surface-2); }
.icon-button:disabled { opacity: .35; cursor: default; }
.month-today { font-size: var(--piper-text-footnote-size); color: var(--muted); text-decoration: underline; text-underline-offset: 3px; margin-left: var(--piper-space-1); }

.hero-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--piper-space-3);
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--piper-space-4) var(--piper-space-4);
  display: grid;
  gap: var(--piper-space-1);
  box-shadow: var(--shadow);
}
.metric .metric-label { font-size: var(--piper-text-caption1-size); font-weight: 650; letter-spacing: .04em; color: var(--muted); text-transform: uppercase; }
.metric .metric-value { font-size: clamp(1.5rem, 4vw, 1.95rem); font-weight: 720; letter-spacing: -.03em; }
.metric .metric-note { font-size: var(--piper-text-footnote-size); color: var(--muted); }
/* The Forest stage: the one lit card (tokens in :root). Its colours never follow light or dark. */
.metric.primary {
  background: var(--stage); color: var(--stage-ink);
  border-color: color-mix(in srgb, var(--stage-line) 35%, var(--stage));
  border-radius: var(--piper-radius-xl);
}
.metric.primary .metric-label, .metric.primary .metric-note { color: var(--stage-quiet); }
/* The hero figure: largeTitle, in the system face. */
.metric.primary .metric-value { font-size: var(--piper-text-large-title-size); line-height: var(--piper-text-large-title-leading); font-weight: 700; letter-spacing: -.02em; }
.metric.primary .metric-value.negative { color: var(--stage-negative); }
.metric.primary :focus-visible { outline-color: var(--stage-ink); }
.metric.primary .button { background: transparent; border-color: var(--stage-line); color: var(--stage-ink); }
.metric.primary .button:hover { background: color-mix(in srgb, var(--stage-ink) 12%, transparent); }
.metric.primary .button.primary { background: var(--stage-accent); border-color: transparent; color: var(--stage-on-accent); }
/* How much of the money has a job: a bar and the share in words. */
.stage-share { display: grid; gap: var(--piper-space-2); margin-top: var(--piper-space-2); }
.stage-track { display: block; height: 8px; border-radius: var(--piper-radius-pill); background: var(--stage-track); border: 1px solid var(--stage-line); overflow: hidden; }
.stage-track > span { display: block; height: 100%; background: var(--stage-accent); }
.stage-share-text { font-size: var(--piper-text-footnote-size); font-weight: 600; color: var(--stage-ink); font-variant-numeric: tabular-nums; }

.assign-bar {
  display: flex; flex-wrap: wrap; gap: var(--piper-space-2); margin-top: var(--piper-space-3);
}
.button {
  border-radius: var(--piper-radius-pill); border: 1px solid var(--line); background: var(--surface);
  padding: var(--piper-space-2) var(--piper-space-4); font-weight: 620; font-size: var(--piper-text-subheadline-size); display: inline-flex; align-items: center; gap: var(--piper-space-2);
  text-decoration: none;
}
.button:hover { background: var(--surface-2); }
.button.primary { background: var(--accent-strong); border-color: transparent; color: var(--on-accent); }
.button.primary:hover { filter: brightness(1.05); }
.button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.button.danger { color: var(--danger); }
.button:disabled { opacity: .5; cursor: default; }

/* ---------- Category groups ---------- */

.groups { display: grid; gap: var(--piper-space-4); margin-top: var(--piper-space-5); }

.group-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.group-head {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: var(--piper-space-3);
  align-items: center;
  padding: var(--piper-space-4) var(--piper-space-4);
  background: color-mix(in srgb, var(--surface-2) 55%, var(--surface));
  border-bottom: 1px solid var(--line);
}
.group-head h2 { font-size: var(--piper-text-callout-size); display: flex; align-items: center; gap: var(--piper-space-2); }
.group-head .group-name { font-weight: 720; }
.group-head .pill { font-size: var(--piper-text-caption2-size); padding: var(--piper-space-1) var(--piper-space-2); border-radius: var(--piper-radius-pill); background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.group-totals { display: none; gap: var(--piper-space-4); font-size: var(--piper-text-footnote-size); color: var(--muted); }
.group-totals b { display: block; color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 650; }
.group-collapse { border: none; background: none; color: var(--muted); font-size: var(--piper-text-callout-size); padding: var(--piper-space-1) var(--piper-space-2); }

.cat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name available" "bar bar";
  gap: var(--piper-space-2) var(--piper-space-3);
  align-items: center;
  padding: var(--piper-space-3) var(--piper-space-4);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.cat-row:last-child { border-bottom: 0; }
.cat-row.is-hidden { display: none; }
.cat-main { grid-area: name; min-width: 0; display: grid; gap: var(--piper-space-0-5); }
.cat-title { display: flex; align-items: center; gap: var(--piper-space-3); min-width: 0; }
.cat-emoji { width: 34px; height: 34px; border-radius: var(--piper-radius-md); background: var(--surface-2); display: grid; place-items: center; font-size: var(--piper-text-body-size); flex: none; }
.cat-name { font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-meta { font-size: var(--piper-text-caption1-size); color: var(--muted); display: flex; gap: var(--piper-space-2); flex-wrap: wrap; }
.cat-goal { font-size: var(--piper-text-caption1-size); color: var(--muted); }
.cat-goal.warn { color: var(--sun); }
.cat-budgeted, .cat-activity { display: none; }
.cat-available { grid-area: available; text-align: right; font-weight: 700; font-size: var(--piper-text-callout-size); padding: var(--piper-space-2) var(--piper-space-3); border-radius: var(--piper-radius-md); font-variant-numeric: tabular-nums; }
.cat-available.overspent { background: var(--danger-soft); color: var(--danger); }
.cat-available.usable { background: var(--mint-soft); color: var(--usable-ink); }

.progress { grid-area: bar; height: 6px; border-radius: var(--piper-radius-pill); background: var(--surface-2); overflow: hidden; display: flex; }
.progress > span { display: block; height: 100%; background: var(--mint); }
.progress > span.spent { background: color-mix(in srgb, var(--ink) 55%, var(--surface-2)); }
.progress > span.overspent { background: var(--danger); }

/* ---------- Tables ---------- */

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--piper-text-subheadline-size); }
table.data th, table.data td { padding: var(--piper-space-3) var(--piper-space-4); text-align: left; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); white-space: nowrap; }
table.data th { font-size: var(--piper-text-caption1-size); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 680; background: color-mix(in srgb, var(--surface-2) 50%, var(--surface)); position: sticky; top: 0; }
table.data td.money, table.data th.money { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:hover td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.account-register { table-layout: fixed; }
table.account-register th, table.account-register td { white-space: normal; padding: var(--piper-space-3) var(--piper-space-2); overflow-wrap: anywhere; }
table.data tr.is-uncleared td { color: var(--muted); }
td .flag { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--sun); margin-right: var(--piper-space-2); }

/* ---------- Cards, grids ---------- */

.layout-2 { display: grid; gap: var(--piper-space-4); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--piper-space-4);
}
.card h2 { font-size: var(--piper-text-body-size); margin-bottom: var(--piper-space-1); }
.card p.lede { color: var(--muted); margin: 0 0 var(--piper-space-4); font-size: var(--piper-text-subheadline-size); }

.start-here { margin-bottom: var(--piper-space-4); display: grid; gap: var(--piper-space-3); border-color: color-mix(in srgb, var(--sun) 55%, var(--line)); }
.start-here ol { margin: 0; padding-left: 1.3em; display: grid; gap: var(--piper-space-2); font-size: var(--piper-text-subheadline-size); }

.account-card { display: grid; gap: var(--piper-space-4); }
.account-balance { font-size: var(--piper-text-title1-size); font-weight: 720; letter-spacing: -.02em; }
.account-kind { font-size: var(--piper-text-caption1-size); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.bars { display: grid; gap: var(--piper-space-3); }
.bar-row { display: grid; grid-template-columns: 92px 1fr 74px; align-items: center; gap: var(--piper-space-3); font-size: var(--piper-text-footnote-size); }
.bar-row .track { height: 10px; border-radius: var(--piper-radius-pill); background: var(--surface-2); overflow: hidden; }
.bar-row .fill { display: block; height: 100%; border-radius: var(--piper-radius-pill); background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.bar-row .fill.spend { background: linear-gradient(90deg, color-mix(in srgb, var(--ink) 70%, transparent), var(--mint)); }
.report-group summary { cursor: pointer; min-height: 44px; }
.report-group summary::marker, .report-group summary::-webkit-details-marker { display: none; content: ''; }
.report-group-arrow { display: inline-block; }
.report-group[open] .report-group-arrow { transform: rotate(90deg); }
.report-category-list { list-style: none; padding: 0 0 0 var(--piper-space-5); margin: var(--piper-space-1) 0 var(--piper-space-3); display: grid; gap: var(--piper-space-3); font-size: var(--piper-text-footnote-size); }
.report-category-list li { display: flex; justify-content: space-between; gap: var(--piper-space-4); }

/* ---------- Dialog ---------- */

dialog.sheet {
  border: 0; padding: 0; border-radius: var(--piper-radius-xl) var(--piper-radius-xl) 0 0; background: var(--surface); color: var(--ink);
  width: min(560px, 100%); max-height: 92dvh; margin: auto auto 0; box-shadow: var(--piper-shadow-3);
}
dialog.sheet::backdrop { background: rgb(0 0 0 / .45); backdrop-filter: blur(2px); }
.sheet form { display: grid; gap: var(--piper-space-4); padding: var(--piper-space-5) var(--piper-space-5) calc(var(--piper-space-5) + var(--safe-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--piper-space-3); }
.sheet-head h2 { font-size: var(--piper-text-body-size); }
.field { display: grid; gap: var(--piper-space-2); }
/* The hidden attribute must win over display rules like the one above. */
[hidden] { display: none !important; }
.field label { font-size: var(--piper-text-footnote-size); font-weight: 650; color: var(--muted); }
.field input, .field select, .field textarea, .split-line input, .split-line select {
  border: 1px solid var(--line); background: var(--page); border-radius: var(--piper-radius-md); padding: var(--piper-space-3) var(--piper-space-4); width: 100%;
  font-size: var(--piper-text-callout-size);
}
.field input:focus, .field select:focus, .field textarea:focus, .split-line input:focus, .split-line select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--piper-space-3); }
.quick-chips { display: flex; flex-wrap: wrap; gap: var(--piper-space-2); }
.quick-chips button { border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--piper-radius-pill); padding: var(--piper-space-2) var(--piper-space-3); font-size: var(--piper-text-footnote-size); }
.sheet-actions { display: flex; gap: var(--piper-space-3); justify-content: flex-end; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: var(--piper-radius-md); padding: var(--piper-space-1); gap: var(--piper-space-0-5); }
.segmented button { border: 0; background: transparent; padding: var(--piper-space-2) var(--piper-space-4); border-radius: var(--piper-radius-sm); font-weight: 600; font-size: var(--piper-text-footnote-size); color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--piper-shadow-1); }

.menu {
  position: absolute; right: 18px; top: 64px; z-index: 40; min-width: 240px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--piper-radius-md); box-shadow: var(--piper-shadow-2);
  padding: var(--piper-space-2); display: grid; gap: var(--piper-space-0-5);
}
.menu button, .menu a { border: 0; background: none; text-align: left; padding: var(--piper-space-3) var(--piper-space-3); border-radius: var(--piper-radius-sm); font-size: var(--piper-text-subheadline-size); text-decoration: none; display: block; }
.menu button:hover, .menu a:hover { background: var(--surface-2); }
.menu .menu-user { padding: var(--piper-space-3) var(--piper-space-3) var(--piper-space-2); font-size: var(--piper-text-footnote-size); color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: var(--piper-space-1); }
.menu .signout { color: var(--danger); }

/* ---------- Send feedback ---------- */
.feedback-body { display: grid; gap: var(--piper-space-4); }
.feedback-kinds { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: var(--piper-space-2); }
.feedback-kinds legend { font-size: var(--piper-text-footnote-size); color: var(--muted); font-weight: 650; padding: 0; margin-bottom: var(--piper-space-2); }
.feedback-kind { display: inline-flex; align-items: center; gap: var(--piper-space-2); min-height: 40px; padding: 6px 14px; border: 1px solid var(--line); border-radius: var(--piper-radius-pill); color: var(--ink); cursor: pointer; font-size: var(--piper-text-subheadline-size); }
.feedback-kind:has(input:checked) { border-color: var(--accent-strong); background: var(--accent-soft); }
.feedback-attach { display: flex; align-items: flex-start; gap: var(--piper-space-3); font-weight: 500; color: var(--ink); font-size: var(--piper-text-footnote-size); cursor: pointer; }
.feedback-attach input { margin-top: 3px; flex: none; }
.feedback-preview { margin: 0; padding: var(--piper-space-3); border-radius: var(--piper-radius-md); background: var(--surface-2); color: var(--muted); font-size: var(--piper-text-caption1-size); line-height: 1.5; overflow-wrap: anywhere; }
.feedback-error:not(:empty) { color: var(--danger); font-weight: 600; margin: 0; }
.feedback-actions { flex-wrap: wrap; }
.feedback-actions .feedback-roadmap { margin-right: auto; align-self: center; }
.feedback-roadmap { color: var(--accent-strong); font-weight: 650; font-size: var(--piper-text-footnote-size); }

/* ---------- Welcome ---------- */

.welcome {
  display: grid; gap: var(--piper-space-6); align-items: center;
  max-width: 1100px; margin: 4vh auto 0;
}
.welcome-copy h1 { font-size: clamp(2.1rem, 6vw, 3.4rem); letter-spacing: -.035em; line-height: 1.02; }
.welcome-copy h1 span { background: linear-gradient(100deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome-copy p { color: var(--muted); font-size: var(--piper-text-body-size); max-width: 46ch; margin: var(--piper-space-4) 0 var(--piper-space-6); }
.welcome-actions { display: flex; flex-wrap: wrap; gap: var(--piper-space-3); }
.auth-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--piper-radius-xl); box-shadow: var(--shadow);
  padding: var(--piper-space-6); display: grid; gap: var(--piper-space-4);
}
.auth-panel h2 { font-size: var(--piper-text-body-size); }
.auth-tabs { display: flex; gap: var(--piper-space-1); }
.piper-social-signin { display: flex; flex-direction: column; gap: var(--piper-space-3); }
.piper-social-stack { display: flex; flex-direction: column; gap: var(--piper-space-3); }
.piper-social-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--piper-target-min, 44px); width: 100%; padding: 10px 16px;
  border-radius: var(--piper-radius-md, 10px); font-weight: 600; font-size: 15px; line-height: 1.25;
  text-decoration: none; box-sizing: border-box; cursor: pointer; transition: opacity .15s ease;
}
.piper-social-btn:hover { opacity: 0.92; }
.piper-social-btn:focus-visible { outline: 2px solid var(--piper-focus-color, #007aff); outline-offset: 2px; }
.piper-social-btn--apple { background: var(--ink); color: var(--page); border: 1px solid var(--ink); }
.piper-social-btn--google { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.piper-social-btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; pointer-events: none; }
.piper-social-privacy { margin: 0; font-size: var(--piper-text-caption1-size, 12px); line-height: 1.4; color: var(--muted); }
.piper-social-error { margin: 0; padding: 10px 12px; border-radius: var(--piper-radius-sm, 8px); font-size: var(--piper-text-footnote-size, 13px); background: var(--piper-critical-tint, #fdecec); color: var(--piper-critical-ink, #9b1c1c); }
.piper-social-divider { display: flex; align-items: center; gap: var(--piper-space-3); color: var(--muted); font-size: var(--piper-text-caption1-size, 12px); }
.piper-social-divider::before, .piper-social-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.piper-social-link-card { display: grid; gap: var(--piper-space-3); padding: var(--piper-space-4); border-radius: var(--piper-radius-md, 10px); border: 1px solid var(--line); background: var(--surface-2, var(--surface)); }
.piper-social-row { display: flex; align-items: center; justify-content: space-between; gap: var(--piper-space-3); padding: var(--piper-space-3) 0; border-bottom: 1px solid var(--line); }
.piper-social-row:last-child { border-bottom: 0; }
.demo-note { font-size: var(--piper-text-footnote-size); color: var(--muted); }
.benefits { display: grid; gap: var(--piper-space-3); margin-top: var(--piper-space-5); }
.benefits li { list-style: none; display: flex; gap: var(--piper-space-3); font-size: var(--piper-text-subheadline-size); color: var(--muted); }
.benefits li::before { content: "✓"; color: var(--accent); font-weight: 800; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); transform: translate(-50%, 16px);
  background: var(--ink); color: var(--page); padding: var(--piper-space-3) var(--piper-space-4); border-radius: var(--piper-radius-pill); font-size: var(--piper-text-footnote-size);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.update-banner {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--piper-space-4); z-index: 60; max-width: 90vw;
  background: var(--ink); color: var(--page); padding: var(--piper-space-3) var(--piper-space-4); border-radius: var(--piper-radius-pill);
  font-size: var(--piper-text-footnote-size);
}
.update-banner[hidden] { display: none; }
.update-banner button {
  background: var(--page); color: var(--ink); border: 0; border-radius: var(--piper-radius-pill);
  padding: var(--piper-space-1) var(--piper-space-3); font-size: var(--piper-text-footnote-size); font-weight: 700; cursor: pointer;
}

.empty {
  padding: var(--piper-space-10) var(--piper-space-5); text-align: center; color: var(--muted);
  border: 1px dashed var(--line); border-radius: var(--radius);
}

/* ---------- Phone ---------- */

@media (max-width: 719px) {
  :root { --tabbar-height: 64px; }
  main { padding-bottom: calc(96px + var(--safe-bottom)); }
  .topnav { display: none; }
  .avatar-button { margin-left: 0; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; z-index: 30; bottom: 0; left: 0; right: 0;
    height: calc(var(--tabbar-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
  }
  .tabbar a {
    display: grid; place-items: center; align-content: center; gap: var(--piper-space-1); font-size: var(--piper-text-caption2-size); font-weight: 600;
    color: var(--muted); text-decoration: none;
  }
  .tabbar a span:first-child { font-size: var(--piper-text-body-size); line-height: 1; }
  .tabbar a[aria-current="page"] { color: var(--accent-strong); }
  .topbar-status .status-text { display: none; }
  .group-head { grid-template-columns: 1fr auto; }
  .group-collapse { display: none; }
  .field-row { grid-template-columns: 1fr; }
  dialog.sheet { border-radius: var(--piper-radius-xl) var(--piper-radius-xl) 0 0; }
}

/* ---------- Tablet ---------- */

@media (min-width: 720px) and (max-width: 1023px) {
  .topnav { display: flex; }
  .hero-strip { grid-template-columns: repeat(2, 1fr); }
  .metric.primary { grid-column: span 2; }
  .group-totals { display: flex; }
  .layout-2 { grid-template-columns: 1fr 1fr; }
  dialog.sheet { border-radius: var(--piper-radius-xl); margin: auto; }
}

/* ---------- Desktop ---------- */

@media (min-width: 1024px) {
  .topnav { display: flex; }
  .hero-strip { grid-template-columns: 1.4fr 1fr 1fr 1fr; }
  .group-totals { display: flex; }
  .layout-2 { grid-template-columns: 1.5fr 1fr; }
  .cat-row {
    grid-template-columns: minmax(220px, 1.5fr) 120px 140px 130px 120px;
    grid-template-areas: "name budgeted activity available bar";
    gap: var(--piper-space-4);
    padding: var(--piper-space-3) var(--piper-space-4);
  }
  .cat-main { grid-area: name; }
  .cat-budgeted, .cat-activity { display: block; text-align: right; font-size: var(--piper-text-subheadline-size); color: var(--muted); font-variant-numeric: tabular-nums; }
  .cat-budgeted { grid-area: budgeted; }
  .cat-activity { grid-area: activity; }
  .cat-available { grid-area: available; }
  .progress { grid-area: bar; }
  .welcome { grid-template-columns: 1.15fr .85fr; margin-top: 8vh; }
  .month-head { grid-template-columns: 1fr; }
}

@media (hover: none) and (pointer: coarse) {
  .cat-row { padding: var(--piper-space-4) var(--piper-space-4); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}

/* Move money and cover overspending */
.move-box { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--piper-space-3) var(--piper-space-4); }
.move-box summary { cursor: pointer; font-weight: 650; }
.cover-box { border-radius: var(--radius-sm); padding: var(--piper-space-3) var(--piper-space-4); background: var(--danger-soft); }
/* Credit overspending is card debt, not a hole in next month's plan. */
.cat-available.credit-overspent { background: var(--piper-warning-tint); color: var(--piper-warning-ink); }
/* Cleared / reconciled marker on each transaction */
.clear-cell { width: 34px; text-align: center; }
.clear-state { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: var(--piper-radius-pill); font: 700 var(--piper-text-caption1-size) var(--font); border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.clear-state.cleared { background: var(--mint-soft); color: var(--mint); border-color: transparent; }
.clear-state.reconciled { background: var(--mint); color: var(--surface); border-color: transparent; cursor: default; }
/* Undo / redo */
.history-buttons { display: flex; gap: var(--piper-space-1); }
.history-buttons .icon-button:disabled { opacity: .35; cursor: default; }
[data-view="welcome"] .history-buttons, [data-view="loading"] .history-buttons { display: none; }
@media (min-width: 720px) and (max-width: 1023px) {
  /* Room for undo / redo beside the tabs on tablets. */
  .brand-domain { display: none; }
  .topbar { gap: var(--piper-space-3); }
}
/* Transaction flags */
.txn-flag { display: inline-block; width: 10px; height: 10px; border-radius: var(--piper-radius-xs); margin-right: var(--piper-space-2); vertical-align: middle; }
.flag-red { background: #d64541; } .flag-orange { background: #ef7d1c; } .flag-yellow { background: #e7b416; }
.flag-green { background: #2e9b5f; } .flag-blue { background: #2f6fd6; } .flag-purple { background: #8a4fd0; }
/* Grid and flex children default to min-width: auto, which let wide tables push cards, views
   and the sheet wider than a phone screen instead of scrolling inside their own box. */
main > *, .view > *, .sheet-body > *, .group-card > *, .layout-2 > *, .hero-strip > * { min-width: 0; }
.table-wrap { max-width: 100%; }
.sheet input, .sheet select, .sheet textarea { min-width: 0; max-width: 100%; }
@media (max-width: 719px) {
  /* Ready to Assign leads; the other three numbers sit in one compact row under it, so the
     first categories are on screen without scrolling. */
  .hero-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--piper-space-2); }
  .hero-strip .metric.primary { grid-column: 1 / -1; }
  .hero-strip .metric:not(.primary) { padding: var(--piper-space-3) var(--piper-space-3); border-radius: var(--radius-sm); gap: var(--piper-space-0-5); }
  .hero-strip .metric:not(.primary) .metric-label { font-size: var(--piper-text-caption2-size); letter-spacing: .03em; }
  .hero-strip .metric:not(.primary) .metric-value { font-size: var(--piper-text-callout-size); letter-spacing: -.01em; }
  .hero-strip .metric:not(.primary) .metric-note { font-size: var(--piper-text-caption2-size); }
  .month-head { gap: var(--piper-space-3); }
  /* Transactions read as two lines on a phone: payee and amount, then category and account. */
  table.data tr[data-transaction] {
    display: grid; grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "payee amount clear" "category account clear";
    column-gap: var(--piper-space-2); padding: var(--piper-space-2) var(--piper-space-1);
    border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  }
  table.data tr[data-transaction] td { border: 0; padding: var(--piper-space-0-5) var(--piper-space-2); white-space: normal; align-self: center; }
  table.data tr[data-transaction] td:nth-child(1) { grid-area: payee; }
  table.data tr[data-transaction] td:nth-child(2) { grid-area: category; padding-left: var(--piper-space-4); }
  table.data tr[data-transaction] td:nth-child(3) { grid-area: account; text-align: right; }
  table.data tr[data-transaction] td:nth-child(4) { grid-area: amount; }
  table.data tr[data-transaction] td:nth-child(5) { grid-area: clear; }
  table.data tr[data-rule] {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    /* The buttons get their own row: sharing the amount's column made it as wide as all four
       buttons and squeezed the payee to a word per line (AUDIT-ROUND5 finding 6). */
    grid-template-areas: "payee amount" "date date" "actions actions"; padding: var(--piper-space-2) var(--piper-space-1);
    border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  }
  table.data tr[data-rule] td { border: 0; padding: var(--piper-space-0-5) var(--piper-space-3); white-space: normal; align-self: center; }
  table.data tr[data-rule] td:nth-child(1) { grid-area: payee; }
  table.data tr[data-rule] td:nth-child(2) { grid-area: date; }
  table.data tr[data-rule] td:nth-child(3) { grid-area: amount; text-align: right; }
  table.data tr[data-rule] td:nth-child(4) { grid-area: actions; }
  table.data tr[data-rule] .schedule-actions { justify-content: flex-start; margin-left: -6px; }
  .schedule-actions .button { padding: var(--piper-space-2) var(--piper-space-3); min-height: 44px; min-width: 44px; justify-content: center; }
  .bar-row[style] { grid-template-columns: 96px 1fr 84px !important; }
}
/* Ready to Assign: over-assigned is a problem to fix, not a quiet green number. */
.metric.primary.is-over, .ready-sticky-bar.is-over {
  --stage: var(--stage-over); --stage-ink: #FBF5EC; --stage-quiet: var(--stage-over-quiet); --stage-line: var(--stage-over-quiet);
  --stage-accent: #FBF5EC; --stage-on-accent: var(--stage-over); --stage-track: var(--stage-over-track);
}
/* Income rows show what came in; it already went to Ready to Assign, so there is no balance. */
.cat-available.income-received { background: transparent; color: var(--mint); font-weight: 650; }
.progress.income { visibility: hidden; }
/* Phone: Ready to Assign follows you down the list once its card has scrolled away. */
.ready-sticky { display: none; }
@media (max-width: 719px) {
  .ready-sticky { display: block; position: sticky; z-index: 15; height: 0; margin: 0 -2px; }
  .ready-sticky-bar {
    display: flex; justify-content: space-between; align-items: center; gap: var(--piper-space-3);
    padding: var(--piper-space-2) var(--piper-space-4); border-radius: 0 0 var(--piper-radius-md) var(--piper-radius-md); font-size: var(--piper-text-footnote-size); font-weight: 650;
    background: var(--stage); color: var(--stage-ink); box-shadow: var(--piper-shadow-2);
    transform: translateY(-110%); opacity: 0; transition: transform .18s, opacity .18s; pointer-events: none;
  }
  .ready-sticky-bar b { font-size: var(--piper-text-callout-size); }
  /* The label is drawn, not text: the bar repeats the card above for sighted users only. */
  .ready-sticky-bar [data-label]::before { content: attr(data-label); }
  .ready-sticky.is-shown .ready-sticky-bar { transform: none; opacity: 1; }
}
/* Split transactions */
.split-box { border: 1px solid var(--line); border-radius: var(--radius-sm, var(--piper-radius-md)); padding: var(--piper-space-3) var(--piper-space-3); margin: 0; display: grid; gap: var(--piper-space-3); }
.split-line input, .split-line select { padding: var(--piper-space-2) var(--piper-space-3); font-size: var(--piper-text-subheadline-size); color: inherit; }
.split-line input[type="checkbox"] { width: auto; }
.split-line { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, .8fr) minmax(0, 1fr) auto; gap: var(--piper-space-2); align-items: center; }
.split-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--piper-space-3); margin-top: var(--piper-space-2); }
.split-foot .negative { color: var(--danger); }
@media (max-width: 719px) {
  .split-line { grid-template-columns: minmax(0, 1fr) 96px auto; }
  .split-line [data-line-memo] { grid-column: 1 / 3; }
}
/* Import review */
.import-review tr.is-duplicate td { color: var(--muted); }
.import-review select { max-width: 180px; border: 1px solid var(--line); background: var(--page); border-radius: var(--piper-radius-md); padding: var(--piper-space-2) var(--piper-space-2); color: inherit; }
/* Each import row reads as two lines in the sheet: payee and amount, then date and category. */
.import-review thead { display: none; }
.import-review tr[data-import-row] {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; column-gap: var(--piper-space-3);
  grid-template-areas: "keep payee amount" "keep date category"; padding: var(--piper-space-2) var(--piper-space-2);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.import-review tr[data-import-row] td { border: 0; padding: var(--piper-space-0-5) var(--piper-space-1); white-space: normal; }
.import-review td:nth-child(1) { grid-area: keep; }
.import-review td:nth-child(2) { grid-area: date; color: var(--muted); }
.import-review td:nth-child(3) { grid-area: payee; font-weight: 600; }
.import-review td:nth-child(4) { grid-area: category; justify-self: end; }
.import-review td:nth-child(5) { grid-area: amount; text-align: right; }
.import-review select { max-width: 170px; }
/* Transactions: the month switcher stays on one line, and on a phone takes its own full row. */
.month-switch { display: inline-flex; align-items: center; gap: var(--piper-space-2); white-space: nowrap; }
.month-switch-title { font-weight: 650; }
@media (max-width: 719px) {
  .month-switch { display: flex; width: 100%; justify-content: space-between; }
}

/* Assign presets: a quiet select and Apply at the end of the plan's action bar. */
.preset-picker { display: inline-flex; gap: var(--piper-space-2); align-items: center; margin-left: auto; }
.preset-picker select {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--piper-radius-pill);
  padding: var(--piper-space-2) var(--piper-space-4); color: inherit; font: inherit; font-size: var(--piper-text-subheadline-size); max-width: 100%;
}
@media (max-width: 560px) { .preset-picker { margin-left: 0; width: 100%; } .preset-picker select { flex: 1; } }

/* Income vs expense fits a phone: short month names and tighter cells keep Net in view. */
.narrow-only { display: none; }
@media (max-width: 560px) {
  .wide-only { display: none; }
  .narrow-only { display: inline; }
  [data-report="income-expense"] table.data th, [data-report="income-expense"] table.data td { padding: var(--piper-space-3) var(--piper-space-2); font-size: var(--piper-text-footnote-size); }
  [data-report="income-expense"] table.data th { letter-spacing: .04em; }
}

/* Scheduled rows: Enter, Skip, edit and delete wrap rather than widen the table on a tablet. */
.schedule-actions { display: flex; flex-wrap: wrap; gap: var(--piper-space-1); justify-content: flex-end; }

/* Coming up: scheduled and future-dated entries with projected balances. */
.forecast-head { display: flex; flex-wrap: wrap; gap: var(--piper-space-3) var(--piper-space-4); align-items: center; justify-content: space-between; padding: var(--piper-space-4) var(--piper-space-4) var(--piper-space-3); }
.forecast-head h2 { font-size: var(--piper-text-callout-size); }
.forecast-head p { margin: var(--piper-space-0-5) 0 0; }
.forecast-accounts { list-style: none; margin: 0; padding: 0 var(--piper-space-4) var(--piper-space-3); display: grid; gap: var(--piper-space-2); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.forecast-accounts li { display: grid; gap: var(--piper-space-0-5); align-content: start; padding: var(--piper-space-3) var(--piper-space-3); border-radius: var(--radius-sm); background: var(--surface-2); }
.forecast-span { font-variant-numeric: tabular-nums; }
.forecast-low { font-size: var(--piper-text-footnote-size); color: var(--muted); }
.forecast-low.is-below { color: var(--danger); font-weight: 650; }
.forecast-days ul { list-style: none; margin: 0; padding: 0; }
.forecast-day { margin: 0; padding: var(--piper-space-2) var(--piper-space-4); font-size: var(--piper-text-caption1-size); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 680; background: color-mix(in srgb, var(--surface-2) 50%, var(--surface)); }
.forecast-day.is-due { color: var(--sun); }
.forecast-item { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(6.5rem, auto); gap: var(--piper-space-3); align-items: center; padding: var(--piper-space-3) var(--piper-space-4); border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.forecast-what { display: grid; min-width: 0; }
.forecast-what strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.forecast-item .money { text-align: right; font-variant-numeric: tabular-nums; }
.forecast-balance { font-size: var(--piper-text-footnote-size); }
@media (max-width: 600px) {
  .forecast-item { grid-template-columns: minmax(0, 1fr) auto; gap: var(--piper-space-0-5) var(--piper-space-3); }
  .forecast-what { grid-row: span 2; }
  .forecast-what strong { white-space: normal; }
  .forecast-balance { grid-column: 2; }
}

/* Payee rules list. */
.rule-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--piper-space-2); }
.rule-list li { display: flex; gap: var(--piper-space-3); align-items: center; justify-content: space-between; padding: var(--piper-space-3) var(--piper-space-3); border-radius: var(--radius-sm); background: var(--surface-2); }
.rule-list li > span { display: grid; min-width: 0; overflow-wrap: anywhere; }

/* Rows sit inside clipped cards: draw their focus ring inside the row so no edge is cut off. */
.cat-row:focus-visible, .forecast-item:focus-visible, table.data tr:focus-visible { outline-offset: -2px; }

/* Keyboard shortcuts sheet. */
.shortcut-list { margin: 0; display: grid; gap: var(--piper-space-2); }
.shortcut-list > div { display: flex; justify-content: space-between; gap: var(--piper-space-4); align-items: baseline; padding: var(--piper-space-2) 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.shortcut-list dt, .shortcut-list dd { margin: 0; }
kbd { font: inherit; font-size: var(--piper-text-footnote-size); font-weight: 650; padding: var(--piper-space-0-5) var(--piper-space-2); border-radius: var(--piper-radius-xs); border: 1px solid var(--line); background: var(--surface-2); }

/* The last dollar gets a job: the amount settles once. Stilled by reduced motion (see the global rule). */
.settled-mark { font-weight: 800; }
@keyframes settle { 0% { transform: scale(1.08); opacity: .6; } 100% { transform: scale(1); opacity: 1; } }
.metric.primary.just-settled .metric-value { animation: settle .5s ease-out 1; transform-origin: left center; }
/* Looks regular: recurring charges found in history. */
.found-list { list-style: none; margin: 0; padding: 0; }
.found-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: var(--piper-space-2) var(--piper-space-4); align-items: center; padding: var(--piper-space-3) var(--piper-space-4); border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.found-money { display: grid; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) {
  .found-list li { grid-template-columns: minmax(0, 1fr) auto; }
  .found-list .schedule-actions { grid-column: 1 / -1; justify-content: flex-start; }
}
.found-more { padding: var(--piper-space-2) var(--piper-space-3) var(--piper-space-3); border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }

/* Transactions filters. */
.filter-row { display: flex; flex-wrap: wrap; gap: var(--piper-space-2) var(--piper-space-3); align-items: center; margin-top: var(--piper-space-3); }
.filter-row select, .filter-row input[type="date"] { padding: var(--piper-space-2) var(--piper-space-3); border-radius: var(--piper-radius-md); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--piper-text-subheadline-size); max-width: 100%; }
.filter-check, .filter-date { display: inline-flex; gap: var(--piper-space-2); align-items: center; }
.month-divider { margin: var(--piper-space-4) var(--piper-space-1) var(--piper-space-3); font-size: var(--piper-text-body-size); display: flex; gap: var(--piper-space-3); align-items: baseline; flex-wrap: wrap; }
.filter-check { white-space: nowrap; }
@media (max-width: 600px) {
  .filter-row { display: grid; grid-template-columns: 1fr 1fr; }
  .filter-row .segmented { grid-column: 1 / -1; justify-self: start; }
  .filter-select select { width: 100%; }
  .filter-date { display: grid; gap: var(--piper-space-1); }
  .filter-date input { width: 100%; }
  .filter-row [data-action="clear-filters"] { grid-column: 1 / -1; justify-self: start; }
}
.filter-check input { width: auto; flex: none; margin: 0; }
.filter-check { justify-content: flex-start; }

/* Transactions tabs: the list, or scheduled and upcoming. */
.tx-tabs { margin: var(--piper-space-1) 0 var(--piper-space-4); }
.tab-badge { margin-left: var(--piper-space-2); padding: 1px var(--piper-space-2); border-radius: var(--piper-radius-pill); background: var(--accent-strong); color: var(--on-accent); font-size: var(--piper-text-caption1-size); font-weight: 700; }

/* Changing several transactions at once. */
.row-select { width: 20px; height: 20px; margin: 0 var(--piper-space-2) 0 var(--piper-space-0-5); vertical-align: middle; accent-color: var(--accent-strong); }
.bulk-bar { position: sticky; bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 10px); z-index: 12; display: flex; flex-wrap: wrap; gap: var(--piper-space-2) var(--piper-space-3); align-items: center; margin-top: var(--piper-space-3); padding: var(--piper-space-3) var(--piper-space-4); border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.bulk-bar select { padding: var(--piper-space-2) var(--piper-space-3); border-radius: var(--piper-radius-md); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--piper-text-subheadline-size); max-width: 100%; }
.bulk-bar :disabled { opacity: .5; }
@media (max-width: 600px) {
  .bulk-bar { gap: var(--piper-space-2) var(--piper-space-2); padding: var(--piper-space-2) var(--piper-space-3); }
  .bulk-bar .button { padding: var(--piper-space-2) var(--piper-space-3); font-size: var(--piper-text-footnote-size); }
  .bulk-bar select { padding: var(--piper-space-2) var(--piper-space-2); font-size: var(--piper-text-footnote-size); }
}

/* Report rows that open their transactions. */
.report-link { all: unset; box-sizing: border-box; cursor: pointer; width: 100%; border-radius: var(--piper-radius-sm); }
.report-category-list .report-link { display: flex; justify-content: space-between; gap: var(--piper-space-3); padding: var(--piper-space-1) var(--piper-space-2); }
.bar-row.report-link { display: grid; align-items: center; gap: var(--piper-space-3); padding: var(--piper-space-1) var(--piper-space-2); font-size: var(--piper-text-footnote-size); min-height: 36px; }
.report-link:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.report-link:focus-visible { outline: var(--piper-focus-width) solid var(--accent-strong); outline-offset: var(--piper-focus-offset); }
.report-payee-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.report-link .money { text-align: right; font-variant-numeric: tabular-nums; }

/* Hide amounts: every element holding a dollar figure is tagged (markAmounts) and blurred until
   shown again. Form fields stay readable so you can still type. */
.amounts-hidden main .has-amount, .amounts-hidden main .money, .amounts-hidden main .metric-value { filter: blur(7px); user-select: none; }
/* A reminder that floats at the bottom corner, clear of the tab bar on phones. */
.amounts-chip { position: fixed; right: 12px; bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 12px); z-index: 30; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--piper-radius-pill); padding: var(--piper-space-2) var(--piper-space-4); font: inherit; font-size: var(--piper-text-footnote-size); font-weight: 650; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow); }
.amounts-chip[hidden] { display: none; }

/* Report months chosen by hand: two fields that share the row at any width. */
.report-range { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.report-range .filter-date { display: grid; gap: var(--piper-space-1); min-width: 0; }
.report-range input { width: 100%; min-width: 0; box-sizing: border-box; }

/* First-run steps: a tick and quieter text once a step is done; the step you are on stands out. */
.start-here li.is-done { color: var(--muted); }
.start-here li.is-done b { font-weight: 600; }
.start-here .step-tick { color: var(--mint); font-weight: 800; margin-right: var(--piper-space-2); }
.start-here li.is-current { color: var(--ink); }

/* The pile still to file: spending with no category yet. */
.needs-chip { display: inline-flex; gap: var(--piper-space-2); align-items: baseline; margin: 0 0 var(--piper-space-3); padding: var(--piper-space-2) var(--piper-space-4); border-radius: var(--piper-radius-pill); border: 1px solid color-mix(in srgb, var(--sun) 55%, var(--line)); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--piper-text-subheadline-size); cursor: pointer; }
.needs-chip[aria-pressed="true"] { background: var(--surface-2); }

/* A loan's interest for the month, offered to confirm. */
.interest-due { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--piper-space-2) var(--piper-space-3); }
.interest-due .button { min-height: 36px; padding: var(--piper-space-2) var(--piper-space-3); }

/* Import: choosing a CSV's columns by hand. */
.import-columns { border: 1px solid var(--line); border-radius: var(--piper-radius-md); padding: var(--piper-space-3) var(--piper-space-4); }
.import-columns summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.import-columns-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--piper-space-3); margin-bottom: var(--piper-space-3); }
.import-columns-grid .field { min-width: 0; margin: 0; }
.import-columns-grid select { width: 100%; min-width: 0; }

/* API keys sheet. */
.key-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--piper-space-3); }
.key-row { display: flex; flex-wrap: wrap; gap: var(--piper-space-2) var(--piper-space-3); align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: var(--piper-radius-md); padding: var(--piper-space-3) var(--piper-space-4); }
.key-row.is-expired { opacity: 0.75; }
.key-main { min-width: 0; flex: 1 1 220px; }
.key-main p { margin: var(--piper-space-1) 0 0; overflow-wrap: anywhere; }
.key-actions { display: flex; gap: var(--piper-space-2); }
.key-chip { display: inline-block; font-size: var(--piper-text-caption1-size); font-weight: 600; padding: var(--piper-space-0-5) var(--piper-space-2); border-radius: var(--piper-radius-pill); border: 1px solid var(--line); }
.key-chip.warn { border-color: var(--danger); color: var(--danger); }
.key-made, .key-form { display: grid; gap: var(--piper-space-3); border: 1px solid var(--line); border-radius: var(--piper-radius-md); padding: var(--piper-space-3) var(--piper-space-4); }
.key-made h3, .key-form h3 { margin: 0; font-size: var(--piper-text-callout-size); }
.key-token { width: 100%; min-width: 0; font-family: var(--mono); font-size: var(--piper-text-footnote-size); }
.key-access { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: var(--piper-space-2) var(--piper-space-4); }
.key-access legend { font-weight: 600; font-size: var(--piper-text-subheadline-size); padding: 0; margin-bottom: var(--piper-space-1); }
.key-help summary { cursor: pointer; font-weight: 600; min-height: 32px; }
/* Bank feed sheet: the same cards as API keys. */
.feed-steps { margin: 0; padding-left: 1.3em; display: grid; gap: 4px; }
.feed-account { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 220px); gap: 8px 14px; align-items: center; border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; }
.feed-account select { width: 100%; }
@media (max-width: 600px) { .feed-account { grid-template-columns: 1fr; } }
.key-help pre { overflow-x: auto; padding: var(--piper-space-3) var(--piper-space-3); border: 1px solid var(--line); border-radius: var(--piper-radius-md); font-size: var(--piper-text-footnote-size); margin: var(--piper-space-2) 0; }

/* Theme picker (docs/THEMES.md) */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--piper-space-3); }
.theme-option { display: grid; gap: var(--piper-space-2); padding: var(--piper-space-3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.theme-option:has(input:checked) { border-color: var(--accent-strong); box-shadow: 0 0 0 2px var(--accent-strong) inset; }
.theme-option:has(input:focus-visible) { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.theme-option input { position: absolute; opacity: 0; pointer-events: none; }
.theme-swatch { display: flex; height: 28px; border-radius: var(--piper-radius-sm); overflow: hidden; border: 1px solid var(--line); }
.theme-swatch span { flex: 1; }
.theme-name { font-weight: 600; }

/* Touch: every control is at least 44 px (WCAG 2.2, the design system's target size). Small marks
   keep their size and get a larger hit area instead. */
@media (pointer: coarse) {
  .button, .topnav a, .menu button, .menu a, .segmented button, .quick-chips button, .needs-chip, .amounts-chip,
  .preset-picker select, .filter-row select, .filter-row input[type="date"], .bulk-bar select, .bulk-bar .button,
  .interest-due .button, .import-review select, .import-columns summary, .key-help summary, .move-box summary,
  .field input:not([type="checkbox"], [type="radio"]), .field select, .split-line input:not([type="checkbox"]), .split-line select, .report-link, .bar-row.report-link, .theme-option {
    min-height: var(--piper-target-min);
  }
  .icon-button, .avatar-button, .group-collapse { min-width: var(--piper-target-min); min-height: var(--piper-target-min); }
  .topnav a, .month-today { display: inline-flex; align-items: center; }
  .month-today { min-height: var(--piper-target-min); }
  .clear-state { position: relative; }
  .clear-state::after { content: ""; position: absolute; inset: -10px; }
}
/* Phones: the 44 px header controls leave no room for the long name, so the mark and "ForMyLife" stay. */
@media (pointer: coarse) and (max-width: 430px) {
  .brand-domain { display: none; }
}
/* A grid item that holds a table: let the table scroll inside its own wrap, not widen the sheet. */
.sheet-block { min-width: 0; }
/* In a category's own sheet every row's category column repeats the sheet's title; hiding it keeps
   the last column (the cleared button) inside the wrap at desktop and tablet widths. */
.sheet-block td:nth-child(2) { display: none; }
