/* ============================================
   Chat Module Styles — منصة الجنوب
   RTL, Responsive, Dark Sidebar + Light Chat
   ============================================ */

:root {
    --chat-sidebar: #1E293B;
    --chat-sidebar-hover: #27354f;
    --chat-sidebar-active: #334155;
    --chat-sidebar-border: #334155;
    --chat-sidebar-text: #94A3B8;
    --chat-sidebar-text-light: #E2E8F0;
    --chat-area: #F8FAFC;
    --chat-area-border: #E2E8F0;
    --chat-sent: #0D9488;
    --chat-sent-text: #FFFFFF;
    --chat-received: #E2E8F0;
    --chat-received-text: #1E293B;
    --chat-online: #22C55E;
    --chat-unread-bg: #EF4444;
    --chat-unread-text: #FFFFFF;
    --chat-typing: #94A3B8;

    /* Status indicator colors */
    --status-online: #22C55E;
    --status-offline: #94A3B8;
    --status-away: #F59E0B;
    --status-busy: #EF4444;
    --status-typing: #3B82F6;

    --sidebar-width: 340px;
    --header-height: 64px;
    --input-height: 72px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

/* ===== Base ===== */
* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    font-family: 'IBM Plex Sans Arabic', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--chat-area);
    color: var(--gray-800);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Font Awesome override */
i, i.fas, i.far, i.fal, .fas, .far, .fal, [class^="fa-"], [class*=" fa-"] {
    font-family: "Font Awesome 6 Free", "FontAwesome" !important;
}

/* ===== Layout ===== */
.chat-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    direction: rtl;
}

/* ===== Sidebar ===== */
.chat-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--chat-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--chat-sidebar-border);
    border-left: none;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--chat-sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
}

.sidebar-title {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.sidebar-title-main {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--chat-sidebar-text-light);
}

.sidebar-title-sub {
    font-size: 0.7rem;
    color: var(--chat-sidebar-text);
}

.sidebar-actions {
    display: flex;
    gap: 6px;
}

.sidebar-action-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    border: none;
    background: rgba(255,255,255,0.06);
    color: var(--chat-sidebar-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 0.8rem;
}

.sidebar-action-btn:hover {
    background: rgba(255,255,255,0.12);
    color: var(--chat-sidebar-text-light);
}

/* Sidebar Search */
.sidebar-search {
    padding: 12px 16px;
    position: relative;
}

.sidebar-search i {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--chat-sidebar-text);
    font-size: 0.8rem;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border-radius: var(--radius-md);
    border: 1px solid var(--chat-sidebar-border);
    background: rgba(255,255,255,0.05);
    color: var(--chat-sidebar-text-light);
    font-family: inherit;
    font-size: 0.8rem;
    outline: none;
    transition: all 0.2s ease;
}

.sidebar-search input::placeholder {
    color: var(--chat-sidebar-text);
}

.sidebar-search input:focus {
    border-color: #0D9488;
    background: rgba(255,255,255,0.08);
}

/* Conversation List */
.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 8px;
}

.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
.sidebar-list::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

.conversation-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    margin-bottom: 2px;
}

.conversation-item:hover {
    background: var(--chat-sidebar-hover);
}

.conversation-item.active {
    background: var(--chat-sidebar-active);
}

.conversation-avatar {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #0D9488, #14B8A6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1rem;
    flex-shrink: 0;
    position: relative;
}

.conversation-avatar.group {
    background: linear-gradient(135deg, #3B82F6, #60A5FA);
}

.conversation-avatar i { font-size: 1rem; }

/* ===== Main Chat Area ===== */
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.conversation-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.conversation-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--chat-sidebar-text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 0.65rem;
    color: var(--chat-sidebar-text);
    white-space: nowrap;
    flex-shrink: 0;
}

