/* ============================================
   FictionX Chatbot - Glassmorphism Design
   Dark/Light mode via Metronic CSS vars
   ============================================ */

/* ---------- Toggler Button ---------- */
#chatbot-toggler {
  position: fixed;
  bottom: 28px;
  right: 28px;
  border: none;
  height: 56px;
  width: 56px;
  display: flex;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #0D7A8D 0%, #09B1A0 100%);
  box-shadow: 0 6px 24px rgba(13, 122, 141, 0.35);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 9999999999;
}
#chatbot-toggler:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 32px rgba(13, 122, 141, 0.5);
}
.chatbot-container.show-chatbot #chatbot-toggler {
  transform: rotate(90deg);
}
#chatbot-toggler span {
  color: #fff;
  position: absolute;
  font-size: 1.3rem;
}
#chatbot-toggler span:last-child,
.chatbot-container.show-chatbot #chatbot-toggler span:first-child {
  opacity: 0;
}
.chatbot-container.show-chatbot #chatbot-toggler span:last-child {
  opacity: 1;
}

/* ---------- Popup Container (Glass) ---------- */
.chatbot-popup {
  position: fixed;
  right: 28px;
  bottom: 92px;
  width: 380px;
  max-width: calc(100% - 50px);
  overflow: hidden;
  border-radius: 20px;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.2);
  transform-origin: bottom right;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 99999999999;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.12),
    0 8px 32px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.chatbot-container.show-chatbot .chatbot-popup {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

/* Maximized */
@media (min-width: 481px) {
  .chatbot-container.maximized .chatbot-popup {
    width: 75%;
    height: 80%;
    max-width: 900px;
  }
  .chatbot-container.maximized .chat-body {
    height: calc(80vh - 150px);
  }
}

/* ---------- Header ---------- */
.chat-header {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  background: linear-gradient(135deg, #041317e3 0%, #0D7A8DEB 100%);
  justify-content: space-between;
}
.chat-header .header-info {
  display: flex;
  gap: 12px;
  align-items: center;
}
.fx-chat-avatar {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}
.header-info .logo-text {
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  margin: 0;
  line-height: 1.2;
}
.fx-chat-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 500;
}
.fx-chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34D399;
  display: inline-block;
  animation: dotBlink 2s infinite;
}

.header-controls {
  display: flex;
  gap: 2px;
  align-items: center;
}
.header-control-btn {
  border: none;
  color: rgba(255, 255, 255, 0.8);
  height: 32px;
  width: 32px;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 8px;
  background: transparent;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-control-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

/* ---------- Chat Body ---------- */
.chat-body {
  padding: 20px 16px;
  gap: 14px;
  display: flex;
  height: 400px;
  overflow-y: auto;
  margin-bottom: 72px;
  flex-direction: column;
  background: transparent;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.1) transparent;
}
.chat-body .message {
  display: flex;
  gap: 8px;
  position: relative;
}
.chat-body .message .message-text {
  padding: 12px 16px;
  max-width: 82%;
  font-size: 0.875rem;
  line-height: 1.55;
}

