:root{
  --bg:#f6f7fb;
  --card:#fff;
  --text:#111;
  --muted:#6b7280;
  --pri:#1f7ae0;
}

/* Base */
*{box-sizing:border-box}
html,body{margin:0;overflow-x:hidden}
body{
  font-family:Inter,system-ui,-apple-system,Segoe UI,Roboto,Arial;
  background:var(--bg);
  color:var(--text);
}

/* Top Bar */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 16px;
  border-bottom:1px solid #e5e7eb;
  background:#fff;
  position:sticky;
  top:0;
  left:0;
  right:0;
  z-index:20;
  width:100%;
  box-sizing:border-box;
}

.topbar .brand{
  display:flex;
  align-items:center;
  gap:8px;
  font-weight:700;
}
.brand-logo{
  display:block;
  max-height:44px;
  width:auto;
}

.menu-toggle {
  display:none;
  background:none;
  border:none;
  font-size:24px;
  padding:5px;
  cursor:pointer;
  color:var(--text);
}

/* Topbar actions */
.top-actions{
  display:flex;
  align-items:center;
  gap:12px;
}
.icon-btn{
  width:34px;height:34px;
  border:1px solid #e5e7eb;
  border-radius:10px;
  background:#fff;
  position:relative;
}
.icon-btn .dot{
  position:absolute;
  top:8px;right:9px;
  width:6px;height:6px;
  background:#7c3aed;
  border-radius:999px;
}

/* Layout */
.wrap{
  display:flex;
  min-height:calc(100vh - 56px);
  overflow:hidden;
}
.content{
  flex:1;
  padding:18px;
}

