/* ============================================================
 * AHB CRM — Messenger UI Styles
 * WhatsApp-inspired chat interface
 * ============================================================ */

/* ─── Messenger Layout ───────────────────────── */
.messenger-layout {
    display: flex;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* ─── Conversation Sidebar ───────────────────── */
.chat-sidebar {
    width: var(--chat-sidebar-width);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    flex-shrink: 0;
    min-height: 0;
}

.chat-sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.chat-search {
    position: relative;
}

.chat-search input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.chat-search input:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-search::before {
    content: '🔍';
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
}

.chat-filters {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem 0;
}

.chat-filter-btn {
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-xl);
    font-size: 0.8rem;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chat-filter-btn.active,
.chat-filter-btn:hover {
    background: var(--primary-light);
    color: var(--primary-hover);
    border-color: var(--primary);
}

/* ─── Conversation List ──────────────────────── */
.conversation-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: all var(--transition-fast);
    position: relative;
    border-left: 3px solid transparent;
}

.conversation-item:hover {
    background: var(--bg-hover);
    border-left-color: rgba(99, 102, 241, 0.3);
}

.conversation-item.active {
    background: var(--primary-light);
    border-left-color: var(--primary);
}

.conversation-item.unread {
    background: rgba(99, 102, 241, 0.03);
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-name-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.conversation-name {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-item.unread .conversation-name {
    font-weight: 600;
}

.conversation-label-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.conversation-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-top: 0.1rem;
}

.conversation-preview {
    font-size: 0.8rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 0.15rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.conversation-preview .preview-icon {
    flex-shrink: 0;
    font-size: 0.75rem;
}

.conversation-item.unread .conversation-preview {
    color: var(--text-secondary);
    font-weight: 500;
}

.conversation-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
    flex-shrink: 0;
    transition: opacity var(--transition-fast);
}

.conversation-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.conversation-item.unread .conversation-time {
    color: var(--primary);
    font-weight: 600;
}

.conversation-assigned {
    font-size: 0.65rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

/* Quick Actions on Hover (Respond.io 3.0 pattern) */
.conv-quick-actions {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    z-index: 2;
}

.conversation-item:hover .conv-quick-actions {
    opacity: 1;
    pointer-events: auto;
}

.conversation-item:hover .conversation-meta {
    opacity: 0;
    pointer-events: none;
}

.conv-quick-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.conv-quick-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
    transform: scale(1.1);
}

.conv-quick-btn.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-color: var(--danger);
}

/* ─── Chat Area ──────────────────────────────── */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
    min-height: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 1.25rem;
    background: linear-gradient(135deg, var(--bg-secondary), rgba(99, 102, 241, 0.03));
    border-bottom: 1px solid var(--border-color);
    z-index: 5;
    backdrop-filter: blur(12px);
    position: relative;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.15), rgba(168, 85, 247, 0.1), transparent);
}

/* ─── Header Avatar (Premium Gradient) ───── */
.chat-header .avatar {
    width: 42px;
    height: 42px;
    font-size: 1rem;
    background: linear-gradient(135deg, #6366f1, #8b5cf6, #a855f7);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
    position: relative;
    flex-shrink: 0;
}

.chat-header .avatar-status {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    background: #22c55e;
}

.chat-header .avatar-status.online {
    background: #22c55e;
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(34, 197, 94, 0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Clickable avatar hover */
.chat-header .avatar:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.chat-header-name .header-tag {
    font-size: 0.6rem;
    padding: 1px 6px;
    border-radius: 4px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(168, 85, 247, 0.08));
    color: var(--primary);
    font-weight: 500;
}

.chat-header-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.chat-header-status .status-text {
    color: #22c55e;
    font-weight: 500;
}

/* ─── Header Actions (Premium Grouped) ───── */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.header-action-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.02);
}

.header-action-group+.header-action-group {
    margin-left: 4px;
}

.header-action-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 4px;
    opacity: 0.5;
}

.chat-action-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 0.9rem;
    position: relative;
}

.chat-action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.chat-action-btn:active {
    transform: translateY(0);
}

/* Primary action buttons with accent */
.chat-action-btn.primary-action {
    color: var(--primary);
}

.chat-action-btn.primary-action:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

/* Danger action buttons */
.chat-action-btn.danger-action:hover {
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger);
}

/* ─── Conv Action Bar (Inline in header) ─── */
.conv-actions-bar {
    display: flex;
    align-items: center;
    gap: 2px;
}

