/* ESG Navigator Accessibility Enhancements */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .bg-primary-50 { background-color: #ffffff !important; }
    .bg-primary-600 { background-color: #000000 !important; }
    .text-primary-600 { color: #000000 !important; }
    .border-primary-600 { border-color: #000000 !important; }
    
    .bg-gray-50 { background-color: #ffffff !important; }
    .bg-gray-100 { background-color: #f0f0f0 !important; }
    .text-gray-600 { color: #333333 !important; }
    .text-gray-500 { color: #666666 !important; }
}

/* 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;
    }
    
    .fade-in, .slide-over {
        animation: none !important;
    }
}

/* Focus management */
.focus-trap {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Enhanced focus indicators */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #3b82f6;
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    z-index: 1000;
    transition: top 0.3s;
}

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

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

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

/* Improved color contrast for dark mode */
.dark {
    --tw-text-opacity: 1;
    color: rgba(243, 244, 246, var(--tw-text-opacity));
}

.dark .text-gray-400 {
    --tw-text-opacity: 1;
    color: rgba(156, 163, 175, var(--tw-text-opacity));
}

.dark .text-gray-500 {
    --tw-text-opacity: 1;
    color: rgba(107, 114, 128, var(--tw-text-opacity));
}

/* Keyboard navigation improvements */
.nav-link:focus-visible {
    background-color: rgba(59, 130, 246, 0.1);
    border-radius: 4px;
}

.regime-card:focus-within {
    ring: 2px;
    ring-color: #3b82f6;
    ring-offset: 2px;
}

/* Mobile accessibility improvements */
@media (max-width: 768px) {
    /* Larger tap targets */
    button, .btn, [role="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Better spacing for touch */
    .regime-card {
        margin-bottom: 1rem;
        padding: 1.5rem;
    }
    
    /* Improved form controls */
    input, select, textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Mobile navigation */
    .mobile-menu-toggle {
        display: block;
        z-index: 50;
    }
    
    /* Hide desktop navigation on mobile */
    .desktop-nav {
        display: none;
    }
}

/* High DPI display support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .icon-small {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Print styles */
@media print {
    .no-print {
        display: none !important;
    }
    
    .print-break-after {
        page-break-after: always;
    }
    
    .print-break-inside-avoid {
        page-break-inside: avoid;
    }
    
    /* Ensure good contrast in print */
    * {
        color: black !important;
        background: white !important;
    }
    
    .regime-card {
        border: 1px solid #000 !important;
        margin-bottom: 1rem;
    }
}

/* Error and validation styling */
.error-message {
    color: #dc2626;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.field-error input,
.field-error select,
.field-error textarea {
    border-color: #dc2626;
    box-shadow: 0 0 0 1px #dc2626;
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

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

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

/* Tooltips for accessibility */
.tooltip {
    position: relative;
}

.tooltip::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: white;
    padding: 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
}

.tooltip:hover::before,
.tooltip:focus::before {
    opacity: 1;
}

/* Improved checkbox and radio styling */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Status indicators with icons for better accessibility */
.status-mandatory::before { content: '⚠️ '; }
.status-voluntary::before { content: '💡 '; }
.status-proposed::before { content: '📋 '; }
.status-evolving::before { content: '🔄 '; }

/* Improved table accessibility */
table {
    border-collapse: collapse;
}

th {
    background-color: #f9fafb;
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
    border-bottom: 2px solid #e5e7eb;
}

td {
    padding: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
}

.dark th {
    background-color: #374151;
    border-bottom-color: #4b5563;
}

.dark td {
    border-bottom-color: #4b5563;
}

/* Responsive text sizing */
@media (max-width: 640px) {
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.125rem; }
}

/* Announcement banner for screen readers */
.announcement {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.announcement:focus {
    position: static;
    left: auto;
    width: auto;
    height: auto;
    overflow: visible;
    background: #3b82f6;
    color: white;
    padding: 1rem;
    text-align: center;
    font-weight: 600;
}

/* Button group accessibility */
.btn-group [role="button"]:first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.btn-group [role="button"]:last-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.btn-group [role="button"]:not(:first-child):not(:last-child) {
    border-radius: 0;
}