"use client";

import { useState, useEffect, useMemo } from "react";
import { useParams } from "next/navigation";
import Link from "next/link";
import { CheckCircle, ArrowRight, Home, FileText, Send, Sparkles } from "lucide-react";

// PUBLIC application forms accessed via direct link or QR code
const categories: {[key: string]: string} = {
  // Medical & Internship
  "internship": "المتقدمين للإمتياز",
  "medical-training": "طب تدريب",
  "medical_training": "طب تدريب",
  "medical-sec": "سكرتارية طبية",
  "medical_sec": "سكرتارية طبية",
  "medical-labs": "مختبرات طبية",
  "medical_labs": "مختبرات طبية",
  "medical-engineering": "هندسة طبية",
  "biomedical-engineering": "هندسة طبية",
  "volunteer-medicine": "طب تطوع",

  // Nursing
  "nursing": "التمريض",
  "nursing-training": "تمريض تدريب",
  "nursing-internship": "تمريض امتياز",
  "volunteer-nursing": "تمريض تطوع",

  // Universities & Contracted Doctors & Allied Health Trainers
  "university-nursing-trainers": "تقديم طلبات لتدريب طلاب التمريض في الجامعات",
  "university -nursing-trainers": "تقديم طلبات لتدريب طلاب التمريض في الجامعات",
  "university%20-nursing-trainers": "تقديم طلبات لتدريب طلاب التمريض في الجامعات",
  "university.nursing.trainers": "تقديم طلبات لتدريب طلاب التمريض في الجامعات",
  "contracted-doctors": "الأطباء المتعاقدون مع الجامعات",
  "contracted_doctors": "الأطباء المتعاقدون مع الجامعات",
  "radiology-trainers": "مدربي أشعة",
  "physical-therapy-trainers": "مدربي علاج طبيعي",
  "lab-trainers": "مدربي مختبر",
  "pharmacy-trainers": "مدربي صيدلية",
  "occupational-therapy-trainers": "مدربي علاج وظيفي",
  "nutrition-trainers": "مدربي تغذية",
  "medical-engineering-trainers": "مدربي هندسة طبية",

  // Allied Health
  "physical-therapy": "العلاج الطبيعي",
  "physical-therapy-training": "علاج طبيعي تدريب",
  "physical-therapy-internship": "علاج طبيعي امتياز",
  "occupational-therapy": "العلاج الوظيفي",
  "radiology": "أشعة",
  "nutrition": "تغذية",
  "ambulance-officers": "تدريب ضباط الإسعاف",
  "social-service": "خدمة اجتماعية",
  "community-work": "العمل المجتمعي",
  "psychological-counseling": "إرشاد وصحة نفسية",
  "mental-health": "إرشاد وصحة نفسية",
  "counseling-mental-health": "إرشاد وصحة نفسية",
  "psychological_counseling": "إرشاد وصحة نفسية",

  // Administration & Support
  "admin": "إدارة",
  "accounting": "المحاسبة",
  "kitchen": "المطبخ",
};

// Categories that are volunteer-type (not internship)
const volunteerCategories = ['volunteer-medicine', 'social-service', 'volunteer-nursing', 'community-work'];

// Nursing-specific categories
const nursingTrainingCategory = 'nursing-training';
const nursingInternshipCategory = 'nursing-internship';
const nursingCategories = [nursingTrainingCategory, nursingInternshipCategory];

export interface TrainerOption {
  name: string;
  department: string;
  university: string;
  category: string;
  specialtyGroup: 'nursing' | 'radiology' | 'lab' | 'pt' | 'pharmacy' | 'nutrition' | 'biomedical' | 'ot' | 'other';
}

export const DEFAULT_ACCREDITED_TRAINERS: TrainerOption[] = [
  // مدربو تمريض الجامعات الشريكة
  { name: 'باسل ماهر نواف عمرو', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'بلال رباح محمد امواس /مناصرة', department: 'تدريب تمريض الجامعات', university: 'الكلية الذكية الجامعية للتعليم الحديث', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'مهران درويش', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'مهران داود احمد درويش', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'عمر رجوب', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'عمر محمد محمود ارجوب', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'طلحة دبابسة', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'طلحه عمر محمد خشان', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'محمد راتب جلق', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'محمود فخري عبد الواحد العملة', department: 'تدريب تمريض الجامعات', university: 'الكلية الذكية الجامعية للتعليم الحديث', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'سلام نسيم محمود ابو عياش', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'المنتصر بالله عماد سعدي ادعيس', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'سلامه يوسف سلامه طميزي', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'سلامه يوسف سلامه طميزة', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'نور الدين محمود حسن عواودة', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'عباده عايش حسن زهور', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'أحمد موسى عيسى ابو عواد', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'احمد موسى عيسى ابوعواد', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'محمد عادل يوسف ابوريان', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'أحمد بجالي', department: 'تدريب تمريض الجامعات', university: 'جامعة الخليل', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'حاتم رائد محمد خلاف', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'جبريل سليمان ابراهيم الهرينات', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'مؤمن خالد حسن السماحين', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'سلسبيل محمد ايوب مناصره', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'سمر اكرم حسين ابو رميله', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'معاذ محمد عبد المغني حلاحله', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'ضياء عبد الحليم يوسف عواوده', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'ريا محمد بدر قرعيش', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'لؤي مازن طلب أبوشرخ', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'حذيفة محمد حسن هرينات', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'ساجده محمد علي عايش', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'علي عزام جابر عصافرة', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'عروبة ماجد عبد الفتاح شلالفة', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'عثمان احمد عثمان عمرو', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'ولاء محمد سلمان نعمان سكافي', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'ريم عمار محمد طباخي', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'ياسمين حسين يحيى النتشه', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'مجد احمد محمود سماره', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'Saqer jameel yahia abu safi', department: 'تدريب تمريض الجامعات', university: 'جامعة الخليل', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'أريج يحيى عبد القادر الكفراوي', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'أسماء زياد عبد الحميد الصبارنه', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'أسيل محمد عبد القادر عصافرة', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'أنصار الاسلام يوسف احمد الغنيمات', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'أنوار محمد حمدان صليبي', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'أويس هشام محمد المحاريق', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'أيمن إبراهيم محمد سلامة', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'احلام عصام هاشم معيوي', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'اسيل اسامة سعيد ادعيس', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'الاء ابراهيم سالم فراشات', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'الاء شفيق عيسى أبو عفيفه', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'امال خالد احمد محمد عودة', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'امال ضرار شحاده السلامين', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'امير حمدي عيد النتشه', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'انس عايد محمد ابو اسنينه', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'ايمان هيثم شريتح', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'بداية أيمن محمد المصري', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'براءه جمال عثمان كرامه', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'تاله سمير توفيق عمرو', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'تسنيم عرفات شاهر أبوعلان', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'جازيه اسحق علي حسين', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'جنات عبدالله عبدالله الخضور', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'جنات فخري عبد الحكيم محتسب', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'جنى محمد حج يوسف شوامرة', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'رؤى امجد محمود اسليمية', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'لمار سفيان شريف عوض', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },
  { name: 'ميس مضر محمود غنيمات', department: 'تدريب تمريض الجامعات', university: 'جامعة بوليتكنك فلسطين', category: 'university-nursing-trainers', specialtyGroup: 'nursing' },

  // مدربو ومسؤولو قسم الأشعة والتصوير الطبي
  { name: 'ضياء الدين يوسف محمد هيموني', department: 'قسم الأشعة والتصوير الطبي', university: 'مستشفى الهلال الأحمر', category: 'radiology-trainers', specialtyGroup: 'radiology' },
  { name: 'مشرف قسم الأشعة والتصوير الطبي', department: 'قسم الأشعة والتصوير الطبي', university: 'مستشفى الهلال الأحمر', category: 'radiology-trainers', specialtyGroup: 'radiology' },

  // الأطباء المتعاقدون مع الجامعات
  { name: 'تامر عثمان محمد (شاور تميمي)', department: 'الأطباء المتعاقدون', university: 'جامعة الخليل / مستشفى الهلال الأحمر', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'فوزي مازن محمدفوزي ابو نجمة', department: 'الأطباء المتعاقدون', university: 'جامعة الخليل / مستشفى الهلال الأحمر', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'شريف محمد يوسف حسان', department: 'الأطباء المتعاقدون', university: 'جامعة الخليل', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'إياد عصام عيسى جابر', department: 'الأطباء المتعاقدون', university: 'جامعة بوليتكنك فلسطين', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'خليل نهاد مصطفى ابو زينة', department: 'الأطباء المتعاقدون', university: 'جامعة الخليل', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'رضوان سليمان رمضان أبو كرش', department: 'الأطباء المتعاقدون', university: 'جامعة الخليل', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'عبدالحق محمود محمد شاهين', department: 'الأطباء المتعاقدون', university: 'جامعة بوليتكنك فلسطين', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'جهاد محمد عبدالعزيز امحيميد', department: 'الأطباء المتعاقدون', university: 'جامعة بوليتكنك فلسطين', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'اسماعيل محمد اسماعيل ارزيقات', department: 'الأطباء المتعاقدون', university: 'جامعة الخليل', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'عبدالرزاق عبدالفتاح حسن ابومياله', department: 'الأطباء المتعاقدون', university: 'جامعة القدس - أبو ديس', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'احمد عمر حسين', department: 'الأطباء المتعاقدون', university: 'جامعة الخليل', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'عبد الله تيسير محمود حسن', department: 'الأطباء المتعاقدون', university: 'جامعة الخليل', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'الاء سعيد سعد عباس', department: 'الأطباء المتعاقدون', university: 'جامعة الخليل', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'وليد سعيد موسى التميمي', department: 'الأطباء المتعاقدون', university: 'جامعة بوليتكنك فلسطين', category: 'contracted-doctors', specialtyGroup: 'other' },
  { name: 'اسامه محمد محمود عطاونه', department: 'الأطباء المتعاقدون', university: 'جامعة بوليتكنك فلسطين', category: 'contracted-doctors', specialtyGroup: 'other' },

  // مدربو ومسؤولو الأقسام الطبية المساندة
  { name: 'مشرف قسم المختبرات الطبية', department: 'قسم المختبرات الطبية', university: 'مستشفى الهلال الأحمر', category: 'lab-trainers', specialtyGroup: 'lab' },
  { name: 'مشرف قسم العلاج الطبيعي', department: 'قسم العلاج الطبيعي والتأهيل', university: 'مستشفى الهلال الأحمر', category: 'physical-therapy-trainers', specialtyGroup: 'pt' },
  { name: 'مشرف قسم الصيدلة السريرية', department: 'قسم الصيدلة السريرية', university: 'مستشفى الهلال الأحمر', category: 'pharmacy-trainers', specialtyGroup: 'pharmacy' },
  { name: 'مشرف قسم التغذية السريرية', department: 'قسم التغذية السريرية', university: 'مستشفى الهلال الأحمر', category: 'nutrition-trainers', specialtyGroup: 'nutrition' },
  { name: 'مشرف قسم العلاج الوظيفي', department: 'قسم العلاج الوظيفي', university: 'مستشفى الهلال الأحمر', category: 'occupational-therapy-trainers', specialtyGroup: 'ot' },
  { name: 'مشرف قسم الهندسة الطبية', department: 'قسم الهندسة الطبية', university: 'مستشفى الهلال الأحمر', category: 'medical-engineering-trainers', specialtyGroup: 'biomedical' },
  { name: 'مشرف التدريب الميداني للإسعاف والطوارئ', department: 'تدريب ضباط الإسعاف', university: 'مستشفى الهلال الأحمر', category: 'ambulance-officers', specialtyGroup: 'other' }
];


interface DepartmentTheme {
  primary: string;
  gradientBg: string;
  cardBorder: string;
  cardShadow: string;
  badgeBg: string;
  badgeBorder: string;
  badgeColor: string;
  badgeIcon: string;
  badgeSubtitle: string;
  photoBorder: string;
  submitGradient: string;
  submitShadow: string;
  ambient1: string;
  ambient2: string;
}

const defaultDepartmentTheme: DepartmentTheme = {
  primary: '#2563eb',
  gradientBg: 'linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%)',
  cardBorder: '1px solid #e2e8f0',
  cardShadow: '0 25px 50px -12px rgba(0,0,0,0.35)',
  badgeBg: 'rgba(255,255,255,0.12)',
  badgeBorder: '1.5px solid rgba(255,215,0,0.4)',
  badgeColor: '#ffffff',
  badgeIcon: '📋',
  badgeSubtitle: '',
  photoBorder: '#0284c7',
  submitGradient: 'linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%)',
  submitShadow: '0 10px 25px rgba(37, 99, 235, 0.35)',
  ambient1: 'rgba(59, 130, 246, 0.15)',
  ambient2: 'rgba(16, 185, 129, 0.1)'
};

