/* Tokens ------------------------------------------------------------ */
:root {
  color-scheme: light;
  --bg: #F4F4F2;
  --surface: #FFFFFF;
  --raised: #EDEDEA;
  --border: #E4E4E0;
  --text: #0B0B0B;
  --text-2: #52514E;
  --income: #2A78D6;
  --expense: #EB6834;
  --critical: #D03B3B;
  --bar: rgba(255, 255, 255, 0.8);

  --s-25: 2px; --s-50: 4px; --s-75: 8px; --s-100: 12px; --s-200: 16px;
  --s-300: 24px; --s-400: 32px; --s-500: 40px; --s-600: 48px; --s-700: 64px;
  --s-800: 80px; --s-900: 96px;

  --curve: cubic-bezier(0.22, 1, 0.36, 1);
  --font: "Manrope", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #181818;
    --surface: #1F1F1F;
    --raised: #272727;
    --border: #313131;
    --text: #F0EFEC;
    --text-2: #B4B3AB;
    --income: #3987E5;
    --expense: #D95926;
    --critical: #E66767;
    --bar: rgba(31, 31, 31, 0.8);
  }
}

/* Text styles ------------------------------------------------------- */
.heading-3 { font-size: 36px; line-height: 40px; font-weight: 600; }
.heading-5 { font-size: 24px; line-height: 32px; font-weight: 600; }
.heading-6 { font-size: 20px; line-height: 28px; font-weight: 600; }
.title-3 { font-size: 16px; line-height: 24px; font-weight: 500; }
.title-4 { font-size: 14px; line-height: 20px; font-weight: 500; }
.body-1 { font-size: 16px; line-height: 24px; font-weight: 600; }
.body-3 { font-size: 16px; line-height: 24px; font-weight: 400; }
.body-4 { font-size: 14px; line-height: 20px; font-weight: 600; }
.body-5 { font-size: 14px; line-height: 20px; font-weight: 500; }
.body-6 { font-size: 14px; line-height: 20px; font-weight: 400; }
.button-md { font-size: 16px; line-height: 24px; font-weight: 600; }
.button-sm { font-size: 14px; line-height: 20px; font-weight: 600; }
.caption-2 { font-size: 14px; line-height: 20px; font-weight: 400; }
.caption-4 { font-size: 12px; line-height: 16px; font-weight: 500; }
.caption-5 { font-size: 12px; line-height: 16px; font-weight: 400; }
.muted { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }

/* Base -------------------------------------------------------------- */
* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-style: normal;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 24px;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) var(--s-200) calc(var(--s-900) + var(--s-300) + env(safe-area-inset-bottom));
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--income); outline-offset: 2px; }
main:focus { outline: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 16; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.skip { position: absolute; left: var(--s-200); top: -80px; background: var(--text); color: var(--bg); padding: var(--s-75) var(--s-100); border-radius: 8px; z-index: 50; }
.skip:focus { top: var(--s-200); }

button, .chip, .seg button { transition: opacity 300ms var(--curve), transform 300ms var(--curve), background-color 300ms var(--curve), color 300ms var(--curve); }
button:active { transform: scale(0.98); }

/* Header ------------------------------------------------------------ */
.top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-100); padding: var(--s-300) 0 var(--s-200); }
.month { display: flex; align-items: center; gap: var(--s-50); }
.month span { min-width: 80px; text-align: center; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 9999px; color: var(--text-2); }
.icon-btn svg { width: 16px; height: 16px; stroke-width: 24; }
@media (hover: hover) { .icon-btn:hover { background: var(--raised); color: var(--text); } }

/* Layout ------------------------------------------------------------ */
main { display: flex; flex-direction: column; gap: var(--s-200); animation: enter 500ms var(--curve); }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: var(--s-200); display: flex; flex-direction: column; gap: var(--s-200); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-100); }
.stack { display: flex; flex-direction: column; gap: var(--s-50); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-100); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: var(--s-200); display: flex; flex-direction: column; gap: var(--s-50); min-width: 0; }
.tile .body-1, .tile .heading-6 { overflow-wrap: anywhere; }
.key { display: inline-flex; align-items: center; gap: var(--s-75); }
.dot { width: 8px; height: 8px; border-radius: 9999px; flex: none; }
.dot.income { background: var(--income); }
.dot.expense { background: var(--expense); }

