/* pages/finance.css — /finance/, /finance/connect (SPEC §5.11).
 *
 * PAGE-SCOPE RULE (§1.1, test_design check 9): every selector starts with a
 * class this file owns — `.acct*`, `.fin__head`, `.bankbar*`, `.flagform*`,
 * `#transactions`, `.finance-connect` — or with [data-page="finance"]. All
 * eleven page files load on every page. `.tiles` is Mail's class: Finance's
 * row of account cards restates every property it needs under its own scope,
 * so a change to Mail's row never reaches it.
 *
 * The page: a FIXED TOP (.page-top: the total, the account cards, the
 * bank bar), then the list/detail split — the months on the card, one
 * account's lines in the reading region under its sticky head (§4.7).
 */

/* ── The fixed top ─────────────────────────────────────────────────────── */
[data-page="finance"] .page-top { display: flex; flex-direction: column; gap: 12px; }
[data-page="finance"] .page-top > .head { margin: 0; }
[data-page="finance"] .page-top > .head .head__sub {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  font-variant-numeric: tabular-nums;
}

/* The account cards: one row that scrolls SIDEWAYS (app.css gives .tiles its
   40px fade). It bleeds to the pane's edges, so a card scrolls out under the
   fade rather than being cut at the padding. The focus ring is drawn inside
   the card (−3px), because this scroller clips anything outside it. */
[data-page="finance"] .tiles {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin: 0 calc(-1 * var(--app-viewpad));
  padding: 0 var(--app-viewpad);
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-padding-inline: var(--app-viewpad);
}
[data-page="finance"] .tiles[hidden] { display: none; }

/* A selectable card (M3): #282A2C at rest with the state layer; pressed
   (aria-pressed="true") is the grey selected step #333537 with an emphasized
   name. The name is an .m3-label, so it already holds its emphasized width
   and selecting never reflows the row (D18). */
.acct {
  --_container: var(--md-sys-color-surface-container-high);
  --_state-color: var(--md-sys-color-on-surface);
  --_fill: 0;
  --_label-em: var(--md-sys-typescale-emphasized-title-small-weight);
  box-sizing: border-box;
  flex: none;
  display: grid;
  gap: 2px;
  align-content: start;
  min-width: 200px;
  margin: 0;
  padding: 12px 16px;
  border: 0;
  border-radius: var(--md-sys-shape-corner-medium);
  background-color: color-mix(in srgb, var(--_state-color) var(--_state), var(--_container));
  color: var(--md-sys-color-on-surface);
  font: inherit;
  text-align: start;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  outline-offset: var(--app-focus-offset-inner);
}
.acct[hidden] { display: none; }
.acct > b {
  align-items: flex-start;              /* a card title reads from the start edge (m3.css centres an .m3-label in its reserved width) */
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-title-small-size);
  line-height: var(--md-sys-typescale-title-small-line-height);
  font-weight: var(--md-sys-typescale-title-small-weight);
  white-space: nowrap;
}
.acct > span:not(.acct__bal) {
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-block-size: var(--md-sys-typescale-body-small-line-height);  /* no IBAN: the line holds, the balances still align */
}
.acct__bal {
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-title-medium-size);
  line-height: var(--md-sys-typescale-title-medium-line-height);
  font-weight: var(--md-sys-typescale-title-medium-weight);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
