:root {
    /* Color Palette Inspired by ChatGPT */
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f0f4f8;
    --color-text-primary: #1a1a1a;
    --color-text-secondary: #8d8b8b;
    --color-accent: #10a37f;
    --color-border: #e0e0e0;

    /* Dark Mode Palette */
    --color-bg-dark: #1a1a1a;
    --color-text-dark: #ffffff;
    --color-bg-secondary-dark: #2c2c2c;

    /* Color Scheme Variables */
    /* Light Mode Colors */
    --color-bg-hover: #151618;
    --color-code-bg: #f8f8f8;
    --color-code-text: #333;
    
    /* Dark Mode Colors */
    --color-bg-primary-dark: #121212;
    --color-bg-secondary-dark: #1e1e1e;
    --color-bg-hover-dark: #2a2a2a;
    --color-text-primary-dark: #e0e0e0;
    --color-text-secondary-dark: #b0b0b0;
    --color-border-dark: #333333;
    --color-accent-active-dark: #087d73;
    --color-accent-dark: #087d73;
    --color-bg-hover-active-dark: #10201f;
    --color-code-bg-dark: #2c2c2c;
    --color-code-text-dark: #e0e0e0;

    /* Typography */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Typography Styles Inspired by Pico CSS */
/* Headings */
h1, h2, h3, h4, h5, h6 {
    margin-bottom: 1rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-text-primary);
}

h1 {
    font-size: 2.5rem;
    margin-top: 2rem;
}

h2 {
    font-size: 2rem;
    margin-top: 1.75rem;
    padding-bottom: 0.5rem;
}

h3 {
    font-size: 1.75rem;
    margin-top: 1.5rem;
}

h4 {
    font-size: 1.5rem;
    margin-top: 1.25rem;
}

h5 {
    font-size: 1.25rem;
    margin-top: 1rem;
}

h6 {
    font-size: 1rem;
    margin-top: 1rem;
    color: var(--color-text-secondary);
}

