/* ═════════════════════════════════════════════════════════════════════════════════════════════════════════════════
   APEBA — Accessibility & Visual Refinements v1.0
   ═════════════════════════════════════════════════════════════════════════════════════════════════════════════════
   Melhorias de acessibilidade: skip-to-content, focus-visible, prefers-reduced-motion,
   contraste, aria helpers, print styles, responsive refinements.
   ═════════════════════════════════════════════════════════════════════════════════════════════════════════════════ */

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ SKIP-TO-CONTENT — Navegação por teclado
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
.skip-to-content {
  position: fixed;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  background: var(--accent-1, #14b8a6);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 0 0 var(--radius-sm, 10px) var(--radius-sm, 10px);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: top 0.2s ease;
  box-shadow: var(--shadow-md, 0 4px 20px rgba(0,0,0,0.3));
}

.skip-to-content:focus {
  top: 0;
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ FOCUS-VISIBLE — Indicador de foco visível para navegação por teclado
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
:focus-visible {
  outline: 2px solid var(--accent-1, #14b8a6);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Remove focus outline apenas para clique com rato (mantém para teclado) */
:focus:not(:focus-visible) {
  outline: none;
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ PREFERS-REDUCED-MOTION — Respeitar preferências de movimento
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
@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;
  }

  .animate-in {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  body::before,
  body::after {
    animation: none !important;
    display: none !important;
  }
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ SCREEN-READER UTILITIES — Classes para leitores de ecrã
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sr-only-focusable:focus,
.sr-only-focusable:focus-visible {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ CONTRASTE & LEGIBILIDADE
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */

/* Melhorar contraste de links em cards e áreas de destaque */
.card a:not(.button-primary):not(.button-secondary) {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.card a:not(.button-primary):not(.button-secondary):hover {
  text-decoration: none;
}

/* Badges com contraste suficiente */
.badge {
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Melhorar legibilidade de textos pequenos */
small, .text-muted {
  color: var(--text-muted, #94a3b8) !important;
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ TABELAS — Acessibilidade
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
.data-table caption,
table caption {
  caption-side: bottom;
  padding: 0.5rem 0;
  font-size: 0.8rem;
  color: var(--text-muted, #94a3b8);
  text-align: left;
}

.data-table th[scope="col"],
table th[scope="col"] {
  position: relative;
}

/* Zebra striping com contraste suficiente */
.data-table tbody tr:nth-child(even),
table.table-striped tbody tr:nth-child(even) {
  background: var(--bg-glass, rgba(255,255,255,0.04));
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ FORMULÁRIOS — Acessibilidade
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent-1, #14b8a6);
  outline-offset: 2px;
}

/* Labels com cursor pointer para melhor usabilidade */
label {
  cursor: pointer;
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ BOTÕES E LINKS — Área de clique adequada
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
.main-nav a,
.topbar-nav a,
.topbar-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ MENSAGENS E ALERTAS — ARIA roles implícitos
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
.alert {
  border: 1px solid transparent;
}

.alert-success {
  border-color: var(--color-success, #10b981);
}

.alert-error,
.alert-danger {
  border-color: var(--color-danger, #f43f5e);
}

.alert-warning {
  border-color: var(--color-warning, #f59e0b);
}

.alert-info {
  border-color: var(--color-info, #14b8a6);
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ ESTADOS VAZIOS (EMPTY STATES)
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted, #94a3b8);
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ RESPONSIVE — Melhorias de toque em ecrãs pequenos
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .data-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table th,
  .data-table td {
    white-space: nowrap;
  }

  .main-nav {
    flex-wrap: wrap;
    gap: 2px;
  }

  .main-nav a {
    font-size: 0.78rem;
    padding: 0.35rem 0.6rem;
  }
}

/* ╔════════════════════════════════════════════════════════════════════════════════════════════════════════════
   │ PRINT STYLES
   ╚════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
@media print {
  /* Esconder elementos de navegação e UI */
  .site-header,
  .topbar,
  .app-topbar,
  .site-footer,
  .app-footer,
  .sidebar,
  .skip-to-content,
  .main-nav,
  .topbar-nav,
  .breadcrumbs,
  .page-actions,
  .btn,
  .button-primary,
  .button-secondary,
  .nav-tabs,
  .filters-bar,
  .header-user,
  .app-topbar-user,
  .toast-container,
  #toast-container {
    display: none !important;
  }

  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 11pt;
  }

  .page-container,
  .app-content,
  .app-main {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .card,
  .stat-card,
  .data-table-wrapper,
  .chart-wrapper {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    break-inside: avoid;
    background: #fff !important;
  }

  a {
    color: #000 !important;
    text-decoration: underline;
  }

  .data-table th {
    background: #f5f5f5 !important;
    color: #000 !important;
  }

  table {
    break-inside: avoid;
    font-size: 9pt;
  }

  h1, h2, h3, h4 {
    break-after: avoid;
    color: #000 !important;
  }

  img {
    max-width: 100% !important;
    page-break-inside: avoid;
  }
}