
/* ── Шрифт (свой хостинг: Google Fonts у RU-пользователей бывает медленным) ── */
@font-face {
  font-family: 'Onest'; font-style: normal; font-weight: 400 800; font-display: swap;
  src: url(/fonts/onest-cyrillic.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Onest'; font-style: normal; font-weight: 400 800; font-display: swap;
  src: url(/fonts/onest-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── Дизайн-токены (стиль A: тёмный премиум) ─────────
   Своя палитра вместо цветов темы Telegram — приложение узнаваемо.
   Старые имена (--bg, --bg2, --accent…) сохранены: страницы их уже используют. */
html { color-scheme: dark; }
:root {
  --bg:        #0a0a0f;
  --bg2:       #15141d;                    /* сплошная поверхность: листы, карточки */
  --surface:   rgba(255,255,255,0.055);    /* «стекло» поверх фона */
  --surface-2: rgba(255,255,255,0.09);
  --stroke:    rgba(255,255,255,0.09);
  --text:      #f4f3f8;
  --hint:      #8d8b9c;
  --accent:    #8b5cf6;
  --accent-2:  #ec4899;
  --accent-text: #b9a4ff;                  /* акцент для текста/иконок на тёмном */
  --accent-fg: #ffffff;
  --link:      #b9a4ff;
  --green:     #34d399;
  --danger:    #f87171;
  --grad:      linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --glow-1:    rgba(139,92,246,0.35);
  --glow-2:    rgba(236,72,153,0.20);
  --bar-bg:    rgba(16,15,23,0.78);        /* шапки и плавающие панели с blur */
  --radius:    18px;
  --radius-sm: 10px;
  --font: 'Onest', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(420px 320px at 100% -60px, var(--glow-1), transparent 70%),
    radial-gradient(360px 300px at -80px 40%, var(--glow-2), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font-family: inherit; }

/* ── Клавиатура ──────────────────────────────────────
   body закреплён и всегда равен видимой области (--app-h / --app-top ставит shared.js
   по visualViewport). Иначе iOS сначала сдвигает документ к полю ввода, а Telegram
   меняет высоту WebView только после анимации клавиатуры — интерфейс дёргается дважды. */
html { overscroll-behavior: none; }
body {
  position: fixed; top: 0; left: 0; right: 0;
  transform: translateY(var(--app-top, 0px));
  overscroll-behavior: none;
}

/* Иконки из спрайта shared.js: <svg class="ico"><use href="#i-home"/></svg> */
.ico {
  width: 20px; height: 20px; flex-shrink: 0;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* Стеклянная поверхность */
.glass {
  background: var(--surface); border: 1px solid var(--stroke);
  -webkit-backdrop-filter: blur(20px) saturate(140%); backdrop-filter: blur(20px) saturate(140%);
}

/* ── Skeleton ───────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, rgba(255,255,255,0.05) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius);
  height: 40px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Экраны-состояния (showState / showLoadError в shared.js) ─ */
.state {
  display: none; flex: 1; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 48px 28px; text-align: center; color: var(--hint);
}
.state-ic {
  width: 56px; height: 56px; border-radius: 18px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--stroke); color: var(--accent-text);
}
.state-ic .ico { width: 26px; height: 26px; }
.state-title { font-size: 16px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.state-sub { font-size: 13px; line-height: 1.4; max-width: 280px; }
.state-btn {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 12px;
  padding: 11px 20px; border: none; border-radius: 13px; cursor: pointer;
  background: var(--grad); color: #fff; font: 600 14px var(--font);
}
.state-btn .ico { width: 16px; height: 16px; }
.state-btn:active { opacity: 0.85; }

/* ── Переходы между страницами (View Transitions) ─ */
/* Без поддержки браузер просто игнорирует правило */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0.18s; }
.bottom-nav { view-transition-name: bottom-nav; }

/* ── Плавное появление ──────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.fade-in { animation: fadeIn 0.24s ease-out both; }

/* Картинка проявляется по onload (класс loaded ставит shared.js),
   до этого на её месте плейсхолдер фона контейнера */
img.fade-img { opacity: 0; transition: opacity 0.3s ease; }
img.fade-img.loaded { opacity: 1; }

/* ── Прогресс генерации изображения (createGenProgress) ── */
.gen-progress { width: 240px; max-width: 100%; }
.gen-canvas {
  display: flex; align-items: center; justify-content: center;
  border-radius: 18px; border: 1px solid var(--stroke);
  background: linear-gradient(110deg, rgba(139,92,246,0.10) 30%, rgba(236,72,153,0.24) 50%, rgba(139,92,246,0.10) 70%);
  background-size: 250% 100%;
  animation: shimmer 1.8s linear infinite;
}
.gen-icon {
  width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center;
  background: var(--grad); color: #fff; box-shadow: 0 12px 30px -10px var(--glow-1);
  animation: genPulse 1.6s ease-in-out infinite;
}
.gen-icon .ico { width: 26px; height: 26px; }
@keyframes genPulse {
  0%, 100% { transform: scale(1);    opacity: 0.75; }
  50%      { transform: scale(1.12); opacity: 1; }
}
.gen-meta {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 8px; font-size: 13px;
}
.gen-time { color: var(--hint); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.gen-bar {
  height: 3px; margin-top: 6px; border-radius: 2px;
  background: rgba(255,255,255,0.1); overflow: hidden;
}
.gen-bar-fill {
  height: 100%; width: 0; background: var(--grad);
  border-radius: 2px; transition: width 0.5s linear;
}

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  .gen-canvas, .gen-icon { animation: none; }
  .fade-in { animation: none; }
  img.fade-img { transition: none; }
}

/* ── Common components ──────────────────────────── */
.page-title {
  font-size: 20px; font-weight: 700;
  padding: 20px 20px 4px;
}

.section-title {
  font-size: 12px; font-weight: 600; color: var(--hint);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 16px 20px 8px;
}

.info-card {
  margin: 0 12px;
  background: var(--bg2);
  border-radius: 14px;
  overflow: hidden;
}
.info-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.info-row:last-child { border-bottom: none; }
.info-label { font-size: 14px; color: var(--hint); }
.info-value { font-size: 14px; font-weight: 500; }
.info-value.green { color: var(--green); }

/* ── Error state ────────────────────────────────── */
.error-state {
  display: none; flex: 1; align-items: center; justify-content: center;
  flex-direction: column; gap: 10px; color: var(--hint);
  font-size: 14px; text-align: center; padding: 20px;
}

/* ── Scroll container bottom clearance ──────────── */
#scroll-area,
#content {
  padding-bottom: 16px;
}

/* ── Шапка страницы ──────────────────────────────── */
/* #header есть почти на каждой странице; кнопку ☰ в него вставляет shared.js */
#header {
  background: var(--bar-bg) !important;
  border-bottom: 1px solid var(--stroke) !important;
  -webkit-backdrop-filter: blur(20px) saturate(140%); backdrop-filter: blur(20px) saturate(140%);
  position: relative; z-index: 20;
}
.app-burger {
  width: 40px; height: 40px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border-radius: 13px; border: 1px solid var(--stroke); background: var(--surface);
  color: var(--text); cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s, background 0.15s;
}
.app-burger:active { transform: scale(0.94); background: var(--surface-2); }
.app-burger i { display: block; height: 2px; width: 18px; border-radius: 2px; background: currentColor; }
.app-burger i:nth-child(2) { width: 12px; margin-right: 6px; }

/* ── Шторка (drawer) ─────────────────────────────── */
.drawer-scrim {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(0,0,0,0.55);
  opacity: 0; pointer-events: none;
  transition: opacity 0.28s ease;
}
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 901;
  width: min(84vw, 340px);
  display: flex; flex-direction: column;
  padding: calc(14px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
  background: #111018; border-right: 1px solid var(--stroke);
  box-shadow: 24px 0 60px -24px rgba(0,0,0,0.7);
  transform: translateX(-102%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
}
body.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }
body.drawer-open .drawer { transform: none; }
.drawer.dragging, .drawer-scrim.dragging { transition: none; }

.dr-search {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; height: 42px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--stroke); color: var(--hint);
}
.dr-search input {
  flex: 1; min-width: 0; background: none; border: none; outline: none;
  color: var(--text); font-size: 15px;
}
.dr-search input::placeholder { color: var(--hint); }
.dr-nav { margin: 12px 0 4px; display: flex; flex-direction: column; gap: 2px; }
.dr-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border-radius: 12px;
  color: var(--text); text-decoration: none; font-size: 15px; font-weight: 600;
  -webkit-tap-highlight-color: transparent; transition: background 0.15s;
}
.dr-item .ico { color: var(--hint); }
.dr-item:active { background: var(--surface); }
.dr-item.active { background: var(--surface-2); }
.dr-item.active .ico { color: var(--accent-text); }
.dr-badge {
  margin-left: auto; font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  padding: 3px 7px; border-radius: 999px; color: var(--accent-text);
  background: linear-gradient(135deg, rgba(139,92,246,0.28), rgba(236,72,153,0.28));
}
.dr-hist { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; scrollbar-width: none; }
.dr-hist::-webkit-scrollbar { display: none; }
.dr-sec {
  padding: 16px 10px 6px; font-size: 11px; font-weight: 600; color: var(--hint);
  text-transform: uppercase; letter-spacing: 0.07em;
}
.dr-chat {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 12px;
  color: var(--text); text-decoration: none; font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}
