/*
 * Tandem layout and components. Colors come only from tokens.css.
 * Dynamic values (bar widths, heights) arrive as CSS custom properties set from JS.
 */

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

/* Hidden means hidden, even when a class sets display (e.g. .field is display: flex). */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

svg {
  display: block;
}

.num {
  font-variant-numeric: tabular-nums;
}

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

.text-a {
  color: var(--a-text);
}

.text-b {
  color: var(--b-text);
}

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: var(--s-4);
  top: -48px;
  z-index: 100;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  background: var(--primary-bg);
  color: var(--primary-fg);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: var(--s-4);
}

/* ---------- App frame ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  height: 100vh;
  padding: var(--s-5) var(--s-3) var(--s-4);
  background: var(--side-bg);
  color: var(--nav-off);
}

.side :focus-visible,
.topbar :focus-visible,
.drawer :focus-visible {
  outline-color: var(--focus-on-dark);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

/* The expand/collapse button exists only in the medium (icon rail) range. */
.side-toggle {
  display: none !important;
}

@media (min-width: 768px) and (max-width: 1023px) {
  .side-toggle {
    display: grid !important;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--s-2);
  color: var(--side-fg);
  text-decoration: none;
}

.brand .logo {
  flex: none;
  margin: -10px -8px -10px -12px; /* the mark fills ~60% of its 1024 viewBox; trim the empty edges */
}

.logo-a {
  fill: var(--logo-a);
}

.logo-ours {
  fill: var(--logo-ours);
}

.logo-b-stop1 {
  stop-color: var(--logo-b1);
}

.logo-b-stop2 {
  stop-color: var(--logo-b2);
}

.brand-name {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.nav-group + .nav-group {
  margin-top: var(--s-4);
}

.nav-group-label {
  padding: 0 var(--s-3) var(--s-1);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px var(--s-3);
  border-radius: 10px;
  color: var(--nav-off);
  font-size: var(--fs-md);
  text-decoration: none;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}

.nav-link svg {
  flex: none;
  width: 18px;
  height: 18px;
}

.nav-link:hover {
  background: var(--side-hover);
  color: var(--side-fg);
}

.nav-link[aria-current="page"] {
  background: var(--side-active);
  color: var(--side-fg);
  font-weight: 600;
}

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--sage);
  color: var(--evergreen);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* In the icon rail the count becomes a small dot on the icon (the number stays for screen readers). */
.rail .nav-link {
  position: relative;
}

.rail .nav-badge:not([hidden]) {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 0;
  width: 9px;
  height: 9px;
  padding: 0;
  overflow: hidden;
  color: transparent;
  line-height: 0;
}

.side-foot {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-2) 0;
  border-top: 1px solid var(--side-line);
}

.sync-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: var(--s-2);
  padding: 3px 10px;
  border: 1px solid var(--side-line);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
}

.sync-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mist);
}

.side-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

.avatars {
  display: flex;
  gap: 6px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: var(--fs-xs);
  font-weight: 700;
}

.avatar-a {
  background: var(--avatar-a-bg);
  color: var(--avatar-a-fg);
}

.avatar-b {
  background: var(--avatar-b-bg);
  color: var(--avatar-b-fg);
}

.side-btns {
  display: flex;
  gap: 6px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--side-line);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--nav-off);
  cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.icon-btn:hover {
  background: var(--side-hover);
  color: var(--side-fg);
}

.main {
  min-width: 0;
  padding: 28px var(--s-8) 48px;
}

.page {
  max-width: var(--content-max);
  view-transition-name: page;
}

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

.page-title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.page-title:focus {
  outline: none;
}

.page-sub {
  margin-top: var(--s-1);
  color: var(--muted);
}

/* ---------- Owner chips ---------- */
.owner-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border: 0;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

button.chip {
  cursor: pointer;
  transition: box-shadow var(--t-fast) ease, background-color var(--t-fast) ease;
}

.chip-all {
  background: var(--chip-all-bg);
  color: var(--chip-all-fg);
}

.chip-a {
  background: var(--chip-a-bg);
  color: var(--chip-a-fg);
}

.chip-b {
  background: var(--chip-b-bg);
  color: var(--chip-b-fg);
}

.chip-ours {
  background: var(--chip-ours-bg);
  color: var(--chip-ours-fg);
}

.chip-all[aria-pressed="false"] {
  background: transparent;
  color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--line);
}

.chip[aria-pressed="true"]:not(.chip-all) {
  box-shadow: inset 0 0 0 1.5px currentColor;
}

.chip-sm {
  padding: 2px 10px;
  font-size: var(--fs-xs);
}

/* Long names are cut with an ellipsis; the full name is in the tooltip and the accessible label. */
.chip-name {
  display: inline-block;
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

.chip-you {
  margin-left: 0.3em;
  font-weight: 500;
}

/* ---------- Owner badges on rows (initials in the person's own color) ---------- */
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
}

.badge-a {
  background: var(--chip-a-bg);
  color: var(--chip-a-fg);
}

.badge-b {
  background: var(--chip-b-bg);
  color: var(--chip-b-fg);
}

.badge-ours {
  background: var(--chip-ours-bg);
  color: var(--chip-ours-fg);
}

.badge-pair {
  display: inline-flex;
}

.badge-pair .badge {
  box-shadow: 0 0 0 2px var(--card);
}

.badge-pair .badge + .badge {
  margin-left: -7px;
}

/* ---------- Grids ---------- */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.grid {
  display: grid;
  gap: var(--s-4);
}

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

.grid-cards {
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 1000px) {
  .grid-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

/* ---------- Card and tile ---------- */
.card {
  min-width: 0;
  padding: var(--s-5) 22px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--card);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-2) var(--s-3);
  margin-bottom: var(--s-4);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
}

