/**
 * Color Contrast Fixes
 * Ensures all text/background combinations meet WCAG AA standards
 * Minimum contrast ratios: 4.5:1 for normal text, 3:1 for large text
 */

/* 1. Fix Light Gray Text on White - Replace #6c757d with darker #495057 */
.text-muted,
.text-secondary,
.feed-timestamp,
.feed-stat-item,
.item-subtitle,
.widget-desc,
.match-location,
.media-text,
.meta-text,
.help-text,
small.text-muted {
    color: #495057 !important; /* Darker gray for 7:1 contrast on white */
}

/* 2. Fix Placeholder Text - Darker and more visible */
::placeholder,
::-webkit-input-placeholder,
::-moz-placeholder,
:-ms-input-placeholder,
.form-control::placeholder,
input::placeholder,
textarea::placeholder,
select::placeholder {
    color: #495057 !important;
    opacity: 1 !important; /* Full opacity for better visibility */
}

/* 3. Fix Low Opacity Elements */
.opacity-50 { opacity: 0.8 !important; }
.opacity-60 { opacity: 0.85 !important; }
.opacity-75 { opacity: 0.9 !important; }

/* Links with better contrast */
a:not(.btn) {
    color: #0056b3 !important; /* Darker blue for better contrast */
}

a:not(.btn):hover {
    color: #003d82 !important; /* Even darker on hover */
}

/* 4. Fix Light Backgrounds with Light Text */
/* Elements with #f8f9fa background */
.bg-light,
[style*="background: #f8f9fa"],
[style*="background-color: #f8f9fa"] {
    color: #212529 !important; /* Force dark text */
}

.bg-light .text-muted,
.bg-light .text-secondary {
    color: #495057 !important; /* Ensure readable gray */
}

/* Elements with #e9ecef background */
.bg-secondary-light,
[style*="background: #e9ecef"],
[style*="background-color: #e9ecef"] {
    color: #212529 !important;
}

/* 5. Fix Form Elements */
.form-control,
.form-select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
textarea,
select {
    border-color: #adb5bd !important; /* Darker border for visibility */
    color: #212529 !important; /* Ensure dark text */
}

/* Disabled form elements with better contrast */
.form-control:disabled,
.form-select:disabled,
input:disabled,
select:disabled,
textarea:disabled,
[readonly] {
    background-color: #e9ecef !important;
    color: #495057 !important; /* Darker text on disabled */
    opacity: 1 !important; /* Full opacity */
    border-color: #adb5bd !important;
}

/* Focus states with strong contrast */
.form-control:focus,
.form-select:focus,
input:focus,
select:focus,
textarea:focus {
    border-color: #0056b3 !important;
    box-shadow: 0 0 0 0.2rem rgba(0, 86, 179, 0.25) !important;
}

/* 6. Fix Button Contrast */
.btn-secondary {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
    color: #fff !important; /* White text on gray */
}

.btn-secondary:hover {
    background-color: #5a6268 !important;
    border-color: #545b62 !important;
    color: #fff !important;
}

.btn-outline-secondary {
    color: #495057 !important; /* Darker gray */
    border-color: #6c757d !important;
}

.btn-outline-secondary:hover {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
    color: #fff !important;
}

/* 7. Fix Table Contrast */
.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, 0.04) !important; /* Darker stripes */
}

.table td,
.table th {
    color: #212529 !important; /* Ensure dark text */
}

.table-light,
.table-light > th,
.table-light > td {
    background-color: #f8f9fa !important;
    color: #212529 !important;
}

/* 8. Fix Alert Contrast */
.alert {
    border-width: 1px !important; /* Ensure visible borders */
}

.alert-warning {
    background-color: #fff3cd !important;
    border-color: #ffecb5 !important;
    color: #664d03 !important; /* Dark enough for contrast */
}

.alert-info {
    background-color: #cff4fc !important;
    border-color: #b6effb !important;
    color: #055160 !important; /* Dark blue for contrast */
}

.alert-light {
    background-color: #f8f9fa !important;
    border-color: #d6d8db !important;
    color: #383d41 !important; /* Darker text */
}

/* 9. Fix Badge Contrast */
.badge-light,
.badge-secondary {
    background-color: #495057 !important; /* Darker background */
    color: #fff !important; /* White text */
}

