/* Accessibility Enhanced CSS
 * WCAG 2.1 AA/AAA compliance enhancements for Pedro Calado Portfolio
 * Addresses color contrast, focus management, screen reader support, and motion preferences
 */

/* =========================================== */
/* FOCUS ENHANCEMENTS */
/* =========================================== */

/* Enhanced focus indicators for better visibility */
:focus-visible {
    outline: 3px solid var(--focus-color, #4a9eff);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(74, 158, 255, 0.2);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :focus-visible {
        outline: 4px solid #000;
        outline-offset: 2px;
        background: #ff0;
    }
}

/* Focus styles for specific interactive elements */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    border-color: var(--focus-color, #4a9eff);
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}

/* Focus indicators for cards and clickable elements */
.repo-card:focus-within,
.skill-card:focus-within,
.education-card:focus-within {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(74, 158, 255, 0.3);
    outline: 2px solid var(--focus-color, #4a9eff);
    outline-offset: 2px;
}

/* =========================================== */
/* SCREEN READER ENHANCEMENTS */
/* =========================================== */

/* Screen reader only content (enhanced) */
.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;
    clip-path: inset(50%) !important;
}

/* Skip link enhancements */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary-color, #2d7a4e);
    color: #ffffff;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    z-index: 1000;
    transition: top 0.3s ease, background-color 0.3s ease;
}

