/* ═══════════════════════════════════════════════════════
   THABET Chat — WhatsApp-like messaging
   Phases 10-12-18-19: Full polling, UX, mobile, emoji
   ═══════════════════════════════════════════════════════ */

/* ─── CHAT LAYOUT ─────────────────────────────────── */
.chat-container {
    display: flex;
    height: calc(100vh - 120px);
    max-width: 900px;
    margin: 0 auto;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 20px rgba(0,0,0,0.08);
    background: var(--bg-primary, #fff);
}

/* ─── CONVERSATION LIST ──────────────────────────── */
.chat-sidebar {
    width: 340px;
    border-right: 1px solid var(--border-color, #e5e7eb);
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary, #f9fafb);
}

.chat-sidebar.hidden {
    display: none;
}

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

.chat-sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.chat-search {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.chat-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    font-size: 0.875rem;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #111827);
}

.chat-search input:focus {
    outline: none;
    border-color: var(--primary-color, #059669);
    box-shadow: 0 0 0 2px rgba(5,150,105,0.15);
}

.chat-conversation-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

.chat-conv-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border-light, #f3f4f6);
    text-decoration: none;
    color: inherit;
    min-height: 60px;
}

.chat-conv-item:hover {
    background: var(--bg-hover, #f0fdf4);
}

.chat-conv-item.active {
    background: var(--primary-light, #ecfdf5);
    border-left: 3px solid var(--primary-color, #059669);
}

.chat-conv-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin-left: 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    background: var(--primary-light, #ecfdf5);
    color: var(--primary-color, #059669);
    overflow: hidden;
}

.chat-conv-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-conv-avatar svg {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-conv-avatar .avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.chat-conv-info {
    flex: 1;
    min-width: 0;
}

.chat-conv-title {
    font-weight: 500;
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-conv-preview {
    font-size: 0.8125rem;
    color: var(--text-secondary, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-conv-meta {
    text-align: left;
    flex-shrink: 0;
    margin-left: 8px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.chat-conv-time {
    font-size: 0.6875rem;
    color: var(--text-secondary, #6b7280);
}

.chat-conv-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--primary-color, #059669);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 600;
}

.chat-conv-online {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
    flex-shrink: 0;
}

.chat-conv-muted {
    font-size: 0.75rem;
    opacity: 0.5;
    flex-shrink: 0;
}

/* ─── MESSAGE AREA ───────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.chat-main-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-primary, #fff);
    z-index: 5;
}

.chat-main-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-main-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light, #ecfdf5);
    color: var(--primary-color, #059669);
    flex-shrink: 0;
}

.chat-main-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-main-header-avatar svg {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-main-header-avatar .avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.chat-main-header-text {
    min-width: 0;
}

.chat-main-header-text h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-status {
    font-size: 0.75rem;
    color: var(--text-secondary, #6b7280);
}

.chat-status-online {
    color: #22c55e;
    font-weight: 500;
}

.chat-main-header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.chat-action-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 50%;
    font-size: 1.1rem;
    color: var(--text-primary, #111827);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.chat-action-btn:hover {
    background: var(--bg-secondary, #f3f4f6);
}

/* ─── MESSAGES ───────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

/* ─── MESSAGE BUBBLES ────────────────────────────── */
.chat-message {
    display: flex;
    max-width: 75%;
    margin-bottom: 2px;
    animation: chatMsgIn 0.2s ease;
}

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

.chat-message.sent {
    align-self: flex-end;
}

.chat-message.received {
    align-self: flex-start;
}

.chat-message-bubble {
    padding: 8px 12px;
    border-radius: 16px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
    font-size: 0.9375rem;
    max-width: 100%;
    min-width: 0;
}

.chat-message-avatar {
    align-self: flex-end;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    margin-inline-end: 8px;
    display: none;
    overflow: hidden;
    border-radius: 50%;
    background: var(--primary-light, #ecfdf5);
    border: 2px solid var(--bg-primary, #fff);
    box-shadow: 0 2px 7px rgba(15, 46, 31, .16);
}

.chat-message.received .chat-message-avatar {
    display: block;
}

.chat-message-avatar img,
.chat-message-avatar svg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 50%;
}

.chat-message-avatar .avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(145deg,#176c4a,#39a878);
    font-size: 12px;
    font-weight: 800;
}

.chat-message.sent .chat-message-bubble {
    background: var(--primary-color, #059669);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.received .chat-message-bubble {
    background: var(--bg-secondary, #f3f4f6);
    color: var(--text-primary, #111827);
    border-bottom-left-radius: 4px;
}

.chat-message-bubble.chat-verse-msg {
    border-inline-start: 3px solid var(--primary-color, #059669);
    font-family: 'Amiri', 'Noto Kufi Arabic', serif;
    padding: 10px 12px;
}

.chat-message-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color, #059669);
    margin-bottom: 2px;
}

.chat-message.sent .chat-message-sender {
    display: none;
}

.chat-message-text {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.chat-message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
}

.chat-message-time {
    font-size: 0.625rem;
    opacity: 0.7;
}

.chat-message.sent .chat-message-time {
    color: rgba(255,255,255,0.8);
}

.chat-message.received .chat-message-time {
    color: var(--text-secondary, #9ca3af);
}

.chat-message-status {
    font-size: 0.625rem;
    color: rgba(255,255,255,0.8);
    opacity: 0.8;
}

.chat-message-reply {
    font-size: 0.75rem;
    padding: 4px 8px;
    margin-bottom: 4px;
    border-radius: 8px;
    opacity: 0.85;
    border-left: 3px solid rgba(255,255,255,0.4);
    cursor: pointer;
}

.chat-reply-text {
    opacity: 0.8;
}

.chat-message.received .chat-message-reply {
    border-left-color: var(--primary-color, #059669);
    background: rgba(0,0,0,0.04);
}

.chat-message-deleted {
    font-style: italic;
    opacity: 0.6;
}

/* ─── MESSAGE ACTIONS ────────────────────────────── */
.chat-message-actions {
    position: absolute;
    top: -8px;
    right: 8px;
    display: none;
    gap: 2px;
    background: var(--bg-primary, #fff);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    padding: 2px 4px;
    z-index: 10;
}

.chat-message:hover .chat-message-actions {
    display: flex;
}

.chat-message.sent .chat-message-actions {
    right: auto;
    left: 8px;
}

.chat-message-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.875rem;
    transition: background 0.15s;
    line-height: 1;
    min-width: 28px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-message-action-btn:hover {
    background: var(--bg-secondary, #f3f4f6);
}

/* ─── REACTIONS ──────────────────────────────────── */
.chat-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.chat-reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(0,0,0,0.06);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
    min-height: 24px;
}

.chat-reaction-chip:hover {
    background: rgba(0,0,0,0.1);
}

.chat-reaction-chip.active {
    border-color: var(--primary-color, #059669);
    background: var(--primary-light, #ecfdf5);
}

.chat-reaction-picker {
    position: absolute;
    bottom: calc(100% + 4px);
    right: 0;
    background: var(--bg-primary, #fff);
    border-radius: 24px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 6px 8px;
    display: none;
    gap: 2px;
    z-index: 20;
    flex-wrap: wrap;
    max-width: 260px;
}

.chat-reaction-picker.visible {
    display: flex;
}

.chat-reaction-option {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    padding: 6px;
    border-radius: 8px;
    transition: background 0.15s, transform 0.15s;
    line-height: 1;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-reaction-option:hover {
    background: var(--bg-secondary, #f3f4f6);
    transform: scale(1.2);
}

/* ─── DATE DIVIDER ───────────────────────────────── */
.chat-date-divider {
    text-align: center;
    margin: 12px 0;
    position: relative;
}

.chat-date-divider span {
    background: var(--bg-secondary, #f3f4f6);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-secondary, #6b7280);
    position: relative;
    z-index: 1;
}

/* ─── SKELETON LOADING ───────────────────────────── */
.chat-skeleton {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

.chat-skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--border-light, #e5e7eb);
    flex-shrink: 0;
}

.chat-skeleton-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: var(--border-light, #e5e7eb);
    width: 80%;
}

.chat-skeleton-line.short {
    width: 40%;
}

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

/* ─── NEW MESSAGES BUTTON ────────────────────────── */
.chat-new-messages-btn {
    position: sticky;
    bottom: 8px;
    align-self: center;
    z-index: 5;
    background: var(--primary-color, #059669);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 8px 20px;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(5,150,105,0.3);
    display: none;
    align-items: center;
    gap: 6px;
    transition: background 0.15s;
    margin-top: 8px;
}

.chat-new-messages-btn:hover {
    background: var(--primary-dark, #047857);
}

/* ─── NETWORK BANNER ─────────────────────────────── */
.chat-network-banner {
    background: #fef3c7;
    color: #92400e;
    padding: 8px 16px;
    font-size: 0.8125rem;
    text-align: center;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-bottom: 1px solid #fde68a;
    flex-shrink: 0;
}

/* ─── SEND BUTTON STATES ─────────────────────────── */
.chat-send-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: chatSpin 0.6s linear infinite;
}

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

/* ─── INPUT AREA ─────────────────────────────────── */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--bg-primary, #fff);
}

.chat-reply-preview {
    padding: 8px 12px;
    margin-bottom: 8px;
    background: var(--bg-secondary, #f3f4f6);
    border-radius: 8px;
    border-left: 3px solid var(--primary-color, #059669);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8125rem;
}

.chat-reply-preview-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-reply-preview-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    color: var(--text-secondary, #6b7280);
    flex-shrink: 0;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-input-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-end;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 24px;
    background: var(--bg-secondary, #f9fafb);
    padding: 4px 4px 4px 16px;
    transition: border-color 0.15s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary-color, #059669);
    box-shadow: 0 0 0 2px rgba(5,150,105,0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 0.9375rem;
    line-height: 1.4;
    max-height: 120px;
    min-height: 24px;
    padding: 8px 0;
    color: var(--text-primary, #111827);
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
}

.chat-input:disabled {
    opacity: 0.5;
}

.chat-input::placeholder {
    color: var(--text-secondary, #9ca3af);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color, #059669);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
    font-size: 1.1rem;
}

.chat-send-btn:hover {
    background: var(--primary-dark, #047857);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

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

/* ─── LOADING / EMPTY ────────────────────────────── */
.chat-loading {
    text-align: center;
    padding: 16px;
    color: var(--text-secondary, #9ca3af);
}

.chat-loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-light, #e5e7eb);
    border-top-color: var(--primary-color, #059669);
    border-radius: 50%;
    animation: chatSpin 0.6s linear infinite;
}

.chat-load-more {
    text-align: center;
    padding: 8px;
}

.chat-load-more button {
    background: none;
    border: 1px solid var(--border-color, #e5e7eb);
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 0.8125rem;
    color: var(--primary-color, #059669);
    cursor: pointer;
    transition: background 0.15s;
}

.chat-load-more button:hover {
    background: var(--primary-light, #ecfdf5);
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary, #6b7280);
    padding: 32px;
    text-align: center;
}

.chat-empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-empty h3 {
    font-size: 1.125rem;
    margin: 0 0 8px;
    color: var(--text-primary, #111827);
}

.chat-empty p {
    margin: 0;
    font-size: 0.875rem;
    max-width: 300px;
}

/* ─── TOAST ──────────────────────────────────────── */
.chat-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 24px;
    border-radius: 8px;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 10000;
    animation: chatToastIn 0.3s ease;
    white-space: nowrap;
}

.chat-toast-success { background: #059669; }
.chat-toast-error { background: #dc2626; }
.chat-toast-info { background: #2563eb; }

.chat-toast-hide {
    animation: chatToastOut 0.3s ease forwards;
}

@keyframes chatToastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes chatToastOut {
    to { opacity: 0; transform: translateX(-50%) translateY(20px); }
}

/* ─── UNREAD DIVIDER ─────────────────────────────── */
.chat-unread-divider {
    text-align: center;
    margin: 8px 0;
}

.chat-unread-divider span {
    background: var(--primary-color, #059669);
    color: #fff;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* ─── CONTEXT MENU ───────────────────────────────── */
.chat-context-menu {
    position: fixed;
    background: var(--bg-primary, #fff);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 4px;
    z-index: 100;
    min-width: 160px;
    display: none;
}

.chat-context-menu.visible {
    display: block;
}

.chat-context-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary, #111827);
    transition: background 0.15s;
    min-height: 40px;
}

.chat-context-item:hover {
    background: var(--bg-secondary, #f3f4f6);
}

.chat-context-item.danger {
    color: #ef4444;
}

/* ─── SEARCH RESULTS ─────────────────────────────── */
.chat-search-results {
    max-height: 400px;
    overflow-y: auto;
}

.chat-search-result-item {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-light, #f3f4f6);
    cursor: pointer;
    transition: background 0.15s;
}

.chat-search-result-item:hover {
    background: var(--bg-hover, #f0fdf4);
}

.chat-search-highlight {
    background: #fef08a;
    padding: 0 2px;
    border-radius: 2px;
}

/* ─── ADMIN CHAT DASHBOARD ───────────────────────── */
.admin-chat-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.admin-chat-stat-card {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.admin-chat-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color, #059669);
}

.admin-chat-stat-label {
    font-size: 0.8125rem;
    color: var(--text-secondary, #6b7280);
    margin-top: 4px;
}

/* ─── RTL ────────────────────────────────────────── */
[dir="rtl"] .chat-sidebar {
    border-right: none;
    border-left: 1px solid var(--border-color, #e5e7eb);
}

[dir="rtl"] .chat-conv-avatar {
    margin-left: 0;
    margin-right: 12px;
}

[dir="rtl"] .chat-conv-meta {
    text-align: right;
    margin-left: 0;
    margin-right: 8px;
    align-items: flex-start;
}

[dir="rtl"] .chat-message.sent .chat-message-bubble {
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .chat-message.received .chat-message-bubble {
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 4px;
}

[dir="rtl"] .chat-message.sent .chat-message-actions {
    right: 8px;
    left: auto;
}

[dir="rtl"] .chat-reply-preview {
    border-left: none;
    border-right: 3px solid var(--primary-color, #059669);
}

[dir="rtl"] .chat-message-reply {
    border-left: none;
    border-right: 3px solid rgba(255,255,255,0.4);
}

[dir="rtl"] .chat-message.received .chat-message-reply {
    border-right-color: var(--primary-color, #059669);
}

[dir="rtl"] .chat-reaction-picker {
    right: auto;
    left: 0;
}

[dir="rtl"] .chat-input-wrapper {
    padding: 4px 16px 4px 4px;
}

[dir="rtl"] .chat-context-item {
    text-align: right;
}

[dir="rtl"] .chat-input-area {
    direction: rtl;
}

/* ─── MOBILE (max-width: 768px) ──────────────────── */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 56px);
        border-radius: 0;
        max-width: 100%;
    }

    .chat-sidebar {
        width: 100%;
    }

    .chat-sidebar.hidden {
        display: none;
    }

    .chat-main.hidden {
        display: none;
    }

    .chat-message {
        max-width: 88%;
    }

    .chat-conv-item {
        padding: 10px 12px;
        min-height: 56px;
    }

    .chat-conv-avatar {
        width: 42px;
        height: 42px;
        margin-left: 10px;
    }

    [dir="rtl"] .chat-conv-avatar {
        margin-left: 0;
        margin-right: 10px;
    }

    .chat-messages {
        padding: 12px;
    }

    .chat-input-area {
        padding: 8px 12px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .chat-send-btn {
        width: 40px;
        height: 40px;
    }

    .chat-message-actions {
        display: none !important;
    }

    .chat-message:hover .chat-message-actions {
        display: none !important;
    }

    .chat-reaction-picker {
        position: fixed;
        bottom: 80px;
        left: 8px;
        right: 8px;
        max-width: none;
        border-radius: 16px;
        justify-content: center;
    }

    .chat-context-menu {
        position: fixed;
        bottom: 80px;
        left: 8px;
        right: 8px;
        min-width: auto;
    }

    .chat-main-header {
        padding: 10px 12px;
    }

    .chat-main-header-avatar {
        width: 36px;
        height: 36px;
    }

    .chat-main-header-text h3 {
        font-size: 0.9375rem;
    }

    .chat-new-messages-btn {
        bottom: 4px;
    }
}

/* ─── MOBILE BACK BUTTON ─────────────────────────── */
.chat-mobile-back {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 50%;
    font-size: 1.25rem;
    color: var(--text-primary, #111827);
    margin-right: 8px;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.chat-mobile-back:hover {
    background: var(--bg-secondary, #f3f4f6);
}

@media (max-width: 768px) {
    .chat-mobile-back {
        display: flex !important;
    }
}

/* ─── SMALL SCREENS (320-375px) ──────────────────── */
@media (max-width: 375px) {
    .chat-container {
        height: calc(100vh - 56px);
    }

    .chat-message {
        max-width: 92%;
    }

    .chat-message-bubble {
        padding: 6px 10px;
        font-size: 0.875rem;
    }

    .chat-conv-item {
        padding: 8px 10px;
    }

    .chat-conv-avatar {
        width: 38px;
        height: 38px;
    }

    .chat-input {
        font-size: 0.875rem;
    }
}

/* ─── PWA STANDALONE MODE ────────────────────────── */
@media (display-mode: standalone) {
    .chat-container {
        height: calc(100vh - 56px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }

    .chat-input-area {
        padding-bottom: env(safe-area-inset-bottom, 12px);
    }
}

/* ─── TABLET (768-1024px) ────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
    .chat-container {
        max-width: 100%;
        border-radius: 0;
        height: calc(100vh - 64px);
    }
}

/* ─── LANDSCAPE MOBILE ───────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    .chat-main-header {
        padding: 6px 12px;
    }

    .chat-input-area {
        padding: 6px 12px;
    }

    .chat-container {
        height: 100vh;
    }
}

/* 2026 WhatsApp-style conversation workspace */
.chat-container{max-width:1180px;height:calc(100dvh - 104px);border:1px solid var(--border-color,#dfe5e2);border-radius:20px;background:#efeae2;box-shadow:0 18px 50px rgba(15,46,31,.14)}
.chat-sidebar{width:360px;min-width:300px;background:var(--bg-primary,#fff);border-inline-end:1px solid var(--border-color,#dfe5e2);border-right:0}
.chat-sidebar-header,.chat-main-header{min-height:64px;background:var(--bg-secondary,#f0f2f5);border-color:var(--border-color,#dfe5e2)}
.chat-sidebar-close{width:36px;height:36px;border:0;border-radius:50%;background:transparent;color:var(--text-secondary,#667781);font-size:25px;cursor:pointer}.chat-sidebar-close:hover{background:rgba(0,0,0,.06)}
.chat-search{display:flex;align-items:center;gap:8px;margin:8px 12px;padding:0 12px;border:0;border-radius:10px;background:var(--bg-secondary,#f0f2f5)}.chat-search input{border:0;background:transparent;padding:10px 2px;box-shadow:none!important}
.chat-conv-item{min-height:72px;padding:10px 12px;border-bottom:1px solid var(--border-light,#eef1ef)}.chat-conv-item:hover{background:var(--bg-hover,#f5f6f6)}.chat-conv-item.active{background:var(--primary-light,#e7f7f0);border-inline-start:4px solid #00a884;border-left:0}.chat-conv-avatar{width:50px;height:50px;margin-inline:0 12px}.chat-conv-title{font-size:.98rem;font-weight:650}.chat-conv-preview{margin-top:4px;color:var(--text-secondary,#667781);font-size:.8rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chat-main{position:relative;background-color:#efeae2;background-image:radial-gradient(rgba(94,74,57,.055) 1px,transparent 1px);background-size:18px 18px}.chat-messages{padding:18px 6%;gap:2px}.chat-message{max-width:68%}.chat-message-bubble{padding:7px 10px 6px;border-radius:9px;box-shadow:0 1px 1px rgba(0,0,0,.09)}.chat-message.sent .chat-message-bubble{background:#d9fdd3;color:#111b21;border-bottom-right-radius:2px}.chat-message.received .chat-message-bubble{background:#fff;color:#111b21;border-bottom-left-radius:2px}.chat-message-status{color:#53bdeb}.chat-input-area{background:var(--bg-secondary,#f0f2f5);border-top:1px solid var(--border-color,#dfe5e2)}.chat-input{border:0!important;border-radius:12px!important;background:var(--bg-primary,#fff)!important}.chat-send-btn{background:#00a884!important}.chat-container.sidebar-collapsed .chat-sidebar{display:none}.chat-container.sidebar-collapsed{max-width:900px}
@media(max-width:768px){.chat-container{height:calc(100dvh - 56px);border:0;border-radius:0}.chat-container[data-conversation-id] .chat-sidebar{display:none}.chat-sidebar{min-width:0}.chat-sidebar-close{display:none}.chat-messages{padding:12px 10px}.chat-message{max-width:88%}.chat-main-header-actions{gap:2px}}
.chat-container.sidebar-collapsed .chat-mobile-back{display:flex}
