/* ============ Токены: палитра в духе Т-Банка. Светлая/тёмная — по теме Telegram или системы ============ */
:root {
  --bg: #f6f7f8;
  --card: #ffffff;
  --card-2: #f6f7f8;          /* вложенные поля, неактивные чипы */
  --text: #333333;
  --text-strong: #000000;
  --hint: #9299a2;
  --sep: rgba(0, 16, 61, 0.08);
  --brand: #ffdd2d;           /* жёлтый */
  --brand-press: #fcc521;
  --on-brand: #333333;
  --link: #336fee;
  --ink: #333333;             /* активная вкладка, чёрный чип */
  --on-ink: #ffffff;
  --ok: #00b92d;
  --warn: #ff8a00;
  --danger: #f52222;
  --skel: rgba(0, 16, 61, 0.06);
  --shadow: 0 2px 12px rgba(0, 16, 61, 0.06);
  --bar: #dde0e4;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f0f0f;
  --card: #1c1c1e;
  --card-2: #2a2a2d;
  --text: #f2f2f2;
  --text-strong: #ffffff;
  --hint: #8e8e93;
  --sep: rgba(255, 255, 255, 0.08);
  --link: #5c8eff;
  --ink: #f2f2f2;
  --on-ink: #000000;
  --skel: rgba(255, 255, 255, 0.06);
  --shadow: none;
  --bar: #3a3a3d;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0f; --card: #1c1c1e; --card-2: #2a2a2d; --text: #f2f2f2; --text-strong: #ffffff;
    --hint: #8e8e93; --sep: rgba(255, 255, 255, 0.08); --link: #5c8eff; --ink: #f2f2f2; --on-ink: #000000;
    --skel: rgba(255, 255, 255, 0.06); --shadow: none; --bar: #3a3a3d; color-scheme: dark;
  }
}
:root {
  --ok-soft: color-mix(in srgb, var(--ok) 13%, transparent);
  --warn-soft: color-mix(in srgb, var(--warn) 15%, transparent);
  --danger-soft: color-mix(in srgb, var(--danger) 12%, transparent);
  --brand-soft: color-mix(in srgb, var(--brand) 30%, transparent);
  --r: 24px;
  --r-sm: 20px;
  --r-btn: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tabbar-h: 64px;
}

/* ============ База ============ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); font-size: 16px; line-height: 1.3;
  color: var(--text); background: var(--bg);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain; -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
b, strong { font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }
.hint { color: var(--hint); font-size: 14px; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .danger { color: var(--danger); } .accent { color: var(--link); }

.app { max-width: 600px; margin: 0 auto; padding: 8px 12px calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); }

/* ============ Шапка ============ */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 4px 14px; }
h1 { font-size: 28px; font-weight: 800; margin: 0; letter-spacing: -0.5px; color: var(--text-strong); }
.sub { color: var(--hint); font-size: 14px; margin-top: 2px; }
.icon-btn {
  position: relative; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--card); color: var(--text-strong); box-shadow: var(--shadow);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.is-spinning svg { animation: spin .8s linear infinite; }
.sync-dot { position: absolute; top: 5px; right: 5px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--card); display: none; }
.sync-dot.is-pending { display: block; background: var(--warn); }
.sync-dot.is-error { display: block; background: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Нижняя навигация ============ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--sep);
}
.tabbar-item {
  flex: 1 1 0; max-width: 120px; border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px 4px;
  color: var(--hint); font-size: 11px; font-weight: 500; cursor: pointer;
}
.tabbar-item svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar-item svg .fill { fill: currentColor; stroke: none; }
.tabbar-item.is-active { color: var(--text-strong); font-weight: 600; }
.tabbar-item:active { transform: scale(.94); }