.conv-action-btn {
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.78rem;
    transition: all var(--transition-fast);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.conv-action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.conv-action-btn.assign:hover {
    background: rgba(99, 102, 241, 0.08);
    color: var(--primary);
}

.conv-action-btn.close-conv:hover,
.conv-action-btn.reopen:hover {
    background: rgba(239, 68, 68, 0.06);
    color: var(--danger);
}

/* ─── Messages ───────────────────────────────── */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    scrollbar-width: thin;
    min-height: 0;
}

/* Push messages to bottom when few, allow natural scroll when many */
.messages-container::before {
    content: '';
    margin-top: auto;
}

.message-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.message-date-separator {
    text-align: center;
    padding: 0.5rem;
}

.message-date-separator span {
    background: var(--bg-glass);
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-xl);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.message {
    max-width: 65%;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-lg);
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 0.9rem;
}

.message.inbound {
    align-self: flex-start;
    background: var(--bg-tertiary);
    border-bottom-left-radius: 4px;
}

.message.outbound {
    align-self: flex-end;
    background: #dcf8c6;
    color: #1a1a2e;
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
}

.message-status {
    font-size: 0.7rem;
}

.message-status.sent {
    color: var(--text-muted);
}

.message-status.delivered {
    color: var(--text-secondary);
}

.message-status.read {
    color: #53bdeb;
}

/* ─── Media Messages ─────────────────────────── */
.message-image {
    border-radius: var(--radius-md);
    max-width: 280px;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.message-image:hover {
    transform: scale(1.02);
}

.message-document {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    cursor: pointer;
}

.message-document .doc-icon {
    font-size: 1.5rem;
}

.message-document .doc-name {
    font-size: 0.8rem;
    flex: 1;
}

.message-document .doc-size {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ─── Compose Area ───────────────────────────── */
.compose-area {
    padding: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.compose-row {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
}

.compose-actions {
    display: flex;
    gap: 0.25rem;
}

.compose-input-wrapper {
    flex: 1;
    position: relative;
}

.compose-input {
    width: 100%;
    min-height: 40px;
    max-height: 120px;
    padding: 0.5rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
}

.compose-input:focus {
    outline: none;
    border-color: var(--primary);
}

.compose-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.compose-send:hover {
    box-shadow: var(--shadow-glow);
    transform: scale(1.05);
}

/* ─── Reply Bar (in compose area) ────────────── */
.reply-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid var(--border-color);
    border-left: 3px solid var(--primary);
}

.reply-bar-content {
    flex: 1;
    min-width: 0;
}

.reply-bar-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
}

.reply-bar-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-bar-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
}

.reply-bar-close:hover {
    color: var(--text-primary);
}

/* ─── Media Preview (in compose area) ────────── */
.media-preview {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    background: rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid var(--border-color);
}

.media-preview-content {
    flex: 1;
}

.media-preview-content img {
    border-radius: 6px;
}

.media-preview-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
}

.media-preview-close:hover {
    color: var(--danger);
}

/* ─── Message Dropdown Menu ──────────────────── */
.msg-dropdown {
    position: absolute;
    top: 0.3rem;
    right: 0.3rem;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.message:hover .msg-dropdown {
    opacity: 1;
}

.message.inbound .msg-dropdown {
    right: auto;
    left: 0.3rem;
}

.msg-dropdown-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: var(--bg-glass);
    color: var(--text-muted);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.msg-dropdown-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.msg-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 130px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.25rem 0;
    box-shadow: var(--shadow-lg);
    z-index: 50;
}

.message.inbound .msg-dropdown-menu {
    right: auto;
    left: 0;
}

.msg-dropdown.open .msg-dropdown-menu {
    display: block;
}

.msg-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.82rem;
    text-align: left;
    transition: background var(--transition-fast);
}

.msg-menu-item:hover {
    background: var(--bg-hover);
}

.msg-menu-icon {
    font-size: 0.9rem;
}

/* ─── Quoted Message (in message bubble) ─────── */
.quoted-message {
    padding: 0.4rem 0.6rem;
    margin-bottom: 0.35rem;
    border-left: 3px solid var(--primary);
    background: var(--bg-glass);
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.quoted-message:hover {
    background: var(--bg-hover);
}

/* ─── Contact Menu (chat header dropdown) ────── */
.contact-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 230px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 0.35rem 0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(99, 102, 241, 0.04);
    backdrop-filter: blur(20px);
    z-index: 100;
    animation: slideUp 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.contact-menu-section {
    padding: 0.5rem 1rem 0.25rem;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    margin-top: 0.2rem;
}

.contact-menu-section:first-child {
    border-top: none;
    margin-top: 0;
}

.contact-menu-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.55rem 1rem;
    border: none;
    border-left: 3px solid transparent;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.82rem;
    text-align: left;
    transition: all 0.15s ease;
}

