:root {
  --bg: #161a24;
  --surface: #1e2331;
  --surface-2: #272d3f;
  --line: #333a52;
  --text: #eceaf4;
  --muted: #9ba1ba;
  --accent: #ffb86b;
  --accent-ink: #2a1a06;
  --income: #7bd8b0;
  --expense: #ff8d9d;
  --danger: #ff8d9d;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, Georgia, "Times New Roman", serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
.boot { padding: 40px; color: var(--muted); }

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

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 14px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=month], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
textarea { resize: vertical; min-height: 160px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #6c738d; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.error-text { color: var(--danger); font-size: 14px; min-height: 20px; }

/* ---------- Экран входа ---------- */
.center {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
}
.auth-card { width: min(440px, 100%); display: grid; gap: 20px; }
.wordmark { font: 600 38px/1.1 var(--serif); letter-spacing: -.01em; }
.tagline { color: var(--muted); margin-top: 6px; }
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px; display: grid; gap: 14px;
}
.panel h2 { font-size: 18px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.tab { min-height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 600; }
.tab[aria-selected=true] { background: var(--surface-2); color: var(--text); }
.onboard { width: min(880px, 100%); display: grid; gap: 20px; }
.onboard-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }

/* ---------- Оболочка ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100dvh; }
.side {
  position: sticky; top: 0; height: 100dvh; padding: 24px 14px;
  border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 24px;
}
.side .wordmark { font-size: 26px; padding: 0 10px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  cursor: pointer; font-weight: 600; text-align: left;
}
.nav-btn:hover { color: var(--text); background: var(--surface); }
.nav-btn[aria-current=page] { color: var(--text); background: var(--surface-2); }
.nav-btn[aria-current=page] .ico { color: var(--accent); }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.main { min-width: 0; padding: 28px clamp(16px, 4vw, 44px) 48px; max-width: 980px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.topbar h1 { font: 600 30px/1.15 var(--serif); letter-spacing: -.01em; }
.topbar .who { color: var(--muted); font-size: 14px; }
.page { display: grid; gap: 20px; }

/* ---------- Карточки и сводки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; display: grid; gap: 14px; }
.card h2 { font-size: 17px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 14px; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; overflow-wrap: anywhere; }
.pos { color: var(--income); }
.neg { color: var(--expense); }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.empty { color: var(--muted); padding: 8px 0; }
.invite { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.code { font: 700 22px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .08em; padding: 10px 14px; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; user-select: all; }

/* ---------- Формы ---------- */
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
.form-grid .wide { grid-column: 1 / -1; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.seg button { min-height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.seg button[aria-pressed=true].k-expense { background: rgba(255,141,157,.16); color: var(--expense); }
.seg button[aria-pressed=true].k-income { background: rgba(123,216,176,.16); color: var(--income); }
.inline-form { display: grid; grid-template-columns: 1fr 110px auto; gap: 10px; align-items: end; }

/* ---------- Списки ---------- */
.rows { display: grid; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.row-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--danger); }
.bought .row-title { text-decoration: line-through; color: var(--muted); }

.bar-row { display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 12px; font-size: 14px; }
.bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--expense); border-radius: 99px; }
.bar-row span:last-child { font-variant-numeric: tabular-nums; }

/* ---------- Заметки ---------- */
.notes-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.note { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; cursor: pointer; display: grid; gap: 8px; align-content: start; min-height: 130px; }
.note:hover { border-color: var(--muted); }
.note h3 { font-size: 16px; overflow-wrap: anywhere; }
.note p { color: var(--muted); font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 5; line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.note small { color: var(--muted); font-size: 12px; align-self: end; }

dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(580px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(8, 10, 16, .72); }
.dialog-body { padding: 18px; display: grid; gap: 14px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.dialog-actions .spacer { margin-right: auto; }

/* ---------- Калькулятор ---------- */
.calc { width: min(360px, 100%); display: grid; gap: 12px; }
.calc-screen { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; text-align: right; min-height: 104px; display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden; }
.calc-line { color: var(--muted); font-size: 15px; min-height: 22px; font-variant-numeric: tabular-nums; }
.calc-cur { font-size: 38px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.key { min-height: 62px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); font-size: 22px; font-weight: 600; cursor: pointer; }
.key:hover { border-color: var(--muted); }
.key:active { background: var(--surface-2); }
.key.fn { color: var(--muted); }
.key.op { color: var(--accent); background: var(--surface-2); }
.key.eq { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- Уведомления ---------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(90px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; pointer-events: none; z-index: 50; padding: 0 16px; }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; max-width: 460px; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); }
.toast.err { border-color: var(--danger); color: var(--danger); }

/* ---------- Адаптивность ---------- */
@media (max-width: 820px) {
  .shell { display: block; }
  .side {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: auto; z-index: 20;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line); background: var(--surface);
  }
  .side .wordmark { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-btn { flex: 1; flex-direction: column; justify-content: center; gap: 2px; min-height: 52px; padding: 4px 2px; font-size: 11.5px; text-align: center; }
  .main { padding-bottom: 110px; }
  .topbar h1 { font-size: 26px; }
  .stats { grid-template-columns: 1fr; }
  .stat { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
  .stat-value { margin-top: 0; }
  .actions { grid-template-columns: 1fr 1fr; }
  .onboard-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 96px 1fr auto; }
}
@media (max-width: 520px) {
  .form-grid { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr 84px; }
  .inline-form .btn { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- Обновление 2: вкладки, цели, повторяющиеся ---------- */
.tabs.three { grid-template-columns: repeat(3, 1fr); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.bar.good > i { background: var(--income); }
.goal-nums { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; font-weight: 600; }
.icon-btn.edit:hover { color: var(--accent); }
@media (max-width: 520px) {
  .tabs.three .tab { font-size: 14px; padding: 0 4px; }
}
