/* app.css — оформление кабинета (build 4).

   Палитра брендовая, унаследована от питч-дека: кабинет и презентации должны
   читаться одним продуктом. Она своя, а не из `themeParams` Telegram:
   приложение открывают и в браузере с компьютера, где никаких параметров темы
   нет, — вид должен совпадать. От Telegram берётся только светло/темно
   (`colorScheme` → data-theme на <html>, ставится в index.html до отрисовки).

   Основная тема — тёмная; светлая нужна для браузера с компьютера. Цвета
   записей и колеса живут в `app.js` (KINDS и RING) — там же, где рисуются
   точки и сектора.

   Разметка — потоком, без сеточных фреймворков: экран узкий, всё в одну колонку.

   Отступы держатся на margin'ах, а не на `gap` у флексов (build 4). Во
   встроенных браузерах постарше flex-gap не поддерживается: он молча
   отбрасывается, и карточки слипаются краями — скругления соседей смыкаются и
   читаются как одна съехавшая фигура. Grid-gap умеют все, поэтому у сетки
   месяца (`.dow`, `.grid`) он остался; **новый флекс-ряд разводи `margin`'ом**
   (`> * + *`), а не `gap`. Величины — две: `--gap` между соседями в ряду,
   `--block` между блоками сверху вниз. */

/* Светлая тема. */
:root {
  --bg: #FBFAF7;
  --card: #FFFFFF;
  --sunk: #F2F0EA;        /* подложка: нажатая строка, тихий фон */
  --ink: #14352E;
  --muted: #5C7069;
  --dim: #8FA098;         /* третий по тихости: дни недели, легенда */
  --line: #DFDCD2;
  --accent: #1F7C6A;
  --on-accent: #FFFFFF;   /* текст на акценте */
  --ok: #1F7C6A;          /* доход */
  --bad: #C24A30;         /* расход: на светлом нужен контраст потемнее */
  --shadow: 0 1px 2px rgba(20, 53, 46, .06), 0 6px 18px rgba(20, 53, 46, .05);
  --radius: 14px;
  --pad: 16px;
  --gap: 8px;      /* между соседями в ряду: карточки сводки, кнопки */
  --block: 12px;   /* между блоками сверху вниз: карточка, ряд, шапка */
}

/* Тёмная тема — основная. */
:root[data-theme="dark"] {
  --bg: #0E2620;
  --card: #14352E;
  --sunk: #1C453B;
  --ink: #F0EFEA;
  --muted: #9DB3AC;
  --dim: #6B8880;
  --line: #27564A;
  --accent: #2E9E88;
  --on-accent: #06231C;
  --ok: #2E9E88;
  --bad: #D95A3F;
  --shadow: none;
}

* { box-sizing: border-box; }

/* Шрифты брендовые и системные: заголовки — Georgia (кириллица в ней есть на
   всех платформах, везти файлы незачем), текст — Arial, служебное —
   моноширинным. Ничего не загружаем: у мини-приложения и без того первый
   экран должен появляться сразу. */
:root {
  --font-head: Georgia, "Times New Roman", serif;
  --font-text: Arial, Helvetica, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font-text);
  -webkit-text-size-adjust: 100%;
}

/* Заголовки — Georgia. Суммы и прочие числа остаются в тексте: им нужны
   ровные табличные цифры (tabular-nums), а не засечки. */
.head h1, .card > h2, .login-title, .monthbar .name, .wheel-center {
  font-family: var(--font-head);
}

body {
  min-height: 100vh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

a { color: var(--accent); }

.hidden { display: none !important; }

.screen { padding: var(--pad); max-width: 720px; margin: 0 auto; }

.center {
  min-height: 70vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
}
.center > * + * { margin-top: var(--block); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ── Кнопки и поля ──────────────────────────────────────────────────────── */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent);
  font-size: 16px; font-weight: 600;
  padding: 12px 20px; border-radius: 12px;
  min-height: 46px;
}
.btn:active { opacity: .85; }
.btn[disabled] { opacity: .5; cursor: default; }

.btn-quiet {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); font-weight: 500;
}

.code {
  display: block; width: 100%; margin: 18px 0 12px;
  font-size: 30px; letter-spacing: .35em; text-align: center;
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.code:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.login-title { font-size: 22px; margin: 8px 0; }
#login { max-width: 380px; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ── Шапка ──────────────────────────────────────────────────────────────── */
.head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: var(--block);
}
.head > * + * { margin-left: var(--block); }
.head h1 { font-size: 20px; margin: 0; font-weight: 700; }
.head .sub { font-size: 13px; color: var(--muted); }

