// Home page — the main landing.
// Sections: Hero (variant-switchable), brand marquee, RAL palette OS,
// categories, popular products, services, branches, testimonials, CTA.

function PageHome() {
  return (
    <>
      <Hero />
      <BrandMarquee />
      <SectionPalette />
      <SectionCategories />
      <SectionPopular />
      <SectionServices />
      <SectionBranches />
      <SectionTestimonials />
      <SectionCTA />
    </>
  );
}

// ============= HERO =============
function Hero() {
  // Read hero variant from the nearest scoped element's data attribute
  // (set by applyThemeToScope). Falls back to palette-strip.
  const [variant, setVariant] = useState('palette-strip');
  useEffect(() => {
    const findScope = () => {
      let el = document.querySelector('.fl-app-scroll[data-hero-variant]');
      if (el) return el.getAttribute('data-hero-variant');
      return 'palette-strip';
    };
    setVariant(findScope());
    // Re-check whenever a tweak might have updated it
    const obs = new MutationObserver(() => setVariant(findScope()));
    document.querySelectorAll('.fl-app-scroll').forEach(el => {
      obs.observe(el, { attributes: true, attributeFilter: ['data-hero-variant'] });
    });
    return () => obs.disconnect();
  }, []);
  if (variant === 'split-image')   return <HeroSplit />;
  if (variant === 'manifesto')     return <HeroManifesto />;
  if (variant === 'product-led')   return <HeroProductLed />;
  return <HeroPalette />;
}

function HeroPalette() {
  // Editorial hero: oversized headline, RAL strip below, side info.
  // Strip wraps onto two rows on tablet, single tall column on mobile.
  const swatches = RAL_COLORS.slice(0, 36);
  return (
    <section className="hero hero--palette">
      <div className="container">
        <div className="hero__top">
          <span className="eyebrow">Bełchatów · Radomsko · od 1990</span>
          <span className="text-mono text-3" style={{ fontSize: 12 }}>
            <span style={{ display: 'inline-block', width: 8, height: 8, borderRadius: 999,
              background: '#3da564', marginRight: 8, verticalAlign: 1 }}/>
            Salony otwarte do 17:00
          </span>
        </div>
        <h1 className="h-display reveal-up" style={{ marginTop: 'var(--space-4)' }}>
          Każdy odcień, jaki<br/>
          potrafisz <em>nazwać</em> —<br/>
          i dwadzieścia tysięcy<br/>
          tych, które znajdziemy<br/>
          dla Ciebie.
        </h1>

        <div className="hero__cta">
          <Link to="/katalog" className="btn btn--primary btn--lg">
            Otwórz katalog kolorów <Icon name="arrow-right" size={16}/>
          </Link>
          <Link to="/kalkulator" className="btn btn--ghost btn--lg">
            <Icon name="calculator" size={16}/> Policz, ile farby kupić
          </Link>
          <span className="text-mono text-3" style={{ alignSelf: 'center', fontSize: 12 }}>
            <Icon name="phone" size={12} stroke={2}/> &nbsp;Doradca odbiera w 30 sek.
          </span>
        </div>
      </div>

      <div className="hero__strip" aria-hidden="true">
        {swatches.map((c, i) => (
          <div className="hero__swatch" key={c.ral} style={{ background: c.hex }}>
            <div className="hero__swatch-meta">
              <span className="hero__swatch-ral">RAL {c.ral}</span>
              <span className="hero__swatch-name">{c.name}</span>
            </div>
          </div>
        ))}
      </div>

      <div className="container hero__metrics">
        <Metric value="35" suffix="lat" label="rodzinnej historii" />
        <Metric value="20K" suffix="+" label="receptur w mieszalniku" />
        <Metric value="3" suffix="oddziały" label="Bełchatów &amp; Radomsko" />
        <Metric value="48h" suffix="" label="dostawa pod budowę" />
      </div>

      <style>{`
        .hero--palette { padding-top: var(--space-9); padding-bottom: 0; position: relative; }
        .hero__top {
          display: flex; justify-content: space-between; align-items: center;
          padding-bottom: var(--space-4); border-bottom: var(--hairline);
        }
        .hero__cta {
          display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
          margin-top: var(--space-7); padding-bottom: var(--space-7);
        }
        .hero__strip {
          display: grid;
          grid-template-columns: repeat(12, 1fr);
          height: 380px;
          border-block: var(--hairline);
        }
        .hero__swatch {
          position: relative; overflow: hidden;
          border-right: 1px solid rgba(0,0,0,0.06);
        }
        .hero__swatch:last-child { border-right: 0; }
        .hero__swatch:nth-child(n+13) { display: none; }
        .hero__swatch:hover { z-index: 1; }
        .hero__swatch-meta {
          position: absolute; left: 14px; bottom: 14px; right: 14px;
          font-family: var(--font-mono); font-size: 10px; line-height: 1.3;
          color: rgba(255,255,255,0.85); mix-blend-mode: difference;
          letter-spacing: 0.06em;
          opacity: 0; transform: translateY(6px); transition: 240ms ease;
        }
        .hero__swatch:hover .hero__swatch-meta { opacity: 1; transform: translateY(0); }
        .hero__swatch-ral { display: block; font-weight: 600; }
        .hero__swatch-name { text-transform: uppercase; opacity: 0.85; }
        .hero__metrics {
          display: grid; grid-template-columns: repeat(4, 1fr);
          padding-block: var(--space-6);
          border-bottom: var(--hairline);
        }
        @media (max-width: 980px) {
          .hero__strip { grid-template-columns: repeat(6, 1fr); height: 280px; }
          .hero__swatch:nth-child(n+7) { display: none; }
          .hero__metrics { grid-template-columns: repeat(2, 1fr); gap: var(--space-5); }
        }
        @media (max-width: 600px) {
          .hero__strip { grid-template-columns: repeat(4, 1fr); height: 200px; }
          .hero__swatch:nth-child(n+5) { display: none; }
        }
      `}</style>
    </section>
  );
}

