/* Moneva components (BEM-ish). Documented in docs/DESIGN_SYSTEM.md; the round-7 contract
 * (docs/DESIGN-DIRECTION.md §3) lives at the end of this file and restyles what came before. */

/* Page header & sections --------------------------------------------- */

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.page-header__title { font-family: var(--font-display); font-size: var(--text-title); line-height: var(--leading-title); font-weight: var(--weight-display); letter-spacing: var(--tracking-tight); }
.page-header__subtitle { color: var(--color-text-muted); margin-top: var(--space-1); }

.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.section { margin-bottom: var(--space-5); }

.section__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.section__title { font-family: var(--font-display); font-size: var(--text-heading); line-height: var(--leading-heading); font-weight: var(--weight-display); letter-spacing: var(--tracking-tight); }
.section__subtitle { font-size: var(--text-sm); color: var(--color-text-muted); }

.section__action {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 32px;
}

/* Card ---------------------------------------------------------------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--card-padding);
  box-shadow: var(--shadow-card);
}

.card--flush { padding: 0; overflow: hidden; }

.card--accent { border-color: var(--color-border); }

/* The navy summary card (screen 1): flat navy surface, white text, figures in the dark palette.
 * .card--hero and .hero--brand are the older names for the same thing. The card owns its text
 * colours: headings (base.css sets h1–h4 to --color-text), muted lines, ring percentages,
 * progress values and meta rows all read the re-scoped tokens, so they stay readable on navy in
 * both themes. The fixed hero tokens live in tokens.css. */
.summary-card,
.hero--brand,
.card--hero {
  --color-text: var(--color-hero-text);
  --color-text-muted: var(--color-hero-text-muted);
  --color-text-subtle: var(--color-hero-text-subtle);
  --color-border: var(--color-hero-border);
  --color-border-strong: var(--color-hero-text-subtle);
  --color-surface-sunken: var(--color-hero-surface);
  --color-neutral-soft: var(--color-hero-surface);
  --color-primary-text: var(--color-hero-primary);
  --color-success: var(--color-hero-success);
  --color-success-bright: var(--color-hero-success);
  --color-warning: var(--color-hero-warning);
  --color-warning-bright: var(--color-hero-warning);
  --color-danger: var(--color-hero-danger);
  --color-danger-bright: var(--color-hero-danger);
  --color-teal: var(--color-hero-teal);
  --color-money-positive: var(--color-hero-success);
  --color-money-negative: var(--color-hero-text);
  color: var(--color-hero-text);
  background: var(--color-hero-bg);
  background-image: linear-gradient(135deg, var(--color-hero-bg) 0%, var(--color-hero-bg-end) 100%);
  border: 1px solid transparent;
  border-radius: var(--radius-xl);
  padding: var(--card-padding);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}

:is(.summary-card, .hero--brand, .card--hero) > * { position: relative; }
:is(.summary-card, .hero--brand, .card--hero) a:not([class]) { color: inherit; text-decoration: underline; }
.card--hero .button--ghost { --button-fg: var(--color-hero-text); --button-border: var(--color-hero-border); }
:is(.summary-card, .hero--brand) .button--ghost { --button-fg: var(--color-hero-text); --button-border: var(--color-hero-border); }
:is(.summary-card, .hero--brand, .card--hero) .button--ghost:hover { background: var(--overlay-light); }
:is(.summary-card, .hero--brand, .card--hero) .button--secondary { --button-bg: var(--overlay-light); --button-fg: var(--color-hero-text); --button-border: var(--color-hero-border); }
:is(.summary-card, .hero--brand, .card--hero) .button--secondary:hover { background: var(--color-hero-border); }
:is(.summary-card, .hero--brand, .card--hero) .chip { background: var(--color-hero-surface); color: var(--color-hero-text); }
:is(.summary-card, .hero--brand, .card--hero) .progress { background: var(--color-hero-border); }
:is(.summary-card, .hero--brand, .card--hero) .progress__marker { box-shadow: 0 0 0 1px var(--color-hero-bg); }

/* The hero card keeps its blue in the dark theme too (the identity colour, white text 5.2:1);
 * a faint hairline separates it from the dark ground. */
html[data-resolved-theme="dark"] :is(.summary-card, .hero--brand, .card--hero) {
  border-color: var(--color-hero-border);
}

/* Surfaces nested inside the card paint their own light background: give them the page tokens back. */
.summary-card :is(.stat, .banner, .challenge-progress, .list, .table-wrap, .card),
.hero--brand :is(.stat, .banner, .challenge-progress, .list, .table-wrap, .card),
.card--hero :is(.stat, .banner, .challenge-progress, .list, .table-wrap, .card) {
  --color-text: var(--color-on-surface);
  --color-text-muted: var(--color-on-surface-muted);
  --color-text-subtle: var(--color-on-surface-subtle);
  --color-border: var(--color-on-surface-border);
  --color-border-strong: var(--color-on-surface-border);
  --color-primary-text: var(--color-on-surface-primary);
  --color-success: var(--color-on-surface-success);
  --color-warning: var(--color-on-surface-warning);
  --color-danger: var(--color-on-surface-danger);
  color: var(--color-text);
}

.card--interactive {
  transition: box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease), border-color var(--duration);
  color: inherit;
  display: block;
}

.card--interactive:hover {
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  border-color: var(--color-border-strong);
  transform: translateY(-1px);
}

.card__title {
  font-family: var(--font-display);
  font-size: var(--text-heading);
  line-height: var(--leading-heading);
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-1);
}

.card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.card__body > * + * { margin-top: var(--space-3); }

.card__footer {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: space-between;
}

.card--flush .card__header,
.card--flush .card__footer { padding: var(--card-padding); margin: 0; }

/* Buttons ------------------------------------------------------------- */

.button {
  --button-bg: var(--color-surface);
  --button-fg: var(--color-text);
  --button-border: var(--color-border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: 0 var(--space-4);
  border: 1px solid var(--button-border);
  border-radius: var(--radius-md);
  background: var(--button-bg);
  color: var(--button-fg);
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  position: relative;
  transition: background var(--duration-fast), border-color var(--duration-fast), transform var(--duration-fast), opacity var(--duration-fast);
  user-select: none;
}

.button:hover { text-decoration: none; background: var(--color-surface-sunken); }
.button:active { transform: translateY(1px); }

.button:disabled,
.button[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }

.button--primary {
  --button-bg: var(--color-primary);
  --button-fg: var(--color-text-on-primary);
  --button-border: var(--color-primary);
}

.button--primary:hover {
  --button-bg: var(--color-primary-hover);
  --button-border: var(--color-primary-hover);
  background: var(--color-primary-hover);
}

/* Secondary: white with a 1px border (the design's second button). */
.button--secondary {
  --button-bg: var(--color-surface);
  --button-fg: var(--color-text);
  --button-border: var(--color-border-strong);
}

.button--secondary:hover { background: var(--color-surface-sunken); }

/* Soft: the old tinted secondary, for pages that still want it. */
.button--soft {
  --button-bg: var(--color-primary-soft);
  --button-fg: var(--color-primary-soft-text);
  --button-border: transparent;
}

.button--soft:hover { background: var(--color-primary-soft); filter: brightness(0.96); }

/* Text buttons: ghost (primary text) and danger text ("Remove" with a trash icon). */
.button--ghost,
.button--text {
  --button-bg: transparent;
  --button-border: transparent;
  --button-fg: var(--color-primary-text);
}

.button--ghost:hover,
.button--text:hover { background: var(--color-primary-soft); }

.button--danger {
  --button-bg: var(--color-danger);
  --button-fg: var(--color-text-on-danger);
  --button-border: var(--color-danger);
}

.button--danger:hover { background: var(--color-danger); filter: brightness(0.92); }

.button--danger-ghost,
.button--danger-text {
  --button-bg: transparent;
  --button-border: transparent;
  --button-fg: var(--color-danger);
}

.button--danger-ghost:hover,
.button--danger-text:hover { background: var(--color-danger-soft); }

.button--sm {
  min-height: var(--control-sm);
  padding-inline: var(--space-3);
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
}

.button--block { display: flex; width: 100%; }

/* Block on phones, inline from 640px (the design's primary actions). */
.button--block-phone { display: flex; width: 100%; }

@media (min-width: 640px) {
  .button--block-phone { display: inline-flex; width: auto; }
}

.button.is-loading { color: transparent !important; pointer-events: none; }

.button.is-loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-color: var(--button-fg) var(--button-fg) transparent;
  animation: um-spin 0.7s linear infinite;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  background: transparent;
  border: 0;
  position: relative;
  flex-shrink: 0;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.icon-button:hover {
  background: var(--color-surface-sunken);
  color: var(--color-text);
  text-decoration: none;
}

.icon-button--sm { width: 36px; height: 36px; }
.icon-button--badge { position: relative; } /* anchors .icon-button__dot */
.icon-button--outline { border: 1px solid var(--color-border); background: var(--color-surface); }

.icon-button__dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-danger-bright);
  border: 2px solid var(--color-surface);
}

/* Stat tiles ---------------------------------------------------------- */

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--card-padding);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  min-width: 0;
  color: inherit;
}

a.stat:hover {
  text-decoration: none;
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-sm);
}

.stat--compact { padding: var(--space-3); }

.stat__label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.stat__value {
  /* Title size from 440px up, shrinking with the viewport so a seven-digit amount fits a 2-up
   * tile on a 360px phone; wraps only between the currency code and the number. */
  font-size: clamp(var(--text-heading), 5vw, var(--text-title));
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-tight);
  white-space: normal;
  overflow-wrap: normal;
}

.stat--compact .stat__value { font-size: var(--text-xl); }
.stat__meta { font-size: var(--text-sm); color: var(--color-text-muted); }

.stat--success .stat__value,
.stat__meta--success { color: var(--color-success); }

.stat--danger .stat__value,
.stat__meta--danger { color: var(--color-danger); }

.stat--warning .stat__value,
.stat__meta--warning { color: var(--color-warning); }
.stat--info .stat__value { color: var(--color-info); }

.stat__icon { color: var(--color-primary-text); }

/* Progress ------------------------------------------------------------ */

.progress {
  --progress-color: var(--color-primary);
  position: relative;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-neutral-soft);
  overflow: hidden;
  width: 100%;
}

.progress--sm { height: 4px; }
.progress--lg { height: 10px; }

.progress--success { --progress-color: var(--color-success-bright); }
.progress--warning { --progress-color: var(--color-warning-bright); }

.progress--over,
.progress--danger { --progress-color: var(--color-danger-bright); }
.progress--accent { --progress-color: var(--color-accent); }

.progress__bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  background: var(--progress-color);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}

.progress__bar--committed {
  background-color: var(--progress-color);
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0 4px,
    var(--overlay-stripe) 4px 8px
  );
  opacity: 0.85;
}

.progress__bar--pending {
  background: transparent;
  border: 2px dashed var(--progress-color);
  opacity: 0.7;
}

.progress--over .progress__bar { width: 100% !important; }

/* Progress row (screen 1): name left, "RWF 95,000 of 180,000" right, 6px bar, one-line status
 * in the semantic colour. The older form (bar + percentage) still works: when the bar comes
 * first it takes the first column and the value sits beside it. */
.progress-row {
  display: grid;
  /* The name keeps at least 45%: on a 320px phone the amounts wrap at " of " instead. */
  grid-template-columns: minmax(45%, 1fr) auto;
  align-items: center;
  gap: var(--space-1) var(--space-3);
}

.progress-row + .progress-row { margin-top: var(--space-3); }
.progress-row .progress { grid-column: 1 / -1; }
.progress-row > .progress:first-child { grid-column: 1; }

.progress-row__name {
  min-width: 0;
  font-weight: var(--weight-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-row__amounts {
  font-size: var(--text-label);
  line-height: var(--leading-label);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: normal;
  overflow-wrap: normal;
  text-align: right;
}

.progress-row__amounts .money { white-space: nowrap; } /* each amount stays whole; wraps at " of " */
.progress-row__amounts strong { color: var(--color-text); font-weight: var(--weight-display); }

.progress-row__value {
  font-size: var(--text-label);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  min-width: 3ch;
  text-align: right;
}

.progress-row__status {
  grid-column: 1 / -1;
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.progress-row__status--success,
.progress-row__status--ok { color: var(--color-success); }
.progress-row__status--warning,
.progress-row__status--near,
.progress-row__status--at_risk { color: var(--color-warning); }
.progress-row__status--danger,
.progress-row__status--over { color: var(--color-danger); }

/* Period marker: a tick at X% of the bar ("55% of the period gone"). Full-strength text colour
 * with a one-pixel surface halo, so it reads on the green/amber fill as well as on the track. */
.progress__marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  left: var(--marker, 0%);
  background: var(--color-text);
  box-shadow: 0 0 0 1px var(--color-surface);
  border-radius: 1px;
}

/* Chips & badges ------------------------------------------------------ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-full);
  background: var(--color-neutral-soft);
  color: var(--color-neutral-soft-text);
  font-size: var(--text-caption);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  line-height: 1;
  vertical-align: middle;
}

.chip .icon { width: 14px; height: 14px; }
.chip--sm { min-height: 20px; padding-inline: 6px; }

.chip--success { background: var(--color-success-soft); color: var(--color-success-soft-text); }
.chip--warning { background: var(--color-warning-soft); color: var(--color-warning-soft-text); }

.chip--danger { background: var(--color-danger-soft); color: var(--color-danger-soft-text); }
.chip--info { background: var(--color-info-soft); color: var(--color-info-soft-text); }

.chip--primary { background: var(--color-primary-soft); color: var(--color-primary-soft-text); }
.chip--accent { background: var(--color-accent-soft); color: var(--color-accent-soft-text); }

.chip--neutral { background: var(--color-neutral-soft); color: var(--color-neutral-soft-text); }
.chip--teal { background: var(--color-teal-soft); color: var(--color-teal-soft-text); }

/* Status chips (screen 1): Active green soft · Draft neutral · Completed primary soft · Upcoming
 * teal soft · Needs attention amber soft · Over plan red soft · Shared teal (with a people icon). */
.chip--active { background: var(--color-success-soft); color: var(--color-success-soft-text); }
.chip--draft { background: var(--color-neutral-soft); color: var(--color-neutral-soft-text); }
.chip--completed { background: var(--color-primary-soft); color: var(--color-primary-soft-text); }
.chip--upcoming { background: var(--color-teal-soft); color: var(--color-teal-soft-text); }
.chip--attention { background: var(--color-warning-soft); color: var(--color-warning-soft-text); }
.chip--over { background: var(--color-danger-soft); color: var(--color-danger-soft-text); }
.chip--shared { background: var(--color-teal-soft); color: var(--color-teal-soft-text); }

.chip--outline {
  background: transparent;
  border: 1px solid var(--color-border-strong);
  color: var(--color-text-muted);
}

a.chip,
button.chip {
  cursor: pointer;
  min-height: var(--control-sm);
  padding-inline: var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

a.chip:hover,
button.chip:hover { text-decoration: none; border-color: var(--color-border-strong); }

a.chip.is-active,
button.chip.is-active {
  background: var(--color-text);
  border-color: var(--color-text);
  color: var(--color-text-inverse);
}

.badge-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-subtle);
  flex-shrink: 0;
}

.badge-dot--success { background: var(--color-success-bright); }
.badge-dot--warning { background: var(--color-warning-bright); }
.badge-dot--danger { background: var(--color-danger-bright); }
.badge-dot--info { background: var(--color-info-bright); }
.badge-dot--primary { background: var(--color-primary); }

/* Lists --------------------------------------------------------------- */

.list {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--card-padding);
  min-height: 56px;
  color: inherit;
  text-decoration: none;
  position: relative;
}

.list-item + .list-item { border-top: 1px solid var(--color-border); }

a.list-item:hover,
button.list-item:hover,
.list-item--interactive:hover { background: var(--color-surface-sunken); text-decoration: none; }
.list-item--align-start { align-items: flex-start; }

.list-item__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
  flex-shrink: 0;
}

.list-item__icon--round { border-radius: var(--radius-full); }
.list-item__body { flex: 1 1 auto; min-width: 0; }

.list-item__title {
  display: block; /* inline boxes never truncate: the title would overflow into the trailing amount */
  font-weight: var(--weight-medium);
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item__meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 var(--space-2);
}

.list-item__trailing {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
  text-align: right;
}

.list-item__chevron { color: var(--color-text-subtle); flex-shrink: 0; }

