/* Ocular accessibility overrides (WCAG 2.2 AA).
 *
 * Loaded last from base.html so these rules win over page stylesheets at equal
 * specificity. Findings refer to docs/audits/2026-11-01-ui-design-quality-audit.md.
 */

/* ---- R-1: .btn-gradient / .btn-modern are used by the shared auth templates but
 *      not defined by any loaded stylesheet, so the primary CTA rendered as plain text. */
.btn-gradient {
    background: linear-gradient(135deg, #0b5ed7 0%, #0a58ca 100%);
    border: 0;
    color: #fff;
    box-shadow: 0 4px 15px rgba(13, 110, 253, 0.3);
}
.btn-gradient:hover,
.btn-gradient:focus-visible {
    color: #fff;
    filter: brightness(1.08);
}
.btn-modern {
    padding: 0.65rem 1.25rem;
    min-height: 2.75rem;
}

/* ---- X-4: colour tokens that fail 4.5:1 on white ---- */
.btn.btn-primary,
.btn-primary,
.nav-pills .nav-link.active {
    --bs-btn-bg: #0b5ed7;
    --bs-btn-hover-bg: #0a58ca;
    background-color: #0b5ed7;
    /* The theme and style.css paint #007bff -> #0056b3 gradients (white text 3.98:1 at the light end). */
    background-image: linear-gradient(135deg, #0b5ed7 0%, #0a58ca 100%);
    color: #fff;
}
.badge.bg-success,
.badge.text-bg-success {
    background-color: #047857 !important;
    color: #fff !important;
}
.badge.bg-info,
.badge.text-bg-info {
    background-color: #0e7490 !important;
    color: #fff !important;
}
.badge.bg-warning,
.badge.text-bg-warning {
    background-color: #ffc107 !important;
    color: #212529 !important;
}
.btn-outline-warning {
    --bs-btn-color: #8a4b00;
    --bs-btn-border-color: #b45309;
    --bs-btn-hover-color: #212529;
}
.btn-outline-info {
    --bs-btn-color: #0e7490;
    --bs-btn-border-color: #0e7490;
    --bs-btn-hover-bg: #0e7490;
    --bs-btn-hover-color: #fff;
}
.btn-outline-secondary {
    --bs-btn-color: #565e64;
    --bs-btn-border-color: #6c757d;
}
.link-primary,
a.link-primary,
.auth-card a:not(.btn) {
    color: #1d4ed8 !important;
}
.form-text,
.text-muted,
small.text-muted {
    color: #5c636a !important;
}
.log-level.INFO {
    background: #0e7490;
    color: #fff;
}
.sidebar-nav .nav-link.active {
    color: #0a58ca;
}

/* ---- Minimum readable text: nothing below 12px ---- */
.badge,
.log-level,
.small,
small {
    font-size: max(0.75rem, 0.875em);
}
.badge,
.log-level {
    font-size: 0.75rem;
}

/* ---- M-3: tap targets. WCAG 2.2 SC 2.5.8 requires >= 24x24 CSS px. ---- */
.btn,
.form-select,
.form-control {
    min-height: 2rem;
}
.btn-sm {
    min-height: 2rem;
    min-width: 2rem;
}
.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.125rem;
}
th.sortable-header {
    cursor: pointer;
}
@media (pointer: coarse) {
    .btn,
    .form-select,
    .form-control,
    .sidebar-nav .nav-link,
    .dropdown-item {
        min-height: 2.75rem;
    }
    .btn-sm {
        min-width: 2.75rem;
    }
}

/* ---- X-5: visible keyboard focus everywhere, including the upload drop zone ---- */
:focus-visible {
    outline: 3px solid #1d4ed8;
    outline-offset: 2px;
}
.file-upload-area:focus-visible {
    outline: 3px solid #1d4ed8 !important;
    outline-offset: 2px;
    border-color: #1d4ed8;
    background-color: #eef4ff;
}

/* ---- X-1: dark theme ---- */
[data-bs-theme="dark"] .logo-text {
    color: #93c5fd;
}
[data-bs-theme="dark"] .sidebar-nav .nav-link {
    color: #cbd5e1;
}
[data-bs-theme="dark"] .sidebar-nav .nav-link:hover {
    color: #fff;
    background-color: rgba(148, 163, 184, 0.16);
}
[data-bs-theme="dark"] .sidebar-nav .nav-link.active {
    color: #bfdbfe;
    background-color: rgba(59, 130, 246, 0.25);
}
[data-bs-theme="dark"] .sidebar-section {
    color: #94a3b8;
}
[data-bs-theme="dark"] .text-muted,
[data-bs-theme="dark"] .form-text,
[data-bs-theme="dark"] small.text-muted {
    color: #a8b3c4 !important;
}
[data-bs-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: #cbd5e1;
    --bs-btn-border-color: #64748b;
    --bs-btn-hover-bg: #334155;
    --bs-btn-hover-color: #fff;
}
[data-bs-theme="dark"] .btn-outline-warning {
    --bs-btn-color: #fbbf24;
    --bs-btn-border-color: #fbbf24;
    --bs-btn-hover-color: #212529;
}
[data-bs-theme="dark"] .btn-outline-info {
    --bs-btn-color: #67e8f9;
    --bs-btn-border-color: #67e8f9;
    --bs-btn-hover-color: #0f172a;
    --bs-btn-hover-bg: #67e8f9;
}
[data-bs-theme="dark"] .link-primary,
[data-bs-theme="dark"] a.link-primary,
[data-bs-theme="dark"] .auth-card a:not(.btn),
[data-bs-theme="dark"] #userMenuDropdown {
    color: #93c5fd !important;
}
[data-bs-theme="dark"] #upload-dashboard .provider-card,
[data-bs-theme="dark"] .provider-card {
    background-color: #1f2937;
    color: #e5e7eb;
    border-color: #374151;
}
[data-bs-theme="dark"] #upload-dashboard .provider-card.selected,
[data-bs-theme="dark"] .provider-card.selected {
    background-color: rgba(59, 130, 246, 0.2);
    border-color: #60a5fa;
    color: #f1f5f9;
}
[data-bs-theme="dark"] #upload-dashboard .file-upload-area:hover,
[data-bs-theme="dark"] #upload-dashboard .file-upload-area.dragover,
[data-bs-theme="dark"] .file-upload-area:focus-visible {
    background-color: rgba(59, 130, 246, 0.12);
}
[data-bs-theme="dark"] :focus-visible {
    outline-color: #93c5fd;
}
[data-bs-theme="dark"] .badge.bg-warning,
[data-bs-theme="dark"] .badge.text-bg-warning {
    color: #212529 !important;
}

