/**
 * VSDM - Very Simple Dark Mode - front-end stylesheet.
 * The variable VALUES are injected inline (see VSDM_Frontend::inline_variables).
 *
 * Strategy
 * --------
 * Elementor writes most backgrounds into GENERATED css files, not inline styles,
 * so they cannot be matched by attribute selectors. Worse, blindly clearing all
 * container backgrounds also destroys legitimate "card" surfaces (a white box
 * sitting on a background image, etc.).
 *
 * So the companion script (dark-mode.js) reads each element's ORIGINAL (light)
 * background once and tags every element that has a LIGHT background with the
 * class .vsdm-surface. Here we simply repaint those surfaces with the dark
 * palette. Elements that were transparent stay transparent (the dark page shows
 * through); background IMAGES and intentionally dark / colored sections are left
 * untouched.
 */

html.vsdm-dark,
html.vsdm-dark body,
html.vsdm-light,
html.vsdm-light body {
	transition: background-color .25s ease, color .25s ease;
}

/* Native browser parts (scrollbars, checkboxes, select popups, date pickers)
   follow the active scheme. */
html.vsdm-dark { color-scheme: dark; }
html.vsdm-light { color-scheme: light; }

/* Visitors who ask the system for less motion get instant switches. */
@media (prefers-reduced-motion: reduce) {
	html.vsdm-dark,
	html.vsdm-dark body,
	html.vsdm-light,
	html.vsdm-light body,
	.vsdm-toggle--floating {
		transition: none !important;
	}
	.vsdm-toggle--floating:hover {
		transform: none !important;
	}
}

/* Measurement freeze: while the engine reads computed backgrounds it must not
   see in-flight transition values (Elementor puts background transitions on
   containers). dark-mode.js toggles this class around every measuring pass. */
html.vsdm-measure,
html.vsdm-measure * {
	transition: none !important;
	animation: none !important;
}

/* --- Opt-out: .vsdm-ignore ---
   Any element carrying .vsdm-ignore keeps its native look in the alternate
   scheme, together with everything inside it: no surface repaint, no text or
   field recolouring (dark-mode.js also skips it in the contrast pass).
   Every scheme rule below ends with :not(:where(.vsdm-ignore, .vsdm-ignore *)):
   :where() has zero specificity, so the rules keep exactly the specificity
   they had before 0.3.1. Note: the admin "custom CSS" is NOT filtered. */

/* --- Page base (both alternate schemes consume the same variables) --- */
html.vsdm-dark body,
html.vsdm-light body {
	background-color: var(--vsdm-bg-page) !important;
	color: var(--vsdm-text);
}

html.vsdm-dark :is(h1, h2, h3, h4, h5, h6):not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-light :is(h1, h2, h3, h4, h5, h6):not(:where(.vsdm-ignore, .vsdm-ignore *)) {
	color: var(--vsdm-heading, var(--vsdm-text));
}

html.vsdm-dark :is(p, li, td, th):not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-light :is(p, li, td, th):not(:where(.vsdm-ignore, .vsdm-ignore *)) {
	color: var(--vsdm-text-soft);
}

/* --- Native-scheme surfaces detected by dark-mode.js -> alternate card --- */
html.vsdm-dark .vsdm-surface:not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-light .vsdm-surface:not(:where(.vsdm-ignore, .vsdm-ignore *)) {
	background-color: var(--vsdm-bg-card) !important;
	border-color: var(--vsdm-border) !important;
}

/* Surfaces whose native background was a CSS gradient: drop the gradient too. */
html.vsdm-dark .vsdm-surface--flat:not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-light .vsdm-surface--flat:not(:where(.vsdm-ignore, .vsdm-ignore *)) {
	background-image: none !important;
}

/* --- Sticky-on-scroll header (Elementor native) safety: stay solid --- */
html.vsdm-dark .elementor-sticky--effects,
html.vsdm-light .elementor-sticky--effects {
	background-color: var(--vsdm-bg-page) !important;
}

/* --- Form fields ---
   !important: Elementor Pro form widgets style their fields with much higher
   specificity (per-element selectors), which would keep e.g. dark inputs on a
   light card after the scheme switch. */
