/*
 * https://github.com/morethanwords/tweb
 * Copyright (C) 2019-2021 Eduard Kuzmenko
 * https://github.com/morethanwords/tweb/blob/master/LICENSE
 */

.media-viewer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, .88);
  /* color: var(--secondary-text-color); */
  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: var(--open-duration);
    cursor: pointer;

    @include hover() {
      color: #fff;
    }
  }

  &-userpic {
    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: var(--open-duration);

      @include 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;
    min-height: 50px;
  } */

  &-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 {
    position: absolute;
    text-align: center;
    color: #fff;
    //color: var(--secondary-text-color);
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 5;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0 .5rem;
    background-color: rgba(0, 0, 0, .6);
    border-radius: 8px;
    opacity: 0;
    transition: opacity var(--open-duration);

    @include respond-to(handhelds) {
      border-radius: 0;
      width: 100%;
    }

    > .scrollable {
      padding: .5rem 0;
      max-height: 10rem;
      max-width: 1280px;
      position: relative;
    }

    .media-viewer-whole.active & {
      opacity: 1;

      @include hover() { 
        opacity: .2;

        &:hover {
          opacity: 1;
          //color: #fff;
        }
      }
    }
  }

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

    @include hover() {
      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: var(--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/* , &-canvas */ {
    position: fixed!important;
    z-index: 4;
    //transition: .5s all;
    display: flex;
    justify-content: center;
    align-items: center; // mb net
    min-height: auto!important;
    left: 0;
    top: 0;
    transform-origin: top left;
    //transform-origin: bottom right;
    overflow: hidden;
    transform: translateZ(0) scale3d(1, 1, 1);
    border-radius: 0;
    -webkit-mask-image: -webkit-radial-gradient(circle, white 100%, black 100%); // fix border-radius overflow

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

    // эти значения должны быть такими же, как при установке maxWidth и maxHeight в openMedia!
    @include respond-to(handhelds) {
      overflow: visible;
      //max-height: 100% !important;
      //max-width: 100vw !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;
      transition: var(--open-duration) opacity;

      /* border-radius: inherit;
      transition: var(--open-duration) border-radius; */

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

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

    &.active {
      transition: var(--open-duration) transform, var(--open-duration) border-radius;
    }

    &.moving {
      transition: var(--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;
      max-width: calc(100vw - 16px);
      max-height: calc((var(--vh, 1vh) * 100) - 100px);

      @include respond-to(handhelds) {
        width: 100% !important;
        height: 100% !important;
        max-width: 100vw !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 {
        opacity: 0;
      }
    }
  }

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

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

  &-mover.active &-aspecter {
    transition: width var(--open-duration), height var(--open-duration), transform var(--open-duration), border-radius var(--open-duration);
    //transition: var(--open-duration) all;
  }

  &-whole {
    --open-duration: .2s;
    --move-duration: .35s;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    position: fixed!important;
    display: block;
    z-index: 4;
    visibility: hidden;
    transition: visibility 0s var(--open-duration);

    body.animation-level-0 & {
      --open-duration: 0s;
      --move-duration: 0s;
    }

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

      .overlays, > .btn-icon {
        opacity: 1;
        visibility: visible;
        transition: opacity var(--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 var(--open-duration) 0s, visibility 0s var(--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 var(--open-duration) 0s, visibility 0s var(--open-duration);
}
