/* ============================================================
   508 / WCAG 2.2 Accessibility Overrides
   Applied via body classes toggled by the AccessibilityPanel
   ============================================================ */

/* ---------- Skip-to-content link ---------- */
.skip-to-content {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 10000;
    background: var(--rz-primary);
    color: #fff;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 8px 0;
}

.skip-to-content:focus {
    position: fixed;
    left: 0;
    top: 0;
    width: auto;
    height: auto;
    overflow: visible;
    outline: 3px solid #ffcc00;
    outline-offset: 2px;
}

/* ---------- Accessibility toolbar ---------- */
.a11y-toggle-btn {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 9999;
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    border: 2px solid var(--rz-base-700, #555);
    background: var(--rz-base-background-color, #fff);
    color: var(--rz-text-color, #333);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.a11y-toggle-btn:hover,
.a11y-toggle-btn:focus-visible {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    outline: 3px solid var(--rz-primary, #1976d2);
    outline-offset: 2px;
}

.a11y-panel {
    position: fixed;
    bottom: 4rem;
    right: 1rem;
    z-index: 9998;
    background: var(--rz-base-background-color, #fff);
    color: var(--rz-text-color, #333);
    border: 1px solid var(--rz-base-400, #ccc);
    border-radius: 12px;
    padding: 1rem;
    width: 280px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.a11y-panel-title {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.a11y-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--rz-base-200, #eee);
}

.a11y-option:last-child {
    border-bottom: none;
}

.a11y-option-label {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.a11y-font-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.a11y-font-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border: 1px solid var(--rz-base-400, #ccc);
    border-radius: 6px;
    background: var(--rz-base-background-color, #fff);
    color: var(--rz-text-color, #333);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    transition: background 0.15s ease;
}

.a11y-font-btn:hover,
.a11y-font-btn:focus-visible {
    background: var(--rz-base-200, #eee);
    outline: 2px solid var(--rz-primary, #1976d2);
    outline-offset: 1px;
}

.a11y-font-size-label {
    font-size: 0.75rem;
    min-width: 36px;
    text-align: center;
    font-weight: 600;
}

.a11y-reset-btn {
    margin-top: 0.5rem;
    width: 100%;
    padding: 0.4rem;
    border: 1px solid var(--rz-base-400, #ccc);
    border-radius: 6px;
    background: transparent;
    color: var(--rz-text-color, #333);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    transition: background 0.15s ease;
}

.a11y-reset-btn:hover,
.a11y-reset-btn:focus-visible {
    background: var(--rz-base-200, #eee);
    outline: 2px solid var(--rz-primary, #1976d2);
    outline-offset: 1px;
}

/* ---------- High Contrast Mode ---------- */
body.a11y-high-contrast {
    --rz-text-color: #000 !important;
    --rz-text-secondary-color: #222 !important;
    --rz-base-background-color: #fff !important;
    --rz-body-background-color: #fff !important;
}

body.a11y-high-contrast *:not(.rz-icon):not(.material-icons) {
    border-color: #000 !important;
}

body.a11y-high-contrast a,
body.a11y-high-contrast .rz-link {
    color: #0000ee !important;
    text-decoration: underline !important;
}

body.a11y-high-contrast .rz-button:not(.rz-button-icon-only) {
    border: 2px solid #000 !important;
}

body.a11y-high-contrast .rz-badge {
    border: 1px solid #000 !important;
}

/* ---------- Focus Highlight Mode ---------- */
body.a11y-focus-highlight *:focus-visible {
    outline: 3px solid #ff6600 !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 5px rgba(255, 102, 0, 0.25) !important;
}

body.a11y-focus-highlight .rz-button:focus-visible,
body.a11y-focus-highlight .rz-textbox:focus-visible,
body.a11y-focus-highlight .rz-dropdown:focus-visible,
body.a11y-focus-highlight .rz-inputtext:focus-visible,
body.a11y-focus-highlight input:focus-visible,
body.a11y-focus-highlight select:focus-visible,
body.a11y-focus-highlight textarea:focus-visible {
    outline: 3px solid #ff6600 !important;
    outline-offset: 2px !important;
}

/* ---------- Large Text / Font Scaling ---------- */
body.a11y-font-scale-110 {
    font-size: calc(var(--rz-body-font-size, 14px) * 1.1) !important;
}

body.a11y-font-scale-120 {
    font-size: calc(var(--rz-body-font-size, 14px) * 1.2) !important;
}

body.a11y-font-scale-130 {
    font-size: calc(var(--rz-body-font-size, 14px) * 1.3) !important;
}

body.a11y-font-scale-140 {
    font-size: calc(var(--rz-body-font-size, 14px) * 1.4) !important;
}

body.a11y-font-scale-150 {
    font-size: calc(var(--rz-body-font-size, 14px) * 1.5) !important;
}

/* ---------- Reduced Motion ---------- */
body.a11y-reduced-motion,
body.a11y-reduced-motion * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* ---------- Text Spacing ---------- */
body.a11y-text-spacing,
body.a11y-text-spacing * {
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

/* ---------- Line Height ---------- */
body.a11y-line-height-1-8 {
    line-height: 1.8 !important;
}

body.a11y-line-height-1-8 p,
body.a11y-line-height-1-8 li,
body.a11y-line-height-1-8 td,
body.a11y-line-height-1-8 th,
body.a11y-line-height-1-8 span,
body.a11y-line-height-1-8 div,
body.a11y-line-height-1-8 label {
    line-height: 1.8 !important;
}

body.a11y-line-height-2-0 {
    line-height: 2.0 !important;
}

body.a11y-line-height-2-0 p,
body.a11y-line-height-2-0 li,
body.a11y-line-height-2-0 td,
body.a11y-line-height-2-0 th,
body.a11y-line-height-2-0 span,
body.a11y-line-height-2-0 div,
body.a11y-line-height-2-0 label {
    line-height: 2.0 !important;
}

/* ---------- Hide Images ---------- */
body.a11y-hide-images img,
body.a11y-hide-images svg:not(.rz-icon):not(.material-icons),
body.a11y-hide-images picture,
body.a11y-hide-images video,
body.a11y-hide-images [role="img"] {
    visibility: hidden !important;
}

/* ---------- Large Cursor ---------- */
body.a11y-large-cursor,
body.a11y-large-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M3 0L3 28L9 22L14 32L18 30L13 20L20 20Z' fill='black' stroke='white' stroke-width='1.5'/%3E%3C/svg%3E") 3 0, default !important;
}

body.a11y-large-cursor a,
body.a11y-large-cursor button,
body.a11y-large-cursor [role="button"],
body.a11y-large-cursor input[type="submit"],
body.a11y-large-cursor .rz-button {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='10' r='9' fill='none' stroke='black' stroke-width='2.5'/%3E%3Cline x1='16' y1='19' x2='16' y2='30' stroke='black' stroke-width='2.5'/%3E%3Cline x1='9' y1='10' x2='23' y2='10' stroke='black' stroke-width='2.5'/%3E%3Cline x1='16' y1='3' x2='16' y2='17' stroke='black' stroke-width='2.5'/%3E%3C/svg%3E") 16 10, pointer !important;
}

/* ---------- Highlight Tooltips ---------- */
body.a11y-tooltips [title]:not([title=""]) {
    border-bottom: 2px dashed var(--rz-primary, #1976d2) !important;
    position: relative;
}

body.a11y-tooltips [title]:not([title=""]):hover::after,
body.a11y-tooltips [title]:not([title=""]):focus::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    z-index: 10000;
    pointer-events: none;
    max-width: 300px;
    white-space: normal;
    word-break: break-word;
    box-sizing: border-box;
}

/* ---------- Page Structure (Heading Outlines) ---------- */
body.a11y-page-structure h1,
body.a11y-page-structure h2,
body.a11y-page-structure h3,
body.a11y-page-structure h4,
body.a11y-page-structure h5,
body.a11y-page-structure h6,
body.a11y-page-structure [role="heading"],
body.a11y-page-structure .rz-text-h1,
body.a11y-page-structure .rz-text-h2,
body.a11y-page-structure .rz-text-h3,
body.a11y-page-structure .rz-text-h4,
body.a11y-page-structure .rz-text-h5,
body.a11y-page-structure .rz-text-h6 {
    outline: 2px dashed #1976d2 !important;
    outline-offset: 4px !important;
    position: relative;
}

body.a11y-page-structure h1::before,
body.a11y-page-structure .rz-text-h1::before { content: "H1 " !important; font-size: 0.65rem; font-weight: 700; color: #fff; background: #1976d2; padding: 1px 5px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
body.a11y-page-structure h2::before,
body.a11y-page-structure .rz-text-h2::before { content: "H2 " !important; font-size: 0.65rem; font-weight: 700; color: #fff; background: #1976d2; padding: 1px 5px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
body.a11y-page-structure h3::before,
body.a11y-page-structure .rz-text-h3::before { content: "H3 " !important; font-size: 0.65rem; font-weight: 700; color: #fff; background: #1976d2; padding: 1px 5px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
body.a11y-page-structure h4::before,
body.a11y-page-structure .rz-text-h4::before { content: "H4 " !important; font-size: 0.65rem; font-weight: 700; color: #fff; background: #1976d2; padding: 1px 5px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
body.a11y-page-structure h5::before,
body.a11y-page-structure .rz-text-h5::before { content: "H5 " !important; font-size: 0.65rem; font-weight: 700; color: #fff; background: #1976d2; padding: 1px 5px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
body.a11y-page-structure h6::before,
body.a11y-page-structure .rz-text-h6::before { content: "H6 " !important; font-size: 0.65rem; font-weight: 700; color: #fff; background: #1976d2; padding: 1px 5px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

body.a11y-page-structure nav,
body.a11y-page-structure [role="navigation"] {
    outline: 2px dashed #e65100 !important;
    outline-offset: 2px !important;
}

body.a11y-page-structure main,
body.a11y-page-structure [role="main"] {
    outline: 2px dashed #2e7d32 !important;
    outline-offset: 2px !important;
}

/* ---------- Text Align ---------- */
body.a11y-text-align-left,
body.a11y-text-align-left p,
body.a11y-text-align-left li,
body.a11y-text-align-left td,
body.a11y-text-align-left th,
body.a11y-text-align-left span,
body.a11y-text-align-left div,
body.a11y-text-align-left label {
    text-align: left !important;
}

/* ---------- Screen Reader Live Region ---------- */
.a11y-sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ---------- Mobile-Responsive Layout ---------- */
@media (max-width: 768px) {
    /* Header: stack columns vertically */
    .rz-header .rz-row {
        flex-wrap: wrap !important;
    }

    .rz-header .rz-row > .rz-col,
    .rz-header .rz-row > [class*="rz-col-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Collapse search bar on small screens */
    .rz-header .rz-row > .rz-col:nth-child(2) {
        order: 3;
        padding: 0.25rem 0.5rem;
    }

    /* Profile & theme row */
    .rz-header .rz-row > .rz-col:nth-child(3) {
        order: 2;
        justify-content: flex-end;
    }

    .rz-header .rz-row > .rz-col:nth-child(3) .rz-stack {
        flex-wrap: wrap;
        gap: 0.25rem !important;
    }

    /* Hide theme dropdown and appearance toggle on mobile */
    .rz-header [name="ThemeDropDown"],
    .rz-header .rz-appearance-toggle {
        display: none !important;
    }

    /* Hide user name text, keep icon */
    .rz-header .rz-profile-menu .rz-stack span:first-child {
        display: none;
    }

    /* Sidebar overlay on mobile */
    .rz-sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100% !important;
        z-index: 1100 !important;
        transition: transform 0.25s ease !important;
    }

    /* Sidebar hidden when collapsed on mobile — class toggled by JS */
    .rz-sidebar:not(.rz-sidebar-expanded) {
        transform: translateX(-100%) !important;
    }

    /* Body takes full width when sidebar collapsed */
    .rz-body,
    .rz-header {
        grid-column: 1 / -1 !important;
    }

    /* Ensure content doesn't overflow */
    .rz-body .rz-row {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }

    /* Larger touch targets for interactive elements */
    .rz-button {
        min-height: 44px;
        min-width: 44px;
    }

    .rz-panelmenu-header > a,
    .rz-menuitem-link {
        padding: 0.75rem 1rem !important;
        min-height: 44px;
    }

    /* Accessibility toggle button — move above bottom to avoid conflict with nav */
    .a11y-toggle-btn {
        bottom: 4.5rem;
    }

    /* Make dialogs full-width on mobile */
    .rz-dialog {
        width: 95vw !important;
        max-width: 95vw !important;
        margin: 0.5rem auto !important;
    }

    .rz-dialog-content {
        max-height: 75vh !important;
        overflow-y: auto !important;
    }

    /* Tables: horizontal scroll */
    .rz-datatable-wrapper,
    .rz-grid,
    table {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Accessibility panel: full width on mobile */
    .a11y-panel {
        width: calc(100vw - 2rem) !important;
        right: 1rem !important;
        left: 1rem !important;
        bottom: 5.5rem !important;
        max-height: 60vh;
        overflow-y: auto;
    }
}
