/* ========================================
   ZALO CRM — Meta Flat Design System
   Clean UI · Dark/Light · Cobalt Accent
   ======================================== */

/* ===== CSS Variables — Dark Theme (Default) ===== */
:root {
    /* Colors — Dark (Meta Dark) */
    --bg-primary: #18191A;
    --bg-secondary: #242526;
    --bg-tertiary: #303133;
    --bg-elevated: #3A3B3C;
    --bg-hover: #303133;
    --bg-active: #3A3B3C;

    --text-primary: #E4E6EB;
    --text-secondary: #B0B3B8;
    --text-tertiary: #8A8D91;
    --text-muted: #606770;

    --accent: #2D88FF;
    --accent-hover: #1A7AFF;
    --accent-light: rgba(45, 136, 255, 0.1);
    --accent-glow: rgba(45, 136, 255, 0.2);

    --success: #31A24C;
    --warning: #F2A918;
    --error: #E41E3F;
    --info: #2D88FF;

    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.12);

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 8px;
    --radius-lg: 8px;
    --radius-xl: 16px;
    --radius-xxl: 24px;
    --radius-full: 100px;

    /* Flat Shadows — Dark */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 0 transparent;

    /* Legacy compat — no neumorphism, flat alternatives */
    --neu-shadow: var(--shadow-md);
    --neu-shadow-sm: var(--shadow-sm);
    --neu-shadow-inset: none;
    --neu-shadow-pressed: none;
    --neu-flat: none;

    /* Glass — simplified for compat */
    --glass-bg: rgba(36, 37, 38, 0.92);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-blur: blur(12px);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-smooth: 350ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Layout */
    --sidebar-width: 260px;
    --chatlist-width: 340px;
    --header-height: 60px;

    /* Message bubbles */
    --msg-outgoing-bg: #0064E0;
    --msg-outgoing-text: #FFFFFF;
    --msg-incoming-bg: #303133;
    --msg-incoming-text: #E4E6EB;

    /* Login */
    --login-bg: linear-gradient(135deg, #111213, #18191A, #0F1011);
    --login-card-bg: #242526;
    --login-card-border: rgba(255, 255, 255, 0.08);
}

/* ===== CSS Variables — Light Theme ===== */
[data-theme="light"] {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F6F7F9;
    --bg-tertiary: #F1F4F7;
    --bg-elevated: #FFFFFF;
    --bg-hover: #F1F4F7;
    --bg-active: #E4E6EB;

    --text-primary: #0A1317;
    --text-secondary: #444950;
    --text-tertiary: #5D6C7B;
    --text-muted: #8595A4;

    --accent: #0064E0;
    --accent-hover: #0457CB;
    --accent-light: rgba(0, 100, 224, 0.08);
    --accent-glow: rgba(0, 100, 224, 0.15);

    --success: #31A24C;
    --warning: #F2A918;
    --error: #E41E3F;
    --info: #0064E0;

    --border: #DEE3E9;
    --border-hover: #CED0D4;

    /* Flat Shadows — Light */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 0 transparent;

    --neu-shadow: var(--shadow-md);
    --neu-shadow-sm: var(--shadow-sm);
    --neu-shadow-inset: none;
    --neu-shadow-pressed: none;
    --neu-flat: none;

    --glass-bg: rgba(255, 255, 255, 0.95);
    --glass-border: #DEE3E9;

    --msg-outgoing-bg: #0064E0;
    --msg-outgoing-text: #FFFFFF;
    --msg-incoming-bg: #F1F4F7;
    --msg-incoming-text: #0A1317;

    --login-bg: linear-gradient(135deg, #E8EDF3, #F1F4F7, #DDE3EB);
    --login-card-bg: #FFFFFF;
    --login-card-border: #DEE3E9;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: -0.14px;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== LOGIN SCREEN ===== */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--login-bg);
    position: relative;
}

.login-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.login-card {
    background: var(--login-card-bg);
    border: 1px solid var(--login-card-border);
    border-radius: var(--radius-xxl);
    padding: 48px 40px;
    width: 400px;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: fadeInUp 0.6s ease;
}

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

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo svg { margin-bottom: 16px; }
.login-logo h1 {
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #5AB0FF);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.login-logo p { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }

.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    transition: border-color var(--transition-fast);
    outline: none;
    box-shadow: none;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

.error-text { color: var(--error); font-size: 13px; margin-top: 12px; text-align: center; min-height: 20px; }

/* ===== Buttons ===== */
.btn-primary {
    width: 100%;
    padding: 12px 20px;
    background: #0064E0;
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
    overflow: hidden;
    box-shadow: none;
}

.btn-primary:hover {
    background: #0457CB;
}

.btn-primary:active { background: #0352C1; }

.btn-secondary {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    box-shadow: none;
}

.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-hover); }
.btn-secondary:active { background: var(--bg-active); }

.btn-small {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast);
    box-shadow: none;
}

