/**
 * Modern CSS Reset and Base Styles - Mindeck Platform
 * Normalizes browser defaults and applies design tokens
 * Based on modern reset practices (Josh Comeau, Andy Bell)
 */

/* ============================================
   BOX SIZING RESET
   ============================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ============================================
   MARGIN AND PADDING RESET
   ============================================ */

* {
  margin: 0;
  padding: 0;
}

/* ============================================
   ROOT ELEMENT CONFIGURATION
   ============================================ */

html {
  /* Smooth scrolling for anchor links */
  scroll-behavior: smooth;
  
  /* Prevent font size adjustments on orientation change */
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  
  /* Set base font size for rem calculations */
  font-size: 16px;
}

/* Respect user's reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   BODY BASE STYLES
   ============================================ */

body {
  /* Apply design tokens */
  font-family: var(--font-family-sans);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  
  /* Font smoothing for better text rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  
  /* Improve text rendering */
  text-rendering: optimizeLegibility;
  
  /* Prevent horizontal overflow */
  overflow-x: hidden;
  
  /* Minimum height for full viewport */
  min-height: 100vh;
}

/* ============================================
   TYPOGRAPHY ELEMENTS
   ============================================ */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

h1 {
  font-size: var(--font-size-4xl);
  letter-spacing: var(--letter-spacing-tight);
}

h2 {
  font-size: var(--font-size-3xl);
  letter-spacing: var(--letter-spacing-tight);
}

h3 {
  font-size: var(--font-size-2xl);
}

h4 {
  font-size: var(--font-size-xl);
}

h5 {
  font-size: var(--font-size-lg);
}

h6 {
  font-size: var(--font-size-md);
}

p {
  margin-bottom: var(--space-4);
  color: var(--text-secondary);
}

/* ============================================
   LINKS
   ============================================ */

a {
  color: var(--interactive-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--interactive-primary-hover);
  text-decoration: underline;
}

a:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================
   LISTS
   ============================================ */

ul, ol {
  list-style: none;
}

ul[role="list"],
ol[role="list"] {
  list-style: revert;
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
}

li {
  margin-bottom: var(--space-2);
}

/* ============================================
   IMAGES AND MEDIA
   ============================================ */

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

img {
  /* Prevent image dragging */
  -webkit-user-drag: none;
  user-select: none;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

input,
textarea,
select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background-color: var(--bg-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}

/* Remove default button styles */
button {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

/* ============================================
   TABLES
   ============================================ */

table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: var(--space-4);
}

th,
td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-secondary);
}

th {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  background-color: var(--bg-secondary);
}

/* ============================================
   CODE AND PREFORMATTED TEXT
   ============================================ */

code,
kbd,
samp,
pre {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
}

code {
  padding: var(--space-1) var(--space-2);
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

pre {
  padding: var(--space-4);
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--space-4);
}

pre code {
  padding: 0;
  background-color: transparent;
}

/* ============================================
   HORIZONTAL RULE
   ============================================ */

hr {
  border: none;
  border-top: 1px solid var(--border-secondary);
  margin: var(--space-8) 0;
}

/* ============================================
   BLOCKQUOTE
   ============================================ */

blockquote {
  padding-left: var(--space-6);
  border-left: 4px solid var(--border-primary);
  margin: var(--space-6) 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* ============================================
   SELECTION
   ============================================ */

::selection {
  background-color: var(--color-primary-200);
  color: var(--text-primary);
}

::-moz-selection {
  background-color: var(--color-primary-200);
  color: var(--text-primary);
}

/* ============================================
   SCROLLBAR STYLING (Webkit browsers)
   ============================================ */

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background-color: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background-color: var(--border-primary);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-secondary);
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-tertiary);
}

/* ============================================
   FOCUS VISIBLE UTILITY
   ============================================ */

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Skip to main content link */
.skip-to-main {
  position: absolute;
  top: -100%;
  left: 0;
  padding: var(--space-4);
  background-color: var(--bg-elevated);
  color: var(--text-primary);
  z-index: var(--z-index-tooltip);
  transition: top var(--transition-fast);
}

.skip-to-main:focus {
  top: 0;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  
  a,
  a:visited {
    text-decoration: underline;
  }
  
  a[href]::after {
    content: " (" attr(href) ")";
  }
  
  abbr[title]::after {
    content: " (" attr(title) ")";
  }
  
  pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  }
  
  thead {
    display: table-header-group;
  }
  
  tr,
  img {
    page-break-inside: avoid;
  }
  
  img {
    max-width: 100% !important;
  }
  
  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }
  
  h2,
  h3 {
    page-break-after: avoid;
  }
}
