@font-face {
  font-family: "Schibsted Grotesk";
  src: url("https://fonts.gstatic.com/s/schibstedgrotesk/v7/Jqz55SSPQuCQF3t8uOwiUL-taUTtap9Gayo.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}

:root {
  --paper: #f1f3f4;
  --surface: #ffffff;
  --ink: #1a1d21;
  --graphite: #5f6670;
  --rule: #e1e4e8;
  --pencil: #f2b33d;
  --pencil-ink: #3a2a05;
  --income: #1c7c54;
  --danger: #b3261e;
  --scrim: rgb(26 29 33 / 0.4);

  --font: "Schibsted Grotesk", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15171a;
    --surface: #1e2125;
    --ink: #eceef0;
    --graphite: #9aa1aa;
    --rule: #2c3035;
    --income: #4cc38a;
    --danger: #ff8a80;
    --scrim: rgb(0 0 0 / 0.55);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.4 var(--font);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(6rem + var(--safe-bottom));
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 1.375rem; height: 1.375rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--pencil); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Header */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: calc(var(--safe-top) + 0.5rem) 0.75rem 0.5rem;
  background: var(--paper);
}

.month { display: flex; align-items: center; gap: 0.125rem; min-width: 0; }

.month h1 {
  margin: 0 0.25rem;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--graphite);
}
.icon-btn:active { background: var(--rule); }
.icon-btn:disabled { opacity: 0.3; }

/* Totals */

.totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 0.25rem 1.25rem 1rem;
}
.totals div { display: flex; flex-direction: column; min-width: 0; }
.totals-label { font-size: 0.875rem; color: var(--graphite); }
.totals-value { font-size: 1.375rem; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.income { color: var(--income); }

.banner {
  margin: 0 1rem 0.75rem;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  font-size: 0.9375rem;
  color: var(--graphite);
}

/* List */

.day { margin-bottom: 0.5rem; }

.day-head {
  position: sticky;
  top: calc(var(--safe-top) + 3.75rem);
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.75rem 1.25rem 0.375rem;
  background: var(--paper);
  font-size: 0.9375rem;
}
.day-head h2 { margin: 0; font-size: inherit; font-weight: 650; }
.day-head span { color: var(--graphite); }

.tx {
  display: grid;
  grid-template-columns: 2.75rem 1fr auto;
  align-items: center;
  gap: 0.875rem;
  width: 100%;
  padding: 0.625rem 1.25rem;
  border: 0;
  background: none;
  text-align: left;
}
.tx:active { background: var(--rule); }

.cat-icon {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c, var(--graphite)) 20%, transparent);
  font-size: 1.3rem;
  font-weight: 650;
  color: var(--c, var(--graphite));
  line-height: 1;
}
.tx.pending .cat-icon { outline: 2px dashed var(--graphite); outline-offset: 2px; }

.tx-main, .tx-side { display: flex; flex-direction: column; min-width: 0; }
.tx-side { align-items: flex-end; }
.tx-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { font-size: 0.875rem; color: var(--graphite); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amount { font-weight: 600; white-space: nowrap; }

.empty {
  padding: 3rem 2rem;
  text-align: center;
  color: var(--graphite);
}
.empty strong { display: block; color: var(--ink); font-size: 1.125rem; margin-bottom: 0.25rem; }

/* Welcome */

.welcome { padding: 2rem 1.25rem; max-width: 28rem; }
.welcome h2 { margin: 0 0 0.5rem; font-size: 1.75rem; line-height: 1.15; letter-spacing: -0.015em; }
.welcome p { margin: 0 0 1.5rem; color: var(--graphite); }

/* Add button: the one loud thing on the main screen. */

.fab {
  position: fixed;
  right: 1.25rem;
  bottom: calc(1.25rem + var(--safe-bottom));
  z-index: 10;
  display: grid;
  place-items: center;
  width: 4rem;
  height: 4rem;
  border: 0;
  border-radius: 1.375rem;
  background: var(--pencil);
  color: var(--pencil-ink);
  box-shadow: 0 6px 18px -6px rgb(120 80 0 / 0.55);
}
.fab svg { width: 1.75rem; height: 1.75rem; stroke-width: 2.5; }
.fab:active { transform: scale(0.95); }

/* Sheets */

.sheet {
  width: 100%;
  max-width: 34rem;
  max-height: 94dvh;
  margin: auto auto 0;
  padding: 0 1.25rem calc(1.5rem + var(--safe-bottom));
  border: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  background: var(--surface);
  color: var(--ink);
  overscroll-behavior: contain;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), overlay 0.28s allow-discrete, display 0.28s allow-discrete;
  transform: translateY(100%);
}
.sheet[open] { transform: translateY(0); }
@starting-style { .sheet[open] { transform: translateY(100%); } }
.sheet::backdrop { background: var(--scrim); }

