/**
 * Accessibility CSS - IS 5568 / WCAG 2.0 AA Compliance
 * Version: 2.0.0
 * Last Update: 2026-03-01
 *
 * Centralized accessibility styles for the entire platform.
 * Included via main_header.php and _shop_header.php.
 *
 * Features:
 * - Skip-to-content link
 * - Universal focus-visible ring (overrides outline:none across codebase)
 * - Screen-reader-only utility class
 * - High-contrast focus indicators for light and dark modes
 * - Focus-within support for dropdown menus
 */

/* ============================================================================
   Skip-to-Content Link
   Hidden off-screen, appears on Tab focus for keyboard users
   ============================================================================ */
.skip-to-content {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: #287535;
    color: #fff;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 8px 8px;
    z-index: 100000;
    transition: top 0.2s ease;
    white-space: nowrap;
}

.skip-to-content:focus {
    top: 0;
    outline: 3px solid #287535;
    outline-offset: 2px;
}

/* ============================================================================
   Universal Focus Ring
   Overrides all outline:none declarations across the codebase (80+ instances)
   Uses :focus-visible so mouse clicks don't show the ring
   ============================================================================ */
*:focus-visible {
    outline: 3px solid #287535 !important;
    outline-offset: 2px !important;
}

/* Dark mode: brighter focus ring for contrast */
[data-theme="dark"] *:focus-visible {
    outline-color: #51CF66 !important;
}

/* Ensure inputs show focus ring even with existing border styles */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid #287535 !important;
    outline-offset: 0 !important;
    border-color: #287535 !important;
}

[data-theme="dark"] input:focus-visible,
[data-theme="dark"] textarea:focus-visible,
[data-theme="dark"] select:focus-visible {
    outline-color: #51CF66 !important;
    border-color: #51CF66 !important;
}

/* ============================================================================
   Screen-Reader-Only Utility
   Visually hidden but accessible to screen readers
   ============================================================================ */
.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;
}

/* ============================================================================
   Focus-Within for Dropdown Menus
   Allows keyboard navigation of user dropdown menu
   ============================================================================ */
.user-menu:focus-within .user-menu-dropdown {
    display: block;
}

/* ============================================================================
   Link Distinguishability (WCAG 1.4.1)
   Links in body text must be distinguishable by more than color alone
   ============================================================================ */
.mk-card a:not(.mk-btn),
.content-area a:not(.mk-btn),
article a:not(.mk-btn),
.terms-text a,
.footer-tagline a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.mk-card a:not(.mk-btn):hover,
.content-area a:not(.mk-btn):hover,
article a:not(.mk-btn):hover {
    text-decoration-thickness: 2px;
}

/* ============================================================================
   Reduced Motion
   Respect user preference for reduced motion
   ============================================================================ */
@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;
    }
}

/* ============================================================================
   Accessibility Effect Classes (applied to <html>)
   Toggled by A11yToolbar, cascade to entire page
   ============================================================================ */

/* --- Font Size Steps ---
   Site uses px units throughout (2000+ declarations), so html font-size %
   has no effect. CSS zoom scales everything including px values and
   reflows layout correctly. Supported in Chrome, Safari, Edge, Firefox 126+. */
html.a11y-font-1 { zoom: 1.1; }
html.a11y-font-2 { zoom: 1.2; }
html.a11y-font-3 { zoom: 1.3; }

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

/* --- Grayscale --- */
html.a11y-grayscale { filter: grayscale(100%); }

/* --- Combined: High Contrast + Grayscale --- */
html.a11y-high-contrast.a11y-grayscale { filter: contrast(1.4) grayscale(100%); }

/* --- Highlight Links --- */
html.a11y-highlight-links a {
    background-color: #FFFF00 !important;
    color: #000 !important;
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    font-weight: bold !important;
    padding: 1px 3px !important;
}
/* Exclude toolbar links from highlighting */
html.a11y-highlight-links #a11y-toolbar a {
    background-color: transparent !important;
    color: inherit !important;
    text-decoration: none !important;
    font-weight: inherit !important;
    padding: 0 !important;
}

/* --- Stop Animations --- */
html.a11y-stop-animations *,
html.a11y-stop-animations *::before,
html.a11y-stop-animations *::after {
    animation: none !important;
    transition: none !important;
}
/* Keep toolbar transitions working */
html.a11y-stop-animations #a11y-toolbar,
html.a11y-stop-animations #a11y-toolbar *,
html.a11y-stop-animations #a11y-toolbar *::before,
html.a11y-stop-animations #a11y-toolbar *::after {
    transition: all 0.3s ease !important;
}

/* --- Readable Font --- */
html.a11y-readable-font * {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif !important;
}

/* --- Large Cursor --- */
html.a11y-large-cursor,
html.a11y-large-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 20H20l-4 16L8 4z' fill='%23000' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 4 4, auto !important;
}

/* --- Line Spacing Steps --- */
html.a11y-spacing-1 * { line-height: 1.8 !important; letter-spacing: 0.05em !important; }
html.a11y-spacing-2 * { line-height: 2.0 !important; letter-spacing: 0.1em !important; }
html.a11y-spacing-3 * { line-height: 2.2 !important; letter-spacing: 0.15em !important; }

/* Exclude toolbar from spacing effects */
#a11y-toolbar,
#a11y-toolbar * {
    line-height: normal !important;
    letter-spacing: normal !important;
}

/* ============================================================================
   Accessibility Toolbar - Button, Strip, Panel
   z-index: 99999 (toolbar), 99998 (backdrop)
   ============================================================================ */

