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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #fff;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
}

.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: #333;
    font-weight: 700;
    font-size: 1.2rem;
}

.logo img {
    margin-right: 0.5rem;
}

.nav {
    display: flex;
    gap: 2rem;
}

.nav-link {
    text-decoration: none;
    color: #666;
    font-weight: 500;
    transition: color 0.3s ease;
}

.nav-link:hover,
.nav-link.active {
    color: #2563eb;
}

.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
}

.mobile-menu-toggle span {
    width: 25px;
    height: 3px;
    background: #333;
    margin: 3px 0;
    transition: 0.3s;
}

/* Cookie Banner */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #333;
    color: white;
    padding: 1rem;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.cookie-banner.show {
    transform: translateY(0);
}

.cookie-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
    gap: 1rem;
}

.cookie-content p {
    margin: 0;
    font-size: 0.9rem;
}

/* Buttons */
.btn-primary {
    background: #2563eb;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.btn-primary:hover {
    background: #1d4ed8;
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 4rem 0;
    text-align: center;
}

.hero-content h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.hero-content p {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

/* Page Header */
.page-header {
    background: #f8fafc;
    padding: 3rem 0;
    text-align: center;
}

.page-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: #1f2937;
}

.page-header p {
    font-size: 1.1rem;
    color: #6b7280;
}

/* Book Cards */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.book-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.book-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}

.book-cover {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background: #f3f4f6;
}

.book-info {
    padding: 1.5rem;
}

.book-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #1f2937;
}

.book-author {
    color: #6b7280;
    margin-bottom: 0.5rem;
}

.book-category {
    display: inline-block;
    background: #e0e7ff;
    color: #3730a3;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 1rem;
}

.book-description {
    color: #4b5563;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.book-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.btn-secondary:hover {
    background: #e5e7eb;
}

/* Sections */
.featured-books,
.categories-preview,
.content-section,
.books-directory,
.categories-listing,
.contact-section {
    padding: 4rem 0;
}

.featured-books h2,
.categories-preview h2,
.content-section h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 2rem;
    text-align: center;
    color: #1f2937;
}

/* Categories */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.category-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    padding: 2rem;
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.category-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}

.category-card h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #1f2937;
}

.category-card p {
    color: #6b7280;
    margin-bottom: 1.5rem;
}

/* Filters */
.filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.search-input,
.category-select {
    padding: 0.75rem;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 1rem;
    min-width: 200px;
}

.search-input:focus,
.category-select:focus {
    outline: none;
    border-color: #2563eb;
}

/* Book Detail */
.book-detail {
    padding: 4rem 0;
}

.book-detail-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 3rem;
    align-items: start;
}

.book-detail-cover {
    width: 100%;
    max-width: 400px;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}

.book-detail-info h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: #1f2937;
}

.book-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
}

.meta-item {
    display: flex;
    flex-direction: column;
}

.meta-label {
    font-size: 0.875rem;
    color: #6b7280;
    font-weight: 500;
}

.meta-value {
    font-weight: 600;
    color: #1f2937;
}

.book-description-long {
    font-size: 1.1rem;
    line-height: 1.7;
    margin-bottom: 2rem;
    color: #4b5563;
}

.key-takeaways,
.who-its-for {
    margin-bottom: 2rem;
}

.key-takeaways h3,
.who-its-for h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #1f2937;
}

.key-takeaways ul {
    list-style: none;
    padding: 0;
}

.key-takeaways li {
    padding: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
    color: #4b5563;
}

.key-takeaways li:before {
    content: "•";
    color: #2563eb;
    font-weight: bold;
    position: absolute;
    left: 0;
}

.external-links {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 2rem;
}

.disclaimer-note {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    padding: 1rem;
    margin-top: 2rem;
    color: #92400e;
}

/* Contact Form */
.contact-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 3rem;
}

.contact-form {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #374151;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #2563eb;
}

