/* ===========================================================
   دردشة الدعم — واجهة مبسّطة، مبنية للجوال أولاً
   بلا إطار هاتف وهمي وبلا زخرفة زائدة.
   =========================================================== */

.mb-chat-stage {
  display: flex;
  justify-content: center;
}

/* الصندوق يبدأ مضغوطاً ثم ينمو مع المحادثة حتى سقف الشاشة، بدل أن
   يفتح فارغاً بارتفاع نصف الصفحة. */
.mb-chat-panel {
  width: 100%;
  max-width: 460px;
  min-height: 340px;
  max-height: 70vh;
  max-height: 70dvh;
  display: flex;
  flex-direction: column;
  background: #161616;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 20px;
  overflow: hidden;
}

/* ------------------------------------------------------ الرأس */

.mb-chat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mb-chat-avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 189, 0, 0.10);
  font-size: 18px;
}

.mb-chat-titles {
  min-width: 0;
}

.mb-chat-titles b {
  display: block;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
}

.mb-chat-titles span {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #8f8f8f;
  font-size: 12.5px;
  line-height: 1.5;
}

.mb-chat-titles span::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #35c46a;
  flex: 0 0 auto;
}

/* -------------------------------------------------- الرسائل */

.mb-chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mb-chat-log::-webkit-scrollbar {
  width: 5px;
}

.mb-chat-log::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

/* يبتلع الفراغ فتستقر الرسائل عند الأسفل قرب صندوق الكتابة — كما في
   تطبيقات المحادثة — بدل أن تعلق في الأعلى وتترك فراغاً كبيراً تحتها.
   ويتقلّص تلقائياً حين تمتلئ المحادثة. */
.mb-chat-spacer {
  flex: 1 1 auto;
  min-height: 0;
}

.mb-msg {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* في الواجهة العربية تُعرض رسائلك أنت على اليسار ورسائل الطرف الآخر
   على اليمين — مثل واتساب وتيليجرام بالعربية. */
.mb-msg-user {
  align-self: flex-end;
  background: var(--mb-accent, #ffbd00);
  color: #000000;
  border-bottom-left-radius: 5px;
}

.mb-msg-bot,
.mb-msg-agent {
  align-self: flex-start;
  background: #242424;
  color: #e8e8e8;
  border-bottom-right-radius: 5px;
}

.mb-msg-agent {
  background: #1c2620;
  border: 1px solid rgba(53, 196, 106, 0.28);
}

.mb-msg-system {
  align-self: center;
  max-width: 92%;
  text-align: center;
  color: #8a8a8a;
  font-size: 12.5px;
  line-height: 1.7;
  padding: 4px 8px;
}

/* شارة تظهر فوق رسائل الموظف البشري فقط — الباقي واضح بلونه */
.mb-msg-who {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #35c46a;
  margin-bottom: 4px;
}

/* مؤشر الكتابة — بجانب رسائل المساعد */
.mb-typing {
  align-self: flex-start;
  display: none;
  gap: 4px;
  padding: 14px 16px;
  background: #242424;
  border-radius: 16px;
  border-bottom-right-radius: 5px;
}

.mb-typing.is-on {
  display: inline-flex;
}

.mb-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8a8a8a;
  animation: mb-blink 1.2s infinite ease-in-out;
}

.mb-typing i:nth-child(2) { animation-delay: 0.18s; }
.mb-typing i:nth-child(3) { animation-delay: 0.36s; }

@keyframes mb-blink {
  0%, 60%, 100% { opacity: 0.25; }
  30%           { opacity: 1; }
}

/* ------------------------------------------- اقتراحات البداية */
/* تظهر قبل أول رسالة فقط ثم تختفي — لا تبقى تزحم الواجهة */

.mb-chat-chips {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 14px 12px;
}

.mb-chat-chips[hidden] {
  display: none;
}

.mb-chat-chips button {
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: transparent;
  color: #c9c9c9;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: 0.15s ease;
}

.mb-chat-chips button:hover {
  border-color: rgba(255, 189, 0, 0.5);
  color: var(--mb-accent, #ffbd00);
}

/* ------------------------------------------------ شريط الكتابة */

.mb-chat-foot {
  flex: 0 0 auto;
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.mb-chat-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.mb-chat-bar textarea {
  flex: 1 1 auto;
  min-height: 46px;
  max-height: 110px;
  padding: 12px 15px;
  border-radius: 23px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #101010;
  color: #ffffff;
  font-family: inherit;
  /* 16px إلزامية: أقل منها يجعل سفاري على iOS يكبّر الصفحة عند اللمس */
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
}

.mb-chat-bar textarea:focus {
  outline: none;
  border-color: rgba(255, 189, 0, 0.5);
}

.mb-chat-send {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--mb-accent, #ffbd00);
  color: #000000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.mb-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.mb-chat-send svg {
  width: 18px;
  height: 18px;
  transform: scaleX(-1);
}

/* زر التحويل — نصّي هادئ، لا يزاحم زر الإرسال */
.mb-chat-handoff {
  display: block;
  width: 100%;
  margin-top: 9px;
  padding: 6px;
  border: 0;
  background: none;
  color: #8f8f8f;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: 0.15s ease;
}

.mb-chat-handoff:hover:not(:disabled) {
  color: #35c46a;
}

.mb-chat-handoff:disabled {
  opacity: 0.5;
  cursor: default;
}

/* -------------------------------------- زر عائم في باقي الصفحات */

.mb-chat-fab {
  position: fixed;
  inset-inline-end: 18px;
  bottom: 18px;
  z-index: 1200;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--mb-accent, #ffbd00);
  color: #000000;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}

.mb-chat-fab svg {
  width: 18px;
  height: 18px;
}

.mb-chat-fab[hidden] {
  display: none;
}

.mb-chat-pop {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.7);
}

.mb-chat-pop.is-open {
  display: flex;
}

.mb-chat-close {
  position: absolute;
  top: 16px;
  inset-inline-start: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.5);
  color: #ffffff;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
}

/* ============================================ الجوال ============ */

@media (max-width: 640px) {

  .mb-chat-panel {
    max-width: none;
    min-height: 320px;
    max-height: 72vh;
    max-height: 72dvh;
    border-radius: 16px;
  }

  .mb-chat-log {
    padding: 14px 12px;
  }

  .mb-msg {
    max-width: 90%;
  }

  .mb-chat-chips {
    padding: 0 12px 10px;
  }

  .mb-chat-foot {
    padding: 10px 12px;
  }

  /* المنبثقة تملأ الشاشة */
  .mb-chat-pop {
    padding: 0;
  }

  .mb-chat-pop .mb-chat-stage {
    width: 100%;
  }

  /* المنبثقة وحدها تملأ الشاشة كاملة */
  .mb-chat-pop .mb-chat-panel {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    max-height: none;
    border-radius: 0;
    border: 0;
  }

  .mb-chat-pop .mb-chat-head {
    padding-inline-start: 58px;
  }

  .mb-chat-close {
    top: 12px;
    inset-inline-start: 12px;
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.07);
  }

  .mb-chat-fab {
    inset-inline-end: 14px;
    bottom: 14px;
  }
}

/* شاشة قصيرة أو لوحة مفاتيح مفتوحة: نُخفي الاقتراحات لتبقى
   الرسائل وصندوق الكتابة ظاهرين */
@media (max-width: 640px) and (max-height: 620px) {
  .mb-chat-panel {
    min-height: 260px;
    max-height: 86vh;
    max-height: 86dvh;
  }

  .mb-chat-chips {
    display: none;
  }
}
