/**
 * VariantView Base Styles
 *
 * Contains:
 * - Modern CSS reset
 * - Typography styles
 * - Layout grid
 * - Skip link for accessibility
 */

/* ════════════════════════════════════════════════════════════════════════════
   MODERN CSS RESET
   Based on Josh Comeau's CSS Reset + accessibility best practices
   ════════════════════════════════════════════════════════════════════════════ */

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

* {
  margin: 0;
}

html {
  font-size: 75%; /* Sassline: 12px root, making 2rem = 24px = 1 rhythm line */
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  line-height: var(--vv-line-height-base); /* 1.5 → 24px for 16px base font */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: var(--vv-font-family-sans);
  font-size: var(--vv-font-size-base);
  color: var(--vv-color-text-primary);
  background-color: var(--vv-color-surface-primary);
}

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

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

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

/* Remove list styles on ul, ol when role="list" */
ul[role="list"],
ol[role="list"] {
  list-style: none;
  padding-left: 0;
}

/* Set core root defaults */
html:focus-within {
  scroll-behavior: smooth;
}

/* A elements that don't have a class get default styles */
a:not([class]) {
  text-decoration-skip-ink: auto;
}

/* Remove all animations and transitions for people that prefer not to see them */
@media (prefers-reduced-motion: reduce) {
  html:focus-within {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ════════════════════════════════════════════════════════════════════════════
   TYPOGRAPHY
   ════════════════════════════════════════════════════════════════════════════ */

/* Headings - Sans-serif
   Line-heights calculated for 24px baseline grid rhythm

   Vertical Rhythm System:
   ───────────────────────
   Each heading's total height (line-height + margin) must be a WHOLE rhythm multiple.
   This ensures body text PARAGRAPHS maintain baseline alignment throughout.

   WHY HEADING BASELINES DON'T ALIGN:
   Different font sizes have different baseline positions within their line-boxes.
   For IBM Plex Sans with ~0.86 ascent ratio:
   - 16px body: baseline at 17.76px in 24px line-box (aligns with cap-unit shift)
   - 31px H2: baseline at 29.25px in 36px line-box (~12px off grid)
   - 25px H3: baseline at 27.2px in 36px line-box (~9px off grid)

   Tested: Increasing H2/H3 line-heights to 48px makes alignment WORSE (17px off).
   This is mathematically inherent - no line-height value can align all font sizes.
   The Sassline approach accepts this: maintain rhythm totals so PARAGRAPHS align.

   Total Heights (all whole rhythm multiples):
   - H1: 48px + 24px = 72px (3 rhythm)
   - H2: 36px + 12px = 48px (2 rhythm)
   - H3: 36px + 12px = 48px (2 rhythm)
   - H4: 24px + 24px = 48px (2 rhythm)
   - H5: 24px + 24px = 48px (2 rhythm)
   - H6: 24px + 24px = 48px (2 rhythm) */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--vv-font-family-sans);
  font-weight: var(--vv-font-weight-semibold);
  color: var(--vv-color-text-primary);
}

h1 {
  font-size: var(--vv-font-size-2xl);  /* 39px */
  line-height: 1.231;                   /* 48px = 2 rhythm lines */
  letter-spacing: var(--vv-letter-spacing-tight);
  margin-bottom: var(--vv-rhythm);      /* 24px → total 72px (3 rhythm) */
}

h2 {
  font-size: var(--vv-font-size-xl);   /* 31.25px */
  line-height: 1.152;                   /* 36px = 1.5 rhythm lines */
  letter-spacing: var(--vv-letter-spacing-tight);
  margin-bottom: var(--vv-rhythm-half); /* 12px → total 48px (2 rhythm) */
}

h3 {
  font-size: var(--vv-font-size-lg);   /* 25px */
  line-height: 1.44;                    /* 36px = 1.5 rhythm lines */
  margin-bottom: var(--vv-rhythm-half); /* 12px → total 48px (2 rhythm) */
}