.btn-small:hover { background: var(--bg-hover); border-color: var(--border-hover); }
.btn-small:active { background: var(--bg-active); }

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    flex-shrink: 0;
    box-shadow: none;
}

.btn-icon:hover { background: var(--bg-hover); color: var(--accent); }
.btn-icon:active { background: var(--bg-active); }

/* ===== APP LAYOUT ===== */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) var(--chatlist-width) 1fr;
    height: 100vh;
    overflow: hidden;
}

.app.show-contact-panel {
    grid-template-columns: var(--sidebar-width) var(--chatlist-width) 1fr 320px;
}

.app.show-suggestions-panel {
    grid-template-columns: var(--sidebar-width) var(--chatlist-width) 1fr 340px;
}

.hidden { display: none !important; }

/* ===== SIDEBAR ===== */
.sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.logo-small {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
}

.sidebar-section {
    padding: 12px 12px 8px;
    border-bottom: 1px solid var(--border);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-tertiary);
}

.account-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.account-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.account-item:hover { background: var(--bg-hover); }
.account-item.active { background: var(--accent-light); }

.account-item .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.connected { background: var(--success); box-shadow: 0 0 4px rgba(49, 162, 76, 0.4); }
.status-dot.disconnected { background: var(--text-muted); }
.status-dot.error { background: var(--error); }

.account-item .account-name {
    font-size: 13px;
    font-weight: 500;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-item .account-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

/* Stats */
.stats-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
}

.stat-value { display: block; font-size: 20px; font-weight: 700; color: var(--accent); }
.stat-label { display: block; font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }

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

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

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    font-weight: 700;
    font-size: 13px;
    color: white;
    flex-shrink: 0;
}

.user-details { display: flex; flex-direction: column; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-tertiary); text-transform: capitalize; }

/* ===== CHAT LIST PANEL ===== */
.chat-list-panel {
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-tabs {
    display: flex;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    overflow-x: auto;
}

.main-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition-fast), background var(--transition-fast);
    border-bottom: 2px solid transparent;
}

.main-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.main-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: var(--accent-light);
}

#conversations-view,
#contacts-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.crm-panel-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
}

.panel-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-header h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    transition: border-color var(--transition-fast);
    margin-bottom: 10px;
}

.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }

.search-box svg { color: var(--text-muted); flex-shrink: 0; }

.search-box input {
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    width: 100%;
    outline: none;
    padding: 0;
    box-shadow: none;
}

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

.filter-tab {
    padding: 6px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
    box-shadow: none;
}

.filter-tab:hover { background: var(--bg-hover); border-color: var(--border-hover); }
.filter-tab.active { background: var(--accent); color: white; border-color: var(--accent); }

.filter-account-select {
    margin-left: auto;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 500;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
    padding-right: 20px;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238A8D91' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
}
.filter-account-select:hover { border-color: var(--accent); color: var(--text-primary); }
.filter-account-select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border);
}

.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.active { background: var(--accent-light); }

.conversation-item .contact-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    color: var(--text-secondary);
    flex-shrink: 0;
    position: relative;
    box-shadow: none;
}

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

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

.conversation-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.conversation-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.conversation-time {
    font-size: 11px;
    color: var(--text-muted);
}

.unread-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--accent);
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.account-label {
    font-size: 10px;
    color: var(--accent);
    font-weight: 500;
}

/* ===== CHAT DETAIL PANEL ===== */
.chat-detail-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

.chat-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    color: var(--text-muted);
}

.chat-placeholder h3 { font-size: 18px; font-weight: 600; color: var(--text-tertiary); }
.chat-placeholder p { font-size: 13px; }

.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    z-index: 2;
}

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

