/* Мини-приложение. Цвета — только переменные темы Telegram с запасными значениями на старые
   версии (rules/design.md); единственное исключение — оттенок значка категории, он приходит с
   сервера в --tint. Никаких градиентов, теней и рамок: пилот владелец назвал «некрасиво, дёшево».
   Скрипт Telegram сам обновляет переменные при смене темы, поэтому цвета нигде не кешируем. */
:root {
  --c-page: var(--tg-theme-secondary-bg-color, var(--tg-theme-bg-color, #f0f0f5));
  --c-section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --c-text: var(--tg-theme-text-color, #000000);
  --c-hint: var(--tg-theme-hint-color, #8e8e93);
  --c-sub: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #6d6d72));
  --c-accent: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #007aff));
  --c-button: var(--tg-theme-button-color, #007aff);
  --c-button-text: var(--tg-theme-button-text-color, #ffffff);
  --c-sep: var(--tg-theme-section-separator-color, var(--tg-theme-secondary-bg-color, #d9d9de));
  /* Без color-mix (старый WebView) — подпись темы: она всегда темнее подсказки. */
  --c-caption: var(--c-sub);
  --c-prev: var(--c-sub);
  --c-soft: var(--c-sep);
  --inset-top: calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --inset-right: calc(var(--tg-safe-area-inset-right, env(safe-area-inset-right, 0px)) + var(--tg-content-safe-area-inset-right, 0px));
  --inset-bottom: calc(var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
  --inset-left: calc(var(--tg-safe-area-inset-left, env(safe-area-inset-left, 0px)) + var(--tg-content-safe-area-inset-left, 0px));
}

/* Обычно --c-caption и --c-prev задаёт tg.js: считает наименьшую долю цвета текста для контраста
   на палитре этой темы. Ниже — запасные значения на случай, когда в теме нет нужных цветов:
   серая линия с долей цвета текста в светлых темах, сама подсказка в тёмных. */
@supports (color: color-mix(in srgb, red, blue)) {
  :root {
    --c-caption: color-mix(in srgb, var(--c-sub) 90%, var(--c-text));
    --c-prev: color-mix(in srgb, var(--c-hint) 85%, var(--c-text));
    --c-soft: color-mix(in srgb, var(--c-hint) 14%, transparent);
  }
}

:root[data-scheme="dark"] { --c-prev: var(--c-hint); }

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: var(--tg-color-scheme, light);
}

body {
  margin: 0;
  background: var(--c-page);
  color: var(--c-text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  /* Долгое нажатие на iPhone выделяло текст и в раскрытой записи (05.11): экран — не документ. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input { -webkit-user-select: text; user-select: text; }

h1, h2, p { margin: 0; font: inherit; }
/* Явно и у кнопок: на iPhone 05.11 проверено именно это правило, наследование от body — нет. */
button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
[hidden] { display: none !important; }
.screen:focus { outline: none; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--inset-top) + 4px) calc(var(--inset-right) + 16px) calc(var(--inset-bottom) + 24px) calc(var(--inset-left) + 16px);
}

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.chevron { display: block; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Месяц */
.month {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  margin: 0 -14px;
}
.month-title { font-size: 17px; font-weight: 600; text-align: center; min-width: 0; overflow-wrap: anywhere; }
.nav, .nav-gap { flex: none; width: 44px; height: 44px; }
.nav {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--c-caption);
  cursor: pointer;
}

/* Сумма и сравнение. Высота блока общая для загрузки и данных: линия ниже не сдвигается. */
.hero-block { min-height: 106px; }
.hero, .hero-sk { margin: 6px 0 2px; min-height: 52px; }
.hero {
  font-size: 48px;
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -.02em;
  overflow-wrap: anywhere;
}
.hero-m { font-size: 40px; line-height: 52px; }
.hero-s { font-size: 32px; line-height: 40px; }
.cap { font-size: 14px; color: var(--c-caption); overflow-wrap: anywhere; }
.delta { margin-top: 6px; font-size: 14px; overflow-wrap: anywhere; }
.delta b { font-weight: 600; }
.since { color: var(--c-caption); }
/* Узкие телефоны: «потратили за сентябрь 2025, с учётом возвратов» в одну строку, блок не прыгает. */
@media (max-width: 360px) {
  .cap { font-size: 13px; line-height: 20px; }
}

.notice {
  margin: 0 0 10px;
  padding: 12px;
  border-radius: 14px;
  background: var(--c-section);
  font-size: 15px;
  overflow-wrap: anywhere;
}

/* Секции */
.sec { margin-top: 12px; border-radius: 14px; background: var(--c-section); overflow: hidden; }
.sech { margin: 18px 4px -6px; font-size: 13px; line-height: 18px; color: var(--c-caption); }
.sub { display: block; font-size: 13px; color: var(--c-caption); overflow-wrap: anywhere; }

/* Линия темпа */
.chart { padding: 10px 12px 10px; overflow: visible; }
.read {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  column-gap: 8px;
  min-height: 20px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 20px;
  color: var(--c-caption);
}
.read-day { overflow-wrap: anywhere; min-width: 0; }
.read-values { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0 10px; min-width: 0; margin-left: auto; }
.val { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.val-now { color: var(--c-text); font-weight: 600; }

.pace-box {
  height: clamp(150px, 44vw, 190px);
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.pace { display: block; overflow: visible; cursor: crosshair; }
.pace:focus { outline: none; }
.pace:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 4px; border-radius: 4px; }
.grid { stroke: var(--c-sep); stroke-width: 1; }
.axis-zero { stroke: var(--c-prev); stroke-width: 1; }
.area-now { fill: var(--c-button); fill-opacity: .1; }
.line-prev, .line-now { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.line-prev { stroke: var(--c-prev); stroke-width: 1.75; }
.line-now { stroke: var(--c-button); stroke-width: 2.5; stroke-dasharray: 1; }
.tick {
  font-size: 11px;
  fill: var(--c-caption);
  paint-order: stroke;
  stroke: var(--c-section);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.cross { stroke: var(--c-hint); stroke-width: 1; stroke-opacity: .55; }
.dot-today, .dot-now { fill: var(--c-button); stroke: var(--c-section); stroke-width: 2; }
.dot-prev { fill: var(--c-prev); stroke: var(--c-section); stroke-width: 2; }

.legend { display: flex; gap: 14px; min-height: 18px; margin-top: 8px; font-size: 13px; line-height: 18px; color: var(--c-caption); }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; vertical-align: 1px; }
.dot.now, .meter .now { background: var(--c-button); }
.dot.prev, .meter .prev { background: var(--c-prev); }

/* Строки */
.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 9px 12px;
  border: 0;
  background: none;
  text-align: left;
}
button.row, .more { cursor: pointer; }
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 60px;
  height: 1px;
  background: var(--c-sep);
}
button.row:active, .more:active, .nav:active { background: var(--c-soft); }
@media (hover: hover) {
  button.row:hover, .more:hover, .nav:hover { background: var(--c-soft); }
}
.ico, .chip { flex: none; width: 36px; height: 36px; display: grid; place-items: center; }
.ico { border-radius: 10px; background: var(--c-soft); font-size: 19px; line-height: 1; }
.chip { border-radius: 50%; background: var(--c-soft); color: var(--c-accent); font-size: 14px; font-weight: 600; }
.chip-other { color: var(--c-caption); }
@supports (color: color-mix(in srgb, red, blue)) {
  .ico { background: color-mix(in srgb, var(--tint, var(--c-hint)) 15%, transparent); }
  .chip { background: color-mix(in srgb, var(--c-button) 16%, transparent); }
  .chip-other { background: var(--c-soft); }
}
.grow { display: block; flex: 1; min-width: 0; }
.line { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.nm {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.am { flex: none; max-width: 60%; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.bar { display: block; min-width: 4px; height: 4px; margin-top: 6px; border-radius: 2px; background: var(--c-button); transform-origin: left; }
.more {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--c-accent);
  font-size: 15px;
  text-align: left;
}
.row + .more, .more + .more { border-top: 1px solid var(--c-sep); }

/* Самые узкие телефоны: «Кредиты и ипотека» и сумма умещаются в одну строку. Суммы с копейками
   в строке чтения могут занять две строки: место держим сразу, блок при чтении не прыгает. */
@media (max-width: 350px) {
  .read { min-height: 40px; font-size: 12px; }
  .row { gap: 10px; }
  .row + .row::before { left: 58px; }
  .line { gap: 8px; font-size: 15px; }
}

/* Кто сколько */
.pair { display: flex; justify-content: space-between; gap: 12px; padding: 12px 12px 6px; }
.pair-item { min-width: 0; }
.pair-item:last-child { text-align: right; }
.pair-am { display: block; font-weight: 600; overflow-wrap: anywhere; }
.meter { display: flex; gap: 2px; height: 8px; margin: 2px 12px 12px; }
.meter i { display: block; flex-basis: 0; min-width: 4px; border-radius: 4px; }

/* Доходы и остаток */
.tiles { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-top: 12px; }
.tile { padding: 10px 12px; border-radius: 14px; background: var(--c-section); }
.tile b { display: block; margin-top: 1px; font-size: 19px; font-weight: 600; overflow-wrap: anywhere; }
.tile .tile-long { font-size: 16px; line-height: 27px; }

/* Сумма категории: чуть меньше главной, столбики идут сразу под ней. */
.hero-block-short { min-height: 78px; }
.hero-cat { font-size: 40px; line-height: 52px; }
.hero-cat.hero-s { font-size: 32px; }

/* Шесть месяцев: выбранный — цветом кнопки, как линия месяца, остальные — серым, как прошлый месяц.
   Новые справа, поэтому выбранный всегда на одном месте.
   stretch — явно: на iOS 18 у кнопок flex-start, и без него столбики шириной 0 пропадали. */
.cols { display: flex; justify-content: flex-end; padding: 12px; }
.col {
  display: flex;
  flex: 0 0 calc(100% / 6);
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  height: 112px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
button.col:active .col-bar { opacity: .7; }
.col-plot { display: flex; flex: 1; align-items: flex-end; min-height: 0; padding: 0 8px; }
.col-bar, .sk-col { display: block; width: 100%; border-radius: 6px 6px 0 0; }
.col-bar { background: var(--c-prev); transform-origin: bottom; }
.sk-col { height: 60%; background: var(--c-soft); }
.col-label { margin-top: 4px; font-size: 12px; line-height: 18px; text-align: center; color: var(--c-caption); }
.col[aria-current] .col-bar { background: var(--c-button); }
.col[aria-current] .col-label { font-weight: 600; color: var(--c-text); }
.sk-col-label { width: 24px; height: 10px; }

/* Выбор участника: одна строка; имена не влезают — листается внутри, страница не шире экрана. */
.seg {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  padding: 2px;
  overflow-x: auto;
  border-radius: 10px;
  background: var(--c-soft);
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg-item {
  flex: 1 0 auto;
  max-width: 70%;
  min-height: 44px;
  padding: 0 14px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}
.seg-item.on { background: var(--c-section); font-weight: 600; }
/* В тёмных темах секция темнее подложки: выбранное выглядело бы вдавленным. */
:root[data-scheme="dark"] .seg-item.on { background: var(--c-soft); }

/* Записи по дням */
.day { display: flex; justify-content: space-between; gap: 12px; margin: 16px 4px -6px; font-size: 13px; line-height: 18px; color: var(--c-caption); }
.day-title { min-width: 0; overflow-wrap: anywhere; }
.day-total { flex: none; max-width: 60%; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.entry { position: relative; }
.entry + .entry::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 60px;
  z-index: 1;
  height: 1px;
  background: var(--c-sep);
}
.nm-open { display: block; }
.sub-line { align-items: center; margin-top: 1px; }
.sub-line .sub { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sub-line .chevron { color: var(--c-caption); }
.details { padding: 0 12px 12px 60px; font-size: 14px; }
.details dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 10px; margin: 0 0 6px; }
.detail { display: contents; }
.detail dt { color: var(--c-caption); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.none { margin-top: 24px; text-align: center; color: var(--c-caption); }
/* Прозрачная полоса над концом списка, по ней приходит следующая страница. */
.spot { height: 1000px; margin-top: -1000px; pointer-events: none; }
.next-page { margin-top: 12px; }

/* Короткая строка сбоя: показанное остаётся на месте. */
.failure {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--c-section);
  overflow-wrap: anywhere;
}
.failure-title { display: block; font-size: 15px; line-height: 20px; font-weight: 600; }
/* balance: на 375–390 px иначе «раз.» остаётся одно на второй строке; старый WebView правило пропустит. */
.failure-text { display: block; margin-top: 2px; font-size: 13px; line-height: 18px; color: var(--c-caption); text-wrap: balance; }
.retry { flex: none; min-height: 44px; margin: -10px -8px; padding: 0 8px; border: 0; background: none; color: var(--c-accent); font-size: 15px; cursor: pointer; }

/* Настройки */
.title { margin: 8px 4px 0; font-size: 22px; line-height: 28px; font-weight: 700; }
.settings .row + .row::before { left: 12px; }
.time-row { padding: 4px 4px 4px 12px; }
.time { font-size: 20px; font-variant-numeric: tabular-nums; }
.off-row { color: var(--c-caption); }
.remove {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--c-caption);
  cursor: pointer;
}
.remove:active { background: var(--c-soft); }
.add-row { gap: 8px; padding: 4px 4px 4px 12px; }
.time-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  border-radius: 10px;
  background: var(--c-soft);
  color: var(--c-text);
  font: inherit;
}
.add-ok { flex: none; min-height: 44px; padding: 0 4px; border: 0; background: none; color: var(--c-accent); font-size: 15px; font-weight: 600; cursor: pointer; }
.add-ok[aria-disabled] { color: var(--c-caption); }
.taken { padding: 0 12px 10px; font-size: 13px; color: var(--c-caption); }
.taken + .more { border-top: 1px solid var(--c-sep); }
.note { margin: 8px 4px 0; font-size: 13px; line-height: 18px; color: var(--c-caption); overflow-wrap: anywhere; }
.switch-row { justify-content: space-between; cursor: pointer; }
.switch {
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: var(--c-prev);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--c-section);
}
[aria-checked="true"] > .switch { background: var(--c-button); }
[aria-checked="true"] > .switch::after { left: 22px; background: var(--c-button-text); }
[aria-disabled="true"] { cursor: default; }

/* Первый день, ошибки */
.empty { padding: 64px 12px 0; text-align: center; }
.empty-short { padding-top: 40px; }
.big { font-size: 48px; line-height: 1; }
.empty h1 { margin: 14px 0 6px; font-size: 20px; font-weight: 600; line-height: 1.25; }
.empty p { margin: 0 0 20px; color: var(--c-caption); overflow-wrap: anywhere; }
.examples { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 24px; }
.ex { padding: 7px 12px; border-radius: 999px; background: var(--c-section); font-size: 14px; }
.btn {
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--c-button);
  color: var(--c-button-text);
  font-weight: 600;
  cursor: pointer;
}
.btn:active { opacity: .85; }

/* Загрузка */
.sk { display: inline-block; max-width: 100%; border-radius: 6px; background: var(--c-soft); vertical-align: middle; }
.sk-month { width: 88px; height: 18px; }
.sk-hero { width: 220px; height: 40px; border-radius: 10px; }
.sk-cap { width: 250px; height: 12px; }
.sk-delta { width: 200px; height: 12px; }
.sk-read { width: 96px; height: 12px; }
.sk-legend { width: 140px; height: 12px; }
.sk-sech { width: 72px; height: 10px; }
.sk-row { display: block; width: 100%; height: 12px; }
.busy { opacity: .55; transition: opacity .15s linear .1s; pointer-events: none; }

/* Движение: только если человек его не отключил и устройство не слабое. */
@media (prefers-reduced-motion: no-preference) {
  html:not(.calm) .line-now { animation: draw .55s ease-out; }
  html:not(.calm) .bar { animation: grow .4s ease-out; }
  html:not(.calm) .col-bar { animation: rise .4s ease-out; }
  html:not(.calm) .switch, html:not(.calm) .switch::after { transition: left .15s ease-out, background-color .15s linear; }
  html:not(.calm) .sk { animation: breathe 1.4s ease-in-out infinite; }
}
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes breathe { 50% { opacity: .55; } }
