:root {
  color-scheme: dark;
  --bg: #080b14;
  --surface: #101522;
  --surface-2: #161d2d;
  --surface-3: #1d2639;
  --text: #f6f7fb;
  --muted: #9aa4b7;
  --faint: #687286;
  --line: rgba(255,255,255,.08);
  --accent: #8b7bff;
  --accent-2: #55d6be;
  --danger: #ff6b7a;
  --warning: #ffcc66;
  --shadow: 0 24px 70px rgba(0,0,0,.38);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; }
button { color: inherit; }
button, select { cursor: pointer; }
.hidden { display: none !important; }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 90% -5%, rgba(139,123,255,.17), transparent 35%),
    radial-gradient(circle at 0% 35%, rgba(85,214,190,.08), transparent 30%);
  z-index: 0;
}

.privacy-cover {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  background: #080b14;
}
.privacy-cover.visible { display: grid; }
.privacy-mark, .brand-mark {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 22px;
  background: linear-gradient(145deg, #9c90ff, #5b4fd7);
  box-shadow: 0 16px 40px rgba(111,92,255,.32);
  font-weight: 800;
  letter-spacing: -.04em;
}

.auth-view {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  align-items: center;
  padding: calc(28px + var(--safe-top)) 22px calc(28px + var(--safe-bottom));
}
.auth-card {
  width: min(100%, 430px);
  margin: auto;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: rgba(16,21,34,.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}
.auth-card.compact { padding-top: 34px; }
.auth-card .brand-mark { margin-bottom: 28px; }
.auth-card h1 { margin: 5px 0 10px; font-size: clamp(30px, 8vw, 42px); line-height: 1.02; letter-spacing: -.045em; }
.muted { color: var(--muted); line-height: 1.55; margin: 0 0 26px; }
.eyebrow { margin: 0; color: var(--faint); font-size: 11px; font-weight: 800; letter-spacing: .15em; }
.fine-print, .helper-text { color: var(--faint); font-size: 12px; line-height: 1.5; }
.fine-print { margin: 22px 0 0; text-align: center; }

.field-label, form label > span, .field-row > span {
  display: block;
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.text-input, .search-input, .select-input {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  padding: 0 15px;
  transition: border-color .18s, box-shadow .18s;
}
.text-input:focus, .search-input:focus, .select-input:focus {
  border-color: rgba(139,123,255,.78);
  box-shadow: 0 0 0 4px rgba(139,123,255,.12);
}
.form-error { min-height: 18px; margin: 10px 0 0; color: var(--danger); font-size: 13px; }

.primary-button, .faceid-button, .danger-button {
  min-height: 50px;
  border: 0;
  border-radius: 16px;
  padding: 0 20px;
  font-weight: 800;
}
.primary-button { background: linear-gradient(135deg, #9b90ff, #6f5cff); color: white; box-shadow: 0 12px 28px rgba(111,92,255,.25); }
.primary-button:active, .faceid-button:active, .quick-action:active { transform: scale(.985); }
.primary-button.full, .danger-button.full { width: 100%; }
.primary-button.small { min-height: 46px; padding: 0 16px; }
.faceid-button { width: 100%; display: flex; gap: 10px; align-items: center; justify-content: center; background: white; color: #111522; }
.face-glyph { font-size: 25px; }
.danger-button { background: rgba(255,107,122,.12); color: #ff8a96; }
.divider { display: flex; align-items: center; gap: 14px; margin: 22px 0 2px; color: var(--faint); font-size: 12px; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 760px);
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(112px + var(--safe-bottom));
}
.top-bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 4px 20px; }
.top-bar h1 { margin: 3px 0 0; font-size: 30px; letter-spacing: -.04em; }
.icon-button {
  width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 15px;
  background: rgba(16,21,34,.75); color: var(--muted); font-size: 21px;
}
.screen { display: none; animation: fadeIn .2s ease; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.balance-card {
  padding: 24px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(145deg, rgba(139,123,255,.18), transparent 55%),
    linear-gradient(180deg, #171d2d, #101522);
  box-shadow: var(--shadow);
}
.balance-header, .section-heading, .field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.balance-header { color: var(--muted); font-size: 13px; font-weight: 700; }
.period-pill, .metric-chip {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 11px; border-radius: 999px;
  background: rgba(255,255,255,.07); color: #c8cde0; font-size: 11px; font-weight: 800;
}
.balance-amount { margin: 13px 0 25px; font-size: clamp(46px, 13vw, 72px); font-weight: 760; letter-spacing: -.065em; }
.balance-amount.negative { color: #ff8b96; }
.balance-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.balance-metrics > div { padding: 14px; border-radius: 16px; background: rgba(255,255,255,.045); }
.balance-metrics span, .safe-row span { display: block; color: var(--faint); font-size: 12px; margin-bottom: 5px; }
.balance-metrics strong { font-size: 16px; }
.payday-countdown {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%;
  margin-top: 10px; padding: 14px 15px; border: 1px solid rgba(103,225,201,.20); border-radius: 17px;
  background: rgba(85,214,190,.075); color: var(--text); text-align: left;
}
.payday-countdown.needs-setup { border-color: var(--line); background: rgba(255,255,255,.035); }
.payday-countdown.today { border-color: rgba(103,225,201,.42); background: rgba(85,214,190,.13); }
.payday-copy { min-width: 0; }
.payday-copy small { display: block; color: var(--faint); font-size: 10px; font-weight: 850; letter-spacing: .12em; }
.payday-copy strong { display: block; margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.payday-days { display: flex; flex: 0 0 auto; align-items: baseline; gap: 5px; color: #67e1c9; }
.payday-countdown.needs-setup .payday-days { color: var(--faint); }
.payday-days strong { font-size: 29px; line-height: 1; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.payday-days small { font-size: 11px; font-weight: 800; }
.safe-row { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.safe-row strong { font-size: 15px; }
.text-button { border: 0; background: transparent; color: #a89eff; padding: 5px; font-size: 13px; font-weight: 800; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.quick-action {
  display: flex; align-items: center; gap: 12px; text-align: left; min-height: 78px; padding: 15px;
  border: 1px solid var(--line); border-radius: 20px; background: var(--surface); transition: transform .12s;
}
.quick-action small, .stat-card small, .settings-row small { display: block; margin-top: 4px; color: var(--faint); font-size: 11px; }
.quick-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 13px; font-size: 24px; font-weight: 300; }
.quick-action.expense .quick-icon { background: rgba(255,107,122,.12); color: #ff8b96; }
.quick-action.income .quick-icon { background: rgba(85,214,190,.12); color: #67e1c9; }

.section-card { margin-top: 14px; padding: 19px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: rgba(16,21,34,.86); }
.section-heading { margin-bottom: 16px; }
.section-heading h2 { margin: 3px 0 0; font-size: 18px; letter-spacing: -.02em; }
.empty-state { display: grid; place-items: center; min-height: 110px; color: var(--faint); text-align: center; font-size: 13px; }

.transaction-list { display: grid; gap: 2px; }
.transaction-item {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px;
  width: 100%; padding: 12px 0; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left;
}
.transaction-item:last-child { border-bottom: 0; }
.transaction-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; background: var(--surface-2); font-size: 19px; }
.transaction-main strong { display: block; font-size: 14px; }
.transaction-main small { color: var(--faint); font-size: 11px; }
.transaction-amount { font-weight: 800; font-variant-numeric: tabular-nums; }
.transaction-amount.expense { color: #f5f6fa; }
.transaction-amount.income { color: #67e1c9; }

.filter-bar { display: grid; grid-template-columns: minmax(0,1fr) 125px; gap: 10px; margin-bottom: 14px; }
.transaction-card { margin-top: 0; }
.search-input { padding-left: 16px; }

.insight-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card { min-height: 118px; padding: 17px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.stat-card > span { color: var(--muted); font-size: 12px; font-weight: 700; }
.stat-card strong { display: block; margin-top: 12px; font-size: 23px; letter-spacing: -.035em; }
.category-chart { min-height: 190px; }
.category-layout { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 18px; }
.donut { position: relative; width: 145px; aspect-ratio: 1; border-radius: 50%; }
.donut::after { content: ""; position: absolute; inset: 27px; border-radius: 50%; background: var(--surface); }
.donut-center { position: absolute; inset: 0; z-index: 1; display: grid; place-content: center; text-align: center; }
.donut-center strong { font-size: 19px; }
.donut-center small { color: var(--faint); font-size: 10px; }
.legend { display: grid; gap: 10px; }
.legend-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; font-size: 12px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.legend-row span:nth-child(2) { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-chart { display: flex; align-items: end; gap: 7px; min-height: 160px; padding-top: 12px; overflow-x: auto; }
.bar-column { min-width: 28px; flex: 1; display: grid; grid-template-rows: 1fr auto; align-items: end; height: 140px; }
.bar { width: 100%; min-height: 3px; border-radius: 7px 7px 3px 3px; background: linear-gradient(180deg, #9b90ff, #6758e8); }
.bar-label { margin-top: 8px; color: var(--faint); font-size: 9px; text-align: center; }
.insight-copy { color: var(--muted); line-height: 1.55; font-size: 14px; }
.mini-chart svg { display: block; width: 100%; height: 130px; overflow: visible; }
.chart-grid { stroke: rgba(255,255,255,.08); stroke-width: 1; }
.chart-line { fill: none; stroke: #8b7bff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: url(#areaGradient); opacity: .45; }
.chart-dot { fill: #b7afff; }

.settings-group { margin-bottom: 18px; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.settings-title { margin: 0; padding: 13px 16px 8px; color: var(--faint); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.settings-row {
  display: flex; width: 100%; min-height: 64px; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 16px; border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left;
}
.settings-row strong { font-size: 14px; }
.settings-row > span:last-child { color: var(--faint); font-size: 23px; }
.select-row { cursor: default; }
.inline-select { max-width: 125px; border: 0; background: transparent; color: #b5abff; text-align: right; outline: none; font-size: 13px; }
.danger-zone .danger strong { color: #ff8793; }
.version-label { color: var(--faint); text-align: center; font-size: 11px; }

.bottom-nav {
  position: fixed; z-index: 50; left: 50%; bottom: max(8px, var(--safe-bottom)); transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; width: min(calc(100% - 20px), 730px); min-height: 72px;
  padding: 7px 12px; border: 1px solid rgba(255,255,255,.11); border-radius: 24px; background: rgba(18,23,36,.91);
  box-shadow: 0 22px 50px rgba(0,0,0,.45); backdrop-filter: blur(25px);
}
.nav-item { display: grid; gap: 2px; place-items: center; border: 0; background: transparent; color: var(--faint); }
.nav-item span { font-size: 21px; line-height: 1; }
.nav-item small { font-size: 9px; font-weight: 700; }
.nav-item.active { color: #b8b0ff; }
.nav-add { width: 50px; height: 50px; margin: auto; border: 0; border-radius: 18px; background: linear-gradient(145deg,#9d91ff,#6757e8); color: white; font-size: 30px; box-shadow: 0 10px 26px rgba(111,92,255,.38); }

.sheet-backdrop { position: fixed; z-index: 90; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(5px); }
.sheet {
  position: fixed; z-index: 100; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(100%, 760px); max-height: min(90svh, 850px); overflow-y: auto;
  padding: 10px 20px calc(24px + var(--safe-bottom)); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 30px 30px 0 0; background: #101522; box-shadow: 0 -24px 70px rgba(0,0,0,.45);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translate(-50%, 20px); opacity: .3; } to { transform: translate(-50%, 0); opacity: 1; } }
.sheet-handle { width: 38px; height: 5px; margin: 0 auto 8px; border-radius: 99px; background: rgba(255,255,255,.16); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 7px 0 12px; }
.sheet-header h2 { margin: 0; font-size: 20px; }
.sheet-close { border: 0; background: transparent; color: #a89eff; font-weight: 800; }
.amount-entry { display: flex; align-items: center; justify-content: center; margin: 4px 0 16px; }
.amount-entry span { color: var(--muted); font-size: 28px; }
.amount-entry input { width: min(75%, 390px); border: 0; background: transparent; color: var(--text); outline: 0; font-size: clamp(46px, 13vw, 68px); font-weight: 730; letter-spacing: -.055em; text-align: center; }
.amount-entry input::placeholder { color: #30394b; }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 14px; background: var(--bg); }
.segmented-control button { min-height: 40px; border: 0; border-radius: 11px; background: transparent; color: var(--faint); font-weight: 800; }
.segmented-control button.active { background: var(--surface-3); color: var(--text); }
.form-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.category-picker { display: flex; gap: 9px; overflow-x: auto; padding: 3px 1px 7px; scrollbar-width: none; }
.category-picker::-webkit-scrollbar { display: none; }
.category-option { flex: 0 0 auto; min-width: 72px; padding: 10px 9px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-2); color: var(--muted); }
.category-option span { display: block; margin-bottom: 5px; font-size: 20px; }
.category-option small { display: block; max-width: 82px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.category-option.active { border-color: #8b7bff; background: rgba(139,123,255,.13); color: white; box-shadow: 0 0 0 3px rgba(139,123,255,.08); }
.full-select { width: 100%; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.sheet-actions .primary-button { flex: 1; }
.inline-form { display: grid; grid-template-columns: 52px 1fr auto; gap: 8px; align-items: end; margin-bottom: 14px; }
.emoji-input { width: 52px; height: 50px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-2); color: white; text-align: center; font-size: 21px; }
.category-manager-list { display: grid; }
.category-manager-row { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; min-height: 58px; border-bottom: 1px solid var(--line); }
.category-manager-row:last-child { border-bottom: 0; }
.category-manager-row .emoji { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 13px; background: var(--surface-2); }
.category-manager-row small { color: var(--faint); }
.category-manager-row button { border: 0; background: transparent; color: #ff8793; }
.confirmation-sheet { max-height: 340px; }
.confirm-message { color: var(--muted); line-height: 1.6; }
.toast { position: fixed; z-index: 200; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translateX(-50%); max-width: calc(100% - 40px); padding: 12px 16px; border-radius: 14px; background: #f5f6fa; color: #111522; font-size: 13px; font-weight: 800; box-shadow: var(--shadow); }

@media (max-width: 430px) {
  .app-shell { padding-inline: 12px; }
  .balance-card { padding: 20px; }
  .quick-actions { grid-template-columns: 1fr; }
  .quick-action { min-height: 68px; }
  .category-layout { grid-template-columns: 120px 1fr; gap: 12px; }
  .donut { width: 120px; }
  .donut::after { inset: 23px; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .sheet { padding-inline: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

.backup-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 14px 0;
  padding: 14px 15px;
  border: 1px solid rgba(255,204,102,.30);
  border-radius: 18px;
  background: rgba(255,204,102,.09);
}
.backup-banner strong { display: block; font-size: 14px; }
.backup-banner small { display: block; margin-top: 4px; color: #c6b98e; font-size: 11px; line-height: 1.4; }
.backup-banner button {
  flex: 0 0 auto;
  min-height: 38px;
  border: 0;
  border-radius: 12px;
  padding: 0 12px;
  background: #f5f6fa;
  color: #111522;
  font-size: 12px;
  font-weight: 800;
}
.storage-summary {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 11px;
  align-items: center;
  padding: 15px 16px;
  border-top: 1px solid var(--line);
}
.storage-summary strong { display: block; font-size: 14px; }
.storage-summary small { display: block; margin-top: 4px; color: var(--faint); font-size: 11px; line-height: 1.45; }
.storage-indicator { width: 10px; height: 10px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 4px rgba(255,204,102,.10); }
.storage-meta { padding: 10px 16px 13px; border-top: 1px solid var(--line); color: var(--faint); font-size: 11px; }

@media (max-width: 430px) {
  .backup-banner { align-items: flex-start; }
  .backup-banner button { min-width: 96px; }
}
.secondary-button {
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 20px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 800;
}
.secondary-button.full { width: 100%; }
.recovery-link { display: block; margin: 17px auto 0; }
.storage-indicator.safe { background: var(--accent-2); box-shadow: 0 0 0 4px rgba(85,214,190,.10); }
.storage-indicator.error { background: var(--danger); box-shadow: 0 0 0 4px rgba(255,107,122,.10); }
