/* Base: reset, type, the app shell (header band, side nav, bottom nav, main). Mobile first:
   everything below works at 360px with a 16px gutter and no horizontal scroll. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: var(--lh);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
/* Inline icons get a text-sized default; components set their own sizes on top. */
svg { flex-shrink: 0; width: 1.25em; height: 1.25em; vertical-align: -0.25em; }
h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); font-weight: var(--fw-bold); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
code, pre, kbd { font-family: var(--mono); font-size: 0.9em; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
ul, ol { margin: 0; padding: 0; }
li { list-style: none; }
dl, dd { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-4) 0; }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-1); }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--s-2); top: -100px; z-index: 100;
  background: var(--surface); color: var(--ink); padding: var(--s-2) var(--s-4);
  border-radius: var(--r-1); box-shadow: var(--shadow-2);
}
.skip-link:focus { top: var(--s-2); }
.noscript { padding: var(--s-5); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Boot screen */
.boot {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-4); padding: var(--gutter); text-align: center;
}
.boot-mark {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid var(--brand-wash); border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
.boot-text { color: var(--ink-2); max-width: 32rem; }
.boot-error { color: var(--danger); font-weight: var(--fw-medium); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- App shell ---- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }

.band {
  position: sticky; top: 0; z-index: 20;
  background: var(--ctx); color: var(--ink-inverse);
  min-height: var(--header-h);
  display: flex; align-items: center; gap: var(--s-2);
  padding: 0 var(--gutter);
  padding-top: env(safe-area-inset-top);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}
.band :focus-visible { outline-color: var(--focus-on-band); }
.band-brand { display: flex; align-items: center; gap: var(--s-2); min-width: 0; color: inherit; text-decoration: none; }
.band-brand .ctx-icon { display: flex; }
.band-brand .ctx-icon svg { width: 28px; height: 28px; }
.band-title { font-weight: var(--fw-bold); font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.band-sub { font-size: var(--fs-xs); opacity: 0.92; white-space: nowrap; }
.band-spacer { flex: 1 1 auto; min-width: 0; }
/* With two contexts on a phone, the switcher itself names the side in force (the white pill),
   so the title gives way to it rather than squeezing it into the account button. */
@media (max-width: 559px) { .band.has-switch .band-text { display: none; } }

.ctx-switch {
  display: flex; background: rgba(0, 0, 0, 0.22); border-radius: var(--r-pill); padding: 3px; gap: 2px;
  flex-shrink: 1; min-width: 0;
}
.ctx-switch a {
  display: flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 var(--s-3);
  border-radius: var(--r-pill); color: #FFFFFF; text-decoration: none; font-size: var(--fs-sm);
  font-weight: var(--fw-medium); white-space: nowrap;
}
.ctx-switch a[aria-current="page"] { background: #FFFFFF; color: var(--ctx-strong); }
.ctx-switch a:not([aria-current="page"]):hover { background: rgba(255, 255, 255, 0.16); }
.ctx-switch .ctx-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #FFFFFF; }
.ctx-switch .ctx-dot[data-for="patient"] { background: var(--ctx-patient); }
.ctx-switch .ctx-dot[data-for="recruitment"] { background: var(--ctx-recruitment); }
.ctx-switch .long { display: none; }
@media (min-width: 520px) { .ctx-switch .long { display: inline; } .ctx-switch .short { display: none; } }

.me-btn {
  min-width: var(--tap); min-height: var(--tap); border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.18); color: #FFFFFF; font-weight: var(--fw-bold); cursor: pointer; padding: 0;
}
.me-btn:hover { background: rgba(0, 0, 0, 0.3); }

.layout { flex: 1 1 auto; display: flex; min-height: 0; }
.side-nav { display: none; }
.main {
  flex: 1 1 auto; min-width: 0; width: 100%;
  padding: var(--s-4) var(--gutter) calc(var(--bottom-nav-h) + var(--s-6) + env(safe-area-inset-bottom));
}
.main:focus { outline: none; }
.page { max-width: var(--content-max); margin: 0 auto; display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; }
.page > div:empty { display: none; }
h1[tabindex="-1"]:focus, h1[tabindex="-1"]:focus-visible { outline: none; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a, .bottom-nav button {
  min-height: var(--bottom-nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--ink-2); text-decoration: none; font-size: var(--fs-xs); font-weight: var(--fw-medium);
  background: none; border: 0; cursor: pointer; position: relative;
}
.bottom-nav [aria-current="page"] { color: var(--ctx-ink); }
.bottom-nav [aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--ctx);
}
.bottom-nav svg { width: 24px; height: 24px; }
.nav-count {
  position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--r-pill); background: var(--danger); color: #FFFFFF; font-size: 11px; line-height: 18px; text-align: center;
}

@media (min-width: 900px) {
  :root { --gutter: 24px; }
  .bottom-nav { display: none; }
  .side-nav {
    display: block; width: var(--nav-w); flex: 0 0 var(--nav-w);
    border-right: 1px solid var(--line); background: var(--surface);
    position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow-y: auto;
    padding: var(--s-3) var(--s-2);
  }
  .side-nav a {
    display: flex; align-items: center; gap: var(--s-3); min-height: var(--tap); padding: 0 var(--s-3);
    border-radius: var(--r-2); color: var(--ink-2); text-decoration: none; font-weight: var(--fw-medium);
    position: relative;
  }
  .side-nav a:hover { background: var(--surface-3); color: var(--ink); }
  .side-nav a[aria-current="page"] { background: var(--ctx-wash); color: var(--ctx-ink); }
  .side-nav a[aria-current="page"]::before {
    content: ""; position: absolute; left: -8px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--ctx);
  }
  .side-nav svg { width: 20px; height: 20px; }
  .side-nav .nav-count { position: static; margin-left: auto; }
  .side-nav-group { margin-top: var(--s-4); padding: 0 var(--s-3) var(--s-1); font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); }
  .main { padding-bottom: var(--s-7); }
}

/* Page header */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3); justify-content: space-between; }
.page-head-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: var(--fw-bold);
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ctx-ink);
}
.eyebrow svg { width: 14px; height: 14px; }
.page-head h1 { overflow-wrap: anywhere; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.lede { color: var(--ink-2); max-width: 60rem; }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }
.wrap-any { overflow-wrap: anywhere; word-break: break-word; }
.mono { font-family: var(--mono); }
.stack { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
.stack-sm { display: flex; flex-direction: column; gap: var(--s-2); min-width: 0; }
.row { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; min-width: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); flex-wrap: wrap; min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
