/* ==========================================================================
   Trader's Master Library Styles — MyFinanceSheet
   ========================================================================== */

:root {
    --lib-bg: #07090e;
    --lib-card-bg: rgba(16, 20, 31, 0.75);
    --lib-card-border: rgba(255, 255, 255, 0.08);
    --lib-card-hover-border: rgba(245, 158, 11, 0.35);
    --lib-accent: #f59e0b;
    --lib-accent-glow: rgba(245, 158, 11, 0.25);
    --lib-text-primary: #f8fafc;
    --lib-text-secondary: #94a3b8;
    --lib-text-muted: #64748b;
    --lib-drawer-bg: rgba(10, 14, 23, 0.98);
}

body.library-page {
    background: var(--lib-bg);
    color: var(--lib-text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Scrolled Navbar Opaque Glassmorphism Fix */
.navbar.scrolled {
    background: rgba(8, 12, 20, 0.95) !important;
    backdrop-filter: blur(24px) !important;
    -webkit-backdrop-filter: blur(24px) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important;
}

/* Background Ambient Glows */
.lib-ambient-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(140px);
    pointer-events: none;
    z-index: 0;
    opacity: 0.18;
}
.lib-glow-1 {
    top: -100px;
    left: 15%;
    width: 550px;
    height: 550px;
    background: radial-gradient(circle, #f59e0b 0%, transparent 70%);
}
.lib-glow-2 {
    bottom: 50px;
    right: 10%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, #3b82f6 0%, transparent 70%);
}

/* Header & Container (Proper 120px offset to prevent navbar collision) */
.library-container {
    max-width: 1400px;
    margin: 110px auto 80px auto;
    padding: 0 24px;
    position: relative;
    z-index: 1;
}

/* Hero Section */
.lib-hero {
    text-align: center;
    padding: 24px 0 20px;
}

.lib-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #fbbf24;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    margin-bottom: 16px;
}

.lib-hero h1 {
    font-size: clamp(2rem, 4vw, 2.85rem);
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #ffffff 30%, #cbd5e1 70%, #f59e0b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.lib-hero p {
    color: var(--lib-text-secondary);
    font-size: 1.05rem;
    max-width: 720px;
    margin: 0 auto;
    line-height: 1.6;
}

/* Stats Ribbon */
.lib-stats-ribbon {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 28px;
    margin: 24px 0 32px;
    flex-wrap: wrap;
}

.lib-stat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--lib-card-border);
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 0.88rem;
    color: var(--lib-text-secondary);
}

.lib-stat-item strong {
    color: #f8fafc;
    font-weight: 700;
}

/* Control Bar (Search & Categories) */
.lib-controls {
    background: rgba(15, 20, 32, 0.6);
    border: 1px solid var(--lib-card-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 18px;
    padding: 16px 20px;
    margin-bottom: 36px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.lib-search-box {
    position: relative;
    width: 100%;
}

.lib-search-box svg {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--lib-text-muted);
}

.lib-search-input {
    width: 100%;
    background: rgba(8, 11, 18, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 16px 12px 46px;
    color: #fff;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s ease;
}

.lib-search-input:focus {
    border-color: var(--lib-accent);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

.lib-search-input::placeholder {
    color: var(--lib-text-muted);
}

/* Category Filter Pills */
.lib-categories-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
}

.lib-category-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--lib-text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.lib-category-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}

.lib-category-btn.active {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(245, 158, 11, 0.08));
    border-color: #f59e0b;
    color: #fbbf24;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.2);
}

.lib-cat-count {
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 7px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Books Grid */
.lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 22px;
}

/* Individual Book Card */
.lib-card {
    background: var(--lib-card-bg);
    border: 1px solid var(--lib-card-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 18px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.lib-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, rgba(245, 158, 11, 0.6), transparent);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.lib-card:hover {
    transform: translateY(-4px);
    border-color: var(--lib-card-hover-border);
    box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.5), 0 0 20px rgba(245, 158, 11, 0.1);
}

