/* =============================================================================
   Afiyah — visual design system (redesign round 3)
   -----------------------------------------------------------------------------
   Direction: still "the patient chart, not the dashboard" — doctors and
   clinic staff read this dozens of times a day, it should feel like a
   well-made instrument, not a marketing surface — but the palette moved
   away from a generic cool "medical teal" toward something specific to
   where this app actually lives: a private Bangladeshi clinic. Betel-leaf
   green and terracotta clay are real material references (paan leaf,
   pottery, manila folders), not a healthcare-app default; the background
   is warm kraft paper, not clinical white-blue.

   The signature device is the *chop* — a doctor's registration stamp, a
   real convention on a Bangladeshi prescription. It appears exactly where
   its meaning is real: an ISSUED prescription (permanently locked, which
   is precisely what a physical stamp signifies) and the public
   verification page's confirmation — never as decoration on an ordinary
   card. See the "The chop" section below for the component itself and
   the earlier apothecary-green round's retired rationale.

   This file overrides Bootstrap 5.3's CSS custom properties (loaded before
   this file) rather than fighting its classes, so `.card`, `.btn-primary`,
   `.badge`, `.table`, etc. inherit the new system with minimal template
   changes.
   ========================================================================= */

:root {
  /* Explicit light palette (default, and also what an explicit "Light"
     toggle choice forces via :root[data-bs-theme="light"] below). Real dark
     support now exists — see the [data-bs-theme="dark"] block and the
     prefers-color-scheme fallback further down — so this no longer
     claims "light only"; `color-scheme: light` still tells the browser's
     own chrome (scrollbars, form-control native styling) which mode this
     specific state is in. */
  color-scheme: light;

  /* --- Palette: "Ward Round" (redesign phase 1) ---
     Cool porcelain page, deep teal primary, one signal coral for alerts, a
     saffron for waiting/attention. Every colour that carries white text was
     checked against WCAG: --pharmacy ~8.6:1, --alert ~6.4:1, --amber ~6.0:1.
     Variable names are kept from earlier rounds on purpose (--pharmacy is the
     brand/primary colour, --terracotta the "chop"/stamp colour): 30+ call
     sites read them, and renaming risks silently missing one. */
  --paper:          #F5F8F8;   /* app background — cool porcelain */
  --surface:        #FFFFFF;   /* card / input surfaces */
  --ink:             #12262B;   /* primary text — deep ink-teal */
  --pharmacy:        #0B5560;   /* brand / primary actions — deep teal (white text ≈8.6:1) */
  --pharmacy-deep:   #073A42;   /* pressed / sidebar spine */
  --terracotta:      #8A5A00;   /* the chop / stamp colour ONLY (saffron-brown) */
  --alert:           #B93A26;   /* critical warnings ONLY (allergy, destructive) — white text ≈6.4:1 */
  --amber:           #8A5A00;   /* moderate warnings and "waiting" — white text ≈6.0:1 */
  --line:            #DCE5E7;   /* hairline rules — cool grey */
  --line-strong:     #A9BABE;   /* a control's own edge, status rails at rest */

  /* Derived tints */
  --ink-muted:       #4B6168;
  --tint-green:      #E3F0F2;
  --tint-amber:      #FBF0D6;
  --tint-red:        #FBEAE6;

  /* Chrome accents that were one-off hardcoded hex values through two
     redesign rounds — pulled into tokens here specifically so dark mode
     can override them instead of leaving the sidebar/glyph/allergy-banner
     stuck with light-mode-tuned colours no matter which theme is active. */
  /* Sidebar moved off the kraft/betel-green family onto the "sky" blue
     the patient-sky.css hero uses, on request — the two now read as one
     system rather than a green shell around blue content. The top stop is
     literally that hero's own --blue-deep (#14292F); the bottom stop goes
     *deeper* rather than toward the hero's lighter --blue-mid, because
     the hero only ever carries large display text (AA 3:1) while these
     nav links are 0.92rem/500 (AA 4.5:1) — white on --blue-mid is ~3.4:1
     and would fail. Deepening instead keeps every nav row >=4.6:1 top to
     bottom while staying unmistakably the same blue. Tokens, not literals,
     so dark mode below can restate them. */
  --sidebar-gradient-start: #14292F;
  --sidebar-gradient-end:   #0E1F24;
  --sidebar-text:           #E4EEF0;
  --sidebar-nav-text:       #B7CBD0;
  --brand-glyph:          #F0B84A;
  --allergy-border:       #E5B5AB;

  /* --- Type --- */
  --font-display: "Hind Siliguri", "Anek Bangla", "Noto Sans Bengali", -apple-system, sans-serif;
  --font-body: "Hind Siliguri", "Anek Bangla", "Noto Sans Bengali", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "Noto Sans Bengali", ui-monospace, Consolas, monospace;

  /* --- Bootstrap variable overrides (bootstrap.min.css is loaded first;
     these win by source order, and every Bootstrap component below reads
     these same custom properties at paint time) --- */
  --bs-body-font-family: var(--font-body);
  --bs-body-bg: var(--paper);
  --bs-body-color: var(--ink);
  --bs-emphasis-color: var(--ink);
  --bs-secondary-color: var(--ink-muted);
  --bs-border-color: var(--line);
  --bs-border-radius: 0.375rem;
  --bs-border-radius-sm: 0.25rem;
  --bs-border-radius-lg: 0.5rem;
  --bs-font-monospace: var(--font-mono);

  --bs-primary: #0B5560;
  --bs-primary-rgb: 11, 85, 96;
  --bs-secondary: #4B6168;
  --bs-secondary-rgb: 75, 97, 104;
  --bs-success: #1F7A4D;
  --bs-success-rgb: 31, 122, 77;
  --bs-danger: #B93A26;
  --bs-danger-rgb: 185, 58, 38;
  --bs-warning: #8A5A00;
  --bs-warning-rgb: 138, 90, 0;
  --bs-light: #F5F8F8;
  --bs-light-rgb: 245, 248, 248;
  --bs-dark: #12262B;
  --bs-dark-rgb: 18, 38, 43;
  --bs-link-color: var(--pharmacy);
  --bs-link-color-rgb: 11, 85, 96;
  --bs-link-hover-color: var(--pharmacy-deep);
  --bs-focus-ring-color: rgba(11, 85, 96, 0.35);
}

/* -----------------------------------------------------------------------
   Dark mode. Three-way, same contract most modern sites use:
     1. No explicit choice yet, OS prefers dark → dark tokens apply via
        the prefers-color-scheme block below.
     2. No explicit choice yet, OS prefers light → the plain :root block
        above applies, unchanged.
     3. Explicit choice made (the toggle button in the topbar; see
        app.js) → :root[data-bs-theme="…"] always wins over both, in either
        direction — a user who picked dark on a light-OS machine, or
        light on a dark-OS machine, gets exactly what they picked.
   The blocking inline script in base.html's <head> sets data-bs-theme from
   localStorage before first paint, so there's no flash of the wrong
   theme; leaving no attribute at all (first visit, no stored preference)
   is intentional — it's what lets the prefers-color-scheme block below
   keep working, and what lets a live OS theme change re-paint the page
   without a reload.

   Only the values that carry through the rest of this file as CSS custom
   properties need restating here — anything already written as
   `var(--paper)` etc. (most of --bs-* below the palette, and every
   component further down this file) picks up the new values
   automatically the moment these tokens change; nothing else in this
   file needs a dark-specific rule. The two exceptions are Bootstrap's
   `.text-bg-*` badge utilities, which hardcode white text regardless of
   how light the background colour is — every accent below is chosen to
   stay ≥4.5:1 against white for exactly that reason, verified by hand
   the same way the light palette was; and the auth/login screens, which
   keep their own fixed dark-panel-on-light-page look regardless of this
   toggle (that page has no toggle button — it's a deliberate brand
   moment, not app chrome, same reasoning `static/css/app.css`'s auth-hero
   section already documents). PDF/print output is untouched by design —
   a printed document doesn't have a "dark mode." */

/* Dark-token block, shared verbatim by both trigger conditions below
   (system preference with no explicit override, and an explicit "Dark"
   toggle choice) — written once as a mixin-style comment marker isn't
   possible in plain CSS, so the same list appears twice; keep them in
   sync if either changes. Plain @media-wraps-selector syntax throughout
   (not the newer CSS nesting shorthand) so this doesn't depend on
   nesting support — everything else in this file already only needs
   custom-property support, which is much older/safer ground. */
@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme="light"]) {
    color-scheme: dark;

    --paper:          #0C1A1D;
    --surface:        #13262A;
    --ink:             #E6F0F0;
    --ink-muted:       #9DB4B8;
    --pharmacy:        #14707B;   /* lighter teal, still white-text-safe (≈5.5:1) */
    --pharmacy-deep:   #0E555E;
    --terracotta:      #F0B84A;   /* text/border colour only (the chop) — ≈5.6:1 against --surface */
    --alert:           #C8432C;   /* white text ≈5.2:1 */
    --amber:           #8A5A00;   /* unchanged — already had no headroom left to brighten safely */
    --line:            #24393D;
    --line-strong:     #46606B;

    --tint-green:      #17343A;
    --tint-amber:      #3A2F14;
    --tint-red:        #34201C;

    --sidebar-gradient-start: #0F1F23;
    --sidebar-gradient-end:   #0A1518;
    --sidebar-text:           #DCE8EA;
    --sidebar-nav-text:       #A9C0C5;
    --brand-glyph:          #F0B84A;
    --allergy-border:       #5A3A32;

    --bs-primary: #14707B;
    --bs-primary-rgb: 20, 112, 123;
    --bs-secondary: #9DB4B8;
    --bs-secondary-rgb: 157, 180, 184;
    --bs-success: #1F7A4D;
    --bs-success-rgb: 31, 122, 77;
    --bs-danger: #C8432C;
    --bs-danger-rgb: 200, 67, 44;
    --bs-warning: #8A5A00;
    --bs-warning-rgb: 138, 90, 0;
    /* Bootstrap's light/dark semantic pair swaps meaning in dark mode —
       "light" badges/borders should read as a dark neutral here, not a
       jarring white box on a dark page, and vice versa. */
    /* One step lighter than --surface/--paper (matches --line) rather
       than equal to it — a .text-bg-light badge sitting on a card was
       otherwise the exact same colour as the card itself, invisible as
       a pill shape even after the text-colour fix above made its label
       legible. */
    --bs-light: #24393D;
    --bs-light-rgb: 36, 57, 61;
    --bs-dark: #E6F0F0;
    --bs-dark-rgb: 230, 240, 240;
    --bs-link-color-rgb: 58, 179, 194;
    --bs-link-color: #3AB3C2;
    --bs-link-hover-color: #7CD3DE;
    --bs-focus-ring-color: rgba(58, 179, 194, 0.55);
  }
}

:root[data-bs-theme="dark"] {
  color-scheme: dark;

  --paper:          #0C1A1D;
  --surface:        #13262A;
  --ink:             #E6F0F0;
  --ink-muted:       #9DB4B8;
  --pharmacy:        #14707B;
  --pharmacy-deep:   #0E555E;
  --terracotta:      #F0B84A;
  --alert:           #C8432C;
  --amber:           #8A5A00;
  --line:            #24393D;
  --line-strong:     #46606B;

  --tint-green:      #17343A;
  --tint-amber:      #3A2F14;
  --tint-red:        #34201C;

  --sidebar-gradient-start: #0F1F23;
  --sidebar-gradient-end:   #0A1518;
  --sidebar-text:           #DCE8EA;
  --sidebar-nav-text:       #A9C0C5;
  --brand-glyph:          #F0B84A;
  --allergy-border:       #5A3A32;

  --bs-primary: #14707B;
  --bs-primary-rgb: 20, 112, 123;
  --bs-secondary: #9DB4B8;
  --bs-secondary-rgb: 157, 180, 184;
  --bs-success: #1F7A4D;
  --bs-success-rgb: 31, 122, 77;
  --bs-danger: #C8432C;
  --bs-danger-rgb: 200, 67, 44;
  --bs-warning: #8A5A00;
  --bs-warning-rgb: 138, 90, 0;
  --bs-light: #24393D;
  --bs-light-rgb: 36, 57, 61;
  --bs-dark: #E6F0F0;
  --bs-dark-rgb: 230, 240, 240;
  --bs-link-color-rgb: 58, 179, 194;
    --bs-link-color: #3AB3C2;
    --bs-link-hover-color: #7CD3DE;
  --bs-focus-ring-color: rgba(58, 179, 194, 0.55);
}

/* Status colours used as TEXT (stock counts, errors, warnings) need a lighter
   step on dark surfaces than the same colour used as a button fill, where it
   carries white text. Measured on --surface: danger 7.7:1, warning 8.7:1,
   success 8.5:1 (the fills themselves would be 3.2 / 2.7 / 3.9). */
