Spaces:
Paused

dushyantsingh0 commited on
Commit
3750b99
·
1 Parent(s): 4d67cfa

backend stabilization

Browse files
frontend/apps/internal/src/components/TicketDetails.module.css CHANGED
@@ -50,64 +50,54 @@
50
  gap: 12px;
51
  }
52
 
53
- /* --- Main Workspace Grid --- */
54
  .workspace {
55
  display: flex;
56
  flex: 1;
57
  overflow: hidden;
58
  position: relative;
 
59
  }
60
 
61
- /* --- Left Panel (Intelligence) --- */
62
- .intelPanel {
63
- width: 260px;
64
- flex-shrink: 0;
65
- background: var(--bg-card);
66
- border-right: 1px solid var(--border-subtle);
67
- display: flex;
68
- flex-direction: column;
69
- transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
70
- overflow-y: auto;
71
- }
72
-
73
- .intelPanelCollapsed {
74
- width: 0;
75
- overflow: hidden;
76
- border-right: none;
77
- }
78
-
79
- /* --- Center Content (The Scrollable Area) --- */
80
  .mainContent {
81
  flex: 1;
82
  overflow-y: auto;
83
- padding: 24px;
84
  display: flex;
85
  flex-direction: column;
86
  gap: 32px;
87
- background: var(--bg-dark);
88
  }
89
 
90
- /* --- Right Panel (Properties) --- */
91
- .propertiesPanel {
92
- width: 300px;
93
  flex-shrink: 0;
94
  background: var(--bg-card);
95
  border-left: 1px solid var(--border-subtle);
96
- padding: 24px 20px;
97
  display: flex;
98
  flex-direction: column;
99
- gap: 24px;
100
- overflow-y: auto;
101
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
 
 
 
102
  }
103
 
104
- .propertiesPanelCollapsed {
105
  width: 0;
106
- padding: 0;
107
  overflow: hidden;
108
  border-left: none;
109
  }
110
 
 
 
 
 
 
 
 
 
111
  /* --- Specific Components Refined --- */
112
 
113
  /* 1. Intelligence Timeline (Forensic Trail) */
 
50
  gap: 12px;
51
  }
52
 
53
+ /* --- Main Workspace Grid (Unified 2-Column) --- */
54
  .workspace {
55
  display: flex;
56
  flex: 1;
57
  overflow: hidden;
58
  position: relative;
59
+ background: var(--bg-dark);
60
  }
61
 
62
+ /* --- Center Content (The Focus Area) --- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  .mainContent {
64
  flex: 1;
65
  overflow-y: auto;
66
+ padding: 32px 40px;
67
  display: flex;
68
  flex-direction: column;
69
  gap: 32px;
70
+ min-width: 600px;
71
  }
72
 
73
+ /* --- Sidebar (Intelligence & Properties) --- */
74
+ .sidebar {
75
+ width: 360px;
76
  flex-shrink: 0;
77
  background: var(--bg-card);
78
  border-left: 1px solid var(--border-subtle);
 
79
  display: flex;
80
  flex-direction: column;
 
 
81
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
82
+ overflow-y: auto;
83
+ padding: 0;
84
+ z-index: 5;
85
  }
86
 
87
+ .sidebarCollapsed {
88
  width: 0;
 
89
  overflow: hidden;
90
  border-left: none;
91
  }
92
 
93
+ .sidebarSection {
94
+ padding: 24px;
95
+ border-bottom: 1px solid var(--border-subtle);
96
+ display: flex;
97
+ flex-direction: column;
98
+ gap: 20px;
99
+ }
100
+
101
  /* --- Specific Components Refined --- */
102
 
103
  /* 1. Intelligence Timeline (Forensic Trail) */
frontend/apps/internal/src/components/TicketDetails.tsx CHANGED
@@ -1,6 +1,6 @@
1
  /* BUILD_REFRESH: 2026-04-17-0815 - Ensuring label synchronization */
2
  import React, { useState, useEffect, useRef, useCallback } from 'react';
3
- import { api, NexusMarkdown, useAuth, getFileIcon } from '@nexus/shared';
4
  import styles from './TicketDetails.module.css';
