/**
 * 無障礙功能樣式表 - WCAG 2.1 AA 等級
 * 包含無障礙工具列、高對比模式、焦點樣式等
 */

/* ========================================
   螢幕閱讀器專用樣式
   ======================================== */
.sr-only,
.sr-only-focusable:not(:focus):not(:focus-within) {
  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;
}

.sr-only-focusable:focus,
.sr-only-focusable:focus-within {
  position: static !important;
  width: auto !important;
  height: auto !important;
  overflow: visible !important;
  clip: auto !important;
  white-space: normal !important;
}

/* ========================================
   跳過導覽連結
   ======================================== */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 10000;
  font-weight: bold;
  border-radius: 0 0 4px 0;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid #ffbf47;
  outline-offset: 0;
}

/* ========================================
   無障礙工具列
   ======================================== */
.accessibility-toolbar {
  position: fixed;
  top: 20%;
  right: 0;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* 工具列切換按鈕 */
.a11y-toggle-btn {
  position: absolute;
  right: 0;
  top: 0;
  width: 50px;
  height: 50px;
  background: #0066cc;
  color: #fff;
  border: none;
  border-radius: 8px 0 0 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: -2px 2px 8px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

.a11y-toggle-btn:hover {
  background: #0052a3;
  width: 55px;
}

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

/* 工具列面板 */
.a11y-panel {
  position: absolute;
  right: 50px;
  top: 0;
  width: 320px;
  background: #fff;
  border-radius: 8px 0 0 8px;
  box-shadow: -4px 4px 16px rgba(0, 0, 0, 0.2);
  max-height: 80vh;
  overflow-y: auto;
}

.a11y-panel[hidden] {
  display: none;
}

.a11y-panel-title {
  margin: 0;
  padding: 20px;
  font-size: 18px;
  font-weight: bold;
  border-bottom: 2px solid #e0e0e0;
  color: #333;
}

/* 控制項容器 */
.a11y-controls {
  padding: 16px;
}

.a11y-control-group {
  margin-bottom: 16px;
}

.a11y-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #555;
  margin-bottom: 8px;
}

/* 按鈕群組 */
.a11y-button-group {
  display: flex;
  gap: 8px;
}

.a11y-btn {
  flex: 1;
  padding: 10px;
  background: #f5f5f5;
  border: 2px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: #333;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.a11y-btn:hover {
  background: #e8e8e8;
  border-color: #0066cc;
}

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

.a11y-btn:active {
  transform: scale(0.95);
}

/* 全寬按鈕 */
.a11y-btn-full {
  width: 100%;
  padding: 12px 16px;
  background: #f5f5f5;
  border: 2px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: #333;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.a11y-btn-full:hover {
  background: #e8e8e8;
  border-color: #0066cc;
}

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

.a11y-btn-full[aria-pressed="true"] {
  background: #0066cc;
  color: #fff;
  border-color: #0066cc;
}

.a11y-btn-full i {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

/* ========================================
   高對比模式
   ======================================== */
body.high-contrast {
  background: #000 !important;
  color: #fff !important;
}

body.high-contrast * {
  background-color: #000 !important;
  color: #fff !important;
  border-color: #fff !important;
}

body.high-contrast a {
  color: #ffff00 !important;
  text-decoration: underline !important;
}

body.high-contrast button,
body.high-contrast .btn {
  background: #fff !important;
  color: #000 !important;
  border: 2px solid #fff !important;
}

body.high-contrast img {
  opacity: 0.8;
  border: 1px solid #fff !important;
}

body.high-contrast .a11y-toggle-btn,
body.high-contrast .a11y-panel {
  background: #000 !important;
  color: #fff !important;
  border: 2px solid #fff !important;
}

/* ========================================
   閱讀輔助線
   ======================================== */
.reading-guide {
  position: fixed;
  left: 0;
  width: 100%;
  height: 3px;
  background: rgba(255, 191, 71, 0.8);
  pointer-events: none;
  z-index: 9998;
  box-shadow: 0 0 20px rgba(255, 191, 71, 0.5);
  transition: top 0.1s ease;
}

.reading-guide::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 0;
  width: 100%;
  height: 26px;
  background: linear-gradient(to bottom, 
    rgba(255, 191, 71, 0.1) 0%,
    rgba(255, 191, 71, 0.3) 50%,
    rgba(255, 191, 71, 0.1) 100%
  );
}

/* ========================================
   焦點指示器
   ======================================== */
.focus-indicator {
  position: absolute;
  pointer-events: none;
  border: 3px solid #0066cc;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0, 102, 204, 0.5);
  transition: all 0.15s ease;
  z-index: 9997;
  display: none;
}

/* 增強的焦點樣式 */
*:focus {
  outline: 3px solid #ffbf47 !important;
  outline-offset: 2px !important;
}

a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid #ffbf47 !important;
  outline-offset: 2px !important;
}

