/**
 * ACESSIBILIDADE - WCAG 2.1 AA
 * TagFarma 2.0
 */

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

/* Foco visível para todos os elementos interativos */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 3px solid #0d6efd !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.25) !important;
}

/* Remover outline apenas quando usando mouse */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: #0d6efd;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    border-radius: 0 0 4px 0;
}

.skip-to-main:focus {
    top: 0;
}

/* =====================================================
   ALTO CONTRASTE
   ===================================================== */

@media (prefers-contrast: high) {
    :root {
        --primary: #0056b3;
        --text-color: #000000;
        --bg-color: #ffffff;
    }

    body {
        background: var(--bg-color);
        color: var(--text-color);
    }

    .btn {
        border: 2px solid currentColor;
    }

    a {
        text-decoration: underline;
    }
}

/* =====================================================
   TAMANHOS DE FONTE AJUSTÁVEIS
   ===================================================== */

/* Suporte para zoom de texto até 200% */
html {
    font-size: 16px;
}

@media (max-width: 768px) {
    html {
        font-size: 14px;
    }
}

/* Permitir que usuários aumentem fonte */
body {
    font-size: 1rem;
    line-height: 1.5;
}

h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.75rem;
}

h4 {
    font-size: 1.5rem;
}

h5 {
    font-size: 1.25rem;
}

h6 {
    font-size: 1rem;
}

/* Texto pequeno ainda legível */
small,
.small {
    font-size: 0.875rem;
    min-height: 1.2em;
}

/* =====================================================
   ÁREAS CLICÁVEIS MÍNIMAS (44x44px)
   ===================================================== */

button,
.btn,
a.btn,
input[type="button"],
input[type="submit"],
input[type="reset"] {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 1rem;
}

/* Links em texto */
a:not(.btn) {
    display: inline-block;
    min-height: 24px;
    padding: 2px 0;
}

/* Checkbox e radio */
input[type="checkbox"],
input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* =====================================================
   LABELS E DESCRIÇÕES
   ===================================================== */

/* Mensagens de erro visíveis */
.error-message,
.invalid-feedback {
    color: #dc3545;
    font-weight: 600;
    margin-top: 0.25rem;
    display: block;
}

.is-invalid {
    border-color: #dc3545 !important;
}

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

/* =====================================================
   SCREEN READERS
   ===================================================== */

/* Classe para esconder visualmente mas manter para screen readers */
.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;
}

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

/* =====================================================
   CONTRASTE DE CORES (WCAG AA)
   ===================================================== */

/* Garantir contraste mínimo 4.5:1 para texto normal */
body {
    color: #212529;
    /* Contraste 16.1:1 em branco */
}

.text-muted {
    color: #6c757d !important;
    /* Contraste 4.6:1 em branco */
}

/* Links com contraste adequado */
a {
    color: #0d6efd;
    /* Contraste 4.5:1 em branco */
}

a:hover {
    color: #0a58ca;
    /* Contraste 6.1:1 em branco */
}

/* Botões com contraste adequado */
.btn-primary {
    background-color: #0d6efd;
    border-color: #0d6efd;
    color: #ffffff;
    /* Contraste 8.6:1 */
}

.btn-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
    color: #ffffff;
    /* Contraste 4.6:1 */
}

/* =====================================================
   ESTADOS INTERATIVOS
   ===================================================== */

/* Indicar elementos desabilitados */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled,
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Indicar elementos carregando */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 3px solid #0d6efd;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* =====================================================
   TABELAS ACESSÍVEIS
   ===================================================== */

table {
    border-collapse: collapse;
    width: 100%;
}

th {
    text-align: left;
    font-weight: 600;
    background-color: #f8f9fa;
}

/* Zebra striping para melhor leitura */
tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

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

/* Labels sempre visíveis */
label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

/* Campos obrigatórios */
.required::after {
    content: ' *';
    color: #dc3545;
}

/* Grupos de campos relacionados */
fieldset {
    border: 1px solid #dee2e6;
    padding: 1rem;
    margin-bottom: 1rem;
}

legend {
    font-weight: 600;
    padding: 0 0.5rem;
}

/* =====================================================
   IMAGENS ACESSÍVEIS
   ===================================================== */

/* Garantir que todas as imagens tenham alt */
img:not([alt]) {
    border: 3px solid #dc3545;
}

/* Imagens decorativas: img[alt=""] e img[role="presentation"] são permitidas */

/* =====================================================
   MODAIS ACESSÍVEIS
   ===================================================== */

/* Foco deve ser capturado no modal via JavaScript */

.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.75);
}

/* =====================================================
   NOTIFICAÇÕES ACESSÍVEIS
   ===================================================== */

.alert {
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: 0.25rem;
}

.alert-success {
    color: #0f5132;
    background-color: #d1e7dd;
    border-color: #badbcc;
}

.alert-danger {
    color: #842029;
    background-color: #f8d7da;
    border-color: #f5c2c7;
}

