/*
 * monoNotices storefront styles. Prefix: mn-.
 *
 * Every notice is first an inline banner (works with no JavaScript). notices.js lifts toasts into a fixed layer
 * (.mn-layer) and modals into a backdrop (.mn-backdrop); the rules for those only apply once the notice is inside one.
 *
 * Colour tokens live on .mn-notice and are checked by tests/ContrastTest.php (text 4.5:1, icon/border 3:1, light and dark).
 * The settings add per-type overrides after this file (Style::css): radius, width, shadow, and a colour set derived
 * from the chosen accent.
 */

.mn-notice {
	--mn-surface: #ffffff;
	--mn-ink: #0f172a;
	--mn-ok: #15803d;
	--mn-on-ok: #ffffff;
	--mn-info: #1d4ed8;
	--mn-on-info: #ffffff;
	--mn-bad: #b91c1c;
	--mn-on-bad: #ffffff;
	--mn-neutral: #111827;
	--mn-on-neutral: #ffffff;
}

.mn-notice[data-scheme="dark"] {
	--mn-surface: #1e293b;
	--mn-ink: #f1f5f9;
	--mn-ok: #4ade80;
	--mn-on-ok: #052e16;
	--mn-info: #93c5fd;
	--mn-on-info: #0f172a;
	--mn-bad: #fca5a5;
	--mn-on-bad: #3b0a0a;
	--mn-neutral: #e2e8f0;
	--mn-on-neutral: #0f172a;
}

@media (prefers-color-scheme: dark) {
	.mn-notice[data-scheme="auto"] {
		--mn-surface: #1e293b;
		--mn-ink: #f1f5f9;
		--mn-ok: #4ade80;
		--mn-on-ok: #052e16;
		--mn-info: #93c5fd;
		--mn-on-info: #0f172a;
		--mn-bad: #fca5a5;
		--mn-on-bad: #3b0a0a;
		--mn-neutral: #e2e8f0;
		--mn-on-neutral: #0f172a;
	}
}

/* Semantic defaults per type. The settings override these through --mn-accent, --mn-on-accent and --mn-accent-ui. */
.mn-notice--success { --mn-accent: var(--mn-ok); --mn-on-accent: var(--mn-on-ok); --mn-accent-ui: var(--mn-ok); }
.mn-notice--info { --mn-accent: var(--mn-info); --mn-on-accent: var(--mn-on-info); --mn-accent-ui: var(--mn-info); }
.mn-notice--error { --mn-accent: var(--mn-bad); --mn-on-accent: var(--mn-on-bad); --mn-accent-ui: var(--mn-bad); }
.mn-notice--cart { --mn-accent: var(--mn-neutral); --mn-on-accent: var(--mn-on-neutral); --mn-accent-ui: var(--mn-neutral); }

/* The extra selectors are WooCommerce's own notice classes, which stay on the element for its scripts: this beats their box styles. */
.mn-notice,
.mn-notice.woocommerce-message,
.mn-notice.woocommerce-info,
.mn-notice.woocommerce-error {
	box-sizing: border-box;
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: start;
	gap: 0.5rem 0.75rem;
	margin: 0 0 1rem;
	padding: 0.875rem 1rem;
	list-style: none;
	font: inherit;
	font-size: 1rem;
	line-height: 1.5;
	color: var(--mn-ink);
	background: var(--mn-surface);
	background: color-mix(in srgb, var(--mn-accent) 7%, var(--mn-surface));
	border: 1px solid color-mix(in srgb, var(--mn-ink) 14%, transparent);
	border-inline-start: 4px solid var(--mn-accent-ui);
	border-radius: var(--mn-radius, 10px);
	box-shadow: var(--mn-shadow, none);
	text-align: start;
}

.mn-notice--no-icon { grid-template-columns: minmax(0, 1fr) auto; }

/* WooCommerce's stylesheet draws an icon font glyph in front of these classes. */
.mn-notice::before,
.mn-notice::after { content: none; display: none; }

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

.mn-notice__icon {
	width: 1.25rem;
	height: 1.25rem;
	margin-top: 0.2rem;
	color: var(--mn-accent-ui);
}

.mn-notice__body { min-width: 0; overflow-wrap: anywhere; }

.mn-notice__text,
.mn-notice__list { margin: 0; padding: 0; color: inherit; }
.mn-notice__list { padding-inline-start: 1.1rem; }
.mn-notice__list li { margin: 0.15rem 0; }
.mn-notice a { color: inherit; text-decoration: underline; }
.mn-notice a.mn-button { text-decoration: none; }

.mn-notice__actions { grid-column: 2; }
.mn-notice--no-icon .mn-notice__actions { grid-column: 1; }

