/* =============================================================================
   BASE — reset, typography, global element defaults
   Depends on tokens.css. Contains no literal colours.
   ========================================================================== */

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

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--text);
  background-color: var(--canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

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

svg {
  flex-shrink: 0;
}

/* Size floor for the inline icon set. :where() carries zero specificity, so any
   component rule overrides it - but an icon dropped into an unstyled context can
   never render at its intrinsic size and blow out the layout. */
:where(svg) {
  width: 16px;
  height: 16px;
}

/* ---------- Typography ---------- */

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--space-4);
  color: var(--text);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: -0.011em;
}

h1 { font-size: var(--text-2xl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-xl); letter-spacing: -0.017em; }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }
h5, h6 { font-size: var(--text-md); }

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

p:last-child { margin-bottom: 0; }

a {
  color: var(--accent-text);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease);
}

a:hover { color: var(--accent-text-hover); }

small { font-size: var(--text-xs); }

code, kbd, pre, samp {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

hr {
  height: 1px;
  margin: var(--space-6) 0;
  border: 0;
  background-color: var(--border);
  opacity: 1;
}

::selection {
  background-color: var(--selection-bg);
  color: var(--text);
}

/* ---------- Focus ----------
   One ring definition for the whole app. Pointer interaction never shows it;
   keyboard interaction always does. */

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* ---------- Utilities ---------- */

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

/* Visible when focused - the skip link */
.u-skip-link {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: var(--z-toast);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  background-color: var(--accent);
  color: var(--accent-fg);
  font-weight: var(--weight-medium);
  transform: translateY(-200%);
  transition: transform var(--duration-normal) var(--ease-out);
}

.u-skip-link:focus-visible {
  transform: translateY(0);
  color: var(--accent-fg);
}

.u-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.u-nums { font-variant-numeric: tabular-nums; }
.u-mono { font-family: var(--font-mono); }

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

.u-stack   { display: flex; flex-direction: column; }
.u-row     { display: flex; align-items: center; }
.u-gap-2   { gap: var(--space-2); }
.u-gap-3   { gap: var(--space-3); }
.u-gap-4   { gap: var(--space-4); }
.u-gap-5   { gap: var(--space-5); }
.u-grow    { flex: 1 1 auto; min-width: 0; }
.u-right   { text-align: right; }
.u-center  { text-align: center; }

.u-hide { display: none !important; }

/* ---------- Vertical rhythm ----------
   One owner for the gaps between stacked blocks. A page marks up its column as
   a stack and the spacing comes from the scale, instead of every page hanging a
   one-off margin on each section (which is how "20px here, 24px there" starts).
   The stack is a plain block box, so a block's own bottom margin collapses with
   the gap above the next one instead of adding to it. */

/* The doubled class is deliberate. Components in components.css set their own
   margins with the `margin` shorthand - .section-title is `margin: 0 0 20px`,
   which also sets margin-top to 0. At equal specificity the later stylesheet
   wins, so a single .stack class lost every time and blocks ended up flush
   against each other (this is what closed the gap above "Choose a plan" on the
   subscription page). Layout owns the space between blocks; the component owns
   its own inside. */
.stack.stack > * + *          { margin-top: var(--gap-block); }
.stack--tight.stack--tight > * + *   { margin-top: var(--gap-tight); }
.stack--field.stack--field > * + *   { margin-top: var(--gap-field); }
.stack--section.stack--section > * + * { margin-top: var(--gap-section); }

@media (max-width: 767.98px) {
  .u-hide-mobile { display: none !important; }
}

@media (min-width: 768px) {
  .u-only-mobile { display: none !important; }
}

/* ---------- Motion preference ---------- */

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

/* ---------- Scrollbars ---------- */

@supports selector(::-webkit-scrollbar) {
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb {
    background-color: var(--border-strong);
    border: 3px solid transparent;
    border-radius: var(--radius-pill);
    background-clip: content-box;
  }
  ::-webkit-scrollbar-thumb:hover { background-color: var(--text-subtle); }
}

/* ---------- Print ---------- */

@media print {
  .app-sidebar,
  .app-topbar,
  .bulk-bar,
  .toolbar,
  .pagination-bar { display: none !important; }

  body { background: #fff; }
}
