/**
 * Table of Contents Plus（TOC+）— 目次のカスタムスタイル
 * 単位: フォント・行間（数値）は rem、余白・寸法・角丸・線は px
 */

/* --- コンテナ -------------------------------------------------------- */
#toc_container {
  background: #f4f4f4 !important;
  border: none !important;
  border-radius: 10px !important;
  padding: 20px;
  margin: 16px 0 32px;
  width: auto;
  display: block;
  font-size: 0.875rem; /* 14px 相当 */
}

/* --- タイトル -------------------------------------------------------- */
#toc_container p.toc_title {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: bold;
  font-size: 0.875rem;
  margin: 0 0 10px;
  position: relative;
}

/* トグルボタン（[閉じる] / [表示する]） */
#toc_container span.toc_toggle {
  font-weight: 400;
  font-size: 0.75rem;
  margin-left: 10px;
  color: #5f5f5f;
}

/* --- リスト ---------------------------------------------------------- */
#toc_container p.toc_title + ul.toc_list {
  margin-top: 20px;
}

#toc_container .toc_list,
#toc_container .toc_list ul {
  list-style: none !important;
  margin: 6px 0 0 !important;
  padding: 0 !important;
}

#toc_container .toc_list li {
  list-style: none !important;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

#toc_container .toc_list {
  counter-reset: toc-h2;
}

/* H2行: flex で番号・バー・リンクを縦中央で揃える */
#toc_container .toc_list > li {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  list-style: none !important;
  padding-left: 0;
  counter-increment: toc-h2;
  margin-bottom: 5px !important;
}

/* 「01」— 数字 */
#toc_container .toc_list > li::before {
  content: counter(toc-h2, decimal-leading-zero);
  color: #0b71b3;
  font-weight: bold;
  font-size: 0.8rem;
  line-height: 1;
  flex-shrink: 0;
  margin-right: 3px;
  margin-top: 6px;
}

/* H2直下のリンクを flex にしてバーとテキストを先頭揃え */
#toc_container .toc_list > li > a {
  display: flex;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
}

/* 「|」— バーブロック */
#toc_container .toc_list > li > a::before {
  content: "";
  display: block;
  font-size: 0.8rem;
  width: 1px;
  height: 12px;
  background-color: #0b71b3;
  flex-shrink: 0;
  box-sizing: content-box;
  margin-right: 6px;
  margin-top: 7px;
}

/* H3（第2階層）: 入れ子 ul を次行に全幅で折り返す */
#toc_container .toc_list > li > ul {
  flex: 1 0 100%;
  width: 100%;
  padding-left: 24px !important;
  margin-top: 12px !important;
}

#toc_container .toc_list > li > ul > li {
  margin-bottom: 8px !important;
  margin-left: 0 !important;
  padding-left: 0;
}

#toc_container .toc_list > li > ul > li:last-child {
  margin-bottom: 16px !important;
}

#toc_container .toc_list > li > ul > li::before {
  content: "–";
  color: #0b71b3;
  font-weight: bold;
  padding-right: 5px;
}

/* --- 番号を非表示 ---------------------------------------------------- */
#toc_container .toc_number {
  display: none !important;
}

/* --- リンク ---------------------------------------------------------- */
#toc_container a {
  color: #333;
  text-decoration: none;
  text-shadow: none;
}

#toc_container a:hover {
  text-decoration: underline;
}

/* =====================================================================
 * カスタムHTML目次（.toc-custom-wrap）
 * 記事内のカスタムブロック用。機能（折りたたみ・もっと見る・プラグイン目次の非表示）は維持し、
 * 上記の見た目（#F4F4F4・番号バー・入れ子）に揃える。
 * ===================================================================== */

/* プラグイン自動生成の目次を隠し、カスタム側の #toc_container のみ表示 */
body:has(.toc-custom-wrap) #toc_container {
  display: none !important;
}

body:has(.toc-custom-wrap) .toc-custom-wrap #toc_container {
  display: block !important;
  position: relative;
}

/* カスタム枠内では、プラグインの [閉じる]/[表示する] が付かない想定の調整 */
.toc-custom-wrap #toc_container:first-of-type span.toc_toggle {
  display: none;
}

/* --- 「もっと見る」：高さ制限・グラデーション（背景はコンテナと同色 #F4F4F4） --- */
.toc-custom-wrap #toc_container .toc_list {
  overflow: hidden;
  height: 185px;
  position: relative;
  padding-bottom: 45px !important;
}

.toc-custom-wrap #toc_container .toc_list.height {
  height: auto;
  overflow: auto;
}

.toc-custom-wrap #toc_container .toc_list::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  width: auto;
  pointer-events: none;
  background: linear-gradient(
    0deg,
    #f4f4f4 30%,
    #f4f4f4 60%,
    rgba(244, 244, 244, 0) 100%
  );
}

.toc-custom-wrap #toc_container .toc_list.no-bg::after {
  content: none;
}

/* a でも button でも同じ見た目（リンクではなく button 推奨：# によるスクロール防止） */
.toc-custom-wrap #toc_container a.more,
.toc-custom-wrap #toc_container button.more {
  font-size: 0.8125rem; /* 13px 相当 */
  position: absolute;
  bottom: 10px;
  left: 10px;
  cursor: pointer;
  z-index: 1;
  color: #0b71b3;
  text-decoration: none;
  font-weight: 600;
  font-family: inherit;
  line-height: inherit;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  text-align: left;
  appearance: none;
  -webkit-appearance: none;
}

.toc-custom-wrap #toc_container a.more:hover,
.toc-custom-wrap #toc_container button.more:hover {
  text-decoration: underline;
}

.toc-custom-wrap #toc_container button.more:focus-visible {
  outline: 2px solid #0b71b3;
  outline-offset: 2px;
}

/* --- セクション見出し行（リンクのない li）：カウンター・縦バーは出さない --- */
.toc-custom-wrap #toc_container .toc_list > li.toc-custom-section-label,
.toc-custom-wrap #toc_container .toc_list > li:not(:has(> a)) {
  display: block;
  width: 100%;
  flex: 1 0 100%;
  counter-increment: toc-h2 0;
  margin-top: 12px;
  margin-bottom: 8px !important;
  padding-left: 0;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #333;
  line-height: 1.45;
}

.toc-custom-wrap #toc_container .toc_list > li.toc-custom-section-label:first-child,
.toc-custom-wrap #toc_container .toc_list > li:not(:has(> a)):first-child {
  margin-top: 0;
}

.toc-custom-wrap #toc_container .toc_list > li.toc-custom-section-label::before,
.toc-custom-wrap #toc_container .toc_list > li:not(:has(> a))::before {
  content: none !important;
  margin: 0 !important;
}

/* 見出し行の直後の通常項目は上マージンを詰める */
.toc-custom-wrap #toc_container .toc_list > li.toc-custom-section-label + li > a,
.toc-custom-wrap #toc_container .toc_list > li:not(:has(> a)) + li > a {
  margin-top: 0;
}
