/**
 * Reusable UI primitives. Depends on tokens.css + base.css.
 */

/* --- Brand mark --- */

.brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

.brand img {
  display: block;
  height: var(--logo-h);
  width: auto;
}

/* Clinic brand slot (tono-5vv1): the clinic's lockup, or its name as a
   text lockup when it has no logo. Never Tonotop on the patient side. */
.brand--clinic img {
  height: 2.75rem;
  max-width: 14rem;
  width: auto;
  object-fit: contain;
}

.brand-text {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  color: var(--ink);
  white-space: nowrap;
}

/* Divider + uppercase tagline after the brand. Lives here, not in
   layout.css: the auth pages load primitives without layout, and a
   tagline with no rules pushed the lockup off the card's centre line
   (Micah 2026-09-14). */
.brand-tagline {
  max-width: 13.125rem; /* MVP 210px */
  padding-left: var(--space-4);
  border-left: 1px solid var(--line);
  font-size: var(--text-xs);
  line-height: 1.25;
  text-transform: uppercase;
  color: var(--muted);
}

@media (width < 48rem), (height < 32rem) {
  .brand-tagline { display: none; }
}

/* Back in the iPhone home-screen app: a 44px target whose chevron
   sits on the header's edge, so the logo moves over as little as it can. */
.header-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0 -0.5rem 0 -0.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--accent-ink);
  font-size: 1.375rem;
  cursor: pointer;
}

.header-back[hidden] {
  display: none;
}

.header-back:hover {
  background: var(--accent-soft);
}

/* Clinic support button, header right, ahead of the user menu */
.support-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.support-button svg {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--accent-ink);
}

.support-button:hover {
  border-color: var(--accent-ink);
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.support-button--icon {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  justify-content: center;
}

.support-button--icon svg {
  width: 1.5rem;
  height: 1.5rem;
}

/* the unread count on the header's Messages button (proposal, Micah 2026-11-02) */
#messages-link {
  position: relative;
}

.header-badge {
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: var(--radius-pill);
  background: var(--accent-ink);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.25rem;
  text-align: center;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
}

/* Keep phone-only hidden text in the accessibility tree, unlike display:none. */
@media (width < 40rem) {
  .sr-only-phone {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    clip: rect(0 0 0 0);
    overflow: hidden;
    white-space: nowrap;
    border: 0;
  }

  .support-button {
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0;
    justify-content: center;
  }

  .header-badge {
    position: absolute;
    top: -0.25rem;
    right: -0.25rem;
  }
}

/* Guest landing uses class "sign-in" (kept for existing selectors / specs).
   Prefer a.button.secondary for new chrome actions. */
.sign-in {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
}

.sign-in:hover {
  border-color: var(--accent-ink);
  color: var(--accent-ink);
  background: var(--accent-soft);
}

/* MVP back button: white circle with accent ring + chevron. Shared by
   clinician profile and patient module/activity headers. */
.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4rem;
  height: 4rem;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--accent-ink), 0 4px 24px rgba(0, 0, 0, 0.02);
  color: var(--accent-ink);
  font-size: 1.25rem;
}

.back-button:hover {
  background: var(--accent-soft);
}

/* --- User account menu (details/summary) --- */

.user-menu {
  position: relative;
  /* shrink to the pill: as a block it stretches, and the right-anchored
     panel opens at the container's far edge instead of under the pill */
  display: inline-block;
}

/* The pill itself — avatar + address. Its own class, not a descendant of
   <summary>, so a preview that renders the pill without a menu around it
   looks identical (Micah 2026-09-14: no forks). */
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.25rem;
  border-radius: var(--radius-pill);
  color: var(--muted-strong);
  font: inherit;
  font-size: var(--text-lg); /* MVP 18px/600 header identity */
  font-weight: 600;
  max-width: var(--menu-max);
}

/* Only what makes it a disclosure control. */
.user-menu summary {
  list-style: none;
  cursor: pointer;
}

/* MVP avatar disc: 40px circle, lavender-gray fill, slate person glyph */
.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: #d4d2e3;
  color: #8189a3;
  font-size: 1.375rem; /* 22px glyph */
}

.user-menu summary::-webkit-details-marker {
  display: none;
}

.user-menu summary::after {
  content: "\25BE";
  color: var(--muted-strong);
  font-size: 1.25rem;
  line-height: 1;
  transition: transform 150ms ease;
}

.user-menu[open] summary::after {
  transform: rotate(180deg);
}

.user-menu[open] .user-avatar {
  box-shadow: 0 0 0 2px var(--accent-soft-strong);
}

.user-email {
  min-width: 0;
  flex: 0 1 auto;
  overflow-wrap: anywhere;
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 12rem;
  margin: 0;
  padding: 0.4rem 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-menu);
  z-index: 20;
}

.user-menu-panel a {
  display: block;
  padding: 0.55rem 0.9rem;
  color: var(--ink);
  text-decoration: none;
  font-size: var(--text-sm);
}

.user-menu-panel a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* blue icon leading each menu item */
.user-menu-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--accent-ink);
  font-size: 1.15rem;
}

.user-menu-panel a:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.user-menu-panel form {
  margin: 0;
}

