/* Adaptive Check-In staff website. Tokens mirror docs/design.md. */

@font-face {
  font-family: "Inter";
  src: url("/static/vendor/fonts/inter-latin-wght.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("/static/vendor/fonts/fraunces-latin-wght.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}

:root {
  --bg: #F7F3EC;
  --surface: #FFFDF9;
  --sunken: #F0EBE2;
  --line: #E6DED2;
  --line-strong: #D3C8B8;
  --ink: #2B2621;
  --ink-2: #554D45;
  --muted: #776C61;
  --primary: #3E6A55;
  --primary-hover: #33594A;
  --primary-soft: #E3EDE6;
  --primary-ink: #2C5242;
  --on-primary: #FFFFFF;
  --accent: #C0653D;
  --accent-soft: #F7E5DA;
  --accent-ink: #94481F;
  --risk: #B13A2C;
  --risk-soft: #FAE6E1;
  --risk-ink: #8C2B1F;
  --warn-soft: #FBEFD5;
  --warn-ink: #7A5200;
  --info-soft: #E6ECF2;
  --info-ink: #3B5672;
  --plum-soft: #F2E7F0;
  --plum-ink: #6E4269;
  --sidebar: #F1ECE3;

  --shadow: 0 1px 2px rgba(43, 38, 33, .05), 0 6px 20px -8px rgba(43, 38, 33, .10);
  --shadow-lg: 0 2px 4px rgba(43, 38, 33, .05), 0 18px 40px -12px rgba(43, 38, 33, .18);
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px;
  --focus: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);

  --font-text: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", ui-serif, Georgia, serif;

  /* legacy names still used by chart SVGs */
  --accent-line: var(--primary);
  --critical: var(--risk);

  color-scheme: light;
  font-family: var(--font-text);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181614;
    --surface: #221F1C;
    --sunken: #2A2622;
    --line: #37322C;
    --line-strong: #4A433B;
    --ink: #F1EBE3;
    --ink-2: #D2C8BC;
    --muted: #A69B8E;
    --primary: #8FC0A6;
    --primary-hover: #A6CFB9;
    --primary-soft: #233229;
    --primary-ink: #BFE0CD;
    --on-primary: #14201A;
    --accent: #E49A75;
    --accent-soft: #3A2A21;
    --accent-ink: #F2C2A8;
    --risk: #F08F80;
    --risk-soft: #3D231E;
    --risk-ink: #F7BFB5;
    --warn-soft: #3A3018;
    --warn-ink: #EDCB7F;
    --info-soft: #1F2A35;
    --info-ink: #A9C2DC;
    --plum-soft: #33232F;
    --plum-ink: #DDB3D6;
    --sidebar: #1D1B18;
    --shadow: none;
    --shadow-lg: 0 18px 40px -12px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); line-height: 1.5; font-feature-settings: "cv11", "ss01"; }
h1, h2, h3 { color: var(--ink); }
h1 { font-family: var(--font-display); font-weight: 580; font-size: 1.95rem; line-height: 1.15;
  letter-spacing: -.015em; margin: 0; font-variation-settings: "opsz" 72; }
h2 { font-family: var(--font-display); font-weight: 580; font-size: 1.2rem; line-height: 1.3; margin: 0;
  letter-spacing: -.005em; font-variation-settings: "opsz" 36; }
h3 { font-size: .75rem; font-weight: 650; margin: 0 0 .5rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: .07em; }
p { margin: 0; }
a { color: var(--primary); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .85em; background: var(--sunken);
  padding: .05em .35em; border-radius: 5px; }
::selection { background: var(--primary-soft); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.icon { flex: none; display: inline-block; vertical-align: -.2em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.muted, .meta { color: var(--muted); }
.htmx-request { opacity: .6; transition: opacity .2s; }

/* ---------- App shell ---------- */

.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--sidebar);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 1.1rem .85rem 1rem; }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); padding: .2rem .5rem .9rem; }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.08rem; letter-spacing: -.01em; line-height: 1.1; }
.brand-sub { display: block; font-family: var(--font-text); font-size: .72rem; font-weight: 500; color: var(--muted); letter-spacing: .02em; }
.nav-group { margin-top: .9rem; }
.nav-label { font-size: .7rem; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  padding: 0 .6rem .35rem; }
.nav-study { font-family: var(--font-display); font-size: .95rem; font-weight: 560; color: var(--ink); padding: 0 .6rem .4rem;
  text-transform: none; letter-spacing: 0; line-height: 1.25; }
.nav-link { display: flex; align-items: center; gap: .65rem; padding: .48rem .6rem; border-radius: 10px; color: var(--ink-2);
  text-decoration: none; font-weight: 500; font-size: .93rem; }
.nav-link:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); color: var(--ink); }
.nav-link .icon { color: var(--muted); }
.nav-link.current { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.nav-link.current .icon { color: var(--primary); }
.nav-pill { margin-left: auto; background: var(--risk); color: #fff; border-radius: 999px; font-size: .7rem; font-weight: 700;
  padding: .05rem .45rem; min-width: 1.3rem; text-align: center; }
.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: .6rem; padding: .25rem .35rem; }
.avatar { width: 32px; height: 32px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 650; font-size: .78rem; flex: none; letter-spacing: .02em; }
.me-text { min-width: 0; flex: 1; line-height: 1.2; }
.me-name { font-weight: 600; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role { font-size: .75rem; color: var(--muted); }
.signout { margin: 0; }
.signout button { border: 0; background: transparent; color: var(--muted); padding: .4rem; border-radius: 8px; }
.signout button:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink); }