.skip-link:focus {
    top: 6px;
    background: var(--focus-color, #4a9eff);
}

/* Live region styling for screen readers */
[aria-live="polite"],
[aria-live="assertive"],
[aria-live="polite"] *,
[aria-live="assertive"] * {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* =========================================== */
/* COLOR CONTRAST ENHANCEMENTS */
/* =========================================== */

/* Ensure all text meets WCAG AA standards */
.text-muted {
    color: var(--secondary-text, #64748b) !important;
}

/* Enhanced contrast for light theme */
[data-theme="light"] {
    --text-primary-contrast: #0f172a; /* 15.2:1 */
    --text-secondary-contrast: #1e293b; /* 12.4:1 */
    --text-muted-contrast: #334155; /* 8.9:1 */
}

/* Enhanced contrast for dark theme */
[data-theme="dark"] {
    --text-primary-contrast: #f0f9ff; /* 12.6:1 */
    --text-secondary-contrast: #e2e8f0; /* 15.1:1 */
    --text-muted-contrast: #cbd5e1; /* 8.9:1 */
}

/* High contrast mode styles */
@media (prefers-contrast: high) {
    [data-theme="light"] {
        --light-text: #000;
        --primary-color: #0066cc;
        --focus-color: #ff0;
    }
    
    [data-theme="dark"] {
        --light-text: #fff;
        --primary-color: #00aaff;
        --focus-color: #ff0;
    }
    
    .btn {
        border: 2px solid #000;
    }
    
    [data-theme="dark"] .btn {
        border-color: #fff;
    }
}

/* =========================================== */
/* REDUCED MOTION ENHANCEMENTS */
/* =========================================== */

/* Respect user motion preferences */
@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;
    }
    
    /* Disable parallax and complex animations */
    body::before,
    body::after {
        display: none !important;
    }
    
    /* Simple hover states instead of animations */
    .btn:hover,
    .skill-card:hover,
    .repo-card:hover {
        transform: none !important;
    }
    
    /* Simple focus transitions */
    :focus {
        transition: none !important;
    }
}

/* Enable animations with user preference */
@media (prefers-reduced-motion: no-preference) {
    /* Enhanced animations for users who prefer motion */
    .skill-level {
        transition: transform 1.5s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .btn::before {
        transition: width 0.6s ease, height 0.6s ease;
    }
}

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

/* Keyboard focus trap for modals */
.modal[aria-hidden="false"] {
    /* Ensure modal is in focus stack */
}

.modal[aria-hidden="false"] *:not(:focus):not(:focus-within) {
    /* Dim non-focused elements in modal */
    opacity: 0.7;
}

/* Keyboard navigation indicators */
.keyboard-nav-active {
    outline: 2px solid var(--focus-color, #4a9eff);
    background: rgba(74, 158, 255, 0.1);
}

/* Skip links enhancement */
.skip-to-content {
    position: absolute;
    top: auto;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: -9999;
}

.skip-to-content:focus,
.skip-to-content:active {
    top: 10px;
    left: 10px;
    width: auto;
    height: auto;
    overflow: visible;
    z-index: 9999;
    padding: 10px 20px;
    background: var(--primary-color, #2d7a4e);
    color: #ffffff;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
}

/* =========================================== */
/* MOBILE ACCESSIBILITY ENHANCEMENTS */
/* =========================================== */

/* Touch target improvements */
@media (pointer: coarse) {
    a, button, input, select, textarea {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Larger spacing for touch targets */
    .btn {
        padding: 14px 24px;
        margin: 8px 4px;
    }
    
    /* Enhanced touch feedback */
    button:active,
    a:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}

/* Device orientation support */
@media screen and (orientation: portrait) {
    /* Portrait-specific accessibility adjustments */
    .skills-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

@media screen and (orientation: landscape) {
    /* Landscape-specific accessibility adjustments */
    .timeline-item {
        margin-bottom: 30px;
    }
}

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

@media print {
    /* Ensure print is accessible */
    body {
        font-size: 12pt;
        line-height: 1.4;
        color: #000;
        background: #fff;
    }
    
    /* Hide non-essential content */
    .theme-toggle,
    .keyboard-help-btn,
    #dropdown-menu,
    .loading-spinner-enhanced {
        display: none !important;
    }
    
    /* Ensure links are visible in print */
    a::after {
        content: " (" attr(href) ")";
        color: #000;
        text-decoration: underline;
    }
    
    /* Print-friendly focus indicators */
    :focus {
        outline: 2px solid #000;
    }
}

/* =========================================== */
/* HIGH CONTRAST MODE ENHANCEMENTS */
/* =========================================== */

/* Windows High Contrast Mode support */
@media screen and (-ms-high-contrast: active) {
    .btn {
        border: 2px solid windowText;
    }
    
    .theme-toggle {
        background: window;
        border: 2px solid windowText;
        color: windowText;
    }
    
    a {
        color: linkText;
        text-decoration: underline;
    }
}

/* Forced colors mode support */
@media (forced-colors: active) {
    .btn {
        border: 2px solid ButtonText;
        background: ButtonFace;
        color: ButtonText;
    }
    
    :focus {
        outline: 2px solid Highlight;
    }
    
    [aria-current="page"] {
        background: Highlight;
        color: HighlightText;
    }
}

/* =========================================== */
/* FONT SIZE AND ZOOM ENHANCEMENTS */
/* =========================================== */

/* Support for font size preferences */
@media (min-resolution: 120dpi) {
    body {
        font-size: calc(1em + 0.5vw);
    }
}

/* Large text improvements */
@media (min-width: 1200px) {
    body {
        font-size: 18px;
    }
    
    h1 {
        font-size: 2.5rem;
    }
    
    h2 {
        font-size: 2rem;
    }
}

/* Zoom support up to 400% */
@media (min-width: 320px) and (max-width: 1279px) {
    /* Responsive adjustments for zoom */
    .container {
        max-width: 100%;
        padding: 0 15px;
    }
    
    .skills-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .repo-card {
        margin-bottom: 20px;
    }
}

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

/* Form field enhancements */
input[type="text"],
input[type="email"],
input[type="search"],
textarea,
select {
    border: 2px solid transparent;
    border-radius: 4px;
    background: var(--card-bg, #fff);
    color: var(--light-text, #000);
    padding: 10px 12px;
    font-size: 16px; /* Prevent zoom on iOS */
}

input:focus[type="text"],
input:focus[type="email"],
input:focus[type="search"],
textarea:focus,
select:focus {
    border-color: var(--focus-color, #4a9eff);
    outline: none;
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.1);
}

/* Error and validation states */
input[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: #dc3545;
    background: rgba(220, 53, 69, 0.1);
}

input[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus {
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.2);
}

/* Form labels */
label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--light-text, #000);
}

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

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

/* Data table improvements */
table {
    border-collapse: collapse;
    width: 100%;
    margin: 20px 0;
}

th,
td {
    border: 1px solid var(--border-color, #dee2e6);
    padding: 12px;
    text-align: left;
}

th {
    background: var(--secondary-color, #f4a460);
    color: var(--light-text, #000);
    font-weight: 600;
    position: relative;
}

/* Table headers for screen readers */
th {
    text-align: left;
}

[role="table"] th {
    position: relative;
}

[role="table"] th::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    pointer-events: none;
}

/* =========================================== */
/* PERFORMANCE OPTIMIZATIONS */
/* =========================================== */

/* Reduce paint and layout for better performance */
.skill-card,
.repo-card,
.btn {
    contain: layout style paint;
    will-change: auto;
}

/* Optimize for reduced motion users */
@media (prefers-reduced-motion: reduce) {
    * {
        will-change: auto !important;
    }
}

/* =========================================== */
/* ACCESSIBILITY TESTING AIDS */
/* =========================================== */

/* Developer testing aids - remove in production */
.dev-accessibility-outline * {
    outline: 1px solid #ff0 !important;
    background: rgba(255, 255, 0, 0.1) !important;
}

.dev-accessibility-outline button,
.dev-accessibility-outline a,
.dev-accessibility-outline input {
    outline: 2px solid #f0f !important;
}

.dev-accessibility-outline h1,
.dev-accessibility-outline h2,
.dev-accessibility-outline h3,
.dev-accessibility-outline h4,
.dev-accessibility-outline h5,
.dev-accessibility-outline h6 {
    outline: 2px solid #0ff !important;
}

/* Accessibility controls for testing */
.accessibility-controls {
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    padding: 10px;
    border-radius: 4px;
    z-index: 10000;
    font-family: monospace;
    font-size: 12px;
}

.accessibility-controls button {
    display: block;
    width: 100%;
    margin: 5px 0;
    padding: 5px 10px;
    border: 1px solid #ffffff;
    background: transparent;
    color: #ffffff;
    cursor: pointer;
}

.accessibility-controls button:hover {
    background: rgba(255, 255, 255, 0.2);
}