.badge-warning {
    background-color: #ffc107 !important;
    color: #212529 !important; /* Dark text on yellow */
}

/* 10. Fix Card Elements */
.card {
    border-color: #adb5bd !important; /* Darker border */
}

.card-header {
    background-color: #f8f9fa !important;
    border-bottom-color: #adb5bd !important;
    color: #212529 !important;
}

.card-footer {
    background-color: #f8f9fa !important;
    border-top-color: #adb5bd !important;
    color: #212529 !important;
}

/* 11. Fix Navigation Elements */
.navbar-light .navbar-nav .nav-link {
    color: #495057 !important; /* Darker gray */
}

.navbar-light .navbar-nav .nav-link:hover,
.navbar-light .navbar-nav .nav-link:focus {
    color: #212529 !important; /* Black on hover */
}

.navbar-light .navbar-nav .nav-link.active {
    color: #212529 !important;
}

/* Dropdown items */
.dropdown-item {
    color: #212529 !important;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: #e9ecef !important;
    color: #212529 !important;
}

.dropdown-item.disabled,
.dropdown-item:disabled {
    color: #6c757d !important;
    opacity: 1 !important;
}

/* 12. Fix Breadcrumbs */
.breadcrumb {
    background-color: #f8f9fa !important;
}

.breadcrumb-item {
    color: #495057 !important;
}

.breadcrumb-item.active {
    color: #212529 !important;
}

.breadcrumb-item + .breadcrumb-item::before {
    color: #6c757d !important;
}

/* 13. Fix Pagination */
.page-link {
    color: #0056b3 !important; /* Darker blue */
    border-color: #adb5bd !important;
}

.page-link:hover {
    color: #003d82 !important;
    background-color: #e9ecef !important;
    border-color: #adb5bd !important;
}

.page-item.disabled .page-link {
    color: #6c757d !important;
    background-color: #f8f9fa !important;
    border-color: #dee2e6 !important;
    opacity: 1 !important;
}

/* 14. Fix List Groups */
.list-group-item {
    border-color: #adb5bd !important;
    color: #212529 !important;
}

.list-group-item.disabled {
    color: #495057 !important;
    background-color: #f8f9fa !important;
    opacity: 1 !important;
}

/* 15. Fix Progress Bars */
.progress {
    background-color: #e9ecef !important;
    border: 1px solid #adb5bd !important;
}

/* 16. Fix Modal Elements */
.modal-header {
    border-bottom-color: #adb5bd !important;
}

.modal-footer {
    border-top-color: #adb5bd !important;
}

/* 17. Fix Close Buttons */
.btn-close {
    opacity: 0.8 !important;
}

.btn-close:hover {
    opacity: 1 !important;
}

/* 18. Fix Code Elements */
code {
    color: #d63384 !important; /* Darker pink for contrast */
    background-color: #f8f9fa !important;
    padding: 0.2em 0.4em !important;
    border-radius: 0.25rem !important;
}

pre {
    color: #212529 !important;
    background-color: #f8f9fa !important;
    border: 1px solid #adb5bd !important;
}

/* 19. Fix HR Elements */
hr {
    color: #adb5bd !important;
    opacity: 1 !important;
}

/* 20. Special Cases for Known Issues */
/* Dashboard sidebar */
.dashboard-sidebar .nav-link {
    color: rgba(255, 255, 255, 0.95) !important; /* Higher opacity */
}

.dashboard-sidebar .nav-link:hover {
    color: #fff !important;
    background-color: rgba(255, 255, 255, 0.1) !important;
}

/* Feed elements */
.feed-item .text-muted {
    color: #495057 !important;
}

/* Match cards */
.match-card .text-secondary {
    color: #495057 !important;
}

/* Widget text */
.widget-box .text-muted {
    color: #495057 !important;
}

/* 21. High Contrast Mode Support */
@media (prefers-contrast: high) {
    * {
        border-width: 2px !important;
    }
    
    .text-muted,
    .text-secondary {
        color: #212529 !important;
    }
    
    .form-control,
    .btn {
        border: 2px solid currentColor !important;
    }
}

/* 22. Print Styles */
@media print {
    * {
        color: #000 !important;
        background: #fff !important;
    }
    
    .text-muted {
        color: #000 !important;
    }
}