/* =========================
   Sandoogh Chat Widget CSS
   ========================= */

/* برای این‌که استایل‌های قالب کمتر تداخل کنند */
#chat-widget-container,
#chat-widget-container * {
    box-sizing: border-box;
    direction: rtl;
    font-family: inherit;
}

/* انیمیشن‌ها */
@keyframes slideUpEntrance {
    0% { opacity: 0; transform: translateY(60px); }
    100% { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes messagePop {
    0% { opacity: 0; transform: translateY(10px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* کانتینر اصلی */
#chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 15px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    pointer-events: none;
}
#chat-widget-container > * { pointer-events: auto; }

/* حباب پرومو */
#chat-promo-bubble {
    background: white;
    padding: 12px 15px;
    border-radius: 15px;
    border-bottom-right-radius: 5px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
    width: 220px;
    position: relative;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.04);
    display: none;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease,
                transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#chat-promo-bubble.show {
    opacity: 1;
    transform: translateY(0);
}
.promo-content {
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: right;
}
.promo-image {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #eee;
}
.promo-text {
    display: flex;
    flex-direction: column;
}
.promo-title {
    font-weight: bold;
    font-size: 14px;
    color: #333;
}
.promo-desc {
    font-size: 12px;
    color: #666;
}
.close-promo {
    position: absolute;
    top: 5px;
    left: 8px;
    color: #999;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 2px;
}

/* دکمه باز/بستن چت */
#chat-toggle-btn {
    background: linear-gradient(135deg, #0d6efd, #0043a8);
    color: white;
    border: none;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(13, 110, 253, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 100001;
    animation: slideUpEntrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 1s backwards;
}
#chat-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.6);
}
.notification-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #ffc107;
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse 2s infinite;
}

/* پنجره چت */
#chat-window {
    display: none;
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    height: 450px;
    max-height: 85vh;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.3s ease,
                transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid rgba(0,0,0,0.08);
    z-index: 100000;
}
#chat-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* هدر */
.chat-header {
    background: linear-gradient(135deg, #0d6efd, #0043a8);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.avatar-container {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.3);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
}
.header-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.header-info h5 {
    margin: 0;
    font-size: 16px;
    font-weight: bold;
}
.status {
    font-size: 12px;
    opacity: 0.9;
}
.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* منوی سه‌نقطه */
.chat-menu-wrapper {
    position: relative;
}
.chat-menu-toggle-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    font-size: 18px;
    line-height: 1;
}
.chat-menu-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}
.chat-menu-dropdown {
    position: absolute;
    top: 40px;
    left: 0;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.18);
    padding: 6px 0;
    min-width: 160px;
    z-index: 100002;
    display: none;
    text-align: right;
}
.chat-menu-dropdown.open {
    display: block;
}
.chat-menu-item {
    width: 100%;
    border: none;
    background: transparent;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.chat-menu-item:hover {
    background: #f5f5f5;
}
.chat-menu-item svg {
    width: 16px;
    height: 16px;
}

/* دکمه بستن */
.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    line-height: 0.5;
    opacity: 0.8;
    padding: 0;
}
.close-btn:hover {
    opacity: 1;
}

/* بدنه چت */
.chat-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* پیام‌ها */
.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    text-align: right;
    margin-bottom: 4px;
    animation: messagePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
.bot-message {
    background: white;
    color: #333;
    border-bottom-left-radius: 2px;
    align-self: flex-end;
    margin-left: 0;
    margin-right: auto;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transform-origin: bottom left;
}
.user-message {
    background: #0d6efd;
    color: white;
    border-bottom-right-radius: 2px;
    align-self: flex-start;
    margin-right: 0;
    margin-left: auto;
    box-shadow: 0 2px 5px rgba(13, 110, 253, 0.2);
    transform-origin: bottom right;
}

