"use client";

import { useState, useEffect } from "react";
import Link from "next/link";
import { SITE, type Lang } from "@/lib/config";

const LAST_UPDATED = "January 11, 2025";

interface CookieCategory {
  id: string;
  titleEn: string;
  titleAr: string;
  descriptionEn: string;
  descriptionAr: string;
  cookies: {
    nameEn: string;
    nameAr: string;
    purposeEn: string;
    purposeAr: string;
    duration: string;
    type: string;
  }[];
}

interface Section {
  id: string;
  titleEn: string;
  titleAr: string;
  contentEn: string;
  contentAr: string;
}

const COOKIE_CATEGORIES: CookieCategory[] = [
  {
    id: "essential",
    titleEn: "Essential Cookies",
    titleAr: "ملفات تعريف الارتباط الأساسية",
    descriptionEn:
      "These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you such as setting your privacy preferences, logging in, or filling in forms.",
    descriptionAr:
      "هذه الملفات ضرورية لعمل الموقع ولا يمكن إيقافها. عادةً ما يتم تعيينها فقط استجابةً لإجراءات تقوم بها مثل تعيين تفضيلات الخصوصية أو تسجيل الدخول أو ملء النماذج.",
    cookies: [
      {
        nameEn: "mawidi_session",
        nameAr: "mawidi_session",
        purposeEn: "Maintains your session state and keeps you logged in",
        purposeAr: "يحافظ على حالة الجلسة ويبقيك مسجلاً للدخول",
        duration: "Session",
        type: "HTTP Cookie",
      },
      {
        nameEn: "next-auth.session-token",
        nameAr: "next-auth.session-token",
        purposeEn: "Authentication token for secure login",
        purposeAr: "رمز المصادقة لتسجيل الدخول الآمن",
        duration: "30 days",
        type: "HTTP Cookie",
      },
      {
        nameEn: "NEXT_LOCALE",
        nameAr: "NEXT_LOCALE",
        purposeEn: "Stores your language preference (Arabic/English)",
        purposeAr: "يحفظ تفضيل اللغة الخاص بك (عربي/إنجليزي)",
        duration: "1 year",
        type: "HTTP Cookie",
      },
    ],
  },
  {
    id: "analytics",
    titleEn: "Analytics Cookies",
    titleAr: "ملفات تعريف ارتباط التحليلات",
    descriptionEn:
      "These cookies help us understand how visitors interact with our website by collecting and reporting information anonymously. This helps us improve our services.",
    descriptionAr:
      "تساعدنا هذه الملفات على فهم كيفية تفاعل الزوار مع موقعنا من خلال جمع المعلومات والإبلاغ عنها بشكل مجهول. هذا يساعدنا على تحسين خدماتنا.",
    cookies: [
      {
        nameEn: "_ga",
        nameAr: "_ga",
        purposeEn: "Google Analytics - distinguishes unique users",
        purposeAr: "Google Analytics - يميز المستخدمين الفريدين",
        duration: "2 years",
        type: "HTTP Cookie",
      },
      {
        nameEn: "_ga_*",
        nameAr: "_ga_*",
        purposeEn: "Google Analytics - maintains session state",
        purposeAr: "Google Analytics - يحافظ على حالة الجلسة",
        duration: "2 years",
        type: "HTTP Cookie",
      },
      {
        nameEn: "_gid",
        nameAr: "_gid",
        purposeEn: "Google Analytics - distinguishes users",
        purposeAr: "Google Analytics - يميز المستخدمين",
        duration: "24 hours",
        type: "HTTP Cookie",
      },
    ],
  },
  {
    id: "functional",
    titleEn: "Functional Cookies",
    titleAr: "ملفات تعريف الارتباط الوظيفية",
    descriptionEn:
      "These cookies enable enhanced functionality and personalization, such as remembering your preferences and settings.",
    descriptionAr:
      "تتيح هذه الملفات وظائف محسّنة وتخصيصًا، مثل تذكر تفضيلاتك وإعداداتك.",
    cookies: [
      {
        nameEn: "theme_preference",
        nameAr: "theme_preference",
        purposeEn: "Stores your dark/light mode preference",
        purposeAr: "يحفظ تفضيلك للوضع الداكن/الفاتح",
        duration: "1 year",
        type: "HTTP Cookie",
      },
      {
        nameEn: "cookie_consent",
        nameAr: "cookie_consent",
        purposeEn: "Remembers your cookie preferences",
        purposeAr: "يتذكر تفضيلات ملفات تعريف الارتباط الخاصة بك",
        duration: "1 year",
        type: "HTTP Cookie",
      },
    ],
  },
  {
    id: "third-party",
    titleEn: "Third-Party Cookies",
    titleAr: "ملفات تعريف ارتباط الطرف الثالث",
    descriptionEn:
      "These cookies are set by external services we use to provide certain features on our website.",
    descriptionAr:
      "يتم تعيين هذه الملفات بواسطة خدمات خارجية نستخدمها لتوفير ميزات معينة على موقعنا.",
    cookies: [
      {
        nameEn: "stripe_*",
        nameAr: "stripe_*",
        purposeEn: "Stripe payment processing - fraud detection and security",
        purposeAr: "معالجة الدفع عبر Stripe - اكتشاف الاحتيال والأمان",
        duration: "Session",
        type: "HTTP Cookie",
      },
    ],
  },
];

