/**
 * ACCESSIBILITY - Доступність
 * Focus management, high contrast, screen readers,
 * reduced motion support, touch device improvements, iOS fixes
 * 
 * WCAG 2.1 AA Compliance:
 * - Focus indicators
 * - Touch target sizes (44x44px minimum)
 * - Color contrast ratios
 * - Motion reduction
 * - Screen reader support
 */

/* === FOCUS STYLES === */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.btn:focus-visible {
    outline-offset: 3px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline-offset: 0;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

/* === SCREEN READER ONLY === */
.sr-only,
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Show on focus */
.sr-only-focusable:focus,
.visually-hidden-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* === HIGH CONTRAST MODE === */
@media (prefers-contrast: high) {

    /* Stronger borders for better visibility */
    .btn,
    .card,
    .event-card,
    .course-card,
    html body .notification {
        border: 2px solid currentColor;
    }

    .badge {
        border: 1px solid currentColor;
    }

    /* Underline all links */
    a {
        text-decoration: underline;
    }
    
    /* Виняток для статистичних карток хабу */
    .hub-stat-card,
    .hub-stat-card:hover,
    .hub-stat-card:focus,
    .hub-stat-card:active {
        text-decoration: none !important;
    }

    /* Increase contrast for form elements */
    input,
    textarea,
    select {
        border: 2px solid currentColor;
        background: var(--color-bg);
    }

    /* Better focus indicators */
    html body *:focus-visible {
        outline: 3px solid currentColor;
        outline-offset: 3px;
    }

    /* Text shadows removed for headings */
    .hero-title,
    h1,
    h2,
    h3 {
        text-shadow: none;
    }
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    html body *,
    html body *::before,
    html body *::after {
        animation-duration: 0.01ms;
        animation-iteration-count: 1;
        transition-duration: 0.01ms;
        scroll-behavior: auto;
    }

    /* Виключення для зображень - дозволяємо GIF анімацію */
    img,
    img::before,
    img::after {
        animation-duration: initial;
        animation-iteration-count: initial;
        transition-duration: initial;
    }

    /* Remove all transforms and complex animations */
    .animate-fade-in,
    .animate-fade-out,
    .animate-slide-in-right,
    .animate-slide-out-right,
    .animate-spin,
    .animate-pulse,
    .animate-fade-in-up,
    html body .animate-typing {
        animation: none;
        transform: none;
    }

    /* Disable parallax scrolling */
    html body .parallax {
        transform: none;
    }

    /* Instant card animations */
    .card,
    .event-card,
    html body .course-card {
        transition: none;
        transform: none;
    }

    /* Disable smooth scrolling */
    html body {
        scroll-behavior: auto;
    }

    /* Keep minimal opacity transitions for better UX */
    button,
    a,
    input,
    html body .btn {
        transition-property: opacity;
        transition-duration: 0.15s;
    }

    /* Disable loading animations */
    .spinner,
    .loading-animation,
    html body .skeleton-loading {
        animation: none;
    }

    /* Disable video autoplay */
    html body video[autoplay] {
        animation-play-state: paused;
    }
}

/* === TOUCH DEVICE IMPROVEMENTS === */
@media (hover: none) and (pointer: coarse) {

  
    /* Видалити hover effects на touch devices */
    .card:hover,
    .btn:hover,
    .event-card:hover,
    .course-card:hover {
        transform: none;
    }

    /* Add active states for better feedback */
    .btn:active,
    button:active {
        opacity: 0.8;
        transform: scale(0.98);
    }

    /* Better scroll handling */
    .scroll-container {
        scroll-snap-type: x mandatory;
        scroll-snap-align: start;
    }
}

/* === iOS SAFARI SPECIFIC === */
@supports (-webkit-touch-callout: none) {

    .fullscreen-section,
    .hero-section,
    .vh-100 {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }

    .hero-new-design {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }

    /* Fix for iOS input zoom - prevent zoom on focus */
    input,
    textarea,
    select {
        font-size: 16px;
        font-family: 'Roboto', sans-serif;
    }

    /* Smooth scrolling for iOS */
    .scroll-container {
        -webkit-overflow-scrolling: touch;
    }

    /* Fix for iOS tap highlight */
    button,
    a,
    .btn {
        -webkit-tap-highlight-color: rgba(255, 107, 53, 0.2);
    }

    /* Fix for iOS safe area */
    .mobile-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Fix iOS rubber band scrolling - proper way without blocking scroll */
    body {
        overscroll-behavior-y: contain;
    }
}

/* === ПРИХОВУВАННЯ ТЕКСТУ ПЕРЕД HEADER === */
/* Додатковий захист: забезпечуємо, що header є першим видимим елементом */
/* Виправлено: position: sticky для коректного закріплення при скролі */
body > header.main-header {
    position: sticky;
    top: 0;
    z-index: var(--z-header, 1000);
}

/* Приховуємо будь-які елементи, які можуть з'явитися перед header */
/* Це правило спрацює тільки якщо елемент дійсно з'явиться перед header */
body > *:first-child:not(header):not(script):not(style):not(link):not(meta):not(title):not(noscript) {
    display: none;
    visibility: hidden;
    height: 0;
    overflow: hidden;
    position: absolute;
    left: -9999px;
    width: 0;
}