/**
 * WCAG 2.2 Accessibility Styles
 * Website JDIH - Sekretariat DPRD Kabupaten Tasikmalaya
 * 
 * File ini berisi styling untuk meningkatkan aksesibilitas website
 * tanpa mengubah tampilan visual yang sudah ada.
 */

/* ==========================================================================
   Skip to Content Link
   ========================================================================== */

/**
 * Link "Langsung ke konten" yang tersembunyi secara visual
 * namun dapat diakses oleh keyboard dan screen reader.
 * Muncul saat pengguna menekan Tab pertama kali.
 */
.skip-to-content {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 99999;
    background: #1a56db;
    color: #ffffff;
    padding: 0;
    border: none;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    border-radius: 0 0 8px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: none;
}

.skip-to-content:focus,
.skip-to-content:active {
    position: fixed;
    top: 0;
    left: 0;
    width: auto;
    height: auto;
    padding: 16px 24px;
    overflow: visible;
    clip: auto;
    white-space: nowrap;
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

/* ==========================================================================
   Focus Visibility
   ========================================================================== */

/**
 * Focus ring yang lebih jelas untuk navigasi keyboard.
 * Menggunakan :focus-visible untuk hanya menampilkan
 * focus ring saat menggunakan keyboard (bukan mouse).
 */

/* Default focus untuk browser yang tidak support focus-visible */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 3px solid #1a56db;
    outline-offset: 2px;
}

/* Hilangkan outline untuk interaksi mouse */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
[tabindex]:focus:not(:focus-visible) {
    outline: none;
}

/* Focus ring untuk keyboard navigation */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid #1a56db;
    outline-offset: 2px;
}

/* Focus state untuk main content saat di-skip ke */
#main-content:focus {
    outline: none;
}

/* ==========================================================================
   Dropdown Menu Accessibility
   ========================================================================== */

/**
 * Styling untuk dropdown menu saat diakses via keyboard
 */
.dropdown-menu a:focus-visible,
.dropdown-item:focus-visible {
    background-color: #e5edff;
    outline: 2px solid #1a56db;
    outline-offset: -2px;
}

/* ==========================================================================
   Form Accessibility
   ========================================================================== */

/**
 * Styling tambahan untuk form elements
 */
.form-control:focus-visible,
.form-select:focus-visible {
    border-color: #1a56db;
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.25);
}

/* Error state yang lebih jelas */
.is-invalid:focus-visible {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.25);
}

/* ==========================================================================
   Button Accessibility
   ========================================================================== */

/**
 * Memastikan button dengan icon saja tetap dapat diakses
 */
.btn:focus-visible {
    outline: 3px solid #1a56db;
    outline-offset: 2px;
    box-shadow: none;
}

/* Social media buttons di footer */
.btn-outline-secondary:focus-visible {
    outline: 3px solid #1a56db;
    outline-offset: 2px;
    background-color: #e5edff;
}

/* ==========================================================================
   Navigation Accessibility
   ========================================================================== */

/**
 * Styling untuk navbar links
 */
.navbar-nav-link:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 2px;
    background-color: rgba(255, 255, 255, 0.15);
    border-radius: 50rem;
}

/* Active page indicator yang lebih jelas */
.navbar-nav-link.active {
    position: relative;
}

/* ==========================================================================
   Reduced Motion Support
   ========================================================================== */

/**
 * Menghormati preferensi pengguna yang memilih reduced motion.
 * Ini penting untuk pengguna dengan vestibular disorders.
 */
@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;
    }

    /* Nonaktifkan scroll animations */
    .animate-on-scroll {
        opacity: 1 !important;
        transform: none !important;
    }

    /* Nonaktifkan hover scale effects */
    .motion-safe\:hover\:scale-\[1\.01\]:hover {
        transform: none !important;
    }
}

/* ==========================================================================
   High Contrast Mode Support
   ========================================================================== */

/**
 * Mendukung Windows High Contrast Mode
 */
