/*
 * Internal page shell (T4, docs/05-templates-and-pages.md).
 *
 * Shared by templates/page.html and every internal single template. All rules
 * are scoped to .charis-page so the home-page styles in style.css stay
 * untouched. The shell has two bands:
 *   1. .charis-page-header — grey intro band with breadcrumbs, H1 and lead;
 *   2. .wp-block-post-content — white reading column (1200px at 1280).
 * Colours, radii and spacing resolve through theme.json presets.
 */

.charis-page {
	--charis-page-h1: var(--wp--preset--font-size--fs-h-1);
	--charis-page-h1-line: 72px;
	--charis-page-h2: var(--wp--preset--font-size--fs-h-2);
	--charis-page-h2-line: 56px;
	--charis-page-h3: var(--wp--preset--font-size--fs-h-3);
	--charis-page-h3-line: 48px;
	--charis-page-h4: var(--wp--preset--font-size--fs-h-4);
	--charis-page-h4-line: 40px;
	--charis-page-h5: var(--wp--preset--font-size--fs-h-5);
	--charis-page-h5-line: 28px;
	--charis-page-lead: var(--wp--preset--font-size--fs-body-l);
	--charis-page-lead-line: 32px;

	margin-block-start: 0;
	background-color: var(--wp--preset--color--bg-white);
	color: var(--wp--preset--color--text-main);
}

/* The shell is one vertical stack; the band and the body sit edge to edge. */
.charis-page > * + * {
	margin-block-start: 0;
}

/* ---- Intro band --------------------------------------------------------- */

.charis-page-header {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--60);
	padding-block: var(--wp--preset--spacing--90) var(--wp--preset--spacing--100);
	padding-inline: max(var(--wp--preset--spacing--80), calc((100% - var(--charis-content-width)) / 2));
	background-color: var(--wp--preset--color--bg-grey);
	color: var(--wp--preset--color--text-main);
}

/* Breadcrumbs, H1 and lead are three stacked blocks, not a core flow list. */
.charis-page-header > * {
	margin-block: 0;
}

.charis-page-header .wp-block-charis-breadcrumbs {
	margin-block: 0;
}

.charis-page-header__title {
	margin: 0;
	color: var(--wp--preset--color--brand-indigo);
	font-size: var(--charis-page-h1);
	font-weight: 600;
	letter-spacing: var(--wp--custom--charis--ls-h-1);
	line-height: var(--charis-page-h1-line);
	overflow-wrap: break-word;
}

.charis-page-header__lead {
	max-width: 840px;
	margin: 0;
	color: var(--wp--preset--color--text-main);
	font-size: var(--charis-page-lead);
	font-weight: 300;
	line-height: var(--charis-page-lead-line);
}

.charis-page-header__lead .wp-block-post-excerpt__excerpt,
.charis-page-header__lead .wp-block-post-excerpt__more-text {
	margin: 0;
}

/* The lead is optional. Hide the wrapper when core renders it empty (for
 * example when the excerpt is blank) instead of leaving a phantom gap. */
.charis-page-header__lead:empty,
.charis-page-header__lead .wp-block-post-excerpt__excerpt:empty {
	display: none;
}

/* ---- 404 empty state ----------------------------------------------------
 * The 404 template is a single grey band: display-size 404, short
 * explanation, one way back. It deliberately has no search and no cards —
 * a missing URL is not a browsing context. */

.charis-page-header--404 {
	align-items: center;
	gap: var(--wp--preset--spacing--70);
	padding-block: clamp(96px, 12vw, 160px);
	text-align: center;
}

.charis-page-header--404 .charis-404__title {
	font-size: clamp(96px, 14vw, 168px);
	letter-spacing: var(--wp--custom--charis--ls-heading);
	line-height: 0.86;
}

.charis-404__text {
	max-width: 560px;
	margin: 0;
	font-size: var(--wp--preset--font-size--fs-body-l);
	font-weight: 300;
	line-height: 32px;
}

.charis-404__actions {
	justify-content: center;
	margin: 0;
}