.lib-card:hover::before {
    opacity: 1;
}

.lib-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.lib-priority-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(245, 158, 11, 0.06));
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: #fbbf24;
    font-weight: 800;
    font-size: 0.88rem;
    flex-shrink: 0;
}

.lib-card-cat-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.76rem;
    color: var(--lib-text-secondary);
}

.lib-card-title {
    font-size: 1.18rem;
    font-weight: 700;
    line-height: 1.35;
    color: #ffffff;
    margin-bottom: 6px;
}

.lib-card-author {
    font-size: 0.88rem;
    color: #fbbf24;
    font-weight: 500;
    margin-bottom: 14px;
}

.lib-card-tagline {
    font-size: 0.88rem;
    color: var(--lib-text-secondary);
    line-height: 1.5;
    margin-bottom: 18px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.lib-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 20px;
}

.lib-tag-pill {
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    font-size: 0.72rem;
    color: var(--lib-text-muted);
}

.lib-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    margin-top: auto;
}

.lib-card-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.78rem;
    color: var(--lib-text-muted);
}

.lib-read-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 10px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #fbbf24;
    font-size: 0.84rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.lib-card:hover .lib-read-btn {
    background: #f59e0b;
    color: #000;
    border-color: #f59e0b;
}

/* ==========================================================================
   Slide-out Reader Drawer
   ========================================================================== */
.lib-drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 99999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.lib-drawer-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.lib-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(840px, 95vw);
    height: 100vh;
    background: var(--lib-drawer-bg);
    border-left: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: -15px 0 50px rgba(0, 0, 0, 0.7);
    z-index: 100000;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.lib-drawer.active {
    transform: translateX(0);
}

.lib-drawer-header {
    padding: 24px 28px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    background: rgba(15, 20, 32, 0.5);
}

.lib-drawer-header-left {
    flex: 1;
}

.lib-drawer-pills {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.lib-drawer-title {
    font-size: 1.45rem;
    font-weight: 800;
    line-height: 1.25;
    color: #ffffff;
    margin-bottom: 4px;
}

.lib-drawer-author {
    font-size: 0.95rem;
    color: #fbbf24;
    font-weight: 600;
}

.lib-drawer-close-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lib-drawer-close-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
    color: #ef4444;
}

/* Drawer Tabs */
.lib-drawer-tabs {
    display: flex;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0 28px;
    background: rgba(10, 14, 23, 0.6);
    gap: 8px;
    overflow-x: auto;
}

.lib-tab-btn {
    padding: 14px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--lib-text-secondary);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.lib-tab-btn:hover {
    color: #fff;
}

.lib-tab-btn.active {
    color: #fbbf24;
    border-bottom-color: #fbbf24;
}

/* Drawer Body */
.lib-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 28px;
    scrollbar-width: thin;
}

/* 60-Sec Essence Card */
.lib-essence-card {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(245, 158, 11, 0.02));
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: 14px;
    padding: 18px 20px;
    margin-bottom: 24px;
}

.lib-essence-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.84rem;
    font-weight: 700;
    color: #fbbf24;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.lib-essence-text {
    font-size: 0.96rem;
    line-height: 1.6;
    color: #f1f5f9;
}

/* Chapter Cards */
.lib-chapter-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 20px 22px;
    margin-bottom: 16px;
    transition: all 0.25s ease;
}

.lib-chapter-card:hover {
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
}

.lib-chapter-card.expanded {
    border-color: rgba(245, 158, 11, 0.35);
    background: rgba(18, 24, 38, 0.7);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.lib-chapter-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 1.02rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 12px;
}

.lib-chapter-head-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.lib-chapter-badge {
    background: rgba(255, 255, 255, 0.08);
    padding: 3px 9px;
    border-radius: 6px;
    font-size: 0.76rem;
    color: #fbbf24;
    font-weight: 700;
    flex-shrink: 0;
}

