:root{
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --border: #e8eaf0;
  --border-strong: #d8dce6;

  --text: #111111;
  --text-soft: #6b7280;
  --text-faint: #9ca3af;

  --sidebar: #0f0f11;
  --sidebar-soft: #17171b;
  --sidebar-border: rgba(255,255,255,0.06);
  --sidebar-text: rgba(255,255,255,0.84);
  --sidebar-text-soft: rgba(255,255,255,0.58);

  --primary: #d61f37;
  --primary-hover: #b91c31;
  --primary-soft: #fff1f3;

  --accent: #f43f5e;
  --accent-soft: #ffe4e6;

  --success: #15803d;
  --success-bg: #ecfdf3;

  --warning: #b45309;
  --warning-bg: #fffbeb;

  --danger: #b91c1c;
  --danger-bg: #fef2f2;

  --info: #1d4ed8;
  --info-bg: #eff6ff;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.04);
  --shadow: 0 10px 30px rgba(17,17,17,.05);
  --shadow-lg: 0 24px 60px rgba(17,17,17,.08);

  --transition: 160ms ease;
}

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

html,body{
  width:100%;
  min-height:100%;
}

body{
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:var(--bg);
  color:var(--text);
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
}

a{
  color:inherit;
  text-decoration:none;
}

button,
input,
select,
textarea{
  font:inherit;
}

img{
  max-width:100%;
  display:block;
}

/* layout */
.layout{
  display:flex;
  min-height:100vh;
  background:var(--bg);
}

.sidebar{
  width:280px;
  min-width:280px;
  background:linear-gradient(180deg, #0f0f11 0%, #141419 100%);
  color:#fff;
  padding:22px 18px;
  display:flex;
  flex-direction:column;
  border-right:1px solid var(--sidebar-border);
  position:sticky;
  top:0;
  height:100vh;
  z-index:50;
}

.sidebar-logo{
  padding:10px 10px 20px;
  border-bottom:1px solid var(--sidebar-border);
  margin-bottom:18px;
}

.brand{
  font-size:20px;
  font-weight:800;
  letter-spacing:-0.03em;
  color:#fff;
}

.sub{
  margin-top:4px;
  color:var(--sidebar-text-soft);
  font-size:12px;
  font-weight:500;
}

.sidebar-nav{
  display:flex;
  flex-direction:column;
  gap:4px;
  flex:1;
  overflow:auto;
  padding-right:4px;
}

.nav-section{
  padding:14px 10px 8px;
  font-size:11px;
  letter-spacing:.08em;
  text-transform:uppercase;
  color:var(--sidebar-text-soft);
  font-weight:700;
}

.nav-item{
  display:flex;
  align-items:center;
  gap:12px;
  padding:12px 12px;
  border-radius:14px;
  color:var(--sidebar-text);
  font-size:14px;
  font-weight:600;
  transition:background var(--transition), color var(--transition), transform var(--transition);
}

.nav-item .icon{
  width:20px;
  text-align:center;
  font-size:15px;
  flex-shrink:0;
}

.nav-item:hover{
  background:rgba(255,255,255,0.06);
  color:#fff;
}

.nav-item.active{
  background:linear-gradient(180deg, rgba(214,31,55,.18) 0%, rgba(214,31,55,.12) 100%);
  color:#fff;
  box-shadow:inset 0 0 0 1px rgba(214,31,55,.25);
}

.sidebar-user{
  display:flex;
  align-items:center;
  gap:12px;
  padding:14px 10px 6px;
  margin-top:14px;
  border-top:1px solid var(--sidebar-border);
}

.user-avatar{
  width:42px;
  height:42px;
  border-radius:50%;
  display:flex;
  align-items:center;
  justify-content:center;
  background:#1f2937;
  color:#fff;
  font-weight:800;
  font-size:13px;
  letter-spacing:.04em;
  flex-shrink:0;
}

.user-info .name{
  font-size:14px;
  font-weight:700;
  color:#fff;
}

.user-info .role{
  font-size:12px;
  color:var(--sidebar-text-soft);
}

.main{
  flex:1;
  min-width:0;
  display:flex;
  flex-direction:column;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:22px 28px 16px;
  background:transparent;
}

.topbar-title{
  font-size:24px;
  line-height:1.1;
  font-weight:800;
  letter-spacing:-0.04em;
  color:var(--text);
}

.topbar-actions{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.content{
  padding:0 28px 28px;
}

/* cards */
.card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  box-shadow:var(--shadow-sm);
  padding:20px;
}

.card + .card{
  margin-top:16px;
}

.card-title{
  font-size:15px;
  font-weight:800;
  letter-spacing:-0.02em;
  color:var(--text);
  margin-bottom:14px;
}

/* metrics */
.metrics-grid{
  display:grid;
  grid-template-columns:repeat(4, minmax(0,1fr));
  gap:16px;
}

.metric-card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  padding:20px;
  box-shadow:var(--shadow-sm);
}

