/**
 * Widget de Acessibilidade v3.0 - Estilos Profissionais
 * Design inspirado em padrões de governo e ferramentas líderes
 */

/* ============================================
   RESET & VARIÁVEIS
   ============================================ */
:root {
    /* Cores Institucionais */
    --acc-primary: #00318B;       /* Azul Institucional */
    --acc-primary-dark: #002366;
    --acc-primary-light: #335eb0;
    --acc-accent: #00A3FF;        /* Destaque */
    
    /* Cores de Interface */
    --acc-bg: #ffffff;
    --acc-bg-hover: #f0f4fa;
    --acc-text: #1a1a1a;
    --acc-text-light: #666666;
    --acc-border: #e0e0e0;
    --acc-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    
    /* Dimensões */
    --acc-fab-size: 48px;
    --acc-panel-width: 360px; /* Aumentado para evitar quebra de texto */
    --acc-z-index: 100000;
}

/* Ocultar painel antigo para evitar duplicidade */
.preciso-panel {
    display: none !important;
}

/* ============================================
   CONTAINER PRINCIPAL (ROOT)
   ============================================ */
.acc-widget-root {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    line-height: 1.5;
    /* Garante que o widget nunca seja afetado por filtros da página */
    filter: none !important;
    -webkit-filter: none !important;
    position: fixed;
    z-index: var(--acc-z-index);
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none; /* Permite clicar através da área vazia */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.acc-widget-root * {
    box-sizing: border-box;
}

/* ============================================
   BOTÃO FLUTUANTE (FAB)
   ============================================ */
.acc-fab {
    pointer-events: auto;
    width: var(--acc-fab-size);
    height: var(--acc-fab-size);
    border-radius: 50%;
    background: var(--acc-primary);
    color: white;
    border: 2px solid white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    z-index: 2;
}

.acc-fab:hover {
    transform: scale(1.1);
    background: var(--acc-primary-light);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.acc-fab:focus-visible {
    outline: 3px solid var(--acc-accent);
    outline-offset: 2px;
}

.acc-fab i {
    font-size: 22px;
}

/* Estado Ativo (quando painel aberto) */
.acc-fab[aria-expanded="true"] {
    background: var(--acc-text); /* Cor escura para fechar */
    border-color: var(--acc-border);
    /* Transform removed to prevent icon rotation */
}

/* ============================================
   PAINEL DE OPÇÕES
   ============================================ */
.acc-panel {
    pointer-events: auto;
    position: absolute;
    top: 0;
    right: 60px; /* Distância fixa do botão (48px + gap) */
    width: 360px; /* Largura fixa explícita */
    min-width: 360px; /* Garante que não encolha */
    background: var(--acc-bg);
    border-radius: 12px;
    box-shadow: var(--acc-shadow);
    opacity: 0;
    transform: translateX(20px) scale(0.95);
    transform-origin: top right;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    visibility: hidden;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0,0,0,0.05);
}

.acc-panel.active {
    opacity: 1;
    transform: translateX(0) scale(1);
    visibility: visible;
}

/* Cabeçalho */
.acc-header {
    padding: 16px 20px;
    background: var(--acc-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.acc-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.acc-close-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.acc-close-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* Grid de Opções */
.acc-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 colunas */
    gap: 1px;
    background: var(--acc-border); /* Cria as linhas da grid */
    padding: 1px; /* Borda externa */
}

.acc-option-btn {
    background: var(--acc-bg);
    border: none;
    padding: 12px 5px; /* Reduzido padding lateral para dar mais espaço ao texto */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    min-height: 80px;
    color: var(--acc-text);
    width: 100%; /* Garante uso total da célula */
}

.acc-option-btn:hover {
    background: var(--acc-bg-hover);
    color: var(--acc-primary);
}

.acc-option-btn.active {
    background: #e3f2fd;
    color: var(--acc-primary-dark);
    position: relative;
}

.acc-option-btn.active::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 12px 12px 0;
    border-color: transparent var(--acc-primary) transparent transparent;
}

.acc-option-btn:focus-visible {
    outline: 2px solid var(--acc-primary);
    z-index: 1;
}

.acc-icon {
    font-size: 24px; /* Ícone levemente maior */
    color: var(--acc-primary);
    margin-bottom: 2px;
}

.acc-option-btn.active .acc-icon {
    color: var(--acc-primary-dark);
}

.acc-label {
    font-size: 12px; /* Fonte maior para legibilidade */
    font-weight: 600;
    text-align: center;
    line-height: 1.3;
    max-width: 100%;
}

/* Botão Resetar (Destaque) */
.acc-reset-btn {
    grid-column: span 2; /* Ocupa largura total */
    flex-direction: row;
    height: 45px;
    min-height: auto;
    background: #f8f9fa;
    color: #d32f2f;
    gap: 10px;
}

.acc-reset-btn .acc-icon {
    font-size: 14px;
    margin: 0;
    color: #d32f2f;
}

.acc-reset-btn:hover {
    background: #ffebee;
}

/* Rodapé */
.acc-footer {
    padding: 8px;
    text-align: center;
    font-size: 10px;
    color: #999;
    background: #fcfcfc;
    border-top: 1px solid var(--acc-border);
}

/* ============================================
   MODOS DE ACESSIBILIDADE (Classes no BODY)
   ============================================ */

/* 1. Grayscale Overlay */
body.acc-grayscale::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    pointer-events: none;
    backdrop-filter: grayscale(100%);
    -webkit-backdrop-filter: grayscale(100%);
}

