/* OTTO Chatbot Widget */

/* 플로팅 버튼 — appbar(54px) 바로 위 */
#chatbot-toggle {
  position: fixed;
  bottom: 64px;
  right: 10px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #212020;
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
}
#chatbot-toggle:hover {
  transform: scale(1.08);
  background: #333;
}
#chatbot-toggle svg {
  width: 24px;
  height: 24px;
  fill: #fff;
}
#chatbot-toggle .chatbot-close-icon {
  display: none;
}
#chatbot-toggle.active .chatbot-chat-icon {
  display: none;
}
#chatbot-toggle.active .chatbot-close-icon {
  display: block;
}

/* 채팅 패널 */
#chatbot-panel {
  position: fixed;
  bottom: 124px;
  right: 10px;
  width: 350px;
  height: 500px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  z-index: 9998;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Pretendard', -apple-system, sans-serif;
}
#chatbot-panel.open {
  display: flex;
}

/* 헤더 */
#chatbot-header {
  background: #212020;
  color: #fff;
  padding: 16px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#chatbot-header svg {
  width: 20px;
  height: 20px;
  fill: #fff;
  flex-shrink: 0;
}

/* 메시지 영역 */
#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f5f5f5;
}
#chatbot-messages::-webkit-scrollbar {
  width: 4px;
}
#chatbot-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 2px;
}

/* 메시지 버블 */
.chatbot-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.chatbot-msg.bot {
  background: #fff;
  color: #333;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.chatbot-msg.user {
  background: #212020;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* 챗봇 답변 안의 마크다운 표 → HTML 표 */
.chatbot-msg.bot .chatbot-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
  margin: 6px 0;
  background: #fafafa;
  table-layout: fixed;
}
.chatbot-msg.bot .chatbot-table th,
.chatbot-msg.bot .chatbot-table td {
  border: 1px solid #e0e0e0;
  padding: 5px 7px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
  white-space: normal;
}
.chatbot-msg.bot .chatbot-table th {
  background: #f0f0f0;
  font-weight: 600;
  color: #222;
}
.chatbot-msg.bot .chatbot-table tr:nth-child(even) td {
  background: #f5f5f5;
}
.chatbot-msg.bot .chatbot-table a {
  color: #2e7d32;
  text-decoration: underline;
}
.chatbot-msg-text { white-space: pre-wrap; }

/* 로딩 인디케이터 */
.chatbot-msg.loading {
  background: #fff;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.chatbot-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}
.chatbot-dots span {
  width: 6px;
  height: 6px;
  background: #999;
  border-radius: 50%;
  animation: chatbot-bounce 1.4s infinite ease-in-out;
}
.chatbot-dots span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatbot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* 빠른 메뉴 버튼 */
#chatbot-quick-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 8px;
  background: #f5f5f5;
  flex-shrink: 0;
}
.chatbot-quick-btn {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 16px;
  font-size: 12px;
  color: #333;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.chatbot-quick-btn:hover {
  background: #212020;
  color: #fff;
  border-color: #212020;
}

/* 입력 영역 */
#chatbot-input-area {
  display: flex;
  padding: 12px;
  background: #fff;
  border-top: 1px solid #eee;
  gap: 8px;
  flex-shrink: 0;
}
#chatbot-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
  resize: none;
  max-height: 80px;
  line-height: 1.4;
}
#chatbot-input:focus {
  border-color: #212020;
}
#chatbot-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #212020;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#chatbot-send:hover {
  background: #444;
}
#chatbot-send:disabled {
  background: #ccc;
  cursor: not-allowed;
}
#chatbot-send svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* PC: appbar 800px 중앙정렬 기준 우측 끝 */
@media (min-width: 481px) {
  #chatbot-toggle {
    right: calc(50% - 400px + 10px);
  }
  #chatbot-panel {
    right: calc(50% - 400px + 10px);
  }
}

/* 모바일 — clamp 로 화면크기에 따라 동적으로 비율 + 한계값 */
@media (max-width: 480px) {
  #chatbot-toggle {
    bottom: clamp(56px, 8vh, 76px);
    right: clamp(8px, 3vw, 14px);
  }
  #chatbot-panel {
    /* 상단: OTTO 헤더(로고·언어선택·메신저 아이콘)와 겹치지 않게 14vh 이상 띄움 */
    top: clamp(88px, 14vh, 120px);
    /* 하단: 챗봇 토글 + appbar 위에 안 걸리게 */
    bottom: clamp(96px, 14vh, 130px);
    /* 좌우: viewport 비율 기반 여백 */
    left: clamp(12px, 4vw, 24px);
    right: clamp(12px, 4vw, 24px);
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    border-radius: 14px;
  }
}
