/**
 * Pattern: Card Grid — 3-Column Static + Query Loop  (patterns/card-grid.php + card-grid-query.php)
 *
 * Full-bleed purple section band → centred section heading → 3-column CSS-grid
 * of white bordered event cards (image + date + title + excerpt) → outline CTA
 * button below the grid. Used by BOTH blg/card-grid (static) and
 * blg/card-grid (static only; card-grid-query re-scoped to .blg-spotlight__query 2026-08-21). All visual rules live here; query-specific
 * overrides go in card-grid-query.css if ever needed.
 *
 * Figma source: node 2107:3873 — event card full render.
 *   Card outer (258:2552): 392×582px, border 4px (donor purple), radius 24px,
 *     box-shadow 0 0 10px 6px rgba(0,0,0,0.05), white bg.
 *   Image inner (258:2565): 343×295px within 392px card → 24px side padding,
 *     radius 10px, object-cover, aspect ≈7/6.
 *   Date (258:2560): Inter Bold, 14px, (donor purple), UPPERCASE, letter-spacing 0.25px.
 *     Sits ABOVE the title.
 *   Heading (258:2556): Montserrat Black, 26px, dark ink (--blg-color-contrast),
 *     line-height 34px. NOT purple — title is the link anchor; purple used for date.
 *   Paragraph (258:2563): Inter Regular, 16px, body-ink, line-height 26px.
 *   No button: whole card is clickable via title link + ::after overlay.
 *   Section heading (258:2617): Montserrat Black, 50px, white, centered, capitalize.
 *   Section CTA (258:2605): white outline pill, "view events calendar", 18px.
 *
 * Column gap derivation: cards at x=109, x=526, x=935 (each w=392).
 *   Gap 1: 526−109−392 = 25px. Gap 2: 935−526−392 = 17px → rounding artifact → 24px.
 *   Token: --blg-space-md = 1.5rem (24px). ✓
 *
 * Whole-card click (a11y):
 *   - Title carries the single <a> per card (wp:post-title isLink:true / static <a href>).
 *   - Title ::after { position:absolute; inset:0 } stretches over the whole .kd-card
 *     (which is position:relative).
 *   - Featured image is NOT a separate link (isLink:false on wp:post-featured-image)
 *     to avoid duplicate links to the same URL (screen-reader unfriendly).
 *   - Hover/focus-within: card lifts (translateY -2px + shadow) + title turns purple.
 *
 * Static grid centering fix:
 *   - The static .kd-card-grid group uses layout type:default (not flex) so WP does
 *     NOT inject is-layout-flex / is-content-justification-left classes that fight the
 *     CSS display:grid. The query version (.wp-block-post-template) is already a grid.
 *
 * Responsive plan (no mobile frame; derived from desktop + token spec):
 *   1440px desktop:  3 columns, gap 24px, full-width purple band.
 *   ≤1024px tablet:  2 columns, same gap.
 *   ≤768px mobile:   1 column, cards stack.
 *   375px phone:     1 column as above, reduced card padding.
 *
 * One pattern = one CSS partial (auto-enqueued by inc/enqueue.php glob).
 * All responsive media queries for both card-grid patterns live in this file.
 */

/* ── Section band — full-bleed purple ──────────────────────────────────────── */

.kd-card-grid-section {
	padding-block: var(--blg-space-xl) !important; /* 64px top + bottom */
}

/* Section heading — "Upcoming Events": Montserrat Black, 50px, white, capitalize. */
.kd-card-grid-section .kd-card-grid-section__heading {
	font-size: var(--blg-size-h2-section) !important; /* shared section scale */
	font-family: var(--blg-font-heading);
	font-weight: var(--blg-fw-heading);
	color: var(--blg-color-base) !important;
	text-align: center;
	text-transform: capitalize;
	line-height: 1.15 !important;
	margin: 0 0 var(--blg-space-lg);
	letter-spacing: 0.15px;
}

/* ── Card grid — 3-column CSS grid ─────────────────────────────────────────── */

/* Shared grid wrapper — static .kd-card-grid uses layout type:default so WP
   renders it as a block (no is-layout-flex override). Query Loop post-template
   is already a native grid. Both land on this ruleset. */
.kd-card-grid {
	/* Was accidentally comma-joined into .kd-card's ruleset below (a CSS comment
	   does not terminate a selector list), so this never applied and grid consumers
	   inherited card chrome instead. Split out 2026-08-21 (morning-r1 review find). */
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: var(--blg-space-md);
}

/* .kd-card-grid is is-layout-flow (a type:default group) rendered AS a grid. WP's flow
   rule — :where(.is-layout-flow) > * — adds margin-block-start (= the block-gap, 24px)
   to every NON-first child, offsetting cards 2+ downward on desktop and double-spacing
   the mobile stack. The grid `gap` owns all spacing → zero the flow margins on grid items. */
.kd-card-grid > * {
	margin-block-start: 0;
}

/* ── Card — white bordered container (position:relative for ::after overlay) ── */

