/* Shared components. Each component reads per-theme tokens built from the existing palette,
   so Light, Dark and Grey Glass keep their own character while every instance looks the same. */

/* Segmented control: Home views, Stats lenses and series, Settings sections, entry type. */
:root {
  --seg-bg:var(--subtle); --seg-border:var(--border); --seg-text:var(--muted); --seg-hover:var(--text);
  --seg-active-bg:var(--decorative); --seg-active-text:var(--text); --seg-active-shadow:none;
  --seg-semantic-bg:var(--surface);
}
:root[data-theme=dark] {
  --seg-bg:var(--surface); --seg-active-bg:var(--brand-soft); --seg-active-text:var(--brand);
  --seg-semantic-bg:var(--subtle);
}
:root[data-theme=grey-glass] {
  --seg-bg:var(--surface); --seg-border:var(--glass-edge); --seg-active-bg:var(--brand-soft); --seg-active-text:var(--brand);
  --seg-active-shadow:inset 0 1px 0 var(--experience-edge); --seg-semantic-bg:var(--subtle);
}

/* One component, 44px tall, pill track and pill selection. Two sizes: page level fills its row; in-card (.report-scope) hugs its labels.
   The edge is an inset ring so the 44px buttons fill the height exactly. */
.segmented { padding:4px; background:var(--seg-bg); border:1px solid var(--seg-border); border-radius:var(--radius-pill); }
.segmented:not(.settings-jump) { box-sizing:border-box; min-height:44px; padding:0 4px; border:0; box-shadow:inset 0 0 0 1px var(--seg-border); align-items:stretch; }
.segmented > button,.segmented > [role=tab] {
  min-height:44px; padding:0 12px; border:0; border-radius:var(--radius-pill); background:transparent; box-shadow:none;
  color:var(--seg-text); font-size:var(--text-md); font-weight:500;
  transition:background-color var(--motion-enter) var(--motion-ease),color var(--motion-enter) var(--motion-ease);
}
@media (hover:hover) and (pointer:fine){.segmented > :is(button,[role=tab]):hover{ color:var(--seg-hover); }}
.segmented > :is([aria-selected=true],[aria-pressed=true],[aria-current]) {
  background:var(--seg-active-bg); color:var(--seg-active-text); font-weight:600; box-shadow:var(--seg-active-shadow);
}
/* Entry type: the selected option reads like every other selected segment (no orange text on the orange pill). */
.segmented-semantic > [aria-pressed=true] { background:var(--seg-semantic-bg); color:var(--seg-active-text); }
@media (prefers-reduced-motion:reduce) { .segmented > button,.segmented > [role=tab] { transition:none; } }

/* Motion patterns. Durations and curves come only from the motion tokens; everything settles instantly
   under reduced motion. Primary amounts and headings never move; feedback is short and physical. */

/* Press: anything tappable gives under the finger. */
:is(.quick-category,.home-goal,.account-card,.merchant-chip,.chip,.mobile-category-chips button,.segmented > button,.segmented > [role=tab],.category-row) { transition-property:background-color,border-color,color,box-shadow,transform; transition-duration:var(--motion-enter); transition-timing-function:var(--motion-ease); }
:is(.quick-category,.home-goal,.merchant-chip,.chip,.mobile-category-chips button,.segmented > button,.segmented > [role=tab]):active { transform:scale(.97); transition-duration:var(--motion-press); }
:is(.account-card,.category-row):active { transform:scale(.99); transition-duration:var(--motion-press); }

/* Hover lift for cards you can open (mouse and trackpad only). */
@media (hover:hover) and (pointer:fine) {
  /* The lift shadow lives on ::after and only fades, so hovering never repaints a growing box-shadow. */
  #app .account-card { position:relative; }
  #app .account-card::after { content:''; position:absolute; inset:0; border-radius:inherit; box-shadow:var(--elevation-2); opacity:0; pointer-events:none; transition:opacity var(--motion-enter) var(--motion-ease); }
  #app .account-card:hover { transform:translateY(-2px); }
  #app .account-card:hover::after { opacity:1; }
}

/* Selection pop: a chosen tile or goal acknowledges the tap. */
@keyframes select-pop {  60% { transform:scale(1.06); } }
.quick-category[aria-pressed=true] span { animation:select-pop var(--motion-move) var(--motion-ease); }

/* Disclosures open and close by height where the browser supports it (others snap, as before).
   Menus and pickers are excluded so their popovers are never clipped. */