const departmentThemes: { [key: string]: DepartmentTheme } = {
  // Medical Internship (Prestige Navy & Gold)
  "internship": {
    primary: '#1e3a8a',
    gradientBg: 'linear-gradient(135deg, #091224 0%, #172554 50%, #080f1e 100%)',
    cardBorder: '2px solid rgba(59, 130, 246, 0.35)',
    cardShadow: '0 25px 60px -12px rgba(30, 58, 138, 0.45)',
    badgeBg: 'linear-gradient(135deg, rgba(30, 58, 138, 0.4), rgba(59, 130, 246, 0.25))',
    badgeBorder: '1.5px solid rgba(245, 158, 11, 0.7)',
    badgeColor: '#fef08a',
    badgeIcon: '🩺',
    badgeSubtitle: 'برنامج الامتياز الطبي العام — أطباء الامتياز البشري',
    photoBorder: '#2563eb',
    submitGradient: 'linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #1d4ed8 100%)',
    submitShadow: '0 10px 25px rgba(37, 99, 235, 0.4)',
    ambient1: 'rgba(37, 99, 235, 0.22)',
    ambient2: 'rgba(245, 158, 11, 0.18)'
  },
  // Medical Training (Sapphire Blue)
  "medical-training": {
    primary: '#0369a1',
    gradientBg: 'linear-gradient(135deg, #081d33 0%, #0c4a6e 50%, #061526 100%)',
    cardBorder: '2px solid rgba(14, 165, 233, 0.35)',
    cardShadow: '0 25px 60px -12px rgba(2, 132, 199, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(3, 105, 161, 0.4), rgba(14, 165, 233, 0.2))',
    badgeBorder: '1.5px solid rgba(56, 189, 248, 0.7)',
    badgeColor: '#e0f2fe',
    badgeIcon: '🥼',
    badgeSubtitle: 'برنامج التدريب السريري التخصصي للأطباء',
    photoBorder: '#0284c7',
    submitGradient: 'linear-gradient(135deg, #0369a1 0%, #0284c7 100%)',
    submitShadow: '0 10px 25px rgba(2, 132, 199, 0.4)',
    ambient1: 'rgba(14, 165, 233, 0.2)',
    ambient2: 'rgba(3, 105, 161, 0.18)'
  },
  "medical_training": {
    primary: '#0369a1',
    gradientBg: 'linear-gradient(135deg, #081d33 0%, #0c4a6e 50%, #061526 100%)',
    cardBorder: '2px solid rgba(14, 165, 233, 0.35)',
    cardShadow: '0 25px 60px -12px rgba(2, 132, 199, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(3, 105, 161, 0.4), rgba(14, 165, 233, 0.2))',
    badgeBorder: '1.5px solid rgba(56, 189, 248, 0.7)',
    badgeColor: '#e0f2fe',
    badgeIcon: '🥼',
    badgeSubtitle: 'برنامج التدريب السريري التخصصي للأطباء',
    photoBorder: '#0284c7',
    submitGradient: 'linear-gradient(135deg, #0369a1 0%, #0284c7 100%)',
    submitShadow: '0 10px 25px rgba(2, 132, 199, 0.4)',
    ambient1: 'rgba(14, 165, 233, 0.2)',
    ambient2: 'rgba(3, 105, 161, 0.18)'
  },
  // Radiology (High-tech Cyan & Electric Blue)
  "radiology": {
    primary: '#0891b2',
    gradientBg: 'linear-gradient(135deg, #031c28 0%, #083344 50%, #02121a 100%)',
    cardBorder: '2px solid rgba(6, 182, 212, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(6, 182, 212, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(8, 145, 178, 0.4), rgba(6, 182, 212, 0.25))',
    badgeBorder: '1.5px solid rgba(6, 182, 212, 0.8)',
    badgeColor: '#cffafe',
    badgeIcon: '☢️',
    badgeSubtitle: 'قسم الأشعة والتصوير الطبي التخصصي (X-Ray, CT, MRI, Ultrasound)',
    photoBorder: '#06b6d4',
    submitGradient: 'linear-gradient(135deg, #0891b2 0%, #06b6d4 100%)',
    submitShadow: '0 10px 25px rgba(6, 182, 212, 0.4)',
    ambient1: 'rgba(6, 182, 212, 0.25)',
    ambient2: 'rgba(14, 165, 233, 0.18)'
  },
  // Physical Therapy (Vitality Emerald & Mint)
  "physical-therapy": {
    primary: '#059669',
    gradientBg: 'linear-gradient(135deg, #02251d 0%, #064e3b 50%, #011b15 100%)',
    cardBorder: '2px solid rgba(16, 185, 129, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(16, 185, 129, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(5, 150, 105, 0.4), rgba(16, 185, 129, 0.25))',
    badgeBorder: '1.5px solid rgba(52, 211, 153, 0.8)',
    badgeColor: '#d1fae5',
    badgeIcon: '🏃‍♂️',
    badgeSubtitle: 'قسم العلاج الطبيعي والتأهيل الحركي والفيزيائي',
    photoBorder: '#10b981',
    submitGradient: 'linear-gradient(135deg, #059669 0%, #10b981 100%)',
    submitShadow: '0 10px 25px rgba(16, 185, 129, 0.4)',
    ambient1: 'rgba(16, 185, 129, 0.25)',
    ambient2: 'rgba(52, 211, 153, 0.15)'
  },
  "physical-therapy-training": {
    primary: '#16a34a',
    gradientBg: 'linear-gradient(135deg, #02251d 0%, #064e3b 50%, #011b15 100%)',
    cardBorder: '2px solid rgba(22, 163, 74, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(22, 163, 74, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(22, 163, 74, 0.4), rgba(34, 197, 94, 0.25))',
    badgeBorder: '1.5px solid rgba(74, 222, 128, 0.8)',
    badgeColor: '#dcfce7',
    badgeIcon: '🏃‍♂️',
    badgeSubtitle: 'قسم العلاج الطبيعي والتأهيل الحركي والفيزيائي - برنامج التدريب الميداني',
    photoBorder: '#22c55e',
    submitGradient: 'linear-gradient(135deg, #16a34a 0%, #22c55e 100%)',
    submitShadow: '0 10px 25px rgba(22, 163, 74, 0.4)',
    ambient1: 'rgba(22, 163, 74, 0.25)',
    ambient2: 'rgba(74, 222, 128, 0.15)'
  },
  "physical-therapy-internship": {
    primary: '#059669',
    gradientBg: 'linear-gradient(135deg, #02251d 0%, #064e3b 50%, #011b15 100%)',
    cardBorder: '2px solid rgba(16, 185, 129, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(16, 185, 129, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(5, 150, 105, 0.4), rgba(16, 185, 129, 0.25))',
    badgeBorder: '1.5px solid rgba(52, 211, 153, 0.8)',
    badgeColor: '#d1fae5',
    badgeIcon: '🎓',
    badgeSubtitle: 'قسم العلاج الطبيعي والتأهيل الحركي والفيزيائي - برنامج سنة الامتياز',
    photoBorder: '#10b981',
    submitGradient: 'linear-gradient(135deg, #059669 0%, #10b981 100%)',
    submitShadow: '0 10px 25px rgba(16, 185, 129, 0.4)',
    ambient1: 'rgba(16, 185, 129, 0.25)',
    ambient2: 'rgba(52, 211, 153, 0.15)'
  },
  // Occupational Therapy (Warm Amber & Terracotta)
  "occupational-therapy": {
    primary: '#ea580c',
    gradientBg: 'linear-gradient(135deg, #240b03 0%, #431407 50%, #180602 100%)',
    cardBorder: '2px solid rgba(249, 115, 22, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(249, 115, 22, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(234, 88, 12, 0.4), rgba(249, 115, 22, 0.25))',
    badgeBorder: '1.5px solid rgba(251, 146, 60, 0.8)',
    badgeColor: '#ffedd5',
    badgeIcon: '🤲',
    badgeSubtitle: 'قسم العلاج الوظيفي والتأهيل العصبي والمهني',
    photoBorder: '#f97316',
    submitGradient: 'linear-gradient(135deg, #ea580c 0%, #f97316 100%)',
    submitShadow: '0 10px 25px rgba(249, 115, 22, 0.4)',
    ambient1: 'rgba(249, 115, 22, 0.25)',
    ambient2: 'rgba(234, 88, 12, 0.18)'
  },
  // Medical Labs (Bio-Purple & Violet)
  "medical-labs": {
    primary: '#7c3aed',
    gradientBg: 'linear-gradient(135deg, #180733 0%, #2e1065 50%, #110524 100%)',
    cardBorder: '2px solid rgba(168, 85, 247, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(124, 58, 237, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(124, 58, 237, 0.4), rgba(168, 85, 247, 0.25))',
    badgeBorder: '1.5px solid rgba(192, 132, 252, 0.8)',
    badgeColor: '#f3e8ff',
    badgeIcon: '🔬',
    badgeSubtitle: 'قسم المختبرات والتحاليل الطبية وبنك الدم',
    photoBorder: '#a855f7',
    submitGradient: 'linear-gradient(135deg, #7c3aed 0%, #a855f7 100%)',
    submitShadow: '0 10px 25px rgba(124, 58, 237, 0.4)',
    ambient1: 'rgba(168, 85, 247, 0.25)',
    ambient2: 'rgba(124, 58, 237, 0.2)'
  },
  "medical_labs": {
    primary: '#7c3aed',
    gradientBg: 'linear-gradient(135deg, #180733 0%, #2e1065 50%, #110524 100%)',
    cardBorder: '2px solid rgba(168, 85, 247, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(124, 58, 237, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(124, 58, 237, 0.4), rgba(168, 85, 247, 0.25))',
    badgeBorder: '1.5px solid rgba(192, 132, 252, 0.8)',
    badgeColor: '#f3e8ff',
    badgeIcon: '🔬',
    badgeSubtitle: 'قسم المختبرات والتحاليل الطبية وبنك الدم',
    photoBorder: '#a855f7',
    submitGradient: 'linear-gradient(135deg, #7c3aed 0%, #a855f7 100%)',
    submitShadow: '0 10px 25px rgba(124, 58, 237, 0.4)',
    ambient1: 'rgba(168, 85, 247, 0.25)',
    ambient2: 'rgba(124, 58, 237, 0.2)'
  },
  // Medical Secretary (Executive Indigo & Slate)
  "medical-sec": {
    primary: '#4f46e5',
    gradientBg: 'linear-gradient(135deg, #0e0d2b 0%, #1e1b4b 50%, #0a091f 100%)',
    cardBorder: '2px solid rgba(99, 102, 241, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(79, 70, 229, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(79, 70, 229, 0.4), rgba(99, 102, 241, 0.25))',
    badgeBorder: '1.5px solid rgba(129, 140, 248, 0.8)',
    badgeColor: '#e0e7ff',
    badgeIcon: '📁',
    badgeSubtitle: 'قسم السكرتارية الطبية وإدارة السجلات والتوثيق الصحي',
    photoBorder: '#6366f1',
    submitGradient: 'linear-gradient(135deg, #4f46e5 0%, #6366f1 100%)',
    submitShadow: '0 10px 25px rgba(79, 70, 229, 0.4)',
    ambient1: 'rgba(99, 102, 241, 0.25)',
    ambient2: 'rgba(79, 70, 229, 0.18)'
  },
  "medical_sec": {
    primary: '#4f46e5',
    gradientBg: 'linear-gradient(135deg, #0e0d2b 0%, #1e1b4b 50%, #0a091f 100%)',
    cardBorder: '2px solid rgba(99, 102, 241, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(79, 70, 229, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(79, 70, 229, 0.4), rgba(99, 102, 241, 0.25))',
    badgeBorder: '1.5px solid rgba(129, 140, 248, 0.8)',
    badgeColor: '#e0e7ff',
    badgeIcon: '📁',
    badgeSubtitle: 'قسم السكرتارية الطبية وإدارة السجلات والتوثيق الصحي',
    photoBorder: '#6366f1',
    submitGradient: 'linear-gradient(135deg, #4f46e5 0%, #6366f1 100%)',
    submitShadow: '0 10px 25px rgba(79, 70, 229, 0.4)',
    ambient1: 'rgba(99, 102, 241, 0.25)',
    ambient2: 'rgba(79, 70, 229, 0.18)'
  },
  // Biomedical Engineering (Steel Blue & Cyan Tech)
  "biomedical-engineering": {
    primary: '#0284c7',
    gradientBg: 'linear-gradient(135deg, #051a29 0%, #075985 50%, #03121d 100%)',
    cardBorder: '2px solid rgba(14, 165, 233, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(2, 132, 199, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(2, 132, 199, 0.4), rgba(14, 165, 233, 0.25))',
    badgeBorder: '1.5px solid rgba(56, 189, 248, 0.8)',
    badgeColor: '#e0f2fe',
    badgeIcon: '⚙️',
    badgeSubtitle: 'قسم الهندسة الطبية وصيانة ومعايرة الأجهزة السريرية',
    photoBorder: '#0ea5e9',
    submitGradient: 'linear-gradient(135deg, #0284c7 0%, #0ea5e9 100%)',
    submitShadow: '0 10px 25px rgba(2, 132, 199, 0.4)',
    ambient1: 'rgba(14, 165, 233, 0.25)',
    ambient2: 'rgba(2, 132, 199, 0.18)'
  },
  "medical-engineering": {
    primary: '#0284c7',
    gradientBg: 'linear-gradient(135deg, #051a29 0%, #075985 50%, #03121d 100%)',
    cardBorder: '2px solid rgba(14, 165, 233, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(2, 132, 199, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(2, 132, 199, 0.4), rgba(14, 165, 233, 0.25))',
    badgeBorder: '1.5px solid rgba(56, 189, 248, 0.8)',
    badgeColor: '#e0f2fe',
    badgeIcon: '⚙️',
    badgeSubtitle: 'قسم الهندسة الطبية وصيانة ومعايرة الأجهزة السريرية',
    photoBorder: '#0ea5e9',
    submitGradient: 'linear-gradient(135deg, #0284c7 0%, #0ea5e9 100%)',
    submitShadow: '0 10px 25px rgba(2, 132, 199, 0.4)',
    ambient1: 'rgba(14, 165, 233, 0.25)',
    ambient2: 'rgba(2, 132, 199, 0.18)'
  },
  // Clinical Nutrition (Fresh Lime & Green)
  "nutrition": {
    primary: '#16a34a',
    gradientBg: 'linear-gradient(135deg, #042110 0%, #14532d 50%, #02170b 100%)',
    cardBorder: '2px solid rgba(34, 197, 94, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(22, 163, 74, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(22, 163, 74, 0.4), rgba(34, 197, 94, 0.25))',
    badgeBorder: '1.5px solid rgba(74, 222, 128, 0.8)',
    badgeColor: '#dcfce7',
    badgeIcon: '🥗',
    badgeSubtitle: 'قسم التغذية السريرية والعلاجية وتخطيط الوجبات',
    photoBorder: '#22c55e',
    submitGradient: 'linear-gradient(135deg, #16a34a 0%, #22c55e 100%)',
    submitShadow: '0 10px 25px rgba(22, 163, 74, 0.4)',
    ambient1: 'rgba(34, 197, 94, 0.25)',
    ambient2: 'rgba(22, 163, 74, 0.18)'
  },
  // Ambulance Officers (Emergency Red & Crimson)
  "ambulance-officers": {
    primary: '#dc2626',
    gradientBg: 'linear-gradient(135deg, #2b0505 0%, #450a0a 50%, #1c0303 100%)',
    cardBorder: '2px solid rgba(239, 68, 68, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(220, 38, 38, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(220, 38, 38, 0.4), rgba(239, 68, 68, 0.25))',
    badgeBorder: '1.5px solid rgba(248, 113, 113, 0.8)',
    badgeColor: '#fee2e2',
    badgeIcon: '🚑',
    badgeSubtitle: 'برنامج تدريب وتأهيل ضباط الإسعاف وخدمات الطوارئ الميدانية',
    photoBorder: '#ef4444',
    submitGradient: 'linear-gradient(135deg, #dc2626 0%, #ef4444 100%)',
    submitShadow: '0 10px 25px rgba(220, 38, 38, 0.4)',
    ambient1: 'rgba(239, 68, 68, 0.25)',
    ambient2: 'rgba(220, 38, 38, 0.18)'
  },
  // Nursing Training & Internship (Ocean Sky Blue & Teal)
  "nursing-training": {
    primary: '#0284c7',
    gradientBg: 'linear-gradient(135deg, #051d2e 0%, #0369a1 50%, #031420 100%)',
    cardBorder: '2px solid rgba(56, 189, 248, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(2, 132, 199, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(2, 132, 199, 0.4), rgba(56, 189, 248, 0.25))',
    badgeBorder: '1.5px solid rgba(56, 189, 248, 0.8)',
    badgeColor: '#e0f2fe',
    badgeIcon: '🩺',
    badgeSubtitle: 'برنامج تدريب طلاب التمريض السريري',
    photoBorder: '#38bdf8',
    submitGradient: 'linear-gradient(135deg, #0284c7 0%, #38bdf8 100%)',
    submitShadow: '0 10px 25px rgba(2, 132, 199, 0.4)',
    ambient1: 'rgba(56, 189, 248, 0.25)',
    ambient2: 'rgba(2, 132, 199, 0.18)'
  },
  "nursing-internship": {
    primary: '#0d9488',
    gradientBg: 'linear-gradient(135deg, #042320 0%, #115e59 50%, #021715 100%)',
    cardBorder: '2px solid rgba(20, 184, 166, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(13, 148, 136, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(13, 148, 136, 0.4), rgba(20, 184, 166, 0.25))',
    badgeBorder: '1.5px solid rgba(45, 212, 191, 0.8)',
    badgeColor: '#ccfbf1',
    badgeIcon: '🩺',
    badgeSubtitle: 'برنامج امتياز التمريض العام التخصصي',
    photoBorder: '#14b8a6',
    submitGradient: 'linear-gradient(135deg, #0d9488 0%, #14b8a6 100%)',
    submitShadow: '0 10px 25px rgba(13, 148, 136, 0.4)',
    ambient1: 'rgba(20, 184, 166, 0.25)',
    ambient2: 'rgba(13, 148, 136, 0.18)'
  },
  "nursing": {
    primary: '#0284c7',
    gradientBg: 'linear-gradient(135deg, #051d2e 0%, #0369a1 50%, #031420 100%)',
    cardBorder: '2px solid rgba(56, 189, 248, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(2, 132, 199, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(2, 132, 199, 0.4), rgba(56, 189, 248, 0.25))',
    badgeBorder: '1.5px solid rgba(56, 189, 248, 0.8)',
    badgeColor: '#e0f2fe',
    badgeIcon: '🩺',
    badgeSubtitle: 'برنامج التمريض والرعاية التمريضية',
    photoBorder: '#38bdf8',
    submitGradient: 'linear-gradient(135deg, #0284c7 0%, #38bdf8 100%)',
    submitShadow: '0 10px 25px rgba(2, 132, 199, 0.4)',
    ambient1: 'rgba(56, 189, 248, 0.25)',
    ambient2: 'rgba(2, 132, 199, 0.18)'
  },
  // Volunteer & Community
  "volunteer-medicine": {
    primary: '#2563eb',
    gradientBg: 'linear-gradient(135deg, #0c1c38 0%, #1e40af 50%, #081326 100%)',
    cardBorder: '2px solid rgba(96, 165, 250, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(37, 99, 235, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(37, 99, 235, 0.4), rgba(96, 165, 250, 0.25))',
    badgeBorder: '1.5px solid rgba(96, 165, 250, 0.8)',
    badgeColor: '#dbeafe',
    badgeIcon: '🤝',
    badgeSubtitle: 'برنامج التطوع الطبي الإنساني',
    photoBorder: '#60a5fa',
    submitGradient: 'linear-gradient(135deg, #2563eb 0%, #60a5fa 100%)',
    submitShadow: '0 10px 25px rgba(37, 99, 235, 0.4)',
    ambient1: 'rgba(96, 165, 250, 0.25)',
    ambient2: 'rgba(37, 99, 235, 0.18)'
  },
  "volunteer-nursing": {
    primary: '#0d9488',
    gradientBg: 'linear-gradient(135deg, #042320 0%, #0f766e 50%, #021715 100%)',
    cardBorder: '2px solid rgba(20, 184, 166, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(13, 148, 136, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(13, 148, 136, 0.4), rgba(20, 184, 166, 0.25))',
    badgeBorder: '1.5px solid rgba(45, 212, 191, 0.8)',
    badgeColor: '#ccfbf1',
    badgeIcon: '🤝',
    badgeSubtitle: 'برنامج التطوع في الرعاية التمريضية',
    photoBorder: '#14b8a6',
    submitGradient: 'linear-gradient(135deg, #0d9488 0%, #14b8a6 100%)',
    submitShadow: '0 10px 25px rgba(13, 148, 136, 0.4)',
    ambient1: 'rgba(20, 184, 166, 0.25)',
    ambient2: 'rgba(13, 148, 136, 0.18)'
  },
  "social-service": {
    primary: '#854d0e',
    gradientBg: 'linear-gradient(135deg, #291804 0%, #713f12 50%, #1a0f02 100%)',
    cardBorder: '2px solid rgba(234, 179, 8, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(161, 98, 7, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(161, 98, 7, 0.4), rgba(234, 179, 8, 0.25))',
    badgeBorder: '1.5px solid rgba(250, 204, 21, 0.8)',
    badgeColor: '#fef9c3',
    badgeIcon: '👥',
    badgeSubtitle: 'قسم الخدمة الاجتماعية والدعم النفسي الاجتماعي',
    photoBorder: '#eab308',
    submitGradient: 'linear-gradient(135deg, #a16207 0%, #eab308 100%)',
    submitShadow: '0 10px 25px rgba(161, 98, 7, 0.4)',
    ambient1: 'rgba(234, 179, 8, 0.25)',
    ambient2: 'rgba(161, 98, 7, 0.18)'
  },
  "community-work": {
    primary: '#0f766e',
    gradientBg: 'linear-gradient(135deg, #052623 0%, #134e4a 50%, #031715 100%)',
    cardBorder: '2px solid rgba(20, 184, 166, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(15, 118, 110, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(15, 118, 110, 0.4), rgba(20, 184, 166, 0.25))',
    badgeBorder: '1.5px solid rgba(45, 212, 191, 0.8)',
    badgeColor: '#ccfbf1',
    badgeIcon: '🌱',
    badgeSubtitle: 'برنامج العمل المجتمعي والمبادرات التنموية',
    photoBorder: '#14b8a6',
    submitGradient: 'linear-gradient(135deg, #0f766e 0%, #14b8a6 100%)',
    submitShadow: '0 10px 25px rgba(15, 118, 110, 0.4)',
    ambient1: 'rgba(20, 184, 166, 0.25)',
    ambient2: 'rgba(15, 118, 110, 0.18)'
  },
  // Administration & Support
  "admin": {
    primary: '#334155',
    gradientBg: 'linear-gradient(135deg, #0b0f17 0%, #1e293b 50%, #070a0f 100%)',
    cardBorder: '2px solid rgba(148, 163, 184, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(30, 41, 59, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(51, 65, 85, 0.4), rgba(148, 163, 184, 0.25))',
    badgeBorder: '1.5px solid rgba(148, 163, 184, 0.8)',
    badgeColor: '#f1f5f9',
    badgeIcon: '🏢',
    badgeSubtitle: 'التدريب الإداري والشؤون المؤسسية',
    photoBorder: '#64748b',
    submitGradient: 'linear-gradient(135deg, #334155 0%, #475569 100%)',
    submitShadow: '0 10px 25px rgba(51, 65, 85, 0.4)',
    ambient1: 'rgba(148, 163, 184, 0.25)',
    ambient2: 'rgba(51, 65, 85, 0.18)'
  },
  "accounting": {
    primary: '#0f766e',
    gradientBg: 'linear-gradient(135deg, #062623 0%, #115e59 50%, #041715 100%)',
    cardBorder: '2px solid rgba(45, 212, 191, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(15, 118, 110, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(15, 118, 110, 0.4), rgba(45, 212, 191, 0.25))',
    badgeBorder: '1.5px solid rgba(45, 212, 191, 0.8)',
    badgeColor: '#ccfbf1',
    badgeIcon: '📊',
    badgeSubtitle: 'قسم المحاسبة والإدارة المالية والموازنات',
    photoBorder: '#2dd4bf',
    submitGradient: 'linear-gradient(135deg, #0f766e 0%, #14b8a6 100%)',
    submitShadow: '0 10px 25px rgba(15, 118, 110, 0.4)',
    ambient1: 'rgba(45, 212, 191, 0.25)',
    ambient2: 'rgba(15, 118, 110, 0.18)'
  },
  "kitchen": {
    primary: '#b45309',
    gradientBg: 'linear-gradient(135deg, #281202 0%, #78350f 50%, #190a01 100%)',
    cardBorder: '2px solid rgba(245, 158, 11, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(180, 83, 9, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(180, 83, 9, 0.4), rgba(245, 158, 11, 0.25))',
    badgeBorder: '1.5px solid rgba(251, 191, 36, 0.8)',
    badgeColor: '#fef3c7',
    badgeIcon: '🍳',
    badgeSubtitle: 'قسم المطبخ والتغذية والإعاشة الصحية',
    photoBorder: '#f59e0b',
    submitGradient: 'linear-gradient(135deg, #b45309 0%, #f59e0b 100%)',
    submitShadow: '0 10px 25px rgba(180, 83, 9, 0.4)',
    ambient1: 'rgba(245, 158, 11, 0.25)',
    ambient2: 'rgba(180, 83, 9, 0.18)'
  },
  // Psychological Counseling & Mental Health (Healing Emerald & Teal)
  "psychological-counseling": {
    primary: '#059669',
    gradientBg: 'linear-gradient(135deg, #022c22 0%, #065f46 50%, #021e17 100%)',
    cardBorder: '2px solid rgba(16, 185, 129, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(5, 150, 105, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(5, 150, 105, 0.4), rgba(16, 185, 129, 0.25))',
    badgeBorder: '1.5px solid rgba(52, 211, 153, 0.8)',
    badgeColor: '#d1fae5',
    badgeIcon: '🧠',
    badgeSubtitle: 'قسم الإرشاد والصحة النفسية والدعم النفسي الاجتماعي',
    photoBorder: '#10b981',
    submitGradient: 'linear-gradient(135deg, #059669 0%, #10b981 100%)',
    submitShadow: '0 10px 25px rgba(16, 185, 129, 0.4)',
    ambient1: 'rgba(16, 185, 129, 0.25)',
    ambient2: 'rgba(5, 150, 105, 0.18)'
  },
  "mental-health": {
    primary: '#059669',
    gradientBg: 'linear-gradient(135deg, #022c22 0%, #065f46 50%, #021e17 100%)',
    cardBorder: '2px solid rgba(16, 185, 129, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(5, 150, 105, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(5, 150, 105, 0.4), rgba(16, 185, 129, 0.25))',
    badgeBorder: '1.5px solid rgba(52, 211, 153, 0.8)',
    badgeColor: '#d1fae5',
    badgeIcon: '🧠',
    badgeSubtitle: 'قسم الإرشاد والصحة النفسية والدعم النفسي الاجتماعي',
    photoBorder: '#10b981',
    submitGradient: 'linear-gradient(135deg, #059669 0%, #10b981 100%)',
    submitShadow: '0 10px 25px rgba(16, 185, 129, 0.4)',
    ambient1: 'rgba(16, 185, 129, 0.25)',
    ambient2: 'rgba(5, 150, 105, 0.18)'
  },
  "counseling-mental-health": {
    primary: '#059669',
    gradientBg: 'linear-gradient(135deg, #022c22 0%, #065f46 50%, #021e17 100%)',
    cardBorder: '2px solid rgba(16, 185, 129, 0.4)',
    cardShadow: '0 25px 60px -12px rgba(5, 150, 105, 0.35)',
    badgeBg: 'linear-gradient(135deg, rgba(5, 150, 105, 0.4), rgba(16, 185, 129, 0.25))',
    badgeBorder: '1.5px solid rgba(52, 211, 153, 0.8)',
    badgeColor: '#d1fae5',
    badgeIcon: '🧠',
    badgeSubtitle: 'قسم الإرشاد والصحة النفسية والدعم النفسي الاجتماعي',
    photoBorder: '#10b981',
    submitGradient: 'linear-gradient(135deg, #059669 0%, #10b981 100%)',
    submitShadow: '0 10px 25px rgba(16, 185, 129, 0.4)',
    ambient1: 'rgba(16, 185, 129, 0.25)',
    ambient2: 'rgba(5, 150, 105, 0.18)'
  }
};

