/**
 * Frontend design tokens.
 *
 * Every colour this plugin paints on the storefront resolves through here, and
 * each token chains through the ACTIVE THEME'S own tokens before falling back
 * to a hex. That is what makes the plugin follow the store: an owner sets their
 * brand once at theme level and these panels follow it, instead of staying
 * Wbcom-blue on a green store.
 *
 * It is also what makes dark mode almost free. BuddyX and Reign each flip their
 * own tokens at their own dark root; because ours resolve to theirs, ours flip
 * with them and no plugin dark-mode CSS runs at all. The block at the bottom is
 * only a fallback for themes with no dark tokens of their own.
 *
 * The two vocabularies are genuinely different and mutually exclusive - Reign
 * defines no --bx-* and BuddyX defines no --reign-* - so the chain tries both.
 * Only one theme is active at a time, so the other's variables are undefined
 * and fall through cleanly.
 *
 * Variable names are taken from the verified Wbcom host-theme map rather than
 * from memory. Re-check after a theme bump with:
 *   grep -rhoE '\-\-bx-color-[a-z-]+' wp-content/themes/buddyx | sort -u
 *
 * @package Woocommerce_Price_Quote
 * @since   2.1.1
 */

/*
 * BLOCK THEMES: `contrast` / `base` are the last resort, and they pair.
 *
 * Twenty Twenty-Five - the WordPress default - defines neither
 * --wp--preset--color--primary nor --accent. It defines `contrast` (#111111)
 * and `base` (#FFFFFF), and WooCommerce draws Add to cart with exactly those.
 * Without them in the chain this plugin fell through to its own hex and drew a
 * BLUE Request Quote button next to a BLACK Add to cart, on the default theme.
 *
 * They are deliberately last: `contrast` is a theme's strong neutral, not its
 * brand, so any real brand slug above should win first. Taken as a PAIR they
 * are safe in either direction - a block theme guarantees its text colour
 * reads against its background colour, so a `contrast` fill under a `base`
 * label is readable whether the theme is light or dark.
 */

