/* ==================================================================
   Threshold
   Engagement / next-step plugin for the Esselith suite
   ------------------------------------------------------------------
   Sitewide floating "Next Steps" button + cream next-step modal.
   All color is variable-driven (--thx-*).
   Fonts: Playfair Display (display) + Montserrat (body).
   (No version here — the version lives ONLY in threshold.php, where
   release.sh checks it. A fact not stated cannot go stale.)

   Esselith Core token layer (#20, step 4): the brand color var
   (--thx-primary) and the font vars alias the suite-wide --es-* tokens,
   with the pre-Core value as the fallback — so with Core deactivated
   Threshold renders exactly as before (Core is an enhancer, never a
   dependency). threshold.php still prints a :root inline block AFTER this
   file that sets --thx-primary from the shared pulpit_suite_brand_primary
   option, so a church's saved brand color applies with or without Core.
   The darkened hover/eyebrow tone (--thx-primary-deep) is derived from the
   brand in CSS so it tracks any brand. The cream panel + ink are suite
   NEUTRALS kept Threshold-local (no --es- alias — there is a matching
   --es-surface/--es-ink, but Threshold preserves its own saved values via
   the inline block, exactly how Credo kept its deep-blue bookends).

   Breakpoint standard (Esselith Core): 600 phone / 782 tablet / 1024
   desktop. Threshold uses 600 (standard) plus a documented 460 narrow-phone
   exception where the two-up option grid genuinely needs to stack.
   ------------------------------------------------------------------
   v1.0.9 — Canon/AAA pass (Esselith design canon; Roger signed off
            each judgment call 2026-07-21). Light-surface orange text
            fails contrast on cream (2.29:1), so: title accent word +
            eyebrow -> teal (the suite workhorse; new --thx-secondary
            token, Core-less fallback #004F71); eyebrow to the canon
            13px/700/0.14em; muted subtexts deepened to clear AAA 7:1;
            outline/text inline buttons -> teal (they were darkened-
            orange text at 3.48:1, and canon makes secondary buttons
            teal anyway). KEPT deliberately: every ink-on-orange fill
            (FAB, primary tile, solid button = the canon CTA pattern),
            the decorative resting tile icons (labels carry meaning;
            hover state is solid orange + ink), and all theme-defense
            !important pins.
   v1.0.5 — Theme-defense (cont.): the modal option words turned orange
            on hover. The options are <a>, and `.thx-option-label` had no
            explicit color, so it inherited the anchor color — which LIVE
            Astra's link hover recolors to its accent (#c97700). Pinned the
            label `color` to the ink !important. Also pinned the inline
            shortcode buttons' background/color/border-color !important
            (same bare-<button> defect as the FAB: Astra's button:hover/
            :focus sets all three to its accent). Hid on dev (default-blue
            Astra). No brand/behavior change.
   v1.0.4 — Theme-defense (cont.): pin the modal close (✕) button's
            background + ink with !important against the same global
            `button:focus` rule. open() focuses the ✕ on modal open, so
            LIVE's Astra painted button:focus with its palette accent
            (amber #c97700) over the faint-ink fill; .thx-close (single
            class) lost to button:focus. Its :hover tint is pinned too so
            the hover cue still shows. Hid on dev (Astra accents :hover,
            not bare :focus). Mirrors the v1.0.3 FAB fix.
   v1.0.3 — Theme-defense: pin the floating button's brand fill + ink with
            !important so a theme's global `button:hover/:focus` rule (Astra's
            button system, lightbox focus blanking) can't recolor the pill on
            hover. .thx-fab is a single class and lost to `button:hover`.
   v1.0.2 — Esselith Core token-layer wiring: --thx-primary → --es-brand-
            primary, --thx-primary-deep → --es-brand-primary-dark (CSS-
            derived so it follows any brand), fonts → --es-font-*. Scrim
            brand wash now lightens-before-alpha (--thx-glow-base) so the
            warm halo survives a dark brand instead of vanishing.
   v1.0.1 — Dropped the -webkit-mask-image hack (it cropped the logo
            on the floating pill); added an orange hover state to the
            light option tiles and brightened resting option icons;
            logo now sized within a max-height / max-width box so any
            aspect ratio scales without cropping.
   ================================================================== */

