/* ==========================================================================
   Budget Bot Mini WebApp — MD3 component library
   Depends on: tokens.css (all colour/type/shape/motion tokens)
   Naming: m3-  ·  __element  ·  --modifier
   No colour literals in this file except the documented ::backdrop scrim.
   ========================================================================== */

/* ==========================================================================
   0. Shared plumbing
   ========================================================================== */

/* 0.3 State layer — add .m3-stateful to any interactive element.
   NOTE: no `overflow: hidden` here on purpose. The ::before layer already
   clips itself with `border-radius: inherit`, and hiding overflow would clip
   the .m3-touch ::after hit-area expander back down to the visual size —
   silently breaking the 48dp target on every 32px chip and 40px icon button. */
.m3-stateful {
  position: relative;
  isolation: isolate;
}
.m3-stateful::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: currentColor;
  opacity: 0;
  border-radius: inherit;
  transition: opacity var(--md-sys-motion-duration-short2) linear;
  pointer-events: none;
}
@media (hover: hover) {
  .m3-stateful:hover:not(:disabled):not([aria-disabled="true"])::before { opacity: 0.08; }
}
.m3-stateful:focus-visible::before { opacity: 0.10; }
.m3-stateful:active:not(:disabled):not([aria-disabled="true"])::before { opacity: 0.10; }

/* 0.4 Focus ring — :focus-visible only, everywhere */
:where(
  .m3-stateful,
  .m3-field__input,
  .m3-select,
  .m3-switch input,
  .m3-tab,
  .m3-chip,
  .m3-segmented__btn,
  a.m3-link
):focus-visible {
  outline: 3px solid var(--md-sys-color-secondary);
  outline-offset: 2px;
}
/* Suppress the ring for pointer/programmatic focus only. `:where()` above
   zeroes the ring selector's specificity, so a bare `.m3-stateful:focus`
   reset would out-specify it and kill the ring on keyboard focus too. */
.m3-stateful:focus:not(:focus-visible) { outline: none; }

/* 0.5 Disabled */
.m3-disabledable:disabled,
.m3-disabledable[aria-disabled="true"] {
  cursor: not-allowed;
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
}

/* 0.6 Touch target expander (::after — ::before is the state layer) */
.m3-touch { position: relative; }
.m3-touch::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: max(100%, 48px);
  height: max(100%, 48px);
}

/* ==========================================================================
   1. Common buttons
   ========================================================================== */
.m3-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--md-sys-spacing-2);
  min-height: 40px;
  padding: 0 var(--md-sys-spacing-6);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  white-space: nowrap;
}
.m3-btn:has(.m3-btn__icon),
.m3-btn:has(.m3-circular) { padding-left: var(--md-sys-spacing-4); }
/* MD3 draws common buttons 40px tall but still requires a 48dp target, so
   every button grows an invisible hit area the way .m3-touch does for chips
   and icon buttons. Width is left alone — buttons are never narrower than
   48px in this app, and widening would overlap the neighbour in a button row. */
.m3-btn::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  translate: 0 -50%;
  height: max(100%, 48px);
}
.m3-btn__icon { width: 18px; height: 18px; flex-shrink: 0; }
.m3-btn--block { display: flex; width: 100%; }

