// Modal Dialog and Messages
//================================================== //

// Dependencies
// icons/icons

// NOTE: this element gets a margin dynamically set in the "resize" method of modal.js
.modal-wrapper {
  align-items: center;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  margin: 0 auto;
  position: absolute;
  width: 100%;
}

.modal-page-container {
  height: 100%;
  left: 0;
  position: absolute;
  top: 0;
  width: 100%;

  &[aria-hidden='true'] {
    pointer-events: none;

    .modal-wrapper {
      display: none;
    }
  }
}

// Extra Class to hide the header and keep the padding
.modal-no-header {
  .modal-title {
    display: none !important;
  }

  .modal-header {
    padding: 0 0 5px;
  }

  .modal-buttonset {
    margin-top: 2px;
  }
}

.modal {
  @include css3(transform, scale(0.9, 0.9));
  @include css3(transition, opacity 0.2s, transform 0.2s);

  //Added after size calc
  bottom: 0;
  height: auto;
  max-height: 90%;
  max-width: 100%;
  min-width: 200px;
  opacity: 0;
  pointer-events: none;
  position: relative;
  vertical-align: middle;
  z-index: 1001;
  width: 100%;

  @media screen and (min-width: ($breakpoint-big-phone + 1)) {
    max-width: 90%;
    width: auto;
  }

  &.has-close-btn {
    min-width: 400px;
  }

  &.is-visible.is-active {
    @include css3(transform, scale(1, 1));

    opacity: 1;
  }

  &:not(.hide-underneath) {
    &.is-visible {
      @include css3(transform, scale(1, 1));

      opacity: 1;
    }
  }

  &.is-active {
    pointer-events: auto;
  }

  .field {
    .icon + .icon-error,
    .icon + .icon-success {
      top: 12px !important;
    }

    input[data-error-type='tooltip'] + .icon-error,
    input[data-error-type='tooltip'] + .icon-success {
      position: absolute;
      display: inline-block;
      top: 33px !important;
      right: 11px;
      height: 14px;
      width: 14px;

      &:focus {
        outline: none;
        box-shadow: none;
      }

      @media (max-width: $breakpoint-big-phone) {
        inset-inline-end: 16px;
        inset-inline-start: auto;
      }

      @media (max-width: 366px) {
        inset-inline-end: 16px;
        inset-inline-start: auto;
      }
    }

    [data-error-type='tooltip']:not(input) ~ .icon-error,
    [data-error-type='tooltip']:not(input) ~ .icon-success {
      position: absolute;
      display: inline-block;
      right: 27px;
      height: 14px;
      width: 14px;

      &:focus {
        outline: none;
        box-shadow: none;
      }
    }

    .dropdown-wrapper {
      [data-error-type='tooltip'] ~ .icon-error,
      [data-error-type='tooltip'] ~ .icon-success {
        top: 1px;
      }
    }

    &.editor-container {
      [data-error-type='tooltip'] ~ .icon-error,
      [data-error-type='tooltip'] ~ .icon-success {
        top: 55px;
      }
    }

    textarea {
      max-width: 300px;

      &[data-error-type='tooltip'] ~ .icon-error,
      &[data-error-type='tooltip'] ~ .icon-success {
        top: 20px;
      }

      &.input-lg {
        min-height: inherit;
        width: 400px;
      }
    }

    &.editor-container {
      max-width: 820px;

      .editor-source textarea {
        max-width: inherit;
      }
    }

    &:first-child .audible ~ input:not(.spinbox):not(.colorpicker):not(.field-filter),
    &:first-child .audible ~ .searchfield-wrapper {
      margin-top: 4px;
    }

    &:first-child .checkbox-label {
      margin-top: 2px;
    }

    &:last-child .checkbox-label {
      margin-bottom: 1px;
    }
  }

  .textarea-wordcount {
    width: auto;
  }

  hr {
    border-bottom: 0 none;
    border-top: 1px solid $fieldset-border-top-color;
    margin-bottom: -10px;
    margin-left: -27px;
    margin-top: 10px;
    padding: 0;
  }

  &.full-width {
    margin: auto;
    width: auto;

    .modal-content {
      .modal-body-wrapper {
        padding: 5px 0 0;
      }

      .no-full-width {
        padding: 0 20px;
      }

      .modal-buttonset {
        margin-top: 0;
      }
    }

    @media (max-width: 380px) {
      margin: 0;
    }
  }

  &.is-draggable {
    .modal-header {
      cursor: move;
    }
  }

  &.divider-top {
    .modal-content {
      .modal-header {
        border-bottom: 1px solid $modal-border-color;
        padding-bottom: 15px;
      }

      .modal-body-wrapper {
        padding: 0;
      }
    }
  }

  .card {
    .listview-search {
      width: 370px;

      @media only screen and (max-width: 520px) {
        width: 100%;
      }
    }

    .listview {
      width: 370px;

      @media only screen and (max-width: 520px) {
        width: 100%;
      }
    }

    .listview-search
    + .listview {
      max-height: none;
    }

    .listview-search .searchfield-wrapper {
      min-width: unset;
      top: -1px;
    }
  }

  .listview-search {
    + .listview {
      max-height: 220px;
      min-height: 220px;
    }

    .searchfield-wrapper {
      min-width: 300px;
      width: 100%;
      margin: 0;

      input {
        border-color: $fieldset-border-top-color;
        width: 100%;
      }

      &.has-focus {
        box-shadow: none;

        input {
          box-shadow: none;
        }
      }
    }
  }

  .alternate-bg {
    &.listview {
      background-color: $listview-full-width-bg-color;

      li {
        border-color: transparent;
      }
    }

    &.listview-search input {
      border-color: $listview-full-width-border-color;
      border-left-color: transparent;
      border-right-color: transparent;
    }
  }

  .accordion {
    @media (min-width: ($breakpoint-phone + 1px)) {
      max-width: 100%;
      width: inherit;
    }
  }

  .busy.overlay {
    background-color: $modal-bg-color;
  }

  // Creates the full size "sheet" effect
  // See infor-design/enterprise#2433 for more info.
  &.display-fullsize {
    height: 100%;
    max-height: 100%;
    max-width: 100%;
    width: 100%;

    .modal-content {
      align-items: stretch;
      display: flex;
      flex-direction: column;
      height: 100%;
      margin: 0;

      h1 {
        white-space: initial;
        width: 100%;
      }
    }

    .modal-body-wrapper {
      flex-grow: 1;

      .splitter-container,
      .splitter-container .is-right-side,
      .splitter-container .is-right-side, .page-container {
        position: initial;
      }
    }
  }

  .modal-content {
    .modal-header.splitter-header {
      padding: 16px;
    }

    .modal-body-wrapper.splitter-wrapper {
      position: relative;
      border-top: 1px solid $modal-splitter-top-border-color;
    }

  }


  &:not(.display-fullsize):not(.about) {
    .modal-content {
      h1 {
        @include line-clamp(2);

        white-space: initial;
        width: inherit;
      }
    }
  }

  &.has-minwidth {
    &:not(.display-fullsize):not(.about) {
      .modal-content {
        h1 {
          max-width: 450px;
        }
      }
    }
  }
}

