/* ============================================================
   ChurnShield — Base styles
   Reset, root typography, focus management, a11y primitives.
   Depends on tokens.css.
   ============================================================ */

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

/* `hidden` must win over display: flex/grid on components */
[hidden] { display: none !important; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-base);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  overflow-x: hidden;
  /* Subtle noise overlay for depth */
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

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

img, video {
  height: auto;
}

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

button {
  background: none;
  border: 0;
  cursor: pointer;
}

/* ── Typography primitives ─────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: 1.15;
  color: var(--color-text);
  text-wrap: balance;
}

h1 { font-size: var(--text-5xl); letter-spacing: var(--tracking-tighter); line-height: var(--leading-5xl); }
h2 { font-size: var(--text-3xl); line-height: var(--leading-3xl); }
h3 { font-size: var(--text-2xl); line-height: var(--leading-2xl); }
h4 { font-size: var(--text-xl);  line-height: var(--leading-xl); }
h5 { font-size: var(--text-lg);  line-height: var(--leading-lg); }
h6 { font-size: var(--text-base); }

p {
  text-wrap: pretty;
  max-width: var(--max-width-prose);
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out),
              opacity var(--duration-fast) var(--ease-out);
}
a:hover { opacity: 0.82; }

hr {
  border: 0;
  border-top: 1px solid var(--color-border-subtle);
  margin: var(--space-8) 0;
}

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.125em 0.375em;
}

pre {
  font-family: var(--font-mono);
  background: var(--color-surface-1);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: var(--leading-base);
}
pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

ul, ol {
  padding-left: var(--space-6);
}
li + li { margin-top: var(--space-2); }

/* ── Focus — visible always; ring never clipped ─── */
:focus {
  outline: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
  transition: box-shadow var(--duration-fast) var(--ease-out);
}

/* Some elements already have a rounded shape — preserve it on focus */
button:focus-visible,
a.btn:focus-visible,
.btn:focus-visible {
  box-shadow: var(--focus-ring);
}

/* Inputs get a softer ring so the field border reads first */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  box-shadow: var(--focus-ring-soft);
  border-color: var(--color-accent);
}

/* ── Skip link — visible on focus, hidden otherwise ─ */
.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  background: var(--color-accent);
  color: var(--color-bg);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-md);
  transform: translateY(-200%);
  transition: transform var(--duration-base) var(--ease-out);
}
.skip-link:focus {
  transform: translateY(0);
  outline: none;
}

/* ── Screen-reader-only helper ─────────────────────── */
.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;
}

/* ── Selection ─────────────────────────────────────── */
::selection {
  background: var(--color-accent-soft);
  color: var(--color-text);
}

/* ── Reduced motion — disable transitions & animations ─ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Page wrapper / landmark scaffolding ──────────── */
.page {
  position: relative;
  z-index: var(--z-base);
}

.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--space-6);
}

@media (min-width: 640px) {
  .container { padding-inline: var(--space-8); }
}

.main-content {
  min-height: calc(100vh - var(--nav-height));
}