@media (hover: hover) {
  .acct:hover { --_state: var(--md-sys-state-hover-state-layer-opacity); }
}
.acct:focus-visible { --_state: var(--md-sys-state-focus-state-layer-opacity); }
.acct:active { --_state: var(--md-sys-state-pressed-state-layer-opacity); }
.acct[aria-pressed="true"] {
  --_container: var(--md-sys-color-secondary-container);
  --_state-color: var(--md-sys-color-on-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.acct[aria-pressed="true"] > b {
  color: var(--md-sys-color-on-secondary-container);
  font-weight: var(--md-sys-typescale-emphasized-title-small-weight);
  font-variation-settings: "ROND" var(--md-sys-typescale-emphasized-rond);
}
@media (prefers-reduced-motion: no-preference) {
  .acct {
    transition: background-color var(--md-sys-motion-spring-fast-effects-duration) var(--md-sys-motion-spring-fast-effects);
  }
}

/* Reading one account on a phone (one pane, <=839px), the fixed top keeps
   only what switches the record — the cards. The total is the head, which the
   shell already hides there; the bank bar goes with it and is back on Back. */
@media (max-width: 839px) {
  [data-page="finance"].content.is-reading .page-top > .bankbar { display: none; }
}
/* …and reading one in a half of a split (app.css, READING MODE). The PANE's
   state there: the other half may be on its own list. */
[data-page="finance"].pane.is-reading:where(.content.is-split *) .page-top > .bankbar { display: none; }

/* ── The bank bar ──────────────────────────────────────────────────────────
   The Refresh button (outlined S, a leading `sync`) with its cost line
   (.bankbar__note), or, when it cannot run, a .notice saying why (off,
   expired, no consent: the notice Tasks and Chat use for "off"); a refresh
   report (a .notice too) or an error (the .err banner). While the refresh runs, the form grows a WAVY
   indeterminate bar on its own last line (§3.20): a bank fetch can take longer
   than 5s, and it is the one wavy bar in the app. The form carries the four
   segment edges (registered, inheriting); ::after is the wave, ::before the
   flat 4px track centred under it. */
.bankbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-width: 0;
  margin: 0;
}
.bankbar[hidden] { display: none; }
.bankbar > form {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
}
.bankbar > :is(.formerr, .notice) { flex: 1 1 100%; margin: 0; }
.bankbar__note {
  margin: 0;
  min-width: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
  overflow-wrap: anywhere;
}
.bankbar__note[hidden] { display: none; }
.bankbar__note code { font-size: var(--md-sys-typescale-body-small-size); line-height: var(--md-sys-typescale-body-small-line-height); }
.bankbar form.htmx-request::after {
  content: "";
  flex: 1 1 100%;
  height: var(--app-progress-wavy-h);
  background: var(--md-sys-color-primary);
  mask-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='10'%3E%3Cpath d='M0 5Q5 -1 10 5T20 5' fill='none' stroke='black' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E"),
    linear-gradient(to right, transparent var(--_s2t), black 0 var(--_s2h), transparent 0 var(--_s1t), black 0 var(--_s1h), transparent 0);
  mask-size: 20px 10px, 100% 100%;
  mask-repeat: repeat-x, no-repeat;
  mask-position: 0 50%, 0 0;
  mask-composite: intersect;
}
.bankbar form.htmx-request::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 3px;
  height: var(--app-progress-h);
  border-radius: var(--app-shape-corner-mark);
  background: var(--md-sys-color-secondary-container);
  mask-image: linear-gradient(to right,
    black calc(var(--_s2t) - 4px), transparent 0 calc(var(--_s2h) + 4px),
    black 0 calc(var(--_s1t) - 4px), transparent 0 calc(var(--_s1h) + 4px), black 0);
  pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .bankbar form.htmx-request {
    animation:
      m3-lp-s1h var(--app-motion-progress) infinite, m3-lp-s1t var(--app-motion-progress) infinite,
      m3-lp-s2h var(--app-motion-progress) infinite, m3-lp-s2t var(--app-motion-progress) infinite;
  }
  .bankbar form.htmx-request::after { animation: m3-wave var(--app-motion-wave) linear infinite; }
}
@media (prefers-reduced-motion: reduce) {
  .bankbar form.htmx-request::before { display: none; }
  .bankbar form.htmx-request::after {                 /* the still wave at full width */
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='10'%3E%3Cpath d='M0 5Q5 -1 10 5T20 5' fill='none' stroke='black' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E");
    mask-size: 20px 10px;
    mask-repeat: repeat-x;
    mask-position: 0 50%;
  }
}

/* ── The months (the list column) ──────────────────────────────────────────
   A short SEGMENTED list (one tile a month) under a sentence-case head. The
   list is its own scroller with the vertical 40px fade, so twelve months never
   spill over the record below (pages-b §3e #4). Negative money is red TEXT. */