.m3-btn--filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}
.m3-btn--tonal {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.m3-btn--outlined {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}
.m3-btn--text {
  background: transparent;
  color: var(--md-sys-color-primary);
  padding: 0 var(--md-sys-spacing-3);
}
.m3-btn--error {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}
.m3-btn--error-tonal {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}
.m3-btn--tertiary-tonal {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}
.m3-btn--text-error { color: var(--md-sys-color-error); }

.m3-btn:disabled,
.m3-btn[aria-disabled="true"] {
  cursor: not-allowed;
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
}
.m3-btn--filled:disabled,
.m3-btn--tonal:disabled,
.m3-btn--error:disabled,
.m3-btn--error-tonal:disabled,
.m3-btn--tertiary-tonal:disabled,
.m3-btn--filled[aria-disabled="true"],
.m3-btn--tonal[aria-disabled="true"],
.m3-btn--error[aria-disabled="true"],
.m3-btn--error-tonal[aria-disabled="true"],
.m3-btn--tertiary-tonal[aria-disabled="true"] {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
}
.m3-btn--outlined:disabled,
.m3-btn--outlined[aria-disabled="true"] {
  border-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
}
.m3-btn:disabled::before,
.m3-btn[aria-disabled="true"]::before { opacity: 0 !important; }

/* ==========================================================================
   2. Icon buttons
   ========================================================================== */
.m3-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.m3-icon-btn svg { width: 24px; height: 24px; display: block; }
.m3-icon-btn--tonal {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.m3-icon-btn--primary { color: var(--md-sys-color-primary); }
.m3-icon-btn--error { color: var(--md-sys-color-error); }
.m3-icon-btn:disabled {
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  cursor: not-allowed;
}
.m3-icon-btn:disabled::before { opacity: 0 !important; }
.m3-icon-btn--tonal:disabled {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
}

/* ==========================================================================
   3. FAB
   ========================================================================== */
.m3-fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  box-shadow: var(--md-sys-elevation-shadow-2);
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}
.m3-fab svg { width: 24px; height: 24px; display: block; }
@media (hover: hover) {
  .m3-fab:hover { box-shadow: var(--md-sys-elevation-shadow-3); }
}

/* ==========================================================================
   4. Chips (filter chips, single-select radiogroups)
   ========================================================================== */
.m3-chip-set {
  display: flex;
  gap: var(--md-sys-spacing-2);
  flex-wrap: wrap;
}
.m3-chip-set--scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  /* `overflow-x: auto` forces the untouched y axis to compute to `auto` too, so
     this row clips vertically as well. Without room inside the scrollport the
     48px `.m3-touch` ::after on a 32px chip would be clipped away (and its
     bottom half turned into stray scrollable overflow). Pad both block edges by
     the 8px of overhang and pull it back out with a matching negative margin:
     the ::after and the focus ring now fit inside the padding box, and the row
     occupies exactly the same space in the flow as before. */
  padding-block: 8px;
  margin-block: -8px;
}
.m3-chip-set--scroll::-webkit-scrollbar { display: none; }
.m3-chip-set--scroll > .m3-chip { scroll-snap-align: start; }

.m3-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--md-sys-spacing-2);
  height: 32px;
  padding: 0 var(--md-sys-spacing-4);
  flex-shrink: 0;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.m3-chip__check {
  width: 18px;
  height: 18px;
  display: none;
  margin-left: -6px;
  flex-shrink: 0;
}
.m3-chip[aria-checked="true"],
.m3-chip[aria-pressed="true"] {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-color: transparent;
}
.m3-chip[aria-checked="true"] .m3-chip__check,
.m3-chip[aria-pressed="true"] .m3-chip__check { display: inline-block; }
.m3-chip:disabled {
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  border-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  cursor: not-allowed;
}
.m3-chip:disabled::before { opacity: 0 !important; }

/* ==========================================================================
   5. Segmented button
   ========================================================================== */
.m3-segmented {
  display: flex;
  width: 100%;
  height: 40px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
}
.m3-segmented__btn {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--md-sys-spacing-2);
  border: none;
  background: transparent;
  padding: 0 var(--md-sys-spacing-3);
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m3-segmented__btn + .m3-segmented__btn { border-left: 1px solid var(--md-sys-color-outline); }
/* Round the end segments instead of clipping the group, so each button keeps
   its full 48dp touch expander. */
.m3-segmented__btn:first-child {
  border-radius: var(--md-sys-shape-corner-full) 0 0 var(--md-sys-shape-corner-full);
}
.m3-segmented__btn:last-child {
  border-radius: 0 var(--md-sys-shape-corner-full) var(--md-sys-shape-corner-full) 0;
}
.m3-segmented__btn:only-child { border-radius: var(--md-sys-shape-corner-full); }
.m3-segmented__check { width: 18px; height: 18px; display: none; flex-shrink: 0; }
.m3-segmented__btn[aria-checked="true"] {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.m3-segmented__btn[aria-checked="true"] .m3-segmented__check { display: inline-block; }
.m3-segmented__btn:focus-visible { outline-offset: -3px; }

/* ==========================================================================
   6. Text fields (outlined) — inputs, textareas, selects, date inputs
   ========================================================================== */
.m3-field {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.m3-field__input {
  width: 100%;
  min-height: 56px;
  padding: var(--md-sys-spacing-4);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-large);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--md-sys-motion-duration-short2) linear;
}
.m3-field__input--area { resize: vertical; min-height: 88px; }
.m3-field__input::placeholder { color: transparent; }
.m3-field__label {
  position: absolute;
  left: var(--md-sys-spacing-3);
  top: var(--md-sys-spacing-4);
  padding: 0 var(--md-sys-spacing-1);
  max-width: calc(100% - var(--md-sys-spacing-6));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  background: var(--app-field-bg, var(--md-sys-color-surface));
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-large);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  transition:
    top var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
    font-size var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}
