/* ============================================================
   Ledger — design system
   Dark · Nothing ethos · cards + breathing room · minimal motion
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  --bg: #0A0A0A;
  --surface: #141414;
  --surface-2: #1C1C1C;
  --surface-3: #242424;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);

  --text: #F5F5F5;
  --muted: #8A8A8A;
  --muted-2: #5E5E5E;

  --accent: #FF3B3B;
  --accent-press: #E22E2E;
  --accent-weak: rgba(255, 59, 59, 0.14);

  --pos: #34D399;   /* income / gains  */
  --neg: #FF6B6B;   /* expense / loss  */

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --r-pill: 999px;

  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 28px; --s7: 40px; --s8: 56px;

  --font-ui: "Space Grotesk", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-display: "Doto", "Space Grotesk", ui-monospace, monospace;

  --app-w: 560px;
  --nav-h: 66px;

  --t-fast: 140ms cubic-bezier(.4, 0, .2, 1);
  --t: 220ms cubic-bezier(.4, 0, .2, 1);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea, button { font-family: inherit; }
a { color: inherit; }
::selection { background: var(--accent); color: #fff; }

/* Scrollbar (subtle) */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 99px; }

/* ---------- App shell ---------- */
#app {
  width: 100%;
  max-width: var(--app-w);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  padding: max(var(--s5), env(safe-area-inset-top)) var(--s5) var(--s4);
  background: linear-gradient(var(--bg) 72%, rgba(10, 10, 10, 0));
}
.appbar__title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.appbar__sub { color: var(--muted); font-size: 13px; letter-spacing: .02em; }
.appbar__big { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.05; }
.appbar__avatar { flex: none; }

