/* ===================================
   NineSec - Accessibility Styles
   WCAG 2.1 AA Compliance
   Version 1.0.0
   =================================== */

/* ===================================
   1. FOCUS STATES
   =================================== */

/* High contrast focus indicator */
*:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Remove default outline for mouse users, keep for keyboard */
*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Enhanced focus for interactive elements */
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
    transition: box-shadow 0.2s ease;
}

/* ===================================
   2. SKIP LINKS
   =================================== */

.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--color-primary);
    color: white;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    font-weight: 600;
    z-index: 10000;
    border-radius: 0 0 0.5rem 0.5rem;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid white;
    outline-offset: 2px;
}

/* ===================================
   3. HIGH CONTRAST MODE SUPPORT
   =================================== */

@media (prefers-contrast: high) {
    :root {
        --color-bg-dark: hsl(0, 0%, 0%);
        --color-surface: hsl(0, 0%, 10%);
        --color-text-primary: hsl(0, 0%, 100%);
        --color-border: hsl(0, 0%, 100%);
    }

    /* Increase border widths */
    * {
        border-width: 2px !important;
    }

    /* Remove subtle effects */
    .glass-effect,
    .backdrop-blur {
        backdrop-filter: none !important;
        background: var(--color-surface) !important;
    }

    /* Higher contrast shadows */
    .shadow,
    .card {
        box-shadow: 0 0 0 2px var(--color-border) !important;
    }
}

/* ===================================
   4. SCREEN READER ONLY CONTENT
   =================================== */

.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;
}

/* ===================================
   5. COLOR CONTRAST UTILITIES
   =================================== */

/* Ensure minimum 4.5:1 contrast ratio for normal text */
.text-high-contrast {
    color: var(--color-text-primary);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* Ensure minimum 3:1 contrast ratio for large text */
.heading-high-contrast {
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

/* Link contrast */
a {
    color: var(--color-primary-light);
    text-decoration: underline;
    text-decoration-color: rgba(59, 130, 246, 0.5);
    text-underline-offset: 2px;
}

a:hover {
    text-decoration-color: var(--color-primary);
    text-decoration-thickness: 2px;
}

/* ===================================
   6. TOUCH TARGET SIZES
   =================================== */

/* Minimum 44x44px touch targets (WCAG 2.5.5) */
button,
a,
input[type="checkbox"],
input[type="radio"],
[role="button"],
[role="link"] {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Exception for text links within paragraphs */
p a,
li a {
    min-width: auto;
    min-height: auto;
}

/* ===================================
   7. TEXT SPACING & READABILITY
   =================================== */

/* WCAG 2.1.4: Text Spacing */
.readable-text {
    line-height: 1.5;
    letter-spacing: 0.12em;
    word-spacing: 0.16em;
}

p {
    margin-bottom: 1em;
}

p + p {
    margin-top: 1em;
}

/* Maximum line length for readability */
.text-content {
    max-width: 70ch; /* ~70 characters per line */
}

/* ===================================
   8. KEYBOARD NAVIGATION INDICATORS
   =================================== */

.keyboard-nav-active *:focus {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
}

/* Indicate current navigation context */
[aria-current="page"] {
    font-weight: 700;
    color: var(--color-primary);
    position: relative;
}

[aria-current="page"]::before {
    content: '';
    position: absolute;
    left: -1rem;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--color-primary);
}

/* ===================================
   9. FORM ACCESSIBILITY
   =================================== */

/* Required field indicator */
.required::after {
    content: ' *';
    color: var(--color-danger);
    font-weight: bold;
    margin-left: 0.25rem;
}

/* Error states */
.form-error {
    color: var(--color-danger);
    font-size: var(--font-size-sm);
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-error::before {
    content: '⚠';
    font-size: 1.2em;
}

/* Valid states */
.form-valid {
    border-color: var(--color-success);
}

.form-valid::after {
    content: '✓';
    color: var(--color-success);
    margin-left: 0.5rem;
}

/* Field descriptions */
.field-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-top: 0.25rem;
}

/* ===================================
   10. ARIA LIVE REGIONS
   =================================== */

[aria-live] {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
}

.toast[role="alert"],
.toast[role="status"] {
    background: var(--color-surface-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* ===================================
   11. LOADING & BUSY STATES
   =================================== */

[aria-busy="true"] {
    cursor: wait;
    opacity: 0.6;
}

.loading-spinner[role="status"] {
    position: relative;
}

.loading-spinner::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===================================
   12. MODAL & DIALOG ACCESSIBILITY
   =================================== */

[role="dialog"],
[role="alertdialog"] {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
}

/* Modal backdrop */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
}

/* Focus trap indicator */
[data-focus-trap] {
    outline: 2px dashed var(--color-primary);
    outline-offset: 4px;
}

/* ===================================
   13. TABLE ACCESSIBILITY
   =================================== */

table {
    border-collapse: collapse;
    width: 100%;
}

th {
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--color-border);
    padding: 0.75rem;
}

td {
    border-bottom: 1px solid var(--color-border-light);
    padding: 0.75rem;
}

tr:hover {
    background: var(--color-surface-hover);
}

/* Sortable columns */
th[aria-sort] {
    cursor: pointer;
    user-select: none;
}

th[aria-sort]::after {
    content: ' ↕';
    opacity: 0.5;
}

th[aria-sort="ascending"]::after {
    content: ' ↑';
    opacity: 1;
}

th[aria-sort="descending"]::after {
    content: ' ↓';
    opacity: 1;
}

/* ===================================
   14. TOOLTIP ACCESSIBILITY
   =================================== */

[role="tooltip"] {
    position: absolute;
    z-index: 1000;
    background: var(--color-bg-darker);
    border: 1px solid var(--color-border);
    border-radius: 0.25rem;
    padding: 0.5rem 0.75rem;
    font-size: var(--font-size-sm);
    max-width: 200px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* ===================================
   15. REDUCED MOTION SUPPORT
   =================================== */

@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;
    }

    /* Keep essential animations like spinners */
    .loading-spinner::after,
    [role="progressbar"] {
        animation-duration: 1s !important;
        animation-iteration-count: infinite !important;
    }
}

/* ===================================
   16. PRINT ACCESSIBILITY
   =================================== */

@media print {
    /* Show link URLs */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }

    /* Hide non-essential elements */
    nav,
    .sidebar,
    .modal,
    .toast,
    button:not(.print-visible) {
        display: none !important;
    }

    /* Ensure readable contrast */
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
}

/* ===================================
   17. FORCED COLORS MODE (Windows High Contrast)
   =================================== */

@media (forced-colors: active) {
    * {
        forced-color-adjust: auto;
    }

    .card,
    .button,
    input,
    select,
    textarea {
        border: 1px solid;
    }

    .focus-ring:focus {
        outline: 2px solid;
        outline-offset: 2px;
    }
}
