/*
 * Service pages: the contents panel (VOY-1527, spec KB-554 shared component 1).
 *
 * A glass panel: a title bar, a list of items, and one detail card under the
 * list. First use is the /audit/ hero (the report's eight chapters, each with
 * a sample finding labelled Illustration); next are a case study's chapter
 * list and the SEO readout, which is why nothing here names the audit.
 *
 * Without JavaScript every item reads in order: number, name, then its card.
 * svc-contents.js adds .is-js, builds the tab list and shows one card at a
 * time. The active tab carries a 22px progress line that fills over
 * --cycle-ms; .is-paused holds it and .is-still removes it (reduced motion,
 * the motion pause, a visitor's pick, a phone).
 *
 * Under 768px the tabs become pills ("Ch. 01") over the one card, from the
 * mobile board. Radii stay inside the design system's 6px (pills are 999px).
 */

.vy-svc-page .vy-svc-contents {
	position: relative;
	overflow: hidden;
	border: 1px solid color-mix(in oklab, var(--um-500) 35%, transparent);
	border-radius: 6px;
	background: color-mix(in oklab, var(--bg-panel) 90%, transparent);
	backdrop-filter: blur(14px);
	box-shadow:
		0 40px 100px -30px color-mix(in oklab, var(--um-700) 45%, transparent),
		0 0 60px color-mix(in oklab, var(--um-500) 10%, transparent);
}

/* ---- Title bar ---------------------------------------------------------------- */

.vy-svc-page .vy-svc-contents__bar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 16px;
	padding: 14px 18px;
	border-bottom: 1px solid var(--border-hair);
	background: var(--bg-raised);
	font-family: var(--font-mono);
	font-size: 11px;
	color: var(--fg-3);
}
.vy-svc-page .vy-svc-contents__bar > :last-child { color: var(--fg-4); }

/* ---- Items: the no-JavaScript reading order ------------------------------------- */

.vy-svc-page .vy-svc-contents__item {
	display: grid;
	grid-template-columns: 28px minmax(0, 1fr);
	gap: 8px 10px;
	padding: 14px 18px;
	border-top: 1px solid var(--border-hair);
}
.vy-svc-page .vy-svc-contents__bar + .vy-svc-contents__item { border-top: 0; }
.vy-svc-page .vy-svc-contents__item > .vy-svc-contents__card { grid-column: 1 / -1; }

.vy-svc-page .vy-svc-contents__num {
	font-family: var(--font-mono);
	font-size: 11px;
	line-height: 1.9;
	color: var(--um-500);
}
.vy-svc-page .vy-svc-contents__name {
	font-size: 14px;
	color: var(--fg-1);
}

/* ---- The card ------------------------------------------------------------------- */

.vy-svc-page .vy-svc-contents__card {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	gap: 8px 12px;
	align-items: center;
	padding: 16px;
	border: 1px solid color-mix(in oklab, var(--um-500) 45%, transparent);
	border-radius: 6px;
	background: var(--bg-canvas);
}
.vy-svc-page .vy-svc-contents__kicker {
	font-family: var(--font-mono);
	font-size: 10px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--um-500);
}
.vy-svc-page .vy-svc-contents__tag {
	justify-self: end;
	padding: 2px 6px;
	border: 1px solid var(--border-1);
	border-radius: 4px;
	font-family: var(--font-mono);
	font-size: 9px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--fg-4);
}
.vy-svc-page .vy-svc-contents__text {
	grid-column: 1 / -1;
	font-family: var(--font-display);
	font-size: 18px;
	font-weight: 500;
	line-height: 1.3;
	letter-spacing: -0.01em;
	color: var(--fg-1);
}

/* ---- JavaScript on: a tab list and one card --------------------------------------- */

.vy-svc-page .vy-svc-contents.is-js .vy-svc-contents__item {
	display: block;
	margin: 0 18px 18px;
	padding: 0;
	border: 0;
}
.vy-svc-page .vy-svc-contents.is-js .vy-svc-contents__item[hidden] { display: none; }
.vy-svc-page .vy-svc-contents.is-js .vy-svc-contents__item > :not(.vy-svc-contents__card) { display: none; }

