/* =============================================================================
   styles.css — every color, font and layout rule for the Budget app
   -----------------------------------------------------------------------------
   Layout concept: a dark band (with faint engraved lines, like a bank check)
   holds the verdict and the month's income strip; plain panels sit below in
   two columns that stack into one on phones.

   Theme: the app is black by design, so there is a single set of colors
   (no separate light mode). The grays are pure neutral grays, with no color
   tint.

   How colors work: every color is a variable ("token") defined once below.
   Components only ever use the variables, so changing a value here changes
   it everywhere.
   ========================================================================== */

/* ---- Tokens ------------------------------------------------------------------ */
:root {
  /* Background and text */
  --paper: #000000; /* page background: black */
  --check: #0b0b0b; /* the patterned band at the top of the overview */
  --guilloche: #242424; /* the faint wavy lines on that band */
  --sheet: #141414; /* panels and the chart surface, one step up from black */
  --field: #1c1c1c; /* text inputs */
  --ink: #f2f2f2; /* main text */
  --ink-2: #b3b3b3; /* secondary text */
  --muted: #8a8a8a; /* hints, small labels */
  --rule: #262626; /* hairlines and panel borders */
  --rule-strong: #3a3a3a; /* input borders, chart ticks */
  --hover: rgba(255, 255, 255, 0.07);
  --track: #262626; /* empty part of bars and meters */

  /* Accent: soft blue, for actions, links, the active tab and focus */
  --accent: #9dbbe8;
  --accent-hover: #b6cdf0;
  --accent-ink: #000000; /* text on the accent */
  --accent-wash: #1a2433;

  /* Budget groups. These five, in this order, passed a color-blindness
     check as neighbors in the income strip on this background.
     Text drawn on each uses --g-*-on. */
  --g-taxes: #c98500;
  --g-needs: #3987e5;
  --g-debt: #d95926;
  --g-wants: #9085e9;
  --g-savings: #199e70;
  --g-taxes-on: #000000;
  --g-needs-on: #000000;
  --g-debt-on: #000000;
  --g-wants-on: #000000;
  --g-savings-on: #000000;
  --g-rest: #333333; /* "not assigned" / "not spent yet" */
  --g-rest-on: #f2f2f2;
  --g-other: #6e6e6e; /* spending under deleted categories */
  --g-other-on: #000000;

  /* Status (health only; always shown with an icon and a word) */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-text: #ff8f8f;
  --on-status: #ffffff; /* marks drawn on good / serious / critical */
  --on-warning: #3d2c00; /* marks drawn on the yellow warning */

  /* Type */
  --font-ui: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Newsreader', Georgia, 'Times New Roman', serif;

  /* Shape */
  --radius-band: 16px;
  --radius-panel: 12px;
  --radius-control: 8px;
  --gutter: clamp(16px, 4vw, 40px);

  /* Tells the browser to draw form controls and scrollbars dark. */
  color-scheme: dark;
}

