/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/* =========================================================================
 * RuralHealthConsentBanner by visuaFUSION
 *
 * Every configurable value arrives as a custom property from the inline
 * block the plugin prints in the head, so this file is static, cacheable,
 * and identical on every site. Nothing here is generated.
 *
 * Defaults below are the fallbacks used when "follow the theme's colors"
 * is switched on and the theme defines nothing, so the banner is always
 * legible even on a theme that has never heard of this plugin.
 * ========================================================================= */

:root {
	--rhcb-surface:      #1B1A44;
	--rhcb-panel:        #2B2B5E;
	--rhcb-text:         #E1E0E7;
	--rhcb-muted:        #CCCBD2;
	--rhcb-heading:      #F9F7FF;
	--rhcb-accent:       #00CDE5;
	--rhcb-accent-text:  #1B1A44;
	--rhcb-border:       #807F86;

	--rhcb-radius:        24px;
	--rhcb-button-radius: 999px;

	--rhcb-max:     78rem;
	--rhcb-gutter:  clamp(1rem, 0.5rem + 2.5vw, 2rem);
	--rhcb-gap:     0.75rem;
	--rhcb-target:  44px;

	/* Published by the script once it has measured the banner. */
	--rhcb-height: 0px;
}

/* -------------------------------------------------------------------------
 * Shell and visibility
 *
 * Hidden by default and revealed only by the attribute the pre-paint gate
 * sets. That is the arrangement that survives a full page cache: the HTML
 * is identical for everybody and the cookie decides, in the browser.
 * ---------------------------------------------------------------------- */

.rhcb {
	position: fixed;
	z-index: 2147483000;
	display: none;
	box-sizing: border-box;
	max-height: 85dvh;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--rhcb-surface);
	color: var(--rhcb-text);
	font-size: 14px;
	line-height: 1.5;
	box-shadow: 0 0 2.5rem rgb(0 0 0 / 35%);
}

.rhcb *,
.rhcb *::before,
.rhcb *::after {
	box-sizing: border-box;
}

/* The browser's own [hidden] rule is display:none, but it comes from the
   user agent stylesheet, so any author rule setting display beats it.
   .rhcb__button is display:inline-flex, which means setting el.hidden on
   a button did nothing at all and the element stayed visible. Restating
   it here as an author rule, with !important so it also wins against the
   more specific selectors below, makes `hidden` mean hidden. */
.rhcb [hidden] {
	display: none !important;
}

:root[data-rhcb="pending"] .rhcb {
	display: block;
}

/* Only the full width bar covers the end of the page, so only it needs
   the page to reserve room underneath. A floating card leaves the page
   scrollable past it. */
:root[data-rhcb="pending"] body {
	padding-block-end: var(--rhcb-reserve, 0px);
}

:root[data-rhcb="pending"] {
	scroll-padding-bottom: var(--rhcb-reserve, 0px);
}

:root[data-rhcb="pending"]:has(.rhcb--strip.rhcb--pos-bottom) {
	--rhcb-reserve: var(--rhcb-height);
}

/* -------------------------------------------------------------------------
 * Layout: full width strip
 * ---------------------------------------------------------------------- */

.rhcb--strip {
	inset-inline: 0;
}

.rhcb--strip.rhcb--pos-bottom {
	bottom: 0;
	border-top: 3px solid var(--rhcb-accent);
	border-start-start-radius: var(--rhcb-radius);
	border-start-end-radius: var(--rhcb-radius);
}

.rhcb--strip.rhcb--pos-top {
	top: 0;
	border-bottom: 3px solid var(--rhcb-accent);
	border-end-start-radius: var(--rhcb-radius);
	border-end-end-radius: var(--rhcb-radius);
}

/* -------------------------------------------------------------------------
 * Layout: floating panel
 * ---------------------------------------------------------------------- */

.rhcb--panel {
	border: 1px solid var(--rhcb-accent);
	border-radius: var(--rhcb-radius);
	margin: var(--rhcb-gutter);
	width: calc(100% - (var(--rhcb-gutter) * 2));
}

.rhcb--panel.rhcb--size-small  { max-width: 22rem; }
.rhcb--panel.rhcb--size-medium { max-width: 30rem; }
.rhcb--panel.rhcb--size-large  { max-width: 40rem; }

