File size: 43,456 Bytes
87d1369
0dbef86
 
e919b6e
30bff0b
d1e9df6
6815a7b
 
 
cb571ee
d1e9df6
55ecd21
 
9859341
bc34ac4
810b74a
 
 
 
 
 
 
bc34ac4
 
 
 
810b74a
 
 
 
 
 
bc34ac4
810b74a
 
bc34ac4
 
 
 
 
 
a905215
bc34ac4
 
 
 
 
810b74a
 
 
 
 
bc34ac4
 
810b74a
 
8a316b5
ac12398
a905215
ac12398
810b74a
bc34ac4
810b74a
 
 
bc34ac4
810b74a
 
 
 
bc34ac4
810b74a
bc34ac4
810b74a
 
bc34ac4
 
 
 
 
 
 
 
 
810b74a
bc34ac4
810b74a
 
 
679efd6
7e268c8
 
810b74a
bc34ac4
810b74a
 
 
 
 
bc34ac4
 
 
 
 
 
 
 
 
 
 
 
 
e4a9cdf
 
7950e75
 
 
42ee111
7950e75
9f8a193
7950e75
 
 
 
 
 
6bc8971
7950e75
 
6bc8971
 
a35de65
6bc8971
 
 
7950e75
e4a9cdf
6bc8971
 
 
7950e75
 
 
 
 
 
 
 
e4a9cdf
 
49e1167
e657f5b
 
 
 
 
 
4b3cacd
e657f5b
 
 
 
 
 
7850dd2
e657f5b
b8ff5b4
e657f5b
f0512a3
b81c60c
e657f5b
 
c307e52
3cb6cd7
a6da6b1
 
 
 
 
 
 
 
b8ff5b4
e657f5b
 
 
 
 
 
 
 
7849e25
ff6b058
c90dee5
a6da6b1
 
3cb6cd7
a6da6b1
 
 
 
 
3cb6cd7
a6da6b1
b8ff5b4
a6da6b1
 
e4a9cdf
3cb6cd7
a6da6b1
 
e4a9cdf
27688cc
 
 
 
 
 
1a92a5c
307eeb6
27688cc
 
 
 
 
7850dd2
27688cc
1a92a5c
27688cc
 
 
c307e52
3cb6cd7
 
 
 
 
 
c307e52
4f9418b
3cb6cd7
1a92a5c
3cb6cd7
 
27688cc
c80f65d
 
 
 
 
5166288
ff6b058
c90dee5
c80f65d
f4993c1
3cb6cd7
 
 
 
 
 
 
 
1a92a5c
3cb6cd7
 
 
 
 
67822d7
e4a9cdf
27688cc
 
57de3f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27688cc
e4a9cdf
bc34ac4
810b74a
 
 
9e11c36
810b74a
bc34ac4
810b74a
 
 
bc34ac4
810b74a
bc34ac4
810b74a
 
 
bc34ac4
810b74a
bc34ac4
810b74a
bc34ac4
810b74a
 
bc34ac4
810b74a
bc34ac4
810b74a
bc34ac4
810b74a
 
bc34ac4
810b74a
bc34ac4
810b74a
bc34ac4
810b74a
bc34ac4
 
 
 
 
810b74a
bc34ac4
810b74a
bc34ac4
 
810b74a
 
bc34ac4
810b74a
 
bc34ac4
810b74a
 
 
 
 
bc34ac4
 
 
 
 
 
 
810b74a
 
 
 
 
bc34ac4
810b74a
 
 
 
 
bc34ac4
810b74a
bc34ac4
810b74a
bc34ac4
 
810b74a
bc34ac4
810b74a
bc34ac4
810b74a
 
 
 
bc34ac4
810b74a
 
 
 
 
bc34ac4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
810b74a
 
 
 
 
bc34ac4
810b74a
bc34ac4
810b74a
bc34ac4
 
810b74a
bc34ac4
810b74a
bc34ac4
810b74a
 
 
 
2b93111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
810b74a
 
 
bc34ac4
 
 
810b74a
e4a9cdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60c01af
e4a9cdf
 
 
 
 
 
 
60c01af
e4a9cdf
23aea0d
308e4f8
 
 
23aea0d
e4a9cdf
 
 
222eb7b
3e1a571
a6da6b1
3e1a571
e4a9cdf
 
2734b8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e332b4a
2734b8d
 
 
 
 
 
e4a9cdf
67822d7
27688cc
d468bfe
c307e52
 
 
 
 
e657f5b
 
 
 
 
 
 
 
 
 
 
 
 
 
c307e52
67822d7
 
 
 
c307e52
 
 
 
 
27688cc
c307e52
 
 
 
 
 
 
 
 
 
 
 
 
c80f65d
67822d7
 
57de3f5
 
 
 
 
 
 
 
9eae25f
 
57de3f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc34ac4
a6da6b1
e4a9cdf
2b93111
ae6a606
 
 
 
 
 
 
 
 
 
 
 
0d8d3d5
ae6a606
 
 
 
a151a19
 
 
 
 
 
 
 
 
2f2c9cb
a151a19
 
 
ae6a606
 
 
 
 
 
 
 
 
2f2c9cb
ae6a606
 
 
 
 
 
 
 
 
 
 
 
2f2c9cb
ae6a606
 
 
 
 
 
 
 
 
 
 
 
2f2c9cb
ae6a606
 
 
 
 
 
 
 
 
 
 
 
2f2c9cb
ae6a606
 
 
 
a151a19
 
 
 
 
 
 
 
2f2c9cb
a151a19
 
2f2c9cb
 
 
 
 
 
