/**
 * 접근성 개선 CSS
 * WCAG 2.1 준수를 위한 스타일
 * 
 * @since 2025-07-02
 */

/* ===================================
   스크린 리더 전용 텍스트
   =================================== */
   
.screen-reader-text,
.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.screen-reader-text:focus {
    position: absolute !important;
    width: auto;
    height: auto;
    padding: 15px 20px;
    margin: 10px;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: #000;
    color: #fff;
    text-decoration: none;
    font-size: 16px;
    font-weight: bold;
    z-index: 100000;
    border-radius: 3px;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}

/* ===================================
   Skip Links
   =================================== */
   
.skip-links {
    position: absolute;
    top: -40px;
    left: 0;
    background: #000;
    z-index: 999999;
}

.skip-link {
    display: block;
    padding: 10px 15px;
    color: #fff;
    text-decoration: none;
}

.skip-link:focus {
    position: absolute;
    top: 40px;
    outline: 3px solid #ff0;
}

/* ===================================
   포커스 스타일
   =================================== */
   
/* 기본 포커스 스타일 강화 */
:focus {
    outline: 3px solid #0073aa;
    outline-offset: 2px;
}

/* 버튼 포커스 */
button:focus,
.button:focus,
input[type="button"]:focus,
input[type="submit"]:focus {
    outline: 3px solid #0073aa;
    outline-offset: 2px;
    box-shadow: 0 0 0 2px #fff, 0 0 0 5px #0073aa;
}

/* 링크 포커스 */
a:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
    text-decoration: underline;
}

/* 폼 요소 포커스 */
input:focus,
textarea:focus,
select:focus {
    outline: 3px solid #0073aa;
    outline-offset: 0;
    border-color: #0073aa;
}

/* ===================================
   고대비 모드
   =================================== */
   
@media (prefers-contrast: high) {
    * {
        border-color: currentColor !important;
    }
    
    body {
        background: #fff !important;
        color: #000 !important;
    }
    
    a {
        color: #0000ee !important;
        text-decoration: underline !important;
    }
    
    a:visited {
        color: #551a8b !important;
    }
    
    button,
    input[type="button"],
    input[type="submit"] {
        background: #000 !important;
        color: #fff !important;
        border: 2px solid #000 !important;
    }
}

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

body.high-contrast a {
    color: #4a90e2 !important;  /* 파란색으로 변경 - 더 나은 가독성 */
    text-decoration: underline !important;
}

body.high-contrast button,
body.high-contrast input[type="button"],
body.high-contrast input[type="submit"] {
    background: #fff !important;
    color: #000 !important;
    border: 2px solid #fff !important;
}

/* ===================================
   색맹 친화적 색상
   =================================== */
   
body.color-blind-mode {
    /* 빨강 대신 주황 사용 */
    --error-color: #ff6600;
    /* 초록 대신 파랑 사용 */
    --success-color: #0066cc;
    /* 경고는 노랑 유지 */
    --warning-color: #ffcc00;
}

/* ===================================
   텍스트 크기 조절
   =================================== */
   
body.text-size-small {
    font-size: 14px;
}

body.text-size-medium {
    font-size: 16px;
}

body.text-size-large {
    font-size: 20px;
}

body.text-size-xlarge {
    font-size: 24px;
}

/* ===================================
   키보드 네비게이션
   =================================== */
   
/* 탭 포커스 표시 */
.keyboard-navigation *:focus {
    outline: 3px solid #ff0 !important;
    outline-offset: 2px !important;
}

/* 드롭다운 메뉴 키보드 접근성 */
.menu-item-has-children > a:focus + .sub-menu,
.menu-item-has-children > a[aria-expanded="true"] + .sub-menu {
    display: block;
}

/* ===================================
   ARIA 라이브 영역
   =================================== */
   
[aria-live="polite"] {
    position: relative;
}

[aria-live="assertive"] {
    position: relative;
}

.aria-notification {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ===================================
   폼 접근성
   =================================== */
   
/* 필수 필드 표시 */
.required {
    color: #dc3545;
}

label .required {
    margin-left: 5px;
}

/* 에러 메시지 */
.form-error {
    color: #dc3545;
    font-size: 14px;
    margin-top: 5px;
}

/* 유효성 검사 상태 */
input:invalid,
textarea:invalid,
select:invalid {
    border-color: #dc3545;
}

input:valid,
textarea:valid,
select:valid {
    border-color: #28a745;
}

/* ===================================
   테이블 접근성
   =================================== */
   
table {
    border-collapse: collapse;
}

table caption {
    font-weight: bold;
    margin-bottom: 10px;
}

th {
    background: #f8f9fa;
    font-weight: bold;
    text-align: left;
}

th[scope="col"] {
    vertical-align: bottom;
}

th[scope="row"] {
    text-align: left;
}

/* ===================================
   이미지 접근성
   =================================== */
   
img:not([alt]) {
    outline: 3px solid #dc3545;
}

/* ===================================
   모달/팝업 접근성
   =================================== */
   
.modal {
    display: none;
}

.modal[aria-hidden="false"] {
    display: block;
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9998;
}

.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 20px;
    border-radius: 5px;
    z-index: 9999;
    max-width: 90%;
    max-height: 90%;
    overflow: auto;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 5px 10px;
}

/* ===================================
   로딩 상태
   =================================== */
   
[aria-busy="true"] {
    cursor: wait;
    opacity: 0.6;
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #0073aa;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ===================================
   툴팁 접근성
   =================================== */
   
[role="tooltip"] {
    position: absolute;
    background: #333;
    color: #fff;
    padding: 5px 10px;
    border-radius: 3px;
    font-size: 14px;
    z-index: 10000;
    display: none;
}

[aria-describedby]:hover + [role="tooltip"],
[aria-describedby]:focus + [role="tooltip"] {
    display: block;
}

/* ===================================
   프린트 스타일
   =================================== */
   
@media print {
    .no-print,
    .skip-links,
    nav,
    .navigation,
    .site-footer {
        display: none !important;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
    
    abbr[title]:after {
        content: " (" attr(title) ")";
    }
}

/* ===================================
   미디어 쿼리 접근성
   =================================== */
   
@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-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #f0f0f0;
        --link-color: #66b3ff;
        --focus-color: #ffcc00;
    }
    
    body {
        background-color: var(--bg-color);
        color: var(--text-color);
    }
    
    a {
        color: var(--link-color);
    }
    
    :focus {
        outline-color: var(--focus-color);
    }
}
