/**
 * PMN Assess Liberty - Accessibility Widget Styles
 * WCAG 2.1 Compliant Accessibility Tools
 * Version: 1.1.0
 */

/* ============================================
   CSS Variables
   ============================================ */
:root {
    --pmn-a11y-primary: #1976d2;
    --pmn-a11y-primary-dark: #1565c0;
    --pmn-a11y-primary-light: #42a5f5;
    --pmn-a11y-bg: #ffffff;
    --pmn-a11y-text: #333333;
    --pmn-a11y-text-secondary: #666666;
    --pmn-a11y-border: #e0e0e0;
    --pmn-a11y-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --pmn-a11y-radius: 12px;
    --pmn-a11y-transition: 0.3s ease;
    --pmn-a11y-panel-width: 320px;
    --pmn-a11y-z-index: 999999;
}

/* ============================================
   Screen Reader Only
   ============================================ */
.pmn-a11y-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;
}

/* ============================================
   Widget Container
   ============================================ */
.pmn-a11y-widget {
    position: fixed;
    z-index: var(--pmn-a11y-z-index);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Thai', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--pmn-a11y-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Position Classes */
.pmn-a11y-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.pmn-a11y-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.pmn-a11y-position-top-left {
    top: 20px;
    left: 20px;
}

.pmn-a11y-position-top-right {
    top: 20px;
    right: 20px;
}

/* ============================================
   Toggle Button
   ============================================ */
.pmn-a11y-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--pmn-a11y-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--pmn-a11y-shadow);
    transition: transform var(--pmn-a11y-transition), background var(--pmn-a11y-transition);
    position: relative;
}

.pmn-a11y-toggle:hover {
    transform: scale(1.1);
    background: var(--pmn-a11y-primary-dark);
}

.pmn-a11y-toggle:focus {
    outline: 3px solid var(--pmn-a11y-primary-light);
    outline-offset: 3px;
}

.pmn-a11y-toggle:focus:not(:focus-visible) {
    outline: none;
}

.pmn-a11y-toggle:focus-visible {
    outline: 3px solid var(--pmn-a11y-primary-light);
    outline-offset: 3px;
}

.pmn-a11y-toggle[aria-expanded="true"] {
    background: var(--pmn-a11y-primary-dark);
}

.pmn-a11y-icon {
    width: 28px;
    height: 28px;
    color: #ffffff;
}

/* Pulse Animation */
.pmn-a11y-toggle::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--pmn-a11y-primary);
    opacity: 0;
    animation: pmn-pulse 2s ease-out infinite;
    pointer-events: none;
}

@keyframes pmn-pulse {
    0% {
        transform: scale(1);
        opacity: 0.4;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* ============================================
   Panel
   ============================================ */
.pmn-a11y-panel {
    position: absolute;
    width: var(--pmn-a11y-panel-width);
    max-height: 80vh;
    background: var(--pmn-a11y-bg);
    border-radius: var(--pmn-a11y-radius);
    box-shadow: var(--pmn-a11y-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    opacity: 0;
    visibility: hidden;
    transition: transform var(--pmn-a11y-transition),
                opacity var(--pmn-a11y-transition),
                visibility var(--pmn-a11y-transition);
}

.pmn-a11y-panel:not([hidden]) {
    transform: scale(1);
    opacity: 1;
    visibility: visible;
}

/* Panel Position based on widget position */
.pmn-a11y-position-bottom-left .pmn-a11y-panel {
    bottom: 70px;
    left: 0;
}

.pmn-a11y-position-bottom-right .pmn-a11y-panel {
    bottom: 70px;
    right: 0;
}

.pmn-a11y-position-top-left .pmn-a11y-panel {
    top: 70px;
    left: 0;
}

.pmn-a11y-position-top-right .pmn-a11y-panel {
    top: 70px;
    right: 0;
}

/* ============================================
   Panel Header
   ============================================ */
.pmn-a11y-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--pmn-a11y-primary);
    color: #ffffff;
}

.pmn-a11y-panel-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.pmn-a11y-title-icon {
    width: 24px;
    height: 24px;
}

.pmn-a11y-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--pmn-a11y-transition);
}

.pmn-a11y-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.pmn-a11y-close:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.pmn-a11y-close svg {
    width: 20px;
    height: 20px;
    color: #ffffff;
}

/* ============================================
   Panel Content
   ============================================ */
.pmn-a11y-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--pmn-a11y-border) transparent;
}

.pmn-a11y-content::-webkit-scrollbar {
    width: 6px;
}

.pmn-a11y-content::-webkit-scrollbar-track {
    background: transparent;
}

.pmn-a11y-content::-webkit-scrollbar-thumb {
    background: var(--pmn-a11y-border);
    border-radius: 3px;
}

/* ============================================
   Sections
   ============================================ */
.pmn-a11y-section {
    padding: 12px 20px;
    border-bottom: 1px solid var(--pmn-a11y-border);
}

.pmn-a11y-section:last-child {
    border-bottom: none;
}

.pmn-a11y-section-title {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--pmn-a11y-text);
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pmn-a11y-section-title svg {
    width: 18px;
    height: 18px;
    color: var(--pmn-a11y-primary);
}

