/* ============================================
   JAK PRACUJEME - apple-style horizontal cards
   ============================================ */
function Realizations() {
  const mobile = useIsMobile();
  const [active, setActive] = React.useState(0);
  const [viewportWidth, setViewportWidth] = React.useState(window.innerWidth);
  const [card0Zoomed, setCard0Zoomed] = React.useState(false);
  const sectionRef = React.useRef(null);
  const carouselRef = React.useRef(null);
  const trackRef = React.useRef(null);
  const card0ImgRef = React.useRef(null);
  const videoRefs = React.useRef({});
  const videoPlayedRef = React.useRef({});
  const [videoEndedSet, setVideoEndedSet] = React.useState(new Set());
  const [cardAutoPlay, setCardAutoPlay] = React.useState(false);
  const [cardProgress, setCardProgress] = React.useState(0);
  const cardAutoPlayRef = React.useRef(false);
  const cardProgressRef = React.useRef(null);
  const cardActiveRef = React.useRef(0);
  const CARD_DURATION = 7000;

  const cards = [
    {
      eyebrow: 'Váš designer',
      title: 'Návrh od profíka, který naslouchá.',
      text: 'Naši designéři neskládají katalogové krabice. Společně s vámi vymyslí ergonomické a chytré řešení na míru vašemu vkusu a rozpočtu.',
      image: 'images/imagove-4.jpg',
      fullBleed: true,
      bg: '#a6705a',
      ink: '#ffffff',
      boldFirst: true,
    },
    {
      eyebrow: 'Premium partner Gorenje',
      title: 'Přes 30 let zkušeností.',
      text: 'Jako smluvní partner Gorenje stavíme na dekádami ověřené kvalitě, precizním plánování a jistotě, že tu pro vás budeme i za deset let.',
      image: 'images/namiru_3.webp',
      fullBleed: true,
      bg: '#898672',
      ink: '#ffffff',
      gorenje: true,
      boldFirst: true,
    },
    {
      eyebrow: 'Doba realizace',
      title: 'Nová kuchyně už za 7 až 12 týdnů.',
      text: 'Díky efektivnímu plánování a přímé vazbě na výrobu držíme slovo i termíny. Používáme prémiové materiály, které vydrží dekády provozu.',
      video: 'images/namiru_vid1.mp4',
      fullBleed: true,
      bg: '#b99884',
      ink: '#ffffff',
      boldFirst: true,
    },
    {
      eyebrow: 'Výroba a montáž',
      title: 'Montáž bez chyb a reklamací.',
      text: 'Naši zkušení řemeslníci si poradí s každým detailem i nerovností stěn. Kuchyni předáváme kompletně čistou, seřízenou a plně funkční.',
      image: 'images/namiru_7.webp',
      fullBleed: true,
      bg: '#EEF3EA',
      ink: '#ffffff',
      dark: true,
      boldFirst: true,
    },
    {
      eyebrow: 'Letní akce',
      title: 'Využijte aktuální nabídku a pořiďte si vysněnou kuchyni za výhodnější cenu.',
      text: 'Začněte 3D návrhem zdarma.',
      boldLast: true,
      bg: '#a6192e',
      ink: '#ffffff',
      promo: true,
    },
  ];

  const scrollToCard = (index, stopAutoPlay = true) => {
    if (stopAutoPlay) {
      cardAutoPlayRef.current = false;
      setCardAutoPlay(false);
      if (cardProgressRef.current) cancelAnimationFrame(cardProgressRef.current);
      setCardProgress(0);
    }
    cardActiveRef.current = index;
    setActive(index);
    if (!trackRef.current) return;
    const card = trackRef.current.querySelector(`[data-card-index="${index}"]`);
    if (card) {
      const sidePadding = Math.max(20, (trackRef.current.clientWidth - card.getBoundingClientRect().width) / 2);
      trackRef.current.scrollTo({
        left: card.offsetLeft - sidePadding,
        behavior: 'smooth',
      });
    }
  };

  const next = () => scrollToCard(Math.min(cards.length - 1, active + 1));
  const prev = () => scrollToCard(Math.max(0, active - 1));

  const startCardProgress = React.useCallback(() => {
    let start = null;
    const animate = (ts) => {
      if (!cardAutoPlayRef.current) return;
      if (!start) start = ts;
      const elapsed = ts - start;
      const pct = Math.min(elapsed / CARD_DURATION, 1);
      setCardProgress(pct);
      if (pct < 1) {
        cardProgressRef.current = requestAnimationFrame(animate);
      } else {
        const next = cardActiveRef.current + 1;
        if (next >= cards.length) {
          cardAutoPlayRef.current = false;
          setCardAutoPlay(false);
          setCardProgress(0);
          return;
        }
        scrollToCard(next, false);
        setCardProgress(0);
        start = null;
        cardProgressRef.current = requestAnimationFrame(animate);
      }
    };
    cardProgressRef.current = requestAnimationFrame(animate);
  }, []);

  React.useEffect(() => {
    const track = trackRef.current;
    if (!track) return;

    const onScroll = () => {
      const cardNodes = Array.from(track.querySelectorAll('[data-card-index]'));
      const center = track.scrollLeft + track.clientWidth / 2;
      let closest = 0;
      let closestDistance = Infinity;
      cardNodes.forEach((card) => {
        const distance = Math.abs(card.offsetLeft + card.getBoundingClientRect().width / 2 - center);
        if (distance < closestDistance) {
          closestDistance = distance;
          closest = Number(card.dataset.cardIndex);
        }
      });
      setActive(closest);
    };

    track.addEventListener('scroll', onScroll, { passive: true });
    return () => track.removeEventListener('scroll', onScroll);
  }, [mobile]);

  React.useEffect(() => {
    const onResize = () => setViewportWidth(window.innerWidth);
    window.addEventListener('resize', onResize);
    return () => window.removeEventListener('resize', onResize);
  }, []);

  React.useEffect(() => {
    if (cards[active]?.video && !videoPlayedRef.current[active] && videoRefs.current[active]) {
      videoPlayedRef.current[active] = true;
      videoRefs.current[active].play();
    }
  }, [active]);

  React.useEffect(() => {
    const el = card0ImgRef.current;
    if (!el) return;
    const observer = new IntersectionObserver(
      ([entry]) => {
        if (entry.isIntersecting) {
          setCard0Zoomed(true);
          observer.disconnect();
        }
      },
      { threshold: 0.3 }
    );
    observer.observe(el);
    return () => observer.disconnect();
  }, []);

  React.useEffect(() => {
    const section = sectionRef.current;
    if (!section) return;
    const observer = new IntersectionObserver(([entry]) => {
      if (entry.isIntersecting && !cardAutoPlayRef.current) {
        cardAutoPlayRef.current = true;
        setCardAutoPlay(true);
        startCardProgress();
      }
    }, { threshold: 0.2 });
    observer.observe(section);
    return () => {
      observer.disconnect();
      cardAutoPlayRef.current = false;
      if (cardProgressRef.current) cancelAnimationFrame(cardProgressRef.current);
    };
  }, [startCardProgress]);

  const cardWidth = mobile
    ? Math.min(viewportWidth * 0.75, 320)
    : Math.min(viewportWidth * 0.47, 921);
  const sidePadding = mobile
    ? 20
    : Math.max(80, (viewportWidth - 1440) / 2 + 80);
  const controls = (
    <div style={{
      display: 'inline-flex',
      alignItems: 'center',
      gap: mobile ? '11px' : '13px',
      padding: mobile ? '19px 31px' : '21px 34px',
      borderRadius: '999px',
      background: 'rgba(242, 242, 242, 0.72)',
      backdropFilter: 'blur(24px) saturate(170%)',
      WebkitBackdropFilter: 'blur(24px) saturate(170%)',
    }}>
      {cards.map((card, index) => (
        active === index ? (
          /* Active dot — animated progress fill */
          <div
            key={card.eyebrow}
            onClick={() => scrollToCard(index)}
            style={{
              width: mobile ? '48px' : '58px',
              height: mobile ? '9px' : '10px',
              borderRadius: '999px',
              background: 'rgba(88,88,88,0.22)',
              overflow: 'hidden',
              cursor: 'pointer',
              flexShrink: 0,
            }}
          >
            <div style={{
              width: `${cardProgress * 100}%`,
              height: '100%',
              background: 'rgba(52,52,52,0.72)',
              borderRadius: '999px',
            }} />
          </div>
        ) : (
          <button
            key={card.eyebrow}
            onClick={() => scrollToCard(index)}
            aria-label={`Zobrazit kartu ${index + 1}`}
            style={{
              width: mobile ? '9px' : '10px',
              height: mobile ? '9px' : '10px',
              borderRadius: '999px',
              background: 'rgba(88,88,88,0.34)',
              transition: 'width 0.25s ease, background 0.25s ease',
              boxShadow: 'none',
              flexShrink: 0,
            }}
          />
        )
      ))}
    </div>
  );

  return (
    <section ref={sectionRef} id="jak-pracujeme" style={{
      padding: mobile ? '8px 0 96px' : '124px 0 132px',
      background: 'var(--bg)',
      overflow: 'visible',
    }}>
      <style>{`@keyframes promoBounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }`}</style>
      <div className="container">
        <div className="section-header" style={{ marginBottom: mobile ? '34px' : '54px', maxWidth: mobile ? undefined : '900px' }}>
          <div className="eyebrow" style={{ marginBottom: '14px' }}>Proč kuchyně od DOTu</div>
          <h2 className="display-l" style={{ marginTop: '0', fontSize: mobile ? '36px' : undefined }}>
            Kuchyně bez starostí a kompromisů
          </h2>
          <p className="body-text" style={{ marginTop: '20px', maxWidth: 'none' }}>
            Vy víte, jak chcete bydlet. My víme, jak to vyrobit, aby to <strong>vydrželo roky</strong>. Od prvního tahu tužkou designéra až po <strong>precizní montáž</strong> – u nás máte jistotu, že celý proces proběhne <strong>hladce, transparentně a bez zbytečných starostí</strong>.
          </p>
        </div>
      </div>

      <div
        ref={carouselRef}
        style={{
          position: 'relative',
          paddingBottom: mobile ? '0px' : '4px',
          marginTop: mobile ? '30px' : '0',
        }}
      >
        <div
          ref={trackRef}
          className="no-scrollbar"
          style={{
            display: 'flex',
            gap: mobile ? '16px' : '24px',
            overflowX: 'auto',
            scrollSnapType: 'x mandatory',
            scrollBehavior: 'smooth',
            paddingLeft: `${sidePadding}px`,
            paddingRight: `${sidePadding}px`,
            scrollPaddingLeft: `${sidePadding}px`,
            scrollPaddingRight: `${sidePadding}px`,
          }}
        >
          {cards.map((card, index) => (
            <div
              key={card.eyebrow}
              data-card-index={index}
              onClick={() => index !== active && scrollToCard(index)}
              style={{
                flex: `0 0 ${cardWidth}px`,
                flexShrink: 0,
                scrollSnapAlign: 'start',
                display: 'flex',
                flexDirection: 'column',
                cursor: index === active ? 'default' : 'pointer',
              }}
            >
              {/* Image / visual card — full rounded corners */}
              <article
                style={{
                  aspectRatio: mobile ? '4 / 5' : '3 / 2',
                  borderRadius: '16px',
                  background: card.promo ? '#a6192e' : card.bg,
                  color: card.ink,
                  overflow: 'hidden',
                  display: 'flex',
                  flexDirection: 'column',
                  position: 'relative',
                  flexShrink: 0,
                }}
              >
                {/* Step number */}
                {/* Promo: centered numbers + CTA inside */}
                {card.promo && (
                  <div style={{
                    flex: 1,
                    display: 'flex',
                    flexDirection: 'column',
                    alignItems: 'center',
                    justifyContent: 'center',
                    gap: mobile ? '28px' : '40px',
                    color: '#ffffff',
                    fontFamily: 'var(--sans)',
                  }}>
                    {mobile ? (
                      <div style={{ display: 'flex', flexDirection: 'column', gap: '14px', paddingLeft: '8px' }}>
                        <div style={{ display: 'flex', alignItems: 'center', gap: '14px' }}>
                          <div style={{ fontSize: '48px', fontWeight: 700, lineHeight: 1, letterSpacing: '-0.02em', minWidth: '90px' }}>30 %</div>
                          <div style={{ fontSize: '17px', fontWeight: 400, color: 'rgba(255,255,255,0.85)', lineHeight: 1.2 }}>sleva na kuchyně</div>
                        </div>
                        <div style={{ display: 'flex', alignItems: 'center', gap: '14px' }}>
                          <div style={{ fontSize: '48px', fontWeight: 700, lineHeight: 1, letterSpacing: '-0.02em', minWidth: '90px' }}>3</div>
                          <div style={{ fontSize: '17px', fontWeight: 400, color: 'rgba(255,255,255,0.85)', lineHeight: 1.2 }}>spotřebiče zdarma</div>
                        </div>
                      </div>
                    ) : (
                      <div style={{ display: 'flex', alignItems: 'center', gap: '56px' }}>
                        <div style={{ textAlign: 'center' }}>
                          <div style={{ fontSize: '100px', fontWeight: 700, lineHeight: 1, letterSpacing: '-0.02em' }}>30 %</div>
                          <div style={{ fontSize: '18px', fontWeight: 400, color: 'rgba(255,255,255,0.8)', marginTop: '8px' }}>na kuchyně na míru</div>
                        </div>
                        <div style={{ width: '1px', height: '110px', background: 'rgba(255,255,255,0.3)', flexShrink: 0 }} />
                        <div style={{ textAlign: 'center' }}>
                          <div style={{ fontSize: '100px', fontWeight: 700, lineHeight: 1, letterSpacing: '-0.02em' }}>3</div>
                          <div style={{ fontSize: '18px', fontWeight: 400, color: 'rgba(255,255,255,0.8)', marginTop: '8px' }}>spotřebiče zdarma</div>
                        </div>
                      </div>
                    )}
                    <button style={{
                      padding: mobile ? '14px 36px' : '16px 48px',
                      borderRadius: '999px',
                      background: '#ffffff',
                      border: 'none',
                      fontFamily: 'var(--sans)',
                      fontSize: mobile ? '14px' : '15px',
                      fontWeight: 600,
                      letterSpacing: '0.06em',
                      color: '#a6192e',
                      cursor: 'pointer',
                      textTransform: 'uppercase',
                      animation: 'promoBounce 2s ease-in-out infinite',
                      marginTop: '20px',
                    }} onClick={(e) => { e.stopPropagation(); window.scrollToKontakt(); }}>MÁM ZÁJEM →</button>
                  </div>
                )}

                {/* Image / Video */}
                {!card.promo && (
                  <div
                    ref={index === 0 ? card0ImgRef : null}
                    style={{
                      flex: 1,
                      position: 'relative',
                      width: '100%',
                      minHeight: 0,
                      background: card.dark ? '#1c1c1c' : 'rgba(255,255,255,0.38)',
                    }}
                  >
                    {card.video ? (
                      <>
                        <video
                          ref={el => { if (el) videoRefs.current[index] = el; }}
                          src={card.video}
                          muted
                          playsInline
                          preload="auto"
                          onEnded={() => setVideoEndedSet(prev => new Set([...prev, index]))}
                          style={{
                            width: '100%',
                            height: '100%',
                            objectFit: 'cover',
                            display: 'block',
                          }}
                        />
                        {videoEndedSet.has(index) && (
                          <button
                            onClick={(e) => {
                              e.stopPropagation();
                              setVideoEndedSet(prev => { const s = new Set(prev); s.delete(index); return s; });
                              videoRefs.current[index].currentTime = 0;
                              videoRefs.current[index].play();
                            }}
                            title="Přehrát znovu"
                            style={{
                              position: 'absolute',
                              top: '18px',
                              right: '18px',
                              zIndex: 10,
                              width: '36px',
                              height: '36px',
                              borderRadius: '50%',
                              background: 'rgba(255,255,255,0.18)',
                              border: '1px solid rgba(255,255,255,0.32)',
                              backdropFilter: 'blur(8px)',
                              WebkitBackdropFilter: 'blur(8px)',
                              display: 'flex',
                              alignItems: 'center',
                              justifyContent: 'center',
                              cursor: 'pointer',
                              color: '#ffffff',
                            }}
                          >
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
                              <path d="M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"/>
                            </svg>
                          </button>
                        )}
                      </>
                    ) : (
                      <img
                        src={card.image}
                        alt={card.eyebrow}
                        style={{
                          width: '100%',
                          height: '100%',
                          objectFit: 'cover',
                          transformOrigin: 'center center',
                          ...(index === 0 ? {
                            animation: card0Zoomed ? 'card0ZoomOut 3s cubic-bezier(0.25, 0.46, 0.45, 0.94) both' : 'none',
                          } : {}),
                        }}
                      />
                    )}
                    {!card.fullBleed && (
                      <div style={{
                        position: 'absolute',
                        inset: 0,
                        background: card.dark
                          ? 'linear-gradient(180deg, rgba(0,0,0,0) 42%, rgba(0,0,0,0.34) 100%)'
                          : 'linear-gradient(180deg, rgba(255,255,255,0) 48%, rgba(255,255,255,0.16) 100%)',
                      }} />
                    )}
                    {card.gorenje && (
                      <>
                        <div style={{
                          position: 'absolute',
                          inset: 0,
                          background: 'radial-gradient(ellipse 60% 50% at 0% 100%, rgba(0,0,0,0.45) 0%, rgba(0,0,0,0) 100%)',
                          pointerEvents: 'none',
                        }} />
                        <img
                          src="images/logogorneje_white.png"
                          alt="Gorenje"
                          style={{
                            position: 'absolute',
                            bottom: '26px',
                            left: '28px',
                            height: mobile ? '50px' : '62px',
                            width: 'auto',
                            pointerEvents: 'none',
                            userSelect: 'none',
                          }}
                        />
                      </>
                    )}
                  </div>
                )}
              </article>

              {/* Text below the image card */}
              {(card.fullBleed || card.promo) && (
                <div style={{ paddingTop: mobile ? '14px' : '20px', paddingLeft: mobile ? '0' : '10px', maxWidth: mobile ? undefined : '85%' }}>
                  <p style={{
                    fontFamily: 'var(--sans)',
                    fontSize: mobile ? '16px' : '18px',
                    lineHeight: 1.6,
                    fontWeight: 300,
                    color: 'var(--ink)',
                    margin: 0,
                  }}>
                    {(() => {
                      const full = [card.title, card.text].filter(Boolean).join(' ');
                      if (card.boldFirst) {
                        const dotIdx = full.indexOf('. ');
                        if (dotIdx === -1) return <strong>{full}</strong>;
                        return <><strong>{full.slice(0, dotIdx + 1)}</strong>{full.slice(dotIdx + 1)}</>;
                      }
                      if (card.boldLast) {
                        const dotIdx = full.lastIndexOf('. ');
                        if (dotIdx === -1) return <strong>{full}</strong>;
                        return <>{full.slice(0, dotIdx + 2)}<strong>{full.slice(dotIdx + 2)}</strong></>;
                      }
                      return full;
                    })()}
                  </p>
                </div>
              )}
              {!card.fullBleed && !card.promo && (
                <div style={{ paddingTop: mobile ? '20px' : '28px' }}>
                  <div style={{
                    fontFamily: 'var(--sans)',
                    fontSize: '11px',
                    fontWeight: 500,
                    letterSpacing: '0.18em',
                    textTransform: 'uppercase',
                    color: 'rgba(0,0,0,0.48)',
                    marginBottom: '14px',
                  }}>
                    {card.eyebrow}
                  </div>
                  <h3 style={{
                    fontFamily: 'var(--sans)',
                    fontSize: mobile ? '27px' : '34px',
                    lineHeight: 1.08,
                    fontWeight: 400,
                    letterSpacing: 0,
                    maxWidth: '620px',
                    marginBottom: 0,
                    color: 'var(--ink)',
                  }}>
                    {card.title}
                  </h3>
                </div>
              )}
            </div>
          ))}
        </div>

        <div style={{
          display: 'flex',
          justifyContent: 'center',
          marginTop: mobile ? '68px' : '46px',
        }}>
          {controls}
        </div>
      </div>
    </section>
  );
}

