/**
 * Entry content: singular post/page body, post navigation, pagination,
 * comments, and the search form (03-ui-system/02-template-system.md,
 * 04-content-areas/06-single-post-system.md §3).
 *
 * Enqueued by Kivora\Assets\Manager on the templates that render an entry
 * body — the blog grid uses post-card.css instead (04-css-architecture.md §5).
 */

/* Breadcrumbs: a small trail above the title. Separators live in CSS so
   screen readers hear "Home, Category, Title" with no clutter. */
.kivora-breadcrumbs {
	margin-block-end: var(--kivora-spacing-sm);
	font-size: var(--kivora-font-size-small);
	color: var(--kivora-color-border-muted);
}

.kivora-breadcrumbs ol {
	display: flex;
	flex-wrap: wrap;
	gap: var(--kivora-spacing-xs);
	list-style: none;
	margin: 0;
	padding: 0;
}

/* Flex items refuse to shrink past their longest word unless told to —
 * without this the trail keeps the page-wide overflow the wrap above
 * was meant to fix. */
.kivora-breadcrumbs li {
	min-width: 0;
}

.kivora-breadcrumbs li + li::before {
	/* The separator is decoration: the list already says these are separate
	   steps. The empty alternative text after the slash keeps screen readers
	   from announcing "single right-pointing angle quotation mark" between
	   crumbs; browsers without the syntax fall back to the line above. */
	content: "›";
	content: "›" / "";
	margin-inline-end: var(--kivora-spacing-xs);
}

/*
 * Crumb links keep their underline: against the current item and the muted
 * separators their colour difference is 1.24:1 to 2.38:1, too little to mark
 * them as links on its own (WCAG 1.4.1). Hover removes it, as in content.
 */
