:root {
  --bg: #090b10;
  --surface: #11141b;
  --surface-2: #171b24;
  --surface-3: #1e2430;
  --text: #f7f8fb;
  --muted: #8b92a0;
  --line: rgba(255,255,255,.08);
  --accent: #7c5cff;
  --positive: #48d597;
  --negative: #ff6b78;
  --warning: #ffca5c;
  --shadow: 0 18px 60px rgba(0,0,0,.35);
  --radius-xl: 24px;
  --radius-md: 16px;
  --safe-bottom: max(env(safe-area-inset-bottom), 12px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button, .clickable { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.positive { color: var(--positive) !important; }
.negative { color: var(--negative) !important; }
.warning { color: var(--warning) !important; }

#app {
  min-height: 100vh;
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: 96px;
  background: radial-gradient(circle at 80% -10%, rgba(124,92,255,.16), transparent 36%), var(--bg);
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 18px 10px;
  background: rgba(9,11,16,.86);
  backdrop-filter: blur(18px);
}
.top-title { font-size: 24px; font-weight: 820; letter-spacing: -.04em; }
.avatar {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%;
  font-weight: 850; background: linear-gradient(145deg, #6d53ff, #9b7cff);
}

.view { padding: 8px 14px 24px; display: grid; gap: 12px; }

.loading-card {
  min-height: 220px; border: 1px solid var(--line); border-radius: var(--radius-xl);
  display: grid; place-items: center; align-content: center; gap: 14px;
  background: rgba(17,20,27,.65); color: var(--muted);
}
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.12); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- карточки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-xl); padding: 16px 18px;
}
.card-title { font-size: 16px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 6px; }
.card-sub { font-size: 12px; color: var(--muted); font-weight: 700; margin: 12px 0 2px; }
.explain { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 8px 0 4px; }
.empty-line { font-size: 13px; color: var(--muted); padding: 14px 0 6px; }

.main-card { padding-top: 12px; }
.net-label { text-align: center; color: var(--muted); font-size: 13px; font-weight: 650; margin-top: 14px; }
.net-value {
  text-align: center; font-size: clamp(38px, 12vw, 52px); font-weight: 880;
  letter-spacing: -.05em; margin: 2px 0 10px;
}

