/**
 * LD4T Portable Text — front-end content styles.
 * Scoped to .cms-content so it never leaks into the rest of the theme.
 * Uses the theme's --ld4t-* tokens with fallbacks.
 */

.cms-content {
	--cms-orange: var( --ld4t-orange, #f97316 );
	--cms-blue: var( --ld4t-blue-bright, #2563eb );
	--cms-ink: var( --ld4t-ink, #0f172a );
	--cms-muted: var( --ld4t-muted, #64748b );
	--cms-border: var( --ld4t-border, #e2e8f0 );
	--cms-surface: var( --ld4t-surface, #f8fafc );
	color: var( --ld4t-text, #334155 );
	line-height: 1.75;
}

.cms-content > *:first-child {
	margin-top: 0;
}

.cms-content p {
	margin: 0 0 1.1em;
}

.cms-content h1,
.cms-content h2,
.cms-content h3,
.cms-content h4 {
	color: var( --cms-ink );
	line-height: 1.25;
	margin: 1.6em 0 .5em;
	font-family: var( --ld4t-font-heading, inherit );
}

.cms-content h1 { font-size: 2em; }
.cms-content h2 { font-size: 1.6em; }
.cms-content h3 { font-size: 1.3em; }
.cms-content h4 { font-size: 1.1em; }

.cms-content a {
	color: var( --cms-blue );
	text-decoration: underline;
	text-underline-offset: 2px;
}

.cms-content a:hover {
	color: var( --cms-orange );
}

.cms-content strong { font-weight: 700; }
.cms-content em { font-style: italic; }
.cms-content u { text-decoration: underline; }

.cms-content code {
	background: var( --cms-surface );
	border: 1px solid var( --cms-border );
	border-radius: 4px;
	padding: .1em .4em;
	font-family: Consolas, Monaco, monospace;
	font-size: .9em;
}

.cms-content blockquote {
	position: relative;
	margin: 1.8em 0;
	padding: 0 0 0 1.5em;
	color: var( --cms-ink );
	font-family: var( --ld4t-font-heading, inherit );
	font-size: 1.25em;
	font-style: italic;
	line-height: 1.5;
}

.cms-content blockquote::before {
	content: '\201C';
	position: absolute;
	left: 0;
	top: -.1em;
	font-family: Georgia, 'Times New Roman', serif;
	font-style: normal;
	font-size: 2.2em;
	line-height: 1;
	color: var( --cms-orange );
}

.cms-content ul,
.cms-content ol {
	margin: 0 0 1.1em;
	padding-left: 1.5em;
}

.cms-content li {
	margin: .3em 0;
}

.cms-content .cms-image {
	margin: 1.6em 0;
}

.cms-content .cms-image img {
	max-width: 100%;
	height: auto;
	border-radius: var( --ld4t-radius, 14px );
}

.cms-content .cms-image figcaption {
	margin-top: .5em;
	font-size: .9em;
	color: var( --cms-muted );
	text-align: center;
}

/* Callout — full border + tint, not a side-stripe accent */
.cms-content .cms-callout {
	margin: 1.4em 0;
	padding: 1em 1.2em;
	border-radius: var( --ld4t-radius, 14px );
	border: 1px solid var( --cms-border );
	background: var( --cms-surface );
}

.cms-content .cms-callout-info {
	border-color: #93c5fd;
	background: var( --ld4t-blue-light, #dbeafe );
}

.cms-content .cms-callout-warning {
	border-color: #fdba74;
	background: var( --ld4t-orange-light, #ffedd5 );
}

.cms-content .cms-callout-success {
	border-color: #86efac;
	background: #dcfce7;
}

/* Embed (responsive 16:9) */
.cms-content .cms-embed {
	margin: 1.6em 0;
}

.cms-content .cms-embed-frame {
	position: relative;
	width: 100%;
	padding-bottom: 56.25%;
	height: 0;
	border-radius: var( --ld4t-radius, 14px );
	overflow: hidden;
	background: #000;
}

.cms-content .cms-embed-frame iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: 0;
}

/* Code block */
.cms-content pre.cms-code {
	margin: 1.4em 0;
	padding: 1em 1.2em;
	overflow-x: auto;
	background: var( --ld4t-ink, #0f172a );
	color: #e2e8f0;
	border-radius: var( --ld4t-radius-sm, 8px );
	font-size: .9em;
	line-height: 1.6;
}

.cms-content pre.cms-code code {
	background: none;
	border: 0;
	padding: 0;
	color: inherit;
	font-family: Consolas, Monaco, "Courier New", monospace;
}

/* Button / CTA */
.cms-content .cms-button-wrap {
	margin: 1.4em 0;
}

/* Divider */
.cms-content hr.cms-divider {
	margin: 2em 0;
	border: 0;
	border-top: 1px solid var( --cms-border );
}

/**
 * The theme's global widget sidebar (#secondary, "Quick Link" etc.) competes
 * with the TOC for the same right-hand rail on this CPT, so it's hidden here
 * and .site-main reclaims the full row. Scoped to the body class — every
 * other post type keeps the theme's sidebar untouched.
 */
.single-ld4t_cms_doc .content-area-with-sidebar {
	grid-template-columns: 1fr;
}

.single-ld4t_cms_doc #secondary.widget-area {
	display: none;
}

/**
 * Article layout — table of contents + content, added around .cms-content
 * only on the single ld4t_cms_doc view when there are enough headings to
 * justify it (see ld4t_cms_render_toc() in inc/render.php). The TOC sits in
 * the same right-hand position the theme sidebar would otherwise occupy
 * (see the sidebar-suppression rule above) — .cms-article-toc-col is `order:
 * 2` for exactly that reason.
 */
.cms-article {
	display: flex;
	align-items: flex-start;
	gap: 48px;
	max-width: var( --ld4t-container, 1200px );
	margin: 0 auto;
}

.cms-article-toc-col {
	flex: 0 0 240px;
	width: 240px;
	order: 2;
}

.cms-article-body {
	flex: 1 1 auto;
	min-width: 0;
	order: 1;
}

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

.cms-toc-toggle {
	display: none;
}

.cms-toc-panel {
	background: #fff;
	border: 1px solid var( --ld4t-border, #e2e8f0 );
	border-radius: var( --ld4t-radius, 14px );
	box-shadow: var( --ld4t-shadow-sm, 0 2px 10px -3px rgba( 15, 23, 42, .12 ) );
	padding: 20px;
}

.cms-toc-title {
	margin: 0 0 .75em;
	font-family: var( --ld4t-font-heading, inherit );
	font-weight: 600;
	font-size: 1em;
	color: var( --ld4t-ink, #0f172a );
}

.cms-toc ul {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: .3em;
}

.cms-toc a {
	position: relative;
	display: block;
	padding: .35em .6em .35em 1.9em;
	border-radius: var( --ld4t-radius-sm, 8px );
	color: var( --ld4t-muted, #64748b );
	text-decoration: none;
	font-size: .95em;
	line-height: 1.4;
	transition: background-color .2s ease, color .2s ease;
}

.cms-toc a:hover {
	color: var( --ld4t-blue-bright, #2563eb );
	background: var( --ld4t-surface, #f8fafc );
}

/*
 * Step-progress marker: a small circle before each link tracking whether
 * that section is upcoming (hollow), the one being read now (filled orange),
 * or already passed (filled, checkmark) — see initScrollProgress() in
 * assets/js/toc.js, which is the sole source of the is-current/is-done state.
 */
.cms-toc a::before {
	content: '';
	position: absolute;
	left: .6em;
	top: 50%;
	width: 9px;
	height: 9px;
	margin-top: -4.5px;
	border-radius: 50%;
	border: 1.5px solid var( --ld4t-border, #e2e8f0 );
	background: #fff;
	transition: background-color .2s ease, border-color .2s ease, transform .2s ease;
}

.cms-toc li.is-current > a {
	color: var( --cms-orange, #f97316 );
	background: var( --ld4t-orange-light, #ffedd5 );
	font-weight: 500;
}

.cms-toc li.is-current > a::before {
	border-color: var( --cms-orange, #f97316 );
	background: var( --cms-orange, #f97316 );
	transform: scale( 1.2 );
}

.cms-toc li.is-done > a {
	color: var( --ld4t-muted, #64748b );
}

.cms-toc li.is-done > a::before {
	border-color: var( --cms-orange, #f97316 );
	background-color: var( --cms-orange, #f97316 );
	background-image: url( "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.3l3 3 6-6' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E" );
	background-size: 8px 8px;
	background-position: center;
	background-repeat: no-repeat;
}

.cms-toc-lvl-3 a { padding-left: 2.8em; }
.cms-toc-lvl-3 a::before { left: 1.5em; }
.cms-toc-lvl-4 a { padding-left: 3.7em; font-size: .88em; }
.cms-toc-lvl-4 a::before { left: 2.4em; }

@media ( prefers-reduced-motion: reduce ) {
	.cms-toc a,
	.cms-toc a::before {
		transition: none;
	}
}

@media ( max-width: 991px ) {
	.cms-article {
		flex-direction: column;
		gap: 16px;
	}

	.cms-article-toc-col {
		width: 100%;
		order: 1;
	}

	.cms-article-body {
		order: 2;
	}

	.cms-toc {
		position: static;
	}

	.cms-toc-toggle {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: .5em;
		width: 100%;
		background: #fff;
		border: 1px solid var( --ld4t-border, #e2e8f0 );
		border-radius: var( --ld4t-radius, 14px );
		padding: .85em 1.1em;
		font-family: var( --ld4t-font-heading, inherit );
		font-weight: 500;
		font-size: .95em;
		color: var( --ld4t-ink, #0f172a );
		cursor: pointer;
	}

	.cms-toc-toggle::after {
		content: '\25be';
		transition: transform .2s ease;
	}

	.cms-toc-toggle[ aria-expanded="true" ]::after {
		transform: rotate( 180deg );
	}

	.cms-toc-panel {
		margin-top: 8px;
		display: none;
	}

	.cms-toc-panel.is-open {
		display: block;
	}

	@media ( prefers-reduced-motion: reduce ) {
		.cms-toc-toggle::after { transition: none; }
	}
}

/**
 * Article header — editorial treatment for the single ld4t_cms_doc view.
 * Scoped to the body class so it never touches posts/pages using the same
 * theme template.
 */
.single-ld4t_cms_doc .entry-header {
	max-width: var( --ld4t-container, 1200px );
	margin: 0 auto;
	padding: 0 0 8px;
	text-align: center;
}

.single-ld4t_cms_doc .entry-title {
	font-size: clamp( 1.8rem, 1.3rem + 2vw, 2.6rem );
	line-height: 1.25;
	text-wrap: balance;
}

.single-ld4t_cms_doc .entry-meta {
	justify-content: center;
	color: var( --ld4t-muted, #64748b );
	font-size: .95em;
}

.single-ld4t_cms_doc .entry-thumbnail {
	max-width: var( --ld4t-container, 1200px );
	margin: 24px auto 40px;
}

.single-ld4t_cms_doc .entry-thumbnail img {
	width: 100%;
	height: auto;
	border-radius: var( --ld4t-radius, 14px );
}

/* Reading-progress bar, fixed to the viewport top. */
.cms-progress {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 3px;
	background: transparent;
	z-index: 100001;
}

.cms-progress-bar {
	height: 100%;
	width: 100%;
	background: var( --ld4t-orange, #f97316 );
	transform: scaleX( 0 );
	transform-origin: left;
}

@media ( prefers-reduced-motion: no-preference ) {
	.cms-progress-bar {
		transition: transform .1s linear;
	}
}

/* Closing CTA. */
.cms-closing-cta {
	max-width: var( --ld4t-container, 1200px );
	margin: 48px auto 0;
	padding: 40px;
	border-radius: var( --ld4t-radius, 14px );
	background: var( --ld4t-orange-light, #ffedd5 );
	text-align: center;
}

.cms-closing-cta-heading {
	margin: 0 0 20px;
	font-family: var( --ld4t-font-heading, inherit );
	font-weight: 600;
	font-size: 1.4em;
	color: var( --ld4t-ink, #0f172a );
}

/*
 * The one authored entrance on this page (see initCtaEntrance() in
 * assets/js/toc.js). `.cms-cta-armed` only ever gets added by JS immediately
 * before the reveal is wired up, so a script error can't leave the CTA
 * stuck invisible — without JS, or with reduced motion, it's just always
 * visible in its final position.
 */
.cms-closing-cta.cms-cta-armed {
	opacity: 0;
	transform: translateY( 24px ) scale( .98 );
	transition: opacity .6s cubic-bezier( .16, 1, .3, 1 ), transform .6s cubic-bezier( .16, 1, .3, 1 );
}

.cms-closing-cta.cms-cta-armed.cms-cta-in {
	opacity: 1;
	transform: none;
}
