/* ==========================================================================
   Base - reset, typography activation, focus, motion, a11y utilities
   ==========================================================================

   This is where Phase A stops being inert. Three things switch on here:
   Barlow, the two-tone focus ring, and the reduced-motion guard.

   Load order (base.html): fonts -> tokens -> BASE -> shell -> components ->
   main.css (page-specific + compatibility) -> print.

   base.css sits early on purpose. Everything below it can override it, so
   activating global typography here cannot fight a page-specific rule that
   has not been migrated yet.
   ========================================================================== */

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

/* ---------------------------------------------------------------- typography
   The single line that activates Barlow application-wide. Everything else
   in this file is the hierarchy that line makes possible.

   Barlow Medium (500) is the body weight, per Brand Book p20 - not 400.
   Barlow's 400 is noticeably light at UI sizes and 500 is what the brand
   specifies for body copy, so --font-weight-body is the default rather
   than an override. */

body {
  margin: 0;
  font-family: var(--font-brand);
  font-size: var(--type-body-size);
  line-height: var(--type-body-line);
  font-weight: var(--font-weight-body);
  color: var(--text-primary);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Numbers in data contexts line up column-to-column. Applied at the root
   for tables, metrics and charts; prose is unaffected because it rarely
   contains column-aligned figures. */
table,
.kpi-value,
.tile-value,
.metric-value {
  font-variant-numeric: tabular-nums;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  color: var(--text-primary);
  font-weight: var(--font-weight-subhead);
  line-height: var(--type-subhead-line);
}

h1 {
  font-size: var(--type-page-title-size);
  line-height: var(--type-page-title-line);
  font-weight: var(--type-page-title-weight);
  letter-spacing: var(--type-page-title-tracking);
}

h2 {
  font-size: var(--type-section-size);
  line-height: var(--type-section-line);
  font-weight: var(--type-section-weight);
}

h3 {
  font-size: var(--type-card-title-size);
  line-height: var(--type-card-title-line);
  font-weight: var(--type-card-title-weight);
}

h4,
h5,
h6 {
  font-size: var(--type-subhead-size);
  font-weight: var(--type-subhead-weight);
}

p {
  margin: 0 0 var(--space-4);
}

a {
  color: inherit;
  text-decoration: none;
}

/* Links inside prose keep an underline. Colour is never the only thing
   distinguishing a link from the text around it. */
.content p > a,
.content li > a {
  color: var(--link-default);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.content p > a:hover,
.content li > a:hover {
  color: var(--link-hover);
}

small {
  font-size: var(--type-caption-size);
}

.muted {
  color: var(--text-muted);
}

/* ------------------------------------------------------- typography roles
   Utility classes for the roles in the design system. Page-specific CSS
   should use these rather than re-declaring sizes. */

.type-display {
  font-size: var(--type-display-size);
  line-height: var(--type-display-line);
  font-weight: var(--type-display-weight);
  letter-spacing: var(--type-display-tracking);
  text-transform: uppercase;
}

.type-page-title {
  font-size: var(--type-page-title-size);
  line-height: var(--type-page-title-line);
  font-weight: var(--type-page-title-weight);
}

.type-section {
  font-size: var(--type-section-size);
  line-height: var(--type-section-line);
  font-weight: var(--type-section-weight);
}

.type-label {
  font-size: var(--type-label-size);
  line-height: var(--type-label-line);
  font-weight: var(--type-label-weight);
}

.type-helper {
  font-size: var(--type-helper-size);
  line-height: var(--type-helper-line);
  color: var(--text-muted);
}

/* Brand Book p20: call-outs and extra information are Barlow Medium
   Italic. A real italic file is loaded, so this is never synthesised. */
.type-callout {
  font-size: var(--type-callout-size);
  line-height: var(--type-callout-line);
  font-weight: var(--type-callout-weight);
  font-style: var(--type-callout-style);
}

.type-caption {
  font-size: var(--type-caption-size);
  line-height: var(--type-caption-line);
  color: var(--text-muted);
}

.type-metric-value {
  font-size: var(--type-metric-value-size);
  line-height: var(--type-metric-value-line);
  font-weight: var(--type-metric-value-weight);
}

.type-metric-label {
  font-size: var(--type-metric-label-size);
  line-height: var(--type-metric-label-line);
  font-weight: var(--type-metric-label-weight);
  letter-spacing: var(--type-metric-label-tracking);
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------- focus
   The two-tone ring from the design system, activated globally.

   Two tones because one colour cannot work everywhere: #006DE9 is 4.81:1
   on white but 1.75:1 on the dark-blue sidebar, and #97C9E9 is the
   reverse. The white halo (box-shadow) sits outside the coloured outline,
   so on dark chrome the halo carries the contrast and on light surfaces
   the outline does.

   :focus-visible rather than :focus, so a mouse click on a button does not
   paint a ring, but tabbing to it does. */

:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-sm);
}

/* On dark-blue chrome the ring switches to the light-blue tone and gains a
   halo, which is what keeps it visible against #1D4484.

   BUILD 1 NARROWED THIS LIST. The sidebar used to be the largest dark-blue
   surface in the application and was the main reason this rule existed. It
   is now pale blue, where the light-blue ring would be the invisible one -
   so the sidebar takes the STANDARD ring, which measures 4.29:1 against
   --sidebar-surface and clears the 3:1 that WCAG 1.4.11 asks of a focus
   indicator.

   What stays dark-blue is the report masthead, and the one row inside the
   sidebar that is filled with --sidebar-active-bg. Both are listed below;
   everything else in the sidebar is light and is covered by the rule
   above. */
.app-masthead :focus-visible,
.nav-item.active:focus-visible,
.nav-subitem.active:focus-visible,
.sidebar-cta:focus-visible {
  outline-color: var(--focus-ring-inverse);
  box-shadow: 0 0 0 calc(var(--focus-ring-width) + var(--focus-ring-offset)) var(--focus-halo-inverse);
}

/* Elements that already carry a radius keep it, so the ring traces the
   control rather than boxing it. */
.btn:focus-visible,
.nav-item:focus-visible,
.nav-subitem:focus-visible,
.sidebar-cta:focus-visible {
  border-radius: var(--radius-md);
}

/* Never remove a focus indicator without replacing it. This is the only
   place outline:none appears, and it is immediately paired with the ring
   above via :focus-visible. */
:focus:not(:focus-visible) {
  outline: none;
}

/* ------------------------------------------------------------------ motion
   The tokens are already neutralised under prefers-reduced-motion in
   tokens.css. This is the belt-and-braces rule for anything that sets a
   duration without going through a token - including third-party CSS and
   anything added later. */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* The `!important` above is deliberate and is the single exception in the
   codebase. It is not a migration shortcut - it exists because an
   accessibility preference must win against any rule, including ones this
   project does not control. */

/* ------------------------------------------------------ the hidden attribute
   CORRECTION 10 - the orange bar with the upward arrow.

   `hidden` is not a CSS feature this project owns. It is a UA stylesheet
   rule, `[hidden] { display: none }`, at the lowest possible origin - so
   ANY author rule that sets `display` on the same element defeats it, and
   the element stays painted while the markup and the JavaScript both
   believe it is hidden.

   That is exactly what produced the bar on the Weekly Executive Report.
   `.data-quality-notice { display: flex }` in reports.css beat the UA rule
   on `<p class="data-quality-notice" hidden>`, so the element rendered on
   every load with no text in it - an empty warning-orange strip showing
   only its ::before glyph, U+25B2 BLACK UP-POINTING TRIANGLE. The arrow was
   never data. It was the bullet of a notice that had nothing to say.

   An audit of every `hidden` element in the templates found the same
   collision on FOUR elements, not one:

     #retentionDataQuality   .data-quality-notice   display: flex
     #draftNotice            .alert                 display: flex
     #backBtn                .btn                   display: inline-flex
     #saveBtn                .btn                   display: inline-flex

   The modal backdrops are NOT in that list: components.css already carries
   `.modal-backdrop[hidden] { display: none }`, the per-component form of
   this fix. That is the proof the defect is known and the patching is
   piecemeal - one component was guarded, three were not, and nothing made
   the next component remember. Patching the one reported selector would
   have left three live and the next one unguarded again. This restores the
   platform guarantee once, for every element, present and future: `hidden`
   means hidden.

   This is the second `!important` in the codebase and the reason is the
   same as the first - it is not a migration shortcut and not a specificity
   race. `hidden` is a semantic promise the HTML standard makes, relied on
   by assistive technology as well as by paint, and it must win against
   component styling that has no idea the attribute is present. The
   alternative - auditing every component for `display` and rewriting each
   as `:not([hidden])` forever - is the shortcut, not this. */

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------- a11y utilities */

/* Visually hidden, still announced. Used for chart data tables, status
   messages and the skip link below. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Becomes visible on focus - the standard skip-link pattern. Keyboard
   users should not have to tab through the whole sidebar to reach the
   page content. */
.skip-link {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: var(--z-toast);
  padding: var(--space-3) var(--space-5);
  background: var(--brand-primary);
  color: var(--text-inverse);
  font-weight: var(--font-weight-label);
  border-radius: var(--radius-md);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: translateY(0);
}

/* ------------------------------------------------------------ selection */

::selection {
  background: var(--brand-light);
  color: var(--text-on-light-blue);
}
