File size: 32,603 Bytes
12b36d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c14503
12b36d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c14503
 
 
 
 
 
 
 
 
 
12b36d3
 
 
0c14503
 
 
 
12b36d3
0c14503
 
 
 
12b36d3
0c14503
 
 
 
12b36d3
0c14503
 
 
 
12b36d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c14503
12b36d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c14503
12b36d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c14503
12b36d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c14503
12b36d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interactive Domain Analysis</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-annotation@3.0.1/dist/chartjs-plugin-annotation.min.js"></script>
    <!-- Chosen Palette: Calm Harmony Neutrals -->
    <!-- Application Structure Plan: The application is designed as a single-page dashboard with a fixed sidebar navigation. This structure was chosen to allow users to easily switch between different analytical views (Dashboard, Comparison Table, Thematic Groups, Risk/Reward Chart) without losing context. This non-linear approach is superior to a long-scrolling page for a data-rich report, as it empowers users to explore data from multiple perspectives. A modal window provides deep-dive details on demand, keeping the main views clean and focused on comparison and high-level insights. This design prioritizes user-driven exploration and rapid synthesis of the report's key findings. -->
    <!-- Visualization & Content Choices: 
        - Report Info: Top Recommendations -> Goal: Inform -> Viz: Highlighted Cards -> Interaction: Click for Detail -> Justification: Immediately surfaces the report's conclusion for quick decision-making. -> Method: HTML/Tailwind.
        - Report Info: Full Scoring Matrix -> Goal: Compare/Organize -> Viz: Sortable Table -> Interaction: Click headers to sort by Score, etc. -> Justification: Enables users to rank and compare all candidates based on various quantitative factors. -> Method: HTML/JS.
        - Report Info: Thematic Categories -> Goal: Organize/Inform -> Viz: Tabbed Content Layout -> Interaction: Click tabs to view domains by category -> Justification: Translates the report's narrative structure into an interactive format, allowing users to analyze branding strategies. -> Method: HTML/JS.
        - Report Info: Risk vs. Reward Analysis -> Goal: Relationships/Compare -> Viz: Bubble Chart -> Interaction: Hover for tooltip, click for detail -> Justification: Provides a powerful visual synthesis of the strategic trade-offs between brand potential and risk, making complex relationships easy to grasp. -> Library: Chart.js.
        - Report Info: Granular Domain Analysis -> Goal: Inform -> Viz: Modal Window -> Interaction: Click any domain to open -> Justification: Provides access to detailed qualitative data without cluttering the main interface. -> Method: HTML/JS.
    -->
    <!-- CONFIRMATION: NO SVG graphics used. NO Mermaid JS used. -->
    <style>
        body { font-family: 'Inter', sans-serif; background-color: #F8F7F4; color: #333333; }
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
        .nav-link { transition: all 0.2s ease-in-out; }
        .nav-link.active { background-color: #EAE7E1; color: #A57C5A; border-right: 4px solid #A57C5A; }
        .nav-link:not(.active):hover { background-color: #EFEBE6; transform: translateX(2px); }
        .view { display: none; }
        .view.active { display: block; animation: fadeIn 0.5s; }
        @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
        .chart-container { position: relative; width: 100%; height: 400px; max-height: 50vh; margin-left: auto; margin-right: auto; }
        .modal-bg { background-color: rgba(0,0,0,0.5); }
        .sortable-header { cursor: pointer; }
        .sortable-header:hover { background-color: #f0ebe5; }
        .asc::after { content: ' ▲'; font-size: 0.8em; }
        .desc::after { content: ' ▼'; font-size: 0.8em; }
        .tier-1 { border-left: 5px solid #22c55e; }
        .tier-2 { border-left: 5px solid #f97316; }
        .tier-3 { border-left: 5px solid #ef4444; }
    </style>
</head>
<body class="antialiased">

    <div class="flex h-screen bg-gray-100">
        <aside class="w-64 bg-[#F8F7F4] shadow-md flex flex-col fixed top-0 left-0 h-full z-20">
            <div class="p-6">
                <h1 class="text-2xl font-bold text-[#A57C5A]">Brand Analysis</h1>
                <p class="text-sm text-gray-500 mt-1">Candidate List Review</p>
            </div>
            <nav class="flex-1 px-4 py-2 space-y-2">
                <a href="#" data-view="dashboard" class="nav-link active flex items-center p-3 rounded-lg">
                    <span class="mr-3">📊</span> Dashboard
                </a>
                <a href="#" data-view="comparison" class="nav-link flex items-center p-3 rounded-lg">
                    <span class="mr-3">📋</span> Full Comparison
                </a>
                <a href="#" data-view="themes" class="nav-link flex items-center p-3 rounded-lg">
                    <span class="mr-3">📚</span> Thematic Groups
                </a>
                <a href="#" data-view="quadrant" class="nav-link flex items-center p-3 rounded-lg">
                    <span class="mr-3">🎯</span> Risk vs Reward
                </a>
            </nav>
            <div class="p-4 text-xs text-gray-400">
                <p>&copy; 2024 Strategic Analysis. All Rights Reserved.</p>
            </div>
        </aside>

        <main class="flex-1 ml-64 p-6 md:p-10 overflow-y-auto bg-[#F0EBE5]">
            <div id="dashboard" class="view active">
                <div class="mb-8">
                    <h2 class="text-3xl font-bold text-gray-800">Dashboard Overview</h2>
                    <p class="text-gray-600 mt-2">A high-level summary of the brand name analysis, highlighting top recommendations and key data distributions for the latest list of candidates.</p>
                </div>

                <div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8">
                    <div class="lg:col-span-1 bg-white p-6 rounded-lg shadow-lg">
                        <h3 class="font-bold text-lg text-green-600 mb-2">🏆 Premier Recommendation</h3>
                        <div id="top-recommendation-card" class="cursor-pointer hover:shadow-xl transition-shadow"></div>
                    </div>
                    <div class="lg:col-span-2 bg-white p-6 rounded-lg shadow-lg">
                        <h3 class="font-bold text-lg text-gray-700 mb-2">Strategic Score Distribution</h3>
                        <p class="text-sm text-gray-500 mb-4">This chart shows the number of brands falling into different strategic score brackets, indicating the overall quality of this candidate pool.</p>
                        <div class="chart-container h-64 max-h-[300px]">
                            <canvas id="scoreDistributionChart"></canvas>
                        </div>
                    </div>
                </div>

                <div class="grid grid-cols-1 gap-6">
                    <div class="bg-white p-6 rounded-lg shadow-lg">
                        <h3 class="font-bold text-lg text-gray-700 mb-2">Candidate Quality Overview</h3>
                        <p class="text-sm text-gray-500 mb-4">A breakdown of all names by their strategic viability tier. This highlights the proportion of high-potential names versus those with significant challenges.</p>
                        <div class="chart-container">
                            <canvas id="tierDistributionChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>

            <div id="comparison" class="view">
                <div class="mb-8">
                    <h2 class="text-3xl font-bold text-gray-800">Full Comparison Matrix</h2>
                    <p class="text-gray-600 mt-2">An interactive table of all brand candidates, scored across five critical success factors. Click any column header to sort the data and any row to view a detailed analysis.</p>
                </div>
                <div class="bg-white rounded-lg shadow-lg overflow-x-auto">
                    <table class="w-full text-sm text-left text-gray-500">
                        <thead class="text-xs text-gray-700 uppercase bg-gray-50">
                            <tr>
                                <th scope="col" class="px-6 py-3 sortable-header" data-sort="name">Brand Name</th>
                                <th scope="col" class="px-6 py-3 sortable-header" data-sort="clarity">Brand Clarity</th>
                                <th scope="col" class="px-6 py-3 sortable-header" data-sort="uniqueness">Market Uniqueness</th>
                                <th scope="col" class="px-6 py-3 sortable-header" data-sort="seo">SEO Potential</th>
                                <th scope="col" class="px-6 py-3 sortable-header" data-sort="international">Int'l Viability</th>
                                <th scope="col" class="px-6 py-3 sortable-header" data-sort="legal">Legal Viability</th>
                                <th scope="col" class="px-6 py-3 sortable-header active desc" data-sort="score">Overall Score</th>
                            </tr>
                        </thead>
                        <tbody id="comparison-table-body">
                        </tbody>
                    </table>
                </div>
            </div>

            <div id="themes" class="view">
                <div class="mb-8">
                    <h2 class="text-3xl font-bold text-gray-800">Thematic Group Analysis</h2>
                    <p class="text-gray-600 mt-2">Explore the brands organized by their underlying philosophy. Each category presents a different strategic approach, allowing for evaluation based on the desired brand identity.</p>
                </div>
                <div id="themes-container" class="space-y-8"></div>
            </div>

            <div id="quadrant" class="view">
                <div class="mb-8">
                    <h2 class="text-3xl font-bold text-gray-800">Risk vs. Reward Quadrant</h2>
                    <p class="text-gray-600 mt-2">This chart visually plots each brand's potential (reward) against its market and legal risks. Ideal candidates are in the top-left quadrant (High Reward, Low Risk).</p>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-lg">
                    <div class="chart-container h-[500px]">
                        <canvas id="riskRewardChart"></canvas>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <div id="modal" class="fixed inset-0 z-30 items-center justify-center p-4 hidden modal-bg">
        <div id="modal-content" class="bg-white rounded-lg shadow-2xl w-full max-w-3xl max-h-[90vh] flex flex-col">
            <div class="p-6 border-b flex justify-between items-start">
                <div>
                    <h3 id="modal-title" class="text-2xl font-bold"></h3>
                    <p id="modal-subtitle" class="text-gray-500 text-sm"></p>
                </div>
                <button id="modal-close" class="text-gray-400 hover:text-gray-800 text-2xl font-bold">&times;</button>
            </div>
            <div id="modal-body" class="p-6 overflow-y-auto flex-1"></div>
            <div class="p-4 bg-gray-50 border-t flex justify-end">
                <button id="modal-close-footer" class="px-4 py-2 bg-gray-700 text-white rounded-lg hover:bg-gray-800">Close</button>
            </div>
        </div>
    </div>

<script>
const domainData = [
    { name: 'easetrust.com', cost: 4995, category: 'Hybrid', scores: { clarity: 9, uniqueness: 9, seo: 7, international: 8, legal: 8, score: 8.2 }, analysis: 'A premier candidate. Masterfully combines "Ease" (insurtech value) and "Trust" (core insurance value). The name is a mission statement. It is short, memorable, professional, and highly brandable. The primary risk is a Swiss company "Ease&Trust AG", but geographic and service differences may make this manageable. The cost is a sound investment in a top-tier brand asset.' },
    { name: 'ateaseinsurance.com', cost: 3300, category: 'Hybrid', scores: { clarity: 8, uniqueness: 6, seo: 7, international: 7, legal: 6, score: 6.8 }, analysis: 'Leverages a positive idiom ("at ease") to evoke comfort and security. Professional and clear. Its viability is entirely contingent on the legal status of an active Florida corporation with the same name. A solid, if more conservative, choice if legally clear.' },
    { name: 'allsura.com', cost: 2499, category: 'Abstract/Sura', scores: { clarity: 5, uniqueness: 5, seo: 4, international: 1, legal: 1, score: 3.2 }, analysis: 'Unacceptable risk. "Sura" is a sacred term in Islam (chapter of the Quran), posing a severe risk of causing profound religious offense. It also creates a direct trademark conflict with SURA, a major Latin American insurer. Strategically and ethically untenable.' },
    { name: 'gosura.com', cost: 2988, category: 'Abstract/Sura', scores: { clarity: 4, uniqueness: 5, seo: 4, international: 1, legal: 1, score: 3.0 }, analysis: 'Unacceptable risk. Same religious and trademark conflicts as allsura.com. The "go" prefix does not mitigate the core issues. Additionally, it phonetically resembles "Gokshura," an Ayurvedic herb, adding another layer of brand confusion.' },
    { name: 'surabay.com', cost: 2990, category: 'Abstract/Sura', scores: { clarity: 2, uniqueness: 2, seo: 2, international: 2, legal: 3, score: 2.2 }, analysis: 'Poor choice. The name is nearly identical to Surabaya, Indonesia\'s second-largest city, making it a geo-domain unsuitable for branding. The city\'s name derives from "sura" (shark) and "baya" (crocodile), both negative connotations for an insurance brand.' },
    { name: 'trustshieldpro.com', cost: 1, category: 'Security/Trust', scores: { clarity: 7, uniqueness: 3, seo: 5, international: 6, legal: 2, score: 4.6 }, analysis: 'High risk. The core "Trustshield" is already in use by multiple entities in related sectors, including an insurance agency and a safety systems manufacturer. The "-pro" suffix can cheapen the brand. Low cost masks significant legal hurdles.' },
    { name: 'securecoverpro.com', cost: 1, category: 'Security/Trust', scores: { clarity: 7, uniqueness: 4, seo: 6, international: 6, legal: 5, score: 5.6 }, analysis: 'A functional but generic and uninspired name. "Secure Cover" is highly descriptive and lacks brand-building potential. The "-pro" suffix is a detractor. Offers little strategic value beyond its low cost.' },
    { name: 'insureeaze.com', cost: 1, category: 'Ease/Simplicity', scores: { clarity: 6, uniqueness: 2, seo: 4, international: 5, legal: 2, score: 3.8 }, analysis: 'High risk. The unconventional spelling creates user friction and can be perceived as unprofessional. More importantly, it faces a high probability of trademark conflict with existing companies "Insureaze" and "Insureze".' },
    { name: 'insureeez.com', cost: 1, category: 'Ease/Simplicity', scores: { clarity: 5, uniqueness: 2, seo: 3, international: 5, legal: 2, score: 3.4 }, analysis: 'High risk. Even more problematic spelling than insureeaze.com, exacerbating user error and unprofessional perception. Faces the same significant legal risks from existing, phonetically identical brands.' },
    { name: 'ensureease.com', cost: 1, category: 'Ease/Simplicity', scores: { clarity: 8, uniqueness: 3, seo: 6, international: 7, legal: 1, score: 5.0 }, analysis: 'High risk. While phonetically strong, the name creates a near-certain trademark conflict with "Ensure," the globally recognized nutritional supplement brand owned by Abbott Laboratories. This makes the name strategically unviable.' }
];

const themeInfo = {
    Hybrid: {
        description: "This strategy combines two core value propositions—typically 'ease' and 'trust'—to create a powerful, modern brand message that resonates with today's insurtech consumers.",
        pros: "Creates a highly relevant and differentiated market position. The names are often memorable and professional.",
        cons: "Finding a unique and legally available combination can be challenging. Premium domains may be costly."
    },
    'Security/Trust': {
        description: "This approach focuses on the foundational pillars of the insurance industry: protection, security, and trust. The brand promise is one of unwavering reliability and dependability.",
        pros: "The message is clear and directly addresses a core consumer need in the insurance space.",
        cons: "This is a very crowded branding category, making it difficult to find a unique name. Many names can sound generic or dated."
    },
    'Ease/Simplicity': {
        description: "This cohort seeks to capitalize on a primary insurtech differentiator: making insurance simple, fast, and user-friendly. The core brand promise is a frictionless customer experience.",
        pros: "Directly communicates a modern value proposition that appeals to consumers frustrated with traditional insurance.",
        cons: "Often relies on misspelled or generic terms, which can appear unprofessional and face significant legal challenges from existing brands."
    },
    'Abstract/Sura': {
        description: "This cohort uses the root word 'Sura' to create short, modern-sounding names. These names are intended as 'blank slates' to be imbued with meaning through marketing.",
        pros: "The names are short and can sound modern.",
        cons: "Carries profound and unacceptable risks, including direct trademark conflicts with a major global insurer and the potential for severe, widespread religious offense."
    }
};

let currentSort = { column: 'score', order: 'desc' };
let charts = {};

document.addEventListener('DOMContentLoaded', () => {
    initApp();
});

function initApp() {
    setupNavigation();
    renderAllViews();
}

function setupNavigation() {
    const navLinks = document.querySelectorAll('.nav-link');
    navLinks.forEach(link => {
        link.addEventListener('click', (e) => {
            e.preventDefault();
            const viewId = link.dataset.view;
            
            navLinks.forEach(l => l.classList.remove('active'));
            link.classList.add('active');

            document.querySelectorAll('.view').forEach(view => {
                view.classList.remove('active');
            });
            document.getElementById(viewId).classList.add('active');
            
            if (viewId === 'dashboard') {
                initDashboardCharts();
            } else if (viewId === 'quadrant') {
                initRiskRewardChart();
            }
        });
    });
}

function renderAllViews() {
    renderDashboard();
    renderComparisonTable();
    renderThemes();
    initRiskRewardChart();
    setupModal();
}

function renderDashboard() {
    const topRec = [...domainData].sort((a, b) => b.scores.score - a.scores.score)[0];
    if (topRec) {
        const tierClass = topRec.scores.score >= 7 ? 'tier-1' : topRec.scores.score >= 5 ? 'tier-2' : 'tier-3';
        const tierColor = topRec.scores.score >= 7 ? 'text-green-600' : topRec.scores.score >= 5 ? 'text-orange-600' : 'text-red-600';
        const tierIcon = topRec.scores.score >= 7 ? '🏆' : topRec.scores.score >= 5 ? '⚠️' : '🚫';
        document.getElementById('top-recommendation-card').innerHTML = `
            <div class="bg-yellow-50 p-4 rounded-md ${tierClass}" onclick="showModal('${topRec.name}')">
                <h4 class="font-bold text-xl ${tierColor}">${tierIcon} ${topRec.name}</h4>
                <p class="text-sm text-gray-600 mt-1">${topRec.category} - $${topRec.cost.toLocaleString()}</p>
                <div class="flex justify-between items-baseline mt-4">
                    <span class="text-3xl font-bold ${tierColor}">${topRec.scores.score.toFixed(1)}</span>
                </div>
            </div>`;
    }
    initDashboardCharts();
}

function initDashboardCharts() {
    initScoreDistributionChart();
    initTierDistributionChart();
}

function renderComparisonTable() {
    const tbody = document.getElementById('comparison-table-body');
    const sortedData = [...domainData].sort((a, b) => {
        let valA = typeof a.scores[currentSort.column] !== 'undefined' ? a.scores[currentSort.column] : a[currentSort.column];
        let valB = typeof b.scores[currentSort.column] !== 'undefined' ? b.scores[currentSort.column] : b[currentSort.column];
        
        if (typeof valA === 'string') {
            return currentSort.order === 'asc' ? valA.localeCompare(valB) : valB.localeCompare(valA);
        } else {
            return currentSort.order === 'asc' ? valA - valB : valB - valA;
        }
    });

    tbody.innerHTML = sortedData.map(d => {
        const tierClass = d.scores.score >= 7 ? 'tier-1' : d.scores.score >= 5 ? 'tier-2' : 'tier-3';
        return `
            <tr class="bg-white border-b hover:bg-gray-50 cursor-pointer ${tierClass}" onclick="showModal('${d.name}')">
                <th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">${d.name}</th>
                <td class="px-6 py-4">${d.scores.clarity}</td>
                <td class="px-6 py-4">${d.scores.uniqueness}</td>
                <td class="px-6 py-4">${d.scores.seo}</td>
                <td class="px-6 py-4">${d.scores.international}</td>
                <td class="px-6 py-4">${d.scores.legal}</td>
                <td class="px-6 py-4 font-bold text-gray-800">${d.scores.score.toFixed(1)}</td>
            </tr>
        `;
    }).join('');

    const headers = document.querySelectorAll('.sortable-header');
    headers.forEach(header => {
        header.addEventListener('click', () => {
            const sortKey = header.dataset.sort;
            if (currentSort.column === sortKey) {
                currentSort.order = currentSort.order === 'asc' ? 'desc' : 'asc';
            } else {
                currentSort.column = sortKey;
                currentSort.order = 'desc';
            }
            headers.forEach(h => { h.classList.remove('active', 'asc', 'desc'); h.className = h.className.replace(/ asc| desc/g, ''); });
            header.classList.add('active', currentSort.order);
            renderComparisonTable();
        });
    });
}

function renderThemes() {
    const container = document.getElementById('themes-container');
    container.innerHTML = Object.keys(themeInfo).map(theme => {
        const domainsInTheme = domainData.filter(d => d.category === theme);
        if (domainsInTheme.length === 0) return '';
        return `
            <div class="bg-white p-6 rounded-lg shadow-lg">
                <h3 class="text-2xl font-bold text-[#A57C5A] mb-2">${theme}</h3>
                <p class="text-gray-600 mb-4">${themeInfo[theme].description}</p>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <h4 class="font-semibold text-green-600">Strengths</h4>
                        <p class="text-sm text-gray-500">${themeInfo[theme].pros}</p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-red-600">Weaknesses</h4>
                        <p class="text-sm text-gray-500">${themeInfo[theme].cons}</p>
                    </div>
                </div>
                <div class="mt-6 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
                    ${domainsInTheme.sort((a,b) => b.scores.score - a.scores.score).map(d => {
                        const tierClass = d.scores.score >= 7 ? 'tier-1' : d.scores.score >= 5 ? 'tier-2' : 'tier-3';
                        return `
                        <div class="p-4 rounded-md border-l-4 cursor-pointer hover:shadow-md transition-shadow bg-gray-50 ${tierClass}" onclick="showModal('${d.name}')">
                            <div class="flex justify-between items-center">
                                <span class="font-semibold text-gray-800">${d.name}</span>
                                <span class="font-bold text-lg text-gray-700">${d.scores.score.toFixed(1)}</span>
                            </div>
                        </div>
                        `
                    }).join('')}
                </div>
            </div>
        `;
    }).join('');
}


function setupModal() {
    const modal = document.getElementById('modal');
    const closeButtons = [document.getElementById('modal-close'), document.getElementById('modal-close-footer')];
    closeButtons.forEach(btn => btn.addEventListener('click', () => modal.classList.add('hidden')));
    modal.addEventListener('click', (e) => {
        if (e.target === modal) {
            modal.classList.add('hidden');
        }
    });
}

function showModal(domainName) {
    const domain = domainData.find(d => d.name === domainName);
    if (domain) {
        document.getElementById('modal-title').textContent = domain.name;
        document.getElementById('modal-subtitle').textContent = `Category: ${domain.category} | Domain Cost: $${domain.cost.toLocaleString()}`;
        
        const scoreBars = Object.keys(domain.scores).map(key => {
            if (key === 'score') return '';
            const score = domain.scores[key];
            const color = score > 7 ? 'bg-green-500' : score >= 5 ? 'bg-yellow-500' : 'bg-red-500';
            return `
                <div class="mb-2">
                    <div class="flex justify-between mb-1">
                        <span class="text-sm font-medium text-gray-700 capitalize">${key.replace(/([A-Z])/g, ' $1')}</span>
                        <span class="text-sm font-medium text-gray-700">${score}/10</span>
                    </div>
                    <div class="w-full bg-gray-200 rounded-full h-2.5">
                        <div class="${color} h-2.5 rounded-full" style="width: ${score * 10}%"></div>
                    </div>
                </div>
            `;
        }).join('');

        document.getElementById('modal-body').innerHTML = `
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <h4 class="font-bold text-lg mb-3">Analysis Summary</h4>
                    <p class="text-gray-600">${domain.analysis}</p>
                </div>
                <div>
                    <h4 class="font-bold text-lg mb-3">Scoring Breakdown</h4>
                    ${scoreBars}
                    <div class="mt-4 pt-4 border-t">
                        <div class="flex justify-between items-center">
                           <span class="text-lg font-bold text-gray-800">Overall Strategic Score</span>
                           <span class="text-2xl font-bold text-[#A57C5A]">${domain.scores.score.toFixed(1)}</span>
                        </div>
                    </div>
                </div>
            </div>
        `;
        document.getElementById('modal').classList.remove('hidden');
        document.getElementById('modal').classList.add('flex');
    }
}


function initScoreDistributionChart() {
    const ctx = document.getElementById('scoreDistributionChart').getContext('2d');
    if (charts.scoreDistribution) charts.scoreDistribution.destroy();
    
    const scoreBrackets = { '0-2': 0, '2-4': 0, '4-6': 0, '6-8': 0, '8-10': 0 };
    domainData.forEach(d => {
        const score = d.scores.score;
        if (score < 2) scoreBrackets['0-2']++;
        else if (score < 4) scoreBrackets['2-4']++;
        else if (score < 6) scoreBrackets['4-6']++;
        else if (score < 8) scoreBrackets['6-8']++;
        else scoreBrackets['8-10']++;
    });

    charts.scoreDistribution = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: Object.keys(scoreBrackets),
            datasets: [{
                label: 'Number of Brands',
                data: Object.values(scoreBrackets),
                backgroundColor: ['#ef4444', '#f97316', '#eab308', '#84cc16', '#22c55e'],
                borderRadius: 4
            }]
        },
        options: {
            responsive: true, maintainAspectRatio: false,
            plugins: { legend: { display: false }, tooltip: { displayColors: false } },
            scales: {
                y: { beginAtZero: true, grid: { drawOnChartArea: false }, ticks: { stepSize: 2 } },
                x: { grid: { display: false }, title: { display: true, text: 'Strategic Score Bracket'} }
            }
        }
    });
}

function initTierDistributionChart() {
    const ctx = document.getElementById('tierDistributionChart').getContext('2d');
    if (charts.tierDistribution) charts.tierDistribution.destroy();
    
    const tiers = { 'Top Tier (7+)': 0, 'Viable (5-7)': 0, 'High-Risk / Flawed (<5)': 0 };
    domainData.forEach(d => {
        const score = d.scores.score;
        if (score >= 7) tiers['Top Tier (7+)']++;
        else if (score >= 5) tiers['Viable (5-7)']++;
        else tiers['High-Risk / Flawed (<5)']++;
    });

    charts.tierDistribution = new Chart(ctx, {
        type: 'doughnut',
        data: {
            labels: Object.keys(tiers),
            datasets: [{
                data: Object.values(tiers),
                backgroundColor: ['#22c55e', '#f97316', '#ef4444'],
                borderColor: '#F8F7F4',
                borderWidth: 4
            }]
        },
        options: {
            responsive: true, maintainAspectRatio: false,
            plugins: {
                legend: { position: 'right' }
            }
        }
    });
}

function initRiskRewardChart() {
    const ctx = document.getElementById('riskRewardChart').getContext('2d');
    if (charts.riskReward) charts.riskReward.destroy();
    
    const chartData = domainData.map(d => {
        const riskScore = 10 - ((d.scores.uniqueness + d.scores.legal) / 2);
        return {
            x: riskScore,
            y: d.scores.clarity,
            r: d.scores.score * 2.5,
            name: d.name
        };
    });

    charts.riskReward = new Chart(ctx, {
        type: 'bubble',
        data: {
            datasets: [{
                label: 'Brand Candidates',
                data: chartData,
                backgroundColor: (context) => {
                    if(!context.raw) { return 'rgba(0,0,0,0.1)'; }
                    const data = context.raw;
                    if (data.x < 4 && data.y > 6) return 'rgba(34, 197, 94, 0.7)';
                    if (data.x >= 4 && data.y > 6) return 'rgba(234, 179, 8, 0.7)';
                    if (data.x < 4 && data.y <= 6) return 'rgba(249, 115, 22, 0.7)';
                    return 'rgba(239, 68, 68, 0.7)';
                },
                borderColor: 'rgba(0,0,0,0.2)'
            }]
        },
        options: {
            responsive: true, maintainAspectRatio: false,
            plugins: {
                legend: { display: false },
                tooltip: {
                    callbacks: {
                        label: function(context) {
                            const d = context.raw;
                            return `${d.name}: Risk ${d.x.toFixed(1)}, Reward ${d.y}`;
                        }
                    }
                },
                annotation: {
                    annotations: {
                        xLine: { type: 'line', xMin: 4, xMax: 4, borderColor: 'rgba(0,0,0,0.2)', borderWidth: 1, borderDash: [6, 6] },
                        yLine: { type: 'line', yMin: 6, yMax: 6, borderColor: 'rgba(0,0,0,0.2)', borderWidth: 1, borderDash: [6, 6] },
                        topLeftLabel: { type: 'label', xValue: 2, yValue: 8, content: 'Prime Candidates', font: {size: 14}, color: 'rgba(0,0,0,0.5)'},
                        topRightLabel: { type: 'label', xValue: 7, yValue: 8, content: 'High-Stakes', font: {size: 14}, color: 'rgba(0,0,0,0.5)'},
                        bottomLeftLabel: { type: 'label', xValue: 2, yValue: 4, content: 'Low Potential', font: {size: 14}, color: 'rgba(0,0,0,0.5)'},
                        bottomRightLabel: { type: 'label', xValue: 7, yValue: 4, content: 'Avoid', font: {size: 14}, color: 'rgba(0,0,0,0.5)'}
                    }
                }
            },
            scales: {
                x: { title: { display: true, text: 'Market & Legal Risk (Higher is worse)' }, min: 0, max: 10 },
                y: { title: { display: true, text: 'Brand Clarity / Reward' }, min: 0, max: 10 }
            },
            onClick: (e, elements) => {
                if (elements.length > 0) {
                    const domainName = elements[0].element.$context.raw.name;
                    showModal(domainName);
                }
            }
        }
    });
}
</script>
</body>
</html>