/* ---- X-4 (round 2): contrast of coloured badges, cards, stat tiles and status pills ---- */
.badge.bg-primary,
.card.bg-primary,
.text-bg-primary {
    background-color: #1d4ed8 !important;
    color: #fff !important;
}
.badge.bg-secondary,
.card.bg-secondary,
.text-bg-secondary {
    background-color: #4b5563 !important;
    color: #fff !important;
}
.card.bg-success,
.card.bg-info {
    color: #fff;
}
.card.bg-success {
    background-color: #047857 !important;
}
.card.bg-info {
    background-color: #0e7490 !important;
}
/* Amber needs dark text, including utility classes added for "white on colour" cards. */
.card.bg-warning,
.card.bg-warning .text-white,
.card.bg-warning .text-white-50,
.card.bg-warning h6 {
    color: #212529 !important;
}
.card.bg-warning .text-white-50 {
    opacity: 0.85;
}
.card .text-white-50 {
    color: rgba(255, 255, 255, 0.88) !important;
}
.badge.bg-success-subtle.text-success,
.badge.bg-success-subtle {
    color: #065f46 !important;
}
.text-success {
    color: #047857 !important;
}
[data-bs-theme="dark"] .text-success {
    color: #34d399 !important;
}
[data-bs-theme="dark"] .badge.bg-success-subtle,
[data-bs-theme="dark"] .badge.bg-success-subtle.text-success {
    background-color: rgba(52, 211, 153, 0.18) !important;
    color: #6ee7b7 !important;
}

/* Batch page stat tiles: white text needs a dark enough gradient end-to-end. */
#batch-processing-page .stat-card,
#batch-processing-page .stat-card.success {
    background: linear-gradient(135deg, #4f46e5 0%, #6d28d9 100%);
}
#batch-processing-page .stat-card.warning {
    background: linear-gradient(135deg, #be185d 0%, #b91c1c 100%);
}
#batch-processing-page .stat-card.info {
    background: linear-gradient(135deg, #0369a1 0%, #0e7490 100%);
}
#batch-processing-page .stat-card.primary {
    background: linear-gradient(135deg, #047857 0%, #0f766e 100%);
}

/* Observability status UI */
.service-badge.healthy,
.health-indicator.healthy {
    background: #157347;
    color: #fff;
}
.service-meta,
.service-details small,
.health-check-result {
    color: #495057;
}
.log-timestamp {
    color: #adb5bd;
}
.log-level.WARN {
    color: #212529;
}

/* Table row selection checkboxes: 24px minimum target (WCAG 2.5.8). */
.model-checkbox,
#select-all-checkbox {
    width: 1.5rem;
    height: 1.5rem;
}

/* Remaining contrast offenders from the re-audit */
.card.bg-danger {
    background-color: #b02a37 !important;
    color: #fff;
}
.nav-tabs .nav-link:not(.active),
.nav-pills .nav-link:not(.active) {
    color: #495057;
}
[data-bs-theme="dark"] .nav-tabs .nav-link:not(.active),
[data-bs-theme="dark"] .nav-pills .nav-link:not(.active) {
    color: #cbd5e1;
}
/* Large tables: let the browser skip layout/paint for off-screen rows. */
.table-responsive tbody tr {
    content-visibility: auto;
    contain-intrinsic-size: auto 3rem;
}

