/*
 * Every action. A <button>, or an <a> when the action navigates.
 * Variants only swap the --button-* properties; the base rule draws the shape once.
 * Without a variant the button looks like --secondary.
 * Loading keeps the label (aria-busy="true") so the width does not jump and the screen reader
 * still announces the action; the static ring follows docs/DESIGN.md, Tokens (nothing loops forever).
 */
@layer components {
  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: calc(var(--space-8) + var(--space-3));
    padding: var(--space-2) var(--space-4);
    border: var(--border-width) solid var(--button-border, var(--color-border-strong));
    border-radius: var(--radius-md);
    background: var(--button-bg, var(--color-surface));
    color: var(--button-fg, var(--color-action));
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    line-height: var(--leading-tight);
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: transform var(--duration-fast) var(--ease-out);

    & svg {
      flex: none;
      inline-size: 1.25em;
      block-size: 1.25em;
    }
  }

  .button:hover {
    background: var(--button-bg-hover, var(--color-action-tint));
    color: var(--button-fg, var(--color-action));
  }

  .button:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
  }

  .button:active {
    background: var(--button-bg-hover, var(--color-action-tint));
    transform: translateY(1px);
  }

  .button--primary {
    --button-bg: var(--color-action);
    --button-bg-hover: var(--color-action-hover);
    --button-fg: var(--color-on-action);
    --button-border: var(--color-action);
  }

  .button--secondary {
    --button-bg: var(--color-surface);
    --button-bg-hover: var(--color-action-tint);
    --button-fg: var(--color-action);
    --button-border: var(--color-border-strong);
  }

  .button--ghost {
    --button-bg: transparent;
    --button-bg-hover: var(--color-action-tint);
    --button-fg: var(--color-action);
    --button-border: transparent;
  }

  .button--danger {
    --button-bg: var(--color-danger);
    --button-bg-hover: var(--color-danger-strong);
    --button-fg: var(--color-on-action);
    --button-border: var(--color-danger);
  }

  .button--sm {
    min-height: var(--space-8);
    padding: var(--space-1) var(--space-3);
    gap: var(--space-1);
  }

  .button--block {
    display: flex;
    width: 100%;
  }

  /* Icon only: a square the height of the control; the label lives in aria-label. */
  .button--icon {
    inline-size: calc(var(--space-8) + var(--space-3));
    padding: 0;

    &.button--sm {
      inline-size: var(--space-8);
    }
  }

  /* Native disabled on <button>; aria-disabled only on an <a> that cannot navigate yet. */
  .button:disabled,
  .button[aria-disabled="true"] {
    border-color: var(--color-border);
    background: var(--color-surface-sunken);
    color: var(--color-text-muted);
    cursor: not-allowed;
    transform: none;
  }

  .button[aria-busy="true"] {
    cursor: progress;
    transform: none;

    &::before {
      content: "";
      flex: none;
      inline-size: 1em;
      block-size: 1em;
      border: 0.15em solid currentColor;
      border-block-start-color: transparent;
      border-radius: var(--radius-full);
      transform: rotate(45deg);
    }
  }
}
