/* Launch mode's "Connect your phone" page — its whole stylesheet (the setup wizard keeps its
 * own, welcome.css). Built on the Biolink Health design system (the one biolink.health is
 * built from): near-white surfaces, ink type, one soft blue for controls and links, 1px
 * borders instead of shadows, Instrument Sans with IBM Plex Mono for codes. Status is a
 * coloured WORD. Light on every device. No external assets (CSP: self); motion honours
 * reduced-motion. */

/* ---- self-hosted fonts (served from /app/fonts; CSP forbids external fonts) ---- */
@font-face {
  font-family: "Instrument Sans";
  src: url("/app/fonts/instrument-sans.woff2") format("woff2");
  font-weight: 400 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/app/fonts/ibm-plex-mono-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/app/fonts/ibm-plex-mono-500.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}

:root {
  color-scheme: light;

  --paper-a: #F5F7F9;          /* page ground (neutral-50) */
  --paper-b: #F5F7F9;
  --surface: #FFFFFF;          /* cards */
  --field: #FFFFFF;            /* inputs */
  --hairline: #DFE4E9;         /* border-default (neutral-200) */
  --hairline-strong: #C9D0D8;  /* border-strong (neutral-300) */
  --ink: #0D1520;              /* text-primary, matched to the logo */
  --muted-c: #5B6672;          /* text-secondary */
  --faint: #7A8592;            /* text-tertiary */
  --accent: #3C74A8;           /* blue-600: buttons and controls */
  --accent-hover: #2D5D8A;     /* blue-700 */
  --accent-text: #2D5D8A;      /* blue-700: links, eyebrows, brand text */
  --accent-soft: #EFF5FA;      /* blue-50 */
  --on-accent: #FFFFFF;
  --ok: #2A6E45;
  --warn: #8A5A00;
  --err: #A4281E;
  --err-soft: #FBEDEB;
  --disabled-bg: #DFE4E9;
  --disabled-fg: #A3ADB8;
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px #538CBE;

  --font-ui: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: var(--font-ui);
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r-xs: 4px;
  --r-sm: 6px;                 /* controls */
  --r-md: 8px;                 /* cards */
  --dur: 200ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);

  font-family: var(--font-ui);
  color: var(--ink);
  font-size: 16px;
}

/* Light is the default on every device. Dark is opt-in only (data-theme="dark" on <html>);
   it never follows the device setting. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper-a: #0B1118; --paper-b: #0B1118;
  --surface: #121A23; --field: #0E151D;
  --hairline: #26313D; --hairline-strong: #36434F;
  --ink: #E8EDF2; --muted-c: #A3ADB8; --faint: #7F8A97;
  --accent: #3C74A8; --accent-hover: #538CBE; --accent-text: #9BBEDD;
  --accent-soft: #17283A; --on-accent: #FFFFFF;
  --ok: #74C493; --warn: #E2B45A; --err: #F08A7E; --err-soft: #2A1614;
  --disabled-bg: #26313D; --disabled-fg: #6B7684;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper-a);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main {
  width: min(680px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 56px;
}

a { color: var(--accent-text); }
::selection { background: rgba(83, 140, 190, 0.25); }

/* ---- header ---------------------------------------------------------------------- */
/* The Biolink Health logo (the wordmark whose first letter is the B mark, as on
   biolink.health), painted through a mask so it takes this page's ink rather than the SVG's
   own colour (an <img> cannot inherit `currentColor`). Aspect is the artwork's own. The logo
   is always ink (or white on ink), never brand blue. */
.w-lockup {
  display: block;
  width: 150px;
  aspect-ratio: 445 / 115;
  margin: 0 0 28px;
  background-color: var(--ink);
  -webkit-mask: url("/app/brand/biolink-logo.svg") left center / contain no-repeat;
  mask: url("/app/brand/biolink-logo.svg") left center / contain no-repeat;
}

/* Sentence case, brand blue, no tracked capitals (the design system's eyebrow). */
.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}

h1, h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
  text-wrap: balance;
}
h1 { font-size: clamp(28px, 4.4vw, 32px); line-height: 1.25; letter-spacing: -0.015em; }
h2 { font-size: clamp(20px, 3vw, 24px); line-height: 1.33; letter-spacing: -0.01em; }

.lede { max-width: 620px; margin: 0; color: var(--muted-c); font-size: 16px; line-height: 1.6; }

/* ---- device strip ---------------------------------------------------------------- */
.device {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  margin: 24px 0 0;
  padding: 10px 16px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--muted-c);
  font-size: 14px;
}
.device b { color: var(--ink); font-weight: 600; margin-right: 6px; }
/* A way OUT of setup: signing in as the wrong person used to be a dead end (the wizard
   has no nav), leaving clearing site data as the only escape. */
