/* ==========================================================================
   GLOBALITY ACCESSIBILITY WIDGET — Premium CSS
   A floating accessibility menu for inclusive design.
   ========================================================================== */

/* ── FAB (Floating Action Button) ── */
.a11y-fab {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9998;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 50%, #06B6D4 100%);
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 4px 20px rgba(79, 70, 229, 0.35),
        0 0 0 0 rgba(79, 70, 229, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: a11yPulse 3s ease-in-out infinite;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.a11y-fab:hover {
    transform: scale(1.12);
    box-shadow:
        0 8px 30px rgba(79, 70, 229, 0.45),
        0 0 0 4px rgba(79, 70, 229, 0.15);
    animation: none;
}

.a11y-fab:active {
    transform: scale(0.95);
}

.a11y-fab.active {
    animation: none;
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.35);
}

.a11y-fab.active i {
    transform: rotate(180deg);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.a11y-fab i {
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Badge counter on FAB */
.a11y-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #EF4444;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
    animation: a11yBadgePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-family: 'Inter', sans-serif;
}

/* ── PANEL ── */
.a11y-panel {
    position: fixed;
    bottom: 90px;
    left: 24px;
    z-index: 9997;
    width: 380px;
    max-height: 85vh;
    border-radius: 20px;
    background: rgba(var(--surface-rgb, 255, 255, 255), 0.88);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border: 1px solid rgba(var(--text-rgb, 15, 23, 42), 0.08);
    box-shadow:
        0 25px 60px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
    transition:
        opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
        visibility 0.35s;
}

.a11y-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    animation: a11ySlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.a11y-panel.closing {
    animation: a11ySlideDown 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Panel Header */
.a11y-panel-header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(var(--text-rgb, 15, 23, 42), 0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: rgba(var(--surface-rgb, 255, 255, 255), 0.5);
}

.a11y-panel-header h3 {
    color: var(--text-main, #0F172A);
}

.a11y-close {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: none;
    background: rgba(var(--text-rgb, 15, 23, 42), 0.05);
    color: var(--text-muted, #64748B);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.a11y-close:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #EF4444;
    transform: rotate(90deg);
}

/* Panel Body */
.a11y-panel-body {
    padding: 16px 20px 20px;
    overflow-y: auto;
    flex: 1;
    overscroll-behavior: contain;
}

/* Sections */
.a11y-section {
    margin-bottom: 20px;
}

.a11y-section:last-of-type {
    margin-bottom: 16px;
}

.a11y-section-title {
    font-family: var(--font-heading, 'Outfit', sans-serif);
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted, #64748B);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.a11y-section-title i {
    font-size: 0.72rem;
    color: var(--primary, #4F46E5);
}

/* Options Grid */
.a11y-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Individual Option Button */
.a11y-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px;
    border-radius: 14px;
    border: 1.5px solid rgba(var(--text-rgb, 15, 23, 42), 0.08);
    background: rgba(var(--surface-rgb, 255, 255, 255), 0.6);
    color: var(--text-main, #0F172A);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: var(--font-body, 'Inter', sans-serif);
    position: relative;
    overflow: hidden;
}

.a11y-option::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.08), rgba(124, 58, 237, 0.04));
    opacity: 0;
    transition: opacity 0.25s;
}

.a11y-option:hover {
    border-color: rgba(79, 70, 229, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.1);
}

.a11y-option:hover::before {
    opacity: 1;
}

.a11y-option:active {
    transform: scale(0.96);
}

/* Active State */
.a11y-option.active {
    border-color: var(--primary, #4F46E5);
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.12), rgba(124, 58, 237, 0.08));
    box-shadow:
        0 0 0 1px rgba(79, 70, 229, 0.2),
        0 4px 16px rgba(79, 70, 229, 0.15);
}

.a11y-option.active .a11y-icon {
    background: linear-gradient(135deg, #4F46E5, #7C3AED);
    color: #fff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.a11y-option.active .a11y-label {
    color: var(--primary, #4F46E5);
    font-weight: 700;
}

/* Icon wrapper */
.a11y-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(var(--text-rgb, 15, 23, 42), 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    color: var(--text-muted, #64748B);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    z-index: 1;
}

/* Label */
.a11y-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
    color: var(--text-main, #0F172A);
    position: relative;
    z-index: 1;
    transition: all 0.2s;
}

/* ── Font Size Slider ── */
.a11y-slider-group {
    margin-top: 14px;
    padding: 14px;
    border-radius: 12px;
    background: rgba(var(--text-rgb, 15, 23, 42), 0.03);
    border: 1px solid rgba(var(--text-rgb, 15, 23, 42), 0.05);
}

.a11y-slider-group label {
    color: var(--text-main, #0F172A);
}

.a11y-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right,
        rgba(79, 70, 229, 0.2) 0%,
        rgba(79, 70, 229, 0.4) 100%);
    outline: none;
    cursor: pointer;
}

.a11y-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4F46E5, #7C3AED);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4);
    border: 2px solid #fff;
    transition: transform 0.2s, box-shadow 0.2s;
}

.a11y-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.5);
}

.a11y-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4F46E5, #7C3AED);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4);
    border: 2px solid #fff;
}

