/**
 * ComplyEur Accessibility Fixes
 * WCAG 2.1 AA Compliance Updates
 * Version: 1.0.0
 * Date: 2025-11-26
 */

/* ============================================
   1. COLOUR CONTRAST FIXES (WCAG AA 4.5:1)
   ============================================ */

/* Override status text colours for better contrast */
:root {
    /* Updated status colours with improved contrast ratios */
    /* Safe/Green: #166534 on #d1fae5 = 4.8:1 ✓ */
    --status-safe-text-accessible: #166534;
    
    /* Warning/Amber: #78350f on #fef3c7 = 5.2:1 ✓ (was #92400e = 4.3:1) */
    --status-warning-text-accessible: #78350f;
    
    /* Danger/Red: #991b1b on #fee2e2 = 5.1:1 ✓ */
    --status-danger-text-accessible: #991b1b;
    
    /* Info/Blue: #1e40af on #dbeafe = 5.5:1 ✓ */
    --status-info-text-accessible: #1e40af;
}

/* Badge contrast fixes */
.badge-warning,
.status-warning,
.forecast-badge-yellow {
    color: var(--status-warning-text-accessible, #78350f) !important;
}

.badge-success,
.status-safe,
.forecast-badge-green {
    color: var(--status-safe-text-accessible, #166534) !important;
}

.badge-danger,
.status-danger,
.forecast-badge-red {
    color: var(--status-danger-text-accessible, #991b1b) !important;
}

.badge-info,
.status-info {
    color: var(--status-info-text-accessible, #1e40af) !important;
}

/* Days remaining text colours with improved contrast */
.progress-label-amber,
.text-warning {
    color: #78350f !important; /* Improved from #92400e */
}

.progress-label-green,
.text-success {
    color: #166534 !important; /* Maintained good contrast */
}

.progress-label-red,
.text-danger {
    color: #991b1b !important; /* Good contrast */
}

/* Days used badge contrast fixes */
.days-used-amber {
    color: #78350f !important;
    background: #fef3c7;
}

.days-used-green {
    color: #166534 !important;
    background: #dcfce7;
}

.days-used-red {
    color: #991b1b !important;
    background: #fee2e2;
}


/* ============================================
   2. FOCUS INDICATORS (WCAG 2.4.7)
   ============================================ */

/* Brand-aligned focus tokens */
:root {
    --focus-ring-color: var(--brand-blue-primary, #385070);
    --focus-ring-shadow: 0 0 0 4px rgba(56, 80, 112, 0.2);
    --focus-outline-radius: 4px;
}

/* Global focus-visible styles */
*:focus-visible {
    outline: 2px solid var(--focus-ring-color) !important;
    outline-offset: 2px !important;
}

/* Remove default outlines when using focus-visible */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Button focus states */
.btn:focus-visible,
button:focus-visible {
    outline: 2px solid var(--focus-ring-color) !important;
    outline-offset: 2px !important;
    box-shadow: var(--focus-ring-shadow) !important;
}

/* Link focus states */
a:focus-visible {
    outline: 2px solid var(--focus-ring-color) !important;
    outline-offset: 2px !important;
    border-radius: var(--focus-outline-radius);
}

/* Form input focus states */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--focus-ring-color) !important;
    outline-offset: 0 !important;
    border-color: var(--focus-ring-color) !important;
    box-shadow: 0 0 0 3px rgba(56, 80, 112, 0.15) !important;
}

/* Navigation item focus */
.nav-item:focus-visible,
.sidebar-nav a:focus-visible {
    outline: 2px solid var(--focus-ring-color) !important;
    outline-offset: -2px !important;
    background: rgba(56, 80, 112, 0.1) !important;
    box-shadow: var(--focus-ring-shadow) !important;
}

/* Dropdown item focus */
.dropdown-item:focus-visible {
    outline: 2px solid var(--focus-ring-color) !important;
    outline-offset: -2px !important;
    background: rgba(56, 80, 112, 0.06) !important;
}

/* Card focus for keyboard navigation */
.employee-card:focus-visible,
.card:focus-visible {
    outline: 2px solid var(--focus-ring-color) !important;
    outline-offset: 2px !important;
    box-shadow: var(--focus-ring-shadow) !important;
}

/* Table row focus */
tr:focus-visible {
    outline: 2px solid var(--focus-ring-color) !important;
    outline-offset: -2px !important;
}

/* Skip link focus */
.skip-link:focus {
    position: fixed !important;
    top: 10px !important;
    left: 10px !important;
    z-index: 10000 !important;
    width: auto !important;
    height: auto !important;
    padding: 12px 24px !important;
    background: #1f2937 !important;
    color: #fff !important;
    text-decoration: none !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}


/* ============================================
   3. TOUCH TARGET SIZES (WCAG 2.5.5)
   Minimum 44x44px for touch targets
   ============================================ */

@media (pointer: coarse) {
    /* Buttons */
    .btn,
    button {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
    }

    .btn-sm {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 16px;
    }

    /* Form controls */
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="date"],
    input[type="number"],
    select,
    textarea {
        min-height: 44px;
        padding: 12px 16px;
    }

    /* Checkboxes and radio buttons */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
    }

    /* Links in navigation */
    .nav-item,
    .sidebar-nav a,
    .dropdown-item {
        min-height: 44px;
        padding: 12px 16px;
    }

    /* Action buttons in tables */
    .action-buttons .btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Search input */
    #globalSearchInput,
    #employeeSearch {
        min-height: 44px;
    }

    /* Modal close button */
    .settings-modal-close,
    .modal-close {
        min-width: 44px;
        min-height: 44px;
    }

    /* Expand/collapse buttons */
    .btn-expand {
        min-width: 44px;
        min-height: 44px;
    }

    /* Employee checkbox labels */
    .employee-checkbox {
        min-height: 44px;
        padding: 12px;
    }
}


