/**
 * 可访问性增强 CSS
 */

/* ========== 焦点样式 ========== */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--color-primary, #5f8f7a);
    outline-offset: 2px;
    border-radius: 4px;
}

/* 跳过导航链接 */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary, #5f8f7a);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    border-radius: 0 0 4px 0;
    font-weight: 500;
}

.skip-link:focus {
    top: 0;
}

/* ========== 键盘导航样式 ========== */
kbd {
    display: inline-block;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 0.875rem;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.shortcuts-table {
    width: 100%;
    border-collapse: collapse;
}

.shortcuts-table th,
.shortcuts-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.shortcuts-table th {
    font-weight: 600;
    background: #f8fafc;
}

/* ========== 屏幕阅读器专用 ========== */
.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;
}

/* ========== 减少动画（用户偏好） ========== */
@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;
    }
}

/* ========== 高对比度模式 ========== */
@media (prefers-contrast: high) {
    :root {
        --color-text: #000000;
        --color-bg: #ffffff;
        --color-border: #000000;
    }

    .button {
        border: 2px solid currentColor;
    }
}

/* ========== 暗色模式支持 ========== */
@media (prefers-color-scheme: dark) {
    :root {
        --color-text: #f8fafc;
        --color-textMuted: #cbd5e1;
        --color-bg: #1e293b;
        --color-bgDeep: #0f172a;
        --color-surface: #334155;
        --color-border: rgba(255, 255, 255, 0.1);
    }
}

/* ========== 触摸目标大小 ========== */
button,
a,
input[type="checkbox"],
input[type="radio"] {
    min-width: 44px;
    min-height: 44px;
}

/* ========== 文本可读性 ========== */
p,
li,
td {
    max-width: 70ch; /* 最佳阅读宽度 */
}

/* 行高 */
body {
    line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
}

/* ========== 颜色对比度 ========== */
.text-muted {
    color: var(--color-textMuted, #52657a);
}

/* 确保链接可识别 */
a {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

a:hover {
    text-decoration-thickness: 2px;
}

/* ========== 表单可访问性 ========== */
label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
}

input:invalid,
select:invalid,
textarea:invalid {
    border-color: var(--color-danger, #dc2626);
}

input:invalid:focus,
select:invalid:focus,
textarea:invalid:focus {
    outline-color: var(--color-danger, #dc2626);
}

.error-message {
    color: var(--color-danger, #dc2626);
    font-size: 0.875rem;
    margin-top: 4px;
}

/* ========== 加载状态可访问性 ========== */
[aria-busy="true"] {
    cursor: wait;
}

[aria-disabled="true"] {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* ========== 屏幕阅读器实时提示 ==========
   不要按 aria-live 全局隐藏元素；页面主体也会用 aria-live 做动态内容区。 */
.sr-only[aria-live],
.sr-live,
.visually-hidden[aria-live] {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}