/* ========================================
   語音朗讀模式
   ======================================== */
body.speech-enabled p:hover,
body.speech-enabled h1:hover,
body.speech-enabled h2:hover,
body.speech-enabled h3:hover,
body.speech-enabled h4:hover,
body.speech-enabled h5:hover,
body.speech-enabled h6:hover,
body.speech-enabled li:hover,
body.speech-enabled a:hover,
body.speech-enabled button:hover {
  background: rgba(255, 191, 71, 0.2) !important;
  cursor: pointer;
}

/* ========================================
   模態對話框
   ======================================== */
.a11y-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.a11y-modal-content {
  background: #fff;
  border-radius: 8px;
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.a11y-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  border-bottom: 2px solid #e0e0e0;
}

.a11y-modal-header h2 {
  margin: 0;
  font-size: 24px;
  color: #333;
}

.a11y-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.a11y-modal-close:hover {
  background: #f5f5f5;
  color: #333;
}

.a11y-modal-close:focus {
  outline: 3px solid #ffbf47;
  outline-offset: 2px;
}

.a11y-modal-body {
  padding: 24px;
}

.a11y-modal-footer {
  padding: 16px 24px;
  border-top: 2px solid #e0e0e0;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* ========================================
   鍵盤快速鍵表格
   ======================================== */
.a11y-keyboard-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
}

.a11y-keyboard-table th {
  background: #f5f5f5;
  padding: 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid #ddd;
}

.a11y-keyboard-table td {
  padding: 12px;
  border-bottom: 1px solid #e0e0e0;
}

.a11y-keyboard-table kbd {
  display: inline-block;
  padding: 4px 8px;
  background: #333;
  color: #fff;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  margin: 0 2px;
}

.a11y-accesskey-list {
  list-style: none;
  padding: 0;
  margin: 20px 0 0 0;
}

.a11y-accesskey-list li {
  padding: 10px;
  border-left: 3px solid #0066cc;
  margin-bottom: 8px;
  background: #f8f8f8;
}

/* ========================================
   無障礙檢查報告
   ======================================== */
.a11y-report-modal .a11y-modal-content {
  max-width: 900px;
}

.a11y-report-summary {
  margin-bottom: 24px;
}

