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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #1e1b4b;
    --gray-900: #111827;
    --gray-800: #1f2937;
    --gray-700: #374151;
    --gray-600: #4b5563;
    --gray-500: #6b7280;
    --gray-400: #9ca3af;
    --gray-300: #d1d5db;
    --gray-200: #e5e7eb;
    --gray-100: #f3f4f6;
    --white: #ffffff;
    --sidebar-width: 260px;
}

body {
    font-family: 'Space Grotesk', -apple-system, sans-serif;
    background: linear-gradient(135deg, #0f0c29 0%, #1e1b4b 50%, #24243e 100%);
    min-height: 100vh;
    color: var(--gray-100);
}

.screen { display: none; }
.screen.active { display: flex; }

/* Login */
#login-screen {
    min-height: 100vh;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #0f0c29 0%, #1e1b4b 50%, #24243e 100%);
}

.login-container {
    background: rgba(255,255,255,0.05);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 24px;
    padding: 48px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
}

.login-brand { text-align: center; margin-bottom: 40px; }
.login-brand .logo { margin-bottom: 16px; }
.login-brand h1 { font-size: 32px; font-weight: 700; background: linear-gradient(135deg, #6366f1, #8b5cf6); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-brand p { color: var(--gray-400); margin-top: 8px; }

.form-group { margin-bottom: 24px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 500; color: var(--gray-300); font-size: 14px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 14px 16px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    color: var(--white);
    font-size: 16px;
    transition: all 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}
.form-group input::placeholder { color: var(--gray-500); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(99,102,241,0.3); }
.btn-secondary { background: rgba(255,255,255,0.1); color: white; }
.btn-secondary:hover { background: rgba(255,255,255,0.15); }
.btn-danger { background: var(--danger); color: white; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 13px; }

.error-message { color: var(--danger); text-align: center; margin-top: 16px; font-size: 14px; }
.login-footer { text-align: center; margin-top: 24px; color: var(--gray-500); font-size: 12px; }
.login-footer p { margin: 4px 0; }

/* App Layout */
#app-screen { display: none; min-height: 100vh; }
#app-screen.active { display: flex; }

.sidebar {
    width: var(--sidebar-width);
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-title { font-size: 20px; font-weight: 700; }

.nav-menu { list-style: none; padding: 16px 12px; flex: 1; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 4px;
    color: var(--gray-400);
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--white); }
.nav-item.active { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; }
.nav-icon { font-size: 18px; }
.superadmin-only { display: none; }
body.is-superadmin .superadmin-only { display: flex; }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-info { display: flex; align-items: center; gap: 12px; flex: 1; }
.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}
.user-details { display: flex; flex-direction: column; }
.user-name { font-weight: 600; font-size: 14px; }
.user-role { font-size: 12px; color: var(--gray-400); text-transform: capitalize; }
.btn-logout {
    background: rgba(255,255,255,0.1);
    border: none;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}
.btn-logout:hover { background: rgba(239,68,68,0.2); }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    min-height: 100vh;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 16px;
}
.page-header h1 { font-size: 28px; font-weight: 700; }
.header-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.search-input, .select-filter {
    padding: 10px 16px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    color: white;
    font-size: 14px;
}
.search-input { width: 200px; }
.search-input::placeholder { color: var(--gray-500); }
.select-filter { cursor: pointer; }
.select-filter option { background: var(--gray-800); }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 32px; }
.stat-card {
    background: rgba(255,255,255,0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.3s;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: 0 20px 40px rgba(0,0,0,0.3); }
.stat-icon { font-size: 32px; }
.stat-label { display: block; color: var(--gray-400); font-size: 14px; margin-bottom: 4px; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-card.clicks { border-left: 4px solid #3b82f6; }
.stat-card.leads { border-left: 4px solid #10b981; }
.stat-card.sales { border-left: 4px solid #f59e0b; }
.stat-card.revenue { border-left: 4px solid #8b5cf6; }

/* Dashboard Grid */
.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
@media (max-width: 1200px) { .dashboard-grid { grid-template-columns: 1fr; } }

.chart-card, .top-campaigns-card {
    background: rgba(255,255,255,0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 24px;
}
.chart-card h3, .top-campaigns-card h3 { margin-bottom: 20px; font-size: 18px; }
.chart-card canvas { max-height: 300px; }

#top-campaigns-list .campaign-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
#top-campaigns-list .campaign-item:last-child { border-bottom: none; }
.campaign-item-name { font-weight: 500; }
.campaign-item-stats { display: flex; gap: 16px; font-size: 13px; color: var(--gray-400); }

/* Period Selector */
.period-selector { display: flex; gap: 8px; }
.period-btn {
    padding: 8px 16px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: var(--gray-400);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 13px;
}
.period-btn:hover { background: rgba(255,255,255,0.1); }
.period-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Tables */
.table-container { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: rgba(255,255,255,0.03);
    border-radius: 16px;
    overflow: hidden;
}
.data-table th, .data-table td { padding: 16px; text-align: left; }
.data-table th {
    background: rgba(255,255,255,0.05);
    font-weight: 600;
    font-size: 13px;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.data-table td { border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 14px; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}
.status-active { background: rgba(16,185,129,0.2); color: #10b981; }
.status-inactive { background: rgba(239,68,68,0.2); color: #ef4444; }
.status-pending { background: rgba(245,158,11,0.2); color: #f59e0b; }
.status-approved { background: rgba(16,185,129,0.2); color: #10b981; }
.status-rejected { background: rgba(239,68,68,0.2); color: #ef4444; }

.toggle-switch {
    width: 44px;
    height: 24px;
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
}
.toggle-switch.active { background: var(--success); }
.toggle-switch::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 10px;
    top: 2px;
    left: 2px;
    transition: all 0.2s;
}
.toggle-switch.active::after { left: 22px; }

.action-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    margin-right: 4px;
}
.action-btn:hover { background: rgba(255,255,255,0.2); }
.action-btn.danger:hover { background: rgba(239,68,68,0.3); }

.tracking-url {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    background: rgba(0,0,0,0.3);
    padding: 6px 10px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.7;
    font-size: 14px;
}
.copy-btn:hover { opacity: 1; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.modal.active { display: flex; }
.modal-content {
    background: var(--gray-800);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.modal-header h2 { font-size: 20px; }
.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--gray-400);
    cursor: pointer;
    line-height: 1;
}
.modal-close:hover { color: white; }
.modal-body { padding: 24px; }
.modal-body .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.modal-body .form-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; padding-top: 24px; border-top: 1px solid rgba(255,255,255,0.1); }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--gray-800);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 16px 24px;
    border-radius: 12px;
    display: none;
    z-index: 2000;
    animation: toastIn 0.3s ease;
}
.toast.active { display: block; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 16px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .modal-body .form-row { grid-template-columns: 1fr; }
}
