/* The shared layer (post-EXAM restyle R2): the exam page's look for every
   page that opts in with the `ui` body class, page by page (R4–R7), until R8
   makes it the default and main.css's old components go.

   Three parts:
   1. Tokens on :root, for every page: the unit --u, the eight type roles,
      the fonts and the colours. Every size is a multiple of
      --u, so the text-size preference (R3) scales a page by setting --u on
      <html>; page widths, breakpoints and the exam's panel stay in px.
   2. The sidebar, on every page (it is the same sidebar everywhere).
   3. Components, every rule scoped under .ui so a page that hasn't been
      converted keeps main.css: cards, buttons, badges, tables, fields, menus
      / popovers / toasts and the in-page confirm. The exam's versions, moved
      here from exam.css, which now keeps only what is the exam's own.

   Mono is for codes, IDs and table column headers only; uppercase for the
   .sub sub-headings (and the sidebar's section labels) only.
   No inline styles anywhere (CSP style-src 'self'). */

/* ── 1. Tokens ─────────────────────────────────────────────────────────── */
:root {
  --u: 15px;                                     /* Standard; the other steps below */
  /* The eight type roles (Carson, Oct 15). micro never goes below 11px. */
  --fs-micro:   max(11px, calc(.75 * var(--u))); /* tags, carets, Rx table headers, hints */
  --fs-caption: calc(.8 * var(--u));             /* badges, sub-labels, xs buttons, timestamps */
  --fs-small:   calc(.85 * var(--u));            /* meta lines, chips, field labels, save state */
  --fs-ui:      calc(.9 * var(--u));             /* body text, tables, buttons, popovers, toasts */
  --fs-title:   calc(.95 * var(--u));            /* card and section titles */
  --fs-input:   var(--u);                        /* field values and inputs */
  --fs-name:    calc(1.1 * var(--u));            /* patient name */
  --fs-page:    calc(1.25 * var(--u));           /* page titles on non-patient pages */

  /* Atkinson Hyperlegible Next (Carson, Oct 7): numbers in the UI face with
     tabular figures, the mono for codes and IDs. */
  --font-ui: 'Atkinson Hyperlegible Next', 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'Atkinson Hyperlegible Mono', 'IBM Plex Mono', ui-monospace, monospace;
  --font-num: var(--font-ui);

  /* The top bar's height, and so the sidebar logo's: their bottom borders
     make one line across the page (Carson, Oct 17). Fixed, not in u, so the
     text size never moves the line. */
  --bar-h: 52px;

  /* The sidebar's spacing, in u: the sidebar rules (section 2) and the
     Patients list's toolbar, which lines up with the Patients link, both read
     these, so a change here moves both. */
  --sb-line:        1.4;                         /* the sidebar's line-height */
  --sb-logo-gap:    calc(.67 * var(--u));        /* under the logo */
  --nav-label-pad-t: calc(.67 * var(--u));
  --nav-label-pad-b: calc(.27 * var(--u));
  --nav-link-pad-y: calc(.6 * var(--u));
  --nav-label-h: calc(var(--nav-label-pad-t) + var(--nav-label-pad-b) + var(--sb-line) * var(--fs-micro));
  --nav-link-h:  calc(2 * var(--nav-link-pad-y) + var(--sb-line) * var(--fs-ui));

  /* The colours (moved from main.css in R7c, so a page can load this file
     alone: the signed-out pages), then the exam's additions. */
  /* The brand (Nov 2026): deep teal for what you press, pick or focus
     (buttons, links, selected chips and tabs, focus rings, checkboxes); brand
     cream for the page; warm borders. Green stays for what MEANS done or good
     (Complete, saved, success, slow progression, booked), so the two never
     blur. --text-muted is darker than before so it passes 4.5:1 on cream
     (5.3:1) as well as white (6.1:1). */
  --brand: #094A57; --brand-dark: #06343D; --brand-light: #E3EFF1; --brand-mid: #B3D3D9;
  --green: #1d6b4e; --green-dark: #155239; --green-light: #e8f4ef; --green-mid: #b6d9cb;
  --bg: #F5EFE4; --bg-card: #ffffff; --bg-hover: #f0efeb;
  --text: #1a1f1e; --text-secondary: #374151; --text-muted: #5B6370; --text-faint: #9ca3af;
  --border: #E6DFD2; --border-mid: #D5CDBF;
  --shadow-card: 0 1px 4px rgba(0,0,0,0.06); --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --bg-sub: #fafaf8;
  --amber: #b45309; --amber-light: #fef3c7; --amber-mid: #fde68a;
  --red: #b91c1c; --red-light: #fef2f2; --red-mid: #fecaca; --red-hover: #fee2e2;
  --blue: #1d4ed8; --blue-light: #eff6ff; --blue-mid: #bfdbfe;
  --purple: #6d28d9; --purple-light: #f5f3ff;
  --gray-light: #f3f4f6;

  /* The eyes (R4; eyecolours Nov 2026): the reports' pair, so the app and a
     printed report agree — right = indigo + circle + solid line, left = ochre +
     square + dashed line. --od / --os are for marks (legend dots, chart lines
     and points; 3:1+ on white and cream). Text uses the -ink pair: ochre is
     only 3.8:1 on white, so left-eye text is a darker ochre (5.9:1 white,
     5.1:1 cream). app/reports/svg.py's C["od"] / C["os"] must equal --od / --os
     (test_eye_colours.py). -border is a 35% tint, for the eye headings. */
  --od: #5B4E9B; --od-ink: #5B4E9B; --od-border: #C6C1DC;
  --os: #B0763A; --os-ink: #8A5A26; --os-border: #E3CFBA;
}

/* The text-size steps (R3b): base.html writes the user's users.text_size on
   <html data-text-size>; Standard is :root's 15px. html[…] outranks :root.
   Same four as models.TEXT_SIZES and migration 0021's CHECK. */