.card-sub {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.tile {
  display: flex;
  flex-direction: column;
}

.tile-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  color: var(--muted);
  font-size: var(--fs-sm);
}

.tile-value {
  margin: 6px 0 var(--s-3);
  font-size: var(--fs-num);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.tile-foot {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin-top: auto;
  font-size: var(--fs-sm);
}

.sample-tag {
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: var(--info-tint);
  color: var(--info-text);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- Progress bar ---------- */
.progress {
  height: 8px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: var(--track);
}

.progress-fill {
  width: var(--pct, 0%);
  height: 100%;
  border-radius: inherit;
  background: var(--bar, var(--progress));
  transition: width 300ms var(--ease);
}

.progress-a {
  --bar: var(--a-chart);
}

.progress-b {
  --bar: var(--b-chart);
}

.progress-savings {
  --bar: var(--savings);
}

/* ---------- Status label (dot + text, never color alone) ---------- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
}

.status::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot);
}

.status-ok {
  --dot: var(--ok);
  color: var(--ok-text);
}

.status-watch {
  --dot: var(--watch);
  color: var(--watch-text);
}

.status-risk {
  --dot: var(--risk);
  color: var(--risk-text);
}

/* ---------- Banner (static, never flashing) ---------- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
}

.banner svg {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.banner-info {
  background: var(--info-tint);
  color: var(--info-text);
}

.banner-watch {
  background: var(--watch-tint);
  color: var(--watch-text);
}

.banner-risk {
  background: var(--risk-tint);
  color: var(--risk-text);
}

.banner-title {
  font-weight: 600;
}

/* ---------- Empty state ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  padding: 56px var(--s-6);
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--hover);
  color: var(--muted);
}

.empty-icon svg {
  width: 24px;
  height: 24px;
}

.empty-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
}

.empty-text {
  max-width: 46ch;
  color: var(--muted);
  font-size: 15px;
}

.empty-note {
  margin-top: var(--s-1);
  padding: 2px 10px;
  border-radius: var(--r-pill);
  background: var(--hover);
  color: var(--muted);
  font-size: var(--fs-xs);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  font-size: var(--fs-md);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--t-fast) ease, transform var(--t-fast) ease;
}

.btn:hover {
  background: var(--hover);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  border-color: transparent;
  background: var(--primary-bg);
  color: var(--primary-fg);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

/* ---------- Form fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: var(--fs-md);
  font-weight: 600;
}

.field-hint {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  transition: border-color var(--t-fast) ease;
}

.input:hover {
  border-color: var(--muted);
}

.input:focus-visible {
  border-color: var(--focus);
  outline-offset: 1px;
}

.input[aria-invalid="true"] {
  border-color: var(--risk);
}

/* ---------- Dropdowns (DESIGN.md "Dropdowns") ----------
   Every browser: a clean closed field with a drawn chevron and soft hover/focus transitions.
   Browsers with customizable select (appearance: base-select): a styled, animated list too.
   Others fall back to their own list when open; everything still works the same. */
select.input {
  appearance: none;
  padding-right: 36px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 52%,
    calc(100% - 13px) 52%;
  background-repeat: no-repeat;
  background-size: 5px 5px;
  cursor: pointer;
  transition: border-color var(--t-fast) ease, background-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}

select.input:hover {
  border-color: var(--muted);
}

@supports (appearance: base-select) {
  select.input,
  select.input::picker(select) {
    appearance: base-select;
  }

  select.input {
    display: flex;
    align-items: center;
    background-image: none;
  }

  /* A thin chevron instead of the default solid triangle; it turns over when the list opens. */
  select.input::picker-icon {
    content: "";
    width: 7px;
    height: 7px;
    margin-inline: auto 2px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    rotate: 45deg;
    translate: 0 -2px;
    transition: rotate 200ms var(--ease), translate 200ms var(--ease);
  }

  select.input:open {
    border-color: var(--focus);
    box-shadow: 0 0 0 3px var(--hover);
  }

  select.input:open::picker-icon {
    rotate: 225deg;
    translate: 0 2px;
  }

  /* The open list: a card that fades and slides in, and back out. */
  select.input::picker(select) {
    max-height: min(320px, 60vh);
    margin-block: 6px;
    padding: 6px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--card);
    color: var(--fg);
    box-shadow: var(--shadow-pop);
    opacity: 0;
    translate: 0 -6px;
    transition:
      opacity 160ms ease,
      translate 200ms var(--ease),
      display 200ms allow-discrete,
      overlay 200ms allow-discrete;
  }

  select.input:open::picker(select) {
    opacity: 1;
    translate: 0 0;
  }

  @starting-style {
    select.input:open::picker(select) {
      opacity: 0;
      translate: 0 -6px;
    }
  }

  select.input option {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: 8px 10px;
    border-radius: var(--r-sm);
    color: var(--fg);
    font-size: var(--fs-md);
    font-weight: 400;
    letter-spacing: normal;
    text-transform: none;
    cursor: pointer;
    transition: background-color var(--t-fast) ease;
  }

  select.input option:hover,
  select.input option:focus-visible {
    outline: none;
    background: var(--hover);
  }

  select.input option:checked {
    font-weight: 600;
  }

  select.input option::checkmark {
    order: 1;
    margin-left: auto;
    color: var(--savings);
  }

  /* The blank "Choose…" option reads as a hint. */
  select.input option[value=""] {
    color: var(--muted);
  }

  select.input option[value=""]::checkmark {
    visibility: hidden;
  }

  /* Group labels (Accounts, Cards, Goals and funds…) as quiet small caps headings. */
  select.input optgroup {
    padding: 6px 0 2px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  select.input optgroup + optgroup {
    margin-top: 4px;
    border-top: 1px solid var(--line);
  }
}

.field-error {
  color: var(--risk-text);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.field-error[hidden] {
  display: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.field-inline-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.field-inline .field-label {
  font-weight: 500;
}

.checkbox {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary-bg);
}

.money-wrap {
  position: relative;
}

.money-sign {
  position: absolute;
  top: 50%;
  left: 12px;
  color: var(--muted);
  transform: translateY(-50%);
}

.input-money {
  padding-left: 24px;
}

.input-short {
  width: 9rem;
}

.input-search {
  width: min(280px, 100%);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-3);
}

.stack-tight {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.form-details {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.form-details[open] > :not(summary) + * {
  margin-top: var(--s-3);
}

.form-details summary {
  font-weight: 600;
  cursor: pointer;
}

.form-status {
  flex: 1;
  color: var(--risk-text);
  font-size: var(--fs-sm);
}

.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-quiet:hover {
  background: var(--hover);
}

.btn-danger {
  border-color: transparent;
  background: transparent;
  color: var(--risk-text);
}

.btn-danger:hover {
  background: var(--risk-tint);
}

.btn[hidden] {
  display: none;
}

/* The plain sentence under the transfer form that says what the transfer is. */
.transfer-sentence {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--info-tint);
  color: var(--info-text);
  font-size: var(--fs-sm);
}

.transfer-sentence-problem {
  background: var(--risk-tint);
  color: var(--risk-text);
}

/* ---------- Split editor ---------- */
.split-box:empty {
  display: none;
}

.split-box {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

/* ---------- Goals & Funds ---------- */

.big-num {
  font-size: var(--fs-xl);
  font-weight: 600;
}

.em-headline {
  margin: 0;
  font-size: var(--fs-md);
}

.em-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
}

.em-custom,
.em-follow {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  font-size: var(--fs-sm);
}

.goal-nudge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--info-tint);
  color: var(--info-text);
  font-size: var(--fs-sm);
}

.goal-nudge .input-short {
  width: 4.5rem;
}

.goal-refill {
  margin: 0;
  font-size: var(--fs-sm);
}

.goal-meta {
  display: block;
  font-size: var(--fs-xs);
}

.goal-flag {
  margin-left: var(--s-1);
}

.table td .progress {
  margin-top: var(--s-1);
}

.ret-aside {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 14rem;
  font-size: var(--fs-sm);
}

.ret-aside .progress {
  width: 100%;
}

.ret-status {
  margin-left: var(--s-2);
}

.fund-pct {
  min-width: 6rem;
  font-size: var(--fs-sm);
}

.fund-catchup {
  display: block;
  font-size: var(--fs-xs);
}

.pooled {
  margin: 0 0 var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--hover);
  font-size: var(--fs-sm);
}

