:root {
    /* Light Mode Variables */
    --primary-color: #2c3e50; /* Darker blue-gray, professional */
    --secondary-color: #3498db; /* Vibrant blue */
    --accent-color: #e74c3c; /* Red for highlights/hover */
    --text-color: #34495e; /* Darker text for readability */
    --light-text-color: #ecf0f1; /* Light text for dark backgrounds */
    --background-color: #f8f9fa; /* Lighter background */
    --card-background: #ffffff;
    --border-color: #e0e0e0;
    --shadow-light: 0 2px 5px rgba(0, 0, 0, 0.05);
    --shadow-medium: 0 5px 15px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
    --spacing-unit: 1em;
}

body.dark-mode {
    /* Dark Mode Variables */
    --primary-color: #5fa8d3; /* Lighter blue for dark mode primary elements */
    --secondary-color: #4ea8de; /* Slightly different blue */
    --accent-color: #e74c3c; /* Still red for highlights */
    --text-color: #ecf0f1; /* Light text */
    --light-text-color: #2c3e50; /* Darker text for light backgrounds in dark mode */
    --background-color: #1a202c; /* Dark background */
    --card-background: #2d3748; /* Darker card background */
    --border-color: #4a5568;
    --shadow-light: 0 2px 5px rgba(0, 0, 0, 0.3);
    --shadow-medium: 0 5px 15px rgba(0, 0, 0, 0.4);
}

body {
    font-family: 'Inter', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Apply sticky to the new wrapper */
.sticky-wrapper {
    position: sticky;
    top: 0;
    z-index: 100; /* Ensure it stays above other content */
    background-color: var(--primary-color); /* Ensure background is defined for the sticky part */
    box-shadow: var(--shadow-medium); /* Add shadow for better visibility when sticky */
}

/* General Header Styling for Flexbox */
header.site-header {
    display: flex;
    justify-content: space-between; /* Distribute items */
    align-items: center; /* Vertically center */
    padding: var(--spacing-unit) calc(2 * var(--spacing-unit)); /* Consistent padding */
    color: var(--light-text-color);
    position: static; /* No longer sticky, wrapper handles it */
    top: auto;
    z-index: auto;
    text-align: left; /* Default to left align to give space */
}

header.site-header .header-left {
    display: flex;
    align-items: center;
}

header.site-header h2 {
    margin: 0; /* Remove default margin from h2 */
    font-size: 2.2em; /* Desktop size */
    letter-spacing: 0.05em;
    font-weight: 700;
    flex-shrink: 0; /* Prevent it from shrinking too much */
}

header.site-header .header-right { /* New styling for header-right */
    /* position: relative; Removed this for static search results */
    display: flex; /* Make it a flex container */
    align-items: center; /* Align items vertically */
    gap: var(--spacing-unit); /* Space between search and toggle */
    margin-left: auto; /* Push header-right to the far right on desktop */
}

/* Menu Toggle Styling (Desktop - hidden) */
.menu-toggle {
    display: none; /* Hidden by default on desktop */
    background: none;
    border: none;
    color: var(--light-text-color);
    font-size: 2em;
    cursor: pointer;
    padding: 0.5em;
}

/* Theme Toggle Styling (Desktop) */
#theme-toggle {
    position: static;
    margin-left: 0; /* Reset any auto margin */
}

/* Search Input Styling */
#search-input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1em;
    width: auto; /* Let content determine width, or give it flex-grow */
    min-width: 150px; /* Ensure it's not too small */
    background-color: var(--card-background);
    color: var(--text-color);
    transition: all 0.3s ease;
}

#search-input::placeholder {
    color: var(--text-color);
    opacity: 0.7;
}

#search-input:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
    outline: none;
}

