/* ----------------------------------------------------
   DESIGN SYSTEM & CUSTOM STYLING (BIRIBOL.COM THEME)
   ---------------------------------------------------- */

:root {
    /* Color Tokens - Dark Mode (Default) */
    --bg-main: #0a192f;
    --bg-surface: #112240;
    --bg-surface-hover: #1d3557;
    --border-color: rgba(255, 255, 255, 0.08);
    
    --primary-color: #0066cc;
    --primary-dark: #004499;
    --primary-light: #4d99e6;
    --secondary-color: #00d2ff;
    --accent-color: #ffaa00;
    --text-main: #ccd6f6;
    --text-muted: #8892b0;
    --white: #ffffff;
    --shadow: 0 10px 30px -15px rgba(2, 12, 27, 0.7);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.1);
    
    /* Typography */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    
    /* Global values */
    --transition-speed: 0.25s;
    --transition-curve: cubic-bezier(0.25, 0.8, 0.25, 1);
    --sidebar-width: 320px;
    --header-height: 80px;
}

/* Light Theme Variables */
body.light-theme {
    --bg-main: #f8f9fa;
    --bg-surface: #ffffff;
    --bg-surface-hover: #e9ecef;
    --border-color: rgba(0, 0, 0, 0.08);
    
    --primary-color: #0055b3;
    --primary-dark: #003366;
    --primary-light: #3399ff;
    --secondary-color: #00a8cc;
    --text-main: #2d3748;
    --text-muted: #718096;
    --shadow: 0 10px 30px -15px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.08);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.7;
    transition: background-color var(--transition-speed) var(--transition-curve),
                color var(--transition-speed) var(--transition-curve);
    overflow-x: hidden;
}

/* Fonts Import */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800;900&display=swap');

/* Typography Utilities */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--white);
    line-height: 1.25;
    margin-bottom: 0.5em;
    transition: color var(--transition-speed) var(--transition-curve);
}

body.light-theme h1, 
body.light-theme h2, 
body.light-theme h3, 
body.light-theme h4, 
body.light-theme h5, 
body.light-theme h6 {
    color: #1a202c;
}

p {
    margin-bottom: 1rem;
}

a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: color var(--transition-speed) var(--transition-curve);
}

a:hover {
    color: var(--primary-light);
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-surface-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* ----------------------------------------------------
   HEADER & NAVBAR
   ---------------------------------------------------- */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height);
    background: rgba(10, 25, 47, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    transition: background var(--transition-speed) var(--transition-curve),
                border-color var(--transition-speed) var(--transition-curve);
}

body.light-theme .navbar {
    background: rgba(255, 255, 255, 0.85);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-text {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 900;
    color: var(--white);
    letter-spacing: -0.05em;
}

body.light-theme .logo-text {
    color: #1a202c;
}

.logo-dot {
    color: var(--secondary-color);
}

.logo-subtitle {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent-color);
    font-weight: 700;
    border-left: 2px solid var(--border-color);
    padding-left: 10px;
    margin-left: 5px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

/* Theme Switcher Button */
.theme-toggle {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.3rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.theme-toggle:hover {
    background-color: var(--bg-surface);
    color: var(--secondary-color);
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--white);
    font-size: 1.5rem;
    cursor: pointer;
}

body.light-theme .menu-toggle {
    color: #1a202c;
}

/* ----------------------------------------------------
   MAIN LAYOUT CONTAINER
   ---------------------------------------------------- */
.app-container {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
    position: relative;
}

/* ----------------------------------------------------
   SIDEBAR (TABLE OF CONTENTS)
   ---------------------------------------------------- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    overflow-y: auto;
    z-index: 90;
    padding: 1.5rem 1rem;
    transition: transform var(--transition-speed) var(--transition-curve),
                background-color var(--transition-speed) var(--transition-curve),
                border-color var(--transition-speed) var(--transition-curve);
}

/* Search bar in Sidebar */
.search-container {
    position: relative;
    margin-bottom: 1.5rem;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 40px;
    border-radius: 30px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--transition-speed) var(--transition-curve),
                box-shadow var(--transition-speed) var(--transition-curve);
}

.search-input:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(0, 210, 255, 0.15);
}

.search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* Sidebar Navigation List */
.sidebar-menu {
    list-style: none;
}

.sidebar-item {
    margin-bottom: 4px;
    transition: max-height var(--transition-speed) ease, opacity var(--transition-speed) ease;
}

/* Hidden state for search filtering */
.sidebar-item.hidden {
    display: none;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.95rem;
    transition: all var(--transition-speed) var(--transition-curve);
}

.sidebar-link:hover {
    color: var(--white);
    background-color: rgba(255, 255, 255, 0.03);
}

