/* Reset and Base Styles */
.tp-chat * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Welcome Notice */
#tp-chat-notice {
    position: fixed;
    bottom: calc(65px + 25px);
    right: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
    z-index: 10000;
    max-width: 280px;
    font-size: 14px;
    font-family: system-ui, -apple-system, sans-serif;
    display: none;
    animation: slideInRight 0.5s ease-out;
    line-height: 1.4;
    backdrop-filter: blur(10px);
}

#tp-chat-notice-close {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    float: left;
    margin-right: 10px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

#tp-chat-notice-close:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
}

/* Chat Icon */
#tp-chat-icon {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 65px;
    height: 65px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 3px solid rgba(255,255,255,0.1);
}

#tp-chat-icon:hover {
    transform: scale(1.15) rotate(5deg);
    box-shadow: 0 12px 40px rgba(102, 126, 234, 0.4);
}

#tp-chat-icon.active {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    transform: scale(1.1);
}

#tp-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e53e3e;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 11px;
    font-weight: bold;
    display: none;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
    border: 2px solid #1e2a3a;
    box-shadow: 0 2px 8px rgba(229, 62, 62, 0.4);
}

/* Main Chat Box - INITIALLY HIDDEN */
#tp-chat-box {
    position: fixed;
    bottom: 100px;
    right: 25px;
    width: 380px;
    height: 520px;
    background: #1e2a3a;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    z-index: 10002;
    display: none;
    flex-direction: column;
    font-family: system-ui, -apple-system, sans-serif;
    border: 1px solid #344050;
    overflow: hidden;
    backdrop-filter: blur(20px);
    opacity: 1 !important;
    visibility: visible !important;
}

/* ✅ کلاس برای حالت باز */
#tp-chat-box.tp-chat-open {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: scale(1) translateY(0) !important;
}

/* Chat Header - FIXED HEIGHT AND OVERFLOW */
#tp-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
    min-height: 60px;
    max-height: 60px;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
}

.tp-chat-title {
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1;
    margin: 0;
    padding: 0;
}

#tp-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #28a745;
    display: inline-block;
    animation: statusPulse 2s infinite;
    flex-shrink: 0;
}

.tp-chat-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
}

#tp-chat-close {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

#tp-chat-close:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
}

/* Messages Container - FLEXIBLE HEIGHT */
#tp-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: #1e2a3a;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    scroll-behavior: smooth;
    position: relative;
    z-index: 1;
}

/* Input Area - INCREASED HEIGHT - NO SCROLL */
#tp-chat-inputs {
    background: #2d3748;
    border-top: 1px solid #344050;
    flex-shrink: 0;
    height: 150px;
    min-height: 150px;
    max-height: 150px;
    position: relative;
    z-index: 30;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0;
}

/* Quick Actions - FIXED HEIGHT WITH SCROLL */
#tp-quick-actions {
    padding: 12px 20px 8px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    height: auto;
    min-height: 60px;
    max-height: 70px;
    overflow-y: auto;
    align-items: flex-start;
    flex-shrink: 0;
    background: #2d3748;
}

.tp-quick-btn {
    background: #4a5568;
    color: #e2e8f0;
    border: none;
    padding: 8px 14px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    font-weight: 500;
    flex-shrink: 0;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.tp-quick-btn:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* Chat Controls - ADJUSTED HEIGHT - NO SCROLL */
#tp-chat-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    height: 70px;
    min-height: 70px;
    max-height: 70px;
    padding: 15px 20px;
    flex-shrink: 0;
    overflow: hidden;
    background: #2d3748;
}

#tp-chat-message {
    flex: 1;
    background: #4a5568;
    border: 1px solid #4a5568;
    color: #e2e8f0;
    border-radius: 20px;
    padding: 12px 16px;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    min-height: 40px;
    max-height: 40px;
    transition: all 0.3s ease;
    line-height: 1.4;
    height: 40px;
    overflow: hidden;
}

#tp-chat-message:focus {
    outline: none;
    border-color: #667eea;
    background: #3a4555;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#tp-chat-message::placeholder {
    color: #a0aec0;
}

#tp-send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 0 16px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
    min-width: 60px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#tp-send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#tp-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Message Styles */
.tp-message {
    display: flex;
    max-width: 85%;
    animation: messageSlide 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    flex-shrink: 0;
}

.tp-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.tp-message-admin {
    align-self: flex-start;
}

.tp-message-system {
    align-self: center;
    max-width: 90%;
}

