/* =========================================================
   AI CHAT FLOATING BUTTON
========================================================= */

.ai-chat-trigger {
  position: fixed;

  right: 22px;
  bottom: 141px;

  width: 122px;

  padding: 0;

  border: 0;
  outline: 0;

  background: transparent !important;

  display: flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;

  z-index: 1044;

  overflow: visible;

  filter:
    drop-shadow(0 10px 15px rgba(0, 0, 0, .18));

  transition:
    transform .25s ease,
    filter .25s ease;
}


/* =========================================================
   FLOATING CHARACTER IMAGE
========================================================= */

.ai-chat-trigger-icon {
  position: relative;

  z-index: 2;

  width: 130px;

  padding: 0;

  margin: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  background: transparent !important;

  border: 0;

  border-radius: 50%;


}


.ai-chat-trigger-icon img {
  width: 100%;
  height: 100%;

  display: block;

  object-fit: cover;

  /*
     * الصورة الأصلية فيها مساحة حول الرسم.
     * التكبير يجعل الشخصية أوضح.
     */
  transform: scale(1.13);

  transform-origin: center;

  pointer-events: none;
}


/* =========================================================
   HOVER
========================================================= */

.ai-chat-trigger:hover {
  transform:
    translateY(-4px) scale(1.05);

  filter:
    drop-shadow(0 15px 20px rgba(0, 0, 0, .24));
}


/* =========================================================
   ONLINE DOT
========================================================= */

.ai-chat-trigger-status {
  position: absolute;

  right: 2px;
  top: 5px;

  width: 15px;
  height: 15px;

  border: 3px solid #fff;

  border-radius: 50%;

  background: #22c55e;

  z-index: 5;

  box-shadow:
    0 2px 7px rgba(0, 0, 0, .18);
}


/* =========================================================
   PULSE
========================================================= */

.ai-chat-trigger-glow {
  position: absolute;

  inset: 4px;

  border-radius: 50%;

  background:
    rgba(17, 24, 39, .14);

  z-index: -1;

  animation:
    aiChatPulse 2.2s infinite;
}


@keyframes aiChatPulse {

  0% {
    transform: scale(.92);
    opacity: .45;
  }

  70% {
    transform: scale(1.35);
    opacity: 0;
  }

  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}


/* =========================================================
   OFFCANVAS
========================================================= */

.ai-chat-canvas {
  width: 430px !important;
  max-width: 100vw;

  border: 0 !important;

  background: #f8f9fb;

  display: flex;
  flex-direction: column;

  overflow: hidden;
}


/* =========================================================
   HEADER
========================================================= */

.ai-chat-header {
  height: 82px;
  min-height: 82px;

  padding: 0 20px;

  display: flex;
  align-items: center;
  justify-content: space-between;

  flex: 0 0 auto;

  background: #fff;

  border-bottom:
    1px solid #edf0f4;
}


.ai-chat-header-info {
  min-width: 0;

  display: flex;
  align-items: center;

  gap: 12px;
}


/* =========================================================
   HEADER AI IMAGE
========================================================= */

.ai-chat-avatar {
  position: relative;

  width: 52px;
  height: 52px;

  flex: 0 0 52px;

  padding: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  background: transparent;

  border-radius: 50%;

  overflow: visible;
}


.ai-chat-avatar>img {
  width: 52px;
  height: 52px;

  display: block;

  object-fit: cover;

  border-radius: 50%;

  transform: scale(1.08);

  filter:
    drop-shadow(0 5px 8px rgba(0, 0, 0, .15));
}


/* =========================================================
   HEADER ONLINE
========================================================= */

.ai-chat-online {
  position: absolute;

  right: -1px;
  bottom: 1px;

  width: 12px;
  height: 12px;

  background: #22c55e;

  border:
    2px solid #fff;

  border-radius: 50%;

  z-index: 3;
}


/* =========================================================
   HEADER TEXT
========================================================= */

.ai-chat-header-text {
  min-width: 0;
}