.fin__head { margin: 0; min-width: 0; }
[data-page="finance"] .split__list > .fin__head {
  flex: none;
  padding: 0 16px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-title-small-size);
  line-height: var(--md-sys-typescale-title-small-line-height);
  font-weight: var(--md-sys-typescale-title-small-weight);
}
[data-page="finance"] .split__list > .rows {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  list-style: none;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
[data-page="finance"] .split__list > .rows::-webkit-scrollbar { display: none; }
@supports (animation-timeline: scroll(self)) {
  [data-page="finance"] .split__list > .rows {
    mask-image: linear-gradient(to bottom, transparent 0, black var(--m3-fade-start),
                                black calc(100% - var(--m3-fade-end)), transparent 100%);
    animation-name: m3-fade-start, m3-fade-end;
    animation-duration: auto, auto;
    animation-timing-function: linear, linear;
    animation-fill-mode: both, both;
    animation-timeline: scroll(self block), scroll(self block);
    animation-range: 0px var(--m3-fade, 40px), calc(100% - var(--m3-fade, 40px)) 100%;
  }
}
[data-page="finance"] .row__note.is-out { color: var(--md-sys-color-error); }

/* ── One account's lines (the record) ──────────────────────────────────────
   #transactions is a flex column with a 16px gap, so the sticky head
   (app.css §4.7: its skirt, its margins and padding — this file sets none
   of them) stands 28px clear of the lines (its 12px margin + the gap). The account name is the record title in
   headline-small EMPHASIZED (§3.28), the role Mail, News, Contacts and the
   Calendar sheet give theirs, not §5.11's title-large: one record tier on the
   same head. It is an inline-size container: the
   line layout below follows the RECORD's width (a split pane, a 1024px
   window), not the window's. */
#transactions {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  container-type: inline-size;
}
#transactions[hidden] { display: none; }
#transactions > .fin__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface-brand);
  font-size: var(--md-sys-typescale-headline-small-size);
  line-height: var(--md-sys-typescale-headline-small-line-height);
  font-weight: var(--md-sys-typescale-emphasized-headline-small-weight);
  font-variation-settings: "ROND" var(--md-sys-typescale-emphasized-rond);
  overflow-wrap: anywhere;
}

/* A STANDARD list (M3E: segmented lists are not for long feeds, and this one
   runs to 150 lines): transparent 72px two-line items that morph on hover
   (4 → 12) and while the flag field inside has focus (16), with the state
   layer. Grid areas: the text, the flag field, the amount. */
[data-page="finance"] #transactions .rows {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}
[data-page="finance"] #transactions .rows > .row {
  --_container: transparent;
  --_r: var(--md-sys-shape-corner-extra-small);
  --_rt-own: var(--_r);
  --_rb-own: var(--_r);
  min-height: var(--app-list-h-2);
  padding: 8px 16px;
}
[data-page="finance"] #transactions .rows > .row:has(> .flagform) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "main flag note";
  align-items: center;
  column-gap: 16px;
  row-gap: 8px;
}
@media (hover: hover) {
  [data-page="finance"] #transactions .rows > .row:hover {
    --_state: var(--md-sys-state-hover-state-layer-opacity);
    --_r: var(--md-sys-shape-corner-medium);
  }
}
[data-page="finance"] #transactions .rows > .row:focus-within {
  --_state: var(--md-sys-state-focus-state-layer-opacity);
  --_r: var(--md-sys-shape-corner-large);
}
[data-page="finance"] #transactions .row__main { grid-area: main; margin-inline-end: 0; min-width: 0; }
[data-page="finance"] #transactions .row__note {
  grid-area: note;
  max-inline-size: none;
  text-align: end;
  white-space: nowrap;
}
@media (prefers-reduced-motion: no-preference) {
  [data-page="finance"] #transactions .rows > .row {
    transition-property: border-radius, background-color;
    transition-duration: var(--md-sys-motion-spring-fast-spatial-duration), var(--md-sys-motion-spring-fast-effects-duration);
    transition-timing-function: var(--md-sys-motion-spring-fast-spatial), var(--md-sys-motion-spring-fast-effects);
  }
}

