/**
 * FlipSecure Accessibility Enhancements
 * Requirements: 9.5 - ARIA labels, semantic HTML, keyboard navigation, screen reader compatibility
 */

/* ===== FOCUS MANAGEMENT ===== */

/* Enhanced focus indicators */
*:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Custom focus styles for interactive elements */
.btn:focus,
.nav-link:focus,
.form-control:focus,
.modal-close:focus,
.toast-close:focus,
.alert .btn-close:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(102, 126, 234, 0.2);
}

/* Focus within containers */
/* .form-group:focus-within {
    background-color: rgba(102, 126, 234, 0.05);
    border-radius: 6px;
    transition: background-color 0.2s ease;
    padding: 10px;
} */

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #667eea;
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 0 0 4px 4px;
    z-index: 1000;
    font-weight: 600;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* ===== KEYBOARD NAVIGATION ===== */

/* Keyboard navigation for custom components */
.dropdown[tabindex="0"]:focus,
.modal[tabindex="0"]:focus,
.toast[tabindex="0"]:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Tab order management */
.modal.show {
    /* Trap focus within modal */
}

.modal.show~* {
    /* Hide other content from screen readers when modal is open */
    aria-hidden: true;
}

/* Keyboard shortcuts indicator */
.keyboard-shortcut {
    font-family: monospace;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 3px;
    padding: 0.2em 0.4em;
    font-size: 0.85em;
    color: #495057;
}

/* ===== SCREEN READER SUPPORT ===== */

/* Screen reader only content */
.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 only content that becomes visible on focus */
.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: inherit !important;
    margin: inherit !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* Live regions for dynamic content */
.live-region {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ===== ARIA ENHANCEMENTS ===== */

/* Visual indicators for ARIA states */
[aria-expanded="true"] .dropdown-icon::before {
    content: "▲";
}

[aria-expanded="false"] .dropdown-icon::before {
    content: "▼";
}

[aria-pressed="true"] {
    background-color: #667eea;
    color: white;
}

[aria-selected="true"] {
    background-color: #e8f2ff;
    border-left: 4px solid #667eea;
}

[aria-current="page"] {
    font-weight: 600;
    color: #667eea;
}

[aria-invalid="true"] {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.15) !important;
}

/* Required field indicators */
[aria-required="true"]::after,
.required::after {
    content: " *";
    color: #dc3545;
    font-weight: bold;
}

/* ===== HIGH CONTRAST MODE SUPPORT ===== */

@media (prefers-contrast: high) {

    /* Enhanced contrast for high contrast mode */
    :root {
        --primary-color: #000000;
        --secondary-color: #ffffff;
        --border-color: #000000;
        --text-color: #000000;
        --bg-color: #ffffff;
        --focus-color: #0000ff;
    }

    body {
        background: var(--bg-color) !important;
        color: var(--text-color) !important;
    }

    .btn,
    .form-control,
    .nav-link,
    .card,
    .modal-content,
    .toast,
    .alert {
        border: 2px solid var(--border-color) !important;
        background: var(--bg-color) !important;
        color: var(--text-color) !important;
    }

    .btn:focus,
    .form-control:focus,
    .nav-link:focus {
        outline: 3px solid var(--focus-color) !important;
        outline-offset: 2px !important;
    }

    /* Ensure sufficient contrast for interactive elements */
    .btn-primary {
        background: var(--text-color) !important;
        color: var(--bg-color) !important;
    }

    .btn-secondary {
        background: var(--bg-color) !important;
        color: var(--text-color) !important;
        border: 2px solid var(--text-color) !important;
    }
}

/* ===== REDUCED MOTION SUPPORT ===== */

@media (prefers-reduced-motion: reduce) {

    /* Disable animations for users who prefer reduced motion */
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Remove transform animations */
    .btn:hover,
    .card:hover,
    .nav-link:hover {
        transform: none !important;
    }

    /* Disable parallax and other motion effects */
    .parallax,
    .floating,
    .bounce {
        transform: none !important;
    }
}

/* ===== FONT SIZE PREFERENCES ===== */

@media (prefers-reduced-data: reduce) {

    /* Optimize for reduced data usage */
    .background-image,
    .hero-image,
    .decorative-image {
        display: none;
    }
}

/* ===== COLOR SCHEME PREFERENCES ===== */

@media (prefers-color-scheme: dark) {

    /* Dark mode support */
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --text-primary: #ffffff;
        --text-secondary: #b0b0b0;
        --border-color: #404040;
    }

    body {
        background-color: var(--bg-primary);
        color: var(--text-primary);
    }

    .form-control,
    .btn,
    .card,
    .modal-content {
        background-color: var(--bg-secondary);
        color: var(--text-primary);
        border-color: var(--border-color);
    }
}

/* ===== SEMANTIC HTML ENHANCEMENTS ===== */

/* Landmark roles visual indicators (for development) */
main[role="main"]::before,
nav[role="navigation"]::before,
aside[role="complementary"]::before,
section[role="region"]::before {
    content: attr(role);
    position: absolute;
    top: -20px;
    left: 0;
    font-size: 10px;
    color: #666;
    background: #f0f0f0;
    padding: 2px 4px;
    border-radius: 2px;
    display: none;
    /* Only show in development */
}