/* Table --------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.table { width: 100%; font-size: var(--text-sm); }

.table th,
.table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--color-border);
}

.table thead th {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  background: var(--color-surface-sunken);
  white-space: nowrap;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--color-surface-sunken); }

.table td.is-numeric,
.table th.is-numeric,
.table .money {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table tfoot td { font-weight: var(--weight-semibold); background: var(--color-surface-sunken); }

.table--dense th,
.table--dense td { padding: var(--space-2) var(--space-3); }

@media (max-width: 639.98px) {
  .table--responsive thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .table--responsive tr {
    display: block;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
  }

  .table--responsive tbody tr:last-child { border-bottom: 0; }

  .table--responsive td {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-1) var(--space-4);
    border: 0;
    text-align: right;
  }

  .table--responsive td::before {
    content: attr(data-label);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    text-align: left;
    flex-shrink: 0;
  }

  .table--responsive td[data-label=""]::before,
  .table--responsive td:not([data-label])::before { display: none; }
}

/* Tabs & segmented ---------------------------------------------------- */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  scrollbar-width: none;
  margin-bottom: var(--space-4);
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: 0 var(--space-3);
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  white-space: nowrap;
  background: none;
  text-decoration: none;
}

.tab:hover { color: var(--color-text); text-decoration: none; }

.tab.is-active,
.tab[aria-selected="true"] { color: var(--color-primary-text); border-bottom-color: var(--color-primary); font-weight: var(--weight-semibold); }

.tab__count {
  font-size: var(--text-xs);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--color-neutral-soft);
}

[role="tabpanel"][hidden] { display: none; }

/* Segmented control: pill track, active item white. */
.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-full);
  background: var(--color-neutral-soft);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.segmented::-webkit-scrollbar { display: none; }

.segmented--block { display: flex; }
.segmented--block > * { flex: 1 1 0; }

.segmented__item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: var(--control-sm);
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  text-decoration: none;
  border: 0;
  background: transparent;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.segmented__item:hover { color: var(--color-text); text-decoration: none; }

.segmented__item.is-active,
.segmented__item[aria-current],
.segmented__item[aria-pressed="true"] {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

/* Forms --------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.field:last-child { margin-bottom: 0; }

.field__label,
.field__fieldset > legend {
  font-size: var(--text-label);
  line-height: var(--leading-label);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}

.field__optional {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  color: var(--color-text-subtle);
}

.field__fieldset {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}

.field__fieldset > legend { padding: 0; margin-bottom: var(--space-2); }
.field__control { position: relative; }

.field__help { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }

.field__errors {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-danger);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.field__errors li::before { content: "• "; }

/* Fields: 44px, radius 12, a 1px border and a 3px primary ring on focus; a sunken fill in the
 * dark theme (--color-field-bg) so a field reads as a field on a dark card. */
.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-field-border);
  border-radius: var(--radius-md);
  background: var(--color-field-bg);
  color: var(--color-text);
  font-size: 16px; /* prevents iOS zoom */
  line-height: 1.4;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast), background var(--duration-fast);
  appearance: none;
  -webkit-appearance: none;
}

.input:hover:not(:disabled):not([readonly]),
.select:hover:not(:disabled),
.textarea:hover:not(:disabled) { border-color: var(--color-border-strong); }

.input::placeholder,
.textarea::placeholder { color: var(--color-text-subtle); }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-focus);
}

.input:disabled,
.select:disabled,
.textarea:disabled { background-color: var(--color-surface-sunken); color: var(--color-text-subtle); }
/* background-color, not the shorthand: the shorthand dropped the select's chevron sizing and the
   dark theme's chevron image then tiled across a locked select. */
.input[readonly] { background: var(--color-surface-sunken); }

.field--invalid .input,
.field--invalid .select,
.field--invalid .textarea,
.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] { border-color: var(--color-danger); }

.field--invalid .input:focus,
.field--invalid .select:focus,
.field--invalid .textarea:focus,
.input[aria-invalid="true"]:focus,
.select[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus { border-color: var(--color-danger); box-shadow: 0 0 0 3px var(--color-danger-soft); }
.input--sm { min-height: 36px; padding-block: var(--space-1); }

.input--money {
  font-variant-numeric: tabular-nums;
  font-feature-settings: var(--font-features-numeric);
  text-align: right;
  font-weight: var(--weight-medium);
}

.select {
  padding-right: var(--space-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235A6577' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
}

.select[multiple] {
  background-image: none;
  padding-right: var(--space-3);
  min-height: 120px;
}

html[data-resolved-theme="dark"] .select:not([multiple]) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

.textarea { min-height: 112px; resize: vertical; }
.field__control--prefix .input { padding-left: calc(var(--space-3) + 3.6ch); }
.field__control--suffix .input { padding-right: calc(var(--space-3) + 3.6ch); }

/* Prefix / suffix (currency code, unit): vertically centred, tabular, never in the way. */
.field__prefix,
.field__suffix {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  pointer-events: none;
}

.field__suffix { left: auto; right: var(--space-3); }

.field__control--icon .icon {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-subtle);
  pointer-events: none;
}

.field__check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-height: var(--touch-target);
  padding: var(--space-2) 0;
  cursor: pointer;
  font-size: var(--text-sm);
}

/* The label is a normal inline-flow block, so a consent line that mixes text and links stays one
 * paragraph; a .field__help inside it drops to its own line underneath. */
.field__check-label {
  display: block;
  min-width: 0;
  padding-top: 2px;
}

.field__check-label > .field__help,
.field__check-label > .field__check-help { display: block; margin-top: 2px; }

.checkbox,
.choice-list input[type="checkbox"],
.choice-list input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin: 0;
  border: 2px solid var(--color-border-strong);
  border-radius: 6px;
  background: var(--color-surface);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast);
}

.choice-list input[type="radio"] { border-radius: 50%; }

.checkbox::before,
.choice-list input::before {
  content: "";
  width: 12px;
  height: 12px;
  transform: scale(0);
  transition: transform var(--duration-fast) var(--ease-spring);
  background: var(--color-text-on-primary);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.choice-list input[type="radio"]::before {
  clip-path: none;
  border-radius: 50%;
  width: 10px;
  height: 10px;
}

.checkbox:checked,
.choice-list input:checked { background: var(--color-primary); border-color: var(--color-primary); }

.checkbox:checked::before,
.choice-list input:checked::before { transform: scale(1); }

.checkbox:focus-visible,
.choice-list input:focus-visible { outline: 3px solid var(--color-border-focus); outline-offset: 2px; }

.choice-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: 0;
  margin: 0;
  list-style: none;
}

.choice-list > div,
.choice-list > li { display: block; }

.choice-list label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  font-size: var(--text-sm);
}

.choice-list label:has(input:checked) { border-color: var(--color-primary); background: var(--color-primary-soft); }

.file-input {
  display: block;
  width: 100%;
  padding: var(--space-3);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  font-size: var(--text-sm);
  cursor: pointer;
}

.file-input::file-selector-button {
  font: inherit;
  margin-right: var(--space-3);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

.file-input__preview {
  margin-top: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.file-input__preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.file-input__current {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.field--money .input--money,
.amount-input { font-variant-numeric: tabular-nums; }

.amount-input {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-3) 0;
}

.amount-input__currency {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
}

.amount-input .input,
.amount-input__field {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  border-bottom: 2px solid var(--color-border);
  border-radius: 0;
  padding: 0;
  font-size: var(--text-display);
  line-height: var(--leading-display);
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-tight);
  text-align: left;
  background: transparent;
  min-height: 60px;
}

.amount-input .input:focus { box-shadow: none; border-bottom-color: var(--color-primary); }

.form-errors {
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-danger-soft);
  color: var(--color-danger-soft-text);
  border: 1px solid color-mix(in srgb, var(--color-danger) 30%, transparent);
  font-size: var(--text-sm);
}

.form-errors__title { font-weight: var(--weight-semibold); margin-bottom: var(--space-1); }
.form-errors ul { padding-left: var(--space-5); list-style: disc; }

.form-errors a { color: inherit; text-decoration: underline; }
.form-row { display: grid; gap: var(--space-3); }

@media (min-width: 640px) {
  .form-row { grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); }
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-6);
}

/* Banners & toasts ---------------------------------------------------- */

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-neutral-soft);
  color: var(--color-neutral-soft-text);
  font-size: var(--text-sm);
}

.banner > .icon { flex-shrink: 0; margin-top: 2px; }

.banner a {
  color: inherit;
  text-decoration: underline;
  font-weight: var(--weight-medium);
}

.banner--info { background: var(--color-info-soft); color: var(--color-info-soft-text); }
.banner--warning { background: var(--color-warning-soft); color: var(--color-warning-soft-text); }
.banner--danger { background: var(--color-danger-soft); color: var(--color-danger-soft-text); }
.banner--success { background: var(--color-success-soft); color: var(--color-success-soft-text); }
.banner__body { flex: 1 1 auto; }

.banner__actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.toast-region {
  position: fixed;
  z-index: var(--z-toast);
  left: 50%;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + var(--space-3));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(100% - 2 * var(--space-4), 420px);
  pointer-events: none;
}

@media (min-width: 900px) {
  .toast-region {
    left: auto;
    right: var(--space-6);
    bottom: var(--space-6);
    transform: none;
  }
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-hero-bg);
  color: var(--color-hero-text);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: um-toast-in var(--duration-slow) var(--ease-out);
}

html[data-resolved-theme="dark"] .toast {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-strong);
  color: var(--color-text);
}

.toast > .icon { flex-shrink: 0; }

.toast > span,
.toast__body { flex: 1 1 auto; }
.toast--success > .icon { color: var(--color-hero-success); }
.toast--error > .icon,
.toast--danger > .icon { color: var(--color-hero-danger); }
.toast--warning > .icon { color: var(--color-hero-warning); }
.toast--info > .icon { color: var(--color-hero-primary); }

.toast__close {
  width: 32px;
  height: 32px;
  color: inherit;
  opacity: 0.7;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.toast__close:hover { opacity: 1; background: var(--overlay-light); }

.toast__action {
  color: inherit;
  font-weight: var(--weight-semibold);
  text-decoration: underline;
  white-space: nowrap;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

.toast.is-leaving { animation: um-toast-out var(--duration) var(--ease) forwards; }

@keyframes um-toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes um-toast-out {
  to { opacity: 0; transform: translateY(8px); }
}

/* Sheet (bottom sheet on mobile, centred dialog on desktop) ----------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: var(--color-surface-overlay);
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

/* The panel is a flex column capped at the viewport: the body (flex: 1, min-height 0) is the
 * only part that scrolls. The vh line is the fallback for browsers without dvh (Chrome < 108,
 * Safari < 15.4, older Android WebViews): without it the panel had no cap at all there, grew
 * past the screen and, with the page scroll locked behind the sheet, nothing could scroll. */
.sheet__panel {
  position: relative;
  width: 100%;
  max-height: calc(100vh - var(--safe-top) - var(--space-6));
  max-height: calc(100dvh - var(--safe-top) - var(--space-6));
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-sheet);
  padding-bottom: var(--safe-bottom);
  transform: translateY(100%);
  transition: transform var(--duration-slow) var(--ease-out);
  outline: none;
}

.sheet.is-open .sheet__backdrop { opacity: 1; }
.sheet.is-open .sheet__panel { transform: none; }

.sheet__handle {
  width: 40px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
  margin: var(--space-2) auto 0;
  flex-shrink: 0;
}

.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  flex-shrink: 0;
}

.sheet__title {
  font-family: var(--font-display);
  font-size: var(--text-heading);
  line-height: var(--leading-heading);
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-tight);
}

.sheet__body {
  padding: var(--space-2) var(--space-4) var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
}

/* A body that is also a .stack (a form) keeps scrolling: its children never shrink to fit. */
.sheet__body.stack > * { flex-shrink: 0; }

/* Sticky footer: stays visible while the body scrolls. */
.sheet__footer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.sheet__footer > .button { flex: 1 1 auto; }

@media (min-width: 900px) {
  .sheet { align-items: center; padding: var(--space-6); }

  .sheet__panel {
    max-width: 560px;
    max-height: calc(100vh - var(--space-12));
    max-height: calc(100dvh - var(--space-12));
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    transform: translateY(16px) scale(0.98);
    opacity: 0;
    transition: transform var(--duration) var(--ease-out), opacity var(--duration) var(--ease-out);
  }

  .sheet--wide .sheet__panel { max-width: 800px; }
  .sheet.is-open .sheet__panel { opacity: 1; }

  .sheet__handle { display: none; }
  .sheet__footer > .button { flex: 0 0 auto; }
}

/* <dialog> ------------------------------------------------------------ */

.dialog {
  border: 0;
  padding: 0;
  margin: auto;
  width: min(100% - 2 * var(--space-4), 440px);
  max-height: calc(100vh - 2 * var(--space-6));
  max-height: calc(100dvh - 2 * var(--space-6));
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.dialog::backdrop { background: var(--color-surface-overlay); }

/* Open: a flex column so a long body scrolls on its own while the title and the buttons stay
 * visible (the UA only gives the whole <dialog> overflow: auto, and not in every browser). */
.dialog[open] { display: flex; flex-direction: column; animation: um-dialog-in var(--duration) var(--ease-out); }

.dialog__header { padding: var(--space-5) var(--space-5) 0; flex-shrink: 0; }
.dialog__title { font-family: var(--font-display); font-size: var(--text-heading); line-height: var(--leading-heading); font-weight: var(--weight-display); letter-spacing: var(--tracking-tight); }

.dialog__body {
  padding: var(--space-3) var(--space-5);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
}

.dialog__footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
  padding: var(--space-3) var(--space-5) var(--space-5);
  flex-shrink: 0;
}

.dialog--danger .dialog__title { color: var(--color-danger); }

.dialog__icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
}

.dialog--danger .dialog__icon { background: var(--color-danger-soft); color: var(--color-danger); }

@keyframes um-dialog-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Dropdown & workspace switcher (details/summary) --------------------- */

.dropdown { position: relative; }

.dropdown > summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
}

.dropdown__menu,
.workspace-switcher__menu {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 2 * var(--space-4)));
  padding: var(--space-1);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: um-dialog-in var(--duration-fast) var(--ease-out);
}

.dropdown__item,
.workspace-switcher__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: var(--text-sm);
  text-decoration: none;
  text-align: left;
}

.dropdown__item:hover,
.workspace-switcher__item:hover { background: var(--color-surface-sunken); text-decoration: none; }

.workspace-switcher { position: relative; }

.workspace-switcher__current {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  transition: border-color var(--duration-fast);
}

.workspace-switcher__current:hover { border-color: var(--color-border-strong); }

.workspace-switcher__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  flex-shrink: 0;
}

.workspace-switcher__text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.workspace-switcher__name {
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-switcher__meta { font-size: var(--text-xs); color: var(--color-text-muted); }

.workspace-switcher__menu {
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
}

.workspace-switcher__item.is-active {
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
  font-weight: var(--weight-semibold);
}

.workspace-switcher__item--new {
  color: var(--color-primary-text);
  border-top: 1px solid var(--color-border);
  border-radius: 0;
  margin-top: var(--space-1);
}

.workspace-switcher--compact .workspace-switcher__current {
  border: 0;
  min-height: var(--touch-target);
  padding-inline: var(--space-2);
  background: transparent;
}

.workspace-switcher--compact .workspace-switcher__meta { display: none; }

/* Avatar -------------------------------------------------------------- */

.avatar {
  --avatar-size: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: var(--radius-full);
  flex-shrink: 0;
  overflow: hidden;
  background: var(--color-teal-soft);
  color: var(--color-teal-soft-text);
  text-decoration: none;
}

.avatar--xs { --avatar-size: 24px; }
.avatar--sm { --avatar-size: 32px; }
.avatar--md { --avatar-size: 40px; }
.avatar--lg { --avatar-size: 56px; }
.avatar--xl { --avatar-size: 88px; }

.avatar__img,
.avatar__initials {
  width: var(--avatar-size, 40px);
  height: var(--avatar-size, 40px);
  border-radius: var(--radius-full);
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: var(--weight-display);
  font-size: calc(var(--avatar-size, 40px) * 0.4);
  background: var(--color-teal-soft);
  color: var(--color-teal-soft-text);
  letter-spacing: 0;
  flex-shrink: 0;
}

.avatar__img--xs, .avatar__initials--xs { --avatar-size: 24px; }
.avatar__img--sm, .avatar__initials--sm { --avatar-size: 32px; }
.avatar__img--md, .avatar__initials--md { --avatar-size: 40px; }
.avatar__img--lg, .avatar__initials--lg { --avatar-size: 56px; }
.avatar__img--xl, .avatar__initials--xl { --avatar-size: 88px; }

/* Avatar stack (S A E): overlapping initials with a surface ring; "+2" for the rest. */
.avatar-stack,
.avatar-group {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.avatar-stack > .avatar,
.avatar-group > .avatar,
.avatar-stack > .avatar__initials,
.avatar-stack > .avatar__img {
  --avatar-size: 28px;
  box-shadow: 0 0 0 2px var(--color-surface);
  margin-left: -8px;
}

.avatar-stack > :first-child,
.avatar-group > :first-child { margin-left: 0; }
.avatar-stack--md > .avatar,
.avatar-stack--md > .avatar__initials { --avatar-size: 36px; margin-left: -10px; }

.avatar-stack__more {
  --avatar-size: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--avatar-size);
  height: var(--avatar-size);
  margin-left: -8px;
  border-radius: var(--radius-full);
  background: var(--color-neutral-soft);
  color: var(--color-neutral-soft-text);
  box-shadow: 0 0 0 2px var(--color-surface);
  font-size: var(--text-min);
  font-weight: var(--weight-semibold);
}

.avatar-stack__label {
  margin-left: var(--space-2);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  color: var(--color-text-muted);
}

/* Empty state, skeleton ---------------------------------------------- */

/* Empty state (screen 2): illustration slot, title, lead, numbered steps, then clear vertical
 * space before a block primary button and a text link (the button never looks attached). */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.empty-state--compact { padding: var(--space-5) var(--space-4); }

.empty-state__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
  margin-bottom: var(--space-2);
}

