/* ═══════════════════════════════════════════════════════════════
   a11y.css — Acessibilidade Global (WCAG 2.2 AA)
   Inclua este arquivo em TODOS os HTMLs, após os outros estilos.
   ═══════════════════════════════════════════════════════════════ */

/* ── 1. Skip link (WCAG 2.4.1) ──────────────────────────────── */
.skip-link {
  position: fixed;
  top: -100px;
  left: 8px;
  padding: 12px 20px;
  background: #6366f1;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  z-index: 9999;
  border-radius: 0 0 8px 8px;
  text-decoration: none;
  white-space: nowrap;
  transition: top .15s;
}
.skip-link:focus {
  top: 0;
}

/* ── 2. Visualmente oculto mas acessível (sr-only) ──────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ── 3. Foco visível global (WCAG 2.4.7, 2.4.11) ───────────── */
*:focus-visible {
  outline: 3px solid #6366f1;
  outline-offset: 3px;
  border-radius: 4px;
}
/* Remove outline somente quando não é navegação por teclado */
*:focus:not(:focus-visible) {
  outline: none;
}

/* ── 4. Tamanho mínimo de toque (WCAG 2.5.5 — 44×44px) ──────── */
button,
[role="button"],
[role="tab"],
input[type="submit"],
input[type="button"],
input[type="reset"],
.btn,
.tab,
.alert-tab {
  min-height: 44px;
}
nav a {
  min-height: 44px;
  display: flex;
  align-items: center;
}
.btn-primary,
.btn-google {
  min-height: 48px;
}

/* ── 5. Reduced motion (WCAG 2.3.3) ────────────────────────── */
@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;
  }
}

/* ── 6. Contraste de cor mínimo para texto muted ─────────────── */
/* --muted deve ter pelo menos 4.5:1 contra o fundo */
/* Nos temas escuros, elevar para #94a3b8 (≈ 6:1 vs #0f0f13) */
/* Nos temas claros, elevar para #5a6582 (≈ 5:1 vs #f4f5f9) */

/* ── 7. Responsividade mobile — breakpoint principal ─────────── */
@media (max-width: 768px) {
  /* Grids → 1 coluna */
  .two-col,
  .opp-grid,
  .news-grid,
  .perf-kpi-grid,
  .best-grid,
  .kpi-grid,
  .stats-grid {
    grid-template-columns: 1fr !important;
  }

  /* Calendário → 1 coluna */
  .calendar-grid {
    grid-template-columns: 1fr !important;
  }

  /* Painéis laterais com width fixo → full width */
  .detail-panel {
    width: 100% !important;
    min-width: 0 !important;
    flex-shrink: 1 !important;
  }

  /* Tabelas com scroll horizontal */
  .table-scroll-wrap {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
  }

  /* Botões de ação no topo */
  .top-bar,
  .page-header {
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 8px;
    padding-right: 8px;
  }

  /* Cards de alerta empilhados */
  [style*="grid-template-columns: 1fr 380px"],
  [style*="grid-template-columns:1fr 380px"] {
    grid-template-columns: 1fr !important;
  }
}

/* Breakpoint extra pequeno */
@media (max-width: 480px) {
  .card {
    padding: 24px 16px !important;
    border-radius: 16px !important;
  }

  .stats-row,
  .summary-row {
    flex-wrap: wrap;
  }

  .summary-card {
    min-width: 140px;
  }
}

/* ── 8. Zoom até 200% sem quebrar layout (WCAG 1.4.4) ─────────── */
html {
  font-size: 100%; /* Base 16px */
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

/* Impede overflow horizontal ao fazer zoom */
body {
  overflow-x: hidden;
}

/* ── 9. Tabelas acessíveis ───────────────────────────────────── */
table {
  border-collapse: collapse;
}
table caption {
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  padding: 0 0 8px;
  color: inherit;
}

/* ── 10. Modo escuro do sistema (WCAG 1.4.3) ─────────────────── */
/* O app já tem tema escuro nativo — ok para usuários que preferem escuro */
/* Para usuários que preferem claro, as páginas claras já usam --bg: #f4f5f9 */

/* ── 11. Seleção de texto acessível ─────────────────────────── */
::selection {
  background: rgba(99, 102, 241, 0.3);
  color: inherit;
}

/* ── 12. Foco em inputs e selects ────────────────────────────── */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #6366f1 !important;
  outline-offset: 0 !important;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2) !important;
  border-color: #6366f1 !important;
}

/* ── 13. Links de navegação — foco visível ──────────────────── */
nav a:focus-visible {
  outline: 3px solid #6366f1;
  outline-offset: 2px;
  background: rgba(108, 99, 255, 0.15) !important;
  color: #a89dff !important;
}

/* ── 14. Dialog / modal acessível ───────────────────────────── */
dialog,
[role="dialog"] {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  border: none;
  border-radius: 16px;
  padding: 0;
  max-width: 90vw;
  max-height: 90dvh;
  overflow: auto;
}
dialog::backdrop,
.modal-backdrop {
  background: rgba(0, 0, 0, 0.55);
}

/* ── 15. Botão hamburguer — oculto em telas grandes ─────────── */
@media (min-width: 769px) {
  .hamburger-btn {
    display: none !important;
  }
}