.conversation-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.conversation-preview {
    font-size: 0.75rem;
    color: var(--chat-sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conversation-unread {
    min-width: 20px;
    height: 20px;
    border-radius: var(--radius-full);
    background: var(--chat-unread-bg);
    color: var(--chat-unread-text);
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    flex-shrink: 0;
    /* جولة «إعادة تصميم الإشعارات والرسائل» (وثيقة «أنا معك 100%.txt» — خامسًا:
       «لا أريد نبضات مستمرة»): كان unreadPulse 2s infinite نبضًا دائمًا في
       سطح الرسائل. الشارة الآن مصمتة هادئة وحدَثية المعنى (العدد نفسه). */
    animation: none;
}

.conversation-unread:empty,
.conversation-unread[data-count="0"],
.conversation-unread.hide {
    display: none;
}

/* جولة «إعادة تصميم الإشعارات والرسائل» (وثيقة «أنا معك 100%.txt» — ثالثًا):
   صنف unread كان ميتًا (قواعد بلا طرف JS يضيفها) — chat.js أصبح يضيفه عند
   unread_count>0. غير المقروء الآن: خلفية مختلفة قليلًا + اسم أثخن + معاينة
   أوضح + شارة العدد المصمتة (النقطة الملونة). تُزال الحالة فور الفتح فيعاد
   الطبيعي («إذا قُرئت: تعود للون الطبيعي»). */
.conversation-item.unread {
    background: rgba(96, 165, 250, 0.08);
}

.conversation-item.unread:hover {
    background: rgba(96, 165, 250, 0.13);
}

.conversation-item.unread .conversation-name {
    color: #fff;
    font-weight: 700;
}

.conversation-item.unread .conversation-preview {
    color: var(--chat-sidebar-text-light);
    font-weight: 600;
}

.sidebar-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--chat-sidebar-text);
    text-align: center;
    gap: 10px;
}

.sidebar-empty i { font-size: 2rem; opacity: 0.5; }
.sidebar-empty span { font-size: 0.8rem; }

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--chat-sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #0D9488, #14B8A6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.8rem;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.sidebar-user-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--chat-sidebar-text-light);
}

