/**
 * ==========================================================================
 * SimpleWebsites Template Factory — Modern CSS Reset
 * ==========================================================================
 * 
 * Version: 1.0.0
 * Last updated: January 2025
 * 
 * A comprehensive, production-ready CSS reset that:
 * - Removes browser inconsistencies
 * - Sets sensible defaults for all elements
 * - Respects user preferences (reduced motion, color scheme)
 * - Improves accessibility
 * - Optimizes for modern CSS features
 * 
 * Based on best practices from:
 * - Josh Comeau's Custom CSS Reset
 * - Andy Bell's Modern CSS Reset
 * - Normalize.css concepts
 * - WCAG 2.1 AA accessibility guidelines
 * 
 * ==========================================================================
 */


/* ==========================================================================
   1. BOX SIZING & LAYOUT FUNDAMENTALS
   ========================================================================== */

/**
 * Use border-box sizing for everything
 * This makes width/height calculations predictable
 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/**
 * Remove default margin and padding from all elements
 * We'll add them back intentionally where needed
 */
* {
  margin: 0;
  padding: 0;
}


/* ==========================================================================
   2. ROOT & DOCUMENT
   ========================================================================== */

/**
 * Root element setup
 * - Prevent font size inflation on mobile (iOS Safari)
 * - Smooth scrolling with respect for user preferences
 * - Establish base font size for rem calculations
 * - Set line-height early to prevent layout shifts
 */
:root {
  /* Base font size - all rem values reference this */
  font-size: 100%; /* Usually 16px */
  
  /* Prevent iOS text size adjustment on orientation change */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  
  /* Enable smooth scrolling by default */
  scroll-behavior: smooth;
  
  /* Improve text rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  
  /* Establish color scheme support */
  color-scheme: light dark;
  
  /* Default line height - improves readability */
  line-height: 1.5;
  
  /* Tab size for code elements */
  -moz-tab-size: 4;
  tab-size: 4;
}

/**
 * Disable smooth scrolling when users prefer reduced motion
 * Respect user's motion preferences for accessibility
 */
