/**
 * Base CSS - ADA WCAG 2.1 AA Compliant
 * All brands extend this with their color variables
 */

/* ============================================
   CSS CUSTOM PROPERTIES (Brand Colors)
   Override these in brand-*.css files
   ============================================ */
:root {
    /* Default brand colors - override per brand */
    --brand-primary: #0d6efd;
    --brand-secondary: #6c757d;
    --brand-success: #198754;
    --brand-danger: #dc3545;
    --brand-warning: #ffc107;
    --brand-info: #0dcaf0;

    /* Bootstrap overrides using brand colors */
    --bs-primary: var(--brand-primary);
    --bs-secondary: var(--brand-secondary);
    --bs-success: var(--brand-success);
    --bs-danger: var(--brand-danger);
    --bs-warning: var(--brand-warning);
    --bs-info: var(--brand-info);

    /* ADA-compliant focus ring */
    --focus-ring-width: 2px;
    --focus-ring-color: var(--brand-primary);
    --focus-ring-offset: 2px;
}

/* ============================================
   1. SKIP LINK (ADA Requirement)
   ============================================ */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--brand-primary);
    color: #fff !important;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 4px 0;
}

.skip-link:focus {
    top: 0;
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* ============================================
   2. KEYBOARD FOCUS INDICATORS (ADA 2.4.7, 2.4.11)
   ============================================ */
/* Global focus - never remove outline without replacement */
*:focus {
    outline: var(--focus-ring-width) solid var(--focus-ring-color) !important;
    outline-offset: var(--focus-ring-offset) !important;
}

*:focus:not(:focus-visible) {
    outline: none !important;
}

*:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color) !important;
    outline-offset: var(--focus-ring-offset) !important;
}

/* Specific focus styles for interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color) !important;
    outline-offset: var(--focus-ring-offset) !important;
    border-color: var(--brand-primary) !important;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1) !important;
}

/* ============================================
   3. COLOR CONTRAST (ADA 1.4.3 - 4.5:1 for text)
   ============================================ */
/* Ensure sufficient contrast - override brand colors if needed */
/* Default Bootstrap grays pass on white, but verify per brand */

body {
    color: #212529; /* 15.3:1 on white - passes */
    background-color: #ffffff;
}

/* Light text on dark backgrounds - check contrast */
/* #15920 round2: #6c757d measured 4.45-4.49:1 on brand-tinted backgrounds
   (bl cream #fbf9f7/#fdf8f5, dv #f1fcfe/#ddf7fc, ns #f1f0ed, nw footer #f4f4f4)
   = sub-threshold. Darkened to #5a6268: worst case 5.45:1 (#f1f0ed), all >= AA. */
.text-muted {
    color: #5a6268 !important; /* #15920: 5.45-6.89:1 across all page backgrounds */
}

/* #15920 round2: bootstrap outline-secondary text #6c757d failed on dv/ns tints */
.btn-outline-secondary {
    color: #5a6268 !important;
    border-color: #5a6268 !important;
}

/* #15920 round2: .btn-link bootstrap blue #0d6efd = 4.31-4.35:1 on cream/blue tints.
   Darkened to bs blue-800 #0a58ca: 5.65-6.44:1 everywhere. */
.btn-link {
    color: #0a58ca !important;
}

/* Links - ensure distinguishable */
a {
    color: var(--brand-primary);
    text-decoration: underline;
}

a:hover {
    color: var(--brand-secondary);
}

/* ============================================
   4. FORM ACCESSIBILITY (ADA 1.3.1, 3.3.1, 4.1.2)
   ============================================ */
/* Visible labels - NEVER use placeholder as sole label */
.form-label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #212529;
}

/* Required field indicator */
.form-label .required-indicator {
    color: #dc3545;
    margin-left: 2px;
    font-weight: bold;
}

/* Error states - color alone is not enough (ADA 3.3.1) */
.is-invalid {
    border-color: #dc3545 !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23dc3545' class='bi bi-exclamation-circle' viewBox='0 0 16 16'%3E%3Cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z'/%3E%3Cpath d='M7.002 11a1 1 0 1 1 2 0 1 1 0 0 1-2 0zM7.1 4.995a.905.905 0 1 1 1.8 0l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 4.995z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
    padding-right: calc(1.5em + 0.75rem);
}

.invalid-feedback {
    color: #dc3545;
    font-size: 0.875em;
    margin-top: 0.25rem;
    display: block;
}

/* Accessible error messages with icon */
.error-message {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #dc3545;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.error-message::before {
    content: "⚠";
    font-size: 1em;
}

/* Success states */
.is-valid {
    border-color: #198754 !important;
}

/* Form check inputs - larger hit area (ADA) */
.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.125em;
    cursor: pointer;
}

.form-check-input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.form-check-input:checked {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
}

/* Radio and checkbox labels */
.form-check-label {
    padding-left: 0.25rem;
    cursor: pointer;
}

/* ============================================
   5. HEADINGS & READING ORDER (ADA 1.3.1)
   ============================================ */
h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    font-weight: 600;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

/* ============================================
   6. BUTTONS & INTERACTIVE ELEMENTS
   ============================================ */
.btn {
    min-height: 44px; /* ADA touch target minimum */
    min-width: 44px;
    padding: 0.5rem 1rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
}

.btn:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color) !important;
    outline-offset: var(--focus-ring-offset) !important;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.15) !important;
}

