/* @group Buttons */

input[type='submit'] {
  appearance: none;
}

.button {
  position: relative;
  display: inline-block;
  box-sizing: border-box;
  min-width: var(--ui-control-height);
  height: var(--ui-control-height);
  margin-block-start: var(--ui-space-2);
  margin-block-end: var(--ui-space-2);
  padding: 0 var(--ui-space-4);
  overflow: hidden;
  color: var(--color-button-text);
  font-family: var(--ui-font-family);
  font-size: var(--ui-font-size-control);
  font-weight: var(--ui-weight-medium);
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
  background-color: var(--color-button-background);
  background-image: none;
  border: none;
  border-radius: var(--ui-radius-control);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: color var(--ui-duration-feedback) var(--ui-ease-feedback), background-color var(--ui-duration-feedback) var(--ui-ease-feedback), border-color var(--ui-duration-feedback) var(--ui-ease-feedback), box-shadow var(--ui-duration-feedback) var(--ui-ease-feedback);
  vertical-align: middle;
}

/* Native hidden state must win over the shared inline-block presentation. */
.button[hidden] {
  display: none;
}

.button span {
  display: flex;
  flex-flow: row nowrap;
  place-content: stretch center;
  align-items: center;
  height: 100%;
}

.button[disabled]:hover,
.button[disabled]:focus,
.button[disabled]:active {
  color: var(--color-button-flat-text);
  background-color: var(--color-button-background);
}

.button.flat {
  color: var(--color-button-flat-text);
  background-color: transparent;
}

.button.flat:hover,
.button.flat:focus,
.button.flat:active {
  color: var(--color-button-flat-text);
  background-color: var(--color-surface-muted);
}

.button.flat[disabled]:hover,
.button.flat[disabled]:focus,
.button.flat[disabled]:active {
  color: var(--color-button-flat-text);
  background-color: transparent;
}

.button:hover,
.button:focus,
.button:active {
  color: var(--color-button-flat-text);
  text-decoration: none;
  outline: 0;
}

.button:hover,
.button:focus {
  box-shadow: none;
}

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
  .button:hover,
  .button:focus {
    box-shadow: 0 -1px 2px rgb(0 0 0 / 12%), -1px 0 2px rgb(0 0 0 / 12%), 0 0 2px rgb(0 0 0 / 12%), 0 2px 2px rgb(0 0 0 / 20%);
  }
}

.button:active:hover {
  box-shadow: inset 0 1px 2px rgb(0 0 0 / 12%);
}

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
  .button:active:hover {
    box-shadow: 0 -1px 2px rgb(0 0 0 / 12%), -1px 0 2px rgb(0 0 0 / 12%), 0 10px 20px rgb(0 0 0 / 19%), 0 6px 6px rgb(0 0 0 / 23%);
  }
}

.button:disabled,
.button[aria-disabled='true'],
.button.disabled {
  box-shadow: none;
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

.button + .button {
  margin-inline-start: var(--ui-space-2);
}

.flat {
  background-color: transparent;
}

.flat:hover,
.flat:focus,
.flat:active,
.flat:active:hover {
  background-color: var(--color-button-hover);
  box-shadow: none;
}

.raised {
  box-shadow: none;
}

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
  .raised {
    box-shadow: 0 -1px 2px rgb(0 0 0 / 12%), -1px 0 2px rgb(0 0 0 / 12%), 0 0 2px rgb(0 0 0 / 12%), 0 2px 2px rgb(0 0 0 / 20%);
  }
}

.raised:active {
  box-shadow: inset 0 1px 2px rgb(0 0 0 / 12%);
}

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
  .raised:active {
    box-shadow: 0 -1px 2px rgb(0 0 0 / 12%), -1px 0 2px rgb(0 0 0 / 12%), 0 10px 20px rgb(0 0 0 / 19%), 0 6px 6px rgb(0 0 0 / 23%);
  }
}

/* While a form owns its request the spinner takes the label's place, centred
   in the label's colour. The label stays (unpainted), so the button keeps its
   size and accessible name. */