@supports not (backdrop-filter: grayscale(100%)) {
    body.acc-grayscale {
        filter: grayscale(100%);
    }
}

/* 2. Modo Escuro / Contraste Negativo */
body.acc-negative-contrast::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    pointer-events: none;
    backdrop-filter: invert(100%) hue-rotate(180deg);
    -webkit-backdrop-filter: invert(100%) hue-rotate(180deg);
}

@supports not (backdrop-filter: invert(100%)) {
    body.acc-negative-contrast {
        filter: invert(100%) hue-rotate(180deg);
    }
    body.acc-negative-contrast .acc-widget-root {
        filter: invert(100%) hue-rotate(180deg);
    }
}

/* 4. Links Sublinhados */
body.acc-underline-links a {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 2px !important;
}

/* 5. Fonte Legível */
body.acc-readable-font {
    font-family: Arial, Helvetica, sans-serif !important;
}
body.acc-readable-font * {
    font-family: Arial, Helvetica, sans-serif !important;
}

/* ============================================
   RESPONSIVIDADE (Mobile)
   ============================================ */
@media (max-width: 768px) {
    .acc-widget-root {
        right: 15px;
        left: auto;
        top: auto;
        bottom: 170px;
        transform: none;
        align-items: flex-end;
    }
    
    .acc-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
        z-index: 100001;
    }
    
    .acc-panel.active {
        transform: translateY(0);
    }
    
    .acc-fab {
        width: 50px;
        height: 50px;
    }
    
    /* Overlay Escuro para Mobile */
    .acc-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 99998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s;
    }
    
    .acc-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

/* ============================================
   VLIBRAS POSITION FIX
   ============================================ */
/* Posiciona o VLibras logo abaixo do widget de acessibilidade */
div[vw] {
    right: 10px !important;
    top: 60% !important; /* Bem abaixo do widget de acessibilidade */
    bottom: auto !important;
    transform: translateY(-50%) !important;
    position: fixed !important;
    z-index: 9998 !important; /* Atrás do painel de acessibilidade */
}

@media (max-width: 768px) {
    div[vw] {
        right: 10px !important;
        top: auto !important;
        bottom: 20px !important; /* Canto inferior direito em mobile */
        transform: none !important;
    }
    
    /* Ajusta widget de acessibilidade para ficar acima do VLibras em mobile */
    /* .acc-widget-root rule removed as it is now on the left side */
}