.kivora-breadcrumbs a {
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

.kivora-breadcrumbs a:hover {
	text-decoration: none;
}

.kivora-breadcrumbs [aria-current="page"] {
	color: var(--kivora-color-foreground);
}

/* 1. Entry */
.kivora-entry__header {
	margin-block-end: var(--kivora-spacing-md);
}

.kivora-entry__title {
	margin-block: 0 var(--kivora-spacing-xs);
}

/* A title printed as a paragraph because the content owns the page's h1
   (content-page.php, content-single.php): same look, no heading level. */
.kivora-entry__title--plain {
	font-size: var(--kivora-font-size-h1);
	font-weight: 700;
	line-height: 1.2;
}

.kivora-entry__meta {
	display: flex;
	flex-wrap: wrap;
	gap: var(--kivora-spacing-xs);
	font-size: var(--kivora-font-size-small);
	color: var(--kivora-color-border-muted);
}

.kivora-entry__thumbnail {
	margin-block-end: var(--kivora-spacing-md);
}

/*
 * Long-form reading: slightly larger body text than the blog index and a
 * consistent vertical rhythm between blocks (06-single-post-system.md §3).
 */
.kivora-entry__content {
	font-size: 1.125rem;
	line-height: 1.7;
}

.kivora-entry__content > * {
	margin-block: var(--kivora-spacing-md);
}

.kivora-entry__content > :first-child {
	margin-block-start: 0;
}

.kivora-entry__content > :last-child {
	margin-block-end: 0;
}

/*
 * Wide and full alignment inside ordinary content.
 *
 * add_theme_support( 'align-wide' ) is what puts the Wide and Full buttons in
 * the editor, and theme.json declares both widths, so the editor showed a
 * wide-aligned block breaking out of the text column -- while the front end
 * left it at the reading width, because nothing here styled .alignwide. The
 * two disagreed on every post anyone aligned by hand. Patterns were never
 * affected: their own constrained groups get layout rules from WordPress.
 *
 * The width is clamped against the viewport as well as against wideSize, so a
 * wide block on a narrow screen simply stays the width of the column instead of
 * pushing the page sideways. The gutter subtracted (2rem) is wider than any
 * scrollbar, which is what keeps 100vw honest here.
 */
/*
 * Only where there is room. Beside a sidebar the column is all the width there
 * is, and breaking out of it puts the image straight over the widgets -- which
 * is what the Theme Unit Test's "Block: Image" post did on the first attempt.
 */
.kivora-layout:not([class*="kivora-layout--sidebar-"]) .kivora-entry__content > .alignwide,
.kivora-layout:not([class*="kivora-layout--sidebar-"]) .kivora-entry__content > .alignfull {
	margin-inline: calc((100% - var(--kivora-align-width)) / 2);
	inline-size: var(--kivora-align-width);
	max-inline-size: var(--kivora-align-width);
}

.kivora-layout:not([class*="kivora-layout--sidebar-"]) .kivora-entry__content > .alignwide {
	--kivora-align-width: max(
		100%,
		min(var(--wp--style--global--wide-size, 1200px), 100vw - (var(--kivora-spacing-sm) * 2))
	);
}

.kivora-layout:not([class*="kivora-layout--sidebar-"]) .kivora-entry__content > .alignfull {
	--kivora-align-width: max(100%, 100vw - (var(--kivora-spacing-sm) * 2));
}

/*
 * Tablet stacking for the pattern opt-in class: core only stacks media-text
 * below 600px, which leaves a squeezed 50/50 row through the whole tablet
 * range. Below 880px the image goes on top and the copy underneath. The
 * content padding is inline in the markup, hence the !important — same as
 * core's own stacking rule.
 */
@media (max-width: 60rem) {
	.wp-block-media-text.kivora-stack-tablet {
		grid-template-columns: 100%;
	}

	.wp-block-media-text.kivora-stack-tablet .wp-block-media-text__media {
		grid-column: 1;
		grid-row: 1;
	}

	.wp-block-media-text.kivora-stack-tablet .wp-block-media-text__content {
		grid-column: 1;
		grid-row: 2;
		padding-inline-start: 0 !important;
	}
}

/* An image or gallery that has grown wider should fill the room it took. */
.kivora-entry__content > .alignwide img,
.kivora-entry__content > .alignfull img {
	inline-size: 100%;
}

/*
 * Section headings get extra room above them. A hero headline is an h2 set at
 * the h1 size (the page title owns the h1), and it keeps the spacing of its
 * pattern's layout instead, as it had when it was an h1. The exclusion sits in
 * :where() so the selector's specificity stays exactly what it was.
 */
.kivora-entry__content :is(h2, h3, h4):where(:not(.has-h-1-font-size)) {
	margin-block-start: var(--kivora-spacing-lg);
}

/*
 * Preformatted text is the one block that keeps its own width no matter how
 * narrow the column is: the Theme Unit Test's "Markup: HTML Tags and
 * Formatting" post carries a 1376px <pre>, which made the whole page scroll
 * sideways at both viewports. It scrolls inside its own box instead.
 */
.kivora-entry__content pre,
.kivora-comments pre {
	max-inline-size: 100%;
	overflow-x: auto;
}

/*
 * Long unbroken strings — pasted URLs, code spans, German compounds — would
 * push the column open the same way.
 */
.kivora-entry__content,
.kivora-comments .comment-content {
	overflow-wrap: break-word;
}

/*
 * The same for titles: the classic edge case is an 85-character single-word
 * post title, which otherwise scrolls the whole page sideways. The trail
 * carries the same title, so it gets the same treatment.
 */
.kivora-entry__title,
.kivora-archive-header__title,
.kivora-breadcrumbs {
	overflow-wrap: break-word;
}

/*
 * Plain HTML tables — imported content, classic editor posts, anything not a
 * core Table block — arrive with no styling at all and render as cramped,
 * borderless columns. Wrapped in :where() so they carry no specificity: the
 * Table block's own styles, and any plugin's, still win.
 */
:where(.kivora-entry__content, .kivora-comments .comment-content) table {
	inline-size: 100%;
	border-collapse: collapse;
}

:where(.kivora-entry__content, .kivora-comments .comment-content) th,
:where(.kivora-entry__content, .kivora-comments .comment-content) td {
	padding: var(--kivora-spacing-xs);
	border-block-end: 1px solid var(--kivora-color-border-muted);
	text-align: start;
	vertical-align: top;
}

:where(.kivora-entry__content, .kivora-comments .comment-content) th {
	font-weight: 700;
}

:where(.kivora-entry__content, .kivora-comments .comment-content) caption {
	padding-block-end: var(--kivora-spacing-xs);
	font-size: var(--kivora-font-size-small);
	color: var(--kivora-color-border-muted);
}

/* Password form: core prints the submit button bare against the field. */
.post-password-form input[type="submit"] {
	margin-block-start: var(--kivora-spacing-sm);
}

/* 2. Post navigation (06-single-post-system.md §2) */
.post-navigation {
	margin-block: var(--kivora-spacing-xl);
	padding-block: var(--kivora-spacing-md);
	border-block: var(--kivora-border-width) solid color-mix(in srgb, var(--kivora-color-border-muted) 30%, transparent);
}

.post-navigation .nav-links {
	display: grid;
	gap: var(--kivora-spacing-md);
}

/* Grid items refuse to shrink past their longest word: one 85-character
 * post title would otherwise shove the other column off the layout. */
.post-navigation .nav-links > * {
	min-width: 0;
}

@media (min-width: 600px) {
	.post-navigation .nav-links {
		grid-template-columns: 1fr 1fr;
	}

	.post-navigation .nav-next {
		text-align: end;
	}
}

.kivora-post-nav__label {
	display: block;
	font-size: var(--kivora-font-size-small);
	color: var(--kivora-color-border-muted);
}

.kivora-post-nav__title {
	font-weight: 600;
	overflow-wrap: break-word;
}

.post-navigation a {
	color: var(--kivora-color-foreground);
	text-decoration: none;
}

.post-navigation a:hover,
.post-navigation a:focus-visible {
	color: var(--kivora-color-primary);
}

/* 3. Pagination */
.pagination .nav-links {
	display: flex;
	flex-wrap: wrap;
	gap: var(--kivora-spacing-xs);
	align-items: center;
	justify-content: center;
	margin-block: var(--kivora-spacing-lg);
}

.pagination .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 2.5rem;
	min-height: 2.5rem;
	padding-inline: var(--kivora-spacing-xs);
	border: var(--kivora-border-width) solid color-mix(in srgb, var(--kivora-color-border-muted) 40%, transparent);
	border-radius: var(--kivora-radius-sm);
	color: var(--kivora-color-foreground);
	text-decoration: none;
}

