/* ============================================================
   MadSSolutions · mobile-fixes.css
   Correções defensivas para Android e iOS · incluir em TODOS os gestores e no portal
   ============================================================ */

/* iOS — evitar zoom automático ao focar inputs (precisa font-size >= 16px) */
@media (max-width: 768px) {
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="date"],
  input[type="search"],
  input[type="url"],
  select,
  textarea,
  #ac-input {
    font-size: 16px !important;
  }
}

/* Touch targets — mínimo 44px (Apple HIG) e 48px (Material) */
@media (max-width: 768px) {
  .icon-btn,
  .btn-icon,
  .sb-toggle,
  .theme-toggle,
  button[class*="btn"],
  .tab,
  .filtro {
    min-width: 44px;
    min-height: 44px;
  }

  /* botões textuais não precisam ser quadrados, mas precisam ter altura confortável */
  button.btn,
  a.btn,
  button.btn-primary,
  a.btn-primary,
  button.btn-ghost,
  a.btn-ghost {
    min-height: 44px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
}

/* Sidebar mobile — garantir overlay tocável e fundo escuro */
@media (max-width: 900px) {
  .sb-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 49;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
  aside.open + .sb-backdrop,
  .sb-backdrop.show {
    display: block;
  }
}

/* Tabelas largas — scroll horizontal em vez de quebrar layout */
@media (max-width: 768px) {
  .panel table,
  .pn-card table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
}

/* Chat flutuante mobile — full width */
@media (max-width: 768px) {
  #agent-chat:not(.hidden) {
    width: 100vw !important;
    max-width: 100vw !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    border-radius: 16px 16px 0 0 !important;
    height: 70vh !important;
  }
}

/* Topbar mobile — não estourar nunca · empilhar antes de cortar */
@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 10px 12px !important;
    overflow: hidden !important;
    max-width: 100% !important;
  }
  .topbar h2,
  .topbar #page-title {
    font-size: 15px !important;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar .conn,
  .topbar .badge-status {
    font-size: 10px !important;
    padding: 3px 8px !important;
  }
  .topbar .icon-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    flex-shrink: 0 !important;
  }
  .topbar .sb-toggle {
    flex-shrink: 0 !important;
  }
}
@media (max-width: 480px) {
  .topbar {
    padding: 8px 10px !important;
  }
  .topbar h2,
  .topbar #page-title {
    font-size: 14px !important;
  }
  /* No celular pequeno · esconde os botões de notificação/ajuda · mantém só toggle, logo, título e tema */
  .topbar .icon-btn:nth-of-type(2),
  .topbar .icon-btn:nth-of-type(3) {
    display: none !important;
  }
  .topbar .conn,
  .topbar .badge-status {
    font-size: 9px !important;
    padding: 2px 6px !important;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Garante que main não tem overflow horizontal estourando */
@media (max-width: 900px) {
  main, #content, .layout {
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
}

/* Portal — hero e seções respeitam padding em telas pequenas */
@media (max-width: 480px) {
  section,
  .section {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
  .hero h1,
  .hero-setor h1 {
    font-size: clamp(28px, 8vw, 42px) !important;
    line-height: 1.1 !important;
  }
}

/* Cards de produto / cardápio — grid se ajusta sem cortar */
@media (max-width: 380px) {
  .lista-cards,
  .kpis,
  .cardapio-grid,
  #tp-results {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
}

/* Acessibilidade — reduce motion para quem habilita */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Safe area iOS notch */
@supports (padding-top: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* iOS Safari · upload de arquivo (label clicável precisa cobrir toda a área)
   APENAS .upload · não afeta outros labels ou inputs */
@media (max-width: 768px) {
  label.upload {
    -webkit-tap-highlight-color: rgba(255,195,0,0.2);
    cursor: pointer;
  }
  label.upload input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
  }
}

/* Botões com gradient · forçar hardware acceleration no iOS evita flash branco */
@media (max-width: 768px) {
  button.btn,
  a.btn,
  .float-btn,
  .btn-primary,
  .cta-nav {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
}

/* Android Chrome · scroll horizontal de tabs (cardápio · setores) */
@media (max-width: 768px) {
  .tabs,
  .filtros,
  .setor-tags {
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
  }
  .tab,
  .filtro,
  .setor-tag {
    scroll-snap-align: start;
  }
}

/* Forçar fontes legíveis no iOS Safari low-power mode */
@media (max-width: 768px) {
  body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
}

/* Background gradient com -webkit-background-clip:text (logo, acentos)
   Em alguns Android antigos não renderiza · fallback pra cor sólida */
@media (max-width: 768px) {
  @supports not (-webkit-background-clip: text) {
    .acento, .ss, .nome-grupo {
      background: none !important;
      color: var(--am, #FFC300) !important;
    }
  }
}

/* Pre/code overflow no mobile · não quebrar layout */
@media (max-width: 768px) {
  pre, code, .json-box {
    word-break: break-all;
    white-space: pre-wrap;
    max-width: 100%;
    overflow-x: auto;
  }
}

/* Drawer sidebar no mobile · z-index acima de tudo */
@media (max-width: 900px) {
  aside,
  aside#sidebar {
    z-index: 1000 !important;
  }
  .sb-backdrop {
    z-index: 999 !important;
  }
}

/* Evitar shift quando teclado mobile abre */
@media (max-width: 768px) {
  body {
    min-height: 100vh;
    min-height: 100dvh; /* dynamic viewport height · iOS 16+, Android Chrome */
  }
}

/* Imagens de produto / cardápio · não distorcer no mobile */
@media (max-width: 768px) {
  .item .foto img,
  .tp-prod img,
  .preview {
    object-fit: contain !important;
    background: #fff;
  }
}
