File size: 22,554 Bytes
b5a1b3b
84fe53c
 
c33dd31
 
e7e25da
c33dd31
 
8624ca2
e7e25da
c33dd31
 
e7e25da
c33dd31
e7e25da
c33dd31
 
e7e25da
 
5b64eb6
e7e25da
8624ca2
 
 
8d2ffe3
 
 
84fe53c
 
 
03ed280
 
 
c33dd31
36d7087
4d393e8
 
 
 
 
 
 
 
 
e7e25da
 
8624ca2
0a16b93
 
03ed280
e59840b
a04377a
36d7087
 
4d393e8
84fe53c
e7e25da
5b64eb6
 
 
 
 
 
 
 
 
 
 
 
e7e25da
4d393e8
e7e25da
4d393e8
b5a1b3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d393e8
 
e3f3c8e
 
 
 
 
 
 
 
 
 
4d393e8
e7e25da
4d393e8
 
8d2ffe3
 
0a16b93
 
 
 
 
 
 
 
 
 
b5a1b3b
e7e25da
0a16b93
 
84fe53c
 
 
 
 
8d2ffe3
c33dd31
 
4d393e8
84fe53c
e7e25da
84fe53c
e7e25da
84fe53c
 
 
 
 
 
e7e25da
8d2ffe3
e7e25da
84fe53c
8624ca2
e7e25da
c33dd31
4d393e8
e7e25da
84fe53c
e7e25da
 
 
8624ca2
e7e25da
4d393e8
84fe53c
4d393e8
e7e25da
4d393e8
84fe53c
 
 
 
8d2ffe3
 
 
 
 
 
 
 
84fe53c
8d2ffe3
e7e25da
b5a1b3b
e7e25da
b5a1b3b
 
 
 
84fe53c
e7e25da
8d2ffe3
 
 
e7e25da
 
 
 
 
8d2ffe3
84fe53c
 
e7e25da
8d2ffe3
84fe53c
8d2ffe3
84fe53c
8d2ffe3
84fe53c
8d2ffe3
 
84fe53c
8d2ffe3
 
 
 
84fe53c
8d2ffe3
 
84fe53c
 
 
 
8d2ffe3
 
 
 
b5a1b3b
84fe53c
8d2ffe3
 
 
 
62256b3
 
 
 
e7e25da
 
8624ca2
62256b3
a46398e
 
 
4d393e8
 
 
e59840b
84fe53c
e59840b
 
 
 
 
 
 
 
 
 
 
 
 
 
8d2ffe3
 
84fe53c
8d2ffe3
 
e7e25da
 
36d7087
 
 
 
 
 
e59840b
84fe53c
 
 
 
 
 
 
 
 
 
 
 
 
 
8d2ffe3
e7e25da
b5a1b3b
a46398e
b5a1b3b
 
 
 
e7e25da
a46398e
e7e25da
 
 
 
 
 
 
a46398e
e7e25da
 
8d2ffe3
e7e25da
 
 
 
84fe53c
 
 
8d2ffe3
 
 
 
84fe53c
a04377a
 
 
 
 
 
e7e25da
 
84fe53c
a04377a
 
 
84fe53c
 
 
 
 
 
 
 
e7e25da
 
 
84fe53c
e7e25da
84fe53c
e7e25da
84fe53c
 
 
 
 
e7e25da
84fe53c
 
 
 
 
 
 
 
 
 
 
 
e7e25da
 
a46398e
e7e25da
84fe53c
 
 
e7e25da
84fe53c
 
e7e25da
 
 
a46398e
e7e25da
8d2ffe3
e7e25da
8d2ffe3
 
 
 
 
84fe53c
 
 
8d2ffe3
 
 
 
84fe53c
8d2ffe3
 
 
 
 
 
 
 
03ed280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d2ffe3
 
a46398e
03ed280
8d2ffe3
03ed280
 
 
 
 
 
 
 
 
 
 
8d2ffe3
 
 
 
 
a46398e
8d2ffe3
 
 
84fe53c
8d2ffe3
a46398e
84fe53c
 
 
 
 
 
 
8d2ffe3
a46398e
 
8d2ffe3
84fe53c
8d2ffe3
84fe53c
8d2ffe3
 
 
 
84fe53c
8d2ffe3
84fe53c
 
8d2ffe3
e7e25da
8d2ffe3
 
