/* style.css - Premium Flat Zalo Web Light Theme Stylesheet for RioAZCRM */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-main: #f4f5f7;
    --bg-card: #ffffff;
    --border-color: #dbdde2;
    --primary: #0068ff;
    --primary-glow: rgba(0, 104, 255, 0.1);
    --primary-gradient: linear-gradient(135deg, #0068ff, #1e75ff);
    --ai-gradient: linear-gradient(135deg, #f59e0b, #ec4899);
    --ai-glow: rgba(245, 158, 11, 0.15);
    --text-main: #1c1d21;
    --text-muted: #757f90;
    --online-color: #10b981;
    --online-glow: rgba(16, 185, 129, 0.2);
    
    /* Lead grade colors */
    --grade-a: #d97706;
    --grade-b: #0891b2;
    --grade-c: #4b5563;
    --grade-d: #6b7280;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.24);
}

/* Glassmorphism utility replaced with Flat utility */
.glass-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Login Screen */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: #eef1f6;
}

.login-card {
    width: 420px;
    padding: 40px;
    text-align: center;
    background: #ffffff;
    border: 1px solid #dbdde2;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.login-logo {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 30px;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

select.form-input {
    background-color: #ffffff !important;
    color: var(--text-main) !important;
    cursor: pointer;
}

select.form-input option {
    background-color: #ffffff;
    color: var(--text-main);
}

.btn {
    width: 100%;
    padding: 10px;
    background: var(--primary);
    border: none;
    border-radius: 6px;
    color: white;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn:hover {
    background: #0056d6;
    transform: none;
    box-shadow: none;
}

.btn:active {
    transform: translateY(1px);
}

/* Dashboard Workspace Layout */
.app-container {
    display: grid;
    grid-template-columns: 1fr;
    height: 100vh;
    padding: 0;
    gap: 0;
}

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

.sidebar-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}

/* Zalo accounts section - flat style */
.zalo-accounts-section {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.zalo-account-badge {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 6px;
    background: #f4f5f7;
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.zalo-account-badge:hover, .zalo-account-badge.active {
    background: #e5efff;
    border-color: var(--primary);
}

.avatar-wrapper {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 12px;
}

.avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #dbdde2;
}

.status-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--text-muted);
    border: 2px solid #ffffff;
}

.status-dot.online {
    background-color: var(--online-color);
    box-shadow: none;
}

.status-dot.qr-pending {
    background-color: #f59e0b;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

/* Zalo web style conversation item */
.conversation-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid #f2f3f5;
    position: relative;
}

.conversation-item:hover {
    background: #f3f5f8;
}

.conversation-item.active {
    background: #e5efff;
}

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

.conv-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.conv-name {
    font-weight: 500;
    font-size: 14px;
    color: #1c1d21;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-meta {
    display: flex;
    align-items: center;
    gap: 6px;
}

.badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

.badge-grade {
    background: #e5e7eb;
    color: #4b5563;
}
.badge-grade.A { color: white; background: var(--grade-a); }
.badge-grade.B { color: white; background: var(--grade-b); }
.badge-grade.C { color: white; background: var(--grade-c); }

/* Main Workspace Column */
.main-workspace {
    display: grid;
    grid-template-rows: 60px 1fr;
    height: 100vh;
    overflow: hidden;
    background: #ffffff;
}

.workspace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    background: #ffffff;
}

.tab-menu {
    display: flex;
    gap: 6px;
    align-items: center;
}

