/**
 * Button.
 *
 * The site's button CSS, in one file. `.btn` is the hand-authored name - usable
 * in a template, a snippet or an Elementor HTML widget - and `.roofkit-btn` is
 * what the Roofing Kit Button widget emits. They share one base ruleset with the
 * bare form elements, so all of them read the same tokens.
 *
 * Every declaration in the base reads a custom property, and the variants below
 * *reassign those properties* instead of setting CSS properties directly. That
 * indirection is the point: the Customizer can retune any button from :root and
 * have it land everywhere, and variants never end up in a specificity fight with
 * the base because the two never set the same thing.
 *
 * This file is a move, not a redesign. `.btn` and `.roofkit-btn` keep the exact
 * values they each had before - including the two places they differ, weight and
 * transition - and the two variant families stay separate for the same reason.
 *
 * A bare `button` in the selector also catches controls that are buttons to the
 * accessibility tree but not to the eye - an accordion toggle, a tab, a slider
 * arrow. Those carry `.btn-unstyled` and the base skips them. The exclusion is
 * wrapped in :where() so it costs nothing: the base stays at (0,2,0), exactly as
 * described below, and an opting-out widget's own single class is enough to
 * dress the control without an !important or a specificity ladder.
 *
 * Token defaults live in global.css's :root, not here. Dynamic_Styles prints the
 * Customizer's :root block immediately after global.css, so a default declared
 * in this file would load later and beat the Customizer.
 *
 * Everything is scoped under the `.roofing` body class, which puts the base at
 * (0,2,1) - above a stray `.btn` from a plugin shipping Bootstrap, without an
 * !important anywhere.
 *
 * @package roofing
 * @author Masood HQ <hey@masoodhq.com>
 * @version 1.0
 */

/**
 * ------------------------------
 *  Base
 * ------------------------------
 */

.roofing :is(.btn, .roofkit-btn, button, input[type="submit"], input[type="button"], input[type="reset"]):not(:where(.btn-unstyled)) {
  display: inline-block;
  box-sizing: border-box;
  padding: var(--btn-pad-block) var(--btn-pad-inline);
  font-size: var(--btn-font-size);
  font-weight: var(--btn-weight);
  letter-spacing: var(--btn-tracking);
  text-transform: var(--btn-text-transform);
  color: var(--btn-fg);
  background-color: var(--btn-bg);
  border: var(--btn-border-width) var(--btn-border-style) var(--btn-border);
  border-radius: var(--btn-radius);
  box-shadow: var(--btn-shadow);
  text-align: center;
  text-decoration: none;
  transition: var(--btn-transition);
}

/*
 * cursor: pointer was on .btn/button/input[...] before but not on .roofkit-btn,
 * which the widget renders as an <a> and relies on the browser's own pointer
 * cursor for links. Kept as its own rule rather than folded into the base above
 * so that split stays exactly as it was.
 */
.roofing :is(.btn, button, input[type="submit"], input[type="button"], input[type="reset"]):not(:where(.btn-unstyled)) {
  cursor: pointer;
}

/*
 * The widget's base differed from .btn in exactly two places, and still does: it
 * takes its weight from the page instead of going medium, and it transitions
 * colour, border and opacity as well as background and shadow.
 */
.roofing .roofkit-btn {
  --btn-weight: inherit;
  --btn-transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease,
    opacity 0.3s ease;

  /* The widget's default hover. When the Customizer hover-effect setting lands
     it will set these same tokens on :root for every button instead. */
  --btn-opacity-hover: 0.9;
  --btn-shadow-hover: var(--shadow-md);
}

/*
 * Hover. Every token falls back to its own resting value, so a button with no
 * --btn-*-hover set resolves this to exactly its resting state and looks
 * untouched - which is why `.btn`, which never had a hover rule, still has no
 * hover. A hover effect is then nothing more than a set of these six tokens.
 *
 * The fallbacks have to live here rather than as `--btn-fg-hover: var(--btn-fg)`
 * on :root. A custom property is substituted where it is declared, so a :root
 * default would resolve against the :root value of --btn-fg and stop tracking a
 * variant's. Left unset and defaulted here, they resolve against the button.
 *
 * :not() keeps a disabled button from lighting up under the cursor, which the
 * fallbacks alone would not - the disabled rule at the bottom of this file sits
 * below this one on specificity.
 */
.roofing :is(.btn, .roofkit-btn, button, input[type="submit"], input[type="button"], input[type="reset"]):not(:where(.btn-unstyled)):hover:not(:disabled, .disabled) {
  color: var(--btn-fg-hover, var(--btn-fg));
  background-color: var(--btn-bg-hover, var(--btn-bg));
  border-color: var(--btn-border-hover, var(--btn-border));
  box-shadow: var(--btn-shadow-hover, var(--btn-shadow));
  transform: var(--btn-transform-hover, none);
  opacity: var(--btn-opacity-hover, 1);
}

/**
 * ------------------------------
 *  Theme variants (.btn)
 * ------------------------------
 */

.roofing .btn-simple {
  border-bottom: var(--border-dark);
}

.roofing .btn-primary {
  --btn-bg: var(--color-primary);
  --btn-fg: var(--color-bg);
}

.roofing .btn-secondary {
  --btn-bg: var(--color-secondary);
  --btn-fg: var(--color-bg);
}

.roofing .btn-outline {
  --btn-bg: transparent;
  --btn-fg: var(--color-primary);
  --btn-border: var(--color-primary);
  --btn-border-width: 1px;
}