html[data-text-size="compact"] { --u: 13.5px; }
html[data-text-size="large"]   { --u: 16.5px; }
html[data-text-size="larger"]  { --u: 18.75px; }

/* ── 2. The sidebar (every page) ───────────────────────────────────────── */
/* Sizes in u, so it follows the text size; its width stays 220px. */
.sidebar { font-family: var(--font-ui); line-height: var(--sb-line); }
.sidebar-logo { gap: calc(.67 * var(--u)); height: var(--bar-h); padding: 0 calc(1.2 * var(--u));
  margin-bottom: var(--sb-logo-gap); }
/* The brand lockup (branding, Nov 2026): its height in u, its width from the
   artwork's 279.62 × 64 */
.logo-lockup { display: block; height: calc(1.8 * var(--u)); width: auto; }
.nav-section { padding: 0 calc(.67 * var(--u)); margin-bottom: calc(.27 * var(--u)); }
.nav-label { font-family: inherit; font-size: var(--fs-micro); font-weight: 600; letter-spacing: .06em;
  padding: var(--nav-label-pad-t) calc(.53 * var(--u)) var(--nav-label-pad-b); }
.nav-link { gap: calc(.6 * var(--u)); padding: var(--nav-link-pad-y) calc(.67 * var(--u)); font-size: var(--fs-ui); font-weight: 500; }
.nav-link svg { width: calc(1.07 * var(--u)); height: calc(1.07 * var(--u)); }
.sidebar-bottom { padding: calc(.8 * var(--u)) calc(.67 * var(--u)) 0; }
.user-chip { gap: calc(.6 * var(--u)); padding: calc(.53 * var(--u)) calc(.67 * var(--u)); }
.user-avatar { width: calc(1.73 * var(--u)); height: calc(1.73 * var(--u)); font-size: var(--fs-micro); font-weight: 600; }
.user-name { font-size: var(--fs-small); font-weight: 500; }
.user-role { font-family: inherit; font-size: var(--fs-micro); }
.nav-tag { font-family: inherit; font-size: var(--fs-micro); font-weight: 600; padding: 0 calc(.4 * var(--u)); border-radius: 999px; }

/* ── 3. Components (pages with the ui body class) ──────────────────────── */
body.ui { font-family: var(--font-ui); font-size: var(--fs-ui); line-height: 1.4; }
/* Controls take the page's font. Not the sidebar's: its Sign out is a button
   styled as a nav link. (:where keeps this at the specificity of .ui button.) */
.ui :is(button, input, select, textarea):where(:not(.sidebar *)) { font: inherit; color: inherit; }
.ui button { cursor: pointer; }
.ui .mono { font-family: var(--font-mono); }
.ui .num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.ui .muted { color: var(--text-muted); }
.ui :is(.small, .text-sm) { font-size: var(--fs-small); }  /* .text-sm: main.css's name (history notes cells) */
/* Sub-headings: the one uppercase text */
.ui .sub { font-size: var(--fs-caption); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
  margin: calc(.45 * var(--u)) 0 calc(.2 * var(--u)); }

/* The page frame on a non-exam page: its title, subtitle and flash messages
   in the type roles. Spacing around them stays main.css's (page layout). */
.ui .page-header h1 { font-size: var(--fs-page); font-weight: 600; letter-spacing: 0; line-height: 1.3; }
.ui .page-header-sub { font-size: var(--fs-small); }
.ui .flash { font-size: var(--fs-ui); }
/* Cards stacked down a page (not .stack: the exam's .pairs.stack is its own) */
.ui .stacked { display: grid; gap: calc(.8 * var(--u)); align-content: start; }
/* Report 3: an Rx's Note and its "Print the note" tick, under the Rx (punch4 R3) */
.ui .rx-note-opt { margin: calc(-.4 * var(--u)) 0 0 calc(2.2 * var(--u)); display: grid; gap: calc(.2 * var(--u)); }

/* The patient header (R4, from the exam): a sticky bar in place of the top
   bar on every patient page (_patient_header.html), the name in the name
   role and one meta line. The h1 form (the dashboard) drops main.css's h1. */
.ui .pt-hdr { position: sticky; top: 0; z-index: 40; background: #fff; border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.ui .pt-bar { display: flex; align-items: center; gap: calc(.5 * var(--u)) calc(.8 * var(--u)); padding: calc(.3 * var(--u)) calc(.8 * var(--u));
  flex-wrap: wrap; min-height: calc(var(--bar-h) - 1px); }   /* + .pt-hdr's border = the top bar, so the sidebar logo's line runs on */
/* The exam's first header row is a .pt-bar too, so where it fits on one row
   (wide screens) its line meets the logo's as well; it was 3.8u before Oct 17
   and is kept this way (review finding 4, Oct 22). */
.ui .pt-bar .topbar-menu { margin-right: calc(.2 * var(--u)); }
.ui .pt { display: flex; align-items: baseline; gap: calc(.55 * var(--u)); min-width: 0; }
.ui .pt-name { margin: 0; font-weight: 600; font-size: var(--fs-name); letter-spacing: 0; line-height: 1.4; white-space: nowrap;
  color: var(--text); text-decoration: none; }
.ui a.pt-name:hover { text-decoration: underline; }
.ui .pt-meta { font-size: var(--fs-small); color: var(--text-muted); white-space: nowrap; }
.ui .pt-acts { margin-left: auto; display: flex; align-items: center; gap: calc(.4 * var(--u)); flex-wrap: wrap; }

/* Cards: the exam's section card. .sec / .pc are the exam's own names for it. */
.ui :is(.card, .sec, .pc) { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-card); }
.ui :is(.card-header, .sec-h) { display: flex; align-items: center; gap: calc(.6 * var(--u));
  padding: calc(.3 * var(--u)) calc(.35 * var(--u)) calc(.3 * var(--u)) calc(.6 * var(--u)); min-height: calc(2.4 * var(--u)); }
