/* ========== 메시지 스타일 (head_style_0018.css에서 분리, 2025-10-02) ========== */
/* 라인 650-2395 범위에서 메시지 관련 스타일 추출 */

/* ---------- 메시지 컨테이너 ---------- */
/* 레이아웃 스타일은 layout.css에서 관리 (2025-10-20) */
.chat-messages {
  gap: var(--space-4);  /* 메시지 간 간격만 관리 */
}

/* ---------- 메시지 기본 구조 ---------- */
.message {
  display: flex;
  gap: 12px;
  width: min(var(--chat-rail-width, var(--chat-thread-max, 720px)), 100%);
  margin: 0 auto;
  box-sizing: border-box;
  padding: 0 var(--chat-thread-padding, 20px);
}

.message.user {
  flex-direction: row-reverse;
}

/* ---------- 메시지 아바타 ---------- */
.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden; /* 이미지가 아바타 밖으로 넘치지 않도록 */
  position: relative; /* absolute 포지셔닝을 위한 기준점 */
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); /* (★수정) 더 진한 그라데이션 */
  color: #ffffff; /* (★수정) 명시적 흰색 */
  font-weight: 700; /* (★수정) 굵게 */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); /* (★추가) 텍스트 그림자로 가독성 향상 */
}

.message.assistant .message-avatar {
  background: var(--bg-chat);
  color: var(--text-primary);
}

/* ---------- 메시지 콘텐츠 ---------- */
.message-content {
  flex: 1 1 auto;
  max-width: 100%;
  min-width: 0;
  overflow: visible; /* (★중요) 스크롤 잘림 방지 */
  max-height: none; /* (★중요) 높이 제한 제거 */
}

.message.assistant .message-content {
  margin-right: auto;
}

.message.user .message-content {
  margin-right: auto;
}

/* 음악 플레이어를 포함한 메시지 폭 제한 */
.message:has(.music-player-wrapper) .message-content {
  max-width: 520px !important; /* (★중요) 플레이어 최대 폭보다 약간 크게 */
  min-width: auto !important;
}

/* ---------- 메시지 말풍선 ---------- */
.message-bubble {
  padding: 12px 16px; /* (★중요) 패딩 축소로 컴팩트하게 */
  border-radius: 16px;
  background: var(--bg-chat); /* (★중요) 가독성 개선 */
  box-shadow: var(--shadow);
  position: relative;
  overflow: visible; /* (★중요) 리스트 불릿이 잘리지 않도록 */
  border: 1px solid var(--border-primary); /* (★중요) 경계선 추가로 명확성 향상 */
}

/* AI 메시지 버블 */
.message.assistant .message-bubble {
  background: var(--bg-chat);
  color: var(--text-primary);
}

.search-source-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary-700, #4338ca);
  background: rgba(99, 102, 241, 0.12);
  border-radius: 999px;
  padding: 4px 10px;
  margin-bottom: 8px;
  width: fit-content;
}

