/* iOS-inspired look: system colors, grouped inset lists, large titles, tab bar and bottom sheets. */

:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-pressed: #e5e5ea;
  --elevated: #ffffff;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.29);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.2);
  --segment-selected: #ffffff;
  --bar-bg: rgba(249, 249, 249, 0.86);
  --switch-off: #e9e9eb;
  --blue: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --teal: #30b0c7;
  --gray: #8e8e93;
  --sheet-bg: #f2f2f7;
  --sheet-card: #ffffff;
  --shadow: 0 0.5px 0 rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --navbar-height: 44px;
  --tabbar-height: 50px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-pressed: #2c2c2e;
    --elevated: #1c1c1e;
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.65);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-strong: rgba(120, 120, 128, 0.36);
    --segment-selected: #636366;
    --bar-bg: rgba(22, 22, 23, 0.86);
    --switch-off: #39393d;
    --blue: #0a84ff;
    --green: #30d158;
    --red: #ff453a;
    --orange: #ff9f0a;
    --teal: #40c8e0;
    --gray: #8e8e93;
    --sheet-bg: #1c1c1e;
    --sheet-card: #2c2c2e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 17px/1.29 var(--font);
  letter-spacing: -0.41px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }
svg.icon { width: 1em; height: 1em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.positive { color: var(--green); }
.negative { color: var(--red); }
.muted { color: var(--label-2); }

/* ---------- navigation bar ---------- */

.navbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  padding-top: var(--safe-top);
  background: transparent;
  transition: background-color 0.2s, border-color 0.2s;
  border-bottom: 0.5px solid transparent;
}
.navbar.scrolled {
  background: var(--bar-bg);
  border-bottom-color: var(--separator);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
.navbar-inner {
  max-width: 720px; height: var(--navbar-height); margin: 0 auto; padding: 0 8px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
}
.navbar-title {
  font-weight: 600; text-align: center; white-space: nowrap;
  opacity: 0; transition: opacity 0.2s;
}
.navbar.scrolled .navbar-title { opacity: 1; }
.navbar-side { display: flex; align-items: center; }
.navbar-side.end { justify-content: flex-end; }

.nav-button {
  border: 0; background: none; color: var(--blue);
  height: 44px; min-width: 44px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; font-size: 17px;
}
.nav-button:active { opacity: 0.4; }
.nav-button.strong { font-weight: 600; }
.nav-button:disabled { color: var(--label-3); }
.nav-button .icon { font-size: 22px; stroke-width: 2.2; }

/* ---------- screens ---------- */

.screen {
  max-width: 720px; margin: 0 auto;
  padding: calc(var(--safe-top) + var(--navbar-height)) 0 calc(var(--tabbar-height) + var(--safe-bottom) + 32px);
}

.large-title-row {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 2px 16px 8px;
}
.large-title {
  margin: 0; font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: 0.37px;
}
.large-title-suffix { font-size: 34px; line-height: 41px; font-weight: 700; color: var(--label-3); }
.large-title-row .spacer { flex: 1; }

.month-nav { display: flex; gap: 8px; padding-bottom: 4px; }
.circle-button {
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: var(--fill); color: var(--blue);
  display: grid; place-items: center; cursor: pointer; font-size: 18px;
}
.circle-button:active { background: var(--fill-strong); }
.circle-button .icon { stroke-width: 2.6; }

.intro { margin: 0 16px 8px; color: var(--label-2); font-size: 15px; }

/* ---------- hero card ---------- */

.hero {
  margin: 8px 16px 0; padding: 16px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}
.hero-label { font-size: 15px; color: var(--label-2); font-weight: 500; }
.hero-value {
  display: block; margin: 2px 0 12px;
  font: 700 40px/1.1 var(--font-rounded); letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}
.progress { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.progress > div { height: 100%; width: 0; border-radius: 3px; background: var(--green); transition: width 0.4s ease; }
.progress > div[data-level="medium"] { background: var(--orange); }
.progress > div[data-level="high"] { background: var(--red); }
.hero-detail { margin-top: 8px; font-size: 13px; color: var(--label-2); }

/* ---------- grouped lists ---------- */

.section-header {
  margin: 24px 32px 7px;
  font-size: 13px; line-height: 18px; font-weight: 400;
  text-transform: uppercase; letter-spacing: -0.08px; color: var(--label-2);
}
.section-footer {
  margin: 7px 32px 0;
  font-size: 13px; line-height: 18px; letter-spacing: -0.08px; color: var(--label-2);
}
.section-footer:empty { display: none; }

.group {
  margin: 0 16px; overflow: hidden;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}
.group:empty { display: none; }
.group + .group { margin-top: 24px; }

.row {
  position: relative; width: 100%;
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 10px 16px;
  border: 0; background: none; text-align: left; color: var(--label);
}
.row:not(:last-child)::after,
.row-list > .row:last-child::after { /* a list followed by an action row inside the same group */
  content: ""; position: absolute; right: 0; bottom: 0; left: var(--separator-inset, 16px);
  height: 0.5px; background: var(--separator);
}
.row:has(> .row-icon) { --separator-inset: 58px; }
button.row, label.row.tappable { cursor: pointer; }
button.row:active, label.row.tappable:active { background: var(--card-pressed); }
button.row:disabled { cursor: default; }
button.row:disabled:active { background: none; }

.row-icon {
  width: 30px; height: 30px; border-radius: 7px; flex: none;
  display: grid; place-items: center;
  color: #fff; font-size: 15px; font-weight: 600; letter-spacing: 0;
}
.row-icon .icon { font-size: 18px; stroke-width: 2.2; }
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-subtitle { font-size: 13px; line-height: 18px; color: var(--label-2); overflow-wrap: anywhere; }
.row-detail { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.row-value { color: var(--label-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-value.strong { color: var(--label); font-weight: 600; }
.row-value.amount { color: var(--label); }
.row-value.positive { color: var(--green); }
.row-value.negative { color: var(--red); }
.row-value-sub { font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-chevron { color: var(--label-3); font-size: 14px; stroke-width: 3; margin-left: -4px; }
.row-title.strong { font-weight: 600; }

.row.action { color: var(--blue); }
.row.action .row-icon { background: none; color: var(--blue); }
.row.destructive { color: var(--red); justify-content: center; }
.row.centered { justify-content: center; }

.badge {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 6px;
  background: var(--fill); color: var(--label-2);
  font-size: 11px; line-height: 17px; font-weight: 600; vertical-align: 2px; letter-spacing: 0;
}

.empty { margin: 0 16px; padding: 28px 16px; text-align: center; color: var(--label-2); font-size: 15px; background: var(--card); border-radius: var(--radius); }

/* ---------- charts ---------- */

.chart-card { padding: 16px; }
.doughnut { position: relative; height: 220px; }
.doughnut-center {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.doughnut-center small { color: var(--label-2); font-size: 13px; }
.doughnut-center strong { font: 600 20px var(--font-rounded); font-variant-numeric: tabular-nums; }
.bars { position: relative; height: 260px; }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  padding-bottom: var(--safe-bottom);
  background: var(--bar-bg);
  border-top: 0.5px solid var(--separator);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
.tabbar-inner { max-width: 720px; margin: 0 auto; display: flex; height: var(--tabbar-height); }
.tab {
  flex: 1; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--gray); font-size: 10px; font-weight: 500; letter-spacing: 0.1px;
}
.tab .icon { font-size: 26px; stroke-width: 1.8; }
.tab[aria-selected="true"] { color: var(--blue); }
.tab[aria-selected="true"] .icon { stroke-width: 2.3; }

/* ---------- bottom sheets ---------- */

.sheet {
  width: 100%; max-width: 640px; max-height: calc(100% - var(--safe-top) - 12px);
  margin: auto auto 0; padding: 0;
  border: 0; border-radius: 14px 14px 0 0;
  background: var(--sheet-bg); color: var(--label);
  overflow: hidden; display: none; flex-direction: column;
}
.sheet .group { background: var(--sheet-card); }
.sheet[open] { display: flex; animation: sheet-in 0.32s cubic-bezier(0.2, 0.9, 0.3, 1); }
.sheet.closing { animation: sheet-out 0.22s ease-in forwards; }
/* literal colors: older Chromium doesn't pass custom properties down to ::backdrop */
.sheet::backdrop { background: rgba(0, 0, 0, 0.4); animation: fade-in 0.3s; }
@media (prefers-color-scheme: dark) { .sheet::backdrop { background: rgba(0, 0, 0, 0.6); } }
.sheet.closing::backdrop { animation: fade-out 0.22s forwards; }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 14px; max-height: 86vh; }
  .sheet[open] { animation-name: sheet-pop; }
  .sheet.closing { animation-name: sheet-pop-out; }
  @keyframes sheet-pop { from { transform: scale(0.94); opacity: 0; } }
  @keyframes sheet-pop-out { to { transform: scale(0.94); opacity: 0; } }
}

.sheet form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.sheet-header {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 6px 8px 0; flex: none;
}
.sheet-header .nav-button:last-child { justify-self: end; }
.sheet-title { margin: 0; font-size: 17px; font-weight: 600; text-align: center; }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 0 calc(24px + var(--safe-bottom));
}
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label-3); margin: 6px auto 0; }
@media (min-width: 700px) { .grabber { display: none; } }

.amount-input {
  display: flex; align-items: baseline; justify-content: center; gap: 6px;
  margin: 8px 16px 20px;
}
.amount-input span { font: 600 28px var(--font-rounded); color: var(--label-2); }
.amount-input input {
  width: 4.5ch; max-width: calc(100% - 48px); /* width follows the typed value (see app.js) */
  border: 0; outline: 0; background: none; padding: 0;
  font: 700 48px/1.1 var(--font-rounded); text-align: center; color: var(--label);
  font-variant-numeric: tabular-nums;
}
.amount-input input::placeholder { color: var(--label-3); }

/* form rows: label on the left, control on the right (like iOS Settings) */
.field { cursor: text; }
.field > span:first-child { flex: none; }
.field input, .field select {
  flex: 1; min-width: 0; height: 24px;
  border: 0; outline: 0; background: none; padding: 0;
  text-align: right; color: var(--label-2);
  font-size: 17px; /* 16px+ keeps iOS from zooming in */
}
.field input:focus { color: var(--label); }
.field input::placeholder { color: var(--label-3); }
.field input[type="date"], .field input[type="month"] { -webkit-appearance: none; appearance: none; display: flex; justify-content: flex-end; }
.field input::-webkit-date-and-time-value { text-align: right; }
.field select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  padding-right: 18px; text-align-last: right;
  background: no-repeat right center / 12px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 16' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 6l4-4 4 4M2 10l4 4 4-4'/%3E%3C/svg%3E");
}
.field select option { color: initial; }

