/* The interface typefaces are self-hosted. */
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/jetbrains-mono-latin-400-normal.caf0dfde4e44.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* RxReach clinical-financial identity. */
@font-face {
  font-family: "DM Sans";
  src: url("../fonts/dm-sans-latin-variable.09d1eaa1672d.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("../fonts/plus-jakarta-sans-latin-semibold-bold.13d1b429e990.woff2") format("woff2");
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/jetbrains-mono-latin-700-normal.69002db50656.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;
  /* Clinical-financial identity; see ADR-0006. */
  --brand-cyan: #9FE7F5;
  --brand-blue: #0097B2;
  --brand-navy: #002250;
  --brand-gold: #F9D032;
  --ink: #0f172a;
  --muted: #475569;
  --quiet: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  /* Accent system (ADR-0006, brand blue #0097B2 wins):
     --accent       literal brand blue — borders, focus rings, icons, graphic
                    fills (non-text roles; 3.5:1 on white, fine for non-text)
     --accent-ink   deep brand teal — accent-colored TEXT (≥4.5:1 on white
                    and on --accent-soft)
     --accent-strong  fill for primary buttons (white text ≥4.5:1)
     --accent-hover darker hover fill / link hover (≥6:1 on white) */
  --accent: #0097B2;
  --accent-ink: #0C5F70;
  --accent-strong: #007A93;
  --accent-hover: #005D73;
  --accent-soft: #E1F4F8;
  --accent-contrast: #ffffff;
  --hazard: #dc2626;
  --positive: #16a34a;
  --positive-ink: #166534;
  --positive-soft: #dcfce7;
  --negative: #dc2626;
  --negative-ink: #b91c1c;
  --negative-soft: #fee2e2;
  --warning: #d97706;
  --warning-ink: #92400E;
  --warning-soft: #fef3c7;
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;
  --shadow-panel: none;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  /* Motion: brand moments use the expressive lane; the working interior
     stays fast. --ease-out-soft is the single house curve. */
  --motion-fast: 150ms;
  --motion-base: 300ms;
  --motion-slow: 450ms;
  --ease-out-soft: cubic-bezier(0.2, 0, 0, 1);
  --sidebar-width: 64px;
  --content-max: 1280px;
  /* Lets the details accordions animate to height auto (Chromium 131+);
     no effect in browsers without support. */
  interpolate-size: allow-keywords;
  font-family: "DM Sans", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  font-optical-sizing: auto;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100%; background: var(--bg); }

/* No fixed min-width: the layout is fluid down to the narrowest supported
   viewport, so a vertical scrollbar at exactly 320px cannot clip a strip. */
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-size: 0.9375rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent-ink); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
button { color: inherit; }
svg { display: block; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

::selection { color: var(--bg); background: var(--ink); }

.skip-link {
  position: fixed;
  z-index: 20;
  inset-block-start: 0.75rem;
  inset-inline-start: 0.75rem;
  transform: translateY(-160%);
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--bg);
  background: var(--ink);
  font-weight: 650;
}
.skip-link:focus { transform: translateY(0); color: var(--bg); }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* The shell keeps navigation steady while the work area stays calm and readable. */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  z-index: 5;
  inset-block: 0;
  inset-inline-start: 0;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  padding: 1.35rem 1rem 1rem;
  border-inline-end: 1px solid var(--line);
  background: var(--surface);
}
.brand {
  display: flex;
  min-height: 50px;
  align-items: center;
  gap: 0.7rem;
  padding-inline: 0.4rem;
  color: var(--ink);
  text-decoration: none;
}
.brand:hover { color: var(--ink); }
.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 0;
  /* Definite tracks are required: the logo img sizes itself 100%/100% and
     a percentage height does not resolve against an auto grid row — a
     portrait logo then overflows the box on its intrinsic aspect (the
     347x512 mark rendered 40x59 before this). The inactive theme variant
     is display:none, so a single track never stacks two children. */
  grid-template-columns: 100%;
  grid-template-rows: 100%;
}
.brand-mark .brand-logo { display: block; width: 100%; height: 100%; object-fit: contain; }
/* The logo ships in two inks: the navy original for light surfaces, a cyan
   recolor for dark ones. The auth pages are always dark regardless of the
   stored theme, so they always take the cyan variant. Variant rules are
   scoped inside .brand-mark so they outrank the base img display rule. */
.brand-mark .brand-logo-dark { display: none; }
:root:not([data-theme="light"]) .brand-mark .brand-logo-light,
:root[data-theme="dark"] .brand-mark .brand-logo-light { display: none; }
:root:not([data-theme="light"]) .brand-mark .brand-logo-dark,
:root[data-theme="dark"] .brand-mark .brand-logo-dark { display: block; }
.brand-copy { display: grid; line-height: 1.15; }
.brand-copy strong { color: var(--ink); font-size: 0.97rem; font-weight: 700; letter-spacing: -0.02em; font-family: "Plus Jakarta Sans", "DM Sans", sans-serif; }
.brand-copy span { margin-block-start: 0.25rem; color: var(--quiet); font-size: 0.73rem; }
.primary-nav { display: flex; flex: 1; flex-direction: column; gap: 0.25rem; padding-block-start: 2rem; }
/* Readable group labels in the expanded navigation panel. */
.nav-label {
  display: block;
  margin: 14px 8px 8px;
  border: 0;
  color: var(--quiet);
  background: transparent;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.3;
  text-transform: uppercase;
}
.nav-label-spaced { margin-block-start: 1.55rem; }
.nav-link {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 540;
  text-decoration: none;
  transition: background-color 140ms ease-out, color 140ms ease-out;
}
.nav-link svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}
.nav-link:hover { color: var(--ink); background: var(--surface-soft); }
/* Active destination: a solid carbon block (paper block in dark mode via
   the token remaps). */
.nav-link.is-active { color: var(--accent-ink); background: var(--accent-soft); font-weight: 650; }
.nav-link:focus-visible { outline-offset: 1px; }
/* Unread-count marker on nav links (notifications bell, and the Refills item
   on phones where the bell's nav slot is hidden). Square hazard plate — the
   alarm red is reserved for exactly this kind of real signal. */
.nav-link { position: relative; }
.nav-badge {
  position: absolute;
  top: 4px;
  inset-inline-end: 6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 0;
  background: var(--hazard);
  color: #F4F4F0;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}
/* The bell lives in the rail from 601px up; phones see the mirrored badge
   on the Refills tab instead (the bottom bar keeps its approved 5 slots). */
.nav-badge-refills { display: none; }
/* Staff notifications list */
.notification-list { display: grid; }
.notification-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.9rem 0.25rem;
  border-block-end: 1px solid var(--line);
}
.notification-row:last-child { border-block-end: 0; }
.notification-title { font-weight: 650; }
.notification-when { font-size: 0.75rem; }
.notification-row.is-unread .notification-title::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 0;
  background: var(--hazard);
  margin-inline-end: 0.45rem;
}
.notification-actions { display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; }
.sidebar-footer {
  display: flex;
  min-height: 57px;
  align-items: center;
  gap: 0.65rem;
  margin-block-start: 1rem;
  padding: 0.7rem 0.35rem 0.1rem;
  border-block-start: 1px solid var(--line);
}
.sidebar-footer-mark {
  display: grid;
  width: 31px;
  height: 31px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 0;
  color: var(--bg);
  background: var(--ink);
  font-size: 0.72rem;
  font-weight: 750;
}
.sidebar-footer > span:nth-child(2) { display: grid; line-height: 1.3; }
.sidebar-footer strong { font-size: 0.77rem; font-weight: 650; }
.sidebar-footer small { margin-block-start: 0.16rem; color: var(--muted); font-size: 0.7rem; }
.online-indicator {
  width: 8px;
  height: 8px;
  margin-inline-start: auto;
  border-radius: 50%;
  background: var(--positive);
  box-shadow: 0 0 0 3px var(--positive-soft);
}
.dashboard-sidebar-actions { display: flex; flex-basis: 100%; justify-content: flex-end; gap: .75rem; margin-block-start: .25rem; font-size: .75rem; }
.dashboard-sidebar-actions a { color: var(--muted); text-decoration: none; }
.dashboard-sidebar-actions a:hover { color: var(--accent-ink); text-decoration: underline; }
.dashboard-sidebar-actions form { margin: 0; }
.dashboard-sidebar-actions .signout-button { padding: 0; border: 0; color: var(--muted); background: transparent; font-size: inherit; }
.dashboard-sidebar-actions .signout-button:hover { color: var(--accent-ink); text-decoration: underline; }

.app-main { min-height: 100vh; margin-inline-start: var(--sidebar-width); }
.topbar {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 0.75rem clamp(1.25rem, 3vw, 2.5rem);
  border-block-end: 1px solid var(--line);
  background: var(--surface);
}
.topbar-account { display: flex; align-items: center; gap: 0.65rem; }
.avatar { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border-radius: 50%; color: var(--accent-ink); background: var(--accent-soft); font-size: 0.77rem; font-weight: 700; }
.account-copy { display: grid; line-height: 1.3; }
.account-copy strong { max-width: 14ch; overflow: hidden; font-size: 0.8rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.account-copy small { margin-block-start: 0.16rem; color: var(--muted); font-size: 0.7rem; }
.topbar-account form { margin: 0; }
.signout-button { min-height: 38px; padding: 0.45rem 0.65rem; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; font-size: 0.8rem; }
.signout-button:hover { color: var(--ink); background: var(--surface-soft); }
.account-link { color: var(--muted); font-size: 0.78rem; text-decoration: none; white-space: nowrap; }
.account-link:hover { color: var(--accent-ink); text-decoration: underline; }

.container {
  width: min(100%, var(--content-max));
  margin-inline: auto;
  padding: clamp(1.7rem, 3vw, 2.65rem) clamp(1.25rem, 3vw, 2.5rem) 3rem;
}
/* Macro typography: page titles are heavy; descriptive copy stays DM Sans
   at calm sizes. (Section labels are re-set in Plus Jakarta Sans by the
   canonical ADR-0006 block near the end of this file.) */
.container h1 { margin: 0 0 0.55rem; padding-block-end: 0; border: 0; font-family: "Plus Jakarta Sans", "DM Sans", sans-serif; font-size: clamp(1.5rem, 2vw, 1.75rem); font-weight: 700; letter-spacing: -0.035em; line-height: 1.2; text-transform: none; text-wrap: balance; }
.container h2 { margin: 0 0 0.65rem; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; line-height: 1.35; text-transform: uppercase; }
.container h3 { margin: 1.45rem 0 0.6rem; font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; line-height: 1.4; text-transform: uppercase; }
.container p { max-width: 72ch; }
.container > p:first-of-type { margin-block: 0.3rem 1.4rem; }
.muted { color: var(--muted); font-size: 0.86rem; }
.quiet { color: var(--quiet); }
.container h1 + .muted { margin-block: 0.55rem 1.55rem; }
.container h1 + p:not(.muted) { margin-block: 0.45rem 1.45rem; }

/* Page heading: the title stays a heading; actions sit beside it. Composite
   heading rows carry the thick rule themselves, so their h1 drops its own. */
.page-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-block-end: 1.2rem;
  padding-block-end: 0.9rem;
  border-block-end: 3px solid var(--ink);
}
.page-heading h1 { margin: 0; padding-block-end: 0; border-block-end: 0; }
.page-heading .heading-meta { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.55rem; }
.page-heading .button { flex: 0 0 auto; }
.page-heading-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-inline-start: auto; }

