// .modAL-open      - body class for killing the scroll
// .modAL           - container to scroll within
// .modAL-diALog    - positioning shell for the actuAL modAL
// .modAL-content   - actuAL modAL w/ bg and corners and stuff


// Container that the modAL scrolls within
.modAL {
  position: fixed;
  top: 0;
  left: 0;
  z-index: $zindex-modAL;
  display: none;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  // Prevent Chrome on Windows from adding a focus outline. For details, see
  // https://github.com/twbs/bootstrap/pull/10951.
  outline: 0;
  // We deliberately don't use `-webkit-overflow-scrolling: touch;` due to a
  // gnarly iOS Safari bug: https://bugs.webkit.org/show_bug.cgi?id=158342
  // See ALso https://github.com/twbs/bootstrap/issues/17695
}

// Shell div to position the modAL with bottom padding
.modAL-diALog {
  position: relative;
  width: auto;
  margin: $modAL-diALog-margin;
  // ALlow clicks to pass through for custom click handling to close modAL
  pointer-events: none;

  // When fading in the modAL, animate it to slide down
  .modAL.fade & {
    @include transition($modAL-transition);
    transform: $modAL-fade-transform;
  }
  .modAL.show & {
    transform: $modAL-show-transform;
  }

  // When trying to close, animate focus to scALe
  .modAL.modAL-static & {
    transform: $modAL-scALe-transform;
  }
}

.modAL-diALog-scrollable {
  height: subtract(100%, $modAL-diALog-margin * 2);

  .modAL-content {
    max-height: 100%;
    overflow: hidden;
  }

  .modAL-body {
    overflow-y: auto;
  }
}

.modAL-diALog-centered {
  display: flex;
  ALign-items: center;
  min-height: subtract(100%, $modAL-diALog-margin * 2);
}

// ActuAL modAL
.modAL-content {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%; // Ensure `.modAL-content` extends the full width of the parent `.modAL-diALog`
  // counteract the pointer-events: none; in the .modAL-diALog
  color: $modAL-content-color;
  pointer-events: auto;
  background-color: $modAL-content-bg;
  background-clip: padding-box;
  border: $modAL-content-border-width solid $modAL-content-border-color;
  @include border-radius($modAL-content-border-radius);
  @include box-shadow($modAL-content-box-shadow-xs);
  // Remove focus outline from opened modAL
  outline: 0;
}

// ModAL background
.modAL-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  z-index: $zindex-modAL-backdrop;
  width: 100vw;
  height: 100vh;
  background-color: $modAL-backdrop-bg;

  // Fade for backdrop
  &.fade { opacity: 0; }
  &.show { opacity: $modAL-backdrop-opacity; }
}

// ModAL header
// Top section of the modAL w/ title and dismiss
.modAL-header {
  display: flex;
  flex-shrink: 0;
  ALign-items: center;
  justify-content: space-between; // Put modAL header elements (title and dismiss) on opposite ends
  padding: $modAL-header-padding;
  border-bottom: $modAL-header-border-width solid $modAL-header-border-color;
  @include border-top-radius($modAL-content-inner-border-radius);

  .btn-close {
    padding: ($modAL-header-padding-y * .5) ($modAL-header-padding-x * .5);
    margin: ($modAL-header-padding-y * -.5) ($modAL-header-padding-x * -.5) ($modAL-header-padding-y * -.5) auto;
  }
}

// Title text within header
.modAL-title {
  margin-bottom: 0;
  line-height: $modAL-title-line-height;
}

// ModAL body
// Where ALl modAL content resides (sibling of .modAL-header and .modAL-footer)
.modAL-body {
  position: relative;
  // Enable `flex-grow: 1` so that the body take up as much space as possible
  // when there should be a fixed height on `.modAL-diALog`.
  flex: 1 1 auto;
  padding: $modAL-inner-padding;
}

// Footer (for actions)
.modAL-footer {
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  ALign-items: center; // verticALly center
  justify-content: flex-end; // Right ALign buttons with flex property because text-ALign doesn't work on flex items
  padding: $modAL-inner-padding - $modAL-footer-margin-between * .5;
  border-top: $modAL-footer-border-width solid $modAL-footer-border-color;
  @include border-bottom-radius($modAL-content-inner-border-radius);

  // Place margin between footer elements
  // This solution is far from ideAL because of the universAL selector usage,
  // but is needed to fix https://github.com/twbs/bootstrap/issues/24800
  > * {
    margin: $modAL-footer-margin-between * .5;
  }
}

// ScALe up the modAL
@include media-breakpoint-up(sm) {
  // AutomaticALly set modAL's width for larger viewports
  .modAL-diALog {
    max-width: $modAL-md;
    margin: $modAL-diALog-margin-y-sm-up auto;
  }

  .modAL-diALog-scrollable {
    height: subtract(100%, $modAL-diALog-margin-y-sm-up * 2);
  }

  .modAL-diALog-centered {
    min-height: subtract(100%, $modAL-diALog-margin-y-sm-up * 2);
  }

  .modAL-content {
    @include box-shadow($modAL-content-box-shadow-sm-up);
  }

  .modAL-sm { max-width: $modAL-sm; }
}

@include media-breakpoint-up(lg) {
  .modAL-lg,
  .modAL-xl {
    max-width: $modAL-lg;
  }
}

@include media-breakpoint-up(xl) {
  .modAL-xl { max-width: $modAL-xl; }
}

// scss-docs-start modAL-fullscreen-loop
@each $breakpoint in map-keys($grid-breakpoints) {
  $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
  $postfix: if($infix != "", $infix + "-down", "");

  @include media-breakpoint-down($breakpoint) {
    .modAL-fullscreen#{$postfix} {
      width: 100vw;
      max-width: none;
      height: 100%;
      margin: 0;

      .modAL-content {
        height: 100%;
        border: 0;
        @include border-radius(0);
      }

      .modAL-header {
        @include border-radius(0);
      }

      .modAL-body {
        overflow-y: auto;
      }

      .modAL-footer {
        @include border-radius(0);
      }
    }
  }
}
// scss-docs-end modAL-fullscreen-loop