.empty-state__art {
  width: min(100%, 160px);
  margin-bottom: var(--space-2);
}

.empty-state__art img,
.empty-state__art svg { width: 100%; height: auto; }

.empty-state__title {
  font-size: var(--text-heading);
  line-height: var(--leading-heading);
}

.empty-state__body,
.empty-state__lead {
  color: var(--color-text-muted);
  max-width: 38ch;
  font-size: var(--text-body);
  line-height: var(--leading-body);
}

.empty-state__steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 420px;
  margin: var(--space-4) 0 0;
  padding: 0;
  text-align: left;
  list-style: none;
  counter-reset: empty-step;
}

.empty-state__steps li {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  font-size: var(--text-label);
  line-height: var(--leading-label);
  color: var(--color-text-muted);
  counter-increment: empty-step;
}

.empty-state__steps li::before {
  content: counter(empty-step);
  flex: 0 0 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
  font-family: var(--font-display);
  font-weight: var(--weight-display);
  font-size: var(--text-caption);
}

.empty-state__steps strong { color: var(--color-text); font-weight: var(--weight-semibold); }

.empty-state .button,
.empty-state__actions { margin-top: var(--space-6); }

.empty-state__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
}

.empty-state__actions .button { margin-top: 0; }
.empty-state__actions .button--primary { width: 100%; max-width: 420px; }
.empty-state__link { font-size: var(--text-label); font-weight: var(--weight-medium); }

/* The actions can also sit outside the card so the button never looks attached to it. */
.empty-state--detached { border: 0; background: transparent; padding-inline: 0; }
.empty-state--detached .empty-state__card {
  width: 100%;
  padding: var(--space-8) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--color-surface-sunken) 0%, var(--color-border) 50%, var(--color-surface-sunken) 100%);
  background-size: 200% 100%;
  animation: um-shimmer 1.4s linear infinite;
  min-height: 1em;
}

.skeleton--text { height: 0.9em; width: 70%; }
.skeleton--title { height: 1.2em; width: 45%; }

.skeleton--circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.skeleton--block { height: 96px; border-radius: var(--radius-lg); }

.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.skeleton-list__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.skeleton-list__row > .stack { flex: 1 1 auto; gap: var(--space-2); }

@keyframes um-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@keyframes um-spin {
  to { transform: rotate(360deg); }
}

/* Key-value, meta-row, money ------------------------------------------ */

.kv {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2) var(--space-4);
  align-items: baseline;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
}

.kv:last-child { border-bottom: 0; }
.kv__label { color: var(--color-text-muted); }
/* A <dl class="kv kv--stacked"> of <div><dt/><dd/></div> rows: each row is its own label · value line. */
.kv--stacked { display: block; padding: 0; border-bottom: 0; }
.kv--stacked > div { display: grid; grid-template-columns: fit-content(45%) minmax(0, 1fr); gap: var(--space-2) var(--space-4); align-items: baseline; padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); }
.kv--stacked > div:last-child { border-bottom: 0; }
.kv--stacked dd { margin: 0; text-align: right; }

.kv__value {
  font-weight: var(--weight-medium);
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.meta-row > * + *::before {
  content: "·";
  margin-right: var(--space-2);
  color: var(--color-border-strong);
}

.money {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: var(--weight-semibold);
}

.money--positive { color: var(--color-money-positive); }
.money--negative { color: var(--color-money-negative); }
.money--pending { color: var(--color-money-pending); }
.money--muted { color: var(--color-text-muted); font-weight: var(--weight-regular); }
.money--danger { color: var(--color-danger); }
.money--sm { font-size: var(--text-label); }
.money--lg { font-size: var(--text-xl); }
.money--xl { font-size: var(--text-display); line-height: var(--leading-display); letter-spacing: var(--tracking-tight); }

/* Timeline ------------------------------------------------------------ */

.timeline {
  display: flex;
  flex-direction: column;
  padding-left: var(--space-1);
}

.timeline__item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  position: relative;
}

.timeline__item::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 28px;
  bottom: 0;
  width: 2px;
  background: var(--color-border);
}

.timeline__item:last-child::before { display: none; }

.timeline__marker {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-neutral-soft);
  color: var(--color-neutral-soft-text);
  flex-shrink: 0;
}

.timeline__marker--success { background: var(--color-success-soft); color: var(--color-success-soft-text); }
.timeline__marker--warning { background: var(--color-warning-soft); color: var(--color-warning-soft-text); }
.timeline__marker--danger { background: var(--color-danger-soft); color: var(--color-danger-soft-text); }
.timeline__marker--info { background: var(--color-info-soft); color: var(--color-info-soft-text); }
.timeline__marker--primary { background: var(--color-primary-soft); color: var(--color-primary-soft-text); }
.timeline__what { font-size: var(--text-sm); font-weight: var(--weight-medium); }

.timeline__detail {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-surface-sunken);
  font-size: var(--text-sm);
}

.timeline__meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* Step indicator ------------------------------------------------------ */

.step-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.step-indicator__step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1 1 0;
  min-width: 0;
  color: var(--color-text-subtle);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.step-indicator__step::before {
  counter-increment: step;
  content: counter(step);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--color-border-strong);
  background: var(--color-surface);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  flex-shrink: 0;
}

.step-indicator__step::after {
  content: "";
  flex: 1 1 auto;
  height: 2px;
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.step-indicator__step:last-child::after { display: none; }
.step-indicator__step.is-done { color: var(--color-success); }

.step-indicator__step.is-done::before {
  content: "✓";
  background: var(--color-success); /* the text green: white tick 5.0:1 (the bright fill was 3.2:1) */
  border-color: var(--color-success);
  color: var(--color-text-on-success);
}

.step-indicator__step.is-done::after { background: var(--color-success-bright); }
.step-indicator__step.is-current { color: var(--color-primary-text); }

.step-indicator__step.is-current::before {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: var(--color-text-on-primary);
}

.step-indicator__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 639.98px) {
  .step-indicator__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .step-indicator__step.is-current .step-indicator__label {
    position: static;
    width: auto;
    height: auto;
    clip: auto;
  }
}

/* Insight and challenge cards ------------------------------------------ */

/* Insight cards are soft-tinted (amber, lilac, rose, sky) with an eyebrow, a title, one or two
 * lines, a metric line and an optional "Recommended" pill (docs/DESIGN-DIRECTION.md §3). The
 * severity tones map onto the tints; the icon sits on a white tile. */
.insight-card {
  --insight-color: var(--color-info);
  --insight-soft: var(--color-info-soft);
  --insight-tint: var(--tint-sky);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-3);
  padding: var(--card-padding);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: var(--insight-tint);
  color: var(--color-text);
}

.insight-card--positive,
.insight-card--success { --insight-color: var(--color-success); --insight-soft: var(--color-success-soft); --insight-tint: var(--color-success-soft); }

.insight-card--warning,
.insight-card--attention,
.insight-card--amber { --insight-color: var(--color-warning); --insight-soft: var(--color-warning-soft); --insight-tint: var(--tint-amber); }

.insight-card--critical,
.insight-card--danger,
.insight-card--rose { --insight-color: var(--color-danger); --insight-soft: var(--color-danger-soft); --insight-tint: var(--tint-rose); }

.insight-card--neutral,
.insight-card--info,
.insight-card--sky { --insight-color: var(--color-info); --insight-soft: var(--color-info-soft); --insight-tint: var(--tint-sky); }

.insight-card--lilac { --insight-color: var(--tile-lilac-ink); --insight-soft: var(--tile-lilac); --insight-tint: var(--tint-lilac); }

.insight-card__icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  color: var(--insight-color);
  box-shadow: var(--shadow-xs);
}

.insight-card__title { font-size: var(--text-base); font-weight: var(--weight-semibold); }
.insight-card__what { font-size: var(--text-sm); margin-top: 2px; }

.insight-card__why {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}

.insight-card__next {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-size: var(--text-sm);
}

.insight-card__next strong { color: var(--insight-color); }

.insight-card__actions {
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.insight-card--compact { padding: var(--space-3); }
.insight-card--compact .insight-card__why,
.insight-card--compact .insight-card__next { display: none; }

.challenge-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: inherit;
}

.challenge-card--active { border-color: var(--color-accent); background: linear-gradient(160deg, var(--color-accent-soft), var(--color-surface) 60%); }

.challenge-card__head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.challenge-card__icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  flex-shrink: 0;
}

.challenge-card__title { font-weight: var(--weight-semibold); }
.challenge-card__summary { font-size: var(--text-sm); color: var(--color-text-muted); }

/* Budget line row, category pill ------------------------------------- */

.budget-line {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--color-border);
}

.budget-line:last-child { border-bottom: 0; }
a.budget-line:hover { background: var(--color-surface-sunken); text-decoration: none; }

.budget-line__icon {
  grid-row: span 2;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--category-color, var(--color-primary-soft));
  color: var(--color-text-on-primary);
  flex-shrink: 0;
}

.budget-line__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
}

.budget-line__name {
  font-weight: var(--weight-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.budget-line__amounts {
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--color-text-muted);
}

.budget-line__amounts strong { color: var(--color-text); }

.budget-line__foot {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.budget-line__foot .progress { flex: 1 1 auto; }

.budget-line__status {
  font-size: var(--text-xs);
  white-space: nowrap;
  color: var(--color-text-muted);
}

.budget-line--over .budget-line__status { color: var(--color-danger); font-weight: var(--weight-semibold); }
.budget-line--at_risk .budget-line__status,
.budget-line--near .budget-line__status { color: var(--color-warning); font-weight: var(--weight-medium); }

.category-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px var(--space-2) 2px 2px;
  border-radius: var(--radius-full);
  background: var(--color-surface-sunken);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  max-width: 100%;
}

.category-pill__icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--category-color, var(--color-primary));
  color: var(--color-text-on-primary);
  flex-shrink: 0;
}

.category-pill__icon .icon { width: 13px; height: 13px; }

.category-pill__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Charts (server-rendered SVG) ---------------------------------------- */

.chart { position: relative; width: 100%; }

.chart svg {
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: var(--font-sans);
}

.chart--bar svg,
.chart--line svg { aspect-ratio: 16 / 9; }
.chart--donut svg { max-width: 240px; margin-inline: auto; }

.chart__axis { stroke: var(--chart-axis); stroke-width: 1; }

.chart__grid {
  stroke: var(--chart-grid);
  stroke-width: 1;
  stroke-dasharray: 2 4;
}

.chart__baseline { stroke: var(--chart-baseline); }
.chart__label { fill: var(--chart-axis); font-size: 11px; }

.chart__bar,
.chart__slice,
.chart__point { transition: opacity var(--duration-fast); cursor: default; }

.chart__bar:hover,
.chart__slice:hover,
.chart__bar:focus-visible,
.chart__slice:focus-visible { opacity: 0.8; outline: 2px solid var(--color-border-focus); outline-offset: 2px; }

.chart__line {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart__area { opacity: 0.12; }
.chart__point { stroke: var(--color-surface); stroke-width: 2; }

.chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  list-style: none;
  padding: 0;
}

.chart__legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: none;
  border: 0;
  color: inherit;
  min-height: 28px;
}

.chart__legend-item[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }

.chart__swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.chart-tooltip {
  position: fixed;
  z-index: var(--z-toast);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--chart-tooltip-bg);
  color: var(--chart-tooltip-text);
  font-size: var(--text-xs);
  line-height: 1.3;
  pointer-events: none;
  box-shadow: var(--shadow-md);
  max-width: 220px;
  transform: translate(-50%, calc(-100% - 10px));
}

.chart-tooltip__label { opacity: 0.75; }
.chart-tooltip__value { font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }

.series-1 { fill: var(--chart-1); stroke: var(--chart-1); }
.series-2 { fill: var(--chart-2); stroke: var(--chart-2); }
.series-3 { fill: var(--chart-3); stroke: var(--chart-3); }
.series-4 { fill: var(--chart-4); stroke: var(--chart-4); }
.series-5 { fill: var(--chart-5); stroke: var(--chart-5); }
.series-6 { fill: var(--chart-6); stroke: var(--chart-6); }
.series-7 { fill: var(--chart-7); stroke: var(--chart-7); }
.series-8 { fill: var(--chart-8); stroke: var(--chart-8); }

/* Pagination, filter bar, FAB ----------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-5);
  font-size: var(--text-sm);
}

.pagination__pages {
  display: none;
  gap: var(--space-1);
  list-style: none;
  padding: 0;
  margin: 0;
}

@media (min-width: 640px) {
  .pagination__pages { display: flex; }
}

.pagination__page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  text-decoration: none;
}

.pagination__page:hover { background: var(--color-surface-sunken); text-decoration: none; }

.pagination__page.is-active {
  background: var(--color-primary);
  color: var(--color-text-on-primary);
  font-weight: var(--weight-semibold);
}

.pagination__summary { color: var(--color-text-muted); }

.filter-bar {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: var(--space-1) 0 var(--space-2);
  margin-bottom: var(--space-3);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}

.filter-bar::-webkit-scrollbar { display: none; }
.filter-bar > * { flex-shrink: 0; scroll-snap-align: start; }
/* Desktop: filters sit in a top bar and wrap instead of scrolling off the column's edge. */
@media (min-width: 1024px) {
  .filter-bar { flex-wrap: wrap; overflow: visible; scroll-snap-type: none; }
}

.filter-bar__count {
  margin-left: 2px;
  color: var(--color-text-subtle);
  font-weight: var(--weight-regular);
}

a.chip.is-active .filter-bar__count { color: inherit; opacity: 0.8; }

.fab {
  position: fixed;
  z-index: var(--z-fab);
  right: calc(var(--space-4) + var(--safe-right));
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + var(--space-4));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 56px;
  height: 56px;
  padding: 0 var(--space-5);
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-on-primary);
  font-weight: var(--weight-semibold);
  box-shadow: var(--shadow-fab);
  text-decoration: none;
  transition: transform var(--duration-fast), background var(--duration-fast);
}

.fab:hover {
  background: var(--color-primary-hover);
  text-decoration: none;
  transform: translateY(-1px);
}

.fab--icon { padding: 0; width: 56px; }

@media (min-width: 900px) {
  .fab { bottom: var(--space-6); right: var(--space-6); }
}

/* Misc small components ----------------------------------------------- */


/* --- Mobile density fixes (visual pass 2026-10-19) ------------------------------------------ */
.money,
.stat__value,
.list-item__trailing .money,
[data-amount] { white-space: nowrap; }

