/* ===== SGS Toast — the one shared transient feedback surface =====
 *
 * Paired with includes/class-sgs-toast.php (markup) and
 * src/shared/toast/store.js (behaviour).
 *
 * Variant colours, the 44px close button and the focus ring are the same
 * tokens and sizings sgs/notice-banner uses, so the toast reads as part of
 * the same system. Every value resolves from a theme.json preset with a
 * literal only as the no-theme fallback.
 *
 * A site restyles the toast from theme.json `settings.custom.toast.*`
 * (WordPress prints each as `--wp--custom--toast--<kebab-name>`). Unset keys
 * fall back to the look below, so nothing changes for a site that sets none.
 * Keys: background, colour, borderColour, borderWidth, radius, padding,
 * gap, fontSize, shadow, offsetBottom, duration, iconBackground, iconColour, iconRadius, iconBox,
 * iconSize, actionColour, actionWeight, actionPadding, actionHoverBackground,
 * actionFontSize, actionUnderlineColour, actionHoverUnderlineThickness.
 *
 * The wrapper is NEVER display:none, visibility:hidden or [hidden]: its
 * message paragraph is a role="status" live region, and any of those three
 * would drop it out of the accessibility tree and silence every
 * announcement. It hides by opacity, and the two focusable controls inside
 * carry a bound `hidden` attribute instead.
 */

