/* ---------------------------------------------------------------------------
   Bonakude executive intelligence — application surface.

   Sits on top of m3-tokens.css (generated roles) and m3-layer.css (typescale,
   shape, state, motion). Colour here resolves to an --md-sys-color-* role or
   to a PINNED brand value, never to a loose literal.

   Pinned brand values, and why: the Treasury-aligned reference reports fixed
   the Bonakude identity, and the workstream brief required it be carried into
   the platform. Two values are therefore held fixed rather than taken from the
   generated scheme, and the rest of the surface uses M3 neutral roles.
--------------------------------------------------------------------------- */
/* Typefaces are self-hosted (app/www/fonts.css), not fetched from Google.
   See that file for why. */

:root {
  /* ── Pinned brand (reference-report identity) ───────────────────────── */
  --bk-ink: #0F2032;        /* brand surface: the navigation shell and covers */
  --bk-accent: #49C0DF;     /* brand accent: rules, eyebrows, the active mark */
  --bk-on-ink: #FFFFFF;
  --bk-on-ink-muted: #C7D4DE;
  --bk-on-ink-faint: #6B8096;

  /* The M3 primary role is pinned to the brand accent so state layers,
     focus rings and links all resolve to one brand colour. */
  --md-sys-color-primary: var(--bk-accent);

  /* ── Status. M3 ships only `error`; success/warning/info are M3 custom
        colour groups. They must stay visually distinct from brand action. ── */
  --bk-good: #1E7F5C;
  --bk-warn: #B07D1A;
  --bk-serious: #C4561B;
  --bk-critical: #A32A2A;

  /* ── Density. Deliberately tighter than M3's phone-first default: this is
        an analytical register surface, not a consumer one. ───────────────── */
  --bk-gutter: 26px;
  --bk-panel-pad: 15px 17px;
  --bk-nav-w: 252px;

  /* A filled button must stay legible on its own surface. The brand ink is
     fixed, so on a dark surface it would sit almost invisibly against it;
     the accent carries the brand there instead. Pinned brand values, chosen
     per surface -- not a generated M3 role. */
  --bk-btn-bg: var(--bk-ink);
  --bk-btn-fg: var(--bk-on-ink);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bk-good: #4FBF91;
    --bk-warn: #D9A94A;
    --bk-serious: #E58A54;
    --bk-critical: #E97070;
    --bk-btn-bg: var(--bk-accent);
    --bk-btn-fg: #0F1416;
  }
}
:root[data-theme="dark"] {
  --bk-good: #4FBF91;
  --bk-warn: #D9A94A;
  --bk-serious: #E58A54;
  --bk-critical: #E97070;
  --bk-btn-bg: var(--bk-accent);
  --bk-btn-fg: #0F1416;
}

/* ── Root sizing ───────────────────────────────────────────────────────────
   Bootstrap 3 sets `html { font-size: 10px }`. The entire M3 typescale is
   authored in rem against a 16px root, so every type size in this stylesheet
   was rendering at 62.5% of specification: body text at 8.75px instead of
   14px, table cells at 7.5px instead of 12px, measure labels at 6.875px.
   Restoring the root to the browser default is what makes the typescale
   mean what it says. */
html { font-size: 100%; }

* { box-sizing: border-box; }

body {
  font-family: 'Poppins', -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  font-weight: 300;
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-low);
  margin: 0;
}
h1, h2, h3, h4, .wordmark { font-family: 'Montserrat', Helvetica, Arial, sans-serif; }

/* ── Shell ───────────────────────────────────────────────────────────────── */
.bk-shell { display: flex; min-height: 100vh; }

/* The navigation keeps the Bonakude brand surface rather than an M3
   surface-container. Brand identity was explicitly in scope to preserve. */
