<?php
// ============================================
// NYAYA GURU — Blog / Legal Guide
// newsletter.php  (handles both listing & single post)
// ============================================
require_once __DIR__ . '/includes/config.php';

$db = getDB();

// ── helpers ──────────────────────────────────
function timeAgo(string $date): string {
    $diff = time() - strtotime($date);
    if ($diff < 60)           return 'Just now';
    if ($diff < 3600)         return floor($diff/60)  . ' min ago';
    if ($diff < 86400)        return floor($diff/3600) . ' hrs ago';
    if ($diff < 2592000)      return floor($diff/86400) . ' days ago';
    return date('d M Y', strtotime($date));
}

function readingTime(string $text): string {
    $words = str_word_count(strip_tags($text));
    return max(1, ceil($words / 200)) . ' min read';
}

function slugToTitle(string $slug): string {
    return ucwords(str_replace('-', ' ', $slug));
}

// ── Static fallback articles ──────────────────
$staticPosts = [
    [
        'id' => 1,
        'slug' => 'property-rights-india-complete-guide',
        'title' => 'Property Rights in India: A Complete Legal Guide for 2025',
        'excerpt' => 'Everything you need to know about buying, selling, and inheriting property in India — including RERA rules, stamp duty, and how to handle disputes.',
        'content' => '
<p>Property disputes are among the most common legal issues faced by Indians. Whether you are buying your first home, inheriting ancestral land, or dealing with a builder who has defaulted on promises, understanding your property rights is essential.</p>

<h2>1. Types of Property Ownership in India</h2>
<p>Indian law recognises several forms of property ownership:</p>
<ul>
<li><strong>Freehold Property</strong> – You own the land and the building outright. This is the most complete form of ownership.</li>
<li><strong>Leasehold Property</strong> – You own the building but the land is leased from a government body (common in Delhi and some metropolitan cities).</li>
<li><strong>Joint Ownership</strong> – Two or more persons own the property together, either as joint tenants or tenants in common.</li>
<li><strong>Ancestral Property</strong> – Property inherited through generations. Governed by the Hindu Succession Act and personal law.</li>
</ul>

<h2>2. Documents You Need Before Buying Property</h2>
<p>Never buy property without verifying these critical documents:</p>
<ul>
<li>Title Deed / Sale Deed</li>
<li>Encumbrance Certificate (EC) — confirms the property is free of loans and liabilities</li>
<li>Khata Certificate and Khata Extract</li>
<li>Approved Building Plan</li>
<li>Occupancy Certificate (OC) for completed buildings</li>
<li>RERA Registration Number (mandatory for new projects)</li>
<li>Property Tax receipts (latest)</li>
<li>No Objection Certificates (NOC) from relevant authorities</li>
</ul>

<h2>3. RERA — Your Shield as a Home Buyer</h2>
<p>The Real Estate (Regulation and Development) Act, 2016 (RERA) is the most important law protecting home buyers in India. Under RERA:</p>
<ul>
<li>Builders must register all new residential projects (above 500 sq.m. or 8 units) with the state RERA authority.</li>
<li>Builders cannot change the approved plan without buyer consent.</li>
<li>If possession is delayed, the builder must pay interest at the SBI MCLR rate + 2% for every month of delay.</li>
<li>Structural defects reported within 5 years must be rectified by the builder free of cost.</li>
</ul>

<h2>4. Stamp Duty and Registration</h2>
<p>In Telangana, stamp duty on property purchase is <strong>5% of the market value</strong> (or agreement value, whichever is higher), plus a registration fee of 0.5%. The property must be registered at the Sub-Registrar\'s Office within 4 months of execution of the sale deed.</p>

<h2>5. Handling Property Disputes</h2>
<p>If you are involved in a property dispute, here are your legal options:</p>
<ol>
<li><strong>Civil Court</strong> – File a civil suit for declaration, injunction, or specific performance.</li>
<li><strong>Revenue Court</strong> – For disputes over agricultural land and patta (ownership records).</li>
<li><strong>RERA Authority</strong> – For disputes with builders about new projects.</li>
<li><strong>Lok Adalat</strong> – For quick, consensual dispute resolution.</li>
<li><strong>Mediation</strong> – A cost-effective alternative before going to court.</li>
</ol>

<p>Always consult a qualified property lawyer before taking any legal action. The limitation period for property disputes in India is typically 12 years, but acting sooner is always better.</p>
',
        'thumbnail' => null,
        'category_name' => 'Property Law',
        'category_slug' => 'property-law',
        'author' => 'Adv. Rajesh Kumar',
        'views' => 4821,
        'published_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
        'tags' => ['Property', 'RERA', 'Telangana', 'Real Estate'],
        'featured' => true,
    ],
    [
        'id' => 2,
        'slug' => 'divorce-law-india-mutual-consent-contested',
        'title' => 'Divorce in India: Mutual Consent vs Contested — What You Must Know',
        'excerpt' => 'A plain-language guide to the two types of divorce in India, timelines, maintenance rights, child custody, and how to protect yourself legally.',
        'content' => '
<p>Divorce is one of the most emotionally and legally complex processes anyone can go through. Understanding the law helps you make informed decisions during an already difficult time.</p>

<h2>1. Two Types of Divorce</h2>
<h3>Mutual Consent Divorce (Section 13-B, Hindu Marriage Act)</h3>
<p>When both spouses agree to end the marriage, they can file a joint petition. The process involves two court hearings separated by a mandatory 6-month cooling-off period (which can be waived by the Supreme Court in certain cases).</p>
<p><strong>Timeline:</strong> Typically 6–18 months.</p>
<p><strong>Cost:</strong> Relatively low — mainly lawyer fees and court filing fees.</p>

<h3>Contested Divorce (Section 13, Hindu Marriage Act)</h3>
<p>When one spouse contests the divorce, the grounds must be proved in court. Valid grounds include cruelty, adultery, desertion (2+ years), conversion to another religion, mental disorder, and leprosy.</p>
<p><strong>Timeline:</strong> Can take 2–10 years depending on the court\'s workload and complexity.</p>
<p><strong>Cost:</strong> Significantly higher due to prolonged litigation.</p>

<h2>2. Maintenance and Alimony</h2>
<p>Under Section 24 and 25 of the Hindu Marriage Act, either spouse can claim maintenance. The court considers:</p>
<ul>
<li>Income and assets of both spouses</li>
<li>Standard of living during marriage</li>
<li>Age and health of the applicant</li>
<li>Duration of the marriage</li>
</ul>

<h2>3. Child Custody</h2>
<p>Courts in India apply the "best interest of the child" standard. Custody can be:</p>
<ul>
<li><strong>Physical Custody</strong> – The child lives with one parent.</li>
<li><strong>Joint Custody</strong> – The child spends time with both parents.</li>
<li><strong>Sole Custody</strong> – Rare; granted when one parent is deemed unfit.</li>
</ul>
<p>Generally, for children below 5 years, the mother is preferred. For older children, courts may consider the child\'s own preference.</p>
',
        'thumbnail' => null,
        'category_name' => 'Family Law',
        'category_slug' => 'family-law',
        'author' => 'Adv. Priya Sharma',
        'views' => 7234,
        'published_at' => date('Y-m-d H:i:s', strtotime('-6 days')),
        'tags' => ['Divorce', 'Family Law', 'Custody', 'Maintenance'],
        'featured' => true,
    ],
    [
        'id' => 3,
        'slug' => 'fir-filing-guide-police-complaint-india',
        'title' => 'How to File an FIR in India — Step-by-Step Legal Guide',
        'excerpt' => 'Learn exactly how to file a First Information Report (FIR), what to do if police refuse, and your rights as a complainant under Indian criminal law.',
        'content' => '
<p>Filing an FIR (First Information Report) is the first official step in the criminal justice process. Many people are unaware of their rights when reporting a crime. Here is a complete guide.</p>

<h2>What is an FIR?</h2>
<p>An FIR is a written document prepared by the police when they receive information about the commission of a cognizable offence (a crime for which police can arrest without a warrant, such as robbery, murder, rape, etc.).</p>

<h2>Step-by-Step: How to File an FIR</h2>
<ol>
<li><strong>Visit the nearest police station</strong> – Go to the police station that has jurisdiction over the area where the crime occurred.</li>
<li><strong>Narrate the incident</strong> – Clearly describe what happened, when, where, and who was involved. Bring any evidence you have (photos, screenshots, documents).</li>
<li><strong>FIR is recorded</strong> – The officer records your statement. You have the right to have the FIR read back to you.</li>
<li><strong>Sign the FIR</strong> – Read carefully before signing. Do not sign anything you disagree with.</li>
<li><strong>Get a free copy</strong> – You are legally entitled to a free copy of the FIR under Section 154(2) CrPC.</li>
<li><strong>Note the FIR number</strong> – Keep this for all future follow-ups.</li>
</ol>

<h2>What if Police Refuse to File FIR?</h2>
<p>Refusing to register an FIR for a cognizable offence is illegal. If police refuse:</p>
<ul>
<li>Send your complaint by post (registered AD) to the Superintendent of Police.</li>
<li>File a complaint under Section 156(3) CrPC before a Judicial Magistrate.</li>
<li>File a complaint with the State Human Rights Commission or Police Complaints Authority.</li>
<li>Contact a criminal lawyer immediately.</li>
</ul>

<h2>Zero FIR</h2>
<p>A Zero FIR can be registered at any police station, regardless of jurisdiction. It is then transferred to the appropriate police station. This is particularly useful in emergencies.</p>
',
        'thumbnail' => null,
        'category_name' => 'Criminal Law',
        'category_slug' => 'criminal-law',
        'author' => 'Adv. Mohammed Ali',
        'views' => 9102,
        'published_at' => date('Y-m-d H:i:s', strtotime('-10 days')),
        'tags' => ['FIR', 'Criminal Law', 'Police Complaint'],
        'featured' => false,
    ],
    [
        'id' => 4,
        'slug' => 'startup-registration-india-types-comparison',
        'title' => 'Startup Registration in India: Private Ltd vs LLP vs OPC Compared',
        'excerpt' => 'Confused about which business structure to choose for your startup? This guide compares Private Limited Company, LLP, and One Person Company with pros, cons, and costs.',
        'content' => '
<p>Choosing the right legal structure is one of the most critical decisions for a new startup. Each structure has different implications for liability, taxation, fundraising, and compliance.</p>

<h2>1. Private Limited Company (Pvt. Ltd.)</h2>
<p><strong>Best for:</strong> Startups planning to raise VC/Angel funding.</p>
<ul>
<li>Minimum 2 directors, 2 shareholders</li>
<li>Limited liability for shareholders</li>
<li>Easiest to raise investment (equity shares)</li>
<li>Regulated by Companies Act 2013 and MCA</li>
<li>Annual compliance: Board meetings, ROC filings, audit required</li>
<li><strong>Setup cost:</strong> ₹8,000 – ₹15,000</li>
<li><strong>Annual compliance cost:</strong> ₹15,000 – ₹40,000</li>
</ul>

<h2>2. Limited Liability Partnership (LLP)</h2>
<p><strong>Best for:</strong> Professional services firms, small businesses with 2+ founders.</p>
<ul>
<li>Minimum 2 designated partners</li>
<li>Partners have limited liability (protected from business debts)</li>
<li>Less compliance than Pvt. Ltd.</li>
<li>Cannot issue equity shares — harder to raise VC funding</li>
<li><strong>Setup cost:</strong> ₹5,000 – ₹10,000</li>
<li><strong>Annual compliance cost:</strong> ₹8,000 – ₹20,000</li>
</ul>

<h2>3. One Person Company (OPC)</h2>
<p><strong>Best for:</strong> Solo founders who want limited liability without a co-founder.</p>
<ul>
<li>Only 1 director and 1 shareholder (can be the same person)</li>
<li>Limited liability protection</li>
<li>Mandatory nominee director</li>
<li>Must convert to Pvt. Ltd. if paid-up capital exceeds ₹50 lakhs or turnover exceeds ₹2 crores</li>
<li><strong>Setup cost:</strong> ₹5,000 – ₹12,000</li>
</ul>

<h2>Quick Comparison Table</h2>
<table border="1" cellpadding="8" cellspacing="0" style="width:100%;border-collapse:collapse;font-size:0.9rem;">
<thead style="background:#0A2342;color:white;">
<tr><th>Feature</th><th>Pvt. Ltd.</th><th>LLP</th><th>OPC</th></tr>
</thead>
<tbody>
<tr><td>Min. Founders</td><td>2</td><td>2</td><td>1</td></tr>
<tr style="background:#f8f9fc;"><td>Fundraising</td><td>✅ Easy</td><td>⚠️ Difficult</td><td>❌ Not allowed</td></tr>
<tr><td>Compliance</td><td>High</td><td>Medium</td><td>Medium</td></tr>
<tr style="background:#f8f9fc;"><td>Tax Rate</td><td>22% (base)</td><td>30%</td><td>22% (base)</td></tr>
<tr><td>Best For</td><td>Funded startups</td><td>Service firms</td><td>Solo founders</td></tr>
</tbody>
</table>
',
        'thumbnail' => null,
        'category_name' => 'Startup Law',
        'category_slug' => 'startup-law',
        'author' => 'Adv. Sunitha Reddy',
        'views' => 3410,
        'published_at' => date('Y-m-d H:i:s', strtotime('-14 days')),
        'tags' => ['Startup', 'Business Registration', 'Private Limited', 'LLP'],
        'featured' => false,
    ],
    [
        'id' => 5,
        'slug' => 'cyber-crime-india-how-to-report',
        'title' => 'Cyber Crime in India: Types, How to Report & What the Law Says',
        'excerpt' => 'Online fraud, hacking, social media abuse — cyber crime is rising fast. Here\'s how to protect yourself legally and report cybercrime in India.',
        'content' => '
<p>India reported over 14 lakh cybercrime complaints in 2023 alone. With more of our lives moving online, knowing your legal rights and remedies is critical.</p>

<h2>Common Types of Cyber Crime in India</h2>
<ul>
<li><strong>Online Financial Fraud</strong> – UPI fraud, OTP scams, fake investment schemes (e.g. "doubling money" apps).</li>
<li><strong>Identity Theft</strong> – Using someone else\'s Aadhaar, PAN, or login credentials.</li>
<li><strong>Hacking</strong> – Unauthorised access to computer systems (Section 66, IT Act).</li>
<li><strong>Cyberbullying & Harassment</strong> – Sending threatening messages, morphing photos, defamation online.</li>
<li><strong>Phishing</strong> – Fake emails/messages/websites designed to steal credentials.</li>
<li><strong>Sextortion</strong> – Threatening to leak intimate images.</li>
<li><strong>Child Pornography</strong> – Creating, distributing or viewing CSAM (severe punishment under POCSO + IT Act).</li>
</ul>

<h2>How to Report Cybercrime in India</h2>
<ol>
<li><strong>National Cyber Crime Reporting Portal</strong> – Visit <a href="https://cybercrime.gov.in" target="_blank">cybercrime.gov.in</a> to file a complaint online.</li>
<li><strong>Cyber Crime Helpline</strong> – Call <strong>1930</strong> for immediate assistance with financial cyber fraud.</li>
<li><strong>Local Police Station</strong> – File an FIR at the nearest station. Ask for the Cyber Crime cell.</li>
<li><strong>State Cyber Crime Cell</strong> – Each state has a dedicated Cyber Crime investigation unit.</li>
</ol>

<h2>Key Laws Protecting You</h2>
<ul>
<li><strong>IT Act 2000</strong> – Primary law governing cybercrime in India.</li>
<li><strong>Section 66</strong> – Hacking: up to 3 years imprisonment + fine.</li>
<li><strong>Section 66C</strong> – Identity theft: up to 3 years + ₹1 lakh fine.</li>
<li><strong>Section 67</strong> – Publishing obscene content: up to 5 years + ₹10 lakh fine.</li>
<li><strong>IPC Section 420</strong> – Cheating (applies to online fraud).</li>
<li><strong>POCSO Act</strong> – Protection of children from sexual offences online.</li>
</ul>

<h2>What to Do Immediately After Being Victimised</h2>
<ol>
<li>Call 1930 immediately for financial fraud — golden hour matters!</li>
<li>Screenshot and preserve all evidence.</li>
<li>Do NOT delete any messages or emails.</li>
<li>Inform your bank immediately to freeze transactions.</li>
<li>Consult a cyber crime lawyer for complex cases.</li>
</ol>
',
        'thumbnail' => null,
        'category_name' => 'Cyber Crime',
        'category_slug' => 'cyber-crime',
        'author' => 'Adv. Ravi Prasad',
        'views' => 6677,
        'published_at' => date('Y-m-d H:i:s', strtotime('-18 days')),
        'tags' => ['Cyber Crime', 'IT Act', 'Online Fraud', 'Cyberbullying'],
        'featured' => false,
    ],
    [
        'id' => 6,
        'slug' => 'consumer-rights-india-forum-complaint',
        'title' => 'Consumer Rights in India: How to File a Consumer Forum Complaint',
        'excerpt' => 'Got cheated by a company? Bought a defective product? Know your rights under the Consumer Protection Act 2019 and how to get justice fast.',
        'content' => '
<p>India\'s Consumer Protection Act 2019 is one of the strongest consumer laws in the world. If you\'ve been wronged as a consumer, you have powerful legal remedies available.</p>

<h2>Who is a Consumer?</h2>
<p>Under the Act, a consumer is anyone who buys goods or avails services for personal use (not for commercial resale). This includes online purchases, hotel stays, medical services, education, and more.</p>

<h2>Your Rights as a Consumer</h2>
<ul>
<li>Right to Safety</li>
<li>Right to Information</li>
<li>Right to Choose</li>
<li>Right to be Heard</li>
<li>Right to Seek Redressal</li>
<li>Right to Consumer Education</li>
</ul>

<h2>Consumer Forums — Which One to Approach?</h2>
<table border="1" cellpadding="8" cellspacing="0" style="width:100%;border-collapse:collapse;font-size:0.88rem;">
<thead style="background:#0A2342;color:white;">
<tr><th>Forum</th><th>Claim Amount</th></tr>
</thead>
<tbody>
<tr><td>District Consumer Commission</td><td>Up to ₹1 Crore</td></tr>
<tr style="background:#f8f9fc;"><td>State Consumer Commission</td><td>₹1 Crore – ₹10 Crore</td></tr>
<tr><td>National Consumer Commission (NCDRC)</td><td>Above ₹10 Crore</td></tr>
</tbody>
</table>

<h2>Filing an Online Complaint</h2>
<p>Under the 2019 Act, you can file complaints online at <a href="https://edaakhil.nic.in" target="_blank">edaakhil.nic.in</a>. No lawyer is required for complaints below ₹5 lakhs.</p>

<h2>Time Limit</h2>
<p>Complaints must be filed within <strong>2 years</strong> from the date the cause of action arose. Do not delay!</p>
',
        'thumbnail' => null,
        'category_name' => 'Consumer Protection',
        'category_slug' => 'consumer-protection',
        'author' => 'Adv. Lakshmi Devi',
        'views' => 2890,
        'published_at' => date('Y-m-d H:i:s', strtotime('-22 days')),
        'tags' => ['Consumer Rights', 'Consumer Forum', 'Complaint', 'Refund'],
        'featured' => false,
    ],
    [
        'id' => 7,
        'slug' => 'bail-types-india-regular-anticipatory',
        'title' => 'Types of Bail in India: Regular, Anticipatory & Interim Bail Explained',
        'excerpt' => 'If you or someone you know is arrested or facing arrest, understanding bail is critical. Here\'s a plain-language guide to all types of bail under Indian law.',
        'content' => '
<p>Bail is the temporary release of an accused person awaiting trial. Indian law provides several types of bail depending on the stage of the case and the nature of the offence.</p>

<h2>1. Regular Bail (Section 437 & 439 CrPC)</h2>
<p>Applied for after arrest. A person in custody can apply for bail before the Magistrate (Section 437) or the Sessions Court / High Court (Section 439).</p>
<p>Courts consider: nature of the offence, prior criminal record, risk of flight, and likelihood of tampering with evidence.</p>

<h2>2. Anticipatory Bail (Section 438 CrPC)</h2>
<p>Applied for <em>before</em> arrest when a person has reason to believe they may be arrested for a non-bailable offence. This is one of the most powerful protections available under Indian law.</p>
<p>Only Sessions Court or High Court can grant anticipatory bail.</p>

<h2>3. Interim Bail</h2>
<p>A temporary bail granted for a short period (usually a few days) while the regular bail or anticipatory bail application is being heard.</p>

<h2>4. Default Bail (Section 167(2) CrPC)</h2>
<p>If the police fail to file a chargesheet within the stipulated time (60 days for offences punishable with death/life imprisonment; 90 days for others), the accused is entitled to bail as a matter of right. This is called default bail or statutory bail.</p>

<h2>Bailable vs Non-Bailable Offences</h2>
<ul>
<li><strong>Bailable offences</strong> – Bail is a right. The police must grant bail if requested.</li>
<li><strong>Non-bailable offences</strong> – Bail is at the court\'s discretion. A lawyer is strongly recommended.</li>
</ul>
',
        'thumbnail' => null,
        'category_name' => 'Criminal Law',
        'category_slug' => 'criminal-law',
        'author' => 'Adv. Mohammed Ali',
        'views' => 5341,
        'published_at' => date('Y-m-d H:i:s', strtotime('-27 days')),
        'tags' => ['Bail', 'Criminal Law', 'Anticipatory Bail', 'Arrest'],
        'featured' => false,
    ],
    [
        'id' => 8,
        'slug' => 'gst-basics-small-business-india',
        'title' => 'GST for Small Businesses in India: Registration, Filing & Common Mistakes',
        'excerpt' => 'A practical GST guide for small business owners — when to register, which returns to file, ITC claims, and the 5 most common mistakes that attract notices.',
        'content' => '
<p>Goods and Services Tax (GST), introduced in July 2017, unified India\'s indirect tax system. For small businesses, understanding GST compliance is not optional — penalties can be severe.</p>

<h2>When Must You Register for GST?</h2>
<ul>
<li>Annual turnover exceeds ₹40 lakhs (goods) or ₹20 lakhs (services) — for most states.</li>
<li>Threshold is ₹10 lakhs for Special Category States (North-Eastern states, Himachal Pradesh, Uttarakhand).</li>
<li>If you sell interstate, regardless of turnover.</li>
<li>If you sell on e-commerce platforms (Amazon, Flipkart, etc.).</li>
</ul>

<h2>GST Returns for Small Businesses</h2>
<table border="1" cellpadding="8" cellspacing="0" style="width:100%;border-collapse:collapse;font-size:0.88rem;">
<thead style="background:#0A2342;color:white;">
<tr><th>Return</th><th>Who Files</th><th>Frequency</th></tr>
</thead>
<tbody>
<tr><td>GSTR-1</td><td>All regular taxpayers</td><td>Monthly / Quarterly</td></tr>
<tr style="background:#f8f9fc;"><td>GSTR-3B</td><td>All regular taxpayers</td><td>Monthly</td></tr>
<tr><td>GSTR-4</td><td>Composition scheme taxpayers</td><td>Annually</td></tr>
<tr style="background:#f8f9fc;"><td>GSTR-9</td><td>Annual return for all taxpayers</td><td>Annually</td></tr>
</tbody>
</table>

<h2>5 Common GST Mistakes That Attract Notices</h2>
<ol>
<li>Not reconciling GSTR-1 with GSTR-3B.</li>
<li>Wrongly claiming Input Tax Credit (ITC) on ineligible items.</li>
<li>Not filing nil returns when there is no business activity.</li>
<li>Wrong HSN/SAC codes for goods/services.</li>
<li>Delayed filing leading to late fees and interest.</li>
</ol>

<h2>Composition Scheme — Is It Right for You?</h2>
<p>If your turnover is below ₹1.5 crores (goods) or ₹50 lakhs (services), you can opt for the Composition Scheme. You pay a flat tax (1% for traders, 5% for restaurants, 6% for service providers) and file only one quarterly return. However, you cannot claim ITC or issue tax invoices.</p>
',
        'thumbnail' => null,
        'category_name' => 'Tax Law',
        'category_slug' => 'tax-law',
        'author' => 'Adv. Ravi Prasad',
        'views' => 3120,
        'published_at' => date('Y-m-d H:i:s', strtotime('-31 days')),
        'tags' => ['GST', 'Tax Law', 'Small Business', 'Compliance'],
        'featured' => false,
    ],
];

