/* CEG Health Centre -- clinic console.
 *
 * Hand-written, no framework, no build step (spec section 3).
 *
 * A calm clinical workspace: white panels on a cool grey canvas, slate ink,
 * one clinical teal for action, selection and focus, and a fixed meaning for
 * every other colour -- red is allergy, cancellation and destructive action,
 * amber is out of range or needing attention, green is done. The CEG crest is
 * the only brand colour. Inter, held on this machine, with tabular figures
 * wherever numbers line up.
 *
 * The accessibility floor from spec section 7 is not decoration: 48px targets,
 * 16px base text and nothing below 14px, every icon beside a text label, full
 * keyboard operation, visible focus, and no horizontal scrolling at 1366x768.
 */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/static/inter-latin.woff2') format('woff2');
}

:root {
  --canvas: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f2f4f7;

  --ink: #101828;
  --ink-2: #344054;
  --muted: #5d6b7e;

  --line: #e3e6ea;
  --line-strong: #c9d0d8;

  --accent: #0b6e76;
  --accent-hover: #095a61;
  --accent-ink: #07525a;
  --accent-wash: #e7f3f4;
  --accent-line: #a9d2d5;

  --danger: #b42318;
  --danger-hover: #912018;
  --danger-ink: #7a271a;
  --danger-wash: #fef3f2;
  --danger-line: #fecdca;

  --warn: #b54708;
  --warn-ink: #93370d;
  --warn-wash: #fffaeb;
  --warn-line: #fedf89;

  --ok: #067647;
  --ok-ink: #085d3a;
  --ok-wash: #ecfdf3;
  --ok-line: #abefc6;

  --restricted: #3e4784;
  --restricted-wash: #eef0fb;

  --sans: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, Menlo, monospace;

  --tap: 48px;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar: 248px;
  --appbar: 72px;
  --gutter: 28px;

  --shadow-pop: 0 12px 32px rgba(16, 24, 40, 0.14), 0 2px 6px rgba(16, 24, 40, 0.06);
  --shadow-bar: 0 -8px 24px rgba(16, 24, 40, 0.07);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  --check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: #c3e3e5; color: var(--ink); }
input, textarea { caret-color: var(--accent); }
* { scrollbar-color: #c3cad3 transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #c3cad3; border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

h1 { font-size: 26px; line-height: 1.25; font-weight: 650; letter-spacing: -0.015em; margin: 0 0 4px; text-wrap: balance; }
h2 { font-size: 18px; line-height: 1.35; font-weight: 600; letter-spacing: -0.005em; margin: 0 0 12px; }
h3 { font-size: 16px; line-height: 1.4; font-weight: 600; margin: 0 0 10px; color: var(--ink); }
p { margin: 0 0 12px; }
strong { font-weight: 600; }

.page-sub { color: var(--muted); margin: 0 0 20px; }
.card-sub { color: var(--muted); margin: -4px 0 16px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 15px; margin: 12px 0 0; }
.num { font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; color: var(--ink); }
.right { text-align: right; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.push { margin-left: auto; }
.flush { margin: 0; }
.flush-top { margin-top: 0; }
.spaced { margin-top: 16px; }
.narrow { max-width: 680px; }
ul.plain { margin: 0; padding-left: 18px; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 12px; top: -80px; z-index: 100;
  background: var(--surface); color: var(--ink); padding: 12px 16px;
  border: 2px solid var(--accent); border-radius: var(--radius);
}
.skip:focus { top: 12px; }

kbd {
  display: inline-block; min-width: 22px; padding: 0 6px;
  font: 500 14px/22px var(--sans); color: var(--ink-2); text-align: center;
  background: var(--surface); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px;
}

svg { flex: none; }

/* ===================================================================== */
/* The shell: sidebar, top bar, workspace                                */
/* ===================================================================== */

body.app {
  display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh;
  /* The sidebar's white column and its rule run the full height of a long page. */
  background: linear-gradient(to right, var(--surface) calc(var(--sidebar) - 1px), var(--line) calc(var(--sidebar) - 1px), var(--line) var(--sidebar), var(--canvas) var(--sidebar));
}

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 16px 12px;
}

.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 12px 16px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
.brand:hover { color: inherit; }
.crest-img { display: block; flex: none; height: auto; }
.brand-unit { display: block; font-weight: 650; font-size: 17px; line-height: 1.25; letter-spacing: -0.01em; }
.brand-org { display: block; font-size: 14px; color: var(--muted); line-height: 1.3; }

.nav { display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap); padding: 0 12px; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--ink-2); text-decoration: none;
  font: 500 16px var(--sans); cursor: pointer; width: 100%; text-align: left;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.nav-item svg { width: 20px; height: 20px; color: var(--muted); transition: color 150ms var(--ease); }
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item:hover svg { color: var(--ink-2); }
.nav-item[aria-current='page'] { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.nav-item[aria-current='page'] svg { color: var(--accent); }
.nav-item kbd { margin-left: auto; }

.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.who { display: grid; gap: 4px; padding: 8px 0 0; }
.who-text { display: grid; padding: 0 12px 4px; }
.who-name { font-weight: 600; line-height: 1.3; }
.who-role { font-size: 14px; color: var(--muted); }
.who-switch {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); border: 1px solid var(--line-strong); border-radius: var(--radius);
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 15px;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease);
}
.who-switch { margin-top: 4px; }
/* Sign out is a form (a POST, so no other page can sign anyone out); the button looks like the link it was. */
.who-form { display: grid; margin: 0; }
button.who-switch { width: 100%; background: transparent; font: inherit; font-weight: 600; font-size: 15px; cursor: pointer; }
.who-switch svg { width: 18px; height: 18px; }
.who-link {
  display: flex; align-items: center; min-height: var(--tap); padding: 0 12px; border-radius: var(--radius);
  color: var(--muted); font-size: 15px; font-weight: 500; text-decoration: none;
}
.who-link:hover { color: var(--ink); background: var(--surface-3); }
.who-switch:hover { background: var(--surface-2); border-color: #aeb7c2; color: var(--ink); }

.workspace { min-width: 0; display: flex; flex-direction: column; }

.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  min-height: var(--appbar);
  /* The right edge lines up with main's, which stops at 1360px. */
  padding: 10px calc(max(0px, 100% - 1360px) + var(--gutter)) 10px var(--gutter);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.appbar > .btn { min-height: 52px; }

.appsearch { position: relative; flex: 1; display: flex; align-items: center; margin: 0; }
.appsearch > svg { position: absolute; left: 16px; width: 22px; height: 22px; color: var(--muted); pointer-events: none; }
.appsearch input[type='search'] {
  width: 100%; min-height: 52px; padding: 0 64px 0 50px;
  font: 400 18px var(--sans); color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 10px;
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease), background-color 150ms var(--ease);
}
.appsearch input[type='search']::placeholder { color: #6b7789; }
.appsearch input[type='search']:hover { border-color: #aeb7c2; }
.appsearch input[type='search']:focus { outline: none; background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px rgba(11, 110, 118, 0.14); }
.appsearch input::-webkit-search-cancel-button { display: none; }
.appsearch-key { position: absolute; right: 14px; pointer-events: none; }

.search-pop {
  display: none; position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 40;
  max-height: min(70vh, 560px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop); padding: 6px;
}
.appsearch:focus-within .search-pop:not(:empty) { display: block; animation: pop-in 160ms var(--ease); }
.search-note { margin: 0; padding: 8px 12px; font-size: 14px; color: var(--muted); }
.search-empty { padding: 20px 16px; text-align: center; color: var(--ink-2); }
.search-empty p { margin-bottom: 12px; }

.results { display: grid; gap: 2px; }
.result {
  display: flex; align-items: center; gap: 14px;
  min-height: 72px; padding: 8px 12px; border-radius: var(--radius);
  color: inherit; text-decoration: none;
}
.result > svg { width: 20px; height: 20px; color: var(--muted); }
.result:hover, .result:focus-visible { background: var(--accent-wash); color: inherit; outline-offset: -2px; }
.result:hover > svg, .result:focus-visible > svg { color: var(--accent); }
.result-static { flex-wrap: wrap; border-bottom: 1px solid var(--line); border-radius: 0; }
.result-static:last-child { border-bottom: 0; }
.who-line { flex: 1; min-width: 180px; display: flex; flex-direction: column; }
.who-line .name, .result .name { font-weight: 600; font-size: 17px; color: var(--ink); text-decoration: none; line-height: 1.3; }
.result a.name:hover { color: var(--accent); text-decoration: underline; }
.who-line .meta { color: var(--muted); font-size: 15px; }

main { flex: 1; width: 100%; max-width: 1360px; padding: 24px var(--gutter) 96px; }

.back {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: var(--tap); margin: -12px 0 4px -6px; padding: 0 8px 0 2px; border-radius: 6px;
  color: var(--muted); font-weight: 500; font-size: 15px; text-decoration: none;
}
.back svg { width: 18px; height: 18px; }
.back:hover { color: var(--ink); background: var(--surface-3); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
/* Centre a 48px action on the 32px title line. */
.page-head > .btn, .page-head > .btn-row { margin-top: -8px; }
.page-head .page-sub { margin: 0; }

.help {
  margin: 0 var(--gutter) 32px; max-width: calc(1360px - 2 * var(--gutter));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.help:not([open]) { display: none; }
.help > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 0 18px; font-weight: 600; color: var(--ink-2);
}
.help > summary::-webkit-details-marker { display: none; }
.help > summary svg { width: 20px; height: 20px; color: var(--muted); }
.help > summary:hover { color: var(--ink); }
.help-body {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 32px;
  padding: 16px 18px 18px; border-top: 1px solid var(--line);
}
.help-body ul { margin: 0 0 12px; padding-left: 20px; }
.help-body li + li { margin-top: 4px; }
.help-foot { grid-column: 1 / -1; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  max-width: min(640px, calc(100% - 32px)); padding: 14px 20px 14px 16px;
  background: var(--ink); color: #fff; border-radius: 10px; font-weight: 500;
  box-shadow: var(--shadow-pop);
  animation: toast-in 280ms var(--ease) both, toast-out 400ms 5.6s var(--ease) forwards;
}
.toast svg { width: 20px; height: 20px; color: #6ce9a6; }
/* The Esc guard's warning: stays until it is answered or times out, never fades early. */
.toast-warn { animation: toast-in 280ms var(--ease) both; background: var(--warn-ink); }
/* The server could not be reached (DECISIONS #46): above any save toast, until it answers again. */
#net-note { bottom: 88px; }
/* A list that refreshes itself says when it last did, once it cannot. */
.stale-note {
  margin: 0 0 12px; padding: 10px 14px; border: 1px solid var(--warn-line); border-radius: var(--radius);
  background: var(--warn-wash); color: var(--warn-ink); font-weight: 600;
}
/* A live search on its way: htmx marks the box, and the magnifier pulses. */
.appsearch:has(input.htmx-request) > svg { color: var(--accent); animation: searching 700ms var(--ease) infinite alternate; }
input.terminology-search.htmx-request { border-color: var(--accent); }
@keyframes searching { from { opacity: 1; } to { opacity: 0.3; } }

/* ===================================================================== */
/* Panels                                                                */
/* ===================================================================== */

.panel, .card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  margin-bottom: 16px; min-width: 0;
  /* A jump link (e.g. /admin#readiness) must not land under the sticky app bar. */
  scroll-margin-top: calc(var(--appbar) + 16px);
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  min-height: 64px; padding: 8px 20px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; flex: 1; display: flex; align-items: center; gap: 10px; font-size: 17px; }
.panel-head h2 svg { width: 20px; height: 20px; color: var(--muted); }
.panel-count {
  min-width: 28px; padding: 1px 9px; border-radius: 999px; text-align: center;
  background: var(--surface-3); color: var(--ink-2); font-size: 14px; font-weight: 600;
}
.panel-body { padding: 16px 20px; }
.panel-pad { padding: 20px; }
.panel-attention { border-color: var(--warn-line); }
.panel-attention .panel-head { background: var(--warn-wash); border-bottom-color: var(--warn-line); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.panel-attention .panel-head h2, .panel-attention .panel-head svg { color: var(--warn-ink); }

.card { padding: 0 20px 20px; }
.card > h2 {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; margin: 0 -20px 16px; padding: 10px 20px;
  font-size: 17px; border-bottom: 1px solid var(--line);
}
.card > h2 svg { width: 20px; height: 20px; color: var(--muted); }
.card-plain { padding-top: 20px; }
.card-doctor { border-color: var(--restricted); box-shadow: inset 0 3px 0 var(--restricted); }
.card-doctor > h2 { color: var(--restricted); }
.h2-count { margin-left: auto; font-size: 14px; font-weight: 600; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-top { align-items: start; }

.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty-title { color: var(--ink); font-weight: 600; margin-bottom: 4px; }
.empty p:last-child { margin-bottom: 0; }
.card .empty, .panel-body .empty { background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ===================================================================== */
/* Home: the day's line, who is in the centre now, today, the rail       */
/* ===================================================================== */

/* The day's figures, as one quiet line under the date. They support the
 * page; the people in the centre carry it. */
.today-line { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 6px 0 0; color: var(--ink-2); }
.today-line strong { color: var(--ink); font-weight: 650; }
.today-line a { text-underline-offset: 3px; }
.today-line a strong { color: inherit; }

/* In the centre now: the peak of the home screen. */
.board { margin-bottom: 20px; }
.board-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.board-col { min-width: 0; padding-bottom: 6px; }
.board-col + .board-col { border-left: 1px solid var(--line); }
.board-title {
  display: flex; align-items: center; gap: 10px; margin: 0; padding: 16px 20px 6px;
  font-size: 15px; font-weight: 600; color: var(--ink-2);
}
.board-title svg { width: 20px; height: 20px; color: var(--muted); }
.board-empty { margin: 0; padding: 6px 20px 18px; color: var(--muted); }

/* A person in the centre. The tile speaks the chart's blood-group grammar:
 * one big tabular figure (bed number, or time waiting) over its label. */
.occupants { list-style: none; margin: 0; padding: 0; }
.occupant { display: flex; align-items: center; gap: 16px; padding: 12px 20px; }
.occupant + .occupant { border-top: 1px solid var(--line); }
.occ-tile {
  flex: none; width: 68px; min-height: 64px; display: grid; place-content: center; justify-items: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.occ-n { font-size: 28px; line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.occ-k { font-size: 14px; font-weight: 500; color: var(--muted); }
.occ-who { flex: 1; min-width: 0; display: grid; gap: 2px; }
.occ-name { justify-self: start; font-size: 18px; font-weight: 600; line-height: 1.35; color: var(--ink); text-decoration: none; }
.occ-name:hover { color: var(--accent); text-decoration: underline; }
.occ-meta { font-size: 14px; color: var(--muted); }
.occupant form { margin: 0; }
.occupant > .btn, .occupant form { flex: none; }

/* The doctor's next patient, in the chart header's grammar. */
.next { margin-bottom: 20px; }
.next .panel-head .muted { font-size: 14px; }
.next-body { display: flex; align-items: flex-start; gap: 24px; padding: 20px; }
.next-id { flex: 1; min-width: 0; }
.next-name {
  display: inline-block; margin: 2px 0 8px; font-size: 28px; line-height: 1.25; font-weight: 650;
  letter-spacing: -0.015em; color: var(--ink); text-decoration: none; text-wrap: balance;
}
.next-name:hover { color: var(--accent); text-decoration: underline; }
.next-side { display: flex; flex-direction: column; align-items: stretch; gap: 12px; min-width: 200px; }
.wait-tile {
  display: grid; justify-items: center; padding: 10px 16px 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.wait-k { font-size: 14px; font-weight: 500; color: var(--muted); }
.wait-n { font-size: 32px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.wait-unit { font-size: 16px; font-weight: 600; letter-spacing: 0; color: var(--ink-2); }
.empty-lg { padding: 48px 20px; }

/* The same figures row, inside a card (old registers, admin). */
.summary-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.summary-strip .stat { padding: 12px 18px; border-left: 1px solid var(--line); }
.summary-strip .stat:first-child { padding-left: 0; }
.summary-strip .stat:first-child { border-left: 0; }
.summary-strip .n { font-size: 26px; line-height: 1.2; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.summary-strip .k { font-size: 14px; color: var(--muted); margin-top: 2px; }

.dash { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.rail { display: grid; gap: 0; }
.rail-line { margin: 12px 0 14px; color: var(--ink-2); }
.rail-link {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 16px 0 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  color: var(--ink); font-weight: 600; text-decoration: none;
}
.rail-link svg { width: 20px; height: 20px; color: var(--muted); }
.rail-link svg:last-child { margin-left: auto; }
.rail-link:hover { background: var(--surface-2); color: var(--ink); }

.status { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); }
.status-live { color: var(--ink); font-weight: 600; }
.status-live::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-2); }

.progress { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ===================================================================== */
/* Chips and status                                                      */
/* ===================================================================== */

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 26px;
  padding: 1px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-3); color: var(--ink-2);
  font-size: 14px; font-weight: 500; line-height: 1.4; white-space: nowrap;
}
.chip-strong { background: var(--surface); border-color: var(--line-strong); color: var(--ink); font-weight: 600; }
.chip-danger { background: var(--danger-wash); border-color: var(--danger-line); color: var(--danger-ink); font-weight: 600; }
.chip-warn { background: var(--warn-wash); border-color: var(--warn-line); color: var(--warn-ink); }
.chip-ok { background: var(--ok-wash); border-color: var(--ok-line); color: var(--ok-ink); }
.chip-restricted { background: var(--restricted-wash); border-color: #c7cced; color: var(--restricted); font-weight: 600; }
.chip-note { font-weight: 400; color: inherit; opacity: 0.85; }
.chip-note::before { content: '·'; margin-right: 6px; }
/* Typed with no concept on the clinic list (DECISIONS #50): a dashed edge and the word, never colour alone. */
.chip-typed { border-style: dashed; white-space: normal; text-align: left; }

/* Colour by meaning (DECISIONS #53). Four brand hues, teal first, validated
 * with the dataviz script as a set (every pair apart for normal vision and
 * every simulated colour blindness, all at least 3:1 on white) and apart from
 * the status colours. An outcome keeps one hue everywhere, and so does a kind
 * of patient: a dot for an outcome, a rounded square for a kind of patient,
 * always beside its words. Wine, nearest the warnings, goes to the rarest of
 * each set: Referred out, Visitors. Text never wears these colours. */
:root { --cat-1: #00929c; --cat-2: #7a5cd6; --cat-3: #b08900; --cat-4: #8a3b5c; }
.cat-1 { --cat-color: var(--cat-1); }
.cat-2 { --cat-color: var(--cat-2); }
.cat-3 { --cat-color: var(--cat-3); }
.cat-4 { --cat-color: var(--cat-4); }
.cat::before {
  content: ''; display: inline-block; flex: none; width: 10px; height: 10px; margin-right: 8px;
  border-radius: 50%; background: var(--cat-color); vertical-align: 0.02em;
}
.cat-kind::before { border-radius: 3px; }
.chip.cat::before, .status.cat::before { margin-right: 0; }
.option.cat::before { margin-right: 10px; }
.chip-tag { font-size: 14px; font-weight: 400; color: var(--ink-2); white-space: nowrap; }
.chip-tag::before { content: '·'; margin-right: 6px; }
.typed-box { margin-top: 16px; }

/* ===================================================================== */
/* Buttons                                                               */
/* ===================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: 600 16px/1.2 var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease), transform 100ms var(--ease);
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: var(--surface-2); border-color: #aeb7c2; color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--accent); padding: 0 10px; }
.btn-ghost:hover { background: var(--accent-wash); border-color: transparent; color: var(--accent-ink); }
.btn-lg { min-height: 52px; padding: 0 24px; font-size: 17px; }
.btn-block { width: 100%; }
.btn-sm { padding: 0 14px; font-size: 15px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row form { margin: 0; }
.save-row { margin: 8px 0 16px; }

.savebar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  margin: 8px calc(-1 * var(--gutter)) 0; padding: 12px var(--gutter);
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow-bar);
}
.savebar-note { margin-right: auto; color: var(--muted); font-size: 15px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin: 8px 0 0; }
.inline-form input[type='text'], .inline-form input[type='search'] { width: auto; flex: 1; min-width: 160px; }
.inline-form .field { margin: 0; }

/* ===================================================================== */
/* Tap options                                                           */
/* Spec 7.4: positions are fixed forever so muscle memory forms. Never   */
/* reordered by frequency at runtime.                                    */
/* ===================================================================== */

.optiongrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); gap: 8px; }
.optiongrid:empty { display: none; }
.optiongrid:not(:empty) + .field { margin-top: 16px; }
.optiongrid-3 { grid-template-columns: repeat(3, 1fr); }
.optiongrid-blood { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }

.option {
  position: relative;
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 56px; padding: 8px 28px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 16px; font-weight: 500; line-height: 1.3; color: var(--ink);
  cursor: pointer; user-select: none;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}
.option:hover { border-color: var(--accent); background: var(--surface-2); }
.option:active { transform: translateY(1px); }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option:has(input:checked) {
  background: var(--accent-wash); border-color: var(--accent); color: var(--accent-ink); font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--accent);
}
.option:has(input:checked)::after {
  content: ''; position: absolute; top: 8px; right: 8px; width: 16px; height: 16px;
  background: var(--accent); -webkit-mask: var(--check) center / contain no-repeat; mask: var(--check) center / contain no-repeat;
}
.option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.option-inline { display: inline-flex; max-width: 380px; margin-top: 8px; }
.option-row { justify-content: flex-start; text-align: left; gap: 10px; padding-left: 16px; }

.allergy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 16px 10px; }
.allergy-choice { display: grid; gap: 6px; }
.allergy-choice select { min-height: var(--tap); font-size: 16px; }
.visit-picks { display: grid; gap: 8px; }

/* Choosing a role is choosing a job: each option says what that person can do. */
.role-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.role-grid-1 { grid-template-columns: 1fr; }
.role-option { min-height: 64px; padding: 10px 40px 10px 16px; align-items: center; }
.role-option .grow { display: grid; gap: 2px; }
.role-summary { font-size: 15px; font-weight: 400; }
.option:has(input:checked) .role-summary { color: var(--accent-ink); }

/* ===================================================================== */
/* Fields                                                                */
/* ===================================================================== */

.field { display: block; margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
.field .label, fieldset .label, .label {
  display: block; margin-bottom: 6px; padding: 0;
  font-weight: 600; font-size: 15px; color: var(--ink-2);
}
.field .note { display: block; color: var(--muted); font-size: 14px; margin-top: 6px; }
.note-ok { color: var(--ok-ink) !important; font-weight: 600; }
.note-warn { color: var(--warn-ink) !important; font-weight: 600; }

input[type='text'], input[type='number'], input[type='date'], input[type='search'],
input[type='tel'], input[type='password'], input[type='file'], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
input::placeholder, textarea::placeholder { color: #6b7789; }
input:hover, select:hover, textarea:hover { border-color: #aeb7c2; }
input[type='file'] { padding: 10px; background: var(--surface-2); }
input[type='file']::file-selector-button {
  margin-right: 12px; min-height: 32px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--surface); font: 600 15px var(--sans); color: var(--ink); cursor: pointer;
}
select { appearance: none; padding-right: 40px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235d6b7e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 12px center / 18px no-repeat; }
textarea { min-height: 104px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px rgba(11, 110, 118, 0.14);
}
input.amber { border-color: var(--warn); background: var(--warn-wash); box-shadow: 0 0 0 1px var(--warn); }

.vitals-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.vitals-row .field { margin: 0; }
.unit { color: var(--muted); font-weight: 400; }

.more { margin-top: 16px; }
.more > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 10px 0 6px; margin-left: -6px; border-radius: 6px;
  font-weight: 600; color: var(--accent);
}
.more > summary::-webkit-details-marker { display: none; }
.more > summary::before {
  content: ''; width: 8px; height: 8px; margin: 0 4px 0 2px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform 150ms var(--ease);
}
.more[open] > summary::before { transform: rotate(45deg); }
.more > summary:hover { background: var(--accent-wash); }
.more-body { padding-top: 12px; }
.reveal { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line-strong); }
.medicine-line { border: 0; padding: 0; margin: 0 0 8px; min-width: 0; }
.medicine-line .field { margin-bottom: 8px; }

/* ===================================================================== */
/* The chart: the digitised case sheet                                   */
/* ===================================================================== */

.chart-head {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  margin-bottom: 16px; overflow: hidden;
}
.chart-id { display: flex; gap: 20px; align-items: flex-start; padding: 20px 20px 16px; }
.photo-block { display: grid; gap: 6px; justify-items: start; }
.photo-upload > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 6px; margin-left: -6px; border-radius: 6px;
  font-size: 15px; font-weight: 600; color: var(--accent);
}
.photo-upload > summary::-webkit-details-marker { display: none; }
.photo-upload > summary svg { width: 18px; height: 18px; }
.photo-upload > summary:hover { background: var(--accent-wash); }
.photo-upload form { max-width: 280px; margin-top: 6px; }

.identity { flex: 1; min-width: 240px; }
.identity h1 { font-size: 28px; margin: 2px 0 8px; }
.identity-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 0 0 6px; color: var(--ink-2); }

.chart-side { display: flex; flex-direction: column; align-items: stretch; gap: 12px; min-width: 176px; }
.blood {
  display: grid; justify-items: center; padding: 10px 16px 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.blood-label { font-size: 14px; font-weight: 500; color: var(--muted); }
.blood-value { font-size: 32px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }

.allergy {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 20px; font-size: 17px;
  background: var(--danger-wash); color: var(--danger-ink);
  border-top: 1px solid var(--danger-line); border-bottom: 1px solid var(--danger-line);
}
.allergy svg { width: 22px; height: 22px; color: var(--danger); margin-top: 2px; }
.allergy strong { margin-right: 10px; color: var(--danger); }
.allergy-none { background: var(--surface-2); color: var(--muted); border-color: var(--line); font-size: 16px; }
.allergy-none strong { color: var(--ink-2); }
.allergy-standalone { border: 1px solid var(--danger-line); border-radius: var(--radius-lg); margin-bottom: 16px; }

.chart-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 0.7fr)) minmax(0, 2fr); margin: 0; }
.chart-facts > div { padding: 12px 20px 14px; border-left: 1px solid var(--line); }
.chart-facts > div:first-child { border-left: 0; }
.chart-facts dt { font-size: 14px; font-weight: 500; color: var(--muted); }
.chart-facts dd { margin: 2px 0 0; font-size: 18px; font-weight: 600; }
.chart-facts-wide dd { font-size: 16px; font-weight: 400; }

/* Which doctor this patient is with. Only that doctor can open the record. */
.care {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px;
  padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface-2);
}
.care-who { flex: 1 1 260px; min-width: 0; display: grid; gap: 2px; }
.care-label { font-size: 14px; font-weight: 500; color: var(--muted); }
.care-name { font-size: 18px; font-weight: 600; color: var(--ink); }
.care-name-none { font-size: 16px; font-weight: 500; color: var(--ink-2); }
.care-who .muted { font-size: 14px; }
.care form { display: flex; align-items: center; gap: 8px; margin: 0; }
.care select { min-height: 48px; font-size: 16px; max-width: 260px; }

.chart-body { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.chart-rail .panel { position: sticky; top: calc(var(--appbar) + 72px); }

.note-line { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; padding: 0; color: var(--ink-2); }
.note-line svg { width: 20px; height: 20px; color: var(--muted); }

/* The patient strip: name, blood group and allergy stay in view while the history scrolls. */
.chart-strip {
  position: fixed; top: var(--appbar); left: var(--sidebar); right: 0; z-index: 25;
  display: flex; align-items: center; gap: 8px 20px; flex-wrap: wrap;
  min-height: 56px; padding: 6px var(--gutter);
  background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: 0 6px 16px rgba(16, 24, 40, 0.06);
  transform: translateY(-110%); visibility: hidden;
  transition: transform 200ms var(--ease), visibility 0s linear 200ms;
}
.chart-strip.is-visible { transform: translateY(0); visibility: visible; transition: transform 200ms var(--ease); }
.chart-strip-name { font-weight: 650; font-size: 17px; }
.chart-strip-blood { color: var(--muted); }
.chart-strip-blood strong { color: var(--ink); margin-left: 4px; }
.chart-strip-allergy { display: inline-flex; align-items: center; gap: 6px; color: var(--danger); font-weight: 600; }
.chart-strip-allergy svg { width: 18px; height: 18px; }
.chart-strip .btn { margin-left: auto; }

.stack-kv { margin: 0; padding: 4px 20px 16px; }
.stack-kv dt { margin-top: 14px; font-size: 14px; font-weight: 500; color: var(--muted); }
.stack-kv dd { margin: 4px 0 0; }

/* Identity photo. A real photo when this machine holds one, a neutral frame
 * when not -- never coloured initials, which confirm nothing (DECISIONS #18). */
.photo {
  width: 46px; height: 56px; flex: none; display: block; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--line); background: var(--surface-3);
}
.photo-lg { width: 88px; height: 110px; border-radius: var(--radius); }
.photo-empty { display: grid; place-items: center; align-content: center; gap: 2px; }
.photo-empty svg { width: 24px; height: 24px; color: #98a2b3; }
.photo-lg.photo-empty svg { width: 40px; height: 40px; }
.photo-caption { font-size: 14px; color: var(--muted); }

/* ===================================================================== */
/* Banners                                                               */
/* ===================================================================== */

.banner {
  display: flex; gap: 10px; padding: 14px 18px; margin: 0 0 16px;
  border: 1px solid; border-radius: var(--radius-lg); font-size: 16px;
}
.banner strong { display: block; margin-bottom: 2px; }
.banner form { margin: 8px 0 0; }
.banner-danger { background: var(--danger-wash); border-color: var(--danger-line); color: var(--danger-ink); }
.banner-danger strong { color: var(--danger); }
.banner-warn { background: var(--warn-wash); border-color: var(--warn-line); color: var(--warn-ink); }
.banner-info { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.banner-info strong { color: var(--ink); }
.banner-ok { background: var(--ok-wash); border-color: var(--ok-line); color: var(--ok-ink); }

/* ===================================================================== */
/* Visits                                                                */
/* ===================================================================== */

.visits { display: grid; }
.visit { border-bottom: 1px solid var(--line); }
.visit:last-child { border-bottom: 0; }
.visit > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  min-height: 60px; padding: 10px 20px;
  transition: background-color 120ms var(--ease);
}
.visit > summary::-webkit-details-marker { display: none; }
.visit > summary::before {
  content: ''; width: 8px; height: 8px; flex: none; margin: 0 2px 2px 0;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform 150ms var(--ease);
}
.visit[open] > summary::before { transform: rotate(45deg); margin-bottom: 6px; }
.visit > summary:hover { background: var(--surface-2); }
.visit > summary:focus-visible { outline-offset: -2px; border-radius: 0; }
.visit[open] > summary { background: var(--surface-2); }
.visit .when { font-weight: 600; min-width: 190px; font-variant-numeric: tabular-nums; }
.visit-outcome { color: var(--muted); font-size: 15px; }
.visit .body { padding: 16px 20px 20px 42px; background: var(--surface-2); border-top: 1px solid var(--line); }
.visit.voided .when { text-decoration: line-through; color: var(--muted); }
.visit.voided > summary .chip-strong { color: var(--muted); font-weight: 500; }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: 10px 20px; margin: 0; }
.kv dt { color: var(--muted); font-size: 15px; }
.kv dd { margin: 0; }
.kv-tight { grid-template-columns: 140px 1fr; gap: 8px 14px; }
.kv-visit .data { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; max-width: 420px; }

/* ===================================================================== */
/* Tables                                                                */
/* ===================================================================== */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 16px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data thead th {
  padding-top: 10px; padding-bottom: 10px;
  font-size: 14px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
table.data th:first-child, table.data td:first-child { padding-left: 20px; }
table.data th:last-child, table.data td:last-child { padding-right: 20px; }
table.data tbody tr:last-child td, table.data tbody tr:last-child th { border-bottom: 0; }
table.data tbody tr { transition: background-color 120ms var(--ease); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .right { text-align: right; }
table.data tbody th { font-weight: 500; color: var(--ink-2); }
table.data-compact th, table.data-compact td { padding: 8px 12px; font-size: 15px; }
table.data-compact th:first-child, table.data-compact td:first-child { padding-left: 12px; }
.card .table-wrap { margin: 0 -20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.card .table-wrap:last-child { margin-bottom: -20px; border-bottom: 0; }
.nowrap { white-space: nowrap; }
.row-actions { display: flex; align-items: center; gap: 16px; white-space: nowrap; }
.muted-cell { color: var(--muted); white-space: nowrap; }
.cell-sub { color: var(--muted); font-size: 14px; }
.strong-link { font-weight: 600; color: var(--ink); text-decoration: none; }
.strong-link:hover { color: var(--accent); text-decoration: underline; }
tr.row-off td { color: var(--muted); }
.tick { width: 52px; }
.tick input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }

table.bars th { width: 96px; }
table.bars td:last-child { width: 64px; }
.bar { display: block; height: 16px; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }

/* ===================================================================== */
/* Admin, queue, registers                                               */
/* ===================================================================== */

.sticky-bar {
  position: sticky; top: var(--appbar); z-index: 20;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin: 0 calc(-1 * var(--gutter)) 16px; padding: 10px var(--gutter);
  background: var(--canvas); border-bottom: 1px solid var(--line);
}

.jump {
  position: sticky; top: var(--appbar); z-index: 20;
  display: flex; flex-wrap: wrap; gap: 4px;
  margin: 0 calc(-1 * var(--gutter)) 20px; padding: 8px var(--gutter);
  background: var(--canvas); border-bottom: 1px solid var(--line);
}
.jump a {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 14px; border-radius: var(--radius);
  color: var(--ink-2); text-decoration: none; font-size: 15px; font-weight: 500;
}
.jump a:hover { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }

.danger-zone { margin-top: 18px; padding: 16px 18px; border: 1px solid var(--danger-line); border-radius: var(--radius-lg); background: var(--danger-wash); color: var(--danger-ink); }

.checklist { list-style: none; margin: 0; padding: 0; }
.check { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check-mark {
  width: 26px; height: 26px; flex: none; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--line-strong); display: grid; place-items: center; color: #fff;
}
.check-mark svg { width: 16px; height: 16px; }
.check.done .check-mark { background: var(--ok); border-color: var(--ok); }
.check-title { font-weight: 600; }
.check-status { font-size: 15px; margin-top: 4px; color: var(--warn-ink); font-weight: 600; }
.check-status.ok { color: var(--ok-ink); }
.check-kind { display: inline-block; margin-top: 6px; font-size: 14px; color: var(--muted); }

.dupes { display: grid; }
.dupe { display: grid; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.dupe:first-child { padding-top: 0; }
.dupe:last-child { border-bottom: 0; padding-bottom: 0; }
.dupe .chip { justify-self: start; }
.dupe-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.compare > .card { padding-top: 16px; }
.keep-choice { margin-bottom: 16px; font-weight: 600; }
.compare-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.compare-head .name { font-weight: 650; font-size: 20px; color: var(--ink); text-decoration: none; }
.compare-head .name:hover { color: var(--accent); text-decoration: underline; }
.compare-col h3 { margin-top: 16px; }
.compare-visits { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.compare-visits li { padding: 8px 0; border-bottom: 1px solid var(--line); }

.register-image { display: block; max-width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line); }
.fastentry-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 16px; align-items: start; }
.page-pane { position: sticky; top: calc(var(--appbar) + 16px); }

/* ===================================================================== */
/* Sign in and first start                                               */
/* ===================================================================== */

.signin-page { min-height: 100vh; }
.signin { width: min(100% - 32px, 480px); margin: 0 auto; padding: 48px 0 40px; }

.signin-brand { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; color: inherit; text-decoration: none; }
.signin-brand:hover { color: inherit; }
.signin-unit { display: block; font-size: 22px; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; }
.signin-org { display: block; font-size: 15px; color: var(--muted); }

.demo-flag {
  margin: 0 0 16px; padding: 12px 16px; border-radius: var(--radius-lg);
  background: var(--warn-wash); border: 1px solid var(--warn-line); color: var(--warn-ink);
}

.signin-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
}
.signin-card h1 { font-size: 24px; margin-bottom: 4px; }
.signin-foot { margin: 20px 4px 0; color: var(--muted); font-size: 15px; }

/* ===================================================================== */
/* Welcome -- the front door for anyone not signed in                    */
/* ===================================================================== */

.welcome-page, .verify-page { min-height: 100vh; display: flex; flex-direction: column; }
.welcome-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.welcome-bar {
  width: min(100% - 48px, 1200px); margin: 0 auto; min-height: 76px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.welcome-brand { display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; }
.welcome-brand:hover { color: inherit; }
.welcome-unit { display: block; font-size: 18px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
.welcome-org { display: block; font-size: 14px; color: var(--muted); }

.welcome { width: min(100% - 48px, 1200px); margin: 0 auto; flex: 1; padding-top: 24px; }
.welcome-hero {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr); gap: 56px; align-items: center;
  padding: 48px 0 56px;
}
.welcome-copy h1 { font-size: 52px; line-height: 1.08; font-weight: 700; letter-spacing: -0.03em; margin: 0 0 20px; max-width: 12ch; }
.welcome-intro { max-width: 520px; margin: 0 0 32px; font-size: 19px; line-height: 1.55; color: var(--ink-2); }
.welcome-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.welcome-actions .btn svg { transition: transform 160ms var(--ease); }
.welcome-actions .btn:hover svg { transform: translateX(3px); }
.welcome-access { color: var(--muted); font-size: 15px; }

.welcome-crest {
  margin: 0; padding: 36px 28px 28px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
}
.welcome-crest img { display: block; width: 180px; height: auto; margin: 0 auto 20px; }
.welcome-crest figcaption { display: grid; gap: 2px; color: var(--muted); font-size: 15px; padding-top: 18px; border-top: 1px solid var(--line); }
.welcome-crest-name { font-weight: 600; color: var(--ink); font-size: 16px; }

.welcome-privacy { margin: 20px 0 0; color: var(--muted); font-size: 15px; }

.welcome-links {
  margin-bottom: 48px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.welcome-row {
  display: flex; align-items: center; gap: 16px; margin: 0; padding: 18px 22px;
  color: inherit; text-decoration: none; border-bottom: 1px solid var(--line);
}
.welcome-row:last-child { border-bottom: 0; }
.welcome-row > svg { width: 24px; height: 24px; color: var(--muted); }
.welcome-row-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.welcome-row-title { font-weight: 600; font-size: 17px; color: var(--ink); }
a.welcome-row { transition: background-color 150ms var(--ease); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
a.welcome-row:hover { background: var(--surface-2); color: inherit; }
.welcome-row-go { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 600; white-space: nowrap; }
.welcome-row-go svg { width: 18px; height: 18px; transition: transform 160ms var(--ease); }
a.welcome-row:hover .welcome-row-go svg { transform: translateX(3px); }

.welcome-footer {
  width: min(100% - 48px, 1200px); margin: 0 auto; min-height: 64px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 14px;
}

/* The public certificate check. */
.verify { width: min(100% - 32px, 640px); margin: 0 auto; padding: 40px 0 56px; }
.verify-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; margin-bottom: 16px; }
.verify-card .kv { padding: 20px 24px 24px; }
.verdict { display: flex; align-items: center; gap: 16px; padding: 20px 24px; font-size: 16px; border-bottom: 1px solid; }
.verdict strong { display: block; font-size: 20px; letter-spacing: -0.01em; }
.verdict-icon { width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.verdict-icon svg { width: 24px; height: 24px; }
.verdict-ok { background: var(--ok-wash); border-color: var(--ok-line); color: var(--ok-ink); }
.verdict-ok .verdict-icon { background: var(--ok); }
.verdict-bad { background: var(--danger-wash); border-color: var(--danger-line); color: var(--danger-ink); }
.verdict-bad .verdict-icon { background: var(--danger); }
.verdict-warn { background: var(--warn-wash); border-color: var(--warn-line); color: var(--warn-ink); border-bottom: 0; }
.verdict-warn .verdict-icon { background: var(--warn); }

/* ===================================================================== */
/* Motion: state changes only                                            */
/* ===================================================================== */

@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 8px); visibility: hidden; } }

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

/* ===================================================================== */
/* Smaller screens                                                       */
/* The clinic screen is 1366x768; these keep a phone or a narrow window  */
/* usable without sideways scrolling.                                    */
/* ===================================================================== */

@media (max-width: 1200px) {
  .dash, .chart-body { grid-template-columns: minmax(0, 1fr) 300px; }
}

/* ===================================================================== */
/* Prescriptions, the pharmacy and the printed slip (DECISIONS #39)       */
/* ===================================================================== */

.rx { border: 0; padding: 0; margin: 0; min-width: 0; }
.rx-title { display: block; padding: 0; margin: 0 0 4px; font-size: 17px; font-weight: 650; color: var(--ink); }
.rx-title .muted { font-weight: 500; font-size: 15px; }
.rx-line { margin-bottom: 4px; }

.rx-line .field { margin-bottom: 8px; }
.rx-where { margin-top: 16px; }
.rx-record .plain { margin: 6px 0; }
.rx-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }
.rx-bought { margin-left: 8px; vertical-align: 1px; }
.rx-record .btn-row { margin-top: 8px; }
.rx-order { display: grid; gap: 10px; }
.rx-order .option-row { min-height: 64px; align-items: center; }
.rx-how { display: block; font-size: 15px; margin-top: 2px; }

/* The pharmacy's scan box: the counter's search box, on the page itself. */
.scanbox { position: relative; display: flex; gap: 12px; align-items: center; margin: 0 0 20px; max-width: 760px; }
.scanbox > svg { position: absolute; left: 16px; width: 22px; height: 22px; color: var(--muted); pointer-events: none; }
.scanbox input[type='search'] { min-height: 56px; padding-left: 50px; font-size: 17px; }
.scanbox .btn { min-height: 56px; flex: none; }

/* The slip: a plain page that prints on A5 or A4, or saves as a PDF. */
.slip-page { background: var(--canvas, #f3f5f7); margin: 0; padding: 24px 16px 64px; }
.slip-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; max-width: 720px; margin: 0 auto 16px; }
.slip {
  max-width: 720px; margin: 0 auto; padding: 32px 36px;
  background: #fff; color: #101828; border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.slip-head { display: flex; align-items: center; gap: 16px; padding-bottom: 18px; border-bottom: 2px solid #101828; }
.slip-unit { margin: 0; font-size: 20px; font-weight: 700; }
.slip-org { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.slip-number { margin-left: auto; display: grid; justify-items: end; gap: 2px; font-size: 14px; }
.slip-number strong { font-size: 17px; }
.slip-k { text-transform: uppercase; letter-spacing: 0.06em; font-size: 14px; color: var(--muted); font-weight: 600; }
.slip-who { display: grid; grid-template-columns: 140px 1fr; gap: 6px 16px; margin: 20px 0; }
.slip-who dt { color: var(--muted); }
.slip-who dd { margin: 0; font-weight: 600; }
.slip-items { width: 100%; border-collapse: collapse; font-size: 16px; }
.slip-items th { text-align: left; font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 8px 10px 8px 0; border-bottom: 1px solid #101828; }
.slip-items td { padding: 12px 10px 12px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.slip-foot { margin-top: 28px; }
.slip-foot p { margin: 0 0 4px; }

@media print {
  @page { margin: 12mm; }
  .slip-page { background: #fff; padding: 0; }
  .slip-tools, .slip-page .toast { display: none !important; }
  .slip { border: 0; border-radius: 0; padding: 0; max-width: none; }
}

/* ===================================================================== */
/* Reports (DECISIONS #40)                                                */
/* ===================================================================== */

.report-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 20px; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.segmented a {
  display: inline-flex; align-items: center; min-height: 48px; padding: 0 20px;
  color: var(--ink-2); font-weight: 600; text-decoration: none; border-left: 1px solid var(--line-strong);
}
.segmented a:first-child { border-left: 0; }
.segmented a:hover { background: var(--surface-2); color: var(--ink); }
.segmented a[aria-current='page'] { background: var(--accent); color: #fff; }
.report-step { display: flex; align-items: center; gap: 12px; }
.report-step svg { width: 18px; height: 18px; }
.report-step [aria-disabled='true'] { opacity: 0.45; pointer-events: none; }
.report-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; align-items: start; }
.report-panel { margin-bottom: 20px; }
.report-sub { font-size: 15px; font-weight: 600; color: var(--ink-2); margin: 24px 0 10px; }
.report-sub.flush-top { margin-top: 0; }

/* The period is the heading; "So far" says it is still running (DECISIONS #52). */
.report-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.report-sofar {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px;
  background: var(--accent-wash); color: var(--accent); font-size: 14px; font-weight: 650; letter-spacing: 0;
}
.page-sub { max-width: 72ch; }
/* What changed: the page's peak (DECISIONS #53). How many came, in display
 * type with the figures at full weight; the change beside it, marked in the
 * brand teal; the commonest complaint and the biggest mover, quieter, apart. */
.report-lead {
  display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 20px 40px; align-items: end;
  margin: 4px 0 20px; padding: 28px 32px 30px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.lead-main {
  margin: 0; max-width: 18ch; font-size: 52px; line-height: 1.08; letter-spacing: -0.03em;
  font-weight: 400; color: var(--ink-2); text-wrap: balance;
}
.report-lead > .lead-main { max-width: 32ch; font-size: 30px; line-height: 1.25; letter-spacing: -0.02em; }
.lead-n { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.lead-change { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 16px 0 0; font-size: 18px; color: var(--ink-2); }
.lead-change strong { color: var(--ink); font-weight: 650; }
.lead-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px;
  background: var(--accent-wash); color: var(--accent-ink); font-weight: 650; font-variant-numeric: tabular-nums;
}
.lead-pill .tile-arrow { fill: currentColor; }
.lead-more { padding: 4px 0 4px 32px; border-left: 1px solid var(--line); }
.lead-more p { margin: 0; max-width: 46ch; font-size: 17px; line-height: 1.5; color: var(--ink-2); }
.lead-more p + p { margin-top: 12px; }
.report-lead p + p { margin-top: 4px; }
.report-toc { display: flex; flex-wrap: wrap; gap: 0 4px; margin: 0 0 16px; }
.report-toc a { display: inline-flex; align-items: center; min-height: 48px; padding: 0 12px; border-radius: var(--radius); font-weight: 600; }
.report-toc a:first-child { padding-left: 0; }
.report-toc a:hover { background: var(--surface-2); }
.report-section, .report-panel { scroll-margin-top: 16px; }
.report-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 32px; }
.hint { max-width: 80ch; }
.data tr.is-total th, .data tr.is-total td { font-weight: 650; border-top: 1px solid var(--line-strong); }
.num-col { text-align: right; width: 160px; font-variant-numeric: tabular-nums; }

/* Headline figures, each with how it compares to the period before. */
.tiles {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.tile { min-width: 0; padding: 16px 20px; border-left: 1px solid var(--line); }
.tile:first-child { border-left: 0; }
.tile-k { font-size: 14px; font-weight: 500; color: var(--muted); }
.tile-n { font-size: 30px; line-height: 1.25; font-weight: 650; letter-spacing: -0.02em; color: var(--ink); }
.tiles-1 { grid-template-columns: minmax(0, 480px); background: none; border: 0; }
.tiles-1 .tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.tile-d { margin-top: 2px; font-size: 14px; color: var(--ink-2); }

/* Charts (DECISIONS #42, #52). One series, one validated hue; hairline grid;
 * bars capped at 24px with a 4px rounded data end; every figure drawn as it is.
 * Each plot is one keyboard stop, read with the arrow keys. */
.viz { --chart: #00929c; margin: 0; }
.viz-plot { position: relative; height: 200px; margin: 22px 0 0 44px; }
.viz-grid { position: absolute; inset: 0; pointer-events: none; }
.viz-gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.viz-tick { position: absolute; right: calc(100% + 8px); top: -10px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.viz-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.viz-col { position: relative; flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.viz-bar { display: block; width: min(24px, 72%); min-height: 1px; background: var(--chart); border-radius: 4px 4px 0 0; }
.viz-bar.is-partial { background: var(--chart-soft); }
.viz-zero { display: block; width: min(24px, 72%); height: 0; }
.viz-col.is-active .viz-bar { filter: brightness(1.15); }
.viz-col.is-active::after {
  content: ''; position: absolute; inset: 0 -1px; background: var(--ink); opacity: 0.06; border-radius: 4px; pointer-events: none;
}
.viz-slot { display: block; width: min(24px, 72%); height: 0; }
.viz-val { position: absolute; left: 50%; transform: translateX(-50%); font-size: 14px; font-weight: 650; color: var(--ink); white-space: nowrap; }
.viz-x { display: flex; gap: 2px; margin: 6px 0 0 44px; }
.viz-x span { flex: 1 1 0; min-width: 0; text-align: center; font-size: 14px; color: var(--muted); white-space: nowrap; }
.viz-table { margin-top: 8px; }
.viz-table summary { display: inline-flex; align-items: center; min-height: 48px; color: var(--accent); font-weight: 600; cursor: pointer; }
.viz-table table { margin-top: 4px; }
.viz-table th a { display: flex; align-items: center; min-height: 48px; }
.viz-tip {
  position: absolute; z-index: 70; pointer-events: none; display: grid; gap: 2px; max-width: 260px;
  padding: 8px 12px; background: var(--ink); color: #fff; border-radius: 8px; box-shadow: var(--shadow-pop); font-size: 14px;
}
.viz-tip strong { font-size: 15px; }
.viz-tip span { color: #c9d0d8; }

.viz-empty { margin: 0; padding: 18px 20px; background: var(--surface-2); border-radius: var(--radius); color: var(--ink-2); max-width: 80ch; }

.barlist { --chart: #00929c; margin: 0; }
.barlist ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
/* Label, bar, figure, and (given a total) its share, each in a column of its own. */
.barlist-row {
  display: grid; grid-template-columns: minmax(120px, 34%) minmax(0, 1fr) minmax(3ch, auto);
  gap: 12px; align-items: center; min-height: 32px;
}
.barlist.has-share .barlist-row { grid-template-columns: minmax(120px, 34%) minmax(0, 1fr) minmax(3ch, auto) 4.5ch; }
.barlist-label { font-size: 15px; color: var(--ink-2); overflow-wrap: anywhere; }
.barlist-label a { display: flex; align-items: center; min-height: 48px; width: 100%; }
.barlist-track { display: block; min-width: 0; }
.barlist-bar { display: block; height: 14px; background: var(--chart); border-radius: 0 4px 4px 0; }
.barlist-bar.c1 { background: var(--cat-1); }
.barlist-bar.c2 { background: var(--cat-2); }
.barlist-bar.c3 { background: var(--cat-3); }
.barlist-bar.c4 { background: var(--cat-4); }
.barlist-bar.r0 { background: var(--line-strong); }
.barlist-bar.r1 { background: #73c0c7; }
.barlist-bar.r2 { background: #2da6b0; }
.barlist-bar.r3 { background: #048891; }
.barlist-bar.r4 { background: #026970; }
.barlist-bar.r5 { background: #014c52; }
.barlist-value { font-size: 15px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.barlist-more { margin-top: 6px; }
.barlist-more summary { display: inline-flex; align-items: center; min-height: 48px; color: var(--accent); font-weight: 600; cursor: pointer; }

/* Finding a past report: a month's days, a year's months, as large links. */
.daygrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.daygrid-head { text-align: center; font-size: 14px; font-weight: 600; color: var(--muted); }
.daycell {
  display: grid; align-content: center; justify-items: center; min-height: 56px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none;
}
a.daycell:hover { border-color: var(--accent); background: var(--accent-wash); color: var(--ink); }
.daycell-n { font-size: 16px; font-weight: 650; }
.daycell-w { display: none; font-size: 14px; color: var(--muted); }
.daycell-v { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.daycell.is-future, .monthcell.is-future { background: var(--surface-2); color: var(--muted); }
.monthgrid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.monthcell {
  display: grid; gap: 2px; align-content: center; min-height: 64px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none;
}
a.monthcell:hover { border-color: var(--accent); background: var(--accent-wash); color: var(--ink); }
.monthcell-n { font-weight: 650; }
.monthcell-v { font-size: 14px; color: var(--muted); }
.report-find { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; margin-bottom: 20px; }
.report-find .field { margin: 0; min-width: 180px; }
.panel-head .btn-sm { margin-left: 8px; }

/* ---- Reports in more detail (DECISIONS #51, #52) ----
   One hue (#00929c) for the period itself, a lighter step of it (#99d3d9) for
   the point still being counted; the period before as a dashed slate line
   (#525c6b: 3:1 on white, and apart from the teal for every kind of colour
   vision, checked with the dataviz validator); a five-step ramp of the same
   teal for the heatmap, validated as ordinal on white. Text never wears a
   series colour. */
:root { --chart-soft: #99d3d9; --chart-before: #525c6b; }
.tiles-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles-6 .tile:nth-child(3n + 1) { border-left: 0; }
.tiles-6 .tile:nth-child(n + 4) { border-top: 1px solid var(--line); }
.tile-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.tile-row .spark { flex: 0 1 112px; min-width: 64px; margin-bottom: 6px; }
.tile-d { display: flex; align-items: center; gap: 6px; }
.tile-arrow { flex: none; width: 12px; height: 12px; fill: var(--ink-2); }

.viz-line .viz-plot, .viz[data-chart='columns'] .viz-plot { cursor: crosshair; }
.viz-plot:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.viz-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.viz-path, .viz-path-before, .viz-path-partial { fill: none; stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; }
.viz-path { stroke: var(--chart); }
.viz-path-partial { stroke: var(--chart); stroke-dasharray: 3 4; }
.viz-path-before { stroke: var(--chart-before); stroke-width: 1.5px; stroke-dasharray: 6 4; }
.viz-area { fill: var(--chart); opacity: 0.1; }
.viz-dot {
  position: absolute; width: 8px; height: 8px; margin: 0 0 -6px -6px; box-sizing: content-box;
  background: var(--chart); border: 2px solid var(--surface); border-radius: 50%; pointer-events: none;
}
.viz-dot-before { background: var(--chart-before); }
/* The point still being counted: hollow, so a half-counted day never reads as a fall. */
.viz-dot-partial { background: var(--surface); border-color: var(--chart); }
.viz-cross { position: absolute; top: 0; bottom: 0; width: 1px; margin-left: -0.5px; background: var(--muted); pointer-events: none; }
.is-compare-off .viz-path-before, .is-compare-off .viz-dot-before { display: none; }
.viz-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-bottom: 4px; }
.viz-key { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; font-size: 14px; color: var(--ink-2); }
.viz-key-toggle {
  padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  font: inherit; font-size: 14px; color: var(--ink-2); cursor: pointer;
}
.viz-key-toggle:hover { border-color: var(--line-strong); background: var(--surface-2); }
.viz-key-toggle[aria-pressed='false'] { color: var(--muted); text-decoration: line-through; }
.viz-key-toggle[aria-pressed='false'] .viz-keyline { opacity: 0.4; }
.viz-keyline { flex: none; width: 16px; height: 2px; border-radius: 1px; background: var(--chart, #00929c); }
.viz-keyline-before { height: 0; background: none; border-top: 2px dashed var(--chart-before); border-radius: 0; }
.viz-keydot { flex: none; width: 8px; height: 8px; border: 2px solid #00929c; border-radius: 50%; background: var(--surface); }
.viz-tip .viz-tip-title { color: #fff; font-weight: 600; }
.viz-tip-row { display: flex; align-items: center; gap: 8px; }
.viz-tip-row strong { color: #fff; }
.viz-tip-row .viz-keyline:not(.viz-keyline-before) { background: #00929c; }
.viz-tip-row strong { white-space: nowrap; }
/* On the dark tooltip the slate is too dark to see; the dash is drawn in the light grey of its text. */
.viz-tip-row.is-before .viz-keyline { border-top-color: #98a2b3; }

.heat .viz-plot { height: auto; margin: 0; }
.heat-grid { display: grid; grid-template-columns: 40px repeat(var(--cols), minmax(0, 1fr)); gap: 2px; }
.heat-row { display: flex; align-items: center; font-size: 14px; color: var(--muted); }
.heat-col { padding-top: 6px; font-size: 14px; color: var(--muted); text-align: center; white-space: nowrap; }
.heat-col.is-sparse { visibility: hidden; }
.heat-cell {
  display: flex; align-items: center; justify-content: center; min-height: 32px; border-radius: 4px;
  font-size: 14px; font-weight: 650; color: #fff; font-variant-numeric: tabular-nums;
}
.heat-cell.is-active { box-shadow: inset 0 0 0 2px var(--ink), inset 0 0 0 3px var(--surface); }
.heat-cell.s0, .heat-swatch.s0 { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.heat-cell.s0.is-active { box-shadow: inset 0 0 0 2px var(--ink); }
.heat-cell.s1, .heat-swatch.s1 { background: #73c0c7; color: var(--ink); }
.heat-cell.s2, .heat-swatch.s2 { background: #2da6b0; color: var(--ink); }
.heat-cell.s3, .heat-swatch.s3 { background: #048891; }
.heat-cell.s4, .heat-swatch.s4 { background: #026970; }
.heat-cell.s5, .heat-swatch.s5 { background: #014c52; }
.heat-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.heat-swatch { display: inline-block; width: 20px; height: 12px; border-radius: 2px; }
.heat-legend-gap { width: 8px; }

.spark { position: relative; display: block; height: 36px; }
.spark svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.spark-line { fill: none; stroke: #00929c; stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: #00929c; opacity: 0.1; }
.spark-dot {
  position: absolute; width: 8px; height: 8px; margin: 0 0 -6px -6px; box-sizing: content-box;
  background: #00929c; border: 2px solid var(--surface); border-radius: 50%; pointer-events: none;
}

/* Small multiples: one strip of months per complaint, all on one scale, the months written once. */
.multiples { --chart: #00929c; }
.multiple {
  display: grid; grid-template-columns: minmax(120px, 24%) minmax(0, 1fr) minmax(120px, 16%);
  align-items: center; gap: 16px; margin: 0; padding: 6px 0; border-bottom: 1px solid var(--line);
}
.multiple-axis { border-bottom: 0; padding: 0; }
.multiple-axis .viz-x { margin: 0; }
.multiple-name { display: flex; align-items: center; min-height: 48px; font-weight: 600; }
.multiple .viz-plot.multiple-strip { height: 48px; margin: 0; }
.multiple-v { font-size: 14px; color: var(--ink-2); text-align: right; }
.barlist-share { font-size: 14px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: no-preference) {
  .viz-bar { transform-origin: bottom; animation: viz-rise 560ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .barlist-bar { transform-origin: left; animation: viz-grow 560ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .viz-line .viz-svg, .spark svg { animation: viz-reveal 900ms ease-out both; }
  .heat-cell { animation: viz-fade 480ms ease-out both; }
}
@keyframes viz-rise { from { transform: scaleY(0); } }
@keyframes viz-grow { from { transform: scaleX(0); } }
@keyframes viz-reveal { from { clip-path: inset(0 100% 0 0); } }
@keyframes viz-fade { from { opacity: 0; } }

@media (max-width: 1040px) {
  .dash, .chart-body { grid-template-columns: minmax(0, 1fr); }
  .board-cols { grid-template-columns: minmax(0, 1fr); }
  .report-cols { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile:nth-child(3) { border-left: 0; }
  .tile:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .tiles-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles-6 .tile:nth-child(3n + 1) { border-left: 1px solid var(--line); }
  .tiles-6 .tile:nth-child(odd) { border-left: 0; }
  .tiles-1 { grid-template-columns: minmax(0, 1fr); }
  .tiles-1 .tile { border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
  .report-pair { grid-template-columns: minmax(0, 1fr); }
  .report-lead { grid-template-columns: minmax(0, 1fr); align-items: start; }
  .lead-more { padding: 16px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .monthgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .board-col + .board-col { border-left: 0; border-top: 1px solid var(--line); }
  .chart-rail .panel { position: static; }
  .chart-facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chart-facts-wide { grid-column: 1 / -1; border-left: 0 !important; border-top: 1px solid var(--line); }
}

@media (max-width: 900px) {
  :root { --gutter: 16px; }
  body.app { display: block; background: var(--canvas); }
  .sidebar {
    position: static; height: auto; overflow: visible; flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 8px 12px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { border-bottom: 0; padding: 4px 0; margin: 0 auto 0 0; }
  /* Every menu item stays in view: the menu wraps rather than scrolling off the edge. */
  .nav { order: 3; width: 100%; display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-item { width: auto; white-space: nowrap; }
  .sidebar-foot { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .sidebar-foot > .nav-item kbd, .who-role { display: none; }
  .role-grid { grid-template-columns: 1fr; }
  /* Who is signed in stays on screen: on a shared computer it is what stops a
     visit being saved under a colleague's name (DECISIONS #46). */
  .who { padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
  .who-text { display: block; padding: 0 4px; }
  .who-switch { padding: 0 12px; margin-top: 0; }
  .appbar { position: static; flex-wrap: wrap; }
  .appsearch { max-width: none; flex-basis: 100%; }
  .grid-2, .grid-3, .help-body, .compare, .dupe-pair, .fastentry-layout { grid-template-columns: 1fr; }
  .page-pane { position: static; }
  .sticky-bar, .jump { position: static; }
  .welcome-hero { grid-template-columns: 1fr; gap: 32px; padding: 32px 0 40px; }
  .welcome-copy h1 { font-size: 40px; }
  .welcome-row { flex-wrap: wrap; }
  .chart-strip { left: 0; top: 0; }
}

@media (max-width: 640px) {
  main { padding-top: 16px; }
  h1 { font-size: 24px; }
  /* Two columns, so a long menu (the in-charge has nine items) stays short. */
  .nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-item { white-space: normal; line-height: 1.25; }
  .next-body { flex-wrap: wrap; gap: 16px; }
  .next-side { flex-direction: row; flex-wrap: wrap; width: 100%; min-width: 0; }
  .next-side > * { flex: 1 1 140px; }
  .occupant { gap: 12px; padding: 12px 16px; flex-wrap: wrap; }
  .occ-tile { width: 60px; min-height: 58px; }
  .scanbox { flex-wrap: wrap; }
  .report-bar .segmented { width: 100%; }
  .tile { padding: 12px 14px; }
  .tile-n { font-size: 24px; }
  .monthgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* Seven columns cannot each be 48px wide on a phone, so the days flow as
     labelled tiles instead of a weekday grid. */
  .daygrid { display: flex; flex-wrap: wrap; gap: 6px; }
  .daygrid-head, .daygrid-pad { display: none; }
  .daycell { flex: 0 0 calc((100% - 18px) / 4); min-height: 64px; }
  .daycell-w { display: block; }
  .viz-plot { height: 160px; margin-left: 36px; }
  .viz-x { margin-left: 36px; }
  .viz-x .is-phone-hidden { visibility: hidden; }
  .heat-grid { grid-template-columns: 32px repeat(var(--cols), minmax(0, 1fr)); }
  .heat-cell { min-height: 28px; font-size: 0; }
  .heat-col.is-sparse, .heat-col { visibility: visible; }
  .heat-col.is-phone-hidden { visibility: hidden; }
  .multiple { grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; }
  .multiple .viz-plot.multiple-strip { grid-column: 1 / -1; grid-row: 2; }
  .multiple-axis { grid-template-columns: minmax(0, 1fr); }
  .multiple-axis > span { display: none; }
  .barlist-row, .barlist.has-share .barlist-row { grid-template-columns: minmax(0, 1fr) minmax(3ch, auto) 4.5ch; gap: 0 12px; }
  .barlist:not(.has-share) .barlist-row { grid-template-columns: minmax(0, 1fr) minmax(3ch, auto); }
  .barlist-label { grid-column: 1 / -1; }
  .report-lead { padding: 20px; }
  .lead-main { font-size: 34px; }
  .lead-change { font-size: 16px; }
  .lead-more p { font-size: 16px; }
  .report-toc a { padding: 0 8px; }
  .report-bar .segmented a { flex: 1; justify-content: center; padding: 0 8px; }
  .report-step { width: 100%; justify-content: space-between; gap: 8px; }
  .num-col { width: auto; }
  .scanbox .btn { width: 100%; }
  .slip { padding: 20px; }
  .slip-head { flex-wrap: wrap; }
  .slip-number { margin-left: 0; justify-items: start; }
  .slip-who { grid-template-columns: 1fr; gap: 0 0; }
  .slip-who dd { margin-bottom: 8px; }
  .chart-id { flex-wrap: wrap; }
  .chart-side { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .chart-side .btn { flex: 1; }
  .chart-facts { grid-template-columns: 1fr 1fr; }
  .chart-facts > div:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .identity h1 { font-size: 24px; }
  .optiongrid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .optiongrid-3 { grid-template-columns: 1fr; }
  .kv, .kv-tight { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 10px; }
  .visit .body { padding-left: 20px; }
  .visit .when { min-width: 0; flex-basis: calc(100% - 30px); }
  .visit > summary .chips { flex-basis: 100%; padding-left: 24px; }
  .chip { white-space: normal; }
  .appsearch-key { display: none; }
  .appsearch input[type='search'] { padding-right: 16px; font-size: 16px; }
  .welcome-bar .btn { display: none; }
  .welcome-copy h1 { font-size: 34px; }
  .welcome-crest img { width: 140px; }
  .signin { padding-top: 28px; }
  .signin-card { padding: 20px; }
  .savebar-note { display: none; }
  .savebar .btn { flex: 1; }
  .chart-strip .btn { display: none; }

  /* Today's list stacks into rows rather than scrolling sideways. */
  .data-today thead { display: none; }
  .data-today tbody tr { display: grid; padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .data-today tbody tr:last-child { border-bottom: 0; }
  .data-today tbody td { border: 0; padding: 1px 0 !important; }
  .data-today tbody td:first-child { font-size: 15px; }
  .data-today tbody td.nowrap { white-space: normal; color: var(--muted); font-size: 15px; }

  /* A table whose columns will not fit any width stacks into label-above-value
   * rows instead of scrolling sideways -- so a long certificate number never
   * pushes Status and Links off screen. Label above value, not beside it,
   * because a value can hold more than one line's worth (the cancel form). */
  .data-stack thead { display: none; }
  .data-stack tbody tr { display: block; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .data-stack tbody tr:last-child { border-bottom: 0; }
  .data-stack tbody td { display: block; border: 0; padding: 8px 0 0 !important; white-space: normal; }
  .data-stack tbody td:first-child { padding-top: 0 !important; }
  .data-stack tbody td::before { display: block; content: attr(data-label); font-size: 14px; font-weight: 500; color: var(--muted); margin-bottom: 2px; }
}

/* Access log (DECISIONS #44): filters in one wrapping row, then the count and the download. */
.log-card { padding-top: 20px; }
.log-filters { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.log-filters .field { margin: 0; flex: 1 1 200px; min-width: 0; }
.log-filters .log-date { flex: 0 1 170px; }
.log-filters .log-what { flex: 1.4 1 280px; }
.log-filters .log-go { flex: 0 0 auto; min-height: var(--tap); }
.log-chosen { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-height: var(--tap); font-weight: 600; }
.log-any { display: inline-flex; align-items: center; min-height: var(--tap); font-weight: 500; font-size: 15px; }
.log-summary { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.log-count { margin: 0; font-size: 17px; }
.log-hint { margin: 8px 0 16px; }
.log-role { display: block; font-size: 14px; }
.log-pager { margin-top: 16px; }
@media (max-width: 640px) {
  .log-filters .field, .log-filters .log-date { flex: 1 1 100%; }
}