/* Bot message */
.chat-body .bot-message .message-text {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 16px 16px 16px 4px;
  color: #1a1a2e;
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.chat-body .bot-message.thinking .message-text {
  padding: 4px 16px;
}

/* User message */
.chat-body .user-message {
  flex-direction: column;
  align-items: flex-end;
}
.chat-body .user-message .message-text {
  color: #fff;
  background: linear-gradient(135deg, #0D7A8D 0%, #09A396 100%);
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 2px 12px rgba(13, 122, 141, 0.25);
}

/* Thinking dots */
.chat-body .bot-message .thinking-indicator {
  display: flex;
  gap: 5px;
  padding-block: 14px;
}
.chat-body .bot-message .thinking-indicator .dot {
  height: 8px;
  width: 8px;
  opacity: 0.7;
  border-radius: 50%;
  background: #0D7A8D;
  animation: dotPulse 1.8s ease-in-out infinite;
}
.chat-body .bot-message .thinking-indicator .dot:nth-child(1) { animation-delay: 0.2s; }
.chat-body .bot-message .thinking-indicator .dot:nth-child(2) { animation-delay: 0.35s; }
.chat-body .bot-message .thinking-indicator .dot:nth-child(3) { animation-delay: 0.5s; }

/* ---------- Message Container & Sources ---------- */
.message-container {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.message-content {
  display: flex;
  gap: 8px;
}
.message-sources-section {
  margin-top: 4px;
  padding-top: 6px;
  width: 100%;
}
.sources-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.source-item {
  border-radius: 8px;
  transition: all 0.2s ease;
  padding: 3px 0;
}
.source-item:hover {
  background: rgba(13, 122, 141, 0.06);
}
.source-content {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
  border-radius: 6px;
}
.source-link-icon {
  width: 14px;
  height: 14px;
  color: #0D7A8D;
  flex-shrink: 0;
  opacity: 0.6;
}
.source-link {
  color: #0D7A8D;
  text-decoration: none;
  font-size: 0.8rem;
  line-height: 1.4;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.2s ease;
}
.source-link:hover {
  color: #065A6A;
  text-decoration: underline;
}

/* ---------- Footer ---------- */
.chat-footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 12px 16px 16px;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.3);
}
.chat-form {
  display: flex;
  align-items: center;
  position: relative;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 32px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  transition: all 0.2s ease;
}
.chat-form:focus-within {
  border-color: #0D7A8D;
  box-shadow: 0 0 0 3px rgba(13, 122, 141, 0.12);
}
.chat-form .message-input {
  width: 100%;
  height: 46px;
  outline: none;
  resize: none;
  border: none;
  max-height: 160px;
  scrollbar-width: thin;
  border-radius: inherit;
  font-size: 0.95rem;
  padding: 13px 0 11px 18px;
  scrollbar-color: transparent transparent;
  background: transparent;
  color: #1a1a2e;
}
.chat-form .message-input::placeholder {
  color: rgba(0, 0, 0, 0.35);
}
.chat-form .chat-controls {
  gap: 3px;
  height: 46px;
  display: flex;
  padding-right: 6px;
  align-items: center;
  align-self: flex-end;
}
.chat-form .chat-controls button {
  height: 34px;
  width: 34px;
  border: none;
  cursor: pointer;
  color: #fff;
  border-radius: 50%;
  font-size: 1.1rem;
  background: linear-gradient(135deg, #0D7A8D, #09A396);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(13, 122, 141, 0.3);
}
.chat-form .chat-controls button:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(13, 122, 141, 0.4);
}

/* ---------- RTL support ---------- */
.rtl {
  direction: rtl;
  text-align: right;
}

/* ---------- Markdown content styles ---------- */
.chat-body .message-text h1,
.chat-body .message-text h2,
.chat-body .message-text h3 {
  margin: 8px 0 4px;
  font-weight: 700;
}
.chat-body .message-text h1 { font-size: 1.1rem; }
.chat-body .message-text h2 { font-size: 1rem; }
.chat-body .message-text h3 { font-size: 0.95rem; }
.chat-body .message-text p { margin: 4px 0; }
.chat-body .message-text pre {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
  font-size: 0.8rem;
}
.chat-body .message-text code {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.82rem;
}
.chat-body .message-text a {
  color: #0D7A8D;
  text-decoration: underline;
}
.dash-item {
  display: flex;
  gap: 6px;
  margin: 2px 0;
}
.dash { flex-shrink: 0; font-weight: 600; }

/* ============================================
   DARK MODE
   ============================================ */
[data-bs-theme="dark"] .chatbot-popup {
  background: rgba(22, 27, 34, 0.78);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.4),
    0 8px 32px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
[data-bs-theme="dark"] .chat-body {
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
[data-bs-theme="dark"] .chat-body .bot-message .message-text {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
}
[data-bs-theme="dark"] .chat-body .message-text pre {
  background: rgba(255, 255, 255, 0.08);
}
[data-bs-theme="dark"] .chat-body .message-text code {
  background: rgba(255, 255, 255, 0.1);
}
[data-bs-theme="dark"] .chat-footer {
  background: rgba(22, 27, 34, 0.6);
  border-top-color: rgba(255, 255, 255, 0.06);
}
[data-bs-theme="dark"] .chat-form {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.1);
}
[data-bs-theme="dark"] .chat-form:focus-within {
  border-color: #0D7A8D;
  box-shadow: 0 0 0 3px rgba(13, 122, 141, 0.2);
}
[data-bs-theme="dark"] .chat-form .message-input {
  color: #e2e8f0;
}
[data-bs-theme="dark"] .chat-form .message-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}
[data-bs-theme="dark"] .source-item:hover {
  background: rgba(255, 255, 255, 0.05);
}
[data-bs-theme="dark"] .source-link {
  color: #34D399;
}
[data-bs-theme="dark"] .source-link:hover {
  color: #6EE7B7;
}
[data-bs-theme="dark"] .chat-body .message-text a {
  color: #34D399;
}
[data-bs-theme="dark"] #chatbot-toggler {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

/* ---------- Animations ---------- */
@keyframes dotPulse {
  0%, 44% { transform: translateY(0); }
  28% { opacity: 0.4; transform: translateY(-5px); }
  44% { opacity: 0.2; }
}
@keyframes dotBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------- Mobile responsive ---------- */
@media (max-width: 480px) {
  .chatbot-popup {
    width: calc(100% - 16px) !important;
    right: 8px;
    bottom: 80px;
    border-radius: 16px;
    max-width: 100%;
  }
  .chat-body {
    height: 350px;
  }
  #chatbot-toggler {
    bottom: 16px;
    right: 16px;
    height: 50px;
    width: 50px;
  }
}
@media (max-width: 768px) {
  .chatbot-popup {
    width: calc(100% - 32px);
  }
}