.chat-header-info h3 {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-account-label { font-size: 11px; color: var(--accent); }

.btn-back { display: none; }

.contact-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    color: var(--text-secondary);
    flex-shrink: 0;
    box-shadow: none;
}

.contact-avatar.large {
    width: 72px;
    height: 72px;
    font-size: 28px;
    margin: 16px auto;
    box-shadow: none;
}

/* Message List */
.message-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-bubble {
    max-width: 65%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 13px;
    line-height: 1.5;
    position: relative;
    animation: msgFadeIn 0.2s ease;
    word-wrap: break-word;
}

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

.message-incoming {
    align-self: flex-start;
    background: var(--msg-incoming-bg);
    border-bottom-left-radius: 4px;
    color: var(--msg-incoming-text);
    box-shadow: none;
}

.message-outgoing {
    align-self: flex-end;
    background: var(--msg-outgoing-bg);
    border-bottom-right-radius: 4px;
    color: var(--msg-outgoing-text);
    box-shadow: none;
}

/* Flat outgoing — same for both themes */
html:not([data-theme="light"]) .message-outgoing {
    background: #0064E0;
    color: white;
}

[data-theme="light"] .message-outgoing {
    background: #0064E0;
    color: white;
}

[data-theme="light"] .message-incoming {
    background: var(--msg-incoming-bg);
    color: var(--msg-incoming-text);
}

.message-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

.message-outgoing .message-time { color: rgba(255, 255, 255, 0.6); text-align: right; }
[data-theme="light"] .message-outgoing .message-time { color: rgba(255, 255, 255, 0.7); }

/* Group message — sender name */
.group-sender-name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 3px;
    line-height: 1.2;
}
.message-bubble.group-msg {
    margin-top: 2px;
}
.message-bubble.group-msg + .message-bubble.group-msg {
    margin-top: 1px;
}
.message-bubble.group-msg .group-sender-name:empty { display: none; }

/* System messages (thông báo hệ thống) */
.message-system {
    align-self: center;
    text-align: center;
    padding: 6px 16px;
    font-size: 12px;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    max-width: 80%;
    animation: msgFadeIn 0.2s ease;
}

/* Chat header group badge */
.chat-group-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-light);
    padding: 1px 6px;
    border-radius: 4px;
    margin-right: 4px;
    vertical-align: middle;
}

/* Group avatar in chat header */
.contact-avatar.group-avatar {
    font-size: 16px;
    line-height: 36px;
}

.message-date-divider {
    text-align: center;
    padding: 12px 0;
    font-size: 11px;
    color: var(--text-muted);
    position: relative;
}

.message-date-divider::before,
.message-date-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: var(--border);
}

.message-date-divider::before { left: 5%; }
.message-date-divider::after { right: 5%; }

.message-content-type {
    font-size: 12px;
    font-style: italic;
    opacity: 0.7;
}

/* ===== CONTACT PANEL ===== */
.contact-panel {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.contact-detail {
    padding: 20px;
}

.contact-detail h3 { text-align: center; font-size: 16px; margin-bottom: 4px; }
.contact-phone { display: block; text-align: center; color: var(--text-tertiary); font-size: 13px; margin-bottom: 20px; }

.contact-section {
    margin-bottom: 20px;
}

.contact-section label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    margin-bottom: 6px;
}

.contact-section textarea {
    min-height: 80px;
    resize: vertical;
}

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

.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--accent-light);
}

.tag .tag-remove {
    cursor: pointer;
    opacity: 0.6;
    font-size: 14px;
    line-height: 1;
}

.tag .tag-remove:hover { opacity: 1; }

.tag-input-row {
    display: flex;
    gap: 6px;
}

.tag-input-row input { flex: 1; padding: 6px 10px; font-size: 12px; }