.content { min-width: 0; display: flex; flex-direction: column; }
main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 1.9rem 2.2rem 4rem; }

.banner { display: flex; gap: .6rem; align-items: flex-start; background: var(--warn-soft); color: var(--warn-ink);
  padding: .6rem 2.2rem; font-size: .87rem; border-bottom: 1px solid color-mix(in srgb, var(--warn-ink) 15%, transparent); }
.banner .icon { margin-top: .15rem; }
.banner.danger { background: var(--risk-soft); color: var(--risk-ink); font-weight: 550;
  border-bottom-color: color-mix(in srgb, var(--risk-ink) 15%, transparent); }
.banner code { background: color-mix(in srgb, currentColor 10%, transparent); }

/* Narrow screens: sidebar becomes a top bar with a disclosure menu */
.mobile-bar { display: none; }
@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .7rem 1rem;
    background: var(--sidebar); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
  .mobile-bar .brand { padding: 0; }
  .mobile-menu > summary { list-style: none; cursor: pointer; padding: .45rem; border-radius: 10px; color: var(--ink); }
  .mobile-menu > summary::-webkit-details-marker { display: none; }
  .mobile-menu[open] > summary { background: var(--surface); }
  .mobile-menu .sheet { position: absolute; left: .75rem; right: .75rem; top: 3.6rem; background: var(--sidebar);
    border: 1px solid var(--line); border-radius: var(--r-lg); padding: .5rem .6rem .75rem; box-shadow: var(--shadow-lg); }
  main { padding: 1.25rem 1rem 3rem; }
  .banner { padding: .55rem 1rem; }
}

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

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem 1.5rem; flex-wrap: wrap;
  margin-bottom: 1.6rem; }
.page-head > div:first-child { min-width: 0; flex: 1 1 420px; }
.eyebrow { display: flex; align-items: center; gap: .35rem; font-size: .82rem; color: var(--muted); margin-bottom: .45rem; }
.eyebrow a { color: var(--muted); text-decoration: none; }
.eyebrow a:hover { color: var(--ink); text-decoration: underline; }
.eyebrow .icon { opacity: .6; }
.lede { color: var(--ink-2); max-width: 68ch; margin-top: .45rem; font-size: .97rem; }
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.crumbs { display: none; }

/* ---------- Surfaces ---------- */

.card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.panel { padding: 1.25rem 1.35rem; }
.card { padding: 1.2rem 1.3rem; }
.panel + .panel, .panel + section, .tiles + .panel { margin-top: 1.25rem; }
.panel-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .9rem; flex-wrap: wrap; }
.panel-head .spacer { flex: 1; }
.panel-sub { color: var(--muted); font-size: .87rem; margin: -.5rem 0 .9rem; }
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 1.55rem; height: 1.35rem; padding: 0 .45rem;
  border-radius: 999px; background: var(--sunken); color: var(--ink-2); font: 600 .74rem/1 var(--font-text);
  text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.section-title { display: flex; align-items: center; gap: .55rem; margin: 2rem 0 .9rem; }
.empty { color: var(--muted); font-size: .92rem; }
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty-state .icon { color: var(--primary); opacity: .7; margin-bottom: .4rem; }
.empty-state p + p { margin-top: .2rem; font-size: .88rem; }

.cards { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); align-items: start; }

/* ---------- Buttons and controls ---------- */

button, .button { font: inherit; font-size: .9rem; font-weight: 550; display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem; min-height: 2.25rem; padding: .4rem .85rem; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; line-height: 1.2;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s; white-space: nowrap; }
button:hover:not(:disabled), .button:hover { border-color: var(--ink-2); color: var(--ink); }
button:disabled { opacity: .4; cursor: default; }
button.primary, .button.primary, .button:not(.secondary):not(.ghost) { background: var(--primary); border-color: var(--primary);
  color: var(--on-primary); }
button.primary:hover:not(:disabled), .button:not(.secondary):not(.ghost):hover { background: var(--primary-hover);
  border-color: var(--primary-hover); color: var(--on-primary); }
.button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
button.ghost, .button.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
button.ghost:hover:not(:disabled), .button.ghost:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); border-color: transparent; }
button.danger { color: var(--risk); }
button.danger:hover:not(:disabled) { border-color: var(--risk); color: var(--risk); background: var(--risk-soft); }
button.icon-btn { width: 2.25rem; padding: 0; }
button.small, .button.small { min-height: 1.95rem; padding: .25rem .6rem; font-size: .84rem; border-radius: 8px; }
button.icon-btn.small { width: 1.95rem; }

input, select, textarea { font: inherit; font-size: .92rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 10px; padding: .5rem .7rem; min-height: 2.35rem; width: 100%;
  transition: border-color .15s, box-shadow .15s; }
select { appearance: none; padding-right: 2rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23776C61' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .6rem center; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-2); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input[type="checkbox"], input[type="radio"] { width: 1.05rem; height: 1.05rem; min-height: 0; padding: 0; margin: 0;
  accent-color: var(--primary); flex: none; cursor: pointer; }