/* Search Results Container Styling */
#search-results {
    /* Reverted max-width and margin to match article again for static placement */
    max-width: 75%; /* Match main content width */
    margin: var(--spacing-unit) auto; /* Top margin, and auto left/right for centering */

    background-color: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    margin-top: var(--spacing-unit); /* Give space below main nav */
    padding: var(--spacing-unit);
    display: none; /* Hidden by default, shown by JS */
    max-height: 400px; /* Limit height */
    overflow-y: auto; /* Enable scrolling for many results */
    z-index: 99; /* Below sticky header */
    position: relative; /* Normal flow */
}

#search-results h3 {
    margin-top: 0;
    margin-bottom: var(--spacing-unit);
    color: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5em;
}

#search-results ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

#search-results li {
    margin-bottom: var(--spacing-unit);
    padding-bottom: var(--spacing-unit);
    border-bottom: 1px dashed var(--border-color);
}

#search-results li:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

#search-results li a {
    font-weight: 600;
    color: var(--secondary-color);
    text-decoration: none;
    display: block;
    margin-bottom: 0.3em;
}

#search-results li a:hover {
    text-decoration: underline;
}

#search-results li p {
    font-size: 0.9em;
    color: var(--text-color);
    margin: 0;
}

/* Search Results Info (Ctrl+F Hint) */
#search-results-info {
    max-width: 75%; /* Match main content width */
    margin: var(--spacing-unit) auto 0.5em auto; /* Space from sticky header, auto left/right for centering */
    text-align: center;
    font-size: 0.9em;
    color: var(--text-color); /* Use theme text color */
    padding: 0.5em;
    border-bottom: 1px dashed var(--border-color); /* Subtle separator */
    display: none; /* Hidden by default, only shown if search results container is shown */
}

#search-results-info p {
    margin: 0;
}

/* --- Reverted Floating Search Results Styling --- */
/* Remove .search-overlay-container styles completely */
.search-overlay-container {
    display: none !important; /* Force hide if any remnants */
}

@media (min-width: 769px) { /* Desktop only adjustments */
    header.site-header .header-right {
        /* Revert to default behavior, no specific width for results container */
        width: auto; 
        flex-shrink: 1; 
    }
}

@media (max-width: 768px) {
    /* Ensure search input on mobile still looks good */
    header.site-header .header-right {
        /* ... existing mobile header-right flex styles ... */
        position: static; /* Revert */
    }
}


.main-nav {
    background-color: var(--secondary-color);
    box-shadow: var(--shadow-light);
    padding: 0 calc(2 * var(--spacing-unit));
    display: flex;
    justify-content: center;
    align-items: center;
    position: static; /* No longer sticky on its own, wrapper handles it */
    z-index: auto; /* Z-index managed by wrapper */
}

.main-nav .nav-links ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center; /* Center main nav items */
}

.main-nav .nav-links ul li {
    position: relative;
    margin: 0 5px;
}

.main-nav .nav-links ul li a {
    display: block;
    padding: 15px 20px;
    text-decoration: none;
    color: var(--light-text-color);
    font-weight: 600;
    transition: background-color 0.3s ease, color 0.3s ease;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.main-nav .nav-links ul li ul {
    display: none;
    position: absolute;
    background-color: var(--primary-color);
    min-width: 250px;
    box-shadow: var(--shadow-medium);
    z-index: 1000;
    flex-direction: column;
    padding: 10px 0;
    left: 0;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    overflow: hidden;
}

.main-nav .nav-links ul li:hover > ul {
    display: flex;
}

.main-nav .nav-links ul li ul li {
    margin: 0;
    width: 100%;
}

.main-nav .nav-links ul li ul li a {
    padding: 10px 20px;
    color: var(--light-text-color);
    white-space: nowrap;
    font-weight: normal;
    border-radius: 0;
}

.main-nav .nav-links ul li ul li a:hover,
.main-nav .nav-links ul li ul li a:focus {
    background-color: var(--secondary-color);
    color: white;
}

main {
    flex-grow: 1;
    padding: var(--spacing-unit);
    max-width: 75%; /* Changed from 95% to 75% */
    margin: calc(2 * var(--spacing-unit)) auto;
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
}

.content-article {
    padding: calc(1.5 * var(--spacing-unit));
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--card-background); /* Use variable */
}

