/* Base layer of the Nomad CRM visual system: the reset, body type, focus, selection, scrollbar,
 * the visually hidden utility, the skip link and the reduced-motion rules. Every value is a token
 * from tokens.css, which must load first.
 *
 * Load order in apps/crm (see docs/20-experience/visual-system/visual-system.md → Setup in apps/crm):
 *   @import "tailwindcss";
 *   @import "@nomad/visual-system/tokens.css";
 *   @import "@nomad/visual-system/tailwind-theme.css";
 *   @import "@nomad/visual-system/base.css";
 *
 * Everything sits in @layer base. Under Tailwind this appends to its base layer, after preflight,
 * so these rules answer preflight and utilities still win over them. In a page without Tailwind
 * (the prototype) the layer is the only one, so any unlayered component rule wins over it. */

@layer base {
  /* ---------- Reset ---------- */
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    border-color: var(--border);
  }
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  h1,
  h2,
  h3,
  h4,
  p,
  ul,
  ol,
  dl,
  dd,
  figure {
    margin: 0;
  }
  h1,
  h2,
  h3,
  h4 {
    font-weight: var(--fw-semibold);
    font-size: inherit;
  }
  ul,
  ol {
    padding: 0;
    list-style: none;
  }
  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
  }
  button {
    cursor: pointer;
    background: none;
    border: 0;
    padding: 0;
    text-align: inherit;
  }
  button:disabled {
    cursor: not-allowed;
  }
  a {
    color: inherit;
    text-decoration: none;
  }
  img {
    display: block;
    max-width: 100%;
  }
  b,
  strong {
    font-weight: var(--fw-semibold);
  }
  [hidden] {
    display: none !important;
  }

  /* ---------- Body ---------- */
  body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--fs);
    line-height: var(--lh-20);
    font-weight: var(--fw-regular);
    color: var(--text);
    background: var(--surface);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    caret-color: var(--accent);
    font-synthesis: none;
  }
  ::selection {
    background: var(--selection);
  }

  /* ---------- Focus ---------- */
  :focus {
    outline: none;
  }
  :focus-visible {
    outline: var(--focus-w) solid var(--focus-ring);
    outline-offset: var(--focus-offset);
  }

  /* ---------- Scrollbar ---------- */
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
  }
  ::-webkit-scrollbar {
    width: var(--s-2-5);
    height: var(--s-2-5);
  }
  ::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--r-lg);
    border: var(--so-3) solid transparent;
    background-clip: padding-box;
  }
  ::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-4);
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }

  /* ---------- Visually hidden, skip link ---------- */
  .sr {
    position: absolute !important;
    width: var(--s-px);
    height: var(--s-px);
    padding: 0;
    margin: calc(var(--s-px) * -1);
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
  .skip {
    position: absolute;
    left: var(--s-3);
    top: calc(var(--s-10) * -1);
    z-index: var(--z-skip);
    height: var(--h-md);
    display: inline-flex;
    align-items: center;
    padding: 0 var(--so-11);
    border-radius: var(--r-sm);
    background: var(--accent);
    color: var(--on-accent);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
  }
  .skip:focus {
    top: var(--s-2);
  }

  /* ---------- Reduced motion ----------
   * The duration tokens collapse to --dur-instant under reduced motion, but a looping animation
   * (the skeleton's pulse, the spinner) would still loop at that speed. These rules make every
   * animation run once, instantly, and every transition end at once, for the device setting and
   * for Settings → Appearance → Reduce ([data-motion="reduce"], set by boot.js). Components need
   * no reduced-motion code of their own. */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: var(--dur-instant) !important;
      animation-iteration-count: 1 !important;
      transition-duration: var(--dur-instant) !important;
      scroll-behavior: auto !important;
    }
  }
  :root[data-motion='reduce'] *,
  :root[data-motion='reduce'] *::before,
  :root[data-motion='reduce'] *::after {
    animation-duration: var(--dur-instant) !important;
    animation-iteration-count: 1 !important;
    transition-duration: var(--dur-instant) !important;
    scroll-behavior: auto !important;
  }
}
