/* post.html content styles - extracted for reuse in preview */
body {
    font-family: Arial, sans-serif;
    overflow-x: hidden;
    overflow-y: hidden; /* bodyのスクロールバーを非表示にする */
}
pre{
    margin-bottom: 0rem;
}
.mermaid {
    margin-top: 20px;
}
.button-link {
    display: inline-block;
    margin-left: 10px;
    background-color: #007bff;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    text-decoration: none;
}
.button-link:hover {
    background-color: #0056b3;
}
.edit-link {
    background-color: #28a745;
}
.edit-link:hover {
    background-color: #218838;
}
.tweet-link {
    background-color: #1da1f2;
}
.tweet-link:hover {
    background-color: #0d95e8;
}
@media print {
    .tweet-link,
    .none_print {
        display: none; /* 印刷時に非表示にする */
    }
    a {
        pointer-events: none; /* リンクのクリックイベントを無効化 */
    }
    a::after {
        content: ""; /* リンク先のURLを空にする */
    }
}
.post-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: var(--ui-header-bg, white);
    padding: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    gap: 12px;
}
.post-header-title {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 0 4px 0 8px;
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
    color: var(--ui-header-title-color, #222);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.single-section-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 10px;
    padding: 2px 10px;
    font-size: 0.78rem;
    font-weight: 500;
    color: #d97706;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 12px;
    text-decoration: none;
    white-space: nowrap;
    vertical-align: middle;
}
.single-section-badge:hover {
    background: #ffedd5;
    color: #b45309;
}
.single-section-badge-link {
    color: #2563eb;
    font-weight: 600;
}
/* H1見出し横「セクションURLコピー」アイコン（旧UI・互換のため残置） */
.section-link-icon {
    display: inline-block;
    margin-left: 10px;
    padding: 2px 6px;
    font-size: 0.55em;
    color: #b0b0b0;
    text-decoration: none;
    vertical-align: middle;
    border-radius: 4px;
    opacity: 0.55;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.section-link-icon:hover {
    opacity: 1;
    color: #2563eb;
    background: #eef2ff;
}
@media print {
    .section-link-icon {
        display: none !important;
    }
}

/* H1見出し行の右端に薄く配置する「⋮」セクションメニュー
   #content (閲覧) / #preview-content (編集画面プレビュー) 双方に同じUI */
#content h1,
#preview-content h1 {
    position: relative;
    padding-right: 36px; /* ⋮ボタンとの干渉防止スペース */
}
.section-menu-wrap {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-block;
    /* transform でスタッキングコンテキストを作るため、内側の .section-menu の
       z-index がローカル化される。ラッパ自身に z-index を与え、後続の
       .table-responsive(position:relative) よりメニューを前面に出す */
    z-index: 50;
}
.section-menu-trigger {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #b0b0b0;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.7em;
    line-height: 1;
    opacity: 0.55;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.section-menu-trigger:hover,
.section-menu-trigger:focus {
    opacity: 1;
    color: #2563eb;
    background: #eef2ff;
    outline: none;
}
.section-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    min-width: 280px;
    padding: 4px 0;
    font-weight: normal;
    white-space: nowrap;
    /* 親 H1 の font-size: 2em が継承されないよう、ここで絶対サイズにリセット
       （他の三点リーダー .options-menu-item と同等の見た目に揃える） */
    font-size: 0.9rem;
}
.section-menu.show {
    display: block;
}
/* テーマCSS（例: [data-theme="mono"] #content a の text-decoration: underline）に
   負けないよう、ID セレクタとの組み合わせで specificity を上げる。
   font-size は親 .section-menu (0.9rem) を継承（H1 の 2em 継承を断ち切る） */
#content .section-menu-item,
#content .section-menu-item:link,
#content .section-menu-item:visited,
#preview-content .section-menu-item,
#preview-content .section-menu-item:link,
#preview-content .section-menu-item:visited {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    color: #333;
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: background 0.15s;
}
#content .section-menu-item:hover,
#preview-content .section-menu-item:hover {
    background: #f5f5f5;
    color: #2563eb;
    text-decoration: none;
}
.section-menu-item i {
    width: 16px;
    text-align: center;
    color: #666;
}
.section-menu-item:hover i {
    color: #2563eb;
}
@media print {
    .section-menu-wrap {
        display: none !important;
    }
}
@media (max-width: 768px) {
    /* 未認証（ボタンが少ない）: 従来の折り返しレイアウト */
    .post-header:not(.hdr-auth) {
        flex-wrap: wrap;
        row-gap: 6px;
    }
    .post-header:not(.hdr-auth) .post-header-title {
        order: -1;
        flex: 1 1 100%;
        text-align: left;
        padding: 0 4px;
        font-size: 1rem;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        word-break: break-word;
    }
    .post-header .btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* 認証時: 2段グリッド
       1段目 = ★ / タイトル / バッジ / 目次 / ⋮（中低頻度）
       2段目 = 一覧(左端) / ◀ / ▶ / 末尾 / 切替 / 編集（高頻度・均等幅） */
    .post-header.hdr-auth {
        display: grid;
        grid-template-columns: repeat(7, 1fr);
        grid-template-areas:
            "star title title title badge toc  opts"
            "back prev  next  tail  switch edit today";
        gap: 6px;
        align-items: center;
        padding: 8px 10px;
    }
    /* .align-right の子をグリッドに直接参加させる */
    .post-header.hdr-auth .align-right {
        display: contents;
    }
    .post-header.hdr-auth #post-star-btn   { grid-area: star; }
    .post-header.hdr-auth .post-header-title {
        grid-area: title;
        align-self: center;
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding: 0 2px;
    }
    .post-header.hdr-auth #section-badge-btn { grid-area: badge; }
    .post-header.hdr-auth #toggle-toc        { grid-area: toc; }
    .post-header.hdr-auth .options-dropdown  { grid-area: opts; }
    .post-header.hdr-auth #back-to-index     { grid-area: back; }
    .post-header.hdr-auth .adj-prev          { grid-area: prev; }
    .post-header.hdr-auth .adj-next          { grid-area: next; }
    .post-header.hdr-auth #tail-view-btn     { grid-area: tail; }
    .post-header.hdr-auth #switchPageButton  { grid-area: switch; }
    .post-header.hdr-auth .hdr-edit          { grid-area: edit; }
    .post-header.hdr-auth .hdr-today         { grid-area: today; }

    /* 各セルいっぱいに広げてタッチ目標を確保 */
    .post-header.hdr-auth .btn,
    .post-header.hdr-auth .options-dropdown #optionsButton {
        width: 100%;
        padding-left: 2px;
        padding-right: 2px;
    }
    .post-header.hdr-auth .options-dropdown {
        display: block;
        grid-area: opts;
    }
    /* 幅が細いセルに収めるための微調整 */
    .post-header.hdr-auth #toggle-toc { font-size: 0.78rem; gap: 2px; }
    .post-header.hdr-auth #toggle-toc .toc-icon { display: none; }
    .post-header.hdr-auth #tail-view-btn { font-size: 0.72rem; gap: 2px; white-space: nowrap; }
    .post-header.hdr-auth #section-badge-btn { font-size: 0.78rem; }
    .post-header.hdr-auth #section-badge-arrows { display: none; }
}
@media print {
    .post-header-title {
        display: none;
    }
}
.content-wrapper {
    display: flex;
    gap: 20px;
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: hidden; /* 縦スクロールバーを非表示にする */
}
/* 目次非表示時のコンテンツラッパーのスタイル */
.content-wrapper.toc-hidden {
    /* flexを維持しつつ、子要素の配置を調整 */
    display: flex;
    gap: 0; /* 目次とメインコンテンツの間隔をなくす */
}
/* 目次非表示時のインデックスコンテナのスタイル */
.content-wrapper.toc-hidden .index-container {
    flex: 0 0 0; /* 幅を0に */
    width: 0;
    padding: 0;
    margin: 0;
    border: none;
    overflow: hidden;
}
/* 目次非表示時のメインコンテンツのスタイル */
.content-wrapper.toc-hidden .main-content {
    flex: 1 1 100% !important;
    width: 100% !important;
    max-width: 100% !important;
}
.main-content {
    flex: 1;
    min-width: 0;
    width: calc(100% - 250px); /* 通常時の幅 */
    overflow-wrap: break-word;
    overflow-y: auto;
    height: calc(100vh - 100px);
    padding-right: 20px;
    transition: width 0.3s ease; /* 幅の変更をアニメーション化 */
}
.main-content.full-width {
    width: 100% !important; /* 目次非表示時は全幅 */
    max-width: 100% !important;
    flex: 1 1 100% !important;
    transition: width 0.3s ease;
}
/* 目次ボタンのスタイル */
#toggle-toc {
    margin-right: 5px;
}
/* 目次の表示/非表示のアニメーション */
.index-container {
    width: 250px;
    padding: 15px;
    border: 1px solid var(--ui-sidebar-border, #ddd);
    border-radius: 4px;
    background-color: var(--ui-sidebar-bg, #f9f9f9);
    position: sticky;
    top: 20px;
    height: fit-content;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    flex-shrink: 0;
    font-size: 0.9em;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    display: block !important; /* 明示的に表示を設定 */
}
.index-container ul {
    list-style-type: none;
    padding-left: 0;
    margin: 0;
}
.index-container li {
    margin: 5px 0;
    font-size: 0.9em;
}
.index-container a {
    text-decoration: none;
    color: var(--ui-sidebar-link-color, #007bff);
    word-break: break-all;
}
.index-container a:hover {
    text-decoration: underline;
}
blockquote p {
    white-space: pre-wrap; /* 改行を反映させる */
}
/* ページ内リンク遷移時のスクロールマージンを設定 */
h1, h2, h3, h4, h5, h6 {
    scroll-margin-top: 70px; /* ヘッダーの高さ + 余白 */
}
.align-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
}
.toggle-button::after {
    content: '▼';
}
.toggle-button.collapsed::after {
    content: '▲';
}
#toggle-index {
    cursor: pointer;
    user-select: none;
}
#toggle-index:hover {
    color: #007bff;
}
.toggle-icon {
    font-size: 0.8em;
    margin-left: 5px;
}
@media (max-width: 991px) {
    .content-wrapper {
        flex-direction: column;
        overflow-y: auto; /* 解決策1: スクロールを有効にする */
    }
    .main-content {
        width: 100% !important; /* !importantを追加して優先度を上げる */
        height: auto; /* 解決策2: 高さの制限を解除 */
        order: 2; /* メインコンテンツを下に表示 */
        transition: none; /* スマホ表示時はアニメーションを無効化 */
    }
    .index-container {
        width: 100%;
        position: relative;
        top: 0;
        margin-bottom: 20px;
        order: 1; /* 目次を上に表示 */
    }
    #index-content {
        display: none; /* スマホ表示時にデフォルトで非表示 */
    }
    /* 目次非表示時のスタイル */
    .content-wrapper.toc-hidden .index-container {
        margin-bottom: 0 !important;
        border-bottom: none !important;
        padding-bottom: 0 !important;
        min-height: 0 !important;
        height: auto !important;
    }
}
