@use '../../00-settings/settings' as *;
@use '../../00-mixins/mixins' as *;

/* stylelint-disable no-descending-specificity */

// Needed for smooths scrolling on iphone / ipad inside modals.
// Placing it on .modal is not sufficient for safari.
* {
  -webkit-overflow-scrolling: touch; // stylelint-disable-line  property-no-vendor-prefix
}

.modal {
  @include tablet-and-below {
    @include theme('background-color', 'color-none', 'modal-background');
  }

  @include tablet {
    animation: fade .2s ease-in-out;
  }

  display: flex;
  visibility: hidden;
  position: fixed;
  z-index: z('modal', 'base');
  inset: 0;
  max-height: 100vh;
  overflow-y: auto;

  // states
  &.visible {
    visibility: visible;

    @include tablet {
      .modal-overlay {
        display: block;
      }
    }
  }

  // modifiers
  &.modal--fixed-height {
    &.visible > .modal-inner {
      max-height: 80vh;

      @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { // stylelint-disable-line  property-no-vendor-prefix
        height: 80vh; // IE fix
      }
    }

    > .modal-inner {
      > .modal-content {
        z-index: z('modal', 'inner');
        flex-grow: 1;
        overflow-y: auto;
      }

      > .modal-actions {
        padding-top: 30px;
      }
    }
  }

  // children
  &.visible .modal-inner {
    display: flex;
    position: absolute;
    z-index: z('modal', 'content');
    top: 0;
    left: 0;
    flex-direction: column;
    width: 100%;
    min-height: 100%;
    margin: 0 auto;

    @include tablet {
      right: 0;
      width: 970px;
      max-width: calc(100% - #{$gutter-width * 2});
      height: auto;
      min-height: 0;
      margin: 10vh auto 0;
      padding-bottom: $gutter-width;
      animation: fade .2s ease-in-out forwards;
      animation-delay: .1s;
      opacity: 0;
    }

    > * {
      @include theme('background-color', 'color-none', 'modal-inner-background');

      &:first-of-type {
        border-top-left-radius: border-radius('radius-2');
        border-top-right-radius: border-radius('radius-2');
      }

      &:last-of-type {
        border-bottom-right-radius: border-radius('radius-2');
        border-bottom-left-radius: border-radius('radius-2');
      }
    }
  }

  ///
  /// Header
  ///
  &-header {
    display: block;
    flex-shrink: 0;
    text-align: right;
  }

  ///
  /// Content
  ///
  &-content {
    padding: 16px 20px;

    @include tablet {
      padding: 16px 70px 60px;
    }

    figure {
      img {
        width: auto;
      }
    }

    p {
      &:last-child {
        margin-bottom: 0;
      }
    }
  }

  ///
  /// Actions
  ///
  &-actions {
    @include theme('border-color', 'color-primary-light', 'modal-action-border-bottom');
    @include theme('background-color', 'color-none', 'modal-action-background-color');

    display: flex;
    z-index: z('modal', 'actions');
    flex-shrink: 0;
    align-items: center;
    width: 100%;
    padding: 30px 20px;

    @include tablet {
      position: relative;
      margin-top: -15px;
      padding: 0 70px 30px;
    }
  }

  ///
  /// Overlay
  ///
  .modal-overlay {
    display: none;
    position: fixed;
    z-index: z('modal', 'overlay');
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: .9;

    &,
    &:hover,
    &:focus {
      @include theme('background-color', 'color-tertiary-light', 'modal-overlay-background-color');
    }
  }
}

@keyframes fade {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}
