function Logo({ size = 28, href = './' }) {
  // Инлайн-SVG (не <img>): iOS Safari мылит SVG-картинки внутри sticky/
  // composited-родителя — векторная разметка в DOM растрится в полном DPR.
  return (
    <a href={href} aria-label="Фидли — на главную" style={{ display: 'inline-flex' }}>
      <svg
        role="img"
        aria-label="Фидли"
        height={size}
        viewBox="0 0 1077 300"
        fill="none"
        xmlns="http://www.w3.org/2000/svg"
        style={{ width: 'auto', display: 'block' }}
      >
        <path d="M674.604 207.921H692.264V249H662.14V233H592.468V249H561.602V207.921H570.356C572.879 206.338 574.908 203.815 576.441 200.353C578.024 196.89 579.311 192.809 580.3 188.11C581.339 183.411 582.13 178.341 582.674 172.899C583.267 167.409 583.786 161.869 584.231 156.279L587.2 119.032H674.604V207.921ZM359.474 97.3662H361.254C373.422 97.3662 384.206 99.9386 393.604 105.083C403.052 110.227 410.447 117.474 415.789 126.823C421.181 136.123 423.877 147.054 423.877 159.618C423.877 171.787 421.181 182.397 415.789 191.449C410.447 200.501 403.052 207.55 393.604 212.596C384.206 217.592 373.422 220.09 361.254 220.09H359.474V233H328.978V220.09H327.271C315.054 220.09 304.22 217.616 294.772 212.67C285.325 207.674 277.905 200.65 272.514 191.598C267.171 182.546 264.5 171.861 264.5 159.544C264.5 146.98 267.196 136.048 272.588 126.749C278.029 117.4 285.473 110.178 294.921 105.083C304.369 99.9386 315.153 97.3662 327.271 97.3662H328.978V85H359.474V97.3662ZM475.062 191.301L516.093 119.032H547.256V233H517.132V160.509L476.249 233H444.863V119.032H475.062V191.301ZM810.394 233H780.27V143.889H752.148L750.367 178.688C749.922 188.234 748.759 196.445 746.88 203.32C745.05 210.196 742.503 215.836 739.238 220.238C735.974 224.591 732.041 227.806 727.44 229.884C722.84 231.961 717.498 233 711.414 233H701.916L701.768 207.921H705.552C708.223 207.921 710.523 207.278 712.452 205.992C714.431 204.657 716.064 202.505 717.35 199.537C718.636 196.569 719.65 192.636 720.392 187.739C721.134 182.793 721.629 176.708 721.876 169.486L723.73 119.032H810.394V233ZM863.007 191.301L904.038 119.032H935.201V233H905.077V160.509L864.193 233H832.809V119.032H863.007V191.301ZM612.872 156.279C612.031 168.448 610.819 178.786 609.236 187.294C607.653 195.752 605.18 202.628 601.816 207.921H644.777V143.369H614.06L612.872 156.279ZM327.271 124.226C320.742 124.226 314.979 125.537 309.983 128.158C305.037 130.73 301.178 134.639 298.408 139.882C295.638 145.125 294.253 151.679 294.253 159.544C294.253 167.063 295.663 173.32 298.482 178.316C301.351 183.312 305.26 187.046 310.206 189.52C315.153 191.993 320.841 193.229 327.271 193.229H328.978V124.226H327.271ZM359.474 193.229H361.477C367.957 193.229 373.62 191.968 378.468 189.445C383.365 186.923 387.149 183.164 389.82 178.168C392.541 173.172 393.901 166.988 393.901 159.618C393.901 151.753 392.541 145.199 389.82 139.956C387.149 134.713 383.365 130.78 378.468 128.158C373.62 125.537 367.956 124.226 361.477 124.226H359.474V193.229Z" fill="#7A60FF"/>
        <path d="M178 49C210.033 49 236 74.9675 236 107V203C236 235.033 210.033 261 178 261H119.848C118.49 261 117.161 261.395 116.023 262.137L73.416 289.924C67.4296 293.828 59.5001 289.533 59.5 282.386V261.903C59.4997 261.368 59.0738 260.928 58.5391 260.896C28.1178 259.106 4 233.871 4 203V107C4 74.9675 29.9675 49 62 49H178ZM128.56 85.1074C125.865 76.8156 114.135 76.8157 111.44 85.1074L99.5156 121.807C98.5784 124.691 95.8909 126.644 92.8584 126.644H54.2705C45.5523 126.644 41.9273 137.8 48.9805 142.925L80.1992 165.605C82.6525 167.388 83.679 170.548 82.7422 173.432L70.8174 210.131C68.1232 218.423 77.6136 225.318 84.667 220.193L109.923 201.844L155.099 169.022L191.019 142.925C198.072 137.8 194.447 126.644 185.729 126.644H147.141C144.108 126.643 141.421 124.691 140.483 121.807L128.56 85.1074ZM186.089 127.65C186.2 127.655 186.31 127.661 186.419 127.67L186.089 127.65ZM100.361 122.422C100.34 122.479 100.316 122.536 100.294 122.593C100.318 122.533 100.342 122.473 100.364 122.412L100.361 122.422ZM125.52 82.0479C125.671 82.1919 125.818 82.3426 125.959 82.501C125.889 82.4219 125.816 82.345 125.743 82.2695L125.52 82.0479ZM124.558 81.2705L124.808 81.4482C124.725 81.387 124.641 81.3281 124.557 81.2705L124.301 81.1035C124.387 81.1575 124.473 81.2129 124.558 81.2705Z" fill="#7A60FF"/>
        <path d="M941.4 99V93.1C946.133 89.3667 950.633 85.6 954.9 81.8C959.233 78 963.067 74.2333 966.4 70.5C969.733 66.7 972.333 63 974.2 59.4C976.133 55.8 977.1 52.3333 977.1 49C977.1 46.5333 976.667 44.2667 975.8 42.2C974.933 40.0667 973.533 38.3333 971.6 37C969.733 35.6667 967.2 35 964 35C960.867 35 958.267 35.7 956.2 37.1C954.133 38.4333 952.567 40.2333 951.5 42.5C950.5 44.7 950 47.1333 950 49.8H941.9C941.967 45.2 942.933 41.2667 944.8 38C946.733 34.6667 949.367 32.1333 952.7 30.4C956.033 28.6667 959.833 27.8 964.1 27.8C968.3 27.8 972 28.6 975.2 30.2C978.4 31.7333 980.9 34.0333 982.7 37.1C984.567 40.1667 985.5 44.0333 985.5 48.7C985.5 51.9667 984.8 55.2333 983.4 58.5C982.067 61.7667 980.267 64.9667 978 68.1C975.733 71.1667 973.2 74.1333 970.4 77C967.667 79.8667 964.833 82.5667 961.9 85.1C959.033 87.6333 956.333 89.9333 953.8 92H987.9V99H941.4ZM1002.62 99.5C1000.95 99.5 999.551 98.9667 998.417 97.9C997.351 96.7667 996.817 95.4 996.817 93.8C996.817 92.2 997.351 90.8667 998.417 89.8C999.551 88.6667 1000.95 88.1 1002.62 88.1C1004.28 88.1 1005.65 88.6667 1006.72 89.8C1007.78 90.8667 1008.32 92.2 1008.32 93.8C1008.32 95.4 1007.78 96.7667 1006.72 97.9C1005.65 98.9667 1004.28 99.5 1002.62 99.5ZM1042.74 100.2C1036.6 100.2 1031.3 98.7 1026.84 95.7C1022.44 92.6333 1019.07 88.4 1016.74 83C1014.4 77.5333 1013.24 71.2 1013.24 64C1013.24 56.8 1014.4 50.5 1016.74 45.1C1019.07 39.6333 1022.44 35.4 1026.84 32.4C1031.3 29.3333 1036.6 27.8 1042.74 27.8C1048.87 27.8 1054.1 29.3333 1058.44 32.4C1062.84 35.4 1066.2 39.6333 1068.54 45.1C1070.87 50.5 1072.04 56.8 1072.04 64C1072.04 71.2 1070.87 77.5333 1068.54 83C1066.2 88.4 1062.84 92.6333 1058.44 95.7C1054.1 98.7 1048.87 100.2 1042.74 100.2ZM1042.64 92.8C1046.64 92.8 1050.2 91.6667 1053.34 89.4C1056.47 87.0667 1058.94 83.7667 1060.74 79.5C1062.54 75.1667 1063.44 70 1063.44 64C1063.44 58 1062.54 52.8667 1060.74 48.6C1058.94 44.2667 1056.47 40.9667 1053.34 38.7C1050.2 36.4333 1046.64 35.3 1042.64 35.3C1038.64 35.3 1035.04 36.4333 1031.84 38.7C1028.7 40.9667 1026.24 44.2667 1024.44 48.6C1022.7 52.8667 1021.84 58 1021.84 64C1021.84 70 1022.7 75.1667 1024.44 79.5C1026.24 83.7667 1028.7 87.0667 1031.84 89.4C1035.04 91.6667 1038.64 92.8 1042.64 92.8Z" fill="#7A60FF"/>
      </svg>
    </a>
  );
}

