/* ================================================
   DSH에듀 채팅 위젯
   ================================================ */

/* ── FAB (Floating Action Button) ── */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: #0040c8;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 16px rgba(0, 64, 200, 0.4);
  z-index: 9999;
  transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
  outline: none;
}

.chat-fab:hover {
  background-color: #0033a0;
  box-shadow: 0 6px 20px rgba(0, 64, 200, 0.5);
  transform: scale(1.06);
}

.chat-fab:active {
  transform: scale(0.96);
}

/* 안읽음 뱃지 */
.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background-color: #e53e3e;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  border: 2px solid #fff;
}

/* 뱃지 있을 때 pulse 애니메이션 */
.chat-fab.has-unread {
  animation: chat-pulse 2s infinite;
}

@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(0, 64, 200, 0.4); }
  50%       { box-shadow: 0 4px 24px rgba(0, 64, 200, 0.7); }
}

/* ── 채팅 패널 ── */
.chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 64, 200, 0.12), 0 2px 8px rgba(0,0,0,0.08);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: chat-panel-open 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes chat-panel-open {
  from { opacity: 0; transform: scale(0.85) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── 헤더 ── */
.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #0040c8;
  color: #fff;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}

.chat-admin-status {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: #a0aec0;
  border: 2px solid rgba(255,255,255,0.6);
  flex-shrink: 0;
  transition: background-color 0.3s;
}

.chat-admin-status.online {
  background-color: #48bb78;
}

.chat-close-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
  transition: background-color 0.15s, color 0.15s;
}

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

/* ── 메시지 영역 ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 2px;
}

/* 로딩 스피너 */
.chat-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a0aec0;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
}

/* 빈 상태 */
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: #a0aec0;
  font-size: 13px;
  text-align: center;
}

.chat-empty i {
  font-size: 2.2rem;
  color: #cbd5e0;
}

/* 날짜 구분선 */
.chat-date-separator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 6px;
  color: #a0aec0;
  font-size: 11px;
}

.chat-date-separator::before,
.chat-date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e2e8f0;
}

/* 페이징 로더 */
.chat-load-more {
  text-align: center;
  padding: 8px 0;
  color: #a0aec0;
  font-size: 12px;
}

/* ── 메시지 버블 ── */
.chat-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 100%;
  margin-bottom: 2px;
}

.chat-msg-row.own {
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e2e8f0;
  color: #4a5568;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-msg-avatar.hidden {
  visibility: hidden;
}

.chat-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-msg-content {
  display: flex;
  flex-direction: column;
  max-width: 70%;
}

.chat-msg-row.own .chat-msg-content {
  align-items: flex-end;
}

.chat-msg-bubble {
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

/* 내 메시지 */
.chat-msg-row.own .chat-msg-bubble {
  background-color: #0040c8;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* 상대 메시지 */
.chat-msg-row.other .chat-msg-bubble {
  background-color: #f0f2f5;
  color: #1a202c;
  border-bottom-left-radius: 4px;
}

/* optimistic 전송 중 */
.chat-msg-row.sending .chat-msg-bubble {
  opacity: 0.65;
}

.chat-msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 10.5px;
  color: #a0aec0;
}

.chat-msg-row.own .chat-msg-meta {
  flex-direction: row-reverse;
}

.chat-read-receipt {
  font-size: 10px;
  color: #63b3ed;
  font-weight: 500;
}

/* ── 타이핑 인디케이터 ── */
.chat-typing-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 2px 0 4px;
}

.chat-typing-bubble {
  background: #f0f2f5;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 9px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a0aec0;
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); background: #a0aec0; }
  30%            { transform: translateY(-5px); background: #718096; }
}

/* ── 입력 영역 ── */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  resize: none;
  outline: none;
  max-height: 90px;
  overflow-y: auto;
  font-family: inherit;
  color: #1a202c;
  background: #f7f8fa;
  transition: border-color 0.15s;
}

.chat-input:focus {
  border-color: #0040c8;
  background: #fff;
}

.chat-input::placeholder {
  color: #a0aec0;
}

.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background-color: #0040c8;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: background-color 0.15s, opacity 0.15s, transform 0.15s;
}

.chat-send-btn:hover:not(:disabled) {
  background-color: #0033a0;
  transform: scale(1.05);
}

.chat-send-btn:disabled {
  background-color: #cbd5e0;
  cursor: not-allowed;
  opacity: 0.7;
}

/* ── 연결 오류 배너 ── */
.chat-error-banner {
  background: #fff5f5;
  color: #c53030;
  font-size: 12px;
  text-align: center;
  padding: 7px 12px;
  border-top: 1px solid #fed7d7;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.chat-reconnect-btn {
  background: none;
  border: 1px solid #c53030;
  color: #c53030;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}

.chat-reconnect-btn:hover {
  background: #c53030;
  color: #fff;
}

/* ── 환영 메시지 ── */
.chat-welcome-wrap {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 8px 0 12px;
}

.chat-welcome-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0040c8, #2563eb);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 2px;
}

.chat-welcome-bubble {
  background: #f0f2f5;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.65;
  color: #1a202c;
  max-width: 82%;
}

.chat-welcome-bubble strong {
  color: #0040c8;
}

/* ── 모바일 ── */
@media (max-width: 576px) {
  .chat-fab {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
    font-size: 20px;
  }

  .chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
    animation: none;
  }
}
