"use client";

import React, { useState, useEffect, useMemo, useRef } from "react";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { signOut } from "next-auth/react";
import {
  LayoutDashboard,
  Film,
  Smartphone,
  Tag,
  ShieldAlert,
  Megaphone,
  Users,
  Settings,
  Sliders,
  Radio,
  ChevronRight,
  ChevronLeft,
  Search,
  Bell,
  ExternalLink,
  Menu,
  X,
  LogOut,
  ShieldCheck,
  CheckCircle2,
  AlertTriangle,
  Clock,
  Command,
  Activity,
  Plus
} from "lucide-react";

interface AdminShellProps {
  children: React.ReactNode;
  user?: {
    name?: string | null;
    email?: string | null;
    image?: string | null;
    role?: string | null;
  };
  siteName?: string;
  brandShort?: string;
  brandAccentColor?: string;
}

interface NavItem {
  href: string;
  label: string;
  icon: React.ComponentType<{ size?: number; className?: string }>;
  badge?: string | null;
  badgeColor?: string;
  external?: boolean;
}

interface NavSection {
  title: string;
  items: NavItem[];
}

const NAV_SECTIONS: NavSection[] = [
  {
    title: "VUE D'ENSEMBLE",
    items: [
      { href: "/admin", label: "Dashboard", icon: LayoutDashboard },
    ],
  },
  {
    title: "GESTION CONTENU",
    items: [
      { href: "/admin/media", label: "Catalogue Vidéos", icon: Film },
      { href: "/admin/shorts", label: "Vidéos Shorts", icon: Smartphone, badge: "TikTok", badgeColor: "bg-pink-500/20 text-pink-300 border-pink-500/30" },
      { href: "/admin/categories", label: "Catégories", icon: Tag },
    ],
  },
  {
    title: "MONÉTISATION & LIVE",
    items: [
      { href: "/admin/ads", label: "Publicités & Bannières", icon: Megaphone },
      { href: "/live", label: "Salons Live Cams", icon: Radio, badge: "LIVE", badgeColor: "bg-emerald-500/20 text-emerald-300 border-emerald-500/30", external: true },
    ],
  },
  {
    title: "COMMUNAUTÉ & DROITS",
    items: [
      { href: "/admin/users", label: "Utilisateurs & Bans", icon: Users },
      { href: "/admin/moderation", label: "Modération & Reports", icon: ShieldAlert, badge: "Live", badgeColor: "bg-rose-500/20 text-rose-300 border-rose-500/30" },
    ],
  },
  {
    title: "SYSTÈME & CONFIGURATION",
    items: [
      { href: "/admin/builder", label: "Site Builder & Thèmes", icon: Sliders },
      { href: "/admin/settings", label: "Paramètres Globaux", icon: Settings },
    ],
  },
];

