/**
 * 🎨 DigiMSP Premium Chat Widget
 * طراحی لوکس و کاربرپسند برای چت باکس
 */

/* ==================== متغیرهای طراحی ==================== */
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --chat-bg: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --message-user: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --message-ai: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 15px 35px rgba(0, 0, 0, 0.15);
    --shadow-strong: 0 20px 40px rgba(0, 0, 0, 0.2);
    --border-radius: 20px;
    --border-radius-lg: 25px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== Container اصلی ==================== */
.digimsp-chat-widget {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 10000;
    font-family: 'Vazir', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    direction: rtl;
    font-size: 14px;
    line-height: 1.6;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* حالت بزرگ شده */
.digimsp-chat-widget.expanded {
    bottom: 20px;
    left: 20px;
}

.digimsp-chat-widget.expanded .digimsp-chat-window {
    width: 450px !important;
    height: 650px !important;
    max-height: 85vh !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
}

/* آیکون‌های toggle size */
.digimsp-chat-control-btn .icon-expand,
.digimsp-chat-control-btn .icon-collapse {
    transition: all 0.2s ease;
}

.digimsp-chat-control-btn:hover .icon-expand,
.digimsp-chat-control-btn:hover .icon-collapse {
    transform: scale(1.1);
}

/* ==================== دکمه Toggle لوکس ==================== */
.digimsp-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-gradient);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-medium);
    transition: var(--transition);
    position: absolute;
    bottom: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    z-index: 10001;
}

.digimsp-chat-toggle::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, transparent 100%);
    opacity: 0;
    transition: var(--transition);
}

.digimsp-chat-toggle:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: var(--shadow-strong);
}

.digimsp-chat-toggle:hover::before {
    opacity: 1;
}

.digimsp-chat-toggle:active {
    transform: translateY(-2px) scale(0.98);
}

.digimsp-chat-toggle svg {
    width: 28px;
    height: 28px;
    color: white;
    transition: var(--transition);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
}

.digimsp-chat-toggle .icon-close {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(180deg) scale(0.8);
}

.digimsp-chat-toggle.active .icon-chat {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(-180deg) scale(0.8);
}

.digimsp-chat-toggle.active .icon-close {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
}

/* ==================== پنجره چت لوکس ==================== */
.digimsp-chat-window {
    position: absolute;
    bottom: 75px;
    left: 0;
    width: 420px;
    height: 600px;
    background: var(--message-ai);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-strong);
    border: 1px solid rgba(255, 255, 255, 0.2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(30px) scale(0.9);
    transition: var(--transition);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    resize: both;
    min-width: 350px;
    min-height: 400px;
    max-width: 90vw;
    max-height: 80vh;
}

.digimsp-chat-widget.open .digimsp-chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ==================== هدر چت لوکس ==================== */
.digimsp-chat-header {
    background: var(--primary-gradient);
    color: white;
    padding: 20px 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
}

.digimsp-chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, transparent 100%);
    pointer-events: none;
}

.digimsp-chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1;
}

.digimsp-chat-header .status {
    font-size: 13px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.digimsp-chat-header .status-dot {
    width: 10px;
    height: 10px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse-glow 2s infinite;
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.5);
}

@keyframes pulse-glow {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1);
    }
    50% { 
        opacity: 0.7; 
        transform: scale(1.2);
    }
}

/* ==================== دکمه‌های کنترل ==================== */
.digimsp-chat-controls {
    display: flex;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.digimsp-chat-control-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    backdrop-filter: blur(10px);
}

.digimsp-chat-control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.digimsp-chat-control-btn svg {
    width: 16px;
    height: 16px;
}

/* ==================== بدنه چت ==================== */
.digimsp-chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
}

.digimsp-chat-body::-webkit-scrollbar {
    width: 6px;
}

.digimsp-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.digimsp-chat-body::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 3px;
}

.digimsp-chat-body::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.5);
}

/* ==================== پیام‌های لوکس ==================== */
.digimsp-message {
    display: flex;
    margin-bottom: 16px;
    animation: messageSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.digimsp-message.user {
    justify-content: flex-end;
}

.digimsp-message.ai {
    justify-content: flex-start;
}

.digimsp-message-content {
    max-width: 85%;
    padding: 16px 20px;
    border-radius: var(--border-radius);
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    position: relative;
    backdrop-filter: blur(10px);
}

.digimsp-message.user .digimsp-message-content {
    background: var(--message-user);
    color: white;
    border-bottom-right-radius: 8px;
    box-shadow: var(--shadow-soft);
}

.digimsp-message.ai .digimsp-message-content {
    background: var(--message-ai);
    color: #2d3748;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-bottom-left-radius: 8px;
    box-shadow: var(--shadow-soft);
}

.digimsp-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 6px;
    text-align: right;
    font-weight: 500;
}

/* ==================== Typing Indicator لوکس ==================== */
.digimsp-typing-indicator {
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--message-ai);
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: var(--shadow-soft);
    margin-bottom: 16px;
    max-width: 180px;
    backdrop-filter: blur(10px);
    white-space: nowrap;
}

.digimsp-typing-indicator.show {
    display: flex;
}

.digimsp-typing-dots {
    display: flex;
    flex-direction: row;
    gap: 6px;
    flex-shrink: 0;
}

.digimsp-typing-indicator span {
    white-space: nowrap;
    font-size: 13px;
    color: #4a5568;
}

.digimsp-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--primary-gradient);
    border-radius: 50%;
    animation: typingDotBounce 1.4s infinite ease-in-out;
}

.digimsp-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.digimsp-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingDotBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* ==================== Footer چت لوکس ==================== */
.digimsp-chat-footer {
    padding: 20px;
    background: var(--message-ai);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    gap: 12px;
    align-items: flex-end;
    backdrop-filter: blur(10px);
}

