/* ================================================================
   مساعد دعم يودمي — Chat Widget CSS
   fahdacademy.org
   ================================================================ */

:root {
  --chat-primary: #6D28D9;
  --chat-primary-dark: #4C1D95;
  --chat-primary-light: #EDE9FE;
  --chat-accent: #A435F0;
  --chat-udemy: #A435F0;
  --chat-radius: 16px;
  --chat-shadow: 0 20px 60px rgba(109,40,217,.22), 0 8px 24px rgba(0,0,0,.12);
  --chat-w: 360px;
  --chat-h: 500px;
}

/* ── Floating Button ── */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(109,40,217,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s ease, box-shadow .25s ease;
  outline: none;
}
.chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 10px 30px rgba(109,40,217,.55);
}
.chat-fab:focus-visible {
  outline: 3px solid var(--chat-primary-light);
  outline-offset: 3px;
}
.chat-fab svg {
  width: 28px;
  height: 28px;
  color: #fff;
  transition: opacity .2s;
}
.chat-fab .fab-icon-close { display: none; }
.chat-fab.is-open .fab-icon-chat { display: none; }
.chat-fab.is-open .fab-icon-close { display: block; }

/* Pulse ring */
.chat-fab::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(109,40,217,.4);
  animation: chat-pulse 2.5s ease-in-out infinite;
}
@keyframes chat-pulse {
  0%, 100% { transform: scale(1); opacity: .6; }
  50% { transform: scale(1.15); opacity: 0; }
}
.chat-fab.is-open::before { animation: none; opacity: 0; }

/* Notification badge */
.chat-fab .chat-badge {
  position: absolute;
  top: -2px;
  left: -2px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  font-size: .62rem;
  font-weight: 900;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0);
  transition: transform .2s, opacity .2s;
}
.chat-fab .chat-badge.visible {
  opacity: 1;
  transform: scale(1);
}

/* ── Chat Window ── */
.chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 9989;
  width: var(--chat-w);
  height: var(--chat-h);
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(.92) translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .25s ease;
  direction: rtl;
}
.chat-window.is-visible {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ── */
.chat-header {
  background: linear-gradient(135deg, #1e1b4b, #3730a3, #6D28D9);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.15rem;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info h3 {
  color: #fff;
  font-size: .9rem;
  font-weight: 800;
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-info p {
  color: rgba(255,255,255,.75);
  font-size: .72rem;
  margin: 0;
}
.chat-header-info .chat-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .72rem;
  color: rgba(255,255,255,.8);
}
.chat-header-info .chat-status::before {
  content: '';
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  flex-shrink: 0;
}
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.chat-header-btn {
  background: rgba(255,255,255,.12);
  border: none;
  cursor: pointer;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.85);
  font-size: .75rem;
  transition: background .2s;
  font-family: inherit;
}
.chat-header-btn:hover { background: rgba(255,255,255,.22); }
.chat-header-btn svg { width: 15px; height: 15px; }

/* ── Privacy Notice ── */
.chat-privacy {
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  padding: 8px 14px;
  font-size: .73rem;
  color: #78350f;
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: 7px;
  flex-shrink: 0;
}
.chat-privacy-icon { flex-shrink: 0; font-size: .85rem; margin-top: 1px; }

/* ── Messages Area ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #f9fafb;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

/* Message bubbles */
.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 88%;
  animation: msg-in .25s ease both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-msg.bot { flex-direction: row; align-self: flex-start; }
.chat-msg.user { flex-direction: row-reverse; align-self: flex-end; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--chat-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  flex-shrink: 0;
}
.chat-msg.user .msg-avatar { display: none; }

.msg-bubble {
  border-radius: 14px;
  padding: 10px 14px;
  font-size: .875rem;
  line-height: 1.65;
  word-break: break-word;
}
.chat-msg.bot .msg-bubble {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-bottom-right-radius: 4px;
  color: #1f2937;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.chat-msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--chat-primary), #5B21B6);
  color: #fff;
  border-bottom-left-radius: 4px;
}

/* Links inside bot bubbles */
.msg-bubble a {
  color: var(--chat-primary);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-msg.user .msg-bubble a { color: rgba(255,255,255,.9); }

/* Action button inside bot message */
.msg-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 14px;
  background: var(--chat-primary-light);
  color: var(--chat-primary-dark);
  border-radius: 8px;
  font-size: .8rem;
  font-weight: 700;
  text-decoration: none !important;
  transition: background .2s;
  border: 1px solid #ddd6fe;
}
.msg-action-btn:hover { background: #ddd6fe; }

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  animation: msg-in .2s ease both;
}
.typing-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--chat-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  flex-shrink: 0;
}
.typing-dots {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  border-bottom-right-radius: 4px;
  padding: 10px 14px;
  display: flex;
  gap: 5px;
  align-items: center;
}
.typing-dots span {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: dot-bounce .9s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .30s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ── Quick Replies ── */
.chat-quickreplies {
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-top: 1px solid #f0f0f0;
  background: #fff;
  flex-shrink: 0;
}
.qr-chip {
  background: var(--chat-primary-light);
  color: var(--chat-primary-dark);
  border: 1px solid #ddd6fe;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, transform .15s;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}
.qr-chip:hover {
  background: #ddd6fe;
  transform: translateY(-1px);
}
.qr-chip:active { transform: scale(.97); }
.chat-quickreplies:empty { display: none; }

/* ── Input Area ── */
.chat-input-area {
  border-top: 1px solid #e5e7eb;
  padding: 12px 14px;
  background: #fff;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}
.chat-textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: .875rem;
  font-family: inherit;
  color: #1f2937;
  line-height: 1.5;
  max-height: 100px;
  min-height: 40px;
  height: 40px;
  overflow-y: auto;
  direction: rtl;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  background: #f9fafb;
}
.chat-textarea:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px rgba(109,40,217,.12);
  background: #fff;
}
.chat-textarea::placeholder { color: #9ca3af; }
.chat-textarea:disabled { opacity: .6; cursor: not-allowed; }

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .2s, box-shadow .2s, opacity .2s;
  box-shadow: 0 4px 12px rgba(109,40,217,.3);
}
.chat-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(109,40,217,.4);
}
.chat-send-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.chat-send-btn svg { width: 18px; height: 18px; color: #fff; }

/* ── Footer bar (clear + ticket link) ── */
.chat-footer-bar {
  padding: 8px 14px;
  border-top: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff;
  flex-shrink: 0;
}
.chat-clear-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .72rem;
  color: #9ca3af;
  font-family: inherit;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color .2s, background .2s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-clear-btn:hover { color: #ef4444; background: #fef2f2; }
.chat-ticket-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .72rem;
  font-weight: 700;
  color: var(--chat-udemy);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .2s;
}
.chat-ticket-link:hover { background: #fdf4ff; }

/* ── Rate limit message ── */
.chat-rate-msg {
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .8rem;
  color: #78350f;
  text-align: center;
  margin: 0 14px;
  flex-shrink: 0;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  :root {
    --chat-w: calc(100vw - 20px);
    --chat-h: 78vh;
  }
  .chat-window {
    right: 10px;
    bottom: 86px;
    max-height: 78vh;
  }
  .chat-fab {
    right: 16px;
    bottom: 16px;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .chat-window, .chat-fab, .chat-msg { transition: none; animation: none; }
  .chat-fab::before { animation: none; }
  .typing-dots span { animation: none; }
}
