/**
 * MTC Sticky CTA
 *
 * Loaded only on views that show a bar, so the body-level rules here need no
 * page scoping: they cannot reach any other page.
 *
 * Colours, inner width and z-index come from custom properties set inline by
 * the plugin from its settings screen.
 */

.mtccta-bar {
	position: fixed;
	left: 0;
	right: 0;
	z-index: var(--mtccta-z, 10500);
	background: var(--mtccta-bg, #111111);
	box-sizing: border-box;

	/*
	 * A constrained-layout parent applies max-width and auto margins to every
	 * child, including fixed ones, which renders the bar at content width and
	 * centred. These three are inert elsewhere, so they are always included.
	 */
	max-width: none;
	width: auto;
	margin: 0;
}

.mtccta-bar__inner {
	max-width: var(--mtccta-max-width, 1340px);
	margin: 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	min-width: 0;
}

.mtccta-bar__text {
	margin: 0;
	color: var(--mtccta-text, #fff);
	min-width: 0;
}

.mtccta-bar__actions {
	display: flex;
	align-items: center;
	gap: 8px;
	min-width: 0;
}

/*
 * inline-flex matters: min-height is ignored on inline elements.
 *
 * border-box matters just as much. Themes do not reliably apply a universal
 * border-box reset, and under content-box the min-height below excludes the
 * padding, which silently makes every button 16px taller than intended and the
 * whole bar with it.
 */
.mtccta-bar__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	border-radius: 6px;
	font-weight: 700;
	text-decoration: none;
	text-align: center;
	min-width: 0; /* lets flex items shrink instead of overflowing their box */
	transition: opacity .15s ease;
}

.mtccta-bar__btn--primary {
	background: var(--mtccta-primary-bg, #e2af80);
	color: var(--mtccta-primary-text, #111111);
}

.mtccta-bar__btn--ghost {
	background: transparent;
	color: var(--mtccta-text, #fff);
	border: 1px solid rgba(255, 255, 255, .7);
}

.mtccta-bar__btn:hover {
	opacity: .88;
}

.mtccta-bar__btn:focus-visible {
	outline: 2px solid var(--mtccta-text, #fff);
	outline-offset: 2px;
}

.mtccta-lbl-short {
	display: none;
}

/* ---------- Desktop: slim bar, top mounted by default ---------- */
@media (min-width: 782px) {

	.mtccta-bar {
		top: 0;
		bottom: auto;
		padding: 0 24px;
		box-shadow: 0 1px 10px rgba(0, 0, 0, .14);
	}

	.mtccta-bar__inner {
		min-height: 52px;
		gap: 24px;
	}

	.mtccta-bar__text {
		display: flex;
		flex-direction: row;
		align-items: baseline;
		gap: 8px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.mtccta-bar__text strong {
		font-size: .88rem;
		font-weight: 700;
	}

	.mtccta-bar__text span {
		font-size: .82rem;
		opacity: .9;
	}

	.mtccta-bar__text span::before {
		content: "\00B7";
		margin-right: 8px;
		opacity: .55;
	}

	.mtccta-bar__actions {
		flex-shrink: 0;
	}

	.mtccta-bar__btn {
		min-height: 34px;
		padding: 6px 18px;
		font-size: .84rem;
		white-space: nowrap;
	}

	/* Anchor targets would otherwise land underneath a top-mounted bar. */
	body [id] {
		scroll-margin-top: 68px;
	}
}

/* ---------- Mobile: bar at the bottom, in the thumb zone ---------- */
@media (max-width: 781px) {

	.mtccta-bar {
		bottom: 0;
		top: auto;
		padding:
			6px
			max(10px, env(safe-area-inset-right))
			calc(6px + env(safe-area-inset-bottom))
			max(10px, env(safe-area-inset-left));
		box-shadow: 0 -1px 12px rgba(0, 0, 0, .16);
	}

	.mtccta-bar__text {
		display: none;
	}

	.mtccta-bar__inner {
		gap: 0;
	}

	.mtccta-bar__actions {
		width: 100%;
		gap: 8px;
	}

	/* 44px is the tap-target floor in both Apple's guidance and WCAG AAA. */
	.mtccta-bar__btn {
		min-height: 44px;
		font-size: .86rem;
		line-height: 1.2;
		white-space: normal;
	}

	/* An asymmetric split reads lighter than two equal halves. */
	.mtccta-bar__btn--primary {
		flex: 1 1 auto;
		padding: 8px 12px;
	}

	.mtccta-bar__btn--ghost {
		flex: 0 0 auto;
		padding: 8px 20px;
	}

	.mtccta-lbl-full {
		display: none;
	}

	.mtccta-lbl-short {
		display: inline;
	}

	/* Without this the bar permanently covers the end of the page. */
	body {
		padding-bottom: calc(62px + env(safe-area-inset-bottom));
	}
}

@media (max-width: 360px) {

	.mtccta-bar__btn {
		font-size: .8rem;
	}

	.mtccta-bar__btn--primary {
		padding: 8px 8px;
	}

	.mtccta-bar__btn--ghost {
		padding: 8px 14px;
	}
}

/*
 * Scroll reveal.
 *
 * The hidden state hangs off html.mtccta-js, set by an inline head script
 * before first paint. No JS means no flag, which means a visible bar: the
 * failure mode is a working CTA rather than an invisible one.
 *
 * visibility and pointer-events matter as well as transform: a parked bar that
 * is only translated still catches clicks and keyboard focus.
 *
 * 150% rather than 110% so the box-shadow clears the screen edge too.
 */
html.mtccta-js .mtccta-bar {
	visibility: hidden;
	pointer-events: none;
	will-change: transform;
}

@media (min-width: 782px) {

	html.mtccta-js .mtccta-bar {
		transform: translateY(-150%);
	}
}

@media (max-width: 781px) {

	html.mtccta-js .mtccta-bar {
		transform: translateY(150%);
	}
}

html.mtccta-js .mtccta-bar.is-visible {
	transform: translateY(0);
	visibility: visible;
	pointer-events: auto;
}

/*
 * Transitions arrive on a later frame than the transform, via a class added on
 * double rAF. Applying both at once leaves the transition stuck at time zero
 * and the bar never moves.
 */
.mtccta-bar--anim {
	transition: transform .28s ease, visibility .28s;
}

/*
 * Admin toolbar offset, for the site owner's own logged-in view.
 *
 * Top-mounted bars only, and that restriction is load-bearing. On mobile the
 * bar is anchored with bottom: 0; adding a top value as well makes the fixed
 * box stretch between the two and fill the entire screen.
 */
@media (min-width: 782px) {

	body.admin-bar .mtccta-bar {
		top: 32px;
	}
}

@media (prefers-reduced-motion: reduce) {

	.mtccta-bar--anim,
	.mtccta-bar__btn {
		transition: none;
	}
}

@media print {

	.mtccta-bar {
		display: none;
	}
}
