/*
 * Hello Budget Mini App — GPM design system.
 *
 * Slate ink, one cyan accent used sparingly, Geist everywhere with Geist Mono for
 * labels and amounts, borders instead of shadows. The dark palette is not an
 * afterthought: most people read Telegram in dark mode.
 *
 * Every rule is written once. Half of this file used to be here twice — the keypad, the buttons,
 * the fields, the empty state — with the second copy quietly winning, so reading the first one
 * told you the wrong thing about what the screen looked like.
 */

:root {
  --ink-950: #020617;
  --ink-900: #0F172A;
  --ink-500: #64748B;
  --ink-400: #94A3B8;
  --ink-150: #E9EEF4;
  --ink-100: #F1F5F9;
  --ink-50:  #F8FAFC;

  --bg: var(--ink-50);
  --surface: #FFFFFF;
  --surface-2: var(--ink-50);
  --border: var(--ink-150);
  --border-strong: #E2E8F0;
  --text: var(--ink-900);
  --text-muted: var(--ink-500);
  --text-subtle: var(--ink-400);
  --text-on-accent: #FFFFFF;
  --accent: #0E7490;
  --accent-hover: #155E75;
  --accent-soft: #ECFEFF;
  --success: #1F8A5B;
  --danger: #C0392B;

  --font-sans: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', 'Roboto Mono', monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  /* the sheet's own corner. It was used here and never defined, so the card that slides up from
     the bottom — the one screen this app is mostly used through — had square corners */
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* Motion.
     One curve and three durations, so that everything that moves moves the same way. The curve
     decelerates hard: things arrive rather than drift, which is what makes a screen feel answered
     instead of slow. Nothing here runs longer than a third of a second. */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --fast: 130ms;
  --medium: 220ms;
  --slow: 320ms;
}