.m3-field__input:focus {
  border: 2px solid var(--md-sys-color-primary);
  padding: calc(var(--md-sys-spacing-4) - 1px);
  outline: none;
}
.m3-field__input:focus + .m3-field__label,
.m3-field__input:not(:placeholder-shown) + .m3-field__label,
.m3-field__label--pinned {
  top: -8px;
  font: var(--md-sys-typescale-body-small);
  letter-spacing: var(--md-sys-typescale-body-small-tracking);
}
.m3-field__input:focus + .m3-field__label { color: var(--md-sys-color-primary); }
.m3-field__support {
  margin: var(--md-sys-spacing-1) var(--md-sys-spacing-4) 0;
  font: var(--md-sys-typescale-body-small);
  letter-spacing: var(--md-sys-typescale-body-small-tracking);
  color: var(--md-sys-color-on-surface-variant);
}
.m3-field--error .m3-field__input,
.m3-field--error .m3-field__input:focus { border-color: var(--md-sys-color-error); }
.m3-field--error .m3-field__label,
.m3-field--error .m3-field__support { color: var(--md-sys-color-error); }
.m3-field__input:disabled {
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  border-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  cursor: not-allowed;
}
.m3-field__input[type="date"] { display: block; min-width: 0; }
.m3-field__input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.m3-field__input[type="date"]::-webkit-calendar-picker-indicator { opacity: 0.6; }

/* Fields laid out side by side (amount + currency, date from/to) */
.m3-field-row {
  display: flex;
  gap: var(--md-sys-spacing-3);
  align-items: flex-start;
}
.m3-field-row > .m3-field { flex: 1; min-width: 0; }
.m3-field--narrow { flex: 0 0 96px !important; width: 96px; }
.m3-field--emoji { flex: 0 0 76px !important; width: 76px; }
.m3-field--emoji .m3-field__input { text-align: center; }

/* 6.1 Large amount input (expense form hero) */
.m3-amount__input {
  min-height: 96px;
  text-align: center;
  padding-left: 64px;
  padding-right: 64px;
  font: var(--md-sys-typescale-display-small);
  letter-spacing: 0;
}
.m3-amount__input:focus { padding-left: 63px; padding-right: 63px; }
.m3-amount__suffix {
  position: absolute;
  right: 20px;
  top: 50%;
  translate: 0 -50%;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-headline-small);
  pointer-events: none;
}

/* ==========================================================================
   7. Native select styled as an outlined field
   ========================================================================== */
.m3-select { padding-right: var(--md-sys-spacing-12); cursor: pointer; }
.m3-select__arrow {
  position: absolute;
  right: var(--md-sys-spacing-3);
  top: var(--md-sys-spacing-4);
  width: 24px;
  height: 24px;
  color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
}
select.m3-field__input option {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
}

/* ==========================================================================
   8. Cards
   ========================================================================== */
.m3-card {
  background: var(--md-sys-color-surface-container-low);
  --app-field-bg: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: var(--md-sys-spacing-4);
  overflow: hidden;
  min-width: 0;
}
.m3-card--flush { padding: 0; }
.m3-card--hero {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 20px;
}
.m3-card--outlined {
  background: var(--md-sys-color-surface);
  --app-field-bg: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
}
.m3-card--elevated { box-shadow: var(--md-sys-elevation-shadow-1); }
.m3-card__title {
  font: var(--md-sys-typescale-title-medium);
  letter-spacing: var(--md-sys-typescale-title-medium-tracking);
  color: var(--md-sys-color-on-surface);
  margin: 0 0 var(--md-sys-spacing-3);
}
.m3-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--md-sys-spacing-2);
  margin: 0 0 var(--md-sys-spacing-3);
}
.m3-card__header .m3-card__title { margin: 0; }
.m3-section-label {
  font: var(--md-sys-typescale-label-medium);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  margin: 0 0 var(--md-sys-spacing-3);
}
/* A section label inside a .m3-card--flush, where the card supplies no
   padding of its own. Same look as .m3-section-label everywhere else, so
   headings do not change appearance from card to card. */
.m3-section-label--inset {
  padding: var(--md-sys-spacing-4) var(--md-sys-spacing-4) 0;
  margin-bottom: 0;
}
.m3-card--hero .m3-section-label {
  color: color-mix(in srgb, var(--md-sys-color-on-primary-container) 80%, transparent);
}
.m3-trend {
  display: inline-flex;
  align-items: center;
  gap: var(--md-sys-spacing-1);
  height: 24px;
  padding: 0 var(--md-sys-spacing-2);
  border-radius: var(--md-sys-shape-corner-full);
  background: color-mix(in srgb, var(--md-sys-color-on-primary-container) 12%, transparent);
  font: var(--md-sys-typescale-label-medium);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
}