/* ---- Base --------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  line-height: 1.55;
}
h1,
h2,
h3,
p {
  margin: 0;
}
h1,
h2,
h3 {
  text-wrap: balance;
}
a {
  color: var(--accent);
  text-underline-offset: 2px;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Top bar --------------------------------------------------------------- */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: 'brand tabs account';
  align-items: center;
  gap: 0.5rem 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px var(--gutter);
}
.brand {
  grid-area: brand;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.tabs {
  grid-area: tabs;
  display: flex;
  gap: 1.25rem;
}
.tabs a {
  position: relative;
  padding: 0.4rem 0.1rem;
  color: var(--ink-2);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
.tabs a:hover {
  color: var(--ink);
}
.tabs a[aria-current='page'] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
/* Small dot on the Budget tab when there are unsaved edits. */
.tabs a.has-unsaved::after {
  content: '';
  position: absolute;
  top: 0.35rem;
  right: -0.5rem;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.account {
  grid-area: account;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
  min-width: 0;
}
.account-name {
  color: var(--ink-2);
  font-size: 0.875rem;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-wash);
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      'brand account'
      'tabs tabs';
  }
  .account .btn {
    padding: 0 0.6rem;
  }
  /* Make room for the name on narrow screens. */
  .account .pill,
  .account-name {
    display: none;
  }
}

/* ---- Main area ------------------------------------------------------------- */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding-inline: var(--gutter);
  padding-block: 4px 96px;
  transition: opacity 0.15s;
}
.main:focus {
  outline: none;
}
.main.is-refreshing {
  opacity: 0.6;
}
.loading {
  padding-block: 3rem;
  color: var(--muted);
}
.page {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---- Shared type ------------------------------------------------------------ */
.display {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.9rem, 1.3rem + 2.4vw, 2.75rem);
  line-height: 1.08;
  letter-spacing: -0.015em;
  max-width: 20ch;
}
.page-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.75rem, 1.4rem + 1.4vw, 2.25rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.lede {
  color: var(--ink-2);
  font-size: 1rem;
  max-width: 62ch;
}
.note,
.empty {
  color: var(--ink-2);
  font-size: 0.875rem;
}
.fineprint {
  color: var(--ink-2);
  font-size: 0.875rem;
  max-width: 52ch;
}

/* ---- Buttons ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.5rem;
  padding: 0 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-weight: 600;
  font-size: 0.9375rem;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  background: transparent;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-secondary {
  background: var(--accent-wash);
  color: var(--accent);
}
.btn-quiet {
  color: var(--ink-2);
}
.btn-quiet:hover {
  background: var(--hover);
  color: var(--ink);
}
.btn-danger {
  background: var(--critical);
  color: #ffffff;
}
.btn-small {
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.875rem;
}
.btn-add {
  align-self: flex-start;
  color: var(--accent);
  padding: 0 0.5rem;
  margin-left: -0.5rem;
}
.btn-add:hover {
  background: var(--accent-wash);
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--hover);
  color: var(--ink);
}
.icon-btn-danger:hover {
  color: var(--critical-text);
}
.link-btn {
  white-space: nowrap;
  border: 0;
  background: none;
  padding: 0 0.4rem;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* ---- Panels ----------------------------------------------------------------- */
.panel {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-panel);
  padding: clamp(16px, 2.4vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.panel-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.panel-head h2,
.edit-group-head h2 {
  font-size: 1.0625rem;
  font-weight: 700;
}
.panel-head p,
.edit-group-head p {
  color: var(--ink-2);
  font-size: 0.875rem;
  max-width: 62ch;
}
.notice {
  max-width: 44rem;
  margin-top: 2rem;
}

/* ---- Hero: the check-paper band --------------------------------------------- */
.hero,
.signin {
  position: relative;
  overflow: hidden;
  background: var(--check);
  border: 1px solid var(--rule);
  border-radius: var(--radius-band);
}
.guilloche {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.hero-inner,
.signin-inner {
  position: relative; /* sits above the pattern */
  padding: clamp(20px, 4vw, 40px);
}
.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem 2rem;
  flex-wrap: wrap;
}
.verdict {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  flex: 1 1 26rem;
}
.score-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
}
.score-number {
  font-size: 3.5rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}
.score-of {
  color: var(--ink-2);
  font-weight: 500;
  margin-right: 0.5rem;
}
.summary {
  color: var(--ink-2);
  max-width: 60ch;
}

/* Month switcher (on the band it gets its own small sheet). */
.month-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}
.hero .month-switch {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 2px;
}
.month-name {
  min-width: 9rem;
  text-align: center;
  font-weight: 600;
}

/* Sign-in / empty state band */
.signin,
.hero-empty {
  margin-top: 2rem;
}
.signin-inner,
.hero-empty .hero-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
  padding-block: clamp(32px, 7vw, 72px);
}