/* ============ Карточки ============ */
.card { background: var(--card); border-radius: var(--r); padding: 18px; margin-bottom: 10px; box-shadow: var(--shadow); }
.card.list { padding: 6px 18px; }
.card.tight { padding: 14px 18px; }
.card h2 { font-size: 20px; font-weight: 800; margin: 0 0 6px; letter-spacing: -0.3px; color: var(--text-strong); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.empty { text-align: center; color: var(--hint); padding: 28px 16px; }
.empty .big { font-size: 36px; margin-bottom: 8px; }
.error { color: var(--danger); }
.section-title { font-size: 20px; font-weight: 800; color: var(--text-strong); letter-spacing: -0.3px; margin: 22px 6px 10px; }
.section-title:first-child { margin-top: 4px; }
.section-title.danger { color: var(--danger); }

/* Главная карточка — жёлтая, как карта */
.hero { position: relative; overflow: hidden; background: var(--brand); color: var(--on-brand); box-shadow: none; padding: 20px; }
.hero::after {
  content: ""; position: absolute; right: -50px; bottom: -80px; width: 220px; height: 220px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.28); pointer-events: none;
}
.hero .hero-label { font-size: 14px; font-weight: 500; opacity: .75; position: relative; }
.hero .hero-amount { font-size: 36px; font-weight: 800; letter-spacing: -1px; line-height: 1.1; margin: 6px 0 4px; color: #000; position: relative; }
.hero .hero-sub { font-size: 14px; opacity: .8; position: relative; }
.hero .hero-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; position: relative; }
.hero .hero-right { text-align: right; font-size: 13px; opacity: .85; }
.hero .hero-right b { display: block; font-size: 20px; color: #000; opacity: 1; }
.hero .progress { background: rgba(0, 0, 0, .1); position: relative; }
.hero .progress > i { background: #333; }
.hero .progress-label { color: rgba(0, 0, 0, .65); position: relative; }
.hero .pill { background: rgba(0, 0, 0, .08); color: #333; }
.hero .stack { position: relative; }
.hero .legend { color: rgba(0, 0, 0, .7); position: relative; }
.hero .legend i, .hero .stack i { box-shadow: inset 0 0 0 1.5px rgba(0, 0, 0, .18); }

/* Плитки */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.tile { background: var(--card); border-radius: var(--r-sm); padding: 14px 16px 16px; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; min-height: 104px; }
.tile:active { transform: scale(.98); }
.tile .t-ico { width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; margin-bottom: auto; }
.tile .t-label { font-size: 13px; color: var(--hint); margin-top: 10px; }
.tile .t-value { font-size: 19px; font-weight: 800; margin-top: 2px; letter-spacing: -0.3px; color: var(--text-strong); }
.tile .t-value.danger { color: var(--danger); }
.tile .t-sub { font-size: 12px; color: var(--hint); margin-top: 2px; }

.stat-big { font-size: 32px; font-weight: 800; letter-spacing: -0.8px; color: var(--text-strong); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--card-2); color: var(--text); vertical-align: middle; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }

.progress { height: 6px; border-radius: 3px; background: var(--card-2); margin: 14px 0 6px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 3px; transition: width .35s cubic-bezier(.2,.8,.2,1); }
.progress-label { font-size: 13px; color: var(--hint); }

.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 11px 0; border-top: 1px solid var(--sep); }
.kv:first-child { border-top: 0; padding-top: 2px; }
.kv .k { color: var(--hint); font-size: 15px; }
.kv .k small { display: block; font-size: 12px; margin-top: 1px; }
.kv .v { font-weight: 600; text-align: right; color: var(--text-strong); }
.kv .v.big { font-weight: 800; font-size: 19px; }
.kv .v.ok { color: var(--ok); } .kv .v.warn { color: var(--warn); } .kv .v.danger { color: var(--danger); }
.note { color: var(--hint); font-size: 14px; margin-top: 6px; }

/* ============ Список операций ============ */
.day { display: flex; align-items: center; gap: 8px; padding: 14px 0 4px; font-size: 15px; font-weight: 700; color: var(--text-strong); }
.day .day-sum { margin-left: auto; font-weight: 500; font-size: 14px; color: var(--hint); }
.row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 10px 0; min-height: 60px; border: 0; background: transparent;
  text-align: left; cursor: pointer; transition: opacity .15s;
}
.row:active { opacity: .55; }
.row[disabled] { opacity: .5; cursor: default; }
.row.static { cursor: default; }
.row.static:active { opacity: 1; }
.avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; color: #fff; letter-spacing: -0.3px;
}
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.row-main { flex: 1; min-width: 0; }
.name { display: block; font-size: 16px; font-weight: 500; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bank { display: block; font-size: 14px; color: var(--hint); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount { font-weight: 600; white-space: nowrap; color: var(--text-strong); }
.amount.plus { color: var(--ok); }
.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--bar);
  position: relative; transition: background .18s, border-color .18s;
}
.check::after {
  content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px;
  border: solid #333; border-width: 0 2.4px 2.4px 0; transform: rotate(45deg) scale(0); transition: transform .18s cubic-bezier(.3,1.6,.5,1);
}
.is-paid .check { background: var(--brand); border-color: var(--brand); }
.is-paid .check::after { transform: rotate(45deg) scale(1); }
.is-paid .name { color: var(--hint); }
.is-paid .amount { color: var(--hint); font-weight: 500; text-decoration: line-through; }
.is-paid .avatar { filter: grayscale(.6); opacity: .55; }
.row.overdue .check { border-color: var(--danger); }

