const { useState } = React;
const { Button, Input, StatusBadge, SectionLabel, Card, MetricCard, Marquee, LuxeHeading, TopBar } = window.KSystemDesignSystem_e702cb;

/* Nine modules, verified against backend/app/agents/, backend/app/routers/, frontend/app/.
   Each is shown as the kitchen above and the live product panel below. */

const PIPELINE = [
  { label: 'Natural language', icon: 'message-square', note: 'PT · EN · any' },
  { label: 'Chef Agent', icon: 'chef-hat', note: 'Seasonal recipes' },
  { label: 'Inventory Agent', icon: 'package', note: 'Live tracking' },
  { label: 'Prep orchestrator', icon: 'list-checks', note: 'Plans & orders' },
  { label: 'Actionable output', icon: 'check', note: 'Prep · POs · costs' },
];

/* Priced exactly as the pitch deck prices it. */
const TIERS = [
  { name: 'Basic', price: '€99', period: '/ month' },
  { name: 'Standard', price: '€249', period: '/ month' },
  { name: 'Premium', price: '€499', period: '/ month', featured: true },
  { name: 'Enterprise', price: 'Custom', period: '/ annual' },
];
const SPEC_ROWS = [
  ['Recipes', ['150', '500', '∞', '∞']],
  ['Stock items', ['200', '600', '∞', '∞']],
  ['Chef Agent tokens', ['500K', '2M', '∞', '∞']],
  ['Users', ['2', '5', '15', '∞']],
  ['Sites', ['1', '1', '2', 'Multi']],
];

const PROBLEMS = [
  ['Inventory chaos', 'Manual sheets lead to surprise stock-outs mid-service and expired product.'],
  ['Recipe inconsistency', "Dishes live in the chef's notebook — not linked to real inventory or costs."],
  ['5–10 hrs / week lost', 'Chefs and managers burn admin time instead of running the pass.'],
  ['Purchasing blind spots', 'Over-ordering creates waste, under-ordering kills covers — no smart triggers.'],
];

function Icon({ name, size = 24 }) {
  const ref = React.useRef(null);
  React.useEffect(() => {
    if (ref.current && window.lucide) {
      ref.current.innerHTML = '<i data-lucide="' + name + '"></i>';
      window.lucide.createIcons({ attrs: { 'stroke-width': 1.5, width: size, height: size } });
    }
  }, [name, size]);
  return <span ref={ref} style={{ display: 'inline-flex' }} />;
}

const PHOTO = 'assets/photos/';
const go = (h) => (window.KMotion && window.KMotion.ready ? window.KMotion.scrollTo(h) : (window.location.hash = h));

/* Photographic frame: image, hairline, and a scrim. */
function Photo({ src, alt = '', ratio = '16 / 10', scrim = 0.35, style }) {
  return (
    <div data-photo style={{ position: 'relative', aspectRatio: ratio, overflow: 'hidden', border: 'var(--border-hairline-w) solid var(--border-hairline)', ...style }}>
      <img data-photo-img src={PHOTO + src} alt={alt} style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', filter: 'brightness(1.14) contrast(1.02)', display: 'block' }} />
      <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(to top, rgba(10,10,10,' + (scrim + 0.45) + ') 0%, rgba(10,10,10,' + scrim * 0.3 + ') 55%, rgba(10,10,10,0) 100%)' }} />
    </div>
  );
}

const SHELL = { maxWidth: 'var(--container-max)', margin: '0 auto', padding: '0 var(--space-8)' };
const HAIRLINE = 'var(--border-hairline-w) solid var(--border-hairline)';
const HAIRLINE_INK = 'var(--border-hairline-w) solid rgba(0,0,0,0.14)';
const MONO = { fontFamily: 'var(--font-mono)', fontSize: 'var(--text-base)', lineHeight: 'var(--leading-relaxed)' };
const LABEL = { fontFamily: 'var(--font-mono)', fontSize: 'var(--text-micro)', textTransform: 'uppercase', letterSpacing: 'var(--track-label)' };
const STRUCT = { fontFamily: 'var(--font-structural)', textTransform: 'uppercase', letterSpacing: '0.05em' };

/* ── Product surfaces ───────────────────────────────────────────────
   Real interface built from the design system, standing in for
   screenshots. Every figure below is internally consistent. */

