/* 새로운 챗박스 기본 스타일 - chatbox-base.css */
/* CSS 변수를 사용하여 테마별 색상 교체 가능 */

:root {
  /* 기본 파란색 테마 */
  --chatbot-primary-color: #003df5;
  --chatbot-primary-hover: #0033cc;
  --chatbot-primary-shadow: rgba(0, 61, 245, 0.3);
  --chatbot-primary-light: rgba(0, 61, 245, 0.1);
  --chatbot-background: #f6f6f7;
  --chatbot-white: #ffffff;
  --chatbot-text-primary: #222222;
  --chatbot-text-secondary: #6d6d6d;
  --chatbot-text-light: #667085;
  --chatbot-border: #e3e3e3;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    sans-serif;
}

.privacy-policy-link {
  color: var(--chatbot-primary-color);
  text-decoration: underline;
}

.privacy-policy-link:focus {
  color: var(--chatbot-primary-color);
  outline: none;
  border: none;
  box-shadow: none;
}

.privacy-policy-link:hover {
  color: var(--chatbot-primary-hover);
  text-decoration: underline;
}

/* 플로팅 챗 버튼 */
.floating-chat-btn {
  position: fixed; /* [수정] fixed -> relative로 변경 */
  right: 24px;
  bottom: 84px;
  width: 60px;
  height: 60px;
  background: var(--chatbot-primary-color);
  border-radius: 50%;
  box-shadow: 0px 5px 22px 0px rgba(0, 0, 0, 0.04),
    0px 0px 0px 1px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
}

.floating-chat-btn:hover {
  transform: scale(1.05);
  box-shadow: 0px 8px 30px 0px var(--chatbot-primary-shadow);
}

.floating-chat-btn svg {
  width: 28px;
  height: 28px;
  fill: #fff;
}
/* [추가] 알림 점 스타일 */
#notificationDot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 12px;
  height: 12px;
  background-color: #ff3b30;
  border-radius: 50%;
  border: 2px solid var(--chatbot-white);
  display: none; /* 평소에는 숨김 */
}

/* [추가] 알림 점을 보여줄 때 사용할 'show' 클래스 */
#notificationDot.show {
  display: block;
}
/* 챗 팝업 컨테이너 */
.chat-popup {
  position: fixed;
  right: 24px;
  bottom: 160px;
  width: 380px;
  max-width: calc(100vw - 48px);
  background: var(--chatbot-background);
  border-radius: 30px;
  box-shadow: 0px 5px 22px 0px rgba(0, 0, 0, 0.04),
    0px 0px 0px 1px rgba(0, 0, 0, 0.06);
  display: none;
  flex-direction: column;
  z-index: 1001;
  overflow: hidden;
  font-family: 'Inter', sans-serif;
}

