<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }}</title>
    <meta name="description" content="{{ description }}">
    <meta name="keywords" content="{{ keywords }}">
    
    <!-- Open Graph -->
    <meta property="og:type" content="article">
    <meta property="og:title" content="{{ title }}">
    <meta property="og:description" content="{{ description }}">
    <meta property="og:image" content="{{ og_image }}">
    <meta property="og:url" content="{{ canonical_url }}">
    
    <!-- Twitter Card -->
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="{{ title }}">
    <meta name="twitter:description" content="{{ description }}">
    <meta name="twitter:image" content="{{ og_image }}">
    
    <!-- Canonical and Schema -->
    <link rel="canonical" href="{{ canonical_url }}">
    <script type="application/ld+json">{{ schema_json }}</script>
    
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { 
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
            line-height: 1.6; 
            color: #333; 
            background: #f5f5f5; 
        }
        
        .header { 
            background: white; 
            border-bottom: 1px solid #ddd; 
            padding: 1.5rem; 
            margin-bottom: 2rem; 
        }
        .header-content { 
            max-width: 1200px; 
            margin: 0 auto; 
        }
        
        .breadcrumb { 
            font-size: 0.9rem; 
            margin-bottom: 1rem; 
        }
        .breadcrumb a { 
            color: #0066cc; 
            text-decoration: none; 
        }
        .breadcrumb a:hover { 
            text-decoration: underline; 
        }
        .breadcrumb span { 
            color: #666; 
        }
        
        h1 { 
            font-size: 1.8rem; 
            margin-bottom: 0.5rem; 
            color: #222; 
        }
        .doc-link { 
            font-size: 0.95rem; 
            color: #666; 
            margin-top: 0.5rem; 
        }
        .doc-link a { 
            color: #0066cc; 
            text-decoration: none; 
        }
        .doc-link a:hover { 
            text-decoration: underline; 
        }
        
        .container { 
            max-width: 1200px; 
            margin: 0 auto; 
            padding: 0 1rem; 
        }
        
        .page-image-block { 
            background: white; 
            padding: 2rem; 
            margin-bottom: 2rem; 
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            text-align: center;
        }
        .page-image-block img { 
            max-width: 100%; 
            height: auto; 
            display: inline-block;
            box-shadow: 0 2px 8px rgba(0,0,0,0.15);
        }
        
        .page-meta {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1rem;
            margin-bottom: 2rem;
        }
        
        .meta-card {
            background: white;
            padding: 1.5rem;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            border-radius: 4px;
        }
        
        .meta-card h3 {
            font-size: 0.9rem;
            text-transform: uppercase;
            color: #999;
            margin-bottom: 0.5rem;
            font-weight: 600;
        }
        
        .meta-card p {
            color: #333;
            line-height: 1.5;
        }
        
        .keywords-block {
            display: flex;
            flex-wrap: wrap;
            gap: 0.5rem;
        }
        
        .keyword-tag {
            display: inline-block;
            background: #f0f0f0;
            color: #333;
            padding: 0.4rem 0.8rem;
            border-radius: 20px;
            font-size: 0.85rem;
            border: 1px solid #ddd;
        }
        
        .ocr-text {
            background: white;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            line-height: 1.8;
            color: #444;
            border-left: 4px solid #0066cc;
        }
        
        .ocr-text h3 {
            margin-bottom: 1rem;
            color: #333;
            font-size: 1.1rem;
        }
        
        .ocr-text p {
            margin-bottom: 1rem;
        }
        
        .actions {
            background: white;
            padding: 1.5rem;
            margin-bottom: 2rem;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            display: flex;
            gap: 1rem;
        }
        
        .action-link {
            display: inline-block;
            padding: 0.75rem 1.5rem;
            background: #0066cc;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            font-weight: 500;
            transition: background 0.2s;
        }
        
        .action-link:hover {
            background: #0052a3;
        }
        
        .action-link.secondary {
            background: white;
            color: #0066cc;
            border: 1px solid #0066cc;
        }
        
        .action-link.secondary:hover {
            background: #f0f0f0;
        }
        
        footer { 
            text-align: center; 
            padding: 2rem; 
            color: #999; 
            font-size: 0.9rem; 
        }
        
        @media (max-width: 768px) {
            .page-meta {
                grid-template-columns: 1fr;
            }
            
            .actions {
                flex-direction: column;
            }
            
            .action-link {
                text-align: center;
            }
            
            h1 {
                font-size: 1.4rem;
            }
        }
    </style>
</head>
<body>
    <header class="header">
        <div class="header-content">
            <div class="breadcrumb">
                <a href="{{ site_root }}">Home</a> › 
                <a href="{{ document_url }}">{{ document_title }}</a> › 
                <span>Page {{ page_num }}</span>
            </div>
            
            <h1>{{ title }}</h1>
            
            <div class="doc-link">
                <p><a href="{{ document_url }}">← Back to {{ document_title }}</a></p>
            </div>
        </div>
    </header>
    
    <div class="container">
        <!-- Page Image -->
        {% if image_url %}
        <div class="page-image-block">
            <img src="{{ image_url }}" alt="{{ alt_text }}" loading="lazy">
        </div>
        {% endif %}
        
        <!-- Metadata Cards -->
        <div class="page-meta">
            <div class="meta-card">
                <h3>Description</h3>
                <p>{{ description }}</p>
            </div>
            
            <div class="meta-card">
                <h3>Keywords</h3>
                <div class="keywords-block">
                    {% for kw in keywords_list %}
                    <span class="keyword-tag">{{ kw }}</span>
                    {% endfor %}
                </div>
            </div>
        </div>
        
        <!-- OCR Text -->
        {% if ocr_text %}
        <div class="ocr-text">
            <h3>Page Content</h3>
            <p>{{ ocr_text }}</p>
        </div>
        {% endif %}
        
        <!-- Actions -->
        <div class="actions">
            <a href="{{ document_url }}" class="action-link secondary">View Full Document</a>
        </div>
    </div>
    
    <footer>
        <p>{{ document_title }} — Page {{ page_num }} | 
            <a href="{{ canonical_url }}" style="color: #0066cc; text-decoration: none;">Permalink</a>
        </p>
    </footer>
</body>
</html>