/* ---- Health meter + status colors --------------------------------------------- */
.s-good {
  --status: var(--good);
}
.s-warning {
  --status: var(--warning);
}
.s-serious {
  --status: var(--serious);
}
.s-critical {
  --status: var(--critical);
}
.meter {
  flex: 1 1 10rem;
  max-width: 18rem;
  height: 8px;
  border-radius: 4px;
  /* Track is a lighter step of the same status color. */
  background: color-mix(in srgb, var(--status) 24%, var(--sheet));
  overflow: hidden;
}
.meter-fill {
  display: block;
  height: 100%;
  background: var(--status);
  border-radius: 0 4px 4px 0;
}
.status-icon {
  flex: none;
}
.status-icon-bg {
  fill: var(--status);
}
.status-icon-mark {
  fill: none;
  stroke: var(--on-status);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.status-icon-dot {
  fill: var(--on-status);
}
.s-warning .status-icon-mark {
  stroke: var(--on-warning);
}
.s-warning .status-icon-dot {
  fill: var(--on-warning);
}

/* ---- The income strip ------------------------------------------------------------ */
.strip-block {
  margin-top: 1.75rem;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-panel);
  padding: clamp(16px, 2.4vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.strip-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}
.strip-head h2 {
  font-size: 1.0625rem;
  font-weight: 700;
}
.strip-wrap {
  position: relative;
}
.strip-wrap.has-mark {
  padding-top: 1.6rem;
}
.strip {
  display: grid;
  column-gap: 2px; /* the surface-colored gap between slices */
  height: 3.25rem;
}
.strip-slice {
  display: flex;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  padding: 0 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: default;
}
.strip-slice:first-child {
  border-radius: 4px 0 0 4px;
}
.strip-slice:last-child {
  border-radius: 0 4px 4px 0;
}
.strip-slice:only-child {
  border-radius: 4px;
}
.strip-slice:hover {
  filter: brightness(1.08);
}
.strip-slice:focus-visible {
  outline-offset: 2px;
}
.strip-income-mark {
  position: absolute;
  top: 0;
  bottom: -6px;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
}
.strip-income-mark span {
  position: absolute;
  top: 0;
  right: 6px;
  white-space: nowrap;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--critical-text);
}

/* Group colors, shared by strip slices, swatches and bars. */
.slice-taxes {
  background: var(--g-taxes);
  color: var(--g-taxes-on);
}
.slice-needs {
  background: var(--g-needs);
  color: var(--g-needs-on);
}
.slice-debt {
  background: var(--g-debt);
  color: var(--g-debt-on);
}
.slice-wants {
  background: var(--g-wants);
  color: var(--g-wants-on);
}
.slice-savings {
  background: var(--g-savings);
  color: var(--g-savings-on);
}
.slice-rest {
  background: var(--g-rest);
  color: var(--g-rest-on);
}
.slice-other {
  background: var(--g-other);
  color: var(--g-other-on);
}

