/* ==========================================================
   ربات گفتگو
   ----------------------------------------------------------
   از همان متغیرهای رنگ style.css استفاده می‌کند و در هر دو
   جهت (راست‌به‌چپ و چپ‌به‌راست) درست می‌نشیند.
   ========================================================== */

.chat{
  position:fixed;
  inset-block-end:max(20px,env(safe-area-inset-bottom));
  inset-inline-end:20px;
  z-index:150;
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:12px;
}

/* ---------- دکمه شناور ---------- */

.chat-fab{
  display:inline-flex;align-items:center;gap:9px;
  padding:13px 20px;
  border:0;border-radius:999px;cursor:pointer;
  font-family:inherit;font-size:14.5px;font-weight:600;
  color:var(--navy-900);
  background:linear-gradient(135deg,var(--gold-400),var(--gold-500));
  box-shadow:0 10px 30px rgba(198,149,46,.35);
  transition:transform var(--t),box-shadow var(--t);
}
.chat-fab:hover{transform:translateY(-2px);box-shadow:0 16px 40px rgba(198,149,46,.45)}
.chat-fab:focus-visible{outline:2px solid var(--gold-300);outline-offset:3px}
.chat-fab svg{width:21px;height:21px;flex:none}

.chat.is-open .chat-fab{display:none}

/* ---------- پنل ---------- */

.chat-panel{
  display:flex;flex-direction:column;
  width:min(380px,calc(100vw - 40px));
  height:min(560px,calc(100vh - 120px));
  border-radius:18px;overflow:hidden;
  background:var(--paper);
  border:1px solid var(--line);
  box-shadow:0 30px 70px rgba(10,21,38,.32);
  animation:chatIn .22s ease both;
}
.chat-panel[hidden]{display:none}

@keyframes chatIn{
  from{opacity:0;transform:translateY(14px) scale(.98)}
  to{opacity:1;transform:none}
}

.chat-head{
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:15px 18px;
  color:var(--paper);
  background:linear-gradient(135deg,var(--navy-800),var(--navy-900));
}
.chat-head h2{margin:0;font-size:15.5px;font-weight:700;line-height:1.4}
.chat-sub{display:flex;align-items:center;gap:6px;margin:2px 0 0;font-size:11.5px;letter-spacing:.06em;color:var(--gold-400)}
.chat-online{width:7px;height:7px;border-radius:50%;background:#54d68b;box-shadow:0 0 0 3px rgba(84,214,139,.14)}

.chat-x{
  flex:none;width:32px;height:32px;line-height:1;
  font-size:22px;cursor:pointer;
  color:var(--paper);background:rgba(247,245,241,.1);
  border:1px solid rgba(247,245,241,.18);border-radius:9px;
  transition:background var(--t);
}
.chat-x:hover{background:rgba(247,245,241,.2)}
.chat-x:focus-visible{outline:2px solid var(--gold-300);outline-offset:2px}

/* ---------- گفتگو ---------- */

.chat-log{
  flex:1;overflow-y:auto;overscroll-behavior:contain;
  padding:18px;display:flex;flex-direction:column;gap:12px;
  background:linear-gradient(180deg,rgba(14,26,46,.03),transparent 120px);
}

.chat-msg{max-width:86%;border-radius:14px;padding:11px 14px;font-size:14.5px;line-height:1.75}
.chat-msg p{margin:0}
.chat-msg p + p{margin-top:8px}
.chat-time{display:block;margin-top:5px;font-size:10px;line-height:1;color:currentColor;opacity:.55;text-align:end}

.chat-bot{
  align-self:flex-start;
  background:#fff;color:var(--ink);
  border:1px solid var(--line);
  border-start-start-radius:5px;
}
.chat-user{
  align-self:flex-end;
  background:var(--navy-800);color:var(--paper);
  border-start-end-radius:5px;
}

/* ---------- «در حال نوشتن» ---------- */

.chat-typing{display:flex;gap:5px;align-items:center;padding:15px 16px}
.chat-dot{
  width:7px;height:7px;border-radius:50%;
  background:var(--slate,#7c8a9e);
  animation:chatDot 1.3s ease-in-out infinite;
}
.chat-dot:nth-child(2){animation-delay:.18s}
.chat-dot:nth-child(3){animation-delay:.36s}
@keyframes chatDot{0%,60%,100%{opacity:.3;transform:translateY(0)}30%{opacity:1;transform:translateY(-4px)}}

/* ---------- پرسش‌های پیشنهادی ---------- */

.chat-chips{display:flex;flex-wrap:wrap;gap:7px}
.chat-chips-label{
  width:100%;margin:2px 0 3px;font-size:12px;color:var(--slate,#7c8a9e);
}
.chat-chip{
  padding:8px 13px;border-radius:999px;cursor:pointer;
  font-family:inherit;font-size:13px;text-align:start;
  color:var(--navy-800);background:#fff;
  border:1px solid var(--gold-500);
  transition:background var(--t),color var(--t);
}
.chat-chip:hover{background:var(--gold-500);color:var(--navy-900)}
.chat-chip:focus-visible{outline:2px solid var(--gold-300);outline-offset:2px}

/* ---------- فرم ---------- */

.chat-form{
  display:flex;align-items:flex-end;gap:8px;padding:12px;
  border-top:1px solid var(--line);background:#fff;
}
.chat-compose{position:relative;flex:1;min-width:0}
.chat-form textarea{
  flex:1;min-width:0;
  display:block;width:100%;min-height:44px;max-height:112px;resize:none;
  padding:10px 14px 19px;border-radius:11px;
  font-family:inherit;font-size:14.5px;color:var(--ink);
  border:1px solid var(--line);background:var(--paper);
}
.chat-form textarea:focus{outline:2px solid var(--gold-400);outline-offset:-1px}
.chat-counter{position:absolute;inset-inline-end:10px;inset-block-end:5px;font-size:9.5px;color:var(--slate);pointer-events:none}
.chat-form button{
  flex:none;width:44px;height:44px;cursor:pointer;
  display:grid;place-items:center;
  border:0;border-radius:11px;
  color:var(--navy-900);background:var(--gold-500);
  transition:filter var(--t);
}
.chat-form button:hover{filter:brightness(1.08)}
.chat-form button:disabled{cursor:not-allowed;filter:grayscale(.35);opacity:.55}
.chat-form button:focus-visible{outline:2px solid var(--gold-300);outline-offset:2px}
.chat-form button svg{width:20px;height:20px}
[dir="rtl"] .chat-form button svg{transform:scaleX(-1)}

.chat-note{
  margin:0;padding:9px 14px 12px;
  font-size:11.5px;line-height:1.6;text-align:center;
  color:var(--slate,#7c8a9e);background:#fff;
}

.sr-only{
  position:absolute;width:1px;height:1px;padding:0;margin:-1px;
  overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;border:0;
}

/* ---------- موبایل ---------- */

@media (max-width:680px){
  .chat{inset-block-end:max(14px,env(safe-area-inset-bottom));inset-inline-end:14px;inset-inline-start:14px;align-items:flex-end}
  .chat-fab-label{display:none}
  .chat-fab{width:54px;height:54px;padding:0;justify-content:center}
  .chat-panel{width:100%;height:min(76vh,76dvh,540px)}
  .chat-msg{max-width:92%}
}

@media (prefers-reduced-motion:reduce){
  .chat-panel{animation:none}
  .chat-dot{animation:none;opacity:.6}
  .chat-fab{transition:none}
}
