/*
 * Accessibility and Compatibility Fixes
 * Addresses browser compatibility, accessibility, and performance issues
 */

/* ===== BROWSER COMPATIBILITY FIXES ===== */

/* Text size adjust - Chrome 54+, Edge 79+, Safari */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Backdrop filter - Safari 9+ support */
.backdrop-blur {
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

/* Text align match parent - Safari 15.4+ */
.text-match-parent {
    text-align: -webkit-match-parent;
    text-align: match-parent;
}

/* User select - Safari 3+ */
.user-select-none {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.user-select-auto {
    -webkit-user-select: auto;
    -moz-user-select: auto;
    -ms-user-select: auto;
    user-select: auto;
}

.user-select-text {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Print color adjust */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* Scrollbar width - Safari fallback */
.scrollbar-thin {
    scrollbar-width: thin;
}

.scrollbar-none {
    scrollbar-width: none;
}

/* Webkit scrollbar for Safari */
.scrollbar-thin::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.scrollbar-thin::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.scrollbar-thin::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.scrollbar-none::-webkit-scrollbar {
    display: none;
}

/* ===== ACCESSIBILITY FIXES ===== */

/* Skip link for screen readers */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #000;
    color: #fff;
    padding: 8px;
    text-decoration: none;
    z-index: 9999;
    border-radius: 4px;
    font-weight: bold;
}

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

/* Focus indicators */
.btn:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border-width: 2px;
    }
    
    .card {
        border-width: 2px;
    }
    
    .alert {
        border-width: 2px;
    }
}

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

/* Touch target sizes - minimum 44px */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Button accessibility improvements */
.btn-icon-only {
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
}

/* List accessibility fixes */
.list-unstyled-accessible {
    list-style: none;
    padding-left: 0;
    margin-bottom: 0;
}

.list-unstyled-accessible li {
    position: relative;
    padding-left: 0;
}

/* Form accessibility */
.form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #212529;
}

.form-control:invalid {
    border-color: #dc3545;
}

.form-control:invalid:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* Error message styling */
.invalid-feedback {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875em;
    color: #dc3545;
}

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

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

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

/* Use transform instead of layout-triggering properties */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Performance-optimized animations */
.animate-slide-in-right {
    animation: slideInRight 0.3s ease-out;
}

.animate-slide-in-left {
    animation: slideInLeft 0.3s ease-out;
}

.animate-slide-in-up {
    animation: slideInUp 0.3s ease-out;
}

.animate-slide-in-down {
    animation: slideInDown 0.3s ease-out;
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out;
}

.animate-scale-in {
    animation: scaleIn 0.3s ease-out;
}

/* GPU acceleration for smooth animations */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* ===== RESPONSIVE IMPROVEMENTS ===== */

/* Better responsive button groups */
.btn-group-responsive {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.btn-group-responsive .btn {
    border-radius: 0.375rem !important;
    margin-bottom: 0.25rem;
}

.btn-group-responsive .btn:last-child {
    margin-bottom: 0;
}

/* Responsive tables */
.table-responsive-stack {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
    .table-responsive-stack table,
    .table-responsive-stack thead,
    .table-responsive-stack tbody,
    .table-responsive-stack th,
    .table-responsive-stack td,
    .table-responsive-stack tr {
        display: block;
    }
    
    .table-responsive-stack thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    .table-responsive-stack tr {
        border: 1px solid #ccc;
        margin-bottom: 10px;
        padding: 10px;
        border-radius: 0.375rem;
    }
    
    .table-responsive-stack td {
        border: none;
        position: relative;
        padding-left: 50% !important;
        padding-top: 10px;
        padding-bottom: 10px;
    }
    
    .table-responsive-stack td:before {
        content: attr(data-label) ": ";
        position: absolute;
        left: 6px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: bold;
        color: #666;
    }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
    .auto-dark {
        background-color: #1a1a1a;
        color: #ffffff;
    }
    
    .auto-dark .card {
        background-color: #2d2d2d;
        border-color: #404040;
    }
    
    .auto-dark .form-control {
        background-color: #2d2d2d;
        border-color: #404040;
        color: #ffffff;
    }
    
    .auto-dark .btn-outline-primary {
        color: #66b3ff;
        border-color: #66b3ff;
    }
    
    .auto-dark .btn-outline-primary:hover {
        background-color: #66b3ff;
        color: #000000;
    }
}
