$button-shadow: 0 0.25rem 0.5rem 0 rgba(0, 0, 0, 0.2);

$info-light-alt: #9DDFEB;
$info-lighter-alt: #E7F6F8;
$info-dark-alt: #009EC1;

$error-light-alt: #FDB8AE;
$error-lightest-alt: #FDE0DB;
$error-dark-alt: #B50909;

.usa-button {
  @include u-text("secondary-darker");
  @include u-border("primary");
  @include u-border-width("2px");
  @include u-minw(15);

  &.usa-button--hover,
  &:hover {
    @include u-bg("primary-light");
    @include u-border("primary-light");
    @include u-border-width("2px");
    @include u-text("secondary-darker");
  }

  &.usa-button--active,
  &:active {
    @include u-bg("primary-dark");
    @include u-border("primary-dark");
    @include u-text("white");
  }

  &.usa-focus,
  &:focus {
    outline-offset: units(2px) !important;
    outline-width: 2px;
  }

  &--unstyled {
    @include u-text($theme-link-color);
    border: none;
    text-decoration: underline;
    min-width: 0px !important;

    &.usa-button--active,
    &:active {
      border: none;
      @include u-bg("transparent");
      @include u-text($theme-link-active-color);
    }

    &.usa-button--hover,
    &:hover {
      border: none;
      @include u-bg("transparent");
      text-decoration: underline;
    }
  }

  &.bg-primary-lighter {
    @include u-border("primary");

    &.usa-button--hover,
    &:hover {
      @include u-text("bold", $theme-link-active-color);
      background-color: white !important;
    }

    &.usa-button--active,
    &:active {
      background-color: white !important;
      @include u-border("primary-dark");
      @include u-text("bold", $theme-link-active-color);
    }

    &:disabled {
      background-color: color("white") !important;
      @include u-text("bold", $theme-color-base);
      @include u-border("base-light");
      box-shadow: none;
    }
  }

  &.bg-secondary-lighter {
    @include u-border("secondary");
    background-color: #adcdff !important;
    @include u-text("bold", $theme-link-active-color);

    &.usa-button--hover,
    &:hover {
      @include u-text("bold", $theme-link-active-color);
      background-color: white !important;
    }

    &.usa-button--active,
    &:active {
      background-color: #adcdff !important;
      @include u-border("secondary-dark");
      @include u-text("bold", $theme-link-active-color);
    }

    &:disabled {
      background-color: color("white") !important;
      @include u-text("bold", $theme-color-base);
      @include u-border("base-light");
      box-shadow: none;
    }
  }

  &.bg-base-lighter {
    @include u-border("base-light");
    @include u-text("bold", $theme-link-active-color);

    &.usa-button--hover,
    &:hover {
      @include u-text("bold", $theme-link-active-color);
      background-color: white !important;
    }

    &.usa-button--active,
    &:active {
      background-color: color("base-lightest") !important;
      @include u-border("base-dark");
      @include u-text("bold", $theme-link-active-color);
    }

    &:disabled {
      background-color: color("white") !important;
      @include u-text("bold", $theme-color-base);
      @include u-border("base-light");
      box-shadow: none;
    }
  }

  &.bg-accent-cool-lighter {
    @include u-border("accent-cool-light");

    &.usa-button--hover,
    &:hover {
      @include u-text("bold", $theme-link-active-color);
      @include u-border("accent-cool");
      background-color: white !important;
    }

    &.usa-button--active,
    &:active {
      background-color: white !important;
      @include u-border("accent-cool-dark");
      @include u-text("bold", $theme-link-active-color);
    }

    &:disabled {
      background-color: color("white") !important;
      @include u-text("bold", $theme-color-base);
      @include u-border("base-light");
      box-shadow: none;
    }
  }

  &.bg-accent-warm-lighter {
    @include u-border("accent-warm-light");

    &.usa-button--hover,
    &:hover {
      @include u-text("bold", $theme-link-active-color);
      @include u-border("accent-warm");
      background-color: white !important;
    }

    &.usa-button--active,
    &:active {
      background-color: white !important;
      @include u-border("accent-warm-dark");
      @include u-text("bold", $theme-link-active-color);
    }

    &:disabled {
      background-color: color("white") !important;
      @include u-text("bold", $theme-color-base);
      @include u-border("base-light");
      box-shadow: none;
    }
  }
}