/* Stat tiles sit two-up on phones instead of stacking nine high. */
@media (max-width: 639.98px) {
  .stat-grid,
  .grid--stats,
  .savings-tiles,
  .grid--2.stat-grid,
  .grid--3.stat-grid,
  .grid--4.stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2, 0.5rem); }
  .stat-grid .stat,
  .savings-tiles .stat,
  .grid--stats .stat { padding: var(--space-3, 0.75rem); }
  .stat-grid .stat__value,
  .savings-tiles .stat__value,
  .grid--stats .stat__value { font-size: clamp(1.05rem, 5.2vw, 1.35rem); }
  .stat-grid .stat__label,
  .grid--stats .stat__label { font-size: var(--text-min); }
  .stat-grid .stat__meta,
  .grid--stats .stat__meta { font-size: var(--text-caption); }
  .stat-grid .stat--wide,
  .grid--stats .stat--wide { grid-column: 1 / -1; }

  /* Action bars scroll horizontally rather than wrapping into tall blocks. */
  .action-bar .cluster,
  .cluster--scroll {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
    margin-inline: calc(-1 * var(--space-4, 1rem));
    padding-inline: var(--space-4, 1rem);
  }
  .action-bar .cluster::-webkit-scrollbar,
  .cluster--scroll::-webkit-scrollbar { display: none; }
  .action-bar .cluster > *,
  .cluster--scroll > * { flex: 0 0 auto; }
}

/* --- Charts (server-rendered SVG from {% load charts %}) ------------------------------------- */
.chart figure, figure.chart { margin: 0; }
.chart--empty .empty-state { margin: 0; }
.chart__alt { margin-top: var(--space-2); }
.chart__alt > summary { display: inline-flex; list-style: none; cursor: pointer; }
.chart__alt > summary::-webkit-details-marker { display: none; }
.chart__alt .table-wrap { margin-top: var(--space-2); }
.chart__legend--list { display: grid; gap: var(--space-1); }
.chart__legend--list .chart__legend-item { justify-content: space-between; width: 100%; }
.chart__legend-value { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--color-text); }
.chart--sparkline { display: inline-block; width: 120px; vertical-align: middle; }
.chart--sparkline svg { display: block; }

/* ==========================================================================================
   Moneva revamp — compact, low-noise building blocks
   ========================================================================================== */

/* Hero: the one number a screen is about. */
.hero {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
/* .hero--brand is the navy summary card (declared with .summary-card above); restate the surface
 * here so the plain .hero rule above cannot win by source order. */
.hero--brand {
  background: var(--color-hero-bg);
  border-color: transparent;
  color: var(--color-hero-text);
}
html[data-resolved-theme="dark"] .hero--brand { background: var(--color-surface-raised); border-color: var(--color-border); }
.hero__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}
.hero__value {
  font-family: var(--font-display);
  font-size: var(--text-hero);
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-display);
  color: var(--color-text);
  white-space: normal;
  overflow-wrap: normal; /* wraps only between the currency code and the number */
}
.hero__value .money__code,
.hero__value small {
  font-size: 0.42em;
  font-weight: var(--weight-semibold);
  letter-spacing: 0;
  color: var(--color-text-muted);
  margin-right: 0.2em;
  vertical-align: 0.5em;
}
.hero__meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.hero__actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; }

/* Metric row: up to three compact figures side by side. */
.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

/* Phones: three metrics side by side leave ~80px per figure, so the third drops under the pair. */
@media (max-width: 639.98px) {
  .metric-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-row > .metric:nth-child(3n) { grid-column: 1 / -1; }
}
.metric {
  min-width: 0;
  padding: var(--space-3) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.metric__label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  margin-bottom: 2px;
}
.metric__value {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(1rem, 4.2vw, 1.2rem);
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text);
  line-height: 1.15;
  overflow-wrap: normal; /* may wrap between the currency code and the number, never inside */
}
.metric__value--positive { color: var(--color-money-positive); }
.metric__delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: 2px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-subtle);
}
.metric__delta--up { color: var(--color-success); }
.metric__delta--down { color: var(--color-danger); }
@media (min-width: 640px) {
  .metric { padding: var(--space-4); }
  .metric__value { font-size: var(--text-xl); }
}

/* Lists that sit directly in a card without their own padding. */
.list--flush { margin: 0 calc(-1 * var(--card-padding)); }
.list--flush .list-item { padding-inline: var(--card-padding); }
.list--flush .list-item:last-child { border-bottom: 0; }

/* Tighter section rhythm for the revamped screens. */
.section--tight { margin-top: var(--space-5); }
.section--tight .section__title {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
}
.section__link {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-primary-text);
  white-space: nowrap; /* "Your behaviour" never breaks mid-word beside a title */
  flex-shrink: 0;
}

/* Progress ring (SVG from {% chart_ring %}). */
.ring { display: inline-grid; place-items: center; position: relative; width: 72px; height: 72px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring__track { fill: none; stroke: var(--color-surface-sunken); stroke-width: 7; }
.ring__value { fill: none; stroke: var(--color-primary); stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset var(--duration-slow) var(--ease); }
.ring__label {
  position: absolute;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-extrabold);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text);
}
.ring--lg { width: 112px; height: 112px; }
.ring--lg .ring__label { font-size: var(--text-2xl); }
.ring--success .ring__value,
.ring--ok .ring__value { stroke: var(--color-success-bright); }
.ring--warning .ring__value,
.ring--warn .ring__value { stroke: var(--color-warning-bright); }
.ring--danger .ring__value,
.ring--over .ring__value { stroke: var(--color-expense-bright); }
.ring--sm { width: 48px; height: 48px; }
.ring--sm .ring__label { font-size: var(--text-caption); }
.ring--xl { width: 140px; height: 140px; }
.ring--xl .ring__label { font-size: var(--text-display); }
/* Rings drawn by app.js (data-ring) use pathLength=100, so the arc is "percent 100". */
.ring .ring__value[pathLength] { transition: stroke-dasharray var(--duration-slow) var(--ease); }

/* Sticky action bar at the bottom of long forms on phones. */
.sticky-actions {
  position: sticky;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
  z-index: 2;
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) 0;
  margin-top: var(--space-4);
  background: linear-gradient(to top, var(--color-bg) 70%, transparent);
}
.sticky-actions .button { flex: 1 1 auto; }
@media (min-width: 900px) {
  .sticky-actions { position: static; background: none; padding: 0; }
  .sticky-actions .button { flex: 0 0 auto; }
}

/* Pill-style segmented control for type switches. */
.segmented--pills { background: var(--color-surface-sunken); border-radius: var(--radius-full); padding: 3px; }
.segmented--pills .segmented__item { border-radius: var(--radius-full); min-height: var(--control-sm); }
.segmented--pills .segmented__item.is-active { background: var(--color-surface); box-shadow: var(--shadow-xs); color: var(--color-text); }

/* Big amount entry (quick-add). */
.amount-input--hero {
  width: 100%;
  border: 0;
  border-bottom: 2px solid var(--color-border);
  border-radius: 0;
  background: transparent;
  font-family: var(--font-display);
  font-size: var(--text-hero);
  line-height: var(--leading-display);
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-tight);
  padding: var(--space-2) 0;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
.amount-input--hero:focus { outline: none; border-bottom-color: var(--color-primary); box-shadow: none; }

/* Sidebar groups */
.app-nav__group {
  margin: var(--space-4) var(--space-3) var(--space-1);
  font-size: var(--text-min);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}
.app-nav__group:first-child { margin-top: var(--space-2); }

/* Typography refinements for existing blocks */
.stat__value,
.page-header__title,
.app-topbar__title,
.card__title,
.sheet__title { font-family: var(--font-display); letter-spacing: var(--tracking-tight); }
.button { font-weight: var(--weight-medium); }

/* Key/value list: <dl class="kv-list"> with <div class="kv__row"><dt class="kv__label"><dd class="kv__value"> */
.kv-list { margin: 0; display: grid; }
.kv-list .kv__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2) var(--space-4);
  align-items: baseline;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
}
.kv-list .kv__row:last-child { border-bottom: 0; }
.kv-list .kv__value { text-align: right; }

/* Disclosure: a quiet <details> for secondary figures. */
.disclosure { border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); padding: 0 var(--space-4); }
.disclosure__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
}
.disclosure__summary::-webkit-details-marker { display: none; }
.disclosure__summary::after { content: "+"; font-weight: var(--weight-regular); color: var(--color-text-subtle); }
.disclosure[open] .disclosure__summary::after { content: "–"; }
.disclosure[open] .disclosure__summary { color: var(--color-text); }
.disclosure > :not(summary) { padding-bottom: var(--space-2); }
.hero__value.money--positive { color: var(--color-money-positive); }
.hero__value.money--negative { color: var(--color-danger); }
.metric__value.money--negative { color: var(--color-danger); }

/* Compact demo-data notice (app shell) */
.demo-note {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin: 0 0 var(--space-3);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--color-info-soft);
  color: var(--color-info-soft-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}
.demo-note a { color: inherit; text-decoration: underline; }

/* Habits card (shared: embedded on Home and the Habits page) */
.habits-card { display: grid; gap: var(--space-3); }
.habits-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.habits-card__title {
  margin: 0;
  font-family: var(--font-display, var(--font-sans));
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight, -0.01em);
}
.habits-card__streak {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2); border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  background: var(--color-surface-sunken); color: var(--color-text-muted);
}
.habits-card__streak.is-alive { background: var(--color-warning-soft); color: var(--color-warning-soft-text); }
.habits-card__level { display: grid; gap: var(--space-1); }
.habits-card__level-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); font-size: var(--text-sm); }
.habits-card__level-label { font-weight: var(--weight-semibold); }
.habits-card__level-meta { color: var(--color-text-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.habits-card__body { display: flex; gap: var(--space-4); align-items: flex-start; }
.habits-card__ring { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 0 0 auto; }
.habits-card__ring-caption { font-size: var(--text-xs); color: var(--color-text-subtle); white-space: nowrap; }
.habits-goals { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; flex: 1 1 auto; min-width: 0; }
.habits-goal {
  --goal-percent: 0%;
  position: relative;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center;
  gap: var(--space-2); min-height: 36px; padding: var(--space-1) 0;
  font-size: var(--text-sm);
}
.habits-goal::after {
  /* a 2px progress underline, so the row stays one line */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--color-primary) var(--goal-percent), var(--color-border) var(--goal-percent));
  opacity: 0.8;
}
.habits-goal.is-done::after { background: var(--color-success); }
.habits-goal--warning::after { background: linear-gradient(to right, var(--color-warning-bright, var(--color-warning)) var(--goal-percent), var(--color-border) var(--goal-percent)); }
.habits-goal__icon { display: inline-flex; color: var(--color-text-muted); }
.habits-goal.is-done .habits-goal__icon { color: var(--color-success); }
.habits-goal__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--weight-medium); color: inherit; }
a.habits-goal__label { text-decoration: none; }
a.habits-goal__label:hover { text-decoration: underline; }
.habits-goal__detail { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.habits-goal__state { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: var(--radius-full); color: var(--color-text-subtle); }
.habits-goal.is-done .habits-goal__state { background: var(--color-success-soft); color: var(--color-success-soft-text); }
.habits-goal__dot { width: 8px; height: 8px; border-radius: var(--radius-full); border: 2px solid var(--color-border-strong); }
.habits-card__cta {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  background: var(--color-primary-soft); color: var(--color-primary-soft-text);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); text-decoration: none;
}
.habits-card__cta:hover { text-decoration: none; filter: brightness(0.98); }
.habits-card__cta-chevron { margin-left: auto; }
.habits-card__done { margin: 0; display: flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); color: var(--color-text-muted); }
@media (max-width: 379px) {
  .habits-card__body { flex-direction: column; }
  .habits-card__ring { flex-direction: row; gap: var(--space-2); }
}

/* Reading typography (legal pages, long copy) */
.prose {
  max-width: 68ch;
  font-size: 1.0625rem;
  line-height: var(--leading-relaxed);
}

.prose > * + * { margin-top: var(--space-4); }
.prose h1 { font-size: var(--text-3xl); }

.prose h2 { font-size: var(--text-2xl); margin-top: var(--space-10); }
.prose h3 { font-size: var(--text-xl); margin-top: var(--space-8); }

.prose ul,
.prose ol { padding-left: var(--space-6); }
.prose ul { list-style: disc; }

.prose ol { list-style: decimal; }
.prose li + li { margin-top: var(--space-1); }

.prose a { text-decoration: underline; }

.prose blockquote {
  padding: var(--space-3) var(--space-5);
  border-left: 4px solid var(--color-primary);
  background: var(--color-surface);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--color-text-muted);
}

.prose img { border-radius: var(--radius-lg); }
.prose table { width: 100%; font-size: var(--text-sm); }

.prose th,
.prose td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}

.prose code {
  padding: 0.1em 0.35em;
  background: var(--color-surface-sunken);
  border-radius: var(--radius-xs);
}

.prose pre {
  padding: var(--space-4);
  background: var(--color-surface-sunken);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.prose .lead { font-size: var(--text-xl); color: var(--color-text-muted); }

/* Habits card on phones: ring sits beside the level bar, goals get the full width. */
@media (max-width: 639.98px) {
  .habits-card__body { display: grid; grid-template-columns: 1fr; gap: var(--space-3); }
  .habits-card__ring { flex-direction: row; justify-content: flex-start; gap: var(--space-3); order: -1; }
  .habits-card__ring .ring { width: 56px; height: 56px; }
  .habits-card__ring .ring__label { font-size: var(--text-base); }
  .habits-card__ring-caption { white-space: normal; font-size: var(--text-sm); color: var(--color-text-muted); }
  .habits-goal__label { white-space: normal; overflow: visible; text-overflow: clip; }
  .habits-goal__detail { white-space: normal; text-align: right; }
}

/* Grouped fields rendered as <fieldset class="field"> never show the browser's box. */
fieldset.field { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.field > legend.field__label { padding: 0; float: none; }

/* Segmented items and tabs rendered as <button> inherit the control styling. */
button.segmented__item,
.tabs button.tab { font: inherit; background: none; border: 0; cursor: pointer; }


/* Shortcuts grid in the More sheet (three taps to any common task). */
.app-menu__shortcuts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.shortcut {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-decoration: none;
}
.shortcut:hover { text-decoration: none; filter: brightness(0.97); }
.shortcut .icon { flex: none; }

/* Reward toasts (XP, badges, level-ups) */
.toast--xp { border-left: 4px solid var(--brand-purple); }
.toast--xp .icon { color: var(--brand-purple); }
.toast--badge { border-left: 4px solid var(--brand-amber); }
.toast--badge .icon { color: var(--brand-amber); }
.toast--level-up { border-left: 4px solid var(--brand-green); }
.toast--level-up .icon { color: var(--brand-green); }

/* Celebration burst: a soft radial pulse, no confetti, honours reduced motion. */
@keyframes mv-burst {
  0% { transform: scale(0.6); opacity: 0; }
  40% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes mv-glow {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 0 14px var(--color-teal-soft); }
}
.celebrate { animation: mv-burst var(--duration-slow) var(--ease-spring) both; }
.celebrate--glow { animation: mv-burst var(--duration-slow) var(--ease-spring) both, mv-glow 1.2s var(--ease) 1; border-radius: var(--radius-lg); }
.badge-art { display: inline-block; width: 56px; height: 56px; }
.badge-art--lg { width: 96px; height: 96px; }
.badge-art.is-locked { filter: grayscale(1); opacity: 0.45; }

/* Page enter: a quiet fade so navigation feels native. */
@keyframes mv-page-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.app-content > * { animation: mv-page-in var(--duration) var(--ease-out) both; }
@media (prefers-reduced-motion: reduce) {
  .celebrate, .celebrate--glow, .app-content > * { animation: none !important; }
}

/* Celebration overlay (badges, level-ups) */
.celebration { position: fixed; inset: 0; z-index: var(--z-dialog, 60); display: flex; align-items: flex-end; justify-content: center; padding: var(--space-4, 16px); padding-bottom: calc(var(--bottom-nav-height, 64px) + var(--space-4, 16px) + var(--safe-bottom, 0px)); pointer-events: none; }
.celebration__backdrop { position: absolute; inset: 0; background: var(--color-surface-overlay); pointer-events: auto; }
.celebration__card { position: relative; width: min(100%, 420px); display: grid; justify-items: center; gap: var(--space-2, 8px); padding: var(--space-5, 20px) var(--space-4, 16px); border-radius: var(--radius-xl, 20px); background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-lg); text-align: center; pointer-events: auto; }
.celebration__art { display: flex; gap: var(--space-2, 8px); align-items: center; justify-content: center; }
.celebration__level { display: inline-grid; place-items: center; width: 96px; height: 96px; border-radius: 50%; background: var(--color-primary); color: var(--color-text-on-primary); font-family: var(--font-display); font-weight: var(--weight-display); font-size: 2rem; line-height: 1; }
.celebration__level small { font-size: var(--text-min); font-weight: var(--weight-semibold); letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.85; }
.celebration__title { margin: 0; font-family: var(--font-display); font-size: var(--text-xl); font-weight: var(--weight-display); letter-spacing: var(--tracking-tight); }
.celebration__text { margin: 0; color: var(--color-text-muted); font-size: var(--text-sm); }
.celebration__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: var(--text-sm, 0.9rem); }
.celebration__actions { display: flex; flex-wrap: wrap; gap: var(--space-2, 8px); justify-content: center; margin-top: var(--space-2, 8px); }
.celebration__share { margin: 0; font-size: var(--text-xs); color: var(--color-text-subtle); }
@media (min-width: 900px) { .celebration { align-items: center; padding-bottom: var(--space-4, 16px); } }
@media (prefers-reduced-motion: reduce) { .celebration__card { animation: none !important; } }

