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

.btn, .btn-icon {
  background: none;
	outline: none;
  border: none;
  cursor: pointer;

  body.animation-level-0 & {
    transition: none;
  }

  @include btn-hoverable();

  &:disabled {
    pointer-events: none !important;
    opacity: var(--disabled-opacity);
  }
}

.btn-icon {
  text-align: center;
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 50% !important;
  color: var(--secondary-text-color);
  background-color: transparent;
  border: none;
  padding: .5rem;
  position: relative;
  // overflow: hidden;
  transition: color .15s ease-in-out, opacity .15s ease-in-out, background-color .15s ease-in-out;
  
  /* kostil */
  display: flex;
  align-items: center;
  justify-content: center;

  &.rp {
    overflow: hidden;
  }

  &.active {
    color: var(--primary-color);
  }
}

.btn-corner {
  --offset: 1.25rem;
  --translateY: calc(54px + var(--offset));
  position: absolute !important;
  bottom: var(--offset);
  right: var(--offset);
  //transition: .2s ease;
  transition: transform var(--btn-corner-transition) !important;
  transform: translate3d(0, var(--translateY), 0);
  z-index: 3;
  user-select: none;
  background-color: var(--primary-color);
  text-align: center;
  font-size: 1.5rem;
  color: #fff;
  border: none;
  outline: none;
  cursor: pointer;
  
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 !important;
  
  &.is-visible {
    --translateY: 0;
  }

  body.animation-level-0 & {
		transition: none !important;
  }
  
  &:disabled {
    opacity: 1 !important;
    pointer-events: all !important;
  }

  .preloader-circular {
    width: 2.5rem;
    height: 2.5rem;
  }
}

