/**
 * MCN Animations — Feedback (toasts, snackbars, undo)
 *
 * Studied from forevercomponents.com ("Toast Stack", "Undo Snackbar") and
 * rebuilt. Theirs are wall demos: they auto-cycle, and the toast stack has no
 * live region at all, so a screen reader never hears the message. Here a toast
 * is a real announcement:
 *
 *   - Each toast carries role="status" (polite) or role="alert" (assertive),
 *     so it is announced when it appears.
 *   - Every toast has a close button, and the auto-dismiss bar PAUSES on hover
 *     and on focus-within, and while the tab is hidden. That is WCAG 2.2.2
 *     (Pause, Stop, Hide) — you can always stop the clock and read it.
 *   - A toast with an action (Undo) defaults to no auto-dismiss at all: a
 *     destructive action must not commit because someone looked away.
 *   - Nothing here animates under prefers-reduced-motion; the toast simply
 *     appears and still dismisses.
 *
 * Usage (Oxygen: paste nothing, just call it from a Code Block or let the
 * Gravity Forms bridge do it):
 *   MCNAnimations.toast({ title: 'Saved', text: 'Changes synced', kind: 'success' });
 *   MCNAnimations.toast({ title: 'Item deleted', kind: 'warn',
 *     action: { label: 'Undo', onClick: restore }, timeout: 8000, onTimeout: commit });
 *
 * @package MCN_Animations
 */

.anim-toasts {
	--toast-bg: #14181f;
	--toast-ink: #eef2f8;
	--toast-mut: #9aa3b2;
	--toast-line: rgba(255, 255, 255, 0.08);
	--toast-ok: #2f9e6b;
	--toast-err: #d2453c;
	--toast-warn: #b0791b;
	--toast-info: #3a6ea8;
	position: fixed;
	z-index: 9999;
	right: max(16px, env(safe-area-inset-right));
	bottom: max(16px, env(safe-area-inset-bottom));
	display: flex;
	flex-direction: column-reverse;
	gap: 10px;
	width: min(360px, calc(100vw - 32px));
	pointer-events: none;
}

.anim-toasts--start { right: auto; left: max(16px, env(safe-area-inset-left)); }
.anim-toasts--top   { bottom: auto; top: max(16px, env(safe-area-inset-top)); flex-direction: column; }

/* Light sites: the plate follows the page, not the other way round. */
@media (prefers-color-scheme: light) {
	.anim-toasts {
		--toast-bg: #ffffff;
		--toast-ink: #1b2130;
		--toast-mut: #5b6472;
		--toast-line: rgba(20, 24, 32, 0.12);
	}
}

.anim-toast {
	position: relative;
	display: grid;
	grid-template-columns: auto 1fr auto;
	align-items: start;
	gap: 12px;
	padding: 13px 14px 15px;
	border-radius: 12px;
	border: 1px solid var(--toast-line);
	background: var(--toast-bg);
	color: var(--toast-ink);
	box-shadow: 0 14px 34px -16px rgba(0, 0, 0, 0.7);
	pointer-events: auto;
	overflow: hidden;
}

/* Enter/exit are transform+opacity only. .is-in is set on the next frame. */
.js-anim .anim-toast {
	opacity: 0;
	transform: translate3d(0, 14px, 0) scale(0.97);
	transition:
		transform var(--anim-duration) var(--anim-ease-overshoot),
		opacity var(--anim-duration-fast) var(--anim-ease);
}

.js-anim .anim-toast.is-in { opacity: 1; transform: none; }

.js-anim .anim-toast.is-out {
	opacity: 0;
	transform: translate3d(24px, 0, 0) scale(0.97);
}

.anim-toast__icon {
	display: grid;
	place-items: center;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	background: var(--toast-tone, var(--toast-info));
	color: #fff;
}

.anim-toast__icon svg { width: 13px; height: 13px; }

.anim-toast--success { --toast-tone: var(--toast-ok); }
.anim-toast--error   { --toast-tone: var(--toast-err); }
.anim-toast--warn    { --toast-tone: var(--toast-warn); }
.anim-toast--info    { --toast-tone: var(--toast-info); }

.anim-toast__body { min-width: 0; }
.anim-toast__title { font-weight: 650; line-height: 1.25; }
.anim-toast__text  { margin-top: 2px; font-size: 0.86em; color: var(--toast-mut); }

.anim-toast__actions {
	display: flex;
	align-items: center;
	gap: 6px;
}

.anim-toast__action,
.anim-toast__close {
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	cursor: pointer;
	border-radius: 7px;
}