.modal {
  .searchfield-wrapper {
    + .error-message {
      margin-top: 7px;
    }

    > .icon {
      &:not(.close):not(.icon-error) {
        left: 9px;
      }
    }
  }

  .editor {
    &.required.error {
      margin-bottom: 0;

      + .error-message {
        margin-top: 7px;
      }
    }
  }
}

.overlay {
  @include css3(transition, all 0.2s);

  background: rgba(0, 0, 0, 0.7);
  height: 100%;
  left: 0;
  position: fixed;
  top: 0;
  visibility: hidden;
  width: 100%;
  z-index: 1000;
}

// Body tag is notified when a modal is present in the page.
body.modal-engaged {
  .overlay {
    visibility: visible;
  }
}

.modal-header {
  padding: 16px 16px 0;
}

.modal-content {
  background: $modal-bg-color;
  border: 1px solid $modal-border-color;
  border-radius: 2px;
  box-shadow: $modal-box-shadow;
  margin: 16px;

  @media screen and (min-width: ($breakpoint-big-phone + 1)) {
    margin: 10px;
  }

  // Messages/Content
  h1 {
    @include ellipsis();
    @include line-clamp(1);

    color: $modal-primary-color;
    font-size: $ids-size-font-lg;
    font-weight: $ids-number-font-weight-base;
    -webkit-margin-after: 0;
    text-align: left;

    > * {
      vertical-align: text-top;
      margin: -1px 8px 0 0;
    }

    &:focus {
      outline: none;
    }

    &.has-status {
      .icon {
        left: -6px;
        margin-left: 6px;
        margin-right: 4px;
        top: 9px;
      }
    }

    &.is-error {
      .icon {
        color: $error-color;
      }
    }

    &.is-alert {
      .icon {
        color: $alert-color;
      }
    }

    &.is-success {
      .icon {
        color: $success-color;
      }
    }

    &.is-info {
      .icon {
        color: $info-color;
      }
    }
  }

  h2 {
    @include font-size(16);

    color: $modal-primary-color;
    font-weight: $ids-number-font-weight-base;
    -webkit-margin-after: 0;
    text-align: left;

    + p {
      margin: 15px 0;
    }

    + img {
      margin: 7px 0;
    }

    button {
      margin: 2px;
    }
  }

  .modal-body-wrapper {
    overflow: auto;
    padding: 32px 16px;

    .field:not(.label-left).last-child {
      margin-bottom: 0;

      label,
      .label {
        margin-top: 20px;
      }
    }
  }

  // Modal Buttons
  .modal-body > button {
    display: block;
    font-size: 1.5rem;
    margin: 25px auto 5px;
  }

  > .modal-buttonset {
    .btn-close {
      bottom: 0;
      position: relative;
    }
  }

  > .btn-close {
    position: absolute;
    right: 10px;
    top: 10px;
  }

  // Message specific styles
  .message {
    @include antialiased();

    color: $modal-color;
    font-size: $ids-size-font-base;
    line-height: 20px;
    margin-bottom: 0;
    max-width: 369px;
    padding: 0;
    text-align: left;

    .modal-body-wrapper {
      padding: 5px 20px;
    }

    ol,
    ul {
      list-style: initial;
      margin: -4px 20px 0;
    }
  }

  .alert-text {
    display: inline-block;
    margin-bottom: 10px;
    position: relative;
  }

  p + p {
    margin-top: 20px;
  }

  &.has-icon .message {
    margin: 25px 33px -6px;
  }
}

