@use "../../styles/mixins";

.MiddleHeader {
  position: relative;
  z-index: var(--z-middle-header);

  display: flex;
  flex-shrink: 0;
  align-items: center;

  width: 100%;
  height: var(--header-height);
  padding-top: 0.25rem;
  padding-right: max(0.8125rem, env(safe-area-inset-right));
  padding-bottom: 0.25rem;
  padding-left: max(1.4375rem, env(safe-area-inset-left));

  background: var(--color-background);

  .Transition {
    width: 100%;
    // https://dfmcphee.com/flex-items-and-min-width-0/
    // https://stackoverflow.com/questions/36247140/why-dont-flex-items-shrink-past-content-size
    min-width: 0;

    > .Transition_slide {
      display: flex;
      align-items: center;
      width: 100%;
    }
  }

  .back-button {
    position: relative;
    margin-right: 0.5rem;
    margin-left: -0.5rem;

    .unread-count {
      pointer-events: none;

      position: absolute;
      top: -0.25rem;
      right: -0.5rem;

      min-width: 1.25rem;
      height: 1.25rem;
      padding: 0 0.375rem;
      border-radius: 0.625rem;

      font-size: 0.75rem;
      font-weight: var(--font-weight-medium);
      line-height: 1.25rem;
      color: white;
      text-align: center;

      background: var(--color-gray);

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

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

  .chat-info-wrapper {
    flex-grow: 1;
    min-width: 0;
  }

  .header-tools {
    z-index: 1;

    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: flex-end;

    margin-left: auto;

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

    body.no-page-transitions & {
      &,
      .AudioPlayer,
      .HeaderActions {
        transition: none !important;
      }
    }

    body.no-right-column-animations & {
      &,
      .HeaderActions {
        transition: none !important;
      }
    }

    // @optimization
    #Main.right-column-animating & {
      pointer-events: none;
    }

    @media (min-width: 1276px) {
      transform: translate3d(0, 0, 0);
      transition: transform var(--layer-transition);

      #Main.right-column-open & {
        transform: translate3d(calc(var(--right-column-width) * -1), 0, 0);
      }
    }
  }

  h3 {
    unicode-bidi: plaintext;
    overflow: hidden;

    margin: 0;

    font-size: 1.125rem;
    font-weight: var(--font-weight-medium);
    line-height: 1.5rem;
    text-overflow: ellipsis;
    white-space: pre;

    body.is-ios &,
    body.is-macos & {
      font-size: 1.0625rem;
      font-weight: var(--font-weight-semibold);
    }

    @media (max-width: 600px) {
      overflow: hidden;
      display: block;
      text-overflow: ellipsis;
    }

    @media (min-width: 1275px) {
      #Main.right-column-open & {
        max-width: calc(100% - var(--right-column-width));
      }
    }
  }

  .ChatInfo {
    cursor: var(--custom-cursor, pointer);
    display: flex;
    align-items: center;
    // Space for unread story circle
    padding: 0.0625rem 0 0.0625rem 0.0625rem;

    .info {
      display: flex;
      flex-direction: column;
      flex-grow: 1;
      justify-content: center;

      min-width: 0;
    }

    .title {
      --custom-emoji-size: 1.375rem;

      display: flex;
      align-items: center;

      .VerifiedIcon {
        width: 1.25rem;
        height: 1.25rem;
      }
    }

    .saved-dialog-avatar {
      position: absolute;
    }

    .overlay-avatar {
      margin-left: 2.125rem;
      .inner {
        outline: 2px solid var(--color-background);
      }
    }

    .status,
    .typing-status {
      unicode-bidi: plaintext;

      @media (min-width: 1275px) {
        #Main.right-column-open & {
          max-width: calc(100% - var(--right-column-width));
        }
      }
    }

    .custom-emoji {
      color: var(--color-primary);
    }

    .story-circle {
      max-width: 2.625rem !important;
      max-height: 2.625rem !important;
    }

    .message-count-transition {
      height: 1.125rem;
    }

    @media (max-width: 600px) {
      user-select: none;
    }
  }

  .ChatInfo .Avatar, .topic-header-icon {
    // TODO For some reason webpack imports `Audio.scss` second time when loading calls bundle
    width: 2.5rem !important;
    height: 2.5rem !important;
    margin-right: 0.625rem;
  }

  .topic-header-icon {
    --custom-emoji-size: 2.25rem;

    font-size: 2.25rem;

    .emoji-small {
      width: 1.25rem;
      height: 1.25rem;
    }

    .topic-icon-letter {
      font-size: 1.25rem;
    }

    &.general-forum-icon {
      color: var(--color-text-secondary);
    }
  }

  .Avatar {
    font-size: 1.0625rem;
  }

  .status {
    color: var(--color-text-secondary);
    &.online {
      color: var(--color-primary);
    }
  }

  .status,
  .typing-status {
    overflow: hidden;

    margin: 0;

    font-size: 0.875rem;
    line-height: 1.125rem;
    text-overflow: ellipsis;
    white-space: nowrap;

    .ellipsis {
      display: inline-flex;
    }

    .font-emoji {
      line-height: 1rem;
    }
  }

  .HeaderActions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: flex-end;

    margin-left: auto;

    .Button {
      margin-left: 0.25rem;

      &.tiny {
        margin-right: 0.625rem;
      }
    }

    .toggle-right-pane-button {
      &.active {
        color: var(--color-primary);
        opacity: 1;
      }
    }

    .badge-button {
      position: relative;
      overflow: visible;
    }

    .badge {
      position: absolute;
      top: 0;
      right: 0;

      flex-shrink: 0;

      min-width: 1rem;
      height: 1rem;
      border-radius: 0.5rem;

      font-size: 0.75rem;
      font-weight: var(--font-weight-medium);
      line-height: 1rem;
      color: white;
      text-align: center;

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

  body.is-tauri.is-macos #Main:not(.left-column-open):not(.is-fullscreen) & {
    @media (max-width: 925px) {
      padding-left: var(--window-controls-width);

      .back-button {
        margin-left: -0.5rem;
      }
    }
  }

  @media (max-width: 600px) {
    position: relative;
    padding-right: max(0.5rem, env(safe-area-inset-right));
    padding-left: max(0.5rem, env(safe-area-inset-left));
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
