/**
 * Floating TOC (Table of Contents)
 * 個別カード投稿・通常投稿の右下に出る目次フロートボタン
 * モバイル: ピル型ボタン → タップで縦メニュー展開 + 丸閉じるボタン
 * PC      : メニュー常時表示(右下サイドバー風)
 */

.cg-float-toc {
    position: fixed;
    bottom: 20px;
    right: 16px;
    z-index: 9990;
    font-family: inherit;
    pointer-events: none;
}

.cg-float-toc > * {
    pointer-events: auto;
}

/* ピルボタン（スマホ用トリガー） */
.cg-toc-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px 9px 12px;
    background: #3366cc;
    color: #fff;
    border: none;
    border-radius: 22px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.03em;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(51, 102, 204, 0.35);
    transition: all 0.15s;
}

.cg-toc-pill:hover {
    background: #1e4799;
    transform: translateY(-1px);
}

.cg-toc-pill-icon {
    display: inline-flex;
    align-items: center;
}

/* メニュー本体 */
.cg-toc-menu {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 16px;
    z-index: 9999;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    width: 220px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

.cg-toc-menu.is-open {
    display: flex;
}

.cg-toc-menu-head {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    background: #eef3fb;
    color: #3366cc;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid #d6e3f5;
}

.cg-toc-item {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-bottom: 1px solid #eef0f3;
    font-size: 12px;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    transition: background 0.12s;
}

.cg-toc-item:last-of-type {
    border-bottom: none;
    border-radius: 0 0 12px 12px;
}

.cg-toc-item:hover {
    background: #f6f9ff;
    color: #1e4799;
}

.cg-toc-item:focus {
    outline: 2px solid #3366cc;
    outline-offset: -2px;
}

.cg-toc-num {
    flex-shrink: 0;
    width: 18px;
    font-size: 10px;
    color: #999;
    font-weight: 600;
}

.cg-toc-label {
    flex: 1;
    line-height: 1.4;
}

.cg-toc-arrow {
    flex-shrink: 0;
    font-size: 11px;
    color: #aaa;
    margin-left: auto;
}

/* 閉じるボタン (スマホ用) */
.cg-toc-close {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #3366cc;
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(51, 102, 204, 0.35);
    transition: all 0.15s;
    align-self: flex-end;
    margin-top: 8px;
}

.cg-toc-close:hover {
    background: #1e4799;
}

/* PC: メニュー常時表示、ピルと閉じるボタンを非表示 */
@media (min-width: 900px) {
    .cg-float-toc .cg-toc-pill {
        display: none;
    }
    .cg-float-toc .cg-toc-menu {
        display: flex !important;
        max-height: 70vh;
    }
    .cg-float-toc .cg-toc-close {
        display: none;
    }
}

/* TOC が空(autoモードでH2なし)のときは丸ごと隠す */
.cg-float-toc.cg-toc-empty {
    display: none;
}