function Metric({ value, suffix, label }) {
  return (
    <div>
      <div style={{
        fontFamily: 'var(--font-display)', fontSize: 'clamp(36px, 5vw, 64px)',
        fontWeight: 470, letterSpacing: '-0.02em', lineHeight: 1
      }}>
        {value}<span style={{ color: 'var(--brand)', fontStyle: 'italic', fontWeight: 380 }}> {suffix}</span>
      </div>
      <div className="text-3" style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.12em',
        textTransform: 'uppercase', marginTop: 8 }} dangerouslySetInnerHTML={{ __html: label }}/>
    </div>
  );
}

function HeroSplit() {
  return (
    <section className="hero-split">
      <div className="container hero-split__inner">
        <div className="hero-split__copy">
          <span className="eyebrow">Salon &amp; hurtownia · od 1990</span>
          <h1 className="h-display" style={{ marginTop: 16 }}>
            Sklep, w którym <em>kolor</em><br/> ma swoje zdanie.
          </h1>
          <p className="lede" style={{ marginTop: 24 }}>
            Nie sprzedajemy wiader z farbą — pomagamy dobrać matową bazę pod światło z północy,
            właściwą emalię na bramę garażową i tynk wenecki, który nie odpadnie po pierwszej zimie.
            Trzy oddziały, jeden mieszalnik na wszystko.
          </p>
          <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', marginTop: 32 }}>
            <Link to="/katalog" className="btn btn--primary btn--lg">
              Przejdź do katalogu <Icon name="arrow-right" size={16}/>
            </Link>
            <Link to="/o-firmie" className="btn btn--ghost btn--lg">
              Poznaj historię firmy
            </Link>
          </div>
          <div className="hero-split__chips">
            <span className="chip"><Icon name="shield-check" size={12}/> Autoryzowany Tikkurila</span>
            <span className="chip"><Icon name="truck" size={12}/> Dostawa 48h</span>
            <span className="chip"><Icon name="users" size={12}/> Doradca B2B</span>
          </div>
        </div>
        <div className="hero-split__image">
          <PhotoMosaic />
        </div>
      </div>
      <style>{`
        .hero-split { padding-top: var(--space-9); padding-bottom: var(--space-9); }
        .hero-split__inner { display: grid; grid-template-columns: 1.1fr 1fr; gap: var(--space-8); align-items: center; }
        .hero-split__chips { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 28px; }
        .hero-split__image { aspect-ratio: 4/5; }
        @media (max-width: 980px) { .hero-split__inner { grid-template-columns: 1fr; } }
      `}</style>
    </section>
  );
}

function PhotoMosaic() {
  // Stylized photo placeholder with paint stripe overlay using the brand swatches
  return (
    <div className="photo-mosaic">
      <div className="photo-mosaic__main">
        <div style={{
          position: 'absolute', inset: 0, padding: 24,
          display: 'grid', gridTemplateColumns: '1fr 1fr', gridTemplateRows: '1fr 1fr', gap: 16
        }}>
          {[
            { c: '#8D1D2C', l: 'RAL 3003' },
            { c: '#FDF4E3', l: 'RAL 9001' },
            { c: '#293133', l: 'RAL 7016' },
            { c: '#E5BE01', l: 'RAL 1003' },
          ].map((s, i) => (
            <div key={i} style={{
              background: s.c, borderRadius: 14, position: 'relative',
              boxShadow: 'inset 0 0 0 1px rgba(0,0,0,0.06)'
            }}>
              <span style={{
                position: 'absolute', left: 12, bottom: 10,
                fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.1em',
                color: i === 1 || i === 3 ? '#14110d' : '#fff', opacity: 0.7
              }}>{s.l}</span>
            </div>
          ))}
        </div>
        <div className="photo-mosaic__tag">
          <Icon name="palette" size={14}/> Mieszalnik · 09:23 · Bełchatów Os. Słoneczne
        </div>
      </div>
      <style>{`
        .photo-mosaic { width: 100%; height: 100%; position: relative; }
        .photo-mosaic__main {
          position: absolute; inset: 0;
          background: var(--bg-tint);
          border-radius: var(--r-xl);
          border: var(--hairline);
          overflow: hidden;
        }
        .photo-mosaic__tag {
          position: absolute; left: 16px; top: 16px;
          padding: 8px 14px; border-radius: 999px;
          background: rgba(255,255,255,0.9); backdrop-filter: blur(8px);
          font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em;
          display: inline-flex; align-items: center; gap: 6px;
          color: var(--ink-2);
        }
      `}</style>
    </div>
  );
}

