@use "mixins";

// Common styles for all media-type components across the app.
.media-inner {
  user-select: none;
  position: relative;

  video.full-media,
  img.full-media,
  img.thumbnail,
  canvas.thumbnail {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .full-media.with-blurred-bg {
    position: relative;
    border-radius: 0 !important;
  }

  video {
    background: no-repeat 50% 50%;
    background-size: contain;
  }

  .thumbnail {
    position: absolute;
    top: 0;
    left: 0;

    &.with-blurred-bg {
      left: 50%;
      transform: translateX(-50%);
      border-radius: 0 !important;
    }
  }

  .media-loading {
    position: absolute;
  }

  &.fix-min-height {
    min-height: 5rem;
  }

  .message-media-last-progress {
    --_progress: 0%;
    --_color: var(--color-primary);

    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;

    height: 0.25rem;

    background-color: rgba(255 255 255 / 0.3);

    &::before {
      content: "";

      position: absolute;
      top: 0;
      left: 0;

      width: var(--_progress);
      height: 100%;
      border-top-right-radius: 0.125rem;
      border-bottom-right-radius: 0.125;

      background-color: var(--_color);
    }

    .theme-dark & {
      --_color: white;
    }
  }
}

.animated-close-icon {
  position: absolute;
  transform: rotate(-45deg);

  &::before,
  &::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
  }

  &::before {
    transform: rotate(90deg);
  }

  &,
  &::before,
  &::after {
    width: 1.125rem;
    height: 0.125rem;
    border-radius: 0.125rem;

    background-color: var(--color-text-secondary);

    transition: transform var(--slide-transition);
  }

  &.no-transition {
    &,
    &::before,
    &::after {
      transition: none;
    }
  }

  &.state-back {
    transform: rotate(180deg);

    &::before {
      transform: rotate(45deg) scaleX(0.75) translate(0, -0.375rem);
    }

    &::after {
      transform: rotate(-45deg) scaleX(0.75) translate(0, 0.375rem);
    }
  }
}

.overscroll-trigger {
  display: none;
  height: 1px;
}

// Used by ChatList and ContactList components
.chat-list {
  overflow-x: hidden;
  overflow-y: scroll;

  height: 100%;
  padding: 0.5rem;

  background: var(--color-background);

  /* stylelint-disable-next-line no-duplicate-selectors */
  & {
    @include mixins.adapt-padding-to-scrollbar(0.5rem);
  }

  &.forum-panel-open {
    .info {
      transform: translateX(-20%);
      opacity: 0;
    }

    .Chat[dir="rtl"] .info {
      transform: translateX(20%);
    }

    .Avatar {
      transform: scale(0.9);
    }
  }

  .scroll-container {
    position: relative;
  }

  .no-results {
    margin-top: 2rem;
    color: var(--color-text-meta);
    text-align: center;
  }

  .Avatar {
    transition: transform var(--layer-transition);

    body.no-page-transitions & {
      transition: none;
    }
  }

  .ListItem {
    &.chat-item-clickable {
      margin: 0;
    }
  }

  body.is-ios &,
  body.is-android & {
    padding-right: 0;
    padding-left: 0;

    .ListItem::after {
      opacity: 1;
      transition: opacity var(--layer-transition);
    }

    &.forum-panel-open {
      .ListItem::after {
        opacity: 0;
      }
    }
  }

  @media (min-width: 600px) {
    &.forum-panel-open .selected-forum .Avatar {
      transform: none;
    }
  }

  @media (max-width: 600px) {
    padding-right: 0;
    padding-left: 0;
  }
}

// Used by Avatar and ProfilePhoto components
.Avatar, .ProfilePhoto {
  --color-user: var(--accent-color);

  &.replies-bot-account,
  &.anonymous-forwards,
  &.saved-messages {
    --color-user: var(--color-primary);
  }

  &.deleted-account {
    --color-user: var(--color-deleted-account);
  }
}

.fab-padding-bottom {
  padding-bottom: 5rem !important;
}

.with-story-ribbon {
  --story-ribbon-height: 5.5rem;

  transform: translateY(calc(var(--story-ribbon-height) * -1));
  height: calc(100% - var(--extra-height, 0px) + var(--story-ribbon-height)) !important;

  &.open, &.closing {
    transition: transform 250ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  }

  &.open {
    transform: translateY(0);
  }
}

// Update this value when new server colors are added
@for $i from 0 through 25 {
  .peer-color-#{$i} {
    --accent-color: var(--color-peer-#{$i}, var(--color-text));
    --bar-gradient: var(--color-peer-gradient-#{$i});
    --accent-background-color: var(--color-peer-bg-#{$i}, var(--hover-color));
    --accent-background-active-color: var(--color-peer-bg-active-#{$i}, var(--active-color));
  }
}

.peer-color-count-1,
.peer-color-count-2,
.peer-color-count-3 {
  --accent-background-color: var(--hover-color);
  --accent-background-active-color: var(--active-color);
}

.peer-color-count-2 {
  @include mixins.peer-gradient(--bar-gradient, 2);
}

.peer-color-count-3 {
  @include mixins.peer-gradient(--bar-gradient, 3);
}

.flex-column-centered {
  display: flex;
  flex-direction: column;
  align-items: center;
}
