/*
 * #96-101 - Accessibility Enhancements
 * Additional accessibility improvements for better UX
 */

/* ===== #96 - Focus Ring Enhancements ===== */

/* Custom focus styles */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    transition: outline-color 0.2s;
}

/* Button focus */
button:focus-visible,
.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(255, 107, 0, 0.2);
}

/* Link focus */
a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 4px;
    border-radius: 2px;
}

/* Input focus */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 0;
    box-shadow: 0 0 0 4px rgba(255, 107, 0, 0.1);
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    z-index: 10000;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 20px;
}

/* ===== #97 - Screen Reader Only Content ===== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sr-only-focusable:focus,
.sr-only-focusable:active {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ===== #98 - High Contrast Mode Support ===== */

@media (prefers-contrast: high) {
    * {
        border-color: currentColor !important;
    }
    
    button, .btn {
        border: 2px solid currentColor;
    }
    
    input, textarea, select {
        border: 2px solid currentColor;
    }
    
    a {
        text-decoration: underline;
    }
    
    .card, .deal-card {
        border: 2px solid currentColor;
    }
}

/* ===== #99 - Reduced Motion Enhancements ===== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    /* Keep scroll-triggered elements visible */
    .animate-on-scroll,
    .animate-on-scroll.animated,
    [class*="animate"],
    .fade-in,
    .fade-up,
    .fade-down,
    .slide-in,
    .slide-up {
        opacity: 1 !important;
        transform: none !important;
        visibility: visible !important;
    }
    
    /* Keep essential animations */
    .sr-only-focusable:focus {
        transition: none;
    }
    
    /* Disable parallax */
    .parallax {
        transform: none !important;
    }
    
    /* Instant page transitions */
    .page-transition-fade,
    .page-transition-slide,
    .page-transition-scale {
        animation: none;
    }
}

/* ===== #100 - Keyboard Navigation Enhancements ===== */

/* Visual indicator for keyboard navigation */
.keyboard-nav *:focus {
    outline: 3px solid var(--primary);
    outline-offset: 3px;
}

/* Hide focus indicators when using mouse */
.mouse-nav *:focus {
    outline: none;
}

/* Roving tabindex support */
[role="menu"],
[role="listbox"],
[role="tablist"] {
    outline: none;
}

[role="menuitem"],
[role="option"],
[role="tab"] {
    outline: none;
}

[role="menuitem"]:focus,
[role="option"]:focus,
[role="tab"]:focus {
    background: rgba(255, 107, 0, 0.1);
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

/* ===== #101 - Color Contrast Improvements ===== */

/* Ensure text meets WCAG AA standards */
.text-muted {
    color: #6b7280 !important; /* Improved from lighter grays */
}

/* Link color contrast */
a {
    color: var(--primary);
    /* Underlines removed by user preference - kept in high-contrast mode only */
}
/* Error text contrast */
.error-text {
    color: #dc2626 !important; /* Ensures 4.5:1 contrast */
}

/* Success text contrast */
.success-text {
    color: #059669 !important; /* Ensures 4.5:1 contrast */
}

/* Warning text contrast */
.warning-text {
    color: #d97706 !important; /* Ensures 4.5:1 contrast */
}

/* ===== Additional Accessibility Utilities ===== */

/* Visually hide but keep accessible */
.visually-hidden:not(:focus):not(:active) {
    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;
}

/* Focus trap for modals */
.focus-trap {
    position: relative;
}

/* ARIA landmarks */
[role="main"] {
    outline: none;
}

[role="banner"],
[role="navigation"],
[role="contentinfo"],
[role="complementary"] {
    outline: none;
}

/* ===== Print Accessibility ===== */

@media print {
    /* Show links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    /* Don't break inside these elements */
    .card, .deal-card, article {
        break-inside: avoid;
    }
    
    /* Show abbreviations */
    abbr[title]:after {
        content: " (" attr(title) ")";
    }
}

/* ===== Touch Target Size ===== */

/* Ensure touch targets are at least 44x44px */
button,
.btn,
a,
input[type="checkbox"],
input[type="radio"],
select {
    min-height: 44px;
    min-width: 44px;
}

/* Adjust for inline elements */
a:not(.btn),
input[type="checkbox"],
input[type="radio"] {
    min-height: auto;
    min-width: auto;
    padding: var(--space-2);
}

/* ===== Font Size Accessibility ===== */

/* Support for users who increase font size */
@media (min-resolution: 120dpi) {
    html {
        font-size: 112.5%; /* Increase base size */
    }
}

@media (min-resolution: 144dpi) {
    html {
        font-size: 125%;
    }
}

/* ===== Accessible Tables ===== */

table {
    border-collapse: collapse;
}

th {
    text-align: left;
    font-weight: 600;
}

/* Ensure table headers are associated */
th[scope="col"],
th[scope="row"] {
    background: rgba(0, 0, 0, 0.05);
}

/* ===== Loading States for Screen Readers ===== */

[aria-busy="true"] {
    position: relative;
}

[aria-busy="true"]::after {
    content: "Loading...";
    position: absolute;
    left: -9999px;
}

/* ===== Live Regions ===== */

[aria-live="polite"] {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

[aria-live="assertive"] {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ===== Focus Management ===== */

/* Remove focus outline for mouse users */
body.using-mouse *:focus {
    outline: none;
}

/* Show focus outline for keyboard users */
body.using-keyboard *:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}


/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark light;
    }
    img:not([src*=".svg"]) {
        opacity: 0.9;
    }
}


