/**
 * Iron TeleSpecialists Elements — Posts Grid
 *
 * Brand tokens are CSS custom properties on the grid root so they are easy to
 * retheme (e.g. swap --ite-accent to the live-site teal). Colors are sourced
 * from the TeleSpecialists theme: navy #00164C, accent #9F1F60.
 *
 * STYLE ISOLATION
 * ---------------
 * WordPress themes/plugins ship broad rules on bare elements (a, button, img,
 * p, h*, ul…), some flagged !important. To keep this component looking the same
 * on any site:
 *   1. Every rule is scoped under `.ite-posts-grid`, so its specificity beats a
 *      theme's single-class/element selectors without needing !important.
 *   2. A reset block (below) neutralizes the inherited/forced properties themes
 *      most commonly inject on the elements we render.
 *   3. !important is used *surgically* — only on the few properties themes are
 *      known to force with it (button paint, link underlines, image framing).
 * Short of Shadow DOM this is the robust way to prevent style bleed.
 */

/* ============================================================ Root + tokens */

.ite-posts-grid {
	--ite-cols: 3;

	--ite-primary: #00164c;
	--ite-accent: #9f1f60;
	--ite-accent-hover: #7f194d; /* darkened magenta for button hover (matches site CTA) */
	--ite-ink: #1a1a2e;
	--ite-muted: #6c6c6c;
	--ite-line: #e6e8ef;
	--ite-surface: #ffffff;
	--ite-bg-soft: #f5f6fa;

	--ite-radius: 14px;
	--ite-btn-radius: 0.5em; /* matches site button border-radius */
	--ite-control-h: 52px;   /* shared height for inputs, select + filter buttons */
	--ite-gap: 28px;
	--ite-shadow: 0 2px 6px rgba(0, 22, 76, 0.06);
	--ite-shadow-hover: 0 8px 20px rgba(0, 22, 76, 0.1);

	font-family: "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 16px;
	line-height: 1.5;
	color: var(--ite-ink);
	box-sizing: border-box;
}

/* ================================================ Isolation reset (scoped) */

.ite-posts-grid,
.ite-posts-grid *,
.ite-posts-grid *::before,
.ite-posts-grid *::after {
	box-sizing: border-box;
}

/* Links: kill theme underline + hover/focus paint that bleed onto the card. */
.ite-posts-grid a,
.ite-posts-grid a:hover,
.ite-posts-grid a:focus {
	text-decoration: none !important;
	box-shadow: none;
	background: none;
	outline: none;
}

/* Form controls: drop inherited skins so our own button/input styles apply on
   a clean slate (theme button paint is overridden explicitly further down). */
.ite-posts-grid button,
.ite-posts-grid input,
.ite-posts-grid select,
.ite-posts-grid textarea {
	margin: 0;
	font: inherit;
	color: inherit;
	line-height: normal;
	letter-spacing: normal;
	text-shadow: none;
	min-height: 0;
	max-width: none;
	float: none;
	box-shadow: none;
	text-decoration: none;
}

.ite-posts-grid button {
	width: auto;
	-webkit-appearance: none;
	appearance: none;
}

/* Images: strip theme framing (borders, radius, shadows, forced margins). */
.ite-posts-grid img {
	max-width: 100%;
	height: auto;
	margin: 0;
	padding: 0;
	border: 0 !important;
	border-radius: 0 !important;
	box-shadow: none !important;
	background: none;
	vertical-align: middle;
}

/* Text blocks: zero theme margins/list chrome; we set our own spacing. */
.ite-posts-grid h1,
.ite-posts-grid h2,
.ite-posts-grid h3,
.ite-posts-grid h4,
.ite-posts-grid h5,
.ite-posts-grid h6,
.ite-posts-grid p,
.ite-posts-grid ul,
.ite-posts-grid li,
.ite-posts-grid figure {
	margin: 0;
	padding: 0;
	background: none;
	list-style: none;
	text-transform: none;
}

/* =============================================================== Filter bar */

/* Two stacked, centered rows: the category icon filter, then keyword search. */
.ite-posts-grid .ite-posts-grid__filter {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 26px;
	margin-bottom: 40px;
}

/* ---- Category icon filter ---- */

.ite-posts-grid .ite-cat-filter {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: clamp(14px, 4vw, 52px);
	width: 100%;
}

.ite-posts-grid .ite-cat-filter__item {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	padding: 6px 4px;
	text-decoration: none;
	color: var(--ite-primary);
	background: none;
	border: 0;
	cursor: pointer;
}

/* The icons are square SVGs, so they scale crisply — size them by the box
   height and let width follow. */
.ite-posts-grid .ite-cat-filter__icon {
	display: flex;
	align-items: flex-end;
	justify-content: center;
	height: 60px;
	border-radius: 12px;
}

.ite-posts-grid .ite-cat-filter__icon img {
	width: auto;
	height: 100%;
	max-width: none;
	opacity: 0.82;
	transition: opacity 0.18s ease;
}

