/* Монета — оформление. Тёмная тема по умолчанию, светлая по системе. */

:root {
  --bg: #0b0d12;
  --bg-soft: #10141c;
  --card: #161b26;
  --card-2: #1d2430;
  --line: #262e3d;
  --text: #eef1f7;
  --muted: #8d97ad;
  --accent: #4c6fff;
  --accent-soft: rgba(76, 111, 255, 0.16);
  --expense: #ff5a5f;
  --income: #2fbe7e;
  --transfer: #8b93a7;
  --warn: #ffb224;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 20px;
  --tap: rgba(255, 255, 255, 0.06);
  color-scheme: dark;
}

html[data-theme='light'] {
  --bg: #f2f4f8;
  --bg-soft: #e9ecf3;
  --card: #ffffff;
  --card-2: #f4f6fa;
  --line: #e2e6ee;
  --text: #0e1220;
  --muted: #6b7385;
  --accent: #3355e8;
  --accent-soft: rgba(51, 85, 232, 0.12);
  --expense: #e5484d;
  --income: #16a06a;
  --shadow: 0 8px 24px rgba(16, 22, 40, 0.10);
  --tap: rgba(0, 0, 0, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  html:not([data-theme='dark']) {
    --bg: #f2f4f8;
    --bg-soft: #e9ecf3;
    --card: #ffffff;
    --card-2: #f4f6fa;
    --line: #e2e6ee;
    --text: #0e1220;
    --muted: #6b7385;
    --accent: #3355e8;
    --accent-soft: rgba(51, 85, 232, 0.12);
    --expense: #e5484d;
    --income: #16a06a;
    --shadow: 0 8px 24px rgba(16, 22, 40, 0.10);
    --tap: rgba(0, 0, 0, 0.05);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea { user-select: text; -webkit-user-select: text; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

input, select, textarea {
  font: inherit;
  font-size: 16px; /* iOS не зумит поля от 16px */
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}

select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%238d97ad' stroke-width='2' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 34px;
}

.hidden { display: none !important; }

/* ─────────── каркас ─────────── */

#app { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
.topbar .spacer { flex: 1; }

.month-switch {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 6px;
}
.month-switch button { padding: 4px 8px; color: var(--muted); font-size: 18px; line-height: 1; }
.month-switch .label { font-size: 14px; font-weight: 600; min-width: 96px; text-align: center; }

.view { padding: 4px 16px 20px; display: none; animation: fade 0.18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 22px 2px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title .link { margin-left: auto; color: var(--accent); font-size: 13px; text-transform: none; letter-spacing: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

/* ─────────── счета ─────────── */

.accounts {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  margin: 0 -16px;
  padding: 4px 16px 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.accounts::-webkit-scrollbar { display: none; }
.account-card {
  scroll-snap-align: start;
  flex: 0 0 auto;
  min-width: 60%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  position: relative;
  overflow: hidden;
}
.account-card::after {
  content: '';
  position: absolute;
  inset: auto -30% -60% auto;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--acc, var(--accent));
  opacity: 0.16;
  filter: blur(6px);
}
.account-card .name { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.account-card .amount { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; }
.account-card .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.account-card.total { min-width: 46%; }

/* ─────────── сводка ─────────── */

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.summary .card { padding: 14px; }
.summary .lbl { font-size: 12px; color: var(--muted); }
.summary .val { font-size: 20px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; }
.val.expense { color: var(--expense); }
.val.income { color: var(--income); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ─────────── список операций ─────────── */

.day-group { margin-top: 18px; }
.day-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  padding: 0 4px 8px;
}
.tx-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tx {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid var(--line);
  transition: background 0.15s;
}
.tx:last-child { border-bottom: 0; }
.tx:active { background: var(--tap); }
.tx .ico {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 19px;
  background: var(--card-2);
}
.tx .mid { flex: 1; min-width: 0; }
.tx .t1 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .t2 { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-size: 16px; font-weight: 700; white-space: nowrap; letter-spacing: -0.01em; }
.amt.expense { color: var(--expense); }
.amt.income { color: var(--income); }
.amt.transfer { color: var(--transfer); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 15px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 10px; opacity: 0.6; }

/* ─────────── бюджеты ─────────── */

.budget { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.budget:last-child { border-bottom: 0; }
.budget .row { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; }
.budget .row .r { color: var(--muted); font-size: 13px; }
.bar { height: 8px; border-radius: 999px; background: var(--card-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.4s ease; }
.bar > span.over { background: var(--expense); }
.bar > span.near { background: var(--warn); }

/* ─────────── графики ─────────── */

.donut-wrap { display: flex; align-items: center; gap: 16px; }
.donut { flex: 0 0 auto; }
.donut-center { text-align: center; }
.legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.legend .item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; }
.legend .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .pc { color: var(--muted); font-variant-numeric: tabular-nums; }

.cat-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-row .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--card-2); flex: 0 0 34px; }
.cat-row .mid { flex: 1; min-width: 0; }
.cat-row .nm { font-size: 14px; font-weight: 600; }
.cat-row .bar { margin-top: 6px; }
.cat-row .amt { font-size: 14px; font-weight: 700; white-space: nowrap; }

/* ─────────── нижняя навигация ─────────── */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  padding: 8px 6px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 0;
  color: var(--muted);
  font-size: 10px;
}
.tabbar button.active { color: var(--accent); }
.tabbar button svg { width: 24px; height: 24px; }
.tabbar .add {
  color: #fff;
}
.tabbar .add .fab {
  width: 46px; height: 46px;
  margin-top: -14px;
  border-radius: 16px;
  background: var(--accent);
  display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(76, 111, 255, 0.4);
}
.tabbar .add .fab svg { width: 26px; height: 26px; }

/* ─────────── шторки ─────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.22s ease;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 41;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-soft);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--line);
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: var(--shadow);
}
.sheet.open { transform: none; }
.sheet .grabber { width: 38px; height: 5px; border-radius: 999px; background: var(--line); margin: 6px auto 12px; }
.sheet h2 { font-size: 18px; margin: 0 0 12px; }
.sheet .field { margin-bottom: 12px; }
.sheet .field > label { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 6px; }
.sheet .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: block;
  width: 100%;
  padding: 15px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  text-align: center;
}
.btn:active { filter: brightness(0.92); }
.btn.secondary { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--expense); border: 1px solid var(--line); }
.btn.small { padding: 10px; font-size: 14px; border-radius: 12px; }

.segment {
  display: flex;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
}
.segment button {
  flex: 1;
  padding: 9px 4px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
.segment button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.segment button.active[data-type='expense'] { color: var(--expense); }
.segment button.active[data-type='income'] { color: var(--income); }

/* ввод суммы */
.amount-display {
  text-align: center;
  padding: 10px 0 6px;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  min-height: 56px;
}
.amount-display .cur { font-size: 22px; color: var(--muted); margin-left: 6px; }
.amount-display.expense { color: var(--expense); }
.amount-display.income { color: var(--income); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.keypad button {
  height: 54px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 22px;
  font-weight: 600;
}
.keypad button:active { background: var(--accent-soft); }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.cat-pick .ico { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 17px; background: var(--card-2); }
.cat-pick.active { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.cat-pick .nm { line-height: 1.2; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  width: 100%;
  text-align: left;
}
.list-item:last-child { border-bottom: 0; }
.list-item .ico { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--card-2); flex: 0 0 36px; }
.list-item .mid { flex: 1; min-width: 0; }
.list-item .t1 { font-size: 15px; font-weight: 600; }
.list-item .t2 { font-size: 12px; color: var(--muted); }
.list-item .chev { color: var(--muted); font-size: 20px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  z-index: 60;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--expense); color: var(--expense); }

/* ─────────── вход ─────────── */

#login {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 24px calc(env(safe-area-inset-bottom) + 24px);
}
#login .logo { font-size: 48px; text-align: center; margin-bottom: 10px; }
#login h1 { font-size: 26px; text-align: center; margin: 0 0 4px; }
#login p { text-align: center; color: var(--muted); margin: 0 0 26px; font-size: 14px; }
#login .field { margin-bottom: 12px; }
#login .err { color: var(--expense); font-size: 14px; text-align: center; min-height: 20px; margin-top: 10px; }

.offline-badge {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--warn);
  color: #1a1200;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
}

.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; padding-top: 6px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; }
.bars .b i { display: block; border-radius: 3px 3px 0 0; background: var(--expense); opacity: 0.9; min-height: 2px; }
.bars .b i.inc { background: var(--income); }
.bars-x { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 6px; }

.month-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.month-row:last-child { border-bottom: 0; }
.month-row .m { width: 74px; font-size: 13px; color: var(--muted); }
.month-row .mb { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.month-row .mb i { display: block; height: 8px; border-radius: 4px; background: var(--expense); min-width: 2px; }
.month-row .mb i.inc { background: var(--income); }
.month-row .mv { font-size: 12px; text-align: right; width: 92px; }

/* строчные элементы внутри карточек делаем блочными */
.account-card .name,
.account-card .amount,
.account-card .sub,
.tx .mid, .tx .t1, .tx .t2,
.list-item .mid, .list-item .t1, .list-item .t2,
.cat-row .mid, .cat-row .nm,
.cat-pick .ico, .cat-pick .nm { display: block; }

.summary .val { font-size: 20px; line-height: 1.25; }
.summary .val span { display: block; }
.summary .val span + span { font-size: 15px; opacity: 0.85; margin-top: 2px; }

/* кнопки-строки должны занимать всю ширину (иначе браузер сжимает их по содержимому) */
.cat-row, .month-row, .budget, .tx, .list-item { width: 100%; }
.bar, .cat-row .bar, .budget .bar { display: block; width: 100%; }
.cat-row .bar { margin-top: 7px; height: 6px; }
.cat-row .amt { margin-left: auto; padding-left: 10px; }
.month-row .mb i { display: block; }
.cat-row, .month-row { text-align: left; }
.cat-row .nm, .month-row .m { text-align: left; }
.cat-grid > * { min-width: 0; }
.sheet .chips { margin: 0 -2px; padding: 2px; }

.sheet-actions {
  position: sticky;
  bottom: 0;
  margin: 14px -16px 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 6px);
  background: linear-gradient(to top, var(--bg-soft) 86%, transparent);
  border-top: 1px solid transparent;
}

/* ─────────── вкладки счетов ─────────── */

.acc-tabs {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 46px);
  z-index: 19;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  scrollbar-width: none;
}
.acc-tabs::-webkit-scrollbar { display: none; }
.acc-tab {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}
.acc-tab .ic { font-size: 15px; }
.acc-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.acc-tab.add { padding: 9px 14px; color: var(--muted); font-weight: 400; }

/* ─────────── карточка баланса ─────────── */

.balance-card {
  position: relative;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  margin-top: 4px;
}
.balance-card::after {
  content: '';
  position: absolute;
  inset: auto -20% -70% auto;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: var(--acc, var(--accent));
  opacity: 0.14;
  filter: blur(4px);
}
.balance-card .ttl { font-size: 14px; color: var(--muted); }
.balance-card .sum { font-size: 34px; font-weight: 700; letter-spacing: -0.03em; margin-top: 8px; }
.balance-card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
