/* ============================================================
   Plugin de Acessibilidade WCAG 2.1 AA — Portal de Transparência
   Widget · Modos visuais · Zoom · Espaçamento · Foco · Guia de Leitura
   Usa variáveis de tema --pt-* definidas em portal_tema.css.
   ============================================================ */

/* ────────────────────────────────────────────────────────────
   LINK DE SALTO — "Pular para o conteúdo principal"
   Visível apenas no foco por teclado (WCAG 2.4.1)
──────────────────────────────────────────────────────────── */
.acb-skip-link {
    position: absolute;
    top: -120px;
    left: 0;
    z-index: 99999;
    background: #000;
    color: #fff !important;
    padding: 14px 28px;
    font-size: 16px;
    font-weight: 700;
    text-decoration: none;
    border-radius: 0 0 8px 0;
    transition: top 0.15s ease;
    white-space: nowrap;
}
.acb-skip-link:focus {
    top: 0;
    outline: 3px solid #ff6b35;
    outline-offset: -3px;
}

/* ────────────────────────────────────────────────────────────
   WIDGET — CONTAINER PRINCIPAL
──────────────────────────────────────────────────────────── */
#acb-widget {
    position: fixed;
    bottom: 155px;    /* Acima do leitor de tela (#sr-widget em 96px + 46px toggle + 13px gap) */
    left: 18px;
    z-index: 9997;
    font-family: 'Segoe UI', Roboto, Arial, sans-serif;
}

/* ── Botão flutuante de abertura ── */
#acb-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px 0 12px;
    height: 46px;
    border-radius: 23px;
    background: var(--pt-primaria, #1565c0);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.26);
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    white-space: nowrap;
}
#acb-toggle:hover {
    background: var(--pt-dark, #0d47a1);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.32);
}
#acb-toggle:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}
#acb-toggle .bi {
    font-size: 1.25rem;
}
.acb-badge {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    opacity: 0.92;
}

/* ── Painel de ferramentas ── */
#acb-panel {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    width: 288px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.20);
    border-top: 4px solid var(--pt-primaria, #1565c0);
    animation: acb-slide-in 0.18s ease;
    max-height: 82vh;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
}
#acb-panel[hidden] {
    display: none !important;
}
@keyframes acb-slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0);   }
}

/* ── Cabeçalho do painel ── */
.acb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    background: var(--pt-primaria, #1565c0);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 700;
    gap: 6px;
    position: sticky;
    top: 0;
    z-index: 2;
}
.acb-header span {
    display: flex;
    align-items: center;
    gap: 6px;
}
#acb-close {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    font-size: 0.95rem;
    padding: 3px 5px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
    line-height: 1;
    flex-shrink: 0;
}
#acb-close:hover { color: #fff; background: rgba(255,255,255,0.18); }
#acb-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ── Seções ── */
.acb-section {
    padding: 10px 12px 8px;
    border-bottom: 1px solid #e8ecf0;
}
.acb-section:last-of-type { border-bottom: none; }
.acb-section-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #667;
    margin: 0 0 8px;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* ── Grade 2 colunas de botões ── */
.acb-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

