/* =====================================================
   ai_chat.css — واجهة مساعد Gemini AI
   ===================================================== */

/* ── زر الدردشة العائم ─────────────────────────────── */
#aiChatToggle {
  position: fixed;
  bottom: 28px;
  left: 28px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1A1A2E 0%, #E8C547 150%);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(26,26,46,0.35), 0 0 0 0 rgba(232,197,71,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  z-index: 9990;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: aiPulse 3s infinite;
}
#aiChatToggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(26,26,46,0.45), 0 0 0 8px rgba(232,197,71,0.15);
}
#aiChatToggle .ai-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #10B981;
  border-radius: 50%;
  border: 2px solid white;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
}

@keyframes aiPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(26,26,46,0.35), 0 0 0 0 rgba(232,197,71,0.4); }
  50%       { box-shadow: 0 4px 20px rgba(26,26,46,0.35), 0 0 0 10px rgba(232,197,71,0); }
}

/* ── نافذة الدردشة ─────────────────────────────────── */
#aiChatWindow {
  position: fixed;
  bottom: 100px;
  left: 20px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: #FFFFFF;
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(26,26,46,0.18), 0 2px 8px rgba(26,26,46,0.08);
  display: flex;
  flex-direction: column;
  z-index: 9991;
  overflow: hidden;
  transform: scale(0.85) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s ease;
  border: 1px solid rgba(0,0,0,0.06);
}
#aiChatWindow.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── رأس النافذة ──────────────────────────────────── */
#aiChatHeader {
  background: linear-gradient(135deg, #1A1A2E 0%, #2D2D44 100%);
  color: white;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  border-radius: 20px 20px 0 0;
}
.ai-avatar {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #E8C547, #C9A832);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.ai-header-info { flex: 1; }
.ai-header-info h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}
.ai-header-info small {
  font-size: 11px;
  opacity: 0.7;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ai-status-dot {
  width: 7px;
  height: 7px;
  background: #10B981;
  border-radius: 50%;
  display: inline-block;
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.4} }

#aiCloseBtn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.15s;
  flex-shrink: 0;
}
#aiCloseBtn:hover { background: rgba(255,255,255,0.2); }

/* ── منطقة الرسائل ────────────────────────────────── */
#aiMessages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #F7F5F0;
  scroll-behavior: smooth;
}
#aiMessages::-webkit-scrollbar { width: 4px; }
#aiMessages::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 2px; }

/* رسالة فردية */
.ai-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  animation: msgIn 0.25s ease;
}
@keyframes msgIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

.ai-msg.user { flex-direction: row-reverse; }
.ai-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 2px;
}
.ai-msg.bot .ai-msg-avatar  { background: linear-gradient(135deg,#1A1A2E,#2D2D44); color: #E8C547; }
.ai-msg.user .ai-msg-avatar { background: #E8C547; color: #1A1A2E; font-weight:700; }

.ai-msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}
.ai-msg.bot .ai-msg-bubble {
  background: white;
  color: #1A1A2E;
  border-radius: 4px 16px 16px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.ai-msg.user .ai-msg-bubble {
  background: #1A1A2E;
  color: white;
  border-radius: 16px 4px 16px 16px;
}

/* markdown داخل فقاعة البوت */
.ai-msg-bubble strong { font-weight: 700; }
.ai-msg-bubble em { font-style: italic; }
.ai-msg-bubble ul, .ai-msg-bubble ol {
  padding-right: 20px;
  margin: 6px 0;
}
.ai-msg-bubble li { margin-bottom: 3px; }
.ai-msg-bubble code {
  background: rgba(0,0,0,0.07);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: monospace;
}
.ai-msg-bubble h1, .ai-msg-bubble h2, .ai-msg-bubble h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 8px 0 4px;
}

/* ── بطاقة الإجراء (Action Card) ─────────────────── */
.ai-action-card {
  background: white;
  border: 1.5px solid #E8C547;
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 8px;
  font-size: 13px;
}
.ai-action-card h6 {
  font-weight: 700;
  font-size: 13px;
  margin: 0 0 8px;
  color: #1A1A2E;
}
.ai-action-card .action-field {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  font-size: 12.5px;
}
.ai-action-card .action-field:last-of-type { border-bottom: none; }
.ai-action-card .action-field span:first-child { color: #6B7280; }
.ai-action-card .action-field span:last-child  { font-weight: 600; color: #1A1A2E; }
.ai-action-confirm {
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  background: #1A1A2E;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.ai-action-confirm:hover { background: #2D2D44; }
.ai-action-confirm.done  { background: #10B981; }

/* ── حالة الكتابة ─────────────────────────────────── */
.ai-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 10px 14px;
  background: white;
  border-radius: 4px 16px 16px 16px;
  width: fit-content;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.ai-typing span {
  width: 8px; height: 8px;
  background: #9CA3AF;
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%,60%,100% { transform:translateY(0); }
  30%         { transform:translateY(-6px); background:#1A1A2E; }
}

/* ── اقتراحات سريعة ──────────────────────────────── */
#aiSuggestions {
  padding: 8px 12px;
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  background: #F7F5F0;
  border-top: 1px solid rgba(0,0,0,0.05);
  flex-shrink: 0;
}
#aiSuggestions::-webkit-scrollbar { display: none; }
.ai-suggestion {
  background: white;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 11.5px;
  white-space: nowrap;
  cursor: pointer;
  color: #1A1A2E;
  transition: all 0.15s;
  flex-shrink: 0;
}
.ai-suggestion:hover { background: #1A1A2E; color: white; border-color: #1A1A2E; }

/* ── شريط الإدخال ─────────────────────────────────── */
#aiInputArea {
  padding: 12px 14px;
  border-top: 1px solid rgba(0,0,0,0.06);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: white;
  flex-shrink: 0;
}
#aiInput {
  flex: 1;
  border: 1.5px solid rgba(0,0,0,0.1);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: 'Tajawal', sans-serif;
  font-size: 13.5px;
  color: #1A1A2E;
  resize: none;
  min-height: 44px;
  max-height: 100px;
  outline: none;
  background: #F7F5F0;
  transition: border-color 0.15s;
  direction: rtl;
  overflow-y: auto;
}
#aiInput:focus { border-color: #E8C547; background: white; }
#aiInput::placeholder { color: #9CA3AF; }

#aiSendBtn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #1A1A2E;
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.15s;
  flex-shrink: 0;
}
#aiSendBtn:hover   { background: #E8C547; color: #1A1A2E; }
#aiSendBtn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── رسالة ترحيب فارغة ────────────────────────────── */
.ai-empty-state {
  text-align: center;
  padding: 32px 16px;
  color: #9CA3AF;
}
.ai-empty-state .ai-empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  display: block;
}
.ai-empty-state h5 { font-size: 15px; font-weight: 700; color: #1A1A2E; margin-bottom: 6px; }
.ai-empty-state p  { font-size: 13px; margin: 0; }

/* ── جوال ─────────────────────────────────────────── */
@media (max-width: 480px) {
  #aiChatWindow { bottom: 90px; left: 10px; right: 10px; width: auto; max-width: none; }
  #aiChatToggle { bottom: 20px; left: 16px; width: 52px; height: 52px; font-size: 20px; }
}
