function renderDiv7Work() {
    const container = document.getElementById('edWorkContainer');
    if (!container || state.activeDashboardDivId !== 7 || !state.div7WorkData) return;

    const allOperationalDivisions = state.divisions.filter((div) => div.id !== 8);
    const laneSummaries = allOperationalDivisions.map((div) => ({
        id: div.id,
        name: getDivisionCopy(div).name,
        subtitle: getDivisionCopy(div).subtitle,
        vfp: getLiveVfp(div),
        workflows: div.items.length,
        pendingTasks: getPendingTaskCount(div.id),
        overduePlans: getOverdueDailyPlanCount(div.id),
        incomingOrders: getTargetDivisionOrders(div.id).length
    }));
    const policies = state.div7WorkData.policies || [];
    const meetings = state.div7WorkData.meetings || [];
    const risks = state.div7WorkData.risks || [];
    const div7Orders = getTargetDivisionOrders(7, { includeDone: true });
    const orgOrders = (state.executiveOrders || []).filter((order) => Number(order.target_division_id) !== 7);
    const activePolicies = policies.filter((policy) => policy.status === 'active');
    const openRisks = risks.filter((risk) => risk.status !== 'mitigated');
    const scheduledMeetings = meetings.filter((meeting) => String(meeting.meeting_date || '').trim());
    const legalAudits = getLatestMetricValue(7, 'legal_audits') ?? 0;
    const policyUpdates = getLatestMetricValue(7, 'policies') ?? activePolicies.length;
    const treasuryMetricsCurrent = getDivisionMetricStatus(3) === 'Current';
    const div7MetricsCurrent = getDivisionMetricStatus(7) === 'Current';
    const controlGaps = [
        { label: 'Policy library', ok: activePolicies.length > 0, detail: `${activePolicies.length} active policies` },
        { label: 'Treasury daily stats', ok: treasuryMetricsCurrent, detail: treasuryMetricsCurrent ? 'Current today' : 'Missing today' },
        { label: 'Division 7 legal/admin stats', ok: div7MetricsCurrent, detail: div7MetricsCurrent ? 'Current today' : 'Missing today' },
        { label: 'Open structural risks', ok: openRisks.length === 0, detail: `${openRisks.length} open risks` },
        { label: 'Execution orders acknowledged', ok: div7Orders.filter((order) => order.status === 'open').length === 0, detail: `${div7Orders.filter((order) => order.status === 'open').length} unstarted orders` }
    ];
    const hiringPressure = [...laneSummaries]
        .filter((lane) => lane.id !== 7)
        .sort((a, b) => (b.pendingTasks + b.overduePlans * 2 + b.incomingOrders) - (a.pendingTasks + a.overduePlans * 2 + a.incomingOrders));
    const workTabs = [
        ['policies', 'Policies', 'fa-file-contract'],
        ['org', 'Org Structure', 'fa-sitemap'],
        ['battleplans', 'Battle Plans', 'fa-chess-knight'],
        ['admin', 'Admin Control', 'fa-clipboard-check'],
        ['compliance', 'Compliance', 'fa-shield-check'],
        ['execution', 'Execution Control', 'fa-diagram-project'],
        ['standards', 'Standards', 'fa-book-open'],
        ['meetings', 'Meetings', 'fa-calendar-check'],
        ['risks', 'Risks', 'fa-triangle-exclamation'],
        ['hiring', 'Hiring / Capacity', 'fa-user-plus']
    ];

    const standardsModules = state.trainingsData?.modules || [];
    const upcomingMeetings = [...meetings].sort((a, b) => String(a.meeting_date || '9999-99-99').localeCompare(String(b.meeting_date || '9999-99-99')));

    container.innerHTML = `
        <div class="flex flex-col gap-8">
            <section class="glass-panel rounded-[2rem] border border-white/10 bg-black/40 p-6">
                <div class="flex flex-col xl:flex-row xl:items-start xl:justify-between gap-6">
                    <div>
                        <p class="text-[11px] uppercase tracking-[0.28em] text-gray-500">Division 7 Work Console</p>
                        <h3 class="text-3xl font-bold text-white mt-2">Executive Implementation and Control</h3>
                        <p class="text-sm text-gray-400 mt-3 max-w-3xl">Division 7 turns ED direction into policy, admin control, structural enforcement, and organizational follow-through. Battle plans belong inside this work console, because this hat exists to implement and stabilize the org.</p>
                    </div>
                    <div class="grid grid-cols-2 md:grid-cols-4 gap-3 min-w-0 xl:min-w-[420px]">
                        <div class="rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-4">
                            <p class="text-[10px] uppercase tracking-[0.2em] text-gray-500">Active Policies</p>
                            <p class="text-2xl font-bold text-white mt-2">${activePolicies.length}</p>
                        </div>
                        <div class="rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-4">
                            <p class="text-[10px] uppercase tracking-[0.2em] text-gray-500">Legal Audits</p>
                            <p class="text-2xl font-bold text-white mt-2">${legalAudits}</p>
                        </div>
                        <div class="rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-4">
                            <p class="text-[10px] uppercase tracking-[0.2em] text-gray-500">Open Risks</p>
                            <p class="text-2xl font-bold text-white mt-2">${openRisks.length}</p>
                        </div>
                        <div class="rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-4">
                            <p class="text-[10px] uppercase tracking-[0.2em] text-gray-500">Meetings</p>
                            <p class="text-2xl font-bold text-white mt-2">${meetings.length}</p>
                        </div>
                    </div>
                </div>
                <div class="flex flex-wrap gap-2 mt-6">
                    ${workTabs.map(([id, label, icon]) => `
                        <button class="div7-work-tab-btn px-4 py-2.5 rounded-xl border text-sm font-semibold transition ${state.activeDiv7WorkTab === id ? 'bg-white/10 border-white/20 text-white' : 'bg-white/[0.03] border-white/10 text-gray-400 hover:text-white'}" data-div7-work-tab="${id}">
                            <i class="fas ${icon} mr-2"></i>${label}
                        </button>
                    `).join('')}
                </div>
            </section>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'policies' ? '' : 'hidden'}" data-div7-work-panel="policies">
                <div class="grid grid-cols-1 xl:grid-cols-[0.9fr_1.25fr] gap-6">
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Policy Creation</p>
                        <h4 class="text-2xl font-bold text-white">Write enforceable operating policy</h4>
                        <p class="text-sm text-gray-400 mt-3">Division 7 turns repeated executive decisions into stable policy so the org does not rely on memory or improvisation.</p>
                        <div class="mt-5 flex flex-col gap-3">
                            <input id="div7PolicyTitle" type="text" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]" placeholder="Policy title">
                            <input id="div7PolicyScope" type="text" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]" placeholder="Scope (e.g. Div 3 + Div 4)">
                            <select id="div7PolicyStatus" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]">
                                <option value="draft">Draft</option>
                                <option value="active" selected>Active</option>
                                <option value="archived">Archived</option>
                            </select>
                            <textarea id="div7PolicyContent" rows="6" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)] resize-y" placeholder="What must be done, by whom, and why does this policy exist?"></textarea>
                            <button id="createDiv7PolicyBtn" class="mt-2 px-5 py-3 rounded-xl bg-[var(--dash-accent)] text-white font-bold hover:brightness-110 transition">Create Policy</button>
                        </div>
                    </div>
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Policy Library</p>
                        <div class="flex flex-col gap-4 mt-4">
                            ${policies.length ? policies.map((policy) => `
                                <div class="rounded-2xl border border-white/10 bg-white/[0.03] p-5">
                                    <div class="flex flex-col md:flex-row md:items-start justify-between gap-4">
                                        <div>
                                            <div class="flex flex-wrap items-center gap-2">
                                                <h4 class="text-lg font-bold text-white">${escapeHtml(policy.title)}</h4>
                                                <span class="px-2 py-1 rounded-full bg-black/30 border border-white/10 text-[10px] uppercase tracking-[0.18em] text-gray-300">${escapeHtml(policy.status)}</span>
                                                <span class="px-2 py-1 rounded-full bg-black/30 border border-white/10 text-[10px] uppercase tracking-[0.18em] text-gray-300">${escapeHtml(policy.scope || 'all')}</span>
                                            </div>
                                            <p class="text-sm text-gray-400 mt-3 whitespace-pre-line">${escapeHtml(policy.content || '')}</p>
                                        </div>
                                        <div class="flex flex-wrap gap-2 shrink-0">
                                            ${policy.status !== 'active' ? `<button class="div7-policy-status-btn px-3 py-2 rounded-xl bg-emerald-500/10 hover:bg-emerald-500/20 border border-emerald-400/20 text-xs text-emerald-100" data-id="${policy.id}" data-status="active">Activate</button>` : ''}
                                            ${policy.status !== 'draft' ? `<button class="div7-policy-status-btn px-3 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs text-white" data-id="${policy.id}" data-status="draft">Set Draft</button>` : ''}
                                            ${policy.status !== 'archived' ? `<button class="div7-policy-status-btn px-3 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs text-white" data-id="${policy.id}" data-status="archived">Archive</button>` : ''}
                                            <button class="div7-policy-delete-btn px-3 py-2 rounded-xl bg-red-500/10 hover:bg-red-500/20 border border-red-400/20 text-xs text-red-200" data-id="${policy.id}">Delete</button>
                                        </div>
                                    </div>
                                </div>
                            `).join('') : '<p class="text-sm text-gray-500">No policies yet.</p>'}
                        </div>
                    </div>
                </div>
            </div>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'org' ? '' : 'hidden'}" data-div7-work-panel="org">
                <div class="grid grid-cols-1 xl:grid-cols-2 gap-6">
                    ${laneSummaries.map((lane) => `
                        <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                            <div class="flex items-start justify-between gap-4">
                                <div>
                                    <p class="text-[10px] uppercase tracking-[0.24em] text-gray-500">${escapeHtml(lane.subtitle)}</p>
                                    <h4 class="text-xl font-bold text-white mt-2">${escapeHtml(lane.name)}</h4>
                                </div>
                                <button class="px-3 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs text-white work-open-division-btn" data-division="${lane.id}">Open Division</button>
                            </div>
                            <p class="text-sm text-gray-400 mt-4">${escapeHtml(lane.vfp || 'No VFP defined yet.')}</p>
                            <div class="grid grid-cols-3 gap-3 mt-5">
                                <div class="rounded-2xl border border-white/10 bg-white/[0.03] px-3 py-3 text-center"><p class="text-[10px] text-gray-500 uppercase tracking-[0.18em]">Workflows</p><p class="text-lg font-bold text-white mt-1">${lane.workflows}</p></div>
                                <div class="rounded-2xl border border-white/10 bg-white/[0.03] px-3 py-3 text-center"><p class="text-[10px] text-gray-500 uppercase tracking-[0.18em]">Pending</p><p class="text-lg font-bold text-white mt-1">${lane.pendingTasks}</p></div>
                                <div class="rounded-2xl border border-white/10 bg-white/[0.03] px-3 py-3 text-center"><p class="text-[10px] text-gray-500 uppercase tracking-[0.18em]">Orders</p><p class="text-lg font-bold text-white mt-1">${lane.incomingOrders}</p></div>
                            </div>
                        </div>
                    `).join('')}
                </div>
            </div>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'battleplans' ? '' : 'hidden'}" data-div7-work-panel="battleplans">
                <div class="glass-panel p-4 mb-6 rounded-xl border border-white/5 bg-black/40 flex flex-wrap items-center gap-4 justify-between shadow-lg">
                    <div>
                        <div class="flex items-center gap-2 text-purple-400 font-bold"><i class="fas fa-magic"></i> Division 7 Strat-Gen</div>
                        <p class="text-sm text-gray-400 mt-1">Keep Division 7 plans subordinate to ED direction, then use policies and execution control to make them real.</p>
                    </div>
                    <div class="flex flex-wrap gap-2">
                        <button class="div7-ai-bp-gen-btn bg-white/5 hover:bg-white/10 text-gray-300 px-4 py-2 rounded-lg text-sm font-medium transition flex items-center gap-2" data-period="yearly"><i class="fas fa-calendar"></i> Yearly</button>
                        <button class="div7-ai-bp-gen-btn bg-white/5 hover:bg-white/10 text-gray-300 px-4 py-2 rounded-lg text-sm font-medium transition flex items-center gap-2" data-period="monthly"><i class="fas fa-calendar-alt"></i> Monthly</button>
                        <button class="div7-ai-bp-gen-btn bg-white/5 hover:bg-white/10 text-gray-300 px-4 py-2 rounded-lg text-sm font-medium transition flex items-center gap-2" data-period="weekly"><i class="fas fa-calendar-week"></i> Weekly</button>
                        <button class="div7-ai-bp-gen-btn bg-[var(--dash-accent)] text-white px-4 py-2 rounded-lg text-sm font-bold shadow-[0_0_15px_var(--dash-accent)] hover:brightness-110 transition flex items-center gap-2" data-period="daily"><i class="fas fa-bolt"></i> Generate Daily Tasks</button>
                    </div>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-6" id="div7BattlePlanGrid"></div>
            </div>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'admin' ? '' : 'hidden'}" data-div7-work-panel="admin">
                <div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4">
                    ${[
                        ['Policy Updates', policyUpdates, `${activePolicies.length} active / ${policies.length} total`],
                        ['Meetings Scheduled', scheduledMeetings.length, scheduledMeetings.length ? 'Cadence logged' : 'No date on file'],
                        ['Open ED Orders', div7Orders.filter((order) => order.status !== 'done').length, 'Structural work coming from ED'],
                        ['Open Org Risks', openRisks.length, 'Items that still need mitigation']
                    ].map(([label, value, body]) => `
                        <div class="glass-panel rounded-2xl border border-white/10 bg-black/40 p-5">
                            <p class="text-[10px] uppercase tracking-[0.24em] text-gray-500">${label}</p>
                            <p class="text-3xl font-bold text-white mt-3">${value}</p>
                            <p class="text-sm text-gray-400 mt-2">${body}</p>
                        </div>
                    `).join('')}
                </div>
                <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6 mt-6">
                    <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Admin Control Checklist</p>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-3 mt-4">
                        ${controlGaps.map((check) => `
                            <div class="rounded-2xl border ${check.ok ? 'border-emerald-400/20 bg-emerald-500/5' : 'border-amber-400/20 bg-amber-500/5'} p-4">
                                <div class="flex items-center justify-between gap-3">
                                    <p class="text-sm font-semibold text-white">${check.label}</p>
                                    <span class="text-xs ${check.ok ? 'text-emerald-200' : 'text-amber-200'}">${check.ok ? 'Stable' : 'Needs attention'}</span>
                                </div>
                                <p class="text-sm text-gray-400 mt-2">${check.detail}</p>
                            </div>
                        `).join('')}
                    </div>
                </div>
            </div>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'compliance' ? '' : 'hidden'}" data-div7-work-panel="compliance">
                <div class="grid grid-cols-1 xl:grid-cols-2 gap-6">
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Compliance Status</p>
                        <div class="flex flex-col gap-3 mt-4">
                            ${[
                                ['Treasury stats current', treasuryMetricsCurrent, treasuryMetricsCurrent ? 'Div 3 metrics are current today.' : 'Div 3 metrics are missing today.'],
                                ['Division 7 legal/admin stats current', div7MetricsCurrent, div7MetricsCurrent ? 'Div 7 metrics are current today.' : 'Div 7 metrics are missing today.'],
                                ['Policy base active', activePolicies.length > 0, `${activePolicies.length} active policy item(s).`],
                                ['Critical risks mitigated', openRisks.length === 0, `${openRisks.length} risk item(s) remain open.`]
                            ].map(([label, ok, body]) => `
                                <div class="rounded-2xl border ${ok ? 'border-emerald-400/20 bg-emerald-500/5' : 'border-amber-400/20 bg-amber-500/5'} p-4">
                                    <div class="flex items-center justify-between gap-3">
                                        <p class="text-sm font-semibold text-white">${label}</p>
                                        <span class="text-xs ${ok ? 'text-emerald-200' : 'text-amber-200'}">${ok ? 'Pass' : 'Check'}</span>
                                    </div>
                                    <p class="text-sm text-gray-400 mt-2">${body}</p>
                                </div>
                            `).join('')}
                        </div>
                    </div>
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Compliance Reading</p>
                        <p class="text-sm text-gray-400 mt-4">Division 7 should use this area to hold the line on contracts, written approvals, stats discipline, and structural adherence. This is not treasury or delivery work itself. It is the control function that keeps those lines from drifting.</p>
                        <div class="mt-6 grid grid-cols-1 sm:grid-cols-2 gap-3">
                            <div class="rounded-2xl border border-white/10 bg-white/[0.03] p-4">
                                <p class="text-[10px] uppercase tracking-[0.2em] text-gray-500">Legal Audits Logged</p>
                                <p class="text-2xl font-bold text-white mt-2">${legalAudits}</p>
                            </div>
                            <div class="rounded-2xl border border-white/10 bg-white/[0.03] p-4">
                                <p class="text-[10px] uppercase tracking-[0.2em] text-gray-500">Policy Updates Logged</p>
                                <p class="text-2xl font-bold text-white mt-2">${policyUpdates}</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'execution' ? '' : 'hidden'}" data-div7-work-panel="execution">
                <div class="grid grid-cols-1 xl:grid-cols-[0.95fr_1.25fr] gap-6">
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Incoming to Division 7</p>
                        <div class="flex flex-col gap-4 mt-4">
                            ${div7Orders.length ? div7Orders.map((order) => `
                                <div class="rounded-2xl border border-white/10 bg-white/[0.03] p-5">
                                    <div class="flex flex-wrap items-center gap-2">
                                        <h4 class="text-lg font-bold text-white">${escapeHtml(order.title)}</h4>
                                        <span class="px-2 py-1 rounded-full bg-black/30 border border-white/10 text-[10px] uppercase tracking-[0.18em] text-gray-300">${escapeHtml(order.priority)}</span>
                                        <span class="px-2 py-1 rounded-full bg-black/30 border border-white/10 text-[10px] uppercase tracking-[0.18em] text-gray-300">${escapeHtml(String(order.status).replace('_', ' '))}</span>
                                    </div>
                                    <p class="text-sm text-gray-400 mt-3">${escapeHtml(order.body || '')}</p>
                                    <div class="mt-4 flex flex-wrap gap-2">
                                        ${order.status !== 'in_progress' ? `<button class="div7-order-status-btn px-3 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs text-white" data-order-id="${order.id}" data-status="in_progress">Start</button>` : ''}
                                        ${order.status !== 'done' ? `<button class="div7-order-status-btn px-3 py-2 rounded-xl bg-emerald-500/15 hover:bg-emerald-500/25 border border-emerald-400/20 text-xs text-emerald-100" data-order-id="${order.id}" data-status="done">Complete</button>` : ''}
                                        ${order.status !== 'open' ? `<button class="div7-order-status-btn px-3 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs text-white" data-order-id="${order.id}" data-status="open">Reopen</button>` : ''}
                                    </div>
                                </div>
                            `).join('') : '<p class="text-sm text-gray-500">No incoming Division 7 orders.</p>'}
                        </div>
                    </div>
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Org-Wide Execution Flow</p>
                        <div class="flex flex-col gap-4 mt-4">
                            ${orgOrders.length ? allOperationalDivisions.filter((div) => div.id !== 7).map((div) => {
                                const targetOrders = getTargetDivisionOrders(div.id, { includeDone: true });
                                const openCount = targetOrders.filter((order) => order.status !== 'done').length;
                                return `
                                    <div class="rounded-2xl border border-white/10 bg-white/[0.03] p-5">
                                        <div class="flex items-center justify-between gap-3">
                                            <div>
                                                <h4 class="text-lg font-bold text-white">${escapeHtml(getDivisionCopy(div).name)}</h4>
                                                <p class="text-sm text-gray-400 mt-1">${openCount} open order(s), ${targetOrders.length} total tracked.</p>
                                            </div>
                                            <button class="px-3 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs text-white work-open-division-btn" data-division="${div.id}">Open</button>
                                        </div>
                                    </div>
                                `;
                            }).join('') : '<p class="text-sm text-gray-500">No org-wide orders yet.</p>'}
                        </div>
                    </div>
                </div>
            </div>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'standards' ? '' : 'hidden'}" data-div7-work-panel="standards">
                <div class="grid grid-cols-1 xl:grid-cols-2 gap-6">
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Division 7 Standards Library</p>
                        <div class="flex flex-col gap-3 mt-4">
                            ${standardsModules.length ? standardsModules.map((module) => `
                                <div class="rounded-2xl border border-white/10 bg-white/[0.03] p-4">
                                    <div class="flex items-center justify-between gap-3">
                                        <div>
                                            <h4 class="text-base font-bold text-white">${escapeHtml(module.title)}</h4>
                                            <p class="text-sm text-gray-400 mt-1">${escapeHtml(module.read_time || '')}</p>
                                        </div>
                                        <button class="px-3 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs text-white work-open-training-btn">Open Training</button>
                                    </div>
                                </div>
                            `).join('') : '<p class="text-sm text-gray-500">No standards modules loaded yet.</p>'}
                        </div>
                    </div>
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Policy to Standard Link</p>
                        <p class="text-sm text-gray-400 mt-4">Use Division 7 to turn repeated executive guidance into policy first, then training and standards so every hat can execute the same way without drift.</p>
                        <div class="mt-5 flex flex-col gap-3">
                            ${activePolicies.slice(0, 4).map((policy) => `
                                <div class="rounded-2xl border border-white/10 bg-white/[0.03] p-4">
                                    <h4 class="text-sm font-bold text-white">${escapeHtml(policy.title)}</h4>
                                    <p class="text-sm text-gray-400 mt-2">${escapeHtml(policy.scope || 'all')}</p>
                                </div>
                            `).join('') || '<p class="text-sm text-gray-500">No active policies to map yet.</p>'}
                        </div>
                    </div>
                </div>
            </div>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'meetings' ? '' : 'hidden'}" data-div7-work-panel="meetings">
                <div class="grid grid-cols-1 xl:grid-cols-[0.9fr_1.25fr] gap-6">
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Meeting Cadence</p>
                        <div class="mt-5 flex flex-col gap-3">
                            <input id="div7MeetingTitle" type="text" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]" placeholder="Meeting title">
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
                                <select id="div7MeetingCadence" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]">
                                    <option value="daily">Daily</option>
                                    <option value="weekly" selected>Weekly</option>
                                    <option value="biweekly">Biweekly</option>
                                    <option value="monthly">Monthly</option>
                                </select>
                                <input id="div7MeetingDate" type="date" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]">
                            </div>
                            <textarea id="div7MeetingNotes" rows="5" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)] resize-y" placeholder="Meeting notes or checklist"></textarea>
                            <input id="div7MeetingNextAction" type="text" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]" placeholder="Next action">
                            <button id="createDiv7MeetingBtn" class="mt-2 px-5 py-3 rounded-xl bg-[var(--dash-accent)] text-white font-bold hover:brightness-110 transition">Schedule Meeting</button>
                        </div>
                    </div>
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Meeting Log</p>
                        <div class="flex flex-col gap-4 mt-4">
                            ${upcomingMeetings.length ? upcomingMeetings.map((meeting) => `
                                <div class="rounded-2xl border border-white/10 bg-white/[0.03] p-5">
                                    <div class="flex flex-col md:flex-row md:items-start justify-between gap-4">
                                        <div>
                                            <div class="flex flex-wrap items-center gap-2">
                                                <h4 class="text-lg font-bold text-white">${escapeHtml(meeting.title)}</h4>
                                                <span class="px-2 py-1 rounded-full bg-black/30 border border-white/10 text-[10px] uppercase tracking-[0.18em] text-gray-300">${escapeHtml(meeting.cadence || 'weekly')}</span>
                                                ${meeting.meeting_date ? `<span class="px-2 py-1 rounded-full bg-black/30 border border-white/10 text-[10px] uppercase tracking-[0.18em] text-gray-300">${escapeHtml(meeting.meeting_date)}</span>` : ''}
                                            </div>
                                            <p class="text-sm text-gray-400 mt-3 whitespace-pre-line">${escapeHtml(meeting.notes || '')}</p>
                                            ${meeting.next_action ? `<p class="text-sm text-emerald-200 mt-3">Next action: ${escapeHtml(meeting.next_action)}</p>` : ''}
                                        </div>
                                        <button class="div7-meeting-delete-btn px-3 py-2 rounded-xl bg-red-500/10 hover:bg-red-500/20 border border-red-400/20 text-xs text-red-200" data-id="${meeting.id}">Delete</button>
                                    </div>
                                </div>
                            `).join('') : '<p class="text-sm text-gray-500">No meetings scheduled yet.</p>'}
                        </div>
                    </div>
                </div>
            </div>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'risks' ? '' : 'hidden'}" data-div7-work-panel="risks">
                <div class="grid grid-cols-1 xl:grid-cols-[0.9fr_1.25fr] gap-6">
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Risk Register</p>
                        <div class="mt-5 flex flex-col gap-3">
                            <input id="div7RiskTitle" type="text" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]" placeholder="Risk title">
                            <textarea id="div7RiskImpact" rows="3" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)] resize-y" placeholder="What damage or instability can this cause?"></textarea>
                            <textarea id="div7RiskMitigation" rows="3" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)] resize-y" placeholder="Mitigation plan"></textarea>
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
                                <select id="div7RiskStatus" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]">
                                    <option value="open" selected>Open</option>
                                    <option value="monitoring">Monitoring</option>
                                    <option value="mitigated">Mitigated</option>
                                </select>
                                <select id="div7RiskOwner" class="bg-black/30 text-white border border-white/10 rounded-xl px-4 py-3 focus:outline-none focus:border-[var(--dash-accent)]">
                                    ${allOperationalDivisions.map((div) => `<option value="${div.id}" ${div.id === 7 ? 'selected' : ''}>${escapeHtml(getDivisionCopy(div).name)}</option>`).join('')}
                                </select>
                            </div>
                            <button id="createDiv7RiskBtn" class="mt-2 px-5 py-3 rounded-xl bg-[var(--dash-accent)] text-white font-bold hover:brightness-110 transition">Add Risk</button>
                        </div>
                    </div>
                    <div class="glass-panel rounded-3xl border border-white/10 bg-black/40 p-6">
                        <p class="text-[11px] uppercase tracking-[0.24em] text-gray-500 mb-2">Open Risk Register</p>
                        <div class="flex flex-col gap-4 mt-4">
                            ${risks.length ? risks.map((risk) => `
                                <div class="rounded-2xl border border-white/10 bg-white/[0.03] p-5">
                                    <div class="flex flex-col md:flex-row md:items-start justify-between gap-4">
                                        <div>
                                            <div class="flex flex-wrap items-center gap-2">
                                                <h4 class="text-lg font-bold text-white">${escapeHtml(risk.title)}</h4>
                                                <span class="px-2 py-1 rounded-full bg-black/30 border border-white/10 text-[10px] uppercase tracking-[0.18em] text-gray-300">${escapeHtml(risk.status)}</span>
                                                <span class="px-2 py-1 rounded-full bg-black/30 border border-white/10 text-[10px] uppercase tracking-[0.18em] text-gray-300">${escapeHtml(getDivisionCopy(getDivisionById(risk.owner_division_id) || { id: risk.owner_division_id, name: `Division ${risk.owner_division_id}`, subtitle: '' }).name)}</span>
                                            </div>
                                            <p class="text-sm text-gray-300 mt-3"><span class="text-gray-500">Impact:</span> ${escapeHtml(risk.impact || '')}</p>
                                            <p class="text-sm text-gray-300 mt-2"><span class="text-gray-500">Mitigation:</span> ${escapeHtml(risk.mitigation || '')}</p>
                                        </div>
                                        <div class="flex flex-wrap gap-2 shrink-0">
                                            ${risk.status !== 'monitoring' ? `<button class="div7-risk-status-btn px-3 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs text-white" data-id="${risk.id}" data-status="monitoring">Monitor</button>` : ''}
                                            ${risk.status !== 'mitigated' ? `<button class="div7-risk-status-btn px-3 py-2 rounded-xl bg-emerald-500/15 hover:bg-emerald-500/25 border border-emerald-400/20 text-xs text-emerald-100" data-id="${risk.id}" data-status="mitigated">Mitigated</button>` : ''}
                                            ${risk.status !== 'open' ? `<button class="div7-risk-status-btn px-3 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs text-white" data-id="${risk.id}" data-status="open">Reopen</button>` : ''}
                                            <button class="div7-risk-delete-btn px-3 py-2 rounded-xl bg-red-500/10 hover:bg-red-500/20 border border-red-400/20 text-xs text-red-200" data-id="${risk.id}">Delete</button>
                                        </div>
                                    </div>
                                </div>
                            `).join('') : '<p class="text-sm text-gray-500">No risks registered yet.</p>'}
                        </div>
                    </div>
                </div>
            </div>

            <div class="div7-work-panel ${state.activeDiv7WorkTab === 'hiring' ? '' : 'hidden'}" data-div7-work-panel="hiring">
                <div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
                    ${hiringPressure.map((lane) => `
                        <div class="glass-panel rounded-2xl border border-white/10 bg-black/40 p-5">
                            <p class="text-lg font-bold text-white">${escapeHtml(lane.name)}</p>
                            <p class="text-sm text-gray-400 mt-2">Current pressure profile for future hiring or contractor support.</p>
                            <div class="mt-4 flex flex-wrap gap-2 text-xs">
                                <span class="px-3 py-1 rounded-full bg-white/[0.05] border border-white/10 text-gray-300">${lane.workflows} workflows</span>
                                <span class="px-3 py-1 rounded-full bg-white/[0.05] border border-white/10 text-gray-300">${lane.pendingTasks} pending tasks</span>
                                <span class="px-3 py-1 rounded-full bg-white/[0.05] border border-white/10 text-gray-300">${lane.overduePlans} overdue plans</span>
                            </div>
                            <p class="text-sm text-amber-200 mt-4">${getHatLoadLabel(lane)}</p>
                            <button class="mt-4 px-4 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-sm text-white work-open-division-btn" data-division="${lane.id}">Open ${escapeHtml(lane.name)}</button>
                        </div>
                    `).join('')}
                </div>
            </div>
        </div>
    `;

    container.querySelectorAll('[data-div7-work-tab]').forEach((btn) => {
        btn.addEventListener('click', () => {
            state.activeDiv7WorkTab = btn.dataset.div7WorkTab;
            renderDiv7Work();
        });
    });
    container.querySelectorAll('.work-open-division-btn').forEach((btn) => {
        btn.addEventListener('click', () => openDashboard(Number(btn.dataset.division)));
    });
    container.querySelectorAll('.work-open-training-btn').forEach((btn) => {
        btn.addEventListener('click', () => document.querySelector('.dash-nav-btn[data-view="dashboardTrainingView"]')?.click());
    });
    container.querySelectorAll('.div7-policy-status-btn').forEach((btn) => {
        btn.addEventListener('click', async () => {
            await api.updatePolicy(btn.dataset.id, { status: btn.dataset.status });
            await refreshDiv7WorkData();
            renderDiv7Work();
        });
    });
    container.querySelectorAll('.div7-policy-delete-btn').forEach((btn) => {
        btn.addEventListener('click', () => customConfirm('Delete this policy?', async () => {
            await api.deletePolicy(btn.dataset.id);
            await refreshDiv7WorkData();
            renderDiv7Work();
        }));
    });
    container.querySelectorAll('.div7-meeting-delete-btn').forEach((btn) => {
        btn.addEventListener('click', () => customConfirm('Delete this meeting?', async () => {
            await api.deleteMeeting(btn.dataset.id);
            await refreshDiv7WorkData();
            renderDiv7Work();
        }));
    });
    container.querySelectorAll('.div7-risk-status-btn').forEach((btn) => {
        btn.addEventListener('click', async () => {
            await api.updateRisk(btn.dataset.id, { status: btn.dataset.status });
            await refreshDiv7WorkData();
            renderDiv7Work();
        });
    });
    container.querySelectorAll('.div7-risk-delete-btn').forEach((btn) => {
        btn.addEventListener('click', () => customConfirm('Delete this risk?', async () => {
            await api.deleteRisk(btn.dataset.id);
            await refreshDiv7WorkData();
            renderDiv7Work();
        }));
    });
    container.querySelectorAll('.div7-order-status-btn').forEach((btn) => {
        btn.addEventListener('click', async () => {
            await api.updateExecutiveOrder(btn.dataset.orderId, { status: btn.dataset.status });
            await refreshDiv7WorkData();
            renderDiv7Work();
        });
    });

    document.getElementById('createDiv7PolicyBtn')?.addEventListener('click', async () => {
        const title = document.getElementById('div7PolicyTitle')?.value.trim();
        const content = document.getElementById('div7PolicyContent')?.value.trim();
        const scope = document.getElementById('div7PolicyScope')?.value.trim();
        const status = document.getElementById('div7PolicyStatus')?.value || 'active';
        if (!title) return showToast('Policy title is required.', 'warning');
        await api.addPolicy({ division_id: 7, title, content, scope, status });
        await refreshDiv7WorkData();
        renderDiv7Work();
        showToast('Policy created.', 'success');
    });

    document.getElementById('createDiv7MeetingBtn')?.addEventListener('click', async () => {
        const title = document.getElementById('div7MeetingTitle')?.value.trim();
        const cadence = document.getElementById('div7MeetingCadence')?.value || 'weekly';
        const meetingDate = document.getElementById('div7MeetingDate')?.value || null;
        const notes = document.getElementById('div7MeetingNotes')?.value.trim();
        const nextAction = document.getElementById('div7MeetingNextAction')?.value.trim();
        if (!title) return showToast('Meeting title is required.', 'warning');
        await api.addMeeting({ division_id: 7, title, cadence, meeting_date: meetingDate, notes, next_action: nextAction });
        await refreshDiv7WorkData();
        renderDiv7Work();
        showToast('Meeting scheduled.', 'success');
    });

    document.getElementById('createDiv7RiskBtn')?.addEventListener('click', async () => {
        const title = document.getElementById('div7RiskTitle')?.value.trim();
        const impact = document.getElementById('div7RiskImpact')?.value.trim();
        const mitigation = document.getElementById('div7RiskMitigation')?.value.trim();
        const status = document.getElementById('div7RiskStatus')?.value || 'open';
        const ownerDivisionId = Number(document.getElementById('div7RiskOwner')?.value || 7);
        if (!title) return showToast('Risk title is required.', 'warning');
        await api.addRisk({ division_id: 7, title, impact, mitigation, status, owner_division_id: ownerDivisionId });
        await refreshDiv7WorkData();
        renderDiv7Work();
        showToast('Risk added.', 'success');
    });

    renderBattlePlan(7, {
        containerId: 'div7BattlePlanGrid',
        aiButtonsSelector: '#dashboardWorkView .div7-ai-bp-gen-btn'
    });
}

