/**
 * CSS Reset / Normalize
 * =====================
 * 
 * A comprehensive CSS reset that establishes consistent baseline styles
 * across all browsers. This file must be loaded FIRST in the CSS load order.
 * 
 * Features:
 * - Box-sizing border-box for all elements
 * - Margin and padding resets
 * - Font smoothing for improved text rendering
 * - Sensible defaults for common elements
 * - Accessibility-friendly resets
 * 
 * NO FRAMEWORKS: Pure CSS only — no Bootstrap, no Tailwind, no dependencies.
 * 
 * Requirements: 2.2, 9.3
 * 
 * @file /css/base/reset.css
 * @since 2025-01-01
 */

/* ==========================================================================
   Box Sizing
   ========================================================================== */

/**
 * Universal box-sizing reset
 * Makes padding and border included in element's total width/height
 */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* ==========================================================================
   Root & Document
   ========================================================================== */

/**
 * Root element defaults
 * - Smooth scrolling for anchor navigation
 * - Prevent horizontal overflow
 * - Improved text rendering
 */
:root {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/**
 * HTML element reset
 * - Full height for sticky footers
 * - Prevent iOS font size adjustment
 * - Smooth scrolling behavior
 */
html {
    height: 100%;
    line-height: 1.15;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

/**
 * Body element reset
 * - Remove default margin
 * - Full minimum height
 * - Sensible font defaults
 */
body {
    min-height: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: inherit;
    background-color: inherit;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Margin & Padding Resets
   ========================================================================== */

/**
 * Remove default margins from common block elements
 */
h1, h2, h3, h4, h5, h6,
p, blockquote, pre,
dl, dd, ol, ul,
figure, hr,
fieldset, legend {
    margin: 0;
    padding: 0;
}

/**
 * Remove list styles on ul, ol elements
 * Note: List styles can be restored with specific classes
 */
ul, ol {
    list-style: none;
}

/* ==========================================================================
   Typography
   ========================================================================== */

/**
 * Headings
 * - Inherit font-family from body
 * - Sensible line-height for readability
 */
h1, h2, h3, h4, h5, h6 {
    font-family: inherit;
    font-weight: 600;
    line-height: 1.2;
    color: inherit;
}

/**
 * Paragraph default
 */
p {
    line-height: 1.6;
}

/**
 * Strong element
 * - Add explicit font-weight for Edge/IE
 */
strong, b {
    font-weight: 700;
}

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

/**
 * Prevent sub and sup 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;
}

/* ==========================================================================
   Links
   ========================================================================== */

/**
 * Anchor/Link reset
 * - Remove default underline
 * - Inherit color by default
 * - Remove outline on focus (custom focus styles should be applied)
 */
a {
    color: inherit;
    text-decoration: none;
    background-color: transparent;
}

a:hover {
    text-decoration: underline;
}

/**
 * Remove the outline on focused links when they are also active or hovered
 */
a:active,
a:hover {
    outline-width: 0;
}

/* ==========================================================================
   Media Elements
   ========================================================================== */

/**
 * Responsive media elements
 * - Prevent overflow
 * - Maintain aspect ratio
 */
img, video, audio, canvas, iframe, embed, object {
    display: block;
    max-width: 100%;
    height: auto;
}

/**
 * Remove border on images inside links in IE 10
 */
img {
    border-style: none;
}

/**
 * Hide overflow in IE
 */
svg:not(:root) {
    overflow: hidden;
}

/* ==========================================================================
   Forms
   ========================================================================== */

/**
 * Form element resets
 * - Inherit font properties
 * - Remove default appearance
 */
button,
input,
optgroup,
select,
textarea {
    font-family: inherit;
    font-size: 100%;
    line-height: 1.15;
    margin: 0;
    padding: 0;
}

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

/**
 * Remove inheritance of text-transform in Edge, Firefox, IE
 */
button,
select {
    text-transform: none;
}

/**
 * Correct inability to style clickable types in iOS and Safari
 */
button,
[type="button"],
[type="reset"],
[type="submit"] {
    -webkit-appearance: button;
    appearance: button;
    cursor: pointer;
}

/**
 * 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;
}

/**
 * Restore focus styles unset by previous rule
 */
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
    outline: 1px dotted ButtonText;
}

/**
 * Input field resets
 */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"],
input[type="week"],
textarea {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/**
 * Remove inner padding in Chrome and Safari on macOS
 */
[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
}

/**
 * Correct inability to style clickable types in iOS and Safari
 */
::-webkit-file-upload-button {
    -webkit-appearance: button;
    font: inherit;
}

/**
 * Textarea
 * - Only allow vertical resize
 * - Remove default resize handle in some browsers
 */
textarea {
    overflow: auto;
    resize: vertical;
}

/**
 * Fieldset reset
 */
fieldset {
    border: 0;
    min-width: 0;
}

/**
 * Legend reset
 * - Correct text wrapping in Edge and IE
 * - Correct color inheritance from fieldset
 */
legend {
    display: table;
    max-width: 100%;
    white-space: normal;
    color: inherit;
}

/**
 * Progress bar reset
 * - Add correct vertical alignment in Chrome, Firefox, Opera
 */
progress {
    vertical-align: baseline;
}

/**
 * Remove default vertical scrollbar in IE 10+
 */
textarea {
    overflow: auto;
}

/**
 * Checkbox and radio reset
 * - Add correct box sizing in IE 10
 * - Remove padding in IE 10
 */
[type="checkbox"],
[type="radio"] {
    box-sizing: border-box;
    padding: 0;
}

/**
 * Number input spin buttons
 * - Correct cursor style in Chrome
 */
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
    height: auto;
}

/* ==========================================================================
   Tables
   ========================================================================== */

/**
 * Table reset
 * - Remove spacing between table cells
 * - Ensure consistent border behavior
 */
table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
}

th {
    text-align: left;
    font-weight: 600;
}

td, th {
    padding: 0;
}

/* ==========================================================================
   Misc Elements
   ========================================================================== */

/**
 * Horizontal rule reset
 * - Add correct box sizing in Firefox
 * - Show overflow in Edge and IE
 */
hr {
    box-sizing: content-box;
    height: 0;
    overflow: visible;
    border: 0;
    border-top: 1px solid currentColor;
    opacity: 0.25;
}

/**
 * Add correct display in IE 10+
 */
template {
    display: none;
}

/**
 * Hidden attribute support
 * - Add correct display in IE 10
 */
[hidden] {
    display: none !important;
}

/**
 * Abbreviation with title
 * - Add correct text decoration in Chrome, Edge, Safari
 */
abbr[title] {
    border-bottom: none;
    text-decoration: underline;
    text-decoration: underline dotted;
}

/**
 * Code elements
 * - Correct font and sizing
 */
code, kbd, samp, pre {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 1em;
}

/**
 * Pre element
 * - Allow horizontal scroll for overflow
 */
pre {
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/**
 * Details/Summary reset
 * - Add correct display in Edge, IE, Firefox
 */
details {
    display: block;
}

summary {
    display: list-item;
    cursor: pointer;
}

/**
 * Address element
 * - Remove default italic style
 */
address {
    font-style: normal;
}

/**
 * Mark element
 * - Ensure visibility
 */
mark {
    background-color: #ff0;
    color: #000;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/**
 * Focus visible for keyboard navigation
 * - Apply visible focus ring only for keyboard users
 */
:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/**
 * Remove focus outline for mouse users
 * Note: This works in conjunction with :focus-visible
 */
:focus:not(:focus-visible) {
    outline: none;
}

/**
 * Reduced motion preference
 * - Disable 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;
    }
}

/**
 * Skip link styling (for accessibility)
 * - Hidden by default, visible on focus
 */
.skip-link {
    position: absolute;
    top: -9999px;
    left: -9999px;
    z-index: 10000;
    padding: 0.5rem 1rem;
    background: #000;
    color: #fff;
    text-decoration: none;
}

.skip-link:focus {
    top: 0;
    left: 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) ")";
    }

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

    pre {
        white-space: pre-wrap !important;
    }

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