/* ============================================
   ROOT VARIABLES
   ============================================ */
:root {
    --chat-primary: #dc2626;
    --chat-primary-dark: #991b1b;
    --chat-primary-darker: #7f1d1d;
    --chat-primary-light: #fee2e2;
    --chat-primary-lighter: #fef2f2;
    --chat-secondary: #f97316;
    --chat-success: #22c55e;
    --chat-info: #3b82f6;
    --chat-warning: #eab308;
    --chat-bg: #f8fafc;
    --chat-text: #1e293b;
    --chat-text-light: #64748b;
    --chat-border: #e2e8f0;
    --chat-shadow: rgba(220, 38, 38, 0.15);
    --chat-radius: 16px;
    --chat-font: 'IRANSans', 'Vazirmatn', 'Tahoma', Arial, sans-serif;
}

/* ============================================
   دکمه چت - سمت چپ
   ============================================ */
.chat-toggle {
    position: fixed !important;
    bottom: 30px !important;
    left: 30px !important;
    right: auto !important;
    top: auto !important;
    z-index: 9998 !important;
    
    transform: none !important;
    contain: layout style;
    
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 20px;
    cursor: pointer;
    font-family: var(--chat-font);
    font-size: 14px;
    font-weight: 600;
    direction: rtl;
    display: flex !important;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 32px rgba(220, 38, 38, 0.4);
    transition: all 0.3s ease;
    overflow: visible;
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    will-change: auto;
}

.chat-toggle:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 12px 40px rgba(220, 38, 38, 0.5);
}

.chat-toggle:active {
    transform: scale(0.95) !important;
}

.toggle-content {
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-text {
    white-space: nowrap;
}

.unread-badge {
    position: absolute !important;
    top: -6px !important;
    right: -6px !important;
    left: auto !important;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: badgePulse 2s infinite;
    z-index: 1;
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.toggle-ripple {
    position: absolute;
    inset: -4px;
    border-radius: 50px;
    border: 2px solid var(--chat-primary);
    opacity: 0;
    animation: rippleAnimation 3s infinite;
    pointer-events: none;
}

@keyframes rippleAnimation {
    0% { opacity: 0.6; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.3); }
}

/* ============================================
   ویجت چت
   ============================================ */
.chat-widget {
    position: fixed !important;
    bottom: 24px !important;
    left: 24px !important;
    right: auto !important;
    top: auto !important;
    z-index: 9999 !important;
    contain: layout style;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    max-width: calc(100vw - 48px);
    background: white;
    border-radius: var(--chat-radius);
    box-shadow: 0 20px 60px var(--chat-shadow), 0 0 0 1px rgba(220, 38, 38, 0.05);
    flex-direction: column;
    font-family: var(--chat-font);
    direction: rtl;
    overflow: hidden;
    transform-origin: bottom left;
    display: none !important;
}

.chat-widget.active {
    display: flex !important;
    animation: widgetPopIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes widgetPopIn {
    0% {
        opacity: 0;
        transform: scale(0.5) translateY(40px) translateX(-20px);
    }
    60% {
        transform: scale(1.02) translateY(-5px) translateX(0);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0) translateX(0);
    }
}

@keyframes widgetPopOut {
    0% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    100% {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
}

.chat-widget.minimized {
    height: 60px;
    overflow: hidden;
}

/* ============================================
   هدر چت
   ============================================ */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 50%, var(--chat-primary-darker) 100%);
    color: white;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    min-height: 60px;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 100%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.08) 0%, transparent 70%);
    pointer-events: none;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1;
}

.bot-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar-icon {
    font-size: 28px;
    line-height: 1;
}

.online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: var(--chat-success);
    border-radius: 50%;
    border: 2px solid var(--chat-primary-dark);
    animation: onlinePulse 2s infinite;
}

@keyframes onlinePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.header-text h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
}

.status-text {
    font-size: 11px;
    opacity: 0.85;
}

.header-actions {
    display: flex;
    gap: 6px;
    z-index: 1;
}

.header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 8px;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    transition: background 0.2s;
}

.header-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* ============================================
   ناحیه پیام‌ها
   ============================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 0;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.message {
    max-width: 85%;
    clear: both;
    animation: messageSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes messageSlideIn {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.85);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.user {
    align-self: flex-end;
}

.message.bot,
.message.system {
    align-self: flex-start;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.7;
    font-size: 13.5px;
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: white;
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 6px;
    box-shadow: 0 3px 12px rgba(220, 38, 38, 0.25);
}

.message.bot .message-content {
    background: white;
    color: var(--chat-text);
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid var(--chat-border);
}

.message.system .message-content {
    background: rgba(0,0,0,0.04);
    color: var(--chat-text-light);
    font-size: 12px;
    border-radius: 12px;
    text-align: center;
    padding: 8px 16px;
}

.message-time {
    font-size: 10px;
    margin-top: 4px;
    color: var(--chat-text-light);
}

.message.user .message-time {
    text-align: left;
    color: rgba(0,0,0,0.4);
}

/* ============================================
   تایپینگ ایندیکیتور
   ============================================ */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: white;
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.typing-avatar {
    font-size: 20px;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    background: var(--chat-primary);
    border-radius: 50%;
    animation: dotBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.typing-text {
    font-size: 12px;
    color: var(--chat-text-light);
}

/* ============================================
   پیشنهاد تیکت
   ============================================ */
.ticket-suggestion {
    background: #fffbeb;
    border-top: 1px solid #fde68a;
    padding: 10px 16px;
    flex-shrink: 0;
}

.ticket-content {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.ticket-icon {
    font-size: 18px;
}

.ticket-text {
    flex: 1;
    color: #92400e;
}

.ticket-btn {
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 12px;
    font-family: var(--chat-font);
    cursor: pointer;
    transition: background 0.2s;
}

.ticket-btn:hover {
    background: var(--chat-primary-dark);
}

/* ============================================
   ناحیه ورودی
   ============================================ */
.chat-input-area {
    background: white;
    border-top: 1px solid var(--chat-border);
    padding: 12px 16px 8px;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: #f1f5f9;
    border-radius: 24px;
    padding: 4px 8px;
    gap: 6px;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--chat-primary);
    background: white;
}

.emoji-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: background 0.2s;
    flex-shrink: 0;
}

.emoji-btn:hover {
    background: #e2e8f0;
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 8px;
    font-size: 14px;
    font-family: var(--chat-font);
    direction: rtl;
    outline: none;
    color: var(--chat-text);
    min-width: 0;
}

#message-input::placeholder {
    color: #94a3b8;
}

