:root {
    /* Main Theme */
    --primary: #25d366;
    --primary-dark: #075e54;
    --primary-light: #dcf8c6;
    --secondary: #34b7f1;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #111b21;
    --text-muted: #667781;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --border: #e9edef;
    
    /* Layout Constants */
    --sidebar-width: 260px;
    --navbar-height: 64px;
    
    /* Visuals */
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 5px 0 rgba(11,20,26,.08), 0 2px 10px 0 rgba(11,20,26,.12);

    /* Backward compatibility aliases */
    --primary-color: var(--primary);
    --primary-dark-color: var(--primary-dark);
    --secondary-color: var(--secondary);
    --danger-color: var(--danger);
    --success-color: var(--success);
    --warning-color: var(--warning);
    --text-main: var(--text);
    --bg-color: var(--bg);
    --border-color: var(--border);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Layout Core */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Modernized */
.sidebar {
    width: var(--sidebar-width);
    background: #0b141a; /* Darker WhatsApp theme */
    color: #d1d7db;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    z-index: 1000;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 10px rgba(0,0,0,0.1);
    border-right: 1px solid rgba(255,255,255,0.05);
}

.sidebar.collapsed {
    width: 80px;
}

.sidebar-header {
    height: var(--navbar-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary);
    font-weight: 800;
    font-size: 1.25rem;
    white-space: nowrap;
    transition: opacity 0.2s;
}

.sidebar.collapsed .brand-text {
    display: none;
}

.sidebar-toggle-btn {
    background: transparent;
    border: none;
    color: #c1c8cd;;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.sidebar-toggle-btn:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.nav-category {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #667781;
    padding: 24px 20px 8px 24px;
    font-weight: 800;
    letter-spacing: 1.5px;
    white-space: nowrap;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.nav-category:hover {
    color: #d1d7db;
}

.category-chevron {
    transition: transform 0.3s ease;
    opacity: 0.5;
}

.nav-section.collapsed .category-chevron {
    transform: rotate(-90deg);
}

.nav-list {
    list-style: none;
    overflow: hidden;
    max-height: 500px; /* Large enough to fit any section */
    transition: max-height 0.3s cubic-bezier(0, 1, 0, 1);
}

.nav-section.collapsed .nav-list {
    max-height: 0;
    transition: max-height 0.3s cubic-bezier(1, 0, 1, 0);
}

.sidebar.collapsed .category-chevron {
    display: none;
}

.sidebar.collapsed .nav-category {
    justify-content: center;
    padding: 24px 0 8px 0;
}

.sidebar.collapsed .nav-list {
    max-height: none; /* Don't collapse individual lists when sidebar is collapsed */
}

.sidebar.collapsed .nav-section.collapsed .nav-list {
    max-height: 0; /* Keep them collapsed if they were manually collapsed */
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 24px;
    color: #d1d7db;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.2s;
    position: relative;
    border-left: 4px solid transparent;
}

.nav-link:hover {
    background: rgba(255,255,255,0.05);
    color: white;
}

.nav-link.active {
    background: rgba(37, 211, 102, 0.1);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

.nav-link svg {
    min-width: 20px;
    opacity: 0.8;
    transition: 0.2s;
}

.nav-link:hover svg, .nav-link.active svg {
    opacity: 1;
    transform: scale(1.1);
}

.sidebar.collapsed .link-text {
    display: none;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 15px 0;
    border-left-width: 4px;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    background: rgba(0,0,0,0.2);
    border-top: 1px solid rgba(255,255,255,0.05);
}

.user-profile-link {
    text-decoration: none;
    display: block;
    border-radius: var(--radius-md);
    transition: 0.2s;
}

.user-profile-link:hover {
    background: rgba(255,255,255,0.05);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    overflow: hidden;
}

.sidebar.collapsed .user-details {
    display: none;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary-dark);
    color: white;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    flex-shrink: 0;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.user-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
    white-space: nowrap;
}

.user-role {
    font-size: 0.7rem;
    color: #8696a0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Main Content adjustment */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: calc(100% - var(--sidebar-width));
}

body.sidebar-collapsed .main-content {
    margin-left: 80px;
    width: calc(100% - 80px);
}

.mobile-only { display: none !important; }
.desktop-only { display: flex !important; }

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width) !important; }
    .sidebar.active { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.5); }
    .main-content { margin-left: 0 !important; width: 100% !important; }
    .mobile-only { display: flex !important; }
    .desktop-only { display: none !important; }
}

.navbar {
    height: var(--navbar-height);
    background: white;
    padding: 0 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 900;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.user-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
}

.user-meta .name {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text);
}

.user-meta .role {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.nav-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 8px;
}

#logoutBtn {
    background: transparent;
    color: var(--text-muted);
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: 0.2s;
    border: 1px solid transparent;
}

#logoutBtn:hover {
    color: var(--danger);
    background: #fff1f2;
    border-color: #fecaca;
}

#logoutBtn span {
    font-size: 0.85rem;
    font-weight: 600;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px;
    width: 100%;
}

