/* AI Chat Widget Styles */
.ai-chat-container {
    position: fixed;
    bottom: 20px;
    z-index: 9999;
    font-family: inherit;
}

/* RTL Support */
[dir="rtl"] .ai-chat-container {
    left: 20px;
}

[dir="ltr"] .ai-chat-container,
.ai-chat-container {
    right: 20px;
}

/* Launcher Button */
.ai-chat-launcher {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: #fff !important; /* خلفية بيضاء لضمان ظهور الروبوت بشكل جيد */
    border: 2px solid var(--bs-primary, #4338ca);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    padding: 0;
    overflow: hidden; /* ضروري لقص الفيديو على شكل دائرة */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
}

.ai-chat-video {
    width: 100%;
    height: 100%;
    object-fit: cover; /* لملء الدائرة بالكامل */
    display: block;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 0 rgba(67, 56, 202, 0);
    }
    50% {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 10px rgba(67, 56, 202, 0);
    }
}

.ai-chat-launcher:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.ai-chat-icon {
    color: white;
}

.ai-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
}

/* Chat Panel */
.ai-chat-panel {
    position: fixed;
    bottom: 100px;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

[dir="rtl"] .ai-chat-panel {
    left: 20px;
}

[dir="ltr"] .ai-chat-panel {
    right: 20px;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Dark theme support */
[theme="dark"] .ai-chat-panel {
    background: #1f2937;
    color: #f3f4f6;
}

/* Header */
.ai-chat-header {
    background: linear-gradient(135deg, var(--bs-primary, #4338ca) 0%, var(--primary-dark, #3730a3) 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

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

.ai-chat-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.ai-chat-status {
    font-size: 12px;
    opacity: 0.9;
    margin-top: 2px;
}

.ai-chat-close-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

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

/* Quick Action Chips */
.ai-chat-chips {
    padding: 12px 16px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}

[theme="dark"] .ai-chat-chips {
    background: #111827;
    border-bottom-color: #374151;
}

.ai-chat-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

[theme="dark"] .ai-chat-chip {
    background: #1f2937;
    border-color: #374151;
    color: #f3f4f6;
}

.ai-chat-chip:hover {
    background: var(--bs-primary, #4338ca);
    color: white;
    border-color: var(--bs-primary, #4338ca);
    transform: translateY(-1px);
}

.ai-chat-chip svg {
    flex-shrink: 0;
}

/* Messages Container */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

[theme="dark"] .ai-chat-messages {
    background: #111827;
}

/* Message Styles */
.ai-chat-message {
    display: flex;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat-message.user-message {
    flex-direction: row-reverse;
}

[dir="rtl"] .ai-chat-message {
    flex-direction: row-reverse;
}

[dir="rtl"] .ai-chat-message.user-message {
    flex-direction: row;
}

.ai-chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bs-primary, #4338ca);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.user-message .ai-chat-message-avatar {
    background: #6b7280;
}

.ai-chat-message-content {
    flex: 1;
    max-width: 75%;
}

.ai-chat-message-text {
    background: #f3f4f6;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    padding-right: 30px; /* Space for copy button */
}

.ai-chat-copy-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0; /* Hidden by default */
}

.ai-chat-message-text:hover .ai-chat-copy-btn {
    opacity: 1; /* Show on hover */
}

.ai-chat-copy-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--bs-primary);
}

[dir="rtl"] .ai-chat-message-text {
    padding-right: 14px;
    padding-left: 30px;
}

[dir="rtl"] .ai-chat-copy-btn {
    right: auto;
    left: 5px;
}

[theme="dark"] .ai-chat-message-text {
    background: #1f2937;
}

.user-message .ai-chat-message-text {
    background: var(--bs-primary, #4338ca);
    color: white;
}

/* Product Recommendations */
.ai-product-recommendations {
    margin-top: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.ai-product-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.2s;
    cursor: pointer;
}

[theme="dark"] .ai-product-card {
    background: #1f2937;
    border-color: #374151;
}

.ai-product-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.ai-product-image {
    width: 100%;
    height: 140px;
    object-fit: cover;
}

.ai-product-info {
    padding: 10px;
}

.ai-product-name {
    font-size: 13px;
    font-weight: 500;
    margin: 0 0 6px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;
}

[theme="dark"] .ai-product-name {
    color: #f3f4f6;
}

.ai-product-price {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--bs-primary, #4338ca);
    margin-bottom: 4px;
}

.ai-product-price-old {
    font-size: 12px;
    color: #9ca3af;
    text-decoration: line-through;
    font-weight: normal;
}

.ai-product-reason {
    font-size: 11px;
    color: #6b7280;
    margin-top: 4px;
}

.ai-product-badge {
    display: inline-block;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: #dcfce7;
    color: #166534;
    margin-top: 4px;
}

.ai-product-badge.limited {
    background: #fef3c7;
    color: #92400e;
}

/* Feedback Buttons */
.ai-message-feedback {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.ai-feedback-btn {
    background: transparent;
    border: 1px solid #e5e7eb;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

[theme="dark"] .ai-feedback-btn {
    border-color: #374151;
    color: #9ca3af;
}

.ai-feedback-btn:hover {
    background: #f3f4f6;
    border-color: var(--bs-primary, #4338ca);
}

[theme="dark"] .ai-feedback-btn:hover {
    background: #1f2937;
}

.ai-feedback-btn.active {
    background: var(--bs-primary, #4338ca);
    color: white;
    border-color: var(--bs-primary, #4338ca);
}

/* Typing Indicator */
.ai-chat-typing {
    padding: 16px;
    display: flex;
    gap: 6px;
    align-items: center;
}

.ai-chat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typing 1.4s infinite;
}

.ai-chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input Area */
.ai-chat-input-container {
    border-top: 1px solid #e5e7eb;
    padding: 16px;
    background: white;
}

[theme="dark"] .ai-chat-input-container {
    background: #1f2937;
    border-top-color: #374151;
}

.ai-chat-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ai-chat-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

[theme="dark"] .ai-chat-input {
    background: #111827;
    border-color: #374151;
    color: #f3f4f6;
}

.ai-chat-input:focus {
    border-color: var(--bs-primary, #4338ca);
}

.ai-chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bs-primary, #4338ca);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-chat-send-btn:hover {
    background: var(--primary-dark, #3730a3);
    transform: scale(1.05);
}

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

/* Scrollbar Styles */
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

[theme="dark"] .ai-chat-messages::-webkit-scrollbar-track {
    background: #1f2937;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

[theme="dark"] .ai-chat-messages::-webkit-scrollbar-thumb {
    background: #374151;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .ai-chat-panel {
        width: calc(100vw - 20px);
        height: calc(100vh - 120px);
        bottom: 90px;
        right: 10px;
        left: 10px;
        border-radius: 16px 16px 0 0;
    }

    .ai-chat-launcher {
        width: 56px;
        height: 56px;
        bottom: 80px;
    }

    .ai-product-recommendations {
        grid-template-columns: 1fr;
    }
}

/* Accessibility */
.ai-chat-launcher:focus,
.ai-chat-send-btn:focus,
.ai-chat-input:focus {
    outline: 2px solid var(--bs-primary, #4338ca);
    outline-offset: 2px;
}

/* Action Button in Messages */
.ai-action-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bs-primary, #4338ca);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.2s;
    text-decoration: none;
}

.ai-action-button:hover {
    background: var(--primary-dark, #3730a3);
    transform: translateY(-1px);
    color: white;
}
