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
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
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MV Cable & Transformer Sizing Tool</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        electric: '#00B4D8',
                        powerblue: '#0077B6',
                        darkblue: '#03045E',
                    }
                }
            }
        }
    </script>
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #03045E 0%, #0077B6 50%, #00B4D8 100%);
        }
        .result-card {
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
        }
        .result-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .tab-content {
            display: none;
        }
        .tab-content.active {
            display: block;
            animation: fadeIn 0.5s ease;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .input-highlight {
            border-left: 4px solid #00B4D8;
        }
        .chart-container {
            position: relative;
            height: 400px;
            width: 100%;
        }
    </style>
</head>
<body class="bg-gray-50 font-sans">
    <header class="gradient-bg text-white">
        <div class="container mx-auto px-4 py-8">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h1 class="text-3xl md:text-4xl font-bold mb-2">
                        <i class="fas fa-bolt mr-2"></i> MV Power Sizing Tool
                    </h1>
                    <p class="text-lg opacity-90">Medium Voltage Cable & Transformer Sizing Calculator</p>
                </div>
                <div class="flex space-x-4">
                    <button onclick="switchTab('cable')" class="tab-btn bg-white text-powerblue px-6 py-2 rounded-full font-semibold shadow-md hover:bg-gray-100 transition">
                        <i class="fas fa-cable-car mr-2"></i> Cable Sizing
                    </button>
                    <button onclick="switchTab('transformer')" class="tab-btn bg-transparent border-2 border-white text-white px-6 py-2 rounded-full font-semibold hover:bg-white hover:text-powerblue transition">
                        <i class="fas fa-transformer mr-2"></i> Transformers
                    </button>
                </div>
            </div>
        </div>
    </header>

    <main class="container mx-auto px-4 py-8">
        <!-- Cable Sizing Tab -->
        <div id="cable-tab" class="tab-content active">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                <div class="p-6">
                    <h2 class="text-2xl font-bold text-darkblue mb-4 flex items-center">
                        <i class="fas fa-cable-car text-electric mr-3"></i> Medium Voltage Cable Sizing
                    </h2>
                    <p class="text-gray-600 mb-6">Enter the system parameters to calculate the appropriate cable size for your medium voltage application.</p>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div>
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="system-voltage">
                                    System Voltage (kV)
                                </label>
                                <select id="system-voltage" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight">
                                    <option value="3.3">3.3 kV</option>
                                    <option value="6.6">6.6 kV</option>
                                    <option value="11" selected>11 kV</option>
                                    <option value="22">22 kV</option>
                                    <option value="33">33 kV</option>
                                </select>
                            </div>
                            
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="load-current">
                                    Load Current (A)
                                </label>
                                <input type="number" id="load-current" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight" placeholder="e.g. 150">
                            </div>
                            
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="cable-length">
                                    Cable Length (m)
                                </label>
                                <input type="number" id="cable-length" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight" placeholder="e.g. 250">
                            </div>
                        </div>
                        
                        <div>
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="installation-method">
                                    Installation Method
                                </label>
                                <select id="installation-method" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight">
                                    <option value="buried">Buried Direct in Ground</option>
                                    <option value="duct">In Duct/Buried</option>
                                    <option value="tray">Cable Tray</option>
                                    <option value="ladder">Cable Ladder</option>
                                    <option value="air">In Air</option>
                                </select>
                            </div>
                            
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="soil-resistivity">
                                    Soil Thermal Resistivity (K.m/W)
                                </label>
                                <input type="number" id="soil-resistivity" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight" value="1.2" step="0.1">
                            </div>
                            
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="ambient-temp">
                                    Ambient Temperature (°C)
                                </label>
                                <input type="number" id="ambient-temp" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight" value="30" step="1">
                            </div>
                        </div>
                    </div>
                    
                    <div class="flex justify-center mt-6">
                        <button onclick="calculateCableSize()" class="gradient-bg text-white px-8 py-3 rounded-full font-semibold hover:opacity-90 transition flex items-center">
                            <i class="fas fa-calculator mr-2"></i> Calculate Cable Size
                        </button>
                    </div>
                </div>
            </div>
            
            <div id="cable-results" class="hidden">
                <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 result-card">
                    <div class="p-6">
                        <h3 class="text-xl font-bold text-darkblue mb-4 flex items-center">
                            <i class="fas fa-file-alt text-electric mr-3"></i> Cable Sizing Results
                        </h3>
                        
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <p class="text-gray-600 font-medium">Recommended Size</p>
                                <p id="recommended-size" class="text-2xl font-bold text-electric">-- mm²</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <p class="text-gray-600 font-medium">Current Capacity</p>
                                <p id="current-capacity" class="text-2xl font-bold text-electric">-- A</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <p class="text-gray-600 font-medium">Voltage Drop</p>
                                <p id="voltage-drop" class="text-2xl font-bold text-electric">-- %</p>
                            </div>
                        </div>
                        
                        <div class="mb-4">
                            <h4 class="font-semibold text-gray-700 mb-2">Cable Specifications:</h4>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <div class="grid grid-cols-2 gap-4">
                                    <div>
                                        <p class="text-gray-600">Type: <span id="cable-type" class="font-medium">--</span></p>
                                        <p class="text-gray-600">Insulation: <span id="cable-insulation" class="font-medium">--</span></p>
                                    </div>
                                    <div>
                                        <p class="text-gray-600">Sheath: <span id="cable-sheath" class="font-medium">--</span></p>
                                        <p class="text-gray-600">Conductor: <span id="cable-conductor" class="font-medium">--</span></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mt-6">
                            <h4 class="font-semibold text-gray-700 mb-2">Notes:</h4>
                            <ul class="list-disc pl-5 text-gray-600 space-y-1">
                                <li>Results are based on IEC 60502 standards</li>
                                <li>Consider derating factors for grouping and depth of burial</li>
                                <li>Verify short circuit withstand capacity</li>
                                <li>Consult manufacturer data for exact specifications</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- Interactive Power Loss Diagram -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 result-card">
                    <div class="p-6">
                        <h3 class="text-xl font-bold text-darkblue mb-4 flex items-center">
                            <i class="fas fa-chart-line text-electric mr-3"></i> Power Loss Analysis
                        </h3>
                        
                        <div class="mb-6">
                            <div class="flex flex-col md:flex-row gap-4 mb-4">
                                <div class="w-full md:w-1/3">
                                    <label class="block text-gray-700 font-medium mb-2" for="chart-type">
                                        Chart Type
                                    </label>
                                    <select id="chart-type" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight">
                                        <option value="length">Power Loss vs Cable Length</option>
                                        <option value="current">Power Loss vs Load Current</option>
                                        <option value="voltage">Power Loss vs System Voltage</option>
                                    </select>
                                </div>
                                <div class="w-full md:w-1/3">
                                    <label class="block text-gray-700 font-medium mb-2" for="cable-size-chart">
                                        Cable Size (mm²)
                                    </label>
                                    <select id="cable-size-chart" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight">
                                        <option value="35">35 mm²</option>
                                        <option value="50">50 mm²</option>
                                        <option value="70">70 mm²</option>
                                        <option value="95">95 mm²</option>
                                        <option value="120">120 mm²</option>
                                        <option value="150">150 mm²</option>
                                        <option value="185">185 mm²</option>
                                        <option value="240">240 mm²</option>
                                    </select>
                                </div>
                                <div class="w-full md:w-1/3">
                                    <label class="block text-gray-700 font-medium mb-2" for="chart-method">
                                        Installation Method
                                    </label>
                                    <select id="chart-method" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight">
                                        <option value="buried">Buried Direct</option>
                                        <option value="duct">In Duct</option>
                                        <option value="tray">Cable Tray</option>
                                        <option value="air">In Air</option>
                                    </select>
                                </div>
                            </div>
                            
                            <button onclick="updatePowerLossChart()" class="gradient-bg text-white px-6 py-2 rounded-full font-semibold hover:opacity-90 transition flex items-center">
                                <i class="fas fa-sync-alt mr-2"></i> Update Chart
                            </button>
                        </div>
                        
                        <div class="chart-container">
                            <canvas id="powerLossChart"></canvas>
                        </div>
                        
                        <div class="mt-6 bg-gray-50 p-4 rounded-lg">
                            <h4 class="font-semibold text-gray-700 mb-2">Key Observations:</h4>
                            <ul class="list-disc pl-5 text-gray-600 space-y-1">
                                <li>Power losses increase <span class="font-semibold">quadratically</span> with current (P = I²R)</li>
                                <li>Higher voltage systems show <span class="font-semibold">lower percentage</span> power losses</li>
                                <li>Larger cable sizes reduce losses but increase <span class="font-semibold">initial cost</span></li>
                                <li>Buried cables typically have <span class="font-semibold">better cooling</span> than tray installations</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6">
                    <h3 class="text-xl font-bold text-darkblue mb-4 flex items-center">
                        <i class="fas fa-info-circle text-electric mr-3"></i> Cable Sizing Guidelines
                    </h3>
                    
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="bg-electric text-white rounded-full p-2 mr-4">
                                <i class="fas fa-1"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">Current Carrying Capacity</h4>
                                <p class="text-gray-600">The cable must be able to carry the maximum load current without exceeding temperature limits.</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <div class="bg-electric text-white rounded-full p-2 mr-4">
                                <i class="fas fa-2"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">Voltage Drop</h4>
                                <p class="text-gray-600">Ensure voltage drop is within acceptable limits (typically 3-5% for distribution systems).</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <div class="bg-electric text-white rounded-full p-2 mr-4">
                                <i class="fas fa-3"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">Short Circuit Withstand</h4>
                                <p class="text-gray-600">Cable must withstand short circuit currents for the duration of protection operation.</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- Transformer Sizing Tab -->
        <div id="transformer-tab" class="tab-content">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                <div class="p-6">
                    <h2 class="text-2xl font-bold text-darkblue mb-4 flex items-center">
                        <i class="fas fa-transformer text-electric mr-3"></i> Measurement Transformer Sizing
                    </h2>
                    <p class="text-gray-600 mb-6">Calculate the appropriate current and voltage transformer specifications for your protection and metering needs.</p>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div>
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="transformer-type">
                                    Transformer Type
                                </label>
                                <select id="transformer-type" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight">
                                    <option value="current">Current Transformer (CT)</option>
                                    <option value="voltage">Voltage Transformer (VT)</option>
                                </select>
                            </div>
                            
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="primary-value">
                                    Primary Value
                                </label>
                                <div class="flex">
                                    <input type="number" id="primary-value" class="w-full px-4 py-3 rounded-l-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight" placeholder="e.g. 100">
                                    <span id="primary-unit" class="bg-gray-200 px-4 py-3 rounded-r-lg border border-l-0 border-gray-300">A</span>
                                </div>
                            </div>
                            
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="secondary-value">
                                    Secondary Value
                                </label>
                                <div class="flex">
                                    <input type="number" id="secondary-value" class="w-full px-4 py-3 rounded-l-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight" placeholder="e.g. 1 or 5">
                                    <span id="secondary-unit" class="bg-gray-200 px-4 py-3 rounded-r-lg border border-l-0 border-gray-300">A</span>
                                </div>
                            </div>
                        </div>
                        
                        <div>
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="accuracy-class">
                                    Accuracy Class
                                </label>
                                <select id="accuracy-class" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight">
                                    <option value="0.1">0.1 (Metering)</option>
                                    <option value="0.2">0.2 (Metering)</option>
                                    <option value="0.5">0.5 (Metering)</option>
                                    <option value="1">1 (General Purpose)</option>
                                    <option value="3">3 (Protection)</option>
                                    <option value="5">5 (Protection)</option>
                                    <option value="10">10 (Protection)</option>
                                </select>
                            </div>
                            
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="burden">
                                    Burden (VA)
                                </label>
                                <input type="number" id="burden" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight" placeholder="e.g. 15">
                            </div>
                            
                            <div class="mb-6">
                                <label class="block text-gray-700 font-medium mb-2" for="application">
                                    Application
                                </label>
                                <select id="application" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-electric focus:border-transparent input-highlight">
                                    <option value="metering">Metering</option>
                                    <option value="protection">Protection</option>
                                    <option value="both">Both (Metering & Protection)</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    
                    <div class="flex justify-center mt-6">
                        <button onclick="calculateTransformer()" class="gradient-bg text-white px-8 py-3 rounded-full font-semibold hover:opacity-90 transition flex items-center">
                            <i class="fas fa-calculator mr-2"></i> Calculate Transformer
                        </button>
                    </div>
                </div>
            </div>
            
            <div id="transformer-results" class="hidden">
                <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 result-card">
                    <div class="p-6">
                        <h3 class="text-xl font-bold text-darkblue mb-4 flex items-center">
                            <i class="fas fa-file-alt text-electric mr-3"></i> Transformer Sizing Results
                        </h3>
                        
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <p class="text-gray-600 font-medium">Ratio</p>
                                <p id="transformer-ratio" class="text-2xl font-bold text-electric">--</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <p class="text-gray-600 font-medium">Accuracy Class</p>
                                <p id="result-accuracy" class="text-2xl font-bold text-electric">--</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <p class="text-gray-600 font-medium">Burden</p>
                                <p id="result-burden" class="text-2xl font-bold text-electric">-- VA</p>
                            </div>
                        </div>
                        
                        <div class="mb-4">
                            <h4 class="font-semibold text-gray-700 mb-2">Specifications:</h4>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <div class="grid grid-cols-2 gap-4">
                                    <div>
                                        <p class="text-gray-600">Type: <span id="transformer-type-result" class="font-medium">--</span></p>
                                        <p class="text-gray-600">Application: <span id="transformer-application" class="font-medium">--</span></p>
                                    </div>
                                    <div>
                                        <p class="text-gray-600">Primary: <span id="transformer-primary" class="font-medium">--</span></p>
                                        <p class="text-gray-600">Secondary: <span id="transformer-secondary" class="font-medium">--</span></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mt-6">
                            <h4 class="font-semibold text-gray-700 mb-2">Recommendations:</h4>
                            <ul class="list-disc pl-5 text-gray-600 space-y-1">
                                <li>Verify short-time current rating matches system fault levels</li>
                                <li>Consider using dual-core CTs for metering and protection</li>
                                <li>Ensure burden doesn't exceed transformer rating</li>
                                <li>Check compliance with IEC 60044 standards</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6">
                    <h3 class="text-xl font-bold text-darkblue mb-4 flex items-center">
                        <i class="fas fa-info-circle text-electric mr-3"></i> Transformer Selection Guidelines
                    </h3>
                    
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="bg-electric text-white rounded-full p-2 mr-4">
                                <i class="fas fa-bolt"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">Current Transformers (CTs)</h4>
                                <p class="text-gray-600">Select CTs based on primary current, accuracy class, burden, and application (metering or protection).</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <div class="bg-electric text-white rounded-full p-2 mr-4">
                                <i class="fas fa-charging-station"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">Voltage Transformers (VTs)</h4>
                                <p class="text-gray-600">Choose VTs based on system voltage, accuracy requirements, and burden of connected instruments.</p>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <div class="bg-electric text-white rounded-full p-2 mr-4">
                                <i class="fas fa-exclamation-triangle"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">Safety Considerations</h4>
                                <p class="text-gray-600">Never open-circuit a CT secondary circuit or short-circuit a VT secondary circuit.</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>
    
    <footer class="gradient-bg text-white py-8">
        <div class="container mx-auto px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold mb-2">MV Power Sizing Tool</h3>
                    <p class="text-sm opacity-80">Professional tool for medium voltage electrical design</p>
                </div>
                <div class="flex space-x-4">
                    <a href="#" class="text-white hover:text-gray-200 transition">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-white hover:text-gray-200 transition">
                        <i class="fab fa-linkedin text-xl"></i>
                    </a>
                    <a href="#" class="text-white hover:text-gray-200 transition">
                        <i class="fas fa-envelope text-xl"></i>
                    </a>
                </div>
            </div>
            <div class="border-t border-white border-opacity-20 mt-6 pt-6 text-sm text-center opacity-80">
                <p>© 2023 MV Power Sizing Tool. All calculations are based on IEC standards.</p>
                <p class="mt-1">For professional engineering verification only.</p>
            </div>
        </div>
    </footer>

    <script>
        // Tab switching functionality
        function switchTab(tabName) {
            // Hide all tab contents
            document.querySelectorAll('.tab-content').forEach(tab => {
                tab.classList.remove('active');
            });
            
            // Show selected tab
            document.getElementById(`${tabName}-tab`).classList.add('active');
            
            // Update tab buttons
            document.querySelectorAll('.tab-btn').forEach(btn => {
                if (btn.textContent.includes(tabName.charAt(0).toUpperCase() + tabName.slice(1))) {
                    btn.classList.remove('bg-transparent', 'border-white', 'text-white');
                    btn.classList.add('bg-white', 'text-powerblue');
                } else {
                    btn.classList.remove('bg-white', 'text-powerblue');
                    btn.classList.add('bg-transparent', 'border-white', 'text-white');
                }
            });
        }
        
        // Update transformer units based on type
        document.getElementById('transformer-type').addEventListener('change', function() {
            const type = this.value;
            const primaryUnit = document.getElementById('primary-unit');
            const secondaryUnit = document.getElementById('secondary-unit');
            
            if (type === 'current') {
                primaryUnit.textContent = 'A';
                secondaryUnit.textContent = 'A';
            } else {
                primaryUnit.textContent = 'kV';
                secondaryUnit.textContent = 'V';
            }
        });
        
        // Cable sizing calculation
        function calculateCableSize() {
            // Get input values
            const voltage = parseFloat(document.getElementById('system-voltage').value);
            const current = parseFloat(document.getElementById('load-current').value);
            const length = parseFloat(document.getElementById('cable-length').value);
            const method = document.getElementById('installation-method').value;
            const soilResistivity = parseFloat(document.getElementById('soil-resistivity').value);
            const ambientTemp = parseFloat(document.getElementById('ambient-temp').value);
            
            // Validate inputs
            if (isNaN(current) || isNaN(length)) {
                alert('Please enter valid numbers for load current and cable length');
                return;
            }
            
            // Simplified calculation (real implementation would use detailed tables)
            let recommendedSize;
            let currentCapacity;
            let voltageDrop;
            
            if (current <= 100) {
                recommendedSize = 35;
                currentCapacity = 140;
                voltageDrop = 1.2;
            } else if (current <= 150) {
                recommendedSize = 50;
                currentCapacity = 170;
                voltageDrop = 0.9;
            } else if (current <= 200) {
                recommendedSize = 70;
                currentCapacity = 210;
                voltageDrop = 0.7;
            } else if (current <= 250) {
                recommendedSize = 95;
                currentCapacity = 250;
                voltageDrop = 0.5;
            } else {
                recommendedSize = 120;
                currentCapacity = 290;
                voltageDrop = 0.4;
            }
            
            // Apply derating factors
            let deratingFactor = 1.0;
            
            // Installation method derating
            if (method === 'buried') deratingFactor *= 0.9;
            else if (method === 'duct') deratingFactor *= 0.85;
            else if (method === 'tray') deratingFactor *= 0.8;
            else if (method === 'ladder') deratingFactor *= 0.75;
            
            // Soil resistivity derating
            if (soilResistivity > 1.0) deratingFactor *= (1.0 / soilResistivity);
            
            // Ambient temperature derating
            if (ambientTemp > 20) deratingFactor *= (1.0 - (ambientTemp - 20) * 0.005);
            
            // Apply derating
            currentCapacity = Math.round(currentCapacity * deratingFactor);
            
            // Adjust voltage drop for length
            voltageDrop = (voltageDrop * length / 100).toFixed(2);
            
            // Display results
            document.getElementById('recommended-size').textContent = recommendedSize + ' mm²';
            document.getElementById('current-capacity').textContent = currentCapacity + ' A';
            document.getElementById('voltage-drop').textContent = voltageDrop + ' %';
            
            // Set cable specifications based on voltage
            document.getElementById('cable-type').textContent = voltage >= 22 ? 'XLPE/SWA/PVC' : 'XLPE/PVC';
            document.getElementById('cable-insulation').textContent = 'XLPE';
            document.getElementById('cable-sheath').textContent = voltage >= 22 ? 'PVC' : 'LSZH';
            document.getElementById('cable-conductor').textContent = 'Copper';
            
            // Show results
            document.getElementById('cable-results').classList.remove('hidden');
            
            // Initialize power loss chart
            initializePowerLossChart();
            
            // Scroll to results
            document.getElementById('cable-results').scrollIntoView({ behavior: 'smooth' });
        }
        
        // Transformer calculation
        function calculateTransformer() {
            // Get input values
            const type = document.getElementById('transformer-type').value;
            const primary = parseFloat(document.getElementById('primary-value').value);
            const secondary = parseFloat(document.getElementById('secondary-value').value);
            const accuracy = document.getElementById('accuracy-class').value;
            const burden = parseFloat(document.getElementById('burden').value);
            const application = document.getElementById('application').value;
            
            // Validate inputs
            if (isNaN(primary) || isNaN(secondary) || isNaN(burden)) {
                alert('Please enter valid numbers for primary, secondary and burden values');
                return;
            }
            
            // Calculate ratio
            const ratio = `${primary}${type === 'current' ? 'A' : 'kV'}/${secondary}${type === 'current' ? 'A' : 'V'}`;
            
            // Display results
            document.getElementById('transformer-ratio').textContent = ratio;
            document.getElementById('result-accuracy').textContent = accuracy;
            document.getElementById('result-burden').textContent = burden + ' VA';
            
            // Set transformer specifications
            document.getElementById('transformer-type-result').textContent = 
                type === 'current' ? 'Current Transformer (CT)' : 'Voltage Transformer (VT)';
            document.getElementById('transformer-application').textContent = 
                application.charAt(0).toUpperCase() + application.slice(1);
            document.getElementById('transformer-primary').textContent = 
                primary + (type === 'current' ? 'A' : 'kV');
            document.getElementById('transformer-secondary').textContent = 
                secondary + (type === 'current' ? 'A' : 'V');
            
            // Show results
            document.getElementById('transformer-results').classList.remove('hidden');
            
            // Scroll to results
            document.getElementById('transformer-results').scrollIntoView({ behavior: 'smooth' });
        }

        // Power Loss Chart Variables
        let powerLossChart;

        // Initialize Power Loss Chart
        function initializePowerLossChart() {
            const ctx = document.getElementById('powerLossChart').getContext('2d');
            
            // Destroy previous chart if it exists
            if (powerLossChart) {
                powerLossChart.destroy();
            }
            
            // Create new chart
            powerLossChart = new Chart(ctx, {
                type: 'line',
                data: {
                    labels: generateChartLabels(),
                    datasets: [{
                        label: 'Power Loss (kW)',
                        data: generatePowerLossData(),
                        backgroundColor: 'rgba(0, 180, 216, 0.2)',
                        borderColor: 'rgba(0, 180, 216, 1)',
                        borderWidth: 2,
                        tension: 0.4,
                        fill: true
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    plugins: {
                        title: {
                            display: true,
                            text: getChartTitle(),
                            font: {
                                size: 16,
                                weight: 'bold'
                            }
                        },
                        tooltip: {
                            callbacks: {
                                label: function(context) {
                                    return `Power Loss: ${context.parsed.y.toFixed(2)} kW`;
                                }
                            }
                        },
                        legend: {
                            display: false
                        }
                    },
                    scales: {
                        x: {
                            title: {
                                display: true,
                                text: getXAxisLabel(),
                                font: {
                                    weight: 'bold'
                                }
                            }
                        },
                        y: {
                            title: {
                                display: true,
                                text: 'Power Loss (kW)',
                                font: {
                                    weight: 'bold'
                                }
                            },
                            min: 0
                        }
                    }
                }
            });
        }

        // Update Power Loss Chart
        function updatePowerLossChart() {
            if (!powerLossChart) {
                initializePowerLossChart();
                return;
            }
            
            // Update chart data
            powerLossChart.data.labels = generateChartLabels();
            powerLossChart.data.datasets[0].data = generatePowerLossData();
            powerLossChart.options.plugins.title.text = getChartTitle();
            powerLossChart.options.scales.x.title.text = getXAxisLabel();
            
            // Update chart
            powerLossChart.update();
        }

        // Generate chart labels based on selected chart type
        function generateChartLabels() {
            const chartType = document.getElementById('chart-type').value;
            
            if (chartType === 'length') {
                return Array.from({length: 10}, (_, i) => (i + 1) * 100); // 100m to 1000m in 100m steps
            } else if (chartType === 'current') {
                return Array.from({length: 10}, (_, i) => (i + 1) * 25); // 25A to 250A in 25A steps
            } else { // voltage
                return [3.3, 6.6, 11, 22, 33]; // Common MV voltages
            }
        }

        // Generate power loss data based on current inputs
        function generatePowerLossData() {
            const chartType = document.getElementById('chart-type').value;
            const cableSize = parseFloat(document.getElementById('cable-size-chart').value);
            const installationMethod = document.getElementById('chart-method').value;
            const baseCurrent = parseFloat(document.getElementById('load-current').value) || 100;
            const baseLength = parseFloat(document.getElementById('cable-length').value) || 100;
            const baseVoltage = parseFloat(document.getElementById('system-voltage').value) || 11;
            
            // Get resistance per km based on cable size (simplified)
            const resistancePerKm = getResistanceForSize(cableSize);
            
            // Get derating factor based on installation method
            const deratingFactor = getDeratingFactor(installationMethod);
            
            return generateChartLabels().map(value => {
                let current, length, voltage;
                
                if (chartType === 'length') {
                    current = baseCurrent;
                    length = value;
                    voltage = baseVoltage;
                } else if (chartType === 'current') {
                    current = value;
                    length = baseLength;
                    voltage = baseVoltage;
                } else { // voltage
                    current = baseCurrent;
                    length = baseLength;
                    voltage = value;
                }
                
                // Calculate power loss (P = I²R)
                const resistance = (resistancePerKm * length / 1000) * deratingFactor;
                const powerLoss = Math.pow(current, 2) * resistance / 1000; // in kW
                
                return powerLoss;
            });
        }

        // Get resistance for cable size (Ω/km)
        function getResistanceForSize(size) {
            // Simplified resistance values for copper conductors at 20°C
            const resistances = {
                35: 0.524,
                50: 0.387,
                70: 0.268,
                95: 0.193,
                120: 0.153,
                150: 0.124,
                185: 0.099,
                240: 0.075
            };
            
            return resistances[size] || 0.524;
        }

        // Get derating factor for installation method
        function getDeratingFactor(method) {
            const factors = {
                'buried': 1.0,
                'duct': 1.1,
                'tray': 1.2,
                'air': 1.15
            };
            
            return factors[method] || 1.0;
        }

        // Get chart title based on selected type
        function getChartTitle() {
            const chartType = document.getElementById('chart-type').value;
            const cableSize = document.getElementById('cable-size-chart').value;
            
            if (chartType === 'length') {
                return `Power Loss vs Cable Length (${cableSize}mm²)`;
            } else if (chartType === 'current') {
                return `Power Loss vs Load Current (${cableSize}mm²)`;
            } else {
                return `Power Loss vs System Voltage (${cableSize}mm²)`;
            }
        }

        // Get X-axis label based on selected type
        function getXAxisLabel() {
            const chartType = document.getElementById('chart-type').value;
            
            if (chartType === 'length') {
                return 'Cable Length (m)';
            } else if (chartType === 'current') {
                return 'Load Current (A)';
            } else {
                return 'System Voltage (kV)';
            }
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=acwk/test" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>