const { useState, useMemo, useEffect, useRef } = React;

/* ── PWA Install Banner (same pattern as Bajrangi Travels) ── */
function PWAInstallBanner() {
  const [deferredPrompt, setDeferredPrompt] = useState(null);
  const [show, setShow]     = useState(false);
  const [isIOS, setIsIOS]   = useState(false);
  const [isAndroid, setIsAndroid] = useState(false);
  const promptReceived = useRef(false);

  useEffect(() => {
    // Inject slide-up keyframe once
    if (!document.getElementById('pwa-banner-style')) {
      const s = document.createElement('style');
      s.id = 'pwa-banner-style';
      s.textContent = `@keyframes pwaBannerUp{from{transform:translateY(100%);opacity:0}to{transform:translateY(0);opacity:1}}.pwa-sheet{animation:pwaBannerUp .35s cubic-bezier(.22,1,.36,1) both}`;
      document.head.appendChild(s);
    }

    const lastDismissed = localStorage.getItem('pwa-banner-dismissed');
    if (lastDismissed && Date.now() - parseInt(lastDismissed) < 7 * 24 * 60 * 60 * 1000) return;
    if (window.matchMedia('(display-mode: standalone)').matches) return;

    const ua = navigator.userAgent;
    const ios = /iphone|ipad|ipod/i.test(ua) && !navigator.standalone;

    if (ios) {
      setIsIOS(true);
      setTimeout(() => setShow(true), 3000);
      return;
    }

    const android = /android/i.test(ua);
    const chrome  = /chrome/i.test(ua) && !/edge|opr\//i.test(ua);

    if (android && chrome) {
      setIsAndroid(true);
      const handler = (e) => {
        e.preventDefault();
        promptReceived.current = true;
        setDeferredPrompt(e);
        setTimeout(() => setShow(true), 3000);
      };
      window.addEventListener('beforeinstallprompt', handler);
      const fallback = setTimeout(() => { if (!promptReceived.current) setShow(true); }, 5000);
      return () => { window.removeEventListener('beforeinstallprompt', handler); clearTimeout(fallback); };
    }
  }, []);

  const handleInstall = async () => {
    if (!deferredPrompt) return;
    await deferredPrompt.prompt();
    const { outcome } = await deferredPrompt.userChoice;
    if (outcome === 'accepted') setShow(false);
    setDeferredPrompt(null);
  };

  const handleDismiss = () => {
    setShow(false);
    localStorage.setItem('pwa-banner-dismissed', Date.now().toString());
  };

  if (!show) return null;

  const BRAND = '#235b74';
  const overlay = { position:'fixed',inset:0,zIndex:9999,display:'flex',alignItems:'flex-end',justifyContent:'center',padding:'0 16px 24px' };
  const backdrop = { position:'absolute',inset:0,background:'rgba(0,0,0,.52)',backdropFilter:'blur(4px)' };
  const sheet = { position:'relative',width:'100%',maxWidth:380,background:'#fff',borderRadius:'24px',boxShadow:'0 24px 64px rgba(0,0,0,.25)',overflow:'hidden' };
  const header = { background:BRAND,padding:'24px 24px 20px',textAlign:'center' };
  const logo = { width:64,height:64,borderRadius:16,overflow:'hidden',margin:'0 auto 12px',boxShadow:'0 4px 12px rgba(0,0,0,.3)',border:'2px solid rgba(255,255,255,.3)' };
  const dismissBtn = { position:'absolute',top:12,right:12,background:'rgba(255,255,255,.18)',border:'none',borderRadius:'50%',width:30,height:30,cursor:'pointer',display:'flex',alignItems:'center',justifyContent:'center',color:'#fff',fontSize:16,lineHeight:1 };
  const stepRow = { display:'flex',alignItems:'center',gap:14,marginBottom:16 };
  const stepIcon = (bg) => ({ width:40,height:40,borderRadius:12,background:bg,display:'flex',alignItems:'center',justifyContent:'center',flexShrink:0 });
  const installBtn = { width:'100%',display:'flex',alignItems:'center',justifyContent:'center',gap:8,padding:'14px',background:BRAND,color:'#fff',border:'none',borderRadius:14,fontSize:15,fontWeight:700,cursor:'pointer',fontFamily:'inherit' };

  const SvgX = () => (
    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round">
      <path d="M6 6l12 12M18 6L6 18"/>
    </svg>
  );
  const SvgShare = () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#3b82f6" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 12v8a2 2 0 002 2h12a2 2 0 002-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/>
    </svg>
  );
  const SvgPlus = () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#16a34a" strokeWidth="2" strokeLinecap="round">
      <line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/>
    </svg>
  );
  const SvgDownload = () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/>
    </svg>
  );

  if (isIOS) return (
    <div style={overlay}>
      <div style={backdrop} onClick={handleDismiss} />
      <div style={sheet} className="pwa-sheet">
        <button style={dismissBtn} onClick={handleDismiss} aria-label="Dismiss"><SvgX /></button>
        <div style={header}>
          <div style={{background:'#fff',borderRadius:12,padding:'10px 18px',display:'inline-block',marginBottom:12,boxShadow:'0 4px 12px rgba(0,0,0,.2)'}}>
            <img src="images/logo.png" alt="567 1st Destiny Plast" style={{height:44,display:'block',objectFit:'contain'}} />
          </div>
          <p style={{color:'#fff',fontWeight:800,fontSize:17,margin:0}}>Add to Home Screen</p>
          <p style={{color:'rgba(255,255,255,.7)',fontSize:12,margin:'4px 0 0'}}>Get 567 1st Destiny Plast on your phone</p>
        </div>
        <div style={{padding:'20px 24px'}}>
          <div style={stepRow}>
            <div style={stepIcon('#eff6ff')}><SvgShare /></div>
            <div>
              <p style={{margin:0,fontWeight:700,fontSize:13,color:'#14323d'}}>Step 1 — Tap the Share button</p>
              <p style={{margin:'3px 0 0',fontSize:12,color:'#7a929b'}}>Tap <strong>⬆ Share</strong> at the bottom of Safari</p>
            </div>
          </div>
          <div style={stepRow}>
            <div style={stepIcon('#f0fdf4')}><SvgPlus /></div>
            <div>
              <p style={{margin:0,fontWeight:700,fontSize:13,color:'#14323d'}}>Step 2 — Add to Home Screen</p>
              <p style={{margin:'3px 0 0',fontSize:12,color:'#7a929b'}}>Scroll and tap <strong>"Add to Home Screen"</strong></p>
            </div>
          </div>
          <div style={stepRow}>
            <div style={stepIcon('#eef2f4')}><img src="icons/icon-72x72.png" alt="" style={{width:24,height:24,borderRadius:6,objectFit:'cover'}} /></div>
            <div>
              <p style={{margin:0,fontWeight:700,fontSize:13,color:'#14323d'}}>Step 3 — Tap Add</p>
              <p style={{margin:'3px 0 0',fontSize:12,color:'#7a929b'}}>The app icon appears on your Home Screen</p>
            </div>
          </div>
          <p style={{textAlign:'center',fontSize:12,color:'#7a929b',margin:'4px 0 0'}}>Look for the <strong>⬆</strong> Share icon in Safari's toolbar below</p>
          <p style={{textAlign:'center',fontSize:20,margin:'4px 0 0'}}>↓</p>
        </div>
      </div>
    </div>
  );

  if (isAndroid) return (
    <div style={overlay}>
      <div style={backdrop} onClick={handleDismiss} />
      <div style={sheet} className="pwa-sheet">
        <button style={dismissBtn} onClick={handleDismiss} aria-label="Dismiss"><SvgX /></button>
        <div style={header}>
          <div style={{background:'#fff',borderRadius:12,padding:'10px 18px',display:'inline-block',marginBottom:12,boxShadow:'0 4px 12px rgba(0,0,0,.2)'}}>
            <img src="images/logo.png" alt="567 1st Destiny Plast" style={{height:44,display:'block',objectFit:'contain'}} />
          </div>
          <div style={{display:'flex',justifyContent:'center',gap:2,marginBottom:6}}>
            {[1,2,3,4,5].map(i => <span key={i} style={{color:'#f59e0b',fontSize:12}}>★</span>)}
          </div>
          <p style={{color:'#fff',fontWeight:800,fontSize:17,margin:0}}>Install the App</p>
          <p style={{color:'rgba(255,255,255,.7)',fontSize:12,margin:'4px 0 0'}}>Faster browsing &amp; offline access</p>
        </div>
        <div style={{padding:'20px 24px'}}>
          <button onClick={handleInstall} disabled={!deferredPrompt} style={{...installBtn,opacity:deferredPrompt?1:.6}}>
            <SvgDownload /> Install 567 1st Destiny Plast App
          </button>
          {!deferredPrompt && (
            <p style={{textAlign:'center',fontSize:12,color:'#7a929b',margin:'12px 0 0'}}>
              Tap <strong>⋮</strong> in Chrome → <strong>Add to Home screen</strong>
            </p>
          )}
        </div>
      </div>
    </div>
  );

  return null;
}
const C = window.CATALOG;
const WA = C.contact.whatsapp;
const PDF = "catalogue/1st-Destiny-Plast-Catalogue.pdf";

