File size: 29,467 Bytes
28f4aa5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
// Global Variables
let currentData = {};
let charts = {};

// Initialize functions for each page
function initializeRecoveryPage() {
    loadMockData();
    updateRecoveryDashboard();
    createRecoveryCharts();
}

function initializeSleepPage() {
    loadMockData();
    updateSleepDashboard();
    createSleepCharts();
}

function initializeStrainPage() {
    loadMockData();
    updateStrainDashboard();
    createStrainCharts();
}

function initializeJournalPage() {
    loadMockData();
    setupJournalHandlers();
    updateJournalDashboard();
}

function initializeCoachPage() {
    loadMockData();
    setupCoachHandlers();
    updateCoachStats();
}

// Load Mock Data
function loadMockData() {
    // Generate mock data for the last 30 days
    currentData = {
        today: generateTodayData(),
        week: generateWeekData(),
        month: generateMonthData()
    };
}

function generateTodayData() {
    return {
        date: new Date().toISOString().split('T')[0],
        recoveryScore: Math.floor(Math.random() * 40) + 60, // 60-100
        hrv: Math.floor(Math.random() * 30) + 40, // 40-70 ms
        rhr: Math.floor(Math.random() * 20) + 50, // 50-70 bpm
        respRate: Math.floor(Math.random() * 6) + 12, // 12-18 breaths/min
        sleepPerformance: Math.floor(Math.random() * 30) + 70, // 70-100%
        sleepDuration: (Math.random() * 2 + 6).toFixed(1), // 6-8 hours
        sleepStages: {
            deep: (Math.random() * 1.5 + 1).toFixed(1),
            rem: (Math.random() * 2 + 1.5).toFixed(1),
            light: (Math.random() * 3 + 3).toFixed(1),
            awake: (Math.random() * 0.5 + 0.2).toFixed(1)
        },
        dailyStrain: Math.floor(Math.random() * 15) + 5, // 5-20
        maxHR: Math.floor(Math.random() * 50) + 140, // 140-190 bpm
        avgHR: Math.floor(Math.random() * 30) + 80, // 80-110 bpm
        calories: Math.floor(Math.random() * 1000) + 500, // 500-1500 kcal
        activities: generateActivities()
    };
}

function generateWeekData() {
    const data = [];
    for (let i = 6; i >= 0; i--) {
        const date = new Date();
        date.setDate(date.getDate() - i);
        data.push({
            date: date.toISOString().split('T')[0],
            recoveryScore: Math.floor(Math.random() * 40) + 60,
            strain: Math.floor(Math.random() * 15) + 5,
            sleepHours: (Math.random() * 2 + 6).toFixed(1)
        });
    }
    return data;
}

function generateMonthData() {
    const data = [];
    for (let i = 29; i >= 0; i--) {
        const date = new Date();
        date.setDate(date.getDate() - i);
        data.push({
            date: date.toISOString().split('T')[0],
            recoveryScore: Math.floor(Math.random() * 40) + 60,
            hrv: Math.floor(Math.random() * 30) + 40,
            rhr: Math.floor(Math.random() * 20) + 50
        });
    }
    return data;
}

function generateActivities() {
    const types = ['Running', 'Weight Training', 'Yoga', 'Cycling', 'Swimming'];
    const activities = [];
    const count = Math.floor(Math.random() * 3) + 1;
    
    for (let i = 0; i < count; i++) {
        activities.push({
            type: types[Math.floor(Math.random() * types.length)],
            duration: Math.floor(Math.random() * 60) + 20,
            strain: Math.floor(Math.random() * 10) + 1,
            calories: Math.floor(Math.random() * 300) + 100
        });
    }
    return activities;
}

// Update Recovery Dashboard
function updateRecoveryDashboard() {
    const today = currentData.today;
    
    // Update gauge
    const gauge = document.querySelector('custom-recovery-gauge');
    if (gauge) {
        gauge.setAttribute('score', today.recoveryScore);
    }
    
    // Update metrics
    document.getElementById('hrvValue').textContent = today.hrv;
    document.getElementById('rhrValue').textContent = today.rhr;
    document.getElementById('respRateValue').textContent = today.respRate;
    
    // Calculate strain target based on recovery
    let strainTarget;
    if (today.recoveryScore > 80) {
        strainTarget = '14.0-17.9';
    } else if (today.recoveryScore > 60) {
        strainTarget = '10.0-13.9';
    } else {
        strainTarget = '0.0-9.9';
    }
    document.getElementById('strainTarget').textContent = strainTarget;
    
    // Update insights
    updateRecoveryInsights(today);
}

