/* ============================================================================
   Alpha Branding Studio — Button System
   assets/css/buttons.css
   ----------------------------------------------------------------------------
   The complete button component. Load after tokens.css, base.css, layout.css,
   utilities.css.

   Contract:
   - Uses ONLY variables from tokens.css. No hardcoded colors/spacing/shadows/type.
   - Motion is quick and mechanical (the "shutter", per DESIGN-SYSTEM.md):
     Ink -> Flare on the Primary hover is the single most important color moment.
   - Naming per COMPONENT.md: Primary = "Shutter". Variants: primary, secondary,
     outline, ghost, text. Sizes: sm / md (default) / lg.
   - Minimum 44px touch target on all interactive variants.
   - No JS: the loading state is markup/attribute-driven ([data-loading] / aria-busy).
   ============================================================================ */


/* ==========================================================================
   1. BASE BUTTON
   Shared structure for every variant. Applies to <button>, <a>, and inputs
   that carry .btn.
   ========================================================================== */

.btn {
  /* Layout ---------------------------------------------------------------- */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);                 /* icon <-> label spacing */
  vertical-align: middle;

  /* Sizing (md default; overridden by size modifiers) --------------------- */
  min-block-size: 52px;                /* comfortable target, > 44px minimum */
  padding-block: var(--space-3);
  padding-inline: var(--space-6);

  /* Typography (display face per system; base.css doesn't touch .btn) ----- */
  font-family: var(--font-display);
  font-size: var(--fs-body);
  font-weight: var(--fw-medium);
  line-height: 1;
  letter-spacing: var(--tracking-snug);
  text-align: center;
  text-decoration: none;               /* for <a class="btn"> */
  white-space: nowrap;

  /* Shape ----------------------------------------------------------------- */
  border: var(--border-medium) solid transparent;  /* keeps all variants same box */
  border-radius: var(--radius-md);

  /* Behavior -------------------------------------------------------------- */
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;          /* removes 300ms tap delay */
  appearance: none;
  isolation: isolate;                  /* keeps ::before spinner scoped */

  /* Motion — mechanical, quick -------------------------------------------- */
  transition:
    background-color var(--dur-base) var(--ease-standard),
    border-color     var(--dur-base) var(--ease-standard),
    color            var(--dur-base) var(--ease-standard),
    box-shadow       var(--dur-base) var(--ease-standard),
    transform        var(--dur-base) var(--ease-standard);
}

/* Icons within a button: inherit color, size from token, never shrink. */
.btn > svg,
.btn > .btn__icon {
  inline-size: var(--icon-sm);
  block-size: var(--icon-sm);
  flex-shrink: 0;
  fill: currentColor;
  stroke-width: var(--icon-stroke);
  pointer-events: none;                /* clicks always register on the button */
}

/* Label wrapper (optional) sits on its own line box for spinner swaps. */
.btn__label {
  display: inline-block;
}


/* ==========================================================================
   2. BUTTON VARIANTS
   ========================================================================== */

