/* --- Global Variables & Manning Theme --- */
:root {
    /* Colors */
    --bg-primary: #ffffff;
    --bg-sidebar: #f8f9fc;
    --bg-topbar: #ffffff;
    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #868e96;
    --border-color: #e9ecef;
    --accent-color: #ff6600; /* Signature Manning Orange */

    /* Code Blocks (Light Theme default) */
    --code-bg: #f8f9fa;
    --code-text: #212529;
    --code-border: #dee2e6;

    /* Dimensions & Typography */
    --sidebar-width: 300px;
    --font-ui:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    --font-reading: "Georgia", "Merriweather", serif;
}

/* Link Colors */
.reader-view a {
    color: #023047;
}

/* Buttons */
.btn-primary {
    padding: 8px 16px;
    background-color: #facc15;
    border-radius: 9999px;
    font-size: 14px;
    font-weight: 600;
    color: #000000;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -2px rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s;
    text-decoration: none;
    border: none;
    cursor: pointer;
}

.btn-primary:hover {
    background-color: #eab308;
}

/* Dark Mode Palette */
[data-theme="dark"] {
    --bg-primary: #121212;
    --bg-sidebar: #1a1a1a;
    --bg-topbar: #121212;
    --text-primary: #e9ecef;
    --text-secondary: #ced4da;
    --text-muted: #6c757d;
    --border-color: #2b2b2b;
    --accent-color: #ff8533;

    --code-bg: #1e1e1e;
    --code-text: #e9ecef;
    --code-border: #333333;
}

/* --- Base Resets --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition:
        background-color 0.2s ease,
        color 0.2s ease;
}

/* --- Top Navigation Bar --- */
.top-bar {
    background-color: var(--bg-topbar);
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.top-left,
.top-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.book-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.search-container input {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    color: var(--text-primary);
    width: 320px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.search-container input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(255, 102, 0, 0.1);
    background: var(--bg-primary);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--bg-sidebar);
    color: var(--accent-color);
}

/* --- App Layout Structure --- */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: margin 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

.right-sidebar {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 20px;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

/* --- Left Sidebar: Table of Contents --- */
.toc-list {
    padding: 12px 0;
}

details > summary {
    list-style: none;
}
details > summary::-webkit-details-marker {
    display: none;
}

.toc-chapter {
    padding: 12px 20px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.toc-chapter:hover {
    color: var(--accent-color);
}

.toc-item {
    display: block;
    padding: 8px 20px 8px 36px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    line-height: 1.4;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
}

.toc-item:hover {
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.02);
}

.toc-item.active {
    color: var(--accent-color);
    font-weight: 600;
    border-left-color: var(--accent-color);
    background-color: rgba(255, 102, 0, 0.04);
}

/* --- Center Content: Book Typography --- */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 60px 40px;
    display: flex;
    justify-content: center;
    scroll-behavior: smooth;
}

.reader-view {
    max-width: 760px; /* Optimal reading width for books */
    width: 100%;
}

.reader-view h1,
.reader-view h2,
.reader-view h3 {
    font-family: var(--font-ui); /* Headers remain clean sans-serif */
    color: var(--text-primary);
    margin-top: 2.5em;
    margin-bottom: 1em;
    font-weight: 700;
}

.reader-view h1 {
    font-size: 2.5rem;
    letter-spacing: -0.02em;
    margin-top: 0;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.reader-view h2 {
    font-size: 1.75rem;
}
.reader-view h3 {
    font-size: 1.35rem;
}

.section-badge {
    display: inline-block;
    color: var(--accent-color);
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.reader-view p {
    font-family: var(--font-reading); /* Serif font for long-form reading */
    font-size: 1.15rem;
    line-height: 1.8;
    color: var(--text-secondary);
    margin-bottom: 1.5em;
}

.reader-view strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Lists in content */
.reader-view ul,
.reader-view ol {
    font-family: var(--font-reading);
    font-size: 1.15rem;
    line-height: 1.8;
    color: var(--text-secondary);
    margin-bottom: 1.5em;
    padding-left: 2em;
}

.reader-view li {
    margin-bottom: 0.5em;
}

/* --- Technical Content (Code & Images) --- */
.reader-view pre {
    background-color: var(--code-bg);
    color: var(--code-text);
    border: 1px solid var(--code-border);
    border-radius: 6px;
    padding: 20px;
    overflow-x: auto;
    font-family: "Fira Code", "Consolas", "Monaco", monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    margin: 2em 0;
}

.reader-view code {
    font-family: "Fira Code", "Consolas", "Monaco", monospace;
    background-color: var(--bg-sidebar);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--accent-color);
}

.reader-view pre code {
    background-color: transparent;
    padding: 0;
    color: inherit;
}

.reader-view img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin: 2.5em auto;
    display: block;
}

/* --- Right Side Tools --- */
.tools-content {
    padding: 20px;
}

.tool-section {
    margin-bottom: 30px;
}

.tool-section h3 {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.empty-state {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
}

/* --- Toggle / Utility States --- */
.sidebar.collapsed-left {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar.collapsed-right {
    margin-right: calc(-1 * var(--sidebar-width));
    display: none;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 1024px) {
    .right-sidebar {
        display: none;
    }
}

@media (max-width: 768px) {
    .sidebar.left-sidebar {
        position: absolute;
        height: 100%;
        z-index: 50;
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.05);
    }
    .sidebar.left-sidebar.collapsed-left {
        transform: translateX(-100%);
        margin-left: 0;
    }
    .search-container {
        display: none; /* Hide search on mobile for cleaner top bar */
    }
    .main-content {
        padding: 30px 20px;
    }
}