// ── Category list (for filters) ──────────────────
$allCategories = array_unique(array_column($staticPosts, 'category_name'));
$allTags = array_unique(array_merge(...array_column($staticPosts, 'tags')));

// ── Try to load from DB, fall back to static ─────
$dbHasBlogs = false;
try {
    $count = $db->query("SELECT COUNT(*) FROM blogs")->fetchColumn();
    if ($count > 0) {
        $dbHasBlogs = true;
        $dbPosts = $db->query("
            SELECT b.*, lc.name as category_name, lc.slug as category_slug
            FROM blogs b
            LEFT JOIN legal_categories lc ON b.category_id = lc.id
            WHERE b.status = 1
            ORDER BY b.published_at DESC
        ")->fetchAll();
        foreach ($dbPosts as &$p) {
            $p['tags']    = [];
            $p['author']  = $p['author_id'] ? 'Nyaya Guru Team' : 'Nyaya Guru Team';
            $p['featured']= false;
        }
        $posts = $dbPosts;
    }
} catch (\Throwable $e) { /* table may not exist yet */ }

if (!$dbHasBlogs) $posts = $staticPosts;

// ── Routing: list vs single post ─────────────────
$slug = $_GET['slug'] ?? '';
$catFilter = $_GET['category'] ?? '';
$tagFilter  = $_GET['tag'] ?? '';
$search    = trim($_GET['q'] ?? '');
$pageNum   = max(1, (int)($_GET['page'] ?? 1));
$perPage   = 6;

if ($slug) {
    // ── SINGLE POST VIEW ─────────────────────────
    $post = null;
    foreach ($posts as $p) {
        if ($p['slug'] === $slug) { $post = $p; break; }
    }
    if (!$post) { header('Location: /newsletter.php'); exit; }

    // Increment views in DB if available
    if ($dbHasBlogs) {
        try { $db->prepare("UPDATE blogs SET views = views + 1 WHERE id = ?")->execute([$post['id']]); } catch(\Throwable $e){}
    }

    // Related posts
    $related = array_filter($posts, fn($p) =>
        $p['slug'] !== $slug && ($p['category_slug'] === $post['category_slug'])
    );
    $related = array_slice(array_values($related), 0, 3);

    // Prev / Next
    $postIndex = array_search($post, array_column($posts, 'slug'));
    $prevPost  = $posts[$postIndex - 1] ?? null;
    $nextPost  = $posts[$postIndex + 1] ?? null;

    $pageTitle       = $post['title'] . ' | Nyaya Guru Legal Guide';
    $metaDescription = $post['excerpt'];

    require_once __DIR__ . '/includes/header.php';
    ?>

<!-- ── SINGLE POST HERO ─────────────────────────── -->
<div style="background:linear-gradient(135deg,var(--primary-dark) 0%,var(--primary) 60%,#1a3a6b 100%);padding:56px 0 0;position:relative;overflow:hidden;">
    <div style="position:absolute;inset:0;background-image:url('data:image/svg+xml,%3Csvg width=\'60\' height=\'60\' viewBox=\'0 0 60 60\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cg fill=\'%23D4AF37\' fill-opacity=\'0.04\'%3E%3Cpath d=\'M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z\'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');"></div>
    <div class="container" style="position:relative;z-index:2;">
        <nav aria-label="breadcrumb" style="margin-bottom:20px;">
            <ol class="breadcrumb" style="margin:0;background:transparent;">
                <li class="breadcrumb-item"><a href="/" style="color:rgba(255,255,255,0.65);">Home</a></li>
                <li class="breadcrumb-item"><a href="<?= SITE_URL ?>/newsletter.php" style="color:rgba(255,255,255,0.65);">Legal Guide</a></li>
                <li class="breadcrumb-item active" style="color:var(--gold);"><?= htmlspecialchars($post['category_name']) ?></li>
            </ol>
        </nav>

        <div style="max-width:820px;">
            <div style="display:flex;gap:10px;flex-wrap:wrap;margin-bottom:18px;">
                <a href="/newsletter.php?category=<?= urlencode($post['category_slug']) ?>"
                   style="background:var(--gold);color:var(--primary);padding:5px 16px;border-radius:50px;font-size:0.75rem;font-weight:800;text-transform:uppercase;letter-spacing:0.06em;text-decoration:none;">
                    <?= htmlspecialchars($post['category_name']) ?>
                </a>
                <span style="background:rgba(255,255,255,0.1);color:rgba(255,255,255,0.7);padding:5px 14px;border-radius:50px;font-size:0.75rem;">
                    <i class="fas fa-clock me-1"></i><?= readingTime($post['content']) ?>
                </span>
                <span style="background:rgba(255,255,255,0.1);color:rgba(255,255,255,0.7);padding:5px 14px;border-radius:50px;font-size:0.75rem;">
                    <i class="fas fa-eye me-1"></i><?= number_format($post['views']) ?> views
                </span>
            </div>
            <h1 style="color:white;font-size:clamp(1.5rem,3.5vw,2.3rem);font-weight:800;line-height:1.25;margin-bottom:20px;">
                <?= htmlspecialchars($post['title']) ?>
            </h1>
            <div style="display:flex;align-items:center;gap:18px;flex-wrap:wrap;padding-bottom:28px;">
                <div style="display:flex;align-items:center;gap:10px;">
                    <div style="width:40px;height:40px;background:var(--gold);border-radius:50%;display:flex;align-items:center;justify-content:center;font-weight:800;color:var(--primary);font-size:0.9rem;font-family:var(--font-heading);">
                        <?= strtoupper(substr($post['author'], 0, 2)) ?>
                    </div>
                    <div>
                        <div style="color:white;font-size:0.87rem;font-weight:600;"><?= htmlspecialchars($post['author']) ?></div>
                        <div style="color:rgba(255,255,255,0.5);font-size:0.75rem;">Legal Expert</div>
                    </div>
                </div>
                <span style="color:rgba(255,255,255,0.4);">·</span>
                <span style="color:rgba(255,255,255,0.6);font-size:0.82rem;">
                    <i class="fas fa-calendar me-1"></i><?= date('d F Y', strtotime($post['published_at'])) ?>
                </span>
                <span style="color:rgba(255,255,255,0.4);">·</span>
                <span style="color:rgba(255,255,255,0.6);font-size:0.82rem;">
                    <i class="fas fa-clock me-1"></i><?= readingTime($post['content']) ?>
                </span>
            </div>
        </div>
    </div>
    <!-- Wave bottom -->
    <svg viewBox="0 0 1440 40" xmlns="http://www.w3.org/2000/svg" style="display:block;width:100%;margin-top:-1px;" preserveAspectRatio="none">
        <path d="M0,20 C360,40 1080,0 1440,20 L1440,40 L0,40 Z" fill="#ffffff"/>
    </svg>
</div>

<!-- ── SINGLE POST BODY ───────────────────────────── -->
<section style="padding:56px 0 80px;">
    <div class="container">
        <div class="row g-5">

            <!-- Article content -->
            <div class="col-lg-8">
                <article style="background:white;border-radius:20px;overflow:hidden;box-shadow:var(--shadow);border:1px solid var(--border);">
                    <!-- Thumbnail placeholder -->
                    <div style="background:linear-gradient(135deg,var(--primary),#1a3a6b);height:12px;"></div>

                    <div style="padding:44px;">
                        <!-- Excerpt / lead -->
                        <p style="font-size:1.05rem;color:var(--text-light);line-height:1.85;padding:20px;background:var(--off-white);border-radius:12px;border-left:4px solid var(--gold);margin-bottom:32px;">
                            <?= htmlspecialchars($post['excerpt']) ?>
                        </p>

                        <!-- Full content -->
                        <div class="article-body" style="font-size:0.95rem;line-height:1.9;color:var(--text);">
                            <?= $post['content'] ?>
                        </div>

                        <!-- Tags -->
                        <?php if (!empty($post['tags'])): ?>
                        <div style="margin-top:36px;padding-top:24px;border-top:1px solid var(--border);">
                            <span style="font-size:0.8rem;font-weight:700;color:var(--text-light);text-transform:uppercase;letter-spacing:0.06em;margin-right:10px;">Tags:</span>
                            <?php foreach($post['tags'] as $tag): ?>
                            <a href="/newsletter.php?tag=<?= urlencode($tag) ?>"
                               style="background:var(--off-white);color:var(--primary);padding:5px 14px;border-radius:50px;font-size:0.78rem;font-weight:600;text-decoration:none;margin-right:6px;margin-bottom:6px;display:inline-block;border:1px solid var(--border);transition:var(--transition);"
                               onmouseover="this.style.background='var(--primary)';this.style.color='white';this.style.borderColor='var(--primary)'"
                               onmouseout="this.style.background='var(--off-white)';this.style.color='var(--primary)';this.style.borderColor='var(--border)'">
                                #<?= htmlspecialchars($tag) ?>
                            </a>
                            <?php endforeach; ?>
                        </div>
                        <?php endif; ?>

                        <!-- Share -->
                        <div style="margin-top:28px;padding:20px;background:var(--off-white);border-radius:14px;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:14px;">
                            <span style="font-size:0.88rem;font-weight:700;color:var(--primary);">Share this article:</span>
                            <div style="display:flex;gap:8px;">
                                <?php
                                $shareUrl = urlencode(SITE_URL . '/newsletter.php?slug=' . $post['slug']);
                                $shareTitle = urlencode($post['title']);
                                $shares = [
                                    ['fab fa-whatsapp',  '#25D366', 'https://wa.me/?text='.$shareTitle.'%20'.$shareUrl],
                                    ['fab fa-twitter',   '#1DA1F2', 'https://twitter.com/intent/tweet?text='.$shareTitle.'&url='.$shareUrl],
                                    ['fab fa-linkedin-in','#0A66C2','https://linkedin.com/shareArticle?url='.$shareUrl.'&title='.$shareTitle],
                                    ['fab fa-facebook-f','#1877F2', 'https://facebook.com/sharer.php?u='.$shareUrl],
                                ];
                                foreach($shares as $s): ?>
                                <a href="<?= $s[2] ?>" target="_blank"
                                   style="width:38px;height:38px;background:<?= $s[0] === 'fab fa-whatsapp' ? '#25D366' : $s[1] ?>;border-radius:8px;display:flex;align-items:center;justify-content:center;color:white;font-size:0.9rem;text-decoration:none;transition:var(--transition);"
                                   onmouseover="this.style.transform='translateY(-2px)'"
                                   onmouseout="this.style.transform=''">
                                    <i class="<?= $s[0] ?>"></i>
                                </a>
                                <?php endforeach; ?>
                            </div>
                        </div>
                    </div>
                </article>

                <!-- Author card -->
                <div style="background:white;border-radius:20px;padding:28px;box-shadow:var(--shadow);border:1px solid var(--border);margin-top:24px;display:flex;gap:20px;align-items:flex-start;">
                    <div style="width:64px;height:64px;min-width:64px;background:linear-gradient(135deg,var(--primary),#1a3a6b);border-radius:16px;display:flex;align-items:center;justify-content:center;font-size:1.4rem;font-weight:800;color:var(--gold);font-family:var(--font-heading);">
                        <?= strtoupper(substr($post['author'], 0, 2)) ?>
                    </div>
                    <div>
                        <div style="font-size:0.75rem;text-transform:uppercase;letter-spacing:0.07em;color:var(--text-light);font-weight:700;margin-bottom:4px;">Written by</div>
                        <h5 style="font-size:1rem;margin-bottom:6px;"><?= htmlspecialchars($post['author']) ?></h5>
                        <p style="font-size:0.85rem;color:var(--text-light);margin-bottom:14px;line-height:1.7;">Verified legal expert on Nyaya Guru with deep experience in <?= htmlspecialchars($post['category_name']) ?>. Providing accessible legal guidance to thousands of Indians.</p>
                        <a href="lawyers.php?category=<?= $post['category_slug'] ?>"
                           style="background:var(--primary);color:white;padding:9px 20px;border-radius:50px;font-size:0.82rem;font-weight:600;text-decoration:none;">
                            <i class="fas fa-comments me-1"></i>Consult a <?= htmlspecialchars($post['category_name']) ?> Expert
                        </a>
                    </div>
                </div>

                <!-- Prev / Next Navigation -->
                <div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-top:24px;">
                    <?php if ($prevPost): ?>
                    <a href="/newsletter.php?slug=<?= $prevPost['slug'] ?>"
                       style="background:white;border:1px solid var(--border);border-radius:14px;padding:18px;text-decoration:none;transition:var(--transition);"
                       onmouseover="this.style.borderColor='var(--primary)';this.style.transform='translateX(-2px)'"
                       onmouseout="this.style.borderColor='var(--border)';this.style.transform=''">
                        <div style="font-size:0.72rem;color:var(--text-light);font-weight:700;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:6px;">
                            <i class="fas fa-arrow-left me-1"></i>Previous
                        </div>
                        <div style="font-size:0.85rem;font-weight:700;color:var(--primary);line-height:1.4;"><?= htmlspecialchars(substr($prevPost['title'], 0, 60)) ?>...</div>
                    </a>
                    <?php else: ?><div></div><?php endif; ?>
                    <?php if ($nextPost): ?>
                    <a href="/newsletter.php?slug=<?= $nextPost['slug'] ?>"
                       style="background:white;border:1px solid var(--border);border-radius:14px;padding:18px;text-decoration:none;text-align:right;transition:var(--transition);"
                       onmouseover="this.style.borderColor='var(--primary)';this.style.transform='translateX(2px)'"
                       onmouseout="this.style.borderColor='var(--border)';this.style.transform=''">
                        <div style="font-size:0.72rem;color:var(--text-light);font-weight:700;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:6px;">
                            Next <i class="fas fa-arrow-right ms-1"></i>
                        </div>
                        <div style="font-size:0.85rem;font-weight:700;color:var(--primary);line-height:1.4;"><?= htmlspecialchars(substr($nextPost['title'], 0, 60)) ?>...</div>
                    </a>
                    <?php endif; ?>
                </div>
            </div>

            <!-- Sidebar -->
            <div class="col-lg-4">
                <!-- CTA -->
                <div style="background:linear-gradient(135deg,var(--primary),#1a3a6b);border-radius:20px;padding:28px;text-align:center;margin-bottom:24px;">
                    <div style="width:56px;height:56px;background:var(--gold);border-radius:14px;display:flex;align-items:center;justify-content:center;margin:0 auto 16px;font-size:1.3rem;color:var(--primary);">
                        <i class="fas fa-user-tie"></i>
                    </div>
                    <h5 style="color:white;font-size:1rem;margin-bottom:8px;">Need Legal Help?</h5>
                    <p style="color:rgba(255,255,255,0.65);font-size:0.82rem;margin-bottom:18px;">Consult a verified <?= htmlspecialchars($post['category_name']) ?> expert online — right now.</p>
                    <a href="lawyers.php?category=<?= $post['category_slug'] ?>"
                       style="display:block;background:var(--gold);color:var(--primary);padding:12px;border-radius:10px;font-weight:700;font-size:0.88rem;text-decoration:none;">
                        <i class="fas fa-comments me-1"></i>Talk to a Lawyer
                    </a>
                    <a href="https://wa.me/9876543210" target="_blank"
                       style="display:block;background:rgba(255,255,255,0.08);color:rgba(255,255,255,0.8);padding:11px;border-radius:10px;font-weight:600;font-size:0.85rem;text-decoration:none;margin-top:8px;border:1px solid rgba(255,255,255,0.12);">
                        <i class="fab fa-whatsapp me-1" style="color:#25D366;"></i>Chat on WhatsApp
                    </a>
                </div>

                <!-- Related articles -->
                <?php if (!empty($related)): ?>
                <div style="background:white;border-radius:16px;padding:24px;box-shadow:var(--shadow);border:1px solid var(--border);margin-bottom:24px;">
                    <h6 style="font-size:0.88rem;font-weight:800;color:var(--primary);margin-bottom:18px;padding-bottom:12px;border-bottom:2px solid var(--gold);text-transform:uppercase;letter-spacing:0.05em;">Related Articles</h6>
                    <?php foreach($related as $r): ?>
                    <a href="/newsletter.php?slug=<?= $r['slug'] ?>"
                       style="display:flex;gap:12px;padding:12px 0;border-bottom:1px solid var(--border);text-decoration:none;transition:var(--transition);"
                       onmouseover="this.style.paddingLeft='6px'" onmouseout="this.style.paddingLeft='0'">
                        <div style="width:48px;height:48px;min-width:48px;background:linear-gradient(135deg,var(--primary),#1a3a6b);border-radius:10px;display:flex;align-items:center;justify-content:center;color:var(--gold);font-size:1rem;">
                            <i class="fas fa-file-alt"></i>
                        </div>
                        <div>
                            <div style="font-size:0.83rem;font-weight:600;color:var(--primary);line-height:1.4;margin-bottom:4px;"><?= htmlspecialchars(substr($r['title'],0,65)) ?>...</div>
                            <div style="font-size:0.74rem;color:var(--text-light);"><?= readingTime($r['content']) ?></div>
                        </div>
                    </a>
                    <?php endforeach; ?>
                </div>
                <?php endif; ?>

                <!-- Categories -->
                <div style="background:white;border-radius:16px;padding:24px;box-shadow:var(--shadow);border:1px solid var(--border);">
                    <h6 style="font-size:0.88rem;font-weight:800;color:var(--primary);margin-bottom:18px;padding-bottom:12px;border-bottom:2px solid var(--gold);text-transform:uppercase;letter-spacing:0.05em;">Browse Topics</h6>
                    <?php
                    $catCount = array_count_values(array_column($posts, 'category_name'));
                    arsort($catCount);
                    foreach ($catCount as $cat => $cnt):
                        $cSlug = array_column($posts, 'category_slug', 'category_name')[$cat] ?? slugify($cat);
                    ?>
                    <a href="newsletter.php?category=<?= urlencode($cSlug) ?>"
                       style="display:flex;justify-content:space-between;align-items:center;padding:9px 0;border-bottom:1px solid var(--border);text-decoration:none;color:var(--text);font-size:0.85rem;transition:var(--transition);"
                       onmouseover="this.style.paddingLeft='6px';this.style.color='var(--primary)'"
                       onmouseout="this.style.paddingLeft='0';this.style.color='var(--text)'">
                        <span><i class="fas fa-chevron-right me-2" style="color:var(--gold);font-size:0.65rem;"></i><?= htmlspecialchars($cat) ?></span>
                        <span style="background:var(--off-white);border-radius:50px;padding:2px 10px;font-size:0.72rem;color:var(--text-light);"><?= $cnt ?></span>
                    </a>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Related in same category -->
<?php if (!empty($related)): ?>
<section style="background:var(--off-white);padding:60px 0;">
    <div class="container">
        <h4 style="font-size:1.1rem;color:var(--primary);margin-bottom:24px;">More in <?= htmlspecialchars($post['category_name']) ?></h4>
        <div class="row g-4">
            <?php foreach($related as $r): ?>
            <div class="col-md-4">
                <?php include __DIR__ . '/blog_card.inc.php'; // reuse card inline below ?>
                <a href="/newsletter.php?slug=<?= $r['slug'] ?>"
                   style="display:block;background:white;border-radius:16px;overflow:hidden;box-shadow:var(--shadow);border:1px solid var(--border);text-decoration:none;transition:var(--transition);"
                   onmouseover="this.style.transform='translateY(-6px)';this.style.boxShadow='var(--shadow-lg)'"
                   onmouseout="this.style.transform='';this.style.boxShadow='var(--shadow)'">
                    <div style="background:linear-gradient(135deg,var(--primary),#1a3a6b);height:6px;"></div>
                    <div style="padding:22px;">
                        <span style="background:rgba(212,175,55,0.12);color:var(--gold-dark);padding:4px 12px;border-radius:50px;font-size:0.72rem;font-weight:700;text-transform:uppercase;"><?= htmlspecialchars($r['category_name']) ?></span>
                        <h6 style="margin:12px 0 8px;font-size:0.95rem;color:var(--primary);line-height:1.45;"><?= htmlspecialchars($r['title']) ?></h6>
                        <p style="color:var(--text-light);font-size:0.82rem;line-height:1.7;margin-bottom:14px;"><?= htmlspecialchars(substr($r['excerpt'],0,100)) ?>...</p>
                        <span style="font-size:0.78rem;color:var(--primary);font-weight:600;">Read more <i class="fas fa-arrow-right ms-1"></i></span>
                    </div>
                </a>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<style>
.article-body h2 { font-size:1.3rem;margin:28px 0 14px;color:var(--primary);padding-top:8px; }
.article-body h3 { font-size:1.1rem;margin:22px 0 10px;color:var(--primary); }
.article-body h4 { font-size:1rem;margin:18px 0 8px;color:var(--primary); }
.article-body p  { margin-bottom:16px; }
.article-body ul,.article-body ol { padding-left:22px;margin-bottom:18px; }
.article-body li { margin-bottom:8px;line-height:1.75; }
.article-body strong { color:var(--primary); }
.article-body a  { color:var(--primary);font-weight:600;text-decoration:underline; }
.article-body table { width:100%;border-collapse:collapse;margin:18px 0;font-size:0.88rem; }
.article-body table th { background:var(--primary);color:white;padding:10px 14px; }
.article-body table td { padding:10px 14px;border-bottom:1px solid var(--border); }
.article-body table tr:nth-child(even) td { background:var(--off-white); }
.article-body blockquote { border-left:4px solid var(--gold);padding:16px 20px;background:rgba(212,175,55,0.06);border-radius:0 10px 10px 0;margin:20px 0;font-style:italic;color:var(--text-light); }
</style>

    <?php

} else {
    // ══════════════════════════════════════════════
    // BLOG LISTING PAGE
    // ══════════════════════════════════════════════

    // Filter
    $filtered = $posts;
    if ($catFilter) {
        $filtered = array_filter($filtered, fn($p) => $p['category_slug'] === $catFilter || $p['category_name'] === $catFilter);
    }
    if ($tagFilter) {
        $filtered = array_filter($filtered, fn($p) => in_array($tagFilter, $p['tags'] ?? []));
    }
    if ($search) {
        $filtered = array_filter($filtered, fn($p) =>
            stripos($p['title'], $search) !== false ||
            stripos($p['excerpt'], $search) !== false ||
            stripos($p['category_name'], $search) !== false
        );
    }
    $filtered = array_values($filtered);

    // Pagination
    $total    = count($filtered);
    $totalPages = max(1, ceil($total / $perPage));
    $pageNum    = min($pageNum, $totalPages);
    $paginated  = array_slice($filtered, ($pageNum - 1) * $perPage, $perPage);

    // Featured post (first with featured flag, or first overall)
    $featured = null;
    foreach ($posts as $p) { if ($p['featured'] ?? false) { $featured = $p; break; } }
    if (!$featured) $featured = $posts[0] ?? null;

    // Popular (top 5 by views)
    $popular = $posts;
    usort($popular, fn($a,$b) => $b['views'] - $a['views']);
    $popular = array_slice($popular, 0, 5);

    $pageTitle       = 'Legal Guide & Blog — Free Legal Articles | Nyaya Guru';
    $metaDescription = 'Free legal articles and guides covering Property, Criminal, Family, Divorce, Corporate, Cyber Crime law and more — by verified Indian lawyers.';

    require_once __DIR__ . '/includes/header.php';
    ?>

<!-- ── BLOG HERO ──────────────────────────────────── -->
<section style="background:linear-gradient(135deg,var(--primary-dark) 0%,var(--primary) 55%,#1a3a6b 100%);padding:64px 0 80px;position:relative;overflow:hidden;">
    <div style="position:absolute;inset:0;background-image:url('data:image/svg+xml,%3Csvg width=\'60\' height=\'60\' viewBox=\'0 0 60 60\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cg fill=\'%23D4AF37\' fill-opacity=\'0.04\'%3E%3Cpath d=\'M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z\'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');pointer-events:none;"></div>
    <div class="container" style="position:relative;z-index:2;">
        <div class="row align-items-center g-4">
            <div class="col-lg-7">
                <nav aria-label="breadcrumb" style="margin-bottom:18px;">
                    <ol class="breadcrumb" style="margin:0;background:transparent;">
                        <li class="breadcrumb-item"><a href="/" style="color:rgba(255,255,255,0.6);">Home</a></li>
                        <li class="breadcrumb-item active" style="color:var(--gold);">Legal Guide</li>
                    </ol>
                </nav>
                <span style="background:rgba(212,175,55,0.18);border:1px solid rgba(212,175,55,0.4);color:var(--gold);padding:6px 18px;border-radius:50px;font-size:0.75rem;font-weight:700;text-transform:uppercase;letter-spacing:0.07em;display:inline-block;margin-bottom:18px;">
                    Free Legal Knowledge
                </span>
                <h1 style="color:white;font-size:clamp(1.8rem,4vw,2.8rem);font-weight:800;line-height:1.22;margin-bottom:16px;">
                    India's Best <span style="color:var(--gold);">Legal Guide</span><br>— Written by Lawyers
                </h1>
                <p style="color:rgba(255,255,255,0.72);font-size:1rem;max-width:500px;margin-bottom:28px;line-height:1.8;">
                    Plain-language legal articles on property, criminal, family, startup and tax law — absolutely free, written by verified Indian advocates.
                </p>
                <!-- Search -->
                <form action="/newsletter.php" method="GET" style="display:flex;background:white;border-radius:14px;overflow:hidden;box-shadow:0 12px 40px rgba(0,0,0,0.25);max-width:480px;">
                    <input type="text" name="q" value="<?= htmlspecialchars($search) ?>"
                           style="flex:1;border:none;padding:14px 18px;font-size:0.9rem;color:var(--text);outline:none;"
                           placeholder="Search legal topics...">
                    <button type="submit" style="background:var(--gold);border:none;padding:14px 22px;color:var(--primary);font-size:1rem;cursor:pointer;font-weight:700;transition:var(--transition);"
                            onmouseover="this.style.background='var(--gold-dark)'"
                            onmouseout="this.style.background='var(--gold)'">
                        <i class="fas fa-search"></i>
                    </button>
                </form>
            </div>
            <div class="col-lg-5 d-none d-lg-flex justify-content-center">
                <!-- Floating stat cards -->
                <div style="position:relative;width:320px;height:220px;">
                    <div style="position:absolute;top:0;left:0;background:white;border-radius:16px;padding:18px 22px;box-shadow:0 12px 40px rgba(0,0,0,0.2);animation:float 3s ease-in-out infinite;">
                        <div style="font-size:1.8rem;font-weight:800;color:var(--primary);font-family:var(--font-heading);"><?= count($posts) ?>+</div>
                        <div style="font-size:0.8rem;color:var(--text-light);">Legal Articles</div>
                    </div>
                    <div style="position:absolute;top:50px;right:0;background:linear-gradient(135deg,var(--gold),var(--gold-dark));border-radius:16px;padding:18px 22px;box-shadow:0 12px 40px rgba(212,175,55,0.3);animation:float 3s ease-in-out infinite 1s;">
                        <div style="font-size:1.8rem;font-weight:800;color:var(--primary);font-family:var(--font-heading);">Free</div>
                        <div style="font-size:0.8rem;color:var(--primary-dark);">Always</div>
                    </div>
                    <div style="position:absolute;bottom:0;left:40px;background:white;border-radius:16px;padding:18px 22px;box-shadow:0 12px 40px rgba(0,0,0,0.15);animation:float 3s ease-in-out infinite 1.8s;">
                        <div style="font-size:1.8rem;font-weight:800;color:var(--primary);font-family:var(--font-heading);">18+</div>
                        <div style="font-size:0.8rem;color:var(--text-light);">Legal Topics</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Wave -->
    <svg viewBox="0 0 1440 48" xmlns="http://www.w3.org/2000/svg" style="position:absolute;bottom:-1px;left:0;width:100%;" preserveAspectRatio="none">
        <path d="M0,24 C480,48 960,0 1440,24 L1440,48 L0,48 Z" fill="#f8f9fc"/>
    </svg>
</section>

<!-- ── CATEGORY FILTER TABS ──────────────────────── -->
<div style="background:var(--off-white);padding:20px 0;border-bottom:1px solid var(--border);position:sticky;top:68px;z-index:98;">
    <div class="container">
        <div style="display:flex;gap:8px;overflow-x:auto;padding-bottom:4px;scrollbar-width:thin;">

            <a href="<?= SITE_URL ?>/newsletter.php<?= $search ? '?q='.urlencode($search) : '' ?>"
               style="white-space:nowrap;padding:9px 20px;border-radius:50px;font-size:0.82rem;font-weight:700;text-decoration:none;transition:var(--transition);<?= !$catFilter && !$tagFilter ? 'background:var(--primary);color:white;' : 'background:white;color:var(--text-light);border:1px solid var(--border);' ?>">
                All Articles
                <span style="font-size:0.72rem;opacity:0.7;">
                    (<?= count($posts) ?>)
                </span>
            </a>

            <?php
            $catCounts = [];

            foreach ($posts as $p) {
                $catCounts[$p['category_name']][$p['category_slug']] =
                    ($catCounts[$p['category_name']][$p['category_slug']] ?? 0) + 1;
            }

            foreach ($catCounts as $cat => $slugs):

                $cSlug = array_key_first($slugs);
                $cnt   = array_sum($slugs);
                $isActive = $catFilter === $cSlug;
            ?>

            <a href="<?= SITE_URL ?>/newsletter.php?category=<?= urlencode($cSlug) ?><?= $search ? '&q='.urlencode($search) : '' ?>"
               style="white-space:nowrap;padding:9px 20px;border-radius:50px;font-size:0.82rem;font-weight:700;text-decoration:none;transition:var(--transition);<?= $isActive ? 'background:var(--primary);color:white;' : 'background:white;color:var(--text-light);border:1px solid var(--border);' ?>">

                <?= htmlspecialchars($cat) ?>

                <span style="font-size:0.72rem;opacity:0.7;">
                    (<?= $cnt ?>)
                </span>

            </a>

            <?php endforeach; ?>

        </div>
    </div>
</div>

<!-- ── MAIN CONTENT ──────────────────────────────── -->
<section style="background:var(--off-white);padding:52px 0 80px;">
    <div class="container">

        <?php if ($search || $catFilter || $tagFilter): ?>
        <!-- Filter Info Bar -->
        <div style="background:white;border-radius:12px;padding:14px 20px;margin-bottom:28px;display:flex;align-items:center;justify-content:space-between;border:1px solid var(--border);flex-wrap:wrap;gap:10px;">
            <span style="font-size:0.88rem;color:var(--text);">
                <?php if ($search): ?>Showing results for: <strong>"<?= htmlspecialchars($search) ?>"</strong><?php endif; ?>
                <?php if ($catFilter): ?><?= $search ? ' in ' : 'Category: ' ?><strong><?= htmlspecialchars(slugToTitle($catFilter)) ?></strong><?php endif; ?>
                <?php if ($tagFilter): ?>&nbsp;· Tag: <strong>#<?= htmlspecialchars($tagFilter) ?></strong><?php endif; ?>
                &nbsp;— <span style="color:var(--text-light);"><?= $total ?> article<?= $total !== 1 ? 's' : '' ?> found</span>
            </span>
            <a href="<?= SITE_URL ?>/newsletter.php" style="font-size:0.82rem;color:var(--primary);font-weight:600;text-decoration:none;display:flex;align-items:center;gap:5px;">
                <i class="fas fa-times-circle"></i> Clear filters
            </a>
        </div>
        <?php endif; ?>

        <div class="row g-5">
            <!-- Article Grid -->
            <div class="col-lg-8">
                <?php if (empty($paginated)): ?>
                <div style="text-align:center;padding:80px 0;">
                    <i class="fas fa-search" style="font-size:3rem;color:var(--border);margin-bottom:16px;display:block;"></i>
                    <h5 style="color:var(--primary);">No articles found</h5>
                    <p style="color:var(--text-light);font-size:0.9rem;margin-bottom:24px;">Try different search terms or browse all articles.</p>
                    <a href="<?= SITE_URL ?>/newsletter.php" class="btn btn-primary-dark">View All Articles</a>
                </div>

                <?php elseif (!$catFilter && !$tagFilter && !$search && $pageNum === 1 && $featured): ?>
                <!-- Featured Article (only on first page, no filters) -->
                <a href="<?= SITE_URL ?>/newsletter.php?slug=<?= $featured['slug'] ?>"
                   style="display:block;background:white;border-radius:20px;overflow:hidden;box-shadow:var(--shadow-lg);border:1px solid var(--border);margin-bottom:28px;text-decoration:none;transition:var(--transition);"
                   onmouseover="this.style.transform='translateY(-4px)';this.style.boxShadow='0 24px 60px rgba(10,35,66,0.15)'"
                   onmouseout="this.style.transform='';this.style.boxShadow='var(--shadow-lg)'">
                    <div style="background:linear-gradient(135deg,var(--primary),#1a3a6b);padding:44px 40px;position:relative;overflow:hidden;">
                        <div style="position:absolute;top:-30px;right:-30px;width:200px;height:200px;background:rgba(212,175,55,0.1);border-radius:50%;"></div>
                        <span style="background:var(--gold);color:var(--primary);padding:5px 14px;border-radius:50px;font-size:0.72rem;font-weight:800;text-transform:uppercase;letter-spacing:0.06em;">⭐ Featured</span>
                        <h2 style="color:white;font-size:clamp(1.2rem,2.5vw,1.7rem);margin:16px 0 12px;font-weight:800;line-height:1.3;position:relative;z-index:1;">
                            <?= htmlspecialchars($featured['title']) ?>
                        </h2>
                        <p style="color:rgba(255,255,255,0.7);font-size:0.9rem;line-height:1.75;margin-bottom:20px;max-width:560px;position:relative;z-index:1;">
                            <?= htmlspecialchars($featured['excerpt']) ?>
                        </p>
                        <div style="display:flex;align-items:center;gap:16px;flex-wrap:wrap;position:relative;z-index:1;">
                            <span style="background:rgba(255,255,255,0.12);color:rgba(255,255,255,0.8);padding:6px 16px;border-radius:50px;font-size:0.78rem;">
                                <i class="fas fa-tag me-1" style="color:var(--gold);"></i><?= htmlspecialchars($featured['category_name']) ?>
                            </span>
                            <span style="color:rgba(255,255,255,0.55);font-size:0.8rem;">
                                <i class="fas fa-clock me-1"></i><?= readingTime($featured['content']) ?>
                            </span>
                            <span style="color:rgba(255,255,255,0.55);font-size:0.8rem;">
                                <i class="fas fa-eye me-1"></i><?= number_format($featured['views']) ?> views
                            </span>
                            <span style="background:var(--gold);color:var(--primary);padding:8px 20px;border-radius:50px;font-weight:700;font-size:0.82rem;margin-left:auto;">
                                Read Article <i class="fas fa-arrow-right ms-1"></i>
                            </span>
                        </div>
                    </div>
                </a>

                <!-- Rest of articles grid -->
                <div class="row g-4">
                    <?php foreach(array_filter($paginated, fn($p) => $p['slug'] !== $featured['slug']) as $post): ?>
                   
                    <div class="col-md-6 fade-up">
                        <a href="newsletter.php?slug=<?= $post['slug'] ?>"
                           style="display:flex;flex-direction:column;height:100%;background:white;border-radius:16px;overflow:hidden;box-shadow:var(--shadow);border:1px solid var(--border);text-decoration:none;transition:var(--transition);"
                           onmouseover="this.style.transform='translateY(-5px)';this.style.boxShadow='var(--shadow-lg)';this.style.borderColor='var(--gold)'"
                           onmouseout="this.style.transform='';this.style.boxShadow='var(--shadow)';this.style.borderColor='var(--border)'">
                            <!-- Colour band -->
                            <div style="height:6px;background:linear-gradient(90deg,var(--primary),var(--gold));"></div>
                            <div style="padding:22px;flex:1;display:flex;flex-direction:column;">
                                <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:14px;flex-wrap:wrap;gap:6px;">
                                    <span style="background:rgba(212,175,55,0.1);color:var(--gold-dark);border:1px solid rgba(212,175,55,0.25);padding:4px 12px;border-radius:50px;font-size:0.7rem;font-weight:700;text-transform:uppercase;">
                                        <?= htmlspecialchars($post['category_name']) ?>
                                    </span>
                                    <span style="font-size:0.72rem;color:var(--text-light);"><?= timeAgo($post['published_at']) ?></span>
                                </div>
                                <h5 style="font-size:0.97rem;color:var(--primary);line-height:1.42;margin-bottom:10px;font-weight:700;">
                                    <?= htmlspecialchars($post['title']) ?>
                                </h5>
                                <p style="font-size:0.83rem;color:var(--text-light);line-height:1.72;flex:1;margin-bottom:16px;">
                                    <?= htmlspecialchars(substr($post['excerpt'], 0, 110)) ?>...
                                </p>
                                <div style="display:flex;align-items:center;justify-content:space-between;padding-top:14px;border-top:1px solid var(--border);">
                                    <div style="display:flex;align-items:center;gap:8px;">
                                        <div style="width:28px;height:28px;background:var(--primary);border-radius:50%;display:flex;align-items:center;justify-content:center;color:var(--gold);font-size:0.65rem;font-weight:700;">
                                            <?= strtoupper(substr($post['author'],0,2)) ?>
                                        </div>
                                        <span style="font-size:0.75rem;color:var(--text-light);"><?= htmlspecialchars(explode(' ',$post['author'])[0].' '.explode(' ',$post['author'])[1]) ?></span>
                                    </div>
                                    <span style="font-size:0.75rem;color:var(--text-light);">
                                        <i class="fas fa-clock me-1"></i><?= readingTime($post['content']) ?>
                                        &nbsp;·&nbsp;
                                        <i class="fas fa-eye me-1"></i><?= number_format($post['views']) ?>
                                    </span>
                                </div>
                            </div>
                        </a>
                    </div>
                    <?php endforeach; ?>
                </div>

                <?php else: ?>
                <!-- Standard grid (filtered / paginated) -->
                <div class="row g-4">
                    <?php foreach($paginated as $post): ?>
                    <div class="col-md-6 fade-up">
                        <a href="/newsletter.php?slug=<?= $post['slug'] ?>"
                           style="display:flex;flex-direction:column;height:100%;background:white;border-radius:16px;overflow:hidden;box-shadow:var(--shadow);border:1px solid var(--border);text-decoration:none;transition:var(--transition);"
                           onmouseover="this.style.transform='translateY(-5px)';this.style.boxShadow='var(--shadow-lg)';this.style.borderColor='var(--gold)'"
                           onmouseout="this.style.transform='';this.style.boxShadow='var(--shadow)';this.style.borderColor='var(--border)'">
                            <div style="height:6px;background:linear-gradient(90deg,var(--primary),var(--gold));"></div>
                            <div style="padding:22px;flex:1;display:flex;flex-direction:column;">
                                <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:14px;flex-wrap:wrap;gap:6px;">
                                    <span style="background:rgba(212,175,55,0.1);color:var(--gold-dark);border:1px solid rgba(212,175,55,0.25);padding:4px 12px;border-radius:50px;font-size:0.7rem;font-weight:700;text-transform:uppercase;">
                                        <?= htmlspecialchars($post['category_name']) ?>
                                    </span>
                                    <span style="font-size:0.72rem;color:var(--text-light);"><?= timeAgo($post['published_at']) ?></span>
                                </div>
                                <h5 style="font-size:0.97rem;color:var(--primary);line-height:1.42;margin-bottom:10px;font-weight:700;">
                                    <?= htmlspecialchars($post['title']) ?>
                                </h5>
                                <p style="font-size:0.83rem;color:var(--text-light);line-height:1.72;flex:1;margin-bottom:16px;">
                                    <?= htmlspecialchars(substr($post['excerpt'], 0, 110)) ?>...
                                </p>
                                <div style="display:flex;align-items:center;justify-content:space-between;padding-top:14px;border-top:1px solid var(--border);">
                                    <div style="display:flex;align-items:center;gap:8px;">
                                        <div style="width:28px;height:28px;background:var(--primary);border-radius:50%;display:flex;align-items:center;justify-content:center;color:var(--gold);font-size:0.65rem;font-weight:700;">
                                            <?= strtoupper(substr($post['author'],0,2)) ?>
                                        </div>
                                        <span style="font-size:0.75rem;color:var(--text-light);"><?= htmlspecialchars($post['author']) ?></span>
                                    </div>
                                    <span style="font-size:0.75rem;color:var(--text-light);">
                                        <i class="fas fa-clock me-1"></i><?= readingTime($post['content']) ?>
                                    </span>
                                </div>
                            </div>
                        </a>
                    </div>
                    <?php endforeach; ?>
                </div>
                <?php endif; ?>

                <!-- Pagination -->
                <?php if ($totalPages > 1): ?>
                <nav style="margin-top:40px;" aria-label="Blog pagination">
                    <ul class="pagination justify-content-center" style="gap:6px;">
                        <?php if ($pageNum > 1): ?>
                        <li class="page-item">
                            <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $pageNum - 1])) ?>"
                               style="border-radius:10px;border:1px solid var(--border);color:var(--primary);padding:10px 16px;">
                                <i class="fas fa-chevron-left"></i>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php for($p = 1; $p <= $totalPages; $p++): ?>
                        <li class="page-item <?= $p === $pageNum ? 'active' : '' ?>">
                            <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $p])) ?>"
                               style="border-radius:10px;<?= $p === $pageNum ? 'background:var(--primary);border-color:var(--primary);color:white;' : 'border:1px solid var(--border);color:var(--primary);' ?>padding:10px 16px;">
                                <?= $p ?>
                            </a>
                        </li>
                        <?php endfor; ?>
                        <?php if ($pageNum < $totalPages): ?>
                        <li class="page-item">
                            <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $pageNum + 1])) ?>"
                               style="border-radius:10px;border:1px solid var(--border);color:var(--primary);padding:10px 16px;">
                                <i class="fas fa-chevron-right"></i>
                            </a>
                        </li>
                        <?php endif; ?>
                    </ul>
                </nav>
                <?php endif; ?>
            </div>

            <!-- Sidebar -->
            <div class="col-lg-4">

                <!-- Search box (sidebar) -->
                <div style="background:white;border-radius:16px;padding:22px;box-shadow:var(--shadow);border:1px solid var(--border);margin-bottom:24px;">
                    <h6 style="font-size:0.85rem;font-weight:800;color:var(--primary);margin-bottom:14px;text-transform:uppercase;letter-spacing:0.06em;">Search Articles</h6>
                    <form action="/newsletter.php" method="GET">
                        <div style="display:flex;border:1.5px solid var(--border);border-radius:10px;overflow:hidden;">
                            <input type="text" name="q" value="<?= htmlspecialchars($search) ?>"
                                   style="flex:1;border:none;padding:11px 14px;font-size:0.88rem;outline:none;color:var(--text);"
                                   placeholder="Search legal topics...">
                            <button style="background:var(--primary);border:none;padding:11px 16px;color:var(--gold);cursor:pointer;">
                                <i class="fas fa-search"></i>
                            </button>
                        </div>
                    </form>
                </div>

                <!-- Popular articles -->
                <div style="background:white;border-radius:16px;padding:22px;box-shadow:var(--shadow);border:1px solid var(--border);margin-bottom:24px;">
                    <h6 style="font-size:0.85rem;font-weight:800;color:var(--primary);margin-bottom:18px;padding-bottom:12px;border-bottom:2px solid var(--gold);text-transform:uppercase;letter-spacing:0.06em;">🔥 Most Popular</h6>
                    <?php foreach($popular as $i => $p): ?>
                   <a href="<?= SITE_URL ?>/newsletter.php?slug=<?= $p['slug'] ?>"
   style="display:flex;gap:12px;padding:12px 0;border-bottom:1px solid var(--border);text-decoration:none;transition:var(--transition);"
   onmouseover="this.style.paddingLeft='6px'"
   onmouseout="this.style.paddingLeft='0'">

    <span style="width:28px;height:28px;min-width:28px;background:<?= $i === 0 ? 'var(--gold)' : 'var(--off-white)' ?>;border-radius:8px;display:flex;align-items:center;justify-content:center;font-weight:800;font-size:0.75rem;color:<?= $i === 0 ? 'var(--primary)' : 'var(--text-light)' ?>;font-family:var(--font-heading);">
        <?= $i + 1 ?>
    </span>

    <div>

        <div style="font-size:0.82rem;font-weight:600;color:var(--primary);line-height:1.42;margin-bottom:3px;">
            <?= htmlspecialchars(substr($p['title'],0,58)) ?>...
        </div>

        <span style="font-size:0.72rem;color:var(--text-light);">
            <i class="fas fa-eye me-1"></i>
            <?= number_format($p['views']) ?>
        </span>

    </div>

