/*
 Theme Name:   Election Protection Child
 Description:  Election Protection Resource Hub child theme. Extends Bricks.
               Styling is authored in the Bricks builder where possible.
               A small set of structural rules below handle dynamic-data
               edge cases that can't be expressed in the builder.
 Template:     bricks
 Version:      0.3.0
 Text Domain:  election-protection
*/

/* Resource card grid.
   Two different DOM shapes route into the same card grid:
   1. Browse page (homepage, term archives): single .brxe-browseloop holds
      every card. Make its parent the grid; loop uses display:contents to
      flatten its children into that grid.
   2. Category Landing: Bricks repeats the entire .brxe-catfeat/.brxe-catrest
      wrapper per iteration, so each becomes one grid item, not a container.
      Make the parent .brxe-catlwrap the grid, with hero / headings / query
      trails spanning full width. */
#brxe-ac993f {
	display: grid !important;
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important;
	gap: 20px !important;
	border: 0 !important;
	background: transparent !important;
	padding: 0 !important;
}
.brxe-browseloop.brxe-block {
	display: contents !important;
	border: 0 !important;
	background: transparent !important;
}

#brxe-catlwrap {
	display: grid !important;
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important;
	gap: 20px !important;
}
#brxe-catlwrap > #brxe-catlhwts,
#brxe-catlwrap > #brxe-catlhadd,
#brxe-catlwrap > .brx-query-trail {
	grid-column: 1 / -1;
}
/* Each .brxe-catfeat/.brxe-catrest is one looped wrapper holding a single
   card; its own Bricks settings give it an inner 3-column grid that would
   shrink the card to 1/3 width. Make it transparent to layout so the inner
   cardwrap becomes the direct grid item of #brxe-catlwrap. */
.brxe-catfeat,
.brxe-catrest {
	display: contents !important;
}

/* Fallback for the section headings' server-side conditions: if a loop still
   renders zero cards (e.g. a stale cached condition), collapse its heading so
   it never dangles over an empty grid. */
#brxe-catlwrap:not(:has(.brxe-catfeat .brxe-cardwrap)) > #brxe-catlhwts {
	display: none !important;
}
#brxe-catlwrap:not(:has(.brxe-catrest .brxe-cardwrap)) > #brxe-catlhadd {
	display: none !important;
}

/* Empty-state box on topic/term archives with no resources at all. The
   element only renders when {cc_topic_is_empty} is "1" (templates 1716/950);
   it's a grid item of #brxe-catlwrap so it spans every column. */
#brxe-catlwrap > .ep-empty-state {
	grid-column: 1 / -1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	text-align: center;
	padding: 56px 24px;
	border: 1.5px dashed #C5CCD9;
	border-radius: 12px;
	background: #fff;
}
.ep-empty-state__link {
	font-family: "Public Sans", system-ui, sans-serif;
	font-weight: 600;
	font-size: 14px;
	letter-spacing: 0.04em;
	color: #1B3A6B;
	text-decoration: none;
	padding: 12px 24px;
	border: 1.5px solid #1B3A6B;
	border-radius: 8px;
}
.ep-empty-state__link:hover {
	background: #1B3A6B;
	color: #fff;
}

/* Sidebar "About" card — labeled chip groups (Type / Format / State /
   Topics). Each group: small uppercase label above a wrapped chip rail.
   Empty groups are dropped server-side, so there are no empty rows. */
.ep-about-group {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-bottom: 14px;
}
.ep-about-group:last-child {
	margin-bottom: 0;
}
.ep-about-group__label {
	font-family: "Public Sans", system-ui, sans-serif;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.10em;
	text-transform: uppercase;
	color: #5A6478;
}
.ep-about-group__chips {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	gap: 6px;
	align-items: center;
}
/* Hide the whole About card when the resource has nothing tagged
   (no Type / Format / State / Topics) — no empty heading dangling. */
#brxe-cacbfb:not(:has(.ep-about-group)) {
	display: none !important;
}

