{% load static %}
<!DOCTYPE html>
<html lang="en-GB" class="enhanced-typography">
<head>
    <title>{% block header-title %}Blog | TPSCheck{% endblock header-title %}</title>

    {% include "partials/head.html" %}

    {# Bootstrap 5 CSS for blog layout #}
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">

    {% block header-resource-extra %}{% endblock header-resource-extra %}

    {# Blog-specific styles - extracted to blog.css for consistency #}
    <link href="{% static 'css/blog.css' %}" rel="stylesheet" type="text/css" />
    <style nonce="{{ request.csp_nonce }}">
        /* All blog styles moved to blog.css */
    </style>
    <!-- The following duplicate block is kept temporarily for safety.
         TODO: Remove once blog.css is confirmed loading correctly. -->
    <style nonce="{{ request.csp_nonce }}">
        .navbar {
            z-index: 2000 !important;
            width: 100% !important;
            -webkit-backdrop-filter: blur(5px) !important;
            backdrop-filter: blur(5px) !important;
            background-color: rgba(255, 255, 255, 0.95) !important;
            position: sticky !important;
            top: 0 !important;
            flex-wrap: nowrap !important;
            padding: 0 !important;
            min-height: 70px;
        }

        .navbar .navbar-space {
            height: 10px !important;
            display: block !important;
        }

        .navbar .navbar-inner {
            z-index: 5 !important;
            width: 100% !important;
            background-color: transparent !important;
            margin-left: auto !important;
            margin-right: auto !important;
            display: block !important;
        }

        .navbar .container-copy {
            max-width: 1290px !important;
            margin: 0 auto !important;
            padding: 0 10px !important;
        }

        @media (min-width: 1440px) {
            .navbar .container-copy {
                max-width: 1350px !important;
            }
        }

        .navbar .navbar-wrapper {
            justify-content: space-between !important;
            align-items: center !important;
            display: flex !important;
        }

        .navbar .nav-menu-wrapper {
            display: flex !important;
            width: 100% !important;
        }

        .navbar .nav-menu-flex {
            display: flex !important;
            align-items: center !important;
            width: 100% !important;
            min-height: 60px;
            gap: 0 !important;
        }

        .navbar .brand {
            flex-shrink: 0 !important;
        }

        .navbar .nav-menu {
            display: flex !important;
            align-items: center !important;
            list-style: none !important;
            margin: 0 !important;
            padding: 0 !important;
            gap: 40px !important;
            flex: 1 !important;
            justify-content: flex-start !important;
            margin-left: 40px !important;
            margin-right: 1rem !important;
        }

        .navbar .nav-menu li {
            margin: 0 !important;
            padding: 0 !important;
        }

        /* Ensure navbar styling is consistent with homepage - override Bootstrap 5 */
        .navbar .nav-link {
            font-weight: 500 !important;
            color: #343f52 !important;
            padding: 0.5rem 0 !important;
            background: none !important;
        }

        .navbar .nav-link:hover,
        .navbar .nav-link:focus {
            color: #667eea !important;
            background: none !important;
        }

        .navbar .navbar-button-wrapper {
            display: flex !important;
            align-items: center !important;
            flex-shrink: 0 !important;
        }

        .navbar .navbar-button-wrapper:first-of-type {
            margin-left: auto !important;
        }

        .navbar .navbar-button-wrapper:not(:last-child) {
            margin-right: 0.75rem !important;
        }

        .navbar .navbar-button-wrapper .btn {
            margin: 0 !important;
            white-space: nowrap !important;
            display: inline-flex !important;
            align-items: center !important;
            justify-content: center !important;
            text-decoration: none !important;
            transition: all 0.2s ease !important;
            height: auto !important;
            line-height: 1.5 !important;
            vertical-align: middle !important;
        }

        .navbar .navbar-button-wrapper .btn.btn-sm {
            padding: 0.5rem 1rem !important;
            font-size: 0.875rem !important;
            border-radius: 0.5rem !important;
            min-height: 36px !important;
        }

        .navbar .navbar-button-wrapper .btn-ghost {
            font-weight: 500 !important;
            background: transparent !important;
            color: #343f52 !important;
            border: 1px solid #e2e8f0 !important;
        }

        .navbar .navbar-button-wrapper .btn-ghost:hover {
            background: #f8fafc !important;
            border-color: #cbd5e1 !important;
            color: #667eea !important;
            transform: translateY(-1px) !important;
        }

        .navbar .navbar-button-wrapper .btn-primary {
            font-weight: 500 !important;
            background: var(--gradient-primary) !important;
            color: white !important;
            border: none !important;
            box-shadow: 0 2px 4px rgba(102, 126, 234, 0.2) !important;
        }

        .navbar .navbar-button-wrapper .btn-primary:hover {
            background: var(--gradient-primary-hover) !important;
            transform: translateY(-1px) !important;
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
            color: white !important;
        }

        .navbar .navbar-button-wrapper .btn-primary:active {
            transform: translateY(0) !important;
        }

        /* Blog Sub-Header */
        .blog-subheader {
            background: white;
            border-bottom: 1px solid var(--color-border);
            position: sticky;
            top: 70px;
            z-index: 999;
        }

        .blog-subheader-container {
            max-width: 1290px;
            margin: 0 auto;
            padding: 0 10px;
            display: flex;
            align-items: center;
            gap: var(--spacing-xl);
            height: 56px;
            box-sizing: border-box;
        }

        @media (min-width: 1440px) {
            .blog-subheader-container {
                max-width: 1350px;
            }
        }

        @media (max-width: 991px) {
            .blog-subheader-container {
                padding: 0 20px;
                gap: var(--spacing-md);
            }
        }

        .blog-subheader-brand {
            font-size: 18px;
            font-weight: 800;
            color: var(--color-text-primary);
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: var(--spacing-xs);
            flex-shrink: 0;
            white-space: nowrap;
        }

        .blog-subheader-brand:hover {
            color: var(--color-primary);
        }

        .blog-subheader-brand .brand-highlight {
            color: var(--color-primary);
        }

        .blog-subheader-nav {
            display: flex;
            align-items: center;
            gap: var(--spacing-md);
            overflow-x: auto;
            scrollbar-width: none;
            -ms-overflow-style: none;
            flex: 1;
        }

        .blog-subheader-nav::-webkit-scrollbar {
            display: none;
        }

        .blog-subheader-link {
            font-size: 14px;
            font-weight: 500;
            color: var(--color-text-secondary);
            text-decoration: none;
            white-space: nowrap;
            padding: var(--spacing-xs) var(--spacing-sm);
            border-radius: var(--radius-md);
            transition: all 0.2s ease;
        }

        .blog-subheader-link:hover {
            color: var(--color-primary);
            background: rgba(102, 126, 234, 0.1);
        }

        .blog-subheader-link.active {
            color: var(--color-primary);
            font-weight: 600;
        }

        /* Blog Main Container */
        .blog-main {
            background: #f8fafc;
            min-height: calc(100vh - 136px);
            padding-top: 0;
        }

        .blog-container {
            width: 100%;
            max-width: 1290px;
            margin: 0 auto;
            padding: var(--spacing-xl) 10px;
        }

        @media (min-width: 1440px) {
            .blog-container {
                max-width: 1350px;
            }
        }

        @media (max-width: 991px) {
            .blog-container {
                padding: var(--spacing-xl) 20px;
            }
        }

        /* Featured Article Hero */
        .featured-article {
            position: relative;
            border-radius: var(--radius-xl);
            overflow: hidden;
            margin-bottom: var(--spacing-xl);
            min-height: 400px;
            display: flex;
            align-items: flex-end;
            text-decoration: none;
            transition: all 0.3s ease;
        }

        .featured-article:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
        }

        .featured-article-bg {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-size: contain;
            background-position: center;
            background-repeat: no-repeat;
            background-color: #f5f5f5;
            z-index: 1;
        }

        .featured-article-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.4) 50%, rgba(0, 0, 0, 0.2) 100%);
            z-index: 2;
        }

        .featured-article-content {
            position: relative;
            z-index: 3;
            padding: var(--spacing-2xl);
            width: 100%;
            max-width: 700px;
        }

        .featured-article-meta {
            display: flex;
            align-items: center;
            gap: var(--spacing-md);
            margin-bottom: var(--spacing-md);
        }

        .featured-article-category {
            background: var(--gradient-primary);
            color: white;
            padding: 6px 12px;
            border-radius: var(--radius-sm);
            font-size: 12px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .featured-article-date {
            color: rgba(255, 255, 255, 0.8);
            font-size: 14px;
        }

        .featured-article-readtime {
            color: rgba(255, 255, 255, 0.8);
            font-size: 14px;
        }

        .featured-article-title {
            font-size: clamp(28px, 4vw, 40px);
            font-weight: 800;
            color: white;
            margin: 0 0 var(--spacing-md) 0;
            line-height: 1.2;
            letter-spacing: -0.02em;
        }

        .featured-article-intro {
            font-size: 16px;
            color: rgba(255, 255, 255, 0.85);
            line-height: 1.6;
            margin: 0;
        }

        /* Two-Column Row (Articles 2 & 3) */
        .articles-row-2 {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: var(--spacing-lg);
            margin-bottom: var(--spacing-xl);
        }

        /* Three-Column Grid (Articles 4+) */
        .articles-row-3 {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: var(--spacing-lg);
        }

        /* Article Cards */
        .article-card {
            background: white;
            border-radius: var(--radius-lg);
            overflow: hidden;
            text-decoration: none;
            transition: all 0.3s ease;
            display: flex;
            flex-direction: column;
            border: 1px solid var(--color-border-light);
        }

        .article-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1);
            border-color: var(--color-primary);
        }

        .article-card-image-wrapper {
            width: 100%;
            height: 220px;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
        }

        .article-card-image {
            max-width: 100%;
            max-height: 100%;
            width: auto;
            height: auto;
            object-fit: contain;
        }

        .article-card-placeholder {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #8b5cf6 100%);
            color: rgba(255, 255, 255, 0.3);
            font-size: 80px;
            font-weight: 800;
        }

        .article-card-body {
            padding: var(--spacing-lg);
            flex: 1;
            display: flex;
            flex-direction: column;
        }

        .article-card-meta {
            display: flex;
            align-items: center;
            gap: var(--spacing-sm);
            margin-bottom: var(--spacing-sm);
            font-size: 13px;
        }

        .article-card-category {
            color: var(--color-primary);
            font-weight: 600;
        }

        .article-card-date {
            color: var(--color-text-tertiary);
        }

        .article-card-title {
            font-size: 18px;
            font-weight: 700;
            color: var(--color-text-primary);
            margin: 0 0 var(--spacing-sm) 0;
            line-height: 1.3;
            letter-spacing: -0.01em;
        }

        .article-card-intro {
            font-size: 14px;
            color: var(--color-text-secondary);
            line-height: 1.6;
            flex: 1;
            margin: 0;
        }

        /* Article detail styles */
        .article-detail .image img {
            max-width: 100%;
            height: auto;
            border-radius: var(--radius-lg);
        }

        .article-detail .title {
            font-size: clamp(28px, 5vw, 40px);
            font-weight: 800;
            color: var(--color-text-primary);
            margin: var(--spacing-lg) 0 var(--spacing-sm) 0;
            letter-spacing: -0.02em;
            line-height: 1.2;
        }

        .article-detail .publish {
            color: var(--color-text-tertiary);
            font-size: 14px;
            margin-bottom: var(--spacing-lg);
        }

        .article-detail .introduction {
            font-size: 18px;
            color: var(--color-text-secondary);
            line-height: 1.7;
            margin-bottom: var(--spacing-lg);
            padding-bottom: var(--spacing-lg);
            border-bottom: 1px solid var(--color-border);
        }

        .article-detail .content {
            font-size: 16px;
            line-height: 1.8;
            color: var(--color-text-primary);
        }

        .article-detail .content h2 {
            font-size: 24px;
            font-weight: 700;
            margin-top: var(--spacing-2xl);
            margin-bottom: var(--spacing-md);
        }

        .article-detail .content h3 {
            font-size: 20px;
            font-weight: 700;
            margin-top: var(--spacing-xl);
            margin-bottom: var(--spacing-sm);
        }

        .article-detail .content p {
            margin-bottom: var(--spacing-md);
        }

        .article-detail .content img {
            max-width: 100%;
            height: auto;
            border-radius: var(--radius-md);
            margin: var(--spacing-lg) 0;
        }

        .article-detail .content pre {
            background: #1e293b;
            color: #e2e8f0;
            border-radius: var(--radius-md);
            padding: var(--spacing-lg);
            overflow-x: auto;
        }

        .article-detail .content code {
            font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
            font-size: 14px;
        }

        .article-detail .content a {
            color: var(--color-primary);
            text-decoration: none;
            font-weight: 500;
        }

        /* Detail sidebar cards */
        .detail-sidebar .card {
            background: white;
            border: 1px solid var(--color-border);
            border-radius: var(--radius-lg);
            overflow: hidden;
            margin-bottom: var(--spacing-md);
        }

        .detail-sidebar .card-header {
            background: var(--color-bg-secondary);
            border-bottom: 1px solid var(--color-border);
            font-weight: 700;
            font-size: 14px;
            padding: var(--spacing-md);
        }

        .detail-sidebar .list-group-item {
            border: none;
            padding: var(--spacing-sm) var(--spacing-md);
            border-bottom: 1px solid var(--color-border-light);
            font-size: 14px;
        }

        .detail-sidebar .list-group-item:last-child {
            border-bottom: none;
        }

        .detail-sidebar .list-group-item a {
            color: var(--color-text-secondary);
            text-decoration: none;
        }

        .detail-sidebar .list-group-item a:hover {
            color: var(--color-primary);
        }

        /* Tags */
        .badge.btn-primary,
        .blog-tag {
            background: var(--gradient-primary);
            border: none;
            padding: 6px 12px;
            border-radius: var(--radius-sm);
            font-size: 12px;
            font-weight: 600;
            color: white;
            text-decoration: none;
            display: inline-block;
            margin: 2px;
        }

        /* Pagination */
        .pagination {
            gap: 4px;
            margin-top: var(--spacing-xl);
            justify-content: center;
        }

        .pagination .page-link {
            border-radius: var(--radius-md);
            border: 1px solid var(--color-border);
            color: var(--color-text-secondary);
            padding: 8px 14px;
            font-weight: 500;
        }

        .pagination .page-link:hover {
            background: var(--color-primary);
            border-color: var(--color-primary);
            color: white;
        }

        .pagination .page-item.active .page-link {
            background: var(--gradient-primary);
            border-color: var(--color-primary);
        }

        /* Category/Author page headers */
        .page-header {
            margin-bottom: var(--spacing-xl);
        }

        .page-title {
            font-size: clamp(32px, 5vw, 48px);
            font-weight: 900;
            color: var(--color-text-primary);
            margin: 0 0 var(--spacing-sm) 0;
            letter-spacing: -0.02em;
        }

        .page-title .highlight {
            color: var(--color-primary);
        }

        .page-description {
            font-size: 18px;
            color: var(--color-text-secondary);
            line-height: 1.6;
        }

        /* Breadcrumbs */
        .breadcrumb {
            background: transparent;
            padding: 0;
            margin-bottom: var(--spacing-md);
            font-size: 14px;
        }

        .breadcrumb-item a {
            color: var(--color-primary);
            text-decoration: none;
            font-weight: 500;
        }

        .breadcrumb-item.active {
            color: var(--color-text-tertiary);
        }

        /* Override lotus default styles */
        .list.container {
            padding: 0;
            max-width: 100%;
        }

        .article.card {
            background: white;
            border: 1px solid var(--color-border);
            border-radius: var(--radius-lg);
            overflow: hidden;
            transition: all 0.3s ease;
        }

        .article.card:hover {
            transform: translateY(-4px);
            box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1);
        }

        /* Responsive */
        @media (max-width: 1024px) {
            .articles-row-3 {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        @media (max-width: 991px) {
            .navbar .nav-menu {
                margin-right: 0.5rem !important;
            }

            .navbar .navbar-button-wrapper:not(:last-child) {
                margin-right: 0.5rem !important;
            }

            .navbar .navbar-button-wrapper .btn.btn-sm {
                padding: 0.4rem 0.8rem !important;
                font-size: 0.8125rem !important;
            }
        }

        @media (max-width: 768px) {
            .blog-subheader {
                top: 64px;
            }

            .blog-subheader-container {
                gap: var(--spacing-md);
                padding: 0 var(--spacing-md);
            }

            .articles-row-2,
            .articles-row-3 {
                grid-template-columns: 1fr;
            }

            .featured-article {
                min-height: 300px;
            }

            .featured-article-content {
                padding: var(--spacing-lg);
            }

            .featured-article-title {
                font-size: 24px;
            }

            .blog-container {
                padding: var(--spacing-lg) var(--spacing-md);
            }
        }

        @media (max-width: 640px) {
            .blog-subheader-brand {
                font-size: 16px;
            }

            .blog-subheader-container {
                height: 48px;
                padding: 0 var(--spacing-md);
            }

            .featured-article {
                min-height: 280px;
            }
        }
    </style>

    {% block metas %}{% endblock metas %}
    {% block extra_head %}{% endblock extra_head %}
</head>

<body class="body enhanced-typography">

{# Blog Sub-Header with Categories #}
<div class="blog-subheader">
    <div class="blog-subheader-container">
        <a href="{% url 'lotus:article-index' %}" class="blog-subheader-brand">
            <span class="brand-highlight">TPSCheck</span> Blog
        </a>
        <nav class="blog-subheader-nav">
            {% if blog_categories %}
                {% for category in blog_categories %}
                    <a href="{{ category.get_absolute_url }}" class="blog-subheader-link{% if request.path == category.get_absolute_url %} active{% endif %}">
                        {{ category.title }}
                    </a>
                {% endfor %}
            {% endif %}
        </nav>
    </div>
</div>

{# Blog Main Content #}
{% block blog_main %}
<div class="blog-main">
    <div class="blog-container">
        {% block breadcrumbs %}{% endblock %}
        {% block content %}
        <div class="page-header">
            <h1 class="page-title">
                Welcome to <span class="highlight">TPSCheck</span>'s Blog
            </h1>
            <p class="page-description">
                TPS compliance guides, API tutorials, and insights to help you stay compliant with UK telemarketing regulations.
            </p>
        </div>
        {% endblock content %}
    </div>
</div>
{% endblock blog_main %}

{# Original site footer #}
{% include "partials/footer.html" %}

{# Bootstrap 5 JS #}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>

<script nonce="{{ request.csp_nonce }}">
    // Calculate navbar height dynamically and set blog-subheader top position
    (function() {
        const navbar = document.querySelector('.navbar');
        const blogSubheader = document.querySelector('.blog-subheader');

        if (navbar && blogSubheader) {
            function updateBlogSubheaderTop() {
                const navbarHeight = navbar.offsetHeight;
                blogSubheader.style.top = navbarHeight + 'px';
            }

            // Update on load
            updateBlogSubheaderTop();

            // Update on resize (in case navbar height changes)
            window.addEventListener('resize', updateBlogSubheaderTop);

            // Update after a short delay to ensure all styles are applied
            setTimeout(updateBlogSubheaderTop, 100);
        }
    })();
</script>

{% block body-javascript %}{% endblock body-javascript %}
{% block extra_js %}{% endblock extra_js %}
</body>
</html>