.metric-label{
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.06em;
  color:var(--text-soft);
  font-weight:700;
}

.metric-value{
  margin-top:10px;
  font-size:30px;
  line-height:1;
  font-weight:800;
  letter-spacing:-0.05em;
  color:var(--text);
}

.metric-sub{
  margin-top:10px;
  font-size:13px;
  color:var(--text-soft);
}

/* tables */
.table-wrap{
  overflow:auto;
  border-radius:inherit;
}

table{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  min-width:900px;
}

thead th{
  background:#fbfbfc;
  color:var(--text-soft);
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.05em;
  font-weight:800;
  padding:14px 16px;
  text-align:left;
  border-bottom:1px solid var(--border);
  white-space:nowrap;
}

tbody td{
  padding:16px;
  border-bottom:1px solid var(--border);
  vertical-align:middle;
  font-size:14px;
}

tbody tr{
  transition:background var(--transition);
}

tbody tr:hover{
  background:#fcfcfd;
}

tbody tr:last-child td{
  border-bottom:none;
}

/* forms */
.form-group{
  display:flex;
  flex-direction:column;
  gap:8px;
  margin-bottom:16px;
}

.form-label{
  font-size:12px;
  font-weight:700;
  color:var(--text-soft);
  text-transform:uppercase;
  letter-spacing:.04em;
}

