:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1c2026;
  --muted: #697282;
  --accent: #2459d6;
  --accent-soft: #e8efff;
  --ok: #1a7f4b;
  --ok-soft: #e3f5eb;
  --warn: #9a5b00;
  --danger: #c0352b;
  --danger-soft: #fdecea;
  --ms: #2459d6;
  --google: #1a7f4b;
  --shadow: 0 1px 2px rgba(20, 24, 31, .06), 0 4px 16px rgba(20, 24, 31, .05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --border: #2b313a;
    --text: #e6e9ee;
    --muted: #8e97a6;
    --accent: #6e9bff;
    --accent-soft: #1f2a44;
    --ok: #4cc38a;
    --ok-soft: #173326;
    --warn: #e0a84a;
    --danger: #ff7b70;
    --danger-soft: #3a1d1b;
    --ms: #6e9bff;
    --google: #4cc38a;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #8f5bd6); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.admin-name { color: var(--muted); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.live.off .dot { background: var(--danger); }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.btn {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 7px 14px;
  border: 1px solid var(--accent); background: var(--accent); color: #fff; font-weight: 500;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.icon { padding: 4px 10px; }
.btn:disabled { opacity: .5; cursor: default; }

.login { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { width: 100%; max-width: 420px; padding: 28px; }
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.provider-buttons { display: flex; flex-direction: column; gap: 10px; margin: 20px 0; }
.provider-buttons a {
  display: flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none;
  padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); color: var(--text); font-weight: 500;
}
.provider-buttons a:hover { background: var(--bg); }
.bootstrap { border-top: 1px solid var(--border); padding-top: 16px; }
.bootstrap label { display: block; font-weight: 500; margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
input[type=search], input[type=password] {
  font: inherit; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-width: 0;
}
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.error { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 8px 12px; margin-top: 12px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 28px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.accent .stat-value { color: var(--accent); }

.toolbar { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar input[type=search] { width: 260px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.spacer { flex: 1; }

.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; }
.users th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.users td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users tbody tr { cursor: pointer; transition: background .15s; }
.users tbody tr:hover { background: var(--bg); }
.users tbody tr:last-child td { border-bottom: none; }
.users .num { text-align: right; }
.users tr.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px;
}
.user-name { font-weight: 500; }
.user-email { color: var(--muted); font-size: 12px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); color: var(--muted); }
.badge.microsoft { color: var(--ms); border-color: currentColor; }
.badge.google { color: var(--google); border-color: currentColor; }
.count {
  display: inline-flex; min-width: 32px; justify-content: center; padding: 2px 10px; border-radius: 999px;
  font-weight: 650; font-variant-numeric: tabular-nums; background: var(--bg); color: var(--muted);
}
.count.on { background: var(--ok-soft); color: var(--ok); }
.chev { color: var(--muted); text-align: right; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: center; padding: 8px; }

.activity { margin-top: 20px; padding: 0 16px; }
.activity summary { cursor: pointer; padding: 14px 0; font-weight: 500; }
.audit { list-style: none; padding: 0; margin: 0 0 12px; }
.audit li { display: flex; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 13px; }
.audit time { color: var(--muted); min-width: 140px; font-variant-numeric: tabular-nums; }
.audit .ev { font-weight: 500; min-width: 150px; }

.drawer { position: fixed; inset: 0; background: rgba(10, 12, 16, .35); z-index: 20; display: flex; justify-content: flex-end; }
.drawer-panel { width: min(560px, 100%); height: 100%; overflow-y: auto; background: var(--surface); padding: 24px; border-left: 1px solid var(--border); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 18px 0; font-size: 13px; }
.drawer-meta dt { color: var(--muted); }
.drawer-meta dd { margin: 0; word-break: break-all; }
.drawer h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 10px; }
.devices { display: flex; flex-direction: column; gap: 10px; }
.device { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.device.inactive { opacity: .62; }
.device-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.device-name { font-weight: 600; }
.device-grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; margin-top: 8px; font-size: 12px; }
.device-grid span:nth-child(odd) { color: var(--muted); }
.status { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.status.active { background: var(--ok-soft); color: var(--ok); }
.status.expired, .status.signed_out { background: var(--bg); color: var(--muted); }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); max-width: 360px; animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  main { padding: 16px; }
  .toolbar input[type=search] { width: 100%; }
  .users th:nth-child(3), .users td:nth-child(3) { display: none; }
}
