/*
 * Accessibility Styles
 * WCAG 2.1 AA Compliant Styles for Ali Musa Portfolio Theme
 */

/* Skip Links */
.skip-links {
    position: absolute;
    top: -40px;
    left: 0;
    right: 0;
    z-index: 999999;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: -9999px;
    z-index: 999999;
    background: #000;
    color: #fff;
    padding: 8px 16px;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 4px 4px;
    transition: all 0.3s ease;
}

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

/* Screen Reader Text */
.screen-reader-text {
    clip: rect(1px, 1px, 1px, 1px);
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    word-wrap: normal !important;
    /* Many screen reader and browser combinations announce broken words as they would appear visually. */
}

.screen-reader-text:focus {
    background-color: #f1f1f1;
    border-radius: 3px;
    box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
    clip: auto !important;
    color: #21759b;
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    height: auto;
    left: 5px;
    line-height: normal;
    padding: 15px 23px 14px;
    text-decoration: none;
    top: 5px;
    width: auto;
    z-index: 100000;
}

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

/* Enhanced focus for interactive elements */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
}

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

.js-focus-visible *:focus.focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --text-color: #000;
        --background-color: #fff;
        --link-color: #0066cc;
        --border-color: #000;
    }
    
    body {
        background: var(--background-color);
        color: var(--text-color);
    }
    
    a {
        color: var(--link-color);
        text-decoration: underline;
    }
    
    a:hover,
    a:focus {
        background: #ffff99;
        color: #000;
        text-decoration: none;
    }
    
    .btn {
        background: #000;
        color: #fff;
        border: 2px solid #000;
    }
    
    .btn:hover,
    .btn:focus {
        background: #fff;
        color: #000;
        border: 2px solid #000;
    }
    
    /* Override gradient backgrounds */
    .hero,
    .section-bg {
        background: #fff !important;
        color: #000 !important;
    }
}

/* High Contrast Mode Toggle */
.high-contrast {
    --text-color: #000;
    --background-color: #fff;
    --link-color: #0066cc;
    --border-color: #000;
}

.high-contrast body {
    background: var(--background-color) !important;
    color: var(--text-color) !important;
}

.high-contrast a {
    color: var(--link-color) !important;
    text-decoration: underline !important;
}

.high-contrast .hero,
.high-contrast .section-bg {
    background: #fff !important;
    color: #000 !important;
}

.high-contrast .btn {
    background: #000 !important;
    color: #fff !important;
    border: 2px solid #000 !important;
}

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

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

/* Form Accessibility */
.field-error {
    color: #d63384;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
}

input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
    border-color: #d63384;
    box-shadow: 0 0 0 0.2rem rgba(214, 51, 132, 0.25);
}

/* Required field indicators */
.required::after {
    content: ' *';
    color: #d63384;
    font-weight: 600;
}

/* Form labels */
label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: block;
}

/* Fieldset and legend styling */
fieldset {
    border: 2px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

legend {
    font-weight: 700;
    font-size: 1.125rem;
    padding: 0 0.5rem;
}

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

th,
td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #dee2e6;
}

th {
    font-weight: 600;
    background-color: #f8f9fa;
}

caption {
    caption-side: top;
    text-align: left;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

/* List Accessibility */
ul,
ol {
    padding-left: 2rem;
}

ul[role="list"],
ol[role="list"] {
    list-style: none;
    padding-left: 0;
}

/* Navigation Accessibility */
nav[aria-label],
nav[aria-labelledby] {
    /* Ensure navigation landmarks are properly labeled */
}

.nav-toggle {
    background: transparent;
    border: 2px solid transparent;
    padding: 0.5rem;
    border-radius: 0.25rem;
    cursor: pointer;
}

.nav-toggle:focus {
    border-color: #667eea;
}

.nav-toggle[aria-expanded="true"] .nav-toggle-icon {
    transform: rotate(90deg);
}

/* Breadcrumb Accessibility */
.breadcrumbs nav {
    margin-bottom: 1rem;
}

.breadcrumb-item a:focus {
    text-decoration: underline;
}

/* Modal/Dialog Accessibility */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-content {
    background: #fff;
    border-radius: 0.5rem;
    padding: 2rem;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.25rem;
}

.modal-close:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Card/Item Accessibility */
.card,
.portfolio-item,
.service-item {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:focus,
.portfolio-item:focus,
.service-item:focus {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Color Contrast Enhancements */
.text-muted {
    color: #666 !important;
}

.text-light {
    color: #f8f9fa !important;
}

/* Ensure sufficient contrast for all text */
.hero .hero-description {
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Loading States */
.loading {
    position: relative;
    color: transparent;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #667eea;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Status Messages */
.status-message {
    padding: 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.status-message.success {
    background: #d1edff;
    color: #0c4a6e;
    border-color: #0ea5e9;
}

.status-message.error {
    background: #fee2e2;
    color: #7f1d1d;
    border-color: #ef4444;
}

.status-message.warning {
    background: #fef3c7;
    color: #78350f;
    border-color: #f59e0b;
}

/* Print Accessibility */
@media print {
    .skip-links,
    .nav-toggle,
    .modal {
        display: none !important;
    }
    
    a::after {
        content: ' (' attr(href) ')';
        font-size: 0.8em;
        color: #666;
    }
    
    a[href^="#"]::after {
        content: '';
    }
}

/* Touch Target Sizes (Minimum 44px for WCAG AA) */
@media (pointer: coarse) {
    a,
    button,
    input,
    select,
    textarea {
        min-height: 44px;
        min-width: 44px;
    }
    
    .btn {
        min-height: 44px;
        padding: 0.75rem 1.5rem;
    }
    
    .nav-toggle {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Windows High Contrast Mode */
@media screen and (-ms-high-contrast: active) {
    .btn {
        border: 2px solid;
    }
    
    .card,
    .portfolio-item,
    .service-item {
        border: 1px solid;
    }
}

/* Responsive Text Scaling */
@media (min-resolution: 144dpi) {
    .high-dpi {
        /* Adjustments for high DPI displays */
    }
}

/* Text Size Support (up to 200% zoom) */
@media screen and (min-width: 1280px) {
    /* Ensure layout doesn't break at 200% text size */
    .container {
        max-width: 90%;
    }
    
    .hero-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
        text-align: center;
    }
}

/* Error Prevention */
.confirm-action {
    background: #dc3545;
    color: white;
}

.confirm-action:hover,
.confirm-action:focus {
    background: #c82333;
}

.confirm-action::before {
    content: '⚠ ';
}

/* Landmark Navigation */
main[role="main"],
main {
    display: block;
}

/* Heading Structure */
h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-weight: 600;
    line-height: 1.2;
}

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 headings have proper spacing and color contrast */
.section-title {
    margin-bottom: 2rem;
    text-align: center;
}

/* ARIA Live Regions (Hidden) */
#aria-live-polite,
#aria-live-assertive {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}