/* Trauma Hub — single shared stylesheet (ARCHITECTURE 3.6).
   Components are documented live at /styleguide/ (TH_DEBUG only).
   CSP: no inline styles anywhere; dynamic colours use classes (tag--teal, group--red ...).

   Design language: dark ink sidebar, ruby-red accent, soft rounded white cards on a warm off-white
   page, Inter type. Status is carried by a coloured rail + dot + tinted header, never by colour alone.
   Because the accent is red, three things deliberately do NOT use it, so they cannot be mistaken for
   "not ready"/error red: keyboard focus (ink), neutral list groups such as wards (ink), and danger
   buttons (outlined). Class names and token names are a contract used by every app: restyle, don't rename. */

@font-face {
  font-family: "Inter var"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("fonts/inter-latin-wght-normal.260c81a4759b.woff2") format("woff2");
}
@font-face {
  font-family: "Inter var"; font-style: italic; font-weight: 100 900; font-display: swap;
  src: url("fonts/inter-latin-wght-italic.0a81fe197e0d.woff2") format("woff2");
}

/* ---------- Tokens ---------- */
:root {
  --brand: #d11f45;
  --brand-dark: #a8163a;
  --brand-mid: #b81a40;
  --brand-tint: #fdf0f3;
  --brand-sub: #f8d4dc;
  --accent: #ff8fa6;
  --brand-grad: linear-gradient(135deg, #f0566f, #b3123a);

  --ink: #17151a;
  --ink-2: #231f26;
  --ink-line: rgba(255, 255, 255, .08);

  --bg: #f6f5f4;
  --surface: #ffffff;
  --surface-2: #faf9f8;
  --text: #1c1a1d;
  --muted: #645f66;
  --border: #e8e5e4;
  --border-control: #d6d2d1;
  --border-strong: #9b9698;
  --focus: #17151a;

  --red: #c0281b;      --red-tint: #fdf3f2;   --red-sub: #fbdcd8;   --red-ink: #8a1c12;
  --amber: #b45309;    --amber-tint: #fff8ed; --amber-sub: #fde8c8; --amber-ink: #7a3905;
  --green: #0f7a4d;    --green-tint: #f0faf4; --green-sub: #d2f0df; --green-ink: #0a5434;
  --neutral: #4d484f;  --neutral-tint: #f6f4f4; --neutral-sub: #eae7e6;

  --radius: 8px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(30, 20, 24, .04), 0 2px 6px rgba(30, 20, 24, .05);
  --shadow-md: 0 4px 14px rgba(30, 20, 24, .08), 0 1px 3px rgba(30, 20, 24, .05);
  --shadow-lg: 0 18px 48px rgba(30, 20, 24, .2), 0 4px 12px rgba(30, 20, 24, .08);
  --ring: 0 0 0 3px rgba(23, 21, 26, .14);
  --font: "Inter var", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --topbar-h: 60px;
  --sidebar-w: 224px;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  font-feature-settings: "cv11", "ss03", "calt";
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.011em; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand-mid); text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { color: var(--brand-dark); }
img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
code, kbd { font-family: var(--mono); font-size: .85em; }
code { background: var(--neutral-sub); padding: .08rem .35rem; border-radius: 5px; }
::selection { background: var(--brand-sub); }

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

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: .5rem; top: -4rem; z-index: 100; background: var(--brand); color: #fff; padding: .55rem .9rem; font-weight: 600; border-radius: var(--radius); }
.skip-link:focus { top: .5rem; color: #fff; }

/* ---------- Utilities ---------- */
.muted { color: var(--muted); }
.small { font-size: .8125rem; }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.stack > * + * { margin-top: .75rem; }
.cluster { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
[hidden] { display: none !important; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- App shell: sidebar + top strip ---------- */
body.has-shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.shell { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 45;
  display: flex; flex-direction: column; gap: 1.25rem; padding: 1rem .75rem;
  background: var(--ink); color: rgba(255, 255, 255, .72);
  background-image: radial-gradient(120% 60% at 0% 0%, rgba(209, 31, 69, .26), transparent 60%);
}
.sidebar :focus-visible { outline-color: var(--accent); }
.wordmark { display: inline-flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.0625rem; letter-spacing: -.015em; white-space: nowrap; text-decoration: none; color: var(--text); }
.sidebar .wordmark { color: #fff; padding: .25rem .5rem .5rem; }
.wordmark__logo { width: 30px; height: 30px; flex: none; border-radius: 9px; box-shadow: 0 4px 12px rgba(209, 31, 69, .4); }
.wordmark__mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: #fff; font-size: .8125rem; font-weight: 800; }

.mainnav { display: flex; flex-direction: column; gap: 2px; }
.mainnav__heading { margin: 0 0 .25rem; padding: 0 .65rem; font-size: .6875rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: rgba(255, 255, 255, .42); }
.mainnav a {
  display: flex; align-items: center; gap: .7rem; padding: .5rem .65rem; border-radius: var(--radius);
  color: rgba(255, 255, 255, .74); font-weight: 550; text-decoration: none; position: relative;
  transition: background .12s, color .12s;
}
.mainnav a:hover { color: #fff; background: rgba(255, 255, 255, .07); }
.mainnav a.is-active, .mainnav a[aria-current="page"] { color: #fff; background: rgba(255, 255, 255, .11); }
.mainnav a.is-active::before, .mainnav a[aria-current="page"]::before {
  content: ""; position: absolute; left: -.75rem; top: 22%; bottom: 22%; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.mainnav a.is-active .icon { color: var(--accent); }
.mainnav--text a { padding: .4rem .65rem; font-weight: 500; font-size: .9375rem; }
.mainnav__back { color: rgba(255, 255, 255, .6) !important; font-size: .875rem; }
.sidebar__foot { margin-top: auto; padding: .75rem .65rem .25rem; border-top: 1px solid var(--ink-line); font-size: .75rem; line-height: 1.45; color: rgba(255, 255, 255, .45); }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem;
  height: var(--topbar-h); padding: 0 2rem;
  background: rgba(246, 245, 244, .82); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__search { flex: 1 1 320px; max-width: 520px; position: relative; display: flex; align-items: center; }
.topbar__search .icon { position: absolute; left: .8rem; color: var(--muted); pointer-events: none; }
.topbar__search input[type="search"] {
  width: 100%; height: 40px; min-height: 40px; padding: 0 2.6rem 0 2.5rem; border-radius: 999px;
  border: 1px solid var(--border-control); background: var(--surface); color: var(--text); font: inherit;
  box-shadow: var(--shadow); transition: border-color .12s, box-shadow .12s;
}
.topbar__search input[type="search"]::placeholder { color: var(--muted); }
.topbar__search input[type="search"]:focus { outline: none; border-color: var(--text); box-shadow: var(--ring); }
.topbar__kbd {
  position: absolute; right: .7rem; font-family: var(--mono); font-size: .75rem; color: var(--muted);
  border: 1px solid var(--border-control); border-radius: 5px; padding: 0 .4rem; line-height: 1.5; background: var(--surface-2); pointer-events: none;
}
.topbar__search:focus-within .topbar__kbd { display: none; }
.topbar__spacer { flex: 1 1 auto; }
.topbar__admin { display: none; }

.usermenu { position: relative; }
.usermenu > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: .55rem;
  padding: .25rem .6rem .25rem .25rem; border-radius: 999px; white-space: nowrap; font-weight: 550;
  border: 1px solid transparent; transition: background .12s, border-color .12s;
}
.usermenu > summary::-webkit-details-marker { display: none; }
.usermenu > summary:hover, .usermenu[open] > summary { background: var(--surface); border-color: var(--border); }
.usermenu > summary::after { content: ""; width: 6px; height: 6px; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); transform: rotate(45deg); margin: -3px 2px 0 2px; }
.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--ink-2); color: #fff; font-weight: 650; font-size: .75rem; text-transform: uppercase; letter-spacing: .02em;
}
.usermenu__panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; z-index: 50;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: .4rem;
}
.usermenu__panel .usermenu__who { padding: .6rem .7rem .7rem; border-bottom: 1px solid var(--border); margin-bottom: .35rem; }
.usermenu__panel a, .usermenu__panel button {
  display: block; width: 100%; text-align: left; padding: .5rem .7rem; color: var(--text); border-radius: var(--radius);
  background: none; border: 0; font: inherit; cursor: pointer; text-decoration: none;
}
.usermenu__panel a:hover, .usermenu__panel button:hover { background: var(--neutral-tint); }
.usermenu__panel form { margin: 0; }

/* Signed-out pages (sign in, register, 2FA): no sidebar, soft gradient backdrop */
body.is-public {
  min-height: 100vh;
  background:
    radial-gradient(60rem 36rem at 12% -10%, rgba(209, 31, 69, .16), transparent 60%),
    radial-gradient(48rem 30rem at 100% 0%, rgba(240, 150, 90, .13), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
.is-public .topbar { position: static; height: auto; justify-content: center; padding: 3.25rem 1rem 0; background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none; }
.is-public .wordmark { font-size: 1.25rem; }
.is-public .wordmark__logo { width: 36px; height: 36px; border-radius: 11px; }

/* ---------- Page ---------- */
.page { width: 100%; max-width: 1440px; margin: 0 auto; padding: 1.5rem 2rem 4rem; flex: 1 0 auto; }
.page:focus { outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head__actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.page-head__sub { color: var(--muted); margin: .3rem 0 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem 1.35rem; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card + .card { margin-top: 1rem; }

/* ---------- Tabs (segmented control) ---------- */
.tabs {
  display: inline-flex; max-width: 100%; gap: 2px; padding: 3px; margin-bottom: 1.25rem;
  background: var(--neutral-sub); border-radius: 11px; overflow-x: auto; overflow-y: hidden;
}
.tabs a, .tabs button {
  display: inline-flex; align-items: center; gap: .45rem; padding: .4rem .9rem;
  color: var(--muted); text-decoration: none; font: inherit; font-weight: 600; white-space: nowrap;
  border: 0; border-radius: 8px; background: none; cursor: pointer; transition: background .12s, color .12s;
}
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs .is-active, .tabs [aria-current="page"], .tabs [aria-selected="true"] { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.tabs .count { font-size: .6875rem; background: var(--neutral-sub); color: var(--neutral); padding: .05rem .45rem; border-radius: 999px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tabs .is-active .count, .tabs [aria-current="page"] .count, .tabs [aria-selected="true"] .count { background: var(--brand-tint); color: var(--brand-dark); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 36px; padding: .4rem .95rem; border-radius: var(--radius);
  border: 1px solid var(--border-control); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none; cursor: pointer; white-space: nowrap;
  box-shadow: 0 1px 1px rgba(24, 20, 50, .04); transition: background .12s, border-color .12s, box-shadow .12s, transform .06s;
}
.btn:hover { background: var(--neutral-tint); border-color: var(--border-strong); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(168, 22, 58, .35), inset 0 1px 0 rgba(255, 255, 255, .16); }
.btn--primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
/* Danger is outlined so it never looks like the (red) primary button. */
.btn--danger { background: var(--surface); border-color: var(--red); color: var(--red-ink); box-shadow: none; }
.btn--danger::before { content: "!"; display: inline-grid; place-items: center; width: 1.05rem; height: 1.05rem; border-radius: 50%; background: var(--red); color: #fff; font-size: .7rem; font-weight: 800; }
.btn--danger:hover { background: var(--red-tint); border-color: var(--red); color: var(--red-ink); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--brand-mid); box-shadow: none; }
.btn--ghost:hover { background: var(--brand-tint); border-color: transparent; color: var(--brand-dark); }
.btn--small { min-height: 28px; padding: .2rem .65rem; font-size: .8125rem; border-radius: 7px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--brand-mid); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.btn .icon { width: 16px; height: 16px; margin-left: -.15rem; }

/* Icon-only button: always give it data-tip (hover text) and an aria-label. */
.icon-btn {
  display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--brand-tint); color: var(--brand-dark); }
.icon-btn .icon { width: 17px; height: 17px; }

/* Copy button: deliberately faint until hovered. */
.copy {
  display: inline-grid; place-items: center; width: 20px; height: 20px; padding: 0; margin: 0 0 0 .05rem; vertical-align: -5px;
  border: 0; border-radius: 5px; background: none; color: var(--border-strong); cursor: pointer; transition: background .12s, color .12s;
}
.copy .icon { width: 13px; height: 13px; }
.copy .copy__done { display: none; }
.copy:hover, .copy:focus-visible { color: var(--text); background: var(--neutral-sub); }
.copy.is-copied { color: var(--green); background: var(--green-tint); }
.copy.is-copied .copy__icon { display: none; }
.copy.is-copied .copy__done { display: block; }

/* Tooltip: data-tip="Add comment". Shows on hover and on keyboard focus. */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; z-index: 70; left: 50%; bottom: calc(100% + 6px); transform: translate(-50%, 3px);
  padding: .2rem .5rem; border-radius: 6px; background: var(--ink); color: #fff; box-shadow: var(--shadow-md);
  font: 600 .75rem/1.4 var(--font); letter-spacing: 0; text-transform: none; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .1s, transform .1s;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after, .copy.is-copied::after { opacity: 1; transform: translate(-50%, 0); }

/* Back link above a page title (patient edit and timeline pages). */
.backlink { display: inline-flex; align-items: center; gap: .3rem; margin-bottom: .7rem; font-size: .8125rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.backlink:hover { color: var(--text); }
.backlink .icon { width: 15px; height: 15px; }

/* ---------- Tags and badges ---------- */
.tag {
  display: inline-flex; align-items: center; gap: .35rem; padding: .08rem .55rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; line-height: 1.5; white-space: nowrap; border: 1px solid transparent;
}
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; }
.tag--red    { background: #fde4e1; color: #8a1c12; }
.tag--amber  { background: #fdecd2; color: #7a3905; }
.tag--green  { background: #dcf3e6; color: #0a5434; }
.tag--teal   { background: #d8eef0; color: #0b4a58; }
.tag--blue   { background: #dfe9fc; color: #1a468a; }
.tag--purple { background: #ece5fa; color: #522699; }
.tag--pink   { background: #fce3ef; color: #8a1d59; }
.tag--brown  { background: #f0e4d7; color: #66401e; }
.tag--grey   { background: #e9e8ee; color: #3d3c4d; }
.tag--black  { background: #1b1a24; color: #ffffff; }
.tag-list { display: inline-flex; flex-wrap: wrap; gap: .3rem; }

.badge {
  display: inline-block; padding: .08rem .45rem; border-radius: 6px; font-size: .6875rem; font-weight: 650;
  letter-spacing: .03em; text-transform: uppercase; line-height: 1.55; vertical-align: middle;
  background: var(--neutral-sub); color: var(--neutral);
}
.badge--brand   { background: var(--ink-2); color: #fff; }
.badge--success { background: var(--green-sub); color: var(--green-ink); }
.badge--warning { background: var(--amber-sub); color: var(--amber-ink); }
.badge--danger  { background: var(--red-sub); color: var(--red-ink); }
.badge--solid   { background: var(--brand); color: #fff; }

/* ---------- Toggle chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.chips__label { color: var(--muted); font-size: .8125rem; margin-right: .25rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem; min-height: 30px; padding: .2rem .8rem;
  border-radius: 999px; border: 1px solid var(--border-control); background: var(--surface); color: var(--muted);
  font: inherit; font-size: .8125rem; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background .12s, border-color .12s, color .12s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
/* Toggle chips carry a little switch dot; link chips (quick filters) don't. */
.chip[aria-pressed]::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--border-strong); }
.chip[aria-pressed="true"] { background: var(--brand-tint); border-color: var(--brand-sub); color: var(--brand-dark); }
.chip[aria-pressed="true"]::before { border-color: var(--brand); background: var(--brand); }
a.chip { text-decoration: none; }
.chip.is-active { background: var(--text); border-color: var(--text); color: #fff; }

/* Toggle targets: a chip with data-toggle="notes" hides .t-notes inside its root. */
.hide-details .t-details, .hide-notes .t-notes, .hide-comments .t-comments, .hide-pmh .t-pmh,
.hide-tags .t-tags, .hide-images .t-images, .hide-equipment .t-equipment, .hide-audit .t-audit { display: none !important; }

/* ---------- List + filter layout: filters are a bar above the list ---------- */
.with-filters { display: flex; flex-direction: column; gap: 1rem; }
.with-filters__main { min-width: 0; }
.with-filters > .filters { order: -1; }
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: .8rem 1rem; box-shadow: var(--shadow);
}
.filters > form { display: contents; }
.filters__title { align-self: center; font-size: .6875rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 650; margin: 0; }
.filters__quick { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0; align-self: center; }
.filters .field { margin: 0; flex: 0 1 190px; min-width: 150px; }
.filters .field > label, .filters .field__label { font-size: .75rem; color: var(--muted); font-weight: 600; margin-bottom: .2rem; }
.filters .field__help { display: none; }
.filters input, .filters select, .filters .multi__button { min-height: 34px; padding-top: .25rem; padding-bottom: .25rem; }
.filters__actions { display: flex; gap: .4rem; margin-left: auto; align-self: flex-end; border: 0; padding: 0; }
.list-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* Multi-select dropdown (app.js upgrades select[multiple] inside .filters, or any select[data-multi]) */
.multi { position: relative; }
.multi__button {
  list-style: none; display: flex; align-items: center; justify-content: space-between; gap: .5rem; cursor: pointer;
  width: 100%; min-height: 38px; padding: .4rem .65rem; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.multi__button::-webkit-details-marker { display: none; }
.multi__button::after { content: ""; flex: none; width: 6px; height: 6px; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); transform: rotate(45deg); margin-top: -3px; }
.multi[open] .multi__button { border-color: var(--text); box-shadow: var(--ring); }
.multi:not(.has-value) .multi__button { color: var(--muted); }
.multi.has-value .multi__button { color: var(--brand-dark); font-weight: 600; }
.multi__panel {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 30; min-width: 100%; width: max-content; max-width: 340px; max-height: 300px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: .35rem;
}
.multi__option { display: flex; align-items: center; gap: .1rem; padding: .35rem .55rem; border-radius: 7px; cursor: pointer; font-weight: 500; }
.multi__option:hover { background: var(--neutral-tint); }
.multi__panel .multi__search { min-height: 32px; margin-bottom: .3rem; padding: .25rem .6rem; border-color: var(--border-control); }
.multi__none { margin: 0; padding: .4rem .55rem; color: var(--muted); }

/* Searchable dropdown (app.js upgrades every single-choice <select>): click the box and type. */
.sel { position: relative; }
.sel::after {
  content: ""; position: absolute; right: .8rem; top: 19px; margin-top: -5px; width: 6px; height: 6px; pointer-events: none;
  border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); transform: rotate(45deg); transition: transform .12s;
}
.sel.is-open::after { transform: rotate(225deg); margin-top: -1px; }
.filters .sel::after { top: 17px; }
.sel__input[type="text"] { padding-right: 2rem; cursor: pointer; text-overflow: ellipsis; }
.sel.is-open .sel__input[type="text"] { cursor: text; }
.sel__input::placeholder { color: var(--muted); }
.field--narrow .sel { max-width: 16rem; }
.sel__list {
  position: absolute; z-index: 35; left: 0; top: calc(100% + 4px); min-width: 100%; width: max-content; max-width: min(420px, 90vw);
  max-height: 17.5rem; overflow-y: auto; margin: 0; padding: .3rem; list-style: none; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.sel--up .sel__list { top: auto; bottom: calc(100% + 4px); }
/* Inside the modal (which scrolls) the list sits in the flow so it is never clipped. */
.modal .sel__list { position: static; width: auto; max-width: none; max-height: 13rem; margin-top: .25rem; box-shadow: var(--shadow); }
.sel__option { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .4rem .6rem; border-radius: 7px; cursor: pointer; font-weight: 500; }
.sel__option:hover { background: var(--neutral-tint); }
.sel__option.is-active { background: var(--neutral-sub); }
.sel__option[aria-selected="true"] { font-weight: 650; }
.sel__option[aria-selected="true"]::after { content: ""; flex: none; width: 5px; height: 10px; margin: -3px .2rem 0 0; border-right: 2px solid var(--brand); border-bottom: 2px solid var(--brand); transform: rotate(45deg); }
.sel__option--blank { color: var(--muted); }
.sel__option[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.sel__group { padding: .5rem .6rem .15rem; font-size: .6875rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sel__none { padding: .45rem .6rem; color: var(--muted); }

/* Row action menu: opens upwards when app.js finds no room below. */
.row-menu.is-up .row-menu__panel { top: auto; bottom: calc(100% + 4px); }

/* ---------- Grouped lists ---------- */
/* No overflow:hidden here: row menus and tooltips must be able to hang outside the card. The corners
   of the first and last child are rounded instead (inner radius = outer radius minus the border). */
.group {
  margin-bottom: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--neutral);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.group__head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin: 0; padding: .7rem 1.1rem; font-size: .9375rem; font-weight: 650; letter-spacing: -.005em;
  color: var(--text); background: var(--neutral-tint); border-bottom: 1px solid var(--border);
}
.group__head > span:first-child { display: inline-flex; align-items: center; gap: .6rem; min-width: 0; }
.group__head > span:first-child::before { content: ""; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--neutral); box-shadow: 0 0 0 3px rgba(77, 72, 79, .14); }
.group__meta { font-weight: 600; font-size: .75rem; white-space: nowrap; padding: .12rem .6rem; border-radius: 999px; background: rgba(255, 255, 255, .75); color: var(--neutral); font-variant-numeric: tabular-nums; }
.group__sub {
  margin: 0; padding: .35rem 1.1rem; font-size: .6875rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
  background: var(--surface-2); color: var(--muted); border-bottom: 1px solid var(--border);
}
.rows + .group__sub { border-top: 1px solid var(--border); }
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.rows > :first-child { border-top-left-radius: 13px; border-top-right-radius: 13px; }
.rows > :last-child { border-bottom-left-radius: 13px; border-bottom-right-radius: 13px; }
.group .rows { border: 0; border-radius: 0; }
.group .rows > * { border-radius: 0; }
.group > :first-child { border-top-left-radius: 10px 13px; border-top-right-radius: 13px; }
.group > :last-child, .group > .rows:last-child > :last-child { border-bottom-left-radius: 10px 13px; border-bottom-right-radius: 13px; }

.group--red { border-left-color: var(--red); }
.group--red .group__head { background: var(--red-tint); color: var(--red-ink); }
.group--red .group__head > span:first-child::before { background: var(--red); box-shadow: 0 0 0 3px rgba(192, 40, 27, .16); }
.group--red .group__meta { color: var(--red-ink); }
.group--amber { border-left-color: #e08a1e; }
.group--amber .group__head { background: var(--amber-tint); color: var(--amber-ink); }
.group--amber .group__head > span:first-child::before { background: #e08a1e; box-shadow: 0 0 0 3px rgba(224, 138, 30, .2); }
.group--amber .group__meta { color: var(--amber-ink); }
.group--green { border-left-color: var(--green); }
.group--green .group__head { background: var(--green-tint); color: var(--green-ink); }
.group--green .group__head > span:first-child::before { background: var(--green); box-shadow: 0 0 0 3px rgba(15, 122, 77, .16); }
.group--green .group__meta { color: var(--green-ink); }
/* "brand" groups (wards, locations) are ink, not red: red is reserved for the not-ready list. */
.group--brand { border-left-color: var(--ink); }
.group--brand .group__head { background: var(--neutral-sub); color: var(--text); }
.group--brand .group__head > span:first-child::before { background: var(--ink); box-shadow: 0 0 0 3px rgba(23, 21, 26, .14); }
.group--brand .group__meta { color: var(--text); }
.group--neutral { border-left-color: var(--neutral); }

.row {
  display: grid; grid-template-columns: minmax(13rem, 17rem) minmax(0, 1fr) auto; gap: .5rem 1.5rem;
  padding: .9rem 1.1rem; border-top: 1px solid var(--border); align-items: start; background: var(--surface);
  transition: background .12s;
}
.rows > .row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); }
.row__main { min-width: 0; }
.row__title { font-weight: 650; margin: 0; letter-spacing: -.005em; }
.row__line { margin: .1rem 0 0; }
.row__meta { color: var(--muted); font-size: .8125rem; margin: .15rem 0 0; }
.row__note { font-style: italic; margin: .3rem 0 0; color: var(--neutral); }
.row__notes { margin: .45rem 0 0; white-space: pre-line; font-size: .875rem; color: var(--neutral); }
.row__aside { display: flex; flex-direction: column; align-items: flex-end; gap: .4rem; text-align: right; font-size: .8125rem; color: var(--muted); }
.row__actions { display: flex; gap: .3rem; }
.row__status { font-size: .8125rem; margin: .35rem 0 0; }
.row__comment {
  margin: .5rem 0 0; padding: .4rem .7rem; font-size: .8125rem; background: var(--neutral-tint);
  border-radius: 4px 10px 10px 10px; width: fit-content; max-width: 100%;
}
.row__comment-meta { color: var(--muted); }
/* Latest comment bubble with the add-comment icon beside it. */
.latest-comment { display: flex; align-items: center; gap: .3rem; margin-top: .45rem; }
.latest-comment .row__comment { margin: 0; min-width: 0; }
.drag-handle {
  cursor: grab; color: var(--border-strong); padding: .25rem; border: 0; background: none; font-size: 1.1rem; line-height: 1;
  touch-action: none; border-radius: 6px;
}
.drag-handle:hover { color: var(--text); background: var(--neutral-sub); }
.row--sortable { grid-template-columns: auto minmax(13rem, 17rem) minmax(0, 1fr) auto; }
.is-ghost { opacity: .5; background: var(--brand-tint) !important; }
.sortable-chosen { box-shadow: var(--shadow-lg); }
@media (max-width: 900px) {
  .row, .row--sortable { grid-template-columns: minmax(0, 1fr); }
  .row__aside { align-items: flex-start; text-align: left; }
}

/* Patient cell */
.patient-cell { min-width: 0; }
.patient-cell__name { overflow-wrap: anywhere; font-weight: 650; color: var(--text); text-decoration: none; letter-spacing: -.005em; }
a.patient-cell__name:hover { color: var(--brand-dark); text-decoration: underline; }
.patient-cell__ids { color: var(--muted); font-size: .8125rem; font-variant-numeric: tabular-nums; margin: .1rem 0 0; }
.patient-cell .tag-list { margin-top: .4rem; }
.nhs { font-variant-numeric: tabular-nums; letter-spacing: .01em; white-space: nowrap; }

/* ---------- Tables and detail lists ---------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .75rem; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); font-weight: 650; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table--compact th, .table--compact td { padding: .4rem .65rem; }
.details { display: grid; grid-template-columns: minmax(8rem, 12rem) minmax(0, 1fr); gap: .45rem 1rem; margin: 0; }
.details dt { color: var(--muted); font-size: .8125rem; padding-top: .08rem; }
.details dd { margin: 0; }

/* ---------- Forms ---------- */
form { margin: 0; }
.field { margin-bottom: 1rem; }
.field > label, .field__label, fieldset > legend { display: block; font-weight: 600; font-size: .875rem; margin-bottom: .3rem; }
.field__required { color: var(--red); margin-left: .15rem; }
.field__help { display: block; color: var(--muted); font-size: .8125rem; margin-top: .3rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"],
input[type="tel"], input[type="date"], input[type="datetime-local"], input[type="time"], input[type="url"],
select, textarea {
  width: 100%; max-width: 100%; padding: .45rem .65rem; min-height: 38px;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: #8e8ba3; }
textarea { min-height: 5rem; resize: vertical; line-height: 1.5; }
select[multiple] { min-height: 7rem; padding: .25rem; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text); box-shadow: var(--ring); }
input[type="checkbox"], input[type="radio"] { width: 1.05rem; height: 1.05rem; accent-color: var(--brand); vertical-align: middle; margin: 0 .5rem 0 0; }
input[type="file"] { font: inherit; }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; margin-right: .75rem; padding: .35rem .8rem; border-radius: var(--radius);
  border: 1px solid var(--border-control); background: var(--surface); color: var(--text); cursor: pointer;
}
.field--checkbox > label, .field--inline > label { display: inline-flex; align-items: center; font-weight: 500; }
.field--narrow input, .field--narrow select { max-width: 16rem; }
.field ul { list-style: none; padding: 0; margin: 0; }
.field ul li label { display: inline-flex; align-items: center; font-weight: 500; padding: .15rem 0; }
.field--error input, .field--error select, .field--error textarea { border-color: var(--red); box-shadow: 0 0 0 3px rgba(192, 40, 27, .14); }
.field__errors, .errorlist { list-style: none; margin: .3rem 0 0; padding: 0; color: var(--red); font-weight: 600; font-size: .8125rem; }
.form-errors {
  border: 1px solid var(--red-sub); border-left: 4px solid var(--red); background: var(--red-tint); color: var(--red-ink);
  padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem;
}
.form-errors .errorlist, .form-errors ul { margin: 0; color: inherit; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 760px) { .form-grid, .form-grid--3 { grid-template-columns: minmax(0, 1fr); } }
.form-section { border: 0; padding: 0; margin: 0 0 1.5rem; }
.form-section > legend, .form-section__title { font-size: 1rem; font-weight: 650; padding: 0; margin-bottom: .75rem; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; border-top: 1px solid var(--border); padding-top: 1rem; margin-top: .5rem; }

/* ---------- Modal (<dialog id="modal">, filled by HTMX) ---------- */
.modal {
  width: min(760px, 94vw); max-height: 88vh; padding: 0; border: 0; border-radius: 16px;
  box-shadow: var(--shadow-lg); color: var(--text); background: var(--surface);
}
.modal--wide { width: min(1100px, 96vw); }
.modal::backdrop { background: rgba(21, 20, 29, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal[open] { display: flex; flex-direction: column; animation: th-pop .16s ease-out; }
@keyframes th-pop { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.modal__header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.35rem; border-bottom: 1px solid var(--border); }
.modal__header h2 { margin: 0; }
.modal__close { border: 0; background: none; font-size: 1.4rem; line-height: 1; width: 32px; height: 32px; cursor: pointer; color: var(--muted); border-radius: 50%; }
.modal__close:hover { background: var(--neutral-sub); color: var(--text); }
.modal__body { padding: 1.35rem; overflow-y: auto; }
.modal__footer { display: flex; justify-content: flex-end; gap: .5rem; padding: .9rem 1.35rem; border-top: 1px solid var(--border); background: var(--surface-2); }
/* Confirmation question (app.js, data-confirm) */
.modal--confirm { width: min(440px, 92vw); }
.modal--confirm::backdrop { background: rgba(21, 20, 29, .32); backdrop-filter: none; -webkit-backdrop-filter: none; }
.modal--confirm .modal__body { padding: 1.5rem 1.35rem 1.2rem; }
.confirm__text { margin: 0; font-size: 1.0625rem; font-weight: 650; letter-spacing: -.01em; line-height: 1.4; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; top: calc(var(--topbar-h) + 12px); right: 20px; z-index: 60;
  display: flex; flex-direction: column; gap: .5rem; width: min(400px, calc(100vw - 40px));
}
.toast {
  display: flex; align-items: flex-start; gap: .7rem; padding: .8rem .9rem; background: var(--ink); color: #fff;
  border-radius: 12px; box-shadow: var(--shadow-lg); animation: th-pop .16s ease-out;
}
.toast::before { content: ""; flex: none; width: 8px; height: 8px; margin-top: .45rem; border-radius: 50%; background: var(--accent); }
.toast__text { flex: 1; }
.toast__close { border: 0; background: none; cursor: pointer; font-size: 1.2rem; line-height: 1; color: rgba(255, 255, 255, .6); padding: 0 .2rem; }
.toast__close:hover { color: #fff; }
.toast--success::before { background: #4ade80; }
.toast--warning::before { background: #fbbf24; }
.toast--error::before { background: #f87171; }
.toast--info::before { background: var(--accent); }
.toast.is-leaving { opacity: 0; transform: translateX(8px); transition: opacity .2s, transform .2s; }

/* ---------- Empty state ---------- */
.empty {
  text-align: center; padding: 2.75rem 1.5rem; color: var(--muted);
  border: 1px dashed var(--border-control); border-radius: var(--radius-lg); background: var(--surface);
}
.group .empty, .rows > .empty { border: 0; border-radius: 0; }
.empty__title { color: var(--text); font-weight: 650; font-size: 1.0625rem; margin-bottom: .35rem; }
.empty .btn { margin-top: .75rem; }

/* ---------- Audit line ---------- */
.audit-line { color: var(--muted); font-size: .75rem; margin: .5rem 0 0; }
.audit-line a, .audit-line button { color: var(--muted); }
.audit-line a:hover, .audit-line button:hover { color: var(--brand-dark); }

/* ---------- Home ---------- */
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.hero h1 { font-size: 1.75rem; margin: 0; }
.hero__sub { display: inline-flex; align-items: center; gap: .5rem; margin: .5rem 0 0; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: .4rem; padding: .15rem .65rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .8125rem; font-weight: 600; color: var(--text); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.section-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 650; margin: 0 0 .75rem; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat {
  position: relative; display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem 1.15rem; text-decoration: none; color: var(--text); box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
a.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--brand-sub); color: var(--text); }
.stat__label { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-weight: 600; font-size: .8125rem; }
.stat__label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.stat__value { display: block; font-size: 2.25rem; font-weight: 700; line-height: 1.1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin-top: .5rem; }
.stat--amber .stat__label::before { background: #e08a1e; }
.stat--green .stat__label::before { background: var(--green); }
.quick-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.quick-link {
  position: relative; display: flex; flex-direction: column; gap: .15rem; padding: .95rem 2.5rem .95rem 1.1rem; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); transition: border-color .12s, box-shadow .12s;
}
.quick-link::after { content: "→"; position: absolute; right: 1rem; top: 50%; transform: translateY(-50%); color: var(--border-strong); font-size: 1.1rem; transition: transform .12s, color .12s; }
.quick-link:hover { border-color: var(--brand-sub); box-shadow: var(--shadow-md); color: var(--text); }
.quick-link:hover::after { color: var(--brand); transform: translate(3px, -50%); }
.quick-link strong { color: var(--text); font-weight: 650; }
.quick-link span { color: var(--muted); font-size: .8125rem; }
.home-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.home-panel { display: flex; flex-direction: column; }
.home-panel .card__head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: .5rem; }
.home-panel .card__head h2 { margin: 0; font-size: 1rem; }
.home-list { list-style: none; margin: 0; padding: 0; }
.home-list > li { border-top: 1px solid var(--border); }
.home-list > li:first-child { border-top: 0; }
.home-list > li > a, .home-list__row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .1rem 1rem; padding: .55rem .25rem; color: var(--text); text-decoration: none; border-radius: var(--radius); }
.home-list > li > a:hover, .home-list__row:hover { background: var(--surface-2); }
.home-list__link { color: var(--text); text-decoration: none; }
.home-list__link:hover { color: var(--brand-dark); text-decoration: underline; }
.home-list__title { font-weight: 650; min-width: 0; overflow-wrap: anywhere; }
.home-list__meta { grid-column: 1; color: var(--muted); font-size: .8125rem; min-width: 0; }
.home-list__aside { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--muted); font-size: .8125rem; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.home-panel .empty { padding: 1.5rem 1rem; border: 0; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .quick-links { grid-template-columns: repeat(2, minmax(0, 1fr)); } .home-panels { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Admin panel shell (its navigation lives in the sidebar) ---------- */
.manage { display: block; }
.manage__main { min-width: 0; }
.sidenav { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: .5rem; }
.sidenav__heading { padding: .6rem .65rem .25rem; margin: 0; font-size: .6875rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 650; }
.sidenav ul { list-style: none; margin: 0; padding: 0; }
.sidenav a { display: block; padding: .4rem .65rem; color: var(--text); text-decoration: none; border-radius: var(--radius); }
.sidenav a:hover { background: var(--neutral-tint); }
.sidenav a.is-active { background: var(--brand-tint); color: var(--brand-dark); font-weight: 650; }

/* ---------- Sign-in and other signed-out cards ---------- */
.auth { max-width: 420px; margin: 1.75rem auto 3rem; }
.error-page { max-width: 520px; }
.error-page__code { margin: 0 0 .35rem; font-size: .75rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.error-page__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.25rem; }
.auth.error-page .btn--primary { width: auto; }
.auth.error-page .btn { min-height: 44px; }
.auth .card { padding: 2rem; border-radius: 18px; box-shadow: var(--shadow-lg); border-color: rgba(255, 255, 255, .7); }
.auth__title { margin-bottom: .25rem; font-size: 1.375rem; }
.auth__lead { color: var(--muted); margin-bottom: 1.5rem; }
.auth .btn--primary { width: 100%; min-height: 44px; font-size: .9375rem; }
.auth input[type="text"], .auth input[type="email"], .auth input[type="password"] { min-height: 42px; }
.notice { background: var(--neutral-tint); border: 1px solid var(--neutral-sub); padding: .75rem 1rem; border-radius: var(--radius); }
.notice--warning { background: var(--amber-tint); border-color: var(--amber-sub); }
.notice--danger { background: var(--red-tint); border-color: var(--red-sub); }

/* ---------- Styleguide ---------- */
.sg-section { margin-bottom: 2.5rem; }
.sg-section > h2 { border-bottom: 1px solid var(--border); padding-bottom: .4rem; margin-bottom: 1rem; }
.sg-swatches { display: flex; flex-wrap: wrap; gap: .5rem; }
.sg-swatch { width: 120px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: .75rem; background: var(--surface); }
.sg-swatch span { display: block; height: 40px; }
.sg-swatch code { display: block; padding: .3rem .4rem; background: none; }
.sg-brand { background: var(--brand); } .sg-red { background: var(--red); } .sg-amber { background: var(--amber); }
.sg-green { background: var(--green); } .sg-neutral { background: var(--neutral); } .sg-bg { background: var(--bg); }
.sg-code { display: block; white-space: pre; overflow-x: auto; padding: .75rem; background: var(--neutral-tint); border: 1px solid var(--border); border-radius: var(--radius); font-size: .8125rem; }

/* ---------- HTMX (includeIndicatorStyles is off under our CSP, so the styles live here) ---------- */
.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; transition: opacity 200ms ease-in; }
.spinner {
  display: inline-block; width: 1rem; height: 1rem; vertical-align: middle;
  border: 2px solid var(--brand-sub); border-top-color: var(--brand); border-radius: 50%;
  animation: th-spin .8s linear infinite;
}
@keyframes th-spin { to { transform: rotate(360deg); } }
.htmx-swapping { opacity: .6; transition: opacity 120ms; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Narrower screens ---------- */
/* Icon rail: only when the sidebar shows the icon nav (admin pages keep text links). */
@media (max-width: 1180px) {
  body.has-shell { --sidebar-w: 68px; }
  body.has-shell.sidebar-text { --sidebar-w: 200px; }
  body:not(.sidebar-text) .sidebar { padding: 1rem .6rem; align-items: center; }
  body:not(.sidebar-text) .sidebar .wordmark { padding: .25rem 0 .5rem; }
  body:not(.sidebar-text) .wordmark__text,
  body:not(.sidebar-text) .mainnav a > span,
  body:not(.sidebar-text) .mainnav__heading,
  body:not(.sidebar-text) .sidebar__foot { display: none; }
  body:not(.sidebar-text) .mainnav a { justify-content: center; padding: .6rem; }
  body:not(.sidebar-text) .mainnav a.is-active::before { left: -.6rem; }
  .topbar, .page { padding-left: 1.25rem; padding-right: 1.25rem; }
  .usermenu__name { display: none; }
}
@media (max-width: 720px) {
  body.has-shell, body.has-shell.sidebar-text { display: block; }
  .sidebar, body:not(.sidebar-text) .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: .5rem; padding: .5rem .75rem; overflow-x: auto; }
  .mainnav { flex-direction: row; }
  .mainnav a.is-active::before, .sidebar__foot, .mainnav__heading { display: none; }
  .shell { min-height: 0; }
  .filters .field { flex: 1 1 100%; }
}
@media print {
  .sidebar, .topbar, .filters, .chips, .btn, .toasts, .icon-btn, .copy, .backlink { display: none !important; }
  body, body.has-shell { display: block; background: #fff; }
  .group, .card { box-shadow: none; }
}