/* Paragraph and Text Styles */
p {
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

small {
    font-size: 0.875rem;
}

/* Lists */
ul, ol {
    margin-bottom: 1.5rem;
    padding-left: 2rem;
}

ul {
    list-style-type: disc;
}

ol {
    list-style-type: decimal;
}

li {
    margin-bottom: 0.5rem;
}

/* Links */
a {
    color: var(--color-accent);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    text-decoration: underline;
    color: var(--color-accent-active-dark);
}

/* Code and Preformatted Text */
code, pre {
    font-family: 'Courier New', Courier, monospace;
    background-color: black;
    border-radius: 4px;
    color: #f8f8f2; /* Light text color for readability */
}

code {
    padding: 0.2rem 0.4rem;
    font-size: 0.9rem;
}

pre {
    padding: 1rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

pre code {
    padding: 0;
    background-color: transparent;
}

/* Blockquotes */
blockquote {
    border-left: 4px solid var(--color-accent);
    padding-left: 1rem;
    margin: 1.5rem 0;
    font-style: italic;
    color: var(--color-text-secondary);
}

/* Horizontal Rule */
hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 2rem 0;
}

/* Dark Mode Typography Adjustments */
@media (prefers-color-scheme: dark) {
    h1, h2, h3, h4, h5, h6 {
        color: var(--color-text-primary-dark);
    }

    a {
        color: var(--color-accent-dark);
    }

    a:hover {
        color: var(--color-accent-active-dark);
    }

    blockquote {
        color: var(--color-text-secondary-dark);
    }

    code, pre {
        background-color: black;
        color: #f8f8f2; /* Light text color for readability */
    }
}

/* Removed redundant heading style */

/* Paragraph and Text Elements */
p, ul, ol, dl {
    margin-bottom: var(--pico-typography-spacing-vertical);
}

a {
    text-decoration-thickness: var(--pico-border-width);
    text-underline-offset: var(--pico-text-underline-offset);
}

/* Code Typography */
code, pre {
    font-family: var(--pico-font-family-monospace);
    font-size: 0.9em; /* Slightly smaller than body text */
}

/* Responsive Typography Adjustments */
@media (min-width: 576px) {
    body {
        font-size: calc(var(--pico-font-size) * 1.0625);
    }
}

@media (min-width: 768px) {
    body {
        font-size: calc(var(--pico-font-size) * 1.125);
    }
}

@media (min-width: 1024px) {
    body {
        font-size: calc(var(--pico-font-size) * 1.1875);
    }
}

@media (min-width: 1280px) {
    body {
        font-size: calc(var(--pico-font-size) * 1.25);
    }
}

body {
    font-family: 'Inter', var(--pico-font-family-sans-serif);
    line-height: var(--pico-line-height);
    font-weight: var(--pico-font-weight);
    font-size: var(--pico-font-size);
    color: var(--color-text-primary);
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
}

body.dark-mode {
    --color-bg-primary: var(--color-bg-primary-dark);
    --color-bg-secondary: var(--color-bg-secondary-dark);
    --color-bg-hover: var(--color-bg-hover-dark);
    --color-text-primary: var(--color-text-primary-dark);
    --color-text-secondary: var(--color-text-secondary-dark);
    --color-border: var(--color-border-dark);
    --color-accent: var(--color-accent-dark);
    --color-accent-active: var(--color-accent-active-dark);
    --color-bg-hover-active: var(--color-bg-hover-active-dark);
    --color-code-bg: var(--color-code-bg-dark);
    --color-code-text: var(--color-code-text-dark);
}

/* Hugo-Friendly Page Transition Styles */
body {
    transition: opacity 0.3s ease-in-out;
}

/* Request State (Preparing to load) */
body.htmx-request {
    opacity: 0.7;
    transition: opacity 0.2s ease-in;
}

/* Swapping Content */
body.htmx-swapping {
    opacity: 0.5;
    transition: opacity 0.2s ease-in;
}

/* Settling (New Content Loaded) */
body.htmx-settling {
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

/* Fallback Transition */
.page-container {
    transition: 
        opacity 0.3s ease-in-out, 
        transform 0.3s ease-in-out;
}

.page-container.page-entering {
    opacity: 0;
    transform: translateY(10px);
}

.page-container.page-entered {
    opacity: 1;
    transform: translateY(0);
}

/* Prevent layout shifts */
body {
    overflow-x: hidden;
}

/* HTMX Transition Styles */
#page-content {
    transition: opacity 0.3s ease-in-out;
}

body.htmx-request #page-content {
    opacity: 0.5;
}

.htmx-indicator {
    display: none;
}