/* ===== SUGGESTIONS PANEL ===== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
}

.stat-box .box-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.stat-box .box-label {
    display: block;
    font-size: 11px;
    color: var(--text-tertiary);
}

.quick-replies {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.quick-reply-btn {
    text-align: left;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
    box-shadow: none;
}

.quick-reply-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}

.unanswered-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-bottom: 8px;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.unanswered-item:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.unanswered-item .un-name {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.unanswered-item .un-msg {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
}

.unanswered-item .un-time {
    display: block;
    font-size: 11px;
    color: var(--text-tertiary);
    text-align: right;
}


/* ===== MODAL ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 560px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.3s ease;
}

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

.modal-header h2 { font-size: 18px; }

.modal-body { padding: 24px; }

.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.settings-section .hint { font-size: 12px; color: var(--text-tertiary); margin-bottom: 12px; }

.form-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.form-row input, .form-row select { flex: 1; padding: 8px 12px; font-size: 13px; }
.form-row .btn-primary { width: auto; padding: 8px 16px; font-size: 13px; white-space: nowrap; }

/* User list */
.user-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.user-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.user-item-info { font-size: 13px; }
.user-item-role { font-size: 11px; color: var(--text-tertiary); }

.btn-delete {
    padding: 4px 10px;
    background: transparent;
    border: 1px solid var(--error);
    color: var(--error);
    border-radius: var(--radius-sm);
    font-size: 11px;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-delete:hover { background: var(--error); color: white; }

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 3.7s;
    min-width: 260px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.info { border-left: 3px solid var(--info); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ===== EMPTY STATE ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px;
    color: var(--text-muted);
    text-align: center;
    gap: 8px;
}

.empty-state.small { padding: 12px; font-size: 12px; }
.empty-state p { font-size: 13px; }
.empty-state small { font-size: 11px; color: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .app { grid-template-columns: 1fr; }
    .sidebar, .contact-panel { display: none; }
    .btn-back { display: flex; }
}

/* ===== MESSAGE INPUT ===== */
.message-input-container {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.message-input-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 4px 4px 4px 16px;
    transition: border-color var(--transition-fast);
    box-shadow: none;
}

.message-input-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.message-input-box input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    padding: 8px 0;
    outline: none;
    box-shadow: none;
}

.message-input-box input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0064E0;
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition-fast);
    box-shadow: none;
}

.btn-send:hover {
    background: #0457CB;
}

.btn-send:active {
    background: #0352C1;
    transform: scale(0.97);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ===== INLINE MEDIA IN MESSAGES ===== */
.message-image {
    max-width: 280px;
    border-radius: 12px;
    margin: 4px 0;
    cursor: pointer;
    transition: opacity var(--transition-fast);
}

.message-image:hover {
    opacity: 0.9;
}

.message-sticker {
    width: 120px;
    height: 120px;
    object-fit: contain;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: background var(--transition-fast);
}

.message-file:hover {
    background: rgba(0, 0, 0, 0.25);
}

.message-file-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-size: 18px;
}

.message-file-name {
    font-size: 13px;
    font-weight: 500;
}

.message-file-size {
    font-size: 11px;
    opacity: 0.7;
}

.message-voice {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 160px;
}

.message-voice-icon {
    font-size: 20px;
}

.message-voice-bar {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}

.message-incoming .message-voice-bar {
    background: rgba(0, 0, 0, 0.1);
}

.message-video {
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-video-icon {
    font-size: 24px;
}

/* ===== Image lightbox ===== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    animation: fadeInUp 0.2s ease;
}

.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}

/* ===== SYNC SECTION ===== */
.sync-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.sync-section h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.sync-status {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: 8px;
    min-height: 18px;
}

.sync-status.syncing {
    color: var(--accent);
}

.sync-status.done {
    color: var(--success);
}

/* ===== NOTIFICATION ===== */
.notification-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    background: var(--error);
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    animation: pulse 2s infinite;
}

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

/* ===== Message states ===== */
.message-sending {
    opacity: 0.6;
}

.message-sent {
    opacity: 1;
}

/* ===== Main Tabs override (Hội thoại | Danh bạ) ===== */
.main-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
    z-index: 1;
}

.main-tab {
    flex: 1;
    padding: 12px 8px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: color 0.2s, background 0.2s;
}

.main-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.main-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: var(--accent-light);
}

.main-tab svg {
    width: 18px;
    height: 18px;
}

