/**
 * Accessibility Styles
 * v2.5.1 - WCAG 2.1 AAA Compliance Styles
 *
 * Features:
 * - High contrast mode
 * - Font size controls
 * - Dyslexic-friendly font
 * - Reduced motion
 * - Enhanced focus indicators
 */

/* ==================== Font Imports ==================== */

/* OpenDyslexic Font (for dyslexia support) */
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/gh/antijingoist/opendyslexic@master/otf/OpenDyslexic-Regular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ==================== Accessibility Panel ==================== */

.accessibility-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

.accessibility-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.accessibility-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.accessibility-toggle:focus {
    outline: 3px solid #4A90E2;
    outline-offset: 3px;
}

.accessibility-panel-content {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    max-height: 80vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideInUp 0.3s ease;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.accessibility-panel-content[hidden] {
    display: none;
}

.panel-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.panel-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.panel-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.panel-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(80vh - 60px);
}

.panel-body fieldset {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.panel-body legend {
    font-weight: 600;
    color: #333;
    padding: 0 8px;
    font-size: 14px;
}

.setting-item {
    margin-bottom: 16px;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-item label {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #333;
    cursor: pointer;
}

.setting-item input[type="checkbox"] {
    margin-right: 10px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.setting-item small {
    display: block;
    color: #666;
    font-size: 12px;
    margin-top: 4px;
    margin-left: 28px;
}

.setting-item select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    margin-top: 8px;
    cursor: pointer;
}

.panel-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.panel-actions .btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.panel-actions .btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.panel-actions .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.panel-actions .btn-secondary {
    background: #f5f5f5;
    color: #333;
}

.panel-actions .btn-secondary:hover {
    background: #e0e0e0;
}

.panel-info {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.panel-info h3 {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
}

.shortcuts-list {
    font-size: 12px;
}

.shortcuts-list dt {
    background: #f5f5f5;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    margin-bottom: 4px;
}

.shortcuts-list dd {
    margin: 0 0 10px 0;
    color: #666;
}

/* ==================== High Contrast Mode ==================== */

.high-contrast {
    --text-color: #000;
    --bg-color: #fff;
    --link-color: #0000ff;
    --link-visited: #551a8b;
    --border-color: #000;
    --focus-color: #ff0;
}

.high-contrast body {
    background: var(--bg-color) !important;
    color: var(--text-color) !important;
}

.high-contrast a {
    color: var(--link-color) !important;
}

.high-contrast a:visited {
    color: var(--link-visited) !important;
}

.high-contrast button,
.high-contrast input,
.high-contrast select,
.high-contrast textarea {
    border: 2px solid var(--border-color) !important;
    background: var(--bg-color) !important;
    color: var(--text-color) !important;
}

.high-contrast .card,
.high-contrast .knowledge-item,
.high-contrast .calculator {
    border: 2px solid var(--border-color) !important;
    box-shadow: none !important;
}

.high-contrast img {
    filter: contrast(1.2);
}

/* ==================== Font Size Controls ==================== */

:root[data-font-size="small"] {
    font-size: 14px;
}

:root[data-font-size="medium"] {
    font-size: 16px;
}

:root[data-font-size="large"] {
    font-size: 18px;
}

:root[data-font-size="xlarge"] {
    font-size: 20px;
}

/* Maintain relative sizing */
:root[data-font-size] h1 {
    font-size: 2em;
}

:root[data-font-size] h2 {
    font-size: 1.75em;
}

:root[data-font-size] h3 {
    font-size: 1.5em;
}

:root[data-font-size] h4 {
    font-size: 1.25em;
}

:root[data-font-size] small {
    font-size: 0.875em;
}

/* ==================== Dyslexic Font ==================== */

.dyslexic-font,
.dyslexic-font * {
    font-family: 'OpenDyslexic', Arial, sans-serif !important;
}

.dyslexic-font code,
.dyslexic-font pre {
    font-family: 'Courier New', monospace !important;
}

/* ==================== Reduced Motion ==================== */

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

@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;
    }
}

/* ==================== Enhanced Focus Indicators ==================== */

.focus-visible *:focus-visible {
    outline: 3px solid #4A90E2;
    outline-offset: 2px;
    border-radius: 2px;
}

.focus-visible button:focus-visible,
.focus-visible a:focus-visible,
.focus-visible input:focus-visible,
.focus-visible select:focus-visible,
.focus-visible textarea:focus-visible {
    outline: 3px solid #4A90E2;
    outline-offset: 2px;
}

/* ==================== Skip Links ==================== */

.skip-links {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
}

.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 12px 20px;
    text-decoration: none;
    font-weight: bold;
    z-index: 10001;
    transition: top 0.2s ease;
}

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

