/* Оформление мини-аппа Vespier.
 *
 * ВСЁ ЧЕРЕЗ ПЕРЕМЕННЫЕ, И ЭТО НЕ ПЕДАНТИЗМ
 *
 * Дизайнерша даёт палитру и шрифт — меняются значения в этом блоке, вёрстка не
 * трогается. Если хоть один цвет вписать в правило руками, переодевание
 * превратится в поиск по всем файлам.
 *
 * ТЕМА БЕРЁТСЯ У ТЕЛЕГРАМА
 *
 * Телеграм отдаёт мини-аппу цвета своей темы, и пользователь переключает её
 * когда захочет. Поэтому основа — переменные телеграма, а наши значения стоят
 * запасными: приложение выглядит родным в обеих темах без единой строки
 * условий, и не ломается, если открыть его вне телеграма.
 */

:root {
  --bg:        var(--tg-theme-bg-color, #ffffff);
  --bg-2:      var(--tg-theme-secondary-bg-color, #f4f4f5);
  --ink:       var(--tg-theme-text-color, #1a1a1a);
  --ink-2:     var(--tg-theme-hint-color, #7d7d85);
  --link:      var(--tg-theme-link-color, #2a78d6);
  --btn:       var(--tg-theme-button-color, #2a78d6);
  --btn-ink:   var(--tg-theme-button-text-color, #ffffff);
  --rule:      color-mix(in srgb, var(--ink) 12%, transparent);

  /* Смысловые цвета. Не из темы телеграма: вход и выход обязаны читаться
     одинаково у всех, иначе решение зависит от того, какую тему человек
     выбрал. */
  --in:        #1f8f5f;
  --out:       #c8503a;
  --silent:    var(--ink-2);

  --pad:       16px;
  --radius:    12px;
  --f: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --f-num: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f);
  font-size: 16px;
  line-height: 1.45;
  /* Безопасные поля телеграма: сверху шапка, снизу системная полоса. */
  padding: env(safe-area-inset-top) 0 calc(64px + env(safe-area-inset-bottom));
}

/* ---------- общее ---------- */

.wrap { padding: 0 var(--pad); }

.muted { color: var(--ink-2); }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }

h1 { font-size: 22px; font-weight: 700; margin: 18px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 15px; font-weight: 600; margin: 22px 0 8px; }

.sub { color: var(--ink-2); font-size: 13px; margin: 0 0 14px; }

button, .btn {
  font: inherit; border: 0; cursor: pointer;
  background: var(--btn); color: var(--btn-ink);
  padding: 13px 18px; border-radius: var(--radius); width: 100%;
  font-weight: 600;
}
button:disabled { opacity: .45; cursor: default; }
.btn-quiet {
  background: var(--bg-2); color: var(--ink);
}

/* ---------- экраны ---------- */

.screen { display: none; }
.screen.on { display: block; }

/* ---------- состояния ---------- */

.state {
  padding: 48px var(--pad); text-align: center; color: var(--ink-2); font-size: 15px;
}
.state b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 6px; }

/* ---------- список бумаг ---------- */

.group-title {
  font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-2); margin: 20px 0 6px;
}
.group-title .count { font-weight: 500; }

.row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  align-items: center; padding: 11px 0; border-bottom: 1px solid var(--rule);
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row .tk { font-weight: 600; font-size: 16px; }
.row .nm { grid-column: 1; font-size: 13px; color: var(--ink-2);
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .px { text-align: right; font-weight: 600; }
.row .ch { grid-column: 2; text-align: right; font-size: 13px; }
.up { color: var(--in); }
.down { color: var(--out); }

.pill {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px;
  border-radius: 6px; letter-spacing: .03em; vertical-align: 1px; margin-left: 6px;
}
.pill.in  { background: color-mix(in srgb, var(--in) 16%, transparent);  color: var(--in); }
.pill.out { background: color-mix(in srgb, var(--out) 16%, transparent); color: var(--out); }

/* ---------- карточка бумаги ---------- */

.card-head { padding: 16px 0 4px; }
.price { font-size: 34px; font-weight: 700; letter-spacing: -0.03em; }
.price-meta { font-size: 13px; color: var(--ink-2); margin-top: 2px; }

.verdict {
  background: var(--bg-2); border-radius: var(--radius);
  padding: 14px; margin: 14px 0;
}
.verdict .line { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 3px 0; }
.verdict .line span:last-child { color: var(--ink-2); text-align: right; }
.verdict .stamp { font-size: 12px; color: var(--ink-2); margin-top: 8px; }

/* ---------- фильтры ленты ---------- */

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 12px; }
.filters button {
  width: auto; flex: none; padding: 7px 13px; font-size: 13px; font-weight: 500;
  background: var(--bg-2); color: var(--ink); border-radius: 999px;
}
.filters button.on { background: var(--btn); color: var(--btn-ink); }

/* ---------- событие ---------- */

.event { padding: 13px 0; border-bottom: 1px solid var(--rule); }
.event:last-child { border-bottom: 0; }
.event .top { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--ink-2); }
.event .txt { margin: 5px 0 0; font-size: 15px; }
.event a { color: var(--link); text-decoration: none; font-size: 13px; }
.event .tag {
  font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 5px;
  background: var(--bg-2); color: var(--ink-2);
}
.event.major .tag { background: color-mix(in srgb, var(--out) 15%, transparent); color: var(--out); }

/* ---------- тарифы ---------- */

.plan {
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.plan.current { border-color: var(--btn); }
.plan .name { font-weight: 600; }
.plan .price-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
.plan .was { color: var(--ink-2); text-decoration: line-through; font-size: 13px; margin-right: 6px; }

/* Покупка: три шага — набор бумаг, срок, сами бумаги. Каждый шаг отделён
   заголовком, потому что иначе шестнадцать тарифов сливаются в один список. */

.step-title {
  font-size: 13px; color: var(--ink-2); margin: 18px 0 8px;
  display: flex; justify-content: space-between; align-items: baseline;
}
.step-title .count { font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  padding: 12px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--bg); color: var(--ink); font: inherit; cursor: pointer;
  width: 100%;
}
.tile.active { border-color: var(--btn); box-shadow: inset 0 0 0 1px var(--btn); }
.tile-name { font-weight: 600; }
.tile-price { font-size: 15px; }
.tile-price .per { color: var(--ink-2); font-weight: 400; font-size: 13px; }

.periods { display: flex; flex-direction: column; gap: 8px; }
.period {
  position: relative; display: grid; grid-template-columns: 1fr auto;
  gap: 2px 10px; align-items: baseline; text-align: left;
  padding: 12px 14px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--bg); color: var(--ink); font: inherit; cursor: pointer;
}
.period.active { border-color: var(--btn); box-shadow: inset 0 0 0 1px var(--btn); }
.p-term { font-weight: 600; }
.p-total { text-align: right; font-weight: 600; }
.p-mo { grid-column: 1; color: var(--ink-2); font-size: 13px; }
.p-off {
  grid-column: 2; justify-self: end; font-size: 12px; font-weight: 600;
  color: var(--in); background: color-mix(in srgb, var(--in) 14%, transparent);
  border-radius: 6px; padding: 1px 6px;
}

.tickers { display: flex; flex-wrap: wrap; gap: 6px; }
.tk-chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 7px 10px; border: 1px solid var(--rule); border-radius: 9px;
  background: var(--bg); color: var(--ink); font: inherit; cursor: pointer;
  /* Ширину задаёт содержимое: глобальное button { width: 100% } иначе
     растягивает каждую бумагу на строку, и вместо ряда чипов получается
     список в десять экранов. */
  width: auto; flex: 0 0 auto;
}
.tk-chip span { font-size: 11px; color: var(--ink-2); max-width: 96px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tk-chip.on { border-color: var(--btn); box-shadow: inset 0 0 0 1px var(--btn); }
.tk-chip.disabled { opacity: .4; cursor: default; }

.pay {
  width: 100%; margin-top: 18px; padding: 14px; border: 0;
  border-radius: var(--radius); background: var(--btn); color: var(--btn-ink);
  font: inherit; font-weight: 600; font-size: 16px; cursor: pointer;
}
.pay:disabled { opacity: .45; cursor: default; }
.pay-note { margin-top: 8px; }

/* ---------- настройки ---------- */

.setting {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 0; border-bottom: 1px solid var(--rule); gap: 12px;
}
.setting:last-child { border-bottom: 0; }
.setting .label { font-size: 15px; }
.setting .label small { display: block; color: var(--ink-2); font-size: 12px; }

.switch { width: 46px; height: 28px; border-radius: 999px; background: var(--bg-2);
          position: relative; flex: none; cursor: pointer; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
                 border-radius: 50%; background: #fff; transition: transform .15s;
                 box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch.on { background: var(--btn); }
.switch.on::after { transform: translateX(18px); }

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

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--bg); border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; background: none; color: var(--ink-2); border-radius: 0;
  padding: 11px 4px 12px; font-size: 12px; font-weight: 500;
}
.tabs button.on { color: var(--btn); font-weight: 600; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
