<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' 'unsafe-eval' https://accounts.google.com https://apis.google.com https://www.gstatic.com https://n8n.minerva-metrics.com; default-src 'self' 'unsafe-inline' https:; img-src 'self' data: https:;">
<title>Bulls Media — Risk Intelligence Dashboard</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg-primary: #0a0f1e;
--bg-secondary: #12172a;
--bg-tertiary: #1a2137;
--accent-green: #00ff88;
--accent-cyan: #00d4ff;
--accent-red: #ff3366;
--accent-orange: #ff9933;
--accent-yellow: #ffcc00;
--text-primary: #e4e8f0;
--text-secondary:#8b94ad;
--text-dim: #5a6480;
--border: rgba(255,255,255,0.08);
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
font-size: 15px;
line-height: 1.6;
-webkit-font-smoothing: antialiased;
}

body::before {
content: '';
position: fixed; inset: 0; z-index: 0;
background-image:
linear-gradient(rgba(0,212,255,0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0,212,255,0.03) 1px, transparent 1px);
background-size: 50px 50px;
pointer-events: none;
opacity: 0.4;
}

#app { position: relative; z-index: 1; }

/* LOGIN */
#loginScreen {
min-height: 100vh;
display: flex; align-items: center; justify-content: center;
flex-direction: column; gap: 40px; padding: 40px;
}

.login-card {
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 16px;
padding: 50px 60px;
max-width: 480px; width: 100%;
text-align: center;
box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.login-title {
font-size: 32px; font-weight: 800;
letter-spacing: -0.5px; margin-bottom: 8px;
}

.login-subtitle {
font-size: 14px; color: var(--text-secondary);
margin-bottom: 40px;
}

.login-btn {
display: flex; align-items: center; justify-content: center; gap: 12px;
background: linear-gradient(135deg, var(--accent-cyan), var(--accent-green));
color: #000; font-weight: 700; font-size: 15px;
border: none; border-radius: 10px;
padding: 16px 32px; width: 100%;
cursor: pointer; transition: all 0.3s;
}

.login-btn:hover {
transform: translateY(-2px);
box-shadow: 0 0 20px rgba(0,212,255,0.4);
}

/* TOPBAR */
.topbar {
display: flex; align-items: center; justify-content: space-between;
padding: 20px 32px;
background: var(--bg-secondary);
border-bottom: 1px solid var(--border);
position: sticky; top: 0; z-index: 100;
backdrop-filter: blur(10px);
}

.topbar-left {
display: flex;
align-items: center;
gap: 20px;
flex: 1;
}

.topbar-center {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
flex: 1;
}

.topbar-title {
font-size: 20px;
font-weight: 900;
letter-spacing: -0.5px;
background: linear-gradient(135deg, var(--accent-green), var(--accent-cyan));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
white-space: nowrap;
}

.google-ads-badge {
display: inline-flex;
align-items: center;
gap: 6px;
background: rgba(66, 133, 244, 0.1);
border: 1px solid rgba(66, 133, 244, 0.3);
border-radius: 6px;
padding: 4px 10px;
font-size: 11px;
font-weight: 700;
color: #4285f4;
letter-spacing: 0.5px;
}

.topbar-right {
display: flex;
align-items: center;
gap: 16px;
flex: 1;
justify-content: flex-end;
}

.brand {
font-size: 14px; font-weight: 700;
letter-spacing: 1px; color: var(--accent-cyan);
text-transform: uppercase;
}

.status-badge {
display: flex; align-items: center; gap: 8px;
background: rgba(0,255,136,0.1);
border: 1px solid rgba(0,255,136,0.3);
border-radius: 20px; padding: 5px 14px;
font-size: 12px; font-weight: 600;
letter-spacing: 0.5px;
color: var(--accent-green);
}

.status-badge.demo {
background: rgba(255,153,51,0.1);
border-color: rgba(255,153,51,0.3);
color: var(--accent-orange);
}

.status-dot {
width: 7px; height: 7px; border-radius: 50%;
background: currentColor;
animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
0%,100% { opacity:1; }
50% { opacity:0.4; }
}

@keyframes glow-pulse {
0%, 100% {
filter: brightness(1) drop-shadow(0 0 20px rgba(0,255,136,0.4));
}
50% {
filter: brightness(1.2) drop-shadow(0 0 40px rgba(0,212,255,0.6));
}
}

.topbar-right { display: flex; align-items: center; gap: 16px; }

.user-pill {
display: flex; align-items: center; gap: 10px;
background: var(--bg-tertiary);
border: 1px solid var(--border);
border-radius: 24px; padding: 6px 16px 6px 6px;
}

.user-avatar {
width: 30px; height: 30px; border-radius: 50%;
border: 1px solid var(--border);
}

.user-name { font-size: 14px; font-weight: 600; }

.topbar-btn {
background: transparent;
border: 1px solid var(--border);
border-radius: 8px; padding: 8px 16px;
color: var(--text-secondary);
font-size: 13px; font-weight: 600;
cursor: pointer; transition: all 0.2s;
}

.topbar-btn:hover {
border-color: var(--accent-cyan);
color: var(--accent-cyan);
}

.topbar-btn.refresh-btn {
border-color: rgba(0,212,255,0.4);
color: var(--accent-cyan);
}

.topbar-btn.refresh-btn.loading {
animation: spin-btn 1s linear infinite;
}

@keyframes spin-btn { to { transform: rotate(360deg); } }

/* MAIN */
.main-content {
padding: 32px;
max-width: 1800px;
margin: 0 auto;
}

.section-header {
display: flex; align-items: center; gap: 16px;
margin-bottom: 24px; margin-top: 48px;
}

.section-header:first-child { margin-top: 0; }

.section-title {
font-size: 12px; font-weight: 700;
letter-spacing: 2px; text-transform: uppercase;
color: var(--accent-cyan);
white-space: nowrap;
}

.section-line {
flex: 1; height: 1px;
background: linear-gradient(90deg, var(--border), transparent);
}

/* KPI GRID */
.kpi-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px; margin-bottom: 16px;
}