.fund-line-short {
  color: var(--watch-text);
}

/* Spent | Got back and expected money back (spending form) */
.amount-cell {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.kind-switch .seg {
  align-self: flex-start;
}

.kind-hint {
  margin-top: calc(var(--s-1) * -1);
}

.link-btn {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ok-text);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.expect-box {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-3);
  border-radius: var(--r-sm);
  background: var(--info-tint);
}

.amt-back {
  color: var(--ok-text);
}

/* ---------- Cards & Rewards ---------- */

.card-head-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: calc(var(--s-6) * -1);
}

.form-section {
  margin: var(--s-3) 0 0;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stmt {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.stmt-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stmt-label {
  font-size: var(--fs-sm);
}

.stmt-value {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-3);
  font-size: var(--fs-lg);
  font-weight: 600;
}

.stmt-value .btn {
  padding-inline: var(--s-2);
}

.stmt-meta {
  font-size: var(--fs-xs);
}

.stmt-six,
.stmt-history {
  margin: 0;
}

.estimate-wrap {
  display: inline;
}

.estimate {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline dashed;
  text-decoration-color: var(--muted);
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.estimate-exact {
  text-decoration-style: dotted;
}

.estimate-approx {
  color: var(--muted);
}

.override-dot {
  width: 7px;
  height: 7px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--watch);
  align-self: center;
}

.estimate-pop {
  max-height: calc(100vh - 16px);
  overflow: auto;
}

.pop-form {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin-top: var(--s-2);
  padding-top: var(--s-2);
  border-top: 1px solid var(--line);
}

.range {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.range-track {
  position: relative;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--track);
}

.range-marker {
  position: absolute;
  top: -3px;
  left: var(--at, 50%);
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: var(--progress);
}

.range-ends {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.rules {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.rule-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s-1) var(--s-2);
  padding: var(--s-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}

.rule-main,
.rule-extra {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-2);
}

.rule-main select {
  flex: 1 1 10rem;
}

.rule-main input {
  width: 5rem;
}

.rule-extra {
  grid-column: 1 / 2;
  font-size: var(--fs-sm);
}

.rule-extra input[type='date'] {
  width: 9.5rem;
}

.rule-extra input[type='text'] {
  width: 6rem;
}

.card-form-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
}

.look-box {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.look-swatch {
  width: 28px;
  height: 18px;
  border: 2px solid transparent;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  cursor: pointer;
}

.look-swatch.is-picked {
  border-color: var(--fg);
}

.best-inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}

.best-inputs select {
  width: auto;
  min-width: 12rem;
}

.best-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  margin: 0;
  padding-left: var(--s-4);
}

.best-list .is-best {
  font-weight: 600;
}

.best-flag {
  margin-left: var(--s-2);
}

.details-card > summary {
  cursor: pointer;
}

.bonus-aside {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 12rem;
  font-size: var(--fs-sm);
}

