:root {
  --navy: #1e3a5f;
  --navy-light: #2a4f80;
  --gold: #c9973a;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #d1d9e3;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 8px;
  --shadow: 0 1px 6px rgba(30,58,95,0.10);
}

* { 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: 0.9rem;
  line-height: 1.5;
}

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

/* ── Nav ── */
.topnav {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 1rem; letter-spacing: 0.02em; }
.nav-links { display: flex; gap: 1rem; align-items: center; }
.nav-links a { color: rgba(255,255,255,0.85); font-size: 0.85rem; }
.nav-links a:hover { color: #fff; text-decoration: none; }
.nav-logout { color: rgba(255,255,255,0.6) !important; display:flex; align-items:center; }
.logout-dot {
  display: inline-block;
  width: 14px; height: 14px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  transition: border-color 0.15s;
}
.nav-logout:hover .logout-dot { border-color: #fff; }

/* ── Container ── */
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

/* ── Alerts ── */
.alert {
  border-radius: var(--radius);
  padding: 0.65rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-error   { background: #fee2e2; color: #991b1b; }

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.3rem; font-weight: 700; }
.back-link { font-size: 0.8rem; color: var(--muted); display: block; margin-bottom: 0.2rem; }

/* ── Search ── */
.search-form { display: flex; gap: 0.5rem; align-items: center; }
.search-form input { padding: 0.4rem 0.7rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.85rem; min-width: 220px; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

/* ── User meta ── */
.user-meta { display: flex; flex-direction: column; gap: 0.4rem; }
.meta-row { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.85rem; }
.meta-row > span:first-child { color: var(--muted); min-width: 120px; }

/* ── Section ── */
.section { margin-bottom: 2rem; }
.section h2 { font-size: 1rem; font-weight: 700; margin-bottom: 0.75rem; display: flex; align-items: center; gap: 0.5rem; }

/* ── Table ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
thead { background: #f8fafc; }
th, td { padding: 0.55rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
.row-revoked { opacity: 0.5; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; }
.muted { color: var(--muted); }
.mono { font-family: monospace; font-size: 0.8rem; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-premium { background: #fef3c7; color: #92400e; }
.badge-free    { background: #f1f5f9; color: var(--muted); }
.badge-active  { background: #dcfce7; color: #166534; }
.badge-revoked { background: #fee2e2; color: #991b1b; }
.badge-expired { background: #fef3c7; color: #92400e; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.84rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.85; text-decoration: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-ghost   { background: transparent; border-color: var(--border); color: var(--text); }
.btn-sm      { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-full    { width: 100%; justify-content: center; }

/* ── Form ── */
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.field textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem 1rem; padding-top: 1rem; }
.field-full { grid-column: 1 / -1; }

/* ── Grant form (details/summary) ── */
.grant-form { margin-top: 1rem; }
.grant-form summary { cursor: pointer; font-weight: 600; color: var(--navy); font-size: 0.88rem; }
.grant-form[open] summary { margin-bottom: 0.5rem; }

/* ── Login page ── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
}
.login-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 1.5rem;
  text-align: center;
}
.login-card .field { margin-bottom: 1rem; }
.login-card button { margin-top: 0.5rem; }

/* ── Stat cards ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
.stat-card--green { border-left: 4px solid var(--success); }
.stat-card--gold  { border-left: 4px solid var(--gold); }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--navy); line-height: 1.1; }
.stat-label { font-size: 0.78rem; color: var(--muted); margin-top: 0.25rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* ── TOTP setup ── */
.totp-uri {
  display: block;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  font-size: 0.78rem;
  word-break: break-all;
  font-family: monospace;
  user-select: all;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .search-form input { min-width: 0; width: 100%; }
  .search-form { width: 100%; }
}
