/* #1122 — Scroll do menu lateral no mobile.
   Arquivo SEPARADO de propósito: o style.css é precacheado pelo service worker (cache-first), então
   a correção colocada lá ficava presa no cache antigo do app. Este arquivo NÃO está no PRECACHE do
   sw.js → o SW o busca fresco da rede → a correção chega ao aparelho SEM reinstalar/limpar cache. */
@media (max-width: 991.98px) {
  /* Nunca bloqueie o scroll root por causa do drawer. Estas classes podem
     reaparecer por uma página restaurada do bfcache ou por script.js antigo
     ainda residente no PWA. Neutralizá-las no CSS evita uma tela morta mesmo
     antes do JS de compatibilidade conseguir limpar o estado legado. */
  html.sidebar-menu-open {
    overflow-y: auto !important;
    height: auto !important;
  }

  #sidebar {
    position: fixed !important;
    top: 0 !important;
    right: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    height: 100svh !important;
    height: 100dvh !important;
    height: var(--kimori-menu-height, 100dvh) !important;
    max-height: 100vh !important;
    max-height: 100svh !important;
    max-height: 100dvh !important;
    max-height: var(--kimori-menu-height, 100dvh) !important;
    /* O drawer inteiro é o único scroll container. No Safari/iOS, um
       overflow dentro de um elemento fixed cria uma cadeia de hit-test frágil:
       dependendo do item onde o gesto começa, o pan fica preso no ancestral. */
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: contain !important;
    touch-action: pan-y !important;
  }

  .wrapper:not(.sidebar-mobile-open) #sidebar {
    transform: translateX(calc(var(--sidebar-width) * -1)) !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  #sidebar,
  .sidebar-overlay {
    transition: none !important;
  }

  .wrapper.sidebar-mobile-open #sidebar {
    transform: none !important;
    visibility: visible !important;
    z-index: 1060 !important;
    pointer-events: auto !important;
  }

  /* v22 — o conteúdo atrás não recebe toque. O body NÃO é mais position:fixed:
     no WebKit, body fixed + um scroller filho fixed faz o gesto depender do ponto
     exato onde o touch começou e trava depois de algumas interações. */
  .wrapper.sidebar-mobile-open #page-content-wrapper {
    pointer-events: none !important;
    overflow: hidden !important;
  }

  .wrapper.sidebar-mobile-open #content-header {
    z-index: 1070 !important;
    pointer-events: auto !important;
  }

  /* #2450 — #content-header (z-index 1070, acima do drawer, regra logo acima)
     precisa ficar por cima só pra manter o botão hambúrguer clicável — mas isso
     também levava junto a tarja laranja de ponto (.topbar-header-alert, filha de
     #content-header), que ficava sobreposta ao drawer (#sidebar, z-index 1060)
     tampando a busca/topo da lista de menu. Recolhe só a tarja enquanto o drawer
     está aberto; ela reaparece ao fechar (o resto de #content-header continua
     visível/clicável normalmente). */
  .wrapper.sidebar-mobile-open .topbar-header-alert {
    display: none !important;
  }

  /* v19 — overlay full-screen (inset:0) captura toque SOBRE o drawer no iOS mesmo com
     z-index menor que #sidebar → scroll só “funciona” na borda/canto. Cobrir só a área
     escurecida à direita do menu; toques no drawer nunca batem no overlay. */
  .wrapper.sidebar-mobile-open .sidebar-overlay {
    inset: auto !important;
    left: var(--sidebar-width) !important;
    right: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: auto !important;
    z-index: 1040 !important;
    touch-action: none !important;
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-overlay {
    z-index: 1040 !important;
    -webkit-tap-highlight-color: transparent;
  }

  .wrapper.sidebar-mobile-open #sidebar,
  .wrapper.sidebar-mobile-open #sidebar * {
    pointer-events: auto !important;
  }

  #sidebarCollapse.btn-toggle {
    position: relative !important;
    z-index: 3 !important;
    min-width: 44px !important;
    min-height: 44px !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent;
  }

  body.sidebar-no-scroll {
    position: static !important;
    inset: auto !important;
    width: auto !important;
    overflow-y: auto !important;
  }

  #sidebar .sidebar-sticky-shell {
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    height: auto !important;
    min-height: 100% !important;
    max-height: none !important;
    padding-top: 0 !important;
    overflow: visible !important;
  }

  #sidebar .sidebar-menu-mode-panels,
  #sidebar .sidebar-menu-mode-view {
    display: flex !important;
    flex-direction: column !important;
    flex: 0 0 auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  /* A lista participa do fluxo normal. O scroll pertence ao drawer, evitando
     dois candidatos ao mesmo gesto vertical no WebKit. */
  #sidebar ul.components {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    -webkit-overflow-scrolling: auto !important;
    touch-action: pan-y !important;
  }

  /* Os wrappers também não podem virar scroll layers implícitos no WebKit. */
  #sidebar .sidebar-sticky-shell,
  #sidebar .sidebar-menu-mode-panels,
  #sidebar .sidebar-menu-mode-view {
    -webkit-overflow-scrolling: auto !important;
  }

  #sidebar ul.components * {
    touch-action: pan-y !important;
  }

  .wrapper.sidebar-mobile-open .app-footer-fab,
  .wrapper.sidebar-mobile-open .fin-edge {
    display: none !important;
  }
}