function HeroManifesto() {
  // Big text block, no images. Editorial declaration.
  return (
    <section style={{ padding: 'var(--space-9) 0 var(--space-7)' }}>
      <div className="container">
        <span className="eyebrow">Manifest · 1990 → dziś</span>
        <h1 style={{
          fontFamily: 'var(--font-display)',
          fontSize: 'clamp(48px, 9vw, 132px)',
          fontWeight: 460, letterSpacing: '-0.03em', lineHeight: 0.92,
          marginTop: 32,
          textWrap: 'balance'
        }}>
          Trzydzieści <em style={{ color: 'var(--brand)', fontStyle: 'italic', fontWeight: 380 }}>pięć</em> lat wybierania
          farby <em style={{ color: 'var(--brand)', fontStyle: 'italic', fontWeight: 380 }}>za</em> kogoś, kto nie ma
          na to czasu, oczu, ani cierpliwości. <em style={{ color: 'var(--brand)', fontStyle: 'italic', fontWeight: 380 }}>I</em> jeszcze nigdy nie pomylili­śmy się dwa razy
          w tej samej sprawie.
        </h1>
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)',
          gap: 'var(--space-7)', marginTop: 'var(--space-8)',
          paddingTop: 'var(--space-6)', borderTop: 'var(--hairline)'
        }}>
          {[
            { n: '01', t: 'Bez pośpiechu', d: 'Spotkanie z doradcą trwa tyle, ile potrzeba — nie tyle, ile starczy w grafiku.' },
            { n: '02', t: 'Bez kompromisów', d: 'Polecamy tylko to, co sami przemalowaliśmy. Tikkurila, Beckers, Teknos — sprawdzone.' },
            { n: '03', t: 'Bez bajek', d: 'Jeśli farba nie nadaje się do Twojej łazienki, mówimy to wprost. Także o cenie.' },
          ].map(c => (
            <div key={c.n}>
              <div className="text-mono text-3" style={{ fontSize: 11, letterSpacing: '0.16em', marginBottom: 12 }}>{c.n}</div>
              <h3 style={{ fontSize: 22, marginBottom: 10 }}>{c.t}</h3>
              <p className="text-2" style={{ fontSize: 14, lineHeight: 1.55 }}>{c.d}</p>
            </div>
          ))}
        </div>
        <div style={{ display: 'flex', gap: 12, marginTop: 48, flexWrap: 'wrap' }}>
          <Link to="/katalog" className="btn btn--primary btn--lg">
            Otwórz katalog <Icon name="arrow-right" size={16}/>
          </Link>
          <Link to="/o-firmie" className="btn btn--ghost btn--lg">
            Czytaj dalej
          </Link>
        </div>
      </div>
    </section>
  );
}

function HeroProductLed() {
  // Picks 3 popular products and shows them as the hero
  const featured = PRODUCTS.filter(p => p.popular).slice(0, 3);
  return (
    <section style={{ padding: 'var(--space-9) 0 var(--space-7)' }}>
      <div className="container">
        <div style={{
          display: 'grid', gridTemplateColumns: '1.2fr 1fr', gap: 'var(--space-7)',
          alignItems: 'end', marginBottom: 48
        }}>
          <div>
            <span className="eyebrow">Polecane w tym tygodniu</span>
            <h1 className="h-display" style={{ marginTop: 16 }}>
              Co malują profesjonaliści <em>tego</em> miesiąca?
            </h1>
          </div>
          <p className="lede">
            Nie reklamy, nie afilianty — realny ranking sprzedaży z trzech naszych
            oddziałów. Aktualizowany co poniedziałek. Cena netto, bez kosmicznych marż.
          </p>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 'var(--space-5)' }}>
          {featured.map((p, i) => <FeaturedProduct key={p.id} p={p} rank={i + 1}/>)}
        </div>
        <div style={{ display: 'flex', gap: 12, marginTop: 32 }}>
          <Link to="/katalog" className="btn btn--primary btn--lg">
            Cały katalog <Icon name="arrow-right" size={16}/>
          </Link>
        </div>
      </div>
    </section>
  );
}

function FeaturedProduct({ p, rank }) {
  const swatch = RAL_COLORS.find(c => c.ral === p.ral) || RAL_COLORS[0];
  return (
    <article className="card" style={{ padding: 0, overflow: 'hidden' }}>
      <div style={{
        aspectRatio: '4/3', background: swatch.hex, position: 'relative',
        display: 'grid', placeItems: 'center'
      }}>
        <div style={{
          width: '52%', aspectRatio: '3/4',
          background: 'linear-gradient(180deg, rgba(255,255,255,0.18), rgba(0,0,0,0.18))',
          borderRadius: '8px 8px 4px 4px',
          boxShadow: '0 30px 60px -20px rgba(0,0,0,0.4), inset 0 0 0 1px rgba(255,255,255,0.2)',
          position: 'relative',
        }}>
          <div style={{
            position: 'absolute', left: '50%', top: '14%', transform: 'translateX(-50%)',
            width: '70%', aspectRatio: '4/3', background: '#faf7f2', borderRadius: 4,
            display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
            color: '#14110d', textAlign: 'center', padding: 8, gap: 4,
          }}>
            <span style={{ fontFamily: 'var(--font-display)', fontSize: 14, fontWeight: 500 }}>{p.brand}</span>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: 9, letterSpacing: '0.1em' }}>RAL {p.ral}</span>
          </div>
        </div>
        <span style={{
          position: 'absolute', top: 14, left: 14,
          padding: '6px 10px', borderRadius: 999, background: 'rgba(255,255,255,0.92)',
          fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.1em',
          color: '#14110d', fontWeight: 600
        }}>#{String(rank).padStart(2, '0')} TOP</span>
      </div>
      <div style={{ padding: 'var(--space-5)' }}>
        <div className="text-mono text-3" style={{ fontSize: 10, letterSpacing: '0.16em', marginBottom: 6 }}>
          {p.brand.toUpperCase()} · {p.subcat.toUpperCase()}
        </div>
        <h3 style={{ fontSize: 22, marginBottom: 6 }}>{p.name}</h3>
        <p className="text-2" style={{ fontSize: 13 }}>{p.subtitle}</p>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginTop: 16 }}>
          <span style={{ fontFamily: 'var(--font-display)', fontSize: 24, fontWeight: 500 }}>
            od {p.price} zł
          </span>
          <span className="text-mono text-3" style={{ fontSize: 11 }}>{p.coverage}</span>
        </div>
      </div>
    </article>
  );
}

