/**
 * @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 {
  display: inline-block;
  margin-block: var(--space-m);
  margin-inline: 0 var(--space-s);
  padding-block: var(--space-s);
  padding-inline: var(--space-m);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  color: var(--button-fg-color);
  border: 1px solid var(--button-border-color);
  border-radius: var(--button-border-radius-size);
  background-color: var(--button-bg-color);
  font-size: var(--button-font-size);
  font-weight: var(--button-font-weight);
  line-height: 1;
  appearance: none;

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

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

  &:focus {
    text-decoration: none;
    box-shadow: var(--focus-ring);
  }

  &:active {
    border-color: var(--button--active-border-color);
    background-color: var(--button--active-bg-color);
  }
}

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

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

/* 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 style.s */
.button--primary {
  color: var(--button-fg-color--primary);
  border-color: transparent;
  background-color: var(--button-bg-color--primary);

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

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

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

/**
 * Disabled state styles as last.
 *
 * Overrides every definitions before, including variants.
 */
.button {
  &:is(:disabled, .is-disabled) {
    color: var(--button--disabled-fg-color);
    background-color: var(--button--disabled-bg-color);
  }

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

/**
 * 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;
}
