/* ========================================
   SISTEMA MOBILE PROFISSIONAL - ANTECH O&M
   Versão: 3.0.0
   Data: 2025-11-12
   Responsável: Otimização completa mobile
   ======================================== */

/* ========================================
   1. FUNDAMENTOS E RESET
   ======================================== */

/* Prevenir scroll horizontal em TODOS os elementos */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  overflow-x: hidden !important;
  max-width: 100vw;
  position: relative;
  min-height: 100vh;
  margin: 0;
  padding: 0;
}

#app {
  overflow-x: hidden !important;
  max-width: 100vw;
  min-height: 100vh;
}

/* Prevenir zoom indesejado em inputs (iOS) */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
    max-width: 100%;
  }
  
  /* Prevenir zoom em double-tap */
  a, button, [role="button"] {
    touch-action: manipulation;
  }
}

/* ========================================
   2. SIDEBAR MOBILE (OVERLAY)
   ======================================== */

@media (max-width: 768px) {
  /* Sidebar como overlay fixo */
  #sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 85% !important;
    max-width: 320px !important;
    z-index: 1000 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.3);
  }
  
  #sidebar.mobile-open {
    transform: translateX(0) !important;
  }
  
  /* Forçar menu completo (com textos) */
  #sidebar nav button span,
  #sidebar nav h3,
  #sidebar .flex-1 {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
  }
  
  /* Espaçamento adequado */
  #sidebar nav button {
    padding: 0.875rem 1rem !important;
    margin-bottom: 0.375rem !important;
    border-radius: 0.5rem !important;
    min-height: 44px !important;
  }
  
  /* Ícones */
  #sidebar nav button i {
    font-size: 1.25rem !important;
    margin-right: 1rem !important;
    width: 1.5rem !important;
    text-align: center;
  }
  
  /* Textos */
  #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;
  }
}

/* Overlay */
@media (max-width: 768px) {
  #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: 999 !important;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
  }
  
  #sidebar-overlay.active {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
}

/* ========================================
   3. HEADER MOBILE
   ======================================== */

@media (max-width: 768px) {
  header {
    position: sticky !important;
    top: 0 !important;
    z-index: 900 !important;
    padding: 0.75rem 1rem !important;
    background: white !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
  }
  
  /* Botão hambúrguer */
  header button.hamburger {
    min-width: 44px !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 0.5rem !important;
    margin-right: 0.75rem;
  }
  
  /* Título do header */
  header h2 {
    font-size: 1.125rem !important;
    line-height: 1.3 !important;
    margin: 0 !important;
  }
  
  /* Subtítulo (ocultar em mobile pequeno) */
  header p {
    display: none !important;
  }
  
  /* Botões do header */
  header button {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 0.875rem !important;
  }
  
  /* Avatar do usuário */
  header .w-9, header .w-11 {
    width: 2.25rem !important;
    height: 2.25rem !important;
    font-size: 1rem !important;
  }
}

/* ========================================
   4. MAIN CONTENT (ÁREA PRINCIPAL)
   ======================================== */

@media (max-width: 768px) {
  main {
    width: 100% !important;
    margin-left: 0 !important;
    padding: 1rem !important;
    overflow-x: hidden;
  }
  
  /* Conteúdo interno */
  #content, #main-content {
    max-width: 100% !important;
    overflow-x: hidden;
  }
}

/* ========================================
   5. TABELAS MOBILE (SCROLL HORIZONTAL)
   ======================================== */

@media (max-width: 768px) {
  /* Container de tabela com scroll */
  .table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  
  table {
    min-width: 600px;
    width: 100%;
    display: table !important;
  }
  
  /* Cabeçalho sticky */
  thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: white;
  }
  
  /* Células */
  th, td {
    padding: 0.75rem !important;
    font-size: 0.875rem !important;
    white-space: nowrap;
  }
  
  th {
    font-weight: 600 !important;
  }
  
  /* Ações em tabela (botões) */
  td button {
    min-width: 36px !important;
    min-height: 36px !important;
    padding: 0.375rem 0.5rem !important;
    font-size: 0.8125rem !important;
    margin: 0 0.125rem !important;
  }
}