// ============= BRAND MARQUEE =============
function BrandMarquee() {
  const items = [...PARTNERS, ...PARTNERS]; // duplicate for seamless loop
  return (
    <section className="marquee-band" aria-label="Nasi partnerzy">
      <div className="marquee marquee--paused">
        {items.map((p, i) => (
          <span key={i} style={{
            fontFamily: 'var(--font-display)', fontSize: 36, fontWeight: 460,
            letterSpacing: '-0.02em', color: 'var(--ink-3)',
            display: 'inline-flex', alignItems: 'center', gap: 48, whiteSpace: 'nowrap'
          }}>
            {p.name}
            <span style={{ width: 6, height: 6, borderRadius: 999, background: 'var(--brand)' }}/>
          </span>
        ))}
      </div>
      <style>{`
        .marquee-band {
          padding: var(--space-6) 0;
          border-bottom: var(--hairline);
          overflow: hidden;
          position: relative;
          background: var(--bg);
        }
        .marquee-band::before, .marquee-band::after {
          content: ''; position: absolute; top: 0; bottom: 0; width: 80px; z-index: 1;
          pointer-events: none;
        }
        .marquee-band::before { left: 0; background: linear-gradient(90deg, var(--bg), transparent); }
        .marquee-band::after { right: 0; background: linear-gradient(270deg, var(--bg), transparent); }
      `}</style>
    </section>
  );
}

// ============= PALETTE OS =============
// A novel "color OS" pane that lets the user pick an RAL family,
// browse sub-swatches, and see suggested products.
function SectionPalette() {
  const [family, setFamily] = useState('blue');
  const colors = useMemo(() => RAL_COLORS.filter(c => c.family === family), [family]);
  const featured = colors[0] || RAL_COLORS[0];
  const matchingProducts = useMemo(
    () => PRODUCTS.filter(p => p.ral === featured.ral).concat(PRODUCTS.slice(0, 2)).slice(0, 3),
    [featured.ral]
  );

  return (
    <section className="section">
      <div className="container">
        <div className="palette-head">
          <div>
            <span className="eyebrow">Wzornik RAL</span>
            <h2 className="h-section" style={{ marginTop: 16 }}>
              Otwórz paletę,<br/>znajdź <em>swój</em> ton.
            </h2>
          </div>
          <p className="lede">
            Kliknij rodzinę kolorów — wzornik rozsunie się i pokaże dostępne odcienie
            wraz z gotowymi produktami z magazynu. Każdy z 1850 standardów RAL
            zmieszamy na poczekaniu.
          </p>
        </div>

        <div className="palette-os">
          <aside className="palette-os__families">
            {RAL_FAMILIES.map(f => (
              <button key={f.id}
                className={'palette-os__fam' + (f.id === family ? ' is-active' : '')}
                onClick={() => setFamily(f.id)}>
                <span className="swatch" style={{ background: f.hex, width: 24, height: 24 }}/>
                <span>{f.label}</span>
                <span className="text-mono text-3" style={{ marginLeft: 'auto', fontSize: 11 }}>
                  {RAL_COLORS.filter(c => c.family === f.id).length}
                </span>
              </button>
            ))}
          </aside>

          <div className="palette-os__feature">
            <div className="palette-os__big" style={{ background: featured.hex }}>
              <div className="palette-os__meta">
                <span className="text-mono" style={{ fontSize: 12, letterSpacing: '0.12em' }}>RAL {featured.ral}</span>
                <h3 style={{ color: 'inherit', fontSize: 36, lineHeight: 1.05, marginTop: 6 }}>{featured.name}</h3>
                <span className="text-mono" style={{ fontSize: 11, opacity: 0.75 }}>{featured.hex.toUpperCase()}</span>
              </div>
            </div>
            <div className="palette-os__strip">
              {colors.map(c => (
                <div key={c.ral} className="palette-os__chip" style={{ background: c.hex }}>
                  <span>{c.ral}</span>
                </div>
              ))}
            </div>
          </div>

          <aside className="palette-os__products">
            <div className="text-mono text-3" style={{
              fontSize: 11, letterSpacing: '0.16em', textTransform: 'uppercase', marginBottom: 16
            }}>Pasujące produkty</div>
            {matchingProducts.map(p => (
              <a key={p.id} href="#/katalog" className="palette-os__prod">
                <span className="swatch" style={{
                  background: (RAL_COLORS.find(c => c.ral === p.ral) || {}).hex,
                  width: 44, height: 44, borderRadius: 8, flex: '0 0 44px'
                }}/>
                <span style={{ flex: 1, minWidth: 0 }}>
                  <span style={{ display: 'block', fontWeight: 600, fontSize: 14 }}>{p.brand} {p.name}</span>
                  <span className="text-3" style={{ fontSize: 12, display: 'block' }}>{p.subtitle}</span>
                </span>
                <span style={{ fontFamily: 'var(--font-mono)', fontSize: 12 }}>{p.price} zł</span>
              </a>
            ))}
            <Link to="/katalog" className="btn btn--ghost btn--sm" style={{ marginTop: 16 }}>
              Wszystkie pasujące <Icon name="arrow-right" size={12}/>
            </Link>
          </aside>
        </div>
      </div>

      <style>{`
        .palette-head {
          display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--space-7);
          align-items: end; margin-bottom: var(--space-7);
        }
        .palette-os {
          display: grid;
          grid-template-columns: 240px 1fr 280px;
          gap: var(--space-5);
          background: var(--bg-elev);
          border: var(--hairline);
          border-radius: var(--r-xl);
          padding: var(--space-5);
          box-shadow: var(--sh-2);
        }
        .palette-os__families {
          display: flex; flex-direction: column; gap: 4px;
          padding-right: var(--space-4);
          border-right: var(--hairline);
        }
        .palette-os__fam {
          display: flex; align-items: center; gap: 12px;
          padding: 10px 12px;
          border: 0; background: transparent;
          border-radius: var(--r-md);
          font-size: 14px; font-weight: 500; color: var(--ink-2);
          text-align: left; transition: 160ms ease;
        }
        .palette-os__fam:hover { background: var(--bg-tint); color: var(--ink); }
        .palette-os__fam.is-active { background: var(--ink); color: var(--bg); }
        .palette-os__fam.is-active .text-3 { color: rgba(255,255,255,0.6); }
        .palette-os__feature {
          display: flex; flex-direction: column; gap: var(--space-3);
        }
        .palette-os__big {
          aspect-ratio: 16/10; border-radius: var(--r-lg); position: relative;
          padding: 28px;
        }
        .palette-os__meta { color: #fff; mix-blend-mode: difference; }
        .palette-os__strip {
          display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
          gap: 6px;
        }
        .palette-os__chip {
          aspect-ratio: 1; border-radius: 8px; position: relative;
          box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
          cursor: pointer; transition: transform 160ms ease;
          display: flex; align-items: end; justify-content: center; padding: 4px;
        }
        .palette-os__chip:hover { transform: translateY(-2px) scale(1.05); z-index: 1; }
        .palette-os__chip span {
          font-family: var(--font-mono); font-size: 9px; color: rgba(255,255,255,0.85);
          mix-blend-mode: difference; letter-spacing: 0.04em;
        }
        .palette-os__products {
          padding-left: var(--space-4);
          border-left: var(--hairline);
          display: flex; flex-direction: column;
        }
        .palette-os__prod {
          display: flex; align-items: center; gap: 12px;
          padding: 12px 0; border-bottom: var(--hairline);
        }
        .palette-os__prod:last-of-type { border-bottom: 0; }
        .palette-os__prod:hover { color: var(--brand); }
        @media (max-width: 1100px) {
          .palette-os { grid-template-columns: 200px 1fr; }
          .palette-os__products {
            grid-column: 1 / -1; padding-left: 0; border-left: 0;
            padding-top: var(--space-4); border-top: var(--hairline);
          }
        }
        @media (max-width: 720px) {
          .palette-head { grid-template-columns: 1fr; }
          .palette-os { grid-template-columns: 1fr; }
          .palette-os__families {
            flex-direction: row; flex-wrap: wrap;
            border-right: 0; border-bottom: var(--hairline);
            padding-right: 0; padding-bottom: var(--space-4);
          }
        }
      `}</style>
    </section>
  );
}

