/**
 * WhiteR Pro - WCAG 2.2 Accessibility Fixes
 * @version 1.0.0
 */

/* ==================== FOCUS STATES ==================== */
:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* High contrast focus for buttons */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(var(--color-primary-rgb), 0.2);
}

/* ==================== SKIP LINK ==================== */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 9999;
    padding: 1rem 1.5rem;
    background-color: var(--color-primary);
    color: white;
    font-weight: 600;
    text-decoration: none;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
}

/* ==================== SCREEN READER ONLY ==================== */
.sr-only,
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sr-only-focusable:focus,
.screen-reader-text:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: inherit;
}

/* ==================== MINIMUM TARGET SIZE ==================== */
/* WCAG 2.2 requires 24x24px minimum touch target */
button,
a,
input[type="checkbox"],
input[type="radio"],
select {
    min-height: 24px;
    min-width: 24px;
}

/* Larger touch targets for mobile */
@media (pointer: coarse) {
    button,
    a.btn,
    .nav-link,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ==================== COLOR CONTRAST ==================== */
/* Ensure sufficient contrast ratios */
.text-muted {
    color: var(--text-muted);
    /* Minimum 4.5:1 contrast ratio for normal text */
}

/* Link underlines for distinguishability */
a:not(.btn):not(.nav-link):not(.whiter-cta) {
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:not(.btn):not(.nav-link):not(.whiter-cta):hover {
    text-decoration-thickness: 2px;
}

/* ==================== FORM ACCESSIBILITY ==================== */
/* Required field indicator */
.form-label.required::after {
    content: ' *';
    color: #dc2626;
}

/* Error states */
.form-input.error,
.form-textarea.error,
.form-select.error {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.form-error {
    color: #dc2626;
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Success states */
.form-input.success,
.form-textarea.success {
    border-color: var(--color-secondary);
}

/* Disabled states */
input:disabled,
textarea:disabled,
select:disabled,
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ==================== MOTION PREFERENCES ==================== */
@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 transitions but make them instant */
    .whiter-popup,
    .whiter-cookie-banner,
    .mobile-menu {
        transition: none !important;
    }
}

/* ==================== HIGH CONTRAST MODE ==================== */
@media (prefers-contrast: high) {
    :root {
        --border-color: currentColor;
    }
    
    button,
    input,
    select,
    textarea {
        border: 2px solid currentColor;
    }
    
    a {
        text-decoration: underline;
        text-decoration-thickness: 2px;
    }
}

/* ==================== FORCED COLORS (Windows High Contrast) ==================== */
@media (forced-colors: active) {
    .btn,
    button {
        border: 2px solid currentColor;
    }
    
    :focus-visible {
        outline: 3px solid CanvasText;
    }
    
    a {
        text-decoration: underline;
    }
}

/* ==================== TEXT SPACING ==================== */
/* Support for user text spacing overrides (WCAG 1.4.12) */
body {
    line-height: 1.5;
    letter-spacing: normal;
    word-spacing: normal;
}

p {
    margin-bottom: 1em;
}

/* ==================== REFLOW ==================== */
/* Ensure content reflows at 400% zoom (WCAG 1.4.10) */
@media (max-width: 320px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .whiter-nav {
        flex-wrap: wrap;
    }
    
    .hero-title {
        font-size: 1.75rem;
    }
}

/* ==================== VISIBLE LABELS ==================== */
/* Ensure form controls have visible labels */
.form-group {
    position: relative;
}

/* Floating label support */
.form-label-floating {
    position: absolute;
    top: 0.75rem;
    left: 1rem;
    font-size: 1rem;
    color: var(--text-muted);
    pointer-events: none;
    transition: all 0.2s ease;
}

.form-input:focus + .form-label-floating,
.form-input:not(:placeholder-shown) + .form-label-floating {
    top: -0.5rem;
    left: 0.75rem;
    font-size: 0.75rem;
    background-color: var(--bg-primary);
    padding: 0 0.25rem;
    color: var(--color-primary);
}

/* ==================== STATUS MESSAGES ==================== */
[role="alert"],
[role="status"] {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin: 1rem 0;
}

[role="alert"] {
    background-color: rgba(220, 38, 38, 0.1);
    border: 1px solid #dc2626;
    color: #dc2626;
}

[role="status"] {
    background-color: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--color-secondary);
    color: var(--color-secondary);
}

/* ==================== CONSISTENT NAVIGATION ==================== */
/* Ensure navigation is consistent and predictable */
.nav-link[aria-current="page"] {
    color: var(--text-primary);
    font-weight: 600;
}

.nav-link[aria-current="page"]::after {
    width: 100%;
}

/* ==================== WCAG 2.2 - DRAGGING (2.5.7) ==================== */
/* Ensure draggable elements have alternatives */
[draggable="true"] {
    cursor: grab;
}

[draggable="true"]:active {
    cursor: grabbing;
}

/* Provide keyboard alternatives for drag operations */
.sortable-item {
    position: relative;
}

.sortable-item .move-buttons {
    display: flex;
    gap: 0.25rem;
}

/* ==================== WCAG 2.2 - FOCUS NOT OBSCURED (2.4.11) ==================== */
/* Ensure focused elements are not hidden by sticky elements */
:target {
    scroll-margin-top: 100px;
}

[id] {
    scroll-margin-top: 100px;
}

/* ==================== WCAG 2.2 - VISIBLE FOCUS (2.4.12) ==================== */
/* Enhanced focus indicators */
:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
}

/* ==================== DIALOG ACCESSIBILITY ==================== */
[role="dialog"] {
    position: fixed;
}

[role="dialog"][aria-modal="true"] {
    z-index: 9999;
}

/* Trap focus within dialog */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
}

/* ==================== LOADING STATES ==================== */
[aria-busy="true"] {
    cursor: wait;
    opacity: 0.7;
}

.loading-spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .loading-spinner {
        animation: none;
        border-style: dotted;
    }
}

/* ==================== TOOLTIP ACCESSIBILITY ==================== */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
    opacity: 1;
    visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
    [data-tooltip]::after {
        transition: none;
    }
}

/* ==================== PRINT STYLES ==================== */
@media print {
    .whiter-header,
    .whiter-footer,
    .cookie-banner,
    .scroll-to-top,
    #whiter-popups,
    .no-print {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: black;
        background: white;
    }
    
    a {
        color: black;
        text-decoration: underline;
    }
    
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
    }
    
    a[href^="#"]::after,
    a[href^="javascript"]::after {
        content: "";
    }
}