.bonus-aside .progress {
  width: 100%;
}

.settings-inline-field {
  margin-top: var(--s-3);
}

.input-short-wide {
  max-width: 16rem;
}

.best-line {
  margin-top: calc(var(--s-1) * -1);
}

/* ---------- Checking timeline ---------- */

.tl-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  margin-bottom: var(--s-3);
}

.tl-safe-wrap .input {
  width: 7rem;
}

.tl-banner {
  flex-direction: column;
  align-items: stretch;
  margin-top: var(--s-3);
}

.tl-chart-wrap {
  margin-top: var(--s-3);
}

.tl-chart {
  display: block;
  width: 100%;
  height: auto;
}

.tl-line {
  fill: none;
  stroke: var(--progress);
  stroke-width: 2;
}

.tl-safe {
  stroke: var(--watch);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}

.tl-zero {
  stroke: var(--line);
  stroke-width: 1;
}

.tl-tick {
  stroke: var(--line);
  stroke-width: 1;
}

.tl-label {
  fill: var(--muted);
  font-size: 11px;
}

.tl-pay {
  fill: var(--set-aside);
  stroke: var(--card);
  stroke-width: 1.5;
}

.tl-low {
  fill: var(--risk);
  stroke: var(--card);
  stroke-width: 2;
}

.tl-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.tl-key {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.tl-key-line {
  background: var(--progress);
}

.tl-key-safe {
  border-top: 2px dashed var(--watch);
  height: 0;
}

.tl-key-pay {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--set-aside);
}

.tl-other {
  margin: var(--s-2) 0 0;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--watch-tint);
  color: var(--watch-text);
  font-size: var(--fs-sm);
}

.tl-days {
  margin-top: var(--s-3);
}

.tl-below td {
  color: var(--risk-text);
}

/* ---------- Calendar ---------- */

.cal-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--s-2);
}

.cal-strip-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
}

.cal-strip-item:hover {
  background: var(--hover);
}

.cal-strip-item.is-current {
  border-color: var(--progress);
}

.cal-strip-month {
  font-weight: 600;
}

.cal-status {
  margin: 0 0 var(--s-3);
}

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

.cal-head {
  padding: var(--s-1);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: center;
}

.cal-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 72px;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--card);
}

.cal-empty {
  border-color: transparent;
  background: transparent;
}

.cal-today {
  border-color: var(--progress);
}

.cal-day {
  color: var(--muted);
  font-size: var(--fs-xs);
}

.cal-chip {
  overflow: hidden;
  padding: 2px 5px;
  border: 0;
  border-radius: 4px;
  background: var(--info-tint);
  color: var(--info-text);
  font: inherit;
  font-size: 11px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.cal-derived {
  background: var(--hover);
  color: var(--muted);
  cursor: default;
}

.cal-short {
  background: var(--risk-tint);
  color: var(--risk-text);
}

.cal-note {
  font-size: var(--fs-xs);
}

@media (max-width: 767px) {
  .cal-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .cal-cell {
    min-height: 48px;
  }
}

/* ---------- Developer "Pretend today is…" banner ---------- */

.pretend-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  margin-bottom: var(--s-4);
  padding: var(--s-2) var(--s-3);
  border: 1px dashed var(--watch);
  border-radius: var(--r-sm);
  background: var(--watch-tint);
  color: var(--watch-text);
  font-size: var(--fs-sm);
  font-weight: 600;
}

/* ---------- Add row in the Spending table ---------- */

/* At rest: a skinny, quiet line at the top edge of the list (always there, no box, nothing
   hidden), like the "+ New" line in good list tools. It tints on hover or keyboard focus. */
.table .quick-rest > td {
  padding: 0;
}

.table .quick-editing > td {
  padding: 6px 0;
}

.quick-open {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 30px;
  padding: 4px var(--s-2);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}

.quick-open:focus-visible {
  outline-offset: -2px;
}

.quick-open svg {
  width: 14px;
  height: 14px;
}

.quick-open:hover,
.quick-open:focus-visible {
  background: var(--ok-tint);
  color: var(--ok-text);
}

/* Open: one cell spanning the table, with the fields lined up to the columns. */
.table .quick-editing > td {
  background: var(--ok-tint);
}

.quick-grid {
  display: grid;
  grid-template-columns: var(--qa-cols, 6rem minmax(0, 1fr) 8rem 6rem 8rem 4rem 6rem 3.5rem);
  align-items: center;
  animation: quick-in 160ms ease both;
}

.quick-slot {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  min-width: 0;
  padding: 0 4px;
}

.qs-amount,
.qs-actions {
  justify-content: flex-end;
}

.qs-actions {
  padding-right: 0;
}

.quick-slot .input-compact {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  padding-inline: 6px;
  font-size: var(--fs-sm);
}

.quick-slot select {
  white-space: nowrap;
  text-overflow: ellipsis;
}

#qa-amount {
  text-align: right;
}

.quick-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ok-text);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.quick-icon {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.quick-icon svg {
  width: 16px;
  height: 16px;
}

.quick-icon:hover,
.quick-icon:focus-visible {
  background: var(--card);
  color: var(--fg);
}

.quick-icon-add {
  color: var(--ok-text);
}

.table.quick-is-open .col-edit {
  width: 58px;
}

/* Narrow screens (some columns hidden): the fields wrap instead of lining up. */
.quick-grid.quick-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 0;
}

.quick-wrap .qs-date {
  flex: 0 0 6.5rem;
}

.quick-wrap .qs-merchant {
  flex: 1 1 10rem;
}

.quick-wrap .qs-category,
.quick-wrap .qs-owner,
.quick-wrap .qs-account {
  flex: 1 1 7.5rem;
}

