:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #181c25;
  --surface-3: #1f2430;
  --border: #232837;
  --border-strong: #2f3547;
  --text: #e7eaf2;
  --muted: #8b93a7;
  --faint: #5d6579;
  --accent: #7c9cff;
  --accent-soft: rgb(124 156 255 / 0.14);
  --green: #3ddc97;
  --green-soft: rgb(61 220 151 / 0.13);
  --amber: #ffb454;
  --amber-soft: rgb(255 180 84 / 0.13);
  --red: #ff6b6b;
  --red-soft: rgb(255 107 107 / 0.13);
  --gray-soft: rgb(139 147 167 / 0.14);
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  background: rgb(11 13 18 / 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: 0.01em; }
.brand img { width: 26px; height: 26px; }
.spacer { flex: 1; }
.page { max-width: 1180px; margin: 0 auto; padding: 24px 24px 64px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 0 14px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 8px;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b0d12; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #93adff; }
.btn-danger { color: var(--red); border-color: rgb(255 107 107 / 0.35); }
.btn-danger:hover:not(:disabled) { background: var(--red-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-small { min-height: 28px; padding: 0 10px; font-size: 12.5px; }
.icon-btn { width: 32px; height: 32px; padding: 0; background: transparent; border: 1px solid transparent; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }
.stat {
  text-align: left; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color 0.12s, background 0.12s;
}
.stat:hover { border-color: var(--border-strong); }
.stat[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.stat-value { font-size: 26px; font-weight: 650; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.search { position: relative; flex: 1; max-width: 420px; }
.search input {
  width: 100%; height: 38px; padding: 0 12px 0 36px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
}
.search input::placeholder { color: var(--faint); }
.search svg { position: absolute; left: 11px; top: 11px; width: 16px; height: 16px; color: var(--faint); pointer-events: none; }
.count { color: var(--muted); font-size: 13px; }

/* ---------- table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  position: sticky; top: 0;
  padding: 10px 16px; text-align: left; white-space: nowrap;
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
th button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
th button:hover { color: var(--text); }
th button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
tbody tr:last-child td { border-bottom: 0; }
.cell-user { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.cell-user b { display: block; font-weight: 600; }
.cell-user span { color: var(--muted); font-size: 12.5px; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.soon { color: var(--amber); }

.avatar {
  --hue: 220;
  flex: none; display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: hsl(var(--hue) 40% 24%); color: hsl(var(--hue) 80% 82%);
  font-weight: 650; font-size: 14px;
}
.avatar-lg { width: 48px; height: 48px; font-size: 19px; }
img.avatar { object-fit: cover; background: var(--surface-3); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-active { color: var(--green); background: var(--green-soft); }
.badge-pending { color: var(--amber); background: var(--amber-soft); }
.badge-expired { color: var(--muted); background: var(--gray-soft); }
.badge-revoked { color: var(--red); background: var(--red-soft); }
.tag {
  display: inline-block; min-width: 84px; padding: 1px 8px; border-radius: 6px; text-align: center;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft);
}
.tag-off { color: var(--faint); background: var(--gray-soft); }

/* ---------- drawer ---------- */
.overlay { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / 0.55); opacity: 0; transition: opacity 0.18s; }
.overlay.open { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(560px, 100vw); overflow-y: auto;
  background: var(--bg); border-left: 1px solid var(--border-strong);
  transform: translateX(100%); transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer.open { transform: none; }
.drawer-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 14px; padding: 18px 20px;
  background: rgb(11 13 18 / 0.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 17px; line-height: 1.25; }
.drawer-head p { margin: 0; color: var(--muted); font-size: 13px; }
.drawer-body { padding: 20px; display: grid; gap: 20px; }

.section h3 {
  margin: 0 0 10px; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.facts { display: grid; grid-template-columns: 1fr 1fr; }
.fact { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.fact:nth-child(odd) { border-right: 1px solid var(--border); }
.fact:nth-last-child(-n + 2) { border-bottom: 0; }
.fact dt { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.fact dd { margin: 0; font-weight: 550; }
.fact dd small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

.row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.row + .row { border-top: 1px solid var(--border); }
.row-main { flex: 1; min-width: 0; }
.row-main b { font-weight: 550; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main small { color: var(--muted); font-size: 12px; }
.row-empty { padding: 16px 14px; color: var(--muted); }
.keybox { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; }
.keybox code { flex: 1; overflow-wrap: anywhere; }

.reset-note { padding: 10px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.reset-note b { color: var(--text); font-weight: 600; }
.reset-note.warn b { color: var(--amber); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.timeline { list-style: none; margin: 0; padding: 4px 14px; }
.timeline li { position: relative; padding: 9px 0 9px 20px; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 16px; width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); }
.timeline li + li { border-top: 1px solid var(--border); }
.timeline small { color: var(--muted); }

/* ---------- modal + toast ---------- */
dialog.modal {
  width: min(440px, calc(100vw - 32px)); padding: 22px;
  color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px;
}
dialog.modal::backdrop { background: rgb(0 0 0 / 0.6); }
dialog.modal h3 { margin: 0 0 8px; font-size: 16px; }
dialog.modal p { margin: 0 0 18px; color: var(--muted); }
dialog.viewer { width: min(720px, calc(100vw - 32px)); }
dialog.viewer pre {
  margin: 0 0 16px; padding: 14px; max-height: 55vh; overflow: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  font: 12.5px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; left: 50%; bottom: 24px; z-index: 50; display: grid; gap: 8px; transform: translateX(-50%); }
.toast {
  padding: 10px 16px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border-strong);
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.4); animation: pop 0.18s ease-out;
}
.toast.error { border-color: rgb(255 107 107 / 0.5); color: var(--red); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); padding: 32px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.login-card img { width: 44px; height: 44px; margin-bottom: 14px; }
.login-card h1 { margin: 0 0 8px; font-size: 20px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-card code { padding: 2px 8px; border-radius: 6px; background: var(--surface-3); font-family: var(--mono); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .hide-md { display: none; }
}
@media (max-width: 560px) {
  .page { padding: 16px 16px 48px; }
  .topbar { padding: 10px 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .toolbar { flex-wrap: wrap; }
  .search { max-width: none; flex-basis: 100%; }
  .facts { grid-template-columns: 1fr; }
  .fact:nth-child(odd) { border-right: 0; }
  .fact:nth-last-child(2) { border-bottom: 1px solid var(--border); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