/* ── Botão de recurso individual ── */
.acb-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 6px 7px;
    background: #f0f4f8;
    border: 2px solid transparent;
    border-radius: 8px;
    color: #333;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    text-align: center;
    line-height: 1.25;
    min-height: 58px;
}
.acb-btn .bi {
    font-size: 18px;
    line-height: 1;
}
.acb-btn:hover {
    background: #dce8f7;
    border-color: var(--pt-primaria, #1565c0);
    color: var(--pt-dark, #0d47a1);
}
.acb-btn:focus-visible {
    outline: 2px solid #e65100;
    outline-offset: 2px;
}
.acb-btn.acb-active {
    background: var(--pt-primaria, #1565c0);
    border-color: var(--pt-dark, #0d47a1);
    color: #fff;
}
.acb-btn.acb-active .bi { color: #fff; }

/* ── Controle de zoom ── */
.acb-zoom-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
    background: #f0f4f8;
    border-radius: 8px;
    padding: 7px 12px;
}
.acb-zoom-row button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 22px;
    color: var(--pt-primaria, #1565c0);
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    line-height: 1;
    transition: color 0.15s, transform 0.12s;
}
.acb-zoom-row button:hover { color: var(--pt-dark, #0d47a1); transform: scale(1.15); }
.acb-zoom-row button:focus-visible { outline: 2px solid #e65100; outline-offset: 2px; }
.acb-zoom-val {
    font-size: 16px;
    font-weight: 700;
    color: #333;
    min-width: 52px;
    text-align: center;
    letter-spacing: 0.02em;
}

/* ── Rodapé — Redefinir Tudo ── */
.acb-footer {
    padding: 8px 12px 12px;
}
#acb-reset {
    width: 100%;
    padding: 8px 12px;
    background: #fdf0f0;
    border: 1px solid #f0d0d0;
    border-radius: 7px;
    color: #c0392b;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
#acb-reset:hover { background: #fce4e1; }
#acb-reset:focus-visible { outline: 2px solid #c0392b; outline-offset: 2px; }

/* ────────────────────────────────────────────────────────────
   GUIA DE LEITURA
──────────────────────────────────────────────────────────── */
#acb-reading-guide {
    position: fixed;
    left: 0;
    width: 100%;
    height: 28px;
    background: rgba(255, 228, 0, 0.28);
    border-top: 2px solid rgba(180, 140, 0, 0.50);
    border-bottom: 2px solid rgba(180, 140, 0, 0.50);
    pointer-events: none;
    z-index: 99990;
    top: 0;
    will-change: top;
}

/* ════════════════════════════════════════════════════════════
   MODOS DE PERCEPÇÃO VISUAL
════════════════════════════════════════════════════════════ */

/* ── Alto Contraste (WCAG 1.4.3 — razão mínima 4.5:1) ── */
html.acb-high-contrast body {
    background-color: #ffffff !important;
    color: #000000 !important;
}
html.acb-high-contrast p,
html.acb-high-contrast li,
html.acb-high-contrast td,
html.acb-high-contrast th,
html.acb-high-contrast span:not(.acb-badge):not(.sr-badge),
html.acb-high-contrast h1, html.acb-high-contrast h2,
html.acb-high-contrast h3, html.acb-high-contrast h4,
html.acb-high-contrast h5, html.acb-high-contrast h6,
html.acb-high-contrast label, html.acb-high-contrast small {
    color: #000000 !important;
    background-color: transparent !important;
}
html.acb-high-contrast a:not(#acb-widget a):not(#sr-widget a) {
    color: #0000b3 !important;
    text-decoration: underline !important;
    background: transparent !important;
}
html.acb-high-contrast .btn,
html.acb-high-contrast button:not(#acb-widget button):not(#sr-widget button) {
    background-color: #000000 !important;
    color: #ffffff !important;
    border: 2px solid #ffffff !important;
    outline: 2px solid #000000 !important;
}
html.acb-high-contrast .pnav-bar,
html.acb-high-contrast nav[role="navigation"] {
    background-color: #000000 !important;
}
html.acb-high-contrast .pnav-link,
html.acb-high-contrast .pnav-bar a {
    color: #ffffff !important;
}
html.acb-high-contrast footer,
html.acb-high-contrast .portal-footer,
html.acb-high-contrast .dr-footer {
    background-color: #000000 !important;
    color: #ffffff !important;
}
html.acb-high-contrast .footer-links a,
html.acb-high-contrast .footer-title,
html.acb-high-contrast .footer-text {
    color: #ffffff !important;
}
html.acb-high-contrast input,
html.acb-high-contrast select,
html.acb-high-contrast textarea {
    background-color: #ffffff !important;
    color: #000000 !important;
    border: 2px solid #000000 !important;
}
html.acb-high-contrast img {
    filter: contrast(110%);
}
/* Preserva estilo do próprio widget no alto contraste */
html.acb-high-contrast #acb-widget #acb-toggle,
html.acb-high-contrast #sr-widget #sr-toggle {
    background-color: var(--pt-primaria, #1565c0) !important;
    color: #ffffff !important;
    border: none !important;
    outline: none !important;
}
html.acb-high-contrast #acb-widget .acb-btn {
    background: #f0f4f8 !important;
    color: #333 !important;
    border: 2px solid transparent !important;
    outline: none !important;
}
html.acb-high-contrast #acb-widget .acb-btn.acb-active {
    background: var(--pt-primaria, #1565c0) !important;
    color: #ffffff !important;
}
html.acb-high-contrast #acb-widget #acb-reset {
    background: #fdf0f0 !important;
    color: #c0392b !important;
    border: 1px solid #f0d0d0 !important;
    outline: none !important;
}
html.acb-high-contrast #acb-widget .acb-header {
    background: var(--pt-primaria, #1565c0) !important;
    color: #ffffff !important;
}
html.acb-high-contrast #acb-widget #acb-panel {
    background: #ffffff !important;
}
html.acb-high-contrast #acb-widget .acb-section-label {
    color: #667 !important;
}
html.acb-high-contrast #acb-widget .acb-zoom-row {
    background: #f0f4f8 !important;
}

/* ── Modo Escuro ── */
html.acb-dark {
    filter: invert(1) hue-rotate(180deg);
}
html.acb-dark img,
html.acb-dark video,
html.acb-dark iframe,
html.acb-dark picture,
html.acb-dark canvas {
    filter: invert(1) hue-rotate(180deg); /* re-inverte para cor original */
}
/* Preserva widgets no modo escuro */
html.acb-dark #acb-widget,
html.acb-dark #sr-widget {
    filter: invert(1) hue-rotate(180deg);
}
html.acb-dark #acb-reading-guide {
    filter: invert(1) hue-rotate(180deg);
}