/* Card body: the standard vertical rhythm inside a card. */
.m3-card__body,
/* …and the same rhythm for a group of blocks that is NOT inside a card
   (tab panels, a list of date groups). Same rule, honest name. */
.m3-stack {
  display: flex;
  flex-direction: column;
  gap: var(--md-sys-spacing-3);
  min-width: 0;
}

/* A field directly under a chip set needs the row gap the flex parents give
   everything else — these two are plain block siblings. */
.m3-chip-set + .m3-field { margin-top: var(--md-sys-spacing-4); }

/* Hero card anatomy (index «Потрачено») */
.m3-hero__label {
  margin: 0 0 var(--md-sys-spacing-2);
  font: var(--md-sys-typescale-label-medium);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
  text-transform: uppercase;
  color: color-mix(in srgb, var(--md-sys-color-on-primary-container) 80%, transparent);
}
.m3-hero__amount {
  margin: 0;
  font: var(--md-sys-typescale-display-small);
  letter-spacing: var(--md-sys-typescale-display-small-tracking);
  color: var(--md-sys-color-on-primary-container);
  overflow-wrap: anywhere;
}
.m3-hero__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--md-sys-spacing-2);
  margin: var(--md-sys-spacing-3) 0 0;
  font: var(--md-sys-typescale-body-small);
  letter-spacing: var(--md-sys-typescale-body-small-tracking);
  color: color-mix(in srgb, var(--md-sys-color-on-primary-container) 80%, transparent);
}

/* Key/value row — per-currency totals, summary tiles, member meta */
.m3-kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--md-sys-spacing-3);
  min-height: 32px;
}
.m3-kv__key {
  min-width: 0;
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m3-kv__value {
  flex-shrink: 0;
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  color: var(--md-sys-color-on-surface);
}
.m3-kv--strong .m3-kv__value {
  font: var(--md-sys-typescale-title-medium);
  letter-spacing: var(--md-sys-typescale-title-medium-tracking);
}

/* A row of buttons (filter card «Применить», sheet-less form actions) */
.m3-btn-row {
  display: flex;
  gap: var(--md-sys-spacing-3);
  flex-wrap: wrap;
}
.m3-btn-row--end { justify-content: flex-end; }
.m3-btn-row > .m3-btn--block { flex: 1; width: auto; }

/* ==========================================================================
   9. Lists
   ========================================================================== */
.m3-list {
  list-style: none;
  margin: 0;
  padding: var(--md-sys-spacing-2) 0;
}
.m3-list-item {
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-4);
  width: 100%;
  min-height: 72px;
  padding: var(--md-sys-spacing-2) var(--md-sys-spacing-4);
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  font: var(--md-sys-typescale-body-large);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-radius: 0;
}
.m3-list-item--1line { min-height: 56px; }
.m3-list-item--static { cursor: default; }
.m3-list-item__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.m3-list-item__headline {
  font: var(--md-sys-typescale-body-large);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  color: var(--md-sys-color-on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m3-list-item__support {
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m3-list-item__trailing {
  flex-shrink: 0;
  font: var(--md-sys-typescale-title-small);
  letter-spacing: var(--md-sys-typescale-title-small-tracking);
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}
.m3-list-item__actions {
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-1);
  flex-shrink: 0;
}
.m3-list-item__icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--md-sys-color-on-surface-variant);
}
.m3-list-item--danger .m3-list-item__headline,
.m3-list-item--danger .m3-list-item__icon { color: var(--md-sys-color-error); }
.m3-list-subheader {
  padding: var(--md-sys-spacing-3) var(--md-sys-spacing-4) var(--md-sys-spacing-1);
  font: var(--md-sys-typescale-label-medium);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
  color: var(--md-sys-color-primary);
}

/* ==========================================================================
   10. Divider
   ========================================================================== */
.m3-divider {
  border: none;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  margin: 0;
}
.m3-divider--inset { margin-left: 72px; }

/* ==========================================================================
   13. Primary tabs
   ========================================================================== */
.m3-tabs {
  display: flex;
  height: 48px;
  background: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.m3-tab {
  position: relative;
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 0 var(--md-sys-spacing-2);
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-title-small);
  letter-spacing: var(--md-sys-typescale-title-small-tracking);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m3-tabs--sticky {
  position: sticky;
  top: 0;
  z-index: 7;
}
/* Tab strip living inside .app-topbar: it must elevate WITH the bar rather
   than paint its own opaque surface over it (SPEC-layout §4). */
.m3-tabs--in-bar { background: transparent; }
.m3-tab[aria-selected="true"] { color: var(--md-sys-color-primary); }
.m3-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  translate: -50% 0;
  width: min(100%, 56px);
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--md-sys-color-primary);
}

