@import "../base/media-queries.pcss.css";

/**
 * @file
 * Structural styles for Claro's UI buttons
 *
 * Apply these classes to button elements (<button>, <input type="button" />).
 */

/**
 * Buttons.
 *
 * 1. Padding widths detracted by width of the transparent borders to make
 *    button size match with design system.
 * 2. Prevent fat text in WebKit.
 *
 * @todo Consider moving box-sizing into base.css under a universal selector.
 * See https://www.drupal.org/node/2124251
 */

/**
 * Base button styles.
 *
 * These styles have been duplicated to dropbutton.css and action-links.css
 * since those components inherits most of these design elements. Whenever
 * making changes to this file, remember to check if that needs to be applied to
 * dropbutton.css or action-links.css as well.
 */
.button,
.project__action_button {
  display: inline-block;
  margin-block: var(--space-m);
  margin-inline: 0 var(--space-s);
  padding-block: calc(var(--gin-spacing-s) - 2px);
  padding-inline: var(--gin-spacing-m);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  color: var(--gin-color-primary);
  border: 2px solid var(--gin-color-primary);
  border-radius: var(--gin-border-m);
  background-color: transparent;
  box-shadow: 0 1px 2px var(--gin-color-primary-light);
  font-size: var(--gin-font-size-s);
  font-weight: var(--gin-font-weight-semibold);
  line-height: 1;
  appearance: none;

  &:hover {
    text-decoration: none;
    color: var(--gin-color-button-text);
    border-color: var(--gin-color-primary-hover);
    background-color: var(--gin-color-primary-hover);
  }

  &:active {
    color: var(--gin-color-button-text);
    border-color: var(--gin-color-primary-active);
    background-color: var(--gin-color-primary-active);
  }

  @media (prefers-reduced-motion: no-preference) {
    transition: var(--gin-transition);
  }
}

.form-actions .button {
  margin-inline-end: var(--gin-spacing-xs);
}

/* Common styles for small buttons. */
.no-touchevents {
  & .button--small {
    min-height: 2rem;
    font-size: var(--font-size-xs);
    margin-block: var(--space-s);
    margin-inline: 0 var(--space-xs);
    padding-block: var(--space-xs);
    padding-inline: var(--space-s);
  }

  /* Common styles for extra small buttons. */
  & .button--extrasmall {
    min-height: 1.5rem;
    font-size: var(--font-size-xxs);
    margin-block: var(--space-xs);
    margin-inline: 0 var(--space-xs);
    padding-block: var(--space-xxs);
    padding-inline: var(--space-xs);
  }
}

.button.button--small {
  border-radius: var(--gin-border-s);
  font-size: var(--gin-font-size-xxs);
  padding-block: calc(var(--gin-spacing-xxs) + 2px);
  padding-inline: var(--gin-spacing-s);
}

/* Common styles for extra small buttons. */
.button.button--extrasmall {
  border-radius: var(--gin-border-s);
  font-size: var(--gin-font-size-xxs);
  padding-block: var(--gin-spacing-xxs);
  padding-inline: var(--gin-spacing-s);
}

/* Styles for action link buttons. */
.button--action {
  margin: 0;

  &::before {
    margin-inline: -0.25em 0;
    padding-inline: 0 0.25em;
    content: "+";
    font-weight: 900;
  }
}

/* Primary button styles. */
#edit-submit.form-submit,
.button--primary,
.button--primary:not(:focus),
.ief-entity-submit {
  background: var(--gin-color-primary);
  box-shadow: 0.1em 0.25em 0.5em var(--gin-color-primary-light);

  &:hover {
    color: var(--gin-color-button-text);
    background-color: var(--gin-color-primary-hover);
  }

  &:active {
    color: var(--gin-color-button-text);
    background-color: var(--gin-color-primary-active);
  }

  &,
  &:hover,
  &:active {
    color: var(--gin-color-button-text);
  }
}

/* Danger button styles */
.button--danger {
  color: var(--button-fg-color--danger);
  border-color: transparent;

  &:is(:hover, :active) {
    color: var(--button-fg-color--danger);
    border-color: var(--gin-color-danger);
    background-color: var(--button--hover-bg-color--danger);
  }
}

a.button:hover,
a.button:active {
  color: var(--gin-color-button-text);
}

a.button--primary:hover,
a.button--primary:active {
  .gin--dark-mode & {
    color: var(--gin-bg-app);
  }
}

/**
 * Disabled state styles as last.
 *
 * Overrides every definitions before, including variants.
 */
.button.button:disabled,
.button.button.is-disabled {
  &,
  &:hover,
  &:active {
    color: var(--gin-color-disabled);
    border: 2px solid var(--gin-color-disabled-border) !important;
    background: transparent;
    box-shadow: none;
  }

  /* Make disabled <link> behave like a [disabled] <input> or <button>. */
  &.is-disabled {
    user-select: none;
    pointer-events: none;
  }
}

.button.button--primary:disabled,
.button.button--primary.is-disabled {
  &,
  &:hover,
  &:active {
    color: var(--gin-color-disabled);
    background-color: var(--gin-color-disabled-bg);
  }
}

/**
 * Style a clickable/tappable element as a link. Duplicates the base style for
 * the <a> tag, plus a reset for padding, borders and background.
 */
.link {
  display: inline;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  border: 0;
  background: none;
  appearance: none;
}

/* Autocomplete field remove button. */
.multiple-fields-remove-button.button {
  border: 0 none !important;
  mask-image: var(--admin-icon-remove);
  mask-size: 16px 16px;
  mask-repeat: no-repeat;
  mask-position: center center;
}
