/* ==========================================================================
   shell.v3.css — the Haresign Intelligence application shell.

   Phase 4C.25. The design language is the monolith's Bixoo/Haresign app shell,
   reproduced rather than copied: a 264px navy sidebar, a 60px sticky topbar, a
   #f4f6fa ground, and the same brand values the estate already wears. The token
   values below were read from `modules/core/website/templates/website/
   base_app.html` and haresign-web's design system; not one hex value is
   invented.

   What is deliberately NOT carried across:

   * the inline <style> block — the monolith's shell keeps ~250 lines of CSS in
     the document head, and this service's Content Security Policy forbids
     inline style outright, so it lives here in a versioned file instead;
   * Bootstrap, Font Awesome and swiper — three libraries for a grid, some
     icons and a carousel this shell does not have. Icons here are inline SVG
     with `currentColor`, so they inherit the palette and cost no request;
   * the remote web font. A `@font-face` pointing at Google Fonts would be both a
     remote dependency and a CSP violation. UX2b self-hosts the estate's two faces
     instead (below), copied from haresign-web with their licence;
   * the monolith's inline JavaScript. The checkbox drawer works without script;
     the self-hosted enhancement closes it with Escape and on desktop resize.

   The filename carries the version so a changed stylesheet is a changed URL.

   UX2b. The brand values now come from `vendor/haresign/tokens.css`, haresign-web's
   canonical token file (UX0 decision D1), loaded before this one. Intelligence keeps
   its own names where they mean something different (`--hs-border`, `--hs-radius-sm`
   and the rest below win because this file comes later); the brand colours it shares
   with the estate (`--hs-navy`, `--hs-aqua`, `--hs-teal-deep`, `--hs-surface`) are no
   longer redefined here. The navy is therefore the estate's #111827 (decision D4).
   ========================================================================== */

/* The estate's faces, self-hosted (`font-src 'self'`). Byte-identical to haresign-web's
   copies, pinned in vendor/haresign/SOURCE.toml; OFL 1.1 in vendor/haresign/fonts/OFL.txt.
   The family names are the ones the shell already asked for, so a tool's computed
   `font-family` is unchanged: the face now arrives instead of falling back. */
