/* Admin Portal — professional dashboard UI */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');



:root {
  --ink: #0f172a;
  --ink-soft: #334155;
  --paper: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-ring: rgba(37, 99, 235, .18);
  --ok: #15803d;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --bad: #b91c1c;
  --bad-soft: #fef2f2;
  --admin: #7c3aed;
  --admin-soft: #f5f3ff;
  --header-h: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-lg: 0 4px 6px rgba(15, 23, 42, .04), 0 20px 40px rgba(15, 23, 42, .08);
}

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

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  margin: 0;
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }

/* ---- Header ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(124, 58, 237, .35);
}

.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--ink);
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.header-spacer { flex: 1; }

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

a.back-link {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
}

a.back-link:hover {
  background: var(--paper);
  color: var(--ink);
}

.who-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  background: var(--admin-soft);
  border: 1px solid rgba(124, 58, 237, .15);
  border-radius: 999px;
}

.who-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--admin);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.who-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.who-role {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--admin);
}

.logout {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.logout:hover { background: var(--paper); color: var(--ink); }

/* ---- Main layout ---- */
.admin-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.page-intro {
  margin-bottom: 24px;
}

.page-intro h2 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.03em;
  color: var(--ink);
}

.page-intro p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---- Gate cards (login / setup) ---- */
.gate-wrap {
  min-height: calc(100vh - var(--header-h) - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}

.gate-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--admin-soft);
  color: var(--admin);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.gate-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--ink);
}

.gate-card .lead {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

/* ---- Dashboard cards ---- */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(#fff, #fafbfc);
}

.panel-head-left {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-width: 0;
}

.panel-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.panel-icon.users { background: var(--accent-soft); color: var(--accent); }
.panel-icon.keys { background: var(--warn-soft); color: var(--warn); }
.panel-icon.courses { background: var(--ok-soft); color: var(--ok); }

.panel-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.01em;
}

.panel-desc {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.panel-body { padding: 20px 22px; }

.panel-foot {
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}

/* ---- Forms ---- */
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 14px 0 6px;
}

label:first-child { margin-top: 0; }

label code, .label-key {
  font-weight: 400;
  color: var(--muted);
  font-size: 11px;
}

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--muted);
  border-radius: 6px;
}
.pw-eye:hover { color: var(--ink); background: var(--paper); }

button {
  padding: 9px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  transition: background .15s, border-color .15s;
}

button:hover { background: var(--paper); color: var(--ink); }

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

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

button.danger {
  color: var(--bad);
  border-color: #fecaca;
  background: #fff;
}

button.danger:hover { background: var(--bad-soft); }

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

.row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 12px;
}

.row > div { flex: 1; min-width: 140px; }

.add-user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

.add-user-grid .btn-cell {
  display: flex;
  align-items: flex-end;
}

.muted { color: var(--muted); font-size: 12px; line-height: 1.45; }

.banner {
  background: var(--warn-soft);
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--warn);
  margin-bottom: 20px;
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

tr:last-child td { border-bottom: none; }

th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

tbody tr:hover td { background: #fafbfc; }

td select {
  padding: 6px 10px;
  font-size: 12px;
  min-width: 100px;
}

.table-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  white-space: nowrap;
}

.table-actions button {
  padding: 6px 12px;
  font-size: 12px;
}

a.table-link {
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
}

a.table-link:hover { text-decoration: underline; }

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  text-transform: lowercase;
}

.pill.admin { background: var(--admin-soft); color: var(--admin); }
.pill.creator { background: var(--ok-soft); color: var(--ok); }
.pill.viewer { background: var(--accent-soft); color: var(--accent); }
.pill.draft { background: var(--paper); color: var(--muted); }
.pill.approved, .pill.voiced, .pill.published { background: var(--ok-soft); color: var(--ok); }
.pill.awaiting { background: var(--warn-soft); color: var(--warn); }

.prov-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
}

.prov-status strong { color: var(--ink); font-weight: 600; }

.keys-grid {
  display: grid;
  gap: 0;
}

.keys-grid label { margin-top: 16px; }
.keys-grid label:first-child { margin-top: 0; }

.empty-state {
  text-align: center;
  padding: 32px 20px;
  color: var(--muted);
  font-size: 13px;
}

/* ---- Toast & busy ---- */
#msg {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--ink);
  color: #fff;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  display: none;
  max-width: min(420px, 92vw);
  z-index: 40;
  box-shadow: var(--shadow-lg);
}

#busy {
  position: fixed;
  inset: 0;
  background: rgba(241, 245, 249, .75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 35;
  backdrop-filter: blur(4px);
}

#busy.open { display: flex; }

#busy .panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 32px;
  box-shadow: var(--shadow-lg);
  min-width: min(360px, 90vw);
  text-align: center;
}

#busy .spin {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--admin);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: aga-spin .7s linear infinite;
}

#busy .label { color: var(--ink); font-size: 16px; font-weight: 600; margin: 0 0 6px; }
#busy .hint { color: var(--muted); font-size: 13px; margin: 0; }

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

body.is-busy { cursor: progress; }

@media (max-width: 720px) {
  .site-header { padding: 0 16px; flex-wrap: wrap; height: auto; min-height: var(--header-h); padding-top: 10px; padding-bottom: 10px; }
  .admin-main { padding: 16px; }
  .panel-head { flex-direction: column; }
  .add-user-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  #busy .spin { animation: none; border-top-color: var(--admin); }
}
