/* ==========================================================================
   TAMIRAT — ربات گفتگو
   دکمه همیشه شناور است؛ گوشه آن (راست/چپ، پایین/بالا) از تنظیمات می‌آید و
   روی موبایل هم شناور می‌ماند. پنجره گفتگو روی عرض کم تمام‌عرض باز می‌شود.
   ========================================================================== */
.cs-bot{
  position:fixed;z-index:60;
  font-family:var(--font);line-height:1.8;
}
/* گوشه‌ها: b/t = پایین/بالا، r/l = راست/چپ */
.cs-bot[data-pos$="r"]{right:clamp(12px,2.4vw,28px)}
.cs-bot[data-pos$="l"]{left:clamp(12px,2.4vw,28px)}
.cs-bot[data-pos^="b"]{bottom:var(--cs-bot-bottom,72px)}
.cs-bot[data-pos^="t"]{top:var(--cs-bot-top,84px)}

/* --- دکمه ------------------------------------------------------------- */
.cs-bot__launcher{
  position:relative;display:grid;place-items:center;width:56px;height:56px;border-radius:50%;
  background:linear-gradient(135deg,var(--accent),var(--accent-2));color:var(--on-accent);
  box-shadow:0 12px 30px rgb(var(--accent-rgb) / .38),0 0 0 6px rgb(var(--accent-rgb) / .12);
  transition:transform .3s var(--ease),box-shadow .3s var(--ease);
}
.cs-bot__launcher:hover{transform:translateY(-2px) scale(1.04)}
.cs-bot__launcher svg{width:26px;height:26px}
.cs-bot__badge{
  position:absolute;top:-3px;inset-inline-end:-3px;display:grid;place-items:center;
  min-width:20px;height:20px;padding:0 6px;border-radius:999px;
  background:#EF4444;color:#fff;font-size:.66rem;font-weight:700;line-height:1;
  box-shadow:0 0 0 3px var(--night);
}
.cs-bot__badge[hidden]{display:none}

/* --- پیش‌نمایش پیام --------------------------------------------------- */
.cs-bot__teaser{
  position:absolute;bottom:calc(100% + 12px);
  display:flex;align-items:flex-start;gap:8px;width:max-content;max-width:min(270px,72vw);
  padding:10px 12px 10px 14px;
  border:1px solid var(--line);border-radius:16px;border-end-end-radius:5px;
  background:var(--panel);backdrop-filter:blur(14px);box-shadow:0 14px 34px var(--shadow);
  color:var(--on);font-size:.8rem;cursor:pointer;
  animation:cs-bot-pop .45s var(--ease);
}
.cs-bot__teaser[hidden]{display:none}
.cs-bot__teaser-text{min-width:0}
.cs-bot__teaser-close{flex:none;display:grid;place-items:center;width:22px;height:22px;margin-top:1px;border-radius:50%;color:var(--on-3)}
.cs-bot__teaser-close:hover{color:var(--on);background:rgb(var(--ink-rgb) / .08)}
.cs-bot__teaser-close svg{width:13px;height:13px}
.cs-bot.is-open .cs-bot__teaser{display:none}

/* --- پنجره گفتگو ------------------------------------------------------ */
.cs-bot__panel{
  position:absolute;bottom:calc(100% + 14px);
  display:flex;flex-direction:column;
  width:min(370px,calc(100vw - 24px));height:min(540px,calc(100svh - var(--cs-bot-bottom,72px) - 92px));
  border:1px solid var(--line);border-radius:22px;overflow:hidden;
  background:var(--panel);backdrop-filter:blur(18px);box-shadow:0 30px 80px var(--shadow);
  animation:cs-bot-pop .32s var(--ease);
}
.cs-bot__panel[hidden]{display:none}
@keyframes cs-bot-pop{from{opacity:0;transform:translateY(10px) scale(.97)}to{opacity:1;transform:none}}