@font-face {
  font-family: "DM Sans";
  src: url("vendor/haresign/fonts/dm-sans-latin.7c87a648293f.woff2") format("woff2-variations"),
       url("vendor/haresign/fonts/dm-sans-latin.7c87a648293f.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Mona Sans";
  src: url("vendor/haresign/fonts/mona-sans-latin.74c4838e4577.woff2") format("woff2-variations"),
       url("vendor/haresign/fonts/mona-sans-latin.74c4838e4577.woff2") format("woff2");
  font-weight: 500 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Brand. `--hs-navy`, `--hs-aqua` and `--hs-teal-deep` are the canonical tokens (UX2b).
     The two lifts on the navy are mapped onto canonical values rather than invented:
     the soft navy for a raised control, and the estate's on-dark border tint, made a
     little stronger so a scrollbar thumb and a button stay visible on #111827. */
  --hs-navy-2: var(--hs-navy-soft);
  --hs-navy-3: rgba(255, 255, 255, 0.16);
  --hs-aqua-bright: #7fb3ff;

  /* Ink and ground. */
  --hs-ink: #1f2937;
  --hs-ink-muted: #55637a;
  /* 4.5:1 or more on the page ground, white and the info tint (was #7b8798, 3.4:1, too faint for 12px text). */
  --hs-ink-faint: #5f6d84;
  --hs-on-navy: #cdd6e6;
  --hs-on-navy-muted: #93a3bd;
  /* An unavailable tool: dimmer than a link (10.7:1) yet 5.1:1 on the navy, so the words stay readable. */
  --hs-on-navy-dim: #8493ae;
  /* UX2a. The focus ring on the navy sidebar. Aqua was 2.4:1 there, under WCAG 1.4.11's 3:1;
     white is 15.7:1 on the navy and 6.6:1 on the aqua of the current page's link. */
  --hs-focus-on-navy: #ffffff;
  --hs-ground: #f4f6fa;
  --hs-border: #dfe4ec;
  --hs-border-strong: #c8d0dd;

  /* Status. */
  --hs-warn-bg: #fff8e6;
  --hs-warn-border: #e6c34a;
  --hs-warn-ink: #6b5200;
  --hs-info-bg: #eef4fd;

  /* Metrics, from the monolith shell. */
  --hs-nav-heading: #7f8db0;
  --hs-nav-icon: #8ea2c6;

  --hs-sidebar-w: 264px;
  --hs-topbar-h: 60px;
  --hs-radius: 10px;
  --hs-radius-sm: 6px;
  --hs-measure: 68ch;
  --hs-shadow: 0 1px 2px rgba(17, 24, 39, 0.06), 0 4px 12px rgba(17, 24, 39, 0.05);

  /* UX2b. A canonical name no Intelligence stylesheet defined, read by a tool with its own
     fallback (QOF Income's `progress.v1.css`). Restyling a tool is not part of the shell
     change (UX0 section 5), so the name stays unset here and the tool keeps its fallback.
     `web/tests/test_brand_vendor.py` lists every such name. */
  --hs-text: initial;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--hs-ground);
  color: var(--hs-ink);
  font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

a { color: var(--hs-aqua); }

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

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Moved out of view with a transform rather than a negative `top`. Offsetting
   the box leaves its shadow behind — a grey sliver in the top-left corner of
   every page, which is what the first staging screenshot showed. A transform
   moves the shadow with the element. */
.skip-link {
  position: absolute;
  left: 8px; top: 8px;
  z-index: 1100;
  padding: 10px 14px;
  background: var(--hs-surface);
  border-radius: var(--hs-radius-sm);
  box-shadow: var(--hs-shadow);
  transform: translateY(calc(-100% - 16px));
  transition: transform .15s ease;
}
.skip-link:focus-visible { transform: none; }

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */

.shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--hs-sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--hs-navy);
  color: var(--hs-on-navy);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 1040;
  transition: transform .2s ease;
  padding-left: env(safe-area-inset-left);
  padding-bottom: env(safe-area-inset-bottom);
  scrollbar-width: thin;
  scrollbar-color: var(--hs-navy-3) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--hs-navy-3); border-radius: 4px; }

/* `min-width: 0` — without it a wide table inside a flex child refuses to
   shrink and pushes the whole page sideways instead of scrolling inside itself.
   The monolith learned this the hard way and the note is worth carrying. */
