:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-raised: #22263a;
  --border: #2d3048;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-dim: rgba(99, 102, 241, 0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-dim: rgba(239, 68, 68, 0.12);
  --success: #22c55e;
  --warning: #f59e0b;
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #475569;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

*, *::before, *::after { 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);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

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

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 12px 16px;
  gap: 4px;
}

.sidebar-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
  padding: 0 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-logo span { color: var(--text-2); font-weight: 400; font-size: 12px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--primary-dim); color: var(--text); }
.nav-item.active { background: var(--primary-dim); color: var(--primary); font-weight: 600; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }
.nav-item.danger:hover { background: var(--danger-dim); color: var(--danger); }

.sidebar-spacer { flex: 1; }

.sidebar-user {
  padding: 10px 10px 0;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.sidebar-user .email { font-size: 12px; color: var(--text-2); word-break: break-all; }
.sidebar-user .role-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: var(--primary-dim);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 99px;
  margin-top: 4px;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */

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

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

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

label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus { border-color: var(--primary); }
input[type="file"] { color: var(--text-2); }

.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-raised); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-google {
  background: #fff;
  color: #333;
  border: 1px solid #ddd;
  width: 100%;
  justify-content: center;
  font-size: 14px;
}
.btn-google:hover { background: #f5f5f5; }

/* ── Tables ──────────────────────────────────────────────────────────────── */

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

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
}

.tag-global { background: rgba(99,102,241,0.15); color: var(--primary); }
.tag-tenant { background: rgba(34,197,94,0.12); color: var(--success); }
.tag-super_admin { background: rgba(245,158,11,0.15); color: var(--warning); }
.tag-admin { background: rgba(99,102,241,0.15); color: var(--primary); }
.tag-operator { background: rgba(148,163,184,0.12); color: var(--text-2); }
.tag-inactive { background: rgba(239,68,68,0.12); color: var(--danger); }
.tag-expired { background: rgba(234,179,8,0.15); color: #a16207; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 16px;
}

.alert-error { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.alert-success { background: rgba(34,197,94,0.1); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.alert-info { background: var(--primary-dim); color: var(--primary); border: 1px solid rgba(99,102,241,0.2); }

/* ── Auth pages ──────────────────────────────────────────────────────────── */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 28px;
}

.auth-divider {
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  margin: 16px 0;
  position: relative;
}

.auth-divider::before, .auth-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--border);
}

.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }

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

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

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Misc ────────────────────────────────────────────────────────────────── */

.page-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 24px;
}

.empty-state {
  text-align: center;
  color: var(--text-3);
  padding: 40px 0;
  font-size: 14px;
}

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

.otp-input {
  text-align: center;
  font-size: 24px;
  letter-spacing: 8px;
  font-weight: 700;
}

.qr-wrap { text-align: center; margin: 16px 0; }
.qr-wrap img { border-radius: var(--radius-sm); max-width: 200px; }

.uri-code {
  font-family: monospace;
  font-size: 11px;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  word-break: break-all;
  margin: 8px 0 16px;
}

.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
}

.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-bar .form-group { margin-bottom: 0; }

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

/* ── Enroll source tabs ─────────────────────────────────────────────────── */
.enroll-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.enroll-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  padding: 6px 14px 8px;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}

.enroll-tab:hover { color: var(--text-1); }

.enroll-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Webcam capture ─────────────────────────────────────────────────────── */
.webcam-wrap {
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 640px;
}

.webcam-wrap video,
.webcam-wrap img {
  width: 100%;
  max-width: 640px;
  display: block;
  border-radius: 8px;
}

/* ── Credentials display ──────────────────────────────────────────────────── */

.modal-wide { max-width: 560px; }
.modal-wide-lg { max-width: 720px; }

.modal-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin: 16px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.field-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-3);
}

.form-row-2 { display: flex; gap: 12px; }
.form-row-2 > * { flex: 1; }
.form-row-3 { display: flex; gap: 12px; }
.form-row-3 > * { flex: 1; }

.creds-notice {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: var(--radius-sm);
  color: var(--warning);
  font-size: 13px;
  padding: 8px 12px;
  margin-bottom: 16px;
}

.creds-grid { display: flex; flex-direction: column; gap: 12px; }

.creds-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.creds-field {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 10px;
  min-width: 0;
  user-select: all;
}

/* ── Device status tags ────────────────────────────────────────────────────── */

.tag-inactive {
  background: rgba(100, 116, 139, 0.15);
  color: #64748b;
}
.tag-online {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
}
.tag-offline {
  background: rgba(100, 116, 139, 0.12);
  color: #64748b;
}
.tag-ok {
  background: rgba(34, 197, 94, 0.12);
  color: #16a34a;
}
.tag-warn {
  background: rgba(234, 179, 8, 0.15);
  color: #a16207;
}
.tag-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #b91c1c;
}

/* ── Device sub-tabs ──────────────────────────────────────────────────────── */

.device-sub-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.device-sub-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px 8px;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.device-sub-tab:hover { color: var(--text); }

.device-sub-tab.active {
  border-bottom-color: var(--primary);
  color: var(--text);
}