/* ---- Primary ("Shutter") — one high-emphasis action per view ----------- */
.btn-primary {
  background-color: var(--color-ink);
  color: var(--color-paper);
  border-color: var(--color-ink);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background-color: var(--color-flare);   /* the key color moment */
  border-color: var(--color-flare);
  color: var(--color-bone);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.btn-primary:active {
  background-color: var(--color-ember);
  border-color: var(--color-ember);
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Accent — the terracotta call-to-action. Used for the single primary action
   in a view (hero audit CTA, final CTA). Reserve it; Ink is the workhorse. */
.btn-accent {
  background-color: var(--color-flare);
  color: var(--color-bone);
  border-color: var(--color-flare);
  box-shadow: var(--shadow-sm);
}

.btn-accent:hover {
  background-color: var(--color-ember);
  border-color: var(--color-ember);
  color: var(--color-bone);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-accent:active {
  background-color: var(--color-ember);
  border-color: var(--color-ember);
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Inverse — for dark (Ink) bands: paper button that flips to Flare on hover. */
.btn-inverse {
  background-color: var(--color-paper);
  color: var(--color-ink);
  border-color: var(--color-paper);
  box-shadow: var(--shadow-sm);
}

.btn-inverse:hover {
  background-color: var(--color-flare);
  border-color: var(--color-flare);
  color: var(--color-bone);
  transform: translateY(-1px);
}

/* ---- Secondary — Ink outline that fills on hover ----------------------- */
.btn-secondary {
  background-color: transparent;
  color: var(--color-ink);
  border-color: var(--color-ink);
}
.btn-secondary:hover {
  background-color: var(--color-ink);
  color: var(--color-paper);
  border-color: var(--color-ink);
}
.btn-secondary:active {
  background-color: var(--color-graphite);
  border-color: var(--color-graphite);
  color: var(--color-paper);
}

/* ---- Outline — quiet, tertiary in dense areas -------------------------- */
.btn-outline {
  background-color: transparent;
  color: var(--text-secondary);
  border-color: var(--border-default);
}
.btn-outline:hover {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--color-ink);
}
.btn-outline:active {
  background-color: var(--bg-page);
  border-color: var(--color-graphite);
}

/* ---- Ghost — text-only with an animated underline ---------------------- */
.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
  border-color: transparent;
  padding-inline: var(--space-3);
}
.btn-ghost:hover {
  color: var(--color-flare);
}
.btn-ghost:active {
  color: var(--color-ember);
}
/* Underline draws in left -> right on hover (uses .btn__label as the target) */
.btn-ghost .btn__label {
  position: relative;
}
.btn-ghost .btn__label::after {
  content: "";
  position: absolute;
  inset-block-end: -2px;
  inset-inline-start: 0;
  inline-size: 100%;
  block-size: var(--border-thick);
  background-color: currentColor;
  transform: scaleX(0);
  transform-origin: inline-start;
  transition: transform var(--dur-base) var(--ease-out);
}
.btn-ghost:hover .btn__label::after,
.btn-ghost:focus-visible .btn__label::after {
  transform: scaleX(1);
}

/* ---- Text — inline, lowest emphasis, no padded box --------------------- */
.btn-text {
  min-block-size: 0;
  padding: 0;
  background-color: transparent;
  color: var(--text-accent);
  border-color: transparent;
  border-radius: var(--radius-sm);
  letter-spacing: var(--tracking-normal);
}
.btn-text:hover {
  color: var(--color-ember);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}


/* ==========================================================================
   3. BUTTON SIZES
   md is the base defined in §1. sm/lg adjust height, padding, type, icon.
   ========================================================================== */

.btn-sm {
  min-block-size: 40px;
  padding-block: var(--space-2);
  padding-inline: var(--space-4);
  font-size: var(--fs-body-sm);
  gap: var(--space-1);
}
.btn-sm > svg,
.btn-sm > .btn__icon {
  inline-size: var(--icon-sm);
  block-size: var(--icon-sm);
}

/* md — explicit class for clarity; matches base .btn values */
.btn-md {
  min-block-size: 52px;
  padding-block: var(--space-3);
  padding-inline: var(--space-6);
  font-size: var(--fs-body);
}

.btn-lg {
  min-block-size: 60px;
  padding-block: var(--space-4);
  padding-inline: var(--space-7);
  font-size: var(--fs-body-lg);
}
.btn-lg > svg,
.btn-lg > .btn__icon {
  inline-size: var(--icon-md);
  block-size: var(--icon-md);
}


/* ==========================================================================
   4. WIDTH VARIANTS
   ========================================================================== */

.btn-auto  { inline-size: auto; }
.btn-block {
  display: flex;
  inline-size: 100%;
}

/* Full width on mobile, natural width from md up */
.btn-block-mobile {
  display: flex;
  inline-size: 100%;
}
@media (min-width: 768px) {
  .btn-block-mobile {
    display: inline-flex;
    inline-size: auto;
  }
}


/* ==========================================================================
   5. STATES
   Hover/active are defined per-variant above. Focus, disabled, and the
   shared disabled surface live here.
   ========================================================================== */

/* Focus-visible — token-driven ring, consistent across variants */
.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
/* Preserve the primary's resting elevation alongside the focus ring */
.btn-primary:focus-visible {
  box-shadow: var(--shadow-focus), var(--shadow-sm);
}

/* Disabled — real attribute, .is-disabled class, or aria-disabled */
.btn:disabled,
.btn.is-disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.4;
  box-shadow: none;
  transform: none;
  pointer-events: none;                /* block clicks; aria-disabled kept focusable via markup */
}


/* ==========================================================================
   6. LOADING STATE
   Attribute-driven ([data-loading] or [aria-busy="true"]). Hides the label,
   shows a pure-CSS spinner, preserves width, and blocks further clicks.
   ========================================================================== */

.btn[data-loading="true"],
.btn[aria-busy="true"] {
  position: relative;
  color: transparent !important;       /* hide label/icon text, keep box size */
  cursor: progress;
  pointer-events: none;                /* prevent multiple submits */
}

/* Keep icon/label invisible but occupying space (width preserved) */
.btn[data-loading="true"] > svg,
.btn[data-loading="true"] > .btn__icon,
.btn[data-loading="true"] .btn__label,
.btn[aria-busy="true"] > svg,
.btn[aria-busy="true"] > .btn__icon,
.btn[aria-busy="true"] .btn__label {
  visibility: hidden;
}

/* Spinner — centered, inherits the variant's original text color */
.btn[data-loading="true"]::after,
.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  inline-size: 1.15em;
  block-size: 1.15em;
  margin-block-start: -0.575em;
  margin-inline-start: -0.575em;
  border: var(--border-medium) solid currentColor;
  border-inline-end-color: transparent;   /* the gap that reads as motion */
  border-radius: var(--radius-pill);
  color: var(--color-paper);               /* default: light spinner on dark fills */
  animation: btn-spin 0.6s linear infinite;
}

