/**
 * أنماط دردشة الذكاء الاصطناعي
 * Author: MiniMax Agent
 */

/* متغيرات CSS */
:root {
  --ai-chat-primary: #007cba;
  --ai-chat-secondary: #ffffff;
  --ai-chat-accent: #0096dc;
  --ai-chat-text: #333333;
  --ai-chat-text-light: #666666;
  --ai-chat-border: #e0e0e0;
  --ai-chat-bg: #ffffff;
  --ai-chat-bg-light: #f8f9fa;
  --ai-chat-shadow: 0 4px 20px rgba(0,0,0,0.1);
  --ai-chat-shadow-hover: 0 8px 25px rgba(0,0,0,0.15);
  --ai-chat-radius: 12px;
  --ai-chat-radius-small: 6px;
  --ai-chat-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --ai-chat-font-size: 14px;
  --ai-chat-line-height: 1.5;
  --ai-chat-z-index: 9999;
  --ai-chat-animation: cubic-bezier(0.4, 0, 0.2, 1);
}

/* الحاوي الرئيسي */
.ai-chat-widget {
  position: relative;
  font-family: var(--ai-chat-font-family);
  font-size: var(--ai-chat-font-size);
  line-height: var(--ai-chat-line-height);
  background: var(--ai-chat-bg);
  border: 1px solid var(--ai-chat-border);
  border-radius: var(--ai-chat-radius);
  box-shadow: var(--ai-chat-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: var(--ai-chat-text);
  direction: rtl;
  text-align: right;
  --primary-color: var(--ai-chat-primary);
}

/* أوضاع العرض المختلفة */
.ai-chat-widget[data-position="bottom-right"] {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: var(--ai-chat-z-index);
  max-width: 400px;
  width: 90vw;
  max-height: 600px;
  height: 500px;
}

.ai-chat-widget[data-position="bottom-left"] {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: var(--ai-chat-z-index);
  max-width: 400px;
  width: 90vw;
  max-height: 600px;
  height: 500px;
}

.ai-chat-widget[data-position="top-right"] {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: var(--ai-chat-z-index);
  max-width: 400px;
  width: 90vw;
  max-height: 600px;
  height: 500px;
}

.ai-chat-widget[data-position="top-left"] {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: var(--ai-chat-z-index);
  max-width: 400px;
  width: 90vw;
  max-height: 600px;
  height: 500px;
}

.ai-chat-widget[data-position="center"] {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--ai-chat-z-index);
  max-width: 500px;
  width: 90vw;
  max-height: 600px;
  height: 500px;
}

.ai-chat-widget[data-position="inline"] {
  position: relative;
  margin: 20px auto;
  max-width: 100%;
  width: 100%;
  height: auto;
  min-height: 400px;
}

/* رأس الدردشة */
.ai-chat-header {
  background: linear-gradient(135deg, var(--primary-color), var(--ai-chat-accent));
  color: white;
  padding: 12px 16px;
  border-bottom: 1px solid var(--ai-chat-border);
  flex-shrink: 0;
}

.ai-chat-header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
}

.ai-chat-icon {
  font-size: 18px;
  animation: ai-chat-pulse 2s infinite;
}

@keyframes ai-chat-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.ai-chat-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chat-model-selector {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  border-radius: var(--ai-chat-radius-small);
  padding: 4px 8px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  transition: all 0.2s var(--ai-chat-animation);
}

.ai-chat-model-selector:hover {
  background: rgba(255,255,255,0.3);
}

.ai-chat-model-selector option {
  background: var(--ai-chat-primary);
  color: white;
}

.ai-chat-minimize,
.ai-chat-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ai-chat-animation);
  font-size: 16px;
  font-weight: bold;
}

.ai-chat-minimize:hover,
.ai-chat-close:hover {
  background: rgba(255,255,255,0.3);
  transform: scale(1.1);
}

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

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

.ai-chat-messages::-webkit-scrollbar-track {
  background: var(--ai-chat-bg-light);
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--ai-chat-border);
  border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--ai-chat-text-light);
}

/* رسائل المستخدم */
.user-message {
  animation: ai-chat-slide-in-right 0.3s var(--ai-chat-animation);
}

.user-message-content {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  justify-content: flex-start;
}

.user-message-bubble {
  background: var(--primary-color);
  color: white;
  padding: 12px 16px;
  border-radius: var(--ai-chat-radius);
  border-bottom-right-radius: var(--ai-chat-radius-small);
  max-width: 80%;
  word-wrap: break-word;
  position: relative;
}

.user-message-text {
  margin-bottom: 4px;
}

.user-message-time {
  font-size: 11px;
  opacity: 0.8;
  text-align: left;
}

.user-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ai-chat-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

/* رسائل الذكاء الاصطناعي */
.ai-message {
  animation: ai-chat-slide-in-left 0.3s var(--ai-chat-animation);
}

.ai-message-content {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  justify-content: flex-end;
}

