/*
 * OPERA - Mobile Global
 * Fase 47
 *
 * Camada responsiva compartilhada.
 * Preserva desktop e permissoes por empresa.
 */

/* TABLETS E CELULARES */
@media (max-width: 900px) {

  #app.app-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  #app .main-area {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    margin-left: 0;
  }

  #app #sidebar {
    width: min(88vw, 320px) !important;
    min-width: 0 !important;
    max-width: 320px !important;
    height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  #app #sidebar .nav-item {
    min-height: 44px;
    touch-action: manipulation;
  }

  #app #pagesContainer {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 16px !important;
  }

  #app #pagesContainer > .page-content {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
  }

  #app .page-content .grid > * {
    min-width: 0;
  }

  #app .table-wrapper,
  #app .overflow-x-auto {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  #app input,
  #app select,
  #app textarea {
    max-width: 100%;
    box-sizing: border-box;
  }

  #app img,
  #app video,
  #app canvas {
    max-width: 100%;
  }

  /* Janelas e formularios modais */
  .modal-bg .modal-box,
  .modal-backdrop .modal-box {
    box-sizing: border-box;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* CELULARES */
@media (max-width: 640px) {

  #app .main-area > header {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 10px 12px !important;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
  }

  #app .main-area > header > div {
    min-width: 0;
    max-width: 100%;
  }

  #app .main-area > header > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
  }

  #app #sidebarTopToggle {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    min-height: 40px;
    touch-action: manipulation;
  }

  #app #globalSearch {
    box-sizing: border-box;
    min-width: 0;
    width: 100% !important;
    max-width: 100%;
    font-size: 16px;
  }

  #app #empresaContextoHeader {
    min-width: 0 !important;
    max-width: 100%;
  }

  #app #empresaContextoHeader select {
    max-width: 100%;
    font-size: 16px;
  }

  #app #pagesContainer {
    padding: 12px !important;
  }

  #app #pagesContainer > .page-content {
    padding: 8px 0 !important;
  }

  /* Cabecalhos comuns das paginas */
  #app .page-content > .flex.items-center.justify-between {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 12px;
  }

  #app .page-content h1 {
    max-width: 100%;
    overflow-wrap: anywhere;
    line-height: 1.25;
  }

  /* Formularios */
  #app .page-content input:not([type="checkbox"]):not([type="radio"]),
  #app .page-content select,
  #app .page-content textarea {
    min-height: 42px;
    max-width: 100%;
    font-size: 16px;
  }

  #app .page-content textarea {
    min-height: 96px;
  }

  #app .page-content button {
    touch-action: manipulation;
  }

  /* Tabelas mantem suas colunas e podem rolar
     dentro do proprio componente. */
  #app .page-content .table-wrapper,
  #app .page-content .overflow-x-auto {
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
  }

  /* Cartoes nunca ultrapassam o container. */
  #app .page-content article,
  #app .page-content .rounded-xl {
    min-width: 0;
  }

  /* Modal adaptado a altura util da tela */
  .modal-bg .modal-box,
  .modal-backdrop .modal-box {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    padding: 16px;
    border-radius: 16px;
  }

  .modal-bg input:not([type="checkbox"]):not([type="radio"]),
  .modal-bg select,
  .modal-bg textarea {
    max-width: 100%;
    font-size: 16px;
  }
}

/* TELAS MUITO ESTREITAS */
@media (max-width: 390px) {

  #app #pagesContainer {
    padding: 8px !important;
  }

  #app .main-area > header {
    padding: 8px !important;
  }

  #app .page-content h1 {
    font-size: 21px;
  }
}

/* AREA SEGURA PARA PWA EM IOS */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 900px) {
    #app #pagesContainer {
      padding-bottom:
        calc(18px + env(safe-area-inset-bottom)) !important;
    }

    #app #sidebar {
      padding-bottom:
        env(safe-area-inset-bottom);
    }
  }
}


/* OPERA MOBILE - FASE 48 - EMPRESA */

/*
 * Reorganiza apenas o header mobile.
 * Preserva o seletor empresarial existente.
 */

@media (max-width: 640px) {

  #app .main-area > header {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px !important;
    padding: 10px 12px !important;
    height: auto !important;
    min-height: 60px !important;
    overflow: visible !important;
  }

  /* Primeira linha: menu e busca. */
  #app .main-area > header > div:first-child {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* Grupo com empresa e notificacoes. */
  #app .main-area > header > div:nth-child(2) {
    display: flex !important;
    flex: 1 1 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* Seletor da empresa ativa. */
  #app #empresaContextoHeader {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    flex: 1 1 180px !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  #app #empresaContextoHeader > * {
    max-width: 100% !important;
    min-width: 0 !important;
  }

  #app #empresaContextoHeader select,
  #app #empresaContextoHeader button {
    box-sizing: border-box !important;
    max-width: 100% !important;
    min-height: 42px !important;
    font-size: 16px !important;
  }

  #app #empresaContextoHeader select {
    width: 100% !important;
  }

  /* Notificacoes continuam acessiveis. */
  #app #notificationBellBtn {
    flex-shrink: 0 !important;
  }

}

/* Tablets */
@media (min-width: 641px) and (max-width: 900px) {

  #app #empresaContextoHeader {
    display: block !important;
    visibility: visible !important;
    min-width: 180px !important;
    max-width: 100% !important;
  }

}