.segmented {
  display: flex; margin: 0 16px 16px; padding: 2px;
  background: var(--fill); border-radius: 9px;
}
.segmented button {
  flex: 1; height: 28px; border: 0; border-radius: 7px; background: none; cursor: pointer;
  font-size: 13px; font-weight: 500; letter-spacing: -0.08px;
}
.segmented button[aria-selected="true"] {
  background: var(--segment-selected); font-weight: 600;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
}

/* iOS switch */
.switch {
  -webkit-appearance: none; appearance: none; flex: none; cursor: pointer;
  position: relative; width: 51px; height: 31px; margin: 0;
  border-radius: 16px; background: var(--switch-off); transition: background-color 0.25s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
  transition: transform 0.25s;
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }

.swatches {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; justify-items: center;
  padding: 16px;
}
.swatch {
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.1);
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--label-2); }
.swatch-custom { position: relative; overflow: hidden; background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; z-index: 50;
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 16px);
  transform: translate(-50%, 12px);
  max-width: calc(100% - 32px); padding: 11px 18px;
  border-radius: 14px; background: var(--elevated); color: var(--label);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  font-size: 15px; font-weight: 500; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); color: #fff; }

/* ---------- login ---------- */

.login {
  min-height: 100vh; min-height: 100dvh;
  max-width: 420px; margin: 0 auto;
  padding: calc(var(--safe-top) + 64px) 0 calc(var(--safe-bottom) + 32px);
  display: flex; flex-direction: column;
}
.login-header { text-align: center; padding: 0 32px 28px; }
.login-icon { width: 88px; height: 88px; border-radius: 20px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); }
.login-header h1 { margin: 20px 0 6px; font-size: 28px; font-weight: 700; letter-spacing: 0.36px; }
.login-header p { margin: 0; color: var(--label-2); font-size: 15px; }
.login-actions { padding: 0 16px; display: flex; flex-direction: column; gap: 12px; }
.login .group { margin: 0 0 16px; }
.login-error { min-height: 20px; margin: 12px 16px 0; text-align: center; color: var(--red); font-size: 15px; }
.login-offer { text-align: center; padding: 0 32px; }
.login-offer .icon { font-size: 64px; color: var(--blue); stroke-width: 1.4; }
.login-offer h2 { margin: 16px 0 8px; font-size: 22px; font-weight: 700; }
.login-offer p { margin: 0 0 28px; color: var(--label-2); font-size: 15px; }

.button {
  height: 50px; width: 100%; border: 0; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 17px; font-weight: 600;
}
.button .icon { font-size: 22px; }
.button.filled { background: var(--blue); color: #fff; }
.button.filled:active { filter: brightness(0.9); }
.button.plain { background: none; color: var(--blue); font-weight: 400; }
.button.plain:active { opacity: 0.4; }
.button:disabled { opacity: 0.5; cursor: default; }

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