.device .linky {
  margin-left: auto;
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.device .linky:hover { text-decoration: underline; text-underline-offset: 2px; background: none; }

/* ---- progress rail --------------------------------------------------------------- */
.rail {
  display: flex;
  gap: 4px;
  margin: 24px 0 20px;
  padding: 0;
  list-style: none;
}
/* The browser's own `[hidden] { display: none }` is a USER-AGENT rule, so ANY author rule
   that sets `display` on the same element beats it — regardless of order. That silently
   broke two things here: `.rail` (which showed every owner step to a household member on
   the first screen) and `.ghost` (the wizard's "Turn off remote access" button, which the
   JS hides but which stayed on screen anyway). Make hiding authoritative once, for every
   element, the way app.css already does for the app shell. */
[hidden] { display: none !important; }
.rail li {
  flex: 1;
  padding-top: 8px;
  border-top: 2px solid var(--hairline);
  color: var(--faint);
  font-size: 13px;
  font-weight: 500;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.rail li.done { border-top-color: var(--accent); color: var(--muted-c); }
.rail li.done::after { content: " ✓"; color: var(--ok); }
.rail li.active { border-top-color: var(--accent); color: var(--ink); font-weight: 600; }

/* ---- cards ------------------------------------------------------------------------ */
/* White, 1px border, 8px radius, no shadow: structure comes from the line. */
.card {
  margin-top: 20px;
  padding: clamp(20px, 4vw, 32px);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--surface);
  animation: rise 280ms var(--ease);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.card > p:not(.step):not(.result) { color: var(--muted-c); line-height: 1.6; margin: 0 0 8px; }
.card code {
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: var(--r-xs);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.step {
  margin: 0 0 6px;
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}
.step .idx {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 8px;
  border-radius: var(--r-xs);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.step .opt { color: var(--faint); font-weight: 500; }
.step b { color: var(--warn); font-weight: 600; }
.step.success-step { color: var(--ok); }

/* ---- forms ------------------------------------------------------------------------ */
form { display: grid; gap: 8px; margin-top: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; line-height: 18px; margin-top: 6px; color: var(--ink); }
label span, .muted { color: var(--faint); font-weight: 400; }
.muted.small, .small { font-size: 13px; line-height: 20px; }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input:hover, select:hover { border-color: var(--faint); }
input:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.row-inline { display: flex; gap: 8px; align-items: center; }

/* password field + Show/Hide toggle (makeRevealable() in welcome.js) */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 68px; }
.pw-reveal {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  min-height: 0;
  width: auto;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--accent-text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
}
.pw-reveal:hover { background: var(--accent-soft); }
.pw-reveal:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---- buttons ---------------------------------------------------------------------- */
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; align-items: center; }
button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease), color 140ms var(--ease);
}
button:hover { background: var(--accent-hover); }
button:active { background: #22476A; }
button:disabled { background: var(--disabled-bg); color: var(--disabled-fg); cursor: not-allowed; }
button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
/* Secondary: surface fill, strong border, ink text (the site's .btn-secondary). */
button.ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--hairline-strong);
}
button.ghost:hover { background: var(--paper-a); }
button.ghost:disabled { background: var(--disabled-bg); color: var(--disabled-fg); }
button.small { min-height: 36px; padding: 0 12px; font-size: 14px; }

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 6px;
  padding: 0 18px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 140ms var(--ease);
}
.button-link:hover { background: var(--accent-hover); }
.button-link:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---- panels / status -------------------------------------------------------------- */
.panel {
  margin: 8px 0 4px;
  padding: 12px 16px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--paper-a);
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted-c);
}
.panel b { color: var(--ink); font-weight: 600; }

/* Status is a coloured WORD — never a bare dot. */
.pill { font-size: 14px; font-weight: 600; }
.pill.on { color: var(--ok); }
.pill.off { color: var(--faint); }
.pill.warn { color: var(--warn); }

.result { min-height: 20px; margin: 6px 2px 0; font-size: 14px; color: var(--muted-c); }
.result.ok { color: var(--ok); }
.result.bad { color: var(--err); }

.note { margin: 12px 0 0; color: var(--faint); font-size: 14px; line-height: 1.55; }
.message { min-height: 24px; margin: 16px 4px 0; color: var(--err); font-size: 14px; }
.message:empty { min-height: 0; margin: 0; }
.success { border-color: var(--hairline); }

@media (max-width: 560px) {
  main { padding: 24px 0 32px; }
  .w-lockup { margin-bottom: 20px; }
  .device { display: grid; gap: 6px; }
  .grid2 { grid-template-columns: 1fr; }
  .rail li { font-size: 0; }
  .rail li.done::after { content: ""; }
}

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

/* ---- what the Connect page adds ----------------------------------------------------- */
/* On a computer the page is ONE screen: the introduction and status on the left, the
 * card for the current step on the right, and the code sized to the window's height, so
 * nobody scrolls to find it. No external assets (CSP: self). */

