/**
 * Upcoming events block.
 *
 * Figma: PAC-Page-Designs, page "Home Page", "Events"
 *   1440px  node 2001:1725   section 1440 x 428,  cards 313 x 84
 *   1199px  node 2001:1883   section 1199 x 488,  cards 252.75 x 104
 *    768px  node 2001:2041   section  768 x 528,  cards 334 x 84, stacked
 *    390px  node 2001:2148   section  390 x 905,  cards 350 x 84, one column
 *
 * The card is 20px taller at 1199 than anywhere else. Nothing about the card
 * changes: the column is simply narrow enough there that a title of this
 * length takes a third line.
 */

.pchs-events {
	/* Set here so the background rule below is valid even when no drawing
	   has been chosen. render.php replaces it with a url(). */
	--pchs-events-pattern: none;

	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--20); /* 20px */
	/* Plus the gutter, so that past 1440 the contents line up with the rest
	   of the page while the background still fills the screen. */
	padding: var(--pchs-section-py) calc(var(--pchs-section-px) + var(--pchs-page-gutter));

	/*
	 * Two layers, drawing over gradient. The first one listed sits on top.
	 *
	 * The drawing is a PNG with a transparent background, so the gradient
	 * shows through it - which is why it is a background layer rather than
	 * an <img>, and why no opacity is needed.
	 *
	 * cover, centred. Whichever way the drawing overflows - sideways on a
	 * phone, top and bottom on a wide screen - it is trimmed evenly, which
	 * keeps the leaves roughly where they are drawn at every width.
	 *
	 * Figma's own note on this layer says "contain, right top". That is
	 * wrong on both counts and was worth measuring rather than trusting:
	 * contain leaves bare gradient across the bottom of all four frames, and
	 * anchoring right costs 3 to 5 points at every width below 1440. These
	 * two values were picked by scoring every combination against the
	 * frames - see try-background.mjs in the fidelity harness.
	 */
	background-color: var(--wp--preset--color--yellow-100);
	background-image:
		var(--pchs-events-pattern),
		linear-gradient(
			90.44deg,
			var(--wp--preset--color--yellow-100) 0%,
			var(--wp--preset--color--yellow-500) 100%
		);
	background-repeat: no-repeat, no-repeat;
	background-position: center, 0 0;
	background-size: cover, auto;
}

/* The 20px below is on top of the section's own 20px gap, making 40px
   between the heading and the cards - which is what the 768 and 390 frames
   measure. Above that the two sit side by side and it does not apply. */
.pchs-events__intro {
	padding-bottom: var(--wp--preset--spacing--20); /* 20px */
}

.pchs-events__heading {
	color: var(--wp--preset--color--blue-500);
}

.pchs-events__list {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--24); /* 24px */
}


/* ------------------------------------------------------------
   The list of events

   One column on a phone with 20px between cards; two columns
   from 768 with only 8px between the rows, which is what the
   frames measure.
   ------------------------------------------------------------ */

.pchs-events__items {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--wp--preset--spacing--20); /* 20px */
	margin: 0;
	padding: 0;
	list-style: none;
}


/* ------------------------------------------------------------
   One event
   Figma I2001:1725;6086:378 - 12px of padding, 8px between the
   date and the words, 4px between the two lines of words.
   ------------------------------------------------------------ */

.pchs-event {
	/* Anchors the link's stretched hit area, below. */
	position: relative;
	display: flex;
	height: 100%;
	align-items: flex-start;
	gap: var(--wp--preset--spacing--8); /* 8px */
	padding: var(--wp--preset--spacing--12); /* 12px */
	border-radius: var(--wp--custom--radius--sm); /* 16px */
	background-color: var(--wp--preset--color--white);
	box-shadow: var(--wp--preset--shadow--md); /* 0 8px 12px rgba(0,0,0,0.15) */
}

/* A fixed 40px column, so the dates line up down the list however
   wide or narrow the month happens to be. */
.pchs-event__date {
	display: flex;
	width: 40px;
	flex: 0 0 40px;
	flex-direction: column;
	align-items: center;
	color: var(--wp--preset--color--blue-500);
	font-family: var(--wp--preset--font-family--title);
	font-weight: 600;
	text-align: center;
	text-transform: uppercase;
	/* A plain pixel value rather than one of the theme's tracking tokens,
	   which are proportional. The designs apply the same 0.96px to both
	   lines although they are different sizes, so it cannot be expressed
	   as an em without changing one of them. */
	letter-spacing: 0.96px;
}