5
  import {
6
  ShieldAlert,
@@ -12,7 +12,6 @@ import {
12
  Sparkles,
13
  CheckCircle,
14
  RefreshCw,
15
- PanelLeft,
16
  PanelRight,
17
  Edit2
18
  } from 'lucide-react';
@@ -132,11 +131,9 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
132
  const [titleDraft, setTitleDraft] = useState("");
133
  const [assigneeSearch, setAssigneeSearch] = useState("");
134
  const [showAssigneeSuggestions, setShowAssigneeSuggestions] = useState(false);
135
- const [isEditingResolution, setIsEditingResolution] = useState(false);
136
  const [editingNoteId, setEditingNoteId] = useState<string | null>(null);
137
  const [noteEditDraft, setNoteEditDraft] = useState("");
138
 
139
- const [isLeftOpen, setIsLeftOpen] = useState(true);
140
  const [isRightOpen, setIsRightOpen] = useState(true);
141
  const [rightActiveTab, setRightActiveTab] = useState<'external' | 'internal'>('external');
142
 
@@ -200,7 +197,7 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
200
 
201
  // Auto-collapse logic for smaller screens
202
  if (window.innerWidth < 1366) {
203
- setIsLeftOpen(false);
204
  }
205
 
206
  document.addEventListener("mousedown", handleClickOutside);
@@ -246,20 +243,6 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
246
  }
247
  };
248
 
249
- const handleUpdateResolutionText = async () => {
250
- try {
251
- const resp = await api.patch(`tickets/${ticket.id}`, {
252
- status: 'RESOLVED',
253
- resolution_text: resolutionDraft
254
- });
255
- setTicket(resp.data);
256
- setIsEditingResolution(false);
257
- refreshData();
258
- } catch {
259
- alert("Resolution update failed.");
260
- }
261
- };
262
-
263
  const submitResolution = async () => {
264
  if (!resolutionDraft.trim()) return;
265
  try {
@@ -450,9 +433,6 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
450
  <div className={styles.container}>
451
  <header className={styles.header}>
452
  <div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
453
- <button className={styles.toggleBtn} onClick={() => setIsLeftOpen(!isLeftOpen)}>
454
- <PanelLeft size={18} color={isLeftOpen ? 'var(--primary)' : 'var(--text-dim)'} />
455
- </button>
456
  <div className={styles.breadcrumbs}>
457
  <span className={styles.breadcrumbLink} onClick={onBack} style={{ cursor: 'pointer' }}>TICKETS</span>
458
  <ChevronRight size={12} />
@@ -496,60 +476,7 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
496
  </header>
497
 
498
  <div className={styles.workspace}>
499
- {/* 2. Intelligence Sidebar (Left) */}
500
- <aside className={`${styles.intelPanel} ${!isLeftOpen ? styles.intelPanelCollapsed : ''}`}>
501
- <div style={{ padding: '24px 32px' }}>
502
- <div className={styles.sectionBlock}>
503
- <div className={styles.sectionTitle}>FORENSIC TRAIL</div>
504
- <div className={styles.timeline}>
505
- {(() => {
506
- const liveSteps = ticket.ai_metadata?.processed_steps || auditTrail || [];
507
- if (liveSteps.length === 0) return <div className={styles.empty}>Awaiting initiation...</div>;
508
-
509
- return liveSteps.map((step: { name?: string; agent_name?: string; status?: string }, i: number) => {
510
- const isError = step.status === 'error';
511
- const isLast = i === liveSteps.length - 1;
512
- const stepName = (step.name || step.agent_name || 'NEURAL_NODE').toUpperCase();
513
-
514
- return (
515
- <div key={i} className={styles.timelineItem}>
516
- {!isLast && <div className={`${styles.timelineLine} ${!isError ? styles.active : ''}`} />}
517
- <div className={`${styles.timelineDot} ${isLast && !isError ? styles.current : (!isError ? styles.verified : '')} ${isError ? styles.error : ''}`} />
518
- <div className={styles.traceInfo}>
519
- <span className={styles.traceLabel}>{stepName}</span>
520
- <span className={`${styles.traceDetail} ${!isError && !isLast ? styles.verified : ''}`}>
521
- {isError ? 'Interrupted' : 'Cycle Verified'}
522
- </span>
523
- </div>
524
- </div>
525
- );
526
- });
527
- })()}
528
- </div>
529
- </div>
530
-
531
- <div className={styles.sectionBlock} style={{ marginTop: 40 }}>
532
- <div className={styles.sectionTitle}>SEMANTIC PROXIMITY</div>
533
- <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
534
- {ticket.ai_metadata?.similar_tickets && ticket.ai_metadata.similar_tickets.length > 0 ? (
535
- ticket.ai_metadata.similar_tickets.map((sim: { id: string; title: string; similarity: number; status: string }, i: number) => (
536
- <div key={i} className={styles.propertyValue} style={{ cursor: 'pointer' }} onClick={() => window.location.href = `?ticket_id=${sim.id}`}>
537
- <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 4 }}>
538
- <span style={{ fontSize: 9, fontWeight: 900, color: 'var(--primary)', letterSpacing: '0.05em' }}>{(sim.similarity * 100).toFixed(0)}% MATCH</span>
539
- <StatusBadge status={sim.status} />
540
- </div>
541
- <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--text-main)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{sim.title}</div>
542
- </div>
543
- ))
544
- ) : (
545
- <div className={styles.empty}>No semantic overlaps.</div>
546
- )}
547
- </div>
548
- </div>
549
- </div>
550
- </aside>
551
-
552
- {/* 3. Main Operational Flow (Center) */}
553
  <main className={styles.mainContent}>