// ============= CATEGORIES =============
function SectionCategories() {
  return (
    <section className="section section--tight" style={{ background: 'var(--bg-tint)' }}>
      <div className="container">
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'end',
          marginBottom: 'var(--space-6)', flexWrap: 'wrap', gap: 24 }}>
          <div>
            <span className="eyebrow">Cztery filary asortymentu</span>
            <h2 className="h-section" style={{ marginTop: 16 }}>Sklep w czterech aktach.</h2>
          </div>
          <Link to="/katalog" className="btn btn--ghost">
            Zobacz pełny katalog <Icon name="arrow-right" size={14}/>
          </Link>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16 }}>
          {CATEGORIES.map((c, i) => <CategoryCard key={c.id} c={c} idx={i}/>)}
        </div>
      </div>
      <style>{`
        @media (max-width: 980px) {
          .section [style*="grid-template-columns: repeat(4, 1fr)"] {
            grid-template-columns: repeat(2, 1fr) !important;
          }
        }
      `}</style>
    </section>
  );
}

function CategoryCard({ c, idx }) {
  const numbers = ['I', 'II', 'III', 'IV'];
  return (
    <Link to={'/katalog#' + c.id} className="cat-card">
      <div className="cat-card__top">
        <span style={{
          fontFamily: 'var(--font-display)', fontSize: 36, fontWeight: 470,
          fontStyle: 'italic', color: c.accent, lineHeight: 1
        }}>{numbers[idx]}</span>
        <span className="text-mono text-3" style={{ fontSize: 11, letterSpacing: '0.12em' }}>
          {c.count} pozycji
        </span>
      </div>
      <div style={{
        height: 100, borderRadius: 12, background: c.accent, opacity: 0.18,
        marginBlock: 16, position: 'relative'
      }}>
        <Icon name={c.icon} size={48} stroke={1.2}
          style={{ position: 'absolute', right: 16, bottom: 16, color: c.accent }}/>
      </div>
      <h3 style={{ fontSize: 22, marginBottom: 6 }}>{c.title}</h3>
      <p className="text-3" style={{ fontSize: 13, marginBottom: 16 }}>{c.subtitle}</p>
      <span className="text-mono" style={{ fontSize: 11, letterSpacing: '0.12em',
        color: c.accent, display: 'inline-flex', alignItems: 'center', gap: 6 }}>
        OTWÓRZ <Icon name="arrow-right" size={12}/>
      </span>
      <style>{`
        .cat-card {
          display: block;
          background: var(--bg-elev);
          border: var(--hairline);
          border-radius: var(--r-lg);
          padding: 24px;
          transition: 240ms ease;
        }
        .cat-card:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
        .cat-card__top { display: flex; justify-content: space-between; align-items: start; }
      `}</style>
    </Link>
  );
}

