@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,300;0,14..32,400;0,14..32,500;0,14..32,600;0,14..32,700&display=swap');

/* ── Apple Design System Tokens ─────────────────────────────────────────── */
:root {
    /* Backgrounds */
    --bg-primary:   #F2F2F7;
    --bg-secondary: #FFFFFF;
    --bg-card:      #FFFFFF;
    --surface:      #FFFFFF;
    --surface-alt:  #F2F2F7;
    --surface-elevated: rgba(255, 255, 255, 0.82);

    /* Separators — ultra-thin */
    --border-color: rgba(60, 60, 67, 0.18);
    --border-hover: rgba(60, 60, 67, 0.36);

    /* Text hierarchy (iOS HIG) */
    --text-primary:   #000000;
    --text-secondary: rgba(60, 60, 67, 0.75);
    --text-muted:     #8E8E93;
    --text-quaternary: #C7C7CC;

    /* Accent — Apple Blue */
    --accent:          #007AFF;
    --accent-glow:     rgba(0, 122, 255, 0.13);
    --accent-gradient: #007AFF;

    /* Semantic */
    --success:      #34C759;
    --success-glow: rgba(52, 199, 89, 0.15);
    --warning:      #FF9500;
    --danger:       #FF3B30;

    /* Chat bubbles */
    --bubble-out:     #007AFF;
    --bubble-in-bg:   #E9E9EB;
    --bubble-in-text: #000000;

    /* Sidebar */
    --sidebar-width: 248px;
    --sidebar-bg:    rgba(246, 246, 248, 0.82);
    --sidebar-border: rgba(60, 60, 67, 0.18);

    /* Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows (light-mode) */
    --shadow-sm:    0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:    0 4px 12px rgba(0,0,0,0.09), 0 1px 3px rgba(0,0,0,0.05);
    --shadow-lg:    0 8px 24px rgba(0,0,0,0.11), 0 2px 6px rgba(0,0,0,0.06);
    --shadow-modal: 0 20px 60px rgba(0,0,0,0.18);

    --transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Dark Mode ───────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary:   #000000;
        --bg-secondary: #1C1C1E;
        --bg-card:      #1C1C1E;
        --surface:      #1C1C1E;
        --surface-alt:  #2C2C2E;
        --surface-elevated: rgba(44, 44, 46, 0.82);

        --border-color: rgba(84, 84, 88, 0.50);
        --border-hover: rgba(84, 84, 88, 0.80);

        --text-primary:    #FFFFFF;
        --text-secondary:  rgba(235, 235, 245, 0.60);
        --text-muted:      #8E8E93;
        --text-quaternary: #48484A;

        --bubble-in-bg:   #3A3A3C;
        --bubble-in-text: #FFFFFF;

        --sidebar-bg:     rgba(28, 28, 30, 0.85);
        --sidebar-border: rgba(84, 84, 88, 0.50);

        --shadow-sm:    0 1px 3px rgba(0,0,0,0.30);
        --shadow-md:    0 4px 12px rgba(0,0,0,0.40);
        --shadow-lg:    0 8px 24px rgba(0,0,0,0.50);
        --shadow-modal: 0 20px 60px rgba(0,0,0,0.65);
    }
}

:root[data-theme="dark"] {
    --bg-primary:   #000000;
    --bg-secondary: #1C1C1E;
    --bg-card:      #1C1C1E;
    --surface:      #1C1C1E;
    --surface-alt:  #2C2C2E;
    --surface-elevated: rgba(44, 44, 46, 0.82);
    --border-color: rgba(84, 84, 88, 0.50);
    --border-hover: rgba(84, 84, 88, 0.80);
    --text-primary:    #FFFFFF;
    --text-secondary:  rgba(235, 235, 245, 0.60);
    --text-muted:      #8E8E93;
    --text-quaternary: #48484A;
    --bubble-in-bg:   #3A3A3C;
    --bubble-in-text: #FFFFFF;
    --sidebar-bg:     rgba(28, 28, 30, 0.85);
    --sidebar-border: rgba(84, 84, 88, 0.50);
    --shadow-sm:    0 1px 3px rgba(0,0,0,0.30);
    --shadow-md:    0 4px 12px rgba(0,0,0,0.40);
    --shadow-lg:    0 8px 24px rgba(0,0,0,0.50);
    --shadow-modal: 0 20px 60px rgba(0,0,0,0.65);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow: hidden;
    font-size: 15px;
    line-height: 1.47059;
    font-weight: 400;
    letter-spacing: -0.01em;
}