.digimsp-chat-input {
    flex: 1;
    padding: 16px 20px;
    border: 2px solid rgba(102, 126, 234, 0.2);
    border-radius: var(--border-radius);
    font-size: 15px;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.8);
    color: #2d3748;
    resize: none;
    min-height: 50px;
    max-height: 120px;
    transition: var(--transition);
    backdrop-filter: blur(10px);
}

.digimsp-chat-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
    background: rgba(255, 255, 255, 0.95);
}

.digimsp-chat-input::placeholder {
    color: #a0aec0;
    font-weight: 400;
}

.digimsp-chat-send {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: var(--border-radius);
    background: var(--primary-gradient);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: var(--shadow-soft);
}

.digimsp-chat-send:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: var(--shadow-medium);
}

.digimsp-chat-send:active {
    transform: translateY(0) scale(0.95);
}

.digimsp-chat-send:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.digimsp-chat-send svg {
    width: 22px;
    height: 22px;
}

/* ==================== Quick Actions لوکس ==================== */
.digimsp-quick-actions {
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.5);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    backdrop-filter: blur(10px);
}

.digimsp-quick-action {
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: var(--border-radius);
    font-size: 13px;
    color: #4a5568;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    font-weight: 500;
    backdrop-filter: blur(10px);
}

.digimsp-quick-action:hover {
    background: var(--primary-gradient);
    border-color: transparent;
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
}

/* ==================== Welcome Message لوکس ==================== */
.digimsp-welcome-message {
    text-align: center;
    padding: 30px 20px;
    color: #4a5568;
    font-size: 14px;
    line-height: 1.7;
    background: rgba(255, 255, 255, 0.6);
    border-radius: var(--border-radius);
    margin: 20px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.digimsp-welcome-message .welcome-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 16px;
    background: var(--primary-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: var(--shadow-soft);
}

.digimsp-welcome-message .welcome-icon svg {
    width: 28px;
    height: 28px;
}

.digimsp-welcome-message h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: #2d3748;
}

.digimsp-welcome-message p {
    margin: 0;
    opacity: 0.8;
}

/* ==================== HTML Content در پیام‌ها ==================== */
.digimsp-message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

.digimsp-message-content table th,
.digimsp-message-content table td {
    padding: 12px 16px;
    text-align: right;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.digimsp-message-content table th {
    background: var(--primary-gradient);
    color: white;
    font-weight: 600;
}

.digimsp-message-content table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.5);
}

.digimsp-message-content a {
    display: inline-block;
    padding: 10px 16px;
    background: var(--success-gradient);
    color: white !important;
    text-decoration: none;
    border-radius: var(--border-radius);
    margin: 4px 2px;
    font-size: 13px;
    font-weight: 600;
    transition: var(--transition);
    box-shadow: var(--shadow-soft);
}

.digimsp-message-content a:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
    color: white !important;
}

.digimsp-message-content button {
    display: inline-block;
    padding: 12px 20px;
    background: var(--success-gradient);
    color: white;
    text-decoration: none;
    border-radius: var(--border-radius);
    margin: 6px 4px;
    font-size: 14px;
    font-weight: 600;
    transition: var(--transition);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
}

.digimsp-message-content button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.digimsp-message-content strong {
    color: #667eea;
    font-weight: 700;
}

.digimsp-message-content ul,
.digimsp-message-content ol {
    margin: 12px 0;
    padding-right: 24px;
}

.digimsp-message-content li {
    margin: 6px 0;
    line-height: 1.6;
}

/* ==================== Error States ==================== */
.digimsp-error-message {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
    color: white;
    border: none;
    padding: 16px 20px;
    border-radius: var(--border-radius);
    font-size: 14px;
    margin: 12px 0;
    box-shadow: var(--shadow-soft);
}

/* ==================== Loading States ==================== */
.digimsp-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.digimsp-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid rgba(102, 126, 234, 0.3);
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==================== Responsive ==================== */
@media (max-width: 480px) {
    .digimsp-chat-widget {
        bottom: 20px;
        left: 20px;
        right: 20px;
    }
    
    .digimsp-chat-window {
        width: calc(100vw - 40px);
        height: 500px;
        bottom: 70px;
        left: 0;
        right: auto;
        max-width: none;
        max-height: 70vh;
    }
    
    /* حالت expanded در موبایل */
    .digimsp-chat-widget.expanded .digimsp-chat-window {
        width: calc(100vw - 20px) !important;
        height: calc(100vh - 100px) !important;
        max-height: 90vh !important;
    }
    
    .digimsp-chat-toggle {
        width: 50px;
        height: 50px;
    }
    
    .digimsp-chat-toggle svg {
        width: 24px;
        height: 24px;
    }
}

/* ==================== Resize Handle ==================== */
.digimsp-chat-window::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: linear-gradient(-45deg, transparent 30%, rgba(102, 126, 234, 0.3) 30%, rgba(102, 126, 234, 0.3) 70%, transparent 70%);
    cursor: nw-resize;
    opacity: 0;
    transition: var(--transition);
}

.digimsp-chat-window:hover::after {
    opacity: 1;
}

/* ==================== Animations ==================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.digimsp-chat-window {
    animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== Dark Mode Support ==================== */
@media (prefers-color-scheme: dark) {
    :root {
        --message-ai: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
        --chat-bg: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    }
    
    .digimsp-message.ai .digimsp-message-content {
        color: #e2e8f0;
    }
    
    .digimsp-chat-input {
        background: rgba(45, 55, 72, 0.8);
        color: #e2e8f0;
        border-color: rgba(102, 126, 234, 0.3);
    }
    
    .digimsp-chat-input::placeholder {
        color: #a0aec0;
    }
}
