/* Advanced AI Chatbot Styles with RTL Support */
#aichatbot-container {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
}

/* Positioning */
#aichatbot-container.aichatbot-bottom-right {
    bottom: 20px;
    right: 20px;
}

#aichatbot-container.aichatbot-bottom-left {
    bottom: 20px;
    left: 20px;
}

#aichatbot-container.aichatbot-top-right {
    top: 20px;
    right: 20px;
}

#aichatbot-container.aichatbot-top-left {
    top: 20px;
    left: 20px;
}

/* Chat Button */
#aichatbot-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #007cba;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    animation: pulse 2s infinite;
    position: relative;
}

#aichatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

#aichatbot-notification {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    animation: bounce 0.5s ease;
}

@keyframes pulse {
    0% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); }
    50% { box-shadow: 0 4px 16px rgba(0, 124, 186, 0.4); }
    100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}

/* Widget Container */
#aichatbot-widget {
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 40px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    position: absolute;
    bottom: 70px;
    right: 0;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* RTL Widget positioning */
#aichatbot-container.aichatbot-bottom-left #aichatbot-widget,
#aichatbot-container.aichatbot-top-left #aichatbot-widget {
    right: auto;
    left: 0;
}

#aichatbot-container.aichatbot-top-right #aichatbot-widget,
#aichatbot-container.aichatbot-top-left #aichatbot-widget {
    bottom: auto;
    top: 70px;
}

/* RTL Layout Support */
#aichatbot-widget.aichatbot-ar,
#aichatbot-widget.aichatbot-fa {
    direction: rtl;
}

#aichatbot-widget.aichatbot-ar *,
#aichatbot-widget.aichatbot-fa * {
    text-align: right;
}

/* Header */
#aichatbot-header {
    background-color: #007cba;
    color: white;
    padding: 16px 20px;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 24px;
}

#aichatbot-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

#aichatbot-language-selector {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
}

#aichatbot-language-selector option {
    background: #333;
    color: white;
}

#aichatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

#aichatbot-close:hover {
    background-color: rgba(255,255,255,0.2);
}

/* Messages Area */
#aichatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

/* Message Bubbles */
.aichatbot-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: messageSlide 0.3s ease;
    position: relative;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.aichatbot-message.user {
    background: linear-gradient(135deg, #007cba 0%, #005a8c 100%);
    color: white;
    align-self: flex-end;
    margin-left: auto;
    border-bottom-right-radius: 6px;
}

.aichatbot-message.bot {
    background: white;
    color: #333;
    align-self: flex-start;
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-bottom-left-radius: 6px;
}

/* RTL Message alignment */
.aichatbot-ar .aichatbot-message.user,
.aichatbot-fa .aichatbot-message.user {
    align-self: flex-start;
    margin-left: 0;
    margin-right: auto;
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 6px;
}

.aichatbot-ar .aichatbot-message.bot,
.aichatbot-fa .aichatbot-message.bot {
    align-self: flex-end;
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 6px;
}

/* Message metadata */
.aichatbot-message-meta {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.aichatbot-source-badge {
    background: rgba(0, 124, 186, 0.1);
    color: #007cba;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 500;
}

/* Feedback buttons */
.aichatbot-feedback {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
}

.aichatbot-feedback-btn {
    background: none;
    border: 1px solid #ddd;
    padding: 4px 8px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.aichatbot-feedback-btn:hover {
    background: #f0f0f0;
}

.aichatbot-feedback-btn.active {
    background: #007cba;
    color: white;
    border-color: #007cba;
}

.aichatbot-feedback-btn.positive.active {
    background: #00a32a;
    border-color: #00a32a;
}

.aichatbot-feedback-btn.negative.active {
    background: #d63638;
    border-color: #d63638;
}

/* Typing Indicator */
.aichatbot-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background-color: white;
    border: 1px solid #e0e0e0;
    border-radius: 18px;
    align-self: flex-start;
    max-width: 80px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    animation: messageSlide 0.3s ease;
}

.aichatbot-typing-dots {
    display: flex;
    gap: 4px;
}

.aichatbot-typing-dot {
    width: 8px;
    height: 8px;
    background-color: #999;
    border-radius: 50%;
    animation: typingDot 1.4s infinite ease-in-out;
}

.aichatbot-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.aichatbot-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingDot {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Input Area */
#aichatbot-input-container {
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    align-items: center;
    background: white;
    border-radius: 0 0 12px 12px;
}

#aichatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
    background: #f8f9fa;
}

#aichatbot-input:focus {
    border-color: #007cba;
    background: white;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.1);
}