/* ── Thin Apple Scrollbars ───────────────────────────────────────────────── */
::-webkit-scrollbar          { width: 5px; height: 5px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: rgba(60,60,67,0.22); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(60,60,67,0.38); }

/* ── App Shell ───────────────────────────────────────────────────────────── */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
}

/* ── Sidebar — frosted glass ─────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    backdrop-filter: blur(24px) saturate(200%);
    -webkit-backdrop-filter: blur(24px) saturate(200%);
    border-right: 0.5px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100%;
}

.sidebar-header {
    padding: 20px 16px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.40);
    flex-shrink: 0;
}

.logo-text {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    letter-spacing: -0.4px;
}

.sidebar-menu {
    list-style: none;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex-grow: 1;
    overflow-y: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
    -webkit-user-select: none;
    user-select: none;
}

.menu-item:hover {
    color: var(--text-primary);
    background: rgba(60, 60, 67, 0.06);
}

.menu-item.active {
    color: var(--accent);
    background: rgba(0, 122, 255, 0.10);
    font-weight: 600;
}

.menu-item i { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
    padding: 12px 16px 18px;
    border-top: 0.5px solid var(--border-color);
    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;
    font-weight: 600;
    font-size: 0.75rem;
    color: white;
    flex-shrink: 0;
}

.user-info  { display: flex; flex-direction: column; gap: 1px; }
.user-name  { font-size: 0.875rem; font-weight: 600; }
.user-role  { font-size: 0.72rem; color: var(--text-muted); }

/* ── Main Content ────────────────────────────────────────────────────────── */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
}

.top-bar {
    height: 56px;
    border-bottom: 0.5px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    background: var(--surface-elevated);
    backdrop-filter: blur(24px) saturate(200%);
    -webkit-backdrop-filter: blur(24px) saturate(200%);
    z-index: 10;
    flex-shrink: 0;
}

.page-title { font-size: 1rem; font-weight: 600; letter-spacing: -0.2px; }

.status-badge-container { display: flex; gap: 8px; align-items: center; }

.status-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.77rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(118, 118, 128, 0.10);
    color: var(--text-muted);
}

.status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--success);
}
.status-dot.connecting { background: var(--warning); }

/* ── Content Views ───────────────────────────────────────────────────────── */
.content-view {
    padding: 22px;
    flex-grow: 1;
    overflow-y: auto;
    display: none;
}

.content-view.active {
    display: block;
    animation: appleIn 0.18s ease-out;
}

#crm.content-view.active {
    display: flex !important;
    flex-direction: column;
}

#chat.content-view.active {
    display: flex !important;
    flex-direction: column;
    height: calc(100vh - 56px);
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden;
    flex: 1 1 100% !important;
}

#chat .chat-hub {
    display: flex !important;
    height: 100% !important;
    width: 100% !important;
    flex: 1 1 100% !important;
    border-radius: 0 !important;
    border: none !important;
    margin: 0 !important;
    overflow: hidden;
}

/* ── Sidebar collapsed / fullscreen ─────────────────────────────────────── */
.app-container.sidebar-collapsed .sidebar {
    width: 0 !important; min-width: 0 !important;
    overflow: hidden !important; padding: 0 !important;
    border-right: none !important; display: none !important;
}

.app-container.fullscreen-mode .sidebar,
.app-container.fullscreen-mode .top-bar { display: none !important; }

.app-container.fullscreen-mode .main-content {
    width: 100vw !important; height: 100vh !important;
    padding: 0 !important; margin: 0 !important;
}

.app-container.fullscreen-mode .content-view.active {
    height: 100vh !important; width: 100vw !important;
    max-height: 100vh !important; padding: 0 !important; margin: 0 !important;
}

.app-container.fullscreen-mode #chat.content-view.active,
.app-container.fullscreen-mode #chat .chat-hub {
    height: 100vh !important; width: 100vw !important;
}

