/* =============================================
   PT-009: Acessibilidade AA (WCAG 2.1)
   Estados de foco, navegação teclado, ARIA
   ============================================= */

/* ==========================================
   1. SKIP LINKS (navegação por teclado)
   ========================================== */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--secondary-color, #004E89);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 0 0 4px 0;
    font-weight: 600;
    z-index: 10000;
    transition: top 0.2s ease-in-out;
}

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

/* ==========================================
   2. FOCUS STATES VISÍVEIS
   ========================================== */

/* Focus global para elementos interativos */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus,
[tabindex]:focus {
    outline: 2px solid #FF6B35;
    outline-offset: 2px;
}

/* Focus para botões com ações primárias */
.btn:focus,
.btn-primary:focus,
.ui-gradient-btn:focus {
    outline: 3px solid #FF6B35;
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(255, 107, 53, 0.2);
}

/* Focus para botões de perigo */
.btn-danger:focus,
.btn-delete:focus {
    outline: 3px solid #E74C3C;
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(231, 76, 60, 0.2);
}

/* Focus para links de navegação */
.nav-link:focus {
    outline: 2px solid #FF6B35;
    outline-offset: 4px;
    border-radius: 4px;
}

/* Focus para inputs de formulários */
.ui-input:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    outline: 2px solid #FF6B35;
    outline-offset: 0;
    border-color: #FF6B35;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.15);
}

/* Focus para checkboxes e radios */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: 2px solid #FF6B35;
    outline-offset: 2px;
}

/* Focus para modal close buttons */
.modal-close:focus,
.close-alert:focus {
    outline: 2px solid #FF6B35;
    outline-offset: 2px;
    background-color: rgba(255, 107, 53, 0.1);
}

/* Focus para dropdown toggle */
.dropdown > a:focus {
    outline: 2px solid #FF6B35;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Focus para elementos de busca */
.global-search-input:focus {
    outline: 2px solid #FF6B35;
    outline-offset: 0;
    border-color: #FF6B35;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.15);
}

/* Focus para cards clicáveis */
.card:focus-within {
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.2);
    outline: 2px solid #FF6B35;
}

/* Focus para mobile toggle */
.mobile-toggle:focus {
    outline: 2px solid #FF6B35;
    outline-offset: 2px;
    border-radius: 4px;
}

/* ==========================================
   3. FOCUS VISÍVEL EM NAVEGAÇÃO
   ========================================== */

/* Remove outline apenas quando mouse é usado (não teclado) */
*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: 2px solid #FF6B35;
    outline-offset: 2px;
}

/* ==========================================
   4. ESTADOS INTERATIVOS MELHORADOS
   ========================================== */

/* Hover + Focus combinados */
button:hover:focus,
.btn:hover:focus {
    box-shadow: 0 0 0 5px rgba(255, 107, 53, 0.3);
}

/* Disabled state com melhor indicação */
button:disabled,
.btn:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    filter: grayscale(30%);
}

/* ==========================================
   5. MELHOR CONTRASTE PARA TEXTO
   ========================================== */

/* Garantir contraste mínimo 4.5:1 */
.text-muted,
.text-secondary {
    color: #555555; /* Contraste 7.46:1 em fundo branco - AAA */
}

/* Links com melhor contraste */
a {
    color: #0066CC; /* Azul com melhor contraste - 8.59:1 */
}

a:hover {
    color: #004C99; /* Azul mais escuro - 11.42:1 */
}

/* Cor primária ajustada para texto (quando necessário) */
.text-primary,
a.text-primary {
    color: #D74315; /* Laranja mais escuro - 4.51:1 - AA */
}

.text-primary:hover,
a.text-primary:hover {
    color: #B83612; /* Laranja ainda mais escuro - 5.89:1 - AAA */
}

/* ==========================================
   6. LIVE REGIONS E FEEDBACK DINÂMICO
   ========================================== */

/* Alertas/mensagens com role="alert" */
.alert,
.messages .alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-weight: 500;
}

