/**
 * 記事詳細ページの目次スタイル
 * 圧倒的に優れたUXを実現する目次デザイン
 */

/* 目次コンテナ - 固定サイドバー */
.article-toc {
    position: fixed;
    top: 100px;
    right: 20px;
    width: 280px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 134, 123, 0.08);
    overflow: hidden;
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
    transform: translateX(0);
}

/* 大画面対応 */
@media (min-width: 1600px) {
    .article-toc {
        right: calc((100vw - 1200px) / 2 - 300px);
    }
}

/* 目次の内部コンテナ */
.toc-inner {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* 目次ヘッダー */
.toc-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 2px solid #f3f4f6;
    background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
}

.toc-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toc-title i {
    color: var(--primary-color);
    font-size: 0.875rem;
}

/* 目次ナビゲーション */
.toc-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

/* カスタムスクロールバー */
.toc-nav::-webkit-scrollbar {
    width: 4px;
}

.toc-nav::-webkit-scrollbar-track {
    background: transparent;
}

.toc-nav::-webkit-scrollbar-thumb {
    background: rgba(0, 134, 123, 0.2);
    border-radius: 2px;
}

.toc-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 134, 123, 0.3);
}

/* 目次リスト */
.toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc-item {
    margin: 0;
    position: relative;
}

/* 目次リンク */
.toc-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    color: #6b7280;
    font-size: 0.875rem;
    line-height: 1.5;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

/* ホバー効果 */
.toc-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary-color);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
}

.toc-link:hover {
    color: var(--primary-color);
    background: rgba(0, 134, 123, 0.05);
}

.toc-link:hover::before {
    transform: translateX(0);
}

/* アクティブ状態 */
.toc-link.active {
    color: var(--primary-color);
    font-weight: 600;
    background: rgba(0, 134, 123, 0.1);
}

.toc-link.active::before {
    transform: translateX(0);
}

/* 番号 */
.toc-number {
    flex-shrink: 0;
    font-weight: 700;
    color: rgba(0, 134, 123, 0.6);
    font-size: 0.75rem;
    min-width: 20px;
}

.toc-link.active .toc-number {
    color: var(--primary-color);
}

/* テキスト */
.toc-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* 進捗バー */
.toc-progress {
    height: 3px;
    background: #f3f4f6;
    position: relative;
    overflow: hidden;
}

.toc-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    width: 0;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 134, 123, 0.3);
}

/* モバイル・タブレット対応 */
@media (max-width: 1399px) {
    .article-toc {
        display: none;
    }
}

/* モバイル用の目次（記事内に配置） */
@media (max-width: 1399px) {
    .mobile-toc {
        display: block;
        margin: 2rem 0 3rem;
        background: #ffffff;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        overflow: hidden;
    }

    .mobile-toc .toc-header {
        padding: 1rem;
        border-bottom: 1px solid #e5e7eb;
        background: #f9fafb;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
    }

    .mobile-toc .toc-title {
        font-size: 0.9375rem;
    }

    .mobile-toc-toggle {
        background: none;
        border: none;
        padding: 0.5rem;
        cursor: pointer;
        color: #6b7280;
        transition: transform 0.2s ease;
    }

    .mobile-toc.collapsed .mobile-toc-toggle {
        transform: rotate(180deg);
    }

    .mobile-toc .toc-nav {
        max-height: 400px;
        transition: max-height 0.3s ease;
        padding: 0.5rem 0;
    }

    .mobile-toc.collapsed .toc-nav {
        max-height: 0;
        overflow: hidden;
    }

    .mobile-toc .toc-link {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
    }

    .mobile-toc .toc-progress {
        display: none;
    }
}

/* デスクトップのみ表示 */
@media (min-width: 1400px) {
    .mobile-toc {
        display: none;
    }
}

/* アニメーション */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.article-toc {
    animation: slideIn 0.5s ease;
}

/* 目次が非表示の時 */
.article-toc.hidden {
    opacity: 0;
    transform: translateX(100%);
    pointer-events: none;
}

/* フェードイン効果 */
.toc-item {
    opacity: 0;
    animation: fadeInUp 0.4s ease forwards;
}

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

/* 各アイテムに遅延を追加 */
.toc-item:nth-child(1) { animation-delay: 0.1s; }
.toc-item:nth-child(2) { animation-delay: 0.15s; }
.toc-item:nth-child(3) { animation-delay: 0.2s; }
.toc-item:nth-child(4) { animation-delay: 0.25s; }
.toc-item:nth-child(5) { animation-delay: 0.3s; }
.toc-item:nth-child(6) { animation-delay: 0.35s; }
.toc-item:nth-child(7) { animation-delay: 0.4s; }
.toc-item:nth-child(8) { animation-delay: 0.45s; }
.toc-item:nth-child(9) { animation-delay: 0.5s; }
.toc-item:nth-child(10) { animation-delay: 0.55s; }
.toc-item:nth-child(n+11) { animation-delay: 0.6s; }

/* パルスアニメーション（現在のセクション） */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 134, 123, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(0, 134, 123, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 134, 123, 0);
    }
}

.toc-link.active::after {
    content: '';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: pulse 2s infinite;
}