:root {
  --bg: #0d0f14;
  --bg-elevated: #141720;
  --bg-card: #181c27;
  --bg-hover: #1f2433;
  --border: #272c3d;
  --text: #eef1f7;
  --text-muted: #939bb0;
  --accent: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.16);
  --accent-hover: #8b5cf6;
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.14);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --radius: 12px;
  --transition: 0.18s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 13px; }

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, rgba(124, 58, 237, 0.12), transparent 45%), var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.auth-brand h1 { font-size: 18px; font-weight: 700; }
.auth-brand span { font-size: 12px; color: var(--accent-hover); font-weight: 500; }
.auth-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }
.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #5b21b6);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}

/* Forms & Buttons */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12px; font-weight: 500; color: var(--text-muted); }
input, select, textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.btn i, .btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }
.btn-success { background: var(--success-soft); color: var(--success); border-color: rgba(16, 185, 129, 0.3); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.mfa-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: #fff;
  border-radius: 10px;
  margin-bottom: 14px;
}
.mfa-qr-box img { width: 170px; height: 170px; }
.mfa-qr-box code { color: #111; font-size: 11px; word-break: break-all; }

.alert-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  font-size: 12.5px;
}

/* App Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 252px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  transition: width var(--transition);
  flex-shrink: 0;
}
.sidebar.collapsed { width: 74px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .admin-meta,
.sidebar.collapsed #btn-logout span { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 0 4px;
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-text strong { display: block; font-size: 15px; }
.brand-text span { font-size: 11px; color: var(--accent-hover); }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: #d8b4fe;
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-pill { display: flex; align-items: center; gap: 10px; padding: 4px; }
.admin-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.admin-meta strong { display: block; font-size: 12px; max-width: 175px; overflow: hidden; text-overflow: ellipsis; }
.admin-meta span { font-size: 11px; color: var(--text-muted); }

/* Main Area */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 66px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h2 { font-size: 17px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.view-container { padding: 24px; display: flex; flex-direction: column; gap: 20px; }

/* Cards, Grids, Tables */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 14px;
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 700; }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-head h3 { font-size: 15px; font-weight: 600; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 500; font-size: 12px; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
}
.pill-ok { background: var(--success-soft); color: #34d399; }
.pill-warn { background: var(--warn-soft); color: #fbbf24; }
.pill-danger { background: var(--danger-soft); color: #f87171; }
.pill-purple { background: var(--accent-soft); color: #c4b5fd; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-label { width: 80px; font-size: 12px; color: var(--text-muted); }
.bar-track { flex: 1; height: 9px; border-radius: 999px; background: var(--bg-elevated); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-hover)); }
.bar-val { width: 70px; text-align: right; font-size: 12px; font-weight: 600; }

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-body { display: flex; flex-direction: column; gap: 14px; }

.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
}

.mobile-only { display: none; }
@media (max-width: 900px) {
  .mobile-only { display: grid; }
  .sidebar { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 40; transition: left var(--transition); }
  .sidebar.open { left: 0; }
}