---
type: "Source File"
title: "<section class=\"hero hero-compact\">"
description: "{% extends \"base.html\" %} {% block title %}UK Economic Data & ONS Oracle{% endblock %} {% block meta_description %}UK economic data dashboard with ONS statistics, Oracle AI analysis, and bulletin scoring. GDP."
resource: "https://uk.copecheck.com"
tags: ["copecheck", "uk", "source-file", "html"]
timestamp: "2026-05-04T20:10:43Z"
site: "uk"
source_path: "copecheck-uk/templates/data.html"
---

# <section class="hero hero-compact">

Source path: `copecheck-uk/templates/data.html`  
Index snapshot generated: `2026-11-24T13:42:54Z`  
File modified: `2026-05-04T20:10:43Z`

```html
{% extends "base.html" %}
{% block title %}UK Economic Data & ONS Oracle{% endblock %}
{% block meta_description %}UK economic data dashboard with ONS statistics, Oracle AI analysis, and bulletin scoring. GDP, inflation, unemployment and more.{% endblock %}

{% block content %}
<section class="hero hero-compact">
    <div class="hero-inner">
        <h1 class="hero-title">UK Economic Data & ONS Oracle</h1>
        <p class="hero-subtitle">
            Real ONS data with AI analysis. What the numbers actually say versus what politicians claim.
        </p>
    </div>
</section>

<!-- ═══════════════════════════════════════════════════
     SECTION 1: Latest snapshot cards + time range
     ═══════════════════════════════════════════════════ -->
<section class="stats-section">
    {% if stats_latest %}
    <div class="stats-controls">
        <div class="stats-month-header">
            <h2 class="stats-month-title">Latest Data: {{ stats_latest.month }}</h2>
            <span class="oracle-model-badge">{{ stats_latest.ai_model or 'seed' }}</span>
        </div>
        <div class="time-range-controls">
            <span class="range-label">Chart range:</span>
            <button class="range-btn" data-months="12" onclick="setRange(12)">1yr</button>
            <button class="range-btn active" data-months="36" onclick="setRange(36)">3yr</button>
            <button class="range-btn" data-months="60" onclick="setRange(60)">5yr</button>
            <button class="range-btn" data-months="0" onclick="setRange(0)">All</button>
        </div>
    </div>

    {% if stats_latest.data %}
    <div class="stats-grid">
        {% if stats_latest.data.employment_rate is defined %}
        <div class="stats-card"><span class="stats-card-label">Employment Rate</span><span class="stats-card-value">{{ stats_latest.data.employment_rate }}%</span><span class="stats-card-series">LF24</span></div>
        {% endif %}
        {% if stats_latest.data.unemployment_rate is defined %}
        <div class="stats-card"><span class="stats-card-label">Unemployment Rate</span><span class="stats-card-value">{{ stats_latest.data.unemployment_rate }}%</span><span class="stats-card-series">MGSX</span></div>
        {% endif %}
        {% if stats_latest.data.economic_inactivity_rate is defined %}
        <div class="stats-card stats-card-warn"><span class="stats-card-label">Economic Inactivity</span><span class="stats-card-value">{{ stats_latest.data.economic_inactivity_rate }}%</span>
            {% if stats_latest.data.economic_inactivity_level is defined %}<span class="stats-card-note">{{ "{:,}".format(stats_latest.data.economic_inactivity_level) }} people</span>{% endif %}
        </div>
        {% endif %}
        {% if stats_latest.data.vacancies is defined %}
        <div class="stats-card"><span class="stats-card-label">Vacancies</span><span class="stats-card-value">{{ "{:,}".format(stats_latest.data.vacancies) }}</span>
            {% if stats_latest.data.vacancies_change is defined %}<span class="stats-card-note {% if stats_latest.data.vacancies_change < 0 %}text-red{% endif %}">{{ "{:+,}".format(stats_latest.data.vacancies_change) }} from prev.</span>{% endif %}
        </div>
        {% endif %}
        {% if stats_latest.data.total_pay_growth is defined %}
        <div class="stats-card"><span class="stats-card-label">Total Pay Growth</span><span class="stats-card-value">{{ stats_latest.data.total_pay_growth }}%</span><span class="stats-card-series">KAB9</span></div>
        {% endif %}
        {% if stats_latest.data.real_pay_growth is defined %}
        <div class="stats-card {% if stats_latest.data.real_pay_growth is defined and stats_latest.data.real_pay_growth < 1.0 %}stats-card-warn{% endif %}"><span class="stats-card-label">Real Pay Growth</span><span class="stats-card-value">{{ stats_latest.data.real_pay_growth }}%</span><span class="stats-card-note">Total pay minus CPIH</span></div>
        {% endif %}
        {% if stats_latest.data.cpih is defined %}
        <div class="stats-card"><span class="stats-card-label">CPIH Inflation</span><span class="stats-card-value">{{ stats_latest.data.cpih }}%</span><span class="stats-card-series">L55O</span></div>
        {% endif %}
        {% if stats_latest.data.cpi is defined %}
        <div class="stats-card"><span class="stats-card-label">CPI Inflation</span><span class="stats-card-value">{{ stats_latest.data.cpi }}%</span><span class="stats-card-series">D7G7</span></div>
        {% endif %}
        {% if stats_latest.data.claimant_count is defined %}
        <div class="stats-card"><span class="stats-card-label">Claimant Count</span><span class="stats-card-value">{{ "{:,}".format(stats_latest.data.claimant_count) }}</span><span class="stats-card-series">BCJD</span></div>
        {% endif %}
        {% if stats_latest.data.youth_unemployment is defined %}
        <div class="stats-card stats-card-warn"><span class="stats-card-label">Youth Unemployment</span><span class="stats-card-value">{{ stats_latest.data.youth_unemployment }}%</span><span class="stats-card-note">16-24 year olds</span></div>
        {% endif %}
        {% if stats_latest.data.gdp_growth_qoq is defined %}
        <div class="stats-card {% if stats_latest.data.gdp_growth_qoq is defined and stats_latest.data.gdp_growth_qoq < 0 %}stats-card-warn{% endif %}"><span class="stats-card-label">GDP Growth (QoQ)</span><span class="stats-card-value">{{ stats_latest.data.gdp_growth_qoq }}%</span><span class="stats-card-series">IHYQ</span></div>
        {% endif %}
        {% if stats_latest.data.trade_balance_goods is defined %}
        <div class="stats-card stats-card-warn"><span class="stats-card-label">Trade Balance (Goods)</span><span class="stats-card-value">{{ "{:,.0f}".format(stats_latest.data.trade_balance_goods) }}</span><span class="stats-card-note">the post-Brexit reality</span></div>
        {% endif %}
        {% if migration_latest %}
        <div class="stats-card"><span class="stats-card-label">Net Migration</span><span class="stats-card-value">{{ "{:,.0f}".format(migration_latest.value) }}k</span><span class="stats-card-note">{{ migration_latest.month }} (quarterly, ~6mo lag)</span></div>
        {% endif %}
        {% if stats_latest.data.long_term_unemployment is defined %}
        <div class="stats-card"><span class="stats-card-label">Long-Term Unemployed</span><span class="stats-card-value">{{ "{:,}".format(stats_latest.data.long_term_unemployment) }}</span><span class="stats-card-note">12+ months</span></div>
        {% endif %}
    </div>
    {% endif %}

    <!-- ═══════════════════════════════════════════════════
         SECTION 2: Interactive trend charts
         ═══════════════════════════════════════════════════ -->
    <div class="stats-charts">
        <h3 class="stats-charts-title">Trend Charts — The No Cope Version</h3>
        <p class="section-subtitle">Use the time range buttons above to zoom in or out. Hover for exact values.</p>
        <div class="chart-grid-2col">
            <div class="chart-container-lg"><canvas id="chart-labour"></canvas>
                <p class="chart-commentary">Employment and unemployment rates from the Labour Force Survey. Watch for the gap between these — a widening gap with rising inactivity means people are leaving the workforce entirely, not finding jobs.</p>
            </div>
            <div class="chart-container-lg"><canvas id="chart-inactivity"></canvas>
                <p class="chart-commentary">Economic inactivity — people neither working nor looking for work. This is the metric politicians most love to ignore. Long-term sickness is the fastest-growing component.</p>
            </div>
        </div>
        <div class="chart-grid-2col">
            <div class="chart-container-lg"><canvas id="chart-pay"></canvas>
                <p class="chart-commentary">Nominal pay growth looks healthy until you subtract inflation. Real pay growth is what actually hits your wallet. Years of negative real pay growth wiped out a decade of progress.</p>
            </div>
            <div class="chart-container-lg"><canvas id="chart-inflation"></canvas>
                <p class="chart-commentary">CPIH includes housing costs and is the ONS's preferred measure. CPI excludes them. The gap between the two tells you how much housing is adding to the cost of living.</p>
            </div>
        </div>
        <div class="chart-grid-2col">
            <div class="chart-container-lg"><canvas id="chart-vacancies"></canvas>
                <p class="chart-commentary">Vacancies have been falling steadily from their 2022 peak. Fewer openings means less bargaining power for workers and a cooling labour market.</p>
            </div>
            <div class="chart-container-lg"><canvas id="chart-youth"></canvas>
                <p class="chart-commentary">Youth unemployment (16-24) consistently runs 3-4x the headline rate. This is the generation told to "just get a job" while entry-level positions vanish.</p>
            </div>
        </div>
        <div class="chart-grid-2col">
            <div class="chart-container-lg"><canvas id="chart-claimant"></canvas>
                <p class="chart-commentary">The claimant count measures people on unemployment-related benefits. Tightening eligibility can make this fall even when real unemployment rises — always read alongside the LFS rate.</p>
            </div>
            <div class="chart-container-lg"><canvas id="chart-gdp"></canvas>
                <p class="chart-commentary">Quarter-on-quarter GDP growth. Two consecutive negative quarters = technical recession. Per-capita GDP tells a more honest story about living standards.</p>
            </div>
        </div>
        <div class="chart-grid-2col">
            <div class="chart-container-lg"><canvas id="chart-trade"></canvas>
                <p class="chart-commentary">Goods trade balance has been persistently negative. Services trade remains in surplus but can't fully offset the goods deficit. The structural shift accelerated post-2021.</p>
            </div>
            <div class="chart-container-lg"><canvas id="chart-migration"></canvas>
                <p class="chart-commentary">Net migration — the single most scapegoated dataset in British politics. Both sides use it selectively. The data itself is just people moving.<br><span style="opacity:0.6;font-size:0.8em;">ONS publishes quarterly with ~6 month lag. Latest available: Year Ending June 2025.</span></p>
            </div>
        </div>
    </div>

    {% if stats_latest.ai_commentary %}
    <div class="oracle-block oracle-block-commentary">
        <h3 class="oracle-block-title"><span class="block-icon">&#x1F52E;</span> Oracle Commentary — {{ stats_latest.month }}</h3>
        <div class="oracle-text">{{ stats_latest.ai_commentary }}</div>
    </div>
    {% endif %}
    {% endif %}{# end stats_latest #}

    <!-- ═══════════════════════════════════════════════════
         SECTION 3: ONS Oracle AI analysis
         ═══════════════════════════════════════════════════ -->
    {% if oracle_latest %}
    <div class="oracle-latest" style="margin-top: 2.5rem;">
        <div class="oracle-month-header">
            <h2 class="oracle-month-title">Oracle Analysis: {{ oracle_latest.month }}</h2>
            <span class="oracle-model-badge">Scored by {{ oracle_latest.ai_model or 'seed' }}</span>
        </div>

        {% if oracle_latest.ai_summary %}
        <div class="oracle-block">
            <h3 class="oracle-block-title"><span class="block-icon">&#x1f4ca;</span> Summary</h3>
            <div class="oracle-text">{{ oracle_latest.ai_summary }}</div>
        </div>
        {% endif %}

        {% if oracle_latest.ai_gap_analysis %}
        <div class="oracle-block oracle-block-gap">
            <h3 class="oracle-block-title"><span class="block-icon">&#x1f50d;</span> Gap Analysis: Claims vs Reality</h3>
            <div class="oracle-text">{{ oracle_latest.ai_gap_analysis }}</div>
        </div>
        {% endif %}

        {% if oracle_latest.ai_scapegoat_check %}
        <div class="oracle-block oracle-block-scapegoat">
            <h3 class="oracle-block-title"><span class="block-icon">&#x1f3af;</span> Scapegoat Check</h3>
            <div class="oracle-text">{{ oracle_latest.ai_scapegoat_check }}</div>
        </div>
        {% endif %}

        {% if oracle_latest.data %}
        <div class="oracle-data-grid">
            <h3 class="oracle-block-title"><span class="block-icon">&#x1f4c8;</span> Oracle Raw Data — {{ oracle_latest.month }}</h3>
            <div class="data-cards">
                {% if oracle_latest.data.gdp_growth is defined %}
                <div class="data-card"><span class="data-label">GDP Growth</span><span class="data-value">{{ oracle_latest.data.gdp_growth }}%</span></div>
                {% endif %}
                {% if oracle_latest.data.inflation_cpi is defined %}
                <div class="data-card"><span class="data-label">CPI Inflation</span><span class="data-value">{{ oracle_latest.data.inflation_cpi }}%</span></div>
                {% endif %}
                {% if oracle_latest.data.unemployment_rate is defined %}
                <div class="data-card"><span class="data-label">Unemployment</span><span class="data-value">{{ oracle_latest.data.unemployment_rate }}%</span></div>
                {% endif %}
                {% if oracle_latest.data.wage_growth_real is defined %}
                <div class="data-card"><span class="data-label">Real Wage Growth</span><span class="data-value">{{ oracle_latest.data.wage_growth_real }}%</span></div>
                {% endif %}
                {% if oracle_latest.data.net_migration is defined %}
                <div class="data-card"><span class="data-label">Net Migration</span><span class="data-value">{{ "{:,}".format(oracle_latest.data.net_migration) }}</span></div>
                {% endif %}
                {% if oracle_latest.data.housing_avg_price is defined %}
                <div class="data-card"><span class="data-label">Avg House Price</span><span class="data-value">&pound;{{ "{:,}".format(oracle_latest.data.housing_avg_price) }}</span></div>
                {% endif %}
                {% if oracle_latest.data.base_rate is defined %}
                <div class="data-card"><span class="data-label">Base Rate</span><span class="data-value">{{ oracle_latest.data.base_rate }}%</span></div>
                {% endif %}
                {% if oracle_latest.data.productivity_growth is defined %}
                <div class="data-card"><span class="data-label">Productivity Growth</span><span class="data-value">{{ oracle_latest.data.productivity_growth }}%</span></div>
                {% endif %}
            </div>
        </div>
        {% endif %}

        <div class="oracle-actions">
            <button class="btn btn-secondary" onclick="rescoreMonth('{{ oracle_latest.month }}')">
                <span class="btn-text">Re-score with AI</span>
                <span class="btn-loading" style="display:none"><span class="spinner"></span> Scoring...</span>
            </button>
        </div>
    </div>
    {% endif %}

    <!-- ═══════════════════════════════════════════════════
         SECTION 4: What They Say vs What The Data Shows
         ═══════════════════════════════════════════════════ -->
    {% if figures_with_entries %}
    <div class="figures-vs-data">
        <h3 class="stats-charts-title">What They Say vs. What The Data Shows</h3>
        <div class="figures-data-grid">
            {% for fig in figures_with_entries %}
            <div class="figure-data-card">
                <div class="fdc-header">
                    <a href="/figure/{{ fig.id }}" class="fdc-name">{{ fig.name }}</a>
                    <span class="fdc-role">{{ fig.role }}</span>
                    <span class="fdc-score {{ fig.cope_score|copecolor }}">{{ fig.cope_score|int }}</span>
                </div>
                <div class="fdc-scapegoat"><span class="fdc-label">Preferred scapegoat:</span><span class="scapegoat-tag">{{ fig.scapegoat_of_choice }}</span></div>
                {% if fig.recent_entries %}
                <div class="fdc-entries">
                    {% for e in fig.recent_entries[:2] %}
                    <div class="fdc-entry">
                        <span class="entry-score-pip" style="background: {{ '#e63946' if e.cope_score > 60 else '#f4a261' if e.cope_score > 40 else '#2a9d8f' }}">{{ e.cope_score|int }}</span>
                        {% if e.source_url %}<a href="{{ e.source_url }}" target="_blank" class="entry-link">{{ (e.source_title or e.source_url)[:60] }}</a>
                        {% elif e.quote %}<span class="entry-source">"{{ e.quote[:80] }}..."</span>{% endif %}
                    </div>
                    {% endfor %}
                </div>
                {% endif %}
            </div>
            {% endfor %}
        </div>
    </div>
    {% endif %}

    <!-- ═══════════════════════════════════════════════════
         SECTION 5: ONS Bulletin Analyses
         ═══════════════════════════════════════════════════ -->
    {% if bulletins %}
    <div class="bulletin-section">
        <h2 class="section-title"><span class="block-icon">&#x1f4f0;</span> ONS Bulletin Analyses</h2>
        <p class="section-subtitle">The ONS publishes statistical bulletins alongside data releases. The Oracle scores their framing.</p>
        <div class="bulletin-grid">
            {% for b in bulletins %}
            <a href="/bulletin/{{ b.id }}" class="bulletin-card">
                <div class="bulletin-card-header">
                    <span class="bulletin-type-badge">{{ b.bulletin_type|replace('-', ' ')|title }}</span>
                    <span class="bulletin-card-score {{ b.cope_score|copecolor }}">{{ b.cope_score }}</span>
                </div>
                <h3 class="bulletin-card-title">{{ b.bulletin_title or 'ONS Bulletin' }}</h3>
                {% if b.bulletin_date %}<span class="bulletin-card-date">{{ b.bulletin_date }}</span>{% endif %}
                {% if b.what_they_said %}
                <div class="bulletin-card-preview">
                    <span class="preview-label">ONS says:</span>
                    <span class="preview-text">{{ b.what_they_said[:120] }}{% if b.what_they_said|length > 120 %}...{% endif %}</span>
                </div>
                {% endif %}
                <span class="bulletin-card-verdict">{{ b.cope_score|copelabel }}</span>
            </a>
            {% endfor %}
        </div>
        <div class="bulletin-actions">
            <button class="btn btn-secondary" onclick="fetchBulletins()" id="fetch-bulletins-btn">
                <span class="btn-text">&#x1f504; Fetch Latest Bulletins</span>
                <span class="btn-loading" style="display:none"><span class="spinner"></span> Fetching &amp; scoring...</span>
            </button>
        </div>
    </div>
    {% else %}
    <div class="bulletin-section bulletin-empty">
        <h2 class="section-title"><span class="block-icon">&#x1f4f0;</span> ONS Bulletin Analyses</h2>
        <p class="section-subtitle">The Oracle can analyse ONS statistical bulletins — scoring their framing choices through the structural reality lens.</p>
        <button class="btn btn-primary" onclick="fetchBulletins()" id="fetch-bulletins-btn">
            <span class="btn-text">&#x1f504; Fetch &amp; Score Latest Bulletins</span>
            <span class="btn-loading" style="display:none"><span class="spinner"></span> Fetching &amp; scoring (this takes a minute)...</span>
        </button>
    </div>
    {% endif %}

    <!-- ═══════════════════════════════════════════════════
         SECTION 6: Data Archive & Sources
         ═══════════════════════════════════════════════════ -->
    {% if oracle_archive|length > 1 %}
    <div class="oracle-archive">
        <h3 class="archive-title">Oracle Archive</h3>
        <div class="archive-grid">
            {% for entry in oracle_archive %}{% if not loop.first %}
            <a href="/oracle/{{ entry.month }}" class="archive-card">
                <span class="archive-month">{{ entry.month }}</span>
                <span class="archive-model">{{ entry.ai_model or 'seed' }}</span>
                {% if entry.data and entry.data.gdp_growth is defined %}<span class="archive-stat">GDP {{ entry.data.gdp_growth }}%</span>{% endif %}
            </a>
            {% endif %}{% endfor %}
        </div>
    </div>
    {% endif %}

    {% if stats_archive|length > 1 %}
    <div class="oracle-archive">
        <h3 class="archive-title">Stats Archive ({{ stats_archive|length }} months)</h3>
        <div class="archive-grid">
            {% for entry in stats_archive[:12] %}{% if not loop.first %}
            <div class="archive-card">
                <span class="archive-month">{{ entry.month }}</span>
                {% if entry.data and entry.data.employment_rate is defined %}<span class="archive-stat">Emp: {{ entry.data.employment_rate }}%</span>{% endif %}
                {% if entry.data and entry.data.economic_inactivity_rate is defined %}<span class="archive-stat">Inact: {{ entry.data.economic_inactivity_rate }}%</span>{% endif %}
                {% if entry.data and entry.data.unemployment_rate is defined %}<span class="archive-stat">Unemp: {{ entry.data.unemployment_rate }}%</span>{% endif %}
            </div>
            {% endif %}{% endfor %}
        </div>
    </div>
    {% endif %}

    <div class="oracle-sources">
        <h3>Data Sources</h3>
        <p>
            All data from the <a href="https://www.ons.gov.uk/" target="_blank">Office for National Statistics</a> JSON API,
            Bank of England, and UK public APIs. No political filtering applied.
        </p>
    </div>
</section>
{% endblock %}

{% block scripts %}
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
const allArchive = {{ stats_archive|tojson }};
let currentRange = 36;
let charts = {};
const chronological = [...allArchive].reverse();

function getSlice(months) {
    if (months === 0 || months >= chronological.length) return chronological;
    return chronological.slice(-months);
}
function getLabels(data) {
    return data.map(e => {
        const m = e.month || '';
        const parts = m.split(' ');
        if (parts.length === 2) return parts[0].substring(0, 3) + ' ' + parts[1].substring(2);
        return m;
    });
}
function getValues(data, key) {
    return data.map(e => (e.data && e.data[key] !== undefined && e.data[key] !== null) ? e.data[key] : null);
}
const baseOpts = {
    responsive: true, maintainAspectRatio: false,
    interaction: { mode: 'index', intersect: false },
    plugins: {
        legend: { display: false, labels: { color: '#c8cad0', font: { family: "'DM Mono', monospace", size: 11 } } },
        title: { display: true, color: '#c8cad0', font: { family: "'DM Mono', monospace", size: 13 } },
        tooltip: { backgroundColor: '#1a1f3d', titleColor: '#f1faee', bodyColor: '#c8cad0', borderColor: '#3a3d4a', borderWidth: 1, titleFont: { family: "'DM Mono', monospace" }, bodyFont: { family: "'DM Mono', monospace", size: 11 }, padding: 10 }
    },
    scales: {
        x: { ticks: { color: '#8a8d96', font: { size: 10 }, maxRotation: 45, autoSkip: true, maxTicksLimit: 12 }, grid: { color: '#1e2233' } },
        y: { ticks: { color: '#8a8d96', font: { size: 10 } }, grid: { color: '#1e2233' } }
    },
    elements: { point: { radius: 1, hoverRadius: 5 }, line: { tension: 0.3, borderWidth: 2 } }
};
function makeOpts(title, showLegend) {
    const o = JSON.parse(JSON.stringify(baseOpts));
    o.plugins.title.text = title;
    if (showLegend) o.plugins.legend.display = true;
    return o;
}
function buildCharts() {
    const data = getSlice(currentRange);
    const labels = getLabels(data);
    Object.values(charts).forEach(c => c.destroy());
    charts = {};
    charts.labour = new Chart(document.getElementById('chart-labour'), { type: 'line', data: { labels, datasets: [
        { label: 'Employment Rate (%)', data: getValues(data, 'employment_rate'), borderColor: '#2a9d8f', backgroundColor: 'rgba(42,157,143,0.08)', fill: true },
        { label: 'Unemployment Rate (%)', data: getValues(data, 'unemployment_rate'), borderColor: '#e63946', backgroundColor: 'rgba(230,57,70,0.08)', fill: true }
    ]}, options: makeOpts('Employment vs Unemployment Rate (%)', true) });
    charts.inactivity = new Chart(document.getElementById('chart-inactivity'), { type: 'line', data: { labels, datasets: [
        { label: 'Inactivity Rate (%)', data: getValues(data, 'economic_inactivity_rate'), borderColor: '#9b59b6', backgroundColor: 'rgba(155,89,182,0.1)', fill: true }
    ]}, options: makeOpts('Economic Inactivity Rate (%) — The Hidden Crisis', false) });
    charts.pay = new Chart(document.getElementById('chart-pay'), { type: 'bar', data: { labels, datasets: [
        { label: 'Total Pay (inc. bonuses)', data: getValues(data, 'total_pay_growth'), backgroundColor: 'rgba(244,162,97,0.6)', borderColor: '#f4a261', borderWidth: 1 },
        { label: 'Regular Pay (excl. bonuses)', data: getValues(data, 'regular_pay_growth'), backgroundColor: 'rgba(155,89,182,0.5)', borderColor: '#9b59b6', borderWidth: 1 },
        { label: 'Real Pay Growth', data: getValues(data, 'real_pay_growth'), backgroundColor: 'rgba(42,157,143,0.6)', borderColor: '#2a9d8f', borderWidth: 1 }
    ]}, options: makeOpts('Pay Growth (%) — Nominal vs Real', true) });
    charts.inflation = new Chart(document.getElementById('chart-inflation'), { type: 'line', data: { labels, datasets: [
        { label: 'CPIH', data: getValues(data, 'cpih'), borderColor: '#e76f51', backgroundColor: 'rgba(231,111,81,0.1)', fill: true },
        { label: 'CPI', data: getValues(data, 'cpi'), borderColor: '#f4a261', backgroundColor: 'rgba(244,162,97,0.05)', fill: false, borderDash: [5, 3] }
    ]}, options: makeOpts('Inflation — CPIH & CPI (%)', true) });
    charts.vacancies = new Chart(document.getElementById('chart-vacancies'), { type: 'line', data: { labels, datasets: [
        { label: 'Vacancies', data: getValues(data, 'vacancies'), borderColor: '#f4a261', backgroundColor: 'rgba(244,162,97,0.1)', fill: true }
    ]}, options: makeOpts('Vacancies — The Relentless Decline', false) });
    charts.youth = new Chart(document.getElementById('chart-youth'), { type: 'line', data: { labels, datasets: [
        { label: 'Youth Unemployment (16-24, %)', data: getValues(data, 'youth_unemployment'), borderColor: '#e63946', backgroundColor: 'rgba(230,57,70,0.1)', fill: true }
    ]}, options: makeOpts('Youth Unemployment Rate (16-24, %)', false) });
    charts.claimant = new Chart(document.getElementById('chart-claimant'), { type: 'line', data: { labels, datasets: [
        { label: 'Claimant Count', data: getValues(data, 'claimant_count'), borderColor: '#9b59b6', backgroundColor: 'rgba(155,89,182,0.1)', fill: true }
    ]}, options: (() => { const o = makeOpts('Claimant Count', false); o.scales.y.ticks.callback = v => (v/1000).toFixed(0)+'k'; return o; })() });
    charts.gdp = new Chart(document.getElementById('chart-gdp'), { type: 'bar', data: { labels, datasets: [{
        label: 'GDP QoQ Growth (%)', data: getValues(data, 'gdp_growth_qoq'),
        backgroundColor: getValues(data, 'gdp_growth_qoq').map(v => v === null ? 'transparent' : v >= 0 ? 'rgba(42,157,143,0.7)' : 'rgba(230,57,70,0.7)'),
        borderColor: getValues(data, 'gdp_growth_qoq').map(v => v === null ? 'transparent' : v >= 0 ? '#2a9d8f' : '#e63946'), borderWidth: 1
    }]}, options: makeOpts('GDP Growth — Quarter on Quarter (%)', false) });
    charts.trade = new Chart(document.getElementById('chart-trade'), { type: 'line', data: { labels, datasets: [
        { label: 'Goods', data: getValues(data, 'trade_balance_goods'), borderColor: '#e63946', backgroundColor: 'rgba(230,57,70,0.1)', fill: true },
        { label: 'Services', data: getValues(data, 'trade_balance_services'), borderColor: '#2a9d8f', backgroundColor: 'rgba(42,157,143,0.1)', fill: true }
    ]}, options: makeOpts('Trade Balance — Goods vs Services', true) });
    charts.migration = new Chart(document.getElementById('chart-migration'), { type: 'bar', data: { labels, datasets: [{
        label: 'Net Migration (thousands)', data: getValues(data, 'net_migration'),
        backgroundColor: 'rgba(244,162,97,0.6)', borderColor: '#f4a261', borderWidth: 1
    }]}, options: makeOpts('Net Migration — The Most Scapegoated Dataset', false) });
}
function setRange(months) {
    currentRange = months;
    document.querySelectorAll('.range-btn').forEach(b => b.classList.remove('active'));
    document.querySelector('.range-btn[data-months="'+months+'"]').classList.add('active');
    buildCharts();
}
document.addEventListener('DOMContentLoaded', buildCharts);

async function fetchBulletins() {
    const btn = document.getElementById('fetch-bulletins-btn');
    const btnText = btn.querySelector('.btn-text');
    const btnLoading = btn.querySelector('.btn-loading');
    btnText.style.display = 'none';
    btnLoading.style.display = 'inline-flex';
    btn.disabled = true;
    try {
        const resp = await fetch('/api/bulletin/fetch-all', {method: 'POST'});
        const data = await resp.json();
        if (data.ok) { location.reload(); } else { alert(data.error || 'Fetch failed'); }
    } catch (e) { alert('Error: ' + e.message); }
    finally { btnText.style.display = 'inline'; btnLoading.style.display = 'none'; btn.disabled = false; }
}

async function rescoreMonth(month) {
    const btn = event.target.closest('.btn');
    const btnText = btn.querySelector('.btn-text');
    const btnLoading = btn.querySelector('.btn-loading');
    btnText.style.display = 'none';
    btnLoading.style.display = 'inline-flex';
    btn.disabled = true;
    try {
        const resp = await fetch('/api/oracle/rescore/' + month, {method: 'POST'});
        const data = await resp.json();
        if (data.ok) { location.reload(); } else { alert(data.error || 'Scoring failed'); }
    } catch (e) { alert('Error: ' + e.message); }
    finally { btnText.style.display = 'inline'; btnLoading.style.display = 'none'; btn.disabled = false; }
}
</script>
{% endblock %}
```