.user-menu-panel form button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 0.55rem 0.9rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.user-menu-panel form button:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* The full signed-in identity stays available when the pill is clipped. */
.user-menu-identity {
  display: block;
  padding: 0.55rem 0.9rem 0.65rem;
  margin-bottom: 0.3rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

/* The phone menu button: bars + "Menu", an X while open. Hidden on desktop. */
.user-menu-burger,
.user-menu-close-row {
  display: none;
}

/* Phones: a labelled Menu button replaces the avatar pill, and the menu opens
   as a full sheet under the header (tono-kx4s, Micah 2026-09-30). The address
   moves into the menu. */
@media (width < 48rem), (height < 32rem) {
  .user-pill .user-email,
  .user-pill .user-avatar,
  .user-menu summary::after {
    display: none;
  }

  .user-menu-burger {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 2.75rem;
    padding: 0 var(--space-2);
    color: var(--ink);
    font-size: var(--text-md);
    font-weight: 600;
  }

  /* icon and label share one centre line: the svg is a block, not a glyph
     riding the text baseline */
  .user-menu-burger-open,
  .user-menu-burger-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    line-height: 1;
  }

  .user-menu-burger svg {
    display: block;
    width: 2rem;
    height: 2rem;
  }

  /* "Menu" first, then the bars, so the X lands in the far right corner */
  .user-menu-burger-label {
    line-height: 1;
    order: -1;
  }

  .user-pill:has(.user-menu-burger) {
    padding: 0;
    gap: 0;
    align-items: center;
  }

  .user-menu-burger .user-menu-burger-close,
  .user-menu[open] .user-menu-burger-open {
    display: none;
  }

  .user-menu[open] .user-menu-burger-close {
    display: inline-flex;
  }

  .user-menu[open] .user-avatar {
    box-shadow: none;
  }

  .user-menu[open] .user-menu-panel {
    position: fixed;
    top: 3.5rem;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    min-width: 0;
    margin: 0;
    padding: var(--space-2) 0 0;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
    overflow-y: auto;
    z-index: 29;
  }

  /* Close sits at the bottom of the screen, in thumb reach, whatever the
     menu's length (Micah 2026-10-01): the sheet is a column and the Close
     row takes the slack above it, pinned if the items ever scroll. */
  .user-menu[open] .user-menu-panel {
    display: flex;
    flex-direction: column;
  }

  .user-menu[open] .user-menu-panel .user-menu-close-row {
    display: block;
    position: sticky;
    bottom: 0;
    margin-top: auto;
    padding: var(--space-3) var(--space-5) calc(var(--space-3) + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
  }

  .user-menu[open] .user-menu-panel .user-menu-close {
    display: flex;
    justify-content: center;
    width: 100%;
    min-height: 3rem;
  }

  .user-menu[open] .user-menu-panel a,
  .user-menu[open] .user-menu-panel form button {
    padding: var(--space-4) var(--space-5);
    font-size: 1.125rem;
    border-bottom: 1px solid var(--line);
  }

  /* the address reads as the sheet's title, not a row */
  .user-menu[open] .user-menu-panel .user-menu-identity {
    padding: var(--space-4) var(--space-5) var(--space-3);
    margin: 0;
    text-align: center;
    font-size: var(--text-sm);
    font-weight: 400;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
  }

  .user-menu-identity {
    display: block;
  }

  .user-menu-panel {
    max-width: calc(100vw - 2rem);
  }
}

/* --- Card (foundation for future mock screens) --- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-menu);
  padding: var(--space-6);
}

.card + .card {
  margin-top: var(--space-6);
}

.card h2 {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0 0 var(--space-4);
  color: var(--ink);
}

/* --- Stacks & lists --- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}






.empty-state {
  color: var(--muted);
  font-style: italic;
  font-size: var(--text-sm);
  margin: 0;
}

/* --- Forms ---
 *
 * Structure (error attached to the field, not a free-floating alert):
 *
 *   <div class="field error">
 *     <label for="email">Email</label>
 *     <input id="email" type="email"
 *            aria-invalid="true"
 *            aria-describedby="email-err">
 *     <p id="email-err" class="error" role="alert">…</p>
 *   </div>
 *
 * - .field         layout shell (label + control + optional hint/error)
 * - .field.error   invalid state (red outline on the control)
 * - .field p.error error message (id matches control's aria-describedby)
 * - .field p.hint  helper text (same attachment pattern)
 * - .field.checkboxes  checkbox/radio row (control + label side by side)
 */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
}

.field .required {
  color: var(--accent-ink);
  font-weight: 700;
}

.field p.hint {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--muted);
  line-height: var(--leading-body);
  max-width: 24rem;
}

/* A hint in the warning tone: something to know, not a reason the form
   cannot be saved (a blocked mobile number, tono-xtnh). */
.field.field--warn p.hint {
  color: var(--warn-ink);
}

/* Message node owned by the field — sibling of the control */
.field p.error {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--danger);
  line-height: var(--leading-body);
  max-width: 24rem;
}

.field input[type="email"],
.field input[type="password"],
.field input[type="text"],
.field input[type="search"],
.field input[type="number"],
.field input[type="tel"],
.field input[type="url"],
.field input[type="date"],
.field textarea,
.field select {
  font: inherit;
  font-size: var(--text-md); /* MVP generosity: controls read at body size */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  width: 100%;
  max-width: 24rem;
}

/* Input + trailing affix (e.g. search SVG icon) */
.field-control {
  position: relative;
  width: 100%;
  max-width: 24rem;
}

.field-control input {
  max-width: none;
}

.field-control--affix-end input {
  padding-right: 2.25rem;
}

.field-affix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  font-size: 1rem; /* icons default to 1em — size via font-size */
  color: var(--muted);
  user-select: none;
}

.field-affix--end {
  right: 0.65rem;
}

.field-affix--start {
  left: 0.65rem;
}

/* Input with a trailing action button, one outline shared by both */
.field-control--action {
  display: flex;
  align-items: stretch;
}