.main {
  margin-left: var(--hs-sidebar-w);
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.content { flex: 1; min-width: 0; padding: 24px; }
/* The source caps a tool's own wrapper at 1560px: a dashboard should use the
   screen, but a table stretched to 2500px on an ultrawide is unreadable. Matched
   exactly rather than approximately, because the cap is what decides whether the
   page reads as a dashboard or as a centred document. */
.content-inner { max-width: 1560px; margin: 0 auto; }
.content img, .content table { max-width: 100%; }
.scroll-x { overflow-x: auto; }

/* --------------------------------------------------------------------------
   Sidebar: brand, navigation, footer
   -------------------------------------------------------------------------- */

/* The brand bar. One topbar tall, so the brand and the page title share a baseline
 * across the top of the app.
 *
 * Phase 4C.26A-visual put the full-colour lockup on a white bar, because its navy half
 * disappeared against the sidebar. UX2b (decision D4) uses the estate's white-ink lockup
 * instead, so the sidebar's brand cell is navy like the rest of it; the standalone error
 * pages keep the colour lockup on their white bar. */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--hs-topbar-h);
  padding: 14px 18px;
  background: var(--hs-surface);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  text-decoration: none;
  flex: 0 0 auto;
}
.brand-logo { height: 30px; width: auto; flex: 0 0 auto; }
.sidebar .brand {
  gap: 9px;
  background: var(--hs-navy);
  border-bottom-color: var(--hs-border-on-dark);
}
.sidebar .brand-logo { height: 26px; }
/* The service name, as text: the lockup's own strapline is unreadable at this size. */
.brand-service {
  color: #ffffff;
  font-family: var(--hs-font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
  white-space: nowrap;
}

/* UX2a. Everything in the sidebar sits on navy and takes the light ring (the workspace
   select fell through to the page's aqua one). UX2b: the brand cell is navy too, so it
   takes the same ring, drawn inside the cell. */
.sidebar :focus-visible { outline-color: var(--hs-focus-on-navy); }
.sidebar .brand:focus-visible { outline-offset: -4px; }

.nav { padding: 8px 0 24px; }

.nav-section { border: 0; padding: 0 10px; margin-top: 4px; }
.nav-section > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--hs-nav-heading);
}
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section-label { min-width: 0; }
/* The one glyph that turns. `margin-left: auto` puts it at the far edge without
   a spacer element, and `[open]` flips it — no script, no second icon. */
.nav-chevron {
  margin-left: auto;
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  transition: transform 0.15s ease;
}
.nav-section[open] > summary .nav-chevron { transform: rotate(180deg); }
.nav-section > summary:focus-visible { outline: 2px solid var(--hs-focus-on-navy); outline-offset: -2px; }

/* Decorative, and sized to the source's 16px column so labels align down the
   whole sidebar whether or not a row has an icon. */
