/* レイアウト - 左メニューとコンテナ */
/* テーマ: 論文風ライトテーマ */

/* 全体コンテナ */
.container-with-sidebar {
    display: flex;
    gap: 2rem;
}

/* 左サイドバーメニュー */
.sidebar-menu {
    width: 280px;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    z-index: 1000;
    will-change: transform;
}

.sidebar-header {
    padding: 1.5rem 1rem 1rem;
    border-bottom: 1px solid var(--border-primary);
    flex-shrink: 0;
    background: var(--bg-secondary);
}

.sidebar-title {
    font-family: "Noto Serif JP", "Times New Roman", serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    display: block;
}

.sidebar-title:hover {
    text-decoration: underline;
}

/* スクロール可能なナビゲーション領域 */
.sidebar-nav-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

/* ========== 統一ナビゲーションスタイル ========== */
.sidebar-nav-unified {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav-unified .nav-top {
    margin-bottom: 0.75rem;
}

.sidebar-nav-unified .nav-top a {
    display: block;
    padding: 0.4rem 0.5rem;
    color: #333;
    text-decoration: none;
    font-weight: bold;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
}

.sidebar-nav-unified .nav-top a:hover {
    text-decoration: underline;
}

.sidebar-nav-unified .nav-top.current-page a {
    border-left-color: #1565c0;
    background-color: #e0e7ff;
}

/* 章レベル */
.sidebar-nav-unified .nav-chapter {
    margin-bottom: 0.5rem;
}

.sidebar-nav-unified .chapter-title {
    display: block;
    padding: 0.3rem 0.5rem;
    font-weight: bold;
    font-size: 0.9rem;
    color: #1a365d;
    background-color: #e2e8f0;
    border-left: 3px solid #999;
    text-decoration: none;
}

.sidebar-nav-unified .chapter-title:hover {
    text-decoration: underline;
}

.sidebar-nav-unified .nav-chapter.current-chapter .chapter-title {
    border-left-color: #1565c0;
    background-color: #dbeafe;
}

/* 章内のページリスト */
.sidebar-nav-unified .chapter-pages {
    list-style: none;
    padding: 0;
    margin: 0;
    border-left: 3px solid #ddd;
}

.sidebar-nav-unified .chapter-pages li {
    margin: 0;
}

.sidebar-nav-unified .chapter-pages a {
    display: block;
    padding: 0.25rem 0.5rem 0.25rem 1rem;
    color: #555;
    text-decoration: none;
    font-size: 0.85rem;
    line-height: 1.4;
    transition: background-color 0.15s ease;
}

.sidebar-nav-unified .chapter-pages a:hover {
    background-color: #f5f5f5;
    text-decoration: underline;
}

.sidebar-nav-unified .chapter-pages .current-page a {
    background-color: #eff6ff;
    color: #000;
    font-weight: bold;
    border-left: 2px solid #1565c0;
    margin-left: -2px;
}

/* ユーティリティリンク（ブックマーク・学習履歴） */
.sidebar-nav-unified .nav-bookmark,
.sidebar-nav-unified .nav-review {
    margin-top: 0.5rem;
}

.sidebar-nav-unified .nav-bookmark:first-of-type {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #cbd5e1;
}

.sidebar-nav-unified .nav-bookmark a,
.sidebar-nav-unified .nav-review a {
    display: block;
    padding: 0.4rem 0.5rem;
    color: #555;
    text-decoration: none;
    font-size: 0.85rem;
}

.sidebar-nav-unified .nav-bookmark a:hover,
.sidebar-nav-unified .nav-review a:hover {
    text-decoration: underline;
    color: #333;
    background-color: #f5f5f5;
}

.sidebar-nav-unified .nav-bookmark.current a,
.sidebar-nav-unified .nav-review.current a {
    background-color: #eff6ff;
    color: #000;
    font-weight: bold;
}

/* 外部リンク */
.sidebar-nav-unified .nav-external {
    margin-top: 0.5rem;
}

.sidebar-nav-unified .nav-external a {
    display: block;
    padding: 0.4rem 0.5rem;
    color: #666;
    text-decoration: none;
    font-size: 0.85rem;
}

.sidebar-nav-unified .nav-external a:hover {
    text-decoration: underline;
    color: #333;
}

/* ========== 旧スタイル互換 ========== */
.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav > li {
    margin-bottom: 0.3rem;
}

/* トップページリンク */
.sidebar-nav .nav-top > a {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}

.sidebar-nav .nav-top.current > a {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-nav .nav-top > a:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* 章リンク */
.sidebar-nav .nav-chapter {
    margin-top: 0.5rem;
}

.sidebar-nav .nav-chapter > .chapter-link {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
}

.sidebar-nav .nav-chapter > .chapter-link:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* 現在の章 */
.sidebar-nav .nav-chapter.current-chapter > .chapter-link {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 700;
}

/* 章内セクション */
.sidebar-nav .chapter-sections {
    list-style: none;
    padding: 0;
    margin: 0.3rem 0 0.5rem 1rem;
}

.sidebar-nav .chapter-sections > li {
    margin-bottom: 0.2rem;
}

.sidebar-nav .chapter-sections > li > a {
    display: block;
    padding: 0.35rem 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
}

.sidebar-nav .chapter-sections > li > a:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.sidebar-nav .chapter-sections > li > a.active {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
}

/* サブセクション */
.sidebar-nav .section-subs {
    list-style: none;
    padding: 0;
    margin: 0.2rem 0 0.3rem 1rem;
}

.sidebar-nav .section-subs li {
    margin-bottom: 0.1rem;
}

.sidebar-nav .section-subs a {
    display: block;
    padding: 0.25rem 0.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: normal;
}

.sidebar-nav .section-subs a:hover {
    color: var(--text-secondary);
}

.sidebar-nav .section-subs a.active {
    color: var(--text-primary);
    font-weight: 500;
}

/* 外部リンク（hatohato.jpトップ） */
.sidebar-nav .nav-external {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-primary);
}

.sidebar-nav .nav-external > a {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
}

.sidebar-nav .nav-external > a:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

/* ====== 旧スタイル互換（submenu） ====== */
.sidebar-nav .submenu {
    list-style: none;
    padding: 0;
    margin: 0.3rem 0 0.5rem 1rem;
}

.sidebar-nav .submenu li {
    margin-bottom: 0.3rem;
}

.sidebar-nav .submenu a {
    display: block;
    padding: 0.4rem 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: normal;
}

.sidebar-nav .submenu a:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.sidebar-nav .submenu a.active {
    background-color: transparent;
    color: var(--text-primary);
    font-weight: 500;
}

/* メインコンテンツエリア */
.main-content {
    margin-left: 300px;
    max-width: 900px;
    padding: 2rem 3rem;
    flex: 1;
    min-width: 0;
    background-color: var(--bg-primary);
}

/* フッター */
footer {
    margin-left: 280px;
}

/* セクション間の区切り */
section {
    padding-bottom: 2rem;
    margin-bottom: 1rem;
}

/* ヘッダー部分 */
header {
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-primary);
}

