/* Enhanced CSS Reset & Base Styles */

/* Modern CSS Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Remove list styles on ul, ol elements with a list role */
ul[role="list"],
ol[role="list"] {
    list-style: none;
}

/* Set core root defaults */
html {
    line-height: var(--leading-normal);
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    scroll-behavior: smooth;
    tab-size: 4;
}

/* Set core body defaults */
body {
    min-height: 100vh;
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    font-weight: var(--font-normal);
    color: var(--color-text-primary);
    background-color: var(--color-surface);
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Remove list styles for navigation */
ul,
ol {
    list-style: none;
}

/* Make images responsive by default */
img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Inherit fonts for inputs and buttons */
input,
button,
textarea,
select {
    font: inherit;
    color: inherit;
}

/* Remove button defaults */
button {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
}

/* Remove default fieldset styles */
fieldset {
    border: none;
    margin: 0;
    padding: 0;
}

/* Remove default legend styles */
legend {
    padding: 0;
}

/* Remove default table styles */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* Remove default link styles */
a {
    color: inherit;
    text-decoration: none;
}

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

/* Enhanced Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-surface);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
    background: var(--color-quaternary);
    border-radius: var(--radius-full);
    border: 2px solid var(--color-surface);
    transition: background var(--transition-fast);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-tertiary);
}

::-webkit-scrollbar-thumb:active {
    background: var(--color-secondary);
}

::-webkit-scrollbar-corner {
    background: var(--color-surface);
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-quaternary) var(--color-surface);
}

/* Enhanced Focus Styles */
:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
    transition: outline var(--transition-fast);
}

/* Focus for interactive elements */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[role="button"]:focus-visible,
[role="tab"]:focus-visible,
[role="menuitem"]:focus-visible,
[tabindex]:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
    box-shadow: var(--focus-ring-offset-shadow), var(--focus-ring-shadow);
}

/* Enhanced focus for links */
a:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
    border-radius: var(--radius-xs);
}

/* Skip links for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--color-primary);
    color: var(--color-text-inverse);
    padding: var(--space-2) var(--space-4);
    z-index: var(--z-skiplink);
    text-decoration: none;
    border-radius: var(--radius-base);
    font-weight: var(--font-medium);
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: 6px;
}

/* Enhanced Selection Styles */
::selection {
    background: oklch(0.15 0 0 / 0.1);
    color: var(--color-text-primary);
    text-shadow: none;
}

::-moz-selection {
    background: oklch(0.15 0 0 / 0.1);
    color: var(--color-text-primary);
    text-shadow: none;
}

/* Reduce motion for users who prefer it */
@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;
    }
}

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
    :root {
        --color-border: var(--color-gray-900);
        --color-border-subtle: var(--color-gray-800);
    }
    
    .dark {
        --color-border: var(--color-gray-100);
        --color-border-subtle: var(--color-gray-200);
    }
}

/* Screen reader only utility */
.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;
}

.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Typography base styles */
h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-bold);
    line-height: var(--leading-tight);
    color: var(--color-text-primary);
    margin: 0;
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 { font-size: var(--text-sm); }

p {
    margin: 0;
    line-height: var(--leading-relaxed);
}

small {
    font-size: var(--text-xs);
}

strong, b {
    font-weight: var(--font-semibold);
}

em, i {
    font-style: italic;
}

code {
    font-family: ui-monospace, SFMono-Regular, 'Cascadia Code', 'Roboto Mono', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.875em;
    background: var(--color-surface);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-xs);
    border: 1px solid var(--color-border-subtle);
}

pre {
    overflow: auto;
    background: var(--color-surface);
    padding: var(--space-4);
    border-radius: var(--radius-base);
    border: 1px solid var(--color-border);
    font-family: ui-monospace, SFMono-Regular, 'Cascadia Code', 'Roboto Mono', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
}

pre code {
    background: none;
    padding: 0;
    border: none;
    font-size: inherit;
}

blockquote {
    margin: 0;
    padding: var(--space-4);
    border-left: 4px solid var(--color-border);
    background: var(--color-surface);
    border-radius: var(--radius-base);
    font-style: italic;
}

hr {
    border: none;
    height: 1px;
    background: var(--color-border);
    margin: var(--space-8) 0;
}

/* Form element improvements */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="tel"],
input[type="number"],
input[type="search"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select {
    appearance: none;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-base);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--color-text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-outline);
}

input:disabled,
textarea:disabled,
select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Placeholder styles */
::placeholder {
    color: var(--color-text-tertiary);
    opacity: 1;
}

::-webkit-input-placeholder {
    color: var(--color-text-tertiary);
    opacity: 1;
}

::-moz-placeholder {
    color: var(--color-text-tertiary);
    opacity: 1;
}

:-ms-input-placeholder {
    color: var(--color-text-tertiary);
    opacity: 1;
}

/* Auto-fill styles */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--color-text-primary);
    -webkit-box-shadow: 0 0 0 1000px var(--color-surface-elevated) inset;
    transition: background-color 5000s ease-in-out 0s;
}

/* Checkbox and radio improvements */
input[type="checkbox"],
input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
}

/* Better table defaults */
table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
}

th,
td {
    text-align: left;
    vertical-align: top;
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border);
}

th {
    font-weight: var(--font-semibold);
    background: var(--color-surface);
}

/* Print Styles */
@media print {
    *,
    *::before,
    *::after {
        background: transparent !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) ")";
    }
    
    a[href^="#"]:after,
    a[href^="javascript:"]:after {
        content: "";
    }
    
    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;
    }
    
    @page {
        margin: 2cm;
    }
}

/* Animation utilities for loading states */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(-25%);
        animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
    }
    50% {
        transform: translateY(0);
        animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideOutDown {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}