/* 블러 overlay */
.chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chat-overlay.visible {
  display: block;
}

/* 웹뷰 열릴 때: 좌우 50:50 분할 (웹뷰 왼쪽, 대화 오른쪽) */
.chat-overlay.webview-open {
  display: flex;
  flex-direction: row;
}

.chat-overlay.webview-open .chat-messages {
  position: relative;
  transform: none;
  width: 50%;
  max-width: none;
  left: auto;
  top: auto;
  bottom: auto;
  height: 100%;
  padding-bottom: 200px;
  order: 2;
  box-sizing: border-box;
}

.chat-overlay.webview-open ~ .chat-input-bar {
  left: 75%;
  max-width: 50%;
  box-sizing: border-box;
  padding: 0 12px;
}

/* 참고자료 웹뷰 */
.chat-webview {
  display: none;
  flex-direction: column;
  width: 50%;
  height: 100%;
  background: #1a1a1a;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  order: 1;
}

.chat-overlay.webview-open .chat-webview {
  display: flex;
}

.chat-webview-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.chat-webview-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.2s;
}

.chat-webview-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.chat-webview-title {
  flex: 1;
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
  font-family: 'Pretendard', sans-serif;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-webview-external {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 0.2s;
}

.chat-webview-external:hover {
  background: rgba(255, 255, 255, 0.15);
}

.chat-webview-frame {
  flex: 1;
  border: none;
  background: #fff;
}

/* PC 최소화 버튼 (하향 화살표) */
.chat-minimize-btn {
  display: none;
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10000;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s;
}

.chat-minimize-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* PC에서만 표시 */
@media screen and (min-width: 768px) {
  .chat-overlay.visible .chat-minimize-btn {
    display: flex;
  }
  /* 웹뷰 열려있으면 숨기기 */
  .chat-overlay.webview-open .chat-minimize-btn {
    display: none;
  }
}

/* 모바일 뒤로가기 버튼 */
.chat-back-btn {
  display: none;
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10000;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s;
}

.chat-back-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* 채팅 메시지 영역 */
.chat-messages {
  position: absolute;
  top: 0;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 780px;
  padding: 32px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-sizing: border-box;
  /* 스크롤바: 평소 숨김, 스크롤 시만 표시 */
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.3s;
}

.chat-messages:hover {
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

/* Webkit (Chrome, Safari, Edge) */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 3px;
  transition: background 0.3s;
}

.chat-messages:hover::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

/* 사용자 메시지 (우측) */
.chat-msg-user {
  align-self: flex-end;
  max-width: 70%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.chat-msg-user .chat-msg-text {
  background: rgba(90, 90, 90, 0.85);
  color: #fff;
  padding: 12px 18px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.6;
  font-family: 'Pretendard', sans-serif;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-msg-user .chat-msg-images {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chat-msg-user .chat-msg-images img {
  width: 200px;
  max-width: 100%;
  border-radius: 16px;
  display: block;
}

.chat-input-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  width: 100%;
  max-width: 680px;
  padding: 0 16px;
  box-sizing: border-box;
  transition: max-width 0.3s ease, bottom 0.15s ease-out;
}

/* 무지개빛 pulse 테두리 (최소화 상태에서만) */
.chat-input-bar::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 15px;
  right: 15px;
  bottom: -1px;
  border-radius: 29px;
  background: conic-gradient(
    from 0deg,
    #ff6b6b, #ffa94d, #ffd43b, #69db7c, #4dabf7, #9775fa, #f06595, #ff6b6b
  );
  z-index: -1;
  opacity: 0;
  animation: rainbowPulse 3s ease-in-out infinite, rainbowRotate 4s linear infinite;
  pointer-events: none;
}

@keyframes rainbowPulse {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 0.6; }
}

@keyframes rainbowRotate {
  0%   { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

/* 확장 상태에서는 무지개 테두리 숨기기 */
.chat-input-bar.expanded::before {
  display: none;
}

/* 확장 상태 */
.chat-input-bar.expanded {
  max-width: 780px;
}

.chat-input-wrap {
  display: flex;
  flex-direction: column;
  background: rgba(65, 65, 65, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 28px;
  padding: 6px;
  transition: border-color 0.2s;
  position: relative;
  overflow: hidden;
}

/* 입력창 shimmer 효과 (확장 전) */
.chat-input-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.03) 30%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.03) 70%,
    transparent
  );
  animation: inputShimmer 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes inputShimmer {
  0%   { left: -100%; }
  100% { left: 100%; }
}

/* 확장 후 shimmer 제거 */
.chat-input-bar.expanded .chat-input-wrap::after {
  display: none;
}

.chat-input-wrap:focus-within {
  border-color: rgba(255, 255, 255, 0.25);
}

/* 하단 입력 행 */
.chat-input-row {
  display: flex;
  align-items: center;
}

/* 확장 상태: 입력 필드 3배 */
.chat-input-bar.expanded .chat-input-field {
  height: 108px;
  line-height: 1.6;
  overflow-y: auto;
}

.chat-input-bar.expanded .chat-input-row {
  align-items: flex-end;
}

.chat-input-bar.expanded .chat-input-plus,
.chat-input-bar.expanded .chat-input-btn {
  margin-bottom: 2px;
}

/* 이미지 프리뷰 영역 */
.chat-input-preview {
  display: none;
  padding: 8px 8px 4px 8px;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-input-preview.has-image {
  display: flex;
}

.chat-input-thumb {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.chat-input-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-input-thumb-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0;
}

.chat-input-thumb-del:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* 좌측 + 버튼 */
.chat-input-plus {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: 22px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  padding: 0;
  margin-right: 4px;
}

.chat-input-plus:hover {
  color: rgba(255, 255, 255, 0.9);
}

/* 입력 필드 (textarea) */
.chat-input-field {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  line-height: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  margin: 0;
  color: #fff;
  background: transparent;
  font-family: 'Pretendard', sans-serif;
  resize: none;
  overflow-y: hidden;
  transition: height 0.3s ease;
}

.chat-input-field::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

/* 우측 버튼 */
.chat-input-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #3A68FE;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-family: 'Pretendard', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
  pointer-events: auto;
}

/* 활성 상태: 내용이 있을 때 */
.chat-input-btn.active {
  background: #fff;
  color: #1a1a1a;
  cursor: pointer;
  pointer-events: auto;
}

.chat-input-btn.active:hover {
  background: #e5e5e5;
}

/* 아이콘 토글: 기본=NOA텍스트, 활성=화살표 */
.chat-input-btn .btn-label {
  display: block;
}
.chat-input-btn .btn-arrow {
  display: none;
}
.chat-input-btn.active .btn-label {
  display: none;
}
.chat-input-btn.active .btn-arrow {
  display: block;
}

/* AI 응답 메시지 (좌측) */
.chat-msg-ai {
  align-self: flex-start;
  max-width: 70%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.chat-msg-ai .chat-msg-text {
  color: #fff;
  padding: 12px 18px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.6;
  font-family: 'Pretendard', sans-serif;
  word-break: break-word;
  white-space: pre-wrap;
  background: rgba(255, 255, 255, 0.12);
}

.chat-msg-ai .chat-msg-text.chat-msg-error {
  color: #ff8a8a;
}

/* 링크 버튼 */
.chat-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px 4px 8px;
  margin: 2px 2px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s;
  vertical-align: middle;
}

.chat-link-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
}