8aeef2b
2f2c9cb
 
8aeef2b
f98badd
2f2c9cb
 
a151a19
 
 
 
 
 
ae6a606
 
 
 
 
2f2c9cb
a151a19
ae6a606
 
a151a19
 
 
 
 
 
 
 
 
2f2c9cb
a151a19
 
2b93111
 
bc34ac4
 
 
 
e9a420f
bc34ac4
 
 
 
 
810b74a
bc34ac4
 
 
810b74a
 
 
bc34ac4
14c38e4
bc34ac4
 
383a97d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558d642
0b6bc0c
fabae42
d65f53d
b105546
 
 
 
 
d65f53d
 
fabae42
d65f53d
fabae42
 
 
d65f53d
fabae42
 
d65f53d
fabae42
 
d65f53d
fabae42
 
 
 
 
 
 
 
d65f53d
55b6662
fabae42
d65f53d
fabae42
 
 
d65f53d
fabae42
 
d65f53d
fabae42
a151a19
 
 
 
fabae42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a151a19
 
 
d65f53d
55b6662
 
 
fabae42
 
d65f53d
fabae42
 
 
 
 
 
 
 
 
 
 
d65f53d
fabae42
 
 
 
d65f53d
fabae42
d65f53d
fabae42
 
d65f53d
 
 
 
 
 
fabae42
 
 
 
 
 
 
 
8436df1
d65f53d
fabae42
 
 
 
 
 
 
 
8436df1
d65f53d
fabae42
d65f53d
fabae42
 
 
 
 
8436df1
d65f53d
fabae42
 
d65f53d
1c19879
 
 
 
 
93ac351
a151a19
93ac351
 
 
 
 
 
 
 
 
 
 
6f06040
93ac351
 
a2a0b63
93ac351
 
738364f
d65f53d
 
1775bda
d65f53d
 
54af379
93ac351
1ac593a
93ac351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a363dd9
bbe8126
c542223
 
 
 
 
 
 
 
 
 
 
 
 
d65f53d
 
 
 
cd4e48f
 
 
 
 
 
 
 
 
 
 
d65f53d
 
cd4e48f
d65f53d
 
cd4e48f
d65f53d
 
 
 
 
a151a19
d65f53d
c542223
 
 
 
 
 
 
 
 
 
d65f53d
c542223
 
d65f53d
cd4e48f
d65f53d
 
 
bbe8126
 
d65f53d
bbe8126
73bfb21
bbe8126
a151a19
d1e9df6
4a115ce
54af379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ac593a
 
 
 
 
 
 
 
 
 
 
7684911
 
 
 
 
 
1ac593a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
baa0574
6f06040
 
48e7ec6
 
523b107
9d5a638
1775bda
80fa53f
efef438
 
dfaea06
 
 
 
 
 
 
 
 
80fa53f
dfaea06
1775bda
efef438
dfaea06
efef438
 
dfaea06
80fa53f
efef438
 
 
 
80fa53f
efef438
 
 
dfaea06
1775bda
efef438
dfaea06
 
efef438
 
1775bda
dfaea06
 
1775bda
e234896
 
8690ba1
1775bda
efef438
 
 
 
 
 
 
1775bda
 
 
 
 
 
48e7ec6
 
172ffc7
ac67369
9474cf1
ac67369
83c29fc
ac67369
 
172ffc7
 
ac67369
 
 
172ffc7
 
ac67369
172ffc7
 
 
 
 
93ac351
6f06040
ac67369
93ac351
172ffc7
 
93ac351
ac67369
93ac351
356a709
6f06040
 
 
 
 
4a115ce
 
 
 
6815a7b
d1e9df6
cc0a99e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f9ede9
5bb687b
4e56f05
9b1491d
87d1369
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
<!DOCTYPE html>
<html lang="ru">
<head>



<!-- Основные стили PNotify -->
<link href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script>

  
<meta charset="UTF-8">
<title>Калькулятор удобрений</title>
<style>
/* Общие стили */
body {
    margin: 0 auto;
    width: 1000px;
    padding: 1em;
    background-color: #f0f0f0;
    font-family: Arial, sans-serif;
}

/* Стили для заголовка */
.header-box {
    border: 2px solid #2e8b57;
    background-color: #2e8b57;
    color: white;
    text-align: center;
    padding: 1em;
    border-radius: 10px;
    margin-bottom: 20px;
    width: 1000px;
    box-sizing: border-box;
}

/* Общие стили для всех рамок */
fieldset, .calculation-box {
    border: 2px solid #2e8b57;
    background-color: #eaffea;
    padding: 1em;
    margin-bottom: 20px;
    border-radius: 8px;
    width: 1000px;
    box-sizing: border-box;
}

legend {
    font-weight: bold;
    color: #2e8b57;
    padding: 0 10px;
}

/* Стили для блока профиля */
.main-container {
    display: grid;
    grid-template-columns: 38px repeat(7, 110px);
    gap: 10px;
    padding: 5px;
    margin-left: -50px; /* Сдвигаем блок левее */
}

.profile-container {
    display: contents;
}

.profile-element {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.profile-label {
    font-weight: bold;
    font-size: 0.9em;
}

.profile-element input {
    width: 80px;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
    text-align: center;
}

.nitrogen-container {
    grid-column: 1 / -1;
    display: flex;
    gap: 20px;
    padding-left: 40px;
    margin-top: 5px;
}

.nitrogen-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.nitrogen-group label {
    font-weight: bold;
    font-size: 0.9em;
}

.nitrogen-group input {
    width: 60px;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
}



/* Стили для колонок азотных элементов */
.nitrogen-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin-left: 20px; /* Сдвигаем блок правее */
}

