/*
- 파일명: my-toc-frontend.css
- 위치: /my-toc-plugin/assets/css/
- 기능: TOC 플러그인의 프론트엔드 표시 스타일
- 작성일: 2025-03-23
- 수정일: 2025-03-26
*/

/* ===================================
   공통 목차 스타일
   =================================== */
/* 목차 컨테이너 - 기본 배치 및 크기 설정 */
.my-toc {
    margin: 1.5em 0;
    padding: 12px 15px;
    border-radius: 5px;
    border-width: 1px;
    border-style: solid;
    width: auto;
    min-width: 150px;
    max-width: 100%;
    display: inline-block;
    box-sizing: border-box;
    font-size: 0.9em;
    line-height: 1.5;
    overflow: visible;
}

/* 목차 헤더 - 제목과 토글 버튼이 있는 상단 영역 */
.my-toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
    padding: 2px;
}

/* 목차 제목 스타일 */
.my-toc-title {
    font-weight: bold;
    font-size: 1.1em;
    margin-right: 15px;
    padding-right: 5px;
}

/* 토글 버튼 스타일 */
.my-toc-toggle {
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 3px;
}

/* 토글 버튼 호버 효과 */
.my-toc-toggle:hover {
    background: rgba(0,0,0,0.05);
}

/* 목차 내용 영역 - 펼치기/접기 애니메이션을 위한 설정 */
.my-toc-content {
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease;
    max-height: 1000px;
    overflow: hidden;
    opacity: 1;
    padding: 2px;
}

/* 목차가 접혔을 때의 스타일 */
.my-toc-content-hidden {
    max-height: 0;
    opacity: 0;
    margin: 0;
}

/* 목차 리스트의 기본 스타일 - 불릿 제거 및 마진/패딩 초기화 */
.my-toc-list,
.my-toc-sublist {
    list-style-type: none;
    margin: 0;
    padding: 0;
    line-height: 1.2;
}

/* 최상위 목차 리스트 */
.my-toc-list {
    margin-left: 0;
}

/* 서브 목차 리스트 - 들여쓰기 적용 */
.my-toc-sublist {
    margin-left: 8px;
    margin-top: 0;
    margin-bottom: 0;
}

/* 목차 항목 */
.my-toc-item {
    margin: 0;
    padding: 0;
    line-height: 1.2;
}

/* 목차 링크 기본 스타일 - 자식 테마 CSS 오버라이드를 위한 필수 스타일 */
.my-toc-item a,
.my-toc-list a,
.my-toc-sublist a {
    text-decoration: none;
    display: block;
    transition: all 0.2s ease;
    padding: 1px 3px;
    border-radius: 3px;
    border: none;
    box-shadow: none;
    outline: none;
    line-height: 1.2;
    margin: 0;
    white-space: nowrap;
    overflow: visible;
    word-break: normal;
    background-image: none;
    background-color: transparent;
    /* !important 규칙은 필요한 경우에만 사용 */
}

/* 접두사(prefix) 스타일 - H2, H3 앞에 표시되는 기호/텍스트 */
.my-toc-prefix {
    display: inline-block;
    margin-right: 4px;
}

/* 레벨별 스타일 - 헤딩 수준에 따른 차별화 */
.my-toc-level-2 {
    font-weight: bold;
    margin: 1px 0;
}

.my-toc-level-3 {
    font-weight: normal;
    margin: 0;
    margin-left: 10px;
}

.my-toc-level-4 {
    font-weight: normal;
    margin: 0;
    margin-left: 12px;
    font-size: 0.85em;
}

/* 현재 활성화된 항목 스타일 - 스크롤 위치에 따라 하이라이팅되는 항목 */
.my-toc-item-active > a,
.my-toc-list a.active-link,
.my-toc-sublist a.active-link {
    font-weight: bold;
    background-color: rgba(0,0,0,0.05);
    padding-left: 6px;
    border-left: 3px solid #0073aa;
    text-decoration: none;
}

/* ===================================
   마우스 오버 효과
   =================================== */
/* 모든 테마의 공통 호버 스타일 */
.my-toc-item a:hover,
.my-toc-list a:hover,
.my-toc-sublist a:hover {
    text-decoration: none;
    font-weight: 700;
    background-color: rgba(0,0,0,0.1);
    color: #000000;
    border: none;
    box-shadow: none;
    outline: none;
    text-shadow: 0 0 0.65px currentColor;
}

