/* ============================================================================
   ACCESSIBILITY & CONTRAST IMPROVEMENTS FOR h14z.io
   ============================================================================ */

/* 1. ENHANCED FOCUS STATES FOR KEYBOARD NAVIGATION */
:focus-visible {
    outline: 3px solid var(--color-brand-primary);
    outline-offset: 2px;
    border-radius: var(--radius-base);
    box-shadow: 0 0 0 6px var(--alpha-brand-20);
}

/* Remove default focus outline when focus-visible is supported */
:focus:not(:focus-visible) {
    outline: none;
}

/* Enhanced focus for interactive elements */
.btn:focus-visible,
.nav-links a:focus-visible,
.theme-toggle:focus-visible,
.language-toggle:focus-visible {
    outline: 3px solid var(--color-brand-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px var(--alpha-brand-30);
    transform: translateY(-1px);
}

/* 2. SKIP LINKS FOR KEYBOARD NAVIGATION */
.skip-link {
    position: absolute;
    top: -60px;
    left: 6px;
    background: var(--color-brand-primary);
    color: var(--color-neutral-0);
    padding: var(--space-3) var(--space-6);
    text-decoration: none;
    border-radius: var(--radius-base);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-base);
    min-height: 44px;
    min-width: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-skipLink);
    transition: top var(--duration-fast) var(--ease-smooth);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

.skip-link:hover,
.skip-link:focus {
    background: var(--color-brand-dark);
    transform: translateY(-1px);
}

/* 3. IMPROVED BUTTON CONTRAST */
.btn-primary {
    /* Enhanced contrast ratio for better accessibility */
    background: var(--color-brand-dark); /* Using darker variant for better contrast */
    border-color: var(--color-brand-dark);
}

.btn-primary:hover {
    background: var(--color-brand-primary);
    border-color: var(--color-brand-primary);
}

/* 4. ENHANCED MOBILE TOUCH TARGETS */
@media (max-width: 768px) {
    .nav-links a,
    .btn,
    .theme-toggle,
    .language-toggle,
    .mobile-menu-toggle {
        min-height: 44px; /* WCAG minimum touch target size */
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .nav-links a {
        padding: var(--space-3) var(--space-4);
        margin: var(--space-1) 0;
    }
}

/* 5. HIGH CONTRAST MODE SUPPORT */
@media (prefers-contrast: high) {
    :root {
        --text-secondary: var(--color-neutral-800);
        --border-primary: var(--color-neutral-400);
        --alpha-brand-20: rgba(190, 52, 85, 0.4);
        --alpha-brand-30: rgba(190, 52, 85, 0.5);
    }
    
    html[data-theme="light"] {
        --text-secondary: var(--color-neutral-800);
        --text-muted: var(--color-neutral-700);
        --border-primary: var(--color-neutral-400);
    }
    
    .btn-secondary {
        border-width: 2px;
    }
    
    .card-base {
        border-width: 2px;
    }
}

/* 6. 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;
    }
    
    .neural-canvas {
        display: none; /* Hide animated background for users who prefer reduced motion */
    }
    
    .hero-badge::before {
        animation: none;
        opacity: 1;
    }
}

/* 7. IMPROVED ERROR AND SUCCESS STATES */
.form-error {
    color: var(--color-error-600);
    font-size: var(--font-size-sm);
    margin-top: var(--space-1);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

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

.form-success {
    color: var(--color-success-600);
    font-size: var(--font-size-sm);
    margin-top: var(--space-1);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.form-success::before {
    content: '✓';
    font-weight: bold;
}

/* 8. ENHANCED LOADING STATES */
.loading-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--alpha-brand-20);
    border-radius: 50%;
    border-top-color: var(--color-brand-primary);
    animation: spin 1s ease-in-out infinite;
}

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

/* Screen reader only content */
.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;
}

/* 9. IMPROVED LINK INDICATORS */
a:not(.btn):not(.logo) {
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: text-decoration-color var(--duration-fast) var(--ease-smooth);
}

a:not(.btn):not(.logo):hover {
    text-decoration-color: var(--color-brand-primary);
}

/* 10. ENHANCED FORM ACCESSIBILITY */
.form-input {
    border: 1px solid var(--border-primary);
    transition: border-color var(--duration-fast) var(--ease-smooth),
                box-shadow var(--duration-fast) var(--ease-smooth);
}

.form-input:focus {
    border-color: var(--color-brand-primary);
    box-shadow: 0 0 0 2px var(--alpha-brand-20);
    outline: none;
}

/* Subtle validation states - no aggressive red borders */
.form-input:invalid:not(:focus):not(:placeholder-shown) {
    border-color: var(--border-secondary);
    box-shadow: 0 0 0 1px var(--alpha-brand-15);
}

.form-input:valid:not(:focus):not(:placeholder-shown) {
    border-color: var(--border-primary);
    box-shadow: 0 0 0 1px var(--alpha-brand-10);
}

/* Theme-specific form adjustments */
html[data-theme="light"] .form-input:invalid:not(:focus):not(:placeholder-shown) {
    border-color: var(--color-neutral-300);
    box-shadow: 0 0 0 1px rgba(190, 52, 85, 0.1);
}

html[data-theme="dark"] .form-input:invalid:not(:focus):not(:placeholder-shown) {
    border-color: var(--color-neutral-700);
    box-shadow: 0 0 0 1px rgba(190, 52, 85, 0.15);
}

/* Enhanced form styling for better visual hierarchy */
.form-input,
select[name="role"] {
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    min-height: 44px; /* WCAG minimum touch target size */
    min-width: 120px;
    border: 1px solid var(--border-primary);
}