.cs-bot__head{
  flex:none;display:flex;align-items:center;gap:10px;padding:13px 14px;
  border-bottom:1px solid var(--line-2);
  background:linear-gradient(135deg,rgb(var(--accent-rgb) / .16),transparent 72%);
}
.cs-bot__avatar{
  flex:none;display:grid;place-items:center;width:40px;height:40px;border-radius:50%;overflow:hidden;
  background:var(--night-2);box-shadow:0 0 0 2px rgb(var(--accent-rgb) / .45);color:var(--accent);
}
.cs-bot__avatar img{width:80%;height:80%;object-fit:contain}
.cs-bot__avatar svg{width:22px;height:22px}
.cs-bot__who{display:flex;flex:1;flex-direction:column;min-width:0}
.cs-bot__who strong{overflow:hidden;font-size:.9rem;font-weight:700;line-height:1.5;text-overflow:ellipsis;white-space:nowrap}
.cs-bot__who small{display:flex;align-items:center;gap:6px;font-size:.7rem;color:var(--on-3)}
.cs-bot__who small i{width:7px;height:7px;border-radius:50%;background:#22C55E;box-shadow:0 0 0 3px rgb(34 197 94 / .2)}
.cs-bot__close{
  flex:none;display:grid;place-items:center;width:34px;height:34px;border-radius:50%;
  border:1px solid var(--line);color:var(--on-2);transition:color .2s,border-color .2s;
}
.cs-bot__close:hover{color:var(--on);border-color:rgb(var(--accent-rgb) / .45)}
.cs-bot__close svg{width:16px;height:16px}

.cs-bot__log{
  flex:1;display:flex;flex-direction:column;gap:8px;min-height:0;overflow-y:auto;
  padding:16px 14px;overscroll-behavior:contain;scrollbar-width:thin;
}
.cs-bot__msg{
  max-width:86%;padding:9px 13px;border-radius:16px;
  font-size:.84rem;line-height:1.8;white-space:pre-line;overflow-wrap:anywhere;
  animation:cs-bot-pop .28s var(--ease);
}
.cs-bot__msg.is-bot{
  align-self:flex-start;border:1px solid var(--line-2);border-start-start-radius:5px;
  background:rgb(var(--ink-rgb) / .07);color:var(--on);
}
.cs-bot__msg.is-user{
  align-self:flex-end;border-end-end-radius:5px;
  background:linear-gradient(135deg,var(--accent),var(--accent-2));color:var(--on-accent);
}
.cs-bot__msg a{color:inherit;text-decoration:underline;text-underline-offset:2px}
.cs-bot__typing{
  align-self:flex-start;display:flex;gap:4px;padding:12px 14px;border-radius:16px;border-start-start-radius:5px;
  background:rgb(var(--ink-rgb) / .07);
}
.cs-bot__typing i{width:6px;height:6px;border-radius:50%;background:var(--on-3);animation:cs-bot-dot 1.1s ease-in-out infinite}
.cs-bot__typing i:nth-child(2){animation-delay:.15s}
.cs-bot__typing i:nth-child(3){animation-delay:.3s}
@keyframes cs-bot-dot{0%,60%,100%{transform:none;opacity:.5}30%{transform:translateY(-4px);opacity:1}}

.cs-bot__quick{flex:none;display:flex;flex-wrap:wrap;gap:6px;padding:0 14px 10px}
.cs-bot__quick:empty{display:none}
.cs-bot__chip{
  padding:6px 14px;border:1px solid rgb(var(--accent-rgb) / .5);border-radius:999px;
  background:rgb(var(--accent-rgb) / .08);color:var(--on);font-size:.8rem;
  transition:background .2s,transform .2s;
}
.cs-bot__chip:hover{background:rgb(var(--accent-rgb) / .18);transform:translateY(-1px)}

.cs-bot__form{
  flex:none;display:flex;align-items:center;gap:6px;margin:0 12px 12px;padding:5px;
  border:1px solid var(--line);border-radius:999px;background:rgb(var(--ink-rgb) / .04);
  transition:border-color .2s,box-shadow .2s;
}
.cs-bot__form[hidden]{display:none}
.cs-bot__form:focus-within{border-color:rgb(var(--accent-rgb) / .55);box-shadow:0 0 0 4px rgb(var(--accent-rgb) / .1)}
.cs-bot__input{unicode-bidi:plaintext;
  flex:1;min-width:0;height:38px;padding:0 12px;border:0;outline:0;
  background:transparent;color:var(--on);font:inherit;font-size:.84rem;text-align:start;
}
.cs-bot__input::placeholder{color:var(--on-3);opacity:1}
.cs-bot__send{
  flex:none;display:grid;place-items:center;width:38px;height:38px;border-radius:50%;
  background:linear-gradient(135deg,var(--accent),var(--accent-2));color:var(--on-accent);
}
.cs-bot__send svg{width:18px;height:18px}
html[dir="rtl"] .cs-bot__send svg{transform:scaleX(-1)}

/* عرض کم: دکمه در ردیف پاورقی، کنار نام سازنده (bot.js جابه‌جا می‌کند) */
.foot .cs-bot__launcher{
  flex:none;width:36px;height:36px;margin-inline-start:auto;
  box-shadow:0 6px 16px rgb(var(--accent-rgb) / .32),0 0 0 3px rgb(var(--accent-rgb) / .12);
}
.foot .cs-bot__launcher svg{width:19px;height:19px}
.foot .cs-bot__badge{top:-5px;inset-inline-end:-5px;min-width:17px;height:17px;padding:0 5px;font-size:.6rem}

/* موبایل: پنجره گفتگو با فاصله از لبه‌ها باز می‌شود و دکمه شناور تا بسته شدن پنجره پنهان می‌ماند */
@media (max-width:640px){
  .cs-bot__panel{
    position:fixed;top:auto;
    right:max(14px,env(safe-area-inset-right));left:max(14px,env(safe-area-inset-left));
    bottom:max(14px,env(safe-area-inset-bottom));
    width:auto;height:min(580px,calc(100dvh - 28px - env(safe-area-inset-bottom)));
  }
  .cs-bot.is-open .cs-bot__launcher{display:none}
}

@media (prefers-reduced-motion:reduce){
  .cs-bot__panel,.cs-bot__teaser,.cs-bot__msg{animation:none}
}

/* --- گوشه: جهت باز شدن حباب و پنجره ---------------------------------- */
.cs-bot[data-pos$="r"] :is(.cs-bot__teaser,.cs-bot__panel){right:0;left:auto}
.cs-bot[data-pos$="l"] :is(.cs-bot__teaser,.cs-bot__panel){left:0;right:auto}
.cs-bot[data-pos$="r"] .cs-bot__teaser{border-end-end-radius:5px;border-end-start-radius:16px}
.cs-bot[data-pos$="l"] .cs-bot__teaser{border-end-start-radius:5px;border-end-end-radius:16px}
.cs-bot[data-pos^="t"] :is(.cs-bot__teaser,.cs-bot__panel){top:calc(100% + 14px);bottom:auto}
.cs-bot[data-pos^="t"] .cs-bot__panel{height:min(540px,calc(100svh - var(--cs-bot-top,84px) - 92px))}

/* روی عرض کم، دکمه کوچک‌تر می‌شود تا کمتر جلوی محتوا را بگیرد */
@media (max-width:640px){
  .cs-bot__launcher{width:50px;height:50px}
  .cs-bot__launcher svg{width:23px;height:23px}
}

@media (max-width:640px){
  .cs-bot[data-pos] .cs-bot__panel{
    top:auto;bottom:max(14px,env(safe-area-inset-bottom));
    right:max(14px,env(safe-area-inset-right));left:max(14px,env(safe-area-inset-left));
  }
}