.bk-nav {
  width: var(--bk-nav-w); flex: 0 0 var(--bk-nav-w);
  background: var(--bk-ink); color: var(--bk-on-ink);
  padding: 18px 0 28px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.bk-brand {
  display: flex; align-items: center; gap: 9px; padding: 0 18px 16px;
  border-bottom: 1px solid rgb(255 255 255 / 0.1);
}
.bk-brand .wordmark {
  font-size: 0.9375rem; font-weight: 700; letter-spacing: 0.2em; color: var(--bk-on-ink);
}
.bk-navgroup {
  font-size: 0.6875rem; line-height: 1rem; font-weight: 500; letter-spacing: 0.03125rem;
  text-transform: uppercase; color: var(--bk-on-ink-faint); padding: 18px 18px 6px;
}
.bk-navitem {
  display: block; padding: 8px 18px; color: var(--bk-on-ink-muted);
  text-decoration: none; cursor: pointer;
  font-size: 0.875rem; line-height: 1.25rem; font-weight: 400; letter-spacing: 0.00625rem;
  border-left: 3px solid transparent;
  transition: color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  /* Touch target: 8px + 20px line + 8px = 36px; raised to 44 on a phone. */
  min-height: 36px;
}
.bk-navitem:hover { color: var(--bk-on-ink); }
.bk-navitem.active {
  border-left-color: var(--bk-accent); color: var(--bk-on-ink); font-weight: 500;
}
.bk-navitem.active::after { opacity: var(--md-sys-state-focus-state-layer-opacity); }
.bk-navitem .bk-dnum {
  color: var(--bk-accent); font-weight: 600; margin-right: 7px;
  font-size: 0.6875rem; letter-spacing: 0.03125rem;
}
.bk-main { flex: 1; min-width: 0; padding: 0 var(--bk-gutter) 40px; }

/* ── Header and context bar ─────────────────────────────────────────────── */
.bk-head {
  padding: 20px 0 14px; border-bottom: 2px solid var(--bk-accent); margin-bottom: 18px;
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 22px; flex-wrap: wrap;
}
.bk-head h1 {
  margin: 0; font-size: 1.375rem; line-height: 1.75rem; font-weight: 600;
  letter-spacing: 0; color: var(--md-sys-color-on-surface);
}
.bk-head .bk-q {
  margin: 4px 0 0; max-width: 68ch; color: var(--md-sys-color-on-surface-variant);
  font-size: 0.875rem; line-height: 1.25rem; letter-spacing: 0.015625rem;
}
.bk-ctxbar {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 11px 14px; margin-bottom: 16px;
}
.bk-ctxbar .form-group { margin: 0; }
.bk-ctxbar label {
  font-size: 0.6875rem; line-height: 1rem; font-weight: 500; letter-spacing: 0.03125rem;
  text-transform: uppercase; color: var(--md-sys-color-on-surface-variant); margin-bottom: 3px;
}
.bk-ctxbar .shiny-input-container { width: auto; min-width: 150px; }
.bk-ctxbar select.form-control, .bk-ctxbar .form-control {
  border-radius: var(--md-sys-shape-corner-extra-small);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  min-height: 40px;
}
.bk-scope {
  font-size: 0.75rem; line-height: 1rem; letter-spacing: 0.025rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-left: auto; text-align: right;
}

/* ── Key message band ───────────────────────────────────────────────────── */
.bk-message {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-left: 3px solid var(--bk-accent);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 13px 17px; margin: 0 0 16px;
  font-size: 0.875rem; line-height: 1.375rem; letter-spacing: 0.015625rem;
  color: var(--md-sys-color-on-surface);
}
.bk-message strong { font-weight: 600; }

/* ── Measure row ────────────────────────────────────────────────────────── */
.bk-measures {
  display: flex; flex-wrap: wrap;
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  overflow: hidden; margin-bottom: 18px;
}
.bk-measure {
  flex: 1 1 0; min-width: 168px; padding: 12px 15px;
  border-right: 1px solid var(--md-sys-color-outline-variant);
}
.bk-measure:last-child { border-right: none; }
.bk-measure .k {
  display: block; margin-bottom: 5px;
  font-size: 0.6875rem; line-height: 1rem; font-weight: 500; letter-spacing: 0.03125rem;
  text-transform: uppercase; color: var(--md-sys-color-on-surface-variant);
}
.bk-measure .v {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.75rem; line-height: 2.25rem; font-weight: 600; letter-spacing: 0;
  color: var(--md-sys-color-on-surface);
}
.bk-measure .v.na {
  font-family: 'Poppins', sans-serif; font-size: 0.875rem; font-weight: 400;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-measure .d {
  display: block; margin-top: 5px;
  font-size: 0.75rem; line-height: 1rem; letter-spacing: 0.025rem;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-measure .mv {
  display: inline-block; margin-left: 6px; vertical-align: baseline;
  font-size: 0.75rem; line-height: 1rem; font-weight: 500; letter-spacing: 0.03125rem;
}
.mv.up   { color: var(--bk-good); }
.mv.down { color: var(--bk-serious); }
.mv.flat { color: var(--md-sys-color-on-surface-variant); }

/* ── Panels ─────────────────────────────────────────────────────────────── */
.bk-panel {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: var(--bk-panel-pad); margin-bottom: 18px;
}
.bk-panel > h3 {
  margin: 0 0 3px;
  font-size: 1rem; line-height: 1.5rem; font-weight: 600; letter-spacing: 0.009375rem;
  color: var(--md-sys-color-on-surface);
}
.bk-panel .why {
  margin: 0 0 11px; max-width: 100ch;
  font-size: 0.75rem; line-height: 1.125rem; letter-spacing: 0.025rem;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-panel .src {
  margin-top: 10px; padding-top: 8px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  font-size: 0.6875rem; line-height: 1rem; letter-spacing: 0.03125rem;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-cap {
  margin-bottom: 3px;
  font-size: 0.6875rem; line-height: 1rem; font-weight: 500; letter-spacing: 0.03125rem;
  text-transform: uppercase; color: var(--md-sys-color-primary);
  filter: brightness(0.72);
}
.bk-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1180px) { .bk-cols { grid-template-columns: 1fr; } }

/* ── Chips. M3 chips are corner-small. ──────────────────────────────────── */
.chip {
  display: inline-block; margin-right: 5px; padding: 2px 8px;
  border: 1px solid; border-radius: var(--md-sys-shape-corner-small);
  font-size: 0.6875rem; line-height: 1rem; font-weight: 500; letter-spacing: 0.03125rem;
}
.chip.critical { color: var(--bk-critical); border-color: var(--bk-critical);
                 background: color-mix(in srgb, var(--bk-critical) 10%, transparent); }
.chip.high     { color: var(--bk-serious);  border-color: var(--bk-serious);
                 background: color-mix(in srgb, var(--bk-serious) 10%, transparent); }
.chip.medium   { color: var(--bk-warn);     border-color: var(--bk-warn);
                 background: color-mix(in srgb, var(--bk-warn) 10%, transparent); }
.chip.low      { color: var(--md-sys-color-on-surface-variant);
                 border-color: var(--md-sys-color-outline-variant);
                 background: var(--md-sys-color-surface-container); }
.chip.neutral  { color: var(--md-sys-color-on-secondary-container);
                 border-color: var(--md-sys-color-outline-variant);
                 background: var(--md-sys-color-secondary-container); }
.chip.good     { color: var(--bk-good); border-color: var(--bk-good);
                 background: color-mix(in srgb, var(--bk-good) 10%, transparent); }

/* ── Provenance marker ──────────────────────────────────────────────────── */
.prov {
  display: inline-block; margin-left: 6px; padding: 1px 6px; vertical-align: middle;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.625rem; line-height: 0.875rem; font-weight: 500;
  letter-spacing: 0.03125rem; text-transform: uppercase;
}
.prov.syn  { border-color: color-mix(in srgb, var(--bk-warn) 45%, transparent); color: var(--bk-warn); }
.prov.prop { border-color: color-mix(in srgb, #7E57C2 45%, transparent); color: #6B4E8F; }

/* ── Limitation band ────────────────────────────────────────────────────── */
.bk-limit {
  border: 1px solid color-mix(in srgb, var(--bk-warn) 40%, transparent);
  background: color-mix(in srgb, var(--bk-warn) 7%, var(--md-sys-color-surface-container-lowest));
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 11px 14px; margin: 0 0 14px;
  font-size: 0.75rem; line-height: 1.125rem; letter-spacing: 0.025rem;
  color: var(--md-sys-color-on-surface);
}
.bk-limit .lbl {
  display: block; margin-bottom: 4px;
  font-size: 0.6875rem; line-height: 1rem; font-weight: 500; letter-spacing: 0.03125rem;
  text-transform: uppercase; color: var(--bk-warn);
}

/* ── Registers ─────────────────────────────────────────────────────────────
   M3 has NO data table component. This is the platform's own component under
   an M3 theme: it takes the token layer, the typescale and the state layer,
   and nothing is "corrected" against a spec that does not exist. */
table.dataTable { font-size: 0.75rem !important; }
table.dataTable thead th {
  background: var(--bk-ink) !important; color: var(--bk-on-ink) !important;
  font-weight: 500 !important; font-size: 0.6875rem !important;
  letter-spacing: 0.03125rem !important; border: none !important;
}
table.dataTable tbody td {
  padding: 7px 9px !important;
  border-bottom: 1px solid var(--md-sys-color-outline-variant) !important;
  color: var(--md-sys-color-on-surface) !important;
}
table.dataTable tbody tr:nth-child(even) { background: var(--md-sys-color-surface-container-low); }
@media (hover: hover) {
  table.dataTable tbody tr:hover { background: var(--md-sys-color-surface-container); }
}
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  padding: 4px 8px; min-height: 32px;
}
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate,
.dataTables_wrapper label {
  color: var(--md-sys-color-on-surface-variant) !important;
  font-size: 0.75rem; letter-spacing: 0.025rem;
}
.dataTables_wrapper .paginate_button {
  border-radius: var(--md-sys-shape-corner-extra-small) !important;
  min-height: 32px;
}
.dataTables_wrapper .paginate_button.current {
  background: var(--md-sys-color-secondary-container) !important;
  color: var(--md-sys-color-on-secondary-container) !important;
  border-color: var(--md-sys-color-outline-variant) !important;
}

/* ── Buttons. M3 buttons are corner-full. ───────────────────────────────── */
.btn-bk, .btn.btn-bk, .shiny-download-link.btn-bk {
  background: var(--bk-ink); color: var(--bk-on-ink);
  border: none; border-radius: var(--md-sys-shape-corner-full);
  padding: 9px 18px; min-height: 40px;
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; letter-spacing: 0.00625rem;
  text-decoration: none; display: inline-flex; align-items: center; gap: 7px;
  transition: background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
.btn-bk:hover, .btn-bk:focus { background: var(--bk-ink); color: var(--bk-on-ink); }
/* DataTables' own export button inherits the shape but stays secondary. It
   must carry an outline, or on a dark surface the container tone alone leaves
   it almost invisible. */
.dt-buttons .btn-bk, .dt-buttons .dt-button {
  background: var(--md-sys-color-secondary-container) !important;
  color: var(--md-sys-color-on-secondary-container) !important;
  border: 1px solid var(--md-sys-color-outline) !important;
  border-radius: var(--md-sys-shape-corner-full) !important;
  min-height: 32px; padding: 6px 14px !important;
  font-size: 0.75rem; font-weight: 500; letter-spacing: 0.03125rem;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.bk-foot {
  margin-top: 26px; padding: 14px 0 0;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  font-size: 0.75rem; line-height: 1.125rem; letter-spacing: 0.025rem;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-foot strong { color: var(--md-sys-color-on-surface); font-weight: 600; }

/* ── Phone. The 44px target is kept: it is stronger than WCAG 2.5.8's
      24x24 floor and stronger than M3's baseline. ───────────────────────── */
@media (max-width: 640px) {
  :root { --bk-gutter: 16px; }
  .bk-shell { flex-direction: column; }
  /* At compact width the navigation becomes a SCROLLABLE ROW, not a
     persistent drawer. M3's adaptive guidance is explicit that a persistent
     drawer is for expanded widths; left stacked, these 15 destinations filled
     a whole phone screen before any content began. The row is the same
     pattern as M3's scrollable primary tabs, and it needs no JavaScript and
     no change to the markup. */
  .bk-nav {
    width: 100%; max-width: 100%; flex: none; height: auto;
    position: sticky; top: 0; z-index: 20;
    display: flex; flex-direction: row; align-items: stretch;
    gap: 2px; overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding: 0 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
  }
  /* The group headings are a vertical-list affordance; in a row they would
     read as destinations. M3 tabs carry no group label either. */
  .bk-nav .bk-navgroup { display: none; }
  /* The brand is a banner, not a destination: at phone width it must not eat
     the row the destinations scroll in. */
  .bk-brand { flex: 0 0 auto; padding-right: 10px; }
  .bk-brand span[style] { display: none; }
  .bk-navitem {
    flex: 0 0 auto;
    min-height: 44px; display: flex; align-items: center;
    white-space: nowrap;
  }
  /* The active destination needs an indicator that survives the row layout;
     the drawer's full-bleed state layer does not read horizontally. */
  .bk-navitem.active { box-shadow: inset 0 -3px 0 0 var(--bk-accent); }
  .btn-bk { min-height: 44px; }
  .bk-measure { flex: 1 1 100%; border-right: none;
                border-bottom: 1px solid var(--md-sys-color-outline-variant); }
  /* Shiny writes each filter's width as an INLINE style (selectInput(width=)),
     so at phone width the controls rendered at six different widths, centred,
     and read as a staggered ladder. An inline style can only be beaten with
     !important -- the alternative is removing the widths the desktop layout
     needs. The label and control are then flush left in one column. */
  .bk-ctxbar .shiny-input-container,
  .bk-ctxbar .form-group { width: 100% !important; min-width: 0; }
  .bk-ctxbar .selectize-control,
  .bk-ctxbar .selectize-input { width: 100%; }
  .bk-head { flex-direction: column; align-items: flex-start; }
}

/* ── Phone touch targets ───────────────────────────────────────────────────
   A 44px minimum on phone. This is stronger than WCAG 2.2's 24x24 floor and
   stronger than M3's baseline, and it is kept deliberately: Audit 360 holds
   the same rule, and these controls (scope filters, table paging and search)
   are the ones a reader actually drives the page with.

   The three controls below come from Shiny's selectize and from DataTables,
   so their height is set by vendor CSS rather than by this stylesheet; they
   are raised here rather than by overriding the vendor files. The selectize
   TARGET is `.selectize-input` -- the inner <input> is not independently
   tappable, so it is deliberately not sized. */
@media (max-width: 640px) {
  .selectize-input {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .dataTables_wrapper .dataTables_filter input {
    min-height: 44px;
    box-sizing: border-box;
  }
  /* DataTables styles this with a three-class selector AND its stylesheet is
     injected after this one, so an equal-specificity rule loses on cascade
     order. The shell class lifts this above it without !important. A
     two-class selector silently set only min-height -- the one property
     DataTables does not itself set -- which is why the height moved and the
     width did not. */
  .bk-shell .dataTables_wrapper .dataTables_paginate .paginate_button {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }
}

/* ── Sparklines on measure tiles ───────────────────────────────────────────
   The sparkline is inline SVG and takes its colour from `currentColor`, so it
   is correct in both schemes with no server round-trip. The tile is the
   control; the sparkline is not independently clickable. */
.bk-measure {
  position: relative;
  cursor: pointer;
  display: flex; flex-direction: column;
}
.bk-measure .sp-slot {
  display: block; margin-top: auto; padding-top: 10px;
  color: var(--bk-accent);
}
.bk-spark {
  display: block; width: 100%; height: 28px; overflow: visible;
}
.sp-line { fill: none; stroke: currentColor; stroke-width: 1.6px;
           stroke-linejoin: round; stroke-linecap: round; }
.sp-area { fill: currentColor; opacity: 0.14; stroke: none; }
.sp-dot  { fill: currentColor; stroke: var(--md-sys-color-surface-container-lowest); stroke-width: 1.2; }
/* A caveat is not a label: it says the line must not be read as a trend. */
.sp-cav {
  display: block; padding-top: 6px;
  font-size: 0.6875rem; line-height: 1rem; letter-spacing: 0.03125rem;
  color: var(--md-sys-color-on-surface-variant);
}
/* bslib reveals the expand affordance on hover. It is shown here at rest too,
   faintly: a hover-only affordance does not exist on a touch device. */
.bk-measure .sp-cue {
  position: absolute; top: 10px; right: 12px;
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.35;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) { .bk-measure:hover .sp-cue { opacity: 1; } }
.bk-measure:focus-visible .sp-cue { opacity: 1; }

/* ── Expanded measure ──────────────────────────────────────────────────────
   A centred dialog on laptop, a full-viewport sheet on phone. */
.bk-sheet {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  /* The scrim has to actually suppress the page behind it: at 55% the
     registers and exhibits stayed legible and competed with the dialog. */
  background: color-mix(in srgb, var(--md-sys-color-scrim) 78%, transparent);
  backdrop-filter: blur(2px);
}
.bk-sheet-panel {
  width: min(860px, 100%); max-height: calc(100vh - 48px); overflow-y: auto;
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: 20px 22px 22px;
}
.bk-sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.bk-sheet-head .k {
  display: block; font-size: 0.6875rem; line-height: 1rem; font-weight: 500;
  letter-spacing: 0.03125rem; text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-sheet-head .v {
  display: block; font-family: 'Montserrat', sans-serif;
  font-size: 2.25rem; line-height: 2.75rem; font-weight: 600;
  color: var(--md-sys-color-on-surface);
}
.bk-sheet-head .kid {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 4px;
  font-size: 0.75rem; letter-spacing: 0.025rem;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-sheet-close {
  flex: 0 0 auto; width: 40px; height: 40px;
  background: none; border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-on-surface);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.bk-sheet-plot { margin-top: 14px; }
.bk-sheet-cav {
  margin-top: 12px; padding: 10px 12px;
  border-left: 3px solid var(--bk-accent);
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-extra-small);
  font-size: 0.8125rem; line-height: 1.25rem;
  color: var(--md-sys-color-on-surface);
}
.bk-sheet-basis { margin-top: 14px; }
.bk-sheet-basis p {
  margin: 0 0 8px; font-size: 0.8125rem; line-height: 1.25rem;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-sheet-basis p.agg { color: var(--md-sys-color-on-surface-variant); font-style: italic; }
.bk-sheet-table { margin-top: 10px; }
.bk-sheet-table table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.bk-sheet-table th, .bk-sheet-table td {
  padding: 6px 8px; border-bottom: 1px solid var(--md-sys-color-outline-variant);
  text-align: left; color: var(--md-sys-color-on-surface);
}
.bk-sheet-table th {
  font-size: 0.6875rem; font-weight: 500; letter-spacing: 0.03125rem;
  text-transform: uppercase; color: var(--md-sys-color-on-surface-variant);
}
.bk-sheet-table td.num, .bk-sheet-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* The rows the tile's year-on-year movement actually compares. */
.bk-sheet-table tr.same td { background: color-mix(in srgb, var(--bk-accent) 12%, transparent); }

@media (max-width: 640px) {
  .bk-sheet { padding: 0; align-items: stretch; }
  .bk-sheet-panel {
    width: 100%; max-height: 100vh; border-radius: 0; border: none;
  }
  /* The 44px phone minimum applies to the dialog's own control too. */
  .bk-sheet-close { width: 44px; height: 44px; }
  .bk-measure .sp-cue { top: 12px; right: 12px; }
}

/* ── Tooltips and popovers ─────────────────────────────────────────────────
   Bootstrap 3's own plugins, restyled onto the M3 role layer. Bootstrap's
   defaults are a black box with a hardcoded arrow, which reads as a foreign
   object on both surfaces. */
.tooltip { font-family: 'Poppins', sans-serif; z-index: 1200; }
.tooltip-inner {
  max-width: 280px; padding: 7px 10px;
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  border-radius: var(--md-sys-shape-corner-extra-small);
  font-size: 0.75rem; line-height: 1rem; letter-spacing: 0.025rem;
  text-align: left;
}
.tooltip.top .tooltip-arrow    { border-top-color: var(--md-sys-color-inverse-surface); }
.tooltip.bottom .tooltip-arrow { border-bottom-color: var(--md-sys-color-inverse-surface); }
.tooltip.left .tooltip-arrow   { border-left-color: var(--md-sys-color-inverse-surface); }
.tooltip.right .tooltip-arrow  { border-right-color: var(--md-sys-color-inverse-surface); }

.popover {
  font-family: 'Poppins', sans-serif; z-index: 1200;
  max-width: 340px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}
.popover-title {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium) var(--md-sys-shape-corner-medium) 0 0;
  font-size: 0.75rem; font-weight: 500; letter-spacing: 0.03125rem;
  text-transform: uppercase; padding: 9px 12px;
}
.popover-content {
  color: var(--md-sys-color-on-surface);
  font-size: 0.8125rem; line-height: 1.25rem; padding: 11px 12px;
}
/* Bootstrap paints the arrow with hardcoded light values. */
.popover.top > .arrow::after    { border-top-color: var(--md-sys-color-surface-container-high); }
.popover.bottom > .arrow::after { border-bottom-color: var(--md-sys-color-surface-container-highest); }
.popover.left > .arrow::after   { border-left-color: var(--md-sys-color-surface-container-high); }
.popover.right > .arrow::after  { border-right-color: var(--md-sys-color-surface-container-high); }
.popover.top > .arrow    { border-top-color: var(--md-sys-color-outline-variant); }
.popover.bottom > .arrow { border-bottom-color: var(--md-sys-color-outline-variant); }
.popover.left > .arrow   { border-left-color: var(--md-sys-color-outline-variant); }
.popover.right > .arrow  { border-right-color: var(--md-sys-color-outline-variant); }

/* A trigger must look like one. */
[data-toggle="popover"] { cursor: pointer; }
.prov[data-toggle="popover"]:hover,
.prov[data-toggle="popover"]:focus-visible { text-decoration: underline dotted; }

/* ── Issued report library ─────────────────────────────────────────────────
   A document register: each row states what the document is, who it is for,
   and the integrity metadata a recipient needs. */
.bk-docs { display: flex; flex-direction: column; gap: 12px; }
.bk-doc {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
  padding: 16px 18px;
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
}
.bk-doc-main { min-width: 0; }
.bk-doc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.bk-doc-head .ref {
  font-size: 0.6875rem; font-weight: 500; letter-spacing: 0.03125rem;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-doc-head .kind {
  padding: 1px 7px; border-radius: var(--md-sys-shape-corner-full);
  font-size: 0.625rem; font-weight: 500; letter-spacing: 0.0375rem;
  text-transform: uppercase;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.bk-doc h3 {
  margin: 0 0 5px; font-family: 'Montserrat', sans-serif;
  font-size: 1rem; line-height: 1.5rem; font-weight: 600;
  color: var(--md-sys-color-on-surface);
}
.bk-doc .purpose {
  margin: 0 0 9px; max-width: 72ch;
  font-size: 0.8125rem; line-height: 1.25rem;
  color: var(--md-sys-color-on-surface-variant);
}
.bk-doc-meta {
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 0.75rem; line-height: 1rem; color: var(--md-sys-color-on-surface-variant);
}
.bk-doc-meta code {
  font-size: 0.6875rem; padding: 1px 4px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-extra-small);
  color: var(--md-sys-color-on-surface);
}
.bk-doc-meta .aud { font-style: italic; }
.bk-doc-act { flex: 0 0 auto; }
.bk-doc-act .missing { font-size: 0.75rem; color: var(--bk-serious); }
.bk-doc-note {
  align-self: center; margin-left: 12px;
  font-size: 0.75rem; color: var(--md-sys-color-on-surface-variant);
}
@media (max-width: 640px) {
  .bk-doc { flex-direction: column; gap: 12px; }
  .bk-doc-act, .bk-doc-act .btn-bk { width: 100%; }
}

/* ── Register row detail ───────────────────────────────────────────────────
   The expand control and the record panel a row opens to. */
td.bk-detail-control {
  cursor: pointer; width: 26px; text-align: center;
  color: var(--bk-accent); font-size: 12px; user-select: none;
}
tr.bk-open > td { background: var(--md-sys-color-surface-container) !important; }
.bk-rowdetail {
  padding: 12px 14px;
  background: var(--md-sys-color-surface-container-low);
  border-left: 3px solid var(--bk-accent);
}
.bk-dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
         gap: 8px 22px; margin: 0; }
.bk-dl .dli { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.bk-dl dt {
  font-size: 0.625rem; font-weight: 500; letter-spacing: 0.0375rem;
  text-transform: uppercase; color: var(--md-sys-color-on-surface-variant);
}
.bk-dl dd {
  margin: 0; font-size: 0.8125rem; line-height: 1.25rem;
  color: var(--md-sys-color-on-surface); overflow-wrap: anywhere;
}
/* The per-column filter row DataTables adds above the body. */
.dataTables_wrapper thead tr:nth-child(2) th { padding-top: 2px; padding-bottom: 6px; }
.dataTables_wrapper thead input[type="search"],
.dataTables_wrapper thead input:not([type]) {
  width: 100%; box-sizing: border-box;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-small);
  color: var(--md-sys-color-on-surface);
  font-size: 0.75rem; padding: 3px 6px;
}
.dataTables_wrapper .dataTables_length select {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-small);
}
.bk-empty { color: var(--md-sys-color-on-surface-variant); font-size: 0.8125rem; }
@media (max-width: 640px) { .bk-dl { grid-template-columns: 1fr; } }

/* A full SHA-256 shown in a popover must wrap, not overflow it. */
.popover-content code.sha { word-break: break-all; display: block; }

/* ── Graceful failure ──────────────────────────────────────────────────────
   A failed section says so. It never shows a stack trace, and it never shows
   an empty frame, because silence reads as "nothing to report". */
.bk-error {
  margin-bottom: 16px; padding: 12px 15px;
  background: var(--md-sys-color-surface-container);
  border-left: 3px solid var(--bk-serious);
  border-radius: var(--md-sys-shape-corner-extra-small);
  font-size: 0.8125rem; line-height: 1.25rem;
  color: var(--md-sys-color-on-surface);
}
.bk-error .bk-why {
  margin-left: 6px; text-decoration: underline dotted; cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
}

/* ── Exhibit hover readout ─────────────────────────────────────────────────
   The record behind the mark under the cursor. It is positioned by the client
   and filled by the server, so it follows the pointer without lag. */
#bk-hovertip {
  position: fixed; z-index: 1300; display: none;
  max-width: 330px; padding: 10px 12px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  pointer-events: none;
}
.bk-hover-body { display: flex; flex-direction: column; gap: 3px; }
.bk-hover-body .hi { display: flex; justify-content: space-between; gap: 14px; }
.bk-hover-body .hk {
  font-size: 0.625rem; font-weight: 500; letter-spacing: 0.0375rem;
  text-transform: uppercase; color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
}
.bk-hover-body .hv {
  font-size: 0.75rem; line-height: 1rem; text-align: right;
  color: var(--md-sys-color-on-surface); font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.shiny-plot-output img { cursor: crosshair; }

/* The operations entry is rendered by the SERVER for an authorised session,
   so it must not also be hidden here: a CSS rule would then suppress the very
   element the server only emits when it should be visible. */

/* ══ Material 3 control layer ══════════════════════════════════════════════
   One button specification for the whole application. Previously the filled
   buttons had no state layer at all (hover and focus repainted the same
   colour), DataTables' export buttons were a separate look, and the page
   length select was browser default. M3 heights (40dp), corner-full shape,
   label-large type and state layers now apply to all of them. */

/* ── Filled button: the primary action on a surface ─────────────────────── */
.btn-bk, .btn.btn-bk, .shiny-download-link.btn-bk {
  position: relative; isolation: isolate; overflow: hidden;
  background: var(--bk-ink); color: var(--bk-on-ink);
  border: none; border-radius: var(--md-sys-shape-corner-full);
  height: 40px; padding: 0 24px; min-height: 40px;
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; letter-spacing: 0.00625rem;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; cursor: pointer;
}
/* M3 raises hover/press with a state layer of the element's OWN content
   colour, not by repainting the container. */
.btn-bk::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  background: currentColor; opacity: 0; z-index: -1; pointer-events: none;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) { .btn-bk:hover::after { opacity: 0.08; } }
.btn-bk:focus-visible::after { opacity: 0.12; }
.btn-bk:active::after { opacity: 0.12; }
.btn-bk:hover, .btn-bk:focus { background: var(--bk-ink); color: var(--bk-on-ink); }

/* ── Outlined button: the table actions, which are secondary ────────────── */
.dt-buttons .dt-button, .dt-buttons .btn-bk, .dt-buttons button.dt-button {
  position: relative; isolation: isolate; overflow: hidden;
  background: transparent !important;
  color: var(--md-sys-color-on-surface) !important;
  border: 1px solid var(--md-sys-color-outline) !important;
  border-radius: var(--md-sys-shape-corner-full) !important;
  height: 40px; padding: 0 16px !important; margin: 0 6px 8px 0 !important;
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; letter-spacing: 0.00625rem;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: none !important; cursor: pointer;
}
.dt-buttons .dt-button::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  background: currentColor; opacity: 0; z-index: -1; pointer-events: none;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) { .dt-buttons .dt-button:hover::after { opacity: 0.08; } }
.dt-buttons .dt-button:focus-visible::after { opacity: 0.12; }
.dt-buttons .dt-button:active::after { opacity: 0.12; }
.dt-buttons { margin-bottom: 4px; }

/* ── Select: the page-length control, and every other select ────────────── */
/* DataTables injects its stylesheet when the widget renders -- after this
   one -- and styles these with a higher-specificity selector, so an
   equal-specificity rule loses on both counts. The shell class lifts it. */
.bk-shell .dataTables_wrapper .dataTables_length select,
.bk-shell .dataTables_wrapper .dataTables_length .form-control {
  height: 40px; min-width: 76px; padding: 0 32px 0 12px;
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem; line-height: 1.25rem; letter-spacing: 0.015625rem;
  -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: 0.8125rem; color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 10px;
}
.bk-shell .dataTables_wrapper .dataTables_filter input {
  height: 40px; padding: 0 12px; min-width: 220px;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  font-size: 0.875rem;
}

/* ── Theme toggle ──────────────────────────────────────────────────────── */
.bk-topbar { display: flex; justify-content: flex-end; padding: 10px 0 0; }
.bk-themebtn {
  position: relative; isolation: isolate;
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
  font-family: 'Poppins', sans-serif;
  font-size: 0.75rem; font-weight: 500; letter-spacing: 0.03125rem;
  cursor: pointer;
}
.bk-themebtn .ic { flex: 0 0 auto; }
@media (max-width: 640px) { .bk-themebtn { height: 44px; } }

/* ── Selects and text inputs ───────────────────────────────────────────────
   Shiny's selectize and Bootstrap's form controls ship a hardcoded white
   field. On the dark surface those read as bright rectangles punched through
   the page, so they are mapped onto the M3 roles and follow the theme. */
.selectize-input,
.selectize-control.single .selectize-input,
.form-control, input[type="text"], input[type="search"], select {
  /* background-COLOR, not the shorthand: the shorthand resets background-image
     and erased the select's dropdown arrow. */
  background-color: var(--md-sys-color-surface-container) !important;
  color: var(--md-sys-color-on-surface) !important;
  border: 1px solid var(--md-sys-color-outline) !important;
  border-radius: var(--md-sys-shape-corner-extra-small) !important;
  box-shadow: none !important;
  font-family: 'Poppins', sans-serif;
}
.selectize-input.focus { border-color: var(--bk-accent) !important; }
.selectize-input > input, .selectize-input .item { color: var(--md-sys-color-on-surface) !important; }
.selectize-control.single .selectize-input::after { border-top-color: var(--md-sys-color-on-surface-variant) !important; }
.selectize-dropdown, .selectize-dropdown.single {
  background: var(--md-sys-color-surface-container-high) !important;
  color: var(--md-sys-color-on-surface) !important;
  border: 1px solid var(--md-sys-color-outline-variant) !important;
  border-radius: var(--md-sys-shape-corner-extra-small) !important;
}
.selectize-dropdown .option { color: var(--md-sys-color-on-surface) !important; }
.selectize-dropdown .active {
  background: var(--md-sys-color-secondary-container) !important;
  color: var(--md-sys-color-on-secondary-container) !important;
}
/* The scope bar's labels follow the surface too. */
.bk-ctxbar label, .shiny-input-container label {
  color: var(--md-sys-color-on-surface-variant);
}

/* The filled button now takes its colour from the per-surface token. */
.btn-bk, .btn.btn-bk, .shiny-download-link.btn-bk,
.btn-bk:hover, .btn-bk:focus {
  background: var(--bk-btn-bg); color: var(--bk-btn-fg);
}

/* ── Phone: table controls must not widen the page ─────────────────────────
   Restoring the 16px root made the table toolbar wider than a phone
   viewport, which pushed the whole page into horizontal scroll. The table
   itself may scroll sideways; the PAGE may not. */
@media (max-width: 640px) {
  .bk-panel, .bk-main, .bk-measures { min-width: 0; max-width: 100%; }
  .dataTables_wrapper { width: 100%; max-width: 100%; overflow-x: hidden; }
  .dataTables_wrapper .dataTables_scroll,
  .dataTables_wrapper .dataTables_scrollHead,
  .dataTables_wrapper .dataTables_scrollBody { max-width: 100%; }
  .dataTables_wrapper .dataTables_filter { display: flex; width: 100%; }
  .dataTables_wrapper .dataTables_filter label { display: flex; width: 100%; gap: 8px; }
  .dataTables_wrapper .dataTables_filter input { min-width: 0; width: 100%; }
  .dataTables_wrapper .dataTables_length { width: 100%; }
  .dt-buttons { display: flex; flex-wrap: wrap; width: 100%; }
  .dt-buttons .dt-button { flex: 0 1 auto; }
  .dataTables_wrapper .dataTables_paginate { float: none; width: 100%; }
  .bk-doc-meta { max-width: 100%; }
  /* The two report buttons sit side by side at 183px each. At 390px that is
     the single thing pushing the page into horizontal scroll, so they stack. */
  .bk-ctxbar > div { max-width: 100%; }
  .bk-ctxbar .btn-bk,
  .bk-ctxbar .shiny-download-link.btn-bk { width: 100%; justify-content: center; }
  .bk-ctxbar { gap: 10px; }
}
