/* =====================================================================
   Reset, base typography and utilities
   ===================================================================== */

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

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

@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;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--sp-3);
  font-weight: 650;
  line-height: var(--lh-tight);
  letter-spacing: -0.011em;
  color: var(--text);
}
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
h5, h6 { font-size: var(--fs-base); }

p { margin: 0 0 var(--sp-3); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--brand-600);
  text-decoration: none;
  transition: color var(--t-fast) var(--ease);
}
a:hover { color: var(--brand-700); text-decoration: underline; }

small { font-size: var(--fs-sm); }
strong, b { font-weight: 650; }

ul, ol { margin: 0 0 var(--sp-3); padding-left: var(--sp-5); }
li { margin-bottom: var(--sp-1); }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

code, kbd, pre { font-family: var(--font-mono); font-size: 0.9em; }
code {
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: var(--r-xs);
}

img, svg, video { max-width: 100%; height: auto; vertical-align: middle; }
svg.ico { flex: 0 0 auto; }

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

/* Focus: always visible, never removed. Keyboard users depend on it. */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--brand-200); color: var(--brand-900); }

/* Scrollbars that match the theme rather than the OS default. */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid var(--bg);
  border-radius: var(--r-full);
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* ---------------------------------------------------------------------
   Accessibility helpers
   ------------------------------------------------------------------ */

.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;
}

.skip-link {
  position: absolute;
  top: -60px; left: var(--sp-4);
  z-index: 999;
  padding: var(--sp-3) var(--sp-4);
  background: var(--brand-600);
  color: #fff;
  border-radius: 0 0 var(--r-md) var(--r-md);
  font-weight: 600;
  transition: top var(--t-base) var(--ease);
}
.skip-link:focus { top: 0; text-decoration: none; }

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

.container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: var(--sp-5); }
.container--narrow { max-width: var(--container-narrow); }

.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-6); }

.row { display: flex; gap: var(--sp-3); }
.row--wrap { flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--center { align-items: center; }
.row--middle { align-items: center; justify-content: center; }
.row--end { justify-content: flex-end; }
.row--top { align-items: flex-start; }
.row--baseline { align-items: baseline; }
.grow { flex: 1 1 auto; min-width: 0; }

.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid--auto-sm { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--auto-lg { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }

@media (max-width: 1080px) {
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--sidebar { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .grid--2, .grid--3, .grid--4 { grid-template-columns: minmax(0, 1fr); }
  .container { padding-inline: var(--sp-4); }
}

/* ---------------------------------------------------------------------
   Text utilities
   ------------------------------------------------------------------ */

.muted   { color: var(--text-muted); }
.subtle  { color: var(--text-subtle); }
.tiny    { font-size: var(--fs-xs); }
.small   { font-size: var(--fs-sm); }
.lead    { font-size: var(--fs-lg); color: var(--text-muted); line-height: var(--lh-loose); }
.mono    { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.nums    { font-variant-numeric: tabular-nums; }
.bold    { font-weight: 650; }
.upper   { text-transform: uppercase; letter-spacing: 0.05em; font-size: var(--fs-xs); font-weight: 650; }
.right   { text-align: right; }
.center  { text-align: center; }
.nowrap  { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.t-success { color: var(--success-fg); }
.t-warning { color: var(--warning-fg); }
.t-danger  { color: var(--danger-fg); }
.t-info    { color: var(--info-fg); }
.t-brand   { color: var(--brand-600); }

.hide { display: none !important; }
@media (max-width: 860px)  { .hide-mobile  { display: none !important; } }
@media (min-width: 861px)  { .only-mobile  { display: none !important; } }
@media (max-width: 1080px) { .hide-tablet  { display: none !important; } }

.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-5 { margin-bottom: var(--sp-5); }
.mb-6 { margin-bottom: var(--sp-6); }

/* Wide content (tables, charts) scrolls inside itself so the page body
   never scrolls horizontally. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