</a>
                    <?php endforeach; ?>
                </div>

                <!-- Categories -->
                <div style="background:white;border-radius:16px;padding:22px;box-shadow:var(--shadow);border:1px solid var(--border);margin-bottom:24px;">
                    <h6 style="font-size:0.85rem;font-weight:800;color:var(--primary);margin-bottom:18px;padding-bottom:12px;border-bottom:2px solid var(--gold);text-transform:uppercase;letter-spacing:0.06em;">Browse by Topic</h6>
                    <?php
                    foreach ($catCounts as $cat => $slugData):
                        $cSlug = array_key_first($slugData);
                        $cnt   = array_sum($slugData);
                        $isA   = $catFilter === $cSlug;
                    ?>
                   <a href="<?= SITE_URL ?>/newsletter.php?category=<?= urlencode($cSlug) ?>"
   style="display:flex;justify-content:space-between;align-items:center;padding:9px 10px;border-radius:8px;text-decoration:none;margin-bottom:2px;transition:var(--transition);<?= $isA ? 'background:var(--primary);' : '' ?>"
   onmouseover="<?= !$isA ? 'this.style.background=\'var(--off-white)\'' : '' ?>"
   onmouseout="<?= !$isA ? 'this.style.background=\'\'' : '' ?>">

    <span style="font-size:0.85rem;font-weight:500;<?= $isA ? 'color:white;' : 'color:var(--text);' ?>">

        <i class="fas fa-chevron-right me-2"
           style="font-size:0.6rem;<?= $isA ? 'color:var(--gold);' : 'color:var(--gold-dark);' ?>">
        </i>

        <?= htmlspecialchars($cat) ?>

    </span>

    <span style="padding:2px 10px;border-radius:50px;font-size:0.72rem;font-weight:600;<?= $isA ? 'background:rgba(255,255,255,0.15);color:rgba(255,255,255,0.8);' : 'background:var(--off-white);color:var(--text-light);' ?>">

        <?= $cnt ?>

    </span>

