/*
 * Minimal, dependency-free stylesheet.
 *
 * This is a secure core, not a design system - the application built on it will
 * bring its own skin. What is here is the accessibility floor the kit treats as
 * a quality bar rather than a nicety (stacks/static-site/LAYOUT.md):
 * visible focus, AA contrast, real form labels, 44px touch targets.
 *
 * Every colour pair below has been COMPUTED against WCAG AA, not eyeballed.
 * The ratios are recorded in docs/ACCESSIBILITY.md; re-run that check if you
 * change a token. Note .btn-quiet sets an explicit background even though it is
 * transparent - a button with no background lets the browser's ButtonFace
 * default bleed through, which has shipped a near-invisible button twice on
 * other builds in this kit.
 */

:root {
  --ink: #16191d;
  --ink-quiet: #4a5058;
  --paper: #ffffff;
  --paper-alt: #f4f6f8;
  /* Two border tokens, because WCAG treats them differently:
     --line is decorative (table rules, section dividers) and has no minimum;
     --line-strong bounds an INTERACTIVE control and must clear 3:1 against both
     surfaces it sits on (1.4.11 Non-text Contrast). The first draft used --line
     for input borders and measured 1.53:1 - a real failure the computed check
     caught and the eye did not. */
  --line: #cbd2d9;
  --line-strong: #7d8791;   /* 3.65:1 on paper, 3.37:1 on paper-alt */
  --brand: #0b4f9c;
  --brand-dark: #08386e;
  --warn-bg: #fff4e0;
  --warn-ink: #6b4300;
  --error-bg: #fdeceb;
  --error-ink: #8a1c14;
  --ok-bg: #e8f5ec;
  --ok-ink: #14562b;
  --radius: 6px;
  --wrap: 44rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.wrap {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Skip link: present for keyboard users, out of the way for everyone else.
   It must be the first focusable element on the page. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--brand);
  color: var(--paper);
  padding: 0.6rem 1rem;
  z-index: 10;
}
.skip-link:focus { left: 0; }

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--paper-alt);
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
.site-header nav { display: flex; align-items: center; gap: 1rem; }
.who { color: var(--ink-quiet); }
.inline-form { display: inline; margin: 0; }
/* A control inside a table row (e.g. a member's role): same field style and
   44px touch target as the stacked forms, sized to its content. */
.inline-form select {
  min-height: 44px;
  margin-right: 0.35rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

main { padding: 2rem 1.25rem 3rem; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 0.75rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 0.5rem; }
p { margin: 0 0 1rem; }
.hint { color: var(--ink-quiet); }

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

/* Never remove the outline - style it. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

form.stack label { display: block; font-weight: 600; margin-bottom: 0.25rem; }
form.stack p { margin: 0 0 1.1rem; }
form.stack input[type="text"],
form.stack input[type="email"],
form.stack input[type="password"],
form.stack select {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}
form.stack .helptext, form.stack ul.errorlist {
  display: block;
  margin: 0.3rem 0 0;
  padding: 0;
  font-size: 0.9rem;
}
form.stack .helptext { color: var(--ink-quiet); }
form.stack ul.errorlist { list-style: none; color: var(--error-ink); }

.btn {
  display: inline-block;
  min-height: 44px;
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand);   /* explicit, always */
  color: var(--paper);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: var(--paper); }

.btn-quiet {
  background: transparent;    /* explicit: stops the UA ButtonFace default showing through */
  border-color: var(--line-strong);
  color: var(--brand);
}
.btn-quiet:hover { background: var(--paper-alt); color: var(--brand-dark); }

.flash {
  border-left: 4px solid;
  padding: 0.7rem 1rem;
  margin: 1rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.flash-info, .flash-debug { background: var(--paper-alt); border-color: var(--brand); color: var(--ink); }
.flash-success { background: var(--ok-bg); border-color: var(--ok-ink); color: var(--ok-ink); }
.flash-warning { background: var(--warn-bg); border-color: var(--warn-ink); color: var(--warn-ink); }
.flash-error { background: var(--error-bg); border-color: var(--error-ink); color: var(--error-ink); }

table { border-collapse: collapse; width: 100%; }
caption { text-align: left; color: var(--ink-quiet); padding-bottom: 0.5rem; }
th, td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--line); }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.25rem 0;
  color: var(--ink-quiet);
  font-size: 0.9rem;
}