.ite-posts-grid .ite-cat-filter__label {
	position: relative;
	padding-bottom: 7px;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: 0.01em;
	text-align: center;
	color: var(--ite-primary);
	transition: color 0.18s ease;
}

/* Underline bar — grows in on hover/focus, full width when selected. */
.ite-posts-grid .ite-cat-filter__label::after {
	content: "";
	position: absolute;
	left: 50%;
	bottom: 0;
	width: 0;
	height: 2px;
	background: var(--ite-accent);
	transform: translateX(-50%);
	transition: width 0.2s ease;
}

.ite-posts-grid .ite-cat-filter__item:hover .ite-cat-filter__icon img,
.ite-posts-grid .ite-cat-filter__item:focus-visible .ite-cat-filter__icon img {
	opacity: 1;
}

.ite-posts-grid .ite-cat-filter__item:hover .ite-cat-filter__label,
.ite-posts-grid .ite-cat-filter__item:focus-visible .ite-cat-filter__label {
	color: var(--ite-accent);
}

.ite-posts-grid .ite-cat-filter__item:hover .ite-cat-filter__label::after,
.ite-posts-grid .ite-cat-filter__item:focus-visible .ite-cat-filter__label::after {
	width: 55%;
}

.ite-posts-grid .ite-cat-filter__item.is-active .ite-cat-filter__icon img {
	opacity: 1;
}

.ite-posts-grid .ite-cat-filter__item.is-active .ite-cat-filter__label {
	color: var(--ite-accent);
}

.ite-posts-grid .ite-cat-filter__item.is-active .ite-cat-filter__label::after {
	width: 100%;
}

/* Visible keyboard focus (mouse clicks stay clean via :focus-visible). */
.ite-posts-grid .ite-cat-filter__item:focus-visible {
	outline: none;
}

.ite-posts-grid .ite-cat-filter__item:focus-visible .ite-cat-filter__icon {
	box-shadow: 0 0 0 3px rgba(159, 31, 96, 0.3);
}

/* ---- Keyword search ---- */

.ite-posts-grid .ite-search {
	display: flex;
	flex-wrap: wrap;
	align-items: stretch;
	justify-content: center;
	gap: 12px;
	width: 100%;
}

.ite-posts-grid .ite-filter__field {
	position: relative;
	flex: 1 1 220px;
	min-width: 0;
	margin: 0;
}

.ite-posts-grid .ite-filter__field input[type="search"] {
	width: 100%;
	height: var(--ite-control-h);
	padding: 0 18px;
	font: inherit;
	font-size: 16px;
	color: var(--ite-ink);
	background: var(--ite-surface);
	border: 1px solid var(--ite-line);
	border-radius: var(--ite-btn-radius);
	transition: border-color 0.18s ease, box-shadow 0.18s ease;
	-webkit-appearance: none;
	appearance: none;
}

.ite-posts-grid .ite-filter__field input[type="search"]:focus {
	outline: none;
	border-color: var(--ite-accent);
	box-shadow: 0 0 0 3px rgba(159, 31, 96, 0.14);
}

.ite-posts-grid .ite-filter__field input[type="search"]::placeholder {
	color: #9aa0ad;
}

/* ---- Contextual sub-category dropdown ---- */

.ite-posts-grid .ite-subfilter {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 12px;
	width: 100%;
}

.ite-posts-grid .ite-subfilter__label {
	margin-bottom: 0;
	font-size: 14px;
	font-weight: 600;
	letter-spacing: 0.02em;
	color: var(--ite-primary);
}

.ite-posts-grid .ite-subfilter__control {
	display: flex;
	align-items: stretch;
	gap: 12px;
}

.ite-posts-grid .ite-subfilter select {
	min-width: 240px;
	height: var(--ite-control-h);
	padding: 0 44px 0 18px;
	font: inherit;
	font-size: 16px;
	color: var(--ite-ink);
	background-color: var(--ite-surface);
	border: 1px solid var(--ite-line);
	border-radius: var(--ite-btn-radius);
	cursor: pointer;
	transition: border-color 0.18s ease, box-shadow 0.18s ease;
	-webkit-appearance: none;
	appearance: none;
	/* Chevron (navy, matches the theme). */
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath fill='none' stroke='%2300164C' stroke-width='2' d='M1 1l6 6 6-6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 18px center;
}

.ite-posts-grid .ite-subfilter select:focus {
	outline: none;
	border-color: var(--ite-accent);
	box-shadow: 0 0 0 3px rgba(159, 31, 96, 0.14);
}

/* The "Go" submit is a no-JS fallback wrapped in <noscript> in the template, so
   it only exists when scripting is off; with JS the select auto-submits. Its
   paint lives in ITE_Posts_Grid::instance_button_css(). */