.contact-menu-item span:first-child {
    font-size: 1rem;
    transition: transform 0.2s ease;
}

.contact-menu-item:hover {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.06), transparent);
    border-left-color: var(--primary);
    padding-left: 1.1rem;
}

.contact-menu-item:hover span:first-child {
    transform: scale(1.15);
}

.contact-menu-item:active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.12), transparent);
}

/* Danger items in menu */
.contact-menu-item[style*="color:var(--danger)"]:hover,
.contact-menu-item[style*="color: var(--danger)"]:hover {
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.06), transparent);
    border-left-color: var(--danger);
}

/* ─── Tag Badges ─────────────────────────────── */
.tag-badges {
    display: flex;
    gap: 0.3rem;
    align-items: center;
    flex-wrap: wrap;
}

.tag-badge {
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-xl);
    font-size: 0.7rem;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

/* ─── Message Highlight (scroll-to-reply) ────── */
.message.highlight {
    animation: msgHighlight 2s ease;
}

@keyframes msgHighlight {

    0%,
    20% {
        background: rgba(99, 102, 241, 0.3);
    }

    100% {
        background: inherit;
    }
}

/* ─── Quick Reply Picker ─────────────────────── */
.quick-reply-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
    display: none;
}

.quick-reply-picker.active {
    display: block;
}

.quick-reply-item {
    padding: 0.6rem 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}

.quick-reply-item:hover {
    background: var(--bg-hover);
}

.quick-reply-item .qr-shortcut {
    font-size: 0.75rem;
    color: var(--primary);
    font-family: var(--font-mono);
}

.quick-reply-item .qr-content {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

/* ─── Chat Empty State ───────────────────────── */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.chat-empty .empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

/* ─── Lightbox ───────────────────────────────── */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    cursor: zoom-out;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.lightbox.active {
    opacity: 1;
    visibility: visible;
}

.lightbox img {
    max-width: 90%;
    max-height: 90vh;
    border-radius: var(--radius-md);
}

/* ─── Contact Info Panel ─────────────────────── */
.contact-info-panel {
    width: 0;
    overflow: hidden;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.contact-info-panel.open {
    width: 320px;
}

.contact-info-panel .cip-inner {
    width: 320px;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
}

.cip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.cip-header h4 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.cip-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.cip-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.cip-profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem 1rem;
    text-align: center;
}

.cip-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.cip-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.cip-phone {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.cip-lead-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-xl);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.6rem;
}

.cip-lead-badge.customer {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.cip-lead-badge.qualified {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.cip-lead-badge.new {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.cip-section {
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border-color);
}

.cip-section-title {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
}

.cip-field {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.4rem 0;
}

.cip-field-icon {
    font-size: 0.85rem;
    margin-top: 0.1rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.cip-field-content {
    flex: 1;
    min-width: 0;
}

.cip-field-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.1rem;
}

.cip-field-value {
    font-size: 0.85rem;
    color: var(--text-primary);
    word-break: break-word;
}

.cip-field-value.empty {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.8rem;
}

/* Lead Score Bar */
.cip-score-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 0.35rem;
}

.cip-score-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
}

.cip-score-fill.high {
    background: linear-gradient(90deg, #10b981, #34d399);
}

.cip-score-fill.medium {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.cip-score-fill.low {
    background: linear-gradient(90deg, #ef4444, #f87171);
}

/* Quick Action Buttons */
.cip-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0 1rem 0.85rem;
}

.cip-action-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.6rem;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
    transition: all var(--transition-fast);
}

.cip-action-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: rgba(99, 102, 241, 0.3);
}

.cip-action-btn span:first-child {
    font-size: 1rem;
}

/* Order Items */
.cip-order-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.6rem;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    margin-bottom: 0.4rem;
    font-size: 0.8rem;
}

.cip-order-id {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--primary);
}

.cip-order-status {
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-xl);
    font-size: 0.68rem;
    font-weight: 600;
}

