/*
 * Budget App styles, built from design/screens/project/.
 *
 * Every colour, shadow, font, type size, space and radius comes from the
 * custom properties in tokens.css (generated from the design tokens), so
 * the light and dark themes both come from the tokens. No colour literals
 * here (spec 001, AC14).
 */

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

html {
  color-scheme: light dark;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-canvas);
  color: var(--color-ink);
  font-family: var(--text-body-family);
  font-size: var(--text-body-size);
  line-height: var(--text-body-line-height);
  font-weight: var(--text-body-weight);
}

h1,
h2,
p,
dl,
dd,
ul {
  margin: 0;
}

a {
  color: var(--color-brand-strong);
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Type styles ---------------------------------------------------------- */

.text-title {
  font-family: var(--text-title-family);
  font-size: var(--text-title-size);
  line-height: var(--text-title-line-height);
  font-weight: var(--text-title-weight);
  letter-spacing: var(--text-title-letter-spacing);
}

.text-heading {
  font-family: var(--text-heading-family);
  font-size: var(--text-heading-size);
  line-height: var(--text-heading-line-height);
  font-weight: var(--text-heading-weight);
  letter-spacing: var(--text-heading-letter-spacing);
}

.text-amount-hero {
  font-family: var(--text-amount-hero-family);
  font-size: var(--text-amount-hero-size);
  line-height: var(--text-amount-hero-line-height);
  font-weight: var(--text-amount-hero-weight);
  letter-spacing: var(--text-amount-hero-letter-spacing);
  font-variant-numeric: tabular-nums;
}

.text-label {
  font-family: var(--text-label-family);
  font-size: var(--text-label-size);
  line-height: var(--text-label-line-height);
  font-weight: var(--text-label-weight);
}

.text-caption {
  font-family: var(--text-caption-family);
  font-size: var(--text-caption-size);
  line-height: var(--text-caption-line-height);
  font-weight: var(--text-caption-weight);
  letter-spacing: var(--text-caption-letter-spacing);
}

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

.amount {
  font-family: var(--text-amount-family);
  font-size: var(--text-amount-size);
  line-height: var(--text-amount-line-height);
  font-weight: var(--text-amount-weight);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.amount--negative {
  color: var(--color-negative);
}

.amount--positive {
  color: var(--color-positive);
}

/* Screens ---------------------------------------------------------------- */

.screen {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: calc(var(--space-8) + var(--space-4)) var(--space-4) var(--space-6);
}

.screen--detail {
  padding-top: calc(var(--space-8) + var(--space-2));
}

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

.stack-tight {
  display: flex;
  flex-direction: column;
  gap: calc(var(--space-1) / 2);
}

.stack-1 {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

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

.stack-4 {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

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

form.button_to {
  display: contents;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 56px;
  padding: 0 calc(var(--space-6) + var(--space-1));
  border-radius: var(--radius-full);
  border: 0;
  text-decoration: none;
  font-family: var(--text-label-family);
  font-size: var(--text-label-size);
  line-height: var(--text-label-line-height);
  font-weight: var(--text-label-weight);
}

.button--primary {
  background: var(--color-brand);
  color: var(--color-on-brand);
}

.button--outline {
  background: var(--color-surface);
  color: var(--color-ink);
  border: 1.5px solid var(--color-ink-muted);
}

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

.button--raised {
  box-shadow: var(--shadow-card);
}

.button__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.icon-button {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-canvas);
  color: var(--color-ink);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-hero);
  color: var(--color-on-hero);
  font-family: var(--text-label-family);
  font-size: var(--text-label-size);
  line-height: var(--text-label-line-height);
  font-weight: var(--text-label-weight);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 44px;
  color: var(--color-ink);
  text-decoration: none;
}

.back-link svg {
  width: 22px;
  height: 22px;
}

/* Home's Withdraw button floats over the list, always in reach. The list
   ends with room for it: button height, its offset and a gap. */
html:has(.floating-action) {
  /* A row focused from the keyboard scrolls clear of the button, too. */
  scroll-padding-bottom: calc(var(--space-8) * 3 + env(safe-area-inset-bottom));
}

.screen--with-floating-action {
  padding-bottom: calc(var(--space-8) * 3 + env(safe-area-inset-bottom)); /* 96px: the 56px button, its 16px offset and a 24px gap */
}

.floating-action {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  padding: 0 var(--space-4);
  pointer-events: none;
}

.floating-action .button {
  pointer-events: auto;
}

/* Hero ------------------------------------------------------------------- */

.hero {
  background: var(--color-hero);
  color: var(--color-on-hero);
  border-radius: var(--radius-lg);
  padding: calc(var(--space-4) + var(--space-1));
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.hero__soft {
  opacity: 0.78;
}

.hero__meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
}

.hero .progress {
  height: 10px;
  background: color-mix(in srgb, var(--color-on-hero) 22%, transparent);
}

.hero .progress__fill {
  background: var(--color-brand);
}

/* Cards, categories and pot rows ----------------------------------------- */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
}

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

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

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

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  color: var(--color-ink);
  text-decoration: none;
}

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

.row__main {
  flex-grow: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: calc(var(--space-1) / 2);
}

.row__main--with-progress {
  gap: var(--space-1);
}

.row__side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
}

a.row:hover .row__name {
  text-decoration: underline;
}

.progress {
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-brand-soft);
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-brand-strong);
}