.swatch {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* Legend under the strip */
.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}
.legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.875rem;
}
.legend-name {
  color: var(--ink-2);
}
.legend-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.legend-share {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Key figures (used under the strip and on the Budget/Spending pages) */
.figures {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.75rem 1.5rem;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
}
.figures div {
  min-width: 0;
}
.figures dt {
  color: var(--ink-2);
  font-size: 0.8125rem;
}
.figures dd {
  margin: 0;
  font-size: clamp(1.125rem, 1rem + 0.6vw, 1.375rem);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.figures .is-bad dd {
  color: var(--critical-text);
}
.figure-note {
  color: var(--muted);
  font-size: 0.8125rem;
}
.figures-panel {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-panel);
  padding: 16px clamp(16px, 2.4vw, 24px);
}

/* Planned / Spent toggle */
.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-control);
  background: var(--paper);
}
.segmented button {
  height: 2rem;
  padding: 0 0.8rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.segmented button[aria-pressed='true'] {
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--rule-strong);
}
.segmented button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---- Overview columns ----------------------------------------------------------- */
.columns {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.side {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}
@media (max-width: 920px) {
  .columns {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---- Category list ----------------------------------------------------------------- */
.cat-group {
  display: flex;
  flex-direction: column;
}
.cat-group + .cat-group {
  margin-top: 10px;
}
.cat-group-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}
.cat-group-head h3 {
  font-size: 0.9375rem;
  font-weight: 700;
}
.cat-group-total {
  margin-left: auto;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cat-group-share {
  color: var(--muted);
  font-size: 0.8125rem;
  min-width: 6.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.cat-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.cat-row {
  display: grid;
  grid-template-columns: minmax(0, 11rem) minmax(0, 1fr) 5.5rem;
  align-items: center;
  gap: 4px 1rem;
  padding: 9px 0;
}
.cat-row + .cat-row {
  border-top: 1px solid var(--rule);
}
.cat-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-wrap: anywhere;
}
.cat-freq {
  color: var(--muted);
  font-size: 0.8125rem;
}
.cat-bar {
  height: 8px;
}
.cat-bar span {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: 0 4px 4px 0; /* rounded data end, square at the baseline */
}
.cat-amount {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
/* This month's progress sits under the bar and amount columns. */
.cat-progress {
  grid-column: 2 / 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
}
.progress {
  height: 3px;
  border-radius: 2px;
  background: var(--track);
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  background: var(--ink-2);
}
.progress.is-over span {
  background: var(--critical);
}
.cat-progress-text {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 560px) {
  .cat-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .cat-bar,
  .cat-progress {
    grid-column: 1 / -1;
  }
  .cat-bar {
    grid-row: 2;
  }
}
.cat-progress-text .status-icon {
  width: 15px;
  height: 15px;
}
.cat-progress-text.is-over strong {
  color: var(--critical-text);
}

/* ---- Health checks ------------------------------------------------------------- */
.checks {
  list-style: none;
  margin: 0;
  padding: 0;
}
.check {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 0.75rem;
  padding: 12px 0;
}
.check + .check {
  border-top: 1px solid var(--rule);
}
.check .status-icon,
.status-icon-placeholder {
  margin-top: 1px;
}
.status-icon-placeholder {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--rule-strong);
}
.check-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.check-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}
.check-top h3 {
  font-size: 0.9375rem;
  font-weight: 700;
}
.check-points {
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.check-detail {
  color: var(--ink-2);
  font-size: 0.875rem;
}
.check-detail strong {
  color: var(--ink);
}
.check-tip {
  color: var(--muted);
  font-size: 0.8125rem;
}
.check.is-pending h3 {
  color: var(--ink-2);
}

/* ---- 50/30/20 bars -------------------------------------------------------------- */
.targets {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.target-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.target-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.6rem;
  font-size: 0.875rem;
}
.target-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.target-goal {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--ink-2);
  font-size: 0.8125rem;
}
.target-goal .status-icon {
  width: 15px;
  height: 15px;
}
.target-track {
  position: relative;
  height: 10px;
  background: var(--track);
  border-radius: 2px;
}
.target-fill {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
}
.target-tick {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
}

/* ---- Budget editor ---------------------------------------------------------------- */
.page-head {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 1rem;
}
.page-head-row {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}
.budget-page .figures-panel,
.spending-page .figures-panel {
  border-top: 1px solid var(--rule);
}
.edit-group-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.edit-group-head h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.edit-rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.edit-row {
  display: grid;
  gap: 6px 8px;
  align-items: center;
}
.edit-row-category {
  grid-template-columns: minmax(0, 1fr) 8.5rem 10rem 9.5rem 2.25rem;
  grid-template-areas: 'name amount freq group del' 'hint hint hint hint hint';
}
.edit-row-income {
  grid-template-columns: minmax(0, 1fr) 8.5rem 10rem 2.25rem;
  grid-template-areas: 'name amount freq del' 'hint hint hint hint';
}
.edit-row .in-name {
  grid-area: name;
}
.edit-row .money-input {
  grid-area: amount;
}
.edit-row .in-freq {
  grid-area: freq;
}
.edit-row .in-group {
  grid-area: group;
}
.edit-row .icon-btn {
  grid-area: del;
}
.row-monthly {
  grid-area: hint;
  color: var(--muted);
  font-size: 0.8125rem;
  margin-top: -2px;
}
.row-monthly:empty {
  display: none;
}
@media (max-width: 700px) {
  .edit-row-category {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 2.25rem;
    grid-template-areas: 'name name del' 'amount freq freq' 'group group group' 'hint hint hint';
  }
  .edit-row-income {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 2.25rem;
    grid-template-areas: 'name name del' 'amount freq freq' 'hint hint hint';
  }
  .edit-row + .edit-row {
    border-top: 1px solid var(--rule);
    padding-top: 10px;
  }
}
.template-offer {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}

/* Inputs */
input[type='text'],
input[type='number'],
input[type='date'],
select {
  width: 100%;
  min-width: 0;
  height: 2.5rem;
  padding: 0 0.65rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-control);
  background: var(--field);
  color: var(--ink);
}
input::placeholder {
  color: var(--muted);
}
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}
.money-input {
  position: relative;
  display: block;
  min-width: 0;
}
.money-input > span {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.money-input input {
  padding-left: 1.4rem;
  font-variant-numeric: tabular-nums;
}

/* Save bar: sticks to the bottom of the screen while there are edits. */
.savebar {
  position: sticky;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  border-radius: var(--radius-panel);
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}
.savebar p {
  flex: 1 1 12rem;
  font-weight: 600;
}
.savebar .btn-quiet {
  color: var(--paper);
}
.savebar .btn-quiet:hover {
  background: rgba(128, 128, 128, 0.2);
  color: var(--paper);
}
.savebar .btn-primary {
  background: var(--paper);
  color: var(--ink);
}

/* ---- Spending page ----------------------------------------------------------------- */
.add-form {
  display: grid;
  grid-template-columns: 10.5rem minmax(0, 1fr) 9rem minmax(0, 1.2fr) auto;
  gap: 10px;
  align-items: end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.field > span:first-child {
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 600;
}
.form-error {
  grid-column: 1 / -1;
  color: var(--critical-text);
  font-weight: 600;
  font-size: 0.875rem;
}
@media (max-width: 860px) {
  .add-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .add-form .field-wide,
  .add-form .btn {
    grid-column: 1 / -1;
  }
}

.tx-day + .tx-day {
  margin-top: 6px;
}
.tx-day-head {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 700;
}
.tx-day-total {
  font-variant-numeric: tabular-nums;
}
.tx-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.tx {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.75rem;
  padding: 6px 0;
}
.tx + .tx {
  border-top: 1px solid var(--rule);
}
.tx-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.tx-cat {
  overflow-wrap: anywhere;
}
.tx-note {
  color: var(--muted);
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
}
.tx-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.tx-confirm {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
  font-size: 0.875rem;
}
.tx.is-confirming {
  grid-template-columns: 10px minmax(0, 1fr) auto;
}
.tx.is-confirming .tx-confirm {
  grid-column: 2 / -1;
}

/* ---- Toast & tooltip ---------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  z-index: 20;
  max-width: min(32rem, calc(100vw - 32px));
  padding: 0.7rem 1rem;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  font-size: 0.875rem;
  /* Hidden until a message arrives; then it slides up a little. */
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  pointer-events: none;
}
.toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}
.toast.is-error {
  background: var(--critical);
  color: #ffffff;
}
.tooltip {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-control);
  background: var(--sheet);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  font-size: 0.8125rem;
  max-width: 16rem;
}
.tooltip strong {
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.tooltip span {
  color: var(--ink-2);
}

/* ---- Motion preferences ------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .toast,
  .main {
    transition: none;
  }
}
