/* ============================================================
   Городской Транспорт — Telegram Web App
   Тема: нейтральные цвета (фон, текст, разделители, поля) берутся из
   themeParams Telegram (см. applyTheme в app.js) — тёмная, светлая
   или пользовательская тема (например, красная) красит приложение
   как сам Telegram; смена темы на лету — событие themeChanged.
   Акценты (красный/зелёный) — фирменные, QR всегда на белом фоне.
   Цифровая клавиатура — тёмная, в едином стиле с остальным
   интерфейсом: тонкая обводка кнопок вместо сплошной заливки,
   светлый текст; красится темой Telegram вместе с остальными
   элементами (те же переменные, что и везде).
   Ниже тёмная палитра по умолчанию (когда открыли вне Telegram):
     фон          #17212b
     разделители  #2b3947
     втор. текст  #8a97a3
     красный     #e64545 / #d32f2f
     зелёный     #43a047 / #4caf50
   ============================================================ */

:root {
  --bg: #17212b;                        /* themeParams.bg_color */
  --bg-cell: rgba(255, 255, 255, 0.03);  /* ячейки кода — themeParams.secondary_bg_color */
  --divider: #2b3947;                   /* themeParams.section_separator_color (Bot API 7.6+) */
  --cell-border: #3a4956;               /* нет в themeParams — rgba(text_color, 0.25) из app.js */
  --text: #ffffff;                      /* themeParams.text_color */
  --text-muted: #8a97a3;                /* themeParams.hint_color */
  --input-bg: #0e1620;                  /* поля ввода — secondary_bg_color из app.js */
  --input-border: #3a4956;
  --input-placeholder: #55636f;
  --track: #4a5a68;                     /* неактивный трек слайдера и точки-деления */
  --box-border: #ffffff;                /* рамка квадрата количества и кайма ползунка */
  --toggle-track: rgba(255, 255, 255, 0.12);
  --toggle-knob: #c9d3dc;               /* выключенный тумблер — rgba(text_color, 0.85) из app.js */
  --accent-red: #e64545;
  --accent-red-deep: #d32f2f;
  --accent-green: #43a047;
  --accent-green-light: #4caf50;
  --wine: #3d1f24;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* ==================== Шапка (только Экран B: кнопка "←") ==================== */
/* Название бота, "⋮" и "✕" над Web App рисует сам Telegram. */

.header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-back {
  color: var(--text);
  display: flex;
  align-items: center;
  padding: 4px;
}

/* красная акцентная полоса под шапкой — видна только на Экране B */
.header-divider {
  height: 3px;
  background: var(--accent-red);
  flex-shrink: 0;
}

/* ==================== Общая раскладка ==================== */

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.divider {
  height: 1px;
  background: var(--divider);
  margin: 0;
}

.spacer { flex: 1; }

/* ==================== ЭКРАН A: Ввод кода ==================== */

.code-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* пустая тёмная зона ~100-120px под шапкой */
.code-area {
  padding: clamp(80px, 14vh, 130px) 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
}

/* ряд из 6 ячеек */
.code-cells {
  display: flex;
  gap: 3.5vw;
  justify-content: center;
}

.cell {
  width: clamp(44px, 13vw, 60px);
  height: clamp(44px, 13vw, 60px);
  border: 1px solid var(--cell-border);
  border-radius: 8px;
  background: var(--bg-cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 6vw, 26px);
  font-weight: 600;
  color: var(--text);
  transition: border-color 0.15s;
}

/* активная (следующая пустая) ячейка — светлее обводка */
.cell.active { border-color: var(--track); }

/* заголовок с иконкой QR */
.code-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: clamp(18px, 5vw, 22px);
  font-weight: 700;
  color: var(--text);
}

.icon-qr { color: var(--text-muted); flex-shrink: 0; }

/* ==================== Цифровая клавиатура (тёмная, в стиле темы) ==================== */
/* Тонкая обводка кнопок вместо сплошной заливки, светлый текст — единый
   стиль с остальным интерфейсом. Цвета берутся из тех же переменных,
   что и везде, поэтому клавиатура красится темой Telegram (тёмная,
   светлая, кастомная) вместе с остальными элементами. */

.numpad {
  margin-top: auto; /* прижата к низу экрана A */
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.numpad-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.numpad-key {
  height: clamp(56px, 9vh, 72px);
  background: transparent;              /* без заливки — только обводка */
  color: var(--text);
  font-size: clamp(20px, 6vw, 24px);
  font-weight: 500;
  border: 1px solid var(--cell-border); /* тонкая кайма, как у ячеек кода */
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.1s, border-color 0.1s;
}

/* нажатие: лёгкая подсветка цветом ячеек + кайма поярче */
.numpad-key:active {
  background: var(--bg-cell);
  border-color: var(--track);
}

/* кнопка "Сканировать": текст + иконка, компактнее */
.numpad-scan {
  flex-direction: column;
  gap: 3px;
  font-size: clamp(11px, 3vw, 13px);
  font-weight: 600;
}

/* кнопка стирания ⌫ */
.numpad-back { justify-content: center; }

/* Подпись @buspaybot под Web App рисует сам Telegram — стилей больше нет. */

/* ==================== ЭКРАН B: Данные билета ==================== */

.ticket-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 16px 16px;
  min-height: 0;
}

