/* ================================================================
   Nour AI DocuBot — Chatbot Widget
   Fully bidirectional: RTL + LTR via [dir] attribute on wrapper.
   ================================================================ */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&family=Inter:wght@400;600;700&display=swap');

.nadb-chatbot-section {
  --nadb-color: #0a5c38;
  font-family: 'Cairo', 'Inter', -apple-system, sans-serif;
  background: #fff;
  border: 2px solid var(--nadb-color);
  border-radius: 20px;
  overflow: hidden;
  max-width: 920px;
  margin: 0 auto;
  box-shadow: 0 12px 48px rgba(0,0,0,0.12);
}

/* ── Header ──────────────────────────────────────────────────── */
.nadb-chat-head {
  background: linear-gradient(135deg, var(--nadb-color) 0%, color-mix(in srgb, var(--nadb-color) 70%, #000) 100%);
  padding: 1rem 1.35rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  color: #fff;
  user-select: none;
}
[dir="rtl"] .nadb-chat-head { flex-direction: row; }
[dir="ltr"] .nadb-chat-head { flex-direction: row; }

.nadb-chat-avatar { width: 54px; height: 54px; flex-shrink: 0; }
.nadb-candle-svg { width: 100%; height: 100%; }
.nadb-flame { animation: nadb-flicker 2.2s ease-in-out infinite alternate; transform-origin: center bottom; }
@keyframes nadb-flicker {
  0%   { transform: scaleX(1)    scaleY(1);    }
  33%  { transform: scaleX(0.88) scaleY(1.06); }
  66%  { transform: scaleX(1.06) scaleY(0.96); }
  100% { transform: scaleX(0.93) scaleY(1.03); }
}

.nadb-chat-head-info { flex: 1; min-width: 0; }
.nadb-chat-name      { margin: 0; font-size: 1.05rem; font-weight: 800; color: #fff; line-height: 1.2; }
.nadb-chat-status    { margin: 0.15rem 0 0; font-size: 0.79rem; color: rgba(255,255,255,0.78); display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.nadb-status-dot     { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; animation: nadb-pulse 2s infinite; flex-shrink: 0; }
@keyframes nadb-pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
.nadb-ai-label { background: rgba(255,255,255,0.18); padding: 0.1rem 0.5rem; border-radius: 10px; font-size: 0.74rem; font-weight: 700; }
.nadb-doc-only-label { background: rgba(74,222,128,0.25); color: #d1fae5; padding: 0.1rem 0.5rem; border-radius: 10px; font-size: 0.72rem; font-weight: 700; }

.nadb-toggle-btn {
  background: rgba(255,255,255,0.14);
  border: none; color: #fff;
  width: 38px; height: 38px;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.22s ease;
  flex-shrink: 0;
}
.nadb-toggle-btn:hover { background: rgba(255,255,255,0.26); }
.nadb-toggle-btn svg { width: 18px; height: 18px; transition: transform 0.3s ease; }
.nadb-toggle-btn.nadb-collapsed svg { transform: rotate(180deg); }

/* ── Body ────────────────────────────────────────────────────── */
.nadb-chat-body {
  display: flex;
  height: 500px;
}
[dir="rtl"] .nadb-chat-body { flex-direction: row; }
[dir="ltr"] .nadb-chat-body { flex-direction: row-reverse; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.nadb-chat-sidebar {
  width: 185px;
  flex-shrink: 0;
  background: #f9fafb;
  padding: 1rem 0.85rem;
  overflow-y: auto;
}
[dir="rtl"] .nadb-chat-sidebar { border-left: 1px solid #d1e5da; }
[dir="ltr"] .nadb-chat-sidebar { border-right: 1px solid #d1e5da; }

.nadb-sidebar-title {
  font-size: 0.72rem; font-weight: 700;
  color: #6b7280; margin: 0 0 0.85rem;
  text-transform: uppercase; letter-spacing: 0.6px;
}
.nadb-suggestions { display: flex; flex-direction: column; gap: 0.45rem; }
.nadb-suggest-btn {
  width: 100%; background: #fff;
  border: 1.5px solid #d1e5da; border-radius: 8px;
  padding: 0.55rem 0.7rem; font-family: inherit; font-size: 0.81rem;
  color: #374151; cursor: pointer; transition: all 0.2s ease;
  line-height: 1.45;
}
[dir="rtl"] .nadb-suggest-btn { text-align: right; }
[dir="ltr"] .nadb-suggest-btn { text-align: left; }
.nadb-suggest-btn:hover { border-color: var(--nadb-color); background: #e6f2ec; color: var(--nadb-color); }

/* ── Feed ────────────────────────────────────────────────────── */
.nadb-chat-feed-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.nadb-chat-feed {
  flex: 1; overflow-y: auto;
  padding: 1.25rem; display: flex;
  flex-direction: column; gap: 0.9rem;
  scroll-behavior: smooth;
}

/* Messages */
.nadb-msg {
  max-width: 88%;
  padding: 0.88rem 1.1rem;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.7;
  animation: nadb-msg-in 0.28s ease;
  word-wrap: break-word;
}
@keyframes nadb-msg-in { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

.nadb-msg-bot {
  background: #e6f2ec;
  color: #111827;
  align-self: flex-start;
}
[dir="rtl"] .nadb-msg-bot { border-bottom-right-radius: 4px; }
[dir="ltr"] .nadb-msg-bot { border-bottom-left-radius: 4px; }

.nadb-msg-user {
  background: var(--nadb-color);
  color: #fff;
  align-self: flex-end;
}
[dir="rtl"] .nadb-msg-user { border-bottom-left-radius: 4px; }
[dir="ltr"] .nadb-msg-user { border-bottom-right-radius: 4px; }

/* Thinking indicator */
.nadb-msg-thinking {
  display: flex; gap: 5px; align-items: center;
  padding: 0.8rem 1.1rem; background: #e6f2ec;
  border-radius: 16px; align-self: flex-start;
}
[dir="rtl"] .nadb-msg-thinking { border-bottom-right-radius: 4px; }
[dir="ltr"] .nadb-msg-thinking { border-bottom-left-radius: 4px; }
.nadb-msg-thinking span { width: 8px; height: 8px; border-radius: 50%; background: #0a5c38; animation: nadb-bounce 1s infinite; }
.nadb-msg-thinking span:nth-child(2) { animation-delay: 0.15s; }
.nadb-msg-thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes nadb-bounce { 0%,80%,100%{transform:scale(0.6);opacity:0.4} 40%{transform:scale(1);opacity:1} }

/* AI badge in response */
.nadb-ai-badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: rgba(10,92,56,0.1); color: #0a5c38;
  border-radius: 20px; padding: 0.18rem 0.7rem;
  font-size: 0.76rem; font-weight: 700;
  margin-bottom: 0.75rem;
}
.nadb-ai-badge svg { width: 13px; height: 13px; }
.nadb-ai-content { }
.nadb-ai-content p { margin: 0 0 0.6rem; }
.nadb-ai-content p:last-child { margin-bottom: 0; }

/* Not found message */
.nadb-not-found { text-align: center; padding: 0.5rem 0; }
.nadb-not-found-icon { font-size: 1.75rem; display: block; margin-bottom: 0.5rem; }
.nadb-not-found p { margin: 0.25rem 0; font-size: 0.92rem; color: #374151; }
.nadb-not-found-hint { color: #6b7280 !important; font-size: 0.82rem !important; }

/* Sources accordion */
.nadb-sources-details { margin-top: 0.9rem; border: 1px solid #d1e5da; border-radius: 10px; overflow: hidden; }
.nadb-sources-toggle { padding: 0.6rem 0.9rem; cursor: pointer; font-size: 0.83rem; font-weight: 700; color: #0a5c38; background: #e6f2ec; list-style: none; user-select: none; }
.nadb-sources-toggle:hover { background: #d1e5da; }
.nadb-sources-body { padding: 0.8rem; }
.nadb-source-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0; border-bottom: 1px dashed #e5e7eb; font-size: 0.83rem; }
[dir="rtl"] .nadb-source-item { flex-direction: row; }
[dir="ltr"] .nadb-source-item { flex-direction: row; }
.nadb-source-item:last-child { border-bottom: none; }
.nadb-source-title { font-weight: 600; color: #111827; flex: 1; }
.nadb-source-link  { color: #0a5c38; font-size: 0.78rem; text-decoration: none; }
.nadb-source-link:hover { text-decoration: underline; }

/* Doc results (non-AI) */
.nadb-doc-results .nadb-results-intro { color: #6b7280; font-size: 0.86rem; margin-bottom: 0.75rem; }
.nadb-corpus-result h4 { color: #0a5c38; font-size: 0.95rem; margin: 0 0 0.5rem; }
.nadb-corpus-result ul { margin: 0.5rem 0 0.5rem 1.25rem; }
.nadb-corpus-result li { margin-bottom: 0.35rem; font-size: 0.86rem; }
.nadb-fallback { color: #6b7280; font-size: 0.9rem; }

/* ── Input ───────────────────────────────────────────────────── */
.nadb-chat-input-wrap {
  display: flex; gap: 0.5rem;
  padding: 0.9rem 1.1rem;
  border-top: 1px solid #d1e5da;
  background: #fff; align-items: center;
}
[dir="rtl"] .nadb-chat-input-wrap { flex-direction: row; }
[dir="ltr"] .nadb-chat-input-wrap { flex-direction: row; }

.nadb-chat-input {
  flex: 1; border: 1.5px solid #d1e5da; border-radius: 50px;
  padding: 0.58rem 1rem; font-family: inherit; font-size: 0.94rem;
  outline: none; color: #111827; background: #f9fafb;
  transition: all 0.22s ease;
}
[dir="rtl"] .nadb-chat-input { direction: rtl; text-align: right; }
[dir="ltr"] .nadb-chat-input { direction: ltr; text-align: left; }
.nadb-chat-input:focus { border-color: var(--nadb-color); background: #fff; box-shadow: 0 0 0 3px rgba(10,92,56,0.09); }
.nadb-chat-input::placeholder { color: #9ca3af; }

.nadb-chat-send {
  width: 44px; height: 44px;
  background: var(--nadb-color); color: #fff;
  border: none; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.22s ease;
}
.nadb-chat-send:hover { background: color-mix(in srgb, var(--nadb-color) 78%, #000); transform: scale(1.08); box-shadow: 0 4px 12px rgba(10,92,56,0.28); }
.nadb-chat-send svg { width: 17px; height: 17px; }
[dir="rtl"] .nadb-chat-send svg { transform: rotate(180deg); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 680px) {
  .nadb-chat-sidebar { display: none; }
  .nadb-chat-body    { height: 420px; }
  [dir="rtl"] .nadb-chat-body { flex-direction: row; }
  [dir="ltr"] .nadb-chat-body { flex-direction: row; }
}
