/* ===============================================
   CppCore Documentation - Professional Styles
   =============================================== */

/* CSS Variables for Theming */
:root {
    /* Light Theme Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #1a1a1a;
    --text-secondary: #4a5568;
    --text-tertiary: #718096;
    --border-color: #e2e8f0;
    --accent-primary: #2563eb;
    --accent-secondary: #7c3aed;
    --accent-hover: #1d4ed8;
    --code-bg: #f7fafc;
    --code-border: #cbd5e0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --sidebar-bg: #fafbfc;
    --nav-bg: #ffffff;
    
    /* Typography */
    --font-display: 'Fraunces', serif;
    --font-mono: 'JetBrains Mono', monospace;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* Spacing */
    --nav-height: 64px;
    --sidebar-width: 280px;
    --toc-width: 240px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 350ms ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2d2d2d;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --border-color: #27272a;
    --accent-primary: #60a5fa;
    --accent-secondary: #a78bfa;
    --accent-hover: #93c5fd;
    --code-bg: #18181b;
    --code-border: #3f3f46;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --sidebar-bg: #121212;
    --nav-bg: #0a0a0a;
}

/* ===============================================
   Base Styles
   =============================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color var(--transition-base), color var(--transition-base);
    overflow-x: hidden;
}

/* ===============================================
   Top Navigation
   =============================================== */

.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background-color: var(--nav-bg);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-sm);
}

.nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 2rem;
    max-width: 100%;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex: 1;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    flex-direction: column;
    gap: 4px;
}

.nav-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background-color: var(--text-primary);
    transition: var(--transition-fast);
}

.nav-menu {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-item {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.nav-item:hover {
    color: var(--text-primary);
    background-color: var(--bg-secondary);
}

.nav-item.active {
    color: var(--accent-primary);
    background-color: var(--bg-secondary);
}

.nav-center {
    flex: 1;
    max-width: 500px;
    position: relative;
}

.search-container {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-results {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 1001;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background-color: var(--bg-secondary);
}

.search-result-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.search-result-context {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.search-highlight {
    background-color: rgba(37, 99, 235, 0.2);
    padding: 0 2px;
    border-radius: 2px;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex: 1;
    justify-content: flex-end;
}

.brand {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    background-color: var(--bg-secondary);
    border-color: var(--accent-primary);
}

.theme-toggle .sun-icon,
.theme-toggle .moon-icon {
    width: 20px;
    height: 20px;
}

[data-theme="light"] .moon-icon,
[data-theme="dark"] .sun-icon {
    display: none;
}

/* ===============================================
   Main Content
   =============================================== */

.main-content {
    margin-top: var(--nav-height);
    min-height: calc(100vh - var(--nav-height));
}

.view {
    display: none;
}

.view.active {
    display: block;
}

/* ===============================================
   Homepage
   =============================================== */

.hero {
    padding: 5rem 2rem 3rem;
    text-align: center;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border-color);
}

.hero-title {
    font-family: var(--font-display);
    font-size: 3.5rem;
    font-weight: 900;
    margin-bottom: 1rem;
    letter-spacing: -1px;
    line-height: 1.2;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

.topics-grid {
    max-width: 1200px;
    margin: 0 auto;
    padding: 3rem 2rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
}

.topic-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.topic-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, var(--accent-primary), var(--accent-secondary));
    transform: translateX(-4px);
    transition: transform var(--transition-base);
}

.topic-card:hover::before {
    transform: translateX(0);
}

.topic-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}

.topic-card-category {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-primary);
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.topic-card-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.topic-card-description {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.topic-card-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

/* ===============================================
   Documentation View
   =============================================== */

#docView {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr var(--toc-width);
    gap: 0;
    min-height: calc(100vh - var(--nav-height));
}

/* Sidebar */
.sidebar {
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    position: sticky;
    top: var(--nav-height);
    height: calc(100vh - var(--nav-height));
    padding: 2rem 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.sidebar-header h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-secondary);
}

.sidebar-nav {
    padding: 0 1rem;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section-title {
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    padding: 0.5rem 0.5rem 0.25rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.nav-section-toggle {
    transition: transform var(--transition-fast);
}

.nav-section.collapsed .nav-section-toggle {
    transform: rotate(-90deg);
}

.nav-section-items {
    list-style: none;
    transition: max-height var(--transition-base);
    overflow: hidden;
}

.nav-section.collapsed .nav-section-items {
    max-height: 0;
}

.nav-item-link {
    display: block;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: 6px;
    transition: all var(--transition-fast);
    border-left: 2px solid transparent;
    margin-bottom: 0.25rem;
}

.nav-item-link:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
    border-left-color: var(--accent-primary);
}

.nav-item-link.active {
    color: var(--accent-primary);
    background-color: var(--bg-tertiary);
    border-left-color: var(--accent-primary);
    font-weight: 600;
}

.nav-item-link.nav-h3 {
    padding-left: 2rem;
    font-size: 0.85rem;
}

.nav-item-link.nav-h4 {
    padding-left: 3rem;
    font-size: 0.8rem;
}

/* Document Content */
.document {
    padding: 3rem 4rem;
    max-width: 900px;
    overflow-y: auto;
}

.document h1 {
    font-family: var(--font-display);
    font-size: 2.75rem;
    font-weight: 900;
    margin-bottom: 0.5rem;
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.document h2 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    margin-top: 3rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    letter-spacing: -0.25px;
}

.document h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.document h4 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.document p {
    margin-bottom: 1.25rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

.document a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition-fast);
}