textarea { resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
label { display: flex; flex-direction: column; gap: .35rem; font-size: .84rem; font-weight: 550; color: var(--ink-2); flex: 1 1 170px; min-width: 0; }
label .hint, .hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; color: var(--ink); }
label.small { flex: 0 0 auto; }
label.narrow { flex: 0 1 120px; }
fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: .8rem 1rem 1rem; margin: 0; min-width: 0; }
legend { font-size: .8rem; font-weight: 600; color: var(--ink-2); padding: 0 .35rem; }
.row { display: flex; gap: .85rem; flex-wrap: wrap; align-items: flex-end; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack > label, .stack > div { flex: 0 0 auto; }
.form-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

details > summary { cursor: pointer; }
details.create { margin-top: 1.1rem; border-top: 1px solid var(--line); padding-top: 1rem; }
details.create > summary, .disclosure > summary { list-style: none; display: inline-flex; align-items: center; gap: .45rem;
  font-weight: 600; color: var(--primary); font-size: .92rem; }
details.create > summary::-webkit-details-marker, .disclosure > summary::-webkit-details-marker { display: none; }
details.create[open] > summary { margin-bottom: 1rem; }
details.create > summary .icon, .disclosure > summary .icon { transition: transform .15s; }
details.create[open] > summary .chev, .disclosure[open] > summary .chev { transform: rotate(180deg); }

/* Toggle switch (checkbox with role="switch") */
.switch { flex-direction: row; align-items: center; gap: .75rem; flex: 0 0 auto; cursor: pointer; color: var(--ink); font-weight: 600; font-size: .92rem; }
.switch input { appearance: none; width: 2.5rem; height: 1.45rem; border-radius: 999px; background: var(--line-strong);
  border: 0; position: relative; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: calc(1.45rem - 6px); height: calc(1.45rem - 6px);
  border-radius: 999px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(1.05rem); }

/* ---------- Badges and status ---------- */

.badge, .status { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; line-height: 1.35; white-space: nowrap; background: var(--sunken); color: var(--ink-2);
  vertical-align: middle; }
.badge .icon, .status .icon { width: 12px; height: 12px; }
.badge.risk { background: var(--risk-soft); color: var(--risk-ink); }
.badge.placed { background: var(--info-soft); color: var(--info-ink); }
.badge.custom { background: var(--plum-soft); color: var(--plum-ink); }
.badge.locked { background: var(--sunken); color: var(--ink-2); }
.badge.muted { background: var(--sunken); color: var(--muted); }
.badge.ok { background: var(--primary-soft); color: var(--primary-ink); }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; opacity: .85; }
.status-active, .status-completed, .status-answered { background: var(--primary-soft); color: var(--primary-ink); }
.status-invited, .status-scheduled, .status-sent { background: var(--info-soft); color: var(--info-ink); }
.status-withdrawn, .status-expired, .status-cancelled { background: var(--sunken); color: var(--muted); }
h1 .status, h1 .badge { font-family: var(--font-text); font-size: .76rem; margin-left: .5rem; vertical-align: .35em; letter-spacing: 0; }

/* ---------- Flash messages ---------- */

.flash { display: flex; gap: .6rem; align-items: flex-start; padding: .75rem .95rem; border-radius: var(--r-md); margin-bottom: 1rem;
  font-size: .92rem; border: 1px solid transparent; }
.flash .icon { margin-top: .12rem; }
.flash.error { background: var(--risk-soft); color: var(--risk-ink); border-color: color-mix(in srgb, var(--risk) 25%, transparent); }
.flash.ok { background: var(--primary-soft); color: var(--primary-ink); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.flash.info { background: var(--info-soft); color: var(--info-ink); }

/* ---------- Tiles ---------- */

.tiles { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 1.25rem; }
.tile { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 1.05rem 1.15rem 1rem; box-shadow: var(--shadow); }
.tile-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.tile-label { color: var(--ink-2); font-size: .85rem; font-weight: 550; }
.tile-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft);
  color: var(--primary-ink); }
.tile-icon.accent { background: var(--accent-soft); color: var(--accent-ink); }
.tile-icon.info { background: var(--info-soft); color: var(--info-ink); }
.tile-icon.risk { background: var(--risk-soft); color: var(--risk-ink); }
.tile-value { font-family: var(--font-display); font-size: 2.25rem; font-weight: 560; line-height: 1.1; margin-top: .45rem;
  font-variant-numeric: lining-nums tabular-nums; letter-spacing: -.02em; }