/* Heading hierarchy indicators */
h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.75rem;
}

h4 {
    font-size: 1.5rem;
}

h5 {
    font-size: 1.25rem;
}

h6 {
    font-size: 1rem;
}

/* Ensure proper heading hierarchy */
h1:not(:first-child) {
    margin-top: 2rem;
}

h2:not(:first-child) {
    margin-top: 1.5rem;
}

h3:not(:first-child),
h4:not(:first-child),
h5:not(:first-child),
h6:not(:first-child) {
    margin-top: 1rem;
}

/* ===== FORM ACCESSIBILITY ===== */

/* Enhanced form labels */
.form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: block;
    color: #2c3e50;
}

/* Form field grouping */
fieldset {
    border: 2px solid #e9ecef;
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
}

legend {
    font-weight: 600;
    padding: 0 0.5rem;
    color: #2c3e50;
}

/* Error message association */
.form-control[aria-describedby]+.invalid-feedback {
    margin-top: 0.25rem;
}

/* Help text styling */
.form-help {
    font-size: 0.875rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

/* ===== TABLE ACCESSIBILITY ===== */

/* Enhanced table headers */
th[scope="col"]::after {
    content: " (column)";
    font-size: 0;
    speak: literal-punctuation;
}

th[scope="row"]::after {
    content: " (row header)";
    font-size: 0;
    speak: literal-punctuation;
}

/* Table caption styling */
caption {
    font-weight: 600;
    text-align: left;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

/* Sortable table headers */
th[aria-sort] {
    cursor: pointer;
    user-select: none;
}

th[aria-sort="ascending"]::after {
    content: " ↑";
    color: #667eea;
}

th[aria-sort="descending"]::after {
    content: " ↓";
    color: #667eea;
}

th[aria-sort="none"]::after {
    content: " ↕";
    color: #6c757d;
    opacity: 0.5;
}

/* ===== NAVIGATION ACCESSIBILITY ===== */

/* Breadcrumb navigation */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    list-style: none;
    background-color: #f8f9fa;
    border-radius: 6px;
}

.breadcrumb-item+.breadcrumb-item::before {
    content: "/";
    color: #6c757d;
    margin: 0 0.5rem;
}

.breadcrumb-item.active {
    color: #6c757d;
}

/* Pagination accessibility */
.pagination {
    display: flex;
    padding-left: 0;
    list-style: none;
    border-radius: 6px;
}

.page-link {
    position: relative;
    display: block;
    padding: 0.5rem 0.75rem;
    margin-left: -1px;
    line-height: 1.25;
    color: #667eea;
    background-color: #fff;
    border: 1px solid #dee2e6;
    text-decoration: none;
}

.page-link:focus {
    z-index: 3;
    outline: 0;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
}

.page-item.active .page-link {
    z-index: 3;
    color: #fff;
    background-color: #667eea;
    border-color: #667eea;
}

.page-item.disabled .page-link {
    color: #6c757d;
    pointer-events: none;
    cursor: auto;
    background-color: #fff;
    border-color: #dee2e6;
}

/* ===== MODAL ACCESSIBILITY ===== */

/* Modal focus trap */
.modal.show {
    display: flex !important;
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
}

/* ===== TOOLTIP ACCESSIBILITY ===== */

.tooltip {
    position: absolute;
    z-index: 1070;
    display: block;
    margin: 0;
    font-family: inherit;
    font-style: normal;
    font-weight: 400;
    line-height: 1.5;
    text-align: left;
    text-decoration: none;
    text-shadow: none;
    text-transform: none;
    letter-spacing: normal;
    word-break: normal;
    word-spacing: normal;
    white-space: normal;
    line-break: auto;
    font-size: 0.875rem;
    word-wrap: break-word;
    opacity: 0;
}

.tooltip.show {
    opacity: 0.9;
}

.tooltip-inner {
    max-width: 200px;
    padding: 0.25rem 0.5rem;
    color: #fff;
    text-align: center;
    background-color: #000;
    border-radius: 6px;
}

/* ===== RESPONSIVE ACCESSIBILITY ===== */

@media (max-width: 768px) {

    /* Larger touch targets on mobile */
    .btn,
    .nav-link,
    .form-control,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Improved spacing for mobile */
    .form-group {
        margin-bottom: 1.5rem;
    }

    /* Larger text for better readability */
    body {
        font-size: 16px;
        line-height: 1.6;
    }
}

/* ===== PRINT ACCESSIBILITY ===== */

@media print {

    /* Ensure good contrast for print */
    * {
        color: #000 !important;
        background: transparent !important;
    }

    /* Show URLs for links */
    a[href]:after {
        content: " (" attr(href) ")";
    }

    /* Hide interactive elements */
    .btn,
    .nav-link,
    .modal,
    .toast,
    .dropdown {
        display: none !important;
    }

    /* Ensure headings don't break across pages */
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        page-break-after: avoid;
    }

    /* Avoid breaking inside important content */
    .card,
    .form-group,
    .table-row {
        page-break-inside: avoid;
    }
}