@media (prefers-reduced-motion: reduce) {
  :root {
    scroll-behavior: auto;
  }
  
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/**
 * HTML element setup
 * - Full height for sticky footer layouts
 * - Prevent horizontal overflow
 */
html {
  min-height: 100%;
  overflow-x: hidden;
  
  /* Prevent layout shifts from scrollbar */
  scrollbar-gutter: stable;
}

/**
 * Body element setup
 * - Full minimum height for proper layouts
 * - Establish stacking context
 * - Improve text rendering
 */
body {
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  
  /* Allow percentage-based heights in children */
  display: flex;
  flex-direction: column;
  
  /* Font inheritance - will be set by design system */
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 
               'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 
               'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  
  /* Improve text rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


/* ==========================================================================
   3. TYPOGRAPHY
   ========================================================================== */

/**
 * Headings reset
 * - Remove default margins (will be controlled by design system)
 * - Inherit font properties for easier customization
 * - Balance text wrapping for better readability
 */
h1, h2, h3, h4, h5, h6 {
  font-size: inherit;
  font-weight: inherit;
  line-height: 1.2; /* Tighter line height for headings */
  
  /* Modern text balancing for headings */
  text-wrap: balance;
  
  /* Prevent orphans on short headings */
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/**
 * Paragraphs and text content
 * - Improve readability with pretty text wrapping
 * - Prevent text overflow
 */
p {
  text-wrap: pretty; /* Prevent orphans and improve line breaks */
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/**
 * Block quotes
 * - Remove default styling for custom design
 */
blockquote {
  border: none;
  quotes: none;
}

blockquote::before,
blockquote::after {
  content: '';
  content: none;
}

/**
 * Abbreviations with titles
 * - Indicate they have more information
 */
abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
  text-decoration-skip-ink: none;
}

/**
 * Bold text normalization
 * - Ensure consistent bold weight across browsers
 */
b,
strong {
  font-weight: 700; /* Use explicit weight instead of bolder */
}

/**
 * Small text
 * - Set consistent small text size
 */
small {
  font-size: 80%;
}

/**
 * Sub and superscript
 * - Prevent them from affecting line height
 */
sub,
sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

sub {
  bottom: -0.25em;
}

sup {
  top: -0.5em;
}

/**
 * Horizontal rule
 * - Consistent styling across browsers
 */
hr {
  height: 0;
  border: none;
  border-top: 1px solid;
  color: inherit; /* Use currentColor for border */
  overflow: visible;
}


/* ==========================================================================
   4. LINKS
   ========================================================================== */

/**
 * Links reset
 * - Remove default underline (will be controlled by design system)
 * - Inherit color for easier styling
 * - Improve touch targets on mobile
 */
a {
  color: inherit;
  text-decoration: inherit;
  
  /* Improve touch targets */
  -webkit-tap-highlight-color: transparent;
}

/**
 * Links within text should be clearly identifiable
 * Design system will override this
 */
a:not([class]) {
  text-decoration-skip-ink: auto;
}


/* ==========================================================================
   5. LISTS
   ========================================================================== */

/**
 * List reset
 * - Remove default list styling
 * - Design system will add styles as needed
 */
ul,
ol {
  list-style: none;
}

/**
 * Definition lists
 */
dl {
  margin: 0;
}

dt {
  font-weight: 700;
}

dd {
  margin-left: 0;
}

/**
 * Nested lists - reset in case of specificity issues
 */
ul ul,
ol ol,
ul ol,
ol ul {
  list-style: none;
}


/* ==========================================================================
   6. MEDIA ELEMENTS
   ========================================================================== */

/**
 * Images, videos, and other media
 * - Responsive by default
 * - Remove gap below inline media elements
 * - Prevent distortion
 */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/**
 * Images specific
 * - Prevent dragging
 * - Handle broken images gracefully
 */
img {
  border-style: none;
  -webkit-user-drag: none;
  user-drag: none;
}

/**
 * SVG specific
 * - Fix overflow issue in IE
 * - Allow fill to be controlled via CSS
 */
svg {
  overflow: hidden;
  vertical-align: middle;
}

svg:not([fill]) {
  fill: currentColor;
}

/**
 * Embedded content
 * - Remove border in IE 10
 */
embed,
iframe,
object {
  display: block;
  max-width: 100%;
  border: 0;
}

/**
 * Audio and video
 * - Ensure they don't exceed container
 */
audio,
video {
  max-width: 100%;
}

audio:not([controls]) {
  display: none;
  height: 0;
}

/**
 * Figure element
 * - Reset margins
 */
figure {
  margin: 0;
}

figcaption {
  margin-top: 0.5em;
}


/* ==========================================================================
   7. TABLES
   ========================================================================== */

/**
 * Table reset
 * - Remove spacing between cells
 * - Consistent text alignment
 */
table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  text-indent: 0;
  border-color: inherit;
}

/**
 * Table cells
 * - Inherit text alignment from parent
 * - Consistent vertical alignment
 */
th,
td {
  text-align: inherit;
  vertical-align: top;
  padding: 0;
}

/**
 * Table headers
 * - Consistent font weight
 */
th {
  font-weight: 700;
}

/**
 * Caption
 * - Reset positioning
 */
caption {
  text-align: left;
  caption-side: top;
}


/* ==========================================================================
   8. FORMS
   ========================================================================== */

/**
 * Form elements reset
 * - Inherit font styles from parent
 * - Consistent appearance
 */
button,
input,
optgroup,
select,
textarea {
  font-family: inherit;
  font-size: 100%;
  font-weight: inherit;
  line-height: inherit;
  color: inherit;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  
  /* Remove default appearance */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/**
 * Button reset
 * - Remove default styling
 * - Indicate clickability
 */
button,
[type="button"],
[type="reset"],
[type="submit"] {
  cursor: pointer;
  -webkit-appearance: button;
  appearance: button;
  background-color: transparent;
  background-image: none;
}

/**
 * Disabled button state
 */
button:disabled,
[type="button"]:disabled,
[type="reset"]:disabled,
[type="submit"]:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/**
 * Remove inner border and padding in Firefox
 */
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
  border-style: none;
  padding: 0;
}

/**
 * Input elements
 * - Consistent sizing
 * - Remove default styling
 */
input {
  border-radius: 0; /* Remove iOS default rounded corners */
}

/**
 * Checkbox and radio inputs
 * - Keep default appearance for accessibility
 * - But allow custom styling
 */
[type="checkbox"],
[type="radio"] {
  -webkit-appearance: checkbox;
  -moz-appearance: checkbox;
  appearance: auto;
  width: auto;
  height: auto;
}

/**
 * Search input
 * - Consistent styling across browsers
 */
[type="search"] {
  -webkit-appearance: textfield;
  appearance: textfield;
  outline-offset: -2px;
}

/**
 * Remove inner padding and search cancel button in Safari
 */
[type="search"]::-webkit-search-decoration,
[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

/**
 * Number input spinners
 * - Hide by default, can be shown via design system
 */
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
  height: auto;
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

[type="number"] {
  -moz-appearance: textfield;
}

/**
 * File input
 * - Inherit font styles
 */
::-webkit-file-upload-button {
  -webkit-appearance: button;
  appearance: button;
  font: inherit;
}

::file-selector-button {
  font: inherit;
}

/**
 * Textarea
 * - Only allow vertical resizing by default
 * - Prevent horizontal overflow
 */
textarea {
  resize: vertical;
  overflow: auto;
  vertical-align: top;
}

/**
 * Select element
 * - Consistent appearance
 */
select {
  text-transform: none;
}

/**
 * Remove default down arrow in IE10+
 */
select::-ms-expand {
  display: none;
}

/**
 * Fieldset and legend
 * - Reset default styling
 */
fieldset {
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
}

legend {
  padding: 0;
  display: table;
  max-width: 100%;
  white-space: normal;
  color: inherit;
}

/**
 * Labels
 * - Indicate clickability
 */
label {
  cursor: pointer;
}

/**
 * Placeholder styling
 * - Consistent color across browsers
 */
::placeholder {
  color: inherit;
  opacity: 0.5;
}

/**
 * Progress element
 * - Consistent appearance
 */
progress {
  vertical-align: baseline;
  -webkit-appearance: none;
  appearance: none;
}

/**
 * Meter element
 */
meter {
  -webkit-appearance: none;
  appearance: none;
}

/**
 * Output element
 */
output {
  display: inline-block;
}


/* ==========================================================================
   9. INTERACTIVE ELEMENTS
   ========================================================================== */

/**
 * Summary element (accordion trigger)
 * - Remove default marker in some browsers
 * - Indicate clickability
 */
summary {
  display: list-item;
  cursor: pointer;
  outline: none;
}

/**
 * Remove default marker styling
 */
summary::-webkit-details-marker {
  display: none;
}

summary::marker {
  content: '';
}

/**
 * Details element
 */
details {
  display: block;
}

/**
 * Dialog element
 * - Ensure proper stacking and positioning
 */
dialog {
  background-color: inherit;
  border: none;
  color: inherit;
  padding: 0;
  margin: auto;
  max-height: calc(100% - 2em);
  max-width: calc(100% - 2em);
  overflow: auto;
}

dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
}

/**
 * Template element
 * - Hide completely
 */
template {
  display: none;
}


/* ==========================================================================
   10. FOCUS STYLES
   ========================================================================== */

/**
 * Focus visible - Modern approach
 * - Only show focus ring for keyboard navigation
 * - Accessible but not intrusive for mouse users
 */
:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

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

/**
 * Skip link styling
 * - For accessibility navigation
 */
[href="#main-content"]:focus,
[href="#content"]:focus,
.skip-link:focus {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  padding: 1em;
  background-color: #000;
  color: #fff;
}


/* ==========================================================================
   11. SELECTION
   ========================================================================== */

/**
 * Text selection styling
 * - Will be customized by design system
 * - Improve contrast for accessibility
 */
::selection {
  background-color: Highlight;
  color: HighlightText;
  text-shadow: none;
}

::-moz-selection {
  background-color: Highlight;
  color: HighlightText;
  text-shadow: none;
}


/* ==========================================================================
   12. SCROLLBAR STYLING (Optional - Modern Browsers)
   ========================================================================== */

/**
 * Custom scrollbar base styles
 * - Will be customized by design system
 * - Only applies to WebKit browsers
 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.3);
}

/**
 * Dark mode scrollbar
 */
@media (prefers-color-scheme: dark) {
  ::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
  }

  ::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.3);
  }
}