/* URL-source embeds (YouTube, Vimeo, Drive viewers, Docs/Slides, etc.). The
   provider's hardcoded width/height attributes are stripped in ep_resolve_embed
   so the wrapper's aspect-ratio governs the rendered size. Iframes fill the
   wrapper exactly. */
.ep-embed-frame {
	width: 100%;
	background: #000;
	border-radius: 8px;
	overflow: hidden;
}
.ep-embed-frame > * {
	width: 100% !important;
	height: 100% !important;
	border: 0;
	display: block;
}
.ep-embed-frame--16x9 { aspect-ratio: 16 / 9; }
.ep-embed-frame--portrait { aspect-ratio: 3 / 4; }
.ep-embed-frame--audio {
	aspect-ratio: auto;
	background: transparent;
	border-radius: 0;
}
.ep-embed-frame--audio > iframe {
	height: 152px !important;
}

/* Related Resources section on the single-resource template. Bricks repeats
   the entire .brxe-relatedres iteration wrapper per result (same DOM shape
   as catfeat/catrest above), so the grid lives on #brxe-relatedwrap and the
   iteration wrappers are display: contents. Heading spans full width.
   The whole wrap auto-hides when the fallback chain returns no posts. */
#brxe-relatedwrap {
	display: grid !important;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)) !important;
	gap: 16px !important;
}
#brxe-relatedwrap > #brxe-relatedhead {
	grid-column: 1 / -1;
}
.brxe-relatedres {
	display: contents !important;
}
#brxe-relatedwrap:not(:has(.brxe-cardwrap)) {
	display: none !important;
}

/* Card — wrapper is an anchor, so reset link styling.
   height:100% lets the card fill its grid row so siblings stay aligned. */
.brxe-cardwrap {
	display: flex;
	flex-direction: column;
	height: 100%;
	overflow: hidden;
	text-decoration: none;
	color: inherit;
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.brxe-cardwrap:hover {
	transform: translateY(-2px);
	box-shadow: 0 8px 20px rgba(10, 31, 68, 0.1);
}
.brxe-cardwrap:focus-visible {
	outline: 2px solid #1B3A6B;
	outline-offset: 2px;
}

/* Card — image area. Background is set inline via the {cc_format_image}
   dynamic data tag on the cardimg element. */
.brxe-cardimg {
	width: 100%;
	height: 180px;
	background-size: cover;
	background-position: center;
	background-color: #F4F6FA;
	border-bottom: 1px solid #E2E5EA;
}

/* Card — description clamp. */
.ep-card-desc {
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* Filter drawer — long checkbox labels.
   Bricks's default rule pushes the (count) to the row's right edge, leaving
   ugly gaps when a long label wraps. Override so the count sits inline right
   after the last word of the wrapped label. Also top-align the checkbox so
   it sits next to the first line of a wrapped label, not between the lines. */
.brxe-filter-checkbox[data-mode="default"] .brx-option-text {
	flex: initial;
	display: inline;
}
.brxe-filter-checkbox[data-mode="default"] .brx-option-text .brx-option-count {
	margin-inline-start: 4px;
}
.brxe-filter-checkbox[data-mode="default"] label {
	display: flex;
	align-items: flex-start;
	gap: 8px;
}
.brxe-filter-checkbox[data-mode="default"] .brx-input-indicator {
	margin-top: 5px;
	flex-shrink: 0;
}

/* Filter drawer — hierarchical Topics list. One filter element renders the
   whole topic tree; parents read as section rows (matching the old per-topic
   H3 headings) and sub-topics indent beneath them. */
#brxe-tpcfc1 li[data-depth="0"] {
	margin-top: 14px;
}
#brxe-tpcfc1 li[data-depth="0"]:first-child {
	margin-top: 0;
}
#brxe-tpcfc1 li[data-depth="0"] > label .brx-option-text {
	font-weight: 600;
	color: #1d2733;
}
#brxe-tpcfc1 li:not([data-depth="0"]) {
	padding-left: 22px;
}

