/* gate — the fleet's identity service. Mobile-first, cool-slate sibling of the
   other apps' warm palette (same token names, same skeleton, its own hue).

   Self-contained on purpose: no font file, no CDN, no remote image, not one
   byte of JavaScript. gate serves script-src 'none', and a page that fetches
   nothing cannot be broken by what it fetched. Anything here that would need JS
   (a show-password eye, a copy button) is simply absent — see SPECS.md. */

:root {
  --bg: #f2f5f9;
  --card: #ffffff;
  --ink: #1d2430;
  --muted: #64708a;
  --line: #dfe5ee;
  --brand: #3d5a8f;          /* slate blue */
  --brand-ink: #ffffff;
  --accent: #3d7a62;         /* green: a settled state */
  --danger: #ab3131;
  --warn: #8a5a12;
  --shadow: 0 1px 2px rgba(29, 36, 48, 0.06), 0 8px 24px rgba(29, 36, 48, 0.06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181f;
    --card: #1c2230;
    --ink: #e8edf6;
    --muted: #97a3b8;
    --line: #2c3546;
    --brand: #8fabdd;
    --brand-ink: #131822;
    --accent: #74b596;
    --danger: #e58b8b;
    --warn: #dcae63;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  /* System stack only — nothing to download, nothing to block. */
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Every focusable thing keeps a ring, and it is the same ring everywhere: this
   page is sometimes driven entirely by keyboard, and a password manager tabs
   through it. */
:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

/* A link, not a script: one tab to skip the header. */
.skip {
  position: absolute;
  left: -9999px;
  top: 0;
}
.skip:focus {
  left: 8px;
  top: 8px;
  z-index: 30;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  text-decoration: none;
}

/* --- Header ----------------------------------------------------------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--brand);
}
.brand-sub { color: var(--muted); font-size: 0.85rem; }

/* --- Layout ----------------------------------------------------------- */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 56px;
}
/* The single-card pages get a reading column instead of the admin's width. */
.container.narrow { max-width: 420px; }

.page-title { margin: 4px 0 6px; font-size: 1.45rem; letter-spacing: -0.01em; }
.section-title { margin: 26px 0 10px; font-size: 1.1rem; }
.card-title { margin: 0 0 8px; font-size: 1.1rem; }
.sub { margin: 0 0 18px; color: var(--muted); font-size: 0.95rem; }
.muted { color: var(--muted); }
.meta { margin: 0; color: var(--muted); font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.85rem; }

/* --- Cards ------------------------------------------------------------ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin: 0 0 14px;
}
.card:last-child { margin-bottom: 0; }
.stack > * + * { margin-top: 14px; }

/* --- Fields ----------------------------------------------------------- */
.field { display: block; margin: 0 0 14px; }
.field:last-child { margin-bottom: 0; }
.field > span { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 4px; }
.field > .hint { margin: 6px 0 0; }

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  /* 16px and ~46px tall: below that iOS zooms on focus, and this is read
     standing up with one thumb. */
  padding: 12px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }

/* Six digits, read out loud from a phone: wide spacing, tabular figures. */
.code-input {
  font-size: 1.35rem;
  letter-spacing: 0.35em;
  font-variant-numeric: tabular-nums;
}

/* --- Buttons ---------------------------------------------------------- */
.btn {
  display: inline-block;
  width: 100%;
  min-height: 48px;
  padding: 13px 18px;
  border: 2px solid transparent;
  border-radius: 12px;
  font: inherit;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
form > .btn { margin-top: 20px; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:active { filter: brightness(0.95); }

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn-ghost:active { background: var(--line); }

/* Destructive actions must be told apart with the colour turned off: a dashed
   frame, small caps and a warning glyph do that; red alone would not. */
.btn-danger {
  background: transparent;
  border: 2px dashed var(--danger);
  color: var(--danger);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.88rem;
}
.btn-danger:active { background: color-mix(in srgb, var(--danger) 12%, var(--card)); }

/* Inline forms sitting side by side once there is room for them. */
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.actions > * { margin: 0; }
@media (min-width: 620px) {
  .actions { flex-direction: row; flex-wrap: wrap; }
  .actions > * { flex: 1 1 200px; }
  .actions .btn { width: 100%; }
}

/* --- Banners ---------------------------------------------------------- */
.alert, .notice {
  border-radius: 10px;
  padding: 11px 13px;
  margin: 0 0 14px;
}
.alert {
  background: color-mix(in srgb, var(--danger) 12%, var(--card));
  border: 1px solid var(--danger);
  color: var(--danger);
}
.notice {
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border: 1px solid var(--accent);
  color: var(--ink);
}
.warnings {
  background: color-mix(in srgb, var(--warn) 12%, var(--card));
  border: 1px solid var(--warn);
}
.warnings ul { margin: 0; padding-left: 22px; }
.warnings li + li { margin-top: 6px; }

/* --- Unconfirmed revocations ------------------------------------------ */
/* The loudest block on the page, and the only one that earns it: somebody is
   still signed in somewhere. Loud by shape (thick bar, uppercase badge, glyph),
   not by hue alone. */
.pending {
  border: 1px solid var(--danger);
  border-left: 7px solid var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, var(--card));
}
.pending-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 4px; }
.pending-head h2 { margin: 0; font-size: 1.1rem; }
.badge-alert {
  border: 2px solid currentColor;
  border-radius: 6px;
  padding: 1px 6px;
  color: var(--danger);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.pending-list { list-style: none; margin: 12px 0 0; padding: 0; }
.pending-item { padding: 10px 0; border-top: 1px solid color-mix(in srgb, var(--danger) 30%, var(--line)); }
.pending-item:first-child { border-top: 0; }
.pending-what { font-weight: 650; }
.pending-item dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 6px 0 0;
  font-size: 0.85rem;
}
.pending-item dt { color: var(--muted); }
.pending-item dd { margin: 0; overflow-wrap: anywhere; }

