/**
 * Online Chat System Styles
 * استایل‌های سیستم چت آنلاین فروشگاه
 */

/* ========================
   Chat Button (Floating)
   ======================== */

.online-chat-button {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    z-index: 9999;
    font-size: 24px;
    border: none;
}

.online-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(102, 126, 234, 0.6);
}

.online-chat-button .chat-text {
    display: none;
    margin-right: 8px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

/* Expanded state */
.online-chat-button.expanded {
    width: auto;
    padding: 15px 20px;
    border-radius: 30px;
}

.online-chat-button.expanded .chat-text {
    display: inline;
}

/* Animation */
@keyframes chatButtonPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.online-chat-button.pulse {
    animation: chatButtonPulse 2s infinite;
}

/* ========================
   Chat Box Container
   ======================== */

.chat-box {
    position: fixed;
    bottom: 100px;
    left: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 500px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    z-index: 9998;
    font-family: 'IRANSans', Tahoma, Arial, sans-serif;
    overflow: hidden;
    border: 1px solid #e1e5e9;
}

/* Chat Box Header */
.chat-box-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 15px 15px 0 0;
    font-weight: 600;
    font-size: 16px;
}

.chat-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s ease;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Chat Box Content */
.chat-box-content {
    flex: 1;
    padding: 20px;
    background: #f8f9fa;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Chat Box Footer */
.chat-box-footer {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e1e5e9;
    display: flex;
    gap: 10px;
    align-items: center;
    border-radius: 0 0 15px 15px;
}

/* ========================
   User Registration Form
   ======================== */

.chat-user-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chat-form-title {
    text-align: center;
    color: #495057;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 14px;
}

.chat-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e1e5e9;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
    background: white;
    box-sizing: border-box;
}

.chat-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input::placeholder {
    color: #adb5bd;
}

/* Submit Button */
.chat-submit-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
}

.chat-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.chat-submit-btn:disabled {
    background: #adb5bd;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Error Message */
.chat-error-message {
    background: #ffe6e6;
    color: #dc3545;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 13px;
    display: none;
    border: 1px solid #ffb3b3;
    text-align: center;
}

/* Success Message */
.chat-success-message {
    background: #e6ffe6;
    color: #28a745;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 13px;
    border: 1px solid #b3ffb3;
    text-align: center;
    margin-bottom: 15px;
}

/* ========================
   Chat Messages
   ======================== */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 300px;
}

.chat-message {
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User Message (Right aligned) */
.chat-message.user {
    align-items: flex-end;
}

.chat-message.user .message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 18px 18px 5px 18px;
    max-width: 80%;
}

/* Support Message (Left aligned) */
.chat-message.support {
    align-items: flex-start;
}

.chat-message.support .message-bubble {
    background: white;
    color: #495057;
    border: 1px solid #e1e5e9;
    border-radius: 18px 18px 18px 5px;
    max-width: 80%;
}

/* Message Bubble */
.message-bubble {
    padding: 12px 16px;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
}

/* Message Meta */
.message-meta {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    padding: 0 5px;
}

.chat-message.user .message-meta {
    text-align: right;
    color: #666;
}

.chat-message.support .message-meta {
    text-align: left;
    color: #666;
}

/* System Message */
.system-message {
    text-align: center;
    padding: 8px 12px;
    background: rgba(108, 117, 125, 0.1);
    border-radius: 12px;
    font-size: 12px;
    color: #6c757d;
    margin: 8px 0;
}

/* Welcome Message */
.welcome-message {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border: 1px solid #90caf9;
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    margin-bottom: 15px;
}

.welcome-message h4 {
    color: #1976d2;
    margin: 0 0 8px 0;
    font-size: 16px;
}

.welcome-message p {
    color: #424242;
    margin: 0;
    font-size: 14px;
}

/* ========================
   Typing Indicator
   ======================== */

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: #6c757d;
    font-size: 13px;
    font-style: italic;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6c757d;
    animation: typingDot 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.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);
        opacity: 1;
    }
}

/* ========================
   Connection Status
   ======================== */

.connection-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.connection-status.connected {
    background: #d4edda;
    color: #155724;
}

.connection-status.connecting {
    background: #fff3cd;
    color: #856404;
}

.connection-status.disconnected {
    background: #f8d7da;
    color: #721c24;
}

.connection-status i {
    font-size: 10px;
}