.pchs-event__month {
	font-size: var(--wp--preset--font-size--xs); /* 12px */
	line-height: 12px;
}

.pchs-event__day {
	font-size: var(--wp--preset--font-size--xl); /* 24px */
	line-height: 24px;
}

.pchs-event__info {
	display: flex;
	min-width: 0;
	flex: 1 1 0;
	flex-direction: column;
	gap: var(--wp--preset--spacing--4); /* 4px */
	color: var(--wp--preset--color--neutral-800);
}

/* Line heights are whole pixels rather than the ratios Figma reports (1.24
   and 1.32), because Figma lays text out on whole pixels and the leftover
   fraction would leave every card slightly taller than its frame. */
.pchs-event__title {
	margin: 0;
	font-family: var(--wp--preset--font-family--navigation);
	font-size: var(--wp--preset--font-size--md); /* 16px */
	font-weight: 500;
	line-height: 20px; /* 16 x 1.24 */
}

/* Stretched across the whole card, so the card is clickable anywhere while a
   screen reader still announces one link named by the event. */
.pchs-event__link::after {
	position: absolute;
	content: "";
	inset: 0;
}

.pchs-event__time {
	margin: 0;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--xs); /* 12px */
	font-weight: 400;
	line-height: 16px; /* 12 x 1.32 */
}

/* Nothing in the designs covers an empty calendar - see render.php. Shaped
   like a card so the section still looks deliberate. */
.pchs-events__empty {
	margin: 0;
	padding: var(--wp--preset--spacing--20);
	border-radius: var(--wp--custom--radius--sm);
	background-color: var(--wp--preset--color--white);
	box-shadow: var(--wp--preset--shadow--md);
	color: var(--wp--preset--color--neutral-800);
	font-family: var(--wp--preset--font-family--navigation);
	font-size: var(--wp--preset--font-size--md);
	font-weight: 500;
	line-height: 20px;
	text-align: center;
}

.pchs-events__actions {
	margin: 0;
}


/* ------------------------------------------------------------
   768px and up
   Figma node 2001:2041.

   Two columns of cards. The heading still sits above them.
   ------------------------------------------------------------ */

@media (min-width: 768px) {

	.pchs-events__items {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		column-gap: var(--wp--preset--spacing--20); /* 20px */
		row-gap: var(--wp--preset--spacing--8); /* 8px */
		/* Each row is as tall as it needs to be rather than all of them
		   matching the tallest, which is what the frames show. */
		align-items: start;
	}

	/*
	 * The button is drawn on the phone frame only.
	 *
	 * Every wider frame has the same button in it and switched off, so this
	 * is what the design asks for rather than something left out. It is odd
	 * enough to be worth a second look: if the button should appear at every
	 * width, delete this rule and nothing else changes.
	 */
	.pchs-events__actions {
		display: none;
	}
}


/* ------------------------------------------------------------
   1024px and up
   Figma nodes 2001:1883 (1199) and 2001:1725 (1440).

   The heading moves beside the events, each taking half the
   width.
   ------------------------------------------------------------ */

@media (min-width: 1024px) {

	.pchs-events {
		flex-direction: row;
		align-items: flex-start;
	}

	.pchs-events__intro,
	.pchs-events__list {
		min-width: 0;
		flex: 1 1 0;
	}

	.pchs-events__intro {
		/* Side by side now, so the extra space below the heading goes. */
		padding-bottom: 0;
	}

	/*
	 * The 40px gap between the heading and the events is padding on the
	 * HEADING, not on the column around it.
	 *
	 * On the column it would not work: a flex item with flex-basis 0 has its
	 * padding added on top of that basis, not counted inside it, so 40px of
	 * padding makes the heading column 40px wider than its neighbour however
	 * equally the free space is shared. That gave columns of 666 and 626
	 * where the design has two of 646, and every event card came out 10px
	 * narrow as a result.
	 */
	.pchs-events__heading {
		padding-right: var(--wp--preset--spacing--40); /* 40px */
	}
}