.quick-wrap .qs-amount {
  flex: 0 0 7rem;
}

.quick-editing .field-error,
.quick-editing .quick-note {
  margin: 6px 4px 0;
  font-size: var(--fs-xs);
}

.quick-note {
  display: inline-block;
  padding: 1px var(--s-2);
  border-radius: var(--r-sm);
}

.quick-got-back {
  color: var(--ok-text);
}

/* Entries added from the row stay under it; the newest slides in with a fading highlight. */
.flag-new {
  background: var(--ok-tint);
  color: var(--ok-text);
}

.row-enter td {
  animation: row-enter 1.4s ease both;
}

@keyframes row-enter {
  0% {
    background: var(--ok-tint);
    opacity: 0;
    transform: translateY(-6px);
  }

  15% {
    opacity: 1;
    transform: none;
  }

  60% {
    background: var(--ok-tint);
  }

  100% {
    background: transparent;
  }
}

@keyframes quick-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .row-enter td,
  .quick-grid {
    animation: none;
  }
}

/* ---------- Import ---------- */

.plain-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  margin: 0;
  padding-left: var(--s-4);
  font-size: var(--fs-sm);
}

.input-paste {
  min-height: 8rem;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--fs-sm);
  resize: vertical;
}

/* ---------- Review ---------- */

.review-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.review-row {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-3);
  border-bottom: 1px solid var(--line);
  border-radius: var(--r-sm);
  outline-offset: -2px;
}

.review-row:focus-visible,
.review-row:focus-within {
  background: var(--hover);
}

.review-head {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--s-3);
}

.review-date {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.review-desc {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-amt {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.review-in {
  color: var(--ok-text);
}

.review-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  font-size: var(--fs-sm);
}

.review-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: var(--s-2);
}

.input-compact {
  min-height: 34px;
  padding-block: 4px;
  font-size: var(--fs-sm);
}

.review-match,
.review-offer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--watch-tint);
  color: var(--watch-text);
  font-size: var(--fs-sm);
}

/* A paired transfer: neutral, not a warning (it's already decided). */
.review-pair {
  background: var(--info-tint);
  color: var(--info-text);
}

.review-pair-rows {
  flex-basis: 100%;
}

.review-offer {
  justify-content: flex-start;
  background: var(--info-tint);
  color: var(--info-text);
}

.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

/* ---------- History, bank values, out-of-month (transaction forms) ---------- */

.out-of-month {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--watch-tint);
  color: var(--watch-text);
}

.bank-says {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--info-tint);
  color: var(--info-text);
  font-size: var(--fs-sm);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  padding-left: var(--s-3);
  border-left: 2px solid var(--line);
}

.history-item:first-child {
  border-left-color: var(--progress);
}

.history-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s-2);
  font-size: var(--fs-sm);
}

.history-lines {
  margin: 0;
  padding-left: var(--s-4);
  color: var(--muted);
  font-size: var(--fs-sm);
}

.history-item .btn {
  align-self: flex-start;
}

.split-row {
  display: grid;
  grid-template-columns: auto 8rem minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-2);
}

.split-sign {
  color: var(--muted);
}

/* ---------- Explained numbers (dotted underline; estimates use "≈" and a dashed one) ---------- */
.explain-wrap {
  display: inline;
}

.explain {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-align: inherit;
  text-decoration: underline dotted;
  text-decoration-color: var(--muted);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  cursor: help;
}

.explain-info {
  margin-left: 0.25em;
  color: var(--muted);
  font-size: 0.7em;
  vertical-align: super;
}

.popover {
  position: fixed;
  top: var(--pop-y, 0);
  left: var(--pop-x, 0);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: var(--pop-w, 300px);
  padding: var(--s-3) 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm);
  font-weight: 400;
  letter-spacing: normal;
  line-height: 1.45;
  text-align: left;
}

.popover-title {
  font-weight: 600;
}

.popover-formula,
.popover-note {
  color: var(--muted);
}

.popover-values {
  font-weight: 600;
}

.popover-link {
  font-weight: 600;
}

/* ---------- Transactions ---------- */
.tx-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
}

.toolbar-spacer {
  flex: 1;
}

.month-picker {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
}

.month-label {
  min-width: 9.5rem;
  font-weight: 600;
  text-align: center;
}

.icon-btn-light {
  border-color: var(--line);
  color: var(--fg);
  font-size: 18px;
  line-height: 1;
}

.icon-btn-light:hover {
  background: var(--hover);
  color: var(--fg);
}

.chip-review {
  background: transparent;
  color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--line);
}

.chip-review[aria-pressed="true"] {
  background: var(--watch-tint);
  color: var(--watch-text);
  box-shadow: inset 0 0 0 1.5px currentColor;
}

.card-table {
  padding-top: var(--s-3);
}

.row-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- Editable rows (DESIGN.md "Editable rows") ---------- */
.erow {
  position: relative;
  cursor: pointer;
  transition: background-color var(--t-fast) ease;
}

div.erow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-4);
  margin: 0 calc(-1 * var(--s-2));
  padding: var(--s-3) var(--s-2);
  border-bottom: 1px solid var(--line);
  border-radius: var(--r-sm);
}

div.erow:last-child {
  border-bottom: 0;
}

div.erow:hover,
div.erow:focus-within,
tr.erow:hover > td,
tr.erow:focus-within > td {
  background: var(--hover);
}

.erow-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

/* The name's click area covers the whole row. */
.erow-button::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

