/* Telegram's compact chrome can overlap the app by roughly 100px before its
   safe-area metrics arrive. Reserve that room only in the Mini App. */
@media (max-width: 768px) {
  html.telegram-miniapp {
    --ff-telegram-header-clearance: 72px;
  }

  /* Keep the reservation inside the sticky chrome. Padding the whole app
     creates a detached blank strip as the document scrolls. */
  html.telegram-miniapp body:not(.admin-page) .app-shell {
    padding-top: 0 !important;
  }

  html.telegram-miniapp body:not(.admin-page) .topbar {
    position: -webkit-sticky !important;
    position: sticky !important;
    top: 0 !important;
    /* Stay above app content, but below Telegram's Close/menu controls. */
    z-index: 10 !important;
    padding-top: calc(var(--ff-telegram-header-clearance) + 12px) !important;
  }

  /* Account chrome has a later, more-specific mobile reset. Keep the
     Telegram clearance above that reset without affecting the browser view. */
  html.telegram-miniapp.miniapp-dashboard body.view-accounts-active:not(.admin-page) .topbar {
    padding-top: calc(var(--ff-telegram-header-clearance) + 12px) !important;
  }

  /* Signal supplies its own fixed feed chrome; it must clear Telegram's
     native Close/menu row just like the shared and tournament headers. */
  html.telegram-miniapp body.signal-page-active:not(.admin-page)
    .view-section[data-view="signal"]
    .signal-page-head {
    top: 0 !important;
    height: calc(58px + var(--ff-telegram-header-clearance)) !important;
    min-height: calc(58px + var(--ff-telegram-header-clearance)) !important;
    padding-top: var(--ff-telegram-header-clearance) !important;
  }

  html.telegram-miniapp body.signal-page-active:not(.admin-page)
    .view-section[data-view="signal"].is-feed-chrome-fixed
    .signal-page-head {
    top: 0 !important;
  }

  html.telegram-miniapp body.signal-page-active:not(.admin-page)
    .view-section[data-view="signal"].is-feed-chrome-fixed
    .signal-page-head-spacer {
    height: calc(58px + var(--ff-telegram-header-clearance)) !important;
  }

  html.telegram-miniapp body.signal-page-active:not(.admin-page)
    .view-section[data-view="signal"]
    .signal-sticky-tools {
    top: calc(58px + var(--ff-telegram-header-clearance)) !important;
  }

  /* Never let Signal's media banner show through Telegram's native chrome. */
  html.telegram-miniapp body.signal-page-active:not(.admin-page) .signal-shell-safe-mask {
    display: block !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: calc(58px + var(--ff-telegram-header-clearance)) !important;
    z-index: 8 !important;
    background: #08090b !important;
  }

  /* Trading needs the viewport more than the shared brand bar. The native
     Telegram Close control and the app bottom-nav remain available. */
  html.telegram-miniapp body.view-terminal-active:not(.admin-page) .topbar {
    display: none !important;
  }

  html.telegram-miniapp body.view-terminal-active:not(.admin-page) .content-shell {
    padding-top: 0 !important;
  }

  html.telegram-miniapp body.view-terminal-active:not(.admin-page)
    .view-section[data-view="terminal"]
    .terminal-sticky-quote-bar {
    top: 0 !important;
    padding-top: var(--ff-telegram-header-clearance) !important;
  }
}