/* Panels hold related records and controls; lists stay open and scannable. */
.card {
  margin-block: 1rem;
  padding: clamp(1rem, 2vw, 1.4rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: none;
}
.card > :last-child { margin-block-end: 0; }
.card > h2:first-child { margin-block-end: 1rem; }
.status-grid { display: grid; grid-template-columns: minmax(150px, 0.38fr) minmax(0, 1fr); gap: 0.6rem 1.25rem; margin: 0; }
.status-grid dt {
  color: var(--quiet);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 400;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.status-grid dd { min-width: 0; margin: 0; font-weight: 560; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* Inset surface for rendered message copy (template previews, message bodies).
   Patient-facing copy keeps its calm measure; only the frame goes industrial. */
.preview-box {
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  font-size: 0.92rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* Buttons and links use the same clear hierarchy across the existing flows. */
.button, button:not(.link-button):not(.signout-button):not(.button-danger):not(.theme-toggle-button):not(.theme-toggle-single):not(.sign-in-button):not(.theme-segment):not(.sidebar-toggle):not(.sidebar-backdrop):not(.password-visibility-button) {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.52rem 0.9rem;
  border: 1px solid var(--accent-strong);
  border-radius: 0;
  color: var(--accent-contrast);
  background: var(--accent-strong);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 640;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  transition: background-color var(--motion-fast) ease-out, border-color var(--motion-fast) ease-out, transform var(--motion-fast) ease-out;
}
.button:hover, button:not(.link-button):not(.signout-button):not(.button-danger):not(.theme-toggle-button):not(.theme-toggle-single):not(.sign-in-button):not(.theme-segment):not(.sidebar-toggle):not(.sidebar-backdrop):not(.password-visibility-button):hover { border-color: var(--accent-hover); color: var(--accent-contrast); background: var(--accent-hover); }
button:not(.link-button):not(.signout-button):not(.theme-toggle-button):not(.theme-toggle-single):not(.sidebar-toggle):not(.sidebar-backdrop):not(.password-visibility-button):active, .button:active { transform: scale(0.96); }
button:disabled, button[disabled] { border-color: var(--line-strong); color: var(--quiet) !important; background: var(--surface-soft) !important; cursor: not-allowed; }
.button-secondary { border-color: var(--line-strong); color: var(--ink); background: var(--surface); }
.button-secondary:hover { border-color: var(--line-strong); color: var(--ink); background: var(--surface-soft); }
.button-danger { border-color: var(--negative); background: var(--negative); }
/* Entry point to a guarded destructive flow: danger is named by the
   outline, the confirmation page does the actual guarding. */
.button-danger-outline { border-color: var(--negative); color: var(--negative-ink); background: var(--surface); }
.button-danger-outline:hover { border-color: var(--negative); color: #fff; background: var(--negative); }
.button-danger:hover { border-color: #821f28; color: #fff; background: #821f28; }
.link-button {
  min-width: 40px;
  min-height: 40px;
  padding: 0.35rem 0.55rem;
  border: 0;
  border-radius: 0;
  color: var(--accent-ink);
  background: transparent;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 630;
  text-decoration: underline;
  text-underline-offset: 0.16em;
}
.link-button:hover { color: var(--accent-hover); background: var(--accent-soft); }
.link-button-danger { color: var(--negative); }
.link-button-danger:hover { color: #821f28; background: var(--negative-soft); }
.inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: 0.65rem; margin: 0.65rem 0; }
.inline-form > p { min-width: min(100%, 13rem); margin: 0; }
.inline-form label { display: block; margin-block-end: 0.3rem; color: var(--muted); font-size: 0.8rem; font-weight: 600; }

/* Inputs keep Django's generated labels and validation text visible. */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select,
textarea {
  min-height: 42px;
  padding: 0.58rem 0.72rem;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  color: var(--ink);
  background: var(--surface);
  font-size: 0.88rem;
  line-height: 1.35;
}
textarea { min-height: 112px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--quiet); opacity: 1; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); vertical-align: middle; }
input[type="file"] { max-width: 100%; min-height: 40px; padding: 0.35rem; border: 1px solid var(--line-strong); border-radius: 0; color: var(--ink); background: var(--surface); }
input[type="file"]::file-selector-button { min-height: 30px; margin-inline-end: 0.65rem; padding: 0.2rem 0.55rem; border: 1px solid var(--line); border-radius: 0; color: var(--ink); background: var(--surface-soft); cursor: pointer; }
input:focus, select:focus, textarea:focus { border-color: var(--line-strong); outline: 2px solid var(--ink); outline-offset: 1px; box-shadow: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { color: var(--muted); font-size: 0.84rem; font-weight: 590; }
form p { margin-block: 0.9rem; }
form p label { display: block; margin-block-end: 0.3rem; }
form p input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
form p select, form p textarea { width: 100%; max-width: 100%; }
form p .helptext, .helptext { display: block; margin-block-start: 0.25rem; color: var(--muted); font-size: 0.78rem; }
.errorlist { margin: 0.3rem 0; padding-inline-start: 1.15rem; color: var(--negative); font-size: 0.82rem; }
.has-error input, input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--negative); }

/* Search and filters remain useful at compact widths. */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.65rem;
  margin-block: 1.1rem 1.3rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.filter-bar .filter-field { display: grid; min-width: 145px; flex: 1 1 145px; gap: 0.3rem; }
.filter-bar .filter-field input, .filter-bar .filter-field select { min-width: 0; min-height: 40px; width: 100%; }
.filter-bar .filter-field-q { flex-basis: 210px; }
.filter-bar button { min-height: 40px; }
.filter-bar .muted { align-self: center; flex: 1 1 220px; }

/* Native tables keep their semantics, with a local scroll boundary on narrow
   screens. Headers are quiet caps over a hairline — clinical, not print-sheet;
   data columns that hold machine output go mono below. On desktop (>=861px)
   the wrapper stops being a scroll container (overflow clip is not one), so
   thead sticks to the page scroll under the app header. */
.messaging-section-nav { display: none; }
.table-wrap { width: 100%; max-width: 100%; margin-block: 0.6rem; overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-color: var(--line-strong) transparent; scrollbar-width: thin; }
table { width: 100%; border-collapse: separate; border-spacing: 0; color: var(--ink); font-size: 0.84rem; line-height: 1.45; }
th, td { padding: 0.78rem 0.8rem; border-block-end: 1px solid var(--line); text-align: start; vertical-align: top; }
th {
  color: var(--muted);
  background: var(--surface);
  border-block-end: 1px solid var(--line-strong);
  font-family: "DM Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
thead th:first-child { border-start-start-radius: 0; }
thead th:last-child { border-start-end-radius: 0; }
tbody tr:last-child td { border-block-end: 0; }
tbody tr:hover { background: var(--surface-soft); }
td a { font-weight: 590; }
td code, code { padding: 0.16rem 0.38rem; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); background: var(--surface-soft); font-family: var(--font-mono); font-size: 0.72rem; overflow-wrap: anywhere; }
td .inline-form { margin: -0.3rem 0; }

/* Desktop tables: sticky header that tracks the page scroll under the app
   header. From 1024px the wrapper stops being a scroll container (overflow
   clip is not one), which is what lets thead stick. A table too wide to fit
   its wrapper is marked .table-wrap-scroll in its template to keep the local
   scrollbar instead of the sticky header. Below 1024px wrappers scroll and
   headers scroll with them. */
@media (min-width: 1024px) {
  .table-wrap { overflow-x: clip; overflow-y: visible; }
  thead th { position: sticky; z-index: 2; top: var(--app-header-height); background: var(--surface); }
  .table-wrap-scroll { overflow-x: auto; overflow-y: hidden; }
  .table-wrap-scroll thead th { position: static; }
}

/* Status uses readable words as well as color; chips carry a semantic border
   and tint with a contrast-safe status ink, never the raw mid-tone. */
.ok, .bad, .warn { display: inline-flex; align-items: center; gap: 0.28rem; font-weight: 640; }
.ok { color: var(--positive-ink); }
.bad { color: var(--negative-ink); }
.warn { color: var(--warning-ink); }
.badge {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--ink);
  background: var(--surface);
  font-family: "DM Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.15;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-ok { border-color: var(--positive); color: var(--positive-ink); background: var(--positive-soft); }
.badge-bad, .badge-inactive { border-color: var(--negative); color: var(--negative-ink); background: var(--negative-soft); }
.badge-due { border-color: var(--warning); color: var(--warning-ink); background: var(--warning-soft); }
.badge-muted { color: var(--muted); background: var(--surface-soft); }
/* Provider-accepted: neither good nor bad — a carbon outline, visibly not
   "delivered" green. */
.badge-sent { border-color: var(--line-strong); color: var(--ink); background: var(--surface-soft); }
/* Unknown-outcome reconciliation path on the message detail page: the one
   boxed alarm on detail sheets. */
.reconcile-panel {
  margin-block-start: 0.9rem;
  padding: 0.9rem 1rem;
  border: 2px solid var(--line-strong);
  border-radius: 8px;
  background: var(--warning-soft);
}
.reconcile-panel h3 { margin-block: 0 0.4rem; }

/* Messages, pagination, cards, and summary rows. */
.messages { display: grid; gap: 0.55rem; margin: 0 0 1rem; padding: 0; list-style: none; }
.messages li { padding: 0.7rem 0.85rem; border: 1px solid var(--positive); border-radius: 6px; color: var(--positive-ink); background: var(--positive-soft); font-size: 0.86rem; }
.messages li.error { border-color: var(--negative); color: var(--negative-ink); background: var(--negative-soft); }
.messages li.warning { border-color: var(--warning); color: var(--warning-ink); background: var(--warning-soft); }
@media (prefers-reduced-motion: no-preference) {
  .messages li { animation: message-in 240ms cubic-bezier(0.2, 0, 0, 1) backwards; }
  .messages li:nth-child(2) { animation-delay: 40ms; }
  .messages li:nth-child(3) { animation-delay: 80ms; }
}
@keyframes message-in {
  from { opacity: 0; transform: translateY(-4px); }
}
.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; margin-block: 1.25rem; color: var(--muted); font-size: 0.82rem; }
.pagination a { display: inline-flex; min-height: 36px; align-items: center; padding: 0.4rem 0.65rem; border: 1px solid var(--line); border-radius: 0; background: var(--surface); font-weight: 600; text-decoration: none; }
.pagination a:hover { border-color: var(--accent); background: var(--accent-soft); }
.container ul, .container ol { padding-inline-start: 1.35rem; }
.container li { margin-block: 0.25rem; }
.app-footer { display: flex; justify-content: space-between; gap: 1rem; padding: 1rem clamp(1.25rem, 3vw, 2.5rem) 1.35rem; border-block-start: 1px solid var(--line); color: var(--muted); font-size: 0.73rem; }

/* A single restrained dashboard layout: current work first, system details below. */
.dashboard-intro { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 1rem; margin-block-end: 1.45rem; }
.dashboard-intro p { margin: 0.4rem 0 0; color: var(--muted); }
.dashboard-actions { display: flex; flex-wrap: wrap; gap: 0.55rem; }
.work-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.85fr); align-items: stretch; gap: 1rem; }
.work-panel { display: flex; min-width: 0; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.work-panel > .work-list, .work-panel > .empty-state { flex: 1 0 auto; }
.work-panel-footer { margin-block-start: auto; }
.work-panel-header { display: flex; min-height: 70px; align-items: center; justify-content: space-between; gap: 0.8rem; padding: 0.85rem 1rem; border-block-end: 1px solid var(--line); }
.work-panel-header h2 { margin: 0; font-size: 0.98rem; }
.work-panel-header p { margin: 0.18rem 0 0; color: var(--muted); font-size: 0.76rem; }
.work-panel-header > a { flex: 0 0 auto; font-size: 0.79rem; font-weight: 620; text-decoration: none; }
.count-chip {
  display: inline-grid;
  min-width: 38px;
  min-height: 38px;
  place-items: center;
  padding-inline: 0.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  color: var(--ink);
  background: var(--surface);
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.work-list { margin: 0; padding: 0; list-style: none; }
.work-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.8rem; padding: 0.82rem 1rem; border-block-end: 1px solid var(--line); }
.work-row:last-child { border-block-end: 0; }
.work-row:hover { background: var(--surface-soft); }
.work-row-main { display: grid; min-width: 0; gap: 0.18rem; }
.work-row-title { overflow: hidden; color: var(--ink); font-size: 0.86rem; font-weight: 640; text-overflow: ellipsis; white-space: nowrap; }
.work-row-title a { color: inherit; text-decoration: none; }
.work-row-title a:hover { color: var(--accent-ink); text-decoration: underline; }
.work-row-meta { display: flex; flex-wrap: wrap; gap: 0.22rem 0.55rem; color: var(--muted); font-size: 0.75rem; }
.work-row-date { color: var(--ink); font-family: var(--font-mono); font-size: 0.72rem; font-variant-numeric: tabular-nums; font-weight: 400; white-space: nowrap; }
.empty-state { padding: 1.4rem 1rem; color: var(--muted); font-size: 0.84rem; }
.empty-state strong { display: block; margin-block-end: 0.22rem; color: var(--ink); font-weight: 650; }
.system-details { margin-block-start: 1rem; }
.system-details .card { margin-block: 0; }
.system-details-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem; margin-block-start: 1rem; }
.home-sends { margin-block-start: 1rem; }

