/* ============================================================
   Meta WhatsApp CRM — Main Stylesheet
   Dark premium admin theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ============================================================
   CSS Variables
   ============================================================ */
:root {
    --sidebar-width: 260px;
    --sidebar-bg: #0d1117;
    --sidebar-border: #21262d;
    --topbar-height: 64px;
    --topbar-bg: #161b22;
    --body-bg: #0d1117;
    --card-bg: #161b22;
    --card-border: #21262d;
    --text-primary: #e6edf3;
    --text-muted: #8b949e;
    --accent-green: #25d366;
    --accent-blue: #2f81f7;
    --accent-purple: #a371f7;
    --accent-orange: #f0883e;
    --accent-red: #f85149;
    --input-bg: #0d1117;
    --input-border: #30363d;
    --nav-hover: rgba(255,255,255,0.05);
    --nav-active: rgba(47,129,247,0.1);
    --nav-active-border: var(--accent-blue);
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 8px 32px rgba(0,0,0,0.4);
    --transition: all 0.2s ease;

    /* User Theme Variables Fallbacks for Admin Panel */
    --user-primary:    #6366f1;
    --user-primary-dk: #4f46e5;
    --user-accent:     #22d3ee;
    --user-bg:         #0d1117;
    --user-surface:    #161b22;
    --user-surface2:   #0d1117;
    --user-border:     #21262d;
    --user-text:       #e6edf3;
    --user-muted:      #8b949e;
    --user-success:    #25d366;
    --user-warning:    #f0883e;
    --user-danger:     #f85149;
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    background: var(--body-bg);
    color: var(--text-primary);
    margin: 0;
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { color: #5b9ffa; }
h1,h2,h3,h4,h5,h6 { font-weight: 600; }
code { color: var(--accent-green); background: rgba(37,211,102,0.1); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }

/* ============================================================
   App Layout
   ============================================================ */
.app-body {
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: var(--transition);
    overflow-y: auto;
}

/* Sidebar Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: transparent;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    flex-shrink: 0;
}

.brand-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    display: block;
    line-height: 1.2;
}

.brand-sub {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
}

/* Sidebar Nav */
.sidebar-nav {
    list-style: none;
    padding: 12px 0;
    margin: 0;
    flex: 1;
}

.nav-section-label {
    padding: 16px 20px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.sidebar-nav .nav-item .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: var(--transition);
    margin: 1px 0;
}

.sidebar-nav .nav-item .nav-link i {
    font-size: 16px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav .nav-item .nav-link:hover {
    color: var(--text-primary);
    background: var(--nav-hover);
    border-left-color: var(--sidebar-border);
}

.sidebar-nav .nav-item.active .nav-link {
    color: var(--accent-blue);
    background: var(--nav-active);
    border-left-color: var(--nav-active-border);
}

/* Sidebar Footer */
.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

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

.user-avatar {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

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

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

.btn-logout {
    color: var(--text-muted);
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    flex-shrink: 0;
}
.btn-logout:hover { color: var(--accent-red); background: rgba(248,81,73,0.1); }

/* ============================================================
   MAIN WRAPPER
   ============================================================ */
.main-wrapper {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100% - var(--sidebar-width));
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: var(--transition);
    box-sizing: border-box;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
    position: sticky;
    top: 0;
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    z-index: 900;
}

.sidebar-toggle {
    background: none;
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: var(--transition);
}
.sidebar-toggle:hover { color: var(--text-primary); border-color: var(--accent-blue); }

.topbar-title { flex: 1; }
.page-title { font-size: 18px; font-weight: 700; margin: 0; }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.topbar-btn {
    background: none;
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
}
.topbar-btn:hover { color: var(--text-primary); border-color: var(--accent-blue); }

.notification-dot {
    position: absolute;
    top: 6px; right: 6px;
    width: 8px; height: 8px;
    background: var(--accent-red);
    border-radius: 50%;
    border: 1px solid var(--topbar-bg);
}

.topbar-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
}
.topbar-user-btn:hover { border-color: var(--accent-blue); }

.user-avatar-sm {
    width: 26px; height: 26px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
}

/* Dropdowns */
.dropdown-menu {
    background: var(--card-bg) !important;
    border: 1px solid var(--card-border) !important;
    box-shadow: var(--shadow) !important;
}
.dropdown-item { color: var(--text-primary) !important; font-size: 13px; }
.dropdown-item:hover { background: var(--nav-hover) !important; }
.dropdown-header { color: var(--text-muted) !important; font-size: 11px; }
.dropdown-divider { border-color: var(--sidebar-border) !important; }

.notification-dropdown { min-width: 250px; }

/* ============================================================
   PAGE CONTENT
   ============================================================ */
.page-content {
    flex: 1;
    padding: 24px;
}

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
    padding: 12px 24px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--card-bg) !important;
    border: 1px solid var(--card-border) !important;
    border-radius: var(--radius) !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.card-header {
    background: transparent !important;
    border-bottom: 1px solid var(--card-border) !important;
    padding: 14px 20px !important;
}

.card-title { font-size: 14px !important; font-weight: 600 !important; }

.card-body { padding: 20px !important; }

.card-footer {
    background: transparent !important;
    border-top: 1px solid var(--card-border) !important;
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 4px; height: 100%;
}
.stat-card-green::after { background: var(--accent-green); }
.stat-card-blue::after  { background: var(--accent-blue);  }
.stat-card-purple::after{ background: var(--accent-purple);}
.stat-card-orange::after{ background: var(--accent-orange);}

.stat-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}
.stat-card-green .stat-icon { background: rgba(37,211,102,0.12); color: var(--accent-green); }
.stat-card-blue  .stat-icon { background: rgba(47,129,247,0.12);  color: var(--accent-blue);  }
.stat-card-purple .stat-icon{ background: rgba(163,113,247,0.12); color: var(--accent-purple); }
.stat-card-orange .stat-icon{ background: rgba(240,136,62,0.12);  color: var(--accent-orange); }