.field .field-control--action input {
  flex: 1 1 auto;
  min-width: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.field-action {
  flex-shrink: 0;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.field-action:hover { background: var(--accent-soft); }

.field-action:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-action:disabled {
  color: var(--muted);
  background: var(--paper);
  cursor: default;
}

/* .field scope: outranks .field input[type=…] base padding */
.field .field-control--affix-start input {
  padding-left: 2.1rem;
}

.field-affix svg {
  display: block;
}

.field textarea {
  min-height: 5.5rem;
  resize: vertical;
  line-height: var(--leading-body);
}

.field select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.field-control--affix-end select {
  max-width: none;
  padding-right: 2.25rem;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent-ink);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Error outline on every control type (text, textarea, select, …).
   Border only at rest (no extra outer ring); light ring only on focus. */
.field.error input,
.field.error textarea,
.field.error select {
  border-color: var(--danger);
}

.field.error input:focus,
.field.error textarea:focus,
.field.error select:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px var(--danger-soft);
}

.field input:disabled,
.field textarea:disabled,
.field select:disabled {
  background: var(--paper);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.85;
}

/* One-time code (tonotop.ui.code-input). Server and browser render the
   same boxes, one per character, so nothing moves when the bundle
   hydrates. No motion. */
.code-input-boxes {
  display: flex;
  gap: var(--space-2);
  width: 100%;
  max-width: 24rem;
}

.field input.code-input-box {
  flex: 1 1 0;
  min-width: 0;
  max-width: 3.25rem;
  height: 3.25rem; /* touch target well over 44px */
  padding: 0;
  text-align: center;
  font-size: var(--text-xl);
  font-weight: 600;
  text-transform: uppercase;
  caret-color: var(--accent-ink);
}

.field.checkboxes {
  flex-direction: row;
  align-items: flex-start;
  gap: var(--space-3); /* MVP option rows: 12px control-to-label */
  max-width: 28rem;
}

/* A checkbox's hint or inline error takes its own line under the label,
   indented to the label (2026-09-28). */
.field.checkboxes:has(> p.hint, > p.error) {
  flex-wrap: wrap;
}

.field.checkboxes:has(> p.hint, > p.error) > label {
  flex: 1 1 0;
  min-width: 0;
}

/* A disabled checkbox row reads as unavailable: box and label dimmed, with
   the not-allowed cursor (same conventions as .field input:disabled and
   .field.switch input:disabled). The hint stays full strength: it says why. */
.field.checkboxes.is-disabled input,
.field.checkboxes.is-disabled label {
  opacity: 0.45;
  cursor: not-allowed;
}

/* The instruction above a disabled consent question dims with it, so the
   clinician is not told to ask a question they cannot yet record
   (Micah 2026-10-01). */
.cp-sms-consent[data-disabled="true"] > .cp-sms-ask {
  opacity: 0.45;
}

.field.checkboxes > p.hint,
.field.checkboxes > p.error {
  flex-basis: 100%;
  margin: 0 0 0 calc(1.25rem + var(--space-3));
}

/* Radio group: stacked option rows (MVP onboarding-question pattern) */
.field.radios {
  border: none;
  margin: 0;
  padding: 0;
  gap: var(--space-4);
  max-width: 28rem;
}

.field.radios legend {
  padding: 0;
  margin: 0 0 var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
}

.radio-option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.field.radios input[type="radio"] {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.1rem;
  accent-color: var(--accent-ink);
  flex-shrink: 0;
}

.radio-option label {
  font-size: var(--text-md);
  font-weight: 400;
  color: var(--ink);
  line-height: var(--leading-body);
}

/* One radio option can be unavailable on its own (2026-09-30): same dimmed
   treatment as a disabled checkbox row; the hint under it says why, full
   strength, on its own line indented to the label. */
.radio-option:has(> p.hint) {
  flex-wrap: wrap;
}

.radio-option.is-disabled input[type="radio"],
.radio-option.is-disabled label {
  opacity: 0.45;
  cursor: not-allowed;
}

.radio-option > p.hint {
  flex-basis: 100%;
  margin: 0 0 0 calc(1.25rem + var(--space-3));
}

/* Radio error state: no border to redden, so the controls carry the
   signal (accent-color paints the checked state); legend stays neutral. */
.field.radios.error input[type="radio"] {
  accent-color: var(--danger);
  outline: 1px solid var(--danger-soft-strong);
  outline-offset: 1px;
  border-radius: 50%;
}

.field.checkboxes input {
  width: 1.25rem;
  height: 1.25rem;
  max-width: none;
  margin-top: 0.1rem;
  accent-color: var(--accent-ink); /* native controls, MVP blue */
  flex-shrink: 0;
}

/* Switch: a checkbox that reads as on/off (role=switch). Label leads. */
/* Pill group: radios drawn as one segmented pill. Unlike .tabs (a white
   track of floating chips) this is a single outlined capsule with flat
   separators between the options and a solid fill on the chosen one. */
.field.pills {
  border: none;
  margin: 0;
  padding: 0;
  max-width: 28rem;
}

.field.pills legend {
  padding: 0;
  margin: 0 0 var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
}

.pill-track {
  display: inline-flex;
  align-items: stretch;
  align-self: flex-start; /* the .field column would stretch it to the field width */
  width: max-content;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  overflow: hidden;
  max-width: 100%;
}

.pill-option {
  display: flex;
}

/* The pill's radio stays real but unseen (keyboard, forms); .sr-only lives
   only in admin.css, so the pill hides its own input everywhere. */
.pill-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.pill-option + .pill-option {
  border-left: 1px solid var(--line);
}

.field .pill {
  /* .field label sets the 12px caption; the pill is the control, not its caption */
  display: inline-flex;
  align-items: center;
  color: var(--muted-strong);
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1.375;
  padding: 0.5rem 1.25rem;
  cursor: pointer;
  white-space: nowrap;
}

.field .pill:hover { color: var(--accent-ink); }

.pill-option input:checked + .pill {
  background: var(--accent-ink);
  color: #fff;
}

.pill-option input:focus-visible + .pill {
  box-shadow: inset 0 0 0 3px var(--accent-soft);
}

.pill-option input:disabled + .pill {
  opacity: 0.5;
  cursor: default;
}

.field.switch {
  flex-direction: row;
  align-items: center;
  gap: var(--space-3);
  max-width: 28rem;
}

.field.switch label {
  font-size: var(--text-md);
  font-weight: 400;
  color: var(--ink);
}

.field.switch--stacked {
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
}

.field.switch--stacked label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
}

.field.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 2.75rem;
  height: 1.5rem;
  max-width: none;
  margin: 0;
  border: none;
  border-radius: 999px;
  background: #cbc9d9;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 120ms ease;
}

.field.switch input::before {
  content: "";
  position: absolute;
  top: 0.125rem;
  left: 0.125rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 120ms ease;
}

.field.switch input:checked {
  background: var(--accent-ink);
}

.field.switch input:checked::before {
  transform: translateX(1.25rem);
}

.field.switch input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field.switch input:disabled {
  opacity: 0.5;
  cursor: default;
}

.field.checkboxes label {
  font-size: var(--text-md);
  font-weight: 400;
  color: var(--ink);
  line-height: var(--leading-body);
}

/* Buttons: <button class="button primary"> or <a class="button primary">
   Variants: .primary .secondary .danger
   Sizes: default, .small (toolbars, tables, pagination)
   Disabled: :disabled on <button>, or .disabled + aria-disabled on <a> */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  box-sizing: border-box;
  font: inherit;
  font-size: var(--text-md);  /* MVP buttons: 700/16, radius 24 */
  font-weight: 700;
  line-height: 1.375; /* 22px content box at 16px, per MVP measurement */
  padding: 0.75rem 1.75rem; /* 12px vertical, ditto */
  border-radius: var(--radius-xl);
  border: none; /* MVP buttons are borderless; rings are inset shadows */
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}

.button svg {
  pointer-events: none;
}

.button.small {
  font-size: 0.8125rem; /* 13px/600 pill, per the MVP's chip scale */
  font-weight: 600;
  line-height: 1.2;
  padding: 0.2rem 0.6rem;
  gap: 0.2rem;
  min-height: 1.5rem;
  min-width: 1.5rem;
  border-radius: var(--radius-pill);
}

.button.large {
  font-size: var(--text-lg); /* 18px hero CTAs (MVP "Next") */
  padding: 0.875rem 2.5rem;
}

.button.block {
  width: 100%; /* card-footer CTAs (MVP full-width "Open Module") */
}

.button:disabled,
.button.disabled,
a.button.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
  pointer-events: none;
}

.button.primary {
  background: var(--accent-grad); /* vertical deep blue gradient, AA (2026-10-27) */
  color: #fff;
  box-shadow: var(--shadow-button);
}

