All files / src/components Navigation.tsx

87.87% Statements 58/66
71.15% Branches 37/52
78.26% Functions 18/23
89.47% Lines 51/57

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 7424x                                                                                                                                                                           4x                                                                                                         4x                                                                                                           4x                                                                                                                                 4x                                                                                                                                                                                 4x                                                                                                     4x                                                                                                                 4x                                         4x                                 3129x 1749x   2769x                 567x   323x 293x 2562x   293x 293x                 81x 567x 567x                       104x 104x 104x 104x   830x   104x   23x 17x     92x 92x     104x     6x                                             106x                                                       26x     26x 26x 26x         26x       26x           26x           26x       26x 26x       26x         26x     26x 26x 26x     26x                                       92x                                                                                                                                      
"use client";
 
import Link from "next/link";
import { usePathname } from "next/navigation";
import {
  Network,
  BookOpen,
  ShieldCheck,
  Smartphone,
  User,
  BarChart2,
  Search,
  UserPlus,
  FileKey2,
  Upload,
  Database,
  FileSignature,
  ArrowRightLeft,
  LayoutDashboard,
  ChevronDown,
  Heart,
  Activity,
  FileText,
  Gavel,
  Info,
  Code2,
  Layers,
  ScrollText,
  FileBarChart,
  ClipboardList,
  Edit3,
  Lightbulb,
  FlaskConical,
  Gift,
  Sparkles,
  Menu,
  X,
  Globe,
  Languages,
  Scale,
  ChartGantt,
  Fingerprint,
} from "lucide-react";
import UserMenu from "./UserMenu";
import ThemeToggle from "./ThemeToggle";
import LanguagePicker from "./LanguagePicker";
import SiteSearch from "./SiteSearch";
import { useT } from "@/lib/i18n/translate";
import { useState, useRef, useEffect } from "react";
import { deriveParticipantType, derivePersonaId } from "@/lib/auth";
import { useDemoPersona } from "@/lib/use-demo-persona";
import { useTabSession } from "@/lib/use-tab-session";
import type { LucideProps } from "lucide-react";
import { IS_STATIC } from "@/lib/static-export";
 
// ── Types ──────────────────────────────────────────────────────────────────────
 
type LucideIcon = React.ForwardRefExoticComponent<
  Omit<LucideProps, "ref"> & React.RefAttributes<SVGSVGElement>
>;
 
/**
 * Which roles can see this nav item.
 * undefined / empty → public (always visible).
 * "AUTH"           → any authenticated user.
 * string[]         → one of these role codes must be present.
 */
interface NavLink {
  href: string;
  label: string;
  icon: LucideIcon;
  roles?: string[] | "AUTH";
}
 
interface NavGroup {
  label: string;
  icon: LucideIcon;
  /** If set, group is hidden unless user has at least one of these roles. */
  roles?: string[] | "AUTH";
  /** If set, group is hidden when user has any of these roles (persona-specific menus replace it). */
  hideForRoles?: string[];
  links: NavLink[];
}
 