</a>
                    <?php endforeach; ?>
                </div>

                <!-- Tags cloud -->
                <div style="background:white;border-radius:16px;padding:22px;box-shadow:var(--shadow);border:1px solid var(--border);margin-bottom:24px;">
                    <h6 style="font-size:0.85rem;font-weight:800;color:var(--primary);margin-bottom:18px;padding-bottom:12px;border-bottom:2px solid var(--gold);text-transform:uppercase;letter-spacing:0.06em;">Popular Tags</h6>
                    <div style="display:flex;flex-wrap:wrap;gap:7px;">
                        <?php foreach($allTags as $tag): ?>
                        <a href="<?= SITE_URL ?>/newsletter.php?tag=<?= urlencode($tag) ?>"
   style="padding:6px 14px;border-radius:50px;font-size:0.78rem;font-weight:600;text-decoration:none;transition:var(--transition);<?= $tagFilter === $tag ? 'background:var(--primary);color:white;' : 'background:var(--off-white);color:var(--text);border:1px solid var(--border);' ?>"
   onmouseover="<?= $tagFilter !== $tag ? 'this.style.background=\'var(--primary)\';this.style.color=\'white\';this.style.borderColor=\'var(--primary)\'' : '' ?>"
   onmouseout="<?= $tagFilter !== $tag ? 'this.style.background=\'var(--off-white)\';this.style.color=\'var(--text)\';this.style.borderColor=\'var(--border)\'' : '' ?>">

    #<?= htmlspecialchars($tag) ?>