/* サイドバー: ブックマークリンク */
.sidebar-nav .nav-bookmark {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-secondary);
}

.sidebar-nav .nav-bookmark a,
.sidebar-nav .nav-review a {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
}

.sidebar-nav .nav-bookmark a:hover,
.sidebar-nav .nav-review a:hover {
    color: var(--accent-primary);
}

.sidebar-nav .nav-bookmark.current a,
.sidebar-nav .nav-review.current a {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ========================================
   ハンバーガーメニュー
   ======================================== */

.menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1100;
    width: 44px;
    height: 44px;
    background: #fff;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    cursor: pointer;
    padding: 10px;
    flex-direction: column;
    justify-content: space-around;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.menu-toggle span {
    display: block;
    width: 100%;
    height: 2px;
    background-color: #333;
    border-radius: 1px;
    transition: all 0.3s ease;
}

.menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: 999;
}

/* ========================================
   レスポンシブ対応
   ======================================== */

@media (max-width: 768px) {
    .sidebar-menu {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar-menu.active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        padding: 4rem 1.5rem 2rem;
    }
    
    footer {
        margin-left: 0;
    }
    
    .menu-toggle {
        display: flex;
    }
    
    .menu-overlay.active {
        display: block;
    }
}


/* 検索ボックス（ドロップダウン用） */
.search-container {
    margin-bottom: 0.75rem;
}

.search-box {
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: 'Meiryo', sans-serif;
}

.search-box input:focus {
    outline: none;
    border-color: #2d3748;
}

/* ========== サイドバー折りたたみ機能 ========== */
.sidebar-collapse {
    display: block;
    position: fixed;
    top: 10px;
    left: 285px;  /* サイドバー幅280px + 5px */
    z-index: 1100;
    width: 32px;
    height: 32px;
    background: #e2e8f0;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    cursor: pointer;
    padding: 6px;
    transition: left 0.3s ease;
}

.sidebar-collapse span {
    display: block;
    width: 100%;
    height: 2px;
    background: #333;
    margin: 4px 0;
    transition: all 0.3s ease;
}

.sidebar-collapse:hover {
    background: #cbd5e0;
}

.sidebar-hidden .sidebar-collapse {
    left: 10px;
}

.sidebar-hidden .sidebar-menu {
    transform: translateX(-100%);
}

.sidebar-hidden .main-content {
    margin-left: 50px;
    max-width: 900px;
}

/* サイドバーのトランジション */
.sidebar-menu {
    transition: transform 0.3s ease;
}

.main-content {
    transition: margin-left 0.3s ease;
}