.button.ui-submitting {
  opacity: 1;
  cursor: progress;
  -webkit-text-fill-color: transparent;
}

.button.ui-submitting > .dpg-spinner {
  position: absolute;
  inset-block-start: calc(50% - var(--spinner-size) / 2);
  inset-inline-start: calc(50% - var(--spinner-size) / 2);
  color: currentcolor;
  pointer-events: none;
}

.button.negative {
  color: var(--color-text-inverse);
  background-color: var(--color-negative);
}

.button.negative:hover,
.button.negative:focus,
.button.negative:active {
  color: var(--color-text-inverse);
  background-color: var(--color-negative-state-one);
}

.button.negative.hollow {
  color: var(--color-negative);
  background-color: transparent;
  border: 2px solid var(--color-negative);
}

.button.negative.hollow:hover,
.button.negative.hollow:focus,
.button.negative.hollow:active {
  color: var(--color-negative-state-one);
  background-color: transparent;
  border: 2px solid var(--color-negative-state-one);
}

.button.positive {
  color: var(--color-button-positive-text);
  background-color: var(--color-positive);
}

.button.positive:hover,
.button.positive:focus,
.button.positive:active {
  color: var(--color-button-positive-text);
  background-color: var(--color-positive-state-one);
}

.button.positive[disabled]:hover,
.button.positive[disabled]:focus,
.button.positive[disabled]:active {
  color: var(--color-button-positive-text);
  background-color: var(--color-positive);
}

.button.positive.flat {
  color: var(--color-button-positive-quiet-text);
  background-color: transparent;
}

.button.positive.flat:hover,
.button.positive.flat:focus,
.button.positive.flat:active {
  color: var(--color-button-positive-quiet-text);
  background-color: var(--color-surface-muted);
}

.button.positive.flat[disabled]:hover,
.button.positive.flat[disabled]:focus,
.button.positive.flat[disabled]:active {
  color: var(--color-button-positive-quiet-text);
  background-color: transparent;
}

.button.positive.hollow {
  color: var(--color-button-positive-quiet-text);
  background-color: transparent;
  border: 2px solid currentcolor;
}

.button.positive.hollow:hover,
.button.positive.hollow:focus,
.button.positive.hollow:active {
  color: var(--color-button-positive-quiet-text);
  background-color: var(--color-surface-muted);
  border: 2px solid currentcolor;
}

.button.neutral {
  color: var(--color-button-neutral-text);
  background-color: var(--color-button-neutral-background);
}

.button.neutral:hover,
.button.neutral:focus,
.button.neutral:active {
  color: var(--color-button-neutral-hover-text);
  background-color: var(--color-neutral-state-one);
}

.button.neutral.flat {
  color: var(--color-button-neutral-quiet-text);
  background-color: transparent;
}

.button.neutral.flat:hover,
.button.neutral.flat:focus,
.button.neutral.flat:active {
  color: var(--color-button-neutral-quiet-text);
  background-color: var(--color-surface-muted);
}

.button.neutral.hollow {
  color: var(--color-button-neutral-quiet-text);
  background-color: transparent;
  border: 2px solid currentcolor;
}

.button.neutral.hollow:hover,
.button.neutral.hollow:focus,
.button.neutral.hollow:active {
  color: var(--color-button-neutral-quiet-text);
  background-color: var(--color-surface-muted);
  border: 2px solid currentcolor;
}

.button.neutral.flat[disabled]:hover,
.button.neutral.flat[disabled]:focus,
.button.neutral.flat[disabled]:active {
  color: var(--color-button-neutral-quiet-text);
  background-color: transparent;
}

.button.grey.hollow {
  color: var(--color-text);
  background-color: transparent;
  border: 1px solid var(--color-input-border);
}

.button.grey.hollow:hover,
.button.grey.hollow:focus,
.button.grey.hollow:active {
  color: var(--color-text);
  background-color: var(--color-surface-muted);
  border: 1px solid var(--color-input-border);
}

.button.grey.flat[disabled]:hover,
.button.grey.flat[disabled]:focus,
.button.grey.flat[disabled]:active {
  color: var(--color-danger-accent);
  background-color: transparent;
}

