/**
 * Modern CSS Reset
 *
 * Based on modern best practices for accessible, consistent rendering
 * across browsers. Combines ideas from:
 * - Josh Comeau's CSS Reset
 * - Andy Bell's Modern CSS Reset
 * - Normalize.css principles
 */

/* ==================== BOX SIZING ==================== */

/**
 * Use border-box by default for all elements
 * This makes width/height include padding and border
 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ==================== ROOT ELEMENT ==================== */

/**
 * 1. Improve text rendering
 * 2. Prevent adjustments of font size after orientation changes
 */
html {
  -webkit-text-size-adjust: 100%; /* 2 */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ==================== REMOVE DEFAULT MARGINS ==================== */

/**
 * Remove all margins from common elements
 * Allows for more predictable spacing control
 */
body,
h1, h2, h3, h4, h5, h6,
p,
figure,
blockquote,
dl, dd,
ul, ol {
  margin: 0;
}

/* ==================== BODY DEFAULTS ==================== */

/**
 * 1. Set minimum height to fill viewport
 * 2. Improve text rendering
 * 3. Set default line height for readability
 */
body {
  min-height: 100vh; /* 1 */
  line-height: 1.5; /* 3 */
  text-rendering: optimizeSpeed; /* 2 */
}

/* ==================== MEDIA ELEMENTS ==================== */

/**
 * 1. Make images easier to work with
 * 2. Prevent images from overflowing containers
 */
img,
picture,
video,
canvas,
svg {
  display: block; /* 1 */
  max-width: 100%; /* 2 */
  height: auto; /* 2 */
}

/**
 * Maintain aspect ratio for media elements
 */
iframe,
embed,
object {
  max-width: 100%;
}

/* ==================== FORM ELEMENTS ==================== */

/**
 * 1. Inherit font settings from ancestors
 * 2. Remove default margins
 */
input,
button,
textarea,
select {
  font: inherit; /* 1 */
  margin: 0; /* 2 */
}

/**
 * Remove inner border and padding in Firefox 4+
 */
button::-moz-focus-inner,
input::-moz-focus-inner {
  border: 0;
  padding: 0;
}

/**
 * Make buttons and selects look clickable
 */
button,
select {
  cursor: pointer;
}

/**
 * Show overflow in Edge and IE
 */
button,
input {
  overflow: visible;
}

/**
 * Remove default button styles while keeping accessibility
 */
button {
  background-color: transparent;
  border: none;
  padding: 0;
  color: inherit;
  text-align: inherit;
}

/**
 * Restore pointer cursor for disabled buttons
 */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
}

/* ==================== TYPOGRAPHY DEFAULTS ==================== */

/**
 * 1. Prevent text overflow
 * 2. Improve hyphenation in narrow containers
 */
p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word; /* 1 */
  hyphens: auto; /* 2 */
}

/**
 * Balance text wrapping in headings
 */
h1, h2, h3, h4, h5, h6 {
  text-wrap: balance;
}

/**
 * Consistent vertical rhythm for paragraphs
 */
p {
  text-wrap: pretty;
  max-width: var(--measure-base, 65ch);
}

/**
 * Remove list styles from lists with a class attribute
 * Indicates these are being used for layout, not content
 */
ul[class],
ol[class] {
  list-style: none;
  padding: 0;
}

/* ==================== LINKS ==================== */

/**
 * Remove underline from links with a class attribute
 * Assumes styled links will handle their own decoration
 */
a {
  text-decoration-skip-ink: auto;
}

a:not([class]) {
  text-decoration-skip-ink: auto;
}

/* ==================== TABLES ==================== */

/**
 * Consistent table styling
 */
table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
}

td,
th {
  padding: 0;
  text-align: left;
}

/* ==================== ACCESSIBILITY IMPROVEMENTS ==================== */

/**
 * Remove all animations and transitions for users who prefer reduced motion
 */
@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;
  }
}

/**
 * Screen reader only class
 * Hides content visually but keeps it accessible to screen readers
 */
.sr-only,
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/**
 * Restore .sr-only content when focused (for skip links)
 */
.sr-only:focus,
.sr-only:active,
.visually-hidden:focus,
.visually-hidden:active {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ==================== FOCUS STYLES ==================== */

/**
 * Remove default focus outline for mouse users
 * (will be restored by :focus-visible below)
 */
:focus {
  outline: none;
}

/**
 * Show focus outline only when using keyboard navigation
 */
:focus-visible {
  outline: var(--focus-ring-width, 3px) solid currentColor;
  outline-offset: var(--focus-ring-offset, 2px);
}

/* ==================== SCROLLBAR STYLING ==================== */

/**
 * Custom scrollbar for better aesthetics (Webkit browsers)
 */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--gray-100, #f1f3f4);
}

::-webkit-scrollbar-thumb {
  background: var(--gray-400, #bdc1c6);
  border-radius: var(--radius-full, 9999px);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gray-500, #9aa0a6);
}

/* ==================== PRINT STYLES ==================== */

/**
 * Optimize for printing
 */
@media print {
  *,
  *::before,
  *::after {
    background: white !important;
    color: black !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;
  }

  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }

  h2,
  h3 {
    page-break-after: avoid;
  }
}