/* ============================================
   Font Size Controls
   ============================================ */
.pmn-a11y-font-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: #f5f5f5;
    padding: 12px;
    border-radius: 8px;
}

.pmn-a11y-font-btn {
    width: 44px;
    height: 44px;
    border: 2px solid var(--pmn-a11y-border);
    background: var(--pmn-a11y-bg);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--pmn-a11y-text);
    transition: all var(--pmn-a11y-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.pmn-a11y-font-btn:hover {
    border-color: var(--pmn-a11y-primary);
    color: var(--pmn-a11y-primary);
}

.pmn-a11y-font-btn:focus {
    outline: 2px solid var(--pmn-a11y-primary);
    outline-offset: 2px;
}

.pmn-a11y-font-btn:active {
    transform: scale(0.95);
}

.pmn-a11y-font-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--pmn-a11y-primary);
    min-width: 60px;
    text-align: center;
}

/* ============================================
   Toggle Options
   ============================================ */
.pmn-a11y-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pmn-a11y-toggle-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: #f9f9f9;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--pmn-a11y-transition);
}

.pmn-a11y-toggle-option:hover {
    background: #f0f0f0;
}

.pmn-a11y-toggle-option:focus-within {
    outline: 2px solid var(--pmn-a11y-primary);
    outline-offset: 2px;
}

.pmn-a11y-checkbox {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.pmn-a11y-toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: #ccc;
    border-radius: 12px;
    flex-shrink: 0;
    transition: background var(--pmn-a11y-transition);
}

.pmn-a11y-toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform var(--pmn-a11y-transition);
}

.pmn-a11y-checkbox:checked + .pmn-a11y-toggle-switch {
    background: var(--pmn-a11y-primary);
}

.pmn-a11y-checkbox:checked + .pmn-a11y-toggle-switch::after {
    transform: translateX(20px);
}

.pmn-a11y-checkbox:focus + .pmn-a11y-toggle-switch {
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.3);
}

.pmn-a11y-toggle-label {
    font-size: 14px;
    color: var(--pmn-a11y-text);
    flex: 1;
}

/* ============================================
   Panel Footer
   ============================================ */
.pmn-a11y-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--pmn-a11y-border);
}

.pmn-a11y-reset {
    width: 100%;
    padding: 12px 20px;
    border: 2px solid var(--pmn-a11y-border);
    background: var(--pmn-a11y-bg);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--pmn-a11y-text);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--pmn-a11y-transition);
}

.pmn-a11y-reset:hover {
    border-color: #dc3545;
    color: #dc3545;
}

.pmn-a11y-reset:focus {
    outline: 2px solid var(--pmn-a11y-primary);
    outline-offset: 2px;
}

.pmn-a11y-reset svg {
    width: 18px;
    height: 18px;
}

/* ============================================
   Reading Guide
   ============================================ */
.pmn-a11y-reading-guide {
    position: fixed;
    left: 0;
    right: 0;
    height: 40px;
    background: rgba(255, 255, 0, 0.3);
    border-top: 2px solid rgba(255, 200, 0, 0.8);
    border-bottom: 2px solid rgba(255, 200, 0, 0.8);
    pointer-events: none;
    z-index: calc(var(--pmn-a11y-z-index) - 1);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
}

.pmn-a11y-reading-guide.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   Screen Mask
   ============================================ */