/* The page is a column: the content, then the version line centred at the foot of the screen. */
body { display: flex; flex-direction: column; }
.page-foot { margin-top: auto; padding: 8px 16px 16px; text-align: center; }
.page-foot p { margin: 0; color: var(--faint); font-size: 13px; line-height: 20px; }
#server-version, #server-id { font-family: var(--font-mono); font-size: 12px; }

.device .pill { font-size: inherit; }
.pill.bad { color: var(--err); }

.reminder { margin-top: 16px; }
.reminder p { margin: 4px 0 0; }

.steps {
  margin: 12px 0 0;
  padding-left: 1.3em;
  color: var(--muted-c);
  font-size: 15px;
  line-height: 1.5;
}
.steps li { margin: 3px 0; padding-left: 2px; }
.steps li::marker { color: var(--faint); font-variant-numeric: tabular-nums; }
.steps b { color: var(--ink); font-weight: 600; }

/* The code: white quiet zone on every theme (a scanner needs dark-on-light), a 1px line, and
   a size that follows the window's height so the whole card stays on screen. */
.qr-box {
  --qr: clamp(136px, calc(100vh - 526px), 200px);
  margin-top: 16px;
  text-align: center;
}
.qr-box img {
  display: block;
  margin: 0 auto;
  width: var(--qr);
  height: var(--qr);
  max-width: 100%;
  background: #fff;
  padding: 8px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
}
.qr-box p { margin: 8px auto 0; max-width: 460px; }
.qr-box .expired { color: var(--warn); font-weight: 600; }
.qr-box .code-fallback { margin-top: 14px; }
.qr-box .pair-code {
  font-family: var(--font-mono);
  font-size: 30px;
  letter-spacing: 0.3em;
  margin: 10px auto 6px;
  user-select: all;
}
.qr-box .linked { color: var(--ok); font-weight: 600; font-size: 16px; }

#signin-user-slot select, #signin-user-slot input { width: 100%; }

/* Everyone registered here, one row each; the chosen row takes the selected fill. */
.people { display: grid; gap: 6px; }
label.person {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  margin: 0;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  background: var(--field);
  font-size: 15px;
  cursor: pointer;
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease);
}
label.person:hover { border-color: var(--faint); }
/* welcome.css sizes every input as a text box; a radio is not one. */
label.person input {
  width: 16px; height: 16px; min-height: 0; flex: none;
  margin: 0; padding: 0; accent-color: var(--accent);
}
label.person.chosen { border-color: var(--accent); background: var(--accent-soft); }
.person-name { font-weight: 600; color: var(--ink); }
.person-sub { font-weight: 400; color: var(--faint); font-size: 13px; }

/* A link-looking button (same as the wizard's "Not you?" in the status strip). */
.note .linky {
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.note .linky:hover { text-decoration: underline; text-underline-offset: 2px; background: none; }

/* Your phones: one row per phone, its Remove at the end of the row. */
#phones-list { margin-top: 8px; }
.phone-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--hairline);
}
.phone-row:first-child { border-top: 0; }
.phone-words { display: grid; gap: 2px; min-width: 0; }
.phone-name { font-weight: 600; color: var(--ink); font-size: 15px; overflow-wrap: anywhere; }
.phone-note { color: var(--faint); font-size: 13px; }
.phone-note.confirm { color: var(--ink); }
.phone-actions { display: flex; gap: 8px; flex: none; }
.phone-row button { flex: none; width: auto; min-height: 36px; padding: 0 12px; font-size: 14px; }
@media (max-width: 560px) {
  .phone-row { flex-wrap: wrap; }
}

/* The supporting cards (phones, remote access, developer logs) are quieter than the step card. */
#phones-card, #away-card { padding: 20px 24px; }
#phones-card h2, #away-card h2 { font-size: 17px; line-height: 24px; letter-spacing: -0.005em; margin-bottom: 4px; }
#phones-card > p { margin-bottom: 0; }
#away-card { margin-top: 12px; }
.away-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.away-address { margin: 8px 0 0; font-family: var(--font-mono); font-size: 13px; color: var(--muted-c);
  overflow-wrap: anywhere; }
#away-more .note { margin-top: 8px; }
#away-more code { display: block; margin-top: 4px; font-family: var(--font-mono); font-size: 12px;
  white-space: nowrap; overflow-x: auto; }
#away-actions:empty { display: none; }
#away-actions button { width: auto; }
#away-card .result:empty { min-height: 0; margin: 0; }
/* Settings: a quiet gear in the top-right corner of the screen (the owner, at the server's own
   network only). It opens a small menu with Export logs; a click elsewhere or Escape closes it. */
