/*
 * Docs layout — three-column grid, responsive collapse, code blocks,
 * field-reference table. Enqueued only on docs CPT singles.
 *
 * Column widths are CSS custom properties from theme.json:
 *   --wp--custom--layout--docs-nav  260px
 *   --wp--custom--layout--docs-body 760px
 *   --wp--custom--layout--docs-toc  240px
 *   --wp--custom--layout--docs-grid 1360px
 *
 * @package Plinth
 */

/* ── Three-column grid ───────────────────────────────────────────────────── */

.plinth-docs {
	max-width: var(--wp--custom--layout--docs-grid);
	margin: 0 auto;
	display: grid;
	grid-template-columns:
		var(--wp--custom--layout--docs-nav)
		minmax(0, var(--wp--custom--layout--docs-body))
		var(--wp--custom--layout--docs-toc);
	gap: 0 var(--wp--preset--spacing--32);
	align-items: start;
	padding: var(--wp--preset--spacing--48) var(--wp--preset--spacing--40) var(--wp--preset--spacing--96);
}

/* ── Left nav ────────────────────────────────────────────────────────────── */

.plinth-docs-nav {
	position: sticky;
	top: 72px;
	max-height: calc(100dvh - 72px);
	overflow-y: auto;
	padding: var(--wp--preset--spacing--32) var(--wp--preset--spacing--24) var(--wp--preset--spacing--32) 0;
	border-right: 1px solid var(--wp--preset--color--border);
	min-width: 0;
	scrollbar-width: thin;
}

.plinth-docs-nav-summary { display: none; }

.plinth-docs-nav-section-heading {
	font-size: var(--wp--preset--font-size--caption);
	line-height: 18px;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--wp--preset--color--text-muted);
	margin: var(--wp--preset--spacing--24) 0 var(--wp--preset--spacing--8);
	padding: 0;
	overflow-wrap: anywhere;
}

.plinth-docs-nav-section-heading:first-child { margin-top: 0; }

.plinth-docs-nav-link {
	display: flex;
	align-items: center;
	min-height: 40px;
	padding: 2px 10px;
	border-radius: var(--wp--custom--radius--base);
	font-size: var(--wp--preset--font-size--small);
	line-height: 20px;
	color: var(--wp--preset--color--text-secondary);
	text-decoration: none;
	overflow-wrap: anywhere;
	word-break: break-word;
	transition: var(--wp--custom--transition);
}

.plinth-docs-nav-link:hover {
	background: var(--wp--preset--color--surface);
	color: var(--wp--preset--color--text);
}

.plinth-docs-nav-link[aria-current="page"] {
	color: var(--wp--preset--color--rust-600);
	border-left: 2px solid var(--wp--preset--color--rust-600);
	padding-left: 8px;
	font-weight: 500;
}

/* ── Right ToC ───────────────────────────────────────────────────────────── */

.plinth-docs-toc {
	position: sticky;
	top: 72px;
	max-height: calc(100dvh - 72px);
	overflow-y: auto;
	padding: var(--wp--preset--spacing--32) 0 var(--wp--preset--spacing--32) var(--wp--preset--spacing--24);
	border-left: 1px solid var(--wp--preset--color--border);
	min-width: 0;
	scrollbar-width: thin;
}

.plinth-docs-toc-label {
	font-size: var(--wp--preset--font-size--caption);
	line-height: 18px;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--wp--preset--color--text-muted);
	margin: 0 0 var(--wp--preset--spacing--12);
}

.plinth-docs-toc-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.plinth-docs-toc-item a {
	display: flex;
	align-items: center;
	min-height: 40px;
	font-size: var(--wp--preset--font-size--small);
	line-height: 20px;
	color: var(--wp--preset--color--text-secondary);
	text-decoration: none;
	padding: 2px 0;
	overflow-wrap: anywhere;
	transition: color 150ms ease;
}