.tab-btn {
    padding: 8px 14px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-btn:hover {
    color: var(--primary);
    background: rgba(0, 104, 255, 0.05);
}

.tab-btn.active {
    color: var(--primary);
    background: var(--primary-glow);
    font-weight: 600;
}

.tab-icon {
    opacity: 0.65;
    transition: all 0.2s ease;
    stroke: var(--text-muted);
}

.tab-btn:hover .tab-icon, .tab-btn.active .tab-icon {
    opacity: 1;
    stroke: var(--primary);
}

/* Tab contents */
.workspace-content {
    position: relative;
    overflow: hidden;
    min-height: 0;
    background: #f4f5f7;
}

.tab-content {
    display: none;
    height: 100%;
    padding: 20px;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

/* Sub-tabs Styling (Premium Style) */
.sub-tab-menu-horizontal {
    display: flex;
    gap: 6px;
    padding: 12px 20px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
}

.sub-tab-btn {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.sub-tab-btn:hover {
    color: var(--primary);
    background: #f0f4fa;
}

.sub-tab-btn.active {
    color: var(--primary);
    background: #e5efff;
    font-weight: 600;
}

.sub-tab-wrapper-vertical {
    display: grid;
    grid-template-columns: 220px 1fr;
    height: 100%;
    background: #ffffff;
}

.sub-tab-sidebar-vertical {
    background: #f8f9fa;
    border-right: 1px solid var(--border-color);
    padding: 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: 100%;
    overflow-y: auto;
}

.sub-tab-sidebar-vertical .sub-tab-btn {
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    justify-content: flex-start;
}

.sub-tab-content-container-vertical {
    height: 100%;
    overflow: hidden;
    position: relative;
    background: #ffffff;
}

.sub-tab-content {
    display: none;
    height: 100%;
    padding: 20px;
    overflow-y: auto;
}

.sub-tab-content.active {
    display: block;
}

/* Specific grids inside sub-tabs */
#automation-tab.active, #campaign-tab.active {
    display: grid !important;
}
#playground-tab.active {
    display: grid !important;
}
#rbac-tab.active {
    display: grid !important;
}

/* Reset padding for main tabs containing subtabs */
#dashboard-tab, #customers-hub-tab, #automation-hub-tab, #settings-hub-tab {
    padding: 0 !important;
}


/* Chat view specific layout (4 Columns Zalo Web Style) */
#chat-tab {
    display: none;
    grid-template-columns: 64px 340px 1fr 300px;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: #ffffff;
}

#chat-tab.active {
    display: grid;
}

/* Cột 1: Zalo Sidebar Left (Nick Selector) */
.zalo-sidebar-left {
    background: #005ae0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    gap: 16px;
    height: 100%;
    border-right: 1px solid rgba(0,0,0,0.1);
}

.zalo-sidebar-avatar-item {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.zalo-sidebar-avatar-item:hover {
    transform: scale(1.05);
}

.zalo-sidebar-avatar-item.active {
    border-color: #ffffff;
    box-shadow: 0 0 10px rgba(255,255,255,0.4);
}

.zalo-sidebar-avatar-item img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.zalo-sidebar-avatar-item .status-dot {
    width: 11px;
    height: 11px;
    border: 2px solid #005ae0;
    bottom: 0px;
    right: 0px;
}

.zalo-sidebar-add-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px dashed rgba(255, 255, 255, 0.4);
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-size: 20px;
    font-weight: 600;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    margin-top: auto;
    transition: all 0.2s ease;
}

.zalo-sidebar-add-btn:hover {
    border-color: #ffffff;
    color: #ffffff;
    background: rgba(255,255,255,0.1);
}

/* Cột 2: Conversations list sidebar */
.chat-tab-sidebar {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    border-right: 1px solid var(--border-color);
    background: #ffffff;
}

/* Cột 3: Khung chat chính */
.chat-box {
    display: grid;
    grid-template-rows: 60px 1fr auto;
    height: 100%;
    border-right: 1px solid var(--border-color);
    background: #eef1f6; /* Nền chat Zalo */
    min-height: 0;
}

.chat-box-header {
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 20px;
}

.messages-area {
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.msg-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 65%;
    animation: slideUp 0.15s ease-out;
}

.msg-wrapper.self {
    align-self: flex-end;
    align-items: flex-end;
}

.msg-wrapper.peer {
    align-self: flex-start;
    align-items: flex-start;
}

.msg-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 3px;
    padding: 0 4px;
}

.msg-wrapper.self .msg-meta {
    text-align: right;
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: 8px;
    line-height: 1.45;
    font-size: 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    word-break: break-word;
}

.msg-text-content {
    white-space: pre-wrap;
}

