:root {
  --bg: #020617;
  --surf: #0f172a;
  --surf2: #131f37;
  --border: rgba(51, 65, 85, 0.5);
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;
  --accent: #34d399;
  --accent-dim: rgba(52, 211, 153, 0.15);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.15);
  --amber: #fbbf24;
  --amber-dim: rgba(251, 191, 36, 0.15);
  --radius: 10px;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  margin: 0;
}

a { color: inherit; text-decoration: none; }

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

.btn {
  background: var(--surf2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}
.btn:hover { background: #1c2b4a; }
.btn-accent { background: var(--accent); color: #022c22; border-color: var(--accent); font-weight: 600; }
.btn-accent:hover { background: #2ed198; }
.btn-danger { background: transparent; color: var(--red); border-color: rgba(248,113,113,0.4); }
.btn-danger:hover { background: var(--red-dim); }

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
}
.icon-btn:hover { background: var(--surf2); color: var(--text); }

input[type="text"], input[type="password"], input[type="search"] {
  background: var(--surf2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-height: 36px;
  font-size: 14px;
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.card {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-admin { background: var(--amber-dim); color: var(--amber); }
.badge-pending { background: var(--red-dim); color: var(--red); }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.spinner-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

/* Layout */
#app-shell { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surf);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 40;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}
#sidebar.open { transform: translateX(0); }

#sidebar-brand {
  padding: 18px 16px;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
}

#sidebar-nav { flex: 1; padding: 8px; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text2);
  margin-bottom: 2px;
  min-height: 36px;
}
.nav-item:hover { background: var(--surf2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }

#sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }

#backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 30;
  opacity: 0;
  transition: opacity 0.2s ease;
}
#backdrop.open { display: block; opacity: 1; }

#main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  min-height: 56px;
}

#burger { display: none; }

#content { padding: 20px; flex: 1; }

@media (min-width: 768px) {
  #sidebar { position: sticky; transform: none; }
  #main { margin-left: 0; }
  #backdrop { display: none !important; }
}

@media (max-width: 767px) {
  #burger { display: inline-flex; }
  #content { padding: 14px; }
  body.drawer-open { overflow: hidden; }
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
}
.tile:hover { border-color: var(--accent); }
.tile-num { font-size: 24px; font-weight: 700; margin-top: 4px; }

.placeholder {
  color: var(--text3);
  text-align: center;
  padding: 60px 20px;
}

/* Users */
.user-cards { display: flex; flex-direction: column; gap: 10px; }
.user-card { background: var(--surf); border: 1px solid var(--border); border-radius: var(--radius); }
.user-card-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surf2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--accent);
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-username { color: var(--text2); font-size: 12px; }
.user-actions { display: flex; gap: 6px; flex-shrink: 0; }
.user-card-expanded {
  border-top: 1px solid var(--border);
  padding: 14px;
}
.user-created { color: var(--text3); font-size: 12px; margin-top: 10px; }

.tree-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; font-size: 12px; color: var(--text2); }
.tree-legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.dot-explicit { background: var(--accent); }
.dot-inherited { background: rgba(52, 211, 153, 0.35); }
.dot-amber { background: var(--amber); }

.section-tree { display: flex; flex-direction: column; gap: 2px; }
.tree-node { }
.tree-node-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.tree-node-row:hover { background: var(--surf2); }
.tree-node-row.state-explicit { background: var(--accent-dim); color: var(--accent); }
.tree-node-row.state-inherited { background: rgba(52, 211, 153, 0.08); color: var(--text); }
.tree-node-row.state-amber { background: var(--amber-dim); color: var(--amber); }
.tree-children { margin-left: 20px; border-left: 1px solid var(--border); padding-left: 8px; }
.tree-note { font-size: 11px; color: var(--text3); margin-left: 26px; margin-bottom: 4px; }

.extra-keys { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.extra-keys-title { font-size: 12px; color: var(--text3); margin-bottom: 6px; }
.extra-key-chip {
  font-family: monospace;
  font-size: 12px;
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  margin: 2px 4px 2px 0;
  display: inline-block;
  cursor: pointer;
}
.extra-key-chip:hover { border-color: var(--red); color: var(--red); }

/* Access overview */
.access-node { margin-bottom: 14px; }
.access-node-header { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 6px; }
.access-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-left: 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px;
}
.chip-explicit { background: var(--accent-dim); color: var(--accent); }
.chip-inherited { background: rgba(52, 211, 153, 0.1); color: var(--text2); }
.chip-pending { background: var(--surf2); color: var(--text3); }
.chip-none { color: var(--text3); font-size: 12px; margin-left: 20px; }
.admins-banner {
  background: var(--amber-dim);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.admins-banner-title { color: var(--amber); font-weight: 600; margin-bottom: 6px; font-size: 13px; }

/* Confirm modal */
#confirm-modal[hidden] { display: none; }
#confirm-modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
#confirm-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
#confirm-box { position: relative; width: 100%; max-width: 340px; margin: 0 16px; }
#confirm-message { margin-bottom: 16px; }
#confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