html.vsdm-dark input:not([type="submit"]):not([type="button"]):not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-dark textarea:not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-dark select:not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-dark .elementor-field-group .elementor-field:not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-light input:not([type="submit"]):not([type="button"]):not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-light textarea:not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-light select:not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-light .elementor-field-group .elementor-field:not(:where(.vsdm-ignore, .vsdm-ignore *)) {
	background-color: var(--vsdm-bg-elevated) !important;
	color: var(--vsdm-text) !important;
	border-color: var(--vsdm-border) !important;
}

/* Field labels: the repaint above covers the inputs themselves, but a
   label carries its own colour (Elementor Pro writes one per widget), so
   it would stay dark on a dark card. */
html.vsdm-dark label:not(:where(.vsdm-ignore, .vsdm-ignore *)),
html.vsdm-light label:not(:where(.vsdm-ignore, .vsdm-ignore *)) {
	color: var(--vsdm-text) !important;
}

html.vsdm-dark :not(:where(.vsdm-ignore, .vsdm-ignore *))::placeholder,
html.vsdm-light :not(:where(.vsdm-ignore, .vsdm-ignore *))::placeholder {
	color: var(--vsdm-text-soft);
	opacity: .8;
}

/* ============================================================
   TOGGLE BUTTON
   ============================================================ */
/* !important shields the widget from theme/kit global button styles
   (Elementor kits style bare <button> elements with higher specificity). */
.vsdm-toggle--floating {
	position: fixed;
	z-index: 99990;
	width: 48px !important;
	height: 48px !important;
	padding: 0 !important;
	border: none !important;
	border-radius: 50% !important;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--vsdm-tg-bg, #1e1e1e) !important;
	color: var(--vsdm-tg-fg, #ffffff) !important;
	box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
	transition: transform .2s ease, background .2s ease, color .2s ease;
}

.vsdm-toggle--floating:hover {
	transform: scale(1.08);
}

.vsdm-pos-bottom-right { bottom: 24px; right: 24px; }
.vsdm-pos-bottom-left  { bottom: 24px; left: 24px; }
.vsdm-pos-top-right    { top: 24px; right: 24px; }
.vsdm-pos-top-left     { top: 24px; left: 24px; }

/* Icons: always show the scheme you can switch TO.
   Light site: moon at rest (go dark), sun while dark. */
.vsdm-toggle .vsdm-icon { font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.vsdm-toggle .vsdm-icon svg { width: 22px; height: 22px; display: block; }
.vsdm-toggle .vsdm-icon--sun { display: none; }
.vsdm-toggle .vsdm-icon--moon { display: flex; }
html.vsdm-dark .vsdm-toggle .vsdm-icon--sun { display: flex; }
html.vsdm-dark .vsdm-toggle .vsdm-icon--moon { display: none; }

/* Dark site (.vsdm-base-dark on the toggle): sun at rest (go light), moon while light. */
.vsdm-toggle.vsdm-base-dark .vsdm-icon--sun { display: flex; }
.vsdm-toggle.vsdm-base-dark .vsdm-icon--moon { display: none; }
html.vsdm-light .vsdm-toggle.vsdm-base-dark .vsdm-icon--sun { display: none; }
html.vsdm-light .vsdm-toggle.vsdm-base-dark .vsdm-icon--moon { display: flex; }

/* Toggle placed inside a menu (link with the .vsdm-toggle class): no floating style. */
a.vsdm-toggle { cursor: pointer; }

/* [vsdm_toggle] shortcode: a bare icon button taking the surrounding text
   color. !important for the same reason as the floating button (kit styles
   on bare <button> elements). Size via the shortcode "size" attribute. */
.vsdm-toggle--inline {
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	vertical-align: middle;
	padding: 0 !important;
	margin: 0;
	border: none !important;
	background: none !important;
	box-shadow: none !important;
	color: inherit !important;
	cursor: pointer;
	line-height: 1 !important;
	min-height: 0 !important;
}
.vsdm-toggle--inline .vsdm-icon { font-size: var(--vsdm-inline-size, 20px); }
.vsdm-toggle--inline .vsdm-icon svg {
	width: var(--vsdm-inline-size, 20px);
	height: var(--vsdm-inline-size, 20px);
}
.vsdm-toggle--inline:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}
