/**
 * Magnet Connector — feed grid and article view.
 *
 * Scoped entirely to .magnet-* classes so it cannot leak into the rest of a
 * client's site. Tokens are defined once and inherited, which is what lets a
 * client re-skin this to their brand by overriding four custom properties
 * rather than fighting the stylesheet.
 */

.magnet-feed,
.magnet-article {
	--magnet-ink: #16233f;
	--magnet-muted: #5a6579;
	--magnet-rule: #e3e8ef;
	--magnet-surface: #ffffff;
	--magnet-ground: #f7f9fc;
	--magnet-badge-bg: #dbe7fb;
	--magnet-badge-ink: #1b3a72;
	--magnet-radius: 14px;
	--magnet-shadow: 0 1px 2px rgba(16, 30, 54, .04), 0 8px 24px rgba(16, 30, 54, .06);
}

/* -------------------------------------------------------- feed controls */

.magnet-feed-wrap {
	--magnet-ink: #16233f;
	--magnet-muted: #5a6579;
	--magnet-rule: #e3e8ef;
	--magnet-surface: #ffffff;
	--magnet-accent: #1b3a72;
}

/*
 * The page heading is the theme's and sits outside this plugin's markup, so it
 * is centred here rather than composed. Several selectors because themes name
 * the wrapper differently — Hello Elementor uses .page-header, others
 * .entry-header or .page-title. Scoped to the feed page, so nothing else on the
 * site is affected, and harmless on a theme that matches none of them.
 */
.magnet-feed-page .page-header,
.magnet-feed-page .entry-header,
.magnet-feed-page .page-header .entry-title,
.magnet-feed-page h1.entry-title,
.magnet-feed-page h1.page-title {
	text-align: center;
}

.magnet-feed-page .page-header {
	margin-bottom: 10px;
}

.magnet-feed__subtitle {
	margin: 0 auto 34px;
	max-width: 46ch;
	text-align: center;
	color: var(--magnet-muted);
	font-size: 19px;
	line-height: 1.5;
}

.magnet-feed__controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	margin: 0 0 34px;
}

/* The tabs are real links and work with JavaScript disabled, so they always
   render. Only the search box depends on the script, so only it is gated —
   a search field that silently does nothing is worse than no search field. */
.magnet-search { display: none; }
.magnet-feed-wrap--ready .magnet-search { display: block; }

.magnet-filters { display: flex; flex-wrap: wrap; gap: 12px; }

