:root {
  color-scheme: dark;
  --background: #050505;
  --surface: #0c0d0e;
  --surface-raised: #111316;
  --surface-hover: #15171a;
  --line: #282b2f;
  --line-strong: #4a4e54;
  --text: #f4f5f6;
  --muted: #92979e;
  --quiet: #5a5f65;
  --available: #8dd7a8;
  --warning: #d9bd7a;
  --danger: #df9a9a;
  --danger-surface: rgba(130, 43, 43, 0.16);
  --focus: #b8d8ff;
  --radius: 10px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--background); }

body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at 50% -20%, rgba(255, 255, 255, 0.07), transparent 38rem), var(--background);
  color: var(--text);
  font-family: Montserrat, "Helvetica Neue", Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  width: 1px; height: 1px; padding: 0; position: absolute; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Notice pages rendered by the server */
.tts-page { display: grid; place-items: center; padding: 24px 16px; }
.tts-card {
  width: min(480px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.tts-card h1 { margin: 0 0 12px; font-size: 1.5rem; font-weight: 600; }
.tts-card p { color: var(--muted); }
.tts-eyebrow { margin: 0 0 8px; color: var(--quiet) !important; font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; }
.tts-actions { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.tts-button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 18px;
  border: 1px solid var(--text); border-radius: 999px;
  background: var(--text); color: var(--background);
  font-weight: 600; text-decoration: none; cursor: pointer;
}
.tts-link { color: var(--muted); }

/* Application shell */
.shell { width: min(960px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 64px; }
.narrow { width: min(460px, calc(100% - 32px)); }
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 88px; border-bottom: 1px solid var(--line); margin-bottom: 32px;
}
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }
.brand img { display: block; width: 168px; height: auto; max-height: 40px; object-fit: contain; }
.brand span { padding-left: 12px; border-left: 1px solid var(--line-strong); color: var(--muted); font-weight: 600; letter-spacing: 0.02em; }
.header-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

h1 { margin: 0 0 8px; font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 600; letter-spacing: -0.01em; }
h2 { margin: 0 0 4px; font-size: 1.1rem; font-weight: 600; }
.lead { margin: 0 0 24px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.panel {
  margin: 0 0 20px; padding: 24px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.panel > p:first-of-type { margin-top: 4px; }
.panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
/* Sections after the form on an admin's user page: Actions, Sessions, and
   the link panel an action shows between them. */
.section-title { margin-top: 24px; }
.action-output > .panel { margin: 16px 0 0; }

/* Forms */
form { margin: 0; }
.field { display: grid; gap: 6px; margin: 0 0 16px; }
.field label, .field legend { font-size: 0.9rem; font-weight: 600; }
.field .hint { color: var(--muted); font-size: 0.85rem; }
fieldset.field { border: 0; padding: 0; }
input[type="text"], input[type="password"], input[type="email"], input[type="search"], input:not([type]) {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-raised);
}
input[inputmode="numeric"] { font-variant-numeric: tabular-nums; letter-spacing: 0.25em; font-size: 1.2rem; }
input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 0.85rem; }
.checkbox { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 10px; }
.checkbox input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--text); }
.checkbox span small { display: block; color: var(--muted); }

button { min-height: 40px; padding: 8px 18px; border-radius: 999px; cursor: pointer; font-weight: 600; }
button.primary { border: 1px solid var(--text); background: var(--text); color: var(--background); }
button.secondary { border: 1px solid var(--line-strong); background: transparent; }
button.secondary:hover { background: var(--surface-hover); }
button.danger { border: 1px solid var(--danger); background: transparent; color: var(--danger); }
button.link { min-height: auto; padding: 0; border: 0; background: none; color: var(--muted); text-decoration: underline; font-weight: 400; }
button:disabled { opacity: 0.5; cursor: progress; }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.buttons + .checkbox { margin-top: 20px; }

.alert {
  margin: 0 0 16px; padding: 12px 14px; border-radius: 8px;
  border: 1px solid var(--danger); background: var(--danger-surface); color: var(--text);
}
.alert.info { border-color: var(--line-strong); background: var(--surface-raised); }
.alert.success { border-color: var(--available); background: rgba(80, 160, 110, 0.12); }
.notice { color: var(--muted); font-size: 0.9rem; border-top: 1px solid var(--line); padding-top: 16px; margin-top: 24px; }

/* Enrolment */
.qr { display: grid; justify-items: start; gap: 12px; margin: 0 0 16px; }
.qr img { width: 200px; height: 200px; border-radius: 8px; background: #fff; padding: 8px; image-rendering: pixelated; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95rem; word-break: break-all; color: var(--muted); }
/* A recovery code (XXXX-XXXX-XXXX-XXXX) is 19ch wide and never breaks: two
   columns when a whole code fits in each, otherwise one. The 50% term caps it
   at two (half the gap, plus a pixel of slack). */
.codes {
  display: grid; gap: 8px 16px;
  grid-template-columns: repeat(auto-fit, minmax(max(19ch, calc(50% - 9px)), 1fr));
  margin: 0 0 16px; padding: 16px; list-style: none;
  border: 1px dashed var(--line-strong); border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95rem;
}
.codes li { white-space: nowrap; }
.steps { margin: 0 0 20px; padding-left: 20px; color: var(--muted); }

/* Avatars */
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 48px; height: 48px; border-radius: 50%; overflow: hidden;
  background: var(--surface-raised); border: 1px solid var(--line-strong);
  font-weight: 600; letter-spacing: 0.04em;
}
.avatar.large { width: 72px; height: 72px; font-size: 1.4rem; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.identity { display: flex; gap: 16px; align-items: center; margin: 0 0 24px; }

/* Lists and tables */
.list { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list li:first-child { border-top: 0; }
.tag { display: inline-block; margin-left: 8px; padding: 2px 10px; border: 1px solid var(--line-strong); border-radius: 999px; font-size: 0.8rem; color: var(--muted); }
.tag.active { border-color: var(--available); color: var(--available); }
.tag.warning { border-color: var(--warning); color: var(--warning); }
.tag.danger { border-color: var(--danger); color: var(--danger); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; text-align: left; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; border-top: 0; }
tr.selectable { cursor: pointer; }
tr.selectable:hover td { background: var(--surface-hover); }
td button { min-height: 32px; padding: 4px 12px; }
.nowrap { white-space: nowrap; }
/* Long JSON may break anywhere rather than squeeze the other columns. */
td.detail { min-width: 14rem; overflow-wrap: anywhere; }

.tabs { display: flex; gap: 8px; margin: 0 0 20px; }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--background); border-color: var(--text); }

dialog {
  width: min(460px, calc(100% - 32px)); padding: 24px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

@media (max-width: 560px) {
  .panel, .tts-card { padding: 18px; }
  .site-header { min-height: 72px; }
  .brand img { width: 120px; }
}

@media print {
  body { background: #fff; color: #000; }
  .site-header, .buttons, .no-print { display: none !important; }
  .codes { border-color: #000; }
}