// ── Cluster 2: Explore ────────────────────────────────────────────────────────
// Public + authenticated mix — shown to everyone but some items filtered
const exploreGroup: NavGroup = {
  label: "Explore",
  icon: Network,
  // DATA_USER sees "My Researches" instead; PATIENT sees "My Health" instead
  hideForRoles: ["DATA_USER", "PATIENT"],
  links: [
    { href: "/overview", label: "Persona Overview", icon: Layers },
    { href: "/catalog", label: "Dataset Catalog", icon: BookOpen },
    {
      href: "/catalog/editor",
      label: "DCAT-AP Editor",
      icon: Edit3,
      roles: ["EDC_ADMIN", "DATA_HOLDER", "EDC_USER_PARTICIPANT"],
    },
    // Art. 72: a trusted holder answers statistical requests on its datasets.
    {
      href: "/requests",
      label: "Statistical Requests",
      icon: BarChart2,
      roles: ["DATA_HOLDER"],
    },
    {
      href: "/supervision",
      label: "Supervision",
      icon: Gavel,
      roles: ["DATA_HOLDER"],
    },
    { href: "/patient", label: "Patient Journey", icon: User },
    {
      href: "/analytics",
      label: "OMOP Analytics",
      icon: BarChart2,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY", "EDC_USER_PARTICIPANT"],
    },
    {
      href: "/query",
      label: "NLQ / Federated",
      icon: Search,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
    },
    { href: "/eehrxf", label: "EEHRxF Profiles", icon: Heart },
    // Art. 57(1)(j) and 58(1)(f): the access body's decisions are public.
    { href: "/permits", label: "Permits Register", icon: ScrollText },
    // Art. 59: the access body's activity report is public too.
    { href: "/activity-report", label: "Activity Report", icon: FileBarChart },
    // Art. 58(1): what the public is told about secondary use.
    { href: "/information", label: "Secondary Use Info", icon: Info },
    // #782: how each member state implements secondary use.
    { href: "/jurisdictions", label: "National EHDS Rules", icon: Scale },
  ],
};
 
// ── Cluster 3: Governance ─────────────────────────────────────────────────────
const governanceGroup: NavGroup = {
  label: "Governance",
  icon: ShieldCheck,
  roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
  links: [
    {
      href: "/compliance",
      label: "EHDS Approval",
      icon: ShieldCheck,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
    },
    {
      href: "/requests",
      label: "Statistical Requests",
      icon: BarChart2,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
    },
    // Art. 63: findings, views, measures and requests for information.
    {
      href: "/supervision",
      label: "Supervision",
      icon: Gavel,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
    },
    {
      href: "/activity-report",
      label: "Activity Report",
      icon: FileBarChart,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
    },
    {
      href: "/compliance/tck",
      label: "Protocol TCK",
      icon: ShieldCheck,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
    },
    {
      href: "/credentials",
      label: "Credentials",
      icon: FileKey2,
      roles: [
        "EDC_ADMIN",
        "DATA_HOLDER",
        "DATA_USER",
        "HDAB_AUTHORITY",
        "TRUST_CENTER_OPERATOR",
        "EDC_USER_PARTICIPANT",
      ],
    },
  ],
};
 
// ── Cluster 4: Exchange ───────────────────────────────────────────────────────
// Patients are citizens, not active dataspace participants — no data exchange
const exchangeGroup: NavGroup = {
  label: "Exchange",
  icon: ArrowRightLeft,
  roles: [
    "EDC_ADMIN",
    "DATA_HOLDER",
    "HDAB_AUTHORITY",
    "TRUST_CENTER_OPERATOR",
    "EDC_USER_PARTICIPANT",
  ],
  links: [
    {
      href: "/data/share",
      label: "Share Data",
      icon: Upload,
      roles: ["EDC_ADMIN", "DATA_HOLDER", "EDC_USER_PARTICIPANT"],
    },
    {
      href: "/data/discover",
      label: "Discover",
      icon: Database,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
    },
    {
      href: "/negotiate",
      label: "Negotiate",
      icon: FileSignature,
      roles: [
        "EDC_ADMIN",
        "DATA_HOLDER",
        "HDAB_AUTHORITY",
        "TRUST_CENTER_OPERATOR",
        "EDC_USER_PARTICIPANT",
      ],
    },
    {
      href: "/tasks",
      label: "Tasks",
      icon: ClipboardList,
      roles: [
        "EDC_ADMIN",
        "DATA_HOLDER",
        "HDAB_AUTHORITY",
        "TRUST_CENTER_OPERATOR",
        "EDC_USER_PARTICIPANT",
      ],
    },
    {
      href: "/data/transfer",
      label: "Transfer",
      icon: ArrowRightLeft,
      roles: [
        "EDC_ADMIN",
        "DATA_HOLDER",
        "HDAB_AUTHORITY",
        "TRUST_CENTER_OPERATOR",
        "EDC_USER_PARTICIPANT",
      ],
    },
  ],
};
 