.plinth-docs-toc-item a:hover { color: var(--wp--preset--color--text); }
.plinth-docs-toc-item.is-active a { color: var(--wp--preset--color--rust-600); font-weight: 500; }

/* Inline ToC — shown on mobile only (placed inside the article column) */
.plinth-docs-toc-inline { display: none; }

/* ── Article column typography ───────────────────────────────────────────── */

.plinth-docs-article { min-width: 0; padding: var(--wp--preset--spacing--32) 0; }

.plinth-docs-article h1 {
	font-size: var(--wp--preset--font-size--h1);
	line-height: 1.25;
	font-weight: 700;
	letter-spacing: -0.02em;
	margin: 0 0 var(--wp--preset--spacing--8);
	overflow-wrap: anywhere;
}

.plinth-docs-article h2 {
	font-size: var(--wp--preset--font-size--h2);
	line-height: 1.333;
	font-weight: 600;
	letter-spacing: -0.015em;
	margin: var(--wp--preset--spacing--48) 0 var(--wp--preset--spacing--16);
	padding-top: var(--wp--preset--spacing--28);
	border-top: 1px solid var(--wp--preset--color--border);
	overflow-wrap: anywhere;
}

.plinth-docs-article h2:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }

.plinth-docs-article h3 {
	font-size: var(--wp--preset--font-size--h3);
	line-height: 1.4;
	font-weight: 600;
	margin: var(--wp--preset--spacing--32) 0 var(--wp--preset--spacing--12);
	overflow-wrap: anywhere;
}

.plinth-docs-article p {
	font-size: var(--wp--preset--font-size--body);
	line-height: 27px;
	color: var(--wp--preset--color--text-secondary);
	margin: 0 0 var(--wp--preset--spacing--16);
	overflow-wrap: anywhere;
}

.plinth-docs-article section + section { margin-top: var(--wp--preset--spacing--48); }

/* Meta row — last_verified, versions, time_to_fix */
.plinth-docs-meta {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--16) var(--wp--preset--spacing--24);
	margin: var(--wp--preset--spacing--16) 0 var(--wp--preset--spacing--32);
	padding: var(--wp--preset--spacing--16);
	background: var(--wp--preset--color--surface);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--custom--radius--card);
}

.plinth-docs-meta-item {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.plinth-docs-meta-label {
	font-size: var(--wp--preset--font-size--caption);
	line-height: 18px;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--wp--preset--color--text-muted);
}

.plinth-docs-meta-value {
	font-size: var(--wp--preset--font-size--small);
	line-height: 22px;
	color: var(--wp--preset--color--text);
	overflow-wrap: anywhere;
}

/* ── Quick-answer block ──────────────────────────────────────────────────── */

.plinth-quick-answer {
	background: var(--wp--preset--color--surface);
	border-left: 3px solid var(--wp--preset--color--teal-600);
	border-radius: 0 var(--wp--custom--radius--card) var(--wp--custom--radius--card) 0;
	padding: var(--wp--preset--spacing--20) var(--wp--preset--spacing--24);
	margin: 0 0 var(--wp--preset--spacing--32);
}

.plinth-quick-answer p {
	font-size: var(--wp--preset--font-size--body);
	line-height: 26px;
	color: var(--wp--preset--color--text);
	margin: 0;
	overflow-wrap: anywhere;
}

/* ── Code blocks ─────────────────────────────────────────────────────────── */

.plinth-code-wrap {
	overflow-x: auto;
	border-radius: var(--wp--custom--radius--card);
	background: var(--wp--preset--color--navy-900);
	margin: var(--wp--preset--spacing--16) 0;
}

.plinth-code-filename {
	padding: 8px 16px;
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--caption);
	color: rgba(255, 255, 255, 0.5);
	border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.plinth-code-inner {
	display: flex;
	min-width: 0;
}