/* UI Components */
.card {
    background: white;
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

/* Buttons & Interactive */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9rem;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: #f0f2f5; color: var(--text); }
.btn-secondary:hover { background: #e9edef; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.w-full { width: 100%; }

/* Data Tables */
.table-responsive { overflow-x: auto; margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 12px; color: var(--text-muted); font-size: 0.75rem; border-bottom: 2px solid var(--border); text-transform: uppercase; letter-spacing: 0.5px; }
td { padding: 15px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }

/* Badges & Status */
.badge, .status-badge, .health-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge-success, .status-connected, .health-healthy { background: #dcf8c6; color: #075e54; }
.badge-danger, .status-disconnected, .status-banned, .health-unhealthy { background: #fee2e2; color: #991b1b; }
.badge-secondary, .health-unknown { background: #f0f2f5; color: #667781; }
.badge-primary, .status-connecting, .health-risky { background: #e1f5fe; color: #0288d1; }

/* WhatsApp Account Cards */
.account-card {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.account-info-main { flex: 1; }
.account-actions {
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding-top: 15px;
    margin-top: 15px;
}

/* Forms */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; font-size: 0.85rem; color: var(--text); }
.form-control, input[type="text"], input[type="email"], input[type="password"], select {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    font-size: 0.95rem;
    transition: 0.2s;
    background: #fff;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1); }

/* Grid Utilities */
.grid { display: grid; gap: 24px; }
.grid-cols-1 { grid-template-columns: 1fr; }
@media (min-width: 768px) { .md\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .lg\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); } }

/* Flex Utilities */
.flex { display: flex; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.gap-5 { gap: 5px; }
.gap-10 { gap: 10px; }
.gap-20 { gap: 20px; }

/* Spacing Utilities */
.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.mb-30 { margin-bottom: 30px; }

/* Text Utilities */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.small { font-size: 0.75rem; }

/* Alerts */
.alert {
    padding: 15px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.9rem;
}
.alert-info { background: #e3f2fd; color: #0288d1; border: 1px solid #bbdefb; }
.alert-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #c8e6c9; }
.alert-danger { background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(11,20,26,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}
.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2);
    overflow: hidden;
}
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 24px; }

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 25px;
}
.tab-btn {
    padding: 12px 20px;
    border: none;
    background: none;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    position: relative;
    transition: 0.2s;
    font-size: 0.9rem;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary-dark); }
.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--primary);
}

.tab-content {
    display: none;
}

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

/* Dropdown Menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    color: var(--text-muted);
}

.dropdown-toggle:hover {
    background: rgba(0,0,0,0.05);
    color: var(--text);
}

.dropdown-menu {
    display: none;
    position: fixed;
    background: white;
    min-width: 180px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    border-radius: var(--radius-md);
    z-index: 9999;
    border: 1px solid var(--border);
    padding: 8px 0;
}

.dropdown-menu.show {
    display: block;
}

/* We will handle positioning via JS for better reliability */
.dropdown-menu.drop-up {
    /* JS will adjust the top/bottom */
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background: #f0f2f5;
}

.dropdown-item.text-danger {
    color: var(--danger);
}

.dropdown-item.text-danger:hover {
    background: #fff1f2;
}

.dropdown-item.text-primary {
    color: var(--primary-dark);
}

.dropdown-item.text-primary:hover {
    background: #eff6ff;
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

/* Enhanced User Management UI */
.page-header {
    margin-bottom: 30px;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 8px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 15px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-info .stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.stat-info .stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

.search-filter-bar {
    background: white;
    padding: 16px 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    display: flex;
    gap: 15px;
    margin-bottom: 24px;
    align-items: center;
}

.search-input-group {
    position: relative;
    flex: 1;
}

.search-input-group svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input-group input {
    padding-left: 40px !important;
}

.user-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar-lg {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.user-info .user-name {
    font-weight: 700;
    color: var(--text);
    font-size: 0.95rem;
}

.user-info .user-email {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.status-pill {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-pill.active { background: #dcf8c6; color: #075e54; }
.status-pill.pending { background: #fff3cd; color: #856404; }
.status-pill.blocked { background: #f8d7da; color: #721c24; }

.limit-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f0f2f5;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin: 2px;
}

.limit-tag b { color: var(--text); }

.table-modern th {
    background: #f8fafc;
    color: #64748b;
    font-weight: 700;
    padding: 16px 20px;
    font-size: 0.75rem;
}

.table-modern td {
    padding: 16px 20px;
}

/* Professional Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c8cd;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #aab2b7;
}

.form-control-sm {
    padding: 6px 10px;
    font-size: 0.85rem;
}

.modal-body table th {
    background: #f8fafc;
    font-size: 0.7rem;
    padding: 10px 12px;
}

.hover\:bg-gray-50:hover {
    background-color: #f9fafb;
}

/* Scrollbar styling for modal tables */
.modal-body div::-webkit-scrollbar {
    width: 6px;
}
.modal-body div::-webkit-scrollbar-track {
    background: #f1f1f1;
}
.modal-body div::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
}
.modal-body div::-webkit-scrollbar-thumb:hover {
    background: #999;
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .main-content { margin-left: 0; width: 100%; }
    .navbar .sidebar-brand { display: flex !important; }
}