/* заголовок с иконкой документа */
.screen-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: clamp(19px, 5.5vw, 23px);
  font-weight: 700;
  margin-bottom: 22px;
}

.screen-heading .icon-doc { color: var(--text-muted); }
.screen-heading .icon-doc .check { stroke: var(--text); }

/* --- Блок количества: рамка + слайдер --- */

.count-block {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 4px 2px 18px;
}

/* квадратная рамка с числом */
.count-box {
  width: clamp(52px, 15vw, 64px);
  height: clamp(52px, 15vw, 64px);
  border: 2px solid var(--box-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(24px, 7vw, 30px);
  font-weight: 700;
  flex-shrink: 0;
}

.count-slider { flex: 1; min-width: 0; }

.slider-label {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 14px;
}

/* самодельный слайдер: красная линия + ползунок */
.slider-wrap { padding: 6px 6px 0; }

.slider-track {
  position: relative;
  height: 3px;
  background: var(--track);            /* неактивная часть */
  border-radius: 2px;
}

.slider-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: var(--accent-red);
  border-radius: 2px;
  width: 0%;
}

.slider-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  background: var(--accent-red);
  border: 3px solid var(--box-border);
  border-radius: 50%;
  left: 0%;
  cursor: pointer;
  touch-action: none;
}

/* деления-точки с цифрами под слайдером.
   Каждая точка стоит точно на позиции ползунка своего значения:
   0%/25%/50%/75%/100% ширины трека — поэтому цифра 2 ровно под
   ползунком, когда выбрано 2 билета. */
.slider-dots {
  position: relative;
  height: 30px;
  margin-top: 16px;
}

.dot {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  height: 30px;
  min-width: 40px;
  color: var(--text-muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* позиции точек = позиции ползунка (25% = (2-1)/(5-1)) */
.dot[data-value="1"] { left: 0%; }
.dot[data-value="2"] { left: 25%; }
.dot[data-value="3"] { left: 50%; }
.dot[data-value="4"] { left: 75%; }
.dot[data-value="5"] { left: 100%; }

/* точка-деление над цифрой */
.dot::before {
  content: "";
  position: absolute;
  top: -13px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--track);
}

.dot.active { color: var(--text); font-weight: 700; }
.dot.active::before { background: var(--accent-red); }

/* ==================== Инфо-строки (Экраны B, D) ==================== */

.info-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 2px;
}

.row-icon {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  flex-shrink: 0;
  font-size: 18px;
  font-weight: 600;
}

.row-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.row-label {
  color: var(--text-muted);
  font-size: 13px;
}

.row-value {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

/* блок «маршрут + госномер» Экрана D — без подзаголовка: строки вплотную */
.row-text-tight { gap: 0; }

/* название маршрута — тем же стилем, что подписи «Стоимость»,
   «Дата покупки» и т.д. (.row-label): тот же серый и размер */
.row-route-name {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.35;
  /* длинные названия маршрута могут переноситься — не ломаем строку */
  word-break: break-word;
}

/* госномер крупным жирным сразу под названием (вторая строка, как номер
   на настоящем билете) */
.row-plate-big {
  color: var(--text);
  font-weight: 700;
  font-size: clamp(22px, 7vw, 30px);
  letter-spacing: 0.5px;
  word-break: break-word;
}

/* ==================== Госномер ==================== */

/* поле госномера автобуса (вводится перед посадкой, Экран B) */
.plate-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  /* 16px, чтобы iOS не приближал экран при фокусе на поле */
  font-size: 16px;
  font-weight: 700;
  padding: 9px 12px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

.plate-input:focus { border-color: var(--track); }
.plate-input::placeholder {
  color: var(--input-placeholder);
  font-weight: 400;
}

/* ==================== Карточка "Создать подписку?" ==================== */

.subscribe-card {
  margin-top: 18px;
  background: var(--wine);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.subscribe-text {
  font-size: 16px;
  font-weight: 600;
}

/* тумблер (toggle switch) */
.toggle {
  width: 52px;
  height: 30px;
  border-radius: 15px;
  background: var(--toggle-track);
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--toggle-knob);        /* rgba(text_color, 0.85) из app.js */
  transition: transform 0.2s;
}

.toggle.on { background: var(--accent-green); }
.toggle.on .toggle-knob { transform: translateX(22px); background: #ffffff; }

/* ==================== Большие кнопки внизу ==================== */

.btn-pay, .btn-close {
  width: 100%;
  padding: 16px;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #ffffff;
  margin-top: 12px;
  flex-shrink: 0;
}

/* зелёная ОПЛАТИТЬ */
.btn-pay { background: var(--accent-green); }
.btn-pay:active { background: var(--accent-green-light); }
.btn-pay:disabled { opacity: 0.6; }

/* красная ЗАКРЫТЬ */
.btn-close { background: var(--accent-red-deep); }
.btn-close:active { background: #b71c1c; }

/* ==================== СКРЫТЫЙ ЭКРАН ADMIN: таблица автобусов ==================== */

/* Прокручивается ВЕСЬ экран целиком, а не список внутри него.
   Со вложенным скроллом список автобусов схлопывался до нескольких
   пикселей, как только сверху появился блок перевозчиков: ему доставался
   flex-остаток, а остатка не было. */
.admin-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 16px 16px;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.5;
}

/* список автобусов: прокручивается, кнопки всегда видны снизу */
/* Подзаголовок секции админки («Перевозчики», «Автобусы и маршруты») */
.admin-sub {
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  padding: 4px 2px;
  margin-top: 6px;
}

/* Перевозчики обеих версий: карточка на версию (Mini App / сайт) */
.admin-carriers {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 2px 6px;
  flex: none;
}

.carrier-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-cell);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.carrier-kind {
  color: var(--accent-red);
  font-weight: 700;
  font-size: 15px;
}

/* Своего скролла у списка больше нет — прокручивается .admin-screen целиком */
.admin-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 2px 12px;
}