/* ── Карточки ───────────────────────────────────────────────────────────── */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
  margin-bottom: var(--block);
}
.card > h2 {
  font-size: 13px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted);
  margin: 0 0 10px;
}
.card-note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

.row {
  display: flex; align-items: center;
  padding: 9px 0; border-top: 1px solid var(--line);
}
.row > * + * { margin-left: 10px; }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { display: block; overflow-wrap: anywhere; }
.row .sub { display: block; font-size: 13px; color: var(--muted); }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--sunk); }

.dot-sphere {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  background: var(--muted);
}

.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.plus { color: var(--ok); }
.amount.minus { color: var(--bad); }

/* Три числа в ряд: поступления · траты · разница. */
.stats { display: flex; margin-bottom: var(--block); }
.stat + .stat { margin-left: var(--gap); }
.stat {
  flex: 1; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 10px; text-align: center;
}
.stat .val { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Переключатель периода / месяца ─────────────────────────────────────── */
.chips {
  display: flex; overflow-x: auto; padding: 2px 0 var(--block);
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card);
  color: var(--muted); border-radius: 999px; padding: 6px 12px;
  font-size: 14px; cursor: pointer;
}
.chip + .chip { margin-left: 6px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.monthbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--block);
}
.monthbar > * + * { margin-left: var(--gap); }
.monthbar .name { font-weight: 600; font-variant-numeric: tabular-nums; }
.nav-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; width: 38px; height: 38px; font-size: 18px; cursor: pointer;
}

/* ── Сетка месяца ───────────────────────────────────────────────────────── */
.dow, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow div { text-align: center; font-size: 12px; color: var(--dim); padding-bottom: 4px; }

.cell {
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow);
  min-height: 52px; padding: 5px 4px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  border: 1px solid transparent;
  /* Тап по клетке — это тап, а не выделение числа. Во встроенном браузере
     Telegram палец, задержавшийся на тексте, начинает выделение, и click до
     клетки уже не доходит: день «не открывается». touch-action убирает ещё и
     паузу на ожидание двойного тапа. */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; touch-action: manipulation;
}
/* Отклик на палец: день выбирается без обращения к серверу, и подтверждение
   должно быть таким же мгновенным. */
.cell:active { transform: scale(0.97); border-color: var(--accent); }
.cell.blank { background: transparent; box-shadow: none; cursor: default; }
.cell.blank:active { transform: none; border-color: transparent; }
.cell.today .num { color: var(--accent); font-weight: 700; }
.cell.on { border-color: var(--accent); }
.cell .num { font-size: 14px; font-variant-numeric: tabular-nums; }
.cell .dots { display: flex; flex-wrap: wrap; justify-content: center; margin-top: 3px; }
.cell .dots i { width: 5px; height: 5px; border-radius: 50%; display: block; margin: 1px; }

.legend { display: flex; flex-wrap: wrap; margin: var(--block) 0; }
.legend span { font-size: 12px; color: var(--dim); display: flex; align-items: center;
               margin: 0 10px 4px 0; }
.legend i { width: 7px; height: 7px; border-radius: 50%; display: block; margin-right: 4px; }

/* ── Колёса ─────────────────────────────────────────────────────────────── */
.wheel { display: flex; justify-content: center; padding: 4px 0 var(--block); }
.wheel svg { width: 220px; height: 220px; max-width: 100%; }
.wheel-center { font-size: 15px; font-weight: 700; fill: var(--ink); }
.wheel-sub { font-size: 11px; fill: var(--muted); }

.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }

.score { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

/* ── Нижнее меню ────────────────────────────────────────────────────────── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 8px 2px 10px; font-size: 11px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
}
.tabs button .ic { font-size: 20px; line-height: 1; margin-bottom: 2px; }
.tabs button.on { color: var(--accent); }

/* Полоска «обновляю» под шапкой — вместо подмены экрана спиннером. */
.loading-line {
  height: 2px; background: var(--accent); border-radius: 2px;
  animation: pulse 1s ease-in-out infinite; margin-bottom: var(--block);
}
@keyframes pulse { 50% { opacity: .25; } }

.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }

/* Кнопки, по которым тыкают пальцем: без паузы на двойной тап и без выделения
   подписи вместо нажатия (см. пояснение у .cell). */
.chip, .tabs button, .nav-btn, .btn {
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}

/* Полоска на случай сбоя вне отрисовки: во встроенном браузере ошибку иначе
   не видно — страница просто замирает. */
.fatal {
  position: fixed; left: 8px; right: 8px; z-index: 20;
  bottom: calc(64px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 10px 12px; font-size: 14px;
}
.fatal .btn { width: auto; padding: 6px 12px; font-size: 14px; margin-left: 10px; }