#aichatbot-input::placeholder {
    color: #999;
}

/* RTL Input */
.aichatbot-ar #aichatbot-input,
.aichatbot-fa #aichatbot-input {
    direction: rtl;
    text-align: right;
}

#aichatbot-send {
    background-color: #007cba;
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 50px;
    justify-content: center;
}

#aichatbot-send:hover {
    background-color: #005a8c;
    transform: translateY(-1px);
}

#aichatbot-send:active {
    transform: translateY(0);
}

#aichatbot-send:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Footer */
#aichatbot-footer {
    padding: 8px 20px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    background: #f8f9fa;
    border-radius: 0 0 12px 12px;
}

#aichatbot-footer small {
    color: #666;
    font-size: 11px;
}

/* Lead Capture Form */
.aichatbot-lead-form {
    background: linear-gradient(135deg, #f8f9ff 0%, #e8f4fd 100%);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid #d0e7ff;
    margin: 8px 0;
    animation: messageSlide 0.3s ease;
}

.aichatbot-lead-form h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #333;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.aichatbot-lead-form input {
    width: 100%;
    padding: 10px 12px;
    margin: 6px 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 13px;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
}

.aichatbot-lead-form input:focus {
    border-color: #007cba;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.1);
}

.aichatbot-lead-form input::placeholder {
    color: #999;
}

/* RTL Lead form */
.aichatbot-ar .aichatbot-lead-form input,
.aichatbot-fa .aichatbot-lead-form input {
    direction: rtl;
    text-align: right;
}

.aichatbot-lead-form button {
    background: linear-gradient(135deg, #007cba 0%, #005a8c 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    margin-top: 8px;
    transition: all 0.2s ease;
    width: 100%;
}

.aichatbot-lead-form button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 124, 186, 0.3);
}

.aichatbot-lead-form button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Language Selection Dialog */
.aichatbot-language-dialog {
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    margin: 10px 0;
    text-align: center;
    animation: messageSlide 0.3s ease;
}

.aichatbot-language-dialog h4 {
    margin: 0 0 15px 0;
    font-size: 15px;
    color: #333;
}

.aichatbot-language-options {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.aichatbot-language-btn {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px solid #dee2e6;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 80px;
}

.aichatbot-language-btn:hover {
    background: linear-gradient(135deg, #007cba 0%, #005a8c 100%);
    color: white;
    border-color: #007cba;
    transform: translateY(-1px);
}

/* Error/Success Messages */
.aichatbot-system-message {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    text-align: center;
    margin: 8px 0;
    animation: messageSlide 0.3s ease;
}

.aichatbot-system-message.error {
    background: #ffe6e6;
    color: #d63638;
    border: 1px solid #ffcccc;
}

.aichatbot-system-message.success {
    background: #e6ffe6;
    color: #00a32a;
    border: 1px solid #ccffcc;
}

.aichatbot-system-message.info {
    background: #e6f3ff;
    color: #135e96;
    border: 1px solid #cce6ff;
}

/* Loading States */
.aichatbot-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #666;
    padding: 8px 0;
}

.aichatbot-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007cba;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Message Actions */
.aichatbot-message-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 11px;
}

.aichatbot-timestamp {
    color: #999;
}

/* Scrollbar Styling */
#aichatbot-messages::-webkit-scrollbar {
    width: 6px;
}

#aichatbot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

#aichatbot-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

#aichatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Responsive Design */
@media (max-width: 768px) {
    #aichatbot-widget {
        width: calc(100vw - 20px);
        height: calc(100vh - 20px);
        position: fixed;
        top: 10px;
        right: 10px;
        left: 10px;
        bottom: 10px;
        border-radius: 8px;
        max-width: none;
        max-height: none;
    }
    
    #aichatbot-container.aichatbot-bottom-left #aichatbot-widget,
    #aichatbot-container.aichatbot-top-left #aichatbot-widget,
    #aichatbot-container.aichatbot-top-right #aichatbot-widget,
    #aichatbot-container.aichatbot-bottom-right #aichatbot-widget {
        right: 10px;
        left: 10px;
        top: 10px;
        bottom: 10px;
    }
    
    #aichatbot-button {
        width: 50px;
        height: 50px;
    }
    
    .aichatbot-message {
        max-width: 90%;
        font-size: 13px;
    }
    
    #aichatbot-header {
        padding: 12px 16px;
    }
    
    #aichatbot-header h3 {
        font-size: 14px;
    }
    
    #aichatbot-messages {
        padding: 16px;
    }
    
    #aichatbot-input-container {
        padding: 12px 16px;
    }
    
    .aichatbot-language-options {
        flex-direction: column;
        gap: 8px;
    }
    
    .aichatbot-language-btn {
        width: 100%;
    }
}

/* Small screen adjustments */
@media (max-width: 480px) {
    #aichatbot-button {
        width: 45px;
        height: 45px;
    }
    
    #aichatbot-header h3 {
        font-size: 13px;
    }
    
    .aichatbot-message {
        padding: 10px 14px;
        font-size: 12px;
    }
    
    #aichatbot-input {
        font-size: 13px;
        padding: 10px 14px;
    }
    
    .aichatbot-feedback {
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .aichatbot-feedback-btn {
        padding: 3px 6px;
        font-size: 11px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    #aichatbot-widget {
        border: 2px solid #000;
    }
    
    .aichatbot-message.bot {
        border: 2px solid #333;
    }
    
    #aichatbot-input {
        border: 2px solid #333;
    }
    
    .aichatbot-feedback-btn {
        border: 2px solid #333;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    #aichatbot-button {
        animation: none;
    }
    
    .aichatbot-message {
        animation: none;
    }
    
    #aichatbot-widget {
        animation: none;
    }
    
    .aichatbot-typing-dot {
        animation: none;
    }
    
    .aichatbot-spinner {
        animation: none;
    }
    
    * {
        transition: none !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #aichatbot-widget {
        background: #1a1a1a;
        border-color: #333;
    }
    
    #aichatbot-messages {
        background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    }
    
    .aichatbot-message.bot {
        background: #333;
        color: #fff;
        border-color: #444;
    }
    
    #aichatbot-input {
        background: #333;
        border-color: #444;
        color: #fff;
    }
    
    #aichatbot-input::placeholder {
        color: #999;
    }
    
    #aichatbot-footer {
        background: #2a2a2a;
        border-color: #333;
    }
    
    .aichatbot-lead-form {
        background: linear-gradient(135deg, #2a2a3a 0%, #1a1a2a 100%);
        border-color: #444;
    }
    
    .aichatbot-lead-form input {
        background: #333;
        border-color: #444;
        color: #fff;
    }
    
    .aichatbot-language-dialog {
        background: #333;
        border-color: #444;
        color: #fff;
    }
    
    .aichatbot-typing {
        background: #333;
        border-color: #444;
    }
}

/* Print styles */
@media print {
    #aichatbot-container {
        display: none !important;
    }
}

/* Focus indicators for accessibility */
#aichatbot-button:focus,
#aichatbot-input:focus,
#aichatbot-send:focus,
#aichatbot-close:focus,
.aichatbot-feedback-btn:focus,
.aichatbot-language-btn:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* Screen reader only content */
.aichatbot-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Custom properties for easy theming */
:root {
    --aichatbot-primary-color: #007cba;
    --aichatbot-primary-dark: #005a8c;
    --aichatbot-success-color: #00a32a;
    --aichatbot-error-color: #d63638;
    --aichatbot-border-color: #e0e0e0;
    --aichatbot-background: #f8f9fa;
    --aichatbot-text-color: #333;
    --aichatbot-border-radius: 12px;
    --aichatbot-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}