/* ==================== 可访问性改进 ==================== */

/* 焦点样式优化 */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 4px;
}

.btn:focus-visible {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
    outline: none;
}

.link-item:focus-visible {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
    transform: translateY(-2px);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* 跳过导航链接 */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 0 0 8px 0;
    z-index: 10000;
    transition: top 0.3s ease;
}

.skip-to-content:focus {
    top: 0;
}

/* 键盘导航指示器 */
.keyboard-nav-active *:focus {
    outline: 2px dashed var(--primary-color);
    outline-offset: 4px;
}

/* ARIA实时区域 */
[aria-live="polite"],
[aria-live="assertive"] {
    position: relative;
}

/* 屏幕阅读器专用文本 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* 高对比度模式 */
@media (prefers-contrast: high) {

    .btn,
    .link-item,
    .mode-btn,
    input,
    textarea,
    select {
        border: 2px solid currentColor;
    }

    .btn:hover,
    .link-item:hover {
        border-width: 3px;
    }

    *:focus-visible {
        outline-width: 3px;
        outline-offset: 3px;
    }
}

/* 强制颜色模式支持 (Windows高对比度) */
@media (forced-colors: active) {
    .btn {
        border: 1px solid ButtonText;
    }

    .btn:hover {
        forced-color-adjust: none;
        background: Highlight;
        color: HighlightText;
    }

    .link-item {
        border: 1px solid CanvasText;
    }
}

/* 焦点陷阱 - 用于模态框 */
.focus-trap {
    position: relative;
}

.focus-trap::before,
.focus-trap::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
}

/* 键盘快捷键提示 */
.keyboard-hint {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: monospace;
    color: var(--text-muted);
    margin-left: 8px;
}

.keyboard-hint kbd {
    background: var(--bg-secondary);
    padding: 2px 4px;
    border-radius: 3px;
    border: 1px solid var(--border-color);
    font-weight: 600;
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {

    /* 增大触摸目标 */
    .btn,
    .link-item,
    .mode-btn {
        min-height: 48px;
        min-width: 48px;
    }

    /* 移除悬停效果 */
    .btn:hover,
    .link-item:hover {
        transform: none;
    }

    /* 添加触摸反馈 */
    .btn:active,
    .link-item:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
}

/* 文本缩放支持 */
@media (min-resolution: 2dppx) {
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* 语言方向支持 (RTL) */
[dir="rtl"] .side-panel {
    left: 0;
    right: auto;
}

[dir="rtl"] .mobile-nav-menu {
    left: 0;
    right: auto;
}

[dir="rtl"] .error-message,
[dir="rtl"] .warning-message,
[dir="rtl"] .info-message {
    border-left: none;
    border-right: 4px solid currentColor;
}

/* 打印可访问性 */
@media print {

    .skip-to-content,
    .keyboard-hint {
        display: none;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}