/* ===================================================================
   Chat Slide Panel - Responsive 2-Column Layout
   PC (769px+): 70% main : 30% chat
   Tablet (481-768px): 60% main : 40% chat
   Mobile (≤480px): 0% main : 100% chat (main hidden)
   =================================================================== */

/* 📦 Chat Panel Overlay (배경 어두워짐 - 없음) */
.chat-panel-overlay {
  display: none !important;
}

.chat-panel-overlay.active {
  display: none !important;
}

/* 📌 Chat Slide Panel (우측 2분할 영역) */
.chat-slide-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 30%;
  height: 100vh;
  background: #f5f5f5;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  z-index: 1000;
  font-family: "Source Sans Pro", Helvetica, sans-serif;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

/* 채팅 패널이 활성화되면 슬라이드 인 */
.chat-slide-panel.active {
  display: flex;
  transform: translateX(0);
}

/* 메인 콘텐츠 너비 조정 (채팅 패널 활성화 시) */
body.chat-open .avatar-container,
body.chat-open .avatar-display-section,
body.chat-open .hedra-container {
  max-width: none;
  width: 70% !important;
}

body.chat-open {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: row;
}

body.chat-open .avatar-container {
  height: 100vh;
  padding: var(--spacing-md, 1.5rem);
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0;
}

body.chat-open .hedra-container {
  max-height: none;
  overflow: visible;
  padding: var(--spacing-md, 1.5rem);
}

/* HTML 높이 고정 (모바일 주소표시줄 고려) */
html {
  height: 100%;
}

html.chat-open-html {
  height: 100vh;
  overflow: hidden;
}

/* ================================================================
   📱 모바일 레이아웃 (480px 이하: 0:100 - 채팅만, 메인 숨김)
   ================================================================ */
@media (max-width: 480px) {
  html.chat-open-html {
    height: 100dvh;
    overflow: hidden;
  }
  
  body.chat-open {
    height: 100dvh;
  }
  
  .chat-slide-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 100%;
    height: 100dvh;
    z-index: 100;
  }
  
  body.chat-open .avatar-container,
  body.chat-open .avatar-display-section,
  body.chat-open .hedra-container {
    display: none !important;
  }
  
  body.chat-open .chat-slide-panel {
    width: 100%;
    height: 100dvh;
    position: fixed;
    left: 0;
    right: 0;
  }
  
  body.chat-open #sidebar {
    display: none !important;
  }
  
  body.chat-open #wrapper {
    display: none !important;
  }
}

/* ================================================================
   📱 태블릿 레이아웃 (481px ~ 768px: 60:40 - 메인 60% : 채팅 40%)
   ================================================================ */
@media (min-width: 481px) and (max-width: 768px) {
  .chat-slide-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 40%;
    height: 100vh;
    z-index: 100;
  }
  
  body.chat-open .avatar-container,
  body.chat-open .avatar-display-section,
  body.chat-open .hedra-container {
    width: 60% !important;
  }
  
  body.chat-open .avatar-container {
    height: 100vh;
    padding: var(--spacing-sm, 0.75rem);
    overflow-y: auto;
    overflow-x: hidden;
    margin: 0;
  }
  
  body.chat-open .hedra-container {
    max-height: none;
    overflow: visible;
    padding: var(--spacing-sm, 0.75rem);
  }
}

/* ================================================================
   🖥️ PC 레이아웃 (769px 이상: 70:30 - 메인 70% : 채팅 30%)
   ================================================================ */
@media (min-width: 769px) {
  .chat-slide-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 30%;
    height: 100vh;
    z-index: 100;
  }
  
  body.chat-open .avatar-container,
  body.chat-open .avatar-display-section,
  body.chat-open .hedra-container {
    width: 70% !important;
  }
}

/* 📌 Chat Panel Header */
.chat-panel-header {
  padding: 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #5e42a6 0%, #b74e91 100%);
  color: white;
  flex-shrink: 0;
}

.chat-profile-section {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chat-profile-img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid white;
  flex-shrink: 0;
  background: linear-gradient(135deg, #5e42a6 0%, #b74e91 100%);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.3), inset 0 0 6px rgba(255, 255, 255, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chat-profile-img:hover {
  transform: scale(1.05);
  box-shadow: 0 0 16px rgba(183, 78, 145, 0.4), inset 0 0 8px rgba(255, 255, 255, 0.15);
}

.chat-profile-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-profile-name {
  font-weight: 600;
  font-size: 15px;
  color: white;
  margin: 0;
}

.chat-profile-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.9);
  margin: 2px 0 0 0;
}

.chat-panel-close {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.chat-panel-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-panel-close:active {
  background: rgba(255, 255, 255, 0.3);
}

/* 💬 Chat Panel Body */
.chat-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f5f5f5;
  scroll-behavior: smooth;
  align-items: flex-start;
}

/* 📭 Empty State */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
  text-align: center;
  padding: 20px;
  width: 100%;
}

.chat-empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
  color: #b74e91;
}

.chat-empty-state p {
  font-size: 14px;
  margin: 0;
  line-height: 1.4;
}