/* Habits hero (shared: embedded on Home) */
.habits-hero { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-3) var(--space-4); align-items: center; }
.habits-hero__ring .ring__value { stroke: var(--brand-purple); }
.habits-hero__level { display: grid; justify-items: center; line-height: 1; font-family: var(--font-display, var(--font-sans)); font-weight: var(--weight-extrabold, 800); font-size: var(--text-2xl); }
.habits-hero__level small { font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--color-text-muted); letter-spacing: 0.04em; }
.habits-hero__text { display: grid; gap: 2px; min-width: 0; }
.habits-hero__title { margin: 0; font-family: var(--font-display, var(--font-sans)); font-size: var(--text-2xl); font-weight: var(--weight-extrabold, 800); letter-spacing: var(--tracking-tight, -0.01em); line-height: 1.1; }
.habits-hero__meta { margin: 0; color: var(--color-text-muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.habits-hero__streak { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-top: var(--space-2); }
.habits-hero__badges { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); background: var(--color-surface-sunken); color: inherit; text-decoration: none; font-size: var(--text-sm); min-height: var(--touch-target); }
.habits-hero__badges:hover { text-decoration: none; background: var(--color-accent-soft); }
.habits-hero__badge-art { display: inline-flex; align-items: center; }
.habits-hero__badge-art .badge-art { width: 32px; height: 32px; margin-right: -8px; filter: drop-shadow(var(--shadow-drop)); }
.habits-hero__badge-art .badge-art:last-child { margin-right: 4px; }
.habits-hero__badge-text { flex: 1 1 auto; min-width: 0; }
.habits-hero__chevron { color: var(--color-text-subtle); }
.quiet-links__art .badge-art { width: 28px; height: 28px; }

/* Flex/grid children can always shrink so long titles truncate instead of widening the page. */
.list, .list-item, .list-item__body, .metric, .stats__panel { min-width: 0; }

/* Step indicator on phones: the current step's label takes the free width. */
@media (max-width: 639.98px) {
  .step-indicator__step.is-current { flex: 1 1 auto; min-width: 0; }
  .step-indicator__step.is-current .step-indicator__label { overflow: hidden; text-overflow: ellipsis; }
}


/* ==========================================================================================
   Rhythm and semantic colour (round 3)
   ========================================================================================== */
.app-content .section { margin-bottom: var(--space-8); }
.app-content .card + .card { margin-top: var(--space-4); }
/* Cards laid out by a grid take the grid gap, not the stacked-card margin (it staggered rows). */
.app-content .layout-grid > .card + .card,
.app-content .stat-tile-grid > .card + .card,
.app-content .kpi-tile-grid > .card + .card { margin-top: 0; }
.app-content .stack { --stack-gap: var(--space-5); }
@media (min-width: 640px) {
  .card { padding: var(--space-6); }
  .app-content .section { margin-bottom: var(--space-10); }
}

/* Information-type accents: a 4px edge in the colour that matches what the card is about. */
.card--accent { border-left: 4px solid var(--card-accent, var(--color-primary)); }
.card--income { --card-accent: var(--color-success-bright); }
.card--expense { --card-accent: var(--brand-navy); }
.card--savings { --card-accent: var(--color-teal); }
.card--plan { --card-accent: var(--color-primary); }
.card--warning { --card-accent: var(--color-warning-bright); }
.card--danger { --card-accent: var(--color-danger); }
.card--habit { --card-accent: var(--color-warning-bright); }

/* KPI value colouring by meaning (never by sign alone). */
.metric--income .metric__value, .stat--income .stat__value { color: var(--color-success); }
.metric--spent .metric__value, .stat--spent .stat__value { color: var(--color-text); }
.metric--savings .metric__value, .stat--savings .stat__value { color: var(--color-teal); }
.metric--warning .metric__value, .stat--warning .stat__value { color: var(--color-warning); }
.metric--danger .metric__value, .stat--danger .stat__value { color: var(--color-danger); }


/* KPI card: icon, label, value, delta and an optional sparkline. Colour by meaning via modifiers. */
.kpi {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-2) var(--space-3);
  align-items: start;
  padding: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  min-width: 0;
}
.kpi__icon {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--kpi-soft, var(--color-primary-soft));
  color: var(--kpi-color, var(--color-primary-text));
}
.kpi__body { min-width: 0; }
.kpi__label { display: block; font-size: var(--text-caption); line-height: var(--leading-caption); font-weight: var(--weight-medium); color: var(--color-text-muted); }
.kpi__value {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-tight);
  color: var(--kpi-color, var(--color-text));
  line-height: var(--leading-title);
  overflow-wrap: normal;
}
/* Formula captions under a KPI ("1,250,000 − 720,000 − 200,000 savings"). */
.kpi__caption { display: block; margin-top: 2px; font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.kpi__delta { display: inline-flex; align-items: center; gap: 2px; font-size: var(--text-xs); color: var(--color-text-subtle); }
.kpi__delta--up { color: var(--color-success); }
.kpi__delta--down { color: var(--color-danger); }
.kpi__spark { grid-column: 1 / -1; margin-top: var(--space-1); }
.kpi--income { --kpi-color: var(--color-success); --kpi-soft: var(--color-success-soft); }
.kpi--spent { --kpi-color: var(--color-text); --kpi-soft: var(--color-neutral-soft); }
.kpi--savings { --kpi-color: var(--color-teal); --kpi-soft: var(--color-teal-soft); }
.kpi--plan { --kpi-color: var(--color-primary-text); --kpi-soft: var(--color-primary-soft); }
.kpi--warning { --kpi-color: var(--color-warning); --kpi-soft: var(--color-warning-soft); }
.kpi--danger { --kpi-color: var(--color-danger); --kpi-soft: var(--color-danger-soft); }
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
@media (min-width: 900px) { .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* Tables: readable numbers, quiet zebra, sticky header on long tables. */
.table--data th { position: sticky; top: calc(var(--topbar-height) + var(--safe-top)); z-index: 1; background: var(--color-surface); }
/* Inside a scrolling wrapper the sticky header sticks to the wrapper, not the viewport. */
.table-wrap .table--data th { top: 0; }
.table--data td.num, .table--data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table--data tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--color-surface-sunken) 55%, transparent); }
.table--data tfoot td { font-weight: var(--weight-semibold); border-top: 2px solid var(--color-border-strong); }
.table__status { display: inline-flex; align-items: center; gap: 6px; }
.table__status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--status-color, var(--color-text-subtle)); }
.table__status--ok { --status-color: var(--color-success-bright); }
.table__status--warn { --status-color: var(--color-warning-bright); }
.table__status--over { --status-color: var(--color-danger); }


/* Install banner (app shell) and install guide steps */
.install-banner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-primary-soft);
  color: var(--color-primary-soft-text);
  font-size: var(--text-sm);
}
.install-banner__text { display: inline-flex; align-items: center; gap: var(--space-2); flex: 1 1 auto; min-width: 0; }
@media (min-width: 900px) { .install-banner { display: none; } }
body.is-standalone .install-banner { display: none; }
.install-steps { padding-left: var(--space-5); display: grid; gap: var(--space-2); }
.install-steps li { line-height: var(--leading-relaxed); }

/* .switch (shared, lifted from workspaces.css) */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  cursor: pointer;
  min-height: var(--touch-target, 44px);
  user-select: none;
}
.switch__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.switch__track {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--color-border-strong);
  transition: background 160ms ease;
  flex: 0 0 auto;
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  transition: transform 160ms ease;
}
.switch__input:checked + .switch__track { background: var(--color-primary); }
.switch__input:checked + .switch__track::after { transform: translateX(18px); }
.switch__input:focus-visible + .switch__track { outline: 3px solid var(--color-border-focus); outline-offset: 2px; }
.switch__input:disabled + .switch__track { opacity: 0.5; }
.switch__label {
  font-size: var(--text-sm, 0.875rem);
  font-weight: 600;
  min-width: 2ch;
}

/* .approver-chip (shared, lifted from workspaces.css) */
.approver-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  padding: 0.3rem 0.75rem 0.3rem 0.35rem;
  min-height: 40px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}
.approver-chip__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.approver-chip__avatar { flex: 0 0 auto; }
.approver-chip__name { font-weight: 600; font-size: var(--text-sm, 0.875rem); }
.approver-chip__role {
  font-size: var(--text-xs, 0.75rem);
  color: var(--color-text-muted);
}
.approver-chip__check {
  display: none;
  color: var(--color-primary-text);
}
.approver-chip:has(.approver-chip__input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}
.approver-chip:has(.approver-chip__input:checked) .approver-chip__check { display: inline-flex; }
.approver-chip:has(.approver-chip__input:focus-visible) {
  outline: 3px solid var(--color-border-focus);
  outline-offset: 2px;
}

/* Chart semantics and KPI sparklines (merged from pages/charts.css so every page matches) */
/* Chart polish shared by Home, Stats, Behaviour and Reports (the tags live in
   apps/insights/templatetags/charts.py). Semantic colour tokens, chip legends, phone-friendly
   frames, the day strip and the sparkline inside KPI cards. The tags inline their own positioning,
   so pages that do not load this file still render correctly — this file only refines them.
   Candidate for components.css once another app's page needs the same look. */

/* Semantic series colours (--chart-income/spent/savings/plan) live in tokens.css. */

/* Cartesian frames: the plot keeps its aspect ratio; phones get a taller box so bars keep a
   readable height and the overlay labels have room. */
.chart__frame { overflow: visible; margin-bottom: var(--space-1); }
.chart__tick { line-height: 1; }
@media (max-width: 479.98px) {
  .chart__frame { aspect-ratio: 5 / 4 !important; }
}
.chart__grid { stroke-dasharray: 2 4; }
.chart__bar { transition: opacity var(--duration-fast), filter var(--duration-fast); }
.chart__bar:hover, .chart__bar:focus-visible { opacity: 0.85; }

/* Legends read as chips (the donut and flow legends keep their list layout). */
.chart__legend { gap: var(--space-2); margin-top: var(--space-3); }
.chart__legend-item {
  min-height: 26px;
  padding: 2px 10px 2px 7px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}
.chart__legend--list .chart__legend-item,
.chart__legend--inline .chart__legend-item { min-height: 0; padding: 0; border: 0; border-radius: 0; background: none; font-weight: var(--weight-normal, 400); }
.chart__legend--list { gap: var(--space-1); }
.chart__legend--list .chart__legend-item { min-height: 28px; }

/* The last-14-days strip (Today card). */
.chart--strip svg { display: block; overflow: visible; }
.chart__strip-bar--empty { opacity: 0.6; }

/* Sparkline inside a KPI card: fills the card width, area tint in the card's colour. */
.kpi__spark .chart--sparkline { display: block; width: 100%; height: 36px; }
.kpi__spark .chart--sparkline svg { display: block; width: 100%; height: 100%; }
.kpi__spark .chart__area { opacity: 0.14; }
.kpi__spark .chart__line { stroke-width: 2; }
.kpi__spark .chart--empty { display: none; }
.kpi__spark .chart__point { stroke: var(--color-surface); }

/* Tooltip-able points keep the pointer quiet. */
.chart__point, .chart__strip-bar { cursor: default; }

.kpi__delta { flex-wrap: wrap; }

/* Searchable combobox (controls.js) ------------------------------------- */
.combobox {
  position: relative;
}

.combobox__native {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  margin: 0;
  padding: 0;
  border: 0;
}

.combobox__input {
  padding-right: calc(var(--space-3) + 28px);
  text-overflow: ellipsis;
}

.combobox__toggle {
  position: absolute;
  right: var(--space-1);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-subtle);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease);
}

.combobox.is-open .combobox__toggle { transform: translateY(-50%) rotate(180deg); color: var(--color-primary-text); }

.combobox__pop {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-width: min(420px, calc(100vw - 2 * var(--space-4)));
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.combobox.is-above .combobox__pop { top: auto; bottom: calc(100% + 4px); }
.combobox.is-right .combobox__pop { left: auto; right: 0; }

.combobox__sheet-head { display: none; }

.combobox__list {
  list-style: none;
  margin: 0;
  padding: var(--space-1);
  max-height: 300px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.combobox__group {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.combobox__group + .combobox__group { display: none; }

.combobox__option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text);
}

.combobox__option.is-active { background: var(--color-primary-soft); color: var(--color-primary-soft-text); }
.combobox__option[aria-selected="true"] .combobox__label { font-weight: var(--weight-semibold); }
.combobox__option--empty { color: var(--color-text-muted); }
.combobox__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combobox__hint { font-size: var(--text-xs); color: var(--color-text-subtle); white-space: nowrap; }
.combobox__check { display: inline-flex; color: var(--color-primary-text); }

.combobox__create {
  margin-top: var(--space-1);
  border-top: 1px dashed var(--color-border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  color: var(--color-primary-text);
  font-weight: var(--weight-semibold);
}

.combobox__create.is-loading { opacity: 0.6; pointer-events: none; }

.combobox__empty {
  margin: 0;
  padding: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.combobox__empty:not([hidden]) + .combobox__list:empty { display: none; }

.combobox__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  background: var(--color-surface-overlay);
}

/* Phone: the list becomes a bottom sheet with its own search box. */
.combobox.is-sheet .combobox__backdrop:not([hidden]) { display: block; }

.combobox.is-sheet .combobox__pop {
  position: fixed;
  z-index: calc(var(--z-sheet) + 1);
  top: auto;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: none;
  max-height: min(80dvh, 640px);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border: 0;
  padding-bottom: var(--safe-bottom);
  animation: sheet-up var(--duration-slow) var(--ease-out);
}

.combobox.is-sheet .combobox__sheet-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.combobox.is-sheet .combobox__sheet-head::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  width: 40px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
  transform: translateX(-50%);
}

.combobox__sheet-search { flex: 1 1 auto; min-height: 44px; }

.combobox__sheet-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--color-surface-sunken);
  color: var(--color-text-muted);
  cursor: pointer;
}

.combobox.is-sheet .combobox__list { max-height: none; flex: 1 1 auto; padding: var(--space-2); }
.combobox.is-sheet .combobox__option { min-height: 48px; }

body.has-combobox-sheet,
body.has-picker-sheet { overflow: hidden; }

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* Date / time picker (controls.js) --------------------------------------- */
.picker {
  position: relative;
}

.picker__input { padding-right: calc(var(--space-3) + 32px); }
.picker__input[data-invalid] { border-color: var(--color-danger); }

.picker__button {
  position: absolute;
  right: var(--space-1);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-subtle);
  cursor: pointer;
}

.picker__button:hover,
.picker.is-open .picker__button { color: var(--color-primary-text); background: var(--color-primary-soft); }

.picker__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  background: var(--color-surface-overlay);
}

.picker.is-sheet .picker__backdrop:not([hidden]) { display: block; }

.picker__pop {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% + 4px);
  left: 0;
  width: 320px;
  max-width: calc(100vw - 2 * var(--space-4));
  padding: var(--space-3);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
}

.picker.is-above .picker__pop { top: auto; bottom: calc(100% + 4px); }
.picker.is-right .picker__pop { left: auto; right: 0; }
/* Inside a sheet or dialog the popover escapes the panel's clipping: fixed to the viewport
   (top/left set by controls.js from the field's position) and above the sheet layer. */
.picker.is-fixed .picker__pop { position: fixed; z-index: calc(var(--z-dialog) + 1); bottom: auto; right: auto; overflow-y: auto; overscroll-behavior: contain; }

.picker.is-sheet .picker__pop {
  position: fixed;
  z-index: calc(var(--z-sheet) + 1);
  top: auto;
  left: 0;
  right: 0;
  bottom: 0;
  width: auto;
  max-width: none;
  max-height: min(88dvh, 680px);
  overflow-y: auto;
  border: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-4) var(--space-4) calc(var(--space-4) + var(--safe-bottom));
  animation: sheet-up var(--duration-slow) var(--ease-out);
}