.usa-button--outline {
  @include u-border("primary");
  background-color: transparent;
  box-shadow: none;

  &:disabled {
    background-color: color("white") !important;
    color: color($theme-color-base) !important;
    font-weight: bold;
    @include u-text("bold", $theme-color-base);

    @include u-border("base-darker");

    &:hover {
      box-shadow: none;
    }
  }

  // Add color variants here
  &.usa-button--secondary {
    @include u-border("secondary");
    @include u-text("bold", $theme-link-active-color);
    background-color: white;

    &:visited {
      color: black;
      box-shadow: none;
    }

    &.usa-button--hover,
    &:hover {
      background-color: color("white");
      @include u-text("bold", $theme-link-active-color);
      border-color: color("secondary-light");
      box-shadow: none;
    }

    &.usa-button--active,
    &:active {
      background-color: color("white");
      @include u-text("bold", $theme-link-active-color);
      border-color: color("secondary-dark");
      box-shadow: none;
    }
  }

  &.usa-button--secondary-light {
    @include u-border("secondary-light");
  }

  &:visited {
    color: color("primary");
  }

  &.usa-button--hover,
  &:hover {
    background-color: transparent;
    box-shadow: none;
  }

  &.usa-button--active,
  &:active {
    background-color: transparent;
    color: color("secondary-darker");
    box-shadow: none;
  }

  // Add color variants for base
  &.usa-button--base {
    @include u-border("base");
    @include u-text("bold", $theme-link-active-color);
    background-color: white;

    &:visited {
      color: black;
      box-shadow: none;
    }

    &.usa-button--hover,
    &:hover {
      background-color: color("white");
      @include u-text("bold", $theme-link-active-color);
      border-color: color("base-light");
      box-shadow: none;
    }

    &.usa-button--active,
    &:active {
      background-color: color("white");
      @include u-text("bold", $theme-link-active-color);
      border-color: color("base-dark");
      box-shadow: none;
    }
  }

  // Add color variants for accent-cool
  &.usa-button--accent-cool {
    @include u-border("accent-cool");
    @include u-text("bold", $theme-link-active-color);
    background-color: white;

    &:visited {
      color: black;
      box-shadow: none;
    }

    &.usa-button--hover,
    &:hover {
      background-color: color("white");
      @include u-text($theme-link-active-color);
      border-color: color("accent-cool-light");
      box-shadow: none;
    }

    &.usa-button--active,
    &:active {
      background-color: color("white");
      @include u-text($theme-link-active-color);
      border-color: color("accent-cool-dark");
      box-shadow: none;
    }
  }

  // Add color variants for accent-warm
  &.usa-button--accent-warm {
    @include u-border("accent-warm");
    @include u-text("bold", $theme-link-active-color);
    background-color: white;

    &:visited {
      color: black;
      box-shadow: none;
    }

    &.usa-button--hover,
    &:hover {
      background-color: color("white");
      @include u-text("bold", $theme-link-active-color);

      border-color: color("accent-warm-light");
      box-shadow: none;
    }

    &.usa-button--active,
    &:active {
      background-color: color("white");
      @include u-text("bold", $theme-link-active-color);
      border-color: color("accent-warm-dark");
      box-shadow: none;
    }
  }

  &.usa-button--inverse {
    background-color: transparent;
    color: color("white");
    box-shadow: none;

    &:visited {
      color: color("base-lighter");
      box-shadow: none;
    }

    &.usa-button--hover,
    &:hover {
      background-color: transparent;
      color: color("base-lightest");
      box-shadow: none;
    }

    &.usa-button--active,
    &:active {
      background-color: transparent;
      color: color("base-light");
      box-shadow: none;
    }

    &:disabled {
      background-color: transparent;
      color: color("base-light");
      box-shadow: none;
    }
  }
}