const { BatchSheet, AnalyticsTrend, RecipeSheet, AgentThread, StockLedger, SalesReadout, ResearchFeed, SupplierMatch, MenuComposer } = window;

/* ── Sections ─────────────────────────────────────────────────────── */

function Hero({ eyebrow, headline, subhead, note }) {
  return (
    <section data-hero style={{ position: 'relative', background: 'var(--k-black)', borderBottom: HAIRLINE, minHeight: 'min(92vh, 880px)', display: 'grid', alignItems: 'end', overflow: 'hidden' }}>
      <img data-hero-img src={PHOTO + 'hero-grill.jpg'} alt="Dry-aged rib on the open grill" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: '68% 45%', filter: 'brightness(1.55) contrast(1.04) saturate(1.06)', display: 'block' }} />
      <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(to top, rgba(8,8,8,0.88) 0%, rgba(8,8,8,0.6) 20%, rgba(8,8,8,0.3) 48%, rgba(8,8,8,0.16) 78%, rgba(8,8,8,0.4) 100%)' }} />
      <div data-hero-content style={{ position: 'relative', ...SHELL, paddingTop: 'var(--space-24)', paddingBottom: 'var(--space-12)', boxSizing: 'border-box', width: '100%' }}>
        <div data-hero-fade style={{ ...LABEL, color: 'var(--k-orange)', marginBottom: 'var(--space-8)' }}>{eyebrow ?? 'AI-powered kitchen intelligence'}</div>
        <h1 data-hero-title style={{ fontFamily: 'var(--font-structural)', fontSize: 'clamp(2.5rem, 11.5vw, 11rem)', whiteSpace: 'nowrap', lineHeight: 0.86, letterSpacing: '-0.03em', textTransform: 'uppercase', color: 'var(--k-bone)', margin: '0 0 var(--space-10)' }}>{headline ?? 'K—System'}</h1>
        <div data-hero-fade style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 22rem), 1fr))', gap: 'var(--space-12)', alignItems: 'end', paddingBottom: 'var(--space-12)' }}>
          <LuxeHeading as="h2" size="clamp(1.5rem,2.8vw,2.5rem)" style={{ maxWidth: '24ch', margin: 0 }}>{subhead ?? 'Seasonal menus, inventory and portioning turned into measurable profit.'}</LuxeHeading>
          <div style={{ display: 'grid', gap: 'var(--space-8)', justifyItems: 'start' }}>
            <p style={{ ...MONO, fontSize: 'var(--text-sm)', color: 'var(--k-bone-dim)', maxWidth: '40ch', margin: 0 }}>{note ?? 'Without asking chefs to become accountants. Costed to the gram, metric only.'}</p>
            <div data-hero-cta style={{ display: 'flex', gap: 'var(--space-4)', flexWrap: 'wrap' }}>
              <Button variant="solid" size="lg" onClick={() => go('#access')}>Request access</Button>
              <Button variant="outline" size="lg" onClick={() => go('#modules')}>See the modules</Button>
            </div>
          </div>
        </div>
        <div data-hero-fade data-count style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 13rem), 1fr))', borderTop: HAIRLINE }}>
          {[['Nine modules', 'One service'], ['Metric only', 'Costed to the gram'], ['From €99', 'Per month']].map(([k, v], i) => (
            <div key={k} style={{ padding: 'var(--space-6) var(--space-6) 0 0', borderLeft: i === 0 ? 'none' : HAIRLINE, paddingLeft: i === 0 ? 0 : 'var(--space-6)' }}>
              <div style={{ ...STRUCT, fontSize: 'var(--text-sm)', color: 'var(--k-bone)', marginBottom: 'var(--space-2)' }}>{k}</div>
              <div style={{ ...LABEL, color: 'var(--k-bone-faint)' }}>{v}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function Problem() {
  return (
    <section data-cut style={{ background: 'var(--surface-luxe)', borderBottom: HAIRLINE }}>
      <div style={{ ...SHELL, padding: 'var(--space-24) var(--space-8)' }}>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 22rem), 1fr))', gap: 'var(--space-16)', alignItems: 'start' }}>
          <div data-sticky style={{ position: 'sticky', top: 'var(--space-24)' }}>
            <SectionLabel rule style={{ marginBottom: 'var(--space-10)' }}>The problem</SectionLabel>
            <div data-count style={{ fontFamily: 'var(--font-luxe)', fontSize: 'clamp(4.5rem,11vw,9rem)', lineHeight: 0.85, color: 'var(--k-orange)', marginBottom: 'var(--space-6)' }}>30–40%</div>
            <p style={{ fontFamily: 'var(--font-luxe)', fontSize: 'var(--text-xl)', lineHeight: 'var(--leading-relaxed)', color: 'var(--k-bone-dim)', maxWidth: '24ch', margin: 0 }}>
              Average food cost in fine dining — most of it preventable waste.
            </p>
            <Photo src="spices-mortar.jpg" alt="Chef grinding spices by hand" ratio="4 / 3" style={{ marginTop: 'var(--space-10)' }} />
          </div>
          <div>
            <LuxeHeading size="clamp(2rem, 4.5vw, var(--text-luxe-display))" style={{ textTransform: 'uppercase', marginBottom: 'var(--space-10)', maxWidth: '18ch', overflowWrap: 'break-word' }}>Kitchens still run on spreadsheets and guesswork</LuxeHeading>
            <div data-stagger style={{ borderTop: HAIRLINE }}>
              {PROBLEMS.map(([title, desc]) => (
                <div key={title} style={{ display: 'grid', gridTemplateColumns: 'minmax(0,0.9fr) minmax(0,1.4fr)', gap: 'var(--space-8)', padding: 'var(--space-6) 0', borderBottom: HAIRLINE }}>
                  <div style={{ ...STRUCT, fontSize: 'var(--text-sm)', color: 'var(--k-bone)', lineHeight: 1.3 }}>{title}</div>
                  <p style={{ ...MONO, fontSize: 'var(--text-sm)', color: 'var(--k-bone-faint)', margin: 0 }}>{desc}</p>
                </div>
              ))}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

/* Light band: pipeline diagram. */
function HowItWorks({ showMetrics = true }) {
  return (
    <section data-cut style={{ background: 'var(--k-bone)', color: 'var(--k-ink)' }}>
      <div style={{ ...SHELL, padding: 'var(--space-24) var(--space-8)' }}>
        <SectionLabel tone="light" rule style={{ marginBottom: 'var(--space-4)' }}>How it works</SectionLabel>
        <h2 style={{ fontFamily: 'var(--font-structural)', fontSize: 'clamp(2rem,4.5vw,3.25rem)', lineHeight: 1, letterSpacing: 'var(--track-hero)', textTransform: 'uppercase', margin: '0 0 var(--space-12)', maxWidth: '20ch' }}>Language in, deterministic output back</h2>
        <div data-stagger style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 11rem), 1fr))', gap: 0, borderTop: HAIRLINE_INK, borderBottom: HAIRLINE_INK }}>
          {PIPELINE.map((s, i) => (
            <div key={s.label} style={{ display: 'grid', gap: 'var(--space-4)', alignContent: 'start', padding: 'var(--space-8) var(--space-6) var(--space-8) 0', borderLeft: i === 0 ? 'none' : HAIRLINE_INK, paddingLeft: i === 0 ? 0 : 'var(--space-6)' }}>
              <Icon name={s.icon} size={22} />
              <div style={{ ...STRUCT, fontSize: 'var(--text-sm)', lineHeight: 1.3 }}>{s.label}</div>
              <div style={{ ...LABEL, color: 'rgba(0,0,0,0.5)' }}>{s.note}</div>
            </div>
          ))}
        </div>
        <p data-split style={{ fontFamily: 'var(--font-luxe)', fontSize: 'clamp(1.4rem,2.6vw,2.2rem)', lineHeight: 'var(--leading-tight)', maxWidth: '34ch', margin: 'var(--space-12) 0 0' }}>
          An AI agent understands what you say. Stock, costs and orders run on deterministic business rules — <span style={{ borderBottom: '2px solid var(--k-orange)' }}>zero hallucination.</span>
        </p>
      </div>
    </section>
  );
}