.vy-svc-page .vy-svc-contents__tabs {
	position: relative;
	display: flex;
	flex-direction: column;
	padding: 10px 8px;
}
.vy-svc-page .vy-svc-contents__tabs button {
	display: grid;
	grid-template-columns: 28px minmax(0, 1fr) 22px;
	gap: 10px;
	align-items: center;
	width: 100%;
	padding: 9px 12px;
	border: 0;
	border-radius: 6px;
	background: transparent;
	text-align: left;
	cursor: pointer;
	transition: background-color 260ms var(--svc-ease);
}
.vy-svc-page .vy-svc-contents__tnum {
	font-family: var(--font-mono);
	font-size: 11px;
	color: var(--fg-4);
	transition: color 260ms var(--svc-ease);
}
.vy-svc-page .vy-svc-contents__tname {
	font-family: var(--font-body);
	font-size: 14px;
	color: var(--fg-3);
	transition: color 260ms var(--svc-ease);
}
.vy-svc-page .vy-svc-contents__tabs button:hover .vy-svc-contents__tname { color: var(--fg-1); }
.vy-svc-page .vy-svc-contents__tabs button:focus-visible {
	outline: 2px solid var(--um-500);
	outline-offset: -2px;
}
.vy-svc-page .vy-svc-contents__tabs button[aria-selected="true"] {
	background: color-mix(in oklab, var(--accent) 18%, transparent);
}
/* fg-1, as the phone pills already have it: the practice colour on the selected
   tint read 4.3:1, under AA (VOY-232). The tint and the progress line mark it. */
.vy-svc-page .vy-svc-contents__tabs button[aria-selected="true"] .vy-svc-contents__tnum { color: var(--fg-1); }
.vy-svc-page .vy-svc-contents__tabs button[aria-selected="true"] .vy-svc-contents__tname { color: var(--fg-1); }

/* The active tab's line: the cycle's progress, then the selection mark. */
.vy-svc-page .vy-svc-contents__tabs button[aria-selected="true"]::after {
	content: "";
	width: 22px;
	height: 2px;
	background: var(--um-500);
	transform-origin: left;
	animation: vy-svc-contents-cycle var(--cycle-ms, 2600ms) linear both;
}
.vy-svc-page .vy-svc-contents.is-paused .vy-svc-contents__tabs button::after { animation-play-state: paused; }
.vy-svc-page .vy-svc-contents.is-still .vy-svc-contents__tabs button::after { animation: none; transform: none; }
@keyframes vy-svc-contents-cycle { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.vy-svc-page .vy-svc-contents__card.is-in { animation: vy-svc-contents-in 420ms var(--svc-ease) both; }
@keyframes vy-svc-contents-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: none; }
}

/* ---- Before the script runs --------------------------------------------------------- */

/* VOY-232: on /audit/ the eight items with their cards stood about 1,400px tall
   until svc-contents.js built the tabs, and the hero copy jumped 425px, a layout
   shift of 0.50. With scripting on, the first paint lays the items out as the
   tab list will be (bar, 16px gap, 10px pad, 35px rows, 10px pad) with only the
   first card, under the list, so the panel is the height the script leaves it.
   The rows are replaced by the script's buttons, so only the card and the
   panel's height have to match. Under 768px the tabs are pills; left alone. */