body.dark-mode .search-source-chip {
  color: var(--primary-200, #c7d2fe);
  background: rgba(99, 102, 241, 0.24);
}

/* .message.user .message-bubble 스타일은 /css/main.css로 이동 */

/* ---------- 메시지 텍스트 ---------- */
.message-text {
  line-height: 1.5; /* (★중요) 줄 간격 축소 */
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  max-width: 100%;
  overflow: visible; /* (★중요) overflow: hidden 제거로 리스트 표시 문제 해결 */
}

/* (★중요) 리스트 스타일링 개선 - 불릿 포인트가 제대로 표시되도록 */
.message-text ul,
.message-text ol {
  margin: 4px 0; /* (★중요) 여백 대폭 축소 */
  padding-left: 20px; /* (★중요) 왼쪽 패딩 축소 */
  list-style-position: outside; /* inside → outside로 변경 */
}

.message-text li {
  margin: 2px 0; /* (★중요) 항목 간 간격 대폭 축소 */
  padding-left: 2px; /* (★중요) 불릿과 텍스트 간격 축소 */
  line-height: 1.4;
}

.message-text ul li {
  list-style-type: disc;
}

.message-text ol li {
  list-style-type: decimal;
}

/* (★중요) 중첩 리스트 스타일 */
.message-text ul ul,
.message-text ol ol,
.message-text ul ol,
.message-text ol ul {
  margin-top: 2px; /* (★중요) 중첩 리스트 여백 축소 */
  margin-bottom: 2px;
}

/* (★중요) 텍스트 정렬 및 들여쓰기 보정 */
.message-text p {
  margin: 4px 0; /* (★중요) 단락 여백 축소 */
  line-height: 1.5;
}

/* (★중요) 특수문자 및 이모지 처리 */
.message-text {
  font-feature-settings: normal;
  text-rendering: optimizeLegibility;
}

.message-text .citation-block {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.message-text .citation-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.message-text .citation-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-text .citation-list li {
  margin: 0;
  padding: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary, #64748b);
}

.message-text .citation-link {
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

.message-text .citation-link:hover,
.message-text .citation-link:focus-visible {
  text-decoration: underline;
  color: var(--primary-600, #5844d9);
}

/* ---------- 메시지 액션 버튼 ---------- */
.message-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.message:hover .message-actions {
  opacity: 1;
}

/* 모바일에서는 항상 표시 */
@media (hover: none) and (pointer: coarse) {
  .message-actions {
    opacity: 1 !important;
  }
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 16px;
  background: var(--bg-secondary);
  color: var(--text-primary); /* ★수정: 더 진한 색상으로 가독성 향상 */
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
}

.action-btn:hover {
  background: var(--primary-color);
  color: white;
  transform: translateY(-1px);
}

/* ★추가: 라이트 모드에서 명확한 대비 */
[data-theme="light"] .action-btn {
  color: #1c1f3b; /* 진한 남색 */
  background: rgba(28, 31, 59, 0.06); /* 약간의 배경색 */
}

/* ★추가: 다크 모드에서도 명확한 대비 */
[data-theme="dark"] .action-btn {
  color: #f4f5ff; /* 밝은 흰색 */
  background: rgba(244, 245, 255, 0.08); /* 약간의 배경색 */
}

/* ★추가: 라이트 모드에서 복사됨 상태 우선순위 명확화 */
[data-theme="light"] .action-btn.copied {
  background: var(--success-color) !important;
  color: white !important;
}

/* ★추가: 다크 모드에서 복사됨 상태 우선순위 명확화 */
[data-theme="dark"] .action-btn.copied {
  background: var(--success-color) !important;
  color: white !important;
}

.action-btn.active {
  background: var(--primary-color);
  color: white;
}

.action-btn.copied {
  background: var(--success-color);
  color: white;
}

.like-btn.active {
  background: var(--success-color);
  color: white;
}

.dislike-btn.active {
  background: var(--error-color);
  color: white;
}

/* ---------- 응답 시간 표시 ---------- */
.response-time {
  font-size: 12px;
  color: var(--text-light);
  background: var(--bg-secondary);
  padding: 4px 8px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.response-time::before {
  content: '⏱️';
  font-size: 10px;
}

/* ---------- 메시지 타임스탬프 ---------- */
.message-time {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 8px;
}

.message.user .message-time {
  color: rgba(255, 255, 255, 0.8);
}

/* ---------- 타이핑 인디케이터 ---------- */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 16px;
  background: var(--bg-primary);
  border-radius: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---------- 스트리밍 타이핑 애니메이션 (2025-10-14) ---------- */
.typing-animation {
  position: relative;
}

.typing-animation::after {
  content: '▌';
  display: inline-block;
  color: var(--primary-color);
  animation: cursor-blink 0.8s step-end infinite;
  margin-left: 2px;
  font-weight: 400;
}

@keyframes cursor-blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ---------- 스트리밍 대기 중 점 애니메이션 (2025-10-18 리프레시) ---------- */
.waiting-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-radius: 14px;
  line-height: 1.6;
  white-space: normal;
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--bg-secondary) 70%, rgba(106, 85, 255, 0.22) 30%),
    color-mix(in srgb, var(--bg-chat) 88%, rgba(106, 85, 255, 0.12) 12%)
  );
  background-size: 200% 200%;
  border: 1px solid color-mix(in srgb, var(--primary-color) 32%, transparent 68%);
  box-shadow: 0 14px 32px rgba(var(--shadow-rgb), 0.14);
  backdrop-filter: blur(14px);
  animation: waitingGlow 6s ease-in-out infinite;
}

.waiting-status .waiting-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.32s ease;
}

.waiting-status .waiting-text.is-fading {
  opacity: 0;
}

.waiting-dots {
  display: inline-flex;
  align-items: center;
  min-width: 1.6ch;
  gap: 2px;
  padding-left: 2px;
  color: color-mix(in srgb, var(--primary-color) 78%, var(--text-secondary) 22%);
}

.waiting-dots span {
  opacity: 0;
  display: inline-block;
  width: 0.55ch;
  font-weight: 600;
  text-shadow: 0 0 12px color-mix(in srgb, var(--primary-color) 55%, transparent 45%);
  transform-origin: center;
  animation: waitingDotPulse 1.6s ease-in-out infinite;
}

.waiting-long-message {
  width: 100%;
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 0.95em;
}

.waiting-dots span:nth-child(1) { animation-delay: 0s; }
.waiting-dots span:nth-child(2) { animation-delay: 0.18s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.36s; }

@media (prefers-reduced-motion: reduce) {
  .waiting-status {
    backdrop-filter: none;
    box-shadow: 0 8px 18px rgba(var(--shadow-rgb), 0.08);
    animation: none;
  }

  .waiting-dots span {
    animation: none;
    opacity: 1;
    transform: none;
    text-shadow: none;
  }
}

/* ---------- 메시지 관련 코드 블록 스타일 ---------- */
.message-text pre,
.message-text code {
  font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', 'Courier New', monospace;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.6;
  box-shadow: none;
  transition: background 0.2s, color 0.2s;
}

.message-text code {
  background: var(--code-inline-bg);
  color: var(--code-fg);
  border: 1px solid #d0d7de;
  padding: 2px 7px;
}

/* ========== 코드 블록 상세 스타일은 css/components/code-blocks.css 참조 ========== */
