/* ======================================
   MELHORIAS DE ACESSIBILIDADE MOBILE
   Otimizações para leitores de tela, navegação por teclado e usabilidade
   ====================================== */

/* ========== FOCO E NAVEGAÇÃO ========== */
@media (max-width: 767px) {
  /* Skip link para navegação rápida */
  .skip-link {
    position: absolute !important;
    top: -40px !important;
    left: 6px !important;
    background: var(--brand) !important;
    color: white !important;
    padding: 8px !important;
    text-decoration: none !important;
    border-radius: 4px !important;
    z-index: 1000 !important;
    font-size: 14px !important;
  }
  
  .skip-link:focus {
    top: 6px !important;
  }
  
  /* Melhores indicadores de foco */
  button:focus,
  input:focus,
  select:focus,
  textarea:focus,
  a:focus,
  [tabindex]:focus {
    outline: 3px solid var(--brand) !important;
    outline-offset: 2px !important;
    border-radius: 4px !important;
  }
  
  /* Foco mais visível em botões principais */
  .primary-btn:focus,
  .secondary-btn:focus {
    box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.3) !important;
  }
  
  /* Área de toque mínima de 44px */
  button,
  .btn,
  input[type="checkbox"],
  input[type="radio"],
  .clickable {
    min-height: 44px !important;
    min-width: 44px !important;
  }
  
  /* Melhor espaçamento entre elementos interativos */
  button + button,
  .btn + .btn {
    margin-left: 8px !important;
  }
}

/* ========== LABELS E FORMULÁRIOS ========== */
@media (max-width: 767px) {
  /* Labels sempre visíveis */
  label {
    display: block !important;
    margin-bottom: 4px !important;
    font-weight: 600 !important;
    color: var(--fg) !important;
  }
  
  /* Melhor contraste para placeholders */
  input::placeholder,
  textarea::placeholder {
    color: var(--muted) !important;
    opacity: 0.8 !important;
  }
  
  /* Indicadores de campos obrigatórios */
  .required::after {
    content: " *" !important;
    color: var(--warn) !important;
    font-weight: bold !important;
  }
  
  /* Status de validação mais claro */
  .field-error {
    border: 2px solid var(--warn) !important;
    background-color: rgba(255, 176, 32, 0.1) !important;
  }
  
  .field-success {
    border: 2px solid var(--ok) !important;
    background-color: rgba(25, 195, 125, 0.1) !important;
  }
  
  /* Mensagens de erro mais acessíveis */
  .error-message {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 12px !important;
    margin-top: 4px !important;
    border-radius: 6px !important;
    background: rgba(255, 176, 32, 0.1) !important;
    border-left: 4px solid var(--warn) !important;
    font-size: 14px !important;
  }
  
  .error-message::before {
    content: "⚠️" !important;
    font-size: 16px !important;
  }
  
  .success-message {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 12px !important;
    margin-top: 4px !important;
    border-radius: 6px !important;
    background: rgba(25, 195, 125, 0.1) !important;
    border-left: 4px solid var(--ok) !important;
    font-size: 14px !important;
  }
  
  .success-message::before {
    content: "✓" !important;
    font-size: 16px !important;
    color: var(--ok) !important;
  }
}

/* ========== BOTÕES E CONTROLES ========== */
@media (max-width: 767px) {
  /* Botões com melhor feedback */
  button,
  .btn {
    position: relative !important;
    overflow: hidden !important;
    transition: all 0.2s ease !important;
  }
  
  button:active,
  .btn:active {
    transform: scale(0.98) !important;
  }
  
  /* Estado desabilitado mais claro */
  button:disabled,
  .btn:disabled {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
    background: var(--panel2) !important;
    color: var(--muted) !important;
  }
  
  /* Indicador de carregamento */
  .loading {
    position: relative !important;
    color: transparent !important;
  }
  
  .loading::after {
    content: "" !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    width: 20px !important;
    height: 20px !important;
    margin: -10px 0 0 -10px !important;
    border: 2px solid transparent !important;
    border-top: 2px solid currentColor !important;
    border-radius: 50% !important;
    animation: spin 1s linear infinite !important;
  }
  
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
}