.sidebar-user-status {
    font-size: 0.7rem;
    color: var(--chat-sidebar-text);
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chat-online);
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.offline { background: #94A3B8; }
.status-dot.away { background: #F59E0B; }
.status-dot.busy { background: #EF4444; }
.status-dot.typing { background: #3B82F6; animation: pulse 1.5s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Avatar status ring variants */
.conversation-avatar .avatar-status {
    position: absolute;
    left: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--chat-sidebar);
    background: #94A3B8; /* Default: offline (gray) */
}

.conversation-avatar .avatar-status.online { background: var(--chat-online); }
.conversation-avatar .avatar-status.offline { background: #94A3B8; }
.conversation-avatar .avatar-status.away { background: #F59E0B; }
.conversation-avatar .avatar-status.busy { background: #EF4444; }
.conversation-avatar .avatar-status.typing { background: #3B82F6; animation: pulse 1.5s infinite; }

/* ===== Main Chat Area ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-area);
    min-width: 0;
}

/* Empty State */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
    color: #94A3B8;
}

.chat-empty-icon {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, #EFF6FF, #DBEAFE);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #3B82F6;
    font-size: 2rem;
    margin-bottom: 20px;
}

.chat-empty h2 {
    margin: 0 0 8px;
    font-size: 1.2rem;
    color: #1E293B;
    font-weight: 700;
}

.chat-empty p {
    margin: 0 0 20px;
    font-size: 0.85rem;
    color: #64748B;
}

/* Active Chat */
.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Chat Header */
.chat-header {
    height: var(--header-height);
    padding: 0 20px;
    background: #fff;
    border-bottom: 1px solid var(--chat-area-border);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-header-back {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: none;
    background: none;
    color: #64748B;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.chat-header-back:hover { background: #F1F5F9; }

.chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #0D9488, #14B8A6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.9rem;
    flex-shrink: 0;
    position: relative;
}

.chat-header-avatar .avatar-status {
    position: absolute;
    bottom: 1px;
    left: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: var(--chat-online);
}

.chat-header-avatar .avatar-status.offline { background: #94A3B8; }
.chat-header-avatar .avatar-status.away { background: #F59E0B; }
.chat-header-avatar .avatar-status.busy { background: #EF4444; }
.chat-header-avatar .avatar-status.typing { background: #3B82F6; animation: pulse 1.5s infinite; }

.chat-header-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-header-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: #1E293B;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status {
    font-size: 0.75rem;
    color: #64748B;
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-header-action {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: none;
    background: none;
    color: #64748B;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.chat-header-action:hover { background: #F1F5F9; color: #1E293B; }

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 4px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

.messages-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    color: #64748B;
    font-size: 0.75rem;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid #E2E8F0;
    border-top-color: #0D9488;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Date Divider */
.date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 16px 0;
    color: #94A3B8;
    font-size: 0.7rem;
    font-weight: 600;
}

.date-divider::before,
.date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #E2E8F0;
    max-width: 120px;
}

/* Message Bubble */
.message-row {
    display: flex;
    width: 100%;
    margin-bottom: 4px;
}

.message-row.mine { justify-content: flex-end; }
.message-row.theirs { justify-content: flex-start; }

.message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    animation: messageIn 0.25s ease;
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-bubble.sent {
    background: var(--chat-sent);
    color: var(--chat-sent-text);
    border-bottom-left-radius: 4px;
}

.message-bubble.received {
    background: var(--chat-received);
    color: var(--chat-received-text);
    border-bottom-right-radius: 4px;
}

.message-bubble .message-time {
    font-size: 0.6rem;
    opacity: 0.7;
    margin-top: 4px;
    display: block;
    text-align: right;
}

.message-bubble .message-read {
    font-size: 0.6rem;
    opacity: 0.6;
    margin-left: 4px;
}

.message-bubble .message-read.read {
    color: #3B82F6;
    opacity: 1;
}

.message-bubble .message-read.read i {
    color: #3B82F6;
}

.message-bubble .message-sender {
    font-size: 0.65rem;
    font-weight: 600;
    color: #0D9488;
    margin-bottom: 4px;
    direction: rtl;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    animation: messageIn 0.2s ease;
}

.typing-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--chat-received);
    border-radius: var(--radius-md);
    border-bottom-right-radius: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-typing);
    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; }

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

.typing-text {
    font-size: 0.7rem;
    color: var(--chat-typing);
}

/* Input Area */
.chat-input-area {
    padding: 12px 20px;
    background: #fff;
    border-top: 1px solid var(--chat-area-border);
    flex-shrink: 0;
}

.chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #F1F5F9;
    border-radius: var(--radius-lg);
    padding: 6px 8px;
}

.chat-input-field {
    flex: 1;
    min-width: 0;
}

.chat-input-field textarea {
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: #1E293B;
    font-family: inherit;
    font-size: 0.85rem;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 36px;
    line-height: 1.5;
}

.chat-input-field textarea::placeholder { color: #94A3B8; }

.chat-input-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: none;
    background: none;
    color: #64748B;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-input-btn:hover { background: #E2E8F0; color: #1E293B; }

.chat-input-btn.send-btn {
    background: linear-gradient(135deg, #0D9488, #14B8A6);
    color: #fff;
}

.chat-input-btn.send-btn:hover {
    background: linear-gradient(135deg, #0F766E, #0D9488);
    transform: scale(1.05);
}

.chat-input-btn.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: #fff;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 48px rgba(0,0,0,0.15);
    animation: modalIn 0.2s ease;
}

.modal-content.modal-sm { max-width: 400px; }

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #E2E8F0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: #1E293B;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-header h3 i { color: #0D9488; }

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    border: none;
    background: none;
    color: #64748B;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

.modal-close:hover { background: #F1F5F9; color: #1E293B; }

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid #E2E8F0;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Form in modal */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 6px;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #E2E8F0;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.85rem;
    color: #1E293B;
    outline: none;
    transition: border-color 0.2s ease;
}

.form-group input[type="text"]:focus {
    border-color: #0D9488;
}

/* User Search & List in Modals */
.user-search {
    position: relative;
    margin-bottom: 12px;
}

.user-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #94A3B8;
    font-size: 0.8rem;
}

.user-search input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border: 1.5px solid #E2E8F0;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.user-search input:focus { border-color: #0D9488; }

.user-list {
    max-height: 280px;
    overflow-y: auto;
}

.user-list::-webkit-scrollbar { width: 4px; }
.user-list::-webkit-scrollbar-track { background: transparent; }
.user-list::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 4px; }

.user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
}

.user-item:hover { background: #F8FAFC; }

.user-item.selected {
    background: #ECFDF5;
    border-color: #A7F3D0;
}

.user-item-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #0D9488, #14B8A6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.user-item-info { flex: 1; min-width: 0; }
.user-item-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1E293B;
}
.user-item-role {
    font-size: 0.7rem;
    color: #64748B;
}

.user-item-check {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-full);
    border: 2px solid #CBD5E1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.6rem;
    transition: all 0.2s ease;
}

.user-item.selected .user-item-check {
    background: #0D9488;
    border-color: #0D9488;
}

.selected-users {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 32px;
    padding: 8px;
    background: #F8FAFC;
    border-radius: var(--radius-md);
    border: 1px solid #E2E8F0;
}

.selected-user-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #ECFDF5;
    color: #0F766E;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.selected-user-chip button {
    background: none;
    border: none;
    color: #0F766E;
    cursor: pointer;
    font-size: 0.65rem;
    padding: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.selected-user-chip button:hover { background: rgba(0,0,0,0.08); }

/* ===== Buttons (reused from app.css pattern) ===== */
.btn {
    font-family: inherit;
    font-weight: 600;
    border-radius: var(--radius-md);
    padding: 8px 16px;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: linear-gradient(135deg, #0D9488, #14B8A6);
    color: #fff;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0F766E, #0D9488);
    transform: translateY(-1px);
}

.btn-secondary {
    background: #F1F5F9;
    color: #475569;
}

.btn-secondary:hover { background: #E2E8F0; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: #1E293B;
    color: #fff;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    animation: toastIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
    direction: rtl;
}

.toast.success { background: linear-gradient(135deg, #10B981, #059669); }
.toast.error { background: linear-gradient(135deg, #EF4444, #DC2626); }
.toast.warning { background: linear-gradient(135deg, #F59E0B, #D97706); }

@keyframes toastIn {
    from { opacity: 0; transform: translate(-50%, -12px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.toast-exit {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
    to { opacity: 0; transform: translate(-50%, -12px); }
}

/* ===== Mobile Sidebar Toggle ===== */
.mobile-sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--chat-sidebar);
    color: #fff;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 99;
    backdrop-filter: blur(2px);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0,0,0,0.2);
    }

    .chat-sidebar.open {
        transform: translateX(0);
    }

    .mobile-sidebar-toggle {
        display: flex;
    }

    .chat-header-back {
        display: flex;
    }

    .message-bubble { max-width: 85%; }
}

@media (max-width: 480px) {
    .chat-messages { padding: 12px; }
    .chat-input-area { padding: 8px 12px; }
    .chat-header { padding: 0 12px; }
    .message-bubble { max-width: 90%; font-size: 0.8rem; }
    .modal-content { max-height: 90vh; }
}
/* ============================================
   Chat Styles v3 — Complete Rewrite
   All Phases: Toast, Voice, Context Menu, Scroll, Settings
   ============================================ */

:root {
    --primary: #0D9488;
    --primary-light: #14B8A6;
    --primary-50: #F0FDFA;
    --blue: #3B82F6;
    --blue-light: #60A5FA;
    --text: #0F172A;
    --text-muted: #64748B;
    --gray-50: #F8FAFC;
    --gray-100: #F1F5F9;
    --gray-200: #E2E8F0;
    --gray-300: #CBD5E1;
    --gray-400: #94A3B8;
    --gray-500: #64748B;
    --sent-bg: #DCF8C6;
    --online: #22C55E;
    --offline: #94A3B8;
    --read-blue: #3B82F6;
    --danger: #EF4444;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1);
    --radius: 10px;
    --radius-lg: 16px;
}

/* ===== Scroll-to-Bottom Button ===== */
.scroll-to-bottom-btn {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #0D9488, #14B8A6);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(13,148,136,0.3);
    z-index: 50;
    display: none;
    align-items: center;
    gap: 6px;
    direction: rtl;
    animation: btnPopIn 0.3s ease;
    transition: all 0.2s ease;
}
.scroll-to-bottom-btn:hover {
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 6px 16px rgba(13,148,136,0.4);
}
@keyframes btnPopIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Message Context Menu ===== */
.message-context-menu {
    position: fixed;
    z-index: 1000;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.05);
    padding: 6px 0;
    min-width: 180px;
    direction: rtl;
    animation: menuIn 0.15s ease;
    overflow: hidden;
}
@keyframes menuIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ===== Reply / Edit Bar ===== */
.reply-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: #F0FDFA;
    border-top: 1px solid #A7F3D0;
    border-radius: 12px 12px 0 0;
    margin: -12px -20px 8px;
    animation: slideDown 0.2s ease;
}
.reply-bar.edit-bar {
    background: #EFF6FF;
    border-top-color: #BFDBFE;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.reply-bar-content {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: #0F766E;
    flex: 1;
    min-width: 0;
}
.reply-bar.edit-bar .reply-bar-content {
    color: #1D4ED8;
}
.reply-bar-content span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reply-bar button {
    background: none;
    border: none;
    color: #64748B;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.8rem;
    transition: all 0.2s;
}
.reply-bar button:hover {
    background: rgba(0,0,0,0.06);
    color: #1E293B;
}

/* ===== Message Reply Preview ===== */
.message-reply {
    background: rgba(0,0,0,0.04);
    border-radius: 6px;
    padding: 4px 8px;
    margin-bottom: 6px;
    font-size: 0.72rem;
    color: #64748B;
    display: flex;
    align-items: center;
    gap: 4px;
    border-right: 2px solid var(--primary);
}
.message-reply i {
    font-size: 0.6rem;
    color: var(--primary);
}
.message-reply span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Message Edited Flag ===== */
.message-edited {
    font-size: 0.65rem;
    color: var(--gray-400);
    margin-right: 6px;
    font-style: italic;
}

/* ===== Read Receipts (3 states) ===== */
.message-read {
    font-size: 0.7rem;
    margin-right: 4px;
    display: inline-flex;
    align-items: center;
}
.message-read i {
    color: var(--gray-300);
    font-size: 0.65rem;
}
.message-read.delivered {
    opacity: 0.8;
}
.message-read.delivered i {
    color: var(--gray-400);
}
.message-read.read {
    color: var(--read-blue);
    opacity: 1;
}
.message-read.read i {
    color: var(--read-blue);
}

/* ===== Voice Recording Panel ===== */
.voice-recording-panel {
    display: none;
    padding: 12px 20px;
    background: #FEF2F2;
    border-top: 1px solid #FECACA;
    border-radius: 12px 12px 0 0;
    margin: -12px -20px 8px;
    animation: slideDown 0.2s ease;
}
.voice-recording-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.voice-recording-wave {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 1;
    height: 30px;
}
.voice-recording-wave span {
    width: 3px;
    background: #EF4444;
    border-radius: 2px;
    animation: wave 0.8s ease-in-out infinite;
}
.voice-recording-wave span:nth-child(1) { height: 8px; animation-delay: 0s; }
.voice-recording-wave span:nth-child(2) { height: 16px; animation-delay: 0.1s; }
.voice-recording-wave span:nth-child(3) { height: 24px; animation-delay: 0.2s; }
.voice-recording-wave span:nth-child(4) { height: 16px; animation-delay: 0.3s; }
.voice-recording-wave span:nth-child(5) { height: 8px; animation-delay: 0.4s; }
@keyframes wave {
    0%, 100% { transform: scaleY(0.6); }
    50% { transform: scaleY(1); }
}
.voice-recording-timer {
    font-size: 1rem;
    font-weight: 600;
    color: #DC2626;
    font-family: 'IBM Plex Sans Arabic', monospace;
    min-width: 50px;
    text-align: center;
}
.voice-recording-actions {
    display: flex;
    gap: 12px;
}
.voice-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
}
.voice-btn.voice-cancel {
    background: #FEE2E2;
    color: #DC2626;
}
.voice-btn.voice-cancel:hover {
    background: #FECACA;
    transform: scale(1.05);
}
.voice-btn.voice-stop {
    background: #D1FAE5;
    color: #059669;
}
.voice-btn.voice-stop:hover {
    background: #A7F3D0;
    transform: scale(1.05);
}

/* ===== Voice Message Playback ===== */
.voice-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(13, 148, 136, 0.08);
    border-radius: 12px;
    min-width: 200px;
}
.voice-message .voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}
.voice-message .voice-progress {
    flex: 1;
    height: 4px;
    background: var(--gray-200);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}
.voice-message .voice-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
}
.voice-message .voice-time {
    font-size: 0.7rem;
    color: var(--gray-400);
    min-width: 36px;
    text-align: left;
    direction: ltr;
}

/* ===== Settings Panel ===== */
.settings-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 48px rgba(0,0,0,0.15);
    z-index: 1001;
    min-width: 320px;
    max-width: 400px;
    padding: 0;
    overflow: hidden;
    animation: modalIn 0.2s ease;
    display: none;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes modalIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.settings-panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.settings-panel-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.settings-panel-body {
    padding: 12px 0;
}
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--gray-100);
}
.settings-row:last-child {
    border-bottom: none;
}
.settings-row-label {
    font-size: 0.85rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.settings-row-label i {
    color: var(--gray-400);
    width: 20px;
    text-align: center;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    cursor: pointer;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--gray-300);
    border-radius: 24px;
    transition: all 0.3s ease;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ===== Search Box ===== */
#messageSearchBox {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
}
#messageSearchBox input {
    color: var(--text);
}
#messageSearchBox input::placeholder {
    color: var(--gray-400);
}

/* ===== Pinned / Muted Conversation States ===== */
.conversation-item.pinned {
    border-right: 3px solid #F59E0B;
    background: linear-gradient(to left, rgba(245, 158, 11, 0.03), transparent);
}
.conversation-item.muted {
    opacity: 0.65;
}
.conversation-item.muted .conversation-name::after {
    content: '\f6a9';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-right: 6px;
    font-size: 0.6rem;
    color: var(--gray-400);
}

/* ===== Message Bubble Hover ===== */
.message-bubble {
    cursor: context-menu;
    transition: box-shadow 0.2s ease;
}
.message-bubble:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ===== Date Divider ===== */
.date-divider {
    text-align: center;
    margin: 20px 0;
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--gray-400);
    font-weight: 500;
}
.date-divider::before,
.date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--gray-200);
}