/* =================================================================
 * CivicBell Accessibility Widget
 * WCAG 2.1 Level AA aligned end-user accommodations.
 *
 * Pure presentational layer. Adds fixed-position UI + body class hooks
 * that toggle visual properties only — no DOM mutation of host content,
 * no impact on form submission, navigation, or business logic.
 *
 * Loaded by: portal.php, login.php, public_residency_verification.php
 * Mounted by: /v2/scripts/accessibility-widget.js
 * ================================================================= */

/* ------------------------------------------------------------------
 * Trigger button
 * ------------------------------------------------------------------ */
.a11y-trigger {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2147483646;
    width: 44px;
    height: 44px;
    background: #111;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 8px 0 0 8px;
    border-right: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.25);
    transition: background 0.2s;
    padding: 0;
    line-height: 1;
}
.a11y-trigger:hover,
.a11y-trigger:focus-visible { background: #333; }
.a11y-trigger:focus-visible {
    outline: 3px solid #ffbf00;
    outline-offset: 2px;
}
.a11y-trigger i { font-size: 1.3rem; line-height: 1; pointer-events: none; }

/* ------------------------------------------------------------------
 * Panel
 * ------------------------------------------------------------------ */
.a11y-panel {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 2147483647;
    width: 320px;
    max-width: 95vw;
    height: 100vh;
    background: #fff;
    color: #000;
    border-left: 2px solid #000;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}
.a11y-panel.open { transform: translateX(0); }
.a11y-panel * { box-sizing: border-box; }
/* Panel doesn't scroll; the body section does. Keeps header/footer fixed. */
.a11y-panel { overflow: hidden; }

.a11y-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 2px solid #000;
    flex-shrink: 0;
    background: #fff;
}
.a11y-panel-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #000;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.a11y-panel-header h2 i { font-size: 1.05rem; line-height: 1; }

.a11y-panel-close {
    background: #fff;
    border: 2px solid #000;
    color: #000;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s, color 0.15s;
    padding: 0;
    line-height: 1;
}
.a11y-panel-close:hover,
.a11y-panel-close:focus-visible { background: #000; color: #fff; }
.a11y-panel-close:focus-visible { outline: 3px solid #ffbf00; outline-offset: 2px; }
.a11y-panel-close i { font-size: 1rem; line-height: 1; }

.a11y-panel-body {
    padding: 1rem 1.25rem 1.25rem;
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.a11y-section { margin-bottom: 1.25rem; }
.a11y-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #000;
    margin: 0 0 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid #ccc;
}

.a11y-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.a11y-row:last-child { margin-bottom: 0; }
.a11y-row-label {
    font-size: 0.875rem;
    color: #000;
    font-weight: 500;
    flex: 1;
    min-width: 0;
}

.a11y-stepper {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}
.a11y-btn {
    background: #fff;
    color: #000;
    border: 2px solid #000;
    border-radius: 6px;
    padding: 0;
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.a11y-btn:hover,
.a11y-btn:focus-visible { background: #000; color: #fff; }
.a11y-btn:focus-visible { outline: 3px solid #ffbf00; outline-offset: 2px; }
.a11y-btn[aria-disabled="true"],
.a11y-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #fff;
    color: #000;
}
.a11y-stepper-value {
    min-width: 3rem;
    text-align: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #000;
    font-variant-numeric: tabular-nums;
}

.a11y-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border: 2px solid #000;
    border-radius: 8px;
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
    width: 100%;
    color: #000;
    font-family: inherit;
    text-align: left;
    margin-bottom: 0.4rem;
}
.a11y-toggle:last-child { margin-bottom: 0; }
.a11y-toggle:hover,
.a11y-toggle:focus-visible { background: #f0f0f0; }
.a11y-toggle:focus-visible { outline: 3px solid #ffbf00; outline-offset: 2px; }
.a11y-toggle-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #000;
    flex: 1;
    min-width: 0;
}
.a11y-toggle-indicator {
    width: 40px;
    height: 22px;
    border-radius: 11px;
    background: #ccc;
    border: 1px solid #000;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}
.a11y-toggle-indicator::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #000;
    transition: transform 0.2s, background 0.2s;
}
.a11y-toggle[aria-checked="true"] .a11y-toggle-indicator { background: #000; }
.a11y-toggle[aria-checked="true"] .a11y-toggle-indicator::after {
    transform: translateX(16px);
    background: #fff;
}

.a11y-panel-footer {
    padding: 0.75rem 1.25rem 1rem;
    border-top: 2px solid #000;
    background: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.a11y-reset {
    width: 100%;
    background: #fff;
    border: 2px solid #000;
    color: #000;
    border-radius: 6px;
    padding: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}
.a11y-reset:hover,
.a11y-reset:focus-visible { background: #000; color: #fff; }
.a11y-reset:focus-visible { outline: 3px solid #ffbf00; outline-offset: 2px; }

.a11y-statement-link {
    display: block;
    text-align: center;
    font-size: 0.8rem;
    color: #000;
    text-decoration: underline;
    padding: 0.25rem;
    font-weight: 500;
}
.a11y-statement-link:hover,
.a11y-statement-link:focus-visible { color: #444; }
.a11y-statement-link:focus-visible { outline: 3px solid #ffbf00; outline-offset: 2px; border-radius: 4px; }

/* Skip-to-main link injected by widget */
.a11y-skip-link {
    position: fixed;
    top: -100px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 0.75rem 1rem;
    z-index: 2147483647;
    text-decoration: underline;
    font-weight: 700;
    border: 2px solid #fff;
    border-radius: 0 0 6px 0;
    transition: top 0.15s;
}
.a11y-skip-link:focus { top: 0; outline: 3px solid #ffbf00; outline-offset: 2px; color: #fff; }

/* Reading guide & mask overlays */
.a11y-reading-guide {
    position: fixed;
    left: 0;
    right: 0;
    height: 30px;
    background: rgba(255, 235, 59, 0.35);
    border-top: 2px solid #000;
    border-bottom: 2px solid #000;
    pointer-events: none;
    z-index: 2147483640;
    display: none;
}
body.a11y-reading-guide-on .a11y-reading-guide { display: block; }

.a11y-reading-mask-top,
.a11y-reading-mask-bottom {
    position: fixed;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.55);
    pointer-events: none;
    z-index: 2147483640;
    display: none;
}
.a11y-reading-mask-top { top: 0; }
.a11y-reading-mask-bottom { bottom: 0; }
body.a11y-reading-mask-on .a11y-reading-mask-top,
body.a11y-reading-mask-on .a11y-reading-mask-bottom { display: block; }

/* RTL */
[dir="rtl"] .a11y-trigger {
    right: auto;
    left: 0;
    border-radius: 0 8px 8px 0;
    border-right: 2px solid #fff;
    border-left: none;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.25);
}
[dir="rtl"] .a11y-panel {
    right: auto;
    left: 0;
    transform: translateX(-100%);
    border-left: none;
    border-right: 2px solid #000;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
}
[dir="rtl"] .a11y-panel.open { transform: translateX(0); }
[dir="rtl"] .a11y-toggle-indicator::after { left: auto; right: 3px; }
[dir="rtl"] .a11y-toggle[aria-checked="true"] .a11y-toggle-indicator::after {
    transform: translateX(-16px);
}

@media (max-width: 380px) {
    .a11y-panel { width: 100vw; max-width: 100vw; }
}

/* =================================================================
 * Body class hooks — visual accommodations.
 *
 * High specificity + !important on rules that need to override
 * existing page CSS (which may already use !important for theming).
 * Selectors deliberately broad-and-shallow so they work across all
 * three host pages without modifying host markup.
 * ================================================================= */

/* --- Letter / word / line spacing (WCAG 1.4.12 Text Spacing) ----- */
body.a11y-letter-spacing-1 *,
body.a11y-letter-spacing-2 *,
body.a11y-letter-spacing-3 * {
    letter-spacing: var(--a11y-letter-spacing, 0) !important;
}
body.a11y-letter-spacing-1 { --a11y-letter-spacing: 0.05em; }
body.a11y-letter-spacing-2 { --a11y-letter-spacing: 0.10em; }
body.a11y-letter-spacing-3 { --a11y-letter-spacing: 0.15em; }

body.a11y-word-spacing-1 *,
body.a11y-word-spacing-2 *,
body.a11y-word-spacing-3 * {
    word-spacing: var(--a11y-word-spacing, normal) !important;
}
body.a11y-word-spacing-1 { --a11y-word-spacing: 0.16em; }
body.a11y-word-spacing-2 { --a11y-word-spacing: 0.32em; }
body.a11y-word-spacing-3 { --a11y-word-spacing: 0.48em; }

body.a11y-line-height-1 *,
body.a11y-line-height-2 *,
body.a11y-line-height-3 * {
    line-height: var(--a11y-line-height, inherit) !important;
}
body.a11y-line-height-1 { --a11y-line-height: 1.6; }
body.a11y-line-height-2 { --a11y-line-height: 2.0; }
body.a11y-line-height-3 { --a11y-line-height: 2.5; }

/* Exclusions — never re-space the widget's own UI */
body[class*="a11y-letter-spacing-"] .a11y-trigger,
body[class*="a11y-letter-spacing-"] .a11y-panel,
body[class*="a11y-letter-spacing-"] .a11y-panel *,
body[class*="a11y-word-spacing-"] .a11y-trigger,
body[class*="a11y-word-spacing-"] .a11y-panel,
body[class*="a11y-word-spacing-"] .a11y-panel *,
body[class*="a11y-line-height-"] .a11y-trigger,
body[class*="a11y-line-height-"] .a11y-panel,
body[class*="a11y-line-height-"] .a11y-panel * {
    letter-spacing: normal !important;
    word-spacing: normal !important;
    line-height: 1.4 !important;
}

/* --- Readable / dyslexia-friendly font ---------------------------- */
body.a11y-readable-font,
body.a11y-readable-font * {
    font-family: 'Atkinson Hyperlegible', 'Verdana', 'Tahoma', 'Trebuchet MS', Arial, sans-serif !important;
}
body.a11y-readable-font .a11y-trigger,
body.a11y-readable-font .a11y-panel,
body.a11y-readable-font .a11y-panel * {
    font-family: 'Helvetica Neue', Arial, sans-serif !important;
}

/* Bypass icon font replacement so glyphs still render correctly */
body.a11y-readable-font [class*="fa-"],
body.a11y-readable-font .fa,
body.a11y-readable-font .fas,
body.a11y-readable-font .far,
body.a11y-readable-font .fab,
body.a11y-readable-font .fa-solid,
body.a11y-readable-font .fa-regular,
body.a11y-readable-font .fa-brands,
body.a11y-readable-font [class^="bi-"],
body.a11y-readable-font [class*=" bi-"],
body.a11y-readable-font .bi {
    font-family: inherit !important;
}
body.a11y-readable-font i[class*="fa-"],
body.a11y-readable-font i.fa,
body.a11y-readable-font i.fas,
body.a11y-readable-font i.far,
body.a11y-readable-font i.fab,
body.a11y-readable-font i.fa-solid,
body.a11y-readable-font i.fa-regular,
body.a11y-readable-font i.fa-brands {
    font-family: 'Font Awesome 6 Free', 'Font Awesome 6 Brands', 'FontAwesome' !important;
}
body.a11y-readable-font i[class^="bi-"],
body.a11y-readable-font i[class*=" bi-"],
body.a11y-readable-font i.bi {
    font-family: 'bootstrap-icons' !important;
}

/* --- Highlight links (WCAG 1.4.1 Use of Color) -------------------- */
body.a11y-highlight-links a:not(.a11y-trigger):not(.a11y-statement-link):not(.a11y-skip-link):not(.a11y-panel-close):not(.a11y-btn):not(.a11y-toggle):not(.a11y-reset) {
    text-decoration: underline !important;
    outline: 2px solid #ffbf00 !important;
    outline-offset: 2px !important;
    background-color: rgba(255, 191, 0, 0.15) !important;
}

/* Backwards-compat with existing per-page rules */
body.underline-links a:not(.a11y-trigger):not(.a11y-statement-link):not(.a11y-skip-link) {
    text-decoration: underline !important;
}

/* --- Highlight headings ------------------------------------------ */
body.a11y-highlight-headings :is(h1, h2, h3, h4, h5, h6) {
    outline: 2px solid #1d4ed8 !important;
    outline-offset: 2px !important;
    background-color: rgba(29, 78, 216, 0.08) !important;
    padding: 2px 4px !important;
    border-radius: 3px !important;
}
/* Never highlight headings inside the widget itself */
body.a11y-highlight-headings .a11y-panel :is(h1, h2, h3, h4, h5, h6),
body.a11y-highlight-headings .a11y-trigger :is(h1, h2, h3, h4, h5, h6) {
    outline: none !important;
    background-color: transparent !important;
    padding: 0 !important;
}

/* --- Big cursor (WCAG 2.5.5 Target size) ------------------------- */
body.a11y-big-cursor,
body.a11y-big-cursor * {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'><path fill='%23000' stroke='%23fff' stroke-width='1.5' d='M5 2.5l14 9-6.5 1.5-3 6.5z'/></svg>") 0 0, auto !important;
}
body.a11y-big-cursor a,
body.a11y-big-cursor button,
body.a11y-big-cursor [role="button"],
body.a11y-big-cursor input,
body.a11y-big-cursor select,
body.a11y-big-cursor textarea,
body.a11y-big-cursor label,
body.a11y-big-cursor .a11y-trigger,
body.a11y-big-cursor .a11y-panel-close,
body.a11y-big-cursor .a11y-btn,
body.a11y-big-cursor .a11y-toggle,
body.a11y-big-cursor .a11y-reset {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'><path fill='%23ffbf00' stroke='%23000' stroke-width='1.5' d='M5 2.5l14 9-6.5 1.5-3 6.5z'/></svg>") 0 0, pointer !important;
}

/* --- Pause animations (WCAG 2.2.2, 2.3.3) ------------------------- */
body.a11y-pause-animations,
body.a11y-pause-animations *,
body.a11y-pause-animations *::before,
body.a11y-pause-animations *::after {
    animation-duration: 0.001s !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
}
body.a11y-pause-animations video,
body.a11y-pause-animations audio { /* JS pauses these; ensure no auto-restart styling */ }

/* --- Visible focus (WCAG 2.4.7 Focus Visible) -------------------- */
body.a11y-visible-focus a:focus,
body.a11y-visible-focus button:focus,
body.a11y-visible-focus input:focus,
body.a11y-visible-focus select:focus,
body.a11y-visible-focus textarea:focus,
body.a11y-visible-focus [tabindex]:focus,
body.a11y-visible-focus [role="button"]:focus,
body.a11y-visible-focus [role="link"]:focus,
body.a11y-visible-focus details:focus,
body.a11y-visible-focus summary:focus {
    outline: 4px solid #ffbf00 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 2px #000, 0 0 0 6px #ffbf00 !important;
    border-radius: 3px;
}

/* --- Color modes ------------------------------------------------- */
/* Monochrome (grayscale entire page) */
body.a11y-monochrome { filter: grayscale(100%) !important; }
/* Don't grayscale the widget itself (so toggles/colors stay legible) */
body.a11y-monochrome .a11y-trigger,
body.a11y-monochrome .a11y-panel,
body.a11y-monochrome .a11y-skip-link { filter: none !important; }

/* Inverted / negative contrast */
body.a11y-invert {
    filter: invert(100%) hue-rotate(180deg) !important;
    background: #fff !important;
}
body.a11y-invert img,
body.a11y-invert video,
body.a11y-invert canvas,
body.a11y-invert iframe,
body.a11y-invert svg,
body.a11y-invert [style*="background-image"] {
    filter: invert(100%) hue-rotate(180deg) !important;
}
/* Don't double-invert the widget */
body.a11y-invert .a11y-trigger,
body.a11y-invert .a11y-panel,
body.a11y-invert .a11y-skip-link {
    filter: invert(100%) hue-rotate(180deg) !important;
}

/* Dark mode (manual; less aggressive than invert) */
body.a11y-dark-mode {
    background: #111 !important;
    color: #f5f5f5 !important;
}
body.a11y-dark-mode :is(.card, .container, .login-container, .terms-container, .portal-container, main, section, article, .header, .navbar, .modal, .modal-content, .alert, .form-control, .form-select, input, select, textarea, table) {
    background: #1a1a1a !important;
    color: #f5f5f5 !important;
    border-color: #444 !important;
}
body.a11y-dark-mode :is(input, select, textarea) {
    background: #222 !important;
    color: #fff !important;
    border-color: #888 !important;
}
body.a11y-dark-mode :is(h1, h2, h3, h4, h5, h6, label, p, li, span, div, td, th) { color: inherit !important; }
body.a11y-dark-mode a { color: #ffd54f !important; }
/* Don't re-skin the widget */
body.a11y-dark-mode .a11y-trigger,
body.a11y-dark-mode .a11y-panel,
body.a11y-dark-mode .a11y-panel *,
body.a11y-dark-mode .a11y-skip-link {
    background: revert !important;
    color: revert !important;
    border-color: revert !important;
}
body.a11y-dark-mode .a11y-trigger { background: #111 !important; color: #fff !important; }
body.a11y-dark-mode .a11y-panel { background: #fff !important; color: #000 !important; }
body.a11y-dark-mode .a11y-panel * { color: #000 !important; }

/* --- High contrast baseline (in addition to per-page rules) ------ */
body.high-contrast .a11y-trigger { background: #000 !important; color: #fff !important; border-color: #fff !important; }
body.high-contrast .a11y-panel { background: #fff !important; color: #000 !important; border-color: #000 !important; }

/* High-contrast forced color scheme for unstyled or partially-styled pages */
body.high-contrast :is(p, span, div, td, th, li, label, h1, h2, h3, h4, h5, h6) {
    color: inherit;
}

/* --- Mutual exclusion guards ------------------------------------- */
/* If both invert and dark-mode are enabled, invert wins visually */
body.a11y-invert.a11y-dark-mode { background: #fff !important; }

/* --- Print: hide the widget -------------------------------------- */
@media print {
    .a11y-trigger,
    .a11y-panel,
    .a11y-skip-link,
    .a11y-reading-guide,
    .a11y-reading-mask-top,
    .a11y-reading-mask-bottom { display: none !important; }
}

/* --- Honor user reduced-motion preference ------------------------ */
@media (prefers-reduced-motion: reduce) {
    .a11y-trigger,
    .a11y-panel,
    .a11y-toggle-indicator,
    .a11y-toggle-indicator::after,
    .a11y-btn,
    .a11y-panel-close,
    .a11y-reset { transition: none !important; }
}