@media (forced-colors: active) {
    .skip-to-content:focus {
        background: Canvas;
        color: CanvasText;
        border: 3px solid CanvasText;
    }

    a:focus-visible,
    button:focus-visible {
        outline: 3px solid CanvasText;
    }
}

/* ==========================================================================
   Screen Reader Only Content
   ========================================================================== */

/**
 * Class untuk konten yang hanya terlihat oleh screen reader
 */
.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;
}

/* ==========================================================================
   Link Accessibility
   ========================================================================== */

/**
 * Memastikan link eksternal memiliki indikasi visual
 */
a[target="_blank"]::after {
    content: " (buka di tab baru)";
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Accessibility Widget Styles
   ========================================================================== */

/**
 * Floating accessibility widget
 */
.a11y-widget {
    position: fixed;
    right: 20px;
    bottom: 100px;
    z-index: 99998;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Toggle button */
.a11y-toggle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a56db 0%, #1e40af 100%);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(26, 86, 219, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.a11y-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(26, 86, 219, 0.5);
}

.a11y-toggle:focus {
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

.a11y-toggle[aria-expanded="true"] {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow: 0 4px 15px rgba(220, 38, 38, 0.4);
}

/* Panel */
.a11y-panel {
    position: absolute;
    bottom: 60px;
    right: 0;
    width: 280px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    animation: a11ySlideUp 0.2s ease-out;
}

@keyframes a11ySlideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Panel header */
.a11y-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #1a56db 0%, #1e40af 100%);
    color: #ffffff;
}

.a11y-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.a11y-close {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.a11y-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.a11y-close:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* Panel body */
.a11y-body {
    padding: 16px;
}

.a11y-section {
    margin-bottom: 16px;
}

.a11y-section:last-child {
    margin-bottom: 0;
}

.a11y-section-reset {
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}

.a11y-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

/* Font size controls */
.a11y-font-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.a11y-font-size-display {
    min-width: 50px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
}

/* Buttons */
.a11y-btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
}

.a11y-btn:focus {
    outline: 3px solid #1a56db;
    outline-offset: 2px;
}

.a11y-btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #f3f4f6;
    color: #374151;
    display: flex;
    align-items: center;
    justify-content: center;
}

.a11y-btn-icon:hover {
    background: #e5e7eb;
    color: #1f2937;
}

.a11y-btn-icon:active {
    background: #d1d5db;
}

/* Option buttons */
.a11y-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.a11y-btn-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    background: #f9fafb;
    border-radius: 8px;
    color: #4b5563;
    font-size: 11px;
    font-weight: 500;
    text-align: center;
}

.a11y-btn-option:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.a11y-btn-option.active {
    background: #dbeafe;
    color: #1e40af;
    box-shadow: inset 0 0 0 2px #1a56db;
}

/* Reset button */
.a11y-btn-reset {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: #fee2e2;
    color: #dc2626;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
}

.a11y-btn-reset:hover {
    background: #fecaca;
}

/* ==========================================================================
   Accessibility Mode Classes
   ========================================================================== */

/**
 * IMPORTANT: CSS filter on body breaks position:fixed elements.
 * We apply filters to a pseudo-element or use backdrop-filter approach
 * to keep the widget floating properly.
 * 
 * Alternative approach: Apply filter only to content wrapper, not body.
 */

/**
 * High contrast mode
 * Uses CSS variables and direct styling instead of filter
 * to avoid breaking fixed positioning
 */
.a11y-high-contrast {
    --a11y-contrast-boost: 1;
}

.a11y-high-contrast .topbar-modern,
.a11y-high-contrast .page-header,
.a11y-high-contrast .navbar-modern,
.a11y-high-contrast main,
.a11y-high-contrast footer:not(.a11y-widget *) {
    filter: contrast(1.25);
}

.a11y-high-contrast a:not(.a11y-widget a),
.a11y-high-contrast button:not(.a11y-widget button) {
    text-decoration: underline !important;
}

/* Keep widget unaffected */
.a11y-high-contrast .a11y-widget {
    filter: none !important;
}

/**
 * Grayscale mode
 * Apply to content sections only, not the widget
 */