/* Buttons and controls ---------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-75); padding: var(--s-75) var(--s-100); border-radius: 8px; background: var(--text); color: var(--bg); }
.btn.wide { width: 100%; min-height: 48px; border-radius: 12px; }
.btn.quiet { background: var(--raised); color: var(--text); }
.btn.danger { background: none; color: var(--critical); }
.link { color: var(--text-2); padding: var(--s-75) 0; }
@media (hover: hover) { .btn:hover { opacity: 0.85; } .link:hover { color: var(--text); } }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--raised); border-radius: 12px; padding: var(--s-50); }
.seg button { padding: var(--s-75) var(--s-100); border-radius: 8px; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); }

.field { display: flex; flex-direction: column; gap: var(--s-75); }
.input { width: 100%; min-height: 48px; padding: var(--s-75) var(--s-100); border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 16px; line-height: 24px; -webkit-appearance: none; appearance: none; }
.input.amount { font-size: 30px; line-height: 36px; font-weight: 600; min-height: 64px; font-variant-numeric: tabular-nums; }
.input:focus-visible { outline-offset: 0; }
.error { color: var(--critical); }

.chips { display: flex; flex-wrap: wrap; gap: var(--s-75); }
.chip { padding: var(--s-75) var(--s-100); border-radius: 9999px; border: 1px solid var(--border); background: var(--surface); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

/* Transactions ------------------------------------------------------ */
.rows { display: flex; flex-direction: column; gap: var(--s-50); }
.row { display: flex; align-items: center; gap: var(--s-100); width: 100%; text-align: left; padding: var(--s-75) 0; border-radius: 8px; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--raised); position: relative; flex: none; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border: 2px solid var(--surface); }
@media (hover: hover) { .row:hover { opacity: 0.7; } }

.empty { align-items: center; text-align: center; padding: var(--s-400) var(--s-200); }
.empty p { max-width: 280px; }

/* Charts ------------------------------------------------------------ */
.bd { display: flex; flex-direction: column; gap: var(--s-75); }
.bd-line { display: flex; justify-content: space-between; gap: var(--s-100); }
.bd-line span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd-bar { height: 8px; border-radius: 4px; min-width: 4px; }
.bd-bar.income { background: var(--income); }
.bd-bar.expense { background: var(--expense); }

.chart { position: relative; height: 192px; }
.grid { position: absolute; left: 0; right: 0; height: 1px; background: var(--border); }
.grid span { position: absolute; left: 0; bottom: 2px; color: var(--text-2); }
.cols { position: absolute; inset: 0 0 0 var(--s-500); display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.col { display: flex; flex-direction: column; align-items: center; height: 100%; border-radius: 8px; color: var(--text-2); }
.col[aria-pressed="true"] { background: var(--raised); color: var(--text); }
.col:active { transform: none; }
.bars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: var(--s-25); width: 100%; }
.bar { width: 12px; border-radius: 4px 4px 0 0; }
.bar.income { background: var(--income); }
.bar.expense { background: var(--expense); }
.col .caption-4 { height: 32px; display: grid; place-items: center; }
.readout { display: flex; flex-direction: column; gap: var(--s-75); }
.chart { margin-top: var(--s-75); }

/* Settings ---------------------------------------------------------- */
.cat { display: flex; align-items: center; gap: var(--s-75); }
.cat .input { flex: 1; min-width: 0; }
.cat .icon-btn { width: 48px; height: 48px; }
.cat .icon-btn svg { width: 20px; height: 20px; stroke-width: 16; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s-75); }

/* Tab bar ----------------------------------------------------------- */
.tabs { position: fixed; left: 50%; bottom: calc(var(--s-100) + env(safe-area-inset-bottom)); transform: translateX(-50%); width: calc(100% - var(--s-400)); max-width: 448px; display: grid; grid-template-columns: 1fr 1fr auto 1fr 1fr; align-items: center; gap: var(--s-50); padding: var(--s-75); border-radius: 24px; border: 1px solid var(--border); background: var(--bar); -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px); z-index: 10; }
.tab { display: flex; flex-direction: column; align-items: center; gap: var(--s-25); padding: var(--s-75) 0; border-radius: 16px; color: var(--text-2); min-width: 0; }
.tab[aria-current="page"] { color: var(--text); background: var(--raised); }
.add { width: 48px; height: 48px; margin: 0 var(--s-50); border-radius: 16px; background: var(--text); color: var(--bg); display: grid; place-items: center; }
@media (hover: hover) { .tab:hover { color: var(--text); } .add:hover { opacity: 0.85; } }

/* Sheet ------------------------------------------------------------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); opacity: 0; transition: opacity 300ms var(--curve); z-index: 20; }
.backdrop.open { opacity: 1; }
.sheet { position: fixed; left: 50%; bottom: 0; width: 100%; max-width: 480px; max-height: 92dvh; overflow-y: auto; transform: translate(-50%, 100%); transition: transform 500ms var(--curve); background: var(--bg); border-radius: 24px 24px 0 0; padding: var(--s-200) var(--s-200) calc(var(--s-300) + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: var(--s-200); z-index: 30; }
.sheet.open { transform: translate(-50%, 0); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }

/* Toast ------------------------------------------------------------- */
.toast { position: fixed; left: 50%; top: calc(var(--s-200) + env(safe-area-inset-top)); transform: translate(-50%, -8px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); padding: var(--s-75) var(--s-200); border-radius: 9999px; transition: opacity 300ms var(--curve), transform 500ms var(--curve); z-index: 40; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  main { animation-name: fade; }
  @keyframes fade { from { opacity: 0; } }
  .sheet, .toast, button { transition-property: opacity; }
  .sheet { transform: translate(-50%, 0); opacity: 0; }
  .sheet.open { opacity: 1; }
  button:active { transform: none; }
}