.anim-toast__action {
	padding: 6px 11px;
	font-weight: 700;
	font-size: 0.86em;
	letter-spacing: 0.03em;
	color: var(--toast-tone, var(--toast-info));
	background: color-mix(in srgb, var(--toast-tone, var(--toast-info)) 16%, transparent);
	transition: transform var(--anim-duration-fast) var(--anim-ease-overshoot), background-color var(--anim-duration-fast);
}

.anim-toast__action:hover { background: color-mix(in srgb, var(--toast-tone, var(--toast-info)) 26%, transparent); }
.anim-toast__action:active { transform: scale(0.94); }

.anim-toast__close {
	width: 28px;
	height: 28px;
	display: grid;
	place-items: center;
	color: var(--toast-mut);
	font-size: 18px;
	line-height: 1;
}

.anim-toast__close:hover { color: var(--toast-ink); }

.anim-toast__action:focus-visible,
.anim-toast__close:focus-visible {
	outline: var(--anim-focus-width) solid var(--anim-focus-color);
	outline-offset: 2px;
}

/* Auto-dismiss bar. The animation IS the clock, so pausing it pauses the
   dismissal — hover, focus-within and a hidden tab all pause it (2.2.2). */
.anim-toast__life {
	position: absolute;
	left: 0;
	bottom: 0;
	height: 3px;
	width: 100%;
	transform-origin: left center;
	background: var(--toast-tone, var(--toast-info));
	opacity: 0.55;
	animation: anim-toast-life var(--toast-life, 5000ms) linear forwards;
}

.anim-toast:hover .anim-toast__life,
.anim-toast:focus-within .anim-toast__life,
.anim-toast.is-paused .anim-toast__life { animation-play-state: paused; }

@keyframes anim-toast-life {
	from { transform: scaleX(1); }
	to   { transform: scaleX(0); }
}

@media (prefers-reduced-motion: reduce) {

	.js-anim .anim-toast {
		transition: none !important;
		opacity: 1;
		transform: none;
	}

	.js-anim .anim-toast.is-out { opacity: 0; }

	.anim-toast__action { transition: none !important; }

	/* The bar still times out; it just doesn't slide. */
	.anim-toast__life { animation-timing-function: step-end; }
}

@media (forced-colors: active) {
	.anim-toast { border-color: CanvasText; }
	.anim-toast__icon { background: CanvasText; color: Canvas; }
	.anim-toast__life { background: Highlight; }
}

/* --------------------------------------------------------------------------
 * Tooltip — .anim-tip
 *
 * Studied from forevercomponents.com ("Tooltip Pop") and rebuilt. Theirs is a
 * div that appears on pointerenter: no keyboard access, no Escape, no ARIA, and
 * it auto-pops on a loop. This is the criterion those fail, WCAG 1.4.13
 * (Content on Hover or Focus), and the reason the card module carries a comment
 * telling you not to build a detached floating tooltip:
 *
 *   DISMISSIBLE  Escape closes it without moving the pointer (JS).
 *   HOVERABLE    the bubble is a CHILD of the trigger and its hit area reaches
 *                back to the trigger, so the pointer never crosses a gap.
 *   PERSISTENT   it stays while hovered or focused; nothing times it out.
 *
 * The bubble also stays in the accessibility tree while hidden (opacity, never
 * visibility or display), because `aria-describedby` points at it: hiding it
 * the other way would take the description away from a screen reader.
 *
 * Usage (fx.js builds the bubble, so the builder tree stays clean):
 *   <button class="anim-tip" data-anim-tip="Move this case forward">…</button>
 *   <span class="anim-tip" data-anim-tip-from="#gfield_description_4_1">?</span>
 *   data-anim-tip-place="bottom" flips it under the trigger.
 * ----------------------------------------------------------------------- */

.anim-tip {
	position: relative;
	overflow: visible;
}