/* ===== Contacts List (Danh bạ) ===== */
.contacts-group-header {
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    background: var(--bg-primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.contacts-count {
    padding: 4px 16px 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.contact-item {
    transition: background 0.15s;
}

.contact-item:hover {
    background: var(--bg-hover);
}

/* ===== Image Attach Button ===== */
.btn-attach {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}

.btn-attach:hover {
    color: var(--accent);
    background: var(--accent-light);
}

/* ===== Image Preview ===== */
.image-preview-container {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-top: 8px;
    gap: 8px;
    border: 1px solid var(--border);
}

.image-preview-container img {
    max-height: 80px;
    max-width: 120px;
    border-radius: 6px;
    object-fit: cover;
}

.btn-remove-preview {
    background: var(--bg-hover);
    border: none;
    color: var(--error);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.btn-remove-preview:hover {
    background: rgba(228, 30, 63, 0.12);
}

/* ===== Sync Messages Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

.sync-modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 480px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

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

.sync-modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.sync-modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
}

.sync-modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sync-modal-body {
    padding: 24px;
}

#sync-progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 16px;
}

#sync-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.3s ease;
}

#sync-progress-text {
    color: var(--text-primary);
    font-size: 14px;
    margin: 0 0 8px;
}

.sync-detail {
    color: var(--text-secondary) !important;
    font-size: 12px;
}

/* Per-chat sync button */
.btn-sync-single {
    color: var(--text-secondary);
    transition: color 0.2s, background 0.2s;
}

.btn-sync-single:hover {
    color: var(--accent);
    background: var(--accent-light);
}

.btn-sync-single:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Sync spin animation */
.sync-spin {
    display: inline-block;
    animation: syncSpin 1s linear infinite;
}

@keyframes syncSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== Theme Toggle Button ===== */
.btn-theme-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s, background 0.3s;
    position: relative;
}

.btn-theme-toggle:hover {
    color: var(--accent);
    background: var(--accent-light);
}

.btn-theme-toggle svg {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-theme-toggle:hover svg {
    transform: rotate(30deg);
}

/* ===== Light Theme Overrides (minimal — vars handle most) ===== */
[data-theme="light"] .sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
}

[data-theme="light"] .chat-list-panel {
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
}

[data-theme="light"] .chat-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

[data-theme="light"] .contact-panel {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
}

[data-theme="light"] .conversation-item:hover {
    background: var(--bg-hover);
}

[data-theme="light"] .conversation-item.active {
    background: var(--accent-light);
}

[data-theme="light"] .contact-avatar {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

[data-theme="light"] .message-input-container {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

[data-theme="light"] .message-input-box {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}

[data-theme="light"] .message-input-box input {
    color: var(--text-primary);
}

[data-theme="light"] .settings-modal .modal-content {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

[data-theme="light"] .settings-modal .modal-content input,
[data-theme="light"] .settings-modal .modal-content select {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

[data-theme="light"] .login-card {
    background: var(--login-card-bg);
    border: 1px solid var(--login-card-border);
    box-shadow: var(--shadow-lg);
}

[data-theme="light"] .form-group input {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

[data-theme="light"] .form-group input::placeholder {
    color: var(--text-muted);
}

[data-theme="light"] .filter-tab {
    color: var(--text-secondary);
}

[data-theme="light"] .filter-tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

[data-theme="light"] .main-tabs {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

[data-theme="light"] .main-tab {
    color: var(--text-secondary);
}

[data-theme="light"] .main-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

[data-theme="light"] .toast {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}

[data-theme="light"] .modal-overlay {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
}

[data-theme="light"] .sync-modal-card {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

[data-theme="light"] .lightbox {
    background: rgba(0, 0, 0, 0.85);
}

/* ===== Smooth theme transition ===== */
html, html * {
    transition: background-color 0.3s ease, color 0.2s ease, border-color 0.3s ease;
}

/* Disable transition on messages to prevent animation stutter */
.message-bubble, .message-list {
    transition: none !important;
}

/* ===== SUGGESTIONS UI override ===== */
.quick-replies {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quick-reply-btn {
    text-align: left;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    box-shadow: none;
}

.quick-reply-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
    box-shadow: none;
}

.stat-box .box-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent);
    display: block;
    margin-bottom: 4px;
}

.stat-box .box-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.unanswered-item {
    margin: 4px 8px;
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    transition: background 0.2s, border-color 0.2s;
    box-shadow: none;
}
.unanswered-item:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}
.unanswered-item .un-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: block;
}
.unanswered-item .un-msg {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}
.unanswered-item .un-time {
    font-size: 0.75rem;
    color: var(--warning);
    margin-top: 4px;
    display: block;
}

/* ===== SYNC PROMPT overlay ===== */
.sync-prompt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: syncFadeIn 0.3s ease;
}

@keyframes syncFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes syncPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.08); opacity: 0.85; }
}

@keyframes syncPhoneRing {
    0%, 100% { transform: rotate(0deg); }
    10% { transform: rotate(12deg); }
    20% { transform: rotate(-12deg); }
    30% { transform: rotate(8deg); }
    40% { transform: rotate(-8deg); }
    50% { transform: rotate(0deg); }
}

@keyframes syncDots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

@keyframes syncCheckPop {
    0% { transform: scale(0) rotate(-45deg); opacity: 0; }
    60% { transform: scale(1.2) rotate(0deg); opacity: 1; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.sync-prompt-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 420px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    animation: syncSlideUp 0.4s ease;
    overflow: hidden;
}

.sync-prompt-header {
    background: linear-gradient(135deg, var(--accent), #1A7AFF);
    padding: 28px 24px 24px;
    text-align: center;
    position: relative;
}

.sync-prompt-header .sync-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 32px;
    border: 2px solid rgba(255, 255, 255, 0.25);
}

.sync-prompt-header h3 {
    color: #fff;
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0 0 6px;
}

.sync-prompt-header p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85rem;
    margin: 0;
    line-height: 1.5;
}

.sync-prompt-body {
    padding: 24px;
}

/* Steps indicator */
.sync-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.sync-step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    transition: all var(--transition-normal);
    opacity: 0.6;
}

.sync-step.active {
    opacity: 1;
    border-color: var(--accent);
    background: var(--accent-light);
}

.sync-step.done {
    opacity: 1;
    background: rgba(49, 162, 76, 0.08);
    border-color: rgba(49, 162, 76, 0.3);
}

.sync-step-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    transition: all var(--transition-normal);
}

