:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --border: #23232f;
  --text: #e4e4ed;
  --text-dim: #8888a0;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
}

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

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

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

/* ── Header ───────────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 { font-size: 18px; font-weight: 600; }

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.user-info span { color: var(--text-dim); font-size: 14px; }

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

main {
  flex: 1;
  min-width: 0;
  padding: 24px;
  max-width: 100%;
  overflow-y: auto;
}

.centered-main {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.dashboard-layout {
  display: flex;
  min-height: calc(100vh - 60px);
}

.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--text-dim);
  font-size: 16px;
}

.tab-loading {
  padding: 32px;
  text-align: center;
  color: var(--text-dim);
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-tenant {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-tenant h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}

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

.nav-group-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 16px 16px 6px;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 16px;
  font-size: 14px;
  color: var(--text-dim);
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border-radius: 0;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(99, 102, 241, 0.05);
}

.nav-item.active {
  color: var(--text);
  background: rgba(99, 102, 241, 0.08);
  border-left-color: var(--accent);
}

.hamburger-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}

.hamburger-btn:hover { background: var(--surface); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

.sidebar-overlay.open { display: block; }

/* ── Sections & Cards ─────────────────────────────────────────────────── */

.section { margin-bottom: 32px; }

.section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-header h3 { font-size: 16px; font-weight: 600; }

.card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Stats ────────────────────────────────────────────────────────────── */

.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  flex: 1;
  min-width: 140px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-value { font-size: 22px; font-weight: 600; }