/* Alternativa: Tabelas como cards em mobile */
@media (max-width: 640px) {
  .table-as-cards {
    display: block !important;
  }
  
  .table-as-cards thead {
    display: none !important;
  }
  
  .table-as-cards tbody {
    display: block !important;
  }
  
  .table-as-cards tr {
    display: block !important;
    margin-bottom: 1rem !important;
    padding: 1rem !important;
    background: white !important;
    border-radius: 0.5rem !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
  }
  
  .table-as-cards td {
    display: block !important;
    padding: 0.5rem 0 !important;
    text-align: left !important;
    border: none !important;
  }
  
  .table-as-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    display: block;
    margin-bottom: 0.25rem;
    color: #6b7280;
    font-size: 0.75rem;
    text-transform: uppercase;
  }
}

/* ========================================
   6. MODAIS MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Modal responsivo */
  .modal, [class*="modal"] {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh !important;
    margin: 5vh auto !important;
    overflow-y: auto !important;
    border-radius: 0.75rem !important;
  }
  
  /* Header do modal */
  .modal-header, [class*="modal"] > div:first-child {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
    background: white !important;
    padding: 1rem !important;
    border-bottom: 1px solid #e5e7eb;
  }
  
  /* Título do modal */
  .modal-header h3, .modal h3 {
    font-size: 1.125rem !important;
    line-height: 1.3 !important;
  }
  
  /* Conteúdo do modal */
  .modal-body, .modal-content {
    padding: 1rem !important;
  }
  
  /* Footer do modal */
  .modal-footer, [class*="modal"] > div:last-child {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 10 !important;
    background: white !important;
    padding: 1rem !important;
    border-top: 1px solid #e5e7eb;
  }
  
  /* Botões do modal */
  .modal button {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 0.75rem 1rem !important;
    font-size: 0.9375rem !important;
  }
  
  /* Modal fullscreen em mobile pequeno */
  @media (max-width: 640px) {
    .modal-fullscreen-mobile {
      width: 100vw !important;
      max-width: 100vw !important;
      height: 100vh !important;
      max-height: 100vh !important;
      margin: 0 !important;
      border-radius: 0 !important;
    }
  }
}

/* ========================================
   7. FORMULÁRIOS MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Grid de formulário - sempre 1 coluna */
  .form-grid, .grid-cols-2, .grid-cols-3, .grid-cols-4,
  .md\\:grid-cols-2, .md\\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }
  
  /* Labels */
  label {
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    margin-bottom: 0.375rem !important;
    display: block !important;
  }
  
  /* Inputs */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    width: 100% !important;
    min-height: 44px !important;
    padding: 0.75rem !important;
    font-size: 16px !important;
    border-radius: 0.5rem !important;
    border: 2px solid #e5e7eb !important;
    transition: border-color 0.2s !important;
  }
  
  input:focus, select:focus, textarea:focus {
    outline: none !important;
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
  }
  
  /* Textarea */
  textarea {
    min-height: 100px !important;
    resize: vertical !important;
  }
  
  /* Select */
  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E") !important;
    background-position: right 0.75rem center !important;
    background-repeat: no-repeat !important;
    background-size: 1.5em !important;
    padding-right: 2.5rem !important;
  }
  
  /* Checkbox e Radio */
  input[type="checkbox"],
  input[type="radio"] {
    min-width: 20px !important;
    min-height: 20px !important;
    margin-right: 0.5rem !important;
  }
  
  /* Botões de submit */
  button[type="submit"],
  .btn-submit {
    width: 100% !important;
    min-height: 48px !important;
    padding: 0.875rem 1.5rem !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    border-radius: 0.5rem !important;
    margin-top: 1rem !important;
  }
}

/* ========================================
   8. CARDS E DASHBOARDS
   ======================================== */

@media (max-width: 768px) {
  /* Cards responsivos */
  .card, [class*="card"] {
    margin-bottom: 1rem !important;
    padding: 1rem !important;
    border-radius: 0.75rem !important;
  }
  
  /* Grid de cards - sempre 1 coluna em mobile */
  .cards-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
  
  /* Estatísticas/métricas */
  .stat-card {
    padding: 1rem !important;
  }
  
  .stat-card h3 {
    font-size: 0.875rem !important;
  }
  
  .stat-card .value {
    font-size: 1.5rem !important;
  }
}

