/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

html {
    /* font-size: 16px; Removed to let browser default control or use smaller if needed */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px; /* Reduced from 15px */
    line-height: 1.6;
    color: #333;
    background-color: #f6f6f6;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

a {
    color: #333;
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: #64854c;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Header */
header {
    background-color: #96b97d;
    color: white;
    padding: 10px 0;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
    width: 100%;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Main Navigation */
.main-nav {
    display: flex;
    align-items: center;
}

.category-menu {
    display: flex;
    list-style: none;
    gap: 5px;
    margin: 0;
    padding: 0;
}

.category-menu li {
    position: relative;
}

.category-menu a {
    display: block;
    padding: 8px 15px;
    color: white;
    font-size: 0.95rem;
    border-radius: 4px;
    transition: all 0.2s;
    text-decoration: none;
}

.category-menu a:hover {
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
}

/* Dropdown Menu */
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 180px;
    background-color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    list-style: none;
    margin: 2px 0 0;
    padding: 0;
    display: none;
    z-index: 1000;
}

.dropdown:hover .dropdown-menu {
    display: block;
}

.dropdown-menu li {
    border-bottom: 1px solid #f0f0f0;
}

.dropdown-menu li:last-child {
    border-bottom: none;
}

.dropdown-menu a {
    display: block;
    padding: 10px 15px;
    color: #333;
    font-size: 0.9rem;
    background: none;
    border-radius: 0;
    text-decoration: none;
    transition: all 0.2s;
}

.dropdown-menu a:hover {
    background-color: #f8f9fa;
    color: #64854c;
    padding-left: 20px;
}

.dropdown-toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}

.logo {
    font-size: 1.25rem; /* 20px */
    font-weight: bold;
    color: white;
    white-space: nowrap;
}

.logo a:hover {
    color: #e8f5e9 !important;
}

.mobile-menu-toggle {
    display: none; /* Hidden on desktop */
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
}

.search-box {
    flex-grow: 1;
    max-width: 300px;
}

.search-box input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 4px;
    border: none;
    font-size: 0.9rem;
    outline: none;
}

.search-box input:focus {
    box-shadow: 0 0 0 2px rgba(255,255,255,0.5);
}

/* Layout */
.main-wrapper {
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    min-height: 80vh;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-radius: 4px;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: #f8f9fa;
    border-right: 1px solid #e9ecef;
    flex-shrink: 0;
    height: fit-content;
    position: sticky;
    top: 80px; /* Header height + some margin */
    overflow-y: auto;
    max-height: calc(100vh - 100px); /* Adjust based on header height */
    transition: width 0.3s ease, transform 0.3s ease;
    z-index: 900;
    overflow-x: hidden;
}

.sidebar.collapsed {
    width: 40px;
    flex-shrink: 0;
    border-right: none;
}

.sidebar.collapsed .sidebar-header h2 {
    display: none;
}

.sidebar.collapsed .sidebar-nav {
    display: none;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: #f1f3f5;
    border-bottom: 1px solid #e9ecef;
    margin: 0;
}

.sidebar h2 {
    padding: 0;
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: #495057;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 0.8rem;
    cursor: pointer;
    color: #6c757d;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: #495057;
}

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

.sidebar-toggle-icon {
    transition: transform 0.3s ease;
}

.sidebar-nav {
    list-style: none;
    padding: 10px 0;
    margin: 0;
}

.sidebar ul {
    list-style: none;
    padding: 10px;
}

.sidebar li a {
    display: block;
    padding: 10px 20px;
    color: #495057;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
}

.sidebar li a:hover, .sidebar li a.active {
    background-color: #fff;
    color: #64854c;
    border-left-color: #64854c;
    font-weight: 500;
}

/* Content */
.content {
    flex-grow: 1;
    padding: 30px 40px;
    overflow-x: hidden; /* Prevent horizontal scroll */
    min-width: 0; /* Flexbox trick for text-overflow */
}

/* Markdown Content Styles */
.markdown-body {
    line-height: 1.7;
}

.markdown-body h1 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: #212529;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    line-height: 1.3;
}