/* ============================================
   4. SCREEN READER ONLY UTILITIES
   ============================================ */

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

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


/* ============================================
   5. ARIA LIVE REGION STYLES
   ============================================ */

/* Visually hidden but announced by screen readers */
.aria-live-status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}


/* ============================================
   6. REDUCED 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;
    }

    /* Disable pulse animations */
    .badge-danger,
    .status-danger {
        animation: none !important;
    }
}


/* ============================================
   7. HIGH CONTRAST MODE SUPPORT
   ============================================ */

@media (prefers-contrast: more) {
    /* Increase border visibility */
    .card,
    .form-input,
    .btn,
    .badge {
        border: 2px solid currentColor !important;
    }

    /* Improve link visibility */
    a {
        text-decoration: underline !important;
    }

    /* Stronger focus indicators */
    *:focus-visible {
        outline-width: 3px !important;
    }
}


/* ============================================
   8. TOOLTIP ACCESSIBILITY
   ============================================ */

/* Ensure tooltips are accessible */
[data-tooltip],
[data-help] {
    position: relative;
}

[data-tooltip]:focus::after,
[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background: #1f2937;
    color: white;
    font-size: 13px;
    border-radius: 6px;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 8px;
}

/* Ensure tooltips are keyboard accessible */
[data-tooltip]:focus::after {
    display: block;
}


/* ============================================
   9. FORM ERROR STATE ACCESSIBILITY
   ============================================ */

/* Error state styling */
.form-group.has-error .form-input,
.form-input[aria-invalid="true"] {
    border-color: #dc2626 !important;
    border-width: 2px;
}

.form-group.has-error .form-label {
    color: #991b1b;
}

/* Error message styling */
.form-error,
.invalid-feedback {
    color: #991b1b;
    font-size: 13px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.form-error::before {
    content: "⚠";
    font-size: 14px;
}


/* ============================================
   10. LAST UPDATED TIMESTAMP STYLING
   ============================================ */

.data-timestamp {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
    padding: 4px 8px;
    background: #f9fafb;
    border-radius: 4px;
    margin-left: auto;
}

.data-timestamp svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
}


/* ============================================
   11. HELP TOOLTIP BUTTON STYLING
   ============================================ */

.help-tooltip-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #e5e7eb;
    color: #6b7280;
    font-size: 12px;
    font-weight: 600;
    cursor: help;
    border: none;
    margin-left: 6px;
    transition: all 0.2s;
}

.help-tooltip-trigger:hover,
.help-tooltip-trigger:focus {
    background: #f97316;
    color: white;
}

.help-tooltip-trigger:focus-visible {
    outline: 2px solid #f97316;
    outline-offset: 2px;
}


/* ============================================
   12. DUPLICATE WARNING INDICATOR
   ============================================ */

.duplicate-warning {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    margin-top: 8px;
    font-size: 14px;
    color: #78350f;
}

.duplicate-warning svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    stroke: #f59e0b;
}

.duplicate-warning a {
    color: #f97316;
    font-weight: 600;
    text-decoration: underline;
}


/* ============================================
   13. TOOLTIP CONTAINER STYLING
   ============================================ */

.tooltip-container {
    position: fixed;
    z-index: 10001;
    display: none;
    max-width: 300px;
    padding: 10px 14px;
    background: #1f2937;
    color: #fff;
    font-size: 13px;
    line-height: 1.5;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.tooltip-container::before {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: #1f2937 transparent transparent;
}

.tooltip-content {
    margin: 0;
}


/* ============================================
   14. KEYBOARD NAVIGATION HIGHLIGHTS
   ============================================ */

.dropdown-item.highlighted {
    background: #fff7ed !important;
    color: #f97316 !important;
    outline: 2px solid #f97316;
    outline-offset: -2px;
}


/* ============================================
   15. TUTORIAL MODAL STYLING
   ============================================ */

.tutorial-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.tutorial-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.tutorial-modal {
    background: white;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.tutorial-modal-overlay.active .tutorial-modal {
    transform: scale(1) translateY(0);
}

.tutorial-header {
    padding: 24px;
    background: linear-gradient(135deg, #4C739F 0%, #3A5A7C 100%);
    color: white;
    text-align: center;
}

.tutorial-header h2 {
    margin: 0 0 8px;
    font-size: 24px;
    color: white;
}

.tutorial-header p {
    margin: 0;
    opacity: 0.9;
    font-size: 14px;
}

.tutorial-body {
    padding: 24px;
}

.tutorial-step {
    display: none;
}

.tutorial-step.active {
    display: block;
}

.tutorial-step-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: #f0f9ff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.tutorial-step h3 {
    text-align: center;
    margin: 0 0 16px;
    font-size: 20px;
    color: #1f2937;
}

.tutorial-step p,
.tutorial-step ul {
    color: #4b5563;
    font-size: 15px;
    line-height: 1.7;
}

.tutorial-step ul {
    padding-left: 20px;
}

.tutorial-step li {
    margin-bottom: 8px;
}

.tutorial-footer {
    padding: 16px 24px;
    background: #f9fafb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #e5e7eb;
}

.tutorial-progress {
    display: flex;
    gap: 6px;
}

.tutorial-progress-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db;
    transition: background 0.3s;
}

.tutorial-progress-dot.active {
    background: #4C739F;
}

.tutorial-progress-dot.completed {
    background: #16a34a;
}

.tutorial-nav {
    display: flex;
    gap: 12px;
}

.tutorial-nav .btn {
    min-width: 100px;
}

.tutorial-skip {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.tutorial-skip:hover {
    background: rgba(255, 255, 255, 0.3);
}
