import type { Metadata } from "next";
import Link from "next/link";
import { redirect } from "next/navigation";
import { auth } from "@/lib/auth";
import QuickStatsWidget from "@/components/admin/quick-stats-widget";

export const metadata: Metadata = {
  robots: { index: false, follow: false },
};

// All admin pages stay dynamic so cached HTML never leaks PII (admin user
// list embeds emails) and so the auth gate below is re-checked per request.
export const dynamic = "force-dynamic";

const optionTables = [
  { href: "/admin/options/ages", label: "Ages" },
  { href: "/admin/options/alternatives", label: "Alternatives" },
  { href: "/admin/options/breast-sizes", label: "Breast Sizes" },
  { href: "/admin/options/breast-states", label: "Breast States" },
  { href: "/admin/options/callings", label: "Callings" },
  { href: "/admin/options/contact-apps", label: "Contact Apps" },
  { href: "/admin/options/cup-sizes", label: "Cup Sizes" },
  { href: "/admin/options/currencies", label: "Currencies" },
  { href: "/admin/options/enjoys", label: "Enjoys" },
  { href: "/admin/options/ethnicities", label: "Ethnicities" },
  { href: "/admin/options/eye-colors", label: "Eye Colors" },
  { href: "/admin/options/genders", label: "Genders" },
  { href: "/admin/options/hair-colors", label: "Hair Colors" },
  { href: "/admin/options/hair-lengths", label: "Hair Lengths" },
  { href: "/admin/options/hair-publics", label: "Hair Publics" },
  { href: "/admin/options/heights", label: "Heights" },
  { href: "/admin/options/languages", label: "Languages" },
  { href: "/admin/options/nationalities", label: "Nationalities" },
  { href: "/admin/options/offers", label: "Offers" },
  { href: "/admin/options/orientations", label: "Orientations" },
  { href: "/admin/options/piercings", label: "Piercings" },
  { href: "/admin/options/rates", label: "Rates" },
  { href: "/admin/options/smoking", label: "Smoking" },
  { href: "/admin/options/starsigns", label: "Star Signs" },
  { href: "/admin/options/tags", label: "Tags" },
  { href: "/admin/options/tattoos", label: "Tattoos" },
  { href: "/admin/options/timezones", label: "Timezones" },
  { href: "/admin/options/travels", label: "Travels" },
  { href: "/admin/options/weights", label: "Weights" },
  { href: "/admin/options/withs", label: "Withs" },
];