@media (min-width: 768px) and (scripting: enabled) {
	.vy-svc-page .vy-svc-contents:not(.is-js):not(.vy-svc-contents--rail) {
		display: grid;
		grid-template-columns: 20px 28px 10px minmax(0, 1fr) 52px;
		align-content: start;
	}
	.vy-svc-page .vy-svc-contents:not(.is-js):not(.vy-svc-contents--rail) > .vy-svc-contents__bar {
		grid-column: 1 / -1;
		margin: 0 0 26px;
	}
	.vy-svc-page .vy-svc-contents:not(.is-js):not(.vy-svc-contents--rail) > .vy-svc-contents__item { display: contents; }
	.vy-svc-page .vy-svc-contents:not(.is-js):not(.vy-svc-contents--rail) :is(.vy-svc-contents__num, .vy-svc-contents__name) {
		box-sizing: border-box;
		height: 35px;
		margin: 0;
		padding-block: 9px;
		line-height: 17px;
	}
	.vy-svc-page .vy-svc-contents:not(.is-js):not(.vy-svc-contents--rail) .vy-svc-contents__num { grid-column: 2; }
	.vy-svc-page .vy-svc-contents:not(.is-js):not(.vy-svc-contents--rail) .vy-svc-contents__name { grid-column: 4; color: var(--fg-3); }
	.vy-svc-page .vy-svc-contents:not(.is-js):not(.vy-svc-contents--rail) > .vy-svc-contents__item:last-child > :is(.vy-svc-contents__num, .vy-svc-contents__name) { margin-bottom: 10px; }
	.vy-svc-page .vy-svc-contents:not(.is-js):not(.vy-svc-contents--rail) > .vy-svc-contents__item:not(.vy-svc-contents__bar + *) > .vy-svc-contents__card { display: none; }
	.vy-svc-page .vy-svc-contents:not(.is-js):not(.vy-svc-contents--rail) > .vy-svc-contents__bar + .vy-svc-contents__item > .vy-svc-contents__card {
		grid-column: 1 / -1;
		grid-row: 99;
		margin: 0 18px 18px;
	}
}

/* ---- Mobile: chapter pills over one card -------------------------------------------- */

@media (max-width: 767px) {
	.vy-svc-page .vy-svc-contents__bar { padding: 12px 14px; font-size: 10px; }
	.vy-svc-page .vy-svc-contents__text { font-size: 17px; }
	.vy-svc-page .vy-svc-contents.is-js .vy-svc-contents__item { margin: 0 14px 14px; }
	.vy-svc-page .vy-svc-contents__card { padding: 14px; }

	.vy-svc-page .vy-svc-contents__tabs {
		flex-direction: row;
		gap: 6px;
		padding: 12px 14px;
		overflow-x: auto;
		scrollbar-width: none;
	}
	.vy-svc-page .vy-svc-contents__tabs::-webkit-scrollbar { display: none; }
	.vy-svc-page .vy-svc-contents__tabs button {
		display: inline-flex;
		flex: none;
		width: auto;
		min-height: 36px;
		padding: 8px 12px;
		border: 1px solid var(--border-strong);
		border-radius: 999px;
	}
	.vy-svc-page .vy-svc-contents__tabs button[aria-selected="true"] {
		border-color: var(--um-500);
		background: color-mix(in oklab, var(--accent) 16%, transparent);
	}
	.vy-svc-page .vy-svc-contents__tnum { color: var(--fg-3); }
	.vy-svc-page .vy-svc-contents__tnum::before { content: "Ch. "; }
	.vy-svc-page .vy-svc-contents__tabs button[aria-selected="true"] .vy-svc-contents__tnum { color: var(--fg-1); }
	/* The name stays in the button's accessible text; only the pill hides it. */
	.vy-svc-page .vy-svc-contents__tname {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}
	.vy-svc-page .vy-svc-contents__tabs button::after { display: none; }
}

@media (prefers-reduced-motion: reduce) {
	.vy-svc-page .vy-svc-contents__tabs button,
	.vy-svc-page .vy-svc-contents__tnum,
	.vy-svc-page .vy-svc-contents__tname { transition: none; }
	.vy-svc-page .vy-svc-contents__tabs button::after { animation: none; transform: none; }
	.vy-svc-page .vy-svc-contents__card.is-in { animation: none; }
}

