/* ============================================================
   InCred Research Portal — Accessibility Preferences
   ============================================================
   In-house accessibility-preferences widget. Pure CSS + JS, no
   third-party dependency.

   Closes design-accepted audit gaps:
     DOM43-68, 86, 96, 117 (1.4.11 control border contrast)
     DOM43-90              (1.4.12 text-spacing tolerance)

   Default state (no opt-in): zero change to existing design.
   Every override below is conditioned on a data-attribute or CSS
   custom property that is only set when the user has explicitly
   opted in via the floating button. So a user who never opens the
   panel sees the portal exactly as it is today.
   ============================================================ */


/* ---------- Floating button (visible) ----------
   Update 2026-06-04: per user decision, the floating button is restored as
   the primary visible entry point to the accessibility widget. The footer
   link and Alt+A keyboard shortcut remain as additional discoverable paths
   (useful redundancy for users on different access modes). */

.a11y-prefs-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1500;          /* above modals + Zoho widget */
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: #f26319;
    color: #ffffff;
    border: 2px solid #ffffff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font: inherit;
    transition: transform 150ms ease-in-out, background-color 150ms ease-in-out;
}
.a11y-prefs-button:hover {
    background-color: #d94f0a;
    transform: scale(1.05);
}
.a11y-prefs-button:focus-visible {
    outline: 3px solid #B7410E !important;
    outline-offset: 3px !important;
}
.a11y-prefs-button svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
    pointer-events: none;
}


/* ---------- Panel ---------- */

.a11y-prefs-panel {
    position: fixed;
    bottom: 88px;
    right: 20px;
    z-index: 1500;
    width: 320px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 120px);
    background-color: #ffffff;
    color: #2B5A6D;
    border: 1px solid #d6d6d6;
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.20);
    padding: 20px 22px;
    overflow-y: auto;
    font-family: 'Poppins', sans-serif;
    font-size: 14px;
}
.a11y-prefs-panel[hidden] {
    display: none;
}
.a11y-prefs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 14px 0;
    padding-bottom: 12px;
    border-bottom: 1px solid #ececec;
}
.a11y-prefs-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    color: #2B5A6D;
    letter-spacing: 0;
}
.a11y-prefs-close {
    background: transparent;
    border: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    color: #595959;
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.a11y-prefs-close:hover {
    background-color: #f6f1ec;
    color: #B7410E;
}
.a11y-prefs-close:focus-visible {
    outline: 3px solid #B7410E !important;
    outline-offset: 2px !important;
}

.a11y-prefs-group {
    margin: 0 0 16px 0;
    padding: 0;
    border: 0;
}
.a11y-prefs-group legend,
.a11y-prefs-group .a11y-prefs-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #2B5A6D;
    margin: 0 0 6px 0;
    padding: 0;
}
.a11y-prefs-group label {
    display: inline-flex;
    align-items: center;
    margin: 4px 8px 4px 0;
    font-size: 13px;
    font-weight: normal;
    cursor: pointer;
    color: #333333;
}
.a11y-prefs-group label > input[type="radio"],
.a11y-prefs-group label > input[type="checkbox"] {
    /* These radios/checkboxes are scoped here — they MUST be visible.
       The site-wide rule that hides native checkbox/radio is opacity:0,
       so we need to opt out by repositioning + opacity:1. */
    position: static !important;
    opacity: 1 !important;
    z-index: 0 !important;
    margin-right: 6px;
    width: auto;
    height: auto;
}

.a11y-prefs-group input[type="range"] {
    width: 100%;
    margin: 4px 0 0 0;
}
.a11y-prefs-group output {
    font-size: 12px;
    color: #595959;
    margin-left: 6px;
}
.a11y-prefs-reset {
    width: 100%;
    background-color: #2B5A6D;
    color: #ffffff;
    border: 0;
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
}
.a11y-prefs-reset:hover {
    background-color: #1F4250;
}
.a11y-prefs-reset:focus-visible {
    outline: 3px solid #B7410E !important;
    outline-offset: 2px !important;
}


