/* ========================================
   MESSAGING HUB — Messenger + WhatsApp
   Shared styles for chat tabs
   ======================================== */

/* Section: full-bleed like email */
#section-messenger,
#section-whatsapp,
#section-fb-comments {
    padding: 0;
    max-width: 100%;
    height: calc(100vh - 49px);
    flex-direction: column;
    overflow: hidden;
}

/* ============ TOOLBAR ============ */
.msg-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-card);
    flex-shrink: 0;
}

.msg-toolbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-right: auto;
}

.msg-filter-group {
    display: flex;
    gap: 4px;
}

.msg-filter-btn {
    padding: 4px 10px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: var(--bg-card);
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.msg-filter-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.msg-filter-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: transparent;
}

.msg-filter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
    background: var(--danger);
    color: #fff;
    margin-left: 4px;
}

/* ============ 2-PANEL LAYOUT ============ */
.msg-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    flex: 1;
    overflow: hidden;
    background: var(--bg-card);
}

/* ============ LEFT: CONVERSATION LIST ============ */
.msg-list {
    border-right: 1px solid var(--border-light);
    overflow-y: auto;
    background: var(--bg-body);
}

.msg-list-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.msg-list-empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.msg-conv-item {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.15s;
}

.msg-conv-item:hover {
    background: rgba(102, 126, 234, 0.04);
}

.msg-conv-item.active {
    background: rgba(102, 126, 234, 0.08);
    border-left: 3px solid #667eea;
    padding-left: 11px;
}

.msg-conv-item.unread {
    background: rgba(102, 126, 234, 0.03);
}

.msg-conv-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
}

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

.msg-conv-body {
    flex: 1;
    min-width: 0;
}

.msg-conv-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
}

.msg-conv-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-conv-name.unread {
    font-weight: 700;
}

.msg-conv-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
    flex-shrink: 0;
}

.msg-conv-snippet {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-conv-snippet.unread {
    color: var(--text-primary);
    font-weight: 500;
}

.msg-conv-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
}

.msg-account-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    line-height: 16px;
}

.msg-account-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.msg-settings-btn {
    font-size: 14px !important;
    padding: 4px 8px !important;
}

.msg-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.msg-status-dot.ai {
    background: #8b5cf6;
}
.msg-status-dot.agent {
    background: #22c55e;
}
.msg-status-dot.new {
    background: #3b82f6;
}

.msg-unread-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    margin-left: auto;
}

/* ============ SELECTION & BULK DELETE ============ */
.msg-list-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-bottom: 1px solid var(--border-light);
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 2;
}

.msg-list-header--select {
    background: linear-gradient(135deg, #f0f0ff, #f5f0ff);
    border-bottom-color: #e2e0f0;
}

.msg-list-header-count {
    flex: 1;
    font-size: 11px;
    color: var(--text-muted);
}

.msg-list-header-select-btn {
    padding: 3px 10px;
    border: 1px solid var(--border-light);
    border-radius: 5px;
    background: #fff;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.msg-list-header-select-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.msg-list-header-check {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.msg-list-header-check input {
    accent-color: #667eea;
    cursor: pointer;
}

.msg-list-header-del {
    margin-left: auto;
    padding: 4px 12px;
    border: none;
    border-radius: 5px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.msg-list-header-del:hover {
    opacity: 0.85;
}

.msg-list-header-cancel {
    padding: 3px 8px;
    border: 1px solid var(--border-light);
    border-radius: 5px;
    background: #fff;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    line-height: 1;
}

.msg-list-header-cancel:hover {
    color: var(--text-primary);
}

.msg-conv-cb {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #667eea;
    margin: 0;
    align-self: center;
}

.msg-conv-item.selected {
    background: rgba(102, 126, 234, 0.1);
}

/* ============ RIGHT: THREAD VIEW ============ */
.msg-thread {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.msg-thread-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
}

.msg-thread-empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.3;
}

/* Thread Header */
.msg-thread-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-card);
    flex-shrink: 0;
}

.msg-thread-back {
    display: none;
    padding: 4px 8px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: var(--bg-card);
    cursor: pointer;
    font-size: 14px;
}