.alert-success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.alert-error,
.alert-danger {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert-warning {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
}

.alert-info {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

/* ==========================================
   7. MODAL ACESSÍVEL
   ========================================== */

/* Modal com foco capturado - body scroll controlado via JavaScript */

.modal-content:focus {
    outline: none; /* Modal content não precisa outline, apenas elementos dentro */
}

/* ==========================================
   8. DROPDOWN ACESSÍVEL
   ========================================== */

/* Estilos para button dropdown toggle */
.dropdown > button.nav-link {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    padding: inherit;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dropdown > button.nav-link:hover {
    color: inherit;
}

.dropdown-menu[aria-hidden="true"] {
    display: none;
}

.dropdown-menu[aria-hidden="false"] {
    display: block;
}

.dropdown-menu a:focus {
    background-color: rgba(255, 107, 53, 0.1);
    outline: 2px solid #FF6B35;
    outline-offset: -2px;
}

/* ==========================================
   9. LOADING E STATUS
   ========================================== */

/* Loading spinner acessível */
.loading[aria-busy="true"]::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #FF6B35;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==========================================
   10. NAVEGAÇÃO POR TECLADO
   ========================================== */

/* Adicionar indicador visual quando navegando por tab */
body.using-keyboard *:focus {
    outline: 3px solid #FF6B35;
    outline-offset: 2px;
}

/* ==========================================
   11. VISUALMENTE OCULTO (screen reader only)
   ========================================== */

.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-width: 0;
}

.sr-only-focusable:focus,
.visually-hidden-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ==========================================
   12. MELHORIAS DE CONTRASTE
   ========================================== */

/* Badges com melhor contraste */
.badge {
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.875rem;
}

.badge-primary {
    background: #0066CC;
    color: white;
}

.badge-success {
    background: #28A745;
    color: white;
}

.badge-danger {
    background: #DC3545;
    color: white;
}

/* ==========================================
   13. TRANSIÇÕES RESPEITAM PREFERÊNCIAS
   ========================================== */

/* Respeitar preferências de movimento reduzido */
@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;
    }
}

/* ==========================================
   14. CONTRASTE AUMENTADO MANUAL (escolha do usuário)
   ========================================== */

body[data-contrast="high"] {
    --primary-color: #0000CC;
    --text-secondary: #000000;
    --border-color: #000000;
}

body[data-contrast="high"] .btn,
body[data-contrast="high"] button {
    border: 2px solid currentColor;
}

body[data-contrast="high"] a {
    text-decoration: underline;
}

body[data-contrast="high"] .settings-section .btn:focus,
body[data-contrast="high"] .settings-section .btn:focus-visible,
body[data-contrast="high"] .settings-section .card-action:focus,
body[data-contrast="high"] .settings-section .card-action:focus-visible,
body[data-contrast="high"] .auth-container .btn:focus,
body[data-contrast="high"] .auth-container .btn:focus-visible,
body[data-contrast="high"] .auth-container a:focus,
body[data-contrast="high"] .auth-container a:focus-visible,
body[data-contrast="high"] .auth-container input:focus,
body[data-contrast="high"] .auth-container input:focus-visible,
body[data-contrast="high"] .profile-section .btn:focus,
body[data-contrast="high"] .profile-section .btn:focus-visible,
body[data-contrast="high"] .profile-section a:focus,
body[data-contrast="high"] .profile-section a:focus-visible,
body[data-contrast="high"] .profile-section input:focus,
body[data-contrast="high"] .profile-section input:focus-visible,
body[data-contrast="high"] .profile-section textarea:focus,
body[data-contrast="high"] .profile-section textarea:focus-visible,
body[data-contrast="high"] .profile-section select:focus,
body[data-contrast="high"] .profile-section select:focus-visible,
body[data-contrast="high"] .settings-section input:focus,
body[data-contrast="high"] .settings-section input:focus-visible,
body[data-contrast="high"] .settings-section textarea:focus,
body[data-contrast="high"] .settings-section textarea:focus-visible,
body[data-contrast="high"] .settings-section select:focus,
body[data-contrast="high"] .settings-section select:focus-visible {
    outline: 3px solid #000;
    box-shadow: 0 0 0 4px #fff, 0 0 0 7px #000;
    border-radius: 10px;
}

.trend-chart-canvas {
    width: 100%;
    border-radius: 10px;
    outline: none;
    transition: box-shadow 0.2s ease, background-color 0.2s ease;
}

.trend-chart-canvas:focus,
.trend-chart-canvas:focus-visible {
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.35);
    background-color: rgba(255, 107, 53, 0.04);
}

body[data-contrast="high"] .trend-chart-canvas:focus,
body[data-contrast="high"] .trend-chart-canvas:focus-visible {
    outline: 3px solid #000;
    box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.85), 0 0 0 8px #000;
    background-color: rgba(255, 255, 255, 0.18);
}

/* ==========================================
   15. DARK MODE MANUAL (somente escolha do usuário)
   ========================================== */

body[data-theme="dark"] {
    --background-color: #1A1A1A;
    --surface-color: #2D2D2D;
    --text-primary: #FFFFFF;
    --text-secondary: #B8B8B8;
    --border-color: #444444;
    color-scheme: dark;
}

body[data-theme="dark"] a {
    color: #66B3FF;
}

body[data-theme="dark"] a:hover {
    color: #99CCFF;
}