.erow:hover .erow-button {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Other things in the row stay independently hoverable and clickable. */
.erow .badge,
.erow .badge-pair,
.erow .flag,
.erow .explain,
.erow .erow-aside,
.erow .erow-above,
.erow input,
.erow select {
  position: relative;
  z-index: 2;
}

.erow-lead {
  display: inline-flex;
  flex: none;
}

.erow-main {
  display: flex;
  flex: 1;
  min-width: 12rem;
  flex-direction: column;
  gap: 2px;
}

.erow-meta {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.erow-aside {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
}

.erow-pencil {
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  opacity: 0;
  transition: opacity var(--t-fast) ease;
}

.erow-pencil svg {
  width: 16px;
  height: 16px;
}

.erow:hover .erow-pencil,
.erow:focus-within .erow-pencil {
  opacity: 1;
}

/* Touch screens have no hover: the pencil is always shown. */
@media (hover: none) {
  .erow-pencil {
    opacity: 1;
  }
}

.table .col-edit {
  width: 28px;
  padding-left: 0;
  text-align: right;
}

.flags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.flag {
  padding: 1px 7px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.flag-review {
  background: var(--watch-tint);
  color: var(--watch-text);
}

.flag-dup {
  background: var(--risk-tint);
  color: var(--risk-text);
}

.flag-info {
  background: var(--info-tint);
  color: var(--info-text);
}

.flag-muted {
  background: var(--hover);
  color: var(--muted);
}

.badge-row {
  display: inline-flex;
  gap: 4px;
}

.tile-compact .tile-value {
  font-size: 24px;
}

.reminders {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  border-color: var(--info-tint);
  background: var(--info-tint);
  color: var(--info-text);
  box-shadow: none;
}

.reminder {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.reminder + .reminder {
  padding-top: var(--s-3);
  border-top: 1px solid var(--line);
}

/* ---------- Settings lists ---------- */
.settings-tabs {
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}

.settings-tabs .seg-btn {
  white-space: nowrap;
}

.settings-list {
  display: flex;
  flex-direction: column;
}

/* Budget grid: cells look like fields, more clearly on hover and focus. */
.budget-cell {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
}

.budget-input {
  width: 8rem;
  border-color: var(--line);
  background: var(--bg);
  text-align: right;
}

.budget-input:hover {
  border-color: var(--muted);
  background: var(--card);
}

.budget-input:focus {
  background: var(--card);
}

.saved-tick {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--ok-text);
  font-size: var(--fs-xs);
  font-weight: 600;
  animation: tick-in var(--t-fast) ease both;
}

.saved-tick svg {
  width: 14px;
  height: 14px;
}

@keyframes tick-in {
  from {
    opacity: 0;
  }
}

/* Budget screen: what was spent sits under each budget cell; group headings and totals. */
.budget-table td.amt {
  vertical-align: top;
}

.budget-spent {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: var(--fs-xs);
  text-align: right;
}

.budget-table .budget-input {
  width: 6.5rem;
}

.budget-total {
  white-space: nowrap;
}

.budget-status {
  display: block;
  margin-top: 2px;
  font-size: var(--fs-xs);
}

.budget-group th {
  padding-top: var(--s-4);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.budget-subtotal th,
.budget-subtotal td {
  border-top: 1px solid var(--line);
  font-weight: 600;
}

.budget-grand th,
.budget-grand td {
  border-top-width: 2px;
}

/* Needs / Wants / Savings rows */
.nws {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.nws-row {
  display: grid;
  grid-template-columns: 6rem minmax(9rem, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-3);
}

.nws-label {
  font-weight: 600;
}

/* Us */
.us-table th[scope="colgroup"] {
  text-align: right;
}

.us-actual {
  color: var(--muted);
}

.us-strong th,
.us-strong td {
  border-top: 1px solid var(--line);
  font-weight: 600;
}

.us-sub {
  margin-left: var(--s-1);
  font-size: var(--fs-xs);
  font-weight: 400;
}

.score-row {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.score-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s-2);
}

.settle-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

.text-risk {
  color: var(--risk-text);
}

@media (max-width: 767px) {
  .nws-row {
    grid-template-columns: 1fr auto;
  }
}

/* A table cell that edits its record, like an editable row (the category names in the budget grid). */
.erow-cell {
  position: relative;
  cursor: pointer;
  white-space: nowrap;
}

.erow-cell:hover,
.erow-cell:focus-within {
  background: var(--hover);
}

.erow-cell:hover .erow-button {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.erow-cell .erow-pencil {
  margin-left: var(--s-2);
  vertical-align: middle;
}

.erow-cell:hover .erow-pencil,
.erow-cell:focus-within .erow-pencil {
  opacity: 1;
}

/* ---------- First-run setup ---------- */
.setup {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: var(--s-6) var(--s-4);
}

.setup-card {
  width: min(480px, 100%);
  padding: var(--s-8);
}

.setup-mark .logo {
  margin: -24px 0 -24px -20px;
}

/* ---------- Segmented control ---------- */
.seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-pill);
  background: var(--track);
}

.seg-btn {
  padding: 4px 12px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}

.seg-btn[aria-pressed="true"] {
  background: var(--card);
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ---------- Table with sticky header ---------- */
.table-wrap {
  max-height: var(--table-max, none);
  overflow: auto;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-md);
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0 var(--s-3) var(--s-2);
  border-bottom: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.table td,
.table tbody th,
.table tfoot th {
  padding: 11px var(--s-3);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

/* Row headers (a row's name) read like the row, not like the column headings. */
.table tbody th,
.table tfoot th {
  position: static;
  background: none;
  color: var(--fg);
  font-size: inherit;
  font-weight: 500;
  white-space: normal;
}

.table tr:last-child td,
.table tr:last-child th[scope="row"] {
  border-bottom: 0;
}

.table th:first-child,
.table td:first-child {
  padding-left: 0;
}

.table th:last-child,
.table td:last-child {
  padding-right: 0;
}

.table .amt {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.table .strong {
  font-weight: 600;
}

@media (max-width: 999px) {
  .col-optional {
    display: none;
  }
}

/* ---------- Dialog ---------- */
.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--r-card);
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow-pop);
}

.dialog-wide {
  width: min(620px, calc(100vw - 32px));
}

.dialog-form {
  display: flex;
  max-height: calc(100vh - 48px);
  flex-direction: column;
}

.dialog-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.dialog-actions-start {
  margin-right: auto;
}

.dialog-actions {
  align-items: center;
}

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

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-6) var(--s-6) var(--s-4);
}

.dialog-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 500;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: 0 var(--s-6) var(--s-6);
}