.rhcb--panel.rhcb--pos-bottom-left  { bottom: 0; left: 0; }
.rhcb--panel.rhcb--pos-bottom-right { bottom: 0; right: 0; }
.rhcb--panel.rhcb--pos-top-left     { top: 0; left: 0; }
.rhcb--panel.rhcb--pos-top-right    { top: 0; right: 0; }

.rhcb--panel.rhcb--pos-center {
	top: 50%;
	left: 50%;
	/* translate rather than a margin, so it stays centered as the panel
	   grows when the preference list opens. */
	transform: translate(-50%, -50%);
	margin: 0;
	width: calc(100vw - (var(--rhcb-gutter) * 2));
}

/* A card stacks: the buttons never sit beside the text at this width. */
.rhcb--panel .rhcb__inner {
	display: block;
}

.rhcb--panel .rhcb__actions {
	margin-top: var(--rhcb-gap);
	align-items: stretch;
}

.rhcb--panel .rhcb__buttons {
	width: 100%;
}

.rhcb--panel .rhcb__button {
	flex: 1 1 auto;
}

.rhcb--panel .rhcb__byline {
	text-align: center;
}

/* -------------------------------------------------------------------------
 * Inner layout
 * ---------------------------------------------------------------------- */

.rhcb__inner {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--rhcb-gap);
	max-width: var(--rhcb-max);
	margin-inline: auto;
	padding: var(--rhcb-gap) var(--rhcb-gutter);
}

.rhcb__intro {
	flex: 1 1 24rem;
	min-width: 0;
}

.rhcb__title {
	margin: 0 0 0.25rem;
	color: var(--rhcb-heading);
	font-size: 1.125rem;
	font-weight: 700;
	line-height: 1.25;
}

.rhcb__text {
	margin: 0;
	text-wrap: pretty;
}

.rhcb__link {
	color: var(--rhcb-accent);
	font-weight: 600;
	white-space: nowrap;
}

.rhcb__link:hover,
.rhcb__link:focus-visible {
	color: var(--rhcb-accent);
	text-decoration: underline;
}

/* -------------------------------------------------------------------------
 * Buttons
 *
 * Radius is derived from the container setting: square at 0, matching
 * below the pill threshold, fully rounded above it. See
 * RHCB_Settings::button_radius().
 * ---------------------------------------------------------------------- */

.rhcb__actions {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 0.25rem;
	flex-shrink: 0;
}

.rhcb__buttons {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.rhcb__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: var(--rhcb-target);
	padding: 0.5rem 1.25rem;
	border: 2px solid transparent;
	border-radius: var(--rhcb-button-radius);
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
	transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.rhcb__button--primary {
	background: var(--rhcb-accent);
	border-color: var(--rhcb-accent);
	color: var(--rhcb-accent-text);
}

.rhcb__button--primary:hover {
	filter: brightness(1.1);
}

.rhcb__button--quiet {
	background: transparent;
	border-color: var(--rhcb-border);
	color: var(--rhcb-text);
}

.rhcb__button--quiet:hover {
	border-color: var(--rhcb-accent);
	background: rgb(255 255 255 / 8%);
}

.rhcb :focus-visible {
	outline: 3px solid var(--rhcb-accent);
	outline-offset: 2px;
}

/* -------------------------------------------------------------------------
 * Byline
 * ---------------------------------------------------------------------- */

.rhcb__byline {
	margin: 0;
	font-size: 12px;
	line-height: 1.2;
}

.rhcb__byline a {
	display: inline-flex;
	align-items: baseline;
	gap: 0.28em;
	/* WCAG 2.5.8 floor. A standalone link does not get the exception
	   given to links inside a sentence, so it earns the height here. */
	min-height: 24px;
	padding: 0.35rem 0.1rem;
	color: var(--rhcb-muted);
	text-decoration: none;
}

.rhcb__byline-name {
	font-family: ui-serif, Georgia, "Times New Roman", serif;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.01em;
	color: var(--rhcb-text);
}

.rhcb__byline-org {
	font-weight: 600;
	color: var(--rhcb-accent);
}

.rhcb__byline a:hover .rhcb__byline-name,
.rhcb__byline a:hover .rhcb__byline-org,
.rhcb__byline a:focus-visible .rhcb__byline-name,
.rhcb__byline a:focus-visible .rhcb__byline-org {
	text-decoration: underline;
	text-underline-offset: 0.18em;
}

/* -------------------------------------------------------------------------
 * Preference center
 * ---------------------------------------------------------------------- */

.rhcb__panel {
	background: var(--rhcb-panel);
	border-top: 1px solid var(--rhcb-border);
}

.rhcb--panel .rhcb__panel {
	border-end-start-radius: var(--rhcb-radius);
	border-end-end-radius: var(--rhcb-radius);
}

.rhcb__list {
	max-width: var(--rhcb-max);
	margin: 0 auto;
	padding: var(--rhcb-gap) var(--rhcb-gutter);
	list-style: none;
	display: grid;
	gap: var(--rhcb-gap);
}

.rhcb__list--nested {
	padding: 0;
	margin-top: 0.5rem;
	gap: 0.75rem;
}

.rhcb__group + .rhcb__group {
	border-top: 1px solid var(--rhcb-border);
	padding-top: var(--rhcb-gap);
}

.rhcb__group-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	max-width: 60ch;
}