.view {
  flex: 1;
  padding: var(--s2) var(--s5) calc(var(--nav-h) + var(--s8));
  display: flex;
  flex-direction: column;
  gap: var(--s5);
}
.view--enter { animation: viewIn var(--t) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Bottom navigation ---------- */
.nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-w);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  background: rgba(16, 16, 16, 0.86);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}
.nav__item {
  background: none; border: 0;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 0;
  color: var(--muted-2);
  transition: color var(--t-fast);
}
.nav__item svg { width: 22px; height: 22px; }
.nav__label { font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; }
.nav__item.is-active { color: var(--text); }
.nav__item.is-active svg { color: var(--accent); }
.nav__item:active { transform: scale(.94); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s5);
}
.card--tight { padding: var(--s4); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.card__label { color: var(--muted); font-size: 12.5px; letter-spacing: .02em; }
.card__title { font-size: 16px; font-weight: 600; }

/* Hero balance card */
.hero {
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(255, 59, 59, 0.10), transparent 60%),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s6) var(--s5);
  position: relative;
  overflow: hidden;
}
.hero__label { color: var(--muted); font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.hero__amount {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(40px, 13vw, 64px);
  line-height: 1.04;
  letter-spacing: .01em;
  margin-top: var(--s3);
  font-variant-numeric: tabular-nums;
}
.hero__meta { display: flex; gap: var(--s5); margin-top: var(--s4); flex-wrap: wrap; }
.hero__metaItem { display: flex; flex-direction: column; gap: 2px; }
.hero__metaLabel { color: var(--muted); font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; }
.hero__metaVal { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Grid + stats ---------- */
.grid { display: grid; gap: var(--s4); grid-template-columns: repeat(2, 1fr); }
.grid--1 { grid-template-columns: 1fr; }
.stat__label { color: var(--muted); font-size: 12.5px; }
.stat__value { font-size: 24px; font-weight: 700; margin-top: var(--s2); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- Progress bar ---------- */
.bar { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.bar__fill { height: 100%; border-radius: inherit; background: var(--accent); width: 0; transition: width var(--t); }
.bar__fill.is-over { background: var(--neg); }
.bar__fill.is-pos { background: var(--pos); }

/* ---------- Badges / deltas ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  padding: 3px 8px; border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--text);
}
.badge--up { color: var(--pos); background: rgba(52, 211, 153, 0.12); }
.badge--down { color: var(--neg); background: rgba(255, 107, 107, 0.12); }

/* ---------- Filter pills ---------- */
.pills { display: flex; gap: var(--s2); flex-wrap: wrap; }
.pill {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: var(--r-pill);
  font-size: 13px; font-weight: 500;
  transition: all var(--t-fast);
}
.pill.is-active { background: var(--text); color: #0A0A0A; border-color: var(--text); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list__item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--line);
}
.list__item:last-child { border-bottom: 0; }
.list__icon {
  flex: none; width: 40px; height: 40px; border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted);
}
.list__icon svg { width: 18px; height: 18px; }
.list__main { flex: 1; min-width: 0; }
.list__title { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list__sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.list__amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list__amount.is-income { color: var(--pos); }
.list__amount.is-expense { color: var(--text); }
.list__del { background: none; border: 0; color: var(--muted-2); padding: 6px; border-radius: 8px; }
.list__del:hover { color: var(--neg); }

.list__group { color: var(--muted); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; margin: var(--s4) 0 var(--s1); }

/* ---------- Mini bar chart ---------- */
.chart { display: flex; align-items: flex-end; gap: var(--s2); height: 120px; }
.chart__col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: var(--s2); height: 100%; }
.chart__track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.chart__bar { width: 100%; max-width: 26px; margin: 0 auto; border-radius: 6px 6px 4px 4px; background: var(--surface-3); transition: height var(--t); min-height: 4px; }
.chart__bar.is-peak { background: var(--accent); }
.chart__label { color: var(--muted); font-size: 11px; letter-spacing: .02em; }

/* ---------- Section heading ---------- */
.section { display: flex; align-items: center; justify-content: space-between; }
.section__title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.section__link { color: var(--muted); font-size: 13px; background: none; border: 0; }
.muted { color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-size: 15px; font-weight: 600;
  transition: transform var(--t-fast), background var(--t-fast), opacity var(--t-fast);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn--accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--accent:active { background: var(--accent-press); }
.btn--ghost { background: transparent; }
.btn--danger { background: transparent; border-color: rgba(255, 107, 107, 0.4); color: var(--neg); }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.btn--accent.is-loading::after { border-color: rgba(255, 255, 255, 0.45); border-top-color: #fff; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Floating action button */
.fab {
  position: fixed;
  left: 50%;
  transform: translateX(calc(var(--app-w) / 2 - 100%));
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 45;
  width: 56px; height: 56px; border-radius: 18px;
  background: var(--accent); color: #fff; border: 0;
  display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(255, 59, 59, 0.35);
  transition: transform var(--t-fast);
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: translateX(calc(var(--app-w) / 2 - 100%)) scale(.92); }
@media (max-width: 592px) {
  .fab { left: auto; right: 20px; transform: none; }
  .fab:active { transform: scale(.92); }
}

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--s2); }
.label { color: var(--muted); font-size: 12.5px; letter-spacing: .03em; }
.input, .select, .textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 13px 14px;
  font-size: 15px;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); background: var(--surface-3); }
.textarea { resize: vertical; min-height: 76px; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238A8A8A' stroke-width='2'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  padding-right: 38px;
}
.input--amount { font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: .02em; }
.form-grid { display: grid; gap: var(--s4); grid-template-columns: 1fr 1fr; }
.form-grid .field--full { grid-column: 1 / -1; }

/* Segmented control (income / expense, frequency...) */
.seg { display: grid; grid-auto-flow: column; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.seg__opt { border: 0; background: none; color: var(--muted); padding: 9px 10px; border-radius: 10px; font-size: 14px; font-weight: 600; transition: all var(--t-fast); }
.seg__opt.is-active { background: var(--text); color: #0A0A0A; }
.seg__opt.is-active[data-tone="income"] { background: var(--pos); color: #07261a; }
.seg__opt.is-active[data-tone="expense"] { background: var(--accent); color: #fff; }

/* ---------- Modal / bottom sheet ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); animation: fade var(--t) both; }
.modal__card {
  position: relative;
  width: 100%; max-width: var(--app-w);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  padding: var(--s5) var(--s5) calc(var(--s5) + env(safe-area-inset-bottom));
  max-height: 90dvh; overflow-y: auto;
  animation: sheetUp var(--t) both;
}
@media (min-width: 593px) {
  .modal { align-items: center; }
  .modal__card { border-radius: 22px; animation: popIn var(--t) both; }
}
.modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s4); }
.modal__title { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.modal__close { background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; }
.modal__body { display: flex; flex-direction: column; gap: var(--s4); }
.modal__foot { margin-top: var(--s5); display: flex; gap: var(--s3); }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes popIn { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 24px); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: var(--s2); pointer-events: none; padding: 0 var(--s4); }
.toast {
  pointer-events: auto;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 11px 16px; border-radius: var(--r-pill);
  font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toastIn var(--t) both;
  max-width: 100%;
}
.toast--error { border-color: rgba(255, 107, 107, 0.5); }
.toast--success { border-color: rgba(52, 211, 153, 0.5); }
.toast.is-out { animation: toastOut var(--t-fast) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Loading overlay (full-view) ---------- */
.overlay { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; background: rgba(10, 10, 10, 0.6); backdrop-filter: blur(2px); animation: fade var(--t-fast) both; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .7s linear infinite; }

/* ---------- Skeletons (shimmer) ---------- */
.skel { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--r-sm); }
.skel::after {
  content: ""; position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  animation: shimmer 1.25s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skel--line { height: 12px; }
.skel--text { height: 16px; }
.skel--lg { height: 28px; }
.skel--hero { height: 150px; border-radius: var(--r-lg); }
.skel--card { height: 92px; border-radius: var(--r-lg); }
.skel--row { height: 56px; border-radius: var(--r-md); }
.skel-stack { display: flex; flex-direction: column; gap: var(--s4); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: var(--s7) var(--s4); display: flex; flex-direction: column; align-items: center; gap: var(--s2); }
.empty__icon { width: 56px; height: 56px; border-radius: 18px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); margin-bottom: var(--s2); }
.empty__icon svg { width: 26px; height: 26px; }
.empty__title { font-size: 17px; font-weight: 600; }
.empty__text { color: var(--muted); font-size: 14px; max-width: 30ch; }

/* ---------- Avatar ---------- */
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface-3); color: var(--text);
  display: grid; place-items: center;
  font-weight: 700; font-size: 16px; letter-spacing: .02em;
  border: 1px solid var(--line-strong);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--lg { width: 88px; height: 88px; font-size: 30px; border-radius: 28px; }

/* ---------- Auth + setup screens ---------- */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: var(--s6); padding: var(--s6) var(--s5) var(--s7); max-width: 440px; margin: 0 auto; }
.auth__brand { font-family: var(--font-display); font-weight: 900; font-size: 40px; letter-spacing: .04em; text-transform: uppercase; }
.auth__brand b { color: var(--accent); }
.auth__lead { color: var(--muted); margin-top: var(--s2); }
.auth__title { font-size: 22px; font-weight: 700; margin-bottom: var(--s2); }
.auth__form { display: flex; flex-direction: column; gap: var(--s4); }
.auth__switch { text-align: center; color: var(--muted); font-size: 14px; }
.auth__switch button { background: none; border: 0; color: var(--accent); font-weight: 600; }
.auth__error { color: var(--neg); font-size: 13.5px; min-height: 18px; }

.code { font-family: ui-monospace, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px 7px; font-size: 13px; color: var(--accent); }
.setup { max-width: 480px; margin: 0 auto; padding: var(--s7) var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.setup ol { padding-left: 1.1em; margin: 0; display: flex; flex-direction: column; gap: var(--s2); color: var(--muted); }
.setup ol b { color: var(--text); }

/* ---------- flatpickr — dark Nothing theme ---------- */
.flatpickr-calendar {
  background: var(--surface) !important;
  border: 1px solid var(--line-strong) !important;
  border-radius: var(--r-md) !important;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6) !important;
  color: var(--text) !important;
}
.flatpickr-calendar.arrowTop::before, .flatpickr-calendar.arrowTop::after,
.flatpickr-calendar.arrowBottom::before, .flatpickr-calendar.arrowBottom::after { display: none !important; }
.flatpickr-months, .flatpickr-month { background: transparent !important; color: var(--text) !important; fill: var(--text) !important; }
.flatpickr-current-month input.cur-year, .flatpickr-current-month .cur-month, .flatpickr-monthDropdown-months { color: var(--text) !important; font-weight: 600 !important; }
.flatpickr-monthDropdown-months { background: var(--surface) !important; }
.flatpickr-weekday { color: var(--muted) !important; font-weight: 600 !important; }
.flatpickr-prev-month svg, .flatpickr-next-month svg { fill: var(--muted) !important; }
.flatpickr-prev-month:hover svg, .flatpickr-next-month:hover svg { fill: var(--accent) !important; }
.flatpickr-day { color: var(--text) !important; border-radius: 10px !important; border: 0 !important; }
.flatpickr-day:hover { background: var(--surface-3) !important; }
.flatpickr-day.flatpickr-disabled, .flatpickr-day.prevMonthDay, .flatpickr-day.nextMonthDay { color: var(--muted-2) !important; }
.flatpickr-day.today { border: 1px solid var(--line-strong) !important; }
.flatpickr-day.selected, .flatpickr-day.selected:hover { background: var(--accent) !important; color: #fff !important; }
.flatpickr-time input, .flatpickr-time .flatpickr-am-pm { color: var(--text) !important; }
.flatpickr-time input:hover, .flatpickr-time .flatpickr-am-pm:hover { background: var(--surface-3) !important; }
span.flatpickr-weekday { background: transparent !important; }
.flatpickr-innerContainer, .flatpickr-rContainer, .flatpickr-days, .dayContainer { background: transparent !important; }

/* ---------- Utilities ---------- */
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.row { display: flex; align-items: center; gap: var(--s3); }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.hidden, [hidden] { display: none !important; }
.text-pos { color: var(--pos); }
.text-neg { color: var(--neg); }
.nowrap { white-space: nowrap; }

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