const PAGE = (() => {
  const p = window.location.pathname.split('/').pop().replace('.html','');
  return p === '' || p === 'index' ? 'home' : p;
})();

const waLink = (txt) => `https://wa.me/${WA}?text=${encodeURIComponent(txt)}`;
const enquireLink = (p) => {
  const imgUrl = `https://1stdestinyplast567.com/images/products/dp-${p.dp}.jpg`;
  return waLink(`Hi 567 1st Destiny Plast, I'd like to enquire about *${p.name}* (DP ${p.dp}). Please share price & availability.\n\nProduct image: ${imgUrl}`);
};
const generalLink = waLink("Hi 567 1st Destiny Plast, I'd like to enquire about your curtain track & blinds products.");

const SWATCH = { Black:"#1b1b1b", Brown:"#5a3d29", Ivory:"#ece3cf", Gold:"#c9a24b", Grey:"#8d8d8d", Silver:"#cfcfcf" };

/* ---------- icons ---------- */
const I = {
  wa: <svg viewBox="0 0 24 24" fill="currentColor"><path d="M.057 24l1.687-6.163a11.867 11.867 0 01-1.587-5.946C.16 5.335 5.495 0 12.05 0a11.82 11.82 0 018.413 3.488 11.82 11.82 0 013.48 8.414c-.003 6.557-5.338 11.892-11.893 11.892a11.9 11.9 0 01-5.688-1.448L.057 24zm6.597-3.807c1.676.995 3.276 1.591 5.392 1.592 5.448 0 9.886-4.434 9.889-9.885.002-5.462-4.415-9.89-9.881-9.892-5.452 0-9.887 4.434-9.889 9.884a9.86 9.86 0 001.51 5.26l-.999 3.648 3.978-1.039zm11.387-5.464c-.074-.124-.272-.198-.57-.347-.297-.149-1.758-.868-2.031-.967-.272-.099-.47-.149-.669.149-.198.297-.768.967-.941 1.165-.173.198-.347.223-.644.074-.297-.149-1.255-.462-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.297-.347.446-.521.151-.172.2-.296.3-.495.099-.198.05-.372-.025-.521-.075-.148-.669-1.611-.916-2.206-.242-.579-.487-.501-.669-.51l-.57-.01c-.198 0-.52.074-.792.372s-1.04 1.016-1.04 2.479 1.065 2.876 1.213 3.074c.149.198 2.095 3.2 5.076 4.487.709.306 1.263.489 1.694.626.712.226 1.36.194 1.872.118.571-.085 1.758-.719 2.006-1.413.248-.695.248-1.29.173-1.414z"/></svg>,
  search: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4-4"/></svg>,
  dl: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="12" y1="10" x2="12" y2="16"/><polyline points="9 13 12 16 15 13"/></svg>,
  menu: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><path d="M3 6h18M3 12h18M3 18h18"/></svg>,
  x: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>,
  phone: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M22 16.92v3a2 2 0 01-2.18 2 19.8 19.8 0 01-8.63-3.07 19.5 19.5 0 01-6-6 19.8 19.8 0 01-3.07-8.67A2 2 0 014.11 2h3a2 2 0 012 1.72c.13.96.36 1.9.7 2.81a2 2 0 01-.45 2.11L8.09 9.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0122 16.92z"/></svg>,
  mail: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 7l9 6 9-6"/></svg>,
  pin: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M21 10c0 6-9 12-9 12s-9-6-9-12a9 9 0 0118 0z"/><circle cx="12" cy="10" r="3"/></svg>,
  ig: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="1" fill="currentColor" stroke="none"/></svg>,
  shield: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round"><path d="M12 2l8 4v6c0 5-3.5 8.5-8 10-4.5-1.5-8-5-8-10V6z"/><path d="M9 12l2 2 4-4"/></svg>,
  grid: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7"><rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/></svg>,
  bolt: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round"><path d="M13 2L4 14h6l-1 8 9-12h-6z"/></svg>,
  truck: <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round"><rect x="1" y="6" width="13" height="10" rx="1.5"/><path d="M14 9h4l3 3v4h-7z"/><circle cx="6" cy="18" r="2"/><circle cx="17" cy="18" r="2"/></svg>,
};