/* ========== NAVEGAÇÃO E MENU ========== */
@media (max-width: 767px) {
  /* Menu mobile mais acessível */
  .menu-toggle {
    position: relative !important;
    background: none !important;
    border: 2px solid var(--border) !important;
    border-radius: 6px !important;
    padding: 8px !important;
    cursor: pointer !important;
  }
  
  .menu-toggle:focus {
    border-color: var(--brand) !important;
  }
  
  /* Indicador visual do menu aberto/fechado */
  .menu-toggle[aria-expanded="true"] {
    background: var(--brand) !important;
    color: white !important;
  }
  
  /* Breadcrumbs simplificados */
  .breadcrumbs {
    font-size: 12px !important;
    margin-bottom: 16px !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  .breadcrumb-item {
    display: inline-block !important;
    margin-right: 8px !important;
  }
  
  .breadcrumb-item:not(:last-child)::after {
    content: " › " !important;
    color: var(--muted) !important;
    margin-left: 8px !important;
  }
}

/* ========== MODAIS E OVERLAYS ========== */
@media (max-width: 767px) {
  /* Modais ocupam tela inteira em mobile */
  .modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: var(--bg) !important;
    z-index: 1000 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  .modal-header {
    position: sticky !important;
    top: 0 !important;
    background: var(--bg) !important;
    border-bottom: 1px solid var(--border) !important;
    padding: 16px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
  }
  
  .modal-title {
    font-size: 18px !important;
    font-weight: 600 !important;
    margin: 0 !important;
  }
  
  .modal-close {
    background: none !important;
    border: none !important;
    font-size: 24px !important;
    cursor: pointer !important;
    min-width: 44px !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  
  .modal-body {
    padding: 16px !important;
  }
  
  /* Overlays com melhor contraste */
  .overlay {
    background: rgba(0, 0, 0, 0.7) !important;
    backdrop-filter: blur(4px) !important;
  }
}

/* ========== TOOLTIPS E AJUDA ========== */
@media (max-width: 767px) {
  /* Tooltips adaptados para touch */
  .tooltip {
    position: relative !important;
    display: inline-block !important;
  }
  
  .tooltip-content {
    position: absolute !important;
    bottom: 100% !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    background: var(--panel2) !important;
    color: var(--fg) !important;
    padding: 8px 12px !important;
    border-radius: 6px !important;
    font-size: 12px !important;
    white-space: nowrap !important;
    max-width: 200px !important;
    white-space: normal !important;
    text-align: center !important;
    border: 1px solid var(--border) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    z-index: 1000 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transition: all 0.2s ease !important;
  }
  
  .tooltip:hover .tooltip-content,
  .tooltip:focus .tooltip-content {
    opacity: 1 !important;
    visibility: visible !important;
  }
  
  /* Botões de ajuda mais visíveis */
  .help-btn {
    background: var(--brand) !important;
    color: white !important;
    border: none !important;
    border-radius: 50% !important;
    width: 24px !important;
    height: 24px !important;
    font-size: 14px !important;
    font-weight: bold !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-left: 8px !important;
  }
}

/* ========== TABELAS RESPONSIVAS ========== */
@media (max-width: 767px) {
  /* Tabelas com scroll horizontal */
  .table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
  }
  
  table {
    min-width: 500px !important;
    width: 100% !important;
  }
  
  th, td {
    padding: 8px 12px !important;
    font-size: 14px !important;
    white-space: nowrap !important;
  }
  
  th {
    background: var(--panel2) !important;
    font-weight: 600 !important;
    position: sticky !important;
    top: 0 !important;
  }
  
  /* Alternativa: cards para dados tabulares */
  .data-cards {
    display: grid !important;
    gap: 12px !important;
  }
  
  .data-card {
    background: var(--panel2) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    padding: 16px !important;
  }
  
  .data-card-title {
    font-weight: 600 !important;
    margin-bottom: 8px !important;
    color: var(--brand) !important;
  }
  
  .data-card-content {
    display: grid !important;
    gap: 4px !important;
  }
  
  .data-field {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
  }
  
  .data-label {
    font-size: 12px !important;
    color: var(--muted) !important;
  }
  
  .data-value {
    font-weight: 600 !important;
  }
}

/* ========== MELHORIAS GERAIS DE CONTRASTE ========== */
@media (max-width: 767px) {
  /* Melhor contraste para texto sobre fundos */
  .text-on-brand {
    color: white !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3) !important;
  }
  
  .text-on-light {
    color: var(--fg) !important;
  }
  
  /* Separadores mais visíveis */
  .divider {
    border-top: 1px solid var(--border) !important;
    margin: 16px 0 !important;
  }
  
  /* Estados de hover adaptados para touch */
  @media (hover: none) {
    button:hover,
    .btn:hover,
    a:hover {
      background: var(--panel2) !important;
    }
  }
  
  /* Reduzi animações para users que preferem motion reducido */
  @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;
    }
  }
}