.nav-icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--hs-nav-icon);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 1px 0;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--hs-on-navy);
  text-decoration: none;
  font-size: 13.5px;
  line-height: 1.25;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-link:hover .nav-icon { color: #fff; }
.nav-link[aria-current='page'] { background: var(--hs-aqua); color: #fff; font-weight: 600; }
.nav-link[aria-current='page'] .nav-icon { color: #fff; }
.nav-link:focus-visible { outline: 2px solid var(--hs-focus-on-navy); outline-offset: -2px; }
.nav-link .icon { flex: none; width: 16px; height: 16px; opacity: .85; }

/* An unavailable tool is shown and visibly not a link. Hiding it would leave
   the sidebar looking finished; a dead link would be worse than either.
   Phase 4C.29-UI-B2: single line, muted, no repeated text pill — the state is
   explained on the catalogue card instead. */
.nav-link.is-unavailable {
  /* Dimmed by colour, not by opacity: opacity on the whole link took the words to 3.9:1. */
  color: var(--hs-on-navy-dim);
  display: flex;
  align-items: center;
  gap: 11px;
  cursor: default;
}
.nav-link.is-unavailable:hover { background: transparent; color: var(--hs-on-navy-dim); }
.nav-link.is-unavailable > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-lock { margin-left: auto; flex: 0 0 auto; width: 13px; height: 13px; opacity: .8; }

.sidebar-foot {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid var(--hs-navy-2);
  font-size: 12px;
  color: var(--hs-on-navy-muted);
}
.sidebar-foot a { color: #9fb0d0; font-size: 13px; text-decoration: none; }
.sidebar-foot a:hover { color: #fff; }

/* --------------------------------------------------------------------------
   Topbar
   -------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  min-height: var(--hs-topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: var(--hs-surface);
  border-bottom: 1px solid #e6ebf1;
}
.topbar-title {
  margin: 0;
  font-family: var(--hs-font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--hs-navy);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.topbar-right a { color: #4b5563; text-decoration: none; font-size: 14px; }
.topbar-right a:hover { color: var(--hs-aqua); }

/* Two contexts, visibly different.
 *
 * Phase 4C.26A-parity. "Viewing" is the organisation on screen and grants
 * nothing; "Context" is the organisation the reader may act in. They sit side
 * by side and are styled apart on purpose — a reader looking at a practice
 * outside their memberships should be able to see that at a glance, and two
 * identical pills would read as one control with two values.
 */
.context-viewing { border-style: dashed; }
.context-value { font-variant-numeric: tabular-nums; padding: 2px 4px; }

/* The organisation/context selector. */
.context {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 12px;
  background: var(--hs-ground);
  border: 1px solid var(--hs-border);
  border-radius: 999px;
  font-size: 13px;
}
.context-label {
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--hs-ink-faint);
}
.context select {
  font: inherit;
  color: var(--hs-ink);
  background: transparent;
  border: 0;
  padding: 2px 4px;
  max-width: 34ch;
}
.context .kind {
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--hs-teal-deep);
  border: 1px solid var(--hs-border-strong);
  border-radius: 999px;
  padding: 1px 7px;
  background: var(--hs-surface);
}

/* --------------------------------------------------------------------------
   The mobile drawer — native checkbox control with a small keyboard enhancement
   -------------------------------------------------------------------------- */

/* UX2a. 44px square, the same as the label that shows it, so the control itself meets WCAG 2.5.8
   (and 2.5.5) by size rather than by exception. It stays invisible and out of the pointer path:
   a tap lands on the label, which is what opens the drawer. */
.nav-toggle-input { position: absolute; width: 44px; height: 44px; margin: 0; opacity: 0; pointer-events: none; }
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  margin-left: -10px;
  border: 0;
  background: transparent;
  color: #374151;
  cursor: pointer;
}
.shell:has(.nav-toggle-input:focus-visible) .nav-toggle { outline: 2px solid var(--hs-aqua); outline-offset: 2px; }
.backdrop { display: none; }

/* Wider than 991px the navigation is always shown and the label that opens the drawer is not displayed, so the checkbox has
   nothing to control and nowhere to show a focus ring: it was an invisible Tab stop. Take it out there, and only there.
   `not all and (max-width: 991px)` is the exact complement of the mobile block below, so no width (a fractional one from
   browser zoom, say) falls in a gap between the two. */
@media not all and (max-width: 991px) {
  .nav-toggle-input { display: none; }
}

@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); width: min(86vw, var(--hs-sidebar-w)); }
  /* The checkbox is in the header; the drawer is reached from it with :has(). A browser without :has() uses the class the
     script mirrors on .shell below (two separate rules: one unknown selector would discard a whole list). */
  .shell:has(.nav-toggle-input:checked) .sidebar { transform: translateX(0); }
  .shell:has(.nav-toggle-input:checked) .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, .45);
    z-index: 1035;
  }
  .shell.nav-open .sidebar { transform: translateX(0); }
  .shell.nav-open .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, .45);
    z-index: 1035;
  }
  .main { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
  .topbar { padding: 0 14px; gap: 10px; }
  .content { padding: 16px 14px 32px; }
  .topbar-right { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-section > summary::after, .skip-link { transition: none; }
}

/* --------------------------------------------------------------------------
   Components
   -------------------------------------------------------------------------- */

.page-head { margin: 0 0 20px; }
.eyebrow {
  margin: 0 0 6px;
  color: var(--hs-teal-deep);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
h1 { margin: 0 0 8px; font-size: 26px; line-height: 1.2; color: var(--hs-navy); text-wrap: balance; }
h2 { margin: 0 0 10px; font-size: 17px; color: var(--hs-navy); }
h3 { margin: 0 0 8px; font-size: 14px; color: var(--hs-navy); }
p { margin: 0 0 12px; max-width: var(--hs-measure); }
.lead { font-size: 17px; color: var(--hs-ink-muted); }
.muted { color: var(--hs-ink-muted); }

.card {
  background: var(--hs-surface);
  border: 1px solid var(--hs-border);
  border-radius: var(--hs-radius);
  box-shadow: var(--hs-shadow);
  padding: 20px 22px;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--hs-radius-sm);
  background: var(--hs-aqua);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: #0a4c9c; }
.btn-secondary { background: var(--hs-surface); color: var(--hs-ink); border-color: var(--hs-border-strong); }
.btn-secondary:hover { background: var(--hs-ground); }

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--hs-border); }
thead th {
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--hs-ink-muted);
  border-bottom: 1px solid var(--hs-border-strong);
}
tbody tr:last-child td { border-bottom: 0; }

