/* Reunify AI Chat — widget styles.
   Scoped to #chatBubble, #chatPanel, and their children only — nothing here
   touches the page that embeds it. Bootstrap 5 CSS is expected to already
   be loaded on the host page (or load it yourself); these rules only cover
   what's specific to the widget. */

/* ---------- Floating chat bubble ---------- */
#chatBubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: #0d6efd;
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.15s ease;
}
#chatBubble:hover {
  transform: scale(1.06);
}
#chatBubble.hidden {
  display: none;
}

/* ---------- Chat panel ---------- */
#chatPanel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 48px);
  background-color: #fff;
  border-radius: 1rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1001;
  transform-origin: bottom right;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
#chatPanel.collapsed {
  transform: scale(0.85);
  opacity: 0;
  pointer-events: none;
}
@media (max-width: 480px) {
  #chatPanel {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
}

.chat-panel-header {
  flex-wrap: wrap;
  row-gap: 0.5rem;
  flex-shrink: 0;
  background-color: #f8f9fa;
  border-bottom: 1px solid #dee2e6;
  padding: 0.85rem 1.35rem; /* deliberately more than the panel's 1rem border-radius, so the close button clears the rounded corner instead of getting visually clipped by it */
  padding-right: 2.75rem; /* leaves room for the corner-positioned close button so it never overlaps the title or controls */
}

#closeChatBtn {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: #6c757d;
  font-size: 1.3rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  z-index: 1002; /* above the header content it sits over */
  display: flex;
  align-items: center;
  justify-content: center;
}
#closeChatBtn:hover {
  background-color: rgba(0,0,0,0.08);
}
#chatWindow {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.1rem 1.35rem;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: #c1c1c1 transparent; /* Firefox */
}
#chatWindow::-webkit-scrollbar {
  width: 8px;
}
#chatWindow::-webkit-scrollbar-track {
  background: transparent;
}
#chatWindow::-webkit-scrollbar-thumb {
  background-color: #c1c1c1;
  border-radius: 4px;
}
.chat-panel-footer {
  flex-shrink: 0;
  padding: 0.85rem 1.35rem;
}

/* ---------- Message bubbles ---------- */
.chat-bubble {
  display: inline-block;
  max-width: 85%;
  padding: 0.5rem 0.85rem;
  border-radius: 0.75rem;
  white-space: pre-wrap;   /* preserves line breaks + wraps long lines */
  word-wrap: break-word;
  text-align: left;
}
.chat-bubble.user {
  background-color: #0d6efd;
  color: #fff;
}
.chat-bubble.ai {
  background-color: #f1f1f1;
  color: #212529;
}
.chat-bubble a {
  color: inherit;
  text-decoration: underline;
  font-weight: 600;
}
.chat-bubble code {
  background-color: rgba(0,0,0,0.08);
  padding: 0.1rem 0.3rem;
  border-radius: 0.25rem;
  font-size: 0.9em;
}
.chat-bubble-error {
  background-color: #f8d7da;
  color: #58151c;
}

.msg-timestamp {
  font-size: 0.7rem;
  color: #9a9a9a;
  margin-top: 0.15rem;
}
.error-toggle {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 0.8rem;
  color: #58151c;
  text-decoration: underline;
}
.error-details {
  margin: 0.5rem 0 0;
  padding: 0.5rem;
  background-color: rgba(0,0,0,0.06);
  border-radius: 0.4rem;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 200px;
  overflow-y: auto;
}

/* ---------- Typing indicator — shown while a request is genuinely in flight ---------- */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.65rem 0.9rem;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #9a9a9a;
  animation: typingBounce 1.3s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.28s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.14s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

@media (max-width: 400px) {
  .chat-panel-header span {
    font-size: 0.95rem;
  }
  #providerSelect {
    font-size: 0.8rem;
  }
}