const COOKIE_SECTIONS: Section[] = [
  {
    id: "what-are-cookies",
    titleEn: "What Are Cookies?",
    titleAr: "ما هي ملفات تعريف الارتباط؟",
    contentEn: `Cookies are small text files that are placed on your device (computer, smartphone, or tablet) when you visit a website. They are widely used to make websites work more efficiently and provide information to website owners.

Cookies help us:
• Remember your login information
• Keep you signed in between visits
• Remember your language preference
• Understand how you use our website
• Improve your experience

Cookies do not contain any information that personally identifies you, but personal information that we store about you may be linked to the information stored in and obtained from cookies.`,
    contentAr: `ملفات تعريف الارتباط هي ملفات نصية صغيرة يتم وضعها على جهازك (الكمبيوتر أو الهاتف الذكي أو الجهاز اللوحي) عند زيارة موقع ويب. يتم استخدامها على نطاق واسع لجعل مواقع الويب تعمل بكفاءة أكبر وتوفير معلومات لأصحاب المواقع.

تساعدنا ملفات تعريف الارتباط في:
• تذكر معلومات تسجيل الدخول الخاصة بك
• إبقائك مسجلاً للدخول بين الزيارات
• تذكر تفضيل اللغة الخاص بك
• فهم كيفية استخدامك لموقعنا
• تحسين تجربتك

لا تحتوي ملفات تعريف الارتباط على أي معلومات تحدد هويتك شخصيًا، ولكن قد تكون المعلومات الشخصية التي نخزنها عنك مرتبطة بالمعلومات المخزنة والمستمدة من ملفات تعريف الارتباط.`,
  },
  {
    id: "how-we-use-cookies",
    titleEn: "How We Use Cookies",
    titleAr: "كيف نستخدم ملفات تعريف الارتباط",
    contentEn: `We use cookies for several purposes:

Essential Website Functions:
• Authenticating users and preventing fraudulent use of login credentials
• Remembering your language preference
• Maintaining your session state
• Enabling secure payments through Stripe

Analytics and Performance:
• Understanding how visitors use our website
• Measuring the effectiveness of our services
• Identifying technical issues and improving performance
• Tracking page views and user interactions (anonymized)

Functionality and Preferences:
• Remembering your settings (dark/light mode, layout preferences)
• Storing your cookie consent preferences
• Customizing content based on your preferences

We do not use cookies for:
• Selling your data to third parties
• Tracking you across other websites
• Targeted advertising (we don't run ads)`,
    contentAr: `نستخدم ملفات تعريف الارتباط لعدة أغراض:

وظائف الموقع الأساسية:
• مصادقة المستخدمين ومنع الاستخدام الاحتيالي لبيانات تسجيل الدخول
• تذكر تفضيل اللغة الخاص بك
• الحفاظ على حالة الجلسة
• تمكين الدفع الآمن من خلال Stripe

التحليلات والأداء:
• فهم كيفية استخدام الزوار لموقعنا
• قياس فعالية خدماتنا
• تحديد المشكلات الفنية وتحسين الأداء
• تتبع مشاهدات الصفحة وتفاعلات المستخدم (مجهول)

الوظائف والتفضيلات:
• تذكر إعداداتك (الوضع الداكن/الفاتح، تفضيلات التخطيط)
• تخزين تفضيلات موافقة ملفات تعريف الارتباط
• تخصيص المحتوى بناءً على تفضيلاتك

لا نستخدم ملفات تعريف الارتباط من أجل:
• بيع بياناتك لأطراف ثالثة
• تتبعك عبر مواقع ويب أخرى
• الإعلانات المستهدفة (نحن لا نعرض إعلانات)`,
  },
  {
    id: "managing-cookies",
    titleEn: "Managing Cookies",
    titleAr: "إدارة ملفات تعريف الارتباط",
    contentEn: `You have the right to decide whether to accept or reject cookies. You can exercise your cookie preferences by:

Browser Settings:
Most web browsers allow you to control cookies through their settings. You can:
• Block all cookies
• Delete existing cookies
• Allow cookies only from specific websites
• Get notifications when cookies are set

Browser-Specific Instructions:

Google Chrome:
1. Click the three-dot menu → Settings
2. Privacy and security → Cookies and other site data
3. Choose your preferred cookie settings

Safari:
1. Safari → Preferences → Privacy
2. Choose your cookie blocking preferences

Firefox:
1. Menu → Options → Privacy & Security
2. Cookies and Site Data section
3. Choose your preferences

Microsoft Edge:
1. Settings → Cookies and site permissions
2. Manage and delete cookies and site data

Important Note: If you block or delete essential cookies, some features of our website may not work properly (such as staying logged in or remembering your language preference).

Opt-Out of Analytics:
To opt out of Google Analytics tracking, you can install the Google Analytics Opt-out Browser Add-on.`,
    contentAr: `لديك الحق في أن تقرر ما إذا كنت تقبل أو ترفض ملفات تعريف الارتباط. يمكنك ممارسة تفضيلات ملفات تعريف الارتباط الخاصة بك من خلال:

إعدادات المتصفح:
تسمح لك معظم متصفحات الويب بالتحكم في ملفات تعريف الارتباط من خلال إعداداتها. يمكنك:
• حظر جميع ملفات تعريف الارتباط
• حذف ملفات تعريف الارتباط الموجودة
• السماح بملفات تعريف الارتباط فقط من مواقع ويب محددة
• الحصول على إشعارات عند تعيين ملفات تعريف الارتباط

تعليمات خاصة بالمتصفح:

Google Chrome:
1. انقر على قائمة النقاط الثلاث ← الإعدادات
2. الخصوصية والأمان ← ملفات تعريف الارتباط وبيانات الموقع الأخرى
3. اختر إعدادات ملفات تعريف الارتباط المفضلة لديك

Safari:
1. Safari ← التفضيلات ← الخصوصية
2. اختر تفضيلات حظر ملفات تعريف الارتباط

Firefox:
1. القائمة ← الخيارات ← الخصوصية والأمان
2. قسم ملفات تعريف الارتباط وبيانات الموقع
3. اختر تفضيلاتك

Microsoft Edge:
1. الإعدادات ← ملفات تعريف الارتباط وأذونات الموقع
2. إدارة وحذف ملفات تعريف الارتباط وبيانات الموقع

ملاحظة مهمة: إذا قمت بحظر أو حذف ملفات تعريف الارتباط الأساسية، فقد لا تعمل بعض ميزات موقعنا بشكل صحيح (مثل البقاء مسجلاً للدخول أو تذكر تفضيل اللغة الخاص بك).

إلغاء الاشتراك في التحليلات:
لإلغاء الاشتراك في تتبع Google Analytics، يمكنك تثبيت إضافة إلغاء الاشتراك في Google Analytics للمتصفح.`,
  },
  {
    id: "updates",
    titleEn: "Changes to This Cookie Policy",
    titleAr: "التغييرات على سياسة ملفات تعريف الارتباط",
    contentEn: `We may update this Cookie Policy from time to time to reflect changes in our practices or for other operational, legal, or regulatory reasons.

When we make changes:
• We will update the "Last Updated" date at the top of this policy
• Significant changes will be notified through our website or via email
• Your continued use of our website after changes constitutes acceptance

We encourage you to review this Cookie Policy periodically to stay informed about how we use cookies.`,
    contentAr: `قد نقوم بتحديث سياسة ملفات تعريف الارتباط هذه من وقت لآخر لتعكس التغييرات في ممارساتنا أو لأسباب تشغيلية أو قانونية أو تنظيمية أخرى.

عندما نجري تغييرات:
• سنقوم بتحديث تاريخ "آخر تحديث" في أعلى هذه السياسة
• سيتم الإخطار بالتغييرات المهمة من خلال موقعنا أو عبر البريد الإلكتروني
• استمرارك في استخدام موقعنا بعد التغييرات يشكل قبولاً

نشجعك على مراجعة سياسة ملفات تعريف الارتباط هذه بشكل دوري للبقاء على اطلاع بكيفية استخدامنا لملفات تعريف الارتباط.`,
  },
  {
    id: "contact",
    titleEn: "Contact Us",
    titleAr: "اتصل بنا",
    contentEn: `If you have any questions about our use of cookies or this Cookie Policy, please contact us:

Email: ${SITE.contact.email}
WhatsApp: ${SITE.contact.whatsapp}
Address: ${SITE.contact.addressEn}

For privacy-related inquiries, you can also reach us at: privacy@mawidi.com`,
    contentAr: `إذا كان لديك أي أسئلة حول استخدامنا لملفات تعريف الارتباط أو سياسة ملفات تعريف الارتباط هذه، يرجى الاتصال بنا:

البريد الإلكتروني: ${SITE.contact.email}
واتساب: ${SITE.contact.whatsapp}
العنوان: ${SITE.contact.addressAr}

للاستفسارات المتعلقة بالخصوصية، يمكنك أيضًا التواصل معنا على: privacy@mawidi.com`,
  },
];