.stat-detail { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

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

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-running { background: #22c55e20; color: var(--success); }
.badge-stopped { background: #ef444420; color: var(--danger); }
.badge-originator { background: #6366f120; color: var(--accent); }
.badge-role { background: #8888a020; color: var(--text-dim); }
.badge-perm { background: #6366f110; color: var(--accent); font-size: 11px; margin-left: 4px; }
.badge-warning { background: #f59e0b20; color: var(--warning); }
.badge-pending { background: #f59e0b20; color: var(--warning); }

.default-badge {
  background: #22c55e20;
  color: var(--success);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

.system-badge {
  background: #8888a015;
  color: var(--text-dim);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

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

button, .btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button:hover, .btn:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { background: #d97706; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost:hover { background: var(--surface); }

.btn-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

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

input[type="text"], input[type="number"], select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
}

select { cursor: pointer; }
select option { background: var(--bg); color: var(--text); }
input[type="text"]::placeholder, input[type="number"]::placeholder { color: var(--text-dim); }

textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

textarea::placeholder { color: var(--text-dim); }

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-form input, .inline-form select { flex: 1; }

.form-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.form-section h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Toggle ───────────────────────────────────────────────────────────── */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child { border-bottom: none; }

.toggle-label { display: flex; flex-direction: column; gap: 2px; }
.toggle-label span:first-child { font-weight: 500; }
.toggle-label span:last-child { font-size: 13px; color: var(--text-dim); }

.toggle-group {
  display: flex;
  flex-direction: column;
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: 0.2s;
}

.toggle .slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ── Device & member lists ────────────────────────────────────────────── */

.device-list { list-style: none; }

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.device-item:last-child { border-bottom: none; }
.device-name { font-weight: 500; }
.device-ip { color: var(--text-dim); font-family: monospace; font-size: 13px; }

.online-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.online-dot.on { background: var(--success); }
.online-dot.off { background: var(--text-dim); }

.health-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.health-dot.healthy { background: var(--success); }
.health-dot.unhealthy { background: var(--danger); }

.member-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.member-item:last-child { border-bottom: none; }

.member-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.member-info img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.invitation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.invitation-item:last-child { border-bottom: none; }

.approval-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.approval-item:last-child { border-bottom: none; }

.user-group { margin-bottom: 16px; }

.user-group-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Roles & permissions ──────────────────────────────────────────────── */

.role-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--bg);
}

.role-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.role-card-header strong { font-size: 14px; }

.perm-chip {
  display: inline-block;
  padding: 2px 8px;
  margin: 2px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.perm-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.perm-chip.readonly { cursor: default; }

/* ── Code blocks ──────────────────────────────────────────────────────── */

.code-block {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  color: var(--success);
  overflow-x: auto;
  cursor: pointer;
  position: relative;
  display: block;
  white-space: pre-wrap;
  word-break: break-all;
}

.code-block:hover::after {
  content: 'click to copy';
  position: absolute;
  right: 8px;
  top: 8px;
  color: var(--text-dim);
  font-size: 11px;
}

pre {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  color: var(--text);
  overflow-x: auto;
  white-space: pre-wrap;
}

/* ── Audit log ────────────────────────────────────────────────────────── */

.audit-item {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.audit-item:last-child { border-bottom: none; }
.audit-time { color: var(--text-dim); font-size: 12px; }
.audit-actor { color: var(--accent); font-weight: 500; }
.audit-action { color: var(--text); }

/* ── Empty state ──────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--text-dim);
}

.hidden { display: none; }

/* ── Toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  animation: fadeIn 0.2s;
}

.toast-error {
  border-color: var(--danger);
  color: var(--danger);
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } }

/* ── Lockdown banner ──────────────────────────────────────────────────── */

.lockdown-banner {
  background: #f59e0b20;
  border: 1px solid #f59e0b40;
  color: var(--warning);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 500;
}

/* ── Wizard ───────────────────────────────────────────────────────────── */

.wizard-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.wizard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 600px;
  width: 100%;
}

.wizard-card h2 { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.wizard-card p { color: var(--text-dim); font-size: 14px; margin-bottom: 16px; }

.wizard-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  gap: 8px;
}

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

#login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  gap: 24px;
}

#login-page h1 { font-size: 32px; }
#login-page p { color: var(--text-dim); max-width: 400px; text-align: center; }

#login-page form {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 400px;
}

#login-page form input { flex: 1; }

/* ── Join page ────────────────────────────────────────────────────────── */

.join-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.join-card {
  max-width: 500px;
  width: 100%;
  text-align: center;
}

.join-card h1 {
  font-size: 24px;
  margin-bottom: 12px;
}

/* ── Lists & tables ───────────────────────────────────────────────────── */

.item-list { list-style: none; }

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.item-row:last-child { border-bottom: none; }
.item-row-wrap { flex-wrap: wrap; }
.item-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item-name { font-weight: 500; overflow-wrap: anywhere; }
.item-detail { font-size: 13px; color: var(--text-dim); overflow-wrap: anywhere; }
.item-full { flex-basis: 100%; }

.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.badge-stack { display: inline-flex; flex-wrap: wrap; gap: 4px; }

/* ── Access / operator ────────────────────────────────────────────────── */

.access-main {
  display: flex;
  justify-content: center;
  padding: 48px 24px;
}

.access-page {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.access-page h1 { font-size: 24px; }
.access-page .section { margin-bottom: 0; margin-top: 8px; }
.access-page.text-center .btn-group { justify-content: center; }

.copy-field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.copy-field input { font-size: 13px; }

.steps {
  margin: 12px 0 0 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
}

.confirm-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #ef444460;
  border-radius: 8px;
  background: #ef444410;
}

.confirm-panel h4 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }

.inline-alert {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #f59e0b40;
  border-radius: 6px;
  background: #f59e0b15;
  color: var(--text);
  font-size: 14px;
}

.inline-alert ul { margin: 8px 0 0 20px; }

.suspended-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  border: 1px solid #ef444460;
  border-radius: 8px;
  background: #ef444415;
  font-size: 14px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Utility classes ──────────────────────────────────────────────────── */

.text-dim { color: var(--text-dim); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.mono { font-family: 'SF Mono', 'Fira Code', monospace; }
.help-text { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.ml-4 { margin-left: 4px; }
.ml-8 { margin-left: 8px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.w-100 { width: 100px; flex: none !important; }
.w-140 { width: 140px; flex: none !important; }
.w-160 { width: 160px; flex: none !important; }
.w-180 { width: 180px; flex: none !important; }
.w-220 { width: 220px; flex: none !important; }
.justify-center { justify-content: center; }
.text-center { text-align: center; }
.inline-block { display: inline-block; }
.break-all { word-break: break-all; }

/* ── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .hamburger-btn { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.open { transform: translateX(0); }
  main { width: 100%; }
  .stats-row { flex-direction: column; }
  .stat-card { min-width: unset; }
}