.button.primary:hover:not(:disabled):not(.disabled) {
  filter: brightness(0.95);
  color: #fff;
}

/* MVP secondary: white, blue text, 1px blue ring (inset shadow in the
   export; our sizing border does the same job) */
.button.secondary {
  background: var(--surface);
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 1px var(--accent-ink); /* ring per MVP, no size cost */
}

.button.secondary:hover:not(:disabled):not(.disabled) {
  /* Opaque equivalent of --accent-soft over white: buttons float over any
     surface (the blue hero!), so their fills carry no alpha (2026-09-01). */
  background: #d6f0fc;
  color: var(--accent-ink);
}

/* Soft tint variant (MVP "Open Module") */
.button.soft {
  background: #d6f0fc; /* opaque --accent-soft; no alpha on button fills */
  color: var(--accent-ink-deep); /* 6.2:1 here, 5.7:1 on hover; --accent-ink was 4.35 and 3.98, under AA (2026-10-27) */
  border-color: transparent;
}

.button.soft:hover:not(:disabled):not(.disabled) {
  background: #c2e8fa; /* opaque --accent-soft-strong */
  color: var(--accent-ink-deep);
}

/* Danger mirrors secondary: white, red text, red ring */
.button.danger {
  background: var(--surface);
  color: var(--danger);
  box-shadow: inset 0 0 0 1px var(--danger);
}

.button.danger:hover:not(:disabled):not(.disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Actions sit at the end of the row, primary last (Micah 2026-09-02). */
.button-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

/* --- Modal ---
 *
 *   <div class="modal-backdrop" role="dialog" aria-modal="true"
 *        aria-labelledby="modal-title">
 *     <div class="modal">
 *       <h2 id="modal-title">…</h2>
 *       … body …
 *       <div class="button-group">…</div>
 *     </div>
 *   </div>
 *
 * .modal-demo  in-page specimen frame (backdrop is absolute, not fixed)
 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  z-index: 40;
}

/* display:flex above beats the default [hidden] rule — restore hide */
.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-menu);
  padding: var(--space-6);
  width: min(28rem, 100%);
  /* Match the backdrop's vertical padding; keep the panel inside the window
     while leaving the edited patient form room to fit without scrolling. */
  max-height: calc(100dvh - 2 * var(--space-2));
  /* The panel is a column: the head stays put and only the body scrolls, so
     a long dialog never scrolls its own title away or runs a bar down the
     outside of the padding (Micah 2026-09-15). */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal > .modal-head {
  flex: none;
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  /* the scrollbar rides inside the panel, clear of the rounded corner */
  margin-right: calc(var(--space-4) * -1);
  padding-right: var(--space-4);
  /* The primary shadow is 0 6px 16px. This scrolling box clips whatever
     paints past its padding, so the room for that shadow lives here, under
     whatever ends the dialog. */
  padding-bottom: var(--space-6);
  /* A field scrolled into view (a click, a Tab) stops above the sticky
     button row instead of under it (Micah 2026-10-15). */
  scroll-padding-bottom: 6rem;
}

/* When the scrolling body ends the dialog, its padding is the room under
   the buttons: the dialog's own bottom padding would double it and make a
   form that fitted scroll (Micah 2026-10-15). */
.modal:has(> .modal-body:last-child) {
  padding-bottom: 0;
}

.modal h2 {
  margin: 0 0 var(--space-4);
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: var(--leading-tight);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}

.modal-head:has(h2) {
  justify-content: space-between;
}

/* The title and, under it, what the dialog acts on (Micah 2026-11-16). */
.modal-titles {
  flex: 1;
  min-width: 0;
}

.modal-context {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.modal-head h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.modal-close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: -0.45rem -0.45rem 0 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink);
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover,
.modal-close:focus-visible {
  color: var(--ink);
  background: var(--fill, #ececec);
}

.modal > p {
  margin: 0 0 var(--space-4);
  color: var(--muted);
  line-height: var(--leading-body);
}

.modal .button-group {
  margin-top: var(--space-4);
}

/* The ending actions of every dialog, whether they sit in the body or in
   the pinned slot. Room between the copy and the buttons. */
.modal-body .button-group:last-child,
.modal-actions {
  padding-top: var(--space-4);
}

.modal-actions {
  flex: none;
  background: var(--surface);
}

.modal-actions .button-group {
  margin-top: 0;
  padding-top: 0;
}

/* Keep the submit button inside its native form. The action row is
   pinned to the bottom of the scrolling body on both desktop and phone.
   The body's padding is the room under that row, including while it is stuck. */
.modal-body form > .button-group:last-child,
.modal-body > .button-group:last-child {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin-top: 0;
  background: var(--surface);
}

/* The quiet Print control (ui.print) in a dialog: a text control with its
   printer icon, apart from the dialog's buttons (Micah 2026-11-20). */
.print-control {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent-ink);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.print-control:hover,
.print-control:focus-visible {
  background: var(--accent-soft);
}

.print-control svg {
  width: 1rem;
  height: 1rem;
}

/* A dialog with a Print control prints alone: the page around it, its
   close and its buttons stay off the paper, and its body runs to every
   page instead of scrolling. */
@media print {
  .no-print {
    display: none !important;
  }

  body:has(.modal [data-print]) :not(:has([data-print])):not(.modal:has([data-print]) *) {
    display: none !important;
  }

  body:has(.modal [data-print]) {
    background: #fff;
  }

  .modal-backdrop:has([data-print]) {
    position: static;
    display: block;
    padding: 0;
    background: none;
  }

  .modal:has([data-print]) {
    display: block;
    width: auto;
    max-height: none;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .modal:has([data-print]) .modal-body {
    overflow: visible;
    margin: 0;
    padding: 0;
  }

  .modal:has([data-print]) .modal-close,
  .modal:has([data-print]) .modal-actions {
    display: none;
  }
}

/* Phones: dialogs are full-screen sheets (tono-kx4s, Micah 2026-09-30).
   One close control, the X, top-left and 44px; the title beside it; the
   body scrolls between a sticky head and the action buttons pinned at the
   bottom, in thumb reach. Desktop keeps the centered card. */
@media (width < 48rem), (height < 32rem) {
  .modal-backdrop {
    padding: 0;
    align-items: stretch;
    background: var(--surface);
  }

  .modal,
  .modal.modal--wide {
    width: 100%;
    max-width: none;
    max-height: none;
    height: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
  }

  .modal > .modal-head {
    position: sticky;
    top: 0;
    z-index: 1;
    justify-content: flex-start;
    align-items: center;
    gap: var(--space-2);
    min-height: 3.5rem;
    margin: 0;
    padding: 0 var(--space-4) 0 var(--space-2);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }

  .modal-close {
    order: -1;
    margin: 0;
  }

  .modal-head h2 {
    font-size: 1.125rem;
  }

  .modal-body {
    margin: 0;
    padding: var(--space-4) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom));
  }

  .modal-actions {
    padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
  }

  .modal-body form > .button-group:last-child,
  .modal-body > .button-group:last-child {
    bottom: 0;
    margin: var(--space-6) calc(var(--space-4) * -1) 0;
    padding: var(--space-4) var(--space-4) 0;
    background: var(--surface);
  }
}