.ai-chat-header-text h5 {
  margin: 0 0 3px;

  color: #111827;

  font-size: 15px;
  font-weight: 800;

  white-space: nowrap;

  overflow: hidden;

  text-overflow: ellipsis;
}


.ai-chat-header-text>span {
  display: flex;
  align-items: center;

  gap: 5px;

  color: #6b7280;

  font-size: 11px;
}


.ai-chat-header-text>span>i {
  color: #22c55e;

  font-size: 6px;
}


/* =========================================================
   CLOSE
========================================================= */

.ai-chat-close {
  width: 38px;
  height: 38px;

  flex: 0 0 38px;

  padding: 0;

  border: 0;

  border-radius: 12px;

  background: #f3f4f6;

  color: #4b5563;

  display: flex;
  align-items: center;
  justify-content: center;

  font-size: 18px;

  transition: .2s ease;
}


.ai-chat-close:hover {
  background: #e5e7eb;

  color: #111827;
}


/* =========================================================
   MESSAGES CONTAINER
========================================================= */

.ai-chat-messages {
  flex: 1 1 auto;

  min-height: 0;

  width: 100%;

  max-width: 100%;

  padding: 24px 18px 30px;

  overflow-x: hidden;
  overflow-y: auto;

  direction: rtl;

  box-sizing: border-box;
}


/* =========================================================
   WELCOME
========================================================= */

.ai-welcome {
  width: 100%;

  padding: 20px 20px 25px;

  text-align: center;

  box-sizing: border-box;
}


/* =========================================================
   WELCOME AI IMAGE
========================================================= */

.ai-welcome-icon {
  width: 88px;
  height: 88px;

  margin: 0 auto 12px;

  display: flex;
  align-items: center;
  justify-content: center;

  border: 0;

  border-radius: 50%;

  background: transparent;

  overflow: hidden;

  filter:
    drop-shadow(0 8px 14px rgba(0, 0, 0, .14));
}


.ai-welcome-icon img {
  width: 100%;
  height: 100%;

  display: block;

  object-fit: cover;

  transform: scale(1.12);
}


.ai-welcome h4 {
  margin-bottom: 8px;

  color: #111827;

  font-size: 18px;
  font-weight: 800;
}


.ai-welcome p {
  margin-bottom: 5px;

  color: #4b5563;

  font-size: 14px;
}


.ai-welcome small {
  color: #9ca3af;

  font-size: 11px;
}


/* =========================================================
   MESSAGE
========================================================= */

.ai-message {
  width: 100%;

  max-width: 100%;

  margin-bottom: 15px;

  display: flex;
  align-items: flex-start;

  gap: 9px;

  box-sizing: border-box;
}


/* =========================================================
   BOT AVATAR
========================================================= */

.ai-message-avatar {
  width: 34px;
  height: 34px;

  flex: 0 0 34px;

  padding: 0;

  border-radius: 50%;

  background: transparent;

  display: flex;
  align-items: center;
  justify-content: center;

  overflow: hidden;
}


.ai-message-avatar img {
  width: 100%;
  height: 100%;

  display: block;

  object-fit: cover;

  transform: scale(1.10);
}


/* =========================================================
   MESSAGE CONTENT
========================================================= */

.ai-message-content {
  min-width: 0;

  max-width: calc(100% - 45px);

  padding: 11px 14px;

  border-radius:
    5px 16px 16px 16px;

  background: #fff;

  color: #374151;

  font-size: 13px;

  line-height: 1.8;

  box-shadow:
    0 3px 15px rgba(0, 0, 0, .04);

  overflow-wrap: anywhere;

  word-break: break-word;

  box-sizing: border-box;
}


/* =========================================================
   USER MESSAGE
========================================================= */

.ai-message-user {
  justify-content: flex-start;
}


.ai-message-user .ai-message-content {
  max-width: 82%;

  border-radius:
    16px 5px 16px 16px;

  background: #fff;

  overflow: hidden;
}


/* =========================================================
   MOST IMPORTANT FIX:
   USER UPLOADED IMAGE INSIDE MESSAGE
========================================================= */