.nitrogen-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center; /* Центрируем содержимое колонки */
}

.column-header {
    font-weight: bold;
    font-size: 0.8em;
    margin-bottom: 5px;
    text-align: center;
    width: 100%;
}

.nitrogen-group {
    display: flex;
    justify-content: center; /* Центрируем поля ввода */
}

.nitrogen-group input {
    width: 80px;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
}



/* Стили для контейнера первого блока (NPK) */
.npk-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px; /* Отступ между заголовком и основным блоком */
    margin-left: 15px; /* Общий отступ слева */
    margin-top: 10px; /* Отступ сверху */
}

/* Стили для заголовка NPK */
.header-npk {
    font-weight: bold;
    font-size: 0.9em;
    text-align: center;
    width: 65px; /* Ширина заголовка совпадает с шириной блока */
    margin-bottom: 5px; /* Отступ между заголовком и основным блоком */
    margin-left: -5px; /* Сдвигаем строки влево */
    margin-bottom: 5px; /* Отступ между заголовком и основным блоком */
}

/* Стили для основного блока NPK */
.block-npk {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    padding: 10px;
    background-color: #eaffea;
    border: 1px solid #2e8b57;
    border-radius: 8px;
    width: 65px; /* Ширина блока */
}

/* Стили для внутреннего контейнера строк (NPK) */
.inner-block-npk {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    margin-left: -33px; /* Сдвигаем строки влево */
    margin-right: 0px; /* Добавляем внешний отступ справа */
    padding-bottom: 26px; /* Добавляем внешний отступ справа */
}

.row-npk {
    display: flex;
    align-items: center;
    gap: 5px;
}

.label-npk {
    font-weight: bold;
    min-width: 50px; /* Минимальная ширина меток */
    text-align: right;
}

.row-npk span {
    font-size: 0.9em;
}

/* Стили для контейнера второго блока (Ca-Mg-S) */
.camgs-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px; /* Отступ между заголовком и основным блоком */
    margin-left: 8px; /* Общий отступ слева */
    margin-top: 10px; /* Отступ сверху */
}

/* Стили для заголовка Ca-Mg-S */
.header-camgs {
    font-weight: bold;
    font-size: 0.9em;
    text-align: center;
    width: 75px; /* Ширина заголовка совпадает с шириной блока */
    margin-bottom: 5px; /* Отступ между заголовком и основным блоком */
}

/* Стили для основного блока Ca-Mg-S */
.block-camgs {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    padding: 10px;
    background-color: #eaffea;
    border: 1px solid #2e8b57;
    border-radius: 8px;
    width: 85px; /* Ширина блока */
}

/* Стили для внутреннего контейнера строк (Ca-Mg-S) */
.inner-block-camgs {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    margin-left: -31px; /* Сдвигаем строки влево */
    margin-right: 0px; /* Добавляем внешний отступ справа */
    padding-bottom: 26px; /* Добавляем внешний отступ*/
}

.row-camgs {
    display: flex;
    align-items: center;
    gap: 5px;
}

.label-camgs {
    font-weight: bold;
    min-width: 65px; /* Минимальная ширина меток */
    text-align: right;
}

.row-camgs span {
    font-size: 0.9em;
}




/* Стили для контейнера блока N1 */
.n1-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px; /* Отступ между заголовком и основным блоком */
    margin-left: 8px; /* Общий отступ слева */
    margin-top: 10px; /* Отступ сверху */
}

/* Стили для заголовка N1 */
.header-n1 {
    font-weight: bold;
    font-size: 0.9em;
    text-align: left;
    width: 100%; /* Ширина заголовка */
    margin-bottom: 5px; /* Отступ между заголовком и основным блоком */
}

.header-n1 span {
    margin-right: 5px; /* Отступ между "N1=" и значением */
}

#n1-value {
    font-weight: normal;
    color: #333;
    min-width: 100px; /* Место для значения */
}

/* Стили для основного блока N1 */
.block-n1 {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    padding: 10px;
    background-color: #eaffea;
    border: 1px solid #2e8b57;
    border-radius: 8px;
    width: 200px; /* Ширина блока */
}

/* Стили для строки с меткой и индикатором */
.n1-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    width: 100%;
}

.label-n1 {
    font-weight: bold;
    font-size: 0.9em;
    text-align: left;
    width: 100%;
}

/* Стили для контейнера индикатора */
.indicator-container {
    width: 150px; /* Ширина индикатора */
    height: 10px; /* Высота индикатора */
    background-color: #f0f0f0; /* Фон индикатора */
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}

/* Стили для индикатора */
.indicator {
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transition: width 0.3s ease; /* Плавное изменение ширины */
}

.red-indicator {
    background-color: red;
}

.blue-indicator {
    background-color: blue;
}






  
  
  
/* Стили для таблицы удобрений */
.fertilisers-container {
    display: flex;
    flex-direction: column;
    margin-left: 20px; /* Сдвигаем блок  */
}

.fert-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.fert-header {
    font-weight: bold;
    text-align: center;
    width: 80px;
    padding: 5px;
    font-size: 0.9em;
}

.fert-name {
    font-weight: bold;
    width: 120px;
    text-align: left;
    font-size: 0.9em;
}

.fert-cell {
    text-align: center;
    width: 80px;
    padding: 5px;
    font-size: 0.9em;
}

.fert-input {
    width: 70px;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
    text-align: center;
    margin: 0 5px;
    font-size: 0.9em;
}

