/* PWA: плавные переходы между страницами, режим «установленного приложения», баннеры установки и обновления. */

/* ---------- Переходы между страницами (View Transitions, Chrome/Яндекс 126+; остальные браузеры игнорируют) ---------- */
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) { @view-transition { navigation: none; } }
::view-transition-old(root) { animation: pwa-vt-out .14s cubic-bezier(.4,0,1,1) both; }
::view-transition-new(root) { animation: pwa-vt-in .2s cubic-bezier(0,0,.2,1) both; }
@keyframes pwa-vt-out { to { opacity: 0; } }
@keyframes pwa-vt-in { from { opacity: 0; } }
/* Закреплённые панели — отдельные слои: при переходе стоят на месте и не мигают */
.app-bottom-nav { view-transition-name: pwa-bottom-nav; }
.social-topbar { view-transition-name: pwa-topbar; }
.masthead { view-transition-name: pwa-masthead; }
.site-header { view-transition-name: pwa-site-header; }
::view-transition-group(pwa-bottom-nav), ::view-transition-group(pwa-topbar),
::view-transition-group(pwa-masthead), ::view-transition-group(pwa-site-header) { animation-duration: .2s; }
::view-transition-old(pwa-bottom-nav), ::view-transition-new(pwa-bottom-nav),
::view-transition-old(pwa-topbar), ::view-transition-new(pwa-topbar),
::view-transition-old(pwa-masthead), ::view-transition-new(pwa-masthead),
::view-transition-old(pwa-site-header), ::view-transition-new(pwa-site-header) { animation-duration: .2s; height: 100%; object-fit: none; object-position: top; }
/* Полноэкранные редакторы и просмотр историй — без общих слоёв */
html.post-compose .app-bottom-nav, html.story-compose .app-bottom-nav, html.story-open .app-bottom-nav { view-transition-name: none; }