/* ==========================================================================
   14. Modal bottom sheet (<dialog>)
   ========================================================================== */
.m3-sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0 auto;
  width: 100%;
  max-width: 640px;
  max-height: calc(92dvh - var(--safe-top));
  display: none;
  flex-direction: column;
  border: none;
  padding: 0;
  border-radius: var(--md-sys-shape-corner-extra-large) var(--md-sys-shape-corner-extra-large) 0 0;
  background: var(--md-sys-color-surface-container-low);
  --app-field-bg: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-shadow-3);
  overflow: hidden;
}
.m3-sheet[open] {
  display: flex;
  animation: m3-sheet-in var(--md-sys-motion-duration-medium4) var(--md-sys-motion-easing-emphasized-decelerate);
}
.m3-sheet[open].m3-sheet--closing {
  animation: m3-sheet-out var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-emphasized-accelerate) forwards;
}
@keyframes m3-sheet-in { from { translate: 0 100%; } to { translate: 0 0; } }
@keyframes m3-sheet-out { from { translate: 0 0; } to { translate: 0 100%; } }

/* Permitted literal #2: ::backdrop cannot read custom properties reliably. */
.m3-sheet::backdrop,
.m3-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

.m3-sheet__handle {
  width: 32px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
  margin: var(--md-sys-spacing-3) auto var(--md-sys-spacing-1);
  background: var(--md-sys-color-on-surface-variant);
  opacity: 0.4;
}
.m3-sheet__header {
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-2);
  padding: var(--md-sys-spacing-1) var(--md-sys-spacing-2) var(--md-sys-spacing-1) var(--md-sys-spacing-6);
  flex-shrink: 0;
}
.m3-sheet__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font: var(--md-sys-typescale-title-large);
  letter-spacing: var(--md-sys-typescale-title-large-tracking);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m3-sheet__support {
  margin: 0 var(--md-sys-spacing-6) var(--md-sys-spacing-2);
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
}
.m3-sheet__content {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--md-sys-spacing-2) var(--md-sys-spacing-6);
  display: flex;
  flex-direction: column;
  gap: var(--md-sys-spacing-4);
}
.m3-sheet__content--flush { padding-inline: 0; }
/* For a sheet that ends in its content (no .m3-sheet__actions footer to pad
   the home indicator for it). */
.m3-sheet__content--safe {
  padding-bottom: calc(var(--md-sys-spacing-6) + var(--safe-bottom));
}
.m3-sheet__error {
  margin: 0;
  font: var(--md-sys-typescale-body-small);
  letter-spacing: var(--md-sys-typescale-body-small-tracking);
  color: var(--md-sys-color-error);
}
/* Receipt attachment — the photo/PDF an expense was extracted from.
   A tappable thumbnail row; tapping opens it full-size where it can be
   zoomed. Absent on typed expenses, so the whole block is x-show'd. */
.m3-receipt {
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-3);
  width: 100%;
  padding: var(--md-sys-spacing-2);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  text-align: start;
  cursor: pointer;
}
.m3-receipt__thumb {
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: var(--md-sys-shape-corner-small);
  /* Receipts are tall; cover keeps the row height honest and still
     shows the top of the slip, which is where the merchant is. */
  object-fit: cover;
  object-position: top;
  background: var(--md-sys-color-surface-container-highest);
}
.m3-receipt__pdf {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: var(--md-sys-shape-corner-small);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-large);
}

.m3-sheet__actions {
  display: flex;
  gap: var(--md-sys-spacing-3);
  flex-shrink: 0;
  padding: var(--md-sys-spacing-4) var(--md-sys-spacing-6)
           calc(var(--md-sys-spacing-4) + var(--safe-bottom));
}
.m3-sheet__actions .m3-btn { flex: 1; }

/* ==========================================================================
   15. Dialog (confirms)
   ========================================================================== */