function updateRecoveryInsights(data) {
    const insights = document.getElementById('insights');
    const messages = [];
    
    if (data.recoveryScore > 80) {
        messages.push({
            icon: 'check-circle',
            color: 'text-green-400',
            text: 'Excellent recovery! You\'re ready for high-intensity training today.'
        });
    } else if (data.recoveryScore > 60) {
        messages.push({
            icon: 'alert-circle',
            color: 'text-yellow-400',
            text: 'Moderate recovery. Consider a balanced workout with adequate rest periods.'
        });
    } else {
        messages.push({
            icon: 'x-circle',
            color: 'text-red-400',
            text: 'Low recovery detected. Focus on active recovery and proper nutrition today.'
        });
    }
    
    if (data.hrv > 60) {
        messages.push({
            icon: 'trending-up',
            color: 'text-green-400',
            text: 'Your HRV is trending positively, indicating good autonomic balance.'
        });
    }
    
    if (data.rhr < 60) {
        messages.push({
            icon: 'heart',
            color: 'text-blue-400',
            text: 'Your resting heart rate is excellent, showing strong cardiovascular fitness.'
        });
    }
    
    insights.innerHTML = messages.map(msg => `
        <div class="flex items-start space-x-3">
            <i data-feather="${msg.icon}" class="w-5 h-5 ${msg.color} mt-1"></i>
            <p class="text-gray-300">${msg.text}</p>
        </div>
    `).join('');
    
    feather.replace();
}

// Create Recovery Charts
function createRecoveryCharts() {
    // Recovery Trend Chart
    const ctx1 = document.getElementById('recoveryTrendChart');
    if (ctx1) {
        charts.recoveryTrend = new Chart(ctx1, {
            type: 'line',
            data: {
                labels: currentData.month.map(d => new Date(d.date).toLocaleDateString('en', { month: 'short', day: 'numeric' })),
                datasets: [{
                    label: 'Recovery Score',
                    data: currentData.month.map(d => d.recoveryScore),
                    borderColor: '#10b981',
                    backgroundColor: 'rgba(16, 185, 129, 0.1)',
                    tension: 0.4
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true,
                        max: 100,
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    },
                    x: {
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    }
                }
            }
        });
    }
    
    // HRV Trend Chart
    const ctx2 = document.getElementById('hrvTrendChart');
    if (ctx2) {
        charts.hrvTrend = new Chart(ctx2, {
            type: 'line',
            data: {
                labels: currentData.month.slice(-7).map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })),
                datasets: [{
                    label: 'HRV',
                    data: currentData.month.slice(-7).map(d => d.hrv),
                    borderColor: '#8b5cf6',
                    backgroundColor: 'rgba(139, 92, 246, 0.1)',
                    tension: 0.4
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    y: {
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    },
                    x: {
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    }
                }
            }
        });
    }
    
    // RHR Trend Chart
    const ctx3 = document.getElementById('rhrTrendChart');
    if (ctx3) {
        charts.rhrTrend = new Chart(ctx3, {
            type: 'line',
            data: {
                labels: currentData.month.slice(-7).map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })),
                datasets: [{
                    label: 'Resting HR',
                    data: currentData.month.slice(-7).map(d => d.rhr),
                    borderColor: '#3b82f6',
                    backgroundColor: 'rgba(59, 130, 246, 0.1)',
                    tension: 0.4
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    y: {
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    },
                    x: {
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    }
                }
            }
        });
    }
}

// Update Sleep Dashboard
function updateSleepDashboard() {
    const today = currentData.today;
    
    document.getElementById('sleepPerformance').textContent = today.sleepPerformance;
    document.getElementById('sleepDuration').textContent = today.sleepDuration;
    document.getElementById('sleepEfficiency').textContent = Math.floor(Math.random() * 20) + 80; // 80-100%
    
    // Update sleep stages
    document.getElementById('deepSleep').textContent = today.sleepStages.deep;
    document.getElementById('remSleep').textContent = today.sleepStages.rem;
    document.getElementById('lightSleep').textContent = today.sleepStages.light;
    document.getElementById('awakeTime').textContent = today.sleepStages.awake;
    
    // Update sleep planner
    const bedtime = '10:30 PM';
    const wakeTime = '6:30 AM';
    const sleepNeed = '8h 0m';
    
    document.getElementById('bedtime').textContent = bedtime;
    document.getElementById('wakeTime').textContent = wakeTime;
    document.getElementById('sleepNeed').textContent = sleepNeed;
}

