/* Панель — мини-приложение админ-бота (docs/panel.md).
   Цвета — только из темы Telegram (--tg-theme-*). --fb-* — запасные: для старых клиентов,
   у которых в теме нет части цветов, и для страницы вне Telegram. */

:root {
  color-scheme: light dark;

  --fb-bg: #efeff4;
  --fb-section: #ffffff;
  --fb-text: #000000;
  --fb-hint: #8e8e93;
  --fb-link: #007aff;
  --fb-destructive: #ff3b30;
  --fb-header: #6d6d72;
  --fb-separator: #c8c7cc;

  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-section)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --button: var(--tg-theme-button-color, var(--link));
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --destructive: var(--tg-theme-destructive-text-color, var(--fb-destructive));
  --header: var(--tg-theme-section-header-text-color, var(--fb-header));
  --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
  --separator: var(--tg-theme-section-separator-color, var(--fb-separator));

  /* Вырезы экрана и кнопки Telegram поверх страницы (полноэкранный режим, Bot API 8.0) */
  --inset-top: calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 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));
  --inset-right: calc(var(--tg-safe-area-inset-right, env(safe-area-inset-right, 0px)) + var(--tg-content-safe-area-inset-right, 0px));
}

/* data-scheme ставит panel.js по теме Telegram; вне Telegram решает настройка устройства */
:root[data-scheme="light"] { color-scheme: light; }
:root[data-scheme="dark"] {
  color-scheme: dark;
  --fb-bg: #000000;
  --fb-section: #1c1c1e;
  --fb-text: #ffffff;
  --fb-hint: #98989e;
  --fb-link: #0a84ff;
  --fb-destructive: #ff453a;
  --fb-header: #8d8d93;
  --fb-separator: #38383a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme]) {
    --fb-bg: #000000;
    --fb-section: #1c1c1e;
    --fb-text: #ffffff;
    --fb-hint: #98989e;
    --fb-link: #0a84ff;
    --fb-destructive: #ff453a;
    --fb-header: #8d8d93;
    --fb-separator: #38383a;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

/* ─── Заголовок экрана ──────────────────────────────────────────────────── */

.page-head { padding: 10px 4px 0; }
.page-title {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.page-sub { margin: 4px 0 0; color: var(--hint); font-size: 15px; }
.page-sub.is-danger { color: var(--destructive); }

/* ─── Секции и строки в духе настроек Telegram ──────────────────────────── */

.section { margin-top: 24px; }
.page-head + .section,
.page-head + div > .section:first-child,
.search + div > .section:first-child { margin-top: 20px; }
.section-header {
  margin: 0 16px 7px;
  font-size: 13px;
  line-height: 1.3;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--header);
}
.list {
  overflow: hidden;
  border-radius: 12px;
  background: var(--section);
}
.section-footer {
  margin: 7px 16px 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--hint);
  overflow-wrap: anywhere;
}
.section-footer.is-error, .note.is-error { color: var(--destructive); }
.section-footer.is-ok { color: var(--text); }

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 11px 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}
button.row { cursor: pointer; -webkit-appearance: none; appearance: none; }
button.row:disabled { cursor: default; }

/* разделитель — с отступом слева, как в Telegram */
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: 1px solid var(--separator);
}
@media (min-resolution: 2dppx) {
  .row + .row::before { border-top-width: 0.5px; }
}

/* нажатие */
button.row:not(:disabled):active::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: var(--text);
  opacity: 0.07;
  pointer-events: none;
}

