/* ============================================================================
   Reset, base typography and accessibility primitives
   ========================================================================== */

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

html {
  /* Deliberately not a fixed pixel size. Honouring the reader's browser font
     preference is required by WCAG 1.4.4, and the whole type scale is in rem
     so it follows automatically. */
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-tight);
  background: var(--surface-page);
  color: var(--ink);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Stop iOS rubber-band scrolling from exposing the page behind the app. */
  overscroll-behavior-y: none;
}

img,
svg,
canvas,
video {
  display: block;
  max-width: 100%;
}

canvas {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
}

a {
  color: var(--accent-ink);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

ul,
ol {
  list-style: none;
}

table {
  border-collapse: collapse;
  width: 100%;
}

h1,
h2,
h3,
h4 {
  line-height: var(--leading-tight);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--ink-strong);
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

/* Every figure in this application sits in a column that has to line up.
   Tabular numerals are not decoration here, they are a legibility fix. */
.tabular,
.metric,
td.numeric,
th.numeric {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

/* SKU codes, file names and column headers must never force a layout wider
   than a 320px phone. */
.break-anywhere {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ── Icons ────────────────────────────────────────────────────────────────
   Icons inherit colour and sit on the text baseline rather than floating
   above it, which is what makes an icon-plus-label pair look composed.     */
.icon {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: -0.16em;
  color: currentColor;
}

.brand-mark {
  display: block;
  flex-shrink: 0;
  color: var(--accent-ink);
}

/* ── Focus visibility ─────────────────────────────────────────────────────
   One unmistakable treatment on everything focusable. The original stylesheet
   styled only .btn, which left links, selects and inputs with a browser
   default that the dark theme all but erased.                              */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* A region the router focused so a screen reader announces the new view. It is
   not in the tab order, so a ring here would mark a move the reader never
   made. Chromium counts programmatic focus as focus-visible, which is why the
   plain :focus-visible rule above is not enough. */
[data-focus-region]:focus,
[data-focus-region]:focus-visible {
  outline: none;
}

/* ── Skip link ──────────────────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-loader);
  transform: translateY(calc(-100% - var(--space-4)));
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  box-shadow: var(--shadow-lg);
  transition: transform var(--duration-fast) var(--ease-out);
}

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

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

/* ── Scrollbars ─────────────────────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 2px solid transparent;
  border-radius: var(--radius-pill);
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--ink-muted);
  background-clip: content-box;
}

::selection {
  background: var(--accent-wash-strong);
  color: var(--ink-strong);
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Print ────────────────────────────────────────────────────────────────
   Reports from this tool end up in a physical file, so printing is a real
   output format rather than an afterthought.                               */
@media print {
  #sidebar,
  #sidebar-scrim,
  #topbar,
  #filter-panel,
  #toast-region,
  .skip-link,
  .no-print {
    display: none !important;
  }

  html,
  body,
  #app,
  #main-wrapper,
  #main-content {
    height: auto !important;
    overflow: visible !important;
    display: block !important;
    background: #fff !important;
    color: #000 !important;
  }

  .page-content {
    max-width: none;
    padding: 0;
  }

  .card,
  .panel,
  .metric-card,
  .recommendation {
    break-inside: avoid;
    border: 1px solid #ccc !important;
    box-shadow: none !important;
  }

  .table-scroll {
    overflow: visible !important;
  }

  a[href^='http']::after {
    content: ' (' attr(href) ')';
    font-size: 0.85em;
    color: #555;
  }
}