h4 {
  font-size: var(--vv-font-size-md);   /* 20px */
  line-height: 1.2;                     /* 24px = 1 rhythm line */
  margin-bottom: var(--vv-rhythm);      /* 24px → total 48px (2 rhythm) */
}

h5 {
  font-size: var(--vv-font-size-base); /* 16px */
  line-height: 1.5;                     /* 24px = 1 rhythm line */
  margin-bottom: var(--vv-rhythm);      /* 24px → total 48px (2 rhythm) */
}

h6 {
  font-size: var(--vv-font-size-sm);   /* 12.8px */
  line-height: 1.875;                   /* 24px = 1 rhythm line */
  text-transform: uppercase;
  letter-spacing: var(--vv-letter-spacing-caps);
  margin-bottom: var(--vv-rhythm);      /* 24px → total 48px (2 rhythm) */
}

/* Body text */
p {
  margin-bottom: var(--vv-space-5); /* 24px = 1 rhythm line */
}

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

/* ────────────────────────────────────────────────────────────────────────────
   RHYTHM-AWARE TEXT UTILITIES
   Use these classes to ensure text snaps to the 24px baseline grid.
   Each pairs a font-size with its correct line-height.
   ──────────────────────────────────────────────────────────────────────────── */

.vv-text-2xl {
  font-size: var(--vv-font-size-2xl);   /* 39px */
  line-height: var(--vv-line-height-2xl); /* → 48px */
}

.vv-text-xl {
  font-size: var(--vv-font-size-xl);    /* 31.25px */
  line-height: var(--vv-line-height-xl);  /* → 36px */
}

.vv-text-lg {
  font-size: var(--vv-font-size-lg);    /* 25px */
  line-height: var(--vv-line-height-lg);  /* → 36px */
}

.vv-text-md {
  font-size: var(--vv-font-size-md);    /* 20px */
  line-height: var(--vv-line-height-md);  /* → 24px */
}

.vv-text-base {
  font-size: var(--vv-font-size-base);  /* 16px */
  line-height: var(--vv-line-height-base); /* → 24px */
}

.vv-text-sm {
  font-size: var(--vv-font-size-sm);    /* 12.8px */
  line-height: var(--vv-line-height-sm);  /* → 24px */
}

.vv-text-xs {
  font-size: var(--vv-font-size-xs);    /* 10.24px */
  line-height: var(--vv-line-height-xs);  /* → 24px */
}

/* Links */
a {
  color: var(--vv-color-interactive);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  transition: color var(--vv-transition-fast);
}

a:hover {
  color: var(--vv-color-interactive-hover);
}

a:focus-visible {
  outline: 2px solid var(--vv-color-interactive);
  outline-offset: 2px;
  border-radius: var(--vv-radius-sm);
}

/* Small text */
small {
  font-size: var(--vv-font-size-sm);
  color: var(--vv-color-text-secondary);
}

/* Code - Monospace */
code,
kbd,
samp,
pre {
  font-family: var(--vv-font-family-mono);
  font-size: 0.875em;
}

code {
  background-color: var(--vv-color-surface-secondary);
  padding: var(--vv-space-1) var(--vv-space-2);
  border-radius: var(--vv-radius-sm);
}

pre {
  background-color: var(--vv-color-surface-secondary);
  padding: var(--vv-space-4);
  border-radius: var(--vv-radius-md);
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
}

/* Strong and emphasis */
strong,
b {
  font-weight: var(--vv-font-weight-semibold);
}

/* Blockquote */
blockquote {
  margin: var(--vv-space-4) 0;
  padding: var(--vv-space-3) var(--vv-space-4);
  border-left: var(--vv-border-width-thick) solid var(--vv-color-border-primary);
  background-color: var(--vv-color-surface-secondary);
  font-style: italic;
}

blockquote cite {
  display: block;
  margin-top: var(--vv-space-2);
  font-size: var(--vv-font-size-sm);
  font-style: normal;
  color: var(--vv-color-text-tertiary);
}

/* Horizontal rule */
hr {
  border: none;
  border-top: var(--vv-border-width) solid var(--vv-color-border-light);
  margin: var(--vv-space-6) 0;
}

