/* ============================================================
   AMU LABS Chatbot — استایل (بنفش، RTL، ریسپانسیو، سازگار با حالت تاریک سایت)
   ============================================================ */
#amu-chatbot {
  --ac-main: #5b00d6;
  --ac-bright: #7b2fff;
  --ac-pale: #ede9ff;
  --ac-bg: #ffffff;
  --ac-bg2: #f8f7ff;
  --ac-border: #e8e3ff;
  --ac-text: #1a0040;
  --ac-muted: #7a6aa0;
  --ac-bot: #f3f0ff;
  --ac-err-bg: #fff0f3;
  --ac-err: #b4123c;
  --ac-shadow: 0 20px 60px rgba(91, 0, 214, .25);
  font-family: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--ac-text);
}
html[data-theme="dark"] #amu-chatbot {
  --ac-bg: #1c1137;
  --ac-bg2: #140b2b;
  --ac-border: #2f2152;
  --ac-text: #f3eeff;
  --ac-muted: #a99cc9;
  --ac-bot: #2a1a52;
  --ac-pale: #2a1a52;
  --ac-err-bg: #3a1226;
  --ac-err: #ff8aa8;
  --ac-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
#amu-chatbot *, #amu-chatbot *::before, #amu-chatbot *::after { box-sizing: border-box; }
#amu-chatbot button, #amu-chatbot input, #amu-chatbot textarea, #amu-chatbot select { font: inherit; color: inherit; }

/* ---------- دکمه شناور: سمت چپ، درست بالای دکمه‌ی واتساپ سایت (واتساپ: ۵۶px در ۲۴px) ---------- */
.amu-fab {
  position: fixed; left: 24px; bottom: 94px; z-index: 950;
  width: 56px; height: 56px; border: 0; border-radius: 50%; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--ac-bright), var(--ac-main));
  color: #fff; box-shadow: 0 8px 24px rgba(91, 0, 214, .45);
  animation: amuFloat 3.2s ease-in-out infinite;
  transition: box-shadow .2s ease, opacity .2s ease, filter .2s ease;
}
.amu-fab:hover, .amu-fab:focus-visible { animation-play-state: paused; filter: brightness(1.1); box-shadow: 0 10px 30px rgba(91, 0, 214, .6); }
.amu-fab:focus-visible, .amu-btn:focus-visible, .amu-chip:focus-visible, .amu-send:focus-visible {
  outline: 3px solid #c084fc; outline-offset: 2px;
}
.amu-fab svg { width: 32px; height: 32px; transition: transform .2s ease; }
.amu-fab:hover svg, .amu-fab:focus-visible svg { transform: scale(1.08) rotate(-4deg); }
.amu-open .amu-fab { opacity: 0; pointer-events: none; animation: none; }

/* برچسب «دستیار هوش مصنوعی AMU LABS» با هاور/فوکوس/لمس */
.amu-tip {
  position: absolute; left: calc(100% + 12px); top: 50%; transform: translate(-6px, -50%);
  white-space: nowrap; padding: 7px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; line-height: 1.4;
  color: #fff; background: #1a0040; box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .18s ease, transform .18s ease, visibility .18s;
}
.amu-tip::before {
  content: ''; position: absolute; left: -5px; top: 50%; width: 10px; height: 10px; margin-top: -5px;
  background: inherit; transform: rotate(45deg); border-radius: 2px;
}
.amu-fab:hover .amu-tip, .amu-fab:focus-visible .amu-tip, .amu-fab.amu-tip-on .amu-tip {
  opacity: 1; visibility: visible; transform: translate(0, -50%);
}
html[data-theme="dark"] .amu-tip { background: #f3eeff; color: #1a0040; }

/* ---------- پنجره ---------- */
.amu-panel {
  position: fixed; left: 24px; bottom: 24px; z-index: 1500; /* بالاتر از ناوبار سایت (۱۰۰۰) */
  width: 390px; max-width: calc(100vw - 32px);
  height: min(640px, calc(100vh - 48px)); height: min(640px, calc(100dvh - 48px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--ac-bg); border: 1px solid var(--ac-border); border-radius: 22px;
  box-shadow: var(--ac-shadow);
  opacity: 0; transform: translateY(16px) scale(.97); transform-origin: bottom left;
  visibility: hidden; transition: opacity .22s ease, transform .22s ease, visibility .22s;
}
.amu-open .amu-panel { opacity: 1; transform: none; visibility: visible; }

.amu-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px; color: #fff;
  background: linear-gradient(135deg, var(--ac-bright), var(--ac-main));
}
.amu-avatar {
  width: 38px; height: 38px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .18);
}
.amu-avatar svg { width: 22px; height: 22px; }
.amu-titles { flex: 1; min-width: 0; }
.amu-title { font-weight: 700; font-size: 15px; line-height: 1.3; margin: 0; }
.amu-sub { font-size: 12px; opacity: .85; line-height: 1.3; }
.amu-btn {
  width: 34px; height: 34px; flex: none; border: 0; border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .14); color: #fff; transition: background .15s;
}
.amu-btn:hover { background: rgba(255, 255, 255, .28); }
.amu-btn svg { width: 18px; height: 18px; }

