/* ═══════════════════════════════════════════════════════════
   🎨 AI UI Styles v8.0
   ═══════════════════════════════════════════════════════════ */

/* -------- متغيرات AI -------- */
:root {
  --ai-primary: #8b5cf6;
  --ai-primary-dark: #7c3aed;
  --ai-gradient: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --ai-bg: #faf5ff;
  --ai-bg-dark: #1e1b4b;
  --ai-border: #e9d5ff;
  --ai-text: #1f2937;
  --ai-text-light: #6b7280;
  --ai-user-bubble: #8b5cf6;
  --ai-bot-bubble: #f3f4f6;
  --ai-shadow: 0 10px 40px rgba(139, 92, 246, 0.2);
}

/* ═══════════════════════════════════════════════════════════
   💬 الشات بوت العائم
   ═══════════════════════════════════════════════════════════ */
#ai-chatbot-widget {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 9999;
  font-family: 'Tajawal', 'Cairo', system-ui, sans-serif;
}

[dir="rtl"] #ai-chatbot-widget { left: 20px; right: auto; }
[dir="ltr"] #ai-chatbot-widget { right: 20px; left: auto; }

/* زر التفعيل */
.ai-chat-toggle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--ai-gradient);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--ai-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.3s, box-shadow 0.3s;
  animation: ai-pulse 3s ease-in-out infinite;
}

.ai-chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 15px 50px rgba(139, 92, 246, 0.35);
}

.ai-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 10px;
  letter-spacing: 0.5px;
}

@keyframes ai-pulse {
  0%, 100% { box-shadow: var(--ai-shadow); }
  50% { box-shadow: 0 10px 40px rgba(236, 72, 153, 0.4); }
}

/* نافذة الشات */
.ai-chat-window {
  position: absolute;
  bottom: 80px;
  left: 0;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 550px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--ai-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: ai-slide-up 0.3s ease-out;
}

[dir="rtl"] .ai-chat-window { left: 0; right: auto; }
[dir="ltr"] .ai-chat-window { right: 0; left: auto; }

@keyframes ai-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header */
.ai-chat-header {
  background: var(--ai-gradient);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-chat-avatar {
  font-size: 32px;
  background: rgba(255, 255, 255, 0.2);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-title strong {
  display: block;
  font-size: 16px;
  font-weight: 700;
}

.ai-chat-title small {
  display: block;
  font-size: 11px;
  opacity: 0.9;
  margin-top: 2px;
}

.ai-chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.2s;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* الرسائل */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--ai-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-msg {
  display: flex;
  max-width: 85%;
}

.ai-msg-user {
  align-self: flex-end;
  margin-left: auto;
}

.ai-msg-bot {
  align-self: flex-start;
}

.ai-msg-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.ai-msg-user .ai-msg-bubble {
  background: var(--ai-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg-bot .ai-msg-bubble {
  background: #fff;
  color: var(--ai-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.ai-msg-bubble ul {
  margin: 8px 0 0 0;
  padding-inline-start: 20px;
}

.ai-msg-bubble li {
  margin: 4px 0;
}

/* تأثير الكتابة */
.ai-typing {
  display: flex;
  gap: 4px;
  padding: 14px 20px;
}

.ai-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ai-primary);
  animation: ai-typing-bounce 1.4s infinite ease-in-out;
}

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

@keyframes ai-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-8px); opacity: 1; }
}

/* اقتراحات */
.ai-chat-suggestions {
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid var(--ai-border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-sug-btn {
  background: var(--ai-bg);
  border: 1px solid var(--ai-border);
  color: var(--ai-primary-dark);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.ai-sug-btn:hover {
  background: var(--ai-primary);
  color: #fff;
  border-color: var(--ai-primary);
}

/* نموذج الإرسال */
.ai-chat-form {
  display: flex;
  padding: 12px 16px;
  gap: 8px;
  background: #fff;
  border-top: 1px solid var(--ai-border);
}

#ai-chat-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--ai-border);
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: border 0.2s;
  font-family: inherit;
}

#ai-chat-input:focus {
  border-color: var(--ai-primary);
}

.ai-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ai-gradient);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

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

.ai-send-btn svg {
  transform: rotate(180deg); /* للاتجاه العربي */
}

/* ═══════════════════════════════════════════════════════════
   ✨ صفحة مولّد الدعوات
   ═══════════════════════════════════════════════════════════ */
.ai-generator-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.ai-generator-header {
  background: var(--ai-gradient);
  color: #fff;
  padding: 32px;
  border-radius: 20px;
  margin-bottom: 24px;
  text-align: center;
}

.ai-generator-header h1 {
  font-size: 28px;
  margin: 0 0 8px;
}

.ai-generator-header p {
  opacity: 0.95;
  margin: 0;
  font-size: 15px;
}

.ai-generator-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 768px) {
  .ai-generator-grid { grid-template-columns: 1fr; }
}

