:root {
  color-scheme: light;
  --bg: #fbf8fc;
  --surface: #ffffff;
  --text: #1f1a22;
  --muted: #716777;
  --line: #e5dde8;
  --topbar: #08070c;
  --topbar-line: #221726;
  --topbar-muted: #d9ccdd;
  --accent: #c217a7;
  --accent-dark: #861176;
  --accent-soft: #fff0fb;
  --warm: #f0b85c;
  --success: #0d7c66;
  --success-dark: #075746;
  --danger: #a8324a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

a { color: inherit; }

.topbar {
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--topbar-line);
  background: var(--topbar);
  box-shadow: 0 12px 28px rgba(31, 26, 34, 0.08);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: auto;
  height: 34px;
  max-width: min(184px, 38vw);
}

nav {
  display: flex;
  align-items: center;
  gap: 18px;
}

nav a, nav .link-button {
  color: var(--topbar-muted);
  text-decoration: none;
  background: transparent;
  border: 0;
  padding: 6px 0;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

nav a:hover, nav .link-button:hover {
  color: #ffffff;
  border-bottom-color: var(--warm);
}

.user-chip {
  display: grid;
  gap: 1px;
  max-width: 260px;
  padding: 5px 10px;
  border: 1px solid rgba(240, 184, 92, 0.45);
  border-radius: 6px;
  color: #fff;
  text-decoration: none;
  line-height: 1.15;
}

.user-chip strong,
.user-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip strong {
  font-size: 13px;
}

.user-chip span {
  color: var(--topbar-muted);
  font-size: 12px;
}

.user-chip:hover {
  border-color: var(--warm);
}

.shell {
  width: min(1180px, calc(100vw - 40px));
  margin: 34px auto 80px;
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.admin-head {
  margin-bottom: 14px;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 20px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.admin-tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  text-decoration: none;
  font-weight: 800;
}

.admin-tabs a:hover,
.admin-tabs a.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.identity-summary {
  margin: 12px 0 0;
  color: var(--muted);
}

.identity-summary code {
  color: var(--text);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: clamp(30px, 5vw, 48px); line-height: 1.02; }
h2 { font-size: 18px; margin-bottom: 16px; }

.heading-help,
.with-help {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.heading-help {
  margin-bottom: 16px;
}

.help-tip,
.help-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 1px solid #e7b4dc;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.help-tip {
  position: relative;
  cursor: help;
}

.help-tip:focus {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(194, 23, 167, 0.16);
}

.help-tip::after {
  content: attr(aria-label);
  position: absolute;
  left: 50%;
  top: calc(100% + 9px);
  z-index: 20;
  width: 260px;
  max-width: 70vw;
  padding: 10px 12px;
  border: 1px solid var(--topbar-line);
  border-radius: 8px;
  background: var(--topbar);
  color: #fff;
  box-shadow: 0 14px 34px rgba(31, 26, 34, 0.24);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  text-transform: none;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.help-tip:hover::after,
.help-tip:focus::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.activation-cell {
  min-width: 210px;
}

.action-help {
  margin-left: 8px;
  vertical-align: middle;
}

.action-help::after {
  left: auto;
  right: 0;
  transform: translateY(-4px);
}

.action-help:hover::after,
.action-help:focus::after {
  transform: translateY(0);
}

.help-callout {
  margin: 14px 0 18px;
  padding: 12px 14px;
  border: 1px solid #efd1e8;
  border-radius: 8px;
  background: var(--accent-soft);
}

.help-callout summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.help-callout summary::-webkit-details-marker {
  display: none;
}

.help-callout p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.flash {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 20px;
  background: #fff;
  color: var(--text);
  overflow-wrap: anywhere;
}

.flash-success {
  border-color: #b7dccd;
  background: #eef8f3;
  color: var(--success-dark);
}

.flash-error {
  border-color: #efc4c0;
  background: #fff2f1;
  color: var(--danger);
}

.compact { max-width: 820px; }

.grid {
  display: grid;
  gap: 20px;
}

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

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

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-weight: 600;
}

label.inline {
  flex-direction: row;
  align-items: center;
}

input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(194, 23, 167, 0.12);
  outline: 0;
}

button, .primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 8px 13px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

button:hover, .primary:hover { background: var(--accent-dark); }
button.danger { background: var(--danger); }
button.success { background: var(--success); }
button.success:hover { background: var(--success-dark); }
button.secondary {
  background: #fff3d3;
  color: #6f4700;
}
button.secondary:hover {
  background: #ffe3a1;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

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

.validity-form {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 260px;
}

.validity-form input {
  width: 76px;
  min-height: 36px;
}

.form-hint {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin-bottom: 6px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.summary-strip div {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffafd;
}

.summary-strip strong {
  display: block;
  font-size: 24px;
}

.summary-strip span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.user-create-grid {
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) minmax(200px, 1.4fr) minmax(120px, 0.8fr) minmax(170px, 1fr) minmax(170px, 1fr) minmax(120px, 0.7fr) auto;
  gap: 12px;
  align-items: end;
}

.user-edit-grid {
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) minmax(200px, 1.4fr) minmax(120px, 0.8fr) minmax(170px, 1fr) minmax(120px, 0.7fr) auto;
  gap: 12px;
  align-items: end;
}

.user-create-grid {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffafd;
}

.user-list {
  display: grid;
  gap: 0;
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.user-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.user-secondary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  justify-content: flex-end;
}

.password-reset {
  display: flex;
  gap: 8px;
}

.password-reset input {
  width: 210px;
}

.checkbox-stack {
  display: grid;
  gap: 7px;
  align-self: center;
}

.checkbox-stack.compact-checks {
  align-self: end;
}

.checkbox-field {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.checkbox-field input {
  width: 16px;
  min-height: 16px;
}

.form-actions,
.user-row-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
}

.account-grid {
  align-items: start;
}

.self-password-hint {
  margin: 0;
}

.client-groups {
  display: grid;
  gap: 18px;
  margin-top: 16px;
}

.client-group {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.client-group:first-child {
  border-top: 0;
  padding-top: 0;
}

.client-group-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 10px;
}

.client-group h3 {
  margin: 0 0 5px;
  font-size: 18px;
}

.client-group p {
  margin: 0;
  color: var(--muted);
}

.client-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.client-stats span {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge-demo {
  border-color: #ffd889;
  background: #fff7df;
  color: #865700;
}

.meta {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px 18px;
}

.meta dt { color: var(--muted); font-weight: 700; }
.meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.token-box {
  margin-top: 10px;
  display: grid;
  gap: 5px;
  color: var(--muted);
}

.token-box code {
  display: block;
  padding: 10px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--text);
  overflow-wrap: anywhere;
}

.alert {
  background: #fff2f1;
  color: var(--danger);
  border: 1px solid #efc4c0;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.login-panel {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 34px;
}

.login-panel h1 {
  margin-bottom: 24px;
}

.auth-layout {
  min-height: calc(100vh - 126px);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 420px);
  gap: 38px;
  align-items: center;
}

