:root {
  --bg: #13111c;
  --card: #1d1a2b;
  --card-2: #2a2540;
  --line: #363050;
  --text: #f3f0fa;
  --muted: #a49dbb;
  --accent: #7c3aed;       /* fills: buttons, bars (white text on it 5.7:1) */
  --accent-text: #b597ff;  /* text, lines and icons on the dark surfaces */
  --accent-ink: #ffffff;
  --danger: #ff6b5e;
  --radius: 18px;
  --tabbar: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---- shell ---- */
.screen {
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px);
  max-width: 640px;
  margin: 0 auto;
}
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 18px; }
.eyebrow { color: var(--muted); font-size: 14px; font-weight: 500; }
.eyebrow::first-letter { text-transform: uppercase; }
h1 { font-size: 32px; line-height: 1.1; letter-spacing: -0.02em; margin: 2px 0 0; font-weight: 750; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(19, 17, 28, 0.86);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
  border-top: 0.5px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tab svg { width: 25px; height: 25px; }
.tab[aria-current="page"] { color: var(--accent-text); }

/* ---- cards ---- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card h2 { font-size: 17px; margin: 0 0 6px; font-weight: 650; }
.muted { color: var(--muted); }
.soon { list-style: none; padding: 0; margin: 10px 0 0; }
.soon li { display: flex; gap: 10px; padding: 9px 0; border-top: 0.5px solid var(--line); }
.soon li:first-child { border-top: 0; }
.soon li::before { content: ""; flex: none; width: 7px; height: 7px; margin-top: 9px; border-radius: 50%; background: var(--accent-text); }
.empty { text-align: center; padding: 28px 16px; }
.empty svg { width: 44px; height: 44px; color: var(--accent-text); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px;
  background: var(--card-2); font-size: 13px; color: var(--muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4cd07d; }
.dot.off { background: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; width: 100%;
}
.btn:disabled { opacity: 0.55; }
.btn.ghost { background: var(--card-2); color: var(--text); font-weight: 600; width: auto; min-height: 36px; padding: 0 14px; font-size: 14px; }

/* ---- login ---- */
.login {
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 14px;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
  max-width: 400px; margin: 0 auto; text-align: center;
}
.login img { width: 96px; height: 96px; border-radius: 24px; margin: 0 auto 6px; }
.login h1 { margin: 0; }
.login form { display: grid; gap: 12px; margin-top: 12px; text-align: left; }
.field {
  width: 100%; min-height: 50px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--card); outline: none;
  font-size: 17px; /* 16px+ keeps iOS from zooming in */
}
.field:focus { border-color: var(--accent-text); }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 0; }
.hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---- shared controls ---- */
:root { --warn: #f2b84b; --ok: #4cd07d; }
body.locked { overflow: hidden; }
.small { font-size: 13px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--card-2);
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px; flex: none;
}
.icon-btn:disabled { opacity: 0.35; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid #4a2b3a; }
.btn.ghost.wide { width: 100%; min-height: 46px; margin: 8px 0 0; text-decoration: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.card-head h2 { margin: 0; }
.skeleton { height: 180px; opacity: 0.5; }
select.field { appearance: none; -webkit-appearance: none; background-image: none; }

/* ---- month header ---- */
.month-nav { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; white-space: nowrap; }
.hero { font-size: 40px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.hero-sub { margin: 4px 0 14px; font-size: 14px; }

/* ---- quick add ---- */
.quick { display: grid; gap: 10px; }
.quick p { margin: 0; }
.quick-row { display: flex; gap: 10px; }
.round {
  flex: none; width: 50px; height: 50px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 26px; font-weight: 700;
}
.round:disabled { opacity: 0.4; }
.quick-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px;
  border-radius: 99px; background: var(--card-2); border: 0; font-size: 14px; font-weight: 600;
}
.chip input[type="date"] { position: absolute; inset: 0; opacity: 0; width: 100%; }

/* ---- category bars: one hue, sorted, every bar labelled ---- */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bars button { display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; }
.bars li.dim { opacity: 0.4; }
.bar-label { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; margin-bottom: 6px; }
.bar-label b { font-variant-numeric: tabular-nums; }
.track { display: flex; gap: 2px; height: 8px; border-radius: 4px; background: var(--card-2); overflow: hidden; }
.fill { display: block; height: 100%; border-radius: 4px; background: var(--accent-text); }

/* ---- budgets ---- */
.budgets { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 16px; }
.budgets li { cursor: pointer; }
.meter { height: 10px; margin-bottom: 6px; }
.fill.ok { background: var(--accent-text); }
.fill.warn { background: var(--warn); }
.fill.over { background: var(--danger); }
.fill.planned {
  background: repeating-linear-gradient(135deg, #5f5680 0 3px, transparent 3px 6px);
}
.status-warn { color: var(--warn); }
.status-over { color: var(--danger); }

/* ---- rows (expenses, repeating) ---- */
.rows { list-style: none; margin: 0; padding: 0; }
.rows.card { padding: 4px 16px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 0.5px solid var(--line); cursor: pointer; }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .grow b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .grow b::first-letter { text-transform: uppercase; }
.row small { font-size: 13px; }
.badge {
  flex: none; width: 38px; height: 38px; border-radius: 12px; background: var(--card-2);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.total-line { margin: 6px 0 0; text-align: right; }
.day { margin: 18px 0 0; }
.day-head { display: flex; justify-content: space-between; padding: 0 4px 8px; color: var(--muted); font-size: 14px; font-weight: 600; }
.day-head span:first-child::first-letter { text-transform: uppercase; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 8px; margin: 12px 0 0; padding: 6px 8px 6px 14px;
  border-radius: 99px; background: var(--card-2); font-size: 14px; font-weight: 600;
}
.filter-chip button { border: 0; background: var(--card); border-radius: 50%; width: 24px; height: 24px; }

/* ---- bottom sheet ---- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s ease-out;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 88dvh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 20px); animation: rise 0.2s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.sheet p { margin: 0 0 14px; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
.form .field { color: var(--text); background: var(--bg); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---- toast ---- */
.toast {
  position: fixed; z-index: 25; left: 16px; right: 16px; max-width: 608px; margin: 0 auto;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 12px);
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px;
  background: #2a2540; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45); white-space: pre-line; font-size: 15px;
  animation: rise 0.2s ease-out;
}
.toast span { flex: 1; }
.toast.warn { background: #3b2a2a; }
.toast button { border: 0; background: none; color: var(--accent-text); font-weight: 700; padding: 4px; }

@media (prefers-reduced-motion: reduce) { .sheet, .toast, .sheet-backdrop { animation: none; } }

/* ---- money: segmented control, balance, donuts, legends, category editor ---- */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg); }
.segmented button { min-height: 34px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-weight: 600; font-size: 14px; }
.segmented button[aria-selected="true"] { background: var(--card-2); color: var(--text); }
.amount-field { flex: 0 0 96px; min-width: 0; }
.quick-row .field { min-width: 0; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.eyebrow + .hero { margin-top: 2px; }
.balance { display: grid; gap: 10px; }
.track.stack { height: 12px; border-radius: 6px; }
.track.stack .fill { border-radius: 0; }
.track.stack .fill:first-child { border-radius: 6px 0 0 6px; }
.track.stack .fill:last-child { border-radius: 0 6px 6px 0; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 15px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.legend li b { margin-left: auto; font-variant-numeric: tabular-nums; }
.key { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.donut-wrap { display: flex; justify-content: center; margin: 4px 0 12px; }
.donut { width: min(220px, 62vw); height: auto; }
.donut circle { transition: opacity 0.15s; }
.donut-big { fill: var(--text); font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; }
.donut-small { fill: var(--muted); font-size: 12px; font-weight: 600; }
.rows-legend { gap: 0; }
.rows-legend li { display: block; border-top: 0.5px solid var(--line); }
.rows-legend li:first-child { border-top: 0; }
.rows-legend li.dim { opacity: 0.4; }
.rows-legend button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 0; border: 0; background: none; text-align: left;
}
.rows-legend .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows-legend b { font-variant-numeric: tabular-nums; }
.pct { width: 44px; text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.cat-edit { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.cat-edit li { display: flex; gap: 8px; align-items: center; }
.cat-edit .field { background: var(--bg); min-height: 44px; }
.field.emoji { flex: 0 0 56px; text-align: center; padding: 0; }
.danger-btn { background: var(--danger); color: #1a0705; }
.add-cat { margin-top: 4px; }

/* ---- prices ---- */
.tags { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.tag { font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--card-2); color: var(--muted); }
.tag.good { color: var(--ok); }
.spark { flex: none; width: 72px; height: 24px; }
.spark polyline { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linejoin: round; }
.spark circle { fill: var(--accent-text); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
.btn-row .btn.ghost { min-height: 48px; }
.offers .row { align-items: flex-start; cursor: default; }
.offers .amount { display: flex; flex-direction: column; align-items: flex-end; }
.offers s { font-weight: 500; }
b.wrap { white-space: normal !important; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.offer-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.offer-actions .chip { min-height: 30px; font-size: 13px; text-decoration: none; color: var(--text); }
a.plain { color: inherit; text-decoration: none; }
.detail-now { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.detail-now .btn.ghost { text-decoration: none; }
.target-form { display: grid; gap: 8px; margin: 14px 0 6px; }
.link-btn { justify-self: start; border: 0; background: none; color: var(--danger); padding: 4px 0; font-size: 14px; }
h3.sub { font-size: 15px; margin: 18px 0 4px; color: var(--muted); font-weight: 650; }
.linechart { margin: 4px 0 0; }
.linechart svg { width: 100%; height: auto; touch-action: pan-y; display: block; }
.linechart .grid { stroke: var(--line); stroke-width: 1; }
.linechart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.linechart .line { fill: none; stroke: var(--accent-text); stroke-width: 2; stroke-linejoin: round; }
.linechart .target { stroke: var(--ok); stroke-width: 1.5; stroke-dasharray: 5 4; }
.linechart .target-label { fill: var(--ok); }
.linechart .dot-min { fill: var(--bg); stroke: var(--ok); stroke-width: 2.5; }
.linechart .dot-now { fill: var(--accent-text); stroke: var(--card); stroke-width: 2; }
.linechart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.linechart figcaption { min-height: 22px; margin-top: 4px; }
.btn-row .btn.narrow { flex: 0 0 auto; padding: 0 16px; }
.amount.muted { color: var(--muted); }

/* ---- news ---- */
.stories { list-style: none; margin: 4px 0 0; padding: 0; }
.stories li { border-top: 0.5px solid var(--line); }
.stories li:first-child { border-top: 0; }
.story { display: flex; flex-direction: column; gap: 3px; padding: 11px 0; color: inherit; text-decoration: none; }
.story b { font-weight: 600; line-height: 1.35; }
.story small { font-size: 13px; }
.link-btn.more { color: var(--accent-text); font-weight: 650; }
.plain-btn { width: 100%; border: 0; background: none; padding: 0; text-align: left; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.time-row { display: flex; align-items: center; gap: 10px; }
.field.time { width: auto; min-height: 40px; background: var(--bg); color: var(--text); }

/* ---- AI chat ---- */
.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 96px; }
.bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere;
  line-height: 1.4; font-size: 16px;
}
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.bubble.sova { align-self: flex-start; background: var(--card); border-bottom-left-radius: 6px; }
.bubble.error { color: var(--danger); }
.bubble a { color: inherit; text-decoration: underline; }
.typing { display: flex; gap: 5px; padding: 14px 16px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.composer {
  position: fixed; z-index: 9; left: 0; right: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
  display: flex; gap: 8px; align-items: center; padding: 8px 16px; max-width: 640px; margin: 0 auto;
  background: rgba(19, 17, 28, 0.92); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.composer .field { min-height: 44px; border-radius: 22px; }
.composer .round { width: 44px; height: 44px; font-size: 22px; }

/* ---- home ---- */
.card.tap { cursor: pointer; }
.split { display: flex; justify-content: space-between; gap: 12px; }
.split .right { text-align: right; }
.small-hero { font-size: 30px; }
.budgets.mini { gap: 10px; margin-top: 14px; }
.down-from { display: block; font-size: 12px; font-weight: 500; text-align: right; }
.logout { display: block; margin: 18px auto 0; color: var(--muted); }
.notif .btn-row { margin-top: 4px; }