.sgs-toast {
	position: fixed;
	z-index: 100000;
	inset-block-end: var(--wp--custom--toast--offset-bottom, var(--wp--preset--spacing--30, 1rem));
	inset-inline: var(--wp--preset--spacing--30, 1rem);
	margin-inline: auto;
	width: fit-content;
	max-width: min(30rem, calc(100vw - 2rem));

	display: flex;
	align-items: center;
	gap: var(--wp--custom--toast--gap, var(--wp--preset--spacing--20, 0.75rem));
	padding: var(--wp--custom--toast--padding, var(--wp--preset--spacing--20, 0.75rem) var(--wp--preset--spacing--30, 1rem));

	border: var(--wp--custom--toast--border-width, 1px) solid transparent;
	border-radius: var(--wp--custom--toast--radius, var(--wp--custom--border-radius--medium, 8px));
	box-shadow: var(--wp--custom--toast--shadow, 0 6px 24px rgba(0, 0, 0, 0.14));

	background-color: var(--wp--custom--toast--background, var(--wp--preset--color--surface, #faf9f6));
	/* #1f2937 reaches 4.5:1 on both variant tints below. */
	color: var(--wp--custom--toast--colour, var(--wp--preset--color--text, #1f2937));

	opacity: 0;
	pointer-events: none;

	/* The one motion the toast plays while it shows: the timing is set here
	   so src/shared/toast/store.js can read the duration and close the toast
	   when the motion ends. */
	animation-duration: var(--wp--custom--toast--duration, 5s);
	animation-timing-function: cubic-bezier(0.2, 0.7, 0.2, 1);
	animation-fill-mode: both;
}

/* Success — sgs/notice-banner's success tint and border token. */
.sgs-toast--success {
	background-color: var(--wp--custom--toast--background, var(--wp--preset--color--success-light, #ecfdf5));
	border-color: var(--wp--custom--toast--border-colour, var(--wp--preset--color--success, #2e7d4f));
}

/* Error — sgs/notice-banner's error tint and border token. Colour is never
   the only carrier: the icon changes to circle-x alongside it. */
.sgs-toast--error {
	background-color: var(--wp--custom--toast--background, var(--wp--preset--color--error-light, #fef2f2));
	border-color: var(--wp--custom--toast--border-colour, var(--wp--preset--color--error, #dc2626));
}

.sgs-toast--visible {
	opacity: 1;
	pointer-events: auto;
}

/* Motion only when the store has confirmed the visitor has not asked for
   reduced motion (state.isAnimated adds this class). A success toast rises
   16px into place while fading in over the first 12% of its life, holds,
   then fades out over the last 15% while drifting half its own width to the
   right. Hovering or focusing the toast holds the motion, as the store's
   auto-close timer is held. An error toast has no auto-close, so it plays
   only the rise and fade in (the same 12% of the life) and stays. */
.sgs-toast--success.sgs-toast--animated.sgs-toast--visible {
	animation-name: sgs-toast-life;
}

.sgs-toast--error.sgs-toast--animated.sgs-toast--visible {
	animation-name: sgs-toast-in;
	animation-duration: calc(var(--wp--custom--toast--duration, 5s) * 0.12);
}

.sgs-toast--animated.sgs-toast--visible:hover,
.sgs-toast--animated.sgs-toast--visible:focus-within {
	animation-play-state: paused;
}

@keyframes sgs-toast-life {
	0% {
		opacity: 0;
		transform: translate(0, 16px);
	}
	12% {
		opacity: 1;
		transform: translate(0, 0);
	}
	85% {
		opacity: 1;
	}
	100% {
		opacity: 0;
		transform: translate(50%, 0);
	}
}

@keyframes sgs-toast-in {
	0% {
		opacity: 0;
		transform: translate(0, 16px);
	}
	100% {
		opacity: 1;
		transform: translate(0, 0);
	}
}

/* `hidden` must win over every display rule below it. The UA's own
   `[hidden] { display: none }` has lower specificity than a class, so the
   icons' and controls' `display: inline-flex` would otherwise keep a hidden
   element painted and (for the two controls) focusable. */
.sgs-toast [hidden] {
	display: none;
}

/* ===== Icon ===== */

.sgs-toast__icon {
	flex-shrink: 0;
	display: inline-flex;
	line-height: 1;
}

.sgs-toast__icon svg {
	width: var(--wp--custom--toast--icon-size, 22px);
	height: var(--wp--custom--toast--icon-size, 22px);
	display: block;
}

/* An optional disc behind the glyph: iconBackground fills it, iconBox sizes
   it (auto = the glyph's own size) and iconRadius rounds it. */
.sgs-toast__icon--success {
	align-items: center;
	justify-content: center;
	width: var(--wp--custom--toast--icon-box, auto);
	height: var(--wp--custom--toast--icon-box, auto);
	border-radius: var(--wp--custom--toast--icon-radius, 0);
	background-color: var(--wp--custom--toast--icon-background, transparent);
	color: var(--wp--custom--toast--icon-colour, var(--wp--preset--color--success, #2e7d4f));
}

.sgs-toast__icon--error {
	color: var(--wp--preset--color--error, #dc2626);
}

/* ===== Message ===== */

.sgs-toast__message {
	margin: 0;
	flex: 1 1 auto;
	font-size: var(--wp--custom--toast--font-size, var(--wp--preset--font-size--small, 0.9375rem));
	line-height: 1.4;
}

/* ===== "View bag" action =====
 * Underlined and in the toast's own body colour, so it clears 4.5:1 in both
 * variants without depending on an accent token's contrast against a tint.
 */

.sgs-toast__action {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	min-height: 44px;
	padding-inline: var(--wp--custom--toast--action-padding, var(--wp--preset--spacing--20, 0.75rem));
	border-radius: var(--wp--custom--border-radius--small, 4px);
	color: var(--wp--custom--toast--action-colour, inherit);
	font-size: var(--wp--custom--toast--action-font-size, var(--wp--preset--font-size--small, 0.9375rem));
	font-weight: var(--wp--custom--toast--action-weight, 600);
	text-decoration: underline;
	text-decoration-color: var(--wp--custom--toast--action-underline-colour, currentcolor);
	text-underline-offset: 3px;
}

/* Hover BRIGHTENS: a white wash lifts the tint while the dark label stays
   put, so contrast only ever improves. */
.sgs-toast__action:hover {
	background-color: var(--wp--custom--toast--action-hover-background, rgba(255, 255, 255, 0.65));
	color: var(--wp--custom--toast--action-colour, inherit);
	text-decoration-thickness: var(--wp--custom--toast--action-hover-underline-thickness, 2px);
}

/* ===== Close button ===== */

.sgs-toast__close {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	min-height: 44px;
	padding: 0;
	margin-inline-end: calc(var(--wp--preset--spacing--20, 0.75rem) * -0.5);
	background: none;
	border: none;
	border-radius: var(--wp--custom--border-radius--small, 4px);
	color: inherit;
	cursor: pointer;
}

.sgs-toast__close:hover {
	background-color: rgba(255, 255, 255, 0.65);
}

/* ===== Reduced motion =====
 * The CSS half of the contract, so the preference holds even before
 * src/shared/toast/store.js evaluates. The toast still appears and still
 * announces — it simply arrives without the slide or the fade.
 */
@media (prefers-reduced-motion: reduce) {
	.sgs-toast,
	.sgs-toast--animated.sgs-toast--visible {
		animation: none;
	}
}

/* ===== Narrow viewports =====
 * Stays one compact row at its natural width, like the wider screens. A long
 * message wraps inside its own text box, and the toast never runs past the
 * screen (the base max-width keeps the 1rem edge inset).
 */
@media (max-width: 480px) {
	.sgs-toast__message {
		min-width: 0;
	}
}