/* State panels: loading, empty, unavailable and permission-denied all look
   deliberate rather than broken, and each says which one it is. */
.state {
  display: grid;
  gap: 8px;
  justify-items: start;
  padding: 28px 22px;
  border: 1px dashed var(--hs-border-strong);
  border-radius: var(--hs-radius);
  background: var(--hs-surface);
  color: var(--hs-ink-muted);
}
.state h2 { color: var(--hs-ink); }
.state-icon { width: 22px; height: 22px; color: var(--hs-ink-faint); }
.state.is-unavailable { background: var(--hs-info-bg); border-style: solid; }

.notice {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--hs-warn-border);
  border-left-width: 4px;
  border-radius: var(--hs-radius-sm);
  background: var(--hs-warn-bg);
  color: var(--hs-warn-ink);
  font-size: 14px;
}
.notice .icon { flex: none; width: 18px; height: 18px; margin-top: 2px; }
.notice p { margin: 0; max-width: none; }
.notice p + p { margin-top: 6px; }

.footer {
  padding: 18px 24px 28px;
  color: var(--hs-ink-faint);
  font-size: 12px;
}

.signed-out {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.signed-out .card { max-width: 460px; width: 100%; text-align: left; }

/* --------------------------------------------------------------------------
   The authorised workspace, in the sidebar
   --------------------------------------------------------------------------
   Phase 4C.26A-visual. The source keeps its workspace switcher directly under
   the brand, and that placement is the better one for the distinction this
   service draws: authority belongs beside the navigation it governs, and the
   organisation currently on screen belongs in the page chrome beside the page.
   Two regions separate them more plainly than two pills in one corner did. */
.workspace {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.workspace-label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hs-nav-heading);
}
.workspace-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--hs-aqua);
  flex: 0 0 auto;
}
/* The selected workspace in full, Phase 4C.26A-housekeeping. It wraps inside
   the sidebar rather than truncating, so a long Identity name and its code are
   readable without opening the list; nothing here is hidden behind a hover. */
.workspace-current {
  margin: 0 0 8px;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.workspace-current-code {
  display: inline-block;
  color: var(--hs-nav-heading);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.workspace select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  background: var(--hs-navy-2);
  color: #e6ebf4;
  font: inherit;
  font-size: 13px;
}
/* A disabled control still has to be readable: the browser default greys it
   into the navy it sits on. */
.workspace select:disabled { opacity: 1; color: #e6ebf4; }

/* The workspace control is a form, Phase 4C.26A-workspace.
 *
 * It was a disabled `<select>`, which is why a reader saw one organisation and
 * could not reach the others: the options were all in the markup and none of
 * them could be opened. Changing workspace is a POST, because it changes what
 * the reader may act in and — for a practice — what they are looking at. */
.workspace-change {
  width: 100%;
  margin-top: 8px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  background: var(--hs-navy-3);
  color: #e6ebf4;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.workspace-change:hover { background: var(--hs-aqua); border-color: var(--hs-aqua); }
.workspace-change:focus-visible { outline: 2px solid var(--hs-focus-on-navy); outline-offset: 2px; }

/* Phase 4C.26C. On paper the sidebar and the topbar are controls with nothing
   to control; the page's own heading names what was printed. */
@media print {
  .sidebar, .topbar { display: none !important; }
  .shell, .content { display: block; margin: 0; padding: 0; }
}
