/**
 * BP Cantara - Accessibility Styles
 * Business Plan | Grupo Cantara
 * 
 * Sprint 2.1.x: ARIA e Acessibilidade
 * WCAG 2.1 Level AA Compliance
 * 
 * @version 5.0.0
 * @date 2026-01-25
 */

/* ============================================
   SKIP LINKS - Sprint 2.1.4
   ============================================ */

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #2563eb;
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 4px 0;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 2px solid #1d4ed8;
    outline-offset: 2px;
}

.skip-link:hover {
    background: #1d4ed8;
}

/* Skip link para navegação */
.skip-to-nav {
    left: 150px;
}

/* ============================================
   FOCUS VISIBLE - Melhorar visibilidade do foco
   ============================================ */

/* Reset padrão para todos os elementos focáveis */
:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Focus visible apenas quando usando teclado */
:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Botões com foco */
button:focus-visible,
.btn:focus-visible,
[role="button"]:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.3);
}

/* Links com foco */
a:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
    text-decoration: underline;
}

/* Inputs com foco */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* ============================================
   ARIA LABELS - Sprint 2.1.1 & 2.1.2
   ============================================ */

/* Elementos com ARIA expanded */
[aria-expanded="true"]::after {
    content: " (expandido)";
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

[aria-expanded="false"]::after {
    content: " (recolhido)";
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Indicador visual para campos obrigatórios */
[aria-required="true"]::after,
.required::after {
    content: " *";
    color: #ef4444;
    font-weight: bold;
}

/* Indicador visual para campos inválidos */
[aria-invalid="true"] {
    border-color: #ef4444 !important;
    background-color: rgba(239, 68, 68, 0.05);
}

[aria-invalid="true"]:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

/* Descrição de erro */
.error-message,
[role="alert"] {
    color: #ef4444;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ============================================
   MODAL ACCESSIBILITY - Sprint 2.1.1
   ============================================ */

/* Modal overlay - CORRIGIDO Sprint 4.2.1: Respeitar classe hidden do Tailwind */
/* Modais usam a classe .modal que já define o layout via Tailwind */
/* Esta regra apenas adiciona estilos de acessibilidade sem sobrescrever display */
[role="dialog"] {
    /* NÃO definir display aqui - deixar para as classes do elemento */
    /* position, alignment etc já definidos nas classes .modal do HTML */
    z-index: 9999;
}

/* Quando o modal está visível (sem classe hidden) */
[role="dialog"]:not(.hidden) {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* Focus trap visual indicator - apenas quando visível */
[role="dialog"]:not(.hidden)::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
}

/* CRÍTICO: Garantir que modais com classe hidden fiquem ocultos */
[role="dialog"].hidden {
    display: none !important;
}

/* Modal content */
[role="dialog"] > [role="document"],
[role="dialog"] > .modal-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

/* Close button accessibility */
[role="dialog"] [aria-label="Fechar"],
[role="dialog"] .close-button {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
}

[role="dialog"] [aria-label="Fechar"]:hover,
[role="dialog"] .close-button:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* ============================================
   LIVE REGIONS - Anúncios para Screen Readers
   ============================================ */

/* Região live para anúncios */
[aria-live="polite"],
[aria-live="assertive"],
.sr-announce {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Região live visível (para toasts) */
.toast[aria-live="polite"] {
    position: fixed;
    top: 1rem;
    right: 1rem;
    left: auto;
    width: auto;
    height: auto;
    overflow: visible;
    z-index: 10000;
}

/* ============================================
   VISUALLY HIDDEN - Conteúdo apenas para SR
   ============================================ */

.sr-only,
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Visível quando focado (skip links) */
.sr-only-focusable:focus,
.visually-hidden-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */

@media (prefers-contrast: high) {
    :focus {
        outline: 3px solid currentColor;
        outline-offset: 3px;
    }
    
    button,
    .btn,
    input,
    select,
    textarea {
        border: 2px solid currentColor;
    }
    
    a {
        text-decoration: underline;
    }
}

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

/* ============================================
   COLOR CONTRAST HELPERS
   ============================================ */

/* Texto de alto contraste */
.high-contrast-text {
    color: #1f2937;
    background: #ffffff;
}

/* Links com contraste adequado */
a {
    color: #2563eb;
}

a:visited {
    color: #7c3aed;
}

a:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

/* ============================================
   TABLES ACCESSIBILITY
   ============================================ */

table[role="grid"] {
    border-collapse: collapse;
    width: 100%;
}

table[role="grid"] th {
    background: #f3f4f6;
    font-weight: 600;
    text-align: left;
    padding: 0.75rem 1rem;
}

table[role="grid"] td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
}

table[role="grid"] tr:focus-within {
    background: rgba(37, 99, 235, 0.05);
}

/* Row selection indicator */
table[role="grid"] tr[aria-selected="true"] {
    background: rgba(37, 99, 235, 0.1);
}

/* ============================================
   FORM ACCESSIBILITY
   ============================================ */

/* Labels */
label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: #374151;
}

/* Fieldset and legend */
fieldset {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

legend {
    font-weight: 600;
    padding: 0 0.5rem;
    color: #1f2937;
}

/* Error states */
.form-group.has-error input,
.form-group.has-error select,
.form-group.has-error textarea {
    border-color: #ef4444;
}

.form-group.has-error label {
    color: #ef4444;
}

/* Success states */
.form-group.has-success input,
.form-group.has-success select,
.form-group.has-success textarea {
    border-color: #10b981;
}

/* Help text */
.help-text,
[id$="-help"],
[id$="-description"] {
    font-size: 0.875rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

/* ============================================
   ICON ACCESSIBILITY
   ============================================ */

/* Icons decorativos */
[aria-hidden="true"],
.icon-decorative {
    speak: never;
}

/* Icons informativos devem ter label */
.icon[role="img"] {
    display: inline-block;
}

/* ============================================
   LOADING STATES
   ============================================ */

[aria-busy="true"] {
    cursor: wait;
    opacity: 0.7;
}

/* Spinner com descrição */
.spinner[role="status"] {
    display: inline-flex;
    align-items: center;
}

.spinner[role="status"]::after {
    content: "";
    width: 1rem;
    height: 1rem;
    border: 2px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 0.5rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   NAVIGATION ACCESSIBILITY
   ============================================ */

nav[aria-label] {
    margin-bottom: 1rem;
}

/* Breadcrumbs - Sprint 2.3.1 */
nav[aria-label="Breadcrumb"] ol {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
    margin: 0;
}

nav[aria-label="Breadcrumb"] li {
    display: flex;
    align-items: center;
}

nav[aria-label="Breadcrumb"] li:not(:last-child)::after {
    content: "/";
    margin: 0 0.5rem;
    color: #9ca3af;
}

nav[aria-label="Breadcrumb"] a {
    color: #6b7280;
    text-decoration: none;
}

nav[aria-label="Breadcrumb"] a:hover {
    color: #2563eb;
    text-decoration: underline;
}

nav[aria-label="Breadcrumb"] [aria-current="page"] {
    color: #1f2937;
    font-weight: 500;
}

/* ============================================
   PAGINATION ACCESSIBILITY
   ============================================ */

nav[aria-label="Paginação"] {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
}

nav[aria-label="Paginação"] a,
nav[aria-label="Paginação"] span {
    padding: 0.5rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    text-decoration: none;
    color: #374151;
}

nav[aria-label="Paginação"] a:hover {
    background: #f3f4f6;
}

nav[aria-label="Paginação"] [aria-current="page"] {
    background: #2563eb;
    color: white;
    border-color: #2563eb;
}

nav[aria-label="Paginação"] [aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
}
