/**
 * Cassiopeia HTSprout - 無障礙樣式
 * 符合 WCAG 2.1 Level AA 標準
 *
 * @package     Joomla.Site
 * @subpackage  Templates.cassiopeia_htsprout
 * @copyright   Copyright (C) 2026 HTSprout. All rights reserved.
 * @license     GNU General Public License version 2 or later
 */

/* ============================================
   1. 螢幕閱讀器專用 (sr-only)
   ============================================ */
.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;
}

/* 焦點時顯示 */
.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ============================================
   2. 跳過連結
   ============================================ */
.skip-to-content {
  position: absolute;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  white-space: nowrap;
}

.skip-to-content:focus {
  position: fixed;
  top: 0;
  left: 0;
  clip: auto;
  width: auto;
  height: auto;
  margin: 0;
  padding: 8px 16px;
  z-index: 10000;
  background: var(--htsprout-green-800, #135B71);
  color: #ffffff;
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 4px 0;
  outline: 3px solid var(--focus-color, #0d6efd);
  outline-offset: 2px;
  white-space: normal;
  overflow: visible;
}

/* ============================================
   3. 焦點指示器增強
   ============================================ */
body.keyboard-nav *:focus {
  outline: 3px solid var(--focus-color, #0d6efd) !important;
  outline-offset: 2px !important;
}

/* 確保足夠的對比度 (3:1) */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid var(--focus-color, #0d6efd);
  outline-offset: 2px;
}

/* ============================================
   4. 無障礙工具列（可收合/展開式字體調整器）
   ============================================ */
.accessibility-toolbar {
  padding: 0.5rem 0;
}

.font-adjuster {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

/* 按鈕群組容器 */
.font-adjuster-group {
  display: flex;
  gap: 0;
  position: relative;
}

/* 所有按鈕基礎樣式 */
.font-size-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--cassiopeia-color-primary, #132f53);
  background: transparent;
  color: var(--cassiopeia-color-primary, #132f53);
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  transition: background 0.2s, color 0.2s, opacity 0.2s, width 0.2s, padding 0.2s, min-width 0.2s, border-width 0.2s;
}

/* 收合狀態：隱藏非 active 按鈕 */
.font-adjuster-group:not(.is-expanded) .font-size-btn:not(.active) {
  width: 0;
  min-width: 0;
  padding: 0;
  border-width: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* 目前大小按鈕（active） */
.font-size-btn.active {
  background: var(--cassiopeia-color-primary, #132f53);
  color: #fff;
}

/* hover 狀態（非 active 按鈕） */
.font-size-btn:hover:not(.active) {
  background: var(--cassiopeia-color-hover, #f0f0f0);
}

/* focus 狀態 */
.font-size-btn:focus-visible {
  outline: 3px solid var(--focus-color, #0d6efd);
  outline-offset: 2px;
}

/* ============================================
   5. 顏色對比度增強
   ============================================ */
/* 確保連結有足夠對比度 (4.5:1) */
a {
  color: var(--cassiopeia-color-link, #0d6efd);
  text-decoration: underline;
}

/* 標題內連結：預設無底線，互動時才顯示 */
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  text-decoration: none;
}

h1 a:hover, h1 a:focus, h1 a:active,
h2 a:hover, h2 a:focus, h2 a:active,
h3 a:hover, h3 a:focus, h3 a:active,
h4 a:hover, h4 a:focus, h4 a:active,
h5 a:hover, h5 a:focus, h5 a:active,
h6 a:hover, h6 a:focus, h6 a:active {
  text-decoration: underline;
}

a:hover {
  color: var(--cassiopeia-color-link-hover, #0a58ca);
}

/* ============================================
   6. 表單無障礙
   ============================================ */
label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

input:invalid,
select:invalid,
textarea:invalid {
  border-color: #dc3545;
}

.form-error {
  color: #dc3545;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: block;
}

/* ============================================
   7. 高對比模式支援
   ============================================ */
@media (prefers-contrast: high) {
  * {
    border-color: currentColor !important;
  }

}

/* ============================================
   9. 減少動畫（尊重使用者偏好）
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