/* Tables - base styling */
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: var(--vv-space-3) var(--vv-space-4);
  text-align: left;
  border-bottom: var(--vv-border-width) solid var(--vv-color-border-light);
}

th {
  font-weight: var(--vv-font-weight-semibold);
  font-size: var(--vv-font-size-sm);
  color: var(--vv-color-text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--vv-letter-spacing-caps);
}

tbody tr:hover {
  background-color: var(--vv-color-surface-secondary);
}

/* ════════════════════════════════════════════════════════════════════════════
   LAYOUT
   ════════════════════════════════════════════════════════════════════════════ */

/* Container */
.vv-container {
  width: 100%;
  max-width: var(--vv-max-width-content);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--vv-space-4);
  padding-right: var(--vv-space-4);
}

.vv-container--narrow {
  max-width: var(--vv-max-width-narrow);
}

.vv-container--wide {
  max-width: var(--vv-max-width-wide);
}

/* Section spacing */
.vv-section {
  padding-top: var(--vv-space-8);
  padding-bottom: var(--vv-space-8);
}

/* Stack - vertical spacing between children */
.vv-stack > * + * {
  margin-top: var(--vv-space-4);
}

.vv-stack--sm > * + * {
  margin-top: var(--vv-space-2);
}

.vv-stack--lg > * + * {
  margin-top: var(--vv-space-6);
}

/* Cluster - horizontal spacing between children */
.vv-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vv-space-4);
  align-items: center;
}

.vv-cluster--sm {
  gap: var(--vv-space-2);
}

/* Grid */
.vv-grid {
  display: grid;
  gap: var(--vv-space-4);
}

.vv-grid--2 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
}

.vv-grid--3 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}

/* ════════════════════════════════════════════════════════════════════════════
   ACCESSIBILITY - Skip Link
   ════════════════════════════════════════════════════════════════════════════ */

.vv-skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  padding: var(--vv-space-3) var(--vv-space-4);
  background-color: var(--vv-color-interactive);
  color: white;
  text-decoration: none;
  font-weight: var(--vv-font-weight-medium);
  z-index: var(--vv-z-tooltip);
  border-radius: 0 0 var(--vv-radius-md) 0;
}

.vv-skip-link:focus {
  top: 0;
}

/* ════════════════════════════════════════════════════════════════════════════
   FOCUS STATES
   ════════════════════════════════════════════════════════════════════════════ */

:focus-visible {
  outline: 2px solid var(--vv-color-interactive);
  outline-offset: 2px;
}

/* Remove default outline for mouse users, keep for keyboard */
:focus:not(:focus-visible) {
  outline: none;
}

/* ════════════════════════════════════════════════════════════════════════════
   SELECTION
   ════════════════════════════════════════════════════════════════════════════ */

::selection {
  background-color: var(--vv-color-interactive);
  color: white;
}

/* ════════════════════════════════════════════════════════════════════════════
   SCREEN READER ONLY
   ════════════════════════════════════════════════════════════════════════════ */

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

.vv-sr-only-focusable:focus,
.vv-sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ════════════════════════════════════════════════════════════════════════════
   BASELINE GRID DEBUG OVERLAY

   Add [data-debug-baseline] attribute to <html> to visualize the 24px grid.
   Useful for verifying vertical rhythm alignment during development.

   Usage: <html data-debug-baseline>
   ════════════════════════════════════════════════════════════════════════════ */

[data-debug-baseline] {
  background-image: linear-gradient(
    to bottom,
    rgba(0, 119, 255, 0.08) 1px,
    transparent 1px
  );
  background-size: 100% var(--vv-rhythm);
  background-position: 0 0;
}

/* Alternative: more visible grid lines for detailed debugging */
[data-debug-baseline="visible"]::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 9999;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent calc(var(--vv-rhythm) - 1px),
    rgba(255, 0, 136, 0.2) calc(var(--vv-rhythm) - 1px),
    rgba(255, 0, 136, 0.2) var(--vv-rhythm)
  );
}
