@use "../base/mixins" as *;
@use "../base/variables" as *;
@use "../base/typography" as *;

.chat {
  flex-shrink: 0;
  overflow: hidden;
  position: fixed;
  right: 0;
  top: 0;
  width: 36rem;
  height: 100dvh;

  z-index: 91;

  [data-theme="dark"] & {
    background-color: #221A25;
  }

  [data-theme="light"] & {
    background-color: #EEF2F6;
  }

  @include media("lg") {
    overflow: visible;
    width: 100% !important;
    max-width: 36rem;
    background-color: transparent;
  }

  @include media("sm") { 
    max-width: 100%;
  }

  &__inner {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 1;

    @include media("sm") { 
      width: 100%;
    }
  }

  &__header {
    @include flexCenter(space-between);

    flex-shrink: 0;
    padding: 1.2rem;
    width: 100%;
    height: 5.2rem;
    border-bottom: 1px solid theme-color($border-low);
  }

  &__title {
    @include typography("h4");

    font-weight: 700;
    color: theme-color($text-high);
  }

  &__body {
    @include transition(flex);

    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 2rem 1.2rem;
    width: 100%;

    &::-webkit-scrollbar {
      display: none;
    }
  }

  &__message-list {
    display: flex;
    flex-direction: column;
    gap: 1.6rem;
    min-height: 100%;

    @include media("lg") {
      gap: 1.2rem;
    }
  }

  &__message {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;

    @include media("lg") {
      gap: 0.6rem;
    }

    &--outgoing {
      flex-direction: column;
      align-items: flex-end;

      .chat__message-text {
        margin: 0;
        background-color: theme-color($primary);
        color: #111;

        [data-theme="light"] & {
          background-color: theme-rgba($primary, 0.12);
        }
      }

      .chat__mention {
        color: #384099;

        [data-theme="light"] & {
          color: theme-color($primary);
        }
      }
    }

    &-thumb {
      flex-shrink: 0;
      overflow: hidden;
      margin-top: 0.3rem;
      width: 5.2rem;
      height: 5.2rem;
      border-radius: 0.8rem;

      @include media("lg") {
        width: 4.8rem;
        height: 4.8rem;
      }

      img {
        @include img-fit();
      }
    }

    &-content {
      flex: 1;
    }

    &-image {
      width: auto;
      height: 8rem;
      object-fit: contain;
    }

    &-author {
      @include typography("p2");

      display: block;
      color: theme-color($text-high);
      font-weight: 500;
    }

    &-text {
      display: inline-block;
      margin-top: 0.4rem;
      padding: 0.4rem 0.8rem;
      border-radius: 0.4rem;
      background-color: theme-color($container);
      color: theme-color($text-high);
      font-weight: 600;
      word-break: break-all;

      [data-theme="light"] & {
        background-color: rgba(#000, 0.05);
      }
    }
  }

  &__mention {
    color: theme-color($primary);
  }

  &__action-btn {
    @include flexCenter();

    gap: 0.4rem;
    position: absolute;
    bottom: calc(100% - 2rem);
    left: 50%;
    translate: -50% -0.8rem;
    padding: 0 1.4rem;
    height: 3.2rem;
    color: #111;
    background-color: #3ef4b2;
    border-radius: 10rem;
    font-weight: 600;

    [data-theme="dark"] & {
      &::after {
        filter: brightness(0);
      }
    }
  }

  &__footer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    gap: 0.8rem;
    padding: 2rem 1.2rem;
    width: 100%;

    @include media("lg") {
      padding: 1.6rem 1.2rem;
    }

    &-inner {
      display: flex;
      align-items: flex-end;
      gap: 0.8rem;
      translate: 0 0.8rem;
      width: 100%;

      &--actions-open {
        translate: 0;
      }
    }
  }

  &__input-group {
    @include flexCenter();
    @include transition(border-color);

    flex: 1;
    gap: 0.8rem;
    background-color: theme-color($invert-container);
    border-radius: 0.4rem;
    border: 1px solid rgba(#fff, 0.24);

    &:has(.textarea:focus) {
      border-color: theme-color($primary);
    }

    &--column {
      align-items: flex-end;

      .chat__input-controls {
        padding-bottom: 1.1rem;
      }
    }

    [data-theme="light"] & {
      background-color: #fff;
    }

    .textarea {
      flex: 1;
    }
  }

  &__input-controls {
    @include flexCenter();

    gap: 0.4rem;
    padding-right: 1.2rem;
  }

  &__input-btn {
    [data-theme="dark"] & {
      &:hover {
        filter: brightness(0) invert(1);
      }

      &.active {
        filter: brightness(0) invert(1);
      }
    }

    [data-theme="light"] & {
      &:hover {
        filter: brightness(0) invert(0);
      }

      &.active {
        filter: brightness(0) invert(0);
      }
    }
  }

  &__btn-send {
    padding: 0 !important;
    width: 4.8rem !important;
    height: 4.8rem !important;

    @include media("lg") {
      width: 4rem !important;
      height: 4rem !important;

      &::before {
        --ico-size: 1.6rem;
      }
    }
  }

  &__message-actions {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 14.4rem;
    background-color: #261b29;

    [data-theme="light"] & {
      background-color: #fff;
    }

    &::-webkit-scrollbar {
      display: none;
    }

    &-wrapper {
      position: relative;
    }
  }

  .emoji-picker__categories {
    flex-shrink: 0;
    overflow-x: auto;
    display: flex;
    gap: 0.4rem;
    padding: 0.8rem;
    border-bottom: 1px solid theme-color($border-low);

    &::-webkit-scrollbar {
      display: none;
    }
  }

  .emoji-picker__category-btn {
    @include flexCenter();
    @include transition(background-color);

    flex-shrink: 0;
    width: 3.6rem;
    height: 3.6rem;
    background: transparent;
    border: none;
    border-radius: 0.4rem;
    cursor: pointer;

    &.active {
      background-color: theme-rgba($primary, 0.2);
    }
  }

  .emoji-picker__grid {
    @include scrollbar();

    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.4rem;
    align-content: start;
    padding: 0.8rem;
  }

  .emoji-picker__emoji-btn {
    @include flexCenter();
    @include transition((background-color, scale));

    width: 100%;
    min-width: 0;
    aspect-ratio: 1;
    background-color: transparent;
    border: none;
    border-radius: 0.4rem;
    cursor: pointer;

    &:hover {
      scale: 1.1;
      background-color: theme-color($invert-container);
    }

    &:active {
      scale: 0.95;
    }
  }

  .gif-picker__grid {
    @include scrollbar();

    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
    position: relative;

    &-item {
      height: 8rem;

      img {
        @include img-fit();
      }
    }
  }

  .gif-picker__attribution {
    position: absolute;
    right: 0;
    bottom: 0;
  }
}