.tile-sub { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.tile-critical { border-color: color-mix(in srgb, var(--risk) 45%, var(--line)); background:
  linear-gradient(180deg, var(--risk-soft), var(--surface) 70%); }
.tile-critical .tile-value { color: var(--risk); }
.meter { height: 6px; border-radius: 999px; background: var(--sunken); overflow: hidden; margin-top: .6rem; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.meter.low > span { background: var(--accent); }

/* ---------- Overview layout ---------- */

.overview { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; margin-bottom: 1.25rem; }
@media (max-width: 1100px) { .overview { grid-template-columns: 1fr; } }
.overview > .panel { margin-top: 0; }

/* Alerts */
.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.alert-row { display: flex; gap: .85rem; align-items: center; padding: .8rem .9rem; border-radius: var(--r-md);
  background: var(--risk-soft); border: 1px solid color-mix(in srgb, var(--risk) 22%, transparent); flex-wrap: wrap; }
.alert-icon { width: 34px; height: 34px; border-radius: 999px; background: var(--surface); color: var(--risk);
  display: grid; place-items: center; flex: none; }
.alert-main { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: .1rem; color: var(--risk-ink); }
.alert-main a { color: var(--ink); font-weight: 650; text-decoration: none; }
.alert-main a:hover { text-decoration: underline; }
.alert-main .meta { color: color-mix(in srgb, var(--risk-ink) 75%, var(--muted)); font-size: .8rem; }
.alert-row button { background: var(--surface); }
.all-clear { display: flex; align-items: center; gap: .85rem; padding: .9rem 1rem; border-radius: var(--r-md);
  background: var(--primary-soft); color: var(--primary-ink); }
.all-clear .alert-icon { color: var(--primary); }
.note { margin-top: .85rem; font-size: .82rem; color: var(--muted); display: flex; gap: .45rem; align-items: flex-start; }
.note .icon { margin-top: .1rem; flex: none; }

/* Engine card */
.engine-facts { display: grid; grid-template-columns: auto 1fr; gap: .55rem 1rem; margin: 0; font-size: .9rem; }
.engine-facts dt { color: var(--muted); }
.engine-facts dd { margin: 0; color: var(--ink); font-weight: 500; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; margin: 0 -1.35rem; padding: 0 1.35rem; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .9rem; }
th, td { text-align: left; padding: .72rem .75rem; border-top: 1px solid var(--line); vertical-align: middle; }
thead th { border-top: 0; color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  white-space: nowrap; padding-top: .35rem; padding-bottom: .55rem; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: color-mix(in srgb, var(--sunken) 55%, transparent); }
tbody th { font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
.person { display: flex; align-items: center; gap: .65rem; }
.person a { color: var(--ink); text-decoration: none; font-weight: 600; }
.person a:hover { color: var(--primary); text-decoration: underline; }
.person .meta { font-size: .76rem; font-weight: 400; }
.day-cell { min-width: 110px; }
.day-cell .meter { margin-top: .35rem; height: 4px; }
.rate { display: inline-flex; align-items: center; gap: .5rem; justify-content: flex-end; }
.rate .meter { width: 52px; margin: 0; height: 5px; }
.signal { display: inline-flex; align-items: center; gap: .3rem; font-variant-numeric: tabular-nums; }
.signal-high { color: var(--accent-ink); font-weight: 700; }
.risk-value { color: var(--risk); font-weight: 700; }
.people th, .people td { white-space: nowrap; }

/* ---------- Charts ---------- */

.charts { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); }
.chart-card { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1rem 1.1rem .7rem;
  box-shadow: var(--shadow); }
.chart-card figcaption { margin-bottom: .55rem; display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: baseline; }
.chart-title { font-weight: 600; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
svg.chart .tick { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
svg.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font-text); }
svg.chart .series { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .point { fill: var(--primary); stroke: var(--surface); stroke-width: 2; }
svg.chart .point.over { fill: var(--risk); }
svg.chart .threshold { stroke: var(--risk); stroke-width: 1; stroke-dasharray: 4 3; opacity: .8; }
svg.chart .threshold-label { fill: var(--risk); font-size: 10px; }
svg.chart .target { fill: transparent; }
svg.chart .hit:hover .point { r: 5.5; }
svg.chart .bar { fill: var(--primary); opacity: .85; }
svg.chart .bar-track { fill: var(--sunken); }
svg.chart .bar.low { fill: var(--accent); }
details.more-charts { margin-top: 1rem; }

/* ---------- Participant page ---------- */

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0; margin: 0 0 1.25rem; padding: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }
.fact { padding: .9rem 1.1rem; border-left: 1px solid var(--line); margin: -1px 0 0 -1px; border-top: 1px solid var(--line); }
.fact dt { font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.fact dd { margin: .25rem 0 0; font-weight: 550; font-size: .95rem; }
.fact dd .meta { font-weight: 400; font-size: .8rem; }
.code-chip { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .08em; font-weight: 600; background: var(--sunken);
  padding: .1rem .45rem; border-radius: 6px; }
.timeline { min-width: 980px; }
.timeline td { vertical-align: top; }
.timeline tr.has-alert td:first-child { box-shadow: inset 3px 0 0 var(--risk); padding-left: .75rem; }
.timeline td:nth-child(4) { min-width: 300px; }
.timeline td:last-child { min-width: 240px; max-width: 360px; white-space: normal; }
.answers { display: flex; flex-wrap: wrap; gap: .3rem .35rem; }
.answer { background: var(--sunken); border-radius: 7px; padding: .1rem .45rem; white-space: nowrap; font-variant-numeric: tabular-nums; font-size: .84rem; }
.answer strong { font-weight: 650; }
.answer-label { color: var(--muted); }
.answer-risk { background: var(--risk-soft); color: var(--risk-ink); font-weight: 600; }
.answer-risk .answer-label { color: inherit; }
.why { color: var(--ink-2); font-size: .85rem; }
.why strong { color: var(--ink); text-transform: capitalize; }

/* ---------- Protocol workspace ---------- */

.workspace { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 1000px) { .workspace { grid-template-columns: 1fr; } }
.workspace > .panel { margin-top: 0; }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-box input { padding-left: 2.3rem; }
.menu-count { margin: .6rem 0 .25rem; font-size: .82rem; }
.menu, .entries { list-style: none; margin: 0; padding: 0; }
.menu { max-height: 70vh; overflow-y: auto; margin: 0 -1.35rem; padding: 0 1.35rem; }
.menu-item, .entry { display: flex; gap: .75rem 1rem; justify-content: space-between; align-items: flex-start;
  padding: .85rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.menu-item:first-child, .entry:first-child { border-top: 0; }
.item-main { flex: 1 1 260px; min-width: 0; }
.item-text { font-weight: 500; color: var(--ink); }
.meta { font-size: .8rem; display: flex; flex-wrap: wrap; gap: .3rem .55rem; align-items: center; margin-top: .3rem; }
.meta.stem { margin: 0 0 .2rem; font-style: italic; }
.meta.followup { margin: .2rem 0 0; color: var(--primary-ink); }
code.item-id { font-size: .72rem; color: var(--muted); background: transparent; padding: 0; }
.add-form { display: flex; gap: .4rem; align-items: center; flex: 0 0 auto; }
.add-form select { width: auto; min-width: 11rem; min-height: 2.05rem; padding-top: .3rem; padding-bottom: .3rem; font-size: .85rem; }
.add-form button { min-height: 2.05rem; }
.section { padding: .9rem 0 1rem; border-top: 1px solid var(--line); }
.section:first-of-type { border-top: 0; padding-top: 0; }
.section-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; }
.section-head h3 { margin: 0; }
.section-desc { font-size: .8rem; color: var(--muted); margin-bottom: .35rem; }
.entries { counter-reset: entry; }
.entry { counter-increment: entry; align-items: center; }
.entry .item-main { display: flex; gap: .75rem; align-items: flex-start; }
.entry .item-main::before { content: counter(entry); flex: none; width: 1.6rem; height: 1.6rem; border-radius: 999px; background: var(--sunken);
  color: var(--ink-2); font-size: .75rem; font-weight: 650; display: grid; place-items: center; margin-top: .05rem;
  font-variant-numeric: tabular-nums; }
.entry-body { min-width: 0; flex: 1; }
.entry-actions { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.entry-actions select { width: auto; min-height: 1.95rem; padding: .2rem 1.9rem .2rem .55rem; font-size: .82rem; }
.entry-actions label.check { font-size: .82rem; }
.settings-row { display: flex; flex-wrap: wrap; gap: .6rem 1.25rem; align-items: center; margin-bottom: 1.25rem; }
.settings-row .meta { margin: 0; flex: 1 1 280px; font-size: .84rem; }

/* ---------- Libraries ---------- */

.library-card { display: flex; flex-direction: column; gap: .6rem; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; }
.card-head h2 { font-size: 1.12rem; }
.card-head a { color: var(--ink); text-decoration: none; }
.card-head a:hover { color: var(--primary); }
.lib-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft);
  color: var(--primary-ink); flex: none; }
.lib-icon.custom { background: var(--plum-soft); color: var(--plum-ink); }
.card-title { display: flex; gap: .8rem; align-items: center; min-width: 0; }
.desc { color: var(--ink-2); font-size: .92rem; }
.card-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .25rem; }
.card-foot { margin-top: auto; padding-top: .8rem; border-top: 1px solid var(--line); display: flex; justify-content: space-between;
  align-items: center; gap: .5rem; flex-wrap: wrap; }
.new-card { border-style: dashed; box-shadow: none; background: transparent; }
.library-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.panel.tight { margin-bottom: 1rem; padding: 1rem 1.2rem; }
.panel.tight > summary, details.edit > summary, .add-support > summary { cursor: pointer; font-weight: 600; color: var(--primary); }
.panel.tight h2 { margin-bottom: .6rem; font-size: 1.05rem; }
.supports { display: flex; flex-direction: column; gap: 1rem; }
.support { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.5rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.25rem 1.35rem; box-shadow: var(--shadow); }
@media (max-width: 800px) { .support { grid-template-columns: 1fr; } }
.support.inactive { opacity: .62; }
.support-title { font-family: var(--font-display); font-size: 1.15rem; font-weight: 580; color: var(--ink); text-transform: none;
  letter-spacing: 0; margin: 0; }
.trigger { margin: .7rem 0 0; font-size: .9rem; color: var(--ink-2); display: flex; gap: .45rem; align-items: flex-start; }
.trigger .icon { margin-top: .15rem; color: var(--muted); }
details.edit { margin-top: .9rem; }
.phone { border: 1px solid var(--line); border-radius: 26px; padding: 1.1rem 1.15rem 1.3rem; background: var(--bg);
  max-height: 320px; overflow: auto; position: relative; }
.phone::before { content: ""; display: block; width: 54px; height: 5px; border-radius: 999px; background: var(--line-strong);
  margin: -.35rem auto .85rem; opacity: .7; }
.phone-type { margin: 0; font-size: .7rem; color: var(--primary-ink); text-transform: uppercase; letter-spacing: .08em; font-weight: 650; }
.phone-title { margin: .3rem 0 .5rem; font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; }
.phone-body { margin: 0; white-space: pre-line; font-size: .92rem; color: var(--ink-2); }

/* ---------- Studies ---------- */

.study-card { display: flex; flex-direction: column; gap: 1rem; padding: 1.35rem 1.4rem; }
.study-card h2 { font-size: 1.3rem; }
.study-card h2 a { color: var(--ink); text-decoration: none; }
.study-card h2 a:hover { color: var(--primary); }
.study-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; padding: .85rem 0; border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line); }
.study-stats dt { font-size: .74rem; color: var(--muted); font-weight: 600; }
.study-stats dd { margin: .1rem 0 0; font-family: var(--font-display); font-size: 1.5rem; font-weight: 560; font-variant-numeric: tabular-nums; }
.study-stats .alerting dd { color: var(--risk); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem .9rem; font-size: .84rem; color: var(--ink-2); }
.chips span { display: inline-flex; align-items: center; gap: .35rem; }
.chips .icon { color: var(--muted); }