554
  {/* Status Banners */}
555
  {ticket.is_escalated && (
@@ -565,89 +492,43 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
565
  <span style={{ fontSize: 16 }}>🖇️</span>
566
  <span style={{ fontSize: 13, fontWeight: 700 }}>DUPLICATE DETECTED: LINKED TO #{ticket.duplicate_of_id.slice(0, 8)}</span>
567
  </div>
568
- <button
569
- onClick={handleReopenDuplicate}
570
- disabled={isReopening}
571
- className={styles.btnPrimary}
572
- style={{ fontSize: 10, padding: '6px 16px' }}
573
- >
574
  {isReopening ? 'REOPENING...' : 'REOPEN & RETRIAGE'}
575
  </button>
576
  </div>
577
  )}
578
 
579
- {/* AI Summary Card */}
580
- <section className={styles.aiIntelligenceCard}>
581
- <div className={styles.aiHeader}>
582
- <div className={styles.aiBadge}>
583
- <Sparkles size={16} />
584
- AI INTELLIGENCE SUMMARY
585
- </div>
586
- <button
587
- onClick={async () => {
588
- setIsSummarizing(true);
589
- try {
590
- await api.post(`tickets/${ticket.id}/summarize/`);
591
- await refreshData();
592
- } catch (err) {
593
- console.error("Summary failed:", err);
594
- } finally {
595
- setIsSummarizing(false);
596
- }
597
- }}
598
- disabled={isSummarizing}
599
- className={styles.btnSecondary}
600
- style={{ padding: '6px 12px', fontSize: 10 }}
601
- >
602
- <RefreshCw size={12} className={isSummarizing ? styles.spin : ''} />
603
- {isSummarizing ? 'Synthesizing...' : 'Regenerate'}
604
- </button>
605
- </div>
606
- <div className={styles.summaryContent}>
607
- <NexusMarkdown content={internalSummary} />
608
- </div>
609
- </section>
610
-
611
- {/* Description & Detail */}
612
  <section className={styles.sectionBlock}>
613
- <div className={styles.dossierHeader}>
614
- <div className={styles.sectionTitle}>TICKET DESCRIPTION</div>
615
- {!isEditingDescription && (
616
- <button
617
- onClick={() => { setDescriptionDraft(ticket.description); setIsEditingDescription(true); }}
618
- className={styles.btnSecondary}
619
- style={{ padding: '4px 12px', fontSize: 10 }}
620
- >Edit</button>
621
- )}
622
- </div>
623
- <div className={styles.propertyValue}>
624
- {isEditingDescription ? (
625
- <div className={styles.descriptionEditor}>
626
- <textarea
627
- className={styles.descriptionTextarea}
628
- value={descriptionDraft}
629
- onChange={(e) => setDescriptionDraft(e.target.value)}
630
- />
631
- <div className={styles.editorActions}>
632
- <button onClick={() => setIsEditingDescription(false)} className={styles.btnSecondary}>Cancel</button>
633
- <button
634
- onClick={async () => {
635
- await handleUpdateField('description', descriptionDraft);
636
- setIsEditingDescription(false);
637
- }}
638
- className={`${styles.btn} ${styles.btnPrimary}`}
639
- >Save</button>
640
- </div>
641
- </div>
642
- ) : (
643
- <NexusMarkdown content={ticket.description || ""} />
644
  )}
645
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
646
  </section>
647
 
648
  {/* Unified Messaging Thread */}
649
  <section className={styles.sectionBlock}>
650
- <div className={styles.sectionTitle}>OPERATIONAL COLLABORATION</div>
651
  <div className={styles.messageThread}>
