/* مساعد الموقع: الزر العائم ونافذة الدردشة */

.ai-fab[hidden], .ai-hint[hidden], .ai-panel[hidden], .ai-mic[hidden] { display: none !important; }

/* الزر العائم: حبة فيها نجمة الذكاء وكلمة المساعد الذكي وحلقة ألوان تدور حوله
   مكانه جنب زر الواتساب في نفس السطر */
@property --ai-a { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
.ai-fab {
  position: fixed; right: 96px; bottom: 24px; z-index: 51;
  height: 56px; padding: 0; padding-inline: 7px 16px; border-radius: 99px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 10px;
  font: inherit; font-size: 15px; font-weight: 700; color: #fff; white-space: nowrap;
  border: 2px solid transparent;
  background:
    linear-gradient(150deg, #4C1286, #2A0042 75%) padding-box,
    conic-gradient(from var(--ai-a), #02C8F0, #8B5CF6, #FFF200, #02C8F0) border-box;
  box-shadow: 0 10px 28px rgba(42, 0, 66, .5), 0 0 20px rgba(2, 200, 240, .22);
  opacity: 0; transform: translateY(10px) scale(.92);
  transition: opacity .35s, transform .35s;
}
.ai-fab.in { opacity: 1; transform: none; }

/* بعد تجاوز الواجهة يصغر الزر إلى دائرة فوق زر الواتساب حتى لا يغطي البطاقات والنصوص */
.ai-fab.compact { right: 24px; bottom: 94px; width: 56px; padding: 0; justify-content: center; }
.ai-fab.compact .ai-fab-t, .ai-fab.compact .ai-badge { display: none; }
.ai-fab.compact ~ .ai-hint { right: 22px; bottom: 164px; }
.ai-fab:hover { transform: translateY(-2px); }
.ai-fab-ic { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 35% 30%, rgba(2, 200, 240, .35), rgba(2, 200, 240, .08) 70%); }
.ai-fab svg, .ai-avatar svg { width: 26px; height: 26px; overflow: visible; }
.ai-fab svg path, .ai-avatar svg path { stroke: none; }
.ai-fab svg .s1, .ai-avatar svg .s1 { fill: #fff; }
.ai-fab svg .s2, .ai-avatar svg .s2 { fill: #FFF200; }
.ai-fab svg .s3, .ai-avatar svg .s3 { fill: #02C8F0; }
.ai-badge {
  font: 800 11px/1 var(--sans); letter-spacing: .6px; padding: 4px 6px 3px; border-radius: 6px;
  color: #2A0042; background: linear-gradient(135deg, #FFF200, #02C8F0);
}
@media (prefers-reduced-motion: no-preference) {
  .ai-fab { animation: ai-spin 4s linear infinite, ai-glow 3.2s ease-in-out infinite; }
  .ai-fab svg .s1 { transform-origin: 10px 9.8px; animation: ai-breath 3.2s ease-in-out infinite; }
  .ai-fab svg .s2 { transform-origin: 17.6px 16.7px; animation: ai-twinkle 2.4s ease-in-out infinite; }
  .ai-fab svg .s3 { transform-origin: 18.2px 5px; animation: ai-twinkle 2.4s 1.2s ease-in-out infinite; }
  .ai-fab.nudge { animation: ai-spin 4s linear infinite, ai-nudge 1.2s ease-in-out; }
}
@keyframes ai-spin { to { --ai-a: 360deg; } }
@keyframes ai-glow { 50% { box-shadow: 0 10px 28px rgba(42, 0, 66, .5), 0 0 32px rgba(139, 92, 246, .5); } }
@keyframes ai-breath { 50% { transform: scale(.86) rotate(12deg); } }
@keyframes ai-twinkle { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.35); opacity: .4; } }
@keyframes ai-nudge { 0%, 100% { transform: none; } 20% { transform: translateY(-7px); } 40% { transform: none; } 60% { transform: translateY(-4px); } 80% { transform: none; } }

.ai-hint {
  position: fixed; right: 96px; bottom: 94px; z-index: 51; width: max-content; max-width: min(340px, calc(100vw - 24px)); min-height: 44px; cursor: pointer; box-sizing: border-box;
  padding: 11px 15px; border-radius: 16px; font-size: 14.5px; line-height: 1.65;
  background: var(--surface); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: var(--shadow), 0 0 0 4px color-mix(in srgb, var(--accent) 8%, transparent);
  opacity: 0; transform: translateY(6px); transition: opacity .3s, transform .3s;
}
.ai-hint.in { opacity: 1; transform: none; }
.ai-hint::after {
  content: ''; position: absolute; right: calc(var(--ax, 36px) - 6px); bottom: -6px; width: 11px; height: 11px;
  background: var(--surface); border-right: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); transform: rotate(45deg);
}

.ai-panel {
  position: fixed; right: 22px; bottom: 22px; z-index: 56;
  width: 392px; height: min(640px, calc(100dvh - 120px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 30px 70px rgba(10, 0, 20, .45), 0 0 0 1px rgba(2, 200, 240, .05);
  opacity: 0; transform: translateY(14px) scale(.98); transform-origin: bottom right;
  transition: opacity .22s, transform .22s;
}
.ai-panel.in { opacity: 1; transform: none; }
.ai-panel button { font: inherit; }

.ai-head { display: flex; align-items: center; gap: 11px; padding: 13px 12px 13px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.ai-panel[dir="rtl"] .ai-head { padding: 13px 16px 13px 12px; }
.ai-avatar { width: 40px; height: 40px; flex: none; border-radius: 13px; display: grid; place-items: center; color: #02C8F0; background: linear-gradient(150deg, #561C8C, #3A0057 70%); }
.ai-avatar svg { width: 24px; height: 24px; }
.ai-id { flex: 1; min-width: 0; line-height: 1.35; }
.ai-id strong { display: block; font-size: 16px; }
.ai-id small { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.ai-id small::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #3ddc84; box-shadow: 0 0 0 3px rgba(61, 220, 132, .16); flex: none; }

.ai-ic {
  width: 40px; height: 40px; flex: none; border-radius: 12px; border: 0; padding: 0; cursor: pointer;
  display: grid; place-items: center; background: transparent; color: var(--muted); transition: background .15s, color .15s;
}
.ai-ic:hover { background: var(--bg-2); color: var(--text); }
.ai-head .ai-ic:hover { background: var(--surface); }
.ai-ic svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.ai-log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.ai-msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.8; overflow-wrap: anywhere; }
.ai-msg p { margin: 0; }
.ai-msg p + p, .ai-msg p + ul, .ai-msg ul + p { margin-top: 6px; }
.ai-msg ul { margin: 4px 0 0; padding-inline-start: 18px; }
.ai-msg li + li { margin-top: 2px; }
.ai-msg strong { font-weight: 700; }
.ai-msg.bot { align-self: flex-start; background: var(--bg-2); border: 1px solid var(--line); border-start-start-radius: 6px; }
.ai-msg.me { align-self: flex-end; background: var(--brand); color: #fff; border-start-end-radius: 6px; }
.ai-msg.err { border-color: rgba(255, 200, 0, .35); }
:root[lang="en"] .ai-msg { line-height: 1.6; }

.ai-chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 2px 0 4px; }
.ai-chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
  padding: 7px 13px; border-radius: 99px; font-size: 14px; line-height: 1.4; transition: border-color .15s, color .15s;
}
.ai-chip:hover { border-color: var(--accent); color: var(--accent); }

.ai-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ai-act {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: 11px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; line-height: 1.3; text-decoration: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); transition: border-color .15s;
}
.ai-act:hover { border-color: var(--accent); }
.ai-act svg { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--accent); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ai-act.main { background: var(--brand); color: #fff; border-color: transparent; }
.ai-act.main svg { stroke: #02C8F0; }

.ai-play {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; margin-top: 6px; margin-inline-start: -6px;
  border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; padding: 0;
}
.ai-play:hover { color: var(--accent); background: var(--surface); }
.ai-play svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ai-play.on { color: var(--accent); }
.ai-panel[dir="rtl"] .ai-play svg { transform: scaleX(-1); }

.ai-dots { display: inline-flex; gap: 4px; padding: 6px 0; }
.ai-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .4; animation: ai-dot 1.1s infinite; }
.ai-dots i:nth-child(2) { animation-delay: .15s; } .ai-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes ai-dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.ai-form { display: flex; align-items: flex-end; gap: 6px; padding: 10px 10px 8px; border-top: 1px solid var(--line); }
.ai-form textarea {
  flex: 1; min-width: 0; resize: none; max-height: 120px; padding: 9px 13px; border-radius: 14px;
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line); font: inherit; font-size: 15px; line-height: 1.55;
  outline: none; transition: border-color .15s; overflow-y: hidden;
}
.ai-form textarea:focus { border-color: var(--accent); }
.ai-form textarea::placeholder { color: var(--muted); opacity: .8; }
.ai-form.rec textarea { border-color: #FFF200; }
.ai-send { background: var(--accent); color: #12051C; }
.ai-send:hover { background: var(--accent); color: #12051C; filter: brightness(1.08); }
:root[data-theme="light"] .ai-send, :root[data-theme="light"] .ai-send:hover { color: #fff; }
.ai-send.stop { background: var(--bg-2); color: var(--text); }
.ai-panel[dir="rtl"] .ai-send:not(.stop) svg { transform: scaleX(-1); }
.ai-mic.on { color: #12051C; background: #FFF200; position: relative; }
.ai-mic.on::after { content: ''; position: absolute; inset: -3px; border-radius: 14px; border: 2px solid #FFF200; opacity: 0; animation: ai-ring 1.3s infinite; }
@keyframes ai-ring { 0% { opacity: .7; transform: scale(.95); } 100% { opacity: 0; transform: scale(1.25); } }
.ai-mic.wait { color: var(--accent); }
.ai-mic.wait svg { animation: ai-blink 1s infinite; }
@keyframes ai-blink { 50% { opacity: .35; } }

/* شريط التمرير في المحادثة وخانة الكتابة: رفيع بتدرج ألوان الهوية وبدون أسهم */
.ai-log::-webkit-scrollbar, .ai-form textarea::-webkit-scrollbar { width: 8px; }
.ai-log::-webkit-scrollbar-button, .ai-form textarea::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
.ai-log::-webkit-scrollbar-track, .ai-form textarea::-webkit-scrollbar-track { background: transparent; margin-block: 8px; }
.ai-log::-webkit-scrollbar-thumb, .ai-form textarea::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #02C8F0, #8b5cf6) padding-box; border-radius: 99px; border: 2px solid transparent;
}
.ai-log::-webkit-scrollbar-corner, .ai-form textarea::-webkit-scrollbar-corner { background: transparent; }
@supports not selector(::-webkit-scrollbar) {
  .ai-log, .ai-form textarea { scrollbar-width: thin; scrollbar-color: #8b5cf6 transparent; }
}

.ai-note { margin: 0; padding: 0 14px 10px; font-size: 11.5px; line-height: 1.5; color: var(--muted); text-align: center; opacity: .85; }
.ai-toast { margin: 0 12px 8px; padding: 8px 12px; border-radius: 11px; font-size: 13px; line-height: 1.6; background: var(--bg-2); border: 1px solid var(--line); color: var(--text); }

/* مساحة تحت الفوتر عشان الزرين العائمين ما يغطون الشعار والروابط في آخر الصفحة */
:root.ai-ready .foot { padding-bottom: 104px; }

/* الأجهزة التي تعمل باللمس الأوسع من الجوال مثل الجوال بالعرض والآيباد: الزران جنب بعض أيضا */
@media (min-width: 561px) and (hover: none) and (pointer: coarse) {
  .ai-fab.compact { right: 94px; bottom: 24px; }
  .ai-fab.compact ~ .ai-hint { right: 96px; bottom: 94px; }
}
/* الشاشات الواسعة: الفوتر بعيد عن الزرين فلا يحتاج مساحة إضافية تحته */
@media (min-width: 1280px) { :root.ai-ready .foot { padding-bottom: 26px; } }

/* الجوال: النافذة تاخذ الشاشة كاملة */
@media (max-width: 560px) {
  .ai-fab { right: 82px; bottom: 16px; width: 54px; height: 54px; padding: 0; justify-content: center; }
  .ai-fab-t { display: none; }
  .ai-fab-ic { width: 46px; height: 46px; }
  .ai-badge { position: absolute; top: -7px; left: -7px; box-shadow: 0 0 0 2px #2A0042; }
  /* في الجوال يبقى الزران جنب بعض دائما وبأي مقاس */
  .ai-fab.compact { right: 82px; bottom: 16px; width: 54px; }
  .ai-panel { inset: 0; right: 0; bottom: 0; width: 100%; height: 100dvh; border-radius: 0; border: 0; padding-bottom: env(safe-area-inset-bottom); }
  .ai-form textarea { font-size: 16px; }
  :root.ai-ready .foot { padding-bottom: 42px; }
  :root.ai-on, :root.ai-on body { overflow: hidden; }
  :root.ai-on .wa-float { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-fab, .ai-panel, .ai-hint { transition: none; animation: none; }
  .ai-dots i, .ai-mic.on::after, .ai-mic.wait svg { animation: none; }
}
