/* =============================================================================
   Ask Muslim — Floating Chatbot Widget for Quranic Insights Dashboard
   ============================================================================= */

/* ── Bubble Button ────────────────────────────────────────────────────────── */
#ask-muslim-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #0d5c3a;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(13, 92, 58, 0.35);
  transition: all 0.3s ease;
  outline: none;
  ring: 2px solid rgba(13, 92, 58, 0.3);
}

#ask-muslim-bubble:hover {
  background: #0a4e31;
  box-shadow: 0 6px 24px rgba(13, 92, 58, 0.45);
  transform: scale(1.05);
  ring: 2px solid rgba(201, 168, 76, 0.6);
}

#ask-muslim-bubble svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: transform 0.3s;
}

#ask-muslim-bubble:hover svg {
  transform: scale(1.1);
}

#ask-muslim-bubble.hidden {
  transform: scale(0);
  opacity: 0;
  pointer-events: none;
}

/* Pulse animation */
#ask-muslim-bubble::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(13, 92, 58, 0.3);
  animation: am-pulse 2s ease-out 3;
}

@keyframes am-pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.8); opacity: 0; }
}

/* ── Chat Panel ───────────────────────────────────────────────────────────── */
#ask-muslim-panel {
  position: fixed;
  z-index: 10000;
  background: #fff;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#ask-muslim-panel.open {
  display: flex;
  animation: am-slide-up 0.2s ease-out;
}

@keyframes am-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Desktop */
@media (min-width: 992px) {
  #ask-muslim-panel {
    bottom: 96px;
    right: 24px;
    width: 400px;
    height: 560px;
    border-radius: 16px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  }
}

/* Mobile */
@media (max-width: 991px) {
  #ask-muslim-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
}