/* 💭 Message Bubble - Original style (backward compatible) */
.chat-message-bubble {
  display: inline-block;
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.4;
  animation: fadeIn 0.3s ease-out;
}

/* 💭 Message - New unified style */
.chat-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.4;
  animation: fadeIn 0.3s ease-out;
}

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

/* 👤 User Message (우측) */
.chat-message-bubble.user-message,
.chat-message.user-message {
  align-self: flex-end;
  background: linear-gradient(135deg, #5e42a6 0%, #b74e91 100%);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 4px rgba(94, 66, 166, 0.2);
}

/* 🤖 AI Message (좌측) */
.chat-message-bubble.ai-message,
.chat-message.assistant-message {
  align-self: flex-start;
  background: #1a1a1a;
  color: white;
  border: none;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* ⏳ Loading Indicator */
.chat-message-bubble.loading-message,
.chat-message.loading {
  align-self: flex-start;
  background: #1a1a1a;
  color: #999;
  border: none;
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 10px 14px;
  min-width: 60px;
  width: auto;
}

.loading-dot {
  width: 6px;
  height: 6px;
  background: #999;
  border-radius: 50%;
  animation: bounce 1.4s infinite;
  display: inline-block;
  flex-shrink: 0;
}

.loading-dot:nth-child(1) {
  animation-delay: 0s;
}

.loading-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-6px);
  }
}

/* ⚠️ Error Message */
.chat-message-bubble.error-message,
.chat-message.error-message {
  align-self: flex-start;
  background: #fee;
  color: #c33;
  border: 1px solid #fcc;
  border-bottom-left-radius: 4px;
}

/* 🧠 MBTI Error Container - 사용자 친화적 에러 메시지 */
.mbti-error-container {
  padding: 4px;
}

.mbti-error-container p {
  margin: 0;
  line-height: 1.5;
}

.mbti-error-container .mbti-test-link {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white !important;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 500;
  transition: transform 0.2s, box-shadow 0.2s;
}

.mbti-error-container .mbti-test-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.mbti-error-container .mbti-test-link:active {
  transform: translateY(0);
}

/* MBTI 에러 메시지는 배경색 오버라이드 */
.chat-message.error-message:has(.mbti-error-container) {
  background: #fff5f5;
  border-color: #fed7d7;
  color: #333;
}

/* 📝 Chat Panel Footer */
.chat-panel-footer {
  padding: 12px 16px;
  border-top: 1px solid #e0e0e0;
  background: white;
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input-field {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s ease;
  outline: none;
}

.chat-input-field:focus {
  border-color: #b74e91;
  box-shadow: 0 0 0 2px rgba(183, 78, 145, 0.1);
}

.chat-input-field::placeholder {
  color: #999;
}

.chat-send-btn {
  background: linear-gradient(135deg, #5e42a6 0%, #b74e91 100%);
  border: none;
  color: white;
  font-size: 16px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}

.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(183, 78, 145, 0.3);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

/* 📱 반응형 디자인 */
@media (max-width: 768px) {
  .chat-slide-panel {
    width: 100%;
    right: -100%;
  }
  
  .chat-message-bubble {
    max-width: 90%;
  }
  
  .chat-panel-header {
    padding: 12px;
  }
  
  .chat-panel-body {
    padding: 12px;
  }
  
  .chat-panel-footer {
    padding: 10px 12px;
  }
  
  .chat-profile-img {
    width: 36px;
    height: 36px;
  }
  
  .chat-profile-name {
    font-size: 13px;
  }
  
  .chat-profile-status {
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  .chat-slide-panel {
    width: 100%;
  }
  
  .chat-message-bubble {
    max-width: 95%;
    padding: 8px 10px;
    font-size: 13px;
  }
  
  .chat-input-field {
    padding: 6px 10px;
    font-size: 13px;
  }
  
  /* 모바일 로딩 인디케이터 - 가로 정렬 보장 */
  .chat-message-bubble.loading-message,
  .chat-message.loading {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 6px;
    min-width: 50px;
  }
  
  .loading-dot {
    display: inline-block !important;
    flex-shrink: 0;
  }
}

/* ================================================================
   📱 Galaxy Z Fold7 폴더블 - 채팅 분할 레이아웃
   펼친 화면에서 채팅 열 때: 메인 숨기고 채팅만 전체 표시
   ================================================================ */

/* 폴더블 펼친 화면: 채팅 열면 전체화면 */
@media screen and (min-width: 700px) and (max-width: 1400px) and (max-height: 1100px) and (min-height: 600px) {
    /* 채팅 패널 전체 화면 */
    .chat-slide-panel {
        width: 100% !important;
        left: 0 !important;
        right: 0 !important;
    }
    
    /* 메인 콘텐츠 숨김 */
    body.chat-open .avatar-container,
    body.chat-open .avatar-display-section,
    body.chat-open .hedra-container,
    body.chat-open .avatar-header {
        display: none !important;
    }
    
    body.chat-open .mobile-hamburger-wrapper {
        display: none !important;
    }
}