/* ---------- Settings ---------- */

.settings-grid { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
@media (max-width: 1000px) { .settings-grid { grid-template-columns: 1fr; } }
.settings-section { padding: 1.35rem 1.4rem; }
.settings-section + .settings-section { margin-top: 1.25rem; }
.settings-section .row + .row { margin-top: 1rem; }
.section-intro { display: flex; gap: .85rem; align-items: flex-start; margin-bottom: 1.1rem; }
.section-intro p { color: var(--muted); font-size: .87rem; margin-top: .15rem; }
.choice-cards { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.choice { flex-direction: row; align-items: flex-start; gap: .6rem; padding: .8rem .9rem; border: 1px solid var(--line-strong);
  border-radius: var(--r-md); cursor: pointer; color: var(--ink); font-weight: 600; background: var(--surface); }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary); }
.choice input { margin-top: .2rem; }
.choice span { display: flex; flex-direction: column; gap: .15rem; }
.choice small { font-weight: 400; color: var(--muted); font-size: .8rem; }
.checklist { display: flex; flex-direction: column; gap: .45rem; max-height: 260px; overflow-y: auto; padding: .2rem; }
.checklist label.check { font-weight: 450; font-size: .9rem; }
.aside-card { padding: 1.2rem 1.25rem; position: sticky; top: 1.5rem; }
.aside-card h2 { font-size: 1.05rem; margin-bottom: .75rem; }
.save-bar { display: flex; gap: .75rem; align-items: center; justify-content: flex-end; margin-top: 1.25rem; }
.lock-note { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; color: var(--muted); font-weight: 450; }