.alert-warning {
    color: #664d03;
    background-color: #fff3cd;
    border-color: #ffecb5;
}

.alert-info {
    color: #055160;
    background-color: #cff4fc;
    border-color: #b6effb;
}

/* =====================================================
   MODO ESCURO (DARK MODE)
   ===================================================== */

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #e0e0e0;
        --primary: #4d9fff;
    }

    body {
        background-color: var(--bg-color);
        color: var(--text-color);
    }

    .card {
        background-color: #2a2a2a;
        color: var(--text-color);
    }

    input,
    select,
    textarea {
        background-color: #2a2a2a;
        color: var(--text-color);
        border-color: #444;
    }

    .table {
        color: var(--text-color);
    }

    .table-striped tbody tr:nth-of-type(odd) {
        background-color: #2a2a2a;
    }
}


/* =====================================================
   IMPRESSÃO ACESSÍVEL
   ===================================================== */

@media print {

    /* Remover elementos não essenciais */
    nav,
    .navbar,
    .btn,
    .modal,
    .alert,
    .accessibility-toolbar {
        display: none !important;
    }

    /* Garantir contraste em impressão */
    body {
        background: white;
        color: black;
    }

    a {
        text-decoration: underline;
    }

    /* Mostrar URLs dos links */
    a[href]::after {
        content: " (" attr(href) ")";
    }
}

/* =====================================================
   SKIP LINK (Pular para conteúdo)
   ===================================================== */

.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: #0d6efd;
    color: white;
    padding: 12px 20px;
    text-decoration: none;
    z-index: 100000;
    border-radius: 0 0 8px 0;
    font-weight: 600;
    font-size: 1rem;
    transition: top 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

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

.skip-link:hover {
    background: #0a58ca;
    color: white;
}

/* =====================================================
   ACCESSIBILITY TOOLBAR (Barra de Ferramentas)
   ===================================================== */

.accessibility-toolbar {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: #ffffff;
    border: 2px solid #dee2e6;
    border-right: none;
    border-radius: 12px 0 0 12px;
    padding: 12px 8px;
    z-index: 9999;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.accessibility-toolbar button,
.accessibility-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin: 0;
    border: 2px solid #dee2e6;
    background: #f8f9fa;
    border-radius: 8px;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    transition: all 0.2s ease;
    color: #212529;
}

.accessibility-toolbar button:hover,
.accessibility-btn:hover {
    background: #0d6efd;
    color: white;
    border-color: #0d6efd;
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.3);
}

.accessibility-toolbar button:focus,
.accessibility-btn:focus {
    outline: 3px solid #4CAF50;
    outline-offset: 2px;
    background: #0d6efd;
    color: white;
}

.accessibility-toolbar button:active,
.accessibility-btn:active {
    transform: scale(0.95);
}

/* Ícones dos botões */
#toggle-contrast {
    font-size: 24px;
}

#increase-font,
#decrease-font {
    font-size: 18px;
    font-weight: bold;
}

#reset-accessibility {
    font-size: 24px;
}

/* Tooltip ao passar o mouse */
.accessibility-toolbar button::before,
.accessibility-btn::before {
    content: attr(aria-label);
    position: absolute;
    right: 100%;
    margin-right: 12px;
    background: #212529;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    font-weight: normal;
}

.accessibility-toolbar button:hover::before,
.accessibility-btn:hover::before {
    opacity: 1;
}

/* Responsivo - Esconder em mobile pequeno */
@media (max-width: 576px) {
    .accessibility-toolbar {
        padding: 8px 4px;
    }

    .accessibility-toolbar button,
    .accessibility-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .accessibility-toolbar button::before,
    .accessibility-btn::before {
        display: none;
        /* Esconder tooltips em mobile */
    }
}

/* =====================================================
   HIGH CONTRAST MODE (Modo Alto Contraste)
   ===================================================== */

body.high-contrast {
    background: #000 !important;
    color: #fff !important;
}

body.high-contrast .navbar {
    background: #000 !important;
    border-bottom: 2px solid #fff !important;
}

body.high-contrast .card {
    background: #000 !important;
    border: 2px solid #fff !important;
    color: #fff !important;
}

body.high-contrast .btn {
    border: 2px solid currentColor !important;
    font-weight: bold !important;
}

body.high-contrast a {
    text-decoration: underline !important;
    color: #fff !important;
}

body.high-contrast input,
body.high-contrast select,
body.high-contrast textarea {
    background: #000 !important;
    color: #fff !important;
    border: 2px solid #fff !important;
}

body.high-contrast .accessibility-toolbar {
    background: #000 !important;
    border-color: #fff !important;
}

body.high-contrast .accessibility-toolbar button,
body.high-contrast .accessibility-btn {
    background: #000 !important;
    color: #fff !important;
    border-color: #fff !important;
}

body.high-contrast .accessibility-toolbar button:hover,
body.high-contrast .accessibility-btn:hover {
    background: #fff !important;
    color: #000 !important;
}