export default async function AdminLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  // Defence-in-depth: middleware is the primary admin gate but if it ever
  // fails open (Stage 6 hotfix already addresses one such case) this layout
  // refuses to render the admin sidebar to non-admins.
  const session = await auth();
  if (!session?.user || (session.user as { userType?: string }).userType !== "admin") {
    redirect("/login");
  }

  return (
    <div className="min-h-screen flex">
      {/* Sidebar */}
      <aside className="w-64 bg-[#0a0a1a] border-r border-surface-light shrink-0 overflow-y-auto h-screen sticky top-0">
        <div className="p-4 border-b border-surface-light">
          <Link href="/admin/dashboard" className="text-primary font-bold text-xl">
            Admin Panel
          </Link>
          <Link
            href="/"
            className="flex items-center gap-1 text-xs text-text-muted hover:text-gold mt-1 transition-colors"
          >
            <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 19l-7-7m0 0l7-7m-7 7h18" />
            </svg>
            Back to site
          </Link>
        </div>

        <nav className="p-3 space-y-1">
          {/* Main Navigation */}
          <p className="text-text-muted text-xs uppercase tracking-wider px-3 pt-3 pb-1">
            Main
          </p>
          <Link
            href="/admin/dashboard"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
            </svg>
            Dashboard
          </Link>
          <Link
            href="/admin/users"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
            </svg>
            Users
          </Link>
          <Link
            href="/admin/agencies"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
            </svg>
            Agencies
          </Link>
          <Link
            href="/admin/transactions"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M17 9V7a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2m2 4h10a2 2 0 002-2v-6a2 2 0 00-2-2H9a2 2 0 00-2 2v6a2 2 0 002 2zm7-5a2 2 0 11-4 0 2 2 0 014 0z" />
            </svg>
            Transactions
          </Link>
          <Link
            href="/admin/payouts"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />
            </svg>
            Payouts
          </Link>
          <Link
            href="/admin/credits"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5 text-gold" viewBox="0 0 24 24" fill="currentColor">
              <circle cx="12" cy="12" r="10" fill="currentColor" opacity="0.2" />
              <circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="1.5" fill="none" />
              <text x="12" y="16" textAnchor="middle" fontSize="11" fontWeight="bold" fill="currentColor">C</text>
            </svg>
            Credit Packages
          </Link>
          <Link
            href="/admin/boosts"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M13 10V3L4 14h7v7l9-11h-7z" />
            </svg>
            Boosts
          </Link>
          <Link
            href="/admin/subscriptions"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M15 5v2m0 4v2m0 4v2M5 5a2 2 0 00-2 2v3a2 2 0 110 4v3a2 2 0 002 2h14a2 2 0 002-2v-3a2 2 0 110-4V7a2 2 0 00-2-2H5z" />
            </svg>
            Subscriptions
          </Link>
          <Link
            href="/admin/referrals"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
            </svg>
            Referrals
          </Link>
          <Link
            href="/admin/ip-bans"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636" />
            </svg>
            IP Bans
          </Link>
          <Link
            href="/admin/login-history"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
            </svg>
            Login History
          </Link>
          <Link
            href="/admin/age-verification"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
            </svg>
            Age Verification
          </Link>
          <Link
            href="/admin/announcements"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z" />
            </svg>
            Announcements
          </Link>

          {/* Content & Moderation */}
          <p className="text-text-muted text-xs uppercase tracking-wider px-3 pt-4 pb-1">
            Content & Moderation
          </p>
          <Link
            href="/admin/moderation"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
            </svg>
            Moderation
          </Link>
          <Link
            href="/admin/fraud"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5 text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
            </svg>
            Fraud Detection
          </Link>
          <Link
            href="/admin/blog-posts"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" />
            </svg>
            Blog Posts
          </Link>
          <Link
            href="/admin/reviews"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" />
            </svg>
            Reviews
          </Link>
          <Link
            href="/admin/help"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
            </svg>
            Help Articles
          </Link>
          <Link
            href="/admin/newsletters"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
            </svg>
            Newsletters
          </Link>
          <Link
            href="/admin/tickets"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z" />
            </svg>
            Tickets
          </Link>
          <Link
            href="/admin/audit-log"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" />
            </svg>
            Audit Log
          </Link>
          <Link
            href="/admin/finance"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
            </svg>
            Finance
          </Link>
          <Link
            href="/admin/commission"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5 text-gold" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
            </svg>
            Commission
          </Link>
          <Link
            href="/admin/promo-codes"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5 text-gold" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z" />
            </svg>
            Promo Codes
          </Link>
          <Link
            href="/admin/revenue"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6" />
            </svg>
            Revenue
          </Link>
          <Link
            href="/admin/engagement"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
            </svg>
            Engagement
          </Link>
          <Link
            href="/admin/ai-moderation"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
            </svg>
            AI Moderation
          </Link>
          <Link
            href="/admin/reports"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
            </svg>
            Reports
          </Link>
          <Link
            href="/admin/settings"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
            </svg>
            Settings
          </Link>

          {/* Geography */}
          <p className="text-text-muted text-xs uppercase tracking-wider px-3 pt-4 pb-1">
            Geography
          </p>
          <Link
            href="/admin/countries"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
            </svg>
            Countries
          </Link>
          <Link
            href="/admin/cities"
            className="flex items-center gap-3 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors"
          >
            <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
            </svg>
            Cities
          </Link>

          {/* Options */}
          <p className="text-text-muted text-xs uppercase tracking-wider px-3 pt-4 pb-1">
            Options
          </p>
          <div className="space-y-0.5 max-h-[400px] overflow-y-auto">
            {optionTables.map((opt) => (
              <Link
                key={opt.href}
                href={opt.href}
                className="block px-3 py-1.5 rounded text-text-muted hover:text-white hover:bg-surface-light transition-colors text-sm"
              >
                {opt.label}
              </Link>
            ))}
          </div>
        </nav>

        {/* Back to site */}
        <div className="p-3 border-t border-surface-light mt-4">
          <Link
            href="/"
            className="flex items-center gap-2 px-3 py-2 rounded-lg text-text-muted hover:text-white hover:bg-surface-light transition-colors text-sm"
          >
            <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M10 19l-7-7m0 0l7-7m-7 7h18" />
            </svg>
            Back to Site
          </Link>
        </div>
      </aside>

      {/* Main Content */}
      <main className="flex-1 bg-background min-h-screen">
        <QuickStatsWidget />
        <div className="p-6 lg:p-8">{children}</div>
      </main>
    </div>
  );
}