@media (max-width: 767px) {

	.charis-page-header.charis-page-header--404 {
		gap: var(--wp--preset--spacing--60);
		padding-block: var(--wp--preset--spacing--100);
	}

	.charis-404__icon {
		width: 80px;
		height: 80px;
	}

	.charis-404__text {
		font-size: var(--wp--preset--font-size--fs-body-m);
		line-height: 28px;
	}
}

/* ---- Reading column ----------------------------------------------------- */

.charis-page .wp-block-post-content.charis-page__body {
	box-sizing: border-box;
	width: 100%;
	padding-block: var(--wp--preset--spacing--100) var(--wp--preset--spacing--110);
	padding-inline: max(var(--wp--preset--spacing--80), calc((100% - var(--charis-content-width)) / 2));
	background-color: var(--wp--preset--color--bg-white);
	color: var(--wp--preset--color--text-main);
	font-size: var(--wp--preset--font-size--fs-body-m);
	line-height: 28px;
	overflow-wrap: break-word;
}

/* One rhythm for every top-level block: 24px, with larger air before
 * headings (64/48/40/32). The first child always starts at zero. */
.charis-page .wp-block-post-content > * {
	margin-block-start: 0;
	margin-block-end: 0;
}

.charis-page .wp-block-post-content > * + * {
	margin-block-start: var(--wp--preset--spacing--60);
}

.charis-page .wp-block-post-content > * + h2 {
	margin-block-start: var(--wp--preset--spacing--100);
}

.charis-page .wp-block-post-content > * + h3 {
	margin-block-start: 48px;
}

.charis-page .wp-block-post-content > * + h4 {
	margin-block-start: var(--wp--preset--spacing--80);
}

.charis-page .wp-block-post-content > * + h5,
.charis-page .wp-block-post-content > * + h6 {
	margin-block-start: var(--wp--preset--spacing--70);
}

/* Long-form copy is capped at 840px; media, columns, galleries, groups and
 * query loops may use the full 1200px column. */
.charis-page .wp-block-post-content > :is(p, h2, h3, h4, h5, h6, .wp-block-heading, ul, ol, .wp-block-list, .wp-block-quote, .wp-block-pullquote, .wp-block-table, .wp-block-details, .wp-block-buttons, .wp-block-file, .wp-block-separator, .wp-block-code, .wp-block-preformatted, .wp-block-verse) {
	max-width: 840px;
}

/* Typography defaults use :where() so any reusable charis/* block can
 * override them with its own block stylesheet. The page shell owns rhythm and
 * reading width, not the internals of content blocks. */
:where(.charis-page .wp-block-post-content) p {
	font-size: var(--wp--preset--font-size--fs-body-m);
	line-height: 28px;
}

:where(.charis-page .wp-block-post-content) h2,
:where(.charis-page .wp-block-post-content) h3,
:where(.charis-page .wp-block-post-content) h4,
:where(.charis-page .wp-block-post-content) h5,
:where(.charis-page .wp-block-post-content) h6,
:where(.charis-page .wp-block-post-content) .wp-block-heading {
	font-weight: 600;
}

:where(.charis-page .wp-block-post-content) h2 {
	font-size: var(--charis-page-h2);
	letter-spacing: var(--wp--custom--charis--ls-heading);
	line-height: var(--charis-page-h2-line);
}

:where(.charis-page .wp-block-post-content) h3 {
	font-size: var(--charis-page-h3);
	letter-spacing: var(--wp--custom--charis--ls-heading);
	line-height: var(--charis-page-h3-line);
}

:where(.charis-page .wp-block-post-content) h4 {
	font-size: var(--charis-page-h4);
	letter-spacing: 0;
	line-height: var(--charis-page-h4-line);
}

:where(.charis-page .wp-block-post-content) h5 {
	font-size: var(--charis-page-h5);
	letter-spacing: 0;
	line-height: var(--charis-page-h5-line);
}

:where(.charis-page .wp-block-post-content) h6 {
	font-size: var(--wp--preset--font-size--fs-control-m);
	letter-spacing: 0;
	line-height: 24px;
}