.m3-dialog {
  margin: auto;
  width: min(calc(100% - 48px), 400px);
  border: none;
  padding: var(--md-sys-spacing-6);
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container-high);
  --app-field-bg: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-shadow-3);
}
.m3-dialog[open] {
  animation: m3-dialog-in var(--md-sys-motion-duration-medium4) var(--md-sys-motion-easing-emphasized-decelerate);
}
.m3-dialog[open].m3-dialog--closing {
  animation: m3-dialog-out var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-emphasized-accelerate) forwards;
}
@keyframes m3-dialog-in { from { opacity: 0; scale: 0.9; } to { opacity: 1; scale: 1; } }
@keyframes m3-dialog-out { from { opacity: 1; scale: 1; } to { opacity: 0; scale: 0.9; } }
.m3-dialog__headline {
  margin: 0 0 var(--md-sys-spacing-4);
  font: var(--md-sys-typescale-headline-small);
  letter-spacing: var(--md-sys-typescale-headline-small-tracking);
}
.m3-dialog__body {
  margin: 0 0 var(--md-sys-spacing-6);
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
}
.m3-dialog__error {
  margin: 0 0 var(--md-sys-spacing-4);
  font: var(--md-sys-typescale-body-small);
  letter-spacing: var(--md-sys-typescale-body-small-tracking);
  color: var(--md-sys-color-error);
}
.m3-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--md-sys-spacing-2);
  flex-wrap: wrap;
}

/* ==========================================================================
   16. Snackbar
   ========================================================================== */
.m3-snackbar-host {
  position: fixed;
  left: var(--md-sys-spacing-4);
  right: var(--md-sys-spacing-4);
  bottom: calc(var(--app-nav-bar-height) + var(--safe-bottom) + var(--md-sys-spacing-4));
  z-index: 40;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.m3-snackbar-host--flush {
  bottom: calc(var(--md-sys-spacing-4) + var(--safe-bottom));
}
/* ≥600px the bottom bar is gone (the rail replaces it) — stop reserving 80px
   of empty space under the snackbar. */
@media (min-width: 600px) {
  .m3-snackbar-host { bottom: calc(var(--md-sys-spacing-4) + var(--safe-bottom)); }
}
.m3-snackbar {
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-2);
  pointer-events: auto;
  min-height: 48px;
  padding: var(--md-sys-spacing-1) var(--md-sys-spacing-2) var(--md-sys-spacing-1) var(--md-sys-spacing-4);
  max-width: 560px;
  width: 100%;
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  box-shadow: var(--md-sys-elevation-shadow-3);
  animation: m3-snack-in var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-emphasized-decelerate);
}
@keyframes m3-snack-in { from { translate: 0 8px; opacity: 0; } to { translate: 0 0; opacity: 1; } }
.m3-snackbar__text {
  flex: 1;
  min-width: 0;
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
}
.m3-snackbar__action { color: var(--md-sys-color-inverse-primary); }

/* ==========================================================================
   17. Progress indicators & skeletons
   ========================================================================== */
.m3-circular {
  display: inline-block;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 4px solid color-mix(in srgb, var(--md-sys-color-primary) 20%, transparent);
  border-top-color: var(--md-sys-color-primary);
  animation: m3-rotate 1s linear infinite;
}
.m3-circular--sm { width: 18px; height: 18px; border-width: 2.5px; }
.m3-circular--on-filled {
  border-color: color-mix(in srgb, var(--md-sys-color-on-primary) 30%, transparent);
  border-top-color: var(--md-sys-color-on-primary);
}
.m3-circular--on-tonal {
  border-color: color-mix(in srgb, var(--md-sys-color-on-secondary-container) 30%, transparent);
  border-top-color: var(--md-sys-color-on-secondary-container);
}
.m3-circular--on-disabled {
  border-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  border-top-color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
}
@keyframes m3-rotate { to { rotate: 360deg; } }

.m3-linear {
  height: 4px;
  overflow: hidden;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: 2px;
}
.m3-linear__bar {
  height: 100%;
  width: 40%;
  border-radius: 2px;
  background: var(--md-sys-color-primary);
  animation: m3-linear-slide 1.2s var(--md-sys-motion-easing-standard) infinite;
}
@keyframes m3-linear-slide { from { translate: -110% 0; } to { translate: 260% 0; } }

.m3-track {
  height: 8px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  overflow: hidden;
}
.m3-track--thin { height: 4px; }
.m3-track__fill {
  height: 100%;
  border-radius: inherit;
  background: var(--cat-color, var(--md-sys-color-primary));
  transition: width var(--md-sys-motion-duration-long2) var(--md-sys-motion-easing-emphasized-decelerate);
}

.m3-skeleton {
  border-radius: var(--md-sys-shape-corner-medium);
  background: linear-gradient(
    90deg,
    var(--md-sys-color-surface-container) 25%,
    var(--md-sys-color-surface-container-high) 50%,
    var(--md-sys-color-surface-container) 75%
  );
  background-size: 200% 100%;
  animation: m3-shimmer 1.4s ease-in-out infinite;
}
.m3-skeleton--text { height: 16px; border-radius: var(--md-sys-shape-corner-extra-small); }
.m3-skeleton--line { height: 12px; border-radius: var(--md-sys-shape-corner-extra-small); }
.m3-skeleton--circle { border-radius: 50%; }
.m3-skeleton--row { height: 56px; }
.m3-skeleton--hero { height: 120px; border-radius: var(--md-sys-shape-corner-large); }
.m3-skeleton-stack { display: flex; flex-direction: column; gap: var(--md-sys-spacing-2); }
@keyframes m3-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Dimmed refetch state (kept content, 38% until new data lands) */
.m3-refetching { opacity: 0.38; transition: opacity var(--md-sys-motion-duration-short2) linear; }