/* Sign in with Okta button on /sign-in page. */
.ep-sso-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	width: 100%;
	padding: 14px 32px;
	margin-top: 8px;
	background: #1B3A6B;
	color: #fff;
	border: 0;
	border-radius: 6px;
	font-family: 'Public Sans', sans-serif;
	font-size: 16px;
	font-weight: 600;
	letter-spacing: 0.04em;
	line-height: 1.2;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.ep-sso-btn:hover {
	background: #0A1F44;
	transform: translateY(-1px);
	box-shadow: 0 6px 16px rgba(10, 31, 68, 0.18);
}
.ep-sso-btn:focus-visible {
	outline: 2px solid #1B3A6B;
	outline-offset: 3px;
}

/* Load More button under catrest grid on topic landings + sub-topic archives.
   #brxe-catlwrap is forced to display:grid (for the card grid) so the button
   is a grid item — span all columns and use justify-self to center it.
   Keep the button's own inline-flex (icon + text alignment) intact. */
#brxe-catlwrap > #brxe-lmbtn,
#brxe-lmbtn {
	grid-column: 1 / -1 !important;
	justify-self: center !important;
	margin: 16px auto 0 !important;
}

/* Bricks's loadMore JS adds .brx-load-more-hidden when no more pages remain. */
.ep-load-more.brx-load-more-hidden {
	display: none !important;
}

/* Loading state — toggled by the small inline script in bootstrap.php that
   listens for click on .ep-load-more and bricks/ajax/end to clear. */
.ep-load-more.is-loading {
	pointer-events: none;
	color: transparent !important;
	position: relative;
}
.ep-load-more.is-loading::after {
	content: none;
}
.ep-load-more.is-loading::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 18px;
	height: 18px;
	margin: -9px 0 0 -9px;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	color: #1B3A6B;
	animation: ep-spin 0.6s linear infinite;
}
@keyframes ep-spin {
	to { transform: rotate(360deg); }
}

/* Sub-topic drill-down pills on topic umbrella pages.
   Bigger, outlined, button-like — distinct from .ep-chip topic tags. */
.ep-subtopic-pill {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 12px 20px;
	/* margin enforces spacing because the rail's flex-gap doesn't reach the
	   chips (they're wrapped inside a text-basic element, so chips are
	   GRAND-children of the flex parent, not direct children). */
	margin: 0 12px 12px 0;
	background: #fff;
	color: #1B3A6B;
	border: 1.5px solid rgba(27, 58, 107, 0.25);
	border-radius: 8px;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.ep-subtopic-pill::after {
	content: "→";
	font-weight: 700;
	font-size: 16px;
	opacity: 0.55;
	transition: transform 0.15s ease, opacity 0.15s ease;
}
.ep-subtopic-pill:hover {
	background: #1B3A6B;
	color: #fff;
	border-color: #1B3A6B;
	transform: translateY(-1px);
}
.ep-subtopic-pill:hover::after {
	opacity: 1;
	transform: translateX(3px);
}
.ep-subtopic-pill:focus-visible {
	outline: 2px solid #1B3A6B;
	outline-offset: 3px;
}

/* Topic chips emitted by the {cc_category_chips} dynamic data tag (single
   resource page + Browse table). Renders as subtle navy pills. */
.ep-chip {
	display: inline-block;
	padding: 3px 10px;
	margin: 2px 2px 2px 0;
	background: rgba(27, 58, 107, 0.08);
	color: #1B3A6B;
	font-size: 12px;
	font-weight: 600;
	line-height: 1.4;
	text-decoration: none;
	border-radius: 999px;
	transition: background 0.15s ease;
}
.ep-chip:hover {
	background: rgba(27, 58, 107, 0.16);
	color: #0A1F44;
}

/* Browse view toggle.
   The /resources page renders both layouts in the DOM — the grid (#brxe-ac993f)
   and the table view (#brxe-578ab0). The body_class filter in bricks-integration.php
   adds `.ep-view-table` when ?view=table is in the URL, and these rules pick
   which one is visible. Without them both layouts render stacked. */
#brxe-578ab0 {
	display: none;
}
body.ep-view-table #brxe-578ab0 {
	display: block;
}
body.ep-view-table #brxe-ac993f {
	display: none !important;
}