.ai-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), var(--ai-chat-accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  order: 2;
}

.ai-message-bubble {
  background: var(--ai-chat-bg);
  border: 1px solid var(--ai-chat-border);
  padding: 12px 16px;
  border-radius: var(--ai-chat-radius);
  border-bottom-left-radius: var(--ai-chat-radius-small);
  max-width: 80%;
  word-wrap: break-word;
  position: relative;
  order: 1;
}

.ai-message-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--ai-chat-border);
}

.ai-model-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary-color);
}

.ai-message-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s var(--ai-chat-animation);
}

.ai-message-bubble:hover .ai-message-actions {
  opacity: 1;
}

.ai-message-actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--ai-chat-radius-small);
  font-size: 12px;
  transition: all 0.2s var(--ai-chat-animation);
}

.ai-message-actions button:hover {
  background: var(--ai-chat-bg-light);
  transform: scale(1.1);
}

.ai-message-text {
  margin-bottom: 4px;
  white-space: pre-wrap;
}

.ai-message-time {
  font-size: 11px;
  color: var(--ai-chat-text-light);
  text-align: right;
}

/* مؤشر الكتابة */
.ai-typing-indicator {
  animation: ai-chat-fade-in 0.3s var(--ai-chat-animation);
}

.ai-typing-content {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.ai-typing-bubble {
  background: var(--ai-chat-bg);
  border: 1px solid var(--ai-chat-border);
  padding: 12px 16px;
  border-radius: var(--ai-chat-radius);
  border-bottom-left-radius: var(--ai-chat-radius-small);
}

.ai-typing-dots {
  display: flex;
  gap: 4px;
}

.ai-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--ai-chat-text-light);
  border-radius: 50%;
  animation: ai-chat-typing 1.4s infinite ease-in-out;
}

.ai-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes ai-chat-typing {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* منطقة الإدخال */
.ai-chat-input-area {
  flex-shrink: 0;
  background: var(--ai-chat-bg);
  border-top: 1px solid var(--ai-chat-border);
  padding: 12px 16px;
}

.ai-chat-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--ai-chat-bg-light);
  border: 1px solid var(--ai-chat-border);
  border-radius: var(--ai-chat-radius);
  padding: 8px 12px;
  transition: all 0.2s var(--ai-chat-animation);
}

.ai-chat-input-wrapper:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(var(--primary-color), 0.1);
}

.ai-chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  color: var(--ai-chat-text);
  resize: none;
  min-height: 20px;
  max-height: 100px;
  line-height: 1.4;
  direction: rtl;
  text-align: right;
}

.ai-chat-input::placeholder {
  color: var(--ai-chat-text-light);
}

.ai-chat-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-chat-attachment-btn,
.ai-chat-send-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--ai-chat-radius-small);
  transition: all 0.2s var(--ai-chat-animation);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-attachment-btn:hover {
  background: var(--ai-chat-border);
}

.ai-chat-send-btn {
  background: var(--primary-color);
  color: white;
  width: 32px;
  height: 32px;
}

.ai-chat-send-btn:hover:not(:disabled) {
  background: var(--ai-chat-accent);
  transform: scale(1.05);
}

.ai-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-icon {
  font-size: 14px;
  transform: rotate(-90deg);
}

/* شريط الأدوات */
.ai-chat-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-chat-toolbar button {
  background: none;
  border: 1px solid var(--ai-chat-border);
  padding: 6px 12px;
  border-radius: var(--ai-chat-radius-small);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s var(--ai-chat-animation);
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-chat-toolbar button:hover {
  background: var(--ai-chat-bg-light);
  border-color: var(--primary-color);
}

/* شريط الحالة */
.ai-chat-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--ai-chat-text-light);
  margin-top: 4px;
}

.character-count {
  direction: ltr;
}

/* الردود المتعددة */
.multi-ai-message {
  background: var(--ai-chat-bg);
  border: 1px solid var(--ai-chat-border);
  border-radius: var(--ai-chat-radius);
  overflow: hidden;
  animation: ai-chat-slide-in-left 0.3s var(--ai-chat-animation);
}

.multi-ai-header {
  background: var(--ai-chat-bg-light);
  padding: 8px 12px;
  border-bottom: 1px solid var(--ai-chat-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.multi-ai-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--primary-color);
}

.expand-all {
  background: none;
  border: none;
  color: var(--primary-color);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: var(--ai-chat-radius-small);
  transition: all 0.2s var(--ai-chat-animation);
}

.expand-all:hover {
  background: rgba(var(--primary-color), 0.1);
}

.multi-ai-responses {
  display: grid;
  gap: 1px;
}

.multi-ai-responses .ai-message {
  margin: 0;
  border-radius: 0;
}

.multi-ai-responses .ai-message:last-child {
  border-bottom: none;
}

