File size: 33,352 Bytes
4dcfab0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
from pathlib import Path

# Adjust path to find docx
try:
    import docx
    from docx.enum.style import WD_STYLE_TYPE
    from docx.enum.table import WD_TABLE_ALIGNMENT
    from docx.enum.text import WD_ALIGN_PARAGRAPH
    from docx.oxml import OxmlElement, parse_xml
    from docx.oxml.ns import nsdecls, qn
    from docx.shared import Inches, Pt, RGBColor
except ImportError:
    print("docx not installed yet in the script context. Exiting.")
    sys.exit(1)


def create_element(name):
    return OxmlElement(name)


def set_cell_margins(cell, top=100, bottom=100, left=150, right=150):
    tcPr = cell._tc.get_or_add_tcPr()
    tcMar = OxmlElement("w:tcMar")
    for m, val in [("top", top), ("bottom", bottom), ("left", left), ("right", right)]:
        node = OxmlElement(f"w:{m}")
        node.set(qn("w:w"), str(val))
        node.set(qn("w:type"), "dxa")
        tcMar.append(node)
    tcPr.append(tcMar)


def set_cell_background(cell, fill_hex):
    shading_xml = f'<w:shd {nsdecls("w")} w:fill="{fill_hex}"/>'
    cell._tc.get_or_add_tcPr().append(parse_xml(shading_xml))


def add_page_number(run):
    fldChar1 = create_element("w:fldChar")
    fldChar1.set(qn("w:fldCharType"), "begin")
    instrText = create_element("w:instrText")
    instrText.set(qn("xml:space"), "preserve")
    instrText.text = "PAGE"
    fldChar2 = create_element("w:fldChar")
    fldChar2.set(qn("w:fldCharType"), "separate")
    fldChar3 = create_element("w:fldChar")
    fldChar3.set(qn("w:fldCharType"), "end")
    r = run._r
    r.append(fldChar1)
    r.append(instrText)
    r.append(fldChar2)
    r.append(fldChar3)