.contact-info {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.contact-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.contact-card h3,
.contact-card h4 {
    color: #1f2937;
    margin-bottom: 1rem;
}

.contact-item {
    margin-bottom: 1rem;
}

.contact-item h4 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.form-message {
    padding: 1rem;
    border-radius: 6px;
    margin-top: 1rem;
}

.form-message.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

/* Content Sections */
.content-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 3rem;
}

.content-main {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.content-main h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    margin-top: 2rem;
    color: #1f2937;
}

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

.content-main p {
    margin-bottom: 1rem;
    color: #4b5563;
    line-height: 1.7;
}

.content-main ul {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.content-main li {
    margin-bottom: 0.5rem;
    color: #4b5563;
}

.content-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sidebar-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.sidebar-card h3 {
    color: #1f2937;
    margin-bottom: 1rem;
    font-size: 1.25rem;
    font-weight: 600;
}

.sidebar-card ul {
    list-style: none;
    padding: 0;
}

.sidebar-card li {
    padding: 0.25rem 0;
    color: #4b5563;
}

/* Legal Content */
.legal-content {
    background: white;
    padding: 3rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    max-width: 800px;
    margin: 0 auto;
}

.legal-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    margin-top: 2rem;
    color: #1f2937;
}

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

.legal-content p {
    margin-bottom: 1rem;
    color: #4b5563;
    line-height: 1.7;
}