/* 헤더 */
.chat-popup-header {
  background: var(--chatbot-white);
  border-bottom: 1px solid var(--chatbot-border);
  padding: 20px 28px 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-popup-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-popup-avatar {
  width: 40px;
  height: 40px;
  background: var(--chatbot-primary-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 16px;
}

.chat-popup-avatar i {
  font-size: 20px;
}

.chat-popup-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-popup-school-name {
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 20px;
  line-height: 1.5em;
  color: var(--chatbot-text-primary);
}

.chat-popup-close {
  background: none !important;
  border: none !important;
  color: var(--chatbot-text-primary) !important;
  font-size: 24px !important;
  cursor: pointer !important;
  padding: 4px !important;
  border-radius: 4px !important;
  transition: all 0.2s !important;
  width: 32px !important;
  height: 32px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.chat-popup-close:hover {
  background: rgba(0, 0, 0, 0.1) !important;
}

/* 초기 상태 화면 */
.chat-popup-welcome {
  padding: 28px 24px;
  text-align: center;
  background: var(--chatbot-background);
}

.chat-popup-welcome-avatar {
  width: 80px;
  height: 80px;
  background: var(--chatbot-primary-color);
  border-radius: 50%;
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.chat-popup-welcome-avatar svg {
  width: 40px;
  height: 40px;
  fill: white;
}

.chat-popup-welcome-avatar i {
  font-size: 40px;
}

.chat-popup-welcome-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-popup-welcome-text {
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.33em;
  color: var(--chatbot-text-secondary);
  margin-bottom: 32px;
  text-align: center;
}

.chat-popup-start-btn {
  background: var(--chatbot-primary-color);
  color: var(--chatbot-white);
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-family: 'Heebo', sans-serif;
  font-weight: 500;
  font-size: 16px;
  line-height: 1.5em;
  cursor: pointer;
  width: 100%;
  max-width: 300px;
  transition: all 0.2s;
}

.chat-popup-start-btn:hover {
  background: var(--chatbot-primary-hover);
  transform: translateY(-1px);
}

/* 메시지 영역 */
.chat-popup-messages {
  flex: 1;
  padding: 12px 16px;
  background: var(--chatbot-background);
  overflow-y: auto;
  display: none;
  flex-direction: column;
  gap: 12px;
  max-height: 400px;
}

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

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

.chat-popup-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

/* 메시지 스타일 */
.chat-message-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-message-group.ai {
  align-items: flex-start;
}

.chat-message-group.user {
  align-items: flex-end;
}

.chat-message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 12px;
  line-height: 2.5em;
  color: var(--chatbot-text-secondary);
}

.chat-message-header.ai {
  flex-direction: row;
}

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

.chat-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--chatbot-border);
}

.chat-message-avatar.ai {
  background: var(--chatbot-white);
}

.chat-message-avatar.user {
  background: var(--chatbot-primary-color);
  color: white;
  font-weight: 600;
  font-size: 14px;
}

.chat-message-avatar svg {
  width: 16px;
  height: 16px;
  fill: var(--chatbot-primary-color);
}

.chat-message-avatar i {
  font-size: 16px;
}

.chat-message-avatar.ai i {
  color: var(--chatbot-primary-color);
}

.chat-message-avatar.user i {
  color: white;
}

.chat-message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-popup-message {
  max-width: 80%;
  padding: 12px 20px;
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.44em;
  word-wrap: break-word;
  animation: slideIn 0.3s ease-out;
  border: 1px solid var(--chatbot-border);
}

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

.chat-popup-message.user {
  background: var(--chatbot-primary-color);
  color: var(--chatbot-white);
  border-color: var(--chatbot-primary-color);
}

.chat-popup-message.ai {
  background: var(--chatbot-white);
  color: var(--chatbot-text-secondary);
  border-color: var(--chatbot-border);
}

/* AI 메시지 내 요소 스타일링 */
.chat-popup-message.ai h1,
.chat-popup-message.ai h2,
.chat-popup-message.ai h3 {
  color: var(--chatbot-text-primary);
  margin: 8px 0 4px 0;
  font-size: 18px;
  font-weight: 600;
}

.chat-popup-message.ai p {
  margin: 0 0 8px 0;
}

.chat-popup-message.ai p:last-child {
  margin-bottom: 0;
}

.chat-popup-message.ai ul {
  padding-left: 16px;
  margin: 8px 0;
}

.chat-popup-message.ai li {
  margin-bottom: 4px;
}

.chat-popup-message.ai code {
  background: #f1f5f9;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 16px;
  color: var(--chatbot-primary-color);
}

.chat-popup-message.ai pre {
  background: #f1f5f9;
  border-radius: 8px;
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
}

.chat-popup-message.ai pre code {
  background: none;
  padding: 0;
  color: var(--chatbot-text-primary);
}

.chat-popup-message.ai a {
  color: var(--chatbot-primary-color);
  text-decoration: none;
}

.chat-popup-message.ai a:hover {
  text-decoration: underline;
}

/* 입력 영역 */
.chat-popup-input-bar {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--chatbot-background);
  border-top: 1px solid var(--chatbot-border);
}