/* In-page preview for proto / docs (not a real overlay) */
.modal-demo {
  position: relative;
  min-height: 18rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper);
  overflow: hidden;
}

.modal-demo .modal-backdrop {
  position: absolute;
  z-index: 1;
}

.page-lede {
  margin: 0 0 var(--space-6);
  color: var(--muted);
  line-height: var(--leading-body);
  max-width: 36rem;
}

/* --- Combobox (tonotop.ui.combobox) ---
 *
 *   <div class="combobox is-open">
 *     <input role="combobox" aria-expanded="true" …>
 *     <ul class="combobox-menu" role="listbox">
 *       <li class="combobox-option is-active" role="option">…</li>
 *     </ul>
 *   </div>
 */
.combobox {
  position: relative;
  width: 100%;
  max-width: 24rem;
}

.combobox input[role="combobox"] {
  font: inherit;
  font-size: var(--text-sm);
  width: 100%;
  max-width: none;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
}

/* search variant: room for the leading magnifier (affix anchors to the
   .combobox relative wrapper) */
.combobox--search input[role="combobox"] {
  padding-left: 2.1rem;
}

.combobox input[role="combobox"]:focus {
  outline: none;
  border-color: var(--accent-ink);
  box-shadow: var(--shadow-focus);
}

.field.error .combobox input[role="combobox"] {
  border-color: var(--danger);
}

/* Position/size set inline (fixed + getBoundingClientRect) so the menu
   portals above overflow:auto ancestors (modals) without a modal scrollbar. */
.combobox-menu {
  position: fixed;
  z-index: 60;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-menu);
  box-sizing: border-box;
}

/* Scroll cap is opt-in per combobox (:menu-scroll?, default true).
   Vertical only: the menu is width-pinned to the input, so any 1px-wide
   option otherwise spawns a horizontal scrollbar strip at the bottom. */
.combobox-menu--scroll {
  max-height: 14rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.combobox-option {
  padding: 0.5rem 0.75rem;
  font-size: var(--text-sm);
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* long options truncate instead of widening */
}

.combobox-option.is-active,
.combobox-option:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.combobox-empty {
  padding: 0.5rem 0.75rem;
  font-size: var(--text-sm);
  color: var(--muted);
}

/* --- Pagination (tonotop.ui.pagination) --- */

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.pagination .muted {
  font-size: var(--text-xs);
}

.pagination-pages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Page numbers are form/button.small — slightly tighter min width */
.pagination-pages .button {
  min-width: 1.75rem;
}

.pagination-ellipsis {
  color: var(--muted);
  font-size: var(--text-xs);
  padding: 0 var(--space-1);
  user-select: none;
}

/* --- Password field (tonotop.ui.password-field, tono-6t6t) ---
   One input with a show/hide toggle on its trailing edge and a thin
   strength bar with a label under it; the label carries the one rule (12
   characters) in gray, then the tier in green with an icon. Bar and label
   each keep a fixed width so nothing shifts as the words change. Never
   red. The
   field is a .field on account forms; in the claim family
   (.pat-claim-form) the label and input wear the claim classes instead. */

.password-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.password-field-control {
  position: relative;
  display: flex;
  align-items: stretch;
  width: 100%;
  max-width: 24rem;
}

.pat-claim-form .password-field-control {
  max-width: none;
}

.password-field-control input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  max-width: none;
  padding-right: 5.5rem;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.4rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.6rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--accent-ink);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.password-toggle svg {
  font-size: 1.15rem;
}

.password-toggle:hover {
  background: var(--accent-soft);
}

.password-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.password-meter {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  max-width: 24rem;
  min-width: 0;
}

.pat-claim-form .password-meter {
  max-width: none;
}

.password-meter-track {
  flex: 1 1 auto;
  height: 0.375rem;
  border-radius: var(--radius-pill);
  background: var(--fill);
  overflow: hidden;
}

.password-meter-fill {
  height: 100%;
  width: 0;
  border-radius: var(--radius-pill);
  background: var(--meter-short);
  transition: width 0.35s ease-out, background-color 0.35s ease-out;
}

.password-meter[data-tone="low"] .password-meter-fill {
  background: var(--meter-low);
}

.password-meter[data-tone="mid"] .password-meter-fill {
  background: var(--meter-mid);
}

.password-meter[data-tone="high"] .password-meter-fill {
  background: var(--meter-high);
}

/* Fixed column, sized to the longest label ("Needs 12 characters"), text
   on the right edge of the input above; the track takes the rest, so it
   is the same width in every state. */
.password-meter-copy {
  flex: 0 0 7.75rem;
  width: 7.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.3rem;
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  line-height: var(--leading-body);
  text-align: right;
  white-space: nowrap;
}

.password-meter-copy svg {
  flex-shrink: 0;
  font-size: 1.1rem;
}

.password-meter.is-met .password-meter-copy {
  color: var(--success-strong);
}

@media (prefers-reduced-motion: reduce) {
  .password-meter-fill { transition: none; }
}

/* --------------------------------------------------------------------------
 * Text utilities per the v0.3 MVP (see tokens.css header).
 * ------------------------------------------------------------------------ */

.lede {
  font-size: var(--text-lg);
  line-height: 1.6;
  color: var(--muted);
  max-width: var(--lede-max);
}

.caption {
  font-size: var(--text-xs);
  color: var(--muted);
}

.label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--muted);
}

/* Display stats (DM Sans 900 per the MVP's big numerals) */
.stat {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 900;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}

.stat--hero { font-size: var(--text-hero); }