/* Sign-in, recovery, and focused create/edit forms share one quiet surface. */
.auth-layout { display: flex; min-height: 100vh; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-content { width: min(100%, 480px); }
.auth-brand { margin-block-end: 1.15rem; }
.auth-card { width: min(100%, 480px); margin-inline: auto; padding: clamp(1.35rem, 4vw, 2rem); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-panel); }
.auth-card h1 { margin: 0 0 0.65rem; font-size: 1.55rem; letter-spacing: -0.03em; line-height: 1.25; }
.auth-card > p { margin-block: 0.45rem 1rem; color: var(--muted); font-size: 0.88rem; }
.auth-card label { display: block; margin-block-end: 0.3rem; }
.auth-card button, .auth-card .button { width: 100%; margin-block-start: 0.35rem; }
.auth-card form > a { display: inline-flex; align-items: center; min-height: 40px; margin-inline-start: 0.4rem; }
.form-field { display: grid; gap: .3rem; }
.avatar-picker-field { min-width: 0; margin: 0; padding: .75rem; border: 1px solid var(--line); border-radius: 8px; }
.avatar-picker-field legend { padding-inline: .35rem; color: var(--ink); font-size: .85rem; font-weight: 650; }
.avatar-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(82px, 1fr)); gap: .5rem; }
.avatar-option { position: relative; min-width: 0; }
.avatar-option input[type="radio"] { position: absolute; z-index: 1; inset-block-start: .4rem; inset-inline-start: .4rem; width: 16px; height: 16px; margin: 0; accent-color: var(--accent-strong); }
.avatar-option label { display: grid; min-height: 104px; align-content: center; justify-items: center; gap: .2rem; margin: 0; padding: .4rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; text-align: center; }
.avatar-option label img { display: block; width: 72px; height: 72px; object-fit: cover; }
.avatar-option label span { color: var(--muted); font-size: .68rem; line-height: 1.15; }
.avatar-option:has(input:checked) label { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.avatar-option input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }
.avatar-picker-compact { grid-template-columns: repeat(auto-fit, minmax(58px, 1fr)); gap: .35rem; }
.avatar-picker-compact .avatar-option label { min-height: 72px; gap: .1rem; padding: .25rem; }
.avatar-picker-compact .avatar-option label img { width: 44px; height: 44px; }
.avatar-selection-page { display: grid; gap: 1rem; }
.avatar-selection-heading h1 { margin: 0; }
.avatar-selection-heading p { margin: .35rem 0 0; color: var(--muted); }
.avatar-selection-card { padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.avatar-selection-card .avatar-picker { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: .65rem; }
.avatar-selection-card .avatar-option label { min-height: 132px; }
.avatar-selection-card .avatar-option label img { width: 96px; height: 96px; }
.avatar-selection-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .6rem; margin-block-start: 1rem; }
.avatar-selection-actions button { width: auto; min-width: 130px; margin: 0; }
.template-kind-field { min-width: 0; margin: 0 0 .9rem; padding: 0; border: 0; }
.template-kind-field legend { margin-block-end: .4rem; color: var(--muted); font-size: .84rem; font-weight: 590; }
.template-kind-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.template-kind-chip { position: relative; }
.template-kind-chip input[type="radio"] { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.template-kind-chip label { display: inline-flex; min-height: 40px; align-items: center; margin: 0; padding: .45rem .85rem; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: var(--surface); cursor: pointer; font-size: .82rem; font-weight: 600; }
.template-kind-chip input:checked + label { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.template-kind-chip input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }
.patient-form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-block-start: 0.35rem; }
.auth-card .patient-form-actions > button,
.auth-card .patient-form-actions > a.patient-form-cancel {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  min-height: 44px;
  margin: 0;
}
.auth-card .patient-form-actions > button svg { width: 18px; height: 18px; flex: 0 0 auto; }
.auth-card .patient-form-actions > a.patient-form-cancel {
  /* Cancel is a plain dismissal, not a destructive act: secondary treatment,
     never the danger hue. */
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: var(--surface);
}
.auth-card .patient-form-actions > a.patient-form-cancel:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-soft);
}
.auth-card .messages { margin-block-end: 0.8rem; }
.auth-card .helptext, .auth-card .errorlist { font-size: 0.78rem; }
.auth-footer { margin-block-start: 1.2rem; color: var(--quiet); font-size: 0.74rem; text-align: center; }
.auth-content > .messages { width: 100%; }

@media (max-width: 1120px) {
  .work-grid { grid-template-columns: minmax(0, 1fr) minmax(270px, 0.85fr); }
}

@media (max-width: 860px) {
  :root { --sidebar-width: 0px; }
  .sidebar { position: static; width: auto; padding: 0.85rem 1rem 0.65rem; border-inline-end: 0; border-block-end: 1px solid var(--line); }
  .brand { min-height: 42px; }
  .primary-nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.2rem; padding-block-start: 0.8rem; }
  .nav-label { grid-column: 1 / -1; margin-block-start: 0.65rem; }
  .nav-label-spaced { margin-block-start: 0.8rem; }
  .nav-link { min-width: 0; }
  .sidebar-footer { display: none; }
  .app-main { margin-inline-start: 0; }
  .work-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  body { font-size: 0.9rem; }
  .topbar { flex-wrap: wrap; gap: 0.55rem; padding: 0.7rem 1rem; }
  .topbar-account { width: 100%; justify-content: flex-end; order: 1; }
  .account-copy { margin-inline-end: auto; }
  .container { padding: 1.35rem 1rem 2rem; }
  .container h1 { font-size: 1.55rem; }
  .primary-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-link { min-height: 42px; padding-inline: 0.55rem; font-size: 0.82rem; }
  .dashboard-intro { align-items: start; }
  .dashboard-actions { width: 100%; }
  .dashboard-actions .button { flex: 1 1 auto; }
  .work-row { grid-template-columns: minmax(0, 1fr); gap: 0.42rem; }
  .work-row-date { justify-self: start; }
  .filter-bar { align-items: stretch; }
  .filter-bar .filter-field { flex-basis: calc(50% - 0.4rem); }
  .filter-bar button { flex: 1 1 auto; }
  .status-grid { grid-template-columns: minmax(0, 1fr); gap: 0.2rem; }
  .status-grid dt { margin-block-start: 0.6rem; font-size: 0.78rem; }
  .status-grid dt:first-child { margin-block-start: 0; }
  .app-footer { flex-wrap: wrap; padding-inline: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  /* Gentle, not zero: page entrances keep a comprehension-aiding opacity
     fade and lose all movement and delays. */
  main#main-content,
  .dashboard-page .dashboard-kpi,
  .dashboard-page .dashboard-work,
  .dashboard-page .dashboard-overview-grid,
  .dashboard-page .system-details,
  .auth-layout .auth-card,
  .login-brand { animation: entrance-fade 200ms ease !important; }
  .auth-layout::after { animation: entrance-fade 200ms ease !important; }
}
@keyframes entrance-fade {
  from { opacity: 0; }
}

@media (forced-colors: active) {
  :focus-visible { outline: 2px solid Highlight; }
  .nav-link.is-active, .badge, .brand-mark { forced-color-adjust: auto; }
}

/* The dashboard keeps the compact overview from the product design: the shell
   hides the topbar/banner/footer and leads with KPIs; colors are shared tokens. */
.dashboard-shell .sidebar-footer { position: relative; flex-wrap: wrap; padding: 1rem 0 0; }
.dashboard-shell .sidebar-footer > span:nth-child(2) { flex: 1; min-width: 0; }
.dashboard-shell .app-main { margin-inline-start: var(--sidebar-width); }
.dashboard-shell .topbar, .dashboard-shell .app-footer { display: none; }
.dashboard-shell .container { width: 100%; max-width: none; padding: 2rem; }
.dashboard-page { display: grid; gap: 1.25rem; width: 100%; }
.dashboard-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 58px; margin-block-end: 0.25rem; padding-block-end: 0; border: 0; }
.dashboard-heading h1 { margin: 0; padding-block-end: 0; border: 0; color: var(--ink); font-size: 1.5rem; font-weight: 700; letter-spacing: -0.035em; line-height: 1.25; text-transform: none; }
.dashboard-heading p { margin: .2rem 0 0; color: var(--muted); font-size: .86rem; }
.dashboard-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.dashboard-kpi, .dashboard-card { min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.dashboard-kpi { min-height: 122px; padding: 1rem 1.1rem; }
.dashboard-kpi-label { display: flex; align-items: center; justify-content: space-between; gap: .6rem; color: var(--quiet); font-family: var(--font-mono); font-size: .66rem; font-weight: 400; letter-spacing: 0.09em; text-transform: uppercase; }
.dashboard-kpi-label > span { display: grid; width: 32px; height: 32px; place-items: center; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--accent); background: var(--surface); }
.dashboard-kpi-label > span > svg { width: 16px; height: 16px; }
.dashboard-kpi > strong { display: block; margin-block-start: .25rem; color: var(--ink); font-size: 2.4rem; line-height: 1; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.dashboard-kpi > small { display: block; margin-block-start: .45rem; color: var(--quiet); font-family: var(--font-mono); font-size: .6rem; font-weight: 400; letter-spacing: 0.07em; line-height: 1.5; text-transform: uppercase; }
.dashboard-overview-grid { display: grid; grid-template-columns: minmax(0, 1.47fr) minmax(300px, 1fr); align-items: stretch; gap: 1rem; }
.dashboard-card { padding: 1rem 1.25rem; }
.volume-card { min-height: 282px; }
.activity-card { min-height: 240px; }
.dashboard-card-heading { display: flex; align-items: flex-start; justify-content: space-between; }
.dashboard-card-heading h2, .dashboard-section-heading h2 { margin: 0; color: var(--ink); font-family: var(--font-mono); font-size: .78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.dashboard-card-heading p, .dashboard-section-heading p { margin: .18rem 0 0; color: var(--muted); font-size: .75rem; }
/* Section headings use the same sentence-case weight as page titles. */
.dashboard-section-heading h2 { font-family: "Plus Jakarta Sans", "DM Sans", sans-serif; font-size: 1.02rem; font-weight: 700; letter-spacing: -0.01em; }
.volume-chart { display: grid; height: 190px; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .65rem; margin-block-start: 1.1rem; }
.volume-day { display: grid; min-width: 0; grid-template-rows: auto minmax(0, 1fr) auto; justify-items: stretch; text-align: center; }
.volume-value { color: var(--quiet); font-family: var(--font-mono); font-size: .72rem; font-variant-numeric: tabular-nums; line-height: 1.3; }
.volume-track { display: flex; align-items: flex-end; border-block-end: 1px solid var(--line); }
.volume-bar { display: block; width: 100%; min-height: 4px; border-radius: 0; background: var(--ink); }
.volume-label { padding-block-start: .2rem; color: var(--quiet); font-family: var(--font-mono); font-size: .72rem; line-height: 1.3; }
.dashboard-activity-list { display: grid; gap: .8rem; margin: 1rem 0 0; padding: 0; list-style: none; }
.dashboard-activity-list li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: start; gap: .55rem; }
.activity-icon { display: grid; width: 24px; height: 24px; flex: 0 0 auto; place-items: center; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--accent); background: var(--surface); }
.activity-icon svg { width: 12px; height: 12px; }
.activity-copy { min-width: 0; }
.activity-title { overflow: hidden; color: var(--ink); font-size: .8rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.activity-copy p { overflow: hidden; margin: .12rem 0 0; color: var(--muted); font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-activity-list time { padding-block-start: .08rem; color: var(--quiet); font-family: var(--font-mono); font-size: .72rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dashboard-empty { display: grid; min-height: 150px; place-items: center; color: var(--muted); font-size: .8rem; text-align: center; }
.dashboard-work { display: grid; gap: .8rem; }
.dashboard-section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.dashboard-section-heading h2 { font-size: 1.05rem; }
.dashboard-actions { margin: 0; }
.dashboard-shell .work-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dashboard-shell .work-panel { border-radius: 8px; }
.dashboard-shell .count-chip, .dashboard-shell .badge { border-radius: 999px; }

.dashboard-shell .dashboard-section-heading { margin-block-end: .25rem; }
.dashboard-shell .system-details { margin-block-start: 0; }

/* ADR-0004: extend the approved dashboard surface language app-wide. */
.card, .work-panel, .dashboard-card, .dashboard-kpi, .auth-card,
.sidebar-account-menu { border-radius: 8px; }
.button, button:not(.theme-segment):not(.theme-toggle-button):not(.theme-toggle-single):not(.sidebar-toggle),
.account-link, .pagination a, input:not([type="checkbox"]):not([type="radio"]),
select, textarea, input[type="file"], input[type="file"]::file-selector-button {
  /* Controls share the button's 6px so side-by-side inputs and buttons match. */
  border-radius: 6px;
}
.badge, .count-chip, .nav-badge { border-radius: 999px; }

@media (max-width: 1050px) {
  .dashboard-overview-grid { grid-template-columns: minmax(0, 1.15fr) minmax(270px, 1fr); }
}
@media (max-width: 860px) {
  .dashboard-shell .app-main { margin-inline-start: 0; }
  .dashboard-shell .container { padding: 1.35rem 1rem 2rem; }
  .dashboard-overview-grid { grid-template-columns: 1fr; }
  .dashboard-shell .work-grid { grid-template-columns: 1fr; }
  .dashboard-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-heading, .dashboard-section-heading { align-items: flex-start; }
}
/* Tablet band only (601-860): the dashboard uses desktop-like density —
   work panels side-by-side, and volume/activity side-by-side at the
   <=1050 desktop tightening (1.15fr / 270px floor). Below 640px of
   viewport the 7-day chart cannot fit beside a 270px activity card
   (it starves to an unreadable ~200px), so the overview keeps its
   stack there while the work grid stays two-column. KPIs stay 2x2
   (four-across would be too tight); the generic .work-grid keeps its
   <=860 collapse for any non-dashboard use. */
@media (min-width: 601px) and (max-width: 860px) {
  .dashboard-shell .work-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-overview-grid { grid-template-columns: minmax(0, 1.15fr) minmax(270px, 1fr); }
}
@media (min-width: 601px) and (max-width: 639px) {
  .dashboard-overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .dashboard-heading, .dashboard-section-heading { flex-direction: column; }
  .dashboard-heading h1 { font-size: 1.3rem; }
  .dashboard-kpis { gap: .55rem; }
  .dashboard-kpi { min-height: 112px; padding: .8rem; }
  .dashboard-kpi-label { font-size: .62rem; }
  .dashboard-kpi-label > span { width: 26px; height: 26px; }
  .dashboard-kpi > strong { font-size: 1.85rem; }
  .volume-chart { gap: .35rem; }
  .dashboard-actions { width: 100%; }
  .dashboard-actions .button { flex: 1 1 auto; }
}

/* RxReach layouts shared by the desktop, tablet, and mobile design frames. */
:root { --sidebar-width: 64px; }
/* The 64px-rail frame definitions of this layer are superseded by the
   app-header grid + hover rail below; the account popover rules stay. */
.sidebar-account > summary { list-style: none; cursor: pointer; }
.sidebar-account > summary::-webkit-details-marker { display: none; }
.sidebar-account-menu {
  position: absolute;
  z-index: 40;
  /* Float INSIDE the sidebar, just above the account row: the old
     escape-to-the-right placement is clipped by the sidebar's own
     overflow (width-transition + scroll region), which hid the popup
     — and the Sign out button with it — entirely. */
  inset: auto 12px 80px 12px;
  display: grid;
  min-width: 190px;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-panel);
  font-size: 0.82rem;
}
.sidebar-account-menu strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-account-menu small { margin-block-start: -6px; color: var(--muted); }
.sidebar-account-menu a { color: var(--accent-ink); text-decoration: none; }
.sidebar-account-menu form { margin: 0; }
.sidebar-account-menu .signout-button { padding: 0; border: 0; color: var(--negative); background: transparent; font-size: inherit; }
@media (prefers-reduced-motion: no-preference) {
  .sidebar-account[open] .sidebar-account-menu {
    animation: menu-in 160ms cubic-bezier(0.2, 0, 0, 1);
    transform-origin: 0 100%;
  }
}
@keyframes menu-in {
  from { opacity: 0; transform: scale(0.96); }
}
.container { width: 100%; max-width: 1480px; margin-inline: auto; padding: 24px 30px 40px; }
.dashboard-shell .container { padding: 24px 30px 40px; }
.dashboard-shell .sidebar-footer { flex-wrap: nowrap; padding: 0; }
.dashboard-shell .sidebar-footer-mark { margin-inline: auto; }
.dashboard-shell .dashboard-sidebar-actions { display: none; }

/* Dark-theme input ground: the canonical dark remap sits at the end of this
   file; only these input rules live here so form fields keep a recessive
   surface in every dark path. */
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) input,
:root:not([data-theme="light"]) select,
:root:not([data-theme="light"]) textarea { background: var(--bg); }
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea { background: var(--bg); }

@media (min-width: 601px) and (max-width: 860px) {
  .container, .dashboard-shell .container { padding: 22px 20px 36px; }
}

@media (max-width: 600px) {
  /* Wide operational tables scroll inside their own .table-wrap. Keep their
     intrinsic columns from adding a second, page-wide horizontal scrollbar. */
  html { overflow-x: clip; }
  body { font-size: 0.875rem; }
  .messaging-section-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 0.15rem 0.85rem; }
  .messaging-section-nav a { display: inline-flex; min-height: 40px; align-items: center; padding: 0.4rem 0.7rem; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); text-decoration: none; }
  .messaging-section-nav a:hover, .messaging-section-nav a:focus-visible { background: var(--surface-soft); }
  .container, .dashboard-shell .container { padding: 18px 16px 30px; }
  .container h1 { margin-block-end: 0.35rem; font-size: 1.25rem; line-height: 1.25; }
  .container > p:first-of-type { margin-block: 0.25rem 1rem; }
  .dashboard-heading { align-items: flex-start; }
  .dashboard-heading h1 { font-size: 1.25rem; }
  .dashboard-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-kpi { min-height: 104px; padding: 0.8rem; }
  .dashboard-kpi > strong { font-size: 1.35rem; }
  .dashboard-overview-grid { grid-template-columns: 1fr; }
  .filter-bar { gap: 0.55rem; }
  .filter-field, .filter-field-q { flex: 1 1 100%; }
  .table-wrap { margin-inline: 0; border: 0; overflow-x: auto; }
  .table-wrap table { min-width: 620px; }
  .pagination { justify-content: center; flex-wrap: wrap; }
  .auth-layout { min-height: 100svh; padding: 1rem; }
  .auth-brand { display: none; }
}

