/* ========================================
   ACCESSIBILITY ENHANCEMENTS
   ปรับปรุงความสามารถในการเข้าถึง
   ======================================== */

/* ========================================
   1. FOCUS INDICATORS (เพิ่มความชัดเจน)
   ======================================== */

/* Focus ทั่วไป */
*:focus-visible {
    outline: 3px solid #ec4899;
    outline-offset: 3px;
    border-radius: 4px;
    transition: outline 0.2s ease;
}

/* Links และ Buttons */
a:focus-visible,
button:focus-visible {
    outline: 3px solid #ec4899;
    outline-offset: 4px;
    box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.2);
}

/* Navigation Links */
.nav-link:focus-visible {
    background: rgba(236, 72, 153, 0.1);
    outline: 3px solid #ec4899;
    outline-offset: -3px;
}

/* Skip Link */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    z-index: 10000;
    padding: 1rem 2rem;
    background: #ec4899;
    color: white;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 8px 0;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid white;
    outline-offset: -3px;
}

/* ========================================
   2. HIGH CONTRAST MODE SUPPORT
   ======================================== */

@media (prefers-contrast: high) {
    * {
        border-width: 2px !important;
    }
    
    .btn,
    .card,
    .feature-card {
        border: 2px solid currentColor !important;
    }
    
    /* เพิ่ม contrast ให้ข้อความ */
    body {
        color: #000 !important;
        background: #fff !important;
    }
    
    [data-theme="dark"] body {
        color: #fff !important;
        background: #000 !important;
    }
}

/* ========================================
   3. REDUCED MOTION SUPPORT
   ======================================== */

@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;
    }
    
    /* ปิด particles */
    #particles-js {
        display: none !important;
    }
    
    /* ปิด floating shapes */
    .floating-shape {
        animation: none !important;
    }
}

/* ========================================
   4. KEYBOARD NAVIGATION ENHANCEMENTS
   ======================================== */

/* Tab order ชัดเจน */
[tabindex]:focus-visible {
    outline: 3px dashed #ec4899;
    outline-offset: 3px;
}

/* Form elements */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid #ec4899;
    outline-offset: 2px;
    border-color: #ec4899;
}

/* ========================================
   5. SCREEN READER IMPROVEMENTS
   ======================================== */

/* ซ่อนจาก visual แต่ screen reader อ่านได้ */
.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;
}

/* ซ่อนจาก screen reader แต่แสดงได้ */
[aria-hidden="true"] {
    speak: none;
}

/* ========================================
   6. COLOR CONTRAST FIXES
   ======================================== */

/* ปรับ contrast ให้ผ่าน WCAG AAA */
.text-muted {
    color: #4b5563 !important; /* เพิ่ม contrast */
}

[data-theme="dark"] .text-muted {
    color: #d1d5db !important; /* เพิ่ม contrast */
}

/* Links ต้องมี contrast เพียงพอ */
a {
    color: #dc2626; /* Red ที่มี contrast ดี */
    text-decoration: underline;
    text-decoration-color: rgba(220, 38, 38, 0.3);
    text-underline-offset: 3px;
}

a:hover {
    color: #b91c1c;
    text-decoration-color: #b91c1c;
}

[data-theme="dark"] a {
    color: #ffffff;
}

[data-theme="dark"] a:hover {
    color: #fca5a5;
}

/* ========================================
   7. TOUCH TARGET SIZE (มือถือ)
   ======================================== */

@media (max-width: 768px) {
    /* ขนาดต่ำสุด 44x44px ตาม WCAG */
    a,
    button,
    .btn,
    .nav-link,
    input,
    select,
    textarea {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }
    
    /* Icon buttons */
    .icon-btn {
        min-width: 48px;
        min-height: 48px;
    }
}

/* ========================================
   8. ERROR STATES (Form Validation)
   ======================================== */

input:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown) {
    border-color: #dc2626;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23dc2626' viewBox='0 0 20 20'%3E%3Cpath fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
}

input:valid:not(:placeholder-shown),
textarea:valid:not(:placeholder-shown) {
    border-color: #16a34a;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%2316a34a' viewBox='0 0 20 20'%3E%3Cpath fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
}

/* ========================================
   9. PRINT STYLES
   ======================================== */

@media print {
    /* ซ่อนส่วนที่ไม่จำเป็น */
    .navbar,
    .footer,
    #particles-js,
    .scroll-progress,
    .md-popup,
    .loading-screen,
    .btn,
    button {
        display: none !important;
    }
    
    /* ปรับสีให้เหมาะกับการพิมพ์ */
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    /* แสดง URLs ของ links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    /* Page breaks */
    h1, h2, h3 {
        page-break-after: avoid;
    }
    
    img {
        page-break-inside: avoid;
        max-width: 100% !important;
    }
}

/* ========================================
   10. DARK MODE CONTRAST
   ======================================== */

[data-theme="dark"] {
    /* เพิ่ม contrast สำหรับ dark mode */
    --text-primary: #f9fafb;
    --text-secondary: #e5e7eb;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
}

[data-theme="dark"] .card,
[data-theme="dark"] .feature-card {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ========================================
   END OF ACCESSIBILITY ENHANCEMENTS
   ======================================== */