/* ---------- Toast with Undo ---------- */
.toast-region {
  position: fixed;
  right: var(--s-6);
  bottom: var(--s-6);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: 10px 12px 10px var(--s-4);
  border-radius: var(--r-md);
  background: var(--toast-bg);
  color: var(--toast-fg);
  box-shadow: var(--shadow-pop);
  animation: toast-in 200ms var(--ease) both;
}

.toast-action {
  padding: 4px 10px;
  border: 1px solid currentColor;
  border-radius: var(--r-sm);
  background: transparent;
  color: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}

.toast :focus-visible {
  outline-color: var(--focus-on-dark);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------- Card thumbnail (generated face) ---------- */
.card-face {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: var(--w, 96px);
  aspect-ratio: 1.586 / 1;
  overflow: hidden;
  padding: 7px 9px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  color: var(--face-fg);
  font-size: 10px;
  line-height: 1.2;
}

.card-face::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.2), transparent 45%);
  pointer-events: none;
}

.card-face-name {
  font-weight: 700;
}

.card-face-foot {
  display: flex;
  justify-content: space-between;
  opacity: 0.9;
  font-variant-numeric: tabular-nums;
}

.face-1 {
  --c1: var(--face-1a);
  --c2: var(--face-1b);
}

.face-2 {
  --c1: var(--face-2a);
  --c2: var(--face-2b);
}

.face-3 {
  --c1: var(--face-3a);
  --c2: var(--face-3b);
}

.face-4 {
  --c1: var(--face-4a);
  --c2: var(--face-4b);
}

.face-5 {
  --c1: var(--face-5a);
  --c2: var(--face-5b);
}

.face-6 {
  --c1: var(--face-6a);
  --c2: var(--face-6b);
}

/* ---------- Chart wrapper ---------- */
.chart {
  margin: 0;
}

.chart-body {
  margin: var(--s-4) 0 var(--s-3);
}

.chart-data summary {
  color: var(--muted);
  font-size: var(--fs-sm);
  cursor: pointer;
}

.chart-data .table {
  margin-top: var(--s-2);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  color: var(--muted);
  font-size: var(--fs-xs);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-item::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--c);
}

.bars {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: var(--s-4);
  height: 160px;
}

.bar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
}

.bar-set {
  display: flex;
  flex: 1;
  align-items: flex-end;
  gap: 4px;
}

.bar {
  width: 14px;
  height: var(--h, 0%);
  border-radius: 4px 4px 0 0;
  background: var(--c);
  transform-origin: bottom;
  animation: bar-in 400ms var(--ease) both;
}

.c-a {
  --c: var(--a-chart);
}

.c-b {
  --c: var(--b-chart);
}

.c-ours {
  --c: var(--ours-chart);
}

@keyframes bar-in {
  from {
    transform: scaleY(0);
  }
}

/* ---------- Overview ---------- */
.person-row + .person-row {
  margin-top: var(--s-4);
}

.person-row-head {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: 6px;
  font-size: var(--fs-md);
}

.person-name {
  font-weight: 600;
}

.big-value {
  font-size: 24px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.kv {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: var(--s-3);
  font-size: var(--fs-md);
}

.kv-row {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
}

.gallery-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
}

/* ---------- Page transitions (View Transitions API) ---------- */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
}

::view-transition-old(page) {
  animation: page-out var(--t-page-out) ease-in both;
}

::view-transition-new(page) {
  animation: page-in var(--t-page-in) var(--ease) both;
}

@keyframes page-out {
  to {
    opacity: 0;
  }
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------- Narrower desktops ---------- */
@media (max-width: 1023px) {
  .main {
    padding: var(--s-6) var(--s-6) 40px;
  }
}

/* ---------- Medium (768–1023px): icon-only rail, expandable ---------- */
.app.rail {
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
}

.rail .side {
  align-items: center;
  padding: var(--s-4) 10px;
}

.rail .side-head {
  flex-direction: column;
  gap: var(--s-3);
}

.rail .brand {
  padding: 0;
}

.rail .brand-name,
.rail .nav-text,
.rail .sync-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.rail .nav {
  width: 100%;
  scrollbar-width: none; /* still scrolls on very short windows, without a bar squeezing the icons */
}

.rail .nav-list {
  gap: 0;
}

.rail .nav-group-label {
  display: none;
}

.rail .nav-group + .nav-group {
  margin-top: var(--s-2);
  padding-top: var(--s-2);
  border-top: 1px solid var(--side-line);
}

.rail .nav-link {
  justify-content: center;
  padding: 8px 0;
}

.rail .side {
  gap: var(--s-3);
}

.rail .side-foot {
  gap: var(--s-2);
}

.rail .side-foot {
  align-items: center;
  width: 100%;
  padding: var(--s-3) 0 0;
}

.rail .sync-chip {
  align-self: center;
  padding: 7px;
}

.rail .side-row,
.rail .avatars,
.rail .side-btns {
  flex-direction: column;
  align-items: center;
}

/* Floating label for icon-only controls (positioned from JS via custom properties) */
.side-tip {
  position: fixed;
  top: var(--tip-y, 0);
  left: var(--tip-x, 0);
  z-index: 60;
  padding: 4px 10px;
  border-radius: var(--r-sm);
  background: var(--toast-bg);
  color: var(--toast-fg);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  transform: translateY(-50%);
}

.side-tip[hidden] {
  display: none;
}

/* ---------- Narrow (below 768px): top bar plus slide-out drawer ---------- */
.topbar {
  display: none;
}

@media (max-width: 767px) {
  /* Rows: the top bar keeps its own height; the page takes whatever is left.
     Without this, a short page lets the grid stretch the top bar's row. */
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  }

  .app > .side {
    display: none;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: var(--s-3);
    height: var(--topbar-h);
    padding: 0 var(--s-4);
    background: var(--side-bg);
    color: var(--nav-off);
    transition: box-shadow var(--t-fast) ease;
  }

  .topbar.is-scrolled {
    box-shadow: var(--topbar-shadow);
  }

  .topbar .brand {
    padding: 0;
  }

  .topbar .sync-chip {
    align-self: center;
    margin-left: auto;
  }

  .main {
    padding: var(--s-4) var(--s-4) 40px;
  }

  .grid-tiles {
    grid-template-columns: minmax(0, 1fr);
  }
}