.stat-content { flex: 1; }
.stat-value { font-size: 28px; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-trend { font-size: 11px; color: var(--text-muted); }

/* Mini stats */
.stat-mini {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    text-align: center;
}
.stat-mini-value { font-size: 24px; font-weight: 800; }
.stat-mini-label { font-size: 11px; color: var(--text-muted); }
.stat-mini-blue  .stat-mini-value { color: var(--accent-blue); }
.stat-mini-green .stat-mini-value { color: var(--accent-green); }
.stat-mini-yellow .stat-mini-value{ color: var(--accent-orange); }
.stat-mini-red   .stat-mini-value { color: var(--accent-red); }

/* ============================================================
   TABLES
   ============================================================ */
.table {
    color: var(--text-primary) !important;
    --bs-table-bg: transparent !important;
    --bs-table-hover-bg: rgba(255,255,255,0.03) !important;
}
.table thead th {
    background: rgba(255,255,255,0.03) !important;
    border-bottom: 1px solid var(--card-border) !important;
    color: var(--text-muted) !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 16px !important;
}
.table td {
    border-bottom: 1px solid var(--card-border) !important;
    padding: 12px 16px !important;
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none !important; }

/* ============================================================
   FORMS
   ============================================================ */
.form-control, .form-select {
    background: var(--input-bg) !important;
    border: 1px solid var(--input-border) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent-blue) !important;
    box-shadow: 0 0 0 3px rgba(47,129,247,0.15) !important;
}
.form-control::placeholder { color: var(--text-muted) !important; }
.form-label { color: var(--text-primary); font-weight: 500; margin-bottom: 6px; }
.form-text  { color: var(--text-muted) !important; }