/* ---------- پیام‌ها ---------- */
.amu-log {
  flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px;
  background: var(--ac-bg2); scroll-behavior: smooth; overscroll-behavior: contain;
}
.amu-msg {
  max-width: 86%; padding: 9px 13px; border-radius: 16px; word-wrap: break-word; overflow-wrap: anywhere;
  animation: amuIn .22s ease both;
}
.amu-msg p { margin: 0; }
.amu-msg p + p, .amu-msg ul + p, .amu-msg p + ul { margin-top: 6px; }
.amu-msg ul { margin: 0; padding-inline-start: 20px; }
.amu-msg a { color: inherit; text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.amu-bot { background: var(--ac-bot); border: 1px solid var(--ac-border); border-end-start-radius: 4px; }
.amu-user { color: #fff; background: linear-gradient(135deg, var(--ac-bright), var(--ac-main)); border-end-end-radius: 4px; }
.amu-bot a { color: var(--ac-main); }
html[data-theme="dark"] .amu-bot a { color: #c4a5ff; }
.amu-error { background: var(--ac-err-bg); color: var(--ac-err); border: 1px solid currentColor; }

/* راست‌چین: کاربر سمت راست، دستیار سمت چپ — چپ‌چین: برعکس */
#amu-chatbot[dir="rtl"] .amu-user { align-self: flex-start; }
#amu-chatbot[dir="rtl"] .amu-bot, #amu-chatbot[dir="rtl"] .amu-error { align-self: flex-end; }
#amu-chatbot[dir="ltr"] .amu-user { align-self: flex-end; }
#amu-chatbot[dir="ltr"] .amu-bot, #amu-chatbot[dir="ltr"] .amu-error { align-self: flex-start; }

.amu-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.amu-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ac-muted); animation: amuDot 1s infinite ease-in-out; }
.amu-typing i:nth-child(2) { animation-delay: .15s; }
.amu-typing i:nth-child(3) { animation-delay: .3s; }

/* ---------- پیشنهادها و دکمه ثبت درخواست ---------- */
.amu-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.amu-chip {
  border: 1px solid var(--ac-border); background: var(--ac-bg); color: var(--ac-main);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; text-align: start;
  transition: background .15s, border-color .15s;
}
html[data-theme="dark"] .amu-chip { color: #c4a5ff; }
.amu-chip:hover { background: var(--ac-pale); border-color: var(--ac-bright); }
.amu-tools { display: flex; gap: 8px; padding: 8px 12px 0; background: var(--ac-bg); }
.amu-tools .amu-chip { padding: 4px 11px; font-size: 12.5px; }

/* ---------- ورودی ---------- */
.amu-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 6px; background: var(--ac-bg); }
.amu-input {
  flex: 1; resize: none; max-height: 120px; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--ac-border); border-radius: 14px; background: var(--ac-bg2); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.amu-input:focus { border-color: var(--ac-bright); box-shadow: 0 0 0 3px rgba(123, 47, 255, .15); }
.amu-send {
  width: 42px; height: 42px; flex: none; border: 0; border-radius: 14px; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, var(--ac-bright), var(--ac-main));
  display: flex; align-items: center; justify-content: center; transition: opacity .15s, transform .15s;
}
.amu-send:hover:not(:disabled) { transform: translateY(-1px); }
.amu-send:disabled { opacity: .45; cursor: not-allowed; }
#amu-chatbot[dir="rtl"] .amu-send svg { transform: scaleX(-1); }
.amu-send svg { width: 20px; height: 20px; }
.amu-foot { padding: 0 14px 10px; font-size: 11.5px; color: var(--ac-muted); background: var(--ac-bg); display: flex; justify-content: space-between; gap: 8px; }
.amu-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* ---------- فرم ثبت درخواست ---------- */
.amu-lead { display: none; flex-direction: column; gap: 10px; padding: 14px; overflow-y: auto; flex: 1; background: var(--ac-bg2); }
.amu-lead-on .amu-lead { display: flex; }
.amu-lead-on .amu-log, .amu-lead-on .amu-form, .amu-lead-on .amu-tools, .amu-lead-on .amu-foot { display: none; }
.amu-lead h3 { margin: 0; font-size: 15px; }
.amu-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.amu-field input, .amu-field select, .amu-field textarea {
  padding: 8px 11px; border: 1px solid var(--ac-border); border-radius: 12px; background: var(--ac-bg); outline: none;
}
.amu-field input:focus, .amu-field select:focus, .amu-field textarea:focus { border-color: var(--ac-bright); box-shadow: 0 0 0 3px rgba(123, 47, 255, .15); }
.amu-field.amu-bad input, .amu-field.amu-bad select, .amu-field.amu-bad textarea { border-color: var(--ac-err); }
.amu-consent { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--ac-muted); }
.amu-consent input { margin-top: 5px; accent-color: var(--ac-bright); }
.amu-consent.amu-bad { color: var(--ac-err); }
.amu-lead-actions { display: flex; gap: 8px; margin-top: 4px; }
.amu-primary {
  flex: 1; border: 0; border-radius: 12px; padding: 10px; color: #fff; cursor: pointer; font-weight: 700;
  background: linear-gradient(135deg, var(--ac-bright), var(--ac-main));
}
.amu-primary:disabled { opacity: .5; cursor: wait; }
.amu-secondary { border: 1px solid var(--ac-border); background: var(--ac-bg); border-radius: 12px; padding: 10px 14px; cursor: pointer; }
.amu-lead-msg { font-size: 13px; color: var(--ac-err); min-height: 1.2em; }

/* ---------- موبایل: تمام‌صفحه ---------- */
@media (max-width: 520px) {
  .amu-fab { left: 16px; bottom: 90px; }
  .amu-tip { font-size: 12.5px; }
  .amu-panel {
    left: 0; right: 0; bottom: 0; top: 0; width: 100%; max-width: 100%; height: 100%; border-radius: 0; border: 0;
    transform-origin: bottom center; padding-top: env(safe-area-inset-top, 0px);
  }
  .amu-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .amu-input, .amu-field input, .amu-field select, .amu-field textarea { font-size: 16px; } /* جلوگیری از زوم iOS */
}

@keyframes amuFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes amuIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes amuDot { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  #amu-chatbot * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