function Modules() {
  const cards = [
    ['01', 'Recipe Bible', 'Every dish costed to the gram. Change a supplier price and every plate that uses it re-costs itself.', 'recipe-bible.jpg', <RecipeSheet key="rb" />],
    ['02', 'Inventory', 'Record the sale and the ingredients come off stock automatically, through the recipe.', 'inventory-shelves.jpg', <StockLedger key="iv" />],
    ['03', 'Chef Agent', 'Dictate the dish and it lands in the Bible already costed. Answers in PT or EN.', 'chef-agent.jpg', <AgentThread key="ca" />],
    ['04', 'Prepared Recipes', 'Turn recipes into consistent, repeatable production processes. K-System organizes recipes, ingredients, quantities, costs, and preparation instructions, helping teams maintain consistency and reduce waste.', ['prepared-recipes.jpg', 'pass-slicing.jpg'], <BatchSheet key="pr" />],
    ['05', 'Suppliers', 'Their catalogue maps onto your stock items, so the order goes out against the right line.', 'suppliers-goods-in.jpg', <SupplierMatch key="sm" />],
    ['06', 'AI Analytics', 'Analyzes your business data to uncover costs, margins, sales, waste, and trends. AI Analytics turns operational data into actionable insights, helping you identify problems and opportunities.', ['ai-analytics.jpg', 'spices-mortar.jpg'], <AnalyticsTrend key="aa" />],
    ['07', 'Sales Intelligence', 'Five agents read revenue, menu, customers and costs together, then hand back what to do.', 'the-pass.jpg', <SalesReadout key="si" />],
    ['08', 'Seasonal Menu', 'Compose the season with seasonal tags per dish and a live margin before it reaches the board.', 'seasonal-board.jpg', <MenuComposer key="mc" />],
    ['09', 'AI Research', 'Food trends and artisan suppliers, researched inside the system and dated to the season.', 'ai-research.jpg', <ResearchFeed key="rf" />],
  ];
  return (
    <section data-cut id="modules" style={{ background: 'var(--surface-luxe)', borderTop: HAIRLINE }}>
      <div style={{ ...SHELL, padding: 'var(--space-24) var(--space-8)' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', gap: 'var(--space-8)', marginBottom: 'var(--space-12)', flexWrap: 'wrap' }}>
          <div>
            <SectionLabel style={{ marginBottom: 'var(--space-4)' }}>Nine modules</SectionLabel>
            <h2 style={{ fontFamily: 'var(--font-structural)', fontSize: 'clamp(2.5rem,6vw,4.5rem)', lineHeight: 0.9, letterSpacing: 'var(--track-hero)', color: 'var(--k-bone)', margin: 0 }}>One system,<br />one service.</h2>
          </div>
          <p style={{ ...MONO, fontSize: 'var(--text-sm)', color: 'var(--k-bone-faint)', maxWidth: '30ch', margin: 0 }}>All nine as they run during service — the kitchen above, the screen below.</p>
        </div>
        </div>
      <div>
        {cards.map(([num, title, desc, photo, panel], i) => (<React.Fragment key={num}>
          <article data-mod-sheet style={{ position: 'sticky', top: 0, minHeight: '100vh', display: 'grid', overflow: 'hidden', background: 'var(--k-black)', borderRadius: i === 0 ? 0 : '28px 28px 0 0', boxShadow: i === 0 ? 'none' : '0 -30px 60px -20px rgba(0,0,0,0.7)', borderTop: HAIRLINE }}>
            <img src={PHOTO + (Array.isArray(photo) ? photo[0] : photo)} onError={Array.isArray(photo) ? (e) => { if (!e.currentTarget.dataset.fb) { e.currentTarget.dataset.fb = '1'; e.currentTarget.src = PHOTO + photo[1]; } } : undefined} alt={title} style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', filter: 'brightness(1.1) contrast(1.02)', display: 'block' }} />
            <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(90deg, rgba(8,8,8,0.92) 0%, rgba(8,8,8,0.7) 38%, rgba(8,8,8,0.35) 70%, rgba(8,8,8,0.55) 100%)' }}></div>
            <div data-mod-grid style={{ position: 'relative', ...SHELL, width: '100%', boxSizing: 'border-box', display: 'grid', gridTemplateColumns: 'minmax(0,1fr) minmax(0,27rem)', gap: 'var(--space-12)', alignItems: 'center', padding: 'var(--space-24) var(--space-8) var(--space-16)' }}>
              <div data-mod-text style={{ display: 'grid', gap: 'var(--space-6)', alignContent: 'start', alignSelf: 'stretch' }}>
                <span style={{ ...LABEL, color: 'var(--k-bone-faint)' }}>Module {num} / 09</span>
                <span aria-hidden="true" style={{ fontFamily: 'var(--font-structural)', fontSize: 'clamp(7rem,17vw,16rem)', lineHeight: 0.78, letterSpacing: '-0.05em', color: 'transparent', WebkitTextStroke: '1.5px var(--k-orange)' }}>{num}</span>
                <h3 style={{ ...STRUCT, fontSize: 'clamp(2.25rem,4.6vw,4.25rem)', color: 'var(--k-bone)', margin: 0, letterSpacing: '-0.02em', lineHeight: 0.92 }}>{title}</h3>
                <p style={{ ...MONO, fontSize: 'var(--text-sm)', color: 'var(--k-bone-dim)', margin: 0, maxWidth: '38ch' }}>{desc}</p>
              </div>
              <div data-float style={{ borderRadius: '28px', boxShadow: '0 40px 90px -30px rgba(0,0,0,0.85)' }}>{panel}</div>
            </div>
          </article>
          {i < cards.length - 1 && <div data-mod-hold aria-hidden="true" style={{ height: '45vh' }}></div>}
        </React.Fragment>))}
      </div>
    </section>
  );
}

/* Full-bleed band: the flat-lay's empty right side carries the line. */
function Season() {
  return (
    <section data-cut style={{ position: 'relative', background: 'var(--k-black)', borderTop: HAIRLINE, minHeight: 'min(70vh, 620px)', display: 'grid', alignItems: 'center', overflow: 'hidden' }}>
      <img data-bleed src={PHOTO + 'seasonal-plating.jpg'} alt="Finishing a plate at the terrace pass" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: '60% 50%', filter: 'brightness(1.18) contrast(1.02)', display: 'block' }} />
      <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(90deg, rgba(8,8,8,0.8) 0%, rgba(8,8,8,0.42) 48%, rgba(8,8,8,0.08) 100%)' }} />
      <div style={{ position: 'relative', ...SHELL, padding: 'var(--space-20) var(--space-8)', boxSizing: 'border-box', width: '100%' }}>
        <SectionLabel style={{ marginBottom: 'var(--space-6)' }}>The season</SectionLabel>
        <LuxeHeading size="clamp(1.75rem, 4vw, 3.5rem)" style={{ maxWidth: '26ch', marginBottom: 'var(--space-8)' }}>Compose the season against what the kitchen can actually buy.</LuxeHeading>
        <p style={{ ...MONO, fontSize: 'var(--text-sm)', color: 'var(--k-bone-dim)', maxWidth: '38ch', margin: 0 }}>Seasonal tags per dish, chef suggestions, and a live margin on every plate before it reaches the printed menu.</p>
      </div>
    </section>
  );
}

