$open-duration: .2s;
//$open-duration: 10s;
$move-duration: .35s;

.media-viewer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, .88);
  /* color: $color-gray; */
  display: flex;
  align-items: center;
  justify-content: center;

  @include respond-to(handhelds) {
    background: #000;
  }

  &-author {
    position: absolute;
    top: 0;
    left: 0;
    height: 3.75rem;
    padding: .5rem .5rem .5rem 5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #8b8b8b;
    transition: $open-duration;
    cursor: pointer;

    html.no-touch &:hover {
      color: #fff;
    }
  }

  &-userpic {
    width: 2.75rem;
    height: 2.75rem;
    position: absolute;
    top: .5rem;
    left: 1.25rem;

    @include respond-to(handhelds) {
      display: none;
    }
  }

  &-name {
    font-weight: 500;
  }
  
  &-date {
    font-size: 15px;
  }

  &-buttons {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    flex-flow: row nowrap;
    padding: .5rem;

    .btn-icon {
      margin: 0 .25rem;
      transition: $open-duration;

      html.no-touch &:hover {
        color: #fff;
      }
    }

    @include respond-to(handhelds) {
      display: none;
    }
  }

  &-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    max-height: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  &-stub {
    flex: 1;
  }

  &-container {
    align-self: center;
    position: relative;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
  }

  &-media {
    visibility: hidden;
  }

  &-caption {
    flex: 1;
    text-align: center;
    color: $color-gray;
    transition: $open-duration;
    max-width: 50vw;
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;

    html.no-touch &:hover {
      color: #fff;
    }
  }

  &-switcher {
    position: absolute;
    left: 0;
    top: 3.75rem;
    width: 7rem;
    height: calc(100% - 7.5rem);
    cursor: pointer;
    z-index: 5;

    html.no-touch & {
      height: calc(100% - 3.75rem);

      &:hover {
        > span {
          opacity: 1;
        }
      }
    }

    @include respond-to(handhelds) {
      width: 4rem;
    }

    &-right {
      left: auto;
      right: 0;
    }
  }

  &-prev-button, &-next-button {
    cursor: pointer;
    position: absolute;
    color: #fff;
    font-size: 2rem;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%) rotate(90deg);
    opacity: 0;
    transition: $open-duration opacity;
    z-index: 5;
    /* box-shadow: 0 1px 2px 0 rgba(16, 35, 47, 0.07); */

    @include respond-to(not-handhelds) {
      font-size: 3rem;
      left: 2rem;
    }
  }

  &-next-button {
    left: auto;
    right: 1rem;
    transform: translateY(-50%) rotate(-90deg);

    @include respond-to(not-handhelds) {
      right: 2rem;
    }
  }

  &-mover {
    position: fixed!important;
    z-index: 4;
    display: flex;
    justify-content: center;
    align-items: center; // mb net
    min-height: auto!important;
    //transition: .5s all;
    left: 0;
    top: 0;
    /* left: 50%;
    top: 50%; */
    transform-origin: top left;
    overflow: hidden;
    //border-radius: 0;

    // эти значения должны быть такими же, как при установке maxWidth и maxHeight в openMedia!
    //max-width: 100%;
    max-width: calc(100% - 16px);
    //max-height: 100%;
    max-height: calc(100% - 100px);

    // эти значения должны быть такими же, как при установке maxWidth и maxHeight в openMedia!
    @include respond-to(handhelds) {
      overflow: visible;
      //max-height: 100% !important;
      max-width: 100% !important;
    }

    .ckin__player {
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
    }

    > svg {
      width: 100%;
      height: 100%;
    }

    img, video {
      width: 100%;
      height: 100%;
      max-width: 100%;
      max-height: 100%;
      user-select: none;
      object-fit: cover;
      //object-fit: contain;
      opacity: 1;

      //&.thumbnail {
        position: absolute;
        //z-index: -1;
      //}
    }

    // !SAFARI
    svg {
      img, video {
        position: unset;
      }
    }

    &.active {
      transition: $open-duration transform, $open-duration border-radius;
    }

    &.moving {
      transition: $move-duration transform ease;
    }

    /* &.center {
      transition: none !important;
    } */

    &.no-transition {
      transition: none !important;
    }

    &.center {
      left: 50% !important;
      top: 50% !important;
      transform: translate3d(-50%, -50%, 0) !important;

      @include respond-to(handhelds) {
        width: 100% !important;
        height: 100% !important;
        //height: calc(100% - 100px) !important;
        /* height: calc(100% - 50px) !important;
        top: calc(50% + 25px) !important;
        
        img, video {
          margin-top: -25px;
        } */

        /* img, video {
          max-height: calc(100% - 100px);
        } */

        .ckin__player:not(.ckin__fullscreen) {
          .default__controls {
            bottom: -50px;
          }

          .default__gradient-bottom {
            bottom: -50px;
          }
        }
      }

      /* @include respond-to(handhelds) {
        &.moving {
          .ckin__player {
            .default__controls, .default__gradient-bottom {
              display: none;
            }
          }
        }
      } */

      img:not(.thumbnail), video {
        height: auto;
        width: auto;
        object-fit: contain;
        //max-height: calc(100% - 100px);
      }

      img.thumbnail {
        width: auto;
        object-fit: contain;
        //height: auto;
      }
    }

    &.hiding {
      img, video {
        transition: $open-duration opacity;
        opacity: 0;
      }
    }
  }

  // возможно тут это вообще не нужно
  &-aspecter {
    width: 100%;
    height: 100%;
    transform: scale(1);
    //overflow: hidden; // WARNING
    position: absolute;

    display: flex;
    align-items: center;
    justify-content: center;
  }

  &-mover.active &-aspecter {
    transition: $open-duration all;
  }

  &-whole {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    position: fixed!important;
    display: block;
    z-index: 4;
    visibility: hidden;
    transition: visibility 0s $open-duration;

    &.active {
      visibility: visible;
      transition-delay: 0s;

      .overlays, > .btn-icon {
        opacity: 1;
        visibility: visible;
        transition: opacity $open-duration 0s, visibility 0s 0s;
      }
    }

    @include respond-to(handhelds) {
      .tgico-close.only-handhelds {
        left: 20px;
      }

      > .btn-icon {
        top: 8px;
        position: fixed;
        z-index: 5;
        opacity: 0;
        transition: opacity $open-duration 0s, visibility 0s $open-duration;
      }
  
      .btn-menu-toggle {
        right: 8px;
  
        &.menu-open {
          color: #fff;
          background-color: rgba(112, 117, 121, .2) !important;
        }
      }
    }

    &.highlight-switchers {
      .media-viewer-switcher > span {
        opacity: 1;
      }
    }
  }

  &-switchers {
    position: relative;
    width: $large-screen;
    max-width: 100%;
    height: 100%;
    margin: 0 auto;
  }
}

.overlays {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  position: fixed!important;
  background-color: rgba(0, 0, 0, .2);
  z-index: 4;
  //display: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity $open-duration 0s, visibility 0s $open-duration;
}