/* ── The flag field ────────────────────────────────────────────────────────
   A line's flags, editable in place: a FILLED text field (.m3-textfield, 56px,
   #333537, corners 4 4 0 0, the accent indicator on focus and never a ring),
   200px wide. Its label "Flags" rests inside while it is empty and floats over
   a value, so the box says what it is; the example ("recurring · label: …")
   shows only on focus (m3.css, D11). It submits on Enter; there is no Save
   button because one field with an obvious value does not need one.
   - WITH A MOUSE it takes no column of its own: out of sight until the line is
     hovered or the field has focus (Tab still reaches it: opacity, not
     display), then drawn OVER the end of the line's own text, so a long
     description is never cut beside 216px of blank space.
   - ON TOUCH it is ALWAYS there (K16) in a column between the text and the
     amount, and the line is an 88px three-line item. In a NARROW record (a
     split pane, a phone) there is no room for that column, so it takes a full
     line of its own under the text. */
.flagform { grid-area: flag; min-width: 0; width: 200px; margin: 0; }
.flagform[hidden] { display: none; }
.flagform > .flagform__field { width: 100%; }
@media (hover: hover) and (pointer: fine) {
  [data-page="finance"] #transactions .rows > .row:has(> .flagform) {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "main note";
  }
  [data-page="finance"] #transactions .flagform {
    grid-area: main;
    justify-self: end;
    position: relative;
    z-index: 1;
    width: min(200px, 100%);
    opacity: 0;
  }
  [data-page="finance"] #transactions .row:is(:hover, :focus-within) .flagform { opacity: 1; }
}
@media (hover: none), (pointer: coarse) {
  [data-page="finance"] #transactions .rows > .row:has(> .flagform) { min-height: var(--app-list-h-3); }
  @container (max-width: 599px) {
    [data-page="finance"] #transactions .rows > .row:has(> .flagform) {
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas: "main note" "flag flag";
    }
    [data-page="finance"] #transactions .flagform {
      justify-self: stretch;
      width: auto;
    }
  }
}
@media (prefers-reduced-motion: no-preference) {
  .flagform {
    transition: opacity var(--md-sys-motion-spring-fast-effects-duration) var(--md-sys-motion-spring-fast-effects);
  }
}

/* ── Connect a bank (/finance/connect) ─────────────────────────────────────
   One expressive card (28, padding 20/22 — it clears its own corner, K29) at
   a readable measure. The picker is a filled select (.m3-textfield); the URLs
   printed to copy are mono on a #333537 mark. */
.finance-connect {
  box-sizing: border-box;
  width: 100%;
  max-inline-size: 640px;
  padding: 20px 22px;
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container);
}
.finance-connect[hidden] { display: none; }
.finance-connect > :is(.notice, .notice--bad) { margin: 0; }
.finance-connect form.field { display: grid; gap: 16px; }
.finance-connect form.field > .field__row { min-height: 0; }
/* A URL printed for someone to copy — the callback addresses.
   ⚠️ A URL IS ONE UNBREAKABLE TOKEN to normal wrapping, so without
   overflow-wrap the line is as wide as the string: measured at 360px, 391px of
   URL inside a 360px viewport, which the content's overflow turns into a
   sideways scroll rather than a visible break. ⚠️ AND THE DOCUMENT NEVER
   SCROLLS, so a check that watched documentElement.scrollWidth reported the
   page as fitting — smoke-width.mjs measures every scrollable ancestor for
   exactly this reason. */
[data-page="finance"] .field code {
  padding: 2px 6px;
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: var(--md-sys-color-surface-container-highest);
  font-family: var(--app-typeface-mono);
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* K42: the list and record rules above give a display at a specificity that
   outranks m3.css's `[hidden]` (0,2,0), so [hidden] is restated at theirs —
   LAST in the file, because equal specificity goes to the later rule. */
.fin__head[hidden],
#transactions > .fin__head[hidden],
[data-page="finance"] .split__list > .rows[hidden],
[data-page="finance"] #transactions .rows[hidden],
[data-page="finance"] #transactions .rows > .row[hidden],
[data-page="finance"] #transactions .rows > .row:has(> .flagform)[hidden] { display: none; }