.usa-button--secondary {
  background-color: color("secondary");
  @include u-border("secondary");
  color: color("white");

  &.usa-button--hover,
  &:hover {
    background-color: color("secondary-light");
    @include u-border("secondary-light");
    color: color("white");
  }

  &.usa-button--active,
  &:active {
    color: color("white");
    background-color: color("secondary-dark");
    @include u-border("secondary-dark");
  }

  &.usa-button--disabled,
  &:disabled {
    color: color("disabled");
    @include u-border("disabled");
    background-color: transparent;
  }
}

.usa-button--base {
  @include u-text("white");
  background-color: color("base");
  @include u-border("base");

  &.usa-button--hover,
  &:hover {
    @include u-text("bold", $theme-link-active-color);
    background-color: color("base-light");
    @include u-border("base-light");
  }

  &.usa-button--active,
  &:active {
    color: color("white");
    background-color: color("base-dark");
    @include u-border("base-dark");
  }
}

.usa-button--accent-cool {
  background-color: color("accent-cool");
  @include u-border("accent-cool");

  &.usa-button--hover,
  &:hover {
    background-color: color("accent-cool-light");
    @include u-border("accent-cool-light");
  }

  &.usa-button--active,
  &:active {
    color: color("white");
    background-color: color("accent-cool-darker");
    @include u-border("accent-cool-darker");
  }
}

.usa-button--info-light {
  background-color: $info-light-alt;
  border-color: $info-light-alt;

  &.usa-button--hover,
  &:hover {
    background-color: $info-lighter-alt;
  border-color: $info-lighter-alt;
  }

  &.usa-button--active,
  &:active {
    color: color("white");
    background-color: $info-dark-alt;
  border-color: $info-dark-alt;
  }
}

.usa-button--error-light {
  background-color: $error-light-alt;
  border-color: $error-light-alt;

  &.usa-button--hover,
  &:hover {
    background-color: $error-lightest-alt;
  border-color: $error-lightest-alt;
  }

  &.usa-button--active,
  &:active {
    color: color("white");
    background-color: $error-dark-alt;
  border-color: $error-dark-alt;
  }
}

.usa-button--accent-warm {
  background-color: color("accent-warm");
  @include u-border("accent-warm");

  &.usa-button--hover,
  &:hover {
    background-color: color("accent-warm-light");
    @include u-border("accent-warm-light");
  }

  &.usa-button--active,
  &:active {
    color: color("white");
    background-color: color("accent-warm-darker");
    @include u-border("accent-warm-darker");
  }
}

.sds-button--circle {
  border-radius: 50%;
  height: units(4);
  width: units(4);
  @include u-minw(0);
  @include u-display("inline-flex");
  @include u-flex("align-center");
  @include u-flex("justify-center");
  margin: unset;
  padding: 0;

  .svg-inline--fa {
    align-self: center;
  }

  &.sds-button--small {
    height: units(3);
    width: units(3);
    padding: 0;
    font-size: size("body", 1);
  }

  &.sds-button--big,
  &.usa-button--big {
    height: units(5);
    width: units(5);
    font-size: size("body", 6);
  }
}

.sds-button--danger {
  background-color: color("error");
  @include u-border("error");

  &.usa-button--hover,
  &:hover {
    background-color: color("error-lighter");
    @include u-border("error-lighter");
  }

  &.usa-button--active,
  &:active {
    color: color("white");
    background-color: color("error-dark");
    @include u-border("error-dark");
  }
}

.sds-button--white {
  background-color: color("white");
  @include u-border("white");
  transition: box-shadow 0.2s ease-out;

  &.usa-button--hover,
  &:hover {
    background-color: color("white");
    @include u-border("white");
    // @include u-shadow(2);
  }

  &.usa-button--active,
  &:active {
    color: color("white");
    background-color: color("base-light");
    @include u-border("base-light");
  }
}