/* Extracted from index.html inline styles */


/* ===== UNIFIED A11Y MENU (matches sites.cris.ventures design) ===== */

.a11y-controls {
    position: relative;
}

.a11y-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    color: currentColor;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    -webkit-tap-highlight-color: transparent;
}

.a11y-toggle:hover,
.a11y-toggle[aria-expanded="true"] {
    border-color: var(--primary, #6366f1);
    background: color-mix(in srgb, var(--primary, #6366f1) 14%, transparent);
}

.a11y-toggle:focus-visible {
    border-color: var(--primary, #6366f1);
    outline: 3px solid var(--primary, #6366f1);
    outline-offset: 3px;
}

.a11y-toggle:active { transform: scale(0.98); }

.a11y-toggle img {
    transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    flex-shrink: 0;
}

.a11y-toggle:hover img,
.a11y-toggle[aria-expanded="true"] img { transform: scale(1.1); }

/* Invert white icon → black in light theme */
[data-theme="light"] .a11y-toggle img,
[data-theme="light"] .a11y-menu-header img {
    filter: invert(1);
}

.a11y-menu {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(-8px) scale(0.95);
    transform-origin: top center;
    pointer-events: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--dark-light, #1e293b);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    min-width: 240px;
    max-width: 300px;
    z-index: 9999;
    overflow: hidden;
    transition: opacity 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
        transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
        visibility 0s linear 0.3s;
}

.a11y-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0) scale(1);
    pointer-events: auto;
    transition: opacity 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
        transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
        visibility 0s linear 0s;
}

/* Light theme menu overrides */
[data-theme="light"] .a11y-menu {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.1);
    color: #1e293b;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

.a11y-menu-header {
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.06);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 600;
    font-size: 0.875rem;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 8px;
}

[data-theme="light"] .a11y-menu-header {
    background: rgba(0, 0, 0, 0.03);
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.a11y-menu-section {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.a11y-menu-section:last-child { border-bottom: none; }

[data-theme="light"] .a11y-menu-section {
    border-bottom-color: rgba(0, 0, 0, 0.06);
}

.a11y-menu-section-title {
    padding: 4px 16px;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.4);
    font-weight: 600;
}

[data-theme="light"] .a11y-menu-section-title {
    color: rgba(0, 0, 0, 0.4);
}

/* Font size buttons row */
.a11y-font-row {
    display: flex;
    gap: 4px;
    padding: 4px 12px;
}

.a11y-font-btn {
    flex: 1;
    padding: 10px 8px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    min-height: 44px;
}

[data-theme="light"] .a11y-font-btn {
    border-color: rgba(0, 0, 0, 0.12);
}

.a11y-font-btn:hover,
.a11y-font-btn:focus-visible {
    background: color-mix(in srgb, var(--primary, #6366f1) 18%, transparent);
    border-color: var(--primary, #6366f1);
    color: var(--primary, #6366f1);
}

.a11y-font-btn.active {
    background: var(--primary, #6366f1);
    border-color: var(--primary, #6366f1);
    color: #fff;
}

/* Individual option buttons */
.a11y-btn {
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    color: inherit;
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.a11y-btn:hover,
.a11y-btn:focus-visible {
    background: color-mix(in srgb, var(--primary, #6366f1) 15%, transparent);
    border-left-color: var(--primary, #6366f1);
    color: var(--primary, #6366f1);
}

.a11y-btn[aria-pressed="true"] {
    background: color-mix(in srgb, var(--primary, #6366f1) 18%, transparent);
    border-left-color: var(--primary, #6366f1);
    color: var(--primary, #6366f1);
    font-weight: 600;
}

.a11y-btn svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.a11y-btn:hover svg,
.a11y-btn:focus-visible svg { opacity: 1; }

/* Theme icon show/hide */
.theme-icon.dark { display: none; }
[data-theme="dark"] .theme-icon.light { display: none; }
[data-theme="dark"] .theme-icon.dark { display: inline; }

/* Accessibility body classes */
html.reduce-motion *, body.reduce-motion * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
html.high-contrast, body.high-contrast { filter: contrast(1.2); }
html.high-contrast a, html.high-contrast button,
body.high-contrast a, body.high-contrast button { text-decoration: underline !important; }
html.highlight-links a { outline: 2px solid var(--primary, #6366f1) !important; outline-offset: 2px; }
body.highlight-links a {
    background: color-mix(in srgb, var(--primary, #6366f1) 18%, transparent) !important;
    padding: 2px 4px !important;
    border-radius: 4px !important;
    outline: 2px dashed var(--primary, #6366f1) !important;
    outline-offset: 2px;
}
html.line-spacing, body.line-spacing { line-height: 2 !important; }
html.line-spacing p, html.line-spacing li,
body.line-spacing p, body.line-spacing li { margin-bottom: 1em !important; }

/* Smooth theme transitions */
html { transition: background-color 0.3s ease, color 0.3s ease; }
html.theme-transitioning,
html.theme-transitioning * {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

/* External link indicator */
a[href^="http"]:not([href*="cris.ventures"]):not([href*="localhost"])::after {
    content: "↗";
    font-size: 0.7em;
    margin-left: 3px;
    opacity: 0.6;
}