/* 입력 제한 UI 스타일 */
.chat-popup-input-limit {
  font-size: 12px;
  color: var(--chatbot-text-light);
  text-align: right;
  padding-top: 4px;
  white-space: nowrap;
}

#charCount {
  font-weight: bold;
  color: var(--chatbot-text-primary);
}

.chat-popup-input-container {
  flex: 1;
  background: var(--chatbot-white);
  padding: 12px 16px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.chat-popup-textarea-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.chat-popup-input {
  border: none !important;
  outline: none !important;
  font-family: 'Inter', sans-serif !important;
  font-weight: 400 !important;
  font-size: 18px !important;
  line-height: 1.67em !important;
  color: var(--chatbot-text-secondary) !important;
  background: transparent !important;
  resize: none !important;
  min-height: 24px !important;
  max-height: 120px !important;
  overflow-y: auto !important;
  padding: 0 !important;
  background: none !important;
  color: #6d6d6d !important;
}

.chat-popup-input:focus {
  border: none !important;
  background: #fff !important;
  outline: none !important;
  box-shadow: 0 0 0 2px var(--chatbot-primary-focus-shadow) !important;
}

.chat-popup-input::placeholder {
  color: var(--chatbot-text-secondary);
}

.chat-popup-send-btn {
  background: none !important;
  border: none !important;
  cursor: pointer !important;
  padding: 4px !important;
  border-radius: 4px !important;
  transition: all 0.2s !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.chat-popup-send-btn:hover:not(:disabled) {
  background: var(--chatbot-primary-light);
}

.chat-popup-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-popup-send-btn svg {
  width: 20px;
  height: 20px;
  fill: var(--chatbot-text-secondary);
}

/* 푸터 */
.chat-popup-footer {
  background: rgba(255, 255, 255, 0.5);
  border-top: 1px solid var(--chatbot-border);
  padding: 4px 20px;
  text-align: center;
}

.chat-popup-footer-text {
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 15px;
  line-height: 2em;
  color: var(--chatbot-text-light);
}

/* 로딩 애니메이션 */
.loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--chatbot-text-secondary);
  font-style: italic;
}

.loading-dots span {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: bounce 1.4s infinite both;
}

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

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

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

/* 상태별 표시/숨김 */
.chat-popup.welcome-state .chat-popup-welcome {
  display: block;
}

.chat-popup.welcome-state .chat-popup-messages,
.chat-popup.welcome-state .chat-popup-input-bar {
  display: none;
}

.chat-popup.chat-state .chat-popup-welcome {
  display: none;
}

.chat-popup.chat-state .chat-popup-messages,
.chat-popup.chat-state .chat-popup-input-bar {
  display: flex;
}

/* 모바일 오버레이 */
.mobile-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-overlay.show {
  opacity: 1;
}

/* 태블릿 반응형 */
@media (max-width: 768px) and (min-width: 481px) {
  .chat-popup {
    width: 360px;
    max-width: calc(100vw - 32px);
    right: 16px;
    bottom: 90px;
  }

  .floating-chat-btn {
    right: 16px;
    bottom: 16px;
  }

  .chat-popup-header {
    padding: 24px 32px 20px 24px;
  }

  .chat-popup-welcome {
    padding: 32px 24px;
  }

  .chat-popup-messages {
    padding: 16px 24px;
  }
}