.msg-thread-info {
    flex: 1;
    min-width: 0;
}

.msg-thread-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}
.msg-rename-btn {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.5;
    transition: opacity 0.15s;
    margin-left: 4px;
}
.msg-rename-btn:hover {
    opacity: 1;
    color: var(--primary);
}

.msg-thread-subtitle {
    font-size: 11px;
    color: var(--text-muted);
}

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

.msg-action-btn {
    padding: 5px 10px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: var(--bg-card);
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.msg-action-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.msg-action-btn.active {
    background: #8b5cf6;
    color: #fff;
    border-color: transparent;
}

.msg-action-btn.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* Messages Area */
.msg-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8f9fb;
}

/* Chat Bubbles */
.msg-bubble-wrap {
    display: flex;
    max-width: 70%;
}

.msg-bubble-wrap.inbound {
    align-self: flex-start;
}

.msg-bubble-wrap.outbound {
    align-self: flex-end;
}

.msg-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
}

.msg-bubble-wrap.inbound .msg-bubble {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 4px;
}

.msg-bubble-wrap.outbound .msg-bubble {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-bubble-wrap.outbound.ai .msg-bubble {
    background: linear-gradient(135deg, #8b5cf6, #a855f7);
}

.msg-bubble-sender {
    font-size: 10px;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.7;
}

.msg-bubble-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 3px;
    text-align: right;
}

.msg-bubble-status {
    font-size: 10px;
    margin-left: 4px;
}

/* ============ DRAFT BUBBLES ============ */
.msg-draft-wrap .msg-bubble {
    background: linear-gradient(135deg, #fef3c7, #fde68a) !important;
    color: #92400e !important;
    border: 2px dashed #f59e0b !important;
    border-radius: 12px !important;
}

.msg-draft-wrap .msg-bubble-sender {
    color: #b45309;
    opacity: 1;
    font-weight: 700;
}

.msg-draft-content {
    padding: 4px 0;
    outline: none;
    min-height: 20px;
}

.msg-draft-content.editing {
    background: #fff;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    padding: 6px 8px;
    color: #1e293b;
}

.msg-draft-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(245, 158, 11, 0.3);
}

.msg-draft-btn {
    padding: 4px 12px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.msg-draft-btn:hover {
    opacity: 0.85;
}

.msg-draft-btn.approve {
    background: #22c55e;
    color: #fff;
}

.msg-draft-btn.edit {
    background: #3b82f6;
    color: #fff;
}

.msg-draft-btn.regenerate {
    background: #8b5cf6;
    color: #fff;
}

.msg-draft-btn.reject {
    background: #ef4444;
    color: #fff;
}

/* System messages */
.msg-system {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    padding: 8px 0;
}

/* CRM Mini Card */
.msg-crm-card {
    margin: 8px 16px;
    padding: 8px 12px;
    background: var(--bg-body);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    flex-shrink: 0;
}

.msg-crm-card-name {
    font-weight: 600;
    color: var(--text-primary);
}

.msg-crm-card-stage {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
}

.msg-crm-card-link {
    margin-left: auto;
    color: var(--primary);
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
}

/* Input Bar */
.msg-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-card);
    flex-shrink: 0;
}

.msg-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    outline: none;
    transition: border-color 0.15s;
}

.msg-input:focus {
    border-color: #667eea;
}

.msg-send-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
}

.msg-send-btn:hover {
    opacity: 0.9;
}

.msg-send-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

/* ============ ACCOUNTS MODAL ============ */
.msg-accounts-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.msg-accounts-modal {
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    width: 680px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}

.msg-accounts-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border-light);
}

.msg-accounts-modal tbody tr {
    border-bottom: 1px solid var(--border-light);
    transition: background 0.1s;
}

.msg-accounts-modal tbody tr:hover {
    background: rgba(102, 126, 234, 0.04);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    .msg-layout {
        grid-template-columns: 1fr;
    }

    .msg-layout.thread-open .msg-list {
        display: none;
    }

    .msg-layout:not(.thread-open) .msg-thread {
        display: none;
    }

    .msg-thread-back {
        display: block;
    }
}
