/**
 * Progressive Day - Accessibility Styles
 * WCAG 2.1 AA compliant styles for enhanced accessibility
 * Part of Competitive Parity Initiative 1.1 Week 4-5
 */

/* ========================================
   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: 0;
}

.sr-only-focusable:focus,
.sr-only-focusable:active {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

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

:root {
    --pd-focus-ring: #0066cc;
    --pd-focus-ring-offset: 2px;
    --pd-focus-ring-width: 3px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --pd-focus-ring: currentColor;
        --pd-focus-ring-width: 4px;
    }
}

/* Enhanced focus visibility */
*:focus-visible {
    outline: var(--pd-focus-ring-width) solid var(--pd-focus-ring);
    outline-offset: var(--pd-focus-ring-offset);
}

/* Remove outline for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* ========================================
   Keyboard Navigation Hints
   ======================================== */

kbd {
    display: inline-block;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 0.875em;
    color: var(--pd-text-primary);
    background-color: var(--pd-gray-100);
    border: 1px solid var(--pd-gray-300);
    border-radius: 3px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

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

.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--pd-primary);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    font-weight: 600;
    z-index: 100000;
    border-radius: 0 0 4px 0;
    transition: top 0.2s ease;
}

.skip-to-content:focus {
    top: 0;
    outline: 3px solid var(--pd-focus-ring);
    outline-offset: 2px;
}

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

[data-contrast="high"] {
    --pd-text-primary: #000000;
    --pd-text-secondary: #000000;
    --pd-bg-primary: #ffffff;
    --pd-bg-secondary: #f0f0f0;
    --pd-border-color: #000000;
    --pd-primary: #0000ff;
    --pd-link-color: #0000ff;
}

[data-contrast="high"] * {
    border-color: currentColor !important;
}

[data-contrast="high"] img {
    filter: contrast(1.5);
}

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

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

[data-motion="reduced"] *,
[data-motion="reduced"] *::before,
[data-motion="reduced"] *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

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

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

[data-font-size="medium"] {
    font-size: 16px; /* Default */
}

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

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

/* ========================================
   Accessibility Toolbar
   ======================================== */

.accessibility-toolbar {
    position: fixed;
    top: 96px;
    right: -280px;
    width: 280px;
    background: #ffffff;
    border: 2px solid #dee2e6;
    border-right: none;
    border-radius: 8px 0 0 8px;
    padding: 12px;
    box-shadow: -2px 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    transition: right 0.3s ease;
}

.accessibility-toolbar.open {
    right: 0;
}

.accessibility-toolbar-toggle {
    position: fixed;
    top: 96px;
    right: 16px;
    background: var(--pd-primary);
    color: white;
    border: none;
    border-radius: 8px 0 0 8px;
    padding: 12px 8px;
    cursor: pointer;
    z-index: 10000;
    font-size: 20px;
    line-height: 1;
}

.accessibility-toolbar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.15);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 9998;
}

.accessibility-toolbar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.accessibility-toolbar-toggle:hover {
    background: var(--pd-primary-dark);
}

.accessibility-toolbar-toggle:focus {
    outline: 3px solid var(--pd-focus-ring);
    outline-offset: 2px;
}

.accessibility-toolbar h3 {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
}

.accessibility-toolbar-group {
    margin-bottom: 16px;
}

.accessibility-toolbar-group:last-child {
    margin-bottom: 0;
}

.accessibility-toolbar-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.accessibility-toolbar button,
.accessibility-toolbar select {
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: #ffffff;
    color: #212529;
    cursor: pointer;
    font-size: 14px;
    text-align: left;
}

.accessibility-toolbar button:hover {
    background: #f8f9fa;
    color: #212529;
}

.accessibility-toolbar button.active {
    background: #0d6efd;
    color: white;
    border-color: #0d6efd;
}

.accessibility-toolbar button.active:hover {
    background: #0b5ed7;
    color: #fff;
}

.accessibility-toolbar h3 {
    color: #212529;
}

.accessibility-toolbar-group label {
    color: #212529;
}

/* ========================================
   Interactive Element States
   ======================================== */

/* Ensure all interactive elements have visible focus states */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
    outline: var(--pd-focus-ring-width) solid var(--pd-focus-ring);
    outline-offset: var(--pd-focus-ring-offset);
}

/* Enhanced hover states for better affordance */
a:hover,
button:not(:disabled):hover,
[role="button"]:hover {
    text-decoration: underline;
    cursor: pointer;
}

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

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

/* Required field indicators */
.required::after,
label.required::after {
    content: " *";
    color: var(--pd-danger, #dc3545);
    font-weight: bold;
}

/* Error states */
.is-invalid,
.form-control.is-invalid {
    border-color: var(--pd-danger, #dc3545) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.invalid-feedback {
    display: block;
    color: var(--pd-danger, #dc3545);
    font-size: 0.875em;
    margin-top: 4px;
}

/* Success states */
.is-valid,
.form-control.is-valid {
    border-color: var(--pd-success, #28a745) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* ========================================
   Modal Accessibility
   ======================================== */

.modal {
    /* Ensure modals are announced to screen readers */
}

.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.5);
}

/* ========================================
   Color Contrast Helpers
   ======================================== */

/* Ensure minimum 4.5:1 contrast ratio for normal text */
.text-muted {
    color: #666666 !important; /* 4.54:1 on white */
}

/* Ensure minimum 3:1 contrast ratio for large text (18pt+) */
.text-secondary {
    color: #757575 !important; /* 4.6:1 on white */
}

/* ========================================
   Touch Target Sizes
   ======================================== */

/* Ensure minimum 44x44px touch targets (WCAG 2.1 AA) */
button,
a.btn,
[role="button"],
[role="link"] {
    min-height: 44px;
    min-width: 44px;
}

/* Checkboxes and radios: increase clickable area without enlarging the input itself */
input[type="checkbox"],
input[type="radio"] {
    /* Use padding on parent label or wrapper to achieve 44x44px touch target */
    cursor: pointer;
}

/* Exception for inline links */
p a,
li a,
td a,
a:not(.btn) {
    min-height: auto;
    min-width: auto;
}

/* ========================================
   Table Accessibility
   ======================================== */

/* Ensure tables have proper headers */
table caption {
    padding: 8px;
    caption-side: top;
    font-weight: 600;
    text-align: left;
}

th {
    font-weight: 600;
    text-align: left;
}

/* Striped rows for better readability */
.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, 0.02);
}

/* ========================================
   Live Regions for Screen Readers
   ======================================== */

[role="status"],
[role="alert"],
[aria-live] {
    position: relative;
}

/* ========================================
   Print Accessibility
   ======================================== */

@media print {
    .accessibility-toolbar,
    .accessibility-toolbar-toggle,
    .skip-to-content {
        display: none !important;
    }

    /* Ensure links are visible in print */
    a[href]::after {
        content: " (" attr(href) ")";
    }

    /* Don't show URL for skip links, anchors, or javascript links */
    a[href^="#"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }
}
