/* Base styles */
:root {
    --sidebar-width-lg: 16.66667%;  /* col-lg-2 */
    --sidebar-width-md: 25%;        /* col-md-3 */
    --content-max-width: 100%;      /* Allow content to fill available space */
    --header-height: 70px;
    --border-color: #dee2e6;
    --text-color: #333;
    --link-color: #007bff;
    --bg-light: #f8f9fa;
}

body {
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-color);
    background-color: #f8f9fa;
    padding: 2rem;
    margin: 0;
    min-height: 100vh;
}

/* Layout */
.container-fluid {
    min-height: 100%;
}

.row {
    min-height: 100%;
}

.page-wrapper {
    max-width: 1600px;
    margin: 0 auto;
    min-height: calc(100vh - 4rem);
    display: flex;
}

.card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for Firefox */
    margin: 0;
}

.card-body {
    flex: 1;
    min-height: 0; /* Important for Firefox */
}

/* Header */
.card-header {
    padding: 1.25rem 1.5rem;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
    line-height: 1.2;
}

/* Content area */
.content-wrapper {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

#content {
    padding: 1.5rem 0;
}

/* Typography */
#content h2 {
    font-size: 1.5rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    scroll-margin-top: 1rem;
}

#content h2:first-child {
    margin-top: 0;
}

#content h3 {
    font-size: 1.2rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    scroll-margin-top: 1rem;
}

#content h4 {
    font-size: 1.1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    scroll-margin-top: 1rem;
}

#content p {
    margin-bottom: 1.2rem;
}

#content ul, #content ol {
    margin-bottom: 1.2rem;
    padding-left: 1.5rem;
}

/* Sidebar */
.sidebar {
    position: sticky;
    top: 0;
    min-height: 100vh;
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
    padding-right: 0;
    background-color: transparent;
}

.sidebar-heading {
    font-size: 1.2rem;
    font-weight: 600;
    color: #495057;
}

/* Navigation */
.nav {
    --nav-indent: 1rem;
    --nav-spacing: 0.25rem;
    --nav-indicator-width: 3px;
}

.nav-link {
    position: relative;
    padding: var(--nav-spacing) var(--nav-indent);
    color: #666;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    margin-left: -2px;
}

.nav-link:hover {
    border-left-color: rgba(0, 123, 255, 0.3);
}

.nav-link.active {
    border-left-color: var(--link-color);
}

/* Main navigation */
.sidebar .nav-link {
    font-size: 1rem;
    padding: 0.4rem var(--nav-indent);
}

/* Table of contents */
#toc {
    margin: 0;
    padding: 0;
}

#toc .nav-link {
    font-size: 0.95rem;
    color: #666;
    padding: 0.35rem 1.5rem;
    border-left: 3px solid transparent;
    margin-left: -2px;
    line-height: 1.4;
    transition: border-color 0.2s ease;
}

#toc .nav-link:hover {
    border-left-color: rgba(0, 123, 255, 0.3);
}

#toc .nav-link.active {
    border-left-color: var(--link-color);
}

/* Remove Bootstrap nav defaults */
.nav-pills .nav-link {
    border-radius: 0;
}

.nav-item {
    margin: 0;
    padding: 0;
}

/* Hide empty nav items */
.nav-item:empty,
.nav-link:empty {
    display: none;
}

/* Main content area */
main {
    min-height: 100vh;
    overflow-y: visible;
}

/* Right Sidebar (TOC) */
.toc-sidebar {
    top: 1rem;
    height: calc(100vh - 2rem);
    overflow-y: auto;
    padding-left: 0;
    padding-right: 1rem;
}

.toc-sidebar .nav-link {
    padding: 0.35rem 1.5rem;
    color: #666;
    border-left: 3px solid transparent;
    margin-left: -2px;
    line-height: 1.4;
    transition: border-color 0.2s ease;
}

.toc-sidebar .nav-link:hover {
    border-left-color: rgba(0, 123, 255, 0.3);
}

.toc-sidebar .nav-link.active {
    border-left-color: var(--link-color);
}

/* Hide unvisited navigation links, show only visited ones */
.sidebar .nav-link:not(.active):not(.visited) {
    opacity: 0;
    pointer-events: none;
}

/* Remove any text styling differences */
.sidebar .nav-link,
.toc-sidebar .nav-link,
.sidebar .nav-link:hover,
.toc-sidebar .nav-link:hover,
.sidebar .nav-link.active,
.toc-sidebar .nav-link.active {
    color: #666;
    font-weight: normal;
    text-decoration: none;
}

/* Ensure visited and active links are visible */
.sidebar .nav-link.visited,
.sidebar .nav-link.active {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Hamburger menu button */
.navbar-toggler {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    display: none; /* Hidden by default, shown on mobile */
}

.navbar-toggler-icon {
    display: block;
    width: 24px;
    height: 2px;
    background-color: #333;
    position: relative;
    transition: all 0.3s ease;
}

.navbar-toggler-icon::before,
.navbar-toggler-icon::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 2px;
    background-color: #333;
    transition: all 0.3s ease;
}

.navbar-toggler-icon::before {
    top: -8px;
}

.navbar-toggler-icon::after {
    top: 8px;
}

/* Hamburger animation when active */
.navbar-toggler.active .navbar-toggler-icon {
    background-color: transparent;
}

.navbar-toggler.active .navbar-toggler-icon::before {
    transform: rotate(45deg);
    top: 0;
}