:is(.week,.more-details,.entry-details,.stats-summary-details,.stats-more-insights,.stats-longer-history,.stats-disclosure-section,.stats-explanation,.archived-accounts,.merchant-more,.backup-text,.calendar-weekly-totals,.calendar-breakdown,.chart-data,.settings-data-help,.receipt-more,.payoff-schedule,.story-chart-option,.sms-source-disclosure,.sms-bulk-disclosure,.private-report,.private-recorded-history,.private-plan-disclosure,.private-older-payments,.private-help,.private-exact-payments) {
  interpolate-size:allow-keywords;
}
:is(.week,.more-details,.entry-details,.stats-summary-details,.stats-more-insights,.stats-longer-history,.stats-disclosure-section,.stats-explanation,.archived-accounts,.merchant-more,.backup-text,.calendar-weekly-totals,.calendar-breakdown,.chart-data,.settings-data-help,.receipt-more,.payoff-schedule,.story-chart-option,.sms-source-disclosure,.sms-bulk-disclosure,.private-report,.private-recorded-history,.private-plan-disclosure,.private-older-payments,.private-help,.private-exact-payments)::details-content {
  block-size:0; overflow-y:clip;
  transition:block-size var(--motion-move) var(--motion-ease),content-visibility var(--motion-move) allow-discrete;
}
:is(.week,.more-details,.entry-details,.stats-summary-details,.stats-more-insights,.stats-longer-history,.stats-disclosure-section,.stats-explanation,.archived-accounts,.merchant-more,.backup-text,.calendar-weekly-totals,.calendar-breakdown,.chart-data,.settings-data-help,.receipt-more,.payoff-schedule,.story-chart-option,.sms-source-disclosure,.sms-bulk-disclosure,.private-report,.private-recorded-history,.private-plan-disclosure,.private-older-payments,.private-help,.private-exact-payments)[open]::details-content {
  block-size:auto;
}