/* Telegram sets this class from the client theme; the media query catches the rest */
:root.dark, html.dark {
  --bg: var(--ink-950);
  --surface: #111B2E;
  --surface-2: #1A2740;
  --border: #283449;
  --border-strong: #3A4862;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --text-subtle: #64748B;
  --text-on-accent: #04121A;
  --accent: #22D3EE;
  --accent-hover: #67E8F9;
  --accent-soft: rgba(34, 211, 238, 0.14);
  --success: #34B27B;
  --danger: #E2604F;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  /* the safe area keeps the last row clear of the home indicator */
  padding-bottom: env(safe-area-inset-bottom);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* ---- motion ----
   The keyframes everything borrows. They are declared once and used by name, so a screen, a row
   and a panel all enter the same way and the app reads as one thing rather than as a set of
   screens that each had their own idea. */

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* the placeholder rows while the answer is on its way: a block that sits still reads as a screen
   that has stopped, and the sweep is the difference between waiting and broken */
@keyframes shimmer {
  from { background-position: -160px 0; }
  to   { background-position: 240px 0; }
}

/* ---- screens ---- */

.screen {
  display: none;
  padding: var(--space-4);
  /* the top bar is fixed, so every screen starts below it */
  padding-top: calc(var(--space-4) + 44px + env(safe-area-inset-top));
  padding-bottom: 96px;
}
.screen.is-active {
  display: block;
  animation: rise var(--medium) var(--ease) both;
}

/* ---- month header ---- */

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

.month__label {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
/* the label is what changed when an arrow was pressed, so it is what says so */
.month__label.is-changed { animation: fade var(--medium) var(--ease); }

.month__nav {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: transform var(--fast) var(--ease), background var(--fast) linear;
}
.month__nav:active { background: var(--surface-2); transform: scale(0.92); }

/* ---- total ---- */

.total {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.total__amount {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: var(--space-1);
}

/* what came in and what is left of it, under what went out: two figures of the same size as each
   other and smaller than the one above, because the month is read as one number and then two */
.total__pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.total__small {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: var(--space-1);
}
.total__small.is-negative { color: var(--danger); }

/* a figure that has just been recalculated says so, briefly. Without it a delete and a month
   change look the same as nothing happening */
.total__amount.is-changed, .total__small.is-changed { animation: bump var(--slow) var(--ease); }

/* ---- lists ---- */

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

/* the rows arrive one after the other rather than all at once. The delay is small and stops at
   the eighth: past that it is not a list appearing, it is a list being slow */
.list > * { animation: rise var(--medium) var(--ease) both; }
.list > *:nth-child(1) { animation-delay: 0ms; }
.list > *:nth-child(2) { animation-delay: 24ms; }
.list > *:nth-child(3) { animation-delay: 48ms; }
.list > *:nth-child(4) { animation-delay: 72ms; }
.list > *:nth-child(5) { animation-delay: 96ms; }
.list > *:nth-child(6) { animation-delay: 120ms; }
.list > *:nth-child(7) { animation-delay: 144ms; }
.list > *:nth-child(n+8) { animation-delay: 160ms; }

.expense {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: border-color var(--fast) linear, transform var(--fast) var(--ease);
}
.expense:active { transform: scale(0.99); }
.expense.is-selected { border-color: var(--accent); }

.expense__day {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-subtle);
  white-space: nowrap;
}
.expense__body { min-width: 0; }
.expense__description {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.expense__category { font-size: 13px; color: var(--text-muted); }
.expense__amount {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}
.expense__instalment { font-family: var(--font-mono); }

.empty {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-7) var(--space-4);
  text-align: center;
  color: var(--text-muted);
}

.skeleton {
  height: 64px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  background-image: linear-gradient(90deg, transparent, var(--border), transparent);
  background-repeat: no-repeat;
  background-size: 160px 100%;
  animation: shimmer 1100ms linear infinite;
}

/* ---- add card ---- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(2, 6, 23, 0.55);
  opacity: 0;
  transition: opacity var(--medium) ease;
}
.sheet-backdrop.is-open { opacity: 1; }
.sheet-backdrop[hidden] { display: none; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  transform: translateY(100%);
  transition: transform 260ms var(--ease);
}
.sheet.is-open { transform: translateY(0); }
.sheet[hidden] { display: none; }

.sheet__grip {
  flex: none;
  width: 40px;
  height: 4px;
  margin: var(--space-3) auto var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}

.sheet__body {
  overflow-y: auto;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

/* ---- amount ---- */

.amount-display {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  text-align: right;
}
.amount-display__pending {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  min-height: 20px;
  transition: opacity var(--fast) linear;
}
.amount-display__value {
  font-family: var(--font-mono);
  font-size: 38px;
  font-weight: 600;
  letter-spacing: -0.02em;
  overflow-x: auto;
  white-space: nowrap;
  /* the origin is the right edge, where the digits are: growing from the middle would move the
     number sideways every time it changed */
  transform-origin: right center;
}
/* the display answers the key that was pressed. Without it the only thing that says a tap landed
   is the digit itself, and a digit added to a long number is not something the eye catches */
.amount-display__value.is-bumped { animation: bump var(--fast) var(--ease); }

/* ---- keypad ---- */

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.key {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  padding: var(--space-4) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  /* a keypad gets hammered: without this every tap tries to select the label */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--fast) var(--ease), background var(--fast) linear;
}
.key:active { background: var(--surface-2); transform: scale(0.94); }
.key--op { color: var(--accent); }
.key--muted { color: var(--text-muted); }
.key--wide { grid-column: span 2; }

/* the operator that is waiting for its right hand side stays lit, so the display and the keypad
   agree about what the calculator is in the middle of */
.key--op.is-armed {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.key--save {
  color: var(--text-on-accent);
  background: var(--accent);
  border-color: var(--accent);
  font-family: var(--font-sans);
  font-size: 17px;
  font-weight: 600;
}
.key--save:active { background: var(--accent-hover); }
.key--save[disabled] { opacity: 0.45; transform: none; }

/* ---- chips ---- */

.chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-1);
  /* the row scrolls sideways rather than wrapping: a wrapping row of thirty categories
     would push the keypad off the screen */
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips--wrap { flex-wrap: wrap; overflow-x: visible; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-sans);
  font-size: 15px;
  white-space: nowrap;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--fast) var(--ease), background var(--fast) linear,
              color var(--fast) linear, border-color var(--fast) linear;
}
.chip:active { transform: scale(0.94); }
.chip.is-selected {
  color: var(--text-on-accent);
  background: var(--accent);
  border-color: var(--accent);
}
.chip--more { border-style: dashed; }
.chip--date { position: relative; overflow: hidden; }
/* the native picker is what opens on tap, so the input covers the chip and stays invisible */
.chip--date input {
  position: absolute;
  inset: 0;
  opacity: 0;
  border: none;
  padding: 0;
}