/* --- The one-shot enrolment link -------------------------------------- */
/* No copy button: that needs JavaScript. So the URL is selectable text, and one
   tap selects the whole of it. */
.once { border: 1px solid var(--brand); }
.copyable {
  display: block;
  margin: 8px 0 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  user-select: all;
}

/* --- Second factor ---------------------------------------------------- */
.qr {
  display: block;
  width: 100%;
  max-width: 220px;
  margin: 12px auto;
  /* The QR is dark-on-light whatever the theme, so it stays scannable in dark
     mode: a QR inverted by a filter is a QR most phones refuse. */
  background: #ffffff;
  padding: 8px;
  border-radius: 10px;
}
.qr svg { display: block; width: 100%; height: auto; }
.secret {
  display: block;
  margin: 8px 0 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
}

/* --- Accounts --------------------------------------------------------- */
.account-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}
.account-mail {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.tag {
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 0.75rem;
  font-weight: 650;
  white-space: nowrap;
}
/* Each state carries a word, so the tags do not depend on their colour. */
.tag-ok { color: var(--accent); }
.tag-wait { color: var(--warn); }
.tag-off { color: var(--muted); border-style: dashed; }

.sub-title {
  margin: 16px 0 6px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.grants { list-style: none; margin: 0; padding: 0; }
.grant {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}
.grant:first-child { border-top: 0; }
.grant-main { min-width: 0; display: flex; flex-direction: column; }
.grant-app { font-weight: 650; }
.grant-roles { color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.grant form { margin: 0 0 0 auto; }
/* A small square button next to a grant, still a 44px tap target. */
.btn-small {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 12px;
  border: 2px dashed var(--danger);
  border-radius: 10px;
  background: transparent;
  color: var(--danger);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  cursor: pointer;
}
.btn-small:active { background: color-mix(in srgb, var(--danger) 12%, var(--card)); }

/* --- Sessions table --------------------------------------------------- */
/* The one table on the site. It scrolls inside its own box; the page itself
   never scrolls sideways. */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 10px;
}
table {
  width: 100%;
  min-width: 460px;
  border-collapse: collapse;
  font-size: 0.88rem;
}
th, td {
  padding: 9px 11px;
  text-align: left;
  border-top: 1px solid var(--line);
  white-space: nowrap;
}
thead th {
  border-top: 0;
  color: var(--muted);
  font-weight: 650;
  background: var(--bg);
}
td code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

/* --- Notice page ------------------------------------------------------ */
.notice-card { text-align: center; padding: 30px 20px 26px; }
.notice-card .page-title { margin-top: 0; }
.notice-card p { color: var(--muted); }
.notice-card .btn { margin-top: 18px; }

/* --- Form sections ---------------------------------------------------- */
/* fieldset + legend rather than a <div> and a heading: it is the grouping a
   screen reader announces when it reaches the fields inside. */
fieldset { border: 0; margin: 0; padding: 0; }
fieldset + fieldset { margin-top: 22px; }
legend { padding: 0; }

/* The admin page's title row: the heading, and the two sign-out buttons. Stacked
   on a phone, side by side once there is room — same rule as .actions. */
.page-head { display: flex; flex-direction: column; gap: 12px; margin-bottom: 6px; }
.page-head .page-title { margin: 0; }
.page-head-actions { display: flex; flex-direction: column; gap: 8px; }
@media (min-width: 620px) {
  .page-head { flex-direction: row; align-items: baseline; justify-content: space-between; }
  .page-head-actions { flex-direction: row; align-items: center; }
}