/* Quote text keeps the Body/L scale from the theme.json quote block. */
:where(.charis-page .wp-block-post-content) .wp-block-quote p,
:where(.charis-page .wp-block-post-content) .wp-block-pullquote p {
	font-size: var(--wp--preset--font-size--fs-body-l);
	line-height: var(--charis-page-lead-line);
}

.charis-page .wp-block-post-content > .wp-block-quote,
.charis-page .wp-block-post-content > .wp-block-pullquote {
	margin-block: var(--wp--preset--spacing--90);
}

.charis-page .wp-block-post-content > .wp-block-quote:first-child,
.charis-page .wp-block-post-content > .wp-block-pullquote:first-child {
	margin-block-start: 0;
}

/* Columns keep the 40px section gap on desktop and stack with a 24px gap on
 * mobile (core switches them to one column at 781px). */
.charis-page .wp-block-post-content .wp-block-columns {
	gap: var(--wp--preset--spacing--80);
}

.charis-page .wp-block-post-content .wp-block-column > * {
	margin-block-start: 0;
	margin-block-end: 0;
}

.charis-page .wp-block-post-content .wp-block-column > * + * {
	margin-block-start: var(--wp--preset--spacing--60);
}

/* Inline links in prose only: reusable blocks own their link/card colours. */
:where(.charis-page .wp-block-post-content) :is(p, li) a:not(.wp-block-button__link):not(.wp-element-button):not([class*="wp-block-charis-"]) {
	color: var(--wp--preset--color--brand-red);
	text-decoration: underline;
	text-underline-offset: 2px;
}

:where(.charis-page .wp-block-post-content) :is(p, li) a:not(.wp-block-button__link):not(.wp-element-button):not([class*="wp-block-charis-"]):hover {
	color: var(--wp--preset--color--brand-red-hover);
}

:where(.charis-page .wp-block-post-content) :is(p, li) a:focus-visible {
	border-radius: var(--wp--preset--border-radius--r-8);
	outline: none;
	box-shadow: var(--charis-focus-ring);
}

/* Lists and nested lists share the 24px block rhythm. Reusable block lists
 * (numbers, partner logos) are excluded: their own stylesheet owns layout. */
:where(.charis-page .wp-block-post-content) :is(ul, ol):not([class*="wp-block-charis-"]) {
	line-height: 28px;
}

:where(.charis-page .wp-block-post-content) :is(ul, ol):not([class*="wp-block-charis-"]) li + li {
	margin-block-start: var(--wp--preset--spacing--20);
}

:where(.charis-page .wp-block-post-content) :is(ul, ol):not([class*="wp-block-charis-"]) li > :is(ul, ol) {
	margin-block: 0;
	margin-block-start: var(--wp--preset--spacing--20);
}

/* Raw paragraphs inside legacy list markup (privacy/terms imports): keep the
 * line rhythm without the browser's 1em default margins. */
:where(.charis-page .wp-block-post-content) :is(ul, ol):not([class*="wp-block-charis-"]) li p {
	margin-block: 0;
}

:where(.charis-page .wp-block-post-content) :is(ul, ol):not([class*="wp-block-charis-"]) li p + p {
	margin-block-start: var(--wp--preset--spacing--20);
}

/* Tables: capped to the reading width, scroll inside their own wrapper. */
.charis-page .wp-block-post-content .wp-block-table {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.charis-page .wp-block-post-content .wp-block-table table {
	width: 100%;
}

/* Media uses the 1200px column with the r-24 brand radius. */
.charis-page .wp-block-post-content .wp-block-image img,
.charis-page .wp-block-post-content .wp-block-gallery img,
.charis-page .wp-block-post-content .wp-block-media-text__media img,
.charis-page .wp-block-post-content .wp-block-media-text__media video,
.charis-page > .wp-block-post-featured-image img {
	border-radius: var(--wp--preset--border-radius--r-24);
}

.charis-page .wp-block-post-content .wp-block-image figcaption,
.charis-page .wp-block-post-content .wp-block-gallery figcaption,
.charis-page .wp-block-post-content .wp-block-table figcaption {
	margin-block-start: var(--wp--preset--spacing--30);
	text-align: left;
}

/* Buttons: keep the shared button system, add a page-level gap. */
.charis-page .wp-block-post-content .wp-block-buttons {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--40);
}

