/* ==========================================================================
   Панель доступности (Accessibility Panel)
   ========================================================================== */

/* Защита иконок от смены шрифта */
.material-icons {
    font-family: 'Material Icons' !important;
}

/* Фиксированная панель */
.accessibility-panel {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    width: 420px;
    max-width: 100vw;
    overflow-y: auto;
    background: #ffffff;
    z-index: 1040;
    transition: transform 0.3s ease;
    transform: translateX(100%);
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.15);
    padding: 1.25rem;
    margin: 0 !important;
    box-sizing: border-box;
}

/* На мобильных устройствах панель занимает 85% экрана */
@media (max-width: 575.98px) {
    .accessibility-panel {
        width: 85%;
    }
}

/* Переключатель открытия панели */
.accessibility-panel.show {
    transform: translateX(0);
}

/* Фиксированная кнопка открытия панели */
.accessibility-btn {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 1050;
    background: var(--accent-purple, #855533 );
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 52px;
    height: 52px;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(93, 58, 155, 0.3);
    transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.accessibility-btn:hover {
    background: rgb(133 69 53 / 0.63);
    transform: scale(1.08);
    box-shadow: 0 6px 18px rgba(93, 58, 155, 0.4);
}



/* Иконки Material Icons внутри кнопок панели */
.accessibility-panel .material-icons {
    font-size: 1.25rem;
    line-height: 1;
    vertical-align: middle;
}

.accessibility-panel {
    padding-bottom: 5rem !important;
}

/* ==========================================================================
   Адаптация панели под тёмную тему Bootstrap 5 и высокую контрастность
   ========================================================================== */

/* Переключение фона и цвета текста панели в зависимости от data-bs-theme */
[data-bs-theme="dark"] .accessibility-panel {
    background-color: var(--bs-body-bg, #212529) !important;
    color: var(--bs-body-color, #f8f9fa) !important;
    border-left: 1px solid var(--bs-border-color, #495057);
}

/* Заголовок и метки полей */
[data-bs-theme="dark"] .accessibility-panel h5,
[data-bs-theme="dark"] .accessibility-panel label {
    color: var(--bs-body-color, #f8f9fa) !important;
}

/* Адаптация кнопок .btn-outline-dark для тёмной темы */
[data-bs-theme="dark"] .accessibility-panel .btn-outline-dark {
    color: #f8f9fa !important;
    border-color: #6c757d !important;
    background-color: transparent;
}

[data-bs-theme="dark"] .accessibility-panel .btn-outline-dark:hover,
[data-bs-theme="dark"] .accessibility-panel .btn-outline-dark:focus {
    color: #212529 !important;
    background-color: #f8f9fa !important;
    border-color: #f8f9fa !important;
}

/* Выпадающий список (select) */
[data-bs-theme="dark"] .accessibility-panel .form-select {
    background-color: var(--bs-body-bg, #212529) !important;
    color: var(--bs-body-color, #f8f9fa) !important;
    border-color: var(--bs-border-color, #495057) !important;
}

[data-bs-theme="dark"] .accessibility-panel .form-select option {
    background-color: #212529 !important;
    color: #f8f9fa !important;
}

/* Принудительная контрастность при включении режима high-contrast */
body.high-contrast .accessibility-panel {
    background-color: #000000 !important;
    color: #ffffff !important;
    border-left: 2px solid #ffffff !important;
}

body.high-contrast .accessibility-panel .btn-outline-dark,
body.high-contrast .accessibility-panel .form-select {
    background-color: #000000 !important;
    color: #ffffff !important;
    border-color: #ffffff !important;
}

/* ==========================================================================
   Режимы отображения и стилизации доступности
   ========================================================================== */

/* 1. Высокая контрастность */
body.high-contrast * {
    color: #ffffff !important;
    background-color: #000000 !important;
    border-color: #ffffff !important;
}

body.high-contrast a {
    color: #00ffff !important;
    text-decoration: underline !important;
}

/* 2. Цветовые фильтры дальтонизма */
/* Протанопия (дефицит красного) - ИСПРАВЛЕНО: contrast(1) вместо contract(1) */
#page-wrapper.filter-protanopia,
body.filter-protanopia #page-wrapper,
body.filter-protanopia header {
    filter: contrast(1) sepia(0.6) hue-rotate(-30deg) saturate(1.4) !important;
}

/* Дейтеранопия (дефицит зеленого) */
#page-wrapper.filter-deuteranopia,
body.filter-deuteranopia #page-wrapper,
body.filter-deuteranopia header {
    filter: sepia(0.8) hue-rotate(170deg) saturate(1.2) !important;
}

/* Тританопия (дефицит синего) */
#page-wrapper.filter-tritanopia,
body.filter-tritanopia #page-wrapper,
body.filter-tritanopia header {
    filter: sepia(0.5) hue-rotate(210deg) saturate(2) !important;
}

/* 3. Инверсия цветов */
body.invert-colors {
    filter: invert(100%) hue-rotate(180deg) !important;
    background-color: #ffffff !important;
}

/* Возвращаем естественный вид картинкам, видео и иконкам при инверсии */
body.invert-colors img,
body.invert-colors video,
body.invert-colors iframe,
body.invert-colors .material-icons,
body.invert-colors [style*="background-image"] {
    filter: invert(100%) hue-rotate(180deg) !important;
}

/* 4. Оттенки серого */
body.grayscale #page-wrapper,
body.grayscale .accessibility-panel,
body.grayscale .accessibility-btn {
    filter: grayscale(100%);
}

/* 5. Подсветка ссылок */
body.highlight-links a {
    text-decoration: underline !important;
    text-decoration-color: #ff9800 !important;
    text-decoration-thickness: 2px !important;
}

/* 6. Отключение анимаций */
html.animations-disabled *,
html.animations-disabled *::before,
html.animations-disabled *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
}

/* 7. Подсветка фокуса */
body.show-focus-outline *:focus,
body.focus-highlight *:focus {
    outline: 3px solid #ff9800 !important;
    outline-offset: 3px !important;
}

/* 8. Гигантский курсор (64x64px с высокой контрастностью) */
body.large-cursor,
body.large-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cpath fill='%23000000' stroke='%23ffffff' stroke-width='3' d='M2 2L24 58L34 38L58 34L2 2Z'/%3E%3C/svg%3E") 0 0, auto !important;
}

body.large-cursor a,
body.large-cursor button,
body.large-cursor select,
body.large-cursor input,
body.large-cursor [role="button"] {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cpath fill='%23000000' stroke='%23ffffff' stroke-width='3' d='M2 2L24 58L34 38L58 34L2 2Z'/%3E%3C/svg%3E") 0 0, pointer !important;
}

/* 9. Линейка для чтения (Reading Guide) */
#accessibility-reading-guide {
    position: fixed;
    left: 0;
    top: 50%;
    width: 100vw;
    height: 60px;
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 999998;
    box-shadow:
            0 -1000vh 0 1000vh rgba(0, 0, 0, 0.35),
            0  1000vh 0 1000vh rgba(0, 0, 0, 0.35);
    border-top: 2px solid #3b82f6;
    border-bottom: 2px solid #3b82f6;
    background-color: rgba(255, 255, 255, 0.05);
    transition: top 0.05s ease-out;
}

/* 10. Межбуквенный интервал */
body.wide-letter-spacing,
body.wide-letter-spacing *:not(.material-icons) {
    letter-spacing: 0.12em !important;
}

/* 11. Межсловный интервал */
body.wide-word-spacing,
body.wide-word-spacing *:not(.material-icons) {
    word-spacing: 0.25em !important;
}


/* ==========================================================================
   Скрытие изображений (Hide Images)
   ========================================================================== */
body.hide-images img,
body.hide-images svg:not(.material-icons),
body.hide-images [style*="background-image"],
body.hide-images picture,
body.hide-images figure {
    opacity: 0 !important;
    visibility: hidden !important;
}