/**
 * Readable text on the Agend theme's own buttons.
 *
 * THE PREMISE OF THIS FILE CHANGED. It was written when --at-color-accent was
 * ochre #F04C3A, where the theme's white button text failed and black was the
 * fix. The Customizer now sets --at-color-accent to navy #003038, so every
 * entry below that was black *because its background is the accent* had become
 * black on navy, 1.48:1. `.woocommerce-Address .edit` on
 * /my-account/edit-address is the one Bryce reported. Those entries are white
 * again, which is what the theme's own default gives them; they are kept rather
 * than deleted because the selector lists record which buttons are accent
 * backed, and that map is the expensive part.
 *
 * Only --at-color-background-badge is still ochre, so only the one entry that
 * takes it keeps black. The #ffffff exceptions further down were always about
 * the dark #005361 teal and are untouched.
 *
 * Whoever changes --at-color-accent again has to revisit this file. There is no
 * way to derive the text colour from the background in CSS, so the pairing is
 * always a literal and always a standing bet on the accent.
 *
 * Nothing here touches an OTA button. This is about buttons that have not been
 * moved onto the design yet and are still painted by the Agend theme, and it
 * fixes one thing about them: text that cannot be read on its button's
 * background. Originally that was white on ochre; since the accent change it
 * is mostly black on navy.
 *
 * The OTA buttons were already right. The `ochre-button` and
 * `ochre-button-text` roles in Colour_Themes pair `#F04C3A` with `#000000` in
 * the themes whose button is ochre, and invert to a navy button with white text
 * in the themes whose section is already ochre, so an OTA button can never put
 * white on ochre. The theme's buttons have no such pairing: its two variables
 * are set independently of each other, so nothing keeps them readable
 * together:
 *
 *   --at-button-background-color  var(--at-color-accent)           #003038
 *   --at-button-text-color        var(--at-color-text-accent-link) white
 *
 * That pair happens to pass today (14.19:1). It failed when the accent was
 * ochre, and it fails again the next time either variable moves alone.
 *
 * A WHITELIST, AND WHY IT HAS TO BE
 *
 * The first version of this file did the obvious thing: set the text colour to
 * black on `:root`, then except the call sites that pass a dark background. That
 * was wrong, and it shipped a regression. `.at-card--secondary-accent
 * .at-card__button` and at least one portal card component pass
 * `$at-color-secondary-accent` (#005361) and were not in the exception list, so
 * they came out black on dark teal, around 1.6:1 and unreadable. Bryce found
 * them on the member dashboard.
 *
 * The mistake was not the missing entry, it was the direction. The theme's
 * `color` comes from a variable while its `background` is chosen per call site,
 * and there are dozens of call sites across the theme's 25 button files, some of
 * which override each other (`.shop_table input.button` is declared twice, with
 * different backgrounds, and the later one wins). Any global change to the text
 * colour is a bet that the enumeration of dark ones is complete.
 *
 * The failure modes are not symmetrical:
 *
 *   A whitelist that misses a button leaves it with the theme's own pairing.
 *   When the accent was ochre that was white on ochre: the visible status quo,
 *   fixable when found. Now the accent is navy it is white on navy, which
 *   passes, so a miss costs nothing at all.
 *
 *   A blacklist that misses a button makes it unreadable. That is a regression,
 *   and it will be found by a member rather than by us.
 *
 * So this lists only selectors that have been read in the theme source and
 * confirmed to take the accent as their background. It is deliberately
 * incomplete. Buttons not listed keep whatever they had.
 *
 * Setting the variable rather than `color` means there is no specificity fight:
 * the theme's mixin reads `color: var(--at-button-text-color)`, and a `var()` is
 * substituted at the element that uses it, so redefining the property on the
 * element wins however specific the theme's own rule is. Nothing here needs
 * `!important` and no selector is inflated.
 *
 * Literal colours rather than reading the OTA roles (`--ota-ochre-button-text`
 * is where a black would come from, and would read better). A `var()` resolves
 * against the element it is declared on and is then inherited as a fixed
 * value, so it cannot follow the theme of the section a button sits in, and it
 * would silently flip if the site's default theme were changed to one of the
 * five whose ochre button inverts to navy. These backgrounds are a fixed
 * `--at-color-accent` and are not theme-aware at all, so the pairing is
 * decided here unconditionally: white on the accent entries now the accent is
 * navy, black only where the background is still the ochre badge.
 *
 * All of this goes away when these surfaces become `.ota-btn`, where a type
 * picks a paint mode and a colour supplies a fill and an on-fill together, so
 * contrast cannot be got wrong. That is the real fix and this is a holding
 * pattern.
 */