.rhcb__group-title {
	margin: 0;
	color: var(--rhcb-heading);
	font-size: 13px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
}

.rhcb__group-text {
	margin: 0.25rem 0 0;
	max-width: 60ch;
	color: var(--rhcb-muted);
	text-wrap: pretty;
}

.rhcb__always {
	font-size: 12px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--rhcb-muted);
}

.rhcb__panel-actions {
	max-width: var(--rhcb-max);
	margin-inline: auto;
	padding: 0 var(--rhcb-gutter) var(--rhcb-gap);
}

/* -------------------------------------------------------------------------
 * Switch
 *
 * A real checkbox, visually hidden but still the thing that receives
 * focus and toggles, so keyboard, screen reader and form semantics all
 * come for free. The track and knob are painted by the sibling span.
 *
 * The knob is white when off against a neutral track and takes the
 * accent's text color when on against the accent track. A white knob
 * on a light accent can fall under 3:1 and fail WCAG 1.4.11, and knob
 * position is what conveys the state.
 * ---------------------------------------------------------------------- */

.rhcb__switch {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	min-height: var(--rhcb-target);
	cursor: pointer;
	color: var(--rhcb-heading);
	font-size: 1rem;
	font-weight: 600;
}

.rhcb__switch input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	margin: 0;
}

.rhcb__track {
	position: relative;
	flex-shrink: 0;
	width: 2.75rem;
	height: 1.5rem;
	border-radius: 999px;
	background: var(--rhcb-border);
	transition: background-color 150ms ease;
}

.rhcb__track::after {
	content: "";
	position: absolute;
	top: 0.1875rem;
	left: 0.1875rem;
	width: 1.125rem;
	height: 1.125rem;
	border-radius: 50%;
	background: #FFFFFF;
	transition: transform 150ms ease, background-color 150ms ease;
}

.rhcb__switch input:checked + .rhcb__track {
	background: var(--rhcb-accent);
}

.rhcb__switch input:checked + .rhcb__track::after {
	transform: translateX(1.25rem);
	background: var(--rhcb-accent-text);
}

.rhcb__switch input:focus-visible + .rhcb__track {
	outline: 3px solid var(--rhcb-accent);
	outline-offset: 2px;
}

.rhcb__switch input:disabled + .rhcb__track {
	opacity: 0.65;
}

.rhcb__switch:has(input:disabled) {
	cursor: default;
}

/* -------------------------------------------------------------------------
 * The control that brings it back
 * ---------------------------------------------------------------------- */

.rhcb-reopen {
	background: none;
	border: 0;
	padding: 0;
	font: inherit;
	color: inherit;
	text-decoration: underline;
	cursor: pointer;
}

/* -------------------------------------------------------------------------
 * Narrow viewports and reduced motion
 * ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.rhcb__button,
	.rhcb__track,
	.rhcb__track::after {
		transition: none;
	}
}

@media (max-width: 40rem) {
	.rhcb--panel,
	.rhcb--panel.rhcb--pos-center {
		max-width: none;
		width: calc(100% - (var(--rhcb-gutter) * 2));
	}

	.rhcb--panel.rhcb--pos-center {
		top: auto;
		bottom: 0;
		left: 0;
		transform: none;
		margin: var(--rhcb-gutter);
	}

	.rhcb__actions {
		width: 100%;
		align-items: center;
	}

	.rhcb__buttons {
		width: 100%;
	}

	.rhcb__button {
		flex: 1 1 100%;
	}
}
