/*
 * vigie — one stylesheet, no framework, no web font (CSP 'self').
 * Built for an iPhone at 375 pt, used in a hurry: big targets (44 pt and more), high contrast,
 * red reserved for "Critique" and for errors, dark mode that follows iOS.
 */

:root {
  color-scheme: light dark;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #0a1f33;
  --muted: #475769;
  --line: #a9b6c4;
  --action: #0b3d91;
  --on-action: #ffffff;
  --focus: #1d6fe0;
  --critical: #c40d1e;
  --on-critical: #ffffff;
  --critical-soft: #fde8ea;
  --urgent: #8f4500;
  --urgent-soft: #fff0d9;
  --ok: #17663a;
  --ok-soft: #e3f4ea;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text: 1.0625rem; /* 17 px, iOS body size; >= 16 px keeps Safari from zooming on inputs */
  --small: 0.9375rem;
  --h2: 1.3125rem;
  --h1: 1.75rem;
  --target: 3.25rem; /* 52 px: buttons and fields */
  --radius: 0.75rem;
  --gutter: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #121a23;
    --ink: #f2f5f8;
    --muted: #a9b6c3;
    --line: #4a5868;
    --action: #9cc2ff;
    --on-action: #00152f;
    --focus: #9cc2ff;
    --critical: #ff6b6b;
    --on-critical: #1a0003;
    --critical-soft: #3b0b10;
    --urgent: #ffb547;
    --urgent-soft: #3a2400;
    --ok: #6fdc9a;
    --ok-soft: #0c2e1b;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The attribute wins over any display rule (.button is inline-flex): app.js reveals what works. */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text);
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Masthead and navigation ---------- */

.masthead {
  padding: calc(env(safe-area-inset-top) + 0.75rem) calc(env(safe-area-inset-right) + var(--gutter)) 0
    calc(env(safe-area-inset-left) + var(--gutter));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  margin-bottom: 0.5rem;
  color: var(--ink);
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.brand-mark {
  display: block;
  border-radius: 0.5rem;
}

.nav-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.nav-link[aria-current="page"] {
  border-bottom-color: var(--ink);
  color: var(--ink);
}

.nav-link:hover {
  color: var(--ink);
}

.nav-signout {
  font-weight: 500;
}

/* ---------- Page ---------- */

.page {
  max-width: 36rem;
  padding: 1.5rem calc(env(safe-area-inset-right) + var(--gutter)) calc(env(safe-area-inset-bottom) + 3rem)
    calc(env(safe-area-inset-left) + var(--gutter));
}

h1,
h2 {
  margin: 0 0 0.75rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h1 {
  font-size: var(--h1);
  font-weight: 750;
}

h2 {
  margin-top: 2rem;
  font-size: var(--h2);
  font-weight: 700;
}

p {
  margin: 0 0 1rem;
}

a {
  color: var(--action);
  text-underline-offset: 0.15em;
}

.lead {
  color: var(--muted);
}

.aside {
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: var(--small);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Forms ---------- */

.form {
  display: grid;
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.field {
  display: grid;
  gap: 0.375rem;
}

.field label {
  font-weight: 650;
}

.field-help {
  margin: 0;
  color: var(--muted);
  font-size: var(--small);
}

input[type="email"],
input[type="password"],
input[type="text"],
textarea,
select {
  width: 100%;
  min-height: var(--target);
  padding: 0.75rem 0.875rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

/* Shown for the record (the account's email), not to be typed in. */
input[readonly] {
  border-style: dashed;
  background: transparent;
  color: var(--muted);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  border-color: var(--focus);
}

.input-code {
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.25em;
}

/* ---------- Buttons ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--target);
  padding: 0.75rem 1.25rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button-primary {
  background: var(--action);
  color: var(--on-action);
}

.button-quiet {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

/* The one red button: it wakes people up. */
.button-critical {
  background: var(--critical);
  color: var(--on-critical);
}

.button:active {
  transform: translateY(1px);
}

@media (min-width: 40rem) {
  .button {
    width: auto;
    min-width: 14rem;
  }
}

/* ---------- Account set-up: steps, TOTP key, backup codes ---------- */

.steps {
  display: grid;
  gap: 1rem;
  margin: 1.5rem 0 0;
  padding-left: 1.5rem;
}

.steps li::marker {
  font-weight: 750;
}

.steps p {
  margin-bottom: 0.5rem;
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* The TOTP key, typed by hand: large, grouped by four, wraps between groups only. */
.secret {
  display: block;
  padding: 0.75rem 0.875rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 1.125rem;
  letter-spacing: 0.06em;
  word-spacing: 0.3em;
  overflow-wrap: normal;
  user-select: all;
  -webkit-user-select: all;
}

.backup-codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 1rem;
  margin: 1.5rem 0;
  padding: 1rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
  list-style: none;
}

.signin > .notice {
  margin-bottom: 1rem;
}

.backup-codes code {
  font-size: 1.0625rem;
  letter-spacing: 0.04em;
  user-select: all;
  -webkit-user-select: all;
}

/* ---------- Passkeys (Face ID) ---------- */

.passkey-action {
  display: grid;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.passkey-action > .notice {
  margin: 0;
}

/* Between the Face ID button and the password form: a rule with the words in its gap. */
.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0 -0.5rem;
  color: var(--muted);
  font-size: var(--small);
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--line);
}

.passkeys {
  display: grid;
  margin: 1.5rem 0 0;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  list-style: none;
}

.passkey {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
}

.passkey + .passkey {
  border-top: 1px solid var(--line);
}

.passkey p {
  margin: 0;
}

.passkey-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.passkey-meta {
  color: var(--muted);
  font-size: var(--small);
}

.passkey-rename summary {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  color: var(--action);
  font-weight: 650;
  cursor: pointer;
}

.passkey-rename .form {
  margin-top: 0.5rem;
}

/* ---------- Receiving alerts: the enrolment guide ---------- */

.guide-figure {
  display: block;
  width: 100%;
  max-width: 20rem;
  height: auto;
  margin: 0.75rem 0 0;
  border-radius: var(--radius);
}

.guide .secret {
  overflow-wrap: anywhere;
}

.guide .copy-button {
  margin-bottom: 0.75rem;
}

.guide .field {
  margin: 0.75rem 0;
}

.existing-key,
.restart {
  margin: 0.75rem 0;
}

.existing-key summary,
.restart summary {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  color: var(--action);
  font-weight: 650;
  cursor: pointer;
}

.restart {
  margin-top: 2rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}

.device-status {
  display: grid;
  gap: 0.75rem;
  margin: 1rem 0 0;
  padding: 1rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.device-status > p,
.device-status > h2 {
  margin: 0;
}

.device-active {
  border-color: var(--ok);
}

.actions {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.test-state {
  margin-bottom: 1rem;
}

.causes {
  display: grid;
  gap: 0.75rem;
  margin: 0 0 1rem;
  padding-left: 1.5rem;
}

/* ---------- Sending an alert: recipients, level, per-recipient state ---------- */

.choices {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.choices legend {
  margin-bottom: 0.375rem;
  padding: 0;
  font-weight: 650;
}

/* The whole row is the target: 52 px high, the box or dot on the left. */
.choice {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--target);
  padding: 0.5rem 0.875rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.choice:has(input:checked) {
  border-color: var(--action);
}

.choice input {
  flex: none;
  width: 1.375rem;
  height: 1.375rem;
  margin: 0;
  accent-color: var(--action);
}

.choice > span {
  display: grid;
  gap: 0.125rem;
}

.choice .level {
  justify-self: start;
}

.choice-all {
  font-weight: 650;
}

.choice-help {
  color: var(--muted);
  font-size: var(--small);
}

/* Recipients: compact toggle pills, two per row at 375 pt. The real checkbox covers the pill
   (invisible, still focusable and announced); the selected state is a filled pill with a check. */
.recipients {
  display: grid;
  gap: 0.375rem;
}

.recipients-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.recipients-title {
  font-weight: 650;
}

.recipients-count {
  color: var(--muted);
  font-size: var(--small);
}

.all-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 2.75rem;
  margin-left: auto;
  padding: 0 0.5rem;
  color: var(--action);
  font-weight: 650;
  cursor: pointer;
}

.all-toggle > span {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.all-toggle:has(input:checked) > span::after {
  content: " ✓";
  text-decoration: none;
  display: inline-block;
}

.pills {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

@media (min-width: 30rem) {
  .pills {
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  }
}

.pill {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.pill input,
.all-toggle input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.pill-name {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.pill-name small {
  font-size: 0.8125rem;
  font-weight: 500;
  opacity: 0.85;
}

.pill::after {
  content: "✓";
  flex: none;
  font-weight: 700;
  visibility: hidden;
}

.pill:has(input:checked) {
  border-color: var(--action);
  background: var(--action);
  color: var(--on-action);
  font-weight: 650;
}

.pill:has(input:checked)::after {
  visibility: visible;
}

.pill:has(input:focus-visible),
.all-toggle:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.optional {
  color: var(--muted);
  font-weight: 500;
}

textarea {
  min-height: 7rem;
  resize: vertical;
}

.send-summary {
  margin-bottom: 0.25rem;
  overflow-wrap: anywhere;
}

.send-meta {
  color: var(--muted);
  font-size: var(--small);
}

.results {
  display: grid;
  margin: 1rem 0 0;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  list-style: none;
}

.result {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.875rem 1rem;
}

.result + .result {
  border-top: 1px solid var(--line);
}

.result-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.result-label {
  color: var(--muted);
}

.result[data-state="sent"] .result-label {
  color: var(--ok);
  font-weight: 650;
}

.result[data-state="sent"] .result-label::before {
  content: "✓ ";
}

.result[data-state="failed"] .result-label {
  color: var(--critical);
  font-weight: 650;
}

.result[data-state="retrying"] .result-label,
.result[data-state="interrupted"] .result-label {
  color: var(--urgent);
  font-weight: 650;
}

/* ---------- History and audit journal ---------- */

.history-item {
  margin-top: 1.5rem;
}

.history-item .results {
  margin-top: 0.5rem;
}

.journal-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 1rem 0;
}

.journal-filter select {
  width: auto;
  flex: 1 1 12rem;
}

.journal-scroll {
  margin-top: 1rem;
  overflow-x: auto;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.journal {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--small);
}

.journal th,
.journal td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.journal th {
  color: var(--muted);
  font-weight: 650;
  white-space: nowrap;
}

.journal td:first-child,
.journal td:nth-child(4) {
  white-space: nowrap;
}

.journal tbody tr:last-child td {
  border-bottom: 0;
}

.send-status .aside {
  margin-top: 1rem;
}

/* ---------- Admin: accounts, invitations, settings ---------- */

/* One bordered list per page, one row per account or invitation (the passkey list's pattern). */
.admin-list {
  display: grid;
  margin: 1.5rem 0;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  list-style: none;
}

.admin-item {
  display: grid;
  gap: 0.375rem;
  padding: 1rem;
}

.admin-item + .admin-item {
  border-top: 1px solid var(--line);
}

.admin-item p {
  margin: 0;
}

/* A disabled account, a used or revoked invitation: still listed, visibly out of play. */
.admin-item-off .admin-name {
  color: var(--muted);
}

.admin-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.admin-name small {
  color: var(--muted);
  font-weight: 500;
}

.admin-meta {
  color: var(--muted);
  font-size: var(--small);
  overflow-wrap: anywhere;
}

.admin-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0;
  padding: 0;
  font-size: var(--small);
  list-style: none;
}

.admin-actions {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.admin-confirm summary {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  color: var(--action);
  font-weight: 650;
  cursor: pointer;
}

.admin-confirm[open] {
  display: grid;
  gap: 0.5rem;
}

.chip {
  display: inline-block;
  padding: 0.0625rem 0.5rem;
  border: 2px solid var(--action);
  border-radius: 999px;
  color: var(--action);
  font-size: var(--small);
  font-weight: 650;
}

.chip-off {
  border-color: var(--muted);
  color: var(--muted);
}

.admin-section-link {
  font-size: var(--h2);
  font-weight: 700;
}

.admin-link {
  overflow-wrap: anywhere;
  letter-spacing: 0;
  word-spacing: normal;
}

.copy-button {
  margin-bottom: 0.75rem;
}

.field-error {
  margin-top: 0.5rem;
}

/* ---------- Notices and levels ---------- */

.notice {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  border-left: 6px solid var(--line);
  border-radius: 0.25rem;
  background: var(--surface);
}

.notice-error {
  border-left-color: var(--critical);
  background: var(--critical-soft);
  font-weight: 600;
}

.notice-ok {
  border-left-color: var(--ok);
  background: var(--ok-soft);
}

.level {
  display: inline-block;
  padding: 0.125rem 0.625rem;
  border-radius: 999px;
  font-size: var(--small);
  font-weight: 700;
}

.level-critical {
  background: var(--critical);
  color: var(--on-critical);
}

.level-urgent {
  background: var(--urgent-soft);
  color: var(--urgent);
  box-shadow: inset 0 0 0 2px var(--urgent);
}

@media (prefers-reduced-motion: reduce) {
  .button:active {
    transform: none;
  }
}