/*
 * src/scss/modules/elementor/widgets/_call-to-action.scss:10
 *   `@include button-agend()` with no background, so --at-button-background-color,
 *   which is the accent. This is the button Bryce reported.
 */
.elementor-cta__button,
.elementor-widget-button:not(.exclude-agend-theme-link) a,

/*
 * src/scss/modules/_buttons.scss:15 and :26
 *   Both `@include button-agend()` with no background. Note that
 *   `.at-button-secondary-accent` is in the accent group despite its name; it is
 *   `.agendtheme-button-secondary-accent`, on line 34, that takes the dark
 *   background, and that one is deliberately absent from this list.
 */
html body .at-button-accent,
html body .at-button-secondary-accent,
html body .agendtheme-button-accent,
html body .btn.btn-primary,

/*
 * src/scss/modules/_woocommerce.scss:292
 *   `@include button-agend-in-form($at-button-background-color)`, so the accent
 *   is passed explicitly.
 */
.woocommerce-Address .edit {
	/*
	 * White, not black: every selector above takes --at-color-accent as its
	 * background and the accent is navy #003038. White on navy is 14.19:1,
	 * against 1.48:1 for the black this used to set.
	 *
	 * Hover and disabled too, and not because they were wrong: the mixin's
	 * `&:active, &:focus, &:hover` sets background-color from
	 * --at-button-background-color-hover, and the call sites that pass a
	 * background only ever pass the resting one. So these buttons are navy in
	 * every state, and disabled is the same story through
	 * --at-button-background-color-disabled.
	 */
	--at-button-text-color: #ffffff;
	--at-button-text-color-hover: #ffffff;
	--at-button-text-color-disabled: #ffffff;
}

/*
 * The only entry still on ochre, so the only one that keeps black. And the one
 * entry where setting the variables is not enough, because the call site does
 * not stop at the mixin.
 *
 * src/scss/modules/_woocommerce.scss:51
 *   `@include button-agend-in-form($at-color-background-badge)`, and
 *   --at-color-background-badge is #F04C3A, which the Customizer did not change.
 *   Black measures 5.80:1 on it; white would be 3.62:1, which is the
 *   failure this file was created to fix.
 *
 * But the same block then sets, per the compiled skin:
 *
 *   color: var(--at-color-foreground-badge) !important        (all states)
 *   background: var(--at-color-foreground-badge) !important   (hover/focus/active)
 *
 * and --at-color-foreground-badge is #F0E7D8 ash here. So the variables alone
 * paint nothing on this button: at rest the !important ash beats the mixin's
 * `color: var(--at-button-text-color)` (2.95:1 on the ochre), and on hover both
 * the text and the background are the same ash, which is invisible. The
 * `color` below answers that at the compiled rule's own weight (1,4,2; the
 * selector is copied from the build), which this file wins on load order.
 * Black holds in both states: 5.80:1 on the ochre rest, 17.05:1 on the ash
 * hover.
 *
 * Disabled is the one state the variables do reach, because the theme's
 * disabled rule says `color: var(--at-button-text-color-disabled) !important`
 * and outweighs the rule below with the `.agendtheme-disabled` class. Its
 * background is --at-button-background-color-disabled, which is the ACCENT,
 * now navy: so the disabled variable is white (14.19:1), not black, and rest
 * and disabled backgrounds now genuinely differ on this button.
 */