/* ── Inversão de Cores ── */
html.acb-inverted {
    filter: invert(1);
}
html.acb-inverted img,
html.acb-inverted video,
html.acb-inverted iframe,
html.acb-inverted picture,
html.acb-inverted canvas {
    filter: invert(1); /* re-inverte imagens para cor original */
}
html.acb-inverted #acb-widget,
html.acb-inverted #sr-widget {
    filter: invert(1);
}
html.acb-inverted #acb-reading-guide {
    filter: invert(1);
}

/* ── Monocromático ── */
html.acb-monochromatic {
    filter: grayscale(1);
}

/* ── Destaque de Links (WCAG 1.4.1) ── */
html.acb-link-highlight a:not(#acb-widget a):not(#sr-widget a):not(.pnav-link) {
    text-decoration: underline !important;
    text-underline-offset: 4px !important;
    text-decoration-thickness: 2px !important;
    background-color: rgba(255, 240, 0, 0.35) !important;
    color: #00007a !important;
    padding: 0 3px !important;
    border-radius: 3px !important;
}
html.acb-link-highlight a:not(#acb-widget a):not(#sr-widget a):not(.pnav-link):hover {
    background-color: rgba(255, 240, 0, 0.65) !important;
}

/* ════════════════════════════════════════════════════════════
   TEXTO E ZOOM
════════════════════════════════════════════════════════════ */

/* ── Espaçamento de Texto (WCAG 1.4.12) ── */
html.acb-text-spacing p,
html.acb-text-spacing li,
html.acb-text-spacing td, html.acb-text-spacing th,
html.acb-text-spacing h1, html.acb-text-spacing h2,
html.acb-text-spacing h3, html.acb-text-spacing h4,
html.acb-text-spacing h5, html.acb-text-spacing h6,
html.acb-text-spacing a, html.acb-text-spacing label,
html.acb-text-spacing span:not(.bi):not([class*="bi-"]):not([class*="fa"]):not(.acb-badge):not(.sr-badge) {
    line-height: 1.8 !important;
    letter-spacing: 0.10em !important;
    word-spacing: 0.14em !important;
}
/* Restaura espaçamento nos widgets */
html.acb-text-spacing #acb-widget *,
html.acb-text-spacing #sr-widget * {
    line-height: revert !important;
    letter-spacing: revert !important;
    word-spacing: revert !important;
}

/* ── Fonte Legível (sem serifa, indicada para dislexia) ── */
html.acb-readable-font body,
html.acb-readable-font p,
html.acb-readable-font h1, html.acb-readable-font h2,
html.acb-readable-font h3, html.acb-readable-font h4,
html.acb-readable-font h5, html.acb-readable-font h6,
html.acb-readable-font a, html.acb-readable-font li,
html.acb-readable-font td, html.acb-readable-font th,
html.acb-readable-font label, html.acb-readable-font button,
html.acb-readable-font input, html.acb-readable-font select,
html.acb-readable-font textarea, html.acb-readable-font small,
html.acb-readable-font span:not(.bi):not([class*="bi-"]):not([class*="fa"]) {
    font-family: Arial, Verdana, "Helvetica Neue", Helvetica, sans-serif !important;
}

/* ════════════════════════════════════════════════════════════
   NAVEGAÇÃO E FOCO
════════════════════════════════════════════════════════════ */

/* ── Foco Visível (WCAG 2.4.7) ── */
html.acb-focus-visible *:focus,
html.acb-focus-visible *:focus-visible {
    outline: 3px solid #e65100 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 6px rgba(230, 81, 0, 0.22) !important;
    border-radius: 3px !important;
}

/* ════════════════════════════════════════════════════════════
   COGNITIVO E MOTOR
════════════════════════════════════════════════════════════ */

/* ── Pausar Animações (WCAG 2.3.1 / 2.2.2) ── */
html.acb-pause-anim *,
html.acb-pause-anim *::before,
html.acb-pause-anim *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

/* ── Alvos Grandes — mínimo 44×44 px (WCAG 2.5.5) ── */
html.acb-large-targets button:not(#acb-widget button):not(#sr-widget button),
html.acb-large-targets input[type="button"],
html.acb-large-targets input[type="submit"],
html.acb-large-targets input[type="reset"],
html.acb-large-targets select,
html.acb-large-targets [role="button"] {
    min-height: 44px !important;
    min-width: 44px !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
}
html.acb-large-targets a:not(#acb-widget a):not(#sr-widget a) {
    display: inline-block !important;
    padding: 6px 4px !important;
    min-height: 44px !important;
    line-height: 32px !important;
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVIDADE
════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    #acb-widget {
        bottom: 133px;  /* Ajusta junto com #sr-widget que vai a 80px no mobile */
        left: 10px;
    }
    #acb-panel {
        width: calc(100vw - 28px);
        max-height: 75vh;
    }
    .acb-badge {
        display: none;
    }
    #acb-toggle {
        padding: 0 12px 0 10px;
        height: 42px;
    }
}