.roofing .btn-small {
  --btn-pad-block: 0.4em;
  --btn-pad-inline: 0.8em;
  --btn-font-size: var(--fs-xs);
}

.roofing .btn-large {
  --btn-pad-block: 0.8em;
  --btn-pad-inline: 1.6em;
  --btn-font-size: var(--fs-md);
}

.roofing .btn-fullwidth {
  width: 100%;
  --btn-pad-block: 0.8em;
  --btn-pad-inline: 0;
  --btn-font-size: var(--fs-md);
  --btn-radius: var(--radius-lg);
}

/**
 * ------------------------------
 *  Widget style variants
 * ------------------------------
 */

.roofing .roofkit-btn-solid {
  --btn-bg: var(--color-primary);
  --btn-fg: var(--color-bg);
  --btn-border: var(--color-primary);
  --btn-border-width: 1px;
}

.roofing .roofkit-btn-secondary {
  --btn-bg: var(--color-secondary);
  --btn-fg: var(--color-bg);
  --btn-border: var(--color-secondary);
  --btn-border-width: 1px;
}

.roofing .roofkit-btn-outline {
  --btn-bg: transparent;
  --btn-fg: var(--color-text);
  --btn-border: var(--color-border);
  --btn-border-width: 1px;
  --btn-bg-hover: var(--color-primary);
  --btn-fg-hover: var(--color-bg);
  --btn-border-hover: var(--color-primary);
}

.roofing .roofkit-btn-creative {
  --btn-bg: var(--color-bg);
  --btn-fg: var(--color-heading);
  --btn-border: var(--color-bg);
  --btn-border-width: 1px;
  --btn-bg-hover: var(--color-primary);
  --btn-fg-hover: var(--color-bg);
  --btn-border-hover: var(--color-primary);
}

.roofing .roofkit-btn-white {
  --btn-bg: var(--color-bg);
  --btn-fg: var(--color-heading);
  --btn-border: var(--color-border);
  --btn-border-width: 1px;
  --btn-bg-hover: var(--color-primary);
  --btn-fg-hover: var(--color-bg);
  --btn-border-hover: var(--color-primary);
}

/**
 * ------------------------------
 *  Widget size variants
 * ------------------------------
 */

.roofing .roofkit-btn--size-small {
  --btn-pad-block: var(--btn-padding-block-sm);
  --btn-pad-inline: var(--btn-padding-inline-sm);
  --btn-font-size: var(--btn-font-size-sm);
}

.roofing .roofkit-btn--size-medium {
  --btn-pad-block: var(--btn-padding-block-md);
  --btn-pad-inline: var(--btn-padding-inline-md);
  --btn-font-size: var(--btn-font-size-md);
}

.roofing .roofkit-btn--size-large {
  --btn-pad-block: var(--btn-padding-block-lg);
  --btn-pad-inline: var(--btn-padding-inline-lg);
  --btn-font-size: var(--btn-font-size-lg);
}

/**
 * ------------------------------
 *  Widget radius variants
 * ------------------------------
 */

.roofing .roofkit-btn--radius-sharp { --btn-radius: var(--radius-xs); }
.roofing .roofkit-btn--radius-soft  { --btn-radius: var(--radius-md); }
.roofing .roofkit-btn--radius-round { --btn-radius: var(--radius-xl); }
.roofing .roofkit-btn--radius-pill  { --btn-radius: var(--radius-pill); }

/**
 * ------------------------------
 *  Widget shadow variants
 * ------------------------------
 */

.roofing .roofkit-btn--shadow-none   { --btn-shadow: none; }
.roofing .roofkit-btn--shadow-soft   { --btn-shadow: var(--shadow-soft); }
.roofing .roofkit-btn--shadow-strong { --btn-shadow: var(--shadow-lg); }

/**
 * ------------------------------
 *  Widget border variants
 * ------------------------------
 */

/*
 * "none" intentionally has no rule, so a button keeps the border that came with
 * its style variant unless light/dark explicitly overrides it. These must stay
 * *after* the style variants above: both sit at (0,2,0), so source order is what
 * decides.
 */
.roofing .roofkit-btn--border-light {
  --btn-border-width: 1px;
  --btn-border: var(--color-border);
}

.roofing .roofkit-btn--border-dark {
  --btn-border-width: 1px;
  --btn-border: var(--color-heading);
}

/**
 * ------------------------------
 *  Widget width
 * ------------------------------
 */

.roofing .roofkit-btn-block {
  display: block;
  width: 100%;
}

.roofing .roofkit-btn-inline {
  display: inline-block;
  width: auto;
}

/**
 * ------------------------------
 *  Loading state
 * ------------------------------
 */

.roofing .btn-loader {
  width: 1.125rem;
  height: 1.125rem;
  border: 2px solid var(--color-bg);
  border-top: 2px solid transparent;
  border-radius: var(--radius-round);
  animation: spin 0.8s linear infinite;
  display: none; /* hidden by default */
}

.roofing .btn .btn-text {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi-bold);
  color: var(--color-bg);
}

.roofing .btn.loading .btn-text {
  display: none; /* hide text when loading */
}

.roofing .btn.loading .btn-loader {
  display: inline-block; /* show loader */
}

@keyframes spin {
  100% {
    transform: rotate(360deg);
  }
}

/**
 * ------------------------------
 *  Disabled
 * ------------------------------
 */

.roofing .btn:disabled,
.roofing .btn.disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  .roofing .roofkit-btn {
    --btn-transition: none;
    --btn-transform-hover: none;
  }
}