export default function CookiesPage({ params }: { params: { lang: Lang } }) {
  const [activeSection, setActiveSection] =
    useState<string>("what-are-cookies");
  const isAr = params.lang === "ar";
  const dir = isAr ? "rtl" : "ltr";

  useEffect(() => {
    const handleScroll = () => {
      const sections = COOKIE_SECTIONS.map((s) => s.id);
      const current = sections.find((id) => {
        const element = document.getElementById(id);
        if (element) {
          const rect = element.getBoundingClientRect();
          return rect.top <= 150 && rect.bottom >= 150;
        }
        return false;
      });
      if (current) setActiveSection(current);
    };

    window.addEventListener("scroll", handleScroll);
    return () => window.removeEventListener("scroll", handleScroll);
  }, []);

  const scrollToSection = (id: string) => {
    const element = document.getElementById(id);
    if (element) {
      const offset = 100;
      const elementPosition = element.getBoundingClientRect().top;
      const offsetPosition = elementPosition + window.pageYOffset - offset;
      window.scrollTo({ top: offsetPosition, behavior: "smooth" });
    }
  };

  return (
    <main className="min-h-screen bg-white" dir={dir}>
      {/* ══════════════════════════════════════════════════════════════════
          HERO SECTION - Editorial Style
      ══════════════════════════════════════════════════════════════════ */}
      <section className="relative py-24 md:py-32 bg-gradient-to-b from-white via-[#FAFAFA] to-white overflow-hidden">
        {/* Subtle grid pattern */}
        <div
          className="pointer-events-none absolute inset-0 opacity-[0.02]"
          aria-hidden="true"
          style={{
            backgroundImage: `
              linear-gradient(to right, #1E293B 1px, transparent 1px),
              linear-gradient(to bottom, #1E293B 1px, transparent 1px)
            `,
            backgroundSize: "80px 80px",
          }}
        />

        <div className="relative z-10 mx-auto max-w-7xl px-6">
          <div className="max-w-4xl">
            {/* Section number */}
            <div className="flex items-center gap-3 mb-8">
              <span
                className="text-[#10B981] font-mono text-sm tracking-wider"
                dir="ltr"
              >
                LEGAL
              </span>
              <div className="w-12 h-px bg-[#10B981]" />
              <span className="text-[#10B981] text-sm font-medium uppercase tracking-wider">
                {isAr ? "الخصوصية" : "Privacy"}
              </span>
            </div>

            {/* Headline */}
            <h1 className="text-5xl md:text-6xl lg:text-7xl font-bold text-[#1E293B] leading-[1.1] tracking-tight mb-8">
              {isAr ? "سياسة ملفات تعريف الارتباط" : "Cookie Policy"}
            </h1>

            {/* Subhead */}
            <p className="text-xl md:text-2xl text-[#64748B] leading-relaxed max-w-3xl mb-8">
              {isAr
                ? "فهم كيفية استخدامنا لملفات تعريف الارتباط لتحسين تجربتك وإدارة تفضيلاتك"
                : "Understanding how we use cookies to improve your experience and manage your preferences"}
            </p>

            {/* Last updated */}
            <div className="flex items-center gap-3 text-sm text-[#64748B]">
              <div className="w-1.5 h-1.5 bg-[#10B981]" />
              <span>
                {isAr ? "آخر تحديث:" : "Last Updated:"} {LAST_UPDATED}
              </span>
            </div>
          </div>
        </div>
      </section>

      {/* ══════════════════════════════════════════════════════════════════
          TL;DR SUMMARY - Editorial Style
      ══════════════════════════════════════════════════════════════════ */}
      <section className="py-16 bg-[#FAFAFA]">
        <div className="mx-auto max-w-7xl px-6">
          <div className="bg-white border-l-4 border-[#10B981] p-8 md:p-12">
            <div className="flex items-center gap-3 mb-8">
              <span className="text-[#10B981] font-mono text-sm" dir="ltr">
                TL;DR
              </span>
              <div className="w-8 h-px bg-[#10B981]" />
              <h2 className="text-2xl font-bold text-[#1E293B]">
                {isAr ? "الملخص السريع" : "Quick Summary"}
              </h2>
            </div>

            <div className="grid md:grid-cols-2 gap-12">
              {/* What We Do */}
              <div>
                <div className="flex items-center gap-2 mb-4">
                  <span className="w-1.5 h-1.5 bg-[#10B981]" />
                  <h3 className="font-bold text-[#1E293B] uppercase tracking-wider text-sm">
                    {isAr ? "ما نفعله" : "What We Do"}
                  </h3>
                </div>
                <ul className="space-y-3">
                  {[
                    isAr
                      ? "نستخدم ملفات تعريف الارتباط الأساسية للوظائف الأساسية"
                      : "Use essential cookies for core functionality",
                    isAr
                      ? "نجمع تحليلات مجهولة لتحسين خدماتنا"
                      : "Collect anonymous analytics to improve our services",
                    isAr
                      ? "نتذكر تفضيلاتك (اللغة، السمة)"
                      : "Remember your preferences (language, theme)",
                    isAr
                      ? "نسمح لك بإدارة إعدادات ملفات تعريف الارتباط"
                      : "Let you manage cookie settings",
                  ].map((item, idx) => (
                    <li key={idx} className="flex items-start gap-3">
                      <div className="w-1.5 h-1.5 bg-[#10B981] mt-2 flex-shrink-0" />
                      <span className="text-[#64748B]">{item}</span>
                    </li>
                  ))}
                </ul>
              </div>

              {/* What We Don't Do */}
              <div>
                <div className="flex items-center gap-2 mb-4">
                  <span className="w-1.5 h-1.5 bg-red-500" />
                  <h3 className="font-bold text-[#1E293B] uppercase tracking-wider text-sm">
                    {isAr ? "ما لا نفعله" : "What We Don't Do"}
                  </h3>
                </div>
                <ul className="space-y-3">
                  {[
                    isAr
                      ? "لا نبيع بياناتك لأطراف ثالثة"
                      : "Don't sell your data to third parties",
                    isAr
                      ? "لا نتتبعك عبر مواقع أخرى"
                      : "Don't track you across other websites",
                    isAr
                      ? "لا نعرض إعلانات مستهدفة"
                      : "Don't show targeted ads",
                    isAr
                      ? "لا نستخدم ملفات تعريف ارتباط غير ضرورية"
                      : "Don't use unnecessary cookies",
                  ].map((item, idx) => (
                    <li key={idx} className="flex items-start gap-3">
                      <div className="w-1.5 h-1.5 bg-red-500 mt-2 flex-shrink-0" />
                      <span className="text-[#64748B]">{item}</span>
                    </li>
                  ))}
                </ul>
              </div>
            </div>
          </div>
        </div>
      </section>

      {/* ══════════════════════════════════════════════════════════════════
          MAIN CONTENT WITH SIDEBAR
      ══════════════════════════════════════════════════════════════════ */}
      <section className="py-16 md:py-24 bg-white">
        <div className="mx-auto max-w-7xl px-6">
          <div className="flex flex-col lg:flex-row gap-12">
            {/* Sticky TOC Sidebar */}
            <aside className="lg:w-72 flex-shrink-0">
              <div className="sticky top-24">
                <div className="flex items-center gap-3 mb-6">
                  <span className="text-[#10B981] font-mono text-xs" dir="ltr">
                    NAV
                  </span>
                  <div className="w-8 h-px bg-[#10B981]" />
                </div>
                <h3 className="font-bold text-[#1E293B] mb-4">
                  {isAr ? "المحتويات" : "Contents"}
                </h3>
                <nav className="space-y-1">
                  {COOKIE_SECTIONS.map((section, idx) => (
                    <button
                      key={section.id}
                      onClick={() => scrollToSection(section.id)}
                      className={`group w-full flex items-center gap-3 py-3 text-left transition-colors duration-300 ${
                        activeSection === section.id
                          ? "text-[#10B981]"
                          : "text-[#64748B] hover:text-[#1E293B]"
                      }`}
                    >
                      <span className="font-mono text-xs" dir="ltr">
                        {String(idx + 1).padStart(2, "0")}
                      </span>
                      <span className="text-sm font-medium">
                        {isAr ? section.titleAr : section.titleEn}
                      </span>
                      <div
                        className={`h-px flex-1 transition-all duration-300 ${
                          activeSection === section.id
                            ? "bg-[#10B981] w-full"
                            : "bg-transparent w-0 group-hover:w-full group-hover:bg-slate-200"
                        }`}
                      />
                    </button>
                  ))}
                </nav>
              </div>
            </aside>

            {/* Main Content */}
            <main className="flex-1 min-w-0">
              {/* ══════════════════════════════════════════════════════════════════
                  COOKIE CATEGORIES
              ══════════════════════════════════════════════════════════════════ */}
              <div className="mb-16">
                <div className="flex items-start gap-4 mb-12">
                  <div className="flex items-center gap-3 pt-2">
                    <span
                      className="text-[#10B981] font-mono text-sm tracking-wider"
                      dir="ltr"
                    >
                      00
                    </span>
                    <div className="w-12 h-px bg-[#10B981]" />
                  </div>
                  <h2 className="text-3xl md:text-4xl font-bold text-[#1E293B]">
                    {isAr ? "فئات ملفات تعريف الارتباط" : "Cookie Categories"}
                  </h2>
                </div>

                <div className="grid md:grid-cols-2 gap-px bg-slate-200">
                  {COOKIE_CATEGORIES.map((category, idx) => (
                    <div
                      key={category.id}
                      className="group bg-white p-8 hover:bg-[#FAFAFA] transition-colors duration-300"
                    >
                      <div className="flex items-center gap-3 mb-4">
                        <span
                          className="text-[#10B981] font-mono text-xs"
                          dir="ltr"
                        >
                          {String(idx + 1).padStart(2, "0")}
                        </span>
                        <h3 className="text-xl font-bold text-[#1E293B]">
                          {isAr ? category.titleAr : category.titleEn}
                        </h3>
                      </div>

                      <p className="text-sm text-[#64748B] mb-6">
                        {isAr ? category.descriptionAr : category.descriptionEn}
                      </p>

                      {/* Cookie list */}
                      <div className="space-y-3">
                        {category.cookies.map((cookie, cookieIdx) => (
                          <div
                            key={cookieIdx}
                            className="flex items-start gap-3"
                          >
                            <div className="w-1.5 h-1.5 bg-[#10B981] mt-2 flex-shrink-0" />
                            <div>
                              <code className="text-xs text-[#10B981] bg-[#10B981]/10 px-2 py-0.5 font-mono">
                                {isAr ? cookie.nameAr : cookie.nameEn}
                              </code>
                              <p className="text-xs text-[#64748B] mt-1">
                                {isAr ? cookie.purposeAr : cookie.purposeEn}
                              </p>
                              <p className="text-xs text-[#94A3B8] mt-0.5">
                                {cookie.duration} • {cookie.type}
                              </p>
                            </div>
                          </div>
                        ))}
                      </div>

                      {/* Hover underline */}
                      <div className="w-0 group-hover:w-12 h-0.5 bg-[#10B981] mt-6 transition-all duration-300" />
                    </div>
                  ))}
                </div>
              </div>

              {/* ══════════════════════════════════════════════════════════════════
                  POLICY SECTIONS
              ══════════════════════════════════════════════════════════════════ */}
              {COOKIE_SECTIONS.map((section, idx) => (
                <section
                  key={section.id}
                  id={section.id}
                  className="mb-16 scroll-mt-24"
                >
                  <div className="flex items-start gap-4 mb-8">
                    <div className="flex items-center gap-3 pt-2">
                      <span
                        className="text-[#10B981] font-mono text-sm tracking-wider"
                        dir="ltr"
                      >
                        {String(idx + 1).padStart(2, "0")}
                      </span>
                      <div className="w-12 h-px bg-[#10B981]" />
                    </div>
                    <h2 className="text-3xl md:text-4xl font-bold text-[#1E293B]">
                      {isAr ? section.titleAr : section.titleEn}
                    </h2>
                  </div>

                  <div className="bg-[#FAFAFA] p-8 md:p-10">
                    <div className="text-[#64748B] whitespace-pre-line leading-relaxed">
                      {(isAr ? section.contentAr : section.contentEn)
                        .split("\n")
                        .map((line, lineIdx) => {
                          // Handle bullet points
                          if (line.trim().startsWith("•")) {
                            return (
                              <div
                                key={lineIdx}
                                className="flex items-start gap-3 my-2"
                              >
                                <div className="w-1.5 h-1.5 bg-[#10B981] mt-2 flex-shrink-0" />
                                <span>{line.trim().substring(1).trim()}</span>
                              </div>
                            );
                          }
                          // Handle headers (lines ending with :)
                          if (
                            line.trim().endsWith(":") &&
                            line.trim().length < 50
                          ) {
                            return (
                              <h4
                                key={lineIdx}
                                className="font-bold text-[#1E293B] mt-6 mb-3"
                              >
                                {line}
                              </h4>
                            );
                          }
                          // Handle numbered items
                          if (/^\d+\./.test(line.trim())) {
                            return (
                              <div
                                key={lineIdx}
                                className="flex items-start gap-3 my-2"
                              >
                                <span className="text-[#10B981] font-mono text-sm">
                                  {line.trim().match(/^\d+/)?.[0]}.
                                </span>
                                <span>
                                  {line.trim().replace(/^\d+\.\s*/, "")}
                                </span>
                              </div>
                            );
                          }
                          // Regular paragraphs
                          return line.trim() ? (
                            <p key={lineIdx} className="my-3">
                              {line}
                            </p>
                          ) : (
                            <div key={lineIdx} className="h-4" />
                          );
                        })}
                    </div>
                  </div>
                </section>
              ))}

              {/* ══════════════════════════════════════════════════════════════════
                  RELATED POLICIES
              ══════════════════════════════════════════════════════════════════ */}
              <section className="mb-16">
                <div className="flex items-start gap-4 mb-8">
                  <div className="flex items-center gap-3 pt-2">
                    <span
                      className="text-[#10B981] font-mono text-sm tracking-wider"
                      dir="ltr"
                    >
                      LINKS
                    </span>
                    <div className="w-12 h-px bg-[#10B981]" />
                  </div>
                  <h2 className="text-2xl font-bold text-[#1E293B]">
                    {isAr ? "سياسات ذات صلة" : "Related Policies"}
                  </h2>
                </div>

                <div className="grid md:grid-cols-3 gap-px bg-slate-200">
                  {[
                    {
                      href: `/${params.lang}/privacy`,
                      titleEn: "Privacy Policy",
                      titleAr: "سياسة الخصوصية",
                      descEn: "How we protect and use your data",
                      descAr: "كيف نحمي ونستخدم بياناتك",
                    },
                    {
                      href: `/${params.lang}/terms`,
                      titleEn: "Terms & Conditions",
                      titleAr: "الشروط والأحكام",
                      descEn: "Terms of using our services",
                      descAr: "شروط استخدام خدماتنا",
                    },
                    {
                      href: `/${params.lang}/help`,
                      titleEn: "Help Center",
                      titleAr: "مركز المساعدة",
                      descEn: "FAQs and support",
                      descAr: "الأسئلة الشائعة والدعم",
                    },
                  ].map((policy, idx) => (
                    <Link
                      key={idx}
                      href={policy.href}
                      className="group bg-white p-6 hover:bg-[#FAFAFA] transition-colors duration-300"
                    >
                      <div className="flex items-center gap-2 mb-2">
                        <span
                          className="text-[#10B981] font-mono text-xs"
                          dir="ltr"
                        >
                          {String.fromCharCode(65 + idx)}
                        </span>
                        <h4 className="font-bold text-[#1E293B] group-hover:text-[#10B981] transition-colors duration-300">
                          {isAr ? policy.titleAr : policy.titleEn}
                        </h4>
                      </div>
                      <p className="text-sm text-[#64748B]">
                        {isAr ? policy.descAr : policy.descEn}
                      </p>
                      <div className="w-0 group-hover:w-8 h-0.5 bg-[#10B981] mt-4 transition-all duration-300" />
                    </Link>
                  ))}
                </div>
              </section>
            </main>
          </div>
        </div>
      </section>

      {/* ══════════════════════════════════════════════════════════════════
          CONTACT CTA - Editorial Style
      ══════════════════════════════════════════════════════════════════ */}
      <section className="py-24 md:py-32 bg-[#FAFAFA]">
        <div className="mx-auto max-w-7xl px-6">
          <div className="bg-[#1E293B] p-12 md:p-20">
            <div className="max-w-3xl mx-auto text-center">
              {/* Section marker */}
              <div className="flex items-center justify-center gap-3 mb-8">
                <span
                  className="text-[#10B981] font-mono text-sm tracking-wider"
                  dir="ltr"
                >
                  CONTACT
                </span>
                <div className="w-12 h-px bg-[#10B981]" />
              </div>

              <h2 className="text-4xl md:text-5xl font-bold text-white leading-tight mb-6">
                {isAr
                  ? "هل لديك أسئلة حول ملفات تعريف الارتباط؟"
                  : "Questions About Cookies?"}
              </h2>
              <p className="text-lg md:text-xl text-white/70 mb-10">
                {isAr
                  ? "فريق الخصوصية لدينا موجود هنا للمساعدة. اتصل بنا للحصول على إجابات حول ملفات تعريف الارتباط أو الخصوصية أو أمان البيانات."
                  : "Our privacy team is here to help. Contact us for answers about cookies, privacy, or data security."}
              </p>

              <div className="flex flex-wrap items-center justify-center gap-4">
                <a
                  href={`mailto:${SITE.contact.email}`}
                  className="group relative inline-flex items-center gap-3 px-8 py-4 bg-[#10B981] text-white font-semibold overflow-hidden transition-all duration-300"
                >
                  <span className="relative z-10">{SITE.contact.email}</span>
                  <svg
                    className="relative z-10 h-5 w-5 transition-transform duration-300 group-hover:translate-x-1"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      strokeLinecap="round"
                      strokeLinejoin="round"
                      strokeWidth={2}
                      d={
                        isAr
                          ? "M19 12H5M12 5l-7 7 7 7"
                          : "M5 12h14M12 5l7 7-7 7"
                      }
                    />
                  </svg>
                  <div className="absolute inset-0 bg-[#059669] transform translate-y-full group-hover:translate-y-0 transition-transform duration-300" />
                </a>
                <a
                  href={`https://wa.me/${SITE.contact.whatsapp.replace(/\D/g, "")}`}
                  target="_blank"
                  rel="noopener noreferrer"
                  className="inline-flex items-center gap-2 px-8 py-4 border-2 border-white/30 text-white font-semibold hover:bg-white/10 transition-colors duration-300"
                >
                  {SITE.contact.whatsapp}
                </a>
              </div>
            </div>
          </div>
        </div>
      </section>
    </main>
  );
}