body.woocommerce #agendtheme-content .product_meta .posted_in a[rel="tag"] {
	--at-button-text-color: #000000;
	--at-button-text-color-hover: #000000;
	--at-button-text-color-disabled: #ffffff;
	color: #000000 !important;
}

/*
 * The one exception, and it is an exception to the whitelist rather than a
 * return to blacklisting: an ancestor can override the background of a button
 * that is otherwise accent-backed.
 *
 * src/scss/modules/elementor/widgets/_call-to-action.scss:40
 *   `.agendtheme-elementor-section-header-secondary-accent-color` sets
 *   `background-color: $at-color-secondary-accent` (#005361) on any
 *   `a.elementor-button` inside it, which covers both the Call to Action
 *   widget's button and the Button widget's link. This is what the member
 *   dashboard's Library and Support cards use, and it is what made them
 *   unreadable when the whitelist alone gave them black text.
 *
 * Hover as well, because the wrapper's rule is not state-scoped and reaches
 * 0,4,1 without a pseudo-class, while the mixin's own hover rule reaches the
 * same 0,4,1 with one. Equal weight, so source order decides, and the wrapper is
 * declared second: these buttons stay dark teal on hover, so the text stays
 * white. Disabled is not listed because an <a> cannot match `:disabled`.
 *
 * The matching `...-primary-accent-color` wrapper sets the accent, which is
 * now navy, so it needs nothing: the whitelist above already gives it white.
 *
 * This did not work on the first attempt, and the reason is worth recording. The
 * whitelist also carried
 * `.elementor-cta--skin-classic.elementor-cta--skin-classic .elementor-button.elementor-cta__button`,
 * mirroring _call-to-action.scss:24. At 0,4,0 that outranked this exception's
 * 0,2,1, so a skin-classic Call to Action inside the secondary wrapper still came
 * out black on #005361, measured at 2.41:1. The entry was never doing any work:
 * `.elementor-cta__button` at 0,1,0 already covers the same buttons, and these
 * rules only ever set one property to one value, so there was nothing for the
 * extra weight to win against. It is gone, which is the fix.
 *
 * The general lesson for anything added here: keep every whitelist selector as
 * weak as it can be. Weight has no upside when all the rules agree, and it
 * silently blocks the exceptions.
 */
.agendtheme-elementor-section-header-secondary-accent-color a.elementor-button,
.agendtheme-elementor-section-header-secondary-accent-color a.elementor-widget-button {
	--at-button-text-color: #ffffff;
	--at-button-text-color-hover: #ffffff;
}

/*
 * Second exception, and the same shape as the first: a whitelisted class whose
 * background is reassigned by its context.
 *
 * src/scss/modules/_content.scss:466 gives `.btn`, `.at-button-secondary-accent`,
 * `.agendtheme-button-accent` and `.agendtheme-button-secondary-accent` the dark
 * `$at-color-secondary-accent` background when they are inside a content table,
 * through `button-agend-in-form()`. Three of those are on the whitelist above, so
 * in a table they were getting black text on #005361, measured at 2.41:1 on
 * /my-account/order-history.
 *
 * Rest state only. The mixin's hover rule takes its background from
 * --at-button-background-color-hover, which is the accent, so these turn navy
 * on hover, and the whitelist's white hover text is already right for that:
 * this entry only has to fix the rest state.
 *
 * The pattern is now clear enough to write down: this file's whitelist is keyed on
 * class, and the theme reassigns backgrounds by context. Every entry above is a
 * standing bet that no ancestor changes its background, and that bet has been
 * wrong twice. Anything added to the whitelist should be measured on a real page
 * before it is trusted, which is what tools/ and the member area sweep are for.
 */
main#agendtheme-content table:not(.at-table-reset, .tribe-events-calendar-month) :is(.btn, .at-button-secondary-accent, .agendtheme-button-accent, .agendtheme-button-secondary-accent) {
	--at-button-text-color: #ffffff;
}