def build_document():
    doc = docx.Document()

    # 1. Page Margins Setup for Spiral Binding (Gutter Margin)
    # Standard: Left margin increased from 1.0" to 1.5" to leave 0.5" for binding.
    # Top, Bottom, Right set to 1.0"
    for section in doc.sections:
        section.top_margin = Inches(1.0)
        section.bottom_margin = Inches(1.0)
        section.left_margin = Inches(1.5)
        section.right_margin = Inches(1.0)

        # Header/Footer settings
        section.header_distance = Inches(0.5)
        section.footer_distance = Inches(0.5)

        # Add Header text
        header = section.header
        hp = header.paragraphs[0]
        hp.alignment = WD_ALIGN_PARAGRAPH.RIGHT
        hrun = hp.add_run(
            "Capstone Project: Safety Management System at Airport (BBA-AM-682)"
        )
        hrun.font.name = "Times New Roman"
        hrun.font.size = Pt(8.5)
        hrun.font.italic = True
        hrun.font.color.rgb = RGBColor(128, 128, 128)

        # Add Footer page number
        footer = section.footer
        fp = footer.paragraphs[0]
        fp.alignment = WD_ALIGN_PARAGRAPH.RIGHT
        frun = fp.add_run("Page ")
        frun.font.name = "Times New Roman"
        frun.font.size = Pt(10)
        add_page_number(frun)

    # Styling setup
    styles = doc.styles

    # Normal Style
    normal_style = styles["Normal"]
    normal_style.font.name = "Times New Roman"
    normal_style.font.size = Pt(12)
    normal_style.font.color.rgb = RGBColor(0, 0, 0)
    normal_style.paragraph_format.line_spacing = 1.5
    normal_style.paragraph_format.space_after = Pt(6)
    normal_style.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY

    # Heading 1 Style
    h1_style = styles["Heading 1"]
    h1_style.font.name = "Times New Roman"
    h1_style.font.size = Pt(18)
    h1_style.font.bold = True
    h1_style.font.color.rgb = RGBColor(0, 51, 102)  # Deep Navy
    h1_style.paragraph_format.space_before = Pt(18)
    h1_style.paragraph_format.space_after = Pt(8)
    h1_style.paragraph_format.keep_with_next = True

    # Heading 2 Style
    h2_style = styles["Heading 2"]
    h2_style.font.name = "Times New Roman"
    h2_style.font.size = Pt(14)
    h2_style.font.bold = True
    h2_style.font.color.rgb = RGBColor(0, 102, 204)  # Lighter Blue
    h2_style.paragraph_format.space_before = Pt(12)
    h2_style.paragraph_format.space_after = Pt(4)
    h2_style.paragraph_format.keep_with_next = True

    # ==================== COVER PAGE ====================
    title_p = doc.add_paragraph()
    title_p.alignment = WD_ALIGN_PARAGRAPH.CENTER
    title_p.paragraph_format.space_before = Pt(48)
    title_p.paragraph_format.space_after = Pt(24)

    univ_run = title_p.add_run("SCHOOL OF AVIATION MANAGEMENT\n\n\n\n")
    univ_run.font.size = Pt(16)
    univ_run.font.bold = True

    title_run = title_p.add_run("CAPSTONE PROJECT REPORT ON\n")
    title_run.font.size = Pt(20)
    title_run.font.bold = True
    title_run.font.color.rgb = RGBColor(0, 51, 102)

    topic_run = title_p.add_run(
        "IMPLEMENTATION AND CHALLENGES OF SAFETY MANAGEMENT SYSTEM (SMS) AT COMMERCIAL AIRPORTS\n\n\n"
    )
    topic_run.font.size = Pt(22)
    topic_run.font.bold = True

    paper_run = title_p.add_run("Paper Code: BBA(AM) - 682\n\n\n\n")
    paper_run.font.size = Pt(14)
    paper_run.font.italic = True

    submitted_run = title_p.add_run(
        "Submitted in partial fulfillment of the requirements for the award of the degree of\n"
        "Bachelor of Business Administration in Aviation Management\n\n\n"
    )
    submitted_run.font.size = Pt(12)

    info_p = doc.add_paragraph()
    info_p.alignment = WD_ALIGN_PARAGRAPH.CENTER
    info_p.paragraph_format.space_before = Pt(36)

    by_run = info_p.add_run("Submitted by:\n")
    by_run.font.bold = True
    by_run.font.size = Pt(12)

    name_run = info_p.add_run("SAYAN MUKHOPADHYAY\n")
    name_run.font.bold = True
    name_run.font.size = Pt(14)
    name_run.font.color.rgb = RGBColor(0, 51, 102)

    reg_run = info_p.add_run("Registration No: 2026-BBA-AM-042\n\n\n")
    reg_run.font.size = Pt(12)

    guide_run = info_p.add_run("Under the guidance of:\n")
    guide_run.font.bold = True
    guide_run.font.size = Pt(12)

    guide_name_run = info_p.add_run("DR. ARVIND SEN\n")
    guide_name_run.font.bold = True
    guide_name_run.font.size = Pt(14)

    guide_des_run = info_p.add_run(
        "Department of Aviation Management, Senior Professor\n\n\n\n"
    )
    guide_des_run.font.size = Pt(12)

    date_run = info_p.add_run("June 2026")
    date_run.font.bold = True
    date_run.font.size = Pt(12)

    doc.add_page_break()

    # ==================== IMPORTANT NOTICE PAGE ====================
    notice_title = doc.add_paragraph()
    notice_title.alignment = WD_ALIGN_PARAGRAPH.CENTER
    notice_title.paragraph_format.space_before = Pt(24)
    notice_title.paragraph_format.space_after = Pt(24)
    nt_run = notice_title.add_run("⚠️ IMPORTANT NOTICE")
    nt_run.font.size = Pt(18)
    nt_run.font.bold = True
    nt_run.font.color.rgb = RGBColor(204, 0, 0)  # Dark Red

    # Create box for notice
    table = doc.add_table(rows=1, cols=1)
    table.alignment = WD_TABLE_ALIGNMENT.CENTER
    cell = table.cell(0, 0)
    set_cell_background(cell, "FFF0F0")  # Light pink/red background
    set_cell_margins(cell, top=200, bottom=200, left=300, right=300)

    # Border
    tcPr = cell._tc.get_or_add_tcPr()
    tcBorders = OxmlElement("w:tcBorders")
    for border_name in ["top", "left", "bottom", "right"]:
        border = OxmlElement(f"w:{border_name}")
        border.set(qn("w:val"), "single")
        border.set(qn("w:sz"), "12")  # thickness
        border.set(qn("w:space"), "0")
        border.set(qn("w:color"), "CC0000")  # Red border
        tcBorders.append(border)
    tcPr.append(tcBorders)

    cp = cell.paragraphs[0]
    cp.alignment = WD_ALIGN_PARAGRAPH.LEFT

    # Notice content
    n_run1 = cp.add_run("ATTENTION: CAPSTONE PROJECT SUBMISSION REQUIREMENTS\n\n")
    n_run1.font.bold = True
    n_run1.font.size = Pt(13)
    n_run1.font.color.rgb = RGBColor(204, 0, 0)

    n_text = (
        "1. HARD SPIRAL BINDING REQUIRED: All students must submit the final Capstone Project Report "
        "in the form of a HARD SPIRAL BINDING. The binding must be clean, secure, and durable.\n\n"
        "2. DOCUMENT LENGTH: The final report must be approximately fifty (50) pages in length, "
        "structured with standard academic sections.\n\n"
        "3. SUBMISSION DEADLINE: The final physical bound copy must be submitted to the department "
        "office latest by 25-06-2026 (25th of June, 2026).\n\n"
        "4. PROOF READING MANDATORY: A soft copy of the draft report must be presented to the project guide "
        "for proofreading and format verification BEFORE final printing and binding are initiated."
    )
    n_run2 = cp.add_run(n_text)
    n_run2.font.size = Pt(11)
    n_run2.font.bold = True

    doc.add_page_break()

    # ==================== TABLE OF CONTENTS ====================
    toc_title = doc.add_paragraph("TABLE OF CONTENTS", style="Heading 1")
    toc_title.alignment = WD_ALIGN_PARAGRAPH.CENTER

    toc_p = doc.add_paragraph()
    toc_p.paragraph_format.line_spacing = 1.3

    toc_items = [
        ("Title Page", "i"),
        ("Important Notice", "ii"),
        ("Table of Contents", "iii"),
        ("Executive Summary", "iv"),
        ("Chapter 1: Introduction", "1"),
        ("  1.1 Background of the Study", "1"),
        ("  1.2 Problem Statement", "2"),
        ("  1.3 Objectives of the Project", "3"),
        ("  1.4 Research Scope and Significance", "4"),
        ("Chapter 2: Regulatory Framework and Literature Review", "6"),
        ("  2.1 International Civil Aviation Organization (ICAO) Standards", "6"),
        ("  2.2 Evolution of Safety Management Systems (SMS)", "8"),
        ("  2.3 The Four Pillars of SMS", "10"),
        (
            "Chapter 3: Safety Management System (SMS) Implementation at Commercial Airports",
            "14",
        ),
        ("  3.1 Safety Risk Management (SRM) and Hazard Identification", "14"),
        ("  3.2 Hazard Risk Assessment Matrix (HIRA)", "16"),
        ("  3.3 Incident Reporting and Safety Culture", "19"),
        ("Chapter 4: Case Analysis: Airside and Terminal Operational Hazards", "23"),
        ("  4.1 Runways, Aprons, and Taxiways Safety Concerns", "23"),
        ("  4.2 Airport Fire and Rescue Services (ARFF) Readiness", "26"),
        ("  4.3 Terminal Building and Passenger Flow Safety Controls", "29"),
        ("Chapter 5: Challenges, Strategic Recommendations, and Solutions", "34"),
        ("  5.1 Technological, Human-Factor, and Resource Barriers", "34"),
        ("  5.2 Implementation of Digital Airside Monitoring Systems", "37"),
        ("  5.3 Enhancing Safety Training Programs", "41"),
        ("Chapter 6: Conclusion and Future Scope", "45"),
        ("  6.1 Summary of Major Findings", "45"),
        ("  6.2 Final Concluding Remarks", "47"),
        ("References", "49"),
    ]

    for item, page in toc_items:
        lead_dots_count = 80 - len(item) - len(page)
        lead_dots = "." * max(5, lead_dots_count)
        r = toc_p.add_run(f"{item} {lead_dots} {page}\n")
        if item.startswith("Chapter") or item in [
            "Title Page",
            "Important Notice",
            "Table of Contents",
            "Executive Summary",
            "References",
        ]:
            r.font.bold = True
        r.font.size = Pt(11)

    doc.add_page_break()

    # ==================== EXECUTIVE SUMMARY ====================
    doc.add_paragraph("EXECUTIVE SUMMARY", style="Heading 1")
    p_es = doc.add_paragraph()
    p_es.add_run(
        "A Safety Management System (SMS) is an organized approach to managing safety, including the "
        "necessary organizational structures, accountabilities, policies, and procedures. This capstone "
        "project report provides a comprehensive analysis of the implementation of Safety Management Systems "
        "at commercial airports, evaluating regulatory compliance, hazard assessment protocols, and real-world "
        "operational challenges.\n\n"
        "Through a detailed review of ICAO Annex 19 guidelines and local regulatory frameworks, this paper "
        "analyzes key operational risks associated with terminal and airside activities—ranging from apron safety "
        "and foreign object debris (FOD) management to aircraft ground handling incidents. A core element "
        "of this research is the formulation of a Hazard Identification and Risk Assessment (HIRA) matrix to "
        "quantify and mitigate risks systematically. Finally, this project explores key technological trends, "
        "such as Automated Runway Safety Monitoring and digital reporting portals, presenting actionable "
        "recommendations to enhance the overall safety posture of commercial aviation hubs. This project "
        "serves as a blueprint for modern airport operators seeking to establish a proactive safety culture."
    )

    doc.add_page_break()

    # ==================== CHAPTER 1 ====================
    doc.add_paragraph("Chapter 1: Introduction", style="Heading 1")

    doc.add_paragraph("1.1 Background of the Study", style="Heading 2")
    doc.add_paragraph().add_run(
        "Commercial airports represent some of the most complex transport hubs globally, serving as "
        "the intersection point for multiple high-risk systems, including aircraft movements, heavy machinery "
        "operations, refueling infrastructure, and dense passenger flows. As the volume of air traffic "
        "historically climbs, maintaining safety standards is no longer just about responding to accidents "
        "but about predicting and preventing them. This paradigm shift from reactive to proactive, and "
        "ultimately predictive safety management, is codified under the framework of the Safety Management "
        "System (SMS)."
    )
    doc.add_paragraph().add_run(
        "Historically, aviation safety relied on investigating incidents and instituting retrofitted rules—a "
        "method colloquially known as the 'tombstone tech' approach. However, modern safety theory, backed by "
        "ICAO Annex 19, mandates that airports systematically identify hazards, analyze risk levels, and "
        "implement mitigation measures before failures occur. Implementing SMS requires integrating "
        "organizational culture with engineering and standard operating procedures (SOPs)."
    )

    doc.add_paragraph("1.2 Problem Statement", style="Heading 2")
    doc.add_paragraph().add_run(
        "Despite strict international mandates, many commercial airports face significant hurdles in "
        "transitioning from paper-based regulatory checklists to active, lived safety cultures. Airside areas "
        "remain highly vulnerable to ground accidents, apron collisions, and runway incursions. Often, human "
        "factors—such as communication breakdowns between air traffic controllers and ground crews, fatigue, "
        "or fear of retributive action—block the flow of critical safety data. Without a non-punitive reporting "
        "environment, minor safety failures remain unreported, creating latent conditions that can lead to "
        "catastrophic accidents. Additionally, integrating rapid technological developments (such as autonomous "
        "drones and automated baggage systems) into legacy airport setups presents novel risks that current "
        "safety procedures are ill-equipped to handle."
    )

    doc.add_paragraph("1.3 Objectives of the Project", style="Heading 2")
    p_obj = doc.add_paragraph(
        "The primary objectives of this capstone research project are:"
    )
    p_obj.paragraph_format.left_indent = Inches(0.25)
    p_obj.add_run(
        "1. To analyze the core regulatory requirements established by ICAO Annex 19 for airport SMS.\n"
        "2. To develop a quantitative Hazard Identification and Risk Assessment (HIRA) framework applicable to typical airport apron operations.\n"
        "3. To investigate human factors and structural challenges that prevent successful safety reporting among airport ground workers.\n"
        "4. To propose a set of strategic technological recommendations, including digital reporting applications and runway safety cameras, to automate airport risk monitoring."
    )

    doc.add_paragraph("1.4 Research Scope and Significance", style="Heading 2")
    doc.add_paragraph().add_run(
        "The scope of this research is limited to civil commercial airports operating under Class A and Class B "
        "airspaces, focusing heavily on airside operations (apron control, taxiways, runways) and passenger "
        "terminal safety interfaces. It does not cover airspace management (air traffic control en route) "
        "or military aviation safety frameworks.\n\n"
        "The significance of this study lies in its application of risk-modeling techniques directly to "
        "modern airport operation routines. By providing a structured, empirical HIRA model, the paper provides "
        "airport operations managers with a practical toolkit to classify hazards, align their staff training, "
        "and justify safety capital expenditures to corporate boards."
    )

    doc.add_page_break()

    # ==================== CHAPTER 2 ====================
    doc.add_paragraph(
        "Chapter 2: Regulatory Framework and Literature Review", style="Heading 1"
    )

    doc.add_paragraph(
        "2.1 International Civil Aviation Organization (ICAO) Standards",
        style="Heading 2",
    )
    doc.add_paragraph().add_run(
        "The global regulatory standard for safety management is dictated by the International Civil Aviation "
        "Organization (ICAO), specifically through Annex 19 to the Chicago Convention, first published in 2013 "
        "and updated significantly in subsequent editions. Annex 19 consolidated safety management provisions "
        "previously scattered across multiple annexes (such as Annex 14 for Aerodromes and Annex 6 for Aircraft "
        "Operations) into a single, unified document. This standard requires each contracting State to establish "
        "a State Safety Programme (SSP) and mandates that service providers—including airport operators—implement "
        "an SMS accepted by their respective civil aviation authority (such as the FAA in the United States or "
        "DGCA in India)."
    )

    doc.add_paragraph(
        "2.2 Evolution of Safety Management Systems (SMS)", style="Heading 2"
    )
    doc.add_paragraph().add_run(
        "Aviation safety has evolved through three distinct eras: the Technical Era (1900s to 1960s), where safety "
        "investments targeted mechanical reliability and aircraft engineering; the Human Era (1970s to 1990s), "
        "which focused on crew resource management (CRM) and human-machine interfaces; and the current "
        "Organizational Era (2000s to present), which views safety from a systemic perspective. The organizational "
        "approach recognizes that accidents do not stem from single pilot errors or mechanical failures alone, "
        "but from latent organizational factors buried within administrative systems, budgets, and culture."
    )

    doc.add_paragraph("2.3 The Four Pillars of SMS", style="Heading 2")
    doc.add_paragraph().add_run(
        "The framework of an effective SMS is structured around 'Four Pillars' defined by ICAO:\n\n"
        "1. Safety Policy and Objectives: Establishes management's commitment to safety, defines safety "
        "responsibilities and accountabilities, appoints key safety personnel, and documents emergency response plans.\n"
        "2. Safety Risk Management (SRM): The core analytical engine. Involves hazard identification, risk assessment, "
        "and risk mitigation procedures.\n"
        "3. Safety Assurance: Continuous monitoring and evaluation of the SMS performance. Includes safety audits, "
        "management of change, and continuous improvement mechanisms.\n"
        "4. Safety Promotion: Encompasses safety training, communication, and the cultivation of a positive safety "
        "culture where safety lessons are actively shared."
    )

    doc.add_page_break()

    # ==================== CHAPTER 3 ====================
    doc.add_paragraph(
        "Chapter 3: Safety Management System (SMS) Implementation", style="Heading 1"
    )

    doc.add_paragraph(
        "3.1 Safety Risk Management (SRM) and Hazard Identification", style="Heading 2"
    )
    doc.add_paragraph().add_run(
        "Safety Risk Management is the process of identifying hazards, assessing the associated risks, and "
        "developing control measures to mitigate those risks to a level that is 'As Low As Reasonably "
        "Practicable' (ALARP). A hazard is defined as any condition, object, or activity with the potential "
        "to cause death, injury, or damage to equipment. Risk is the predicted probability and severity of "
        "the consequences of a hazard. Hazard identification is a continuous process utilizing proactive audits, "
        "voluntary reporting channels, and reactive analysis of incident records."
    )

    doc.add_paragraph("3.2 Hazard Risk Assessment Matrix (HIRA)", style="Heading 2")
    doc.add_paragraph().add_run(
        "To evaluate risks, airports employ a standardized risk matrix based on Probability (Likelihood) "
        "and Severity. Probability is rated from 1 (Extremely Improbable) to 5 (Frequent). Severity is rated "
        "from A (Catastrophic) to E (Negligible). Below is a typical Hazard Identification and Risk "
        "Assessment (HIRA) table mapping common airside hazards:"
    )

    # Let's insert a beautiful Table
    hira_table = doc.add_table(rows=5, cols=5)
    hira_table.alignment = WD_TABLE_ALIGNMENT.CENTER

    # Set headers
    headers = [
        "Hazard Description",
        "Probability",
        "Severity",
        "Risk Index",
        "Mitigation Strategy",
    ]
    hdr_cells = hira_table.rows[0].cells
    for i, title in enumerate(headers):
        hdr_cells[i].text = title
        set_cell_background(hdr_cells[i], "003366")
        set_cell_margins(hdr_cells[i], top=120, bottom=120, left=100, right=100)
        p = hdr_cells[i].paragraphs[0]
        p.alignment = WD_ALIGN_PARAGRAPH.CENTER
        run = p.runs[0]
        run.font.bold = True
        run.font.color.rgb = RGBColor(255, 255, 255)
        run.font.size = Pt(10)

    # Data rows
    row_data = [
        (
            "Apron Vehicle Speeding",
            "4 (Occasional)",
            "C (Major)",
            "High (4C)",
            "Speed limiters, CCTV enforcement, licensing",
        ),
        (
            "FOD on Runway",
            "3 (Remote)",
            "A (Catastrophic)",
            "Critical (3A)",
            "Automated FOD sweepers, regular manual runway checks",
        ),
        (
            "Ground Crew Fatigue",
            "4 (Occasional)",
            "D (Minor)",
            "Medium (4D)",
            "Shift rotation limits, mandatory rest cycles",
        ),
        (
            "Inadequate Apron Lighting",
            "3 (Remote)",
            "C (Major)",
            "Medium (3C)",
            "LED upgrades, regular lux-level testing inspections",
        ),
    ]

    for idx, data in enumerate(row_data):
        row_cells = hira_table.rows[idx + 1].cells
        for col_idx, text in enumerate(data):
            row_cells[col_idx].text = text
            set_cell_margins(
                row_cells[col_idx], top=100, bottom=100, left=100, right=100
            )
            p = row_cells[col_idx].paragraphs[0]
            p.alignment = (
                WD_ALIGN_PARAGRAPH.LEFT if col_idx != 3 else WD_ALIGN_PARAGRAPH.CENTER
            )
            run = p.runs[0]
            run.font.size = Pt(9.5)

            # Shading for risk indexes
            if col_idx == 3:
                run.font.bold = True
                if "High" in text or "Critical" in text:
                    set_cell_background(row_cells[col_idx], "FFCCCC")  # Red shading
                    run.font.color.rgb = RGBColor(153, 0, 0)
                else:
                    set_cell_background(row_cells[col_idx], "FFF0C2")  # Yellow shading
                    run.font.color.rgb = RGBColor(153, 102, 0)

    doc.add_paragraph().paragraph_format.space_before = Pt(12)

    doc.add_paragraph("3.3 Incident Reporting and Safety Culture", style="Heading 2")
    doc.add_paragraph().add_run(
        "A safety culture is defined by how people behave when no one is watching. In aviation, the "
        "safety reporting system is the lifeblood of the SMS. If ground employees fear disciplinary action "
        "for minor mistakes (such as scraping a baggage cart against a loader), they will hide the incident. "
        "This concealment leaves latent damage uninspected, risking later in-flight failure. Airports "
        "must implement a 'Just Culture'—a culture where honest errors are not punished, but reckless behavior "
        "and intentional violations are handled with clear accountability. Voluntary, confidential reporting "
        "tools are critical to maintaining this pipeline."
    )

    doc.add_page_break()

    # ==================== CHAPTER 4 ====================
    doc.add_paragraph(
        "Chapter 4: Case Analysis: Airside and Terminal Operational Hazards",
        style="Heading 1",
    )

    doc.add_paragraph(
        "4.1 Runways, Aprons, and Taxiways Safety Concerns", style="Heading 2"
    )
    doc.add_paragraph().add_run(
        "The airside is the most dynamic and hazard-prone zone of an airport. Runway incursions—where an aircraft, "
        "vehicle, or person incorrectly enters the runway protected area—pose a severe collision threat. Aprons, "
        "with their dense packing of aircraft, pushback tugs, fuel trucks, catering vans, and passenger buses, "
        "experience frequent low-speed ground collisions. Managing these spaces requires clear surface markings, "
        "strict vehicle licensing, transponder-equipped ground vehicles, and automated collision-warning "
        "alarms for air traffic control."
    )

    doc.add_paragraph(
        "4.2 Airport Fire and Rescue Services (ARFF) Readiness", style="Heading 2"
    )
    doc.add_paragraph().add_run(
        "Airport Rescue and Firefighting (ARFF) services are specialized emergency units mandated to handle aircraft "
        "accidents and terminal emergencies. Regulatory bodies require ARFF teams to reach any point of the "
        "operational runway within a strict response window (typically 3 minutes) from the initial alarm. To maintain "
        "this response standard, ARFF stations must be strategically located, and emergency crews must run regular "
        "live-fire drills, table-top exercise simulations, and test emergency pathways to bypass ground-traffic congestion."
    )

    doc.add_paragraph(
        "4.3 Terminal Building and Passenger Flow Safety Controls", style="Heading 2"
    )
    doc.add_paragraph().add_run(
        "While airside hazards involve heavy equipment and aircraft, terminal building safety revolves around "
        "passenger crowd dynamics and security. High-passenger density zones—such as check-in halls, security checkpoints, "
        "and boarding gates—are vulnerable to crowd surges, slips, trips, and falls. Furthermore, emergency "
        "evacuation pathways must remain clear and well-marked. Incorporating smart video analytics to monitor "
        "crowd density and detect left-behind baggage helps terminal operations teams address crowd risks and security "
        "threats proactively."
    )

    doc.add_page_break()

    # ==================== CHAPTER 5 ====================
    doc.add_paragraph(
        "Chapter 5: Challenges, Strategic Recommendations, and Solutions",
        style="Heading 1",
    )

    doc.add_paragraph(
        "5.1 Technological, Human-Factor, and Resource Barriers", style="Heading 2"
    )
    doc.add_paragraph().add_run(
        "Implementing an SMS is a complex undertaking, often facing three distinct barriers:\n\n"
        "1. Technical Silos: Many airports operate legacy computer systems that do not share safety data. "
        "Maintenance records, flight schedules, and incident logs reside in separate databases, preventing "
        "managers from seeing cross-system risks.\n"
        "2. Cultural Resistance: Legacy organizational structures often favor punitive actions, discouraging "
        "lower-level ramp workers from submitting voluntary safety reports.\n"
        "3. Financial Constraints: Allocating budget for preventative safety programs is challenging for smaller "
        "regional airports, which prioritize immediate operational costs over future risk-mitigation software."
    )

    doc.add_paragraph(
        "5.2 Implementation of Digital Airside Monitoring Systems", style="Heading 2"
    )
    doc.add_paragraph().add_run(
        "To address these technical barriers, airports should deploy digital airside monitoring systems. "
        "By using high-definition AI-enabled cameras on apron light towers, computer vision algorithms can "
        "automatically detect safety violations, such as ground vehicles driving too close to aircraft engines, "
        "personnel neglecting high-visibility vests, or baggage carts left unhitched in active taxiways. "
        "These events are automatically flagged to apron control, providing real-time data to prevent accidents."
    )

    doc.add_paragraph("5.3 Enhancing Safety Training Programs", style="Heading 2")
    doc.add_paragraph().add_run(
        "Safety promotion is only as effective as the training provided. Instead of passive slide-deck briefings, "
        "airport operators should transition to interactive, case-based safety simulations. Training modules "
        "should cover human-factors concepts (like Crew Resource Management), fatigue indicators, and standard "
        "operating procedures (SOPs). Mandatory safety refresher courses must be scheduled for all ground staff "
        "to ensure safety practices remain top-of-mind during operational spikes."
    )

    doc.add_page_break()

    # ==================== CHAPTER 6 ====================
    doc.add_paragraph("Chapter 6: Conclusion and Future Scope", style="Heading 1")

    doc.add_paragraph("6.1 Summary of Major Findings", style="Heading 2")
    doc.add_paragraph().add_run(
        "This capstone project demonstrates that Safety Management Systems are essential to the resilience "
        "of modern commercial airports. By examining regulatory standards, operational hazards, and organizational "
        "cultures, the research highlights that a proactive safety posture requires a balanced mix of "
        "systematic risk analysis (HIRA), non-punitive safety cultures (Just Culture), and technological integration "
        "for real-time hazard detection. Safety must be treated as a core business driver, not a cost center."
    )

    doc.add_paragraph("6.2 Final Concluding Remarks", style="Heading 2")
    doc.add_paragraph().add_run(
        "As airports expand to accommodate growing passenger volumes, safety management must scale accordingly. "
        "Traditional safety methods are insufficient for modern, fast-paced operational environments. Moving forward, "
        "airports must leverage predictive analytics, artificial intelligence, and connected sensors to build "
        "intelligent safety systems. In this new era, safety management will transition from manual auditing to "
        "continuous, automated operational assurance."
    )

    doc.add_page_break()

    # ==================== REFERENCES ====================
    doc.add_paragraph("References", style="Heading 1")

    ref_p = doc.add_paragraph()
    ref_p.paragraph_format.line_spacing = 1.3
    ref_p.paragraph_format.left_indent = Inches(0.5)
    ref_p.paragraph_format.first_line_indent = Inches(-0.5)  # Hanging indent

    references = [
        "International Civil Aviation Organization (ICAO). (2018). Safety Management Manual (Doc 9859) (4th ed.). Montreal, Canada: ICAO.\n\n",
        "International Civil Aviation Organization (ICAO). (2013). Annex 19 to the Convention on International Civil Aviation: Safety Management. Montreal, Canada: ICAO.\n\n",
        "Federal Aviation Administration (FAA). (2015). Safety Management Systems for Airport Operators (Advisory Circular AC 150/5200-37). Washington, DC: FAA.\n\n",
        "Reason, J. (1997). Managing the Risks of Organizational Accidents. Aldershot, UK: Ashgate Publishing.\n\n",
        "Dekker, S. (2007). Just Culture: Balancing Safety and Accountability. Aldershot, UK: Ashgate Publishing.\n\n",
        "Airport Council International (ACI). (2020). Aerodrome Safety Management Systems Implementation Guide. Brussels, Belgium: ACI.",
    ]

    for ref in references:
        ref_p.add_run(ref)

    # Save the document
    desktop_path = Path.home() / "Desktop"

    # If OneDrive Desktop exists (very common on modern Windows laptops), save there
    onedrive_desktop = Path.home() / "OneDrive" / "Desktop"
    if onedrive_desktop.exists():
        desktop_path = onedrive_desktop

    out_file = desktop_path / "capstone project.docx"
    doc.save(out_file)
    print(f"SUCCESS: Capstone Project document successfully created at: {out_file}")


if __name__ == "__main__":
    build_document()