body.light-theme .sidebar-link:hover {
    color: #1a202c;
    background-color: rgba(0, 0, 0, 0.03);
}

.sidebar-link.active {
    color: var(--white);
    background-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.2);
}

body.light-theme .sidebar-link.active {
    color: var(--white);
}

.sidebar-sub-menu {
    list-style: none;
    padding-left: 1.2rem;
    margin-top: 2px;
    border-left: 1px solid var(--border-color);
    transition: max-height var(--transition-speed) ease;
}

.sidebar-sub-menu.collapsed {
    display: none;
}

.sidebar-sub-link-item.hidden {
    display: none;
}

.sidebar-sub-link {
    display: block;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
    border-radius: 6px;
    transition: all var(--transition-speed);
}

.sidebar-sub-link:hover {
    color: var(--secondary-color);
}

.sidebar-sub-link.active {
    color: var(--secondary-color);
    font-weight: 600;
}

/* Highlight matching search text inside sidebar links */
mark.sidebar-highlight {
    background-color: rgba(255, 170, 0, 0.4);
    color: var(--white);
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: bold;
}

body.light-theme mark.sidebar-highlight {
    color: #000;
    background-color: rgba(255, 170, 0, 0.55);
}

/* Match indicator count badge */
.sidebar-badge {
    margin-left: auto;
    font-size: 0.72rem;
    background-color: var(--bg-surface-hover);
    color: var(--accent-color);
    border: 1px solid var(--border-color);
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 700;
}

/* ----------------------------------------------------
   READER CONTAINER (MAIN CONTENT)
   ---------------------------------------------------- */
.main-content {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    padding: 2rem 3rem;
    max-width: 1200px;
    position: relative;
    transition: margin-left var(--transition-speed) var(--transition-curve),
                padding var(--transition-speed) var(--transition-curve);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ----------------------------------------------------
   E-BOOK READER INTERFACE
   ---------------------------------------------------- */
.reader-panel {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: calc(100vh - var(--header-height) - 4rem);
    position: relative;
}

/* Reader Top Controls */
.reader-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    padding: 10px 20px;
    gap: 1.5rem;
}

.control-btn {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.25rem;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background-color: var(--bg-surface-hover);
    color: var(--secondary-color);
}

.control-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-slider-container {
    flex-grow: 1;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.page-number-display {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--white);
    min-width: 110px;
    text-align: center;
}

body.light-theme .page-number-display {
    color: #1a202c;
}

.page-slider {
    flex-grow: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-surface);
    outline: none;
    cursor: pointer;
}

.page-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--secondary-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    transition: transform 0.1s ease;
}

.page-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Pane Display Layout */
.reading-pane {
    flex-grow: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 500px;
}

.pane-content {
    display: flex;
    justify-content: center;
    width: 100%;
    height: 100%;
    animation: fadeIn var(--transition-speed) ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ----------------------------------------------------
   BOOK VISUAL PRESENTATION
   ---------------------------------------------------- */
.book-page-wrapper {
    position: relative;
    max-width: 580px;
    width: 100%;
    background-color: #fff;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.4), 
                inset 10px 0 20px rgba(0,0,0,0.05);
    border-radius: 4px 12px 12px 4px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Spine effect for a booklet feel */
.book-spine {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 18px;
    background: linear-gradient(to right, 
        rgba(0, 0, 0, 0.15) 0%, 
        rgba(0, 0, 0, 0.05) 30%, 
        rgba(255, 255, 255, 0.02) 60%, 
        rgba(0, 0, 0, 0.02) 100%);
    z-index: 10;
    border-right: 1px solid rgba(0,0,0,0.05);
}

.book-page-img {
    width: 100%;
    height: auto;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    object-fit: contain;
}

/* ----------------------------------------------------
   FLOATING ELEMENTS (BACK TO TOP)
   ---------------------------------------------------- */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all var(--transition-speed) var(--transition-curve);
    z-index: 99;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background-color: var(--secondary-color);
    transform: scale(1.1);
}

/* ----------------------------------------------------
   RESPONSIVE DESIGN (TABLETS & MOBILE)
   ---------------------------------------------------- */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }
    
    .main-content {
        margin-left: 0;
        padding: 1.5rem 1rem;
    }
    
    .menu-toggle {
        display: block;
    }
}

@media (max-width: 768px) {
    .navbar {
        padding: 0 1rem;
    }
    
    .logo-subtitle {
        display: none;
    }
    
    .reader-panel {
        padding: 1rem;
    }
    
    .reader-controls {
        padding: 8px 12px;
        gap: 0.8rem;
    }
    
    .page-number-display {
        font-size: 0.9rem;
        min-width: 80px;
    }
}