:root {
	/* brand slot — alias the suite token; fallback = pre-Core value */
	--thx-primary:      var(--es-brand-primary, #ED8B00);
	/* darkened hover/eyebrow tone — alias the suite dark token; the Core-less
	   fallback derives it from --thx-primary so it tracks any saved brand
	   without a PHP recompute (was thx_darken(primary, 22)). */
	--thx-primary-deep: var(--es-brand-primary-dark, color-mix(in srgb, var(--thx-primary) 80%, black));
	/* dark-section glow base: the brand lightened toward white BEFORE a glow's
	   own transparency is applied. A brand wash at low alpha over the near-black
	   scrim is visible for a bright brand (Grove orange) but composites to the
	   scrim's own luminance — and vanishes — for a dark brand (burgundy/navy/
	   forest, common church palettes). Lightening first keeps every brand's halo
	   visible; bright brands just read a touch paler, which is fine over the dark
	   scrim. (Mirrors Credo's --cs-glow-base / Pulpit Live's --pl-pulse-base; see
	   migration checklist item (d).) */
	--thx-glow-base:    color-mix(in srgb, var(--thx-primary) 65%, white);
	/* teal workhorse (canon: everyday/secondary accents + light-surface text
	   accents are teal, orange is reserved for fills + the on-dark hero word).
	   Same alias pattern as --thx-primary: suite token, Core-less fallback. */
	--thx-secondary:    var(--es-brand-secondary, #004F71);
	/* suite neutrals — local, not brand slots (still inline-overridable from a
	   church's saved values). Match --es-surface / --es-ink in role. */
	--thx-panel:        #F7F3EC;
	--thx-ink:          #07111A;
	--thx-font-display: var(--es-font-display, 'Playfair Display', Georgia, 'Times New Roman', serif);
	--thx-font-body:    var(--es-font-body, 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif);
}

/* --- SVG hardening -------------------------------------------------
   Some themes ship aggressive global rules (svg path { fill: ... }).
   Pinning stroke/fill on plugin icons wins reliably and scoped, so
   nothing leaks into theme content. */
.thx-modal svg,
.thx-fab svg,
.thx-inline svg,
.thx-wrap svg.thx-ico {
	fill: none !important;
	stroke: currentColor !important;
	display: inline-block;
	vertical-align: middle;
}
.thx-modal svg :is(path, circle, rect, line),
.thx-fab svg :is(path, circle, rect, line),
.thx-inline svg :is(path, circle, rect, line),
.thx-wrap svg.thx-ico :is(path, circle, rect, line) {
	fill: none !important;
	stroke: currentColor !important;
}


/* ==================================================================
   FLOATING TRIGGER BUTTON
   ================================================================== */

.thx-fab {
	position: fixed;
	bottom: 22px;
	z-index: 99990;
	display: inline-flex;
	align-items: center;
	gap: 9px;
	margin: 0;
	padding: 13px 21px;
	border: none;
	border-radius: 999px;
	/* !important defends against themes that globally style `button:hover` /
	   `button:focus` (e.g. Astra's button system recolors a hovered <button> to
	   its palette accent — blue on default Astra, amber on a Grove-aligned one —
	   and a lightbox `button:focus{background:none}` rule can blank it and show the
	   dark section behind). The FAB is a bare <button>, and a single class (.thx-fab)
	   can't outweigh `button:hover`, so the brand fill + ink are pinned across every
	   interaction state. The FAB only lifts on hover; its fill never changes. */
	background: var(--thx-primary) !important;
	color: var(--thx-ink) !important;
	font-family: var(--thx-font-body);
	font-size: 15px;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 12px 30px -8px rgba(0, 0, 0, 0.5);
	-webkit-tap-highlight-color: transparent;
	transform: translateZ(0);
	will-change: transform;
	backface-visibility: hidden;
	transition: transform 0.18s ease, box-shadow 0.18s ease;
	animation: thx-fab-in 0.4s ease 0.3s both;
}
.thx-fab--bottom-right { right: 22px; }
.thx-fab--bottom-left  { left: 22px; }

.thx-fab:hover {
	transform: translateY(-3px) translateZ(0);
	box-shadow: 0 18px 40px -10px rgba(0, 0, 0, 0.6);
}
.thx-fab:active { transform: translateY(-1px) translateZ(0); }
.thx-fab:focus-visible {
	outline: 3px solid var(--thx-primary-deep);
	outline-offset: 3px;
}

.thx-fab-icon svg { width: 19px; height: 19px; }
.thx-fab-label { white-space: nowrap; }
.thx-fab-logo-wrap { display: inline-flex; }
.thx-fab-logo {
	display: block;
	width: auto;
	height: auto;
	max-width: 150px;
	max-height: 30px;
}
.thx-fab--mode-logo { width: 66px; height: 66px; padding: 0; justify-content: center; }
.thx-fab--mode-logo .thx-fab-logo { max-height: 40px; max-width: 40px; }

@keyframes thx-fab-in {
	from { opacity: 0; transform: translateY(16px) translateZ(0); }
	to   { opacity: 1; transform: translateY(0)    translateZ(0); }
}

/* Mobile button variants — 600 = the Esselith Core phone breakpoint standard. */
@media (max-width: 600px) {
	.thx-fab {
		bottom: 16px;
		padding: 12px 18px;
		font-size: 14px;
	}
	.thx-fab--bottom-right { right: 16px; }
	.thx-fab--bottom-left  { left: 16px; }

	.thx-fab--m-icon {
		padding: 0;
		width: 56px;
		height: 56px;
		justify-content: center;
		border-radius: 50%;
	}
	.thx-fab--m-icon .thx-fab-label { display: none; }
	.thx-fab--m-icon .thx-fab-icon svg { width: 22px; height: 22px; }
	.thx-fab--m-icon .thx-fab-logo { max-height: 28px; }

	.thx-fab--m-hidden { display: none; }
}


/* ==================================================================
   MODAL — scrim + cream panel
   ================================================================== */

.thx-modal {
	position: fixed;
	inset: 0;
	z-index: 99991;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 22px;
	font-family: var(--thx-font-body);
}
.thx-modal[hidden] { display: none; }

.thx-scrim {
	position: absolute;
	inset: 0;
	border: 0;
	background-color: rgba(14, 9, 4, 0.84);
	/* Faint brand halo behind the panel over the near-black scrim — uses the
	   lightened glow base so it survives a dark brand (checklist item (d)). */
	background-image: radial-gradient(ellipse 52% 46% at 50% 47%,
		color-mix(in srgb, var(--thx-glow-base) 13%, transparent), transparent 70%);
	opacity: 0;
	transition: opacity 0.28s ease;
}
.thx-modal.is-open .thx-scrim { opacity: 1; }

.thx-panel {
	position: relative;
	z-index: 1;
	width: 440px;
	max-width: 100%;
	max-height: 90vh;
	overflow: hidden auto;
	padding: 32px 30px 34px;
	border-radius: 22px;
	background: var(--thx-panel);
	color: var(--thx-ink);
	box-shadow:
		0 36px 82px -18px rgba(0, 0, 0, 0.8),
		0 0 0 1px color-mix(in srgb, var(--thx-primary) 24%, transparent);
	transform: scale(0.95) translateZ(0);
	backface-visibility: hidden;
	opacity: 0;
	transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
.thx-modal.is-open .thx-panel {
	opacity: 1;
	transform: scale(1) translateZ(0);
}

.thx-close {
	position: absolute;
	top: 16px;
	right: 16px;
	width: 34px;
	height: 34px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: none;
	border-radius: 50%;
	/* !important defends against the same theme button system as the FAB (v1.0.3).
	   open() calls close.focus(), so the ✕ <button> is focused the instant the modal
	   pops — and a theme's global `button:focus` rule (Astra's button system paints
	   the palette accent: amber #c97700 on a Grove-aligned theme, blue on default)
	   would recolor it. A single .thx-close class (0,1,0) loses to `button:focus`
	   (0,1,1), so the faint-ink fill + ink color are pinned across every state; the
	   :hover tint is likewise pinned so the hover cue still shows over the theme rule.
	   Dev's Astra applies that accent on :hover only, not bare :focus, so this bug
	   hid on dev — same dev-vs-live gotcha as the FAB. */
	background: color-mix(in srgb, var(--thx-ink) 6%, transparent) !important;
	color: var(--thx-ink) !important;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: background 0.15s ease;
}
.thx-close:hover { background: color-mix(in srgb, var(--thx-ink) 13%, transparent) !important; }
.thx-close:focus-visible {
	outline: 2px solid var(--thx-primary-deep);
	outline-offset: 2px;
}
.thx-close svg { width: 17px; height: 17px; }

/* Modal text */
.thx-eyebrow {
	margin: 0 0 10px;
	font-family: var(--thx-font-body);
	/* canon eyebrow: 13px / 700 / 0.14em, teal on light surfaces */
	font-size: 13px;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--thx-secondary);
}
.thx-title {
	margin: 0;
	padding: 0;
	font-family: var(--thx-font-display);
	font-size: 28px;
	font-weight: 500;
	line-height: 1.22;
	color: var(--thx-ink);
}
.thx-title em {
	font-style: italic;
	font-weight: 500;
	/* teal, not orange: orange text on the cream panel is 2.29:1 — the
	   large-accent-word exemption only exists on DARK backgrounds */
	color: var(--thx-secondary);
}
.thx-sub {
	margin: 9px 0 0;
	font-size: 14px;
	line-height: 1.6;
	/* 75% ink clears AAA 7:1 on the cream panel (60% measured 4.84:1) */
	color: color-mix(in srgb, var(--thx-ink) 75%, var(--thx-panel));
}


/* ==================================================================
   OPTION GRID
   ================================================================== */

.thx-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 11px;
	margin-top: 22px;
}
/* Documented narrow-phone exception to the 600/782/1024 standard: the two-up
   option grid only gets too cramped once the cream panel is below ~416px wide
   (viewport ≈ 460px). Folding this into 600 would needlessly stack the tiles at
   500–599px where two columns still fit comfortably — so the break stays at 460. */
@media (max-width: 460px) {
	.thx-grid { grid-template-columns: 1fr; }
}

.thx-option {
	position: relative;
	display: flex;
	flex-direction: column;
	min-height: 108px;
	padding: 15px;
	border-radius: 15px;
	background: #FFFFFF;
	border: 1px solid color-mix(in srgb, var(--thx-ink) 10%, transparent);
	color: var(--thx-ink);
	text-decoration: none;
	-webkit-tap-highlight-color: transparent;
	transform: translateZ(0);
	transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}
.thx-option:hover {
	transform: translateY(-3px) translateZ(0);
	box-shadow: 0 14px 26px -12px rgba(0, 0, 0, 0.32);
	border-color: color-mix(in srgb, var(--thx-primary) 50%, transparent);
}
.thx-option:not(.thx-option--primary):hover .thx-option-ico {
	background: var(--thx-primary);
}
.thx-option:not(.thx-option--primary):hover .thx-option-ico svg {
	color: var(--thx-ink);
}
.thx-option:not(.thx-option--primary):hover .thx-option-arrow {
	color: var(--thx-primary-deep);
}
.thx-option:focus-visible {
	outline: 2px solid var(--thx-primary-deep);
	outline-offset: 2px;
}

.thx-option-ico {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: color-mix(in srgb, var(--thx-primary) 14%, #FFFFFF);
	transition: background 0.14s ease;
}
.thx-option-ico svg {
	width: 17px;
	height: 17px;
	color: var(--thx-primary);
	transition: color 0.14s ease;
}

.thx-option-arrow {
	position: absolute;
	top: 15px;
	right: 14px;
	color: color-mix(in srgb, var(--thx-ink) 26%, var(--thx-panel));
}
.thx-option-arrow svg { width: 15px; height: 15px; }

.thx-option-text { margin-top: auto; padding-top: 12px; }
.thx-option-label {
	display: block;
	font-size: 15px;
	font-weight: 600;
	/* The option is an <a>, and the label has no explicit color, so it inherited
	   the anchor's color — which a theme's global a:hover/a:focus recolors (LIVE
	   Astra paints hovered links its accent, #c97700 amber), turning the word
	   orange on hover. Pin the ink so the label keeps its color on any theme; the
	   sublabel + arrow + icon already carry their own colors. !important beats the
	   non-!important theme link rule regardless of its selector. */
	color: var(--thx-ink) !important;
}
.thx-option-sub {
	display: block;
	margin-top: 2px;
	font-size: 12px;
	/* 75% ink clears AAA 7:1 on the white tile (52% measured 4.12:1 —
	   that failed plain AA for this 12px text) */
	color: color-mix(in srgb, var(--thx-ink) 75%, var(--thx-panel));
}

/* Primary (first enabled) option — solid orange tile */
.thx-option--primary {
	background: var(--thx-primary);
	border-color: transparent;
}
.thx-option--primary .thx-option-ico {
	width: auto;
	height: auto;
	background: transparent;
	border-radius: 0;
}
.thx-option--primary .thx-option-ico svg {
	width: 24px;
	height: 24px;
	color: var(--thx-ink);
}
.thx-option--primary .thx-option-arrow {
	color: color-mix(in srgb, var(--thx-ink) 55%, var(--thx-primary));
}
.thx-option--primary .thx-option-sub {
	/* near-ink: even pure ink on the orange fill is only 7.51:1, so AAA
	   leaves almost no room to mute — 96% measures 7.2:1, 92% fell to
	   6.85 (and the original 62% was 3.76, an AA fail) */
	color: color-mix(in srgb, var(--thx-ink) 96%, var(--thx-primary));
}
.thx-option--primary:hover {
	box-shadow: 0 16px 30px -12px color-mix(in srgb, var(--thx-primary) 70%, black);
	border-color: transparent;
}


/* ==================================================================
   INLINE SHORTCODE BUTTON  [threshold_button]
   ================================================================== */

.thx-inline {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	margin: 4px 0;
	padding: 11px 20px;
	border: 1.5px solid transparent;
	border-radius: 999px;
	font-family: var(--thx-font-body);
	font-size: 15px;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: transform 0.14s ease, background 0.14s ease, color 0.14s ease;
}
.thx-inline:hover { transform: translateY(-2px); }
.thx-inline:focus-visible {
	outline: 3px solid var(--thx-primary-deep);
	outline-offset: 2px;
}
.thx-inline-icon svg { width: 17px; height: 17px; }

/* The inline shortcode buttons are bare <button>s with single-class variant
   selectors, so a theme's global button:hover/:focus (LIVE Astra sets
   color:#071120; background-color:#c97700; border-color:#c97700) overrides their
   fill, ink, AND border on hover/focus — the same defect as the FAB/✕. Pin all
   three with !important across states (hover tints pinned too so they still win). */
.thx-inline--solid {
	background: var(--thx-primary) !important;
	color: var(--thx-ink) !important;
	border-color: transparent !important;
}
/* Outline + text variants are SECONDARY buttons — canon makes those teal
   (the workhorse). They were darkened-orange text: 3.48:1 on cream, an AA
   fail, and a second-orange drift besides. Teal is 8.06:1 AAA. */
.thx-inline--outline {
	background: transparent !important;
	color: var(--thx-secondary) !important;
	border-color: var(--thx-secondary) !important;
}
.thx-inline--outline:hover {
	background: color-mix(in srgb, var(--thx-secondary) 12%, transparent) !important;
}
.thx-inline--text {
	background: transparent !important;
	color: var(--thx-secondary) !important;
	border-color: transparent !important;
	padding-left: 6px;
	padding-right: 6px;
}
.thx-inline--text:hover {
	background: color-mix(in srgb, var(--thx-secondary) 10%, transparent) !important;
}


/* ==================================================================
   BODY SCROLL LOCK + REDUCED MOTION
   ================================================================== */

body.thx-noscroll { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
	.thx-fab,
	.thx-scrim,
	.thx-panel,
	.thx-option,
	.thx-inline {
		transition: none !important;
		animation: none !important;
	}
	.thx-panel { transform: none; }
}


/* ==================================================================
   ADMIN — SETTINGS PAGE
   ================================================================== */

.thx-wrap .thx-tagline {
	font-size: 14px;
	color: #50575e;
	max-width: 640px;
}
.thx-wrap .thx-tagline em { color: #ED8B00; font-style: italic; }

.thx-wrap .thx-sec {
	margin-top: 32px;
	padding-bottom: 8px;
	border-bottom: 2px solid #ED8B00;
	font-size: 1.1rem;
}
.thx-wrap .thx-pool-note { max-width: 660px; margin: 6px 0 16px; }

.thx-row {
	margin-bottom: 12px;
	padding: 14px 16px;
	background: #fff;
	border: 1px solid #dcdcde;
	border-radius: 8px;
}
.thx-row-head {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 10px;
	padding-bottom: 9px;
	border-bottom: 1px solid #f0f0f1;
}
.thx-row-head .thx-drag { color: #a7aaad; }
.thx-toggle {
	display: flex;
	align-items: center;
	gap: 6px;
	font-weight: 600;
}
.thx-icon-preview { display: inline-flex; }
.thx-icon-preview svg.thx-ico { width: 24px; height: 24px; color: #ED8B00; }

.thx-row-move { display: flex; gap: 4px; margin-left: auto; }
.thx-row-move .button-link {
	width: 28px;
	height: 28px;
	font-size: 16px;
	line-height: 26px;
	text-align: center;
	text-decoration: none;
	border-radius: 4px;
	color: #50575e;
}
.thx-row-move .button-link:hover { background: #f0f0f1; }
.thx-row-move .thx-remove { color: #b32d2e; }

.thx-row-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 2px 20px;
}
.thx-row-grid p { margin: 0.45em 0; }
.thx-row-grid .thx-newtab { grid-column: 1 / -1; }
.thx-row-grid input.regular-text,
.thx-row-grid select { width: 100%; max-width: 100%; }

.thx-logo-field { display: flex; align-items: center; gap: 12px; }
.thx-logo-preview {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 64px;
	height: 64px;
	overflow: hidden;
	background: #f6f7f7;
	border: 1px dashed #c3c4c7;
	border-radius: 6px;
}
.thx-logo-preview img { max-width: 100%; max-height: 100%; display: block; }
.thx-logo-clear { color: #b32d2e; }

.thx-wrap .thx-color { width: 120px; }

/* "Brand colors moved to Esselith → Brand" note (token layer #20, step 4). */
.thx-wrap .thx-brand-moved {
	max-width: 660px;
	margin: 6px 0 0;
	padding: 14px 18px;
	background: #f0f6fc;
	border: 1px solid #c3d4e8;
	border-left: 4px solid #2271b1;
	border-radius: 4px;
	color: #135e96;
	font-size: 13.5px;
	line-height: 1.55;
}
.thx-wrap .thx-brand-moved strong { display: block; margin-bottom: 4px; }
.thx-wrap .thx-brand-moved p { margin: 0; }
.thx-wrap .thx-brand-moved a { color: #2271b1; }
