@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700&display=swap');

:root {
    --ds-primary: #2563eb;
    --ds-primary-dark: #1d4ed8;
    --ds-primary-light: #60a5fa;
    --ds-secondary: #475569;
    --ds-bg-white: #ffffff;
    --ds-bg-light: #f8fafc;
    --ds-bg-chat: #f1f5f9;
    --ds-text-dark: #0f172a;
    --ds-text-gray: #64748b;
    --ds-border: #e2e8f0;
    --ds-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --ds-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --ds-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --ds-radius-lg: 16px;
    --ds-radius-xl: 24px;
    --ds-font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
    --ds-z-modal: 9999999;
    --ds-z-widget: 9999998;
    --ds-z-bubble: 9999990;
}

/* Reset */
#ds-chat-container *, #ds-lead-modal *, #ds-chat-widget * {
    box-sizing: border-box; margin: 0; padding: 0; border: 0; 
    font-family: var(--ds-font-family);
    -webkit-font-smoothing: antialiased;
    direction: rtl;
    text-align: right;
}

/* Bubble Button */
#ds-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--ds-primary), var(--ds-primary-dark));
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.3);
    z-index: var(--ds-z-bubble);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 2px solid rgba(255,255,255,0.2);
    outline: none;
}

#ds-chat-bubble:hover {
    transform: scale(1.1) translateY(-4px);
    box-shadow: 0 12px 32px rgba(37, 99, 235, 0.4);
}

#ds-chat-bubble svg {
    width: 30px;
    height: 30px;
    color: white;
    transition: transform 0.3s ease;
}

#ds-chat-bubble:hover svg {
    transform: rotate(15deg);
}

/* --- Centered Lead Modal (Glassmorphism) --- */
#ds-lead-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: var(--ds-z-modal);
    display: none; /* JS toggles flex */
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#ds-lead-modal-content {
    width: 100%;
    max-width: 380px;
    background: var(--ds-bg-white);
    border-radius: var(--ds-radius-xl);
    box-shadow: var(--ds-shadow-xl);
    overflow: hidden;
    position: relative;
    animation: modalUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid rgba(255,255,255,0.5);
}

@keyframes modalUp {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.ds-modal-header {
    background: linear-gradient(135deg, var(--ds-primary), var(--ds-primary-dark));
    padding: 30px 24px;
    text-align: center;
    color: white;
}

.ds-modal-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: white;
}

.ds-modal-header p {
    font-size: 0.9rem;
    opacity: 0.9;
    color: white;
}

.ds-modal-close {
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    font-size: 24px;
    line-height: 1;
    z-index: 10;
}

.ds-modal-close:hover {
    background: rgba(255,255,255,0.3);
}

.ds-modal-body {
    padding: 30px 24px;
}

.ds-form-group {
    margin-bottom: 16px;
}

.ds-form-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--ds-border);
    border-radius: 12px;
    font-size: 1rem;
    background: var(--ds-bg-light);
    transition: all 0.2s ease;
    text-align: right;
    color: var(--ds-text-dark);
}

.ds-form-group input:focus {
    outline: none;
    border-color: var(--ds-primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.ds-btn-primary {
    width: 100%;
    padding: 14px;
    margin-top: 10px;
    background: linear-gradient(135deg, var(--ds-primary), var(--ds-primary-dark));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.ds-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.3);
}

.ds-btn-primary:disabled {
    opacity: 0.7;
    transform: none;
    cursor: not-allowed;
}

/* --- Chat Widget --- */
#ds-chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--ds-bg-white);
    border-radius: var(--ds-radius-lg);
    z-index: var(--ds-z-widget);
    display: none;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(0,0,0,0.05);
    animation: widgetUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes widgetUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.ds-chat-header {
    background: linear-gradient(135deg, var(--ds-primary), var(--ds-primary-dark));
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
}

.ds-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ds-online-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.2);
}

.ds-chat-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: white;
}

.ds-close-chat {
    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;
    font-size: 20px;
    line-height: 1;
    transition: background 0.2s;
}

.ds-close-chat:hover {
    background: rgba(255,255,255,0.3);
}

.ds-chat-body {
    flex: 1;
    padding: 20px;
    background: var(--ds-bg-chat);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Message Bubbles */
.ds-message-row {
    display: flex;
    width: 100%;
}

.ds-message-row.user {
    justify-content: flex-start; /* User right (RTL start) */
}

.ds-message-row.assistant {
    justify-content: flex-end; /* Bot left (RTL end) */
}

.ds-chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    box-shadow: var(--ds-shadow-sm);
    text-align: justify;
    text-justify: inter-word;
}

.ds-message-row.user .ds-chat-message {
    background: var(--ds-primary);
    background: linear-gradient(135deg, var(--ds-primary), var(--ds-primary-dark));
    color: white;
    border-bottom-right-radius: 4px;
    text-align: right;
}

.ds-message-row.assistant .ds-chat-message {
    background: white;
    color: var(--ds-text-dark);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--ds-border);
}

/* Footer */
.ds-chat-footer {
    padding: 16px;
    background: white;
    border-top: 1px solid var(--ds-border);
}

.ds-chat-footer form {
    display: flex;
    gap: 10px;
    align-items: center;
}

#ds-message-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--ds-border);
    border-radius: 24px;
    background: var(--ds-bg-light);
    font-size: 0.95rem;
    transition: all 0.2s;
    outline: none;
}

#ds-message-input:focus {
    background: white;
    border-color: var(--ds-primary-light);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#ds-chat-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--ds-primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
    flex-shrink: 0;
}

#ds-chat-send:hover:not(:disabled) {
    transform: scale(1.05);
    background: var(--ds-primary-dark);
}

#ds-chat-send svg {
    transform: rotate(180deg); /* Flip for RTL */
}

/* Loading Dots */
.typing-dots { display: flex; gap: 4px; padding: 4px; }
.typing-dots span { width: 6px; height: 6px; background: #94a3b8; border-radius: 50%; animation: typing 1.4s infinite ease-in-out both; }
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* Mobile */
@media (max-width: 480px) {
    #ds-chat-widget { width: 100%; height: 100%; max-height: 100%; bottom: 0; right: 0; border-radius: 0; }
    #ds-lead-modal-content { width: 90%; }
}