.ai-card {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  border: 1px solid #f3f4f6;
}

.ai-card h3 {
  margin: 0 0 16px;
  color: var(--ai-primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* شبكة الأنماط */
.ai-style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.ai-style-card {
  padding: 16px;
  border: 2px solid var(--ai-border);
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  background: #fff;
}

.ai-style-card:hover {
  border-color: var(--ai-primary);
  background: var(--ai-bg);
}

.ai-style-card.selected {
  border-color: var(--ai-primary);
  background: var(--ai-gradient);
  color: #fff;
}

.ai-style-card .name {
  font-weight: 700;
  margin-bottom: 4px;
}

.ai-style-card .desc {
  font-size: 11px;
  opacity: 0.8;
}

/* حقول الإدخال */
.ai-form-group {
  margin-bottom: 16px;
}

.ai-form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 13px;
  color: var(--ai-text);
}

.ai-form-group input,
.ai-form-group select,
.ai-form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--ai-border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  transition: border 0.2s;
}

.ai-form-group input:focus,
.ai-form-group textarea:focus,
.ai-form-group select:focus {
  outline: none;
  border-color: var(--ai-primary);
}

/* زر التوليد */
.ai-generate-btn {
  width: 100%;
  padding: 14px;
  background: var(--ai-gradient);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
}

.ai-generate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
}

.ai-generate-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* النتائج */
.ai-result {
  padding: 20px;
  background: var(--ai-bg);
  border-radius: 12px;
  border-inline-start: 4px solid var(--ai-primary);
  margin-bottom: 12px;
  position: relative;
  white-space: pre-wrap;
  line-height: 1.8;
  font-size: 15px;
}

.ai-result-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.ai-result-btn {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid var(--ai-border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
  font-family: inherit;
}

.ai-result-btn:hover {
  background: var(--ai-primary);
  color: #fff;
  border-color: var(--ai-primary);
}

/* مؤشر الكوتا */
.ai-quota-bar {
  background: var(--ai-bg);
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-quota-progress {
  flex: 1;
  height: 8px;
  background: #fff;
  border-radius: 4px;
  overflow: hidden;
}

.ai-quota-progress-fill {
  height: 100%;
  background: var(--ai-gradient);
  transition: width 0.3s;
}

.ai-quota-text {
  font-size: 13px;
  color: var(--ai-text-light);
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════
   👑 لوحة إدارة AI (للأدمن)
   ═══════════════════════════════════════════════════════════ */
.ai-admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.ai-admin-stat {
  background: #fff;
  padding: 20px;
  border-radius: 12px;
  border-inline-start: 4px solid var(--ai-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.ai-admin-stat .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--ai-primary-dark);
  margin: 4px 0;
}

.ai-admin-stat .label {
  font-size: 12px;
  color: var(--ai-text-light);
}

.ai-admin-stat .sub {
  font-size: 11px;
  color: var(--ai-text-light);
  margin-top: 4px;
}

/* جدول الكوتا */
.ai-quota-table {
  width: 100%;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.ai-quota-table th {
  background: var(--ai-bg);
  padding: 12px;
  text-align: start;
  font-size: 13px;
  color: var(--ai-primary-dark);
}

.ai-quota-table td {
  padding: 12px;
  border-top: 1px solid #f3f4f6;
  font-size: 14px;
}

.ai-quota-table input[type="number"] {
  width: 80px;
  padding: 6px 10px;
  border: 1px solid var(--ai-border);
  border-radius: 6px;
  text-align: center;
}

/* إشعار الترقية */
.ai-upgrade-notice {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1px solid #f59e0b;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  color: #92400e;
}

.ai-upgrade-notice strong {
  display: block;
  margin-bottom: 4px;
}

/* ═══════════════════════════════════════════════════════════
   📱 استجابة للجوال
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .ai-chat-window {
    width: calc(100vw - 20px);
    height: calc(100vh - 120px);
    bottom: 80px;
  }
  
  .ai-chat-toggle {
    width: 56px;
    height: 56px;
  }
  
  .ai-generator-header {
    padding: 24px 16px;
  }
  
  .ai-generator-header h1 {
    font-size: 22px;
  }
}