/* Group backgrounds get a comfortable inset even when the editor leaves the
 * padding untouched; explicit block padding still wins. */
.charis-page .wp-block-post-content > .wp-block-group:is(
	.has-background,
	.is-style-on-lightpeach
):not(.is-style-hero):not(.is-style-page-hero):not(.is-style-sheet):not(.is-style-section-stack):not(.is-style-block-stack):not(.is-style-content-section) {
	padding: var(--wp--preset--spacing--80);
	border-radius: var(--wp--preset--border-radius--r-24);
}

/* Separators and details follow the long-form rhythm. */
.charis-page .wp-block-post-content > .wp-block-separator {
	margin-block: var(--wp--preset--spacing--90);
}

.charis-page .wp-block-post-content > .wp-block-details {
	margin-block-start: var(--wp--preset--spacing--40);
}

/* Final guard: however the first block is spaced, the column always starts
 * flush with its top padding. */
.charis-page .wp-block-post-content > *:first-child {
	margin-block-start: 0;
}

/* Featured image (single templates): 1200px column below the intro band. */
.charis-page > .wp-block-post-featured-image.charis-page__featured {
	box-sizing: border-box;
	width: 100%;
	margin: 0;
	padding-block: var(--wp--preset--spacing--100) 0;
	padding-inline: max(var(--wp--preset--spacing--80), calc((100% - var(--charis-content-width)) / 2));
	background-color: var(--wp--preset--color--bg-white);
}

.charis-page > .wp-block-post-featured-image.charis-page__featured img {
	display: block;
	width: auto;
	max-width: 100%;
	max-height: 560px;
	height: auto;
	margin-inline: auto;
	border-radius: var(--wp--preset--border-radius--r-24);
}

/* ---- Core alignment inside the page body -------------------------------- */

.charis-page .wp-block-post-content > .alignwide {
	box-sizing: border-box;
	width: 100%;
	max-width: var(--charis-content-width);
	margin-inline: 0;
}

/* Full-bleed section inside the reading column. The negative inline margin is
 * measured from the padded content box, so the block lands on the viewport
 * edges; `width: auto` plus those margins avoids the 100vw scrollbar problem
 * while still filling the viewport. Padding restores the 1200px column. */
.charis-page .wp-block-post-content > .alignfull {
	box-sizing: border-box;
	width: auto;
	max-width: none;
	margin-inline: calc(50% - 50vw);
	padding-inline: max(var(--wp--preset--spacing--80), calc((100vw - var(--charis-content-width)) / 2));
}

/* Section-composed pages: when the content starts with a top-level hero
 * section, the content owns the hero, backgrounds and rhythm. Legacy pages
 * without such a section keep the reading column untouched. */

.charis-page:has(.charis-page__body > :is(.is-style-hero, .is-style-page-hero)) .charis-page-header {
	display: none;
}

/* The body class is repeated with .wp-block-post-content so the reset also
 * wins over the ≤767px reading padding further down this file. */

.charis-page .wp-block-post-content.charis-page__body:has(> :is(.is-style-hero, .is-style-page-hero)) {
	padding-block: 0;
	padding-inline: 0;
}

.charis-page .charis-page__body:has(> :is(.is-style-hero, .is-style-page-hero)) > * {
	margin-block: 0;
}

.charis-page .wp-block-post-content > :is(.is-style-hero, .is-style-page-hero, .is-style-sheet, .is-style-content-section):has(> .is-style-container) {
	padding-inline: 0;
}

.charis-page .wp-block-post-content > .is-style-sheet {
	margin-block-start: -56px;
}

/* ---- Mobile (≤767px): 390px reference, 20px side padding ---------------- */