.a11y-score {
  text-align: center;
  padding: 30px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.a11y-score.success {
  background: #d4edda;
  border: 2px solid #28a745;
}

.a11y-score.warning {
  background: #fff3cd;
  border: 2px solid #ffc107;
}

.a11y-score.error {
  background: #f8d7da;
  border: 2px solid #dc3545;
}

.a11y-score i {
  font-size: 48px;
  margin-bottom: 10px;
}

.a11y-score.success i {
  color: #28a745;
}

.a11y-score.warning i {
  color: #ffc107;
}

.a11y-score.error i {
  color: #dc3545;
}

.score-text {
  display: block;
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

.a11y-stats {
  display: flex;
  justify-content: space-around;
  gap: 20px;
}

.stat-item {
  flex: 1;
  text-align: center;
  padding: 16px;
  background: #f8f8f8;
  border-radius: 6px;
}

.stat-label {
  display: block;
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.stat-value {
  display: block;
  font-size: 32px;
  font-weight: bold;
}

.stat-value.error {
  color: #dc3545;
}

.stat-value.warning {
  color: #ffc107;
}

/* 問題列表 */
.a11y-issues-list {
  margin-top: 24px;
}

.a11y-issue-item {
  margin-bottom: 16px;
  border-left: 4px solid #ddd;
  background: #f8f8f8;
  border-radius: 4px;
  overflow: hidden;
}

.a11y-issue-item.level-a {
  border-left-color: #dc3545;
}

.a11y-issue-item.level-aa {
  border-left-color: #ffc107;
}

.issue-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #fff;
}

.issue-level {
  display: inline-block;
  padding: 4px 8px;
  background: #333;
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
}

.a11y-issue-item.level-a .issue-level {
  background: #dc3545;
}

.a11y-issue-item.level-aa .issue-level {
  background: #ffc107;
  color: #333;
}

.issue-type {
  font-weight: 600;
  color: #333;
  flex: 1;
}

.issue-details {
  padding: 12px 16px;
}

.issue-details p {
  margin: 8px 0;
  font-size: 14px;
  color: #555;
}

.issue-details strong {
  color: #333;
}

/* 成功訊息 */
.a11y-success-message {
  text-align: center;
  padding: 40px;
}

.a11y-success-message i {
  font-size: 64px;
  color: #28a745;
  margin-bottom: 20px;
}

.a11y-success-message p {
  font-size: 18px;
  color: #555;
  margin: 0;
}

/* 報告註腳 */
.a11y-report-footer {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 2px solid #e0e0e0;
}

.a11y-disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  background: #e7f3ff;
  border-radius: 6px;
  font-size: 14px;
  color: #0066cc;
  margin: 0;
}

.a11y-disclaimer i {
  font-size: 20px;
  margin-top: 2px;
}

/* ========================================
   按鈕樣式
   ======================================== */
.a11y-btn-primary {
  padding: 10px 24px;
  background: #0066cc;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.a11y-btn-primary:hover {
  background: #0052a3;
}

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

.a11y-btn-primary:active {
  transform: scale(0.95);
}

/* ========================================
   ARIA 即時通知區域
   ======================================== */
#a11y-announcer {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ========================================
   響應式設計
   ======================================== */
@media (max-width: 768px) {
  .accessibility-toolbar {
    top: auto;
    bottom: 20px;
    right: 10px;
  }

  .a11y-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .a11y-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    top: auto;
    width: 100%;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
  }

  .a11y-modal {
    padding: 10px;
  }

  .a11y-modal-content {
    max-height: 95vh;
  }

  .a11y-keyboard-table {
    font-size: 14px;
  }

  .a11y-keyboard-table th,
  .a11y-keyboard-table td {
    padding: 8px;
  }
}

@media (max-width: 480px) {
  .a11y-stats {
    flex-direction: column;
  }

  .a11y-button-group {
    flex-direction: column;
  }

  .a11y-btn {
    width: 100%;
  }
}

/* ========================================
   列印樣式
   ======================================== */
@media print {
  .accessibility-toolbar,
  .a11y-modal,
  .reading-guide,
  .focus-indicator,
  .skip-link {
    display: none !important;
  }
}

/* ========================================
   動畫偏好設定
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .reading-guide {
    transition: none;
  }
}

/* ========================================
   深色模式支援
   ======================================== */
@media (prefers-color-scheme: dark) {
  .a11y-panel,
  .a11y-modal-content {
    background: #1e1e1e;
    color: #fff;
  }

  .a11y-panel-title,
  .a11y-modal-header h2 {
    color: #fff;
    border-bottom-color: #444;
  }

  .a11y-btn,
  .a11y-btn-full {
    background: #2d2d2d;
    color: #fff;
    border-color: #444;
  }

  .a11y-btn:hover,
  .a11y-btn-full:hover {
    background: #3d3d3d;
  }

  .a11y-keyboard-table th {
    background: #2d2d2d;
  }

  .a11y-keyboard-table td {
    border-bottom-color: #444;
  }

  .issue-details p {
    color: #ccc;
  }

  .a11y-issue-item {
    background: #2d2d2d;
  }

  .issue-header {
    background: #1e1e1e;
  }
}