export default function PublicApplicationForm() {
  const params = useParams();
  const rawCat = (params?.category as string) || "internship";
  let decodedCat = rawCat;
  try {
    decodedCat = decodeURIComponent(rawCat).trim();
  } catch {}
  const categoryId = decodedCat;
  const categoryName = categories[categoryId] || categories[rawCat] || categoryId;

  const isVolunteer = volunteerCategories.includes(categoryId);
  const isNursingTraining = categoryId === nursingTrainingCategory || categoryId === 'تمريض تدريب';
  const isNursingInternship = categoryId === nursingInternshipCategory || categoryId === 'تمريض امتياز';
  const isNursing = 
    nursingCategories.includes(categoryId) ||
    categoryId.includes('nursing') ||
    categoryId.includes('تمريض') ||
    categoryName.includes('تمريض') ||
    categoryName.includes('nursing') ||
    categoryId === 'volunteer-nursing' ||
    categoryId === 'nursing-training' ||
    categoryId === 'nursing-internship' ||
    categoryId === 'nursing' ||
    categoryId === 'التمريض' ||
    categoryId === 'التمريض العام' ||
    categoryId === 'تمريض تدريب' ||
    categoryId === 'تمريض امتياز' ||
    categoryId === 'تمريض تطوع' ||
    categoryId === 'تدريب تمريض الجامعات';
  const isUniversityNursingTrainer = 
    categoryId === 'university-nursing-trainers' || 
    categoryId === 'university -nursing-trainers' || 
    categoryId === 'university%20-nursing-trainers' || 
    categoryId === 'university.nursing.trainers' ||
    categoryId === 'تقديم طلبات لتدريب طلاب التمريض في الجامعات';

  const isUniversityTrainer = 
    isUniversityNursingTrainer ||
    categoryId === 'radiology-trainers' ||
    categoryId === 'physical-therapy-trainers' ||
    categoryId === 'lab-trainers' ||
    categoryId === 'pharmacy-trainers' ||
    categoryId === 'occupational-therapy-trainers' ||
    categoryId === 'nutrition-trainers' ||
    categoryId === 'medical-engineering-trainers';
  const isContractedDoctor = categoryId === 'contracted-doctors' || categoryId === 'contracted_doctors';
  const isUntouchedCategory = isUniversityTrainer || isContractedDoctor;
  const currentTheme = departmentThemes[categoryId] || defaultDepartmentTheme;
  const isInternship = categoryId === 'internship' || categoryName === 'المتقدمين للإمتياز' || categoryName === 'أطباء الامتياز';
  const isMedicalTraining = 
    categoryId === 'medical-training' || 
    categoryId === 'medical_training' || 
    categoryId === 'clinical-medical-training' ||
    categoryId === 'طب تدريب' ||
    categoryId === 'تدريب طب' ||
    categoryId.includes('medical-training') ||
    categoryName === 'طب تدريب' ||
    categoryName === 'طب تدريب سريري' ||
    categoryName.includes('طب تدريب') ||
    categoryName.includes('تدريب سريري طبي');
  const isPsychologicalCounseling = 
    categoryId === 'psychological-counseling' ||
    categoryId === 'mental-health' ||
    categoryId === 'counseling-mental-health' ||
    categoryId === 'psychological_counseling' ||
    categoryId === 'إرشاد وصحة نفسية' ||
    categoryId === 'الصحة النفسية' ||
    categoryId.includes('psychological') ||
    categoryId.includes('mental-health') ||
    categoryName.includes('إرشاد') ||
    categoryName.includes('ارشاد') ||
    categoryName.includes('صحة نفسية') ||
    categoryName.includes('نفسية');

  // Standard Form Data
  const [formData, setFormData] = useState({
    name: "",
    idNumber: "",
    phone: "",
    address: "",
    university: "",
    graduationYear: "",
    studySystem: "",
    internshipYear: "",
    email: "",
    notes: "",
    trainingStartDate: "",
    trainingEndDate: "",
    volunteerStartDate: "",
    volunteerEndDate: "",
    volunteerDepartment: "",
    trainerName: "",
    supervisorName: "",
    nursingSpecialty: "",
    trainingPeriod: "",
    desiredStartDate: "",
    desiredDepartment: "",
    customDesiredDepartment: "",
    department: ""
  });

  // Google Forms Extra Fields State
  const [extras, setExtras] = useState({
    age: "",
    gender: "",
    degree: "",
    employmentType: "",
    paidTraining: "",
    teachingExperienceYears: "",
    previousUniversitiesCountAndPeriod: "",
    teachingCourses: [] as string[],
    previousContractedUniversity: "",
    contractedUniversities: [] as string[],
    customContractedUniversity: "",
    crescentJobNature: "",
    customCrescentJobNature: "",
    doctorPhotoBase64: "",
    workDays: [] as string[],
    trainingDepartments: [] as string[],
    specialty: "",
    dailyStudentsCount: "",
    groupsPerDay: "",
    totalSemesterTrainees: "",
    workHours: ""
  });
  
  const [submitted, setSubmitted] = useState(false);
  const [isSubmitting, setIsSubmitting] = useState(false);

  // Separate State for Personal Photo
  const [photoBase64, setPhotoBase64] = useState<string>("");
  const [photoFileName, setPhotoFileName] = useState<string>("");
  const [photoError, setPhotoError] = useState("");
  const [doctorPhotoError, setDoctorPhotoError] = useState("");

  // Separate State for Union Paper (Never mix with personal photo!)
  const [unionPaperBase64, setUnionPaperBase64] = useState<string>("");
  const [unionPaperFileName, setUnionPaperFileName] = useState<string>("");
  const [unionPaperError, setUnionPaperError] = useState("");

  // Clinical Trainers State (Pre-populated accredited list + custom trainer fallback)
  const availableTrainers = DEFAULT_ACCREDITED_TRAINERS;
  const [isCustomTrainer, setIsCustomTrainer] = useState(false);
  const [customTrainerInput, setCustomTrainerInput] = useState("");

  // Compute department-matching and other trainers
  const targetSpecialtyGroup = useMemo(() => {
    const c = categoryId.toLowerCase();
    const cn = categoryName.toLowerCase();
    if (c.includes('nursing') || cn.includes('تمريض')) return 'nursing';
    if (c.includes('radiology') || cn.includes('أشعة') || cn.includes('اشعة')) return 'radiology';
    if (c.includes('lab') || cn.includes('مختبر')) return 'lab';
    if (c.includes('physical') || cn.includes('طبيعي')) return 'pt';
    if (c.includes('pharmacy') || cn.includes('صيدل')) return 'pharmacy';
    if (c.includes('nutrition') || cn.includes('تغذي')) return 'nutrition';
    if (c.includes('engineering') || cn.includes('هندس')) return 'biomedical';
    if (c.includes('occupational') || cn.includes('وظيفي')) return 'ot';
    return 'other';
  }, [categoryId, categoryName]);

  const deptTrainers = useMemo(() => {
    return availableTrainers
      .filter(t => t.specialtyGroup === targetSpecialtyGroup)
      .sort((a, b) => a.name.localeCompare(b.name, 'ar'));
  }, [availableTrainers, targetSpecialtyGroup]);

  const otherTrainers = useMemo(() => {
    return availableTrainers
      .filter(t => t.specialtyGroup !== targetSpecialtyGroup)
      .sort((a, b) => a.name.localeCompare(b.name, 'ar'));
  }, [availableTrainers, targetSpecialtyGroup]);

  // Helper toggle for array fields (checkboxes)
  const toggleArrayItem = (field: 'teachingCourses' | 'workDays' | 'trainingDepartments' | 'contractedUniversities', item: string) => {
    setExtras(prev => {
      const current = prev[field] || [];
      const updated = current.includes(item)
        ? current.filter(i => i !== item)
        : [...current, item];
      return { ...prev, [field]: updated };
    });
  };

  // Real-time completeness score (0 to 100)
  const completionScore = useMemo(() => {
    let totalPoints = 0;
    let earnedPoints = 0;

    const addCheck = (condition: boolean, weight = 10) => {
      totalPoints += weight;
      if (condition) earnedPoints += weight;
    };

    // 1. Mandatory Photo (20 pts)
    addCheck(Boolean((photoBase64 || extras.doctorPhotoBase64 || '').trim()), 20);

    // 2. Personal Info
    addCheck(Boolean(formData.name?.trim()), 15);
    addCheck(Boolean(formData.idNumber?.trim()), 15);
    addCheck(Boolean(formData.phone?.trim() && formData.phone.trim().length >= 9), 20);
    addCheck(Boolean(formData.address?.trim()), 10);

    if (isUniversityTrainer) {
      if (isUniversityNursingTrainer) {
        addCheck(Boolean(formData.university?.trim()), 5);
        addCheck(Boolean(formData.graduationYear?.trim()), 5);
        addCheck(Boolean(extras.teachingCourses && extras.teachingCourses.length > 0), 10);
      } else {
        addCheck(Boolean(formData.university?.trim()), 10);
        addCheck(Boolean(formData.graduationYear?.trim()), 10);
      }
    } else if (isContractedDoctor) {
      addCheck(Boolean(extras.crescentJobNature), 5);
      addCheck(Boolean(extras.contractedUniversities && extras.contractedUniversities.length > 0), 5);
      addCheck(Boolean(extras.workDays && extras.workDays.length > 0), 5);
      addCheck(Boolean(extras.trainingDepartments && extras.trainingDepartments.length > 0), 5);
    } else {
      addCheck(Boolean(formData.university?.trim()), 10);
      addCheck(Boolean((formData.trainerName || formData.supervisorName)?.trim()), 15);
      if (isMedicalTraining) {
        addCheck(Boolean(formData.desiredDepartment?.trim()), 10);
      } else if (isInternship) {
        addCheck(Boolean(formData.studySystem?.trim()), 10);
      }
    }

    if (totalPoints === 0) return 100;
    return Math.min(100, Math.round((earnedPoints / totalPoints) * 100));
  }, [formData, extras, photoBase64, isUniversityTrainer, isContractedDoctor, isMedicalTraining, isNursingTraining, isNursingInternship, isPsychologicalCounseling, isInternship]);

  useEffect(() => {
    try {
      localStorage.removeItem('submittedApplications');
      localStorage.removeItem('applicationsBackup');
    } catch {}
  }, []);

  // Personal Photo compression & setter
  const compressAndSetPhoto = (file: File) => {
    if (!file) return;
    if (!file.type.startsWith('image/')) {
      alert('يرجى اختيار ملف صورة صالح (JPG, PNG, WEBP, JPEG)');
      return;
    }
    const reader = new FileReader();
    reader.onload = (e) => {
      const img = new Image();
      img.onload = () => {
        const canvas = document.createElement('canvas');
        let width = img.width;
        let height = img.height;
        const maxDim = 800; // 800px ensures crystal clear portrait at ~60-120KB
        if (width > maxDim || height > maxDim) {
          if (width > height) {
            height = Math.round((height * maxDim) / width);
            width = maxDim;
          } else {
            width = Math.round((width * maxDim) / height);
            height = maxDim;
          }
        }
        canvas.width = width;
        canvas.height = height;
        const ctx = canvas.getContext('2d');
        if (ctx) {
          ctx.drawImage(img, 0, 0, width, height);
          const compressed = canvas.toDataURL('image/jpeg', 0.85);
          setPhotoBase64(compressed);
          setPhotoFileName(file.name || 'personal_photo.jpg');
          setExtras(prev => ({ ...prev, doctorPhotoBase64: compressed }));
          setPhotoError('');
          setDoctorPhotoError('');
        }
      };
      img.src = e.target?.result as string;
    };
    reader.readAsDataURL(file);
  };

  // Dedicated Union Paper Upload handler (Never sets personal photo!)
  const handleUnionPaperUpload = (file: File) => {
    if (!file) return;
    if (file.size > 3 * 1024 * 1024) {
      setUnionPaperError('حجم الملف كبير جداً (الحد الأقصى 3MB)');
      return;
    }
    setUnionPaperFileName(file.name);
    setUnionPaperError('');
    if (file.type.startsWith('image/')) {
      const reader = new FileReader();
      reader.onload = (e) => {
        const img = new Image();
        img.onload = () => {
          const canvas = document.createElement('canvas');
          let width = img.width;
          let height = img.height;
          const maxDim = 1200;
          if (width > maxDim || height > maxDim) {
            if (width > height) {
              height = Math.round((height * maxDim) / width);
              width = maxDim;
            } else {
              width = Math.round((width * maxDim) / height);
              height = maxDim;
            }
          }
          canvas.width = width;
          canvas.height = height;
          const ctx = canvas.getContext('2d');
          if (ctx) {
            ctx.drawImage(img, 0, 0, width, height);
            setUnionPaperBase64(canvas.toDataURL('image/jpeg', 0.85));
          }
        };
        img.src = e.target?.result as string;
      };
      reader.readAsDataURL(file);
    } else {
      const reader = new FileReader();
      reader.onload = () => {
        setUnionPaperBase64(reader.result as string);
      };
      reader.readAsDataURL(file);
    }
  };

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    if (isSubmitting) return;

    // ══════ 1. OBLIGATORY IMAGE VALIDATION FOR ALL APPLICATIONS ══════
    const candidatePhoto = (photoBase64 || extras.doctorPhotoBase64 || '').trim();
    if (!candidatePhoto) {
      setPhotoError('الصورة الشخصية مطلوبة وإجبارية لكافة الطلبات');
      setDoctorPhotoError('الصورة الشخصية مطلوبة وإجبارية لكافة الطلبات');
      alert('⚠️ يرجى إرفاق الصورة الشخصية للمتقدم (الصورة الشخصية إجبارية لكافة نماذج وطلبات التقديم)');
      const photoEl = document.getElementById('applicant-photo-card') || 
                      document.getElementById('doctor-photo-card') || 
                      document.getElementById('nursing-photo-card');
      if (photoEl) {
        photoEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
      }
      return;
    }

    // ══════ 2. OBLIGATORY PHONE NUMBER VALIDATION FOR ALL APPLICATIONS ══════
    const cleanPhone = (formData.phone || '').trim();
    if (!cleanPhone) {
      alert('⚠️ يرجى إدخال رقم الهاتف / الجوال (حقل إجباري لكافة الطلبات)');
      const phoneInput = document.querySelector('input[type="tel"]') as HTMLInputElement;
      if (phoneInput) {
        phoneInput.focus();
        phoneInput.scrollIntoView({ behavior: 'smooth', block: 'center' });
      }
      return;
    }
    if (cleanPhone.replace(/\D/g, '').length < 9) {
      alert('⚠️ رقم الهاتف غير صحيح، يرجى التأكد من كتابة رقم هاتف صالح (مثال: 059xxxxxxx)');
      return;
    }

    // Mandatory trainer selection for all trainee applications
    if (!isUntouchedCategory) {
      const chosenTrainer = (formData.trainerName || formData.supervisorName || '').trim();
      if (!chosenTrainer) {
        alert('⚠️ يرجى تحديد أو إدخال اسم المدرب المشرف الخاص بك من القائمة (إجباري لكافة المتدربين)');
        const el = document.getElementById('trainer-selection-card');
        if (el) el.scrollIntoView({ behavior: 'smooth', block: 'center' });
        return;
      }
    }

    if (isUniversityTrainer) {
      if (!formData.idNumber.trim()) {
        alert('يرجى إدخال رقم الهوية (إجباري)');
        return;
      }
      if (!formData.address.trim()) {
        alert('يرجى إدخال مكان السكن (إجباري)');
        return;
      }
      if (!formData.university.trim()) {
        alert('يرجى إدخال اسم الجامعة (إجباري)');
        return;
      }
      if (!formData.graduationYear.trim()) {
        alert('يرجى إدخال سنة التخرج (إجباري)');
        return;
      }
      if (isUniversityNursingTrainer) {
        if (!extras.teachingCourses || extras.teachingCourses.length === 0) {
          alert('يرجى تحديد المساقات التي تدرسها — اختر مساقاً واحداً على الأقل (إجباري)');
          return;
        }
      }
      const hasSelectedUnis = extras.contractedUniversities && extras.contractedUniversities.length > 0;
      const hasCustomUni = !!(extras.customContractedUniversity?.trim() || extras.previousContractedUniversity?.trim());
      if (!hasSelectedUnis && !hasCustomUni) {
        alert('يرجى تحديد أو كتابة الجامعات المتعاقد معها حالياً (إجباري)');
        return;
      }
      if (extras.contractedUniversities?.includes('جامعة أخرى') && !extras.customContractedUniversity?.trim()) {
        alert('يرجى كتابة اسم الجامعة الأخرى المتعاقد معها (إجباري)');
        return;
      }
    }

    if (isContractedDoctor) {
      if (!extras.doctorPhotoBase64) {
        setDoctorPhotoError('الصورة الشخصية للطبيب مطلوبة وإجبارية');
        alert('يرجى إرفاق الصورة الشخصية للطبيب (إجباري)');
        return;
      }
      if (!extras.crescentJobNature) {
        alert('يرجى تحديد طبيعة الوظيفة في مستشفى الهلال الأحمر (إجباري)');
        return;
      }
      if (extras.crescentJobNature === 'أخرى' && !extras.customCrescentJobNature.trim()) {
        alert('يرجى كتابة تفاصيل طبيعة الوظيفة في مستشفى الهلال الأحمر (إجباري)');
        return;
      }
      if (!extras.contractedUniversities || extras.contractedUniversities.length === 0) {
        alert('يرجى اختيار جامعة واحدة على الأقل من قائمة الجامعات المتعاقد معها (إجباري)');
        return;
      }
      if (extras.contractedUniversities.includes('جامعة أخرى') && !extras.customContractedUniversity.trim()) {
        alert('يرجى كتابة اسم الجامعة الأخرى المتعاقد معها (إجباري)');
        return;
      }
      if (!extras.workDays || extras.workDays.length === 0) {
        alert('يرجى تحديد أيام الدوام الأسبوعية (إجباري)');
        return;
      }
      if (!extras.trainingDepartments || extras.trainingDepartments.length === 0) {
        alert('يرجى اختيار القسم أو الأقسام التي يتم التدريب فيها (إجباري)');
        return;
      }
      if (!formData.university?.trim()) {
        alert('يرجى إدخال اسم الجامعة / كلية الطب المتخرج منها الطبيب (إجباري)');
        return;
      }
      if (!formData.graduationYear?.trim()) {
        alert('يرجى إدخال سنة التخرج (إجباري)');
        return;
      }
      if (!formData.trainingStartDate || !formData.trainingEndDate) {
        alert('يرجى تحديد فترة التعاقد والتدريب (من تاريخ إلى تاريخ) بشكل كامل (إجباري)');
        return;
      }
    }
    
    if (isUniversityTrainer) {
      if (!extras.doctorPhotoBase64 && !photoBase64) {
        alert('يرجى إرفاق الصورة الشخصية للمشرف التدريبي (إجباري)');
        return;
      }
      if (!formData.trainingStartDate || !formData.trainingEndDate) {
        alert('يرجى تحديد فترة التدريب المقررة (من تاريخ إلى تاريخ) بشكل كامل (إجباري)');
        return;
      }
    }

    if (isMedicalTraining) {
      if (!formData.desiredDepartment?.trim()) {
        alert('يرجى اختيار القسم الطبي المطلوب التدريب فيه (إجباري)');
        return;
      }
      if (formData.desiredDepartment === 'أخرى' && !formData.customDesiredDepartment?.trim()) {
        alert('يرجى كتابة اسم القسم الطبي المطلوب بالتفصيل (إجباري)');
        return;
      }
    }

    if (isPsychologicalCounseling) {
      if (!formData.supervisorName?.trim()) {
        alert('يرجى إدخال اسم المشرف المسؤول (إجباري)');
        return;
      }
    }
    
    setIsSubmitting(true);

    const customUniText = (extras.customContractedUniversity || extras.previousContractedUniversity || '').trim();
    const finalUniversities = (isContractedDoctor || isUniversityTrainer)
      ? [
          ...(extras.contractedUniversities || []).filter(u => u !== 'جامعة أخرى'),
          ...(customUniText && !(extras.contractedUniversities || []).includes(customUniText) ? [customUniText] : [])
        ]
      : [];

    const finalJobNature = extras.crescentJobNature === 'أخرى' && extras.customCrescentJobNature
      ? `أخرى: ${extras.customCrescentJobNature.trim()}`
      : extras.crescentJobNature || extras.employmentType;
    
    const finalPhoto = extras.doctorPhotoBase64 || photoBase64;
    const gradUni = (formData.university || '').trim();
    const contractedUniStr = finalUniversities.join('، ');

    const finalDesiredDept = formData.desiredDepartment === 'أخرى' && formData.customDesiredDepartment
      ? `أخرى: ${formData.customDesiredDepartment.trim()}`
      : (formData.desiredDepartment || formData.department || '');

    const trainerDeptMap: Record<string, string> = {
      'radiology-trainers': 'قسم الأشعة والتصوير الطبي',
      'physical-therapy-trainers': 'قسم العلاج الطبيعي والتأهيل',
      'lab-trainers': 'قسم المختبرات الطبية',
      'pharmacy-trainers': 'قسم الصيدلة السريرية',
      'occupational-therapy-trainers': 'قسم العلاج الوظيفي',
      'nutrition-trainers': 'قسم التغذية السريرية',
      'medical-engineering-trainers': 'قسم الهندسة الطبية'
    };
    const defaultTrainerDept = trainerDeptMap[categoryId] || '';

    const chosenTrainer = (formData.trainerName || formData.supervisorName || '').trim();

    const newApplication: any = {
      ...formData,
      ...extras,
      assignedTrainer: chosenTrainer,
      trainerName: chosenTrainer,
      supervisorName: chosenTrainer,
      desiredDepartment: isMedicalTraining ? finalDesiredDept : (formData.desiredDepartment || defaultTrainerDept || (isPsychologicalCounseling ? 'الصحة النفسية' : '')),
      department: isMedicalTraining ? finalDesiredDept : (formData.department || defaultTrainerDept || (isPsychologicalCounseling ? 'الصحة النفسية' : '')),
      targetDept: isMedicalTraining ? finalDesiredDept : ((formData as any).targetDept || formData.desiredDepartment || defaultTrainerDept || (isPsychologicalCounseling ? 'الصحة النفسية' : '')),
      assignedDept: isMedicalTraining ? finalDesiredDept : ((formData as any).assignedDept || formData.desiredDepartment || defaultTrainerDept || (isPsychologicalCounseling ? 'الصحة النفسية' : '')),
      trainingDepartments: (extras.trainingDepartments && extras.trainingDepartments.length > 0)
        ? extras.trainingDepartments
        : (defaultTrainerDept ? [defaultTrainerDept] : []),
      trainingStartDate: formData.trainingStartDate || formData.volunteerStartDate || '',
      trainingEndDate: formData.trainingEndDate || formData.volunteerEndDate || '',
      startDate: formData.trainingStartDate || formData.volunteerStartDate || formData.desiredStartDate || '',
      endDate: formData.trainingEndDate || formData.volunteerEndDate || '',
      studySystem: isInternship ? formData.studySystem : '',
      internshipYear: isInternship ? formData.internshipYear : '',
      // 🎓 الجامعة المتخرج منها (درجة التخرج الشخصية)
      graduatedUniversity: gradUni,
      // 🤝 الجامعات المتعاقد معها (شراكة المستشفى)
      contractedUniversities: finalUniversities.length > 0 ? finalUniversities : (customUniText ? [customUniText] : []),
      contractedUniversity: contractedUniStr || customUniText || '',
      previousContractedUniversity: customUniText || contractedUniStr,
      // For trainers, set university to contracted university so hospital quota matches, with fallback
      university: (isContractedDoctor || isUniversityTrainer) 
        ? (contractedUniStr || customUniText || gradUni)
        : (gradUni || contractedUniStr || ''),
      crescentJobNature: finalJobNature,
      employmentType: finalJobNature,
      photoBase64: finalPhoto,
      doctorPhotoBase64: finalPhoto,
      photoFileName: photoFileName || 'personal_photo.jpg',
      unionPaperBase64: unionPaperBase64 || '',
      unionPaperFileName: unionPaperBase64 ? (unionPaperFileName || 'ورقة_النقابة') : '',
      category: categoryName,
      categoryId: categoryId,
      date: new Date().toISOString().split('T')[0],
      status: 'pending',
      id: Date.now().toString(),
      isVolunteer: isVolunteer
    };

    // Retry logic — try up to 3 times
    let lastError: any = null;
    for (let attempt = 1; attempt <= 3; attempt++) {
      try {
        const controller = new AbortController();
        const timeout = setTimeout(() => controller.abort(), 35000);

        const response = await fetch('/api/applications', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ application: newApplication }),
          signal: controller.signal
        });

        clearTimeout(timeout);

        if (!response.ok) {
          const errData = await response.json().catch(() => ({}));
          throw new Error(errData.error || `Server error ${response.status}`);
        }

        // Success!
        setSubmitted(true);
        setIsSubmitting(false);
        return;
      } catch (error: any) {
        lastError = error;
        console.error(`Submission attempt ${attempt}/3 failed:`, error);
        if (attempt < 3) {
          await new Promise(r => setTimeout(r, 1000 * attempt));
        }
      }
    }

    // All attempts failed
    console.error("All submission attempts failed:", lastError);
    if (lastError?.name === 'AbortError') {
      alert("انتهت مهلة الاتصال بالسيرفر. يرجى التحقق من اتصالك بالإنترنت والمحاولة مرة أخرى.");
    } else {
      alert("حدث خطأ أثناء الإرسال. يرجى المحاولة مرة أخرى.\n\nتفاصيل: " + (lastError?.message || 'خطأ غير معروف'));
    }
    setIsSubmitting(false);
  };

  // Success view
  if (submitted) {
    return (
      <div style={{ 
        minHeight: '100vh', 
        display: 'flex', 
        flexDirection: 'column', 
        alignItems: 'center', 
        justifyContent: 'center', 
        textAlign: 'center',
        padding: '20px',
        background: 'linear-gradient(135deg, #064e3b 0%, #0f172a 100%)',
        fontFamily: 'Tajawal, sans-serif',
        direction: 'rtl'
      }}>
        <div style={{
          background: 'white',
          padding: '45px 30px',
          borderRadius: '24px',
          boxShadow: '0 30px 60px rgba(0,0,0,0.3)',
          maxWidth: '520px',
          width: '100%'
        }}>
          <div style={{ fontSize: '65px', marginBottom: '10px' }}>🎉</div>
          <CheckCircle size={65} color="#059669" style={{ marginBottom: '15px', display: 'inline-block' }} />
          <h1 style={{ fontSize: '1.9rem', color: '#059669', marginBottom: '12px', fontWeight: 800 }}>
            تم تقديم الطلب بنجاح!
          </h1>
          <p style={{ color: '#4b5563', fontSize: '1.05rem', lineHeight: '1.7', marginBottom: '20px' }}>
            شكراً لتقديمك نموذج <strong>{categoryName}</strong> بمستشفى الهلال الأحمر التخصصي. سيتم مراجعة طلبك والتواصل معك من قبل وحدة التطوير والتدريب.
          </p>
          <div style={{ 
            padding: '14px', 
            background: '#ecfdf5', 
            borderRadius: '12px',
            border: '2px solid #10b981',
            marginBottom: '25px'
          }}>
            <p style={{ color: '#047857', fontWeight: 'bold', margin: '0 0 6px 0', fontSize: '0.95rem' }}>
              ✓ تم تسجيل وحفظ طلبك في النظام الإلكتروني
            </p>
            <div style={{ display: 'inline-flex', alignItems: 'center', gap: '6px', background: '#dcfce7', color: '#047857', padding: '4px 12px', borderRadius: '20px', fontWeight: 800, fontSize: '0.84rem', border: '1px solid #86efac' }}>
              ★ تم استيفاء بيانات ومعايير الطلب: 100 / 100
            </div>
          </div>

          <div style={{ display: 'flex', flexDirection: 'column', gap: '12px' }}>
            <button
              onClick={() => {
                setSubmitted(false);
                setFormData({
                  name: "", idNumber: "", phone: "", address: "",
                  university: "", graduationYear: "", studySystem: "",
                  internshipYear: "", email: "", notes: "",
                  trainingStartDate: "", trainingEndDate: "",
                  volunteerStartDate: "", volunteerEndDate: "",
                  volunteerDepartment: "", trainerName: "",
                  supervisorName: "", nursingSpecialty: "", trainingPeriod: "",
                  desiredStartDate: "",
                  desiredDepartment: "",
                  customDesiredDepartment: "",
                  department: ""
                });
                setExtras({
                  age: "", gender: "", degree: "", employmentType: "", paidTraining: "",
                  teachingExperienceYears: "", previousUniversitiesCountAndPeriod: "",
                  teachingCourses: [], previousContractedUniversity: "",
                  contractedUniversities: [], customContractedUniversity: "",
                  crescentJobNature: "", customCrescentJobNature: "", doctorPhotoBase64: "",
                  workDays: [], trainingDepartments: [], specialty: "",
                  dailyStudentsCount: "", groupsPerDay: "", totalSemesterTrainees: "", workHours: ""
                });
                setDoctorPhotoError("");
                setPhotoFileName("");
                setPhotoBase64("");
                setPhotoError("");
                setUnionPaperBase64("");
                setUnionPaperFileName("");
                setUnionPaperError("");
              }}
              style={{
                width: '100%',
                padding: '14px',
                fontSize: '1rem',
                fontWeight: 800,
                background: 'linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%)',
                color: 'white',
                border: 'none',
                borderRadius: '12px',
                cursor: 'pointer',
                boxShadow: '0 8px 20px rgba(59, 130, 246, 0.3)',
                fontFamily: 'Tajawal, sans-serif'
              }}
            >
              📝 تقديم طلب جديد لنفس القسم
            </button>

            <Link
              href="/recruitment"
              style={{
                width: '100%',
                padding: '14px',
                fontSize: '1rem',
                fontWeight: 800,
                background: 'linear-gradient(135deg, #059669 0%, #10b981 100%)',
                color: 'white',
                border: 'none',
                borderRadius: '12px',
                textDecoration: 'none',
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'center',
                gap: '8px',
                boxShadow: '0 8px 20px rgba(16, 185, 129, 0.3)',
                fontFamily: 'Tajawal, sans-serif'
              }}
            >
              <ArrowRight size={18} />
              العودة لقائمة كافة النماذج (تقديم الطلبات)
            </Link>

            <Link
              href="/"
              style={{
                width: '100%',
                padding: '12px',
                fontSize: '0.95rem',
                fontWeight: 700,
                background: '#f1f5f9',
                color: '#475569',
                border: '1px solid #cbd5e1',
                borderRadius: '12px',
                textDecoration: 'none',
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'center',
                gap: '8px',
                fontFamily: 'Tajawal, sans-serif'
              }}
            >
              <Home size={16} />
              الصفحة الرئيسية للمستشفى
            </Link>
          </div>
        </div>
      </div>
    );
  }

  // Days list for checkboxes
  const daysList = ['السبت', 'الاحد', 'الاثنين', 'الثلاثاء', 'الاربعاء', 'الخميس', 'الجمعة'];
  
  // Hospital departments list for checkboxes
  const deptsList = [
    'قسم الاطفال', 'قسم الولادة', 'قسم الجراحة', 'قسم الكلى', 'قسم الخداج',
    'قسم العناية المكثفة', 'قسم الاشعة', 'قسم التخدير', 'قسم العمليات', 'قسم الطوارئ'
  ];

  return (
    <div style={{ 
      minHeight: '100vh',
      background: isUntouchedCategory ? 'linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%)' : currentTheme.gradientBg,
      padding: '25px 16px 60px',
      fontFamily: 'Tajawal, sans-serif',
      direction: 'rtl',
      position: 'relative',
      overflow: 'hidden'
    }}>
      {/* Signatures: strictly hidden on screen for applicants, visible only when printing */}
      <style>{`
        .print-only-signatures {
          display: none !important;
        }
        @media print {
          .print-only-signatures {
            display: block !important;
          }
        }
      `}</style>
      {/* Dynamic Ambient Glow for Department Theming */}
      {!isUntouchedCategory && (
        <>
          <div style={{ position: 'absolute', top: '-60px', right: '-60px', width: '250px', height: '250px', background: currentTheme.ambient1, borderRadius: '50%', filter: 'blur(70px)', pointerEvents: 'none' }} />
          <div style={{ position: 'absolute', top: '35%', left: '-80px', width: '280px', height: '280px', background: currentTheme.ambient2, borderRadius: '50%', filter: 'blur(80px)', pointerEvents: 'none' }} />
        </>
      )}
      <div style={{ maxWidth: '750px', margin: '0 auto', position: 'relative', zIndex: 1 }}>

        {/* ══════════════════════════════════════════════════════════
            TOP NAVIGATION BAR (BACK BUTTONS)
        ══════════════════════════════════════════════════════════ */}
        <div style={{
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'space-between',
          gap: '10px',
          marginBottom: '20px',
          flexWrap: 'wrap'
        }}>
          <Link
            href="/recruitment"
            style={{
              display: 'inline-flex',
              alignItems: 'center',
              gap: '8px',
              padding: '10px 20px',
              background: 'linear-gradient(135deg, #059669 0%, #10b981 100%)',
              color: 'white',
              borderRadius: '12px',
              textDecoration: 'none',
              fontWeight: 800,
              fontSize: '0.9rem',
              boxShadow: '0 4px 15px rgba(16, 185, 129, 0.35)',
              border: '1px solid rgba(255,255,255,0.2)',
              transition: 'all 0.3s'
            }}
          >
            <ArrowRight size={18} />
            العودة لكافة النماذج (تقديم الطلبات)
          </Link>

          <Link
            href="/"
            style={{
              display: 'inline-flex',
              alignItems: 'center',
              gap: '6px',
              padding: '10px 18px',
              background: 'rgba(255,255,255,0.12)',
              color: 'white',
              borderRadius: '12px',
              textDecoration: 'none',
              fontWeight: 700,
              fontSize: '0.85rem',
              backdropFilter: 'blur(10px)',
              border: '1px solid rgba(255,255,255,0.2)',
              transition: 'all 0.3s'
            }}
          >
            <Home size={16} />
            الرئيسية
          </Link>
        </div>

        {/* Header Branding */}
        <div style={{
          textAlign: 'center',
          padding: '20px 20px 25px',
          color: 'white',
          marginBottom: '20px'
        }}>
          {/* Crescent Logo */}
          <div style={{
            width: '85px',
            height: '85px',
            background: 'white',
            borderRadius: '50%',
            margin: '0 auto 16px',
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center',
            boxShadow: '0 10px 30px rgba(0,0,0,0.4)',
            border: '3.5px solid #ffd700'
          }}>
            <svg viewBox="0 0 200 200" width="60" height="60">
              <circle cx="100" cy="100" r="96" fill="white" stroke="#CE1126" strokeWidth="4"/>
              <g transform="translate(100, 100)">
                <circle cx="0" cy="0" r="45" fill="#CE1126"/>
                <circle cx="16" cy="0" r="35" fill="white"/>
              </g>
            </svg>
          </div>
          
          <h1 style={{ fontSize: '1.85rem', fontWeight: 900, marginBottom: '6px', color: '#ffffff' }}>
            مستشفى الهلال الأحمر التخصصي
          </h1>
          <div style={{ fontSize: '0.95rem', color: '#ffd700', fontWeight: 800, marginBottom: '12px' }}>
            مديرة وحدة التطوير والتدريب — أ. نسرين عابدين (أم خالد)
          </div>
          {isUntouchedCategory ? (
            <h2 style={{ 
              fontSize: '1.3rem', 
              fontWeight: 800, 
              background: 'rgba(255,255,255,0.12)', 
              display: 'inline-block', 
              padding: '8px 22px', 
              borderRadius: '30px', 
              border: '1.5px solid rgba(255,215,0,0.4)',
              color: '#ffffff'
            }}>
              {categoryName}
            </h2>
          ) : (
            <div style={{
              display: 'inline-flex',
              flexDirection: 'column',
              alignItems: 'center',
              gap: '6px',
              background: currentTheme.badgeBg,
              border: currentTheme.badgeBorder,
              padding: '12px 28px',
              borderRadius: '30px',
              boxShadow: '0 8px 25px rgba(0,0,0,0.3)',
              backdropFilter: 'blur(12px)'
            }}>
              <span style={{ fontSize: '1.35rem', fontWeight: 900, color: currentTheme.badgeColor, display: 'flex', alignItems: 'center', gap: '8px' }}>
                <span style={{ fontSize: '1.4rem' }}>{currentTheme.badgeIcon}</span> {categoryName}
              </span>
              {currentTheme.badgeSubtitle && (
                <span style={{ fontSize: '0.84rem', color: 'rgba(255,255,255,0.9)', fontWeight: 700 }}>
                  {currentTheme.badgeSubtitle}
                </span>
              )}
            </div>
          )}
        </div>

        {/* Main Form Card */}
        <div style={{
          background: '#ffffff',
          borderRadius: '24px',
          padding: '38px 28px',
          boxShadow: isUntouchedCategory ? '0 25px 50px -12px rgba(0,0,0,0.35)' : currentTheme.cardShadow,
          border: isUntouchedCategory ? 'none' : currentTheme.cardBorder,
          color: '#1e293b',
          transition: 'all 0.3s ease'
        }}>
          <form onSubmit={handleSubmit}>

            {/* ══════ شريط اكتمال بيانات الطلب (100 / 100) ══════ */}
            <div style={{
              marginBottom: '26px',
              padding: '16px 20px',
              background: completionScore === 100 ? '#ecfdf5' : '#f8fafc',
              borderRadius: '16px',
              border: completionScore === 100 ? '2px solid #10b981' : '1.5px solid #e2e8f0',
              boxShadow: completionScore === 100 ? '0 4px 15px rgba(16, 185, 129, 0.15)' : 'none',
              transition: 'all 0.3s ease'
            }}>
              <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '8px' }}>
                <span style={{
                  fontSize: '0.94rem',
                  fontWeight: 800,
                  color: completionScore === 100 ? '#059669' : '#334155',
                  display: 'flex',
                  alignItems: 'center',
                  gap: '6px'
                }}>
                  {completionScore === 100 ? '✅ اكتملت كافة البيانات بنجاح:' : '📊 نسبة اكتمال بيانات الطلب الإجبارية:'}
                </span>
                <span style={{
                  fontSize: '1.1rem',
                  fontWeight: 900,
                  color: completionScore === 100 ? '#059669' : '#0284c7',
                  fontFamily: 'monospace'
                }}>
                  {completionScore} / 100
                </span>
              </div>
              <div style={{
                width: '100%',
                height: '10px',
                background: '#e2e8f0',
                borderRadius: '8px',
                overflow: 'hidden'
              }}>
                <div style={{
                  width: `${completionScore}%`,
                  height: '100%',
                  background: completionScore === 100 
                    ? 'linear-gradient(90deg, #10b981 0%, #059669 100%)' 
                    : 'linear-gradient(90deg, #0284c7 0%, #38bdf8 100%)',
                  borderRadius: '8px',
                  transition: 'width 0.4s ease'
                }} />
              </div>
              {completionScore < 100 ? (
                <div style={{ fontSize: '0.8rem', color: '#64748b', marginTop: '7px', fontWeight: 600 }}>
                  💡 يرجى إكمال رفع الصورة الشخصية ورقم الهاتف والبيانات المطلوبة للوصول إلى 100/100 وإرسال الطلب رسمياً
                </div>
              ) : (
                <div style={{ fontSize: '0.8rem', color: '#047857', marginTop: '7px', fontWeight: 800 }}>
                  🎉 رائع! تم استيفاء 100/100 من الشروط والمتطلبات، الطلب جاهز تماماً للإرسال الآن.
                </div>
              )}
            </div>

            {/* ══════════════════════════════════════════════════════════
                FORM 1: مدربو الجامعات والمشرفون السريريون
            ══════════════════════════════════════════════════════════ */}
            {isUniversityTrainer ? (
              <>
                <div style={{ marginBottom: '24px', padding: '16px', background: 'linear-gradient(135deg, #e0f2fe, #bae6fd)', borderRadius: '14px', border: '2px solid #0284c7', textAlign: 'center' }}>
                  <div style={{ fontWeight: 800, color: '#0369a1', fontSize: '1.15rem' }}>
                    📋 نموذج تقديم طلبات {categoryName}
                  </div>
                  <div style={{ fontSize: '0.85rem', color: '#0284c7', marginTop: '4px' }}>
                    {isUniversityNursingTrainer
                      ? 'يرجى تعبئة كافة الحقول، إرفاق الصورة الشخصية، واختيار المساقات وأوقات الدوام'
                      : 'يرجى تعبئة كافة الحقول، إرفاق الصورة الشخصية، وتحديد الجامعات المتعاقد معها وأوقات الدوام'}
                  </div>
                </div>

                {/* 0. الصورة الشخصية */}
                <div id="nursing-photo-card" style={{ marginBottom: '24px', padding: '18px', background: doctorPhotoError ? 'rgba(225,29,72,0.06)' : '#f8fafc', borderRadius: '16px', border: `2px dashed ${doctorPhotoError ? '#e11d48' : extras.doctorPhotoBase64 ? '#10b981' : '#0284c7'}` }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 800, fontSize: '1rem', color: '#1e293b' }}>
                    📸 الصورة الشخصية للمدرب / المشرف <span style={{ color: '#e11d48' }}>* (إجباري لتقديم الطلب)</span>
                  </label>
                  <p style={{ margin: '0 0 12px 0', fontSize: '0.85rem', color: '#64748b' }}>
                    يرجى إرفاق صورة شخصية رسمية وواضحة (إجباري للاعتماد في كشوفات وسجلات التدريب بالمستشفى)
                  </p>
                  
                  {extras.doctorPhotoBase64 ? (
                    <div style={{ display: 'flex', alignItems: 'center', gap: '16px', padding: '10px', background: 'white', borderRadius: '12px', border: '1px solid #e2e8f0' }}>
                      <img 
                        src={extras.doctorPhotoBase64} 
                        alt="الصورة الشخصية" 
                        style={{ width: '70px', height: '70px', borderRadius: '12px', objectFit: 'cover', border: '2px solid #0284c7' }} 
                      />
                      <div>
                        <div style={{ color: '#059669', fontWeight: 800, fontSize: '0.9rem' }}>✓ تم تحميل الصورة الشخصية بنجاح</div>
                        <button 
                          type="button" 
                          onClick={() => {
                            setExtras({...extras, doctorPhotoBase64: ''});
                            setDoctorPhotoError('');
                          }}
                          style={{ marginTop: '6px', background: 'rgba(225,29,72,0.1)', color: '#e11d48', border: '1px solid rgba(225,29,72,0.3)', padding: '4px 12px', borderRadius: '8px', fontSize: '0.8rem', fontWeight: 700, cursor: 'pointer', fontFamily: 'Tajawal' }}
                        >
                          تغيير / حذف الصورة ✕
                        </button>
                      </div>
                    </div>
                  ) : (
                    <div 
                      onClick={() => document.getElementById('nursing-photo-upload')?.click()}
                      style={{ textAlign: 'center', padding: '15px', cursor: 'pointer' }}
                    >
                      <div style={{ fontSize: '2rem', marginBottom: '4px' }}>📷</div>
                      <div style={{ color: doctorPhotoError ? '#e11d48' : '#0284c7', fontWeight: 700, fontSize: '0.95rem' }}>
                        {doctorPhotoError || 'اضغط هنا لرفع الصورة الشخصية (إجباري لتقديم الطلب)'}
                      </div>
                      <div style={{ color: '#94a3b8', fontSize: '0.8rem', marginTop: '3px' }}>
                        صيغ الصور المدعومة: JPG, PNG, WEBP — الحد الأقصى: 2.5MB
                      </div>
                    </div>
                  )}

                  <input 
                    type="file" 
                    id="nursing-photo-upload"
                    accept="image/*"
                    style={{ display: 'none' }}
                    onChange={(e) => {
                      if (e.target.files && e.target.files[0]) {
                        compressAndSetPhoto(e.target.files[0]);
                      }
                    }}
                  />
                </div>

                {/* 1. الاسم الرباعي */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    الاسم الرباعي <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.name}
                    onChange={e => setFormData({...formData, name: e.target.value})}
                    placeholder="الاسم الرباعي كاملاً"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* 2. رقم الهوية */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    رقم الهوية <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.idNumber}
                    onChange={e => setFormData({...formData, idNumber: e.target.value})}
                    placeholder="رقم الهوية المكون من 9 خانات"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* 3. رقم الهاتف / الجوال */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    رقم الهاتف / الجوال <span style={{ color: '#e11d48' }}>* (إجباري)</span>
                  </label>
                  <input 
                    type="tel" required value={formData.phone}
                    onChange={e => setFormData({...formData, phone: e.target.value})}
                    placeholder="059xxxxxxx" dir="ltr"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', textAlign: 'right', outline: 'none' }}
                  />
                </div>

                {/* 3. مكان السكن (إجباري) */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    مكان السكن <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.address}
                    onChange={e => setFormData({...formData, address: e.target.value})}
                    placeholder="المدينة / المنطقة / مكان السكن بالتفصيل"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* 3. الجامعة المتخرج منها (إجباري) */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    الجامعة المتخرج منها <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.university}
                    onChange={e => setFormData({...formData, university: e.target.value})}
                    placeholder="اسم الجامعة التي تخرجت منها"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* 4. سنة التخرج (إجباري) */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    سنة التخرج <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.graduationYear}
                    onChange={e => setFormData({...formData, graduationYear: e.target.value})}
                    placeholder="مثال: 2022" dir="ltr"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', textAlign: 'right', outline: 'none' }}
                  />
                </div>

                {/* 5. العمر */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    العمر
                  </label>
                  <input 
                    type="text" value={extras.age}
                    onChange={e => setExtras({...extras, age: e.target.value})}
                    placeholder="العمر بالسنوات"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* 6. الجنس */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    الجنس
                  </label>
                  <div style={{ display: 'flex', gap: '20px' }}>
                    {['انثى', 'ذكر'].map(g => (
                      <label key={g} style={{ display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer', fontWeight: 600 }}>
                        <input 
                          type="radio" name="gender" value={g} checked={extras.gender === g}
                          onChange={e => setExtras({...extras, gender: e.target.value})}
                          style={{ width: '18px', height: '18px', accentColor: '#0284c7' }}
                        />
                        {g}
                      </label>
                    ))}
                  </div>
                </div>



                {/* 8. الايميل */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    الايميل <span style={{ fontSize: '0.85rem', color: '#64748b', fontWeight: 500 }}>(اختياري — يقبل كافة الصيغ والرموز)</span>
                  </label>
                  <input 
                    type="text" value={formData.email}
                    onChange={e => setFormData({...formData, email: e.target.value})}
                    placeholder="example@email.com (اختياري)" dir="ltr"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', textAlign: 'right', outline: 'none' }}
                  />
                </div>

                {/* 9. الدرجة العلمية */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    الدرجة العلمية <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <div style={{ display: 'flex', gap: '20px', flexWrap: 'wrap' }}>
                    {['بكالوريوس', 'ماجستير', 'دكتوراة'].map(deg => (
                      <label key={deg} style={{ display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer', fontWeight: 600 }}>
                        <input 
                          type="radio" name="degree" value={deg} required checked={extras.degree === deg}
                          onChange={e => setExtras({...extras, degree: e.target.value})}
                          style={{ width: '18px', height: '18px', accentColor: '#0284c7' }}
                        />
                        {deg}
                      </label>
                    ))}
                  </div>
                </div>

                {/* 10. طبيعة العمل في الهلال */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    طبيعة العمل في الهلال
                  </label>
                  <div style={{ display: 'flex', gap: '18px', flexWrap: 'wrap' }}>
                    {['على كادر الهلال الاحمر', 'عقد سنوي', 'مياومه'].map(t => (
                      <label key={t} style={{ display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer', fontWeight: 600 }}>
                        <input 
                          type="radio" name="employmentType" value={t} checked={extras.employmentType === t}
                          onChange={e => setExtras({...extras, employmentType: e.target.value})}
                          style={{ width: '18px', height: '18px', accentColor: '#0284c7' }}
                        />
                        {t}
                      </label>
                    ))}
                  </div>
                </div>

                {/* 11. هل تتقاضى اجر على التدريب (اختياري) */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    هل تتقاضى اجر على التدريب؟ <span style={{ color: '#64748b', fontSize: '0.85rem' }}>(اختياري)</span>
                  </label>
                  <div style={{ display: 'flex', gap: '25px' }}>
                    {['نعم', 'لا'].map(ans => (
                      <label key={ans} style={{ display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer', fontWeight: 600 }}>
                        <input 
                          type="radio" name="paidTraining" value={ans} checked={extras.paidTraining === ans}
                          onChange={e => setExtras({...extras, paidTraining: e.target.value})}
                          style={{ width: '18px', height: '18px', accentColor: '#0284c7' }}
                        />
                        {ans}
                      </label>
                    ))}
                  </div>
                </div>

                {/* 12. كم سنه خبره تدريسية */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    كم سنه خبره تدريسية <span style={{ color: '#64748b', fontSize: '0.85rem' }}>(اختياري)</span>
                  </label>
                  <input 
                    type="text" value={extras.teachingExperienceYears}
                    onChange={e => setExtras({...extras, teachingExperienceYears: e.target.value})}
                    placeholder="مثال: 3 سنوات"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* 13. الجامعات المتعاقد معها سابقاً والفترة (اختياري) */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    الجامعات المتعاقد معها سابقاً والفترة <span style={{ color: '#64748b', fontSize: '0.85rem' }}>(اختياري)</span>
                  </label>
                  <textarea 
                    value={extras.previousUniversitiesCountAndPeriod}
                    onChange={e => setExtras({...extras, previousUniversitiesCountAndPeriod: e.target.value})}
                    placeholder="اذكر الجامعات المتعاقد معها سابقاً والفترة الزمنية إن وجدت..."
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', minHeight: '80px', outline: 'none' }}
                  />
                </div>

                {/* 14. المساقات التي تدرسها (خاص بمدربي التمريض) */}
                {isUniversityNursingTrainer && (
                  <div style={{ marginBottom: '22px' }}>
                    <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                      المساقات التي تدرسها <span style={{ color: '#e11d48' }}>* (إجباري)</span>
                    </label>
                    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(180px, 1fr))', gap: '10px' }}>
                      {[
                        'اساسيات التمريض', 'اطفال', 'باطني و جراحة',
                        'تمريض متقدم', 'ادارة  التمريض', 'نسائية  و توليد'
                      ].map(course => (
                        <label key={course} style={{ display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer', background: '#f8fafc', padding: '8px 12px', borderRadius: '10px', border: '1px solid #e2e8f0', fontSize: '0.9rem', fontWeight: 600 }}>
                          <input 
                            type="checkbox" value={course} checked={extras.teachingCourses?.includes(course)}
                            onChange={() => toggleArrayItem('teachingCourses', course)}
                            style={{ width: '18px', height: '18px', accentColor: '#0284c7' }}
                          />
                          {course}
                        </label>
                      ))}
                    </div>
                  </div>
                )}

                {/* 15. الجامعات المتعاقد معها حالياً (إجباري مع خيار الكتابة الحرة) */}
                <div style={{ marginBottom: '24px', padding: '18px', background: '#f8fafc', borderRadius: '14px', border: '1.5px solid #0284c7' }}>
                  <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '8px', flexWrap: 'wrap', gap: '8px' }}>
                    <label style={{ fontWeight: 800, fontSize: '1rem', color: '#1e293b' }}>
                      🎓 الجامعات المتعاقد معها حالياً <span style={{ color: '#e11d48' }}>* (إجباري)</span>
                    </label>
                    <span style={{ fontSize: '0.8rem', color: '#0284c7', fontWeight: 700 }}>
                      {((extras.contractedUniversities?.length || 0) > 0 || (extras.customContractedUniversity || extras.previousContractedUniversity)?.trim()) 
                        ? `✅ تم التحديد (${((extras.contractedUniversities?.length || 0) + ((extras.customContractedUniversity || extras.previousContractedUniversity)?.trim() ? 1 : 0))})` 
                        : '⚠️ مطلوب اختيار أو كتابة جامعة واحدة على الأقل'}
                    </span>
                  </div>

                  <p style={{ margin: '0 0 12px 0', fontSize: '0.86rem', color: '#64748b' }}>
                    يمكنك اختيار جامعة أو أكثر من القائمة، و/أو كتابة اسم أي جامعة أو تفاصيل تريدها في خانة الكتابة الحرة أدناه:
                  </p>

                  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(210px, 1fr))', gap: '10px', marginBottom: '14px' }}>
                    {[
                      'جامعة الخليل',
                      'جامعة بوليتكنك فلسطين',
                      'الكلية الذكية للتعليم الحديث',
                      'الجامعة العربية الأمريكية',
                      'جامعة النجاح الوطنية',
                      'جامعة بيرزيت',
                      'جامعة بيت لحم'
                    ].map(uni => {
                      const isChecked = extras.contractedUniversities?.includes(uni);
                      return (
                        <label
                          key={uni}
                          style={{
                            display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer',
                            background: isChecked ? '#e0f2fe' : 'white',
                            padding: '10px 14px', borderRadius: '10px',
                            border: '1.5px solid ' + (isChecked ? '#0284c7' : '#cbd5e1'),
                            fontWeight: isChecked ? 700 : 500, fontSize: '0.9rem', color: isChecked ? '#075985' : '#334155',
                            transition: 'all 0.15s ease-in-out'
                          }}
                        >
                          <input
                            type="checkbox"
                            checked={!!isChecked}
                            onChange={() => toggleArrayItem('contractedUniversities', uni)}
                            style={{ width: '18px', height: '18px', accentColor: '#0284c7', cursor: 'pointer' }}
                          />
                          <span>{uni}</span>
                        </label>
                      );
                    })}
                  </div>

                  {/* خانة الكتابة الحرة - يكتب أي شيء يريده */}
                  <div style={{ marginTop: '10px', paddingTop: '12px', borderTop: '1px dashed #cbd5e1' }}>
                    <label style={{ display: 'block', marginBottom: '6px', fontWeight: 700, fontSize: '0.92rem', color: '#1e293b' }}>
                      ✍️ أو اكتب اسم الجامعة / الجامعات المتعاقد معها حالياً (كتابة حرة لأي تفاصيل تريدها):
                    </label>
                    <input
                      type="text"
                      value={extras.customContractedUniversity || extras.previousContractedUniversity || ''}
                      onChange={e => {
                        const val = e.target.value;
                        setExtras({
                          ...extras,
                          customContractedUniversity: val,
                          previousContractedUniversity: val
                        });
                      }}
                      placeholder="اكتب هنا أي جامعة متعاقد معها حالياً أو أي تفاصيل إضافية بحرية كاملة..."
                      style={{
                        width: '100%', padding: '13px 16px', borderRadius: '10px',
                        border: '1.5px solid #0284c7', fontSize: '0.95rem',
                        fontFamily: 'Tajawal', outline: 'none', background: 'white'
                      }}
                    />
                  </div>
                </div>

                {/* 15.2 فترة التدريب (من تاريخ إلى تاريخ) */}
                <div style={{ marginBottom: '22px', padding: '16px', background: '#f8fafc', borderRadius: '14px', border: '1.5px solid #cbd5e1' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 800, fontSize: '1rem', color: '#1e293b' }}>
                    📅 فترة التدريب المقررة <span style={{ color: '#e11d48' }}>* (تحديد تاريخ البدء والانتهاء)</span>
                  </label>
                  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '12px', marginTop: '6px' }}>
                    <div>
                      <label style={{ display: 'block', marginBottom: '6px', fontWeight: 700, fontSize: '0.88rem', color: '#334155' }}>
                        من تاريخ (تاريخ بداية التدريب) <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <input 
                        type="date" required value={formData.trainingStartDate}
                        onChange={e => setFormData({...formData, trainingStartDate: e.target.value})}
                        style={{ width: '100%', padding: '12px 14px', borderRadius: '10px', border: '1.5px solid #cbd5e1', fontSize: '0.92rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                      />
                    </div>
                    <div>
                      <label style={{ display: 'block', marginBottom: '6px', fontWeight: 700, fontSize: '0.88rem', color: '#334155' }}>
                        إلى تاريخ (تاريخ نهاية التدريب) <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <input 
                        type="date" required value={formData.trainingEndDate}
                        onChange={e => setFormData({...formData, trainingEndDate: e.target.value})}
                        style={{ width: '100%', padding: '12px 14px', borderRadius: '10px', border: '1.5px solid #cbd5e1', fontSize: '0.92rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                      />
                    </div>
                  </div>
                </div>

                {/* 16. أوقات الدوام بالأيام */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    أوقات الدوام بالأيام
                  </label>
                  <div style={{ display: 'flex', gap: '10px', flexWrap: 'wrap' }}>
                    {daysList.map(day => (
                      <label key={day} style={{ display: 'flex', alignItems: 'center', gap: '6px', cursor: 'pointer', background: '#f8fafc', padding: '8px 14px', borderRadius: '10px', border: '1px solid #e2e8f0', fontSize: '0.9rem', fontWeight: 600 }}>
                        <input 
                          type="checkbox" value={day} checked={extras.workDays?.includes(day)}
                          onChange={() => toggleArrayItem('workDays', day)}
                          style={{ width: '18px', height: '18px', accentColor: '#0284c7' }}
                        />
                        {day}
                      </label>
                    ))}
                  </div>
                </div>

                {/* 17. القسم الذي يتم التدريب فيه (خاص بمدربي التمريض) */}
                {isUniversityNursingTrainer && (
                  <div style={{ marginBottom: '22px' }}>
                    <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                      القسم الذي يتم التدريب فيه
                    </label>
                    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(180px, 1fr))', gap: '10px' }}>
                      {deptsList.map(dept => (
                        <label key={dept} style={{ display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer', background: '#f8fafc', padding: '8px 12px', borderRadius: '10px', border: '1px solid #e2e8f0', fontSize: '0.9rem', fontWeight: 600 }}>
                          <input 
                            type="checkbox" value={dept} checked={extras.trainingDepartments?.includes(dept)}
                            onChange={() => toggleArrayItem('trainingDepartments', dept)}
                            style={{ width: '18px', height: '18px', accentColor: '#0284c7' }}
                          />
                          {dept}
                        </label>
                      ))}
                    </div>
                  </div>
                )}

                {/* 18. ملاحظات ترغب باضافتها */}
                <div style={{ marginBottom: '26px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    ملاحظات ترغب باضافتها
                  </label>
                  <textarea 
                    value={formData.notes}
                    onChange={e => setFormData({...formData, notes: e.target.value})}
                    placeholder="أي ملاحظات أو تفاصيل أخرى ترغب في ذكرها..."
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', minHeight: '90px', outline: 'none' }}
                  />
                </div>

                {/* ══════════════════════════════════════════════════════════
                    قسم الاعتمادات والتواقيع الرسمية — مخفية عن المتقدم، تظهر عند الطباعة فقط
                ══════════════════════════════════════════════════════════ */}
                <div className="print-only-signatures" style={{
                  marginTop: '35px',
                  padding: '24px 20px',
                  background: 'linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%)',
                  borderRadius: '16px',
                  border: '1.5px solid #cbd5e1',
                  boxShadow: '0 4px 15px rgba(0,0,0,0.04)'
                }}>
                  <div style={{ textAlign: 'center', marginBottom: '20px' }}>
                    <div style={{ fontWeight: 900, color: '#1e293b', fontSize: '1.1rem', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '8px' }}>
                      <span>✍️</span> الاعتمادات والتواقيع الرسمية
                    </div>
                    <div style={{ fontSize: '0.82rem', color: '#64748b', marginTop: '4px' }}>
                      مستشفى الهلال الأحمر التخصصي — وحدة التطوير والتدريب
                    </div>
                  </div>

                  <div style={{
                    display: 'grid',
                    gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))',
                    gap: '16px'
                  }}>
                    {/* 1. رئيس القسم */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1px solid #e2e8f0',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(0,0,0,0.03)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '8px' }}>
                        توقيع رئيس القسم
                      </div>
                      <div style={{ fontSize: '0.8rem', color: '#64748b', marginBottom: '18px' }}>
                        القسم المعني بالتدريب
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #cbd5e1',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#94a3b8', marginTop: '6px' }}>
                        التوقيع والختم: ....................
                      </div>
                    </div>

                    {/* 2. المدير الطبي د. خالد السراحنة */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1px solid #e2e8f0',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(0,0,0,0.03)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                        المدير الطبي
                      </div>
                      <div style={{ fontWeight: 900, color: '#0369a1', fontSize: '0.95rem', marginBottom: '14px' }}>
                        د. خالد سراحنة
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #cbd5e1',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#94a3b8', marginTop: '6px' }}>
                        التوقيع والختم: ....................
                      </div>
                    </div>

                    {/* 3. مدير التمريض أ. زياد حمد (خاص بمدربي التمريض) */}
                    {isUniversityNursingTrainer && (
                      <div style={{
                        background: 'white',
                        padding: '16px',
                        borderRadius: '12px',
                        border: '1px solid #e2e8f0',
                        textAlign: 'center',
                        boxShadow: '0 2px 8px rgba(0,0,0,0.03)'
                      }}>
                        <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                          مدير التمريض
                        </div>
                        <div style={{ fontWeight: 900, color: '#0369a1', fontSize: '0.95rem', marginBottom: '14px' }}>
                          أ. زياد حمد
                        </div>
                        <div style={{
                          borderBottom: '2px dashed #cbd5e1',
                          height: '40px',
                          margin: '0 auto',
                          width: '80%'
                        }}></div>
                        <div style={{ fontSize: '0.75rem', color: '#94a3b8', marginTop: '6px' }}>
                          التوقيع والاعتماد: ....................
                        </div>
                      </div>
                    )}

                    {/* 4. مديرة وحدة التطوير والتدريب أ. نسرين عابدين */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1.5px solid #0284c7',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(2,132,199,0.08)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                        مديرة وحدة التطوير والتدريب
                      </div>
                      <div style={{ fontWeight: 900, color: '#0284c7', fontSize: '0.95rem', marginBottom: '14px' }}>
                        أ. نسرين عابدين
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #0284c7',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#0284c7', marginTop: '6px', fontWeight: 600 }}>
                        الاعتماد والختم الرسمي ✓
                      </div>
                    </div>

                    {/* 5. رئيس الجمعية د. طارق الجعبري */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1.5px solid #16a34a',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(22,163,74,0.08)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                        رئيس الجمعية
                      </div>
                      <div style={{ fontWeight: 900, color: '#16a34a', fontSize: '0.95rem', marginBottom: '14px' }}>
                        د. طارق الجعبري
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #16a34a',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#16a34a', marginTop: '6px', fontWeight: 600 }}>
                        الاعتماد النهائي والتوقيع ✓
                      </div>
                    </div>
                  </div>
                </div>
              </>
            ) : isContractedDoctor ? (
              /* ══════════════════════════════════════════════════════════
                 FORM 2: الأطباء المتعاقدين مع الجامعات (جميع الحقول إجبارية + صورة شخصية)
              ══════════════════════════════════════════════════════════ */
              <>
                <div style={{ marginBottom: '24px', padding: '16px', background: 'linear-gradient(135deg, #e0e7ff, #c7d2fe)', borderRadius: '14px', border: '2px solid #4338ca', textAlign: 'center' }}>
                  <div style={{ fontWeight: 800, color: '#312e81', fontSize: '1.2rem' }}>
                    🩺 نموذج تقديم الأطباء المتعاقدين مع الجامعات
                  </div>
                  <div style={{ fontSize: '0.85rem', color: '#4338ca', marginTop: '4px', fontWeight: 600 }}>
                    جميع الخانات في هذا النموذج إجبارية (*) ومطلوبة لإتمام اعتماد الطلب لدى وحدة التطوير والتدريب
                  </div>
                </div>

                {/* 1. الصورة الشخصية للطبيب (إجباري) */}
                <div id="doctor-photo-card" style={{ marginBottom: '24px', padding: '18px', background: '#f8fafc', borderRadius: '14px', border: `2px dashed ${doctorPhotoError ? '#e11d48' : extras.doctorPhotoBase64 ? '#10b981' : '#cbd5e1'}` }}>
                  <label style={{ display: 'block', marginBottom: '10px', fontWeight: 800, fontSize: '1rem', color: '#1e293b' }}>
                    📸 الصورة الشخصية للطبيب <span style={{ color: '#e11d48' }}>* (إجباري)</span>
                  </label>
                  
                  {extras.doctorPhotoBase64 ? (
                    <div style={{ display: 'flex', alignItems: 'center', gap: '16px', flexWrap: 'wrap' }}>
                      <img 
                        src={extras.doctorPhotoBase64} 
                        alt="صورة الطبيب" 
                        style={{ width: '85px', height: '85px', borderRadius: '50%', objectFit: 'cover', border: '3px solid #10b981', boxShadow: '0 4px 10px rgba(16,185,129,0.25)' }} 
                      />
                      <div>
                        <div style={{ color: '#059669', fontWeight: 800, fontSize: '0.95rem' }}>✅ تم إرفاق الصورة بنجاح</div>
                        <button
                          type="button"
                          onClick={() => {
                            setExtras({...extras, doctorPhotoBase64: ''});
                            setDoctorPhotoError('');
                          }}
                          style={{ marginTop: '6px', background: 'rgba(225,29,72,0.1)', color: '#e11d48', border: '1px solid rgba(225,29,72,0.3)', padding: '4px 12px', borderRadius: '8px', fontSize: '0.8rem', fontWeight: 700, cursor: 'pointer', fontFamily: 'Tajawal' }}
                        >
                          تغيير / حذف الصورة ✕
                        </button>
                      </div>
                    </div>
                  ) : (
                    <div 
                      onClick={() => document.getElementById('doctor-photo-upload')?.click()}
                      style={{ textAlign: 'center', padding: '15px', cursor: 'pointer' }}
                    >
                      <div style={{ fontSize: '2rem', marginBottom: '4px' }}>📷</div>
                      <div style={{ color: doctorPhotoError ? '#e11d48' : '#4338ca', fontWeight: 700, fontSize: '0.95rem' }}>
                        {doctorPhotoError || 'اضغط هنا لرفع الصورة الشخصية للطبيب (إجباري)'}
                      </div>
                      <div style={{ color: '#94a3b8', fontSize: '0.8rem', marginTop: '3px' }}>
                        صيغ الصور المدعومة: JPG, PNG, WEBP — الحد الأقصى: 2MB
                      </div>
                    </div>
                  )}

                  <input 
                    type="file" 
                    id="doctor-photo-upload"
                    accept="image/*"
                    style={{ display: 'none' }}
                    onChange={(e) => {
                      if (e.target.files && e.target.files[0]) {
                        compressAndSetPhoto(e.target.files[0]);
                      }
                    }}
                  />
                </div>

                {/* 2. الاسم الرباعي للطبيب */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    الاسم الرباعي للطبيب <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.name}
                    onChange={e => setFormData({...formData, name: e.target.value})}
                    placeholder="الاسم الرباعي للطبيب كما هو في الهوية الرسمية"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* 3. رقم الهوية */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    رقم الهوية <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.idNumber}
                    onChange={e => setFormData({...formData, idNumber: e.target.value})}
                    placeholder="رقم الهوية الرسمية (9 أرقام)" dir="ltr"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', textAlign: 'right', outline: 'none' }}
                  />
                </div>

                {/* 4. رقم الجوال */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    رقم الجوال <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="tel" required value={formData.phone}
                    onChange={e => setFormData({...formData, phone: e.target.value})}
                    placeholder="059xxxxxxx" dir="ltr"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', textAlign: 'right', outline: 'none' }}
                  />
                </div>

                {/* 5. البريد الإلكتروني */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    البريد الإلكتروني <span style={{ fontSize: '0.85rem', color: '#64748b', fontWeight: 500 }}>(اختياري — يقبل كافة الصيغ والرموز)</span>
                  </label>
                  <input 
                    type="text" value={formData.email}
                    onChange={e => setFormData({...formData, email: e.target.value})}
                    placeholder="doctor@example.com (اختياري)" dir="ltr"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', textAlign: 'right', outline: 'none' }}
                  />
                </div>

                {/* 6. الجامعة المتخرج منها للطبيب (كلية الطب) */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    🎓 الجامعة المتخرج منها (كلية الطب) <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.university}
                    onChange={e => setFormData({...formData, university: e.target.value})}
                    placeholder="اسم الجامعة / كلية الطب التي تخرجت منها (مثال: جامعة النجاح، جامعة القدس، جامعة القاهرة...)"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* سنة التخرج للطبيب */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    سنة التخرج من كلية الطب <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.graduationYear}
                    onChange={e => setFormData({...formData, graduationYear: e.target.value})}
                    placeholder="مثال: 2020" dir="ltr"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', textAlign: 'right', outline: 'none' }}
                  />
                </div>

                {/* 7. التخصص الطبي الدقيق */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    التخصص الطبي الدقيق <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={extras.specialty}
                    onChange={e => setExtras({...extras, specialty: e.target.value})}
                    placeholder="مثال: جراحة عامة، باطني، أطفال، نسائية وتوليد، تخدير، عظام..."
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* 7. طبيعة الوظيفة في مستشفى الهلال الأحمر (إجباري) */}
                <div style={{ marginBottom: '24px', padding: '16px', background: '#f8fafc', borderRadius: '14px', border: '1.5px solid #cbd5e1' }}>
                  <label style={{ display: 'block', marginBottom: '10px', fontWeight: 800, fontSize: '1rem', color: '#1e293b' }}>
                    طبيعة الوظيفة في مستشفى الهلال الأحمر <span style={{ color: '#e11d48' }}>* (إجباري)</span>
                  </label>
                  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '10px' }}>
                    {[
                      'على كادر الهلال الأحمر (موظف كادر رسمي)',
                      'عقد عمل سنوي',
                      'عقد عمل جزئي / بالساعة',
                      'طبيب استشاري متعاقد',
                      'مياومة / مكافأة',
                      'أخرى'
                    ].map(type => (
                      <label 
                        key={type} 
                        style={{ 
                          display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer',
                          background: extras.crescentJobNature === type ? 'rgba(67, 56, 202, 0.08)' : 'white',
                          border: extras.crescentJobNature === type ? '2px solid #4338ca' : '1px solid #e2e8f0',
                          padding: '10px 14px', borderRadius: '10px', fontWeight: 600, fontSize: '0.88rem'
                        }}
                      >
                        <input 
                          type="radio" name="crescentJobNature" value={type} required
                          checked={extras.crescentJobNature === type}
                          onChange={e => setExtras({...extras, crescentJobNature: e.target.value})}
                          style={{ width: '18px', height: '18px', accentColor: '#4338ca' }}
                        />
                        {type}
                      </label>
                    ))}
                  </div>

                  {extras.crescentJobNature === 'أخرى' && (
                    <div style={{ marginTop: '12px' }}>
                      <input 
                        type="text" required value={extras.customCrescentJobNature}
                        onChange={e => setExtras({...extras, customCrescentJobNature: e.target.value})}
                        placeholder="يرجى كتابة تفاصيل طبيعة الوظيفة والتعاقد..."
                        style={{ width: '100%', padding: '12px 14px', borderRadius: '10px', border: '1.5px solid #4338ca', fontSize: '0.9rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                      />
                    </div>
                  )}
                </div>

                {/* 8. اسم الجامعة / الجامعات المتعاقد معها (واحدة أو أكثر) */}
                <div style={{ marginBottom: '24px', padding: '16px', background: '#f8fafc', borderRadius: '14px', border: '1.5px solid #cbd5e1' }}>
                  <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '8px', flexWrap: 'wrap' }}>
                    <label style={{ fontWeight: 800, fontSize: '1rem', color: '#1e293b' }}>
                      اسم الجامعة المتعاقد معها <span style={{ color: '#e11d48' }}>* (يمكن اختيار جامعة واحدة أو أكثر)</span>
                    </label>
                    <span style={{ fontSize: '0.78rem', color: '#6366f1', fontWeight: 700 }}>
                      تم اختيار: ({extras.contractedUniversities?.length || 0})
                    </span>
                  </div>
                  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(210px, 1fr))', gap: '10px', marginTop: '10px' }}>
                    {[
                      'جامعة القدس - أبو ديس',
                      'جامعة الخليل',
                      'جامعة بوليتكنك فلسطين',
                      'الجامعة العربية الأمريكية',
                      'جامعة النجاح الوطنية',
                      'جامعة بيرزيت',
                      'جامعة بيت لحم',
                      'جامعة أخرى'
                    ].map(uni => {
                      const isChecked = extras.contractedUniversities?.includes(uni);
                      return (
                        <label 
                          key={uni} 
                          style={{ 
                            display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer',
                            background: isChecked ? '#e0e7ff' : 'white',
                            padding: '10px 14px', borderRadius: '10px',
                            border: '1.5px solid ' + (isChecked ? '#4f46e5' : '#cbd5e1'),
                            fontWeight: isChecked ? 700 : 500, fontSize: '0.9rem', color: isChecked ? '#3730a3' : '#334155'
                          }}
                        >
                          <input 
                            type="checkbox"
                            checked={isChecked}
                            onChange={() => toggleArrayItem('contractedUniversities', uni)}
                            style={{ width: '18px', height: '18px', accentColor: '#4f46e5', cursor: 'pointer' }}
                          />
                          <span>{uni}</span>
                        </label>
                      );
                    })}
                  </div>

                  {extras.contractedUniversities?.includes('جامعة أخرى') && (
                    <div style={{ marginTop: '12px' }}>
                      <input 
                        type="text" required value={extras.customContractedUniversity}
                        onChange={e => setExtras({...extras, customContractedUniversity: e.target.value})}
                        placeholder="يرجى كتابة اسم الجامعة المتعاقد معها..."
                        style={{ width: '100%', padding: '12px 14px', borderRadius: '10px', border: '1.5px solid #4338ca', fontSize: '0.9rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                      />
                    </div>
                  )}
                </div>

                {/* فترة التعاقد / التدريب (من تاريخ إلى تاريخ) */}
                <div style={{ marginBottom: '22px', padding: '16px', background: '#f8fafc', borderRadius: '14px', border: '1.5px solid #cbd5e1' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 800, fontSize: '1rem', color: '#1e293b' }}>
                    📅 فترة التعاقد والتدريب في المستشفى <span style={{ color: '#e11d48' }}>* (تحديد تاريخ البدء والانتهاء)</span>
                  </label>
                  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '12px', marginTop: '6px' }}>
                    <div>
                      <label style={{ display: 'block', marginBottom: '6px', fontWeight: 700, fontSize: '0.88rem', color: '#334155' }}>
                        من تاريخ (بدء التدريب / التعاقد) <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <input 
                        type="date" required value={formData.trainingStartDate}
                        onChange={e => setFormData({...formData, trainingStartDate: e.target.value})}
                        style={{ width: '100%', padding: '12px 14px', borderRadius: '10px', border: '1.5px solid #cbd5e1', fontSize: '0.92rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                      />
                    </div>
                    <div>
                      <label style={{ display: 'block', marginBottom: '6px', fontWeight: 700, fontSize: '0.88rem', color: '#334155' }}>
                        إلى تاريخ (انتهاء التدريب / التعاقد) <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <input 
                        type="date" required value={formData.trainingEndDate}
                        onChange={e => setFormData({...formData, trainingEndDate: e.target.value})}
                        style={{ width: '100%', padding: '12px 14px', borderRadius: '10px', border: '1.5px solid #cbd5e1', fontSize: '0.92rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                      />
                    </div>
                  </div>
                </div>

                {/* 9. أيام الدوام الأسبوعية (إجباري) */}
                <div style={{ marginBottom: '22px', padding: '16px', background: '#f8fafc', borderRadius: '14px', border: '1.5px solid #cbd5e1' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    أيام الدوام الأسبوعية <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <div style={{ display: 'flex', gap: '10px', flexWrap: 'wrap' }}>
                    {daysList.map(day => (
                      <label key={day} style={{ display: 'flex', alignItems: 'center', gap: '6px', cursor: 'pointer', background: 'white', padding: '8px 14px', borderRadius: '10px', border: extras.workDays?.includes(day) ? '1.5px solid #4338ca' : '1px solid #e2e8f0', fontSize: '0.9rem', fontWeight: 600 }}>
                        <input 
                          type="checkbox" value={day} checked={extras.workDays?.includes(day)}
                          onChange={() => toggleArrayItem('workDays', day)}
                          style={{ width: '18px', height: '18px', accentColor: '#4338ca' }}
                        />
                        {day}
                      </label>
                    ))}
                  </div>
                </div>

                {/* 10. القسم أو الأقسام التي يتم التدريب فيها (إجباري) */}
                <div style={{ marginBottom: '22px', padding: '16px', background: '#f8fafc', borderRadius: '14px', border: '1.5px solid #cbd5e1' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    القسم أو الأقسام التي يتم التدريب فيها <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(180px, 1fr))', gap: '10px' }}>
                    {deptsList.map(dept => (
                      <label key={dept} style={{ display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer', background: 'white', padding: '8px 12px', borderRadius: '10px', border: extras.trainingDepartments?.includes(dept) ? '1.5px solid #4338ca' : '1px solid #e2e8f0', fontSize: '0.9rem', fontWeight: 600 }}>
                        <input 
                          type="checkbox" value={dept} checked={extras.trainingDepartments?.includes(dept)}
                          onChange={() => toggleArrayItem('trainingDepartments', dept)}
                          style={{ width: '18px', height: '18px', accentColor: '#4338ca' }}
                        />
                        {dept}
                      </label>
                    ))}
                  </div>
                </div>

                {/* 11. ملاحظات إضافية */}
                <div style={{ marginBottom: '26px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    ملاحظات إضافية
                  </label>
                  <textarea 
                    value={formData.notes}
                    onChange={e => setFormData({...formData, notes: e.target.value})}
                    placeholder="أي ملاحظات أو تفاصيل أخرى ترغب في ذكرها..."
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', minHeight: '90px', outline: 'none' }}
                  />
                </div>

                {/* ══════════════════════════════════════════════════════════
                    قسم الاعتمادات والتواقيع الرسمية — مخفية عن المتقدم، تظهر عند الطباعة
                ══════════════════════════════════════════════════════════ */}
                <div className="print-only-signatures" style={{
                  marginTop: '35px',
                  marginBottom: '25px',
                  padding: '24px 20px',
                  background: 'linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%)',
                  borderRadius: '16px',
                  border: '1.5px solid #cbd5e1',
                  boxShadow: '0 4px 15px rgba(0,0,0,0.04)'
                }}>
                  <div style={{ textAlign: 'center', marginBottom: '20px' }}>
                    <div style={{ fontWeight: 900, color: '#1e293b', fontSize: '1.1rem', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '8px' }}>
                      <span>✍️</span> الاعتمادات والتواقيع الرسمية
                    </div>
                    <div style={{ fontSize: '0.82rem', color: '#64748b', marginTop: '4px' }}>
                      مستشفى الهلال الأحمر التخصصي — وحدة التطوير والتدريب
                    </div>
                  </div>

                  <div style={{
                    display: 'grid',
                    gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))',
                    gap: '16px'
                  }}>
                    {/* 1. المدير الطبي د. خالد السراحنة */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1px solid #e2e8f0',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(0,0,0,0.03)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                        المدير الطبي
                      </div>
                      <div style={{ fontWeight: 900, color: '#0369a1', fontSize: '0.95rem', marginBottom: '14px' }}>
                        د. خالد سراحنة
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #cbd5e1',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#94a3b8', marginTop: '6px' }}>
                        التوقيع والختم: ....................
                      </div>
                    </div>

                    {/* 3. مديرة وحدة التطوير والتدريب أ. نسرين عابدين */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1.5px solid #0284c7',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(2,132,199,0.08)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                        مديرة وحدة التطوير والتدريب
                      </div>
                      <div style={{ fontWeight: 900, color: '#0284c7', fontSize: '0.95rem', marginBottom: '14px' }}>
                        أ. نسرين عابدين
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #0284c7',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#0284c7', marginTop: '6px', fontWeight: 600 }}>
                        الاعتماد والختم الرسمي ✓
                      </div>
                    </div>

                    {/* 4. رئيس الجمعية د. طارق الجعبري */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1.5px solid #16a34a',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(22,163,74,0.08)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                        رئيس الجمعية
                      </div>
                      <div style={{ fontWeight: 900, color: '#16a34a', fontSize: '0.95rem', marginBottom: '14px' }}>
                        د. طارق الجعبري
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #16a34a',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#16a34a', marginTop: '6px', fontWeight: 600 }}>
                        الاعتماد النهائي والتوقيع ✓
                      </div>
                    </div>
                  </div>
                </div>
              </>
            ) : (
              /* ══════════════════════════════════════════════════════════
                 STANDARD FORM (Internship, Physical Therapy, Lab, etc.)
              ══════════════════════════════════════════════════════════ */
              <>
                {/* ══════ الصورة الشخصية للمتقدم (إجباري لكافة الطلبات) ══════ */}
                <div 
                  id="applicant-photo-card"
                  style={{ 
                    marginBottom: '26px', 
                    padding: '20px', 
                    background: photoError ? 'rgba(225,29,72,0.06)' : '#f8fafc', 
                    borderRadius: '16px', 
                    border: '2px dashed ' + (photoError ? '#e11d48' : photoBase64 ? '#10b981' : (isUntouchedCategory ? '#0284c7' : currentTheme.photoBorder)),
                    boxShadow: photoBase64 ? '0 4px 15px rgba(16,185,129,0.1)' : 'none',
                    transition: 'all 0.3s ease'
                  }}
                >
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 800, fontSize: '1.05rem', color: '#1e293b' }}>
                    📸 الصورة الشخصية للمتقدم <span style={{ color: '#e11d48' }}>* (إجباري لتقديم الطلب)</span>
                  </label>
                  <p style={{ margin: '0 0 14px 0', fontSize: '0.85rem', color: '#64748b' }}>
                    يرجى إرفاق صورة شخصية واضحة وحديثة (تُعتمد للبطاقة التعريفية والملف الرسمي في المستشفى)
                  </p>

                  {photoBase64 ? (
                    <div style={{ display: 'flex', alignItems: 'center', gap: '16px', padding: '12px 16px', background: 'white', borderRadius: '12px', border: '1.5px solid #10b981', boxShadow: '0 2px 8px rgba(0,0,0,0.05)' }}>
                      <img 
                        src={photoBase64} 
                        alt="الصورة الشخصية" 
                        style={{ width: '80px', height: '80px', borderRadius: '12px', objectFit: 'cover', border: '3px solid #10b981', boxShadow: '0 4px 10px rgba(16,185,129,0.25)' }} 
                      />
                      <div>
                        <div style={{ color: '#059669', fontWeight: 800, fontSize: '0.95rem' }}>✓ تم إرفاق الصورة الشخصية بنجاح</div>
                        <div style={{ color: '#64748b', fontSize: '0.8rem', marginTop: '3px' }}>الصورة معتمدة وجاهزة للإرسال مع الطلب</div>
                        <button 
                          type="button" 
                          onClick={() => {
                            setPhotoBase64('');
                            setPhotoFileName('');
                            setPhotoError('');
                          }}
                          style={{ marginTop: '8px', background: 'rgba(225,29,72,0.1)', color: '#e11d48', border: '1px solid rgba(225,29,72,0.3)', padding: '5px 14px', borderRadius: '8px', fontSize: '0.82rem', fontWeight: 700, cursor: 'pointer', fontFamily: 'Tajawal' }}
                        >
                          تغيير / حذف الصورة ✕
                        </button>
                      </div>
                    </div>
                  ) : (
                    <div 
                      onClick={() => document.getElementById('standard-photo-upload')?.click()}
                      style={{ 
                        textAlign: 'center', 
                        padding: '24px 15px', 
                        cursor: 'pointer',
                        background: 'white',
                        borderRadius: '12px',
                        border: '1.5px solid ' + (photoError ? '#e11d48' : '#e2e8f0'),
                        transition: 'all 0.2s ease'
                      }}
                      onMouseEnter={e => e.currentTarget.style.borderColor = '#0284c7'}
                      onMouseLeave={e => e.currentTarget.style.borderColor = photoError ? '#e11d48' : '#e2e8f0'}
                    >
                      <div style={{ fontSize: '2.5rem', marginBottom: '8px' }}>📷</div>
                      <div style={{ color: photoError ? '#e11d48' : '#0284c7', fontWeight: 800, fontSize: '1rem' }}>
                        {photoError || 'اضغط هنا لرفع الصورة الشخصية (إجباري)'}
                      </div>
                      <div style={{ color: '#94a3b8', fontSize: '0.82rem', marginTop: '5px' }}>
                        التقط صورة بالكاميرا أو اختر صورة من الهاتف (JPG, PNG, WEBP)
                      </div>
                    </div>
                  )}

                  <input 
                    type="file" 
                    id="standard-photo-upload" 
                    accept="image/*" 
                    style={{ display: 'none' }} 
                    onChange={(e) => {
                      if (e.target.files && e.target.files[0]) {
                        compressAndSetPhoto(e.target.files[0]);
                      }
                    }}
                  />
                </div>

                {/* Name */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    الاسم الرباعي <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.name}
                    onChange={e => setFormData({...formData, name: e.target.value})}
                    placeholder="الاسم كما هو في الهوية"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* ID Number */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    رقم الهوية <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.idNumber}
                    onChange={e => setFormData({...formData, idNumber: e.target.value})}
                    placeholder="رقم الهوية المكون من 9 خانات"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* Phone */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    رقم الهاتف <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="tel" required value={formData.phone}
                    onChange={e => setFormData({...formData, phone: e.target.value})}
                    placeholder="059xxxxxxx" dir="ltr"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', textAlign: 'right', outline: 'none' }}
                  />
                </div>

                {/* Address */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    مكان السكن <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.address}
                    onChange={e => setFormData({...formData, address: e.target.value})}
                    placeholder="المدينة / المنطقة"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* University */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    الجامعة <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.university}
                    onChange={e => setFormData({...formData, university: e.target.value})}
                    placeholder="اسم الجامعة"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* Graduation Year */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    سنة التخرج <span style={{ color: '#e11d48' }}>*</span>
                  </label>
                  <input 
                    type="text" required value={formData.graduationYear}
                    onChange={e => setFormData({...formData, graduationYear: e.target.value})}
                    placeholder="سنة التخرج (مثال: 2024)"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                  />
                </div>

                {/* Study System & Internship Year — ONLY FOR INTERNSHIP (المتقدمين للإمتياز) */}
                {isInternship && (
                  <>
                    <div style={{ marginBottom: '22px' }}>
                      <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                        نظام الدراسة <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <select 
                        required value={formData.studySystem}
                        onChange={e => setFormData({...formData, studySystem: e.target.value})}
                        style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                      >
                        <option value="" disabled>اختر نظام الدراسة / الدوام</option>
                        <option value="5+2">5+2</option>
                        <option value="6+1">6+1</option>
                      </select>
                    </div>

                    <div style={{ marginBottom: '22px' }}>
                      <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                        سنة الامتياز <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <select 
                        required value={formData.internshipYear}
                        onChange={e => setFormData({...formData, internshipYear: e.target.value})}
                        style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                      >
                        <option value="" disabled>اختر السنة المستهدفة أو الحالية</option>
                        <option value="سنة أولى امتياز">سنة أولى امتياز</option>
                        <option value="سنة ثانية امتياز">سنة ثانية امتياز</option>
                      </select>
                    </div>
                  </>
                )}

                {/* ══════════════════════════════════════════════════════════
                    المدرب المشرف السريري (إجباري لكافة المتدربين في كافة الأقسام)
                ══════════════════════════════════════════════════════════ */}
                <div 
                  id="trainer-selection-card"
                  style={{
                    marginBottom: '26px',
                    padding: '22px 20px',
                    background: '#f8fafc',
                    borderRadius: '16px',
                    border: formData.trainerName?.trim() ? '2px solid #059669' : '2px solid #cbd5e1',
                    boxShadow: formData.trainerName?.trim() ? '0 4px 15px rgba(5,150,105,0.08)' : '0 2px 8px rgba(0,0,0,0.03)',
                    transition: 'all 0.25s ease'
                  }}
                >
                  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: '8px', flexWrap: 'wrap', gap: '8px' }}>
                    <label style={{ fontWeight: 800, fontSize: '1.05rem', color: '#1e293b', display: 'flex', alignItems: 'center', gap: '8px' }}>
                      <span style={{ fontSize: '1.25rem' }}>🩺</span>
                      <span>من هو المدرب السريري المشرف عليك؟</span>
                      <span style={{ color: '#e11d48', fontSize: '0.95rem' }}>* (إجباري)</span>
                    </label>
                    {formData.trainerName?.trim() && (
                      <span style={{ background: '#dcfce7', color: '#15803d', padding: '4px 12px', borderRadius: '20px', fontSize: '0.8rem', fontWeight: 800 }}>
                        ✓ تم تحديد المدرب
                      </span>
                    )}
                  </div>

                  <p style={{ margin: '0 0 16px 0', fontSize: '0.86rem', color: '#64748b', lineHeight: 1.6 }}>
                    يرجى اختيار المدرب السريري المعتمد المشرف على تدريبك، ليقوم البرنامج تلقائياً بوضع اسمك وتوزيع ملفك تحت إشراف هذا المدرب في النظام.
                  </p>

                  {/* قائمة اختيار المدرب Dropdown */}
                  <div style={{ position: 'relative', marginBottom: isCustomTrainer ? '14px' : '0' }}>
                    <select
                      required
                      value={isCustomTrainer ? '__CUSTOM__' : (formData.trainerName || '')}
                      onChange={(e) => {
                        const val = e.target.value;
                        if (val === '__CUSTOM__') {
                          setIsCustomTrainer(true);
                          setFormData(prev => ({ ...prev, trainerName: customTrainerInput, supervisorName: customTrainerInput }));
                        } else {
                          setIsCustomTrainer(false);
                          setFormData(prev => ({ ...prev, trainerName: val, supervisorName: val }));
                        }
                      }}
                      style={{
                        width: '100%',
                        padding: '14px 16px',
                        borderRadius: '12px',
                        border: '1.5px solid ' + (formData.trainerName?.trim() ? '#059669' : '#94a3b8'),
                        fontSize: '0.98rem',
                        fontFamily: 'Tajawal',
                        fontWeight: 700,
                        color: formData.trainerName?.trim() ? '#0f172a' : '#64748b',
                        background: '#ffffff',
                        outline: 'none',
                        cursor: 'pointer',
                        boxShadow: '0 2px 6px rgba(0,0,0,0.04)'
                      }}
                    >
                      <option value="">-- اضغط هنا لاختيار المدرب المشرف الخاص بك من القائمة --</option>
                      
                      {deptTrainers.length > 0 && (
                        <optgroup label={`── 🩺 مدربو ${categoryName} المعتمدون ──`}>
                          {deptTrainers.map(t => (
                            <option key={t.name} value={t.name}>
                              {t.name} {t.university ? `(${t.university})` : ''}
                            </option>
                          ))}
                        </optgroup>
                      )}

                      {otherTrainers.length > 0 && (
                        <optgroup label="── 🏥 كافة المدربين السريريين والجامعيين بالمستشفى ──">
                          {otherTrainers.map(t => (
                            <option key={t.name} value={t.name}>
                              {t.name} {t.department ? `[${t.department}]` : ''} {t.university ? `(${t.university})` : ''}
                            </option>
                          ))}
                        </optgroup>
                      )}

                      <optgroup label="── ✏️ خيار إضافي ──">
                        <option value="__CUSTOM__">✏️ مدرب آخر / كتابة اسم مدرب غير مدرج بالقائمة...</option>
                      </optgroup>
                    </select>
                  </div>

                  {/* حقل كتابة اسم المدرب يدوياً عند اختيار مدرب آخر */}
                  {isCustomTrainer && (
                    <div style={{ marginTop: '12px', padding: '14px 16px', background: '#eff6ff', borderRadius: '12px', border: '1.5px dashed #3b82f6' }}>
                      <label style={{ display: 'block', marginBottom: '6px', fontWeight: 700, fontSize: '0.92rem', color: '#1e40af' }}>
                        ✍️ اكتب اسم المدرب المشرف الخاص بك بالكامل: <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <input
                        type="text"
                        required
                        value={customTrainerInput}
                        onChange={(e) => {
                          const v = e.target.value;
                          setCustomTrainerInput(v);
                          setFormData(prev => ({ ...prev, trainerName: v, supervisorName: v }));
                        }}
                        placeholder="الاسم الرباعي للمدرب المشرف..."
                        style={{
                          width: '100%',
                          padding: '12px 14px',
                          borderRadius: '10px',
                          border: '1.5px solid #3b82f6',
                          fontSize: '0.96rem',
                          fontFamily: 'Tajawal',
                          fontWeight: 600,
                          outline: 'none',
                          background: '#ffffff',
                          color: '#0f172a'
                        }}
                      />
                      <div style={{ fontSize: '0.8rem', color: '#64748b', marginTop: '6px' }}>
                        سيتم اعتماد هذا المدرب كمشرف رئيسي عليك وتوزيع اسمك تحته تلقائياً فور إرسال الطلب.
                      </div>
                    </div>
                  )}

                  {formData.trainerName?.trim() && (
                    <div style={{ marginTop: '12px', display: 'flex', alignItems: 'center', gap: '8px', fontSize: '0.88rem', color: '#065f46', fontWeight: 700 }}>
                      <span>✅ المدرب المشرف المحدد:</span>
                      <span style={{ color: '#047857', background: '#dcfce7', padding: '2px 10px', borderRadius: '6px' }}>
                        {formData.trainerName}
                      </span>
                      <span style={{ fontSize: '0.8rem', color: '#64748b', fontWeight: 500 }}>
                        (سيتم وضع اسمك تلقائياً تحت هذا المدرب في النظام)
                      </span>
                    </div>
                  )}
                </div>

                {/* 📅 فترة التدريب المطلوبة (من تاريخ ... إلى تاريخ ...) لكافة الأقسام */}
                {!isVolunteer && (
                  <div style={{
                    marginBottom: '22px',
                    padding: '16px 18px',
                    background: '#f8fafc',
                    borderRadius: '14px',
                    border: '1.5px solid #cbd5e1'
                  }}>
                    <label style={{ display: 'block', marginBottom: '8px', fontWeight: 800, fontSize: '1rem', color: '#1e293b' }}>
                      📅 فترة التدريب المطلوبة <span style={{ color: '#e11d48' }}>* (من تاريخ إلى تاريخ)</span>
                    </label>
                    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '12px', marginTop: '6px' }}>
                      <div>
                        <label style={{ display: 'block', marginBottom: '6px', fontWeight: 700, fontSize: '0.88rem', color: '#334155' }}>
                          من تاريخ (تاريخ بدء التدريب المطلوب) <span style={{ color: '#e11d48' }}>*</span>
                        </label>
                        <input 
                          type="date" required value={formData.trainingStartDate}
                          onChange={e => setFormData({...formData, trainingStartDate: e.target.value})}
                          style={{ width: '100%', padding: '12px 14px', borderRadius: '10px', border: '1.5px solid #cbd5e1', fontSize: '0.92rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                        />
                      </div>
                      <div>
                        <label style={{ display: 'block', marginBottom: '6px', fontWeight: 700, fontSize: '0.88rem', color: '#334155' }}>
                          إلى تاريخ (تاريخ انتهاء التدريب المتوقع) <span style={{ color: '#e11d48' }}>*</span>
                        </label>
                        <input 
                          type="date" required value={formData.trainingEndDate}
                          onChange={e => setFormData({...formData, trainingEndDate: e.target.value})}
                          style={{ width: '100%', padding: '12px 14px', borderRadius: '10px', border: '1.5px solid #cbd5e1', fontSize: '0.92rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                        />
                      </div>
                    </div>
                  </div>
                )}

                {/* ══════ خيارات واختيار القسم الطبي — خاص بـ (طب تدريب سريري) ══════ */}
                {isMedicalTraining && (
                  <div style={{
                    marginBottom: '24px',
                    padding: '18px 20px',
                    background: '#f0f9ff',
                    borderRadius: '16px',
                    border: '2px solid #0284c7',
                    boxShadow: '0 4px 15px rgba(2, 132, 199, 0.1)'
                  }}>
                    <label style={{ display: 'block', marginBottom: '6px', fontWeight: 800, fontSize: '1.05rem', color: '#0369a1' }}>
                      🏥 القسم الطبي المطلوب التدريب فيه <span style={{ color: '#e11d48' }}>*</span>
                    </label>
                    <p style={{ margin: '0 0 14px 0', fontSize: '0.86rem', color: '#64748b' }}>
                      يرجى تحديد القسم الطبي التخصصي الذي ترغب في قضاء فترة التدريب والتأهيل السريري فيه بمستشفى الهلال الأحمر
                    </p>

                    <div style={{ marginBottom: '14px' }}>
                      <select
                        required
                        value={formData.desiredDepartment}
                        onChange={e => setFormData({ ...formData, desiredDepartment: e.target.value, department: e.target.value })}
                        style={{
                          width: '100%',
                          padding: '14px 16px',
                          borderRadius: '12px',
                          border: '2px solid #0284c7',
                          fontSize: '1rem',
                          fontFamily: 'Tajawal',
                          fontWeight: 700,
                          outline: 'none',
                          background: 'white',
                          color: '#0f172a',
                          boxShadow: '0 2px 6px rgba(0,0,0,0.05)'
                        }}
                      >
                        <option value="" disabled>-- اضغط هنا لاختيار القسم الطبي المطلوب --</option>
                        <option value="الجراحة العامة">الجراحة العامة</option>
                        <option value="النسائية والتوليد">النسائية والتوليد</option>
                        <option value="طب الأطفال">طب الأطفال</option>
                        <option value="الطب الباطني">الطب الباطني</option>
                        <option value="طب وجراحة العظام">طب وجراحة العظام</option>
                        <option value="طب الطوارئ">طب الطوارئ</option>
                        <option value="العناية المكثفة (ICU)">العناية المكثفة (ICU)</option>
                        <option value="التخدير والإنعاش">التخدير والإنعاش</option>
                        <option value="طب وجراحة العيون">طب وجراحة العيون</option>
                        <option value="الأشعة والتصوير الطبي">الأشعة والتصوير الطبي</option>
                        <option value="المسالك البولية">المسالك البولية</option>
                        <option value="الأنف والأذن والحنجرة (ENT)">الأنف والأذن والحنجرة (ENT)</option>
                        <option value="أخرى">قسم آخر (تحديد يدوي)</option>
                      </select>
                    </div>

                    {/* حقل مخصص إذا اختار المتقدم "قسم آخر" */}
                    {formData.desiredDepartment === 'أخرى' && (
                      <div style={{ marginTop: '12px', marginBottom: '14px' }}>
                        <label style={{ display: 'block', marginBottom: '6px', fontWeight: 700, fontSize: '0.9rem', color: '#334155' }}>
                          يرجى كتابة اسم القسم الطبي المطلوب بالتفصيل: <span style={{ color: '#e11d48' }}>*</span>
                        </label>
                        <input
                          type="text"
                          required
                          value={formData.customDesiredDepartment}
                          onChange={e => setFormData({ ...formData, customDesiredDepartment: e.target.value })}
                          placeholder="اكتب اسم القسم الطبي المطلوب..."
                          style={{
                            width: '100%',
                            padding: '12px 14px',
                            borderRadius: '10px',
                            border: '1.5px solid #0284c7',
                            fontSize: '0.95rem',
                            fontFamily: 'Tajawal',
                            outline: 'none',
                            background: 'white'
                          }}
                        />
                      </div>
                    )}

                    {/* الأقسام الطبية الإضافية / التدويرات (اختياري) */}
                    <div style={{ marginTop: '16px', paddingTop: '14px', borderTop: '1px dashed #bae6fd' }}>
                      <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '0.92rem', color: '#0369a1' }}>
                        تدويرات سريرية أو أقسام طبية إضافية ترغب بالتدريب فيها <span style={{ color: '#64748b', fontSize: '0.82rem', fontWeight: 500 }}>(اختياري)</span>:
                      </label>
                      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(150px, 1fr))', gap: '8px' }}>
                        {[
                          'الجراحة العامة', 'النسائية والتوليد', 'طب الأطفال', 'الطب الباطني',
                          'طب وجراحة العظام', 'طب الطوارئ', 'العناية المكثفة', 'التخدير', 'العيون', 'الأشعة'
                        ].map(dept => {
                          const isSelected = extras.trainingDepartments?.includes(dept);
                          return (
                            <label
                              key={dept}
                              style={{
                                display: 'flex',
                                alignItems: 'center',
                                gap: '8px',
                                cursor: 'pointer',
                                background: isSelected ? '#bae6fd' : 'white',
                                padding: '8px 12px',
                                borderRadius: '10px',
                                border: isSelected ? '1.5px solid #0284c7' : '1px solid #cbd5e1',
                                fontSize: '0.86rem',
                                fontWeight: 700,
                                color: isSelected ? '#0369a1' : '#334155',
                                transition: 'all 0.15s ease'
                              }}
                            >
                              <input
                                type="checkbox"
                                value={dept}
                                checked={isSelected}
                                onChange={() => toggleArrayItem('trainingDepartments', dept)}
                                style={{ width: '16px', height: '16px', accentColor: '#0284c7' }}
                              />
                              <span>{dept}</span>
                            </label>
                          );
                        })}
                      </div>
                    </div>
                  </div>
                )}


                {/* التخصص التمريضي لطلبة التمريض والامتياز */}
                {(isNursingTraining || isNursingInternship) && (
                  <div style={{ marginBottom: '22px' }}>
                    <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                      التخصص التمريضي <span style={{ color: '#e11d48' }}>*</span>
                    </label>
                    <input 
                      type="text" required value={formData.nursingSpecialty}
                      onChange={e => setFormData({...formData, nursingSpecialty: e.target.value})}
                      placeholder="مثال: تمريض عام، تمريض طوارئ، تمريض أطفال، قبالة..."
                      style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                    />
                  </div>
                )}

                {/* Email */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    البريد الإلكتروني <span style={{ fontSize: '0.85rem', color: '#64748b', fontWeight: 500 }}>(اختياري — يقبل كافة الصيغ والرموز)</span>
                  </label>
                  <input 
                    type="text" value={formData.email}
                    onChange={e => setFormData({...formData, email: e.target.value})}
                    placeholder="example@email.com (اختياري)" dir="ltr"
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', textAlign: 'right', outline: 'none' }}
                  />
                </div>

                {/* Volunteer Fields */}
                {isVolunteer && (
                  <>
                    <div style={{ marginBottom: '22px' }}>
                      <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                        تاريخ بداية التطوع <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <input 
                        type="date" required value={formData.volunteerStartDate}
                        onChange={e => setFormData({...formData, volunteerStartDate: e.target.value})}
                        style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                      />
                    </div>

                    <div style={{ marginBottom: '22px' }}>
                      <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                        تاريخ نهاية التطوع <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <input 
                        type="date" required value={formData.volunteerEndDate}
                        onChange={e => setFormData({...formData, volunteerEndDate: e.target.value})}
                        style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none' }}
                      />
                    </div>

                    <div style={{ marginBottom: '22px' }}>
                      <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                        قسم التطوع <span style={{ color: '#e11d48' }}>*</span>
                      </label>
                      <select 
                        required value={formData.volunteerDepartment}
                        onChange={e => setFormData({...formData, volunteerDepartment: e.target.value})}
                        style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', outline: 'none', background: 'white' }}
                      >
                        <option value="" disabled>اختر قسم التطوع</option>
                        <option value="الجراحة العامة">الجراحة العامة</option>
                        <option value="النسائية والتوليد">النسائية والتوليد</option>
                        <option value="طب الأطفال">طب الأطفال</option>
                        <option value="الطوارئ">الطوارئ</option>
                        <option value="العيادات الخارجية">العيادات الخارجية</option>
                        <option value="التمريض">التمريض</option>
                        <option value="الإدارة">الإدارة</option>
                        <option value="خدمة اجتماعية">خدمة اجتماعية</option>
                        <option value="وحدة التطوير والتدريب">مديرة وحدة التطوير والتدريب — أ. نسرين عابدين (أم خالد)</option>
                        <option value="أخرى">أخرى</option>
                      </select>
                    </div>
                  </>
                )}

                {/* ورقة النقابة Upload (اختياري) */}
                <div style={{ marginBottom: '22px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    ورقة النقابة (إن وجدت)
                  </label>
                  <div 
                    onClick={() => document.getElementById('union-paper-upload')?.click()}
                    style={{ 
                      border: `2px dashed ${unionPaperError ? '#e11d48' : unionPaperBase64 ? '#10b981' : '#cbd5e1'}`, 
                      borderRadius: '14px', 
                      padding: '24px',
                      textAlign: 'center', 
                      cursor: 'pointer', 
                      transition: 'all 0.3s',
                      background: unionPaperError ? 'rgba(225,29,72,0.05)' : unionPaperBase64 ? 'rgba(16,185,129,0.08)' : '#f8fafc'
                    }}
                  >
                    {unionPaperBase64 ? (
                      <>
                        <div style={{ fontSize: '1.8rem', marginBottom: '6px' }}>✅</div>
                        <p style={{ color: '#059669', fontWeight: 700, margin: 0 }}>تم إرفاق: {unionPaperFileName || 'ورقة_النقابة'}</p>
                        <p style={{ color: '#64748b', fontSize: '0.8rem', marginTop: '4px' }}>اضغط لتغيير الملف</p>
                        <button
                          type="button"
                          onClick={(e) => {
                            e.stopPropagation();
                            setUnionPaperBase64('');
                            setUnionPaperFileName('');
                            setUnionPaperError('');
                          }}
                          style={{ marginTop: '8px', background: 'rgba(225,29,72,0.1)', color: '#e11d48', border: '1px solid rgba(225,29,72,0.3)', padding: '5px 14px', borderRadius: '8px', fontSize: '0.82rem', fontWeight: 700, cursor: 'pointer', fontFamily: 'Tajawal' }}
                        >
                          إلغاء ورقة النقابة ✕
                        </button>
                      </>
                    ) : (
                      <>
                        <div style={{ fontSize: '1.8rem', marginBottom: '6px' }}>📋</div>
                        <p style={{ color: unionPaperError ? '#e11d48' : '#64748b', fontWeight: unionPaperError ? 700 : 600, margin: 0 }}>
                          {unionPaperError || 'اضغط لرفع ورقة النقابة (اختياري)'}
                        </p>
                        <p style={{ color: '#94a3b8', fontSize: '0.8rem', marginTop: '4px' }}>PDF أو صورة — حد أقصى 3MB</p>
                      </>
                    )}
                    <input 
                      type="file" 
                      style={{ display: 'none' }} 
                      id="union-paper-upload" 
                      accept=".pdf,.jpg,.jpeg,.png,.doc,.docx"
                      onChange={(e) => {
                        if (e.target.files && e.target.files[0]) {
                          handleUnionPaperUpload(e.target.files[0]);
                        }
                      }}
                    />
                  </div>
                </div>

                {/* Notes */}
                <div style={{ marginBottom: '26px' }}>
                  <label style={{ display: 'block', marginBottom: '8px', fontWeight: 700, fontSize: '1rem', color: '#1e293b' }}>
                    ملاحظات إضافية
                  </label>
                  <textarea 
                    value={formData.notes}
                    onChange={e => setFormData({...formData, notes: e.target.value})}
                    placeholder="اكتب أي تفاصيل إضافية..."
                    style={{ width: '100%', padding: '14px 16px', borderRadius: '12px', border: '1.5px solid #cbd5e1', fontSize: '0.95rem', fontFamily: 'Tajawal', minHeight: '90px', outline: 'none' }}
                  />
                </div>

                {/* ══════════════════════════════════════════════════════════
                    قسم الاعتمادات والتواقيع الرسمية — مخفية عن المتقدم، تظهر عند الطباعة
                ══════════════════════════════════════════════════════════ */}
                <div className="print-only-signatures" style={{
                  marginTop: '35px',
                  marginBottom: '25px',
                  padding: '24px 20px',
                  background: 'linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%)',
                  borderRadius: '16px',
                  border: '1.5px solid #cbd5e1',
                  boxShadow: '0 4px 15px rgba(0,0,0,0.04)'
                }}>
                  <div style={{ textAlign: 'center', marginBottom: '20px' }}>
                    <div style={{ fontWeight: 900, color: '#1e293b', fontSize: '1.1rem', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '8px' }}>
                      <span>✍️</span> الاعتمادات والتواقيع الرسمية
                    </div>
                    <div style={{ fontSize: '0.82rem', color: '#64748b', marginTop: '4px' }}>
                      مستشفى الهلال الأحمر التخصصي — وحدة التطوير والتدريب
                    </div>
                  </div>

                  <div style={{
                    display: 'grid',
                    gridTemplateColumns: isNursing 
                      ? 'repeat(auto-fit, minmax(200px, 1fr))' 
                      : 'repeat(auto-fit, minmax(220px, 1fr))',
                    gap: '16px'
                  }}>
                    {/* 1. رئيس القسم */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1px solid #e2e8f0',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(0,0,0,0.03)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '8px' }}>
                        توقيع رئيس القسم
                      </div>
                      <div style={{ fontSize: '0.8rem', color: '#64748b', marginBottom: '18px' }}>
                        القسم المعني بالتدريب
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #cbd5e1',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#94a3b8', marginTop: '6px' }}>
                        التوقيع والختم: ....................
                      </div>
                    </div>

                    {/* 2. المدير الطبي د. خالد سراحنة (في كافة الأقسام) */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1px solid #e2e8f0',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(0,0,0,0.03)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                        المدير الطبي
                      </div>
                      <div style={{ fontWeight: 900, color: '#0369a1', fontSize: '0.95rem', marginBottom: '14px' }}>
                        د. خالد سراحنة
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #cbd5e1',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#94a3b8', marginTop: '6px' }}>
                        التوقيع والختم: ....................
                      </div>
                    </div>

                    {/* 3. مدير التمريض أ. زياد حمد (في كافة أقسام التمريض) */}
                    {isNursing && (
                      <div style={{
                        background: 'white',
                        padding: '16px',
                        borderRadius: '12px',
                        border: '1px solid #e2e8f0',
                        textAlign: 'center',
                        boxShadow: '0 2px 8px rgba(0,0,0,0.03)'
                      }}>
                        <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                          مدير التمريض
                        </div>
                        <div style={{ fontWeight: 900, color: '#0369a1', fontSize: '0.95rem', marginBottom: '14px' }}>
                          أ. زياد حمد
                        </div>
                        <div style={{
                          borderBottom: '2px dashed #cbd5e1',
                          height: '40px',
                          margin: '0 auto',
                          width: '80%'
                        }}></div>
                        <div style={{ fontSize: '0.75rem', color: '#94a3b8', marginTop: '6px' }}>
                          التوقيع والاعتماد: ....................
                        </div>
                      </div>
                    )}

                    {/* 4. مديرة وحدة التطوير والتدريب أ. نسرين عابدين */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1.5px solid #0284c7',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(2,132,199,0.08)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                        مديرة وحدة التطوير والتدريب
                      </div>
                      <div style={{ fontWeight: 900, color: '#0284c7', fontSize: '0.95rem', marginBottom: '14px' }}>
                        أ. نسرين عابدين
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #0284c7',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#0284c7', marginTop: '6px', fontWeight: 600 }}>
                        الاعتماد والختم الرسمي ✓
                      </div>
                    </div>

                    {/* 5. رئيس الجمعية د. طارق الجعبري */}
                    <div style={{
                      background: 'white',
                      padding: '16px',
                      borderRadius: '12px',
                      border: '1.5px solid #16a34a',
                      textAlign: 'center',
                      boxShadow: '0 2px 8px rgba(22,163,74,0.08)'
                    }}>
                      <div style={{ fontWeight: 800, fontSize: '0.92rem', color: '#1e293b', marginBottom: '4px' }}>
                        رئيس الجمعية
                      </div>
                      <div style={{ fontWeight: 900, color: '#16a34a', fontSize: '0.95rem', marginBottom: '14px' }}>
                        د. طارق الجعبري
                      </div>
                      <div style={{
                        borderBottom: '2px dashed #16a34a',
                        height: '40px',
                        margin: '0 auto',
                        width: '80%'
                      }}></div>
                      <div style={{ fontSize: '0.75rem', color: '#16a34a', marginTop: '6px', fontWeight: 600 }}>
                        الاعتماد النهائي والتوقيع ✓
                      </div>
                    </div>
                  </div>
                </div>
              </>
            )}

            {/* Submit Button */}
            <button 
              type="submit" 
              disabled={isSubmitting}
              style={{ 
                width: '100%', 
                padding: '16px', 
                fontSize: '1.2rem',
                fontWeight: 800,
                background: isSubmitting ? '#94a3b8' : (isUntouchedCategory ? 'linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%)' : currentTheme.submitGradient),
                color: 'white',
                border: 'none',
                borderRadius: '14px', 
                cursor: isSubmitting ? 'not-allowed' : 'pointer',
                boxShadow: isSubmitting ? 'none' : (isUntouchedCategory ? '0 10px 25px rgba(37, 99, 235, 0.35)' : currentTheme.submitShadow),
                transition: 'all 0.3s',
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'center',
                gap: '12px',
                fontFamily: 'Tajawal, sans-serif',
                marginBottom: '15px'
              }}
            >
              {isSubmitting ? (
                <>
                  <div style={{
                    width: '22px',
                    height: '22px',
                    border: '3px solid rgba(255,255,255,0.3)',
                    borderTop: '3px solid white',
                    borderRadius: '50%',
                    animation: 'spin 1s linear infinite'
                  }} />
                  جاري إرسال الطلب...
                </>
              ) : (
                <>
                  <Send size={20} />
                  إرسال الطلب واعتماده ✨
                </>
              )}
            </button>

            {/* Bottom Back Button */}
            <div style={{ textAlign: 'center', marginTop: '15px' }}>
              <Link
                href="/recruitment"
                style={{
                  display: 'inline-flex',
                  alignItems: 'center',
                  gap: '6px',
                  color: '#64748b',
                  textDecoration: 'none',
                  fontSize: '0.9rem',
                  fontWeight: 700,
                  transition: 'color 0.2s'
                }}
              >
                <ArrowRight size={16} />
                إلغاء والعودة لكافة النماذج
              </Link>
            </div>
          </form>
        </div>

        {/* Footer */}
        <div style={{
          textAlign: 'center',
          padding: '25px',
          color: 'rgba(255,255,255,0.7)',
          fontSize: '0.9rem',
          fontWeight: 600
        }}>
          مستشفى الهلال الأحمر الفلسطيني — وحدة التطوير والتدريب © {new Date().getFullYear()}
        </div>
      </div>
    </div>
  );
}