@media (min-width: 40rem) {
  .sheet { margin: auto; border-radius: 1.5rem; }
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin: 0 -1.25rem 0.5rem;
  padding: 0.75rem 0.5rem;
  background: var(--surface);
}
.sheet-head h2 { margin: 0; font-size: 1.0625rem; font-weight: 650; }
.sheet-head .text-btn:first-child { justify-self: start; }
.sheet-head .text-btn:last-child { justify-self: end; }

.text-btn {
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border: 0;
  border-radius: 0.75rem;
  background: none;
  color: var(--graphite);
}
.text-btn.strong { color: var(--ink); font-weight: 700; }
.text-btn:disabled { opacity: 0.4; }

/* Expense / income switch */

.kind {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0.25rem;
  border-radius: 0.875rem;
  background: var(--paper);
}
.kind label { position: relative; }
.kind input { position: absolute; opacity: 0; inset: 0; }
.kind span {
  display: block;
  padding: 0.5rem;
  border-radius: 0.625rem;
  text-align: center;
  font-weight: 550;
  color: var(--graphite);
}
.kind input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }
.kind input:focus-visible + span { outline: 2px solid var(--pencil); }

/* The amount is the boldest type in the app. */

.amount {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.125rem;
  padding: 1.5rem 0 1.25rem;
  font-size: 3.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}
.amount-sign { color: var(--graphite); font-weight: 500; }
.amount input {
  width: 5ch;
  min-width: 1ch;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  letter-spacing: inherit;
  outline: none;
  field-sizing: content;
}
.amount input::placeholder { color: var(--rule); }
.sheet.is-income .amount input, .sheet.is-income .amount-sign { color: var(--income); }

/* Form fields */

.field { display: flex; flex-direction: column; gap: 0.375rem; margin: 0 0 1rem; padding: 0; border: 0; min-width: 0; }
.field > span, .field legend { padding: 0; font-size: 0.875rem; color: var(--graphite); }
.field legend { margin-bottom: 0.375rem; }

.field input, .field select, .field textarea, .new-cat input {
  width: 100%;
  min-height: 3rem;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--rule);
  border-radius: 0.75rem;
  background: var(--paper);
  font-size: 1rem;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .new-cat input:focus { outline: none; border-color: var(--pencil); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.row .field:only-child { grid-column: span 2; }

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 2.5rem;
  padding: 0 0.875rem 0 0.625rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: none;
  font-size: 0.9375rem;
}
.chip[aria-pressed="true"] {
  border-color: var(--pencil);
  background: color-mix(in srgb, var(--pencil) 22%, transparent);
  font-weight: 600;
}
.chip.add { color: var(--graphite); border-style: dashed; padding: 0 0.875rem; }

.new-cat { display: grid; grid-template-columns: 4rem 1fr auto; gap: 0.5rem; margin-top: 0.625rem; }
.new-cat input:first-child { text-align: center; }

.primary, .small {
  border: 0;
  border-radius: 0.875rem;
  background: var(--ink);
  color: var(--paper);
  font-weight: 650;
}
.primary { width: 100%; min-height: 3.25rem; }
.small { padding: 0 1rem; min-height: 3rem; }
.primary:disabled { opacity: 0.5; }

.danger {
  width: 100%;
  min-height: 3rem;
  margin-top: 0.5rem;
  border: 0;
  border-radius: 0.875rem;
  background: none;
  color: var(--danger);
  font-weight: 600;
}
.danger.confirm { background: var(--danger); color: var(--surface); }

.form-error { margin: 0 0 0.5rem; color: var(--danger); font-size: 0.9375rem; }
.form-error:empty { display: none; }
.hint { margin: -0.5rem 0 1rem; font-size: 0.875rem; color: var(--graphite); }
.token-form .field { margin-bottom: 1rem; }
.token-form .form-error { margin-top: 0.75rem; }

@media (prefers-reduced-motion: reduce) {
  .sheet { transition: none; }
}