/* ============================================================
   PREFERENCE-DRIVEN OVERRIDES
   Only applied when html[data-a11y-*] is set by the JS.
   ============================================================ */


/* ---------- Text size scaling ----------
   FIX 2026-05-29: the previous rule set html { font-size: 17.5px } and
   relied on REM units cascading. But the InCred Research Portal has 111
   px-based font-size declarations in style.css and only 1 rem-based, so
   changing html font-size had ZERO visible effect — user clicked "Large"
   and the page didn't change. Switch to the CSS `zoom` property which
   scales the entire page proportionally regardless of unit type. `zoom`
   is supported in every browser the portal targets (Chrome/Edge/Safari/
   Firefox 126+) and is the standard accessibility-scaling technique used
   by every commercial a11y widget. Excluded from the widget itself so
   the panel doesn't get scaled twice. */

html[data-a11y-text-size="large"]  { zoom: 1.10; }
html[data-a11y-text-size="xl"]     { zoom: 1.25; }
html[data-a11y-text-size="xxl"]    { zoom: 1.50; }
html[data-a11y-text-size="large"] .a11y-prefs-button,
html[data-a11y-text-size="large"] .a11y-prefs-panel,
html[data-a11y-text-size="xl"]    .a11y-prefs-button,
html[data-a11y-text-size="xl"]    .a11y-prefs-panel,
html[data-a11y-text-size="xxl"]   .a11y-prefs-button,
html[data-a11y-text-size="xxl"]   .a11y-prefs-panel {
    zoom: 1;            /* Don't compound — widget panel stays at 100% */
}


/* ---------- High-contrast mode ----------
   Closes DOM43-68, 86, 96, 117 by darkening control borders to ≥3:1.
   Also darkens muted greys (footer copyright, .help-block) to ≥4.5:1.

   FIX 2026-05-29: previous version only modified form input borders and
   muted greys. On pages without forms (Home, Sector, Disclaimer) the user
   clicked "High contrast" and saw zero visible change. Add body-text
   darkening and link-colour boosting so the effect is visible everywhere. */

html[data-a11y-contrast="high"] body,
html[data-a11y-contrast="high"] body p,
html[data-a11y-contrast="high"] body li,
html[data-a11y-contrast="high"] body td,
html[data-a11y-contrast="high"] body span,
html[data-a11y-contrast="high"] body label,
html[data-a11y-contrast="high"] body h1,
html[data-a11y-contrast="high"] body h2,
html[data-a11y-contrast="high"] body h3,
html[data-a11y-contrast="high"] body h4,
html[data-a11y-contrast="high"] body h5,
html[data-a11y-contrast="high"] body h6 {
    color: #000000 !important;
}
html[data-a11y-contrast="high"] .login-box .input-box .textbox,
html[data-a11y-contrast="high"] .change-password-wrapper .input-box .form-control,
html[data-a11y-contrast="high"] .form-control,
html[data-a11y-contrast="high"] input[type="text"]:not([disabled]),
html[data-a11y-contrast="high"] input[type="email"]:not([disabled]),
html[data-a11y-contrast="high"] input[type="password"]:not([disabled]),
html[data-a11y-contrast="high"] input[type="search"]:not([disabled]),
html[data-a11y-contrast="high"] textarea {
    border-color: #000000 !important;
    border-bottom-color: #000000 !important;
    border-bottom-width: 2px !important;
}
html[data-a11y-contrast="high"] label.check-radio::before {
    border-color: #000000 !important;
    border-width: 2px !important;
}
html[data-a11y-contrast="high"] hr,
html[data-a11y-contrast="high"] .horizontal-slider {
    border-color: #000000 !important;
}
html[data-a11y-contrast="high"] .login-footer,
html[data-a11y-contrast="high"] .login-footer span,
html[data-a11y-contrast="high"] .help-block,
html[data-a11y-contrast="high"] .text-muted,
html[data-a11y-contrast="high"] small {
    color: #1A1A1A !important;
}
html[data-a11y-contrast="high"] a:not(.btn):not(.nav-pills a):not(.a11y-prefs-button):not(.a11y-prefs-close):not(.a11y-prefs-reset) {
    color: #0033A0 !important;
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
}
/* Re-invert the widget panel so it stays readable in high-contrast mode */
html[data-a11y-contrast="high"] .a11y-prefs-panel,
html[data-a11y-contrast="high"] .a11y-prefs-panel * {
    color: #2B5A6D !important;
}