/* ---------- Sign-in ---------- */

.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth-art { display: none; } }
.auth-art { position: relative; overflow: hidden; background: var(--primary); color: #F4EFE6; padding: 3rem; display: flex;
  flex-direction: column; justify-content: space-between; }
@media (prefers-color-scheme: dark) { .auth-art { background: #24382D; } }
.auth-art .brand { color: #FFFDF9; padding: 0; }
.auth-art .brand-sub { color: rgba(255, 253, 249, .7); }
.auth-art blockquote { margin: 0; max-width: 30ch; font-family: var(--font-display); font-size: 2.1rem; line-height: 1.2; font-weight: 500;
  letter-spacing: -.015em; position: relative; z-index: 1; }
.auth-art .art-foot { font-size: .85rem; color: rgba(255, 253, 249, .75); position: relative; z-index: 1; max-width: 46ch; }
.auth-art svg.waves { position: absolute; right: -10%; bottom: -5%; width: 90%; opacity: .9; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 2.5rem 1.25rem; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h1 { font-size: 2rem; }
.auth-box .lede { margin-bottom: 1.6rem; }
.auth-box form { gap: 1.1rem; }
.auth-box button[type="submit"] { width: 100%; min-height: 2.75rem; font-size: .97rem; }
.auth-mobile-brand { display: none; }
@media (max-width: 900px) { .auth-mobile-brand { display: flex; margin-bottom: 2rem; padding: 0; } }
.auth-help { margin-top: 1.4rem; font-size: .84rem; color: var(--muted); }

/* ---------- Misc ---------- */

.filter { margin-bottom: 1rem; align-items: flex-end; }
.filter label { max-width: 360px; }
details.inline > summary { color: var(--primary); font-size: .86rem; font-weight: 550; }
details.inline .row { margin-top: .5rem; min-width: 280px; }
details.more-charts > summary { font-weight: 600; color: var(--primary); margin-bottom: .75rem; }
.signal-note { display: none; }
.invite { align-items: flex-end; }
.invite .end { flex: 0 0 auto; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .82rem; }
.audit-action { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .8rem; background: var(--sunken); padding: .1rem .4rem;
  border-radius: 6px; }

/* SVG meters (inline styles are blocked by the CSP) */
.meter-svg { display: block; width: 100%; height: 6px; margin-top: .6rem; }
.meter-svg .track { fill: var(--sunken); }
.meter-svg .fill { fill: var(--primary); }
.meter-svg.low .fill { fill: var(--accent); }
.meter-svg.thin { height: 4px; margin-top: .35rem; }
.rate .meter-svg { width: 52px; margin: 0; height: 5px; }

/* Inline metadata (the flex .meta row is for <p>/<div>) */
span.meta { display: inline; margin-top: 0; }
span.meta.block, .meta.block { display: block; }
.response-chart svg.chart .axis { font-size: 12px; }
.study-card .chips { margin-top: .5rem; }
fieldset.choice-cards { border: 0; padding: 0; margin: 0 0 1rem; }
.checklist label { flex: 0 0 auto; }
input[readonly] { background: var(--sunken); color: var(--muted); cursor: not-allowed; }
.section-intro h2 { font-size: 1.12rem; }
.audit-detail { white-space: normal; min-width: 260px; color: var(--ink-2); }
.filter .search-box { display: block; }
.auth-art .brand img { box-shadow: 0 0 0 1.5px rgba(255, 253, 249, .4); }
@media (max-width: 600px) {
  .tiles { grid-template-columns: 1fr 1fr; gap: .65rem; }
  .tile { padding: .85rem .9rem; }
  .tile-icon { display: none; }
  .tile-value { font-size: 1.7rem; }
  .tile-label { font-size: .8rem; }
  h1 { font-size: 1.6rem; }
  .page-head { margin-bottom: 1.1rem; }
  .panel { padding: 1rem; }
  .table-wrap { margin: 0 -1rem; padding: 0 1rem; }
  .menu { margin: 0 -1rem; padding: 0 1rem; }
}

/* Compact per-item trend cards */
.chart-card { padding: .7rem .95rem .4rem; }
.chart-card figcaption { margin-bottom: .2rem; font-size: .9rem; }
.charts { gap: .75rem; }

/* Raw answers are faint; the LOESS curve carries the trend */
svg.chart .series { stroke: var(--line-strong); stroke-width: 1.25; }
svg.chart .point { fill: color-mix(in srgb, var(--primary) 55%, var(--surface)); stroke-width: 1.5; }
svg.chart .trend { fill: none; stroke: var(--primary); stroke-width: 2.75; stroke-linecap: round; stroke-linejoin: round; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; align-items: center; margin: -.4rem 0 .8rem; font-size: .82rem; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.chart-legend svg { flex: none; }
.chart-legend .sw-trend { stroke: var(--primary); stroke-width: 3; stroke-linecap: round; }
.chart-legend .sw-dot { fill: color-mix(in srgb, var(--primary) 55%, var(--surface)); }
.chart-legend .sw-line { stroke: var(--line-strong); stroke-width: 1.5; }
.chart-legend .sw-threshold { stroke: var(--risk); stroke-width: 1.5; stroke-dasharray: 4 3; }

/* Must follow the .auth-art rule above: hide the brand panel on narrow screens */
@media (max-width: 900px) { .auth-art { display: none; } }

/* ---------- Invites: QR codes, invite page, public join page ---------- */

/* QR codes stay dark-on-white in every theme: scanners need the contrast. */
.qr-frame { background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); padding: .5rem; line-height: 0; }
.qr-frame svg.qr { display: block; width: 100%; height: auto; shape-rendering: crispEdges; }

/* Staff dashboard: shown right after an enrollment code is created */
.invite-ready { display: flex; gap: 1.25rem; align-items: center; margin-bottom: 1.25rem;
  border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); }
.invite-ready .qr-frame { width: 128px; flex: none; }
.invite-ready-main { min-width: 0; display: flex; flex-direction: column; gap: .45rem; }
.invite-ready .actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .3rem; }
.join-link-row code { font-size: .82rem; word-break: break-all; background: none; padding: 0; color: var(--ink-2); }
@media (max-width: 600px) { .invite-ready { flex-direction: column; align-items: flex-start; } }

/* Staff invite page: printable sheet + share panel */
.invite-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(280px, .85fr); gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .invite-layout { grid-template-columns: 1fr; } }
.invite-sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow);
  padding: 2rem 2.2rem 1.6rem; }