/* Стили для блока расчета */
.calculation-container {
    display: flex;
    gap: 40px;
    align-items: flex-start;
}

.compensation-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.enhancement-title {
    font-weight: bold;
    color: #2e8b57;
    margin-bottom: 5px;
}

.compensation-weights {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.weight-input-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.weight-input-group label {
    width: 80px;
    text-align: right;
    font-weight: bold;
    font-size: 0.9em;
}

.weight-input-group input {
    width: 70px;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.input-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#calculate-btn {
    background-color: #2e8b57;
    color: white;
    border: none;
    padding: 8px 16px;
    font-size: 16px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
    margin-bottom: 5px;
    font-weight: bold;
}

#calculate-btn:hover {
    background-color: #3cb371;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-group label {
    width: 80px;
    text-align: right;
    font-weight: bold;
    font-size: 0.9em;
}

.input-group input {
    width: 70px;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
}




.micro-container {
    padding: 10px;
}

.micro-row {
    display: flex;
    gap: 20px;
}

.micro-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.micro-group label {
    min-width: 120px;
}

.micro-group input {
    width: 80px;
    text-align: right;
}




  
</style>

<body>
    <div class="header-box">
        <h1>Калькулятор удобрений</h1>
    </div>

<fieldset>
    <legend>Макропрофиль в мг/л (ppm)</legend>
    <div class="main-container">
        <!-- Основные элементы -->
        <div class="profile-container">
            <div class="profile-element" style="grid-column: 2">
                <span class="profile-label">N</span>
                <input id="profile_n" type="number" value="125.000" step="0.001"/>
            </div>
            <div class="profile-element" style="grid-column: 3">
                <span class="profile-label">P</span>
                <input id="profile_p" type="number" value="31.000" step="0.001"/>
            </div>
            <div class="profile-element" style="grid-column: 4">
                <span class="profile-label">K</span>
                <input id="profile_k" type="number" value="210.000" step="0.001"/>
            </div>
            <div class="profile-element" style="grid-column: 5">
                <span class="profile-label">Ca</span>
                <input id="profile_ca" type="number" value="82.000" step="0.001"/>
            </div>
            <div class="profile-element" style="grid-column: 6">
                <span class="profile-label">Mg</span>
                <input id="profile_mg" type="number" value="24.000" step="0.001"/>
            </div>
            <div class="profile-element" style="grid-column: 7">
                <span class="profile-label">S</span>
                <input id="profile_s" type="number" value="57.49" step="0.001"/>
            </div>
            <div class="profile-element" style="grid-column: 8">
                <span class="profile-label">CaCl</span>
                <input id="profile_cacl" type="number" value="57.49" step="0.001"/>
            </div>
            <div class="profile-element" style="grid-column: 9">
                <span class="profile-label">EC</span>
                <input id="profile_ec" type="number" value="0.0" step="0.001"/>
            </div>
            <div class="profile-element" style="grid-column: 9">
                <span class="profile-label">t°C</span>
                <input id="profile_temp" type="number" value="25.0" step="0.01"/>
            </div>
        </div>
        
        <!-- Азотные элементы и блок NPK -->
        <div style="display: flex; align-items: flex-start; gap: 20px;">
            <!-- Колонки азотных элементов -->
            <div class="nitrogen-container" style="margin-top: 10px; display: flex; gap: 20px;">
                <!-- Колонка 1: NH4 -->
                <div class="nitrogen-column">
                    <div class="column-header">NH4</div>
                    <div class="nitrogen-group">
                        <input id="profile_nh4" type="number" value="1.0" step="1.0" readonly style="background-color: #f0f0f0; color: #666;">
                    </div>
                    <div class="nitrogen-group">
                        <input id="calculated_nh4" type="number" value="0.000" step="0.001" readonly style="background-color: #f0f0f0; color: #666;">
                    </div>
                </div>

                <!-- Колонка 2: NO3 -->
                <div class="nitrogen-column">
                    <div class="column-header">NO3</div>
                    <div class="nitrogen-group">
                        <input id="profile_no3" type="number" value="8.25" step="0.01" min="0" max="100.001"/>
                    </div>
                    <div class="nitrogen-group">
                        <input id="calculated_no3" type="number" value="0.000" step="0.001" readonly style="background-color: #f0f0f0; color: #666;">
                    </div>
                </div>
            </div>



<!-- Первый блок NPK -->
<div class="npk-container">
    <!-- Заголовок NPK -->
    <div class="header-npk">N-P-K</div>
    <!-- Основной блок с содержимым -->
    <div class="block-npk">
        <!-- Дополнительный контейнер для строк -->
        <div class="inner-block-npk">
            <div class="row-npk">
                <span class="label-npk">N:</span>
                <span id="npk-n-value">0</span>
            </div>
            <div class="row-npk">
                <span class="label-npk">P:</span>
                <span id="npk-p-value">0</span>
            </div>
            <div class="row-npk">
                <span class="label-npk">K:</span>
                <span id="npk-k-value">0</span>
            </div>
        </div>
    </div>
</div>

<!-- Второй блок Ca-Mg-S -->
<div class="camgs-container">
    <!-- Заголовок Ca-Mg-S -->
    <div class="header-camgs">Ca-Mg-S</div>
    <!-- Основной блок с содержимым -->
    <div class="block-camgs">
        <!-- Дополнительный контейнер для строк -->
        <div class="inner-block-camgs">
            <div class="row-camgs">
                <span class="label-camgs">CaO:</span>
                <span id="caMaS-ca-value">0</span>
            </div>
            <div class="row-camgs">
                <span class="label-camgs">MgO:</span>
                <span id="caMaS-mg-value">0</span>
            </div>
            <div class="row-camgs">
                <span class="label-camgs">SO:</span>
                <span id="caMaS-so-value">0</span>
            </div>
        </div>
    </div>