// ── Cluster 4b: My Researches (DATA_USER / researcher role) ─────────────────
// EHDS Art. 46-49 — complete researcher workflow in daily-work order.
// Merges explore + exchange + workflow steps into one logical menu.
const myResearchesGroup: NavGroup = {
  label: "My Researches",
  icon: FlaskConical,
  roles: ["DATA_USER"],
  links: [
    {
      href: "/overview",
      label: "My Research in One View",
      icon: Layers,
      roles: ["DATA_USER"],
    },
    {
      href: "/catalog",
      label: "Browse Catalogs",
      icon: BookOpen,
      roles: ["DATA_USER"],
    },
    {
      href: "/data/discover",
      label: "Discover Datasets",
      icon: Search,
      roles: ["DATA_USER"],
    },
    {
      href: "/negotiate",
      label: "Request Access",
      icon: FileSignature,
      roles: ["DATA_USER"],
    },
    // Art. 67: the application for a data permit, with its eleven items.
    {
      href: "/applications",
      label: "Apply for a Permit",
      icon: FileText,
      roles: ["DATA_USER"],
    },
    {
      href: "/requests",
      label: "Statistical Requests",
      icon: BarChart2,
      roles: ["DATA_USER"],
    },
    {
      href: "/supervision",
      label: "Supervision",
      icon: Gavel,
      roles: ["DATA_USER"],
    },
    {
      href: "/tasks",
      label: "My Applications",
      icon: ClipboardList,
      roles: ["DATA_USER"],
    },
    {
      href: "/data/transfer",
      label: "Retrieve Data",
      icon: ArrowRightLeft,
      roles: ["DATA_USER"],
    },
    {
      href: "/analytics",
      label: "Run Analytics",
      icon: BarChart2,
      roles: ["DATA_USER"],
    },
    {
      href: "/query",
      label: "Query & Export",
      icon: Database,
      roles: ["DATA_USER"],
    },
    {
      href: "/patient",
      label: "Patient Journeys",
      icon: User,
      roles: ["DATA_USER"],
    },
    {
      href: "/eehrxf",
      label: "EEHRxF Profiles",
      icon: Heart,
      roles: ["DATA_USER"],
    },
  ],
};
 
// ── Cluster 4c: My Health (PATIENT role only) ────────────────────────────────
// EHDS Chapter II Art. 3-12 / GDPR Art. 15-22 — patient primary-use rights
const myHealthGroup: NavGroup = {
  label: "My Health",
  icon: Heart,
  roles: ["PATIENT"],
  links: [
    {
      href: "/overview",
      label: "My Health in One View",
      icon: Layers,
      roles: ["PATIENT"],
    },
    {
      href: "/patient",
      label: "My Health Records",
      icon: User,
      roles: ["PATIENT"],
    },
    {
      href: "/patient/query",
      label: "Personal Research",
      icon: Sparkles,
      roles: ["PATIENT"],
    },
    {
      href: "/patient/profile",
      label: "Health Profile & Risks",
      icon: Heart,
      roles: ["PATIENT"],
    },
    {
      href: "/patient/research",
      label: "Research Programs",
      icon: FlaskConical,
      roles: ["PATIENT"],
    },
    {
      href: "/patient/programmes",
      label: "Bonus Programs",
      icon: Gift,
      roles: ["PATIENT"],
    },
    {
      href: "/patient/insights",
      label: "Research Insights",
      icon: Lightbulb,
      roles: ["PATIENT"],
    },
  ],
};
 