/* ---- X-1 (round 2): dark-theme surfaces and text that page CSS/utilities pin to light colours ---- */
[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .card-header.bg-light,
[data-bs-theme="dark"] .table-light,
[data-bs-theme="dark"] .table-light > th,
[data-bs-theme="dark"] .table-light > td {
    background-color: #1f2937 !important;
    color: #e5e7eb !important;
}
[data-bs-theme="dark"] .bg-white,
[data-bs-theme="dark"] .card-header.bg-white {
    background-color: #111827 !important;
    color: #e5e7eb !important;
}
[data-bs-theme="dark"] :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6):not([class*="text-"]) {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .metric-value,
[data-bs-theme="dark"] .detail-value,
[data-bs-theme="dark"] .config-item strong,
[data-bs-theme="dark"] .service-details strong,
[data-bs-theme="dark"] .card strong {
    color: #e5e7eb;
}
[data-bs-theme="dark"] .config-label,
[data-bs-theme="dark"] .detail-label {
    color: #9ca3af;
}
[data-bs-theme="dark"] a:not(.btn):not(.nav-link):not(.dropdown-item):not(.list-group-item):not(.badge):not(.skip-to-content) {
    color: #93c5fd;
}
[data-bs-theme="dark"] .btn-outline-primary {
    --bs-btn-color: #93c5fd;
    --bs-btn-border-color: #60a5fa;
    --bs-btn-hover-bg: #1d4ed8;
    --bs-btn-hover-color: #fff;
}
[data-bs-theme="dark"] .nav-tabs .nav-link.active {
    color: #bfdbfe;
}

/* Outline buttons in the dark theme: set the colour directly (page CSS pins it, not the variables). */
[data-bs-theme="dark"] .btn-outline-primary { color: #93c5fd; border-color: #60a5fa; }
[data-bs-theme="dark"] .btn-outline-success { color: #6ee7b7; border-color: #34d399; }
[data-bs-theme="dark"] .btn-outline-warning { color: #fbbf24; border-color: #fbbf24; }
[data-bs-theme="dark"] .btn-outline-info { color: #67e8f9; border-color: #67e8f9; }
[data-bs-theme="dark"] .btn-outline-danger { color: #fca5a5; border-color: #f87171; }
[data-bs-theme="dark"] .btn-outline-secondary { color: #cbd5e1; border-color: #64748b; }
[data-bs-theme="dark"] .btn-outline-primary:hover,
[data-bs-theme="dark"] .btn-outline-success:hover,
[data-bs-theme="dark"] .btn-outline-warning:hover,
[data-bs-theme="dark"] .btn-outline-info:hover,
[data-bs-theme="dark"] .btn-outline-danger:hover,
[data-bs-theme="dark"] .btn-outline-secondary:hover { color: #0f172a; background-color: #e2e8f0; }
.skip-to-content:focus { color: #fff; background: #1d4ed8; }

/* Observability status chips: amber needs dark text, the rest white (in both themes). */
.service-badge {
    color: #fff;
}
.service-badge.warning {
    color: #212529;
}

/* workflows.css defines its own light-only palette and paints <body> with it. Re-map it in dark mode
   so every workflow/billing page follows the theme (audit X-1). */
[data-bs-theme="dark"] {
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #1f2937;
    --border-color: #374151;
    --text-primary: #f1f5f9;
    --text-secondary: #9ca3af;
    --text-tertiary: #9ca3af;
}

/* "Light" utility badges and active filter pills (audit X-1/X-4). */
[data-bs-theme="dark"] .badge.text-bg-light,
[data-bs-theme="dark"] .text-bg-light {
    background-color: #374151 !important;
    color: #e5e7eb !important;
}
.filter-btn.active {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #fff;
}

/* Inline <code> inside the dark CLI terminal must not keep the light "code chip" background. */
.cli-terminal-window code {
    background: transparent;
    color: inherit;
}

/* Dark-mode counterparts for rules above that darken text for light backgrounds. */
[data-bs-theme="dark"] .service-meta,
[data-bs-theme="dark"] .service-details small,
[data-bs-theme="dark"] .health-check-result {
    color: #cbd5e1;
}
[data-bs-theme="dark"] .filter-btn:not(.active) {
    color: #e5e7eb;
    background: #1f2937;
}
[data-bs-theme="dark"] .btn-link {
    color: #93c5fd;
}

/* Active/checked outline buttons are filled: keep their text white in every theme. */
.btn-outline-primary.active,
.btn-check:checked + .btn-outline-primary,
[data-bs-theme="dark"] .btn-outline-primary.active,
[data-bs-theme="dark"] .btn-check:checked + .btn-outline-primary {
    color: #fff;
    background-color: #1d4ed8;
    border-color: #1d4ed8;
}

/* Standalone links in table cells: give them a 24px-tall hit area (WCAG 2.5.8). */
a.model-preview-link {
    display: inline-block;
    min-height: 1.5rem;
    line-height: 1.5rem;
}

/* Benchmark result headers: white text needs a darker gradient end-to-end (>= 5:1). */
.benchmark-header {
    background: linear-gradient(135deg, #4f46e5 0%, #6d28d9 100%);
    color: #fff;
}