// ============= POPULAR PRODUCTS =============
function SectionPopular() {
  const [tab, setTab] = useState('all');
  const tabs = [
    { id: 'all', label: 'Wszystkie' },
    { id: 'dekoracyjne', label: 'Dekoracyjne' },
    { id: 'przemyslowe', label: 'Przemysłowe' },
    { id: 'tynki', label: 'Tynki' },
  ];
  const items = useMemo(() => {
    let list = PRODUCTS;
    if (tab !== 'all') list = list.filter(p => p.category === tab);
    return list.slice(0, 6);
  }, [tab]);

  return (
    <section className="section">
      <div className="container">
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'end',
          marginBottom: 'var(--space-6)', flexWrap: 'wrap', gap: 24 }}>
          <div>
            <span className="eyebrow">Bestsellery · 2025/Q4</span>
            <h2 className="h-section" style={{ marginTop: 16 }}>Co się <em>najczęściej</em> sprzedaje.</h2>
          </div>
          <div className="tabs">
            {tabs.map(t => (
              <button key={t.id}
                className={'tabs__btn' + (tab === t.id ? ' is-active' : '')}
                onClick={() => setTab(t.id)}>{t.label}</button>
            ))}
          </div>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 'var(--space-5)' }}>
          {items.map(p => <ProductCard key={p.id} p={p}/>)}
        </div>
      </div>
      <style>{`
        .tabs { display: inline-flex; padding: 4px; background: var(--bg-tint); border-radius: 999px; gap: 2px; }
        .tabs__btn {
          padding: 8px 14px; font-size: 13px; font-weight: 500;
          border: 0; background: transparent; border-radius: 999px; color: var(--ink-3);
          transition: 160ms ease;
        }
        .tabs__btn:hover { color: var(--ink); }
        .tabs__btn.is-active { background: var(--bg-elev); color: var(--ink); box-shadow: var(--sh-1); }
        @media (max-width: 980px) {
          .section [style*="grid-template-columns: repeat(3, 1fr)"] {
            grid-template-columns: repeat(2, 1fr) !important;
          }
        }
        @media (max-width: 600px) {
          .section [style*="grid-template-columns: repeat(3, 1fr)"] {
            grid-template-columns: 1fr !important;
          }
        }
      `}</style>
    </section>
  );
}

function ProductCard({ p }) {
  const swatch = RAL_COLORS.find(c => c.ral === p.ral) || RAL_COLORS[0];
  return (
    <Link to={'/katalog?id=' + p.id} className="prod-card">
      <div className="prod-card__media" style={{ background: swatch.hex }}>
        <div className="prod-card__can">
          <span style={{ fontFamily: 'var(--font-display)', fontSize: 13, fontWeight: 500 }}>{p.brand}</span>
        </div>
        {p.popular && <span className="prod-card__badge">BESTSELLER</span>}
      </div>
      <div className="prod-card__body">
        <div className="text-mono text-3" style={{ fontSize: 10, letterSpacing: '0.16em', marginBottom: 6 }}>
          {p.brand.toUpperCase()} · {p.subcat.toUpperCase()}
        </div>
        <h3 style={{ fontSize: 19, marginBottom: 4 }}>{p.name}</h3>
        <p className="text-2" style={{ fontSize: 13, marginBottom: 16 }}>{p.subtitle}</p>
        <div className="prod-card__meta">
          <span className="chip">{p.finish}</span>
          <span className="chip">{p.coverage}</span>
          <span className="chip">{p.sizes.join(' / ')}</span>
        </div>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline',
          marginTop: 16, paddingTop: 16, borderTop: 'var(--hairline)' }}>
          <span style={{ fontFamily: 'var(--font-display)', fontSize: 26, fontWeight: 500 }}>
            od {p.price} <span style={{ fontSize: 14, color: 'var(--ink-3)' }}>zł</span>
          </span>
          <span style={{
            width: 40, height: 40, borderRadius: 999, background: 'var(--ink)', color: 'var(--bg)',
            display: 'inline-flex', alignItems: 'center', justifyContent: 'center'
          }}>
            <Icon name="arrow-right" size={14}/>
          </span>
        </div>
      </div>
      <style>{`
        .prod-card {
          display: block;
          background: var(--bg-elev);
          border: var(--hairline);
          border-radius: var(--r-lg);
          overflow: hidden;
          transition: 240ms ease;
        }
        .prod-card:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
        .prod-card__media {
          aspect-ratio: 16/10; position: relative;
          display: grid; place-items: center;
        }
        .prod-card__can {
          width: 90px; height: 110px;
          background: linear-gradient(180deg, rgba(255,255,255,0.18), rgba(0,0,0,0.18));
          border-radius: 4px;
          box-shadow: 0 16px 32px -10px rgba(0,0,0,0.3), inset 0 0 0 1px rgba(255,255,255,0.2);
          display: grid; place-items: center;
          color: #fff; mix-blend-mode: difference;
        }
        .prod-card__badge {
          position: absolute; top: 14px; left: 14px;
          padding: 4px 10px; background: var(--accent); color: #fff;
          font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em;
          border-radius: 4px; font-weight: 600;
        }
        .prod-card__body { padding: 22px; }
        .prod-card__meta { display: flex; gap: 6px; flex-wrap: wrap; }
      `}</style>
    </Link>
  );
}