652
  {messages.map((msg, i) => {
653
  const isMe = msg.sender_role !== 'customer';
@@ -707,18 +588,17 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
707
  style={{ flex: 1, backgroundColor: rightActiveTab === 'internal' ? '#f59e0b' : '' }}
708
  >Internal Note</button>
709
  </div>
710
-
711
  <textarea
712
  className={styles.replyTextarea}
713
  placeholder={rightActiveTab === 'external' ? "Message customer..." : "Record internal note..."}
714
  value={rightActiveTab === 'external' ? replyText : scratchpadText}
715
  onChange={(e) => rightActiveTab === 'external' ? setReplyText(e.target.value) : setScratchpadText(e.target.value)}
716
  />
717
- <div className={styles.consoleFooter}>
 
718
  <div className={styles.toolGroup}>
719
- <button className={styles.btnSecondary} onClick={() => rightActiveTab === 'external' ? replyFileInputRef.current?.click() : scratchpadFileInputRef.current?.click()}>
720
- <Paperclip size={14} />
721
- </button>
722
  <button className={styles.btnSecondary} onClick={generateAIAssistantDraft} disabled={isGenerating}>
723
  <Sparkles size={14} className={isGenerating ? styles.spin : ''} />
724
  {isGenerating ? 'NEURAL DRAFTING...' : 'AI DRAFT'}
@@ -735,47 +615,53 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
735
  </div>
736
  </section>
737
 
738
- {/* Resolution Details */}
739
  {(ticket.resolution_text || ticket.status === 'RESOLVED') && (
740
  <section className={styles.sectionBlock}>
741
  <div className={styles.sectionTitle}>RESOLUTION INTELLIGENCE</div>
742
- <div className={styles.propertyValue} style={{ border: '1px solid var(--success)', background: 'rgba(16, 185, 129, 0.05)' }}>
743
- {isEditingResolution ? (
744
- <div className={styles.descriptionEditor}>
745
- <textarea
746
- className={styles.descriptionTextarea}
747
- value={resolutionDraft}
748
- onChange={(e) => setResolutionDraft(e.target.value)}
749
- placeholder="Root cause and fix steps..."
750
- />
751
- <div className={styles.editorActions}>
752
- <button onClick={() => setIsEditingResolution(false)} className={styles.btnSecondary}>Cancel</button>
753
- <button
754
- onClick={handleUpdateResolutionText}
755
- className={`${styles.btn} ${styles.btnPrimary}`}
756
- >Update Resolution</button>
757
- </div>
758
- </div>
759
- ) : (
760
- <div style={{ position: 'relative' }}>
761
- <NexusMarkdown content={ticket.resolution_text || "No formal resolution recorded."} />
762
- {ticket.status === 'RESOLVED' && (
763
- <button
764
- onClick={() => { setResolutionDraft(ticket.resolution_text || ""); setIsEditingResolution(true); }}
765
- className={styles.btnSecondary}
766
- style={{ position: 'absolute', top: -40, right: 0, fontSize: 10 }}
767
- >Edit</button>
768
- )}
769
- </div>
770
- )}
771
  </div>
772
  </section>
773
  )}
774
  </main>
775
 
776
- {/* 4. Properties Panel (Right) */}
777
- <aside className={`${styles.propertiesPanel} ${!isRightOpen ? styles.propertiesPanelCollapsed : ''}`}>
778
- <div style={{ padding: '24px 32px' }}>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
779
  <div className={styles.propertyGroup}>
780
  <div className={styles.propertyLabel}>OPERATIONAL STATUS</div>
781
  <div style={{ display: 'flex', gap: 8 }}>
@@ -810,83 +696,102 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
810
  </div>
811
 
812
  <div className={styles.propertyGroup}>
813
- <div className={styles.propertyLabel}>ASSIGNED ANALYST</div>
814
- <div style={{ position: 'relative' }} ref={autocompleteRef}>
815
- <input
816
- type="text"
817
- className={styles.propertyValue}
818
- value={assigneeSearch}
819
- onChange={(e) => { setAssigneeSearch(e.target.value); setShowAssigneeSuggestions(true); }}
820
- onFocus={() => setShowAssigneeSuggestions(true)}
821
- placeholder="Dispatch analyst..."
822
- />
823
- {showAssigneeSuggestions && (
824
- <div className={styles.autocompleteSuggestions}>
825
- {internalUsers
826
- .filter(u => u.full_name?.toLowerCase().includes(assigneeSearch.toLowerCase()))
827
- .map(user => (
828
- <div key={user.id} className={styles.suggestionItem} onClick={() => { handleUpdateAssignee(user.id); setShowAssigneeSuggestions(false); }}>
829
- <div style={{ fontWeight: 700 }}>{user.full_name}</div>
830
- <div style={{ fontSize: 10, opacity: 0.7 }}>{user.role}</div>
831
  </div>
832
  ))}
833
- {assigneeSearch && (
834
- <div className={styles.suggestionItem} onClick={() => { handleUpdateAssignee(""); setShowAssigneeSuggestions(false); }}>
835
- <div style={{ fontWeight: 700, color: 'var(--error)' }}>Clear Assignee</div>
836
- </div>
837
- )}
838
- </div>
839
- )}
840
- </div>
841
  </div>
 
842
 
843
- <div className={styles.propertyGroup} style={{ marginTop: 32 }}>
844
- <div className={styles.sectionTitle} style={{ marginBottom: 16 }}>SLA & METRICS</div>
845
- <div className={styles.metricRow}>
846
- <div className={styles.metricItem}>
847
- <div className={styles.metricLabel}>ETA</div>
848
- <input
849
- type="text"
850
- className={styles.propertyValue}
851
- style={{ fontSize: 11, padding: '4px 8px' }}
852
- value={ticket.eta || ""}
853
- onChange={(e) => handleUpdateField('eta', e.target.value)}
854
- placeholder="e.g. 2h"
855
- />
856
- </div>
857
- <div className={styles.metricItem}>
858
- <div className={styles.metricLabel}>EFFORT</div>
859
- <input
860
- type="text"
861
- className={styles.propertyValue}
862
- style={{ fontSize: 11, padding: '4px 8px' }}
863
- value={ticket.estimated_effort || ""}
864
- onChange={(e) => handleUpdateField('estimated_effort', e.target.value)}
865
- placeholder="e.g. 1d"
866
- />
867
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
868
  </div>
869
- <div className={styles.metricRow} style={{ marginTop: 12 }}>
870
- <div className={styles.metricItem} style={{ flex: 1 }}>
871
- <div className={styles.metricLabel}>SLA STATUS</div>
872
- <div className={styles.propertyValue} style={{ fontSize: 11, color: ticket.sla_breach ? 'var(--error)' : 'var(--success)', fontWeight: 800 }}>
873
- {ticket.sla_breach ? 'BREACHED' : 'WITHIN THRESHOLD'}
874
- </div>
875
- </div>
876
  </div>
877
  </div>
878
-
879
- <div className={styles.propertyGroup} style={{ marginTop: 32 }}>
880
- <div className={styles.propertyLabel}>Evidence Hub</div>
881
- <div className={styles.evidenceGrid}>
882
- {ticketAttachments.map((att, i) => (
883
- <div key={i} className={styles.evidenceItem} onClick={() => window.open(`${api.defaults.baseURL}tickets/attachments/${att.id}/download/`, '_blank')}>
884
- <div className={styles.evidenceIcon}>{getFileIcon(att.file_type)}</div>
885
- <div className={styles.evidenceName}>{att.file_name}</div>
886
  </div>
887
- ))}
888
- {ticketAttachments.length === 0 && <div className={styles.empty} style={{ padding: 12, width: '100%' }}>No assets linked.</div>}
889
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
890
  </div>
891
  </div>
892
  </aside>
 
1
  /* BUILD_REFRESH: 2026-04-17-0815 - Ensuring label synchronization */
2
  import React, { useState, useEffect, useRef, useCallback } from 'react';
3
+ import { api, NexusMarkdown, useAuth } from '@nexus/shared';
4
  import styles from './TicketDetails.module.css';
5
  import {
6
  ShieldAlert,
 
12
  Sparkles,
13
  CheckCircle,
14
  RefreshCw,
 
15
  PanelRight,
16
  Edit2
17
  } from 'lucide-react';
 
131
  const [titleDraft, setTitleDraft] = useState("");
132
  const [assigneeSearch, setAssigneeSearch] = useState("");
133
  const [showAssigneeSuggestions, setShowAssigneeSuggestions] = useState(false);
 
134
  const [editingNoteId, setEditingNoteId] = useState<string | null>(null);
135
  const [noteEditDraft, setNoteEditDraft] = useState("");
136
 
 
137
  const [isRightOpen, setIsRightOpen] = useState(true);
138
  const [rightActiveTab, setRightActiveTab] = useState<'external' | 'internal'>('external');
139
 
 
197
 
198
  // Auto-collapse logic for smaller screens
199
  if (window.innerWidth < 1366) {
200
+ setIsRightOpen(false);
201
  }
202
 
203
  document.addEventListener("mousedown", handleClickOutside);
 
243
  }
244
  };
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  const submitResolution = async () => {
247
  if (!resolutionDraft.trim()) return;
248
  try {
 
433
  <div className={styles.container}>
434
  <header className={styles.header}>
435
  <div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
 
 
 
436
  <div className={styles.breadcrumbs}>
437
  <span className={styles.breadcrumbLink} onClick={onBack} style={{ cursor: 'pointer' }}>TICKETS</span>
438
  <ChevronRight size={12} />
 
476
  </header>
477
 
478
  <div className={styles.workspace}>
479
+ {/* Main Column (Primary Operational Flow) */}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
  <main className={styles.mainContent}>
481
  {/* Status Banners */}
482
  {ticket.is_escalated && (
 
492
  <span style={{ fontSize: 16 }}>🖇️</span>
493
  <span style={{ fontSize: 13, fontWeight: 700 }}>DUPLICATE DETECTED: LINKED TO #{ticket.duplicate_of_id.slice(0, 8)}</span>
494
  </div>
495
+ <button onClick={handleReopenDuplicate} disabled={isReopening} className={styles.btnPrimary} style={{ fontSize: 10, padding: '6px 16px' }}>
 
 
 
 
 
496
  {isReopening ? 'REOPENING...' : 'REOPEN & RETRIAGE'}
497
  </button>
498
  </div>
499
  )}
500
 
501
+ {/* Ticket Description Area */}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502
  <section className={styles.sectionBlock}>
503
+ <div className={styles.dossierHeader}>
504
+ <div className={styles.sectionTitle}>TICKET DESCRIPTION</div>
505
+ {isStaff && !isEditingDescription && (
506
+ <button onClick={() => { setDescriptionDraft(ticket.description || ""); setIsEditingDescription(true); }} className={styles.btnSecondary} style={{ padding: '4px 8px', fontSize: 10 }}>Edit</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
507
  )}
508
+ </div>
509
+
510
+ <div className={styles.propertyValue} style={{ padding: '24px', marginTop: 12 }}>
511
+ {isEditingDescription ? (
512
+ <div className={styles.descriptionEditor}>
513
+ <textarea
514
+ className={styles.descriptionTextarea}
515
+ value={descriptionDraft}
516
+ onChange={(e) => setDescriptionDraft(e.target.value)}
517
+ />
518
+ <div className={styles.editorActions}>
519
+ <button onClick={() => setIsEditingDescription(false)} className={styles.btnSecondary}>Cancel</button>
520
+ <button onClick={async () => { await handleUpdateField('description', descriptionDraft); setIsEditingDescription(false); }} className={`${styles.btn} ${styles.btnPrimary}`}>Save</button>
521
+ </div>
522
+ </div>
523
+ ) : (
524
+ <NexusMarkdown content={ticket.description || "No description provided."} />
525
+ )}
526
+ </div>
527
  </section>
528
 
529
  {/* Unified Messaging Thread */}
530
  <section className={styles.sectionBlock}>
531
+ <div className={styles.sectionTitle}>OPERATIONAL COLLABORATION</div>
532
  <div className={styles.messageThread}>
533
  {messages.map((msg, i) => {
534
  const isMe = msg.sender_role !== 'customer';
 
588
  style={{ flex: 1, backgroundColor: rightActiveTab === 'internal' ? '#f59e0b' : '' }}
589
  >Internal Note</button>
590
  </div>
591
+
592
  <textarea
593
  className={styles.replyTextarea}
594
  placeholder={rightActiveTab === 'external' ? "Message customer..." : "Record internal note..."}
595
  value={rightActiveTab === 'external' ? replyText : scratchpadText}
596
  onChange={(e) => rightActiveTab === 'external' ? setReplyText(e.target.value) : setScratchpadText(e.target.value)}
597
  />
598
+
599
+ <div className={styles.consoleFooter}>
600
  <div className={styles.toolGroup}>
601
+ <button className={styles.btnSecondary} onClick={() => rightActiveTab === 'external' ? replyFileInputRef.current?.click() : scratchpadFileInputRef.current?.click()}><Paperclip size={14} /></button>
 
 
602
  <button className={styles.btnSecondary} onClick={generateAIAssistantDraft} disabled={isGenerating}>
603
  <Sparkles size={14} className={isGenerating ? styles.spin : ''} />
604
  {isGenerating ? 'NEURAL DRAFTING...' : 'AI DRAFT'}
 
615
  </div>
616
  </section>
617
 
618
+ {/* Resolution Intelligence Documentation */}
619
  {(ticket.resolution_text || ticket.status === 'RESOLVED') && (
620
  <section className={styles.sectionBlock}>
621
  <div className={styles.sectionTitle}>RESOLUTION INTELLIGENCE</div>
622
+ <div className={styles.propertyValue} style={{
623
+ border: '1px solid var(--success)',
624
+ background: 'rgba(16, 185, 129, 0.03)',
625
+ padding: '24px',
626
+ marginTop: 12
627
+ }}>
628
+ <div style={{ position: 'relative' }}>
629
+ <NexusMarkdown content={ticket.resolution_text || "Awaiting final documentation..."} />
630
+ {ticket.status === 'RESOLVED' && isStaff && (
631
+ <button
632
+ onClick={() => { setResolutionDraft(ticket.resolution_text || ""); setShowResolutionModal(true); }}
633
+ className={styles.btnSecondary}
634
+ style={{ position: 'absolute', top: -16, right: 0, fontSize: 10, padding: '4px 8px' }}
635
+ >Edit Resolution</button>
636
+ )}
637
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
638
  </div>
639
  </section>
640
  )}
641
  </main>
642
 
643
+ {/* Context Sidebar (Intelligence & Properties) */}
644
+ <aside className={`${styles.sidebar} ${!isRightOpen ? styles.sidebarCollapsed : ''}`}>
645
+ {/* AI Intelligence Summary */}
646
+ <div className={styles.sidebarSection}>
647
+ <div className={styles.aiBadge}>
648
+ <Sparkles size={16} /> AI INTELLIGENCE SUMMARY
649
+ </div>
650
+ <div style={{ marginTop: 12 }}>
651
+ <NexusMarkdown content={internalSummary} />
652
+ </div>
653
+ <button
654
+ onClick={async () => { setIsSummarizing(true); try { await api.post(`tickets/${ticket.id}/summarize/`); await refreshData(); } finally { setIsSummarizing(false); } }}
655
+ className={styles.btnSecondary}
656
+ style={{ padding: '6px 12px', fontSize: 10, marginTop: 12 }}
657
+ disabled={isSummarizing}
658
+ >
659
+ <RefreshCw size={12} className={isSummarizing ? styles.spin : ''} /> Regenerate
660
+ </button>
661
+ </div>
662
+
663
+ {/* Operational Properties */}
664
+ <div className={styles.sidebarSection}>
665
  <div className={styles.propertyGroup}>
666
  <div className={styles.propertyLabel}>OPERATIONAL STATUS</div>
667
  <div style={{ display: 'flex', gap: 8 }}>
 
696
  </div>
697
 
698
  <div className={styles.propertyGroup}>
699
+ <div className={styles.propertyLabel}>ASSIGNED ANALYST</div>
700
+ <div style={{ position: 'relative' }} ref={autocompleteRef}>
701
+ <input
702
+ type="text"
703
+ className={styles.propertyValue}
704
+ value={assigneeSearch}
705
+ onChange={(e) => { setAssigneeSearch(e.target.value); setShowAssigneeSuggestions(true); }}
706
+ onFocus={() => setShowAssigneeSuggestions(true)}
707
+ placeholder="Dispatch analyst..."
708
+ />
709
+ {showAssigneeSuggestions && (
710
+ <div className={styles.autocompleteSuggestions}>
711
+ {internalUsers.filter(u => u.full_name?.toLowerCase().includes(assigneeSearch.toLowerCase())).map(u => (
712
+ <div key={u.id} className={styles.suggestionItem} onClick={() => { handleUpdateAssignee(u.id); setShowAssigneeSuggestions(false); }}>
713
+ <div style={{ fontWeight: 700 }}>{u.full_name}</div>
714
+ <div style={{ fontSize: 10, opacity: 0.7 }}>{u.role}</div>
 
 
715
  </div>
716
  ))}
717
+ </div>
718
+ )}
719
+ </div>
 
 
 
 
 
720
  </div>
721
+ </div>
722
 
723
+ {/* Forensic Trail */}
724
+ <div className={styles.sidebarSection}>
725
+ <div className={styles.propertyLabel}>FORENSIC TRAIL</div>
726
+ <div className={styles.timeline} style={{ marginTop: 12 }}>
727
+ {(() => {
728
+ const liveSteps = ticket.ai_metadata?.processed_steps || auditTrail || [];
729
+ if (liveSteps.length === 0) return <div className={styles.empty}>Awaiting initiation...</div>;
730
+
731
+ return liveSteps.map((step: { name?: string; agent_name?: string; status?: string }, i: number) => {
732
+ const isError = step.status === 'error';
733
+ const isLast = i === liveSteps.length - 1;
734
+ const stepName = (step.name || step.agent_name || 'NEURAL_NODE').toUpperCase();
735
+
736
+ return (
737
+ <div key={i} className={styles.timelineItem} style={{ gap: 12 }}>
738
+ {!isLast && <div className={styles.timelineLine} style={{ left: 5, top: 16, bottom: -12 }} />}
739
+ <div className={`${styles.timelineDot} ${isLast && !isError ? styles.current : (!isError ? styles.verified : '')} ${isError ? styles.error : ''}`} style={{ width: 12, height: 12, border: '3px solid var(--border-hi)' }} />
740
+ <div className={styles.traceInfo}>
741
+ <span className={styles.traceLabel} style={{ fontSize: 10 }}>{stepName}</span>
742
+ <span className={`${styles.traceDetail} ${!isError && !isLast ? styles.verified : ''}`} style={{ fontSize: 8 }}>
743
+ {isError ? 'Interrupted' : 'Cycle Verified'}
744
+ </span>
745
+ </div>
746
+ </div>
747
+ );
748
+ });
749
+ })()}
750
+ </div>
751
+ </div>
752
+
753
+ {/* Metrics & Evidence */}
754
+ <div className={styles.sidebarSection}>
755
+ <div className={styles.propertyLabel}>SLA & METRICS</div>
756
+ <div className={styles.metricRow}>
757
+ <div className={styles.metricItem}>
758
+ <div className={styles.metricLabel}>ETA</div>
759
+ <input type="text" className={styles.propertyValue} style={{ fontSize: 11, padding: '4px 8px' }} value={ticket.eta || ""} onChange={(e) => handleUpdateField('eta', e.target.value)} placeholder="e.g. 2h" />
760
  </div>
761
+ <div className={styles.metricItem}>
762
+ <div className={styles.metricLabel}>EFFORT</div>
763
+ <input type="text" className={styles.propertyValue} style={{ fontSize: 11, padding: '4px 8px' }} value={ticket.estimated_effort || ""} onChange={(e) => handleUpdateField('estimated_effort', e.target.value)} placeholder="e.g. 1d" />
 
 
 
 
764
  </div>
765
  </div>
766
+ <div className={styles.propertyLabel} style={{ marginTop: 24 }}>EVIDENCE HUB</div>
767
+ <div className={styles.evidenceGrid}>
768
+ {ticketAttachments.map(att => (
769
+ <div key={att.id} className={styles.evidenceItem} onClick={() => window.open(`${api.defaults.baseURL}tickets/attachments/${att.id}/download/`, '_blank')}>
770
+ <Paperclip size={14} className={styles.evidenceIcon} />
771
+ <span className={styles.evidenceName}>{att.file_name}</span>
 
 
772
  </div>
773
+ ))}
774
+ {ticketAttachments.length === 0 && <div className={styles.empty}>No assets linked.</div>}
775
+ </div>
776
+ </div>
777
+
778
+ {/* Semantic Proximity */}
779
+ <div className={styles.sidebarSection} style={{ borderBottom: 'none' }}>
780
+ <div className={styles.propertyLabel}>SEMANTIC PROXIMITY</div>
781
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginTop: 12 }}>
782
+ {ticket.ai_metadata?.similar_tickets && ticket.ai_metadata.similar_tickets.length > 0 ? (
783
+ ticket.ai_metadata.similar_tickets.map((sim: { id: string; title: string; similarity: number; status: string }, i: number) => (
784
+ <div key={i} className={styles.propertyValue} style={{ cursor: 'pointer', padding: '8px 12px' }} onClick={() => window.location.href = `?ticket_id=${sim.id}`}>
785
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 4 }}>
786
+ <span style={{ fontSize: 8, fontWeight: 900, color: 'var(--primary)', letterSpacing: '0.05em' }}>{(sim.similarity * 100).toFixed(0)}% MATCH</span>
787
+ <StatusBadge status={sim.status} />
788
+ </div>
789
+ <div style={{ fontSize: 11, fontWeight: 700, color: 'var(--text-main)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{sim.title}</div>
790
+ </div>
791
+ ))
792
+ ) : (
793
+ <div className={styles.empty}>No semantic overlaps.</div>
794
+ )}
795
  </div>
796
  </div>
797
  </aside>