.magnet-filter {
	appearance: none;
	cursor: pointer;
	display: inline-block;
	text-decoration: none;
	padding: 11px 26px;
	border: 1px solid var(--magnet-rule);
	border-radius: 999px;
	background: var(--magnet-surface);
	color: var(--magnet-accent);
	font-size: 16px;
	font-weight: 600;
	line-height: 1.3;
	transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.magnet-filter:hover { border-color: var(--magnet-accent); }

.magnet-filter.is-active,
.magnet-filter[aria-current="page"] {
	background: var(--magnet-ink);
	border-color: var(--magnet-ink);
	color: #fff;
}

.magnet-filter:focus-visible,
.magnet-search__input:focus-visible {
	outline: 2px solid var(--magnet-accent);
	outline-offset: 2px;
}

.magnet-search { flex: 1 1 260px; max-width: 420px; margin-left: auto; }

.magnet-search__input {
	width: 100%;
	padding: 13px 22px;
	border: 1px solid var(--magnet-rule);
	border-radius: 999px;
	background: var(--magnet-surface);
	color: var(--magnet-ink);
	font-size: 16px;
	line-height: 1.3;
}

.magnet-search__input::placeholder { color: #97a1b2; }

.magnet-noresults {
	margin: 40px 0;
	text-align: center;
	color: var(--magnet-muted);
	font-size: 17px;
}

/* WordPress ships this class, but the plugin must not assume the theme does. */
.magnet-feed-wrap .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

@media (max-width: 640px) {
	.magnet-feed__controls { flex-direction: column; align-items: stretch; }
	.magnet-search { margin-left: 0; max-width: none; }
}

/* ------------------------------------------------------------------ feed */

.magnet-feed {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
	gap: 28px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.magnet-card {
	background: var(--magnet-surface);
	border: 1px solid var(--magnet-rule);
	border-radius: var(--magnet-radius);
	box-shadow: var(--magnet-shadow);
	overflow: hidden;
	display: flex;
	flex-direction: column;
	transition: transform .18s ease, box-shadow .18s ease;
}

.magnet-card:hover,
.magnet-card:focus-within {
	transform: translateY(-2px);
	box-shadow: 0 2px 4px rgba(16, 30, 54, .05), 0 14px 32px rgba(16, 30, 54, .1);
}

.magnet-card__media {
	position: relative;
	display: block;
	aspect-ratio: 16 / 10;
	background: var(--magnet-ground);
	overflow: hidden;
}

.magnet-card__media img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* The badge sits on the image, so it needs its own contrast rather than
   relying on whatever the photograph happens to be. */
.magnet-card__badge {
	position: absolute;
	top: 14px;
	right: 14px;
	margin: 0;
	padding: 5px 14px;
	border-radius: 999px;
	background: var(--magnet-ink);
	color: #fff;
	font-size: 13px;
	font-weight: 600;
	line-height: 1.4;
	letter-spacing: .01em;
}

.magnet-card__inner {
	padding: 22px 24px 20px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	flex: 1;
}

.magnet-card__title {
	margin: 0;
	font-size: 21px;
	line-height: 1.3;
	font-weight: 700;
	letter-spacing: -.01em;
}

.magnet-card__title a {
	color: var(--magnet-ink);
	text-decoration: underline;
	text-underline-offset: 3px;
	text-decoration-thickness: 1px;
}

.magnet-card__title a:hover { text-decoration-thickness: 2px; }

.magnet-card__excerpt {
	margin: 0;
	color: var(--magnet-muted);
	font-size: 15.5px;
	line-height: 1.6;
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.magnet-card__foot {
	margin-top: auto;
	padding-top: 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	font-size: 14.5px;
}

.magnet-card__date { color: var(--magnet-muted); text-decoration: underline; text-underline-offset: 3px; }
.magnet-card__more { color: var(--magnet-ink); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }

.magnet-feed-empty { color: var(--magnet-muted); }

/* --------------------------------------------------------------- article */

.magnet-article {
	display: grid;
	grid-template-columns: 260px minmax(0, 1fr);
	gap: 56px;
	align-items: start;
	max-width: 1120px;
	margin: 0 auto;
}

@media (max-width: 900px) {
	.magnet-article { grid-template-columns: 1fr; gap: 28px; }
	.magnet-article__rail { position: static !important; }
}

.magnet-article__rail {
	position: sticky;
	top: 32px;
	display: flex;
	flex-direction: column;
	gap: 28px;
}

.magnet-back {
	align-self: flex-start;
	display: inline-block;
	padding: 12px 26px;
	border: 1px solid var(--magnet-rule);
	border-radius: 10px;
	background: var(--magnet-surface);
	color: var(--magnet-ink);
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.magnet-back:hover { border-color: var(--magnet-ink); }

/* Reviewing an unapproved post: make it obvious this is not the live page. */
.magnet-back--review {
	background: #16233f;
	border-color: #16233f;
	color: #fff;
}
.magnet-back--review:hover { background: #0f1a30; border-color: #0f1a30; }

.magnet-preview-note {
	margin: 0;
	padding: 10px 14px;
	border-radius: 8px;
	background: #fbf2e2;
	border: 1px solid #e8d5ac;
	color: #7a5a17;
	font-size: 13.5px;
	line-height: 1.45;
}

.magnet-toc__label {
	margin: 0 0 14px;
	font-size: 12.5px;
	font-weight: 700;
	letter-spacing: .12em;
	text-transform: uppercase;
	color: #8792a6;
}

.magnet-toc ul {
	margin: 0;
	padding: 0 0 0 18px;
	list-style: none;
	border-left: 1px solid var(--magnet-rule);
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.magnet-toc a {
	color: var(--magnet-ink);
	text-decoration: none;
	font-size: 15.5px;
	line-height: 1.45;
}

.magnet-toc a:hover { text-decoration: underline; text-underline-offset: 3px; }

.magnet-hero {
	margin: 0 0 26px;
	border-radius: var(--magnet-radius);
	overflow: hidden;
	background: var(--magnet-ground);
}

.magnet-hero img { width: 100%; height: auto; display: block; }

.magnet-badge {
	display: inline-block;
	margin: 0 0 18px;
	padding: 7px 18px;
	border-radius: 999px;
	background: var(--magnet-badge-bg);
	color: var(--magnet-badge-ink);
	font-size: 13px;
	font-weight: 700;
	letter-spacing: .08em;
	text-transform: uppercase;
}

.magnet-article__title {
	margin: 0 0 10px;
	font-size: clamp(32px, 4.4vw, 50px);
	line-height: 1.1;
	font-weight: 800;
	letter-spacing: -.02em;
	color: var(--magnet-ink);
	text-wrap: balance;
}

.magnet-article__meta { margin: 0 0 32px; color: var(--magnet-muted); font-size: 15px; }

.magnet-article__body { color: #26324a; font-size: 17.5px; line-height: 1.75; }
.magnet-article__body > *:first-child { margin-top: 0; }
.magnet-article__body h2 {
	margin: 46px 0 16px;
	font-size: 28px;
	line-height: 1.25;
	font-weight: 700;
	letter-spacing: -.01em;
	color: var(--magnet-ink);
	scroll-margin-top: 90px;   /* so an anchor jump clears a sticky header */
}
.magnet-article__body h3 { margin: 32px 0 12px; font-size: 21px; font-weight: 700; color: var(--magnet-ink); }
.magnet-article__body p { margin: 0 0 20px; }
.magnet-article__body ul,
.magnet-article__body ol { margin: 0 0 22px; padding-left: 24px; display: flex; flex-direction: column; gap: 10px; }
.magnet-article__body img { max-width: 100%; height: auto; border-radius: 10px; }
.magnet-article__body a { color: var(--magnet-badge-ink); text-underline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
	.magnet-card { transition: none; }
	.magnet-card:hover { transform: none; }
}

/* ------------------------------------------- winning back our own typography */
/*
 * Two separate ways a theme takes over our type, both seen on the same site.
 *
 * COLOUR — equal specificity, theme loads later.
 * ELEMENT SELECTORS — the theme is simply more specific than we were.
 *
 * Our card title is `<h3 class="magnet-card__title">`, and a kit styles headings
 * as `.elementor-kit-<id> h3` — (0,1,1) against our (0,1,0). The theme wins
 * outright, so `font-size: 1.8em; font-weight: 800` replaced our 21px/700 and
 * every card title rendered at roughly 29px. Because `em` compounds, it also
 * scaled with whatever the container inherited.
 *
 * That is what made the feed unusable rather than merely ugly: cards in a grid
 * stretch to the tallest in their row, so one seven-line title inflated all
 * three, and a row no longer fitted on screen.
 *
 * Both problems have the same shape and the same answer — restate our values
 * one class deeper. (0,2,0) beats (0,1,1) on class count alone, and beats an
 * equal-specificity rule regardless of load order. Everything stays scoped
 * inside our own containers.
 *
 * Deliberately NOT reset: font-family, and the article's own h1. Inheriting the
 * client's heading font is what makes an imported article look native to their
 * site rather than bolted on. Only the properties that break the layout are
 * taken back.
 */

/* ------------------------------------------------- winning the link colour */
/*
 * Themes set a global link colour, and it lands on our links too. Elementor
 * kits do it as `.elementor-kit-<id> a { color: … }` — specificity (0,1,1),
 * exactly the same as our own `.magnet-toc a`. Equal specificity means load
 * order decides, and the kit stylesheet is printed after ours, so the theme
 * wins every time.
 *
 * Observed on a real site: a kit setting `color:#FFFF00; font-weight:800`
 * turned the contents rail into yellow bold text on white — close to
 * unreadable, and the kind of thing a client sees before we do.
 *
 * Load order is not something a plugin can rely on across themes, so these
 * restate the same values one class deeper. (0,2,1) beats (0,1,1) regardless
 * of who prints last. Everything stays scoped inside our own containers, so a
 * theme's links are untouched everywhere else on the site.
 *
 * font-weight and letter-spacing are reset alongside colour because kits
 * commonly set all three on `a`, and inheriting just those two is enough to
 * make the rail look broken on its own.
 */
.magnet-article .magnet-toc a,
.magnet-feed-wrap .magnet-toc a {
	color: var(--magnet-ink);
	font-weight: 400;
	letter-spacing: normal;
}

.magnet-article .magnet-back,
.magnet-feed-wrap .magnet-back {
	color: var(--magnet-ink);
	font-weight: 600;
	letter-spacing: normal;
}

.magnet-article .magnet-back--review,
.magnet-feed-wrap .magnet-back--review { color: #fff; }

.magnet-article .magnet-article__body a {
	color: var(--magnet-badge-ink);
	font-weight: inherit;
	letter-spacing: normal;
}

/*
 * Clamped as well as resized. Without a ceiling, one long title still sets the
 * height of every card beside it — and Magnet routinely produces titles like
 * "How to Choose an Integrated Mechanical and Electronics Contract Manufacturer
 * in Texas", which runs to five or six lines here.
 *
 * Three lines rather than two: two truncates titles that would otherwise fit,
 * and a feed of ellipses is its own kind of broken. The full title is still on
 * the article page, in the link's accessible name, and read out in full by
 * screen readers — `-webkit-line-clamp` hides the overflow visually, it does
 * not remove the text.
 */
.magnet-feed-wrap .magnet-card__title {
	font-size: 21px;
	line-height: 1.3;
	font-weight: 700;
	letter-spacing: -.01em;
	display: -webkit-box;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.magnet-feed-wrap .magnet-card__title a {
	color: var(--magnet-ink);
	font-weight: 700;
	letter-spacing: normal;
}

.magnet-feed-wrap .magnet-card__date { color: var(--magnet-muted); font-weight: 400; letter-spacing: normal; }
.magnet-feed-wrap .magnet-card__more { color: var(--magnet-ink); font-weight: 500; letter-spacing: normal; }

.magnet-feed-wrap .magnet-filter {
	color: var(--magnet-accent);
	font-weight: 500;
	letter-spacing: normal;
}

.magnet-feed-wrap .magnet-filter.is-active,
.magnet-feed-wrap .magnet-filter[aria-current="page"] { color: #fff; }

/*
 * Section headings inside an imported article. `.magnet-article__body h2` is
 * (0,1,1) — exactly tied with `.elementor-kit-<id> h2`, so the theme wins on
 * load order. Same fix, and worth doing in the same pass: a 2.2em h2 inside
 * 17.5px body copy makes an article read as a stack of banners.
 */
.magnet-article .magnet-article__body h2 {
	font-size: 28px;
	line-height: 1.25;
	font-weight: 700;
	letter-spacing: -.01em;
}

.magnet-article .magnet-article__body h3 {
	font-size: 21px;
	line-height: 1.35;
	font-weight: 700;
	letter-spacing: normal;
}