/* Кнопки «СОХРАНИТЬ» / «ЗАКРЫТЬ» липнут к низу прокручиваемого экрана */
.admin-actions {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding-bottom: calc(4px + env(safe-area-inset-bottom));
  background: var(--bg);
  flex-shrink: 0;
}

.admin-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-cell);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.admin-bus-no {
  color: var(--accent-red);
  font-weight: 700;
  font-size: 15px;
}

.admin-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  /* 16px, чтобы iOS не приближал экран при фокусе на поле */
  font-size: 16px;
  padding: 10px 12px;
  outline: none;
  /* text-константный ввод: разрешаем и выделение, и ввод с клавиатуры */
  -webkit-user-select: text;
  user-select: text;
}

.admin-input:focus { border-color: var(--track); }
.admin-input::placeholder { color: var(--input-placeholder); }

/* ==================== ЭКРАН D/E: Информация о поездке ==================== */

.trip-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 18px 16px 16px;
  min-height: 0;
}

/* иконки блоков билета (перевозчик, автобус, ₽, календарь, часы) —
   светлыми (цветом текста темы), а не приглушёнными: на Экране билета
   иконка — самостоятельный графический элемент, серый reserved
   для подписей */
.trip-screen .row-icon {
  color: var(--text);
}

/* счётчик сеанса показа билета: "Действует: 9 сек." */
.live-counter {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 6px 0 18px;
}

.counter-caption {
  font-size: clamp(19px, 5.5vw, 23px);
  font-weight: 700;
}

.counter-seconds {
  font-size: clamp(19px, 5.5vw, 23px);
  font-weight: 700;
  color: var(--accent-red);
}

/* табы */
.tabs {
  display: flex;
  justify-content: center;
  gap: clamp(18px, 6vw, 36px);
  margin-bottom: 14px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 4px 10px;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  position: relative;
}

/* красное подчёркивание активной вкладки */
.tab.active {
  color: var(--accent-red);
  border-bottom-color: var(--accent-red);
}

/* номер билета красным жирным в активном табе, серым в неактивном */
.tab-ticket-no {
  font-weight: 700;
  font-size: 15px;
}

.tab-ticket.active .tab-ticket-no { color: var(--accent-red); }
.tab-ticket:not(.active) .tab-ticket-no { color: var(--text-muted); }

/* ==================== ЭКРАН E: QR-код ==================== */

.qr-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: clamp(20px, 5vh, 44px);
  gap: 18px;
}

/* белый квадрат с QR */
.qr-box {
  background: #ffffff;
  border-radius: 14px;
  padding: clamp(14px, 4vw, 22px);
  width: min(350px, 82vw);
  height: min(350px, 82vw);
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-img { width: 100%; height: 100%; }
.qr-img svg, .qr-img canvas, .qr-img img {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.qr-number {
  font-size: clamp(20px, 6vw, 26px);
  font-weight: 700;
  text-align: center;
}

/* ==================== Прочее ==================== */

[hidden] { display: none !important; }

/* маленькие экраны — плотнее */
@media (max-height: 640px) {
  .code-area { padding-top: 50px; gap: 24px; }
  .numpad, .numpad-row { gap: 6px; }
  .numpad-key { height: 50px; }
}