/* A header's buttons a step up from btn-xs (Carson, R4: they read cramped): a
   card's, an exam section's and a panel card's. Elsewhere btn-xs is as is. */
.ui :is(.card-header, .sec-h, .pc-h) { --hdr-btn-h: calc(1.75 * var(--u)); --hdr-btn-px: calc(.65 * var(--u)); }
.ui :is(.card-header, .sec-acts, .pc-acts) .btn-xs { height: var(--hdr-btn-h); padding: 0 var(--hdr-btn-px);
  font-size: var(--fs-small); }
.ui :is(.card-title, .sec-title) { font-size: var(--fs-title); font-weight: 600; letter-spacing: 0; color: var(--text); }
.ui :is(.card-body, .sec-b) { padding: calc(.35 * var(--u)) calc(.6 * var(--u)) calc(.45 * var(--u)); }

/* Line lists (R4, from the exam panel): a card body of rows split by rules,
   the exam panel's cards (.pc-b) and the dashboard's Treatments and problem
   list (.lines). A fold holds more lines behind a button, muted: the problem
   list's Resolved (.pb-res on the exam, drawn by script; a <details> here)
   and the dashboard's Past treatments. */
.ui :is(.pc-b, .lines) .line { display: flex; gap: calc(.4 * var(--u)); align-items: baseline; padding: calc(.12 * var(--u)) 0; }
.ui :is(.pc-b, .lines) .line + .line { border-top: 1px solid var(--border); }
.ui :is(.pc-b, .lines) .grow { flex: 1; min-width: 0; }
.ui :is(.pc-b, .lines) .tx-note { color: var(--text-muted); font-size: var(--fs-micro); white-space: nowrap; }
.ui :is(.pc-b, .lines) .tx-stop b { text-decoration: line-through; }
.ui :is(.pb-res, .fold) { margin-top: calc(.3 * var(--u)); }
.ui :is(.pb-res, .fold) .line { color: var(--text-muted); }
.ui .fold > summary { list-style: none; width: max-content; }
.ui .fold > summary::-webkit-details-marker { display: none; }
.ui .fold[open] > summary { margin-bottom: calc(.15 * var(--u)); }

/* Buttons. The default is white and bordered; ghost is borderless, for icon
   and menu buttons only. */
.ui .btn { height: calc(1.85 * var(--u)); padding: 0 calc(.6 * var(--u)); border: 1px solid var(--border-mid);
  border-radius: 6px; background: #fff; font-family: inherit; font-size: var(--fs-ui); font-weight: 500;
  line-height: 1.4; white-space: nowrap; color: var(--text-secondary); display: inline-flex; align-items: center;
  justify-content: flex-start; gap: calc(.3 * var(--u)); transition: none; box-shadow: none; }
.ui .btn:hover:not(:disabled) { background: var(--bg-hover); box-shadow: none; }
.ui .btn:disabled { opacity: .45; cursor: default; }
.ui .btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.ui .btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.ui .btn-on { background: var(--brand-light); border-color: var(--brand); color: var(--brand-dark); font-weight: 600; }
.ui .btn-on:hover:not(:disabled) { background: var(--brand-mid); }
.ui .btn-xs { height: calc(1.55 * var(--u)); padding: 0 calc(.45 * var(--u)); font-size: var(--fs-caption); border-radius: 5px; }
.ui .btn-ghost { border-color: transparent; background: transparent; color: var(--text-secondary); }
.ui .btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-secondary); }
.ui .btn-danger { background: var(--red-light); border-color: var(--red-mid); color: var(--red); }
.ui .btn-danger:hover:not(:disabled) { background: var(--red-hover); }
/* Segmented control (R4, from the exam): one of a few choices, a bordered
   group, the chosen one light green (.on, or aria-selected on a tab). In a
   card header it takes the header buttons' height and corners. */
.ui .seg { display: inline-flex; border: 1px solid var(--border-mid); border-radius: 6px; overflow: hidden; }
.ui .seg button { border: 0; background: #fff; padding: calc(.1 * var(--u)) calc(.5 * var(--u)); font-size: var(--fs-small);
  color: var(--text-secondary); }
.ui .seg button + button { border-left: 1px solid var(--border-mid); }
.ui .seg button:is(.on, [aria-selected="true"]) { background: var(--brand-light); color: var(--brand-dark); font-weight: 600; }
.ui .card-header .seg { height: var(--hdr-btn-h); border-radius: 5px; }
.ui .card-header .seg button { padding: 0 var(--hdr-btn-px); }
/* Fine print: hints, notes, sources; one with a title explains on hover */
.ui .hint { font-size: var(--fs-micro); color: var(--text-faint); }
.ui .hint[title] { cursor: help; }

/* The hidden attribute always hides: .btn's display (decision 50) and any
   page's own display rules would beat a plain [hidden], whichever loads later. */
.ui [hidden] { display: none !important; }

/* Badges: the UI face, 600, the caption role; colours from tokens */
.ui .badge { font-family: inherit; font-size: var(--fs-caption); font-weight: 600; padding: calc(.12 * var(--u)) calc(.5 * var(--u));
  border-radius: 999px; white-space: nowrap; }
.ui :is(.badge-draft, .badge-amber) { background: var(--amber-light); color: var(--amber); }
.ui :is(.badge-complete, .badge-green) { background: var(--green-light); color: var(--green-dark); }
.ui .badge-gray { background: var(--gray-light); color: var(--text-muted); }
.ui .badge-blue { background: var(--blue-light); color: var(--blue); }
.ui .badge-red { background: var(--red-light); color: var(--red); }
.ui .badge-purple { background: var(--purple-light); color: var(--purple); }

/* Tables: mono column headers, not uppercase, no grey band; ui-role cells.
   Full-width list tables get this padding; the exam's tables set their own. */