.auth-copy {
  max-width: 620px;
}

.auth-copy p:not(.eyebrow) {
  color: var(--muted);
  font-size: 17px;
  line-height: 1.55;
}

.auth-panel,
.auth-form {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}

.auth-form {
  margin: 0 auto;
}

.auth-form h1,
.auth-panel h2 {
  margin-bottom: 18px;
}

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

.mt-3 {
  margin-top: 16px;
}

.text-muted {
  color: var(--muted);
  line-height: 1.5;
}

.alert-success {
  background: #eef8f3;
  color: var(--success-dark);
  border-color: #b7dccd;
}

.btn {
  width: fit-content;
}

@media (max-width: 760px) {
  .topbar { padding: 0 16px; }
  .brand-logo { height: 29px; max-width: 132px; }
  nav { gap: 10px; }
  .user-chip {
    max-width: 132px;
    padding: 4px 7px;
  }
  .user-chip span {
    display: none;
  }
  .shell { width: min(100% - 24px, 1180px); margin-top: 22px; }
  .page-head { align-items: start; flex-direction: column; }
  .grid.two { grid-template-columns: 1fr; }
  .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .client-group-head {
    flex-direction: column;
  }
  .client-stats {
    justify-content: flex-start;
  }
  .auth-layout { grid-template-columns: 1fr; align-items: start; }
  .auth-panel, .auth-form { width: 100%; padding: 22px; }
  .help-tip::after { width: 220px; max-width: 76vw; }
  .activation-cell { min-width: 230px; }
  .validity-form { min-width: 280px; }
  .user-create-grid,
  .user-edit-grid {
    grid-template-columns: 1fr;
  }
  .form-actions,
  .user-row-actions,
  .user-secondary-actions {
    justify-content: flex-start;
  }
  .password-reset {
    flex-direction: column;
    width: 100%;
  }
  .password-reset input {
    width: 100%;
  }
  table { display: block; overflow-x: auto; }
}