@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme="light"]) .text-danger { color: #FF9C87 !important; }
  :root:not([data-bs-theme="light"]) .text-warning { color: #F0B84A !important; }
  :root:not([data-bs-theme="light"]) .text-success { color: #63D494 !important; }
}
:root[data-bs-theme="dark"] .text-danger { color: #FF9C87 !important; }
:root[data-bs-theme="dark"] .text-warning { color: #F0B84A !important; }
:root[data-bs-theme="dark"] .text-success { color: #63D494 !important; }

body {
  font-feature-settings: "cv11" 1;
}

/* Body text, every page — 20% down from Bootstrap's own 1rem default, on
   request (same reduction already applied by hand to the sidebar nav and
   the facility-hierarchy tree; this is the one-place version so every
   other page's plain text matches instead of drifting page by page).
   Bootstrap 5.3's own `body` rule reads this variable (`font-size: var(
   --bs-body-font-size)`), so overriding the token — this file's own
   established convention, per the header comment above — reaches it
   without touching Bootstrap's classes directly. Headings (the type
   scale right below, all in their own explicit rem) and every UI control
   with its own explicit size (buttons, badges, form inputs, this app's
   own component CSS) are unaffected: `rem` is always relative to the
   root element's font-size, which this does not touch, not to `body`'s —
   this only changes what plain, otherwise-unstyled text inherits. */
:root {
  --bs-body-font-size: 0.8rem;
}

/* Type scale — a defined ratio rather than ad-hoc sizes per template.
   Bootstrap's own h1-h6 defaults are kept close but tightened slightly
   for a denser, more "instrument" feel than a marketing page wants. */
h1, .h1 { font-size: 1.75rem; line-height: 1.25; }
h2, .h2 { font-size: 1.5rem;  line-height: 1.3; }
h3, .h3 { font-size: 1.25rem; line-height: 1.35; }
h4, .h4 { font-size: 1.125rem; line-height: 1.4; }
h5, .h5 { font-size: 1rem;    line-height: 1.4; }
h6, .h6 { font-size: 0.875rem; line-height: 1.4; }

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

/* Body copy sizes small enough to matter — keep them from every template
   picking a slightly different muted-text size by hand. */
small, .small { font-size: 0.8125rem; }
.text-muted { color: var(--ink-muted) !important; }

/* Small, wide-tracked labels — used for eyebrows, table headers, tab labels.
   This is the "chart label" voice: how a clinical form labels a field. */
.chart-label {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

a { text-decoration: none; }
a:hover { text-decoration: underline; }

::selection {
  background: var(--pharmacy);
  color: #fff;
}

/* -----------------------------------------------------------------------
   App shell: sidebar is the "sky" blue spine (aligned with patient-sky.css's
   hero on request — it used to be the kraft ledger's betel-green); main area
   stays quiet paper so data — the actual point of every page — has no
   competition.
   ----------------------------------------------------------------------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Responsive sidebar: a Bootstrap .offcanvas-lg — below the `lg` breakpoint
   it's a slide-in drawer (opened via the topbar's hamburger button);
   at `lg` and above Bootstrap resets it to a normal static flex child,
   where the explicit width below takes over. This is the standard
   responsive-sidebar pattern (spec's "Responsive desktop/tablet/mobile
   UI"), not a custom reinvention. */
.app-sidebar {
  /* A subtle vertical gradient rather than a flat fill — same colour
     family, just enough tonal depth to read as considered rather than a
     plain rectangle. Kept subtle deliberately: this is chrome a doctor
     looks past dozens of times a day, not a hero surface.

     Two layers: the linear gradient is the surface; the radial white
     wash at the top-right echoes .patient-sky-hero::before's ambient
     glow, which is what actually ties the two together beyond the shared
     hue. Done as a second background layer rather than the hero's ::before
     pseudo-element on purpose — that approach needs `overflow: hidden`,
     and below `lg` this element is a Bootstrap .offcanvas-lg drawer whose
     nav must still be able to scroll when the menu is taller than the
     viewport. Own gradient start token now, not --pharmacy-deep: that
     token is also buttons' pressed state, which stays betel-green. */
  background:
    radial-gradient(circle at 100% -10%, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0) 55%),
    linear-gradient(180deg, var(--sidebar-gradient-start) 0%, var(--sidebar-gradient-end) 100%);
  color: var(--sidebar-text);
  width: 280px;
}
@media (min-width: 992px) {
  /* A sticky, self-scrolling column. Without this the sidebar is a plain
     flex child: it grows with its own content and, once the nav is taller
     than the viewport (which it is now the four hospital-operations
     modules are in it), the bottom items — Kitchen, Reports, Rx Templates —
     only come into view by scrolling the whole page, with nothing to say
     they are there. Sticky + `height: 100dvh` + an inner scroll keeps the
     whole menu reachable while the main content scrolls independently.
     Below `lg` this element is a Bootstrap `.offcanvas-lg` drawer that
     already scrolls, so this is desktop-only. */
  .app-sidebar {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    height: 100dvh;
  }
  .app-sidebar > .offcanvas-body {
    height: 100%;
    overflow-y: auto;
    /* A thin scrollbar that does not fight the dark surface. */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
  }
  .app-sidebar > .offcanvas-body::-webkit-scrollbar { width: 6px; }
  .app-sidebar > .offcanvas-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 3px;
  }
  /* The nav must not shrink to fit — it scrolls instead. `mt-auto` on the
     user block still pins it to the bottom of the scrollable area. */
  .app-sidebar > .offcanvas-body > .nav { flex: 0 0 auto; }
}
/* Wide screens: the topbar's sidebar button hides the whole column and the
   main area takes the width. Below lg the drawer is used instead. */
@media (min-width: 992px) {
  html[data-sidebar="collapsed"] .app-sidebar { display: none; }
}
.app-sidebar .offcanvas-header .btn-close { opacity: 0.8; }
.app-sidebar .offcanvas-header .btn-close:hover { opacity: 1; }

/* Under `[data-bs-theme="dark"]` Bootstrap repaints every `.btn-close` as a
   white glyph. On a chip that is deliberately light in *both* themes — a
   `.badge.text-bg-light` (e.g. the removable degree chips on a doctor's
   profile) — that white × on a near-white pill is invisible. Force the
   default dark glyph back for those. */
:root[data-bs-theme="dark"] .badge.text-bg-light .btn-close,
:root[data-bs-theme="dark"] .badge.text-bg-white .btn-close {
  filter: none;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 2rem;
}

/* The real logo (static/img/afiyah-logo.svg — a full icon+wordmark
   lockup, not just a mark) replaced the CSS-drawn ℞-glyph-plus-text
   brand-mark it's nested in. Full colour, own fixed palette baked into
   the SVG's gradients — deliberately NOT theme-reactive (see the dark
   mode section's comment for why a full-colour illustrative logo isn't
   recoloured per theme the way flat UI chrome is), so it renders
   identically in light and dark mode; its own colours read fine on both
   the sidebar's blue (dark green before the sky-theme alignment) and the
   light auth-card surface it also appears on. */
.brand-logo {
  height: 3.5rem; /* 200% of the original 1.75rem, per explicit request */
  width: auto;
}
.brand-logo-lg {
  height: 5rem; /* 200% of the original 2.5rem */
}

/* Category header between sidebar groups (Clinical / Facility / Hospital
   Operations / Finance / Administration) — added once the flat list grew
   past the point of being scannable at a glance (see .app-sidebar's own
   comment on why it needed a sticky scroll container in the first place).
   Text stays quiet (small, uppercase, muted) so it reads as a heading
   rather than competing with the links below it; the icon carries the
   colour instead (added on request) — a label naming a group of icons is
   still a label, not a fifth kind of link. */
.app-sidebar .nav-section-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.55rem 0 0.1rem;
  padding: 0.5rem 0.55rem 0;
  /* A dotted hairline between one group and the next, on request — a
     quieter separator than a solid rule, matching this label's own
     already-quiet (small, muted, uppercase) treatment rather than
     drawing a hard line across the sidebar. */
  border-top: 1px dotted rgba(255, 255, 255, 0.22);
  /* ~12.5% up from the original 0.66rem, on request. */
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--sidebar-nav-text);
  opacity: 0.62;
}
/* The first group sits right under Dashboard, not after another group —
   no hairline to draw and no extra top margin either, unlike every
   later label. */
.app-sidebar .nav-section-label:first-of-type {
  margin-top: 0.5rem;
  padding-top: 0;
  border-top: none;
}
/* One colour per group, purely for at-a-glance identity — not a clinical
   signal, so deliberately off app.css's own reserved --amber/--alert
   (same "ornamental, not semantic" carve-out --accent-slate/-plum/-teal
   already document) and off the brand green. `opacity` above dims the
   *text* only; the icon carries its own colour and stays at full
   strength, which is what "colourful" actually asked for. Five fixed
   values rather than the light/dark `--accent-*` tokens: the sidebar's
   own gradient is dark blue in both themes (`--sidebar-gradient-*` barely
   moves), so these have nothing to adapt to and a fixed set is simpler
   than pretending otherwise. */
/* 20% up from the original 0.82rem, on request. */
.app-sidebar .nav-section-label .bi { font-size: 0.98rem; opacity: 1; }
.app-sidebar .nav-section-icon-core      { color: #5CE1FF; }
.app-sidebar .nav-section-icon-clinical  { color: #FF6B6B; }
.app-sidebar .nav-section-icon-facility  { color: #FFC857; }
.app-sidebar .nav-section-icon-hospital-ops { color: #4ECDC4; }
.app-sidebar .nav-section-icon-finance   { color: #B388FF; }
.app-sidebar .nav-section-icon-admin     { color: #64B5F6; }
.app-sidebar .nav-section-icon-additional { color: #FF9F43; }

/* Compact density, on request. The rhythm used to come from Bootstrap
   utilities on every link (`px-2 py-2`, `gap-1` on the nav), which are
   `!important` and so could not be tuned from here; it lives in these
   rules now. Rows are ~28px tall at the staff 110% root, down from ~36px,
   which is what brings the whole menu on screen without scrolling. */
.app-sidebar .nav { gap: 0.08rem; }
.app-sidebar > .offcanvas-body { padding: 0.75rem 0.6rem; }
.app-sidebar .brand-mark { margin-bottom: 0.9rem; }
.app-sidebar .brand-logo { height: 2.6rem; }
.app-sidebar .nav-link {
  /* 0.32rem before the icons grew 20%; trimmed so the row height, and with it
     the no-scroll menu, is unchanged. */
  padding: 0.28rem 0.55rem;
  line-height: 1.25;
  color: var(--sidebar-nav-text);
  /* 20% down from the original 0.92rem, on request. */
  font-size: 0.74rem;
  font-weight: 500;
  border-radius: var(--bs-border-radius-sm);
  transition: background-color 120ms ease, color 120ms ease;
}
/* Menu icons: 20% up from the link text size (0.74rem), each in its own bright
   colour. Keyed on the icon class, so the template stays plain markup; the
   sidebar is dark blue in both themes, so one set of values serves both. */
.app-sidebar .nav-link .bi { font-size: 0.89rem; line-height: 1; }
/* Second level under a module link: indented and smaller than the 0.74rem menu text; colours stay with the theme. */
.app-sidebar .nav-link.nav-sub { padding-left: 2.6rem; font-size: 0.68rem; }
.app-sidebar .nav-link .bi-grid-1x2 { color: #5CE1FF; }
.app-sidebar .nav-link .bi-people { color: #FF7A90; }
.app-sidebar .nav-link .bi-calendar3 { color: #FFB454; }
.app-sidebar .nav-link .bi-person-badge { color: #7CF29A; }
.app-sidebar .nav-link .bi-file-earmark-medical { color: #C58BFF; }
.app-sidebar .nav-link .bi-clipboard2-pulse { color: #FF8F6B; }
.app-sidebar .nav-link .bi-capsule { color: #4DE8C2; }
.app-sidebar .nav-link .bi-clipboard2-data { color: #FFD84D; }
.app-sidebar .nav-link .bi-cash-stack { color: #8DEB5A; }
.app-sidebar .nav-link .bi-activity { color: #FF5FA2; }
.app-sidebar .nav-link .bi-hospital { color: #5CC8FF; }
.app-sidebar .nav-link .bi-person-badge-fill { color: #A3E635; }
.app-sidebar .nav-link .bi-diagram-3 { color: #FF9F43; }
.app-sidebar .nav-link .bi-diagram-2 { color: #B197FF; }
.app-sidebar .nav-link .bi-droplet { color: #4DD0FF; }
.app-sidebar .nav-link .bi-heart-pulse { color: #FF5C7A; }
.app-sidebar .nav-link .bi-egg-fried { color: #FFD166; }
.app-sidebar .nav-link .bi-receipt { color: #7BE0A8; }
.app-sidebar .nav-link .bi-cash-coin { color: #FFE066; }
.app-sidebar .nav-link .bi-fingerprint { color: #5EEAD4; }
.app-sidebar .nav-link .bi-calendar2-check { color: #FFC857; }
.app-sidebar .nav-link .bi-shield-check { color: #3DDC97; }
.app-sidebar .nav-link .bi-bar-chart-line { color: #FF8AD8; }
/* Ward Round: one quiet icon colour. The rainbow per-icon set above is retired;
   the current page's icon takes the saffron "you are here" accent instead. */
.app-sidebar .nav-link .bi,
.app-sidebar .nav-section-label .bi { color: var(--sidebar-nav-text) !important; }
.app-sidebar .nav-link.active:not(.nav-sub) .bi { color: var(--brand-glyph) !important; }
.app-sidebar .nav-link:hover,
.app-sidebar .nav-link:focus-visible {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.08);
}
.app-sidebar .nav-link.active {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.16);
  /* A left rule, so the current page is identifiable at a glance in a long
     scrolled list rather than just "slightly lighter than its neighbours". */
  box-shadow: inset 3px 0 0 #fff;
}

.app-main {
  flex: 1;
  min-width: 0;
}

.app-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

/* -----------------------------------------------------------------------
   Chart cards — a quiet supporting device (the chop, further down, is the
   redesign's actual signature). A real patient-chart folder uses a
   coloured tab to flag status at a glance; every card here borrows that
   silhouette: white leaf, colour spine on the left, radius only on the
   outward corners. Default spine is neutral (--line) — .tab-brand/
   .tab-amber/.tab-alert opt individual cards into colour only when
   there's something real to flag, same "never decoration" rule the
   allergy banner further down has always followed.
   ----------------------------------------------------------------------- */

.card {
  --tab-color: var(--line);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--tab-color);
  border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0;
  box-shadow: 0 1px 2px rgba(36, 27, 18, 0.05);
}

.card.tab-brand   { --tab-color: var(--pharmacy); }
.card.tab-amber   { --tab-color: var(--amber); }
.card.tab-alert   { --tab-color: var(--alert); }

/* Icon tile — a small filled circle for a stat card's leading glyph
   (dashboard widgets). Same tint/ink pairing as .avatar-initial below,
   promoted to a reusable class since the dashboard repeats it five times.
   The -amber/-alert variants are used only when the number inside
   genuinely needs attention, matching the tab-amber/tab-alert card
   border they sit alongside — colour flags a real condition there, never
   just decorates. -slate/-plum/-teal are the one exception: purely an
   identity colour per dashboard tile (multiple stat tiles side by side
   otherwise read as one undifferentiated green row), same "ornamental,
   not semantic" carve-out .contact-chip's own colours already use, and
   for the same reason kept off --amber/--alert/--terracotta so a tile
   that's genuinely alerting is never confused with one that's merely a
   different colour by default. A tile that supports both (e.g. Waiting
   Patients) still switches to -amber the moment it has something real to
   flag — its resting identity colour is never shown at the same time. */
.icon-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--tint-green);
  color: var(--pharmacy);
  font-size: 1.15rem;
  flex-shrink: 0;
}
.icon-tile-sm { width: 2rem; height: 2rem; font-size: 0.95rem; }
.icon-tile-amber {
  background: var(--tint-amber);
  color: var(--amber);
}
.icon-tile-alert {
  background: var(--tint-red);
  color: var(--alert);
}
.icon-tile-slate {
  background: var(--tint-slate);
  color: var(--accent-slate);
}
.icon-tile-plum {
  background: var(--tint-plum);
  color: var(--accent-plum);
}
.icon-tile-teal {
  background: var(--tint-teal);
  color: var(--accent-teal);
}

/* -----------------------------------------------------------------------
   Dashboard "Today's flow" — a progress ring plus a bar split by
   appointment status. Each tone borrows an icon-tile colour pair above, so a
   status reads the same colour here as on the tiles. Pure CSS: --pct is the
   only input (an integer 0-100 from the server).
   ----------------------------------------------------------------------- */
/* Vivid tones: the --rd-* hues (defined further down, already tuned for both themes), each with a fill mixed from
   its own colour so a chip reads as that colour and not as a grey tint. Marks measure >= 4.3:1 on a card. */
.flow-slate { --flow-fg: var(--rd-blue);   --flow-bg: color-mix(in srgb, var(--rd-blue) 16%, var(--surface)); }
.flow-teal  { --flow-fg: var(--rd-teal);   --flow-bg: color-mix(in srgb, var(--rd-teal) 16%, var(--surface)); }
.flow-amber { --flow-fg: var(--rd-amber);  --flow-bg: color-mix(in srgb, var(--rd-amber) 16%, var(--surface)); }
.flow-plum  { --flow-fg: var(--rd-violet); --flow-bg: color-mix(in srgb, var(--rd-violet) 16%, var(--surface)); }
.flow-green { --flow-fg: var(--rd-green);  --flow-bg: color-mix(in srgb, var(--rd-green) 16%, var(--surface)); }
.flow-muted { --flow-fg: var(--bs-secondary-color); --flow-bg: var(--bs-tertiary-bg); }
:root[data-bs-theme="dark"] { --avatar-ink: var(--accent-teal); }

.flow-ring {
  --size: 6.5rem;
  width: var(--size);
  height: var(--size);
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--rd-teal), var(--rd-blue) calc(var(--pct) * 1%), var(--tint-slate) 0);
}
.flow-ring-hole {
  width: calc(var(--size) - 1.1rem);
  height: calc(var(--size) - 1.1rem);
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}
.flow-ring-pct { font-size: 1.35rem; font-weight: 600; }
.flow-ring-cap { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--bs-secondary-color); }

/* 7-day visits chart: one series, so no legend; the day label and the count
   sit on each bar, today is the full brand colour and earlier days a tint of
   it. Bars are anchored to the baseline with a 4px rounded data end. */
.trend {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  height: 8rem;
  border-bottom: 1px solid var(--line);
}
.trend-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 0.2rem;
}
.trend-count { font-size: 0.72rem; font-family: var(--font-mono); color: var(--ink-muted); }
.trend-bar {
  width: 100%;
  max-width: 2.4rem;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--rd-blue) 72%, white), var(--rd-blue));
}
.trend-col.is-today .trend-bar { background: linear-gradient(180deg, color-mix(in srgb, var(--rd-teal) 70%, white), var(--rd-teal)); }
.trend-col.is-today .trend-count { color: var(--ink); font-weight: 600; }
.trend-labels { display: flex; gap: 0.5rem; margin-top: 0.3rem; }
.trend-labels span { flex: 1; text-align: center; font-size: 0.7rem; color: var(--ink-muted); }
.trend-labels .is-today { color: var(--ink); font-weight: 600; }

.flow-bar {
  display: flex;
  gap: 2px;
  height: 0.8rem;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bs-tertiary-bg);
}
.flow-bar .flow-seg { background: linear-gradient(180deg, color-mix(in srgb, var(--flow-fg) 75%, white), var(--flow-fg)); min-width: 4px; }

.flow-legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
  gap: 0.35rem 1rem;
  margin-top: 0.85rem;
}
.flow-legend li { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.flow-chip {
  width: 1.7rem;
  height: 1.7rem;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--flow-bg);
  color: var(--flow-fg);
  font-size: 0.85rem;
}

/* Stat tiles — the row at the top of the dashboard and the bookings inbox
   (`.vib-row` on the Bootstrap row). Ward Round: flat white leaf, 1px rule and
   the status rail (the direction's signature) down the left edge. The rail is
   teal at rest and turns saffron on `.tab-amber`, the existing "needs
   attention" flag, so colour still means a real condition and nothing else;
   the old per-tile blue/plum/teal identity hues are retired.

   Every selector still doubles `.vib-row`: patient-sky.css loads after this
   file and has `.sky-panel .card` / `.sky-panel .chart-label` rules at
   specificity 0,2,0, and the doubled class (0,3,0) wins in either order. */
.vib-row.vib-row .card {
  --rail: var(--pharmacy);
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-left: 5px solid var(--rail);
  border-radius: var(--bs-border-radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: none;
  transition: border-color 120ms ease;
}
.vib-row.vib-row .card.tab-amber { --rail: var(--amber); }
.vib-row.vib-row .card.tab-alert { --rail: var(--alert); }
.vib-row.vib-row .card::after { content: none; }
.vib-row.vib-row .card-body { position: relative; z-index: 1; }
.vib-row.vib-row .chart-label { color: var(--ink-muted) !important; }
.vib-row.vib-row .icon-tile,
.vib-row.vib-row .card:has(.icon-tile-slate) .icon-tile,
.vib-row.vib-row .card:has(.icon-tile-plum) .icon-tile,
.vib-row.vib-row .card:has(.icon-tile-teal) .icon-tile {
  background: var(--tint-green);
  color: var(--pharmacy);
  box-shadow: none;
}
.vib-row.vib-row .card.tab-amber .icon-tile { background: var(--tint-amber); color: var(--amber); }
.vib-row.vib-row .card.tab-alert .icon-tile { background: var(--tint-red); color: var(--alert); }

/* Category identity on a KPI tile. `data-tone="blue"` gives the icon its own
   hue so tiles are told apart without reading; the left rail and the numeral
   still carry status (amber/red only when something needs doing), so colour
   keeps both jobs without sharing one. Hues are the same --rd-* set the
   reports use (deep enough for white text, and not the clinical red/amber/
   green), repeated here because reports-analytics.css is not loaded on every
   page. Must stay below the .tab-* icon rules above so it wins as the later
   one at equal specificity. */
:root {
  --rd-blue: #2B6CB0; --rd-violet: #6B5BA8; --rd-teal: #0B7A83; --rd-green: #2F7D4F;
  --rd-amber: #9A6200; --rd-orange: #B24A12; --rd-rose: #B03060; --rd-slate: #5F7380;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme="light"]) {
    --rd-blue: #6FA8E8; --rd-violet: #A99BE0; --rd-teal: #4FB3BD; --rd-green: #5FBF86;
    --rd-amber: #E0A93A; --rd-orange: #EE8A52; --rd-rose: #E57A9C; --rd-slate: #9FB4BF;
  }
}
:root[data-bs-theme="dark"] {
  --rd-blue: #6FA8E8; --rd-violet: #A99BE0; --rd-teal: #4FB3BD; --rd-green: #5FBF86;
  --rd-amber: #E0A93A; --rd-orange: #EE8A52; --rd-rose: #E57A9C; --rd-slate: #9FB4BF;
}
[data-tone="blue"] { --tone: var(--rd-blue); } [data-tone="violet"] { --tone: var(--rd-violet); }
[data-tone="teal"] { --tone: var(--rd-teal); } [data-tone="green"] { --tone: var(--rd-green); }
[data-tone="amber"] { --tone: var(--rd-amber); } [data-tone="orange"] { --tone: var(--rd-orange); }
[data-tone="rose"] { --tone: var(--rd-rose); } [data-tone="slate"] { --tone: var(--rd-slate); }
.vib-row.vib-row .card[data-tone] .icon-tile {
  background: color-mix(in srgb, var(--tone) 15%, var(--surface));
  color: var(--tone);
}
/* A little depth, as on the reference dashboards: a soft ambient shadow that
   lifts a linked tile on hover. Subtle on purpose — surfaces stay flat. */
.vib-row.vib-row .card[data-tone] { box-shadow: 0 1px 2px rgba(18, 38, 43, 0.06), 0 8px 18px -12px rgba(18, 38, 43, 0.22); }
.vib-row.vib-row a:hover > .card[data-tone] { box-shadow: 0 1px 2px rgba(18, 38, 43, 0.08), 0 12px 22px -12px rgba(18, 38, 43, 0.3); }
.vib-row.vib-row a:hover > .card { border-color: var(--line-strong, var(--pharmacy)); }

/* Patient rows are cards: they carry the same rail through the card spine. A severe
   allergy is red, a mild one saffron, a consultation in progress teal, otherwise neutral. */
.patient-row.card { border-left-width: 5px; }

/* The status rail — Ward Round's signature. A 5px bar on the left edge of a
   table row (drawn as an inset shadow on the first cell, since a row border does
   not survive border-collapse) that carries the row's status, so a queue can be
   read at a glance without reading a word: waiting = saffron, in consultation =
   green, completed = grey, cancelled / no-show = red, not yet arrived = neutral.
   Never the only signal: the status badge in the row still says it in words. */
.status-rail > :first-child { box-shadow: inset 5px 0 0 var(--rail, var(--line)); }
.status-rail.status-scheduled { --rail: var(--line-strong, #A9BABE); }
.status-rail.status-confirmed { --rail: var(--line-strong, #A9BABE); }
.status-rail.status-waiting { --rail: var(--amber); }
.status-rail.status-in_consultation { --rail: var(--bs-success); }
.status-rail.status-completed { --rail: var(--ink-muted); }
/* Attendance register: the day's status. Same hues as the status badge beside it; a row nobody has marked yet is neutral. */
/* Leave requests: waiting is saffron, approved is green, rejected is coral, cancelled is neutral (the badge keeps the word). */
.status-rail.status-leave-pending { --rail: var(--amber); }
.status-rail.status-leave-approved { --rail: var(--bs-success); }
.status-rail.status-leave-rejected { --rail: var(--alert); }
.status-rail.status-leave-cancelled { --rail: var(--line-strong, #A9BABE); }
.status-rail.status-att-present { --rail: var(--bs-success); }
.status-rail.status-att-late, .status-rail.status-att-half_day { --rail: var(--amber); }
.status-rail.status-att-absent { --rail: var(--alert); }
.status-rail.status-att-on_leave { --rail: var(--ic-indigo); }
.status-rail.status-att-weekly_off, .status-rail.status-att-holiday, .status-rail.status-att-pending { --rail: var(--line-strong, #A9BABE); }
/* People and memberships: active or not. */
.status-rail.status-active { --rail: var(--bs-success); }
.status-rail.status-inactive { --rail: var(--ink-muted); }
.status-rail.status-cancelled,
.status-rail.status-no_show { --rail: var(--alert); }

/* Online-booking inbox (appointments/booking_group.html): a headed card whose
   chip takes the tone of its .flow-* class, and a serial shown as a disc. */
.bk-group {
  border: 1px solid var(--sky-line, var(--line));
  border-radius: var(--bs-border-radius-lg, 0.5rem);
  background: var(--sky-surface, var(--surface));
  overflow: hidden;
}
.bk-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--sky-line, var(--line));
  border-left: 4px solid var(--flow-fg);
}
.bk-head-chip { width: 1.6rem; height: 1.6rem; font-size: 0.85rem; }
.bk-count { background: var(--flow-bg); color: var(--flow-fg); }
.bk-serial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--sky-chip-bg, var(--tint-slate));
  color: var(--sky-chip-ink, var(--accent-slate));
  font-weight: 600;
}
.bk-dept { white-space: nowrap; }
/* The check-in control: a department select and two buttons that share one
   height and one text size (the table's own 0.74rem), so they line up as a
   single control. The select used to be `w-auto`, which sizes it to its
   longest option — a department like "Obstetrics & Gynaecology" made it the
   widest thing on the row. A fixed width with an ellipsis keeps it small; the
   full name is still in the opened list and in the title. */
.bk-checkin .form-select,
.bk-checkin .btn-sm,
.bk-table .btn-sm {
  height: 1.9rem;
  font-size: 0.74rem;
}
/* Scoped to the control itself, not to `.bk-table`: the same partial also
   renders in today's queue (appointments/partials/queue_booking_row.html),
   whose table is not a `.bk-table` — there the select fell back to
   Bootstrap's `width: 100%`, stretched the action cell and put a horizontal
   scrollbar on the whole queue. */
.bk-checkin .form-select {
  border-color: var(--sky-field-line, var(--line));
  width: 8.5rem;
  max-width: 100%;
  padding: 0 1.75rem 0 0.55rem;
  border-radius: 999px;
  text-overflow: ellipsis;
}
/* In the queue the control may wrap — the select drops above the button
   when the row is short of room — the same way the appointment rows above
   it already wrap "Cancel" under "No Show". Without this the select and the
   button held their combined width and pushed a horizontal scrollbar onto
   the whole queue between ~1000px and ~1200px, where the sidebar is still
   showing. */
.queue-row-online .bk-checkin {
  flex-wrap: wrap;
  justify-content: flex-end;
  row-gap: 0.3rem;
}
/* And it may shrink: 8.5rem when there is room, down to 6.5rem when not.
   The option list still opens full width, and the title names the choice. */
.queue-row-online .bk-checkin .form-select {
  width: 8.5rem;
  min-width: 6.5rem;
  flex: 0 1 8.5rem;
}
.bk-table .btn-sm,
.bk-checkin .btn-sm {
  display: inline-flex;
  align-items: center;
  padding: 0 0.7rem;
  border-radius: 999px;
}
.bk-table thead th { white-space: nowrap; }
/* `.small` is 0.8125rem app-wide, but .sky-table sets its own text to 0.7rem,
   so every secondary line in a row (phone, clinic, the session span, the
   reason, the code) rendered larger than the name above it. Held to the
   table's size instead; the muted colour is what marks them as secondary. */
.bk-table .small { font-size: inherit; }
.flow-legend .flow-label { flex: 1; min-width: 0; font-size: 0.82rem; }
.flow-legend .flow-count { font-weight: 600; }
.flow-legend .flow-zero { opacity: 0.5; }

/* -----------------------------------------------------------------------
   Avatar circles — a person's photo, or their initial on the same
   tint/ink chip every other placeholder glyph in this file uses. One
   shared component so the doctor directory and patient list (and
   whatever list grows this pattern next) don't each reinvent it; the
   `-lg` modifier is the doctor directory's larger grid-card avatar, the
   bare class is the patient list's inline row avatar.
   ----------------------------------------------------------------------- */
.avatar-initial, .avatar-photo {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.avatar-photo {
  object-fit: cover;
  border: 2px solid var(--tint-green);
}
.avatar-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--tint-green);
  /* The brand teal on its dark tint is 2.3:1; dark mode swaps the ink through this token. */
  color: var(--avatar-ink, var(--pharmacy));
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  border: 2px solid var(--surface);
}
/* Chrome size — the top bar and the mobile sidebar footer. Small
   enough to sit on one line of .small text without changing the bar's
   height, which is the whole constraint here. */
.avatar-xs.avatar-photo,
.avatar-xs.avatar-initial {
  width: 1.65rem;
  height: 1.65rem;
  border-width: 1px;
  font-size: 0.75rem;
}

.avatar-lg.avatar-photo,
.avatar-lg.avatar-initial {
  width: 5.25rem;
  height: 5.25rem;
  border-width: 3px;
}
.avatar-lg.avatar-initial {
  font-size: 1.9rem;
}

/* -----------------------------------------------------------------------
   Pill search box + pill filter tabs — the doctor directory's and
   patient list's shared "facet filter" chrome (a live search plus a row
   of rounded toggle filters). Kept generic/reusable rather than page name-
   spaced since the same pattern is the obvious fit for medicines,
   diagnoses, and investigations lists later (spec §23's autocomplete/
   filter lists).
   ----------------------------------------------------------------------- */
.pill-search {
  position: relative;
  max-width: 320px;
}
.pill-search input[type="search"] {
  border-radius: 999px;
  padding-left: 2.5rem;
  background: var(--tint-green);
  border-color: transparent;
}
.pill-search input[type="search"]:focus {
  background: var(--surface);
}
.pill-search .bi-search {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-muted);
  pointer-events: none;
}

.pill-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.pill-tab {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--line);
}
.pill-tab:hover {
  color: var(--ink);
  background: var(--tint-green);
  text-decoration: none;
}
.pill-tab.active {
  color: #fff;
  background: var(--pharmacy);
  border-color: var(--pharmacy);
}

/* ID chip — a compact rounded pill for an identifier that reads better
   grouped with a name than as plain muted text (patient list row,
   doctor profile header). Monospace is added per use site via
   .font-monospace rather than baked in here, since not every ID this
   wraps is one (e.g. free-text codes). */
.id-chip {
  display: inline-block;
  background: var(--tint-green);
  color: var(--pharmacy);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

/* Specialization badge — a doctor's specialty as a quiet pill rather
   than plain text, used on both the directory grid card and the profile
   header (doctor_list.html / doctor_detail.html). */
.spec-badge {
  display: inline-block;
  background: var(--tint-green);
  color: var(--pharmacy);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
}

/* Contact chip — a small filled, coloured icon circle in front of a
   phone/email/address line (doctor profile header), instead of a flat
   muted icon+text pair. Purely a legibility/attractiveness device for a
   contact list, not a status signal — so it's one of the few places in
   this file that hangs colour on something without a real condition
   behind it. --accent-slate/--accent-plum/--accent-teal (below, also
   used by the dashboard's .icon-tile-* variants) are the ornamental set
   this deliberately stays to, rather than reaching for a generic
   red/blue/purple palette that would fight the kraft-paper palette —
   none of the three overlaps --amber/--alert/--terracotta, which stay
   reserved for their real meanings everywhere these are used. */
:root {
  --accent-slate: #3B6E8F;
  --accent-plum:  #7D4F6B;
  --accent-teal:  #2E7D6B;
  --tint-slate:   #E3EDF3;
  --tint-plum:    #F1E3EB;
  --tint-teal:    #DFF0EC;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme="light"]) {
    --accent-slate: #6FA8C9;
    --accent-plum:  #B5829D;
    --accent-teal:  #4FB39C;
    --tint-slate:   #1C2E3A;
    --tint-plum:    #3A2530;
    --tint-teal:    #16332C;
  }
}
:root[data-bs-theme="dark"] {
  --accent-slate: #6FA8C9;
  --accent-plum:  #B5829D;
  --accent-teal:  #4FB39C;
  --tint-slate:   #1C2E3A;
  --tint-plum:    #3A2530;
  --tint-teal:    #16332C;
}

.contact-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.88rem;
  color: var(--ink);
  white-space: nowrap;
}
.contact-chip:hover {
  color: var(--pharmacy);
  text-decoration: none;
}
.contact-chip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 50%;
  color: #fff;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.contact-chip-phone .contact-chip-icon { background: var(--pharmacy); }
.contact-chip-email .contact-chip-icon { background: var(--amber); }
.contact-chip-location .contact-chip-icon { background: var(--accent-slate); }

/* Profile header — the card an entity's own page (doctor/clinic/patient
   detail) opens with: avatar, name, id-chip, contact chips, an Edit
   button. Padding-only shared rule; each page still supplies its own
   avatar/name/chip markup inside it. */
.profile-header {
  padding: 1.75rem;
}

/* -----------------------------------------------------------------------
   The chop — the redesign's signature device. A Bangladeshi doctor's
   prescription carries their registration stamp once it's real; nothing
   before that point does. This translates the convention directly rather
   than decoratively: a DRAFT prescription has no chop (nothing official
   exists yet to stamp), an ISSUED one gets this mark — permanently, the
   same way a chop never lifts off paper once it's pressed. Used in
   exactly two places: the prescription workspace's issued state, and the
   public verification page's "valid" confirmation — never as a generic
   accent, the same restraint the card system above already practises.
   ----------------------------------------------------------------------- */

.chop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4.75rem;
  height: 4.75rem;
  border-radius: 50%;
  border: 2px solid var(--terracotta);
  color: var(--terracotta);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.35;
  transform: rotate(-7deg);
  position: relative;
  flex-shrink: 0;
  background: transparent;
}
.chop::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid var(--terracotta);
  border-radius: 50%;
}
.chop-lg {
  width: 7rem;
  height: 7rem;
  font-size: 0.75rem;
  border-width: 2.5px;
}
.chop-sm {
  width: 2.5rem;
  height: 2.5rem;
  font-size: 0.44rem;
  letter-spacing: 0.03em;
  border-width: 1.5px;
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--ink);
}

/* -----------------------------------------------------------------------
   Buttons — flatten Bootstrap's default shadow/gradient look; a clinical
   tool should look pressed, not glossy. This is also why the vibrancy
   pass elsewhere in this file (sidebar, auth hero) uses gradients only
   on large background surfaces, never on button fills: a gradient bright
   enough to visibly read as "richer" pushes its lighter stop below the
   4.5:1 contrast a button label needs, which a flat colour picked
   directly against WCAG never has to risk.
   ----------------------------------------------------------------------- */

.btn {
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--bs-border-radius-sm);
  box-shadow: none !important;
}
/* This hardcoded `.btn` font-size above was quietly defeating Bootstrap's
   own `.btn-sm`/`.btn-lg` size variants everywhere in the app — `.btn-sm`
   only ever shrank padding, never the text, since `font-size` was pinned
   by the plain `.btn` selector's literal value rather than reading
   Bootstrap's `--bs-btn-font-size` custom property the size variants set.
   Explicit override here (same `.small`/`small` size token already used
   elsewhere in this file) rather than switching `.btn` itself to
   `var(--bs-btn-font-size)`, which would have handed the *default*
   button size back to Bootstrap's own `--bs-btn-font-size` (1rem) instead
   of this app's own 0.9rem baseline. */
.btn-sm {
  font-size: 0.8125rem;
}
/* Compact button — the pill used on the online-bookings inbox, as a class any
   page can opt into: one fixed height and the sky pages' own 0.74rem text, so
   a row of them lines up whatever is inside (label, icon, or a bare ×). Sits
   after `.btn-sm` on purpose; it replaces that size rather than adding to it. */
/* The field that sits beside a .btn-compact (an "add" row): same height, same
   text, same pill, so the pair reads as one control. */
.field-compact {
  height: 1.9rem;
  padding-top: 0;
  padding-bottom: 0;
  font-size: 0.74rem;
  border-radius: 999px;
}
.btn-compact {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.9rem;
  padding: 0 0.8rem;
  font-size: 0.74rem;
  line-height: 1;
  border-radius: 999px;
  white-space: nowrap;
}
.btn-primary {
  --bs-btn-bg: var(--pharmacy);
  --bs-btn-border-color: var(--pharmacy);
  --bs-btn-hover-bg: var(--pharmacy-deep);
  --bs-btn-hover-border-color: var(--pharmacy-deep);
  --bs-btn-active-bg: var(--pharmacy-deep);
  --bs-btn-active-border-color: var(--pharmacy-deep);
}
.btn-outline-primary {
  --bs-btn-color: var(--pharmacy);
  --bs-btn-border-color: var(--pharmacy);
  --bs-btn-hover-bg: var(--pharmacy);
  --bs-btn-hover-border-color: var(--pharmacy);
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: var(--pharmacy-deep);
  --bs-btn-active-border-color: var(--pharmacy-deep);
}
.btn-outline-secondary {
  --bs-btn-color: var(--ink-muted);
  --bs-btn-border-color: var(--line);
  --bs-btn-hover-bg: var(--tint-green);
  --bs-btn-hover-color: var(--ink);
  --bs-btn-hover-border-color: var(--line);
}
.btn-outline-danger {
  --bs-btn-color: var(--alert);
  --bs-btn-border-color: var(--alert);
  --bs-btn-hover-bg: var(--alert);
  --bs-btn-hover-border-color: var(--alert);
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: var(--alert);
  --bs-btn-active-border-color: var(--alert);
  --bs-btn-active-color: #fff;
}
/* In dark theme the fill tokens (--pharmacy, --alert) are too dark to read as
   text on the card surface (2.7 / 3.5:1), so outlined buttons use a lighter
   text+edge colour; their hover fill keeps the token with white text. */
:root[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: #5CC3CF; --bs-btn-border-color: #5CC3CF; }
:root[data-bs-theme="dark"] .btn-outline-danger  { --bs-btn-color: #F08A7C; --bs-btn-border-color: #F08A7C; }
@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme="light"]) .btn-outline-primary { --bs-btn-color: #5CC3CF; --bs-btn-border-color: #5CC3CF; }
  :root:not([data-bs-theme="light"]) .btn-outline-danger  { --bs-btn-color: #F08A7C; --bs-btn-border-color: #F08A7C; }
}
.btn:disabled, .btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
/* Icon-only buttons (row actions: remove, move up/down) get a fixed,
   comfortable hit target instead of shrinking to the glyph's own size —
   a real usability floor (WCAG 2.5.5-adjacent), not just visual polish. */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
}

/* -----------------------------------------------------------------------
   Forms
   ----------------------------------------------------------------------- */

/* Field text sits at the label's size (.82rem), not above it: at .92rem a
   typed value read larger than the page around it on every form. The sm
   variants stay one step smaller so they are still the smaller control. */
.form-control, .form-select {
  border-color: var(--line);
  font-size: 0.82rem;
}
.form-control-sm, .form-select-sm {
  font-size: 0.78rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--pharmacy);
  box-shadow: 0 0 0 0.2rem var(--bs-focus-ring-color);
}
.form-control:disabled, .form-select:disabled,
.form-control[readonly] {
  background-color: var(--paper);
  color: var(--ink-muted);
}
.form-control.is-invalid, .form-select.is-invalid {
  border-color: var(--alert);
}
.form-control.is-invalid:focus, .form-select.is-invalid:focus {
  box-shadow: 0 0 0 0.2rem rgba(179, 57, 43, 0.25);
}
.invalid-feedback {
  color: var(--alert);
  font-size: 0.8125rem;
}
.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
}
.form-label .text-danger { font-weight: 700; } /* required-field marker */

/* -----------------------------------------------------------------------
   Tables — a chart's flowsheet: quiet hairlines, a tinted header band with
   wide-tracked small-caps, and a faint even-row wash. Colour on a row still
   means status only: the stripe is a neutral tint of the surface.
   ----------------------------------------------------------------------- */

.table {
  --bs-table-border-color: var(--line);
  /* Head band, even-row wash and hover wash. Tokens, so both themes follow;
     patient-sky.css re-points them to the sky tokens inside a .sky-table. */
  --tbl-head-bg: var(--tint-green);
  --tbl-stripe: color-mix(in srgb, var(--tint-green) 62%, var(--surface));
  --tbl-hover: color-mix(in srgb, var(--tint-green) 75%, var(--line));
  font-size: 0.92rem;
}
/* The head is a band, not a label: tinted ground, full-strength ink and a
   teal rule underneath, so it reads as a different kind of row at a glance. */
.table thead th {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink);
  background-color: var(--tbl-head-bg);
  border-bottom: 2px solid var(--pharmacy);
  vertical-align: middle;
}
.table > :not(caption) > * > * {
  padding: 0.7rem 0.85rem;
}
/* Every second body row takes a faint wash, so a long row can be followed
   across the page. Faint on purpose: the status rail and badges still carry
   the colour, and this stays well under the head band's strength. */
.table > tbody > tr:nth-of-type(even) > * {
  background-color: var(--tbl-stripe);
}
.table-hover > tbody > tr:hover > * {
  background-color: var(--tbl-hover);
}
/* Dense list tables (pharmacy stock): column widths come from a <colgroup>,
   and a long name is cut with an ellipsis (full text in the title) instead of
   wrapping to a second line, so every row stays one line tall. */
.table-dense { table-layout: fixed; }
.table-dense, .table-tight { font-size: 0.84rem; }
.table-dense > :not(caption) > * > *, .table-tight > :not(caption) > * > * { padding: 0.32rem 0.6rem; }
.table-dense .cell-trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* :not(.btn) — a button-styled link inside a table cell (e.g. queue_row.html's
   "Start Consultation") is still an <a>, so this rule's higher specificity
   than Bootstrap's own `.btn { color: var(--bs-btn-color) }` was silently
   overriding its intended button text colour with the table's plain-text-
   link colour instead — on `.btn-primary` that swaps the brand green
   button's white label for --ink, which happens to be legible in dark mode
   (--ink is a light cream there) but is a genuine dark-on-dark-green
   failure in light mode (--ink is near-black there), and either way isn't
   the colour the button variant actually specifies. This rule was only
   ever meant for plain in-cell text links (a patient name, an invoice
   number), never for `.btn`, hence the exclusion. */
.table a:not(.btn) { color: var(--ink); font-weight: 600; }
.table a:not(.btn):hover { color: var(--pharmacy); }

/* -----------------------------------------------------------------------
   Badges — Bootstrap's text-bg-* utilities already read the palette via
   the --bs-* overrides at the top of this file; this just softens the
   default weight/tracking to match the rest of the type system.
   ----------------------------------------------------------------------- */

.badge {
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 0.72rem;
  padding: 0.35em 0.6em;
}

/* -----------------------------------------------------------------------
   Empty states — every list in the app hits this eventually (a brand new
   clinic with no patients yet, a doctor with no favorites). One shared
   pattern instead of each template inventing its own "No X found" row.
   ----------------------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--ink-muted);
}
.empty-state .bi {
  font-size: 2rem;
  color: var(--line);
  display: block;
  margin-bottom: 0.75rem;
}
.empty-state p {
  margin-bottom: 1rem;
}

/* -----------------------------------------------------------------------
   Loading — HTMX requests get a subtle spinner via htmx's own
   `.htmx-request` class rather than a bespoke JS loading state.
   ----------------------------------------------------------------------- */

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-flex; }

.spinner-dot {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--line);
  border-top-color: var(--pharmacy);
  border-radius: 50%;
  animation: afiyah-spin 0.6s linear infinite;
}
@keyframes afiyah-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .spinner-dot { animation: none; }
}

/* -----------------------------------------------------------------------
   Nav tabs — underline style rather than Bootstrap's boxed default.
   ----------------------------------------------------------------------- */

.nav-tabs {
  border-bottom: 1px solid var(--line);
}
.nav-tabs .nav-link {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--ink-muted);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.6rem 0.9rem;
}
.nav-tabs .nav-link:hover {
  border-color: var(--line);
  color: var(--ink);
}
.nav-tabs .nav-link.active {
  background: transparent;
  color: var(--pharmacy);
  border-color: var(--pharmacy);
}

/* Keyboard hints ("Ctrl M" on the prescription tabs, "Ctrl + S" on the
   forms) as keycaps on the page's own surface. Bootstrap paints <kbd> with
   the body *text* colour as its background, which in dark theme turned
   them into cream blocks with the muted text all but invisible on them. */
kbd {
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 0.3rem;
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 0.72rem;
  font-weight: 600;
  box-shadow: none;
}

/* Filter pills (patients:list's summary row) — reported too large at
   Bootstrap's own default nav-link size (1rem font, 0.5rem/1rem padding).
   Same 0.85rem font-size `.nav-tabs .nav-link` above already uses for the
   doctor directory's own filter tabs, ~15% less padding than Bootstrap's
   default so the reduction reads consistently in both dimensions, not
   just the text. */
.nav-pills .nav-link {
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem 0.85rem;
}

/* -----------------------------------------------------------------------
   Clinical warnings — the one place saturated colour is allowed to raise
   its voice, and only there.
   ----------------------------------------------------------------------- */

.allergy-banner {
  background: var(--tint-red);
  border: 1px solid var(--allergy-border);
  border-left: 4px solid var(--alert);
  border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0;
}

.clinical-warning {
  border-left: 4px solid var(--amber);
  background-color: var(--tint-amber);
  border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0;
}

/* Bootstrap's warning-variant components (.text-bg-warning badges like the
   allergy chips, .btn-warning, .alert-warning) bake their TEXT colour into
   the compiled CSS from Bootstrap's OWN default $warning (a light yellow
   that reads fine with black text) — a decision made at Bootstrap's build
   time, not read from --bs-warning-rgb at paint time. Overriding
   --bs-warning above (deliberately dark — see the palette comment's
   "--amber (white text) ≈5.1:1") only changes these components'
   *background*, so without this block every one of them silently renders
   black text on dark amber: exactly the illegible allergy-badge bug this
   fixes. .text-bg-warning has no CSS-variable seam to hook (Bootstrap
   hardcodes `color: #000 !important`), so it's met with !important here;
   .btn-warning does expose per-state variables, which is the idiomatic
   override this file otherwise always prefers. */
.text-bg-warning {
  color: #fff !important;
}
.btn-warning {
  --bs-btn-color: #fff;
  --bs-btn-hover-color: #fff;
  --bs-btn-active-color: #fff;
  --bs-btn-disabled-color: #fff;
}
.alert-warning {
  --bs-alert-color: var(--ink);
  --bs-alert-bg: var(--tint-amber);
  --bs-alert-border-color: var(--amber);
}
/* The info notice: the brand tint, not Bootstrap's bright cyan. Same idea as .alert-warning above. */
.alert-info {
  --bs-alert-color: var(--ink);
  --bs-alert-bg: var(--tint-green);
  --bs-alert-border-color: color-mix(in srgb, var(--pharmacy) 35%, var(--line));
  --bs-alert-link-color: var(--ink);
}
.alert-info .alert-link { text-decoration: underline; text-underline-offset: 0.15em; }

/* Same class of bug as .text-bg-warning above, different shape: Bootstrap
   hardcodes .text-bg-light's TEXT colour to `#000 !important` at build
   time, while its *background* correctly reads --bs-light-rgb (which this
   file deliberately repurposes to a dark neutral in dark mode — see that
   section's own comment). Light mode's --bs-light is a light kraft tone,
   so black text there is fine; dark mode's is a dark brown, so the same
   hardcoded black text renders as black-on-near-black — invisible. Unlike
   warning (which always needs white regardless of theme), light's
   background actually flips per theme, so the fix reads --ink (which
   already flips dark/light in step with it) rather than a fixed colour. */
.text-bg-light {
  color: var(--ink) !important;
}

/* .text-bg-secondary / .text-bg-dark ("Inactive" badges, cancelled/
   revised status pills, etc. — widely used across doctors/patients/
   clinics/appointments/prescriptions) — same root cause again, but the
   fix shape is different from .text-bg-light's: here it's the
   *background* that's brightened in dark mode (--bs-secondary and
   --bs-dark both intentionally swap toward light tones there, same
   "light/dark semantic pair swaps meaning" logic as --bs-light/--bs-dark
   generally), while Bootstrap's hardcoded white badge text stays white —
   verified by hand at ~2.4:1 and ~1.2:1 against those two dark-mode
   backgrounds respectively, both well under the 4.5:1 floor this file
   holds everywhere else. --ink doesn't fix this one (it flips the same
   direction badly needed here), so this uses --paper instead, which is
   dark in dark mode — verified ~7.7:1 against dark-mode --bs-secondary,
   and stays white in light mode where these badges are already fine. */
.text-bg-secondary,
.text-bg-dark {
  color: #fff !important;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme="light"]) .text-bg-secondary,
  :root:not([data-bs-theme="light"]) .text-bg-dark {
    color: var(--paper) !important;
  }
}
:root[data-bs-theme="dark"] .text-bg-secondary,
:root[data-bs-theme="dark"] .text-bg-dark {
  color: var(--paper) !important;
}

#patient-quick-search-results .list-group {
  border: 1px solid var(--line);
  border-radius: var(--bs-border-radius);
  overflow: hidden;
}
#patient-quick-search-results .list-group-item {
  border-color: var(--line);
}
#patient-quick-search-results .list-group-item:hover {
  background: var(--tint-green);
}

/* -----------------------------------------------------------------------
   Auth screens
   ----------------------------------------------------------------------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  background: var(--paper);
}

.auth-hero {
  flex: 1 1 44%;
  /* Both gradient stops stay dark enough that the white/near-white hero
     text (below) keeps its contrast margin throughout — the "richer, not
     riskier" rule this whole colour pass follows: see .btn-primary's
     comment for why the same trick isn't used on button text instead. */
  background: linear-gradient(160deg, var(--pharmacy-deep) 0%, #0A1518 100%);
  color: #EAF2F3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4rem;
  position: relative;
  overflow: hidden;
}

.auth-hero .rx-watermark {
  position: absolute;
  right: -3rem;
  bottom: -4rem;
  font-family: var(--font-display);
  font-size: 26rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.05);
  pointer-events: none;
  user-select: none;
}

.auth-hero h1 {
  font-size: 2.6rem;
  color: #fff;
  max-width: 14ch;
  margin-bottom: 1rem;
}

.auth-hero p {
  font-size: 1.05rem;
  color: #B7CBD0;
  max-width: 34ch;
  line-height: 1.6;
}

.auth-panel {
  flex: 1 1 56%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card { max-width: 380px; width: 100%; }

@media (max-width: 900px) {
  .auth-shell { flex-direction: column; }
  .auth-hero { padding: 2.5rem 2rem; }
  .auth-hero h1 { font-size: 1.9rem; }
  .auth-hero .rx-watermark { font-size: 14rem; right: -2rem; bottom: -3rem; }
}

/* -----------------------------------------------------------------------
   Prescription builder — drag-and-drop reordering (SortableJS progressive
   enhancement over the Up/Down buttons; spec §13).
   ----------------------------------------------------------------------- */

.drag-handle {
  cursor: grab;
  padding-top: 0.2rem;
  font-size: 1.1rem;
  touch-action: none;
}
.sortable-item.sortable-ghost { opacity: 0.4; }
.sortable-item.sortable-drag { cursor: grabbing; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15); }

/* -----------------------------------------------------------------------
   Accessibility floor — visible keyboard focus everywhere, motion respected.
   ----------------------------------------------------------------------- */

a:focus-visible, button:focus-visible, .btn:focus-visible,
.nav-link:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--pharmacy);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* -----------------------------------------------------------------------
   Which facility this session is scoped to (templates/base.html).

   Every record a clinic administrator can reach is scoped to one of
   ~14,000 facilities, and the account name alone does not say which. So
   it is named in the top bar, next to the account, not inside a
   dropdown. Truncates rather than wraps: the full name is in `title`,
   and a facility name is allowed to be long ("Kuwait Bangladesh
   Friendship Govt. Hospital") without pushing the top bar around.
   ----------------------------------------------------------------------- */

.app-clinic {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  /* No pill. A bordered chip around it truncated the name at 28ch, which
     on "Kuwait Bangladesh Friendship Govt. Hospital" cut exactly the part
     that tells one facility from another — and the icon already says this
     is a place. The name gets the room instead; the container is what
     truncates, and only when the top bar genuinely runs out. */
  min-width: 0;
  max-width: 42ch;
  color: var(--ink-muted);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.4;
}
.app-clinic i { flex: none; font-size: 0.82rem; opacity: 0.65; }
.app-clinic-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-clinic-more { flex: none; font-weight: 500; opacity: 0.7; }

@media (max-width: 1400px) {
  .app-clinic { max-width: 26ch; }
}

/* -----------------------------------------------------------------------
   Account menu (templates/base.html).

   The toggle (name + role) stays at the inherited .small — it was taken
   to 80% and read as too small next to the facility name, so it is back
   at the standard scale. The menu items get a slightly tighter rhythm
   than Bootstrap's default, which is all this block is for now.
   ----------------------------------------------------------------------- */

.app-user-menu .dropdown-item { font-size: 0.8rem; padding-top: 0.3rem; padding-bottom: 0.3rem; }

/* =======================================================================
   Message toasts
   templates/core/partials/message_toasts.html

   Django's `messages` used to render as `alert alert-dismissible` at the
   top of the main column, in three near-identical copies — the staff
   shell, the patient portal and the public portal. Two problems with
   that, and both are behavioural rather than cosmetic: the banner pushed
   the page down as it appeared, so whatever somebody was about to click
   moved under their cursor; and on a long screen a message about what
   just happened was drawn above content they had already scrolled past,
   which is the same as not showing it.

   A fixed stack is read where the eye already is and costs the layout
   nothing. Bottom-end on a wide screen, where it clears both the sidebar
   and the topbar; a full-width strip at the bottom on a phone, where
   there is no room to inset it and the thumb is already down there.
   ======================================================================= */

.toast-stack {
  position: fixed;
  z-index: 1090; /* above Bootstrap's modal backdrop (1050) and sticky bars */
  inset-block-end: 1rem;
  inset-inline-end: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(26rem, calc(100vw - 2rem));
  /* The stack is only a layout box; clicks belong to the toasts in it, so
     the gaps between them must not swallow a click on the page beneath. */
  pointer-events: none;
}
.toast-stack > .toast { pointer-events: auto; }

.pub-toast {
  /* Bootstrap's own toast surface reads from --bs-* and lands warm-on-warm
     in this app's palette. These are the app's own tokens, with a coloured
     leading edge carrying the level — a border, not a background wash, so
     the text keeps body contrast at every level. */
  background: var(--surface, #fff);
  color: var(--ink);
  border: 1px solid var(--line, rgba(0, 0, 0, 0.1));
  border-inline-start: 4px solid var(--ink-muted);
  border-radius: 0.65rem;
  box-shadow: 0 8px 24px rgba(18, 24, 38, 0.18);
  font-size: 0.88rem;
}
.pub-toast .toast-body { padding: 0.7rem 0.8rem; }
.pub-toast-icon { font-size: 1rem; line-height: 1.35; }

/* The level, on the edge and on the icon only. Four hues that already mean
   these four things everywhere else in the app — see app.css's token
   block — rather than a fifth set invented for toasts. */
.pub-toast.success { border-inline-start-color: var(--pharmacy); }
.pub-toast.success .pub-toast-icon { color: var(--pharmacy); }
.pub-toast.warning { border-inline-start-color: var(--amber); }
.pub-toast.warning .pub-toast-icon { color: var(--amber); }
.pub-toast.error { border-inline-start-color: var(--alert); }
.pub-toast.error .pub-toast-icon { color: var(--alert); }
.pub-toast.info,
.pub-toast.debug { border-inline-start-color: var(--blue-mid, #1E5FA8); }
.pub-toast.info .pub-toast-icon,
.pub-toast.debug .pub-toast-icon { color: var(--blue-mid, #1E5FA8); }

@media (max-width: 575.98px) {
  .toast-stack {
    inset-inline: 0.5rem;
    inset-block-end: 0.5rem;
    width: auto;
  }
}

/* Type-to-search select (static/js/search-select.js) */
.ss { position: relative; }
.ss-input { padding-right: 2.2rem; }
.ss-icon { position: absolute; top: 50%; right: 0.8rem; transform: translateY(-50%); color: var(--bs-secondary-color); pointer-events: none; }
.ss-list { position: absolute; z-index: 1056; top: calc(100% + 0.25rem); left: 0; right: 0; max-height: 17rem; margin: 0; padding: 0.3rem; overflow-y: auto; list-style: none; border: 1px solid var(--bs-border-color); border-radius: 0.7rem; background: var(--bs-body-bg); box-shadow: 0 14px 30px -12px rgba(0, 0, 0, 0.35); }
.ss-list li { display: flex; flex-direction: column; padding: 0.45rem 0.65rem; border-radius: 0.5rem; cursor: pointer; }
.ss-list li.active, .ss-list li:hover { background: color-mix(in srgb, var(--bs-primary) 14%, var(--bs-body-bg)); }
.ss-list .ss-text { font-weight: 600; }
.ss-list .ss-sub { color: var(--bs-secondary-color); font-size: 0.75rem; }
.ss-list .ss-none { cursor: default; color: var(--bs-secondary-color); }

/* Staff top bar account menu: the name is a button with a caret, and Logout
   lives inside it. */
.app-user-trigger { max-width: 18rem; }
.app-user-trigger .app-user-caret { font-size: 0.7rem; opacity: 0.7; transition: transform 0.15s; }
.app-user-trigger[aria-expanded="true"] .app-user-caret { transform: rotate(180deg); }
.app-user-dropdown { min-width: 15rem; padding-bottom: 0.35rem; }
.app-user-head { padding: 0.5rem 1rem 0.35rem; }
@media (prefers-reduced-motion: reduce) { .app-user-trigger .app-user-caret { transition: none; } }

/* Staff app text size, +10%. app.css is shared with the patient portal and
   print pages, so this applies only to a page that carries the staff
   sidebar/top bar. Everything is rem-based, so raising the root scales the
   content, sidebar and top bar together; the sidebar's fixed width grows with
   it so the labels keep their room. */
html:has(.app-sidebar, .app-topbar) { font-size: 110%; }
@media (min-width: 992px) {
  html:has(.app-sidebar) .app-sidebar { width: 236px; }
}

/* A filter row whose small input and small buttons must share one height, so
   they line up on the same top and bottom edge. */
.filter-row .form-control-sm,
.filter-row .btn-sm { height: 2.1rem; display: inline-flex; align-items: center; }
.filter-row .form-control-sm { display: block; }

/* Patient Documents tab */
.docs-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; }
@media (max-width: 991.98px) { .docs-grid { grid-template-columns: 1fr; } }
.docs-card { padding: 0.9rem 1rem; border: 1px solid var(--bs-border-color); border-radius: var(--bs-border-radius-lg, 0.5rem); background: var(--bs-body-bg); }
.docs-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.7rem; }
.docs-title { display: flex; align-items: center; gap: 0.45rem; margin: 0; font-size: 1rem; font-weight: 800; }
.docs-title .bi { color: var(--bs-primary); }
.docs-count { padding: 0.05rem 0.5rem; border-radius: 999px; background: var(--bs-tertiary-bg); font-size: 0.72rem; font-weight: 700; color: var(--bs-secondary-color); }
.docs-search { position: relative; margin-bottom: 0.6rem; }
.docs-search .bi { position: absolute; top: 50%; left: 0.7rem; transform: translateY(-50%); color: var(--bs-secondary-color); pointer-events: none; }
.docs-search input[type="search"] { padding-left: 2rem; border-radius: 999px; }
.docs-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.6rem; }
.docs-chip { padding: 0.2rem 0.65rem; border: 1px solid var(--bs-border-color); border-radius: 999px; background: transparent; color: var(--bs-body-color); font-size: 0.74rem; font-weight: 700; }
.docs-chip:hover { background: var(--bs-tertiary-bg); }
.docs-chip.active { border-color: var(--bs-primary); background: var(--bs-primary); color: #fff; }
.docs-chip-n { margin-left: 0.2rem; opacity: 0.75; font-variant-numeric: tabular-nums; }
.docs-list { margin: 0; padding: 0; list-style: none; }
.docs-item { display: flex; align-items: flex-start; gap: 0.7rem; padding: 0.6rem 0; border-top: 1px solid var(--bs-border-color); }
.docs-item:first-child { border-top: 0; }
.docs-ic { --tone: #6B7B8C; display: grid; place-items: center; flex: none; width: 2.1rem; height: 2.1rem; border-radius: 0.6rem; background: color-mix(in srgb, var(--tone) 16%, var(--bs-body-bg)); color: var(--tone); font-size: 1.05rem; }
.docs-ic-pdf { --tone: #D6453D; } .docs-ic-image { --tone: #2E9157; } .docs-ic-word { --tone: #2F6FC4; } .docs-ic-sheet { --tone: #1F8A5B; }
.docs-ic-cert { --tone: #B8860B; } .docs-ic-ref { --tone: #7D4F9E; }
.docs-body { flex: 1; min-width: 0; }
.docs-name { display: block; overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.docs-name:hover { text-decoration: underline; }
.docs-meta { font-size: 0.74rem; color: var(--bs-secondary-color); }
.docs-cat { display: inline-block; margin-right: 0.35rem; padding: 0 0.45rem; border-radius: 999px; background: var(--bs-tertiary-bg); font-weight: 700; }
.docs-notes { margin-top: 0.15rem; font-size: 0.76rem; color: var(--bs-secondary-color); }
.docs-actions { display: flex; gap: 0.3rem; flex: none; }
.docs-actions .btn { width: 2rem; height: 2rem; padding: 0; display: inline-grid; place-items: center; }
.docs-empty { display: flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 1.4rem 1rem; border: 2px dashed var(--bs-border-color); border-radius: var(--bs-border-radius-lg, 0.5rem); color: var(--bs-secondary-color); }
.docs-pager { display: flex; align-items: center; justify-content: space-between; margin-top: 0.6rem; font-size: 0.76rem; color: var(--bs-secondary-color); }

/* Automatic / manual password choice (portal account create + reset) */
.pw-choice { border: 0; padding: 0; margin: 0; }
.pw-choice .pw-manual { display: none; max-width: 32rem; }
.pw-choice:has(#pw-mode-manual:checked) .pw-manual { display: flex; }

/* -----------------------------------------------------------------------
   Scrollbars: thin and in the brand teal, readable in both themes.

   Standard properties only. Chrome and Firefox both honour them, and once they
   are set Chrome ignores `::-webkit-scrollbar`, so a second set of rules would
   do nothing. `scrollbar-color` inherits, so setting it on the page reaches
   every scrolling panel (tables, modals, lists). The width does not inherit,
   hence the universal rule below. The thumb is 80% of --rd-teal, which is
   tuned separately for light and dark, over the page ground: at least 3:1
   against the page in both. The sidebar keeps its own pale-on-dark bar above.
   ----------------------------------------------------------------------- */
html {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--rd-teal) 80%, var(--paper)) transparent;
}
/* `scrollbar-width` does not inherit, so every scroll container needs it. */
* {
  scrollbar-width: thin;
}

/* A one-line stat: icon, label and a number in a single small pill, for a
   row of counts that should not take a row of cards. The left rail follows the
   same rule as a tile: amber or red only when something needs doing. */
.stat-chip {
  --rail: var(--pharmacy);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.18rem 0.65rem 0.18rem 0.5rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--rail);
  border-radius: var(--bs-border-radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.76rem;
  line-height: 1.3;
  text-decoration: none;
}
.stat-chip.is-amber { --rail: var(--amber); }
.stat-chip.is-alert { --rail: var(--alert); }
.stat-chip .bi { color: var(--ink-muted); font-size: 0.9rem; }
.stat-chip b { font-family: var(--font-mono); font-size: 0.95rem; font-weight: 600; }
a.stat-chip:hover { border-color: var(--pharmacy); }
/* A thin version of the status bar, when it is a hint and not the headline. */
.flow-bar.flow-bar-slim { height: 0.3rem; }

/* -----------------------------------------------------------------------
   Breadcrumb (templates/base.html, core/breadcrumbs.py). Replaces the old
   "Back" button: it says where you are and gives a way up that does not depend
   on how you arrived. One quiet line; the current page is the only bold crumb.
   On a phone it shrinks to a single "‹ Parent" link, which is what a Back
   button was for, but pointing at the parent and not at history.
   ----------------------------------------------------------------------- */
.app-breadcrumb { margin: 0 0 0.7rem; font-size: 0.78rem; }
.app-breadcrumb ol {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
}
.app-breadcrumb li {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
  color: var(--ink-muted);
}
.app-breadcrumb li + li::before {
  content: "›";
  margin: 0 0.4rem;
  opacity: 0.7;
}
.app-breadcrumb a {
  padding: 0.15rem 0.3rem;
  border-radius: var(--bs-border-radius-sm);
  color: var(--ink-muted);
  text-decoration: none;
}
.app-breadcrumb a:hover { color: var(--pharmacy); background: var(--tint-green); }
.app-breadcrumb li.is-current { min-width: 0; color: var(--ink); font-weight: 600; }
.app-breadcrumb li.is-current > span { overflow: hidden; text-overflow: ellipsis; max-width: 40ch; }
@media (max-width: 575.98px) {
  .app-breadcrumb li:not(:nth-last-child(2)) { display: none; }
  .app-breadcrumb li:nth-last-child(2)::before { content: "‹"; margin: 0 0.3rem 0 0; opacity: 1; }
}

/* The clinic directory's area filters (division, district, upazila, thana, union)
   share one line: equal-width small selects that shrink to fit, with the
   clear link at the end. They only wrap on a narrow screen. */
.area-filters { display: flex; flex-wrap: nowrap; align-items: center; gap: 0.4rem; }
.area-filter { flex: 1 1 0; min-width: 0; }
.area-filter .form-select { text-overflow: ellipsis; }
.area-filter-clear { flex: none; font-size: 0.74rem; }
@media (max-width: 991.98px) {
  .area-filters { flex-wrap: wrap; }
  .area-filter { flex: 1 1 calc(50% - 0.4rem); }
}


/* Patient Overview: small charts need a fixed height or Chart.js collapses them. */
.overview-chart-box { position: relative; height: 10rem; }
/* Each trend card carries its own hue as a top rule and in its big number. */
.overview-trend { --tone: var(--pharmacy); border-top: 4px solid var(--tone); }
.overview-trend-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.6rem; }
.overview-trend-value { font-size: 1.35rem; font-weight: 700; color: var(--tone); line-height: 1; }
.overview-trend-value small { font-size: 0.7rem; font-weight: 600; color: var(--ink-muted); }
.overview-trend-foot { margin-top: 0.5rem; }


/* Patient Overview: a single compact line of coloured tiles. Each tile takes one
   categorical hue (the --rd-* chart colours) for its top rule, icon and number.
   Phones show two to a row; from 700px up they all stay on one line. */
.ov-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; margin-bottom: 1rem; }
@media (min-width: 700px) { .ov-tiles { grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr)); } }
.ov-tile {
  --tone: var(--pharmacy);
  display: flex; align-items: center; gap: 0.55rem; min-width: 0;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line); border-top: 3px solid var(--tone); border-radius: 0.5rem;
  background: color-mix(in srgb, var(--tone) 7%, var(--surface));
  color: var(--ink); text-decoration: none; position: relative;
}
a.ov-tile:hover { background: color-mix(in srgb, var(--tone) 14%, var(--surface)); color: var(--ink); }
.ov-tile[data-tone="teal"] { --tone: var(--rd-teal, #0B7A83); } .ov-tile[data-tone="rose"] { --tone: var(--rd-rose, #B03060); }
.ov-tile[data-tone="violet"] { --tone: var(--rd-violet, #6B5BA8); } .ov-tile[data-tone="blue"] { --tone: var(--rd-blue, #2B6CB0); }
.ov-tile[data-tone="orange"] { --tone: var(--rd-orange, #B24A12); } .ov-tile[data-tone="green"] { --tone: var(--rd-green, #2F7D4F); }
.ov-tile-ic {
  flex: none; display: grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 0.5rem;
  background: color-mix(in srgb, var(--tone) 18%, transparent); color: var(--tone); font-size: 1rem;
}
.ov-tile-body { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.ov-tile-label, .ov-tile-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.68rem; color: var(--ink-muted); }
.ov-tile-label { font-weight: 700; }
.ov-tile-value { font-size: 1.15rem; font-weight: 700; color: var(--tone); }
/* Something is waiting on someone: a small dot in the corner, not a different colour. */
.ov-tile-attn::after { content: ""; position: absolute; top: 0.4rem; right: 0.4rem; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--amber); }


/* A card with a coloured top rule, same hues as the Overview tiles. */
.ov-card { --tone: var(--rd-teal, #0B7A83); border-top: 3px solid var(--tone); }
.ov-card[data-tone="teal"] { --tone: var(--rd-teal, #0B7A83); } .ov-card[data-tone="rose"] { --tone: var(--rd-rose, #B03060); }
.ov-card[data-tone="violet"] { --tone: var(--rd-violet, #6B5BA8); } .ov-card[data-tone="blue"] { --tone: var(--rd-blue, #2B6CB0); }
.ov-card[data-tone="orange"] { --tone: var(--rd-orange, #B24A12); } .ov-card[data-tone="green"] { --tone: var(--rd-green, #2F7D4F); }
.ov-card > .card-header { font-weight: 700; color: var(--tone); }


/* A highlighted "who is this about" banner at the top of an account screen. */
.patient-banner {
  --tone: var(--rd-teal, #0B7A83);
  display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap;
  padding: 0.8rem 1rem;
  border: 1px solid var(--line); border-left: 6px solid var(--tone); border-radius: 0.5rem;
  background: color-mix(in srgb, var(--tone) 10%, var(--surface));
}
.patient-banner-label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); }
.patient-banner-name { font-size: 1.35rem; font-weight: 700; line-height: 1.2; color: var(--ink); text-decoration: none; }
a.patient-banner-name:hover { color: var(--tone); text-decoration: underline; }
.patient-banner-id {
  margin-left: auto; padding: 0.25rem 0.7rem; border-radius: 999px; font-weight: 700; font-size: 0.9rem;
  color: var(--tone); background: color-mix(in srgb, var(--tone) 16%, transparent); border: 1px solid var(--tone);
}


/* A compact dropdown: the select counterpart of `.field-compact`. 1.8rem tall, small
   text, a smaller arrow, and still a normal rounded box (not a pill) so a row of
   them reads as a tidy filter strip. Use with `form-select form-select-sm`. */
.select-compact {
  height: 1.8rem;
  min-height: 0;
  padding: 0 1.55rem 0 0.55rem;
  font-size: 0.74rem;
  line-height: 1.2;
  background-size: 11px 8px;
  background-position: right 0.5rem center;
}

/* Documents tab: sit the "Uploaded files" card right under the tab bar. The tab bar
   already leaves 1rem and the shared sky-panel pane adds another 1rem above its content;
   here the pane gives up its own padding and pulls up a little, so about 0.35rem remains. */
.sky-panel .tab-content > #tab-documents { padding-top: 0; margin-top: -0.65rem; }


/* A collapse toggle that shows its state: the text and icon swap, and the open
   button is filled so it reads as "on". Needs aria-expanded on the button. */
.more-toggle[aria-expanded="false"] .when-open,
.more-toggle[aria-expanded="true"] .when-closed { display: none; }
.more-toggle[aria-expanded="true"] {
  background: var(--tint-green);
  border-color: var(--pharmacy);
  color: var(--pharmacy);
  font-weight: 600;
}

/* Pharmacy medicine labels: a grid on screen, one 70 x 45 mm label per sticker on paper. */
.med-label-sheet { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.med-label {
  width: 70mm;
  min-height: 45mm;
  padding: 3mm;
  border: 1px solid var(--line);
  border-radius: var(--bs-border-radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78rem;
  line-height: 1.3;
  break-inside: avoid;
}
.med-label-clinic { color: var(--ink-muted); font-size: 0.68rem; }
.med-label-medicine { font-size: 0.95rem; font-weight: 600; margin: 0.15rem 0; }
.med-label-directions { font-weight: 600; }
.med-label-foot { display: flex; flex-wrap: wrap; gap: 0.25rem 0.6rem; margin-top: 0.3rem; padding-top: 0.25rem; border-top: 1px solid var(--line); color: var(--ink-muted); font-size: 0.68rem; }
@media print {
  .med-label-sheet { gap: 0; }
  .med-label { border-radius: 0; border-color: currentColor; break-after: page; }
}

/* Clinical warning: one look in the prescription builder and at the pharmacy counter. Allergy
   (danger) uses --alert, a duplicate-therapy note (warning) uses --amber. Sticky in the builder so it
   stays in view from every tab. */
.clinical-warning {
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: 0.6rem 0.8rem; margin-bottom: 0.5rem;
  border: 1px solid var(--alert); border-left-width: 5px; border-radius: var(--bs-border-radius);
  background: var(--tint-red); color: var(--ink); font-size: 0.85rem;
}
.clinical-warning > .bi { color: var(--alert); font-size: 1.15rem; line-height: 1.2; }
.clinical-warning strong { display: block; }
.clinical-warning-warning { border-color: var(--amber); background: var(--tint-amber); }
.clinical-warning-warning > .bi { color: var(--amber); }
.rx-warnings-sticky { position: sticky; top: 0.5rem; z-index: 5; }
.rx-warnings-sticky:empty { display: none; }

/* Shelf meter: stock against the reorder level, full at twice the level, with a tick at the level itself. */
.stock-meter { position: relative; height: 4px; min-width: 4.5rem; margin-top: 4px; border-radius: 2px; background: var(--line); }
.stock-meter > span { display: block; height: 100%; border-radius: 2px; background: var(--pharmacy); }
.stock-meter::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--ink-muted); }
.stock-meter-low > span { background: var(--amber); }
.stock-meter-out > span, .stock-meter-expired > span { background: var(--alert); }

/* Large KPI tile: the tile's own hue (data-tone) on its numeral and bar, a line of context under the number. */
.tile-lg .card-body { padding: 0.5rem 0.8rem; }
.tile-lg .icon-tile { width: 2.3rem; height: 2.3rem; font-size: 1.05rem; }
.tile-figure { color: var(--tone, var(--ink)); font-family: var(--font-mono); font-size: 1.45rem; font-weight: 600; line-height: 1.05; }
.tile-bar { height: 3px; background: var(--line); border-radius: 0 0 var(--bs-border-radius) var(--bs-border-radius); overflow: hidden; }
.tile-bar > span { display: block; height: 100%; background: var(--tone, var(--pharmacy)); }
/* Large tiles must stand out in both themes: a surface tinted with the tile's hue, a hue border, and a
   stronger icon disc. (The plain tile surface is nearly the page colour in dark mode.) */
.vib-row.vib-row .card.tile-lg {
  background: color-mix(in srgb, var(--tone) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--tone) 40%, var(--line));
}
.vib-row.vib-row .card.tile-lg.tab-brand { --rail: var(--tone); }
.vib-row.vib-row .card.tile-lg[data-tone] .icon-tile {
  background: color-mix(in srgb, var(--tone) 26%, var(--surface));
  color: var(--tone);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 50%, transparent);
}
.vib-row.vib-row .tile-lg .chart-label { color: var(--ink) !important; opacity: 0.85; }
.tile-lg .tile-bar { background: color-mix(in srgb, var(--tone) 18%, var(--line)); }
.tile-sub { font-size: 0.72rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Purchase order lines: a table built from a grid so each draft row can be its own form. The header row
   labels every column; the column set follows what is shown (cost columns only with "Show costs"). */
.po-grid { --po-cols: minmax(0, 1fr) 9.6rem 2.2rem; font-size: 0.84rem; }
.po-grid.po-grid-cost { --po-cols: minmax(0, 1fr) 9.6rem 7.4rem 6.2rem 2.2rem; }
.po-grid.po-grid-read { --po-cols: minmax(0, 1fr) 10rem; }
.po-grid.po-grid-read.po-grid-cost { --po-cols: minmax(0, 1fr) 10rem 6.2rem; }
.po-row { position: relative; display: grid; grid-template-columns: var(--po-cols); gap: 0.5rem; align-items: center; padding: 0.4rem 0.8rem; border-bottom: 1px solid var(--line); }
.po-row:last-child { border-bottom: 0; }
.po-head > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.po-head { background: var(--tint-green); border-bottom: 2px solid var(--pharmacy); color: var(--ink-muted); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.po-qty { display: flex; align-items: center; gap: 0.25rem; }
.po-qty .form-control { width: 4.2rem; }
.po-num { text-align: right; font-family: var(--font-mono); }
.stock-meter-plain::after { content: none; }

/* -----------------------------------------------------------------------
   Prescription builder — one page of numbered steps (workspace.html).
   Colour comes from the brand tokens only: the step numbers, selected chips
   and the action bar carry the teal; nothing else is tinted.
   ----------------------------------------------------------------------- */
.rx-steps { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; position: sticky; top: 0; z-index: 4; padding: 0.4rem 0; background: var(--paper); }
.rx-steps a { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0.7rem 0.25rem 0.3rem; border: 1px solid var(--line); border-radius: 2rem; background: var(--surface); color: var(--ink); font-size: 0.78rem; text-decoration: none; }
.rx-steps a:hover { border-color: var(--pharmacy); color: var(--pharmacy); }
.rx-steps kbd, .rx-section kbd { font-size: 0.65rem; padding: 0.05rem 0.3rem; background: var(--tint-green); color: var(--ink-muted); border-radius: 0.25rem; }
.rx-step-no { display: inline-grid; place-items: center; width: 1.35rem; height: 1.35rem; border-radius: 50%; background: var(--pharmacy); color: var(--bs-white); font-size: 0.72rem; font-weight: 700; flex-shrink: 0; }
.rx-section { padding: 1rem 1.1rem; margin-bottom: 1rem; scroll-margin-top: 3.5rem; }
.rx-section-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.75rem; }
.rx-section-head h2 { font-size: 1rem; font-weight: 700; margin: 0; }
.rx-dx { display: inline-flex; align-items: baseline; gap: 0.4rem; padding: 0.25rem 0.7rem; border: 1px solid var(--line); border-radius: 2rem; background: var(--surface); font-size: 0.82rem; }
.rx-dx small { color: var(--ink-muted); font-size: 0.7rem; }
.rx-dx-primary { border-color: var(--pharmacy); background: var(--tint-green); font-weight: 600; }
.rx-search { border-color: var(--pharmacy); }
.rx-item { border-left: 4px solid var(--pharmacy); }
.rx-item-no { display: inline-grid; place-items: center; min-width: 1.4rem; height: 1.4rem; border-radius: 0.3rem; background: var(--tint-green); color: var(--ink); font-weight: 700; font-size: 0.75rem; }
.rx-row { display: flex; flex-wrap: wrap; gap: 0.6rem 1.4rem; align-items: flex-start; }
.rx-row { gap: 0.6rem; }
.rx-field { min-width: 0; }
/* Each field is its own labelled box (icon + heading), so a basic user can tell Dose, Meal, Days and Qty apart at a glance. */
.rx-box { border: 1px solid var(--line); border-radius: var(--bs-border-radius); background: var(--paper); padding: 0.4rem 0.6rem 0.55rem; }
.rx-field-qty { width: 6rem; }
.rx-label { display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.4rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--line); font-size: 0.82rem; font-weight: 700; color: var(--ink); }
/* Field icons: one hue per concept, the same in the builder, the template editor and the AI results, on a soft
   tinted disc. Blue, violet, indigo, cyan, magenta and slate only: red, amber and green stay reserved for clinical
   status (docs/BRAND_VOICE.md), and the sidebar keeps its one quiet icon colour. Each is >= 4.5:1 on its own disc. */
:root {
  --ic-teal: var(--pharmacy); --ic-blue: #1D4ED8; --ic-violet: #6D28D9; --ic-indigo: #4338CA;
  --ic-cyan: #0B647B; --ic-magenta: #A21CAF; --ic-slate: #475569;
}
:root[data-bs-theme="dark"] {
  --ic-teal: #5FD0C4; --ic-blue: #8FB0FF; --ic-violet: #BDA3FF; --ic-indigo: #A5ADFF;
  --ic-cyan: #67D4E8; --ic-magenta: #F0A0FA; --ic-slate: #B4C0CD;
}
.rx-label .bi, .rx-more > summary .bi {
  --ic: var(--ic-teal);
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  font-size: 0.9rem; color: var(--ic);
  background: color-mix(in srgb, var(--ic) 15%, transparent);
}
.rx-label .bi-capsule { --ic: var(--ic-blue); }
.rx-label .bi-egg-fried { --ic: var(--ic-violet); }
.rx-label .bi-calendar-week, .rx-label .bi-calendar-check { --ic: var(--ic-indigo); }
.rx-label .bi-box-seam, .rx-more > summary .bi-sliders { --ic: var(--ic-slate); }
.rx-label .bi-chat-left-text { --ic: var(--ic-cyan); }
.rx-label .bi-eyedropper { --ic: var(--ic-magenta); }
.rx-label .bi-clipboard2-pulse, .rx-label .bi-plus-circle { --ic: var(--ic-teal); }
.rx-more { border: 1px dashed var(--pharmacy); border-radius: var(--bs-border-radius); padding: 0.35rem 0.7rem; }
.rx-more[open] { background: var(--paper); }
.rx-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.rx-chip { border-radius: 2rem; padding: 0.2rem 0.75rem; font-size: 0.82rem; }
.rx-chip.btn-secondary { --bs-btn-bg: var(--pharmacy); --bs-btn-border-color: var(--pharmacy); --bs-btn-color: var(--bs-white); --bs-btn-hover-bg: var(--pharmacy-deep); --bs-btn-hover-border-color: var(--pharmacy-deep); --bs-btn-hover-color: var(--bs-white); --bs-btn-active-bg: var(--pharmacy-deep); --bs-btn-active-color: var(--bs-white); }
.rx-more > summary { cursor: pointer; font-size: 0.82rem; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 0.35rem; }
.rx-actionbar { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; gap: 1rem; padding: 0.7rem 1rem; margin-top: 0.5rem; background: var(--surface); border: 1px solid var(--pharmacy); border-left-width: 5px; border-radius: var(--bs-border-radius); box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.08); }
.rx-ai { border-left: 5px solid var(--pharmacy); overflow: hidden; }
.rx-ai-head { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin: -1rem -1.1rem 0; padding: 0.8rem 1.1rem; background: var(--tint-green); border-bottom: 1px solid var(--line); }
.rx-ai-head h2 { font-size: 1.05rem; font-weight: 700; margin: 0; }
.rx-ai-head p { margin: 0; font-size: 0.78rem; color: var(--ink-muted); }
.rx-ai-disc { display: inline-grid; place-items: center; width: 2.4rem; height: 2.4rem; border-radius: 50%; background: var(--pharmacy); color: var(--bs-white); font-size: 1.2rem; flex-shrink: 0; }
.rx-ai-pill { padding: 0.15rem 0.7rem; border: 1px solid var(--amber); border-radius: 2rem; background: var(--tint-amber); color: var(--ink); font-size: 0.72rem; font-weight: 600; }
.rx-ai-summary { margin: 1rem 0 0.75rem; padding: 0.55rem 0.8rem; border-left: 3px solid var(--pharmacy); background: var(--paper); font-size: 0.85rem; }
.rx-chat-thread { max-height: 22rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; padding: 0.6rem; margin-bottom: 0.6rem; border: 1px solid var(--line); border-radius: var(--bs-border-radius); background: var(--paper); }
.rx-bubble { max-width: 88%; padding: 0.45rem 0.75rem; border-radius: 0.75rem; font-size: 0.84rem; line-height: 1.45; border: 1px solid var(--line); }
.rx-bubble-who { display: block; margin-bottom: 0.1rem; font-size: 0.68rem; font-weight: 700; color: var(--ink-muted); }
.rx-bubble-me { align-self: flex-end; background: var(--tint-green); border-color: var(--pharmacy); border-bottom-right-radius: 0.2rem; }
.rx-bubble-ai { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 0.2rem; }
.rx-chat-empty { display: flex; gap: 0.6rem; align-items: center; color: var(--ink-muted); font-size: 0.82rem; }
.rx-chat-empty .bi { font-size: 1.4rem; color: var(--pharmacy); }
.rx-thinking { display: none; color: var(--ink-muted); }
.rx-thinking.htmx-request { display: block; }
.rx-date-set { border-color: var(--pharmacy); background: var(--tint-green); font-weight: 600; }
.rx-page { display: block; width: 100%; height: 62rem; border: 1px solid var(--line); border-radius: var(--bs-border-radius); background: #fff; }
@media (max-width: 767.98px) {
  .rx-steps { position: static; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.5rem; }
  .rx-steps a { flex-shrink: 0; }
  .rx-steps kbd, .rx-section kbd { display: none; }
  .rx-actionbar > span { display: none; }
  .rx-actionbar { justify-content: flex-end; }
  .rx-section { scroll-margin-top: 0.5rem; }
}

/* The builder swaps #items-panel (and resets its open "Custom" boxes) after every edit. Left alone, the browser's
   scroll anchoring re-pins the page to something far below, so it jumped to the Preview on each dose change. */
.rx-section { overflow-anchor: none; transition: border-color 0.15s ease, box-shadow 0.15s ease; }

/* The step the doctor is working in: where focus is, otherwise the one nearest the middle of the screen. */
.rx-section.rx-current { border-color: var(--pharmacy); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pharmacy) 28%, transparent); }
.rx-steps a { transition: background-color 0.15s ease, color 0.15s ease; }
.rx-steps a.rx-current { background: var(--pharmacy); border-color: var(--pharmacy); color: var(--bs-white); font-weight: 600; }
.rx-steps a.rx-current .rx-step-no { background: var(--bs-white); color: var(--pharmacy); }
.rx-steps a.rx-current kbd { background: var(--pharmacy-deep); color: var(--bs-white); }
.rx-note { display: flex; gap: 0.5rem; align-items: flex-start; margin-bottom: 0.75rem; padding: 0.45rem 0.75rem; border: 1px solid var(--line); border-left: 4px solid var(--pharmacy); border-radius: var(--bs-border-radius); background: var(--tint-green); color: var(--ink); font-size: 0.84rem; }
.rx-note .bi { color: var(--pharmacy); margin-top: 0.1rem; }
.rx-note-error { border-left-color: var(--alert); background: var(--tint-red); }
.rx-note-error .bi { color: var(--alert); }

/* File fields ("Currently: <long/path/name.jpg> [ ] Clear  Change: [Choose file]") must wrap inside their card, not run past it. */
.field-file { min-width: 0; font-size: 0.78rem; color: var(--ink-muted); overflow-wrap: anywhere; }
.field-file a { word-break: break-all; }
.field-file input[type="file"] { max-width: 100%; margin-top: 0.25rem; }

/* The builder's step cards sit one step lighter than the page in dark mode. Cards, rows and tables on a sky panel get
   the same step from the `--sky-surface` token in patient-sky.css. Light mode is unchanged. */
:root[data-bs-theme="dark"] .rx-section {
  background-color: color-mix(in srgb, var(--surface) 90%, var(--bs-white));
}

/* An icon button that sits beside text or a title (a card's edit pencil) matches the compact control height
   instead of the 2rem touch target, so it is not the largest thing on the card. */
.btn-icon.btn-icon-compact { width: 1.9rem; height: 1.9rem; font-size: 0.8rem; }

/* A row of counts as one quiet strip: label and number per cell, hairline dividers, neutral at zero. The only colour
   is an amber edge on a cell that needs doing (overdue), the same rule as the status rail. */
.stat-strip {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--bs-border-radius);
  background: var(--surface);
  overflow: hidden;
}
.stat-cell {
  display: inline-flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.3rem 0.9rem;
  border-left: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.78rem;
  line-height: 1.3;
  text-decoration: none;
}
.stat-cell:first-child { border-left: 0; }
.stat-cell .stat-label { color: var(--ink-muted); }
.stat-cell .stat-label .bi { margin-right: 0.3rem; font-size: 0.85rem; }
.stat-cell b { font-family: var(--font-mono); font-size: 0.95rem; font-weight: 600; }
.stat-cell.is-zero b { color: var(--ink-muted); font-weight: 500; }
.stat-cell.is-amber { box-shadow: inset 3px 0 0 var(--amber); }
a.stat-cell:hover { background: var(--tint-green); color: var(--ink); }
/* A strip used as a filter: the chosen cell. */
.stat-cell.is-current { background: var(--tint-green); box-shadow: inset 0 -2px 0 var(--pharmacy); }
.stat-cell.is-current .stat-label { color: var(--ink); }
/* Sample collection: one card per patient; the patient is the card header, their tests are the rows. */
.collection-group { overflow: hidden; }
.collection-group .collection-patient { background: var(--tint-green); border-bottom: 1px solid var(--line); }
.collection-group .patient-name { font-size: 0.95rem; font-weight: 700; }
.collection-table { table-layout: fixed; }
.collection-table th:nth-child(1) { width: 21%; }
.collection-table th:nth-child(2) { width: 14%; }
.collection-table th:nth-child(3) { width: 19%; }
.collection-table th:nth-child(4) { width: 11%; }
.collection-table .test-name { font-weight: 500; }