/*
 * MEASURED, not read.
 *
 * Everything above was worked out from the theme's SCSS. Everything below was
 * found by loading the member area with a session cookie and reading computed
 * styles off the rendered page, which is a better source and should be the one
 * used from here on. Each of these measured white on #F04C3A, which is the fault
 * this file exists to fix, and none of them could have been found by reading:
 * three are the same WooCommerce rule reached through three different class
 * combinations, and one is a sibling of a button that must stay white.
 *
 *   .woocommerce a.button          _woocommerce.scss:266, the accent group.
 *                                  Reached on /my-account/orders as
 *                                  `woocommerce-Button wc-forward button`, on
 *                                  /my-account/payment-methods as a bare
 *                                  `button`, and on /cart as `button
 *                                  wc-backward`. All three measured 3.62:1.
 *
 *   .agendtheme-label-icon-button.dashboard
 *                                  The member navigation. Its `logout` sibling
 *                                  carries the same base class on a dark
 *                                  background and measured 14.19:1, so this is
 *                                  keyed on `.dashboard` and not on the base
 *                                  class. Reading the SCSS would have caught the
 *                                  base class and broken the sibling.
 *
 *   .button--cpd-search-by-date    The CPD search button, from the membership
 *                                  kiosk rather than the theme.
 */
.woocommerce a.button,
.agendtheme-label-icon-button.dashboard,
.button--cpd-search-by-date {
	--at-button-text-color: #ffffff;
	--at-button-text-color-hover: #ffffff;
	--at-button-text-color-disabled: #ffffff;

	/*
	 * And `color` as well, which every rule above this point deliberately avoids.
	 *
	 * Redefining the variable works only for buttons the theme paints through
	 * `color: var(--at-button-text-color)`. Two of these are not painted that way:
	 * measured on the page, `--at-button-text-color` computed to #000000 while
	 * `color` was still white, because something sets `color` literally. The
	 * variable alone is therefore not enough here and the property has to be set.
	 *
	 * That is worth knowing before adding anything else to this file: setting the
	 * token is the tidy approach and it silently does nothing against a literal
	 * `color`. The only way to tell the two apart is to measure, which is how these
	 * were found.
	 */
	color: #ffffff;
}

/*
 * Third exception, same shape as the other two: `.woocommerce a.button` is dark
 * rather than ochre inside a shop table, per _woocommerce.scss:280. Higher weight
 * than the entry above, so it wins where it applies.
 */
.woocommerce .shop_table a.button,
.woocommerce .shop_table .woocommerce-Button {
	--at-button-text-color: #ffffff;
	/* `color` too, to match the entry it is excepting. */
	color: #ffffff;
}

/*
 * Two more, and these needed the browser rather than the source or the page. Both
 * measured white on ochre after the rule above was already matching them, so the
 * question was not "which rule is missing" but "what is beating mine". CDP's
 * matched-rules answered it in one pass:
 *
 *   #agendtheme-header .agendtheme-header-profile .agendtheme-user-profile-controls .dashboard
 *     sets `color: var(--at-color-text-accent-link)` at 1,3,0, over the 0,2,0
 *     above. Mirrored here at the same weight, which wins on load order because
 *     Theme_Buttons enqueues at priority 100, after the theme.
 *
 *   .woocommerce-cart .return-to-shop a.button
 *     sets the same, `!important`. Nothing beats `!important` but `!important`,
 *     so this is the third and last one in the plugin, and it is answering one
 *     named rule rather than hedging. Same selector, so specificity ties and load
 *     order settles it.
 */
#agendtheme-header .agendtheme-header-profile .agendtheme-user-profile-controls .dashboard {
	color: #ffffff;
}

.woocommerce-cart .return-to-shop a.button {
	color: #ffffff !important;
}

/*
 * STILL NOT DONE
 *
 * The Gravity Forms footer rule at _gravity-forms.scss:24 takes the accent, but
 * Submit, Next and Previous are OTA buttons now, so what is left there is Save
 * and continue, which the theme paints white with a grey border and is neither
 * ochre nor broken.
 *
 * `.at-card__button` only appears in the products extension and did not render on
 * any page swept, so it has never been measured. It varies its background per
 * card, so it needs measuring on a page that actually shows one rather than
 * guessing from the SCSS.
 */