/* ---------- product thumbnail glyphs (simple shapes only) ---------- */
function Glyph({ cat }) {
  const blinds = ["roller","zebra"];
  const tape = ["tape"];
  const acc = ["accessories","hospital","universal","ripple"];
  let kind = "track";
  if (blinds.includes(cat)) kind = "blind";
  else if (tape.includes(cat)) kind = "tape";
  else if (acc.includes(cat)) kind = "acc";
  if (kind === "blind")
    return (<svg viewBox="0 0 100 80"><rect x="20" y="12" width="60" height="6" rx="3" fill="currentColor"/><rect x="26" y="22" width="48" height="40" rx="2" fill="none" stroke="currentColor" strokeWidth="2.5"/><line x1="26" y1="34" x2="74" y2="34" stroke="currentColor" strokeWidth="2.5"/><line x1="26" y1="46" x2="74" y2="46" stroke="currentColor" strokeWidth="2.5"/><circle cx="50" cy="68" r="3" fill="currentColor"/></svg>);
  if (kind === "tape")
    return (<svg viewBox="0 0 100 80"><rect x="14" y="30" width="72" height="20" rx="3" fill="none" stroke="currentColor" strokeWidth="2.5"/><circle cx="28" cy="40" r="3" fill="currentColor"/><circle cx="44" cy="40" r="3" fill="currentColor"/><circle cx="60" cy="40" r="3" fill="currentColor"/><circle cx="76" cy="40" r="3" fill="currentColor"/></svg>);
  if (kind === "acc")
    return (<svg viewBox="0 0 100 80"><circle cx="50" cy="30" r="14" fill="none" stroke="currentColor" strokeWidth="2.5"/><path d="M50 44 v14 a8 8 0 0 0 16 0" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round"/></svg>);
  return (<svg viewBox="0 0 100 80"><rect x="10" y="30" width="80" height="12" rx="3" fill="none" stroke="currentColor" strokeWidth="2.5"/><circle cx="28" cy="50" r="4" fill="currentColor"/><circle cx="44" cy="50" r="4" fill="currentColor"/><circle cx="60" cy="50" r="4" fill="currentColor"/><circle cx="76" cy="50" r="4" fill="currentColor"/><line x1="28" y1="42" x2="28" y2="47" stroke="currentColor" strokeWidth="2"/><line x1="44" y1="42" x2="44" y2="47" stroke="currentColor" strokeWidth="2"/><line x1="60" y1="42" x2="60" y2="47" stroke="currentColor" strokeWidth="2"/><line x1="76" y1="42" x2="76" y2="47" stroke="currentColor" strokeWidth="2"/></svg>);
}

function Card({ p, catName }) {
  const [imgOk, setImgOk] = useState(true);
  const src = `images/products/dp-${p.dp}.jpg`;
  return (
    <div className="card">
      <div className="thumb">
        <span className="dp-badge">DP {p.dp}</span>
        {imgOk ? (
          <img className="thumb-img" src={src} alt={p.name} loading="lazy"
               onError={() => setImgOk(false)} />
        ) : (
          <React.Fragment>
            <Glyph cat={p.cat} />
            <span className="thumb-note">product photo</span>
          </React.Fragment>
        )}
      </div>
      <div className="card-body">
        <span className="card-cat">{catName}</span>
        <span className="card-name">{p.name}</span>
        <div className="card-foot">
          <a className="enquire" href={enquireLink(p)} target="_blank" rel="noopener">
            {I.wa} Enquire
          </a>
        </div>
      </div>
    </div>
  );
}

function App() {
  const [q, setQ] = useState("");
  const [active, setActive] = useState(() => {
    if (PAGE === 'products') {
      return new URLSearchParams(window.location.search).get('cat') || 'all';
    }
    return 'all';
  });
  const [drawer, setDrawer] = useState(false);
  const catName = useMemo(() => Object.fromEntries(C.categories.map(c => [c.id, c.name])), []);
  const counts = useMemo(() => {
    const m = {}; C.products.forEach(p => m[p.cat] = (m[p.cat]||0)+1); return m;
  }, []);
  const catFirstDp = useMemo(() => {
    const m = {};
    C.products.forEach(p => { if (!m[p.cat]) m[p.cat] = p.dp; });
    return m;
  }, []);

  const filtered = useMemo(() => {
    const term = q.trim().toLowerCase();
    return C.products.filter(p => {
      if (active !== "all" && p.cat !== active) return false;
      if (!term) return true;
      return p.name.toLowerCase().includes(term)
        || ("dp " + p.dp).toLowerCase().includes(term)
        || ("dp" + p.dp).toLowerCase().includes(term)
        || String(p.dp).toLowerCase().includes(term)
        || catName[p.cat].toLowerCase().includes(term);
    });
  }, [q, active, catName]);

  const groups = useMemo(() => {
    return C.categories
      .map(c => ({ cat: c, items: filtered.filter(p => p.cat === c.id) }))
      .filter(g => g.items.length);
  }, [filtered]);

  const nav = [
    ["Products", "products.html"],
    ["About",    "about.html"],
    ["Contact",  "contact.html"]
  ];

  const isActive = (href) => window.location.pathname.endsWith(href);

  return (
    <React.Fragment>
      {/* HEADER */}
      <header className="hdr">
        <div className="wrap hdr-in">
          <a className="brand" href="index.html">
            <img className="brand-logo" src="images/logo-transparent.png" alt="567 1st Destiny Plast — Curtain Material & Blinds Accessories" />
          </a>
          <nav className="nav">
            {nav.map(([t,h]) => (
              <a key={h} href={h} className={isActive(h) ? "nav-active" : ""}>{t}</a>
            ))}
          </nav>
          <div className="hdr-cta">
            <a className="btn btn-ghost" href={PDF} download>{I.dl}<span className="btn-txt-hide"> Catalogue</span></a>
            <a className="btn btn-wa hdr-wa-hide" href={generalLink} target="_blank" rel="noopener">{I.wa}<span className="btn-txt-hide"> WhatsApp</span></a>
            <button className="menu-btn" onClick={() => setDrawer(true)} aria-label="Menu">{I.menu}</button>
          </div>
        </div>
      </header>

      {/* MOBILE DRAWER */}
      <div className={"drawer" + (drawer ? " open" : "")}>
        <button className="x" onClick={() => setDrawer(false)} aria-label="Close">{I.x}</button>
        {nav.map(([t,h]) => <a key={h} href={h} onClick={() => setDrawer(false)}>{t}</a>)}
        <a className="btn btn-ghost" href={PDF} download onClick={() => setDrawer(false)}>{I.dl} Download Catalogue</a>
        <a className="btn btn-wa" href={generalLink} target="_blank" rel="noopener">{I.wa} Enquire on WhatsApp</a>
      </div>

      {/* HOME PAGE */}
      {PAGE === 'home' && (
        <React.Fragment>
          <section className="hero" id="top">
            <div className="wrap hero-in">
              <div className="hero-left">
                <p className="eyebrow">Curtain Tracks · Blinds · Motorized Systems</p>
                <h1 style={{marginTop:"18px"}}>Hardware that makes <em>every curtain</em> glide.</h1>
                <p>India-made curtain track systems, motorized drives, roller &amp; zebra blinds, tapes and fittings — engineered in Mumbai and trusted by interior professionals.</p>
                <div className="hero-cta">
                  <a className="btn btn-gold" href="products.html">{I.grid} Browse Products</a>
                  <a className="btn btn-ghost" href={PDF} download>{I.dl} Download Catalogue (PDF)</a>
                </div>
                <div className="stats">
                  <div className="stat"><b><em>135+</em></b><span>Products</span></div>
                  <div className="stat"><b>22</b><span>Categories</span></div>
                  <div className="stat"><b>Made in</b><span>Mumbai, India</span></div>
                  <div className="stat"><b>Mfg &amp;</b><span>Wholesale Supply</span></div>
                </div>
              </div>
              <div className="hero-right">
                <div className="hero-img-wrap">
                  <img src="images/products/dp-12.jpg" alt="Silent Track All Colours" loading="eager" />
                </div>
                <div className="hero-img-wrap">
                  <img src="images/products/dp-118.jpg" alt="Gravity Track" loading="eager" />
                </div>
                <div className="hero-img-wrap">
                  <img src="images/products/dp-81.jpg" alt="Diamond Track" loading="eager" />
                </div>
                <div className="hero-img-wrap">
                  <img src="images/products/dp-106.jpg" alt="Alis Track" loading="eager" />
                </div>
              </div>
            </div>
          </section>

          {/* CATEGORY GRID */}
          <section className="cat-section">
            <div className="wrap">
              <div className="cat-sec-head">
                <p className="eyebrow">Shop by Category</p>
                <h2>What are you looking for?</h2>
              </div>
              <div className="cat-grid">
                {C.categories.map(c => (
                  <a key={c.id} className="cat-card" href={`products.html?cat=${c.id}`}>
                    <div className="cat-thumb">
                      <img src={`images/products/dp-${catFirstDp[c.id]}.jpg`} alt={c.name} loading="lazy"
                           onError={e => { e.target.style.display='none'; }} />
                    </div>
                    <span className="cat-name">{c.name}</span>
                    <span className="cat-count">{counts[c.id] || 0} items</span>
                  </a>
                ))}
              </div>
            </div>
          </section>
        </React.Fragment>
      )}

      {/* PRODUCTS PAGE */}
      {PAGE === 'products' && (
        <section className="browse wrap" id="products">
          <div className="sec-head">
            <div>
              <p className="eyebrow">The Catalogue</p>
              <h2>Browse the full range</h2>
            </div>
          </div>

          <div className="toolbar">
            <div className="search">
              {I.search}
              <input value={q} onChange={e => setQ(e.target.value)} placeholder="Search products, DP code, category…" />
            </div>
            <div className="chips">
              <button className={"chip" + (active==="all"?" on":"")} onClick={() => setActive("all")}>
                All <span className="ct">{C.products.length}</span>
              </button>
              {C.categories.map(c => (
                <button key={c.id} className={"chip" + (active===c.id?" on":"")} onClick={() => setActive(c.id)}>
                  {c.name} <span className="ct">{counts[c.id]||0}</span>
                </button>
              ))}
            </div>
          </div>

          <p className="count">
            {filtered.length} {filtered.length===1?"product":"products"}
            {active!=="all" && ` in ${catName[active]}`}
            {q && ` matching "${q}"`}
          </p>

          {groups.length === 0 && (
            <div className="empty"><b>No products found</b>Try a different search term or category.</div>
          )}

          {groups.map(g => (
            <div className="group" key={g.cat.id}>
              <div className="group-head">
                <h3>{g.cat.name}</h3>
                {g.cat.colors && (
                  <div className="swatches">
                    {g.cat.colors.map(col => (
                      <span key={col} className="sw" title={col} style={{background: SWATCH[col]||"#999"}} />
                    ))}
                  </div>
                )}
                <span className="line" />
                <span className="gct">{g.items.length} items</span>
              </div>
              <div className="grid">
                {g.items.map(p => <Card key={String(p.dp)+p.name} p={p} catName={g.cat.name} />)}
              </div>
            </div>
          ))}
        </section>
      )}

      {/* ABOUT PAGE */}
      {PAGE === 'about' && (
        <section className="about" id="about">
          <div className="wrap about-in">
            <div>
              <p className="eyebrow">Who we are</p>
              <h2>Precision curtain hardware, made in Mumbai.</h2>
              <p>567 1st Destiny Plast manufactures and supplies a complete catalogue of curtain track systems — from everyday silent &amp; M tracks to motorized drives, heavy-duty and bending profiles, roller &amp; zebra blinds, ripple-fold systems, tapes and every fitting in between.</p>
              <p>Whether you're an interior designer, contractor, dealer or homeowner, our range covers the full installation in colours to match any space.</p>
            </div>
            <div className="about-feats">
              <div className="feat"><div className="ic">{I.grid}</div><b>Full system</b><span>Tracks, runners, brackets, caps &amp; fittings under one roof.</span></div>
              <div className="feat"><div className="ic">{I.bolt}</div><b>Motorized ready</b><span>Smart curtain motors, drives &amp; remotes.</span></div>
              <div className="feat"><div className="ic">{I.shield}</div><b>Built to last</b><span>Silent, durable profiles engineered for daily use.</span></div>
              <div className="feat"><div className="ic">{I.truck}</div><b>Wholesale supply</b><span>Bulk &amp; dealer orders across India.</span></div>
            </div>
          </div>
        </section>
      )}

      {/* CONTACT PAGE */}
      {PAGE === 'contact' && (
        <section className="contact" id="contact">
          <div className="wrap contact-in">
            <div>
              <p className="eyebrow">Get in touch</p>
              <h2>Enquire &amp; order</h2>
              <p className="lead">Message us on WhatsApp for prices, samples and bulk orders — or reach out the old-fashioned way.</p>
              <div className="cinfo">
                <div className="crow"><span className="ic">{I.phone}</span>
                  <div><div className="k">Phone / WhatsApp</div>
                    <a className="v" href={`tel:${C.contact.phone1.replace(/\s/g,"")}`}>{C.contact.phone1}</a><br/>
                    <a className="v" href={`tel:${C.contact.phone2.replace(/\s/g,"")}`}>{C.contact.phone2}</a></div>
                </div>
                <div className="crow"><span className="ic">{I.mail}</span>
                  <div><div className="k">Email</div><a className="v" href={`mailto:${C.contact.email}`}>{C.contact.email}</a></div>
                </div>
                <div className="crow"><span className="ic">{I.ig}</span>
                  <div><div className="k">Instagram</div><a className="v" href={C.contact.instagramUrl} target="_blank" rel="noopener">@{C.contact.instagram}</a></div>
                </div>
                <div className="crow"><span className="ic">{I.pin}</span>
                  <div><div className="k">Address</div><span className="v">{C.contact.address}</span></div>
                </div>
              </div>
            </div>
            <div className="contact-card">
              <h3>Ready to order?</h3>
              <p>Tap below to start a WhatsApp chat with our sales team, or download the complete product catalogue.</p>
              <div className="stack">
                <a className="btn btn-wa" href={generalLink} target="_blank" rel="noopener">{I.wa} Chat on WhatsApp</a>
                <a className="btn btn-gold" href={PDF} download>{I.dl} Download Catalogue (PDF)</a>
                <a className="btn btn-ghost" href={`tel:${C.contact.phone1.replace(/\s/g,"")}`}>{I.phone} Call {C.contact.phone1}</a>
              </div>
            </div>
          </div>
        </section>
      )}

      {/* FOOTER */}
      <footer className="ftr">
        <div className="wrap ftr-in">
          <div className="ftr-top">
            <a className="brand" href="index.html">
              <img className="brand-logo" src="images/logo-transparent.png" alt="567 1st Destiny Plast" />
            </a>
            <nav className="ftr-links">
              <a href="products.html">Products</a>
              <a href="about.html">About</a>
              <a href="contact.html">Contact</a>
              <a href={C.contact.instagramUrl} target="_blank" rel="noopener">Instagram</a>
            </nav>
          </div>
          <div className="ftr-bottom">
            <small>© {new Date().getFullYear()} 567 1st Destiny Plast. All rights reserved.</small>
            <small>Powered by <a href="https://u1digital.in" target="_blank" rel="noopener">U1 Digital</a></small>
          </div>
        </div>
      </footer>

      {/* FLOATING WHATSAPP */}
      <a className="fab" href={generalLink} target="_blank" rel="noopener" aria-label="WhatsApp">
        {I.wa}
      </a>

      {/* PWA INSTALL BANNER */}
      <PWAInstallBanner />
    </React.Fragment>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