/* Spinner color per variant (spinner uses `color`, label was zeroed) */
.btn-secondary[data-loading="true"]::after,
.btn-secondary[aria-busy="true"]::after,
.btn-outline[data-loading="true"]::after,
.btn-outline[aria-busy="true"]::after,
.btn-ghost[data-loading="true"]::after,
.btn-ghost[aria-busy="true"]::after,
.btn-text[data-loading="true"]::after,
.btn-text[aria-busy="true"]::after {
  color: var(--color-ink);
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}


/* ==========================================================================
   7. ICON BUTTONS
   Left/right icons are handled by source order + the base gap. These classes
   cover icon-only and circular variants, which need a square box.
   ========================================================================== */

/* Icon-only — square, no label. REQUIRES an aria-label in markup. */
.btn-icon {
  gap: 0;
  padding-inline: 0;
  padding-block: 0;
  inline-size: 52px;                   /* matches md height for a square */
  min-block-size: 52px;
  block-size: 52px;
}
.btn-icon > svg,
.btn-icon > .btn__icon {
  inline-size: var(--icon-md);
  block-size: var(--icon-md);
}
.btn-icon.btn-sm {
  inline-size: 40px;
  min-block-size: 40px;
  block-size: 40px;
}
.btn-icon.btn-sm > svg,
.btn-icon.btn-sm > .btn__icon {
  inline-size: var(--icon-sm);
  block-size: var(--icon-sm);
}
.btn-icon.btn-lg {
  inline-size: 60px;
  min-block-size: 60px;
  block-size: 60px;
}
.btn-icon.btn-lg > svg,
.btn-icon.btn-lg > .btn__icon {
  inline-size: var(--icon-lg);
  block-size: var(--icon-lg);
}

/* Circular icon button (social, close, media controls) */
.btn-circle {
  border-radius: var(--radius-pill);
  aspect-ratio: 1 / 1;
}

/* Explicit trailing-icon nudge for text+arrow ghost buttons ("View all ->")
   so the arrow can animate independently on hover. */
.btn-ghost > svg:last-child,
.btn-ghost > .btn__icon:last-child {
  transition: transform var(--dur-base) var(--ease-out);
}
.btn-ghost:hover > svg:last-child,
.btn-ghost:hover > .btn__icon:last-child {
  transform: translateX(var(--space-1));
}


/* ==========================================================================
   8. BUTTON GROUPS
   ========================================================================== */

/* Horizontal group — buttons sit inline with consistent spacing, wrap safely */
.btn-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

/* Equal-width members */
.btn-group-equal > .btn {
  flex: 1 1 0%;
  min-inline-size: 0;
}

/* Vertical stack (any width) */
.btn-group-vertical {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  align-items: stretch;
}
.btn-group-vertical > .btn {
  inline-size: 100%;
}

/* Default groups stack full-width on mobile, go inline from md up.
   Matches WIREFRAMES: hero CTA pairs stack on small screens. */
@media (max-width: 767px) {
  .btn-group-stack {
    flex-direction: column;
    align-items: stretch;
  }
  .btn-group-stack > .btn {
    inline-size: 100%;
  }
}


/* ==========================================================================
   9. ACCESSIBILITY
   Contrast and focus are handled in the variant + state rules (Ink/Paper and
   Flare fills meet WCAG AA; focus ring is always visible via --shadow-focus).
   These rules cover forced-colors and non-pointer input.
   ========================================================================== */

/* Windows High Contrast / forced-colors: keep a visible boundary + focus. */
@media (forced-colors: active) {
  .btn {
    border-color: ButtonText;
  }
  .btn:focus-visible {
    outline: var(--border-thick) solid Highlight;
    outline-offset: 2px;
  }
  .btn[data-loading="true"]::after,
  .btn[aria-busy="true"]::after {
    color: ButtonText;
  }
}

/* Coarse pointers (touch): guarantee the 44px minimum even for sm buttons. */
@media (pointer: coarse) {
  .btn-sm {
    min-block-size: 44px;
  }
  .btn-icon.btn-sm {
    inline-size: 44px;
    min-block-size: 44px;
    block-size: 44px;
  }
}


/* ==========================================================================
   10. MOTION — reduced-motion support
   Transitions above are already short (120–200ms). Here we disable transform,
   underline sweep, arrow nudge, and spinner rotation when the user opts out.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition:
      background-color var(--dur-fast) var(--ease-standard),
      border-color     var(--dur-fast) var(--ease-standard),
      color            var(--dur-fast) var(--ease-standard);
    transform: none !important;
  }
  .btn:hover,
  .btn:active {
    transform: none !important;
  }
  .btn-ghost .btn__label::after {
    transition: none;
  }
  .btn-ghost:hover > svg:last-child,
  .btn-ghost:hover > .btn__icon:last-child {
    transform: none;
  }
  .btn[data-loading="true"]::after,
  .btn[aria-busy="true"]::after {
    animation-duration: 1.2s;   /* keep a slow spin as a progress cue, not a strobe */
  }
}