:root {
	/* Brand. Chains Wbcom themes -> WP "primary" -> the four big page-builder
	   themes -> WP "accent" -> hex. Numbered/decorative slugs are deliberately
	   NOT in the chain: a confidently wrong colour is worse than a clean
	   default the owner can override. */
	--wcpq-accent: var(--bx-color-accent, var(--color-theme-primary, var(--reign-colors-theme, var(--wp--preset--color--primary, var(--ast-global-color-0, var(--global-palette1, var(--theme-palette-color-1, var(--wp--preset--color--accent, var(--wp--preset--color--contrast, #2563eb)))))))));
	--wcpq-accent-hover: var(--bx-color-link-hover, var(--color-link-hover, var(--reign-site-link-hover-color, var(--wcpq-accent))));
	/*
	 * Label colour for anything sitting ON the accent.
	 *
	 * Takes the theme's OWN declared button text colour first, so the plugin's
	 * primary button is the same button the theme draws everywhere else. That is
	 * deliberate even when the theme's pairing is below WCAG AA: BuddyX declares
	 * --bx-color-button-fg #ffffff on an #ef5455 accent, which measures 3.46:1,
	 * and its own Add to cart button measures exactly the same. Overriding it
	 * here would make quote buttons the only ones on the site that do not match,
	 * and "use the same primary button as the shop" is the requirement.
	 *
	 * An owner who needs AA can set either variable without touching the theme,
	 * in Appearance > Customize > Additional CSS:
	 *
	 *   :root { --wcpq-accent: #b3261e; }      // darker fill, keeps white text
	 *   :root { --wcpq-on-accent: #1a1a1a; }   // or dark text on the same fill
	 */
	--wcpq-on-accent: var(--bx-color-button-fg, var(--bx-color-fg-inverse, var(--reign-site-button-text-color, var(--wp--preset--color--base, #ffffff))));

	/* Text. */
	--wcpq-text: var(--bx-color-fg, var(--global-font-color, var(--reign-site-body-text-color, var(--wp--preset--color--contrast, #1e293b))));
	--wcpq-text-muted: var(--bx-color-fg-muted, var(--reign-site-alternate-text-color, #64748b));

	/* Surfaces. */
	--wcpq-surface: var(--bx-color-bg-elevated, var(--color-theme-white-box, var(--reign-site-sections-bg-color, var(--wp--preset--color--base, #ffffff))));
	--wcpq-surface-subtle: var(--bx-color-bg-subtle, var(--reign-site-secondary-bg-color, #f8fafc));
	--wcpq-surface-hover: var(--bx-color-bg-muted, var(--global-body-lightcolor, var(--reign-site-secondary-bg-color, #f1f5f9)));

	/* Lines. */
	--wcpq-border: var(--bx-color-border, var(--global-border-color, var(--reign-site-border-color, #e2e8f0)));

	/* Status. Reign publishes no status tokens, so these keep a hex tail. */
	--wcpq-success: var(--bx-color-success, #2e7d32);
	--wcpq-success-bg: var(--bx-color-success-bg, #edf7ed);
	--wcpq-error: var(--bx-color-error, #b3261e);
	--wcpq-error-bg: var(--bx-color-error-bg, #fdecea);
	--wcpq-warning: var(--bx-color-warning, #8a6914);
	--wcpq-warning-bg: var(--bx-color-warning-bg, #fcf9e8);

	/* Spacing, radius and motion, so components never invent their own. */
	--wcpq-space-xs: 0.25rem;
	--wcpq-space-sm: 0.5rem;
	--wcpq-space-md: 1rem;
	--wcpq-space-lg: 1.5rem;
	--wcpq-space-xl: 2rem;

	--wcpq-radius-sm: 4px;
	--wcpq-radius-md: 6px;
	--wcpq-radius-lg: 10px;

	--wcpq-transition: 0.2s ease;

	/* Elevation. Tokenised so dark mode can deepen them: a black shadow that
	   reads as depth on white is invisible on a dark surface. */
	--wcpq-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
	--wcpq-shadow-md: 0 2px 6px rgba(0, 0, 0, 0.12);
	--wcpq-shadow-lg: 0 6px 20px rgba(0, 0, 0, 0.18);

	/* Accent-tinted glow, derived from the accent instead of the indigo hex it
	   used to hardcode - that hex stayed purple however the store was branded. */
	--wcpq-shadow-accent: 0 4px 16px color-mix(in srgb, var(--wcpq-accent) 40%, transparent);
	--wcpq-shadow-accent-strong: 0 6px 20px color-mix(in srgb, var(--wcpq-accent) 50%, transparent);
}

/*
 * Dark-mode fallback.
 *
 * Only for themes that have no dark tokens of their own. BuddyX and Reign flip
 * their own variables, so on those themes the chain above has already produced
 * dark values and none of this needs to apply.
 *
 * Both explicit roots AND the system preference are covered, because a theme
 * may signal dark by attribute, by class, or by neither.
 */
@media (prefers-color-scheme: dark) {
	:root:not([data-bx-mode="light"]):not([data-theme="light"]) {
		--wcpq-text: var(--bx-color-fg, var(--reign-site-body-text-color, #e5e7eb));
		--wcpq-text-muted: var(--bx-color-fg-muted, var(--reign-site-alternate-text-color, #9ca3af));
		--wcpq-surface: var(--bx-color-bg-elevated, var(--reign-site-sections-bg-color, #1f2430));
		--wcpq-surface-subtle: var(--bx-color-bg-subtle, var(--reign-site-secondary-bg-color, #171b24));
		--wcpq-surface-hover: var(--bx-color-bg-muted, var(--reign-site-secondary-bg-color, #262c3a));
		--wcpq-border: var(--bx-color-border, var(--reign-site-border-color, #374151));
		/*
		 * Status FOREGROUNDS flip too, not just their backgrounds.
		 *
		 * These were the one thing the first version of this block forgot: the
		 * success tint went dark while the success text stayed at its light-mode
		 * #2e7d32, leaving the "products added to quote" confirmation at 3.02:1 -
		 * a real failure, and one that reads as merely "a bit dim" on screen
		 * rather than as broken. A dark surface needs the LIGHT variant of a
		 * status colour, not the same one.
		 */
		--wcpq-success: var(--bx-color-success, #81c784);
		--wcpq-error: var(--bx-color-error, #ef9a9a);
		--wcpq-warning: var(--bx-color-warning, #e0c069);
		--wcpq-success-bg: var(--bx-color-success-bg, #16281c);
		--wcpq-error-bg: var(--bx-color-error-bg, #2b1614);
		--wcpq-warning-bg: var(--bx-color-warning-bg, #2a2312);
		--wcpq-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
		--wcpq-shadow-md: 0 2px 6px rgba(0, 0, 0, 0.5);
		--wcpq-shadow-lg: 0 6px 20px rgba(0, 0, 0, 0.6);
	}
}

:root[data-bx-mode="dark"],
:root[data-theme="dark"],
html.dark,
body.dark-mode {
	--wcpq-text: var(--bx-color-fg, var(--reign-site-body-text-color, #e5e7eb));
	--wcpq-text-muted: var(--bx-color-fg-muted, var(--reign-site-alternate-text-color, #9ca3af));
	--wcpq-surface: var(--bx-color-bg-elevated, var(--reign-site-sections-bg-color, #1f2430));
	--wcpq-surface-subtle: var(--bx-color-bg-subtle, var(--reign-site-secondary-bg-color, #171b24));
	--wcpq-surface-hover: var(--bx-color-bg-muted, var(--reign-site-secondary-bg-color, #262c3a));
	--wcpq-border: var(--bx-color-border, var(--reign-site-border-color, #374151));
	/*
	 * Status FOREGROUNDS flip too, not just their backgrounds.
	 *
	 * These were the one thing the first version of this block forgot: the
	 * success tint went dark while the success text stayed at its light-mode
	 * #2e7d32, leaving the "products added to quote" confirmation at 3.02:1 -
	 * a real failure, and one that reads as merely "a bit dim" on screen
	 * rather than as broken. A dark surface needs the LIGHT variant of a
	 * status colour, not the same one.
	 */
	--wcpq-success: var(--bx-color-success, #81c784);
	--wcpq-error: var(--bx-color-error, #ef9a9a);
	--wcpq-warning: var(--bx-color-warning, #e0c069);
	--wcpq-success-bg: var(--bx-color-success-bg, #16281c);
	--wcpq-error-bg: var(--bx-color-error-bg, #2b1614);
	--wcpq-warning-bg: var(--bx-color-warning-bg, #2a2312);
	--wcpq-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
	--wcpq-shadow-md: 0 2px 6px rgba(0, 0, 0, 0.5);
	--wcpq-shadow-lg: 0 6px 20px rgba(0, 0, 0, 0.6);
}