.pill {
  display: inline-block;
  padding: calc(var(--space-1) / 2) var(--space-2);
  border-radius: var(--radius-full);
  font-family: var(--text-caption-family);
  font-size: var(--text-caption-size);
  line-height: var(--text-caption-line-height);
  font-weight: var(--text-label-weight);
  white-space: nowrap;
}

.row__side .pill {
  align-self: flex-end;
}

.hero .pill {
  align-self: flex-start;
}

.pill--overspent {
  color: var(--color-negative);
  background: var(--color-negative-soft);
}

/* Details and history ---------------------------------------------------- */

.details__item {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

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

.details__item dt {
  color: var(--color-ink-muted);
}

.details__item dd {
  font-family: var(--text-amount-family);
  font-weight: var(--text-amount-weight);
  font-variant-numeric: tabular-nums;
}

.history {
  list-style: none;
  padding: 0;
}

/* Notices ---------------------------------------------------------------- */

.notice {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  font-weight: var(--text-label-weight);
}

.notice svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--color-positive);
}

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  color: var(--color-negative);
  background: var(--color-negative-soft);
  font-weight: var(--text-label-weight);
}

/* Sheets (Account, Withdraw, Withdraw from) ------------------------------ */

.sheet-page {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.sheet-page__scrim {
  position: fixed;
  inset: 0;
  background: var(--color-hero);
  opacity: 0.45;
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-2) var(--space-4) calc(var(--space-6) + var(--space-1));
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  box-shadow: var(--shadow-card);
}

.sheet--tall {
  height: calc(100dvh - var(--space-8) - var(--space-2));
  padding: var(--space-2) 0 var(--space-4);
  gap: var(--space-2);
}

.sheet__grabber {
  align-self: center;
  width: 40px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--color-line);
}

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

.sheet--tall .sheet__header {
  padding: 0 var(--space-4);
}

.sheet__form {
  flex-grow: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sheet__scroll {
  flex-grow: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sheet__footer {
  padding: var(--space-2) var(--space-4) 0;
  border-top: 1px solid var(--color-line);
}

.pot-confirm {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  text-align: center;
}

.sheet__form:not(:has(input[name="pot_id"]:checked)) .pot-confirm__ready,
.sheet__form:has(input[name="pot_id"]:checked) .pot-confirm__waiting {
  display: none;
}

.account-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-canvas);
}

.account-card__text {
  flex-grow: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: calc(var(--space-1) / 2);
  overflow-wrap: anywhere;
}

/* Withdraw --------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: calc(var(--space-1) * 1.5);
}

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

.field__error {
  color: var(--color-negative);
  font-weight: var(--text-label-weight);
}

.field__hint--overspent {
  color: var(--color-negative);
}

.text-input {
  height: 48px;
  padding: 0 calc(var(--space-4) - var(--space-1) / 2);
  border: 1.5px solid var(--color-ink-muted);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-ink);
  font-family: var(--text-body-family);
  font-size: var(--text-body-size);
}

.text-input--invalid {
  border-color: var(--color-negative);
}

.amount-input {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  height: 72px;
  padding: 0 var(--space-4);
  border: 1.5px solid var(--color-ink-muted);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
}

.amount-input:focus-within {
  box-shadow: var(--focus-ring);
}

.amount-input--invalid {
  border-color: var(--color-negative);
}

.amount-input__currency {
  color: var(--color-ink-muted);
}

.amount-input input {
  flex-grow: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--color-ink);
}

.amount-input input:focus-visible {
  outline: none;
  box-shadow: none;
}

.from-button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--color-ink-muted);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-ink);
  text-align: left;
}

.from-button__change {
  color: var(--color-brand-strong);
  font-weight: var(--text-label-weight);
}

.withdraw-submit {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  text-align: center;
}

/* Withdraw from: one radio per pot --------------------------------------- */

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

.pot-choices legend {
  padding: var(--space-3) var(--space-4) var(--space-1);
  color: var(--color-ink-muted);
  font-weight: var(--text-label-weight);
}

.pot-choice {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: 0 var(--space-4);
  cursor: pointer;
}

.pot-choice:has(input:checked) {
  background: var(--color-brand-soft);
}

.pot-choice input {
  appearance: none;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin: 0;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--color-ink-muted);
  background: var(--color-surface);
}

.pot-choice input:checked {
  border-color: var(--color-brand-strong);
  background: var(--color-brand-strong);
  box-shadow: inset 0 0 0 4px var(--color-surface);
}

.pot-choice input:focus-visible {
  box-shadow: inset 0 0 0 4px var(--color-surface), var(--focus-ring);
}

.pot-choice__name {
  flex-grow: 1;
  min-width: 0;
}

/* Sign in ---------------------------------------------------------------- */

.sign-in {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: calc(var(--space-8) + var(--space-2)) var(--space-4);
}

.sign-in__art {
  display: block;
  width: 100%;
  height: auto;
}

.sign-in__art-ground {
  fill: var(--color-hero);
}

.sign-in__art-track {
  fill: var(--color-ink-muted);
}

.sign-in__art-fill {
  fill: var(--color-brand);
}

.sign-in__spacer {
  flex-grow: 1;
}

.sign-in__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  text-align: center;
}

.google-button__logo {
  width: 20px;
  height: 20px;
}

/* Development only. Each label stays on one line; on a narrow phone the
   buttons take a row each instead. */
.dev-sign-in {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.dev-sign-in .button {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 0 var(--space-4);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  button:active:not(:disabled) {
    transform: none;
  }
}