.ai-message-image {
  display: block;

  width: auto;

  max-width: 100% !important;

  height: auto !important;

  max-height: 320px;

  margin: 0 auto;

  border-radius: 12px;

  object-fit: contain;

  object-position: center;

  box-sizing: border-box;
}


/*
 * لو الصورة وحدها في الرسالة
 */

.ai-user-content>.ai-message-image:first-child {
  margin-top: 0;
}


/*
 * نص أسفل الصورة
 */

.ai-user-content .ai-message-image+.ai-message-text {
  margin-top: 9px;
}


/* =========================================================
   EXTRA IMAGE PROTECTION
========================================================= */

.ai-message-content img {
  max-width: 100%;

  height: auto;
}


.ai-chat-messages img {
  max-width: 100%;

  box-sizing: border-box;
}


/* =========================================================
   IMAGE PREVIEW BEFORE SEND
========================================================= */

.ai-upload-preview {
  position: relative;

  width: 100%;

  padding: 10px 18px 0;

  flex: 0 0 auto;

  background: #fff;

  box-sizing: border-box;
}


.ai-upload-image {
  width: 70px;
  height: 70px;

  overflow: hidden;

  border:
    1px solid #e5e7eb;

  border-radius: 12px;

  background: #f8f9fa;
}


.ai-upload-image img {
  width: 100%;
  height: 100%;

  display: block;

  object-fit: contain;
}


.ai-upload-preview>button {
  position: absolute;

  top: 5px;
  right: 73px;

  width: 24px;
  height: 24px;

  padding: 0;

  border: 0;

  border-radius: 50%;

  background: #111827;

  color: #fff;

  display: flex;
  align-items: center;
  justify-content: center;

  font-size: 10px;

  z-index: 2;
}


/* =========================================================
   FOOTER
========================================================= */

.ai-chat-footer {
  width: 100%;

  flex: 0 0 auto;

  padding: 12px 14px 10px;

  background: #fff;

  border-top:
    1px solid #edf0f4;

  box-sizing: border-box;
}


.ai-chat-input-box {
  width: 100%;

  min-height: 54px;

  padding: 6px;

  display: flex;
  align-items: flex-end;

  gap: 4px;

  border:
    1px solid #e5e7eb;

  border-radius: 18px;

  background: #f9fafb;

  transition: .2s ease;

  box-sizing: border-box;
}


.ai-chat-input-box:focus-within {
  background: #fff;

  border-color: #cbd5e1;

  box-shadow:
    0 0 0 3px rgba(17, 24, 39, .04);
}


/* =========================================================
   TEXTAREA
========================================================= */

.ai-chat-input-box textarea {
  flex: 1;

  min-width: 0;

  height: 40px;

  max-height: 110px;

  padding: 9px 6px;

  border: 0;
  outline: 0;

  resize: none;

  background: transparent;

  color: #111827;

  font-size: 13px;

  line-height: 21px;

  overflow-y: auto;
}


.ai-chat-input-box textarea::placeholder {
  color: #9ca3af;
}


/* =========================================================
   IMAGE / VOICE BUTTON
========================================================= */

.ai-input-action {
  width: 40px;
  height: 40px;

  flex: 0 0 40px;

  padding: 0;

  border: 0;

  border-radius: 12px;

  background: transparent;

  color: #6b7280;

  display: flex;
  align-items: center;
  justify-content: center;

  font-size: 17px;

  transition: .2s;
}


.ai-input-action:hover {
  background: #e5e7eb;

  color: #111827;
}


/* =========================================================
   SEND
========================================================= */

.ai-send-button {
  width: 40px;
  height: 40px;

  flex: 0 0 40px;

  padding: 0;

  border: 0;

  border-radius: 13px;

  display: flex;
  align-items: center;
  justify-content: center;

  background: #111827;

  color: #fff;

  font-size: 14px;

  transition: .2s ease;
}


.ai-send-button:hover {
  transform: scale(1.05);

  background: #000;
}


