/* ========================================
   CORREÇÕES MOBILE - SISTEMA ANTECH O&M
   ======================================== */

/* Garantir que o body não tenha scroll horizontal */
body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* Container principal - prevenir overflow */
#app {
  overflow-x: hidden;
  max-width: 100vw;
}

/* Mobile: Sidebar como overlay */
@media (max-width: 768px) {
  /* Sidebar fixa e ocupando toda altura */
  #sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 85% !important;
    max-width: 320px !important;
    z-index: 50 !important;
    transform: translateX(-100%) !important;
  }
  
  /* Sidebar aberta */
  #sidebar.mobile-open {
    transform: translateX(0) !important;
  }
  
  /* FORÇAR menu completo (com textos) em mobile */
  #sidebar nav button span,
  #sidebar nav h3,
  #sidebar .flex-1 {
    display: block !important;
    opacity: 1 !important;
  }
  
  /* Espaçamento adequado para itens do menu */
  #sidebar nav button {
    padding: 0.875rem 1rem !important;
    margin-bottom: 0.375rem !important;
    border-radius: 0.5rem !important;
  }
  
  /* Ícones com tamanho maior e espaçamento */
  #sidebar nav button i {
    font-size: 1.25rem !important;
    margin-right: 1rem !important;
    width: 1.5rem !important;
    text-align: center;
  }
  
  /* Textos dos itens */
  #sidebar nav button span {
    font-size: 0.9375rem !important;
    font-weight: 500 !important;
    line-height: 1.4 !important;
  }
  
  /* Títulos de seção */
  #sidebar nav h3 {
    font-size: 0.6875rem !important;
    letter-spacing: 0.075em !important;
    padding: 0.5rem 1rem !important;
    margin-top: 1rem !important;
    margin-bottom: 0.625rem !important;
    color: #93c5fd !important;
    border-left: 3px solid #3b82f6;
  }
  
  /* Header do sidebar com logo */
  #sidebar > div > div:first-child {
    padding: 1.25rem 1rem !important;
    margin-bottom: 0.5rem !important;
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
  }
  
  /* Logo e título */
  #sidebar h1 {
    font-size: 1.375rem !important;
    font-weight: 700 !important;
  }
  
  /* Botão de fechar (X) em mobile */
  #sidebar button[onclick="toggleSidebar()"] {
    background: rgba(239, 68, 68, 0.2) !important;
    padding: 0.5rem !important;
    border-radius: 0.5rem !important;
    transition: all 0.2s !important;
  }
  
  #sidebar button[onclick="toggleSidebar()"]:hover {
    background: rgba(239, 68, 68, 0.3) !important;
  }
  
  #sidebar button[onclick="toggleSidebar()"] i {
    color: #fca5a5 !important;
  }
  
  /* Rodapé com perfil do usuário */
  #sidebar > div:last-child {
    padding: 1rem !important;
    background: rgba(30, 58, 138, 0.5) !important;
    border-top: 1px solid rgba(59, 130, 246, 0.3) !important;
  }
  
  /* Avatar do usuário */
  #sidebar .w-10.h-10 {
    width: 2.75rem !important;
    height: 2.75rem !important;
    font-size: 1.125rem !important;
  }
  
  /* Submenus */
  #sidebar nav button + div {
    margin-left: 2.5rem !important;
    margin-top: 0.375rem !important;
    padding-left: 0.75rem !important;
    border-left: 2px solid rgba(59, 130, 246, 0.3);
  }
  
  #sidebar nav button + div button {
    padding: 0.625rem 0.875rem !important;
    font-size: 0.875rem !important;
  }
  
  /* Hover states */
  #sidebar nav button:hover {
    background: rgba(59, 130, 246, 0.25) !important;
    transform: translateX(4px);
    transition: all 0.2s !important;
  }
  
  #sidebar nav button:active {
    transform: translateX(2px) scale(0.98);
  }
  
  /* Efeito de ripple ao clicar */
  #sidebar nav button {
    position: relative;
    overflow: hidden;
  }
  
  /* Scroll suave no menu */
  #sidebar > div > div {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Separador visual entre seções */
  #sidebar nav > div:not(:last-child) {
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid rgba(59, 130, 246, 0.15);
  }
  
  /* Melhorar contraste dos ícones */
  #sidebar nav button i {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
  }
  
  /* Feedback tátil (haptic) visual */
  #sidebar nav button:active i {
    transform: scale(0.9);
    transition: transform 0.1s;
  }
  
  /* Overlay para fechar sidebar */
  #sidebar-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    z-index: 40 !important;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
  }
  
  #sidebar-overlay.active {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  
  /* Main content ocupa tela toda */
  main {
    width: 100% !important;
    margin-left: 0 !important;
  }
  
  /* Header responsivo */
  header {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
  
  /* Botões no header menores */
  header button {
    padding: 0.5rem !important;
  }
  
  /* Cards e conteúdo responsivo */
  .card {
    padding: 1rem !important;
  }
  
  /* Tabelas scroll horizontal */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  
  /* Formulários em mobile */
  .form-grid {
    grid-template-columns: 1fr !important;
  }
  
  /* Modais em mobile */
  .modal {
    width: 95% !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }
}

/* Tablet (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
  #sidebar {
    width: 240px !important;
  }
  
  .card {
    padding: 1.25rem !important;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  #sidebar {
    position: relative !important;
  }
}

/* Correções de scroll suave */
* {
  -webkit-overflow-scrolling: touch;
}

/* Prevenir zoom em inputs mobile */
@media (max-width: 768px) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* Botões touch-friendly */
@media (max-width: 768px) {
  button,
  a {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Icones maiores em mobile */
  .fa,
  .fas {
    font-size: 1.125rem;
  }
}

/* Correção do menu hamburguer */
@media (max-width: 768px) {
  .hamburger-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
  }
}

/* Status bar iOS safe area */
@supports (padding: max(0px)) {
  header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }
  
  #sidebar {
    padding-top: max(1rem, env(safe-area-inset-top));
  }
}

/* Animações suaves */
.sidebar-transition {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Em mobile, apenas transição de transform */
@media (max-width: 768px) {
  .sidebar-transition {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }
}

/* Prevenir seleção de texto em botões mobile */
@media (max-width: 768px) {
  button {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
}

/* Grid responsivo para cards */
@media (max-width: 640px) {
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
  }
}

@media (min-width: 640px) and (max-width: 1024px) {
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* Scroll bar estilizada para desktop */
@media (min-width: 1024px) {
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  
  ::-webkit-scrollbar-track {
    background: #f1f1f1;
  }
  
  ::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
  }
  
  ::-webkit-scrollbar-thumb:hover {
    background: #555;
  }
}

/* Loading spinner centralizado */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

/* Toast notifications mobile */
@media (max-width: 768px) {
  .toast {
    left: 1rem !important;
    right: 1rem !important;
    bottom: 1rem !important;
    width: auto !important;
  }
}
