/*
 * Spotlight block (blocks/spotlight/spotlight.php + js/spotlight.js).
 * Markup: per item an <h3><button> then its panel. Phones: an accordion (rows in the item's
 * colour, panel opens below). From 992px, once JS has run (.is-enhanced): coloured tabs in a
 * column on the left, the open panel on the right. Without JS every panel shows, stacked.
 * Plain CSS, no build step.
 */

.spotlight {
	--spotlight-yellow: var(--wp--preset--color--yellow, #ffcf21);
	--spotlight-text: #212529;
	margin: 3rem 0 4rem; /* on top of the page's spacer blocks */
	color: var(--spotlight-text);
}

.spotlight__heading {
	margin: 0 0 2rem;
	font-family: "GillSansNova-Medium", sans-serif;
	font-weight: normal; /* Medium is its own family; the h2 weight would be synthesised */
	font-size: var(--wp--preset--font-size--x-large, 2.5rem);
	text-wrap: balance;
}

/* ---- Item colours (as the old home page boxes) ---- */

.spotlight__item,
.spotlight__panel {
	--spotlight-colour: var(--wp--preset--color--purple, #322173);
	--spotlight-on-colour: #fff;
}

.spotlight__item--light-purple,
.spotlight__panel--light-purple {
	--spotlight-colour: var(--wp--preset--color--light-purple, #7874b5);
}

.spotlight__item--green,
.spotlight__panel--green {
	--spotlight-colour: var(--wp--preset--color--green, #859919);
}

.spotlight__item--maroon,
.spotlight__panel--maroon {
	--spotlight-colour: var(--wp--preset--color--maroon, #8d2862);
}

.spotlight__item--dark-grey,
.spotlight__panel--dark-grey {
	--spotlight-colour: var(--wp--preset--color--dark-grey, #374044);
}

/* ---- Tab / accordion button ---- */

.spotlight__item {
	margin: 0;
	font-size: inherit;
}

.spotlight__tab {
	position: relative;
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: center;
	gap: 0.5rem 1rem;
	width: 100%;
	padding: 1.25rem 1.5rem;
	border: 0;
	border-left: 10px solid var(--spotlight-colour);
	/* Closed: a very light tint of the item's colour, main text colour. */
	background: color-mix(in srgb, var(--spotlight-colour) 10%, #fff);
	color: var(--spotlight-text);
	text-align: left;
	cursor: pointer;
	transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

/* Open: the full colour with white text. */
.spotlight__tab[aria-expanded="true"] {
	background: var(--spotlight-colour);
	color: var(--spotlight-on-colour);
}

/* No focus ring after a mouse click (Bootstrap's button:focus ring); keyboard focus keeps one. */
.spotlight__tab:focus {
	outline: none;
}

.spotlight__tab:focus-visible {
	outline: 3px solid var(--spotlight-text);
	outline-offset: 3px;
}

/* Small outline pill, as on the old boxes. */
.spotlight__label {
	grid-column: 1;
	justify-self: start;
	padding: 0.3rem 0.75rem;
	border: 1px solid currentColor;
	border-radius: 30px;
	font-family: "GillSansNova-SemiBold", sans-serif;
	font-size: 0.75rem;
	letter-spacing: 0.05em;
	line-height: 1.2;
	text-transform: uppercase;
}

.spotlight__title {
	grid-column: 1;
	font-family: "GillSansNova-SemiBold", sans-serif;
	font-size: var(--wp--preset--font-size--large, 1.375rem);
	line-height: 1.25;
	text-wrap: balance;
}

/* Chevron in a circle (as the back links): white on the item's colour when closed, dark on
   white when open (and yellow on desktop, below); rotates when the accordion row is open. */
.spotlight__chevron {
	grid-column: 2;
	grid-row: 1 / span 2;
	width: 2rem;
	height: 2rem;
	border-radius: 50%;
	background: var(--spotlight-colour) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9 L12 15 L18 9' fill='none' stroke='%23ffffff' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / 1.1rem;
	transition: transform 0.2s ease;
}

.spotlight__tab[aria-expanded="true"] .spotlight__chevron {
	background-color: #fff;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9 L12 15 L18 9' fill='none' stroke='%23212529' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	transform: rotate(180deg);
}

/* ---- Panel ---- */

.spotlight__panel {
	padding: 1.5rem;
	background: var(--wp--preset--color--off-white, #f5f5f5);
}

.spotlight__panel[hidden] {
	display: none;
}

.spotlight__item + .spotlight__panel,
.spotlight__panel + .spotlight__item {
	margin-top: 0;
}

.spotlight__panel + .spotlight__item,
.spotlight__item + .spotlight__item {
	margin-top: 0.5rem;
}

.spotlight__media img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 16 / 9; /* as the work program images */
	object-fit: cover;
	border-radius: 0 30px; /* top right + bottom left, as the work program images */
}

.spotlight__body {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 1.25rem;
	padding-top: 1.25rem;
}

.spotlight__blurb {
	margin: 0;
	font-size: var(--wp--preset--font-size--medium, 1.25rem);
	line-height: 1.5;
}

/* The standard button (core classes, child-theme.min.css), in the item's colour with white text.
   Hover stays the standard black with yellow text. (0,3,0)+ beats the standard (0,2,0) rules. */
.spotlight__panel .spotlight__button .wp-block-button__link {
	background: var(--spotlight-colour);
	color: #fff;
}

.spotlight__panel .spotlight__button .wp-block-button__link:hover,
.spotlight__panel .spotlight__button .wp-block-button__link:focus {
	background: var(--wp--preset--color--black, #000);
	color: var(--spotlight-yellow);
}

/* Phones: smaller text so the blurb reads comfortably and the button stays on one line
   (the longest label, "Resources for local authorities", fits down to ~350px screens). */
@media (max-width: 767.98px) {
	.spotlight__panel {
		padding: 1rem;
	}

	.spotlight__blurb {
		font-size: var(--wp--preset--font-size--x-small, 1rem); /* 16px; "small" is 18px on this site */
	}

	.spotlight__panel .spotlight__button .wp-block-button__link {
		padding: 0.75rem 1.25rem;
		font-size: 0.875rem;
		white-space: nowrap;
	}
}

/* Opening fade. */
.spotlight.is-enhanced .spotlight__panel:not([hidden]) {
	animation: spotlight-in 0.3s ease;
}

@keyframes spotlight-in {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

/* ---- Desktop: tabs left, open panel right ---- */

@media (min-width: 992px) {
	.spotlight.is-enhanced .spotlight__items {
		display: grid;
		grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
		/* One row per tab, then a filler row that takes any extra panel height. */
		grid-template-rows: repeat(var(--spotlight-count), auto) 1fr;
		column-gap: 3rem;
		row-gap: 0.75rem;
	}

	.spotlight.is-enhanced .spotlight__item {
		grid-column: 1;
		grid-row: var(--spotlight-row);
		margin: 0;
	}

	.spotlight.is-enhanced .spotlight__panel {
		grid-column: 2;
		grid-row: 1 / -1;
		margin: 0;
		padding: 0;
		background: none;
	}

	.spotlight.is-enhanced .spotlight__tab {
		min-height: 6.5rem;
		padding: 1.5rem 1.75rem;
		transition: transform 0.2s ease, box-shadow 0.2s ease, width 0.25s ease, background-color 0.2s ease, color 0.2s ease;
	}

	/* Closed tabs are a little narrower; the open one reaches out towards its panel. */
	.spotlight.is-enhanced .spotlight__tab[aria-expanded="false"] {
		width: calc(100% - 1.5rem);
	}

	/* Tabs: chevron points right; hover lifts. */
	.spotlight.is-enhanced .spotlight__chevron {
		transform: rotate(-90deg);
	}

	.spotlight.is-enhanced .spotlight__tab:hover {
		transform: translateY(-1px);
		box-shadow: 0 4px 12px rgba(55, 64, 68, 0.2);
	}

	/* Open tab: a notch pointing at the panel, and the arrow circle turns yellow. */
	.spotlight.is-enhanced .spotlight__tab[aria-expanded="true"] {
		box-shadow: none;
		transform: none;
		cursor: default;
	}

	.spotlight.is-enhanced .spotlight__tab[aria-expanded="true"]::after {
		content: "";
		position: absolute;
		top: 50%;
		right: -0.75rem;
		width: 1.5rem;
		height: 1.5rem;
		background: inherit;
		transform: translateY(-50%) rotate(45deg);
	}

	.spotlight.is-enhanced .spotlight__tab[aria-expanded="true"] .spotlight__chevron {
		background-color: var(--spotlight-yellow);
		background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9 L12 15 L18 9' fill='none' stroke='%23212529' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
		transform: rotate(-90deg) scale(1.3); /* bigger, and still pointing right at the panel */
	}

	.spotlight.is-enhanced .spotlight__body {
		padding-top: 1.5rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.spotlight__tab,
	.spotlight__chevron {
		transition: none;
	}

	.spotlight.is-enhanced .spotlight__panel:not([hidden]) {
		animation: none;
	}
}
