/* ============================================
   مساعد المحمودي v3 — واجهة المحادثة
   ============================================ */
.mah-chat {
  --cb-brand: #5a2f58; --cb-brand-2: #7f4a7c; --cb-ink: #24131f; --cb-muted: #7d6a7b;
  --cb-bg: #f7f2f7; --cb-surface: #ffffff; --cb-line: rgba(90, 47, 88, .12); --cb-dots: #5a2f58;
  --cb-wa: #1fae5b; --cb-ease: cubic-bezier(.2, .8, .2, 1); --cb-spring: cubic-bezier(.3, 1.4, .5, 1);
  position: fixed; bottom: 104px; z-index: 9998; font-family: var(--font, 'Expo Arabic', Tahoma, sans-serif);
}
[dir="rtl"] .mah-chat { right: 30px; }
[dir="ltr"] .mah-chat { left: 30px; }
[data-theme="dark"] .mah-chat {
  --cb-ink: #f3e9f2; --cb-muted: #b9a2b6; --cb-bg: #170d16; --cb-surface: #241422; --cb-line: rgba(255, 255, 255, .09);
}
.mah-chat [hidden] { display: none !important; }

/* ---------- الزر العائم ---------- */
.cb-launch {
  position: relative; width: 62px; height: 62px; border-radius: 50%; border: 0; cursor: pointer; color: #fff;
  background: linear-gradient(145deg, var(--cb-brand-2), var(--cb-brand));
  box-shadow: 0 12px 30px rgba(90, 47, 88, .38), inset 0 1px 0 rgba(255, 255, 255, .25);
  display: grid; place-items: center; transition: transform .35s var(--cb-spring), box-shadow .3s;
}
.cb-launch:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 16px 36px rgba(90, 47, 88, .45); }
.cb-launch:focus-visible { outline: 3px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 6px var(--cb-brand); }
.cb-launch__icon { grid-area: 1 / 1; width: 28px; height: 28px; display: grid; place-items: center; transition: transform .45s var(--cb-spring), opacity .25s; }
.cb-launch__icon svg { width: 100%; height: 100%; }
.cb-launch__icon--chat { --cb-dots: var(--cb-brand); }
.cb-launch__icon--chat svg path { fill: #fff; }
.cb-launch__icon--close { opacity: 0; transform: rotate(-90deg) scale(.6); width: 22px; height: 22px; }
.mah-chat.cb-open .cb-launch__icon--chat { opacity: 0; transform: rotate(90deg) scale(.6); }
.mah-chat.cb-open .cb-launch__icon--close { opacity: 1; transform: none; }
.cb-launch__dot { position: absolute; top: 5px; left: 5px; width: 13px; height: 13px; border-radius: 50%; background: #2bd56f; border: 2.5px solid #fff; }
.cb-launch__dot::after { content: ''; position: absolute; inset: -3px; border-radius: 50%; border: 2px solid #2bd56f; animation: cbPing 2.4s var(--cb-ease) infinite; }
.cb-launch__badge { position: absolute; top: -4px; right: -4px; min-width: 21px; height: 21px; padding: 0 5px; border-radius: 11px; background: #e5383b; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; border: 2px solid #fff; animation: cbPop .5s var(--cb-spring); }
.mah-chat.cb-open .cb-launch__dot, .mah-chat.cb-open .cb-launch__badge { display: none; }
.cb-launch.cb-nudge { animation: cbNudge 1s var(--cb-ease); }
@keyframes cbPing { 0% { transform: scale(1); opacity: .8; } 80%, 100% { transform: scale(2.1); opacity: 0; } }
@keyframes cbPop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes cbNudge { 0%, 100% { transform: none; } 20% { transform: rotate(-10deg) scale(1.06); } 40% { transform: rotate(8deg) scale(1.06); } 60% { transform: rotate(-5deg); } 80% { transform: rotate(3deg); } }

/* ---------- فقاعة الدعوة ---------- */
.cb-teaser {
  position: absolute; bottom: 74px; width: max-content; max-width: 250px;
  display: flex; align-items: center; gap: 10px; padding: 12px 34px 12px 14px; border-radius: 18px;
  background: var(--cb-surface); color: var(--cb-ink); box-shadow: 0 14px 40px rgba(36, 19, 31, .18); border: 1px solid var(--cb-line);
  cursor: pointer; animation: cbTeaseIn .6s var(--cb-spring) both; transform-origin: bottom right;
}
[dir="rtl"] .cb-teaser { padding: 12px 14px 12px 34px; right: 0; }
[dir="ltr"] .cb-teaser { left: 0; }
[dir="ltr"] .cb-teaser { transform-origin: bottom left; }
[dir="rtl"] .cb-teaser::after { right: 24px; }
[dir="ltr"] .cb-teaser::after { left: 24px; }
.cb-teaser::after { content: ''; position: absolute; bottom: -7px; width: 14px; height: 14px; background: var(--cb-surface); border-right: 1px solid var(--cb-line); border-bottom: 1px solid var(--cb-line); transform: rotate(45deg); }
.cb-teaser img { width: 28px; height: 28px; border-radius: 50%; background: #fff; flex-shrink: 0; box-shadow: 0 0 0 2px var(--cb-line); }
.cb-teaser p { margin: 0; font-size: 13.5px; font-weight: 600; line-height: 1.5; }
.cb-teaser__x { position: absolute; top: 6px; inset-inline-start: 8px; width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: var(--cb-muted); font-size: 17px; cursor: pointer; line-height: 1; }
[dir="ltr"] .cb-teaser__x { inset-inline-start: auto; right: 8px; }
[dir="rtl"] .cb-teaser__x { left: 8px; right: auto; }
.cb-teaser__x:hover { background: var(--cb-bg); color: var(--cb-ink); }
.cb-teaser.cb-out { animation: cbTeaseOut .3s var(--cb-ease) forwards; }
@keyframes cbTeaseIn { from { opacity: 0; transform: translateY(14px) scale(.85); } to { opacity: 1; transform: none; } }
@keyframes cbTeaseOut { to { opacity: 0; transform: translateY(8px) scale(.92); } }

/* ---------- اللوحة ---------- */
.cb-panel {
  position: absolute; bottom: 76px; width: 390px; height: min(640px, calc(100vh - 200px));
  display: flex; flex-direction: column; overflow: hidden; border-radius: 26px;
  background: var(--cb-bg); box-shadow: 0 30px 80px rgba(36, 19, 31, .28), 0 0 0 1px var(--cb-line);
  transform-origin: bottom right; animation: cbOpen .5s var(--cb-spring) both;
}
[dir="rtl"] .cb-panel { right: 0; }
[dir="ltr"] .cb-panel { left: 0; transform-origin: bottom left; }
.cb-panel.cb-closing { animation: cbClose .25s var(--cb-ease) forwards; }
@keyframes cbOpen { from { opacity: 0; transform: translateY(24px) scale(.88); } to { opacity: 1; transform: none; } }
@keyframes cbClose { to { opacity: 0; transform: translateY(16px) scale(.94); } }

.cb-head {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 16px 16px 16px 14px; color: #fff; flex-shrink: 0;
  background: radial-gradient(120% 140% at 0% 0%, rgba(255, 255, 255, .18), transparent 50%), linear-gradient(135deg, var(--cb-brand-2), var(--cb-brand) 60%, #3d1e3b);
}
.cb-head::after { content: ''; position: absolute; inset: auto 0 -1px; height: 18px; background: var(--cb-bg); border-radius: 18px 18px 0 0; }
.cb-head__ava { position: relative; width: 46px; height: 46px; border-radius: 50%; background: #fff; display: grid; place-items: center; flex-shrink: 0; box-shadow: 0 6px 16px rgba(0, 0, 0, .18); }
.cb-head__ava img { width: 32px; height: 32px; object-fit: contain; }
.cb-head__ava i { position: absolute; bottom: 1px; inset-inline-end: 1px; width: 12px; height: 12px; border-radius: 50%; background: #2bd56f; border: 2px solid #fff; }
.cb-head__txt { flex: 1; min-width: 0; display: flex; flex-direction: column; margin-bottom: 8px; }
.cb-head__txt strong { font-size: 16px; font-weight: 800; letter-spacing: -.2px; }
.cb-head__txt span { font-size: 12px; opacity: .85; }
.cb-head__btn { width: 36px; height: 36px; border: 0; border-radius: 12px; background: rgba(255, 255, 255, .12); color: #fff; cursor: pointer; display: grid; place-items: center; margin-bottom: 8px; transition: background .2s; }
.cb-head__btn:hover { background: rgba(255, 255, 255, .24); }
.cb-head__btn svg { width: 18px; height: 18px; }

/* ---------- المحادثة ---------- */
.cb-body { flex: 1; overflow-y: auto; padding: 8px 14px 14px; display: flex; flex-direction: column; gap: 8px; scroll-behavior: smooth; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(90, 47, 88, .2) transparent; }
.cb-row { display: flex; gap: 8px; align-items: flex-end; animation: cbIn .38s var(--cb-ease) both; }
.cb-row.cb-user { flex-direction: row-reverse; }
.cb-row .cb-av { width: 28px; height: 28px; border-radius: 50%; background: #fff; display: grid; place-items: center; flex-shrink: 0; box-shadow: 0 0 0 1px var(--cb-line); }
.cb-row .cb-av img { width: 20px; height: 20px; }
.cb-row .cb-av.cb-ghost { visibility: hidden; }
.cb-bubble {
  max-width: 84%; padding: 10px 14px; border-radius: 18px; font-size: 14px; line-height: 1.75; color: var(--cb-ink);
  background: var(--cb-surface); box-shadow: 0 1px 2px rgba(36, 19, 31, .06), 0 0 0 1px var(--cb-line); white-space: pre-wrap; word-wrap: break-word;
}
.cb-bot .cb-bubble { border-end-start-radius: 6px; }
.cb-user .cb-bubble { background: linear-gradient(135deg, var(--cb-brand-2), var(--cb-brand)); color: #fff; box-shadow: 0 6px 16px rgba(90, 47, 88, .22); border-end-end-radius: 6px; }
.cb-bubble a { color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.cb-stack { display: flex; flex-direction: column; gap: 8px; max-width: calc(100% - 36px); width: 100%; }
@keyframes cbIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.cb-typing { display: inline-flex; gap: 4px; padding: 13px 16px; }
.cb-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--cb-brand-2); opacity: .5; animation: cbDot 1.1s infinite; }
.cb-typing span:nth-child(2) { animation-delay: .15s; } .cb-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes cbDot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-5px); opacity: 1; } }

/* المربعات (اختيار الخدمة) */
.cb-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cb-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; text-align: start; cursor: pointer; font: inherit;
  border: 0; border-radius: 16px; background: var(--cb-surface); color: var(--cb-ink); box-shadow: 0 0 0 1px var(--cb-line);
  transition: transform .3s var(--cb-spring), box-shadow .3s; animation: cbIn .4s var(--cb-ease) both; animation-delay: calc(var(--i) * 60ms);
}
.cb-tile:hover { transform: translateY(-3px); box-shadow: 0 0 0 1.5px var(--cb-brand), 0 10px 22px rgba(90, 47, 88, .14); }
.cb-tile i { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 15px; color: var(--cb-brand); background: rgba(90, 47, 88, .08); }
[data-theme="dark"] .cb-tile i { color: #e2c4df; background: rgba(255, 255, 255, .08); }
.cb-tile span { font-size: 13.5px; font-weight: 700; line-height: 1.35; }
.cb-tiles.cb-many { grid-template-columns: 1fr; }
.cb-tiles.cb-many .cb-tile { flex-direction: row; align-items: center; padding: 9px 12px; }
.cb-tiles.cb-many .cb-tile i { width: 30px; height: 30px; font-size: 13px; }

/* بطاقات الأعمال */
.cb-cards { display: grid; grid-auto-flow: column; grid-auto-columns: 168px; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px 2px 8px; margin-inline: -2px; scrollbar-width: none; }
.cb-cards::-webkit-scrollbar { display: none; }
.cb-card {
  scroll-snap-align: start; display: flex; flex-direction: column; border-radius: 16px; overflow: hidden; text-decoration: none;
  background: var(--cb-surface); color: var(--cb-ink); box-shadow: 0 0 0 1px var(--cb-line); transition: transform .35s var(--cb-spring), box-shadow .3s;
  animation: cbIn .45s var(--cb-ease) both; animation-delay: calc(var(--i) * 70ms);
}
.cb-card:hover { transform: translateY(-4px); box-shadow: 0 0 0 1px var(--cb-line), 0 14px 28px rgba(36, 19, 31, .16); }
.cb-card__img { position: relative; height: 118px; background: var(--cb-bg); overflow: hidden; }
.cb-card.cb-tall .cb-card__img { height: 150px; }
.cb-card__img img { width: 100%; height: 100%; object-fit: cover; object-position: top; transition: transform .8s var(--cb-ease); }
.cb-card:hover .cb-card__img img { transform: scale(1.05); }
.cb-card__badge { position: absolute; top: 8px; inset-inline-start: 8px; padding: 3px 9px; border-radius: 20px; font-size: 10.5px; font-weight: 700; background: rgba(36, 19, 31, .75); color: #fff; backdrop-filter: blur(4px); }
.cb-card__body { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 2px; }
.cb-card__body strong { font-size: 13px; font-weight: 800; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cb-card__body small { font-size: 11px; color: var(--cb-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* رابط */
.cb-link { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 12px; font-size: 13px; font-weight: 700; text-decoration: none; color: var(--cb-brand); background: rgba(90, 47, 88, .08); transition: background .2s; }
[data-theme="dark"] .cb-link { color: #e2c4df; background: rgba(255, 255, 255, .08); }
.cb-link:hover { background: rgba(90, 47, 88, .15); }

/* الأزرار السريعة */
.cb-quick { display: flex; flex-wrap: wrap; gap: 6px; padding-inline-start: 36px; margin-top: 2px; }
.cb-chip {
  border: 1px solid rgba(90, 47, 88, .28); background: var(--cb-surface); color: var(--cb-brand); font: inherit; font-size: 13px; font-weight: 700;
  padding: 7px 13px; border-radius: 20px; cursor: pointer; transition: background .2s, color .2s, transform .3s var(--cb-spring);
  animation: cbIn .35s var(--cb-ease) both; animation-delay: calc(var(--i) * 50ms);
}
[data-theme="dark"] .cb-chip { color: #e2c4df; border-color: rgba(255, 255, 255, .18); }
.cb-chip:hover { background: var(--cb-brand); color: #fff; transform: translateY(-2px); }

/* واتساب */
.cb-wa {
  display: flex; align-items: center; justify-content: center; gap: 9px; padding: 12px 16px; border-radius: 14px; text-decoration: none;
  font-size: 14px; font-weight: 800; color: #fff; background: linear-gradient(135deg, #2bd56f, var(--cb-wa)); box-shadow: 0 8px 20px rgba(31, 174, 91, .3);
  animation: cbIn .4s var(--cb-ease) both; margin-inline-start: 36px; transition: transform .3s var(--cb-spring);
}
.cb-wa:hover { transform: translateY(-2px); }
.cb-wa i { font-size: 18px; }

/* نموذج العميل */
.cb-lead { margin-inline-start: 36px; padding: 14px; border-radius: 18px; background: var(--cb-surface); box-shadow: 0 0 0 1.5px rgba(90, 47, 88, .22), 0 10px 26px rgba(90, 47, 88, .1); display: flex; flex-direction: column; gap: 8px; animation: cbIn .45s var(--cb-ease) both; }
.cb-lead label { font-size: 12px; font-weight: 700; color: var(--cb-muted); }
.cb-lead input { width: 100%; border: 1px solid var(--cb-line); border-radius: 12px; padding: 10px 12px; font: inherit; font-size: 14px; background: var(--cb-bg); color: var(--cb-ink); outline: none; transition: border-color .2s, box-shadow .2s; }
.cb-lead input:focus { border-color: var(--cb-brand); box-shadow: 0 0 0 3px rgba(90, 47, 88, .12); }
.cb-lead input.cb-bad { border-color: #e5383b; box-shadow: 0 0 0 3px rgba(229, 56, 59, .12); }
.cb-lead button { margin-top: 4px; border: 0; border-radius: 12px; padding: 12px; font: inherit; font-size: 14px; font-weight: 800; color: #fff; cursor: pointer; background: linear-gradient(135deg, var(--cb-brand-2), var(--cb-brand)); transition: transform .3s var(--cb-spring); }
.cb-lead button:hover { transform: translateY(-2px); }
.cb-lead small { font-size: 11.5px; color: var(--cb-muted); display: flex; align-items: center; gap: 5px; }
.cb-lead.cb-sent { opacity: .55; pointer-events: none; }

/* ---------- الإدخال ---------- */
.cb-input { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; margin: 0 10px; border-radius: 18px; background: var(--cb-surface); box-shadow: 0 0 0 1px var(--cb-line), 0 6px 18px rgba(36, 19, 31, .06); flex-shrink: 0; }
.cb-input textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--cb-ink); font: inherit; font-size: 14.5px; line-height: 1.5; max-height: 110px; padding: 6px 4px; }
.cb-input textarea::placeholder { color: var(--cb-muted); }
.cb-send { width: 40px; height: 40px; border: 0; border-radius: 13px; flex-shrink: 0; cursor: pointer; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--cb-brand-2), var(--cb-brand)); transition: transform .3s var(--cb-spring), opacity .2s; }
.cb-send svg { width: 19px; height: 19px; }
[dir="rtl"] .cb-send svg { transform: scaleX(-1); }
.cb-send:disabled { opacity: .35; cursor: default; }
.cb-send:not(:disabled):hover { transform: scale(1.06); }
.cb-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.cb-foot { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 12px 11px; font-size: 12px; font-weight: 600; color: var(--cb-muted); text-decoration: none; flex-shrink: 0; }
.cb-foot i { color: var(--cb-wa); font-size: 14px; }
.cb-foot:hover { color: var(--cb-ink); }

/* ---------- الجوال: شاشة كاملة ---------- */
@media (max-width: 600px) {
  .mah-chat { bottom: 92px; }
  [dir="rtl"] .mah-chat { right: 16px; }
  [dir="ltr"] .mah-chat { left: 16px; }
  .cb-launch { width: 56px; height: 56px; }
  .cb-panel { position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh; border-radius: 0; animation-name: cbSheet; }
  .cb-head { padding-top: calc(14px + env(safe-area-inset-top)); }
  .cb-input { margin-bottom: 2px; }
  .cb-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .mah-chat.cb-open .cb-launch, .mah-chat.cb-open .cb-teaser { display: none; }
  .cb-teaser { max-width: calc(100vw - 110px); }
  @keyframes cbSheet { from { transform: translateY(100%); } to { transform: none; } }
}
html.cb-lock, html.cb-lock body { overflow: hidden !important; }

@media (prefers-reduced-motion: reduce) {
  .mah-chat *, .mah-chat *::before, .mah-chat *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* أثناء فتح المساعد على الجوال: نخفي الأزرار العائمة الأخرى ونرفع المساعد فوق كل شيء */
@media (max-width: 600px) {
  .mah-chat.cb-open { z-index: 2147483000; }
  html.cb-lock #smartWaContainer, html.cb-lock .scroll-top, html.cb-lock #scrollTop, html.cb-lock .cookie-banner { display: none !important; }
}
