/* ================= استایل بازنویسی‌شده چت‌بات پاستیل (هماهنگ با دارک و لایت) ================= */
.chat-container-wrapper {
    display: flex;
    width: 100%;
    height: calc(100vh - 105px);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    backdrop-filter: blur(16px);
}

/* سایدبارهای چت */
.chat-sidebar-right {
    width: 280px;
    min-width: 260px;
    background: var(--chat-sidebar-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 20;
    transition: transform 0.3s ease;
}

.chat-sidebar-left {
    width: 300px;
    min-width: 280px;
    background: var(--chat-sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 20;
    transition: transform 0.3s ease;
}

.chat-sidebar-header {
    padding: 14px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-session-item {
    padding: 10px 12px;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.88rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid transparent;
}
.chat-session-item:hover { background: var(--tab-hover-bg); color: var(--text-main); }
.chat-session-item.active {
    background: var(--tab-active-bg);
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}
.chat-session-del { background: none; border: none; color: #ef4444; cursor: pointer; padding: 2px 6px; opacity: 0.6; }
.chat-session-del:hover { opacity: 1; }

.chat-sidebar-footer { padding: 12px; border-top: 1px solid var(--border-color); }
.chat-btn-subtle { background: none; border: none; color: var(--text-muted); font-size: 0.8rem; cursor: pointer; width: 100%; }
.chat-btn-subtle:hover { color: #ef4444; }

.chat-settings-inner { padding: 18px; display: flex; flex-direction: column; height: 100%; overflow-y: auto; }
.settings-title { color: var(--primary); margin-bottom: 14px; font-size: 0.95rem; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.drawer-header-mobile { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; }

.chat-close-drawer-btn {
    display: none;
    background: var(--tab-hover-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.badge-status-on { padding: 6px 10px; border-radius: 6px; font-size: 0.8rem; margin-top: 6px; background: rgba(16, 185, 129, 0.15); color: var(--accent); border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-status-off { padding: 6px 10px; border-radius: 6px; font-size: 0.8rem; margin-top: 6px; background: rgba(239, 68, 68, 0.15); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.3); }
.chat-tips-box { margin-top: auto; background: var(--tab-hover-bg); border: 1px solid var(--border-color); padding: 10px; border-radius: 8px; font-size: 0.8rem; color: var(--text-muted); line-height: 1.5; }

/* ================= بخش مرکزی پیام‌ها ================= */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    position: relative;
    background: var(--chat-main-bg);
    overflow: hidden;
}

.chat-mobile-nav {
    display: none;
    flex-shrink: 0;
    width: 100%;
    height: 52px;
    padding: 0 14px;
    background: var(--chat-sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.chat-icon-btn {
    background: var(--tab-hover-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

.chat-mobile-latency-pill, .chat-floating-latency {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--accent);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-family: monospace;
    direction: rtl;
}

.chat-floating-latency {
    position: absolute;
    top: 14px;
    left: 20px;
    z-index: 10;
}
.desktop-only { display: block; }

.chat-messages-area {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.chat-welcome-box { text-align: center; margin: auto; max-width: 440px; color: var(--text-muted); }
.chat-welcome-box .welcome-icon { font-size: 3.2rem; margin-bottom: 12px; }
.chat-welcome-box h3 { color: var(--text-main); margin-bottom: 8px; font-size: 1.3rem; }

/* حباب پیام‌ها هماهنگ با تم دارک و لایت */
.chat-msg { display: flex; gap: 12px; max-width: 85%; animation: fadeIn 0.2s ease; }
.chat-msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.user .chat-msg-avatar { background: var(--primary); color: #fff; }
.assistant .chat-msg-avatar { background: var(--accent); color: #fff; }

.chat-msg-bubble {
    background: var(--chat-bubble-assistant);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 12px 18px;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.75;
    white-space: pre-wrap;
    word-break: break-word;
}

.user .chat-msg-bubble {
    background: var(--chat-bubble-user);
    border-color: rgba(99, 102, 241, 0.4);
}

.chat-msg-img { max-width: 260px; max-height: 180px; border-radius: 8px; margin-bottom: 8px; display: block; }

/* نوار ورودی چت */
.chat-input-bar {
    flex-shrink: 0;
    position: relative;
    bottom: 0;
    z-index: 25;
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    background: var(--chat-input-bar-bg);
    border-top: 1px solid var(--border-color);
}

.chat-image-preview-card {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-bottom: 8px;
    padding: 4px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}
.chat-image-preview-card img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 8px;
}
#chat-remove-image-btn {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: #ef4444;
    color: #fff;
    cursor: pointer;
    font-size: 0.75rem;
}

.chat-input-controls { display: flex; align-items: flex-end; gap: 8px; width: 100%; }
.chat-action-btn { background: var(--tab-hover-bg); border: 1px solid var(--border-color); color: var(--text-main); width: 42px; height: 42px; border-radius: 10px; font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chat-textarea { flex: 1; min-width: 0; width: 100%; background: var(--input-bg); border: 1px solid var(--border-color); border-radius: 10px; color: var(--text-main); padding: 10px 12px; font-size: 0.95rem; resize: none; outline: none; min-height: 42px; max-height: 120px; }
.chat-textarea:focus { border-color: var(--primary); }
.chat-send-btn { height: 42px; padding: 0 14px; flex-shrink: 0; }

/* ریسپانسیو موبایل چت */
@media (max-width: 900px) {
    .chat-container-wrapper {
        position: fixed !important;
        top: 72px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: calc(100dvh - 72px) !important;
        border-radius: 0 !important;
        border: none !important;
        background: var(--chat-sidebar-bg) !important;
    }
    .chat-mobile-nav { display: flex !important; }
    .desktop-only { display: none !important; }
    .chat-close-drawer-btn { display: flex !important; }
    .chat-sidebar-right, .chat-sidebar-left {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 85% !important;
        max-width: 320px !important;
        height: 100dvh !important;
        z-index: 10001 !important;
        background: var(--chat-sidebar-bg) !important;
    }
    .chat-sidebar-right { right: 0 !important; transform: translateX(100%) !important; }
    .chat-sidebar-left { left: 0 !important; transform: translateX(-100%) !important; }
    .chat-sidebar-right.open, .chat-sidebar-left.open { transform: translateX(0) !important; }
    .chat-backdrop { display: none; position: fixed !important; inset: 0 !important; background: rgba(0, 0, 0, 0.6) !important; z-index: 10000 !important; }
    .chat-backdrop.active { display: block !important; }
}


@media (max-width: 900px) {
    .chat-container-wrapper {
        position: fixed !important;
        top: 70px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: calc(100dvh - 70px) !important;
        border-radius: 0 !important;
        border: none !important;
        background: var(--chat-sidebar-bg) !important;
    }
    .chat-send-btn {
        padding: 0 12px;
        font-size: 0.85rem;
    }