/* ==========================================================================
   13. PRINT STYLES
   ========================================================================== */

@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  html {
    font-size: 12pt;
  }

  body {
    min-height: auto;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 80%;
  }

  a[href^="#"]::after,
  a[href^="javascript:"]::after {
    content: "";
  }

  abbr[title]::after {
    content: " (" attr(title) ")";
  }

  pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  }

  img,
  svg,
  figure {
    max-width: 100% !important;
    page-break-inside: avoid;
  }

  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    page-break-inside: avoid;
  }

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

  table {
    border-collapse: collapse !important;
  }

  thead {
    display: table-header-group;
  }

  tr,
  img {
    page-break-inside: avoid;
  }
}


/* ==========================================================================
   14. CODE ELEMENTS
   ========================================================================== */

/**
 * Monospace font stack
 * - Consistent code styling
 */
code,
kbd,
samp,
pre {
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 
               'Liberation Mono', monospace;
  font-size: 1em;
}

pre {
  overflow: auto;
  white-space: pre;
  word-wrap: normal;
}

/**
 * Keyboard input styling
 */
kbd {
  font-size: 0.875em;
}


/* ==========================================================================
   15. HIDDEN & ACCESSIBILITY
   ========================================================================== */

/**
 * Hidden attribute
 * - Ensure it works consistently
 */
