:root {
  color-scheme: light;
  --bg: #f4fbf7;
  --surface: #ffffff;
  --surface-2: #eaf4ee;
  --text: #1e2722;
  --muted: #5f6b64;
  --border: #dce9e2;
  --accent: #007650;
  --accent-2: #12a36f;
  --accent-tint: #d9f7e7;
  --success: #007f38;
  --warning: #956300;
  --danger: #bc4a41;
  --cat-1: #007650;
  --cat-2: #1d8f66;
  --cat-3: #34a87a;
  --cat-4: #5bbe92;
  --cat-5: #8acfa9;
  --cat-6: #b7e4c8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .04);
  --radius: 16px;
  --radius-lg: 20px;
  --tab-bg: rgba(255, 255, 255, .92);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141a17;
  --surface: #1e2521;
  --surface-2: #26302a;
  --text: #f2f7f4;
  --muted: #9aa69f;
  --border: #334038;
  --accent: #3ec08c;
  --accent-2: #75d4a8;
  --accent-tint: #0d3625;
  --success: #59be73;
  --warning: #d5a052;
  --danger: #fb8276;
  --cat-1: #3ec08c;
  --cat-2: #75d4a8;
  --cat-3: #a9e6c7;
  --cat-4: #2e9e72;
  --cat-5: #56b68a;
  --cat-6: #8acfa9;
  --shadow: 0 1px 2px rgba(0, 0, 0, .24), 0 12px 32px rgba(0, 0, 0, .18);
  --tab-bg: rgba(20, 26, 23, .92);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 112px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 0 14px;
  background: var(--bg);
}

.topbar__title {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.6px;
  line-height: 1.1;
}

.topbar p {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
  text-transform: capitalize;
}

.topbar__actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 120ms ease, opacity 120ms ease;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn:active {
  transform: scale(.96);
}

.icon-btn:disabled {
  opacity: .35;
  cursor: default;
}

main {
  min-height: 50vh;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: rise 180ms ease both;
}

.view[hidden] {
  display: none !important;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: 18px;
  border-radius: var(--radius-lg);
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-value {
  margin-top: 4px;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -1.4px;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.hero-meta .up {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--success);
  font-weight: 500;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}

.pill.warn {
  background: color-mix(in srgb, var(--warning) 14%, transparent);
  color: var(--warning);
}

.spark {
  margin-top: 10px;
  height: 48px;
}

.spark svg {
  width: 100%;
  height: 100%;
  display: block;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat {
  padding: 14px;
}

.stat__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.stat__value {
  margin-top: 6px;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.4px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat__value.danger { color: var(--danger); }
.stat__value.success { color: var(--success); }

.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 0 2px;
}

.section__head h2 {
  margin: 0;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.35px;
}

.section__note {
  font-size: 12px;
  color: var(--muted);
}

.link-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.budgets {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.budget__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.budget__head span:last-child {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.budget__head span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track {
  height: 8px;
  margin-top: 6px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}

.track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 280ms ease;
}

.track i.warn { background: var(--warning); }
.track i.danger { background: var(--danger); }

.categories {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.donut {
  position: relative;
  width: 120px;
  height: 120px;
  flex: 0 0 120px;
}

.donut svg {
  width: 120px;
  height: 120px;
  transform: rotate(-90deg);
}

.donut__center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.donut__center strong {
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
}

.donut__center span {
  margin-top: 1px;
  font-size: 10px;
  color: var(--muted);
}

.legend {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend__row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
}

.legend__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend__share {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chart-card {
  padding: 14px 16px 10px;
}

.chart-card svg {
  width: 100%;
  height: 110px;
  display: block;
  overflow: visible;
}

.chart-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.insight {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--accent-tint);
}

.insight__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent);
}

.insight__label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent);
}

.insight__text {
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.45;
}

.insight__text + .insight__text {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.goal {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
}

.goal__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--accent);
}

.goal__label {
  font-size: 11px;
  color: var(--muted);
}

.goal__text {
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tx-card {
  overflow: hidden;
}

.tx-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.tx-row:first-child {
  border-top: 0;
}

.tx-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
}

.tx-main {
  min-width: 0;
}

.tx-title {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-sub {
  margin-top: 1px;
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-amount {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tx-amount.income {
  color: var(--success);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 28px 18px;
  text-align: center;
}

.empty__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--muted);
}

.empty p {
  margin: 4px 0 0;
  font-size: 14px;
  font-weight: 600;
}

.empty small {
  max-width: 280px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.empty-inline {
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
}

.budgets .empty-inline {
  padding: 0;
}

.empty-inline strong {
  display: block;
  margin-bottom: 2px;
  color: var(--text);
  font-size: 14px;
}

.ops-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
}

.ops-summary div {
  padding: 14px;
  background: var(--surface);
}

.ops-summary span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.ops-summary strong {
  display: block;
  margin-top: 3px;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.cat-bars {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cat-bar__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.cat-bar__head span:last-child {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.cat-bar .track {
  margin-top: 6px;
}

.view-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 2px 0;
}

.view-title h2 {
  margin: 0;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 22px;
  letter-spacing: -0.5px;
}

.view-title p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: capitalize;
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 30;
  width: min(100%, 480px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px 10px calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: var(--tab-bg);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
}

.tabbar button:hover {
  background: var(--surface-2);
}

.tabbar button.active {
  color: var(--accent);
}

.tabbar button span {
  line-height: 1.2;
}

.skeleton-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sk {
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.sk-hero { height: 210px; }
.sk-stat { height: 92px; }
.sk-block { height: 180px; }

.sk-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

.error-card {
  padding: 24px 18px;
  text-align: center;
}

.error-card h2 {
  margin: 0 0 6px;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 20px;
}

.error-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.error-card button {
  margin-top: 14px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 360px) {
  .categories {
    flex-direction: column;
    align-items: flex-start;
  }
  .donut {
    align-self: center;
  }
  .hero-value {
    font-size: 36px;
  }
}

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