function NavBar() {
  const [scrolled, setScrolled] = React.useState(false);
  const [loginOpen, setLoginOpen] = React.useState(false);
  const [menuOpen, setMenuOpen] = React.useState(false);
  const [isMobile, setIsMobile] = React.useState(
    typeof window !== 'undefined' && window.matchMedia('(max-width: 860px)').matches
  );

  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 12);
    window.addEventListener('scroll', onScroll);
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  React.useEffect(() => {
    const mq = window.matchMedia('(max-width: 860px)');
    const handler = (e) => setIsMobile(e.matches);
    mq.addEventListener ? mq.addEventListener('change', handler) : mq.addListener(handler);
    return () => {
      mq.removeEventListener ? mq.removeEventListener('change', handler) : mq.removeListener(handler);
    };
  }, []);

  React.useEffect(() => {
    if (!menuOpen) return;
    const onKey = (e) => { if (e.key === 'Escape') setMenuOpen(false); };
    window.addEventListener('keydown', onKey);
    document.body.style.overflow = 'hidden';
    return () => {
      window.removeEventListener('keydown', onKey);
      document.body.style.overflow = '';
    };
  }, [menuOpen]);

  const items = [
    { label: 'Возможности', href: '#features' },
    { label: 'Интеграции',  href: '#integrations' },
    { label: 'Карта пути',  href: '#journey' },
    { label: 'Цены',        href: 'pricing/' },
    { label: 'Контакты',    href: '#contact' },
  ];

  const openLogin = () => { setMenuOpen(false); setLoginOpen(true); };

  return (
    <React.Fragment>
      <header style={{
        position: 'sticky', top: 0, zIndex: 50,
        background: scrolled ? 'rgba(255,255,255,0.85)' : '#ffffff',
        backdropFilter: scrolled ? 'saturate(140%) blur(10px)' : 'none',
        borderBottom: scrolled ? '1px solid var(--line)' : '1px solid transparent',
        transition: 'all 0.2s',
      }}>
        <div className="container" style={{
          display: 'flex', alignItems: 'center', justifyContent: 'space-between',
          height: 68,
        }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 48 }}>
            <Logo />
            <nav style={{ display: 'flex', gap: 28 }}>
              {items.map(i => (
                <a key={i.href} href={i.href} style={{
                  fontSize: 14, color: 'var(--ink-2)', fontWeight: 500,
                }}>
                  {i.label}
                </a>
              ))}
            </nav>
          </div>
          <div className="nav-actions" style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
            {!isMobile && (
              <button
                type="button"
                onClick={() => setLoginOpen(true)}
                className="nav-login"
                style={{
                  fontSize: 14, color: 'var(--ink-2)', fontWeight: 500,
                  padding: '8px 12px', background: 'none', border: 'none',
                  cursor: 'pointer', fontFamily: 'inherit',
                }}
              >
                Войти
              </button>
            )}
            <button
              type="button"
              aria-label="Меню"
              onClick={() => setMenuOpen(true)}
              className="nav-burger"
              style={{
                display: 'none',
                width: 40, height: 40, borderRadius: 10,
                border: 'none', background: 'transparent',
                alignItems: 'center', justifyContent: 'center',
                cursor: 'pointer', padding: 0, color: 'var(--ink)',
              }}
            >
              <svg width="22" height="22" viewBox="0 0 22 22" fill="none">
                <path d="M3 6 H19 M3 11 H19 M3 16 H19" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
              </svg>
            </button>
          </div>
          <style>{`
            @media (max-width: 860px) {
              .nav-login { display: none !important; }
              .nav-burger { display: inline-flex !important; }
            }
          `}</style>
        </div>
      </header>

      {/* Mobile menu drawer */}
      {menuOpen && (
        <div
          style={{
            position: 'fixed', inset: 0, zIndex: 90,
            display: 'flex', justifyContent: 'flex-end',
          }}
          onClick={() => setMenuOpen(false)}
        >
          <div
            style={{
              position: 'absolute', inset: 0,
              background: 'rgba(13,13,18,0.45)',
              backdropFilter: 'blur(2px)',
              animation: 'nav-fade 0.18s ease both',
            }}
          />
          <div
            role="dialog"
            aria-modal="true"
            onClick={(e) => e.stopPropagation()}
            style={{
              position: 'relative',
              width: 'min(86vw, 360px)', height: '100%',
              background: '#fff', color: 'var(--ink)',
              boxShadow: '-20px 0 50px -20px rgba(13,13,18,0.25)',
              display: 'flex', flexDirection: 'column',
              animation: 'nav-slide 0.22s cubic-bezier(0.2, 0.7, 0.2, 1) both',
            }}
          >
            <div style={{
              display: 'flex', alignItems: 'center', justifyContent: 'space-between',
              padding: '18px 20px', borderBottom: '1px solid var(--line)',
            }}>
              <Logo />
              <button
                type="button"
                aria-label="Закрыть"
                onClick={() => setMenuOpen(false)}
                style={{
                  width: 36, height: 36, borderRadius: '50%',
                  background: 'transparent', color: 'var(--ink-2)',
                  border: 'none', cursor: 'pointer',
                  display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
                }}
              >
                <svg width="20" height="20" viewBox="0 0 20 20">
                  <path d="M5 5 L15 15 M15 5 L5 15" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
                </svg>
              </button>
            </div>

            <nav style={{
              flex: 1, padding: '12px 8px', display: 'flex', flexDirection: 'column',
              gap: 2,
            }}>
              {items.map(i => (
                <a
                  key={i.href}
                  href={i.href}
                  onClick={() => setMenuOpen(false)}
                  style={{
                    padding: '14px 16px', borderRadius: 12,
                    fontSize: 17, fontWeight: 500, color: 'var(--ink)',
                    textDecoration: 'none',
                  }}
                >
                  {i.label}
                </a>
              ))}
            </nav>

            <div style={{
              padding: '16px 20px 24px', borderTop: '1px solid var(--line)',
              display: 'flex', flexDirection: 'column', gap: 10,
            }}>
              <a
                href="#contact"
                onClick={() => setMenuOpen(false)}
                style={{
                  width: '100%', padding: '14px 20px',
                  borderRadius: 999, border: 'none',
                  background: 'var(--ink)', color: 'var(--bg)',
                  fontSize: 15, fontWeight: 600, fontFamily: 'inherit',
                  textDecoration: 'none', boxSizing: 'border-box',
                  display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 8,
                }}
              >
                Запросить демо
                <svg width="12" height="12" viewBox="0 0 12 12"><path d="M3 6 L9 6 M6 3 L9 6 L6 9" stroke="currentColor" strokeWidth="1.6" fill="none" strokeLinecap="round" strokeLinejoin="round" /></svg>
              </a>
              <button
                type="button"
                onClick={openLogin}
                style={{
                  width: '100%', padding: '14px 20px',
                  borderRadius: 999, border: '1px solid var(--line)',
                  background: 'var(--card)', color: 'var(--ink)',
                  fontSize: 15, fontWeight: 600, fontFamily: 'inherit',
                  cursor: 'pointer',
                  display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 8,
                }}
              >
                <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
                  <path d="M9 4 L12 7 L9 10 M12 7 H4 M5.5 2 H3 V12 H5.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
                </svg>
                Войти
              </button>
            </div>
          </div>
          <style>{`
            @keyframes nav-slide {
              from { transform: translateX(100%); }
              to   { transform: translateX(0); }
            }
            @keyframes nav-fade {
              from { opacity: 0; }
              to   { opacity: 1; }
            }
          `}</style>
        </div>
      )}

      {window.LoginModal && <window.LoginModal open={loginOpen} onClose={() => setLoginOpen(false)} />}
    </React.Fragment>
  );
}

window.NavBar = NavBar;
window.Logo = Logo;