// Create Sleep Charts
function createSleepCharts() {
    const today = currentData.today;
    
    // Sleep Stages Donut Chart
    const ctx1 = document.getElementById('sleepStagesChart');
    if (ctx1) {
        charts.sleepStages = new Chart(ctx1, {
            type: 'doughnut',
            data: {
                labels: ['Deep', 'REM', 'Light', 'Awake'],
                datasets: [{
                    data: [
                        parseFloat(today.sleepStages.deep),
                        parseFloat(today.sleepStages.rem),
                        parseFloat(today.sleepStages.light),
                        parseFloat(today.sleepStages.awake)
                    ],
                    backgroundColor: ['#8b5cf6', '#3b82f6', '#60a5fa', '#6b7280']
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    }
                }
            }
        });
    }
    
    // Weekly Sleep Chart
    const ctx2 = document.getElementById('weeklySleepChart');
    if (ctx2) {
        charts.weeklySleep = new Chart(ctx2, {
            type: 'bar',
            data: {
                labels: currentData.week.map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })),
                datasets: [{
                    label: 'Sleep Hours',
                    data: currentData.week.map(d => parseFloat(d.sleepHours)),
                    backgroundColor: '#3b82f6'
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true,
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    },
                    x: {
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    }
                }
            }
        });
    }
}

// Update Strain Dashboard
function updateStrainDashboard() {
    const today = currentData.today;
    
    document.getElementById('dailyStrain').textContent = today.dailyStrain;
    document.getElementById('maxHR').textContent = today.maxHR;
    document.getElementById('avgHR').textContent = today.avgHR;
    document.getElementById('calories').textContent = today.calories;
    document.getElementById('activeTime').textContent = Math.floor(today.dailyStrain * 15);
    
    // Update strain status
    const statusEl = document.getElementById('strainStatus');
    if (today.dailyStrain >= 15) {
        statusEl.textContent = 'High Intensity';
        statusEl.className = 'px-4 py-2 rounded-full text-sm font-semibold bg-red-900 text-red-400';
    } else if (today.dailyStrain >= 10) {
        statusEl.textContent = 'Moderate';
        statusEl.className = 'px-4 py-2 rounded-full text-sm font-semibold bg-yellow-900 text-yellow-400';
    } else {
        statusEl.textContent = 'Light';
        statusEl.className = 'px-4 py-2 rounded-full text-sm font-semibold bg-green-900 text-green-400';
    }
    
    // Update activities list
    const activitiesList = document.getElementById('activitiesList');
    if (activitiesList) {
        activitiesList.innerHTML = today.activities.map(activity => `
            <div class="activity-card bg-gray-800 rounded-lg p-4 flex items-center justify-between">
                <div class="flex items-center">
                    <i data-feather="activity" class="w-5 h-5 mr-3 text-blue-400"></i>
                    <div>
                        <div class="font-semibold">${activity.type}</div>
                        <div class="text-sm text-gray-400">${activity.duration} min</div>
                    </div>
                </div>
                <div class="text-right">
                    <div class="text-yellow-400 font-semibold">Strain ${activity.strain}</div>
                    <div class="text-sm text-gray-400">${activity.calories} kcal</div>
                </div>
            </div>
        `).join('');
        feather.replace();
    }
}

// Create Strain Charts
function createStrainCharts() {
    // Weekly Strain Chart
    const ctx1 = document.getElementById('weeklyStrainChart');
    if (ctx1) {
        charts.weeklyStrain = new Chart(ctx1, {
            type: 'line',
            data: {
                labels: currentData.week.map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })),
                datasets: [{
                    label: 'Daily Strain',
                    data: currentData.week.map(d => d.strain),
                    borderColor: '#f59e0b',
                    backgroundColor: 'rgba(245, 158, 11, 0.1)',
                    fill: true,
                    tension: 0.4
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true,
                        max: 21,
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    },
                    x: {
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    }
                }
            }
        });
    }
    
    // HR Zones Chart
    const ctx2 = document.getElementById('hrZonesChart');
    if (ctx2) {
        charts.hrZones = new Chart(ctx2, {
            type: 'bar',
            data: {
                labels: ['Zone 1', 'Zone 2', 'Zone 3', 'Zone 4', 'Zone 5'],
                datasets: [{
                    label: 'Time in Zone',
                    data: [45, 30, 20, 10, 5],
                    backgroundColor: ['#10b981', '#3b82f6', '#f59e0b', '#f97316', '#ef4444']
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true,
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    },
                    x: {
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    }
                }
            }
        });
    }
}