.a11y-grayscale .topbar-modern,
.a11y-grayscale .page-header,
.a11y-grayscale .navbar-modern,
.a11y-grayscale main,
.a11y-grayscale footer.bg-white {
    filter: grayscale(100%);
}

/* Keep widget unaffected */
.a11y-grayscale .a11y-widget {
    filter: none !important;
}

/**
 * Combined modes (high contrast + grayscale)
 */
.a11y-high-contrast.a11y-grayscale .topbar-modern,
.a11y-high-contrast.a11y-grayscale .page-header,
.a11y-high-contrast.a11y-grayscale .navbar-modern,
.a11y-high-contrast.a11y-grayscale main,
.a11y-high-contrast.a11y-grayscale footer.bg-white {
    filter: contrast(1.25) grayscale(100%);
}

/**
 * Dyslexia-friendly font
 * Uses OpenDyslexic or similar font with increased letter spacing
 */
.a11y-dyslexia-font {
    font-family: 'OpenDyslexic', 'Comic Sans MS', 'Arial', sans-serif !important;
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

.a11y-dyslexia-font *:not(.a11y-widget *) {
    font-family: inherit !important;
    letter-spacing: inherit !important;
    word-spacing: inherit !important;
}

/* Keep widget font normal */
.a11y-dyslexia-font .a11y-widget,
.a11y-dyslexia-font .a11y-widget * {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
    letter-spacing: normal !important;
    word-spacing: normal !important;
}

/**
 * Increased line height
 * More spacing between lines for easier reading
 */
.a11y-line-height {
    line-height: 2 !important;
}

.a11y-line-height *:not(.a11y-widget *) {
    line-height: inherit !important;
}

/* Keep widget line height normal */
.a11y-line-height .a11y-widget,
.a11y-line-height .a11y-widget * {
    line-height: 1.5 !important;
}

/* ==========================================================================
   Responsive Widget
   ========================================================================== */

@media (max-width: 768px) {
    .a11y-widget {
        right: 15px;
        bottom: 80px;
    }

    .a11y-toggle {
        width: 44px;
        height: 44px;
    }

    .a11y-panel {
        width: 260px;
        right: -5px;
    }
}

/* ==========================================================================
   Text-to-Speech Styles
   ========================================================================== */

/**
 * TTS hint text
 */
.a11y-hint {
    margin: 8px 0 0 0;
    padding: 0;
    font-size: 11px;
    color: #6b7280;
    font-style: italic;
}

/**
 * TTS button active state
 */
.a11y-btn-tts.active {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    border-color: #059669 !important;
}

.a11y-btn-tts.speaking {
    animation: tts-pulse 1.5s ease-in-out infinite;
}

@keyframes tts-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
    }
}

/**
 * TTS indicator dot
 */
.a11y-tts-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #d1d5db;
    border-radius: 50%;
    margin-left: 6px;
    transition: background 0.3s ease;
}

.a11y-tts-indicator.active {
    background: #10b981;
    animation: tts-dot-blink 0.8s ease-in-out infinite;
}

@keyframes tts-dot-blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

/**
 * TTS enabled state - change cursor to indicate text can be selected for reading
 */
.a11y-tts-enabled {
    cursor: default;
}

.a11y-tts-enabled p,
.a11y-tts-enabled span,
.a11y-tts-enabled h1,
.a11y-tts-enabled h2,
.a11y-tts-enabled h3,
.a11y-tts-enabled h4,
.a11y-tts-enabled h5,
.a11y-tts-enabled h6,
.a11y-tts-enabled li,
.a11y-tts-enabled td,
.a11y-tts-enabled th,
.a11y-tts-enabled article,
.a11y-tts-enabled section {
    cursor: text;
}

/* Highlight selected text when TTS is enabled */
.a11y-tts-enabled ::selection {
    background: #10b981;
    color: #ffffff;
}

.a11y-tts-enabled ::-moz-selection {
    background: #10b981;
    color: #ffffff;
}

/* ==========================================================================
   Print Styles - Hide widget when printing
   ========================================================================== */

@media print {
    .a11y-widget {
        display: none !important;
    }
}