/* ==========================================================================
   CastleCRM design system. 2 of 5: BASE. Element defaults, focus, utilities.
   Uses role tokens from tokens.css only.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--surface); color: var(--text);
  font: var(--fw-regular) var(--fs-1) / var(--lh-body) var(--font);
  font-stretch: var(--wd-normal);
  font-variant-numeric: lining-nums;
  -webkit-font-smoothing: antialiased;
}
input, select, textarea, button { font: inherit; color: inherit; letter-spacing: inherit; }
img, svg { max-width: 100%; }
img { height: auto; }

h1, h2, h3, h4 { margin: 0 0 var(--sp-3); color: var(--text); text-wrap: balance; }
h1 { font: var(--fw-black) var(--fs-5) / var(--lh-tight) var(--font); font-stretch: var(--wd-xwide); letter-spacing: var(--tracking-title); }
h2 { font: var(--fw-black) var(--fs-3) / var(--lh-snug) var(--font); font-stretch: var(--wd-wide); letter-spacing: -0.01em; }
h3 { font: var(--fw-heavy) var(--fs-2) / var(--lh-snug) var(--font); }
h4 { font: var(--fw-bold) var(--fs-1) / var(--lh-snug) var(--font); }
p { margin: 0 0 var(--sp-3); }
p, li, dd { text-wrap: pretty; }
strong, b { font-weight: var(--fw-heavy); }
small { font-size: var(--fs-0); }

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--link-hover); text-decoration-thickness: 2px; }

hr { border: 0; border-top: var(--rule-hair) solid var(--rule); margin: var(--sp-6) 0; }
code, kbd, samp, .mono { font-family: var(--font-mono); font-size: 0.92em; }
code { background: var(--surface-sunk); padding: 0.05em 0.3em; }
kbd { border: var(--rule-hair) solid var(--rule); padding: 0 var(--sp-1); font-size: var(--fs-0); }
pre { margin: 0; overflow: auto; }
abbr[title] { text-decoration: none; }
address { font-style: normal; }
time, .num, .tnum { font-variant-numeric: tabular-nums lining-nums; }
::selection { background: var(--surface-highlight); color: var(--text); }

/* Focus: always visible for keyboard users, never removed without a replacement */
:focus-visible { outline: var(--focus-ring) solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* Skip link: first stop for keyboard users */
.skip-link {
  position: absolute; left: var(--sp-2); top: var(--sp-2); z-index: var(--z-overlay);
  padding: var(--sp-2) var(--sp-3); background: var(--accent); color: var(--on-accent);
  font-weight: var(--fw-heavy); text-decoration: none; transform: translateY(-200%);
}
.skip-link:focus { transform: none; outline: var(--focus-ring) solid var(--text); }

/* ---------- Utilities (kept from the first toolkit, same names) ---------- */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: var(--fs-0); }
.strong { font-weight: var(--fw-heavy); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.narrow { font-stretch: var(--wd-narrow); }
.num { font-variant-numeric: tabular-nums lining-nums; text-align: right; white-space: nowrap; }
.mb { margin-bottom: var(--sp-6); }
.stack > * + * { margin-top: var(--sp-6); }
.stack--tight > * + * { margin-top: var(--sp-3); }
.row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.row--between { justify-content: space-between; }
.grid { display: grid; gap: var(--sp-6); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); }

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