.content-article h1, .content-article h2, .content-article h3, .content-article h4, .content-article h5 { /* Added h4, h5 for consistency */
    color: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5em;
    margin-top: 1.5em;
    margin-bottom: 1em;
}

.content-article p {
    margin-bottom: 1em;
    line-height: 1.7;
}


footer {
    background-color: var(--primary-color);
    color: var(--light-text-color);
    text-align: center;
    padding: var(--spacing-unit) calc(2 * var(--spacing-unit));
    margin-top: auto;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    /* No longer apply sticky to header.site-header directly, it's handled by sticky-wrapper */
    header.site-header {
        flex-wrap: wrap; /* Allow items to wrap if space is tight */
        justify-content: space-between;
        padding: var(--spacing-unit);
        position: static; /* Not sticky on its own */
        background-color: transparent; /* Background on sticky-wrapper */
        box-shadow: none; /* Shadow on sticky-wrapper */
    }

    header.site-header .header-left {
        order: 1; /* First item */
        flex-grow: 1; /* Allow it to take available space */
        justify-content: flex-start; /* Align menu toggle and title to start */
    }

    header.site-header h2 {
        font-size: 1.3em; /* Smaller title on mobile */
        text-align: left;
        margin-left: 10px; /* Space from hamburger */
    }

    header.site-header #theme-toggle {
        order: 2; /* Second item */
        position: static;
        margin-left: 0; /* Reset margin-left auto */
    }

    /* Show hamburger on mobile */
    .menu-toggle {
        display: block;
        font-size: 1.5em; /* Adjust size for mobile */
        padding: 0.3em;
    }

    /* Main Nav (below sticky header) */
    .main-nav {
        flex-direction: column;
        align-items: flex-start;
        padding: 0;
        position: static; /* Not sticky on its own */
        width: 100%;
        background-color: var(--secondary-color); /* Maintain background */
        box-shadow: var(--shadow-light); /* Keep its own shadow */
    }

    .main-nav .nav-links {
        display: none; /* Hidden by default */
        flex-direction: column;
        width: 100%;
        background-color: var(--secondary-color);
        box-shadow: none; /* No shadow here */
        position: static; /* Ensure it's not absolutely positioned */
    }

    .main-nav .nav-links.active {
        display: flex; /* Show when active */
    }

    .main-nav .nav-links ul {
        flex-direction: column;
        width: 100%;
        align-items: stretch;
    }
    
    .main-nav .nav-links ul li a {
        padding: 10px 20px;
        text-align: left;
    }

    .main-nav .nav-links ul li ul { /* Submenus */
        position: static;
        box-shadow: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 0;
        background-color: var(--primary-color);
        padding-left: 20px; /* Indent submenu items further */
    }

    .main-nav .nav-links ul li:hover > ul {
        display: flex; /* Still show submenu on hover */
    }

    main {
        margin: var(--spacing-unit);
        max-width: calc(100% - (2 * var(--spacing-unit))); /* Adjust for padding on small screens */
    }
    
    .content-article {
        padding: var(--spacing-unit);
    }

    /* Mobile adjustments for search input */
    header.site-header .header-right {
        order: 3; /* Placed below header-left */
        width: 100%; /* Takes full width below header left */
        margin-top: var(--spacing-unit); /* Space from header-left */
        justify-content: flex-end; /* Push theme toggle to right if not full width */
        display: flex;
        flex-wrap: wrap; /* Allow wrapping */
        align-items: center;
    }

    #search-input {
        flex-grow: 1; /* Allow search input to grow */
        margin-right: var(--spacing-unit); /* Space between search and toggle */
    }

    #theme-toggle {
        margin-left: 0; /* Reset desktop margin */
    }
}