/* Message Content */
.tp-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    position: relative;
    backdrop-filter: blur(10px);
    max-width: 100%;
}

.tp-message-user .tp-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.tp-message-admin .tp-message-content {
    background: #2d3848;
    color: #e2e8f0;
    border-bottom-left-radius: 6px;
    border: 1px solid #3a4555;
}

.tp-message-system .tp-message-content {
    background: rgba(255, 243, 205, 0.1);
    color: #ecc94b;
    border-radius: 12px;
    text-align: center;
    font-style: italic;
    border: 1px solid rgba(255, 234, 167, 0.2);
    font-size: 13px;
}

.tp-message-text {
    line-height: 1.5;
    word-wrap: break-word;
    font-size: 14px;
    word-break: break-word;
}

.tp-message-text a {
    color: #90cdf4 !important;
    text-decoration: underline;
    transition: color 0.3s ease;
}

.tp-message-text a:hover {
    color: #63b3ed !important;
}

.tp-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 6px;
    text-align: right;
    font-weight: 500;
}

.tp-message-user .tp-message-time {
    text-align: right;
    color: rgba(255,255,255,0.8);
}

.tp-message-admin .tp-message-time {
    text-align: left;
    color: rgba(226, 232, 240, 0.7);
}

/* Scrollbar Styling - ONLY FOR MESSAGES */
#tp-chat-messages::-webkit-scrollbar {
    width: 8px;
}

#tp-chat-messages::-webkit-scrollbar-track {
    background: #2d3748;
    border-radius: 4px;
}

#tp-chat-messages::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 4px;
    transition: background 0.3s ease;
}

#tp-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #667eea;
}

/* Scrollbar for Quick Actions */
#tp-quick-actions::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

#tp-quick-actions::-webkit-scrollbar-track {
    background: #2d3748;
    border-radius: 3px;
}

#tp-quick-actions::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 3px;
    transition: background 0.3s ease;
}

#tp-quick-actions::-webkit-scrollbar-thumb:hover {
    background: #667eea;
}

/* Animations */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.7);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 8px rgba(229, 62, 62, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(229, 62, 62, 0);
    }
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Mobile Responsive */
@media (max-width: 480px) {
    #tp-chat-box {
        width: calc(100vw - 30px);
        height: 70vh;
        right: 15px;
        left: 15px;
        bottom: 80px;
    }
    
    #tp-chat-header {
        height: 55px;
        min-height: 55px;
        max-height: 55px;
        padding: 0 15px;
    }
    
    #tp-chat-messages {
        padding: 15px;
    }
    
    #tp-chat-inputs {
        height: 140px;
        min-height: 140px;
        max-height: 140px;
    }
    
    #tp-quick-actions {
        padding: 10px 15px 6px 15px;
        min-height: 55px;
        max-height: 65px;
    }
    
    #tp-chat-controls {
        height: 65px;
        min-height: 65px;
        max-height: 65px;
        padding: 12px 15px;
    }
    
    .tp-quick-btn {
        padding: 6px 10px;
        font-size: 11px;
        height: 28px;
    }
    
    #tp-chat-message {
        min-height: 38px;
        max-height: 38px;
        height: 38px;
        padding: 10px 14px;
    }
    
    #tp-send-btn {
        height: 38px;
        min-width: 55px;
    }
    
    #tp-chat-icon {
        right: 15px;
        bottom: 20px;
        width: 60px;
        height: 60px;
    }
    
    #tp-chat-notice {
        right: 15px;
        bottom: calc(60px + 25px);
        max-width: calc(100vw - 60px);
    }
    
    .tp-message {
        max-width: 90%;
    }
}

/* Loading States */
.tp-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Empty State */
.tp-empty-state {
    text-align: center;
    color: #a0aec0;
    padding: 40px 20px;
    font-style: italic;
    margin: auto;
}

/* Typing Indicator */
.tp-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #2d3848;
    border-radius: 16px;
    color: #a0aec0;
    font-size: 12px;
    align-self: flex-start;
    max-width: 110px;
    margin-bottom: 16px;
}

.tp-typing-dots {
    display: flex;
    gap: 3px;
}

.tp-typing-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #a0aec0;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.tp-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.tp-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Ensure messages are always visible */
.tp-message:last-child {
    margin-bottom: 0;
}

/* Prevent any text selection in footer */
#tp-chat-inputs,
#tp-quick-actions,
#tp-chat-controls,
.tp-quick-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ✅ رفع مشکلات نمایش */
#tp-chat-box.tp-chat-open {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: scale(1) translateY(0) !important;
}