/**
 * Acessibilidade (WCAG 2.1)
 *
 * Estilos e componentes para melhorar a acessibilidade do sistema
 * - Skip links (pular para conteúdo)
 * - Focus visible aprimorado
 * - Alto contraste
 * - Tamanhos de fonte e espaçamento
 * - Suporte para leitores de tela
 *
 * @version 1.0
 * @author Sistema Psicólogos
 */

/* =============================================================================
   SKIP LINKS - Pular para conteúdo principal
   ============================================================================= */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    z-index: 9999;
    padding: 0.75rem 1.5rem;
    background-color: var(--color-primary);
    color: white;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 0.5rem 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--color-primary-light);
    outline-offset: 3px;
}

/* =============================================================================
   FOCUS VISIBLE - Indicadores de foco aprimorados
   ============================================================================= */

/* Remover outline padrão e adicionar customizado */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 0.25rem;
}

/* Focus para botões */
button:focus-visible,
.btn:focus-visible,
a[role="button"]:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.2);
}

/* Focus para inputs */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
    outline: 2px solid var(--color-primary);
    outline-offset: 0;
}

/* Focus para links */
a:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    text-decoration: underline;
    background-color: rgba(79, 70, 229, 0.1);
    border-radius: 0.25rem;
}

/* =============================================================================
   ARIA - Suporte para leitores de tela
   ============================================================================= */

/* Esconder visualmente mas manter acessível para leitores de tela */
.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;
}

/* Mostrar quando em foco (para skip links) */
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Esconder de leitores de tela */
[aria-hidden="true"] {
    speak: none;
}

/* =============================================================================
   CONTRASTE E LEGIBILIDADE
   ============================================================================= */

/* Garantir contraste mínimo para textos pequenos */
.text-contrast-enhanced {
    color: #000000;
}

.dark .text-contrast-enhanced {
    color: #FFFFFF;
}

/* Aumentar contraste de bordas */
@media (prefers-contrast: high) {
    * {
        border-width: 2px;
    }

    button,
    .btn,
    input,
    textarea,
    select {
        border-width: 2px !important;
    }
}

/* =============================================================================
   TAMANHOS E ESPAÇAMENTO
   ============================================================================= */

/* Garantir tamanho mínimo de toque (44x44px - WCAG 2.1 AAA) */
.touch-target {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Aplicar automaticamente em botões e links interativos */
button,
.btn,
a[role="button"],
input[type="button"],
input[type="submit"] {
    min-height: 44px;
    padding: 0.625rem 1rem;
}

/* Espaçamento entre elementos interativos */
.interactive-spacing > * + * {
    margin-top: 0.5rem;
}

/* =============================================================================
   MODO DE ALTO CONTRASTE
   ============================================================================= */
@media (prefers-contrast: high) {
    :root {
        --color-bg-primary: #FFFFFF;
        --color-bg-secondary: #F0F0F0;
        --color-text-primary: #000000;
        --color-border-primary: #000000;
    }

    :root.theme-dark {
        --color-bg-primary: #000000;
        --color-bg-secondary: #1A1A1A;
        --color-text-primary: #FFFFFF;
        --color-border-primary: #FFFFFF;
    }

    /* Aumentar contraste de botões */
    button,
    .btn {
        border: 2px solid currentColor;
    }

    /* Garantir que imagens tenham borda visível */
    img {
        border: 1px solid var(--color-border-primary);
    }
}

/* =============================================================================
   REDUÇÃO 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;
    }

    /* Desabilitar parallax e transformações complexas */
    .parallax,
    .transform-3d {
        transform: none !important;
    }
}

/* =============================================================================
   INDICADORES DE ESTADO
   ============================================================================= */

/* Indicador de loading acessível */
.loading-accessible::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 3px solid var(--color-border-primary);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Indicador de required em formulários */
.required::after {
    content: '*';
    color: var(--color-error);
    margin-left: 0.25rem;
    font-weight: bold;
}