.dr-chat:active { background: var(--surface); }
.dr-chat.active { background: var(--surface-2); }
.dr-chat-ic {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  display: grid; place-items: center; background: var(--surface-2); color: var(--hint);
}
.dr-chat-ic .ico { width: 14px; height: 14px; }
.dr-chat-ic.image { background: linear-gradient(135deg, rgba(139,92,246,0.3), rgba(236,72,153,0.3)); color: #f0abfc; }
.dr-chat .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dr-chat-menu {
  flex-shrink: 0; background: none; border: none; color: var(--hint); font-size: 18px; line-height: 1;
  padding: 4px 8px; margin: -4px -6px -4px 0; border-radius: 8px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dr-chat-menu:active { color: var(--text); background: var(--surface-2); }

/* Лист действий с чатом (поверх шторки) */
.ca-overlay {
  display: flex; position: fixed; inset: 0; z-index: 950; align-items: flex-end; justify-content: center;
  visibility: hidden; pointer-events: none; transition: visibility 0s linear 0.32s;
}
.ca-overlay.open { visibility: visible; pointer-events: auto; transition: none; }
.ca-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); opacity: 0; transition: opacity 0.25s; }
.ca-overlay.open .ca-backdrop { opacity: 1; }
.ca-sheet {
  position: relative; z-index: 1; width: 100%; max-width: 520px;
  background: var(--bg2); border: 1px solid var(--stroke); border-bottom: none; border-radius: 26px 26px 0 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}