.modal-body {
  &.overflow {
    overflow: auto;
  }

  > *:not(.pager-toolbar):last-child {
    margin-bottom: 0;
  }

  p:first-of-type {
    padding-top: 0;
  }

  p:last-child {
    padding-bottom: 0;
  }

  &.propagate-style {
    max-height: inherit;
    max-width: inherit;
    overflow: inherit;
  }

  &.compact {
    padding: 0;
  }
}

//Toolbar Buttons
.modal-buttonset {
  border-top: 1px solid $modal-btn-border-color;
  height: 50px;

  button {
    @include css3(transition, color 0.3s ease 0s);

    border: 1px solid transparent;
    border-left: 1px solid $modal-btn-border-color;
    border-radius: 0;
    color: $modal-btn-color;
    cursor: pointer;
    float: left;
    font-size: $ids-size-font-base;
    font-weight: $ids-number-font-weight-bold;
    height: 49px;
    line-height: 49px;
    margin-right: 0;
    min-width: 0;
    overflow: hidden;
    position: relative;
    text-align: center;
    width: 100%;

    &:hover {
      color: $modal-btn-hover-color;
    }

    &:nth-child(1) {
      border-left: 1px solid transparent;
    }

    &:focus:not(.hide-focus) {
      border: 1px solid $input-color-focus-border;
      box-shadow: $focus-box-shadow;
      outline: none;
      outline-color: transparent;
    }

    &[disabled],
    &[disabled]:hover {
      color: rgba($modal-btn-disabled-color, $modal-btn-disabled-opacity);
      cursor: default;
      text-decoration: none;

      &.btn-modal-primary {
        color: rgba($modal-btn-primary-disabled-color, $modal-btn-primary-disabled-opacity);
      }
    }

    &[disabled]:focus {
      text-decoration: underline;
    }

    .ripple-effect {
      background-color: $button-color-primary-initial-background;
    }

    span {
      @include ellipsis();

      display: block;
      margin: 0;
    }

    &:has(svg.icon) {
      svg.icon {
        margin-right: 8px;
      }
      
      span {
        display: inline;
      }
    }
  }

  .btn-modal-primary {
    background-color: transparent;
    color: $modal-btn-primary-color;

    &:hover {
      background-color: transparent;
      color: $modal-btn-primary-hover-color;
    }
  }
}

// IE-specific adjustments
html.ie {
  .modal {
    &.full-width {
      margin: 0;
    }
  }
}