</div>




<!-- Блок N1 -->
<div class="n1-container">
    <!-- Заголовок N1 -->
    <div class="header-n1">
        <span>N1:</span>
        <span id="n1-value">0.25:1.88:0.67:0.19:0.45 PPM=528.35</span>
    </div>
    <!-- Основной блок с содержимым -->
    <div class="block-n1">
        <!-- Катионы -->
        <div class="n1-row">
            <span class="label-n1">Катионы:</span>
            <div class="indicator-container">
                <div class="indicator red-indicator" id="cation-indicator"></div>
            </div>
        </div>
        <!-- Анионы -->
        <div class="n1-row">
            <span class="label-n1">Анионы:</span>
            <div class="indicator-container">
                <div class="indicator blue-indicator" id="anion-indicator"></div>
            </div>
        </div>
    </div>
</div>






          
        </div>
    </div>
</fieldset>
<fieldset>
    <legend>Составы солей</legend>
    <div class="fertilisers-container">
        <!-- Заголовки -->
        <div class="fert-row">
            <span class="fert-name">Удобрение</span>
            <span class="fert-header">NH4</span>
            <span class="fert-header">NO3</span>
            <span class="fert-header">P</span>
            <span class="fert-header">K</span>
            <span class="fert-header">Ca</span>
            <span class="fert-header">Mg</span>
            <span class="fert-header">S</span>
            <span class="fert-header">Cl</span>
            <span class="fert-header">Грамм</span>
        </div>
        
        <!-- Строки с удобрениями -->
        <div class="fert-row">
            <span class="fert-name">CaN2O6</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="11.863" step="0.001" id="fert_ca_no3"/>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="16.972" step="0.001" id="fert_ca_ca"/>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" step="0.001" id="calcium_nitrate"/>
        </div>
        
        <div class="fert-row">
            <span class="fert-name">KNO3</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="13.854" step="0.001" id="fert_kno3_no3"/>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="36.672" step="0.001" id="fert_kno3_k"/>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" step="0.001" id="potassium_nitrate"/>
        </div>
        
        <div class="fert-row">
            <span class="fert-name">NH4NO3</span>
            <input class="fert-input" type="number" value="17.499" step="0.001" id="fert_nh4no3_nh4"/>
            <input class="fert-input" type="number" value="17.499" step="0.001" id="fert_nh4no3_no3"/>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" step="0.001" id="ammonium_nitrate"/>
        </div>
        
        <div class="fert-row">
            <span class="fert-name">MgSO4</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="10.22" step="0.001" id="fert_mgso4_mg"/>
            <input class="fert-input" type="number" value="13.483" step="0.001" id="fert_mgso4_s"/>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" step="0.001" id="magnesium_sulfate"/>
        </div>
        
        <div class="fert-row">
            <span class="fert-name">KH2PO4</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="22.761" step="0.001" id="fert_kh2po4_p"/>
            <input class="fert-input" type="number" value="28.731" step="0.001" id="fert_kh2po4_k"/>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" step="0.001" id="monopotassium_phosphate"/>
        </div>
        
        <div class="fert-row">
            <span class="fert-name">K2SO4</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="44.874" step="0.001" id="fert_k2so4_k"/>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="18.401" step="0.001" id="fert_k2so4_s"/>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" step="0.001" id="potassium_sulfate"/>
        </div>
        <div class="fert-row">
            <span class="fert-name">CaCl</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="18.294" step="0.001" id="fert_caca"/>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" value="32.366" step="0.001" id="fert_clcl"/>
            <input class="fert-input" type="number" step="0.001" id="ca_cl_nitrate"/>
        </div>
        
        
        <!-- Добавленные строки для Fe и Micro -->
        <div class="fert-row">
            <span class="fert-name">Fe</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" step="0.001" id="iron_amount">
        </div>
        
        <div class="fert-row">
            <span class="fert-name">Micro</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <span class="fert-cell">-</span>
            <input class="fert-input" type="number" step="0.001" id="micro_amount">
        </div>
    </div>
</fieldset>
    <fieldset class="calculation-box">
        <legend>Расчёт удобрений</legend>
        <div class="calculation-container">
            <div class="compensation-section">

            <div class="input-column">
                <button id="calculate-btn">Рассчитать</button>
                <div class="input-group">
                    <label for="liters-input">Литры:</label>
                    <input type="number" id="liters-input" value="100" min="1" step="1">
                </div>
                <div class="input-group">
                    <label for="rounding-precision">Точность:</label>
                    <input type="number" id="rounding-precision" value="3" min="0" max="3" step="1">
                </div>
            </div>
        </div>
    </fieldset>

  

