/*
 * Site-wide pieces the kit owns.
 *
 * Loaded on every front-end page. Everything in here is either scoped to
 * markup this plugin prints, or scoped to a specific Elementor widget on a
 * specific breakpoint and explained in place. Nothing in this file is
 * allowed to be a bare element selector.
 */

/* ====================================================================
 * The header and footer the kit renders
 * ================================================================== */

.csk-header {
	position: relative;
	z-index: 100;
	background: var(--csk-header-bg, #fff);
}

.csk-header--sticky { position: sticky; top: 0; }

/* Under the WordPress admin bar, which is fixed and 32px (46px on phones). */
.admin-bar .csk-header--sticky { top: 32px; }
@media (max-width: 782px) {
	.admin-bar .csk-header--sticky { top: 46px; }
}

/* The theme is asked not to draw its own header once ours is on the page.
 * Hello Elementor listens; for any theme that does not, hide the usual
 * suspects so two headers never stack. */
.csk-has-header .site-header.dynamic-header,
.csk-has-footer .site-footer.dynamic-footer { display: none; }

/*
 * The header on a phone: logo left, menu button right, one row.
 *
 * Elementor stacks a section's columns on mobile, so a three-column header
 * became logo / button / call-to-action, one under the other, with the
 * menu button sitting alone on its own line. The template now carries
 * mobile widths and hides the call-to-action (it is in the menu anyway);
 * these rules do the same for headers built from the older template, so
 * the fix does not wait for a rebuild.
 */
@media (max-width: 767px) {
	.csk-header .elementor-section > .elementor-container {
		flex-wrap: nowrap;
		align-items: center;
	}
	.csk-header .elementor-column:has(.csk-logo) { width: 70%; }
	.csk-header .elementor-column:has(.csk-nav) { width: 30%; }
	.csk-header .elementor-column:has(.csk-nav) .csk-nav { justify-content: flex-end; }
	.csk-header .elementor-column:has(.csk-header-cta),
	.csk-header .elementor-widget.csk-header-cta { display: none; }
}

/*
 * The home page hero, as built by an earlier template.
 *
 * It was a full-width section with a 1100px content width — and Elementor
 * ignores content width on a full-width section, so the column was the
 * viewport and the search bar ran off the right edge. The template now
 * builds it boxed on a stretched section; this boxes the search on pages
 * already built, without waiting for a rebuild. Scoped to a container that
 * actually holds the directory search, and nothing else.
 */
.elementor-section.elementor-section-full_width > .elementor-container:has(.elementor-widget-chd_search) {
	max-width: 1100px;
	margin-left: auto;
	margin-right: auto;
}

/* --- logo ------------------------------------------------------------ */

.csk-logo-wrap { display: flex; align-items: center; }
.csk-logo { display: inline-flex; align-items: center; text-decoration: none; }
.csk-logo img { display: block; height: auto; max-width: 100%; }
.csk-logo-text { font-weight: 700; font-size: 1.25rem; color: var(--ch-ink, #0f172a); letter-spacing: -0.01em; }

/* --- navigation ------------------------------------------------------ */

.csk-nav {
	display: flex;
	align-items: center;
	--csk-nav-gap: 4px;
}

.csk-nav-list,
.csk-nav-list ul { list-style: none; margin: 0; padding: 0; }

.csk-nav-list { display: flex; align-items: center; gap: var(--csk-nav-gap); }
.csk-nav-list li { position: relative; margin: 0; }

.csk-nav-list a {
	display: block;
	padding: 10px 14px;
	color: var(--csk-nav-color, inherit);
	text-decoration: none;
	font-weight: 500;
	border-radius: 6px;
	white-space: nowrap;
}

.csk-nav-list a:hover,
.csk-nav-list a:focus-visible,
.csk-nav-list .current-menu-item > a,
.csk-nav-list .current-menu-ancestor > a { color: var(--csk-nav-hover, var(--ch-brand, #0b5ea8)); }

.csk-nav-list a:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

/* Submenus: open on hover, and on focus so a keyboard reaches them. */
.csk-nav-list .sub-menu {
	position: absolute;
	top: 100%;
	left: 0;
	min-width: 220px;
	padding: 6px;
	background: var(--csk-nav-panel, #fff);
	border-radius: 8px;
	box-shadow: 0 12px 24px rgba(0, 0, 0, .12);
	display: none;
	z-index: 10;
}
.csk-nav-list li:hover > .sub-menu,
.csk-nav-list li:focus-within > .sub-menu { display: block; }
.csk-nav-list .sub-menu a { white-space: normal; }

/* Vertical: a plain list, submenus indented and always open. */
.csk-nav--vertical .csk-nav-list { flex-direction: column; align-items: stretch; gap: 0; }
.csk-nav--vertical .csk-nav-list a { padding: 6px 0; }
.csk-nav--vertical .csk-nav-list .sub-menu { position: static; display: block; box-shadow: none; padding: 0 0 0 14px; min-width: 0; }

/*
 * The button. Hidden until the breakpoint that needs it.
 *
 * Written as `.csk-nav .csk-nav-toggle`, not `.csk-nav-toggle`, on purpose.
 * Hello Elementor styles every `[type=button]`, and an attribute selector
 * has exactly the specificity of a class — so a bare `.csk-nav-toggle` rule
 * ties with the theme's and loses on source order, the theme's stylesheet
 * printing after this one. The result was the theme's pink border on the
 * button and, since the theme's rule also sets display, a hamburger showing
 * on every desktop. Two classes settle it whatever the order.
 */
.csk-nav .csk-nav-toggle {
	display: none;
	align-items: center;
	justify-content: center;
	inline-size: 44px;
	block-size: 44px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--csk-nav-color, inherit);
	cursor: pointer;
}
.csk-nav .csk-nav-toggle svg { inline-size: 24px; block-size: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.csk-nav .csk-nav-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.csk-nav .csk-nav-toggle .csk-nav-close { display: none; }
.csk-nav .csk-nav-toggle[aria-expanded="true"] .csk-nav-open { display: none; }
.csk-nav .csk-nav-toggle[aria-expanded="true"] .csk-nav-close { display: block; }

/*
 * Collapsed: the list becomes a panel under the whole header.
 *
 * Every Elementor column and container is position: relative, so an
 * absolutely positioned panel would anchor to the narrow column the widget
 * sits in — the same bug Elementor Pro's own menu has without "Full Width".
 * Releasing the ancestors between the nav and the header lets the panel
 * anchor to the header itself.
 */
@media (max-width: 1024px) {
	.csk-nav.csk-nav--collapse-tablet .csk-nav-toggle { display: inline-flex; }
	.csk-nav--collapse-tablet .csk-nav-list {
		display: none;
		position: absolute;
		left: 0;
		right: 0;
		top: 100%;
		flex-direction: column;
		align-items: stretch;
		gap: 0;
		padding: 8px;
		background: var(--csk-nav-panel, #fff);
		box-shadow: 0 12px 24px rgba(0, 0, 0, .12);
		max-height: calc(100vh - 90px);
		overflow-y: auto;
		z-index: 9997;
	}
	.csk-nav--collapse-tablet.is-open .csk-nav-list { display: flex; }
	.csk-nav--collapse-tablet .csk-nav-list a { padding: 14px 16px; white-space: normal; }
	.csk-nav--collapse-tablet .csk-nav-list .sub-menu { position: static; display: block; box-shadow: none; padding: 0 0 0 14px; }

	.csk-header :is(.elementor-section, .elementor-container, .elementor-column, .elementor-widget-wrap, .e-con, .e-con-inner, .elementor-widget, .elementor-widget-container):has(.csk-nav--collapse-tablet) { position: static; }
}

@media (max-width: 767px) {
	.csk-nav.csk-nav--collapse-mobile .csk-nav-toggle { display: inline-flex; }
	.csk-nav--collapse-mobile .csk-nav-list {
		display: none;
		position: absolute;
		left: 0;
		right: 0;
		top: 100%;
		flex-direction: column;
		align-items: stretch;
		gap: 0;
		padding: 8px;
		background: var(--csk-nav-panel, #fff);
		box-shadow: 0 12px 24px rgba(0, 0, 0, .12);
		max-height: calc(100vh - 90px);
		overflow-y: auto;
		z-index: 9997;
	}
	.csk-nav--collapse-mobile.is-open .csk-nav-list { display: flex; }
	.csk-nav--collapse-mobile .csk-nav-list a { padding: 14px 16px; white-space: normal; }
	.csk-nav--collapse-mobile .csk-nav-list .sub-menu { position: static; display: block; box-shadow: none; padding: 0 0 0 14px; }

	.csk-header :is(.elementor-section, .elementor-container, .elementor-column, .elementor-widget-wrap, .e-con, .e-con-inner, .elementor-widget, .elementor-widget-container):has(.csk-nav--collapse-mobile) { position: static; }
}

/* ====================================================================
 * Back to top
 * ================================================================== */

button.csk-totop {
	position: fixed;
	right: max(16px, env(safe-area-inset-right));
	bottom: max(16px, env(safe-area-inset-bottom));
	z-index: 90;

	/* 44 × 44 is the minimum a thumb can hit reliably (WCAG 2.5.8 is 24, but
	 * that is a floor for dense UI; this is a lone control at the edge of a
	 * phone screen). */
	inline-size: 44px;
	block-size: 44px;
	display: grid;
	place-items: center;
	box-sizing: border-box;
	padding: 0;
	border: 0;
	border-radius: 999px;

	background: var(--e-global-color-primary, var(--csk-accent, #0b5ea8));
	color: #fff;
	box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
	cursor: pointer;

	/* Present in the DOM from the first paint so a screen reader's controls
	 * list is stable; invisible and non-interactive until there is somewhere
	 * to go back from. */
	opacity: 0;
	visibility: hidden;
	transform: translateY(8px);
	transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
}

button.csk-totop.is-visible {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition: opacity .2s ease, transform .2s ease, visibility 0s;
}

button.csk-totop svg {
	inline-size: 20px;
	block-size: 20px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2.25;
	stroke-linecap: round;
	stroke-linejoin: round;
}

button.csk-totop:hover { filter: brightness(1.08); }

button.csk-totop:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
	box-shadow: 0 0 0 5px var(--e-global-color-primary, var(--csk-accent, #0b5ea8)), 0 6px 18px rgba(0, 0, 0, .22);
}

@media (prefers-reduced-motion: reduce) {
	button.csk-totop { transition: none; transform: none; }
}

@media print {
	button.csk-totop { display: none; }
}

/* ====================================================================
 * Elementor Pro nav menu, on a phone
 *
 * Pro's dropdown menu is not positioned unless the widget's "Full Width"
 * option is on. Without it the open menu is a block *inside* the widget:
 * it simply grows in place, as wide as whatever column the widget sits in.
 * In a header where the menu column is 20% wide on mobile — which is what
 * a three-column header collapses to — that is a strip a few words wide,
 * every item wrapping, the header stretched down the screen.
 *
 * This anchors the open dropdown to the header row instead, edge to edge,
 * which is what "Full Width" does. It is a fallback: the option in the
 * widget remains the right fix, and these rules are inert once it is on
 * because Pro then sets its own position and width inline.
 *
 * Scoped to a theme-builder header and to Elementor's tablet breakpoint,
 * where Pro switches the menu to a dropdown. Nothing here touches desktop.
 * ================================================================== */

@media (max-width: 1024px) {
	.elementor-location-header > .e-con:has(.elementor-widget-nav-menu) { position: relative; }
	.elementor-location-header .e-con:has(> .elementor-widget-nav-menu) { position: static; }
	.elementor-location-header .elementor-widget-nav-menu,
	.elementor-location-header .elementor-widget-nav-menu > .elementor-widget-container { position: static; }

	.elementor-location-header .elementor-widget-nav-menu:not(.elementor-nav-menu--stretch)
		.elementor-nav-menu--dropdown.elementor-nav-menu__container {
		position: absolute;
		left: 0;
		right: 0;
		top: 100%;
		width: auto;
		margin-top: 0;
		z-index: 9997;
		box-shadow: 0 12px 24px rgba(0, 0, 0, .12);
	}

	.elementor-location-header .elementor-nav-menu--dropdown .elementor-item {
		white-space: normal;
		padding-block: 14px;
	}
}

/* Data credit in the footer ([chd_data_credit]): links take the footer's own
   text colour instead of the theme's link colour, which is unreadable on a
   dark footer. Underlined so they still read as links. */
.chd-data-credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.chd-data-credit a:hover,
.chd-data-credit a:focus-visible { text-decoration-thickness: 2px; }