/* ==========================================================================
   18. Switch
   ========================================================================== */
.m3-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  gap: var(--md-sys-spacing-4);
  cursor: pointer;
}
.m3-switch-row__label {
  font: var(--md-sys-typescale-body-large);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
}
.m3-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 32px;
  flex-shrink: 0;
}
.m3-switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}
.m3-switch__track {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  border: 2px solid var(--md-sys-color-outline);
  box-sizing: border-box;
  transition:
    background-color var(--md-sys-motion-duration-short4) linear,
    border-color var(--md-sys-motion-duration-short4) linear;
}
.m3-switch__handle {
  position: absolute;
  left: 6px;
  top: 50%;
  translate: 0 -50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--md-sys-color-outline);
  transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}
.m3-switch input:checked + .m3-switch__track {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}
.m3-switch input:checked + .m3-switch__track .m3-switch__handle {
  left: 24px;
  width: 24px;
  height: 24px;
  background: var(--md-sys-color-on-primary);
}
.m3-switch input:focus-visible + .m3-switch__track {
  outline: 3px solid var(--md-sys-color-secondary);
  outline-offset: 2px;
}
.m3-switch input:disabled + .m3-switch__track { opacity: 0.38; cursor: not-allowed; }

/* ==========================================================================
   19. Category avatar & badges
   ========================================================================== */
.m3-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  font-size: 20px;
  line-height: 1;
  border-radius: var(--md-sys-shape-corner-full);
  background: color-mix(
    in srgb,
    var(--cat-color, var(--md-sys-color-primary)) 18%,
    var(--md-sys-color-surface-container-high)
  );
}
.m3-avatar--lg { width: 48px; height: 48px; font-size: 24px; }
.m3-avatar--sq { border-radius: var(--md-sys-shape-corner-medium); }

.m3-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--md-sys-spacing-1);
  height: 20px;
  padding: 0 var(--md-sys-spacing-2);
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-small);
  letter-spacing: var(--md-sys-typescale-label-small-tracking);
  white-space: nowrap;
}
.m3-badge--tertiary {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}
.m3-badge--primary {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}
.m3-badge--error {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
  min-width: 16px;
  height: 16px;
  padding: 0 var(--md-sys-spacing-1);
  justify-content: center;
}
.m3-badge--dot {
  width: 8px;
  height: 8px;
  min-width: 0;
  padding: 0;
  background: var(--md-sys-color-error);
}

/* Legend dot for chart legends */
.m3-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--cat-color, var(--md-sys-color-primary));
}

/* ==========================================================================
   20. Banners & empty states
   ========================================================================== */
.m3-banner {
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-2);
  padding: var(--md-sys-spacing-2) var(--md-sys-spacing-2) var(--md-sys-spacing-2) var(--md-sys-spacing-4);
  border-radius: var(--md-sys-shape-corner-medium);
}
.m3-banner--error {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}
.m3-banner--warning {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}
.m3-banner__text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
}

/* Empty state — one component for guest / no data / no match / error */
.m3-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--md-sys-spacing-2);
  min-height: 40dvh;
  max-width: 360px;
  margin-inline: auto;
  padding: var(--md-sys-spacing-6);
}
.m3-empty__glyph {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  margin-bottom: var(--md-sys-spacing-1);
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 48px;
  line-height: 1;
}
.m3-empty__glyph svg { width: 48px; height: 48px; }
.m3-empty__title {
  margin: 0;
  font: var(--md-sys-typescale-title-medium);
  letter-spacing: var(--md-sys-typescale-title-medium-tracking);
  color: var(--md-sys-color-on-surface);
}
.m3-empty__text {
  margin: 0;
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
}
.m3-empty__action { margin-top: var(--md-sys-spacing-3); }

/* ==========================================================================
   21. Data table
   ========================================================================== */