/* Primary button */
.btn-primary {
    --bs-btn-bg: var(--brand-primary);
    --bs-btn-border-color: var(--brand-primary);
    --bs-btn-hover-bg: var(--brand-secondary);
    --bs-btn-hover-border-color: var(--brand-secondary);
    --bs-btn-active-bg: var(--brand-secondary);
    --bs-btn-disabled-bg: #6c757d;
    --bs-btn-disabled-border-color: #6c757d;
}

/* ============================================
   7. STEP INDICATOR (Accessibility-friendly)
   ============================================ */
.step-indicator {
    display: flex;
    list-style: none;
    padding: 0;
    margin: 0;
    gap: 1rem;
}

.step-indicator li {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
}

.step-indicator .step-circle {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    background-color: #e9ecef;
    color: #6c757d;
    border: 2px solid #dee2e6;
    margin-bottom: 0.5rem;
}

.step-indicator li.active .step-circle {
    background-color: var(--brand-primary);
    color: #fff;
    border-color: var(--brand-primary);
}

.step-indicator li.completed .step-circle {
    background-color: var(--brand-success);
    color: #fff;
    border-color: var(--brand-success);
}

.step-indicator li.active .step-circle {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* ============================================
   8. MODAL ACCESSIBILITY
   ============================================ */
.modal-open {
    overflow: auto;
}

.modal:focus {
    outline: none;
}

/* Ensure focus stays within modal */
.modal-dialog {
    max-height: calc(100vh - 3.5rem);
    margin: 1.75rem auto;
}

@media (max-width: 576px) {
    .modal-dialog {
        max-height: calc(100vh - 1rem);
        margin: 0.5rem;
    }
}

/* ============================================
   9. CARD COMPONENTS
   ============================================ */
.card {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.card-body {
    padding: 1.25rem;
}

/* ============================================
   10. TABLES (if used)
   ============================================ */
.table {
    border-collapse: collapse;
}

.table th {
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
    border-bottom: 2px solid #dee2e6;
}

.table td {
    padding: 0.75rem;
    border-bottom: 1px solid #dee2e6;
}

.table tbody tr:hover {
    background-color: #f8f9fa;
}

/* ============================================
   11. NAVBAR (ADA compliant)
   ============================================ */
.navbar {
    min-height: 60px;
}

.navbar-brand {
    font-weight: 600;
    font-size: 1.25rem;
}

.navbar-brand img {
    max-height: 40px;
    width: auto;
}

.nav-link {
    padding: 0.5rem 1rem !important;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.nav-link:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color) !important;
    outline-offset: -2px !important;
}

/* ============================================
   12. TOAST NOTIFICATIONS (aria-live)
   ============================================ */
.toast-container {
    z-index: 1100;
}

.toast {
    opacity: 1;
    border-radius: 0.375rem;
}

.toast:focus {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* ============================================
   13. SELECT DROPDOWNS
   ============================================ */
select.form-select {
    min-height: 44px;
    padding: 0.5rem 2.25rem 0.5rem 0.75rem;
}

select.form-select:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* ============================================
   14. FILE UPLOAD
   ============================================ */
input[type="file"] {
    min-height: 44px;
    padding: 0.5rem;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    background-color: #fff;
}

input[type="file"]:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* ============================================
   15. AUTOCOMPLETE / SEARCH
   ============================================ */
.autocomplete-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    background-color: #fff;
}

.autocomplete-list li {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #dee2e6;
}

.autocomplete-list li:last-child {
    border-bottom: none;
}

.autocomplete-list li:hover,
.autocomplete-list li:focus,
.autocomplete-list li[aria-selected="true"] {
    background-color: #f8f9fa;
    outline: none;
}

/* ============================================
   16. PROGRESS / LOADING
   ============================================ */
.spinner {
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    animation: spin 1s linear infinite;
}

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

[aria-busy="true"] {
    cursor: wait;
}

/* ============================================
   17. ACCESSIBLE HIDDEN 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,
.sr-only-focusable:active {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ============================================
   18. REDUCED MOTION (ADA 2.3.3)
   ============================================ */
@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;
    }
}

/* ============================================
   19. PRINT STYLES
   ============================================ */
@media print {
    .no-print {
        display: none !important;
    }

    body {
        background-color: #fff !important;
        color: #000 !important;
    }
}

/* ============================================
   20. FORCED COLORS (Windows High Contrast Mode) — ADA 1.4.3, 1.4.11
   ============================================ */
@media (forced-colors: active) {
    /* Ensure visible borders on form controls */
    input,
    select,
    textarea,
    button {
        border: 1px solid ButtonText !important;
        forced-color-adjust: auto;
    }

    /* Visible focus indicator using system colors */
    *:focus-visible {
        outline: 3px solid Highlight !important;
        outline-offset: 2px !important;
        forced-color-adjust: none;
    }

    /* Buttons need explicit borders to be visible */
    .btn {
        border: 2px solid ButtonText !important;
        forced-color-adjust: none;
    }

    /* Links should always be underlined */
    a {
        text-decoration: underline !important;
    }

    /* Error/alert messages need explicit border */
    .alert {
        border: 2px solid ButtonText !important;
        forced-color-adjust: none;
    }

    /* Skip link */
    .skip-link:focus {
        outline: 3px solid Highlight !important;
        background: Mark !important;
        color: MarkText !important;
        forced-color-adjust: none;
    }

    /* Step indicator circles need borders */
    .step-circle {
        border: 2px solid ButtonText !important;
        forced-color-adjust: none;
    }
}