/* دکمه‌های پیشنهادی داخل هر پاسخ */
.inline-suggestions {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.suggestion-chip {
    background-color: #f0f7ff;
    color: #0d6efd;
    border: 1px solid #cce5ff;
    border-radius: 15px;
    padding: 6px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    flex-shrink: 0;
}
.suggestion-chip:hover {
    background-color: #0d6efd;
    color: white;
    border-color: #0d6efd;
}

/* فوتر و اینپوت */
.chat-footer {
    padding: 12px 15px;
    background: white;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    align-items: center;
}
#chat-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    padding: 10px 14px;
    border-radius: 25px;
    outline: none;
    text-align: right;
    background: #fcfcfc;
    font-size: 15px;
}
#chat-input:focus {
    border-color: #0d6efd;
    background: white;
}
#send-btn {
    background: #0d6efd;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* حالت در حال تایپ */
.typing-indicator-container {
    background: white;
    padding: 12px 15px;
    border-radius: 18px;
    border-bottom-left-radius: 2px;
    width: fit-content;
    align-self: flex-end;
    margin-right: auto;
    margin-left: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    display: flex;
    gap: 4px;
    align-items: center;
    margin-bottom: 5px;
    animation: messagePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
.typing-dot {
    width: 6px;
    height: 6px;
    background: #b0b0b0;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

/* نوار منوی اصلی (دکمه‌های شروع مجدد و …) */
.main-menu-bar {
    background: transparent;
    padding: 0 12px 6px 12px;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    transform: translateY(6px);
    transition:
        max-height 0.25s ease,
        opacity 0.2s ease,
        transform 0.25s ease;
}
.main-menu-bar.open {
    max-height: 140px;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
.main-menu-inner {
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e6e6e6;
    padding: 8px 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.main-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: #6c757d;
}
.main-menu-header-title {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.main-menu-reset-icon {
    border: none;
    background: transparent;
    padding: 4px;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
}
.main-menu-reset-icon svg {
    width: 16px;
    height: 16px;
}
.main-menu-reset-icon:hover {
    background: #f1f3f5;
    transform: rotate(-15deg);
}
.main-menu-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}
.main-menu-btn {
    background-color: #f0f7ff;
    color: #0d6efd;
    border: 1px solid #cce5ff;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s ease;
    outline: none;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.main-menu-btn:hover {
    background-color: #0d6efd;
    color: #ffffff;
    border-color: #0d6efd;
}

/* دکمه همبرگری پایین */
.main-menu-toggle-btn {
    background: transparent !important;
    border: none !important;
    outline: none !important;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    margin: 0;
    color: #0d6efd;
    transition: transform 0.2s ease, color 0.2s ease;
}
.main-menu-toggle-btn:hover {
    transform: scale(1.15);
    color: #0a58ca;
}
.main-menu-toggle-btn svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
    transition: transform 0.2s ease;
}
.main-menu-toggle-btn.open svg {
    transform: rotate(90deg);
}

/* نوار بازخورد زیر هر پاسخ */
.bot-meta-bar {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    font-size: 11px;
    color: #6c757d;
}
.bot-feedback-toggle {
    border: none;
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 0;
}
.bot-feedback-toggle:hover {
    color: #0d6efd;
}
.bot-feedback-toggle .chevron {
    font-size: 10px;
}
.bot-feedback-panel {
    margin-top: 4px;
    padding: 6px 8px;
    border-radius: 10px;
    background: #f8f9fa;
    display: none;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.bot-feedback-panel.open {
    display: inline-flex;
}
.bot-feedback-panel .btn {
    font-size: 11px;
}

/* موبایل فول‌اسکرین */
@media (max-width: 480px) {
    #chat-widget-container {
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100dvh !important;
        pointer-events: none;
        justify-content: flex-end;
        z-index: 2147483647;
    }
    #chat-toggle-btn {
        pointer-events: auto;
        margin-right: 20px;
        margin-bottom: 20px;
        position: absolute;
        bottom: 0;
        right: 0;
    }
    #chat-promo-bubble {
        margin-bottom: 85px;
        margin-right: 20px;
        right: 0px;
        position: absolute;
    }
    #chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100dvh !important;
        max-height: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        pointer-events: auto;
        transform: translateY(100%);
        opacity: 1;
        transition: transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
    }
    #chat-window.active {
        transform: translateY(0) !important;
    }
}