.sync-step.active .sync-step-icon {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    animation: syncPulse 1.5s ease-in-out infinite;
}

.sync-step.done .sync-step-icon {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
    animation: syncCheckPop 0.5s ease forwards;
}

.sync-step-content h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 2px;
}

.sync-step-content p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.4;
}

.sync-step.active .sync-step-content h4 {
    color: var(--accent);
}

.sync-step.done .sync-step-content h4 {
    color: var(--success);
}

/* Phone waiting animation */
.sync-phone-waiting {
    text-align: center;
    padding: 20px 0;
}

.sync-phone-icon {
    font-size: 48px;
    animation: syncPhoneRing 1.5s ease-in-out infinite;
    display: inline-block;
    margin-bottom: 12px;
}

.sync-phone-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.sync-phone-text::after {
    animation: syncDots 1.5s steps(3, end) infinite;
    content: '';
}

/* Progress section */
.sync-prompt-progress {
    margin: 16px 0;
}

.sync-prompt-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: 8px;
}

.sync-prompt-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: var(--radius-full);
    transition: width 0.5s ease;
    width: 0%;
}

.sync-prompt-progress-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Buttons */
.sync-prompt-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.sync-prompt-btn {
    flex: 1;
    padding: 12px 20px;
    border-radius: var(--radius-full);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.sync-prompt-btn.primary {
    background: var(--accent);
    color: #fff;
}

.sync-prompt-btn.primary:hover {
    background: var(--accent-hover);
}

.sync-prompt-btn.primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.sync-prompt-btn.secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.sync-prompt-btn.secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

/* Compact sync status in sidebar */
.sync-prompt-mini {
    margin: 8px 12px;
    padding: 10px 14px;
    background: var(--accent-light);
    border: 1px solid rgba(45, 136, 255, 0.2);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
    color: var(--accent);
    font-weight: 600;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}

.sync-prompt-mini:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
}

.sync-prompt-mini .mini-icon {
    font-size: 20px;
}

/* Result summary */
.sync-result-summary {
    text-align: center;
    padding: 16px 0 8px;
}

.sync-result-summary .result-icon {
    font-size: 48px;
    margin-bottom: 12px;
    display: block;
}

.sync-result-summary h4 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--success);
    margin: 0 0 8px;
}

.sync-result-summary .result-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-top: 12px;
}

.sync-result-summary .stat-item {
    text-align: center;
}

.sync-result-summary .stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    display: block;
}

.sync-result-summary .stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ==========================================
   CRM COMPONENTS — Pipeline Kanban, AI Panel, Stats
   ========================================== */