#message-input:disabled {
    opacity: 0.5;
}

.send-btn {
    background: var(--chat-primary);
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--chat-primary-dark);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.emoji-picker {
    padding: 10px 0;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    text-align: center;
}

.emoji-grid span {
    font-size: 22px;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background 0.15s;
}

.emoji-grid span:hover {
    background: #f1f5f9;
}

.powered-by {
    text-align: center;
    font-size: 11px;
    color: var(--chat-text-light);
    padding: 6px 0 2px;
    opacity: 0.7;
}

/* ============================================
   نوتیفیکیشن
   ============================================ */
.chat-notification {
    position: fixed !important;
    bottom: 100px !important;
    left: 24px !important;
    right: auto !important;
    top: auto !important;
    z-index: 10000 !important;
    max-width: 320px;
    display: none !important;
}

.chat-notification.show {
    display: block !important;
    animation: notifSlideIn 0.4s ease;
}

.chat-notification.hide {
    animation: notifFadeOut 0.3s ease-out forwards;
}

@keyframes notifSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0) translateX(0);
    }
}

@keyframes notifFadeOut {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(10px);
    }
}

.notification-content {
    background: white;
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    direction: rtl;
    cursor: pointer;
}

.notification-avatar {
    font-size: 28px;
    flex-shrink: 0;
}

.notification-text {
    flex: 1;
    min-width: 0;
}

.notification-text strong {
    display: block;
    font-size: 13px;
    color: var(--chat-text);
    margin-bottom: 2px;
}

.notification-text p {
    margin: 0;
    font-size: 12px;
    color: var(--chat-text-light);
}

.notification-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #94a3b8;
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.2s;
}

.notification-close:hover {
    color: #ef4444;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .chat-toggle {
        bottom: 20px !important;
        left: 20px !important;
        padding: 12px !important;
        border-radius: 50% !important;
        width: 50px !important;
        height: 50px !important;
        justify-content: center !important;
    }
    
    .toggle-text {
        display: none !important;
    }
    
    .toggle-icon {
        width: 24px !important;
        height: 24px !important;
        margin: 0 !important;
    }
    
    .toggle-icon svg {
        width: 24px !important;
        height: 24px !important;
    }
    
    .chat-widget {
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
    
    .chat-notification {
        left: 16px !important;
        right: 16px !important;
        bottom: 80px !important;
        max-width: calc(100% - 32px) !important;
    }
}

@media (max-width: 480px) {
    .chat-toggle {
        bottom: 16px !important;
        left: 16px !important;
        width: 44px !important;
        height: 44px !important;
        padding: 10px !important;
    }
    
    .toggle-icon {
        width: 20px !important;
        height: 20px !important;
    }
    
    .toggle-icon svg {
        width: 20px !important;
        height: 20px !important;
    }
    
    .unread-badge {
        width: 18px !important;
        height: 18px !important;
        font-size: 9px !important;
        top: -4px !important;
        right: -4px !important;
    }
    
    .chat-header {
        padding: 10px 14px !important;
        min-height: 50px !important;
    }
    
    .header-text h4 {
        font-size: 12px !important;
    }
    
    .status-text {
        font-size: 9px !important;
    }
    
    .bot-avatar {
        width: 32px !important;
        height: 32px !important;
    }
    
    .avatar-icon {
        font-size: 20px !important;
    }
    
    .online-dot {
        width: 7px !important;
        height: 7px !important;
    }
    
    .message-content {
        font-size: 12.5px !important;
        padding: 10px 14px !important;
    }
    
    .chat-input-area {
        padding: 8px 12px 4px !important;
    }
    
    #message-input {
        font-size: 13px !important;
        padding: 8px 6px !important;
    }
    
    .send-btn {
        width: 34px !important;
        height: 34px !important;
    }
    
    .send-btn svg {
        width: 18px !important;
        height: 18px !important;
    }
    
    .chat-notification {
        left: 12px !important;
        right: 12px !important;
        bottom: 70px !important;
        max-width: calc(100% - 24px) !important;
    }
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 20px 16px;
}

.welcome-emoji {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
    animation: welcomeBounce 0.6s ease-out;
}

@keyframes welcomeBounce {
    0% { transform: scale(0); }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.welcome-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--chat-text);
    margin-bottom: 6px;
}

.welcome-subtitle {
    font-size: 13px;
    color: var(--chat-text-light);
}

.shimmer {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.date-separator {
    text-align: center;
    margin: 8px 0;
}

.date-separator span {
    background: rgba(0,0,0,0.06);
    color: var(--chat-text-light);
    font-size: 11px;
    padding: 4px 14px;
    border-radius: 12px;
    display: inline-block;
}