// ── Cluster 5: Manage ─────────────────────────────────────────────────────────
const manageGroup: NavGroup = {
  label: "Manage",
  icon: LayoutDashboard,
  roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
  links: [
    {
      href: "/onboarding",
      label: "Onboarding",
      icon: UserPlus,
      roles: ["EDC_ADMIN"],
    },
    {
      href: "/admin",
      label: "Operator Dashboard",
      icon: LayoutDashboard,
      roles: ["EDC_ADMIN"],
    },
    {
      href: "/admin/components",
      label: "EDC Components",
      icon: Activity,
      roles: ["EDC_ADMIN"],
    },
    {
      href: "/admin/attestation",
      label: "SPE attestation",
      icon: Fingerprint,
      roles: ["EDC_ADMIN"],
    },
    {
      href: "/admin/tenants",
      label: "Tenants",
      icon: User,
      roles: ["EDC_ADMIN"],
    },
    {
      href: "/admin/participants",
      label: "Participants",
      icon: Globe,
      roles: ["EDC_ADMIN"],
    },
    {
      href: "/admin/policies",
      label: "Policies",
      icon: ShieldCheck,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
    },
    {
      href: "/admin/audit",
      label: "Audit & Provenance",
      icon: ScrollText,
      roles: ["EDC_ADMIN", "HDAB_AUTHORITY"],
    },
  ],
};
 
// ── Cluster 6: Docs ───────────────────────────────────────────────────────────
const docsGroup: NavGroup = {
  label: "Docs",
  icon: FileText,
  links: [
    { href: "/docs", label: "Overview", icon: FileText },
    { href: "/docs/user-guide", label: "User Guide", icon: BookOpen },
    { href: "/docs/developer", label: "Developer Guide", icon: Code2 },
    { href: "/docs/architecture", label: "Architecture", icon: Layers },
    {
      href: "/docs/security",
      label: "Security and Data Protection",
      icon: ShieldCheck,
    },
    { href: "/docs/klarbefund", label: "Klarbefund", icon: Smartphone },
    { href: "/docs/ehds", label: "EHDS Regulation", icon: Scale },
    { href: "/docs/ehds/glossary", label: "Glossary", icon: Languages },
    { href: "/docs/roadmap", label: "Roadmap", icon: ChartGantt },
    { href: "/docs/operations", label: "Operations", icon: Activity },
  ],
};
 
const ALL_NAV_GROUPS: NavGroup[] = [
  exploreGroup,
  myResearchesGroup,
  myHealthGroup,
  governanceGroup,
  exchangeGroup,
  manageGroup,
  docsGroup,
];
 
// ── Role-filter helpers ────────────────────────────────────────────────────────
 
function canSee(
  itemRoles: string[] | "AUTH" | undefined,
  userRoles: string[],
  isAuthenticated: boolean,
): boolean {
  if (!itemRoles) return true; // public
  Iif (itemRoles === "AUTH") return isAuthenticated;
  // Include derived DATA_HOLDER / DATA_USER based on EDC_USER_PARTICIPANT presence
  return itemRoles.some((r) => userRoles.includes(r));
}
 
/** Filters a group's links and the group itself based on the user's roles. */
function filterGroup(
  group: NavGroup,
  userRoles: string[],
  isAuthenticated: boolean,
): NavGroup | null {
  if (!canSee(group.roles, userRoles, isAuthenticated)) return null;
  // Hide group when user has a role that gets a dedicated menu instead
  if (group.hideForRoles?.some((r) => userRoles.includes(r))) return null;
  const visibleLinks = group.links.filter((l) =>
    canSee(l.roles, userRoles, isAuthenticated),
  );
  Iif (visibleLinks.length === 0) return null;
  return { ...group, links: visibleLinks };
}
 
/** The menu a user with these roles sees. The user guide renders its
 *  role matrix from this, so the guide and the menu cannot disagree. */