.form-control{
  width:100%;
  height:46px;
  border:1px solid var(--border);
  background:#fff;
  border-radius:14px;
  padding:0 14px;
  color:var(--text);
  outline:none;
  transition:border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

textarea.form-control{
  min-height:110px;
  height:auto;
  padding:14px;
  resize:vertical;
}

.form-control:focus{
  border-color:rgba(214,31,55,.45);
  box-shadow:0 0 0 4px rgba(214,31,55,.08);
}

.form-control::placeholder{
  color:#b3b8c4;
}

/* buttons */
.btn{
  height:42px;
  border:none;
  border-radius:14px;
  padding:0 16px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  font-size:14px;
  font-weight:700;
  white-space:nowrap;
  cursor:pointer;
  transition:transform var(--transition), background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.btn:hover{
  transform:translateY(-1px);
}

.btn:active{
  transform:translateY(0);
}

.btn-primary{
  background:var(--primary);
  color:#fff;
  box-shadow:0 8px 20px rgba(214,31,55,.18);
}

.btn-primary:hover{
  background:var(--primary-hover);
}

.btn-outline{
  background:#fff;
  color:var(--text);
  border:1px solid var(--border);
}

.btn-outline:hover{
  background:#fafafa;
  border-color:var(--border-strong);
}

.btn-sm{
  height:34px;
  padding:0 12px;
  font-size:12px;
  border-radius:12px;
}

/* badges and status */
.badge,
.status-pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  min-height:28px;
  padding:4px 10px;
  border-radius:999px;
  font-size:12px;
  font-weight:800;
  line-height:1;
  white-space:nowrap;
}

.badge{
  background:#f3f4f6;
  color:#374151;
}

.status-pill{
  background:#f3f4f6;
  color:#374151;
}

/* alerts */
.alert{
  border-radius:16px;
  padding:14px 16px;
  font-size:14px;
  font-weight:600;
  border:1px solid transparent;
  margin-bottom:16px;
}

.alert-success{
  background:var(--success-bg);
  color:var(--success);
  border-color:rgba(21,128,61,.12);
}

.alert-danger{
  background:var(--danger-bg);
  color:var(--danger);
  border-color:rgba(185,28,28,.12);
}

.alert-warning{
  background:var(--warning-bg);
  color:var(--warning);
  border-color:rgba(180,83,9,.12);
}

/* modal */
.modal-overlay{
  position:fixed;
  inset:0;
  background:rgba(15,15,17,.5);
  backdrop-filter:blur(3px);
  display:none;
  align-items:center;
  justify-content:center;
  padding:24px;
  z-index:100;
}

.modal-overlay.open{
  display:flex;
}

.modal{
  width:min(100%, 760px);
  max-height:90vh;
  overflow:auto;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:24px;
  box-shadow:var(--shadow-lg);
}

.modal-header{
  padding:18px 22px;
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  position:sticky;
  top:0;
  background:#fff;
  z-index:2;
}

.modal-title{
  font-size:18px;
  font-weight:800;
  letter-spacing:-0.03em;
}

.modal-close{
  width:36px;
  height:36px;
  border-radius:50%;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  color:var(--text-soft);
  background:#f7f7f8;
  transition:background var(--transition), color var(--transition);
}

.modal-close:hover{
  background:#efeff1;
  color:var(--text);
}

.modal-body{
  padding:22px;
}

.modal-footer{
  padding:18px 22px;
  border-top:1px solid var(--border);
  display:flex;
  justify-content:flex-end;
  gap:10px;
  position:sticky;
  bottom:0;
  background:#fff;
}

/* login */
.login-wrap{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
  background:
    radial-gradient(circle at top left, rgba(214,31,55,.08), transparent 28%),
    radial-gradient(circle at bottom right, rgba(244,63,94,.06), transparent 24%),
    var(--bg);
}

.login-box{
  width:100%;
  max-width:440px;
  background:#fff;
  border:1px solid var(--border);
  border-radius:28px;
  padding:32px;
  box-shadow:var(--shadow-lg);
}

.login-logo{
  font-size:28px;
  font-weight:900;
  letter-spacing:-0.05em;
  color:var(--text);
}

.login-sub{
  margin-top:8px;
  margin-bottom:24px;
  color:var(--text-soft);
  font-size:14px;
}

/* utilities */
.text-muted{ color:var(--text-soft); }
.text-sm{ font-size:12px; }
.fw-600{ font-weight:600; }

.flex{ display:flex; }
.items-center{ align-items:center; }
.justify-between{ justify-content:space-between; }
.gap-12{ gap:12px; }

.grid-2{
  display:grid;
  grid-template-columns:repeat(2, minmax(0,1fr));
  gap:16px;
}

.grid-3{
  display:grid;
  grid-template-columns:repeat(3, minmax(0,1fr));
  gap:16px;
}

.grid-4{
  display:grid;
  grid-template-columns:repeat(4, minmax(0,1fr));
  gap:16px;
}

/* funnel bars if used */
.funil-bar{
  display:grid;
  grid-template-columns:140px 1fr 50px;
  gap:12px;
  align-items:center;
  margin-bottom:12px;
}

.funil-label{
  font-size:13px;
  font-weight:700;
  color:var(--text);
}

.funil-track{
  height:10px;
  border-radius:999px;
  background:#f1f3f7;
  overflow:hidden;
}

.funil-fill{
  height:100%;
  border-radius:999px;
}

.funil-count{
  font-size:12px;
  font-weight:800;
  color:var(--text-soft);
  text-align:right;
}

/* responsive */
#menu-toggle{
  display:none;
}

@media (max-width: 1280px){
  .metrics-grid{
    grid-template-columns:repeat(2, minmax(0,1fr));
  }
}

@media (max-width: 1100px){
  .grid-4{
    grid-template-columns:repeat(2, minmax(0,1fr));
  }
}

@media (max-width: 980px){
  .sidebar{
    position:fixed;
    left:-100%;
    top:0;
    height:100vh;
    transition:left var(--transition);
    box-shadow:var(--shadow-lg);
  }

  .sidebar.open{
    left:0;
  }

  #menu-toggle{
    display:inline-flex !important;
  }

  .topbar{
    padding:18px 18px 14px;
  }

  .content{
    padding:0 18px 22px;
  }

  .grid-3{
    grid-template-columns:1fr;
  }

  .grid-2{
    grid-template-columns:1fr;
  }
}

@media (max-width: 720px){
  .metrics-grid{
    grid-template-columns:1fr;
  }

  .grid-4{
    grid-template-columns:1fr;
  }

  .topbar{
    flex-direction:column;
    align-items:flex-start;
  }

  .topbar-actions{
    width:100%;
    justify-content:flex-start;
  }

  .modal{
    width:100%;
    border-radius:20px;
  }

  .login-box{
    padding:24px;
    border-radius:22px;
  }

  .funil-bar{
    grid-template-columns:1fr;
  }

  .funil-count{
    text-align:left;
  }
}