:root {
    --spacing-unit: 1rem;
    --container-width: 1200px;
    /* Add breakpoints for consistent responsive design */
    --breakpoint-sm: 640px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1024px;
    --breakpoint-xl: 1280px;
}

/* Reset with improved mobile touch handling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Improved font rendering */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html, body {
    height: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Raleway', sans-serif;
    line-height: 1.5;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Remove any body padding - content padding should be handled by containers */
    padding: 0 !important;
    margin: 0 !important;
    /* Prevent content reflow */
    overflow-y: scroll;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: none;
    background-color: var(--bg-color);
}

/* Container with improved mobile responsiveness */
.container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 var(--spacing-unit);
    width: 100%;
}

/* Page Container - for page specific content */
.page-container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: calc(var(--spacing-unit) * 2);
    width: 100%;
}

/* Page Title - standardized across all pages */
.page-container > h1,
main .page-container > h1 {
    font-size: clamp(1.5rem, 5vw, 2rem); /* Responsive font size */
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: calc(var(--spacing-unit) * 3);
    line-height: 1.2;
    text-align: left;
    padding-bottom: calc(var(--spacing-unit) * 0.5);
    border-bottom: 2px solid var(--border-color);
    overflow-wrap: break-word; /* Prevent text overflow on mobile */
    hyphens: auto; /* Enable hyphenation for better text wrapping */
}

/* Main Content */
.main {
    flex: 1 0 auto;
    width: 100%;
    /* Improve scrolling performance */
    will-change: transform;
    /* Enable momentum scrolling on iOS */
    -webkit-overflow-scrolling: touch;
}

/* Footer */
.footer {
    flex-shrink: 0;
    background: var(--bg-header);
    padding: calc(var(--spacing-unit) * 2) 0;
    text-align: center;
    width: 100%;
    border-top: 1px solid var(--border-color);
}

.footer .social-links {
    justify-content: center;
    margin-bottom: 1rem;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 1rem;
}

/* Grid Layouts with improved mobile support */
.grid {
    display: grid;
    gap: var(--spacing-unit);
}

.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
}

.grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
}

/* Responsive adjustments */
@media (max-width: 768px) {
    :root {
        --spacing-unit: 0.875rem; /* Slightly reduced spacing on mobile */
    }

    .page-container {
        padding: var(--spacing-unit);
    }

    .page-container > h1,
    main .page-container > h1 {
        margin-bottom: calc(var(--spacing-unit) * 2);
    }

    /* Adjust grid gap on mobile */
    .grid {
        gap: calc(var(--spacing-unit) * 1.5);
    }
}

/* Prevent content shift when scrollbar appears */
@media screen and (min-width: 960px) {
    html {
        margin-left: calc(100vw - 100%);
        margin-right: 0;
    }
}

/* Improved image handling */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Responsive tables */
table {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: block; /* Enable horizontal scrolling on mobile */
    margin-bottom: var(--spacing-unit);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

/* Print styles */
@media print {
    body {
        min-height: 0;
        background-color: white;
        color: black;
    }

    .no-print {
        display: none !important;
    }
}

/* Focus styles for accessibility */
:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