.pmn-a11y-screen-mask {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: calc(var(--pmn-a11y-z-index) - 2);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

.pmn-a11y-screen-mask.active {
    opacity: 1;
    visibility: visible;
}

.pmn-a11y-mask-top,
.pmn-a11y-mask-bottom {
    position: absolute;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    transition: all 0.1s ease;
}

.pmn-a11y-mask-top {
    top: 0;
    height: 40%;
}

.pmn-a11y-mask-bottom {
    bottom: 0;
    height: 40%;
}

/* ============================================
   TTS Tooltip
   ============================================ */
.pmn-a11y-tts-tooltip {
    position: fixed;
    background: var(--pmn-a11y-primary);
    border-radius: 8px;
    padding: 4px;
    box-shadow: var(--pmn-a11y-shadow);
    z-index: calc(var(--pmn-a11y-z-index) + 1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
}

.pmn-a11y-tts-tooltip.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.pmn-a11y-tts-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    transition: background 0.2s ease;
}

.pmn-a11y-tts-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.pmn-a11y-tts-btn svg {
    width: 24px;
    height: 24px;
}

/* ============================================
   Accessibility Modifier Classes
   ============================================ */

/* Font Size Levels */
body.pmn-a11y-font-size-1 {
    font-size: 100% !important;
}

body.pmn-a11y-font-size-2 {
    font-size: 125% !important;
}

body.pmn-a11y-font-size-3 {
    font-size: 150% !important;
}

body.pmn-a11y-font-size-4 {
    font-size: 175% !important;
}

body.pmn-a11y-font-size-5 {
    font-size: 200% !important;
}

/* High Contrast */
body.pmn-a11y-high-contrast {
    filter: contrast(1.5) !important;
}

body.pmn-a11y-high-contrast * {
    border-color: #000 !important;
}

body.pmn-a11y-high-contrast a {
    color: #0000EE !important;
}

body.pmn-a11y-high-contrast a:visited {
    color: #551A8B !important;
}

/* Grayscale */
body.pmn-a11y-grayscale {
    filter: grayscale(100%) !important;
}

/* Invert Colors */
body.pmn-a11y-invert-colors {
    filter: invert(100%) hue-rotate(180deg) !important;
}

body.pmn-a11y-invert-colors img,
body.pmn-a11y-invert-colors video,
body.pmn-a11y-invert-colors iframe,
body.pmn-a11y-invert-colors .pmn-a11y-widget {
    filter: invert(100%) hue-rotate(180deg) !important;
}

/* Line Height */
body.pmn-a11y-line-height * {
    line-height: 2 !important;
}

/* Letter Spacing */
body.pmn-a11y-letter-spacing * {
    letter-spacing: 0.12em !important;
}

/* Word Spacing */
body.pmn-a11y-word-spacing * {
    word-spacing: 0.16em !important;
}

/* Readable Font */
body.pmn-a11y-readable-font,
body.pmn-a11y-readable-font * {
    font-family: Arial, Helvetica, 'Noto Sans Thai', sans-serif !important;
}

/* Highlight Links */
body.pmn-a11y-highlight-links a {
    background-color: #ffff00 !important;
    color: #000000 !important;
    padding: 2px 4px !important;
    text-decoration: none !important;
}

body.pmn-a11y-highlight-links a:hover {
    background-color: #ff9900 !important;
}

/* Underline Links */
body.pmn-a11y-underline-links a {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 3px !important;
}

/* Big Cursor */
body.pmn-a11y-big-cursor,
body.pmn-a11y-big-cursor * {
    cursor: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24"><path fill="%23000" stroke="%23fff" stroke-width="1" d="M5.5 3.21V20.8l5.32-5.32h7.89L5.5 3.21z"/></svg>') 0 0, auto !important;
}

body.pmn-a11y-big-cursor a,
body.pmn-a11y-big-cursor button,
body.pmn-a11y-big-cursor [role="button"],
body.pmn-a11y-big-cursor input[type="submit"],
body.pmn-a11y-big-cursor input[type="button"],
body.pmn-a11y-big-cursor label {
    cursor: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24"><path fill="%23000" stroke="%23fff" stroke-width="1" d="M10.5 8a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3zm3 3a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3zM12 16.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/></svg>') 12 0, pointer !important;
}

/* Focus Highlight */
body.pmn-a11y-focus-highlight *:focus {
    outline: 4px solid #ff6600 !important;
    outline-offset: 4px !important;
    box-shadow: 0 0 0 8px rgba(255, 102, 0, 0.3) !important;
}

/* Pause Animations */
body.pmn-a11y-pause-animations,
body.pmn-a11y-pause-animations * {
    animation: none !important;
    transition: none !important;
}

body.pmn-a11y-pause-animations *::before,
body.pmn-a11y-pause-animations *::after {
    animation: none !important;
    transition: none !important;
}

/* Hide Images */
body.pmn-a11y-hide-images img,
body.pmn-a11y-hide-images svg:not(.pmn-a11y-icon):not(.pmn-a11y-title-icon),
body.pmn-a11y-hide-images picture,
body.pmn-a11y-hide-images [role="img"],
body.pmn-a11y-hide-images figure img {
    opacity: 0.1 !important;
}

/* ============================================
   Dark Mode Support
   ============================================ */
@media (prefers-color-scheme: dark) {
    :root {
        --pmn-a11y-bg: #2d2d2d;
        --pmn-a11y-text: #ffffff;
        --pmn-a11y-text-secondary: #b0b0b0;
        --pmn-a11y-border: #404040;
    }

    .pmn-a11y-toggle-option {
        background: #383838;
    }

    .pmn-a11y-toggle-option:hover {
        background: #424242;
    }

    .pmn-a11y-font-controls {
        background: #383838;
    }

    .pmn-a11y-font-btn {
        background: #2d2d2d;
        border-color: #505050;
        color: #ffffff;
    }
}

/* ============================================
   Responsive Styles
   ============================================ */
@media (max-width: 480px) {
    .pmn-a11y-widget {
        bottom: 10px !important;
        left: 10px !important;
        right: auto !important;
        top: auto !important;
    }

    .pmn-a11y-panel {
        position: fixed !important;
        bottom: 76px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: none !important;
    }

    .pmn-a11y-toggle {
        width: 50px;
        height: 50px;
    }

    .pmn-a11y-icon {
        width: 24px;
        height: 24px;
    }
}

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .pmn-a11y-toggle::before {
        animation: none;
    }

    .pmn-a11y-panel,
    .pmn-a11y-toggle,
    .pmn-a11y-toggle-switch,
    .pmn-a11y-toggle-switch::after,
    .pmn-a11y-reading-guide,
    .pmn-a11y-screen-mask,
    .pmn-a11y-tts-tooltip {
        transition: none;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .pmn-a11y-widget {
        display: none !important;
    }
}