.kpi-card {
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 12px; padding: 24px;
transition: all 0.3s;
}

.kpi-card:hover {
border-color: rgba(0,212,255,0.4);
transform: translateY(-2px);
box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.kpi-card.danger { border-color: rgba(255,51,102,0.3); }
.kpi-card.warning { border-color: rgba(255,153,51,0.3); }
.kpi-card.safe { border-color: rgba(0,255,136,0.3); }

.kpi-label {
font-size: 11px; font-weight: 700;
color: var(--text-secondary);
letter-spacing: 1.5px; text-transform: uppercase;
margin-bottom: 12px;
}

.kpi-value {
font-size: 32px; font-weight: 800;
letter-spacing: -1px; line-height: 1;
color: #fff;
}

.kpi-value.danger { color: var(--accent-red); }
.kpi-value.warning { color: var(--accent-orange); }
.kpi-value.safe { color: var(--accent-green); }

.kpi-sub {
font-size: 13px; color: var(--text-dim);
margin-top: 8px;
}

/* AI PANEL */
.ai-panel {
background: var(--bg-secondary);
border: 1px solid rgba(191,90,242,0.25);
border-radius: 12px; margin-bottom: 16px;
overflow: hidden;
}

.ai-panel-header {
display: flex; align-items: center; justify-content: space-between;
padding: 18px 24px;
background: rgba(191,90,242,0.08);
border-bottom: 1px solid rgba(191,90,242,0.15);
}

.ai-panel-title {
display: flex; align-items: center; gap: 10px;
font-size: 13px; font-weight: 700;
letter-spacing: 1.5px; text-transform: uppercase;
color: #bf5af2;
}

.ai-status {
font-size: 11px; color: var(--text-dim);
letter-spacing: 1px; text-transform: uppercase;
}

.ai-status.analyzing {
color: #bf5af2;
animation: flicker 1s infinite;
}

@keyframes flicker {
0%,100% { opacity:1; } 50% { opacity:0.5; }
}

.ai-body { padding: 24px; }

.ai-loading {
display: flex; align-items: center; gap: 12px;
color: var(--text-secondary); font-size: 14px;
}

.ai-spinner {
width: 18px; height: 18px; border-radius: 50%;
border: 2px solid rgba(191,90,242,0.3);
border-top-color: #bf5af2;
animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.ai-content { display: none; line-height: 1.8; }
.ai-content.visible { display: block; }

.ai-section { margin-bottom: 28px; }
.ai-section:last-child { margin-bottom: 0; }

.ai-section-title {
font-size: 12px; font-weight: 800;
letter-spacing: 1.5px; text-transform: uppercase;
margin-bottom: 12px; padding-bottom: 8px;
border-bottom: 1px solid var(--border);
display: flex; align-items: center; gap: 8px;
}

.ai-section-title.critical { color: var(--accent-red); }
.ai-section-title.warning { color: var(--accent-orange); }
.ai-section-title.insight { color: var(--accent-cyan); }
.ai-section-title.forecast { color: var(--accent-green); }

.ai-text {
font-size: 14px; line-height: 1.8;
color: var(--text-primary);
}

.ai-text p { margin-bottom: 12px; }
.ai-text p:last-child { margin-bottom: 0; }

.ai-text strong { color: #fff; font-weight: 700; }

/* PANELS */
.two-col {
display: grid;
grid-template-columns: 30% 70%;
gap: 20px;
}

@media (max-width: 1200px) {
.two-col { grid-template-columns: 1fr; }
}

.panel {
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 12px; overflow: hidden;
}

.panel-header {
display: flex; align-items: center; justify-content: space-between;
padding: 16px 24px;
border-bottom: 1px solid var(--border);
background: rgba(255,255,255,0.02);
}

.panel-title {
font-size: 12px; font-weight: 700;
letter-spacing: 1.5px; text-transform: uppercase;
color: var(--accent-cyan);
}

.panel-badge {
font-size: 11px; font-weight: 700;
padding: 4px 12px; border-radius: 6px;
letter-spacing: 0.5px;
}

.panel-badge.red { background: rgba(255,51,102,0.15); color: var(--accent-red); border: 1px solid rgba(255,51,102,0.3); }
.panel-badge.orange { background: rgba(255,153,51,0.15); color: var(--accent-orange); border: 1px solid rgba(255,153,51,0.3); }
.panel-badge.green { background: rgba(0,255,136,0.12); color: var(--accent-green); border: 1px solid rgba(0,255,136,0.3); }
.panel-badge.cyan { background: rgba(0,212,255,0.12); color: var(--accent-cyan); border: 1px solid rgba(0,212,255,0.3); }

.filter-badge {
transition: all 0.2s;
cursor: pointer;
}

.filter-badge:hover {
transform: scale(1.05);
opacity: 1 !important;
}

.panel-body { padding: 20px 24px; }

/* TABLES */
.table-wrap { overflow-x: auto; }

table {
width: 100%; border-collapse: collapse;
font-size: 14px;
}

th {
text-align: left; padding: 12px 16px;
font-size: 11px; font-weight: 700;
color: var(--text-secondary);
letter-spacing: 1px; text-transform: uppercase;
border-bottom: 1px solid var(--border);
white-space: nowrap;
}

th.sortable {
cursor: pointer;
user-select: none;
transition: all 0.2s ease;
}

th.sortable:hover {
background: rgba(0,212,255,0.08);
color: var(--accent-cyan);
}

.sort-icon {
font-size: 10px;
margin-left: 6px;
opacity: 0.4;
transition: opacity 0.2s ease;
}

.sort-icon.active {
opacity: 1;
color: var(--accent-cyan);
}

td {
padding: 14px 16px;
border-bottom: 1px solid rgba(255,255,255,0.04);
border-right: 1px solid rgba(255,255,255,0.02);
vertical-align: middle;
white-space: nowrap;
}

td:last-child { border-right: none; }

tr:hover td { background: rgba(0,212,255,0.08); }

.agency-link {
color: var(--accent-cyan);
text-decoration: none;
font-weight: 600;
font-size: 14px;
}

.agency-link:hover {
color: var(--accent-green);
text-decoration: underline;
}

.tag {
display: inline-block;
padding: 3px 10px;
border-radius: 6px;
font-size: 11px; font-weight: 700;
letter-spacing: 0.5px;
text-transform: uppercase;
}

.tag-unlimited { background: rgba(0,212,255,0.12); color: var(--accent-cyan); border: 1px solid rgba(0,212,255,0.25); }
.tag-limited { background: rgba(255,153,51,0.12); color: var(--accent-orange); border: 1px solid rgba(255,153,51,0.25); }
.tag-easy { background: rgba(0,255,136,0.12); color: var(--accent-green); border: 1px solid rgba(0,255,136,0.25); }

.risk-tag {
padding: 3px 10px; border-radius: 6px;
font-size: 11px; font-weight: 700;
letter-spacing: 0.5px;
}

.risk-high { background: rgba(255,51,102,0.15); color: var(--accent-red); border: 1px solid rgba(255,51,102,0.3); }
.risk-medium { background: rgba(255,153,51,0.15); color: var(--accent-orange); border: 1px solid rgba(255,153,51,0.3); }
.risk-low { background: rgba(0,255,136,0.12); color: var(--accent-green); border: 1px solid rgba(0,255,136,0.3); }

.num {
font-family: 'JetBrains Mono', monospace;
font-size: 14px; font-weight: 500;
}

.num-red { color: var(--accent-red); }
.num-orange { color: var(--accent-orange); }
.num-green { color: var(--accent-green); }
.num-white { color: #fff; }
.num-dim { color: var(--text-dim); }
.num-yellow { color: var(--accent-yellow); }
.num-cyan { color: var(--accent-cyan); }

/* ALERTS */
.alert-list { display: flex; flex-direction: column; gap: 12px; }

.alert-item {
display: flex; align-items: flex-start; gap: 14px;
padding: 14px 18px;
border-radius: 10px;
border: 1px solid;
font-size: 14px; line-height: 1.6;
}

.alert-item.critical {
background: rgba(255,51,102,0.08);
border-color: rgba(255,51,102,0.3);
}

.alert-item.warning {
background: rgba(255,153,51,0.08);
border-color: rgba(255,153,51,0.3);
}

.alert-item.info {
background: rgba(0,212,255,0.06);
border-color: rgba(0,212,255,0.25);
}

.alert-icon { font-size: 16px; flex-shrink: 0; margin-top: 2px; }
.alert-text { flex: 1; }
.alert-title { font-weight: 700; margin-bottom: 4px; }
.alert-detail { color: var(--text-secondary); font-size: 13px; }

/* NOTICES */
.notice-strip {
background: rgba(255,204,0,0.08);
border: 1px solid rgba(255,204,0,0.25);
border-radius: 10px;
padding: 14px 18px;
display: flex; align-items: center; gap: 12px;
font-size: 14px;
color: var(--accent-yellow);
margin-bottom: 8px;
}

.notice-strip strong { font-weight: 700; }

/* FOOTER */
.footer {
padding: 24px 32px;
border-top: 1px solid var(--border);
display: flex; align-items: center; justify-content: space-between;
margin-top: 48px;
font-size: 12px;
color: var(--text-dim);
}

/* LOADING */
#loadingOverlay {
position: fixed; inset: 0;
background: rgba(10,15,30,0.95);
display: flex; align-items: center; justify-content: center;
z-index: 9999; flex-direction: column; gap: 24px;
display: none;
backdrop-filter: blur(4px);
}

.loading-text {
font-size: 13px;
color: var(--accent-cyan);
letter-spacing: 2px;
text-transform: uppercase;
animation: flicker 1s infinite;
}

/* ERROR TOAST */
#errorToast {
position: fixed; bottom: 32px; right: 32px;
background: rgba(255,51,102,0.15);
border: 1px solid rgba(255,51,102,0.4);
border-radius: 12px;
padding: 18px 24px;
color: var(--accent-red);
font-size: 14px;
z-index: 9998; display: none;
max-width: 400px;
box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb {
background: rgba(0,212,255,0.2);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(0,212,255,0.4); }

#dashboard { display: none; }
</style>
</head>
<body>
<div id="app">

<!-- LOGIN -->
<div id="loginScreen">
<div style="font-size: 11px; color: var(--text-dim); letter-spacing: 3px; text-transform: uppercase;">
BULLS MEDIA HOLDINGS // SECURE ACCESS v5.0
</div>

<div class="login-card">
<div style="font-size: 40px; margin-bottom: 16px;">🛡️</div>
<div class="login-title">Risk Intelligence</div>
<div class="login-subtitle">Agency Management Dashboard</div>

<button class="login-btn">
<svg width="20" height="20" viewBox="0 0 48 48">
<path fill="#FFC107" d="M43.6 20H24v8h11.3C33.5 33.3 29.2 36 24 36c-6.6 0-12-5.4-12-12s5.4-12 12-12c3 0 5.8 1.1 7.9 3l5.7-5.7C34.1 6.5 29.3 4 24 4 12.9 4 4 12.9 4 24s8.9 20 20 20c11 0 19.7-8 19.7-20 0-1.3-.1-2.7-.1-4z"/>
<path fill="#FF3D00" d="M6.3 14.7l6.6 4.8C14.5 16 19 13 24 13c3 0 5.8 1.1 7.9 3l5.7-5.7C34.1 6.5 29.3 4 24 4 16.3 4 9.7 8.3 6.3 14.7z"/>
<path fill="#4CAF50" d="M24 44c5.2 0 9.9-1.9 13.5-5.1l-6.2-5.3C29.5 35.5 26.9 36 24 36c-5.2 0-9.4-2.7-11.3-6.7L6 34.3C9.3 39.8 16.2 44 24 44z"/>
<path fill="#1976D2" d="M43.6 20H24v8h11.3c-.9 2.3-2.5 4.3-4.5 5.6l6.2 5.3C40.8 35.5 44 30.2 44 24c0-1.3-.1-2.7-.4-4z"/>
</svg>
Sign in with Google
</button>

<div style="margin-top: 24px; font-size: 12px; color: var(--text-dim); line-height: 1.5;">
Access restricted to <strong style="color: var(--accent-green);">@bulls-media.com</strong> accounts.<br>
Data never leaves your Google account.
</div>
</div>
</div>

<!-- DASHBOARD -->
<div id="dashboard">

<!-- TOP BAR -->
<div class="topbar">
<div class="topbar-left">
<div class="brand">BULLS MEDIA // RISK OPS</div>
<div class="status-badge" id="statusBadge">
<div class="status-dot"></div>
<span id="statusText">LIVE</span>
</div>
<div style="font-size: 12px; color: var(--text-dim);">
<div id="lastRefreshLabel">Updated: —</div>
<a href="https://docs.google.com/spreadsheets/d/1JPOVKTmakKWPyNrUIu3U2NwyCxMHEd_h4yKnH_Y2EiM"
target="_blank"
style="color: var(--accent-cyan); text-decoration: none; font-size: 11px;">
Source: Sheet ↗
</a>
</div>
</div>
<div class="topbar-center">
<div class="topbar-title">RISK INTELLIGENCE</div>
<div class="google-ads-badge">
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
<path d="M12.71 16.29L9 12.58V3h2v8.58l3.29 3.29-1.58 1.42zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/>
</svg>
GOOGLE ADS
</div>
</div>
<div class="topbar-right">
<button class="topbar-btn refresh-btn" id="refreshBtn">
⟳ Refresh
</button>
<div class="user-pill">
<img id="userAvatarImg" class="user-avatar" src="" alt="">
<span class="user-name" id="userNameLabel"></span>
</div>
<button class="topbar-btn">Sign Out</button>
</div>
</div>

<div class="main-content">

<!-- KPI ROW -->
<div class="section-header">
<div class="section-title">Financial Overview</div>
<div class="section-line"></div>
<div id="weekLabel" style="font-size: 11px; color: var(--text-dim); letter-spacing: 1px;"></div>
</div>

<div class="kpi-grid" id="kpiGrid"></div>

<!-- AI INSIGHTS -->
<div class="section-header">
<div class="section-title">AI Analyst</div>
<div class="section-line"></div>
</div>

<div class="ai-panel">
<div class="ai-panel-header">
<div class="ai-panel-title">
<span></span>
Claude Intelligence Engine
</div>
<div class="ai-status" id="aiStatus">STANDBY</div>
</div>
<div class="ai-body">
<div class="ai-loading" id="aiLoading">
<div class="ai-spinner"></div>
Analyzing agency data and generating insights...
</div>
<div class="ai-content" id="aiContent"></div>
</div>
</div>

<!-- ALERTS + FORECAST -->
<div class="section-header">
<div class="section-title">Alerts & Weekly Forecast</div>
<div class="section-line"></div>
</div>

<div class="two-col">
<div class="panel">
<div class="panel-header">
<div class="panel-title">Attention Required</div>
<div class="panel-badge red" id="alertCount"></div>
</div>
<div class="panel-body">
<div class="alert-list" id="alertList"></div>
</div>
</div>

<div class="panel">
<div class="panel-header">
<div class="panel-title" id="suggestedRequestTitle">📊 Suggested Weekly Request (As of Today)</div>
<div class="panel-badge green" id="financeTotal"></div>
</div>
<div class="panel-body table-wrap">
<table>
<thead>
<tr>
<th>Agency</th>
<th>Allocator</th>
<th>Balance</th>
<th>Risk</th>
<th>MB Forecast</th>
<th>Suggested</th>
<th>Basis</th>
</tr>
</thead>
<tbody id="forecastBody"></tbody>
</table>
</div>
</div>
</div>

<!-- FULL AGENCY TABLE -->
<div class="section-header">
<div class="section-title">Agency Risk Register</div>
<div class="section-line"></div>
</div>

<div class="panel">
<div class="panel-header">
<div class="panel-title" id="agencyTableTitle">All Active Agencies</div>
<div style="display:flex; gap:10px;">
<div class="panel-badge red filter-badge" id="highRiskCount" data-filter="high"></div>
<div class="panel-badge orange filter-badge" id="medRiskCount" data-filter="medium"></div>
<div class="panel-badge green filter-badge" id="lowRiskCount" data-filter="low"></div>
<div class="panel-badge" id="allRiskCount" style="cursor:pointer; background:rgba(255,255,255,0.05); color:var(--text-secondary); border:1px solid var(--border);">ALL</div>
</div>
</div>
<div class="table-wrap" style="max-height: 600px; overflow-y: auto; position: relative;">
<table style="position: relative;">
<thead style="position: sticky; top: 0; z-index: 10; background: var(--bg-secondary);">
<tr>
<th class="sortable" data-table="agency" data-column="agency">Agency <span class="sort-icon"></span></th>
<th class="sortable" data-table="agency" data-column="type">Type <span class="sort-icon"></span></th>
<th class="sortable" data-table="agency" data-column="country">Country <span class="sort-icon"></span></th>
<th class="sortable" data-table="agency" data-column="risk">Risk <span class="sort-icon"></span></th>
<th>Status</th>
<th class="sortable" data-table="agency" data-column="riskAmt">Assigned Risk <span class="sort-icon"></span></th>
<th class="sortable" data-table="agency" data-column="balance">Balance <span class="sort-icon"></span></th>
<th class="sortable" data-table="agency" data-column="gap">Gap <span class="sort-icon"></span></th>
<th class="sortable" data-table="agency" data-column="riskPct">Risk % <span class="sort-icon"></span></th>
<th>MB Forecast</th>
<th class="sortable" data-table="agency" data-column="spend5d">5d Spend <span class="sort-icon"></span></th>
<th class="sortable" data-table="agency" data-column="daily">Daily Spend <span class="sort-icon"></span></th>
<th class="sortable" data-table="agency" data-column="days">Days Left <span class="sort-icon"></span></th>
<th>Full Risk ✓</th>
<th class="sortable" data-table="agency" data-column="currency">Currency <span class="sort-icon"></span></th>
</tr>
</thead>
<tbody id="agencyTableBody"></tbody>
</table>
</div>
</div>

<!-- ACCOUNT STATUS BREAKDOWN TABLE -->
<div class="section-header">
<div class="section-title">Account Status Breakdown by Agency</div>
<div class="section-line"></div>
</div>

<div class="panel">
<div class="panel-header">
<div class="panel-title">Detailed Account Metrics (Excluded Burned)</div>
<div class="panel-badge cyan">LIVE DATA</div>
</div>
<div class="table-wrap" style="max-height: 500px; overflow-y: auto; position: relative;">
<table style="position: relative;">
<thead style="position: sticky; top: 0; z-index: 10; background: var(--bg-secondary);">
<tr>
<th class="sortable" data-table="metrics" data-column="agency">Agency <span class="sort-icon"></span></th>
<th>Currency</th>
<th class="sortable" data-table="metrics" data-column="accounts">Total Acc <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="spent5d">5d Spend <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="daily">Avg Daily <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="spent30d">30d Spend <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="notSpending" style="color:var(--accent-yellow);">Not Spending <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="active" style="color:var(--accent-green);">Active <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="warming" style="color:var(--accent-green);">Warming <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="newAccounts" style="color:var(--accent-cyan);">To Delivery <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="stuck" style="color:var(--accent-red);">Appeal/Stuck <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="pending" style="color:var(--accent-yellow);">Pending Cert <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="burn" style="color:var(--accent-red);">Suspended <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="flagged" style="color:var(--accent-orange);">Flagged <span class="sort-icon"></span></th>
<th class="sortable" data-table="metrics" data-column="other" style="color:var(--text-dim);">Other <span class="sort-icon"></span></th>
</tr>
</thead>
<tbody id="metricsTableBody"></tbody>
</table>
</div>
</div>

<!-- TRAPPED CAPITAL BREAKDOWN -->
<div class="section-header">
<div class="section-title">💰 Trapped Capital Breakdown</div>
<div class="section-line"></div>
</div>

<div class="panel">
<div class="panel-header">
<div class="panel-title">Recoverable Funds by Agency & Status</div>
<div class="panel-badge orange" id="trappedAgenciesCount"></div>
</div>
<div class="table-wrap" style="max-height: 500px; overflow-y: auto;">
<table>
<thead style="position: sticky; top: 0; background: var(--bg-secondary); z-index: 5;">
<tr>
<th class="sortable" data-table="trapped" data-column="agency">Agency <span class="sort-icon"></span></th>
<th>Account ID</th>
<th class="sortable" data-table="trapped" data-column="status">Account Status <span class="sort-icon"></span></th>
<th>Currency</th>
<th>Available (Original)</th>
<th class="sortable" data-table="trapped" data-column="amountUSD">Available (USD) <span class="sort-icon"></span></th>
<th>Action</th>
</tr>
</thead>
<tbody id="trappedTableBody"></tbody>
</table>
</div>
</div>

<!-- AGENCIES TO WATCH -->
<div class="section-header">
<div class="section-title">Agencies to Watch — Pending Activation</div>
<div class="section-line"></div>
</div>

<div id="onboardingNotices"></div>

</div>

<div class="footer">
<div>BULLS MEDIA // RISK INTELLIGENCE PLATFORM // CONFIDENTIAL</div>
<div id="footerTime"></div>
</div>

</div>

</div>

<div id="loadingOverlay">
<div class="ai-spinner" style="width:36px; height:36px; border-width:3px;"></div>
<div class="loading-text" id="loadingText">INITIALIZING...</div>
</div>

<div id="errorToast"></div>

<script src="https://accounts.google.com/gsi/client" async></script>

<script src="dashboard.js"></script>
</body>
</html>