window.Realizations = Realizations;

/* ============================================
   KITCHEN SLIDESHOW
   ============================================ */
function KitchenSlideshow() {
  const mobile = useIsMobile();
  const trackRef = React.useRef(null);
  const animRef = React.useRef(null);
  const scrollPos = React.useRef(0);
  const isDragging = React.useRef(false);
  const dragStartX = React.useRef(0);
  const dragStartY = React.useRef(0);
  const dragStartScroll = React.useRef(0);
  const isDirectionSet = React.useRef(false);
  const [viewportW, setViewportW] = React.useState(window.innerWidth);

  React.useEffect(() => {
    const onResize = () => setViewportW(window.innerWidth);
    window.addEventListener('resize', onResize);
    return () => window.removeEventListener('resize', onResize);
  }, []);

  const images = [
    '000e5b8cea114e90b9c418fd348895b3',
    '0d56726e2aee49d79903b5d04aa1eefa',
    '1a57c8e8406340a3a6ce83d908b92c90',
    '291390cc3d7b4ce09651e1a98f18750f',
    '2b9d638143a740a4b351b9df0710d9c8',
    '55c247452ceb46b3b327b1d7092b15a6',
    '65a9bb3bdfe14caaa3493b630bb77254',
    '756a1bc85132416e9c68d80d115ee4d1',
    'a6bdac0366fd4f6fa010351b0ceaa178',
    'bb4bf1a24709493b9b7ba55c9b180702',
    'd0417ebe70d1433fba9591e0c725a0db',
    'dfe0ca918774419d889cb07dfad1ce2d',
    'ec95f703df114cd188a2b52da6d31c6a',
    'fca9f33e90394865a808cbe21b02e23a',
  ];
  const allImages = [...images, ...images, ...images];

  const imgW = mobile ? 206 : 308;
  const gap  = mobile ? 50  : 70;

  React.useEffect(() => {
    const track = trackRef.current;
    if (!track) return;

    const singleSetW = images.length * (imgW + gap);
    scrollPos.current = singleSetW;
    track.scrollLeft  = singleSetW;

    const speed = 0.864;

    const updateCards = () => {
      const containerCx = track.getBoundingClientRect().left + track.clientWidth / 2;
      const threshold   = imgW * 1.4;
      Array.from(track.querySelectorAll('[data-kit-img]')).forEach(card => {
        const r  = card.getBoundingClientRect();
        const cx = r.left + r.width / 2;
        const d  = Math.abs(cx - containerCx);
        const t  = Math.max(0, 1 - d / threshold);
        const s  = 1 + 0.3 * t;
        card.style.transform = `scale(${s})`;
        card.style.zIndex    = Math.round(t * 10);
      });
    };

    const tick = () => {
      if (!isDragging.current) {
        scrollPos.current += speed;
        if (scrollPos.current >= singleSetW * 2) scrollPos.current -= singleSetW;
        track.scrollLeft = scrollPos.current;
      }
      updateCards();
      animRef.current = requestAnimationFrame(tick);
    };

    animRef.current = requestAnimationFrame(tick);

    const onPointerDown = (e) => {
      dragStartX.current = e.clientX ?? 0;
      dragStartY.current = e.clientY ?? 0;
      dragStartScroll.current = scrollPos.current;
      if (e.pointerType !== 'touch') {
        isDragging.current = true;
        track.style.cursor = 'grabbing';
        track.setPointerCapture?.(e.pointerId);
      } else {
        isDragging.current = false;
        isDirectionSet.current = false;
      }
    };

    const onPointerMove = (e) => {
      if (e.pointerType === 'touch') {
        if (!isDirectionSet.current) {
          const dx = Math.abs(e.clientX - dragStartX.current);
          const dy = Math.abs(e.clientY - dragStartY.current);
          if (dx < 6 && dy < 6) return;
          isDirectionSet.current = true;
          if (dx >= dy * 1.2) {
            isDragging.current = true;
            track.setPointerCapture?.(e.pointerId);
          } else {
            isDragging.current = false;
            return;
          }
        }
        if (!isDragging.current) return;
      } else {
        if (!isDragging.current) return;
      }
      const delta = dragStartX.current - e.clientX;
      let next = dragStartScroll.current + delta;
      if (next >= singleSetW * 2) next -= singleSetW;
      if (next < singleSetW) next += singleSetW;
      scrollPos.current = next;
      track.scrollLeft = next;
    };

    const onPointerUp = () => {
      isDragging.current = false;
      isDirectionSet.current = false;
      track.style.cursor = 'grab';
    };

    track.addEventListener('pointerdown', onPointerDown);
    track.addEventListener('pointermove', onPointerMove);
    track.addEventListener('pointerup', onPointerUp);
    track.addEventListener('pointercancel', onPointerUp);

    return () => {
      cancelAnimationFrame(animRef.current);
      track.removeEventListener('pointerdown', onPointerDown);
      track.removeEventListener('pointermove', onPointerMove);
      track.removeEventListener('pointerup', onPointerUp);
      track.removeEventListener('pointercancel', onPointerUp);
    };
  }, [mobile]);

  return (
    <div style={{
      overflow: 'hidden',
      margin: mobile ? '32px -20px 50px' : '0',
    }}>
      <div
        ref={trackRef}
        style={{
          display: 'flex',
          gap: `${gap}px`,
          overflow: 'hidden',
          alignItems: 'center',
          padding: `${mobile ? 56 : 80}px 0`,
          cursor: 'grab',
          userSelect: 'none',
          touchAction: 'pan-y',
        }}
      >
        {allImages.map((img, i) => (
          <div
            key={i}
            data-kit-img
            style={{
              flex: `0 0 ${imgW}px`,
              height: `${imgW * 1.5}px`,
              flexShrink: 0,
              transformOrigin: 'center center',
              willChange: 'transform',
            }}
          >
            <div style={{
              width: '100%',
              height: '100%',
              borderRadius: '8px',
              overflow: 'hidden',
            }}>
              <img
                src={`images/slideshow/${img}.webp`}
                alt=""
                draggable="false"
                style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}
              />
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

window.KitchenSlideshow = KitchenSlideshow;

/* ============================================
   ORIGINAL KITCHEN OPTIONS
   ============================================ */
function InfiniteKitchenOptions() {
  const mobile = useIsMobile();

  return (
    <section id="nase-kuchyne" style={{
      padding: mobile ? '48px 0 92px' : '72px 0 70px',
      background: '#ffffff',
      overflow: 'visible',
    }}>
      {mobile ? (
        <div className="container">
          <div className="section-header" style={{ marginBottom: 0 }}>
            <div className="eyebrow" style={{ marginBottom: '14px' }}>Kuchyně na míru</div>
            <h2 className="display-l" style={{ marginTop: '0' }}>
              Váš prostor.<br />Vaše pravidla.
            </h2>
            <p style={{
              marginTop: '16px',
              fontSize: '17px',
              lineHeight: 1.65,
              color: '#555555',
              fontWeight: 300,
            }}>
              Nekombinujeme unifikované skříňky z katalogu. Nasloucháme tomu, jak žijete, jak rádi vaříte a kolik úložného prostoru skutečně potřebujete. Výsledkem je kuchyně navržená <strong>na milimetr přesně</strong> pro <strong>váš prostor</strong>, <strong>vaše zvyky</strong> a <strong>váš rozpočet</strong>.
            </p>
          </div>
          {/* Stats — mobile: above slideshow */}
          <div style={{ display: 'grid', gridTemplateColumns: '1fr', gap: '16px', padding: '36px 0 28px' }}>
            {[
              { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M20 6L9 17l-5-5"/></svg>, label: '7 000+ realizací' },
              { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>, label: '30 let zkušeností' },
              { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M12 3l2.7 5.7 6.3.9-4.5 4.4 1.1 6.3L12 17.3l-5.6 3 1.1-6.3L3 9.6l6.3-.9z"/></svg>, label: '4,8 hodnocení', href: 'https://www.recenze-kuchyne.cz/recenze/kuchyne-gorenje' },
              { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><circle cx="9" cy="7" r="3.5"/><path d="M2 21v-1.5A5.5 5.5 0 0 1 7.5 14h3A5.5 5.5 0 0 1 16 19.5V21"/><circle cx="17" cy="7" r="3.5"/><path d="M14.5 14c.83-.32 1.73-.5 2.5-.5A5.5 5.5 0 0 1 22.5 19v1"/></svg>, label: '10+ designérů' },
              { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M5 19c8 0 14-6 14-14-8 0-14 6-14 14z"/><path d="M5 19l5-5"/></svg>, label: 'Německo-česká výroba' },
            ].map((it, i) => {
              const inner = (
                <>
                  <span style={{ opacity: 0.5, flexShrink: 0, paddingTop: '2px' }}>{it.icon}</span>
                  <span style={{ paddingTop: '6px' }}>{it.label}</span>
                </>
              );
              const sharedStyle = { display: 'flex', alignItems: 'flex-start', gap: '12px', color: 'var(--ink)', fontFamily: 'var(--sans)', fontSize: '17px', fontWeight: 400, paddingLeft: '10px', textDecoration: 'none' };
              return it.href
                ? <a key={i} href={it.href} target="_blank" rel="noopener noreferrer" style={sharedStyle}>{inner}</a>
                : <div key={i} style={sharedStyle}>{inner}</div>;
            })}
          </div>
          <KitchenSlideshow />
        </div>
      ) : (
        <div className="container" style={{ display: 'flex', alignItems: 'center', gap: '0', paddingBottom: '80px', paddingRight: '0' }}>
          <div style={{ flex: '0 0 50%', paddingRight: '48px' }}>
            <div className="eyebrow" style={{ marginBottom: '14px' }}>Kuchyně na míru</div>
            <h2 className="display-l" style={{ marginTop: '0' }}>
              Váš prostor.<br />Vaše pravidla.
            </h2>
            <p style={{
              marginTop: '20px',
              fontSize: '19px',
              lineHeight: 1.65,
              color: '#555555',
              fontWeight: 300,
              maxWidth: '480px',
            }}>
              Nekombinujeme unifikované skříňky z katalogu. Nasloucháme tomu, jak žijete, jak rádi vaříte a kolik úložného prostoru skutečně potřebujete. Výsledkem je kuchyně navržená <strong>na milimetr přesně</strong> pro <strong>váš prostor</strong>, <strong>vaše zvyky</strong> a <strong>váš rozpočet</strong>.
            </p>
          </div>
          <div style={{ flex: 1, minWidth: 0, marginRight: '-80px' }}>
            <KitchenSlideshow />
          </div>
        </div>
      )}
      {!mobile && <div className="container" style={{ paddingTop: '86px', paddingBottom: '0px' }}>
        <div style={{
          display: 'grid',
          gridTemplateColumns: 'repeat(5, 1fr)',
          gap: mobile ? '16px' : '0',
          justifyItems: mobile ? 'start' : 'center',
        }}>
          {[
            { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M20 6L9 17l-5-5"/></svg>, label: '7 000+ realizací' },
            { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>, label: '30 let zkušeností' },
            { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M12 3l2.7 5.7 6.3.9-4.5 4.4 1.1 6.3L12 17.3l-5.6 3 1.1-6.3L3 9.6l6.3-.9z"/></svg>, label: '4,8 hodnocení', href: 'https://www.recenze-kuchyne.cz/recenze/kuchyne-gorenje' },
            { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><circle cx="9" cy="7" r="3.5"/><path d="M2 21v-1.5A5.5 5.5 0 0 1 7.5 14h3A5.5 5.5 0 0 1 16 19.5V21"/><circle cx="17" cy="7" r="3.5"/><path d="M14.5 14c.83-.32 1.73-.5 2.5-.5A5.5 5.5 0 0 1 22.5 19v1"/></svg>, label: '10+ designérů' },
            { icon: <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M5 19c8 0 14-6 14-14-8 0-14 6-14 14z"/><path d="M5 19l5-5"/></svg>, label: 'Německo-česká výroba' },
          ].map((it, i) => {
            const inner = (
              <>
                <span style={{ opacity: 0.5, flexShrink: 0, paddingTop: '2px' }}>{it.icon}</span>
                <span style={{ paddingTop: '6px' }}>{it.label}</span>
              </>
            );
            const sharedStyle = { display: 'flex', alignItems: 'flex-start', gap: '12px', color: 'var(--ink)', fontFamily: 'var(--sans)', fontSize: mobile ? '17px' : '18px', fontWeight: 400, paddingLeft: mobile ? '64px' : '0', textDecoration: 'none' };
            return it.href
              ? <a key={i} href={it.href} target="_blank" rel="noopener noreferrer" style={sharedStyle}>{inner}</a>
              : <div key={i} style={sharedStyle}>{inner}</div>;
          })}
        </div>
      </div>}
    </section>
  );
}

window.InfiniteKitchenOptions = InfiniteKitchenOptions;

/* ============================================
   SCROLL-DRIVEN PROCESS STEPS SECTION
   ============================================ */
function ProcessStepsSection() {
  const mobile = useIsMobile();
  const sectionRef  = React.useRef(null);
  const introRef    = React.useRef(null);
  const videoRef    = React.useRef(null);
  const blockRef    = React.useRef(null);
  const [videoFailed, setVideoFailed] = React.useState(false);

  React.useEffect(() => {
    const video = videoRef.current;
    const block = blockRef.current;
    if (!video || !block) return;

    let rafId;
    const tick = () => {
      if (video.duration) {
        const rect       = block.getBoundingClientRect();
        const winH       = window.innerHeight;
        const isMob      = window.innerWidth < 768;
        const startDelay = isMob ? 0 : block.offsetHeight * 0.33;
        const scrolled   = Math.max(0, (winH - rect.top) - startDelay);
        const total      = winH + block.offsetHeight - startDelay;
        const progress   = Math.max(0, Math.min(1, (scrolled / total) * 1.6));
        const target   = progress * video.duration;
        // Lerp toward target: 18% per frame ≈ smooth but responsive at 60fps
        const diff = target - video.currentTime;
        if (Math.abs(diff) > 0.0005) {
          video.currentTime += diff * 0.18;
        }
      }
      rafId = requestAnimationFrame(tick);
    };

    // iOS Safari ignores preload="auto" and requires play() to be called
    // before currentTime can be set programmatically. We play briefly then
    // immediately pause so metadata + frames load, enabling scroll-scrub.
    const initPromise = video.play();
    if (initPromise !== undefined) {
      initPromise.then(() => {
        video.pause();
        video.currentTime = 0;
        rafId = requestAnimationFrame(tick);
      }).catch(() => {
        // Autoplay blocked or video failed to load — show poster fallback
        setVideoFailed(true);
      });
    } else {
      // Older browsers without Promise-based play()
      video.pause();
      video.currentTime = 0;
      rafId = requestAnimationFrame(tick);
    }

    return () => cancelAnimationFrame(rafId);
  }, []);

  return (
    <section id="proces" ref={sectionRef} style={{ background: '#ffffff', paddingTop: mobile ? '0' : '0', marginTop: 0, marginBottom: 0 }}>

      {/* ── Intro (scrolls normally) ── */}
      <div ref={introRef} className="container" style={{ padding: mobile ? '56px 20px 40px' : '40px 0 32px' }}>
        <div className="section-header" style={{ marginBottom: 0, maxWidth: mobile ? undefined : '900px' }}>
          <div className="eyebrow" style={{ marginBottom: '14px' }}>Od představy k realitě</div>
          <h2 className="display-l" style={{ marginTop: 0 }}>
            Cesta k vaší nové kuchyni
          </h2>
          <p style={{
            marginTop: '20px',
            fontSize: mobile ? '17px' : '19px',
            lineHeight: 1.65,
            color: '#555555',
            fontWeight: 300,
            maxWidth: 'none',
            margin: '20px auto 0',
          }}>
            Dobrá kuchyně nevzniká náhodou. Vzniká <strong>přesným zaměřením</strong>, <strong>promyšleným návrhem</strong> a <strong>pečlivou realizací</strong>, ve které do sebe všechno přirozeně zapadne.
          </p>
        </div>
      </div>

      {/* ── Sticky two-column block (desktop only) ── */}
      {mobile ? (
        /* Mobile: static layout */
        <div ref={blockRef} className="container" style={{ paddingBottom: '56px' }}>
          {videoFailed ? (
            <img
              src="images/pudorys_poster.jpg"
              alt="Půdorys kuchyně"
              style={{ width: '100%', borderRadius: '10px', display: 'block' }}
            />
          ) : (
            <video
              ref={videoRef}
              src="images/pudorys_scrub.mp4"
              muted playsInline preload="auto"
              poster="images/pudorys_poster.jpg"
              onError={() => setVideoFailed(true)}
              style={{ width: '100%', borderRadius: '10px', display: 'block' }}
            />
          )}
          <div style={{ paddingTop: '32px' }}>
            <h3 style={{ fontFamily: 'var(--sans)', fontSize: '32px', fontWeight: 600, lineHeight: 1.2, color: 'var(--ink)', margin: '0 0 16px' }}>
              Navrženo podle prostoru. Promyšleno podle vás.
            </h3>
            <p style={{ fontSize: '16px', lineHeight: 1.7, color: '#555555', fontWeight: 300, margin: 0 }}>
              Ať zařizujete novostavbu, nebo rekonstruujete starší kuchyň, navrhneme uspořádání, které <strong>využije prostor naplno</strong>. Promyslíme <strong>pracovní zóny, úložná místa i pohodlný pohyb</strong> tak, aby se vám v kuchyni dobře fungovalo každý den. <strong>Dlouholeté zkušenosti</strong> nám pomáhají odhalit nepraktická řešení dřív, než vzniknou.
            </p>
          </div>
        </div>
      ) : (
        <div ref={blockRef} className="container" style={{
          height: '70vh',
          display: 'flex',
          alignItems: 'center',
          gap: '64px',
        }}>
          {/* Left: video */}
          <div style={{
            flex: '0 0 50%',
            overflow: 'hidden',
            borderRadius: '10px',
            background: '#f2f0eb',
            transform: 'translateZ(0)',
          }}>
            <video
              ref={videoRef}
              src="images/pudorys_scrub.mp4"
              muted playsInline preload="auto"
              poster="images/pudorys_poster.jpg"
              style={{ width: '100%', display: 'block' }}
            />
          </div>

          {/* Right: text */}
          <div style={{
            flex: 1,
            display: 'flex',
            alignItems: 'center',
          }}>
            <div>
              <h3 style={{
                fontFamily: 'var(--sans)',
                fontSize: '42px',
                fontWeight: 600,
                lineHeight: 1.15,
                color: 'var(--ink)',
                margin: '0 0 24px',
              }}>
                Navrženo podle prostoru. Promyšleno podle vás.
              </h3>
              <p style={{
                fontSize: '18px',
                lineHeight: 1.7,
                color: '#555555',
                fontWeight: 300,
                margin: 0,
              }}>
                Ať zařizujete novostavbu, nebo rekonstruujete starší kuchyň, navrhneme uspořádání, které <strong>využije prostor naplno</strong>. Promyslíme <strong>pracovní zóny, úložná místa i pohodlný pohyb</strong> tak, aby se vám v kuchyni dobře fungovalo každý den.
              </p>
              <p style={{
                marginTop: '20px',
                fontSize: '18px',
                lineHeight: 1.7,
                color: '#555555',
                fontWeight: 300,
              }}>
                <strong>Dlouholeté zkušenosti</strong> nám pomáhají odhalit nepraktická řešení dřív, než vzniknou.
              </p>
            </div>
          </div>
        </div>
      )}
    </section>
  );
}

window.ProcessStepsSection = ProcessStepsSection;

/* ============================================
   KITCHEN DESIGN SECTION — Krok 2
   ============================================ */
function KitchenDesignSection() {
  const mobile = useIsMobile();
  const [activeTab, setActiveTab] = React.useState(0);

  const tabs = [
    { label: 'Styly' },
    { label: 'Materiály' },
    { label: 'Prac. desky' },
    { label: 'Vybavení' },
  ];

  const tabIcons = [
    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="3" width="8" height="8" rx="1.5"/>
      <rect x="13" y="3" width="8" height="8" rx="1.5"/>
      <rect x="3" y="13" width="8" height="8" rx="1.5"/>
      <rect x="13" y="13" width="8" height="8" rx="1.5"/>
    </svg>,
    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="3" width="18" height="18" rx="2"/>
      <path d="M3 9h18M3 15h18M9 3v18"/>
    </svg>,
    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 7h18v4H3z"/>
      <path d="M3 7V5a1 1 0 0 1 1-1h16a1 1 0 0 1 1 1v2"/>
      <path d="M5 11v8M19 11v8M5 19h14"/>
    </svg>,
    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
      <rect x="2" y="4" width="20" height="16" rx="2"/>
      <path d="M2 10h20M2 16h20"/>
      <circle cx="12" cy="7" r="0.8" fill="currentColor" stroke="none"/>
      <circle cx="12" cy="13" r="0.8" fill="currentColor" stroke="none"/>
    </svg>,
  ];

  const kitchenStyles = [
    { name: 'Moderní',      desc: 'Čisté linie, bez kompromisů',  img: 'images/kit7.webp' },
    { name: 'Skandinávský', desc: 'Světlo, dřevo, příroda',       img: 'images/kitchensize_1.webp' },
    { name: 'Industriální', desc: 'Kov, beton, charakter',        img: 'images/kit2.webp' },
    { name: 'Provence',     desc: 'Vzduch a styl Francie',        img: 'images/kit3.webp' },
    { name: 'Luxusní',      desc: 'Materiály bez kompromisů',     img: 'images/kit4.webp' },
    { name: 'Retro',        desc: 'Osobitý, plný energie',        img: 'images/kit8.webp' },
  ];

  const materials = [
    { name: 'Lamino',             desc: 'Odolné, cenově dostupné',          bg: 'linear-gradient(160deg,#EDEAE4 0%,#E2DDD4 100%)' },
    { name: 'Lak',                desc: 'Hedvábný povrch, tisíce odstínů',  bg: 'linear-gradient(140deg,#DDDAD4 0%,#F6F4F0 36%,#ECEAE4 56%,#DEDAD4 100%)' },
    { name: 'Profilovaná dvířka', desc: 'Klasický rámeček, moderní nádech', type: 'profiled', bg: '#EDEAE3' },
    { name: 'Dýha',               desc: 'Přírodní dřevěný vzor',            bg: 'repeating-linear-gradient(86deg,#C8A87A 0px,#C8A87A 3px,#B49060 3px,#B49060 4px,#C8A87A 4px,#C8A87A 11px)' },
    { name: 'Masiv',              desc: 'Tradiční řemeslo, na generace',    bg: 'repeating-linear-gradient(88deg,#8E6B3E 0px,#8E6B3E 8px,#7A5A2E 8px,#7A5A2E 9px,#8E6B3E 9px,#8E6B3E 22px)' },
    { name: '∞ barev',            desc: 'Tisíce kombinací pro každý styl',  type: 'colors' },
  ];

  const countertops = [
    { name: 'Vysokotlaký laminát', img: 'images/worktops/940-kronos-wood.webp' },
    { name: 'Kompaktní desky',     img: 'images/worktops/898-beton-antracit.webp' },
    { name: 'Technistone',         img: 'images/worktops/927-terrazzo-color.webp' },
    { name: 'Silestone',           img: 'images/worktops/931-kamen-cernosedy.webp' },
    { name: 'Corian',              bg: 'linear-gradient(160deg,#F0ECE4 0%,#E6E0D6 50%,#EDEAE2 100%)' },
    { name: 'Keramické desky',     img: 'images/worktops/977-keramika.webp' },
    { name: 'Přírodní kámen',      img: 'images/worktops/896-mramor.webp' },
    { type: 'colorNote' },
  ];

  const interiorSolutions = [
    { name: 'Rohové řešení',      url: 'https://images.pexels.com/photos/7533923/pexels-photo-7533923.jpeg' },
    { name: 'Šuplíky',            url: 'https://images.pexels.com/photos/9646744/pexels-photo-9646744.jpeg' },
    { name: 'Výsuvy',             url: 'https://images.pexels.com/photos/6264416/pexels-photo-6264416.jpeg' },
    { name: 'Výklopy',            url: 'https://images.pexels.com/photos/7303850/pexels-photo-7303850.jpeg' },
    { name: 'Odpadové koše',      url: 'https://images.pexels.com/photos/7512975/pexels-photo-7512975.jpeg' },
    { name: 'Vnitřní organizéry', url: 'https://images.pexels.com/photos/3722563/pexels-photo-3722563.jpeg' },
  ];

  const renderContent = () => {
    if (activeTab === 0) {
      const card = (item, idx) => (
        <div key={idx} style={{ borderRadius: '10px', overflow: 'hidden', position: 'relative', aspectRatio: '5 / 4', flexShrink: 0 }}>
          <div style={{
            position: 'absolute', inset: 0,
            backgroundImage: `url("${item.img}")`,
            backgroundSize: 'cover',
            backgroundPosition: 'center',
          }} />
          <div style={{
            position: 'absolute', inset: 0,
            background: 'linear-gradient(to top right, rgba(0,0,0,0.42) 0%, rgba(0,0,0,0.14) 22%, rgba(0,0,0,0) 38%)',
          }} />
          <div style={{
            position: 'absolute', bottom: mobile ? '8px' : '10px', left: mobile ? '10px' : '12px',
            fontFamily: 'var(--sans)', fontSize: mobile ? '12px' : '13px', fontWeight: 600,
            color: '#ffffff', lineHeight: 1,
            textShadow: '0 1px 4px rgba(0,0,0,0.4)',
          }}>{item.name}</div>
        </div>
      );

      if (mobile) {
        const row1 = kitchenStyles.slice(0, 3);
        const row2 = kitchenStyles.slice(3, 6);
        return (
          <div style={{ overflowX: 'auto', overflowY: 'hidden', WebkitOverflowScrolling: 'touch', scrollbarWidth: 'none', margin: '0 -24px', padding: '0 24px' }}>
            <style>{`.kds-styles-scroll::-webkit-scrollbar{display:none}`}</style>
            <div className="kds-styles-scroll" style={{ display: 'flex', flexDirection: 'column', gap: '8px', width: 'max-content' }}>
              <div style={{ display: 'flex', gap: '8px' }}>
                {row1.map((item, idx) => (
                  <div key={idx} style={{ width: 'calc(47vw - 20px)', flexShrink: 0 }}>
                    {card(item, idx)}
                  </div>
                ))}
              </div>
              <div style={{ display: 'flex', gap: '8px' }}>
                {row2.map((item, idx) => (
                  <div key={idx} style={{ width: 'calc(47vw - 20px)', flexShrink: 0 }}>
                    {card(item, idx + 3)}
                  </div>
                ))}
              </div>
            </div>
          </div>
        );
      }

      return (
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: '10px' }}>
          {kitchenStyles.map((item, idx) => card(item, idx))}
        </div>
      );
    }

    if (activeTab === 1) {
      const allColors = [
        '#FAFAF7','#F5F2EB','#EDE8DF','#D4C5A9','#C8B898','#B0A888','#A89278','#8A7862',
        '#C8DDB8','#8A9B7A','#5A7A62','#3D5A4A','#2E4A3A','#1E3428','#7AB0C8','#4A8AAA',
        '#2C5A7A','#2C3E5A','#1A2A42','#0E1A2E','#D4B864','#C4A044','#B88030','#8A6020',
        '#F0A888','#D4886A','#B85C3C','#8A3C2A','#6A2418','#7A2535','#C4968A','#D4A090',
        '#F5F0E8','#E8E4DE','#D4D0CC','#B8B4AE','#909088','#6A6862','#4A4A52','#1A1A22',
      ];

      const renderBg = (item) => {
        if (item.type === 'profiled') {
          return (
            <div style={{ position: 'absolute', inset: 0, background: item.bg, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
              <div style={{
                width: '54%', height: '52%',
                background: item.bg,
                borderRadius: '2px',
                boxShadow: 'inset 0 0 0 3px rgba(255,255,255,0.72), inset 0 0 0 5.5px rgba(145,130,110,0.26), 2px 2px 0 rgba(150,135,115,0.6), -1px -1px 0 rgba(255,255,255,0.88)',
              }} />
            </div>
          );
        }
        return <div style={{ position: 'absolute', inset: 0, background: item.bg }} />;
      };

      return (
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: '10px', alignItems: 'end' }}>
          {materials.map((item, idx) => {
            if (item.type === 'colors') {
              return (
                <div key={idx}>
                  <div style={{
                    display: 'grid',
                    gridTemplateColumns: 'repeat(8, 1fr)',
                    gap: mobile ? '4px' : '5px',
                    marginBottom: '8px',
                  }}>
                    {allColors.map((hex, i) => (
                      <div key={i} style={{ background: hex, borderRadius: '20%', aspectRatio: '1/1', border: '1.5px solid rgba(0,0,0,0.07)' }} />
                    ))}
                  </div>
                  <div style={{
                    fontFamily: 'var(--sans)', fontSize: mobile ? '11px' : '12px', fontWeight: 500,
                    color: '#1a1a1a', lineHeight: 1.3,
                  }}>Nekonečné množství barev</div>
                </div>
              );
            }
            return (
              <div key={idx} style={{ position: 'relative', borderRadius: '10px', overflow: 'hidden', aspectRatio: '5 / 4' }}>
                {renderBg(item)}
                <div style={{
                  position: 'absolute', inset: 0,
                  background: 'linear-gradient(to top right, rgba(0,0,0,0.42) 0%, rgba(0,0,0,0.14) 22%, rgba(0,0,0,0) 38%)',
                }} />
                <div style={{
                  position: 'absolute', bottom: mobile ? '7px' : '10px', left: mobile ? '9px' : '12px',
                  fontFamily: 'var(--sans)', fontSize: mobile ? '11px' : '12px', fontWeight: 600,
                  color: '#ffffff', lineHeight: 1,
                  textShadow: '0 1px 4px rgba(0,0,0,0.4)',
                }}>{item.name}</div>
              </div>
            );
          })}
        </div>
      );
    }

    if (activeTab === 2) {
      const ctNames = ['Vysokotlaký laminát', 'Kompaktní desky', 'Technistone', 'Silestone', 'Corian', 'Keramické desky', 'Přírodní kámen'];
      const ctImages = [
        'images/worktops/940-kronos-wood.webp',
        'images/worktops/898-beton-antracit.webp',
        'images/worktops/927-terrazzo-color.webp',
        'images/worktops/931-kamen-cernosedy.webp',
        'images/worktops/977-keramika.webp',
        'images/worktops/896-mramor.webp',
        'images/worktops/868-mramor-cerny.webp',
        'images/worktops/856-bridlice-antracit.webp',
        'images/worktops/972-beton.webp',
      ];
      return (
        <div style={{ display: 'flex', gap: mobile ? '20px' : '36px', alignItems: 'center', width: '100%' }}>
          <div style={{ flex: '0 0 38%', display: 'flex', flexDirection: 'column', gap: mobile ? '10px' : '16px' }}>
            {ctNames.map((name, i) => (
              <div key={i} style={{ display: 'flex', alignItems: 'center', gap: '12px' }}>
                <div style={{ width: '5px', height: '5px', borderRadius: '50%', background: 'rgba(0,0,0,0.28)', flexShrink: 0 }} />
                <span style={{ fontFamily: 'var(--sans)', fontSize: mobile ? '14px' : '17px', fontWeight: 400, color: 'var(--ink)', lineHeight: 1.3 }}>{name}</span>
              </div>
            ))}
          </div>
          <div style={{ flex: '0 0 58%', display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: mobile ? '7px' : '14px' }}>
            {ctImages.map((img, i) => (
              <div key={i} style={{ aspectRatio: '1 / 1', borderRadius: '8px', overflow: 'hidden' }}>
                <img src={img} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }} />
              </div>
            ))}
          </div>
        </div>
      );
    }

    if (activeTab === 3) {
      const card = (item, idx) => (
        <div key={idx} style={{ borderRadius: '10px', overflow: 'hidden', position: 'relative', aspectRatio: '5 / 4' }}>
          <div style={{
            position: 'absolute', inset: 0,
            backgroundImage: `url("${item.url}?auto=compress&cs=tinysrgb&w=600")`,
            backgroundSize: 'cover',
            backgroundPosition: 'center',
          }} />
          <div style={{
            position: 'absolute', inset: 0,
            background: 'linear-gradient(to top right, rgba(0,0,0,0.42) 0%, rgba(0,0,0,0.14) 22%, rgba(0,0,0,0) 38%)',
          }} />
          <div style={{
            position: 'absolute', bottom: mobile ? '8px' : '10px', left: mobile ? '10px' : '12px',
            fontFamily: 'var(--sans)', fontSize: mobile ? '12px' : '13px', fontWeight: 600,
            color: '#ffffff', lineHeight: 1,
            textShadow: '0 1px 4px rgba(0,0,0,0.4)',
          }}>{item.name}</div>
        </div>
      );

      if (mobile) {
        const row1 = interiorSolutions.slice(0, 3);
        const row2 = interiorSolutions.slice(3, 6);
        return (
          <div style={{ overflowX: 'auto', overflowY: 'hidden', WebkitOverflowScrolling: 'touch', scrollbarWidth: 'none', margin: '0 -24px', padding: '0 24px' }}>
            <style>{`.kds-interior-scroll::-webkit-scrollbar{display:none}`}</style>
            <div className="kds-interior-scroll" style={{ display: 'flex', flexDirection: 'column', gap: '8px', width: 'max-content' }}>
              <div style={{ display: 'flex', gap: '8px' }}>
                {row1.map((item, idx) => (
                  <div key={idx} style={{ width: 'calc(47vw - 20px)', flexShrink: 0 }}>
                    {card(item, idx)}
                  </div>
                ))}
              </div>
              <div style={{ display: 'flex', gap: '8px' }}>
                {row2.map((item, idx) => (
                  <div key={idx} style={{ width: 'calc(47vw - 20px)', flexShrink: 0 }}>
                    {card(item, idx + 3)}
                  </div>
                ))}
              </div>
            </div>
          </div>
        );
      }

      return (
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: '10px' }}>
          {interiorSolutions.map((item, idx) => card(item, idx))}
        </div>
      );
    }
  };

  return (
    <section id="navrh" style={{ background: '#ffffff' }}>
      <style>{`@keyframes kdsFadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }`}</style>
      <div className="container" style={{
        display: 'flex',
        alignItems: mobile ? 'flex-start' : 'center',
        flexDirection: mobile ? 'column' : 'row',
        gap: '64px',
        padding: mobile ? '64px 20px' : '120px 0',
      }}>
        {/* Left: text */}
        <div style={{ flex: '0 0 42%' }}>
          <h3 style={{ fontFamily: 'var(--sans)', fontSize: mobile ? '32px' : '42px', fontWeight: 600, lineHeight: 1.15, color: 'var(--ink)', margin: '0 0 24px' }}>
            Váš styl v každém detailu
          </h3>
          <p style={{ fontSize: mobile ? '16px' : '18px', lineHeight: 1.7, color: '#555555', fontWeight: 300, margin: '0 0 20px' }}>
            Někdo chce čistý minimalismus, jiný teplo dřeva nebo výrazné barvy. Z <strong>tisíců kombinací</strong> společně vytvoříme řešení, které bude odpovídat <strong>vašemu stylu i způsobu života</strong>.
          </p>
          <p style={{ fontSize: mobile ? '16px' : '18px', lineHeight: 1.7, color: '#555555', fontWeight: 300, margin: 0 }}>
            Krásný vzhled doplníme <strong>chytrým vnitřním řešením</strong>, díky kterému bude mít vše své místo a kuchyně bude fungovat stejně dobře, jako vypadá.
          </p>
        </div>

        {/* Right: interactive panel */}
        <div style={{ flex: 1, width: mobile ? '100%' : undefined, order: mobile ? -1 : undefined }}>
          {/* Visual content area */}
          <div style={{ background: '#f8f7f5', borderRadius: '16px', padding: mobile ? '24px' : '40px', marginBottom: '12px', minHeight: mobile ? '260px' : '520px', display: 'flex', alignItems: 'center' }}>
            <div key={activeTab} style={{ width: '100%', animation: 'kdsFadeIn 0.22s ease both' }}>
              {renderContent()}
            </div>
          </div>

          {/* Tab switcher — light design */}
          <div style={{ background: '#f0ebe4', borderRadius: '14px', padding: '8px', display: 'flex' }}>
            {tabs.map((tab, i) => {
              const isActive = activeTab === i;
              return (
                <button key={i} onClick={() => setActiveTab(i)} style={{
                  flex: 1,
                  background: isActive ? '#c4b8a8' : 'transparent',
                  borderRadius: '10px', border: 'none',
                  padding: mobile ? '13px 6px' : '16px 8px',
                  cursor: 'pointer',
                  display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '5px',
                  color: isActive ? 'var(--ink)' : 'rgba(0,0,0,0.45)',
                  transition: 'background 0.2s ease, color 0.2s ease',
                  fontFamily: 'var(--sans)',
                  fontSize: mobile ? '11px' : '13px',
                  fontWeight: isActive ? 500 : 400,
                  lineHeight: 1.2, textAlign: 'center',
                }}>
                  {tabIcons[i]}
                  <span>{tab.label}</span>
                </button>
              );
            })}
          </div>
        </div>
      </div>
    </section>
  );
}

window.KitchenDesignSection = KitchenDesignSection;

/* ============================================
   KITCHEN APPLIANCES SECTION — Krok 3
   ============================================ */
function KitchenAppliancesSection() {
  const mobile = useIsMobile();

  const brands = [
    {
      name: 'gorenje',
      tagline: 'Život jednoduše',
      text: 'Spolehlivé a dostupné spotřebiče pro každodenní život. Čistý design, snadná obsluha a prověřená funkčnost, která vydrží roky.',
      logo: 'images/Gorenje-spotrebice.png',
      logoScale: 1.35,
      img: 'images/gorenje_pic1.webp',
    },
    {
      name: 'Hisense',
      tagline: 'Pro fanoušky smart technologií',
      text: 'Inovativní technologie a chytré funkce pro moderní domácnost. Široká řada spotřebičů s připojením a pokročilými funkcemi za dostupnou cenu.',
      logo: 'images/Hisense.png',
      img: 'images/hisense_pic1.webp',
    },
    {
      name: 'ASKO',
      tagline: 'Skandinávská prémiová kvalita',
      text: 'Prémiové spotřebiče pro nejnáročnější. Nordický minimalismus, výjimečná trvanlivost a výkon, který ocení každý, kdo vaření bere vážně.',
      logo: 'images/Asko-spotrebice.png',
      img: 'images/asko_pic1.webp',
    },
    {
      name: 'MORA',
      tagline: 'Tradice a rodinná pohoda',
      text: 'Česká tradice s více než 70letou historií. Spotřebiče, kterým důvěřují generace rodin — spolehlivé, tiché a přirozené do každé kuchyně.',
      logo: 'images/Mora-spotrebice.png',
      img: 'images/mora_pic1.webp',
    },
  ];

  return (
    <section id="spotrebice" style={{ background: '#ffffff' }}>
      <div className="container" style={{ padding: mobile ? '64px 20px' : '100px 0' }}>
        {/* Top: centered text */}
        <div style={{ textAlign: mobile ? 'left' : 'center', maxWidth: mobile ? undefined : '640px', margin: mobile ? '0' : '0 auto', marginBottom: mobile ? '40px' : '64px' }}>
          <h3 style={{ fontFamily: 'var(--sans)', fontSize: mobile ? '32px' : '42px', fontWeight: 600, lineHeight: 1.15, color: 'var(--ink)', margin: '0 0 20px' }}>
            Technika, která vám usnadní každý den
          </h3>
          <p style={{ fontSize: mobile ? '16px' : '18px', lineHeight: 1.7, color: '#555555', fontWeight: 300, margin: 0 }}>
            Někdo hledá jednoduchost, jiný <strong>chytré funkce nebo prémiový výkon</strong>. Porovnáme možnosti jednotlivých značek a doporučíme spotřebiče <strong>podle vašich návyků, prostoru i plánovaného rozpočtu</strong>.
          </p>
        </div>

        <div style={{ textAlign: 'center', marginBottom: mobile ? '24px' : '32px' }}>
          <span style={{ fontFamily: 'var(--sans)', fontSize: mobile ? '13px' : '14px', fontWeight: 500, letterSpacing: '0.12em', textTransform: 'uppercase', color: 'rgba(0,0,0,0.4)' }}>
            Spolupracujeme s
          </span>
        </div>

        {/* Bottom: brand cards — 4 in one row on desktop, 2×2 on mobile */}
        <div style={{
          display: 'grid',
          gridTemplateColumns: mobile ? '1fr' : 'repeat(4, 1fr)',
          gap: mobile ? '32px' : '28px',
        }}>
          {brands.map((brand, i) => (
            <div key={i} style={{
              borderRadius: '16px',
            }}>
              <div style={{ aspectRatio: mobile ? '4 / 3' : '1 / 1', overflow: 'hidden', borderRadius: '16px' }}>
                <img
                  src={brand.img}
                  alt={brand.name}
                  style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}
                />
              </div>
              <div style={{ padding: mobile ? '12px 4px' : '18px 4px 22px' }}>
                <img
                  src={brand.logo}
                  alt={brand.name}
                  style={{
                    height: mobile ? `${Math.round(18 * (brand.logoScale || 1))}px` : `${Math.round(20 * (brand.logoScale || 1))}px`,
                    width: 'auto',
                    display: 'block',
                    marginBottom: '12px',
                    objectFit: 'contain',
                  }}
                />
                <div style={{
                  fontFamily: 'var(--sans)',
                  fontSize: mobile ? '12px' : '10px',
                  fontWeight: 500,
                  letterSpacing: '0.14em',
                  textTransform: 'uppercase',
                  color: 'rgba(0,0,0,0.4)',
                  marginBottom: '10px',
                }}>{brand.tagline}</div>
                <p style={{
                  fontFamily: 'var(--sans)',
                  fontSize: mobile ? '16px' : '15px',
                  lineHeight: 1.6,
                  color: '#666666',
                  fontWeight: 300,
                  margin: 0,
                }}>{brand.text}</p>
              </div>
            </div>
          ))}
        </div>

        {/* Secondary brands strip */}
        <div style={{
          marginTop: mobile ? '40px' : '52px',
          display: 'flex',
          flexDirection: 'column',
          alignItems: 'center',
          gap: '20px',
        }}>
          <p style={{
            fontFamily: 'var(--sans)',
            fontSize: mobile ? '16px' : '16px',
            color: 'rgba(0,0,0,0.38)',
            fontWeight: 400,
            lineHeight: 1.5,
            margin: 0,
            textAlign: 'center',
            maxWidth: '100%',
          }}>
            Na přání dokážeme dodat i spotřebiče dalších prémiových značek:
          </p>
          {mobile ? (
            <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '16px', width: '100%' }}>
              {/* Row 1: Bosch + Siemens + AEG */}
              <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '24px', width: '100%', flexWrap: 'wrap' }}>
                {[
                  { src: 'images/logo_bosh.png', alt: 'Bosch', scale: 1.2 },
                  { src: 'images/siemens_logo.png', alt: 'Siemens', scale: 0.85 },
                  { src: 'images/log_AEG.png', alt: 'AEG', scale: 0.85 },
                ].map((b) => (
                  <img key={b.alt} src={b.src} alt={b.alt} style={{
                    height: `${Math.round(20 * b.scale)}px`,
                    maxWidth: '28%', objectFit: 'contain', filter: 'grayscale(1)', opacity: 0.4,
                  }} />
                ))}
              </div>
              {/* Row 2: Miele + LG + Whirlpool */}
              <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '24px', width: '100%', flexWrap: 'wrap' }}>
                {[
                  { src: 'images/miele_logo.png', alt: 'Miele', scale: 0.85 },
                  { src: 'images/LG_logo.png', alt: 'LG', scale: 0.85 },
                  { src: 'images/whirpool_logo.png', alt: 'Whirlpool', scale: 1.1 },
                ].map((b) => (
                  <img key={b.alt} src={b.src} alt={b.alt} style={{
                    height: `${Math.round(20 * b.scale)}px`,
                    maxWidth: '28%', objectFit: 'contain', filter: 'grayscale(1)', opacity: 0.4,
                  }} />
                ))}
              </div>
            </div>
          ) : (
            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '44px' }}>
              {[
                { src: 'images/logo_bosh.png', alt: 'Bosch', scale: 1.4 },
                { src: 'images/siemens_logo.png', alt: 'Siemens', scale: 1 },
                { src: 'images/log_AEG.png', alt: 'AEG', scale: 1 },
                { src: 'images/miele_logo.png', alt: 'Miele', scale: 1 },
                { src: 'images/LG_logo.png', alt: 'LG', scale: 1 },
                { src: 'images/whirpool_logo.png', alt: 'Whirlpool', scale: 1.5 },
              ].map((b) => (
                <img key={b.alt} src={b.src} alt={b.alt} style={{
                  height: `${Math.round(22 * b.scale)}px`,
                  width: 'auto', objectFit: 'contain', filter: 'grayscale(1)', opacity: 0.4,
                }} />
              ))}
            </div>
          )}
        </div>

      </div>
    </section>
  );
}