/* Figma: 392×582, border 4px solid (donor purple), radius 24px,
   shadow 0 0 10px 6px rgba(0,0,0,0.05), white background. */
.kd-card {
	position: relative; /* anchors the title ::after overlay */
	background-color: var(--blg-color-base);
	border: 4px solid var(--blg-color-primary);
	border-radius: var(--blg-radius-lg); /* 24px */
	box-shadow: 0 0 10px 6px rgba(0, 0, 0, 0.05);
	overflow: hidden; /* clip image corners at the top of the card */
	display: flex !important;
	flex-direction: column !important;
	gap: 0 !important;
	height: 100%; /* stretch to match tallest sibling in the grid row */
	transition:
		transform 0.18s ease,
		box-shadow 0.18s ease;
}

/* Hover / focus-within lift — signals the whole card is clickable */
.kd-card:hover,
.kd-card:focus-within {
	transform: translateY(-2px);
	box-shadow: 0 4px 18px 6px rgba(0, 0, 0, 0.1);
}

/* ── Card image — top of card, 24px inset all around ───────────────────────── */

.kd-card .kd-card__image,
.kd-card .wp-block-post-featured-image {
	margin: 1.5rem 1.5rem 0; /* 24px top + sides */
	border-radius: 10px;
	overflow: hidden;
	flex-shrink: 0;
}

.kd-card .kd-card__image figure,
.kd-card .wp-block-post-featured-image > img {
	display: block;
	width: 100%;
}

.kd-card .kd-card__image img,
.kd-card .wp-block-post-featured-image img {
	width: 100%;
	aspect-ratio: 7 / 6;
	object-fit: cover;
	display: block;
	border-radius: 10px;
}

/* ── Card body — content area below the image ──────────────────────────────── */

.kd-card .kd-card__body {
	padding: 1.25rem 1.5rem 1.5rem; /* ~19px top, 24px sides, 24px bottom */
	display: flex !important;
	flex-direction: column !important;
	gap: 0 !important;
	flex: 1 1 auto;
}

/* ── Date — Inter Bold 14px, purple, UPPERCASE (Figma 258:2560) ─────────────── */

/* Sits above the title. wp:post-date / static paragraph both get .kd-card__date.
   The block attribute textColor:"primary" adds has-primary-color via WP; we
   assert here to guarantee it and add the typography treatment. */
.kd-card .kd-card__date,
.kd-card .wp-block-post-date {
	font-family: var(--blg-font-body); /* Inter */
	font-size: 0.875rem !important; /* 14px */
	font-weight: 700 !important;
	font-style: normal;
	line-height: 1.4;
	color: var(--blg-color-primary) !important; /* purple */
	text-transform: uppercase;
	letter-spacing: 0.25px;
	margin: 0 0 0.375rem; /* ~6px gap to title */
	text-decoration: none;
}

/* wp:post-date uses isLink:false → renders a plain <time>, NOT a link, so it is
   not a second keyboard tab stop. The card's ONLY interactive element is the title. */

/* ── Card heading — h3, Montserrat Black, 26px, DARK INK (not purple) ───────── */

/* Figma 258:2556: dark ink, not purple. Purple is reserved for the date above.
   isLink:true on wp:post-title renders as <h3><a>; the <a> is the card's single
   interactive anchor. ::after stretches it over the whole .kd-card. */
.kd-card .kd-card__heading,
.kd-card .wp-block-post-title {
	font-family: var(--blg-font-heading) !important;
	font-weight: var(--blg-fw-heading) !important;
	font-size: 1.625rem !important; /* 26px */
	line-height: 1.31 !important; /* 34/26 */
	letter-spacing: 0.25px;
	color: var(
		--blg-color-contrast
	) !important; /* dark ink — NOT primary/purple */
	margin: 0 0 var(--blg-gap-tight); /* 8px gap to excerpt */
	text-decoration: none;
}

/* Query Loop cards (News / Search): the title link is the card's single interactive
   element. ::after overlays the full card → whole-card click with one accessible name
   (the title text). Event shortcode cards do NOT use this — their heading is plain text
   and the "Event Details" button is the single link (see .kd-card__btn below). */
.kd-card .wp-block-post-title a {
	color: inherit;
	text-decoration: none;
}

.kd-card .wp-block-post-title a::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: var(--blg-radius-lg); /* match card corners */
	z-index: 1; /* Query Loop cards only: covers the whole card → click anywhere
		navigates (whole-card-click BY DESIGN; those cards carry no button). Event
		cards skip this — the "Event Details" button is their single link. */
}

/* Focus ring on the ::after pseudo-element (keyboard nav) */
.kd-card .wp-block-post-title a:focus-visible::after {
	outline: 3px solid var(--blg-color-primary);
	outline-offset: -3px;
}

/* Hover / focus-within: title turns purple to signal interactivity */
.kd-card:hover .kd-card__heading,
.kd-card:hover .wp-block-post-title,
.kd-card:focus-within .kd-card__heading,
.kd-card:focus-within .wp-block-post-title {
	color: var(--blg-color-primary) !important;
}

/* ── Card excerpt / paragraph ───────────────────────────────────────────────── */