/* ===================================
   붙박이 스타일 - 스크롤에 따라 고정 위치에 표시
   =================================== */
/* 붙박이 기본 스타일 */
.my-toc-sticky {
    position: fixed;
    z-index: 999;
    width: 300px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* 좌측 위치 변형 */
.my-toc-sticky-left-top {
    top: 20px;
    left: 20px;
}

.my-toc-sticky-left-middle {
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
}

.my-toc-sticky-left-bottom {
    bottom: 20px;
    left: 20px;
}

/* 우측 위치 변형 */
.my-toc-sticky-right-top {
    top: 20px;
    right: 20px;
}

.my-toc-sticky-right-middle {
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
}

.my-toc-sticky-right-bottom {
    bottom: 20px;
    right: 20px;
}

/* ===================================
   테마 스타일 - 다양한 외관 옵션
   =================================== */
/* 회색 테마 - 기본 테마 */
.my-toc.my-toc-theme-gray {
    background-color: #f9f9f9;
    border-color: #ddd;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.my-toc.my-toc-theme-gray .my-toc-title {
    color: #333;
    border-bottom: 1px solid #B2B2B2;
    padding-bottom: 5px;
    margin-bottom: 10px;
    font-weight: 600;
}

.my-toc.my-toc-theme-gray .my-toc-list a {
    color: #404040;
    font-weight: normal;
}

.my-toc.my-toc-theme-gray .my-toc-list a:visited {
    color: #404040;
    font-weight: normal;
}

.my-toc.my-toc-theme-gray .my-toc-prefix {
    color: #777;
}

.my-toc.my-toc-theme-gray .my-toc-list a:hover {
    background-color: #c0c0c0;
}

/* 하늘색 테마 */
.my-toc.my-toc-theme-blue {
    background-color: #e6f6ff;
    border-color: #a8d8ff;
    box-shadow: 0 1px 3px rgba(0,120,215,0.1);
}

.my-toc.my-toc-theme-blue .my-toc-title {
    color: #0055aa;
    border-bottom: 1px solid #70A2D4;
    padding-bottom: 5px;
    margin-bottom: 10px;
    font-weight: 600;
}

.my-toc.my-toc-theme-blue .my-toc-list a {
    color: #0066cc;
    font-weight: normal;
}

.my-toc.my-toc-theme-blue .my-toc-list a:visited {
    color: #6a5acd;
    font-weight: normal;
}

.my-toc.my-toc-theme-blue .my-toc-prefix {
    color: #0077cc;
}

.my-toc.my-toc-theme-blue .my-toc-toggle {
    color: #0066cc;
    background-color: rgba(200,230,255,0.5);
    border-radius: 3px;
}

.my-toc.my-toc-theme-blue .my-toc-toggle:hover {
    background-color: rgba(200,230,255,0.8);
}

.my-toc.my-toc-theme-blue .my-toc-list a:hover {
    background-color: #a0c8ff;
}

/* 하얀색 테마 */
.my-toc.my-toc-theme-white {
    background-color: #ffffff;
    border-color: #eeeeee;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border-radius: 8px;
}

.my-toc.my-toc-theme-white .my-toc-title {
    color: #595959;
    border-bottom: 1px solid #9E9E9E;
    padding-bottom: 5px;
    margin-bottom: 10px;
    font-weight: 600;
}

.my-toc.my-toc-theme-white .my-toc-list a {
    color: #595959;
    font-weight: normal;
}

.my-toc.my-toc-theme-white .my-toc-list a:visited {
    color: #595959;
    font-weight: normal;
}

.my-toc.my-toc-theme-white .my-toc-prefix {
    color: #777;
    font-weight: normal;
}

.my-toc.my-toc-theme-white .my-toc-toggle {
    color: #1C1C1C;
    background-color: #f8f9fa;
    border-radius: 4px;
    padding: 3px 6px;
}

.my-toc.my-toc-theme-white .my-toc-toggle:hover {
    background-color: #eee;
}

.my-toc.my-toc-theme-white .my-toc-list a:hover {
    background-color: #606060;
    color: #1C1C1C;
}

/* 따뜻한 색 테마 */
.my-toc.my-toc-theme-warm {
    background-color: #fff5e6;
    border-color: #ffcc80;
    box-shadow: 0 2px 5px rgba(255,152,0,0.1);
    border-radius: 6px;
}

.my-toc.my-toc-theme-warm .my-toc-title {
    color: #DF6000;
    border-bottom: 1px solid #E78840;
    padding-bottom: 5px;
    margin-bottom: 10px;
    font-weight: 600;
}

.my-toc.my-toc-theme-warm .my-toc-list a {
    color: #e65100;
    font-weight: normal;
}

.my-toc.my-toc-theme-warm .my-toc-list a:visited {
    color: #bf5e00;
    font-weight: normal;
}

.my-toc.my-toc-theme-warm .my-toc-prefix {
    color: #f57c00;
    font-weight: normal;
}

.my-toc.my-toc-theme-warm .my-toc-toggle {
    color: #ff8f00;
    background-color: rgba(255,224,178,0.5);
    border-radius: 3px;
}

.my-toc.my-toc-theme-warm .my-toc-toggle:hover {
    background-color: rgba(255,224,178,0.8);
}

.my-toc.my-toc-theme-warm .my-toc-list a:hover {
    background-color: #ffb84d;
}

/* ===================================
   테마별 활성 항목 스타일 - 각 테마에 맞는 강조색
   =================================== */
.my-toc-theme-gray .my-toc-item-active > a,
.my-toc-theme-gray .active-link {
    border-left-color: #0073aa;
    font-weight: 800;
}

.my-toc-theme-blue .my-toc-item-active > a,
.my-toc-theme-blue .active-link {
    border-left-color: #0066cc;
}

.my-toc-theme-white .my-toc-item-active > a,
.my-toc-theme-white .active-link {
    border-left-color: #2271b1;
}

.my-toc-theme-warm .my-toc-item-active > a,
.my-toc-theme-warm .active-link {
    border-left-color: #e65100;
}

/* ===================================
   사용자 정의 테마 스타일
   =================================== */
/* 사용자 정의 색상 스타일 - CSS 변수 활용 */
.my-toc.my-toc-theme-custom {
    --link-color: attr(data-link-color);
    --hover-color: attr(data-hover-color);
    --visited-color: attr(data-visited-color);
    --hover-bg: attr(data-hover-bg);
    --border-color: attr(data-border-color);
}

.my-toc.my-toc-theme-custom .my-toc-list a {
    color: var(--link-color, #0073aa);
}

.my-toc.my-toc-theme-custom .my-toc-list a:hover {
    color: var(--hover-color, #000000);
    background-color: var(--hover-bg, rgba(0,0,0,0.1));
}

.my-toc.my-toc-theme-custom .my-toc-list a:visited {
    color: var(--visited-color, inherit);
}

/* 데이터 속성이 있는 경우의 스타일 */
[data-link-color] .my-toc-list a {
    color: attr(data-link-color);
}

[data-hover-color] .my-toc-list a:hover {
    color: attr(data-hover-color);
}

[data-visited-color] .my-toc-list a:visited {
    color: attr(data-visited-color);
}

/* ===================================
   인쇄 시 스타일 - 인쇄 최적화
   =================================== */
@media print {
    .my-toc {
        page-break-inside: avoid;
    }
    
    .my-toc-item a {
        color: #000;
        text-decoration: none;
    }
}

/* ===================================
   반응형 스타일 - 모바일 디바이스 지원
   =================================== */
@media (max-width: 768px) {
    .my-toc-sticky {
        width: 70%;
    }
    
    .my-toc-item a {
        padding: 4px 6px;
    }
}

@media (max-width: 480px) {
    .my-toc-sticky {
        width: 90%;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }
    
    .my-toc-sticky-left-middle,
    .my-toc-sticky-right-middle {
        transform: translate(-50%, -50%);
    }
}

/* ===================================
   핵심 오버라이드 스타일 - 자식 테마와의 충돌 방지
   - 필요한 경우에만 !important 사용
   =================================== */
/* 자식 테마의 CSS 수정으로 인해 대부분의 !important 제거 가능 */
/* 그러나 일부 핵심 속성은 여전히 !important로 유지하여 안정성 보장 */
.my-toc-list a.active-link,
.my-toc-sublist a.active-link {
    font-weight: bold !important;
    border-left: 3px solid #0073aa !important;
    background-color: rgba(0,0,0,0.05) !important;
}