/* ==================== AI Product Assistant - نسخه نهایی ==================== */

:root {
    --apa-primary: #0073aa;
    --apa-primary-dark: #005a87;
    --apa-bg: #f8f9fa;
    --apa-white: #ffffff;
    --apa-border: #e9ecef;
    --apa-text: #212529;
    --apa-muted: #6c757d;
    --apa-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

/* -------------------- ویجت -------------------- */
.apa-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.apa-chat-widget.bottom-right { bottom: 20px; right: 20px; }
.apa-chat-widget.bottom-left { bottom: 20px; left: 20px; }

/* -------------------- دکمه شناور -------------------- */
.apa-chat-toggle {
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    background: var(--apa-primary) !important;
    color: white !important;
    border: none !important;
    cursor: pointer !important;
    box-shadow: var(--apa-shadow) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.3s ease !important;
    position: relative !important;
    padding: 0 !important;
}

.apa-chat-toggle:hover {
    transform: scale(1.1) !important;
    background: var(--apa-primary-dark) !important;
}

.apa-chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.apa-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #dc3545;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* -------------------- کانتینر چت -------------------- */
.apa-chat-container {
    position: absolute;
    bottom: 75px;
    width: 380px;
    height: 500px;
    background: var(--apa-white);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: apaSlideUp 0.3s ease;
    border: 1px solid var(--apa-border);
}

.apa-chat-widget.bottom-right .apa-chat-container { right: 0; }
.apa-chat-widget.bottom-left .apa-chat-container { left: 0; }

@keyframes apaSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* -------------------- هدر -------------------- */
.apa-chat-header {
    background: var(--apa-primary);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.apa-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.apa-chat-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

.apa-chat-close:hover { background: rgba(255,255,255,0.3); }

/* -------------------- پیام‌ها -------------------- */
.apa-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--apa-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.apa-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 90%;
    animation: apaMessageSlide 0.3s ease;
}

@keyframes apaMessageSlide {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

.apa-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.apa-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--apa-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.apa-message.user .apa-message-avatar { background: #6c757d; }

.apa-message-content {
    background: var(--apa-white);
    padding: 14px 18px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    line-height: 1.7;
    font-size: 14px;
    color: var(--apa-text);
    word-wrap: break-word;
    white-space: pre-line;
}

.apa-message.user .apa-message-content {
    background: var(--apa-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.apa-message:not(.user) .apa-message-content {
    border-bottom-left-radius: 4px;
}

/* استایل متن داخل پیام */
.apa-message-content strong {
    color: var(--apa-primary);
    font-weight: 600;
}

.apa-message.user .apa-message-content strong {
    color: #fff3cd;
}

/* -------------------- انتخاب سوالات شبیه -------------------- */
.apa-similar-questions {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 16px;
    margin-top: 12px;
    color: white;
}

.apa-similar-questions h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    opacity: 0.95;
}

.apa-similar-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.apa-similar-item {
    background: rgba(255,255,255,0.95);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--apa-text);
    text-align: right;
}

.apa-similar-item:hover {
    transform: translateX(-4px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.apa-similar-question {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
    color: var(--apa-primary);
}

.apa-similar-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 12px;
}

.apa-similar-score {
    background: #28a745;
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
}

.apa-similar-keywords {
    color: #6c757d;
}

/* -------------------- نتایج جستجو -------------------- */
.apa-results-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 2px solid var(--apa-border);
}

.apa-results-section h4 {
    margin: 0 0 12px 0;
    color: var(--apa-text);
    font-size: 14px;
    font-weight: 600;
}

.apa-result-item {
    display: block;
    padding: 12px 14px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
    border-right: 3px solid transparent;
}

.apa-result-item:hover {
    background: #e9ecef;
    border-right-color: var(--apa-primary);
    transform: translateX(-3px);
}

.apa-result-type {
    font-size: 11px;
    color: var(--apa-muted);
    margin-bottom: 4px;
    font-weight: 500;
}

.apa-result-title {
    font-weight: 600;
    color: var(--apa-text);
    margin-bottom: 6px;
    font-size: 14px;
}

.apa-result-excerpt {
    font-size: 12px;
    color: var(--apa-muted);
    line-height: 1.5;
}

.apa-result-excerpt mark {
    background: #fff3cd;
    padding: 1px 4px;
    border-radius: 4px;
    font-weight: 600;
    color: #856404;
}

/* -------------------- پیام یافت نشد -------------------- */
.apa-no-results {
    margin-top: 16px;
    padding: 16px;
    background: #f8d7da;
    border-radius: 12px;
    border-right: 4px solid #dc3545;
}

.apa-no-results p {
    margin: 0 0 10px 0;
    font-weight: 600;
    color: #721c24;
}

.apa-no-results ul {
    margin: 0;
    padding-right: 20px;
    color: #721c24;
    font-size: 13px;
}

/* -------------------- پیشنهادات -------------------- */
.apa-suggestions {
    padding: 12px 15px;
    background: var(--apa-white);
    border-top: 1px solid var(--apa-border);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.apa-suggestion-chip {
    background: #e9ecef;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--apa-text);
    font-weight: 500;
}

.apa-suggestion-chip:hover {
    background: var(--apa-primary);
    color: white;
    transform: translateY(-2px);
}

/* -------------------- ورودی -------------------- */
.apa-chat-input-area {
    padding: 15px;
    background: var(--apa-white);
    border-top: 1px solid var(--apa-border);
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.apa-chat-input {
    flex: 1;
    border: 2px solid #dee2e6;
    border-radius: 25px;
    padding: 12px 20px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    font-family: inherit;
}

.apa-chat-input:focus {
    border-color: var(--apa-primary);
    box-shadow: 0 0 0 4px rgba(0,115,170,0.1);
}

.apa-chat-send {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--apa-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.apa-chat-send:hover {
    background: var(--apa-primary-dark);
    transform: scale(1.05);
}

.apa-chat-send svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    margin-right: -2px;
}

/* -------------------- تایپینگ -------------------- */
.apa-typing {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
    background: var(--apa-white);
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.apa-typing-dot {
    width: 8px;
    height: 8px;
    background: #adb5bd;
    border-radius: 50%;
    animation: apaTyping 1.4s infinite ease-in-out both;
}

.apa-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.apa-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes apaTyping {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* -------------------- اسکرول بار -------------------- */
.apa-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.apa-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.apa-chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

/* -------------------- ریسپانسیو -------------------- */
@media (max-width: 480px) {
    .apa-chat-widget {
        bottom: 10px !important;
        right: 10px !important;
        left: 10px !important;
    }
    
    .apa-chat-container {
        width: calc(100vw - 20px) !important;
        height: 70vh !important;
        position: fixed !important;
        bottom: 80px !important;
        right: 10px !important;
        left: 10px !important;
    }
    
    .apa-chat-toggle {
        width: 56px !important;
        height: 56px !important;
    }
}