// ============= SERVICES =============
function SectionServices() {
  const services = [
    { icon: 'palette', title: 'Mieszalnik na poczekaniu', desc: 'Każdy odcień RAL, NCS, Tikkurila Symphony lub własna próbka — ważymy w 8 minut.', stat: '8 min', statLabel: 'średni czas' },
    { icon: 'truck',   title: 'Dostawa pod budowę', desc: 'Trzy busy w trasie, dowóz tego samego dnia w obrębie 30 km — bez minimum.', stat: '48h', statLabel: 'maks. termin' },
    { icon: 'users',   title: 'Doradca dedykowany B2B', desc: 'Stała osoba do kontaktu, indywidualny cennik, fakturowanie z odroczeniem 14 dni.', stat: '14 dni', statLabel: 'termin płatności' },
    { icon: 'shield-check', title: 'Gwarancja zwrotu', desc: 'Nie pasuje kolor? Wymieniamy lub zwracamy w ciągu 30 dni — bez paragonów.', stat: '30 dni', statLabel: 'pełen zwrot' },
  ];
  return (
    <section className="section">
      <div className="container">
        <div style={{ marginBottom: 'var(--space-6)' }}>
          <span className="eyebrow">Co dostajesz oprócz wiadra</span>
          <h2 className="h-section" style={{ marginTop: 16, maxWidth: '20ch' }}>
            Sprzedajemy farbę.<br/>Dostarczamy <em>spokój</em>.
          </h2>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 16 }}>
          {services.map((s, i) => (
            <div key={i} className="service-row">
              <div className="service-row__icon">
                <Icon name={s.icon} size={28} stroke={1.4}/>
              </div>
              <div>
                <h3 style={{ fontSize: 22, marginBottom: 6 }}>{s.title}</h3>
                <p className="text-2" style={{ fontSize: 14, lineHeight: 1.55, maxWidth: '46ch' }}>{s.desc}</p>
              </div>
              <div style={{ textAlign: 'right' }}>
                <div style={{ fontFamily: 'var(--font-display)', fontSize: 36, fontWeight: 470,
                  color: 'var(--brand)', lineHeight: 1, fontStyle: 'italic' }}>{s.stat}</div>
                <div className="text-mono text-3" style={{ fontSize: 10, letterSpacing: '0.12em',
                  textTransform: 'uppercase', marginTop: 4 }}>{s.statLabel}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
      <style>{`
        .service-row {
          display: grid; grid-template-columns: 64px 1fr auto;
          gap: var(--space-4); align-items: center;
          padding: var(--space-5);
          background: var(--bg-elev);
          border: var(--hairline);
          border-radius: var(--r-lg);
        }
        .service-row__icon {
          width: 56px; height: 56px;
          background: var(--brand-soft); color: var(--brand);
          border-radius: var(--r-md);
          display: grid; place-items: center;
        }
        @media (max-width: 720px) {
          .service-row { grid-template-columns: 48px 1fr; }
          .service-row > div:last-child { grid-column: 1 / -1; text-align: left; }
        }
      `}</style>
    </section>
  );
}

// ============= BRANCHES =============
function SectionBranches() {
  return (
    <section className="section section--tight">
      <div className="container">
        <div style={{ marginBottom: 'var(--space-6)' }}>
          <span className="eyebrow">Trzy oddziały · jedno mieszanie</span>
          <h2 className="h-section" style={{ marginTop: 16 }}>Gdzie nas znaleźć?</h2>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16 }}>
          {BRANCHES.map(b => <BranchCard key={b.id} b={b}/>)}
        </div>
      </div>
      <style>{`
        @media (max-width: 980px) {
          .section [style*="grid-template-columns: repeat(3, 1fr)"][style*="gap: 16"] {
            grid-template-columns: 1fr !important;
          }
        }
      `}</style>
    </section>
  );
}

function BranchCard({ b }) {
  return (
    <article className="branch-card">
      <div className="branch-card__head">
        <span className="chip chip--solid">{b.role}</span>
        <span className="text-mono text-3" style={{ fontSize: 11 }}>
          <span style={{ display: 'inline-block', width: 8, height: 8, borderRadius: 999,
            background: '#3da564', marginRight: 6, verticalAlign: 1 }}/>
          OTWARTE
        </span>
      </div>
      <h3 style={{ fontSize: 28, marginTop: 16 }}>{b.name}</h3>
      <p className="text-3" style={{ fontSize: 14, marginTop: 8 }}>{b.note}</p>
      <hr className="divider" style={{ marginBlock: 20 }}/>
      <ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex',
        flexDirection: 'column', gap: 12 }}>
        <li style={{ display: 'flex', gap: 10 }}>
          <Icon name="pin" size={16} stroke={1.6} style={{ marginTop: 2, color: 'var(--brand)' }}/>
          <span style={{ fontSize: 14 }}>{b.address}</span>
        </li>
        <li style={{ display: 'flex', gap: 10 }}>
          <Icon name="phone" size={16} stroke={1.6} style={{ marginTop: 2, color: 'var(--brand)' }}/>
          <a href={b.phoneHref} style={{ fontSize: 14, fontWeight: 600 }}>{b.phone}</a>
        </li>
        <li style={{ display: 'flex', gap: 10 }}>
          <Icon name="clock" size={16} stroke={1.6} style={{ marginTop: 2, color: 'var(--brand)' }}/>
          <span style={{ fontSize: 14 }}>
            {b.weekdays}<br/>
            <span className="text-3">{b.saturday}</span>
          </span>
        </li>
      </ul>
      <style>{`
        .branch-card {
          background: var(--bg-elev);
          border: var(--hairline);
          border-radius: var(--r-lg);
          padding: var(--space-5);
          transition: 200ms ease;
        }
        .branch-card:hover { box-shadow: var(--sh-2); transform: translateY(-2px); }
        .branch-card__head { display: flex; justify-content: space-between; align-items: center; }
      `}</style>
    </article>
  );
}

