/* ── فونت Vazirmatn (لوکال، داخل افزونه — بدون CDN) ──────────────────────────── */
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-Variable.woff2') format('woff2');
    font-weight: 100 900;   /* فونت متغیر — همه‌ی وزن‌ها در یک فایل */
    font-style: normal;
    font-display: swap;
}

.aisb-login-required { text-align: center; padding: 20px; color: #555; }
.aisb-login-required a { color: #4f46e5; }

.aisb-limit-bar {
    font-size: 12px;
    color: #6b7280;
    margin-top: 6px;
    text-align: left;
}
.aisb-limit-exceeded { color: #dc2626; font-weight: bold; }

.aisb-widget {
    font-family: 'Vazirmatn', 'Tahoma', sans-serif;
    direction: rtl;
    max-width: 700px;
    margin: 20px auto !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.7;
    color: #1f2937;
    letter-spacing: 0;
}
/* همه‌ی اجزای داخل ویجت Vazirmatn بگیرند — !important تا استایل لینک/متن تمِ سایت غلبه نکند */
.aisb-widget, .aisb-widget * { font-family: 'Vazirmatn', 'Tahoma', sans-serif !important; }

.aisb-search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.aisb-search-bar input {
    flex: 1;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color .2s;
    /* جهتِ نوشتار را dir="auto" روی خودِ input تعیین می‌کند (با محتوای تایپ‌شده تطبیق می‌یابد) */
}
.aisb-search-bar input:focus { border-color: #6366f1; }

.aisb-search-bar button {
    background: #6366f1;
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    transition: background .2s;
}
.aisb-search-bar button:hover { background: #4f46e5; }

/* Chat mode */
.aisb-chat-reply {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 18px 20px;
    line-height: 1.95;
    font-size: 15px;
    color: #1f2937;
}
.aisb-chat-reply .ai-card {
    display: flex;
    gap: 14px;
    align-items: center;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 12px 14px;
    margin-top: 12px;
    transition: border-color .2s, box-shadow .2s, transform .2s;
}
.aisb-chat-reply .ai-card:hover {
    border-color: #6366f1;
    box-shadow: 0 6px 18px rgba(99,102,241,.12);
    transform: translateY(-1px);
}
.aisb-chat-reply .ai-card img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}
.aisb-chat-reply .ai-card-body { flex: 1; min-width: 0; }
.aisb-chat-reply .ai-card-body a {
    font-weight: 700;
    color: #4f46e5;
    text-decoration: none;
    font-size: 15px;
    line-height: 1.5;
}
.aisb-chat-reply .ai-card-body a:hover { color: #4338ca; }
.aisb-chat-reply .ai-card-body p { font-size: 12.5px; color: #6b7280; margin: 5px 0 0; line-height: 1.7; }

/* Search mode - product cards */
.aisb-products { display: flex; flex-direction: column; gap: 10px; }
.aisb-product-card {
    display: flex;
    gap: 12px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px;
    text-decoration: none;
    color: inherit;
    transition: border-color .2s, box-shadow .2s;
}
.aisb-product-card:hover { border-color: #6366f1; box-shadow: 0 4px 12px rgba(99,102,241,.1); }
.aisb-product-card img {
    width: 80px; height: 80px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
    background: #f3f4f6;
}
.aisb-product-info { flex: 1; }
.aisb-product-title { font-weight: bold; font-size: 14px; color: #111; margin-bottom: 4px; }
.aisb-product-excerpt { font-size: 12px; color: #6b7280; line-height: 1.5; }
.aisb-product-price { font-weight: bold; color: #6366f1; font-size: 13px; margin-top: 6px; }

/* Loading dots */
.aisb-loading { display: flex; gap: 6px; padding: 12px 0; }
.aisb-dot {
    width: 8px; height: 8px;
    background: #6366f1;
    border-radius: 50%;
    animation: aisbBounce .8s infinite alternate;
}
.aisb-dot:nth-child(2) { animation-delay: .2s; }
.aisb-dot:nth-child(3) { animation-delay: .4s; }
@keyframes aisbBounce { from { opacity: .3; transform: translateY(0); } to { opacity: 1; transform: translateY(-6px); } }

.aisb-error { color: #ef4444; font-size: 13px; padding: 8px 0; }

/* ── Price: variable range + sale (regular strikethrough + sale highlighted) ──── */
.aisb-chat-reply .ai-card-price { font-weight: 700; color: #4f46e5; font-size: 13px; margin-top: 6px; }
.aisb-chat-reply .ai-card-price del,
.aisb-product-price del { color: #9ca3af; font-weight: 400; font-size: .9em; margin-inline-end: 6px; }
.aisb-chat-reply .ai-card-price ins,
.aisb-product-price ins { text-decoration: none; color: #16a34a; font-weight: 700; }

/* ── Loading message (rotates while waiting) ─────────────────────────────────── */
.aisb-loading-msg {
  text-align: center;
  font-size: 13px;
  color: #6b7280;
  margin: 8px 0 4px;
  transition: opacity .22s ease;
  min-height: 18px;
}

/* ── Typewriter caret ────────────────────────────────────────────────────────── */
.aisb-chat-reply .aisb-typing::after {
  content: '▌';
  display: inline-block;
  margin-inline-start: 1px;
  color: #6366f1;
  animation: aisb-caret 1s steps(1) infinite;
}
@keyframes aisb-caret { 50% { opacity: 0; } }

/* ── Staggered reveal for cards/products ─────────────────────────────────────── */
.aisb-reveal { opacity: 0; transform: translateY(8px); }
.aisb-reveal-in {
  opacity: 1; transform: none;
  transition: opacity .35s ease, transform .35s ease;
}

/* فاصله‌ی پاراگراف پایانی از آخرین کارت محصول */
.aisb-chat-reply .ai-card + p { margin-top: 16px; }

/* ════════════════════════════════════════════════════════════════════════════
   مشاورِ فروش — تردِ گفتگوی چندمرحله‌ای ([ai_consultant])
   ════════════════════════════════════════════════════════════════════════════ */
.aisb-consultant {
  font-family: 'Vazirmatn', 'Tahoma', sans-serif;
  direction: rtl;
  max-width: 700px;
  margin: 20px auto !important;
  color: #1f2937;
  display: flex;
  flex-direction: column;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(15, 23, 42, .06);
}
.aisb-consultant, .aisb-consultant * { font-family: 'Vazirmatn', 'Tahoma', sans-serif !important; }

.aisb-consultant .aisb-thread {
  height: var(--aisb-thread-h, 520px);
  overflow-y: auto;
  padding: 18px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
  scroll-behavior: smooth;
}

.aisb-msg { display: flex; opacity: 0; transform: translateY(8px); transition: opacity .3s ease, transform .3s ease; }
.aisb-msg.aisb-msg-in { opacity: 1; transform: none; }
.aisb-msg-user { justify-content: flex-start; }   /* RTL: کاربر سمت راست */
.aisb-msg-bot  { justify-content: flex-start; }

.aisb-msg-user { flex-direction: row-reverse; }
.aisb-msg-user .aisb-msg-body {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  font-size: 14.5px;
  max-width: 80%;
  line-height: 1.8;
}
/* پاسخِ ربات از aisb-chat-reply ارث می‌برد؛ فقط حباب‌سازی و حداکثر عرض را تنظیم می‌کنیم */
.aisb-msg-bot .aisb-msg-body.aisb-chat-reply {
  max-width: 92%;
  margin: 0;
  border-radius: 16px 16px 16px 4px;
  font-size: 14.5px;
  padding: 14px 16px;
}
.aisb-msg-bot .aisb-msg-body.aisb-chat-reply > p:first-child { margin-top: 0; }
.aisb-msg-bot .aisb-msg-body.aisb-chat-reply > p:last-child  { margin-bottom: 0; }

.aisb-consultant .aisb-typing { display: flex; gap: 6px; padding: 6px 22px 10px; background: #f8fafc; }

.aisb-consultant-bar {
  margin: 0 !important;
  padding: 12px;
  border-top: 1px solid #eef2f7;
  background: #fff;
}
.aisb-consultant-bar input { border-radius: 12px; }

@media (max-width: 480px) {
  .aisb-consultant .aisb-thread { height: 70vh; }
  .aisb-msg-user .aisb-msg-body { max-width: 88%; }
}

/* ════════════════════════════════════════════════════════════════════════════
   دکمه‌ی چت شناور (FAB + پنل) — مشاورِ فروش روی همه‌ی صفحات
   رنگ از --aisb-accent می‌آید (سرور آن را inline روی .aisb-float ست می‌کند).
   موقعیت با کلاسِ aisb-float-left / aisb-float-right کنترل می‌شود.
   ════════════════════════════════════════════════════════════════════════════ */
.aisb-float {
  --aisb-accent: #4f46e5;
  --aisb-accent-2: #6366f1;
  position: fixed;
  bottom: 22px;
  z-index: 99998;
  direction: rtl;
  font-family: 'Vazirmatn', 'Tahoma', sans-serif;
}
.aisb-float.aisb-float-right { right: 22px; }
.aisb-float.aisb-float-left  { left: 22px; }

/* ── دکمه‌ی شناور (لانچر) ───────────────────────────────────────────────────── */
.aisb-fab {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, var(--aisb-accent-2), var(--aisb-accent));
  box-shadow: 0 10px 28px rgba(15, 23, 42, .28);
  transition: transform .2s ease, box-shadow .2s ease;
}
.aisb-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 34px rgba(15, 23, 42, .34); }
.aisb-fab:active { transform: scale(.97); }
.aisb-fab svg { width: 28px; height: 28px; }
.aisb-fab img { width: 34px; height: 34px; object-fit: contain; border-radius: 8px; }
/* آیکونِ بستن داخلِ همان دکمه — وقتی پنل باز است نشان داده می‌شود */
.aisb-fab .aisb-fab-close { display: none; }
.aisb-float.aisb-open .aisb-fab .aisb-fab-open  { display: none; }
.aisb-float.aisb-open .aisb-fab .aisb-fab-close { display: block; }

/* پالسِ ملایمِ جلب‌توجه فقط تا اولین باز شدن */
.aisb-float:not(.aisb-open) .aisb-fab::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0 var(--aisb-accent);
  opacity: .55;
  animation: aisb-fab-pulse 2.4s ease-out infinite;
}
@keyframes aisb-fab-pulse {
  0%   { box-shadow: 0 0 0 0 var(--aisb-accent); opacity: .5; }
  70%  { box-shadow: 0 0 0 16px var(--aisb-accent); opacity: 0; }
  100% { box-shadow: 0 0 0 0 var(--aisb-accent); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .aisb-float .aisb-fab::after { animation: none; }
}

/* ── پنلِ گفتگو ─────────────────────────────────────────────────────────────── */
.aisb-float-panel {
  position: absolute;
  bottom: 76px;
  width: 380px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
  border: 1px solid #e5e7eb;
  opacity: 0;
  transform: translateY(16px) scale(.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.aisb-float-right .aisb-float-panel { right: 0; transform-origin: bottom right; }
.aisb-float-left  .aisb-float-panel { left: 0;  transform-origin: bottom left; }
.aisb-float.aisb-open .aisb-float-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* سرتیترِ پنل */
.aisb-float-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--aisb-accent-2), var(--aisb-accent));
}
.aisb-float-head .aisb-float-title { font-weight: 700; font-size: 15px; line-height: 1.4; }
.aisb-float-head .aisb-float-sub { font-size: 11px; opacity: .85; margin-top: 2px; }
.aisb-float-head .aisb-float-actions { margin-right: auto; display: flex; gap: 4px; }
.aisb-float-head button {
  background: rgba(255, 255, 255, .18);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
.aisb-float-head button:hover { background: rgba(255, 255, 255, .34); }
.aisb-float-head button svg { width: 16px; height: 16px; }

/* مشاور داخلِ پنل: حاشیه/سایه/گردیِ بیرونی را خنثی کن تا با پنل یکی شود */
.aisb-float-panel .aisb-consultant {
  margin: 0 !important;
  max-width: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
}
.aisb-float-panel .aisb-consultant .aisb-thread { height: 56vh; max-height: 460px; }

/* تطبیقِ رنگِ تمِ شناور: حبابِ کاربر و دکمه‌ی ارسال از رنگِ برند پیروی کنند */
.aisb-float-panel .aisb-msg-user .aisb-msg-body {
  background: linear-gradient(135deg, var(--aisb-accent-2), var(--aisb-accent));
}
.aisb-float-panel .aisb-search-bar button { background: var(--aisb-accent-2); }
.aisb-float-panel .aisb-search-bar button:hover { background: var(--aisb-accent); }
.aisb-float-panel .aisb-search-bar input:focus { border-color: var(--aisb-accent-2); }

/* ── موبایل: پنل تمام‌صفحه ───────────────────────────────────────────────────── */
@media (max-width: 480px) {
  /* پنلِ تمام‌صفحه = ستونِ flex تا هدر و فیلدِ ورودی همیشه دیده شوند و فقط ترد اسکرول شود.
     100dvh به‌جای 100vh تا نوارِ آدرسِ موبایل ارتفاع را نخورد و محتوا سرریز/بریده نشود. */
  .aisb-float-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
  }
  .aisb-float-panel .aisb-float-head { flex: 0 0 auto; }
  /* min-height:0 حیاتی است تا آیتمِ flex بتواند کوچک شود و فرزندِ اسکرول‌شونده‌اش جا شود */
  .aisb-float-panel .aisb-consultant { flex: 1 1 auto; min-height: 0; height: auto; }
  .aisb-float-panel .aisb-consultant .aisb-thread { flex: 1 1 auto; min-height: 0; height: auto; max-height: none; }
  .aisb-float-panel .aisb-consultant .aisb-consultant-bar { flex: 0 0 auto; }
  .aisb-float.aisb-open .aisb-fab { display: none; } /* روی موبایل دکمه پشتِ پنلِ تمام‌صفحه پنهان شود */
}

/* ════════════════════════════════════════════════════════════════════════════
   جایگزینیِ فیلدِ جستجوی قالب — بلاکِ نتیجه‌ی شناور زیرِ فیلد + آیکونِ ما
   position:fixed → چیدمانِ قالب (حتی در هدرِ چسبان) به‌هم نمی‌ریزد.
   ════════════════════════════════════════════════════════════════════════════ */
.aisb-attach-panel {
  --aisb-accent: #4f46e5;
  position: fixed;
  z-index: 99997;
  margin: 0 !important;
  max-width: none;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, .22);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
.aisb-attach-panel.aisb-attach-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.aisb-attach-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  background: #fafbff;
}
.aisb-attach-head .aisb-attach-spark { font-size: 12.5px; font-weight: 700; color: var(--aisb-accent); }
.aisb-attach-head .aisb-attach-close {
  margin-right: auto;
  border: none;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
}
.aisb-attach-head .aisb-attach-close:hover { background: #eef2f7; color: #475569; }

/* ناحیه‌ی نتیجه: اسکرول‌دار تا پنل بلندتر از صفحه نشود */
.aisb-attach-panel .aisb-results {
  max-height: min(60vh, 460px);
  overflow-y: auto;
  padding: 14px 16px;
}
.aisb-attach-panel .aisb-loading { padding: 14px 16px; }

/* فیلدِ جایگزین: فیلدِ جستجوی قالب پنهان می‌شود و فیلدِ ما با دکمه‌ی «ستاره‌ی هوش مصنوعی» جایش می‌نشیند */
.aisb-field-hidden { display: none !important; }
.aisb-attach-field {
  --aisb-accent: #4f46e5;
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 100%;
  flex: 1 1 auto;       /* اگر ظرفِ والد flex بود، فضای فیلدِ قالبِ قبلی را پر کند */
  min-width: 0;
  box-sizing: border-box;
  direction: ltr;
  font-family: 'Vazirmatn', 'Tahoma', sans-serif;
}
.aisb-attach-field.aisb-rtl { direction: rtl; }
.aisb-attach-field .aisb-input {
  width: 100%;
  box-sizing: border-box;
  height: 44px;
  margin: 0;
  padding: 0 48px 0 16px;          /* جا برای دکمه در سمتِ راست (LTR) */
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  color: #1f2937;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  outline: none;
  box-shadow: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.aisb-attach-field.aisb-rtl .aisb-input { padding: 0 16px 0 48px; }
.aisb-attach-field .aisb-input::placeholder { color: #9aa4b2; }
.aisb-attach-field .aisb-input:focus {
  border-color: var(--aisb-accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .14);
}

/* دکمه‌ی ستاره‌ی هوش مصنوعی (شبیه لوگوی Gemini) داخلِ فیلد */
.aisb-attach-icon {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--aisb-accent);
  box-shadow: 0 2px 8px rgba(15, 23, 42, .18);
  transition: transform .15s ease, filter .15s ease;
}
.aisb-attach-field.aisb-rtl .aisb-attach-icon { right: auto; left: 6px; }
.aisb-attach-icon:hover { transform: translateY(-50%) scale(1.08); filter: brightness(1.06); }
.aisb-attach-icon:disabled { opacity: .6; cursor: default; }
.aisb-attach-icon svg { width: 21px; height: 21px; filter: drop-shadow(0 0 3px rgba(255,255,255,.35)); }
.aisb-attach-icon img { width: 22px; height: 22px; object-fit: contain; border-radius: 5px; }

@media (max-width: 480px) {
  .aisb-attach-panel { left: 12px !important; width: calc(100vw - 24px) !important; }
}