/* ==================== Screen Reader Only ==================== */

.sr-only {
    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,
.sr-only-focusable:active {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ==================== ARIA Live Regions ==================== */

[aria-live] {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ==================== Form Error Messages ==================== */

.error-message {
    display: block;
    color: #d32f2f;
    font-size: 0.875em;
    margin-top: 4px;
    font-weight: 500;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: #d32f2f !important;
    background-color: #ffebee !important;
}

/* ==================== Notifications ==================== */

.notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 400px;
}

.notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.notification-success {
    border-left: 4px solid #4caf50;
}

.notification-info {
    border-left: 4px solid #2196f3;
}

.notification-warning {
    border-left: 4px solid #ff9800;
}

.notification-error {
    border-left: 4px solid #f44336;
}

/* ==================== Mobile Optimizations ==================== */

@media (max-width: 768px) {
    .accessibility-panel {
        bottom: 10px;
        right: 10px;
    }

    .accessibility-toggle {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    .accessibility-panel-content {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 70px;
        max-height: 70vh;
    }

    .panel-body {
        padding: 16px;
    }

    .shortcuts-list {
        font-size: 11px;
    }
}

/* ==================== Print Styles ==================== */

@media print {
    .accessibility-panel,
    .skip-links,
    .notification {
        display: none !important;
    }
}

/* ==================== Dark Mode Support ==================== */

@media (prefers-color-scheme: dark) {
    .accessibility-panel-content {
        background: #1e1e1e;
        color: #e0e0e0;
    }

    .panel-body fieldset {
        border-color: #444;
    }

    .panel-body legend {
        color: #e0e0e0;
    }

    .setting-item label {
        color: #e0e0e0;
    }

    .setting-item small {
        color: #aaa;
    }

    .setting-item select {
        background: #2a2a2a;
        color: #e0e0e0;
        border-color: #444;
    }

    .panel-actions .btn-secondary {
        background: #2a2a2a;
        color: #e0e0e0;
    }

    .panel-actions .btn-secondary:hover {
        background: #333;
    }

    .panel-info h3 {
        color: #e0e0e0;
    }

    .shortcuts-list dt {
        background: #2a2a2a;
        color: #e0e0e0;
    }

    .shortcuts-list dd {
        color: #aaa;
    }

    .notification {
        background: #2a2a2a;
        color: #e0e0e0;
    }
}

/* ==================== Keyboard Focus Indicators ==================== */

/* Visible keyboard focus for all interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid #4A90E2;
    outline-offset: 2px;
}

/* Special focus for buttons */
button:focus-visible {
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.3);
}

/* ==================== Improved Link Visibility ==================== */

a {
    text-decoration: underline;
    text-decoration-skip-ink: auto;
}

a:hover {
    text-decoration-thickness: 2px;
}

/* ==================== Improved Contrast for Text ==================== */

/* Ensure minimum contrast ratio of 7:1 for AAA compliance */
body {
    color: #1a1a1a;
}

.text-muted,
.text-secondary {
    color: #4a4a4a; /* Darker than typical gray for better contrast */
}

/* ==================== Touch Target Size ==================== */

/* Ensure minimum 44x44px touch targets for mobile */
@media (hover: none) and (pointer: coarse) {
    button,
    a,
    input,
    select,
    textarea,
    [role="button"],
    [tabindex]:not([tabindex="-1"]) {
        min-height: 44px;
        min-width: 44px;
        padding: 8px 12px;
    }
}
