/* ============================================
   WCAG 2.2 Level A Accessibility Styles
   ============================================ */

/* Skip Link - WCAG 2.4.1 Bypass Blocks */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 12px 24px;
    text-decoration: none;
    font-weight: 600;
    z-index: 10000;
    border-radius: 0 0 8px 0;
    transition: top 0.2s ease;
    box-shadow: var(--shadow-lg);
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

/* Enhanced Focus Indicators - WCAG 2.4.7 (Level AA, but best practice) */
*:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast focus for buttons */
button:focus,
.btn:focus,
a:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Focus indicator for clickable statistics cards */
.stat-card.clickable:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(30, 107, 214, 0.2), var(--shadow-lg);
}

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

*:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Screen Reader Only Text - For hidden labels */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Allow screen reader text to be focusable */
.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Status Icons - WCAG 1.4.1 Use of Color */
.status-icon {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    flex-shrink: 0;
}

.status-icon.active {
    background-color: var(--success-color);
}

.status-icon.inactive {
    background-color: var(--warning-color);
}

.status-icon.error {
    background-color: var(--danger-color);
}

/* Ensure status badges have sufficient contrast and indicators */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Form Error States - WCAG 3.3.1 Error Identification */
.form-input[aria-invalid="true"] {
    border-color: var(--danger-color);
    border-width: 2px;
}

.form-error {
    color: var(--danger-color);
    font-size: 13px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.form-error::before {
    content: "⚠";
    font-weight: bold;
}

.form-group .required {
    color: var(--danger-color);
    font-weight: 700;
}

/* Sortable Table Headers - WCAG 4.1.2 Name, Role, Value */
.sort-button {
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    padding: 0;
    cursor: pointer;
    font: inherit;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sort-button:hover {
    color: var(--primary-color);
}

.sort-indicator {
    font-size: 12px;
    color: var(--text-secondary);
}

th[aria-sort="ascending"] .sort-indicator::after {
    content: "▲";
}

th[aria-sort="descending"] .sort-indicator::after {
    content: "▼";
}

th[aria-sort="none"] .sort-indicator::after {
    content: "⇅";
    opacity: 0.3;
}

/* Modal Accessibility - WCAG 4.1.2 */
/* Only hide modals with aria-hidden="true" if they don't have .show class */
.modal[aria-hidden="true"]:not(.show) {
    display: none !important;
}

.modal[aria-hidden="false"],
.modal.show {
    display: flex !important;
}

/* Ensure modal backdrop dims content behind */
.modal {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

/* Focus trap indicator */
.modal-content:focus {
    outline: none;
}

/* Clickable Cards as Buttons */
button.stat-card {
    width: 100%;
    text-align: left;
    font: inherit;
    background: var(--card-bg);
    border: 2px solid transparent;
}

button.stat-card:hover {
    border-color: var(--primary-color);
}

button.stat-card[aria-pressed="true"] {
    border-color: var(--primary-color);
    background-color: rgba(30, 107, 214, 0.05);
    box-shadow: 0 0 0 3px rgba(30, 107, 214, 0.1), var(--shadow-lg);
}

/* Icon Buttons - Ensure minimum touch target size */
.btn-icon {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .stat-card,
    .card {
        border: 2px solid currentColor;
    }

    button,
    .btn {
        border: 2px solid currentColor;
    }
}

/* Reduced Motion Support - WCAG 2.3.3 (Level AAA, but good practice) */
@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;
    }

    .skip-link {
        transition: none;
    }
}

/* Ensure adequate spacing for touch targets - WCAG 2.5.5 (Level AAA) */
@media (pointer: coarse) {
    button,
    a,
    .btn,
    .btn-icon {
        min-height: 44px;
        min-width: 44px;
    }

    .stat-card.clickable {
        min-height: 88px;
    }
}

/* Loading States with Screen Reader Announcements */
[aria-busy="true"] {
    position: relative;
}

[aria-busy="true"]::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 3px solid rgba(30, 107, 214, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s linear infinite;
}

/* Live Region for Dynamic Updates */
.sr-live-region {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Error Message Styling */
[role="alert"] {
    padding: 12px 16px;
    border-radius: 8px;
    margin-top: 8px;
    font-size: 14px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

[role="alert"].error {
    background-color: #fee2e2;
    color: #991b1b;
    border-left: 4px solid var(--danger-color);
}

[role="alert"].success {
    background-color: #d1fae5;
    color: #065f46;
    border-left: 4px solid var(--success-color);
}

[role="alert"].warning {
    background-color: #fef3c7;
    color: #92400e;
    border-left: 4px solid var(--warning-color);
}

/* Ensure main content can receive focus for skip link */
main:focus {
    outline: none;
}

/* Badge improvements for accessibility */
.badge,
.status-badge,
.license-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Table row hover improvements */
.agents-table tbody tr:hover {
    background-color: #f8fafc;
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

/* Form input focus improvements */
.form-input:focus,
.filter-select:focus,
.filter-input:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 0;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(30, 107, 214, 0.1);
}

/* Ensure disabled elements are clearly indicated */
button:disabled,
.btn:disabled,
input:disabled,
select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    position: relative;
}

/* Add visual indicator for required fields */
.form-group label .required::after {
    content: " (required)";
    font-size: 12px;
    font-weight: normal;
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .form-group label .required::after {
        content: " *";
    }
}
