/* ── Admin Layout ───────────────────────────────────────────────────── */
.admin-layout {
  display: flex;
  min-height: calc(100vh - 57px);
}

.topbar-divider {
  color: var(--border);
  margin: 0 8px;
  font-weight: 300;
}

.topbar-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

/* ── Loading ───────────────────────────────────────────────────────── */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: 1.1rem;
  color: var(--text-muted);
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
.admin-sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  flex-shrink: 0;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

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

.nav-icon {
  font-size: 0.75rem;
  width: 16px;
  text-align: center;
}

/* ── Content area ──────────────────────────────────────────────────── */
.admin-content {
  flex: 1;
  padding: 32px;
  max-width: 1100px;
  overflow-x: auto;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

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

.tab-header h2 {
  margin: 0;
}

/* ── Stats grid ────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.per-app-stats {
  margin-bottom: 32px;
}

.per-app-stats h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.app-stat-pills {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.app-stat-pill {
  background: var(--surface);
  padding: 8px 16px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-stat-pill .count {
  font-weight: 700;
  color: var(--primary);
}

/* ── Pending queue ─────────────────────────────────────────────────── */
.pending-queue h3 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.pending-card {
  background: var(--surface);
  padding: 16px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pending-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pending-name {
  font-weight: 600;
}

.pending-email {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pending-message {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 4px;
}

.pending-actions {
  display: flex;
  gap: 8px;
}

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-success {
  background: #059669;
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #047857;
}

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

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

/* ── Filters ───────────────────────────────────────────────────────── */
.filters-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.filter-input,
.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
}

.filter-input {
  flex: 1;
  max-width: 350px;
}

.filter-input:focus,
.filter-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* ── Data tables ───────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

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

.data-table tbody tr:hover {
  background: rgba(99, 102, 241, 0.08);
}

/* ── Status badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-active { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-pending { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-suspended { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.badge-rejected { background: rgba(100, 116, 139, 0.2); color: #94a3b8; }

.badge-role {
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
  font-size: 0.7rem;
  margin-right: 4px;
  margin-bottom: 2px;
}

/* ── Pagination ────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 16px;
}

.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.85rem;
}

.page-btn:hover {
  background: var(--bg);
}

.page-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Invitations list ──────────────────────────────────────────────── */
.invitations-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.invitation-card {
  background: var(--surface);
  padding: 16px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.invitation-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.invitation-email {
  font-weight: 600;
}

.invitation-roles {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.invitation-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Profile section ───────────────────────────────────────────────── */
.profile-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 800px;
}

.form-card {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-card h3 {
  font-size: 1rem;
  margin-bottom: 16px;
}

.form-card label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
}

.form-card label:first-of-type {
  margin-top: 0;
}

.form-card input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
}

.form-card input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-card input:disabled {
  background: var(--bg);
  color: var(--text-muted);
}

.form-card .btn {
  margin-top: 20px;
  width: 100%;
}

.success-msg {
  background: rgba(21, 94, 117, 0.25);
  color: #4ade80;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

/* ── Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

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

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

.modal-header h3 {
  font-size: 1.1rem;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 24px;
}

.modal-body label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 14px;
}

.modal-body label:first-of-type {
  margin-top: 0;
}

.modal-body input,
.modal-body select,
.modal-body textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
}

.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.modal-body textarea {
  min-height: 80px;
  resize: vertical;
}

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

.modal-body .error-msg {
  margin-top: 12px;
  margin-bottom: 0;
}

/* ── Checkbox group ────────────────────────────────────────────────── */
.checkbox-group {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem !important;
  color: var(--text) !important;
  margin: 0 !important;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* ── App role editor ───────────────────────────────────────────────── */
.role-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 8px;
}

.role-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.role-row:last-child {
  margin-bottom: 0;
}

.role-app-name {
  font-weight: 600;
  font-size: 0.85rem;
  width: 80px;
}

.role-select {
  flex: 1;
}

/* ── Empty state ───────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .admin-layout {
    flex-direction: column;
  }

  .admin-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
  }

  .nav-item {
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 8px 16px;
  }

  .nav-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--primary);
  }

  .admin-content {
    padding: 20px;
  }

  .profile-section {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .filters-row {
    flex-direction: column;
  }

  .filter-input {
    max-width: 100%;
  }
}