.chat-profile-panel.hidden { display: none !important; }

@keyframes appleIn {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: none; }
}

/* ── Stats Grid ──────────────────────────────────────────────────────────── */
.grid-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.card-stat {
    background: var(--surface);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.card-stat:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-info { display: flex; flex-direction: column; gap: 3px; }
.stat-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; letter-spacing: 0.1px; }
.stat-value { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.5px; color: var(--text-primary); }

.stat-icon {
    width: 42px; height: 42px;
    border-radius: 11px;
    background: rgba(0, 122, 255, 0.10);
    display: flex; align-items: center; justify-content: center;
    color: var(--accent);
}

/* ── Charts Grid ─────────────────────────────────────────────────────────── */
.grid-charts {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 14px;
    margin-bottom: 20px;
}

@media (max-width: 1024px) { .grid-charts { grid-template-columns: 1fr; } }

.chart-panel {
    background: var(--surface);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 320px;
}

.chart-header { display: flex; justify-content: space-between; align-items: center; }
.chart-title { font-size: 0.925rem; font-weight: 600; }
.chart-wrapper { position: relative; flex-grow: 1; }

/* ── Channel Cards ───────────────────────────────────────────────────────── */
.grid-channels {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.channel-card {
    background: var(--surface);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: var(--transition);
}

.channel-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.channel-card-header { display: flex; justify-content: space-between; align-items: center; }
.channel-info-meta { display: flex; align-items: center; gap: 12px; }

.channel-logo {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: white; font-size: 0.8rem;
}

.zalo-color    { background: #0068FF; }
.zalo-oa-color { background: linear-gradient(135deg, #0056cc 0%, #0099ff 100%); }
.fb-color      { background: #1877F2; }
.tele-color    { background: #24A1DE; }
.wa-color      { background: #25D366; }

.channel-name    { font-weight: 600; font-size: 0.925rem; }
.channel-details { font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; }

.channel-badge {
    font-size: 0.72rem; font-weight: 600;
    padding: 3px 9px; border-radius: 20px;
}
.channel-badge.connected    { background: rgba(52,199,89,0.12);  color: #34C759; }
.channel-badge.disconnected { background: rgba(255,59,48,0.12);  color: #FF3B30; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    -webkit-user-select: none;
    user-select: none;
    letter-spacing: -0.1px;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 1px 4px rgba(0, 122, 255, 0.32);
}

.btn-primary:hover  { background: #0066DD; box-shadow: 0 2px 8px rgba(0,122,255,0.40); }
.btn-primary:active { background: #005CC4; transform: scale(0.98); }

.btn-secondary {
    background: rgba(118, 118, 128, 0.12);
    color: var(--text-primary);
}

.btn-secondary:hover  { background: rgba(118,118,128,0.20); }
.btn-secondary:active { transform: scale(0.98); }

/* ── QR Modal — frosted sheet ────────────────────────────────────────────── */
.qr-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.38);
    backdrop-filter: blur(14px) saturate(180%);
    -webkit-backdrop-filter: blur(14px) saturate(180%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.qr-modal.active { opacity: 1; pointer-events: auto; }

.qr-container {
    background: var(--surface);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 26px;
    width: 360px;
    max-width: 90%;
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
    transform: translateY(10px) scale(0.97);
    transition: transform 0.3s cubic-bezier(0.34, 1.36, 0.64, 1), opacity 0.22s ease;
}

.qr-modal.active .qr-container { transform: none; }

.qr-box {
    width: 100%;
    max-width: 280px;
    min-height: 220px;
    height: auto;
    background: transparent;
    padding: 0;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    box-shadow: none;
}

/* ── Dropzone ────────────────────────────────────────────────────────────── */
.dropzone {
    border: 1.5px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 34px;
    text-align: center;
    cursor: pointer;
    background: rgba(118,118,128,0.04);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.dropzone:hover { border-color: var(--accent); background: rgba(0,122,255,0.04); }
.dropzone i { font-size: 2rem; color: var(--accent); }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-container {
    background: var(--surface);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow-y: auto;
    max-height: 800px;
    margin-top: 14px;
}

table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.875rem; }

th {
    background: var(--surface-alt) !important;
    padding: 11px 14px;
    font-weight: 600;
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 0.5px solid var(--border-color);
    position: sticky; top: 0; z-index: 10;
}

td {
    padding: 12px 14px;
    border-bottom: 0.5px solid var(--border-color);
    color: var(--text-primary);
}

tr:last-child td { border-bottom: none; }
tr:hover td     { background: rgba(0,122,255,0.025); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.campaign-layout {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 18px;
}

@media (max-width: 900px) { .campaign-layout { grid-template-columns: 1fr; } }

.form-group  { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

.form-group label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.2px;
}

.form-control, select, textarea {
    background: rgba(118,118,128,0.10);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
    -webkit-appearance: none;
}

.form-control:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    background: rgba(118,118,128,0.06);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}

select {
    color-scheme: light !important;
    background-color: #ffffff !important;
    color: #111827 !important;
    padding: 10px 12px;
}

select option { background: #ffffff !important; color: #111827 !important; }

.variables-helper { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.var-tag {
    font-size: 0.72rem;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(0,122,255,0.08);
    color: var(--accent);
    cursor: pointer;
    border: 0.5px solid rgba(0,122,255,0.18);
    font-weight: 500;
    transition: var(--transition);
}

.var-tag:hover { background: rgba(0,122,255,0.14); }

/* ── Log Panel ───────────────────────────────────────────────────────────── */
.log-panel {
    background: #060609;
    border: 0.5px solid rgba(255,255,255,0.07);
    border-radius: var(--radius-md);
    padding: 14px;
    font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
    font-size: 0.78rem;
    height: 230px;
    overflow-y: auto;
    color: #A7F3D0;
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.log-entry           { border-bottom: 0.5px solid rgba(255,255,255,0.03); padding-bottom: 2px; }
.log-entry.success   { color: #34C759; }
.log-entry.error     { color: #FF3B30; }
.log-entry.info      { color: #64AFFF; }

/* ── Progress Bar ────────────────────────────────────────────────────────── */
.progress-container { margin-top: 12px; }

.progress-bar-bg {
    width: 100%; height: 4px;
    background: rgba(118,118,128,0.18);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    border-radius: 4px;
    transition: width 0.35s ease;
}

/* ── Chat Hub ────────────────────────────────────────────────────────────── */
.chat-hub {
    display: grid;
    grid-template-columns: 296px 1fr 286px;
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--surface);
    height: calc(100vh - 120px);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

@media (max-width: 1200px) {
    .chat-hub { grid-template-columns: 276px 1fr; }
    .chat-profile-panel { display: none; }
}

/* ── Chat Sidebar ────────────────────────────────────────────────────────── */
.chat-sidebar {
    border-right: 0.5px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--surface-alt);
}

.chat-search {
    padding: 10px 12px 8px;
    border-bottom: 0.5px solid var(--border-color);
}

.chat-filters {
    display: flex;
    gap: 5px;
    padding: 8px 12px;
    border-bottom: 0.5px solid var(--border-color);
    background: var(--surface-alt);
    overflow-x: auto;
    flex-shrink: 0;
}

.chat-filter-btn {
    padding: 5px 12px;
    font-size: 0.77rem;
    font-weight: 500;
    border-radius: 20px;
    background: rgba(118,118,128,0.12);
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: var(--transition);
}

.chat-filter-btn.active {
    background: var(--accent);
    color: white;
}

.chat-users-list { flex-grow: 1; overflow-y: auto; list-style: none; }

.chat-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 0.5px solid var(--border-color);
    cursor: pointer;
    transition: background 0.12s ease;
}

.chat-user-item:hover { background: rgba(118,118,128,0.06); }

.chat-user-item.active {
    background: rgba(0,122,255,0.08);
    border-left: 2.5px solid var(--accent);
}

.chat-user-meta { flex-grow: 1; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.chat-user-name-row { display: flex; justify-content: space-between; align-items: center; }
.chat-user-name { font-weight: 600; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-user-time { font-size: 0.70rem; color: var(--text-muted); flex-shrink: 0; }
.chat-user-last-msg { font-size: 0.77rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Chat Main area ──────────────────────────────────────────────────────── */
.chat-main {
    display: flex;
    flex-direction: column;
    flex: 1 1 0% !important;
    flex-grow: 1 !important;
    min-width: 0;
    height: 100%;
    background: var(--surface);
    border-right: 0.5px solid var(--border-color);
}

.chat-header {
    padding: 11px 18px;
    border-bottom: 0.5px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-elevated);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    min-height: 52px;
    flex-shrink: 0;
}

/* ── Chat Body ───────────────────────────────────────────────────────────── */
.chat-body {
    flex-grow: 1;
    padding: 14px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bg-primary);
}

/* ── iMessage-style Bubbles ──────────────────────────────────────────────── */
.message-bubble {
    max-width: 65%;
    padding: 9px 13px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.5;
    position: relative;
    word-break: break-word;
}

.message-bubble.incoming {
    align-self: flex-start;
    background: var(--bubble-in-bg);
    color: var(--bubble-in-text);
    border-bottom-left-radius: 5px;
    border-top-left-radius: 5px;
}

.message-bubble.outgoing {
    align-self: flex-end;
    background: var(--bubble-out);
    color: white;
    border-bottom-right-radius: 5px;
    border-top-right-radius: 5px;
}

.message-meta {
    font-size: 0.67rem;
    opacity: 0.52;
    display: block;
    text-align: right;
    margin-top: 2px;
}

/* ── Chat Toolbar ────────────────────────────────────────────────────────── */
.chat-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-top: 0.5px solid var(--border-color);
    background: var(--surface);
    flex-shrink: 0;
}

.toolbar-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.toolbar-btn:hover {
    color: var(--accent);
    background: rgba(0,122,255,0.08);
}

/* ── Chat Footer ─────────────────────────────────────────────────────────── */
.chat-footer {
    padding: 10px 14px 14px;
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--surface);
    border-top: 0.5px solid var(--border-color);
    flex-shrink: 0;
}

.chat-input-wrapper { flex-grow: 1; position: relative; }

.chat-input {
    width: 100%;
    background: rgba(118,118,128,0.12);
    border: none;
    border-radius: 22px;
    padding: 9px 16px;
    color: var(--text-primary);
    outline: none;
    font-size: 0.9rem;
    transition: var(--transition);
}

.chat-input::placeholder { color: var(--text-muted); }

.chat-input:focus {
    background: rgba(118,118,128,0.16);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}

/* ── Chat Profile Panel ──────────────────────────────────────────────────── */
.chat-profile-panel {
    background: var(--surface-alt);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    padding: 18px 14px;
    gap: 18px;
}

.profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
    padding-bottom: 16px;
    border-bottom: 0.5px solid var(--border-color);
}

.profile-avatar {
    width: 68px; height: 68px;
    border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.55rem; font-weight: 700;
    color: white;
    box-shadow: 0 3px 10px rgba(0,122,255,0.32);
}

.profile-name { font-size: 0.975rem; font-weight: 600; }

/* iOS-style grouped list */
.profile-details-list {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 0.5px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    gap: 0;
}

.profile-detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    border-bottom: 0.5px solid var(--border-color);
}

.profile-detail-item:last-child { border-bottom: none; }

.detail-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 500;
}

.detail-value { font-size: 0.875rem; font-weight: 500; color: var(--text-primary); }

.profile-tags-section { display: flex; flex-direction: column; gap: 8px; }
.profile-tags-list    { display: flex; flex-wrap: wrap; gap: 5px; }

.profile-tag {
    font-size: 0.72rem; font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(118,118,128,0.12);
    color: var(--text-muted);
}

.profile-tag.primary {
    background: rgba(0,122,255,0.10);
    color: var(--accent);
}

/* ── Quick Replies ───────────────────────────────────────────────────────── */
.quick-replies-menu {
    position: absolute;
    bottom: 70px; left: 14px;
    width: 290px;
    background: var(--surface);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    display: none;
    overflow: hidden;
}

.quick-replies-menu.active { display: block; animation: appleIn 0.15s ease-out; }

.quick-reply-item {
    padding: 11px 14px;
    border-bottom: 0.5px solid var(--border-color);
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--transition);
}

.quick-reply-item:last-child { border-bottom: none; }
.quick-reply-item:hover { background: rgba(0,122,255,0.06); color: var(--accent); }

/* ── Pane Resizer ────────────────────────────────────────────────────────── */
.pane-resizer { background: var(--border-color) !important; position: relative; }
.pane-resizer:hover, .pane-resizer.active { background: var(--accent) !important; width: 3px !important; }

/* ── Profile Input Wrapper ───────────────────────────────────────────────── */
.profile-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(118,118,128,0.10);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    margin-bottom: 8px;
    color: var(--text-muted);
    transition: var(--transition);
}

.profile-input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.10);
}

.profile-input-wrapper i { width: 15px; height: 15px; opacity: 0.55; flex-shrink: 0; }

.profile-input-wrapper input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    width: 100%;
    outline: none;
}

.profile-note-item {
    background: rgba(118,118,128,0.07);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
    font-size: 0.82rem;
}

.profile-note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.70rem;
    color: var(--text-muted);
    margin-bottom: 5px;
    border-bottom: 0.5px solid var(--border-color);
    padding-bottom: 4px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Connected Accounts ──────────────────────────────────────────────────── */
.connected-accounts-list {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 140px;
    overflow-y: auto;
    padding-top: 8px;
    border-top: 0.5px solid var(--border-color);
}

.mini-account-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(118,118,128,0.08);
    border: 0.5px solid var(--border-color);
    font-size: 0.77rem;
    transition: var(--transition);
}

.mini-account-card:hover { background: rgba(118,118,128,0.14); }
.mini-account-info { display: flex; align-items: center; gap: 8px; min-width: 0; }

.mini-account-avatar {
    width: 22px; height: 22px;
    border-radius: 50%; object-fit: cover;
    border: 0.5px solid var(--border-color);
}

.mini-account-name {
    font-weight: 600; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px;
}

.mini-account-type {
    font-size: 0.62rem; color: var(--text-muted);
    background: rgba(118,118,128,0.12);
    padding: 2px 6px; border-radius: 4px;
    text-transform: uppercase; font-weight: 500;
}

/* ── Custom Channel Dropdown ─────────────────────────────────────────────── */
.custom-channel-dropdown-wrapper { position: relative; display: inline-block; }

.custom-channel-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 0.5px solid var(--border-color);
    background: rgba(118,118,128,0.10);
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    max-width: 145px;
    outline: none;
    transition: var(--transition);
}

.custom-channel-btn:hover { border-color: var(--accent); background: rgba(0,122,255,0.06); }
.custom-channel-btn img { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }

.custom-channel-menu {
    position: absolute;
    top: calc(100% + 4px); left: 0;
    width: 240px; max-height: 300px;
    overflow-y: auto;
    background: var(--surface);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    display: none;
    padding: 4px 0;
}

.custom-channel-menu.show { display: block; animation: appleIn 0.14s ease-out; }

.custom-dropdown-group-label {
    padding: 6px 12px;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.custom-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.12s ease;
}

.custom-dropdown-item:hover { background: rgba(0,122,255,0.06); }

.custom-dropdown-avatar { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.custom-dropdown-icon   { font-size: 1rem; width: 22px; text-align: center; }
.custom-dropdown-name   { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── Antigravity AI Engine Styles ─────────────────────────────────────────── */
.ai-pill-btn {
    background: rgba(168, 85, 247, 0.08);
    border: 1px solid rgba(168, 85, 247, 0.25);
    color: #e9d5ff;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.ai-pill-btn:hover {
    background: rgba(168, 85, 247, 0.2);
    border-color: rgba(168, 85, 247, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.2);
}

.ai-msg-bubble {
    animation: fadeInBubble 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInBubble {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Mobile & Tablet Responsive Optimization ────────────────────────────── */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: -280px;
        width: 260px;
        z-index: 10000;
        box-shadow: 4px 0 25px rgba(0, 0, 0, 0.6);
        transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    
    .sidebar.mobile-open {
        left: 0;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .top-bar {
        padding: 10px 14px;
    }

    .page-title {
        font-size: 1.1rem !important;
    }

    #ai-assistant {
        height: calc(100dvh - 65px) !important;
        padding: 10px 12px !important;
    }

    .ai-msg-bubble {
        max-width: 95% !important;
    }

    .chat-profile-panel {
        display: none !important;
    }

    .chat-sidebar {
        width: 100% !important;
    }
}