.markdown-body h2 {
    font-size: 1.2rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    border-left: 5px solid #96b97d;
    padding-left: 15px;
    background-color: #f8f9fa;
    padding-top: 5px;
    padding-bottom: 5px;
    color: #343a40;
    
    /* Collapsible styles */
    cursor: pointer;
    padding-right: 30px; /* Space for arrow */
    user-select: none; /* Prevent text selection on double click */
    
    /* Sticky styles */
    position: sticky;
    top: 60px; /* Header height + some padding */
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.markdown-body h2::after {
    content: '▼'; /* Down arrow */
    font-size: 0.8em;
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.3s;
    color: #6c757d;
}

.markdown-body h2.collapsed::after {
    transform: translateY(-50%) rotate(-90deg); /* Rotate to point left */
}

/* Helper class for JS to hide content */
.hidden-content {
    display: none !important;
}

.markdown-body h3 {
    font-size: 1.1rem;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    color: #343a40;
}

.markdown-body h4 {
    font-size: 1rem;
    margin-top: 1.25rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.markdown-body p {
    margin-bottom: 1.25rem;
    font-size: 1rem;
}

.markdown-body pre {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 10px 15px;
    overflow-x: auto;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

.markdown-body code {
    font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
    font-size: 0.9em;
    background-color: #fff3f3;
    color: #c92a2a;
    padding: 2px 5px;
    border-radius: 3px;
    word-break: break-word; /* Prevent long codes from breaking layout */
}

.markdown-body pre code {
    background-color: transparent;
    color: inherit;
    padding: 0 !important;
    border: none;
    word-break: normal;
}

.markdown-body blockquote {
    padding: 10px 20px;
    margin: 0 0 1.25rem;
    border-left: 4px solid #ced4da;
    background-color: #f8f9fa;
    color: #6c757d;
    font-style: italic;
}

.markdown-body ul,
.markdown-body ol {
    margin-bottom: 1.25rem;
    padding-left: 2rem;
}

.markdown-body li {
    margin-bottom: 0.5rem;
}

/* Responsive Tables */
.markdown-body table {
    display: block;
    width: 100%;
    overflow-x: auto;
    margin-bottom: 1.5rem;
    border-collapse: collapse;
}

.markdown-body table th,
.markdown-body table td {
    padding: 10px;
    border: 1px solid #dee2e6;
    min-width: 100px; /* Ensure columns don't collapse too much */
}

.markdown-body table th {
    background-color: #e9ecef;
    font-weight: 600;
    text-align: left;
}

.markdown-body table tr:nth-child(even) {
    background-color: #f8f9fa;
}

.markdown-body hr {
    border: 0;
    border-top: 1px solid #dee2e6;
    margin: 2rem 0;
}

/* Article Navigation */
.article-navigation {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid #dee2e6;
}

.nav-prev, .nav-next {
    flex: 1;
    min-width: 250px; /* Stack on small screens */
    padding: 15px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
}

.nav-prev:hover, .nav-next:hover {
    border-color: #96b97d;
    background-color: #f8f9fa;
}

.nav-label {
    font-size: 0.85rem;
    color: #868e96;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-title {
    font-weight: 600;
    color: #96b97d;
}

.nav-prev.empty, .nav-next.empty {
    border: none;
    background: none;
    pointer-events: none;
}

/* Footer */
.site-footer {
    background-color: #343a40;
    color: #adb5bd;
    padding: 30px 0;
    margin-top: 40px;
    text-align: center;
    font-size: 0.9rem;
}

.site-footer a {
    color: #ced4da;
    text-decoration: underline;
}

.site-footer a:hover {
    color: white;
}

/* Back to Top */
.back-to-top {
    display: none;
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1000;
    width: 45px;
    height: 45px;
    line-height: 45px;
    text-align: center;
    background-color: #96b97d;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    opacity: 0.8;
    transition: all 0.3s;
}

.back-to-top:hover {
    opacity: 1;
    background-color: #64854c;
    transform: translateY(-2px);
}

/* MEDIA QUERIES - Mobile Optimization */
@media (max-width: 992px) {
    .container {
        padding: 0 20px;
    }
    
    .sidebar {
        width: 220px;
    }
    
    .content {
        padding: 20px;
    }
}

@media (max-width: 768px) {
    /* Header */
    .mobile-menu-toggle {
        display: block;
    }

    .header-content {
        justify-content: space-between;
        align-items: flex-start;
    }

    /* Main Navigation on Mobile */
    .main-nav {
        display: none;
        order: 3;
        width: 100%;
        margin-top: 10px;
        background-color: rgba(255, 255, 255, 0.1);
        border-radius: 4px;
        padding: 5px;
    }

    .header-content.active .main-nav {
        display: block;
    }

    .category-menu {
        flex-direction: column;
        gap: 0;
        width: 100%;
    }

    .category-menu li {
        width: 100%;
    }

    .category-menu a {
        padding: 10px 12px;
        font-size: 0.9rem;
        border-radius: 4px;
    }

    /* Dropdown Menu on Mobile */
    .dropdown-menu {
        position: static;
        min-width: 100%;
        box-shadow: none;
        border-radius: 4px;
        margin: 5px 0 0 15px;
        background-color: rgba(255, 255, 255, 0.1);
    }

    .dropdown-menu a {
        color: white;
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .dropdown-menu a:hover {
        background-color: rgba(255, 255, 255, 0.2);
        color: white;
        padding-left: 15px;
    }

    .logo {
        font-size: 1.1rem;
    }

    .search-box {
        order: 4;
        width: 100%;
        max-width: 100%;
        margin-top: 10px;
    }

    /* Layout */
    .main-wrapper {
        border-radius: 0;
        box-shadow: none;
    }

    /* Off-canvas Sidebar */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        background: white;
        border-right: 1px solid #eee;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        transform: translateX(-100%); /* Hide by default */
        z-index: 1001;
        padding-top: 60px; /* Space for close button if needed, or just top padding */
    }

    .sidebar.active {
        transform: translateX(0); /* Show when active */
    }

    /* Overlay for sidebar (optional, managed by clicking outside logic in JS) */
    
    .sidebar h2 {
        padding-top: 20px;
    }

    /* Content */
    .content {
        padding: 15px;
    }

    .markdown-body h1 {
        font-size: 1.75rem;
    }

    .markdown-body h2 {
        font-size: 1.35rem;
    }

    .markdown-body pre {
        padding: 10px;
        font-size: 0.85rem;
    }

    /* Navigation */
    .article-navigation {
        flex-direction: column;
    }

    .nav-prev, .nav-next {
        width: 100%;
    }
    
    /* Touch Targets */
    .sidebar li a {
        padding: 12px 20px; /* Larger tap area */
        font-size: 1rem;
    }

    .back-to-top {
        bottom: 20px;
        right: 20px;
        width: 40px;
        height: 40px;
        line-height: 40px;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 1rem;
    }
    
    .header-content {
        padding: 0 5px;
    }
    
    .content {
        padding: 10px;
    }
}