.legal-content ul {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.legal-content li {
    margin-bottom: 0.5rem;
    color: #4b5563;
}

/* Footer */
.footer {
    background: #1f2937;
    color: white;
    padding: 3rem 0 1rem;
    margin-top: 4rem;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-section h3,
.footer-section h4 {
    margin-bottom: 1rem;
    color: white;
}

.footer-section ul {
    list-style: none;
}

.footer-section li {
    margin-bottom: 0.5rem;
}

.footer-section a {
    color: #d1d5db;
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer-section a:hover {
    color: white;
}

.footer-bottom {
    border-top: 1px solid #374151;
    padding-top: 1rem;
    text-align: center;
    color: #9ca3af;
}

/* Responsive Design */
@media (max-width: 768px) {
    .nav {
        display: none;
    }
    
    .mobile-menu-toggle {
        display: flex;
    }
    
    .hero-content h1 {
        font-size: 2rem;
    }
    
    .books-grid {
        grid-template-columns: 1fr;
    }
    
    .book-detail-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .contact-grid {
        grid-template-columns: 1fr;
    }
    
    .content-grid {
        grid-template-columns: 1fr;
    }
    
    .filters {
        flex-direction: column;
    }
    
    .search-input,
    .category-select {
        min-width: 100%;
    }
    
    .cookie-content {
        flex-direction: column;
        text-align: center;
    }
    
    .external-links {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 15px;
    }
    
    .hero {
        padding: 2rem 0;
    }
    
    .hero-content h1 {
        font-size: 1.75rem;
    }
    
    .page-header {
        padding: 2rem 0;
    }
    
    .page-header h1 {
        font-size: 2rem;
    }
    
    .featured-books,
    .categories-preview,
    .content-section,
    .books-directory,
    .categories-listing,
    .contact-section {
        padding: 2rem 0;
    }
    
    .legal-content {
        padding: 2rem 1rem;
    }
}

/* RTL Support */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .header-content {
    flex-direction: row-reverse;
}

[dir="rtl"] .logo {
    flex-direction: row-reverse;
}

[dir="rtl"] .logo img {
    margin-right: 0;
    margin-left: 0.5rem;
}

[dir="rtl"] .nav {
    flex-direction: row-reverse;
}

[dir="rtl"] .key-takeaways li {
    padding-left: 0;
    padding-right: 1.5rem;
}

[dir="rtl"] .key-takeaways li:before {
    left: auto;
    right: 0;
}

[dir="rtl"] .legal-content ul,
[dir="rtl"] .content-main ul {
    padding-left: 0;
    padding-right: 1.5rem;
}

/* FILE: assets/app.js -->
const BookApp = {
    books: [
        {
            id: 1,
            title: "Good to Great",
            author: "Jim Collins",
            category: "Business",
            shortDesc: "Why Some Companies Make the Leap... and Others Don't",
            longDesc: "Built to Last, the defining management study of the nineties, showed how great companies triumph over time and how long-term sustained performance can be engineered into the DNA of an enterprise from the very beginning. But what about the company that is not born with great DNA? How can good companies, mediocre companies, even bad companies achieve enduring greatness?",
            keyTakeaways: [
                "Level 5 Leadership: The most effective leaders combine personal humility with fierce resolve",
                "First Who, Then What: Get the right people on the bus before deciding where to drive it",
                "The Hedgehog Concept: Focus on what you can be best at, what drives your economic engine, and what you're passionate about",
                "Culture of Discipline: Disciplined people engaged in disciplined thought taking disciplined action"
            ],
            whoItsFor: "Business leaders, entrepreneurs, and managers looking to transform their organizations from good to great performance.",
            publicationYear: 2001,
            externalLinks: {
                amazon: "https://amazon.com/dp/0066620996",
                audible: "https://audible.com/pd/Good-to-Great-Audiobook/B003VXI5MS",
                googleBooks: "https://books.google.com/books?id=yOhuCgAAQBAJ"
            },
            image: "/assets/book-01.svg"
        },
        {
            id: 2,
            title: "Thinking, Fast and Slow",
            author: "Daniel Kahneman",
            category: "Personal Development",
            shortDesc: "A groundbreaking exploration of the two systems that drive the way we think",
            longDesc: "In this work, Nobel Prize winner Daniel Kahneman takes us on a groundbreaking tour of the mind and explains the two systems that drive the way we think. System 1 is fast, intuitive, and emotional; System 2 is slower, more deliberative, and more logical. The impact of overconfidence on corporate strategies, the difficulties of predicting what will make us happy in the future, the profound effect of cognitive biases on everything from playing the stock market to planning our next vacation.",
            keyTakeaways: [
                "Understanding System 1 (fast, automatic) vs System 2 (slow, deliberate) thinking",
                "Cognitive biases affect all our decisions, often without our awareness",
                "Loss aversion: People feel losses more intensely than equivalent gains",
                "The planning fallacy: We consistently underestimate time, costs, and risks of future actions"
            ],
            whoItsFor: "Anyone interested in psychology, decision-making, behavioral economics, and understanding how the human mind works.",
            publicationYear: 2011,
            externalLinks: {
                amazon: "https://amazon.com/dp/0374533555",
                audible: "https://audible.com/pd/Thinking-Fast-and-Slow-Audiobook/B005Z9GAJG",
                googleBooks: "https://books.google.com/books?id=ZuKTvERuPG8C"
            },
            image: "/assets/book-02.svg"
        },
        {
            id: 3,
            title: "The Lean Startup",
            author: "Eric Ries",
            category: "Business",
            shortDesc: "How Today's Entrepreneurs Use Continuous Innovation to Create Radically Successful Businesses",
            longDesc: "Most startups fail. But many of those failures are preventable. The Lean Startup is a new approach being adopted across the globe, changing the way companies are built and new products are launched. Eric Ries defines a startup as an organization dedicated to creating something new under conditions of extreme uncertainty.",
            keyTakeaways: [
                "Build-Measure-Learn: The fundamental cycle of turning ideas into products",
                "Minimum Viable Product (MVP): Build only what's necessary to test core assumptions",
                "Validated Learning: Learning about customers through scientific experimentation",
                "Innovation Accounting: A way to evaluate progress when traditional metrics don't apply"
            ],
            whoItsFor: "Entrepreneurs, startup founders, product managers, and anyone involved in creating new products or services.",
            publicationYear: 2011,
            externalLinks: {
                amazon: "https://amazon.com/dp/0307887898",
                audible: "https://audible.com/pd/The-Lean-Startup-Audiobook/B005LXV0HI",
                googleBooks: "https://books.google.com/books?id=tvfyz-4JILwC"
            },
            image: "/assets/book-03.svg"
        },
        {
            id: 4,
            title: "Atomic Habits",
            author: "James Clear",
            category: "Personal Development",
            shortDesc: "An Easy & Proven Way to Build Good Habits & Break Bad Ones",
            longDesc: "No matter your goals, Atomic Habits offers a proven framework for improving every day. James Clear, one of the world's leading experts on habit formation, reveals practical strategies that will teach you exactly how to form good habits, break bad ones, and master the tiny behaviors that lead to remarkable results.",
            keyTakeaways: [
                "The 1% Rule: Small improvements compound into remarkable results over time",
                "Four Laws of Behavior Change: Make it obvious, attractive, easy, and satisfying",
                "Identity-based habits: Focus on who you want to become, not what you want to achieve",
                "Environment design: Your surroundings shape your behavior more than willpower"
            ],
            whoItsFor: "Anyone looking to build better habits, break bad ones, and create lasting positive change in their life.",
            publicationYear: 2018,
            externalLinks: {
                amazon: "https://amazon.com/dp/0735211299",
                audible: "https://audible.com/pd/Atomic-Habits-Audiobook/1524779261",
                googleBooks: "https://books.google.com/books?id=XfFvDwAAQBAJ"
            },
            image: "/assets/book-04.svg"
        },
        {
            id: 5,
            title: "The Innovator's Dilemma",
            author: "Clayton M. Christensen",
            category: "Technology",
            shortDesc: "When New Technologies Cause Great Firms to Fail",
            longDesc: "In this revolutionary bestseller, Harvard professor Clayton M. Christensen says outstanding companies can do everything right and still lose their market leadership or even fail as new, unexpected competitors rise and take over the market. The Innovator's Dilemma is the book that will change the way you think about management and innovation.",
            keyTakeaways: [
                "Disruptive vs Sustaining Innovation: Understanding the two types of technological change",
                "The dilemma: Why good management practices can lead to failure in disruptive situations",
                "Value networks: Different customer segments have different performance metrics",
                "Resource allocation: How companies' processes and values determine their capabilities"
            ],
            whoItsFor: "Business leaders, technology professionals, and entrepreneurs seeking to understand innovation and competitive dynamics.",
            publicationYear: 1997,
            externalLinks: {
                amazon: "https://amazon.com/dp/1633691780",
                audible: "https://audible.com/pd/The-Innovators-Dilemma-Audiobook/B07BVQX9L8",
                googleBooks: "https://books.google.com/books?id=SIexi_qgq2gC"
            },
            image: "/assets/book-05.svg"
        },
        {
            id: 6,
            title: "Deep Work",
            author: "Cal Newport",
            category: "Productivity",
            shortDesc: "Rules for Focused Success in a Distracted World",
            longDesc: "Deep work is the ability to focus without distraction on a cognitively demanding task. It's a skill that allows you to quickly master complicated information and produce better results in less time. Deep Work will make you better at what you do and provide the sense of true fulfillment that comes from craftsmanship.",
            keyTakeaways: [
                "Deep Work vs Shallow Work: Understanding the difference and value of each",
                "The Deep Work Hypothesis: Deep work is becoming increasingly rare and valuable",
                "Four philosophies of deep work: Monastic, bimodal, rhythmic, and journalistic",
                "Digital minimalism: Being more selective about technology tools"
            ],
            whoItsFor: "Knowledge workers, professionals, students, and anyone looking to improve focus and productivity in a distracted world.",
            publicationYear: 2016,
            externalLinks: {
                amazon: "https://amazon.com/dp/1455586692",
                audible: "https://audible.com/pd/Deep-Work-Audiobook/B0189PX1RQ",
                googleBooks: "https://books.google.com/books?id=lZpKCwAAQBAJ"
            },
            image: "/assets/book-06.svg"
        },
        {
            id: 7,
            title: "The Wealth of Nations",
            author: "Adam Smith",
            category: "Economics",
            shortDesc: "An Inquiry into the Nature and Causes of the Wealth of Nations",
            longDesc: "Adam Smith's masterwork is a foundational study of the consequences of economic freedom. First published in 1776, the book offers one of the world's first collected descriptions of what builds nations' wealth, and has become a fundamental work in classical economics.",
            keyTakeaways: [
                "The Invisible Hand: How individual self-interest can benefit society as a whole",
                "Division of Labor: Specialization increases productivity and economic efficiency",
                "Free Markets: Competition leads to better products and lower prices",
                "Role of Government: Limited but important functions in a market economy"
            ],
            whoItsFor: "Students of economics, policy makers, business leaders, and anyone interested in understanding fundamental economic principles.",
            publicationYear: 1776,
            externalLinks: {
                amazon: "https://amazon.com/dp/0679783369",
                audible: "https://audible.com/pd/The-Wealth-of-Nations-Audiobook/B002V0KFPW",
                googleBooks: "https://books.google.com/books?id=C5dHAAAAMAAJ"
            },
            image: "/assets/book-07.svg"
        },
        {
            id: 8,
            title: "The 7 Habits of Highly Effective People",
            author: "Stephen R. Covey",
            category: "Personal Development",
            shortDesc: "Powerful Lessons in Personal Change",
            longDesc: "Stephen Covey's book is one of the most inspiring and impactful books ever written. It has captivated readers for 25 years and transformed the way they think about themselves and the world around them. The 7 Habits have become famous and are integrated into everyday thinking by millions and millions of people.",
            keyTakeaways: [
                "Be Proactive: Take responsibility for your own life and choices",
                "Begin with the End in Mind: Define clear measures of success and create a plan",
                "Put First Things First: Prioritize and execute around your most important goals",
                "Think Win-Win: Seek mutually beneficial solutions in all interactions"
            ],
            whoItsFor: "Anyone seeking personal and professional development, leadership skills, and a principle-centered approach to life.",
            publicationYear: 1989,
            externalLinks: {
                amazon: "https://amazon.com/dp/1982137274",
                audible: "https://audible.com/pd/The-7-Habits-of-Highly-Effective-People-Audiobook/B002V5HAL4",
                googleBooks: "https://books.google.com/books?id=ltYgAQAAMAAJ"
            },
            image: "/assets/book-08.svg"
        }
    ],

    categories: [
        { name: "Business", count: 0, description: "Management, strategy, and business development" },
        { name: "Economics", count: 0, description: "Economic theory, markets, and financial systems" },
        { name: "Technology", count: 0, description: "Innovation, digital transformation, and tech strategy" },
        { name: "Productivity", count: 0, description: "Time management, focus, and efficiency" },
        { name: "Personal Development", count: 0, description: "Self-improvement, habits, and psychology" }
    ],

    filteredBooks: [],
    currentBookId: null,

    init: function() {
        this.updateCategoryCounts();
        this.filteredBooks = [...this.books];
        this.initCookieBanner();
        this.initMobileMenu();
    },

    updateCategoryCounts: function() {
        this.categories.forEach(category => {
            category.count = this.books.filter(book => book.category === category.name).length;
        });
    },

    initCookieBanner: function() {
        const banner = document.getElementById('cookie-banner');
        const acceptBtn = document.getElementById('accept-cookies');
        
        if (!localStorage.getItem('cookies-accepted')) {
            banner.classList.add('show');
        }
        
        if (acceptBtn) {
            acceptBtn.addEventListener('click', function() {
                localStorage.setItem('cookies-accepted', 'true');
                banner.classList.remove('show');
            });
        }
    },

    initMobileMenu: function() {
        const toggle = document.getElementById('mobile-menu-toggle');
        const nav = document.querySelector('.nav');
        
        if (toggle && nav) {
            toggle.addEventListener('click', function() {
                nav.classList.toggle('mobile-active');
            });
        }
    },

    renderFeaturedBooks: function() {
        const container = document.getElementById('featured-books-grid');
        if (!container) return;

        const featuredBooks = this.books.slice(0, 6);
        container.innerHTML = featuredBooks.map(book => this.createBookCard(book)).join('');
    },

    renderAllBooks: function() {
        const container = document.getElementById('all-books-grid');
        if (!container) return;

        container.innerHTML = this.filteredBooks.map(book => this.createBookCard(book)).join('');
    },

    createBookCard: function(book) {
        return `
            <div class="book-card">
                <img src="${book.image}" alt="${book.title}" class="book-cover">
                <div class="book-info">
                    <h3 class="book-title">${book.title}</h3>
                    <p class="book-author">by ${book.author}</p>
                    <span class="book-category">${book.category}</span>
                    <p class="book-description">${book.shortDesc}</p>
                    <div class="book-actions">
                        <a href="/book/?id=${book.id}" class="btn-primary">Learn More</a>
                    </div>
                </div>
            </div>
        `;
    },

    renderCategoriesPreview: function() {
        const container = document.getElementById('categories-grid');
        if (!container) return;

        container.innerHTML = this.categories.map(category => `
            <div class="category-card">
                <h3>${category.name}</h3>
                <p>${category.description}</p>
                <p><strong>${category.count} books</strong></p>
                <a href="/books/?category=${encodeURIComponent(category.name)}" class="btn-secondary">Browse Books</a>
            </div>
        `).join('');
    },

    renderCategoriesPage: function() {
        const container = document.getElementById('categories-content');
        if (!container) return;

        const categoriesHtml = this.categories.map(category => {
            const categoryBooks = this.books.filter(book => book.category === category.name);
            return `
                <div class="category-section">
                    <h2>${category.name} (${category.count} books)</h2>
                    <p>${category.description}</p>
                    <div class="books-grid">
                        ${categoryBooks.map(book => this.createBookCard(book)).join('')}
                    </div>
                </div>
            `;
        }).join('');

        container.innerHTML = categoriesHtml;
    },

    initializeFilters: function() {
        const searchInput = document.getElementById('search-input');
        const categoryFilter = document.getElementById('category-filter');

        // Populate category filter
        if (categoryFilter) {
            const categoryOptions = this.categories.map(cat => 
                `<option value="${cat.name}">${cat.name}</option>`
            ).join('');
            categoryFilter.innerHTML = '<option value="">All Categories</option>' + categoryOptions;

            // Check URL for category parameter
            const urlParams = new URLSearchParams(window.location.search);
            const categoryParam = urlParams.get('category');
            if (categoryParam) {
                categoryFilter.value = categoryParam;
                this.filterBooks();
            }
        }

        // Add event listeners
        if (searchInput) {
            searchInput.addEventListener('input', () => this.filterBooks());
        }
        if (categoryFilter) {
            categoryFilter.addEventListener('change', () => this.filterBooks());
        }
    },

    filterBooks: function() {
        const searchTerm = document.getElementById('search-input')?.value.toLowerCase() || '';
        const selectedCategory = document.getElementById('category-filter')?.value || '';

        this.filteredBooks = this.books.filter(book => {
            const matchesSearch = !searchTerm || 
                book.title.toLowerCase().includes(searchTerm) ||
                book.author.toLowerCase().includes(searchTerm) ||
                book.shortDesc.toLowerCase().includes(searchTerm);
            
            const matchesCategory = !selectedCategory || book.category === selectedCategory;
            
            return matchesSearch && matchesCategory;
        });

        this.renderAllBooks();
    },

    renderBookDetail: function() {
        const urlParams = new URLSearchParams(window.location.search);
        const bookId = parseInt(urlParams.get('id'));
        
        if (!bookId) {
            this.renderBookNotFound();
            return;
        }

        const book = this.books.find(b => b.id === bookId);
        if (!book) {
            this.renderBookNotFound();
            return;
        }

        // Update page title and description
        document.getElementById('page-title').textContent = `${book.title} - Compassionate Book Care`;
        document.getElementById('page-description').setAttribute('content', book.shortDesc);

        const container = document.getElementById('book-detail-content');
        if (!container) return;

        container.innerHTML = `
            <section class="book-detail">
                <div class="container">
                    <div class="book-detail-grid">
                        <div class="book-detail-image">
                            <img src="${book.image}" alt="${book.title}" class="book-detail-cover">
                        </div>
                        <div class="book-detail-info">
                            <h1>${book.title}</h1>
                            <div class="book-meta">
                                <div class="meta-item">
                                    <span class="meta-label">Author</span>
                                    <span class="meta-value">${book.author}</span>
                                </div>
                                <div class="meta-item">
                                    <span class="meta-label">Category</span>
                                    <span class="meta-value">${book.category}</span>
                                </div>
                                <div class="meta-item">
                                    <span class="meta-label">Published</span>
                                    <span class="meta-value">${book.publicationYear}</span>
                                </div>
                            </div>
                            
                            <div class="book-description-long">
                                <p>${book.longDesc}</p>
                            </div>

                            <div class="key-takeaways">
                                <h3>Key Takeaways</h3>
                                <ul>
                                    ${book.keyTakeaways.map(takeaway => `<li>${takeaway}</li>`).join('')}
                                </ul>
                            </div>

                            <div class="who-its-for">
                                <h3>Who It's For</h3>
                                <p>${book.whoItsFor}</p>
                            </div>

                            <div class="external-links">
                                <a href="${book.externalLinks.amazon}" target="_blank" rel="noopener noreferrer" class="btn-primary">View on Amazon</a>
                                <a href="${book.externalLinks.audible}" target="_blank" rel="noopener noreferrer" class="btn-secondary">Listen on Audible</a>
                                <a href="${book.externalLinks.googleBooks}" target="_blank" rel="noopener noreferrer" class="btn-secondary">Google Books</a>
                            </div>

                            <div class="disclaimer-note">
                                <strong>Note:</strong> This book is sold by third-party platforms. We do not sell or distribute books directly. We may receive affiliate commissions from purchases made through these links.
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        `;
    },

    renderBookNotFound: function() {
        const container = document.getElementById('book-detail-content');
        if (!container) return;

        container.innerHTML = `
            <section class="page-header">
                <div class="container">
                    <h1>Book Not Found</h1>
                    <p>Sorry, we couldn't find the book you're looking for.</p>
                    <a href="/books/" class="btn-primary">Browse All Books</a>
                </div>
            </section>
        `;
    },

    initContactForm: function() {
        const form = document.getElementById('contact-form');
        const successMessage = document.getElementById('form-success');

        if (form) {
            form.addEventListener('submit', function(e) {
                e.preventDefault();
                
                // Simple form validation
                const name = document.getElementById('name').value.trim();
                const email = document.getElementById('email').value.trim();
                const subject = document.getElementById('subject').value;
                const message = document.getElementById('message').value.trim();

                if (!name || !email || !subject || !message) {
                    alert('Please fill in all required fields.');
                    return;
                }

                // Hide form and show success message
                form.style.display = 'none';
                successMessage.style.display = 'block';
                
                // In a real application, you would send this data to a server
                console.log('Form submitted:', { name, email, subject, message });
            });
        }
    }
};

// Auto-detect RTL languages and apply RTL styles
document.addEventListener('DOMContentLoaded', function() {
    const lang = document.documentElement.lang;
    const rtlLanguages = ['ar', 'he', 'fa', 'ur'];
    
    if (rtlLanguages.includes(lang)) {
        document.documentElement.setAttribute('dir', 'rtl');
    }
});