/* === CRM Panel Views === */
.crm-panel-view {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.crm-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.crm-panel-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

/* CRM tabs styling */
.main-tab.crm-tab {
    font-size: 0.72rem;
    padding: 8px 6px;
}

/* === Kanban Board === */
.kanban-board {
    display: flex;
    gap: 10px;
    padding: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    flex: 1;
    min-height: 0;
}

.kanban-column {
    flex: 1;
    min-width: 170px;
    max-width: 240px;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.kanban-column-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
}

.kanban-count {
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    min-width: 20px;
    text-align: center;
}

.kanban-column-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 60px;
    transition: background var(--transition-fast);
}

.kanban-column-body.drag-over {
    background: var(--accent-light);
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
    border-radius: var(--radius-sm);
}

.kanban-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    cursor: grab;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: none;
}

.kanban-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
}

.kanban-card.dragging {
    opacity: 0.4;
    transform: rotate(2deg);
}

.kanban-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.kanban-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.kanban-card-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kanban-card-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kanban-card-time {
    font-size: 0.65rem;
    color: var(--text-tertiary);
}

.kanban-card-detail {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.kanban-card-preview {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.kanban-empty {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 16px 8px;
}

/* === Toggle Switch === */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch.small {
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    transition: background var(--transition-normal);
    border: 1px solid var(--border);
    box-shadow: none;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.toggle-switch.small .toggle-slider::before {
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
}

input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: none;
}

input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.toggle-switch.small input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

/* === AI Dashboard === */
.ai-dashboard {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-controls {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

.ai-toggle-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.ai-status {
    font-size: 0.82rem;
    font-weight: 700;
}

.ai-status.active {
    color: var(--success);
}

.ai-status.inactive {
    color: var(--text-muted);
}

.ai-model-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* AI Stats Grid */
.ai-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.ai-stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
}

.ai-stat-value {
    display: block;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.ai-stat-label {
    font-size: 0.68rem;
    color: var(--text-secondary);
}

/* AI Test */
.ai-test-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

.ai-test-section h4 {
    margin: 0 0 10px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary);
}

.ai-test-row {
    display: flex;
    gap: 8px;
}

.ai-test-row input {
    flex: 1;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.8rem;
    outline: none;
    box-shadow: none;
}

.ai-test-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.ai-test-result {
    margin-top: 10px;
    padding: 10px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    line-height: 1.5;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}

.ai-test-success {
    color: var(--text-primary);
}

.ai-test-success small {
    color: var(--text-tertiary);
    display: block;
    margin-top: 6px;
}

.ai-test-error {
    color: var(--error);
}

/* AI Logs */
.ai-logs-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

.ai-logs-section h4 {
    margin: 0 0 10px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary);
}

.ai-logs-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 280px;
    overflow-y: auto;
}

.ai-log-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    font-size: 0.75rem;
}

.ai-log-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.ai-log-contact {
    font-weight: 700;
    color: var(--accent);
}

.ai-log-time {
    color: var(--text-tertiary);
    font-size: 0.68rem;
}

.ai-log-tokens {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.65rem;
    background: var(--bg-elevated);
    padding: 1px 6px;
    border-radius: var(--radius-full);
}

.ai-log-user {
    color: var(--text-secondary);
    margin-bottom: 3px;
    line-height: 1.4;
}

.ai-log-ai {
    color: var(--success);
    line-height: 1.4;
}

/* === Stats Dashboard === */
.stats-dashboard {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stats-overview-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.overview-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    transition: border-color var(--transition-fast);
}

.overview-card:hover {
    border-color: var(--border-hover);
}

.overview-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.overview-info {
    display: flex;
    flex-direction: column;
}

.overview-value {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
}

