/**
 * Accessibility CSS - WCAG 2.1 Compliance
 * มาตรฐานเว็บไซต์ภาครัฐ เวอร์ชัน 3.0
 */

/* ============================================
   1. Skip to Content Link
   ============================================ */
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a5f7a;
    color: #fff;
    padding: 12px 24px;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    z-index: 10000;
    transition: top 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.skip-to-content:focus {
    top: 0;
    outline: 3px solid #ffc107;
    outline-offset: 2px;
}

/* ============================================
   2. Focus Styles (Keyboard Navigation)
   ============================================ */
/* เพิ่ม focus outline ที่ชัดเจนสำหรับทุก element */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 3px solid #ffc107 !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(255, 193, 7, 0.3) !important;
}

/* Focus visible สำหรับ keyboard เท่านั้น */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible) {
    outline: none !important;
    box-shadow: none !important;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid #ffc107 !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(255, 193, 7, 0.3) !important;
}

/* ============================================
   3. Accessibility Toolbar
   ============================================ */
.accessibility-toolbar {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: #1a5f7a;
    padding: 8px 4px;
    border-radius: 8px 0 0 8px;
    box-shadow: -2px 0 10px rgba(0,0,0,0.2);
}

.accessibility-toolbar button {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.accessibility-toolbar button:hover {
    background: rgba(255,255,255,0.2);
}

.accessibility-toolbar button:focus {
    background: #ffc107;
    color: #000;
}

.accessibility-toolbar button.active {
    background: #ffc107;
    color: #000;
}

.accessibility-toolbar .toolbar-divider {
    height: 1px;
    background: rgba(255,255,255,0.3);
    margin: 4px 0;
}

/* Tooltip สำหรับ toolbar */
.accessibility-toolbar button[data-tooltip] {
    position: relative;
}

.accessibility-toolbar button[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    right: 50px;
    top: 50%;
    transform: translateY(-50%);
    background: #333;
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.accessibility-toolbar button[data-tooltip]:hover::before,
.accessibility-toolbar button[data-tooltip]:focus::before {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   4. Font Size Adjustments
   ============================================ */
html.font-size-small {
    font-size: 14px;
}

html.font-size-normal {
    font-size: 16px;
}

html.font-size-large {
    font-size: 18px;
}

html.font-size-xlarge {
    font-size: 20px;
}

/* ============================================
   5. High Contrast Mode
   ============================================ */
html.high-contrast {
    filter: contrast(1.2);
}

html.high-contrast body {
    background: #000 !important;
    color: #fff !important;
}

html.high-contrast a {
    color: #ffff00 !important;
}

html.high-contrast .card,
html.high-contrast .navbar,
html.high-contrast .footer,
html.high-contrast .sidebar {
    background: #111 !important;
    border-color: #fff !important;
}

html.high-contrast .btn-primary {
    background: #ffff00 !important;
    color: #000 !important;
    border-color: #ffff00 !important;
}

html.high-contrast .text-muted {
    color: #ccc !important;
}

/* ============================================
   6. Grayscale Mode (สำหรับผู้บกพร่องทางการมองเห็นสี)
   ============================================ */
html.grayscale {
    filter: grayscale(100%);
}

/* ============================================
   7. Underline Links (ช่วยแยกแยะลิงก์)
   ============================================ */
html.underline-links a {
    text-decoration: underline !important;
}

/* ============================================
   8. Readable Font (ฟอนต์ที่อ่านง่าย)
   ============================================ */
html.readable-font body,
html.readable-font p,
html.readable-font span,
html.readable-font div,
html.readable-font li,
html.readable-font a {
    font-family: Arial, Helvetica, sans-serif !important;
    letter-spacing: 0.5px;
    word-spacing: 2px;
}

/* ============================================
   9. Line Height (เพิ่มระยะห่างบรรทัด)
   ============================================ */
html.increased-line-height body {
    line-height: 2 !important;
}

html.increased-line-height p,
html.increased-line-height li,
html.increased-line-height span {
    line-height: 2 !important;
}

/* ============================================
   10. Cursor Size (ขนาด cursor)
   ============================================ */
html.large-cursor,
html.large-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath fill='%23000' stroke='%23fff' stroke-width='1' d='M5 2l20 12-9 3-4 9z'/%3E%3C/svg%3E"), auto !important;
}

/* ============================================
   11. Animation Reduction (ลด animation)
   ============================================ */
html.reduce-motion *,
html.reduce-motion *::before,
html.reduce-motion *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
}

/* ============================================
   12. Screen Reader Only (สำหรับ SR เท่านั้น)
   ============================================ */
.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;
}

/* ============================================
   13. ARIA Live Region Styles
   ============================================ */
[aria-live="polite"],
[aria-live="assertive"] {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ============================================
   14. Form Accessibility
   ============================================ */
/* Error states ที่ชัดเจน */
.is-invalid {
    border-color: #dc3545 !important;
    border-width: 2px !important;
}

.is-invalid:focus {
    box-shadow: 0 0 0 4px rgba(220, 53, 69, 0.3) !important;
}

/* Required field indicator */
label.required::after,
.form-label.required::after {
    content: " *";
    color: #dc3545;
    font-weight: bold;
}

/* ============================================
   15. Table Accessibility
   ============================================ */
table[role="grid"] th,
table[role="grid"] td {
    padding: 12px;
}

table[role="grid"] tr:focus-within {
    outline: 2px solid #1a5f7a;
    outline-offset: -2px;
}

/* ============================================
   16. Mobile Accessibility Toolbar
   ============================================ */
@media (max-width: 768px) {
    .accessibility-toolbar {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        transform: none;
        flex-direction: row;
        justify-content: center;
        border-radius: 8px 8px 0 0;
        padding: 4px 8px;
    }
    
    .accessibility-toolbar button {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .accessibility-toolbar .toolbar-divider {
        width: 1px;
        height: 24px;
        margin: 0 4px;
    }
    
    .accessibility-toolbar button[data-tooltip]::before {
        display: none;
    }
    
    /* เพิ่ม padding ด้านล่างสำหรับ toolbar */
    body {
        padding-bottom: 50px;
    }
}

/* ============================================
   17. Print Accessibility
   ============================================ */
@media print {
    .accessibility-toolbar,
    .skip-to-content {
        display: none !important;
    }
    
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* ============================================
   18. Accessibility Statement Page
   ============================================ */
.accessibility-statement {
    max-width: 800px;
    margin: 0 auto;
}

.accessibility-statement h2 {
    border-bottom: 2px solid #1a5f7a;
    padding-bottom: 10px;
    margin-top: 30px;
}

.accessibility-statement ul {
    padding-left: 20px;
}

.accessibility-statement .contact-info {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
}