.m3-table-wrap {
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.m3-table-wrap::-webkit-scrollbar { display: none; }
.m3-table {
  width: 100%;
  border-collapse: collapse;
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
}
.m3-table th {
  text-align: left;
  padding: var(--md-sys-spacing-3) var(--md-sys-spacing-2);
  font: var(--md-sys-typescale-label-medium);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  white-space: nowrap;
}
.m3-table td {
  padding: var(--md-sys-spacing-3) var(--md-sys-spacing-2);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
}
.m3-table tr:last-child td { border-bottom: none; }
.m3-table__num { text-align: right; white-space: nowrap; }

/* ==========================================================================
   23. Month navigator (index top bar title slot)
   ========================================================================== */
.m3-month-nav {
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-1);
  flex: 1;
  min-width: 0;
  justify-content: center;
}
.m3-month-nav__label {
  min-width: 140px;
  text-align: center;
  font: var(--md-sys-typescale-title-large);
  letter-spacing: var(--md-sys-typescale-title-large-tracking);
  color: var(--md-sys-color-on-surface);
}

/* ==========================================================================
   Extras the five screens need
   ========================================================================== */

/* Chart canvas wrapper — the canvas must be able to shrink inside a card */
.m3-chart {
  position: relative;
  width: 100%;
  height: 180px;
  min-width: 0;
}
.m3-chart--donut { height: 160px; }
.m3-chart--line { height: 200px; }
.m3-chart canvas { display: block; }
/* Label parked in the hole of a doughnut. */
.m3-chart__center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  text-align: center;
}
.m3-chart__center > * { display: block; }

/* Donut / category legend rows */
.m3-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--md-sys-spacing-3);
}
.m3-legend__row { display: flex; flex-direction: column; gap: var(--md-sys-spacing-1); }
.m3-legend__head {
  display: flex;
  align-items: center;
  gap: var(--md-sys-spacing-2);
  min-width: 0;
}
.m3-legend__label {
  flex: 1;
  min-width: 0;
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  color: var(--md-sys-color-on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m3-legend__value {
  flex-shrink: 0;
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  color: var(--md-sys-color-on-surface-variant);
}

/* Sticky form action bar (expense-form) — sticky, never fixed: a fixed bar
   floats over the Android soft keyboard. */
.m3-form-actions {
  position: sticky;
  bottom: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: var(--md-sys-spacing-2);
  margin-inline: calc(-1 * var(--app-margin));
  padding: var(--md-sys-spacing-3) var(--app-margin)
           calc(var(--md-sys-spacing-3) + var(--safe-bottom));
  background: var(--md-sys-color-surface);
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* Rendered AI markdown body (output of Ui.renderAiMarkdown) */
.m3-ai-body {
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface);
}
.m3-ai-body p { margin: 0 0 var(--md-sys-spacing-2); }
.m3-ai-body p:last-child { margin-bottom: 0; }
.m3-ai-body ul { margin: 0 0 var(--md-sys-spacing-2); padding-left: 20px; }
.m3-ai-body li { margin: 0 0 var(--md-sys-spacing-1); }
.m3-ai-body strong { font-weight: 700; }

/* Headline figure with an overline — the stats summary card.
   .m3-stat__value carries the headline-medium role the type scale has no
   utility for; .m3-num must sit on the nested <span>, because the `font:`
   shorthand here resets font-variant-numeric. */
.m3-stat-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--md-sys-spacing-4);
}
.m3-stat { min-width: 0; }
.m3-stat--end { flex-shrink: 0; text-align: right; }
.m3-stat__value {
  margin: 0;
  font: var(--md-sys-typescale-headline-medium);
  letter-spacing: var(--md-sys-typescale-headline-medium-tracking);
  color: var(--md-sys-color-on-surface);
  overflow-wrap: anywhere;
}

/* Two-line trailing slot: amount over share. The single-line type token on
   .m3-list-item__trailing cannot carry both. */
.m3-list-item__trailing--stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

/* Section heading row outside cards («Последние траты» + «Все →») */
.m3-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--md-sys-spacing-2);
}
.m3-section-head__title {
  margin: 0;
  font: var(--md-sys-typescale-title-small);
  letter-spacing: var(--md-sys-typescale-title-small-tracking);
  color: var(--md-sys-color-on-surface);
}

/* One-line ellipsis inside a table cell / tight row */
.m3-truncate {
  display: inline-block;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* Small helper note («Показаны последние 500 трат…») */
.m3-note {
  margin: 0;
  font: var(--md-sys-typescale-body-small);
  letter-spacing: var(--md-sys-typescale-body-small-tracking);
  color: var(--md-sys-color-on-surface-variant);
}
.m3-note--error { color: var(--md-sys-color-error); }

/* ==========================================================================
   Utilities — declared LAST on purpose.
   The `font:` shorthand used by every component resets font-variant-numeric,
   so .m3-num must win the cascade by source order.
   ========================================================================== */
.m3-num {
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

.m3-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
