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

:root {
  --sidebar-w: 220px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --sidebar-active: #3b82f6;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.15);
}

body { font-family: system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ── Login ──────────────────────────────────────────────────────────────── */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  box-shadow: var(--shadow-lg);
}

.login-card h1 { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.login-card .subtitle { color: var(--text-muted); margin-bottom: 32px; font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 16px; }

/* ── Layout ─────────────────────────────────────────────────────────────── */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}

.sidebar-brand {
  padding: 24px 20px 16px;
  border-bottom: 1px solid #1e293b;
}
.sidebar-brand span { display: block; color: #f1f5f9; font-weight: 700; font-size: 16px; }
.sidebar-brand small { color: #475569; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }

.sidebar nav { flex: 1; padding: 12px 0; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: background .15s, color .15s;
  font-size: 13.5px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.sidebar nav a.active { background: var(--sidebar-hover); color: #fff; border-left-color: var(--sidebar-active); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid #1e293b;
}
.sidebar-footer button {
  width: 100%;
  background: transparent;
  color: var(--sidebar-text);
  border: 1px solid #334155;
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.sidebar-footer button:hover { background: #1e293b; color: #e2e8f0; }

.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: 1100px;
}

/* ── Page header ────────────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 20px; font-weight: 600; }
.page-header .left { display: flex; align-items: center; gap: 12px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

.btn-primary, button.primary { background: var(--primary); color: #fff; }
.btn-primary:hover, button.primary:hover { background: var(--primary-hover); }

.btn-secondary, button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover, button.secondary:hover { background: var(--bg); }

.btn-danger, button.danger { background: var(--danger); color: #fff; }
.btn-danger:hover, button.danger:hover { background: var(--danger-hover); }

.btn-ghost, button.ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover, button.ghost:hover { background: var(--bg); color: var(--text); }

.btn-back { background: transparent; color: var(--text-muted); border: none; padding: 4px 0; font-size: 13px; }
.btn-back:hover { color: var(--text); }

button:disabled { opacity: .5; cursor: not-allowed; }

/* Default button style */
button:not([class]) {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
button:not([class]):hover { background: var(--bg); }

/* ── Forms ──────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text); }
.field small { color: var(--text-muted); font-size: 11.5px; }

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.toggle-row label { font-size: 13px; font-weight: 500; }

input[type="checkbox"] {
  width: 36px; height: 20px;
  appearance: none;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  position: relative;
  transition: background .2s;
}
input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
input[type="checkbox"]:checked { background: var(--primary); }
input[type="checkbox"]:checked::after { left: 18px; }

.form-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}

/* ── Table ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--bg);
  padding: 10px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

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

td.empty { text-align: center; color: var(--text-muted); font-style: italic; padding: 24px; }

/* ── Badges ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  background: #dbeafe;
  color: #1d4ed8;
  margin-right: 3px;
}
.badge-active   { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #dcfce7; color: #166534; }
.badge-disabled { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #f1f5f9; color: #64748b; }
.badge-warn     { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #fef9c3; color: #854d0e; }
.badge-critical { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #fee2e2; color: #991b1b; }

/* ── Group detail sections ──────────────────────────────────────────────── */

.section { margin-top: 28px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-header h3 { font-size: 16px; font-weight: 600; }

/* ── Modal ──────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: transparent; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; padding: 0; line-height: 1; }
.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }

.modal-footer {
  padding: 16px 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
}

/* ── Confirm dialog ─────────────────────────────────────────────────────── */

.confirm-text { color: var(--text-muted); line-height: 1.5; }
.confirm-text strong { color: var(--text); }

/* ── Notifications ──────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #f1f5f9;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Impersonation banner ───────────────────────────────────────────────── */

.impersonation-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 300;
  background: #f59e0b;
  color: #1c1917;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.impersonation-banner strong { font-weight: 700; }
.impersonation-banner button {
  background: #1c1917;
  color: #fef3c7;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}
.impersonation-banner button:hover { background: #292524; }

.app.impersonating { padding-top: 44px; }
.app.impersonating .sidebar { top: 44px; }
.app.impersonating .content { padding-top: 32px; }

[x-cloak] { display: none !important; }