/* ── Gold accent bar ──────────────────────────────────────────────────────── */
.am-accent-bar {
  height: 2px;
  background: linear-gradient(to right, #c9a84c, #e8d48b, #c9a84c);
  flex-shrink: 0;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.am-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid #f3f4f6;
  flex-shrink: 0;
}

.am-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.am-header-title {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}

.am-mode-badge {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
}

.am-mode-badge.private { background: #ecfdf5; color: #047857; }
.am-mode-badge.public { background: #fffbeb; color: #b45309; }
.am-mode-badge.ephemeral { background: #f3f4f6; color: #6b7280; }

.am-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.am-header-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  color: #9ca3af;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  font-size: 14px;
}

.am-header-btn:hover {
  background: #f3f4f6;
  color: #4b5563;
}

.am-header-btn.close-btn:hover {
  background: #fef2f2;
  color: #ef4444;
}

.am-header-btn.active {
  background: #ecfdf5;
  color: #059669;
}

/* ── Mode Selector ────────────────────────────────────────────────────────── */
.am-mode-selector {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.am-mode-selector h3 {
  font-size: 16px;
  font-weight: 600;
  color: #111827;
  margin: 4px 0;
}

.am-mode-selector p {
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 20px;
}

.am-mode-card {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  margin-bottom: 10px;
}

.am-mode-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}

.am-mode-card.private { border-color: #d1fae5; background: #f0fdf4; }
.am-mode-card.private:hover { border-color: #6ee7b7; }
.am-mode-card.public { border-color: #fef3c7; background: #fffbeb; }
.am-mode-card.public:hover { border-color: #fcd34d; }
.am-mode-card.ephemeral { border-color: #e5e7eb; background: #f9fafb; }
.am-mode-card.ephemeral:hover { border-color: #9ca3af; }

.am-mode-icon {
  flex-shrink: 0;
  margin-top: 2px;
  font-size: 18px;
}

.am-mode-card.private .am-mode-icon { color: #047857; }
.am-mode-card.public .am-mode-icon { color: #b45309; }
.am-mode-card.ephemeral .am-mode-icon { color: #6b7280; }

.am-mode-title {
  font-size: 14px;
  font-weight: 500;
  color: #111827;
}

.am-mode-desc {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
}

.am-disclaimer {
  margin-top: 14px;
  font-size: 10px;
  color: #9ca3af;
  text-align: center;
  line-height: 1.4;
}

/* ── Messages Area ────────────────────────────────────────────────────────── */
.am-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.am-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 24px;
}

.am-empty-icon { font-size: 40px; margin-bottom: 8px; }
.am-empty-title { font-size: 14px; font-weight: 500; color: #374151; }
.am-empty-sub { font-size: 12px; color: #9ca3af; margin-top: 4px; }

/* Message bubbles */
.am-msg {
  display: flex;
  margin-bottom: 12px;
}

.am-msg.user { justify-content: flex-end; }
.am-msg.bot { justify-content: flex-start; }

.am-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #0d5c3a;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
  margin-right: 8px;
  margin-top: 4px;
}

.am-bubble {
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.6;
  word-wrap: break-word;
}

.am-msg.user .am-bubble {
  background: #0d5c3a;
  color: white;
  border-radius: 16px 16px 4px 16px;
}

.am-msg.bot .am-bubble {
  background: #fff;
  color: #1f2937;
  border-radius: 16px 16px 16px 4px;
  border: 1px solid #f3f4f6;
  border-left: 2px solid #c9a84c;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* ── Bubble wrapper (holds bubble + action bar) ──────────────────────────── */
.am-bubble-wrap {
  max-width: 85%;
  position: relative;
}

/* ── Message action bar ──────────────────────────────────────────────────── */
.am-actions {
  display: flex;
  gap: 2px;
  padding-top: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.am-msg.user .am-actions { justify-content: flex-end; }
.am-msg.bot .am-actions { justify-content: flex-start; padding-left: 2px; }

.am-msg:hover .am-actions {
  opacity: 1;
  pointer-events: auto;
}

.am-action-btn {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 6px;
  color: #9ca3af;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.am-action-btn:hover {
  background: #f0fdf4;
  color: #0d5c3a;
  border-color: #d1fae5;
}

.am-msg.user .am-action-btn:hover {
  background: rgba(13, 92, 58, 0.08);
  color: #0d5c3a;
  border-color: rgba(13, 92, 58, 0.15);
}

/* "Copied!" toast */
.am-copied-toast {
  position: absolute;
  bottom: -4px;
  left: 0;
  background: #0d5c3a;
  color: #fff;
  font-size: 10px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
  animation: am-toast-in 0.15s ease-out, am-toast-out 0.3s ease-in 1.0s forwards;
  pointer-events: none;
  z-index: 10;
}

@keyframes am-toast-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes am-toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Mobile: always show action buttons (no hover on touch) */
@media (max-width: 991px) {
  .am-actions {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Verse reference chips */
.am-verse-ref {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: rgba(13, 92, 58, 0.1);
  color: #047857;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s;
}

.am-verse-ref:hover {
  background: rgba(13, 92, 58, 0.2);
  text-decoration: none;
  color: #047857;
}

/* Arabic text */
.am-arabic {
  direction: rtl;
  font-family: 'Amiri Quran', 'Scheherazade New', serif;
  font-size: 16px;
  line-height: 2;
}

/* Typing indicator */
.am-typing {
  display: flex;
  align-items: center;
  gap: 6px;
}

.am-typing-text {
  font-size: 12px;
  color: #9ca3af;
}

.am-typing-dots {
  display: flex;
  gap: 3px;
}

.am-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(13, 92, 58, 0.4);
  animation: am-bounce 0.6s ease-in-out infinite alternate;
}

.am-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.am-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes am-bounce {
  to { transform: translateY(-4px); }
}

/* ── Input Area ───────────────────────────────────────────────────────────── */
.am-input-area {
  flex-shrink: 0;
  border-top: 1px solid #f3f4f6;
  padding: 10px 12px;
}

.am-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.am-textarea {
  flex: 1;
  resize: none;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  background: #f9fafb;
  transition: border-color 0.2s;
  max-height: 96px;
  min-height: 36px;
}

.am-textarea:focus {
  border-color: #0d5c3a;
  box-shadow: 0 0 0 2px rgba(13, 92, 58, 0.15);
}

.am-textarea:disabled {
  opacity: 0.5;
}

.am-textarea::placeholder {
  color: #9ca3af;
}

.am-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.am-send-btn.active {
  background: #0d5c3a;
  color: white;
  box-shadow: 0 2px 4px rgba(13, 92, 58, 0.3);
}

.am-send-btn.active:hover {
  background: #0a4e31;
}

.am-send-btn.inactive {
  background: #f3f4f6;
  color: #d1d5db;
  cursor: default;
}

.am-input-hint {
  display: flex;
  justify-content: space-between;
  padding: 4px 4px 0;
}

.am-input-hint span {
  font-size: 10px;
  color: #d1d5db;
}

.am-char-count { color: #f59e0b !important; }

/* ── History Sidebar ──────────────────────────────────────────────────────── */
.am-history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.am-history-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid #f3f4f6;
}

.am-history-header button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  color: #9ca3af;
  font-size: 14px;
}

.am-history-header button:hover { color: #4b5563; }

.am-history-header span {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.am-history-list {
  flex: 1;
  overflow-y: auto;
}

.am-history-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid #fafafa;
  cursor: pointer;
  transition: background 0.2s;
}

.am-history-item:hover { background: #f9fafb; }

.am-history-item-body { flex: 1; min-width: 0; }

.am-history-title {
  font-size: 13px;
  font-weight: 500;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.am-history-preview {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.am-history-meta {
  font-size: 10px;
  color: #d1d5db;
  margin-top: 4px;
}

.am-history-del {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #d1d5db;
  opacity: 0;
  transition: all 0.2s;
  font-size: 12px;
}

.am-history-item:hover .am-history-del { opacity: 1; }
.am-history-del:hover { color: #ef4444; }

.am-history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: #9ca3af;
  text-align: center;
}

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.am-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: am-spin 0.6s linear infinite;
}

@keyframes am-spin {
  to { transform: rotate(360deg); }
}

/* ── Dark mode (auto-detect from Dash theme toggle) ───────────────────────── */
@media (prefers-color-scheme: dark) {
  #ask-muslim-panel {
    background: #111827;
    border-color: #374151;
  }
  .am-header { border-color: #1f2937; }
  .am-header-title { color: #f3f4f6; }
  .am-mode-selector h3 { color: #f3f4f6; }
  .am-msg.bot .am-bubble { background: #1f2937; color: #e5e7eb; border-color: #374151; }
  .am-textarea { background: #1f2937; border-color: #374151; color: #f3f4f6; }
  .am-input-area { border-color: #1f2937; }
  .am-empty-title { color: #e5e7eb; }
  .am-history-title { color: #e5e7eb; }
  .am-history-item:hover { background: #1f2937; }
  .am-history-header { border-color: #1f2937; }
  .am-action-btn { color: #6b7280; }
  .am-action-btn:hover { background: #1f2937; color: #c9a84c; border-color: #374151; }
  .am-msg.user .am-action-btn:hover { background: #1f2937; color: #c9a84c; border-color: #374151; }
  .am-copied-toast { background: #c9a84c; color: #111827; }
}