.overview-label {
    font-size: 0.68rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Stats Section */
.stats-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

.stats-section h4 {
    margin: 0 0 12px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ===== Pipeline bars ===== */
.pipeline-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pipeline-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pipeline-bar-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    width: 80px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pipeline-bar-track {
    flex: 1;
    height: 20px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.pipeline-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 2px;
}

.pipeline-bar-count {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 24px;
    text-align: right;
}

/* Queue Status */
.queue-status {
    display: flex;
    gap: 16px;
    padding: 10px 0;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.queue-status strong {
    color: var(--text-primary);
}

/* ===== Contact CRM Controls (in right panel) ===== */
.contact-crm {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.contact-crm .contact-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.contact-crm label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.pipeline-select {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.78rem;
    cursor: pointer;
    outline: none;
    box-shadow: none;
    transition: border-color var(--transition-fast);
}

.pipeline-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

/* ===== Loading/Error states ===== */
.loading-spinner {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.loading-spinner.small {
    padding: 8px;
    font-size: 0.75rem;
}

.error-state {
    text-align: center;
    padding: 24px;
    color: var(--error);
    font-size: 0.82rem;
}

/* Btn small & secondary override */
.btn-small {
    padding: 6px 12px;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid var(--border);
    font-weight: 600;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    box-shadow: none;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: none;
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

/* ===== Knowledge Base ===== */
.knowledge-dashboard { display: flex; flex-direction: column; gap: 16px; padding: 12px; }
.knowledge-stats { display: flex; gap: 16px; font-size: 0.85rem; color: var(--text-secondary); }
.knowledge-upload, .knowledge-search, .knowledge-files { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; }
.knowledge-upload h4, .knowledge-search h4, .knowledge-files h4 { margin: 0 0 8px 0; font-size: 0.85rem; color: var(--text-primary); }
.upload-row { display: flex; gap: 8px; align-items: center; }
.upload-row input[type="file"] { flex: 1; font-size: 0.8rem; color: var(--text-secondary); }
.knowledge-file-list { display: flex; flex-direction: column; gap: 6px; }
.knowledge-file-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.8rem; }
.knowledge-file-name { flex: 1; color: var(--text-primary); }
.knowledge-file-chunks { color: var(--text-tertiary); font-size: 0.75rem; }
.knowledge-result-item { padding: 8px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 6px; }
.knowledge-result-item strong { color: var(--text-primary); font-size: 0.8rem; }
.knowledge-result-item p { color: var(--text-secondary); font-size: 0.75rem; margin: 4px 0 0; }

/* ===== Follow-up ===== */
.followup-dashboard { display: flex; flex-direction: column; gap: 16px; padding: 12px; }
.followup-list-section { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; }
.followup-list-section h4 { margin: 0 0 8px 0; font-size: 0.85rem; color: var(--text-primary); }
.followup-list { display: flex; flex-direction: column; gap: 8px; }
.followup-item { padding: 8px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm); display: flex; flex-direction: column; gap: 4px; }
.followup-info { display: flex; gap: 12px; align-items: center; font-size: 0.8rem; }
.followup-contact { color: var(--text-primary); font-weight: 600; }
.followup-step { color: var(--accent); font-size: 0.75rem; }
.followup-time { color: var(--text-tertiary); font-size: 0.75rem; }
.followup-preview { color: var(--text-secondary); font-size: 0.75rem; }

/* ===== Branch ===== */
.branch-dashboard { display: flex; flex-direction: column; gap: 16px; padding: 12px; }
.branch-add-form, .branch-list-section { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; }
.branch-add-form h4, .branch-list-section h4 { margin: 0 0 8px 0; font-size: 0.85rem; color: var(--text-primary); }
.branch-form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.branch-form-row input { flex: 1; min-width: 120px; padding: 6px 10px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 0.8rem; box-shadow: none; }
.branch-list { display: flex; flex-direction: column; gap: 6px; }
.branch-item { padding: 8px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.branch-info { display: flex; flex-direction: column; gap: 2px; }
.branch-name { color: var(--text-primary); font-weight: 600; font-size: 0.85rem; }
.branch-address, .branch-phone { color: var(--text-secondary); font-size: 0.75rem; }

/* ===== Lead Info Form ===== */
.lead-info-form { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.lead-field { display: flex; flex-direction: column; gap: 3px; }
.lead-field label { font-size: 0.7rem; color: var(--text-tertiary); text-transform: uppercase; font-weight: 600; }
.lead-field input, .lead-field select { padding: 6px 10px; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 0.8rem; box-shadow: none; }
.lead-field input:focus, .lead-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); outline: none; }

/* ===== Utility classes ===== */
.btn-danger { background: var(--error); color: white; border: none; cursor: pointer; border-radius: var(--radius-sm); font-size: 0.7rem; padding: 4px 8px; }
.btn-danger:hover { background: #C4193A; }
.btn-tiny { padding: 2px 6px; font-size: 0.65rem; }
