:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222637;
  --border: #2e3349;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 0 20px 24px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-brand span { color: var(--accent); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  font-weight: 500;
}

.nav-item:hover, .nav-item.active {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}

.nav-item svg { flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 0;
  border-top: 1px solid var(--border);
}

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  background: var(--surface);
  gap: 12px;
}

.topbar-title { font-weight: 600; font-size: 15px; flex: 1; }

.content { padding: 28px; flex: 1; overflow-y: auto; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.card-value { font-size: 28px; font-weight: 700; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.muted-small { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.muted-cell { color: var(--text-muted); }
.empty-cell { text-align: center; color: var(--text-muted); padding: 32px; }

.role-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.role-stack > div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.data-panel {
  padding: 0;
  overflow: hidden;
  margin-bottom: 24px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}

.panel-sub {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

.table-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) repeat(3, minmax(140px, 1fr));
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(34, 38, 55, .55);
}

.table-toolbar-audits {
  grid-template-columns: minmax(240px, 1.5fr) repeat(5, minmax(130px, 1fr));
}

.table-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 0;
}

.table-toolbar span {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.table-toolbar input,
.table-toolbar select {
  min-height: 36px;
}

.table-wrap-inner {
  border: 0;
  border-radius: 0;
  overflow-x: auto;
}

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  padding: 11px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-basic    { background: rgba(148,163,184,.15); color: #94a3b8; }
.badge-power    { background: rgba(59,130,246,.15);  color: #60a5fa; }
.badge-superadmin { background: rgba(168,85,247,.15); color: #c084fc; }
.badge-active   { background: rgba(34,197,94,.15);  color: #4ade80; }
.badge-inactive { background: rgba(239,68,68,.15);  color: #f87171; }
.badge-used     { background: rgba(148,163,184,.1); color: #64748b; }
.badge-expired  { background: rgba(239,68,68,.1);   color: #f87171; }
.badge-valid    { background: rgba(34,197,94,.15);  color: #4ade80; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}

.btn:hover { text-decoration: none; opacity: .9; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: rgba(239,68,68,.15); color: #f87171; border: 1px solid rgba(239,68,68,.25); }
.btn-success { background: rgba(34,197,94,.15); color: #4ade80; border: 1px solid rgba(34,197,94,.25); }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* Forms */
.form-group { margin-bottom: 18px; }
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-muted); }
input, select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select option { background: var(--surface2); }

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13px;
}
.alert-error   { background: rgba(239,68,68,.1);  border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.1);  border: 1px solid rgba(34,197,94,.3); color: #86efac; }
.alert-info    { background: rgba(59,130,246,.1); border: 1px solid rgba(59,130,246,.3); color: #93c5fd; }

/* Magic link box */
.link-box {
  font-family: monospace;
  font-size: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  word-break: break-all;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.link-box span { flex: 1; }

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px;
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title { font-size: 18px; font-weight: 700; }

/* Detail sections */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.detail-field { display: flex; flex-direction: column; gap: 4px; }
.detail-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.detail-value { font-size: 14px; }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 12px;
  margin-top: 24px;
}

/* Divider */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Checkbox */
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input[type=checkbox] { width: auto; }

@media (max-width: 1180px) {
  .table-toolbar,
  .table-toolbar-audits {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}
