/* Modern SaaS CRM CSS - Premium UI/UX */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #8b5cf6;
    
    /* Light Theme Tokens */
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-glass: rgba(255, 255, 255, 0.85);
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    
    /* Sidebar */
    --sidebar-bg: #ffffff;
    --sidebar-text: #334155;
    --sidebar-hover: #f1f5f9;
    --sidebar-active: #e0e7ff;
    --sidebar-active-text: #4f46e5;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --radius-full: 9999px;
    
    --font-sans: 'Plus Jakarta Sans', sans-serif;
}

body.theme-dark {
    /* Dark Theme Tokens */
    --bg-main: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-glass: rgba(30, 41, 59, 0.85);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-hover: #334155;
    --sidebar-active: #312e81;
    --sidebar-active-text: #818cf8;
    
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    text-decoration: none;
    color: var(--primary);
}

/* Layout */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    z-index: 99;
}
.sidebar-overlay.active {
    display: block;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease, background 0.3s ease;
}

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

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hamburger-close {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
}

.sidebar-user {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-user .avatar {
    width: 40px; height: 40px;
    border-radius: var(--radius-full);
    background: var(--primary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}

.sidebar-user .info {
    display: flex;
    flex-direction: column;
}
.sidebar-user .info .name {
    font-weight: 600;
    font-size: 0.95rem;
}
.sidebar-user .info .role {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.nav-section-label {
    padding: 0.5rem 1.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-text);
    transition: all 0.2s;
    font-weight: 500;
}

.nav-item:hover {
    background: var(--sidebar-hover);
}

.nav-item.active {
    background: var(--sidebar-active);
    color: var(--sidebar-active-text);
    border-right: 4px solid var(--primary);
}

.nav-icon {
    width: 24px;
    margin-right: 12px;
    font-size: 1.1rem;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem 0;
    border-top: 1px solid var(--border-color);
}

.logout-item:hover {
    color: #ef4444;
}

.main-wrapper {
    margin-left: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s;
}

.topbar {
    height: 70px;
    background: var(--bg-surface-glass);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.hamburger-open {
    display: none;
    background: none; border: none;
    font-size: 1.25rem;
    color: var(--text-main);
    cursor: pointer;
    margin-right: 1rem;
}

.page-title {
    font-size: 1.2rem;
    font-weight: 700;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.icon-btn {
    background: none; border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
    width: 40px; height: 40px;
    border-radius: var(--radius-full);
    transition: background 0.2s;
}
.icon-btn:hover {
    background: var(--border-color);
    color: var(--text-main);
}

.topbar-avatar {
    position: relative;
}
.avatar-circle {
    width: 40px; height: 40px;
    border-radius: var(--radius-full);
    background: var(--secondary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    cursor: pointer;
}

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0; top: 50px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    min-width: 150px;
    overflow: hidden;
}
.dropdown-menu.show { display: block; }
.dropdown-menu a {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-main);
}
.dropdown-menu a:hover {
    background: var(--border-color);
}

.page-content {
    padding: 2rem;
    flex: 1;
}

/* Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 56px; height: 56px;
    border-radius: var(--radius-lg);
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
}

.stat-details h3 {
    font-size: 1.5rem;
    font-weight: 800;
    margin-top: 0.25rem;
}
.stat-details p {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

/* Forms & Tables */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
}
.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-main);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    border: none;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-hover);
}

/* Flash msg */
.flash-message {
    padding: 1rem 1.5rem;
    margin: 1rem 2rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.flash-success { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid #10b981; }
.flash-error { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid #ef4444; }

.flash-close {
    background: none; border: none; font-size: 1.2rem; cursor: pointer; color: inherit;
}

/* Table Style */
.table-responsive {
    overflow-x: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th, .table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}
.table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

/* Responsiveness */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.active {
        transform: translateX(0);
    }
    .main-wrapper {
        margin-left: 0;
    }
    .hamburger-open {
        display: block;
    }
    .hamburger-close {
        display: block;
    }
    .topbar {
        padding: 0 1rem;
    }
    .page-content {
        padding: 1rem;
    }
}