.lib-chapter-takeaways {
    list-style: none;
    padding: 0;
    margin: 0 0 14px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lib-chapter-takeaways li {
    position: relative;
    padding-left: 20px;
    font-size: 0.92rem;
    color: var(--lib-text-secondary);
    line-height: 1.55;
}

.lib-chapter-takeaways li::before {
    content: '›';
    position: absolute;
    left: 4px;
    top: -2px;
    color: #fbbf24;
    font-size: 1.2rem;
    font-weight: 700;
}

/* In-Depth Accordion Toggle Button */
.lib-chapter-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 4px;
}

.lib-chapter-toggle-btn:hover {
    background: rgba(245, 158, 11, 0.18);
    border-color: rgba(245, 158, 11, 0.4);
    transform: translateY(-1px);
}

.lib-toggle-icon {
    transition: transform 0.25s ease;
    font-size: 0.75rem;
}

.lib-chapter-card.expanded .lib-toggle-icon {
    transform: rotate(180deg);
}

/* In-Depth Content Panel */
.lib-chapter-deep-panel {
    display: none;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed rgba(245, 158, 11, 0.2);
    animation: fadeInDeep 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.lib-chapter-card.expanded .lib-chapter-deep-panel {
    display: block;
}

@keyframes fadeInDeep {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.lib-deep-section {
    margin-bottom: 16px;
}

.lib-deep-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #60a5fa;
    margin-bottom: 6px;
}

.lib-deep-text {
    font-size: 0.92rem;
    line-height: 1.65;
    color: #cbd5e1;
    margin: 0 0 10px 0;
}

.lib-deep-box {
    background: rgba(0, 0, 0, 0.35);
    border-left: 3px solid #3b82f6;
    border-radius: 0 8px 8px 0;
    padding: 10px 14px;
    font-size: 0.88rem;
    color: #e2e8f0;
    line-height: 1.5;
    margin: 8px 0;
}

.lib-deep-box.example {
    border-left-color: #10b981;
}

.lib-deep-box.checklist {
    border-left-color: #f59e0b;
}

/* Setups Breakdown */
.lib-setup-card {
    background: rgba(16, 24, 39, 0.6);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
}

.lib-setup-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.08rem;
    font-weight: 700;
    color: #60a5fa;
    margin-bottom: 14px;
}

.lib-setup-type {
    font-size: 0.76rem;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #93c5fd;
}

.lib-setup-criteria-list {
    margin-bottom: 16px;
}

.lib-setup-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 10px;
}

.lib-setup-param label {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    color: var(--lib-text-muted);
    margin-bottom: 3px;
    font-weight: 600;
}

.lib-setup-param span {
    font-size: 0.88rem;
    color: #f8fafc;
    font-weight: 600;
}

/* Journal / MFS Usage Callout */
.lib-mfs-callout {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(16, 185, 129, 0.02));
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 14px;
    padding: 18px 20px;
    margin-top: 24px;
}

.lib-mfs-title {
    font-size: 0.84rem;
    font-weight: 700;
    color: #34d399;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

/* Golden Quotes */
.lib-quote-box {
    border-left: 3px solid #f59e0b;
    padding: 10px 16px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 0 10px 10px 0;
    font-style: italic;
    color: #e2e8f0;
    font-size: 0.92rem;
    line-height: 1.5;
}

/* Empty State */
.lib-empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--lib-text-muted);
}

.lib-empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    color: var(--lib-text-muted);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .library-container {
        margin-top: 90px;
        padding: 0 16px 60px;
    }

    .lib-grid {
        grid-template-columns: 1fr;
    }

    .lib-drawer {
        width: 100vw;
    }

    .lib-drawer-header {
        padding: 18px 20px;
    }

    .lib-drawer-body {
        padding: 20px;
    }

    .lib-stats-ribbon {
        gap: 12px;
    }
}