@media (max-width: 767px) {

	.charis-page {
		--charis-page-h1: 40px;
		--charis-page-h1-line: 48px;
		--charis-page-h2: 32px;
		--charis-page-h2-line: 40px;
		--charis-page-h3: 28px;
		--charis-page-h3-line: 36px;
		--charis-page-h4: 24px;
		--charis-page-h4-line: 32px;
		--charis-page-h5: 20px;
		--charis-page-h5-line: 28px;
	}

	.charis-page-header {
		padding-block: var(--wp--preset--spacing--80);
		padding-inline: var(--wp--preset--spacing--50);
	}

	.charis-page .wp-block-post-content.charis-page__body {
		padding-block: var(--wp--preset--spacing--80) var(--wp--preset--spacing--100);
		padding-inline: var(--wp--preset--spacing--50);
	}

	.charis-page > .wp-block-post-featured-image.charis-page__featured {
		padding-block-start: var(--wp--preset--spacing--80);
		padding-inline: var(--wp--preset--spacing--50);
	}

	.charis-page .wp-block-post-content > * + h2 {
		margin-block-start: var(--wp--preset--spacing--80);
	}

	.charis-page .wp-block-post-content > * + h3 {
		margin-block-start: var(--wp--preset--spacing--70);
	}

	.charis-page .wp-block-post-content > * + h4 {
		margin-block-start: var(--wp--preset--spacing--60);
	}

	.charis-page .wp-block-post-content > * + h5,
	.charis-page .wp-block-post-content > * + h6 {
		margin-block-start: var(--wp--preset--spacing--50);
	}

	.charis-page .wp-block-post-content > .wp-block-group:is(
		.has-background,
		.is-style-on-lightpeach
	):not(.is-style-hero):not(.is-style-page-hero):not(.is-style-sheet):not(.is-style-section-stack):not(.is-style-block-stack):not(.is-style-content-section) {
		padding: var(--wp--preset--spacing--50);
	}

	.charis-page .wp-block-post-content .wp-block-table table {
		min-width: 560px;
	}

	.charis-page .wp-block-post-content > .alignfull {
		padding-inline: var(--wp--preset--spacing--50);
	}

	.charis-page .wp-block-post-content > .is-style-sheet {
		margin-block-start: -3px;
	}

	/* Catalog sheet (Figma Mobile / Find support): cards and chips sit on the
	 * 12px side margin, not the generic 20px sheet padding. */
	.charis-page .wp-block-post-content > .is-style-sheet > .wp-block-group.is-style-container:has(.wp-block-charis-scheme-results) {
		padding-inline: 12px;
	}
}

/* ---- Kitchen sink QA chrome ---------------------------------------------
 * The catalogue is composed from the generic page primitives: an
 * `is-style-page-hero` band followed by an `is-style-section-stack` canvas in
 * the normal page body. These rules only name QA utility classes; every block
 * keeps its own stylesheet and no page-scoped shell remains. */

/* Catalogue labels carry the section rhythm. The intro paragraph now lives in
 * the page hero, so the first label is the first stack child. */
.ks-stack > *:not(.ks-label) {
	margin-block: 0;
}

.ks-label {
	max-width: none;
	margin-block: 72px 20px;
	color: var(--wp--preset--color--brand-indigo);
	font-size: 24px;
	font-weight: 600;
	letter-spacing: 0;
	line-height: 32px;
}

.ks-label:first-child {
	margin-block-start: 40px;
}

/* The catalogue is a series of stacks, one per page/area: a section title,
 * an optional note, then label + block pairs. */
.ks-stack {
	padding-block-end: 40px;
}

.ks-stack > .ks-title {
	margin-block: 56px 0;
	color: var(--wp--preset--color--brand-indigo);
}

.ks-stack > .ks-note,
.ks-stack > .ks-toc {
	max-width: 840px;
	margin-block: 16px 0;
	color: var(--wp--preset--color--text-placeholder, var(--wp--preset--color--brand-indigo));
}

.ks-stack > .ks-title + .ks-label {
	margin-block-start: 32px;
}