.sds-button,
.usa-button {
  &--disabled,
  &:disabled {
    box-shadow: none;
    @include u-border("disabled");
    @include u-bg("disabled");
    @include u-text("white");
    border-width: 2px !important;
    border-style: solid !important;
    border-color: color("base-light") !important;

    &.sds-button--unstyled,
    &.usa-button--unstyled {
      box-shadow: none;
      @include u-bg("transparent");
      @include u-text("base");
      border: none !important;
      text-decoration: none;
      &:hover {
        font-weight: unset !important;
      }
    }
  }
}

/*******************************
      SDS Specific Styles
*******************************/
/*-------------------
  Basic Button
--------------------*/
.sds-button {
  @include border-box-sizing;
  @include typeset($theme-button-font-family, null, 1);
  @include add-knockout-font-smoothing;
  appearance: none;
  background-color: color("white");
  border: 0;
  border-radius: radius($theme-button-border-radius);
  color: color("secondary-dark");
  cursor: pointer;
  display: inline-block;
  font-weight: font-weight("bold");
  margin-right: units(1);
  padding: units(1.5) units(2.5);
  text-align: center;
  text-decoration: none;

  &:visited {
    color: color("white");
  }

  &.usa-button--hover,
  &:hover {
    text-decoration: none;
  }

  &.usa-button--active,
  &:active {
    box-shadow: inset 0 0 0 1px color("secondary-darker");
  }

  &.usa-focus,
  &:focus {
    outline-offset: units(0.5);
  }

  &:disabled {
    @include button-disabled;
  }
}

// Shadow
.sds-button--shadow {
  box-shadow: $button-shadow;

  &.usa-button--hover,
  &:hover {
    box-shadow: $button-shadow;
  }

  &.usa-button--active,
  &:active {
    box-shadow: $button-shadow;
  }
}

// Size
.sds-button--small,
.usa-button--small {
  @include u-font("sans", "2xs");
  padding: units(1) units(2);
}

/*-------------------
  SDS Button
--------------------*/
.sds-button--primary {
  @include u-bg("primary");
  // @include u-shadow("none");
  box-shadow: none;

  &.usa-button--hover,
  &:hover {
    background-color: color("primary-light");
    color: color("secondary-darker");
  }

  &.usa-button--active,
  &:active {
    background-color: color("secondary-darker");
    color: color("white");
  }

  &.usa-focus,
  &:focus {
    outline-offset: units(2px);
  }
}

/*-------------------
  SDS Button Secondary
--------------------*/
.sds-button--secondary {
  @include u-bg("secondary-dark");
  color: color("white");
  box-shadow: none;

  &.usa-button--hover,
  &:hover {
    background-color: color("secondary-light");
    color: color("white");
  }

  &.usa-button--active,
  &:active {
    background-color: color("secondary-darker");
    color: color("white");
  }

  &.usa-focus,
  &:focus {
    outline-offset: units(2px);
  }
}

/*-------------------
  Circular Buttons - DEPRECATED: Use .sds-button--circle
--------------------*/
.sds-button.sds-button--circular {
  @include u-radius("pill");
  @include u-padding-x("105");

  .svg-inline--fa.fa-fw {
    width: 1.1em;
  }

  &.sds-button--small .svg-inline--fa.fa-fw {
    width: 0.8em;
  }
}

/*-------------------
  Labeled Icon Button
--------------------*/
.sds-button.sds-button--labeled-icon {
  color: color("indigo-cool-70");
  box-shadow: none;
  transition: box-shadow 0.2s ease-out;
  @include u-position("relative");
  @include u-padding-right(5);
  @include u-padding-left(2);

  &.usa-button--hover,
  &:hover {
    // @include u-shadow(2);
    box-shadow: 2px;
  }

  &.usa-button--active,
  &:active {
    color: color("secondary-dark");
    box-shadow: inset 0 0 0 1px color("secondary-darker");

    .fa-layers {
      .fa-circle {
        color: color("secondary-darker") !important;
      }

      .svg-inline--fa:not(.fa-circle) {
        color: color("white");
      }
    }
  }

  .fa-layers {
    @include u-position("absolute");
    font-size: size("body", 10);
    top: 5px;
    right: 5px;

    .fa-circle {
      color: color("primary");
    }

    .svg-inline--fa:not(.fa-circle) {
      color: color("secondary-dark");
    }
  }

  &.sds-button--small {
    @include u-padding-right(4);

    .fa-layers {
      font-size: size("body", 8);
      top: 6px;
    }
  }
}