.budget-hint {
  min-height: 20px;
  margin-bottom: var(--space-2);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  transition: color var(--fast) linear;
}
.budget-hint--over { color: var(--danger); }

/* ---- fields ---- */

.field { margin-bottom: var(--space-4); }
.field__label { display: block; margin-bottom: var(--space-2); }

.input, .select {
  width: 100%;
  padding: var(--space-3);
  font-family: var(--font-sans);
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--fast) linear;
}
.input:focus, .select:focus { outline: none; border-color: var(--accent); }
.input--description { margin-bottom: var(--space-3); }

/* a control that sits on a row rather than owning one */
.select--inline { width: auto; padding: var(--space-2) var(--space-3); }

/* ---- buttons ---- */

.button {
  display: block;
  width: 100%;
  padding: var(--space-4);
  font-family: var(--font-sans);
  font-size: 17px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--text-on-accent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--fast) var(--ease), background var(--fast) linear,
              border-color var(--fast) linear, opacity var(--fast) linear;
}
.button:active { background: var(--accent-hover); border-color: var(--accent-hover); transform: scale(0.98); }
.button[disabled] { opacity: 0.45; cursor: default; transform: none; }

.button--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.button--ghost:active { background: var(--surface-2); border-color: var(--border-strong); }

.button--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #FFFFFF;
}

.button--small { padding: var(--space-2) var(--space-3); font-size: 15px; }

/* a label that behaves like a button, because a file input cannot be styled and can be hidden
   behind one that can */
.import-button { text-align: center; cursor: pointer; }

/* ---- tab bar ---- */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

/* the hidden attribute only sets display:none at user agent priority, which display:grid
   above wins against: without this the bar stays on screen on the landing */
.tabs[hidden] { display: none; }

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: var(--space-2) 0 var(--space-3);
  background: none;
  border: none;
  border-top: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--medium) linear, border-color var(--medium) linear;
}
.tab__icon {
  width: 22px;
  height: 22px;
  /* the icon takes the colour of the tab, so the active state needs saying only once */
  color: inherit;
  transition: transform var(--medium) var(--ease);
}
.tab:active .tab__icon { transform: scale(0.88); }
.tab.is-active .tab__icon { transform: translateY(-1px); }

.tab__label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tab.is-active { color: var(--accent); border-top-color: var(--accent); }

/* the add button sits in the middle of the bar and is the only filled thing on the
   screen, because it is the one action the app exists for */
.tab--add {
  justify-self: center;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-top: -18px;
  padding: 0;
  border-radius: var(--radius-pill);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--text-on-accent);
}

.tab--add .tab__icon { width: 24px; height: 24px; stroke-width: 2; }
.tab--add:active { background: var(--accent-hover); }
.tab--add:active .tab__icon { transform: scale(0.86) rotate(90deg); }

/* ---- cards, rows, sections ---- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.section-head--spaced { margin-top: var(--space-6); }
/* the button next to a heading is a button, not a column: without this the flex row stretches it
   to whatever is left of the width, and "Aggiungi" ends up the size of a save button */
.section-head .button { flex: none; width: auto; }
.section-head__count { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: var(--space-4);
}

.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1) 0;
}
.row__label { font-size: 15px; }
.row__value { font-family: var(--font-mono); font-size: 15px; font-weight: 600; }
.row__meta { font-size: 13px; color: var(--text-muted); }

/* two buttons to a row, for the ones that come in families: four exports one under the other are
   four full width buttons, which reads as four decisions rather than as one list */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin: var(--space-2) 0 var(--space-4);
}

.form__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

/* ---- rows that can be acted on ---- */

/* three buttons where there were two: cancel, correct, delete */
.row-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-top: var(--space-2);
  animation: rise var(--fast) var(--ease) both;
}

/* ---- budgets ---- */

.budget { display: block; cursor: pointer; }
.budget__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.budget__name { font-size: 15px; font-weight: 600; }
.budget__amounts { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }

.meter {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  width: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  /* the bar grows into place from nothing: a bar that is simply there says how full the budget is,
     a bar that fills says how full it got */
  transition: width var(--slow) var(--ease), background var(--medium) linear;
}
/* over budget is the one thing on this screen worth a colour of its own */
.meter__fill--over { background: var(--danger); }

/* ---- subscriptions and incomes ---- */

.subscription {
  cursor: pointer;
  transition: border-color var(--fast) linear, transform var(--fast) var(--ease);
}
.subscription:active { transform: scale(0.99); }
.subscription.is-selected { border-color: var(--accent); }

/* something that takes or brings nothing in the month on the screen. It is here because it exists,
   not because it is part of the figure above: still readable, still tappable, and no longer one of
   the rows the total is made of */
.is-idle { opacity: 0.55; }

.subscription-form { margin-bottom: var(--space-4); }
.subscription-form .field:last-of-type { margin-bottom: var(--space-4); }

/* ---- folds ----
   A section that is closed until it is asked for. The profile carried thirteen of these open at
   once; the guide chapters were the only thing already folded, and they were folded by a rule that
   another rule further down the file was overriding into a two column grid. */

.folds { display: flex; flex-direction: column; gap: var(--space-2); }
.folds .fold + .fold { margin-top: 0; }

.fold {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  margin-bottom: var(--space-3);
}

.fold__title {
  list-style: none;
  cursor: pointer;
  padding: var(--space-3) var(--space-4);
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  -webkit-tap-highlight-color: transparent;
}
.fold__title::-webkit-details-marker { display: none; }

/* the name takes the room, so whatever comes after it — a figure, the chevron — sits at the far
   edge whether or not there is a figure. Pushing the chevron with a margin instead put it against
   the name on every section that had no figure to show */
.fold__title > span:first-child { flex: 1; }

/* the figure a closed section would otherwise have to be opened to see */
.fold__value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
}

.fold__title::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
  transform: rotate(45deg);
  transition: transform var(--medium) var(--ease);
  flex: none;
}
.fold[open] > .fold__title::after { transform: rotate(-135deg); }

.fold__body {
  padding: 0 var(--space-4) var(--space-4);
  animation: rise var(--medium) var(--ease) both;
}
.fold__body > * + * { margin-top: var(--space-3); }

/* a chapter of the guide: the same fold, with the text of the chapter inside it */
.fold__text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-muted);
  white-space: pre-line;
}

/* ---- messages ---- */

.notice {
  position: sticky;
  top: 0;
  z-index: 10;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--surface);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-3) var(--space-4) 0;
  border-radius: var(--radius-sm);
  font-size: 15px;
  animation: rise var(--medium) var(--ease) both;
}
.notice--error { border-left-color: var(--danger); }
.notice[hidden] { display: none; }

/* ---- charts ---- */

.chart-card { margin-bottom: var(--space-3); }
.chart-card .eyebrow { margin-bottom: var(--space-3); }