.input-group-text {
    background: var(--input-bg) !important;
    border: 1px solid var(--input-border) !important;
    color: var(--text-muted) !important;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary   { background: var(--accent-blue)   !important; border-color: var(--accent-blue)   !important; }
.btn-success   { background: var(--accent-green)  !important; border-color: var(--accent-green)  !important; }

.btn-outline-primary  { color: var(--accent-blue)  !important; border-color: var(--accent-blue)  !important; }
.btn-outline-success  { color: var(--accent-green) !important; border-color: var(--accent-green) !important; }
.btn-outline-danger   { color: var(--accent-red)   !important; border-color: var(--accent-red)   !important; }
.btn-outline-info     { color: #58a6ff !important; border-color: #58a6ff !important; }
.btn-outline-warning  { color: var(--accent-orange) !important; border-color: var(--accent-orange) !important; }
.btn-outline-secondary{ color: var(--text-muted) !important; border-color: var(--input-border) !important; }

.btn-outline-primary:hover  { background: var(--accent-blue)   !important; color: white !important; }
.btn-outline-success:hover  { background: var(--accent-green)  !important; color: white !important; }
.btn-outline-danger:hover   { background: var(--accent-red)    !important; color: white !important; }
.btn-outline-secondary:hover{ background: var(--nav-hover) !important; color: var(--text-primary) !important; }
.btn-outline-info:hover     { background: #58a6ff !important; color: white !important; }

.btn-action {
    text-align: left;
    padding: 10px 14px;
    font-size: 13px;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    border: 1px solid !important;
    border-radius: var(--radius-sm) !important;
}
.alert-success { background: rgba(37,211,102,0.1) !important; border-color: rgba(37,211,102,0.3) !important; color: #56d364 !important; }
.alert-danger  { background: rgba(248,81,73,0.1)  !important; border-color: rgba(248,81,73,0.3)  !important; color: #f85149 !important; }
.alert-warning { background: rgba(240,136,62,0.1) !important; border-color: rgba(240,136,62,0.3) !important; color: #f0883e !important; }
.alert-info    { background: rgba(47,129,247,0.1)  !important; border-color: rgba(47,129,247,0.3)  !important; color: #58a6ff !important; }
.alert-dark    { background: rgba(255,255,255,0.04)!important; border-color: var(--card-border)    !important; color: var(--text-muted) !important; }
.alert .alert-link { text-decoration: underline; }

/* ============================================================
   BADGES
   ============================================================ */
.badge { font-size: 11px !important; font-weight: 600 !important; letter-spacing: 0.3px; }
.bg-success-subtle { background: rgba(37,211,102,0.12) !important; }
.bg-primary-subtle { background: rgba(47,129,247,0.12) !important; }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body {
    background: radial-gradient(ellipse at 20% 50%, rgba(47,129,247,0.08) 0%, transparent 60%),
                radial-gradient(ellipse at 80% 50%, rgba(37,211,102,0.06) 0%, transparent 60%),
                #0d1117;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.auth-container { position: relative; width: 100%; max-width: 440px; padding: 20px; z-index: 1; }

.auth-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}

.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-brand-icon {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, #25d366, #128c7e);
    border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; color: white;
    margin: 0 auto 16px;
    box-shadow: 0 8px 24px rgba(37,211,102,0.3);
}
.auth-brand-name { font-size: 24px; font-weight: 800; margin-bottom: 4px; }
.auth-brand-sub  { color: var(--text-muted); font-size: 13px; margin: 0; }

.input-group-auth .input-group-text { background: var(--input-bg); border: 1px solid var(--input-border); color: var(--text-muted); }
.btn-pw-toggle { cursor: pointer; }

.btn-auth {
    height: 44px;
    font-weight: 600;
    font-size: 14px;
    background: linear-gradient(135deg, var(--accent-blue), #3d5fdb) !important;
    border: none !important;
    box-shadow: 0 4px 16px rgba(47,129,247,0.3);
    transition: all 0.2s;
}
.btn-auth:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(47,129,247,0.4) !important; }

.auth-footer { text-align: center; margin-top: 24px; }

/* Background orbs */
.auth-bg-decoration { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.auth-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    animation: floatOrb 8s ease-in-out infinite;
}
.auth-orb-1 { width: 300px; height: 300px; background: rgba(47,129,247,0.08); top: 10%; left: 5%; }
.auth-orb-2 { width: 200px; height: 200px; background: rgba(37,211,102,0.06); top: 60%; right: 10%; animation-delay: -3s; }
.auth-orb-3 { width: 150px; height: 150px; background: rgba(163,113,247,0.06); bottom: 10%; left: 40%; animation-delay: -6s; }

@keyframes floatOrb {
    0%,100% { transform: translateY(0) scale(1); }
    50%      { transform: translateY(-20px) scale(1.05); }
}

/* ============================================================
   ACCOUNT CARDS
   ============================================================ */
.account-card { transition: transform 0.2s; }
.account-card:hover { transform: translateY(-2px); }
.account-card-active { border-left: 4px solid var(--accent-green) !important; }
.account-card-disconnected { border-left: 4px solid var(--text-muted) !important; opacity: 0.7; }
.account-card-pending { border-left: 4px solid var(--accent-orange) !important; }

.account-avatar {
    width: 48px; height: 48px;
    background: linear-gradient(135deg, #25d366, #128c7e);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; color: white;
}

.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.status-dot-active { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }

.detail-item { }
.detail-label { font-size: 11px; color: var(--text-muted); display: block; }
.detail-value { font-size: 13px; display: block; }

/* ============================================================
   MESSAGES / CONVERSATION
   ============================================================ */
.messages-layout {
    display: flex;
    height: calc(100vh - var(--topbar-height) - 80px);
    gap: 16px;
    min-height: 500px;
}

.conversations-sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.conv-contact-info { text-align: center; padding: 8px 0; }
.conv-avatar {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 700; color: white;
    flex-shrink: 0;
}
.conv-avatar-lg { width: 56px; height: 56px; font-size: 24px; margin: 0 auto; }

.conversations-list { flex: 1; overflow-y: auto; }

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--sidebar-border);
    transition: var(--transition);
    color: var(--text-primary);
    text-decoration: none;
}
.conversation-item:hover { background: var(--nav-hover); color: var(--text-primary); }

.conv-details { flex: 1; overflow: hidden; }
.conv-name { font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.conv-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-muted); }
.conv-unread {
    background: var(--accent-green);
    color: white;
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
}

/* Chat panel */
.chat-panel {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.conversation-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
}

.chat-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message-bubble {
    display: flex;
    width: 100%;
    margin-bottom: 14px;
}
.message-out { justify-content: flex-end; }
.message-in  { justify-content: flex-start; }

.message-content {
    max-width: 65%;
    padding: 10px 16px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.message-out .message-content {
    background: linear-gradient(135deg, var(--user-primary, var(--accent-blue, #2f81f7)), var(--user-primary-dk, #0b5ed7));
    color: white;
    border-radius: 16px 16px 4px 16px;
}
.message-in .message-content {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    border-radius: 16px 16px 16px 4px;
}

.message-text { font-size: 14px; line-height: 1.5; }
.message-template { font-style: normal; opacity: 1; }
.message-media { font-size: 13px; opacity: 0.9; }

.message-template-bubble .message-content {
    background: linear-gradient(135deg, #6366f1, #a855f7) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.template-badge {
    display: inline-flex;
    align-items: center;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

/* Chat Tab styling overrides */
#chatTabs .nav-link {
    color: rgba(255, 255, 255, 0.5) !important;
    transition: all 0.2s ease-in-out;
    border-radius: 0;
    margin-right: 8px;
    border-bottom: 2px solid transparent !important;
}
#chatTabs .nav-link:hover {
    color: rgba(255, 255, 255, 0.8) !important;
    background: transparent !important;
}
#chatTabs .nav-link.active {
    color: var(--user-primary, var(--bs-primary)) !important;
    background: transparent !important;
    border-bottom: 2px solid var(--user-primary, var(--bs-primary)) !important;
    font-weight: 600 !important;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
}
.message-time { font-size: 10px; opacity: 0.7; }
.message-status { font-size: 12px; }

.chat-input-area {
    padding: 16px;
    border-top: 1px solid var(--card-border);
    flex-shrink: 0;
}

.chat-textarea {
    resize: none;
    max-height: 100px;
}

.btn-send {
    width: 44px; height: 44px;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    flex-shrink: 0;
    font-size: 16px;
}

/* ============================================================
   ACTIVITY FEED
   ============================================================ */
.activity-feed { list-style: none; padding: 0; margin: 0; }
.activity-item {
    display: flex;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--card-border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
    width: 32px; height: 32px;
    background: var(--nav-hover);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    flex-shrink: 0;
}
.activity-content { flex: 1; }
.activity-text { font-size: 13px; line-height: 1.4; }
.activity-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ============================================================
   FLOW STEPS (Connect Page)
   ============================================================ */
.flow-steps { display: flex; flex-direction: column; gap: 0; }
.flow-step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 12px 0;
    border-left: 2px solid var(--card-border);
    margin-left: 16px;
    padding-left: 20px;
    position: relative;
}
.flow-step-num {
    position: absolute;
    left: -12px;
    width: 22px; height: 22px;
    background: var(--accent-blue);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: white;
    flex-shrink: 0;
}
.flow-step-num-success { background: var(--accent-green); }
.flow-step-last { border-left-color: transparent; }
.flow-step-content strong { font-size: 13px; display: block; margin-bottom: 2px; }

/* ============================================================
   WHATSAPP CONNECT
   ============================================================ */
.wa-connect-wrapper { }
.wa-connect-icon {
    width: 80px; height: 80px;
    background: linear-gradient(135deg, #25d366, #128c7e);
    border-radius: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 40px; color: white;
    margin: 0 auto;
    box-shadow: 0 12px 32px rgba(37,211,102,0.3);
}
.btn-wa-connect {
    background: linear-gradient(135deg, #1877f2, #3b5998) !important;
    border: none !important;
    color: white !important;
    padding: 14px 32px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(24,119,242,0.4);
    transition: all 0.2s;
}
.btn-wa-connect:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(24,119,242,0.5) !important; }
.btn-wa-connect:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   TEMPLATE PREVIEW
   ============================================================ */
.template-preview-box {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* ============================================================
   LOG VIEWER
   ============================================================ */
.log-raw-payload {
    background: #0d1117;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 12px;
    color: var(--text-muted);
    max-height: 350px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============================================================
   DATATABLE OVERRIDES
   ============================================================ */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    background: var(--input-bg) !important;
    border: 1px solid var(--input-border) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
}
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate { color: var(--text-muted) !important; margin-top: 12px; }
.dataTables_wrapper .paginate_button { color: var(--text-muted) !important; border-radius: 6px !important; }
.dataTables_wrapper .paginate_button.current { background: var(--accent-blue) !important; color: white !important; border-color: var(--accent-blue) !important; }
.dataTables_wrapper .paginate_button:hover { background: var(--nav-hover) !important; color: var(--text-primary) !important; }

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   SETTINGS TAB
   ============================================================ */
.list-group-item {
    background: transparent !important;
    border: none !important;
    border-left: 2px solid transparent !important;
    color: var(--text-muted) !important;
    padding: 10px 16px !important;
    font-size: 13px;
    border-radius: 0 !important;
    transition: var(--transition);
}
.list-group-item.active, .list-group-item:hover {
    background: var(--nav-hover) !important;
    color: var(--text-primary) !important;
    border-left-color: var(--accent-blue) !important;
}
.list-group-item.active { color: var(--accent-blue) !important; }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination .page-link {
    background: var(--card-bg) !important;
    border-color: var(--card-border) !important;
    color: var(--text-muted) !important;
}
.pagination .page-item.active .page-link {
    background: var(--accent-blue) !important;
    border-color: var(--accent-blue) !important;
    color: white !important;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-content {
    background: var(--card-bg) !important;
    border: 1px solid var(--card-border) !important;
    border-radius: var(--radius) !important;
}
.modal-header { border-bottom: 1px solid var(--card-border) !important; }
.modal-footer { border-top:   1px solid var(--card-border) !important; }

/* ============================================================
   RESPONSIVE & UNIVERSAL MOBILE SUITE
   ============================================================ */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Universal Table Auto-Scroll */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Responsive Cards & Forms */
.form-control, .form-select, .input-group {
    max-width: 100%;
}

/* Custom smooth thin scrollbar for Mock Phone preview */
.phone-chat-scroll::-webkit-scrollbar {
    width: 5px;
}
.phone-chat-scroll::-webkit-scrollbar-track {
    background: transparent;
}
.phone-chat-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}
.phone-chat-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

.modal-dialog {
    margin: 10px auto;
    max-width: calc(100% - 20px);
}
@media (min-width: 576px) {
    .modal-dialog { max-width: 500px; }
    .modal-dialog.modal-lg { max-width: 800px; }
    .modal-dialog.modal-xl { max-width: 1140px; }
}

/* Adapt layout when screen is between 992px and 1440px (Common 125% & 150% Windows Display Scale) */
@media (min-width: 992px) and (max-width: 1440px) {
    :root {
        --sidebar-width: 220px !important;
        --sidebar-w: 220px !important;
    }
    .main-wrapper, .user-main {
        margin-left: 220px !important;
        width: calc(100% - 220px) !important;
    }
    .sidebar, .user-sidebar {
        width: 220px !important;
    }
    .page-content, .user-content {
        padding: 16px !important;
    }
    .stat-value {
        font-size: 20px !important;
    }
}

/* Ensure DataTables & Table containers scroll smoothly without page overflow */
.dataTables_wrapper, .table-responsive {
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}
.dataTables_wrapper .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Prevent Topbar Dropdown Menu Clipping on 150% Scale */
.dropdown-menu {
    z-index: 1060 !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4) !important;
}

.dropdown-menu-end {
    right: 0 !important;
    left: auto !important;
    max-width: calc(100vw - 20px) !important;
}

@media (max-width: 768px) {
    .sidebar, .user-sidebar { transform: translateX(-100%); }
    .sidebar.open, .user-sidebar.open { transform: translateX(0); }
    .main-wrapper, .user-main { margin-left: 0 !important; width: 100% !important; }
    .page-content, .user-content { padding: 12px !important; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 20px; }
    
    .user-topbar, .topbar {
        padding: 0 12px !important;
        gap: 6px !important;
    }
    .topbar-title {
        font-size: 14px !important;
    }

    /* Live Chat Mobile Stack & Toggle */
    .messages-layout {
        flex-direction: column;
        height: calc(100vh - 70px) !important;
        margin-bottom: 0 !important;
    }
    .conversations-sidebar {
        width: 100% !important;
        max-height: 100% !important;
        flex: 1;
    }
    .conversation-empty { display: none; }
}

@media (max-width: 576px) {
    .card-header, .card-body, .card-footer {
        padding: 12px !important;
    }
    .btn-sm {
        padding: 4px 8px;
        font-size: 11px;
    }
}

/* Custom Template Card & Active Conversation Styles */
.tpl-card-item .card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25) !important;
    border-color: var(--user-primary, var(--bs-primary)) !important;
}
.conversation-item.active {
    background: rgba(99, 102, 241, 0.1) !important;
    border-left: 3px solid var(--user-primary, var(--bs-primary)) !important;
}

/* ============================================================
   LIGHT MODE THEME OVERRIDES (Smooth, Soothing & Eye-Friendly)
   ============================================================ */
[data-bs-theme="light"] {
    --sidebar-bg: #ffffff;
    --sidebar-border: #e2e8f0;
    --topbar-bg: #ffffff;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --card-border: #e2e8f0;
    --text-primary: #0f172a;
    --text-muted: #475569;
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --nav-hover: rgba(15, 23, 42, 0.04);
    --nav-active: rgba(99, 102, 241, 0.12);
    --nav-active-border: var(--user-primary, #6366f1);
    --shadow: 0 4px 20px rgba(15, 23, 42, 0.05);

    /* User Theme Variables Light Mode Fallbacks */
    --user-bg:         #f1f5f9;
    --user-surface:    #ffffff;
    --user-surface2:   #f8fafc;
    --user-border:     #e2e8f0;
    --user-text:       #0f172a;
    --user-muted:      #475569;
    --user-success:    #10b981;
    --user-warning:    #f59e0b;
    --user-danger:     #ef4444;
}

/* Base Body & Layout in Light Mode */
[data-bs-theme="light"] body,
[data-bs-theme="light"] body.user-body {
    background-color: #f1f5f9 !important;
    color: #0f172a !important;
}

/* Cards & Modals */
[data-bs-theme="light"] .card, 
[data-bs-theme="light"] .modal-content,
[data-bs-theme="light"] .bg-dark-card {
    background-color: #ffffff !important;
    color: #0f172a !important;
    border-color: #e2e8f0 !important;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.04) !important;
}

/* Form Controls */
[data-bs-theme="light"] .form-control, 
[data-bs-theme="light"] .form-select,
[data-bs-theme="light"] .input-group-text {
    background-color: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

[data-bs-theme="light"] .form-control:focus, 
[data-bs-theme="light"] .form-select:focus {
    border-color: #6366f1 !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
}

[data-bs-theme="light"] .form-control::placeholder {
    color: #94a3b8 !important;
}

/* Tables */
[data-bs-theme="light"] .table {
    --bs-table-color: #0f172a !important;
    --bs-table-bg: #ffffff !important;
    --bs-table-border-color: #e2e8f0 !important;
    --bs-table-hover-bg: #f8fafc !important;
}

[data-bs-theme="light"] .table thead th {
    background-color: #f8fafc !important;
    color: #475569 !important;
    border-bottom: 1px solid #cbd5e1 !important;
}

[data-bs-theme="light"] .table-dark {
    --bs-table-color: #0f172a !important;
    --bs-table-bg: #f8fafc !important;
}

/* Text Colors Fix (Prevent Font Color Mixing) */
[data-bs-theme="light"] .text-body-secondary,
[data-bs-theme="light"] .text-secondary {
    color: #475569 !important;
}

[data-bs-theme="light"] .text-muted {
    color: #64748b !important;
}

/* Contextual Heading & Text Fixes */
[data-bs-theme="light"] .text-light:not(.btn *):not(.badge *):not(.btn):not(.badge):not(.avatar *):not(.wallet-badge *),
[data-bs-theme="light"] h1.text-white,
[data-bs-theme="light"] h2.text-white,
[data-bs-theme="light"] h3.text-white,
[data-bs-theme="light"] h4.text-white,
[data-bs-theme="light"] h5.text-white,
[data-bs-theme="light"] h6.text-white,
[data-bs-theme="light"] div.text-white:not(.btn *):not(.badge *):not(.btn):not(.badge):not(.avatar *):not(.wallet-badge *),
[data-bs-theme="light"] p.text-white,
[data-bs-theme="light"] span.text-white:not(.badge):not(.btn *):not(.badge *):not(.avatar *):not(.wallet-badge *) {
    color: #0f172a !important;
}

/* PRESERVE HIGH-CONTRAST WHITE FONT ON BUTTONS & BADGES */
[data-bs-theme="light"] .btn-primary,
[data-bs-theme="light"] .btn-success,
[data-bs-theme="light"] .btn-danger,
[data-bs-theme="light"] .btn-info,
[data-bs-theme="light"] .btn-dark,
[data-bs-theme="light"] .badge.bg-primary,
[data-bs-theme="light"] .badge.bg-success,
[data-bs-theme="light"] .badge.bg-danger,
[data-bs-theme="light"] .badge.bg-info,
[data-bs-theme="light"] .badge.bg-dark,
[data-bs-theme="light"] .avatar-gradient-contact,
[data-bs-theme="light"] .wallet-badge {
    color: #ffffff !important;
}

[data-bs-theme="light"] .btn-primary *,
[data-bs-theme="light"] .btn-success *,
[data-bs-theme="light"] .btn-danger *,
[data-bs-theme="light"] .btn-info *,
[data-bs-theme="light"] .badge.bg-primary *,
[data-bs-theme="light"] .badge.bg-success *,
[data-bs-theme="light"] .badge.bg-danger *,
[data-bs-theme="light"] .avatar-gradient-contact *,
[data-bs-theme="light"] .wallet-badge * {
    color: inherit !important;
}

/* Background Utility Overrides */
[data-bs-theme="light"] .bg-dark,
[data-bs-theme="light"] .bg-body-tertiary {
    background-color: #f8fafc !important;
}

[data-bs-theme="light"] .border-secondary {
    border-color: #cbd5e1 !important;
}

[data-bs-theme="light"] .topbar-btn i {
    color: #475569 !important;
}