e7e25da
 
8d2ffe3
 
 
 
 
 
 
 
 
 
 
 
 
84fe53c
8d2ffe3
 
 
 
 
e7e25da
 
4d393e8
 
 
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
import React, { useState, useRef, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { useTheme } from '../context/ThemeContext.jsx';
import {
  FileDiff,
  GitPullRequest,
  Network,
  ShieldCheck,
  Files,
  Database,
  History,
  Key,
  Search,
  User,
  LogOut,
  ExternalLink,
  ChevronDown,
  Layers,
  CheckCircle2,
  Copy,
  Lock,
  Cpu,
  Plus,
  RefreshCw,
  Sparkles,
  Terminal,
  Grid,
  ArrowLeft,
  Sun,
  Moon,
  Settings,
  Users,
  Globe
} from 'lucide-react';
import NotificationsCenter from './NotificationsCenter';

export default function Navbar({
  workspaces,
  currentWorkspace,
  onSelectWorkspace,
  onCreateWorkspace,
  activeTab,
  onSelectTab,
  stats,
  currentUser,
  onLogout,
  onRefresh,
  refreshing,
  proposals = [],
  diff = null,
  onOpenAccessModal,
  onOpenGlobalSearch,
  onOpenUserProfile,
  showToast = () => {}
}) {
  const { theme, toggleTheme } = useTheme();
  const [showWsDropdown, setShowWsDropdown] = useState(false);
  const [copiedApiKey, setCopiedApiKey] = useState(false);

  const handleCopyApiKey = () => {
    const tok = localStorage.getItem("diffweave_token") || localStorage.getItem("token") || "";
    if (tok) {
      navigator.clipboard.writeText(tok);
      setCopiedApiKey(true);
      setTimeout(() => setCopiedApiKey(false), 2000);
    } else {
      alert("No active API token found. Please sign in.");
    }
  };
  const [showCreateModal, setShowCreateModal] = useState(false);
  const [newWsName, setNewWsName] = useState('');
  const [showUserDropdown, setShowUserDropdown] = useState(false);

  const wsDropdownRef = useRef(null);
  const userDropdownRef = useRef(null);

  // Close dropdowns when clicking anywhere outside
  useEffect(() => {
    function handleClickOutside(event) {
      if (wsDropdownRef.current && !wsDropdownRef.current.contains(event.target)) {
        setShowWsDropdown(false);
      }
      if (userDropdownRef.current && !userDropdownRef.current.contains(event.target)) {
        setShowUserDropdown(false);
      }
    }

    document.addEventListener('mousedown', handleClickOutside);
    document.addEventListener('touchstart', handleClickOutside);
    return () => {
      document.removeEventListener('mousedown', handleClickOutside);
      document.removeEventListener('touchstart', handleClickOutside);
    };
  }, []);

  const handleCreate = async (e) => {
    e.preventDefault();
    const cleanName = newWsName.trim();
    if (!cleanName) return;
    const isDuplicate = (workspaces || []).some(
      (w) => w.name && w.name.trim().toLowerCase() === cleanName.toLowerCase()
    );
    if (isDuplicate) {
      alert(`A workspace named "${cleanName}" already exists. Workspace names must be unique.`);
      return;
    }
    await onCreateWorkspace(cleanName);
    setNewWsName('');
    setShowCreateModal(false);
  };

  const totalDocs = stats?.total_documents ?? currentWorkspace?.d_count ?? 0;
  const verifiedFacts = stats?.knowledge_items ?? stats?.total_knowledge_items ?? currentWorkspace?.k_count ?? 0;

  // Reactively compute pending PR count from live proposals prop
  const pendingProposalsCount = (proposals && proposals.length > 0)
    ? proposals.filter((p) => !p.status || p.status.toUpperCase() === 'PENDING').length
    : (stats?.pending_proposals ?? 0);

  // Reactively compute pending diff deltas from live diff prop
  const pendingDiffDeltasCount = diff
    ? ((diff.additions?.length || 0) + (diff.changes?.length || 0) + (diff.conflicts?.length || 0) + (diff.removals?.length || 0))
    : pendingProposalsCount;

  const tabs = [
    { id: 'diff', label: 'Semantic Diff', icon: FileDiff, badge: pendingDiffDeltasCount > 0 ? `${pendingDiffDeltasCount}` : null },
    { id: 'prs', label: 'PR Review Deck', icon: GitPullRequest, badge: pendingProposalsCount > 0 ? `${pendingProposalsCount} pending` : null },
    { id: 'graph', label: 'Knowledge Graph', icon: Network },
    { id: 'staging', label: 'Ingestion Staging', icon: Files, badge: totalDocs > 0 ? `${totalDocs} docs` : null },
    { id: 'rules', label: 'Policy Rules CI', icon: ShieldCheck },
    { id: 'knowledge', label: 'Truth Register', icon: Database, badge: verifiedFacts > 0 ? `${verifiedFacts} facts` : null },
    { id: 'audit', label: 'Audit & Provenance', icon: History },
    { id: 'quickstart', label: 'CLI Quickstart', icon: Terminal },
  ];

  return (
    <header className="sticky top-0 z-40 bg-[#010409] border-b border-[#30363D] shadow-md select-none">
      {/* --------------------------------------------------------------------- */}
      {/* TIER 1: Global Platform Bar (#010409)                                  */}
      {/* --------------------------------------------------------------------- */}
      <div className="px-4 sm:px-6 py-2.5 flex items-center justify-between border-b border-[#21262D]">
        {/* Left: Brand Logo & Workspace Switcher */}
        <div className="flex items-center space-x-4">
          <Link
            to="/"
            onClick={() => onSelectWorkspace && onSelectWorkspace(null)}
            className="flex items-center space-x-2.5 cursor-pointer group"
            title="Return to Workspaces Hub"
          >
            <div className="w-8 h-8 rounded-lg bg-gradient-to-tr from-emerald-500 via-teal-500 to-sky-500 p-[1px] shadow-sm group-hover:scale-105 transition">
              <div className="w-full h-full bg-[#010409] rounded-[6px] flex items-center justify-center">
                <Layers className="w-4 h-4 text-emerald-400" />
              </div>
            </div>
            <div className="flex flex-col">
              <span className="font-extrabold text-sm text-white tracking-tight group-hover:text-emerald-300 transition">
                DiffWeave
              </span>
              <span className="text-[10px] text-slate-400 font-mono -mt-1">
                Document Git Platform
              </span>
            </div>
          </Link>

          <span className="text-slate-600 hidden sm:inline">/</span>

          {/* Hub Link Button */}
          <Link
            to="/"
            onClick={() => onSelectWorkspace && onSelectWorkspace(null)}
            className={`hidden sm:flex items-center space-x-1.5 px-2.5 py-1 rounded-md border text-xs font-semibold transition ${
              !currentWorkspace
                ? 'bg-emerald-500/10 border-emerald-500/30 text-emerald-400'
                : 'bg-[#161B22] hover:bg-[#21262D] border-[#30363D] text-slate-300 hover:text-white'
            }`}
          >
            <Grid className="w-3.5 h-3.5" />
            <span>Workspaces</span>
          </Link>

          {/* Workspace Dropdown */}
          <div ref={wsDropdownRef} className="relative">
            <button
              onClick={() => {
                setShowWsDropdown((prev) => !prev);
                setShowUserDropdown(false);
              }}
              className="flex items-center space-x-1.5 px-2.5 py-1 rounded-md bg-[#161B22] hover:bg-[#21262D] border border-[#30363D] text-slate-200 transition"
            >
              <span className={`w-2 h-2 rounded-full ${currentWorkspace ? 'bg-emerald-400 animate-pulse' : 'bg-slate-500'}`} />
              <span className="truncate max-w-[150px] text-xs font-semibold">
                {currentWorkspace ? currentWorkspace.name : 'Select Workspace'}
              </span>
              <ChevronDown className="w-3 h-3 text-slate-400" />
            </button>

            {showWsDropdown && (
              <div className="absolute left-0 mt-1.5 w-64 bg-[#161B22] border border-[#30363D] rounded-xl shadow-2xl p-2 z-50 space-y-1">
                <div className="px-2 py-1 text-[11px] font-semibold text-slate-400 border-b border-[#30363D]">
                  Document Workspaces ({workspaces.length})
                </div>

                <div className="max-h-56 overflow-y-auto space-y-0.5 py-1">
                  {workspaces.map((w) => (
                    <Link
                      key={w.id}
                      to={`/workspaces/${w.id}/diff`}
                      onClick={() => {
                        setShowWsDropdown(false);
                        onSelectWorkspace && onSelectWorkspace(w);
                      }}
                      className={`w-full text-left px-2.5 py-1.5 rounded text-xs transition flex items-center justify-between ${
                        currentWorkspace?.id === w.id
                          ? 'bg-emerald-500/20 text-emerald-300 font-bold'
                          : 'text-slate-300 hover:bg-[#21262D] hover:text-white'
                      }`}
                    >
                      <div className="truncate pr-2">
                        <p className="truncate">{w.name}</p>
                        <span className="text-[10px] text-slate-500 font-mono">
                          {w.d_count ?? 0} docs &bull; {w.k_count ?? 0} facts
                        </span>
                      </div>
                      {currentWorkspace?.id === w.id && (
                        <CheckCircle2 className="w-3.5 h-3.5 text-emerald-400 shrink-0" />
                      )}
                    </Link>
                  ))}
                </div>

                <div className="pt-1.5 border-t border-[#30363D]">
                  <Link
                    to="/new"
                    onClick={() => setShowWsDropdown(false)}
                    className="w-full text-left px-2 py-1.5 rounded text-xs text-emerald-400 hover:bg-[#21262D] font-semibold flex items-center space-x-1.5 no-underline"
                  >
                    <Plus className="w-3.5 h-3.5" />
                    <span>New Document Workspace...</span>
                  </Link>
                </div>
              </div>
            )}
          </div>
        </div>

        {/* Right: Search, FastMCP Bridge status, Theme Quick Toggle & User Profile */}
        <div className="flex items-center space-x-2.5">
          {/* Global Search Trigger (Ctrl+K) */}
          <button
            type="button"
            onClick={onOpenGlobalSearch}
            className="flex items-center space-x-2 px-3 py-1.5 rounded-xl bg-[#161B22] hover:bg-[#21262D] border border-[#30363D] hover:border-slate-600 text-xs text-slate-400 hover:text-slate-200 transition font-mono"
            title="Global Search across workspaces & users (Ctrl+K)"
          >
            <Search className="w-3.5 h-3.5 text-emerald-400 shrink-0" />
            <span className="hidden sm:inline">Search...</span>
            <kbd className="hidden sm:inline px-1.5 py-0.2 rounded bg-black/40 border border-[#30363D] text-[10px] text-slate-500 font-mono">
              Ctrl+K
            </kbd>
          </button>

          {/* FastMCP Connected Pill */}
          <div className="hidden md:flex items-center space-x-1.5 px-2.5 py-1 rounded-full bg-[#161B22] border border-[#30363D] text-[11px] text-slate-400 font-mono">
            <span className="w-2 h-2 rounded-full bg-emerald-400" />
            <Cpu className="w-3 h-3 text-emerald-400" />
            <span>FastMCP: Active</span>
          </div>

          {/* Dynamic Real-Time Notifications Center (YouTube style) */}
          <NotificationsCenter
            onSelectWorkspace={onSelectWorkspace}
            onOpenProfile={onOpenUserProfile}
            showToast={showToast}
          />

          {/* Quick Light/Dark Mode Toggle */}
          <button
            onClick={toggleTheme}
            className="p-1.5 rounded-lg bg-[#161B22] hover:bg-[#21262D] border border-[#30363D] text-slate-300 hover:text-white transition flex items-center justify-center"
            title={`Switch to ${theme === 'dark' ? 'Light' : 'Dark'} Mode`}
            aria-label="Toggle interface theme"
          >
            {theme === 'dark' ? (
              <Sun className="w-4 h-4 text-amber-400" />
            ) : (
              <Moon className="w-4 h-4 text-indigo-400" />
            )}
          </button>

          {/* User Menu */}
          {currentUser ? (
            <div ref={userDropdownRef} className="relative">
              <button
                onClick={() => {
                  setShowUserDropdown((prev) => !prev);
                  setShowWsDropdown(false);
                }}
                className="flex items-center space-x-1.5 px-2.5 py-1 rounded-full bg-[#161B22] hover:bg-[#21262D] border border-[#30363D] text-slate-200 transition"
              >
                <div className="w-4 h-4 rounded-full bg-emerald-500 text-black font-bold flex items-center justify-center text-[9px]">
                  {currentUser.username ? currentUser.username[0].toUpperCase() : 'U'}
                </div>
                <span className="font-semibold text-xs truncate max-w-[100px]">
                  {currentUser.username || 'Evaluator'}
                </span>
                <ChevronDown className="w-3 h-3 text-slate-400" />
              </button>

              {showUserDropdown && (
                <div className="absolute right-0 mt-1.5 w-56 bg-[#161B22] border border-[#30363D] rounded-xl shadow-2xl p-2 z-50 space-y-1 text-xs">
                  <div className="px-2 py-1.5 border-b border-[#30363D]">
                    <p className="font-bold text-white">{currentUser.username || 'User'}</p>
                    <p className="text-[11px] text-slate-400 font-mono truncate">{currentUser.email || 'user@docweave.io'}</p>
                  </div>
                  <Link
                    to="/"
                    onClick={() => setShowUserDropdown(false)}
                    className="w-full text-left px-2 py-1.5 rounded text-slate-300 hover:bg-[#21262D] flex items-center space-x-2"
                  >
                    <Grid className="w-3.5 h-3.5 text-sky-400" />
                    <span>Workspaces Hub</span>
                  </Link>
                  <button
                    type="button"
                    onClick={() => {
                      setShowUserDropdown(false);
                      if (onOpenUserProfile) onOpenUserProfile(currentUser?.id || currentUser?.username);
                    }}
                    className="w-full text-left px-2 py-1.5 rounded text-slate-300 hover:bg-[#21262D] flex items-center space-x-2"
                  >
                    <User className="w-3.5 h-3.5 text-emerald-400" />
                    <span>Public Profile & Activity</span>
                  </button>

                  <Link
                    to="/settings"
                    onClick={() => setShowUserDropdown(false)}
                    className="w-full text-left px-2 py-1.5 rounded text-slate-300 hover:bg-[#21262D] flex items-center space-x-2"
                  >
                    <Settings className="w-3.5 h-3.5 text-sky-400" />
                    <span>Platform Settings</span>
                  </Link>
                  <button
                    onClick={() => {
                      setShowUserDropdown(false);
                      handleCopyApiKey();
                    }}
                    className="w-full text-left px-2 py-1.5 rounded text-slate-300 hover:bg-[#21262D] flex items-center justify-between"
                  >
                    <div className="flex items-center space-x-2">
                      <Key className="w-3.5 h-3.5 text-amber-400" />
                      <span>{copiedApiKey ? 'Copied Token!' : 'Copy API Key'}</span>
                    </div>
                    {copiedApiKey && <span className="text-[10px] text-emerald-400 font-bold">&check;</span>}
                  </button>
                  <div className="pt-1 border-t border-[#30363D]">
                    <button
                      onClick={() => {
                        setShowUserDropdown(false);
                        onLogout();
                      }}
                      className="w-full text-left px-2 py-1.5 rounded text-rose-400 hover:bg-rose-950/30 flex items-center space-x-2"
                    >
                      <LogOut className="w-3.5 h-3.5" />
                      <span>Sign Out</span>
                    </button>
                  </div>
                </div>
              )}
            </div>
          ) : (
            <Link
              to="/login"
              className="px-3 py-1 text-xs font-semibold text-white bg-emerald-600 hover:bg-emerald-500 rounded-md transition"
            >
              Sign In
            </Link>
          )}
        </div>
      </div>

      {/* --------------------------------------------------------------------- */}
      {/* TIER 2: Workspace Document Context Header (#0D1117) - If Workspace Active */}
      {/* --------------------------------------------------------------------- */}
      {currentWorkspace && (
        <>
          <div className="px-4 sm:px-6 py-3.5 flex flex-col sm:flex-row sm:items-center justify-between gap-3">
            {/* Workspace Title & Badge */}
            <div className="flex items-center space-x-2.5">
              <Link
                to="/"
                onClick={() => onSelectWorkspace && onSelectWorkspace(null)}
                className="p-1 rounded-md hover:bg-[#161B22] text-slate-400 hover:text-white transition"
                title="Back to All Workspaces"
              >
                <ArrowLeft className="w-4 h-4" />
              </Link>
              <Files className="w-5 h-5 text-emerald-400" />
              <div className="flex items-center space-x-2">
                <span className="text-white font-bold text-base sm:text-lg">
                  {currentWorkspace?.name}
                </span>
                <span className="px-2 py-0.5 rounded-full text-[10px] font-semibold bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 font-mono">
                  Deterministic RAG
                </span>
                {/* Visibility Badge (Clickable to open Share/Access Modal) */}
                <button
                  type="button"
                  onClick={onOpenAccessModal}
                  className={`px-2 py-0.5 rounded-full text-[10px] font-semibold flex items-center space-x-1 border transition ${
                    currentWorkspace?.visibility === 'public'
                      ? 'bg-sky-500/10 text-sky-400 border-sky-500/30 hover:bg-sky-500/20'
                      : 'bg-amber-500/10 text-amber-300 border-amber-500/30 hover:bg-amber-500/20'
                  }`}
                  title="Click to manage workspace access & visibility"
                >
                  {currentWorkspace?.visibility === 'public' ? (
                    <Globe className="w-3 h-3 text-sky-400" />
                  ) : (
                    <Lock className="w-3 h-3 text-amber-400" />
                  )}
                  <span className="capitalize">{currentWorkspace?.visibility || 'Private'}</span>
                </button>
              </div>
            </div>

            {/* Real Document Platform KPI Badges & Access Controls */}
            <div className="flex items-center space-x-2 text-xs font-semibold">
              {/* Share / Access Management Button */}
              <button
                type="button"
                onClick={onOpenAccessModal}
                className="flex items-center space-x-1.5 px-2.5 py-1 rounded-md bg-[#161B22] hover:bg-[#21262D] border border-slate-700 text-slate-200 hover:text-white transition shadow-sm"
                title="Manage workspace access, members & API tokens"
              >
                <Users className="w-3.5 h-3.5 text-emerald-400" />
                <span>Share</span>
              </button>

              <div className="flex items-center space-x-1.5 px-2.5 py-1 rounded-md bg-[#161B22] border border-[#30363D] text-slate-300">
                <Files className="w-3.5 h-3.5 text-sky-400" />
                <span>Tracked Docs:</span>
                <span className="text-white font-bold font-mono">{totalDocs}</span>
              </div>

              <div className="flex items-center space-x-1.5 px-2.5 py-1 rounded-md bg-[#161B22] border border-[#30363D] text-slate-300">
                <Database className="w-3.5 h-3.5 text-emerald-400" />
                <span>Verified Truth:</span>
                <span className="text-white font-bold font-mono">{verifiedFacts}</span>
              </div>

              <button
                onClick={onRefresh}
                className="p-1.5 rounded-md bg-[#161B22] hover:bg-[#21262D] border border-[#30363D] text-slate-400 hover:text-white transition"
                title="Refresh Workspace Data"
              >
                <RefreshCw className={`w-3.5 h-3.5 ${refreshing ? 'animate-spin text-emerald-400' : ''}`} />
              </button>
            </div>
          </div>

          {/* ----------------------------------------------------------------- */}
          {/* TIER 3: Workspace Navigation Tabs (GitHub-style deep Link tabs)   */}
          {/* ----------------------------------------------------------------- */}
          <nav className="flex px-4 sm:px-6 space-x-1 overflow-x-auto border-t border-[#21262D] text-xs font-medium no-scrollbar">
            {tabs.map((tab) => {
              const Icon = tab.icon;
              const isActive = activeTab === tab.id;
              return (
                <Link
                  key={tab.id}
                  to={`/workspaces/${currentWorkspace.id}/${tab.id}`}
                  onClick={() => onSelectTab && onSelectTab(tab.id)}
                  className={`flex items-center space-x-2 px-3.5 py-2.5 border-b-2 transition whitespace-nowrap ${
                    isActive
                      ? 'border-emerald-500 text-white font-bold'
                      : 'border-transparent text-slate-400 hover:text-slate-200 hover:border-slate-600'
                  }`}
                >
                  <Icon className={`w-4 h-4 ${isActive ? 'text-emerald-400' : 'text-slate-500'}`} />
                  <span>{tab.label}</span>
                  {tab.badge && (
                    <span
                      className={`px-1.5 py-0.2 rounded-full text-[10px] font-mono ${
                        isActive
                          ? 'bg-emerald-500/20 text-emerald-300 font-bold'
                          : 'bg-[#21262D] text-slate-400'
                      }`}
                    >
                      {tab.badge}
                    </span>
                  )}
                </Link>
              );
            })}
          </nav>
        </>
      )}


    </header>
  );
}