/**
 * SENTINELA - Estilos de Acessibilidade WCAG 2.1 AA
 * Melhorias para navegação por teclado, leitores de tela e contraste
 */

/* ==================== SKIP LINKS ==================== */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--color-primary, #2563EB);
  color: white;
  padding: 12px 24px;
  text-decoration: none;
  font-weight: 600;
  z-index: 100000;
  border-radius: 0 0 8px 0;
  transition: top 0.3s ease;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid var(--color-secondary, #059669);
  outline-offset: 2px;
}

.skip-link:focus-visible {
  top: 0;
}

/* ==================== FOCUS STYLES ==================== */
/* Foco visível para todos os elementos interativos */
:focus {
  outline: 2px solid var(--color-primary, #2563EB);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--color-primary, #2563EB);
  outline-offset: 2px;
}

/* Foco especial para botões */
button:focus-visible,
.btn:focus-visible,
[role="button"]:focus-visible {
  outline: 3px solid var(--color-secondary, #059669);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(5, 150, 105, 0.2);
}

/* Foco para links */
a:focus-visible {
  outline: 3px solid var(--color-primary, #2563EB);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Foco para inputs */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid var(--color-primary, #2563EB);
  outline-offset: 0;
  border-color: var(--color-primary, #2563EB);
}

/* ==================== SCREEN READER 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: 0;
}

.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ==================== REDUCED MOTION ==================== */
@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;
  }
}

/* ==================== HIGH CONTRAST MODE ==================== */
@media (prefers-contrast: high) {
  :root {
    --color-primary: #0000FF;
    --color-secondary: #008000;
    --color-text: #000000;
    --color-background: #FFFFFF;
    --color-border: #000000;
  }

  button,
  .btn,
  input,
  select,
  textarea {
    border: 2px solid currentColor;
  }

  a {
    text-decoration: underline;
    text-decoration-thickness: 2px;
  }
}

/* ==================== KEYBOARD NAVIGATION INDICATOR ==================== */
body.keyboard-navigation *:focus {
  outline: 3px solid var(--color-primary, #2563EB) !important;
  outline-offset: 2px !important;
}

/* ==================== ACCESSIBLE FORMS ==================== */
/* Labels obrigatórios */
.form-label[required]::after,
label[required]::after,
.required::after {
  content: " *";
  color: #DC2626;
  font-weight: bold;
}

/* Mensagens de erro acessíveis */
.form-error,
[role="alert"] {
  color: #DC2626;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-error::before {
  content: "⚠";
  font-size: 1.1em;
}

/* Campos inválidos */
input:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown),
select:invalid:not(:placeholder-shown) {
  border-color: #DC2626;
}

/* ==================== ACCESSIBLE BUTTONS ==================== */
button:disabled,
.btn:disabled,
[role="button"][aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Área de clique mínima (44x44px para WCAG) */
button,
.btn,
[role="button"],
a[role="button"],
input[type="submit"],
input[type="button"],
input[type="reset"] {
  min-height: 44px;
  min-width: 44px;
}

/* Links em linha podem ser menores */
a:not([role="button"]) {
  min-height: auto;
  min-width: auto;
}

/* ==================== ACCESSIBLE TABLES ==================== */
table {
  border-collapse: collapse;
  width: 100%;
}

th {
  text-align: left;
  font-weight: 600;
  background: var(--color-background, #F3F4F6);
}

th, td {
  padding: 12px;
  border: 1px solid var(--color-border, #E5E7EB);
}

caption {
  caption-side: top;
  text-align: left;
  font-weight: 600;
  padding: 12px 0;
}

/* ==================== ACCESSIBLE MODALS ==================== */
[role="dialog"],
[aria-modal="true"] {
  position: fixed;
  z-index: 10000;
}

[role="dialog"]:focus {
  outline: none;
}

/* Trap focus indicator */
.focus-trap-active {
  overflow: hidden;
}

/* ==================== ACCESSIBLE NAVIGATION ==================== */
nav[aria-label] ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

nav a[aria-current="page"] {
  font-weight: 700;
  text-decoration: underline;
}

/* ==================== ACCESSIBLE ALERTS ==================== */
[role="alert"],
[role="status"] {
  padding: 16px;
  border-radius: 8px;
  margin: 16px 0;
}

[role="alert"] {
  background: #FEE2E2;
  border-left: 4px solid #DC2626;
}

[role="status"] {
  background: #ECFDF5;
  border-left: 4px solid #059669;
}

/* ==================== ACCESSIBLE PROGRESS ==================== */
[role="progressbar"] {
  height: 8px;
  background: var(--color-border, #E5E7EB);
  border-radius: 4px;
  overflow: hidden;
}

[role="progressbar"]::before {
  content: '';
  display: block;
  height: 100%;
  background: var(--color-primary, #2563EB);
  width: var(--progress, 0%);
  transition: width 0.3s ease;
}

/* ==================== ACCESSIBLE TOOLTIPS ==================== */
[aria-describedby] {
  position: relative;
}

[role="tooltip"] {
  position: absolute;
  background: #1F2937;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.875rem;
  max-width: 250px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

[role="tooltip"][data-show] {
  opacity: 1;
}

/* ==================== PRINT STYLES ==================== */
@media print {
  .skip-link,
  .sr-only,
  [aria-hidden="true"] {
    display: none !important;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }

  button,
  .btn {
    background: none !important;
    color: #000 !important;
    border: 1px solid #000 !important;
  }
}

/* ==================== DARK MODE ADJUSTMENTS ==================== */
@media (prefers-color-scheme: dark) {
  :focus-visible {
    outline-color: #60A5FA;
  }

  button:focus-visible,
  .btn:focus-visible {
    outline-color: #34D399;
    box-shadow: 0 0 0 6px rgba(52, 211, 153, 0.2);
  }
}

/* Suporte a tema escuro manual */
[data-theme="dark"] :focus-visible {
  outline-color: #60A5FA;
}

[data-theme="dark"] button:focus-visible,
[data-theme="dark"] .btn:focus-visible {
  outline-color: #34D399;
  box-shadow: 0 0 0 6px rgba(52, 211, 153, 0.2);
}
