/**
 * WCAG 2.1 AA Accessibility Styles
 * High contrast mode and enhanced focus indicators
 */

/* Screen reader only content */
.sr-only {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Skip links */
.skip-links {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--bg-primary);
    z-index: 100000;
}

.skip-link {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.skip-link:focus {
    position: static;
    width: auto;
    height: auto;
    padding: 0.75rem 1.5rem;
    background: var(--color-primary);
    color: white;
    text-decoration: none;
    border-radius: 0 0 0.5rem 0;
    box-shadow: var(--shadow-lg);
    font-weight: 600;
}

/* Enhanced focus indicators */
*:focus {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

/* Remove focus for mouse users */
.using-mouse *:focus {
    outline: none;
}

/* Button and interactive element focus */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus,
[role="button"]:focus,
[tabindex]:not([tabindex="-1"]):focus {
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.5);
}

/* High contrast mode */
.high-contrast {
    filter: contrast(1.5);
}

.high-contrast * {
    border-color: currentColor !important;
}

.high-contrast button,
.high-contrast input,
.high-contrast select,
.high-contrast textarea {
    border: 2px solid currentColor !important;
}

.high-contrast .call-button {
    background: var(--color-primary) !important;
    color: white !important;
}

.high-contrast .control-button {
    background: var(--bg-tertiary) !important;
    border: 2px solid var(--text-primary) !important;
}

/* Improved color contrast for light theme */
:root {
    /* Ensure AA compliance for text contrast */
    --text-secondary: #4B5563; /* 7.04:1 on white */
    --text-tertiary: #6B7280; /* 4.54:1 on white */
    --text-muted: #9CA3AF; /* Use sparingly, 3:1 on white */
}

/* Dark theme contrast improvements */
[data-theme="dark"] {
    --text-secondary: #D1D5DB; /* 11.35:1 on black */
    --text-tertiary: #9CA3AF; /* 7.04:1 on black */
    --text-muted: #6B7280; /* 4.54:1 on black */
}

/* Ensure link contrast */
a {
    color: var(--color-primary);
    text-decoration: underline;
}

a:hover,
a:focus {
    text-decoration: none;
}

/* Form field focus improvements */
input:focus,
select:focus,
textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

/* Error state contrast */
.error,
[aria-invalid="true"] {
    border-color: var(--color-error) !important;
    color: var(--color-error);
}

/* Success state contrast */
.success {
    color: var(--color-success);
}

/* Ensure button text contrast */
.call-button,
.control-button,
.upgrade-btn {
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Loading and disabled states */
[aria-busy="true"],
.loading {
    cursor: wait;
    opacity: 0.7;
}

[disabled],
[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Focus visible polyfill */
.js-focus-visible :focus:not(.focus-visible) {
    outline: none;
}

/* Accessibility toolbar styles */
.accessibility-toolbar {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: 0.5rem 0 0 0.5rem;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.a11y-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 0.375rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    font-size: 14px;
}

.a11y-btn:hover {
    background: var(--bg-tertiary);
    transform: translateX(-2px);
}

.a11y-btn:focus {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

/* Ensure proper heading hierarchy */
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

/* Text size adjustments */
html.text-size-small { font-size: 14px; }
html.text-size-normal { font-size: 16px; }
html.text-size-large { font-size: 18px; }
html.text-size-xlarge { font-size: 20px; }

/* Keyboard shortcuts modal */
.shortcuts-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-primary);
    border: 2px solid var(--border-primary);
    border-radius: 0.5rem;
    padding: 2rem;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 10000;
    box-shadow: var(--shadow-xl);
}

.shortcuts-modal h2 {
    margin: 0 0 1rem 0;
    color: var(--text-primary);
}

.shortcuts-modal ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.shortcuts-modal li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-primary);
    color: var(--text-secondary);
}

.shortcuts-modal kbd {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 0.25rem;
    padding: 0.125rem 0.375rem;
    font-family: monospace;
    font-size: 0.875em;
    color: var(--text-primary);
    font-weight: 600;
}

/* Mobile accessibility */
@media (max-width: 768px) {
    .accessibility-toolbar {
        transform: translateY(-50%) translateX(40px);
        transition: transform 0.3s ease;
    }
    
    .accessibility-toolbar:hover,
    .accessibility-toolbar:focus-within {
        transform: translateY(-50%) translateX(0);
    }
    
    /* Ensure touch targets are at least 44x44 pixels */
    button,
    a,
    input,
    select,
    textarea {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Print styles for better readability */
@media print {
    * {
        background: white !important;
        color: black !important;
    }
    
    .no-print,
    .accessibility-toolbar,
    .skip-links {
        display: none !important;
    }
}