.pagination .page-numbers:hover,
.pagination .page-numbers:focus-visible {
	border-color: var(--kivora-color-primary);
	color: var(--kivora-color-primary);
}

.pagination .page-numbers.current {
	background: var(--kivora-color-primary);
	border-color: var(--kivora-color-primary);
	color: var(--kivora-color-background);
}

.pagination .page-numbers.dots {
	border-color: transparent;
}

/* 4. Comments */
.kivora-comments {
	margin-block-start: var(--kivora-spacing-xl);
}

.kivora-comments__title {
	font-size: var(--kivora-font-size-h4);
	margin-block-end: var(--kivora-spacing-md);
}

.kivora-comments__list {
	margin: 0 0 var(--kivora-spacing-lg);
	padding: 0;
	list-style: none;
}

.kivora-comments__list ol {
	list-style: none;
	padding-inline-start: var(--kivora-spacing-md);
}

.kivora-comments__list .comment-body {
	padding-block: var(--kivora-spacing-md);
	border-block-start: var(--kivora-border-width) solid color-mix(in srgb, var(--kivora-color-border-muted) 30%, transparent);
}

.kivora-comments__list .comment-meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--kivora-spacing-xs);
	font-size: var(--kivora-font-size-small);
	color: var(--kivora-color-border-muted);
	margin-block-end: var(--kivora-spacing-xs);
}