.cip-order-status.pending {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.cip-order-status.confirmed {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.cip-order-status.preparing {
    background: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
}

.cip-order-status.delivering {
    background: rgba(14, 165, 233, 0.15);
    color: #0ea5e9;
}

.cip-order-status.delivered {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.cip-order-status.cancelled {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* Toggle Button Active State */
.chat-action-btn.cip-active {
    background: var(--primary-light);
    color: var(--primary);
}

/* ─── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
    .chat-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        z-index: 20;
        transform: translateX(0);
    }

    .chat-sidebar.hidden-mobile {
        transform: translateX(-100%);
    }

    .chat-area.hidden-mobile {
        display: none;
    }

    .message {
        max-width: 85%;
    }

    .compose-actions {
        display: flex;
        /* Keep attachment button on mobile */
    }
}

/* ─── Modal Overlay & Dialog ─────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    animation: fadeIn 0.2s ease;
}

.modal-dialog {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
    min-width: 300px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Template Picker (Compose Area) ─────────── */
.template-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
    display: none;
    z-index: 200;
    animation: slideUp 0.2s ease;
}

.template-picker.active {
    display: block;
}

.template-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.template-picker-header button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
}

.template-search {
    width: 100%;
    padding: 0.4rem 0.85rem;
    background: var(--bg-input);
    border: none;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.82rem;
    outline: none;
}

.template-item {
    padding: 0.6rem 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}

.template-item:hover {
    background: var(--bg-hover);
}

.template-item:last-child {
    border-bottom: none;
}

.template-item-name {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.template-item-category {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    background: var(--primary-light);
    color: var(--primary);
}

.template-item-preview {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ─── Dark Mode Overrides ────────────────────── */
[data-theme="dark"] .message.outbound {
    background: linear-gradient(135deg, #1a3a2a, #1e4620);
    color: #e2e8f0;
}

[data-theme="dark"] .quick-reply-picker {
    backdrop-filter: blur(20px);
}

[data-theme="dark"] .conv-quick-btn {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

/* ─── Emoji Picker ───────────────────────────── */
.emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    width: 340px;
    max-height: 380px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    margin-bottom: 0.5rem;
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 200;
    animation: slideUp 0.2s ease;
}

.emoji-picker.active {
    display: flex;
}

.emoji-picker-header {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.emoji-search {
    width: 100%;
    padding: 0.4rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    color: var(--text-primary);
    font-size: 0.82rem;
}

.emoji-search:focus {
    outline: none;
    border-color: var(--primary);
}

.emoji-tabs {
    display: flex;
    gap: 0;
    padding: 0;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    scrollbar-width: none;
}

.emoji-tabs::-webkit-scrollbar {
    display: none;
}

.emoji-tab {
    flex: 1;
    min-width: 36px;
    padding: 0.4rem 0;
    font-size: 1.1rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
}

.emoji-tab:hover {
    background: var(--bg-hover);
}

.emoji-tab.active {
    border-bottom-color: var(--primary);
    background: var(--primary-light);
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 0.5rem;
    overflow-y: auto;
    max-height: 260px;
    scrollbar-width: thin;
}

.emoji-item {
    font-size: 1.4rem;
    text-align: center;
    padding: 0.3rem;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    line-height: 1;
}

.emoji-item:hover {
    background: var(--bg-hover);
    transform: scale(1.2);
}

.emoji-no-result {
    grid-column: 1 / -1;
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ─── Voice Recording ────────────────────────── */
.compose-right-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.voice-record-btn.recording {
    background: rgba(239, 68, 68, 0.2) !important;
    color: var(--danger) !important;
    animation: voicePulse 1.5s ease-in-out infinite;
}

.voice-recording-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.08), rgba(239, 68, 68, 0.15));
    border-top: 1px solid rgba(239, 68, 68, 0.3);
}

.voice-rec-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--danger);
    flex: 1;
}

.voice-rec-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    animation: voicePulse 1.2s ease-in-out infinite;
}

.voice-rec-timer {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 40px;
}

@keyframes voicePulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(0.85);
    }
}

/* ─── Message Search Bar ─────────────────────── */
.msg-search-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.msg-search-input {
    flex: 1;
    padding: 0.4rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.msg-search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.msg-search-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 50px;
    text-align: center;
}

/* ─── Dark Mode — New Features ───────────────── */
[data-theme="dark"] .emoji-picker {
    background: var(--bg-card);
    border-color: var(--border-color);
}

[data-theme="dark"] .voice-recording-bar {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(239, 68, 68, 0.18));
}

/* ─── Analytics Row (CSAT + Chart side-by-side) ── */
.analytics-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (max-width: 768px) {
    .analytics-row {
        flex-direction: column;
    }
}

.csat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.82rem;
}

.csat-row span:first-child {
    min-width: 80px;
    text-align: right;
}