/* Specific styling for select elements */
select[name="role"] {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

select[name="role"]:focus {
    border-color: var(--color-brand-primary);
    box-shadow: 0 0 0 2px var(--alpha-brand-20);
    outline: none;
}

.form-input::placeholder {
    color: var(--text-muted);
    opacity: 0.8;
}

/* Hover states for better interactivity */
.form-input:hover:not(:focus) {
    border-color: var(--alpha-brand-20);
}

/* Better visual feedback for different states */
.form-input:focus {
    background: var(--bg-primary);
    transform: translateY(-1px);
}

/* Subtle success indicator */
.form-input:valid:not(:placeholder-shown):not(:focus) {
    border-color: var(--border-primary);
    background: var(--bg-primary);
}

/* Form container improvements */
.contact-form,
.finops-form {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-2xl);
    padding: var(--space-8);
    box-shadow: var(--card-shadow);
}

/* Form labels */
.form-label {
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--space-2);
    display: block;
}

/* Required field indicator */
.form-label .required {
    color: var(--color-brand-primary);
    margin-left: var(--space-1);
}

/* Form button styling */
.form-submit {
    width: 100%;
    margin-top: var(--space-6);
    padding: var(--space-4) var(--space-6);
    font-weight: var(--font-weight-semibold);
}

/* 11. IMPROVED CONTRAST FOR LIGHT THEME BORDERS */
html[data-theme="light"] {
    --border-primary: var(--color-neutral-300); /* Improved from 200 to 300 */
    --border-secondary: var(--color-neutral-400); /* Improved from 300 to 400 */
}

/* 12. SPECIFIC CONTRAST FIXES FOR LIGHTHOUSE ISSUES */
/* Fix demo output title contrast */
.demo-output .output-title {
    color: #ffffff !important; /* Changed from #be3455 to white for better contrast on dark background */
}

/* Fix demo output text contrast */
.demo-output .output-text,
#demoOutput {
    color: #e5e5e5 !important; /* Changed from #6f6f6f to lighter gray for better contrast */
}

/* Fix footer links contrast */
.footer-tagline {
    color: #a3a3a3 !important; /* Changed from #737373 to lighter gray */
}

.legal-link {
    color: #a3a3a3 !important; /* Changed from #737373 to lighter gray */
}

/* Ensure these fixes work in both themes */
html[data-theme="light"] .demo-output .output-title {
    color: #be3455 !important; /* Keep brand color in light theme where contrast is better */
}

html[data-theme="light"] .demo-output .output-text,
html[data-theme="light"] #demoOutput {
    color: #404040 !important; /* Darker gray for light theme */
}

html[data-theme="light"] .footer-tagline,
html[data-theme="light"] .legal-link {
    color: #525252 !important; /* Darker gray for light theme */
}

/* 13. ADDITIONAL ACCESSIBILITY FIXES */
/* Ensure proper heading hierarchy styling */
.demo-title {
    font-size: 1.5rem;
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--space-3);
}

/* Improve focus indicators for all interactive elements */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid var(--color-brand-primary);
    outline-offset: 2px;
    border-radius: var(--radius-base);
}

/* Ensure sufficient color contrast for all text elements */
.hero-subtitle,
.section-subtitle,
.impact-description,
.method-description {
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Improve contrast for interactive elements */
.btn:focus,
.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--alpha-brand-20);
}

/* Better visual hierarchy for headings */
h1, h2, h3, h4, h5, h6 {
    line-height: 1.2;
    margin-bottom: var(--space-3);
}

/* Ensure proper spacing for better readability */
p, li {
    line-height: 1.6;
    margin-bottom: var(--space-3);
}

/* 15. CRITICAL CONTRAST FIXES FOR LIGHTHOUSE COMPLIANCE */
/* Override any existing styles that might interfere with contrast */
.demo-output .output-title,
.output-title {
    color: #ffffff !important;
    background: transparent !important;
    font-weight: var(--font-weight-semibold) !important;
}

.demo-output .output-text,
.output-text,
#demoOutput {
    color: #e5e5e5 !important;
    background: transparent !important;
}

/* Footer contrast improvements */
.footer-tagline,
.legal-link {
    color: #a3a3a3 !important;
    text-decoration-color: #a3a3a3 !important;
}

.legal-link:hover,
.legal-link:focus {
    color: #ffffff !important;
    text-decoration-color: #ffffff !important;
}

/* Light theme specific overrides */
html[data-theme="light"] .demo-output .output-title,
html[data-theme="light"] .output-title {
    color: #be3455 !important;
}

html[data-theme="light"] .demo-output .output-text,
html[data-theme="light"] .output-text,
html[data-theme="light"] #demoOutput {
    color: #404040 !important;
}

html[data-theme="light"] .footer-tagline,
html[data-theme="light"] .legal-link {
    color: #525252 !important;
}

html[data-theme="light"] .legal-link:hover,
html[data-theme="light"] .legal-link:focus {
    color: #be3455 !important;
}

/* 14. ENHANCED MOBILE NAVIGATION */
@media (max-width: 768px) {
    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--alpha-black-50);
        backdrop-filter: blur(4px);
        z-index: var(--z-overlay);
        opacity: 0;
        visibility: hidden;
        transition: all var(--duration-normal) var(--ease-smooth);
    }
    
    .mobile-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .nav-links {
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        height: 100vh;
        background: var(--bg-primary);
        border-left: 1px solid var(--border-primary);
        flex-direction: column;
        padding: var(--space-8) var(--space-6);
        gap: var(--space-4);
        transition: right var(--duration-normal) var(--ease-smooth);
        z-index: var(--z-modal);
    }
    
    .nav-links.active {
        right: 0;
    }
    
    .mobile-menu-toggle {
        display: flex;
    }
    
    .nav-links {
        display: none;
    }
    
    .nav-links.mobile-active {
        display: flex;
    }
}