/* Contrast: the gutter was #505b68 on #152436 — 2.27:1, well under the 4.5:1
   WCAG AA threshold for body text. Line numbers are quiet, not invisible. */
.plinth-code-gutter {
	padding: 16px 12px;
	background: rgba(255, 255, 255, 0.04);
	border-right: 1px solid rgba(255, 255, 255, 0.08);
	color: #9aa7b4;
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--code);
	line-height: 22px;
	text-align: right;
	user-select: none;
	flex-shrink: 0;
	white-space: pre;
}

.plinth-code-body {
	padding: 16px 20px;
	width: max-content;
	min-width: 100%;
	color: var(--wp--preset--color--navy-100);
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--code);
	line-height: 22px;
	white-space: pre;
	overflow-wrap: normal;
	word-break: normal;
}

/* Copy button */
.plinth-code-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 8px 16px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.plinth-code-copy {
	font-family: inherit;
	font-size: var(--wp--preset--font-size--caption);
	color: rgba(255, 255, 255, 0.5);
	background: transparent;
	border: 1px solid rgba(255, 255, 255, 0.16);
	border-radius: var(--wp--custom--radius--base);
	padding: 3px 10px;
	cursor: pointer;
	transition: var(--wp--custom--transition);
}

.plinth-code-copy:hover { color: #fff; border-color: rgba(255, 255, 255, 0.4); }

/* Error-message blocks — searched verbatim, must never re-wrap */
.plinth-error-msg-string {
	overflow-x: auto;
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--code);
	white-space: pre;
	background: var(--wp--preset--color--navy-900);
	color: var(--wp--preset--color--error-100, #fdeae8);
	padding: 12px 16px;
	border-radius: var(--wp--custom--radius--base);
	display: block;
	width: max-content;
	min-width: 100%;
}

/* ── Field-reference table ───────────────────────────────────────────────── */

.plinth-field-table-wrap {
	overflow-x: auto;
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--custom--radius--card);
	margin: var(--wp--preset--spacing--16) 0;
}

.plinth-field-table {
	width: 100%;
	border-collapse: collapse;
	font-size: var(--wp--preset--font-size--small);
}

.plinth-field-table thead th {
	position: sticky;
	top: 0;
	z-index: var(--wp--custom--z--table-head);
	background: var(--wp--preset--color--surface);
	padding: 10px 14px;
	text-align: left;
	font-size: var(--wp--preset--font-size--caption);
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--wp--preset--color--text-muted);
	white-space: nowrap;
	border-bottom: 1px solid var(--wp--preset--color--border);
}

.plinth-field-table tbody td {
	padding: 10px 14px;
	vertical-align: top;
	border-top: 1px solid var(--wp--preset--color--border);
	overflow-wrap: anywhere;
	min-width: 0;
	color: var(--wp--preset--color--text);
}

.plinth-field-table tbody tr:first-child td { border-top: none; }

.plinth-field-name {
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--code);
	color: var(--wp--preset--color--navy-800);
	white-space: nowrap;
}

.plinth-rw-badge {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-size: var(--wp--preset--font-size--caption);
	font-weight: 600;
	padding: 2px 8px;
	border-radius: var(--wp--custom--radius--base);
}

.plinth-rw-badge--read  { background: var(--wp--preset--color--teal-100);    color: var(--wp--preset--color--teal-700); }
.plinth-rw-badge--write { background: var(--wp--preset--color--navy-100);    color: var(--wp--preset--color--navy-700); }
.plinth-rw-badge--no    { background: var(--wp--preset--color--surface);     color: var(--wp--preset--color--text-muted); }

/* Mobile field cards (shown at <900px, hidden above) */
.plinth-field-cards { display: none; }

/* ── Endpoint blocks ─────────────────────────────────────────────────────── */

.plinth-endpoint {
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--custom--radius--card);
	margin: var(--wp--preset--spacing--12) 0;
	overflow: hidden;
}