.ui table { font-size: var(--fs-ui); }
.ui thead th { font-family: var(--font-mono); font-size: var(--fs-micro); font-weight: 600; text-transform: none; letter-spacing: .03em;
  color: var(--text-muted); background: none; padding: calc(.45 * var(--u)) calc(.6 * var(--u)); }
.ui tbody td { padding: calc(.45 * var(--u)) calc(.6 * var(--u)); }
/* A full-history table's sortable heading (history_table.js): the button
   carries the cell's padding, so the cell has none. Screen only: in print the
   button is hidden and history_print.css pads the cell and its plain copy. */
@media screen { .ui thead th.is-sortable { padding: 0; } }
.ui .sort-btn { padding: calc(.45 * var(--u)) calc(.6 * var(--u)); }

/* Record pieces (R4, the patient dashboard; the history and form pages
   share them from R5): main.css's mono-uppercase labels and rem sizes, on
   the roles. Numbers in the UI face with tabular figures, not the mono. */
.ui .td-mono { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: inherit; }
/* A long unbroken value (an email address) wraps rather than widen its table
   past the card (R8: the users table at 1024) */
.ui .td-wrap { overflow-wrap: anywhere; }
.ui [data-lc] .table-wrap.cq > table :is(th, td):first-child { padding-left: calc(.6 * var(--u)); }
/* A narrow list card's cells (main.css's 8px rule under 600px, which .ui
   tbody td has outranked since R2): closes UI.2 finding 6 at 1200 (R5). The
   first column keeps the card's .6u left edge above. */
@container (max-width: 600px) { .ui .cq :is(thead th, tbody td) { padding-left: calc(.45 * var(--u)); padding-right: calc(.45 * var(--u)); } }
.ui .card-title-group { gap: calc(.45 * var(--u)); }
.ui .card-count { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: var(--fs-micro); line-height: 1.4;
  padding: 0 calc(.45 * var(--u)); }
.ui .card-foot { padding: calc(.4 * var(--u)) calc(.6 * var(--u)); }
.ui .card-foot-link { font-size: var(--fs-small); }
/* Two links in one foot (the Treatments card's history and atropine Rx list) */
.ui .card-foot-split { display: flex; flex-wrap: wrap; justify-content: space-between; gap: calc(.4 * var(--u)) var(--u); }
.ui .empty-state { padding: calc(1.6 * var(--u)) calc(1.2 * var(--u)); }
.ui .empty-state-title { font-size: var(--fs-ui); margin-bottom: calc(.3 * var(--u)); }
.ui .empty-state p { font-size: var(--fs-small); }
.ui .detail-row { gap: calc(.8 * var(--u)); padding: calc(.45 * var(--u)) 0; }
.ui .detail-label { font-family: inherit; font-size: var(--fs-small); font-weight: 400; text-transform: none; letter-spacing: 0;
  min-width: calc(7.5 * var(--u)); }
.ui .detail-value { font-size: var(--fs-ui); }
.ui .notes-text { font-size: var(--fs-ui); line-height: 1.5; }
.ui :is(.contact-ok, .address-unverified) { font-size: var(--fs-micro); }
.ui .flash-undo { gap: calc(.8 * var(--u)); }
.ui .discarded-drafts { font-size: var(--fs-small); padding: calc(.4 * var(--u)) calc(.6 * var(--u)); gap: calc(.25 * var(--u)) calc(.9 * var(--u)); }
/* The Progression card (its tabs are a .seg, Risk bands a btn-xs / btn-on, its fine print .hint): the
   legend in the UI face, each eye's rate coloured by its SE flag */
.ui :is(.chart-legend-item, .chart-risk-legend-item) { font-family: inherit; font-size: var(--fs-caption); }
.ui .chart-rate.rate-fast { color: var(--red); }
.ui .chart-rate.rate-slow { color: var(--green-dark); }
.ui .chart-empty { font-size: var(--fs-small); }
/* Phase PROG: "Norms" and the toggle between the sources a patient is offered; PROG-2: the
   Practice toggle and its "Compare with" choice */
.ui :is(.chart-foot-norms, .chart-foot-practice) { display: flex; flex-wrap: wrap; align-items: center; gap: calc(.3 * var(--u)) calc(.5 * var(--u)); }
.ui :is(.chart-foot-norms, .chart-foot-practice) .seg button { white-space: nowrap; }
/* Hidden means hidden in a chart panel: main.css's .chart-panel .is-hidden loses
   to any display rule here, such as the row above's */
.ui .chart-panel .is-hidden { display: none; }