/* ── Reset Button ── */
.a11y-reset-btn {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1.5px dashed rgba(var(--text-rgb, 15, 23, 42), 0.15);
    background: transparent;
    color: var(--text-muted, #64748B);
    font-size: 0.8rem;
    font-weight: 700;
    font-family: var(--font-body, 'Inter', sans-serif);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.25s;
}

.a11y-reset-btn:hover {
    border-color: #EF4444;
    color: #EF4444;
    background: rgba(239, 68, 68, 0.05);
}

.a11y-reset-btn:active {
    transform: scale(0.97);
}


/* ==========================================================================
   ANIMATIONS
   ========================================================================== */

@keyframes a11ySlideUp {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes a11ySlideDown {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
        visibility: hidden;
    }
}

@keyframes a11yPulse {
    0%, 100% {
        box-shadow:
            0 4px 20px rgba(79, 70, 229, 0.35),
            0 0 0 0 rgba(79, 70, 229, 0.3);
    }
    50% {
        box-shadow:
            0 4px 20px rgba(79, 70, 229, 0.35),
            0 0 0 10px rgba(79, 70, 229, 0);
    }
}

@keyframes a11yBadgePop {
    0% { transform: scale(0); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

@keyframes a11yFadeIn {
    0% {
        opacity: 0;
        transform: translateY(8px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Staggered entrance for options */
.a11y-panel.open .a11y-option {
    animation: a11yFadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) both;
}
.a11y-panel.open .a11y-option:nth-child(1) { animation-delay: 0.05s; }
.a11y-panel.open .a11y-option:nth-child(2) { animation-delay: 0.08s; }
.a11y-panel.open .a11y-option:nth-child(3) { animation-delay: 0.11s; }
.a11y-panel.open .a11y-option:nth-child(4) { animation-delay: 0.14s; }
.a11y-panel.open .a11y-option:nth-child(5) { animation-delay: 0.17s; }


/* ==========================================================================
   DARK MODE OVERRIDES
   ========================================================================== */

html.mode-dark .a11y-panel,
html.dark .a11y-panel {
    background: rgba(30, 41, 59, 0.92);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow:
        0 25px 60px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset;
}

html.mode-dark .a11y-panel-header,
html.dark .a11y-panel-header {
    background: rgba(30, 41, 59, 0.5);
    border-color: rgba(255, 255, 255, 0.06);
}

html.mode-dark .a11y-option,
html.dark .a11y-option {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
}

html.mode-dark .a11y-option:hover,
html.dark .a11y-option:hover {
    border-color: rgba(99, 102, 241, 0.35);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

html.mode-dark .a11y-icon,
html.dark .a11y-icon {
    background: rgba(255, 255, 255, 0.08);
    color: #94A3B8;
}

html.mode-dark .a11y-label,
html.dark .a11y-label {
    color: #E2E8F0;
}

html.mode-dark .a11y-close,
html.dark .a11y-close {
    background: rgba(255, 255, 255, 0.06);
    color: #94A3B8;
}

html.mode-dark .a11y-slider-group,
html.dark .a11y-slider-group {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.06);
}

html.mode-dark .a11y-slider,
html.dark .a11y-slider {
    background: linear-gradient(to right,
        rgba(99, 102, 241, 0.15) 0%,
        rgba(99, 102, 241, 0.35) 100%);
}

html.mode-dark .a11y-slider::-webkit-slider-thumb,
html.dark .a11y-slider::-webkit-slider-thumb {
    border-color: #1E293B;
}

html.mode-dark .a11y-reset-btn,
html.dark .a11y-reset-btn {
    border-color: rgba(255, 255, 255, 0.1);
    color: #94A3B8;
}


/* ==========================================================================
   ACCESSIBILITY UTILITY CLASSES (Applied to <html>)
   ========================================================================== */

/* ── High Contrast ── */
html.a11y-high-contrast {
    filter: contrast(1.4) !important;
}

html.a11y-high-contrast *:not(.a11y-panel):not(.a11y-panel *):not(.a11y-fab) {
    border-color: currentColor !important;
}

/* ── Dark Contrast ── */
html.a11y-dark-contrast {
    filter: invert(1) hue-rotate(180deg) !important;
}

html.a11y-dark-contrast img,
html.a11y-dark-contrast video,
html.a11y-dark-contrast canvas,
html.a11y-dark-contrast svg image,
html.a11y-dark-contrast .a11y-fab,
html.a11y-dark-contrast .a11y-panel {
    filter: invert(1) hue-rotate(180deg) !important;
}

/* ── Monochrome (Grayscale) ── */
html.a11y-monochrome {
    filter: grayscale(1) !important;
}

/* ── Sepia ── */
html.a11y-sepia {
    filter: sepia(0.6) !important;
}

/* ── Invert Colors ── */
html.a11y-invert {
    filter: invert(1) !important;
}

html.a11y-invert img,
html.a11y-invert video,
html.a11y-invert canvas,
html.a11y-invert .a11y-fab,
html.a11y-invert .a11y-panel {
    filter: invert(1) !important;
}

/* ── Large Text ── */
html.a11y-large-text body {
    font-size: 1.2em !important;
}

html.a11y-large-text h1 { font-size: 2.5rem !important; }
html.a11y-large-text h2 { font-size: 2rem !important; }
html.a11y-large-text h3 { font-size: 1.6rem !important; }
html.a11y-large-text p,
html.a11y-large-text span,
html.a11y-large-text td,
html.a11y-large-text th,
html.a11y-large-text li,
html.a11y-large-text label,
html.a11y-large-text input,
html.a11y-large-text select,
html.a11y-large-text textarea {
    font-size: 1.1em !important;
}

/* ── Readable Font ── */
html.a11y-readable-font * {
    font-family: Arial, Helvetica, 'Segoe UI', sans-serif !important;
    letter-spacing: 0.01em;
}

/* ── Extra Line Height ── */
html.a11y-line-height * {
    line-height: 2 !important;
}

/* ── Extra Letter Spacing ── */
html.a11y-letter-spacing * {
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

/* ── Highlight Links ── */
html.a11y-highlight-links a {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 3px !important;
    outline: 2px solid rgba(79, 70, 229, 0.3) !important;
    outline-offset: 2px !important;
    border-radius: 2px !important;
    padding: 1px 3px !important;
    background: rgba(79, 70, 229, 0.06) !important;
}

html.a11y-highlight-links a:hover {
    background: rgba(79, 70, 229, 0.12) !important;
}

/* ── Highlight Headings ── */
html.a11y-highlight-headings h1,
html.a11y-highlight-headings h2,
html.a11y-highlight-headings h3,
html.a11y-highlight-headings h4,
html.a11y-highlight-headings h5,
html.a11y-highlight-headings h6 {
    border-left: 4px solid var(--primary, #4F46E5) !important;
    padding-left: 12px !important;
    background: rgba(79, 70, 229, 0.04) !important;
    border-radius: 0 8px 8px 0 !important;
}

/* ── Big Cursor ── */
html.a11y-big-cursor,
html.a11y-big-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M8 4l28 20H20l10 16-5 3-10-16-7 7z' fill='%23000' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 4 4, auto !important;
}

/* ── Stop Animations ── */
html.a11y-stop-animations *,
html.a11y-stop-animations *::before,
html.a11y-stop-animations *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

/* Keep the accessibility widget itself working */
html.a11y-stop-animations .a11y-fab,
html.a11y-stop-animations .a11y-panel,
html.a11y-stop-animations .a11y-panel *,
html.a11y-stop-animations .a11y-option,
html.a11y-stop-animations .a11y-close,
html.a11y-stop-animations .a11y-badge {
    transition-duration: 0.2s !important;
}


/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 640px) {
    .a11y-fab {
        bottom: 16px;
        left: 16px;
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
    }

    .a11y-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 80vh;
        border-radius: 20px 20px 0 0;
    }

    .a11y-panel.open {
        animation: a11ySlideUpMobile 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    }

    .a11y-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .a11y-option {
        padding: 12px 6px;
    }
}

@keyframes a11ySlideUpMobile {
    0% {
        opacity: 0;
        transform: translateY(100%);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ==========================================================================
   WELCOME PAGE OVERRIDES (Landing page uses different variables)
   ========================================================================== */

/* The landing page (welcome.blade.php) uses its own CSS variables,
   so we provide fallbacks within the component inline styles and
   ensure the widget looks good on the dark landing page */
body[style*="--bg-deep"] .a11y-panel,
.bg-grid ~ #a11yWidget .a11y-panel {
    background: rgba(15, 20, 40, 0.92);
    border-color: rgba(255, 255, 255, 0.08);
}

body[style*="--bg-deep"] .a11y-option,
.bg-grid ~ #a11yWidget .a11y-option {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
}

body[style*="--bg-deep"] .a11y-label,
.bg-grid ~ #a11yWidget .a11y-label {
    color: #E2E8F0;
}
