/* Core Accessibility Styles */

/* Skip links for keyboard navigation */
.skip-links {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9999;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #007bff;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: bold;
    transition: top 0.3s ease;
}

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

/* Focus management */
.focus-trap {
    position: relative;
}

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

.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: inherit !important;
    border: inherit !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {

    .btn,
    .navbar-nav .nav-link,
    .card,
    .form-control {
        border: 2px solid;
    }

    .bg-dark {
        background-color: black !important;
        color: white !important;
    }

    .text-muted {
        color: inherit !important;
    }
}

/* Breadcrumb navigation */
.breadcrumbs {
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    background-color: #f8f9fa;
    border-radius: 0.375rem;
    border: 1px solid #dee2e6;
}

.breadcrumb-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
}

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

.breadcrumb-item a {
    text-decoration: none;
    color: #007bff;
}

.breadcrumb-item a:hover,
.breadcrumb-item a:focus {
    text-decoration: underline;
    color: #0056b3;
}

.breadcrumb-item[aria-current="page"] {
    color: #6c757d;
    font-weight: 500;
}

/* Audio section styling */
.audio-section {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 0.5rem;
    margin: 0.75rem 0;
}

.audio-section h2 {
    margin-top: 0;
    margin-bottom: 0.2rem;
    font-size: 1.1rem;
    color: #495057;
}

.audio-section p {
    margin-bottom: 0.4rem;
    color: #6c757d;
    font-size: 0.9rem;
}

/* Improved focus visibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid #007bff;
    outline-offset: 2px;
    border-radius: 2px;
}

/* Validation message styling */
.validation-message {
    color: #dc3545;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

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

/* Form accessibility improvements */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    display: block;
}

.form-control:invalid {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.form-control:valid {
    border-color: #28a745;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

    .reduce-motion *,
    .reduce-motion *::before,
    .reduce-motion *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .skip-link {
        transition: none;
    }
}

/* Dark mode accessibility */
@media (prefers-color-scheme: dark) {
    .skip-link {
        background: #0d6efd;
        color: white;
    }

    .breadcrumbs {
        background-color: #343a40;
        border-color: #495057;
        color: #dee2e6;
    }

    .breadcrumb-item+.breadcrumb-item::before {
        color: #adb5bd;
    }

    .breadcrumb-item[aria-current="page"] {
        color: #adb5bd;
    }

    .audio-section {
        background-color: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .audio-section h2 {
        color: #e2e8f0;
    }

    .audio-section p {
        color: #a0aec0;
    }
}

/* Print accessibility */
@media print {

    .skip-links,
    .audio-section,
    .navbar,
    .btn,
    button {
        display: none !important;
    }

    .breadcrumbs {
        border: none;
        background: none;
        padding: 0;
    }

    .breadcrumb-item a {
        color: inherit;
        text-decoration: none;
    }

    .breadcrumb-item+.breadcrumb-item::before {
        color: inherit;
    }

    /* Ensure sufficient contrast for printing */
    * {
        color: black !important;
        background: white !important;
    }

    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* Mobile accessibility improvements */
@media (max-width: 767.98px) {
    .skip-link {
        left: 4px;
        top: -36px;
        font-size: 0.875rem;
        padding: 6px 12px;
    }

    .skip-link:focus {
        top: 4px;
    }

    .breadcrumbs {
        margin: 0.5rem 0;
        padding: 0.5rem;
        font-size: 0.875rem;
    }

    .breadcrumb-item+.breadcrumb-item::before {
        margin: 0 0.25rem;
    }

    .audio-section {
        margin: 1rem 0;
        padding: 1rem;
    }

    /* Ensure touch targets are large enough */
    .btn,
    .nav-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* Large text support */
@media (min-resolution: 192dpi) and (prefers-contrast: high) {
    body {
        font-size: 1.125rem;
        line-height: 1.6;
    }

    .btn {
        font-size: 1rem;
        padding: 0.75rem 1.25rem;
    }

    .form-control {
        font-size: 1rem;
        padding: 0.75rem 1rem;
    }
}

/* Error state improvements */
[aria-invalid="true"] {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

/* Loading state accessibility */
[aria-busy="true"] {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

[aria-busy="true"]::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top-color: #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Ensure sufficient color contrast */
.text-muted {
    color: #6c757d !important;
}

/* Better link styling for accessibility */
a {
    text-decoration: underline;
}

a:hover {
    text-decoration: none;
}

/* Table accessibility */
table {
    border-collapse: collapse;
    width: 100%;
}

th {
    background-color: #f8f9fa;
    font-weight: bold;
    text-align: left;
    border: 1px solid #dee2e6;
    padding: 0.75rem;
}

td {
    border: 1px solid #dee2e6;
    padding: 0.75rem;
}

/* Code block accessibility */
pre {
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    background-color: #f8f9fa;
    padding: 1rem;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.5;
}

code {
    background-color: #f1f3f4;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}