// Solution for multi line with ellipsis
.ie11 {
  .modal {
    &:not(.display-fullsize):not(.about) {
      .modal-content {
        h1 {
          line-height: 1.2em;
          margin-right: -1em;
          max-height: 2.4em;
          overflow: hidden;
          padding-right: 1em;
          position: relative;
          text-align: justify;
          white-space: normal;

          &::before {
            bottom: 0;
            content: '...';
            position: absolute;
            right: 0;
          }

          &::after {
            background-color: $modal-bg-color; // Covering up the ‘…’ if the text is less than the max number of lines.
            content: '';
            height: 1em;
            position: absolute;
            right: 0;
            width: 1em;
          }
        }
      }
    }
  }
}

// iOS has lots of issues regarding scrolling of elements that are
// technically "behind" the modal.  This CSS, as well as some JS in the Modal component,
// seek to stop scrolling behind the in-focus modal element.
.ios {
  body.modal-engaged {
    -webkit-overflow-scrolling: auto;

    [aria-hidden='true'],
    [aria-hidden='true'] * {
      overflow: hidden;
    }

    .monthview-popup.is-open .day-text {
      &[aria-hidden='true'],
      &[aria-hidden='true'] * {
        overflow: unset;
      }
    }

    .page-container.scrollable,
    .page-container.scrollable-x,
    .page-container.scrollable-y {
      pointer-events: none;
    }

    .modal-body-wrapper {
      -webkit-overflow-scrolling: touch;
    }
  }

  // Fix a sizing bug on textareas in portrait-oriented iOS devices
  .modal {
    .field {
      textarea {
        max-width: 100%;
      }
    }
  }
}

.is-mac {
  .modal-content {
    h1.is-success {
      .icon {
        margin-top: 0;
      }
    }
  }
}

// RTL Styles
html[dir='rtl'] {
  .modal .field {
    .icon + .icon-error,
    .icon + .icon-success {
      top: 11px !important;
    }

    input[data-error-type='tooltip'] + .icon-error,
    input[data-error-type='tooltip'] + .icon-success {
      top: 33px;
      margin-left: unset;
      margin-right: unset;
      right: unset;
      left: 10px;

      @media (max-width: $breakpoint-big-phone) {
        left: unset;
        margin-inline-start: -25px;
      }
    }

    [data-error-type='tooltip']:not(input) ~ .icon-error,
    [data-error-type='tooltip']:not(input) ~ .icon-success {
      margin-left: unset;
      margin-right: unset;
      left: 25px;
      right: unset;
    }
  }

  .modal-buttonset {
    button {
      float: right;
      margin-left: 0;

      &:nth-child(1) {
        border-left: 1px solid $modal-btn-border-color;
      }

      &:last-child {
        border-left-color: transparent;

        &:focus {
          border-left-color: $input-color-focus-border;
        }
      }

      &:has(svg.icon) {
        svg.icon {
          margin-right: 0;
          margin-left: 8px;
        }
      }
    }
  }

  .modal-content {
    padding: 0;

    // Messages/Content
    h1 {
      margin-left: 25px;
      margin-right: inherit;
      padding-left: 20px;
      text-align: right;

      &.has-status {
        svg {
          left: auto;
          margin-left: 10px;
          margin-right: 8px;
          right: 5px;
        }
      }
    }

    .modal-body-wrapper {
      padding-left: 30px;
    }

    h2,
    .message {
      text-align: right;
    }

    .btn-close {
      right: auto;
    }
  }
}

@media all and (orientation: landscape) {
  .modal-content .modal-body-wrapper {
    overflow-x: hidden;
    overflow-y: auto;
  }
}

html[class*='theme-classic-'] {
  .modal-content h1 > * {
    vertical-align: super;
    margin: 0 8px 0 0;
  }
}

@media (min-width: $breakpoint-phone) and (max-width: ($breakpoint-slim + 20px)) {
  .modal {
    .field {
      input[data-error-type='tooltip'][data-validate*="email"] + .icon-error {
        position: absolute;
        inset-inline-end: 16px;
      }
    }
  }
}

@media (min-width: ($breakpoint-slim + 20px)) and (max-width: $breakpoint-phone-to-tablet) {
  .modal {
    .field {
      input[data-error-type='tooltip'][data-validate*="email"] + .icon-error {
        position: relative;
        inset-inline-end: 16px;
        top: -1px !important;
      }
    }
  }
}