/* ---------- Letter spacing + line height sliders ----------
   Closes DOM43-90: user controls text spacing on demand.
   CSS custom properties cascade everywhere.

   FIX 2026-05-29: previously this rule fired whenever data-a11y-active was
   set (which the JS does on load with DEFAULT prefs), forcing
   line-height:1.5 onto every div in the site even when the user opted in
   to NOTHING. That changed visual spacing across every page. Now scope it
   to the dedicated data-a11y-spacing-override attribute, which a11y-prefs.js
   only sets when the user moves either slider above 0. Default state =
   zero CSS override, original design pixel-equivalent. */

:root {
    --ic-a11y-letter-spacing: 0;
    --ic-a11y-line-height-bonus: 0;
}
html[data-a11y-spacing-override="on"] body p,
html[data-a11y-spacing-override="on"] body li,
html[data-a11y-spacing-override="on"] body td,
html[data-a11y-spacing-override="on"] body th,
html[data-a11y-spacing-override="on"] body span,
html[data-a11y-spacing-override="on"] body label,
html[data-a11y-spacing-override="on"] body div:not(.a11y-prefs-panel):not(.a11y-prefs-panel *) {
    letter-spacing: var(--ic-a11y-letter-spacing);
    line-height: calc(1.5 + var(--ic-a11y-line-height-bonus));
}


/* ---------- Emphasise links ---------- */

html[data-a11y-underline-links="on"] a:not(.btn):not(.btn-orange):not(.btn-orange-bg):not(.btn-blue):not(.skip-link):not(.a11y-prefs-button):not(.a11y-prefs-close):not(.a11y-prefs-reset) {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 3px !important;
    font-weight: 600 !important;
}


/* ---------- Pause animations ---------- */

html[data-a11y-pause-animations="on"] *,
html[data-a11y-pause-animations="on"] *::before,
html[data-a11y-pause-animations="on"] *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}


/* ---------- Invert colours ----------
   Site-wide filter inverts everything. Re-invert images so they
   show normally; re-invert the a11y panel + button so the user can
   still see the toggle states correctly. */

html[data-a11y-invert="on"] {
    filter: invert(1) hue-rotate(180deg);
    background-color: #ffffff;
}
html[data-a11y-invert="on"] img,
html[data-a11y-invert="on"] video,
html[data-a11y-invert="on"] picture,
html[data-a11y-invert="on"] svg,
html[data-a11y-invert="on"] .a11y-prefs-button,
html[data-a11y-invert="on"] .a11y-prefs-panel {
    filter: invert(1) hue-rotate(180deg);
}


/* ---------- Mobile responsiveness for the panel itself ---------- */

@media (max-width: 480px) {
    .a11y-prefs-button {
        bottom: 12px;
        right: 12px;
        width: 48px;
        height: 48px;
    }
    .a11y-prefs-panel {
        bottom: 72px;
        right: 12px;
        left: 12px;
        width: auto;
        max-height: calc(100vh - 100px);
        padding: 16px 18px;
    }
}


/* ---------- Footer "Accessibility preferences" link ----------
   Subtle inline link next to "Disclaimer" — the visible discovery point
   for the widget since the floating button is now off-screen by default. */

.a11y-prefs-footer-link {
    margin-left: 16px;
}