/* Core Gutenberg examples use the same 1200px column as the rest of the
 * site (no extra reading-column inset). */
.ks-core {
	box-sizing: border-box;
	padding-block-start: 32px;
}

/* ---- Archive cards (core/group style "card") ----------------------------
 * WP archives render one core/group.is-style-card per post: featured image
 * on top, title + excerpt in a grey body, red arrow pinned to the bottom.
 * The style is registered in functions.php and is reusable in the editor. */

.wp-block-group.is-style-card {
	display: flex;
	flex-direction: column;
	height: 100%;
	overflow: hidden;
	border-radius: var(--wp--preset--border-radius--r-32);
	background: var(--wp--preset--color--bg-grey);
}

.wp-block-group.is-style-card .wp-block-post-featured-image {
	margin: 0;
}

.wp-block-group.is-style-card .wp-block-post-featured-image a {
	display: block;
}

.wp-block-group.is-style-card .wp-block-post-featured-image img {
	display: block;
	width: 100%;
	aspect-ratio: 389 / 240;
	object-fit: cover;
}

.is-style-card__body {
	display: flex;
	flex: 1;
	flex-direction: column;
	box-sizing: border-box;
	padding: var(--wp--preset--spacing--70);
}

.is-style-card .wp-block-post-title {
	margin: 0 0 var(--wp--preset--spacing--40);
	color: var(--wp--preset--color--brand-indigo);
	font-size: var(--wp--preset--font-size--fs-h-5);
	font-weight: 600;
	line-height: 32px;
}

.is-style-card .wp-block-post-title a {
	color: inherit;
	text-decoration: none;
}

.is-style-card .wp-block-post-title a:focus-visible {
	border-radius: var(--wp--preset--border-radius--r-8);
	outline: none;
	box-shadow: var(--charis-focus-ring);
}

.is-style-card .wp-block-post-excerpt {
	margin: 0;
	color: var(--wp--preset--color--brand-indigo);
	font-family: var(--wp--preset--font-family--charis-display);
	font-size: var(--wp--preset--font-size--fs-body-s);
	font-weight: 300;
	line-height: 24px;
}

.is-style-card .wp-block-post-excerpt__more-link {
	display: none;
}

.is-style-card__body::after {
	margin-block-start: auto;
	padding-block-start: var(--wp--preset--spacing--60);
	color: var(--wp--preset--color--brand-red);
	content: "→";
	font-size: 20px;
	line-height: 16px;
	transition: transform var(--charis-icon-hover-duration) var(--charis-icon-hover-easing);
}

.wp-block-group.is-style-card:hover .is-style-card__body::after {
	transform: translateX(4px);
}

@media (prefers-reduced-motion: reduce) {

	.is-style-card__body::after {
		transition: none;
	}

	.wp-block-group.is-style-card:hover .is-style-card__body::after {
		transform: none;
	}
}

@media (min-width: 768px) and (max-width: 1199px) {

	/* Three 300px cards at tablet leave titles like “Management Accountant”
	 * breaking mid-word; two columns keep a readable measure. */
	.wp-block-post-template.is-layout-grid.columns-3 {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (max-width: 767px) {

	/* Archive/search card grids collapse to a single column on phones. */
	.wp-block-post-template.is-layout-grid.columns-3 {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* Legacy intro band: keep its position under the 76px tablet/mobile bar
 * (the bar used to be 92px); the grey border blends with the band. */
@media (max-width: 1023px) {

	body:not(.home) .charis-page-header {
		border-block-start: 16px solid var(--wp--preset--color--bg-grey);
	}
}

/* Editor only: core/post-excerpt shows an empty "Add "read more" link text"
 * placeholder under the page lead. Show it only while the block is selected
 * (the attribute exists only on an empty RichText in the editor). */
.wp-block-post-excerpt:not(.is-selected) .wp-block-post-excerpt__more-text:has(> [data-rich-text-placeholder]),
.wp-block-post-excerpt:not(.is-selected) .wp-block-post-excerpt__more-link[data-rich-text-placeholder] {
	display: none;
}
