/* =========================================================
   El Faraana Chatbot — Clean Professional Stylesheet
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
  /* Light Mode Palette */
  --primary-color: #2563eb;
  --bg-color: #ffffff;
  --header-bg: #ffffff;
  --surface-color: #ffffff;

  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;

  --bot-bubble-bg: #f3f4f6;
  --bot-bubble-text: #1f2937;
  --user-bubble-bg: #2563eb;
  --user-bubble-text: #ffffff;

  --input-bg: #f9fafb;
  --input-text: #1f2937;
  --input-border: #e5e7eb;

  --chip-bg: #ffffff;
  --chip-text: #1f2937;
  --chip-border: #e5e7eb;
  --chip-hover-bg: #f3f4f6;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

  --font-family: 'Inter', sans-serif;
}

/* Dark Mode Palette Override */
@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #3b82f6;
    --bg-color: #111827;
    --header-bg: #1f2937;
    --surface-color: #111827;

    --text-primary: #ffffff;
    --text-secondary: #9ca3af;
    --border-color: #374151;

    --bot-bubble-bg: #374151;
    --bot-bubble-text: #ffffff;
    --user-bubble-bg: #2563eb;
    --user-bubble-text: #ffffff;

    --input-bg: #1f2937;
    --input-text: #ffffff;
    --input-border: #374151;

    --chip-bg: #1f2937;
    --chip-text: #ffffff;
    --chip-border: #374151;
    --chip-hover-bg: #374151;
  }
}

body {
  font-family: var(--font-family);
}

/* ====== Launcher ====== */
#chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--primary-color);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 9999;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#chat-launcher svg {
  width: 30px;
  height: 30px;
}

#chat-launcher:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.3);
}

#chat-launcher.opening {
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from {
    transform: scale(0);
  }

  to {
    transform: scale(1);
  }
}

/* ====== Panel ====== */
#chat-box {
  position: fixed;
  right: 24px;
  bottom: 100px;
  width: 380px;
  height: 650px;
  max-height: 80vh;
  background: var(--bg-color);
  border-radius: 20px;
  display: none;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 9999;
  font-family: var(--font-family);
  border: 1px solid var(--border-color);
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ====== Header ====== */
#chat-header {
  background: var(--header-bg);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.header-avatar {
  width: 40px;
  height: 40px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.header-meta {
  flex: 1;
}

.header-title {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 2px;
}

.header-sub {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
}

.header-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 20px;
}

.header-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

/* ====== Body ====== */
#chat-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--surface-color);
  scroll-behavior: smooth;
}

/* Custom Scrollbar */
#chat-body::-webkit-scrollbar {
  width: 6px;
}

#chat-body::-webkit-scrollbar-track {
  background: transparent;
}

#chat-body::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 10px;
}

.msg-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  opacity: 0;
  animation: fadeIn 0.3s forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

.msg-row.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.avatar.bot {
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary-color);
}

.avatar.user {
  display: none;
}

.bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
}

.msg-row.bot .bubble {
  background: var(--bot-bubble-bg);
  color: var(--bot-bubble-text);
  border-top-left-radius: 4px;
}

.msg-row.user .bubble {
  background: var(--user-bubble-bg);
  color: var(--user-bubble-text);
  border-top-right-radius: 4px;
}

/* Markdown Styles */
.bubble p {
  margin-bottom: 8px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble strong {
  font-weight: 600;
}

.bubble ul,
.bubble ol {
  margin-left: 20px;
  margin-bottom: 8px;
}

.bubble code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
}

.msg-row.user .bubble code {
  background: rgba(255, 255, 255, 0.2);
}

/* Quick Replies */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.quick-replies button {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.quick-replies button:hover {
  background: var(--chip-hover-bg);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* Typing Indicator */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 12px 16px !important;
  align-items: center;
  min-width: 48px;
  justify-content: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: #9ca3af;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

/* ====== Input ====== */
#chat-input {
  padding: 16px 20px;
  background: var(--header-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
  align-items: center;
}

#chat-text {
  flex: 1;
  padding: 12px 16px;
  border-radius: 24px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--input-text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  resize: none;
  max-height: 100px;
  transition: border-color 0.2s;
}

#chat-text:focus {
  border-color: var(--primary-color);
  background: var(--bg-color);
}

#chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--primary-color);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  flex-shrink: 0;
}

#chat-send:hover {
  transform: scale(1.05);
}

#chat-send:active {
  transform: scale(0.95);
}

#chat-send:disabled {
  background: #e5e7eb;
  cursor: not-allowed;
}

/* ====== Mobile ====== */
@media (max-width: 480px) {
  #chat-box {
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  #chat-launcher {
    bottom: 20px;
    right: 20px;
  }
}

/* Explicit Dark Mode Overrides */
@media (prefers-color-scheme: dark) {

  .bubble,
  .bubble p,
  .bubble li,
  .bubble strong,
  .bubble span {
    color: #ffffff !important;
  }

  .quick-replies button {
    background: #1f2937 !important;
    color: #ffffff !important;
    border-color: #374151 !important;
  }

  #chat-text {
    color: #ffffff !important;
    background: #1f2937 !important;
  }
}