/* ==========================================================================
   AccessibilityPlus FAB & Panel UI
   ========================================================================== */

/* Lock the body scroll when the panel is open */
body.aa-panel-active-lock { overflow: hidden !important; }

#aa-access-fab {
    position: fixed; bottom: 30px; width: 50px; height: 50px;
    background-color: #0052cc; color: #fff; /* Distinct Accessibility Blue */
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 999998; border: 2px solid #fff; padding: 0;
    transition: transform 0.2s ease, outline 0.2s ease;
}
#aa-access-fab:hover { transform: scale(1.1); }
#aa-access-fab:focus { outline: 3px solid #003d99; outline-offset: 4px; }
#aa-access-fab.pos-bottom-right { right: 30px; } 
#aa-access-fab.pos-bottom-left { left: 30px; }

/* FAB Tooltip */
#aa-access-fab::after {
    content: attr(aria-label); position: absolute; top: 50%; transform: translateY(-50%);
    background-color: #212529; color: #fff; padding: 8px 14px; border-radius: 4px;
    font-size: 16px; font-weight: 600; white-space: nowrap; opacity: 0; visibility: hidden;
    pointer-events: none; transition: opacity 0.2s ease, visibility 0.2s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3); font-family: "Open Sans", sans-serif;
}
#aa-access-fab:hover::after, #aa-access-fab:focus::after { opacity: 1; visibility: visible; }
#aa-access-fab.pos-bottom-right::after { right: calc(100% + 15px); }
#aa-access-fab.pos-bottom-left::after { left: calc(100% + 15px); }

/* Force FAB tooltip closed via suppression class */
#aa-access-fab.aa-hide-tooltip::after {
    opacity: 0 !important;
    visibility: hidden !important;
}

@keyframes aaHeartbeat {
    0% { transform: scale(1); } 15% { transform: scale(1.15); } 30% { transform: scale(1); }
    45% { transform: scale(1.15); } 60% { transform: scale(1); }
}
.aa-heartbeat { animation: aaHeartbeat 3s infinite; }

#aa-access-panel {
    position: fixed; 
    top: 0; 
    bottom: 0; /* Legacy mobile fallback to pin to physical visible bottom */
    width: 320px; 
    max-width: 100vw; 
    height: 100vh; /* Standard desktop fallback */
    height: 100dvh; /* Modern mobile fix (iOS 15.4+) calculating dynamic visible viewport */
    background: #fff; box-shadow: 0 0 20px rgba(0,0,0,0.3); z-index: 999999;
    box-sizing: border-box; display: flex; flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1); font-family: "Open Sans", sans-serif;
}
#aa-access-panel.pos-bottom-right { right: 0; transform: translateX(100%); }
#aa-access-panel.pos-bottom-left { left: 0; transform: translateX(-100%); }
#aa-access-panel.aa-open { transform: translateX(0); }

.aa-panel-header {
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid #ececec; padding: 12px 16px; background-color: #f8f9fa;
}
.aa-panel-header h2 { margin: 0; font-size: 1.1rem; color: #222; font-family: "Noto Serif", serif; font-weight: 600; }
.aa-close-btn { background: none; border: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: #666; padding: 0; }
.aa-close-btn:hover, .aa-close-btn:focus { color: #000; outline: none; }

/* Strict overflow control to prevent any horizontal scrolling */
.aa-panel-body { padding: 16px; overflow-y: auto; overflow-x: hidden; flex-grow: 1; box-sizing: border-box; }
.aa-tool-group { margin-bottom: 20px; }
.aa-tool-group h3 { font-size: 0.95rem; margin-bottom: 10px; color: #222; font-weight: 700; font-family: "Noto Serif", serif; }

/* Panel Tooltips: Contained and aligned to prevent edge clipping */
.aa-tooltip-target { position: relative; }
#aa-access-panel .aa-tooltip-target::after {
    content: attr(aria-label); 
    position: absolute; 
    bottom: calc(100% + 6px); 
    left: 50%;
    transform: translateX(-50%);
    background-color: #212529; 
    color: #fff; 
    padding: 6px 10px;
    border-radius: 4px; 
    font-size: 11px; 
    font-weight: 600; 
    width: max-content;
    max-width: 220px;
    white-space: normal;
    text-align: center;
    opacity: 0;
    visibility: hidden; 
    pointer-events: none; 
    transition: opacity 0.2s ease, visibility 0.2s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3); 
    z-index: 10000;
}

/* Shift right-column grid tooltips so they never clip against the panel edge */
#aa-access-panel .aa-tools-grid button:nth-child(even)::after {
    left: auto;
    right: 0;
    transform: none;
}

#aa-access-panel .aa-tooltip-target:hover::after, #aa-access-panel .aa-tooltip-target:focus::after { opacity: 1; visibility: visible; }

/* Footer buttons tooltips pop upward safely */
#aa-access-panel .aa-panel-footer .aa-tooltip-target::after { 
    bottom: calc(100% + 8px); 
    top: auto; 
    left: 50%;
    transform: translateX(-50%);
}