body.htmx-request .htmx-indicator {
    display: block;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

/* Smooth content replacement */
.htmx-swapping {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.htmx-settling {
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 2rem;
    background-color: var(--color-bg-primary);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

body.dark-mode .top-bar {
    background-color: var(--color-bg-primary-dark);
}

.top-bar-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1400px; /* Match page container width */
    position: relative;
}

.logo-container {
    display: flex;
    align-items: center;
    margin-right: auto; /* Push other elements to the right */
}

.search-container {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    max-width: 400px;
    width: 100%;
    margin: 0 1rem;
}

.top-nav {
    display: flex;
    align-items: center;
    margin-left: auto; /* Push to the right side */
}

.nav-link {
    margin: 0 0.5rem;
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--color-text-primary);
    transition: color 0.3s ease;
}

.nav-link:hover {
    color: var(--color-accent);
}

.theme-toggle-container {
    display: flex;
    align-items: center;
    margin-left: 1rem; /* Add some spacing between nav and theme toggle */
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
}

/* Theme Toggle Styles */
.theme-toggle-container {
    display: flex;
    align-items: center;
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    transition: transform 0.3s ease;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle-icon {
    width: 18px;
    height: 18px;
    stroke: var(--color-text-primary);
    stroke-width: 1.5;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.theme-toggle .dark-mode-icon {
    display: none;
}

body.dark-mode .theme-toggle .light-mode-icon {
    display: none;
}

body.dark-mode .theme-toggle .dark-mode-icon {
    display: block;
}

.theme-toggle:hover .theme-toggle-icon {
    stroke: var(--color-accent);
}

.theme-toggle:active .theme-toggle-icon {
    transform: rotate(180deg);
}

/* Debug styles to ensure visibility */
.debug-icon {
    border: 2px solid red;
    background-color: rgba(255, 0, 0, 0.1);
}

.theme-toggle-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

.theme-toggle:active .theme-toggle-icon {
    transform: rotate(180deg);
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* Search Container Styles */
.search-container {
    display: flex;
    align-items: center;
    
    /* Increased max-width to provide more horizontal space for search input */
    /* Previous width was too constrained, limiting user input visibility */
    max-width: 400px;  /* Expanded from 300px to 400px */
    
    width: 100%;
    margin: 0 1rem;
}

.search-input {
    flex-grow: 1;
    
    /* Reduced vertical padding to decrease overall input height */
    /* Previous padding made input feel overly tall and bulky */
    padding: 0.35rem 0.75rem;  /* Reduced from 0.5rem 1rem */
    
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    transition: all 0.3s ease;
    outline: none;
    
    /* Slightly smaller font size to complement reduced input height */
    /* Maintains proportional and clean typography */
    font-size: 0.9rem;  /* Reduced from default size */
}

.search-button {
    background: none;
    border: none;
    cursor: pointer;
    margin-left: -40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-button svg {
    width: 24px;
    height: 24px;
    stroke: var(--color-text-secondary);
    transition: stroke 0.3s ease;
}

.search-button:hover svg {
    stroke: var(--color-accent);
}

/* Page Container */
.page-container {
    display: grid;
    grid-template-columns: 250px 1fr 250px;
    gap: 1rem;
    max-width: 1400px;
    margin: 0 auto;
    opacity: 1;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}

/* Sidebar Navigation */
.sidebar {
    /* Sticky positioning ensures sidebar remains visible while scrolling */
    position: sticky;
    
    /* Positions sidebar below the top navigation */
    top: 80px;
    
    /* Calculate height to fit viewport, leaving space for header and potential footer */
    height: calc(100vh - 100px);
    
    /* Enable vertical scrolling for entire sidebar content */
    /* This is now the ONLY scrollable container for sidebar navigation */
    overflow-y: auto;
    
    /* Add slight right padding to prevent content touching the edge */
    padding-right: 1rem;
}

.sidebar-navigation {
    /* Transparent background to inherit parent container's style */
    background-color: transparent !important;
    
    /* Remove any right border to maintain clean design */
    border-right: none;
    
    /* CRITICAL FIX: Disable vertical scrolling to prevent duplicate scrollbars */
    /* Let parent .sidebar handle all scrolling functionality */
    overflow-y: hidden;
    
    /* Prevent horizontal scrolling and handle long content gracefully */
    overflow-x: hidden;
    
    /* Improve text rendering for long navigation items */
    word-break: break-word;
    
    /* Cross-browser hyphenation for better text wrapping */
    hyphens: auto;
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    -ms-hyphens: auto;
}

.sidebar-section {
    margin-bottom: 30px;
    width: 100%; /* Ensure full width */
    box-sizing: border-box; /* Include padding and border in width calculation */
}

.sidebar-section-title {
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 0.850rem;
    letter-spacing: 1px;
    padding-bottom: 10px;
    text-align: left;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-section-items,
.sidebar-subsection-items {
    list-style: none;
    padding: 0.4rem;
    margin: 0;
    text-align: left;
    max-width: 100%;
    overflow-x: hidden;
}

.sidebar-item,
.sidebar-subitem {
    margin-bottom: 8px;
    text-align: left;
    width: 100%;
}

.sidebar-item a,
.sidebar-subitem a,
.sidebar-subsection-title {
    color: var(--text-secondary);
    font-size: 0.750rem;
    font-weight: 400;
    text-decoration: none;
    transition: color 0.3s ease;
    display: block;
    padding: 5px 10px;
    border-radius: 4px;
    text-align: left;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-subsection-items {
    padding-left: 10px;
    width: calc(100% - 10px);
}

.no-navigation {
    color: var(--text-secondary);
    font-style: italic;
    text-align: left;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-section {
    margin-bottom: 1rem;
}

.nav-section-title {
    font-weight: bold;
    color: var(--color-text-primary);
    text-decoration: none;
    display: block;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.5rem;
}

.nav-subsections {
    list-style-type: none;
    padding-left: 0;
}

.nav-subsection {
    margin-bottom: 0.25rem;
}

.nav-subsection-link {
    color: var(--color-text-secondary);
    font-size: 0.857rem;
    text-decoration: none;
    display: block;
    padding: 0.25rem 0.5rem;
    transition: background-color 0.3s ease;
}

.nav-subsection-link:hover {
    background-color: var(--color-bg-hover);
    border-radius: 8px;
}

.nav-subsection.active > .nav-subsection-link {
    color: var(--color-accent-active);
    background-color: var(--color-bg-hover-active);
    font-weight: bold;
    border-radius: 8px;
}

.nav-sub-subsections {
    list-style-type: none;
    padding-left: 1rem;
}

.nav-sub-subsection-link {
    color: var(--color-text-secondary);
    text-decoration: none;
    display: block;
    padding: 0.25rem 0.5rem;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

.nav-sub-subsection-link:hover {
    color: var(--color-accent);
}

.nav-sub-subsections li.active > .nav-sub-subsection-link {
    color: var(--color-accent);
    font-weight: bold;
}

/* Right Navigation */
.right-nav {
    position: sticky;
    top: 80px;
    height: calc(100vh - 100px);
    overflow-y: auto;
    /* border-left: 1px solid var(--color-border); */
    padding: 1rem;
    background-color: transparent !important;
}

.page-contents-nav {
    background-color: transparent !important;
    padding: 0;
    overflow-y: auto;
    max-width: 100%;
    overflow-x: hidden;
    word-wrap: break-word;
    white-space: normal;
}

.page-contents-nav ul {
    background-color: transparent !important;
    max-width: 100%;
    overflow-x: hidden;
    word-wrap: break-word;
    white-space: normal;
}

.page-contents-nav ul li {
    max-width: 100%;
    overflow-x: hidden;
    word-wrap: break-word;
    white-space: normal;
}

.page-contents-nav a {
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    text-decoration: none;
    transition: color 0.3s;
}

.page-contents-nav a:hover {
    color: var(--color-accent);
}

.page-contents-nav a:active {
    color: var(--color-accent-active);
}

.right-nav-section-title {
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 0.9rem;
    letter-spacing: 1px;
    padding-bottom: 10px;
    text-align: left;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Content Page Styles */
.content-page,
.section-list {
    max-width: 800px;
    margin: 0 auto;
    padding: 0.890rem 1rem;
    text-align: left;
}

.content-page h1 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    color: var(--color-text-primary);
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 0.5rem;
}

.content-body,
.section-description {
    line-height: 1.8;
    color: var(--color-text-secondary);
    text-align: left;
}

.content-body h2 {
    font-size: 1.8rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--color-text-primary);
    text-align: left;
}

.content-body h3 {
    font-size: 1.5rem;
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
    text-align: left;
}

.content-body p,
.content-body ul,
.content-body ol {
    margin-bottom: 1rem;
    text-align: left;
}

.content-body code {
    background-color: var(--color-code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
    color: var(--color-code-text);
}

.content-body pre {
    background-color: black;
    padding: 1rem;
    border-radius: 4px;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.content-body pre code {
    background-color: transparent;
    padding: 0;
    color: #f8f8f2; /* Light text color for readability */
}

/* Section List Styles */
.section-list h1 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    color: var(--color-text-primary);
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 0.5rem;
}

.section-items {
    list-style-type: none;
    padding: 0;
}

.section-items li {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}

.section-items li a {
    font-size: 1.4rem;
    color: var(--color-accent);
    text-decoration: none;
    transition: color 0.3s ease;
}

.section-items li a:hover {
    color: var(--color-text-primary);
}

.section-items li p {
    margin-top: 0.5rem;
    color: var(--color-text-secondary);
}

/* Home Page Styles */
.home-page {
    max-width: 800px;
    margin: 0 auto 0 0;
    padding: 2rem 1rem;
    text-align: left;
}

.home-page h1 {
    font-size: 3rem;
    margin-bottom: 1.5rem;
    color: var(--color-text-primary);
}

.home-content {
    margin-bottom: 2rem;
    line-height: 1.8;
    color: var(--color-text-secondary);
    text-align: left;
}

.quick-links {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
}

.quick-link {
    flex-basis: calc(33% - 1rem);
    min-width: 200px;
    padding: 1rem;
    background-color: var(--color-bg-secondary);
    border-radius: 8px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.quick-link:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.quick-link a {
    text-decoration: none;
    color: var(--color-accent);
}

.quick-link h3 {
    margin-bottom: 0.5rem;
    color: var(--color-text-primary);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .page-container {
        grid-template-columns: 1fr;
    }

    .sidebar, .right-nav {
        display: none;
    }

    .top-bar {
        flex-wrap: wrap;
    }
}

/* Flatten table of contents navigation */
#TableOfContents ul ul {
    display: none;
}
#TableOfContents a.active {
    font-weight: bold;
    color: var(--primary-color, #007bff);
    text-decoration: underline;
}
/* Preload transition to prevent initial flicker */
.preload * {
    transition: none !important;
}

/* Minimal Line Numbers Removal */
pre, code {
    counter-reset: none !important;
}

.line-numbers-rows {
    display: none !important;
    width: 0 !important;
}

pre code[class*="language-"],
code[class*="language-"] {
    padding-left: 0 !important;
}

/* Preserve syntax highlighting tokens */
.token {
    display: inline !important;
    background-color: transparent !important;
}
.section-chapter {
    color: var(--color-accent);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: .0625em;
    text-transform: uppercase;
}

body:not(.dark-mode) article {
    box-shadow: none;
}

input:not([type="checkbox"], [type="radio"]), select, textarea {
    margin-bottom:  0;
  }

/* Sidebar Navigation Link Styles */
.sidebar-navigation a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.3s ease;
}

.sidebar-navigation a:hover,
.sidebar-navigation a.active {
    background-color: var(--pico-background-color-secondary);
    color: var(--color-accent);
    border-radius: 0.7rem;
    transition: all 0.3s ease;
}

.sidebar-navigation a.active {
    font-weight: 600;
}

[data-theme="dark"] {
    color: var(--pico-color-dark);
    background-color: var(--pico-background-color-dark);
}

[data-theme="dark"] *:not(pre):not(code) {
    color: inherit;
    background-color: transparent;
}

[data-theme="dark"] .sidebar-navigation a {
    color: var(--color-text-secondary);
}

[data-theme="dark"] .sidebar-navigation a:hover,
[data-theme="dark"] .sidebar-navigation a.active {
    background-color: rgba(8, 125, 115, 0.2); /* Light green background with opacity */
    color: var(--color-accent); /* Dark green font color */
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}
[data-theme="light"] .sidebar-navigation a:hover,
[data-theme="light"] .sidebar-navigation a.active {
    background-color: rgba(8, 125, 115, 0.2); /* Light green background with opacity */
    color: var(--color-accent-dark); /* Dark green font color */
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

[data-theme="dark"] .right-nav a {
    color: var(--color-text-secondary);
}
[data-theme="dark"] .section-chapter {
    color: var(--color-accent);
}
.section-chapter{
    margin-bottom: 0.3rem;
}
.content-page h1.section-chapter-title {
    margin-top: 0.3rem;
    border: 0;
}