@media (prefers-reduced-motion:reduce) {
  :is(.quick-category,.home-goal,.account-card,.merchant-chip,.chip,.mobile-category-chips button,.category-row) { transition:none; }
  :is(.quick-category,.home-goal,.account-card,.merchant-chip,.chip,.mobile-category-chips button,.segmented > button,.category-row):active{ transform:none; }@media (hover:hover) and (pointer:fine){#app .account-card:hover{ transform:none; }}
  .quick-category[aria-pressed=true] span { animation:none; }
  ::details-content { transition:none!important; }
}

/* Skeletons: placeholder shapes while the first cloud download runs. Built from theme tokens;
   the shimmer stops under reduced motion. */
@keyframes skeleton-shimmer { from { background-position:100% 0; } to { background-position:-100% 0; } }
.skeleton { display:block; border-radius:var(--radius-xs); background:linear-gradient(90deg,var(--subtle) 25%,color-mix(in srgb,var(--subtle),var(--text) 7%) 50%,var(--subtle) 75%); background-size:200% 100%; animation:skeleton-shimmer 1.4s var(--ease-move) infinite; }
.skeleton-line { height:12px; width:70%; }
.skeleton-line.short { width:38%; }
.skeleton-hero { height:44px; width:55%; border-radius:var(--radius-sm); }
.skeleton-figure { height:28px; width:65%; margin-top:10px; }
.skeleton-bar { height:8px; width:100%; border-radius:var(--radius-pill); }
.skeleton-chart { height:180px; width:100%; border-radius:var(--radius-md); }
.skeleton-stack { display:grid; gap:14px; margin-bottom:16px; }
.skeleton-list { display:grid; }
.skeleton-row { display:grid; grid-template-columns:36px minmax(0,1fr) 72px; align-items:center; gap:12px; padding:14px 20px; border-top:1px solid var(--divider); }
.skeleton-row:first-child { border-top:0; }
.skeleton-icon { width:36px; height:36px; border-radius:var(--radius-sm); }
.skeleton-lines { display:grid; gap:8px; }
.skeleton-amount { height:14px; }
.skeleton-note { margin:0; padding:14px 20px 20px; color:var(--muted); font-size:var(--text-sm); }
.home-hero-budget .skeleton + .skeleton { margin-top:4px; }
@media (prefers-reduced-motion:reduce) { .skeleton { animation:none; } }

/* Empty states: a context symbol in a soft halo of the theme's accent tint, revealed once. */
@keyframes empty-arrive { from { opacity:0; transform:scale(.95); } }
@keyframes empty-halo { from { box-shadow:0 0 0 0 transparent,0 0 0 0 transparent; } }
.empty-symbol { display:grid; place-items:center; width:56px; height:56px; margin:4px auto 18px; border-radius:var(--radius-pill); background:var(--brand-soft); color:var(--seg-active-text); box-shadow:0 0 0 8px color-mix(in srgb,var(--brand-soft) 55%,transparent),0 0 0 18px color-mix(in srgb,var(--brand-soft) 22%,transparent); animation:empty-arrive 250ms var(--motion-ease) both,empty-halo 250ms var(--motion-ease) 60ms both; }
@media (prefers-reduced-motion:reduce) { .empty-symbol { animation:empty-halo 250ms linear both; } @keyframes empty-halo { from { opacity:0; } } }
.empty-symbol .icon { width:24px; height:24px; }
.empty[data-symbol=search] .empty-symbol { animation:none; background:var(--subtle); color:var(--muted); box-shadow:0 0 0 8px color-mix(in srgb,var(--subtle) 55%,transparent),0 0 0 18px color-mix(in srgb,var(--subtle) 22%,transparent); }
.stats-empty .empty-symbol { margin:0 0 20px; }
@media (prefers-reduced-motion:reduce) { .empty-symbol { animation:none; } }

/* Phone gestures: swipe tray behind a transaction row, and the pull-to-refresh indicator. */
@media (max-width:639px) {
  html { overscroll-behavior-y:contain; }
  .transaction-list { position:relative; }
  .transaction[data-id] { touch-action:pan-y; }
  .transaction[data-swiping] { position:relative; z-index:1; background:var(--experience-surface); }
}
.row-actions { position:absolute; right:0; z-index:0; display:flex; width:152px; }
.row-actions button { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:4px; border:0; background:var(--subtle); color:var(--text); font-size:var(--text-xs); font-weight:600; }
.row-actions button .icon { width:16px; height:16px; }
.row-actions .danger { background:var(--expense-soft); color:var(--expense); }
.pull-indicator { position:fixed; top:8px; left:50%; z-index:50; display:grid; place-items:center; width:40px; height:40px; border-radius:var(--radius-pill); background:var(--surface); color:var(--muted); border:1px solid var(--border); box-shadow:var(--elevation-2); opacity:0; transform:translate(-50%,-48px); pointer-events:none; }
.pull-indicator .icon { width:20px; height:20px; }
.pull-indicator[data-ready] { color:var(--seg-active-text); border-color:var(--seg-active-text); }
@media (min-width:640px) { .pull-indicator { display:none; } }
/* Report primitives reuse the existing theme and type scales. */
.report-amount { white-space:nowrap; }
.report-tag { display:inline-block; margin-inline:8px; padding:2px 6px; border:1px solid var(--border); border-radius:var(--radius-pill); font-size:var(--text-2xs); color:var(--text); background:var(--subtle); }
.report-line { fill:none; stroke-width:2; vector-effect:non-scaling-stroke; }
.report-line.actual { stroke:var(--expense); stroke-width:3; }
.report-line.previous { stroke:var(--muted); stroke-dasharray:3 5; }
.report-line.usual { stroke:var(--chart-2); }
.report-line.forecast { stroke:var(--expense); stroke-dasharray:6 5; }
.report-line.budget { stroke:var(--chart-4); stroke-dasharray:12 5; }
.report-fixed-marker { fill:var(--chart-3); stroke:var(--surface); stroke-width:1; }
.report-spark { width:90px; height:26px; }
.report-spark polyline { fill:none; stroke-width:2; }
.report-breadcrumb { display:flex; align-items:center; flex-wrap:wrap; gap:4px; margin-block:12px; }
.report-breadcrumb button,.report-category-menu summary,.report-insight summary,.report-insight .text-button { min-height:44px; }
.report-category-list { list-style:none; padding:0; margin:0; min-width:0; }
.report-category-list>li { border-bottom:1px solid var(--divider); }
.report-category-row { display:flex; align-items:center; justify-content:space-between; gap:12px; width:100%; min-height:76px; padding:12px 0; border:0; color:var(--text); background:transparent; text-align:start; font-size:var(--text-sm); }
.report-category-row>span { min-width:0; }
.report-category-row>span:last-child { text-align:end; }
.report-category-row small { display:block; color:var(--muted); font-size:var(--text-2xs); margin-block:4px; }
.report-category-row strong { font-weight:600; overflow-wrap:anywhere; }
.report-category-menu { font-size:var(--text-2xs); color:var(--muted); padding-block-end:8px; }
.report-category-menu p { display:flex; flex-wrap:wrap; gap:4px; }
.report-category-menu .button { margin:4px; }
.report-insight { border-block-start:1px solid var(--divider); padding-block:16px; }
.report-insight h3 { font-size:var(--text-md); font-weight:600; }
.report-insight p { font-size:var(--text-sm); line-height:1.6; }
.report-insight summary { display:flex; align-items:center; color:var(--muted); cursor:pointer; }
.report-breakdown button:focus-visible,.report-insights button:focus-visible,.report-trend-switch button:focus-visible { outline:2px solid var(--brand); outline-offset:3px; }
/* Compact category labels remain readable inside the shared donut. */
.report-breakdown .story-donut-label strong { font-size:var(--text-md); white-space:nowrap; overflow-wrap:normal; }
.report-category-row small.report-tag { display:inline-flex; width:auto; margin-inline:0; padding:2px 6px; }
.report-category-row .report-spark { display:block; margin-inline-start:auto; }
/* Deeper analysis shares the app's existing theme tokens. */
.report-matrix { min-width:680px; width:100%; border-collapse:collapse; font-size:var(--text-sm); }
.report-matrix :is(th,td),.report-fixed-list :is(th,td) { padding:10px; border-bottom:1px solid var(--divider); vertical-align:top; text-align:start; }
.report-matrix thead th { font-weight:600; color:var(--text); }
.report-matrix tbody th { min-width:170px; background:var(--surface); color:var(--text); }
.report-matrix [data-depth="1"]>th { padding-inline-start:24px; }
.report-matrix [data-depth="2"]>th { padding-inline-start:38px; }
.report-matrix [data-depth="3"]>th { padding-inline-start:52px; }
.report-matrix-value,.report-matrix-toggle { min-height:44px; color:var(--text); font-size:var(--text-sm); font-weight:500; }
.report-matrix-value { display:block; width:100%; text-align:end; padding:6px; }
.report-matrix-value:disabled { opacity:1; cursor:default; }
.report-matrix [data-heat="1"] { background:color-mix(in srgb,var(--chart-2) 6%,var(--surface)); }
.report-matrix [data-heat="2"] { background:color-mix(in srgb,var(--chart-3) 10%,var(--surface)); }
.report-matrix [data-heat="3"] { background:color-mix(in srgb,var(--chart-4) 14%,var(--surface)); }
.report-matrix [data-heat="4"] { background:color-mix(in srgb,var(--chart-5) 18%,var(--surface)); }
.report-matrix caption,.report-fixed-list caption { text-align:start; color:var(--muted); font-size:var(--text-xs); padding-block:12px; }
.report-matrix-scroll:focus-visible,.report-matrix button:focus-visible { outline:2px solid var(--brand); outline-offset:2px; }
.report-fixed-list table { min-width:720px; width:100%; font-size:var(--text-sm); }
.report-fixed-list small,.report-limit-list small { display:block; color:var(--muted); font-size:var(--text-xs); line-height:1.6; }
.report-fixed-list .text-button { min-height:44px; }
.report-limit-list { margin:12px 0; padding:0; list-style:none; }
.report-limit-list li { border-bottom:1px solid var(--divider); padding-block:16px; }
.report-limit-list progress { width:100%; height:8px; accent-color:var(--income); margin-block:8px; }
.report-limit-list li>button { margin-inline-end:8px; min-height:44px; }
.report-category-budgets label { margin-block:16px 8px; font-size:var(--text-sm); }
.month-review section { margin-block:16px; }
.month-review h3 { margin-block:8px; font-size:var(--text-lg); }
.month-review ul { padding:0; margin:0; list-style:none; }
.review-record { width:100%; display:grid; grid-template-columns:minmax(0,1fr) auto; gap:12px; align-items:center; min-height:64px; padding:12px 0; border:0; border-bottom:1px solid var(--divider); background:transparent; color:var(--text); text-align:start; }
.review-record>span { min-width:0; }
.review-record strong { overflow-wrap:anywhere; font-weight:500; font-size:var(--text-md); }
.review-record small { display:block; margin-top:4px; color:var(--muted); }
.review-record>strong { text-align:end; font-variant-numeric:tabular-nums; }
.month-review-recap { border-bottom:1px solid var(--divider); padding-block-end:16px; }

/* Labels read in sentence case everywhere; uppercase is kept only for table column headers. */
:is(.calendar-studio .calendar-weekdays span,.calendar-month-bar > span,.calendar-month-total > span,.calendar-studio .calendar-breakdown summary,.stats-donut-center span,.amount-field,.mobile-budget-values span,.mobile-pace .split:first-child > span) { text-transform:none; letter-spacing:0; }

/* Switch: on/off settings read as a real iOS-style switch (52×32 track inside a 44px tap target). */
.button.setting-switch { position:relative; flex:none; width:60px; min-width:60px; min-height:44px; padding:0; border:0; background:none; box-shadow:none; font-size:0; color:var(--text); }
.button.setting-switch .icon { display:none; }
.button.setting-switch::before { content:''; position:absolute; left:4px; top:calc(50% - 16px); width:52px; height:32px; border-radius:var(--radius-pill); background:color-mix(in srgb,var(--text) 16%,transparent); box-shadow:none; transition:background-color var(--motion-enter) var(--motion-ease); }
.button.setting-switch::after { content:''; position:absolute; left:6px; top:calc(50% - 14px); width:28px; height:28px; border-radius:var(--radius-pill); background:var(--surface); box-shadow:0 1px 3px rgb(0 0 0 / .25); transition:transform 200ms var(--ease-move); }
.button.setting-switch[aria-pressed=true]::before { background:var(--seg-active-text); box-shadow:none; }
.button.setting-switch[aria-pressed=true]::after { transform:translateX(20px); }
.button.setting-switch:active { transform:none; }
.button.setting-switch:active::after { width:32px; }
@media (prefers-reduced-motion:reduce) { .button.setting-switch::before,.button.setting-switch::after { transition:none; } }

/* One sync indicator: a cloud (or info when attention is needed) everywhere, coloured by state. */
.local-status .sync-state-icon { width:20px; height:20px; flex:none; color:var(--muted); }
.local-status[data-phase=pending] .sync-state-icon { color:var(--expense); }
.local-status:is([data-phase=conflict],[data-phase=error],[data-phase=action-required]) .sync-state-icon { color:var(--error); }
.local-status[data-phase=offline] .sync-state-icon { opacity:.6; }

/* ---- Micro-interactions (D) ---- */
@supports selector(:has(*)) {
  /* D2: one selection pill glides beneath equal-width options; no measuring code. */
  :is(.view-tabs,.type-switch,.stats-segment,.stats-view-switch).segmented { display:grid; grid-auto-flow:column; grid-auto-columns:minmax(0,1fr); grid-template-columns:none; }
  :is(.stats-flow-switch,.report-trend-switch,.report-scope).segmented { display:inline-grid; grid-auto-flow:column; grid-auto-columns:minmax(0,1fr); grid-template-columns:none; }
  .segmented:not(.settings-jump) { --seg-gap:4px; --n:2; --i:0; position:relative; column-gap:var(--seg-gap); isolation:isolate; }
  .segmented:not(.settings-jump):has(> button:nth-of-type(3):last-of-type) { --n:3; }
  .segmented:not(.settings-jump):has(> button:nth-of-type(4):last-of-type) { --n:4; }
  .segmented:not(.settings-jump):has(> button:nth-of-type(2):is([aria-selected=true],[aria-pressed=true])) { --i:1; }
  .segmented:not(.settings-jump):has(> button:nth-of-type(3):is([aria-selected=true],[aria-pressed=true])) { --i:2; }
  .segmented:not(.settings-jump):has(> button:nth-of-type(4):is([aria-selected=true],[aria-pressed=true])) { --i:3; }
  .segmented:not(.settings-jump)::before { content:''; position:absolute; z-index:-1; top:4px; bottom:4px; left:4px; width:calc((100% - 8px - (var(--n) - 1) * var(--seg-gap)) / var(--n)); border-radius:var(--radius-pill); background:var(--seg-active-bg); box-shadow:var(--seg-active-shadow); transform:translateX(calc(var(--i) * (100% + var(--seg-gap)))); transition:transform 200ms var(--ease-move); }
  .segmented-semantic::before { background:var(--seg-semantic-bg); }
  .segmented:not(.settings-jump):not(:has(> button:is([aria-selected=true],[aria-pressed=true])))::before { opacity:0; }
  html[data-theme] .segmented:not(.settings-jump) > button:is([aria-selected=true],[aria-pressed=true]) { background:transparent; box-shadow:none; }
  .segmented:not(.settings-jump) > button { position:relative; }

  /* D1: on phones the tab-bar pill glides between tabs (the + keeps the middle column). */
  @media (max-width:639px) {
    .navigation .nav-items { --nav-gap:2px; --x:0px; position:relative; column-gap:var(--nav-gap); isolation:isolate; }
    .navigation .nav-items:has(> .nav-item:nth-child(2).active) { --x:calc(100% + var(--nav-gap)); }
    .navigation .nav-items:has(> .nav-item:nth-child(3).active) { --x:calc(200% + 56px + 3 * var(--nav-gap)); }
    .navigation .nav-items:has(> .nav-item:nth-child(4).active) { --x:calc(300% + 56px + 4 * var(--nav-gap)); }
    .navigation .nav-items::before { content:''; position:absolute; z-index:-1; top:0; bottom:0; left:0; width:calc((100% - 56px - 4 * var(--nav-gap)) / 4); border-radius:var(--radius-sm); background:var(--brand-soft); transform:translateX(var(--x)); transition:transform 200ms var(--ease-move); }
    .navigation .nav-items:not(:has(> .nav-item.active))::before { opacity:0; }
    html[data-theme] .navigation .nav-items > .nav-item.active { background:transparent; box-shadow:none; }
  }
}
/* Navigation icons stay anchored; the selection pill alone signals route changes. */
@media (prefers-reduced-motion:reduce) {
  .segmented::before,.navigation .nav-items::before { transition:none; }
}

/* D4: Save becomes a round ✓ that draws itself before the sheet closes. */
@keyframes check-draw { from { stroke-dashoffset:24; } to { stroke-dashoffset:0; } }
#transaction-form .dialog-footer { justify-content:center; interpolate-size:allow-keywords; }
html dialog #transaction-form[data-save-complete=true] > .dialog-footer .button.primary { flex:0 0 52px; width:52px; min-width:52px; padding:0; border-radius:var(--radius-pill); font-size:0; pointer-events:none; }
#transaction-form[data-save-complete=true] .dialog-footer .button.primary .icon { width:24px; height:24px; margin:0; stroke-dasharray:24; animation:check-draw var(--motion-move) var(--motion-ease) forwards; }
#transaction-form[data-save-complete=true] .dialog-footer [data-action=close] { opacity:0; }

/* D5: the undo countdown is a thin line along the toast's bottom edge. */
.toast:has(.toast-action) { overflow:hidden; }
.toast:has(.toast-action)::after { content:''; position:absolute; left:0; right:0; bottom:0; height:2px; background:var(--seg-active-text); transform-origin:left center; }
.toast { touch-action:none; }

/* D6: a changed total nudges in the direction it moved while it counts. */
[data-stats-number][data-value-changing] { display:inline-block; }

/* D3: while the entry sheet is open, the add button turns into a close mark (desktop and tablet). */
.nav-add .icon,.header-add .icon { transition:transform 200ms var(--ease-move); }
html:has(dialog.entry-dialog[open]) :is(.nav-add,.header-add) .icon { transform:rotate(45deg); }
@media (prefers-reduced-motion:reduce) {
  #transaction-form .dialog-footer .button.primary,.nav-add .icon,.header-add .icon { transition:none; }
  #transaction-form[data-save-complete=true] .dialog-footer .button.primary .icon,[data-stats-number][data-value-changing] { animation:none; }
}

/* D16: quick-action menu for a transaction (long-press on phones, right-click on desktop). */
.row-menu { position:fixed; z-index:60; display:grid; min-width:184px; padding:6px; border:1px solid var(--border); border-radius:var(--radius-md); background:var(--surface); box-shadow:var(--elevation-3); transform-origin:top left; }
.row-menu[hidden] { display:none; }
.row-menu button { display:flex; align-items:center; gap:10px; min-height:44px; padding:0 12px; border:0; border-radius:var(--radius-sm); background:none; color:var(--text); font-size:var(--text-md); text-align:left; }
.row-menu button:focus-visible{ background:var(--subtle); }@media (hover:hover) and (pointer:fine){.row-menu button:hover{ background:var(--subtle); }}
.row-menu .danger { color:var(--expense); }
.row-menu .icon { width:20px; height:20px; }

/* D19: the keyboard focus ring eases in instead of snapping. */
@keyframes focus-in { from { outline-offset:7px; outline-color:transparent; } }
:focus-visible { animation:focus-in var(--motion-enter) var(--motion-ease); }
@media (prefers-reduced-motion:reduce) { :focus-visible { animation:none; } }

/* ---- Gradient surface ----
   A grainy, soft multi-point gradient for moments (recap, budget), never behind dense data.
   Colours come only from each theme's tokens; strength is lower in the dark themes so text keeps contrast.
   Static by design: no animation, so no battery cost and nothing to reduce. */
:root { --grad-1:var(--decorative); --grad-2:var(--reference-blue); --grad-3:var(--expense); --grad-strength:46%; --grad-grain:.32; }
:root[data-theme=dark] { --grad-1:var(--brand); --grad-2:var(--chart-2); --grad-3:var(--chart-6); --grad-strength:24%; --grad-grain:.22; }
:root[data-theme=grey-glass] { --grad-1:var(--brand); --grad-2:var(--reference-blue); --grad-3:var(--chart-6); --grad-strength:30%; --grad-grain:.24; }
:is(.gradient-surface,.month-review-recap,html[data-theme] #app .budget-card,html[data-theme] #app .mobile-budget-summary) {
  position:relative; isolation:isolate; overflow:hidden;
  background:
    radial-gradient(120% 95% at 0% 0%,color-mix(in srgb,var(--grad-2) var(--grad-s2,var(--grad-strength)),transparent),transparent 62%),
    radial-gradient(95% 85% at 100% 75%,color-mix(in srgb,var(--grad-1) var(--grad-s1,var(--grad-strength)),transparent),transparent 66%),
    radial-gradient(70% 60% at 35% 115%,color-mix(in srgb,var(--grad-3) var(--grad-s3,calc(var(--grad-strength) * .55)),transparent),transparent 72%),
    var(--surface);
}
:is(.gradient-surface,.month-review-recap,html[data-theme] #app .budget-card,html[data-theme] #app .mobile-budget-summary)::after {
  content:''; position:absolute; inset:0; z-index:-1; pointer-events:none; border-radius:inherit;
  background:url('./ambient-grain.svg') repeat; background-size:160px; opacity:var(--grad-grain); mix-blend-mode:overlay;
}
/* Month review: the recap reads as a header card. */
.month-review-recap { margin:0 0 8px; padding:20px; border:1px solid var(--border); border-radius:var(--radius-lg); }
.month-review-recap h3 { margin-top:0; }
/* Budget cards: a subtler wash whose colour follows the budget state. */
html[data-theme] #app :is(.budget-card,.mobile-budget-summary) { --grad-strength:30%; }
html[data-theme=dark] #app :is(.budget-card,.mobile-budget-summary) { --grad-strength:22%; }
html[data-theme=grey-glass] #app :is(.budget-card,.mobile-budget-summary) { --grad-strength:28%; }
html[data-theme] #app :is(.budget-card,.mobile-budget-summary)[data-budget-state=ok] { --grad-1:var(--income); --grad-2:var(--reference-blue); --grad-3:var(--chart-3); }
html[data-theme] #app :is(.budget-card,.mobile-budget-summary)[data-budget-state=near] { --grad-1:var(--warning); --grad-2:var(--decorative); --grad-3:var(--expense); }
html[data-theme] #app :is(.budget-card,.mobile-budget-summary)[data-budget-state=over] { --grad-1:var(--error); --grad-2:var(--expense); --grad-3:var(--warning); }
html[data-theme] #app :is(.budget-card,.mobile-budget-summary)[data-budget-state=unset] { --grad-strength:0%; }
@media (forced-colors:active) { :is(.gradient-surface,.month-review-recap,#app .budget-card,#app .mobile-budget-summary) { background:Canvas; } :is(.gradient-surface,.month-review-recap,#app .budget-card,#app .mobile-budget-summary)::after { display:none; } }

/* Text on a gradient keeps full contrast: secondary text uses the main text colour (hierarchy comes from size and weight). */
:is(.gradient-surface,.month-review-recap,html[data-theme] #app .budget-card,html[data-theme] #app .mobile-budget-summary) { --muted:var(--text); color:var(--text); }
/* Grey Glass's own colours are pastel, so its gradient mostly deepens (navy pools from its scrim and budget tokens)
   with a faint gold glow; white text only gains contrast. Strengths are capped so text stays above 4.5:1. */
html[data-theme=grey-glass] :is(.gradient-surface,.month-review-recap,#app .budget-card,#app .mobile-budget-summary) { --grad-2:var(--scrim); --grad-3:var(--budget-bg); --grad-s1:12%; --grad-s2:70%; --grad-s3:65%; }
html[data-theme=grey-glass] #app :is(.budget-card,.mobile-budget-summary)[data-budget-state] { --grad-2:var(--scrim); --grad-3:var(--budget-bg); }
html[data-theme=grey-glass] #app :is(.budget-card,.mobile-budget-summary)[data-budget-state=unset] { --grad-s1:0%; --grad-s2:0%; --grad-s3:0%; }

/* Odometer: a changed digit rolls inside a one-line window; unchanged digits never move. The whole-number nudge is off while rolling. */
[data-stats-number][data-rolling] { display:inline-block; animation:none; white-space:nowrap; }
.odo-column { display:inline-block; height:1lh; overflow:clip; vertical-align:bottom; }
.odo-reel { display:flex; flex-direction:column; will-change:transform; }
.odo-reel > span { display:block; height:1lh; }
@supports not (height:1lh) { .odo-column,.odo-reel > span { height:1.2em; line-height:1.2em; } }

/* Grey Glass optical finish. Palette and financial content remain unchanged.
   No moving blur, shimmer or refraction behind text. Existing pill motion owns selection. */
@media (prefers-reduced-transparency:no-preference) and (prefers-contrast:no-preference) and (forced-colors:none) {
 @supports ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))) {
  html[data-theme=grey-glass]:not([data-simple-glass=true]):not(.modal-animating) :is(.navigation,.topbar,.mobile-home-header,.stats-scope) {
   background:linear-gradient(145deg,#e7f0ff0d,transparent 46%),var(--glass-tint);
   border-color:var(--glass-edge);box-shadow:inset 0 1px 0 #f3f7ff24,0 8px 24px #0b163024;
   -webkit-backdrop-filter:blur(16px) saturate(115%);backdrop-filter:blur(16px) saturate(115%);
  }
  html[data-theme=grey-glass]:not([data-simple-glass=true]) :is(.nav-item.active,.tab-indicator[data-shape=pill],.month-control) {
   background:linear-gradient(155deg,#e7f0ff18,transparent 58%),var(--brand-soft);
   box-shadow:inset 0 1px 0 #f3f7ff38,inset 0 -1px 0 #0b163026,0 2px 6px #0b16301a;
  }
  html[data-theme=grey-glass]:not([data-simple-glass=true]) .month-control::before,
  html[data-theme=grey-glass]:not([data-simple-glass=true]) .tab-indicator[data-shape=pill]::before {
   -webkit-backdrop-filter:none;backdrop-filter:none;
  }
 }
}

/* Measured mobile selection: only this decorative layer stretches or travels. */
.nav-selection{display:none;pointer-events:none}
@media(max-width:639px){
 .navigation .nav-items.has-nav-selection{position:relative;isolation:isolate}
 .navigation .nav-items.has-nav-selection::before{display:none}
 .navigation .nav-items.has-nav-selection>.nav-selection{display:block;position:absolute;z-index:-1;transform-origin:left center;border-radius:var(--radius-sm);background:var(--brand-soft);box-shadow:var(--seg-active-shadow)}
 html[data-theme] .navigation .nav-items.has-nav-selection>.nav-item.active{background:transparent;box-shadow:none}
 @media(prefers-reduced-transparency:no-preference) and (prefers-contrast:no-preference){
  html[data-theme=grey-glass]:not([data-simple-glass=true]) .navigation .nav-items.has-nav-selection>.nav-selection{background:linear-gradient(155deg,#e7f0ff18,transparent 58%),var(--brand-soft);box-shadow:inset 0 1px 0 var(--experience-edge)}
 }
}
@media(forced-colors:active){html[data-theme] .navigation .nav-items.has-nav-selection>.nav-selection{background:Highlight;box-shadow:none}html[data-theme] .navigation .nav-items.has-nav-selection>.nav-item.active{color:HighlightText}}

.navigation .nav-item .icon{transition:color 160ms var(--motion-ease)}
@media(prefers-reduced-motion:reduce){.navigation .nav-item .icon{transition:none}}
/* A month finished within budget: its recap check draws once (no confetti). */
.month-review-recap h3 { display:flex; align-items:center; gap:8px; }
.month-review-recap .recap-check { color:var(--income); flex:none; }
.month-review-recap .recap-check[data-draw=true] path { stroke-dasharray:24; animation:check-draw 300ms var(--motion-ease) both; }
@media (prefers-reduced-motion:reduce) { .month-review-recap .recap-check[data-draw=true] path { animation:none; } }
