File size: 34,067 Bytes
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
545
546
547
548
549
550
551
552
<!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-orange-600 mb-2">⚠️ Top 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: 'Paix', category: 'Abstract', scores: { clarity: 8, uniqueness: 8, seo: 6, international: 8, legal: 7, score: 7.4 }, analysis: 'French for "peace". Excellent brand potential due to its elegant, memorable, and conceptually relevant nature. However, the premium Paix.com domain is unavailable, and the name is used by other entities (PAIX Data Centres), creating a moderate trademark risk that requires a full clearance search. Viable only with a clear strategy to acquire the domain or brand around an alternative.' },
    { name: 'Insure Pax', category: 'Conceptual', scores: { clarity: 7, uniqueness: 7, seo: 7, international: 6, legal: 6, score: 6.6 }, analysis: 'Combines the direct "Insure" with the evocative "Pax" (peace). The name is clear and positive. Risks include trademark conflicts with PAX Labs and PAX Financial, and potential for brand confusion in Arabic-speaking markets where "Pax" can mean "passengers". A viable option, but requires careful marketing and legal vetting.' },
    { name: 'Insure Bridge', category: 'Connector', scores: { clarity: 7, uniqueness: 3, seo: 3, international: 5, legal: 3, score: 4.2 }, analysis: 'A descriptive name using a common "connector" metaphor. The concept is clear but overused. Faces high risk of confusion with existing insurtechs like bridge.insure and a registered trademark for "The Benefit Bridge". Legally indefensible and lacks originality.' },
    { name: 'Insure Link', category: 'Connector', scores: { clarity: 7, uniqueness: 3, seo: 3, international: 5, legal: 3, score: 4.2 }, analysis: 'Similar to Insure Bridge, this name is highly descriptive but generic. It directly conflicts with "InsurLink," a product name used by major industry players like Vertafore and USI Insurance Services. The name is legally and commercially unviable.' },
    { name: 'Insure U', category: 'Descriptive', scores: { clarity: 6, uniqueness: 4, seo: 4, international: 6, legal: 2, score: 4.4 }, analysis: 'A simple, descriptive name that is easy to understand. However, it is legally unavailable. The domain InsureU.com redirects to a competitor, and a trademark is already registered for "INSURE-U.COM WE MAKE HEALTH INSURANCE EASIER" by another agency.' },
    { name: 'The Connect', category: 'Connector', scores: { clarity: 5, uniqueness: 2, seo: 2, international: 5, legal: 1, score: 3.0 }, analysis: 'A generic and widely used term. The name has a fatal flaw: a direct and overwhelming trademark conflict with "CONNECT, powered by American Family Insurance," a major insurance brand. This makes the name legally untenable for use in the insurance sector.' },
    { name: 'Insura', category: 'Descriptive', scores: { clarity: 4, uniqueness: 2, seo: 2, international: 5, legal: 2, score: 3.0 }, analysis: 'A generic name derived from "insurance". The domain Insura.com redirects to a major competitor (insure.com). The name is unregistrable as a trademark due to being merely descriptive and lacks any distinctiveness to build a brand upon.' },
    { name: 'The Insure', category: 'Descriptive', scores: { clarity: 4, uniqueness: 2, seo: 2, international: 5, legal: 2, score: 3.0 }, analysis: 'Similar to "Insura," adding "The" does not solve the core problem of being generic and descriptive. The domain is owned by a competitor, and the name is legally indefensible and difficult to brand effectively.' },
    { name: 'Ensure U', category: 'Descriptive', scores: { clarity: 3, uniqueness: 3, seo: 3, international: 4, legal: 1, score: 2.8 }, analysis: 'Faces an insurmountable trademark conflict with Abbott\'s globally recognized "Ensure" brand of nutritional products. The phonetic similarity to "Insure U" creates a secondary legal risk. Impossible to register, defend, or brand.' },
    { name: 'Insure Joint', category: 'Descriptive', scores: { clarity: 4, uniqueness: 5, seo: 5, international: 4, legal: 2, score: 4.0 }, analysis: 'This name is a generic legal term ("joint insurance"), making it extremely difficult to trademark as it would be considered "merely descriptive" of a service type. It also creates potential brand confusion regarding the company\'s ownership structure.' },
    { name: 'ARO', category: 'Acronym', scores: { clarity: 2, uniqueness: 3, seo: 2, international: 4, legal: 3, score: 2.8 }, analysis: 'A three-letter acronym with a premium .com domain owned by a major organization (aro.org). The trademark landscape is crowded, with a previously abandoned application for "ARO" in the insurance class. High risk and low brand potential.' },
    { name: 'EVA', category: 'Acronym', scores: { clarity: 4, uniqueness: 3, seo: 2, international: 5, legal: 2, score: 3.2 }, analysis: 'The domain EVA.com is owned by a major airline. The name has a registered trademark for "Economic Value Added" in the financial sector, creating a direct conflict. While it has a positive meaning in Arabic ("life"), the legal and digital barriers are too high.' },
    { name: 'ZAX', category: 'Acronym', scores: { clarity: 2, uniqueness: 4, seo: 3, international: 4, legal: 3, score: 3.2 }, analysis: 'The domain ZAX.com redirects to Zacks Investment Research, a major financial firm. The trademark landscape is crowded. The name has no inherent meaning, making it a poor choice with significant legal and digital obstacles.' }
];

const themeInfo = {
    Conceptual: {
        description: "This approach uses evocative words to communicate a core benefit or feeling, such as peace or security. They aim for a balance between clarity and brandability.",
        pros: "Communicates a positive value proposition, sounds professional, and can be highly brandable.",
        cons: "Good concepts can be competitive, leading to potential market saturation and the need for careful legal vetting."
    },
    Abstract: {
        description: "This strategy focuses on creating a unique, modern-sounding 'blank slate' name. The goal is to build a brand identity from scratch, free from the constraints of existing word associations.",
        pros: "High potential for uniqueness and strong legal protection.",
        cons: "Requires a significant marketing investment to build meaning and brand recognition. Can feel cold or lack direction if not executed well."
    },
    Connector: {
        description: "This strategy uses common 'connector' words like 'link' or 'bridge' to suggest a platform or service that links various parts of the insurance ecosystem. This approach prioritizes functional clarity.",
        pros: "The metaphor is intuitive and easily understood by consumers.",
        cons: "This branding category is highly saturated, making it difficult to find a unique and legally defensible name. Brands can appear as followers rather than innovators."
    },
    Descriptive: {
        description: "This category includes names that are generic or directly describe an insurance-related function. They attempt to capture a foundational, authoritative position in the market.",
        pros: "The names are simple and directly connected to the industry.",
        cons: "These names are almost always legally unavailable due to trademark conflicts and domain squatting. They are non-distinctive and exceptionally difficult to brand."
    },
    Acronym: {
        description: "This strategy uses short, three-letter acronyms to create a modern, tech-forward brand identity. The goal is a concise and memorable name.",
        pros: "Can be short and memorable once established.",
        cons: "The market for short, pronounceable acronyms is almost completely saturated. They face extremely high digital and legal barriers and require significant marketing to build meaning."
    }
};

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}</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}`;
        
        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: 5 } },
                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 * 1.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>