.csat-row span:last-child {
    min-width: 30px;
    text-align: right;
    font-weight: 600;
}

/* ─── Typing Indicator ──────────────────────── */
.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 8px 14px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-6px);
    }
}

/* ─── AI Suggestion Bar ────────────────────── */
.ai-suggestions-bar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    background: rgba(99, 102, 241, 0.04);
    overflow-x: auto;
}

.ai-suggestion-chip {
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid var(--primary);
    background: rgba(99, 102, 241, 0.08);
    color: var(--primary);
    font-size: 0.78rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.ai-suggestion-chip:hover {
    background: var(--primary);
    color: #fff;
}

/* ============================================================
 * RESPONSIVE — Tablet & Mobile
 * ============================================================ */

/* ─── Tablet (≤ 1024px) ─────────────────────── */
@media (max-width: 1024px) {
    .chat-sidebar {
        width: 280px;
    }

    .chat-header {
        padding: 0.6rem 0.75rem;
        gap: 0.5rem;
    }

    .header-action-group {
        gap: 1px;
    }

    .header-action-divider {
        margin: 0 2px;
    }

    .compose-area {
        padding: 0.5rem 0.75rem;
    }

    .contact-info-panel {
        width: 280px;
    }
}

/* ─── Mobile (≤ 768px) ──────────────────────── */
@media (max-width: 768px) {

    /* Sidebar takes full width, chat-area hidden by default */
    .messenger-layout {
        position: relative;
    }

    .chat-sidebar {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
    }

    .chat-area {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 5;
        display: none;
    }

    /* When a conversation is open, show chat-area, hide sidebar */
    .messenger-layout.chat-open .chat-sidebar {
        display: none;
    }

    .messenger-layout.chat-open .chat-area {
        display: flex;
    }

    /* Back button visible on mobile */
    .messenger-layout.chat-open #back-btn {
        display: inline-flex !important;
    }

    /* Header compact */
    .chat-header {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }

    .chat-header .avatar {
        width: 36px;
        height: 36px;
        font-size: 0.85rem;
    }

    .chat-header-name {
        font-size: 0.85rem;
    }

    .chat-header-status {
        font-size: 0.7rem;
    }

    .chat-action-btn {
        width: 30px;
        height: 30px;
        font-size: 0.8rem;
    }

    .header-action-divider {
        display: none;
    }

    /* Messages area */
    .messages-container {
        padding: 0.75rem;
    }

    .message-bubble {
        max-width: 85%;
        font-size: 0.85rem;
    }

    /* Compose area */
    .compose-area {
        padding: 0.5rem;
    }

    .compose-area textarea,
    .compose-area input[type="text"] {
        font-size: 0.85rem;
    }

    /* Conversation cards — quick actions always visible on mobile (no hover) */
    .conv-quick-actions {
        opacity: 1;
        pointer-events: auto;
    }

    .conversation-item:hover .conversation-meta {
        opacity: 1;
        pointer-events: auto;
    }

    .conv-quick-btn {
        width: 26px;
        height: 26px;
        font-size: 0.7rem;
    }

    /* Contact info panel — full overlay on mobile (ONLY when open) */
    .contact-info-panel {
        /* Stay hidden by default */
        width: 0;
    }

    .contact-info-panel.open {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        z-index: 50;
        border-left: none;
    }

    /* Contact menu */
    .contact-menu {
        min-width: 200px;
        right: -8px;
    }

    /* Template picker */
    .template-picker {
        width: calc(100% - 1rem);
        left: 0.5rem;
    }

    /* Notes panel */
    .notes-panel {
        width: 100%;
        max-width: 100%;
    }

    /* Assign dropdown */
    .assign-dropdown {
        min-width: 200px;
        right: 0;
    }

    /* Search bar compact */
    .msg-search-bar {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .msg-search-input {
        width: 100%;
    }
}

/* ─── Small Mobile (≤ 480px) ────────────────── */
@media (max-width: 480px) {
    .chat-sidebar-header {
        padding: 0.75rem;
    }

    .chat-search input {
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem 0.4rem 2rem;
    }

    .conversation-item {
        padding: 0.6rem 0.75rem;
    }

    .conversation-name {
        font-size: 0.82rem;
    }

    .conversation-preview {
        font-size: 0.7rem;
    }

    .chat-header-actions {
        gap: 0;
    }

    .header-action-group {
        padding: 2px;
    }

    /* Hide assign button text on very small screens */
    .conv-actions-bar {
        gap: 0;
    }
}