.document a:hover {
    border-bottom-color: var(--accent-primary);
}

.document ul,
.document ol {
    margin-bottom: 1.25rem;
    padding-left: 2rem;
    color: var(--text-secondary);
}

.document li {
    margin-bottom: 0.5rem;
    line-height: 1.8;
}

.document code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background-color: var(--code-bg);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    border: 1px solid var(--code-border);
    color: var(--accent-secondary);
}

.document pre {
    background-color: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}

.document pre code {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.6;
}

.document blockquote {
    border-left: 4px solid var(--accent-primary);
    padding-left: 1.5rem;
    margin: 1.5rem 0;
    color: var(--text-secondary);
    font-style: italic;
}

.document table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.document table th,
.document table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border: 1px solid var(--border-color);
}

.document table th {
    background-color: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
}

.document table tr:hover {
    background-color: var(--bg-secondary);
}

.document hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2rem 0;
}

.document img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.5rem 0;
}

/* Table of Contents */
.toc {
    background-color: var(--bg-primary);
    border-left: 1px solid var(--border-color);
    padding: 2rem 1.5rem;
    position: sticky;
    top: var(--nav-height);
    height: calc(100vh - var(--nav-height));
    overflow-y: auto;
}

.toc-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.toc-header h3 {
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
}

.toc-nav {
    list-style: none;
}

.toc-item {
    margin-bottom: 0.5rem;
}

.toc-link {
    display: block;
    padding: 0.25rem 0;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    line-height: 1.4;
    transition: color var(--transition-fast);
    border-left: 2px solid transparent;
    padding-left: 0.75rem;
}

.toc-link:hover {
    color: var(--text-primary);
}

.toc-link.active {
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
    font-weight: 600;
}

.toc-link.toc-h3 {
    padding-left: 1.5rem;
    font-size: 0.8rem;
}

/* ===============================================
   Loading Indicator
   =============================================== */

.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    z-index: 2000;
}

.loading.active {
    display: block;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===============================================
   Responsive Design
   =============================================== */

@media (max-width: 1200px) {
    #docView {
        grid-template-columns: var(--sidebar-width) 1fr;
    }
    
    .toc {
        display: none;
    }
}

@media (max-width: 768px) {
    .nav-container {
        padding: 0 1rem;
    }
    
    .nav-toggle {
        display: flex;
    }
    
    .nav-menu {
        position: fixed;
        top: var(--nav-height);
        left: 0;
        right: 0;
        background-color: var(--nav-bg);
        border-bottom: 1px solid var(--border-color);
        flex-direction: column;
        padding: 1rem;
        gap: 0.5rem;
        transform: translateY(-100%);
        transition: transform var(--transition-base);
        box-shadow: var(--shadow-md);
        max-height: calc(100vh - var(--nav-height));
        overflow-y: auto;
    }
    
    .nav-menu.active {
        transform: translateY(0);
    }
    
    .nav-item {
        width: 100%;
        text-align: left;
    }
    
    .nav-center {
        max-width: none;
        flex: 2;
    }
    
    .brand {
        font-size: 1.25rem;
    }
    
    #docView {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        position: fixed;
        left: 0;
        top: var(--nav-height);
        transform: translateX(-100%);
        transition: transform var(--transition-base);
        z-index: 999;
        width: 280px;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-toggle {
        display: block;
    }
    
    .document {
        padding: 2rem 1.5rem;
    }
    
    .hero-title {
        font-size: 2.5rem;
    }
    
    .topics-grid {
        grid-template-columns: 1fr;
        padding: 2rem 1rem;
    }
}

/* ===============================================
   Scrollbar Styling
   =============================================== */

.sidebar::-webkit-scrollbar,
.toc::-webkit-scrollbar,
.search-results::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track,
.toc::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.sidebar::-webkit-scrollbar-thumb,
.toc::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.toc::-webkit-scrollbar-thumb:hover,
.search-results::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* ===============================================
   Utility Classes
   =============================================== */

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}