.anim-tip__bubble {
	position: absolute;
	left: 50%;
	bottom: calc(100% + 10px);
	z-index: 50;
	width: max-content;
	max-width: min(260px, 70vw);
	padding: 7px 11px;
	border-radius: 8px;
	background: var(--anim-tip-bg, #14181f);
	color: var(--anim-tip-ink, #f4f6fb);
	font-size: 0.8rem;
	font-weight: 500;
	line-height: 1.35;
	text-align: left;
	white-space: normal;
	box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
	opacity: 0;
	pointer-events: none;
	transform: translateX(-50%) translateY(6px) scale(0.92);
	transform-origin: bottom center;
	transition:
		opacity var(--anim-duration-fast) var(--anim-ease),
		transform var(--anim-duration) var(--anim-ease-overshoot);
}

/* The notch, plus the bridge that makes "hoverable" true: an invisible band
   spanning the gap so the pointer can travel into the bubble. */
.anim-tip__bubble::after,
.anim-tip__bubble::before {
	content: "";
	position: absolute;
	/* Back out the nudge so the notch still points at the trigger. */
	left: 50%;
	transform: translateX(-50%);
}

.anim-tip__bubble::after {
	top: 100%;
	border: 6px solid transparent;
	border-top-color: var(--anim-tip-bg, #14181f);
}

.anim-tip__bubble::before {
	top: 100%;
	width: 100%;
	height: 12px;
}

.anim-tip:hover > .anim-tip__bubble,
.anim-tip:focus-visible > .anim-tip__bubble,
.anim-tip:focus-within > .anim-tip__bubble,
.anim-tip.is-tip-open > .anim-tip__bubble {
	opacity: 1;
	pointer-events: auto;
	transform: translateX(-50%) scale(1);
}

/* Near the right edge the bubble anchors to the trigger rather than centring on
   it: centred, it would hang past the viewport and give the page a sideways
   scroll even while hidden, because a hidden bubble still takes up layout. The
   runtime adds the class, and the notch moves with it. */
.anim-tip--end > .anim-tip__bubble {
	left: auto;
	right: -4px;
	transform: translateY(6px) scale(0.92);
}

.anim-tip--end:hover > .anim-tip__bubble,
.anim-tip--end:focus-visible > .anim-tip__bubble,
.anim-tip--end:focus-within > .anim-tip__bubble,
.anim-tip--end.is-tip-open > .anim-tip__bubble {
	transform: translateY(0) scale(1);
}

.anim-tip--end > .anim-tip__bubble::after,
.anim-tip--end > .anim-tip__bubble::before {
	left: auto;
	right: 6px;
	transform: none;
}

.anim-tip--end > .anim-tip__bubble::before { width: 24px; }

/* Escape sets this; it wins over hover until the pointer leaves or focus moves. */
.anim-tip.is-tip-dismissed > .anim-tip__bubble {
	opacity: 0;
	pointer-events: none;
}

/* Below the trigger instead of above. */
.anim-tip[data-anim-tip-place="bottom"] > .anim-tip__bubble {
	bottom: auto;
	top: calc(100% + 10px);
	transform-origin: top center;
	transform: translateX(-50%) translateY(-6px) scale(0.92);
}

.anim-tip[data-anim-tip-place="bottom"] > .anim-tip__bubble::after {
	top: auto;
	bottom: 100%;
	border-top-color: transparent;
	border-bottom-color: var(--anim-tip-bg, #14181f);
}

.anim-tip[data-anim-tip-place="bottom"] > .anim-tip__bubble::before {
	top: auto;
	bottom: 100%;
}

.anim-tip[data-anim-tip-place="bottom"]:hover > .anim-tip__bubble,
.anim-tip[data-anim-tip-place="bottom"]:focus-visible > .anim-tip__bubble,
.anim-tip[data-anim-tip-place="bottom"]:focus-within > .anim-tip__bubble,
.anim-tip[data-anim-tip-place="bottom"].is-tip-open > .anim-tip__bubble {
	transform: translateX(-50%) scale(1);
}

/* The injected help trigger the Gravity Forms bridge puts beside a label. */
.anim-tip--help {
	display: inline-grid;
	place-items: center;
	width: 18px;
	height: 18px;
	margin-inline-start: 6px;
	padding: 0;
	border: 1px solid currentColor;
	border-radius: 50%;
	background: none;
	color: inherit;
	font-size: 0.68em;
	font-weight: 700;
	line-height: 1;
	cursor: help;
	opacity: 0.75;
	vertical-align: middle;
}

.anim-tip--help:hover,
.anim-tip--help:focus-visible { opacity: 1; }

.anim-tip:focus-visible {
	outline: var(--anim-focus-width) solid var(--anim-focus-color);
	outline-offset: var(--anim-focus-offset);
}

@media (prefers-reduced-motion: reduce) {
	.anim-tip__bubble { transition: none !important; transform: translateX(-50%) scale(1); }
	.anim-tip[data-anim-tip-place="bottom"] > .anim-tip__bubble { transform: translateX(-50%) scale(1); }
}

@media (forced-colors: active) {
	.anim-tip__bubble { border: 1px solid CanvasText; background: Canvas; color: CanvasText; }
	.anim-tip__bubble::after { border-top-color: CanvasText; }
}