export function visibleNavGroups(
  userRoles: string[],
  isAuthenticated: boolean,
): NavGroup[] {
  return ALL_NAV_GROUPS.map((g) =>
    filterGroup(g, userRoles, isAuthenticated),
  ).filter((g): g is NavGroup => g !== null);
}
 
// ── NavDropdown ───────────────────────────────────────────────────────────────
 
function NavDropdown({
  group,
  onNavigate,
}: {
  group: NavGroup;
  onNavigate?: () => void;
}) {
  const t = useT("nav");
  const [open, setOpen] = useState(false);
  const ref = useRef<HTMLDivElement>(null);
  const pathname = usePathname();
 
  const isActive = group.links.some((l) => pathname?.startsWith(l.href));
 
  useEffect(() => {
    function handleClick(e: MouseEvent) {
      if (ref.current && !ref.current.contains(e.target as Node)) {
        setOpen(false);
      }
    }
    document.addEventListener("mousedown", handleClick);
    return () => document.removeEventListener("mousedown", handleClick);
  }, []);
 
  return (
    <div ref={ref} className="relative">
      <button
        onClick={() => setOpen(!open)}
        aria-expanded={open}
        aria-haspopup="true"
        className={`flex items-center gap-1 px-3 py-2 text-sm transition-colors touch-target-sm ${
          isActive
            ? "text-(--accent) font-semibold border-b-2 border-(--accent) rounded-none"
            : "rounded-sm text-(--text-secondary) hover:text-(--text-primary) hover:bg-(--surface-2)"
        }`}
      >
        <group.icon size={15} aria-hidden="true" />
        {t(group.label)}
        <ChevronDown
          size={12}
          aria-hidden="true"
          className={`transition-transform ${open ? "rotate-180" : ""}`}
        />
      </button>
      {open && (
        <div
          className="absolute top-full left-0 mt-1 py-1 bg-(--surface) border border-(--border) rounded-lg shadow-xl z-50 min-w-[170px]"
          role="menu"
        >
          {group.links.map((l) => (
            <Link
              key={l.href}
              href={l.href}
              role="menuitem"
              onClick={() => {
                setOpen(false);
                onNavigate?.();
              }}
              className={`flex items-center gap-2 py-2 text-sm transition-colors ${
                pathname?.startsWith(l.href)
                  ? "text-(--accent) font-medium border-l-2 border-(--accent) pl-[10px] pr-3 bg-(--accent-surface)"
                  : "text-(--text-secondary) hover:bg-(--surface-2) hover:text-(--text-primary) px-3"
              }`}
            >
              <l.icon size={14} aria-hidden="true" />
              {t(l.label)}
            </Link>
          ))}
        </div>
      )}
    </div>
  );
}
 
// ── Navigation ────────────────────────────────────────────────────────────────
 