.drawer {
  inset: 0 auto 0 0;
  width: min(var(--drawer-w), 86vw);
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: var(--s-5) var(--s-3) var(--s-4);
  border: 0;
  background: var(--side-bg);
  color: var(--nav-off);
  box-shadow: var(--shadow-pop);
}

.drawer[open] {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  animation: drawer-in 220ms var(--ease) both;
}

.drawer::backdrop {
  background: var(--backdrop);
}

@keyframes drawer-in {
  from {
    transform: translateX(-100%);
  }
}

/* ---------- Reduced motion: everything still, nothing animates ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

/* Kept separate: browsers that don't know ::picker would otherwise drop the whole rule above. */
@supports (appearance: base-select) {
  @media (prefers-reduced-motion: reduce) {
    select.input::picker(select),
    select.input::picker-icon {
      transition: none !important;
    }
  }
}

/* ---------- Sprint 8: Overview, Net Worth, Salary, Modules ---------- */
.check-inline-wrap {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  font-size: var(--fs-sm);
}

.tile-foot > * + * {
  margin-top: 4px;
}

.tile-foot > span,
.tile-foot > a {
  display: block;
}

/* Where the money goes: one stacked bar, widths from --w */
.where-bar {
  display: flex;
  gap: 2px;
  height: 14px;
  margin: var(--s-2) 0 var(--s-3);
  overflow: hidden;
  border-radius: 7px;
  background: var(--track);
}

.where-seg {
  flex: 0 0 var(--w, 0%);
  background: var(--c);
}

.seg-need {
  --c: var(--needs);
}

.seg-want {
  --c: var(--wants);
}

.seg-none {
  --c: var(--muted);
}

/* Net worth trend */
.nw-chart {
  display: block;
  width: 100%;
  height: auto;
}

.nw-proj {
  fill: none;
  stroke: var(--savings);
  stroke-width: 2;
  stroke-dasharray: 6 5;
}

.nw-milestone {
  stroke: var(--watch);
  stroke-width: 1.5;
  stroke-dasharray: 3 4;
}

.nw-dot {
  fill: var(--progress);
  stroke: var(--card);
  stroke-width: 1.5;
}

.c-proj {
  --c: var(--savings);
}

@media (min-width: 1000px) {
  .grid-cards.nw-grid {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  }
}

/* Salary */
.salary-sub {
  margin: var(--s-4) 0 var(--s-2);
  font-size: var(--fs-sm);
}

/* Settings → Modules */
.module-list {
  display: grid;
  gap: var(--s-3);
}

.module-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-3) 0;
  border-top: 1px solid var(--line);
}

.module-row:first-child {
  border-top: 0;
}

.module-row .card-sub {
  margin: 2px 0 0;
}

/* First-run setup: "Want any extras?" */
.setup-extras {
  display: grid;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
  border: 0;
}

.setup-extras .check-inline {
  align-items: flex-start;
}

.nw-month {
  width: auto;
}

/* ---------- Sprint 9: vault screens and card images ---------- */
.recovery-key {
  margin: var(--s-2) 0 0;
  padding: var(--s-3) var(--s-4);
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--hover);
  color: var(--fg);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 18px;
  letter-spacing: 0.06em;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
  user-select: all;
}

.recovery-group {
  white-space: nowrap;
}

.recovery-input {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Printing the recovery key prints only the key. */
@media print {
  body.printing-key * {
    visibility: hidden;
  }

  body.printing-key .recovery-print,
  body.printing-key .recovery-print * {
    visibility: visible;
  }

  body.printing-key .recovery-print {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
  }
}

.card-face-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-face.has-image .card-face-name {
  visibility: hidden;
}

.card-face.has-image .card-face-foot {
  position: relative;
  z-index: 1;
  align-self: flex-start;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
}

/* ---------- Sprint 10: sync status and conflicts ---------- */
.sync-chip[data-state="synced"]::before {
  background: var(--ok);
}

.sync-chip[data-state="syncing"]::before {
  background: var(--muted);
}

.sync-chip[data-state="offline"]::before,
.sync-chip[data-state="error"]::before,
.sync-chip[data-state="warn"]::before,
.sync-chip[data-state="rekeyed"]::before {
  background: var(--watch);
}

.dialog-conflict {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: 8px;
  background: var(--watch-tint);
  color: var(--watch-text);
  font-size: var(--fs-sm);
}