.plinth-endpoint-summary {
	display: flex;
	align-items: center;
	gap: var(--wp--preset--spacing--12);
	min-height: 48px;
	padding: 12px 16px;
	cursor: pointer;
	list-style: none;
	background: var(--wp--preset--color--paper);
}

.plinth-endpoint-summary:hover { background: var(--wp--preset--color--surface); }

.plinth-method-badge {
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--caption);
	font-weight: 700;
	padding: 3px 8px;
	border-radius: var(--wp--custom--radius--base);
	flex-shrink: 0;
	min-width: 52px;
	text-align: center;
}

.plinth-method-badge--get    { background: var(--wp--preset--color--teal-100);    color: var(--wp--preset--color--teal-700); }
.plinth-method-badge--post   { background: var(--wp--preset--color--navy-100);    color: var(--wp--preset--color--navy-700); }
.plinth-method-badge--put    { background: var(--wp--preset--color--warning-100); color: var(--wp--preset--color--warning-600); }
.plinth-method-badge--patch  { background: var(--wp--preset--color--warning-100); color: var(--wp--preset--color--warning-600); }
.plinth-method-badge--delete { background: var(--wp--preset--color--error-100);   color: var(--wp--preset--color--error-600); }

.plinth-endpoint-path {
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--text);
	overflow-wrap: anywhere;
	word-break: break-all;
	flex: 1;
}

.plinth-endpoint-body {
	border-top: 1px solid var(--wp--preset--color--border);
	padding: var(--wp--preset--spacing--20);
}

/* ── Applies-to / quick-facts strip ─────────────────────────────────────── */

.plinth-applies-row {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--12) var(--wp--preset--spacing--32);
	padding: var(--wp--preset--spacing--16);
	background: var(--wp--preset--color--surface);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--custom--radius--card);
	margin: var(--wp--preset--spacing--16) 0;
}

.plinth-applies-item { min-width: 0; }

.plinth-applies-label {
	font-size: var(--wp--preset--font-size--caption);
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--wp--preset--color--text-muted);
}

.plinth-applies-value {
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--text);
	margin-top: 2px;
	overflow-wrap: anywhere;
}

/* ── Feedback row ────────────────────────────────────────────────────────── */

.plinth-docs-feedback {
	border-top: 1px solid var(--wp--preset--color--border);
	padding: var(--wp--preset--spacing--32) var(--wp--preset--spacing--40);
	max-width: var(--wp--custom--layout--docs-grid);
	margin: 0 auto;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--wp--preset--spacing--16) var(--wp--preset--spacing--32);
}

.plinth-docs-feedback p {
	font-size: var(--wp--preset--font-size--small);
	font-weight: 500;
	color: var(--wp--preset--color--text-secondary);
	margin: 0;
}

.plinth-feedback-btn {
	font-family: inherit;
	font-size: var(--wp--preset--font-size--small);
	font-weight: 500;
	padding: 8px 16px;
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--custom--radius--base);
	background: transparent;
	color: var(--wp--preset--color--text-secondary);
	cursor: pointer;
	transition: var(--wp--custom--transition);
	min-height: 36px;
}

.plinth-feedback-btn:hover {
	background: var(--wp--preset--color--surface);
	color: var(--wp--preset--color--text);
}

/* ── Responsive — ≤900px ─────────────────────────────────────────────────── */