.invite-sheet .brand { padding: 0 0 1.4rem; }
.invite-sheet h2 { font-size: 1.75rem; }
.sheet-lede { color: var(--ink-2); margin-top: .4rem; font-size: 1.02rem; }
.sheet-body { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 1.6rem; align-items: center; margin: 1.6rem 0; }
@media (max-width: 600px) { .sheet-body { grid-template-columns: 1fr; } .sheet-body .qr-frame { max-width: 220px; } }
.sheet-steps { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .8rem; color: var(--ink); font-size: 1rem; }
.sheet-steps li::marker { color: var(--primary); font-weight: 700; }
.sheet-code, .join-code { display: block; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-weight: 650; color: var(--ink); }
.sheet-code { font-size: 1.55rem; letter-spacing: .16em; margin-top: .35rem; }
.sheet-foot, .join-foot { display: flex; gap: .5rem; align-items: flex-start; color: var(--muted); border-top: 1px solid var(--line);
  padding-top: 1rem; }
.sheet-foot { font-size: .85rem; }
.sheet-foot .icon, .join-foot .icon { margin-top: .2rem; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field > label { flex: none; }
.copy-row { display: flex; gap: .5rem; }
.copy-row input[readonly] { color: var(--ink); cursor: text; font-size: .85rem; }
.copy-row button { flex: none; min-width: 6.2rem; }
.code-input { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .12em; font-weight: 600; }
.fact-link { font-size: .8rem; font-weight: 500; margin-left: .3rem; }

/* Public join page (participants, usually on a phone): body text at least 17 px, tap targets at least 48 px */
.join { max-width: 980px; margin: 0 auto; padding: 2rem 1.25rem 3rem; }
.join-brand { padding: 0 0 1.75rem; }
.join-grid { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 2rem; align-items: start; }
.join-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow);
  padding: 2.2rem 2.2rem 1.6rem; }