/* Tabular numerals: any column of figures (scores, thresholds, money) */
.tnum { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
 * Tabs (MVP segmented pattern: "Weekly Modules / Assessment Results").
 * Works on <a> and <button>. Active = soft blue fill + accent text.
 * ------------------------------------------------------------------------ */

.tabs {
  display: inline-flex;
  flex-wrap: nowrap; /* never wrap: overflow scrolls inside the pill */
  align-items: center;
  gap: 4px; /* MVP track: white pill, 4px padding and gaps */
  list-style: none;
  margin: 0;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none; /* the pill stays clean; trackpad/touch scrolls */
}

.tabs::-webkit-scrollbar { display: none; }

.tabs > li {
  flex-shrink: 0; /* list-based tab rows: options keep their size */
  display: flex;  /* no line box: kills the ~4px descender gap under inline <a> tabs */
  margin: 0;      /* base.css gives list items 4px bottom rhythm; not in a track */
}

.tab {
  display: inline-flex;
  align-items: center;
  border: none;
  border-radius: var(--radius-xl);
  background: transparent;
  color: var(--muted-strong);
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1.375;
  padding: 0.625rem 1.5rem; /* MVP: 10px 24px */
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.tab:hover { color: var(--accent-ink); }

.tab.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* Dense track for page navs (many entries): MVP chip scale. The full-size
   .tab stays for true in-content view switchers (the MVP tab pair). */
.tabs--dense .tab {
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.375;
  padding: 0.375rem 0.875rem;
}

/* --------------------------------------------------------------------------
 * tab-nav (tonotop.ui.navtabs): dense tabs wide, details-menu narrow.
 * ------------------------------------------------------------------------ */

.tab-nav-menu { display: none; position: relative; }

/* Closed state: the white pill TRACK holds the active tab + a real caret,
   so the mobile control keeps the tabs' visual context. */
.tab-nav-menu > summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  list-style: none;
  cursor: pointer;
}

.tab-nav-menu > summary::-webkit-details-marker { display: none; }

.tab-nav-menu > summary::after {
  content: "\25BE";
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted-strong);
  margin: 0 var(--space-3) 0 var(--space-1);
  transition: transform 150ms ease;
}

.tab-nav-menu[open] > summary::after {
  transform: rotate(180deg);
}

/* menu tabs match the dense row scale */
.tab-nav-menu .tab {
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.375;
  padding: 0.375rem 0.875rem;
}

.tab-nav-panel {
  position: absolute;
  z-index: 40;
  margin: var(--space-1) 0 0;
  padding: var(--space-1);
  list-style: none;
  min-width: 12rem;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-menu);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tab-nav-panel li { margin: 0; display: flex; }
.tab-nav-panel .tab { width: 100%; }
/* the selected item stays in the list (stable order) but is inert */
.tab-nav-panel span.tab.is-active { cursor: default; }

@media (width < 50rem) { /* below 800px: dropdown mode */
  .tab-nav .tab-nav-row { display: none; }
  .tab-nav .tab-nav-menu { display: inline-block; }
}

/* Menu mode: always the dropdown control, never the wide row — used in
   rows of per-group selects (proto nav). :header renders the category
   above the control; :placeholder fills the pill when the group holds
   no current page. */
.tab-nav--menu {
  display: inline-flex;
  flex-direction: column;
  gap: var(--space-1);
}
.tab-nav--menu .tab-nav-row { display: none; }
.tab-nav--menu .tab-nav-menu { display: inline-block; }

.tab-nav-header {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding-left: var(--space-3);
}

.tab-nav-menu .tab--placeholder {
  color: var(--muted);
}

/* --- Flash (one-use redirect / ajax notices) ---
   Global stack: .flash-region at top of main (every shell).
   Pair with tonotop.ui.flash. Styles: success | warning | error.
   Test hooks: id="-flash-region", id="-flash", data-flash-style. */

/* The full width of the main it sits in, flush with the content under it;
   it was capped at 40rem and read as narrow (Micah 2026-10-08). The auth
   page keeps its own cap at the card's width. */
.flash-region {
  display: flex;
  flex-direction: column;
  gap: var(--space-2, 0.5rem);
  width: 100%;
  margin: 0 auto var(--space-4, 1rem);
  box-sizing: border-box;
}

.flash {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  margin: 0;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-lg, 0.75rem);
  border: 1px solid var(--line, #ececec);
  text-align: left;
  box-sizing: border-box;
}

.flash-message {
  flex: 1 1 auto;
  margin: 0;
  font-size: var(--text-md, 1rem);
  line-height: 1.45;
  font-weight: 600;
}

.flash-dismiss {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin: 0 -0.35rem 0 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md, 0.5rem);
  background: transparent;
  color: inherit;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}

.flash-dismiss:hover,
.flash-dismiss:focus-visible {
  opacity: 1;
  background: rgba(0, 0, 0, 0.06);
  outline: none;
}

.flash-dismiss:focus-visible {
  box-shadow: 0 0 0 2px currentColor;
}