/* Figma 258:2563: Inter Regular, 16px, body-ink (#343434), line-height 26px. */
.kd-card .kd-card__excerpt,
.kd-card .wp-block-post-excerpt {
	font-family: var(--blg-font-body);
	font-size: var(--blg-size-body); /* 1rem / 16px */
	font-weight: 400;
	line-height: 1.625; /* 26/16 */
	color: var(--blg-color-body);
	margin: 0;
	flex: 1 1 auto; /* expand to fill remaining body height */
}

.kd-card .wp-block-post-excerpt .wp-block-post-excerpt__excerpt {
	margin: 0;
}

.kd-card .wp-block-post-excerpt__more-link {
	display: none;
}

/* ── Section footer CTA ─────────────────────────────────────────────────────── */

/* Figma 258:2605: white outline pill, "view events calendar", 18px, Montserrat Black. */
.kd-card-grid-section__footer-btn {
	margin-top: var(--blg-space-lg) !important; /* 40px gap grid → button */
}

/* Focus ring on purple band: override purple focus → white so it's visible */
.kd-card-grid-section :focus-visible {
	outline-color: var(--blg-color-base);
}

/* ── Tablet (≤1024px) — 2-column grid ──────────────────────────────────────── */

@media (max-width: 1024px) {
	.kd-card-grid,
	.kd-card-grid-section .kd-card-grid-section__heading {
		font-size: clamp(1.75rem, 3vw, 2.5rem) !important;
	}
}

/* ── Mobile (<768px) — 1-column grid ───────────────────────────────────────────
   Boundary is 767.98px (not 768px) so that 768 itself — iPad portrait, the lower
   edge of the mobile-spec "tablet 768–1199" band — stays 2-column. At exactly 768px
   the old `max-width:768px` won the cascade and dropped to a single centred card with
   ~180px empty margins each side. Matches the .98 boundary convention adopted in the
   section-rhythm refactor (honor the chips exactly). */

@media (max-width: 767.98px) {
	.kd-card-grid,
	.kd-card .kd-card__body {
		padding: 1rem 1.25rem 1.25rem;
	}

	.kd-card .kd-card__image,
	.kd-card .wp-block-post-featured-image {
		margin: 1.25rem 1.25rem 0;
	}

	.kd-card-grid-section .kd-card-grid-section__heading {
		font-size: clamp(1.5rem, 6vw, 2rem) !important;
	}
}

/* ── Small phone (≤375px) ───────────────────────────────────────────────────── */

@media (max-width: 375px) {
	.kd-card .kd-card__image,
	.kd-card .wp-block-post-featured-image {
		margin: 1rem 1rem 0;
	}

	.kd-card .kd-card__body {
		padding: 0.875rem 1rem 1rem;
	}
}

/* ── Event Details button (events grid cards) ──────────────────────────────── */

/* The card's single link. Filled purple pill (Figma 223:2158 — Montserrat Black,
   uppercase). Colour comes from the markup (.has-primary-background-color +
   .has-base-color); this owns the pill shape, type, and bottom alignment.
   align-self:flex-start so the pill hugs its label instead of stretching. */
.kd-card__btn {
	align-self: flex-start;
	margin-top: var(--blg-space-md) !important; /* 24px excerpt → button */
}

.kd-card__btn .wp-block-button__link {
	font-family: var(--blg-font-heading);
	font-weight: var(--blg-fw-heading);
	font-size: 0.9375rem; /* 15px */
	line-height: 1.6;
	text-transform: uppercase;
	letter-spacing: 0.2px;
	border-radius: 200px; /* full pill */
	padding: 0.5rem 1.5rem;
}

/* ── Configurable columns (events grid: columns="1|2|3|4") ─────────────────── */

/* The shortcode adds .kd-card-grid--cols-N. These desktop rules win over the base
   3-col rule via later source order; the media queries below (also later) step
   --cols-3/4 down at tablet/mobile (--cols-1/2 are already ≤2-col). The unmodified
   base grid (Query Loop: News / Search) keeps its own 3→2→1 ladder defined above. */
.kd-card-grid--cols-1 {
	grid-template-columns: minmax(0, var(--blg-card-w)) !important;
}
.kd-card-grid--cols-2 {
	grid-template-columns: repeat(2, minmax(0, var(--blg-card-w))) !important;
}
.kd-card-grid--cols-3 {
	grid-template-columns: repeat(3, minmax(0, var(--blg-card-w))) !important;
}
.kd-card-grid--cols-4 {
	grid-template-columns: repeat(4, minmax(0, var(--blg-card-w))) !important;
}

@media (max-width: 1024px) {
	.kd-card-grid--cols-3,
	.kd-card-grid--cols-4 {
		grid-template-columns: repeat(
			2,
			minmax(0, var(--blg-card-w))
		) !important;
	}
}

@media (max-width: 767.98px) {
	.kd-card-grid--cols-2,
	.kd-card-grid--cols-3,
	.kd-card-grid--cols-4 {
		grid-template-columns: minmax(0, var(--blg-card-w)) !important;
	}
}