.ca-sheet::before { content: ''; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--surface-2); margin: 0 auto 14px; }
.ca-overlay.open .ca-sheet { transform: none; }
@media (prefers-reduced-motion: reduce) { .ca-sheet, .ca-backdrop { transition: none; } }
.ca-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-opt {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--stroke); border-radius: 14px; color: var(--text);
  font-size: 15px; font-weight: 600; font-family: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.ca-opt:active { opacity: 0.75; }
.ca-opt.danger { color: var(--danger); }
#ca-input {
  width: 100%; box-sizing: border-box; padding: 12px 14px; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--stroke); border-radius: 12px; color: var(--text);
  font-size: 15px; font-family: inherit; outline: none;
}
#ca-input:focus { border-color: var(--accent); }
.ca-row { display: flex; gap: 8px; }
.ca-btn {
  flex: 1; padding: 12px; border: none; border-radius: 12px; font-size: 15px; font-weight: 600;
  font-family: inherit; cursor: pointer; background: var(--surface-2); color: var(--text);
}
.ca-btn.primary { background: var(--grad); color: #fff; }
.dr-empty { padding: 14px 10px; color: var(--hint); font-size: 13px; }
.dr-all { display: block; padding: 10px; color: var(--hint); font-size: 13px; text-decoration: none; }
.dr-foot {
  display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 10px;
  border-radius: 16px; background: var(--surface); border: 1px solid var(--stroke);
  color: var(--text); text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.dr-foot.active { border-color: rgba(139,92,246,0.5); }
.dr-av {
  width: 36px; height: 36px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; background: var(--grad); color: #fff; font-weight: 800;
}
.dr-who { flex: 1; min-width: 0; }
.dr-who b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dr-who small { color: var(--hint); font-size: 12px; }
.dr-up {
  flex-shrink: 0; padding: 7px 11px; border-radius: 10px;
  background: var(--grad); color: #fff; font-size: 12px; font-weight: 700; text-decoration: none;
}

/* Чип баланса (шапка Главной) */
.bal-pill {
  display: inline-flex; align-items: center; gap: 5px; height: 40px; padding: 0 12px 0 10px;
  border-radius: 13px; background: var(--surface); border: 1px solid var(--stroke);
  color: var(--text); font-size: 14px; font-weight: 700; text-decoration: none;
  font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent;
}
.bal-pill .ico { width: 16px; height: 16px; color: var(--accent-text); }

@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer-scrim { transition: none; }
}

.hdr-main { flex: 1; min-width: 0; }
/* Шапка для страниц без собственной (профиль) */
.page-bar { display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; flex-shrink: 0; }
.page-bar-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }

/* ── Переключатель (профиль → Персонализация) ── */
.switch {
  appearance: none; -webkit-appearance: none; flex-shrink: 0;
  width: 46px; height: 28px; border-radius: 14px; margin: 0;
  background: var(--surface-2, rgba(255,255,255,0.12)); position: relative; cursor: pointer;
  transition: background 0.2s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: transform 0.2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.switch:disabled { opacity: 0.5; }
@media (prefers-reduced-motion: reduce) { .switch, .switch::after { transition: none; } }