/* Fields: the exam's .f, with a plain label (.fl) in the small role */
.ui .f { width: 100%; height: calc(1.7 * var(--u)); padding: 0 calc(.45 * var(--u)); border: 1px solid var(--border); border-radius: 5px;
  background: #fff; font-size: var(--fs-input); color: var(--text); min-width: 0; }
.ui textarea.f { height: auto; min-height: calc(3.6 * var(--u)); padding: calc(.3 * var(--u)) calc(.45 * var(--u)); resize: vertical;
  line-height: 1.4; display: block; }
.ui select.f { padding-right: calc(.2 * var(--u)); }
/* Focus rings are --brand (9.9:1 on white, 8.6:1 on cream): a focus indicator needs 3:1, and --brand-mid was 1.6:1
   (brandfix). The error ring is --red (6.5:1). tests/test_focus_rings.py keeps a pale ring from coming back. */
.ui :is(.f:focus, .search-bar:focus-within) { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.ui :is(.f, .search-bar input)::placeholder { color: var(--text-faint); font-style: italic; opacity: 1; }
.ui .f.err { border-color: var(--red); background: var(--red-light); }
.ui .f.err:focus { outline-color: var(--red); }
/* align-content: a field whose grid row is taller (a neighbour's hint, the
   patient form's Relationship specify) keeps its label on its input (R6c, R8) */
.ui .fl { display: grid; gap: calc(.15 * var(--u)); align-content: start; font-size: var(--fs-small);
  color: var(--text-secondary); }

/* Choices: a radio group as bordered rows, the chosen one tinted (the
   Account page's Text size, R3b) */
.ui .choices { display: grid; gap: calc(.3 * var(--u)); border: 0; padding: 0; margin: 0; min-width: 0; }
/* A legend is no grid item, so the gap above doesn't reach it */
.ui .choices legend { padding: 0; margin-bottom: calc(.3 * var(--u)); }
.ui .choice { display: flex; align-items: center; gap: calc(.5 * var(--u)); padding: calc(.4 * var(--u)) calc(.6 * var(--u));
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.ui .choice:hover { border-color: var(--border-mid); }
.ui .choice:has(input:checked) { border-color: var(--brand); background: var(--brand-light); }
.ui .choice input { margin: 0; accent-color: var(--brand); width: calc(.9 * var(--u)); height: calc(.9 * var(--u)); }
.ui .choice .muted { margin-left: auto; }

/* Menus and popovers: <details class="menu"> lists and the script-placed .pop */
.ui :is(.menu-list, .pop) { background: #fff; border: 1px solid var(--border-mid); border-radius: 8px; box-shadow: var(--shadow-md);
  padding: calc(.3 * var(--u)); min-width: calc(12 * var(--u)); font-size: var(--fs-ui); }
.ui .pop { position: fixed; z-index: 70; max-width: calc(20 * var(--u)); }
.ui :is(.menu-item, .pop button.opt) { display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: calc(.3 * var(--u)) calc(.5 * var(--u)); border-radius: 5px; font-size: inherit; color: var(--text); }
.ui :is(.menu-item, .pop button.opt):is(:hover, :focus-visible) { background: var(--bg-hover); }
.ui :is(.menu-list, .pop) .sep { border-top: 1px solid var(--border); margin: calc(.25 * var(--u)) 0; }
.ui :is(.menu-list, .pop) .lbl { font-size: var(--fs-micro); color: var(--text-muted); padding: calc(.2 * var(--u)) calc(.5 * var(--u)); }
.ui :is(.menu-list, .pop) .lbl.warn { color: var(--amber); }

/* The in-page confirm: <details class="menu confirm"> whose list says what
   the action does, maybe asks for a reason, and ends in the action button.
   Every confirm in the app is one since R7c (window.confirm is gone). */
.ui .menu.confirm .menu-list { display: flex; flex-direction: column; gap: calc(.4 * var(--u));
  width: calc(21.3 * var(--u)); max-width: calc(100vw - 32px); padding: calc(.6 * var(--u)); }
.ui .menu.confirm textarea { width: 100%; font: inherit; font-size: var(--fs-input); }
.ui .menu.confirm .btn { align-self: flex-end; }
/* A page header's actions stack at the left below 900px (main.css), so a
   menu there opens rightward from its button, not off the screen's left edge. */
@media (max-width: 899.98px) { .ui .page-header-actions .menu-list { left: 0; right: auto; } }

/* Record forms and detail pages (R6): the glasses Rx and topography forms and
   their detail pages. main.css's layout grids stay (form-grid-2, eye-columns,
   mm-d-row; the glasses form went in rxunify U3); their spacing moves to u and their labels
   onto the roles: no mono, no uppercase but the .sub sub-headings. */
/* A card header's own buttons (the Rx form's Import): they wrap below the title when it's narrow */
.ui .card-header:has(.card-acts) { flex-wrap: wrap; row-gap: calc(.3 * var(--u)); }
.ui .card-acts { margin-left: auto; display: flex; align-items: center; gap: calc(.4 * var(--u)); flex-wrap: wrap; }
.ui .form-grid-2 { gap: calc(.6 * var(--u)) calc(1 * var(--u)); }
.ui .form-actions { gap: calc(.5 * var(--u)); padding-top: 0; }
.ui .fl .unit { color: var(--text-faint); }
.ui .check { display: inline-flex; align-items: center; gap: calc(.4 * var(--u)); font-size: var(--fs-ui); cursor: pointer; }
.ui .check input { margin: 0; accent-color: var(--brand); width: calc(.9 * var(--u)); height: calc(.9 * var(--u)); }
.ui .notice-box { display: flex; flex-wrap: wrap; align-items: baseline; gap: calc(.4 * var(--u)); margin: 0;
  padding: calc(.45 * var(--u)) calc(.6 * var(--u)); background: var(--bg-sub); border-radius: 6px; font-size: var(--fs-ui); }
/* OD | OS side by side, each eye's heading in its colour (the R4 eye tokens) */
.ui .eye-columns { gap: calc(1.2 * var(--u)); }
.ui .eye-head { font-size: var(--fs-title); font-weight: 600; padding-bottom: calc(.3 * var(--u)); margin-bottom: calc(.5 * var(--u));
  border-bottom: 2px solid var(--border); }
.ui .eye-head.od { color: var(--od-ink); border-color: var(--od-border); }
.ui .eye-head.os { color: var(--os-ink); border-color: var(--os-border); }
.ui .mm-d-row { gap: calc(.35 * var(--u)); }
/* An eye column's groups (Sim-K, Axes, …): a .sub over its fields */
.ui .eye-group { display: grid; gap: calc(.5 * var(--u)); }
.ui .eye-group + .eye-group { margin-top: calc(.5 * var(--u)); padding-top: calc(.2 * var(--u)); border-top: 1px solid var(--border); }
.ui .mm-d-sep { font-family: inherit; font-size: var(--fs-ui); padding-bottom: calc(.3 * var(--u)); }
/* A value worked out from the fields (topography's ΔK): read-only, a field's size */
.ui .calc-display { display: flex; align-items: center; gap: calc(.4 * var(--u)); min-height: calc(1.7 * var(--u)); padding: 0 calc(.45 * var(--u));
  background: var(--bg-sub); border: 1px solid var(--border); border-radius: 5px; font-family: var(--font-num);
  font-variant-numeric: tabular-nums; font-size: var(--fs-input); }
/* Detail pages: the Field | OD | OS table, its section rows a .sub */
.ui .detail-table thead th { padding: calc(.3 * var(--u)) calc(.8 * var(--u)) calc(.3 * var(--u)) 0; }
.ui .detail-table thead th:not(:first-child) { padding: calc(.3 * var(--u)) calc(.8 * var(--u)); }
.ui .detail-table tbody td { padding: calc(.35 * var(--u)) calc(.8 * var(--u)) calc(.35 * var(--u)) 0; }
.ui .detail-table tbody td:not(:first-child) { padding: calc(.35 * var(--u)) calc(.8 * var(--u)); }
.ui .detail-table tbody td.detail-section-row { padding: calc(.2 * var(--u)) 0 0; font: inherit; text-transform: none; letter-spacing: 0; }
/* A shown value: numbers in the UI face with tabular figures (not the mono) */
.ui .val { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 500; color: var(--text); }
.ui .detail-field-label { font-size: var(--fs-ui); font-weight: 500; }
.ui :is(.detail-field-unit, .detail-field-auto) { font-family: inherit; font-size: var(--fs-micro); }
.ui .detail-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: calc(.3 * var(--u)); font-size: var(--fs-small);
  color: var(--text-muted); }
@media (max-width: 599.98px) {
  /* Phone: OD above OS, not squeezed side by side */
  .ui .eye-columns { flex-direction: column; }
  .ui .eye-divider { width: auto; height: 1px; align-self: stretch; }
}

/* The lens detail page (R6b): parameters two to a row, zones a table under
   them. The lens form went in D3a: the lens editor (css/rx_editor.css)
   enters and edits a lens everywhere. */
.ui .form-grid-3 { gap: calc(.6 * var(--u)) calc(1 * var(--u)); }
.ui .err-msg { color: var(--red); font-size: var(--fs-small); font-weight: 500; }
/* A warning that asks before going on (the lens editor's "same as the last lens") */
.ui .warn-box { display: grid; gap: calc(.3 * var(--u)); justify-items: start; padding: calc(.5 * var(--u)) calc(.6 * var(--u));
  background: var(--amber-light); border: 1px solid #fcd34d; border-radius: 6px; }
.ui .warn-box b { color: var(--amber); font-weight: 600; }
.ui .warn-acts { display: flex; flex-wrap: wrap; gap: calc(.4 * var(--u)); }
/* Headers wrap; no letter-spacing, so "Diameter" fits a phone's column, and a
   word still too long breaks rather than run into the next */
.ui .lens-zones thead th { white-space: normal; letter-spacing: 0; overflow-wrap: anywhere; vertical-align: bottom; }
.ui .params-grid-2 { gap: 0 calc(2 * var(--u)); }
.ui .lens-zones { margin-top: calc(.4 * var(--u)); }
@media (max-width: 599.98px) {
  .ui .params-grid-2 { grid-template-columns: 1fr; }
}

/* Patient form (R6c). Contact rows: a heading (Contact N + Remove) only when
   there are two or more; the three checkboxes level with the Relationship
   select through a label-sized spacer (the .fl's first line), dropped when
   no select sits beside them (a Self row, or one column below 900px, where
   main.css's form grids stack). The address type-ahead's list is a
   .menu-list of .menu-item rows; the keyboard's pick shows as a hover. */
.ui .contact-row-head { margin-bottom: calc(.4 * var(--u)); }
.ui .contact-row-head .sub { margin: 0; }
.ui .contact-row + .contact-row { margin-top: calc(1 * var(--u)); padding-top: calc(.8 * var(--u)); }
.ui .contact-rel { gap: calc(.6 * var(--u)); }
.ui .contact-checks-row { display: flex; flex-wrap: wrap; align-items: center; gap: calc(.3 * var(--u)) calc(1 * var(--u));
  min-height: calc(1.7 * var(--u)); padding-block: 0; }
.ui .contact-self-hide[hidden] + .contact-checks > span:first-child { display: none; }
@media (max-width: 900px) { .ui .contact-checks > span:first-child { display: none; } }
.ui .address-suggestions { margin-top: 2px; }   /* a .menu-list of .menu-item rows */
/* main.css's .card clips its overflow, which cut the list at the Address card's
   edge (2 of 5 rows showed at 1440 before R6c). This card's header and body are
   transparent, so its rounded corners hold without the clip. */
.ui .card:has(.address-lookup) { overflow: visible; }
/* (beats .menu-item's background: none, whose :is() counts as .pop button.opt) */
.ui .address-suggestions .menu-item[aria-selected="true"] { background: var(--bg-hover); }
@media screen and (pointer: coarse), screen and (max-width: 899.98px) {
  .ui .eye-seg button { min-height: 44px; }
}

/* The treatment editor (R6d-2, _treatment_editor.html): a details.menu whose
   list app.js places with position: fixed beside its summary, from its left
   edge (a .tx-right one, at the right of a row, from its right edge).
   Its sections (Edit, Stop, an admin's Delete) one above the other. */
.ui .tx-edit { vertical-align: baseline; }
.ui .tx-edit:not(.tx-right) > .menu-list { left: 0; right: auto; }
.ui .tx-edit.tx-right > .menu-list { left: auto; right: 0; }  /* in a narrow page header too */
.ui .tx-edit > summary { cursor: pointer; }
.ui .tx-edit > summary.tx-name { font-weight: 600; color: var(--text); }
.ui .tx-edit > summary.tx-name:hover { color: var(--brand-dark); text-decoration: underline; }
.ui .tx-edit .tx-form { display: grid; gap: calc(.6 * var(--u)); width: calc(21.3 * var(--u)); max-width: calc(100vw - 16px);
  padding: calc(.6 * var(--u)); overflow: auto; font-weight: 400; text-align: left; white-space: normal; }
.ui .tx-form .sub { margin: 0; }
.ui .tx-form > * + :is(form, .tx-del) { border-top: 1px solid var(--border); padding-top: calc(.6 * var(--u)); }
.ui .tx-form .stacked { gap: calc(.5 * var(--u)); }
.ui .tx-acts { display: flex; justify-content: flex-end; gap: calc(.4 * var(--u)); }
.ui .tx-del > summary { list-style: none; width: max-content; }
.ui .tx-del > summary::-webkit-details-marker { display: none; }
.ui .tx-del[open] > summary { margin-bottom: calc(.4 * var(--u)); }

/* The patient list's search (R7a): main.css's search bar in the field's look
   (.f), as tall as the New patient button beside it */
.ui .search-bar { height: calc(1.85 * var(--u)); gap: calc(.45 * var(--u)); padding: 0 calc(.5 * var(--u)); border: 1px solid var(--border);
  border-radius: 6px; }
.ui .search-bar input { font-size: var(--fs-input); padding: 0; }
.ui .search-bar input:focus { outline: none; }  /* the bar's ring (:focus-within) is the indicator, not a second one inside it */
.ui .search-bar-icon { width: var(--u); height: var(--u); }
.ui .page-header-count { font-size: var(--fs-small); }
/* Level with the sidebar's Patients link at >=900px, where the sidebar shows
   (Carson, Oct 17): --tb-h tall, centred on the link. The link's top is the
   logo's (--bar-h, as the top bar) then its gap and the Clinic label, less
   .content's 32px top padding. --tb-h is the link's height, or 44px on a
   touch screen (the touch minimum below), centred on the link all the same. */
@media (min-width: 900px) {
  .ui .page-header-toolbar { --tb-h: var(--nav-link-h);
    margin-top: calc(var(--sb-logo-gap) + var(--nav-label-h) - 32px - (var(--tb-h) - var(--nav-link-h)) / 2); }
  .ui .page-header-toolbar :is(.search-bar, .btn) { height: var(--tb-h); }
}
@media screen and (pointer: coarse) and (min-width: 900px) {
  .ui .page-header-toolbar { --tb-h: max(44px, var(--nav-link-h)); }
}
/* The record's Visit history A&P (punch1, Carson Nov 19: shown at 1440):
   the column takes the room the others leave (width 100% + max-width 0) but
   never less than 120px (the inner div's min-width, which a table cell's own
   min-width can't give), so Type breaks between its parts first; one line cut
   with "…". Hidden when the card can't spare that (<= 640px: the other
   columns take ~500px). */
.ui .vh-ap { width: 100%; max-width: 0; }
.ui .vh-ap > div { min-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@container (max-width: 640px) { .ui .cq .vh-ap { display: none; } }
/* The A&P's width 100% leaves Type its narrowest; on a wide card (>= 800px:
   the rest ~400px + the longest type ~220px + the A&P's 120px) Type keeps one
   line and the A&P still gets the rest. */
@container (min-width: 800px) { .ui .cq .vh-type { white-space: nowrap; } }
/* The Patients list's name link (punch1, Carson Nov 19): no underline until
   hovered, as the patient header's name. */
.ui a.pl-name { text-decoration: none; }
.ui a.pl-name:hover { text-decoration: underline; }
/* The list's Last exam notes: the exam's date, then its A&P cut to two lines
   (the cell's title holds the whole note). */
.ui .pl-note { min-width: calc(12 * var(--u)); max-width: calc(24 * var(--u)); overflow: hidden;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
.ui .pl-note-date { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Admin pages (R7b). Page tabs: the brand catalogs' and Deleted records'
   sections, links drawn as buttons, the current one on (_brand_tabs.html,
   _deleted_tabs.html). They wrap rather than widen a narrow page. */
.ui .tabs { display: flex; flex-wrap: wrap; gap: calc(.3 * var(--u)); margin-bottom: calc(.8 * var(--u)); }
.ui .tabs .btn { text-decoration: none; }
/* An inactive row (an inactive user or brand, a file's refused patient):
   main.css dims it with opacity, which would dim a confirm box opened from it
   too, so here its text is muted instead (as lc.row's not-current rows are) */
.ui tr.row-dim { opacity: 1; }
.ui tr.row-dim > td { color: var(--text-muted); }
/* An in-page confirm in a table row (app.js places its box): the box reads as
   the page does, whatever its cell's alignment and a muted row's colour */
.ui td .menu.confirm .menu-list { text-align: left; white-space: normal; font-weight: 400; color: var(--text); }
/* The lens brand form's designs editor and its preview (brand_form.js draws
   the preview's blocks and pills): on the roles; JSON and field keys stay
   mono (they are code) */
.ui .json-editor-wrap textarea { font-family: var(--font-mono); font-size: var(--fs-small); min-height: calc(18 * var(--u)); }
.ui .json-error { font-family: var(--font-mono); font-size: var(--fs-small); margin-top: calc(.4 * var(--u)); }
.ui .json-preview { background: var(--bg-sub); border-radius: 6px; padding: calc(.6 * var(--u)); margin: 0; }
.ui .json-preview .sub { margin-top: 0; }
.ui .preview-empty { font-size: var(--fs-ui); margin: 0; }
.ui .design-block { margin-bottom: calc(.6 * var(--u)); padding-bottom: calc(.6 * var(--u)); }
.ui .design-name { font-size: var(--fs-title); margin-bottom: calc(.35 * var(--u)); }
.ui .field-pill { font-family: var(--font-mono); font-size: var(--fs-caption); gap: calc(.3 * var(--u));
  padding: calc(.12 * var(--u)) calc(.5 * var(--u)); margin: calc(.15 * var(--u)) calc(.15 * var(--u)) calc(.15 * var(--u)) 0; }
.ui .field-pill .field-type { font-size: var(--fs-micro); }
.ui .preview-row { margin-bottom: calc(.3 * var(--u)); }
.ui .preview-meta { font-family: var(--font-mono); font-size: var(--fs-micro); }
/* Exam settings' tables (the exam types and their reasons, the pharmacy rows):
   main.css's tight px cells, in u */
.ui .st-table :is(th, td) { padding: calc(.2 * var(--u)) calc(.45 * var(--u)); }
.ui .st-table :is(th, td):first-child { padding-left: 0; }
.ui .st-pharm .st-ml { width: calc(5 * var(--u)); }
.ui .st-acts .btn { padding: 0 calc(.35 * var(--u)); }
.ui .st-table input[type="checkbox"] { display: block; margin: 0; accent-color: var(--brand); width: calc(.9 * var(--u));
  height: calc(.9 * var(--u)); }

/* The recall list (R7a): the filter bar in the header toolbar, and the row a
   ⋯ opens (contact log, status actions), spaced in u */
.ui .rc-filters { gap: calc(.5 * var(--u)); }
.ui .rc-filters .f { width: auto; height: calc(1.85 * var(--u)); }  /* level with Filter / Reset */
.ui .rc-filters label { gap: calc(.4 * var(--u)); }
.ui .rc-panel { gap: calc(1.6 * var(--u)); padding: calc(.25 * var(--u)) 0; }
.ui .rc-status { gap: calc(.4 * var(--u)); }
.ui .rc-line { padding: calc(.25 * var(--u)) 0; }
.ui .rc-form { gap: calc(.5 * var(--u)); margin-top: calc(.5 * var(--u)); }
.ui .rc-form .f { width: auto; flex: 1 1 calc(10.7 * var(--u)); }
.ui .rc-form input[type="date"].f { flex: 0 1 auto; }
.ui .rc-methods { gap: calc(.8 * var(--u)); }
.ui .rc-methods label { gap: calc(.27 * var(--u)); }
.ui .pager { gap: calc(.5 * var(--u)); }

/* Toast: one line at the bottom, with an optional action (Undo) */
.ui .toast { position: fixed; left: 50%; bottom: calc(1.2 * var(--u)); transform: translateX(-50%); background: var(--text); color: #fff;
  padding: calc(.45 * var(--u)) calc(.8 * var(--u)); border-radius: 8px; font-size: var(--fs-ui); z-index: 90; display: flex;
  gap: calc(.7 * var(--u)); align-items: center; opacity: 0; pointer-events: none; transition: opacity .15s; max-width: min(40rem, 92vw); }
.ui .toast.show { opacity: 1; pointer-events: auto; }
.ui .toast button { background: none; border: 0; color: #9be3c4; font-weight: 600; }

@media (max-width: 899.98px) {
  /* Portrait tablet: the touch-sized header wraps, so it scrolls away instead of sticking */
  .ui .pt-hdr { position: static; }
}
@media (max-width: 599.98px) {
  /* Phone: the name and the meta line wrap rather than widen the page */
  .ui .pt { flex-wrap: wrap; row-gap: 0; }
  .ui :is(.pt-name, .pt-meta) { white-space: normal; }
}
/* The session-timeout warning (S.7 step (c), A3; _session_timeout.html), on
   every signed-in page, all of which are ui pages since R7c, and the state
   session_timeout.js puts the page in the moment it starts signing someone
   out. That class hides everything before the sign-out request goes out, so
   a patient record leaves the screen even if the request never completes —
   and a Back-button restore of that page from the browser's cache comes back
   hidden too, because the class is part of what was cached. main.css's reset
   zeroes margin on everything, and a modal <dialog> is centred by the
   browser's own margin: auto, hence the margin. */
.ui .session-dialog { margin: auto; max-width: 440px; width: calc(100% - 32px); padding: calc(1.4 * var(--u));
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); color: var(--text);
  box-shadow: var(--shadow-md); }
.ui .session-dialog::backdrop { background: rgba(26, 31, 30, 0.55); }
.ui .session-dialog-title { margin: 0 0 calc(.6 * var(--u)); font-size: var(--fs-name); font-weight: 600; }
.ui .session-dialog-text { margin: 0; font-size: var(--fs-ui); color: var(--text-secondary); line-height: 1.5; }
.ui .session-dialog-text strong { font-variant-numeric: tabular-nums; }
.ui .session-dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: calc(.5 * var(--u));
  margin-top: calc(1.3 * var(--u)); }
html.session-ending body { visibility: hidden; }

@media print {
  /* The patient header is the printed page's patient line (R5 history pages) */
  .ui .pt-hdr { position: static; border-bottom: 0; box-shadow: none; }
  .ui .pt-bar { padding: 0 0 calc(.4 * var(--u)); min-height: 0; }
  .ui .pt-bar :is(.topbar-menu, .pt-acts) { display: none; }
  .ui .history-card { border: 0; border-radius: 0; box-shadow: none; }
  /* A page prints what it records, not its controls (R7a for the dashboard,
     R8 for every page): buttons and menu buttons (+ Add, Edit, Delete ▾,
     Stop ▾, New exam, Print), segmented tabs, a menu or editor left open.
     A treatment's name (its editor's summary, .tx-name) isn't a .btn: it
     stays. !important: a header's or card's own display rule outranks this. */
  .ui :is(.btn, .seg, .menu-list) { display: none !important; }
  .ui .lg-patients-record .chart-hints .hint:not([data-chart-source]) { display: none; }
}
/* Touch sizes: screens only, since a printed page is narrower than 900px too
   (R7a: the dashboard printed its buttons 44px tall) */
@media screen and (pointer: coarse), screen and (max-width: 899.98px) {
  .ui .f, .ui .btn { min-height: 44px; }
  .ui .check { min-height: 44px; }  /* the label is the target: it wraps the box */
  .ui .search-bar { height: auto; min-height: 44px; }
  /* a header's segmented tabs too (the exam's eye picker in a popover keeps its size) */
  .ui .card-header .seg { height: auto; min-height: 44px; }
  .ui :is(.chart-foot-norms, .chart-foot-practice) .seg { min-height: 44px; }
}
