flowchart TD
    Start([User Access System]) --> SSO[SSO Login via RE Bridge]
    SSO --> Auth{Authentication Successful?}
    Auth -->|No| SSO
    Auth -->|Yes| Dashboard[Dashboard]
    
    Dashboard --> NavMenu[Side Navigation Menu]
    NavMenu --> MenuChoice{User Selection}
    
    MenuChoice -->|My Requests| MyReq[View My Requests]
    MenuChoice -->|Open Requests| OpenReq[View Open Requests]
    MenuChoice -->|Closed Requests| ClosedReq[View Closed Requests]
    MenuChoice -->|Raise New Request| RaiseReq[Create New Request]
    
    %% My Requests Flow
    MyReq --> ViewReqDetail[View Request Details]
    OpenReq --> ViewReqDetail
    ClosedReq --> ViewReqDetail
    
    %% Create New Request Flow
    RaiseReq --> Step1[Step 1: Template Selection]
    Step1 --> SelectCustom[Select Custom Request]
    SelectCustom --> Step2[Step 2: Basic Information]
    
    Step2 --> EnterBasic[Enter Request Details: Title, Description, Priority Express/Standard]
    EnterBasic --> Step3[Step 3: Approval Workflow]
    
    Step3 --> DefineApproval[Define Approval Hierarchy: Add Approvers @mention, Set TAT per level, Max 10 levels]
    DefineApproval --> CalcTAT[System Calculates Total TAT]
    CalcTAT --> Step4[Step 4: Participants & Access]
    
    Step4 --> AddSpectators[Add Spectators @mention - View-only access]
    AddSpectators --> Step5[Step 5: Documents & Attachments]
    
    Step5 --> UploadDocs[Upload Documents: PDF, Word, Excel, PPT, Images - Max 10MB per file - Link Google Docs/Sheets]
    UploadDocs --> Step6[Step 6: Review & Submit]
    
    Step6 --> ReviewAll[Review All Details: Request Overview, Basic Info, Approval Workflow, Participants, Documents]
    ReviewAll --> SubmitChoice{User Action}
    
    SubmitChoice -->|Save as Draft| Dashboard
    SubmitChoice -->|Submit Request| ValidateReq[Validate All Fields]
    ValidateReq --> SendNotif[Send Notifications to Approvers & Spectators]
    
    %% Approval Process Flow
    SendNotif --> ApprovalLevel[Request at Approval Level N]
    ApprovalLevel --> StartTAT[Start TAT Timer for Level N]
    StartTAT --> NotifyApprover[Notify Approver]
    
    NotifyApprover --> ApproverAction{Approver Action}
    ApproverAction -->|View Request| ViewReqDetail
    
    ViewReqDetail --> DetailTabs{View Tabs}
    DetailTabs -->|Overview| ShowOverview[Display Request Details & TAT Progress Bar]
    DetailTabs -->|Workflow| ShowWorkflow[Display Approval Hierarchy & TAT Status per Level]
    DetailTabs -->|Documents| ShowDocs[Display Uploaded Files & Preview PDF/Images]
    DetailTabs -->|Activity| ShowActivity[Display Timeline: All Actions & Events]
    
    ShowOverview --> QuickActions
    ShowWorkflow --> QuickActions
    ShowDocs --> QuickActions
    ShowActivity --> QuickActions
    
    QuickActions[Quick Actions Available] --> ActionChoice{Select Action}
    
    ActionChoice -->|Add Work Note| WorkNote[Add Comment/Message, @mention users, Attach files]
    ActionChoice -->|Add Approver| AddApprover[Add New Approver to Hierarchy]
    ActionChoice -->|Add Spectator| AddSpectatorAction[Add New Spectator - View-only]
    ActionChoice -->|Approve| ApproveModal[Approve Request Modal]
    ActionChoice -->|Reject| RejectModal[Reject Request Modal]
    
    WorkNote --> LogActivity1[Log to Activity Tab]
    AddApprover --> LogActivity1
    AddSpectatorAction --> LogActivity1
    LogActivity1 --> SendNotif2[Send Notifications]
    SendNotif2 --> ViewReqDetail
    
    %% Approval Decision Flow
    ApproveModal --> EnterApproveComment[Enter Comments & Remarks - Mandatory - 500 chars max]
    EnterApproveComment --> ConfirmApprove{Confirm Approval?}
    ConfirmApprove -->|Cancel| ViewReqDetail
    ConfirmApprove -->|Approve| CheckLevel{Is Final Approver?}
    
    CheckLevel -->|No| NextLevel[Move to Next Level]
    NextLevel --> LogApproval[Log Approval in Activity]
    LogApproval --> UpdateStatus1[Update Request Status]
    UpdateStatus1 --> ApprovalLevel
    
    CheckLevel -->|Yes| FinalApproval[Final Approval Recorded]
    FinalApproval --> ConsultCheck{Need Consultation?}
    ConsultCheck -->|Yes| UseWorkNote[Use Work Note to Consult with Expert]
    UseWorkNote --> FinalApproval
    ConsultCheck -->|No| GenerateConclusion
    
    %% Rejection Flow
    RejectModal --> EnterRejectComment[Enter Rejection Remarks - Mandatory - 500 chars max]
    EnterRejectComment --> ConfirmReject{Confirm Rejection?}
    ConfirmReject -->|Cancel| ViewReqDetail
    ConfirmReject -->|Reject| LogRejection[Log Rejection in Activity]
    LogRejection --> NotifyInitiator[Notify Initiator with Rejection Remarks]
    NotifyInitiator --> MarkRejected[Mark Request as Rejected]
    MarkRejected --> CloseRejected[Close Request]
    CloseRejected --> ArchivedReq[Move to Closed Requests]
    
    %% TAT Monitoring
    StartTAT --> MonitorTAT[Monitor TAT Progress]
    MonitorTAT --> TATCheck{TAT Status}
    TATCheck -->|Within TAT| GreenStatus[Green Indicator]
    TATCheck -->|80% Used| YellowStatus[Yellow Indicator - Send Reminder]
    TATCheck -->|Breached| RedStatus[Red Indicator - Send Alert]
    
    YellowStatus --> ContinueMonitor[Continue Monitoring]
    RedStatus --> ContinueMonitor
    GreenStatus --> ContinueMonitor
    ContinueMonitor --> ApproverAction
    
    %% Closure Flow
    GenerateConclusion[AI Generates Conclusion Remark from Work Notes, Comments, Activity Logs]
    GenerateConclusion --> ReturnToInitiator[Return to Initiator]
    ReturnToInitiator --> InitiatorReview[Initiator Reviews AI-Generated Conclusion]
    InitiatorReview --> EditConclusion{Edit Conclusion?}
    
    EditConclusion -->|Yes| ModifyConclusion[Edit Conclusion Remark]
    EditConclusion -->|No| ConfirmClosure
    ModifyConclusion --> ConfirmClosure[Confirm & Close Request]
    
    ConfirmClosure --> MarkClosed[Mark Request as Closed]
    MarkClosed --> FinalRecord[Conclusion Becomes Permanent Record]
    FinalRecord --> VisibleIn[Visible in: My Requests, Open Requests, Closed Requests]
    VisibleIn --> PostClosure
    
    %% Post-Closure Access
    PostClosure[Post-Closure Access] --> AccessibleTo[Accessible to All Participants & Spectators]
    AccessibleTo --> ShareOptions{Sharing Options}
    ShareOptions -->|Add Spectator| ShareInternal[Share Internally via Add Spectator]
    ShareOptions -->|Download| DownloadWorkNotes[Download Work Note Attachments Only]
    
    ShareInternal --> AuditTrail[All Actions Viewable for Audit]
    DownloadWorkNotes --> AuditTrail
    
    %% Notification System
    SendNotif -.->|In-App Alert| BellIcon[Bell Icon Notification with Count]
    SendNotif2 -.->|In-App Alert| BellIcon
    YellowStatus -.->|Auto Reminder| BellIcon
    RedStatus -.->|Auto Alert| BellIcon
    NotifyInitiator -.->|In-App Alert| BellIcon
    ReturnToInitiator -.->|In-App Alert| BellIcon
    
    BellIcon --> NotifDetails[Show Request ID, Message & Timestamp]
    NotifDetails --> ClickToView[Click to View Request]
    ClickToView --> ViewReqDetail
    
    AuditTrail --> End([Workflow Complete])
    ArchivedReq --> End
    
    style Start fill:#e1f5ff
    style SSO fill:#fff3cd
    style Dashboard fill:#d4edda
    style Step1 fill:#cfe2ff
    style Step2 fill:#cfe2ff
    style Step3 fill:#cfe2ff
    style Step4 fill:#cfe2ff
    style Step5 fill:#cfe2ff
    style Step6 fill:#cfe2ff
    style ApproveModal fill:#d1e7dd
    style RejectModal fill:#f8d7da
    style GenerateConclusion fill:#d1ecf1
    style MarkClosed fill:#d4edda
    style End fill:#e1f5ff
    style GreenStatus fill:#d1e7dd
    style YellowStatus fill:#fff3cd
    style RedStatus fill:#f8d7da
    style BellIcon fill:#ffeaa7

