// Services.jsx — services, work, process sections

const Services = () => {
  const services = [
    {
      idx: 'I',
      sign: '☾',
      name: 'Public Shopify apps',
      desc: 'End-to-end development of apps destined for the Shopify App Store — from ideation and billing to reviews and growth.',
      bullets: ['Concept & validation', 'App Store listing & ASO', 'Polaris-native UI', 'Billing, webhooks, auth'],
    },
    {
      idx: 'II',
      sign: '✦',
      name: 'Custom merchant apps',
      desc: 'Private apps tailored to a single merchant — internal tools, ERP bridges, fulfilment logic, niche checkout flows.',
      bullets: ['Admin extensions', 'Custom checkout UI', 'ERP / 3PL integrations', 'B2B & wholesale logic'],
    },
    {
      idx: 'III',
      sign: '◐',
      name: 'Audits & rescue',
      desc: 'We inherit underperforming apps and bring them back into orbit — performance, reviews, architecture, billing health.',
      bullets: ['Codebase audits', 'Performance passes', 'Shopify compliance', 'Migration & rewrites'],
    },
  ];

  return (
    <section id="services">
      <div className="container">
        <div className="section-head">
          <div className="meta">
            <span className="section-idx">§ 01 / Services</span>
            <span className="eyebrow">What we build</span>
          </div>
          <h3 className="section-title">
            Three orbits of Shopify work — each one guided by the same north&nbsp;star: a merchant who ships.
          </h3>
        </div>

        <div className="services-grid">
          {services.map((s, i) => (
            <div key={i} style={{
              padding: '36px 28px 44px',
              borderRight: i < 2 ? '1px solid var(--rule-soft)' : 'none',
              borderBottom: '1px solid var(--rule-soft)',
              position: 'relative',
              minHeight: 340,
            }}>
              <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 32 }}>
                <span className="section-idx">{s.idx}</span>
                <span style={{ fontSize: 22, color: 'var(--accent)', fontFamily: 'var(--serif)' }}>{s.sign}</span>
              </div>
              <h4 style={{
                fontFamily: 'var(--serif)',
                fontStyle: 'italic',
                fontWeight: 400,
                fontSize: 28,
                lineHeight: 1.25,
                margin: '0 0 20px',
                letterSpacing: '-0.01em',
              }}>{s.name}</h4>
              <p style={{ color: 'var(--ink-soft)', fontSize: 14, lineHeight: 1.55, margin: '0 0 24px' }}>{s.desc}</p>
              <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 8, fontSize: 13 }}>
                {s.bullets.map((b, j) => (
                  <li key={j} style={{ display: 'flex', gap: 10, alignItems: 'flex-start', color: 'var(--ink-soft)' }}>
                    <span style={{ color: 'var(--accent)', fontSize: 10, marginTop: 4 }}>✦</span>
                    {b}
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </div>

        <div className="services-footer-bar">
          <span>— Every engagement starts with a discovery call.</span>
          <a href="#" style={{ color: 'var(--ink)', textDecoration: 'underline', textDecorationThickness: '0.5px', textUnderlineOffset: 4 }}>Request a chart →</a>
        </div>
      </div>
    </section>
  );
};

// ——— NutriScore Launch Spotlight ———
const NutriScoreSpotlight = () => {
  const grades = [
    { letter: 'A', color: '#2e7d32', label: 'Excellent' },
    { letter: 'B', color: '#558b2f', label: 'Good' },
    { letter: 'C', color: '#f9a825', label: 'Moderate' },
    { letter: 'D', color: '#e65100', label: 'Poor' },
    { letter: 'E', color: '#b71c1c', label: 'Bad' },
  ];
  const features = [
    { sign: '◐', title: 'A–E Grading engine', desc: 'Calculates official Nutri-Score grades automatically from your product nutritional data.' },
    { sign: '✦', title: 'AI-powered analysis', desc: 'GPT-4 reads product descriptions and metafields to surface nutritional highlights and dietary suitability.' },
    { sign: '☾', title: 'Bulk sync', desc: 'Import scores across your entire catalogue in one batch — single product or whole collection.' },
    { sign: '◯', title: 'Live dashboard', desc: 'Grade distribution, coverage %, and missing-score alerts at a glance.' },
  ];

  return (
    <section id="nutriscore" style={{ background: 'var(--bg)', borderTop: '1px solid var(--rule-soft)', borderBottom: '1px solid var(--rule-soft)' }}>
      <div className="container">

        {/* Section header */}
        <div className="section-head">
          <div className="meta">
            <span className="section-idx">§ 02a / New Launch</span>
            <span className="eyebrow">Now live on Shopify</span>
          </div>
          <h3 className="section-title">
            Nutri-Score for Shopify — nutritional transparency, charted at&nbsp;scale.
          </h3>
        </div>

        {/* Hero card */}
        <div className="ns-hero-card" style={{
          display: 'grid',
          gridTemplateColumns: '1fr 1fr',
          gap: 0,
          border: '1px solid var(--rule-soft)',
          marginBottom: 1,
        }}>
          {/* Left: identity & description */}
          <div style={{ padding: '52px 48px 52px', borderRight: '1px solid var(--rule-soft)' }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 14, marginBottom: 28, flexWrap: 'wrap' }}>
              <div style={{
                width: 44, height: 44,
                borderRadius: 10,
                background: 'var(--ink)',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                color: 'var(--bg)',
                fontFamily: 'var(--serif)',
                fontStyle: 'italic',
                fontSize: 22,
              }}>N</div>
              <div>
                <div style={{ fontFamily: 'var(--serif)', fontStyle: 'italic', fontSize: 26, fontWeight: 400, letterSpacing: '-0.01em', lineHeight: 1.1 }}>NutriScore</div>
                <div className="eyebrow" style={{ marginTop: 2 }}>Public Shopify app · 2026</div>
              </div>
              <div style={{
                marginLeft: 'auto',
                fontFamily: 'var(--mono)',
                fontSize: 10,
                letterSpacing: '0.16em',
                textTransform: 'uppercase',
                padding: '5px 12px',
                border: '1px solid var(--accent)',
                borderRadius: 999,
                color: 'var(--accent)',
              }}>In review ✦</div>
            </div>

            <p style={{ color: 'var(--ink-soft)', fontSize: 15, lineHeight: 1.65, margin: '0 0 32px', maxWidth: 400 }}>
              NutriScore calculates and displays official A–E nutritional grades for food products in your Shopify store — helping merchants meet labelling transparency expectations without any manual data entry.
            </p>

            {/* Grade badges */}
            <div style={{ display: 'flex', gap: 8, marginBottom: 36 }}>
              {grades.map(g => (
                <div key={g.letter} style={{
                  display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4,
                }}>
                  <div style={{
                    width: 36, height: 36,
                    borderRadius: 7,
                    background: g.color,
                    color: '#fff',
                    fontFamily: 'var(--mono)',
                    fontWeight: 500,
                    fontSize: 16,
                    display: 'flex', alignItems: 'center', justifyContent: 'center',
                    letterSpacing: 0,
                  }}>{g.letter}</div>
                  <span style={{ fontFamily: 'var(--mono)', fontSize: 9, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--ink-mute)' }}>{g.label}</span>
                </div>
              ))}
            </div>

            {/* <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
              <a href="https://apps.shopify.com" target="_blank" rel="noopener noreferrer" className="btn" style={{ fontSize: 11 }}>
                Install on Shopify <span style={{ fontSize: 13 }}>→</span>
              </a>
              <a href="https://nutriscore.gadget.app" target="_blank" rel="noopener noreferrer" className="btn ghost" style={{ fontSize: 11 }}>
                View demo
              </a>
            </div> */}
          </div>

          {/* Right: feature list */}
          <div style={{ padding: '52px 48px 52px' }}>
            <div className="eyebrow" style={{ marginBottom: 28 }}>Key capabilities</div>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 0 }}>
              {features.map((f, i) => (
                <div key={i} style={{
                  display: 'grid',
                  gridTemplateColumns: '32px 1fr',
                  gap: 16,
                  padding: '22px 0',
                  borderBottom: i < features.length - 1 ? '1px solid var(--rule-soft)' : 'none',
                  alignItems: 'flex-start',
                }}>
                  <span style={{ fontFamily: 'var(--serif)', color: 'var(--accent)', fontSize: 20, lineHeight: 1.2 }}>{f.sign}</span>
                  <div>
                    <div style={{ fontFamily: 'var(--serif)', fontStyle: 'italic', fontSize: 18, fontWeight: 400, marginBottom: 6, letterSpacing: '-0.01em' }}>{f.title}</div>
                    <p style={{ fontSize: 13, color: 'var(--ink-soft)', margin: 0, lineHeight: 1.55 }}>{f.desc}</p>
                  </div>
                </div>
              ))}
            </div>
          </div>
        </div>

        {/* Stats bar */}
        <div className="ns-stats" style={{
          display: 'grid',
          gridTemplateColumns: 'repeat(4, 1fr)',
          border: '1px solid var(--rule-soft)',
          borderTop: 'none',
          marginBottom: 60,
        }}>
          {[
            { num: 'A–E', label: 'Grade scale' },
            { num: 'GPT-4', label: 'AI engine' },
            { num: 'Bulk', label: 'Sync mode' },
            { num: 'Free trial', label: 'To get started' },
          ].map((s, i) => (
            <div key={i} style={{
              padding: '22px 28px',
              borderRight: i < 3 ? '1px solid var(--rule-soft)' : 'none',
            }}>
              <div style={{ fontFamily: 'var(--serif)', fontStyle: 'italic', fontSize: 28, fontWeight: 400, letterSpacing: '-0.01em', marginBottom: 4 }}>{s.num}</div>
              <div className="eyebrow">{s.label}</div>
            </div>
          ))}
        </div>

      </div>
    </section>
  );
};