/* Available to screen readers, invisible on screen. Not display:none, which
   removes it from the accessibility tree along with everything else. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* The idle veil. Covers the viewport so nothing previously displayed remains
   visible once the session has ended (requirement 28). */
#session-veil {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#session-veil[hidden] { display: none; }
.veil-card { text-align: center; max-width: 28rem; padding: 2rem; }

/* ---- Sign-in and account security --------------------------------------- */
.narrow { max-width: 28rem; }
.lead { font-size: 1.05rem; color: var(--ink-quiet); }
.btn-block { display: block; width: 100%; text-align: center; }

/* A button that reads as a link, for secondary actions ("Send a new code",
   "Start again"). Explicit transparent background for the same ButtonFace
   reason as .btn-quiet; full 44px target despite looking like text. */
.btn-link {
  min-height: 44px;
  padding: 0.5rem 0;
  border: 0;
  background: transparent;
  color: var(--brand);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.btn-link:hover { color: var(--brand-dark); }

.form-links { margin-top: 0.75rem; }
.secondary-actions { display: flex; flex-wrap: wrap; gap: 0 1.25rem; align-items: center; margin-top: 0.5rem; }

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.5rem 0;
  color: var(--ink-quiet);
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

form.stack input.code-input {
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  font-variant-numeric: tabular-nums;
}
.field-error { display: block; margin-top: 0.3rem; color: var(--error-ink); font-size: 0.9rem; }

details.other-ways { margin: 1.25rem 0 0.5rem; }
details.other-ways summary { cursor: pointer; color: var(--brand); min-height: 44px; display: flex; align-items: center; }
ul.plain { list-style: none; padding: 0; margin: 0.25rem 0; }
ul.plain li { padding: 0.35rem 0; }

.choices { display: grid; gap: 1rem; margin: 1.5rem 0; }
.choice {
  display: block;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
}
.choice:hover { border-color: var(--brand); background: var(--paper-alt); color: var(--ink); }
.choice-title { display: block; font-weight: 700; color: var(--brand); margin-bottom: 0.25rem; }
.tag {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: var(--ok-bg);
  color: var(--ok-ink);
  font-size: 0.8rem;
  font-weight: 600;
  vertical-align: middle;
}

.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 1rem 0; }
.card h2 { margin-top: 0; }
/* A checkbox with its label: the whole row is the 44px touch target. */
.check { display: flex; gap: 0.6rem; align-items: center; min-height: 44px; font-weight: 600; cursor: pointer; }
.check input { width: 1.25rem; height: 1.25rem; flex: none; margin: 0; accent-color: var(--brand); }
form.stack .check { display: flex; }
.method { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.method:last-child { border-bottom: 0; }
.status-ok { color: var(--ok-ink); font-weight: 600; }

/* The QR image is black on transparent; the explicit white ground keeps it
   scannable whatever a site's skin puts behind it. */
img.qr { display: block; width: 200px; height: 200px; padding: 12px; background: #ffffff; border: 1px solid var(--line); border-radius: var(--radius); margin: 0.75rem 0; }
code.secret { font-size: 1.05rem; letter-spacing: 0.05em; word-break: break-all; }
ol.steps { padding-left: 1.25rem; }
ol.steps > li { margin-bottom: 1.25rem; }

ul.codes {
  list-style: none;
  padding: 1rem;
  margin: 1rem 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 1.5rem;
  background: var(--paper-alt);
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

/* The "add a passkey" suggestion. A card in the flow on small screens; in the
   bottom corner on wide ones. Never a modal: it doesn't take focus or block. */
.security-prompt {
  max-width: 44rem;
  margin: 1rem auto 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}
.security-prompt p { margin: 0 0 0.5rem; }
.security-prompt-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
@media (min-width: 60rem) {
  .security-prompt {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    width: 22rem;
    margin: 0;
    box-shadow: 0 6px 24px rgba(22, 25, 29, 0.18);
    z-index: 50; /* below the session veil (100) */
  }
}
@media (max-width: 59.99rem) { .security-prompt { margin: 1rem 1.25rem 0; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