/* NOTE: the Filter (filled) and Clear (outline) button PAINT + SIZING are
   emitted per-instance, ID-scoped + !important, by
   ITE_Posts_Grid::instance_button_css() — that is the only way to reliably
   outrank aggressive theme/plugin <button> rules. See that method for the
   single source of truth. Only layout/containers live here. */

/* ===================================================================== Grid */

.ite-posts-grid .ite-posts-grid__grid {
	display: grid;
	grid-template-columns: repeat(var(--ite-cols), minmax(0, 1fr));
	gap: var(--ite-gap);
}

/* ===================================================================== Card */

.ite-posts-grid .ite-card {
	display: flex;
	flex-direction: column;
	background: var(--ite-surface);
	border: 1px solid var(--ite-line);
	border-radius: var(--ite-radius);
	overflow: hidden;
	text-decoration: none;
	color: inherit;
	box-shadow: var(--ite-shadow);
	transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
	will-change: transform;
}

/* Belt-and-braces: no underline anywhere inside the card on any state. */
.ite-posts-grid .ite-card,
.ite-posts-grid .ite-card:hover,
.ite-posts-grid .ite-card:focus,
.ite-posts-grid .ite-card:focus-visible,
.ite-posts-grid .ite-card *,
.ite-posts-grid .ite-card:hover *,
.ite-posts-grid .ite-card:focus * {
	text-decoration: none !important;
}

.ite-posts-grid .ite-card:hover,
.ite-posts-grid .ite-card:focus-visible {
	transform: translateY(-6px);
	box-shadow: var(--ite-shadow-hover);
	border-color: transparent;
	outline: none;
}

.ite-posts-grid .ite-card:focus-visible {
	box-shadow: var(--ite-shadow-hover), 0 0 0 3px rgba(159, 31, 96, 0.4);
}

.ite-posts-grid .ite-card__media {
	position: relative;
	aspect-ratio: 3 / 2;
	background: var(--ite-bg-soft);
	overflow: hidden;
}

.ite-posts-grid .ite-card__img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.ite-posts-grid .ite-card__body {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	padding: 22px 24px 26px;
}

.ite-posts-grid .ite-card__terms {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 14px;
}

.ite-posts-grid .ite-card__pill {
	display: inline-block;
	padding: 5px 12px;
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--ite-accent);
	background: rgba(159, 31, 96, 0.08);
	border-radius: 999px;
	line-height: 1.4;
}

.ite-posts-grid .ite-card__title {
	margin: 0 0 12px;
	font-family: "Big Shoulders Display", "Work Sans", sans-serif;
	font-weight: 700;
	font-size: 23px;
	line-height: 1.15;
	color: var(--ite-primary);
	transition: color 0.18s ease;
}

.ite-posts-grid .ite-card:hover .ite-card__title {
	color: var(--ite-accent);
}

.ite-posts-grid .ite-card__excerpt {
	margin: 0 0 20px;
	font-size: 15px;
	font-weight: 400;
	line-height: 1.6;
	color: var(--ite-muted);
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.ite-posts-grid .ite-card__more {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin-top: auto;
	font-weight: 600;
	font-size: 14px;
	letter-spacing: 0.02em;
	color: var(--ite-accent);
}

/* The theme paints a:hover with `color:#00AEEF !important`, which bleeds onto
   this glyph span. Only !important can win against !important — same as the
   text-decoration resets above — so the arrow stays on-brand in every state. */
.ite-posts-grid .ite-card__more-arrow {
	color: var(--ite-accent) !important;
	transition: transform 0.2s ease;
}

.ite-posts-grid .ite-card:hover .ite-card__more-arrow,
.ite-posts-grid .ite-card:focus .ite-card__more-arrow {
	color: var(--ite-accent) !important;
	transform: translateX(4px);
}

/* ================================================================ Load more */

.ite-posts-grid .ite-posts-grid__more {
	display: flex;
	justify-content: center;
	margin-top: 40px;
}

/* The Load-more button (outline, small) is painted per-instance by
   ITE_Posts_Grid::instance_button_css() — see note above. */

.ite-posts-grid .ite-posts-grid__error {
	margin-top: 16px;
	text-align: center;
	color: var(--ite-accent);
	font-size: 14px;
}

.ite-posts-grid .ite-posts-grid__empty {
	padding: 40px 0;
	text-align: center;
	font-size: 17px;
	color: var(--ite-muted);
}

/* =============================================================== Responsive */

@media (max-width: 1024px) {
	.ite-posts-grid {
		--ite-cols: 2 !important;
		--ite-gap: 22px;
	}
}

@media (max-width: 640px) {
	.ite-posts-grid {
		--ite-cols: 1 !important;
	}

	.ite-posts-grid .ite-posts-grid__filter {
		flex-direction: column;
	}

	.ite-posts-grid .ite-filter__field,
	.ite-posts-grid .ite-filter__field--category {
		flex: 1 1 auto;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ite-posts-grid .ite-card,
	.ite-posts-grid .ite-card__more-arrow,
	.ite-posts-grid .ite-card__title {
		transition: none;
	}
}
