:root {
  --bg: #0b0d12;
  --bg-elevated: #12151c;
  --bg-soft: #181c27;
  --border: #2a3142;
  --text: #eef1f8;
  --muted: #9aa3b8;
  --primary: #5b5cff;
  --primary-hover: #7475ff;
  --danger: #ff5b6e;
  --danger-soft: rgba(255, 91, 110, 0.12);
  --success: #3ecf8e;
  --success-soft: rgba(62, 207, 142, 0.12);
  --warning: #f5b942;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(91, 92, 255, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(62, 207, 142, 0.08), transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
}

/* Auth layout */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(440px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 32px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #5b5cff, #8b5cf6);
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}
.auth-card .lead {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 0.95rem;
}
.auth-switch {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

/* App shell */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 10; }
}

.sidebar {
  background: rgba(18, 21, 28, 0.92);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  backdrop-filter: blur(10px);
}
.sidebar .brand { margin-bottom: 24px; padding: 0 8px; }
.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav a, .nav button.linkish {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  text-decoration: none;
}
.nav a:hover, .nav button.linkish:hover {
  background: var(--bg-soft);
  color: var(--text);
  text-decoration: none;
}
.nav a.active {
  background: rgba(91, 92, 255, 0.14);
  color: #cfd0ff;
  font-weight: 600;
}
.sidebar-footer {
  margin-top: 28px;
  padding: 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
.sidebar-footer strong {
  display: block;
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 2px;
}

.main {
  padding: 28px clamp(16px, 3vw, 36px) 48px;
  min-width: 0;
}
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-header h2 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}
.page-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-body { padding: 18px; }
.panel + .panel { margin-top: 18px; }

.form-grid {
  display: grid;
  gap: 14px;
}
.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 700px) {
  .form-grid.two { grid-template-columns: 1fr; }
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}
label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  grid-auto-flow: column;
}
label.checkbox input { width: auto; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 92, 255, 0.2);
}
textarea { min-height: 90px; resize: vertical; }

.roles-grid {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.roles-grid label {
  color: var(--text);
  font-size: 0.92rem;
}
.roles-grid .hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: 22px;
  margin-top: -4px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #222738; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger {
  background: var(--danger-soft);
  color: #ff8a97;
  border-color: rgba(255, 91, 110, 0.25);
}
.btn-danger:hover { background: rgba(255, 91, 110, 0.22); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
.btn-sm { padding: 6px 10px; font-size: 0.86rem; }

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.filter-field {
  flex: 1 1 260px;
  min-width: min(100%, 260px);
  max-width: 480px;
  margin: 0;
}
.filter-field input[type="search"] {
  margin-top: 4px;
}

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(0,0,0,0.15);
  white-space: nowrap;
  user-select: none;
}
th.sortable {
  padding: 0;
}
th.sortable .th-sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 12px 14px;
  margin: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: left;
}
th.sortable .th-sort-btn:hover {
  color: var(--text);
  background: rgba(91, 92, 255, 0.08);
}
th.sortable.is-sorted .th-sort-btn {
  color: #cfd0ff;
}
th.sortable .sort-indicator {
  font-size: 0.65rem;
  opacity: 0.85;
  min-width: 0.75em;
}
tr:last-child td { border-bottom: 0; }
tr:hover td { background: rgba(255,255,255,0.015); }

.mono { font-family: var(--mono); font-size: 0.88rem; }
.muted { color: var(--muted); }
.truncate {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(91, 92, 255, 0.14);
  color: #cfd0ff;
  margin: 0 4px 4px 0;
}
.badge.ok { background: var(--success-soft); color: #7be8b4; }
.badge.warn { background: rgba(245, 185, 66, 0.14); color: #f5b942; }
.badge.danger { background: var(--danger-soft); color: #ff8a97; }

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.92rem;
}
.alert-error {
  background: var(--danger-soft);
  border: 1px solid rgba(255, 91, 110, 0.3);
  color: #ffb3bc;
}
.alert-success {
  background: var(--success-soft);
  border: 1px solid rgba(62, 207, 142, 0.3);
  color: #9beec8;
}
.alert-info {
  background: rgba(91, 92, 255, 0.12);
  border: 1px solid rgba(91, 92, 255, 0.28);
  color: #cfd0ff;
}

.empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  width: min(520px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.modal h3 { margin: 0 0 8px; }
.modal p { margin: 0 0 16px; color: var(--muted); }
.modal .btn-row { justify-content: flex-end; margin-top: 8px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .label { color: var(--muted); font-size: 0.8rem; }
.stat .value { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.03em; }

.copy-btn { margin-left: 6px; }

.hidden { display: none !important; }
