:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-2: #0f172a;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #111827;
  --text: #f9fafb;
  --muted: #9ca3af;
  --border: #243041;
  --accent: #60a5fa;
  --accent-2: #e5e7eb;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #0b1220;
    --panel: #111827;
    --text: #f9fafb;
    --muted: #9ca3af;
    --border: #243041;
    --accent: #60a5fa;
    --accent-2: #e5e7eb;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.brand, .auth-brand, .mini-user { display: flex; align-items: center; gap: 12px; }
.brand-mark, .avatar {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c3aed); color: white; font-weight: 700;
}
.brand-name { font-weight: 700; }
.brand-sub, .muted, .stat-label, .timeline-meta, .mini-user-email { color: var(--muted); font-size: 0.875rem; }
.nav { display: grid; gap: 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px;
  color: var(--text); border: 1px solid transparent;
}
.nav a.active, .nav a:hover { background: rgba(37, 99, 235, 0.08); border-color: var(--border); }
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; position: sticky; top: 0; z-index: 10;
  background: color-mix(in oklab, var(--bg) 85%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.content { padding: 24px; }
.stack { display: grid; gap: 18px; }
.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; }
.card, .stat-card, .auth-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
}
.card { padding: 18px; }
.stat-card { padding: 16px; }
.stat-value { font-size: 1.8rem; font-weight: 700; margin-top: 6px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.page-heading h1, .auth-card h1 { margin: 0; font-size: 2rem; }
.page-heading p, .auth-card p { margin: 6px 0 0; color: var(--muted); }
.actions, .topbar-actions, .row-actions { display: flex; gap: 10px; align-items: center; }
.btn, .icon-btn, .link-btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; font: inherit;
}
.btn-primary { background: var(--accent); color: white; border-color: transparent; }
.btn-secondary { background: transparent; }
.btn-danger { background: var(--danger); color: white; border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-full { width: 100%; }
.icon-btn { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; }
.filters, .form-grid { display: grid; gap: 14px; }
label { display: grid; gap: 8px; font-size: 0.95rem; }
input, select, textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
}
.check-row { display: flex; align-items: center; gap: 10px; }
.check-row input { width: auto; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
.badge { display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 999px; font-size: 0.8rem; border: 1px solid var(--border); }
.badge-active, .badge-success { background: rgba(22, 163, 74, 0.1); color: var(--success); }
.badge-expired, .badge-warning { background: rgba(217, 119, 6, 0.1); color: var(--warning); }
.badge-revoked, .badge-banned, .badge-danger { background: rgba(220, 38, 38, 0.1); color: var(--danger); }
.badge-disabled, .badge-inactive, .badge-secondary { background: rgba(107, 114, 128, 0.1); color: var(--muted); }
.badge-suspended { background: rgba(217, 119, 6, 0.1); color: var(--warning); }
.alert { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); }
.alert-success { background: rgba(22, 163, 74, 0.1); }
.alert-error { background: rgba(220, 38, 38, 0.1); }
.alert-info { background: rgba(37, 99, 235, 0.1); }
.dl-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 0; }
.dl-grid dt { color: var(--muted); font-size: 0.85rem; }
.dl-grid dd { margin: 4px 0 0; font-weight: 600; }
.code-box {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border: 1px dashed var(--border); border-radius: 14px;
}
.copy-btn, .link-btn { background: transparent; border: none; color: var(--accent); cursor: pointer; padding: 0; }
.timeline { display: grid; gap: 14px; }
.timeline-item { display: flex; gap: 12px; align-items: flex-start; }
.timeline-dot { width: 10px; height: 10px; margin-top: 6px; border-radius: 999px; background: var(--accent); }
.muted-links { display: flex; justify-content: space-between; gap: 12px; font-size: 0.95rem; }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-shell { width: min(460px, 100%); }
.auth-card { padding: 28px; display: grid; gap: 20px; }
.permission-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.empty-state { min-height: 45vh; display: grid; place-items: center; text-align: center; gap: 12px; padding: 24px; }
.empty-icon { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; background: rgba(37, 99, 235, 0.08); font-size: 1.5rem; }
.toast-stack { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 10px; z-index: 50; }
.toast {
  min-width: 240px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; box-shadow: var(--shadow);
}
.sidebar-toggle-hidden .sidebar { transform: translateX(-100%); }
.sidebar-toggle-hidden .app-shell { grid-template-columns: 0 1fr; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.compact { gap: 12px; }
.stack.compact { gap: 12px; }
.prose pre { overflow: auto; padding: 12px; border-radius: 12px; background: rgba(0,0,0,0.04); }

@media (max-width: 1100px) {
  .stats-grid, .grid-4, .permission-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .grid-2, .stats-grid, .grid-3, .grid-4, .permission-grid { grid-template-columns: 1fr; }
  .page-heading { align-items: flex-start; flex-direction: column; }
}