</a>
                        <?php endforeach; ?>
                    </div>
                </div>

                <!-- CTA -->
                <div style="background:linear-gradient(135deg,var(--primary),#1a3a6b);border-radius:16px;padding:28px;text-align:center;">
                    <i class="fas fa-user-tie" style="font-size:2rem;color:var(--gold);margin-bottom:14px;display:block;"></i>
                    <h5 style="color:white;font-size:1rem;margin-bottom:8px;">Need Legal Help?</h5>
                    <p style="color:rgba(255,255,255,0.65);font-size:0.82rem;margin-bottom:18px;">Articles are free — but nothing beats personalised legal advice from a verified advocate.</p>
                    <a href="lawyers.php" style="display:block;background:var(--gold);color:var(--primary);padding:12px;border-radius:10px;font-weight:700;font-size:0.88rem;text-decoration:none;margin-bottom:8px;">
                        <i class="fas fa-comments me-1"></i>Talk to a Lawyer
                    </a>
                    <a href="<?= SITE_URL ?>/register-lawyer.php"
   style="display:block;background:rgba(255,255,255,0.08);color:rgba(255,255,255,0.8);padding:11px;border-radius:10px;font-weight:600;font-size:0.82rem;text-decoration:none;border:1px solid rgba(255,255,255,0.12);">

    <i class="fas fa-user-tie me-1"></i>
    Register as Lawyer

</a>
                </div>
            </div>
        </div>
    </div>
</section>

<?php } // end listing / single ?>

<?php require_once __DIR__ . '/includes/footer.php'; ?>