/* ---------- Режим установленного приложения ---------- */
html.pwa-standalone { -webkit-tap-highlight-color: transparent; overscroll-behavior-x: none; }
html.pwa-standalone body { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.pwa-standalone .app-bottom-nav,
html.pwa-standalone .social-topbar,
html.pwa-standalone .masthead .section-nav,
html.pwa-standalone .mast-tools,
html.pwa-standalone .site-header .header-inner,
html.pwa-standalone button,
html.pwa-standalone .btn,
html.pwa-standalone [role="button"] { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html.pwa-standalone .app-bottom-nav a,
html.pwa-standalone .section-nav a { -webkit-touch-callout: none; }
/* Отступы под вырезы экрана (iOS / Android в полноэкранном режиме) */
html.pwa-standalone .masthead,
html.pwa-standalone .social-topbar,
html.pwa-standalone .site-header { padding-top: env(safe-area-inset-top); }
/* Рубрики газеты скроллятся пальцем без «резинки» всей страницы */
html.pwa-standalone .section-nav .wrap { overscroll-behavior-x: contain; }
/* Высота экрана в установленном приложении. Chrome на Android в режиме standalone при открытии страницы
   может считать 100dvh выше видимой области на высоту системных панелей (crbug.com/331326389; проходит только после
   открытия-закрытия клавиатуры) — в чате поле ввода уходит за нижний край экрана. Адресной строки в приложении нет,
   поэтому 100svh здесь равно видимой высоте и не «плавает». Режим клавиатуры (chat-keyboard-open) правило перекрывает. */
html.pwa-standalone body.paper.social-app { min-height: 100svh; }
html.pwa-standalone .chat-app .social-main { height: calc(100svh - 78px - env(safe-area-inset-bottom)); }
html.pwa-standalone .chat-app.chat-conversation-app .social-main { height: 100svh; }
@media (max-width: 600px) {
  html.pwa-standalone .chat-app .social-main { height: calc(100svh - 72px - env(safe-area-inset-bottom)); }
  html.pwa-standalone .chat-app.chat-conversation-app .social-main { height: calc(100svh - env(safe-area-inset-bottom)); }
}
@media (min-width: 900px) {
  html.pwa-standalone .chat-app .social-main, html.pwa-standalone .chat-app.chat-conversation-app .social-main { height: 100svh; }
}
@media (max-width: 768px), (pointer: coarse) {
  html.pwa-standalone .story-compose-app .story-new__frame { height: 100svh; }
}
@media (max-width: 540px) { html.pwa-standalone .story-stage { height: 100svh; } }

/* ---------- Общие элементы PWA (не зависят от styles.css / paper.css) ---------- */
.pwa-ui { --pwa-bg: #fffdf9; --pwa-ink: #20272a; --pwa-muted: #6c6a64; --pwa-rule: #e4ddd1; --pwa-accent: #ae2026; --pwa-chip: #f3ede4;
  font: 400 15px/1.45 Roboto, system-ui, -apple-system, "Segoe UI", Arial, sans-serif; color: var(--pwa-ink); -webkit-tap-highlight-color: transparent; }
[data-theme=dark] .pwa-ui { --pwa-bg: #202f33; --pwa-ink: #f4ecdf; --pwa-muted: #adb6b3; --pwa-rule: #344247; --pwa-accent: #ec5559; --pwa-chip: #26373c; }
.pwa-ui *, .pwa-ui *::before, .pwa-ui *::after { box-sizing: border-box; }
.pwa-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border: 1px solid var(--pwa-rule); border-radius: 12px; background: transparent; color: var(--pwa-ink); font: 600 15px/1 inherit; font-family: inherit; cursor: pointer; text-decoration: none; -webkit-user-select: none; user-select: none; }
.pwa-btn:active { transform: scale(.98); }
.pwa-btn:focus-visible { outline: 2px solid var(--pwa-accent); outline-offset: 2px; }
.pwa-btn--primary { border-color: var(--pwa-accent); background: var(--pwa-accent); color: #fff; }
.pwa-btn--ghost { border-color: transparent; color: var(--pwa-muted); }

/* Тост «Доступна новая версия» */
.pwa-toast { position: fixed; z-index: 1300; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 6px; width: max-content; max-width: calc(100% - 24px); padding: 8px 8px 8px 16px; border: 1px solid var(--pwa-rule); border-radius: 16px; background: var(--pwa-bg); box-shadow: 0 10px 34px rgba(16,23,25,.22); transform: translate(-50%, 16px); opacity: 0; transition: transform .26s cubic-bezier(.2,.8,.2,1), opacity .2s ease; }
.pwa-toast.is-shown { transform: translate(-50%, 0); opacity: 1; }
.pwa-toast__text { flex: 1; min-width: 0; margin-right: 6px; font-weight: 500; }
.pwa-toast .pwa-btn { min-height: 38px; padding: 0 14px; border-radius: 10px; }
.pwa-toast__close { width: 38px; padding: 0; font-size: 20px; font-weight: 400; }
body:not(.has-app-nav) .pwa-toast { bottom: calc(20px + env(safe-area-inset-bottom)); }

/* Нижний лист «Установить приложение» (мобильные) */
.pwa-sheet { position: fixed; z-index: 1250; inset: 0; display: flex; align-items: flex-end; justify-content: center; }
.pwa-sheet__backdrop { position: absolute; inset: 0; background: rgba(10,14,16,.42); opacity: 0; transition: opacity .24s ease; }
.pwa-sheet__panel:focus { outline: none; }
.pwa-sheet__panel { position: relative; width: min(100%, 520px); padding: 10px 20px calc(18px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; background: var(--pwa-bg); box-shadow: 0 -10px 40px rgba(16,23,25,.2); transform: translateY(105%); transition: transform .3s cubic-bezier(.2,.8,.2,1); }
.pwa-sheet.is-shown .pwa-sheet__backdrop { opacity: 1; }
.pwa-sheet.is-shown .pwa-sheet__panel { transform: none; }
.pwa-sheet__grab { width: 40px; height: 4px; margin: 0 auto 16px; border-radius: 4px; background: var(--pwa-rule); }
.pwa-sheet__head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.pwa-sheet__icon { width: 56px; height: 56px; flex: none; border-radius: 14px; box-shadow: 0 2px 10px rgba(16,23,25,.12); }
.pwa-sheet__title { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.25; }
.pwa-sheet__sub { margin: 2px 0 0; color: var(--pwa-muted); font-size: 13px; }
.pwa-sheet__list { margin: 0 0 18px; padding: 0; list-style: none; display: grid; gap: 9px; }
.pwa-sheet__list li { display: flex; align-items: center; gap: 10px; color: var(--pwa-ink); }
.pwa-sheet__list svg { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--pwa-accent); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.pwa-sheet__actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.pwa-sheet__actions .pwa-btn { min-height: 48px; }
.pwa-ios-steps { margin: 0 0 18px; padding: 12px 14px; border-radius: 14px; background: var(--pwa-chip); display: grid; gap: 10px; counter-reset: s; list-style: none; }
.pwa-ios-steps li { display: flex; align-items: center; gap: 10px; counter-increment: s; }
.pwa-ios-steps li::before { content: counter(s); display: inline-grid; place-items: center; width: 24px; height: 24px; flex: none; border-radius: 50%; background: var(--pwa-accent); color: #fff; font-size: 13px; font-weight: 700; }
.pwa-ios-steps svg { width: 20px; height: 20px; vertical-align: -4px; fill: none; stroke: #0a84ff; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* Карточка в профиле (account.php) */
.pwa-install-card[hidden] { display: none !important; }
.pwa-install-card .pwa-install-card__row { display: flex; align-items: center; gap: 14px; }
.pwa-install-card .pwa-install-card__icon { width: 52px; height: 52px; flex: none; border-radius: 13px; box-shadow: 0 2px 10px rgba(16,23,25,.12); }
.pwa-install-card .pwa-install-card__text { flex: 1; min-width: 0; margin: 0; }
.pwa-install-card .pwa-install-card__hint { margin: 12px 0 0; }
.pwa-install-card .pwa-install-card__hint:empty { display: none; }
@media (max-width: 480px) { .pwa-install-card .pwa-install-card__row { flex-wrap: wrap; } .pwa-install-card [data-pwa-install] { width: 100%; } }

@media (prefers-reduced-motion: reduce) { .pwa-toast, .pwa-sheet__panel, .pwa-sheet__backdrop { transition: none; } }