/* The flat-lay's negative space on the right carries the claim. */
function Determinism() {
  return (
    <section data-cut style={{ position: 'relative', background: 'var(--k-black)', borderTop: HAIRLINE, minHeight: 'min(62vh, 540px)', display: 'grid', alignItems: 'center', overflow: 'hidden' }}>
      <img data-bleed src={PHOTO + 'spices-flatlay.jpg'} alt="Spices and herbs laid out on slate" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: '35% 50%', filter: 'brightness(1.22) contrast(1.03)', display: 'block' }} />
      <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(270deg, rgba(8,8,8,0.84) 0%, rgba(8,8,8,0.56) 45%, rgba(8,8,8,0.1) 100%)' }} />
      <div style={{ position: 'relative', ...SHELL, padding: 'var(--space-20) var(--space-8)', boxSizing: 'border-box', width: '100%', display: 'grid', justifyContent: 'end' }}>
        <div style={{ maxWidth: '34rem', textAlign: 'right', justifyItems: 'end', display: 'grid', gap: 'var(--space-6)' }}>
          <SectionLabel>Determinism</SectionLabel>
          <LuxeHeading size="clamp(1.75rem, 3.6vw, 3rem)" style={{ margin: 0 }}>Measured to the gram, not estimated.</LuxeHeading>
          <p style={{ ...MONO, fontSize: 'var(--text-sm)', color: 'var(--k-bone-dim)', margin: 0, maxWidth: '42ch' }}>Language is the only place the model is trusted. Every gram, price and purchase order comes out of business rules you can audit.</p>
        </div>
      </div>
    </section>
  );
}

