@import url('https://fonts.googleapis.com/css2?family=Cafe24+Ssurround&display=swap');
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.min.css');

/* ===== 챗봇 팝업 컨테이너 (항상 열린 상태) ===== */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  background: #f0f2f5;
  overflow: hidden; /* 모바일에서 body 스크롤 방지 — chatbot-messages만 스크롤 */
  overscroll-behavior: none;
}

.chatbot-popup {
  display: flex;
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  height: 100vh; /* fallback for older browsers */
  height: 100dvh; /* dynamic viewport — 모바일 주소창/하단바 자동 반영 */
  max-height: 100dvh;
  border-radius: 0;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  z-index: 9998;
  flex-direction: column;
  background: #fff;
  font-family: 'Pretendard', sans-serif;
}

/* ===== 헤더 ===== */
.chatbot-header {
  background: linear-gradient(to right, #005826 0%, #005826 33.3%, #0e4e96 33.3%, #0e4e96 66.6%, #b82841 66.6%, #b82841 100%);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chatbot-header .title {
  font-size: 15px;
  font-weight: 600;
}

.chatbot-header .header-actions {
  display: flex;
  gap: 8px;
}

.chatbot-header button {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.chatbot-header button:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

/* ===== 메시지 영역 ===== */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f7f8fa;
}

/* 메시지 버블 */
.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.msg.bot {
  align-self: flex-start;
  background: #fff;
  color: #333;
  border: 1px solid #e5e7eb;
  border-top-left-radius: 4px;
}

.msg.user {
  align-self: flex-end;
  background: #004b2b;
  color: #fff;
  border-top-right-radius: 4px;
}

/* 마크다운 스타일 */
.msg.bot p { margin: 0 0 8px; }
.msg.bot p:last-child { margin-bottom: 0; }
.msg.bot ul, .msg.bot ol { margin: 4px 0; padding-left: 20px; }
.msg.bot table { border-collapse: collapse; margin: 8px 0; font-size: 13px; width: 100%; }
.msg.bot th, .msg.bot td { border: 1px solid #ddd; padding: 6px 8px; text-align: left; }
.msg.bot th { background: #f0f0f0; font-weight: 600; }
.msg.bot strong { color: #004b2b; }
.msg.bot code { background: #f0f0f0; padding: 2px 4px; border-radius: 3px; font-size: 13px; }

/* 피드백 버튼 */
.msg-feedback {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.msg-feedback button {
  background: none;
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 12px;
  color: #888;
  transition: all 0.2s;
}

.msg-feedback button:hover {
  border-color: #004b2b;
  color: #004b2b;
}

.msg-feedback button.active {
  border-color: #004b2b;
  background: #e8f5e9;
  color: #004b2b;
}

/* 빠른 질문 버튼 */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.quick-reply-btn {
  background: #fff;
  border: 1px solid #004b2b;
  color: #004b2b;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Pretendard', sans-serif;
}

.quick-reply-btn:hover {
  background: #004b2b;
  color: #fff;
}

/* 타이핑 인디케이터 */
.typing-indicator {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  border-top-left-radius: 4px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: #004b2b;
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite both;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== 입력 영역 ===== */
.chatbot-input {
  display: flex;
  padding: 12px;
  /* iOS/Android notch·홈 인디케이터 안전영역 처리 */
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #e5e7eb;
  background: #fff;
  gap: 8px;
  flex-shrink: 0;
}

.chatbot-input input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: 'Pretendard', sans-serif;
  outline: none;
  transition: border-color 0.2s;
}

.chatbot-input input:focus {
  border-color: #004b2b;
}

.chatbot-input input:disabled {
  background: #f5f5f5;
  color: #999;
}

.chatbot-input button {
  background: #004b2b;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.chatbot-input button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chatbot-input button:not(:disabled):hover {
  opacity: 0.85;
}

/* ===== 모바일 반응형 ===== */
@media (max-width: 480px) {
  .chatbot-popup {
    max-width: 100%;
    box-shadow: none;
  }
}

/* 스크롤바 스타일 */
.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}