/* منطقة المقارنة */
.ai-chat-comparison {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--ai-chat-bg);
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.comparison-header {
  background: var(--ai-chat-bg-light);
  padding: 12px 16px;
  border-bottom: 1px solid var(--ai-chat-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.comparison-header h4 {
  margin: 0;
  font-size: 16px;
  color: var(--ai-chat-text);
}

.close-comparison {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--ai-chat-radius-small);
  transition: all 0.2s var(--ai-chat-animation);
}

.close-comparison:hover {
  background: var(--ai-chat-border);
}

.comparison-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

/* الإعدادات السريعة */
.ai-chat-quick-settings {
  position: absolute;
  top: 60px;
  right: 16px;
  background: var(--ai-chat-bg);
  border: 1px solid var(--ai-chat-border);
  border-radius: var(--ai-chat-radius);
  box-shadow: var(--ai-chat-shadow);
  padding: 16px;
  z-index: 11;
  width: 200px;
}

.quick-settings-content h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--ai-chat-text);
}

.setting-group {
  margin-bottom: 12px;
}

.setting-group label {
  display: block;
  font-size: 12px;
  color: var(--ai-chat-text-light);
  margin-bottom: 4px;
}

.setting-group select,
.setting-group input[type="checkbox"] {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--ai-chat-border);
  border-radius: var(--ai-chat-radius-small);
  font-size: 12px;
}

.setting-group input[type="checkbox"] {
  width: auto;
  margin-left: 8px;
}

/* الرسوم المتحركة */
@keyframes ai-chat-slide-in-right {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes ai-chat-slide-in-left {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes ai-chat-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes ai-chat-bounce {
  0%, 20%, 53%, 80%, 100% {
    transform: translateY(0);
  }
  40%, 43% {
    transform: translateY(-8px);
  }
  70% {
    transform: translateY(-4px);
  }
  90% {
    transform: translateY(-2px);
  }
}

/* حالات خاصة */
.ai-chat-widget.minimized {
  height: 60px !important;
  min-height: 60px !important;
}

.ai-chat-widget.minimized .ai-chat-messages,
.ai-chat-widget.minimized .ai-chat-input-area,
.ai-chat-widget.minimized .ai-typing-indicator {
  display: none;
}

.ai-chat-widget.hidden {
  display: none;
}

/* المظهر الداكن */
.ai-chat-widget.dark-theme {
  --ai-chat-bg: #1a1a1a;
  --ai-chat-bg-light: #2d2d2d;
  --ai-chat-text: #ffffff;
  --ai-chat-text-light: #b0b0b0;
  --ai-chat-border: #404040;
}

/* التجاوب */
@media (max-width: 768px) {
  .ai-chat-widget[data-position^="bottom"],
  .ai-chat-widget[data-position^="top"] {
    left: 10px !important;
    right: 10px !important;
    width: calc(100vw - 20px) !important;
    max-width: none !important;
  }
  
  .ai-chat-widget[data-position="center"] {
    width: calc(100vw - 20px) !important;
    height: calc(100vh - 40px) !important;
    max-width: none !important;
    max-height: none !important;
  }
  
  .ai-chat-input {
    font-size: 16px; /* منع التكبير في Safari */
  }
  
  .multi-ai-responses {
    grid-template-columns: 1fr;
  }
  
  .ai-chat-quick-settings {
    left: 10px;
    right: 10px;
    width: auto;
  }
}

/* إمكانية الوصول */
.ai-chat-widget:focus-within {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.ai-chat-widget [role="button"]:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* حالات التحميل */
.ai-chat-widget.loading .ai-chat-send-btn {
  animation: ai-chat-spin 1s linear infinite;
}

@keyframes ai-chat-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* تأثيرات بصرية إضافية */
.ai-message-bubble.success {
  border-left: 3px solid #28a745;
}

.ai-message-bubble.error {
  border-left: 3px solid #dc3545;
  background-color: #fff5f5;
}

.ai-message-bubble.warning {
  border-left: 3px solid #ffc107;
  background-color: #fffef0;
}

/* أزرار التفاعل */
.message-reaction-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 12px;
  font-size: 12px;
  transition: all 0.2s var(--ai-chat-animation);
  margin: 2px;
}

.message-reaction-btn:hover {
  background: var(--ai-chat-bg-light);
}

.message-reaction-btn.active {
  background: var(--primary-color);
  color: white;
}

/* حالة عدم الاتصال */
.ai-chat-widget.offline .ai-chat-header {
  background: #6c757d;
}

.ai-chat-widget.offline .ai-chat-send-btn {
  background: #6c757d;
  cursor: not-allowed;
}

.offline-message {
  text-align: center;
  padding: 20px;
  color: var(--ai-chat-text-light);
  font-style: italic;
}

/* تحسينات الطباعة */
@media print {
  .ai-chat-widget {
    box-shadow: none;
    border: 1px solid #000;
  }
  
  .ai-chat-header {
    background: #000 !important;
    color: #fff !important;
  }
  
  .ai-chat-input-area {
    display: none;
  }
}