.btn-menu {
  visibility: hidden;
  position: absolute;
  background-color: var(--surface-color);
  z-index: 3;
  top: 100%;
  padding: .5rem 0;
  border-radius: $border-radius-medium;
  opacity: 0;
  transform: scale(.8) !important;
  transition: opacity var(--btn-menu-transition), transform var(--btn-menu-transition), visibility var(--btn-menu-transition);
  font-size: 1rem;

  &/* ,
  &-reactions */ {
    box-shadow: var(--menu-box-shadow);
  }

  body.animation-level-0 & {
    transition: none;
  }

  -webkit-user-select: none; /* disable selection/Copy of UIWebView */
  -webkit-touch-callout: none; /* disable the IOS popup when long-press on a link */

  &.active {
    visibility: visible;
    opacity: 1;
    transform: scale3d(1, 1, 1) !important; // * scale3d (NOT scale) will fix jumping text
  }

  &:not(.active) {
    &, .btn-menu-item {
      pointer-events: none !important;
    }
  }

  &.bottom-left {
    right: 0;
    top: 100%;
    transform-origin: top right;
  }

  &.bottom-right {
    left: 0;
    top: 100%;
    transform-origin: top left;
  }

  &.bottom-center {
    transform-origin: top center;
  }

  &.top-left {
    top: initial;
    right: 0;
    bottom: 100%;
    transform-origin: bottom right;
  }

  &.top-right {
    top: initial;
    left: 0;
    bottom: 100%;
    transform-origin: bottom left;
  }

  &.top-center {
    transform-origin: bottom center;
  }

  &.center-left {
    transform-origin: center right;
  }

  &.center-right {
    transform-origin: center left;
  }

  &-item {
    --padding-left: 1rem;
    --padding-right: 2.5rem;
    --icon-margin: 1.5rem;
    --icon-size: 1.5rem;
    display: flex;
    position: relative;
    padding: 0 var(--padding-right) 0 var(--padding-left);
    height: 3rem;
    cursor: pointer !important;
    pointer-events: all !important;
    color: var(--primary-text-color);
    text-transform: none;
    white-space: nowrap;
    // overflow: hidden;
    // text-overflow: ellipsis;
    align-items: center;
    text-align: left;
    line-height: var(--line-height);

    @include hover-background-effect();

    &.danger {
      @include hover-background-effect(red);
    }

    &:before {
      color: var(--secondary-text-color);
      font-size: var(--icon-size);
    }

    &-icon,
    &:before {
      margin-right: var(--icon-margin);
      position: relative;
    }

    &-icon {
      flex: 0 0 auto;
    }

    @include respond-to(handhelds) {
      --padding-right: 1.875rem;
    }

    &-text {
      position: relative;
      flex: 1 1 auto;

      &,
      &-fake {
        pointer-events: none;
      }

      &-fake {
        --margin-left: calc(var(--icon-size) + var(--icon-margin));
        position: absolute;
        margin-left: var(--margin-left);
        max-width: calc(100% - var(--margin-left) - var(--padding-left) - var(--padding-right));

        @include text-overflow();
      }
    }

    &-subtitle {
      font-size: .875rem;
      color: var(--secondary-text-color);
    }

    &-header {
      color: var(--primary-color);
      height: 2rem;
      font-weight: var(--font-weight-bold);
      pointer-events: none !important;
    }

    .stacked-avatars {
      --margin-right: -.6875rem;
      flex: 0 0 auto;
      right: 1rem;
      // margin-right: -1.5rem;
      // margin-left: 1rem;
      position: absolute;
      pointer-events: none;

      /* @include respond-to(handhelds) {
        margin-right: -.875rem;
      } */
    }
  }

  /* &-overlay {
    position: fixed !important;
    left: -100vw;
    right: -100vw;
    top: -100vh;
    bottom: -100vh;
    z-index: 1;
    background-color: rgba(0, 0, 0, .2);
  } */
  &-overlay {
    position: fixed !important;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 3;
    cursor: default;
    user-select: none;
    //background-color: rgba(0, 0, 0, .2);
  }

  /* &-toggle  */&-overlay {
    left: -100vw;
    right: -100vw;
    top: -100vh;
    bottom: -100vh;

    width: auto !important;
    max-width: none !important;
  }

  &.has-footer {
    padding-bottom: 0;
  }

  &-footer {
    height: 2.5rem;
    background: var(--background-color-true);
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;
    font-size: .875rem;
    color: currentColor;
    // cursor: default;

    /* &-text {
      margin-top: -.125rem;
    } */
  }

  hr {
    padding: 0;
    margin: .5rem 0;
    display: block !important;
  }

  &-reactions {
    --inner-shadow-degree: 90deg;
    max-width: 100%;
    max-height: 100%;
    height: inherit;
    border-radius: var(--height);
    background-color: var(--surface-color);
    position: absolute;
    opacity: 0;
    transform: scale(.8);
    // filter: drop-shadow(0 .125rem .5rem rgba(0, 0, 0, .24));

    &-container {
      --height: 2.625rem;
      --bubble-side-offset: -2.25rem;
      --other-side-offset: -1.5rem;
      --width: calc(100% + (var(--bubble-side-offset) + var(--other-side-offset)) * -1);
      position: absolute;
      top: calc((var(--height) + .5rem) * -1);
      width: var(--width);
      max-width: var(--width);
      left: var(--other-side-offset);
      // left: var(--bubble-side-offset);
      display: flex;
      justify-content: flex-end;
      height: var(--height);

      &-vertical {
        top: var(--other-side-offset);
        left: calc((var(--height) + .5rem) * -1);
        width: var(--height);
        height: var(--width);
        max-width: var(--height);
        max-height: var(--width);
        flex-direction: column;
        
        .btn-menu-reactions {
          --inner-shadow-degree: 180deg;
          width: inherit;
          height: auto;
          display: flex;
          flex-direction: column;
        }

        .btn-menu-reactions-reaction {
          --padding-vertical: var(--padding-base);
          --padding-horizontal: 0rem;
        }

        .btn-menu-reactions-bubble-big {
          right: calc(var(--size) / -2);
          bottom: var(--offset);
        }
      }
    }

    @include animation-level(2) {
      transition: opacity var(--transition-standard-in), transform var(--transition-standard-in);
    }

    &.is-visible {
      opacity: 1;
      transform: scale(1);
    }

    &-bubble {
      position: absolute;
      background-color: inherit;
      border-radius: 50%;
      z-index: -1;

      /* &-small {
        width: .5rem;
        height: .5rem;
        right: .5rem;
        bottom: -1.25rem;
      } */

      &-big {
        --size: 1rem;
        --offset: calc(var(--height) / 2);
        width: var(--size);
        height: var(--size);
        right: var(--offset);
        // left: var(--offset);
        bottom: calc(var(--size) / -2);
      }
    }

    &:after {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      content: " ";
      pointer-events: none;
      border-radius: inherit;
      background: linear-gradient(var(--inner-shadow-degree), var(--surface-color) 0%, rgba(var(--surface-color-rgb), 0) 1rem, rgba(var(--surface-color-rgb), 0) calc(100% - 1rem), var(--surface-color) 100%);
    }

    .scrollable {
      $padding: .25rem;
      position: relative;
      display: flex;
      border-radius: inherit;

      &-x {
        align-items: center;
        padding: 0 #{$padding};
      }

      &-y {
        align-items: center;
        padding: #{$padding} 0;
        flex-direction: column;
      }
    }

    &-reaction {
      --size: 1.75rem;
      --padding-base: .25rem;
      --padding-vertical: 0rem;
      --padding-horizontal: var(--padding-base);
      width: calc(var(--size) + var(--padding-horizontal) * 2);
      height: calc(var(--size) + var(--padding-vertical) * 2);
      flex: 0 0 auto;
      padding: var(--padding-vertical) var(--padding-horizontal);
      cursor: pointer;

      &-scale {
        width: 100%;
        height: 100%;
        
        html:not(.is-safari) & {
          transform: scale(1);
        }

        html:not(.is-safari) body.animation-level-2 & {
          transition: transform .1s linear;
        }
      }

      &-select {
        html.no-touch:not(.is-safari) & {
          transform: scale(1);

          &:hover,
          &:active {
            transform: scale(1.25);
          }
        }
  
        html.no-touch:not(.is-safari) body.animation-level-2 & {
          transition: transform var(--transition-standard-in);
        }
      }

      .media-sticker-wrapper {
        position: relative;
        width: 100%;
        height: 100%;
        /* position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0; */
      }
    }
  }
}