/* =============================================================================
   TOOLTIPS ACESSÍVEIS
   ============================================================================= */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%) scale(0);
    padding: 0.5rem 0.75rem;
    background-color: var(--color-bg-tertiary);
    color: var(--color-text-primary);
    font-size: 0.875rem;
    white-space: nowrap;
    border-radius: 0.375rem;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    z-index: 1000;
}

[data-tooltip]:hover::before,
[data-tooltip]:focus::before {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* =============================================================================
   TABELAS RESPONSIVAS E ACESSÍVEIS
   ============================================================================= */
.table-accessible {
    width: 100%;
    border-collapse: collapse;
}

.table-accessible th {
    background-color: var(--color-bg-secondary);
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
    border: 1px solid var(--color-border-primary);
}

.table-accessible td {
    padding: 0.75rem;
    border: 1px solid var(--color-border-primary);
}

.table-accessible tr:hover {
    background-color: var(--color-bg-tertiary);
}

/* Caption para contexto */
.table-accessible caption {
    caption-side: top;
    padding: 0.75rem;
    font-weight: 600;
    text-align: left;
    color: var(--color-text-primary);
}

/* =============================================================================
   FORMULÁRIOS ACESSÍVEIS
   ============================================================================= */

/* Labels sempre visíveis */
label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--color-text-primary);
}

/* Mensagens de erro acessíveis */
.error-message {
    color: var(--color-error);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
}

.error-message::before {
    content: '⚠';
    margin-right: 0.375rem;
    font-size: 1rem;
}

/* Input com erro */
.input-error {
    border-color: var(--color-error) !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
}

/* Descrição/ajuda do campo */
.field-description {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin-top: 0.25rem;
}

/* =============================================================================
   LANDMARKS E NAVEGAÇÃO
   ============================================================================= */

/* Garantir que landmarks sejam facilmente navegáveis */
main {
    scroll-margin-top: 2rem;
}

nav[aria-label] {
    scroll-margin-top: 2rem;
}

/* =============================================================================
   DARK MODE - Ajustes de acessibilidade
   ============================================================================= */
.dark {
    /* Garantir contraste adequado no dark mode */
    --min-contrast-ratio: 7;
}

.dark .text-muted {
    color: #D1D5DB; /* Garantir contraste mínimo de 4.5:1 */
}

/* =============================================================================
   RESPONSIVIDADE E ZOOM
   ============================================================================= */

/* Suportar zoom de até 200% sem quebrar layout */
@media (max-width: 640px) {
    body {
        font-size: 16px; /* Garantir texto legível */
    }

    /* Ajustar tamanhos de toque em mobile */
    button,
    .btn,
    a[role="button"] {
        min-height: 48px; /* iOS recomenda 48px */
    }
}

/* =============================================================================
   INDICADORES VISUAIS ADICIONAIS
   ============================================================================= */

/* Indicador de página atual em navegação */
[aria-current="page"] {
    font-weight: 700;
    border-left: 4px solid var(--color-primary);
    background-color: var(--color-bg-secondary);
}

/* Indicador de elemento expandido */
[aria-expanded="true"]::after {
    content: '▲';
    margin-left: 0.5rem;
    font-size: 0.75rem;
}

[aria-expanded="false"]::after {
    content: '▼';
    margin-left: 0.5rem;
    font-size: 0.75rem;
}

/* =============================================================================
   NOTIFICAÇÕES E ALERTAS ACESSÍVEIS
   ============================================================================= */
[role="alert"],
[role="status"] {
    padding: 1rem;
    border-left: 4px solid;
    border-radius: 0.5rem;
    margin: 1rem 0;
}

[role="alert"] {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: var(--color-error);
    color: var(--color-error);
}

[role="status"] {
    background-color: rgba(16, 185, 129, 0.1);
    border-color: var(--color-success);
    color: var(--color-success);
}