.row-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.row-title { overflow-wrap: anywhere; }
.row-sub {
  font-size: 14px;
  line-height: 1.35;
  color: var(--subtitle);
  overflow-wrap: anywhere;
}
.row-value {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 64%;
  overflow: hidden;
  color: var(--hint);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.row-meta {
  flex: none;
  align-self: flex-start;
  padding-top: 1px;
  color: var(--hint);
  font-size: 14px;
  white-space: nowrap;
}
.row.is-link .row-title { color: var(--accent); }
.row.is-danger .row-title { color: var(--destructive); }
.row.is-off .row-title { color: var(--hint); }
button.row:disabled .row-title { opacity: 0.6; }

.icon { display: inline-flex; flex: none; color: var(--hint); }
.icon-chevron { opacity: 0.6; }
.row .icon-copy { color: var(--accent); }

/* ─── Переключатель ─────────────────────────────────────────────────────── */

label.row { cursor: pointer; }
label.row.is-off { cursor: default; }
.switch { position: relative; flex: none; width: 51px; height: 31px; }
.switch input {
  position: absolute;
  top: 0; left: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch input:disabled { cursor: default; }
.switch-track {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  border-radius: 16px;
  background: var(--separator);
  transition: background-color 0.2s;
}
@supports (background: color-mix(in srgb, red 50%, transparent)) {
  .switch-track { background: color-mix(in srgb, var(--hint) 34%, transparent); }
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--button-text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch input:checked + .switch-track { background: var(--button); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:disabled + .switch-track { opacity: 0.45; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── Поля ввода ────────────────────────────────────────────────────────── */

.row.is-field { padding-top: 0; padding-bottom: 0; cursor: text; }
.field-label { flex: none; width: 88px; }
.field-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* меньше 16px — iOS приближает страницу при вводе */
  caret-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}
.field-input::placeholder { color: var(--hint); opacity: 1; }
.field-input[readonly] { color: var(--hint); }
.field-input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 100px var(--section) inset;
  -webkit-text-fill-color: var(--text);
}

.search { position: relative; margin-top: 18px; }
.search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  pointer-events: none;
}
.search-input {
  width: 100%;
  height: 44px;
  padding: 0 12px 0 40px;
  border: 0;
  border-radius: 12px;
  outline: 0;
  background: var(--section);
  color: var(--text);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
.search-input::placeholder { color: var(--hint); opacity: 1; }
.search-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }

/* ─── Логин и пароль, если письмо не ушло ───────────────────────────────── */

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  -webkit-user-select: text;
  user-select: text;
}
.copy-btn {
  flex: none;
  min-height: 44px;
  margin: -11px -8px -11px 0;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  cursor: pointer;
}
.copy-btn:active { opacity: 0.6; }

/* ─── Тексты, пустые экраны, итог ───────────────────────────────────────── */

.note { margin: 20px 16px 0; color: var(--hint); font-size: 15px; line-height: 1.45; }
.empty { margin: 56px 24px; text-align: center; color: var(--hint); font-size: 16px; line-height: 1.45; }

.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 70vh;
  padding: 24px 16px;
  text-align: center;
}
.center-text { max-width: 320px; margin: 0; font-size: 17px; line-height: 1.45; }

.btn {
  min-height: 44px;
  padding: 0 22px;
  border: 0;
  border-radius: 12px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 600;
  cursor: pointer;
}
.btn:active { opacity: 0.8; }

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
}

.result { padding: 28px 8px 4px; text-align: center; }
.result-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
}
.result-title { margin: 0; font-size: 21px; line-height: 1.3; font-weight: 700; overflow-wrap: anywhere; }
.result-text { margin: 8px 0 0; color: var(--hint); overflow-wrap: anywhere; }

.spinner {
  flex: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--hint);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.center > .spinner { width: 28px; height: 28px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--inset-bottom) + 20px);
  z-index: 10;
  max-width: calc(100% - 48px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.is-shown { opacity: 0.94; transform: translate(-50%, 0); }

.offscreen { position: fixed; top: 0; left: -9999px; opacity: 0; }

/* ─── Смена экрана ──────────────────────────────────────────────────────── */

.screen.enter-forward { animation: enter-forward 0.18s ease-out; }
.screen.enter-back { animation: enter-back 0.18s ease-out; }
@keyframes enter-forward { from { opacity: 0; transform: translateX(14px); } }
@keyframes enter-back { from { opacity: 0; transform: translateX(-14px); } }

@media (prefers-reduced-motion: reduce) {
  .screen.enter-forward, .screen.enter-back { animation: none; }
  .switch-track, .switch-track::after, .toast { transition: none; }
  .spinner { animation-duration: 1.6s; }
}