.navbar-toggler.active .navbar-toggler-icon::after {
    transform: rotate(-45deg);
    top: 0;
}

/* Mobile navigation overlay */
.mobile-nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    display: none;
}

/* Mobile navigation sidebar */
/* Note: mobile nav styles are applied only within the mobile media query */

/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        padding: 0.5rem;
    }

    .page-wrapper {
        min-height: calc(100vh - 1rem);
    }

    .card {
        min-height: 0;
    }
    
    /* Ensure hamburger menu is visible on mobile */
    .navbar-toggler {
        display: block !important;
    }

    .sidebar {
        position: static;
        height: auto;
        min-height: 0 !important;
        overflow: visible !important;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    /* Mobile nav: hide by default; show as dropdown when toggled */
    .sidebar {
        display: none !important;
        background: #fff;
        border-bottom: 1px solid var(--border-color);
        padding: 0.5rem 0;
    }
    .sidebar.show {
        display: block !important;
    }

    main {
        min-height: auto;
        overflow-y: visible;
        width: 100%;
    }

    .content-wrapper {
        padding: 0 0.75rem;
    }

    #content {
        font-size: 1rem;
    }

    #content h2 {
        font-size: 1.6rem;
        margin-top: 2rem;
    }

    #content h3 {
        font-size: 1.3rem;
    }

    #content h4 {
        font-size: 1.1rem;
    }

    .toc-sidebar {
        display: none;
    }
}

.card-header h5 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
}

#content img {
    width: 100%;
    height: auto;
    margin: 1.5rem 0;
    border-radius: 4px;
}

/* Blockquotes */
#content blockquote {
    margin: 1.5rem 0;
    padding: 0;
    border: none;
}

/* "me" class blockquotes - left-aligned speech bubble */
#content blockquote.me {
    font-weight: normal !important;
    margin: 1rem auto 1rem 0 !important;
    background: #dcf8c6;
    border-radius: 13px;
    padding: 0.75rem 1rem;
    width: fit-content;
    position: relative;
    display: block;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* "reader" class blockquotes - right-aligned speech bubble */
#content blockquote.reader {
    font-weight: normal !important;
    margin: 1rem 0 1rem auto !important;
    background: #f5f5f5;
    border: 1px solid #e5e5e5;
    border-radius: 13px;
    padding: 0.75rem 1rem;
    width: fit-content;
    position: relative;
    display: block;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Speech bubble arrow for .me (left side) */
#content blockquote.me::after {
    content: '';
    position: absolute;
    left: -8px;
    bottom: 12px;
    width: 0;
    height: 0;
    border-right: 8px solid #dcf8c6;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
}

/* Speech bubble arrow for .reader (right side) */
#content blockquote.reader::after {
    content: '';
    position: absolute;
    right: -8px;
    bottom: 12px;
    width: 0;
    height: 0;
    border-left: 8px solid #f5f5f5;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
}

/* Speech bubble arrow border for .reader */
#content blockquote.reader::before {
    content: '';
    position: absolute;
    right: -9px;
    bottom: 12px;
    width: 0;
    height: 0;
    border-left: 9px solid #e5e5e5;
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
}

/* Hide spans with no class or ID inside blockquotes */
#content blockquote span:not([class]):not([id]) {
    display: none !important;
}

/* Style the speaker prefixes */
#content blockquote span {
    font-weight: bold;
    color: #666;
}

/* Nested blockquotes (blockquotes inside blockquotes) - italicised with background */
#content blockquote blockquote {
    margin: 1rem 0;
    padding: 0;
    border: none;
    font-style: italic;
    color: #666;
    background: #f8f9fa;
    border: 1px solid #eee;
    border-radius: 6px;
}
/* Remove margins from paragraphs inside blockquotes */
#content blockquote p {
    margin: 0 !important;
}

/* Add space above lists inside blockquotes for balanced spacing */
#content blockquote ul,
#content blockquote ol {
    margin-top: 0.75rem !important;
    margin-bottom: 0.75rem !important;
}

/* Add space between consecutive paragraphs inside blockquotes */
#content blockquote p + p {
    margin-top: 0.75rem !important;
}

/* Update nested blockquote background to translucent black */
#content blockquote blockquote {
    background: rgba(0, 0, 0, 0.08) !important;
    border: none !important;
}

/* Add padding to nested blockquotes */
#content blockquote blockquote {
    padding: 0.75rem 1rem !important;
}

/* Codeblocks with translucent white background */
#content pre {
    background: rgba(255, 255, 255, 0.5) !important;
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
    border-radius: 6px !important;
    padding: 1rem !important;
}

#content code {
    background: rgba(255, 255, 255, 0.5) !important;
    padding: 0.25rem 0.5rem !important;
    border-radius: 3px !important;
}

#content img {
    margin: 0.5rem 0 !important;
}

/* External Link Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    width: 75%;
    max-width: 1200px;
    height: 80%;
    position: relative;
    overflow: hidden;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    font-size: 1.5rem;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 1);
    color: #333;
    transform: scale(1.1);
}

.modal-body {
    width: 100%;
    height: 100%;
    padding: 0;
    overflow: hidden;
}

#modal-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden;
}

/* Prevent body scroll when mobile nav is open */
body.nav-open {
    overflow: hidden;
}

/* Responsive modal */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 1rem;
    }
    
    .modal-content {
        width: 95%;
        height: 90%;
    }
    
    .modal-close {
        top: 8px;
        right: 8px;
        width: 30px;
        height: 30px;
        font-size: 1.3rem;
    }
}