/* ========================
   Loading States
   ======================== */

.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 15px;
    color: #6c757d;
    font-size: 14px;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e9ecef;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========================
   Responsive Design
   ======================== */

@media (max-width: 480px) {
    .chat-box {
        width: calc(100vw - 20px);
        left: 10px;
        bottom: 150px; /* بالاتر از دکمه چت */
        height: 450px;
    }
    
    .online-chat-button {
        bottom: 90px; /* همخوانی با تنظیمات اصلی */
        left: 15px !important;
        right: auto !important;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .chat-box-content {
        padding: 15px;
    }
    
    .chat-box-footer {
        padding: 12px 15px;
    }
    
    .message-bubble {
        max-width: 90%;
    }
}

@media (max-width: 320px) {
    .chat-box {
        height: 400px;
    }
    
    .chat-input {
        font-size: 13px;
        padding: 10px 12px;
    }
    
    .chat-submit-btn {
        font-size: 13px;
        padding: 10px 16px;
    }
}

/* ========================
   Dark Mode Support
   ======================== */

@media (prefers-color-scheme: dark) {
    .chat-box {
        background: #2c2c2c;
        border-color: #404040;
    }
    
    .chat-box-content {
        background: #363636;
    }
    
    .chat-box-footer {
        background: #2c2c2c;
        border-color: #404040;
    }
    
    .chat-input {
        background: #404040;
        border-color: #555;
        color: white;
    }
    
    .chat-input::placeholder {
        color: #aaa;
    }
    
    .chat-message.support .message-bubble {
        background: #404040;
        border-color: #555;
        color: #e9ecef;
    }
    
    .chat-form-title {
        color: #e9ecef;
    }
    
    .message-meta {
        color: #aaa !important;
    }
    
    .system-message {
        background: rgba(255, 255, 255, 0.1);
        color: #aaa;
    }
}

/* ========================
   Accessibility
   ======================== */

.chat-box *:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.chat-box button:focus {
    outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
    .chat-box,
    .online-chat-button,
    .message-bubble,
    .loading-spinner {
        animation: none;
        transition: none;
    }
}

/* Screen reader only content */
.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;
}

/* ========================
   Print Styles
   ======================== */

@media print {
    .online-chat-button,
    .chat-box {
        display: none !important;
    }
}

/* ========================
   High Contrast Mode
   ======================== */

@media (prefers-contrast: high) {
    .chat-box {
        border: 3px solid #000;
    }
    
    .chat-input {
        border: 2px solid #000;
    }
    
    .chat-submit-btn {
        border: 2px solid #000;
    }
    
    .message-bubble {
        border: 1px solid #000;
    }
}

/* ========================
   RTL Support
   ======================== */

[dir="rtl"] .chat-box {
    left: 20px;
    right: auto;
}

[dir="rtl"] .online-chat-button {
    left: 20px;
    right: auto;
}

[dir="rtl"] .chat-message.user {
    align-items: flex-start;
}

[dir="rtl"] .chat-message.support {
    align-items: flex-end;
}

[dir="rtl"] .chat-message.user .message-bubble {
    border-radius: 18px 18px 18px 5px;
}

[dir="rtl"] .chat-message.support .message-bubble {
    border-radius: 18px 18px 5px 18px;
}

/* ========================
   Custom Scrollbar
   ======================== */

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ========================
   Additional Animations
   ======================== */

@keyframes chatBoxSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-box.show {
    animation: chatBoxSlideUp 0.3s ease;
}

/* Notification badge for chat button */
.online-chat-button::after {
    content: '';
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background: #ff4757;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 10px;
    font-weight: bold;
    border: 2px solid white;
}

.online-chat-button.has-notification::after {
    display: flex;
    content: attr(data-count);
}

/* ========================
   Utility Classes
   ======================== */

.chat-hidden {
    display: none !important;
}

.chat-visible {
    display: block !important;
}

.chat-flex {
    display: flex !important;
}

.chat-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.chat-error-state {
    background: #ffe6e6;
    border: 1px solid #ffb3b3;
    color: #dc3545;
    padding: 20px;
    text-align: center;
    border-radius: 8px;
}

.chat-success-state {
    background: #e6ffe6;
    border: 1px solid #b3ffb3;
    color: #28a745;
    padding: 20px;
    text-align: center;
    border-radius: 8px;
} 