/* ============ Кнопки ============ */
.btn {
  display: block; width: 100%; border: 0; border-radius: var(--r-btn);
  padding: 16px; font-size: 16px; font-weight: 600; cursor: pointer;
  background: var(--brand); color: var(--on-brand); margin-top: 10px; transition: transform .1s, background .15s;
}
.btn:active { background: var(--brand-press); transform: scale(.98); }
.btn.secondary { background: var(--card); color: var(--link); box-shadow: var(--shadow); }
.btn.secondary:active { background: var(--card-2); }
.btn.ghost { background: transparent; color: var(--link); padding: 12px; font-weight: 500; box-shadow: none; }
.btn.ok { background: var(--brand); color: var(--on-brand); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; }
.sheet .btn.secondary { background: var(--card-2); box-shadow: none; }

/* Чипы */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 2px 12px 12px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 0; border-radius: 999px; padding: 9px 14px;
  background: var(--card); color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow);
}
.chip.is-active { background: var(--ink); color: var(--on-ink); }
.chip small { opacity: .65; }
.chip .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-left: 6px; vertical-align: middle; }

/* ============ Календарь ============ */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-nav h2 { margin: 0; font-size: 20px; }
.cal-nav button { border: 0; background: var(--card-2); color: var(--text-strong); width: 38px; height: 38px; border-radius: 50%; font-size: 20px; cursor: pointer; line-height: 1; }
.cal-nav button:active { transform: scale(.92); }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 6px; }
.cal-week span { text-align: center; font-size: 12px; font-weight: 500; color: var(--hint); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day {
  aspect-ratio: 1 / 1.15; border: 0; border-radius: 14px; background: transparent; padding: 4px 2px 3px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.cal-day .d { font-size: 15px; font-weight: 500; width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--text-strong); }
.cal-day.is-today .d { background: var(--card-2); font-weight: 800; }
.cal-day.is-selected .d { background: var(--ink); color: var(--on-ink); }
.cal-day.is-other { opacity: .3; }
.cal-day.is-weekend .d { color: var(--danger); }
.cal-day.is-selected.is-weekend .d { color: var(--on-ink); }
.cal-day .s { font-size: 10px; font-weight: 700; line-height: 1; padding: 2px 4px; border-radius: 6px; }
.cal-day .s.unpaid { background: var(--brand); color: #333; }
.cal-day .s.paid { color: var(--hint); text-decoration: line-through; }
.cal-day .s.due { background: var(--danger-soft); color: var(--danger); }
.cal-day .dots { display: flex; gap: 2px; height: 5px; }
.cal-day .dots i { width: 5px; height: 5px; border-radius: 50%; }
.cal-day .dots i.pay { background: var(--ok); }
.cal-legend { display: flex; gap: 14px; font-size: 12px; color: var(--hint); margin-top: 12px; flex-wrap: wrap; }
.cal-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ============ Графики ============ */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar { fill: var(--bar); }
.chart .bar.paid { fill: var(--brand); }
.chart .bar.current { fill: var(--ink); }
.chart .bar.paid.current { fill: var(--brand); }
.chart .bar.future { opacity: .55; }
.chart .income { fill: none; stroke: var(--ok); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .income-dot { fill: var(--ok); }
.chart .lbl { fill: var(--hint); font-size: 10px; font-family: var(--font); }
.chart .lbl.cur { fill: var(--text-strong); font-weight: 700; }
.chart .val { fill: var(--text-strong); font-size: 9.5px; font-family: var(--font); font-weight: 700; }
.chart .grid { stroke: var(--sep); stroke-width: 1; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--hint); margin-top: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

/* Долги */
.debt-row { padding: 12px 0; }
.debt-row + .debt-row { border-top: 1px solid var(--sep); }
.debt-head { display: flex; align-items: center; gap: 14px; }
.debt-bar { height: 4px; border-radius: 2px; background: var(--card-2); margin: 10px 0 0 50px; overflow: hidden; }
.debt-bar > i { display: block; height: 100%; border-radius: 2px; }
.debt-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--hint); margin: 5px 0 0 50px; }
.debt-meta span:last-child { white-space: nowrap; }
.stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: 14px 0 4px; gap: 2px; }
.stack i { display: block; height: 100%; min-width: 3px; }