.bar {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.bar__label {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar__track {
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.bar__fill {
  height: 100%;
  width: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  transition: width var(--slow) var(--ease);
}
.bar__value {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}
/* A budget that is over is over on the bar too: colour alone is not something everybody sees, so
   the value is also set in bold. */
.bar--over .bar__fill { background: var(--danger); }
.bar--over .bar__value { color: var(--danger); font-weight: 600; }

/* ---- users, categories: a row with something to press ---- */

.user {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: var(--space-3) var(--space-4);
}
.user__name { font-size: 15px; }
.user__meta { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

/* ---- category picker ----
   The row shows the few that are actually used and sends the rest to a screen of its own.
   A search field inside the add card is a row the keypad loses, and tapping it brings up
   a keyboard that covers the card it is in. */

.picker {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: var(--space-4);
  padding-top: calc(var(--space-4) + env(safe-area-inset-top));
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  gap: var(--space-4);
  animation: rise var(--medium) var(--ease) both;
}
.picker[hidden] { display: none; }
.picker__head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-3);
}
.picker__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.picker__row {
  text-align: left;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: transform var(--fast) var(--ease), border-color var(--fast) linear;
}
.picker__row:active { transform: scale(0.99); }
.picker__row.is-selected { border-color: var(--accent); }

/* ---- writing a budget ----
   The categories a budget covers wrap rather than scroll: here the list is being read, not
   walked past, and one hidden off the right is one nobody ticks. */
.budget-form { margin-bottom: var(--space-4); }
.budget-form .button--danger { margin-top: var(--space-3); }

/* ---- stats ----
   Figures first, caption under: the screen is read by scanning the numbers down the
   grid, and a label above each one would put four words between every two of them. */
.stats__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}
.stats__title + .stats { margin-bottom: var(--space-5); }
.stats:last-child { margin-bottom: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: var(--space-3);
}
.stat {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  animation: fade var(--medium) var(--ease) both;
}
.stat__value { font-family: var(--font-mono); font-size: 20px; line-height: 1.1; }
.stat__label { font-size: 12px; color: var(--text-muted); margin-top: var(--space-1); }

/* ---- pro ----
   What the two plans are, side by side. A list of what is missing is not a reason to pay: the
   free column says what somebody already has, and the numbers in it are the server's, asked for
   rather than written here, so a limit changed in the configuration is not a lie on this screen. */

.plans {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin: var(--space-3) 0 var(--space-4);
}
.plan {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}
.plan--pro { border-color: var(--accent); background: var(--accent-soft); }
.plan__name {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: var(--space-2);
}
.plan--pro .plan__name { color: var(--accent); }
.plan__line {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}
.plan__line + .plan__line { margin-top: var(--space-1); }

/* ---- landing ----
   What somebody who reached the page outside Telegram sees. The page has to be
   publicly reachable for the client to load it, so this is a real screen, not a
   fallback: it says why nothing works here and where to go instead. */

.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-6);
}
.landing[hidden] { display: none; }

.landing__card {
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: var(--space-6);
  text-align: center;
  animation: rise var(--slow) var(--ease) both;
}
.landing__card--wide { max-width: 460px; text-align: left; }

.landing__title {
  margin: var(--space-3) 0 var(--space-2);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.landing__text {
  margin: 0 0 var(--space-5);
  color: var(--text-muted);
  font-size: 15px;
}

.landing__button { text-decoration: none; text-align: center; }

.landing__meta {
  margin: var(--space-3) 0 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-subtle);
}

/* ---- welcome ----
   One line per tab. These carried the class the guide chapters carry, further down the same file,
   which meant the chapters were being drawn as this: a summary squeezed into a 76px column with
   its chapter next to it. Two different things now have two different names. */

.map {
  margin: 0 0 var(--space-5);
  padding: 0;
  list-style: none;
}
.map__item {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: var(--space-3);
  align-items: baseline;
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}
.map__item:first-child { border-top: none; }
.map__key {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.map__text { font-size: 15px; color: var(--text-muted); }

/* ---- shared accounts ----
   Opening one, and inviting somebody into it. The form is built with the card and hidden rather
   than created on the press: half a handle typed and then lost to a redraw is how somebody gives
   up on a feature. */

.shared-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.shared-form[hidden] { display: none; }

/* ---- top bar ---- */

/* Two things live up here rather than in the tab bar: the profile and, for whoever runs the
   instance, the admin section. Neither is something you tap while writing down what you spent,
   and the bar below is a grid of five — a sixth button fell onto a second row. */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  height: calc(44px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--space-4) 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar[hidden] { display: none; }

.topbar__title {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.topbar__more {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-right: calc(var(--space-2) * -1);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--fast) linear, color var(--fast) linear;
}

.topbar__more svg { width: 20px; height: 20px; }
.topbar__more[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }

.overflow-menu {
  position: fixed;
  top: calc(44px + env(safe-area-inset-top) + var(--space-1));
  right: var(--space-3);
  z-index: 26;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  transform-origin: top right;
  animation: rise var(--fast) var(--ease) both;
}

.overflow-menu[hidden] { display: none; }

.overflow-menu__item {
  padding: var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.overflow-menu__item[hidden] { display: none; }
.overflow-menu__item:active { background: var(--surface-2); }

/* ---- less motion ----
   Somebody who asked the system for less of it gets none: everything above still arrives, it just
   arrives already there. This is one block at the end rather than a rule at each place, so a thing
   that starts moving cannot be added without this catching it. */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