/* ========================================
   9. BOTÕES MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Botões touch-friendly */
  button, .btn, a[role="button"] {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 0.625rem 1rem !important;
    font-size: 0.9375rem !important;
    border-radius: 0.5rem !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.5rem !important;
    transition: all 0.2s !important;
  }
  
  /* Ícones em botões */
  button i, .btn i {
    font-size: 1.125rem !important;
  }
  
  /* Botões pequenos (ícone-only) */
  .btn-icon {
    width: 44px !important;
    height: 44px !important;
    padding: 0.5rem !important;
  }
  
  /* Grupo de botões */
  .button-group {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
  }
  
  .button-group button {
    width: 100% !important;
  }
}

/* ========================================
   10. NOTIFICAÇÕES TOAST
   ======================================== */

@media (max-width: 768px) {
  .toast, [class*="toast"] {
    position: fixed !important;
    bottom: 1rem !important;
    left: 1rem !important;
    right: 1rem !important;
    width: auto !important;
    max-width: none !important;
    z-index: 9999 !important;
    padding: 1rem !important;
    border-radius: 0.75rem !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2) !important;
    font-size: 0.9375rem !important;
  }
}

/* ========================================
   11. GRID SYSTEM RESPONSIVO
   ======================================== */

/* Mobile: 1 coluna */
@media (max-width: 640px) {
  .grid,
  .grid-cols-1, .grid-cols-2, .grid-cols-3, .grid-cols-4,
  .md\\:grid-cols-2, .md\\:grid-cols-3, .md\\:grid-cols-4 {
    grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
  }
}

/* Tablet: 2 colunas */
@media (min-width: 641px) and (max-width: 1024px) {
  .grid-cols-3, .grid-cols-4,
  .md\\:grid-cols-3, .md\\:grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* ========================================
   12. UTILIDADES MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Ocultar elementos em mobile */
  .hidden-mobile {
    display: none !important;
  }
  
  /* Mostrar apenas em mobile */
  .show-mobile {
    display: block !important;
  }
  
  /* Texto menor em mobile */
  .text-responsive {
    font-size: 0.875rem !important;
  }
  
  /* Espaçamento reduzido */
  .p-mobile {
    padding: 1rem !important;
  }
  
  .m-mobile {
    margin: 1rem !important;
  }
}

/* ========================================
   13. SCROLLBAR CUSTOMIZADA (WEBKIT)
   ======================================== */

@media (min-width: 1024px) {
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  
  ::-webkit-scrollbar-track {
    background: #f1f5f9;
  }
  
  ::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
  }
  
  ::-webkit-scrollbar-thumb:hover {
    background: #64748b;
  }
}

/* ========================================
   14. SAFE AREA (iOS NOTCH)
   ======================================== */

@supports (padding: max(0px)) {
  body {
    padding-top: max(0px, env(safe-area-inset-top));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  header {
    padding-top: max(0.75rem, env(safe-area-inset-top)) !important;
  }
  
  #sidebar {
    padding-top: max(1rem, env(safe-area-inset-top)) !important;
    padding-bottom: max(1rem, env(safe-area-inset-bottom)) !important;
  }
}

/* ========================================
   15. ACESSIBILIDADE
   ======================================== */

/* Foco visível */
*:focus-visible {
  outline: 2px solid #3b82f6 !important;
  outline-offset: 2px !important;
}

/* Reduzir movimento (preferência do usuário) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Modo escuro (preferência do usuário) */
@media (prefers-color-scheme: dark) {
  /* Pode ser implementado no futuro */
}

/* ========================================
   16. PERFORMANCE E OTIMIZAÇÕES
   ======================================== */

/* GPU acceleration para animações */
.animated, .transition {
  will-change: transform;
  transform: translateZ(0);
}

/* Scroll suave iOS */
* {
  -webkit-overflow-scrolling: touch;
}

/* Prevenir seleção de texto em botões */
button, .btn {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* ========================================
   17. CORREÇÕES ESPECÍFICAS
   ======================================== */

@media (max-width: 768px) {
  /* Prevenir elementos largos */
  img, video, iframe {
    max-width: 100% !important;
    height: auto !important;
  }
  
  /* Código e pre */
  pre, code {
    max-width: 100% !important;
    overflow-x: auto !important;
    font-size: 0.75rem !important;
  }
  
  /* Listas */
  ul, ol {
    padding-left: 1.5rem !important;
  }
  
  /* Dividers */
  hr {
    margin: 1rem 0 !important;
  }
}

/* ========================================
   FIM DO ARQUIVO
   ======================================== */
