// KURAL – Voice of Her | Desktop Dashboard Application
// Custom SVG Icons matching exact visual language & palette

const { useState, useEffect, useMemo } = React;

// Custom-Designed Bespoke SVG Icons (No Generic Emojis)
const Icons = {
  // Search: Refined magnifying glass with sparkle
  Search: ({ className = "w-4 h-4" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="11" cy="11" r="7" stroke="var(--kural-lavender)" />
      <path d="M21 21L16.2 16.2" stroke="var(--kural-lavender)" strokeWidth="2.4" />
      <path d="M11 8V9M11 13V14M8.5 11H9.5M12.5 11H13.5" stroke="var(--kural-flamingo)" strokeWidth="1.5" />
    </svg>
  ),

  // Moon (Dark Mode): Delicate crescent with sparkle star
  Moon: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none">
      <path d="M21 12.79A9 9 0 1 1 11.21 3A7 7 0 0 0 21 12.79Z" fill="url(#moonGrad)" stroke="var(--kural-lavender)" strokeWidth="1.5" />
      <path d="M19 4L19.5 5.5L21 6L19.5 6.5L19 8L18.5 6.5L17 6L18.5 5.5L19 4Z" fill="var(--kural-flamingo)" />
      <defs>
        <linearGradient id="moonGrad" x1="0%" y1="0%" x2="100%" y2="100%">
          <stop offset="0%" stopColor="#DABBE0" stopOpacity="0.85" />
          <stop offset="100%" stopColor="#EEBFD1" stopOpacity="0.4" />
        </linearGradient>
      </defs>
    </svg>
  ),

  // Sun (Light Mode): Radiant stylized sun with soft geometric rays
  Sun: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none">
      <circle cx="12" cy="12" r="5" fill="var(--kural-lavender)" stroke="var(--kural-flamingo)" strokeWidth="1.5" />
      <path d="M12 2V4M12 20V22M4 12H2M22 12H20M5.63 5.63L7.05 7.05M16.95 16.95L18.37 18.37M5.63 18.37L7.05 16.95M16.95 7.05L18.37 5.63" stroke="var(--kural-mauve)" strokeWidth="2" strokeLinecap="round" />
    </svg>
  ),

  // Notification Bell: Elegant bell with alert beacon
  Bell: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none">
      <path d="M18 16V11C18 7.93 16.37 5.36 13.5 4.68V4C13.5 3.17 12.83 2.5 12 2.5C11.17 2.5 10.5 3.17 10.5 4V4.68C7.64 5.36 6 7.92 6 11V16L4 18V19H20V18L18 16Z" fill="var(--kural-lavender)" fillOpacity="0.3" stroke="var(--kural-lavender)" strokeWidth="1.5" />
      <path d="M10 20C10 21.1 10.9 22 12 22C13.1 22 14 21.1 14 20H10Z" fill="var(--kural-flamingo)" />
    </svg>
  ),

  // Safety Shield: Unified Protect, Prevent, Support
  SafetyShield: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none">
      <path d="M12 2L4 5.5V11.5C4 16.5 7.4 21.1 12 22.3C16.6 21.1 20 16.5 20 11.5V5.5L12 2Z" fill="var(--kural-lavender)" fillOpacity="0.25" stroke="var(--kural-lavender)" strokeWidth="1.6" />
      <path d="M9 11.5L11 13.5L15 9.5" stroke="var(--kural-flamingo)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
      <circle cx="12" cy="12" r="7" stroke="var(--kural-soft-sky)" strokeWidth="0.8" strokeDasharray="2 2" />
    </svg>
  ),

  // Empower: Raised hands with stars and empowerment wings
  EmpowerStar: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none">
      <path d="M12 2L13.5 6L17.5 7.5L13.5 9L12 13L10.5 9L6.5 7.5L10.5 6L12 2Z" fill="var(--kural-flamingo)" />
      <path d="M5 19C7 16 9 14.5 12 14.5C15 14.5 17 16 19 19M12 10.5C13.1 10.5 14 9.6 14 8.5C14 7.4 13.1 6.5 12 6.5C10.9 6.5 10 7.4 10 8.5C10 9.6 10.9 10.5 12 10.5Z" stroke="var(--kural-lavender)" strokeWidth="1.6" strokeLinecap="round" />
    </svg>
  ),

  // My Complaints & Track
  ComplaintsTrack: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none">
      <rect x="4" y="3" width="16" height="18" rx="3" fill="var(--kural-lavender)" fillOpacity="0.2" stroke="var(--kural-lavender)" strokeWidth="1.5" />
      <path d="M8 8H16M8 12H13M8 16H11" stroke="var(--kural-soft-sky)" strokeWidth="1.8" strokeLinecap="round" />
      <circle cx="16" cy="15" r="3" fill="var(--kural-flamingo)" />
      <path d="M15 15L15.8 15.8L17.5 14" stroke="#060814" strokeWidth="1.4" strokeLinecap="round" />
    </svg>
  ),

  // Protect Icon
  Protect: ({ className = "w-7 h-7" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 2L4 5V11.09C4 16.14 7.41 20.85 12 22C16.59 20.85 20 16.14 20 11.09V5L12 2ZM9.8 16.2L6.3 12.7L7.71 11.29L9.8 13.38L16.29 6.89L17.7 8.3L9.8 16.2Z" />
    </svg>
  ),

  // Prevent Icon
  Prevent: ({ className = "w-7 h-7" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="currentColor">
      <path d="M1 21H23L12 2L1 21ZM13 18H11V16H13V18ZM13 14H11V10H13V14Z" />
    </svg>
  ),

  // Support Icon
  Support: ({ className = "w-7 h-7" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 21.35L10.55 20.03C5.4 15.36 2 12.28 2 8.5C2 5.42 4.42 3 7.5 3C9.24 3 10.91 3.81 12 5.09C13.09 3.81 14.76 3 16.5 3C19.58 3 22 5.42 22 8.5C22 12.28 18.6 15.36 13.45 20.04L12 21.35Z" />
    </svg>
  ),

  // Empower Icon
  Empower: ({ className = "w-7 h-7" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 2C13.1 2 14 2.9 14 4C14 5.1 13.1 6 12 6C10.9 6 10 5.1 10 4C10 2.9 10.9 2 12 2ZM21 9H15V22H13V16H11V22H9V9H3V7H21V9ZM5 3L6 1L7 3L9 4L7 5L6 7L5 5L3 4L5 3ZM19 3L20 1L21 3L23 4L21 5L20 7L19 5L17 4L19 3Z" />
    </svg>
  ),

  // Siren
  Siren: ({ className = "w-9 h-9" }) => (
    <svg className={className} viewBox="0 0 40 40" fill="none">
      <path d="M20 6C14 6 10 11 10 18V26H30V18C30 11 26 6 20 6Z" fill="#EEBFD1" />
      <path d="M8 26H32V30C32 31.1 31.1 32 30 32H10C8.9 32 8 31.1 8 30V26Z" fill="#ECAAC2" />
      <circle cx="20" cy="18" r="4" fill="#FFFFFF" opacity="0.8" />
      <path d="M20 2V4M10 5L11.5 6.5M30 5L28.5 6.5" stroke="#EEBFD1" strokeWidth="2.5" strokeLinecap="round" />
    </svg>
  ),

  // Phone
  Phone: ({ className = "w-6 h-6" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="currentColor">
      <path d="M6.62 10.79C8.06 13.62 10.38 15.94 13.21 17.38L15.41 15.18C15.69 14.9 16.08 14.82 16.43 14.93C17.55 15.3 18.75 15.5 20 15.5C20.55 15.5 21 15.95 21 16.5V20C21 20.55 20.55 21 20 21C10.61 21 3 13.39 3 4C3 3.45 3.45 3 4 3H7.5C8.05 3 8.5 3.45 8.5 4C8.5 5.25 8.7 6.45 9.07 7.57C9.18 7.92 9.1 8.31 8.82 8.59L6.62 10.79Z" />
    </svg>
  ),

  // Document with Shield
  DocumentShield: ({ className = "w-6 h-6" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="currentColor">
      <path d="M14 2H6C4.9 2 4 2.9 4 4V20C4 21.1 4.9 22 6 22H18C19.1 22 20 21.1 20 20V8L14 2ZM12 18.5C9.5 17.3 8 14.8 8 12V8.5L12 7L16 8.5V12C16 14.8 14.5 17.3 12 18.5Z" />
    </svg>
  ),

  // Book
  Book: ({ className = "w-6 h-6" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="currentColor">
      <path d="M18 2H6C4.9 2 4 2.9 4 4V20C4 21.1 4.9 22 6 22H18C19.1 22 20 21.1 20 20V4C20 2.9 19.1 2 18 2ZM18 20H6V4H7V13L9.5 11.5L12 13V4H18V20Z" />
    </svg>
  ),

  // Question Bubble
  QuestionBubble: ({ className = "w-6 h-6" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="currentColor">
      <path d="M20 2H4C2.9 2 2 2.9 2 4V22L6 18H20C21.1 18 22 17.1 22 16V4C22 2.9 21.1 2 20 2ZM12 16C11.45 16 11 15.55 11 15C11 14.45 11.45 14 12 14C12.55 14 13 14.45 13 15C13 15.55 12.55 16 12 16ZM13.07 11.25L12.44 11.89C11.99 12.35 11.7 13 11.7 14H10.3C10.3 12.6 10.87 11.85 11.45 11.25L12.32 10.38C12.74 9.96 13 9.38 13 8.75C13 7.51 11.99 6.5 10.75 6.5C9.51 6.5 8.5 7.51 8.5 8.75H7C7 6.68 8.68 5 10.75 5C12.82 5 14.5 6.68 14.5 8.75C14.5 9.77 13.93 10.66 13.07 11.25Z" />
    </svg>
  ),

  // Navigation General Icons
  Home: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
      <polyline points="9 22 9 12 15 12 15 22" />
    </svg>
  ),
  User: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
      <circle cx="12" cy="7" r="4" />
    </svg>
  ),
  Settings: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="3" />
      <path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z" />
    </svg>
  ),
  Logout: ({ className = "w-5 h-5" }) => (
    <svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
      <polyline points="16 17 21 12 16 7" />
      <line x1="21" y1="12" x2="9" y2="12" />
    </svg>
  )
};

// Main Application Component
function App() {
  const [theme, setTheme] = useState(() => localStorage.getItem("kural_theme") || "dark");
  const [activeTab, setActiveTab] = useState("home");
  const [safetySubTab, setSafetySubTab] = useState("protect");
  const [empowerSubTab, setEmpowerSubTab] = useState("learning");
  const [complaintSubTab, setComplaintSubTab] = useState("list");
  
  const [isSOSActive, setIsSOSActive] = useState(false);
  const [sosCountdown, setSosCountdown] = useState(5);
  const [searchQuery, setSearchQuery] = useState("");
  const [toastMessage, setToastMessage] = useState(null);
  const [isNotificationOpen, setIsNotificationOpen] = useState(false);

  // Sync theme
  useEffect(() => {
    document.documentElement.setAttribute("data-theme", theme);
    localStorage.setItem("kural_theme", theme);
  }, [theme]);

  // Toast Helper
  const showToast = (msg) => {
    setToastMessage(msg);
    setTimeout(() => setToastMessage(null), 3000);
  };

  // SOS Countdown logic
  useEffect(() => {
    let timer;
    if (isSOSActive && sosCountdown > 0) {
      timer = setInterval(() => setSosCountdown((prev) => prev - 1), 1000);
    }
    return () => clearInterval(timer);
  }, [isSOSActive, sosCountdown]);

  const triggerSOS = () => {
    setSosCountdown(5);
    setIsSOSActive(true);
  };

  const cancelSOS = () => {
    setIsSOSActive(false);
    setSosCountdown(5);
    showToast("SOS Alert Cancelled Safely");
  };

  return (
    <div className={`min-h-screen flex ${theme === 'dark' ? 'bg-[#060814] text-white' : 'bg-[#FAF8FD] text-[#0A0D1E]'}`}>
      
      {/* Toast Notification */}
      {toastMessage && (
        <div className="fixed top-6 right-8 z-50 px-5 py-3 rounded-2xl bg-[#0A0D1E] text-[#DABBE0] border border-[#DABBE0]/40 shadow-2xl flex items-center gap-3 text-sm font-medium animate-fadeIn">
          <span>✨</span>
          <span>{toastMessage}</span>
        </div>
      )}

      {/* SOS Emergency Modal */}
      {isSOSActive && (
        <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/80 backdrop-blur-md">
          <div className="kural-card max-w-md w-full p-8 text-center border-[#EEBFD1]/60 shadow-2xl">
            <div className="w-20 h-20 mx-auto rounded-full bg-[#EEBFD1]/20 flex items-center justify-center siren-glowing mb-4">
              <Icons.Siren className="w-12 h-12" />
            </div>
            <h3 className="font-poppins text-2xl font-bold text-[#EEBFD1] mb-2">SOS EMERGENCY TRIGGERED</h3>
            <p className="text-sm text-slate-300 mb-6">
              Transmitting live GPS coordinates and alerting emergency dispatch in:
            </p>
            <div className="text-6xl font-black font-poppins text-[#EEBFD1] my-4">
              00:0{sosCountdown}
            </div>
            <div className="grid grid-cols-2 gap-3 my-6">
              <a href="tel:112" className="py-3 px-4 rounded-2xl bg-[#EEBFD1] text-slate-900 font-bold hover:opacity-90 flex items-center justify-center gap-2 text-sm">
                <Icons.Phone className="w-4 h-4" /> Call 112 (Police)
              </a>
              <a href="tel:181" className="py-3 px-4 rounded-2xl bg-[#DABBE0] text-slate-900 font-bold hover:opacity-90 flex items-center justify-center gap-2 text-sm">
                <Icons.Phone className="w-4 h-4" /> Call 181 (Women)
              </a>
            </div>
            <button 
              onClick={cancelSOS}
              className="w-full py-2.5 rounded-xl border border-white/20 text-slate-300 hover:bg-white/10 text-xs font-semibold"
            >
              Cancel Emergency Alert
            </button>
          </div>
        </div>
      )}

      {/* REORGANIZED LEFT SIDEBAR */}
      <aside className="w-64 h-screen sticky top-0 flex flex-col justify-between p-6 kural-sidebar shrink-0 overflow-y-auto">
        <div className="space-y-8">
          
          {/* Kural Logo */}
          <div className="flex items-center gap-3 cursor-pointer" onClick={() => setActiveTab("home")}>
            <div>
              <div className="font-cormorant text-3xl font-bold tracking-tight text-white flex items-center">
                <span className={theme === 'dark' ? 'text-white' : 'text-[#0A0D1E]'}>Kural</span>
                <span className="text-[#DABBE0] text-lg ml-1">✦</span>
              </div>
              <div className="text-[11px] font-medium tracking-widest text-[#DABBE0] uppercase">
                Voice of Her
              </div>
            </div>
          </div>

          {/* Navigation Links: Reorganized cleanly */}
          <nav className="space-y-1.5 text-xs font-medium">
            {[
              { id: "home", label: "Home", icon: Icons.Home },
              { id: "safety-shield", label: "Safety Shield", badge: "Protect · Prevent · Support", icon: Icons.SafetyShield },
              { id: "empower", label: "Empower", badge: "Learn · Resources", icon: Icons.EmpowerStar },
              { id: "my-complaints", label: "My Complaints", badge: "History & Track", icon: Icons.ComplaintsTrack },
              { id: "emergency", label: "Emergency Contacts", icon: Icons.Phone },
              { id: "faqs", label: "FAQs", icon: Icons.QuestionBubble },
              { id: "profile", label: "User Profile", icon: Icons.User },
              { id: "settings", label: "Settings", icon: Icons.Settings },
            ].map((item) => {
              const IconComp = item.icon;
              const isActive = activeTab === item.id;
              return (
                <button
                  key={item.id}
                  onClick={() => setActiveTab(item.id)}
                  className={`w-full flex items-center justify-between px-4 py-3 rounded-2xl transition ${
                    isActive 
                      ? "sidebar-item-active" 
                      : "text-slate-400 hover:text-white hover:bg-white/5"
                  }`}
                >
                  <div className="flex items-center gap-3">
                    <IconComp className={`w-4 h-4 ${isActive ? 'text-[#DABBE0]' : 'text-slate-400'}`} />
                    <span className="text-[13px]">{item.label}</span>
                  </div>
                  {item.badge && !isActive && (
                    <span className="w-1.5 h-1.5 rounded-full bg-[#EEBFD1]/60"></span>
                  )}
                </button>
              );
            })}
          </nav>
        </div>

        {/* Logout button at sidebar bottom */}
        <div className="pt-4 border-t border-white/10">
          <button 
            onClick={() => showToast("Logged out successfully.")}
            className="w-full flex items-center gap-3 px-4 py-2.5 rounded-2xl text-slate-400 hover:text-rose-300 hover:bg-white/5 text-xs font-medium transition"
          >
            <Icons.Logout className="w-4 h-4 text-slate-400" />
            <span>Logout</span>
          </button>
        </div>
      </aside>

      {/* RIGHT MAIN CONTENT AREA */}
      <div className="flex-1 flex flex-col min-w-0">
        
        {/* TOP HEADER */}
        <header className="h-20 px-8 flex items-center justify-between border-b border-[#DABBE0]/15 sticky top-0 z-30 backdrop-blur-md bg-[var(--header-bg)]">
          
          {/* Greeting */}
          <div>
            <h2 className="font-poppins font-semibold text-lg flex items-center gap-2">
              <span>Welcome back,</span>
              <span className="text-[#DABBE0] font-bold">Priya</span>
            </h2>
            <p className="text-xs text-slate-400">Safe. Strong. Empowered.</p>
          </div>

          {/* Search bar & Actions with Custom Bespoke Icons */}
          <div className="flex items-center gap-4 relative">
            
            {/* Search Input with Custom SVG Search Icon */}
            <div className="relative w-64 hidden sm:block">
              <input 
                type="text"
                value={searchQuery}
                onChange={(e) => setSearchQuery(e.target.value)}
                placeholder="Search resources, complaints..."
                className="w-full px-4 py-2.5 pl-10 rounded-2xl bg-white/5 border border-[#DABBE0]/20 text-xs focus:outline-none focus:border-[#DABBE0] text-slate-200 placeholder:text-slate-500"
              />
              <span className="absolute left-3.5 top-3 text-slate-400">
                <Icons.Search className="w-4 h-4 text-[#DABBE0]" />
              </span>
            </div>

            {/* Notification Bell with Custom Bespoke SVG */}
            <button 
              onClick={() => setIsNotificationOpen(!isNotificationOpen)}
              className="relative w-10 h-10 rounded-2xl bg-white/5 hover:bg-white/10 border border-[#DABBE0]/20 flex items-center justify-center text-slate-300 transition"
              title="Notifications"
            >
              <Icons.Bell className="w-5 h-5 text-[#DABBE0]" />
              <span className="absolute top-2 right-2 w-2 h-2 rounded-full bg-[#EEBFD1] animate-pulse"></span>
            </button>

            {/* Top Bar Notification Flyout / Dropdown */}
            {isNotificationOpen && (
              <div className="absolute right-12 top-14 w-80 kural-card p-5 border-[#DABBE0]/30 shadow-2xl z-50 animate-fadeIn space-y-3">
                <div className="flex items-center justify-between border-b border-white/10 pb-2">
                  <h4 className="font-poppins font-bold text-sm text-white">Notifications</h4>
                  <button onClick={() => setIsNotificationOpen(false)} className="text-xs text-slate-400 hover:text-white">✕</button>
                </div>
                <div className="space-y-2.5 max-h-64 overflow-y-auto">
                  {window.KURAL_DATA?.NOTIFICATIONS.map(n => (
                    <div key={n.id} className="p-3 rounded-xl bg-white/5 border border-white/5 text-xs space-y-1">
                      <div className="flex items-center justify-between">
                        <span className="font-semibold text-white">{n.title}</span>
                        {n.unread && <span className="w-2 h-2 rounded-full bg-[#EEBFD1]"></span>}
                      </div>
                      <p className="text-[11px] text-slate-300 leading-tight">{n.desc}</p>
                      <span className="text-[10px] text-slate-400 font-mono">{n.time}</span>
                    </div>
                  ))}
                </div>
              </div>
            )}

            {/* Dark / Light Toggle with Custom Bespoke SVG Moon/Sun */}
            <button
              onClick={() => {
                const next = theme === "dark" ? "light" : "dark";
                setTheme(next);
                showToast(`Switched to ${next === "dark" ? "Dark Mode" : "Light Mode"}`);
              }}
              className="w-10 h-10 rounded-2xl bg-white/5 hover:bg-white/10 border border-[#DABBE0]/20 flex items-center justify-center transition hover:border-[#DABBE0]"
              title={`Switch Theme (Current: ${theme})`}
            >
              {theme === "dark" ? (
                <Icons.Moon className="w-5 h-5" />
              ) : (
                <Icons.Sun className="w-5 h-5" />
              )}
            </button>

            {/* Profile Avatar */}
            <div 
              onClick={() => setActiveTab("profile")}
              className="flex items-center gap-3 pl-2 cursor-pointer"
            >
              <div className="w-10 h-10 rounded-2xl bg-gradient-to-tr from-[#DABBE0] to-[#EEBFD1] p-0.5 shadow-md">
                <div className="w-full h-full rounded-[14px] bg-[#0A0D1E] flex items-center justify-center text-sm font-bold text-[#DABBE0]">
                  P
                </div>
              </div>
            </div>

          </div>
        </header>

        {/* MAIN BODY CONTENT */}
        <main className="flex-1 p-8 overflow-y-auto">
          {activeTab === "home" && (
            <HomeDashboardScreen 
              theme={theme} 
              setActiveTab={setActiveTab} 
              triggerSOS={triggerSOS}
              setSafetySubTab={setSafetySubTab}
              setEmpowerSubTab={setEmpowerSubTab}
              showToast={showToast}
            />
          )}

          {activeTab === "safety-shield" && (
            <UnifiedSafetyShieldScreen 
              activeSub={safetySubTab} 
              setActiveSub={setSafetySubTab} 
              triggerSOS={triggerSOS} 
              showToast={showToast} 
            />
          )}

          {activeTab === "empower" && (
            <UnifiedEmpowerScreen 
              activeSub={empowerSubTab} 
              setActiveSub={setEmpowerSubTab} 
              showToast={showToast} 
            />
          )}

          {activeTab === "my-complaints" && (
            <UnifiedComplaintsScreen 
              activeSub={complaintSubTab} 
              setActiveSub={setComplaintSubTab} 
              showToast={showToast} 
            />
          )}

          {activeTab === "emergency" && (
            <EmergencyScreen triggerSOS={triggerSOS} showToast={showToast} />
          )}

          {activeTab === "faqs" && <FAQsScreen />}
          {activeTab === "profile" && <ProfileScreen showToast={showToast} />}
          {activeTab === "settings" && <SettingsScreen theme={theme} setTheme={setTheme} showToast={showToast} />}
        </main>

      </div>

    </div>
  );
}

// --------------------------------------------------------------------------
// SECTION: DESKTOP HOMEPAGE DASHBOARD WITH ANONYMOUS COMMUNITY MAP
// --------------------------------------------------------------------------
function HomeDashboardScreen({ theme, setActiveTab, triggerSOS, setSafetySubTab, setEmpowerSubTab, showToast }) {
  const [selectedZone, setSelectedZone] = useState(() => window.KURAL_DATA?.COMMUNITY_ZONES[0]);
  const [zoneFilter, setZoneFilter] = useState("all");

  const zones = window.KURAL_DATA?.COMMUNITY_ZONES || [];

  return (
    <div className="space-y-8 max-w-6xl mx-auto animate-fadeIn">
      
      {/* HERO SECTION */}
      <div className="relative rounded-[32px] p-8 lg:p-12 overflow-hidden kural-card border-[#DABBE0]/20 bg-gradient-to-br from-[#0A0D1E] via-[#1A103C]/40 to-[#060814]">
        
        {/* Curved gradient glow */}
        <div className="absolute -right-16 -top-16 w-96 h-96 rounded-full bg-gradient-to-br from-[#DABBE0]/20 via-[#EEBFD1]/15 to-transparent blur-3xl pointer-events-none"></div>

        <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-center relative z-10">
          
          {/* Left Side: Branding and Welcome */}
          <div className="lg:col-span-7 space-y-4">
            
            <div className="font-cormorant text-4xl lg:text-5xl font-bold tracking-tight text-white flex items-center">
              <span>Kural</span>
              <span className="text-[#EEBFD1] text-2xl ml-1">✦</span>
            </div>
            
            <div className="text-xs font-semibold tracking-widest uppercase text-[#DABBE0] pb-1">
              Voice of Her
            </div>

            <div className="space-y-1">
              <h1 className="font-poppins text-3xl lg:text-4xl font-bold text-white leading-tight">
                Safe. Strong.
              </h1>
              <h1 className="font-poppins text-3xl lg:text-4xl font-bold bg-gradient-to-r from-[#DABBE0] via-[#EEBFD1] to-[#ECAAC2] bg-clip-text text-transparent leading-tight">
                Empowered.
              </h1>
            </div>

            <p className="text-sm lg:text-base text-slate-300 font-light leading-relaxed pt-2 max-w-md">
              "Because every woman deserves to feel safe."
            </p>

            {/* Heart outline and flowing decorative line */}
            <div className="pt-2 flex items-center gap-3">
              <svg className="w-64 h-8 text-[#EEBFD1]" viewBox="0 0 240 32" fill="none" stroke="currentColor">
                <path d="M5 16 Q 60 16, 100 16 T 150 16 C 160 10, 175 10, 180 16 C 185 22, 195 24, 200 16 Q 215 16, 235 16" strokeWidth="2" strokeLinecap="round" />
              </svg>
            </div>

          </div>

          {/* Right Side: Exact Woman Illustration from Reference */}
          <div className="lg:col-span-5 flex justify-center items-center relative">
            <div className="w-72 h-72 rounded-full bg-gradient-to-tr from-[#EEBFD1]/30 via-[#DABBE0]/35 to-[#93AECA]/20 blur-xl absolute"></div>

            <div className="relative w-64 h-64 rounded-full border-2 border-[#DABBE0]/40 overflow-hidden shadow-2xl flex items-center justify-center bg-[#0A0D1E]/80 backdrop-blur-md">
              <img 
                src={theme === 'dark' ? "hero_woman_dark.png" : "hero_woman_light.png"}
                alt="Kural – Voice of Her Illustration"
                className="w-full h-full object-cover transform scale-110"
              />
            </div>
          </div>

        </div>
      </div>

      {/* NEW REQUIREMENT: ANONYMOUS COMMUNITY LOCATION SAFETY MAP */}
      <div className="kural-card p-8 rounded-[32px] border-[#DABBE0]/30 space-y-6" style={{ background: 'var(--grad-map)' }}>
        <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 border-b border-white/10 pb-4">
          <div>
            <div className="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-[#DABBE0]/15 text-[#DABBE0] text-xs font-semibold mb-1 border border-[#DABBE0]/20">
              <span className="w-2 h-2 rounded-full bg-[#EEBFD1] animate-ping"></span>
              Live Anonymous Community Presence
            </div>
            <h3 className="font-poppins font-bold text-xl text-white">
              Kural Sisterhood Community Safety Map
            </h3>
            <p className="text-xs text-slate-300">
              5,370+ active anonymous sisters online in verified safe corridors across Tamil Nadu regions.
            </p>
          </div>

          <div className="flex items-center gap-2 text-xs">
            <span className="px-3 py-1 rounded-full bg-emerald-500/20 text-emerald-300 border border-emerald-500/30 font-semibold text-[11px]">
              ✓ 100% Identity Masked
            </span>
          </div>
        </div>

        {/* Map Grid + Details Split */}
        <div className="grid grid-cols-1 lg:grid-cols-12 gap-6 items-center">
          
          {/* Interactive Geospatial Canvas Area */}
          <div className="lg:col-span-7 relative h-80 rounded-2xl bg-[#060814]/80 border border-white/10 overflow-hidden p-4 flex flex-col justify-between">
            {/* Background grid lines */}
            <div className="absolute inset-0 bg-[radial-gradient(#DABBE0_1px,transparent_1px)] [background-size:24px_24px] opacity-20 pointer-events-none"></div>

            {/* Region Beacons */}
            <div className="relative w-full h-full">
              {zones.map((z) => {
                const isSelected = selectedZone?.id === z.id;
                return (
                  <div
                    key={z.id}
                    onClick={() => {
                      setSelectedZone(z);
                      showToast(`Viewing ${z.city} Safe Corridor`);
                    }}
                    style={{ left: `${z.x}%`, top: `${z.y}%` }}
                    className="absolute -translate-x-1/2 -translate-y-1/2 cursor-pointer group"
                  >
                    {/* Pulsing Beacon */}
                    <div className="relative flex items-center justify-center">
                      <span className="absolute w-8 h-8 rounded-full bg-[#EEBFD1]/30 beacon-pulse pointer-events-none"></span>
                      <span className={`w-4 h-4 rounded-full transition-all ${
                        isSelected 
                          ? 'bg-[#EEBFD1] ring-4 ring-[#DABBE0]/60 scale-125 shadow-lg shadow-[#EEBFD1]' 
                          : 'bg-[#DABBE0] group-hover:scale-110'
                      }`}></span>
                    </div>

                    {/* City Tag Label */}
                    <span className={`absolute left-5 top-0 whitespace-nowrap text-[11px] font-semibold px-2 py-0.5 rounded-md backdrop-blur-md transition ${
                      isSelected 
                        ? 'bg-[#EEBFD1] text-slate-900 shadow-md font-bold' 
                        : 'bg-black/60 text-slate-300 border border-white/10 group-hover:text-white'
                    }`}>
                      {z.city.split('&')[0]} ({z.anonymousCount})
                    </span>
                  </div>
                );
              })}
            </div>

            {/* Map Legend */}
            <div className="relative z-10 flex flex-wrap items-center gap-4 text-[11px] text-slate-400 bg-black/60 backdrop-blur-md p-2.5 rounded-xl border border-white/5">
              <span className="flex items-center gap-1.5"><span className="w-2.5 h-2.5 rounded-full bg-[#EEBFD1]"></span> Active Community Hub</span>
              <span className="flex items-center gap-1.5"><span className="w-2.5 h-2.5 rounded-full bg-[#DABBE0]"></span> Verified Pink Patrol</span>
              <span className="flex items-center gap-1.5"><span className="w-2.5 h-2.5 rounded-full bg-[#BED3E3]"></span> Sakhi One Stop Haven</span>
            </div>
          </div>

          {/* Selected Zone Intelligence Details Card */}
          <div className="lg:col-span-5 kural-card p-6 border-[#DABBE0]/30 space-y-4 bg-black/40">
            <div className="flex items-start justify-between">
              <div>
                <span className="text-[11px] font-mono text-[#EEBFD1] font-bold">REGION SAFETY STATUS</span>
                <h4 className="font-poppins font-bold text-lg text-white mt-0.5">{selectedZone.city}</h4>
                <div className="text-xs text-emerald-400 font-medium">{selectedZone.status}</div>
              </div>
              <span className="px-3 py-1 rounded-xl bg-[#DABBE0]/20 text-[#DABBE0] font-mono text-xs font-bold">
                {selectedZone.anonymousCount} Active
              </span>
            </div>

            <div className="grid grid-cols-2 gap-2 text-xs">
              <div className="p-3 rounded-xl bg-white/5 border border-white/5">
                <span className="text-slate-400 block text-[10px]">Verified Safe Havens</span>
                <span className="text-base font-bold text-white font-poppins">{selectedZone.safeHavens} Booths</span>
              </div>
              <div className="p-3 rounded-xl bg-white/5 border border-white/5">
                <span className="text-slate-400 block text-[10px]">Pink Patrol Units</span>
                <span className="text-base font-bold text-[#EEBFD1] font-poppins">{selectedZone.pinkPatrols} Units</span>
              </div>
            </div>

            <div className="space-y-1.5 text-xs">
              <span className="text-slate-400 font-semibold block text-[11px]">Key Shelters & Nodes:</span>
              {selectedZone.verifiedShelters.map((sh, idx) => (
                <div key={idx} className="flex items-center gap-2 text-slate-200 text-[11px]">
                  <span className="w-1.5 h-1.5 rounded-full bg-[#DABBE0]"></span>
                  <span>{sh}</span>
                </div>
              ))}
            </div>

            <div className="p-3 rounded-xl bg-[#DABBE0]/10 border border-[#DABBE0]/20 text-[11px] text-[#DABBE0]">
              <span className="font-bold">Latest Transit Notice: </span>
              <span>{selectedZone.recentAlert}</span>
            </div>
          </div>

        </div>
      </div>

      {/* FOUR MAIN FEATURE CARDS */}
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-5">
        
        {/* CARD 1: PROTECT */}
        <div 
          onClick={() => {
            setSafetySubTab("protect");
            setActiveTab("safety-shield");
          }}
          className="kural-card p-6 cursor-pointer group hover:border-[#DABBE0]/60 transition flex flex-col justify-between"
          style={{ background: 'var(--grad-protect)' }}
        >
          <div>
            <div className="w-12 h-12 rounded-2xl bg-[#DABBE0]/20 border border-[#DABBE0]/30 flex items-center justify-center text-[#DABBE0] mb-4">
              <Icons.Protect className="w-6 h-6" />
            </div>
            <h3 className="font-poppins font-bold text-lg text-white mb-1">Protect</h3>
            <p className="text-xs text-slate-300">Stay safe with real-time SOS</p>
          </div>
          <div className="mt-6 flex justify-end">
            <div className="w-8 h-8 rounded-full bg-[#DABBE0]/20 flex items-center justify-center text-[#DABBE0] group-hover:translate-x-1 transition">
              →
            </div>
          </div>
        </div>

        {/* CARD 2: PREVENT */}
        <div 
          onClick={() => {
            setSafetySubTab("prevent");
            setActiveTab("safety-shield");
          }}
          className="kural-card p-6 cursor-pointer group hover:border-[#EEBFD1]/60 transition flex flex-col justify-between"
          style={{ background: 'var(--grad-prevent)' }}
        >
          <div>
            <div className="w-12 h-12 rounded-2xl bg-[#EEBFD1]/20 border border-[#EEBFD1]/30 flex items-center justify-center text-[#EEBFD1] mb-4">
              <Icons.Prevent className="w-6 h-6" />
            </div>
            <h3 className="font-poppins font-bold text-lg text-white mb-1">Prevent</h3>
            <p className="text-xs text-slate-300">Detect and avoid dangers</p>
          </div>
          <div className="mt-6 flex justify-end">
            <div className="w-8 h-8 rounded-full bg-[#EEBFD1]/20 flex items-center justify-center text-[#EEBFD1] group-hover:translate-x-1 transition">
              →
            </div>
          </div>
        </div>

        {/* CARD 3: SUPPORT */}
        <div 
          onClick={() => {
            setSafetySubTab("support");
            setActiveTab("safety-shield");
          }}
          className="kural-card p-6 cursor-pointer group hover:border-[#BED3E3]/60 transition flex flex-col justify-between"
          style={{ background: 'var(--grad-support)' }}
        >
          <div>
            <div className="w-12 h-12 rounded-2xl bg-[#BED3E3]/20 border border-[#BED3E3]/30 flex items-center justify-center text-[#BED3E3] mb-4">
              <Icons.Support className="w-6 h-6" />
            </div>
            <h3 className="font-poppins font-bold text-lg text-white mb-1">Support</h3>
            <p className="text-xs text-slate-300">Get help anytime, anywhere</p>
          </div>
          <div className="mt-6 flex justify-end">
            <div className="w-8 h-8 rounded-full bg-[#BED3E3]/20 flex items-center justify-center text-[#BED3E3] group-hover:translate-x-1 transition">
              →
            </div>
          </div>
        </div>

        {/* CARD 4: EMPOWER */}
        <div 
          onClick={() => {
            setEmpowerSubTab("learning");
            setActiveTab("empower");
          }}
          className="kural-card p-6 cursor-pointer group hover:border-[#ECAAC2]/60 transition flex flex-col justify-between"
          style={{ background: 'var(--grad-empower)' }}
        >
          <div>
            <div className="w-12 h-12 rounded-2xl bg-[#ECAAC2]/20 border border-[#ECAAC2]/30 flex items-center justify-center text-[#ECAAC2] mb-4">
              <Icons.Empower className="w-6 h-6" />
            </div>
            <h3 className="font-poppins font-bold text-lg text-white mb-1">Empower</h3>
            <p className="text-xs text-slate-300">Learn, grow and be independent</p>
          </div>
          <div className="mt-6 flex justify-end">
            <div className="w-8 h-8 rounded-full bg-[#ECAAC2]/20 flex items-center justify-center text-[#ECAAC2] group-hover:translate-x-1 transition">
              →
            </div>
          </div>
        </div>

      </div>

      {/* SOS EMERGENCY BANNER */}
      <div 
        className="kural-card p-6 rounded-[28px] border-[#EEBFD1]/40 flex flex-col sm:flex-row items-center justify-between gap-6"
        style={{ background: 'var(--grad-sos)' }}
      >
        <div className="flex items-center gap-5">
          <div className="w-16 h-16 rounded-2xl bg-[#EEBFD1]/20 border border-[#EEBFD1]/30 flex items-center justify-center siren-glowing">
            <Icons.Siren className="w-10 h-10" />
          </div>
          <div>
            <h3 className="font-poppins font-bold text-xl text-white">SOS Emergency</h3>
            <p className="text-xs sm:text-sm text-[#EEBFD1]">One tap for immediate help</p>
          </div>
        </div>

        <button 
          onClick={triggerSOS}
          className="px-8 py-3.5 rounded-2xl bg-gradient-to-r from-[#EEBFD1] to-[#ECAAC2] hover:opacity-95 text-[#060814] font-poppins font-bold text-sm shadow-lg shadow-[#EEBFD1]/20 flex items-center gap-2 transition"
        >
          <span>Tap for SOS</span>
          <span>→</span>
        </button>
      </div>

      {/* QUICK ACCESS SECTION */}
      <div className="space-y-4">
        <div className="flex items-center justify-between">
          <h2 className="font-poppins font-bold text-lg text-white flex items-center gap-2">
            <span className="w-1.5 h-5 rounded-full bg-[#EEBFD1]"></span>
            <span>Quick Access</span>
          </h2>
          <button 
            onClick={() => setActiveTab("empower")} 
            className="text-xs font-semibold text-[#EEBFD1] hover:underline flex items-center gap-1"
          >
            <span>See All</span>
            <span>→</span>
          </button>
        </div>

        <div className="grid grid-cols-2 sm:grid-cols-4 gap-4">
          
          <button 
            onClick={() => setActiveTab("emergency")}
            className="kural-card p-5 rounded-3xl flex flex-col items-center text-center group hover:border-[#DABBE0]/50 transition"
          >
            <div className="w-14 h-14 rounded-full bg-[#DABBE0]/20 border border-[#DABBE0]/30 flex items-center justify-center text-[#DABBE0] group-hover:scale-110 transition mb-3">
              <Icons.Phone className="w-6 h-6" />
            </div>
            <span className="text-xs font-semibold text-slate-200">Emergency Contacts</span>
          </button>

          <button 
            onClick={() => {
              setEmpowerSubTab("resources");
              setActiveTab("empower");
            }}
            className="kural-card p-5 rounded-3xl flex flex-col items-center text-center group hover:border-[#BED3E3]/50 transition"
          >
            <div className="w-14 h-14 rounded-full bg-[#BED3E3]/20 border border-[#BED3E3]/30 flex items-center justify-center text-[#BED3E3] group-hover:scale-110 transition mb-3">
              <Icons.DocumentShield className="w-6 h-6" />
            </div>
            <span className="text-xs font-semibold text-slate-200">Safety Resources</span>
          </button>

          <button 
            onClick={() => {
              setEmpowerSubTab("learning");
              setActiveTab("empower");
            }}
            className="kural-card p-5 rounded-3xl flex flex-col items-center text-center group hover:border-[#EEBFD1]/50 transition"
          >
            <div className="w-14 h-14 rounded-full bg-[#EEBFD1]/20 border border-[#EEBFD1]/30 flex items-center justify-center text-[#EEBFD1] group-hover:scale-110 transition mb-3">
              <Icons.Book className="w-6 h-6" />
            </div>
            <span className="text-xs font-semibold text-slate-200">Digital Learning</span>
          </button>

          <button 
            onClick={() => setActiveTab("faqs")}
            className="kural-card p-5 rounded-3xl flex flex-col items-center text-center group hover:border-[#93AECA]/50 transition"
          >
            <div className="w-14 h-14 rounded-full bg-[#93AECA]/20 border border-[#93AECA]/30 flex items-center justify-center text-[#93AECA] group-hover:scale-110 transition mb-3">
              <Icons.QuestionBubble className="w-6 h-6" />
            </div>
            <span className="text-xs font-semibold text-slate-200">FAQs</span>
          </button>

        </div>
      </div>

      {/* INSPIRATIONAL QUOTE SECTION */}
      <div 
        className="kural-card p-6 rounded-3xl border-[#DABBE0]/20 flex flex-col sm:flex-row items-center justify-between gap-4 text-center sm:text-left"
        style={{ background: 'var(--grad-quote)' }}
      >
        <div className="flex items-center gap-4">
          <span className="text-4xl font-serif text-[#DABBE0]">“</span>
          <p className="font-poppins text-sm sm:text-base italic text-[#DABBE0]">
            A safer tomorrow begins with awareness today.
          </p>
        </div>

        <div className="text-[#EEBFD1] text-2xl font-light">
          ♡
        </div>
      </div>

    </div>
  );
}

// --------------------------------------------------------------------------
// UNIFIED SCREEN 1: SAFETY SHIELD (Combines Protect, Prevent, Support)
// --------------------------------------------------------------------------
function UnifiedSafetyShieldScreen({ activeSub, setActiveSub, triggerSOS, showToast }) {
  return (
    <div className="max-w-4xl mx-auto space-y-6 animate-fadeIn">
      
      {/* Sub-tab Navigation */}
      <div className="kural-card p-3 rounded-2xl flex items-center gap-2 border-[#DABBE0]/20">
        {[
          { id: "protect", label: "Protect (SOS & GPS)", icon: Icons.Protect },
          { id: "prevent", label: "Prevent (Danger Audit)", icon: Icons.Prevent },
          { id: "support", label: "Support (Crisis Aid)", icon: Icons.Support },
        ].map(tab => (
          <button
            key={tab.id}
            onClick={() => setActiveSub(tab.id)}
            className={`flex-1 py-2.5 px-4 rounded-xl text-xs font-bold transition flex items-center justify-center gap-2 ${
              activeSub === tab.id 
                ? "bg-[#DABBE0] text-slate-900 shadow-md" 
                : "text-slate-400 hover:text-white hover:bg-white/5"
            }`}
          >
            <span>{tab.label}</span>
          </button>
        ))}
      </div>

      {/* SUB-VIEW 1: PROTECT */}
      {activeSub === "protect" && (
        <div className="kural-card p-8 border-[#DABBE0]/30 space-y-6" style={{ background: 'var(--grad-protect)' }}>
          <div className="w-12 h-12 rounded-2xl bg-[#DABBE0]/20 border border-[#DABBE0]/30 flex items-center justify-center text-[#DABBE0]">
            <Icons.Protect className="w-6 h-6" />
          </div>
          <div>
            <h2 className="font-poppins text-2xl font-bold text-white">Protect: Real-time SOS & Emergency Network</h2>
            <p className="text-xs text-slate-300 leading-relaxed mt-1">
              Coordinated emergency intervention, live encrypted GPS patrol alerts, and rapid police dispatch.
            </p>
          </div>

          <div className="grid grid-cols-1 sm:grid-cols-2 gap-4 pt-2">
            <div className="p-5 rounded-2xl bg-black/40 border border-white/10 space-y-3">
              <h4 className="font-poppins font-bold text-sm text-[#DABBE0]">Immediate SOS Broadcast</h4>
              <p className="text-xs text-slate-300">Instantly alerts registered guardians and nearest Pink Patrol units.</p>
              <button 
                onClick={triggerSOS}
                className="px-5 py-2.5 rounded-xl bg-gradient-to-r from-[#EEBFD1] to-[#ECAAC2] text-slate-900 font-bold text-xs"
              >
                Trigger Live SOS Alert
              </button>
            </div>

            <div className="p-5 rounded-2xl bg-black/40 border border-white/10 space-y-3">
              <h4 className="font-poppins font-bold text-sm text-[#BED3E3]">Safe Route Corridors</h4>
              <p className="text-xs text-slate-300">Live surveillance data prioritizing verified and well-lit transit routes.</p>
              <span className="inline-block px-3 py-1 rounded-full bg-[#BED3E3]/20 text-[#BED3E3] text-[10px] font-semibold">
                8 Patrol Corridors Active
              </span>
            </div>
          </div>
        </div>
      )}

      {/* SUB-VIEW 2: PREVENT */}
      {activeSub === "prevent" && (
        <div className="kural-card p-8 border-[#EEBFD1]/30 space-y-6" style={{ background: 'var(--grad-prevent)' }}>
          <div className="w-12 h-12 rounded-2xl bg-[#EEBFD1]/20 border border-[#EEBFD1]/30 flex items-center justify-center text-[#EEBFD1]">
            <Icons.Prevent className="w-6 h-6" />
          </div>
          <div>
            <h2 className="font-poppins text-2xl font-bold text-white">Prevent: Danger Detection & Transit Audits</h2>
            <p className="text-xs text-slate-300 leading-relaxed mt-1">
              Verified community hazards, unlit subway corridors, and proactive security measures.
            </p>
          </div>

          <div className="space-y-3 pt-2">
            {[
              { area: "Tambaram West Bus Depot", status: "Pink Patrol Motorized Beat Verified", time: "20 mins ago", color: "text-[#DABBE0]" },
              { area: "College Hostel Outer Road", status: "Solar High-Mast Lighting Restored", time: "1 hour ago", color: "text-[#BED3E3]" },
              { area: "Central Metro Subway Corridor", status: "CCTV Audit Cleared by Special Division", time: "3 hours ago", color: "text-[#EEBFD1]" }
            ].map((item, idx) => (
              <div key={idx} className="p-4 rounded-2xl bg-black/40 border border-white/10 flex items-center justify-between text-xs">
                <div>
                  <span className="font-semibold text-white block">{item.area}</span>
                  <span className="text-slate-400">{item.status}</span>
                </div>
                <span className={`font-mono text-[11px] ${item.color}`}>{item.time}</span>
              </div>
            ))}
          </div>
        </div>
      )}

      {/* SUB-VIEW 3: SUPPORT */}
      {activeSub === "support" && (
        <div className="kural-card p-8 border-[#BED3E3]/30 space-y-6" style={{ background: 'var(--grad-support)' }}>
          <div className="w-12 h-12 rounded-2xl bg-[#BED3E3]/20 border border-[#BED3E3]/30 flex items-center justify-center text-[#BED3E3]">
            <Icons.Support className="w-6 h-6" />
          </div>
          <div>
            <h2 className="font-poppins text-2xl font-bold text-white">Support: Assistance Anytime, Anywhere</h2>
            <p className="text-xs text-slate-300 leading-relaxed mt-1">
              Immediate legal aid clinics, trauma psychologists, and One Stop Sakhi Centre shelter assistance.
            </p>
          </div>

          <div className="grid grid-cols-1 sm:grid-cols-2 gap-4 pt-2">
            <div className="p-5 rounded-2xl bg-black/40 border border-white/10 space-y-2">
              <h4 className="font-bold text-white text-sm">One Stop Sakhi Crisis Centre</h4>
              <p className="text-xs text-slate-400">Integrated medical, legal counseling and safe temporary shelter under one roof.</p>
              <a href="tel:181" className="inline-block mt-2 px-4 py-2 rounded-xl bg-[#BED3E3] text-slate-900 font-bold text-xs">
                Call 181 (Sakhi)
              </a>
            </div>

            <div className="p-5 rounded-2xl bg-black/40 border border-white/10 space-y-2">
              <h4 className="font-bold text-white text-sm">Free Legal Aid Clinic</h4>
              <p className="text-xs text-slate-400">Senior advocates empaneled under State Legal Services Authority (SLSA).</p>
              <button onClick={() => showToast("Legal Consultation Desk scheduled")} className="mt-2 px-4 py-2 rounded-xl bg-white/10 text-white font-semibold text-xs border border-white/15">
                Request Counsel
              </button>
            </div>
          </div>
        </div>
      )}

    </div>
  );
}

// --------------------------------------------------------------------------
// UNIFIED SCREEN 2: EMPOWER (Combines Digital Learning & Safety Resources)
// --------------------------------------------------------------------------
function UnifiedEmpowerScreen({ activeSub, setActiveSub, showToast }) {
  return (
    <div className="max-w-4xl mx-auto space-y-6 animate-fadeIn">
      
      {/* Sub-tab Navigation */}
      <div className="kural-card p-3 rounded-2xl flex items-center gap-2 border-[#ECAAC2]/20">
        {[
          { id: "learning", label: "Digital Learning & Courses" },
          { id: "resources", label: "Safety Resources & Acts" },
        ].map(tab => (
          <button
            key={tab.id}
            onClick={() => setActiveSub(tab.id)}
            className={`flex-1 py-2.5 px-4 rounded-xl text-xs font-bold transition ${
              activeSub === tab.id 
                ? "bg-[#ECAAC2] text-slate-900 shadow-md" 
                : "text-slate-400 hover:text-white hover:bg-white/5"
            }`}
          >
            {tab.label}
          </button>
        ))}
      </div>

      {/* SUB-VIEW 1: DIGITAL LEARNING */}
      {activeSub === "learning" && (
        <div className="kural-card p-8 border-[#ECAAC2]/30 space-y-6">
          <div className="flex items-center justify-between">
            <div>
              <h2 className="font-poppins text-2xl font-bold text-white">Digital Learning Modules</h2>
              <p className="text-xs text-slate-400">Learn, grow, and attain safety independence with verified courses.</p>
            </div>
          </div>

          <div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
            {window.KURAL_DATA?.LEARNING.map(c => (
              <div key={c.id} className="p-5 rounded-2xl bg-white/5 border border-white/10 space-y-3 text-xs flex flex-col justify-between">
                <div>
                  <span className="text-[10px] font-bold px-2 py-0.5 rounded-full bg-[#ECAAC2]/20 text-[#ECAAC2]">
                    {c.badge}
                  </span>
                  <h4 className="font-poppins font-bold text-sm text-white mt-2">{c.title}</h4>
                  <div className="text-slate-400 mt-1">{c.modules} Modules • {c.duration}</div>
                  <ul className="space-y-1 mt-3 pt-3 border-t border-white/10 text-[11px] text-slate-300">
                    {c.topics.map((t, idx) => (
                      <li key={idx}>• {t}</li>
                    ))}
                  </ul>
                </div>
                <button 
                  onClick={() => showToast(`Course started: ${c.title}`)}
                  className="w-full py-2.5 rounded-xl bg-[#ECAAC2]/20 text-[#ECAAC2] font-semibold hover:bg-[#ECAAC2] hover:text-slate-900 transition mt-2"
                >
                  Start Course →
                </button>
              </div>
            ))}
          </div>
        </div>
      )}

      {/* SUB-VIEW 2: SAFETY RESOURCES */}
      {activeSub === "resources" && (
        <div className="kural-card p-8 border-[#BED3E3]/30 space-y-6">
          <div>
            <h2 className="font-poppins text-2xl font-bold text-white">Statutory Safety Resources & Acts</h2>
            <p className="text-xs text-slate-400">Handbooks on PoSH Act 2013, Cyber Stalking, Anti-Ragging regulations, and PWDVA.</p>
          </div>

          <div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
            {window.KURAL_DATA?.RESOURCES.map(r => (
              <div key={r.id} className="p-5 rounded-2xl bg-white/5 border border-white/10 space-y-3 text-xs flex flex-col justify-between">
                <div>
                  <span className="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-[#BED3E3]/20 text-[#BED3E3]">
                    {r.category} • {r.readTime}
                  </span>
                  <h4 className="font-poppins font-bold text-sm text-white mt-2">{r.title}</h4>
                  <p className="text-slate-300 text-xs mt-1.5 leading-relaxed">{r.summary}</p>
                </div>
                <button 
                  onClick={() => showToast(`Downloaded: ${r.file}`)}
                  className="w-full py-2.5 rounded-xl bg-white/10 hover:bg-white/20 text-white font-medium text-xs border border-white/10 transition mt-2"
                >
                  📥 Download PDF Guide
                </button>
              </div>
            ))}
          </div>
        </div>
      )}

    </div>
  );
}

// --------------------------------------------------------------------------
// UNIFIED SCREEN 3: MY COMPLAINTS & TRACK COMPLAINTS
// --------------------------------------------------------------------------
function UnifiedComplaintsScreen({ activeSub, setActiveSub, showToast }) {
  const [complaints, setComplaints] = useState(() => window.KURAL_DATA?.COMPLAINTS || []);
  const [activeComplaint, setActiveComplaint] = useState(() => complaints[0]);
  const [newTitle, setNewTitle] = useState("");
  const [newCategory, setNewCategory] = useState("College Ragging");
  const [newDesc, setNewDesc] = useState("");

  const handleRegister = (e) => {
    e.preventDefault();
    if (!newTitle.trim()) return;

    const newEntry = {
      id: `KUR-2026-${Math.floor(1000 + Math.random() * 9000)}`,
      title: newTitle,
      category: newCategory,
      department: newCategory === "College Ragging" ? "Anti-Ragging Committee" : "Appropriate Complaints Committee",
      filedDate: "2026-11-24 21:55",
      urgency: "High",
      currentStep: 1,
      statusText: "Complaint Created",
      summary: newDesc || "Grievance submitted through Kural desktop portal.",
      officer: "Designated Nodal Officer"
    };

    setComplaints([newEntry, ...complaints]);
    setActiveComplaint(newEntry);
    setNewTitle("");
    setNewDesc("");
    showToast(`Complaint ${newEntry.id} registered! Switched to live tracker.`);
    setActiveSub("track");
  };

  const advanceStep = () => {
    if (activeComplaint.currentStep >= 8) {
      showToast("Complaint is already in final 'Resolved' status.");
      return;
    }
    const nextStep = activeComplaint.currentStep + 1;
    const updated = {
      ...activeComplaint,
      currentStep: nextStep,
      statusText: nextStep === 7 ? "Action in Progress" : nextStep === 8 ? "Resolved" : activeComplaint.statusText
    };
    setActiveComplaint(updated);
    setComplaints(complaints.map(c => c.id === updated.id ? updated : c));
    showToast(`Progressed to Step ${nextStep}!`);
  };

  const steps = [
    "Complaint Created",
    "Risk Assessment",
    "Department Assigned",
    "Complaint Forwarded",
    "Acknowledgement Received",
    "Under Review",
    "Action in Progress",
    "Resolved"
  ];

  return (
    <div className="max-w-4xl mx-auto space-y-6 animate-fadeIn">
      
      {/* Sub-tab Navigation */}
      <div className="kural-card p-3 rounded-2xl flex items-center gap-2 border-[#DABBE0]/20">
        {[
          { id: "list", label: "My Complaints & Registration" },
          { id: "track", label: "Live 8-Stage Progress Tracker" },
        ].map(tab => (
          <button
            key={tab.id}
            onClick={() => setActiveSub(tab.id)}
            className={`flex-1 py-2.5 px-4 rounded-xl text-xs font-bold transition ${
              activeSub === tab.id 
                ? "bg-[#DABBE0] text-slate-900 shadow-md" 
                : "text-slate-400 hover:text-white hover:bg-white/5"
            }`}
          >
            {tab.label}
          </button>
        ))}
      </div>

      {/* SUB-VIEW 1: COMPLAINTS LIST & REGISTRATION */}
      {activeSub === "list" && (
        <div className="kural-card p-8 border-[#DABBE0]/30 space-y-6">
          <h2 className="font-poppins text-2xl font-bold text-white">My Registered Complaints</h2>

          {/* Form */}
          <form onSubmit={handleRegister} className="p-5 rounded-2xl bg-white/5 border border-white/10 space-y-3 text-xs">
            <h4 className="font-poppins font-bold text-sm text-[#DABBE0]">Register New Statutory Grievance</h4>
            <input 
              type="text"
              value={newTitle}
              onChange={(e) => setNewTitle(e.target.value)}
              placeholder="Complaint subject (e.g., Campus Ragging in Hostel Wing)..."
              className="w-full p-3 rounded-xl bg-black/40 border border-white/15 text-white focus:outline-none focus:border-[#DABBE0]"
            />
            <div className="grid grid-cols-2 gap-3">
              <select 
                value={newCategory}
                onChange={(e) => setNewCategory(e.target.value)}
                className="p-3 rounded-xl bg-black/40 border border-white/15 text-white text-xs"
              >
                <option value="College Ragging">College Ragging (Anti-Ragging Committee)</option>
                <option value="Workplace Harassment">Workplace Harassment (PoSH Committee)</option>
                <option value="Scholarship">Scholarship & Social Welfare Authority</option>
                <option value="Cyber Harassment">Cyber Harassment (Women Cyber Cell)</option>
              </select>
              <button 
                type="submit"
                className="px-6 py-3 rounded-xl bg-gradient-to-r from-[#DABBE0] to-[#EEBFD1] text-slate-900 font-bold text-xs"
              >
                Submit & Open Tracker
              </button>
            </div>
          </form>

          {/* List */}
          <div className="space-y-3">
            {complaints.map(c => (
              <div 
                key={c.id} 
                onClick={() => {
                  setActiveComplaint(c);
                  setActiveSub("track");
                  showToast(`Opened Tracker for ${c.id}`);
                }}
                className="p-5 rounded-2xl bg-white/5 border border-white/10 hover:border-[#DABBE0]/50 cursor-pointer transition flex flex-col sm:flex-row sm:items-center justify-between gap-3 text-xs"
              >
                <div>
                  <span className="font-mono font-bold text-[#EEBFD1]">{c.id}</span>
                  <h4 className="font-poppins font-bold text-sm text-white mt-0.5">{c.title}</h4>
                  <div className="text-slate-400 mt-1">{c.department} • Filed: {c.filedDate}</div>
                </div>
                <div className="flex items-center gap-3">
                  <span className="px-3 py-1 rounded-full text-xs font-semibold bg-[#DABBE0]/20 text-[#DABBE0] border border-[#DABBE0]/30">
                    {c.statusText}
                  </span>
                  <span className="text-[#EEBFD1] text-xs font-bold">Track →</span>
                </div>
              </div>
            ))}
          </div>
        </div>
      )}

      {/* SUB-VIEW 2: LIVE 8-STAGE PROGRESS TRACKER */}
      {activeSub === "track" && (
        <div className="kural-card p-8 border-[#DABBE0]/30 space-y-6">
          <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3 border-b border-white/10 pb-4">
            <div>
              <span className="font-mono text-xs text-[#EEBFD1] font-bold">{activeComplaint.id}</span>
              <h2 className="font-poppins text-xl font-bold text-white mt-1">{activeComplaint.title}</h2>
              <div className="text-xs text-slate-400 mt-0.5">{activeComplaint.department}</div>
            </div>
            <button 
              onClick={advanceStep}
              className="px-4 py-2 rounded-xl bg-[#DABBE0] text-slate-900 font-bold text-xs shadow-md"
            >
              Advance Step (Demo)
            </button>
          </div>

          {/* 8-Stage Tracker */}
          <div className="space-y-3 pt-2">
            {steps.map((st, idx) => {
              const stepNum = idx + 1;
              const isDone = stepNum <= activeComplaint.currentStep;
              const isCurrent = stepNum === activeComplaint.currentStep;

              return (
                <div key={idx} className="flex items-center gap-4 text-xs">
                  <div className={`w-8 h-8 rounded-full flex items-center justify-center font-bold transition ${
                    isCurrent 
                      ? "bg-[#EEBFD1] text-slate-900 ring-4 ring-[#EEBFD1]/30" 
                      : isDone 
                      ? "bg-[#DABBE0] text-slate-900" 
                      : "bg-white/10 text-slate-500"
                  }`}>
                    {isDone ? "✓" : stepNum}
                  </div>
                  <div className="flex-1 p-3 rounded-xl bg-white/5 border border-white/5 flex items-center justify-between">
                    <span className={`font-semibold ${isCurrent ? 'text-[#EEBFD1]' : isDone ? 'text-white' : 'text-slate-500'}`}>
                      {stepNum}. {st}
                    </span>
                    <span className="text-[10px] text-slate-400">
                      {isCurrent ? "Active Step" : isDone ? "Completed" : "Pending"}
                    </span>
                  </div>
                </div>
              );
            })}
          </div>
        </div>
      )}

    </div>
  );
}

// --------------------------------------------------------------------------
// OTHER SCREENS (Emergency Contacts, FAQs, Profile, Settings)
// --------------------------------------------------------------------------
function EmergencyScreen({ triggerSOS, showToast }) {
  return (
    <div className="max-w-4xl mx-auto space-y-6 animate-fadeIn">
      <div className="kural-card p-8 border-[#EEBFD1]/30 space-y-6">
        <div className="flex items-center justify-between">
          <h2 className="font-poppins text-2xl font-bold text-white">Emergency Helplines Directory</h2>
          <button 
            onClick={triggerSOS}
            className="px-4 py-2 rounded-xl bg-[#EEBFD1] text-slate-900 font-bold text-xs"
          >
            Trigger SOS
          </button>
        </div>

        <div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
          {window.KURAL_DATA?.HELPLINES.map((h, idx) => (
            <div key={idx} className="p-5 rounded-2xl bg-white/5 border border-white/10 space-y-2 text-xs">
              <div className="flex items-start justify-between">
                <div>
                  <h4 className="font-poppins font-bold text-sm text-white">{h.name}</h4>
                  <div className="font-mono text-xl font-bold text-[#EEBFD1] mt-1">{h.number}</div>
                </div>
                <a 
                  href={`tel:${h.number.split(' ')[0]}`}
                  className="px-3 py-1.5 rounded-lg bg-[#EEBFD1]/20 text-[#EEBFD1] font-bold text-xs hover:bg-[#EEBFD1] hover:text-slate-900 transition"
                >
                  Call
                </a>
              </div>
              <p className="text-slate-400 text-[11px] leading-relaxed">{h.desc}</p>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

function FAQsScreen() {
  const [openIdx, setOpenIdx] = useState(0);

  return (
    <div className="max-w-4xl mx-auto space-y-6 animate-fadeIn">
      <div className="kural-card p-8 border-[#93AECA]/30 space-y-6">
        <h2 className="font-poppins text-2xl font-bold text-white">Frequently Asked Questions</h2>

        <div className="space-y-3">
          {window.KURAL_DATA?.FAQS.map((f, idx) => (
            <div key={idx} className="p-4 rounded-2xl bg-white/5 border border-white/10 text-xs">
              <button 
                onClick={() => setOpenIdx(openIdx === idx ? null : idx)}
                className="w-full text-left font-poppins font-semibold text-sm text-white flex items-center justify-between"
              >
                <span>{f.q}</span>
                <span>{openIdx === idx ? "−" : "+"}</span>
              </button>
              {openIdx === idx && (
                <p className="mt-3 text-slate-300 leading-relaxed border-t border-white/10 pt-2">
                  {f.a}
                </p>
              )}
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

function ProfileScreen({ showToast }) {
  return (
    <div className="max-w-4xl mx-auto space-y-6 animate-fadeIn">
      <div className="kural-card p-8 border-[#DABBE0]/30 space-y-6">
        <div className="flex items-center gap-6">
          <div className="w-20 h-20 rounded-full bg-gradient-to-tr from-[#DABBE0] to-[#EEBFD1] p-0.5">
            <div className="w-full h-full rounded-full bg-[#0A0D1E] flex items-center justify-center font-cormorant text-3xl font-bold text-[#DABBE0]">
              P
            </div>
          </div>
          <div>
            <h2 className="font-poppins text-2xl font-bold text-white">Priya S.</h2>
            <div className="text-xs text-slate-400">priya.demo@kural.org • +91 98765 43210</div>
            <span className="inline-block mt-2 px-3 py-0.5 rounded-full bg-[#DABBE0]/20 text-[#DABBE0] text-[10px] font-semibold">
              Verified Citizen Profile
            </span>
          </div>
        </div>

        <div className="pt-4 border-t border-white/10 space-y-3 text-xs">
          <h4 className="font-poppins font-bold text-sm text-white">Emergency SOS Recipient</h4>
          <div className="p-4 rounded-xl bg-white/5 border border-white/10 flex items-center justify-between">
            <span>Kasthuri (Mother) - +91 94440 98765</span>
            <button onClick={() => showToast("Emergency Contact updated")} className="text-[#EEBFD1] font-semibold">Edit</button>
          </div>
        </div>
      </div>
    </div>
  );
}

function SettingsScreen({ theme, setTheme, showToast }) {
  return (
    <div className="max-w-4xl mx-auto space-y-6 animate-fadeIn">
      <div className="kural-card p-8 border-[#DABBE0]/30 space-y-6">
        <h2 className="font-poppins text-2xl font-bold text-white">Theme & Settings</h2>

        <div className="space-y-4 text-xs">
          <div>
            <label className="text-slate-300 font-semibold block mb-2">Display Theme</label>
            <div className="grid grid-cols-2 gap-4">
              <button 
                onClick={() => {
                  setTheme("dark");
                  showToast("Switched to Dark Mode");
                }}
                className={`p-4 rounded-2xl border text-center transition ${
                  theme === 'dark' ? 'bg-[#DABBE0]/20 border-[#DABBE0] text-white font-bold' : 'bg-white/5 border-white/10 text-slate-400'
                }`}
              >
                <div className="flex justify-center mb-1">
                  <Icons.Moon className="w-6 h-6" />
                </div>
                <div>Dark Mode (Default)</div>
              </button>

              <button 
                onClick={() => {
                  setTheme("light");
                  showToast("Switched to Light Mode");
                }}
                className={`p-4 rounded-2xl border text-center transition ${
                  theme === 'light' ? 'bg-[#DABBE0]/20 border-[#DABBE0] text-white font-bold' : 'bg-white/5 border-white/10 text-slate-400'
                }`}
              >
                <div className="flex justify-center mb-1">
                  <Icons.Sun className="w-6 h-6" />
                </div>
                <div>Light Mode</div>
              </button>
            </div>
          </div>

          <div className="pt-4 border-t border-white/10">
            <h4 className="font-poppins font-bold text-sm text-white mb-2">Studio Vaia Palette Reference</h4>
            <div className="grid grid-cols-5 gap-2 text-center text-[10px]">
              <div className="p-2 rounded-lg bg-[#DABBE0] text-slate-900 font-mono font-bold">#DABBE0<br/>Lavender</div>
              <div className="p-2 rounded-lg bg-[#BED3E3] text-slate-900 font-mono font-bold">#BED3E3<br/>Soft Sky</div>
              <div className="p-2 rounded-lg bg-[#EEBFD1] text-slate-900 font-mono font-bold">#EEBFD1<br/>Flamingo</div>
              <div className="p-2 rounded-lg bg-[#ECAAC2] text-slate-900 font-mono font-bold">#ECAAC2<br/>Mauve</div>
              <div className="p-2 rounded-lg bg-[#93AECA] text-slate-900 font-mono font-bold">#93AECA<br/>Denim</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

// Mount React Root
const rootElement = document.getElementById("root");
ReactDOM.createRoot(rootElement).render(<App />);