.button.input {
  box-sizing: border-box;
  min-width: 30px;
  height: var(--ui-control-height-inline);
  margin-block-start: var(--ui-space-1);
  margin-block-end: var(--ui-space-2);
  padding: 0 var(--ui-space-3);
  font-size: var(--ui-font-size-small);
  border-radius: 0;
}

.button.input:hover,
.button.input:active,
.button.input:focus {
  box-shadow: none;
}

.button.small {
  height: var(--ui-control-height-compact);
  padding: 0 var(--ui-space-4);
  font-size: var(--ui-font-size-label);
}

.button.small.hollow {
  height: var(--ui-control-height-compact);
  padding: 0 var(--ui-space-4);
  font-size: var(--ui-font-size-label);
}

.button.large {
  height: var(--ui-control-height-large);
  padding: 0 var(--ui-space-4);
  font-size: var(--ui-font-size-control);
}

.buttons {
  position: relative;
  display: flex;
  flex-flow: row wrap;
  place-content: stretch flex-end;
  align-items: center;
  gap: var(--ui-action-gap);
  margin-block-start: var(--ui-space-4);
  padding-block-start: var(--ui-space-4);
  border-block-start: 1px solid var(--color-border-faint);
}

.buttons .button + .button {
  margin-inline-start: 0;
}

/* The icon's box is Font Awesome 7's own fixed width. The button is then the
   same width before the icon face arrives as after it (RULES §24.2). */
.button.with_icon > span::before {
  display: inline-block;
  width: 1.25em;
  margin-inline-end: var(--ui-space-1);
  font-family: var(--ui-icon-font-family);
  font-weight: var(--ui-icon-weight);
  text-align: center;
}

.button.with_icon.locked > span::before {
  content: var(--ui-icon-lock) var(--ui-icon-alt,);
}

.button.with_icon.settings > span::before {
  content: var(--ui-icon-gear) var(--ui-icon-alt,);
}

.button.with_icon.remove > span::before {
  content: var(--ui-icon-trash-can) var(--ui-icon-alt,);
}

.button.with_icon.edit > span::before {
  content: var(--ui-icon-pen) var(--ui-icon-alt,);
}

.button.with_icon.clone > span::before {
  content: var(--ui-icon-copy) var(--ui-icon-alt,);
}

.button.with_icon.extend > span::before {
  content: var(--ui-icon-calendar-plus) var(--ui-icon-alt,);
}

.button.with_icon.download > span::before {
  content: var(--ui-icon-download) var(--ui-icon-alt,);
}

.button.with_icon.track > span::before {
  content: var(--ui-icon-crosshairs) var(--ui-icon-alt,);
}

.button.with_icon.add > span::before {
  content: var(--ui-icon-plus) var(--ui-icon-alt,);
}

.button.with_icon.email > span::before {
  content: var(--ui-icon-envelope) var(--ui-icon-alt,);
}

.button.with_icon.share > span::before {
  content: var(--ui-icon-share-nodes) var(--ui-icon-alt,);
}

.button.with_icon.refresh > span::before {
  content: var(--ui-icon-arrows-rotate) var(--ui-icon-alt,);
}

.button.with_icon.support > span::before {
  content: var(--ui-icon-circle-question) var(--ui-icon-alt,);
}

.button.with_icon.example > span::before {
  content: var(--ui-icon-palette) var(--ui-icon-alt,);
}

.button.with_icon.upload > span::before {
  content: var(--ui-icon-upload) var(--ui-icon-alt,);
}

.button.with_icon.images > span::before {
  content: var(--ui-icon-images) var(--ui-icon-alt,);
}

/* @end */

/* Keyboard focus must remain distinct from hover in every button variant. */
.button:focus-visible,
.button:has(input[type='file']:focus-visible) {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* Include hybrid devices: connecting a trackpad must not shrink touch targets. */
@media (any-pointer: coarse) {
  .button {
    min-height: var(--ui-touch-target);
  }

  .button.input {
    min-width: var(--ui-touch-target);
  }
}

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }
}