.join-card h1 { font-size: 2.2rem; }
.join-card .lede { font-size: 1.2rem; max-width: 46ch; }
.join-steps { list-style: none; margin: 2rem 0 1.6rem; padding: 0; display: flex; flex-direction: column; gap: 1.6rem; }
.join-steps li { display: grid; grid-template-columns: 2.25rem minmax(0, 1fr); gap: 1rem; align-items: start; }
.step-n { width: 2.25rem; height: 2.25rem; border-radius: 50%; background: var(--primary-soft); color: var(--primary-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 1.05rem; }
.join-steps h2 { font-family: var(--font-text); font-size: 1.2rem; font-weight: 650; letter-spacing: 0; margin: .25rem 0 .3rem; }
.join-steps p { color: var(--ink-2); font-size: 1.135rem; }
.join-open, .store-links .button { min-height: 3.2rem; font-size: 1.135rem; padding: 0 1.4rem; border-radius: var(--r-md); }
.join-open { margin-top: .8rem; }
.store-links { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .3rem; }
.join-code { font-size: 2rem; letter-spacing: .22em; margin-top: .7rem; padding: .7rem 1rem; text-align: center;
  background: var(--sunken); border-radius: var(--r-md); }
.join-foot { font-size: 1rem; }
.join-qr { position: sticky; top: 2rem; }
.join-qr p { font-size: .95rem; color: var(--muted); margin-top: .85rem; }
@media (max-width: 760px) {
  .join { padding: 1.25rem 1rem 2.5rem; }
  .join-grid { grid-template-columns: 1fr; }
  .join-qr { display: none; } /* already on a phone */
  .join-card { padding: 1.5rem 1.25rem 1.25rem; border-radius: var(--r-lg); }
  .join-card h1 { font-size: 1.85rem; }
  .join-open { width: 100%; }
  .join-code { font-size: 1.7rem; letter-spacing: .16em; }
}

/* Printing the invite: just the sheet, always in light colours */
@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --sunken: #F0EBE2; --line: #D3C8B8; --ink: #2B2621; --ink-2: #554D45;
    --muted: #665C52; --primary: #3E6A55; --primary-ink: #2C5242; --primary-soft: #E3EDE6; --shadow: none; }
  body { background: #fff; }
  .sidebar, .mobile-bar, .banner, .no-print { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  .invite-layout { display: block; }
  .invite-sheet { max-width: 17cm; margin: 0 auto; border: 1.5px solid #D3C8B8; break-inside: avoid; }
  .sheet-body { grid-template-columns: 6cm minmax(0, 1fr); }
}

/* Invites tab */
.row-actions { display: flex; gap: .4rem; justify-content: flex-end; flex-wrap: wrap; }
.row-actions .button, .row-actions button { white-space: nowrap; }
.invites-note { margin-top: 1rem; font-size: .84rem; }

/* Staff accounts: risk-alert emails */
.recipients { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-wrap: wrap; gap: .45rem; }
.recipients li { display: inline-flex; align-items: center; gap: .4rem; background: var(--sunken); border-radius: 999px;
  padding: .3rem .75rem; font-size: .88rem; color: var(--ink); }
.recipients li .icon { color: var(--muted); }
.recipients-note { margin-top: .9rem; font-size: .82rem; }

/* Period toggle (segmented links) */
.segmented { display: inline-flex; background: var(--sunken); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented a { padding: .35rem .75rem; border-radius: 8px; font-size: .86rem; font-weight: 550; color: var(--ink-2); text-decoration: none; }
.segmented a:hover { color: var(--ink); }
.segmented a.current { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* Between-visit summary */
.summary-sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow);
  padding: 1.6rem 1.8rem 1.2rem; }
.summary-head { display: flex; gap: 1rem 2rem; align-items: flex-start; justify-content: space-between; flex-wrap: wrap;
  padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.summary-head .brand { padding: 0; order: 2; }
.summary-head .brand img { width: 28px; height: 28px; border-radius: 8px; }
.summary-head h2 { font-size: 1.45rem; }
.summary-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem 1.25rem; margin: 1.1rem 0 .4rem; }
.summary-facts dt { font-size: .72rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }
.summary-facts dd { margin: .2rem 0 0; font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.summary-facts dd .meta { font-size: .8rem; font-weight: 400; }
.summary-section { margin-top: 1.3rem; }
.summary-section h3, .summary-sub { margin-bottom: .6rem; }
.summary-sub { margin-top: 1rem; }
.summary-charts { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); }
.summary-chart { box-shadow: none; }
.change { display: inline-flex; align-items: center; gap: .15rem; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--ink); }
.summary-table { font-size: .87rem; }
.summary-table td { vertical-align: top; }
.summary-empty { margin-top: 1rem; color: var(--muted); }
.summary-foot { margin-top: 1.4rem; padding-top: .8rem; border-top: 1px solid var(--line); font-size: .78rem; color: var(--muted); }

@media print {
  .summary-sheet { border: 0; padding: 0; border-radius: 0; }
  .summary-charts { grid-template-columns: 1fr 1fr; gap: .4rem; }
  .summary-chart { padding: .35rem .5rem .1rem; break-inside: avoid; }
  .summary-chart figcaption { font-size: .78rem; margin-bottom: 0; }
  .summary-table { font-size: .78rem; }
  .summary-table th, .summary-table td { padding: .3rem .4rem; }
  .summary-section { margin-top: .8rem; break-inside: avoid-page; }
  .summary-facts dd { font-size: .95rem; }
  .table-wrap { overflow: visible; }
}
@media print {
  .summary-head { flex-wrap: nowrap; }
  .summary-facts { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* Protocol: standard questionnaires */
.questionnaires { border: 1px solid var(--line); border-radius: var(--r-md); padding: .7rem .9rem; margin-bottom: 1rem;
  background: var(--sunken); display: flex; flex-direction: column; gap: .55rem; }
.q-label { font-size: .72rem; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.questionnaire { display: flex; align-items: center; justify-content: space-between; gap: .5rem 1rem; flex-wrap: wrap; }
.q-main { display: flex; align-items: center; gap: .35rem .6rem; flex-wrap: wrap; min-width: 0; }
.q-name { font-weight: 650; color: var(--ink); }

/* Questionnaire scores (participant page, visit summary) */
.scale-latest { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; margin: .1rem 0 .4rem; }
.scale-total { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; line-height: 1; color: var(--ink);
  font-variant-numeric: tabular-nums; }
.scale-flag { display: flex; align-items: center; gap: .35rem; margin: 0 0 .4rem; font-size: .84rem; font-weight: 550;
  color: var(--risk-ink); background: var(--risk-soft); border-radius: 8px; padding: .3rem .55rem; }
