/**
 * HRDe Archive - ChatGPT Chatbot Widget
 * 
 * Purpose: Floating chatbot widget for all pages
 * Safe: Only adds new functionality, doesn't modify existing code
 * Clean Code: Component-based, mobile-first design
 */

/* ========================================
   CHATBOT WIDGET STYLES
   ======================================== */

/* Floating Chatbot Button */
.chatbot-toggle {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  left: auto;
/*   width: 60px;
  height: 60px; */
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  /* box-shadow: 0 4px 20px rgba(74, 108, 247, 0.4); */
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.5rem;
  padding: 0;
  overflow: visible !important;
  width: 120px;
}

.chatbot-icon-img {
  object-fit: contain;
  padding: 12px;
  position: relative;
  z-index: 1;
}

.chatbot-icon-img:hover {
  transform: scale(1.1);
}


.chatbot-toggle::after {
  content: attr(data-tooltip);
  position: absolute;
  right: calc(100% + 12px);
  bottom: 50%;
  transform: translateY(50%);
  background: rgba(255, 255, 255, 0.98);
  color: #1f2937;
  padding: 0.875rem 1.125rem;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(76, 106, 247, 0.3);
  font-size: 0.875rem;
  line-height: 1.4;
  width: 260px;
  pointer-events: none;
  white-space: pre-line;
  font-weight: 500;
  background-repeat: no-repeat;
  background-size: 40px 40px;
  background-position: 1.125rem center;
  z-index: 10000;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Override hidden class - tooltip should always be visible by default */
.chatbot-toggle:not(.is-tooltip-hidden)::after {
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

.chatbot-toggle::before {
  content: "";
  position: absolute;
  right: calc(100% + 4px);
  bottom: 50%;
  transform: translateY(50%) rotate(180deg);
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 10px 25px rgba(76, 106, 247, 0.15);
  border-radius: 4px;
  clip-path: polygon(0% 50%, 100% 0%, 100% 100%);
  z-index: 10000;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Override hidden class - tooltip arrow should always be visible by default */
.chatbot-toggle:not(.is-tooltip-hidden)::before {
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}


.chatbot-toggle.active::after,
.chatbot-toggle.active::before {
  opacity: 0;
  animation: none;
}

@keyframes chatbotToggleGlow {
  0%, 100% {
    box-shadow: 0 10px 25px rgba(76, 106, 247, 0.15);
  }
  50% {
    box-shadow: 0 12px 30px rgba(76, 106, 247, 0.35);
  }
}

/* .chatbot-toggle.is-tooltip-bouncing::after {
  animation: chatbotToggleGlow 2.5s ease-in-out infinite, chatbotTooltipBounce 1s ease-out 0s 5;
}
 */
/* Only hide tooltip if explicitly marked as hidden */
.chatbot-toggle.is-tooltip-hidden::after,
.chatbot-toggle.is-tooltip-hidden::before {
  opacity: 0 !important;
  animation: none !important;
  transform: translateY(50%);
  pointer-events: none;
  visibility: hidden !important;
}

/* Force tooltip to be visible initially - override hidden class */
.chatbot-toggle::after {
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

.chatbot-toggle::before {
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

/* Only hide if explicitly marked as hidden */
.chatbot-toggle.is-tooltip-hidden::after,
.chatbot-toggle.is-tooltip-hidden::before {
  opacity: 0 !important;
  visibility: hidden !important;
  display: none !important;
}

@keyframes chatbotTooltipBounce {
  0% {
    transform: translateY(50%) translateX(0);
  }
  30% {
    transform: translateY(40%) translateX(-4px);
  }
  55% {
    transform: translateY(50%) translateX(0);
  }
  70% {
    transform: translateY(44%) translateX(-2px);
  }
  100% {
    transform: translateY(50%) translateX(0);
  }
}

/* Hide tooltip only on very small mobile screens */
@media (max-width: 480px) {
  .chatbot-toggle::after,
  .chatbot-toggle::before {
    display: none;
  }
}

/* Chatbot Panel */
.chatbot-panel {
  position: fixed;
  bottom: 9rem;
  right: 2rem;
  width: 400px;
  height: 550px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  z-index: 1001;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.chatbot-panel.active {
  display: flex;
  animation: slideUp 0.3s ease-out;
}

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

/* Chatbot Header */
.chatbot-header {
  background: #4369EB;
  color: white;
  padding: 1rem 1.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chatbot-title {
  color: #FFF;
  font-family: "Pretendard Variable";
  font-size: 20px;
  font-style: normal;
  font-weight: 700;
  line-height: normal;
  letter-spacing: 0.7px;
}

.chatbot-subtitle {
  color: #fff;
  font-size: 0.75rem;
  opacity: 0.9;
  margin: 0;
}


/* Chat Messages Area */
.chatbot-messages {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chatbot-message-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.chatbot-message-wrapper.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chatbot-message-wrapper.assistant {
  align-self: flex-start;
}

.chatbot-message-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 500px;
  background: linear-gradient(180deg, #AFC7FF 0%, #2351A6 100%);
  box-shadow: 0 4px 15px 1px rgba(58, 58, 58, 0.25);
}

.chatbot-avatar-img {
  width: 60px;
  object-fit: cover;
  
}

.chatbot-message {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: keep-all;
  overflow-wrap: break-word;
  white-space: normal;
}

.chatbot-message.user {
  background: white;
  color: #374151;
  border-radius: 5px;
  border: 1px solid #B0B0B0;
  padding: 10px;
}

.chatbot-message.assistant {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

.chatbot-message.system {
  background: #f3f4f6;
  color: #6b7280;
  align-self: center;
  text-align: center;
  font-size: 0.75rem;
  font-style: italic;
}

/* Typing Indicator */
.chatbot-typing {
  display: none;
  align-self: flex-start;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  max-width: 80px;
}

.chatbot-typing.active {
  display: flex;
}

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

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

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

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

/* Input Area */
.chatbot-input-area {
  padding: 1rem;
  background: white;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.chatbot-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font-size: 0.875rem;
  resize: none;
  max-height: 100px;
  min-height: 44px;
  transition: border-color 0.3s ease;
  background: white;
  color: #374151 !important; /* Ensure text is visible */
}

.chatbot-send {
  background: linear-gradient(135deg, #4A6CF7, #8C5AEF);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  width: 44px;
  height: 44px;
}

.chatbot-send svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
}

.chatbot-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(74, 108, 247, 0.3);
}

.chatbot-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Welcome Message */
.chatbot-welcome {
  padding: 0;
  background: transparent;
  border-radius: 8px;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chatbot-welcome-header {
  display: flex;
  align-items: flex-start;
}

.chatbot-welcome-avatar {
  width: 50px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 500px;
  background: transparent;
  /* box-shadow: 0 4px 15px 1px rgba(58, 58, 58, 0.25); */
}

.chatbot-welcome-text {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  background: #F3F3F3;
  word-break: keep-all;
  overflow-wrap: break-word;
  white-space: normal;
}

.chatbot-welcome-greeting {
  margin: 0;
  color: #374151;
  font-size: 0.875rem;
  line-height: 1.5;
}

.chatbot-user-name {
  font-weight: 600;
}

.chatbot-welcome-intro {
  margin: 0;
  color: #374151;
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Quick Actions */
.chatbot-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chatbot-quick-btn {
  background: #FFF;
  border-radius: 20px;
  border: 1px solid #4369EB;
  padding: 0.5rem 0.7rem;
  color: #4369EB;
  font-family: "Pretendard Variable";
  font-size: 13px;
  font-style: normal;
  font-weight: 500;
  line-height: normal;
  letter-spacing: 0.49px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chatbot-quick-btn:hover {
  background: #4A6CF7;
  color: white;
  border-color: #4A6CF7;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(74, 108, 247, 0.2);
}

/* Error States */
.chatbot-error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.875rem;
  margin: 0.5rem 0;
}

/* Loading States */
.chatbot-loading {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  color: #6b7280;
  font-size: 0.875rem;
}

.chatbot-loading.active {
  display: flex;
}

.chatbot-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #4A6CF7;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 0.5rem;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
  .chatbot-panel {
    width: calc(100vw - 2rem);
    right: 1rem;
    left: 1rem;
    height: 70vh;
    bottom: 1rem;
  }
  
  .chatbot-toggle {
    bottom: 1rem;
    right: 1rem;
    width: 50px;
    height: 50px;
    font-size: 1.25rem;
  }
}

@media (max-width: 480px) {
  .chatbot-panel {
    width: calc(100vw - 1rem);
    right: 0.5rem;
    left: 0.5rem;
    height: 80vh;
  }
  
  .chatbot-message {
    max-width: 90%;
  }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */


/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ========================================
   ANIMATIONS
   ======================================== */

.chatbot-message {
  animation: messageSlide 0.3s ease-out;
}

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

/* Smooth scroll for messages */
.chatbot-messages {
  scroll-behavior: smooth;
}

/* ========================================
   DARK MODE SUPPORT (Future)
   ======================================== */

@media (prefers-color-scheme: dark) {
  .chatbot-panel {
    background: #1f2937;
    border-color: #374151;
  }
  
  .chatbot-messages {
    background: #111827;
  }
  
  .chatbot-message.assistant {
    background: #374151;
    color: #f9fafb;
    border-color: #4b5563;
  }
  
  .chatbot-input-area {
    background: #1f2937;
    border-color: #374151;
  }
  
  .chatbot-input {
    background: #374151;
    color: #f9fafb;
    border-color: #4b5563;
  }
  
  .chatbot-input:focus {
    border-color: #4A6CF7;
  }
}


#chatbot-toggle .chatbot-icon-img{
}