/**
 * Accessibility Enhancements for Tutoring Form
 * Screen reader optimization, high contrast mode, keyboard navigation
 */

/* ============================================
   Screen Reader Optimizations
   ============================================ */

/* Hide decorative elements from screen readers */
.nsemm-interactive-form .decorative-icon,
.nsemm-interactive-form .step-icon::before {
    aria-hidden: true;
}

/* Visually hidden but accessible to screen readers */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Screen reader friendly error messages */
.form-error[role="alert"] {
    font-weight: 600;
    margin-top: 5px;
}

.form-error::before {
    content: "Error: ";
    font-weight: 700;
}

/* Required field indicators */
.required-field::after {
    content: " (required)";
    font-weight: normal;
    font-size: 0.9em;
    color: #666;
}

/* ============================================
   Keyboard Navigation Enhancements
   ============================================ */

/* Clear focus indicators */
.nsemm-interactive-form *:focus {
    outline: 3px solid #0073aa !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

/* Skip to form link */
.skip-to-form {
    position: absolute;
    left: -9999px;
    z-index: 999;
    padding: 1em;
    background: #000;
    color: #fff;
    text-decoration: none;
}

.skip-to-form:focus {
    left: 50%;
    transform: translateX(-50%);
    top: 10px;
}

/* Tab order visual indicator */
.nsemm-interactive-form [tabindex]:focus {
    position: relative;
    z-index: 10;
}

/* Keyboard-only buttons */
.keyboard-nav-hint {
    display: none;
    position: absolute;
    background: #333;
    color: #fff;
    padding: 5px 10px;
    border-radius: 3px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
}

*:focus + .keyboard-nav-hint {
    display: block;
}

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

/* High contrast mode detection and styles */
@media (prefers-contrast: high) {
    .nsemm-interactive-form {
        border: 2px solid currentColor !important;
    }
    
    .nsemm-interactive-form input,
    .nsemm-interactive-form select,
    .nsemm-interactive-form textarea {
        border: 2px solid currentColor !important;
        background: transparent !important;
    }
    
    .nsemm-interactive-form button {
        border: 2px solid currentColor !important;
        font-weight: bold !important;
    }
    
    .form-error {
        border: 2px solid currentColor !important;
        padding: 5px !important;
    }
    
    .step-indicator.active {
        border: 3px solid currentColor !important;
        font-weight: bold !important;
    }
}

/* Forced high contrast mode class */
.high-contrast-mode .nsemm-interactive-form {
    background: #000 !important;
    color: #fff !important;
}

.high-contrast-mode .nsemm-interactive-form input,
.high-contrast-mode .nsemm-interactive-form select,
.high-contrast-mode .nsemm-interactive-form textarea {
    background: #000 !important;
    color: #fff !important;
    border: 2px solid #fff !important;
}

.high-contrast-mode .nsemm-interactive-form input:focus,
.high-contrast-mode .nsemm-interactive-form select:focus,
.high-contrast-mode .nsemm-interactive-form textarea:focus {
    outline: 3px solid #ff0 !important;
    outline-offset: 2px !important;
}

.high-contrast-mode .nsemm-interactive-form button {
    background: #fff !important;
    color: #000 !important;
    border: 2px solid #fff !important;
    font-weight: bold !important;
}

.high-contrast-mode .nsemm-interactive-form button:hover,
.high-contrast-mode .nsemm-interactive-form button:focus {
    background: #ff0 !important;
    color: #000 !important;
    border-color: #ff0 !important;
}

.high-contrast-mode .form-error {
    background: #ff0 !important;
    color: #000 !important;
    padding: 5px !important;
    font-weight: bold !important;
}

/* ============================================
   Mobile Accessibility
   ============================================ */

@media (max-width: 768px) {
    /* Larger touch targets for mobile */
    .nsemm-interactive-form input,
    .nsemm-interactive-form select,
    .nsemm-interactive-form textarea,
    .nsemm-interactive-form button {
        min-height: 44px !important;
        padding: 10px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    /* Better spacing for mobile */
    .form-group {
        margin-bottom: 20px !important;
    }
    
    /* Ensure labels are above inputs on mobile */
    .nsemm-interactive-form label {
        display: block !important;
        margin-bottom: 8px !important;
    }
    
    /* Full width elements on mobile */
    .nsemm-interactive-form input,
    .nsemm-interactive-form select,
    .nsemm-interactive-form textarea {
        width: 100% !important;
        box-sizing: border-box !important;
    }
}

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

/* Status messages for screen readers */
[aria-live="polite"] {
    position: relative;
}

[aria-live="assertive"] {
    font-weight: bold;
}

/* Progress indicators */
.form-progress[role="progressbar"] {
    position: relative;
}

.form-progress[role="progressbar"]::after {
    content: attr(aria-valuenow) "% complete";
    position: absolute;
    left: -9999px;
}

/* ============================================
   Focus Management
   ============================================ */

/* Focus trap for modal/popup elements */
.focus-trap {
    position: relative;
}

.focus-trap:focus-within {
    box-shadow: 0 0 10px rgba(0, 115, 170, 0.3);
}

/* Disabled state clarity */
.nsemm-interactive-form :disabled {
    opacity: 0.6;
    cursor: not-allowed;
    position: relative;
}

.nsemm-interactive-form :disabled::after {
    content: " (disabled)";
    position: absolute;
    left: -9999px;
}

/* ============================================
   Form Validation Accessibility
   ============================================ */

/* Accessible validation messages */
.validation-message {
    display: none;
    margin-top: 5px;
    font-size: 14px;
}

.invalid .validation-message {
    display: block;
    color: #d00;
}

input:invalid,
select:invalid,
textarea:invalid {
    border-color: #d00 !important;
}

input:valid,
select:valid,
textarea:valid {
    border-color: #0a0 !important;
}

/* Success messages */
.success-message[role="status"] {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
    padding: 10px;
    margin: 10px 0;
    border-radius: 4px;
}

/* ============================================
   Loading States
   ============================================ */

/* Accessible loading indicator */
.loading-indicator[aria-busy="true"] {
    position: relative;
}

.loading-indicator[aria-busy="true"]::after {
    content: "Loading, please wait...";
    position: absolute;
    left: -9999px;
}

/* Spinner accessibility */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top-color: #0073aa;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Print Styles for Accessibility
   ============================================ */

@media print {
    .nsemm-interactive-form {
        background: white !important;
        color: black !important;
    }
    
    .nsemm-interactive-form input,
    .nsemm-interactive-form select,
    .nsemm-interactive-form textarea {
        border: 1px solid black !important;
        background: white !important;
        color: black !important;
    }
    
    /* Show URLs for links */
    .nsemm-interactive-form a[href]::after {
        content: " (" attr(href) ")";
    }
    
    /* Hide interactive elements */
    .nsemm-interactive-form button[type="submit"] {
        display: none;
    }
}