.msg-wrapper.self .msg-bubble {
    background: #e5efff; /* Xanh nhạt Zalo */
    color: #1c1d21;
    border-top-right-radius: 2px;
}

.msg-wrapper.peer .msg-bubble {
    background: #ffffff; /* Trắng */
    color: #1c1d21;
    border-top-left-radius: 2px;
}

/* AI Draft Message bubble */
.msg-wrapper.ai-draft {
    align-self: flex-end;
    max-width: 75%;
}

.msg-wrapper.ai-draft .msg-bubble {
    background: #fffbeb;
    color: #b45309;
    border: 1px dashed #f59e0b;
    box-shadow: none;
    border-top-right-radius: 2px;
}

.ai-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 6px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    border: none;
}

.btn-ai-send {
    background: #f59e0b;
    color: white;
}

.btn-ai-edit {
    background: #e5e7eb;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-ai-send:hover, .btn-ai-edit:hover {
    filter: brightness(0.95);
}

/* Chat Input Bar - Flat style */
.input-area {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    position: relative;
}

.input-container-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px 16px;
}

.input-box {
    flex: 1;
    position: relative;
}

.chat-input {
    width: 100%;
    padding: 12px 16px;
    padding-right: 40px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s ease;
    resize: none;
    height: 44px;
    line-height: 1.4;
    overflow-y: auto;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-send-chat {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--primary);
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: none;
    transition: all 0.2s ease;
}

.btn-send-chat:hover {
    background: #0056d6;
    transform: none;
}

.btn-ai-trigger {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #f59e0b;
    cursor: pointer;
    font-size: 18px;
    transition: transform 0.2s ease;
}

.btn-ai-trigger:hover {
    transform: translateY(-50%) scale(1.15);
}

/* Cột 4: Contact Info Sidebar Column (Right Side of Chat) */
.contact-sidebar {
    background: #ffffff;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    border-left: 1px solid var(--border-color);
}

.contact-avatar-big {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 1px solid #dbdde2;
    object-fit: cover;
}

.contact-name-big {
    font-size: 16px;
    font-weight: 600;
    color: #1c1d21;
}

.score-panel {
    width: 100%;
    padding: 12px;
    background: #f4f5f7;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.score-item {
    text-align: center;
}

.score-val {
    font-size: 20px;
    font-weight: 700;
    color: var(--grade-a);
}