export function AdminShell({
  children,
  user,
  siteName = "DoroHub",
  brandShort = "DH",
  brandAccentColor = "#2563eb",
}: AdminShellProps) {
  const pathname = usePathname();
  const router = useRouter();

  // Collapsible sidebar state
  const [collapsed, setCollapsed] = useState<boolean>(false);
  const [mobileOpen, setMobileOpen] = useState<boolean>(false);

  // Top header search & notification states
  const [searchOpen, setSearchOpen] = useState(false);
  const [searchQuery, setSearchQuery] = useState("");
  const [notifOpen, setNotifOpen] = useState(false);
  const [userMenuOpen, setUserMenuOpen] = useState(false);

  const notifRef = useRef<HTMLDivElement>(null);
  const userMenuRef = useRef<HTMLDivElement>(null);

  // Restore sidebar state from localStorage on client mount
  useEffect(() => {
    try {
      const saved = localStorage.getItem("crm_admin_sidebar_collapsed");
      if (saved !== null) {
        setCollapsed(saved === "true");
      }
    } catch (e) {}
  }, []);

  const toggleCollapsed = () => {
    setCollapsed((prev) => {
      const next = !prev;
      try {
        localStorage.setItem("crm_admin_sidebar_collapsed", String(next));
      } catch (e) {}
      return next;
    });
  };

  // Keyboard shortcut Ctrl+K / Cmd+K to focus search
  useEffect(() => {
    const handleKeyDown = (e: KeyboardEvent) => {
      if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "k") {
        e.preventDefault();
        setSearchOpen((prev) => !prev);
      }
      if (e.key === "Escape") {
        setSearchOpen(false);
        setNotifOpen(false);
        setUserMenuOpen(false);
      }
    };
    window.addEventListener("keydown", handleKeyDown);
    return () => window.removeEventListener("keydown", handleKeyDown);
  }, []);

  // Close dropdowns on outside click
  useEffect(() => {
    const handleClickOutside = (e: MouseEvent) => {
      if (notifRef.current && !notifRef.current.contains(e.target as Node)) {
        setNotifOpen(false);
      }
      if (userMenuRef.current && !userMenuRef.current.contains(e.target as Node)) {
        setUserMenuOpen(false);
      }
    };
    document.addEventListener("mousedown", handleClickOutside);
    return () => document.removeEventListener("mousedown", handleClickOutside);
  }, []);

  // Compute Breadcrumb Trail
  const breadcrumbs = useMemo(() => {
    const parts = pathname.split("/").filter(Boolean);
    const crumbs = [{ label: "Console", href: "/admin" }];

    if (parts.length === 1 && parts[0] === "admin") {
      crumbs.push({ label: "Dashboard", href: "/admin" });
      return crumbs;
    }

    const pathMap: Record<string, string> = {
      media: "Catalogue Vidéos",
      shorts: "Vidéos Shorts",
      categories: "Catégories",
      ads: "Publicités & Bannières",
      users: "Utilisateurs",
      moderation: "Modération",
      builder: "Site Builder",
      settings: "Paramètres Globaux",
      new: "Nouveau Média",
    };

    let accum = "";
    for (const part of parts) {
      accum += `/${part}`;
      if (part === "admin") continue;
      crumbs.push({
        label: pathMap[part] || part,
        href: accum,
      });
    }

    return crumbs;
  }, [pathname]);

  // Flattened search items
  const allNavItems = useMemo(() => {
    return NAV_SECTIONS.flatMap((sec) => sec.items);
  }, []);

  const filteredSearchItems = useMemo(() => {
    if (!searchQuery.trim()) return allNavItems;
    const q = searchQuery.toLowerCase();
    return allNavItems.filter(
      (item) =>
        item.label.toLowerCase().includes(q) ||
        item.href.toLowerCase().includes(q)
    );
  }, [searchQuery, allNavItems]);

  const userName = user?.name || user?.email?.split("@")[0] || "Administrateur";
  const userRole = user?.role || "ADMIN";

  return (
    <div className="min-h-screen bg-[#0b0e14] text-[#f8fafc] font-sans flex flex-col md:flex-row antialiased selection:bg-[#2563eb] selection:text-white">
      {/* Mobile Drawer Backdrop */}
      {mobileOpen && (
        <div
          onClick={() => setMobileOpen(false)}
          className="fixed inset-0 bg-black/80 backdrop-blur-sm z-40 md:hidden"
        />
      )}

      {/* ── COLLAPSIBLE NAVIGATION SIDEBAR ── */}
      <aside
        className={`fixed md:sticky top-0 left-0 z-50 h-screen bg-[#12151c] border-r border-[#1e2430] flex flex-col justify-between transition-[width,transform] duration-200 ease-in-out ${
          collapsed ? "w-20" : "w-64"
        } ${mobileOpen ? "translate-x-0 !w-64" : "-translate-x-full md:translate-x-0"}`}
      >
        <div className="flex flex-col h-full overflow-hidden">
          {/* Brand Header */}
          <div className="h-16 px-4 border-b border-[#1e2430] flex items-center justify-between bg-[#12151c]">
            <Link
              href="/admin"
              className="flex items-center gap-3 group min-w-0"
              title={`${siteName} Console`}
            >
              <div
                className="w-9 h-9 rounded-xl flex items-center justify-center font-mono font-bold text-sm text-white shrink-0 shadow-[0_0_15px_rgba(37,99,235,0.35)] transition-transform group-hover:scale-105"
                style={{ background: brandAccentColor }}
              >
                {brandShort}
              </div>
              {(!collapsed || mobileOpen) && (
                <div className="min-w-0 flex flex-col leading-tight">
                  <div className="flex items-center gap-1.5">
                    <span className="font-bold tracking-tight text-white text-base truncate">
                      {siteName}
                    </span>
                    <span className="text-[10px] font-mono font-semibold bg-[#2563eb]/20 text-[#3b82f6] border border-[#2563eb]/30 px-1.5 py-0.2 rounded">
                      CRM
                    </span>
                  </div>
                  <span className="text-[11px] text-[#94a3b8] font-mono tracking-wide">
                    Enterprise v3.2
                  </span>
                </div>
              )}
            </Link>

            {/* Collapse toggle (Desktop) */}
            <button
              onClick={toggleCollapsed}
              className="hidden md:flex items-center justify-center w-7 h-7 rounded-lg text-[#94a3b8] hover:text-white hover:bg-[#1e2430] border border-[#1e2430] transition-colors"
              title={collapsed ? "Déplier la barre latérale" : "Replier la barre latérale"}
            >
              {collapsed ? <ChevronRight size={14} /> : <ChevronLeft size={14} />}
            </button>

            {/* Close button (Mobile) */}
            <button
              onClick={() => setMobileOpen(false)}
              className="md:hidden p-1.5 text-[#94a3b8] hover:text-white rounded-lg"
            >
              <X size={18} />
            </button>
          </div>

          {/* Navigation Links Scrollable Area */}
          <nav className="flex-1 overflow-y-auto px-3 py-4 space-y-6 scrollbar-thin scrollbar-thumb-[#1e2430]">
            {NAV_SECTIONS.map((section, sIdx) => (
              <div key={sIdx} className="space-y-1">
                {(!collapsed || mobileOpen) ? (
                  <p className="px-3 text-[10px] font-mono font-bold text-[#64748b] tracking-wider uppercase mb-2">
                    {section.title}
                  </p>
                ) : (
                  <div className="h-px bg-[#1e2430] my-2 mx-1" />
                )}

                {section.items.map((item) => {
                  const Icon = item.icon;
                  const isActive =
                    item.href === "/admin"
                      ? pathname === "/admin"
                      : pathname.startsWith(item.href);

                  return (
                    <Link
                      key={item.href}
                      href={item.href}
                      target={item.external ? "_blank" : undefined}
                      rel={item.external ? "noopener noreferrer" : undefined}
                      onClick={() => setMobileOpen(false)}
                      className={`group relative flex items-center gap-3 px-3 py-2.5 rounded-xl text-sm font-medium transition-all duration-150 ${
                        isActive
                          ? "bg-[#2563eb] text-white shadow-[0_0_20px_rgba(37,99,235,0.4)]"
                          : "text-[#94a3b8] hover:text-white hover:bg-[#1a202c]"
                      }`}
                      title={collapsed && !mobileOpen ? item.label : undefined}
                    >
                      <Icon
                        size={18}
                        className={`shrink-0 transition-transform duration-150 group-hover:scale-110 ${
                          isActive ? "text-white" : "text-[#94a3b8] group-hover:text-white"
                        }`}
                      />

                      {(!collapsed || mobileOpen) && (
                        <div className="flex items-center justify-between flex-1 min-w-0">
                          <span className="truncate">{item.label}</span>
                          {item.badge && (
                            <span
                              className={`text-[10px] font-mono px-1.5 py-0.5 rounded border font-semibold ${
                                item.badgeColor || "bg-[#2563eb]/20 text-[#3b82f6] border-[#2563eb]/40"
                              }`}
                            >
                              {item.badge}
                            </span>
                          )}
                        </div>
                      )}

                      {/* Tooltip in collapsed mode */}
                      {collapsed && !mobileOpen && (
                        <div className="absolute left-full ml-3 px-2.5 py-1.5 bg-[#12151c] text-white text-xs font-medium rounded-lg border border-[#1e2430] shadow-xl whitespace-nowrap opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto transition-opacity z-50">
                          {item.label}
                          {item.badge && (
                            <span className="ml-1.5 text-[10px] font-mono text-[#3b82f6]">
                              ({item.badge})
                            </span>
                          )}
                        </div>
                      )}
                    </Link>
                  );
                })}
              </div>
            ))}
          </nav>

          {/* User Card & Public Site Shortcut */}
          <div className="p-3 border-t border-[#1e2430] bg-[#0e1117] space-y-2">
            <Link
              href="/"
              target="_blank"
              className="flex items-center justify-center gap-2 w-full py-2 px-3 rounded-xl bg-[#161a24] hover:bg-[#1e2430] border border-[#1e2430] text-xs font-semibold text-[#94a3b8] hover:text-white transition-all group"
            >
              <ExternalLink size={14} className="group-hover:translate-x-0.5 transition-transform" />
              {(!collapsed || mobileOpen) && <span>Voir le site public</span>}
            </Link>

            <div className="flex items-center gap-3 p-2 rounded-xl bg-[#12151c] border border-[#1e2430]/60">
              <div className="w-8 h-8 rounded-lg bg-[#2563eb]/20 border border-[#2563eb]/40 flex items-center justify-center font-bold text-xs text-[#60a5fa] shrink-0">
                {user?.image ? (
                  <img src={user.image} alt={userName} className="w-full h-full object-cover rounded-lg" />
                ) : (
                  userName[0]?.toUpperCase()
                )}
              </div>
              {(!collapsed || mobileOpen) && (
                <div className="min-w-0 flex-1">
                  <p className="text-xs font-bold text-white truncate">{userName}</p>
                  <p className="text-[10px] font-mono text-[#16a34a] font-semibold flex items-center gap-1">
                    <span className="w-1.5 h-1.5 rounded-full bg-[#16a34a]" />
                    {userRole}
                  </p>
                </div>
              )}
            </div>
          </div>
        </div>
      </aside>

      {/* ── MAIN CONTENT AREA & PERSISTENT TOP HEADER ── */}
      <div className="flex-1 flex flex-col min-w-0">
        {/* Persistent Top Header */}
        <header className="sticky top-0 z-30 h-16 bg-[#12151c]/95 backdrop-blur-md border-b border-[#1e2430] px-4 sm:px-6 flex items-center justify-between gap-4">
          {/* Left: Mobile hamburger + Breadcrumbs */}
          <div className="flex items-center gap-3 min-w-0">
            <button
              onClick={() => setMobileOpen(true)}
              className="md:hidden p-2 text-[#94a3b8] hover:text-white bg-[#1a202c] border border-[#1e2430] rounded-xl"
            >
              <Menu size={18} />
            </button>

            {/* Breadcrumb Navigation */}
            <nav className="flex items-center gap-1.5 text-xs text-[#94a3b8] overflow-hidden whitespace-nowrap">
              {breadcrumbs.map((crumb, idx) => {
                const isLast = idx === breadcrumbs.length - 1;
                return (
                  <React.Fragment key={crumb.href + idx}>
                    {idx > 0 && <ChevronRight size={13} className="text-[#475569] shrink-0" />}
                    {isLast ? (
                      <span className="font-semibold text-white truncate">{crumb.label}</span>
                    ) : (
                      <Link
                        href={crumb.href}
                        className="hover:text-white transition-colors truncate"
                      >
                        {crumb.label}
                      </Link>
                    )}
                  </React.Fragment>
                );
              })}
            </nav>
          </div>

          {/* Center / Global Search Bar */}
          <div className="hidden lg:flex items-center flex-1 max-w-md mx-4">
            <div
              onClick={() => setSearchOpen(true)}
              className="w-full flex items-center justify-between px-3.5 py-2 bg-[#0b0e14] border border-[#1e2430] hover:border-[#2563eb]/50 rounded-xl text-xs text-[#64748b] hover:text-[#94a3b8] cursor-pointer transition-all shadow-inner"
            >
              <div className="flex items-center gap-2">
                <Search size={14} className="text-[#64748b]" />
                <span>Rechercher un module, vidéo, utilisateur...</span>
              </div>
              <kbd className="font-mono text-[10px] bg-[#1a202c] border border-[#2b3547] text-[#94a3b8] px-1.5 py-0.5 rounded shadow">
                ⌘K
              </kbd>
            </div>
          </div>

          {/* Right: Quick actions, System status, Notifications & Profile */}
          <div className="flex items-center gap-2.5 sm:gap-3 shrink-0">
            {/* Search Button for Mobile/Tablet */}
            <button
              onClick={() => setSearchOpen(true)}
              className="lg:hidden p-2 text-[#94a3b8] hover:text-white hover:bg-[#1a202c] border border-[#1e2430] rounded-xl transition-colors"
              title="Rechercher (⌘K)"
            >
              <Search size={16} />
            </button>

            {/* System Status Pill */}
            <div className="hidden sm:flex items-center gap-2 px-3 py-1.5 rounded-xl bg-[#0b0e14] border border-[#1e2430] text-xs font-mono">
              <span className="relative flex h-2 w-2">
                <span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-[#16a34a] opacity-75" />
                <span className="relative inline-flex rounded-full h-2 w-2 bg-[#16a34a]" />
              </span>
              <span className="text-[#16a34a] font-semibold text-[11px]">En Ligne</span>
              <span className="text-[#475569] text-[10px]">|</span>
              <span className="text-[#94a3b8] text-[10px]">Turbopack</span>
            </div>

            {/* Quick Add Video Button */}
            <Link
              href="/admin/media/new"
              className="hidden sm:flex items-center gap-1.5 px-3 py-1.5 rounded-xl bg-[#2563eb] hover:bg-[#1d4ed8] text-white text-xs font-semibold shadow-[0_0_15px_rgba(37,99,235,0.3)] transition-all hover:scale-[1.02]"
            >
              <Plus size={14} />
              <span>Nouveau Média</span>
            </Link>

            {/* Notifications Popover */}
            <div className="relative" ref={notifRef}>
              <button
                onClick={() => setNotifOpen(!notifOpen)}
                className="relative p-2 text-[#94a3b8] hover:text-white hover:bg-[#1a202c] border border-[#1e2430] rounded-xl transition-colors"
                title="Notifications système"
              >
                <Bell size={16} />
                <span className="absolute top-1.5 right-1.5 w-2 h-2 rounded-full bg-[#dc2626] ring-2 ring-[#12151c]" />
              </button>

              {notifOpen && (
                <div className="absolute right-0 mt-2 w-80 bg-[#12151c] border border-[#1e2430] rounded-2xl shadow-2xl p-4 z-50 space-y-3 animate-fade-in">
                  <div className="flex items-center justify-between border-b border-[#1e2430] pb-2.5">
                    <p className="font-bold text-xs text-white">Flux d'Activité Récent</p>
                    <span className="text-[10px] font-mono text-[#3b82f6] bg-[#2563eb]/20 px-2 py-0.5 rounded-full font-semibold">
                      Temps réel
                    </span>
                  </div>
                  <div className="space-y-2 text-xs">
                    <div className="p-2.5 rounded-xl bg-[#0b0e14] border border-[#1e2430] flex items-start gap-2.5">
                      <CheckCircle2 size={15} className="text-[#16a34a] shrink-0 mt-0.5" />
                      <div>
                        <p className="font-semibold text-white">Serveur Déployé & Opérationnel</p>
                        <p className="text-[10px] text-[#94a3b8]">Turbopack Next.js 16 build synchronisé</p>
                      </div>
                    </div>
                    <div className="p-2.5 rounded-xl bg-[#0b0e14] border border-[#1e2430] flex items-start gap-2.5">
                      <ShieldCheck size={15} className="text-[#3b82f6] shrink-0 mt-0.5" />
                      <div>
                        <p className="font-semibold text-white">Pare-feu Nexus WAF Actif</p>
                        <p className="text-[10px] text-[#94a3b8]">0 injection bloquée lors des 24h</p>
                      </div>
                    </div>
                    <div className="p-2.5 rounded-xl bg-[#0b0e14] border border-[#1e2430] flex items-start gap-2.5">
                      <Radio size={15} className="text-[#f59e0b] shrink-0 mt-0.5" />
                      <div>
                        <p className="font-semibold text-white">Plateforme Live Cam Connectée</p>
                        <p className="text-[10px] text-[#94a3b8]">Flux Stripcash & salon en direct opérationnels</p>
                      </div>
                    </div>
                  </div>
                </div>
              )}
            </div>

            {/* User Profile Dropdown */}
            <div className="relative" ref={userMenuRef}>
              <button
                onClick={() => setUserMenuOpen(!userMenuOpen)}
                className="flex items-center gap-2 p-1.5 pr-2.5 rounded-xl hover:bg-[#1a202c] border border-transparent hover:border-[#1e2430] transition-all"
              >
                <div className="w-7 h-7 rounded-lg bg-[#2563eb] text-white font-bold text-xs flex items-center justify-center">
                  {user?.image ? (
                    <img src={user.image} alt={userName} className="w-full h-full object-cover rounded-lg" />
                  ) : (
                    userName[0]?.toUpperCase()
                  )}
                </div>
                <span className="hidden md:inline text-xs font-semibold text-white truncate max-w-[100px]">
                  {userName}
                </span>
              </button>

              {userMenuOpen && (
                <div className="absolute right-0 mt-2 w-56 bg-[#12151c] border border-[#1e2430] rounded-2xl shadow-2xl p-2 z-50 space-y-1 animate-fade-in text-xs">
                  <div className="p-2.5 border-b border-[#1e2430]">
                    <p className="font-bold text-white truncate">{userName}</p>
                    <p className="text-[11px] text-[#94a3b8] truncate font-mono">{user?.email}</p>
                    <span className="inline-block mt-1 text-[10px] font-mono text-[#16a34a] font-bold bg-[#16a34a]/15 border border-[#16a34a]/30 px-2 py-0.5 rounded">
                      {userRole}
                    </span>
                  </div>

                  <Link
                    href="/admin/settings"
                    onClick={() => setUserMenuOpen(false)}
                    className="flex items-center gap-2.5 px-3 py-2 rounded-xl text-[#94a3b8] hover:text-white hover:bg-[#1e2430] transition-colors"
                  >
                    <Settings size={14} />
                    <span>Paramètres Globaux</span>
                  </Link>

                  <Link
                    href="/admin/users"
                    onClick={() => setUserMenuOpen(false)}
                    className="flex items-center gap-2.5 px-3 py-2 rounded-xl text-[#94a3b8] hover:text-white hover:bg-[#1e2430] transition-colors"
                  >
                    <Users size={14} />
                    <span>Gérer les Membres</span>
                  </Link>

                  <button
                    onClick={() => signOut({ callbackUrl: "/login" })}
                    className="w-full flex items-center gap-2.5 px-3 py-2 rounded-xl text-[#dc2626] hover:bg-[#dc2626]/10 transition-colors"
                  >
                    <LogOut size={14} />
                    <span>Déconnexion</span>
                  </button>
                </div>
              )}
            </div>
          </div>
        </header>

        {/* Global Search Modal */}
        {searchOpen && (
          <div className="fixed inset-0 bg-black/80 backdrop-blur-md z-50 flex items-start justify-center pt-20 p-4 animate-fade-in">
            <div
              className="bg-[#12151c] border border-[#1e2430] w-full max-w-xl rounded-2xl shadow-2xl overflow-hidden"
              onClick={(e) => e.stopPropagation()}
            >
              <div className="p-3.5 border-b border-[#1e2430] flex items-center gap-3 bg-[#0e1117]">
                <Search size={18} className="text-[#2563eb]" />
                <input
                  type="text"
                  autoFocus
                  placeholder="Tapez pour naviguer (ex: vidéos, pubs, utilisateurs, thèmes)..."
                  value={searchQuery}
                  onChange={(e) => setSearchQuery(e.target.value)}
                  className="bg-transparent flex-1 text-sm text-white placeholder-[#64748b] focus:outline-none"
                />
                <button
                  onClick={() => setSearchOpen(false)}
                  className="p-1 text-[#94a3b8] hover:text-white rounded-lg"
                >
                  <X size={16} />
                </button>
              </div>

              <div className="max-h-80 overflow-y-auto p-2 space-y-1">
                {filteredSearchItems.length === 0 ? (
                  <p className="p-4 text-xs text-center text-[#64748b]">
                    Aucun module correspondant à "{searchQuery}".
                  </p>
                ) : (
                  filteredSearchItems.map((item) => {
                    const Icon = item.icon;
                    return (
                      <button
                        key={item.href}
                        onClick={() => {
                          setSearchOpen(false);
                          router.push(item.href);
                        }}
                        className="w-full flex items-center justify-between p-2.5 rounded-xl hover:bg-[#1a202c] text-left transition-colors text-xs text-[#cbd5e1] hover:text-white group"
                      >
                        <div className="flex items-center gap-3">
                          <Icon size={16} className="text-[#94a3b8] group-hover:text-[#2563eb]" />
                          <span className="font-medium">{item.label}</span>
                        </div>
                        <span className="font-mono text-[10px] text-[#64748b] group-hover:text-[#94a3b8]">
                          {item.href}
                        </span>
                      </button>
                    );
                  })
                )}
              </div>
            </div>
          </div>
        )}

        {/* Main Render Page Content */}
        <main className="flex-1 min-w-0 p-4 sm:p-6 lg:p-8 overflow-y-auto">
          {children}
        </main>
      </div>
    </div>
  );
}
