/* ERP Grupo VDF - camada mobile (mobile-erp-2026-09-26)
   Carregada DEPOIS do style.css. Nao altera nada acima de 900px, exceto o fallback do chat.
   Reverter = tirar o <link> do index.html. */

/* ---------- Tablet e celular (<900px) ---------- */
@media (max-width: 899px) {
  html { -webkit-text-size-adjust: 100%; }
  body { overscroll-behavior-y: none; }

  /* iOS da zoom em input com fonte < 16px */
  input, select, textarea { font-size: 16px !important; }

  /* Alvos de toque minimos (44px - Apple HIG / 48dp - Material) */
  .primary, .ghost, .icon-button, .nav-item, .subnav-item { min-height: 44px; }
  .icon-button { min-width: 44px; }
  .actions button { min-height: 36px; padding: 8px 10px; font-size: 12px; }

  /* Topbar enxuta: sobra o essencial */
  .topbar { padding: 0 8px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); gap: 6px; }
  .topbar > strong { font-size: 15px; white-space: nowrap; }
  .topbar .crumb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; font-size: 12px; color: var(--muted); }
  .topbar-user { gap: 4px; margin-left: 0; }
  .topbar-user #user-summary, .topbar-user .global-search, #band-show { display: none !important; }
  #logout-button { padding: 6px 10px; }

  /* Menu lateral vira gaveta por cima de tudo, altura cheia */
  .sidebar { position: fixed !important; z-index: 60 !important; top: 0 !important; bottom: 0; left: -290px; height: 100dvh !important; width: 270px !important; padding-top: max(14px, env(safe-area-inset-top)); transition: left .2s; }
  .sidebar.open { left: 0; }
  body.nav-min .sidebar .nav-item b, .sidebar .nav-item b { display: inline !important; }
  body.nav-min .sidebar .nav-item { justify-content: flex-start; }
  body.nav-min .sidebar footer { display: block; }
  .m-backdrop { position: fixed; inset: 0; z-index: 55; background: #05070dbd; }

  /* Submenu do modulo: faixa horizontal rolavel, logo abaixo da faixa de avisos */
  .subnav { position: sticky !important; z-index: 12; top: 88px !important; width: 100% !important; height: auto !important; flex-direction: row !important; overflow-x: auto; overflow-y: hidden; padding: 6px 8px !important; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  body.sem-faixa .subnav { top: 48px !important; }
  .subnav::-webkit-scrollbar { display: none; }
  .subnav-item { flex: 0 0 auto; width: auto !important; }
  .subnav-item b { display: inline !important; white-space: nowrap; font-size: 12px; }
  .subnav-secao { display: none !important; }

  /* Conteudo: espaco para a barra inferior */
  .content { padding: 14px 12px calc(84px + env(safe-area-inset-bottom)) !important; }
  .content-embed { padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important; }
  .main { min-height: 0 !important; }
  .module-title { display: grid; gap: 8px; margin-bottom: 14px; }
  .module-title h1 { font-size: 22px; }

  /* Tabela larga rola de lado dentro do painel, nunca a pagina */
  .panel, .modal-card { overflow-x: auto; }
  .content table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  .content .table-wrap table { display: table; }
  th, td { padding: 10px 10px; white-space: nowrap; }

  /* Grades de varias colunas: 2 colunas para cartoes, 1 para formularios/leiautes */
  .hero-grid, .est-cards, .fin-quatro, .ficha-saldos, .kardex-cards, .fin-dre-cards, .oc-cards,
  .an-cards, .rel-catalogo, .nf-cards { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .filters, .oc-filtros, .cat-filtros, .aud-filtros, .nf-filtros, .ficha-form-grid, .ajuste-grid,
  .an-grid, .fin-duas, .fin-list-shell, .fin-list-shell.sem-filtro, .rel-trabalho, .aud-layout,
  .av-info, .fin-baixa-top, .fin-baixa-itens header, .fin-baixa-itens article > div,
  .permission-grid, .loja-cards, .loja-access > div, .vd-tops, .seg-grid, .sep-fila,
  .vendas-hub-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .cat-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important; }
  .fin-summary, .fin-filter { position: static !important; }
  .hero-card { min-height: 96px; padding: 14px; }
  .hero-card strong { margin-top: 10px; font-size: 20px; }

  /* Modal vira folha de baixo para cima, tela cheia */
  .modal { padding: 0; place-items: end stretch; }
  .modal-card { width: 100% !important; max-width: 100% !important; max-height: 94dvh; border-radius: 16px 16px 0 0; padding: 18px 14px calc(18px + env(safe-area-inset-bottom)); }
  .modal-actions { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); background: var(--panel); padding: 10px 0; margin-top: 16px; flex-wrap: wrap; }
  .modal-actions button { flex: 1 1 auto; }

  .toast { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); text-align: center; }

  /* Mensagens: no celular abre como tela cheia pelo 💬 */
  body.m-chat-open .messages { display: flex !important; position: fixed !important; z-index: 70; inset: 0; top: 0 !important; width: 100% !important; height: 100dvh !important; border: 0; padding-bottom: env(safe-area-inset-bottom); }
  body.m-chat-open .messages.collapsed > * { display: revert; }
  .m-chat-fechar { display: none; }
  body.m-chat-open .m-chat-fechar { display: inline-flex; align-items: center; justify-content: center; }
  .msg-form { padding-bottom: env(safe-area-inset-bottom); }

  /* Barra inferior de navegacao */
  .m-tabbar { position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; gap: 2px; padding: 4px 4px env(safe-area-inset-bottom); background: #121927f7; border-top: 1px solid var(--line); backdrop-filter: blur(12px); }
  .m-tabbar button { flex: 1; min-width: 0; min-height: 54px; display: grid; place-items: center; gap: 1px; padding: 4px 2px; border: 0; border-radius: 10px; background: transparent; color: #b7c0d0; position: relative; }
  .m-tabbar button.active { color: #fff; background: #21375f; }
  .m-tabbar button span { font-size: 19px; line-height: 1; }
  .m-tabbar button b { font-size: 10px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .m-tabbar button[data-badge]:not([data-badge=""])::after { content: attr(data-badge); position: absolute; top: 4px; right: calc(50% - 20px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--red); color: #fff; font-size: 10px; line-height: 16px; }
  body.m-chat-open .m-tabbar, .modal:not(.hidden) ~ .m-tabbar, #app-view.hidden ~ .m-tabbar { display: none; }
}

/* Celular estreito */
@media (max-width: 520px) {
  .topbar > strong { display: none; }
  .hero-grid, .est-cards, .fin-quatro, .ficha-saldos, .kardex-cards, .oc-cards, .an-cards, .nf-cards { gap: 8px !important; }
  .kpi-card { min-width: 130px; }
  .panel-title { padding: 12px 12px; flex-wrap: wrap; gap: 6px; }
  .login-card { padding: 26px 18px; }
}

/* Barra inferior nao existe no desktop */
@media (min-width: 900px) { .m-tabbar, .m-backdrop, .m-chat-fechar { display: none !important; } }