/* ==== Rail mode: "On this page" (VOY-1545, the case file) ===========================
 *
 * The same list look as the tabs above, as a sticky page index instead of a
 * card cycler. Markup: a label paragraph, a core/list of in-page links
 * (numbered by a CSS counter, so reordering never renumbers by hand), and an
 * optional "Next step" group. svc-contents.js marks the section in view
 * (.is-current, aria-current) and drops a link whose section is not on the
 * page. Without JavaScript the links still jump.
 *
 * Under 1024px the rail becomes a sticky row of pills under the header, as
 * on the mobile board: names only, the label and the next step hidden.
 */

.vy-svc-page .vy-svc-contents--rail {
	position: sticky;
	top: calc(var(--vy-hdr-h, 72px) + 32px);
	overflow: visible;
	border: 0;
	border-radius: 0;
	background: none;
	backdrop-filter: none;
	box-shadow: none;
}
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__label {
	font-family: var(--font-mono);
	font-size: 10px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--fg-4);
}
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list {
	counter-reset: vy-rail;
	position: relative; /* offsetLeft of a pill is measured from here */
	display: flex;
	flex-direction: column;
	margin: 8px 0 0;
	padding: 0;
	list-style: none;
}
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list li { counter-increment: vy-rail; }
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list li[hidden] { display: none; }
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list a {
	display: grid;
	grid-template-columns: 26px minmax(0, 1fr);
	gap: 8px;
	align-items: baseline;
	padding: 8px 10px;
	border-radius: 6px;
	font-size: 14px;
	line-height: 1.35;
	color: var(--fg-3);
	text-decoration: none;
	transition: background-color 260ms var(--svc-ease), color 260ms var(--svc-ease);
}
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list a::before {
	content: counter(vy-rail, decimal-leading-zero);
	font-family: var(--font-mono);
	font-size: 10.5px;
	color: var(--fg-4);
	transition: color 260ms var(--svc-ease);
}
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list a:hover { color: var(--fg-1); }
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list a:focus-visible {
	outline: 2px solid var(--um-500);
	outline-offset: -2px;
}
.vy-svc-page .vy-svc-contents--rail .is-current a {
	background: color-mix(in oklab, var(--accent) 18%, transparent);
	color: var(--fg-1);
}
.vy-svc-page .vy-svc-contents--rail .is-current a::before { color: var(--um-500); }

.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__next {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin-top: 22px;
	padding-top: 18px;
	border-top: 1px solid var(--border-hair);
}
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__go { font-size: 14px; line-height: 1.4; }
.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__go a { text-decoration: none; }

@media (max-width: 1023px) {
	.vy-svc-page .vy-svc-contents--rail {
		top: var(--vy-hdr-h, 64px);
		z-index: 20;
		margin-inline: calc(-1 * var(--svc-pad));
		padding: 12px var(--svc-pad);
		border-block: 1px solid var(--border-hair);
		background: color-mix(in oklab, var(--bg-canvas) 92%, transparent);
		backdrop-filter: blur(10px);
	}
	.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__label,
	.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__next { display: none; }
	.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list {
		flex-direction: row;
		gap: 8px;
		margin: 0;
		overflow-x: auto;
		scrollbar-width: none;
	}
	.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list::-webkit-scrollbar { display: none; }
	.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list li { flex: none; }
	.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list a {
		display: inline-flex;
		align-items: center;
		min-height: 40px;
		padding: 8px 14px;
		border: 1px solid var(--border-strong);
		border-radius: 999px;
		white-space: nowrap;
	}
	.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list a::before { display: none; }
	.vy-svc-page .vy-svc-contents--rail .is-current a {
		border-color: var(--um-500);
		background: color-mix(in oklab, var(--accent) 16%, transparent);
	}
}

@media (prefers-reduced-motion: no-preference) {
	html:has(.vy-svc-contents--rail) { scroll-behavior: smooth; }
}
@media (prefers-reduced-motion: reduce) {
	.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list a,
	.vy-svc-page .vy-svc-contents--rail .vy-svc-contents__list a::before { transition: none; }
}
