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
f8e8ea9
 
7ff6297
 
 
 
 
f8e8ea9
7ff6297
 
 
f8e8ea9
7ff6297
 
 
f8e8ea9
7ff6297
 
 
f8e8ea9
7ff6297
f8e8ea9
7ff6297
 
 
 
f8e8ea9
7ff6297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8e8ea9
 
 
 
 
7ff6297
 
 
 
 
 
 
f8e8ea9
7ff6297
 
 
 
 
 
 
 
 
 
 
 
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
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
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>ARIA COSMETIC | CMS</title>

  <!-- Tailwind CSS -->
  <script src="https://cdn.tailwindcss.com"></script>

  <!-- Google Fonts -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link
    href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,300;400;500;600;700&family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&display=swap"
    rel="stylesheet">

  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

  <!-- Chart.js -->
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

  <script>
    tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        brand: {
                            red: '#D90429',
                            dark: '#2B2D42',
                            light: '#EDF2F4',
                            gray: '#8D99AE'
                        }
                    },
                    fontFamily: {
                        serif: ['"Playfair Display"', 'serif'],
                        sans: ['"DM Sans"', 'sans-serif'],
                    }
                }
            }
        }
  </script>

  <style>
    body {
      font-family: 'DM Sans', sans-serif;
      background-color: #f8f9fa;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    .font-serif {
      font-family: 'Playfair Display', serif;
    }

    .glass-panel {
      background: rgba(255, 255, 255, 0.95);
      backdrop-filter: blur(10px);
      border: 1px solid rgba(255, 255, 255, 0.2);
    }

    .nav-item.active {
      background-color: #D90429;
      color: white;
      box-shadow: 0 4px 6px -1px rgba(217, 4, 41, 0.3);
    }

    .fade-in {
      animation: fadeIn 0.5s ease-in-out;
    }

    @keyframes fadeIn {
      from {
        opacity: 0;
        transform: translateY(10px);
      }

      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    ::-webkit-scrollbar {
      width: 8px;
    }

    ::-webkit-scrollbar-track {
      background: #f1f1f1;
    }

    ::-webkit-scrollbar-thumb {
      background: #D90429;
      border-radius: 4px;
    }

    ::-webkit-scrollbar-thumb:hover {
      background: #b10322;
    }

    .loader {
      border-top-color: #D90429;
      -webkit-animation: spinner 1.5s linear infinite;
      animation: spinner 1.5s linear infinite;
    }

    @keyframes spinner {
      0% {
        transform: rotate(0deg);
      }

      100% {
        transform: rotate(360deg);
      }
    }

    .company-card {
      transition: all 0.3s ease;
    }

    .company-card:hover {
      transform: translateY(-4px);
      box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    }

    .tab-active {
      border-bottom: 2px solid #D90429;
      color: #D90429;
    }

    .animate-pulse-slow {
      animation: pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    }

    @keyframes pulse {
      0%, 100% {
        opacity: 1;
      }
      50% {
        opacity: .7;
      }
    }
  </style>
</head>

<body class="text-gray-800 h-screen flex overflow-hidden">

  <!-- Sidebar -->
  <aside class="w-64 bg-white border-r border-gray-200 flex-col hidden md:flex z-20 shadow-lg">
    <div class="h-20 flex items-center justify-center border-b border-gray-100">
      <div class="flex items-center gap-2">
        <div
          class="w-8 h-8 bg-brand-red rounded-full flex items-center justify-center text-white font-serif font-bold text-xl">
          A</div>
        <span class="font-serif text-2xl font-bold text-gray-900 tracking-tight">ARIA <span class="text-brand-red">CMS</span></span>
      </div>
    </div>

    <nav class="flex-1 py-6 px-3 space-y-1 overflow-y-auto">
      <button onclick="router('dashboard')" id="nav-dashboard" class="nav-item active w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-xl transition-all duration-200 text-gray-600 hover:bg-gray-50 hover:text-brand-red">
                <i class="fa-solid fa-chart-pie w-5"></i> Dashboard
            </button>
      <button onclick="router('products')" id="nav-products" class="nav-item w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-xl transition-all duration-200 text-gray-600 hover:bg-gray-50 hover:text-brand-red">
                <i class="fa-solid fa-pump-soap w-5"></i> Products
            </button>
      <button onclick="router('add-product')" id="nav-add-product" class="nav-item w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-xl transition-all duration-200 text-gray-600 hover:bg-gray-50 hover:text-brand-red">
                <i class="fa-solid fa-plus-circle w-5"></i> Add Product
            </button>
      <button onclick="router('companies')" id="nav-companies" class="nav-item w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-xl transition-all duration-200 text-gray-600 hover:bg-gray-50 hover:text-brand-red">
                <i class="fa-solid fa-building w-5"></i> Companies
            </button>
      <button onclick="router('certificates')" id="nav-certificates" class="nav-item w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-xl transition-all duration-200 text-gray-600 hover:bg-gray-50 hover:text-brand-red">
                <i class="fa-solid fa-certificate w-5"></i> Certificates
            </button>
      <button onclick="router('support')" id="nav-support" class="nav-item w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-xl transition-all duration-200 text-gray-600 hover:bg-gray-50 hover:text-brand-red">
                <i class="fa-solid fa-headset w-5"></i> Support
            </button>
    </nav>

    <div class="p-4 border-t border-gray-100">
      <div class="flex items-center gap-3">
        <img src="https://ui-avatars.com/api/?name=Admin+User&background=D90429&color=fff" class="w-10 h-10 rounded-full border-2 border-white shadow-sm" alt="Admin">
        <div>
          <p class="text-sm font-bold text-gray-900">Admin User</p>
          <p class="text-xs text-gray-500">Regulatory Manager</p>
        </div>
      </div>
    </div>
  </aside>

  <!-- Main Content -->
  <main class="flex-1 flex flex-col h-screen overflow-hidden relative">
    <!-- Top Header -->
    <header class="h-20 bg-white border-b border-gray-200 flex items-center justify-between px-6 lg:px-10 z-10">
      <div class="flex items-center gap-4 md:hidden">
        <button class="text-gray-600 hover:text-brand-red"><i class="fa-solid fa-bars text-xl"></i></button>
        <span class="font-serif font-bold text-xl">ARIA</span>
      </div>

      <div
        class="hidden md:flex items-center text-gray-400 bg-gray-50 px-4 py-2 rounded-full w-96 border border-gray-200 focus-within:border-brand-red focus-within:ring-1 focus-within:ring-brand-red transition-all">
        <i class="fa-solid fa-search mr-3"></i>
        <input type="text" id="global-search" placeholder="Search products, companies, ingredients..." class="bg-transparent border-none outline-none text-sm w-full text-gray-700 placeholder-gray-400">
      </div>

      <div class="flex items-center gap-4">
        <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank"
          class="hidden lg:block text-xs font-medium text-gray-500 hover:text-brand-red transition-colors">
          Built with anycoder
        </a>
        <button class="relative p-2 text-gray-400 hover:text-brand-red transition-colors">
                    <i class="fa-solid fa-bell text-xl"></i>
                    <span class="absolute top-1 right-1 w-2 h-2 bg-brand-red rounded-full border border-white"></span>
                </button>
      </div>
    </header>

    <!-- Dynamic Content Area -->
    <div id="app-content" class="flex-1 overflow-y-auto p-6 lg:p-10 bg-gray-50 relative">
      <!-- Views will be injected here -->
    </div>
  </main>

  <!-- Toast Notification -->
  <div id="toast"
    class="fixed bottom-5 right-5 bg-gray-900 text-white px-6 py-4 rounded-lg shadow-2xl transform translate-y-20 opacity-0 transition-all duration-300 z-50 flex items-center gap-3">
    <i class="fa-solid fa-check-circle text-green-400"></i>
    <span id="toast-msg">Operation successful</span>
  </div>

  <!-- Company Modal -->
  <div id="company-modal" class="fixed inset-0 bg-black/50 backdrop-blur-sm z-50 hidden items-center justify-center p-4">
    <div class="bg-white rounded-2xl shadow-2xl w-full max-w-4xl max-h-[90vh] overflow-y-auto">
      <div class="sticky top-0 bg-white border-b border-gray-100 p-6 flex justify-between items-center">
        <h3 class="text-2xl font-serif font-bold text-gray-900" id="modal-title">Add New Company</h3>
        <button onclick="closeCompanyModal()" class="text-gray-400 hover:text-gray-600 transition">
          <i class="fa-solid fa-xmark text-2xl"></i>
        </button>
      </div>
      <div class="p-6" id="modal-content">
        <!-- Form content injected here -->
      </div>
    </div>
  </div>

  <!-- JavaScript Application Logic -->
  <script>
    // --- Mock Data & State ---
        const state = {
            currentView: 'dashboard',
            products: [
                {
                    id: 1,
                    name: "Angel's Liquid Red Serum",
                    brand: "ARIA",
                    series: "Premium",
                    category: "Serum",
                    skinType: "All",
                    price: 45.00,
                    stock: 120,
                    inci: "Water, Niacinamide, Hyaluronic Acid, Red Ginseng Extract",
                    cpnp: "CPNP-2023-001",
                    rp: "ARIA Cosmetic EU GmbH",
                    image: "https://images.unsplash.com/photo-1620916566398-39f1143ab7be?ixlib=rb-4.0.3&auto=format&fit=crop&w=600&q=80",
                    expiry: "2025-12-01",
                    pao: "12M"
                },
                {
                    id: 2,
                    name: "Hydra Glow Moisturizer",
                    brand: "ARIA",
                    series: "Daily",
                    category: "Moisturizer",
                    skinType: "Dry",
                    price: 32.50,
                    stock: 85,
                    inci: "Aqua, Glycerin, Ceramide NP, Squalane",
                    cpnp: "CPNP-2023-042",
                    rp: "ARIA Cosmetic EU GmbH",
                    image: "https://images.unsplash.com/photo-1556228720-19875c4b84b2?ixlib=rb-4.0.3&auto=format&fit=crop&w=600&q=80",
                    expiry: "2026-05-15",
                    pao: "6M"
                },
                {
                    id: 3,
                    name: "Pure Clean Foaming Wash",
                    brand: "ARIA",
                    series: "Daily",
                    category: "Cleanser",
                    skinType: "Oily",
                    price: 24.00,
                    stock: 200,
                    inci: "Water, Coco-Glucoside, Salicylic Acid, Tea Tree Oil",
                    cpnp: "CPNP-2023-089",
                    rp: "ARIA Cosmetic EU GmbH",
                    image: "https://images.unsplash.com/photo-1556228578-0d85b1a4d571?ixlib=rb-4.0.3&auto=format&fit=crop&w=600&q=80",
                    expiry: "2025-08-20",
                    pao: "12M"
                },
                {
                    id: 4,
                    name: "Midnight Repair Cream",
                    brand: "ARIA",
                    series: "Night",
                    category: "Cream",
                    skinType: "Mature",
                    price: 58.00,
                    stock: 45,
                    inci: "Retinol, Peptides, Shea Butter, Jojoba Oil",
                    cpnp: "CPNP-2024-010",
                    rp: "ARIA Cosmetic EU GmbH",
                    image: "https://images.unsplash.com/photo-1616683693504-3ea7e9ad6fec?ixlib=rb-4.0.3&auto=format&fit=crop&w=600&q=80",
                    expiry: "2025-11-30",
                    pao: "6M"
                }
            ],
            certificates: [
                { id: 1, name: "ISO 22716 (GMP)", authority: "Bureau Veritas", date: "2023-01-15", type: "pdf" },
                { id: 2, name: "Vegan Society Certified", authority: "The Vegan Society", date: "2023-06-20", type: "img" },
                { id: 3, name: "Leaping Bunny Approved", authority: "CCIC", date: "2023-03-10", type: "pdf" },
                { id: 4, name: "ECOCERT Organic", authority: "ECOCERT", date: "2022-11-05", type: "img" }
            ],
            companies: [
                {
                    id: 1,
                    name: "ARIA Cosmetic EU GmbH",
                    legalName: "ARIA Cosmetic Europe GmbH",
                    type: "Responsible Person",
                    registrationNumber: "HRB 123456",
                    vatNumber: "DE123456789",
                    establishedDate: "2018-03-15",
                    website: "https://aria-cosmetic.eu",
                    email: "regulatory@aria-cosmetic.eu",
                    phone: "+49 30 12345678",
                    address: {
                        street: "Friedrichstraße 123",
                        city: "Berlin",
                        postalCode: "10117",
                        country: "Germany"
                    },
                    regulatoryContact: {
                        name: "Dr. Sarah Mueller",
                        email: "s.mueller@aria-cosmetic.eu",
                        phone: "+49 30 12345679"
                    },
                    certifications: ["ISO 22716", "GMP Certified"],
                    status: "active",
                    logo: "https://ui-avatars.com/api/?name=ARIA+EU&background=D90429&color=fff&size=128",
                    description: "European headquarters and Responsible Person for ARIA Cosmetic products in the EU market.",
                    documents: [
                        { name: "Business Registration", type: "pdf", date: "2018-03-15" },
                        { name: "ISO 22716 Certificate", type: "pdf", date: "2023-01-15" }
                    ]
                },
                {
                    id: 2,
                    name: "ARIA Cosmetic Korea Ltd.",
                    legalName: "아리아 코스메틱 주식회사",
                    type: "Manufacturer",
                    registrationNumber: "123-45-67890",
                    vatNumber: "KR1234567890",
                    establishedDate: "2015-06-20",
                    website: "https://aria-cosmetic.kr",
                    email: "info@aria-cosmetic.kr",
                    phone: "+82 2 1234 5678",
                    address: {
                        street: "Gangnam-daero 123",
                        city: "Seoul",
                        postalCode: "06234",
                        country: "South Korea"
                    },
                    regulatoryContact: {
                        name: "Kim Min-jae",
                        email: "minjae.kim@aria-cosmetic.kr",
                        phone: "+82 2 1234 5679"
                    },
                    certifications: ["KFDA", "CGMP", "ISO 22716"],
                    status: "active",
                    logo: "https://ui-avatars.com/api/?name=ARIA+KR&background=2B2D42&color=fff&size=128",
                    description: "Primary manufacturing facility and R&D center for ARIA Cosmetic products.",
                    documents: [
                        { name: "KFDA Registration", type: "pdf", date: "2023-06-20" },
                        { name: "Manufacturing License", type: "pdf", date: "2023-01-10" }
                    ]
                },
                {
                    id: 3,
                    name: "ARIA Cosmetic USA Inc.",
                    legalName: "ARIA Cosmetic USA Inc.",
                    type: "Distributor",
                    registrationNumber: "DE1234567",
                    vatNumber: "US12-3456789",
                    establishedDate: "2020-01-10",
                    website: "https://aria-cosmetic.us",
                    email: "contact@aria-cosmetic.us",
                    phone: "+1 212 555 0123",
                    address: {
                        street: "5th Avenue 789",
                        city: "New York",
                        postalCode: "10001",
                        country: "United States"
                    },
                    regulatoryContact: {
                        name: "Jennifer Walsh",
                        email: "j.walsh@aria-cosmetic.us",
                        phone: "+1 212 555 0124"
                    },
                    certifications: ["FDA Registered", "cGMP"],
                    status: "active",
                    logo: "https://ui-avatars.com/api/?name=ARIA+US&background=8D99AE&color=fff&size=128",
                    description: "US distribution center handling North American market operations.",
                    documents: [
                        { name: "FDA Registration", type: "pdf", date: "2023-03-15" },
                        { name: "US Agent Agreement", type: "pdf", date: "2020-01-10" }
                    ]
                }
            ],
            editingCompany: null
        };

        // --- Router ---
        function router(view) {
            state.currentView = view;
            
            document.querySelectorAll('.nav-item').forEach(el => el.classList.remove('active', 'bg-brand-red', 'text-white', 'shadow-lg'));
            document.querySelectorAll('.nav-item').forEach(el => el.classList.add('text-gray-600'));
            
            const activeNav = document.getElementById(`nav-${view}`);
            if(activeNav) {
                activeNav.classList.add('active');
                activeNav.classList.remove('text-gray-600');
            }

            const content = document.getElementById('app-content');
            content.innerHTML = '';
            content.classList.remove('fade-in');
            void content.offsetWidth;
            content.classList.add('fade-in');

            switch(view) {
                case 'dashboard': renderDashboard(); break;
                case 'products': renderProducts(); break;
                case 'add-product': renderAddProduct(); break;
                case 'companies': renderCompanies(); break;
                case 'certificates': renderCertificates(); break;
                case 'support': renderSupport(); break;
                default: renderDashboard();
            }
        }

        // --- Render Functions ---

        function renderDashboard() {
            const totalProducts = state.products.length;
            const lowStock = state.products.filter(p => p.stock < 50).length;
            const totalCompanies = state.companies.length;
            const activeCompanies = state.companies.filter(c => c.status === 'active').length;
            
            const html = `
                <div class="space-y-8">
                    <div class="flex justify-between items-end">
                        <div>
                            <h2 class="text-3xl font-serif font-bold text-gray-900">Dashboard</h2>
                            <p class="text-gray-500 mt-1">Welcome back, here's what's happening today.</p>
                        </div>
                        <button onclick="router('add-product')" class="bg-brand-red hover:bg-red-700 text-white px-6 py-2.5 rounded-lg shadow-lg shadow-red-200 transition-all flex items-center gap-2">
                            <i class="fa-solid fa-plus"></i> New Product
                        </button>
                    </div>

                    <!-- Stats Grid -->
                    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
                        <div class="bg-white p-6 rounded-2xl shadow-sm border border-gray-100 flex items-center justify-between">
                            <div>
                                <p class="text-sm text-gray-500 font-medium">Total Products</p>
                                <h3 class="text-3xl font-bold text-gray-900 mt-1">${totalProducts}</h3>
                            </div>
                            <div class="w-12 h-12 bg-red-50 rounded-full flex items-center justify-center text-brand-red text-xl">
                                <i class="fa-solid fa-box-open"></i>
                            </div>
                        </div>
                        <div class="bg-white p-6 rounded-2xl shadow-sm border border-gray-100 flex items-center justify-between">
                            <div>
                                <p class="text-sm text-gray-500 font-medium">Companies</p>
                                <h3 class="text-3xl font-bold text-blue-600 mt-1">${totalCompanies}</h3>
                            </div>
                            <div class="w-12 h-12 bg-blue-50 rounded-full flex items-center justify-center text-blue-600 text-xl">
                                <i class="fa-solid fa-building"></i>
                            </div>
                        </div>
                        <div class="bg-white p-6 rounded-2xl shadow-sm border border-gray-100 flex items-center justify-between">
                            <div>
                                <p class="text-sm text-gray-500 font-medium">Low Stock Alerts</p>
                                <h3 class="text-3xl font-bold text-brand-red mt-1">${lowStock}</h3>
                            </div>
                            <div class="w-12 h-12 bg-red-50 rounded-full flex items-center justify-center text-brand-red text-xl">
                                <i class="fa-solid fa-triangle-exclamation"></i>
                            </div>
                        </div>
                        <div class="bg-white p-6 rounded-2xl shadow-sm border border-gray-100 flex items-center justify-between">
                            <div>
                                <p class="text-sm text-gray-500 font-medium">Active Certs</p>
                                <h3 class="text-3xl font-bold text-green-600 mt-1">${state.certificates.length}</h3>
                            </div>
                            <div class="w-12 h-12 bg-green-50 rounded-full flex items-center justify-center text-green-600 text-xl">
                                <i class="fa-solid fa-shield-check"></i>
                            </div>
                        </div>
                    </div>

                    <!-- Charts Section -->
                    <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
                        <div class="bg-white p-6 rounded-2xl shadow-sm border border-gray-100 lg:col-span-2">
                            <h3 class="font-serif font-bold text-lg mb-4">Inventory Distribution</h3>
                            <canvas id="inventoryChart" height="100"></canvas>
                        </div>
                        <div class="bg-white p-6 rounded-2xl shadow-sm border border-gray-100">
                            <h3 class="font-serif font-bold text-lg mb-4">Companies Overview</h3>
                            <div class="space-y-4">
                                ${state.companies.slice(0, 3).map(c => `
                                    <div class="flex items-center gap-3 p-3 rounded-xl hover:bg-gray-50 transition cursor-pointer" onclick="router('companies')">
                                        <img src="${c.logo}" class="w-10 h-10 rounded-lg" alt="${c.name}">
                                        <div class="flex-1 min-w-0">
                                            <p class="text-sm font-bold text-gray-900 truncate">${c.name}</p>
                                            <p class="text-xs text-gray-500">${c.type} • ${c.address.country}</p>
                                        </div>
                                        <span class="px-2 py-1 text-xs font-medium rounded-full ${c.status === 'active' ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-600'}">
                                            ${c.status}
                                        </span>
                                    </div>
                                `).join('')}
                                <button onclick="router('companies')" class="w-full py-2 text-sm text-brand-red border border-brand-red/20 rounded-lg hover:bg-brand-red hover:text-white transition-colors">
                                    View All Companies
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            `;
            document.getElementById('app-content').innerHTML = html;

            setTimeout(() => {
                const ctx = document.getElementById('inventoryChart').getContext('2d');
                new Chart(ctx, {
                    type: 'bar',
                    data: {
                        labels: state.products.map(p => p.name),
                        datasets: [{
                            label: 'Stock Level',
                            data: state.products.map(p => p.stock),
                            backgroundColor: '#D90429',
                            borderRadius: 6,
                        }]
                    },
                    options: {
                        responsive: true,
                        scales: {
                            y: { beginAtZero: true, grid: { display: false } },
                            x: { grid: { display: false } }
                        },
                        plugins: { legend: { display: false } }
                    }
                });
            }, 100);
        }

        function renderProducts() {
            let html = `
                <div class="space-y-6">
                    <div class="flex flex-col md:flex-row justify-between items-center gap-4">
                        <h2 class="text-3xl font-serif font-bold text-gray-900">Product Inventory</h2>
                        <div class="flex gap-3 w-full md:w-auto">
                            <select id="filter-category" onchange="filterProducts()" class="bg-white border border-gray-300 text-gray-700 text-sm rounded-lg focus:ring-brand-red focus:border-brand-red block p-2.5">
                                <option value="All">All Categories</option>
                                <option value="Serum">Serum</option>
                                <option value="Moisturizer">Moisturizer</option>
                                <option value="Cleanser">Cleanser</option>
                            </select>
                            <button onclick="router('add-product')" class="bg-brand-red text-white px-4 py-2 rounded-lg hover:bg-red-700 transition shadow-md">
                                <i class="fa-solid fa-plus"></i> Add
                            </button>
                        </div>
                    </div>

                    <div id="product-grid" class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6">
                    </div>
                </div>
            `;
            document.getElementById('app-content').innerHTML = html;
            renderProductGrid(state.products);
        }

        function renderProductGrid(products) {
            const grid = document.getElementById('product-grid');
            if(products.length === 0) {
                grid.innerHTML = `<div class="col-span-full text-center py-20 text-gray-500">No products found matching your criteria.</div>`;
                return;
            }

            grid.innerHTML = products.map(p => `
                <div class="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden hover:shadow-xl transition-all duration-300 group">
                    <div class="h-48 overflow-hidden relative">
                        <img src="${p.image}" alt="${p.name}" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500">
                        <div class="absolute top-3 right-3 bg-white/90 backdrop-blur px-2 py-1 rounded-md text-xs font-bold text-gray-800 shadow-sm">
                            ${p.category}
                        </div>
                    </div>
                    <div class="p-5">
                        <div class="flex justify-between items-start mb-2">
                            <div>
                                <p class="text-xs text-brand-red font-bold uppercase tracking-wider">${p.brand}</p>
                                <h3 class="font-serif text-xl font-bold text-gray-900 leading-tight">${p.name}</h3>
                            </div>
                            <span class="font-sans font-bold text-gray-900">$${p.price.toFixed(2)}</span>
                        </div>
                        
                        <div class="flex flex-wrap gap-2 my-3">
                            <span class="px-2 py-1 bg-gray-100 text-gray-600 text-xs rounded-md">${p.skinType} Skin</span>
                            <span class="px-2 py-1 bg-gray-100 text-gray-600 text-xs rounded-md">PAO: ${p.pao}</span>
                        </div>

                        <div class="border-t border-gray-100 pt-4 mt-2">
                            <div class="flex justify-between items-center text-xs text-gray-500 mb-2">
                                <span>Stock: <b class="${p.stock < 50 ? 'text-brand-red' : 'text-green-600'}">${p.stock} units</b></span>
                                <span>CPNP: ${p.cpnp}</span>
                            </div>
                            <button onclick="alert('View details for ${p.name}')" class="w-full py-2 border border-gray-200 rounded-lg text-sm font-medium text-gray-700 hover:bg-gray-50 hover:text-brand-red transition-colors">
                                View Details
                            </button>
                        </div>
                    </div>
                </div>
            `).join('');
        }

        function filterProducts() {
            const cat = document.getElementById('filter-category').value;
            const filtered = cat === 'All' ? state.products : state.products.filter(p => p.category === cat);
            renderProductGrid(filtered);
        }

        function renderAddProduct() {
            const html = `
                <div class="max-w-4xl mx-auto">
                    <h2 class="text-3xl font-serif font-bold text-gray-900 mb-6">Add New Product</h2>
                    
                    <form id="product-form" onsubmit="handleProductSubmit(event)" class="bg-white rounded-2xl shadow-sm border border-gray-100 p-8 space-y-6">
                        
                        <div class="bg-blue-50 border border-blue-100 rounded-xl p-4 flex items-start gap-4 mb-6">
                            <div class="bg-blue-100 p-2 rounded-lg text-blue-600">
                                <i class="fa-solid fa-wand-magic-sparkles"></i>
                            </div>
                            <div class="flex-1">
                                <h4 class="font-bold text-blue-900 text-sm">AI Assistant</h4>
                                <p class="text-xs text-blue-700 mb-2">Enter the product name below and click "Generate" to auto-create SEO title, description, and regulatory warnings.</p>
                                <div class="flex gap-2">
                                    <input type="text" id="ai-input" placeholder="e.g. Vitamin C Brightening Serum" class="flex-1 text-sm border-blue-200 rounded-md px-3 py-1.5 focus:ring-2 focus:ring-blue-400 outline-none">
                                    <button type="button" onclick="generateAIContent()" class="bg-blue-600 text-white text-xs px-4 py-1.5 rounded-md hover:bg-blue-700 transition">Generate</button>
                                </div>
                            </div>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div class="space-y-2">
                                <label class="text-sm font-bold text-gray-700">Product Name</label>
                                <input type="text" name="name" required class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red focus:ring-1 focus:ring-brand-red outline-none transition">
                            </div>
                            <div class="space-y-2">
                                <label class="text-sm font-bold text-gray-700">Company/Brand</label>
                                <select name="brand" class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red outline-none bg-white">
                                    ${state.companies.map(c => `<option value="${c.name}">${c.name}</option>`).join('')}
                                    <option value="ARIA">ARIA (Default)</option>
                                </select>
                            </div>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                            <div class="space-y-2">
                                <label class="text-sm font-bold text-gray-700">Category</label>
                                <select name="category" class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red outline-none bg-white">
                                    <option>Serum</option>
                                    <option>Moisturizer</option>
                                    <option>Cleanser</option>
                                    <option>Cream</option>
                                </select>
                            </div>
                            <div class="space-y-2">
                                <label class="text-sm font-bold text-gray-700">Skin Type</label>
                                <select name="skinType" class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red outline-none bg-white">
                                    <option>All</option>
                                    <option>Dry</option>
                                    <option>Oily</option>
                                    <option>Sensitive</option>
                                    <option>Mature</option>
                                </select>
                            </div>
                            <div class="space-y-2">
                                <label class="text-sm font-bold text-gray-700">Price ($)</label>
                                <input type="number" name="price" step="0.01" required class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red outline-none">
                            </div>
                        </div>

                        <div class="space-y-2">
                            <label class="text-sm font-bold text-gray-700">INCI Ingredients (Comma separated)</label>
                            <textarea name="inci" rows="2" class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red outline-none text-sm"></textarea>
                        </div>

                        <div class="border-t border-gray-100 pt-6 mt-6">
                            <h3 class="font-serif font-bold text-lg mb-4 text-gray-800">Regulatory Information</h3>
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                                <div class="space-y-2">
                                    <label class="text-sm font-bold text-gray-700">Responsible Person (Company)</label>
                                    <select name="rp" class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red outline-none bg-white">
                                        ${state.companies.filter(c => c.type === 'Responsible Person').map(c => `<option value="${c.name}">${c.name}</option>`).join('')}
                                    </select>
                                </div>
                                <div class="space-y-2">
                                    <label class="text-sm font-bold text-gray-700">CPNP Number</label>
                                    <input type="text" name="cpnp" placeholder="e.g. CPNP-2024-XXX" class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red outline-none">
                                </div>
                                <div class="space-y-2">
                                    <label class="text-sm font-bold text-gray-700">Expiry Date</label>
                                    <input type="date" name="expiry" class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red outline-none">
                                </div>
                                <div class="space-y-2">
                                    <label class="text-sm font-bold text-gray-700">Period After Opening (PAO)</label>
                                    <select name="pao" class="w-full border border-gray-300 rounded-lg px-4 py-2.5 focus:border-brand-red outline-none bg-white">
                                        <option>6M</option>
                                        <option>12M</option>
                                        <option>24M</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="pt-6 flex justify-end gap-4">
                            <button type="button" onclick="router('products')" class="px-6 py-2.5 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 font-medium transition">Cancel</button>
                            <button type="submit" class="px-6 py-2.5 bg-brand-red text-white rounded-lg hover:bg-red-700 font-medium shadow-lg shadow-red-200 transition transform active:scale-95">Save Product</button>
                        </div>
                    </form>
                </div>
            `;
            document.getElementById('app-content').innerHTML = html;
        }

        function generateAIContent() {
            const input = document.getElementById('ai-input').value;
            if(!input) return showToast('Please enter a product name first', 'error');

            const btn = document.querySelector('button[onclick="generateAIContent()"]');
            const originalText = btn.innerText;
            btn.innerHTML = '<i class="fa-solid fa-circle-notch fa-spin"></i>';
            btn.disabled = true;

            setTimeout(() => {
                const form = document.getElementById('product-form');
                form.name.value = input;
                form.inci.value = "Aqua, Glycerin, Niacinamide, Hyaluronic Acid, [AI Generated Base]";
                
                showToast('AI generated content applied!');
                btn.innerText = originalText;
                btn.disabled = false;
            }, 1500);
        }

        function handleProductSubmit(e) {
            e.preventDefault();
            const formData = new FormData(e.target);
            const newProduct = {
                id: Date.now(),
                name: formData.get('name'),
                brand: formData.get('brand'),
                category: formData.get('category'),
                skinType: formData.get('skinType'),
                price: parseFloat(formData.get('price')),
                stock: 0,
                inci: formData.get('inci'),
                cpnp: formData.get('cpnp'),
                rp: formData.get('rp'),
                image: "https://images.unsplash.com/photo-1608248597279-f99d160bfbc8?ixlib=rb-4.0.3&auto=format&fit=crop&w=600&q=80",
                expiry: formData.get('expiry'),
                pao: formData.get('pao')
            };

            state.products.unshift(newProduct);
            showToast('Product added successfully!');
            router('products');
        }

        // --- Companies Management ---

        function renderCompanies() {
            const html = `
                <div class="space-y-6">
                    <div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
                        <div>
                            <h2 class="text-3xl font-serif font-bold text-gray-900">Companies</h2>
                            <p class="text-gray-500 mt-1">Manage your business entities, manufacturers, and responsible persons.</p>
                        </div>
                        <button onclick="openCompanyModal()" class="bg-brand-red text-white px-6 py-2.5 rounded-lg hover:bg-red-700 transition shadow-lg shadow-red-200 flex items-center gap-2">
                            <i class="fa-solid fa-plus"></i> Add Company
                        </button>
                    </div>

                    <!-- Company Stats -->
                    <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
                        <div class="bg-white p-4 rounded-xl shadow-sm border border-gray-100">
                            <p class="text-xs text-gray-500 uppercase tracking-wider font-medium">Total Companies</p>
                            <p class="text-2xl font-bold text-gray-900 mt-1">${state.companies.length}</p>
                        </div>
                        <div class="bg-white p-4 rounded-xl shadow-sm border border-gray-100">
                            <p class="text-xs text-gray-500 uppercase tracking-wider font-medium">Responsible Persons</p>
                            <p class="text-2xl font-bold text-blue-600 mt-1">${state.companies.filter(c => c.type === 'Responsible Person').length}</p>
                        </div>
                        <div class="bg-white p-4 rounded-xl shadow-sm border border-gray-100">
                            <p class="text-xs text-gray-500 uppercase tracking-wider font-medium">Manufacturers</p>
                            <p class="text-2xl font-bold text-purple-600 mt-1">${state.companies.filter(c => c.type === 'Manufacturer').length}</p>
                        </div>
                        <div class="bg-white p-4 rounded-xl shadow-sm border border-gray-100">
                            <p class="text-xs text-gray-500 uppercase tracking-wider font-medium">Active</p>
                            <p class="text-2xl font-bold text-green-600 mt-1">${state.companies.filter(c => c.status === 'active').length}</p>
                        </div>
                    </div>

                    <!-- Filters -->
                    <div class="flex flex-wrap gap-3">
                        <button onclick="filterCompanies('all')" class="filter-btn active px-4 py-2 rounded-lg text-sm font-medium transition-all bg-brand-red text-white" data-filter="all">
                            All Companies
                        </button>
                        <button onclick="filterCompanies('Responsible Person')" class="filter-btn px-4 py-2 rounded-lg text-sm font-medium transition-all bg-white text-gray-600 hover:bg-gray-50" data-filter="Responsible Person">
                            Responsible Persons
                        </button>
                        <button onclick="filterCompanies('Manufacturer')" class="filter-btn px-4 py-2 rounded-lg text-sm font-medium transition-all bg-white text-gray-600 hover:bg-gray-50" data-filter="Manufacturer">
                            Manufacturers
                        </button>
                        <button onclick="filterCompanies('Distributor')" class="filter-btn px-4 py-2 rounded-lg text-sm font-medium transition-all bg-white text-gray-600 hover:bg-gray-50" data-filter="Distributor">
                            Distributors
                        </button>
                    </div>

                    <!-- Companies Grid -->
                    <div id="companies-grid" class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-6">
                        ${renderCompanyCards(state.companies)}
                    </div>
                </div>
            `;
            document.getElementById('app-content').innerHTML = html;
        }

        function renderCompanyCards(companies) {
            if(companies.length === 0) {
                return `<div class="col-span-full text-center py-20 text-gray-500">
                    <i class="fa-solid fa-building text-4xl mb-4 text-gray-300"></i>
                    <p>No companies found matching your criteria.</p>
                </div>`;
            }

            return companies.map(c => `
                <div class="company-card bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
                    <div class="p-6">
                        <div class="flex items-start justify-between mb-4">
                            <div class="flex items-center gap-4">
                                <img src="${c.logo}" class="w-16 h-16 rounded-xl shadow-sm" alt="${c.name}">
                                <div>
                                    <h3 class="font-serif font-bold text-lg text-gray-900 leading-tight">${c.name}</h3>
                                    <p class="text-xs text-gray-500">${c.legalName}</p>
                                </div>
                            </div>
                            <div class="flex gap-2