-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1697 lines (1560 loc) Β· 107 KB
/
index.html
File metadata and controls
1697 lines (1560 loc) Β· 107 KB
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
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<title>Finance OS β Personal</title>
<meta name="theme-color" content="#0c0c14">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="Finance OS">
<link rel="manifest" href="./manifest.json">
<style>
/* ββ Reset βββββββββββββββββββββββββββββββββββββββββββ */
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;font-family:'Segoe UI',system-ui,sans-serif;font-size:14px;background:#0c0c14;color:#e2e2f0;overflow:hidden}
button,input,select,textarea{font-family:inherit}
/* ββ CSS Vars ββββββββββββββββββββββββββββββββββββββββ */
:root{
--bg:#0c0c14;--surf:#131320;--surf2:#1a1a2e;--surf3:#1f1f38;
--border:#1e1e30;--border2:#252540;
--accent:#6366f1;--accent-h:#4f46e5;--accent-d:rgba(99,102,241,.12);
--text:#e2e2f0;--text2:#8888a8;--text3:#3a3a5c;
--green:#22c55e;--green-d:rgba(34,197,94,.12);
--red:#f43f5e;--red-d:rgba(244,63,94,.12);
--amber:#f59e0b;--amber-d:rgba(245,158,11,.12);
--blue:#38bdf8;--blue-d:rgba(56,189,248,.12);
}
/* ββ App shell βββββββββββββββββββββββββββββββββββββββ */
#app{display:flex;height:100vh;height:100dvh;overflow:hidden}
#sidebar{width:220px;min-width:220px;background:var(--surf);border-right:1px solid var(--border);display:flex;flex-direction:column;overflow-y:auto;flex-shrink:0;transition:transform .25s;z-index:50}
#main{flex:1;display:flex;flex-direction:column;overflow:hidden;min-width:0}
#content{flex:1;overflow-y:auto;padding:20px;-webkit-overflow-scrolling:touch}
.view{display:none}.view.active{display:block}
/* ββ Topbar ββββββββββββββββββββββββββββββββββββββββββ */
#topbar{min-height:50px;background:var(--surf);border-bottom:1px solid var(--border);display:flex;align-items:center;gap:10px;flex-shrink:0;padding:env(safe-area-inset-top,0px) 16px 0 16px;padding-top:max(env(safe-area-inset-top,0px),14px);padding-bottom:12px}
#tb-title{font-size:13px;font-weight:700;color:var(--text);flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tb-period{display:flex;align-items:center;gap:4px;flex-shrink:0}
.tb-arr{background:none;border:1px solid var(--border);color:var(--text2);width:26px;height:26px;border-radius:4px;cursor:pointer;font-size:14px;display:flex;align-items:center;justify-content:center;transition:all .12s;flex-shrink:0;-webkit-tap-highlight-color:transparent}
.tb-arr:hover{border-color:var(--accent);color:var(--text)}
#period-btn{font-size:11px;background:var(--surf2);border:1px solid var(--border2);color:var(--text2);padding:5px 10px;border-radius:4px;cursor:pointer;transition:all .15s;white-space:nowrap}
#period-btn:hover{border-color:var(--accent);color:var(--text)}
#mb-toggle{display:none;background:none;border:none;color:var(--text2);cursor:pointer;font-size:22px;padding:4px;flex-shrink:0;line-height:1;-webkit-tap-highlight-color:transparent}
/* ββ Status bar ββββββββββββββββββββββββββββββββββββββ */
#status-bar{height:24px;min-height:24px;display:flex;align-items:center;padding:0 14px;gap:7px;font-size:10px;flex-shrink:0;background:#080810;border-bottom:1px solid #10101e;transition:background .3s}
#status-bar.saving{background:#1a1408;border-bottom-color:#2a2010}
#status-bar.err{background:#140808;border-bottom-color:#280e0e}
#sb-dot{width:5px;height:5px;border-radius:50%;background:var(--green);flex-shrink:0;transition:background .3s}
#status-bar.saving #sb-dot{background:var(--amber)}
#status-bar.err #sb-dot{background:var(--red)}
#sb-msg{flex:1;color:#1a4a2a;transition:color .3s;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#status-bar.saving #sb-msg{color:#6a5010}
#status-bar.err #sb-msg{color:#8a1a1a}
#sb-time{color:#141428;flex-shrink:0}
#sync-chip{font-size:9px;padding:1px 6px;border-radius:8px;border:1px solid #1a1a30;color:#2a2a50;cursor:pointer;white-space:nowrap;flex-shrink:0;transition:all .15s}
#sync-chip:hover{border-color:var(--accent);color:var(--accent)}
#sync-chip.signed-in{color:var(--green);border-color:#1a3a1a}
#sync-chip.syncing{color:var(--amber);border-color:#3a2800}
/* ββ Install banner ββββββββββββββββββββββββββββββββββ */
#install-bar{display:none;background:#12122e;border-bottom:1px solid #1e1e5e;padding:6px 14px;align-items:center;gap:10px;font-size:11px;flex-shrink:0}
#install-bar.show{display:flex}
#install-bar span{flex:1;color:#7878c8}
#ib-btn{background:#4444aa;border:none;color:#fff;padding:5px 12px;border-radius:4px;cursor:pointer;font-size:11px;font-weight:700}
#ib-dismiss{background:none;border:none;color:#444;cursor:pointer;font-size:16px;padding:2px 5px}
/* ββ Sidebar βββββββββββββββββββββββββββββββββββββββββ */
.sb-brand{padding:14px 12px 10px;border-bottom:1px solid var(--border);flex-shrink:0}
.sb-logo{display:flex;align-items:center;gap:8px;margin-bottom:2px}
.sb-icon{width:30px;height:30px;background:var(--accent);border-radius:6px;display:flex;align-items:center;justify-content:center;font-weight:900;font-size:11px;color:#fff;flex-shrink:0}
.sb-name{font-size:12px;font-weight:800;color:var(--text)}
.sb-name em{color:var(--accent);font-style:normal}
.sb-sub{font-size:10px;color:var(--text3);padding-left:38px;margin-top:1px}
.sb-sec{border-bottom:1px solid #111120}
.sb-lbl{font-size:9px;font-weight:700;letter-spacing:.16em;text-transform:uppercase;color:var(--text3);padding:7px 12px 2px}
.sbi{display:flex;align-items:center;gap:7px;padding:8px 12px;cursor:pointer;font-size:12px;color:#565678;border-left:2px solid transparent;user-select:none;transition:all .12s;-webkit-tap-highlight-color:transparent}
.sbi:hover{background:#18182a;color:#c8c8e8}
.sbi.active{background:var(--accent-d);color:var(--accent);border-left-color:var(--accent);font-weight:700}
.sbi-ic{width:15px;text-align:center;flex-shrink:0;font-size:13px}
.sb-foot{padding:10px 12px;border-top:1px solid var(--border);margin-top:auto;flex-shrink:0}
.sb-plbl{font-size:9px;color:var(--text3);letter-spacing:.08em;text-transform:uppercase;margin-bottom:2px}
.sb-pval{font-size:11px;color:var(--accent);font-weight:700;margin-bottom:8px}
.sbb{display:block;width:100%;text-align:center;font-size:10px;font-weight:700;letter-spacing:.05em;text-transform:uppercase;padding:6px;border-radius:4px;cursor:pointer;border:1px solid;background:none;margin-top:4px;transition:all .15s;font-family:inherit;-webkit-tap-highlight-color:transparent}
.sbb-a{border-color:#2a2a6a;color:var(--accent)}.sbb-a:hover{background:var(--accent);color:#fff}
.sbb-g{border-color:#1a3a1a;color:var(--green)}.sbb-g:hover{background:var(--green);color:#fff}
/* ββ Mobile overlay ββββββββββββββββββββββββββββββββββ */
#sb-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.65);z-index:49}
#sb-overlay.show{display:block}
/* ββ Page header βββββββββββββββββββββββββββββββββββββ */
.ph{display:flex;align-items:flex-start;justify-content:space-between;flex-wrap:wrap;gap:12px;margin-bottom:20px}
.ph h2{font-size:20px;font-weight:800;color:#eeeeff;margin-bottom:2px}
.ph p{font-size:12px;color:var(--text3)}
.pha{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
/* ββ KPIs ββββββββββββββββββββββββββββββββββββββββββββ */
.kg{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin-bottom:20px}
.kpi{background:var(--surf);border:1px solid var(--border);border-radius:8px;padding:15px;position:relative;overflow:hidden}
.kpi::before{content:'';position:absolute;top:0;left:0;right:0;height:2px}
.k-inc::before{background:var(--green)}.k-exp::before{background:var(--red)}.k-net::before{background:var(--accent)}.k-sv::before{background:var(--amber)}
.kl{font-size:9px;font-weight:700;letter-spacing:.14em;text-transform:uppercase;color:var(--text3);margin-bottom:7px}
.kv{font-size:20px;font-weight:800;color:#eeeeff;font-variant-numeric:tabular-nums;margin-bottom:3px;line-height:1}
.ks{font-size:10px;color:var(--text3)}.ks.pos{color:var(--green)}.ks.neg{color:var(--red)}
/* ββ Account cards βββββββββββββββββββββββββββββββββββ */
.acc-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:20px}
.acc-card{background:var(--surf);border:1px solid var(--border);border-radius:8px;padding:16px;position:relative;overflow:hidden;cursor:pointer;transition:border-color .15s}
.acc-card:hover{border-color:var(--border2)}
.acc-card::before{content:'';position:absolute;top:0;left:0;bottom:0;width:3px}
.acc-bank{font-size:10px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;color:var(--text3);margin-bottom:4px}
.acc-name{font-size:13px;font-weight:700;color:var(--text);margin-bottom:10px}
.acc-bal{font-size:22px;font-weight:800;font-variant-numeric:tabular-nums;line-height:1;margin-bottom:4px}
.acc-sub{font-size:10px;color:var(--text3)}
/* ββ Panels ββββββββββββββββββββββββββββββββββββββββββ */
.panel{background:var(--surf);border:1px solid var(--border);border-radius:8px;margin-bottom:16px;overflow:hidden}
.ph2{display:flex;align-items:center;justify-content:space-between;padding:11px 15px;border-bottom:1px solid var(--border);background:var(--surf2);gap:10px;flex-wrap:wrap}
.pt{font-size:12px;font-weight:700;color:#b8b8d8;display:flex;align-items:center;gap:6px}
.pm{font-size:10px;color:var(--text3);font-variant-numeric:tabular-nums}
.pb{padding:15px}
/* ββ Tables ββββββββββββββββββββββββββββββββββββββββββ */
.tw{overflow-x:auto;-webkit-overflow-scrolling:touch}
table{width:100%;border-collapse:collapse;font-size:12px;min-width:420px}
th{text-align:left;font-size:9px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;color:var(--text3);padding:8px 11px;border-bottom:1px solid var(--border);background:var(--surf2);white-space:nowrap}
td{padding:8px 11px;border-bottom:1px solid rgba(255,255,255,.022);color:#787898;vertical-align:middle}
tr:last-child td{border-bottom:none}tr:hover td{background:rgba(255,255,255,.01)}
td.b{color:#cccce8;font-weight:700}td.pos{color:var(--green);font-weight:700;font-variant-numeric:tabular-nums}
td.neg{color:var(--red);font-weight:700;font-variant-numeric:tabular-nums}td.mono{font-variant-numeric:tabular-nums}
.erow td{text-align:center;color:var(--text3);font-style:italic;padding:26px 11px}
/* ββ Forms βββββββββββββββββββββββββββββββββββββββββββ */
.fg{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.fg .s2{grid-column:1/-1}
.fv{display:flex;flex-direction:column;gap:4px}
.fl{font-size:9px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;color:var(--text3)}
input,select,textarea{font-family:inherit;font-size:13px;color:var(--text);background:#181828;border:1px solid var(--border2);border-radius:4px;padding:8px 10px;outline:none;width:100%;transition:border-color .12s}
input[type=checkbox]{width:auto;cursor:pointer;accent-color:var(--accent)}
input:focus,select:focus,textarea:focus{border-color:var(--accent);background:#1c1c30}
input::placeholder,textarea::placeholder{color:var(--text3)}
select{cursor:pointer;appearance:none;background-image:url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23555' stroke-width='1.5' stroke-linecap='round' fill='none'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 10px center;padding-right:28px}
select option{background:#181828}
textarea{resize:vertical;min-height:66px;line-height:1.5}
.fa{display:flex;gap:8px;margin-top:12px;flex-wrap:wrap}
/* ββ Buttons βββββββββββββββββββββββββββββββββββββββββ */
.btn{display:inline-flex;align-items:center;gap:5px;font-size:12px;font-weight:700;padding:8px 13px;border-radius:4px;border:1px solid transparent;cursor:pointer;white-space:nowrap;transition:all .12s;font-family:inherit;letter-spacing:.03em;-webkit-tap-highlight-color:transparent}
.btn:active{opacity:.75}.btn:disabled{opacity:.35;cursor:not-allowed}
.btn-accent{background:var(--accent);color:#fff;border-color:var(--accent)}.btn-accent:hover{background:var(--accent-h)}
.btn-ghost{background:transparent;color:#545468;border-color:var(--border)}.btn-ghost:hover{border-color:var(--border2);color:#c0c0e0}
.btn-green{background:var(--green);color:#fff;border-color:var(--green)}.btn-green:hover{background:#16a34a}
.btn-danger{background:transparent;color:var(--red);border-color:#2a1018}.btn-danger:hover{background:var(--red);color:#fff}
.btn-sm{padding:5px 10px;font-size:11px}.btn-xs{padding:3px 7px;font-size:10px}
.btn-google{background:#fff;color:#3c3c3c;border-color:#dadce0;width:100%;justify-content:center}.btn-google:hover{box-shadow:0 1px 6px rgba(0,0,0,.25)}
/* ββ Chips βββββββββββββββββββββββββββββββββββββββββββ */
.chip{display:inline-block;font-size:9px;font-weight:700;letter-spacing:.05em;text-transform:uppercase;padding:2px 7px;border-radius:10px}
.ch-g{background:var(--green-d);color:var(--green)}.ch-r{background:var(--red-d);color:var(--red)}
.ch-a{background:var(--accent-d);color:var(--accent)}.ch-o{background:var(--amber-d);color:var(--amber)}
.ch-b{background:var(--blue-d);color:var(--blue)}.ch-x{background:rgba(255,255,255,.05);color:#555}
/* ββ Progress bars βββββββββββββββββββββββββββββββββββ */
.prog-wrap{height:6px;background:var(--surf3);border-radius:10px;overflow:hidden;width:100%}
.prog-fill{height:100%;border-radius:10px;transition:width .5s}
/* ββ Goal cards ββββββββββββββββββββββββββββββββββββββ */
.goal-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-bottom:16px}
.goal-card{background:var(--surf);border:1px solid var(--border);border-radius:8px;padding:16px;cursor:pointer;transition:border-color .12s;-webkit-tap-highlight-color:transparent}
.goal-card:hover{border-color:var(--border2)}
.goal-emoji{font-size:22px;margin-bottom:8px;line-height:1}
.goal-name{font-size:13px;font-weight:700;color:var(--text);margin-bottom:2px}
.goal-amt{font-size:11px;color:var(--text2);margin-bottom:10px;font-variant-numeric:tabular-nums}
.goal-pct{font-size:18px;font-weight:800;font-variant-numeric:tabular-nums;margin-bottom:8px}
.goal-deadline{font-size:10px;color:var(--text3);margin-top:8px}
/* ββ Receipt grid ββββββββββββββββββββββββββββββββββββ */
.receipt-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px}
.receipt-thumb{border-radius:6px;border:1px solid var(--border);overflow:hidden;cursor:pointer;aspect-ratio:3/4;position:relative;background:var(--surf2);transition:border-color .12s}
.receipt-thumb:hover{border-color:var(--accent)}
.receipt-thumb img{width:100%;height:100%;object-fit:cover;display:block}
.receipt-info{font-size:10px;color:var(--text3);padding:5px 7px;background:var(--surf);border-top:1px solid var(--border);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.receipt-noimg{display:flex;align-items:center;justify-content:center;flex-direction:column;height:calc(100% - 31px);font-size:22px;color:var(--text3)}
/* ββ Transaction rows ββββββββββββββββββββββββββββββββ */
.tx-row{display:flex;align-items:center;gap:10px;padding:10px 0;border-bottom:1px solid rgba(255,255,255,.028)}
.tx-row:last-child{border-bottom:none}
.tx-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}
.tx-main{flex:1;min-width:0}
.tx-desc{font-size:12px;color:var(--text);font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tx-meta{font-size:10px;color:var(--text3);margin-top:1px}
.tx-amt{font-size:13px;font-weight:800;font-variant-numeric:tabular-nums;flex-shrink:0}
.tx-inc{color:var(--green)}.tx-exp{color:var(--red)}
.tx-actions{display:flex;gap:4px;flex-shrink:0;opacity:0;transition:opacity .12s}
.tx-row:hover .tx-actions{opacity:1}
/* ββ Recurring rows ββββββββββββββββββββββββββββββββββ */
.rec-row{display:flex;align-items:center;gap:10px;padding:11px 0;border-bottom:1px solid rgba(255,255,255,.028)}
.rec-row:last-child{border-bottom:none}
.rec-ic{width:32px;height:32px;border-radius:6px;display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0}
.rec-main{flex:1;min-width:0}
.rec-name{font-size:12px;font-weight:700;color:var(--text)}
.rec-meta{font-size:10px;color:var(--text3);margin-top:2px}
.rec-amt{font-size:13px;font-weight:800;font-variant-numeric:tabular-nums;flex-shrink:0;text-align:right}
.rec-due{font-size:9px;text-align:right;margin-top:2px}
.due-soon{color:var(--amber)}.due-now{color:var(--red)}.due-ok{color:var(--text3)}
/* ββ History month cards βββββββββββββββββββββββββββββ */
.hist-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin-bottom:16px}
.hm{background:var(--surf);border:1px solid var(--border);border-radius:6px;padding:12px;cursor:pointer;transition:all .12s;-webkit-tap-highlight-color:transparent}
.hm:hover{border-color:var(--accent);background:var(--surf2)}
.hm.cur{border-color:var(--accent);background:var(--accent-d)}
.hm-name{font-size:11px;font-weight:700;color:var(--text2);margin-bottom:8px}
.hm-inc{font-size:11px;color:var(--green);font-variant-numeric:tabular-nums}
.hm-exp{font-size:11px;color:var(--red);font-variant-numeric:tabular-nums}
.hm-net{font-size:12px;font-weight:800;font-variant-numeric:tabular-nums;margin-top:4px}
/* ββ Alerts ββββββββββββββββββββββββββββββββββββββββββ */
.alert{display:flex;align-items:flex-start;gap:8px;padding:9px 12px;border-radius:4px;border:1px solid;font-size:12px;margin-bottom:8px;line-height:1.5}
.alert:last-child{margin-bottom:0}
.a-w{background:var(--amber-d);border-color:rgba(245,158,11,.2);color:#c0880a}
.a-ok{background:var(--green-d);border-color:rgba(34,197,94,.2);color:var(--green)}
.a-d{background:var(--red-d);border-color:rgba(244,63,94,.2);color:var(--red)}
.a-i{background:var(--blue-d);border-color:rgba(56,189,248,.2);color:var(--blue)}
.a-p{background:var(--accent-d);border-color:rgba(99,102,241,.2);color:var(--accent)}
/* ββ Stat rows βββββββββββββββββββββββββββββββββββββββ */
.sr{display:flex;align-items:center;justify-content:space-between;padding:7px 0;border-bottom:1px solid rgba(255,255,255,.028);font-size:12px;gap:8px}
.sr:last-child{border-bottom:none}
.sr-l{color:#545468;flex:1}.sr-v{font-variant-numeric:tabular-nums;font-weight:700;color:#cccce8;white-space:nowrap}
.sr-v.pos{color:var(--green)}.sr-v.neg{color:var(--red)}
/* ββ Grid helpers ββββββββββββββββββββββββββββββββββββ */
.g2{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:16px}
/* ββ Annual chart ββββββββββββββββββββββββββββββββββββ */
.achart{display:flex;align-items:flex-end;gap:4px;height:100px;padding-bottom:20px;position:relative}
.acol{display:flex;flex-direction:column;align-items:center;flex:1;position:relative}
.abars{display:flex;gap:2px;align-items:flex-end;width:100%;height:80px}
.abar{flex:1;border-radius:2px 2px 0 0;min-height:2px;transition:height .4s}
.abar.inc{background:var(--green);opacity:.7}.abar.exp{background:var(--red);opacity:.7}
.amo{font-size:8px;color:var(--text3);position:absolute;bottom:-16px;white-space:nowrap}
/* ββ Audit log βββββββββββββββββββββββββββββββββββββββ */
.alog-row{display:flex;align-items:flex-start;gap:9px;padding:9px 0;border-bottom:1px solid rgba(255,255,255,.025)}
.alog-row:last-child{border-bottom:none}
.alog-ic{flex-shrink:0;font-size:14px;line-height:1.4}
.alog-body{flex:1;min-width:0}
.alog-action{font-size:12px;color:#a0a0c0;font-weight:600}
.alog-detail{font-size:11px;color:var(--text3);margin-top:1px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.alog-ts{font-size:10px;color:var(--text3);white-space:nowrap;flex-shrink:0;font-variant-numeric:tabular-nums}
/* ββ Overlays / Modals βββββββββββββββββββββββββββββββ */
.overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.82);z-index:200;align-items:flex-start;justify-content:center;padding:16px;overflow-y:auto}
.overlay.open{display:flex}
.modal{background:#181828;border:1px solid var(--border2);border-radius:10px;padding:22px;width:360px;max-width:95vw;margin:auto}
.modal h3{font-size:14px;font-weight:700;color:var(--text);margin-bottom:14px}
.mrow{display:flex;gap:10px;margin-bottom:10px}
.mrow select{flex:1;font-size:13px}
.mbtns{display:flex;gap:8px;margin-top:14px}
/* ββ Confirm dialog ββββββββββββββββββββββββββββββββββ */
#cf-ov{display:none;position:fixed;inset:0;background:rgba(0,0,0,.85);z-index:500;align-items:center;justify-content:center}
#cf-ov.open{display:flex}
#cf-box{background:#181828;border:1px solid var(--border2);border-radius:10px;padding:24px;width:300px;max-width:95vw;text-align:center}
#cf-box h4{font-size:14px;font-weight:700;color:var(--text);margin-bottom:6px}
#cf-box p{font-size:12px;color:var(--text3);margin-bottom:18px;line-height:1.5}
.cfbtns{display:flex;gap:8px;justify-content:center}
/* ββ Toast βββββββββββββββββββββββββββββββββββββββββββ */
#toast{position:fixed;bottom:calc(20px + env(safe-area-inset-bottom,0px));right:16px;background:var(--green);color:#fff;font-size:12px;font-weight:700;padding:9px 15px;border-radius:5px;z-index:9999;opacity:0;transform:translateY(8px);transition:all .22s;pointer-events:none;max-width:calc(100vw - 32px)}
#toast.show{opacity:1;transform:translateY(0)}#toast.err{background:var(--red)}
/* ββ Sync modal ββββββββββββββββββββββββββββββββββββββ */
.sync-section-title{font-size:10px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;color:var(--text3);margin-bottom:10px}
.fb-user-row{display:flex;align-items:center;gap:10px;padding:10px 12px;background:#181828;border:1px solid var(--border2);border-radius:4px;margin-bottom:12px}
.fb-avatar{width:28px;height:28px;border-radius:50%;background:var(--accent);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:700;color:#fff;flex-shrink:0}
details summary{list-style:none;cursor:pointer}
details summary::-webkit-details-marker{display:none}
/* ββ Responsive ββββββββββββββββββββββββββββββββββββββ */
@media(max-width:960px){
.kg{grid-template-columns:1fr 1fr}
.goal-grid{grid-template-columns:1fr 1fr}
.receipt-grid{grid-template-columns:repeat(3,1fr)}
.hist-grid{grid-template-columns:repeat(3,1fr)}
.g2{grid-template-columns:1fr}
}
@media(max-width:640px){
#sidebar{position:fixed;top:0;left:0;bottom:0;transform:translateX(-100%);transition:transform .25s}
.sb-brand{padding-top:max(env(safe-area-inset-top,0px),14px)}
#sidebar.open{transform:translateX(0)}
#mb-toggle{display:block}
#content{padding:14px 12px;padding-bottom:calc(20px + env(safe-area-inset-bottom,0px))}
.kg{grid-template-columns:1fr 1fr}
.acc-grid{grid-template-columns:1fr 1fr}
.goal-grid{grid-template-columns:1fr}
.receipt-grid{grid-template-columns:repeat(2,1fr)}
.hist-grid{grid-template-columns:repeat(2,1fr)}
.fg{grid-template-columns:1fr}.fg .s2{grid-column:1}
.tx-actions{opacity:1}
}
@media(max-width:900px) and (orientation:landscape){
#sidebar{position:fixed;top:0;left:0;bottom:0;transform:translateX(-100%)}
#sidebar.open{transform:translateX(0)}
#mb-toggle{display:block}
}
</style>
</head>
<body>
<div id="app">
<!-- βββ SIDEBAR ββββββββββββββββββββββββββββββββββββ -->
<nav id="sidebar">
<div class="sb-brand">
<div class="sb-logo"><div class="sb-icon">π°</div><div class="sb-name"><em>Finance</em> OS</div></div>
<div class="sb-sub">Personal Money Manager</div>
</div>
<div class="sb-sec">
<div class="sb-lbl">Overview</div>
<div class="sbi active" data-v="dashboard"><span class="sbi-ic">π</span>Dashboard</div>
</div>
<div class="sb-sec">
<div class="sb-lbl">Transactions</div>
<div class="sbi" data-v="income"><span class="sbi-ic">π</span>Income</div>
<div class="sbi" data-v="expenses"><span class="sbi-ic">π΄</span>Expenses</div>
<div class="sbi" data-v="recurring"><span class="sbi-ic">π</span>Recurring</div>
</div>
<div class="sb-sec">
<div class="sb-lbl">Accounts & Goals</div>
<div class="sbi" data-v="accounts"><span class="sbi-ic">π¦</span>Bank Accounts</div>
<div class="sbi" data-v="goals"><span class="sbi-ic">π―</span>Savings Goals</div>
</div>
<div class="sb-sec">
<div class="sb-lbl">Records</div>
<div class="sbi" data-v="receipts"><span class="sbi-ic">π§Ύ</span>Receipts</div>
<div class="sbi" data-v="history"><span class="sbi-ic">π
</span>History</div>
<div class="sbi" data-v="reports"><span class="sbi-ic">π</span>Reports & CSV</div>
<div class="sbi" data-v="audit"><span class="sbi-ic">π</span>Audit Log</div>
</div>
<div class="sb-sec">
<div class="sb-lbl">Manage</div>
<div class="sbi" data-v="settings"><span class="sbi-ic">βοΈ</span>Settings</div>
</div>
<div class="sb-foot">
<div class="sb-plbl">Period</div>
<div class="sb-pval" id="sb-period">β</div>
<button class="sbb sbb-a" onclick="openPeriodModal()">β Change Period</button>
<button class="sbb sbb-g" onclick="openBackup()" style="margin-top:5px">β Backup & Sync</button>
</div>
</nav>
<div id="sb-overlay" onclick="closeSidebar()"></div>
<!-- βββ MAIN ββββββββββββββββββββββββββββββββββββββββ -->
<div id="main">
<div id="topbar">
<button id="mb-toggle" onclick="openSidebar()">β°</button>
<div id="tb-title">Dashboard</div>
<div class="tb-period">
<button class="tb-arr" onclick="shiftPeriod(-1)" title="Previous month">βΉ</button>
<button id="period-btn" onclick="openPeriodModal()">β</button>
<button class="tb-arr" onclick="shiftPeriod(1)" title="Next month">βΊ</button>
</div>
</div>
<div id="status-bar">
<div id="sb-dot"></div>
<div id="sb-msg">Loadingβ¦</div>
<div id="sb-time"></div>
<div id="sync-chip" onclick="openBackup()" title="Sync status">β Not synced</div>
</div>
<div id="install-bar">
<span>π² Install Finance OS as an app on this device</span>
<button id="ib-btn">Install</button>
<button id="ib-dismiss">β</button>
</div>
<div id="content">
<!-- DASHBOARD ββββββββββββββββββββββββββββββββ -->
<div id="view-dashboard" class="view active">
<div class="ph"><div><h2>Dashboard</h2><p id="d-sub">Monthly overview</p></div>
<div class="pha">
<button class="btn btn-green btn-sm" onclick="nav('income')">+ Income</button>
<button class="btn btn-danger btn-sm" onclick="nav('expenses')">+ Expense</button>
</div></div>
<div class="acc-grid" id="d-accounts"></div>
<div class="kg" id="d-kpis"></div>
<div class="g2">
<div class="panel"><div class="ph2"><span class="pt">π Recent Income</span><span class="pm" id="d-inc-ct"></span></div><div class="pb" id="d-inc-list"></div></div>
<div class="panel"><div class="ph2"><span class="pt">π΄ Recent Expenses</span><span class="pm" id="d-exp-ct"></span></div><div class="pb" id="d-exp-list"></div></div>
</div>
<div class="g2">
<div class="panel"><div class="ph2"><span class="pt">π― Goals Progress</span></div><div class="pb" id="d-goals"></div></div>
<div class="panel"><div class="ph2"><span class="pt">π Due Soon</span></div><div class="pb" id="d-due"></div></div>
</div>
</div>
<!-- INCOME βββββββββββββββββββββββββββββββββββ -->
<div id="view-income" class="view">
<div class="ph"><div><h2>Income</h2><p id="inc-sub">Log all money coming in</p></div></div>
<div class="g2">
<div class="panel"><div class="ph2"><span class="pt">+ Add Income</span></div>
<div class="pb">
<div class="fg">
<div class="fv"><label class="fl">Date</label><input type="date" id="i-date"></div>
<div class="fv"><label class="fl">Amount (R)</label><input type="number" id="i-amt" placeholder="0.00" min="0" step="0.01"></div>
<div class="fv"><label class="fl">Category</label><select id="i-cat"></select></div>
<div class="fv"><label class="fl">Account</label><select id="i-acc"></select></div>
<div class="fv s2"><label class="fl">Description</label><input type="text" id="i-desc" placeholder="e.g. Monthly salary, client paymentβ¦"></div>
</div>
<div class="fa"><button class="btn btn-green" onclick="addTransaction('income')">+ Add Income</button><button class="btn btn-ghost" onclick="clearIncForm()">Clear</button></div>
</div></div>
<div class="panel"><div class="ph2"><span class="pt">π This Month</span></div><div class="pb" id="inc-sum"></div></div>
</div>
<div class="panel">
<div class="ph2"><span class="pt">Income This Period</span><span class="pm" id="inc-total"></span><button class="btn btn-ghost btn-sm" onclick="openExport('income')">β¬ Export CSV</button></div>
<div class="tw"><table><thead><tr><th>Date</th><th>Category</th><th>Account</th><th>Description</th><th>Amount</th><th></th></tr></thead><tbody id="inc-tb"></tbody></table></div>
</div>
</div>
<!-- EXPENSES βββββββββββββββββββββββββββββββββ -->
<div id="view-expenses" class="view">
<div class="ph"><div><h2>Expenses</h2><p id="exp-sub">Track where your money goes</p></div></div>
<div class="g2">
<div class="panel"><div class="ph2"><span class="pt">+ Add Expense</span></div>
<div class="pb">
<div class="fg">
<div class="fv"><label class="fl">Date</label><input type="date" id="e-date"></div>
<div class="fv"><label class="fl">Amount (R)</label><input type="number" id="e-amt" placeholder="0.00" min="0" step="0.01"></div>
<div class="fv"><label class="fl">Category</label><select id="e-cat"></select></div>
<div class="fv"><label class="fl">Account</label><select id="e-acc"></select></div>
<div class="fv s2"><label class="fl">Description</label><input type="text" id="e-desc" placeholder="e.g. Woolworths groceries, Netflixβ¦"></div>
</div>
<div class="fa"><button class="btn btn-danger" onclick="addTransaction('expense')">+ Add Expense</button><button class="btn btn-ghost" onclick="clearExpForm()">Clear</button></div>
</div></div>
<div class="panel"><div class="ph2"><span class="pt">π Breakdown</span></div><div class="pb" id="exp-sum"></div></div>
</div>
<div class="panel">
<div class="ph2"><span class="pt">Expenses This Period</span><span class="pm" id="exp-total"></span><button class="btn btn-ghost btn-sm" onclick="openExport('expense')">β¬ Export CSV</button></div>
<div class="tw"><table><thead><tr><th>Date</th><th>Category</th><th>Account</th><th>Description</th><th>Amount</th><th></th></tr></thead><tbody id="exp-tb"></tbody></table></div>
</div>
</div>
<!-- ACCOUNTS βββββββββββββββββββββββββββββββββ -->
<div id="view-accounts" class="view">
<div class="ph"><div><h2>Bank Accounts</h2><p>Track balances across both accounts</p></div></div>
<div id="acc-panels"></div>
</div>
<!-- RECURRING ββββββββββββββββββββββββββββββββ -->
<div id="view-recurring" class="view">
<div class="ph"><div><h2>Recurring Transactions</h2><p>Subscriptions, salary, bills</p></div>
<div class="pha"><button class="btn btn-accent btn-sm" onclick="openRecModal()">+ Add Recurring</button></div></div>
<div id="rec-due-banner"></div>
<div class="panel"><div class="ph2"><span class="pt">π Active Recurring</span><span class="pm" id="rec-count"></span></div>
<div class="pb" id="rec-list"></div></div>
</div>
<!-- GOALS ββββββββββββββββββββββββββββββββββββ -->
<div id="view-goals" class="view">
<div class="ph"><div><h2>Savings Goals</h2><p>Track what you're saving towards</p></div>
<div class="pha"><button class="btn btn-accent btn-sm" onclick="openGoalModal()">+ New Goal</button></div></div>
<div class="goal-grid" id="goal-grid"></div>
<div id="goal-empty" style="display:none;text-align:center;color:var(--text3);padding:40px;font-style:italic">No goals yet. Add one to get started!</div>
</div>
<!-- RECEIPTS βββββββββββββββββββββββββββββββββ -->
<div id="view-receipts" class="view">
<div class="ph"><div><h2>Receipts</h2><p>Photos stored on this device only</p></div>
<div class="pha">
<label class="btn btn-accent btn-sm" style="cursor:pointer">π· Add Receipt<input type="file" id="receipt-file" accept="image/*" capture="environment" style="display:none" onchange="addReceipt(this)"></label>
</div></div>
<div class="alert a-i" style="margin-bottom:16px;font-size:11px">Receipt photos are stored locally on this device only β they do not sync to the cloud.</div>
<div class="receipt-grid" id="receipt-grid"></div>
<div id="receipt-empty" style="display:none;text-align:center;color:var(--text3);padding:40px;font-style:italic">No receipts yet. Tap "Add Receipt" to photograph one.</div>
</div>
<!-- HISTORY ββββββββββββββββββββββββββββββββββ -->
<div id="view-history" class="view">
<div class="ph"><div><h2>History</h2><p>Browse by year</p></div>
<div class="pha"><select id="hist-year" onchange="renderHistory()" style="background:#181828;border:1px solid var(--border2);color:var(--text);padding:6px 28px 6px 10px;border-radius:4px;font-size:12px;cursor:pointer;appearance:none;background-image:url('data:image/svg+xml,%3Csvg width=\'10\' height=\'6\' viewBox=\'0 0 10 6\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cpath d=\'M1 1l4 4 4-4\' stroke=\'%23555\' stroke-width=\'1.5\' stroke-linecap=\'round\' fill=\'none\'/%3E%3C/svg%3E');background-repeat:no-repeat;background-position:right 8px center"></select></div></div>
<div class="panel"><div class="ph2"><span class="pt">π Annual Chart</span>
<div style="display:flex;gap:12px;font-size:10px;color:var(--text3)">
<span style="display:flex;align-items:center;gap:4px"><span style="width:8px;height:8px;background:var(--green);border-radius:2px;display:inline-block"></span>Income</span>
<span style="display:flex;align-items:center;gap:4px"><span style="width:8px;height:8px;background:var(--red);border-radius:2px;display:inline-block"></span>Expenses</span>
</div></div>
<div class="pb"><div class="achart" id="hist-chart"></div></div></div>
<div class="hist-grid" id="hist-months"></div>
</div>
<!-- REPORTS ββββββββββββββββββββββββββββββββββ -->
<div id="view-reports" class="view">
<div class="ph"><div><h2>Reports & CSV Export</h2><p>Download data for any period</p></div></div>
<div class="panel"><div class="ph2"><span class="pt">π
Date Range Export</span></div>
<div class="pb">
<div class="alert a-i" style="margin-bottom:16px;font-size:11px">Select any date range and export to CSV β open in Excel or Google Sheets.</div>
<div class="fg" style="margin-bottom:14px">
<div class="fv">
<label class="fl">From</label>
<div style="display:flex;gap:6px">
<select id="rp-from-mo" style="flex:1"></select>
<select id="rp-from-yr" style="width:80px;flex-shrink:0"></select>
</div>
</div>
<div class="fv">
<label class="fl">To</label>
<div style="display:flex;gap:6px">
<select id="rp-to-mo" style="flex:1"></select>
<select id="rp-to-yr" style="width:80px;flex-shrink:0"></select>
</div>
</div>
</div>
<div style="margin-bottom:12px">
<div class="fl" style="margin-bottom:8px">Include</div>
<div style="display:flex;gap:16px;flex-wrap:wrap">
<label style="display:flex;align-items:center;gap:6px;font-size:12px;color:var(--text2);cursor:pointer"><input type="checkbox" id="rp-inc" checked> Income</label>
<label style="display:flex;align-items:center;gap:6px;font-size:12px;color:var(--text2);cursor:pointer"><input type="checkbox" id="rp-exp" checked> Expenses</label>
<label style="display:flex;align-items:center;gap:6px;font-size:12px;color:var(--text2);cursor:pointer"><input type="checkbox" id="rp-sum" checked> Monthly Summary</label>
</div>
</div>
<div style="display:flex;gap:8px;flex-wrap:wrap">
<button class="btn btn-accent" onclick="runReport()">β¬ Download CSV</button>
<button class="btn btn-ghost" onclick="runReport('summary-only')">β¬ Summary Only</button>
</div>
</div></div>
<div class="panel"><div class="ph2"><span class="pt">π Quick Exports</span></div>
<div class="pb">
<div style="display:flex;gap:8px;flex-wrap:wrap">
<button class="btn btn-ghost btn-sm" onclick="exportAll('income')">β¬ All Income</button>
<button class="btn btn-ghost btn-sm" onclick="exportAll('expense')">β¬ All Expenses</button>
<button class="btn btn-ghost btn-sm" onclick="exportAllTx()">β¬ All Transactions</button>
</div>
</div></div>
</div>
<!-- AUDIT ββββββββββββββββββββββββββββββββββββ -->
<div id="view-audit" class="view">
<div class="ph"><div><h2>Audit Log</h2><p>Full history of every action</p></div>
<div class="pha"><button class="btn btn-ghost btn-sm" onclick="cfm('Clear audit log?','This cannot be undone.',function(){DB.audit=[];saveDB();renderAudit();toast('Audit log cleared.');})">Clear Log</button></div></div>
<div class="panel"><div class="ph2"><span class="pt">π Activity Log</span><span class="pm" id="audit-count"></span></div>
<div class="pb" id="audit-list"></div></div>
</div>
<!-- SETTINGS βββββββββββββββββββββββββββββββββ -->
<div id="view-settings" class="view">
<div class="ph"><div><h2>Settings</h2><p>Categories and account names</p></div></div>
<div class="g2">
<div class="panel"><div class="ph2"><span class="pt">π Income Categories</span><button class="btn btn-ghost btn-sm" onclick="addCat('inc')">+ Add</button></div>
<div class="pb" id="inc-cats"></div></div>
<div class="panel"><div class="ph2"><span class="pt">π΄ Expense Categories</span><button class="btn btn-ghost btn-sm" onclick="addCat('exp')">+ Add</button></div>
<div class="pb" id="exp-cats"></div></div>
</div>
<div class="panel"><div class="ph2"><span class="pt">π¦ Bank Accounts</span></div>
<div class="pb" id="acc-settings"></div></div>
</div>
</div><!-- /content -->
</div><!-- /main -->
</div><!-- /app -->
<!-- βββ MODALS βββββββββββββββββββββββββββββββββββββββ -->
<!-- Period picker -->
<div class="overlay" id="period-modal">
<div class="modal"><h3>Select Period</h3>
<div class="mrow">
<select id="pm-year"></select>
<select id="pm-month">
<option value="01">January</option><option value="02">February</option><option value="03">March</option>
<option value="04">April</option><option value="05">May</option><option value="06">June</option>
<option value="07">July</option><option value="08">August</option><option value="09">September</option>
<option value="10">October</option><option value="11">November</option><option value="12">December</option>
</select></div>
<div class="mbtns"><button class="btn btn-accent" onclick="applyPeriod()">Apply</button><button class="btn btn-ghost" onclick="closeOv('period-modal')">Cancel</button></div>
</div>
</div>
<!-- Add/Edit Recurring -->
<div class="overlay" id="rec-modal">
<div class="modal"><h3 id="rec-modal-title">Add Recurring Transaction</h3>
<div class="fg">
<div class="fv s2"><label class="fl">Name / Description</label><input type="text" id="rm-name" placeholder="e.g. Netflix, Salary, Bond"></div>
<div class="fv"><label class="fl">Type</label><select id="rm-type" onchange="populateRecCats()"><option value="income">Income</option><option value="expense">Expense</option></select></div>
<div class="fv"><label class="fl">Amount (R)</label><input type="number" id="rm-amt" placeholder="0.00" min="0" step="0.01"></div>
<div class="fv"><label class="fl">Category</label><select id="rm-cat"></select></div>
<div class="fv"><label class="fl">Account</label><select id="rm-acc"></select></div>
<div class="fv"><label class="fl">Frequency</label><select id="rm-freq"><option value="monthly">Monthly</option><option value="weekly">Weekly</option><option value="yearly">Yearly</option></select></div>
<div class="fv"><label class="fl">Day of Month (or Date)</label><input type="number" id="rm-day" placeholder="e.g. 25" min="1" max="31"></div>
<div class="fv s2"><label class="fl">Next Due Date</label><input type="date" id="rm-next"></div>
</div>
<div class="mbtns"><button class="btn btn-accent" onclick="saveRecModal()">Save</button><button class="btn btn-ghost" onclick="closeOv('rec-modal')">Cancel</button></div>
</div>
</div>
<!-- Add/Edit Goal -->
<div class="overlay" id="goal-modal">
<div class="modal"><h3 id="goal-modal-title">New Savings Goal</h3>
<div class="fg">
<div class="fv"><label class="fl">Goal Name</label><input type="text" id="gm-name" placeholder="e.g. Emergency Fund, Holiday"></div>
<div class="fv"><label class="fl">Emoji</label><input type="text" id="gm-emoji" placeholder="π―" maxlength="2" style="font-size:18px"></div>
<div class="fv"><label class="fl">Target Amount (R)</label><input type="number" id="gm-target" placeholder="0.00" min="0" step="0.01"></div>
<div class="fv"><label class="fl">Current Amount (R)</label><input type="number" id="gm-current" placeholder="0.00" min="0" step="0.01"></div>
<div class="fv"><label class="fl">Deadline (optional)</label><input type="date" id="gm-deadline"></div>
<div class="fv s2"><label class="fl">Notes</label><input type="text" id="gm-notes" placeholder="What this goal is forβ¦"></div>
</div>
<div class="mbtns"><button class="btn btn-accent" onclick="saveGoalModal()">Save</button><button class="btn btn-ghost" onclick="closeOv('goal-modal')">Cancel</button></div>
</div>
</div>
<!-- View Receipt -->
<div class="overlay" id="receipt-view-modal">
<div class="modal" style="width:90vw;max-width:500px;padding:14px">
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:10px">
<div style="font-size:13px;font-weight:700;color:var(--text)" id="rv-title">Receipt</div>
<div style="display:flex;gap:6px">
<button class="btn btn-danger btn-xs" id="rv-delete">Delete</button>
<button class="btn btn-ghost btn-xs" onclick="closeOv('receipt-view-modal')">β</button>
</div></div>
<img id="rv-img" src="" alt="Receipt" style="width:100%;border-radius:6px;display:block;max-height:70vh;object-fit:contain;background:var(--surf2)">
<div style="font-size:11px;color:var(--text3);margin-top:8px" id="rv-meta"></div>
</div>
</div>
<!-- Backup & Sync -->
<div class="overlay" id="backup-modal">
<div class="modal" style="width:440px">
<h3>Backup & Sync</h3>
<div style="margin-bottom:20px">
<div class="sync-section-title">Local Backup</div>
<div class="alert a-i" style="margin-bottom:10px;font-size:11px">Your data lives on this device. Download a backup regularly.</div>
<div style="display:flex;gap:8px;flex-wrap:wrap">
<button class="btn btn-ghost btn-sm" onclick="downloadBackup()">β¬ Download JSON Backup</button>
<label class="btn btn-ghost btn-sm" style="cursor:pointer">β¬ Restore from Backup<input type="file" id="restore-file" accept=".json" style="display:none" onchange="restoreFromFile(this)"></label>
</div></div>
<div style="border-top:1px solid var(--border);padding-top:16px">
<div class="sync-section-title">β Cloud Sync β Google Account</div>
<div id="fb-not-configured">
<div class="alert a-w" style="font-size:11px;margin-bottom:10px">Add your Firebase config to enable Google Sync. See README for setup guide.</div>
</div>
<div id="fb-signed-out" style="display:none">
<div class="alert a-p" style="font-size:11px;margin-bottom:14px">Sign in with Google to sync your data automatically across all devices.</div>
<button class="btn btn-google btn-sm" onclick="firebaseSignIn()">
<svg width="16" height="16" viewBox="0 0 18 18" style="flex-shrink:0;margin-right:6px"><path fill="#4285F4" d="M17.64 9.2c0-.637-.057-1.251-.164-1.84H9v3.481h4.844c-.209 1.125-.843 2.078-1.796 2.717v2.258h2.908c1.702-1.567 2.684-3.874 2.684-6.615z"/><path fill="#34A853" d="M9 18c2.43 0 4.467-.806 5.956-2.18l-2.909-2.259c-.806.54-1.837.86-3.047.86-2.344 0-4.328-1.584-5.036-3.711H.957v2.332C2.438 15.983 5.482 18 9 18z"/><path fill="#FBBC05" d="M3.964 10.71c-.18-.54-.282-1.117-.282-1.71 0-.593.102-1.17.282-1.71V4.958H.957C.347 6.173 0 7.548 0 9s.348 2.827.957 4.042l3.007-2.332z"/><path fill="#EA4335" d="M9 3.58c1.321 0 2.508.454 3.44 1.345l2.582-2.58C13.463.891 11.426 0 9 0 5.482 0 2.438 2.017.957 4.958L3.964 7.29C4.672 5.163 6.656 3.58 9 3.58z"/></svg>
Sign in with Google
</button>
</div>
<div id="fb-signed-in" style="display:none">
<div class="fb-user-row">
<div class="fb-avatar" id="fb-avatar">?</div>
<div style="flex:1;min-width:0">
<div style="font-size:12px;font-weight:700;color:#c8c8e8;white-space:nowrap;overflow:hidden;text-overflow:ellipsis" id="fb-display-name">β</div>
<div style="font-size:10px;color:var(--text3)" id="fb-email-display">β</div>
</div>
<button class="btn btn-ghost btn-xs" onclick="firebaseSignOut()">Sign out</button>
</div>
<div style="font-size:11px;color:var(--green);margin-bottom:12px" id="fb-sync-status">β Auto-sync active</div>
<div style="display:flex;gap:8px;flex-wrap:wrap">
<button class="btn btn-accent btn-sm" onclick="firebasePushManual()">β¬ Push to Cloud</button>
<button class="btn btn-ghost btn-sm" onclick="firebasePullManual()">β¬ Pull from Cloud</button>
</div>
</div>
</div>
<div class="mbtns" style="margin-top:16px"><button class="btn btn-ghost" onclick="closeOv('backup-modal')">Close</button></div>
</div>
</div>
<!-- Confirm dialog -->
<div id="cf-ov">
<div id="cf-box">
<h4 id="cf-title">Are you sure?</h4>
<p id="cf-msg">This cannot be undone.</p>
<div class="cfbtns">
<button class="btn btn-danger" id="cf-yes">Delete</button>
<button class="btn btn-ghost" onclick="closeCf()">Cancel</button>
</div>
</div>
</div>
<!-- Toast -->
<div id="toast"></div>
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
FIREBASE CONFIG β replace null with your config
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
<script>
var FIREBASE_CONFIG = {
apiKey: "AIzaSyBVfcLrA7_Ks0rhsWe4PAFDWPcXLVdkpZM",
authDomain: "personal-36-263f2.firebaseapp.com",
projectId: "personal-36-263f2",
storageBucket: "personal-36-263f2.firebasestorage.app",
messagingSenderId: "426038501875",
appId: "1:426038501875:web:e0f12b08d4d5fac6b2f286",
measurementId: "G-7ZF50LGS50"
};
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
DATA MODEL
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
var DB = {
v: 1,
settings: {
incCats: ['Salary','Freelance','Side Income','Investment Returns','Bonus','Gift','Other'],
expCats: ['Groceries','Eating Out','Transport','Petrol','Utilities','Rent/Bond','Insurance','Medical','Entertainment','Clothing','Education','Subscriptions','Personal Care','Other'],
accounts: [
{ id:'acc1', name:'Cheque Account', bank:'FNB', color:'#6366f1' },
{ id:'acc2', name:'Savings Account', bank:'FNB', color:'#22c55e' }
]
},
transactions: [],
recurring: [],
goals: [],
audit: [],
sync: { lastSync: null }
};
var CUR = { y:'', m:'' };
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
INDEXEDDB β two stores: 'data' and 'receipts'
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
var _idb=null, IDB_NAME='financeOS_v1';
function idbOpen(cb){
if(_idb){cb(_idb);return;}
var r=indexedDB.open(IDB_NAME,1);
r.onupgradeneeded=function(e){
var db=e.target.result;
if(!db.objectStoreNames.contains('data'))db.createObjectStore('data');
if(!db.objectStoreNames.contains('receipts'))db.createObjectStore('receipts');
};
r.onsuccess=function(e){_idb=e.target.result;cb(_idb);};
r.onerror=function(){cb(null);};
}
function idbGet(store,key,cb){
idbOpen(function(db){
if(!db){cb(null);return;}
var r=db.transaction(store,'readonly').objectStore(store).get(key);
r.onsuccess=function(){cb(r.result||null);};r.onerror=function(){cb(null);};
});
}
function idbPut(store,key,val,cb){
idbOpen(function(db){
if(!db){if(cb)cb(false);return;}
var r=db.transaction(store,'readwrite').objectStore(store).put(val,key);
r.onsuccess=function(){if(cb)cb(true);};r.onerror=function(){if(cb)cb(false);};
});
}
function idbDelete(store,key,cb){
idbOpen(function(db){
if(!db){if(cb)cb(false);return;}
var r=db.transaction(store,'readwrite').objectStore(store).delete(key);
r.onsuccess=function(){if(cb)cb(true);};r.onerror=function(){if(cb)cb(false);};
});
}
function idbGetAll(store,cb){
idbOpen(function(db){
if(!db){cb([]);return;}
var results=[];
var req=db.transaction(store,'readonly').objectStore(store).openCursor();
req.onsuccess=function(e){
var cursor=e.target.result;
if(cursor){results.push({key:cursor.key,value:cursor.value});cursor.continue();}
else{cb(results);}
};
req.onerror=function(){cb([]);};
});
}
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SAVE / LOAD
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
var _saveTimer=null,_syncTimer=null;
function saveDB(immediate){
setStat('saving','Savingβ¦',null);
clearTimeout(_saveTimer);
_saveTimer=setTimeout(function(){
idbPut('data','main',JSON.parse(JSON.stringify(DB)),function(ok){
if(ok){
setStat('ok','All changes saved',new Date().toISOString());
clearTimeout(_syncTimer);
_syncTimer=setTimeout(function(){
if(_fbUser&&_fbDb)firebasePushSilent();
},4000);
} else { setStat('err','Save failed',null); }
});
},immediate?0:600);
}
function loadDB(cb){
idbGet('data','main',function(data){
if(data&&data.v)DB=data;
ensureDefaults();cb();
});
}
function ensureDefaults(){
if(!DB.v)DB.v=1;
if(!DB.settings)DB.settings={};
if(!DB.settings.incCats)DB.settings.incCats=['Salary','Freelance','Other'];
if(!DB.settings.expCats)DB.settings.expCats=['Groceries','Transport','Utilities','Other'];
if(!DB.settings.accounts)DB.settings.accounts=[{id:'acc1',name:'Cheque Account',bank:'',color:'#6366f1'},{id:'acc2',name:'Savings Account',bank:'',color:'#22c55e'}];
if(!DB.transactions)DB.transactions=[];
if(!DB.recurring)DB.recurring=[];
if(!DB.goals)DB.goals=[];
if(!DB.audit)DB.audit=[];
if(!DB.sync)DB.sync={lastSync:null};
}
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
STATUS BAR
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
function setStat(state,msg,ts){
var bar=document.getElementById('status-bar');
if(!bar)return;
bar.className=state==='saving'?'saving':state==='err'?'err':'';
var m=document.getElementById('sb-msg'),t=document.getElementById('sb-time');
if(m)m.textContent=msg;
if(t)t.textContent=ts?new Date(ts).toLocaleTimeString('en-ZA',{hour:'2-digit',minute:'2-digit',second:'2-digit'}):'';
updateSyncChip();
}
function updateSyncChip(){
var chip=document.getElementById('sync-chip');if(!chip)return;
if(_fbUser){chip.textContent='β '+(_fbUser.displayName||'Synced').split(' ')[0];chip.className='signed-in';return;}
if(DB.sync.lastSync){var d=new Date(DB.sync.lastSync);chip.textContent='β '+d.toLocaleTimeString('en-ZA',{hour:'2-digit',minute:'2-digit'});chip.className='';return;}
chip.textContent='β Not synced';chip.className='';
}
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
AUDIT LOG
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
function audit(icon,action,detail){
DB.audit.unshift({id:uid(),ts:new Date().toISOString(),icon:icon,action:action,detail:detail});
if(DB.audit.length>500)DB.audit=DB.audit.slice(0,500);
}
function renderAudit(){
var list=document.getElementById('audit-list'),cnt=document.getElementById('audit-count');
if(cnt)cnt.textContent=DB.audit.length+' entries';
if(!list)return;
if(!DB.audit.length){list.innerHTML='<div style="text-align:center;color:var(--text3);padding:24px;font-style:italic">No activity yet.</div>';return;}
list.innerHTML=DB.audit.map(function(a){
var d=new Date(a.ts),ts=(d.getMonth()+1)+'/'+d.getDate()+' '+String(d.getHours()).padStart(2,'0')+':'+String(d.getMinutes()).padStart(2,'0');
return '<div class="alog-row"><div class="alog-ic">'+a.icon+'</div><div class="alog-body"><div class="alog-action">'+esc(a.action)+'</div><div class="alog-detail">'+esc(a.detail)+'</div></div><div class="alog-ts">'+ts+'</div></div>';
}).join('');
}
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
FIREBASE SYNC
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
var _fbApp=null,_fbAuth=null,_fbDb=null,_fbUser=null;
function initFirebase(){
if(!FIREBASE_CONFIG){updateFbUI();return;}
if(typeof firebase==='undefined'){console.warn('Firebase SDKs not loaded yet.');return;}
try{
if(!firebase.apps.length){_fbApp=firebase.initializeApp(FIREBASE_CONFIG);}
else{_fbApp=firebase.apps[0];}
_fbAuth=firebase.auth();
_fbDb=firebase.firestore();
_fbAuth.onAuthStateChanged(function(user){
_fbUser=user;updateSyncChip();updateFbUI();
if(user)firebasePullSilent();
});
}catch(e){console.warn('Firebase init error:',e);}
}
function updateFbUI(){
var nc=document.getElementById('fb-not-configured');
var so=document.getElementById('fb-signed-out');
var si=document.getElementById('fb-signed-in');
if(!nc||!so||!si)return;
if(!FIREBASE_CONFIG){nc.style.display='block';so.style.display='none';si.style.display='none';return;}
nc.style.display='none';
if(_fbUser){
so.style.display='none';si.style.display='block';
var av=document.getElementById('fb-avatar'),nm=document.getElementById('fb-display-name'),em=document.getElementById('fb-email-display');
if(av)av.textContent=(_fbUser.displayName||_fbUser.email||'?')[0].toUpperCase();
if(nm)nm.textContent=_fbUser.displayName||'β';
if(em)em.textContent=_fbUser.email||'β';
}else{so.style.display='block';si.style.display='none';}
}
function firebaseSignIn(){
if(!_fbAuth){toast('Firebase not configured.',true);return;}
_fbAuth.signInWithPopup(new firebase.auth.GoogleAuthProvider()).catch(function(e){toast('Sign-in failed: '+e.message,true);});
}
function firebaseSignOut(){
if(!_fbAuth)return;
_fbAuth.signOut().then(function(){toast('Signed out.');updateSyncChip();updateFbUI();});
}
function fbRef(){return _fbUser&&_fbDb?_fbDb.collection('finance_os').doc(_fbUser.uid):null;}
function firebasePushSilent(){
var ref=fbRef();if(!ref)return;
ref.set(JSON.parse(JSON.stringify(DB))).then(function(){
DB.sync.lastSync=new Date().toISOString();updateSyncChip();
}).catch(function(){});
}
function firebasePullSilent(){
var ref=fbRef();if(!ref)return;
ref.get().then(function(doc){
if(doc.exists&&doc.data()&&doc.data().v){
var remote=doc.data();
var lc=(DB.transactions.length||0)+(DB.goals.length||0);
var rc=(remote.transactions||[]).length+(remote.goals||[]).length;
if(rc>lc){DB=remote;ensureDefaults();saveDB(true);nav(curView());toast('β Data synced from cloud.');}
DB.sync.lastSync=new Date().toISOString();updateSyncChip();
}else{firebasePushSilent();}
}).catch(function(){});
}
function firebasePushManual(){
var ref=fbRef();if(!ref){toast('Not signed in.',true);return;}
var chip=document.getElementById('sync-chip');if(chip){chip.className='syncing';chip.textContent='β Pushingβ¦';}
ref.set(JSON.parse(JSON.stringify(DB))).then(function(){
DB.sync.lastSync=new Date().toISOString();saveDB(true);updateSyncChip();updateFbUI();
var el=document.getElementById('fb-sync-status');if(el)el.textContent='β Pushed at '+new Date().toLocaleTimeString('en-ZA',{hour:'2-digit',minute:'2-digit'});
audit('β','Pushed to Cloud',_fbUser.email);toast('β Pushed to cloud!');
}).catch(function(e){toast('Push failed: '+e.message,true);updateSyncChip();});
}
function firebasePullManual(){
var ref=fbRef();if(!ref){toast('Not signed in.',true);return;}
var chip=document.getElementById('sync-chip');if(chip){chip.className='syncing';chip.textContent='β Pullingβ¦';}
ref.get().then(function(doc){
if(doc.exists&&doc.data()&&doc.data().v){
DB=doc.data();ensureDefaults();DB.sync.lastSync=new Date().toISOString();
saveDB(true);nav(curView());updateSyncChip();updateFbUI();
var el=document.getElementById('fb-sync-status');if(el)el.textContent='β Pulled at '+new Date().toLocaleTimeString('en-ZA',{hour:'2-digit',minute:'2-digit'});
audit('β','Pulled from Cloud',_fbUser.email);toast('β Synced from cloud!');
}else{toast('No cloud data found. Push first.',true);updateSyncChip();}
}).catch(function(e){toast('Pull failed: '+e.message,true);updateSyncChip();});
}
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
HELPERS
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
var MOS=['January','February','March','April','May','June','July','August','September','October','November','December'];
var MOSS=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
function today(){return new Date().toISOString().slice(0,10);}
function uid(){return Date.now().toString(36)+Math.random().toString(36).slice(2,5);}
function esc(s){return String(s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');}
function R(n){return 'R '+Number(n||0).toLocaleString('en-ZA',{minimumFractionDigits:2,maximumFractionDigits:2});}
function periodKey(y,m){return y+'-'+m;}
function txForPeriod(y,m){
return DB.transactions.filter(function(t){return t.date&&t.date.startsWith(y+'-'+m);});
}
function txInRange(fromY,fromM,toY,toM){
var from=fromY+'-'+fromM,to=toY+'-'+toM+'|';
return DB.transactions.filter(function(t){
var ym=t.date?t.date.slice(0,7):'';
return ym>=from&&ym<=to.slice(0,7);
});
}
function sumType(txs,type){return txs.filter(function(t){return t.type===type;}).reduce(function(s,t){return s+(+t.amount||0);},0);}
function accName(id){var a=DB.settings.accounts.find(function(x){return x.id===id;});return a?a.name:'β';}
function accColor(id){var a=DB.settings.accounts.find(function(x){return x.id===id;});return a?a.color:'#6366f1';}
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
NAV + UI
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
var _curView='dashboard';
function curView(){return _curView;}
function nav(v){
_curView=v;
document.querySelectorAll('.view').forEach(function(el){el.classList.remove('active');});
document.querySelectorAll('.sbi').forEach(function(el){el.classList.remove('active');});
var vEl=document.getElementById('view-'+v);if(vEl)vEl.classList.add('active');
var sEl=document.querySelector('.sbi[data-v="'+v+'"]');if(sEl)sEl.classList.add('active');
var titles={dashboard:'Dashboard',income:'Income',expenses:'Expenses',accounts:'Bank Accounts',recurring:'Recurring',goals:'Savings Goals',receipts:'Receipts',history:'History',reports:'Reports & CSV',audit:'Audit Log',settings:'Settings'};
document.getElementById('tb-title').textContent=titles[v]||v;
closeSidebar();
// Render the view
var renders={dashboard:renderDashboard,income:renderIncome,expenses:renderExpenses,accounts:renderAccounts,recurring:renderRecurring,goals:renderGoals,receipts:renderReceipts,history:renderHistory,reports:renderReports,audit:renderAudit,settings:renderSettings};
if(renders[v])renders[v]();
}
function openSidebar(){document.getElementById('sidebar').classList.add('open');document.getElementById('sb-overlay').classList.add('show');}
function closeSidebar(){document.getElementById('sidebar').classList.remove('open');document.getElementById('sb-overlay').classList.remove('show');}
function closeOv(id){document.getElementById(id).classList.remove('open');}
function openOv(id){document.getElementById(id).classList.add('open');}
function toast(msg,err){
var el=document.getElementById('toast');el.textContent=msg;el.className='show'+(err?' err':'');
clearTimeout(toast._t);toast._t=setTimeout(function(){el.className='';},3200);
}
function cfm(title,msg,cb){
document.getElementById('cf-title').textContent=title;
document.getElementById('cf-msg').textContent=msg;
document.getElementById('cf-yes').onclick=function(){closeCf();cb();};
document.getElementById('cf-ov').classList.add('open');
}
function closeCf(){document.getElementById('cf-ov').classList.remove('open');}