.picker__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.picker__heading { font-weight: var(--weight-semibold); color: var(--color-text); }

.picker__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.picker.is-sheet .picker__close { width: 40px; height: 40px; background: var(--color-surface-sunken); }

.picker__nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.picker__nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
}

.picker__nav-button:hover { background: var(--color-surface-sunken); }

.picker__selects { display: flex; flex: 1 1 auto; gap: var(--space-1); min-width: 0; }

.picker__select {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 36px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--color-surface-sunken);
  color: var(--color-text);
  font: inherit;
  font-weight: var(--weight-semibold);
  text-align: center;
}

.picker__select--year { flex: 0 0 auto; }
.picker__select:focus-visible { outline: 3px solid var(--color-border-focus); outline-offset: 1px; }

.picker__weekdays,
.picker__grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
}

.picker__weekdays span {
  padding: var(--space-1) 0;
  text-align: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-subtle);
}

.picker__day {
  aspect-ratio: 1;
  min-height: 36px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.picker.is-sheet .picker__day { min-height: 44px; }
.picker__day:hover { background: var(--color-surface-sunken); }
.picker__day.is-outside { color: var(--color-text-subtle); }
.picker__day.is-today { box-shadow: inset 0 0 0 1px var(--color-primary); font-weight: var(--weight-semibold); }
.picker__day.is-selected { background: var(--color-primary); color: var(--color-text-on-primary); font-weight: var(--weight-semibold); }
.picker__day.is-selected:hover { background: var(--color-primary); }
.picker__day:disabled { opacity: 0.35; cursor: not-allowed; }
.picker__day:focus-visible { outline: 3px solid var(--color-border-focus); outline-offset: 1px; }

.picker__time {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.picker--time .picker__time { margin-top: 0; }

.picker__col-wrap { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.picker__col-label { font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--color-text-subtle); text-align: center; }

.picker__col {
  max-height: 180px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-type: y proximity;
  padding: var(--space-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  display: grid;
  gap: 2px;
}

.picker--time .picker__col { max-height: 240px; }
.picker.is-sheet .picker__col { max-height: 220px; }

.picker__slot {
  min-height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  scroll-snap-align: center;
  cursor: pointer;
}

.picker__slot:hover { background: var(--color-surface-sunken); }
.picker__slot.is-selected { background: var(--color-primary); color: var(--color-text-on-primary); font-weight: var(--weight-semibold); }
.picker__slot:focus-visible { outline: 3px solid var(--color-border-focus); outline-offset: 1px; }

.picker__footer {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-3);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

.picker__spacer { flex: 1 1 auto; }

@media (prefers-reduced-motion: reduce) {
  .combobox.is-sheet .combobox__pop,
  .picker.is-sheet .picker__pop { animation: none; }
}

/* ==========================================================================================
   Screen 1 components (docs/REDESIGN.md §1): summary card, money row, figures, accordion,
   step progress, group labels, action tiles. Older class names stay as aliases above.
   ========================================================================================== */

/* Summary card internals: a 2×2 grid of figures, a divider, then a highlighted row. */
.summary-card__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-3);
}

.summary-card__grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (min-width: 640px) {
  .summary-card__grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.summary-card__item { min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.summary-card__label {
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.summary-card__value {
  /* Title size from 440px up; shrinks with the viewport so a seven-digit amount fits a 2-up
   * column on a 360px phone. Wraps only between the currency code and the number. */
  font-size: clamp(var(--text-heading), 5vw, var(--text-title));
  line-height: var(--leading-title);
  color: var(--color-text);
  white-space: normal;
  overflow-wrap: normal;
}

.summary-card__value--display { font-size: var(--text-hero); line-height: var(--leading-display); }
.summary-card__value--success { color: var(--color-hero-success); }
.summary-card__value--warning { color: var(--color-hero-warning); }
.summary-card__value--danger { color: var(--color-hero-danger); }

.summary-card__meta {
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  color: var(--color-text-muted);
}

.summary-card__divider { border: 0; border-top: 1px solid var(--color-hero-border); margin: var(--space-4) 0; }
.summary-card__row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2) var(--space-4); }
.summary-card__foot { margin-top: var(--space-3); font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }
.summary-card .progress { margin-top: var(--space-3); }

/* Money row: avatar initial · title · meta line · amount right with a small status under it. */
.money-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-2) 0;
  color: inherit;
  text-decoration: none;
}

.money-row + .money-row { border-top: 1px solid var(--color-border); }
a.money-row:hover,
button.money-row:hover { text-decoration: none; }
a.money-row:hover .money-row__title { color: var(--color-primary-text); }
.list > .money-row,
.card > .money-row { padding-inline: var(--card-padding); }
.card > .money-row { margin-inline: calc(-1 * var(--card-padding)); }

.money-row__avatar {
  --avatar-size: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: var(--radius-full);
  background: var(--color-teal-soft);
  color: var(--color-teal-soft-text);
  font-family: var(--font-display);
  font-weight: var(--weight-display);
  font-size: var(--text-label);
  flex-shrink: 0;
}

.money-row__avatar .icon { width: 18px; height: 18px; }
.money-row__body { flex: 1 1 auto; min-width: 0; }

.money-row__title {
  display: block;
  font-weight: var(--weight-medium);
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.money-row__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 var(--space-2);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  color: var(--color-text-muted);
}

.money-row__meta > * + *::before { content: "·"; margin-right: var(--space-2); color: var(--color-border-strong); }

.money-row__trailing {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
  text-align: right;
}

.money-row__amount { font-size: var(--text-body); white-space: nowrap; color: var(--color-text); }
.money-row__amount--positive { color: var(--color-success); }
.money-row__amount--danger { color: var(--color-danger); }
.money-row__amount--muted { color: var(--color-text-muted); }

.money-row__status {
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.money-row__status--success,
.money-row__status--paid,
.money-row__status--received { color: var(--color-success); }
.money-row__status--warning,
.money-row__status--pending { color: var(--color-warning); }
.money-row__status--danger { color: var(--color-danger); }
.money-row__status--teal { color: var(--color-teal); }

/* Figures: two to four label/value pairs side by side ("Planned income / Planned spend / Spent"). */
.figure-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: var(--space-3);
}

.figure-row--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.figure-row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.figure-row--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (min-width: 640px) {
  .figure-row--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Phones: three figures side by side cannot hold a seven-digit amount in Roboto 700 at 16px
 * (~125px in a ~91px column), so the third figure drops under the first two, full width. */
@media (max-width: 639.98px) {
  .figure-row--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .figure-row--3 > :nth-child(3n) { grid-column: 1 / -1; }
}

.figure { min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.figure__label {
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.figure__value {
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--color-text);
  white-space: normal;
  overflow-wrap: normal; /* never breaks inside the digits: at worst "RWF" / "1,250,000" */
}

.figure__value--success { color: var(--color-success); }
.figure__value--warning { color: var(--color-warning); }
.figure__value--danger { color: var(--color-danger); }
.figure__value--muted { color: var(--color-text-muted); }
.figure__meta { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }

/* KPI tile (desktop overview): label, value, formula caption; `.stat`/`.kpi` keep working. */
.kpi-tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--card-padding);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  min-width: 0;
}

.kpi-tile__label { font-size: var(--text-caption); line-height: var(--leading-caption); font-weight: var(--weight-medium); color: var(--color-text-muted); }
.kpi-tile__value { font-family: var(--font-numeric); font-weight: var(--weight-display); font-size: clamp(var(--text-heading), 4.6vw, var(--text-title)); line-height: var(--leading-title); letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; white-space: normal; overflow-wrap: normal; }
.kpi-tile__value--success { color: var(--color-success); }
.kpi-tile__value--warning { color: var(--color-warning); }
.kpi-tile__value--danger { color: var(--color-danger); }
.kpi-tile__caption { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.kpi-tile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }

@media (min-width: 900px) {
  .kpi-tile-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 399.98px) {
  .kpi-tile { padding: var(--space-3); } /* 2-up tiles keep ~134px for an eight-digit figure */
}

/* Accordion: a card that opens (<details class="card accordion"><summary class="card__summary">…). */
details.card > summary,
.card__summary,
.accordion__summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-target);
  margin: calc(-1 * var(--space-4));
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  list-style: none;
  border-radius: inherit;
}

details.card > summary::-webkit-details-marker,
.card__summary::-webkit-details-marker { display: none; }

@media (min-width: 640px) {
  details.card > summary,
  .card__summary,
  .accordion__summary { margin: calc(-1 * var(--space-6)); padding: var(--space-4) var(--space-6); }
}

details.card[open] > summary,
.accordion[open] > .accordion__summary { margin-bottom: 0; border-bottom: 1px solid var(--color-border); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
details.card[open] > summary + * { margin-top: var(--space-4); }

.card__summary-body,
.accordion__body { flex: 1 1 auto; min-width: 0; }

.card__summary-title,
.accordion__title {
  display: block;
  font-family: var(--font-display);
  font-weight: var(--weight-display);
  font-size: var(--text-body);
  letter-spacing: var(--tracking-tight);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card__summary-meta,
.accordion__meta { display: block; font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }
.card__summary-meta--warning { color: var(--color-warning); }
.card__summary-meta--success { color: var(--color-success); }
.card__summary-meta--danger { color: var(--color-danger); }

.card__summary-amounts,
.accordion__amounts { font-size: var(--text-label); line-height: var(--leading-label); color: var(--color-text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.card__summary-amounts strong { color: var(--color-text); }

.card__summary-chevron,
.accordion__chevron { color: var(--color-text-subtle); flex-shrink: 0; transition: transform var(--duration-fast) var(--ease); }
details[open] > summary .card__summary-chevron,
details[open] > summary .accordion__chevron { transform: rotate(180deg); }

/* Item group inside an accordion ("Rice · 3 entries — RWF 39,000"). */
.item-group { padding-top: var(--space-3); }
.item-group + .item-group { margin-top: var(--space-3); border-top: 1px solid var(--color-border); }
.item-group__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.item-group__title { font-weight: var(--weight-semibold); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-group__title small { font-weight: var(--weight-regular); color: var(--color-text-muted); margin-left: var(--space-1); }
.item-group__total { font-size: var(--text-label); font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--color-text-muted); }
.item-group .money-row { min-height: 52px; padding-block: var(--space-2); }

/* Step progress bar for wizards: "Step 1 of 2" + a thin bar. */
.step-progress { display: grid; gap: var(--space-2); }
.step-progress__label { display: flex; justify-content: space-between; gap: var(--space-3); font-size: var(--text-caption); line-height: var(--leading-caption); font-weight: var(--weight-medium); color: var(--color-text-muted); }
.step-progress__track { height: 4px; border-radius: var(--radius-full); background: var(--color-neutral-soft); overflow: hidden; }
.step-progress__fill { display: block; height: 100%; width: var(--step-progress, 50%); border-radius: inherit; background: var(--color-primary); transition: width var(--duration-slow) var(--ease-out); }

/* Group label above a list ("FRI 17 OCT", "RECENTLY USED", "MY HOUSEHOLDS · 2"). */
.group-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin: var(--space-4) 0 var(--space-2);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.group-label:first-child { margin-top: 0; }
.group-label__total { font-weight: var(--weight-medium); letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }

/* Action tiles (Record purchase · Quick expense · Add income) and category tiles. */
.action-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
.action-tiles--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.action-tiles--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (min-width: 640px) {
  .action-tiles--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.action-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  min-height: 84px;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}

.action-tile:hover { text-decoration: none; border-color: var(--color-border-strong); }

.action-tile__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
}

.action-tile--teal .action-tile__icon { background: var(--color-teal-soft); color: var(--color-teal-soft-text); }
.action-tile--success .action-tile__icon { background: var(--color-success-soft); color: var(--color-success-soft-text); }
.action-tile--warning .action-tile__icon { background: var(--color-warning-soft); color: var(--color-warning-soft-text); }
.action-tile__label { font-size: var(--text-label); line-height: var(--leading-label); font-weight: var(--weight-semibold); }
.action-tile__meta { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }
.action-tile--primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-text-on-primary); }
.action-tile--primary .action-tile__icon { background: var(--overlay-light); color: inherit; }
.action-tile--primary .action-tile__meta { color: inherit; opacity: 0.8; }

/* Filter chips row (alias of .filter-bar) with "Filters · 2" and active-filter × chips. */
.filter-chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: var(--space-1) 0 var(--space-2);
  margin-bottom: var(--space-3);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.filter-chips::-webkit-scrollbar { display: none; }
.filter-chips > * { flex-shrink: 0; }
.chip__remove { display: inline-flex; margin-left: 2px; margin-right: -4px; color: inherit; opacity: 0.7; }
.chip__remove:hover { opacity: 1; }
a.chip .icon,
button.chip .icon { width: 16px; height: 16px; }

/* Chips row inside forms (contributor chips, period chips): selectable pills. */
.chip-select { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip-select label { position: relative; }
.chip-select input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chip-select input + span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--control-sm);
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: var(--text-label);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.chip-select input:checked + span { background: var(--color-primary-soft); border-color: var(--color-primary); color: var(--color-primary-soft-text); }
.chip-select input:focus-visible + span { outline: 3px solid var(--color-border-focus); outline-offset: 2px; }

/* Note boxes (the amber "Counts as unplanned…" and red "This would put Food over" cards). */
.note {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  font-size: var(--text-label);
  line-height: var(--leading-label);
}

.note__title { font-weight: var(--weight-semibold); }
.note--warning { background: var(--color-warning-soft); border-color: color-mix(in srgb, var(--color-warning) 30%, transparent); color: var(--color-warning-soft-text); }
.note--danger { background: var(--color-danger-soft); border-color: var(--color-danger-border); color: var(--color-danger-soft-text); }
.note--success { background: var(--color-success-soft); border-color: color-mix(in srgb, var(--color-success) 30%, transparent); color: var(--color-success-soft-text); }
.note--info { background: var(--color-primary-soft); border-color: color-mix(in srgb, var(--color-primary) 30%, transparent); color: var(--color-primary-soft-text); }
.note--teal { background: var(--color-teal-soft); border-color: color-mix(in srgb, var(--color-teal) 30%, transparent); color: var(--color-teal-soft-text); }
.note a { color: inherit; text-decoration: underline; font-weight: var(--weight-medium); }
/* "Lock Debts with a 4-digit PIN · Set up PIN" under a module's page head (accounts/partials/pin_prompt.html) */
.pin-prompt { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.pin-prompt__text { display: inline-flex; align-items: center; gap: var(--space-2); flex: 1 1 14rem; min-width: 0; }
.pin-prompt__action { margin: 0; flex: none; }
.pin-prompt__action .button { white-space: nowrap; }
.pin-length-note { display: flex; align-items: center; gap: var(--space-2); margin: 0; }
.note .kv { border-color: color-mix(in srgb, currentColor 20%, transparent); font-size: inherit; }

/* Header meta line under a title: "Monthly · 1 – 31 Oct 2026" + a status chip. */
.page-header__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin-top: var(--space-1);
  font-size: var(--text-label);
  line-height: var(--leading-label);
  color: var(--color-text-muted);
}

/* Members list row (role · counts · amount). */
.member-row { display: flex; align-items: center; gap: var(--space-3); min-height: 56px; padding: var(--space-2) 0; }
.member-row + .member-row { border-top: 1px solid var(--color-border); }
.member-row__body { flex: 1 1 auto; min-width: 0; }
.member-row__name { font-weight: var(--weight-medium); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-row__meta { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }
.member-row__meta--warning { color: var(--color-warning); }
.member-row__amount { flex-shrink: 0; text-align: right; }

/* =====================================================================
 * Round 7 contract (docs/DESIGN-DIRECTION.md §3): the screenshot-driven components.
 * Class names are fixed; page CSS adds layout only. Everything above keeps working.
 * ===================================================================== */

/* Eyebrow: small-caps section label ("TOTAL BUDGET", "RECENT TRANSACTIONS"). */
.eyebrow {
  display: block;
  font-size: var(--text-eyebrow);
  line-height: 1.45;
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.eyebrow--primary { color: var(--color-primary-text); }
.eyebrow + * { margin-top: var(--space-1); }

/* Icon tiles: a 40px rounded pastel square (or circle) holding a category / transaction icon. */
.icon-tile {
  --tile-bg: var(--tile-sky);
  --tile-ink: var(--tile-sky-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--tile-bg);
  color: var(--tile-ink);
}

.icon-tile .icon { width: 20px; height: 20px; }
.icon-tile--sm { width: 32px; height: 32px; border-radius: var(--radius-sm); }
.icon-tile--sm .icon { width: 16px; height: 16px; }
.icon-tile--lg { width: 48px; height: 48px; border-radius: var(--radius-lg); }
.icon-tile--lg .icon { width: 24px; height: 24px; }
.icon-tile--circle { border-radius: var(--radius-full); }
.icon-tile--yellow { --tile-bg: var(--tile-yellow); --tile-ink: var(--tile-yellow-ink); }
.icon-tile--pink { --tile-bg: var(--tile-pink); --tile-ink: var(--tile-pink-ink); }
.icon-tile--sky { --tile-bg: var(--tile-sky); --tile-ink: var(--tile-sky-ink); }
.icon-tile--mint { --tile-bg: var(--tile-mint); --tile-ink: var(--tile-mint-ink); }
.icon-tile--lilac { --tile-bg: var(--tile-lilac); --tile-ink: var(--tile-lilac-ink); }
.icon-tile--peach { --tile-bg: var(--tile-peach); --tile-ink: var(--tile-peach-ink); }
.icon-tile--primary { --tile-bg: var(--color-primary-soft); --tile-ink: var(--color-primary-soft-text); }
.icon-tile--success { --tile-bg: var(--color-success-soft); --tile-ink: var(--color-success-soft-text); }
.icon-tile--danger { --tile-bg: var(--color-danger-soft); --tile-ink: var(--color-danger-soft-text); }
.icon-tile--warning { --tile-bg: var(--color-warning-soft); --tile-ink: var(--color-warning-soft-text); }
.icon-tile--neutral { --tile-bg: var(--color-neutral-soft); --tile-ink: var(--color-neutral-soft-text); }
.icon-tile--filled { --tile-bg: var(--color-primary); --tile-ink: var(--color-on-primary); }

/* Amounts: income green, spending red, totals ink; 700 with tabular numerals. --signed adds the
 * ↙ (in) / ↗ (out) arrow the screenshots put beside signed totals. */
.amount {
  font-family: var(--font-numeric);
  font-weight: var(--weight-display);
  font-variant-numeric: tabular-nums;
  font-feature-settings: var(--font-features-numeric);
  letter-spacing: var(--tracking-tight);
  white-space: nowrap;
  color: var(--color-text);
}

.amount--in { color: var(--color-income); }
.amount--out { color: var(--color-expense); }
.amount--neutral { color: var(--color-text); }
.amount--muted { color: var(--color-text-muted); }
.amount--sm { font-size: var(--text-label); }
.amount--lg { font-size: var(--text-title); line-height: var(--leading-title); }
.amount--xl { font-size: var(--text-hero); line-height: var(--leading-display); }
.amount--signed.amount--in::before { content: "↙ "; }
.amount--signed.amount--out::before { content: "↗ "; }
.amount__code { font-size: 0.75em; font-weight: var(--weight-medium); color: var(--color-text-muted); margin-right: 0.2em; }

/* Hero card: the saturated primary card with white text (Home summary, budget total). It is
 * the same thing as .summary-card / .card--hero, so the hero tokens apply to all three. */
.hero-card {
  --color-text: var(--color-hero-text);
  --color-text-muted: var(--color-hero-text-muted);
  --color-text-subtle: var(--color-hero-text-subtle);
  --color-border: var(--color-hero-border);
  --color-border-strong: var(--color-hero-text-subtle);
  --color-surface-sunken: var(--color-hero-surface);
  --color-neutral-soft: var(--color-hero-surface);
  --color-primary-text: var(--color-hero-primary);
  --color-success: var(--color-hero-success);
  --color-success-bright: var(--color-hero-success);
  --color-income: var(--color-hero-success);
  --color-warning: var(--color-hero-warning);
  --color-warning-bright: var(--color-hero-warning);
  --color-danger: var(--color-hero-danger);
  --color-danger-bright: var(--color-hero-danger);
  --color-expense: var(--color-hero-danger);
  --color-teal: var(--color-hero-teal);
  --color-money-positive: var(--color-hero-success);
  --color-money-negative: var(--color-hero-text);
  position: relative;
  overflow: hidden;
  padding: var(--space-4);
  border-radius: var(--radius-xl);
  background: var(--color-hero-bg);
  background-image: linear-gradient(135deg, var(--color-hero-bg) 0%, var(--color-hero-bg-end) 100%);
  color: var(--color-hero-text);
  box-shadow: var(--shadow-card);
}

.hero-card > * { position: relative; }
.hero-card a:not([class]) { color: inherit; text-decoration: underline; }
.hero-card .eyebrow,
.hero-card__label { color: var(--color-hero-text-muted); }
.hero-card__label { display: block; font-size: var(--text-eyebrow); line-height: 1.45; font-weight: var(--weight-medium); letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; }

.hero-card__value {
  display: block;
  margin-top: var(--space-1);
  font-family: var(--font-numeric);
  font-weight: var(--weight-display);
  font-size: var(--text-hero);
  line-height: var(--leading-display);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
  font-feature-settings: var(--font-features-numeric);
  color: var(--color-hero-text);
  white-space: normal;
  overflow-wrap: normal;
}

.hero-card__value--sm { font-size: var(--text-title); line-height: var(--leading-title); }
.hero-card__meta { display: block; margin-top: var(--space-1); font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-hero-text-muted); }
.hero-card__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin-top: var(--space-4); }
.hero-card__grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.hero-card__item { min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); background: var(--color-hero-surface); }
.hero-card__item .hero-card__value { font-size: var(--text-heading); line-height: var(--leading-heading); margin-top: 0; }
.hero-card__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-4); margin-top: var(--space-3); }
.hero-card__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.hero-card .button--primary { --button-bg: var(--color-hero-text); --button-fg: var(--color-primary); --button-border: var(--color-hero-text); }
.hero-card .button--primary:hover { background: var(--color-hero-text); filter: brightness(0.96); }
.hero-card .button--secondary,
.hero-card .button--ghost { --button-bg: var(--color-hero-surface); --button-fg: var(--color-hero-text); --button-border: var(--color-hero-border); }
.hero-card .button--secondary:hover,
.hero-card .button--ghost:hover { background: var(--color-hero-border); }
.hero-card .chip,
.hero-card .pill { background: var(--color-hero-surface); color: var(--color-hero-text); }
.hero-card .progress { background: var(--color-hero-border); }
.hero-card .progress__bar { background: var(--color-hero-text); }
.hero-card .ring__track { stroke: var(--color-hero-border); }
.hero-card .ring__value { stroke: var(--color-hero-text); }
.hero-card .ring__label { color: var(--color-hero-text); }
.hero-card .icon-tile { background: var(--color-hero-surface); color: var(--color-hero-text); }
.hero-card .amount { color: var(--color-hero-text); }
/* White-surface children keep readable ink inside the blue hero (.hero-card__item is the in-hero
 * tile; a .stat-tile that lands in a hero restores its tokens too). */