@media (max-width: 900px) {
	.plinth-docs {
		grid-template-columns: minmax(0, 1fr);
		padding-left:  var(--wp--preset--spacing--20);
		padding-right: var(--wp--preset--spacing--20);
		gap: 0;
	}

	/* Left nav: 48px disclosure */
	.plinth-docs-nav {
		position: static;
		max-height: none;
		padding: 0;
		border-right: none;
		border-bottom: 1px solid var(--wp--preset--color--border);
		overflow: visible;
		order: -1;
	}

	.plinth-docs-nav-disclosure { display: block; }

	.plinth-docs-nav-summary {
		display: flex;
		align-items: center;
		justify-content: space-between;
		min-height: 48px;
		padding: 0 var(--wp--preset--spacing--20);
		font-size: var(--wp--preset--font-size--small);
		font-weight: 500;
		color: var(--wp--preset--color--text-secondary);
		cursor: pointer;
		list-style: none;
	}

	.plinth-docs-nav-disclosure[open] .plinth-docs-nav-summary {
		border-bottom: 1px solid var(--wp--preset--color--border);
	}

	.plinth-docs-nav-tree { padding: var(--wp--preset--spacing--16) var(--wp--preset--spacing--20); }

	/* Right ToC: hidden at column level; inline version visible inside article */
	.plinth-docs-toc { display: none; }
	.plinth-docs-toc-inline {
		display: block;
		border: 1px solid var(--wp--preset--color--border);
		border-radius: var(--wp--custom--radius--card);
		margin: var(--wp--preset--spacing--24) 0;
		overflow: hidden;
	}

	/* Field reference: cards instead of table */
	.plinth-field-table-wrap { display: none; }
	.plinth-field-cards {
		display: flex;
		flex-direction: column;
		gap: var(--wp--preset--spacing--12);
		margin: var(--wp--preset--spacing--16) 0;
	}

	.plinth-field-card {
		border: 1px solid var(--wp--preset--color--border);
		border-radius: var(--wp--custom--radius--card);
		padding: var(--wp--preset--spacing--16);
	}

	.plinth-docs-feedback {
		padding-left:  var(--wp--preset--spacing--20);
		padding-right: var(--wp--preset--spacing--20);
	}

	.plinth-docs-article h2 { margin-top: var(--wp--preset--spacing--32); }
}

/* Active-section highlighting via view.js */
.plinth-docs-toc-item a { position: relative; }

/* ── Block-composed documentation ─────────────────────────────────────────
 * The written documentation and troubleshooting pages are built from the
 * marketing blocks, which are designed to run the full width of the viewport:
 * each section carries its own padding and its own centred, max-width wrapper.
 * Dropped into the 760px middle column that machinery fights the grid — the
 * page gains a second set of gutters and the content sits in a column inside a
 * column. These rules stand that chrome down. The blocks keep their internal
 * rhythm, their tables, their callouts and their code samples; they just stop
 * trying to lay out the page, which the docs grid is already doing.
 * ------------------------------------------------------------------------- */

.plinth-docs-article--blocks .pl-section {
	padding-left: 0;
	padding-right: 0;
}

.plinth-docs-article--blocks .pl-wrap {
	max-width: none;
	width: 100%;
	padding-left: 0;
	padding-right: 0;
}

/* A tint reads as a band across the page. In a column it would be a stripe
   down one side of the text, so it becomes a panel with its own edges. */
.plinth-docs-article--blocks .pl-tint {
	border-radius: var(--wp--custom--radius--card);
	padding: var(--wp--preset--spacing--24) var(--wp--preset--spacing--32);
}

/* The hero on a documentation page is a title and a sentence, not a landing
   page: it should read as the top of an article. */
.plinth-docs-article--blocks .pl-hero-compact,
.plinth-docs-article--blocks .pl-hero-commercial {
	padding-top: 0;
	padding-bottom: var(--wp--preset--spacing--24);
}

/* Grids of cards are fine, but four across a 760px column is four slivers. */
.plinth-docs-article--blocks .pl-grid--3,
.plinth-docs-article--blocks .pl-grid--4 {
	grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
}

/* The h2s are now the contents list, so give them something to be scrolled
   to that is not flush against the sticky header. */
.plinth-docs-article--blocks h2 {
	scroll-margin-top: 88px;
}

/* In the docs column the measure is the column, so a note should fill it
   rather than being held to the marketing container's width. */
.plinth-docs-article--blocks .pl-callout {
	max-width: none;
}