/* --- Toolbar Container (self-reset from effect classes) --- */
#a11y-toolbar {
    font-size: 16px !important;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif !important;
    direction: rtl;
    text-align: right;
}
#a11y-toolbar * {
    box-sizing: border-box;
}

/* --- Floating Button Wrapper (State 1) --- */
.a11y-btn-wrap {
    position: fixed;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 99999;
    width: 48px;
    height: 48px;
}
.a11y-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #287535;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    padding: 0;
    line-height: 1;
}
.a11y-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.a11y-btn:focus-visible {
    outline: 3px solid #fff !important;
    outline-offset: 3px !important;
}

/* Dismiss × icon (sibling of button, positioned over it) */
.a11y-btn-dismiss {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-card, #fff);
    color: var(--text-primary, #333);
    border: 1px solid var(--border-color, rgba(0,0,0,0.2));
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}
.a11y-btn-dismiss:hover {
    background: #e74c3c;
    color: #fff;
    border-color: #e74c3c;
}

/* --- Dismissed Strip (State 2) --- */
.a11y-strip {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60px;
    background: #287535;
    border-radius: 0 4px 4px 0;
    z-index: 99999;
    cursor: pointer;
    transition: width 0.3s ease, padding 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0;
    border: none;
}
.a11y-strip-icon {
    opacity: 0;
    font-size: 20px;
    transition: opacity 0.3s ease;
    color: #fff;
    pointer-events: none;
}
.a11y-strip:hover {
    width: 44px;
    padding: 0 8px;
}
.a11y-strip:hover .a11y-strip-icon {
    opacity: 1;
}
.a11y-strip:focus-visible {
    outline: 3px solid #287535 !important;
    outline-offset: 2px !important;
    width: 44px;
    padding: 0 8px;
}
.a11y-strip:focus-visible .a11y-strip-icon {
    opacity: 1;
}

/* --- Backdrop (State 1a) --- */
.a11y-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.a11y-backdrop.a11y-visible {
    opacity: 1;
    visibility: visible;
}

/* --- Panel (State 1a) --- */
.a11y-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 100%;
    background: var(--bg-card, #fff);
    color: var(--text-primary, #1a1a1a);
    z-index: 99999;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}
.a11y-panel.a11y-open {
    transform: translateX(0);
}

/* Panel header */
.a11y-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, rgba(0,0,0,0.1));
    flex-shrink: 0;
}
.a11y-panel-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary, #1a1a1a);
}
.a11y-panel-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--border-color, rgba(0,0,0,0.1));
    color: var(--text-primary, #1a1a1a);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s ease;
}
.a11y-panel-close:hover {
    background: var(--bg-secondary, #f0f0f0);
}

/* Panel body - scrollable */
.a11y-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
}

/* Control group */
.a11y-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color, rgba(0,0,0,0.05));
}
.a11y-control:last-child {
    border-bottom: none;
}
.a11y-control-label {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary, #1a1a1a);
}

/* Toggle switch */
.a11y-toggle {
    position: relative;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}
.a11y-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.a11y-toggle-track {
    position: absolute;
    inset: 0;
    background: var(--border-color, #ccc);
    border-radius: 13px;
    cursor: pointer;
    transition: background 0.3s ease;
}
.a11y-toggle-track::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    top: 2px;
    right: 2px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.a11y-toggle input:checked + .a11y-toggle-track {
    background: #287535;
}
.a11y-toggle input:checked + .a11y-toggle-track::after {
    transform: translateX(-22px);
}
.a11y-toggle input:focus-visible + .a11y-toggle-track {
    outline: 3px solid #287535;
    outline-offset: 2px;
}

/* Stepper buttons (font size / spacing) */
.a11y-stepper {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.a11y-stepper-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border-color, rgba(0,0,0,0.2));
    background: var(--bg-secondary, #f0f0f0);
    color: var(--text-primary, #1a1a1a);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s ease, border-color 0.2s ease;
}
.a11y-stepper-btn:hover {
    background: #287535;
    color: #fff;
    border-color: #287535;
}
.a11y-stepper-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.a11y-stepper-btn:disabled:hover {
    background: var(--bg-secondary, #f0f0f0);
    color: var(--text-primary, #1a1a1a);
    border-color: var(--border-color, rgba(0,0,0,0.2));
}
.a11y-stepper-val {
    min-width: 24px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary, #666);
}
.a11y-stepper-reset {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary, #666);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 4px;
    transition: color 0.2s ease;
}
.a11y-stepper-reset:hover {
    color: #e74c3c;
}

/* Panel footer */
.a11y-panel-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color, rgba(0,0,0,0.1));
    flex-shrink: 0;
}
.a11y-reset-btn {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #e74c3c;
    background: transparent;
    color: #e74c3c;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}
.a11y-reset-btn:hover {
    background: #e74c3c;
    color: #fff;
}

/* ============================================================================
   Accessibility Toolbar - Mobile Responsive
   ============================================================================ */
@media (max-width: 768px) {
    /* Panel: slides from bottom on mobile */
    .a11y-panel {
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        height: auto;
        max-height: 80vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
    }
    .a11y-panel.a11y-open {
        transform: translateY(0);
    }

    /* Strip: larger touch target on mobile */
    .a11y-strip {
        width: 8px;
        /* 44px min touch target via padding */
        padding-left: 36px;
        margin-left: -36px;
    }
    .a11y-strip:hover {
        width: 8px;
        padding-left: 36px;
    }
    .a11y-strip:hover .a11y-strip-icon {
        opacity: 0;
    }

    /* Button position slightly closer to edge on mobile */
    .a11y-btn-wrap {
        left: 12px;
    }
}