/* Sidebar */
.sidenav{
  width:240px;
  background:#fff;
  border-right:1px solid #e5e7eb;
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:10px;
  transition:left .25s ease;
}
.sidenav a{
  color:#111;
  text-decoration:none;
  padding:10px 14px;
  border-radius:8px;
  transition:background .15s,color .15s;
  display:flex;
  align-items:center;
  gap:10px;
}
.sidenav a:hover{background:#f0f4ff}
.sidenav a.active{background:#eef5ff;color:#0b63c5}

/* Purple sidebar variant */
.sidenav.purple{
  background:linear-gradient(180deg,#7c3aed 0%, #6d28d9 100%);
  border-right:none;
}
.sidenav.purple a{
  color:#fff;
}
.sidenav.purple a:hover{
  background:rgba(255,255,255,.10)
}
.sidenav.purple a.active{
  background:rgba(255,255,255,.18)
}

/* Mobile Sidebar Drawer */
@media(max-width:900px){
  .menu-toggle { display:block }
  .sidenav{
    position:fixed;
    top:0;
    left:-260px;
    height:100vh;
    z-index:9999;
  }
  .sidenav.open{
    left:0;
  }
  .wrap{
    flex-direction:column;
  }
}

/* Grids */
.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:18px}
@media(max-width:960px){.grid{grid-template-columns:1fr}}

.grid-3-1{
  display:grid;
  grid-template-columns:2.2fr 1fr;
  gap:18px;
}
@media(max-width:1000px){.grid-3-1{grid-template-columns:1fr}}

.grid-3{display:grid;gap:18px}
@media(max-width:1000px){.grid-3{grid-template-columns:1fr}}

/* Cards */
.card{
  background:var(--card);
  padding:18px;
  border:1px solid #e5e7eb;
  border-radius:12px;
}
.card.span-2{grid-column:span 2}
.card-head{font-weight:700;margin-bottom:8px}

/* Text utils */
.muted{color:var(--muted)}
.big{font-size:34px;font-weight:800;margin-top:6px}

/* Forms & Inputs */
input,select,textarea,button{
  width:100%;
  padding:10px;
  border:1px solid #d1d5db;
  border-radius:8px;
  outline:none;
}
input:focus,select:focus,textarea:focus{
  border-color:#1f7ae0;
  box-shadow:0 0 0 3px rgba(31,122,224,.12)
}
button{
  background:var(--pri);
  color:#fff;
  border:none;
  cursor:pointer;
  transition:filter .15s
}
button:hover{filter:brightness(1.05)}
.btn{
  display:inline-block;
  background:var(--pri);
  color:#fff;
  padding:10px 16px;
  border-radius:8px;
  text-decoration:none;
  transition:filter .15s
}
.btn:hover{filter:brightness(1.05)}
.btn.outline{
  background:#fff;
  color:#1f7ae0;
  border:1px solid #1f7ae0
}

/* Tables */
table{width:100%;border-collapse:collapse}
thead th{
  font-weight:600;
  color:#374151;
  background:#f9fafb
}
th,td{
  padding:10px;
  border-bottom:1px solid #f0f0f0;
  text-align:left
}

/* Alerts */
.alert{
  background:#fff3cd;
  border:1px solid #ffeeba;
  padding:10px;border-radius:8px;
  margin:10px 0;
  color:#8a6d3b
}

/* Public landing */
.wrap.public{display:block}
.wrap.public .content{
  padding:48px 20px;
  max-width:980px;
  margin:0 auto
}
.hero{
  display:flex;
  flex-direction:column;
  gap:14px;
  background:#fff;
  border:1px solid #e5e7eb;
  border-radius:12px;
  padding:28px 24px;
  margin-bottom:20px
}
.hero h1{font-size:28px;margin:0;line-height:1.2}
.hero .muted{color:var(--muted);font-weight:600}
.hero .lead{color:#374151;margin:0}
.cta{display:flex;gap:10px;margin-top:8px}

/* KPI grid */
.kpi-grid{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:16px;
  margin-bottom:16px
}
@media(max-width:900px){
  .kpi-grid{grid-template-columns:repeat(2,1fr)}
}
.kpi-card{
  background:#fff;
  border:1px solid #eee;
  border-radius:12px;
  padding:14px
}
.kpi-title{color:#6b7280;font-weight:600}
.kpi-value{font-size:28px;font-weight:800;margin-top:8px}
.kpi-sub{color:#6b7280;margin-top:4px}

/* Legend */
.legend{
  margin-top:8px;
  color:#6b7280;
  font-size:14px;
  display:flex;
  gap:16px;
  align-items:center
}
.dot{
  display:inline-block;
  width:10px;height:10px;
  border-radius:999px;
  margin-right:4px
}
.dot.spend{background:#7c3aed}
.dot.conv{background:#a78bfa}
.dot.ctr{background:#c4b5fd}

/* Profile menu */
.avatar-btn{
  display:flex;
  align-items:center;
  justify-content:center;
  width:36px;height:36px;
  border-radius:999px;
  border:1px solid #e5e7eb;
  background:#fff;
  cursor:pointer
}
.avatar-initial{font-weight:700;color:#4b5563}
.profile-menu{position:relative}
.profile-menu .menu{
  position:absolute;
  right:0;top:44px;
  background:#fff;
  border:1px solid #e5e7eb;
  border-radius:12px;
  min-width:180px;
  box-shadow:0 8px 24px rgba(0,0,0,.06);
  display:none;
  z-index:30
}
.profile-menu .menu.open{display:block}
.profile-menu .menu a{
  display:block;
  padding:10px 12px;
  color:#111;
  text-decoration:none
}
.profile-menu .menu a:hover{
  background:#f8f5ff;
  color:#4c1d95
}

.badge{
  background:#dc3545;
  color:#fff;
  border-radius:10px;
  padding:0 6px;
  font-size:12px;
  margin-left:6px
}

/* Notification Dropdown */
.dropdown{
  background:#fff;
  border:1px solid #eee;
  border-radius:8px;
  box-shadow:0 8px 24px rgba(0,0,0,.08)
}
.dropdown-body{
  max-height:320px;
  overflow:auto
}
.alert-item{
  padding:10px 12px;
  border-bottom:1px solid #f2f2f2
}
.alert-item:last-child{border-bottom:none}

/* Charts */
.card.chart-card{
  position:relative;
  width:100%;
  height:340px;
  overflow:visible;
  padding-left:8px!important;
  padding-right:8px!important;
}
#perfChart{
  width:100%;
  height:260px;
  overflow:visible;
}

/* Form helpers */
.req:after{content:" *";color:#ef4444;font-weight:700}
.field-error{color:#b91c1c;margin-top:6px;font-size:13px}
input.error, select.error, textarea.error{border-color:#ef4444}
.form-row{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:12px
}
@media(max-width:720px){
  .form-row{grid-template-columns:1fr}
}

/* Chips */
.multi{
  display:flex;flex-wrap:wrap;gap:8px;
  background:#fff;border:1px solid #d1d5db;border-radius:8px;padding:6px
}
.chip{
  background:#eef2ff;color:#3730a3;
  border-radius:999px;padding:6px 10px;
  font-size:13px;display:flex;gap:6px;align-items:center
}
.chip .x{cursor:pointer}
.multi input{
  border:none;outline:none;min-width:120px
}