.hero-card :is(.stat, .stat-tile, .banner, .list, .table-wrap, .card) {
  --color-text: var(--color-on-surface);
  --color-text-muted: var(--color-on-surface-muted);
  --color-text-subtle: var(--color-on-surface-subtle);
  --color-border: var(--color-on-surface-border);
  --color-primary-text: var(--color-on-surface-primary);
  --color-success: var(--color-on-surface-success);
  --color-warning: var(--color-on-surface-warning);
  --color-danger: var(--color-on-surface-danger);
  color: var(--color-text);
}

.hero-card--ink { --color-hero-bg: var(--color-surface-inverse); --color-hero-bg-end: var(--color-surface-inverse); }
html[data-resolved-theme="dark"] .hero-card { border: 1px solid var(--color-hero-border); }

/* Pills: tiny rounded labels ("Recommended", "Upcoming"). */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-neutral-soft);
  color: var(--color-neutral-soft-text);
  font-size: var(--text-eyebrow);
  line-height: 1;
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  white-space: nowrap;
}

.pill--recommended,
.pill--primary { background: var(--color-primary); color: var(--color-on-primary); }
.pill--success { background: var(--color-success-soft); color: var(--color-success-soft-text); }
.pill--warning { background: var(--color-warning-soft); color: var(--color-warning-soft-text); }
.pill--danger { background: var(--color-danger-soft); color: var(--color-danger-soft-text); }
.pill--info { background: var(--color-primary-soft); color: var(--color-primary-soft-text); }
.pill .icon { width: 12px; height: 12px; }

/* Generic row: icon · title · meta · amount (transactions, budgets, bills, stock items). */
.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-2) 0;
  color: inherit;
  text-decoration: none;
}

.list-row + .list-row { border-top: 1px solid var(--color-border); }
a.list-row:hover,
button.list-row:hover { text-decoration: none; }
a.list-row:hover .list-row__title,
button.list-row:hover .list-row__title { color: var(--color-primary-text); }
.list-row__icon { flex-shrink: 0; }
.list-row__body { flex: 1 1 auto; min-width: 0; }
.list-row__title { display: block; font-weight: var(--weight-medium); color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-2); font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }
.list-row__meta > * + *::before { content: "·"; margin-right: var(--space-2); color: var(--color-border-strong); }
.list-row__trailing { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; text-align: right; }
/* Trailing actions side by side (icon buttons, a small button and a chip), right-aligned. */
.list-row__trailing--row { flex-direction: row; align-items: center; gap: var(--space-1); }
.list-row__trailing--row > .button--sm,
.list-row__trailing--row > .icon-button--sm { flex-shrink: 0; }
.list-row__amount { font-family: var(--font-numeric); font-weight: var(--weight-display); font-variant-numeric: tabular-nums; font-feature-settings: var(--font-features-numeric); letter-spacing: var(--tracking-tight); white-space: nowrap; color: var(--color-text); }
.list-row__amount--in { color: var(--color-income); }
.list-row__amount--out { color: var(--color-expense); }
.list-row__amount--muted { color: var(--color-text-muted); }
.list-row__status { font-size: var(--text-caption); line-height: var(--leading-caption); font-weight: var(--weight-medium); color: var(--color-text-muted); white-space: nowrap; }
.list-row__chevron { color: var(--color-text-subtle); flex-shrink: 0; }
/* Inside a padded .card the rows span the content box (no negative margins: the first and last
 * rows trim their own block padding so the card padding stays even); inside .card--flush or a
 * .list they run edge to edge with the card padding as their inline padding. */
.card--flush > .list-row,
.card--flush > .day-group > .list-row,
.card--flush > .day-group__list > .list-row,
.list > .list-row { padding-inline: var(--card-padding); }
.card--flush > .day-group { padding-inline: var(--card-padding); }
.card--flush > .day-group > .list-row,
.card--flush > .day-group__list > .list-row { padding-inline: 0; }
.card:not(.card--flush) > .list-row:first-child { padding-top: var(--space-2); }
.card:not(.card--flush) > .day-group:first-child > .day-group__header { padding-top: 0; }
.card:not(.card--flush) > .list-row:last-child { padding-bottom: var(--space-2); }

/* Transactions grouped by day: the header shows the day's income (green) and spend (red). */
.day-group { display: block; }
.day-group + .day-group { margin-top: var(--space-4); }
.day-group__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1) 0 var(--space-2);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.day-group__title { text-transform: uppercase; letter-spacing: var(--tracking-eyebrow); font-size: var(--text-eyebrow); }
.day-group__totals { display: inline-flex; gap: var(--space-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.day-group__in { color: var(--color-income); }
.day-group__out { color: var(--color-expense); }
.day-group__in::before { content: "↙ "; }
.day-group__out::before { content: "↗ "; }
.day-group__list { display: flex; flex-direction: column; }
.card > .day-group__header { padding-inline: 0; }

/* Budget row: icon · name · "spent / limit" · pace-coloured bar · "80% used" · "RWF 20,000 left". */
.budget-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "icon body amount" "bar bar bar" "captions captions captions"; align-items: center; column-gap: var(--space-3); row-gap: var(--space-2); min-height: 56px; padding: var(--space-3) 0; }
.budget-row > .list-row__icon,
.budget-row > .icon-tile { grid-area: icon; }
.budget-row > .list-row__body { grid-area: body; }
.budget-row > .list-row__amount,
.budget-row > .list-row__trailing,
.budget-row__amounts { grid-area: amount; text-align: right; font-size: var(--text-label); line-height: var(--leading-label); color: var(--color-text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.budget-row__amounts strong { font-family: var(--font-numeric); font-weight: var(--weight-display); color: var(--color-text); }
.budget-row__bar { grid-area: bar; position: relative; height: 6px; border-radius: var(--radius-pill); background: var(--color-surface-sunken); overflow: hidden; }
.budget-row__bar > span,
.budget-row__bar-fill { position: absolute; inset: 0 auto 0 0; width: var(--bar, 0%); border-radius: inherit; background: var(--color-primary); transition: width var(--duration-slow) var(--ease-out); }
.budget-row__bar--ok > span,
.budget-row__bar--ok .budget-row__bar-fill { background: var(--color-income-bright); }
.budget-row__bar--warn > span,
.budget-row__bar--warn .budget-row__bar-fill { background: var(--color-warning-bright); }
.budget-row__bar--over > span,
.budget-row__bar--over .budget-row__bar-fill { background: var(--color-expense-bright); width: 100%; }
.budget-row__captions { grid-area: captions; display: flex; justify-content: space-between; gap: var(--space-3); font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); font-variant-numeric: tabular-nums; margin-top: calc(-1 * var(--space-1)); }
.budget-row__captions > :last-child { text-align: right; }
.budget-row__captions--ok > :first-child { color: var(--color-income); }
.budget-row__captions--warn > :first-child { color: var(--color-warning); }
.budget-row__captions--over { color: var(--color-expense); }
.budget-row + .budget-row { border-top: 1px solid var(--color-border); }
.budget-row__figures { grid-area: amount; text-align: right; font-size: var(--text-label); line-height: var(--leading-label); color: var(--color-text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.budget-row__figures strong { font-family: var(--font-numeric); font-weight: var(--weight-display); color: var(--color-text); }
.card--flush > .budget-row,
.list > .budget-row { padding-inline: var(--card-padding); }

/* Insight card parts (the tints are defined with the base rule above). */
.insight-card__eyebrow { display: block; font-size: var(--text-eyebrow); line-height: 1.45; font-weight: var(--weight-medium); letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; color: var(--insight-color); margin-bottom: 2px; }
.insight-card__body { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: 2px; }
.insight-card__metric { display: inline-flex; align-items: center; gap: var(--space-1); margin-top: var(--space-2); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text); font-variant-numeric: tabular-nums; }
.insight-card__metric strong { font-family: var(--font-numeric); font-weight: var(--weight-display); }
.insight-card__metric--in strong { color: var(--color-income); }
.insight-card__metric--out strong { color: var(--color-expense); }
.insight-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); }
.insight-card .pill--recommended { flex-shrink: 0; }
.insight-card--plain { --insight-tint: var(--color-surface); border-color: var(--color-border); box-shadow: var(--shadow-card); }

/* Bills: a card with a status word, name, amount and a blue check badge once paid. */
.bill-card {
  --bill-color: var(--color-text-muted);
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--card-padding);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  color: inherit;
  text-decoration: none;
}

a.bill-card:hover { text-decoration: none; border-color: var(--color-border-strong); }
.bill-card__body { min-width: 0; }
.bill-card__status { display: block; font-size: var(--text-eyebrow); line-height: 1.45; font-weight: var(--weight-medium); letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; color: var(--bill-color); }
.bill-card__name,
.bill-card__title { display: block; font-weight: var(--weight-medium); color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bill-card__meta { display: block; font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }
.bill-card__amount { font-family: var(--font-numeric); font-weight: var(--weight-display); font-variant-numeric: tabular-nums; font-feature-settings: var(--font-features-numeric); white-space: nowrap; text-align: right; }
.bill-card__check { display: none; width: 22px; height: 22px; border-radius: var(--radius-full); background: var(--color-primary); color: var(--color-on-primary); align-items: center; justify-content: center; flex-shrink: 0; }
.bill-card__check .icon { width: 14px; height: 14px; }
.bill-card--upcoming { --bill-color: var(--color-primary-text); }
.bill-card--due { --bill-color: var(--color-warning); }
.bill-card--overdue { --bill-color: var(--color-expense); border-color: var(--color-danger-border); }
.bill-card--paid { --bill-color: var(--color-income); }
.bill-card--paid .bill-card__check { display: inline-flex; }
.bill-card--paid .bill-card__amount { color: var(--color-text-muted); }

/* Big segmented choice (Expense · Income · Transfer): the active option is filled primary. */
.segmented-big {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: var(--space-1);
  padding: 4px;
  border-radius: var(--radius-lg);
  background: var(--color-surface-sunken);
}

.segmented-big__item,
.segmented-big > label,
.segmented-big > button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: var(--touch-target);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-label);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.segmented-big input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.segmented-big__item:hover { color: var(--color-text); }
.segmented-big__item.is-active,
.segmented-big__item[aria-pressed="true"],
.segmented-big__item[aria-checked="true"],
.segmented-big__item:has(input:checked) { background: var(--color-primary); color: var(--color-on-primary); box-shadow: var(--shadow-sm); }
.segmented-big__item:has(input:focus-visible),
.segmented-big__item:focus-visible { outline: 3px solid var(--color-border-focus); outline-offset: 2px; }
.segmented-big--in .segmented-big__item.is-active { background: var(--color-income-bright); color: var(--color-text-on-success); }
.segmented-big--out .segmented-big__item.is-active { background: var(--color-expense-bright); color: var(--color-text-on-danger); }