/* 모바일 반응형 */
@media (max-width: 480px) {
  .chat-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1001;
  }

  .chat-popup.show {
    transform: translateY(0);
  }

  .floating-chat-btn {
    right: 20px;
    bottom: 80px;
    width: 56px;
    height: 56px;
  }

  .floating-chat-btn svg {
    width: 24px;
    height: 24px;
  }

  .chat-popup-header {
    padding: 20px 20px 16px;
    padding-top: calc(env(safe-area-inset-top) + 20px);
    border-radius: 0;
    position: relative;
  }

  .chat-popup-welcome {
    padding: 24px 20px;
    height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .chat-popup-welcome-avatar {
    width: 60px;
    height: 60px;
    margin-bottom: 20px;
  }

  .chat-popup-welcome-avatar svg {
    width: 30px;
    height: 30px;
  }

  .chat-popup-welcome-avatar i {
    font-size: 30px;
  }

  .chat-popup-welcome-text {
    font-size: 16px;
    margin-bottom: 24px;
  }

  .chat-popup-messages {
    padding: 12px 16px;
    flex: 1;
    overflow-y: auto;
    height: calc(100vh - 240px);
    max-height: none;
  }

  .chat-popup-input-bar {
    background: var(--chatbot-background);
    border-radius: 0;
    margin-bottom: 40px;
  }

  .chat-popup-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px 20px calc(env(safe-area-inset-bottom) + 6px);
    border-radius: 0;
    background: rgba(255, 255, 255, 0.5);
    border-top: 1px solid var(--chatbot-border);
  }

  .chat-popup-school-name {
    font-size: 18px;
  }

  .chat-popup-avatar {
    width: 36px;
    height: 36px;
    font-size: 14px;
  }

  .chat-popup-avatar i {
    font-size: 18px;
  }

  .chat-message-avatar {
    width: 28px;
    height: 28px;
  }

  .chat-message-avatar svg {
    width: 14px;
    height: 14px;
  }

  .chat-message-avatar i {
    font-size: 14px;
  }

  .chat-popup-message {
    font-size: 16px;
    padding: 12px 20px;
  }

  /* 터치 인터페이스 개선 */
  .chat-popup-close {
    width: 40px;
    height: 40px;
    padding: 8px;
  }

  .chat-popup-send-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .chat-popup-start-btn {
    padding: 16px 24px;
    font-size: 16px;
    min-height: 48px;
  }

  /* 입력창 개선 */
  .chat-popup-input {
    font-size: 16px !important; /* iOS에서 줌 방지 */
    /* min-height: 44px; */
    padding: 12px 16px !important;
  }

  .chat-popup-input-container {
    padding: 12px 16px;
  }
}

/* 매우 작은 화면 (320px 이하) */
@media (max-width: 320px) {
  .floating-chat-btn {
    right: 16px;
    bottom: 16px;
    width: 52px;
    height: 52px;
  }

  .floating-chat-btn svg {
    width: 22px;
    height: 22px;
  }

  .chat-popup {
    height: 100vh;
    max-height: none;
  }

  .chat-popup-header {
    padding: 16px 16px 12px;
    padding-top: calc(env(safe-area-inset-top) + 16px);
  }

  .chat-popup-welcome {
    padding: 20px 16px;
    height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .chat-popup-welcome-text {
    font-size: 15px;
  }

  .chat-popup-messages {
    padding: 12px 16px;
    height: calc(100vh - 180px);
    max-height: none;
  }

  .chat-popup-input-container {
    padding: 12px 16px;
  }

  .chat-popup-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 16px calc(env(safe-area-inset-bottom) + 4px);
    background: rgba(255, 255, 255, 0.5);
    border-top: 1px solid var(--chatbot-border);
  }

  .chat-popup-school-name {
    font-size: 16px;
  }
}

/* 가로 모드 모바일 */
@media (max-width: 768px) and (orientation: landscape) and (max-height: 500px) {
  .chat-popup {
    height: 100vh;
    max-height: none;
  }

  .chat-popup-messages {
    height: calc(100vh - 180px);
    max-height: none;
  }

  .chat-popup-welcome {
    padding: 12px 16px;
    height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .chat-popup-welcome-avatar {
    width: 50px;
    height: 50px;
    margin-bottom: 16px;
  }

  .chat-popup-welcome-avatar svg {
    width: 25px;
    height: 25px;
  }

  .chat-popup-welcome-avatar i {
    font-size: 25px;
  }

  .chat-popup-welcome-text {
    font-size: 15px;
    margin-bottom: 20px;
  }

  .chat-popup-header {
    padding: 12px 20px 8px;
    padding-top: calc(env(safe-area-inset-top) + 12px);
  }
}
