// Podform MVP — simplified single-file React app
// Core journey: Land → Browse → View podcast → Submit request
// No login required. No dashboards. No chat. No payments.
const { useState } = React;

// ── Icons (minimal set) ──
const _ic = (paths, p) => {
  const {size=24,fill:fi,style:s,...r} = p||{};
  const ch = (Array.isArray(paths)?paths:[paths]).map((d,i) => typeof d==='string'? React.createElement('path',{key:i,d}) : React.createElement(d.t||'path',{key:i,...d}));
  return React.createElement('svg',{width:size,height:size,viewBox:'0 0 24 24',fill:fi||'none',stroke:'currentColor',strokeWidth:2,strokeLinecap:'round',strokeLinejoin:'round',style:s,...r},...ch);
};
const Search=(p)=>_ic(["M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5z","M16 16l4.5 4.5"],p);
const Mic=(p)=>_ic([{t:'rect',x:9,y:1,width:6,height:12,rx:3},"M19 10v2a7 7 0 0 1-14 0v-2","M12 19v4","M8 23h8"],p);
const ArrowRight=(p)=>_ic(["M5 12h14","M12 5l7 7-7 7"],p);
const ArrowLeft=(p)=>_ic(["M19 12H5","M12 19l-7-7 7-7"],p);
const Check=(p)=>_ic("M20 6L9 17l-5-5",p);
const Shield=(p)=>_ic("M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",p);
const Users=(p)=>_ic(["M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2",{t:'circle',cx:9,cy:7,r:4},"M23 21v-2a4 4 0 0 0-3-3.87","M16 3.13a4 4 0 0 1 0 7.75"],p);
const Play=(p)=>_ic({t:'polygon',points:"5 3 19 12 5 21 5 3"},p);
const Send=(p)=>_ic(["M22 2L11 13","M22 2l-7 20-4-9-9-4 20-7z"],p);
const Mail=(p)=>_ic([{t:'rect',x:2,y:4,width:20,height:16,rx:2},"M22 7l-10 7L2 7"],p);
const ChevronRight=(p)=>_ic("M9 18l6-6-6-6",p);
const ChevronDown=(p)=>_ic("M6 9l6 6 6-6",p);
const ChevronUp=(p)=>_ic("M18 15l-6-6-6 6",p);
const Star=(p)=>{const{fill:f,...r}=p||{};return _ic({t:'polygon',points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2",...(f?{fill:f}:{})},r);};
const X=(p)=>_ic(["M18 6L6 18","M6 6l12 12"],p);

function PodformLogo({ size = 28, color = "#7EE8D5" }) {
  return (
    <svg width={size} height={size} viewBox="0 0 469.29 491.75" fill={color} xmlns="http://www.w3.org/2000/svg">
      <path d="M0,29.61v199.57c0,9.18,3.65,17.99,10.14,24.48l227.95,227.95c13.52,13.52,35.44,13.52,48.95,0l172.1-172.1c6.49-6.49,10.14-15.3,10.14-24.48V12.4C469.29,5.55,463.73,0,456.88,0h-215.59c-30.84,0-46.28,37.29-24.48,59.09l88.49,88.49c13.52,13.52,13.52,35.44,0,48.95l-141.29,141.29c-7.81,7.81-21.17,2.28-21.17-8.77v-163.29c0-16.12-6.47-31.56-17.95-42.86L21.1,20.77C13.26,13.05,0,18.61,0,29.61Z"/>
    </svg>
  );
}

// ── Podcast data ──
const INITIAL_PODCASTS = [
  { id:"1", name:"Gaurar Með Stæla", cat:"Grín", desc:"Unnar, Ingi og Tommi beint í æð alla mánudaga. Hér verða strákar að gaurum og stelpur að gellum.", listeners:0, eps:5, freq:"Vikulega", rating:5.0, reviews:33, age:{a1:0,a2:0,a3:0,a4:0,a5:0}, gender:{m:0,f:0,o:0}, loc:{rvk:0,other:0}, color:"#dc2626", img:"./covers/gaurar.jpg" },
  { id:"2", name:"CURLY FM", cat:"Samfélag", desc:"Jakob og Krulli — snáðar að snáðast í boði tveir heimskir ehf.", listeners:0, eps:96, freq:"Vikulega", rating:4.5, reviews:87, age:{a1:0,a2:0,a3:0,a4:0,a5:0}, gender:{m:0,f:0,o:0}, loc:{rvk:0,other:0}, color:"#f59e0b", img:"./covers/curly.jpg" },
];

const CATS = ["Allt","Fréttir","Tækni","Glæpasögur","Heilsa","Íþróttir","Viðskipti","Menning","Saga","Grín","Fræðsla","Tónlist","Vísindi","Samfélag"];

const fmtK = (n) => n >= 10000 ? (n/1000).toFixed(0)+"k" : n >= 1000 ? (n/1000).toFixed(1)+"k" : String(n);

function RatingStars({rating, size = 14}) {
  return (
    <span className="inline-flex items-center gap-0.5">
      {[1,2,3,4,5].map(i => (
        <Star key={i} size={size} fill={i <= Math.round(rating) ? "#f59e0b" : "none"} stroke="#f59e0b" strokeWidth={1.5}/>
      ))}
    </span>
  );
}

function ProgressBar({pct, color}) {
  return (
    <div className="flex-1 h-1.5 rounded-full bg-gray-800">
      <div className="h-full rounded-full transition-all duration-500" style={{width: pct+"%", backgroundColor: color}}/>
    </div>
  );
}

function PodImg({pod, size = 44, radius = "rounded-xl"}) {
  const s = size + "px";
  if (pod.img) return <img src={pod.img} alt={pod.name} className={`${radius} shrink-0 object-cover`} style={{width:s,height:s}}/>;
  return <div className={`${radius} flex items-center justify-center text-white shrink-0`} style={{width:s,height:s,background:`linear-gradient(135deg,${pod.color},${pod.color}99)`}}><Mic size={Math.round(size*0.4)}/></div>;
}

// ── Main App ──
function PodformApp() {
  const [view, setView] = useState("landing");
  const [q, setQ] = useState("");
  const [cat, setCat] = useState("Allt");
  const [selPod, setSelPod] = useState(null);
  const [openFaq, setOpenFaq] = useState(null);
  const [toast, setToast] = useState(null);
  const [showMobileMenu, setShowMobileMenu] = useState(false);
  const [requestForm, setRequestForm] = useState({
    companyName:"", contactName:"", email:"", phone:"", message:"", podcast:""
  });
  const [podcastForm, setPodcastForm] = useState({
    podcastName:"", contactName:"", email:"", phone:"", message:""
  });
  // Podcast state (mutable for admin CRUD)
  const [podcasts, setPodcasts] = useState(INITIAL_PODCASTS);
  // Admin state
  const [adminPass, setAdminPass] = useState("");
  const [adminAuth, setAdminAuth] = useState(false);
  const [editPod, setEditPod] = useState(null); // null = closed, {} = new, {id:...} = editing
  const [deletePod, setDeletePod] = useState(null); // podcast to confirm delete

  const ADMIN_PASSWORD = "podform2026";

  const emptyPodForm = () => ({name:"",cat:"Fréttir",desc:"",listeners:"",eps:"",freq:"Vikulega",rating:"4.5",reviews:"0",age:{a1:"0",a2:"0",a3:"0",a4:"0",a5:"0"},gender:{m:"0",f:"0",o:"0"},loc:{rvk:"0",other:"0"},color:"#7c3aed",img:""});

  const go = (v) => { setView(v); window.scrollTo(0,0); setShowMobileMenu(false); };
  const showToast = (msg) => { setToast(msg); setTimeout(() => setToast(null), 3500); };

  const filtered = podcasts.filter(p => {
    if (cat !== "Allt" && p.cat !== cat) return false;
    if (q.trim()) { const s = q.toLowerCase(); return p.name.toLowerCase().includes(s) || p.desc.toLowerCase().includes(s); }
    return true;
  });

  const handleRequestSubmit = (e) => {
    e.preventDefault();
    const f = requestForm;
    if (!f.companyName || !f.contactName || !f.email) {
      showToast("Vinsamlegast fylltu út nauðsynlega reiti.");
      return;
    }
    // Send to Formspree
    fetch("https://formspree.io/f/meeppnlw", {
      method: "POST",
      headers: {"Content-Type": "application/json", "Accept": "application/json"},
      body: JSON.stringify({
        podcast: requestForm.podcast || "Ekkert valið",
        companyName: requestForm.companyName,
        contactName: requestForm.contactName,
        email: requestForm.email,
        phone: requestForm.phone || "—",
        message: requestForm.message || "—",
      }),
    }).then(res => {
      if (res.ok) {
        showToast("Fyrirspurn móttekin! Við höfum samband fljótlega.");
        setRequestForm({companyName:"", contactName:"", email:"", phone:"", message:"", podcast:""});
        go("landing");
      } else {
        showToast("Villa kom upp. Reyndu aftur.");
      }
    }).catch(() => {
      showToast("Villa kom upp. Reyndu aftur.");
    });
  };

  return (
    <div className="min-h-screen" style={{fontFamily:"'Inter','Outfit',system-ui,-apple-system,sans-serif", backgroundColor:"#0B1120"}}>

      {toast && (
        <div className="fixed top-4 left-1/2 -translate-x-1/2 z-50 px-6 py-2.5 rounded-xl text-sm font-semibold shadow-lg" style={{backgroundColor:"#7EE8D5",color:"#0B1120",animation:"fadeIn .3s ease"}}>
          {toast}
        </div>
      )}

      <style>{`
        @keyframes fadeIn { from { opacity:0; transform:translateY(8px) } to { opacity:1; transform:translateY(0) } }
        .fade-in { animation: fadeIn .4s ease; }
        .hover-lift { transition: all .2s ease; }
        .hover-lift:hover { transform: translateY(-3px); box-shadow: 0 12px 28px -6px rgba(126,232,213,0.06); }
        ::placeholder { color: #475569; }
        input:focus, textarea:focus, select:focus { outline: none; border-color: #7EE8D5 !important; box-shadow: 0 0 0 3px rgba(126,232,213,0.08); }
        input, textarea, select { font-family: inherit; }
        ::-webkit-scrollbar { width: 5px; } ::-webkit-scrollbar-thumb { background: #1A2744; border-radius: 3px; }
        .btn-primary { text-transform: uppercase; letter-spacing: 0.6px; border-radius: 8px !important; }
        .btn-secondary { text-transform: uppercase; letter-spacing: 0.6px; border-radius: 8px !important; }
        h1, h2, h3 { font-family: 'Outfit', system-ui, sans-serif; }
        @media (max-width: 767px) {
          .hero-heading { font-size: 1.75rem !important; line-height: 1.15 !important; margin-bottom: 1rem !important; }
          .hero-sub { font-size: 0.9rem !important; margin-bottom: 1.25rem !important; }
          .hero-section { min-height: auto !important; padding-top: 2.5rem; padding-bottom: 1.5rem; }
          .hero-btns { gap: 0.5rem !important; }
          .hero-btns > * { padding-top: 0.75rem !important; padding-bottom: 0.75rem !important; padding-left: 1.25rem !important; padding-right: 1.25rem !important; }
          .hero-stats { gap: 0.5rem !important; margin-bottom: 0 !important; }
          .hero-stats > div { padding: 0.375rem 0.625rem !important; }
          .hero-stats > div span { font-size: 0.7rem !important; }
          .nav-cta { padding: 0.5rem 0.75rem !important; font-size: 10px !important; }
        }
        @media (min-width: 768px) and (max-width: 1023px) {
          .hero-heading { font-size: 2.5rem !important; }
          .hero-section { min-height: 70vh !important; }
        }
      `}</style>

      {/* ═══ NAV ═══ */}
      <nav className="sticky top-0 z-40 border-b" style={{backgroundColor:"rgba(11,17,32,0.95)",backdropFilter:"blur(12px)",borderColor:"#1A2744"}}>
        <div className="max-w-6xl mx-auto h-14 px-5 flex items-center justify-between">
          <div className="flex items-center cursor-pointer gap-2" onClick={() => go("landing")}>
            <PodformLogo size={28}/>
            <span className="text-sm font-bold hidden sm:inline" style={{color:"#ffffff"}}>Podform</span>
          </div>
          <div className="hidden md:flex items-center gap-1">
            <button onClick={() => go("dir")} className="px-3 py-1.5 rounded-lg text-sm font-medium transition-colors" style={{color: view === "dir" || view === "profile" ? "#7EE8D5" : "#94A3B8", backgroundColor: view === "dir" || view === "profile" ? "rgba(126,232,213,0.08)" : "transparent", border:"none"}}>Hlaðvörp</button>
            <button onClick={() => { if(view!=="landing") go("landing"); setTimeout(() => document.getElementById("section-about")?.scrollIntoView({behavior:"smooth"}),100); }} className="px-3 py-1.5 rounded-lg text-sm font-medium" style={{color:"#94A3B8",border:"none",background:"none"}}>Um okkur</button>
            <button onClick={() => { if(view!=="landing") go("landing"); setTimeout(() => document.getElementById("section-how")?.scrollIntoView({behavior:"smooth"}),100); }} className="px-3 py-1.5 rounded-lg text-sm font-medium" style={{color:"#94A3B8",border:"none",background:"none"}}>Hvernig virkar það?</button>
          </div>
          <div className="flex items-center gap-2">
            <button onClick={() => { setRequestForm(f=>({...f,podcast:""})); go("request"); }} className="btn-primary nav-cta px-5 py-2.5 rounded-lg text-xs font-bold" style={{backgroundColor:"#7EE8D5",color:"#0B1120",border:"none"}}>Hafa samband</button>
            <button className="md:hidden flex items-center justify-center w-9 h-9 rounded-lg" style={{background:"none",border:"1px solid #1A2744",color:"#94A3B8"}} onClick={() => setShowMobileMenu(!showMobileMenu)}>
              {showMobileMenu ? <X size={18}/> : <span style={{fontSize:"18px",lineHeight:1}}>☰</span>}
            </button>
          </div>
        </div>
        {showMobileMenu && (
          <div className="md:hidden border-t px-5 py-3 flex flex-col gap-2" style={{borderColor:"#1A2744",backgroundColor:"#0B1120"}}>
            <button onClick={() => go("dir")} className="text-left py-2 text-sm font-medium" style={{color:"#94A3B8",border:"none",background:"none"}}>Hlaðvörp</button>
            <button onClick={() => { go("landing"); setTimeout(() => document.getElementById("section-about")?.scrollIntoView({behavior:"smooth"}),100); }} className="text-left py-2 text-sm font-medium" style={{color:"#94A3B8",border:"none",background:"none"}}>Um okkur</button>
            <button onClick={() => { go("landing"); setTimeout(() => document.getElementById("section-how")?.scrollIntoView({behavior:"smooth"}),100); }} className="text-left py-2 text-sm font-medium" style={{color:"#94A3B8",border:"none",background:"none"}}>Hvernig virkar það?</button>
          </div>
        )}
      </nav>

      {/* ═══ LANDING ═══ */}
      {view === "landing" && (
        <div className="fade-in">
          {/* Hero — dual-sided */}
          <section className="relative overflow-hidden hero-section" style={{minHeight:"50vh",display:"flex",alignItems:"center",paddingTop:"3rem",paddingBottom:"2rem"}}>
            <div className="max-w-5xl mx-auto px-5 w-full">
              <div className="flex flex-col md:flex-row items-center gap-6 md:gap-8">
                <div className="flex-1" style={{minWidth:280}}>
                  <h1 className="hero-heading text-4xl md:text-5xl font-extrabold tracking-tight leading-tight mb-3" style={{color:"#ffffff",letterSpacing:"-0.03em"}}>
                    Hlaðvörp og fyrirtæki,{" "}
                    <span style={{color:"#7EE8D5"}}>tengd á einum stað</span>
                  </h1>
                  <p className="hero-sub text-base leading-relaxed mb-5" style={{color:"#94A3B8",maxWidth:460}}>
                    Podform gerir fyrirtækjum auðvelt að finna og styrkja íslensk hlaðvörp — og hlaðvörpum auðvelt að fá styrktaraðila.
                  </p>
                  <div className="hero-btns flex gap-3 flex-wrap mb-4">
                    <button onClick={() => go("dir")} className="btn-primary px-8 py-3.5 rounded-lg font-bold text-xs flex items-center gap-2 transition-all" style={{backgroundColor:"#7EE8D5",color:"#0B1120",border:"none"}} onMouseEnter={e=>e.currentTarget.style.transform="translateY(-2px)"} onMouseLeave={e=>e.currentTarget.style.transform="translateY(0)"}>Skoða hlaðvörp <ArrowRight size={16}/></button>
                    <button onClick={() => document.getElementById("section-podcast-signup")?.scrollIntoView({behavior:"smooth"})} className="btn-secondary px-8 py-3.5 rounded-lg font-bold text-xs border flex items-center gap-2 transition-all" style={{borderColor:"#64748B",backgroundColor:"transparent",color:"#ffffff"}} onMouseEnter={e=>{e.currentTarget.style.borderColor="rgba(126,232,213,0.5)";e.currentTarget.style.transform="translateY(-2px)"}} onMouseLeave={e=>{e.currentTarget.style.borderColor="#64748B";e.currentTarget.style.transform="translateY(0)"}}><Mic size={14}/> Skrá hlaðvarp</button>
                  </div>
                </div>
                <div className="w-full md:flex-1 flex justify-center">
                  <img src="./illustration-podcast.png" alt="Podcast illustration" style={{maxWidth:420,width:"100%"}}/>
                </div>
              </div>
            </div>
          </section>

          {/* Podcasts on Podform */}
          {podcasts.length > 0 && (
          <section className="max-w-5xl mx-auto px-5 py-8 md:py-14">
            <div className="flex justify-between items-center mb-6">
              <h2 className="text-xl font-extrabold tracking-tight" style={{color:"#ffffff"}}>Hlaðvörp á Podform</h2>
              <button onClick={() => go("dir")} className="text-sm font-semibold flex items-center gap-1" style={{color:"#7EE8D5",background:"none",border:"none"}}>Sjá öll <ArrowRight size={14}/></button>
            </div>
            <div className="grid gap-3" style={{gridTemplateColumns:"repeat(auto-fill,minmax(300px,1fr))"}}>
              {[...podcasts].sort((a,b) => b.rating - a.rating).slice(0,6).map(p => (
                <div key={p.id} className="hover-lift flex items-center gap-3.5 p-4 rounded-xl border cursor-pointer" style={{backgroundColor:"#111B2E",borderColor:"#1A2744"}} onClick={() => {setSelPod(p);go("profile")}}>
                  <PodImg pod={p} size={48}/>
                  <div className="flex-1 min-w-0">
                    <div className="font-bold text-sm truncate" style={{color:"#ffffff"}}>{p.name}</div>
                    <div className="text-xs mt-0.5 flex items-center gap-1" style={{color:"#64748B"}}><RatingStars rating={p.rating} size={10}/> {p.rating} ({p.reviews}) · {p.cat}</div>
                  </div>
                  <ChevronRight size={16} style={{color:"#64748B"}}/>
                </div>
              ))}
            </div>
          </section>
          )}

          {/* How it works */}
          <section id="section-how" className="max-w-5xl mx-auto px-5 py-8 md:py-14">
            <h2 className="text-2xl font-extrabold text-center mb-3 tracking-tight" style={{color:"#ffffff"}}>Hvernig virkar Podform?</h2>
            <p className="text-sm text-center mb-6" style={{color:"#64748B"}}>Þrjú einföld skref</p>
            <div className="grid grid-cols-1 md:grid-cols-3 gap-6" style={{maxWidth:900,margin:"0 auto"}}>
              {[
                {n:"1",t:"Skoðaðu hlaðvörp",d:"Skoðaðu hlaðvörp eftir flokkum, einkunnum og markhópi. Allt á einum stað.",icon:<Search size={20}/>},
                {n:"2",t:"Veldu það sem hentar",d:"Skoðaðu lýsingu, flokk og einkunnir hvers hlaðvarps til að finna rétta samsvörun.",icon:<Users size={20}/>},
                {n:"3",t:"Sendu fyrirspurn",d:"Fylltu út stutt eyðublað og við tengum þig við hlaðvarpið. Einfalt og fljótt.",icon:<Send size={20}/>},
              ].map((s,i) => (
                <div key={s.n} className="rounded-2xl p-6 transition-all" style={{backgroundColor:"#111B2E",border:"1px solid #1A2744"}}>
                  <div className="flex items-center gap-3 mb-4">
                    <div className="w-10 h-10 rounded-xl flex items-center justify-center" style={{background:"linear-gradient(135deg,rgba(126,232,213,0.15),rgba(126,232,213,0.08))",color:"#7EE8D5"}}>{s.icon}</div>
                    <div className="text-xs font-bold uppercase tracking-widest" style={{color:"#7EE8D5",opacity:0.5}}>Skref {s.n}</div>
                  </div>
                  <div className="font-bold text-base mb-2" style={{color:"#ffffff"}}>{s.t}</div>
                  <div className="text-sm leading-relaxed" style={{color:"#94A3B8"}}>{s.d}</div>
                </div>
              ))}
            </div>
          </section>

          {/* Fyrir hlaðvörp — podcast acquisition */}
          <section id="section-podcast-signup" className="max-w-5xl mx-auto px-5 py-8 md:py-14">
            <div className="rounded-2xl overflow-hidden" style={{backgroundColor:"#111B2E",border:"1px solid #1A2744"}}>
              <div className="grid md:grid-cols-2">
                <div className="p-6 md:p-8">
                  <div className="inline-flex items-center gap-2 px-3 py-1 rounded-full mb-4" style={{backgroundColor:"rgba(126,232,213,0.08)",border:"1px solid rgba(126,232,213,0.15)"}}>
                    <Mic size={12} style={{color:"#7EE8D5"}}/>
                    <span className="text-[10px] font-bold uppercase tracking-wider" style={{color:"#7EE8D5"}}>Fyrir hlaðvörp</span>
                  </div>
                  <h2 className="text-2xl font-extrabold mb-3 tracking-tight" style={{color:"#ffffff"}}>Fáðu styrktaraðila fyrir hlaðvarpið þitt</h2>
                  <p className="text-sm leading-relaxed mb-5" style={{color:"#94A3B8"}}>Skráðu hlaðvarpið þitt á Podform og opnaðu dyrnar að fyrirtækjum sem vilja styrkja hlaðvörp eins og þitt. Ekkert kostar og enginn binding.</p>
                  <div className="space-y-3">
                    {[
                      {t:"Ókeypis skráning",d:"Enginn kostnaður við að vera á vettvangnum."},
                      {t:"Fyrirtæki finna þig",d:"Þú birtist í leitarniðurstöðum fyrirtækja sem leita að markhópnum þínum."},
                      {t:"Þú ræður skilmálum",d:"Verð og samstarf er alltaf í þínum höndum."},
                    ].map((item,i) => (
                      <div key={i} className="flex items-start gap-2.5">
                        <Check size={14} style={{color:"#7EE8D5",marginTop:2,flexShrink:0}}/>
                        <div>
                          <div className="text-sm font-semibold" style={{color:"#ffffff"}}>{item.t}</div>
                          <div className="text-xs" style={{color:"#64748B"}}>{item.d}</div>
                        </div>
                      </div>
                    ))}
                  </div>
                </div>
                <div className="p-6 md:p-8 md:border-l" style={{borderColor:"#1A2744"}}>
                  <div className="text-sm font-bold mb-4" style={{color:"#ffffff"}}>Skráðu áhuga</div>
                  <form onSubmit={e => {
                    e.preventDefault();
                    if (!podcastForm.podcastName || !podcastForm.email) { showToast("Vinsamlegast fylltu út nauðsynlega reiti."); return; }
                    fetch("https://formspree.io/f/meeppnlw", {
                      method:"POST", headers:{"Content-Type":"application/json","Accept":"application/json"},
                      body: JSON.stringify({type:"HLAÐVARP SKRÁNING", podcastName:podcastForm.podcastName, contactName:podcastForm.contactName||"—", email:podcastForm.email, phone:podcastForm.phone||"—", message:podcastForm.message||"—"}),
                    }).then(r => { if(r.ok){showToast("Takk! Við höfum samband fljótlega.");setPodcastForm({podcastName:"",contactName:"",email:"",phone:"",message:""})}else{showToast("Villa kom upp.")} }).catch(()=>showToast("Villa kom upp."));
                  }} className="space-y-3">
                    <input type="text" value={podcastForm.podcastName} onChange={e => setPodcastForm(f=>({...f,podcastName:e.target.value}))} placeholder="Nafn hlaðvarps *" className="w-full border rounded-lg px-3.5 py-2.5 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}} required/>
                    <input type="text" value={podcastForm.contactName} onChange={e => setPodcastForm(f=>({...f,contactName:e.target.value}))} placeholder="Tengiliður" className="w-full border rounded-lg px-3.5 py-2.5 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                    <input type="email" value={podcastForm.email} onChange={e => setPodcastForm(f=>({...f,email:e.target.value}))} placeholder="Netfang *" className="w-full border rounded-lg px-3.5 py-2.5 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}} required/>
                    <textarea value={podcastForm.message} onChange={e => setPodcastForm(f=>({...f,message:e.target.value}))} placeholder="Skilaboð (valfrjálst)" rows={2} className="w-full border rounded-lg px-3.5 py-2.5 text-sm resize-none" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                    <button type="submit" className="btn-primary w-full py-2.5 rounded-lg font-bold text-xs flex items-center justify-center gap-2" style={{backgroundColor:"#7EE8D5",color:"#0B1120",border:"none"}}><Send size={13}/> Skrá hlaðvarp</button>
                    <div className="text-[10px] text-center" style={{color:"#475569"}}>Við svörum yfirleitt innan sólarhrings</div>
                  </form>
                </div>
              </div>
            </div>
          </section>

          {/* Um Podform — trust section (merged from About page) */}
          <section id="section-about" className="max-w-5xl mx-auto px-5 py-8 md:py-14">
            <div className="grid md:grid-cols-2 gap-6 items-start">
              <div>
                <div className="inline-flex items-center gap-2 px-3 py-1 rounded-full mb-4" style={{backgroundColor:"rgba(126,232,213,0.08)",border:"1px solid rgba(126,232,213,0.15)"}}>
                  <PodformLogo size={12}/>
                  <span className="text-[10px] font-bold uppercase tracking-wider" style={{color:"#7EE8D5"}}>Um Podform</span>
                </div>
                <h2 className="text-2xl font-extrabold mb-3 tracking-tight" style={{color:"#ffffff"}}>Byggt af Vöruvakt</h2>
                <p className="text-sm leading-relaxed mb-3" style={{color:"#94A3B8"}}>
                  Podform var stofnað árið 2026 af teyminu á bak við <a href="https://www.voruvakt.is" target="_blank" rel="noopener noreferrer" style={{color:"#7EE8D5",textDecoration:"none",fontWeight:600}}>Vöruvakt</a> — íslenskt þjónustufyrirtæki sem sérhæfir sig í vörukynningu og markaðslausnum.
                </p>
                <p className="text-sm leading-relaxed" style={{color:"#94A3B8"}}>
                  Hugbúnaðurinn er í stöðugri þróun og við tökum virkan þátt í endurgjöf frá notendum. Markmiðið er einfalt: gera hlaðvarpsstyrkjun á Íslandi aðgengilega og skilvirka.
                </p>
              </div>
              <div className="space-y-3">
                {[
                  {icon:<Shield size={16}/>,t:"Byggt á trausti",d:"Vöruvakt hefur unnið með tugum fyrirtækja á Íslandi. Sú reynsla liggur að baki Podform."},
                  {icon:<Send size={16}/>,t:"Í stöðugri þróun",d:"Við hlustaum á endurgjöf og bætum vettvanginn reglulega. Þetta er aðeins byrjunin."},
                  {icon:<Users size={16}/>,t:"Opið öllum",d:"Stór eða smá — öll hlaðvörp og fyrirtæki eru velkomin á Podform."},
                ].map((item,i) => (
                  <div key={i} className="rounded-xl p-4 flex items-start gap-3" style={{backgroundColor:"#111B2E",border:"1px solid #1A2744"}}>
                    <div className="w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0" style={{background:"linear-gradient(135deg,rgba(126,232,213,0.15),rgba(126,232,213,0.08))"}}><span style={{color:"#7EE8D5"}}>{item.icon}</span></div>
                    <div>
                      <div className="text-sm font-bold mb-0.5" style={{color:"#ffffff"}}>{item.t}</div>
                      <div className="text-xs leading-relaxed" style={{color:"#94A3B8"}}>{item.d}</div>
                    </div>
                  </div>
                ))}
              </div>
            </div>
          </section>

          {/* FAQ — real objections */}
          <section className="max-w-5xl mx-auto px-5 py-8 md:py-14">
            <h2 className="text-2xl font-extrabold text-center mb-3 tracking-tight" style={{color:"#ffffff"}}>Algengar spurningar</h2>
            <p className="text-sm text-center mb-6" style={{color:"#64748B"}}>Svar við því sem flestir spyrja um</p>
            <div className="flex flex-col gap-3" style={{maxWidth:700,margin:"0 auto"}}>
              {[
                {q:"Hvað kostar að auglýsa í hlaðvarpi?",a:"Verð er mismunandi eftir hlaðvörpum og fer eftir stærð, markhópi og tegund samstarfs. Þú getur skoðað hlaðvörp á vettvangnum og sent fyrirspurn til að fá nánari upplýsingar — ókeypis og án skuldbindinga."},
                {q:"Hversu hratt fer ferlið?",a:"Þú getur skoðað hlaðvörp og sent fyrirspurn á nokkrum mínútum. Við svörum yfirleitt innan sólarhrings og tengjum þig við hlaðvarpið sem hentar."},
                {q:"Er Podform aðeins fyrir stór fyrirtæki?",a:"Nei. Podform hentar jafnt litlum fyrirtækjum og stórum. Mörg hlaðvörp ná til afmarkaðs markhóps sem getur verið mjög verðmætur fyrir minni vörumerki."},
                {q:"Hvernig skrái ég hlaðvarpið mitt?",a:"Fylltu út eyðublaðið á síðunni og við höfum samband. Skráning er ókeypis og þú ræður alltaf sjálf/ur hvaða samstarfi þú tekur."},
                {q:"Hvað gerist eftir að ég sendi fyrirspurn?",a:"Við skoðum fyrirspurnina þína og tengjum þig við viðeigandi hlaðvarp. Allt samstarf er í samráði við báða aðila — ekkert gerist án þíns samþykkis."},
              ].map((faq,i) => (
                <div key={i} className="rounded-xl overflow-hidden" style={{backgroundColor:"#111B2E",border:"1px solid #1A2744"}}>
                  <button onClick={() => setOpenFaq(openFaq === i ? null : i)} className="w-full flex items-center justify-between p-5 text-left" style={{background:"none",border:"none"}}>
                    <span className="text-sm font-semibold pr-4" style={{color:"#ffffff"}}>{faq.q}</span>
                    {openFaq === i ? <ChevronUp size={16} style={{color:"#7EE8D5",flexShrink:0}}/> : <ChevronDown size={16} style={{color:"#64748B",flexShrink:0}}/>}
                  </button>
                  {openFaq === i && (
                    <div className="px-5 pb-5 fade-in">
                      <p className="text-sm leading-relaxed" style={{color:"#94A3B8"}}>{faq.a}</p>
                    </div>
                  )}
                </div>
              ))}
            </div>
          </section>

          {/* Bottom CTA — specific and benefit-driven */}
          <section className="max-w-5xl mx-auto px-5 py-8 md:py-14">
            <div className="rounded-2xl p-8 md:p-10" style={{backgroundColor:"#111B2E",border:"1px solid #1A2744"}}>
              <div className="grid md:grid-cols-2 gap-6">
                <div className="text-center md:text-left">
                  <h2 className="text-xl font-extrabold mb-2 tracking-tight" style={{color:"#ffffff"}}>Ertu fyrirtæki?</h2>
                  <p className="text-sm mb-4" style={{color:"#94A3B8"}}>Finndu hlaðvarpið sem talar við þinn markhóp. Skoðaðu og sendu fyrirspurn — ekkert kostar.</p>
                  <button onClick={() => go("dir")} className="btn-primary px-6 py-2.5 rounded-lg font-bold text-xs" style={{backgroundColor:"#7EE8D5",color:"#0B1120",border:"none"}}>Skoða hlaðvörp</button>
                </div>
                <div className="text-center md:text-left md:border-l md:pl-6" style={{borderColor:"#1A2744"}}>
                  <h2 className="text-xl font-extrabold mb-2 tracking-tight" style={{color:"#ffffff"}}>Ertu með hlaðvarp?</h2>
                  <p className="text-sm mb-4" style={{color:"#94A3B8"}}>Skráðu þig og fáðu aðgang að fyrirtækjum sem vilja styrkja hlaðvörp eins og þitt.</p>
                  <button onClick={() => document.getElementById("section-podcast-signup")?.scrollIntoView({behavior:"smooth"})} className="btn-secondary px-6 py-2.5 rounded-lg font-bold text-xs" style={{border:"1px solid #64748B",backgroundColor:"transparent",color:"#ffffff"}}>Skrá hlaðvarp</button>
                </div>
              </div>
            </div>
          </section>

          {/* Footer */}
          <footer className="max-w-5xl mx-auto px-5 pb-8">
            <div className="flex items-center justify-between pt-6 border-t" style={{borderColor:"#1A2744"}}>
              <div className="flex items-center gap-2">
                <PodformLogo size={18}/>
                <span className="text-xs" style={{color:"#475569"}}>Podform</span>
                <span className="text-xs" style={{color:"#334155"}}>·</span>
                <span className="text-xs" style={{color:"#475569"}}>Byggt af <a href="https://www.voruvakt.is" target="_blank" rel="noopener noreferrer" style={{color:"#64748B",textDecoration:"none"}}>Vöruvakt</a></span>
              </div>
              <div className="flex items-center gap-3">
                <div className="flex items-center gap-1.5">
                  <Mail size={12} style={{color:"#64748B"}}/>
                  <span className="text-xs" style={{color:"#64748B"}}>voruvakt@voruvakt.is</span>
                </div>
                <button onClick={() => go("admin")} className="text-xs opacity-30" style={{color:"#64748B",background:"none",border:"none"}}>Stjórnborð</button>
              </div>
            </div>
          </footer>
        </div>
      )}

      {/* ═══ DIRECTORY ═══ */}
      {view === "dir" && (
        <div className="fade-in max-w-6xl mx-auto px-5 py-7">
          <button onClick={() => go("landing")} className="flex items-center gap-1 text-sm mb-4 transition-colors" style={{color:"#64748B",background:"none",border:"none"}} onMouseEnter={e=>e.currentTarget.style.color="#7EE8D5"} onMouseLeave={e=>e.currentTarget.style.color="#64748B"}><ArrowLeft size={13}/> Til baka</button>
          <h1 className="text-2xl font-extrabold tracking-tight mb-1" style={{color:"#ffffff"}}>Hlaðvörp</h1>
          <p className="text-sm mb-5" style={{color:"#94A3B8"}}>Finndu hlaðvarp sem hentar markhópnum þínum.</p>
          <div className="flex items-center gap-2 border rounded-xl px-3.5 py-2.5 mb-3.5" style={{backgroundColor:"#111B2E",borderColor:"#1A2744"}}>
            <Search size={17} style={{color:"#64748B"}}/>
            <input value={q} onChange={e => setQ(e.target.value)} placeholder="Leita eftir nafni eða lýsingu..." className="flex-1 border-0 bg-transparent text-sm outline-none" style={{color:"#e5e7eb"}}/>
            {q && <button onClick={() => setQ("")} className="text-xs px-2 py-0.5 rounded" style={{backgroundColor:"#111B2E",color:"#64748B",border:"none"}}>Hreinsa</button>}
          </div>
          <div className="flex gap-1.5 flex-wrap mb-5 overflow-x-auto pb-1" style={{WebkitOverflowScrolling:"touch"}}>
            {CATS.map(c => (
              <button key={c} onClick={() => setCat(c)} className="px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors whitespace-nowrap flex-shrink-0" style={{borderColor:cat===c?"#7EE8D5":"#1A2744",backgroundColor:cat===c?"rgba(126,232,213,0.08)":"#0B1120",color:cat===c?"#7EE8D5":"#64748B"}}>{c}</button>
            ))}
          </div>
          <div className="text-xs font-medium mb-3.5" style={{color:"#64748B"}}>{filtered.length} hlaðvörp</div>
          <div className="grid gap-3.5" style={{gridTemplateColumns:"repeat(auto-fill,minmax(310px,1fr))"}}>
            {filtered.map(p => (
              <div key={p.id} className="hover-lift rounded-2xl border overflow-hidden cursor-pointer" style={{backgroundColor:"#111B2E",borderColor:"#1A2744"}} onClick={() => {setSelPod(p);go("profile")}}>
                <div className="h-1" style={{background:`linear-gradient(90deg,${p.color},${p.color}66)`}}/>
                <div className="p-5">
                  <div className="flex items-center gap-3 mb-3">
                    <PodImg pod={p} size={44}/>
                    <div className="min-w-0 flex-1">
                      <div className="font-bold text-base truncate" style={{color:"#ffffff"}}>{p.name}</div>
                      <div className="text-xs font-semibold" style={{color:p.color}}>{p.cat}</div>
                    </div>
                  </div>
                  <p className="text-sm leading-relaxed mb-3" style={{color:"#64748B",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"}}>{p.desc}</p>
                  <div className="flex items-center gap-3 text-xs">
                    <span className="flex items-center gap-1 font-semibold" style={{color:"#ffffff"}}><Play size={10}/> {p.eps} þættir</span>
                    <span className="flex items-center gap-1" style={{color:"#ffffff"}}>{p.freq}</span>
                    <span className="ml-auto flex items-center gap-1"><RatingStars rating={p.rating} size={12}/> <span className="font-semibold" style={{color:"#ffffff"}}>{p.rating}</span> <span style={{color:"#64748B"}}>({p.reviews})</span></span>
                  </div>
                </div>
              </div>
            ))}
          </div>
          {filtered.length === 0 && (
            <div className="text-center py-16">
              <Search size={32} style={{color:"#334155",margin:"0 auto 12px"}}/>
              <div className="text-sm" style={{color:"#64748B"}}>Engin hlaðvörp fundust. Prófaðu aðra leit.</div>
            </div>
          )}
        </div>
      )}

      {/* ═══ PODCAST PROFILE ═══ */}
      {view === "profile" && selPod && (
        <div className="fade-in max-w-4xl mx-auto px-5 py-5 pb-16">
          <div className="flex items-center gap-1.5 text-sm mb-5">
            <button onClick={() => go("dir")} className="flex items-center gap-1 transition-colors" style={{color:"#64748B",background:"none",border:"none"}} onMouseEnter={e=>e.currentTarget.style.color="#7EE8D5"} onMouseLeave={e=>e.currentTarget.style.color="#64748B"}><ArrowLeft size={13}/> Hlaðvörp</button>
            <span style={{color:"#334155"}}>/</span>
            <span className="font-medium" style={{color:"#94A3B8"}}>{selPod.name}</span>
          </div>

          {/* Header */}
          <div className="flex gap-4 items-center mb-5">
            <PodImg pod={selPod} size={56} radius="rounded-2xl"/>
            <div className="flex-1">
              <h1 className="text-2xl font-extrabold tracking-tight mb-1" style={{color:"#ffffff"}}>{selPod.name}</h1>
              <div className="flex items-center gap-2.5 text-sm flex-wrap" style={{color:"#64748B"}}>
                <span className="font-semibold" style={{color:selPod.color}}>{selPod.cat}</span>
                <span>·</span>
                <span>{selPod.eps} þættir</span>
                <span>·</span>
                <span>{selPod.freq}</span>
                <span>·</span>
                <span className="flex items-center gap-1"><RatingStars rating={selPod.rating} size={13}/> {selPod.rating} ({selPod.reviews})</span>
              </div>
            </div>
          </div>
          <p className="text-sm leading-relaxed mb-6" style={{color:"#94A3B8"}}>{selPod.desc}</p>

          <div className="flex flex-col md:flex-row gap-6">
            {/* Left: Demographics */}
            <div className="flex-1 min-w-0">
              <div className="border rounded-2xl p-6" style={{backgroundColor:"#111B2E",borderColor:"#1A2744"}}>
                <div className="flex items-center gap-2 mb-5">
                  <Users size={15} style={{color:selPod.color}}/>
                  <span className="font-bold" style={{color:"#ffffff"}}>Lýðfræði hlustenda</span>
                </div>
                {(selPod.age.a1 || selPod.age.a2 || selPod.age.a3 || selPod.gender.m || selPod.gender.f) ? (
                <div className="grid grid-cols-1 sm:grid-cols-2 gap-6">
                  <div>
                    <div className="text-xs font-semibold uppercase tracking-wide mb-3" style={{color:"#64748B"}}>Aldur</div>
                    {[["18–24",selPod.age.a1],["25–34",selPod.age.a2],["35–44",selPod.age.a3],["45–54",selPod.age.a4],["55+",selPod.age.a5]].map(([l,v]) => (
                      <div key={l} className="flex items-center gap-2 mb-2">
                        <span className="w-10 text-xs" style={{color:"#64748B"}}>{l}</span>
                        <ProgressBar pct={v} color={selPod.color}/>
                        <span className="w-8 text-xs font-semibold text-right" style={{color:"#ffffff"}}>{v}%</span>
                      </div>
                    ))}
                  </div>
                  <div>
                    <div className="text-xs font-semibold uppercase tracking-wide mb-3" style={{color:"#64748B"}}>Kyn</div>
                    {[["Karlar",selPod.gender.m],["Konur",selPod.gender.f]].map(([l,v]) => (
                      <div key={l} className="flex items-center gap-2 mb-2">
                        <span className="w-12 text-xs" style={{color:"#64748B"}}>{l}</span>
                        <ProgressBar pct={v} color={selPod.color}/>
                        <span className="w-8 text-xs font-semibold text-right" style={{color:"#ffffff"}}>{v}%</span>
                      </div>
                    ))}
                    <div className="text-xs font-semibold uppercase tracking-wide mt-4 mb-3" style={{color:"#64748B"}}>Staðsetning</div>
                    {[["Höfuðborgarsvæði",selPod.loc.rvk],["Annars staðar",selPod.loc.other]].map(([l,v]) => (
                      <div key={l} className="flex items-center gap-2 mb-2">
                        <span className="w-24 text-xs" style={{color:"#64748B"}}>{l}</span>
                        <ProgressBar pct={v} color={selPod.color}/>
                        <span className="w-8 text-xs font-semibold text-right" style={{color:"#ffffff"}}>{v}%</span>
                      </div>
                    ))}
                  </div>
                </div>
                ) : (
                  <div className="text-center py-6">
                    <Users size={24} style={{color:"#334155",margin:"0 auto 8px"}}/>
                    <div className="text-sm" style={{color:"#64748B"}}>Lýðfræði hlustenda vantar</div>
                    <div className="text-xs mt-1" style={{color:"#475569"}}>Upplýsingar verða birtar þegar þær liggja fyrir.</div>
                  </div>
                )}
              </div>

              {/* Similar podcasts */}
              {(() => {
                const similar = podcasts.filter(p => p.id !== selPod.id && p.cat === selPod.cat).slice(0, 3);
                const fallback = similar.length < 3 ? podcasts.filter(p => p.id !== selPod.id && p.cat !== selPod.cat).slice(0, 3 - similar.length) : [];
                const results = [...similar, ...fallback];
                if (results.length === 0) return null;
                return (
                  <div className="mt-6">
                    <h3 className="font-bold mb-3 text-sm" style={{color:"#ffffff"}}>Svipuð hlaðvörp</h3>
                    <div className="flex flex-col gap-2">
                      {results.map(p => (
                        <div key={p.id} className="hover-lift flex items-center gap-3 p-3 rounded-xl border cursor-pointer" style={{backgroundColor:"#111B2E",borderColor:"#1A2744"}} onClick={() => {setSelPod(p);window.scrollTo(0,0)}}>
                          <PodImg pod={p} size={36} radius="rounded-lg"/>
                          <div className="min-w-0 flex-1">
                            <div className="font-bold text-sm truncate" style={{color:"#ffffff"}}>{p.name}</div>
                            <div className="text-xs flex items-center gap-1" style={{color:"#64748B"}}>{p.cat} · <RatingStars rating={p.rating} size={9}/> {p.rating} ({p.reviews})</div>
                          </div>
                          <ChevronRight size={14} style={{color:"#64748B"}}/>
                        </div>
                      ))}
                    </div>
                  </div>
                );
              })()}
            </div>

            {/* Right: CTA card */}
            <div className="w-full md:w-[340px] md:flex-shrink-0 md:sticky md:top-16">
              <div className="border rounded-2xl overflow-hidden" style={{backgroundColor:"#111B2E",borderColor:"#1A2744"}}>
                <div className="px-5 py-5">
                  <div className="text-base font-bold mb-1" style={{color:"#ffffff"}}>Áhugi á samstarfi?</div>
                  <p className="text-xs leading-relaxed mb-5" style={{color:"#64748B"}}>Sendu okkur fyrirspurn og við tengjum þig við {selPod.name}. Við svörum yfirleitt innan sólarhrings.</p>
                  <button onClick={() => { setRequestForm(f=>({...f,podcast:selPod.name})); go("request"); }} className="btn-primary w-full py-3 rounded-lg font-bold text-xs flex items-center justify-center gap-2 transition-all" style={{backgroundColor:"#7EE8D5",color:"#0B1120",border:"none"}} onMouseEnter={e=>e.currentTarget.style.transform="translateY(-1px)"} onMouseLeave={e=>e.currentTarget.style.transform="translateY(0)"}><Send size={14}/> Senda fyrirspurn</button>
                  <div className="flex items-center justify-center gap-2 text-xs mt-3" style={{color:"#64748B"}}><Shield size={10} style={{color:"#34d399"}}/> Ókeypis og skuldbindingalaust</div>
                </div>
                <div className="px-5 py-4 border-t" style={{borderColor:"#1A2744"}}>
                  <div className="text-xs font-semibold mb-3" style={{color:"#64748B"}}>Hlaðvarpsupplýsingar</div>
                  <div className="space-y-2">
                    <div className="flex justify-between text-xs"><span style={{color:"#64748B"}}>Þættir</span><span className="font-semibold" style={{color:"#ffffff"}}>{selPod.eps}</span></div>
                    <div className="flex justify-between text-xs"><span style={{color:"#64748B"}}>Tíðni</span><span className="font-semibold" style={{color:"#ffffff"}}>{selPod.freq}</span></div>
                    <div className="flex justify-between text-xs"><span style={{color:"#64748B"}}>Einkunn</span><span className="font-semibold" style={{color:"#ffffff"}}>{selPod.rating} / 5</span></div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      )}

      {/* ═══ REQUEST FORM ═══ */}
      {view === "request" && (
        <div className="fade-in max-w-lg mx-auto px-5 py-10">
          <button onClick={() => selPod ? go("profile") : go("landing")} className="flex items-center gap-1 text-sm mb-6 transition-colors" style={{color:"#64748B",background:"none",border:"none"}} onMouseEnter={e=>e.currentTarget.style.color="#7EE8D5"} onMouseLeave={e=>e.currentTarget.style.color="#64748B"}><ArrowLeft size={13}/> Til baka</button>
          <h1 className="text-2xl font-extrabold tracking-tight mb-2" style={{color:"#ffffff"}}>Senda fyrirspurn</h1>
          <p className="text-sm mb-8" style={{color:"#94A3B8"}}>Fylltu út eyðublaðið og við höfum samband eins fljótt og auðið er.</p>

          <form onSubmit={handleRequestSubmit} className="space-y-4">
            {requestForm.podcast && (
              <div className="rounded-xl p-4 flex items-center gap-3" style={{backgroundColor:"rgba(126,232,213,0.04)",border:"1px solid rgba(126,232,213,0.15)"}}>
                <Mic size={16} style={{color:"#7EE8D5"}}/>
                <div>
                  <div className="text-xs" style={{color:"#64748B"}}>Fyrirspurn um</div>
                  <div className="text-sm font-semibold" style={{color:"#7EE8D5"}}>{requestForm.podcast}</div>
                </div>
                <button type="button" onClick={() => setRequestForm(f=>({...f,podcast:""}))} className="ml-auto" style={{color:"#64748B",background:"none",border:"none"}}><X size={14}/></button>
              </div>
            )}
            {!requestForm.podcast && (
              <div>
                <label className="block text-xs font-semibold mb-1.5" style={{color:"#94A3B8"}}>Hlaðvarp (valfrjálst)</label>
                <select value={requestForm.podcast} onChange={e => setRequestForm(f=>({...f,podcast:e.target.value}))} className="w-full border rounded-xl px-4 py-3 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#111B2E",color:"#ffffff"}}>
                  <option value="">Veldu hlaðvarp eða slepptu</option>
                  {podcasts.map(p => <option key={p.id} value={p.name}>{p.name} — {p.cat}</option>)}
                </select>
              </div>
            )}
            <div>
              <label className="block text-xs font-semibold mb-1.5" style={{color:"#94A3B8"}}>Fyrirtæki *</label>
              <input type="text" value={requestForm.companyName} onChange={e => setRequestForm(f=>({...f,companyName:e.target.value}))} placeholder="Nafn fyrirtækis" className="w-full border rounded-xl px-4 py-3 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#111B2E",color:"#ffffff"}} required/>
            </div>
            <div>
              <label className="block text-xs font-semibold mb-1.5" style={{color:"#94A3B8"}}>Tengiliður *</label>
              <input type="text" value={requestForm.contactName} onChange={e => setRequestForm(f=>({...f,contactName:e.target.value}))} placeholder="Nafn tengiliðar" className="w-full border rounded-xl px-4 py-3 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#111B2E",color:"#ffffff"}} required/>
            </div>
            <div>
              <label className="block text-xs font-semibold mb-1.5" style={{color:"#94A3B8"}}>Netfang *</label>
              <input type="email" value={requestForm.email} onChange={e => setRequestForm(f=>({...f,email:e.target.value}))} placeholder="netfang@fyrirtaeki.is" className="w-full border rounded-xl px-4 py-3 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#111B2E",color:"#ffffff"}} required/>
            </div>
            <div>
              <label className="block text-xs font-semibold mb-1.5" style={{color:"#94A3B8"}}>Sími (valfrjálst)</label>
              <input type="tel" value={requestForm.phone} onChange={e => setRequestForm(f=>({...f,phone:e.target.value}))} placeholder="000 0000" className="w-full border rounded-xl px-4 py-3 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#111B2E",color:"#ffffff"}}/>
            </div>
            <div>
              <label className="block text-xs font-semibold mb-1.5" style={{color:"#94A3B8"}}>Skilaboð (valfrjálst)</label>
              <textarea value={requestForm.message} onChange={e => setRequestForm(f=>({...f,message:e.target.value}))} placeholder="Lýstu hugmyndinni þinni eða spyrðu spurninga..." rows={4} className="w-full border rounded-xl px-4 py-3 text-sm resize-none" style={{borderColor:"#1A2744",backgroundColor:"#111B2E",color:"#ffffff"}}/>
            </div>
            <button type="submit" className="btn-primary w-full py-3.5 rounded-lg font-bold text-xs flex items-center justify-center gap-2 transition-all" style={{backgroundColor:"#7EE8D5",color:"#0B1120",border:"none"}} onMouseEnter={e=>e.currentTarget.style.transform="translateY(-1px)"} onMouseLeave={e=>e.currentTarget.style.transform="translateY(0)"}><Send size={14}/> Senda fyrirspurn</button>
            <div className="flex items-center justify-center gap-2 text-xs" style={{color:"#64748B"}}><Shield size={10} style={{color:"#34d399"}}/> Við deilum aldrei upplýsingunum þínum.</div>
          </form>
        </div>
      )}
      {/* ═══ ADMIN ═══ */}
      {view === "admin" && !adminAuth && (
        <div className="fade-in max-w-sm mx-auto px-5 py-8 md:py-14">
          <button onClick={() => go("landing")} className="flex items-center gap-1 text-sm mb-4 transition-colors" style={{color:"#64748B",background:"none",border:"none"}} onMouseEnter={e=>e.currentTarget.style.color="#7EE8D5"} onMouseLeave={e=>e.currentTarget.style.color="#64748B"}><ArrowLeft size={13}/> Til baka</button>
          <div className="rounded-2xl p-8" style={{backgroundColor:"#111B2E",border:"1px solid #1A2744"}}>
            <div className="flex items-center gap-2 mb-6">
              <PodformLogo size={22}/>
              <span className="font-bold" style={{color:"#ffffff"}}>Stjórnborð</span>
            </div>
            <form onSubmit={e => { e.preventDefault(); if(adminPass === ADMIN_PASSWORD){setAdminAuth(true);setAdminPass("")}else{showToast("Rangt lykilorð")} }}>
              <label className="block text-xs font-semibold mb-1.5" style={{color:"#94A3B8"}}>Lykilorð</label>
              <input type="password" value={adminPass} onChange={e => setAdminPass(e.target.value)} placeholder="Sláðu inn lykilorð" className="w-full border rounded-xl px-4 py-3 text-sm mb-4" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}} autoFocus/>
              <button type="submit" className="btn-primary w-full py-3 rounded-lg font-bold text-xs" style={{backgroundColor:"#7EE8D5",color:"#0B1120",border:"none"}}>Skrá inn</button>
            </form>
          </div>
        </div>
      )}

      {view === "admin" && adminAuth && (
        <div className="fade-in max-w-5xl mx-auto px-5 py-7 pb-16">
          <div className="flex items-center justify-between mb-6">
            <div className="flex items-center gap-3">
              <PodformLogo size={22}/>
              <h1 className="text-xl font-extrabold tracking-tight" style={{color:"#ffffff"}}>Stjórnborð</h1>
              <span className="text-xs px-2 py-0.5 rounded-full" style={{backgroundColor:"rgba(126,232,213,0.08)",color:"#7EE8D5"}}>{podcasts.length} hlaðvörp</span>
            </div>
            <div className="flex items-center gap-2">
              <button onClick={() => { setEditPod(emptyPodForm()); }} className="btn-primary px-5 py-2.5 rounded-lg text-xs font-bold flex items-center gap-1.5" style={{backgroundColor:"#7EE8D5",color:"#0B1120",border:"none"}}>+ Bæta við</button>
              <button onClick={() => { setAdminAuth(false); go("landing"); }} className="px-3 py-2 rounded-lg text-xs font-medium" style={{color:"#64748B",border:"1px solid #1A2744",background:"none"}}>Útskrá</button>
            </div>
          </div>

          {/* Delete confirmation */}
          {deletePod && (
            <div className="fixed inset-0 z-50 flex items-center justify-center" style={{backgroundColor:"rgba(0,0,0,0.6)",backdropFilter:"blur(4px)"}}>
              <div className="rounded-2xl p-6 w-full max-w-sm mx-4" style={{backgroundColor:"#111B2E",border:"1px solid #1A2744"}}>
                <div className="text-base font-bold mb-2" style={{color:"#ffffff"}}>Eyða hlaðvarpi?</div>
                <p className="text-sm mb-5" style={{color:"#94A3B8"}}>Ertu viss um að þú viljir eyða <strong style={{color:"#ffffff"}}>{deletePod.name}</strong>?</p>
                <div className="flex gap-2">
                  <button onClick={() => { setPodcasts(prev => prev.filter(p => p.id !== deletePod.id)); setDeletePod(null); showToast("Hlaðvarpi eytt"); }} className="flex-1 py-2.5 rounded-xl text-sm font-semibold" style={{backgroundColor:"#ef4444",color:"#fff",border:"none"}}>Eyða</button>
                  <button onClick={() => setDeletePod(null)} className="flex-1 py-2.5 rounded-xl text-sm font-medium" style={{color:"#94A3B8",border:"1px solid #1A2744",background:"none"}}>Hætta við</button>
                </div>
              </div>
            </div>
          )}

          {/* Edit/Add form */}
          {editPod && (
            <div className="fixed inset-0 z-50 flex items-center justify-center" style={{backgroundColor:"rgba(0,0,0,0.6)",backdropFilter:"blur(4px)"}}>
              <div className="rounded-2xl w-full max-w-2xl mx-4 max-h-[90vh] overflow-y-auto" style={{backgroundColor:"#111B2E",border:"1px solid #1A2744"}}>
                <div className="sticky top-0 px-6 py-4 border-b flex items-center justify-between" style={{borderColor:"#1A2744",backgroundColor:"#111B2E",borderRadius:"16px 16px 0 0"}}>
                  <span className="font-bold" style={{color:"#ffffff"}}>{editPod.id ? "Breyta hlaðvarpi" : "Nýtt hlaðvarp"}</span>
                  <button onClick={() => setEditPod(null)} style={{color:"#64748B",background:"none",border:"none"}}><X size={18}/></button>
                </div>
                <form onSubmit={e => {
                  e.preventDefault();
                  const pod = {
                    ...editPod,
                    id: editPod.id || String(Date.now()),
                    listeners: parseInt(editPod.listeners)||0,
                    eps: parseInt(editPod.eps)||0,
                    rating: parseFloat(editPod.rating)||4.0,
                    reviews: parseInt(editPod.reviews)||0,
                    age: {a1:parseInt(editPod.age.a1)||0,a2:parseInt(editPod.age.a2)||0,a3:parseInt(editPod.age.a3)||0,a4:parseInt(editPod.age.a4)||0,a5:parseInt(editPod.age.a5)||0},
                    gender: {m:parseInt(editPod.gender.m)||0,f:parseInt(editPod.gender.f)||0,o:parseInt(editPod.gender.o)||0},
                    loc: {rvk:parseInt(editPod.loc.rvk)||0,other:parseInt(editPod.loc.other)||0},
                  };
                  if (!pod.name) { showToast("Nafn vantar"); return; }
                  if (editPod.id) {
                    setPodcasts(prev => prev.map(p => p.id === pod.id ? pod : p));
                    showToast("Hlaðvarp uppfært");
                  } else {
                    setPodcasts(prev => [...prev, pod]);
                    showToast("Hlaðvarpi bætt við");
                  }
                  setEditPod(null);
                }} className="px-6 py-5 space-y-4">
                  <div className="grid grid-cols-2 gap-4">
                    <div>
                      <label className="block text-xs font-semibold mb-1" style={{color:"#94A3B8"}}>Nafn *</label>
                      <input type="text" value={editPod.name} onChange={e => setEditPod(p=>({...p,name:e.target.value}))} className="w-full border rounded-lg px-3 py-2 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}} required/>
                    </div>
                    <div>
                      <label className="block text-xs font-semibold mb-1" style={{color:"#94A3B8"}}>Flokkur</label>
                      <select value={editPod.cat} onChange={e => setEditPod(p=>({...p,cat:e.target.value}))} className="w-full border rounded-lg px-3 py-2 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}>
                        {CATS.filter(c=>c!=="Allt").map(c => <option key={c} value={c}>{c}</option>)}
                      </select>
                    </div>
                  </div>
                  <div>
                    <label className="block text-xs font-semibold mb-1" style={{color:"#94A3B8"}}>Lýsing</label>
                    <textarea value={editPod.desc} onChange={e => setEditPod(p=>({...p,desc:e.target.value}))} rows={2} className="w-full border rounded-lg px-3 py-2 text-sm resize-none" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                  </div>
                  <div>
                    <label className="block text-xs font-semibold mb-1" style={{color:"#94A3B8"}}>Mynd</label>
                    <div className="flex gap-2 items-start">
                      <div className="flex-1">
                        <input type="file" accept="image/*" onChange={e => { const file = e.target.files?.[0]; if(file){ const reader = new FileReader(); reader.onload = ev => setEditPod(p=>({...p, img: ev.target.result})); reader.readAsDataURL(file); } }} className="w-full border rounded-lg px-3 py-2 text-sm file:mr-3 file:py-1 file:px-3 file:rounded-lg file:border-0 file:text-xs file:font-semibold file:cursor-pointer" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#94A3B8"}}/>
                        <div className="text-[10px] mt-1" style={{color:"#475569"}}>Hlaðið upp forsíðumynd (JPG/PNG)</div>
                      </div>
                      {editPod.img && <img src={editPod.img} alt="Forskoðun" className="w-12 h-12 rounded-lg object-cover flex-shrink-0"/>}
                    </div>
                  </div>
                  <div className="grid grid-cols-3 gap-3">
                    <div>
                      <label className="block text-xs font-semibold mb-1" style={{color:"#94A3B8"}}>Þættir</label>
                      <input type="number" value={editPod.eps} onChange={e => setEditPod(p=>({...p,eps:e.target.value}))} className="w-full border rounded-lg px-3 py-2 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                    </div>
                    <div>
                      <label className="block text-xs font-semibold mb-1" style={{color:"#94A3B8"}}>Einkunn</label>
                      <input type="number" step="0.1" min="1" max="5" value={editPod.rating} onChange={e => setEditPod(p=>({...p,rating:e.target.value}))} className="w-full border rounded-lg px-3 py-2 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                    </div>
                    <div>
                      <label className="block text-xs font-semibold mb-1" style={{color:"#94A3B8"}}>Umsagnir</label>
                      <input type="number" value={editPod.reviews} onChange={e => setEditPod(p=>({...p,reviews:e.target.value}))} className="w-full border rounded-lg px-3 py-2 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                    </div>
                  </div>
                  <div className="grid grid-cols-2 gap-4">
                    <div>
                      <label className="block text-xs font-semibold mb-1" style={{color:"#94A3B8"}}>Tíðni</label>
                      <select value={editPod.freq} onChange={e => setEditPod(p=>({...p,freq:e.target.value}))} className="w-full border rounded-lg px-3 py-2 text-sm" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}>
                        {["Vikulega","Aðra hverja viku","Mánaðarlega","Á virkum dögum"].map(f => <option key={f} value={f}>{f}</option>)}
                      </select>
                    </div>
                    <div>
                      <label className="block text-xs font-semibold mb-1" style={{color:"#94A3B8"}}>Litur</label>
                      <div className="flex items-center gap-2">
                        <input type="color" value={editPod.color} onChange={e => setEditPod(p=>({...p,color:e.target.value}))} className="w-10 h-9 rounded border-0 cursor-pointer" style={{backgroundColor:"#0B1120"}}/>
                        <input type="text" value={editPod.color} onChange={e => setEditPod(p=>({...p,color:e.target.value}))} className="flex-1 border rounded-lg px-3 py-2 text-sm font-mono" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                      </div>
                    </div>
                  </div>
                  <div>
                    <div className="text-xs font-semibold mb-2" style={{color:"#94A3B8"}}>Aldursdreifing (%)</div>
                    <div className="grid grid-cols-5 gap-2">
                      {[["18–24","a1"],["25–34","a2"],["35–44","a3"],["45–54","a4"],["55+","a5"]].map(([l,k]) => (
                        <div key={k}>
                          <label className="block text-[10px] mb-0.5" style={{color:"#64748B"}}>{l}</label>
                          <input type="number" value={editPod.age[k]} onChange={e => setEditPod(p=>({...p,age:{...p.age,[k]:e.target.value}}))} className="w-full border rounded-lg px-2 py-1.5 text-xs" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                        </div>
                      ))}
                    </div>
                  </div>
                  <div className="grid grid-cols-2 gap-4">
                    <div>
                      <div className="text-xs font-semibold mb-2" style={{color:"#94A3B8"}}>Kyn (%)</div>
                      <div className="grid grid-cols-3 gap-2">
                        {[["Karlar","m"],["Konur","f"],["Annað","o"]].map(([l,k]) => (
                          <div key={k}>
                            <label className="block text-[10px] mb-0.5" style={{color:"#64748B"}}>{l}</label>
                            <input type="number" value={editPod.gender[k]} onChange={e => setEditPod(p=>({...p,gender:{...p.gender,[k]:e.target.value}}))} className="w-full border rounded-lg px-2 py-1.5 text-xs" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                          </div>
                        ))}
                      </div>
                    </div>
                    <div>
                      <div className="text-xs font-semibold mb-2" style={{color:"#94A3B8"}}>Staðsetning (%)</div>
                      <div className="grid grid-cols-2 gap-2">
                        {[["Höfuðb.","rvk"],["Annað","other"]].map(([l,k]) => (
                          <div key={k}>
                            <label className="block text-[10px] mb-0.5" style={{color:"#64748B"}}>{l}</label>
                            <input type="number" value={editPod.loc[k]} onChange={e => setEditPod(p=>({...p,loc:{...p.loc,[k]:e.target.value}}))} className="w-full border rounded-lg px-2 py-1.5 text-xs" style={{borderColor:"#1A2744",backgroundColor:"#0B1120",color:"#ffffff"}}/>
                          </div>
                        ))}
                      </div>
                    </div>
                  </div>
                  <div className="flex gap-2 pt-2">
                    <button type="submit" className="btn-primary flex-1 py-2.5 rounded-lg text-xs font-bold" style={{backgroundColor:"#7EE8D5",color:"#0B1120",border:"none"}}>{editPod.id ? "Vista breytingar" : "Bæta við hlaðvarpi"}</button>
                    <button type="button" onClick={() => setEditPod(null)} className="px-5 py-2.5 rounded-xl text-sm font-medium" style={{color:"#94A3B8",border:"1px solid #1A2744",background:"none"}}>Hætta við</button>
                  </div>
                </form>
              </div>
            </div>
          )}

          {/* Podcast table */}
          <div className="rounded-2xl border overflow-hidden" style={{backgroundColor:"#111B2E",borderColor:"#1A2744"}}>
            <table className="w-full">
              <thead>
                <tr className="border-b" style={{borderColor:"#1A2744"}}>
                  <th className="text-left px-5 py-3 text-xs font-semibold" style={{color:"#64748B"}}>Hlaðvarp</th>
                  <th className="text-left px-3 py-3 text-xs font-semibold hidden md:table-cell" style={{color:"#64748B"}}>Flokkur</th>
                  <th className="text-right px-3 py-3 text-xs font-semibold hidden md:table-cell" style={{color:"#64748B"}}>Þættir</th>
                  <th className="text-right px-3 py-3 text-xs font-semibold hidden md:table-cell" style={{color:"#64748B"}}>Einkunn</th>
                  <th className="text-right px-5 py-3 text-xs font-semibold" style={{color:"#64748B"}}>Aðgerðir</th>
                </tr>
              </thead>
              <tbody>
                {podcasts.map(p => (
                  <tr key={p.id} className="border-b" style={{borderColor:"#1A2744"}}>
                    <td className="px-5 py-3">
                      <div className="flex items-center gap-3">
                        <PodImg pod={p} size={32} radius="rounded-lg"/>
                        <div>
                          <div className="text-sm font-semibold" style={{color:"#ffffff"}}>{p.name}</div>
                          <div className="text-xs md:hidden" style={{color:"#64748B"}}>{p.cat} · {p.eps} þættir</div>
                        </div>
                      </div>
                    </td>
                    <td className="px-3 py-3 text-xs font-medium hidden md:table-cell" style={{color:p.color}}>{p.cat}</td>
                    <td className="px-3 py-3 text-xs font-semibold text-right hidden md:table-cell" style={{color:"#ffffff"}}>{p.eps}</td>
                    <td className="px-3 py-3 text-xs text-right hidden md:table-cell"><span className="flex items-center justify-end gap-1" style={{color:"#ffffff"}}><Star size={10} fill="#f59e0b" stroke="#f59e0b"/> {p.rating}</span></td>
                    <td className="px-5 py-3 text-right">
                      <div className="flex items-center justify-end gap-1.5">
                        <button onClick={() => setEditPod({...p, listeners:String(p.listeners), eps:String(p.eps), rating:String(p.rating), reviews:String(p.reviews), age:{a1:String(p.age.a1),a2:String(p.age.a2),a3:String(p.age.a3),a4:String(p.age.a4),a5:String(p.age.a5)}, gender:{m:String(p.gender.m),f:String(p.gender.f),o:String(p.gender.o)}, loc:{rvk:String(p.loc.rvk),other:String(p.loc.other)}})} className="px-2.5 py-1.5 rounded-lg text-xs font-medium" style={{color:"#7EE8D5",border:"1px solid rgba(126,232,213,0.15)",background:"none"}}>Breyta</button>
                        <button onClick={() => setDeletePod(p)} className="px-2.5 py-1.5 rounded-lg text-xs font-medium" style={{color:"#ef4444",border:"1px solid rgba(239,68,68,0.15)",background:"none"}}>Eyða</button>
                      </div>
                    </td>
                  </tr>
                ))}
              </tbody>
            </table>
          </div>
        </div>
      )}
    </div>
  );
}

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(React.createElement(PodformApp));
