/**
 * BuddyPress Statistics — public CSS variables.
 *
 * Each token chains theme-provided custom properties FIRST, then falls
 * back to a quiet neutral. This lets the plugin inherit any theme that
 * exposes its palette as CSS vars (BuddyBoss, BuddyX, Reign, WP block
 * themes, GeneratePress, Astra, etc.) without us picking a brand color.
 *
 * Chain order:
 *   1. BuddyX       — --bx-color-*
 *   2. Reign        — --reign-*
 *   3. BuddyBoss    — --bb-*
 *   4. WordPress core block themes — --wp--preset--color--*
 *   5. Neutral default (gray-scale, NOT indigo / purple / brand)
 *
 * Why neutral defaults: this plugin ships into hundreds of theme
 * combinations. A bright indigo default looks AI-generated next to a
 * neutral theme. A muted neutral default looks intentional next to
 * everything, and themes that DO expose their palette will override.
 *
 * @package    Bp_Stats
 * @subpackage Bp_Stats/public/css
 * @since      2.0.0
 */

:root {
	/* Surfaces — paper, elevated card, recessed background.
	 * Chain: BuddyX --bx-color-* → Reign --reign-* → BuddyBoss --bb-* →
	 * WP block-theme preset → neutral hex. */
	--bp-stats-bg-primary: var(--bx-color-bg-page,
		var(--reign-site-body-bg-color,
		var(--bb-content-background-color,
		var(--wp--preset--color--base, #ffffff))));

	--bp-stats-bg-elevated: var(--bx-color-bg-elevated,
		var(--reign-site-sections-bg-color,
		var(--bb-content-alternate-background-color,
		var(--wp--preset--color--base, #ffffff))));

	--bp-stats-bg-secondary: var(--bx-color-bg-subtle,
		var(--reign-site-secondary-bg-color,
		var(--bb-background-secondary-color,
		var(--wp--preset--color--tertiary, #f7f7f8))));

	--bp-stats-bg-tertiary: var(--bx-color-bg-muted,
		var(--reign-site-secondary-bg-color,
		var(--bb-background-tertiary-color, #f1f3f5)));

	/* Text — primary headlines, secondary copy, muted helper */
	--bp-stats-text-primary: var(--bx-color-fg,
		var(--reign-site-body-text-color,
		var(--bb-headings-color,
		var(--wp--preset--color--contrast, #1c1f23))));

	--bp-stats-text-secondary: var(--bx-color-fg-muted,
		var(--reign-site-alternate-text-color,
		var(--bb-body-text-color,
		var(--wp--preset--color--contrast-2, #4b5563))));

	--bp-stats-text-muted: var(--bx-color-fg-muted,
		var(--reign-site-alternate-text-color,
		var(--bb-body-secondary-text-color,
		var(--wp--preset--color--contrast-3, #6b7280))));

	--bp-stats-text-light: #9ca3af;
	--bp-stats-text-inverse: #ffffff;
	--bp-stats-text-dark: var(--bp-stats-text-primary);

	/* Borders */
	--bp-stats-border-color: var(--bx-color-border,
		var(--reign-site-border-color,
		var(--bb-content-border-color, #e6e8eb)));

	--bp-stats-border-light: var(--bx-color-divider,
		var(--reign-site-border-color,
		var(--bb-content-alternate-border-color, #eef0f2)));
	--bp-stats-border-medium: var(--bx-color-border-strong,
		var(--reign-form-border-color, #d1d5db));

	/* Link — body links + hover, used by inline anchors in cards. */
	--bp-stats-link: var(--bx-color-link,
		var(--reign-site-link-color,
		var(--bb-primary-color, var(--bp-stats-primary))));
	--bp-stats-link-hover: var(--bx-color-link-hover,
		var(--reign-site-link-hover-color,
		var(--bb-primary-button-background-hover, var(--bp-stats-primary))));

	/*
	 * Accent — the ONE color the plugin uses for emphasis (focus rings,
	 * active tab, primary CTA stroke, hero band, streak ring).
	 * Inherits the theme's primary if exposed; otherwise neutral
	 * currentColor so it picks up the surrounding text color.
	 */
	--bp-stats-primary: var(--bx-color-accent,
		var(--reign-colors-theme,
		var(--bb-primary-button-background-regular,
		var(--bb-primary-color,
		var(--wp--preset--color--primary, currentColor)))));

	--bp-stats-accent: var(--bp-stats-primary);
	--bp-stats-accent-hover: var(--bx-color-link-hover,
		var(--reign-site-link-hover-color, var(--bp-stats-primary)));

	/*
	 * Status hues — restrained, used ONLY to communicate state, not
	 * decoration. Soft saturation; matches typical theme conventions.
	 */
	--bp-stats-success: var(--bb-success-color, #15803d);
	--bp-stats-warning: var(--bb-warning-color, #b45309);
	--bp-stats-danger:  var(--bb-error-color,   #b91c1c);
	--bp-stats-info:    var(--bb-info-color,    #1d4ed8);

	--bp-stats-success-bg: color-mix(in srgb, var(--bp-stats-success) 10%, transparent);
	--bp-stats-warning-bg: color-mix(in srgb, var(--bp-stats-warning) 10%, transparent);
	--bp-stats-danger-bg:  color-mix(in srgb, var(--bp-stats-danger)  10%, transparent);
	--bp-stats-info-bg:    color-mix(in srgb, var(--bp-stats-info)    10%, transparent);

	/* Chart palette — restrained, derived from a single accent + neutrals */
	--bp-stats-chart-1: var(--bp-stats-accent);
	--bp-stats-chart-2: color-mix(in srgb, var(--bp-stats-accent) 65%, var(--bp-stats-text-muted) 35%);
	--bp-stats-chart-3: var(--bp-stats-info);
	--bp-stats-chart-3-alt: color-mix(in srgb, var(--bp-stats-info) 60%, transparent);
	--bp-stats-chart-4: var(--bp-stats-success);
	--bp-stats-chart-5: var(--bp-stats-warning);
	--bp-stats-chart-6: var(--bp-stats-danger);
	--bp-stats-chart-7: color-mix(in srgb, var(--bp-stats-accent) 50%, var(--bp-stats-info) 50%);
	--bp-stats-chart-8: color-mix(in srgb, var(--bp-stats-info) 70%, var(--bp-stats-success) 30%);

	/* Shadows — gentler than default Tailwind-ish */
	--bp-stats-shadow-color: rgba(0, 0, 0, 0.06);
	--bp-stats-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);

	/* Tints (used by gradient backgrounds — soft on light, soft on dark) */
	--bp-stats-tint-primary: color-mix(in srgb, var(--bp-stats-accent) 5%, var(--bp-stats-bg-primary));
	--bp-stats-tint-primary-light: color-mix(in srgb, var(--bp-stats-accent) 3%, var(--bp-stats-bg-primary));
	--bp-stats-tint-primary-alt:   color-mix(in srgb, var(--bp-stats-accent) 8%, var(--bp-stats-bg-primary));
	--bp-stats-tint-accent:        color-mix(in srgb, var(--bp-stats-accent) 8%, var(--bp-stats-bg-primary));
	--bp-stats-tint-accent-alt:    color-mix(in srgb, var(--bp-stats-accent) 12%, var(--bp-stats-bg-primary));
	--bp-stats-tint-info:          color-mix(in srgb, var(--bp-stats-info) 8%, var(--bp-stats-bg-primary));
	--bp-stats-tint-info-alt:      color-mix(in srgb, var(--bp-stats-info) 12%, var(--bp-stats-bg-primary));
	--bp-stats-tint-success:       color-mix(in srgb, var(--bp-stats-success) 8%, var(--bp-stats-bg-primary));
	--bp-stats-tint-warning:       color-mix(in srgb, var(--bp-stats-warning) 8%, var(--bp-stats-bg-primary));
	--bp-stats-tint-warning-alt:   color-mix(in srgb, var(--bp-stats-warning) 12%, var(--bp-stats-bg-primary));
	--bp-stats-tint-warning-light: color-mix(in srgb, var(--bp-stats-warning) 15%, var(--bp-stats-bg-primary));
	--bp-stats-tint-success-light:   color-mix(in srgb, var(--bp-stats-success) 12%, var(--bp-stats-bg-primary));
	--bp-stats-tint-success-lighter: color-mix(in srgb, var(--bp-stats-success) 18%, var(--bp-stats-bg-primary));

	/* Overlays */
	--bp-stats-overlay-bg: color-mix(in srgb, var(--bp-stats-bg-primary) 92%, transparent);
	--bp-stats-overlay-light: rgba(255, 255, 255, 0.3);
	--bp-stats-overlay-subtle: rgba(255, 255, 255, 0.1);

	/* Legacy aliases kept so older blocks don't break */
	--bp-stats-text-secondary-alt: var(--bp-stats-text-secondary);
	--bp-stats-text-muted-alt:     var(--bp-stats-text-muted);
	--bp-stats-text-secondary-light: var(--bp-stats-text-secondary);
	--bp-stats-text-darker: var(--bp-stats-text-primary);
	--bp-stats-svg-stroke: var(--bp-stats-text-primary);
	--bp-stats-success-alt: var(--bp-stats-success);
}

/*
 * Dark mode: only the verified Reign / BuddyX triggers (html[data-bx-mode="dark"]
 * and body.buddyx-dark-theme), never the OS setting. This override flips the surface /
 * text / border tokens for the whole plugin, so per-component
 * ".buddyx-dark-mode .bp-stats-card { ... }" color rules are no longer needed.
 *
 * Values are EXPLICIT dark hex, NOT chained through the theme dark tokens
 * (--bx-color-, --reign-, --bb-): those vars stay LIGHT unless the theme
 * itself is in dark mode, so chaining here would resolve to a light palette
 * on a generic data-theme dark toggle. BuddyX/Reign native dark is already
 * handled by the light :root chain flipping the theme own tokens; this block
 * guarantees a correct dark palette for every other dark trigger. Brand
 * accent stays unchanged (still inherits the theme primary via :root chain).
 */
html[data-bx-mode="dark"],
body.buddyx-dark-theme {
	--bp-stats-text-primary: #e4e4e7;
	--bp-stats-text-secondary: #b4b4b8;
	--bp-stats-text-muted: #8a8a90;
	--bp-stats-text-light: #6b7280;
	--bp-stats-text-inverse: #16191f;

	--bp-stats-bg-primary: #16191f;
	--bp-stats-bg-secondary: #262c3a;
	--bp-stats-bg-tertiary: #16191f;
	--bp-stats-bg-elevated: #1f2430;

	--bp-stats-border-color: #3a4253;
	--bp-stats-border-light: #262c3a;
	--bp-stats-border-medium: #4b5563;

	--bp-stats-shadow-color: rgba(0, 0, 0, 0.3);
}

/*
 * BuddyX / Reign native dark (html[data-bx-mode="dark"]). These themes set
 * their own palette tokens to dark values when this attribute is present,
 * so here the plugin follows the theme's surfaces and text instead of the
 * generic dark hex above. Declared after the generic block (same
 * specificity, plus body because the generic block also matches
 * body.dark-mode) so it wins; the hex fallbacks keep it dark if a token is
 * missing.
 */
html[data-bx-mode="dark"],
html[data-bx-mode="dark"] body {
	--bp-stats-text-primary: var(--bx-color-fg, var(--reign-site-body-text-color, #e4e4e7));
	--bp-stats-text-secondary: var(--bx-color-fg-muted, var(--reign-site-alternate-text-color, #b4b4b8));
	--bp-stats-text-muted: var(--bx-color-fg-subtle, var(--reign-site-alternate-text-color, #8a8a90));
	--bp-stats-text-inverse: var(--bx-color-accent-inverse, var(--reign-on-accent-color, #16191f));

	--bp-stats-bg-primary: var(--bx-color-bg-page, var(--reign-site-body-bg-color, #16191f));
	--bp-stats-bg-elevated: var(--bx-color-bg-elevated, var(--reign-site-secondary-bg-color, #1f2430));
	--bp-stats-bg-secondary: var(--bx-color-bg-subtle, var(--reign-site-secondary-bg-color, #262c3a));
	--bp-stats-bg-tertiary: var(--bx-color-bg-page, var(--reign-site-body-bg-color, #16191f));

	--bp-stats-border-color: var(--bx-color-border, var(--reign-form-border-color, #3a4253));
	--bp-stats-border-light: var(--bx-color-divider, var(--reign-site-border-color, #262c3a));
	--bp-stats-border-medium: var(--bx-color-border-strong, #4b5563);
}

/*
 * Status colours for every dark trigger. The light values (#15803d etc.) sit
 * below 3:1 on dark surfaces, so chart lines and status text vanish. The
 * derived tints and chart tokens are re-declared here so they resolve against
 * these values when the dark trigger is a body class (custom properties
 * declared on :root resolve once, at :root).
 */
body.buddyx-dark-theme,
html[data-bx-mode="dark"],
html[data-bx-mode="dark"] body {
	--bp-stats-success: #4ade80;
	--bp-stats-warning: #fbbf24;
	--bp-stats-danger:  #f87171;
	--bp-stats-info:    #60a5fa;

	--bp-stats-success-bg: color-mix(in srgb, var(--bp-stats-success) 10%, transparent);
	--bp-stats-warning-bg: color-mix(in srgb, var(--bp-stats-warning) 10%, transparent);
	--bp-stats-danger-bg:  color-mix(in srgb, var(--bp-stats-danger)  10%, transparent);
	--bp-stats-info-bg:    color-mix(in srgb, var(--bp-stats-info)    10%, transparent);
	--bp-stats-chart-1: var(--bp-stats-accent);
	--bp-stats-chart-2: color-mix(in srgb, var(--bp-stats-accent) 65%, var(--bp-stats-text-muted) 35%);
	--bp-stats-chart-3: var(--bp-stats-info);
	--bp-stats-chart-3-alt: color-mix(in srgb, var(--bp-stats-info) 60%, transparent);
	--bp-stats-chart-4: var(--bp-stats-success);
	--bp-stats-chart-5: var(--bp-stats-warning);
	--bp-stats-chart-6: var(--bp-stats-danger);
	--bp-stats-chart-7: color-mix(in srgb, var(--bp-stats-accent) 50%, var(--bp-stats-info) 50%);
	--bp-stats-chart-8: color-mix(in srgb, var(--bp-stats-info) 70%, var(--bp-stats-success) 30%);
	--bp-stats-success-alt: var(--bp-stats-success);
}
