.chatbot {
  position: fixed;
  top: 0;
  left: 50%;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh; /* 파이어폭스 fallback */
  height: 100dvh; /* Safari 주소창 고려 */
  background-color: #fff;
  overflow: hidden;
  isolation: isolate;
  z-index: -1;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%);
  transition: all 0.4s ease-out;

  border-radius: 0;
  z-index: 9999;
}

.chatbot.active {
  z-index: 9999;
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* 챗봇 헤더 */
.chatbot__header {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #fff;
  border-bottom: 1px solid #e1e1e1;
}

.chatbot__logo {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chatbot__logo img {
  height: 24px;
}

.chatCloseBtn {
  padding: 9px 14px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.8px;
  color: var(--color-primary);
  background: #fff;
  border: 1px solid var(--color-primary);
  border-radius: 40px;
}

/* 챗봇 메인 기본 구조 */
.chatbot__main {
  padding: 60px 20px 20px;
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  opacity: 1;
  visibility: visible;
  transition: all 0.4s ease-in-out;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* chatbot이 active가 아닐 때 메인 영역 숨기기 */
.chatbot:not(.active) .chatbot__main {
  opacity: 0;
  visibility: hidden;
}

/* chatbot이 active일 때는 메인 영역이 보이도록 */
.chatbot.active .chatbot__main {
  opacity: 1;
  visibility: visible;
}

/* 스크롤 제어 클래스 */
.chatbot.active .chatbot__main.hidden {
  overflow: hidden;
}

/* chatbot__main 내부 요소들의 초기 상태 */
.chatbot__main .chatbot__avatar,
.chatbot__main .chatbot__greeting,
.chatbot__main .chatbot__message--item,
.chatbot__main .chatbot__quick {
  opacity: 0;
  transform: translateY(30px);
  transition: all 0.4s ease-out;
}

/* chatbot이 active될 때 순서대로 나타나는 애니메이션 */
.chatbot.active .chatbot__main .chatbot__avatar {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.1s;
}

.chatbot.active .chatbot__main .chatbot__greeting {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.2s;
}

.chatbot.active .chatbot__main .chatbot__message--item {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.3s;
}

.chatbot.active .chatbot__main .chatbot__quick {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.4s;
}

.chatbot__main.hidden {
  top: 61px;
  height: calc(100% - 115px);
}

.chatbot__main .chatbot__message--item.bot {
  margin-top: auto;
}

/* 챗봇 아바타 */
.chatbot__avatar {
  margin-bottom: 5px;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.chatbot__avatar--icon {
  width: 100px;
  height: 100px;
}

/* 챗봇 인사말 */
.chatbot__greeting {
  margin-bottom: 40px;
  align-self: center;
  text-align: center;
}
.chatbot__greeting img {
  display: inline-block;
  width: 250px;
}
.chatbot__greeting p {
  line-height: 1.42;
  letter-spacing: -0.7px;
}
.chatbot__greeting br {
  display: block;
}
.chatbot__greeting p {
  margin-top: 2px;
  font-size: 14px;
  color: #999;
}

/* 빠른 답변 버튼들 */
.chatbot__quick {
  margin-top: 32px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chatbot__main .chatbot__quick {
  justify-content: flex-end;
}

.quickBtn {
  padding: 10px 16px;
  font-size: 14px;
  line-height: 1;
  letter-spacing: -0.7px;
  background-color: #fff;
  border: 1px solid #e1e1e1;
  border-radius: 20px;
  color: #333;
  cursor: pointer;
  transition: all 0.2s;
}

/* 대화 영역 */
.chatbot__chat {
  position: absolute;
  top: 0;
  display: flex;
  padding: 20px;
  background-color: #fff;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s ease-in-out;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.chatbot__chat.active {
  position: relative;
  opacity: 1;
  visibility: visible;
}

/* 메시지 목록 */
.chatbot__message--list {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  list-style: none;
}

/* 메시지 아이템 기본 스타일 */
.chatbot__message--item {
  display: flex;
  flex-direction: column;
}

/* 봇 메시지 스타일 */
.chatbot__message--item.bot {
  align-items: flex-start;
}

.chatbot__message--item.bot .chatbot__quick {
  margin-top: 10px;
}

/* 사용자 메시지 스타일 */
.chatbot__message--item.user {
  align-items: flex-end;
}

/* 메시지 발신자 */
.chatbot__message--sender {
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.42;
  letter-spacing: -0.7px;
  color: #777;
}

/* 메시지 버블 */
.chatbot__message--bubble {
  padding: 12px 18px;
  font-size: 14px;
  line-height: 1.4;
  border-radius: 20px;
  word-break: break-word;
  max-width: 302px;
}

.chatbot__message--bubble p {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: -0.8px;
  word-break: break-all;
  white-space: pre-wrap;
}

.chatbot__message--item.bot .chatbot__message--bubble {
  background-color: #f1f1f1;
  border-top-left-radius: 0;
}

.chatbot__message--item.bot .chatbot__message--bubble p {
  color: #111;
}

.chatbot__message--item.user .chatbot__message--bubble {
  background-color: var(--color-primary);
  border-top-right-radius: 0;
}

.chatbot__message--item.user .chatbot__message--bubble p {
  color: #fff;
}

/* 타이핑 인디케이터 */
.chatbot__message--item.bot:has(.chatbot__message--typing) .chatbot__message--bubble {
  padding: 15px 18px;
}

.chatbot__message--typing {
  display: flex;
  gap: 7px;
}

.chatbot__message--typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: wave 1.2s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot__message--typing span:nth-child(1) {
  animation-delay: -0.24s;
  background-color: var(--color-primary);
}

.chatbot__message--typing span:nth-child(2) {
  animation-delay: -0.12s;
  background-color: var(--color-primary-alpha-50);
}

.chatbot__message--typing span:nth-child(3) {
  animation-delay: 0s;
  background-color: #d9d9d9;
}

@keyframes wave {
  0%,
  60%,
  100% {
    transform: translateY(0px);
  }
  30% {
    transform: translateY(-6px);
  }
}

/* 메시지 시간 */
.chatbot__message--time {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.5;
  letter-spacing: -0.6px;
  color: #999;
  text-align: center;
}

/* 모바일에서 메시지 간격 */
.chatbot__message--item ~ .chatbot__message--item {
  margin-top: 12px;
}

.chatbot__message--item.bot ~ .chatbot__message--item.bot,
.chatbot__message--item.user ~ .chatbot__message--item.user {
  margin-top: 12px;
}

.chatbot__message--bubble + .chatbot__message--bubble {
  margin-top: 12px;
}

.chatbot__message--time {
  margin-top: 8px;
}

.chatbot__message--item.bot .chatbot__quick {
  margin-top: 8px;
}
/* 빠른 답변 찾기 모달 */
.chatbot__popupWrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: flex-end;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease-in-out;
}

.chatbot__popupWrap.active {
  background-color: rgba(0, 0, 0, 0.6);
  opacity: 1;
  visibility: visible;
}

.chatbot__popup {
  width: 100%;
  background-color: #fff;
  box-shadow: 0 4px 30px 0 rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease-in-out;
  border-radius: 20px 20px 0 0;
}

.chatbot__popupWrap.active .chatbot__popup {
  transform: translateY(0);
}

.chatbot__popup--header {
  position: relative;
  padding: 44px 20px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chatbot__popup--header h3 {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.33;
  letter-spacing: -0.9px;
  color: #111;
}

.popCloseBtn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 24px;
  height: 24px;
  background: url(../img/ic_popClose.svg) no-repeat;
}

.chatbot__popup--content {
  padding: 20px;
}

.chatbot__popup--content .chatbot__quick {
  margin-top: 0;
  padding: 16px;
  max-height: 236px;
  overflow-y: auto;
  border-radius: 20px;
  background-color: #f6f6f6;
}

/* 메시지 입력 영역 */
.chatbot__footer {
  margin-top: auto;
}

.chatbot__footerContent {
  padding: 14px 20px;
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 35px;
  background-color: #fff;
  flex-shrink: 0;
  box-shadow: 0 -5px 10px 0 rgba(0, 0, 0, 0.1);
}

.chatbot__footerContent:before {
  content: "";
  position: absolute;
  top: 0;
  left: 63px;
  width: 1px;
  height: 100%;
  background-color: #f1f1f1;
}

.menuBtn {
  margin-bottom: 2px;
  width: 24px;
  height: 24px;
  background: url(../img/ic_popMenu_mo.svg) no-repeat;
}

.chatbot__inputWrap {
  padding: 0 38px 0 0;
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.chatbot__inputWrap textarea {
  margin-bottom: 2px;
  width: 100%;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: -0.8px;
  color: #999;
  resize: none;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border: 0 !important;
}

.chatbot__inputWrap textarea::-webkit-scrollbar {
  display: none;
}

.chatbot__inputWrap textarea::placeholder {
  font-weight: 400;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: -0.8px;
  color: #aeb0b5;
}

.sendBtn {
  position: absolute;
  right: 0;
  bottom: -1px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: url(../img/ic_arrowSend.svg) no-repeat center / 16px 14px #aeb0b5;
  transition: background-color 0.2s;
}
.chatbot__inputWrap textarea:focus {
  color: #111;
}
.chatbot__inputWrap textarea:focus + .sendBtn {
  border: 0;
  background: url(../img/ic_arrowSend.svg) no-repeat center / 16px 14px var(--color-primary-light);
}

/* 스크롤 제어 클래스 */
.chatbot.active .chatbot__main.hidden {
  overflow: hidden;
}

/* chatbot__main hidden 상태 (공통) */
.chatbot__main.hidden {
  position: absolute;
  left: 0;
  right: 0;
  opacity: 0;
  visibility: hidden;
}

/* 챗봇 이미지 애니메이션 */
.chatbot__avatar--motion {
  width: 100px;
  height: 100px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100px 100px;
  animation: chatbotMotion 5s ease-in-out infinite;
  /* 이미지 미리 로드 */
  background-image: url(../img/ic_chatBot01.svg), url(../img/ic_chatBot02.svg),
    url(../img/ic_chatBot03.svg), url(../img/ic_chatBot04.svg), url(../img/ic_chatBot05.svg),
    url(../img/ic_chatBot06.svg);
}

@keyframes chatbotMotion {
  0%,
  6% {
    background-image: url(../img/ic_chatBot01.svg);
  }
  7%,
  13% {
    background-image: url(../img/ic_chatBot02.svg);
  }
  14%,
  20% {
    background-image: url(../img/ic_chatBot01.svg);
  }
  21%,
  27% {
    background-image: url(../img/ic_chatBot03.svg);
  }
  28%,
  34% {
    background-image: url(../img/ic_chatBot04.svg);
  }
  35%,
  41% {
    background-image: url(../img/ic_chatBot05.svg);
  }
  42%,
  48% {
    background-image: url(../img/ic_chatBot01.svg);
  }
  49%,
  55% {
    background-image: url(../img/ic_chatBot06.svg);
  }
  56%,
  62% {
    background-image: url(../img/ic_chatBot01.svg);
  }
  63%,
  69% {
    background-image: url(../img/ic_chatBot01.svg);
  }
  70%,
  76% {
    background-image: url(../img/ic_chatBot03.svg);
  }
  77%,
  83% {
    background-image: url(../img/ic_chatBot04.svg);
  }
  84%,
  90% {
    background-image: url(../img/ic_chatBot05.svg);
  }
  91%,
  97% {
    background-image: url(../img/ic_chatBot01.svg);
  }
  98%,
  100% {
    background-image: url(../img/ic_chatBot01.svg);
  }
}
