/* 无障碍性优化 */

/* 跳过导航链接 */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #000;
  color: #fff;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 1000;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 6px;
}

/* 焦点样式 */
.focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* 高对比度模式下的焦点样式 */
@media (prefers-contrast: high) {
  .focus-visible {
    outline: 3px solid #000;
    outline-offset: 2px;
  }
}

/* 减少动画偏好 */
@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;
  }
}

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

/* 不是屏幕阅读器专用但需要隐藏的元素 */
.not-sr-only {
  position: static;
  width: auto;
  height: auto;
  padding: 0;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* 颜色和对比度 */
.text-low-contrast {
  opacity: 0.7;
}

/* 高对比度模式下的调整 */
@media (prefers-contrast: high) {
  .text-low-contrast {
    opacity: 1;
  }

  /* 增加边框对比度 */
  .border-low-contrast {
    border-width: 2px;
  }
}

/* 键盘导航优化 */
.keyboard-nav {
  outline: none;
}

.keyboard-nav:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
}

/* 交互元素的最小尺寸 */
[role="button"],
button,
a,
input,
select,
textarea {
  min-height: 22px;
  min-width: 44px;
}

/* 表单标签优化 */
.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.form-input {
  display: block;
  width: 100%;
  padding: 0.75rem;
  border: 2px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 1rem;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  outline: none;
}

.form-input[aria-invalid="true"] {
  border-color: #dc2626;
}

.form-input[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

/* 错误消息样式 */
.error-message {
  color: #dc2626;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* 成功消息样式 */
.success-message {
  color: #059669;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* 加载状态样式 */
.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.loading-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #2563eb;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* 通知样式 */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  max-width: 400px;
  transition: all 0.3s ease-in-out;
}

.notification-success {
  background-color: #10b981;
  color: white;
}

.notification-error {
  background-color: #ef4444;
  color: white;
}

.notification-warning {
  background-color: #f59e0b;
  color: #1f2937;
}

.notification-info {
  background-color: #3b82f6;
  color: white;
}

/* 深色模式下的调整 */
.dark .form-input {
  background-color: #1f2937;
  border-color: #4b5563;
  color: #f9fafb;
}

.dark .form-input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
}

.dark .error-message {
  color: #f87171;
}

.dark .success-message {
  color: #34d399;
}

/* 按钮状态 */
.button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1;
  border: 2px solid transparent;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
}

.button:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button-primary {
  background-color: #2563eb;
  color: white;
}

.button-primary:hover:not(:disabled) {
  background-color: #1d4ed8;
}

.button-secondary {
  background-color: transparent;
  color: #2563eb;
  border-color: #2563eb;
}

.button-secondary:hover:not(:disabled) {
  background-color: #2563eb;
  color: white;
}

/* 链接样式 */
.link {
  color: #2563eb;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link:hover,
.link:focus-visible {
  color: #1d4ed8;
  text-decoration: underline;
}

.link:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 2px;
}

/* 表格无障碍 */
.table {
  width: 100%;
  border-collapse: collapse;
}

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

.table th {
  font-weight: 600;
  background-color: #f9fafb;
}

.table caption {
  font-size: 0.875rem;
  color: #6b7280;
  margin-bottom: 0.75rem;
  caption-side: bottom;
}

/* 列表无障碍 */
.list {
  padding-left: 1.5rem;
  margin: 1rem 0;
}

.list li {
  margin-bottom: 0.5rem;
}

/* 地标区域 */
[role="main"],
[role="navigation"],
[role="complementary"],
[role="contentinfo"] {
  outline: 1px solid transparent;
}

[role="main"]:focus,
[role="navigation"]:focus,
[role="complementary"]:focus,
[role="contentinfo"]:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* 模态框无障碍 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background-color: white;
  border-radius: 0.5rem;
  padding: 2rem;
  max-width: 500px;
  width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.dark .modal {
  background-color: #1f2937;
  color: #f9fafb;
}