/* 目次（template-parts/article-toc.php）。記事詳細（PC はサイドバーで追従）とサービス詳細・業種と課題・長い固定ページ（PC は上端の帯で追従）、SP はどれも左下のボタンから下のシート */
@layer components {
	/* ===== 記事詳細の PC のサイドバー（sidebar） ===== */
	.article-toc-area {
		display: none;
	}

	@media (min-width: 1024px) {
		.article-toc-area {
			display: block;
			flex: 1 0 auto;
			margin-bottom: var(--sp-7);
		}

		.article-toc-sticky {
			position: sticky;
			top: 24px;
		}

		.article-toc-sticky .article-toc {
			max-height: calc(100vh - 54px);
			overflow-y: auto;
			overscroll-behavior: contain;
			padding: var(--sp-5);
			border: 1px solid var(--c-line);
			border-radius: var(--radius-md);
			background: var(--c-bg);
		}
	}

	.article-toc__title {
		margin: 0 0 var(--sp-3);
		font-family: var(--f-en);
		font-weight: 600;
		font-size: var(--fs-md);
		letter-spacing: var(--ls-en);
	}

	.article-toc__list {
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.article-toc__link {
		position: relative;
		display: block;
		padding: 0.4em 0.5em 0.4em 1.5em;
		border-radius: var(--radius-sm);
		color: var(--c-ink-sub);
		font-size: var(--fs-sm);
		line-height: 1.55;
		text-decoration: none;
	}

	.article-toc__link:hover {
		color: var(--c-ink);
		text-decoration: underline;
	}

	.article-toc__item--d1 .article-toc__link {
		color: var(--c-ink);
		font-size: var(--fs-sm);
		font-weight: 700;
	}

	.article-toc__item--d2 .article-toc__link {
		padding-left: 2.4em;
	}

	.article-toc__item--d3 .article-toc__link {
		padding-left: 3.2em;
	}

	/* 読んでいる所に紫の札 */
	.article-toc__link[aria-current] {
		background: var(--c-soft);
		color: var(--c-ink);
		font-weight: 700;
	}

	.article-toc__link[aria-current]::before {
		content: "";
		position: absolute;
		left: 6px;
		top: 0.55em;
		width: 7px;
		height: 1.1em;
		background: var(--c-brand);
		clip-path: var(--clip-tag);
	}

	/* 出す幅は下の @media で決める（記事詳細は 1023px 以下、帯のあるサービス詳細は --wide で 1279px 以下） */
	.article-toc-fab {
		position: fixed;
		left: 16px;
		bottom: 20px;
		z-index: 30;
		display: none;
		align-items: center;
		gap: 0.55em;
		padding: 0.8em 1.3em;
		border: 0;
		border-radius: var(--radius-pill);
		background: var(--c-brand);
		color: var(--c-on-brand);
		font: inherit;
		font-size: var(--fs-sm);
		font-weight: 700;
		box-shadow: var(--shadow-lift);
		cursor: pointer;
		opacity: 0;
		visibility: hidden;
		transform: translateY(12px);
		transition: opacity var(--dur-fast), transform var(--dur-fast), visibility var(--dur-fast);
	}

	.article-toc-fab.is-shown {
		opacity: 1;
		visibility: visible;
		transform: none;
	}

	.article-toc-fab[hidden] {
		display: none;
	}

	@media (max-width: 1023px) {
		.article-toc-fab {
			display: inline-flex;
		}
	}

	/* 帯（1280px 以上）とのすき間を作らない。拡大率によっては幅が 1279.2px のような端数になる */
	@media (max-width: 1279.98px) {
		.article-toc-fab--wide {
			display: inline-flex;
		}
	}

	.article-toc-fab__icon {
		position: relative;
		display: block;
		width: 14px;
		height: 10px;
		border-top: 2px solid currentColor;
		border-bottom: 2px solid currentColor;
	}

	.article-toc-fab__icon::before {
		content: "";
		position: absolute;
		top: 2px;
		left: 0;
		width: 100%;
		height: 2px;
		background: currentColor;
	}

	.article-toc-sheet {
		inset: auto 0 0 0;
		width: 100%;
		max-width: 100%;
		max-height: 80vh;
		margin: 0;
		padding: 0;
		overflow: hidden;
		border: 0;
		border-radius: 16px 16px 0 0;
		background: var(--c-bg);
		color: var(--c-ink);
	}

	.article-toc-sheet::backdrop {
		background: rgba(30, 22, 38, 0.5);
	}

	.article-toc-sheet .article-toc__title {
		margin: 0;
	}

	.article-toc-sheet__head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0.8em 1em 0.8em 1.3em;
		border-bottom: 1px solid var(--c-line);
	}

	.article-toc-sheet__close {
		position: relative;
		width: 44px;
		height: 44px;
		border: 0;
		background: none;
		cursor: pointer;
	}

	.article-toc-sheet__close::before,
	.article-toc-sheet__close::after {
		content: "";
		position: absolute;
		top: 50%;
		left: 50%;
		width: 18px;
		height: 2px;
		background: var(--c-ink);
	}

	.article-toc-sheet__close::before {
		transform: translate(-50%, -50%) rotate(45deg);
	}

	.article-toc-sheet__close::after {
		transform: translate(-50%, -50%) rotate(-45deg);
	}

	.article-toc--sheet {
		max-height: calc(80vh - 62px);
		overflow-y: auto;
		overscroll-behavior: contain;
		padding: 1em 1.3em 2em;
	}

	/*
	 * 固定ページの本文の h2 には style="scroll-margin-top:120px" が付いているものがある（本文は DB のまま変えない）。
	 * 付いたままだと飛び先が画面の上から 200px（html の scroll-padding-top と合わせて）に止まり、
	 * article-tools.js が読んでいる見出しとみなす位置（上から 120px）より下なので、押した項目が強調されない。
	 */
	.v2-page-scope .v2-content h2[id] {
		scroll-margin-top: 0 !important;
	}

	/* ===== サービス詳細の帯（bar）。1280px 以上だけ出し、それより狭いときは左下のボタン（sheet の wide）を使う ===== */
	.article-toc-bar {
		display: none;
	}

	@media (min-width: 1280px) {
		/* 追従する図（service.css の .v2-svc__media、top: var(--sp-6)）を帯（高さ約 50px）の下で止める */
		.v2-svc:has(.article-toc-bar) .v2-svc__media {
			top: calc(3.25rem + var(--sp-6));
		}

		.article-toc-bar {
			position: sticky;
			top: 0;
			z-index: 15;
			display: block;
			border-bottom: 1px solid var(--c-line);
			background: var(--c-bg);
		}
	}

	.article-toc--bar {
		display: flex;
		align-items: center;
		gap: var(--sp-4);
		max-width: calc(var(--w-content) + var(--gutter) * 2);
		margin-inline: auto;
		padding: var(--sp-2) var(--gutter);
	}

	.article-toc--bar .article-toc__title {
		flex: none;
		margin: 0;
		padding-right: var(--sp-4);
		border-right: 1px solid var(--c-line);
		font-size: var(--fs-sm);
		line-height: 1.55;
	}

	/* 1 行に並べる。載せるのは短い決まった文言だけなので、狭い幅では横に送る */
	.article-toc--bar .article-toc__list {
		display: flex;
		flex: 1 1 auto;
		min-width: 0;
		align-items: center;
		gap: var(--sp-1);
		overflow-x: auto;
		scrollbar-width: thin;
	}

	/* 本文の .v2-content li + li の上余白が付くと、2 つ目以降の項目だけ下にずれて上下の中央から外れる */
	.article-toc--bar .article-toc__item {
		flex: none;
		margin: 0;
	}

	.article-toc--bar .article-toc__link {
		padding: 0.4em 0.7em 0.4em 1.4em;
		font-weight: 400;
		white-space: nowrap;
	}

	/* 紫の札の位置は一覧と同じ。帯では文字を太くしない（幅が変わって並びがずれるため） */
	.article-toc--bar .article-toc__link[aria-current] {
		font-weight: 400;
	}
}
