/* global React */
const { useState, useEffect, useRef } = React;

// ============================== ICONS (hairline geometric) ==============================
function Arrow({ rotate = 0, size = 16 }) {
  return (
    <svg viewBox="0 0 16 16" width={size} height={size} style={{transform:`rotate(${rotate}deg)`}} fill="none" stroke="currentColor" strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 8h10M9 4l4 4-4 4" />
    </svg>
  );
}

// ============================== NAV ==============================
function Nav({ t, lang, setLang, theme, setTheme, openDemoModal }) {
  const [shrunk, setShrunk] = useState(false);
  useEffect(() => {
    const onScroll = () => setShrunk(window.scrollY > 24);
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  const logo = theme === "dark" 
    ? "/prosoft_ai_studio_gradient_text_svg/prosoft-ai-studio-gradient-prosoft-titlecase-transparent.svg?v=2" 
    : "/prosoft_ai_studio_gradient_text_svg/prosoft-ai-studio-gradient-prosoft-titlecase-transparent.svg?v=2";
  return (
    <nav className={"nav" + (shrunk ? " shrunk" : "")}>
      <div className="nav-inner">
        <a href="#top" className="nav-mark"><img src={logo} alt="Prosoft AI Studio" /></a>
        <div className="nav-menu">
          <a href="#modules">{t.nav_studios}</a>
          <a href="#workflow">{t.nav_workflow}</a>
          <a href="#trends">{t.nav_trends}</a>
          <a href="#pricing">{t.nav_pricing}</a>
          <a href="#contact">{t.nav_contact}</a>
        </div>
        <div className="nav-right">
          <button className="theme-toggle" onClick={() => setTheme(theme === "light" ? "dark" : "light")} aria-label="Toggle theme">
            {theme === "light" ? "◐" : "◑"}
          </button>
          <div className="lang-toggle">
            <button className={lang === "tr" ? "on" : ""} onClick={() => setLang("tr")}>TR</button>
            <span className="div">/</span>
            <button className={lang === "en" ? "on" : ""} onClick={() => setLang("en")}>EN</button>
          </div>
          <a className="nav-login" href="/aistudio.html" style={{fontSize:14}}>{t.nav_login}</a>
          <button className="btn btn-primary" onClick={openDemoModal} style={{padding:"10px 20px",fontSize:13}}>{t.nav_demo}</button>
        </div>
      </div>
    </nav>
  );
}

// ============================== HERO ==============================
function Hero({ t, openDemoModal }) {
  return (
    <section className="hero" id="top">
      <div className="wrap">
        <div className="hero-grid">
          <div className="hero-left">
            <div className="eyebrow">{t.hero_eyebrow}</div>
            <h1 className="display hero-title">
              {t.hero_title_a} <em>{t.hero_title_em}</em> {t.hero_title_b}
            </h1>
            <p className="hero-sub">{t.hero_sub}</p>
            <div className="hero-ctas">
              <button className="btn btn-primary" onClick={openDemoModal}>{t.hero_cta_primary} <Arrow size={14}/></button>
              <a href="#workflow" className="btn btn-text">{t.hero_cta_ghost}</a>
            </div>
          </div>
          <div className="hero-right">
            <div className="hero-img" style={{ overflow: "hidden", backgroundColor: "var(--bg-alt)" }}>
              <img src="/assets/hero-look-042.png" alt={t.hero_image_label} className="hero-img-zoom" style={{ width: "100%", height: "100%", objectFit: "cover" }} />
            </div>

          </div>
        </div>
        <div className="hero-metrics">
          <div className="hero-metric"><div className="v"><span className="arrow">↓</span>87%</div><div className="lbl">{t.hero_metric_1}</div></div>
          <div className="hero-metric"><div className="v"><span className="arrow">↑</span>14×</div><div className="lbl">{t.hero_metric_2}</div></div>
          <div className="hero-metric"><div className="v">0</div><div className="lbl">{t.hero_metric_3}</div></div>
          <div className="hero-metric"><div className="v">100%</div><div className="lbl">{t.hero_metric_4}</div></div>
        </div>
      </div>
    </section>
  );
}

// ============================== PROOF ==============================
function Proof({ t }) {
  const logos = ["Atelier Çift", "Maison Nahil", "Studio Verda", "Bey Knit", "Halia Couture", "Form & Loom", "Tarz Atölye", "House of Lale"];
  return (
    <section className="proof">
      <div className="wrap">
        <div className="proof-kicker eyebrow">{t.proof_kicker}</div>
      </div>
      <div className="proof-marquee">
        <div className="proof-track">
          {logos.concat(logos).map((l, i) => <span key={i} className="proof-logo">{l}</span>)}
        </div>
      </div>
    </section>
  );
}

// ============================== PROBLEM/SOLUTION ==============================
function ProblemSolution({ t }) {
  return (
    <section className="ps" id="workflow">
      <div className="wrap">
        <div className="ps-head">
          <div className="eyebrow">{t.ps_eyebrow}</div>
          <h2 className="display">{t.ps_title}</h2>
        </div>
        <div className="ps-grid">
          <div className="ps-panel old">
            <div className="ps-panel-head">
              <div className="ps-panel-title">{t.ps_old_title}</div>
              <div className="ps-panel-total">{t.ps_old_total}</div>
            </div>
            {t.ps_steps_old.map((s, i) => (
              <div className="ps-step" key={i}>
                <span className="ps-step-name">{s[0]}</span>
                <span className="ps-step-time">{s[1]}</span>
              </div>
            ))}
          </div>
          <div className="ps-panel new">
            <div className="ps-panel-head">
              <div className="ps-panel-title">{t.ps_new_title}</div>
              <div className="ps-panel-total">{t.ps_new_total}</div>
            </div>
            {t.ps_steps_new.map((s, i) => (
              <div className="ps-step" key={i}>
                <span className="ps-step-name">{s[0]}</span>
                <span className="ps-step-time">{s[1]}</span>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

// ============================== MODULES ==============================
function Modules({ t }) {
  return (
    <section className="mods" id="modules">
      <div className="wrap">
        <div className="mods-head">
          <div>
            <div className="eyebrow" style={{marginBottom:18}}>{t.modules_eyebrow}</div>
            <h2 className="display mods-title">{t.modules_title_a}<em><span style={{color:"var(--signature)"}}>13</span> {t.modules_title_em.replace("13 ", "")}</em>{t.modules_title_b}</h2>
          </div>
          <p className="mods-intro">{t.modules_intro}</p>
        </div>
        <div className="mods-list">
          {t.modules.map((m, i) => {
            const n = String(i + 1).padStart(2, "0");
            const reverse = i % 2 === 1;
            const wide = i === 1 || i === 6 || i === 10;
            return (
              <div className={"mod-row" + (reverse ? " reverse" : "")} id={`module-${i}`} key={i}>
                <div className="mod-text">
                  <div className="mod-num"><span className="ix">{n}</span> / 13</div>
                  <h3 className="mod-name">{m.name}</h3>
                  <p className="mod-desc">{m.desc}</p>
                  <ul className="mod-bullets">
                    {m.bullets.map((b, j) => <li key={j}>{b}</li>)}
                  </ul>
                  <div className="mod-metric">{m.metric}</div>
                </div>
                <div className={"mod-img-wrap" + (wide ? " wide" : "")}>
                  {i === 0 ? (
                    <img src="/assets/module-01-collection.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 1 ? (
                    <img src="/assets/module-02-virtualstudio.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 2 ? (
                    <img src="/assets/module-03-designstudio.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 3 ? (
                    <img src="/assets/module-04-brandstudio.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 4 ? (
                    <img src="/assets/module-05-sketchtoimage.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 5 ? (
                    <img src="/assets/module-06-modelrevise.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 6 ? (
                    <img src="/assets/module-07-patterndesign.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 7 ? (
                    <img src="/assets/module-08-patterntryon.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 8 ? (
                    <img src="/assets/module-09-patternanalysis.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 9 ? (
                    <img src="/assets/module-10-modelmanagement.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 10 ? (
                    <img src="/assets/module-11-trendanalysis.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 11 ? (
                    <img src="/assets/module-12-gallery.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : i === 12 ? (
                    <img src="/assets/module-13-workflow.png" alt={m.name} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: wide ? "16 / 11" : "4 / 5", display: "block", borderRadius: "1px" }} />
                  ) : (
                    <div className="ph">
                      <span className="ph-label">module {n} · ui</span>
                      <span className="ph-ratio">{wide ? "16 / 11" : "4 / 5"}</span>
                    </div>
                  )}
                </div>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}

// ============================== WORKFLOW DIAGRAM ==============================
function WorkflowDiagram({ t }) {
  return (
    <section className="wf" id="trends">
      <div className="wrap">
        <div className="wf-head">
          <div className="eyebrow">{t.wf_eyebrow}</div>
          <h2 className="display">{t.wf_title_a}<em>{t.wf_title_em}</em>{t.wf_title_b}</h2>
        </div>
        <div className="wf-flow">
          {t.wf_nodes.map((n, i) => (
            <React.Fragment key={i}>
              <div className="wf-node">
                <div className="lbl">node · 0{i+1}</div>
                <div className="name">{n}</div>
                <div className="time">{t.wf_times[i]}</div>
              </div>
              {i < t.wf_nodes.length - 1 && (
                <div className="wf-arrow">
                  <svg viewBox="0 0 32 1"><line x1="0" y1="0.5" x2="32" y2="0.5" stroke="currentColor" strokeWidth="1" strokeDasharray="2 3"/></svg>
                  <span>AI</span>
                  <svg viewBox="0 0 32 1"><line x1="0" y1="0.5" x2="32" y2="0.5" stroke="currentColor" strokeWidth="1" strokeDasharray="2 3"/></svg>
                </div>
              )}
            </React.Fragment>
          ))}
        </div>
      </div>
    </section>
  );
}

// ============================== METRICS BANNER ==============================
function MetricsBanner({ t }) {
  return (
    <section className="metrics-banner">
      <div className="wrap">
        <div className="eyebrow metrics-head" style={{opacity:.65}}>{t.metrics_eyebrow}</div>
        <div className="metrics-grid">
          {t.metrics.map((m, i) => (
            <div className="metric-cell" key={i}>
              <div className={"v" + (i === 0 || i === 2 ? " sig" : "")}>{m[0]}</div>
              <div className="lbl">{m[1]}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ============================== PRICING ==============================
function Pricing({ t }) {
  const moduleNames = t.modules.map(m => m.name);
  return (
    <section className="price" id="pricing">
      <div className="wrap">
        <div className="price-head">
          <div className="eyebrow">{t.price_eyebrow}</div>
          <h2 className="display price-title">{t.price_title_a}<em>{t.price_title_em}</em></h2>
          <p className="price-intro">{t.price_intro}</p>
        </div>

        <div className="price-section-label eyebrow">{t.price_credit_packs}</div>
        <div className="price-grid">
          {t.price_packages.map((p, i) => {
            const n = String(i + 1).padStart(2, "0");
            const planKeys = ["starter", "growth", "scale"];
            const buyPlan = () => window.location.href = "/aistudio.html?plan=" + planKeys[i] + "&cycle=monthly";
            return (
              <div className={"price-card" + (p.popular ? " featured" : "")} key={i}>
                <div className="price-card-head">
                  <div className="price-num"><span className="ix">{n}</span> / 03</div>
                  {p.popular && <span className="price-tag">{t.price_popular}</span>}
                </div>
                <h3 className="price-name">{p.name}</h3>
                <div className="price-amount">
                  <span className="price-currency">{p.price}</span>
                  <span className="price-unit">{p.unit}</span>
                </div>
                <div className="price-for">
                  <div className="price-for-label">{t.price_for}</div>
                  <div className="price-for-text">{p.for}</div>
                </div>
                <div className="price-includes-label">{t.price_includes}</div>
                <ul className="price-modules">
                  {moduleNames.map((name, j) => (
                    <li key={j}><span className="mod-ix">{String(j + 1).padStart(2, "0")}</span><span className="mod-name-li">{name}</span><span className="mod-check">●</span></li>
                  ))}
                </ul>
                <button className={"btn " + (p.popular ? "btn-primary" : "btn-ghost")} onClick={buyPlan} style={{marginTop:"auto",alignSelf:"stretch",justifyContent:"center"}}>{t.price_cta}</button>
              </div>
            );
          })}
        </div>

        <div className="price-byok">
          <div className="price-byok-left">
            <div className="eyebrow">{t.price_byok_title}</div>
            <h3 className="price-byok-name">{t.price_byok.name}</h3>
            <p className="price-byok-sub">{t.price_byok_sub}</p>
            <div className="price-for" style={{marginTop:24,borderTop:"1px solid var(--hairline)",paddingTop:20}}>
              <div className="price-for-label">{t.price_for}</div>
              <div className="price-for-text">{t.price_byok.for}</div>
            </div>
          </div>
          <div className="price-byok-mid">
            <div className="price-byok-amount">
              <span className="price-currency">{t.price_byok.price}</span>
              <span className="price-unit">{t.price_byok.unit}</span>
            </div>
            <div className="price-includes-label" style={{marginTop:24}}>{t.price_includes}</div>
            <ul className="price-modules byok">
              {moduleNames.map((name, j) => (
                <li key={j}><span className="mod-ix">{String(j + 1).padStart(2, "0")}</span><span className="mod-name-li">{name}</span><span className="mod-check">●</span></li>
              ))}
            </ul>
          </div>
          <div className="price-byok-right">
            <button className="btn btn-primary" onClick={() => window.location.href = "/aistudio.html?plan=byok&cycle=yearly"} style={{alignSelf:"flex-start"}}>{t.price_cta_byok} <Arrow size={14}/></button>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============================== USE CASES ==============================
function UseCases({ t }) {
  return (
    <section className="uc" id="who">
      <div className="wrap">
        <div className="uc-head">
          <div className="eyebrow">{t.uc_eyebrow}</div>
          <h2 className="display">{t.uc_title}</h2>
        </div>
        <div className="uc-grid">
          {t.uc_cases.map((c, i) => (
            <div className="uc-card" key={i}>
              <div className="num">0{i+1} / 03</div>
              <h3 className="role">{c.role}</h3>
              <p className="story">{c.story}</p>
              <div className="roi">{c.roi}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ============================== SUSTAINABILITY ==============================
function Sustainability({ t }) {
  return (
    <section className="sus">
      <div className="wrap">
        <div className="eyebrow" style={{opacity:.65,marginBottom:32}}>{t.sus_eyebrow}</div>
        <div className="sus-grid">
          <div>
            <h2 className="sus-quote">{t.sus_quote}</h2>
            <p className="sus-caption">{t.sus_caption}</p>
          </div>
          <div className="sus-metrics">
            {t.sus_metrics.map((m, i) => (
              <div className="sus-metric" key={i}>
                <div className="v">{m[0]}</div>
                <div className="lbl">{m[1]}</div>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

// ============================== TESTIMONIAL ==============================
function Testimonial({ t }) {
  return (
    <section className="test">
      <div className="wrap">
        <div className="eyebrow" style={{marginBottom:32}}>{t.test_eyebrow}</div>
        <div className="test-grid">
          <div>
            <p className="test-quote">{t.test_quote}</p>
          </div>
          <div className="test-side">
            <div className="mod-img-wrap" style={{ aspectRatio: "3 / 4", width: "100%", height: "100%", overflow: "hidden" }}>
              <img src="/assets/testimonial-portrait.png" alt="Customer Portrait" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block", borderRadius: "1px" }} />
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============================== CTA ==============================
function CTA({ t, openDemoModal }) {
  return (
    <section className="cta" id="contact">
      <div className="wrap">
        <h2>{t.cta_title_a}<em>{t.cta_title_em}</em></h2>
        <p className="cta-sub">{t.cta_sub}</p>
        <div className="cta-buttons">
          <button className="btn btn-primary" onClick={openDemoModal}>{t.cta_primary} <Arrow size={14}/></button>
          <a href="#pricing" className="btn btn-ghost">{t.cta_ghost}</a>
        </div>
      </div>
    </section>
  );
}

// ============================== FOOTER ==============================
function Footer({ t, theme, openLegalModal }) {
  const logo = theme === "dark" 
    ? "/prosoft_ai_studio_gradient_text_svg/prosoft-ai-studio-gradient-prosoft-titlecase-transparent.png" 
    : "/prosoft_ai_studio_gradient_text_svg/prosoft-ai-studio-gradient-prosoft-titlecase-transparent.png";
  return (
    <footer className="foot">
      <div className="wrap">
        <div className="foot-grid">
          <div className="foot-mark">
            <img src={logo} alt="Prosoft AI Studio" />
            <p className="foot-manifesto">{t.foot_manifesto}</p>
          </div>
          <div className="foot-col foot-col-studios">
            <h4>{t.foot_studios}</h4>
            <ul>{t.modules.map((m,i) => <li key={i}><a href={`#module-${i}`}>{m.name}</a></li>)}</ul>
          </div>
          <div className="foot-col">
            <h4>{t.foot_legal}</h4>
            <ul>{t.foot_legal_links.map((l,i) => <li key={i}><a href="#" onClick={(e) => { e.preventDefault(); openLegalModal(i); }}>{l}</a></li>)}</ul>
          </div>
        </div>
        <div className="foot-bottom">
          <span>{t.foot_copy}</span>
          <span dangerouslySetInnerHTML={{__html: t.foot_addr}}></span>
        </div>
      </div>
    </footer>
  );
}

// ============================== DEMO MODAL ==============================
function DemoModal({ isOpen, onClose, lang }) {
  const [status, setStatus] = useState("idle");
  const [message, setMessage] = useState("");

  if (!isOpen) return null;

  const handleSubmit = async (e) => {
    e.preventDefault();
    setStatus("loading");
    
    const formData = new FormData(e.target);
    const object = Object.fromEntries(formData);
    const json = JSON.stringify(object);

    try {
      const response = await fetch('https://api.web3forms.com/submit', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Accept': 'application/json'
        },
        body: json
      });
      const result = await response.json();
      if (response.status === 200) {
        setStatus("success");
        setMessage(lang === "tr" ? "Talebiniz başarıyla alınmıştır. En kısa sürede iletişime geçeceğiz." : "Request received successfully. We will contact you shortly.");
        setTimeout(() => {
          onClose();
          setTimeout(() => setStatus("idle"), 500);
        }, 3000);
      } else {
        setStatus("error");
        setMessage((lang === "tr" ? "Bir hata oluştu: " : "An error occurred: ") + result.message);
      }
    } catch (error) {
      setStatus("error");
      setMessage(lang === "tr" ? "Bağlantı hatası oluştu. Lütfen tekrar deneyin." : "Connection error. Please try again.");
    }
  };

  const isTr = lang === "tr";

  return (
    <div style={{position:"fixed",inset:0,zIndex:100,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"}}>
      <div style={{position:"absolute",inset:0,backgroundColor:"rgba(0,0,0,0.8)",backdropFilter:"blur(8px)"}} onClick={onClose}></div>
      
      <div style={{position:"relative",background:"#0a0a0a",border:"1px solid rgba(245,158,11,0.2)",borderRadius:"1rem",width:"100%",maxWidth:"36rem",maxHeight:"90vh",overflowY:"auto",boxShadow:"0 0 50px rgba(245,158,11,0.1)",animation:"modalIn 0.3s ease-out"}}>
        <div style={{position:"absolute",top:0,left:0,width:"100%",height:"4px",background:"linear-gradient(to right, transparent, #f59e0b, transparent)"}}></div>
        
        <button onClick={onClose} style={{position:"absolute",top:"1.25rem",right:"1.25rem",background:"transparent",border:"none",color:"#71717a",cursor:"pointer",fontSize:"1.5rem"}}>
          ✕
        </button>
        
        <div style={{padding:"2rem 2.5rem"}}>
          <div style={{textAlign:"center",marginBottom:"2rem"}}>
            <h3 style={{fontSize:"1.875rem",fontFamily:"Fraunces, serif",color:"#fff",marginBottom:"0.5rem"}}>
              Demo <span style={{color:"#f59e0b",fontStyle:"italic"}}>{isTr ? "Talep Et" : "Request"}</span>
            </h3>
            <p style={{fontSize:"0.875rem",color:"#a1a1aa",fontWeight:300}}>
              {isTr ? "Lütfen aşağıdaki bilgileri eksiksiz doldurun. En kısa sürede sizinle iletişime geçeceğiz." : "Please fill out the details below. We will get in touch with you shortly."}
            </p>
          </div>
          
          <form onSubmit={handleSubmit} style={{display:"flex",flexDirection:"column",gap:"1.25rem"}}>
            <input type="hidden" name="access_key" value="109e5b5e-28e7-446f-97cf-a16391c1eaf7" />
            <input type="hidden" name="subject" value="Yeni Demo Talebi - Prosoft AI Studio" />
            
            <div>
              <label style={{display:"block",fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.2em",color:"#71717a",textTransform:"uppercase",marginBottom:"0.5rem"}}>
                {isTr ? "İsim Soyisim" : "Full Name"} <span style={{color:"#f59e0b"}}>*</span>
              </label>
              <input type="text" name="name" required style={{width:"100%",background:"rgba(0,0,0,0.5)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"0.5rem",padding:"0.75rem 1rem",color:"#fff",fontSize:"0.875rem",outline:"none"}} placeholder={isTr ? "Örn: Ahmet Yılmaz" : "e.g. John Doe"} />
            </div>
            
            <div style={{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"1.25rem"}}>
              <div>
                <label style={{display:"block",fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.2em",color:"#71717a",textTransform:"uppercase",marginBottom:"0.5rem"}}>
                  {isTr ? "Firma İsmi" : "Company Name"} <span style={{color:"#f59e0b"}}>*</span>
                </label>
                <input type="text" name="company" required style={{width:"100%",background:"rgba(0,0,0,0.5)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"0.5rem",padding:"0.75rem 1rem",color:"#fff",fontSize:"0.875rem",outline:"none"}} placeholder={isTr ? "Firma Adı" : "Company Name"} />
              </div>
              <div>
                <label style={{display:"block",fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.2em",color:"#71717a",textTransform:"uppercase",marginBottom:"0.5rem"}}>
                  {isTr ? "Telefon" : "Phone"} <span style={{color:"#f59e0b"}}>*</span>
                </label>
                <input type="tel" name="phone" required style={{width:"100%",background:"rgba(0,0,0,0.5)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"0.5rem",padding:"0.75rem 1rem",color:"#fff",fontSize:"0.875rem",outline:"none"}} placeholder="+90 5XX XXX XX XX" />
              </div>
            </div>
            
            <div style={{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"1.25rem"}}>
              <div>
                <label style={{display:"block",fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.2em",color:"#71717a",textTransform:"uppercase",marginBottom:"0.5rem"}}>
                  {isTr ? "E-Posta" : "Email"} <span style={{color:"#f59e0b"}}>*</span>
                </label>
                <input type="email" name="email" required style={{width:"100%",background:"rgba(0,0,0,0.5)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"0.5rem",padding:"0.75rem 1rem",color:"#fff",fontSize:"0.875rem",outline:"none"}} placeholder="ornek@firma.com" />
              </div>
              <div>
                <label style={{display:"block",fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.2em",color:"#71717a",textTransform:"uppercase",marginBottom:"0.5rem"}}>
                  {isTr ? "Lokasyon" : "Location"} <span style={{color:"#f59e0b"}}>*</span>
                </label>
                <input type="text" name="location" required style={{width:"100%",background:"rgba(0,0,0,0.5)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"0.5rem",padding:"0.75rem 1rem",color:"#fff",fontSize:"0.875rem",outline:"none"}} placeholder={isTr ? "Türkiye, İstanbul" : "Country, City"} />
              </div>
            </div>
            
            <div>
              <label style={{display:"block",fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.2em",color:"#71717a",textTransform:"uppercase",marginBottom:"0.5rem"}}>
                {isTr ? "Mesajınız" : "Message"} <span style={{color:"#f59e0b"}}>*</span>
              </label>
              <textarea name="message" required rows="3" style={{width:"100%",background:"rgba(0,0,0,0.5)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"0.5rem",padding:"0.75rem 1rem",color:"#fff",fontSize:"0.875rem",outline:"none",resize:"none"}} placeholder={isTr ? "Projenizden veya beklentilerinizden kısaca bahsedin..." : "Tell us about your project or expectations..."}></textarea>
            </div>
            
            <input type="checkbox" name="botcheck" style={{display:"none"}} />
            
            <div style={{paddingTop:"1rem"}}>
              <button type="submit" disabled={status === "loading" || status === "success"} style={{width:"100%",background: status === "success" ? "#10b981" : "#f59e0b",color:"#000",fontWeight:700,fontSize:"0.75rem",letterSpacing:"0.2em",textTransform:"uppercase",padding:"1rem",borderRadius:"0.5rem",border:"none",cursor:status === "loading" || status === "success" ? "default" : "pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"0.5rem",boxShadow:status === "success" ? "0 0 20px rgba(16, 185, 129, 0.2)" : "0 0 20px rgba(245,158,11,0.2)",transition:"all 0.3s"}}>
                {status === "loading" ? (isTr ? "Gönderiliyor..." : "Sending...") : status === "success" ? (isTr ? "Gönderildi" : "Sent") : (isTr ? "Gönder" : "Send")}
              </button>
            </div>
            
            {status === "success" && (
              <div style={{textAlign:"center",fontSize:"0.875rem",marginTop:"1rem",padding:"0.75rem",borderRadius:"0.5rem",background:"rgba(16,185,129,0.1)",color:"#10b981"}}>
                {message}
              </div>
            )}
            {status === "error" && (
              <div style={{textAlign:"center",fontSize:"0.875rem",marginTop:"1rem",padding:"0.75rem",borderRadius:"0.5rem",background:"rgba(239,68,68,0.1)",color:"#ef4444"}}>
                {message}
              </div>
            )}
          </form>
        </div>
      </div>
      <style dangerouslySetInnerHTML={{__html:`
        @keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
      `}} />
    </div>
  );
}

// ============================== LEGAL MODAL ==============================
function LegalModal({ isOpen, onClose, lang, typeIndex }) {
  if (!isOpen) return null;
  const legalData = window.PROSOFT_LEGAL;
  if (!legalData) return null;

  const currentLangData = legalData[lang] || legalData["tr"];
  let contentData = null;
  if (typeIndex === 0) contentData = currentLangData.privacy;
  else if (typeIndex === 1) contentData = currentLangData.terms;
  else if (typeIndex === 2) contentData = currentLangData.kvkk;

  if (!contentData) return null;

  return (
    <div style={{position:"fixed",inset:0,zIndex:100,display:"flex",alignItems:"center",justifyContent:"center",padding:"1rem"}}>
      <div style={{position:"absolute",inset:0,backgroundColor:"rgba(0,0,0,0.8)",backdropFilter:"blur(8px)"}} onClick={onClose}></div>
      
      <div style={{position:"relative",background:"#0a0a0a",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"1rem",width:"100%",maxWidth:"48rem",maxHeight:"90vh",display:"flex",flexDirection:"column",boxShadow:"0 0 50px rgba(0,0,0,0.5)",animation:"modalIn 0.3s ease-out"}}>
        <div style={{position:"absolute",top:0,left:0,width:"100%",height:"4px",background:"linear-gradient(to right, transparent, #3b82f6, transparent)"}}></div>
        
        <button onClick={onClose} style={{position:"absolute",top:"1.25rem",right:"1.25rem",background:"transparent",border:"none",color:"#71717a",cursor:"pointer",fontSize:"1.5rem",zIndex:10}}>
          ✕
        </button>
        
        <div style={{padding:"2rem 2.5rem 1.5rem",borderBottom:"1px solid rgba(255,255,255,0.05)"}}>
          <h3 style={{fontSize:"1.5rem",fontFamily:"Fraunces, serif",color:"#fff",margin:0}}>
            {contentData.title}
          </h3>
        </div>
        
        <div className="legal-content" style={{padding:"2rem 2.5rem",overflowY:"auto",color:"#a1a1aa",fontSize:"0.875rem",lineHeight:1.6}} dangerouslySetInnerHTML={{__html: contentData.content}}></div>
      </div>
      <style dangerouslySetInnerHTML={{__html:`
        .legal-content h4 { color: #fff; margin-top: 1.5rem; margin-bottom: 0.75rem; font-size: 1rem; }
        .legal-content p { margin-bottom: 1rem; }
        .legal-content a { color: #f59e0b; text-decoration: none; }
        .legal-content a:hover { text-decoration: underline; }
      `}} />
    </div>
  );
}

// ============================== SCROLL TO TOP ==============================
function ScrollToTop() {
  const [visible, setVisible] = useState(false);

  useEffect(() => {
    const handleScroll = () => {
      setVisible(window.scrollY > 400);
    };
    window.addEventListener("scroll", handleScroll, { passive: true });
    return () => window.removeEventListener("scroll", handleScroll);
  }, []);

  const scrollToTop = () => {
    window.scrollTo({ top: 0, behavior: "smooth" });
  };

  return (
    <button 
      onClick={scrollToTop} 
      style={{
        position: "fixed", 
        bottom: "2rem", 
        right: "2rem", 
        width: "3rem", 
        height: "3rem", 
        borderRadius: "50%", 
        backgroundColor: "var(--bg)", 
        color: "var(--fg)", 
        border: "1px solid var(--hairline-strong)",
        display: "flex", 
        alignItems: "center", 
        justifyContent: "center", 
        cursor: "pointer", 
        boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
        zIndex: 90,
        opacity: visible ? 1 : 0,
        pointerEvents: visible ? "auto" : "none",
        transform: visible ? "translateY(0)" : "translateY(20px)",
        transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)"
      }}
      aria-label="Yukarı Çık"
    >
      <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
        <path d="M18 15l-6-6-6 6"/>
      </svg>
    </button>
  );
}

// ============================== ROOT ==============================
function App() {
  const i18n = window.PROSOFT_I18N;
  const [lang, setLangState] = useState(() => {
    const saved = localStorage.getItem("prosoft_lang");
    if (saved === "tr" || saved === "en") return saved;
    return (navigator.language || "tr").toLowerCase().startsWith("tr") ? "tr" : "en";
  });
  const [theme, setThemeState] = useState(() => {
    const saved = localStorage.getItem("prosoft_theme");
    if (saved === "light" || saved === "dark") return saved;
    return window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
  });
  const [isDemoModalOpen, setDemoModalOpen] = useState(false);
  const [legalModalState, setLegalModalState] = useState({ isOpen: false, typeIndex: null });

  const setLang = (l) => { localStorage.setItem("prosoft_lang", l); setLangState(l); };
  const setTheme = (th) => { localStorage.setItem("prosoft_theme", th); setThemeState(th); };

  useEffect(() => {
    document.documentElement.setAttribute("data-theme", theme);
    document.documentElement.setAttribute("lang", lang);
  }, [theme, lang]);

  const t = i18n[lang];
  return (
    <>
      <Nav t={t} lang={lang} setLang={setLang} theme={theme} setTheme={setTheme} openDemoModal={() => setDemoModalOpen(true)} />
      <main>
        <Hero t={t} openDemoModal={() => setDemoModalOpen(true)} />
        <ProblemSolution t={t} />
        <Modules t={t} />
        <WorkflowDiagram t={t} />
        <MetricsBanner t={t} />
        <UseCases t={t} />
        <Pricing t={t} />
        <Sustainability t={t} />
        <Testimonial t={t} />
        <CTA t={t} openDemoModal={() => setDemoModalOpen(true)} />
        <Footer t={t} theme={theme} openLegalModal={(i) => setLegalModalState({ isOpen: true, typeIndex: i })} />
      </main>
      <DemoModal isOpen={isDemoModalOpen} onClose={() => setDemoModalOpen(false)} lang={lang} />
      <LegalModal isOpen={legalModalState.isOpen} onClose={() => setLegalModalState({ isOpen: false, typeIndex: null })} lang={lang} typeIndex={legalModalState.typeIndex} />
      <ScrollToTop />
    </>
  );
}

window.ProsoftApp = App;