@media (max-width: 600px) {
  .filter-bar .filter-field, .filter-bar .filter-field-q { flex: 1 1 100%; }
  .filter-bar .filter-field:not(.filter-field-q) { flex-basis: calc(50% - 0.3rem); }
  .filter-bar .filter-field-q { flex-basis: 100%; }
  .filter-bar { padding: 0; border: 0; background: transparent; }
  .advanced-patient-filters { flex: 1 1 100%; }
  .advanced-patient-filters summary { padding: 0.35rem 0; color: var(--accent-ink); cursor: pointer; font-size: 0.82rem; }
  .advanced-patient-filter-fields { display: flex; flex-wrap: wrap; gap: 0.55rem; padding-block: 0.4rem; }
  .page-actions .secondary-action { display: none; }
  .patient-table { display: none; }
  .mobile-patient-list { display: grid; gap: 10px; margin-block-start: 12px; }
  .mobile-patient-card {
    display: grid;
    gap: 10px;
    padding: 14px 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
  }
  .patient-card-heading, .patient-card-footer { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
  .patient-card-heading > div { display: grid; min-width: 0; gap: 2px; }
  .patient-card-heading strong { color: var(--ink); font-size: 0.9rem; }
  .patient-card-meta { color: var(--muted); font-size: 0.75rem; }
  .patient-card-footer { align-items: center; }
  .patient-card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
  .patient-card-tags .badge { min-height: 20px; padding: 0.12rem 0.45rem; border-color: transparent; color: var(--accent-ink); background: var(--accent-soft); }
  .patient-card-footer > a { flex: 0 0 auto; color: var(--accent-ink); font-weight: 650; text-decoration: none; }
  .mobile-pagination-count { display: block; width: 100%; text-align: center; }
  .pagination-count { display: none; }
  .mobile-patient-card .badge { font-size: 0.65rem; }
  .mobile-card-table { min-width: 0 !important; width: 100%; border-collapse: separate; border-spacing: 0; }
  .mobile-card-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .mobile-card-table tbody { display: grid; gap: 10px; }
  .mobile-card-table tbody tr {
    display: grid;
    gap: 7px 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
  }
  .mobile-card-table tbody td {
    display: flex;
    min-width: 0;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 0;
    border: 0;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: end;
  }
  .mobile-card-table tbody td::before {
    flex: 0 0 auto;
    color: var(--quiet);
    content: attr(data-label);
    font-size: 0.72rem;
    text-align: start;
  }
  .mobile-card-table tbody td:first-child { color: var(--ink); font-size: 0.9rem; font-weight: 650; }
  .mobile-card-table tbody td:first-child::before { color: var(--ink); font-size: 0.9rem; font-weight: 650; }
  .mobile-card-table tbody td:last-child { flex-wrap: wrap; }
  .mobile-card-table tbody td[colspan] { display: block; color: var(--muted); text-align: start; }
  .mobile-card-table tbody td[colspan]::before { content: none; }
  .mobile-card-table .inline-form { display: inline-flex; }
  .page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .page-actions > * { margin: 0; }
}

@media (min-width: 601px) {
  .mobile-patient-list, .mobile-pagination-count { display: none; }
}

/* The "More filters" accordion expands smoothly where details content can be
   animated (Chromium 131+); elsewhere it snaps open as before. */
@media (prefers-reduced-motion: no-preference) {
  .advanced-patient-filters::details-content {
    block-size: 0;
    opacity: 0;
    overflow-y: clip;
    transition:
      block-size 200ms cubic-bezier(0.2, 0, 0, 1),
      content-visibility 200ms allow-discrete,
      opacity 200ms ease-out;
  }
  .advanced-patient-filters[open]::details-content { block-size: auto; opacity: 1; }
  @starting-style {
    .advanced-patient-filters[open]::details-content { opacity: 0; }
  }
}

.auth-layout {
  position: relative;
  isolation: isolate;
  color: #EDECE6;
  background: #0F0F0E url("../img/rxreach-login-background.04307f914ab0.jpeg") center 43% / cover no-repeat;
}
.auth-layout::before { position: absolute; z-index: -1; inset: 0; background: rgb(10 10 9 / 82%); content: ""; }
.auth-layout > * { position: relative; z-index: 1; }
.auth-brand { display: none; }
.auth-content { width: min(100%, 430px); }
/* Auth pages (sign-in, recovery) stay visually dark in every theme: fixed
   charcoal literals, square card, sharp rules — the tactical face of the
   same theme. Every rule below is scoped under .auth-layout: the .auth-card
   class is shared with in-app form sheets (template/campaign/patient/staff
   forms, confirm pages), which follow the active theme's tokens instead. */
.auth-layout .auth-card {
  width: 100%;
  padding: clamp(1.35rem, 4vw, 2rem);
  border-color: #3E3C35;
  border-radius: 0;
  color: #EDECE6;
  background: rgb(15 15 14 / 94%);
  box-shadow: none;
}
/* The old single-card entrance moved to the split-login section's staged
   brand moment (end of file). */
.login-brand { display: grid; justify-items: center; gap: 8px; margin-block-end: 24px; text-align: center; }
.login-brand .brand-mark { width: 48px; height: 48px; margin-block-end: 7px; border-radius: 13px; }
.login-brand h1 { margin: 0; color: #EDECE6; font-size: 1.5rem; letter-spacing: -0.025em; font-weight: 700; font-family: "Plus Jakarta Sans", "DM Sans", sans-serif; }
/* Auth pages are visually dark in every theme: always the light-stroke logo. */
.auth-layout .brand-mark .brand-logo-light { display: none; }
.auth-layout .brand-mark .brand-logo-dark { display: block; }
.login-brand p { margin: 0; color: #B9B7AC; font-size: 0.84rem; }
/* The auth card is dark in every theme, so links and focus rings need the
   light ink — the global accent/ink resolve near-black in light mode and
   would vanish on it (the in-app sheets inherit the themed defaults). */
.auth-layout .auth-card a { color: #B9B7AC; }
.auth-layout .auth-card a:hover { color: #EDECE6; }
.auth-layout :focus-visible { outline-color: #EDECE6; }
.auth-layout input:focus,
.auth-layout select:focus,
.auth-layout textarea:focus { outline-color: #EDECE6; }
.auth-layout .auth-card form { display: grid; gap: 14px; padding-block-start: 22px; border-block-start: 1px solid #3E3C35; }
.auth-layout .auth-card form > p { margin: 0; }
.auth-layout .auth-card label { margin-block-end: 6px; color: #8B897E; font-size: 0.7rem; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; }
.auth-help { display: block; margin-block-start: 0.25rem; color: #B9B7AC; font-size: 0.75rem; line-height: 1.45; }
/* The :not() chain mirrors the base input rule so this override outranks it:
   the base selector carries three :not([type]) clauses, i.e. (0,3,1) — a
   plain `.auth-layout .auth-card input` (0,2,1) would lose and the sign-in
   fields would fall back to the themed paper surface. */
.auth-layout .auth-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.auth-layout .auth-card select,
.auth-layout .auth-card textarea { width: 100%; min-height: 44px; color: #EDECE6; border-color: #3E3C35; background: #0F0F0E; }
.auth-layout .auth-card input::placeholder,
.auth-layout .auth-card textarea::placeholder { color: #8B897E; }
.password-field { position: relative; display: block; }
.password-field input { padding-inline-end: 48px; }
.auth-card .password-field > button.password-visibility-button {
  position: absolute;
  inset: 50% 4px auto auto;
  display: grid;
  width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  transform: translateY(-50%);
  place-items: center;
  border: 0;
  color: var(--quiet);
  background: transparent;
  cursor: pointer;
}
.auth-card .password-field > button.password-visibility-button:active { transform: translateY(-50%) scale(0.96); }
.button svg { width: 18px; height: 18px; flex: 0 0 auto; }
.auth-card .password-field > button.password-visibility-button:hover { border: 0; color: var(--ink); background: transparent; box-shadow: none; }
.auth-layout .auth-card .password-field > button.password-visibility-button { color: #8B897E; }
.auth-layout .auth-card .password-field > button.password-visibility-button:hover { color: #EDECE6; }
.password-visibility-button img { display: block; max-width: none; }
.password-visibility-button .eye-closed { display: none; }
.password-visibility-button[aria-pressed="true"] .eye-open { display: none; }
.password-visibility-button[aria-pressed="true"] .eye-closed { display: block; }
/* Sign-in CTA: the inverted plate — substrate ink on phosphor. */
.auth-layout .auth-card button { min-height: 44px; margin-block-start: 8px; border-color: #EDECE6; color: #141310; background: #EDECE6; }
.auth-layout .auth-card button:hover { border-color: #FFFFFF; color: #141310; background: #FFFFFF; }
.password-label-row { display: flex; align-items: center; justify-content: space-between; }
.auth-layout .password-label-row > a { margin-block-end: 6px; color: #B9B7AC; font-size: 0.75rem; text-decoration: none; }
.auth-layout .auth-footer { position: relative; z-index: 1; color: #8B897E; }
@media (max-width: 600px) {
  .auth-layout { min-height: 100svh; justify-content: center; padding: 1rem 1.5rem; background-position: 43% center; }
  .auth-content { width: 100%; }
  .auth-layout .auth-card { padding: 24px; }
  .auth-layout .auth-footer { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .nav-link { transition: color 140ms ease, background-color 140ms ease, box-shadow 140ms ease; }
}


/* Rail expansion is owned by base.html's JS (pointerenter/focusin toggling
   .is-open on the app-header grid); the pre-JS CSS :hover and tap-to-peek
   bands were removed as dead conflicts. */
@keyframes rail-reveal {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Touch devices at 601px and up (tablets, including landscape) expand the rail
   by tap-to-peek: base.html toggles .rail-peek-open on the first tap on the
   rail's non-interactive surface and clears it on taps outside. These
   declarations deliberately mirror the hover band above — keep the two in
   sync — because touch never fires :hover. Reduced motion collapses the width
   transition via the global reduce block. The media gate keeps the class
   inert on hover-capable pointers and at <=600. */
/* Short viewports: the rail's natural stack is ~796px (9 destinations, brand,
   theme control, account), so anything below ~800px of viewport height was
   silently clipping the last nav icons behind the nav's overflow clip. At
   <=799px the stack tightens to ~711px (gaps and dividers shrink; hit targets
   stay >=44px), which fits a maximized 720px-screen window outright. Below
   ~711px the nav scrolls with a thin scrollbar while the theme control and
   account stay pinned — the nav is the only squeezeable region, so nothing
   critical ever clips without an affordance. */
@media (min-width: 601px) and (max-height: 799px) {
  .sidebar { padding-block-start: 0.75rem; }
  .brand { min-height: 44px; }
  .primary-nav { gap: 2px; padding-block-start: 12px; }
  /* 42px stays comfortably above WCAG 2.5.8; absorbs the tenth nav link. */
  .nav-link { min-height: 42px; }
  .nav-label { margin-block: 5px 4px; }
  .nav-label-spaced { margin-block-start: 9px; }
}

/* Theme changes snap, never smear: applyTheme() sets data-theme while this
   class suppresses every transition for exactly one frame, then a short
   ripple radiates from the toggle as the single expressive beat (one of the
   three brand moments). Reduced motion skips the ripple entirely and keeps
   the hard cut. */
.theme-swap *,
.theme-swap *::before,
.theme-swap *::after { transition: none !important; }

.theme-ripple {
  position: fixed;
  z-index: 9999;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
  border: 2px solid var(--accent);
  background: var(--accent-soft);
  opacity: 0.55;
  animation: theme-ripple-out 320ms var(--ease-out-soft) forwards;
}
@keyframes theme-ripple-out {
  from { transform: translate(-50%, -50%) scale(0); opacity: 0.55; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* Manual theme toggle: a segmented sun/moon control, per the approved sidebar
   design — stacked pill in the collapsed rail, horizontal pill in the expanded
   rail and the mobile bottom bar; the active segment gets a white pill.
   data-theme on <html> overrides the system preference; without it the OS
   setting decides. */
.theme-toggle-button {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 3px;
  width: 33px;
  padding: 4px;
  margin-block-start: 8px;
  border-radius: 0;
  background: var(--surface-soft);
}
.theme-segment {
  display: grid;
  width: 25px;
  height: 25px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: background-color 140ms ease-out, color 140ms ease-out;
}
.theme-segment svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}
.theme-segment:hover { color: var(--ink); }
.theme-segment:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Pressed segment: ink block, substrate icon — token-driven so it inverts
   correctly in dark mode too. */
.theme-segment[aria-pressed="true"] { color: var(--bg); background: var(--ink); }
@media (max-width: 600px) {
  .sidebar { display: flex; flex-direction: row; align-items: stretch; }
  .primary-nav { flex: 1 1 auto; overflow: visible; }
  .theme-toggle-button { flex: 0 0 58px; flex-direction: row; gap: 2px; width: auto; align-self: center; margin: 0; }
  .theme-segment { width: 24px; height: 32px; }
  .theme-segment svg { width: 18px; height: 18px; }
}
/* ============================================================
   INDUSTRIAL THEME — telemetry typography + alarm emphasis
   ============================================================
   Machine output goes monospace (dates, phones, IDs, attempts);
   hazard red marks real operational alarms only. Kept as one
   append section so the theme's emphasis rules stay auditable;
   component restyling above is merged in place. */

.mono {
  font-family: var(--font-mono);
  font-size: 0.78em;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
/* Data columns keyed off the mobile-card-table data-label hooks: dates,
   phones, counts and attempts read as machine output; names and bodies do
   not. */
td[data-label="Due"],
td[data-label="When"],
td[data-label="To"],
td[data-label="Phone"],
td[data-label="Attempts"],
td[data-label="Last sign-in"],
td[data-label="Next refill"],
td[data-label="Last sent"],
td[data-label="Scheduled"],
td[data-label="Created"],
td[data-label="Updated"] {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}
/* The customer table's phone column is the third cell (after the checkbox). */
.patient-table td:nth-child(3) {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}
.mobile-card-table td::before {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
/* Alarm edges: failed/undelivered rows red, unknown rows amber, overdue
   refills red with a red date — queue table rows and dashboard work rows
   alike. The row still carries the word (badge or status text): the edge
   and the ink never stand alone. */
tr.row-alert td:first-child,
tr.is-overdue td:first-child,
.work-row.is-overdue { box-shadow: inset 4px 0 0 var(--hazard); }
tr.row-warn td:first-child { box-shadow: inset 4px 0 0 var(--warning); }
tr.is-overdue td[data-label="Due"],
.work-row.is-overdue .work-row-date { color: var(--negative); font-weight: 700; }
/* Alarm variant of the work-panel count chip (messages needing reconcile). */
.count-chip-alert { border-color: var(--hazard); color: var(--hazard); background: var(--negative-soft); }
/* Oversized queue count plate beside a page title (refills queue). */
.heading-count {
  display: inline-grid;
  min-width: 56px;
  min-height: 56px;
  place-items: center;
  padding-inline: 0.7rem;
  border: 2px solid var(--line-strong);
  color: var(--bg);
  background: var(--ink);
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  border-radius: 8px;
}

/* ADR-0004: complete the surface treatment after component and auth overrides. */
.card, .work-panel, .dashboard-card, .dashboard-kpi, .auth-card,
.filter-bar, .reconcile-panel,
.messages li, .mobile-patient-card, .patient-mobile-card,
.sidebar-account-menu, .auth-layout .auth-card {
  border-radius: 8px;
}
.button, button:not(.theme-segment):not(.theme-toggle-button):not(.theme-toggle-single):not(.sidebar-toggle),
.account-link, .pagination a,
input:not([type="checkbox"]):not([type="radio"]), select, textarea,
input[type="file"], input[type="file"]::file-selector-button {
  border-radius: 6px;
}
.badge, .count-chip, .nav-badge {
  border-radius: 999px;
}
.theme-toggle-button { border-radius: 8px; }
.theme-segment { border-radius: 4px; }

/* Canonical clinical-financial system (ADR-0006). Light is the reference
   theme; dark is the slate sibling. Accent = brand blue #0097B2: the literal
   blue serves non-text roles, --accent-ink/#0C5F70 carries accent text
   (>=4.5:1), --accent-strong fills primary buttons (white text >=4.5:1),
   dark mode inverts to brand cyan with navy text on fills. */
:root {
  --ink: #0f172a;
  --muted: #475569;
  --quiet: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --bg: #f8fafc;
  --surface: #fff;
  --surface-soft: #f1f5f9;
  --accent: #0097B2;
  --accent-ink: #0C5F70;
  --accent-strong: #007A93;
  --accent-hover: #005D73;
  --accent-soft: #E1F4F8;
  --accent-contrast: #fff;
  --hazard: #dc2626;
  --positive: #16a34a;
  --positive-ink: #166534;
  --positive-soft: #dcfce7;
  --negative: #dc2626;
  --negative-ink: #b91c1c;
  --negative-soft: #fee2e2;
  --warning: #d97706;
  --warning-ink: #92400E;
  --warning-soft: #fef3c7;
  --sidebar-width: 64px;
  --content-max: 1280px;
  color-scheme: light;
  font-family: "DM Sans", "Segoe UI", system-ui, sans-serif;
}
:root[data-theme="dark"] {
  --ink: #f1f5f9;
  --muted: #cbd5e1;
  --quiet: #94a3b8;
  --line: #334155;
  --line-strong: #475569;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-soft: #273449;
  --accent: #9FE7F5;
  --accent-ink: #9FE7F5;
  --accent-strong: #9FE7F5;
  --accent-hover: #C7F1F9;
  --accent-soft: #0B3540;
  --accent-contrast: #002250;
  --hazard: #FF2A2A;
  --positive: #4ade80;
  --positive-ink: #4ade80;
  --positive-soft: #123321;
  --negative: #f87171;
  --negative-ink: #f87171;
  --negative-soft: #3b1b22;
  --warning: #fbbf24;
  --warning-ink: #fbbf24;
  --warning-soft: #3b2c10;
  color-scheme: dark;
}
:root:not([data-theme="light"]):not([data-theme="dark"]) { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f1f5f9; --muted: #cbd5e1; --quiet: #94a3b8; --line: #334155; --line-strong: #475569;
    --bg: #0f172a; --surface: #1e293b; --surface-soft: #273449;
    --accent: #9FE7F5; --accent-ink: #9FE7F5; --accent-strong: #9FE7F5; --accent-hover: #C7F1F9;
    --accent-soft: #0B3540; --accent-contrast: #002250; --hazard: #FF2A2A;
    --positive: #4ade80; --positive-ink: #4ade80; --positive-soft: #123321;
    --negative: #f87171; --negative-ink: #f87171; --negative-soft: #3b1b22;
    --warning: #fbbf24; --warning-ink: #fbbf24; --warning-soft: #3b2c10; color-scheme: dark;
  }
}

body, button, input, select, textarea { font-family: "DM Sans", "Segoe UI", system-ui, sans-serif; }
.container h1, .dashboard-heading h1, .login-brand h1 { font-family: "Plus Jakarta Sans", "DM Sans", sans-serif; font-weight: 700; text-transform: none; text-wrap: balance; }
.container h1, .dashboard-heading h1 { border: 0; font-weight: 700; text-transform: none; }
.container h2, .container h3, .dashboard-card-heading h2, .dashboard-section-heading h2 { font-family: "Plus Jakarta Sans", "DM Sans", sans-serif; letter-spacing: -0.01em; text-transform: none; }
.mono, time, .work-row-date, .volume-value, .volume-label, .dashboard-kpi > strong { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.sidebar { width: var(--sidebar-width); background: var(--surface); }
.app-main, .dashboard-shell .app-main { margin-inline-start: var(--sidebar-width); }
.primary-nav { gap: 4px; }
.nav-link { min-height: 40px; border-radius: 6px; color: var(--muted); font-family: "DM Sans", sans-serif; white-space: nowrap; }
.nav-link.is-active { color: var(--accent-ink); background: var(--accent-soft); box-shadow: none; }
.nav-label {
  /* Text label, not the old 1px divider: reset the legacy clipped
     treatment so drawer and panel labels render as readable caps. */
  display: block;
  block-size: auto;
  overflow: visible;
  margin: 14px 8px 10px;
  border: 0;
  background: transparent;
  color: var(--quiet);
  font-family: "DM Sans", sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  line-height: 1.3;
}
.topbar, .dashboard-shell .topbar {
  position: sticky; z-index: 4; inset-block-start: 0; display: flex !important;
  min-height: 60px; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .65rem 1.5rem; border-block-end: 1px solid var(--line);
  background: var(--surface);
}
.topbar-account { margin-inline-start: auto; }
.container, .dashboard-shell .container { width: min(100%, var(--content-max)); max-width: var(--content-max); }
.card, .work-panel, .dashboard-card, .dashboard-kpi, .auth-card { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: none; }
.table-wrap { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
th, td { padding-block: .55rem; border-color: var(--line); }
tbody tr:hover { background: var(--surface-soft); }
.badge, .count-chip, .nav-badge { border-radius: 999px; }
.badge-ok { color: var(--positive-ink); }
.badge-bad, .badge-inactive { color: var(--negative-ink); }
.badge-due { color: var(--warning-ink); }
.badge-sent, .badge-muted { color: var(--muted); }
.button, button:not(.link-button):not(.signout-button):not(.button-danger):not(.theme-toggle-button):not(.theme-toggle-single):not(.sign-in-button):not(.theme-segment):not(.sidebar-toggle):not(.sidebar-backdrop):not(.password-visibility-button) { border-color: var(--accent-strong); border-radius: 6px; color: var(--accent-contrast); background: var(--accent-strong); white-space: nowrap; flex-shrink: 0; }
.auth-layout { color: var(--ink); background: var(--bg); }
.auth-layout::before { display: none; }
.auth-layout > .auth-brand { display: none; }
.auth-layout .auth-card { color: var(--ink); background: var(--surface); }
.auth-layout .login-brand h1, .auth-layout .auth-card label { color: var(--ink); }
.auth-layout .login-brand p, .auth-layout .auth-card a, .auth-layout .auth-footer { color: var(--muted); }
.auth-layout .auth-card form { border-color: var(--line); }
.auth-layout .auth-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .auth-layout .auth-card select, .auth-layout .auth-card textarea { color: var(--ink); border-color: var(--line); background: var(--surface); }
.auth-layout .auth-card button { border-color: var(--accent-strong); color: #fff; background: var(--accent-strong); }
.auth-layout .brand-mark .brand-logo-light { display: block; }
.auth-layout .brand-mark .brand-logo-dark { display: none; }
.app-footer { max-width: var(--content-max); margin-inline: auto; }

@media (min-width: 601px) and (max-width: 860px) {
  :root { --sidebar-width: 64px; }
  .sidebar { width: 64px; }
  .app-main, .dashboard-shell .app-main { margin-inline-start: 64px; }
  .topbar { padding-inline: 1.1rem; }
}
@media (max-width: 600px) {
  .topbar, .dashboard-shell .topbar { display: flex !important; min-height: 52px; gap: .5rem; padding: .45rem .75rem; }
  .account-copy, .topbar-account .account-link { display: none; }
  .topbar-account { width: auto; flex: 0 0 auto; gap: .25rem; }
  .topbar-account form { display: none; }
  .dashboard-shell .app-footer { display: block; }
  .container, .dashboard-shell .container { width: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
  main#main-content { animation: workspace-enter 140ms ease-out both; }
  @keyframes workspace-enter { from { opacity: .7; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
}
@media (prefers-reduced-motion: reduce) { main#main-content { animation: none !important; } }

.selection-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 0.75rem 0 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.selection-bar p { margin: 0; }
.selection-bar ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.selection-bar li {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.select-col { width: 2.25rem; }

/* Shell control buttons (hamburger, theme): the live visual rules from the
   retired drawer layer; placement comes from the app-header grid below. */
/* The toggle IS the brand on narrow screens: the bird logo replaces the old
   panel glyph, and the light/dark variants swap exactly like the rail tile. */
/* Explicit paint: without it the browser's default button chrome (gray plate,
   black border) shows through — every button chain excludes this control. */
.sidebar-toggle {
  display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 6px; color: var(--ink); background: transparent;
}
.sidebar-toggle .brand-logo { display: block; width: 34px; height: 34px; object-fit: contain; }
.sidebar-toggle .brand-logo-dark { display: none; }
:root:not([data-theme="light"]) .sidebar-toggle .brand-logo-light,
:root[data-theme="dark"] .sidebar-toggle .brand-logo-light { display: none; }
:root:not([data-theme="light"]) .sidebar-toggle .brand-logo-dark,
:root[data-theme="dark"] .sidebar-toggle .brand-logo-dark { display: block; }
.sidebar-toggle:hover { background: var(--surface-soft); }
.sidebar-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle-single {
  --theme-toggle-scale: .0546075;
  --theme-toggle-track: #E5E7EB;
  position: relative; display: block; flex: 0 0 48px; width: 48px; height: 25px; padding: 0;
  overflow: hidden; border: 0; border-radius: 999px; background: var(--theme-toggle-track); cursor: pointer;
}
.theme-toggle-single[data-theme-state="dark"] { --theme-toggle-track: #2563EB; }
.theme-toggle-single:hover { background: var(--theme-toggle-track); }
.theme-toggle-single:focus-visible { outline: 3px solid #60A5FA66; outline-offset: 3px; }
.theme-toggle-single:active { transform: none; }
.theme-toggle-art {
  position: absolute; inset-block-start: 50%; inset-inline-start: 0; display: block;
  width: 879px; height: 329px; transform: scale(var(--theme-toggle-scale)) translateY(-50%); transform-origin: top left;
  border-radius: 194px; background: var(--theme-toggle-track);
}
.theme-toggle-sun, .theme-toggle-moon { position: absolute; display: block; }
.theme-toggle-sun { inset: 26.75% 10.02% 26.48% 72.47%; }
.theme-toggle-sun img { position: absolute; top: 50%; left: 50%; display: block; width: calc(11px / var(--theme-toggle-scale)); height: calc(11px / var(--theme-toggle-scale)); transform: translate(-50%, -50%); }
.theme-toggle-moon { inset: 26.75% 73.03% 26.46% 10.01%; }
.theme-toggle-moon img { position: absolute; top: 50%; left: 50%; display: block; width: calc(11px / var(--theme-toggle-scale)); height: calc(11px / var(--theme-toggle-scale)); transform: translate(-50%, -50%); }
.theme-toggle-thumb {
  position: absolute; top: -21.12px; left: -21.62px; display: block;
  width: 371.231px; height: 371.231px;
  transition: transform 250ms cubic-bezier(.34, 1.56, .64, 1);
}
.theme-toggle-thumb img {
  position: absolute; inset: 50% auto auto 50%; display: block; width: 262px; height: 263px;
  margin: -131.5px 0 0 -131px;
  transition: opacity var(--motion-fast) ease-out, transform var(--motion-fast) var(--ease-out-soft), filter var(--motion-fast) ease-out;
}
.theme-toggle-thumb-light { transform: rotate(45deg) scale(1); opacity: 1; filter: blur(0); }
.theme-toggle-thumb-dark { transform: rotate(-135deg) scale(.25); opacity: 0; filter: blur(4px); }
.theme-toggle-single[data-theme-state="dark"] .theme-toggle-thumb { transform: translateX(551px); }
.theme-toggle-single[data-theme-state="dark"] .theme-toggle-thumb-light { transform: rotate(45deg) scale(.25); opacity: 0; filter: blur(4px); }
.theme-toggle-single[data-theme-state="dark"] .theme-toggle-thumb-dark { transform: rotate(-135deg) scale(1); opacity: 1; filter: blur(0); }
/* The page theme changes in a hard cut, while the control keeps its own motion. */
.theme-swap .theme-toggle-single .theme-toggle-thumb,
.theme-swap .theme-toggle-single .theme-toggle-thumb { transition: transform 250ms cubic-bezier(.34, 1.56, .64, 1) !important; }
.theme-swap .theme-toggle-single .theme-toggle-thumb img { transition: opacity var(--motion-fast) ease-out, transform var(--motion-fast) var(--ease-out-soft), filter var(--motion-fast) ease-out !important; }
@media (prefers-reduced-motion: reduce) {
  .theme-toggle-thumb, .theme-toggle-thumb img { transition-duration: 0.01ms !important; }
}
@media (max-width: 520px) {
  .theme-toggle-single { --theme-toggle-scale: .0637088; flex-basis: 56px; width: 56px; height: 29px; }
  .theme-toggle-sun img, .theme-toggle-moon img { width: calc(13px / var(--theme-toggle-scale)); height: calc(13px / var(--theme-toggle-scale)); }
}
@media (hover: hover) and (min-width: 521px) and (prefers-reduced-motion: no-preference) {
  .theme-toggle-single { transition: transform var(--motion-fast) var(--ease-out-soft); }
  .theme-toggle-single:hover { transform: scale(1.05); }
}

/* App header + collapsible sidebar that pushes the desktop workspace. */
:root { --app-header-height: 64px; }
.app-shell {
  display: grid; grid-template-columns: 0 minmax(0, 1fr); grid-template-rows: var(--app-header-height) minmax(0, 1fr);
  min-height: 100vh; transition: grid-template-columns 180ms ease;
}
.app-shell.sidebar-open { grid-template-columns: 256px minmax(0, 1fr); }
.app-header {
  position: sticky; z-index: 70; top: 0; grid-column: 1 / -1; grid-row: 1;
  display: flex; min-width: 0; height: var(--app-header-height); align-items: center; gap: 14px;
  padding: 0 20px; border-block-end: 1px solid var(--line); background: var(--surface);
}
.sidebar-toggle {
  position: static; flex: 0 0 42px; width: 42px; height: 42px;
}
.app-header-brand { display: grid; min-width: 0; gap: 1px; color: var(--ink); line-height: 1.15; text-decoration: none; }
.app-header-brand:hover { color: var(--ink); }
.app-header-brand strong { color: var(--ink); font-family: "Plus Jakarta Sans", "DM Sans", sans-serif; font-size: 1rem; font-weight: 700; letter-spacing: -.02em; }
.app-header-brand span { color: var(--quiet); font-size: .7rem; }
.app-header > .theme-toggle-single { margin-inline-start: auto; }
.sidebar {
  position: relative !important; z-index: 10 !important; grid-column: 1; grid-row: 2;
  width: 0 !important; min-width: 0; min-height: calc(100vh - var(--app-header-height)); height: auto !important;
  padding: 0 !important; overflow: hidden; visibility: hidden; transform: none;
  border: 0 !important; border-inline-end: 1px solid transparent !important; box-shadow: none !important;
  transition: width 180ms ease, padding 180ms ease, visibility 0s linear 180ms;
}
.sidebar.is-open {
  width: 256px !important; padding: 16px !important; overflow-x: hidden; overflow-y: auto; visibility: visible;
  border-inline-end-color: var(--line) !important; transition-delay: 0s;
}
.app-main, .dashboard-shell .app-main { grid-column: 2; grid-row: 2; min-width: 0; min-height: calc(100vh - var(--app-header-height)); margin: 0 !important; }
.app-shell > .sidebar-backdrop { display: none !important; }
.app-main > main#main-content { padding-block-start: 24px; }
.dashboard-shell .container { padding-block-start: 2rem !important; }

@media (max-width: 767px) {
  .app-shell { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--app-header-height) minmax(0, 1fr); }
  .app-shell.sidebar-open { grid-template-columns: minmax(0, 1fr); }
  .app-main, .dashboard-shell .app-main { grid-column: 1; grid-row: 2; width: 100%; margin: 0 !important; }
  .sidebar, .sidebar:hover, .sidebar:focus-within, .sidebar.rail-peek-open {
    position: fixed !important; z-index: 55 !important; inset: var(--app-header-height) auto 0 0 !important;
    width: min(270px, calc(100vw - 48px)) !important; min-height: 0; height: auto !important;
    padding: 16px !important; border: 1px solid var(--line) !important; border-block-start: 0 !important;
    visibility: hidden; transform: translateX(-105%); transition: transform 150ms ease, visibility 0s linear 150ms;
  }
  .sidebar.is-open { visibility: visible; transform: translateX(0); transition: transform 180ms ease, visibility 0s; }
  .app-shell > .sidebar-backdrop:not([hidden]) {
    position: fixed; z-index: 50; inset: var(--app-header-height) 0 0; display: block !important;
    width: 100%; height: auto; padding: 0; border: 0; background: rgb(15 23 42 / 32%);
  }
  .sidebar, .primary-nav { display: flex !important; }
  .brand, .brand-copy, .nav-link > span:not(.nav-badge), .sidebar-footer, .nav-label { display: flex !important; }
  /* The header carries the brand (logo toggle + lockup); the drawer must not
     repeat it below the button that opens it. */
  .sidebar .sidebar-panel .brand { display: none !important; }
  .nav-label { display: block !important; }
  .primary-nav { flex: 1 1 auto; flex-direction: column !important; grid-template-columns: none !important; }
  .nav-link, .nav-link:nth-of-type(n) { min-height: 42px; flex-direction: row; justify-content: flex-start; order: initial; }
  .app-main > main#main-content, .dashboard-shell .container { padding-block-start: 18px !important; }
}
@media (prefers-reduced-motion: reduce) {
  .app-shell, .sidebar, .sidebar.is-open { transition: none !important; }
}

/* Figma-inspired hover-expanding icon rail. */
@media (min-width: 768px) {
  .app-shell { grid-template-columns: 64px minmax(0, 1fr); }
  .app-shell.sidebar-open { grid-template-columns: 235px minmax(0, 1fr); }
  .app-header { grid-column: 2 / -1; }
  /* ADR-0006: the header carries the RxReach name at every width; the rail
     below shows the mark, so the lockup is not doubled. */
  .app-header .sidebar-toggle { display: none !important; }
  .sidebar, .sidebar:hover, .sidebar:focus-within, .sidebar.rail-peek-open {
    position: fixed !important; z-index: 55 !important; inset: 0 auto 0 0 !important; align-self: start;
    display: flex !important; width: 64px !important; min-width: 64px;
    height: 100dvh !important;
    min-height: 100dvh !important;
    flex-direction: row; align-items: stretch; gap: 0;
    padding: 4px !important; overflow-x: hidden; overflow-y: auto; visibility: visible; border: 0 !important;
    border-inline-end: 1px solid var(--line) !important; border-radius: 0;
    /* Flat clinical surface: the hairline edge carries the boundary; no
       floating-card radius or shadow (ADR-0006). */
    background: var(--surface); box-shadow: none;
    transition: width 180ms ease, min-width 180ms ease;
  }
  .sidebar.is-open { width: 235px !important; min-width: 235px; padding: 4px 0 10px !important; box-shadow: none; }
  .sidebar-rail { display: flex; width: 48px; min-width: 48px; flex-direction: column; align-items: center; }
  .sidebar-rail-brand { display: grid; width: 44px; height: 58px; flex: 0 0 58px; place-items: center; }
  .sidebar-rail-brand .brand-logo { display: block; width: 34px; height: 34px; object-fit: contain; }
  .sidebar-rail-brand .brand-logo-dark { display: none; }
  :root:not([data-theme="light"]) .sidebar-rail-brand .brand-logo-light,
  :root[data-theme="dark"] .sidebar-rail-brand .brand-logo-light { display: none; }
  :root:not([data-theme="light"]) .sidebar-rail-brand .brand-logo-dark,
  :root[data-theme="dark"] .sidebar-rail-brand .brand-logo-dark { display: block; }
  .sidebar-rail-nav { display: flex; flex: 1; width: 100%; flex-direction: column; align-items: center; gap: 1px; padding-block-start: 0; }
  .sidebar-rail-nav .nav-link { display: grid; width: 44px; min-height: 34px; flex: 0 0 34px; place-items: center; padding: 0; }
  .sidebar-rail-nav .nav-link > span:not(.nav-badge) { display: none; }
  .sidebar-rail-nav .nav-link svg { width: 19px; height: 19px; }
  .sidebar-rail-nav .nav-label { visibility: hidden; }
  .sidebar-rail-footer { display: grid; width: 36px; height: 36px; flex: 0 0 36px; place-items: center; margin-block-start: auto; overflow: hidden; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: var(--surface-soft); font-size: .72rem; font-weight: 700; text-decoration: none; }
  .sidebar-rail-footer img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .sidebar-rail-footer:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .sidebar-panel { display: none; min-width: 0; width: 0; overflow: hidden; }
  .sidebar.is-open .sidebar-rail { display: none; }
  .sidebar.is-open .sidebar-panel { display: flex; width: 100%; min-width: 0; flex: 1 1 0; flex-direction: column; padding-inline-start: 0; animation: rail-reveal 140ms ease-out; }
  .sidebar.is-open .sidebar-panel .brand,
  .sidebar.is-open .sidebar-panel .brand-copy,
  .sidebar.is-open .sidebar-panel .nav-link > span:not(.nav-badge),
  .sidebar.is-open .sidebar-panel .sidebar-footer,
  .sidebar.is-open .sidebar-panel .nav-label { display: flex; }
  .sidebar.is-open .sidebar-panel .nav-label { display: block; }
  .sidebar.is-open .sidebar-panel .primary-nav { display: flex; flex-direction: column; gap: 1px; padding: 0; }
  .sidebar.is-open .sidebar-panel .nav-link { display: flex; min-height: 34px; justify-content: flex-start; border-radius: 8px; }
  .sidebar.is-open .sidebar-panel .sidebar-footer { display: flex; }
  .app-header .sidebar-toggle { border-color: transparent !important; border-radius: 8px; color: var(--ink) !important; background: transparent !important; box-shadow: none !important; }
  .app-header .sidebar-toggle:hover { color: var(--ink) !important; background: var(--surface-soft) !important; }
  .sidebar-backdrop { display: none !important; }
  .sidebar, .sidebar.is-open { color: var(--ink); }
  .sidebar .nav-link { color: var(--muted); font-size: .875rem; font-weight: 500; }
  .sidebar .nav-link:hover { color: var(--ink); background: var(--surface-soft); }
  .sidebar .nav-link.is-active {
    color: var(--accent-ink); background: var(--accent-soft); font-weight: 600;
    /* Crisp active edge: a 3px brand-blue inset on the item's start side. */
    box-shadow: inset 3px 0 0 var(--accent);
  }
  .sidebar .nav-label { margin-inline: 12px; background: var(--line); }
  /* Freeze the icon column: the collapsed rail and the expanded panel share
     ONE vertical rhythm, so expanding reveals labels around icons that never
     move. The rail clones each section header (base.html JS) as a hidden
     spacer carrying the same box as the panel's visible label, and both
     columns use equal 40px targets with a fixed 8px gap. Icons share one
     20px size and one centerline (sidebar padding 4px + 48px rail / 2 = 28px;
     panel rows pad 18px + 20px icon / 2 = 28px). */
  .sidebar-rail { align-items: center; }
  .sidebar-rail-nav { width: 48px; flex: 1 0 auto; align-items: center; gap: 8px; padding-block-start: 0; }
  .sidebar-rail-nav .nav-link { display: flex; width: 40px; min-height: 40px; flex: 0 0 40px; align-self: center; align-items: center; justify-content: center; margin-inline: auto; padding: 0; }
  .sidebar-rail-nav .nav-link svg { width: 20px; height: 20px; }
  .sidebar.is-open .sidebar-panel .primary-nav { gap: 8px; }
  .sidebar.is-open .sidebar-panel .nav-link { min-height: 40px; gap: 0.7rem; padding-inline: 18px 12px; }
  .sidebar.is-open .sidebar-panel .nav-link svg { width: 20px; height: 20px; }
  .sidebar.is-open .sidebar-panel .nav-label,
  .sidebar-rail-nav .nav-label { block-size: auto; min-height: 1.2em; margin: 4px 0 0; padding-inline-start: 48px; overflow: visible; background: transparent; color: var(--quiet); font-size: 0.64rem; line-height: 1.2; }
  .sidebar .sidebar-panel .brand { width: 100%; min-height: 58px; justify-content: flex-start; gap: 8px; padding: 8px 12px; }
  .sidebar .sidebar-panel .brand-mark { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
  .sidebar.is-open .sidebar-panel .brand-copy { display: grid; }
  .sidebar .sidebar-panel .brand-copy strong { color: var(--ink); font-family: "Plus Jakarta Sans", "DM Sans", sans-serif; font-size: .875rem; font-weight: 600; letter-spacing: 0; }
  .sidebar .sidebar-panel .brand-copy span { display: none; }
  .sidebar.is-open .sidebar-panel .sidebar-footer { display: block; width: 100%; min-height: 0; margin: auto 0 0; padding: 0 8px; border: 0; }
  .sidebar .sidebar-account { width: 100%; flex: 1 1 auto; }
  .sidebar .sidebar-footer-mark { display: flex; width: 100%; min-height: 58px; align-items: center; gap: 8px; padding: 8px 4px; border: 0; border-radius: 8px; color: var(--ink); background: transparent; text-align: start; }
  .sidebar .sidebar-footer-mark:hover { background: var(--surface-soft); }
  .sidebar .sidebar-footer-avatar { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 50%; color: #fff; background: var(--accent-strong); font-weight: 700; }
  .sidebar .sidebar-footer-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .sidebar .sidebar-footer-copy { display: grid; min-width: 0; flex: 1; gap: 1px; line-height: 1.2; }
  .sidebar .sidebar-footer-copy strong { overflow: hidden; font-size: .85rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar .sidebar-footer-copy small { color: var(--muted); font-size: .72rem; }
  .sidebar .sidebar-account-menu { inset: auto 8px 80px 8px; }
}

@media (max-width: 767px) {
  /* One column: the header spans it, main fills it, and the drawer overlays.
     The earlier two-column "0 + 1fr" template parked app-main in the
     zero-width track — the page only worked by overflowing it. */
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .app-shell.sidebar-open { grid-template-columns: minmax(0, 1fr); }
  .app-header { grid-column: 1 / -1; }
  .app-header .sidebar-toggle { display: inline-flex; }
  .sidebar-rail { display: none; }
  .sidebar-panel { display: flex; width: 100%; min-width: 0; flex-direction: column; overflow: visible; }
  .sidebar-panel .brand, .sidebar-panel .brand-copy, .sidebar-panel .nav-link > span:not(.nav-badge),
  .sidebar-panel .sidebar-footer, .sidebar-panel .nav-label { display: flex !important; }
  .sidebar-panel .nav-label { display: block !important; }
  .sidebar-panel .primary-nav { flex: 1 1 auto; flex-direction: column !important; grid-template-columns: none !important; padding-block-start: 2rem; }
  .sidebar-panel .nav-link, .sidebar-panel .nav-link:nth-of-type(n) { min-height: 42px; flex-direction: row; justify-content: flex-start; order: initial; }
  .sidebar-account { width: 100%; }
  /* Paint overrides: the base rule is the old 31px carbon initials plate —
     without these the drawer account row renders as a dark box. */
  .sidebar-footer-mark { display: flex; width: 100%; min-height: 54px; align-items: center; gap: 8px; padding: 6px 4px; border: 0; border-radius: 8px; color: var(--ink); background: transparent; text-align: start; }
  .sidebar-footer-mark:hover { background: var(--surface-soft); }
  .sidebar-footer-avatar { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; overflow: hidden; border-radius: 50%; color: #fff; background: var(--accent-strong); font-weight: 700; }
  .sidebar-footer-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .sidebar-footer-copy { display: grid; min-width: 0; gap: 1px; line-height: 1.2; }
  .sidebar-footer-copy strong { overflow: hidden; font-size: .85rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar-footer-copy small { color: var(--muted); font-size: .72rem; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar.is-open, .sidebar-panel { animation: none !important; transition: none !important; }
}

/* Dashboard workspace: KPI-first hierarchy and paired operational panels. */
.dashboard-shell .container {
  width: min(100%, var(--content-max));
  max-width: var(--content-max);
  margin-inline: auto;
  padding: 28px clamp(20px, 2.5vw, 36px) 40px;
}
.dashboard-page { gap: 1.2rem; }
.dashboard-heading {
  min-height: 0;
  margin: 0;
  padding-block-end: 1rem;
  border-block-end: 1px solid var(--line);
}
.dashboard-heading h1 {
  color: var(--ink);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.2;
}
.dashboard-heading p { margin-block-start: .35rem; font-size: .88rem; }
.dashboard-kpis { gap: .9rem; }
.dashboard-kpi {
  min-height: 122px;
  padding: 1rem 1.1rem;
  border-radius: 8px;
}
.dashboard-kpi-label {
  color: var(--muted);
  font-family: "DM Sans", sans-serif;
  font-size: .78rem;
  font-weight: 550;
  letter-spacing: 0;
  text-transform: none;
}
.dashboard-kpi-label > span {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  color: var(--accent);
  background: var(--accent-soft);
}
.dashboard-kpi > strong { margin-block-start: .45rem; font-size: 2rem; }
.dashboard-kpi > small {
  margin-block-start: .35rem;
  color: var(--quiet);
  font-family: "DM Sans", sans-serif;
  font-size: .72rem;
  letter-spacing: 0;
  text-transform: none;
}
.dashboard-work { gap: .9rem; }
.dashboard-section-heading { align-items: center; }
.dashboard-section-heading h2 {
  font-size: 1.08rem;
  font-weight: 700;
}
.dashboard-section-heading p { font-size: .8rem; }
.dashboard-shell .work-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.dashboard-shell .work-panel { min-height: 330px; border-radius: 8px; }
.work-panel-header { padding: .9rem 1.1rem; }
.work-panel-header h2 { font-size: .98rem; font-weight: 700; }
.work-panel-header p { font-size: .77rem; }
.work-panel-header.work-panel-footer {
  min-height: 46px;
  padding-block: .65rem;
  border-block-start: 1px solid var(--line);
  border-block-end: 0;
}
.work-panel-footer a { font-size: .78rem; font-weight: 650; text-decoration: none; }
.work-row { padding: .76rem 1.1rem; }
.work-row:hover { background: var(--surface-soft); }
.work-row-title { font-size: .84rem; }
.work-row-date { font-size: .72rem; }
.count-chip {
  min-width: 34px;
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
}
.count-chip-alert { color: var(--negative); background: var(--negative-soft); }
.dashboard-overview-grid { grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr); gap: .9rem; }
.dashboard-card { border-radius: 8px; }
.dashboard-card-heading h2 { font-size: .98rem; font-weight: 700; }
.dashboard-card-heading p { font-size: .78rem; }
.volume-card { min-height: 286px; }
.volume-chart { gap: .8rem; }
.volume-track {
  border: 0;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(25% - 1px), var(--line) 25%, transparent calc(25% + 1px));
}
.volume-bar { min-height: 4px; border-radius: 5px 5px 0 0; background: var(--accent); }
.dashboard-activity-list { gap: 0; }
.dashboard-activity-list li { padding-block: .7rem; border-block-end: 1px solid var(--line); }
.dashboard-activity-list li:last-child { border-block-end: 0; }
.activity-icon { border: 0; border-radius: 8px; background: var(--accent-soft); }

/* List screens share the dashboard heading, controls, and bordered panels. */
.list-page { gap: 1rem; }
.list-page .dashboard-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.list-page .dashboard-heading .page-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; margin: 0; }
.list-page .messaging-section-nav { display: flex; flex-wrap: wrap; gap: .45rem; margin: -.25rem 0 0; }
.list-page .messaging-section-nav a { display: inline-flex; min-height: 36px; align-items: center; padding: .4rem .75rem; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); text-decoration: none; }
.list-page .messaging-section-nav a:hover, .list-page .messaging-section-nav a:focus-visible { color: var(--accent-ink); background: var(--accent-soft); }
.list-page .messaging-section-nav a.is-active { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); font-weight: 600; }
.list-page .dashboard-card { padding: 0; overflow: hidden; }
.list-page .dashboard-card-heading { align-items: center; padding: .9rem 1rem; border-block-end: 1px solid var(--line); }
.list-page .dashboard-card-heading h2 { margin: 0; font-family: "Plus Jakarta Sans", "DM Sans", sans-serif; font-size: .98rem; font-weight: 700; letter-spacing: -.01em; text-transform: none; }
.list-page .dashboard-card-heading p { margin: .2rem 0 0; font-size: .78rem; }
.list-page .dashboard-card-heading .customer-heading-icon { display: inline-flex; width: 18px; height: 18px; margin-inline-start: .45rem; vertical-align: -.2em; }
.list-page .dashboard-card-heading .customer-heading-icon svg { width: 18px; height: 18px; }
.list-page .filter-bar { margin: 0; padding: 1rem; border: 0; border-radius: 0; background: transparent; }
.list-page .selection-bar { margin: 1rem; }
.list-page .table-wrap { margin: 0; border: 0; border-radius: 0; }
.list-page .pagination { margin: 0; padding: .85rem 1rem; border-block-start: 1px solid var(--line); }
.ops-gateway-card .status-grid { grid-template-columns: minmax(140px, auto) 1fr; padding: .25rem 1rem 1rem; }
.list-page > .system-details { padding: 0; }
.system-details .status-grid { grid-template-columns: auto 1fr; }

@media (min-width: 601px) and (max-width: 860px) {
  .dashboard-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-shell .work-grid, .dashboard-overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .dashboard-shell .container { padding: 18px 16px 30px; }
  .dashboard-page { gap: 1rem; }
  .dashboard-heading { gap: .7rem; }
  .list-page .dashboard-heading { align-items: flex-start; flex-direction: column; }
  .list-page .dashboard-heading .page-actions { width: 100%; justify-content: flex-start; }
  .dashboard-heading h1 { font-size: 1.35rem; }
  .dashboard-kpis { gap: .6rem; }
  .dashboard-kpi { min-height: 106px; padding: .8rem; }
  .dashboard-kpi > strong { font-size: 1.55rem; }
  .dashboard-kpi-label { align-items: flex-start; font-size: .72rem; }
  .dashboard-kpi-label > span { width: 28px; height: 28px; }
  .dashboard-kpi-label > span > svg { width: 14px; height: 14px; }
  .dashboard-kpi > small { font-size: .66rem; }
  .dashboard-section-heading { align-items: flex-start; }
  .dashboard-actions { width: 100%; }
  .dashboard-actions .button { flex: 1 1 auto; }
  .dashboard-shell .work-panel { min-height: 0; }
  .dashboard-overview-grid { grid-template-columns: 1fr; }
  .volume-card { min-height: 260px; }
  .volume-chart { gap: .35rem; }
}

/* Split sign-in layout adapted from the supplied login reference. The image
   comes from the app's existing pharmacy photography; auth stays staff-only. */
.auth-layout {
  --login-ink: #0f172a;
  --login-muted: #475569;
  --login-quiet: #64748b;
  --login-line: #cbd5e1;
  --login-input: #f8fafc;
  --login-accent: #0097B2;
  --login-accent-ink: #0C5F70;
  min-height: 100vh;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
  overflow: hidden;
  color: var(--login-ink);
  background: #fff;
}
.auth-layout::before { display: none; }
.auth-layout::after {
  position: absolute;
  z-index: 0;
  inset: 0 0 0 auto;
  width: 50%;
  border-radius: 36px 0 0 36px;
  background: #e2e8f0 url("../img/rxreach-login-background.04307f914ab0.jpeg") center 48% / cover no-repeat;
  content: "";
}
.auth-layout .auth-content {
  display: flex;
  width: 50%;
  max-width: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 72px clamp(36px, 8vw, 120px);
}
.auth-layout .auth-card {
  width: 100%;
  max-width: 440px;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--login-ink);
  background: transparent;
  box-shadow: none;
}
.login-brand {
  display: flex;
  align-items: center;
  justify-items: initial;
  justify-content: flex-start;
  gap: .75rem;
  margin-block-end: 2.5rem;
  text-align: start;
  text-decoration: none;
}
.login-brand .brand-mark { width: 42px; height: 42px; margin: 0; border-radius: 10px; }
.login-brand-copy { display: grid; gap: 2px; line-height: 1.15; }
.login-brand-copy strong {
  color: var(--login-ink);
  font-family: "Plus Jakarta Sans", "DM Sans", sans-serif;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -.025em;
}
.login-brand-copy small { color: var(--login-quiet); font-size: .73rem; }
.auth-layout .auth-card h1 {
  margin: 0;
  color: var(--login-ink);
  font-family: "Plus Jakarta Sans", "DM Sans", sans-serif;
  font-size: clamp(1.75rem, 2.5vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -.04em;
  line-height: 1.2;
}
.auth-layout .login-intro { margin: .55rem 0 2rem; color: var(--login-muted); font-size: .93rem; }
.auth-layout .auth-card form {
  gap: 1.2rem;
  padding-block-start: 0;
  border-block-start: 0;
}
.auth-layout .auth-card form > p { margin: 0; }
.auth-layout .auth-card label {
  margin-block-end: .45rem;
  color: var(--login-ink);
  font-size: .86rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}
.auth-layout .auth-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.auth-layout .auth-card select,
.auth-layout .auth-card textarea {
  width: 100%;
  min-height: 48px;
  padding: .7rem .85rem;
  border: 1px solid var(--login-line);
  border-radius: 9px;
  color: var(--login-ink);
  background: #fff;
}
.auth-layout .auth-card input::placeholder { color: var(--login-quiet); }
.auth-layout .auth-help { color: var(--login-quiet); }
.auth-layout .auth-card a { color: var(--login-accent-ink); }
.auth-layout .auth-card a:hover { color: #005D73; }
.auth-layout .password-label-row > a { margin-block-end: .45rem; font-size: .8rem; text-decoration: none; }
.auth-layout .password-label-row > a:hover { text-decoration: underline; }
.auth-layout .auth-card .sign-in-button {
  min-height: 48px;
  margin: .15rem 0 0;
  border: 1px solid #007A93;
  border-radius: 9px;
  color: #fff;
  background: #007A93;
  font-size: .92rem;
  font-weight: 650;
}
.auth-layout .auth-card .sign-in-button:hover { border-color: #005D73; background: #005D73; }
.auth-layout .auth-card #toggle-password {
  border: 0;
  color: var(--login-quiet);
  background: transparent;
  box-shadow: none;
}
.auth-layout .auth-card #toggle-password:hover { border: 0; color: var(--login-ink); background: transparent; }
.auth-layout .auth-card .bad {
  margin: 0 0 1rem;
  padding: .65rem .8rem;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #b91c1c;
  background: #fef2f2;
  font-size: .86rem;
}
.auth-layout .auth-footer {
  position: absolute;
  inset: auto auto 20px clamp(24px, 4vw, 64px);
  color: var(--login-quiet);
  font-size: .76rem;
}

@media (min-width: 601px) and (max-width: 900px) {
  .auth-layout::after { width: 42%; border-radius: 28px 0 0 28px; }
  .auth-layout .auth-content { width: 58%; padding-inline: clamp(32px, 6vw, 76px); }
  .auth-layout .auth-footer { inset-inline-start: 32px; }
}
@media (max-width: 600px) {
  .auth-layout { min-height: 100svh; overflow: auto; }
  .auth-layout::after { display: none; }
  .auth-layout .auth-content { width: 100%; min-height: 100svh; padding: 76px 24px 72px; }
  .auth-layout .auth-card { max-width: 440px; }
  .login-brand { margin-block-end: 2rem; }
  .auth-layout .auth-footer { inset: auto 16px 14px; text-align: center; }
}
.auth-layout > .auth-brand { display: none !important; }

/* Login brand moment — one of the three expressive surfaces. An infrequent,
   staged entrance where sequence communicates hierarchy: the image panel
   fades in, then the brand lockup leads, heading, intro, and each form field
   follow at ~70ms steps. Runs once per load; reduced motion keeps a plain
   static page. */
@media (prefers-reduced-motion: no-preference) {
  .auth-layout .auth-card { animation: none; }
  .auth-layout::after { animation: login-panel-in 640ms var(--ease-out-soft) backwards; }
  .login-brand { animation: login-rise 420ms var(--ease-out-soft) 60ms backwards; }
  .auth-layout .auth-card h1 { animation: login-rise 420ms var(--ease-out-soft) 130ms backwards; }
  .auth-layout .auth-card > .login-intro { animation: login-rise 420ms var(--ease-out-soft) 200ms backwards; }
  .auth-layout .auth-card > .bad { animation: login-rise 420ms var(--ease-out-soft) 240ms backwards; }
  .auth-layout .auth-card form > p:nth-of-type(1) { animation: login-rise 420ms var(--ease-out-soft) 260ms backwards; }
  .auth-layout .auth-card form > p:nth-of-type(2) { animation: login-rise 420ms var(--ease-out-soft) 330ms backwards; }
  .auth-layout .auth-card .sign-in-button { animation: login-rise 420ms var(--ease-out-soft) 400ms backwards; }
  .auth-layout .auth-footer { animation: login-rise 420ms var(--ease-out-soft) 520ms backwards; }
}
@keyframes login-rise {
  from { opacity: 0; transform: translateY(10px); }
}
@keyframes login-panel-in {
  from { opacity: 0; }
}

/* Dashboard first-load: the second brand moment. The KPI row leads and the
   work, overview, and system-detail sections follow in reading order — one
   shot per load; reduced motion renders a static page. */
@media (prefers-reduced-motion: no-preference) {
  .dashboard-page .dashboard-kpi { animation: dash-rise 380ms var(--ease-out-soft) backwards; }
  .dashboard-page .dashboard-kpis .dashboard-kpi:nth-child(1) { animation-delay: 40ms; }
  .dashboard-page .dashboard-kpis .dashboard-kpi:nth-child(2) { animation-delay: 120ms; }
  .dashboard-page .dashboard-kpis .dashboard-kpi:nth-child(3) { animation-delay: 200ms; }
  .dashboard-page .dashboard-kpis .dashboard-kpi:nth-child(4) { animation-delay: 280ms; }
  .dashboard-page .dashboard-work { animation: dash-rise 380ms var(--ease-out-soft) 360ms backwards; }
  .dashboard-page .dashboard-overview-grid { animation: dash-rise 380ms var(--ease-out-soft) 420ms backwards; }
  .dashboard-page .system-details { animation: dash-rise 380ms var(--ease-out-soft) 480ms backwards; }
}
@keyframes dash-rise {
  from { opacity: 0; transform: translateY(8px); }
}