[hidden] {
  display: none !important;
}

/**
 * Visually hidden but accessible to screen readers
 * Use class .sr-only or .visually-hidden
 */
.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: 0;
}

/**
 * Allow visually hidden elements to be focusable
 */
.sr-only-focusable:focus,
.sr-only-focusable:active,
.visually-hidden-focusable:focus,
.visually-hidden-focusable:active {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/**
 * Disable pointer events
 */
.pointer-events-none {
  pointer-events: none;
}

/**
 * Disable user selection
 */
.user-select-none {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}


/* ==========================================================================
   16. ARIA & SEMANTIC ELEMENT SUPPORT
   ========================================================================== */

/**
 * Indicate disabled state for ARIA
 */
[aria-disabled="true"],
[disabled] {
  cursor: not-allowed;
}

/**
 * Hide decorative elements from screen readers
 */
[aria-hidden="true"] {
  display: block;
}

/**
 * Ensure clickable ARIA elements have cursor
 */
[aria-controls],
[aria-expanded],
[aria-haspopup],
[role="button"],
[role="tab"],
[role="checkbox"],
[role="radio"],
[role="switch"],
[role="option"],
[role="menuitem"],
[role="link"] {
  cursor: pointer;
}

/**
 * Mark element
 * - For highlighted/marked text
 */
mark {
  background-color: #ff0;
  color: #000;
}


/* ==========================================================================
   17. MISCELLANEOUS
   ========================================================================== */

/**
 * Address element
 * - Remove italic styling
 */
address {
  font-style: normal;
  line-height: inherit;
}

/**
 * Prevent VoiceOver from ignoring list semantics
 * when list-style is removed
 */
[role="list"] {
  list-style: none;
}

/**
 * Remove touch callout on iOS
 * - Prevents long-press popup on links/images
 */
a,
img,
button {
  -webkit-touch-callout: none;
}

/**
 * Main element
 * - Full width flex item
 */
main {
  flex: 1;
  width: 100%;
}

/**
 * Article, aside, footer, header, nav, section
 * - Block display for older browsers
 */
article,
aside,
footer,
header,
hgroup,
main,
nav,
section {
  display: block;
}

/**
 * Prevent content from being selectable
 * (for UI elements only, not text content)
 */
[data-noselect] {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/**
 * Touch action optimization
 * - Improve touch responsiveness
 */
a,
area,
button,
input,
label,
select,
summary,
textarea,
[tabindex] {
  touch-action: manipulation;
}

/**
 * Content editable styling
 */
[contenteditable] {
  outline: none;
}

[contenteditable]:empty::before {
  content: attr(data-placeholder);
  opacity: 0.5;
}