function Pricing() {
  const cell = { padding: 'var(--space-4) var(--space-5)', borderBottom: HAIRLINE };
  return (
    <section data-cut id="pricing" style={{ background: 'var(--surface-luxe)', borderTop: HAIRLINE }}>
      <div style={{ ...SHELL, padding: 'var(--space-24) var(--space-8)' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', gap: 'var(--space-8)', marginBottom: 'var(--space-12)', flexWrap: 'wrap' }}>
          <LuxeHeading size="clamp(2rem, 4.5vw, var(--text-luxe-display))" style={{ textTransform: 'uppercase', maxWidth: '16ch', overflowWrap: 'break-word' }}>Priced on capacity and intelligence</LuxeHeading>
          <p style={{ ...LABEL, color: 'var(--k-bone-faint)', maxWidth: '28ch', lineHeight: 'var(--leading-relaxed)' }}>Every tier includes the Recipe Bible, Inventory and Suppliers</p>
        </div>
        <div style={{ overflowX: 'auto' }}>
          <div data-count style={{ minWidth: '48rem', display: 'grid', gridTemplateColumns: 'minmax(0,1.2fr) repeat(4, minmax(0,1fr))', borderTop: HAIRLINE }}>
            <div style={{ ...cell, borderBottom: HAIRLINE }} />
            {TIERS.map((t) => (
              <div key={t.name} style={{ ...cell, background: t.featured ? 'var(--k-ink-2)' : 'transparent' }}>
                <div style={{ display: 'grid', gap: 'var(--space-2)' }}>
                  <span style={{ ...LABEL, color: t.featured ? 'var(--k-orange)' : 'transparent' }}>Most kitchens</span>
                  <span style={{ fontFamily: 'var(--font-luxe)', fontSize: 'var(--text-xl)', color: 'var(--k-bone)', textTransform: 'uppercase' }}>{t.name}</span>
                  <span style={{ fontFamily: 'var(--font-luxe)', fontSize: 'clamp(1.75rem,2.6vw,2.5rem)', lineHeight: 'var(--leading-tight)', color: 'var(--k-bone)' }}>{t.price}</span>
                  <span style={{ ...LABEL, color: 'var(--k-bone-faint)' }}>{t.period}</span>
                </div>
              </div>
            ))}
            {SPEC_ROWS.map(([label, vals]) => (
              <React.Fragment key={label}>
                <div style={{ ...cell, ...LABEL, color: 'var(--k-bone-faint)' }}>{label}</div>
                {vals.map((v, i) => (
                  <div key={i} style={{ ...cell, background: TIERS[i].featured ? 'var(--k-ink-2)' : 'transparent', fontFamily: 'var(--font-mono)', fontSize: 'var(--text-sm)', color: 'var(--k-bone)' }}>{v}</div>
                ))}
              </React.Fragment>
            ))}
            <div style={{ ...cell, borderBottom: 'none' }} />
            {TIERS.map((t) => (
              <div key={t.name} style={{ ...cell, borderBottom: 'none', background: t.featured ? 'var(--k-ink-2)' : 'transparent' }}>
                <Button variant={t.featured ? 'solid' : 'outline'} size="sm" full onClick={() => go('#access')}>Request access</Button>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

function Access() {
  const [email, setEmail] = useState('');
  const [sent, setSent] = useState(false);
  return (
    <section data-cut id="access" style={{ background: 'var(--k-black)', borderTop: HAIRLINE }}>
      <div style={{ ...SHELL, padding: 'var(--space-24) var(--space-8)' }}>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 20rem), 1fr))', gap: 'var(--space-16)', alignItems: 'center' }}>
          <Photo src="pass-slicing.jpg" alt="Chef portioning beef at the pass" ratio="4 / 5" scrim={0.3} />
          <div style={{ display: 'grid', gap: 'var(--space-8)' }}>
            <div>
              <SectionLabel style={{ marginBottom: 'var(--space-6)' }}>Access</SectionLabel>
              <LuxeHeading size="clamp(2rem, 4.5vw, var(--text-luxe-display))" style={{ textTransform: 'uppercase', overflowWrap: 'break-word' }}>Request a kitchen</LuxeHeading>
            </div>
            <Card surface="hairline" padding="var(--space-8)">
              {sent ? (
                <div style={{ display: 'grid', gap: 'var(--space-4)', justifyItems: 'start' }}>
                  <StatusBadge tone="success" square>Request received</StatusBadge>
                  <p style={{ fontFamily: 'var(--font-mono)', fontSize: 'var(--text-sm)', color: 'var(--k-bone-dim)', margin: 0 }}>We will reply to {email} within one service day.</p>
                </div>
              ) : (
                <form onSubmit={(e) => { e.preventDefault(); setSent(true); }} style={{ display: 'grid', gap: 'var(--space-6)' }}>
                  <Input label="Email" type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="chef@restaurant.pt" tone="dark" />
                  <Button type="submit" variant="solid" size="lg" full disabled={!email}>Request access</Button>
                </form>
              )}
            </Card>
          </div>
        </div>
      </div>
    </section>
  );
}

function Footer() {
  return (
    <footer style={{ background: 'var(--surface-luxe)', paddingTop: 'var(--space-16)' }}>
      <Marquee text="©2026 — K—SYSTEM " />
      <div style={{ ...SHELL, padding: 'var(--space-16) var(--space-8) var(--space-12)', borderTop: HAIRLINE, marginTop: 'var(--space-16)' }}>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 12rem), 1fr))', gap: 'var(--space-8)' }}>
          <div>
            <div style={{ fontFamily: 'var(--font-structural)', fontSize: 'var(--text-xl)', color: 'var(--k-bone)', letterSpacing: 'var(--track-tight)' }}>K—System</div>
            <div style={{ fontFamily: 'var(--font-mono)', fontSize: 'var(--text-xs)', color: 'var(--k-bone-faint)', marginTop: 'var(--space-2)', maxWidth: '28ch', lineHeight: 'var(--leading-relaxed)' }}>The kitchen's operating system — powered by AI, grounded in reality.</div>
          </div>
          <div><SectionLabel style={{ marginBottom: 'var(--space-4)' }}>Modules</SectionLabel>
            <div style={{ fontFamily: 'var(--font-mono)', fontSize: 'var(--text-xs)', color: 'var(--k-bone-dim)', lineHeight: 2 }}>Recipe Bible<br />Chef Agent<br />Inventory</div></div>
          <div><SectionLabel style={{ marginBottom: 'var(--space-4)' }}>Reach</SectionLabel>
            <div style={{ fontFamily: 'var(--font-mono)', fontSize: 'var(--text-xs)', color: 'var(--k-bone-dim)', lineHeight: 2 }}>Lisbon<br />Dublin<br />London</div></div>
          <div><SectionLabel style={{ marginBottom: 'var(--space-4)' }}>Contact</SectionLabel>
            <div style={{ fontFamily: 'var(--font-mono)', fontSize: 'var(--text-xs)', color: 'var(--k-bone-dim)', lineHeight: 2 }}>hello@ksystem.ai</div></div>
        </div>
      </div>
    </footer>
  );
}

function Landing({ eyebrow, headline, subhead, note, showMetrics = true, showPricing = true }) {
  React.useEffect(() => { window.KMotion && window.KMotion.init(); }, []);
  return (
    <div className="k-luxe" style={{ background: 'var(--surface-luxe)' }}>
      <div style={{ position: 'sticky', top: 0, zIndex: 70 }}>
        <TopBar luxe crumbs={[]} initials={null} cta="Login" ctaHref="https://the-k-system.ravenautomations.com" />
      </div>
      <Hero eyebrow={eyebrow} headline={headline} subhead={subhead} note={note} />
      <Problem />
      <HowItWorks showMetrics={showMetrics} />
      <Modules />
      <Season />
      <Determinism />
      {showPricing && <Pricing />}
      <Access />
      <Footer />
    </div>
  );
}

Object.assign(window, { Landing, Icon });