.score-lbl {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.grade-val {
    font-size: 26px;
    font-weight: 800;
}
.grade-val.A { color: var(--grade-a); }
.grade-val.B { color: var(--grade-b); }
.grade-val.C { color: var(--grade-c); }

.labels-manager {
    width: 100%;
}

.labels-header {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 12px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tag-remove {
    cursor: pointer;
    color: #ef4444;
}

.tag-add-btn {
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 12px;
    background: #e5efff;
    border: 1px dashed var(--primary);
    color: var(--primary);
    cursor: pointer;
}

/* QR Code scanning box modal overlay */
.qr-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.qr-box {
    width: 360px;
    padding: 30px;
    text-align: center;
    background: #ffffff;
    border: 1px solid #dbdde2;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.qr-image-container {
    width: 200px;
    height: 200px;
    margin: 20px auto;
    background: white;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border: 1px solid #dbdde2;
}

.qr-image-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

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

/* Chat Toolbar & Emoji Picker styles */
.chat-toolbar {
    display: flex;
    gap: 6px;
    padding: 8px 16px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

.toolbar-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 15px;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-btn:hover {
    color: var(--primary) !important;
    background: #f0f4fa;
    transform: none;
}

.emoji-picker-popup {
    animation: fadeIn 0.15s ease-out;
}

.emoji-item {
    font-size: 20px;
    padding: 4px;
    cursor: pointer;
    text-align: center;
    border-radius: 4px;
    transition: all 0.1s ease;
    user-select: none;
}

.emoji-item:hover {
    background: #e5efff;
    transform: scale(1.1);
}

.chat-box {
    grid-template-rows: 60px 1fr auto !important;
}

.input-area {
    display: flex;
    flex-direction: column;
    align-items: stretch !important;
    gap: 0px !important;
    padding: 0px !important;
    position: relative;
}

/* Sticker Picker & Recalled Message styles */
.sticker-picker-popup {
    animation: fadeIn 0.15s ease-out;
}

.sp-chip {
    font-size: 11px;
    padding: 3px 8px;
    background: #f3f4f6;
    border: 1px solid transparent;
    border-radius: 12px;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sp-chip:hover {
    background: #e5efff;
    color: var(--primary);
}

.sp-chip.active {
    background: var(--primary);
    color: white;
}

.sticker-item {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 4px;
    cursor: pointer;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.sticker-item:hover {
    background: #e5efff;
    border-color: var(--primary);
    transform: scale(1.05);
}

.sticker-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Recalled messages */
.msg-wrapper.recalled .msg-bubble {
    background: #f3f4f6 !important;
    border: 1px dashed #d1d5db;
    color: var(--text-muted) !important;
    font-style: italic;
}

/* Sticker message bubbles (no background/padding) */
.msg-bubble-sticker {
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.msg-bubble-recalled-text {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

/* Hover recall actions */
.msg-wrapper {
    position: relative;
}

.msg-bubble .msg-actions-hover {
    display: flex;
    position: absolute;
    bottom: -10px;
    z-index: 10;
    flex-direction: row;
    gap: 4px;
    align-items: center;
    justify-content: center;
    min-width: auto;
    height: 32px;
    
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: scale(0.9);
}

/* Khi hover vào tin nhắn, hiện mờ nút hành động ở góc để định hướng */
.msg-bubble:hover .msg-actions-hover {
    opacity: 0.35;
    pointer-events: auto;
    transform: scale(1);
}

/* Khi di chuột trực tiếp vào vùng góc chứa nút, hiện rõ 100% */
.msg-bubble .msg-actions-hover:hover {
    opacity: 1 !important;
}

/* Định vị góc dưới bên trái cho tin self (bên phải màn hình) - nhô ra ngoài góc dưới trái */
.msg-wrapper.self .msg-bubble .msg-actions-hover {
    left: -10px;
    right: auto;
    bottom: -10px;
}

/* Định vị góc dưới bên phải cho tin peer (bên trái màn hình) - nhô ra ngoài góc dưới phải */
.msg-wrapper.peer .msg-bubble .msg-actions-hover {
    right: -10px;
    left: auto;
    bottom: -10px;
}

.btn-msg-action {
    background: #ffffff;
    border: 1px solid #dbdde2;
    color: var(--text-muted);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.btn-msg-action:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
    transform: scale(1.1);
}

/* Custom System Modals */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.custom-modal-overlay.show {
    opacity: 1;
}

.custom-modal-box {
    width: 90%;
    max-width: 450px;
    padding: 24px;
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid #dbdde2;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    transform: translateY(10px);
    transition: transform 0.2s ease;
    text-align: left;
}

.custom-modal-overlay.show .custom-modal-box {
    transform: translateY(0);
}

.custom-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.custom-modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}

.custom-modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
}

.custom-modal-close:hover {
    color: var(--text-main);
}

.custom-modal-body {
    font-size: 14px;
    color: var(--text-main);
    line-height: 1.5;
    margin-bottom: 24px;
}

.custom-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Style for Label Picker Modal */
.label-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    max-height: 150px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #f9fafb;
}

.label-chip-item {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 20px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    color: #4b5563;
}

.label-chip-item:hover {
    background: #e5e7eb;
    color: #1f2937;
}

.label-chip-item.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: none;
}

/* CRM Table overrides - flat light */
.crm-table {
    width: 100%;
    border-collapse: collapse;
}

.crm-table th {
    background: #f4f5f7;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid #dbdde2;
    padding: 10px 12px;
}

.crm-table td {
    padding: 12px;
    border-bottom: 1px solid #e5e7eb;
    color: var(--text-main);
}

.crm-table tr:hover {
    background: #f9fafb;
}

/* Sidebar toggle button (right panel) */
.toggle-right-sidebar-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.toggle-right-sidebar-btn:hover {
    color: var(--primary);
    background: #f0f4fa;
}

/* Unread message styles */
.conversation-item.unread .conv-name {
    font-weight: 600;
    color: #000000;
}

.unread-badge {
    box-shadow: 0 1px 3px rgba(239, 68, 68, 0.4);
}

/* Mobile & Tablet Responsive Layout */
@media (max-width: 768px) {
    #chat-tab {
        display: block; /* Switch from grid to block */
        position: relative;
        height: 100%;
        width: 100%;
    }

    /* Column 1: Zalo Sidebar Left (Nick List) */
    .zalo-sidebar-left {
        display: none !important; /* Hide left accounts bar on mobile */
    }

    /* Column 2: Conversations Sidebar */
    .chat-tab-sidebar {
        width: 100% !important;
        display: flex !important;
        height: 100%;
    }

    /* Column 3: Main Chat Box */
    .chat-box {
        display: none !important;
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100%;
        z-index: 10;
    }

    /* Column 4: Contact Details Sidebar */
    .contact-sidebar {
        display: none !important; /* Always hide contact sidebar on mobile to save space */
    }

    /* When a conversation is selected and active */
    #chat-tab.chat-active .chat-tab-sidebar {
        display: none !important; /* Hide conversations list */
    }

    #chat-tab.chat-active .chat-box {
        display: grid !important; /* Show chat box as grid */
    }

    /* Mobile Back Button */
    .mobile-back-btn {
        display: block !important; /* Show back button on mobile chat header */
    }
}

