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

:root {
  --bg:       #f8fafc;
  --surface:  #ffffff;
  --border:   #e2e8f0;
  --text:     #1e293b;
  --text-sub: #64748b;
  --primary:  #6366f1;
  --primary-h:#4f46e5;
  --danger:   #ef4444;
  --success:  #22c55e;
  --warning:  #f59e0b;
  --radius:   14px;
  --shadow:      0 2px 10px rgba(15,23,42,.05);
  --shadow-hover:0 10px 28px -8px rgba(99,102,241,.20);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0f172a;
    --surface:  #1e293b;
    --border:   #334155;
    --text:     #f1f5f9;
    --text-sub: #94a3b8;
    --shadow:      0 2px 10px rgba(0,0,0,.3);
    --shadow-hover:0 10px 28px -8px rgba(99,102,241,.32);
  }
}
:root[data-theme="dark"] {
  --bg: #0f172a; --surface: #1e293b; --border: #334155;
  --text: #f1f5f9; --text-sub: #94a3b8;
}
:root[data-theme="light"] {
  --bg: #f8fafc; --surface: #ffffff; --border: #e2e8f0;
  --text: #1e293b; --text-sub: #64748b;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px; height: 56px;
}
.topbar-logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.topbar-back {
  display: flex; align-items: center; gap: 5px;
  color: var(--text-sub); font-size: 13px; text-decoration: none;
  padding: 5px 8px; border-radius: 6px; transition: background .15s;
}
.topbar-back:hover { background: var(--border); color: var(--text); }
.topbar-sep { color: var(--border); font-size: 16px; }
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-spacer { flex: 1; }
.btn-sm {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 500;
  border: none; cursor: pointer; transition: background .15s, transform .1s;
}
.btn-sm:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }

/* Layout */
.page { max-width: 900px; margin: 0 auto; padding: 28px 20px 60px; }

/* Page header */
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.page-header p  { font-size: 14px; color: var(--text-sub); }

/* Section */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--text-sub); text-transform: uppercase; letter-spacing: .05em; }

/* User cards */
.users-list { display: flex; flex-direction: column; gap: 10px; }
.user-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden; transition: border-color .15s, box-shadow .15s;
}
.user-card:hover { box-shadow: var(--shadow-hover); }
.user-card:has(.user-body.open) { border-color: var(--primary); }

.user-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; cursor: pointer; user-select: none;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: #e0e7ff; color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
@media (prefers-color-scheme: dark) { .user-avatar { background: #312e81; } }
:root[data-theme="dark"] .user-avatar { background: #312e81; }

.user-info { flex: 1; min-width: 0; }
.user-email { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta  { font-size: 12px; color: var(--text-sub); margin-top: 1px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-admin   { background: #ede9fe; color: #5b21b6; }
.badge-viewer  { background: #e0f2fe; color: #0369a1; }
.badge-pending { background: #fef9c3; color: #854d0e; }
:root[data-theme="dark"] .badge-admin   { background: #2e1065; color: #c4b5fd; }
:root[data-theme="dark"] .badge-viewer  { background: #0c4a6e; color: #7dd3fc; }
:root[data-theme="dark"] .badge-pending { background: #422006; color: #fde68a; }
@media (prefers-color-scheme: dark) {
  .badge-admin   { background: #2e1065; color: #c4b5fd; }
  .badge-viewer  { background: #0c4a6e; color: #7dd3fc; }
  .badge-pending { background: #422006; color: #fde68a; }
}

.user-chevron {
  color: var(--text-sub); transition: transform .2s; flex-shrink: 0;
}
.user-card:has(.user-body.open) .user-chevron { transform: rotate(180deg); }

.user-actions { display: flex; align-items: center; gap: 6px; }
.btn-icon {
  width: 30px; height: 30px; border-radius: 6px; border: none; cursor: pointer;
  background: none; color: var(--text-sub); display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--border); color: var(--danger); }

/* Access body */
.user-body { display: none; border-top: 1px solid var(--border); }
.user-body.open { display: block; }

.access-panel { padding: 16px 16px 18px; }
.access-title { font-size: 12px; font-weight: 600; color: var(--text-sub); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 12px; }
.access-grid { display: flex; flex-direction: column; gap: 8px; }
.access-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg);
  cursor: pointer; transition: border-color .15s;
}
.access-item:has(input:checked) { border-color: var(--primary); background: #eef2ff; }
:root[data-theme="dark"] .access-item:has(input:checked) { background: #1e1b4b; }
@media (prefers-color-scheme: dark) { .access-item:has(input:checked) { background: #1e1b4b; } }
.access-item input[type=checkbox] { accent-color: var(--primary); width: 15px; height: 15px; flex-shrink: 0; }
.access-item-info { flex: 1; min-width: 0; }
.access-item-label { font-size: 13px; font-weight: 500; }
.access-item-sub   { font-size: 11px; color: var(--text-sub); }
.access-empty { font-size: 13px; color: var(--text-sub); padding: 4px 0; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-sub); font-size: 14px; }

/* Skeleton */
.skeleton {
  background: var(--border); border-radius: 6px; animation: pulse 1.4s ease infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 12px; padding: 24px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-title  { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.modal-sub    { font-size: 13px; color: var(--text-sub); margin-bottom: 20px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--text-sub); margin-bottom: 5px; }
.field input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg); color: var(--text); font-size: 14px; outline: none; transition: border-color .15s;
}
.field input:focus { border-color: var(--primary); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #f1f5f9; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 200; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* Spinner */
.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