.btn-primary {
  border-radius: $border-radius-medium;
  width: 100%;
  text-align: center;
  height: 54px;
  border: none;
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  padding: 0; // new
  transition: .2s opacity;
 
  @include hover() {
    transition: .2s background-color, .2s opacity;
    background: var(--dark-primary-color);
  }

  &-transparent {
    color: var(--primary-color);
    background-color: transparent;

    @include hover() {
      background: var(--light-primary-color);
    }

    .c-ripple__circle {
      background-color: var(--light-primary-color);
    }

    &.danger {
      @include hover-background-effect(red, false);
    }

    .preloader-circular .preloader-path {
      stroke: var(--primary-color);
    }
  }

  body.animation-level-0 & {
    transition: none;
  }
  
  > svg, use {
    height: calc(100% - 20px);
    right: 15px;
    left: auto;
  }

  &:disabled {
    pointer-events: none !important;
    opacity: var(--disabled-opacity);
  }
}

.btn-control {
  width: auto;
  height: 40px;
  align-items: center;
  margin: 15px auto 1rem;
  border-radius: 20px;
  padding: 0 24px 0 12px;
  display: flex;

  &.tgico:before {
    font-size: 1.5rem;
    margin-right: .375rem;
  }
}

// ! example: multiselect input, button in pinned messages chat, settings, chat background tab
.btn-transparent {
  color: var(--primary-text-color);
  background-color: transparent;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  height: 3.5rem;
  //width: auto;
  //text-transform: capitalize;
  font-weight: normal;
  line-height: var(--line-height); // * it centers the text

  @include respond-to(handhelds) {
    height: 3rem;
  }

  @include hover-background-effect();

  &.danger {
    @include hover-background-effect(red);
  }
  
  &.primary {
    @include hover-background-effect(primary);
  }

  // * tgico
  &:before {
    color: var(--secondary-text-color);
    font-size: 1.5rem;
    margin-right: 2rem;
  }

  &.btn-short:before {
    margin-right: 1rem;
  }
}

.btn-primary.btn-circle {
  .preloader-circular {
    height: calc(100% - 20px);
    right: auto;
    left: auto;
    margin: 0;
    top: 10px;
    
    .preloader-path {
      stroke: #fff;
    }
  }
}

.btn-menu-toggle {
  position: relative;
  overflow: visible !important;
  font-weight: normal !important;
  cursor: pointer !important;
  pointer-events: all !important;

  &:not(.btn-primary):not(.btn-corner).menu-open {
    background-color: var(--light-secondary-text-color);
  }

  .btn-menu {
    margin-top: .5rem;
  }
}

.btn-circle {
  --size: 54px;
  border-radius: 50%;
  height: var(--size);
  width: var(--size);
  line-height: var(--size);
  
  @include respond-to(handhelds) {
    --size: 46px;
  }
  
  path {
    fill: white;
  }
}

.btn-disabled {
  pointer-events: none !important;
  cursor: default !important;
  color: var(--secondary-text-color) !important;

  &:before {
    color: inherit !important;
  }
}

.btn-secondary:not(:first-child) {
  margin-top: .5rem !important;
}

.btn-color-primary {
  background: var(--primary-color);
  color: #fff;

  /* .c-ripple__circle {
    background-color: var(--light-primary-color);
  } */
}

.call-button {
  width: var(--call-button-size);
  height: var(--call-button-size);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.5rem;
  position: relative;
  border-radius: 50%;
  backdrop-filter: blur(25px);

  &-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    width: var(--call-button-size);

    &.disabled {
      pointer-events: none;

      .call-button { // ! fix backdrop-filter transition
        pointer-events: none;

        &,
        &-text {
          opacity: .8;
        }
      }
    }
  }

  &-text {
    white-space: nowrap;
    font-size: .875rem;
    margin-top: .25rem;

    @include animation-level(2) {
      transition: opacity var(--transition-standard-in);
    }
  }

  @include animation-level(2) {
    transition: background-color var(--transition-standard-in), opacity var(--transition-standard-in);
  }

  & + &,
  &-container + &-container {
    margin-left: var(--call-button-margin);
  }
}

// .btn-update {
//   position: absolute;
//   right: 0;
//   bottom: 0;
//   left: 0;
//   height: 2.5rem;
//   line-height: 2.5rem;
//   text-align: center;
//   color: #fff;

//   &-weave {
//     position: absolute;
//     top: 0;
//     right: 0;
//     bottom: -2.5rem;
//     left: 0;
//     z-index: -1;
//     transform: scale(1, -1);

//     &-canvas {
//       width: 100%;
//       height: 100%;
//     }
//   }
// }

.btn-update {
  width: auto;
  padding: 0 2rem !important;
  border-radius: var(--size);
  font-size: 1rem;
  font-weight: var(--font-weight-bold);
  /* margin-right: calc(var(--size) + 0.5rem); */
  /* left: var(--offset); */
  right: auto;
}