.ai-send-button:disabled {
  opacity: .6;

  cursor: not-allowed;
}


/* =========================================================
   DISCLAIMER
========================================================= */

.ai-chat-disclaimer {
  margin-top: 7px;

  text-align: center;

  color: #9ca3af;

  font-size: 9px;
}


/* =========================================================
   STREAMING
========================================================= */

.ai-streaming {
  white-space: pre-wrap;

  word-break: break-word;
}


/* =========================================================
   TYPING DOTS
========================================================= */

.ai-typing {
  min-height: 20px;

  display: flex;
  align-items: center;

  gap: 4px;
}


.ai-typing span {
  width: 6px;
  height: 6px;

  border-radius: 50%;

  background: currentColor;

  opacity: .35;

  animation:
    aiTypingDot 1.2s infinite ease-in-out;
}


.ai-typing span:nth-child(2) {
  animation-delay: .15s;
}


.ai-typing span:nth-child(3) {
  animation-delay: .30s;
}


@keyframes aiTypingDot {

  0%,
  60%,
  100% {
    transform: translateY(0);

    opacity: .35;
  }

  30% {
    transform: translateY(-4px);

    opacity: 1;
  }
}


/* =========================================================
   VOICE
========================================================= */

.ai-voice-button {
  position: relative;
}


.ai-voice-button.is-listening {
  background: #fee2e2;

  color: #dc2626;

  animation:
    aiVoicePulse 1.2s infinite;
}


.ai-voice-button.is-listening::before {
  content: '';

  position: absolute;

  inset: -4px;

  border:
    2px solid rgba(220, 38, 38, .20);

  border-radius: 15px;

  animation:
    aiVoiceWave 1.2s infinite;
}


@keyframes aiVoicePulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.08);
  }
}


@keyframes aiVoiceWave {

  0% {
    transform: scale(.9);

    opacity: .8;
  }

  100% {
    transform: scale(1.35);

    opacity: 0;
  }
}


/* =========================================================
   SAVED IMAGE
========================================================= */

.ai-saved-image-info {
  margin-bottom: 5px;

  opacity: .7;
}


/* =========================================================
   STORE RESULTS
========================================================= */

.ai-store-results,
.ai-category-results {
  width: 100%;

  max-width: 100%;

  box-sizing: border-box;
}


.ai-store-results img {
  max-width: 72px !important;
}


/* =========================================================
   SCROLLBAR
========================================================= */

.ai-chat-messages::-webkit-scrollbar {
  width: 5px;
}


.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}


.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;

  border-radius: 20px;
}


/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 576px) {

  .ai-chat-trigger {
    width: 120px;

    right: 14px;
    bottom: 138px;
  }


  .ai-chat-trigger-icon {
    width: 100px;
  }


  .ai-chat-canvas {
    width: 100% !important;

    max-width: 100vw;
  }


  .ai-chat-header {
    height: 72px;
    min-height: 72px;

    padding: 0 14px;
  }


  .ai-chat-avatar {
    width: 46px;
    height: 46px;

    flex-basis: 46px;
  }


  .ai-chat-avatar>img {
    width: 46px;
    height: 46px;
  }


  .ai-chat-messages {
    padding: 17px 12px 24px;
  }


  .ai-welcome {
    padding:
      15px 10px 22px;
  }


  .ai-welcome-icon {
    width: 78px;
    height: 78px;
  }


  .ai-message-content {
    max-width:
      calc(100% - 43px);

    padding:
      10px 12px;

    font-size: 13px;
  }


  .ai-message-user .ai-message-content {
    max-width: 86%;
  }


  /*
     * صورة العميل على الموبايل
     */

  .ai-message-image {
    width: auto;

    max-width: 100% !important;

    max-height: 280px;
  }


  .ai-chat-footer {
    padding: 10px;
  }


  .ai-chat-input-box {
    gap: 2px;
  }


  .ai-input-action,
  .ai-send-button {
    width: 38px;
    height: 38px;

    flex-basis: 38px;
  }

}