/* Category grid picker: circle tiles with a one-word label; the chosen one is outlined. */
.category-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.category-grid__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  min-height: 76px;
  padding: var(--space-2) var(--space-1);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-medium);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: border-color var(--duration-fast), background var(--duration-fast);
}

.category-grid__item input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.category-grid__item:hover { background: var(--color-surface-sunken); text-decoration: none; }
.category-grid__item .icon-tile { border-radius: var(--radius-full); width: 44px; height: 44px; }
.category-grid__item > span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-grid__item.is-selected,
.category-grid__item[aria-pressed="true"],
.category-grid__item:has(input:checked) { border-color: var(--color-primary); background: var(--color-primary-soft); color: var(--color-primary-soft-text); }
.category-grid__item:has(input:focus-visible),
.category-grid__item:focus-visible { outline: 3px solid var(--color-border-focus); outline-offset: 2px; }
.category-grid__item--more .icon-tile { background: var(--color-surface-sunken); color: var(--color-text-muted); border: 1px dashed var(--color-border-strong); }

@media (min-width: 640px) { .category-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 900px) { .category-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* Period switch: ‹ October 2026 › */
.period-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  max-width: 100%;
}

.period-switch__button,
.period-switch > a,
.period-switch > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target);
  height: var(--touch-target);
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
}

.period-switch__button:hover,
.period-switch > a:hover,
.period-switch > button:hover { background: var(--color-surface-sunken); color: var(--color-text); text-decoration: none; }
.period-switch__button[aria-disabled="true"],
.period-switch__button:disabled { opacity: 0.4; pointer-events: none; }
/* The label shrinks before the arrows do and may wrap to a second line on narrow phones; a
 * ".period-switch__suffix" (e.g. "· yours") disappears below 360px instead of being clipped. */
.period-switch__label { min-width: 0; flex: 1 1 auto; text-align: center; font-family: var(--font-display); font-weight: var(--weight-display); font-size: var(--text-heading); line-height: var(--leading-heading); letter-spacing: var(--tracking-tight); white-space: normal; overflow-wrap: anywhere; color: var(--color-text); }
.period-switch__label--nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.period-switch__suffix { font-weight: var(--weight-regular); color: var(--color-text-muted); white-space: nowrap; }

@media (max-width: 359.98px) {
  .period-switch__label { font-size: var(--text-body); line-height: var(--leading-body); }
  .period-switch__suffix { display: none; }
}
.period-switch--block { display: flex; width: 100%; justify-content: space-between; }
.period-switch--sm .period-switch__label { font-size: var(--text-label); line-height: var(--leading-label); }
.period-switch--sm .period-switch__button { width: var(--control-sm); height: var(--control-sm); }
.hero-card .period-switch__label,
.hero-card .period-switch__button { color: var(--color-hero-text); }
.hero-card .period-switch__button:hover { background: var(--color-hero-surface); }

/* Underline tabs under a header (.tabs__item is the contract name; .tab keeps working). */
.tabs__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: 0 var(--space-3);
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--color-text-muted);
  font: inherit;
  font-size: var(--text-label);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--duration-fast), border-color var(--duration-fast);
}

.tabs__item:hover { color: var(--color-text); text-decoration: none; }
.tabs__item.is-active,
.tabs__item[aria-selected="true"],
.tabs__item[aria-current] { color: var(--color-primary-text); border-bottom-color: var(--color-primary); font-weight: var(--weight-semibold); }
/* A count beside a tab label is a .chip (or .pill): "Expenses <span class="chip chip--sm">12</span>". */
.tabs__item .chip,
.tabs__item .pill { margin-left: 2px; }
.tabs__item.is-active .chip,
.tabs__item[aria-selected="true"] .chip { background: var(--color-primary-soft); color: var(--color-primary-soft-text); }
.tabs--block .tabs__item,
.tabs--block .tab { flex: 1 1 0; justify-content: center; }
.tabs--pills { border-bottom: 0; gap: var(--space-2); padding: 2px 0; }
.tabs--pills .tabs__item,
.tabs--pills .tab { min-height: var(--control-sm); padding: 0 var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-pill); margin-bottom: 0; background: var(--color-surface); }
.tabs--pills .tabs__item.is-active,
.tabs--pills .tab.is-active,
.tabs--pills .tabs__item[aria-selected="true"],
.tabs--pills .tab[aria-selected="true"] { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-primary); }

/* Stat tile: arrow + label + value ("Total spending", "Total income"). */
.stat-tile {
  --stat-color: var(--color-text);
  --stat-soft: var(--color-neutral-soft);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--card-padding);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  color: inherit;
  text-decoration: none;
}

a.stat-tile:hover { text-decoration: none; border-color: var(--color-border-strong); }
.stat-tile__arrow,
.stat-tile__icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex-shrink: 0; border-radius: var(--radius-full); background: var(--stat-soft); color: var(--stat-color); font-weight: var(--weight-display); font-size: var(--text-body); }
.stat-tile__body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.stat-tile__label { font-size: var(--text-caption); line-height: var(--leading-caption); font-weight: var(--weight-medium); color: var(--color-text-muted); overflow-wrap: normal; }
.stat-tile__value { font-family: var(--font-numeric); font-weight: var(--weight-display); font-size: clamp(var(--text-heading), 4.4vw, var(--text-title)); line-height: var(--leading-title); letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; font-feature-settings: var(--font-features-numeric); color: var(--stat-color); white-space: normal; overflow-wrap: normal; }
.stat-tile__meta { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }
/* A signed value may override the tile's tone (a negative cash on hand in a green tile reads red). */
.stat-tile__value.amount--out { color: var(--color-expense); }
.stat-tile__value.amount--in { color: var(--color-income); }
.stat-tile--in { --stat-color: var(--color-income); --stat-soft: var(--color-success-soft); }
.stat-tile--out { --stat-color: var(--color-expense); --stat-soft: var(--color-danger-soft); }
.stat-tile--primary { --stat-color: var(--color-primary-text); --stat-soft: var(--color-primary-soft); }
.stat-tile--warning { --stat-color: var(--color-warning); --stat-soft: var(--color-warning-soft); }
.stat-tile--in .stat-tile__arrow:empty::before { content: "↙"; }
.stat-tile--out .stat-tile__arrow:empty::before { content: "↗"; }
.stat-tile-grid,
.stat-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--card-gap); }
@media (min-width: 900px) { .stat-tile-grid--4, .stat-tiles--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* Desktop column grids: one column on phones, columns from 1024px (8/4 for main + side). */
.layout-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--card-gap); align-items: start; }
.layout-grid > * { min-width: 0; }
.layout-grid__main,
.layout-grid__side { min-width: 0; }

@media (min-width: 640px) {
  .layout-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .layout-grid { gap: var(--space-4); }
}

@media (min-width: 1024px) {
  .layout-grid { gap: var(--space-5); }
  .layout-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .layout-grid--main-side { grid-template-columns: minmax(0, 8fr) minmax(0, 4fr); }
  .layout-grid--side-main { grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); }
  .layout-grid--main-side > .layout-grid__side,
  .layout-grid--side-main > .layout-grid__side { position: sticky; top: calc(var(--topbar-height) + var(--space-4)); }
  .layout-grid__full { grid-column: 1 / -1; }
}

/* Data table (desktop lists): sticky header, right-aligned amounts, no zebra. On phones a list
 * renders .list-row instead: either two markup branches, or .data-table--switch + .list--switch
 * (the table shows from 1024px and the list below it). */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  font-size: var(--text-label);
  line-height: var(--leading-label);
}

.data-table th,
.data-table td { padding: var(--space-3) var(--space-4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--color-border); }
.data-table thead th { position: sticky; top: 0; z-index: 1; background: var(--color-surface); font-size: var(--text-eyebrow); line-height: 1.45; font-weight: var(--weight-medium); letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; color: var(--color-text-muted); white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--color-surface-sunken); }
.data-table .is-num,
.data-table .num,
.data-table th.is-num,
.data-table td.is-num,
.data-table [data-amount] { text-align: right; font-variant-numeric: tabular-nums; font-feature-settings: var(--font-features-numeric); white-space: nowrap; }
.data-table td.is-num,
.data-table td[data-amount] { font-family: var(--font-numeric); font-weight: var(--weight-display); }
.data-table .is-in { color: var(--color-income); }
.data-table .is-out { color: var(--color-expense); }
.data-table .is-muted { color: var(--color-text-muted); }
.data-table .is-actions { text-align: right; white-space: nowrap; }
.data-table__cell-main { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.data-table__cell-main .icon-tile { flex-shrink: 0; }
.data-table__title { font-weight: var(--weight-medium); color: var(--color-text); }
.data-table__meta { display: block; font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--color-text-muted); }
.data-table a.data-table__title:hover { color: var(--color-primary-text); }
.data-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-lg); }
.data-table--switch { display: none; }
.list--switch { display: block; }

@media (min-width: 1024px) {
  .data-table--switch { display: table; }
  .list--switch { display: none; }
}

/* A table that still lands on a phone scrolls sideways inside its own box instead of widening
 * the page (lists should render .list-row there; this is the safety net). */
@media (max-width: 1023.98px) {
  .data-table:not(.data-table--switch) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Page head: title (+ subtitle), actions on the right, an optional period switch and tabs below. */
.page-head { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.page-head__row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-2) var(--space-3); }
.page-head__title { font-family: var(--font-display); font-size: var(--text-title); line-height: var(--leading-title); font-weight: var(--weight-display); letter-spacing: var(--tracking-tight); min-width: 0; overflow-wrap: anywhere; }
.page-head__subtitle { color: var(--color-text-muted); font-size: var(--text-label); line-height: var(--leading-label); margin-top: 2px; }
.page-head__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.page-head__period { display: flex; align-items: center; }
.page-head__tabs { margin: var(--space-1) 0 0; }
.page-head__tabs .tabs,
.page-head .tabs { margin-bottom: 0; }
.page-head--center { align-items: center; text-align: center; }

@media (min-width: 900px) {
  .page-head { margin-bottom: var(--space-5); }
  .page-head__title { font-size: var(--text-display); line-height: var(--leading-display); }
}

/* The round primary "+": the bottom-nav centre on phones (.bottom-nav__add shares the class),
 * bottom-right on desktop pages that record. */
.fab,
.fab--icon { width: 56px; min-width: 56px; height: 56px; padding: 0; border-radius: var(--radius-full); background: var(--color-primary); color: var(--color-on-primary); box-shadow: var(--shadow-fab); }
.fab--label { width: auto; padding: 0 var(--space-5); gap: var(--space-2); font-weight: var(--weight-medium); }
.fab--static { position: static; }
.fab:hover { background: var(--color-primary-hover); }
.fab:active { transform: translateY(1px); }
.fab .icon { width: 26px; height: 26px; }
.bottom-nav__add.fab { position: static; min-width: 0; }

/* Day totals / lists inside cards sit flush to the card edge. */
.card > .day-group + .day-group { margin-top: var(--space-3); }

/* Card modifiers for the new surfaces. */
.card--tint-amber { background: var(--tint-amber); border-color: transparent; }
.card--tint-lilac { background: var(--tint-lilac); border-color: transparent; }
.card--tint-rose { background: var(--tint-rose); border-color: transparent; }
.card--tint-sky { background: var(--tint-sky); border-color: transparent; }
.card--flat { box-shadow: none; }
.card--ghost { background: transparent; border-color: transparent; box-shadow: none; padding: 0; }
.card__eyebrow { display: block; font-size: var(--text-eyebrow); line-height: 1.45; font-weight: var(--weight-medium); letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; color: var(--color-text-muted); }
.card > .eyebrow:first-child { margin-bottom: var(--space-1); }

/* Older tiles and KPI cards carry the same soft shadow as cards. */
.kpi,
.action-tile,
.stat { box-shadow: var(--shadow-card); }

/* Chip-select, segmented and combobox inputs line up with the 44px field height. */
.chip-select input + span { min-height: var(--control-sm); }
.combobox__input { min-height: var(--touch-target); }

/* Tooltip ({% tip "…" %} in apps/core/templatetags/ui.py; docs/DESIGN_SYSTEM.md "Tooltips").
 * .tip wraps a 16px info button (.tip__button, data-tip) and a hidden copy of the text the
 * button is described by (aria-describedby works on hidden content). app.js shows the text in one body-level
 * .tip-bubble on hover, focus or tap; any element with data-tip gets the same bubble. */
.tip { display: inline-flex; align-items: center; vertical-align: middle; margin-inline-start: var(--space-1); }
/* Wrap the heading's last word with its tip so the icon never drops onto a line of its own. */
.tip-anchor { white-space: nowrap; }
.tip__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  min-height: 0;
  padding: 0;
  margin: -4px 0;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  line-height: 1;
  cursor: help;
}
.tip__button .icon { width: 16px; height: 16px; }
.tip__button:hover,
.tip__button[aria-expanded="true"] { color: var(--color-primary-text); background: var(--color-primary-soft); }
.tip__button:focus-visible { outline: 3px solid var(--color-border-focus); outline-offset: 2px; }
@media (pointer: coarse) { .tip__button { width: 32px; height: 32px; margin: -8px -4px; } }
.tip-bubble {
  position: fixed;
  z-index: var(--z-toast);
  max-width: min(300px, calc(100vw - 32px));
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--chart-tooltip-bg);
  color: var(--chart-tooltip-text);
  font-family: var(--font-sans);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-regular);
  letter-spacing: 0;
  text-transform: none;
  white-space: normal;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}
.tip-bubble::after { content: ""; position: absolute; left: var(--tip-arrow, 50%); bottom: -5px; width: 10px; height: 10px; margin-left: -5px; background: inherit; transform: rotate(45deg); }
.tip-bubble[data-placement="bottom"]::after { bottom: auto; top: -5px; }
.tip-bubble[hidden] { display: none; }

/* Language switcher (templates/components/language_switcher.html): a compact select in the public
 * nav and drawer, text buttons in the footer and on the sign-in page, a <details> row in the
 * app menu. The buttons are real submits (no inline handlers), styled as links. */
.language-switcher { margin: 0; }
.language-switcher--select { display: inline-flex; align-items: center; gap: var(--space-1); }
.language-switcher__label { display: inline-flex; color: var(--color-text-muted); }
.language-switcher__select {
  width: auto;
  min-height: 36px;
  padding: var(--space-1) var(--space-6) var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  background-position: right var(--space-2) center;
}
.language-switcher__list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.language-switcher__option {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.language-switcher__option:hover { text-decoration: underline; }
.language-switcher__option[aria-current="true"] { font-weight: var(--weight-medium); color: var(--color-text); }
.language-switcher--menu > summary { list-style: none; }
.language-switcher--menu > summary::-webkit-details-marker { display: none; }
.language-switcher--menu[open] .language-switcher__chevron { transform: rotate(180deg); }
.language-switcher__form { display: contents; }
.language-switcher__row { padding-left: var(--space-6); }
.language-switcher__row .language-switcher__mark { --tile-bg: transparent; }
.language-switcher__row.is-current .list-row__title { color: var(--color-primary-text); }
.site-footer__languages .language-switcher__list { flex-direction: column; gap: var(--space-2); align-items: flex-start; }
.site-footer__languages .language-switcher__option[aria-current="true"] { color: inherit; }
.site-nav .language-switcher { margin-top: var(--space-2); }
.auth-languages .language-switcher__list { justify-content: center; font-size: var(--text-caption); }