/* История */
.ev { display: flex; gap: 14px; align-items: center; padding: 10px 0; }
.ev-ico { flex: none; width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 19px; background: var(--card-2); }
.ev-ico.paid { background: var(--brand-soft); } .ev-ico.deposit { background: var(--warn-soft); } .ev-ico.received { background: var(--ok-soft); }
.ev-main { flex: 1; min-width: 0; }
.ev-title { display: block; font-size: 16px; font-weight: 500; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-sub { display: block; font-size: 14px; color: var(--hint); margin-top: 1px; }
.ev-amt { font-weight: 600; white-space: nowrap; color: var(--text-strong); }
.ev-amt.plus { color: var(--ok); }
.ev-amt.minus { color: var(--hint); font-weight: 500; text-decoration: line-through; }

.sync-card { display: flex; align-items: center; gap: 14px; }
.sync-card .status-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--ok); flex: none; }
.sync-card .status-dot.pending { background: var(--warn); }
.sync-card .status-dot.error { background: var(--danger); }

/* ============ Форма ============ */
.field {
  width: 100%; border: 0; border-radius: var(--r-btn); padding: 16px;
  font: inherit; font-size: 17px; color: var(--text-strong); background: var(--card-2); margin-top: 10px; outline: none;
  box-shadow: inset 0 0 0 1.5px transparent; transition: box-shadow .15s;
}
.field::placeholder { color: var(--hint); }
.field:focus { box-shadow: inset 0 0 0 1.5px var(--link); }

/* ============ Нижняя шторка ============ */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .5); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease-out; }
.sheet-backdrop[hidden], .toast[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 600px; background: var(--card); color: var(--text);
  border-radius: 28px 28px 0 0; padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  animation: slide .22s cubic-bezier(.2,.8,.2,1);
}
.sheet::before { content: ""; display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--bar); margin: 0 auto 16px; }
.sheet h3 { margin: 0 0 6px; font-size: 22px; font-weight: 800; letter-spacing: -0.3px; color: var(--text-strong); }
.sheet p { margin: 0 0 8px; color: var(--hint); }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(40px); opacity: .5; } }

/* ============ Скелет, тост ============ */
.skel { background: var(--skel); border-radius: 8px; height: 16px; margin: 10px 0; animation: pulse 1.2s ease-in-out infinite; }
.skel.w30 { width: 30%; } .skel.w50 { width: 50%; } .skel.w70 { width: 70%; } .skel.w90 { width: 90%; } .skel.tall { height: 34px; }
@keyframes pulse { 50% { opacity: .45; } }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%); max-width: calc(100% - 32px); z-index: 30;
  background: #333; color: #fff; padding: 12px 18px; border-radius: 16px;
  font-size: 15px; font-weight: 500; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: fade .15s;
}
.toast.error { background: var(--danger); }
.toast.ok { background: #333; }

.fade-in { animation: fadein .25s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
