.button {
  /* Its colours, which the kinds of button change and which fade while it's disabled */
  --button-fg: var(--button-text-color);
  --button-bg: var(--button-color);

  display: inline-block;
  padding: var(--space-1) var(--space-4);

  color: var(--button-fg);
  font-size: var(--fs-body);
  line-height: 1.5;
  text-decoration: none;
  white-space: nowrap;

  background-color: var(--button-bg);
  border-radius: var(--radius-m);
  cursor: pointer;

  transition: transform 0.2s ease-out,
              box-shadow 0.2s ease-out,
              background-color 0.2s ease-out;

  @media (hover: hover) {
    &:hover:not(:disabled, [aria-disabled="true"]) {
      --button-bg: var(--button-hover-color);

      transform: translateY(-1px);
      box-shadow: 0 4px 8px 0 var(--drop-shadow-color);
      color: var(--button-fg);
      text-decoration: none;
    }
  }

  &.secondary {
    --button-bg: var(--bg-color);

    border: 1px solid var(--border-color);

    @media (hover: hover) {
      &:hover:not(:disabled, [aria-disabled="true"]) {
        --button-bg: var(--bg-color);
      }
    }
  }

  /* An icon, with or without a label beside it */
  &:has(.icon) {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
  }

  .icon svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  &.icon-only {
    padding: var(--space-1);

    .icon svg {
      width: 1.5rem;
      height: 1.5rem;
    }
  }

  /* Deletes something */
  &.danger {
    --button-fg: var(--danger-color);
  }

  /* Can't be used yet, such as an action for selected items while none are. A panel's button can't be disabled, so it
     only says so. After the kinds of button, to fade any. Its colours fade rather than all of it, as opacity would fade
     its tooltip too */
  &:is(:disabled, [aria-disabled="true"]) {
    color: color-mix(in srgb, var(--button-fg) 40%, transparent);
    background-color: color-mix(in srgb, var(--button-bg) 40%, transparent);
    border-color: color-mix(in srgb, var(--border-color) 40%, transparent);
    cursor: not-allowed;
  }
}

/* A button or link whose action is under way, such as sending its form or starting a download. A spinner takes the
   place of its icon, or goes before its label */
:is(a, button).sending {
  cursor: progress;

  .icon {
    position: relative;

    svg {
      visibility: hidden;
    }
  }

  .icon::after, &:not(:has(.icon))::before {
    content: "";
    background-color: currentColor;
    mask: url("/assets/icons/progress_activity-b600a072.svg") center / contain no-repeat;
    animation: spin 0.8s linear infinite;
  }

  .icon::after {
    position: absolute;
    inset: 0;
  }

  &:not(:has(.icon)) {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);

    &::before {
      width: 1.25rem;
      height: 1.25rem;
    }
  }
}