.chat-link-btn svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.chat-link-btn:hover svg {
  opacity: 1;
}

/* 참고자료 (말풍선 내부 하단) */
.chat-sources {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.chat-sources-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 8px;
}

.chat-sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-source-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px 5px 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s;
}

.chat-source-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.chat-source-btn svg {
  flex-shrink: 0;
  opacity: 0.5;
}

.chat-source-btn:hover svg {
  opacity: 1;
}

/* 복사 버튼 */
.chat-copy-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, 0.35);
  cursor: pointer;
  padding: 0;
  transition: color 0.2s, background 0.2s;
}

.chat-copy-btn:hover {
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.08);
}

/* 스켈레톤 UI */
.chat-skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  width: 480px;
  min-width: 480px;
  max-width: 100%;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  transition: width 0.4s ease;
}

/* shimmer sweep overlay */
.chat-skeleton::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.05) 30%,
    rgba(255, 255, 255, 0.10) 50%,
    rgba(255, 255, 255, 0.05) 70%,
    transparent
  );
  animation: shimmerSweep 1.8s ease-in-out infinite;
}

@keyframes shimmerSweep {
  0%   { left: -100%; }
  100% { left: 100%; }
}

.chat-skeleton-line {
  height: 13px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.10);
}

.chat-skeleton-line:nth-child(1) { width: 90%; }
.chat-skeleton-line:nth-child(2) { width: 75%; }
.chat-skeleton-line:nth-child(3) { width: 82%; }
.chat-skeleton-line:nth-child(4) { width: 60%; }
.chat-skeleton-line:nth-child(5) { width: 88%; }
.chat-skeleton-line:nth-child(6) { width: 70%; }
.chat-skeleton-line:nth-child(7) { width: 78%; }
.chat-skeleton-line:nth-child(8) { width: 55%; }
.chat-skeleton-line:nth-child(9) { width: 85%; }
.chat-skeleton-line:nth-child(10) { width: 65%; }
.chat-skeleton-line:nth-child(11) { width: 92%; }
.chat-skeleton-line:nth-child(12) { width: 50%; }