/* --- Message Reactions Styles --- */
.msg-reaction-container {
    position: relative;
    display: inline-block;
}

.msg-reaction-picker-menu {
    display: none;
    position: absolute;
    bottom: 28px;
    background: #ffffff;
    border: 1px solid #dbdde2;
    border-radius: 20px;
    padding: 6px 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 100;
    white-space: nowrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

/* Đối với tin self: picker mở rộng sang bên trái (hướng vào giữa màn hình) để tránh tràn lề phải */
.msg-wrapper.self .msg-reaction-picker-menu {
    right: 0;
    left: auto;
}

/* Đối với tin peer: picker mở rộng sang bên phải (hướng vào giữa màn hình) để tránh tràn lề trái */
.msg-wrapper.peer .msg-reaction-picker-menu {
    left: 0;
    right: auto;
}

.msg-reaction-picker-menu::before {
    content: "";
    position: absolute;
    bottom: -35px;
    left: -30px;
    right: -30px;
    height: 40px;
    background: transparent;
}

.msg-reaction-container:hover .msg-reaction-picker-menu {
    display: flex;
}

.react-emoji-btn {
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.12s ease;
    padding: 4px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.react-emoji-btn:hover {
    transform: scale(1.35);
    background: #f3f4f6;
}

/* Reaction Pill dưới chân bubble */
.msg-bubble {
    position: relative !important;
}

.msg-reaction-pill {
    position: absolute;
    bottom: -10px;
    background: #ffffff;
    border: 1px solid #dbdde2;
    border-radius: 12px;
    padding: 2px 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    cursor: pointer;
    user-select: none;
    z-index: 2;
    transition: all 0.15s ease;
}

.msg-reaction-pill:hover {
    background: #f3f5f8;
    transform: scale(1.05);
}

.msg-wrapper.self .msg-reaction-pill {
    left: 12px;
    right: auto;
}

.msg-wrapper.peer .msg-reaction-pill {
    right: 12px;
    left: auto;
}

.reaction-emojis {
    display: flex;
    gap: 1px;
}

.reaction-count {
    color: var(--text-muted);
    font-weight: 600;
}

/* Tránh đè lên tin tiếp theo */
.msg-wrapper.has-reactions {
    margin-bottom: 15px;
}

/* Modal chi tiết reaction */
.reaction-detail-modal-body {
    max-height: 250px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px;
}

.reaction-detail-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

.reaction-detail-user {
    display: flex;
    align-items: center;
    gap: 8px;
}

.reaction-detail-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #0068ff;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
}

.reaction-detail-name {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-main);
}

.reaction-detail-emoji {
    font-size: 18px;
}