.aagrid-paginator .aa-tooltip-target::after { top: auto; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%); }
.aa-tooltip-wrapper { display: inline-block; position: relative; }

/* Redesigned Text Stepper */
.aa-stepper { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.aa-stepper button { 
    width: 44px; height: 40px; background: #e9ecef; border: 1px solid #ced4da; 
    border-radius: 4px; cursor: pointer; font-size: 1.4rem; font-weight: bold; 
    color: #212529; display: flex; align-items: center; justify-content: center; line-height: 1;
}
#aa-txt-dec { padding-bottom: 10px; }
.aa-stepper button:hover, .aa-stepper button:focus { background-color: #dde0e3; color: #000; outline: none; }
.aa-readonly-badge {
    flex-grow: 1; height: 40px; background: #f8f9fa; border: 1px dashed #ccc; border-radius: 4px;
    display: flex; align-items: center; justify-content: center; font-weight: 700; color: #666; 
    font-size: 1rem; font-family: monospace;
}

/* Tools Grid */
.aa-tools-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.aa-grid-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: #e9ecef; border: 2px solid #ced4da; border-radius: 6px; padding: 10px 4px;
    cursor: pointer; color: #212529; transition: all 0.2s ease; position: relative;
}
.aa-grid-btn svg { width: 22px; height: 22px; margin-bottom: 6px; fill: currentColor; }
.aa-grid-btn span { font-size: 0.8rem; font-weight: 600; text-align: center; line-height: 1.2; }
.aa-grid-btn:hover, .aa-grid-btn:focus { background: #dde0e3; border-color: #adb5bd; outline: none; }
.aa-grid-btn.active { background: #fff; color: #0052cc; border-color: #0052cc; }
.aa-grid-btn.active::before {
    content: '✔'; position: absolute; top: 4px; right: 4px; background: #0052cc;
    color: #fff; font-size: 10px; font-weight: bold; width: 16px; height: 16px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}

/* Position Row */
.aa-button-row { display: flex; gap: 10px; }
.aa-pos-btn {
    flex: 1; padding: 10px; background: #e9ecef; color: #212529; border: 2px solid #ced4da; 
    border-radius: 4px; cursor: pointer; font-size: 0.9rem; font-weight: 600; 
}
.aa-pos-btn:hover, .aa-pos-btn:focus { background: #dde0e3; outline: none; }
.aa-pos-btn.active { background: #fff; color: #0052cc; border-color: #0052cc; }

/* Split Sticky Footer */
.aa-panel-footer {
    position: sticky; bottom: 0; background: #fff; padding: 16px;
    border-top: 1px solid #ececec; box-shadow: 0 -4px 10px rgba(0,0,0,0.05); display: flex; gap: 12px;
}
.aa-reset-btn { 
    flex: 1; padding: 12px; background: #f8f9fa; color: #495057; border: 2px solid #ced4da; 
    border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 0.9rem; transition: all 0.2s ease;
}
.aa-reset-btn:hover, .aa-reset-btn:focus { background: #e2e6ea; color: #212529; border-color: #dae0e5; outline: none; }
.aa-close-panel-btn {
    flex: 2; padding: 12px; background: #0052cc; color: #fff; font-weight: bold;
    font-size: 1rem; border-radius: 4px; border: none; cursor: pointer; transition: background 0.2s ease;
}
.aa-close-panel-btn:hover, .aa-close-panel-btn:focus {
    background: #003d99; outline: 2px solid #000; outline-offset: 2px;
}

/* ==========================================================================
   Accessibility CSS Guardrails & Overrides (Scaling up to 200%)
   ========================================================================== */
html.aa-text-110 { font-size: 110% !important; }
html.aa-text-120 { font-size: 120% !important; }
html.aa-text-130 { font-size: 130% !important; }
html.aa-text-140 { font-size: 140% !important; }
html.aa-text-150 { font-size: 150% !important; }
html.aa-text-160 { font-size: 160% !important; }
html.aa-text-170 { font-size: 170% !important; }
html.aa-text-180 { font-size: 180% !important; }
html.aa-text-190 { font-size: 190% !important; }
html.aa-text-200 { font-size: 200% !important; }

/* Scale Custom Tooltips to match */
html.aa-text-110 #aa-access-panel .aa-tooltip-target::after { font-size: 13.2px !important; }
html.aa-text-120 #aa-access-panel .aa-tooltip-target::after { font-size: 14.4px !important; }
html.aa-text-130 #aa-access-panel .aa-tooltip-target::after { font-size: 15.6px !important; }
html.aa-text-140 #aa-access-panel .aa-tooltip-target::after { font-size: 16.8px !important; }
html.aa-text-150 #aa-access-panel .aa-tooltip-target::after { font-size: 18.0px !important; }
html.aa-text-160 #aa-access-panel .aa-tooltip-target::after { font-size: 19.2px !important; }
html.aa-text-170 #aa-access-panel .aa-tooltip-target::after { font-size: 20.4px !important; }
html.aa-text-180 #aa-access-panel .aa-tooltip-target::after { font-size: 21.6px !important; }
html.aa-text-190 #aa-access-panel .aa-tooltip-target::after { font-size: 22.8px !important; }
html.aa-text-200 #aa-access-panel .aa-tooltip-target::after { font-size: 24.0px !important; }

html.aa-text-110 #aa-access-fab::after { font-size: 17.6px !important; }
html.aa-text-120 #aa-access-fab::after { font-size: 19.2px !important; }
html.aa-text-130 #aa-access-fab::after { font-size: 20.8px !important; }
html.aa-text-140 #aa-access-fab::after { font-size: 22.4px !important; }
html.aa-text-150 #aa-access-fab::after { font-size: 24.0px !important; }
html.aa-text-160 #aa-access-fab::after { font-size: 25.6px !important; }
html.aa-text-170 #aa-access-fab::after { font-size: 27.2px !important; }
html.aa-text-180 #aa-access-fab::after { font-size: 28.8px !important; }
html.aa-text-190 #aa-access-fab::after { font-size: 30.4px !important; }
html.aa-text-200 #aa-access-fab::after { font-size: 32.0px !important; }

/* Tabulator Grid explicitly forced wildcard scaling */
html.aa-text-110 .tabulator-cell, html.aa-text-110 .tabulator-cell *, html.aa-text-110 .tabulator-col-title, html.aa-text-110 .tabulator-col-title *, html.aa-text-110 .tabulator-header-filter * { font-size: 15.4px !important; }
html.aa-text-120 .tabulator-cell, html.aa-text-120 .tabulator-cell *, html.aa-text-120 .tabulator-col-title, html.aa-text-120 .tabulator-col-title *, html.aa-text-120 .tabulator-header-filter * { font-size: 16.8px !important; }
html.aa-text-130 .tabulator-cell, html.aa-text-130 .tabulator-cell *, html.aa-text-130 .tabulator-col-title, html.aa-text-130 .tabulator-col-title *, html.aa-text-130 .tabulator-header-filter * { font-size: 18.2px !important; }
html.aa-text-140 .tabulator-cell, html.aa-text-140 .tabulator-cell *, html.aa-text-140 .tabulator-col-title, html.aa-text-140 .tabulator-col-title *, html.aa-text-140 .tabulator-header-filter * { font-size: 19.6px !important; }
html.aa-text-150 .tabulator-cell, html.aa-text-150 .tabulator-cell *, html.aa-text-150 .tabulator-col-title, html.aa-text-150 .tabulator-col-title *, html.aa-text-150 .tabulator-header-filter * { font-size: 21.0px !important; }
html.aa-text-160 .tabulator-cell, html.aa-text-160 .tabulator-cell *, html.aa-text-160 .tabulator-col-title, html.aa-text-160 .tabulator-col-title *, html.aa-text-160 .tabulator-header-filter * { font-size: 22.4px !important; }
html.aa-text-170 .tabulator-cell, html.aa-text-170 .tabulator-cell *, html.aa-text-170 .tabulator-col-title, html.aa-text-170 .tabulator-col-title *, html.aa-text-170 .tabulator-header-filter * { font-size: 23.8px !important; }
html.aa-text-180 .tabulator-cell, html.aa-text-180 .tabulator-cell *, html.aa-text-180 .tabulator-col-title, html.aa-text-180 .tabulator-col-title *, html.aa-text-180 .tabulator-header-filter * { font-size: 25.2px !important; }
html.aa-text-190 .tabulator-cell, html.aa-text-190 .tabulator-cell *, html.aa-text-190 .tabulator-col-title, html.aa-text-190 .tabulator-col-title *, html.aa-text-190 .tabulator-header-filter * { font-size: 26.6px !important; }
html.aa-text-200 .tabulator-cell, html.aa-text-200 .tabulator-cell *, html.aa-text-200 .tabulator-col-title, html.aa-text-200 .tabulator-col-title *, html.aa-text-200 .tabulator-header-filter * { font-size: 28.0px !important; }

/* aaGrid Custom Paginator Footer explicitly forced wildcard scaling + Specific Spinner Input override */
html.aa-text-110 .aagrid-paginator, html.aa-text-110 .aagrid-paginator *, html.aa-text-110 .aagrid-paginator input, html.aa-text-110 .aagrid-paginator select, html.aa-text-110 #aagrid-page-input { font-size: 15.4px !important; }
html.aa-text-120 .aagrid-paginator, html.aa-text-120 .aagrid-paginator *, html.aa-text-120 .aagrid-paginator input, html.aa-text-120 .aagrid-paginator select, html.aa-text-120 #aagrid-page-input { font-size: 16.8px !important; }
html.aa-text-130 .aagrid-paginator, html.aa-text-130 .aagrid-paginator *, html.aa-text-130 .aagrid-paginator input, html.aa-text-130 .aagrid-paginator select, html.aa-text-130 #aagrid-page-input { font-size: 18.2px !important; }
html.aa-text-140 .aagrid-paginator, html.aa-text-140 .aagrid-paginator *, html.aa-text-140 .aagrid-paginator input, html.aa-text-140 .aagrid-paginator select, html.aa-text-140 #aagrid-page-input { font-size: 19.6px !important; }
html.aa-text-150 .aagrid-paginator, html.aa-text-150 .aagrid-paginator *, html.aa-text-150 .aagrid-paginator input, html.aa-text-150 .aagrid-paginator select, html.aa-text-150 #aagrid-page-input { font-size: 21.0px !important; }
html.aa-text-160 .aagrid-paginator, html.aa-text-160 .aagrid-paginator *, html.aa-text-160 .aagrid-paginator input, html.aa-text-160 .aagrid-paginator select, html.aa-text-160 #aagrid-page-input { font-size: 22.4px !important; }
html.aa-text-170 .aagrid-paginator, html.aa-text-170 .aagrid-paginator *, html.aa-text-170 .aagrid-paginator input, html.aa-text-170 .aagrid-paginator select, html.aa-text-170 #aagrid-page-input { font-size: 23.8px !important; }
html.aa-text-180 .aagrid-paginator, html.aa-text-180 .aagrid-paginator *, html.aa-text-180 .aagrid-paginator input, html.aa-text-180 .aagrid-paginator select, html.aa-text-180 #aagrid-page-input { font-size: 25.2px !important; }
html.aa-text-190 .aagrid-paginator, html.aa-text-190 .aagrid-paginator *, html.aa-text-190 .aagrid-paginator input, html.aa-text-190 .aagrid-paginator select, html.aa-text-190 #aagrid-page-input { font-size: 26.6px !important; }
html.aa-text-200 .aagrid-paginator, html.aa-text-200 .aagrid-paginator *, html.aa-text-200 .aagrid-paginator input, html.aa-text-200 .aagrid-paginator select, html.aa-text-200 #aagrid-page-input { font-size: 28.0px !important; }

html[class*="aa-text-"] .aagrid-paginator, html[class*="aa-text-"] .aagrid-paginator .aagrid-paginator-center, html[class*="aa-text-"] .aagrid-paginator .aagrid-paginator-right { height: auto !important; flex-wrap: wrap; }
html[class*="aa-text-"] .aagrid-paginator input, html[class*="aa-text-"] .aagrid-paginator select, html[class*="aa-text-"] .aagrid-paginator button { height: auto !important; min-height: 30px; padding-top: 4px; padding-bottom: 4px; }

/* aaMultiViewer text scaling */
html.aa-text-110 .aamv-header *, html.aa-text-110 .aamv-viewer-header *, html.aa-text-110 .aamv-toolbar *, html.aa-text-110 .openseadragon-toolbar *, html.aa-text-110 .aamv-viewer-title, html.aa-text-110 .aamv-viewer-title *, html.aa-text-110 .aamv-file-name, html.aa-text-110 .aamv-file-name * { font-size: 15.4px !important; }
html.aa-text-120 .aamv-header *, html.aa-text-120 .aamv-viewer-header *, html.aa-text-120 .aamv-toolbar *, html.aa-text-120 .openseadragon-toolbar *, html.aa-text-120 .aamv-viewer-title, html.aa-text-120 .aamv-viewer-title *, html.aa-text-120 .aamv-file-name, html.aa-text-120 .aamv-file-name * { font-size: 16.8px !important; }
html.aa-text-130 .aamv-header *, html.aa-text-130 .aamv-viewer-header *, html.aa-text-130 .aamv-toolbar *, html.aa-text-130 .openseadragon-toolbar *, html.aa-text-130 .aamv-viewer-title, html.aa-text-130 .aamv-viewer-title *, html.aa-text-130 .aamv-file-name, html.aa-text-130 .aamv-file-name * { font-size: 18.2px !important; }
html.aa-text-140 .aamv-header *, html.aa-text-140 .aamv-viewer-header *, html.aa-text-140 .aamv-toolbar *, html.aa-text-140 .openseadragon-toolbar *, html.aa-text-140 .aamv-viewer-title, html.aa-text-140 .aamv-viewer-title *, html.aa-text-140 .aamv-file-name, html.aa-text-140 .aamv-file-name * { font-size: 19.6px !important; }
html.aa-text-150 .aamv-header *, html.aa-text-150 .aamv-viewer-header *, html.aa-text-150 .aamv-toolbar *, html.aa-text-150 .openseadragon-toolbar *, html.aa-text-150 .aamv-viewer-title, html.aa-text-150 .aamv-viewer-title *, html.aa-text-150 .aamv-file-name, html.aa-text-150 .aamv-file-name * { font-size: 21.0px !important; }
html.aa-text-160 .aamv-header *, html.aa-text-160 .aamv-viewer-header *, html.aa-text-160 .aamv-toolbar *, html.aa-text-160 .openseadragon-toolbar *, html.aa-text-160 .aamv-viewer-title, html.aa-text-160 .aamv-viewer-title *, html.aa-text-160 .aamv-file-name, html.aa-text-160 .aamv-file-name * { font-size: 22.4px !important; }
html.aa-text-170 .aamv-header *, html.aa-text-170 .aamv-viewer-header *, html.aa-text-170 .aamv-toolbar *, html.aa-text-170 .openseadragon-toolbar *, html.aa-text-170 .aamv-viewer-title, html.aa-text-170 .aamv-viewer-title *, html.aa-text-170 .aamv-file-name, html.aa-text-170 .aamv-file-name * { font-size: 23.8px !important; }
html.aa-text-180 .aamv-header *, html.aa-text-180 .aamv-viewer-header *, html.aa-text-180 .aamv-toolbar *, html.aa-text-180 .openseadragon-toolbar *, html.aa-text-180 .aamv-viewer-title, html.aa-text-180 .aamv-viewer-title *, html.aa-text-180 .aamv-file-name, html.aa-text-180 .aamv-file-name * { font-size: 25.2px !important; }
html.aa-text-190 .aamv-header *, html.aa-text-190 .aamv-viewer-header *, html.aa-text-190 .aamv-toolbar *, html.aa-text-190 .openseadragon-toolbar *, html.aa-text-190 .aamv-viewer-title, html.aa-text-190 .aamv-viewer-title *, html.aa-text-190 .aamv-file-name, html.aa-text-190 .aamv-file-name * { font-size: 26.6px !important; }
html.aa-text-200 .aamv-header *, html.aa-text-200 .aamv-viewer-header *, html.aa-text-200 .aamv-toolbar *, html.aa-text-200 .openseadragon-toolbar *, html.aa-text-200 .aamv-viewer-title, html.aa-text-200 .aamv-viewer-title *, html.aa-text-200 .aamv-file-name, html.aa-text-200 .aamv-file-name * { font-size: 28.0px !important; }

/* Secondary headers keep flex-wrap to prevent clipping */
html[class*="aa-text-"] .aamv-viewer-header, html[class*="aa-text-"] .aamv-toolbar, html[class*="aa-text-"] .openseadragon-toolbar, html[class*="aa-text-"] .aamv-title-container {
    height: auto !important; min-height: 40px; padding-top: 8px; padding-bottom: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}

/* Strictly enforce CSS Grid on the main header during scaling so buttons stay anchored */
html[class*="aa-text-"] .aamv-header {
    height: auto !important; 
    min-height: 47px !important; 
    padding-top: 8px !important; 
    padding-bottom: 8px !important; 
    display: grid !important; 
    grid-template-columns: 1fr minmax(0, 50%) 1fr !important;
    align-items: center !important;
}

/* Contrast Modes */
html.aa-contrast-high { filter: contrast(120%) saturate(120%); background: #000; color: #fff; }
html.aa-contrast-invert { filter: invert(1) hue-rotate(180deg); background: #000; }
html.aa-contrast-grayscale { filter: grayscale(100%); }

html.aa-contrast-invert img, html.aa-contrast-invert picture, html.aa-contrast-invert video, html.aa-contrast-invert canvas, html.aa-contrast-invert .pv-hero-img, html.aa-contrast-invert .google-viewer-iframe {
    filter: invert(1) hue-rotate(180deg) !important;
}

html.aa-links-highlight a { background-color: #ffeb3b !important; color: #000 !important; text-decoration: underline !important; text-decoration-thickness: 2px !important; }

@import url('https://fonts.cdnfonts.com/css/opendyslexic');
html.aa-font-dyslexia p, html.aa-font-dyslexia h1, html.aa-font-dyslexia h2, html.aa-font-dyslexia h3, html.aa-font-dyslexia h4, html.aa-font-dyslexia h5, html.aa-font-dyslexia h6, html.aa-font-dyslexia li, html.aa-font-dyslexia span, html.aa-font-dyslexia a, html.aa-font-dyslexia .tabulator-cell, html.aa-font-dyslexia .tooltip {
    font-family: 'OpenDyslexic', sans-serif !important;
}

html.aa-font-dyslexia .fa, html.aa-font-dyslexia .fas, html.aa-font-dyslexia .material-icons, html.aa-font-dyslexia [class*="icon"], html.aa-font-dyslexia .openseadragon-container, html.aa-font-dyslexia .splide__arrow, html.aa-font-dyslexia .splide__pagination, html.aa-font-dyslexia .aamv-viewer-container {
    font-family: inherit !important;
}