<!-- Кастомные стили -->
<style>
  .pnotify-success {
    background: linear-gradient(135deg, #4CAF50, #2E7D32) !important;
    border-left: 5px solid #1B5E20 !important;
  }
  
  .pnotify-error {
    background: linear-gradient(135deg, #F44336, #C62828) !important;
    border-left: 5px solid #B71C1C !important;
  }
  
  .deficit-item {
    margin: 8px 0;
    display: flex;
    align-items: center;
  }
  
  .deficit-item i {
    margin-right: 10px;
    font-size: 1.2em;
  }
</style>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
<script>
let call_data;

const ecConstants = {
    'P': 0.0012, 'K': 0.0018, 'Mg': 0.0015, 
    'Ca': 0.0016, 'S': 0.0014, 
    'N (NO3-)': 0.0017, 'N (NH4+)': 0.0019
};

document.getElementById('calculate-btn').addEventListener('click', function () {
    console.log("=== НАЧАЛО ОБРАБОТКИ ===");

    // 1. Получаем значение точности округления с подробным логированием
    const roundingInput = document.getElementById('rounding-precision');
    console.log("Значение поля rounding-precision (raw):", roundingInput.value);

    const initialRounding = parseInt(roundingInput.value);
    console.log("Парсинг значения rounding (после parseInt):", initialRounding);

    const roundingPrecision = Math.min(Math.max(initialRounding || 3, 0), 6);
    console.log("Финальное значение точности (0-6):", roundingPrecision);

    // 2. Улучшенная функция для безопасного получения числового значения с логированием
    const getValue = (id) => {
        const element = document.getElementById(id);
        if (!element) {
            console.error(`Элемент с ID ${id} не найден!`);
            return 0;
        }
        console.log(`Значение поля ${id}:`, element.value);

        const value = parseFloat(element.value); // Парсим число напрямую
        const result = isNaN(value) ? 0 : value;

        console.log(`Парсинг значения ${id}:`, result);
        return result;
    };

    // 3. Формируем данные для сервера с пошаговым логированием
    console.log("=== ФОРМИРОВАНИЕ ДАННЫХ ДЛЯ СЕРВЕРА ===");

    const fertilizerConstants = {
        "Кальциевая селитра": {
            "N (NO3-)": getValue('fert_ca_no3') / 100,
            "Ca": getValue('fert_ca_ca') / 100
        },
        "Калий азотнокислый": {
            "N (NO3-)": getValue('fert_kno3_no3') / 100,
            "K": getValue('fert_kno3_k') / 100
        },
        "Аммоний азотнокислый": {
            "N (NO3-)": getValue('fert_nh4no3_no3') / 100,
            "N (NH4+)": getValue('fert_nh4no3_nh4') / 100
        },
        "Сульфат магния": {
            "Mg": getValue('fert_mgso4_mg') / 100,
            "S": getValue('fert_mgso4_s') / 100
        },
        "Монофосфат калия": {
            "P": getValue('fert_kh2po4_p') / 100,
            "K": getValue('fert_kh2po4_k') / 100
        },
        "Калий сернокислый": {
            "K": getValue('fert_k2so4_k') / 100,
            "S": getValue('fert_k2so4_s') / 100
        },
        "Кальций хлористый": { // Обновленные идентификаторы для CaCl
            "Ca": getValue('fert_caca') / 100, // Новый идентификатор
            "Cl": getValue('fert_clcl') / 100  // Новый идентификатор
        }
    };

    const profileSettings = {
        'P': getValue('profile_p'),
        'K': getValue('profile_k'),
        'Mg': getValue('profile_mg'),
        'Ca': getValue('profile_ca'),
        'S': getValue('profile_s'),
        'NO3_RAT': getValue('profile_no3'),
        'TOTAL_NITROG': getValue('profile_n'),
        'liters': parseInt(document.getElementById('liters-input').value) || 1,
        'rounding_precision': roundingPrecision
    };

    const requestData = {
        fertilizerConstants: fertilizerConstants,
        profileSettings: profileSettings
    };

    console.log("=== ПОЛНЫЙ ОБЪЕКТ ДЛЯ ОТПРАВКИ ===", JSON.stringify(requestData, null, 2));

    // 4. Проверка данных с подробным выводом
    console.log("=== ПРОВЕРКА ДАННЫХ ===");

    const requiredFertilizers = [
        "Кальциевая селитра", "Калий азотнокислый", "Аммоний азотнокислый",
        "Сульфат магния", "Монофосфат калия", "Калий сернокислый", "Кальций хлористый"
    ];

    let hasErrors = false;
    for (const fert of requiredFertilizers) {
        if (!requestData.fertilizerConstants[fert]) {
            console.error(`ОШИБКА: Отсутствует удобрение: ${fert}`);
            hasErrors = true;
        } else {
            console.log(`Удобрение ${fert} присутствует`);
        }
    }

    const requiredProfileFields = ['P', 'K', 'Mg', 'Ca', 'S', 'NO3_RAT', 'TOTAL_NITROG'];
    for (const field of requiredProfileFields) {
        if (isNaN(requestData.profileSettings[field])) {
            console.error(`ОШИБКА: Некорректное значение для параметра ${field}`);
            hasErrors = true;
        } else {
            console.log(`Параметр ${field} в порядке:`, requestData.profileSettings[field]);
        }
    }

    console.log("Параметр rounding_precision:", requestData.profileSettings.rounding_precision);

    if (hasErrors) {
        const errorMsg = "Пожалуйста, проверьте введенные данные. Обнаружены ошибки в форме. Смотрите консоль для деталей.";
        console.error(errorMsg);
        alert(errorMsg);
        return;
    }

    // 5. Отправка данных на сервер с полным логированием
    console.log("=== ОТПРАВКА ДАННЫХ НА СЕРВЕР ===");

    fetch('/calculation', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(requestData),
    })
        .then(response => {
            console.log("Получен ответ от сервера. Статус:", response.status);
            if (!response.ok) {
                console.error("ОШИБКА СЕРВЕРА. Полный ответ:", response);
                throw new Error(`HTTP error! status: ${response.status}`);
            }
            return response.json();
        })
        .then(data => {
            call_data = data;
            console.log("=== УСПЕШНЫЙ ОТВЕТ ОТ СЕРВЕРА ===", call_data);

            // Выводим данные в форму
            data_out(call_data);

            // Показываем статус расчёта
            showCalculationStatus(call_data);

            // Вызываем функцию для расчета катионов и анионов
            calculateCationsAndAnions(data);

            // Обновляем поля NH4 и NO3
            updateNitrogenFields(call_data);

            // Обновляем значения NPK
            calculateAndUpdate(call_data);

            // Получаем температуру из формы
            const temperature = parseFloat(document.getElementById('profile_temp').value) || 25;

            // Рассчитываем EC
            const ecValue = calculateEC(call_data, temperature);

            // Обновляем поле EC
            const ecInput = document.getElementById('profile_ec');
            if (ecInput) {
                ecInput.value = ecValue.toFixed(2);
                console.log(`Установлено значение EC: ${ecValue.toFixed(2)}`);
            }
        })
        .catch(error => {
            console.error("=== ОШИБКА ПРИ ОБРАБОТКЕ ===", error);
            alert("Ошибка при расчете: " + error.message);
        })
        .finally(() => {
            console.log("=== ЗАВЕРШЕНИЕ ОБРАБОТКИ ===");
        });
});













  
// Функция для вывода данных в форму
function data_out(data) {
    console.log("=== ЗАПИСЬ ДАННЫХ В ФОРМУ ===");

    // Сопоставление названий удобрений с их идентификаторами
    const fertilizerIdMap = {
        "Кальциевая селитра": "calcium_nitrate",
        "Калий азотнокислый": "potassium_nitrate",
        "Аммоний азотнокислый": "ammonium_nitrate",
        "Сульфат магния": "magnesium_sulfate",
        "Монофосфат калия": "monopotassium_phosphate",
        "Калий сернокислый": "potassium_sulfate",
        "Кальций хлористый": "ca_cl_nitrate" // Новый ID для хлористого кальция
    };

    // Записываем массы удобрений
    for (const [fertilizer, grams] of Object.entries(data.fertilizers)) {
        const inputId = fertilizerIdMap[fertilizer]; // Получаем ID из карты
        const inputElement = document.getElementById(inputId);
        if (inputElement) {
            inputElement.value = grams.toFixed(3); // Записываем значение в поле
            console.log(`Записано значение для ${fertilizer}: ${grams.toFixed(3)} г`);
        } else {
            console.warn(`Поле для удобрения ${fertilizer} не найдено`);
        }
    }

    // Записываем баланс элементов
    const elementIdMap = {
        "Ca": "profile_ca",
        "K": "profile_k",
        "Mg": "profile_mg",
        "P": "profile_p",
        "S": "profile_s",
        "N (NH4+)": "calculated_nh4", // Специальный ID для NH4
        "N (NO3-)": "calculated_no3"  // Специальный ID для NO3
    };

    for (const [element, ppm] of Object.entries(data.actual_profile)) {
        const inputId = elementIdMap[element]; // Получаем ID из карты
        const inputElement = document.getElementById(inputId);
        if (inputElement) {
            inputElement.value = ppm.toFixed(3); // Записываем значение в поле
            console.log(`Записано значение для ${element}: ${ppm.toFixed(3)} ppm`);
        } else {
            console.warn(`Поле для элемента ${element} не найдено`);
        }
    }
}









function updateNitrogenFields(data) {
    console.log("=== ОБНОВЛЕНИЕ ЗНАЧЕНИЙ NH4 И NO3 ===");

    // Извлекаем значения NH4 и NO3 из actual_profile
    const nh4Value = data.actual_profile["N (NH4+)"] || 0;
    const no3Value = data.actual_profile["N (NO3-)"] || 0;

    // Обновляем поля NH4
    document.getElementById("calculated_nh4").value = nh4Value.toFixed(3); // Расчетное значение NH4

    // Обновляем поля NO3
    document.getElementById("calculated_no3").value = no3Value.toFixed(3); // Расчетное значение NO3

    console.log(`Значения NH4 и NO3 обновлены: NH4=${nh4Value}, NO3=${no3Value}`);
}





  
function calculateAndUpdate(data) {
    console.log("=== РАСЧЕТ И ОБНОВЛЕНИЕ ДАННЫХ ===");

    // Извлекаем значения из actual_profile
    const nValue = (data.actual_profile["N (NH4+)"] || 0) + (data.actual_profile["N (NO3-)"] || 0);
    const pValue = data.actual_profile["P"] || 0;
    const kValue = data.actual_profile["K"] || 0;
    const caValue = data.actual_profile["Ca"] || 0;
    const mgValue = data.actual_profile["Mg"] || 0;
    const sValue = data.actual_profile["S"] || 0;

    // Динамический расчет процента азота
    const totalNitrogen = data.nitrogen_ratios.TOTAL_NITROGEN || 0; // Берем TOTAL_NITROGEN из ответа
    const nPercent = totalNitrogen / 10; // Делим на 10, как предложено

    // Рассчитываем общую массу раствора
    const totalMass = nValue / (nPercent / 100); // Общая масса = N / (nPercent / 100)

    // Переводим элементы в оксидную форму
    const pOxide = pValue * 2.29; // P → P2O5
    const kOxide = kValue * 1.2; // K → K2O
    const caOxide = caValue * 1.4; // Ca → CaO
    const mgOxide = mgValue * 1.67; // Mg → MgO
    const sOxide = sValue * 2.5; // S → SO3

    // Рассчитываем проценты от общей массы
    const pPercent = (pOxide / totalMass) * 100;
    const kPercent = (kOxide / totalMass) * 100;
    const caPercent = (caOxide / totalMass) * 100;
    const mgPercent = (mgOxide / totalMass) * 100;
    const sPercent = (sOxide / totalMass) * 100;

    console.log(`Результаты расчета:
    N: ${nPercent.toFixed(2)}%,
    P2O5: ${pPercent.toFixed(2)}%,
    K2O: ${kPercent.toFixed(2)}%,
    CaO: ${caPercent.toFixed(2)}%,
    MgO: ${mgPercent.toFixed(2)}%,
    SO3: ${sPercent.toFixed(2)}%`);

    // Обновляем HTML-элементы
    document.getElementById("npk-n-value").textContent = nPercent.toFixed(2);
    document.getElementById("npk-p-value").textContent = pPercent.toFixed(2);
    document.getElementById("npk-k-value").textContent = kPercent.toFixed(2);

    document.getElementById("caMaS-ca-value").textContent = caPercent.toFixed(2);
    document.getElementById("caMaS-mg-value").textContent = mgPercent.toFixed(2);
    document.getElementById("caMaS-so-value").textContent = sPercent.toFixed(2);
}






function calculateCationsAndAnions(data) {
    console.log("=== ТОЧНЫЙ РАСЧЕТ КАТИОНОВ И АНИОНОВ ===");
    
    // Молярные массы и валентности элементов
    const ION_DATA = {
        // Катионы
        'Ca': { mass: 40.08, charge: 2 },
        'Mg': { mass: 24.305, charge: 2 },
        'K': { mass: 39.098, charge: 1 },
        'NH4': { mass: 18.038, charge: 1 },
        // Анионы
        'NO3': { mass: 62.004, charge: 1 },
        'SO4': { mass: 96.06, charge: 2 },
        'H2PO4': { mass: 96.99, charge: 1 }
    };

    // Получаем данные профиля
    const profile = data.actual_profile;
    
    // Рассчитываем миллиэквиваленты (meq/L) для каждого иона
    const ions = {
        // Катионы
        'Ca': (profile['Ca'] || 0) * 2 / 40.08,
        'Mg': (profile['Mg'] || 0) * 2 / 24.305,
        'K': (profile['K'] || 0) * 1 / 39.098,
        'NH4': (profile['N (NH4+)'] || 0) * 1 / 18.038,
        // Анионы
        'NO3': (profile['N (NO3-)'] || 0) * 1 / 62.004,
        'SO4': (profile['S'] || 0) * 2 / 96.06,
        'H2PO4': (profile['P'] || 0) * 1 / 96.99
    };

    // Суммируем катионы и анионы
    const totalCations = ions['Ca'] + ions['Mg'] + ions['K'] + ions['NH4'];
    const totalAnions = ions['NO3'] + ions['SO4'] + ions['H2PO4'];
    
    // Рассчитываем процентное соотношение
    const total = totalCations + totalAnions;
    const cationPercent = (totalCations / total * 100).toFixed(1);
    const anionPercent = (totalAnions / total * 100).toFixed(1);

    console.log(`Катионы: ${totalCations.toFixed(2)} mEq/L (${cationPercent}%)`);
    console.log(`Анионы: ${totalAnions.toFixed(2)} mEq/L (${anionPercent}%)`);
    console.log(`Дисбаланс: ${(totalCations - totalAnions).toFixed(2)} mEq/L`);

    // Обновляем UI
    document.getElementById("n1-value").textContent = 
        `Катионы: ${totalCations.toFixed(2)} mEq/L | Анионы: ${totalAnions.toFixed(2)} mEq/L`;
    
    // Обновляем индикаторы
    document.getElementById("cation-indicator").style.width = `${cationPercent}%`;
    document.getElementById("anion-indicator").style.width = `${anionPercent}%`;
}




  
  

function calculateEC(data, temperature, alpha = 0.019) {
    console.log("=== РАСЧЕТ ЭЛЕКТРОПРОВОДНОСТИ (EC) ===");

    const profile = data.actual_profile;
    let totalEC = 0;

    const ecConstants = {
        'P': 0.0012, 'K': 0.0018, 'Mg': 0.0015,
        'Ca': 0.0016, 'S': 0.0014,
        'N (NO3-)': 0.0017, 'N (NH4+)': 0.0019
    };

    const significantElements = Object.keys(ecConstants);

    for (const element of significantElements) {
        const ppm = profile[element] || 0;
        const ecFactor = ecConstants[element];
        const elementEC = ppm * ecFactor;
        totalEC += elementEC;
        console.log(`EC для ${element}: ${elementEC.toFixed(5)} (ppm=${ppm}, const=${ecFactor})`);
    }

    console.log(`Общая EC без компенсации: ${totalEC.toFixed(5)}`);

    const compensatedEC = totalEC * (1 + alpha * (temperature - 25));
    console.log(`Компенсированная EC: ${compensatedEC.toFixed(5)} (T=${temperature}°C, α=${alpha})`);

    return compensatedEC;
}





  
</script>





<script>
// Инициализация
const notyf = new Notyf({
    duration: 5000,
    position: {x: 'right', y: 'top'},
    types: [
        {type: 'success', background: '#4CAF50'},
        {type: 'error', background: '#F44336'}
    ]
});

// Модифицированная функция
function showCalculationStatus(response) {
    if (Object.keys(response.deficits || {}).length === 0) {
        notyf.success('Расчёт успешен! Все элементы сбалансированы');
    } else {
        notyf.error('Дефициты: ' + 
            Object.entries(response.deficits)
                .map(([el, val]) => `${el}: ${val.toFixed(2)} ppm`)
                .join(', '));
    }
}
</script>


  
</body>
</html>