#logs-card.settings { position: fixed; top: 12px; right: 12px; z-index: 20; margin: 0; }
.settings-menu summary {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  color: var(--faint);
  cursor: pointer;
  list-style: none;
  transition: background-color 140ms var(--ease), color 140ms var(--ease);
}
.settings-menu summary::-webkit-details-marker { display: none; }
.settings-menu summary:hover, .settings-menu[open] summary { color: var(--ink); background: var(--hairline); }
.settings-menu summary:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.settings-menu .gear { width: 18px; height: 18px; }
.settings-pop {
  position: absolute;
  top: 42px;
  right: 0;
  width: 260px;
  padding: 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(13, 21, 32, .10), 0 1px 3px rgba(13, 21, 32, .06);
}
.settings-pop button { width: 100%; min-height: 36px; font-size: 14px; }
.settings-note { margin: 8px 0 0; color: var(--faint); font-size: 12px; line-height: 17px; }
.settings-pop .result { font-size: 13px; }
.settings-pop .result:empty { min-height: 0; margin: 0; }

.newcode code {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 20px;
  letter-spacing: 0.06em;
  padding: 6px 10px;
}
label.check { display: flex; gap: 10px; align-items: center; font-size: 15px; font-weight: 500; margin-top: 14px; }
label.check input { width: auto; min-height: 0; }

/* ---- one screen on a computer ------------------------------------------------------ */
/* Two columns: everything that describes the server on the left, the one step card that is
   showing on the right (connect.js shows one of them at a time). The right card spans every
   row, ending in a flexible row, so its height never stretches the gaps on the left. Sizes
   step down a notch from the wizard's so the whole page fits a laptop window. */
@media (min-width: 960px) {
  main {
    margin: auto;   /* centred in the space above the version line */
    width: min(1120px, calc(100% - 64px));
    padding: 32px 0;
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    grid-template-rows: repeat(10, auto) minmax(0, 1fr);
    column-gap: 40px;
  }
  main > * { grid-column: 1; }
  main > #remote-card, main > #signin-card, main > #newcode-card, main > #password-card,
  main > #activate-card, main > #timezone-card, main > #phone-card, main > #hosted-card,
  main > #linked-card {
    grid-column: 2;
    grid-row: 2 / -1;   /* starts level with the server status strip, under the heading */
    align-self: start;
    margin-top: 16px;   /* the strip's own top margin, so the two tops line up */
  }
  .w-lockup { width: 136px; margin-bottom: 24px; }
  h1 { font-size: 28px; line-height: 36px; }
  h2 { font-size: 22px; line-height: 30px; }
  .lede { font-size: 15px; line-height: 1.55; }
  .device { margin-top: 16px; padding: 8px 14px; font-size: 13px; gap: 4px 20px; }
  .device .linky { font-size: 13px; }
  .reminder { margin-top: 12px; padding: 10px 14px; font-size: 13px; }
  .card { padding: 24px 28px; }
  .card > p:not(.step):not(.result) { font-size: 15px; }

  /* The supporting cards: their title says what they are, so the small label above it goes. */
  #phones-card, #away-card { margin-top: 12px; padding: 14px 18px; }
  #phones-card .step { display: none; }
  #phones-card h2, #away-card h2 { font-size: 16px; line-height: 22px; }
  #phones-card > p, #away-card > p { font-size: 13px; line-height: 19px; }
  #away-card button { min-height: 32px; padding: 0 12px; font-size: 13px; }
  .phone-row { padding: 6px 0; }
  .phone-name { font-size: 14px; }
  .phone-note { font-size: 12px; }
  #phones-list { margin-top: 4px; }
  #phones-card button { min-height: 32px; padding: 0 12px; font-size: 13px; }
  #phones-card .result:empty { min-height: 0; margin: 0; }

  /* Inside the code card: the code beside its notes, so the card stays short. */
  .steps { font-size: 14px; margin-top: 8px; }
  .qr-box:has(img) {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 20px;
    align-items: start;
    text-align: left;
  }
  .qr-box:has(img) img { grid-column: 1; grid-row: 1 / span 4; margin: 0; }
  .qr-box:has(img) p { grid-column: 2; margin: 0 0 8px; }
}

/* A short window (a laptop at 1366 x 768 with browser chrome): tighter vertical rhythm. */
@media (min-width: 960px) and (max-height: 760px) {
  main { padding: 8px 0; }
  .w-lockup { margin-bottom: 12px; }
  .page-foot { padding: 0 16px 8px; }
  .card { padding: 18px 24px; }
  h2 { font-size: 20px; line-height: 28px; margin-bottom: 4px; }
  .qr-box { margin-top: 12px; }
  .actions { margin-top: 12px; }
}

/* A narrow laptop window (columns wrap more text): the code gives up a little more height. */
@media (min-width: 960px) and (max-width: 1199px) {
  .qr-box { --qr: clamp(136px, calc(100vh - 546px), 200px); }
}