.kivora-comments__list .avatar {
	border-radius: var(--kivora-radius-pill);
}

.comment-respond .comment-form {
	display: flex;
	flex-direction: column;
	gap: var(--kivora-spacing-sm);
}

/*
 * 5. Form controls shared by the comment form, search form, and widgets.
 *
 * Wrapped in :where() so these rules carry zero specificity: they style bare
 * core markup, but any form plugin's own CSS (Contact Form 7, WPForms, and
 * friends) overrides them without needing a compatibility shim or !important
 * (12-plugin-compatibility.md §5, §10 "broad, unscoped compatibility hacks").
 */
/*
 * The border is the whole visual boundary of a field: at 50% of the muted
 * colour it measured 1.98:1 to 2.49:1 against the eight palette backgrounds,
 * under WCAG 1.4.11's 3:1 for controls. border-muted itself is the token
 * built for 4.5:1 on the same backgrounds, so use it whole.
 */
:where(
	input[type="text"],
	input[type="email"],
	input[type="url"],
	input[type="search"],
	input[type="number"],
	input[type="tel"],
	input[type="password"],
	textarea,
	select
) {
	width: 100%;
	padding: var(--kivora-spacing-xs) var(--kivora-spacing-sm);
	font: inherit;
	color: var(--kivora-color-foreground);
	background: var(--kivora-color-background);
	border: var(--kivora-border-width) solid var(--kivora-color-border-muted);
	border-radius: var(--kivora-radius-sm);
}

/*
 * Except inside the search block: it lays field and button side by side
 * with flex, and a full-width field shoves the button onto its own row.
 */
.wp-block-search__inside-wrapper input[type="search"] {
	width: auto;
	flex: 1 1 auto;
	min-width: 0;
}

/*
 * Fields use the global two-tone focus ring like everything else: the light
 * inner ring reads against the field, the dark outer ring against the page.
 */

.kivora-entry--none .search-form,
.widget .search-form,
.kivora-search-modal .search-form {
	display: flex;
	gap: var(--kivora-spacing-xs);
	align-items: flex-end;
}

:where(.search-form .search-submit, input[type="submit"], button[type="submit"]) {
	padding: var(--kivora-spacing-xs) var(--kivora-spacing-md);
	font: inherit;
	font-weight: 600;
	color: var(--kivora-color-background);
	background: var(--kivora-color-primary);

	/* Transparent, not none: forced-colors mode draws it as the button edge. */
	border: 1px solid transparent;
	border-radius: var(--kivora-radius-sm);
	cursor: pointer;
	transition: background var(--kivora-transition-base);
}

:where(.search-form .search-submit, input[type="submit"], button[type="submit"]):hover {
	background: var(--kivora-color-foreground);
}

/* 6. Not-found / empty states */
.kivora-entry--none {
	padding-block: var(--kivora-spacing-xl);
}

/*
 * Placeholder text: browsers default to a faded foreground (Firefox at 54%
 * opacity), which fell under 4.5:1 in seven of the eight palettes. The
 * muted colour is the token built to clear 4.5:1 on every background.
 */
::placeholder {
	color: var(--kivora-color-border-muted);
	opacity: 1;
}

/*
 * Windows High Contrast replaces author colours, which flattened the current
 * page number and the tag chips into their neighbours: give them system
 * colours and an edge that survive the override.
 */
@media (forced-colors: active) {
	.pagination .page-numbers.current,
	.kivora-entry__pagination > .current {
		background: Highlight;
		border-color: Highlight;
		color: HighlightText;
		forced-color-adjust: none;
	}

	.kivora-entry__tags a {
		border: 1px solid LinkText;
	}
}