.flash--success {
  background: rgba(0, 179, 90, 0.12);
  border-color: var(--success, #00b35a);
  color: var(--success-strong, #1a7a3a);
}

.flash--warning {
  background: rgba(222, 174, 97, 0.22);
  border-color: #c49a3c;
  color: #5c4a1f;
}

.flash--error {
  background: var(--danger-soft, rgba(224, 0, 37, 0.15));
  border-color: var(--danger, #e00025);
  color: var(--danger, #e00025);
}

/* --- Notice (standing page cautions; shares the flash warning palette) --- */
.notice {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  width: 100%;
  margin: 0 0 var(--space-4, 1rem);
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-lg, 0.75rem);
  border: 1px solid var(--line, #ececec);
  text-align: left;
  box-sizing: border-box;
}

.notice-message {
  margin: 0;
  font-size: var(--text-md, 1rem);
  line-height: 1.45;
  font-weight: 600;
}

.notice--warning {
  background: rgba(222, 174, 97, 0.22);
  border-color: #c49a3c;
  color: #5c4a1f;
}

/* The quiet notice: the symbol and the words in the warning ink, no panel
   (the Users page's lookup caution, Micah 2026-10-07). */
.notice--quiet {
  padding: 0;
  border: 0;
  background: none;
  color: var(--warn-ink, #5c4a1f);
}

.notice--quiet .notice-message {
  font-size: var(--text-sm, 0.875rem);
}

/* The passkey offer: a card in the flash slot after a password sign-in,
   a heading, one line, the two buttons right-aligned (tono-rwdp). */
.passkey-offer {
  display: block;
  padding: 1.1rem 1.25rem;
  background: var(--surface, #fff);
  border-color: var(--line, #ececec);
  color: var(--ink, #212322);
}

.passkey-offer-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: var(--text-lg, 1.125rem);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
}

.passkey-offer .notice-message {
  font-weight: 400;
  color: var(--muted, #545f71);
}

/* Proto placement sketch only */
.flash-placement-demo {
  border: 1px dashed var(--line, #ccc);
  border-radius: var(--radius-lg, 0.75rem);
  overflow: hidden;
  max-width: 40rem;
  margin: 0 auto;
}
.flash-placement-demo-header {
  padding: 0.75rem 1rem;
  background: var(--fill, #ececec);
  font-weight: 600;
  font-size: var(--text-sm, 0.875rem);
}
.flash-placement-demo-body {
  padding: 1rem 1.25rem 1.5rem;
}
.flash-placement-demo-body h2 {
  margin: 0 0 0.5rem;
  font-size: var(--text-xl, 1.5rem);
}
.flash-placement-demo-body p {
  margin: 0;
  color: var(--muted, #666);
}
.flash-placement-demo .flash-region {
  margin-top: var(--space-3, 0.75rem);
  margin-bottom: var(--space-3, 0.75rem);
}

/* --- Inop (inoperative) primitive ---
   Aviation glass-panel red-X over not-yet-wired UI. Visible in every
   environment (no env-gating). Clay #C95038 for the X stroke.
   Pair with tonotop.ui.inop / data-inop.
   Shell fills the layout slot (width+height of the component); X is drawn
   corner-to-corner of that box and clipped so it never bleeds. */

.inop {
  position: relative;
  display: block;
  /* Fill the allocated component width (grid/flex/column), not shrink-wrap. */
  width: 100%;
  max-width: 100%;
  height: 100%;
  box-sizing: border-box;
  /* Clip X exactly to this component. */
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

/* Shrink-wrap content — toolbar buttons, chips. Without this, width:100%
   stretches the shell across a flex row and left-aligns the control. */
.inop.inop--fit {
  display: inline-flex;
  width: auto;
  height: auto;
  max-width: 100%;
  flex: 0 0 auto;
  vertical-align: middle;
}

.inop-content {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  opacity: 0.45;
  filter: grayscale(0.35);
  position: relative;
  z-index: 0;
}

.inop.inop--fit .inop-content {
  width: auto;
  height: auto;
}

/* --- Proof of work (tono-et13) --- */

.pow {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  color: var(--muted-strong);
  font-size: var(--text-md);
}

.pow[data-state="verified"] {
  color: var(--accent-ink);
  border-color: var(--accent-ink);
  font-weight: 600;
}

.pow-icon svg,
.pat-pow-icon svg {
  width: 1.1rem;
  height: 1.1rem;
}

.pow-spinner,
.pat-pow-spinner {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent-ink);
  animation: pow-spin 0.9s linear infinite;
}

@keyframes pow-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .pow-spinner,
  .pat-pow-spinner { animation: none; }
}

/* One overlay, both diagonals via gradients — always matches the box size. */
.inop::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.92;
  background:
    linear-gradient(
      to top right,
      transparent calc(50% - 1px),
      #C95038 calc(50% - 1px),
      #C95038 calc(50% + 1px),
      transparent calc(50% + 1px)
    ),
    linear-gradient(
      to top left,
      transparent calc(50% - 1px),
      #C95038 calc(50% - 1px),
      #C95038 calc(50% + 1px),
      transparent calc(50% + 1px)
    );
}

.inop::after {
  content: none;
}

/* In-flight submit (ui.ux [data-busy]): label dims, ring spins. */
.button.is-busy {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.button.is-busy::after {
  content: "";
  position: absolute;
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--ink, #2c4c5c);
  animation: button-busy-spin 0.7s linear infinite;
}

.button.primary.is-busy::after,
.button.danger.is-busy::after {
  color: #fff;
}

/* White-background buttons spin in the action blue, not muted ink. */
.button.secondary.is-busy::after {
  color: var(--accent, #2d828c);
}

/* Waiting on something outside the page (the device's passkey sheet):
   the label stays, saying what it waits for, with the spinner beside it
   (is-busy blanks the label, which left the words floating under the
   button; Micah 2026-10-10). */
.button.is-waiting {
  pointer-events: none;
}

.button.is-waiting::before {
  content: "";
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-right: 0.55em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  vertical-align: -0.15em;
  animation: button-busy-spin 0.7s linear infinite;
}

@keyframes button-busy-spin {
  to { rotate: 360deg; }
}

/* Dialogs that carry a table or a transcript need the room (2026-09-15). */
.modal.modal--wide {
  width: min(48rem, 100%);
}

/* --- Image dialog (tonotop.ui.image-dialog): current-image preview --- */
.admin-image-preview {
  width: 100%;
  height: 12rem;
  background: var(--paper, #fbf6f3);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.admin-image-preview img,
.admin-dialog-host .modal-backdrop .admin-image-preview img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  object-position: center;
}

/* --- File drop (tonotop.ui.file-drop) ---
   Shared by Content Studio, the blob store and clinic settings, so it lives
   with the primitives rather than in admin.css (2026-09-17). */
.admin-image-drop {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-2);
  text-align: center;
}

.admin-image-drop-pad {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 8.5rem;
  padding: var(--space-5);
  border: 2px dashed var(--muted);
  border-radius: var(--radius-lg);
  background: var(--paper, #fbf6f3);
}

.admin-image-drop.is-dragover .admin-image-drop-pad {
  border-color: var(--accent-ink);
  background: var(--accent-soft);
}

.admin-image-drop.error .admin-image-drop-pad {
  border-color: var(--danger, #c95038);
}

.admin-image-drop p.error {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--danger, #c95038);
  line-height: var(--leading-body);
  text-align: left;
}

.admin-image-drop.has-file .admin-image-drop-copy p {
  color: var(--ink);
  word-break: break-word;
}

.admin-image-drop-preview {
  display: none;
  place-items: center;
  width: 100%;
  min-height: 7rem;
}

.admin-image-drop.has-file .admin-image-drop-preview {
  display: grid;
}

.admin-image-drop-thumb {
  display: none;
  max-width: 100%;
  max-height: 10rem;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.admin-image-drop.has-image .admin-image-drop-thumb {
  display: block;
}

.admin-image-drop-preview .admin-file-icon {
  display: none;
}

.admin-image-drop.has-file:not(.has-image) .admin-image-drop-preview .admin-file-icon {
  display: grid;
}

.admin-file-icon {
  position: relative;
  display: grid;
  place-items: end center;
  width: 2.75rem;
  height: 3.4rem;
  background: var(--surface, #fff);
  border: 1px solid var(--muted);
  border-radius: 0.2rem 0.7rem 0.2rem 0.2rem;
  box-shadow: 0 1px 2px rgba(33, 35, 34, 0.1);
  color: var(--accent-ink);
}

.admin-file-icon::before {
  content: "";
  position: absolute;
  top: -1px;
  right: -1px;
  width: 0.7rem;
  height: 0.7rem;
  background: var(--paper, #eef3fa);
  border-bottom: 1px solid var(--muted);
  border-left: 1px solid var(--muted);
  border-radius: 0 0 0 0.15rem;
}

.admin-file-icon-ext {
  display: block;
  width: 100%;
  padding: 0 0.15rem 0.4rem;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-image-drop-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.admin-image-drop-copy {
  display: grid;
  gap: var(--space-3);
  justify-items: center;
  pointer-events: none;
}

.admin-image-drop-copy p {
  margin: 0;
  font-weight: 650;
  color: var(--muted-strong);
}

.admin-image-drop-choose {
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.admin-image-actions {
  width: 100%;
}

.admin-image-actions .danger {
  margin-right: auto;
}

/* Status chips, shared by the clinician chart and the account page
   (hoisted from clinician.css 2026-09-28 so both read the same). The
   text-message tones: success = opted in, neutral = not opted in, warn =
   opted out. */
.clin-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  border-radius: var(--radius-pill);
  padding: 0.15rem 0.5rem;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.clin-chip--success {
  color: var(--success-strong);
  background: var(--success-soft);
}

.clin-chip--pending {
  color: var(--warn-ink);
  background: var(--warn-soft);
}

.clin-chip--warn {
  color: var(--danger);
  background: var(--danger-soft);
}

.clin-chip--accent {
  color: var(--accent-ink);
  background: var(--accent-soft);
}

/* Text-message state on the Mobile row: the chip's word and tone carry
   opted in / not opted in / opted out (2026-09-28). */
.clin-chip--neutral {
  color: var(--muted);
  background: var(--paper);
  box-shadow: inset 0 0 0 1px var(--line);
}

/* Modal grant/revoke outcome: prominent and focusable above the form. */
.form-error {
  margin: 0 0 var(--space-4, 1rem);
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--danger, #b42318);
  border-radius: var(--radius-lg, 0.75rem);
  background: rgba(180, 35, 24, 0.1);
  color: var(--danger-strong, #922018);
  font-weight: 600;
}
.form-error:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

/* --- Copy button: an icon that puts [data-copy] on the clipboard (ui.ux) --- */
.copy-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.4rem;
  margin-left: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: var(--text-sm);
  line-height: 1;
  vertical-align: middle;
  cursor: pointer;
}

.copy-button:hover,
.copy-button:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
}

.copy-button.is-copied {
  color: var(--success, #2d8c5a);
  border-color: currentColor;
}

.copy-button-done:empty {
  display: none;
}

/* Side nav (ui.side-nav, Micah 2026-11-03): settings sections down the
   left, GitHub-style. On a phone it is a row above the page that scrolls
   sideways, the current section in view. */
.side-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.side-nav-label {
  margin: 0 0 var(--space-1);
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.side-nav-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Anything that opens a page is link-coloured; headings are small grey
   capitals and never react to the pointer, so what can be clicked reads
   at a glance (Micah 2026-11-17). */
.side-nav-link {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--accent-ink);
  font-weight: 500;
  text-decoration: none;
}

.side-nav-link:hover {
  background: var(--accent-soft);
}

.side-nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--accent-ink);
}

.settings-layout {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  gap: var(--space-8);
  align-items: start;
}

.settings-layout .side-nav {
  position: sticky;
  top: var(--space-4);
}

@media (width < 48rem), (height < 32rem) {
  .settings-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
  }

  .settings-layout .side-nav {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    gap: var(--space-3);
    padding-bottom: var(--space-1);
    scrollbar-width: none;
  }

  .side-nav-group {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex: none;
  }

  .side-nav-label {
    display: none;
  }

  .side-nav-list {
    flex-direction: row;
  }

  .side-nav-link {
    white-space: nowrap;
  }

  .side-nav-link.is-active {
    box-shadow: inset 0 -3px 0 var(--accent-ink);
  }
}

/* Whose settings: the business, at the top of the side nav (GitHub's
   account block), apart from its clinics below. */
.settings-identity {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
}

.settings-identity-mark {
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--accent-ink);
  color: #fff;
  font-weight: 700;
}

.settings-identity-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.settings-identity-name {
  font-weight: 700;
  color: var(--ink);
}

.settings-identity-kind {
  font-size: var(--text-xs);
  color: var(--muted);
}

.side-nav-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.side-nav-icon {
  display: inline-flex;
  width: 1rem;
  height: 1rem;
}

.side-nav-icon svg {
  width: 100%;
  height: 100%;
}

/* A link with an icon: the icon the size of a clinic's chevron, so its
   words line up with the clinics' names above. */
.side-nav-link--icon {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.side-nav-link--icon .side-nav-icon {
  flex: none;
  width: 0.875rem;
  height: 0.875rem;
}

.side-nav-sub {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-nav-sub-heading {
  padding: var(--space-3) var(--space-3) var(--space-1);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: default;
}

.settings-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.settings-panel-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--line);
}

.settings-panel-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.settings-panel-header .pat-page-title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.settings-panel-lede {
  margin: 0;
  color: var(--muted);
}

@media (width < 48rem), (height < 32rem) {
  .settings-identity {
    display: none;
  }

  .side-nav-sub {
    flex-direction: row;
    align-items: center;
  }

  .side-nav-sub-heading {
    display: none;
  }

  .side-nav-sub .side-nav-link {
    padding-left: var(--space-3);
  }
}

/* Clinics as a tree (Micah 2026-11-03): a node per clinic that opens
   and closes, the current one open. */
.side-nav-node > details > summary {
  list-style: none;
}

.side-nav-node > details > summary::-webkit-details-marker {
  display: none;
}

.side-nav-node-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.side-nav-node-label:hover {
  background: var(--accent-soft);
}

.side-nav-node-chevron {
  display: inline-flex;
  width: 0.875rem;
  height: 0.875rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.side-nav-node-chevron svg {
  width: 100%;
  height: 100%;
}

.side-nav-node > details[open] > summary .side-nav-node-chevron {
  transform: rotate(90deg);
}

.side-nav-node .side-nav-list {
  margin-left: calc(var(--space-3) + 0.4375rem);
  padding-left: var(--space-2);
  border-left: 1px solid var(--line);
}

.side-nav-node .side-nav-sub .side-nav-list {
  margin-left: 0;
  padding-left: 0;
  border-left: 0;
}

.settings-identity-mark svg {
  width: 1.375rem;
  height: 1.375rem;
}

@media (prefers-reduced-motion: reduce) {
  .side-nav-node-chevron {
    transition: none;
  }
}

@media (width < 48rem), (height < 32rem) {
  .side-nav-node > details {
    display: flex;
    align-items: center;
  }

  .side-nav-node .side-nav-list {
    padding-left: 0;
  }
}

.settings-panel-header {
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.settings-panel-titles {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}