export default function Navigation() {
  // Tab-scoped session: immune to cross-tab cookie changes in live mode.
  const { session: tabSession, status: tabStatus } = useTabSession();
  // Always call useDemoPersona — hook rules require unconditional calls.
  // In live mode the return value is ignored.
  const demoPersona = useDemoPersona();
  const t = useT("nav");
  const [mobileOpen, setMobileOpen] = useState(false);
 
  // In static demo mode, derive everything from the stored persona.
  // In live mode, use the tab-scoped session snapshot.
  // demoPersona is null when the user has signed out in static mode.
  const isAuthenticated = IS_STATIC
    ? !!demoPersona
    : tabStatus === "authenticated" && !!tabSession;
 
  const baseRoles: string[] = IS_STATIC
    ? demoPersona
      ? [...demoPersona.roles]
      : []
    : tabSession?.roles ?? [];
 
  const username = IS_STATIC
    ? demoPersona?.username ?? ""
    : tabSession?.username ?? "";
 
  // Use preferredUsername (Keycloak login name) for derivation — the display
  // name (e.g. "Maria Schmidt") may not match username-based patterns.
  const derivationName = IS_STATIC
    ? username
    : tabSession?.preferredUsername ?? username;
 
  const participantType = deriveParticipantType(baseRoles, derivationName);
  const _personaId = derivePersonaId(baseRoles, derivationName);
 
  // Augment roles with derived sub-type so filter helpers work
  const effectiveRoles =
    participantType && !baseRoles.includes(participantType)
      ? [...baseRoles, participantType]
      : baseRoles;
 
  // Filter groups/items for the current user
  const visibleGroups = visibleNavGroups(effectiveRoles, isAuthenticated);
 
  // Close mobile nav on route change
  const pathname = usePathname();
  useEffect(() => {
    setMobileOpen(false);
  }, [pathname]);
 
  return (
    <nav
      className="glass border-b border-(--border) sticky top-0 z-50 flex flex-col max-h-dvh"
      role="navigation"
      aria-label={t("Main navigation")}
    >
      <div className="flex items-center gap-1 px-4 py-2">
        <Link
          href="/"
          className="mr-4 shrink-0 whitespace-nowrap font-bold text-(--accent) tracking-wide text-sm hover:text-(--accent-hover) transition-colors"
        >
          Health Dataspace
        </Link>
 
        {/* Desktop nav, from xl: the groups, the picker and the user menu
            need 1100 to 1220 px depending on the language (#782), so below
            1280 px the bar overflowed in every language; there the menu
            button opens the panel instead. */}
        <div className="hidden xl:flex items-center gap-1">
          {visibleGroups.map((g) => (
            <NavDropdown key={g.label} group={g} />
          ))}
        </div>
 
        <div className="ml-auto flex items-center gap-2">
          {/* In the bar with the desktop nav; on a narrower screen the full
              language name made the bar too wide, so there it sits in the
              menu panel. */}
          <SiteSearch />
          <LanguagePicker className="hidden xl:flex" />
          <ThemeToggle />
          <UserMenu />
          {/* Mobile hamburger */}
          <button
            onClick={() => setMobileOpen(!mobileOpen)}
            className="xl:hidden p-2 rounded-sm text-(--text-secondary) hover:text-(--text-primary) hover:bg-(--surface-2) touch-target"
            aria-expanded={mobileOpen}
            aria-controls="mobile-nav"
            aria-label={mobileOpen ? t("Close menu") : t("Open menu")}
          >
            {mobileOpen ? (
              <X size={22} aria-hidden="true" />
            ) : (
              <Menu size={22} aria-hidden="true" />
            )}
          </button>
        </div>
      </div>
 
      {/* Mobile dropdown panel */}
      {mobileOpen && (
        <div
          id="mobile-nav"
          // The bar is sticky, so a panel taller than the screen could not be
          // scrolled to its end on a phone. The nav is at most the screen's
          // height (flex column); the bar keeps its height, the panel takes
          // the rest and scrolls on its own.
          className="xl:hidden border-t border-(--border) bg-(--surface) px-4 py-3 space-y-1 animate-fade-in-up min-h-0 overflow-y-auto overscroll-contain"
        >
          <div className="mb-2 px-1">
            <LanguagePicker />
          </div>
          {visibleGroups.map((g) => (
            <div key={g.label} className="mb-2">
              <span className="text-xs font-semibold text-(--text-secondary) uppercase tracking-wider px-2">
                {t(g.label)}
              </span>
              <div className="mt-1 space-y-0.5">
                {g.links.map((l) => (
                  <Link
                    key={l.href}
                    href={l.href}
                    onClick={() => setMobileOpen(false)}
                    className="flex items-center gap-2 px-3 py-2.5 rounded-sm text-sm text-(--text-secondary) hover:bg-(--surface-2) hover:text-(--text-primary) transition-colors touch-target-sm"
                  >
                    <l.icon size={16} aria-hidden="true" />
                    {t(l.label)}
                  </Link>
                ))}
              </div>
            </div>
          ))}
        </div>
      )}
    </nav>
  );
}