// ——— Featured Work ———
const Work = () => {
  const apps = [
    {
      id: '01',
      name: 'NutriScore',
      kind: 'Public app',
      year: '2026',
      note: 'A–E nutritional grading for food merchants on Shopify.',
      tag: '◐',
      isNew: true,
    },
    {
      id: '02',
      name: 'Company details submission',
      kind: 'Public app',
      year: '2025',
      note: 'Collects company fields at checkout or pre-checkout, depending by plan.',
      tag: '☾',
    },
    {
      id: '03',
      name: 'Carrier service app',
      kind: 'Public app',
      year: '2025',
      note: 'Custom rates and shipping methods for a client, wired into Shopify checkout.',
      tag: '✦',
    },
    {
      id: '04',
      name: 'Bulk stock sync',
      kind: 'Custom app',
      year: '2025',
      note: 'Imports and reconciles inventory from external systems into Shopify.',
      tag: '◐',
    },
    {
      id: '05',
      name: 'Custom checkout UI',
      kind: 'Custom app',
      year: '2025',
      note: 'Checkout UI and flow tailored for one merchant.',
      tag: '☽',
    },
  ];

  return (
    <section id="work" style={{ background: 'var(--bg-deep)' }}>
      <div className="container">
        <div className="section-head">
          <div className="meta">
            <span className="section-idx">§ 02 / Work</span>
            <span className="eyebrow">Selected constellations</span>
          </div>
          <h3 className="section-title">
            A small catalogue of apps we've charted — public on the Store, or bespoke for a single merchant.
          </h3>
        </div>

        <div style={{ borderTop: '1px solid var(--rule-soft)' }}>
          {apps.map((a, i) => (
            <a key={a.id} href="#" className="work-row"
              onMouseEnter={e => { e.currentTarget.style.paddingLeft = '16px'; e.currentTarget.style.background = 'color-mix(in oklch, var(--accent) 4%, transparent)'; }}
              onMouseLeave={e => { e.currentTarget.style.paddingLeft = ''; e.currentTarget.style.background = ''; }}
            >
              <span className="section-idx work-idx">{a.id}</span>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
                  <h4 style={{ fontFamily: 'var(--serif)', fontStyle: 'italic', fontSize: 32, fontWeight: 400, margin: 0, letterSpacing: '-0.01em', lineHeight: 1.2 }}>{a.name}</h4>
                  {a.isNew && (
                    <span style={{ fontFamily: 'var(--mono)', fontSize: 9, letterSpacing: '0.16em', textTransform: 'uppercase', padding: '3px 8px', border: '1px solid var(--accent)', borderRadius: 999, color: 'var(--accent)', whiteSpace: 'nowrap' }}>New ✦</span>
                  )}
                </div>
                <span style={{ fontSize: 13, color: 'var(--ink-mute)', display: 'inline-block', lineHeight: 1.4 }}>{a.note}</span>
              </div>
              <span className="eyebrow work-kind">{a.kind}</span>
              <span className="eyebrow work-year">{a.year}</span>
              <span style={{ fontSize: 24, color: 'var(--accent)', fontFamily: 'var(--serif)', justifySelf: 'end' }}>{a.tag}</span>
            </a>
          ))}
        </div>
      </div>
    </section>
  );
};