// ============= TESTIMONIALS =============
function SectionTestimonials() {
  const [idx, setIdx] = useState(0);
  const t = TESTIMONIALS[idx];
  return (
    <section className="section" style={{ background: 'var(--ink)', color: 'var(--bg)', position: 'relative' }}>
      <div className="container">
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'end',
          marginBottom: 48, flexWrap: 'wrap', gap: 24 }}>
          <div>
            <span className="eyebrow" style={{ color: 'rgba(255,255,255,0.6)' }}>Opinie · 4.9 / 5</span>
            <h2 className="h-section" style={{ marginTop: 16, color: '#fff' }}>
              Wspierają nas <em style={{ color: 'var(--accent)' }}>od lat</em>.
            </h2>
          </div>
          <div style={{ display: 'flex', gap: 8 }}>
            <button className="btn btn--ghost" style={{ borderColor: 'rgba(255,255,255,0.2)', color: '#fff', padding: 12 }}
              onClick={() => setIdx((idx - 1 + TESTIMONIALS.length) % TESTIMONIALS.length)}>
              <Icon name="chevron-left" size={16}/>
            </button>
            <button className="btn btn--ghost" style={{ borderColor: 'rgba(255,255,255,0.2)', color: '#fff', padding: 12 }}
              onClick={() => setIdx((idx + 1) % TESTIMONIALS.length)}>
              <Icon name="chevron-right" size={16}/>
            </button>
          </div>
        </div>
        <div style={{
          display: 'grid', gridTemplateColumns: '1.6fr 1fr',
          gap: 'var(--space-7)', alignItems: 'start'
        }}>
          <blockquote style={{
            margin: 0, fontFamily: 'var(--font-display)',
            fontSize: 'clamp(28px, 4vw, 44px)', fontWeight: 460,
            letterSpacing: '-0.02em', lineHeight: 1.15,
            textWrap: 'balance'
          }}>
            <span style={{ color: 'var(--accent)' }}>“</span>
            {t.text}
            <span style={{ color: 'var(--accent)' }}>”</span>
          </blockquote>
          <div>
            <div style={{ display: 'flex', gap: 4, marginBottom: 16 }}>
              {Array.from({ length: 5 }).map((_, i) => (
                <Icon key={i} name="star" size={16} style={{ color: 'var(--accent)' }}/>
              ))}
            </div>
            <div style={{ fontFamily: 'var(--font-display)', fontSize: 24, fontWeight: 500 }}>
              {t.name}
            </div>
            <div style={{ color: 'rgba(255,255,255,0.7)', fontSize: 14 }}>{t.role}</div>
            <div className="text-mono" style={{ fontSize: 11, letterSpacing: '0.12em',
              color: 'rgba(255,255,255,0.5)', marginTop: 12, textTransform: 'uppercase' }}>
              Projekt: {t.project}
            </div>
            <div style={{ display: 'flex', gap: 6, marginTop: 28 }}>
              {TESTIMONIALS.map((_, i) => (
                <button key={i} onClick={() => setIdx(i)} aria-label={'Opinia ' + (i + 1)}
                  style={{
                    width: i === idx ? 32 : 8, height: 8,
                    borderRadius: 999, border: 0,
                    background: i === idx ? 'var(--accent)' : 'rgba(255,255,255,0.2)',
                    transition: '200ms ease'
                  }}/>
              ))}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============= CTA =============
function SectionCTA() {
  return (
    <section className="section">
      <div className="container">
        <div className="big-cta">
          <span className="eyebrow">Następny krok</span>
          <h2 style={{
            fontFamily: 'var(--font-display)', fontSize: 'clamp(40px, 6vw, 80px)',
            fontWeight: 470, letterSpacing: '-0.025em', lineHeight: 0.98,
            marginTop: 24
          }}>
            Wpadnij na kawę<br/>
            i <em style={{ color: 'var(--brand)', fontStyle: 'italic', fontWeight: 380 }}>próbnik</em> koloru.
          </h2>
          <p className="lede" style={{ marginTop: 20, maxWidth: '52ch' }}>
            Salon przy Os. Słonecznym 11 w Bełchatowie ma sześć foteli, tablicę z 1850 odcieniami RAL,
            i ekspres ciśnieniowy. Doradca odpowie na pytania, których nie wiesz, że masz.
          </p>
          <div style={{ display: 'flex', gap: 12, marginTop: 32, flexWrap: 'wrap' }}>
            <Link to="/kontakt" className="btn btn--primary btn--lg">
              Umów wizytę <Icon name="arrow-right" size={16}/>
            </Link>
            <a href="tel:+48502263652" className="btn btn--ghost btn--lg">
              <Icon name="phone" size={16}/> 502 263 652
            </a>
          </div>
        </div>
      </div>
      <style>{`
        .big-cta {
          background: var(--bg-tint);
          border: var(--hairline);
          border-radius: var(--r-2xl);
          padding: clamp(40px, 6vw, 96px);
          position: relative; overflow: hidden;
        }
        .big-cta::before {
          content: ''; position: absolute; right: -80px; top: -80px;
          width: 320px; height: 320px; border-radius: 50%;
          background: radial-gradient(circle at center, var(--brand) 0%, transparent 60%);
          opacity: 0.15; pointer-events: none;
        }
      `}</style>
    </section>
  );
}

window.PageHome = PageHome;