/* Custom File Attachment Card */
.file-attachment-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px 14px;
    margin-top: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 320px;
    text-align: left;
}

.file-attachment-card:hover {
    background: #e5efff;
    border-color: var(--primary);
}

.file-icon-wrapper {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: rgba(0, 104, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.file-name {
    font-size: 13px;
    font-weight: 600;
    color: #1c1d21;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.file-action {
    font-size: 11px;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Image bubble customization */
.msg-bubble.msg-bubble-image {
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
}

.msg-bubble.msg-bubble-image img {
    margin-top: 0 !important;
    max-width: 280px !important;
    max-height: 200px !important;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Button size fixes */
.btn.btn-xs {
    width: auto;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    height: auto;
    line-height: normal;
}

/* Dedicated AI Spintax Button */
.btn-ai-spintax {
    width: auto;
    height: 24px;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    background: linear-gradient(to right, #3b82f6, #8b5cf6);
    border: none;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-ai-spintax:hover {
    opacity: 0.95;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(139, 92, 246, 0.2);
}

.btn-ai-spintax:active {
    transform: translateY(0);
}

/* Media Upload Zone & Drag Drop Styles */
.media-upload-zone {
    margin-top: 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.02);
}
.upload-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: border-color 0.3s ease, background 0.3s ease;
}
.upload-dropzone:hover, .upload-dropzone.dragover {
    border-color: var(--primary);
    background: rgba(0, 104, 255, 0.04);
}
.upload-text {
    font-size: 12px;
    color: var(--text-muted);
}
.upload-preview-container {
    margin-top: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.01);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.upload-preview-item {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px;
    display: flex;
    align-items: center;
    background: var(--bg-card);
    animation: fadeIn 0.2s ease-out;
}
.upload-preview-item img, .upload-preview-item video {
    width: 60px;
    height: 60px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}
.upload-preview-item .preview-info {
    flex: 1;
    margin-left: 12px;
    font-size: 12px;
    color: var(--text-main);
    word-break: break-all;
    min-width: 0;
}
.upload-preview-item .preview-remove {
    cursor: pointer;
    color: #ef4444;
    background: none;
    border: none;
    font-size: 18px;
    padding: 4px 10px;
    border-radius: 4px;
    margin-left: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}
.upload-preview-item .preview-remove:hover {
    background: rgba(239, 68, 68, 0.1);
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.crm-spinning {
    animation: spin 1s linear infinite;
    display: inline-block;
}

/* Switch Toggle CSS Mini for Sidebar AI status */
.switch-mini {
    position: relative;
    display: inline-block;
    width: 28px;
    height: 16px;
}
.switch-mini input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider-mini {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255,255,255,0.1);
    border: 1px solid var(--border-color);
    transition: .2s;
    border-radius: 8px;
}
.slider-mini:before {
    position: absolute;
    content: "";
    height: 10px;
    width: 10px;
    left: 2px;
    bottom: 2px;
    background-color: #aaa;
    transition: .2s;
    border-radius: 50%;
}
input:checked + .slider-mini {
    background-color: rgba(16, 185, 129, 0.2);
    border-color: rgba(16, 185, 129, 0.4);
}
input:checked + .slider-mini:before {
    transform: translateX(12px);
    background-color: #10b981;
}
input:checked + .slider-mini.paused {
    background-color: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.4);
}
input:checked + .slider-mini.paused:before {
    background-color: #f59e0b;
}

/* --- TOOLTIP & POPOVER FOR CAMPAIGN LOGS --- */
.status-badge {
    position: relative;
    cursor: help;
}

.status-tooltip {
    visibility: hidden;
    width: 320px;
    background: #0f172a; /* Slate 900 */
    color: #f8fafc;
    text-align: left;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 12px;
    position: absolute;
    z-index: 999;
    bottom: 125%;
    left: 50%;
    margin-left: -160px;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: translateY(8px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
    font-size: 0.75rem;
    line-height: 1.5;
    pointer-events: none;
    font-weight: normal;
}

.status-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: #0f172a transparent transparent transparent;
}

.status-badge:hover .status-tooltip {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