.mn-notice__close {
	grid-column: -2 / -1;
	grid-row: 1;
	justify-self: end;
	min-width: 2rem;
	min-height: 2rem;
	margin: -0.25rem -0.4rem 0 0;
	padding: 0;
	font: inherit;
	font-size: 1.5rem;
	line-height: 1;
	color: var(--mn-ink);
	background: transparent;
	border: 0;
	border-radius: 6px;
	cursor: pointer;
}
.mn-notice__close:hover { background: color-mix(in srgb, var(--mn-ink) 10%, transparent); }

.mn-notice__footer {
	grid-column: 1 / -1;
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	padding-top: 0.25rem;
}

.mn-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 2.5rem;
	padding: 0.4rem 1rem;
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
	cursor: pointer;
	border: 1px solid var(--mn-accent-ui);
	border-radius: calc(var(--mn-radius, 10px) * 0.7);
}
.mn-notice a.mn-button--primary,
.mn-button--primary { color: var(--mn-on-accent); background: var(--mn-accent); }
.mn-notice a.mn-button--secondary,
.mn-button--secondary { color: var(--mn-ink); background: transparent; border-color: var(--mn-ink); }
.mn-button:hover { filter: brightness(1.08); }

/* Visible focus on any background: an ink outline with a surface-coloured gap. */
.mn-notice :focus-visible {
	outline: 2px solid var(--mn-ink);
	outline-offset: 2px;
	box-shadow: 0 0 0 4px var(--mn-surface);
}

/*
 * Inline means in the page flow, on any theme. Some themes (eGateway) turn WooCommerce's notice wrapper into a fixed
 * bottom-right overlay, which would float an "inline" banner over form fields. Where the wrapper holds one of our notices
 * it goes back to being an ordinary block. notices.js adds .mn-flow for browsers without :has(). Toasts and modals do not
 * depend on the wrapper: they are lifted into .mn-layer / .mn-backdrop, which are fixed on their own.
 */
.woocommerce-notices-wrapper:has(> .mn-notice),
.woocommerce-notices-wrapper.mn-flow {
	position: static !important;
	inset: auto !important;
	z-index: auto !important;
	width: auto !important;
	max-width: none !important;
	transform: none !important;
}

/* ---- toast ---------------------------------------------------------------------------------------------- */

.mn-layer {
	position: fixed;
	z-index: 100000;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	max-width: 100%;
	padding: 1rem;
	pointer-events: none; /* the layer itself never blocks the page; only the toasts take clicks */
}
.mn-layer[data-pos^="top"] { top: 0; }
.mn-layer[data-pos^="bottom"] { bottom: 0; }
.mn-layer[data-pos$="left"] { left: 0; align-items: flex-start; }
.mn-layer[data-pos$="right"] { right: 0; align-items: flex-end; }
.mn-layer[data-pos$="center"] { left: 0; right: 0; align-items: center; }
body.admin-bar .mn-layer[data-pos^="top"] { top: 32px; }
@media (max-width: 782px) {
	body.admin-bar .mn-layer[data-pos^="top"] { top: 46px; }
}

.mn-layer .mn-notice {
	width: min(var(--mn-width, 480px), calc(100vw - 2rem));
	margin: 0;
	pointer-events: auto;
	animation: mn-in 0.2s ease-out;
}

/* ---- modal ---------------------------------------------------------------------------------------------- */

.mn-backdrop {
	position: fixed;
	inset: 0;
	z-index: 100001;
	display: grid;
	place-items: center;
	padding: 1rem;
	background: rgba(15, 23, 42, 0.55);
	animation: mn-fade 0.2s ease-out;
}
.mn-backdrop .mn-notice {
	width: min(var(--mn-width, 480px), 100%);
	max-height: calc(100vh - 2rem);
	margin: 0;
	overflow: auto;
}
html.mn-lock { overflow: hidden; }

.mn-notice.is-leaving { opacity: 0; transform: translateY(-4px); transition: opacity 0.18s ease, transform 0.18s ease; }

@keyframes mn-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes mn-fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
	.mn-layer .mn-notice,
	.mn-backdrop { animation: none; }
	.mn-notice.is-leaving { transition: none; }
}

/* The two persistent live regions notices.js announces through: present for screen readers, invisible and out of the way for everyone else. */
.mn-live {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* Windows high contrast: keep a real border and visible controls whatever accent colours are set. */
@media (forced-colors: active) {
	.mn-notice { border: 1px solid CanvasText; border-inline-start-width: 4px; }
	.mn-button, .mn-notice__close { border: 1px solid ButtonText; }
	.mn-notice__icon { color: CanvasText; }
}

/* A placeholder left behind where a lifted notice used to be; it takes no room. */
.mn-ph { display: none; }

/* The hidden marker WooCommerce's add-to-cart message may still carry, and the AJAX fragment. */
.mn-atc-marker,
.mn-atc-fragment { display: none; }