.sum-rows { display: grid; }
.sum-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px;
}
.sum-row:last-child { border-bottom: 0; }
.sum-row span { color: #c3c8d1; }
.sum-row small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.sum-row b { font-weight: 780; white-space: nowrap; }
.sum-row.total { font-size: 17px; }
.sum-row.total span { color: var(--text); font-weight: 780; }
.sum-rows.small .sum-row, .sum-row.small { font-size: 13px; padding: 8px 0; }

.month-nav { display: flex; align-items: center; justify-content: center; gap: 10px; }
.month-btn {
  width: 34px; height: 34px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 18px; line-height: 1;
}
.month-btn:disabled { opacity: .25; }
.month-label { font-size: 14px; font-weight: 750; min-width: 120px; text-align: center; }

.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-btn {
  border: 0; border-radius: 18px; padding: 17px 10px; font-size: 16px; font-weight: 820;
}
.action-btn.income { background: rgba(72,213,151,.14); color: var(--positive); }
.action-btn.expense { background: rgba(255,107,120,.12); color: var(--negative); }
.action-btn:active { transform: scale(.98); }

.pay-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.pay-row:last-of-type { border-bottom: 0; }
.pay-main { min-width: 0; }
.pay-title { font-size: 15px; font-weight: 740; }
.pay-date { font-size: 12px; color: var(--warning); font-weight: 700; margin-left: 4px; }
.pay-note { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.hint { font-size: 12px; color: #b9a8ff; line-height: 1.4; }
.pay-side { display: grid; justify-items: end; gap: 6px; }
.pay-amount { font-size: 16px; font-weight: 800; white-space: nowrap; }

.tx-list { display: flex; flex-direction: column; }
.tx {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.tx:last-child { border-bottom: 0; }
.tx-main { min-width: 0; }
.tx-title { font-weight: 720; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { color: var(--muted); font-size: 11px; margin-top: 3px; }
.tx-amount { font-weight: 820; font-size: 15px; white-space: nowrap; }

.pill {
  border: 1px solid rgba(124,92,255,.45); background: rgba(124,92,255,.14); color: #cbbfff;
  padding: 6px 11px; border-radius: 99px; font-size: 12px; font-weight: 750;
}

details.more > summary {
  cursor: pointer; list-style: none; color: #a996ff; font-size: 13px; font-weight: 750; padding: 4px 0;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸ "; }
details.more[open] > summary::before { content: "▾ "; }
.more-body { display: grid; gap: 12px; margin-top: 12px; }

/* ---------- нижнее меню ---------- */
.bottom-nav {
  position: fixed; z-index: 40; left: 50%; transform: translateX(-50%); bottom: 0;
  width: min(640px, 100%);
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 8px 8px var(--safe-bottom);
  background: rgba(13,15,21,.94); backdrop-filter: blur(22px);
  border-top: 1px solid var(--line);
}
.nav-item {
  border: 0; background: transparent; display: grid; place-items: center; gap: 3px;
  color: #727985; font-size: 11px; font-weight: 720; padding: 4px 0;
}
.nav-icon { font-size: 21px; line-height: 1; height: 23px; }
.nav-item.active { color: #fff; }
.nav-item.active .nav-icon { color: #9077ff; }

/* ---------- шторка и формы ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.56); backdrop-filter: blur(4px); }
.sheet {
  position: fixed; z-index: 90; left: 50%; transform: translateX(-50%); bottom: 0;
  width: min(640px, 100%); max-height: 92vh; overflow-y: auto;
  border-radius: 28px 28px 0 0;
  padding: 9px 18px calc(20px + env(safe-area-inset-bottom));
  background: #12151c; box-shadow: var(--shadow);
}
.sheet-handle { width: 38px; height: 4px; border-radius: 99px; background: rgba(255,255,255,.18); margin: 3px auto 16px; }
.sheet-title { font-size: 23px; font-weight: 840; letter-spacing: -.04em; }
.sheet-sub { margin-top: 5px; font-size: 12px; color: var(--muted); line-height: 1.45; }

.form { margin-top: 14px; display: grid; gap: 14px; }
.field { display: grid; gap: 7px; }
.field label { color: #a5abb5; font-size: 12px; font-weight: 720; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line); background: #0c0f15; color: #fff;
  border-radius: 14px; padding: 13px 14px; outline: none;
}
.input:focus, .select:focus { border-color: rgba(124,92,255,.75); }
.amount-input { font-size: 34px; font-weight: 850; letter-spacing: -.04em; padding: 16px 15px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice-grid.three { grid-template-columns: repeat(3, 1fr); }
.choice {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 14px;
  padding: 12px 6px; font-size: 14px; font-weight: 720; color: #c3c8d1;
}
.choice.active { border: 2px solid var(--accent); color: #fff; background: rgba(124,92,255,.12); padding: 11px 5px; }

.preview-box { background: var(--surface-2); border-radius: 16px; padding: 4px 14px; }
.preview-box:empty { display: none; }
.preview-box .hint { padding: 10px 0; }

.check-row { display: flex; align-items: center; gap: 10px; color: #c3c8d1; font-size: 13px; font-weight: 600; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex: none; }

.btn-primary {
  width: 100%; border: 0; border-radius: 16px; padding: 15px 18px; font-weight: 820; font-size: 16px;
  background: linear-gradient(145deg, #7658fb, #9175ff); color: #fff;
}
.btn-primary:disabled { opacity: .55; }
.btn-secondary {
  width: 100%; border: 1px solid var(--line); border-radius: 16px; padding: 13px 16px;
  font-weight: 760; background: var(--surface-2); margin-top: 10px;
}
.btn-danger {
  width: 100%; border: 0; border-radius: 16px; padding: 14px 16px; font-weight: 800;
  color: var(--negative); background: rgba(255,107,120,.1);
}
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.btn-row .btn-secondary { margin-top: 0; }
.detail-amount { font-size: 34px; font-weight: 860; letter-spacing: -.04em; margin: 12px 0 6px; }

.toast {
  position: fixed; z-index: 120; left: 50%; transform: translateX(-50%); bottom: 96px;
  max-width: calc(100vw - 34px); display: flex; align-items: center; gap: 14px;
  padding: 11px 15px; border-radius: 14px; color: #fff; background: #252a35;
  box-shadow: var(--shadow); font-size: 13px; font-weight: 700;
}
.toast-btn { border: 0; background: none; color: #b7a6ff; font-weight: 850; font-size: 13px; padding: 2px 0; }

.error-box {
  border-radius: var(--radius-xl); background: rgba(255,107,120,.08);
  border: 1px solid rgba(255,107,120,.2); padding: 20px;
}
.error-title { color: var(--negative); font-weight: 850; font-size: 18px; }
.error-text { color: #afb4bd; font-size: 13px; margin-top: 8px; line-height: 1.5; }

.setup-card { border-color: rgba(255,202,92,.35); background: rgba(255,202,92,.06); }
.btn-col { display: grid; gap: 8px; margin-top: 8px; }
.btn-col .btn-secondary { margin-top: 0; }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 700; padding: 6px 0; text-decoration: underline; }
