/* Accessibility and WCAG Compliance Enhancements */

/* Focus Management */
*:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: 2px !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .form-control,
    .form-select,
    .btn,
    .card,
    .flashcard-item {
        border-width: 2px;
        border-style: solid;
    }

    .badge {
        border: 1px solid #000;
    }

    .text-muted {
        color: #000 !important;
        opacity: 0.8;
    }

    .bg-light {
        background-color: #fff !important;
        border: 1px solid #000;
    }

    .alert {
        border-width: 2px;
    }
}

/* Screen reader only content */
.sr-only,
.visually-hidden {
    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;
}

/* Skip to main content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #0d6efd;
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 10000;
    transition: top 0.2s ease;
}

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

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

/* Required field indicators */
.required::after {
    content: " *";
    color: #dc3545;
    font-weight: bold;
}

/* Error message styling */
.error-message {
    color: #dc3545;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
}

/* Success message styling */
.success-message {
    color: #198754;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
}

/* Field description */
.field-description {
    font-size: 0.75rem;
    color: #6c757d;
    margin-bottom: 0.5rem;
    display: block;
}

/* Enhanced button accessibility */
.btn[aria-pressed="true"] {
    background-color: #0b5ed7;
    border-color: #0a58ca;
}

.btn[aria-expanded="true"]::after {
    content: " (expanded)";
    position: absolute;
    left: -10000px;
}

.btn[aria-expanded="false"]::after {
    content: " (collapsed)";
    position: absolute;
    left: -10000px;
}

/* Keyboard navigation indicators */
.keyboard-nav *:focus {
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.3);
}

/* ARIA live regions */
[aria-live="polite"],
[aria-live="assertive"],
[aria-live="rude"] {
    position: relative;
}

/* Status indicators */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-indicator.loading::before {
    background-color: #ffc107;
    animation: pulse 1.5s ease-in-out infinite alternate;
}

.status-indicator.success::before {
    background-color: #198754;
}

.status-indicator.error::before {
    background-color: #dc3545;
}

.status-indicator.info::before {
    background-color: #0dcaf0;
}

@keyframes pulse {
    from { opacity: 1; }
    to { opacity: 0.4; }
}

/* Enhanced table accessibility */
.table {
    border-collapse: collapse;
}

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

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

.table caption {
    caption-side: bottom;
    text-align: left;
    font-size: 0.875rem;
    color: #6c757d;
    margin-top: 0.5rem;
    font-style: italic;
}

/* Modal accessibility */
.modal[aria-hidden="false"] {
    display: block !important;
}

.modal[aria-hidden="true"] {
    display: none !important;
}

.modal-dialog {
    position: relative;
}

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

/* Enhanced link accessibility */
a:focus {
    text-decoration: underline;
}

a[target="_blank"]::after {
    content: " (opens in new window)";
    position: absolute;
    left: -10000px;
}

/* External link indicators */
.external-link {
    position: relative;
    padding-right: 1.25rem;
}

.external-link::after {
    content: "↗";
    position: absolute;
    right: 0;
    top: 0;
    font-size: 0.75em;
    color: #6c757d;
}

/* Form validation accessibility */
.form-control.is-valid {
    border-color: #198754;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' 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);
    padding-right: calc(1.5em + 0.75rem);
}

.form-control.is-invalid {
    border-color: #dc3545;
    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);
    padding-right: calc(1.5em + 0.75rem);
}

/* Checkbox and radio button accessibility */
.form-check-input {
    margin-top: 0.25em;
    vertical-align: top;
    background-color: #fff;
    border: 1px solid rgba(0, 0, 0, 0.25);
    appearance: none;
    width: 1em;
    height: 1em;
    cursor: pointer;
}

.form-check-input:focus {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.form-check-input:checked {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.form-check-input:checked[type="checkbox"] {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3l6-6'/%3e%3c/svg%3e");
}

.form-check-input:checked[type="radio"] {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='2' fill='%23fff'/%3e%3c/svg%3e");
}

/* Progress bar accessibility */
.progress {
    height: 1rem;
    background-color: #e9ecef;
    border-radius: 0.5rem;
    overflow: hidden;
}

.progress-bar {
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    background-color: #0d6efd;
    transition: width 0.6s ease;
}

/* Breadcrumb accessibility */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    padding: 0 0;
    margin-bottom: 1rem;
    list-style: none;
}

.breadcrumb-item + .breadcrumb-item {
    padding-left: 0.5rem;
}

.breadcrumb-item + .breadcrumb-item::before {
    content: var(--bs-breadcrumb-divider, "/");
    float: left;
    padding-right: 0.5rem;
    color: #6c757d;
}

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

/* Alert accessibility */
.alert {
    position: relative;
    padding: 0.75rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: 0.5rem;
}

.alert-heading {
    color: inherit;
}

.alert-link {
    font-weight: 700;
}

.alert-dismissible {
    padding-right: 3rem;
}

.alert-dismissible .btn-close {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 2;
    padding: 0.75rem 1.25rem;
}

/* Tooltip accessibility */
[data-bs-toggle="tooltip"] {
    cursor: help;
}

/* Enhanced color contrast for text */
.text-muted {
    color: #495057 !important; /* Increased contrast from #6c757d */
}

.text-secondary {
    color: #495057 !important;
}

.small,
.small * {
    font-size: 0.875em;
}

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

.loading[aria-busy="true"]::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    z-index: 1;
}

.loading[aria-busy="true"]::after {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    font-weight: 600;
    color: #0d6efd;
}

/* Print accessibility */
@media print {
    .no-print {
        display: none !important;
    }

    .btn {
        border: 1px solid #000;
        background: #fff !important;
        color: #000 !important;
    }

    .card {
        border: 1px solid #000;
        page-break-inside: avoid;
    }

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

    .sr-only-print {
        position: static;
        width: auto;
        height: auto;
        padding: inherit;
        margin: inherit;
        overflow: visible;
        clip: auto;
        white-space: normal;
    }
}

/* Reduced motion support */
@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;
    }

    .carousel-item {
        transition: none;
    }

    .modal {
        animation: none;
    }
}

/* Forced color mode support */
@media (forced-colors: active) {
    .btn {
        border: 1px solid ButtonText;
    }

    .form-control {
        border: 1px solid ButtonText;
        background-color: Field;
        color: FieldText;
    }

    .card {
        border: 1px solid CanvasText;
    }
}

/* Mobile screen reader optimizations */
@media (max-width: 768px) {
    .skip-link {
        left: 50%;
        transform: translateX(-50%);
        border-radius: 0 0 8px 8px;
    }

    .form-label {
        font-size: 1rem; /* Larger on mobile */
    }

    .btn {
        min-height: 44px; /* Touch target size */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .form-control,
    .form-select {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
    }
}