/*-------------------
  Icon Button
--------------------*/
.sds-button.sds-button--icon {
  width: auto;
  height: fit-content;
  line-height: 1;
  @include u-padding-x(4);
  @include u-radius("lg");
  @include u-display("flex");
  @include u-bg("white");
  @include u-flex("justify-center");

  svg {
    margin-right: units(2);
    width: units(6) !important;
  }

  .sds-button--icon__title {
    margin: auto 0;
    @include u-text("bold");
  }

  &--selected,
  &:hover {
    @include u-border("secondary");
    @include u-border-width("2px");
  }

  &:disabled {
    @include button-disabled;
  }
}

.sds-button--outline {
  border: none;
  border-radius: radius($theme-button-border-radius);
  background-color: white;
  padding: 3px;
  height: 51px;
  width: fit-content;

  .sds-button--icon {
    border: solid 1px color("secondary");
    border-radius: radius($theme-button-border-radius);
    margin: auto;
  }
}

/*-------------------
  Icon Button LG
--------------------*/
.sds-button {
  &.sds-button--icon-lg {
    @include u-padding(2);
    @include u-shadow(2);
    @include u-border(2px);
    @include u-border("accent-cool-light");
    @include u-radius("lg");
    @include u-text("left");
    @include u-margin-y(1);

    .sds-button__header {
      @include u-display("flex");
      @include u-flex("row");
      @include u-flex(1);
      padding-bottom: 0.5rem;
      flex-grow: 0;
      margin: auto;

      h1,
      h2,
      h3,
      h4,
      h5,
      h6 {
        @include u-font("sans", "md");
        @include u-text("bold");
      }

      p {
        @include u-margin-bottom(1);
      }

      span,
      svg {
        @include u-margin-top(0);
        @include u-margin-x(2);
      }
    }

    .sds-button--icon__title {
      @include u-color("base");
      @include u-text("italic");
      @include u-margin-top(1);
      @include u-text("normal");
      flex-wrap: wrap;
    }

    &--selected,
    &:hover {
      @include u-border("secondary");
    }

    &:disabled {
      background-color: "base-light";
      color: color("white");
      box-shadow: none;
    }
  }
}

.sds-button.sds-button--icon-lg {
  height: 100%;
  width: 100%;
  @include u-text("center");
  @include u-display("flex");
  @include u-flex("column");
  align-items: center;

  .usa-tag {
    @include u-text("white");
    @include u-text("no-italic");
    @include u-margin-x("auto");
    @include u-padding-y(1);
  }

  .sds-button__body {
    @include u-text("center");
    @include u-display("flex");
    @include u-flex("column");
    flex-grow: 1;
  }
}

.usa-button-pill {
  @include u-radius("pill");
  @include u-display("flex");
  @include u-flex('align-center'); // Vertically align items in the center
  @include u-flex('justify-center'); // Horizontally center content

  svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    stroke-width: 1px;
    stroke: color("secondary-darker");
    @include u-margin-top(3px);
  }
  &.usa-button:active svg,
  &.usa-button:disabled svg,
  &.usa-button--active svg {
    stroke: color("white");
  }

  &.bg-primary-lighter {
    svg {
      @include u-margin-top(2px);
    }
    &:active svg,
    &.usa-button--active svg {
      stroke: color("secondary-darker");
    }
    &:disabled svg {
      stroke: color("base");
    }
  }

  &.usa-button--base {
    svg {
      @include u-margin-top(2px);
      height: 14px !important;
      width: 14px !important;
      stroke: color("ink");
    }
    &:active svg {
      stroke: color("ink");
    }
    &:disabled svg {
      stroke: color("base");
    }
  }
}
.space-x-1 > * + * {
  margin-left: 8px;
}
