/* =========================================
   UI/UX MOBILE REDESIGN (Media Queries)
   Glow Manager
   ========================================= */

@media screen and (max-width: 768px) {
  
  /* Remove o "quadrado azul" padrão dos navegadores ao tocar na tela */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* 1. Sidebar to Overlay Menu (Drawer) */
  .sidebar {
    position: fixed;
    top: 0;
    left: auto !important;
    right: -100%;
    bottom: 0;
    z-index: 1000;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -5px 0 25px rgba(0,0,0,0.15);
    width: 280px;
    background-color: var(--bg-sidebar);
  }
  .sidebar.mobile-open {
    right: 0;
  }
  
  /* Overlays */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 999;
    backdrop-filter: blur(2px);
  }
  .sidebar-overlay.mobile-open {
    display: block;
  }

  /* 2. Bottom Tab Bar (App-like navigation) */
  .mobile-bottom-bar {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(250, 248, 245, 0.98);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    z-index: 900;
    padding-bottom: env(safe-area-inset-bottom); /* Suporte para Notch iOS */
    justify-content: space-around;
    align-items: center;
    height: 70px;
    box-shadow: 0 -4px 20px rgba(197, 168, 128, 0.08);
  }
  .mobile-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    flex: 1;
    transition: var(--transition-smooth);
    user-select: none;
  }
  .mobile-tab.active {
    color: var(--accent-pink);
  }
  .mobile-tab i {
    width: 24px;
    height: 24px;
  }
  .mobile-tab.main-action .main-action-inner {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
    color: white;
    border-radius: 50%;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -30px;
    box-shadow: 0 4px 15px rgba(197, 168, 128, 0.4);
    border: 4px solid var(--bg-main);
  }

  /* Garantir que o conteúdo não fique escondido sob a tab bar */
  .main-content {
    padding-bottom: 90px !important;
  }
  
  /* 3. Ajustes de Cards & Grids para evitar Scroll Horizontal */
  .dashboard-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .grid-stats {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .card-stat {
    flex-direction: column;
    text-align: center;
    padding: 1rem !important;
    gap: 10px !important;
  }
  .stat-label {
    font-size: 0.75rem !important;
    line-height: 1.1;
  }
  .stat-value {
    font-size: 1.4rem !important;
  }
  .dashboard-panel {
    padding: 1.1rem;
    border-radius: 16px;
  }
  
  header {
    padding: 1.5rem 1.1rem 1rem 1.1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .view-section {
    padding: 1rem 1.1rem;
  }

  /* 4. Tabela Inteligente (Transformando em Cards - Zero Regressão JS) */
  .table-wrapper table, 
  .table-wrapper thead, 
  .table-wrapper tbody, 
  .table-wrapper th, 
  .table-wrapper td, 
  .table-wrapper tr {
    display: block;
  }
  
  /* Esconde o cabeçalho original no mobile */
  .table-wrapper thead tr {
    display: none;
  }
  
  .table-wrapper {
    background: transparent;
    box-shadow: none;
    border: none;
    padding: 0;
    overflow-x: visible !important; /* Previne conflito de scroll vertical em modais */
  }

  /* Cada linha tr vira um cartão de informações */
  .table-wrapper tr {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 16px;
    padding: 16px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  
  /* As células td viram itens flex no cartão */
  .table-wrapper td {
    border: none !important; /* Reseta a borda original */
    padding: 0;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    color: var(--text-secondary);
    min-height: auto;
    width: 100%;
  }
  
  /* A primeira coluna (ex: Nome) fica em destaque como Título do Cartão */
  .table-wrapper td:first-child {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(197, 168, 128, 0.15) !important;
    padding-bottom: 10px;
    margin-bottom: 4px;
    display: block;
  }
  
  /* A última coluna (Ações) vai para o final alinhada à direita e destacada */
  .table-wrapper td:last-child {
    margin-top: 8px;
    justify-content: flex-end;
    border-top: 1px dashed rgba(197, 168, 128, 0.2) !important;
    padding-top: 12px;
  }

  /* Esconder células vazias de ação no rodapé */
  #revenue-table-foot td:last-child {
    display: none !important;
  }
  
  /* Rótulos Específicos para Tabela de Estoque no Mobile */
  #inventory-table-body td:nth-child(2)::before { content: "Und:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #inventory-table-body td:nth-child(3)::before { content: "Qtd Atual:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #inventory-table-body td:nth-child(4)::before { content: "Qtd Mínima:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #inventory-table-body td:nth-child(5)::before { content: "Fornecedor:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  
  /* Rótulos Específicos para Tabela de Procedimentos no Mobile */
  #procedures-table-body td:nth-child(2)::before { content: "Preço:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #procedures-table-body td:nth-child(3)::before { content: "Retorno:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #procedures-table-body td:nth-child(4)::before { content: "Duração:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  
  /* Rótulos Específicos para Tabela de Clientes no Mobile */
  #clients-table-body td:nth-child(2)::before { content: "Telefone:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #clients-table-body td:nth-child(3)::before { content: "Cadastro:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #clients-table-body td:nth-child(4)::before { content: "Obs:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #clients-table-body td:nth-child(5)::before { content: "Total Gasto:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }

  /* Rótulos Específicos para Tabela de Usuários no Mobile */
  #users-table-body td:nth-child(2)::before { content: "Permissão:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }

  /* Rótulos Específicos para Tabela de Profissionais no Mobile */
  #professionals-table-body td:nth-child(2)::before { content: "Status:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }

  /* Rótulos Específicos para Tabela de Solicitações no Mobile */
  #requests-table-body td:nth-child(2)::before { content: "Horário:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #requests-table-body td:nth-child(3)::before { content: "Cliente:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #requests-table-body td:nth-child(4)::before { content: "Telefone:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #requests-table-body td:nth-child(5)::before { content: "Procedimento:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #requests-table-body td:nth-child(6)::before { content: "Profissional:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }

  /* Rótulos Específicos para Tabela de Faturamento no Mobile */
  #revenue-table-body td:nth-child(2)::before { content: "Atendimentos:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #revenue-table-body td:nth-child(3)::before { content: "Faturamento:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }

  #revenue-table-foot td:nth-child(2)::before { content: "Atendimentos Anuais:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #revenue-table-foot td:nth-child(3)::before { content: "Faturamento Anual:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }

  /* Rótulos Específicos para Modal de Detalhamento no Mobile */
  #revenue-breakdown-body td:nth-child(2)::before { content: "Qtd Realizada:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
  #revenue-breakdown-body td:nth-child(3)::before { content: "Faturamento:"; font-weight: 600; color: var(--text-primary); margin-right: 4px; }

  /* Ajustar visualização dos títulos das tabelas */
  #inventory-table-body td:first-child,
  #procedures-table-body td:first-child,
  #clients-table-body td:first-child,
  #users-table-body td:first-child,
  #professionals-table-body td:first-child,
  #requests-table-body td:first-child,
  #revenue-table-body td:first-child,
  #revenue-table-foot td:first-child,
  #revenue-breakdown-body td:first-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(197, 168, 128, 0.08);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-primary);
    border-bottom: 2px solid rgba(197, 168, 128, 0.2);
    border-radius: 12px 12px 0 0;
    padding: 12px 10px;
  }
  
  /* 5. Agenda Touch-Friendly */
  .agenda-stats-row {
    grid-template-columns: 1fr !important;
  }
  .agenda-stat-card {
    padding: 12px !important;
  }
  /* Controles de navegação da agenda com toque otimizado */
  #agenda-current-date-text {
    font-size: 1.1rem !important;
  }
  
  /* Melhorando proporções da timeline da Agenda no Mobile */
  .agenda-time-column {
    width: 55px !important;
    min-width: 55px !important;
  }
  .agenda-time-slot {
    font-size: 0.75rem !important;
    padding-right: 4px !important;
  }
  .agenda-prof-header {
    font-size: 0.85rem !important;
    padding: 10px 5px !important;
  }
  
  /* 6. Formulários Full-width e Touch Targets */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  /* Ajustes Ultra-Compactos dos Botões de Modal no Mobile */
  .modal-footer {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    padding: 12px 16px !important;
  }
  .modal-footer > div {
    display: contents !important;
  }
  .modal-footer .btn {
    width: 100% !important;
    margin: 0 !important;
    justify-content: center;
    padding: 0.6rem !important;
    font-size: 0.95rem !important;
    min-height: 44px !important;
  }
  
  /* Inputs e Botões com altura mínima ergonômica da Apple/Google (44px+) */
  .btn, input[type="text"], input[type="number"], input[type="tel"], input[type="date"], input[type="password"], select {
    min-height: 48px;
    font-size: 1rem; /* Previne auto-zoom indesejado no iOS */
  }
  
  /* 7. Modais estilo Bottom Sheet (preenchendo a tela de baixo para cima) */
  .modal-container {
    margin: 0;
    width: 100%;
    max-width: 100% !important;
    height: 85vh; /* Sempre abre expandido para garantir a rolagem */
    max-height: 85vh;
    border-radius: 24px 24px 0 0;
    position: absolute;
    bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
  }
  .modal-overlay {
    align-items: flex-end;
  }
  
  @keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* Esconder botões de conta que ficavam soltos no dashboard */
  .mobile-account-actions {
    display: none !important;
  }

  /* --- CORREÇÕES DE CONFLITO COM STYLES.CSS (max-width: 992px) --- */
  .sidebar {
    width: 280px !important;
    max-width: 280px !important;
    border-right: 1px solid var(--border-color) !important;
    border-bottom: none !important;
    flex-direction: column !important;
    padding: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  
  .nav-menu {
    flex-direction: column !important;
    overflow-x: hidden !important;
    padding-bottom: 20px !important;
  }
  
  .nav-item {
    margin-bottom: 5px !important;
  }

  .nav-item a {
    white-space: normal !important;
  }
  
  .sidebar-footer {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    margin-top: auto;
    width: 100%;
    background: var(--bg-sidebar);
    padding: 1rem;
  }
  
  /* Fallback/Proteção para cache: esconde a barra se a tela de login estiver ativa */
  body:has(#login-wrapper[style*="display: flex"]) .mobile-bottom-bar,
  #login-wrapper[style*="display: flex"] ~ .mobile-bottom-bar {
    display: none !important;
  }
  
  /* 11. Ajustes para Ficha de Cliente Moderna no Mobile */
  .profile-modern-header {
    flex-direction: column !important;
    align-items: center !important;
    text-align: center;
    gap: 1rem !important;
  }

  .profile-modern-user {
    flex-direction: column !important;
    align-items: center !important;
    text-align: center;
    gap: 12px !important;
  }

  .profile-modern-header > div:last-child {
    align-items: center !important;
    width: 100%;
  }

  .profile-modern-header .badge-warning {
    white-space: normal !important;
    text-align: center;
  }
}