/* 새 라인 등장 */
.chat-skeleton-line.new {
  animation: lineAppear 0.3s ease forwards;
}

@keyframes lineAppear {
  from { opacity: 0; width: 0; }
  to   { opacity: 1; }
}

/* 스켈레톤 → 콘텐츠 전환 */
.chat-msg-ai .chat-msg-text.fade-in {
  animation: contentReveal 0.3s ease forwards;
}

@keyframes contentReveal {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 모바일 */
@media screen and (max-width: 767px) {
  .chat-input-bar {
    bottom: 16px;
    max-width: 100%;
    padding: 0 12px;
  }

  .chat-input-wrap {
    padding: 5px 5px 5px 5px;
  }

  .chat-input-field {
    font-size: 14px;
  }

  .chat-input-btn {
    width: 34px;
    height: 34px;
    font-size: 12px;
  }

  .chat-input-plus {
    width: 32px;
    height: 32px;
    font-size: 20px;
  }

  .chat-input-thumb {
    width: 96px;
    height: 96px;
  }

  .chat-input-thumb-del {
    width: 24px;
    height: 24px;
    font-size: 14px;
    top: 4px;
    right: 4px;
  }

  /* 모바일에서는 확장 높이 그대로 */
  .chat-input-bar.expanded .chat-input-field {
    height: 36px;
    line-height: 36px;
    overflow-y: hidden;
  }

  /* 모바일: 스켈레톤 너비 제한 */
  .chat-skeleton {
    width: 300px;
    min-width: 0;
  }

  /* 모바일: 메시지 영역 하단 여백 축소 */
  .chat-messages {
    bottom: 90px;
  }

  /* 모바일: 웹뷰 전체 화면 */
  .chat-overlay.webview-open .chat-webview {
    width: 100%;
  }

  .chat-overlay.webview-open .chat-messages {
    display: none;
  }

  .chat-overlay.webview-open ~ .chat-input-bar {
    display: none;
  }

  /* 모바일: 웹뷰 열려있으면 채팅 뒤로가기 숨김 */
  .chat-overlay.webview-open .chat-back-btn {
    display: none !important;
  }

  /* 모바일 뒤로가기 표시 */
  .chat-overlay.visible .chat-back-btn {
    display: flex;
  }
}