// Setup Journal Handlers
function setupJournalHandlers() {
    // Stress level buttons
    document.querySelectorAll('.stress-btn').forEach(btn => {
        btn.addEventListener('click', function() {
            document.querySelectorAll('.stress-btn').forEach(b => b.classList.remove('active'));
            this.classList.add('active');
        });
    });
    
    // Form submission
    document.getElementById('journalForm').addEventListener('submit', function(e) {
        e.preventDefault();
        // Mock save
        showNotification('Journal entry saved successfully!');
    });
}

// Update Journal Dashboard
function updateJournalDashboard() {
    // Positive behaviors
    const positiveBehaviors = [
        { behavior: 'Good Sleep Duration', impact: '+15% Recovery', icon: 'moon' },
        { behavior: 'No Alcohol', impact: '+8% HRV', icon: 'check' },
        { behavior: 'Moderate Exercise', impact: '+5% Sleep Quality', icon: 'activity' }
    ];
    
    // Negative behaviors
    const negativeBehaviors = [
        { behavior: 'High Stress', impact: '-12% Recovery', icon: 'alert-triangle' },
        { behavior: 'Late Caffeine', impact: '-8% Sleep Efficiency', icon: 'coffee' },
        { behavior: 'Inconsistent Schedule', impact: '-10% HRV', icon: 'clock' }
    ];
    
    const positiveEl = document.getElementById('positiveBehaviors');
    if (positiveEl) {
        positiveEl.innerHTML = positiveBehaviors.map(b => `
            <div class="flex items-center justify-between p-3 bg-green-900/20 border border-green-700 rounded-lg">
                <div class="flex items-center">
                    <i data-feather="${b.icon}" class="w-4 h-4 mr-2 text-green-400"></i>
                    <span class="text-gray-300">${b.behavior}</span>
                </div>
                <span class="text-green-400 font-semibold">${b.impact}</span>
            </div>
        `).join('');
    }
    
    const negativeEl = document.getElementById('negativeBehaviors');
    if (negativeEl) {
        negativeEl.innerHTML = negativeBehaviors.map(b => `
            <div class="flex items-center justify-between p-3 bg-red-900/20 border border-red-700 rounded-lg">
                <div class="flex items-center">
                    <i data-feather="${b.icon}" class="w-4 h-4 mr-2 text-red-400"></i>
                    <span class="text-gray-300">${b.behavior}</span>
                </div>
                <span class="text-red-400 font-semibold">${b.impact}</span>
            </div>
        `).join('');
    }
    
    feather.replace();
    
    // Behavior Chart
    const ctx = document.getElementById('behaviorChart');
    if (ctx) {
        charts.behavior = new Chart(ctx, {
            type: 'line',
            data: {
                labels: currentData.week.map(d => new Date(d.date).toLocaleDateString('en', { weekday: 'short' })),
                datasets: [{
                    label: 'Recovery Score',
                    data: currentData.week.map(d => d.recoveryScore),
                    borderColor: '#10b981',
                    yAxisID: 'y'
                }, {
                    label: 'Alcohol (1=yes, 0=no)',
                    data: [0, 1, 0, 0, 1, 0, 0],
                    borderColor: '#f59e0b',
                    yAxisID: 'y1'
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                scales: {
                    y: {
                        type: 'linear',
                        display: true,
                        position: 'left',
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    },
                    y1: {
                        type: 'linear',
                        display: true,
                        position: 'right',
                        grid: {
                            drawOnChartArea: false
                        },
                        ticks: {
                            color: '#999'
                        }
                    },
                    x: {
                        grid: {
                            color: '#333'
                        },
                        ticks: {
                            color: '#999'
                        }
                    }
                }
            }
        });
    }
    
    // Recent Entries
    const entriesEl = document.getElementById('recentEntries');
    if (entriesEl) {
        const entries = [
            { date: '2024-01-15', note: 'Feeling great after 8 hours of sleep!', score: 92 },
            { date: '2024-01-14', note: 'Tough workout, need extra rest', score: 68 },
            { date: '2024-01-13', note: 'Stressful day at work', score: 55 }
        ];
        
        entriesEl.innerHTML = entries.map(e => `
            <div class="journal-entry p-4 bg-gray-800 rounded-lg">
                <div class="flex justify-between items-start">
                    <div>
                        <div class="text-sm text-gray-400">${e.date}</div>
                        <div class="mt-1">${e.note}</div>
                    </div>
                    <div class="text-2xl font-bold ${e.score > 80 ? 'text-green-400' : e.score > 60 ? 'text-yellow-400' : 'text-red-400'}">${e.score}</div>
                </div>
            </div>
        `).join('');
    }
}

// Setup Coach Handlers
function setupCoachHandlers() {
    // Chat form
    document.getElementById('chatForm').addEventListener('submit', function(e) {
        e.preventDefault();
        const input = document.getElementById('chatInput');
        const message = input.value.trim();
        
        if (message) {
            addUserMessage(message);
            input.value = '';
            
            // Simulate coach response
            setTimeout(() => {
                addCoachMessage(getCoachResponse(message));
            }, 1000);
        }
    });
    
    // Quick prompts
    document.querySelectorAll('.coach-prompt').forEach(btn => {
        btn.addEventListener('click', function() {
            const prompt = this.dataset.prompt;
            addUserMessage(this.textContent.trim());
            
            setTimeout(() => {
                addCoachMessage(getCoachResponse(prompt));
            }, 1000);
        });
    });
}

// Update Coach Stats
function updateCoachStats() {
    const today = currentData.today;
    
    document.getElementById('coachRecovery').textContent = today.recoveryScore + '%';
    document.getElementById('coachSleep').textContent = today.sleepDuration;
    document.getElementById('coachStrain').textContent = today.dailyStrain;
    document.getElementById('coachHRV').textContent = today.hrv;
}

// Coach Chat Functions
function addUserMessage(message) {
    const chatMessages = document.getElementById('chatMessages');
    const messageEl = document.createElement('div');
    messageEl.className = 'flex items-start justify-end chat-message';
    messageEl.innerHTML = `
        <div class="bg-blue-600 rounded-lg p-4 max-w-md">
            <p>${message}</p>
        </div>
        <div class="w-8 h-8 bg-gray-700 rounded-full flex items-center justify-center ml-3 mt-1">
            <i data-feather="user" class="w-4 h-4"></i>
        </div>
    `;
    chatMessages.appendChild(messageEl);
    chatMessages.scrollTop = chatMessages.scrollHeight;
    feather.replace();
}

function addCoachMessage(message) {
    const chatMessages = document.getElementById('chatMessages');
    const messageEl = document.createElement('div');
    messageEl.className = 'flex items-start chat-message';
    messageEl.innerHTML = `
        <div class="w-8 h-8 bg-gradient-to-br from-blue-500 to-purple-600 rounded-full flex items-center justify-center mr-3 mt-1">
            <i data-feather="cpu" class="w-4 h-4"></i>
        </div>
        <div class="bg-gray-800 rounded-lg p-4 max-w-md">
            <p class="text-gray-300">${message}</p>
        </div>
    `;
    chatMessages.appendChild(messageEl);
    chatMessages.scrollTop = chatMessages.scrollHeight;
    feather.replace();
}

function getCoachResponse(prompt) {
    const today = currentData.today;
    const responses = {
        recovery: `Based on your data, today's recovery score is ${today.recoveryScore}%. ${today.recoveryScore > 80 ? 'You\'re in great shape! Consider a high-intensity workout.' : today.recoveryScore > 60 ? 'You\'re moderately recovered. A balanced workout would be ideal.' : 'Your recovery is low. Focus on active recovery and proper nutrition.'}`,
        workout: `With a recovery score of ${today.recoveryScore}% and yesterday's strain of ${today.dailyStrain}, I recommend ${today.recoveryScore > 80 ? 'a high-intensity interval training session' : today.recoveryScore > 60 ? 'moderate cardio with some light strength training' : 'active recovery like yoga or a light walk'} today.`,
        sleep: `You slept ${today.sleepDuration} hours last night with ${today.sleepPerformance}% performance. ${parseFloat(today.sleepDuration) < 7 ? 'Try to get at least 7-8 hours tonight. Consider going to bed 30 minutes earlier.' : 'Great job on sleep duration! Focus on consistency for optimal recovery.'}`,
        strain: `Your daily strain is ${today.dailyStrain}/21. ${today.dailyStrain >= 15 ? 'This was a high-strain day. Ensure adequate recovery tomorrow.' : today.dailyStrain >= 10 ? 'Moderate strain - good balance of activity and recovery.' : 'Light strain day. Consider increasing activity intensity tomorrow.'}`
    };
    
    return responses[prompt] || `I understand you're asking about ${prompt}. Based on your current metrics (Recovery: ${today.recoveryScore}%, Sleep: ${today.sleepDuration}h, Strain: ${today.dailyStrain}), I recommend focusing on consistent sleep patterns and balanced training intensity.`;
}

// Utility Functions
function showNotification(message) {
    // Create notification element
    const notification = document.createElement('div');
    notification.className = 'fixed bottom-4 right-4 bg-green-600 text-white px-6 py-3 rounded-lg shadow-lg z-50 animate-pulse';
    notification.textContent = message;
    document.body.appendChild(notification);
    
    // Remove after 3 seconds
    setTimeout(() => {
        notification.remove();
    }, 3000);
}