window.KitchenAppliancesSection = KitchenAppliancesSection;

/* ============================================
   JAK SESTAVÍME TU VAŠI? SECTION
   ============================================ */
function KitchenAssemblySection() {
  const mobile = useIsMobile();

  return (
    <section id="montaz" style={{ padding: mobile ? '0 0 72px' : '0 0 120px', background: '#ffffff' }}>
      {/* CTA banner */}
      <div className="container">
        <div style={{
          background: '#a6192e',
          borderRadius: '14px',
          overflow: 'hidden',
          display: 'flex',
          flexDirection: mobile ? 'column' : 'row',
          alignItems: 'stretch',
          minHeight: mobile ? 'auto' : '220px',
          maxWidth: mobile ? undefined : '80%',
          marginLeft: 'auto',
          marginRight: 'auto',
        }}>
          {mobile ? (
            <div style={{ padding: '15px 15px 0' }}>
              <img
                src="images/client_designer.webp"
                alt="Designér s klientem"
                style={{
                  width: '100%',
                  aspectRatio: '5 / 4',
                  objectFit: 'cover',
                  objectPosition: 'center top',
                  display: 'block',
                  borderRadius: '8px',
                }}
              />
            </div>
          ) : (
            <div style={{
              flex: '0 0 auto',
              width: '180px',
              height: '180px',
              alignSelf: 'center',
              margin: '20px 0 20px 28px',
              flexShrink: 0,
            }}>
              <img
                src="images/client_designer.webp"
                alt="Designér s klientem"
                style={{
                  width: '100%',
                  height: '100%',
                  objectFit: 'cover',
                  objectPosition: 'center top',
                  borderRadius: '8px',
                }}
              />
            </div>
          )}
          <div style={{
            flex: 1,
            padding: mobile ? '24px 24px 28px' : '36px 44px',
            display: 'flex',
            flexDirection: 'column',
            justifyContent: 'center',
            gap: '12px',
          }}>
            <div style={{
              fontFamily: 'var(--sans)',
              fontSize: '11px',
              fontWeight: 500,
              letterSpacing: '0.18em',
              textTransform: 'uppercase',
              color: 'rgba(255,255,255,0.55)',
            }}>
              3D návrh zdarma
            </div>
            <h3 style={{
              fontFamily: 'var(--sans)',
              fontSize: mobile ? '26px' : '32px',
              fontWeight: 400,
              lineHeight: 1.12,
              color: '#ffffff',
              margin: 0,
            }}>
              Přijďte se podívat, jak může vypadat ta vaše. 3D návrh od designéra je zcela zdarma.
            </h3>
            <div style={{ marginTop: '8px' }}>
              <button onClick={() => window.scrollToKontakt()} style={{
                padding: mobile ? '12px 24px' : '15px 36px',
                borderRadius: '999px',
                background: '#ffffff',
                border: 'none',
                fontFamily: 'var(--sans)',
                fontSize: mobile ? '13px' : '15px',
                fontWeight: 600,
                letterSpacing: '0.06em',
                textTransform: 'uppercase',
                color: '#a6192e',
                cursor: 'pointer',
                whiteSpace: 'nowrap',
              }}>
                DOMLUVIT KONZULTACI →
              </button>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}


window.KitchenAssemblySection = KitchenAssemblySection;

/* ============================================
   PRICING SECTION
   ============================================ */
function PricingSection() {
  const mobile = useIsMobile();
  const [activeIndex, setPricingActive] = React.useState(1);

  const tiers = [
    {
      label: 'Základní',
      labelColor: '#e8f0e8',
      labelText: '#3a6b3a',
      total: '228 000 Kč',
      img: 'images/price_1.png',
      items: [
        { name: 'Nábytek v laminátu', price: '130 000', highlight: false },
        { name: 'Vnitřní vybavení Hettich', price: '14 000', highlight: false },
        { name: 'Deska laminát 38 mm', price: '8 000', highlight: false },
        { name: 'Spotřebiče Gorenje', price: '42 000', highlight: false },
        { name: 'Doplňky (dřez, baterie, LED)', price: '9 000', highlight: false },
        { name: 'Montáž, doprava, zaměření', price: '25 000', highlight: false },
      ],
      note: 'Laminátová dvířka s klasickými úchytkami. Hettich vybavení s tlumením, laminátová deska. Plnohodnotná kuchyně za rozumnou cenu.',
      noteBold: 'Plnohodnotná kuchyně za rozumnou cenu.',
    },
    {
      label: 'Komfortní',
      labelColor: '#e8eef8',
      labelText: '#2a4a8a',
      total: '315 000 Kč',
      img: 'images/price_2.png',
      items: [
        { name: 'Nábytek v laku', price: '165 000', highlight: false },
        { name: 'Bezúchytové řešení', price: '12 000', highlight: false },
        { name: 'Vnitřní vybavení Blum Antaro', price: '27 000', highlight: false },
        { name: 'Skryté potravinové šuplíky', price: '12 000', highlight: false },
        { name: 'Deska laminát 25 mm', price: '8 000', highlight: false },
        { name: 'Spotřebiče Hisense', price: '52 000', highlight: false },
        { name: 'Doplňky + odpadkové koše', price: '14 000', highlight: false },
        { name: 'Montáž, doprava, zaměření', price: '25 000', highlight: false },
      ],
      note: '+87 000 Kč oproti základní variantě. Lakovaná dvířka bez úchytek, Blum Antaro s tlumením a skryté šuplíky.',
      noteBold: '+87 000 Kč oproti základní variantě.',
    },
    {
      label: 'Prémiová',
      labelColor: '#f5f0e8',
      labelText: '#7a5a20',
      total: '506 000 Kč',
      img: 'images/price_3.png',
      items: [
        { name: 'Nábytek v laku na míru (NCS/RAL)', price: '210 000', highlight: false },
        { name: 'Bezúchytové řešení', price: '14 000', highlight: false },
        { name: 'Vnitřní vybavení Blum Merivobox', price: '52 000', highlight: false },
        { name: 'Skryté potravinové šuplíky', price: '16 000', highlight: false },
        { name: 'Pracovní deska Technistone 20 mm', price: '48 000', highlight: false },
        { name: 'Skleněný obklad na míru', price: '22 000', highlight: false },
        { name: 'Spotřebiče Asko', price: '98 000', highlight: false },
        { name: 'Doplňky + odpadkové koše', price: '18 000', highlight: false },
        { name: 'Montáž, doprava, zaměření', price: '28 000', highlight: false },
      ],
      note: '+278 000 Kč oproti základní variantě. Lak na míru NCS/RAL, Blum Merivobox, kamenná deska Technistone, skleněný obklad, Asko spotřebiče.',
      noteBold: '+278 000 Kč oproti základní variantě.',
    },
  ];

  const activeTier = tiers[activeIndex];
  const tabLabels = ['Základní', 'Komfortní', 'Prémiová'];

  const TabButtons = ({ dark }) => (
    <div style={{ display: 'flex', gap: 0, marginBottom: 0 }}>
      {tiers.map((tier, i) => (
        <button
          key={i}
          onClick={() => setPricingActive(i)}
          style={{
            flex: 1,
            padding: '10px 4px',
            fontSize: '13px',
            fontWeight: 600,
            borderRadius: '8px 8px 0 0',
            borderTop: activeIndex === i ? `2px solid ${dark ? 'rgba(255,255,255,0.5)' : 'var(--ink)'}` : `1px solid ${dark ? 'rgba(255,255,255,0.2)' : 'rgba(0,0,0,0.15)'}`,
            borderLeft: activeIndex === i ? `2px solid ${dark ? 'rgba(255,255,255,0.5)' : 'var(--ink)'}` : `1px solid ${dark ? 'rgba(255,255,255,0.2)' : 'rgba(0,0,0,0.15)'}`,
            borderRight: activeIndex === i ? `2px solid ${dark ? 'rgba(255,255,255,0.5)' : 'var(--ink)'}` : `1px solid ${dark ? 'rgba(255,255,255,0.2)' : 'rgba(0,0,0,0.15)'}`,
            borderBottom: activeIndex === i ? `2px solid ${dark ? '#2d4a3e' : '#ffffff'}` : `1px solid ${dark ? 'rgba(255,255,255,0.2)' : 'rgba(0,0,0,0.15)'}`,
            background: dark ? '#2d4a3e' : '#ffffff',
            color: dark ? (activeIndex === i ? '#ffffff' : 'rgba(255,255,255,0.5)') : (activeIndex === i ? 'var(--ink)' : 'var(--ink-muted)'),
            cursor: 'pointer',
            position: 'relative',
            zIndex: activeIndex === i ? 2 : 1,
            marginBottom: activeIndex === i ? '-2px' : '-1px',
          }}
        >
          {tabLabels[i]}
        </button>
      ))}
    </div>
  );

  const CardContent = ({ dark, stretch }) => (
    <div style={{
      border: dark ? '2px solid rgba(255,255,255,0.5)' : '2px solid var(--ink)',
      borderRadius: dark ? '0 0 8px 8px' : '0 0 10px 10px',
      padding: '20px 22px',
      background: dark ? '#2d4a3e' : '#ffffff',
      position: 'relative',
      zIndex: 1,
      marginTop: '-1px',
      flex: stretch ? 1 : undefined,
      display: 'flex',
      flexDirection: 'column',
    }}>
      {/* Tier name */}
      <div style={{ fontSize: '16px', fontWeight: 700, color: dark ? '#ffffff' : 'var(--ink)', marginBottom: '18px' }}>
        {activeTier.label}
      </div>
      {/* Line items */}
      <div style={{ display: 'flex', flexDirection: 'column', gap: '8px', flex: 1 }}>
        {activeTier.items.map((item) => (
          <div key={item.name} style={{ display: 'flex', justifyContent: 'space-between', fontSize: '14px' }}>
            <span style={{ color: dark ? 'rgba(255,255,255,0.75)' : 'var(--ink-soft)' }}>{item.name}</span>
            <span style={{ color: dark ? '#ffffff' : 'var(--ink)', fontWeight: 400 }}>{item.price}</span>
          </div>
        ))}
      </div>
      {/* Divider + total */}
      <div style={{ marginTop: '18px', paddingTop: '14px', borderTop: `1px solid ${dark ? 'rgba(255,255,255,0.25)' : 'var(--line-soft)'}` }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
          <span style={{ fontSize: '14px', color: dark ? 'rgba(255,255,255,0.6)' : 'var(--ink-muted)' }}>Celkem</span>
          <span style={{ fontSize: '20px', fontWeight: 700, color: dark ? '#ffffff' : 'var(--ink)' }}>{activeTier.total}</span>
        </div>
      </div>
    </div>
  );

  return (
    <section id="ceny" style={{ padding: mobile ? '72px 0' : '110px 0', background: '#f5f0eb' }}>
      <div className="container">

        {/* Header */}
        <div className="section-header" style={{ marginBottom: mobile ? '36px' : '48px' }}>
          <div className="eyebrow" style={{ marginBottom: '14px' }}>Na míru vašemu budgetu</div>
          <h2 className="display-l" style={{ marginTop: '0' }}>
            Kolik bude stát ta vaše?
          </h2>
          <p className="body-text" style={{ marginTop: '20px', maxWidth: '520px' }}>
            Stejný styl umíme připravit dostupně i ve špičkovém provedení. Řekněte nám svůj rozpočet — my z něj dostaneme maximum.
          </p>
        </div>

        <div style={{ display: 'flex', flexDirection: mobile ? 'column' : 'row', gap: '0', alignItems: 'stretch', borderRadius: '12px', overflow: 'hidden' }}>
          {/* Photo — first on mobile, right on desktop */}
          {mobile && (
            <div style={{ aspectRatio: '1/1', position: 'relative', background: '#f0ede6' }}>
              {tiers.map((tier, i) => (
                <img key={i} src={tier.img} alt={tier.label} draggable="false" style={{
                  position: 'absolute', inset: 0, width: '100%', height: '100%',
                  objectFit: 'cover', opacity: activeIndex === i ? 1 : 0, transition: 'opacity 0.4s ease',
                }} />
              ))}
            </div>
          )}
          {/* Green pricing panel */}
          <div style={{ flex: mobile ? 'none' : '0 0 44%', background: '#2d4a3e', padding: mobile ? '24px' : '36px', display: 'flex', flexDirection: 'column' }}>
            <div style={{ marginBottom: '28px' }}>
              <div style={{ fontFamily: 'var(--sans)', fontSize: '14px', fontWeight: 500, letterSpacing: '0.18em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.6)', marginBottom: '12px' }}>
                Vzorový příklad
              </div>
              <div style={{ fontSize: mobile ? '24px' : '28px', fontWeight: 400, color: '#ffffff', lineHeight: 1.2 }}>
                Jeden styl, tři různé ceny. Co vše ovlivňuje finální cenu kuchyně?
              </div>
            </div>
            <div style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>
              <TabButtons dark={true} />
              <CardContent dark={true} stretch={true} />
            </div>
          </div>
          {/* Photo — right on desktop only */}
          {!mobile && (
            <div style={{ flex: 1, aspectRatio: '1/1', position: 'relative', background: '#f0ede6', minHeight: 0 }}>
              {tiers.map((tier, i) => (
                <img key={i} src={tier.img} alt={tier.label} draggable="false" style={{
                  position: 'absolute', inset: 0, width: '100%', height: '100%',
                  objectFit: 'cover', opacity: activeIndex === i ? 1 : 0, transition: 'opacity 0.4s ease',
                }} />
              ))}
            </div>
          )}
        </div>

        {/* CTA */}
        <div style={{
          marginTop: mobile ? '48px' : '64px',
          display: 'flex',
          flexDirection: mobile ? 'column' : 'row',
          alignItems: 'center',
          justifyContent: 'center',
          textAlign: mobile ? 'center' : 'left',
          gap: mobile ? '20px' : '32px',
        }}>
          <div>
            <h3 className="serif" style={{ fontSize: mobile ? '28px' : '36px', fontWeight: 400, margin: 0, lineHeight: 1.2 }}>
              Kolik bude stát ta vaše?
            </h3>
            <p className="body-text" style={{ marginTop: '10px', maxWidth: '400px', color: 'var(--ink-muted)' }}>
              Získejte 3D návrh a nacenění zdarma — bez závazků, přímo na vašem studiu.
            </p>
          </div>
          <a href="#kontakt" onClick={(e) => window.scrollToKontakt(e)} className="btn" style={{
            background: '#a6192e',
            color: '#ffffff',
            borderRadius: '999px',
            padding: '15px 36px',
            fontSize: '15px',
            fontWeight: 600,
            letterSpacing: '0.06em',
            textTransform: 'uppercase',
            whiteSpace: 'nowrap',
            flexShrink: 0,
          }}>
            MÁM ZÁJEM →
          </a>
        </div>

      </div>
    </section>
  );
}

window.PricingSection = PricingSection;

/* ============================================
   QUALITY SECTION
   ============================================ */
function QualitySection() {
  const mobile = useIsMobile();

  const cards = [
    {
      img: 'images/kitchengrid.webp',
      tag: 'Prověřeno časem',
      title: 'Jistota opřená o 30 let zkušeností',
      text: 'Kuchyň na míru je investicí na desítky let, proto je důležité vybrat si stabilního partnera. S více než 7 000 úspěšnými realizacemi po celé zemi víme přesně, jaké nástrahy plánování kuchyní obnáší a jak jim včas předejít. S námi neriskujete – sázíte na jistotu a stabilní zázemí.',
    },
    {
      img: 'images/kitchen_factory.webp',
      tag: 'Prověřená výroba',
      title: 'Vyrobeno tam, kde to umí nejlépe',
      text: 'Spolupracujeme s výrobci, jejichž práci a standardy dlouhodobě známe. Převážná část produkce probíhá v Německu, vybraná řešení vznikají v Česku. Společným základem je přesné zpracování a kontrola každého detailu.',
    },
    {
      img: 'images/kitchenbuild.webp',
      tag: 'Stoprocentní servis',
      title: 'Ručíme za každý detail instalace',
      text: 'Žádní externisti, ale výhradně naši vlastní kmenoví montážníci. Postaráme se o kompletní montáž od čistého složení skříněk až po bezpečné zapojení veškeré techniky. Držíme slovo, termíny a stoprocentní kvalitu provedení.',
    },
  ];

  return (
    <section id="zaruka-kvality" style={{ padding: mobile ? '72px 0' : '110px 0', background: '#ffffff' }}>
      <div className="container">

        <div style={{ marginBottom: mobile ? '40px' : '56px' }}>
          <div className="eyebrow" style={{ marginBottom: '14px' }}>Garance klidu</div>
          <h2 className="display-l" style={{ marginTop: '0', maxWidth: mobile ? undefined : '80%' }}>
            Partner, na kterého se můžete spolehnout
          </h2>
          <p className="body-text" style={{ marginTop: '20px', maxWidth: mobile ? undefined : '55%' }}>
            Nejsme jen prodejce kuchyní. Hlídáme <strong>návrh, výrobu, spotřebiče i montáž</strong> a za celý výsledek neseme odpovědnost. Vy tak máte <strong>jednoho partnera</strong>, na kterého se můžete obrátit od první schůzky i roky po dokončení.
          </p>
        </div>

        <div style={{
          display: 'grid',
          gridTemplateColumns: mobile ? '1fr' : 'repeat(3, 1fr)',
          gap: mobile ? '24px' : '28px',
        }}>
          {cards.map((card) => (
            <div key={card.title} style={{
              borderRadius: '10px',
              overflow: 'hidden',
              background: '#f5f2ee',
            }}>
              <div style={{
                aspectRatio: '4/3',
                overflow: 'hidden',
                background: '#f0ede6',
              }}>
                <img
                  src={card.img}
                  alt={card.title}
                  draggable="false"
                  style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}
                />
              </div>
              <div style={{ padding: mobile ? '20px 22px 24px' : '22px 26px 28px' }}>
                <div style={{
                  fontSize: '11px',
                  fontWeight: 600,
                  letterSpacing: '0.1em',
                  textTransform: 'uppercase',
                  color: 'var(--ink-muted)',
                  marginBottom: '10px',
                }}>
                  {card.tag}
                </div>
                <h3 style={{
                  fontFamily: 'var(--sans)',
                  fontSize: mobile ? '18px' : '20px',
                  fontWeight: 700,
                  lineHeight: 1.2,
                  color: 'var(--ink)',
                  marginBottom: '10px',
                }}>
                  {card.title}
                </h3>
                <p style={{
                  fontSize: '15px',
                  lineHeight: 1.65,
                  color: 'var(--ink-soft)',
                  fontWeight: 300,
                  margin: 0,
                }}>
                  {card.text}
                </p>
              </div>
            </div>
          ))}
        </div>

      </div>
    </section>
  );
}

window.QualitySection = QualitySection;