// ——— Process ———
const Process = () => {
  const steps = [
    { phase: 'New moon',       num: '01', title: 'Orientation',  desc: 'A discovery session where we chart ambitions, constraints, and what "done" looks like.' },
    { phase: 'Waxing crescent', num: '02', title: 'Charting',     desc: 'We draft the architecture, flows, and billing model — written plainly, signed off together.' },
    { phase: 'First quarter',  num: '03', title: 'Construction', desc: 'Focused weekly builds. You see every commit; we ship working software each sprint.' },
    { phase: 'Full moon',      num: '04', title: 'Rise',          desc: 'Launch day. App Store listing, merchant rollout, or handoff — whichever keeps you closest to your customers.' },
    { phase: 'Waning',         num: '05', title: 'Care',          desc: 'Ongoing orbit — monitoring, support, and iteration. We stay until you no longer need us.' },
  ];
  return (
    <section id="process">
      <div className="container">
        <div className="section-head">
          <div className="meta">
            <span className="section-idx">§ 03 / Process</span>
            <span className="eyebrow">How we work</span>
          </div>
          <h3 className="section-title">
            Five phases, in step with the moon — a rhythm merchants can plan&nbsp;around.
          </h3>
        </div>

        {/* Moon phases row */}
        <div style={{ marginBottom: 56, paddingBottom: 28, borderBottom: '1px solid var(--rule-soft)', display: 'flex', justifyContent: 'center' }}>
          <MoonPhases size={30} />
        </div>

        <div className="process-grid" style={{ background: 'var(--rule-soft)' }}>
          {steps.map((s, i) => (
            <div key={i} style={{ background: 'var(--bg)', padding: '32px 24px 44px', minHeight: 280 }}>
              <div style={{ display: 'flex', justifyContent: 'center', marginBottom: 24 }}>
                <Moon size={54} phase={i / (steps.length - 0.1)} glow={false} />
              </div>
              <div className="eyebrow" style={{ textAlign: 'center', marginBottom: 4 }}>{s.phase}</div>
              <div style={{ textAlign: 'center', fontFamily: 'var(--mono)', fontSize: 10, color: 'var(--ink-mute)', marginBottom: 16, letterSpacing: '0.1em' }}>— {s.num} —</div>
              <h4 style={{
                fontFamily: 'var(--serif)',
                fontStyle: 'italic',
                fontWeight: 400,
                fontSize: 24,
                margin: '0 0 10px',
                textAlign: 'center',
                letterSpacing: '-0.01em',
              }}>{s.title}</h4>
              <p style={{ fontSize: 13, lineHeight: 1.55, color: 'var(--ink-soft)', margin: 0, textAlign: 'center' }}>{s.desc}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
};

// ——— Contact CTA ———
const ContactCTA = () => (
  <section style={{ padding: '120px 0', borderTop: '1px solid var(--rule)' }}>
    <div className="container" style={{ textAlign: 'center', position: 'relative' }}>
      <div style={{ position: 'absolute', top: -40, left: '50%', transform: 'translateX(-50%)' }}>
        <Moon size={80} phase={0.5} />
      </div>
      <span className="eyebrow" style={{ display: 'block', marginTop: 60, marginBottom: 24 }}>✦ Epilogue</span>
      <h2 className="display" style={{ maxWidth: 900, margin: '0 auto' }}>
        When the stars align,<br/>
        <em>your app will ship.</em>
      </h2>
      <p style={{
        fontFamily: 'var(--serif)',
        fontStyle: 'italic',
        fontSize: 20,
        color: 'var(--ink-soft)',
        margin: '32px auto 40px',
        maxWidth: 520,
      }}>
        We take on four new projects per quarter. Tell us what you're building and we'll chart a path.
      </p>
      <div style={{ display: 'flex', gap: 16, justifyContent: 'center', flexWrap: 'wrap' }}>
        <button className="btn">
          Begin a chart
          <span style={{ fontSize: 14 }}>→</span>
        </button>
        <button className="btn ghost">storeon.shopify.support@gmail.com</button>
      </div>
    </div>
  </section>
);

const Footer = ({ setPage }) => (
  <footer>
    <div className="container">
      <div className="footer-grid">
        <div>
          <div style={{ marginBottom: 16 }}>
            <BrandMark size={32} />
          </div>
          <p style={{ color: 'var(--ink-soft)', fontSize: 13, maxWidth: 320, margin: 0 }}>
            A store-owned agency charting Shopify apps, public and private, from an
            observatory of patient craftsmanship.
          </p>
        </div>
        <div>
          <h4>Services</h4>
          <ul>
            <li><a href="#services">Public apps</a></li>
            <li><a href="#services">Custom apps</a></li>
            <li><a href="#services">Audits</a></li>
            <li><a href="#services">Migrations</a></li>
          </ul>
        </div>
        <div>
          <h4>Apps</h4>
          <ul>
            <li><a href="#nutriscore">NutriScore ✦</a></li>
            <li><a href="#work">Lunar Subscriptions</a></li>
            <li><a href="#work">Orbit Reviews</a></li>
            <li><a href="#work">View all</a></li>
          </ul>
        </div>
        <div>
          <h4>Studio</h4>
          <ul>
            <li><a href="#work">Work</a></li>
            <li><a href="#process">Process</a></li>
            <li><a href="#">Writing</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </div>
        <div>
          <h4>Legal</h4>
          <ul>
            <li><a href="#" onClick={e => { e.preventDefault(); setPage('privacy'); window.scrollTo(0,0); }}>Privacy policy</a></li>
            <li><a href="#">Terms</a></li>
            <li><a href="#">Cookies</a></li>
          </ul>
        </div>
      </div>
      <div className="footer-bottom">
        <span>© 2026 StoreOn Web Solutions</span>
        <span>✦ Observed from a quiet corner of the web</span>
      </div>
    </div>
  </footer>
);

Object.assign(window, { Services, NutriScoreSpotlight, Work, Process, ContactCTA, Footer });
